Skip to contentSkip to conversation

Introduce Nuvoton ma35d1 SoC

PATCH Superseded Jacky Huang 3 participants 17 messages May 16, 2023 – May 30, 2023

Subsystems (7)

v11 of 16 Superseded Latest is v16 →

lore
Share & tools
lore
#0 lore raw

v11 cover Introduce Nuvoton ma35d1 SoC

From: Jacky Huang <[email protected]>

This patchset adds initial support for the Nuvoton ma35d1 SoC, including initial device tree, clock driver, reset driver, and serial driver.

This patchset cover letter is based from the initial support for Nuvoton ma35d1 to keep tracking the version history.

This patchset had been applied to Linux kernel 6.4.0-rc2-dirty and tested on the Nuvoton ma35d1 SOM evaluation board.

(ma35d1 information: https://www.nuvoton.com/products/microprocessors/arm-cortex-a35-mpus/)
MA35D1 porting on linux-5.10.y can be found at: https://github.com/OpenNuvoton/MPU-Family

v11:
- Modify serial driver
- Fixed several coding style issues
- Fixed ma35d1serial_set_mctrl()
- Added the 'MA35_' prefix to all register and bit field definitions.
- Used 'ttyNVT' instead of 'ttyS'
- Modify clock driver
- Added 'source nuvoton/Kconfig' to drivers/clk/Kconfig
- Fixed several coding issues
- Removed unnecessary inline specifier
- Modify reset driver
- Fixed typo and added comments
- Modify ma35d1.dtsi l2-cache node
- Added cache-unified and cache-size properties

v10:
- Change from using ARCH_NUVOTON to using ARCH_MA35. The following patch files have been modified:
- patch 1 arch/arm64/Kconfig.platforms
- patch 2 arch/arm64/configs/defconfig
- patch 7 arch/arm64/boot/dts/nuvoton/Makefile
- patch 8 drivers/clk/Makefile
drivers/clk/nuvoton/Kconfig drivers/clk/nuvoton/Makefile
- patch 9 drivers/reset/Kconfig
- patch 10 drivers/tty/serial/Kconfig

v9:
- Combine MAINTAINERS patch into patch 5 'dt-bindings: arm: Add initial bindings for Nuvoton platform'
- Modify clock driver
- Use the helper function for 64-bit division
- Fixed minor issues
- Modify reset driver
- Refine coding style and add required header files
- Add spin_lock protection
- Add error return handling to the serial driver probe function

v8:
- Remove '0005-dt-bindings-mfd-syscon-Add-nuvoton-ma35d1-sys-compat.patch' as it was applied.
- Modify MAINTAINERS NUVOTON MA35 and NPCM path settings
- Remove 'syscon' from dtsi 'sys' node and modify the corresponding yaml
- Modify clock driver
- Remove the header file and move definitions into .c files.
- Use parent_data instead of parent name.
- Modify serial driver
- Modify reset driver
- Modify reset register/offset lookup table to be indexed by reset id
- Combined reset and reboot structure

v7:
- Fixed dts system-management node and compatible driver
- move 'nuvoton,npcm-gcr.yaml' from 'binding/arm/nuvoton' to 'binding/soc/nuvoton'
- In ma35d1.dtsi, create the soc node for ma35d1 SoC
- Modify the issues found in serial driver
- Modify the issues found in clock driver
- Modify the IDs of reset driver to be contiguous numbers and use lookup table to find register offset and bit position.
- Modify MAINTAINERS NUVOTON NPCM path as npcm directory name to nuvoton

v6:
- Combine nuvoton,ma35d1-clk.yaml and nuvoton,ma35d1-clk.h into one patch
- Combine nuvoton,ma35d1-reset.yaml and nuvoton,ma35d1-reset.h into one patch
- rename Documentation/devicetree/bindings/arm/npcm directory as nuvoton
- Remove patch for adding include/linux/mfd/ma35d1-sys.h as it's not required
- Update dtsi & dts files and move board-specific nodes to dts
- Modify reset driver
- Modify serial driver, fix coding style issues
- Modify clock driver, rewrite the PLL calculation functions

v5:
- Add ARCH_NUVOTON to arm64 Kconfig
- Add ARCH_NUVOTON to defconfig
- Add the clock driver
- Add the reset driver
- Add the serial driver
- Add us to the maintainer

v4:
- patch 4/5 is a resend
- Fixed dt_binding_check errors of nuvoton,ma35d1-clk.yaml
- Modify ma35d1.dtsi
1. Add a node hxt_24m
2. Fixed the base address of gic node
3. Add clocks and clock-names to clock node
- Fixed borad binding mistakes of nuvoton.yaml

v3:
- added patch 4/5 and 5/5
- introduce CONFIG_ARCH_NUVOTON option
- add initial bindings for Nuvoton Platform boards
- fixed coding style problem of nuvoton,ma35d1-clk.h
- added CAPLL to clock-controller node
- modify the chosen node of ma35d1-evb.dts
- modify clock yaml "clk-pll-mode" to "nuvoton,clk-pll-mode"

v2:
- fixed dt_binding_check failed of nuvoton,ma35d1-clk.yaml

Jacky Huang (10):
arm64: Kconfig.platforms: Add config for Nuvoton MA35 platform
arm64: defconfig: Add support for Nuvoton MA35 family SoCs
dt-bindings: clock: nuvoton: add binding for ma35d1 clock controller
dt-bindings: reset: nuvoton: Document ma35d1 reset control
dt-bindings: arm: Add initial bindings for Nuvoton platform
dt-bindings: serial: Document ma35d1 uart controller
arm64: dts: nuvoton: Add initial ma35d1 device tree
clk: nuvoton: Add clock driver for ma35d1 clock controller
reset: Add Nuvoton ma35d1 reset driver support
tty: serial: Add Nuvoton ma35d1 serial driver support

 .../bindings/arm/nuvoton/nuvoton,ma35d1.yaml  |  30 +
 .../npcm.yaml => nuvoton/nuvoton,npcm.yaml}   |   2 +-
 .../bindings/clock/nuvoton,ma35d1-clk.yaml    |  63 ++
 .../bindings/reset/nuvoton,ma35d1-reset.yaml  |  45 +
 .../serial/nuvoton,ma35d1-serial.yaml         |  48 +
 .../nuvoton/nuvoton,npcm-gcr.yaml}            |   2 +-
 MAINTAINERS                                   |  13 +-
 arch/arm64/Kconfig.platforms                  |   8 +
 arch/arm64/boot/dts/nuvoton/Makefile          |   2 +
 .../boot/dts/nuvoton/ma35d1-iot-512m.dts      |  56 ++
 .../boot/dts/nuvoton/ma35d1-som-256m.dts      |  56 ++
 arch/arm64/boot/dts/nuvoton/ma35d1.dtsi       | 234 +++++
 arch/arm64/configs/defconfig                  |   1 +
 drivers/clk/Kconfig                           |   1 +
 drivers/clk/Makefile                          |   1 +
 drivers/clk/nuvoton/Kconfig                   |  19 +
 drivers/clk/nuvoton/Makefile                  |   4 +
 drivers/clk/nuvoton/clk-ma35d1-divider.c      | 135 +++
 drivers/clk/nuvoton/clk-ma35d1-pll.c          | 361 +++++++
 drivers/clk/nuvoton/clk-ma35d1.c              | 933 ++++++++++++++++++
 drivers/reset/Kconfig                         |   6 +
 drivers/reset/Makefile                        |   1 +
 drivers/reset/reset-ma35d1.c                  | 235 +++++
 drivers/tty/serial/Kconfig                    |  18 +
 drivers/tty/serial/Makefile                   |   1 +
 drivers/tty/serial/ma35d1_serial.c            | 800 +++++++++++++++
 .../dt-bindings/clock/nuvoton,ma35d1-clk.h    | 253 +++++
 .../dt-bindings/reset/nuvoton,ma35d1-reset.h  | 108 ++
 28 files changed, 3433 insertions(+), 3 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/arm/nuvoton/nuvoton,ma35d1.yaml
 rename Documentation/devicetree/bindings/arm/{npcm/npcm.yaml => nuvoton/nuvoton,npcm.yaml} (93%)
 create mode 100644 Documentation/devicetree/bindings/clock/nuvoton,ma35d1-clk.yaml
 create mode 100644 Documentation/devicetree/bindings/reset/nuvoton,ma35d1-reset.yaml
 create mode 100644 Documentation/devicetree/bindings/serial/nuvoton,ma35d1-serial.yaml
 rename Documentation/devicetree/bindings/{arm/npcm/nuvoton,gcr.yaml => soc/nuvoton/nuvoton,npcm-gcr.yaml} (93%)
 create mode 100644 arch/arm64/boot/dts/nuvoton/ma35d1-iot-512m.dts
 create mode 100644 arch/arm64/boot/dts/nuvoton/ma35d1-som-256m.dts
 create mode 100644 arch/arm64/boot/dts/nuvoton/ma35d1.dtsi
 create mode 100644 drivers/clk/nuvoton/Kconfig
 create mode 100644 drivers/clk/nuvoton/Makefile
 create mode 100644 drivers/clk/nuvoton/clk-ma35d1-divider.c
 create mode 100644 drivers/clk/nuvoton/clk-ma35d1-pll.c
 create mode 100644 drivers/clk/nuvoton/clk-ma35d1.c
 create mode 100644 drivers/reset/reset-ma35d1.c
 create mode 100644 drivers/tty/serial/ma35d1_serial.c
 create mode 100644 include/dt-bindings/clock/nuvoton,ma35d1-clk.h
 create mode 100644 include/dt-bindings/reset/nuvoton,ma35d1-reset.h
Signature · 1 line
2.34.1
#1 lore raw

PATCH v11 1/10 arm64: Kconfig.platforms: Add config for Nuvoton MA35 platform

From: Jacky Huang <[email protected]>

Add ARCH_NUVOTON configuration option for Nuvoton MA35 family SoCs.

---
 arch/arm64/Kconfig.platforms | 8 ++++++++
 1 file changed, 8 insertions(+)
arch/arm64/Kconfig.platforms +8 -0
index 89a0b13b058d..e28dbc477a99 100644
@@ -225,6 +225,14 @@ config ARCH_S32
 
 endif
 
+config ARCH_MA35
+	bool "Nuvoton MA35 Architecture"
+	select GPIOLIB
+	select PINCTRL
+	select RESET_CONTROLLER
+	help
+	  This enables support for the ARMv8 based Nuvoton MA35 series SoCs.
+
 config ARCH_NPCM
 	bool "Nuvoton NPCM Architecture"
 	select PINCTRL
Signature · 1 line
2.34.1
#2 lore raw

PATCH v11 2/10 arm64: defconfig: Add support for Nuvoton MA35 family SoCs

In reply to Jacky Huang

From: Jacky Huang <[email protected]>

This adds support for the Nuvoton MA35 family SoCs which are based on the Cortex-A35 Armv8-A 64-bit architecture.

---
 arch/arm64/configs/defconfig | 1 +
 1 file changed, 1 insertion(+)
arch/arm64/configs/defconfig +1 -0
index a24609e14d50..0ee572753f1a 100644
@@ -52,6 +52,7 @@ CONFIG_ARCH_NXP=y
 CONFIG_ARCH_LAYERSCAPE=y
 CONFIG_ARCH_MXC=y
 CONFIG_ARCH_S32=y
+CONFIG_ARCH_MA35=y
 CONFIG_ARCH_NPCM=y
 CONFIG_ARCH_QCOM=y
 CONFIG_ARCH_RENESAS=y
Signature · 1 line
2.34.1
#3 lore raw

PATCH v11 3/10 dt-bindings: clock: nuvoton: add binding for ma35d1 clock controller

In reply to Jacky Huang

From: Jacky Huang <[email protected]>

Add the dt-bindings header for Nuvoton ma35d1, that gets shared between the clock controller and clock references in the dts. Add documentation to describe nuvoton ma35d1 clock driver.

---
 .../bindings/clock/nuvoton,ma35d1-clk.yaml    |  63 +++++
 .../dt-bindings/clock/nuvoton,ma35d1-clk.h    | 253 ++++++++++++++++++
 2 files changed, 316 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/clock/nuvoton,ma35d1-clk.yaml
 create mode 100644 include/dt-bindings/clock/nuvoton,ma35d1-clk.h
Documentation/devicetree/bindings/clock/nuvoton,ma35d1-clk.yaml new file +63 -0
new file mode 100644
index 000000000000..8f0c43683729
@@ -0,0 +1,63 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/clock/nuvoton,ma35d1-clk.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Nuvoton MA35D1 Clock Controller Module
+
+maintainers:
+  - Chi-Fang Li <[email protected]>
+  - Jacky Huang <[email protected]>
+
+description: |
+  The MA35D1 clock controller generates clocks for the whole chip,
+  including system clocks and all peripheral clocks.
+
+  See also:
+    include/dt-bindings/clock/ma35d1-clk.h
+
+properties:
+  compatible:
+    items:
+      - const: nuvoton,ma35d1-clk
+
+  reg:
+    maxItems: 1
+
+  "#clock-cells":
+    const: 1
+
+  clocks:
+    maxItems: 1
+
+  nuvoton,pll-mode:
+    description:
+      A list of PLL operation mode corresponding to CAPLL, DDRPLL, APLL,
+      EPLL, and VPLL in sequential.
+    maxItems: 5
+    items:
+      enum:
+        - integer
+        - fractional
+        - spread-spectrum
+    $ref: /schemas/types.yaml#/definitions/non-unique-string-array
+
+required:
+  - compatible
+  - reg
+  - "#clock-cells"
+  - clocks
+
+additionalProperties: false
+
+examples:
+  - |
+
+    clock-controller@40460200 {
+        compatible = "nuvoton,ma35d1-clk";
+        reg = <0x40460200 0x100>;
+        #clock-cells = <1>;
+        clocks = <&clk_hxt>;
+    };
+...
include/dt-bindings/clock/nuvoton,ma35d1-clk.h new file +253 -0

253 lines not on this page · raw message

Signature · 1 line
2.34.1
#4 lore raw

PATCH v11 4/10 dt-bindings: reset: nuvoton: Document ma35d1 reset control

In reply to Jacky Huang

From: Jacky Huang <[email protected]>

Add the dt-bindings header for Nuvoton ma35d1, that gets shared between the reset controller and reset references in the dts. Add documentation to describe nuvoton ma35d1 reset driver.

---
 .../bindings/reset/nuvoton,ma35d1-reset.yaml  |  45 ++++++++
 .../dt-bindings/reset/nuvoton,ma35d1-reset.h  | 108 ++++++++++++++++++
 2 files changed, 153 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/reset/nuvoton,ma35d1-reset.yaml
 create mode 100644 include/dt-bindings/reset/nuvoton,ma35d1-reset.h
Documentation/devicetree/bindings/reset/nuvoton,ma35d1-reset.yaml new file +45 -0
new file mode 100644
index 000000000000..34c5c1c08ec1
@@ -0,0 +1,45 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/reset/nuvoton,ma35d1-reset.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Nuvoton MA35D1 Reset Controller
+
+maintainers:
+  - Chi-Fang Li <[email protected]>
+  - Jacky Huang <[email protected]>
+
+description:
+  The system reset controller can be used to reset various peripheral
+  controllers in MA35D1 SoC.
+
+properties:
+  compatible:
+    items:
+      - const: nuvoton,ma35d1-reset
+
+  reg:
+    maxItems: 1
+
+  '#reset-cells':
+    const: 1
+
+required:
+  - compatible
+  - reg
+  - '#reset-cells'
+
+additionalProperties: false
+
+examples:
+  # system reset controller node:
+  - |
+
+    system-management@40460000 {
+        compatible = "nuvoton,ma35d1-reset";
+        reg = <0x40460000 0x200>;
+        #reset-cells = <1>;
+    };
+...
+
include/dt-bindings/reset/nuvoton,ma35d1-reset.h new file +108 -0

108 lines not on this page · raw message

Signature · 1 line
2.34.1
#5 lore raw

PATCH v11 5/10 dt-bindings: arm: Add initial bindings for Nuvoton platform

In reply to Jacky Huang

From: Jacky Huang <[email protected]>

Modify Nuvoton NPCM and MA35 platform board bindings
- Move 'nuvoton,npcm-gcr.yaml' from 'bindings/arm/npcm' to 'bindings/soc/nuvoton'.
- Rename the 'bindings/arm/npcm' directory to 'bindings/arm/nuvoton'.
- Add bindings for ARMv8-based Nuvoton SoCs and platform boards, and include the initial bindings for ma35d1 series development boards.

Modify MAINTAINERS
- Remove the line for 'bindings/arm/npcm/' under ARM/NUVOTON NPCM, as it has been renamed.
- Add ARM/NUVOTON MA35 for Nuvoton MA35 series SoCs maintainer and files.

---
 .../bindings/arm/nuvoton/nuvoton,ma35d1.yaml  | 30 +++++++++++++++++++
 .../npcm.yaml => nuvoton/nuvoton,npcm.yaml}   |  2 +-
 .../nuvoton/nuvoton,npcm-gcr.yaml}            |  2 +-
 MAINTAINERS                                   | 13 +++++++-
 4 files changed, 44 insertions(+), 3 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/arm/nuvoton/nuvoton,ma35d1.yaml
 rename Documentation/devicetree/bindings/arm/{npcm/npcm.yaml => nuvoton/nuvoton,npcm.yaml} (93%)
 rename Documentation/devicetree/bindings/{arm/npcm/nuvoton,gcr.yaml => soc/nuvoton/nuvoton,npcm-gcr.yaml} (93%)
Documentation/devicetree/bindings/arm/nuvoton/nuvoton,ma35d1.yaml new file +30 -0
new file mode 100644
index 000000000000..fb190db61525
@@ -0,0 +1,30 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/arm/nuvoton/nuvoton,ma35d1.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Nuvoton MA35 series SoC based platforms
+
+maintainers:
+  - Jacky Huang <[email protected]>
+
+description: |
+  Boards with an ARMv8 based Nuvoton MA35 series SoC shall have
+  the following properties.
+
+properties:
+  $nodename:
+    const: '/'
+  compatible:
+    oneOf:
+
+      - description: MA35D1 based boards
+        items:
+          - enum:
+              - nuvoton,ma35d1-iot
+              - nuvoton,ma35d1-som
+          - const: nuvoton,ma35d1
+
+additionalProperties: true
+...
Documentation/devicetree/bindings/arm/nuvoton/nuvoton,npcm.yaml renamed from Documentation/devicetree/bindings/arm/npcm/npcm.yaml +1 -1
similarity index 93%
rename from Documentation/devicetree/bindings/arm/npcm/npcm.yaml
rename to Documentation/devicetree/bindings/arm/nuvoton/nuvoton,npcm.yaml
index 6871483947c5..d386744c8815 100644
@@ -1,7 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
 %YAML 1.2
 ---
-$id: http://devicetree.org/schemas/arm/npcm/npcm.yaml#
+$id: http://devicetree.org/schemas/arm/nuvoton/nuvoton,npcm.yaml#
 $schema: http://devicetree.org/meta-schemas/core.yaml#
 
 title: NPCM Platforms
Documentation/devicetree/bindings/soc/nuvoton/nuvoton,npcm-gcr.yaml renamed from Documentation/devicetree/bindings/arm/npcm/nuvoton,gcr.yaml +1 -1
similarity index 93%
rename from Documentation/devicetree/bindings/arm/npcm/nuvoton,gcr.yaml
rename to Documentation/devicetree/bindings/soc/nuvoton/nuvoton,npcm-gcr.yaml
index 94e72f25b331..23e7e4ea01ff 100644
@@ -1,7 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
 %YAML 1.2
 ---
-$id: http://devicetree.org/schemas/arm/npcm/nuvoton,gcr.yaml#
+$id: http://devicetree.org/schemas/soc/nuvoton/nuvoton,npcm-gcr.yaml#
 $schema: http://devicetree.org/meta-schemas/core.yaml#
 
 title: Global Control Registers block in Nuvoton SoCs
MAINTAINERS +12 -1
index e0ad886d3163..5061868467c9 100644
@@ -2502,6 +2502,18 @@ F:	drivers/rtc/rtc-ab8500.c
 F:	drivers/rtc/rtc-pl031.c
 F:	drivers/soc/ux500/
 
+ARM/NUVOTON MA35 ARCHITECTURE
+M:	Jacky Huang <[email protected]>
+M:	Shan-Chun Hung <[email protected]>
+L:	[email protected] (moderated for non-subscribers)
+S:	Supported
+F:	Documentation/devicetree/bindings/*/*/*ma35*
+F:	Documentation/devicetree/bindings/*/*ma35*
+F:	arch/arm64/boot/dts/nuvoton/*ma35*
+F:	drivers/*/*/*ma35*
+F:	drivers/*/*ma35*
+K:	ma35d1
+
 ARM/NUVOTON NPCM ARCHITECTURE
 M:	Avi Fishman <[email protected]>
 M:	Tomer Maimon <[email protected]>
@@ -2513,7 +2525,6 @@ L:	[email protected] (moderated for non-subscribers)
 S:	Supported
 F:	Documentation/devicetree/bindings/*/*/*npcm*
 F:	Documentation/devicetree/bindings/*/*npcm*
-F:	Documentation/devicetree/bindings/arm/npcm/*
 F:	Documentation/devicetree/bindings/rtc/nuvoton,nct3018y.yaml
 F:	arch/arm/boot/dts/nuvoton-npcm*
 F:	arch/arm/mach-npcm/
Signature · 1 line
2.34.1
#6 lore raw

PATCH v11 6/10 dt-bindings: serial: Document ma35d1 uart controller

In reply to Jacky Huang

From: Jacky Huang <[email protected]>

Add documentation that describes the nuvoton ma35d1 UART driver bindings.

---
 .../serial/nuvoton,ma35d1-serial.yaml         | 48 +++++++++++++++++++
 1 file changed, 48 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/serial/nuvoton,ma35d1-serial.yaml
Documentation/devicetree/bindings/serial/nuvoton,ma35d1-serial.yaml new file +48 -0
new file mode 100644
index 000000000000..a76af0f6009b
@@ -0,0 +1,48 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/serial/nuvoton,ma35d1-serial.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Nuvoton MA35D1 Universal Asynchronous Receiver/Transmitter (UART)
+
+maintainers:
+  - Min-Jen Chen <[email protected]>
+  - Jacky Huang <[email protected]>
+
+allOf:
+  - $ref: serial.yaml
+
+properties:
+  compatible:
+    const: nuvoton,ma35d1-uart
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  clocks:
+    maxItems: 1
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - clocks
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+    #include <dt-bindings/clock/nuvoton,ma35d1-clk.h>
+
+    serial@40700000 {
+        compatible = "nuvoton,ma35d1-uart";
+        reg = <0x40700000 0x100>;
+        interrupts = <GIC_SPI 59 IRQ_TYPE_LEVEL_HIGH>;
+        clocks = <&clk UART0_GATE>;
+    };
+...
Signature · 1 line
2.34.1
#7 lore raw

PATCH v11 7/10 arm64: dts: nuvoton: Add initial ma35d1 device tree

In reply to Jacky Huang

From: Jacky Huang <[email protected]>

Add initial device tree support for Nuvoton ma35d1 SoC, including cpu, clock, reset, and serial controllers.
Add reference boards som-256m and iot-512m.

---
 arch/arm64/boot/dts/nuvoton/Makefile          |   2 +
 .../boot/dts/nuvoton/ma35d1-iot-512m.dts      |  56 +++++
 .../boot/dts/nuvoton/ma35d1-som-256m.dts      |  56 +++++
 arch/arm64/boot/dts/nuvoton/ma35d1.dtsi       | 234 ++++++++++++++++++
 4 files changed, 348 insertions(+)
 create mode 100644 arch/arm64/boot/dts/nuvoton/ma35d1-iot-512m.dts
 create mode 100644 arch/arm64/boot/dts/nuvoton/ma35d1-som-256m.dts
 create mode 100644 arch/arm64/boot/dts/nuvoton/ma35d1.dtsi
arch/arm64/boot/dts/nuvoton/Makefile +2 -0
index a99dab90472a..3bc9787801a5 100644
@@ -1,2 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0
+dtb-$(CONFIG_ARCH_MA35) += ma35d1-iot-512m.dtb
+dtb-$(CONFIG_ARCH_MA35) += ma35d1-som-256m.dtb
 dtb-$(CONFIG_ARCH_NPCM) += nuvoton-npcm845-evb.dtb
arch/arm64/boot/dts/nuvoton/ma35d1-iot-512m.dts new file +56 -0

56 lines not on this page · raw message

arch/arm64/boot/dts/nuvoton/ma35d1-som-256m.dts new file +56 -0

56 lines not on this page · raw message

arch/arm64/boot/dts/nuvoton/ma35d1.dtsi new file +234 -0

234 lines not on this page · raw message

Signature · 1 line
2.34.1
#8 lore raw

PATCH v11 8/10 clk: nuvoton: Add clock driver for ma35d1 clock controller

In reply to Jacky Huang

From: Jacky Huang <[email protected]>

The clock controller generates clocks for the whole chip, including system clocks and all peripheral clocks. This driver support ma35d1 clock gating, divider, and individual PLL configuration.

There are 6 PLLs in ma35d1 SoC:
- CA-PLL for the two Cortex-A35 CPU clock
- SYS-PLL for system bus, which comes from the companion MCU and cannot be programmed by clock controller.
- DDR-PLL for DDR
- EPLL for GMAC and GFX, Display, and VDEC IPs.
- VPLL for video output pixel clock
- APLL for SDHC, I2S audio, and other IPs.
CA-PLL has only one operation mode.
DDR-PLL, EPLL, VPLL, and APLL are advanced PLLs which have 3 operation modes: integer mode, fraction mode, and spread specturm mode.

---
 drivers/clk/Kconfig                      |   1 +
 drivers/clk/Makefile                     |   1 +
 drivers/clk/nuvoton/Kconfig              |  19 +
 drivers/clk/nuvoton/Makefile             |   4 +
 drivers/clk/nuvoton/clk-ma35d1-divider.c | 135 ++++
 drivers/clk/nuvoton/clk-ma35d1-pll.c     | 361 +++++++++
 drivers/clk/nuvoton/clk-ma35d1.c         | 933 +++++++++++++++++++++++
 7 files changed, 1454 insertions(+)
 create mode 100644 drivers/clk/nuvoton/Kconfig
 create mode 100644 drivers/clk/nuvoton/Makefile
 create mode 100644 drivers/clk/nuvoton/clk-ma35d1-divider.c
 create mode 100644 drivers/clk/nuvoton/clk-ma35d1-pll.c
 create mode 100644 drivers/clk/nuvoton/clk-ma35d1.c
drivers/clk/Kconfig +1 -0
index 016814e15536..db789055e0fd 100644
@@ -478,6 +478,7 @@ source "drivers/clk/meson/Kconfig"
 source "drivers/clk/mstar/Kconfig"
 source "drivers/clk/microchip/Kconfig"
 source "drivers/clk/mvebu/Kconfig"
+source "drivers/clk/nuvoton/Kconfig"
 source "drivers/clk/pistachio/Kconfig"
 source "drivers/clk/qcom/Kconfig"
 source "drivers/clk/ralink/Kconfig"
drivers/clk/Makefile +1 -0
index 0aebef17edc6..7cb000549b61 100644
@@ -106,6 +106,7 @@ endif
 obj-y					+= mstar/
 obj-y					+= mvebu/
 obj-$(CONFIG_ARCH_MXS)			+= mxs/
+obj-$(CONFIG_ARCH_MA35)			+= nuvoton/
 obj-$(CONFIG_COMMON_CLK_NXP)		+= nxp/
 obj-$(CONFIG_COMMON_CLK_PISTACHIO)	+= pistachio/
 obj-$(CONFIG_COMMON_CLK_PXA)		+= pxa/
drivers/clk/nuvoton/Kconfig new file +19 -0
new file mode 100644
index 000000000000..fe4b7f62f467
@@ -0,0 +1,19 @@
+# SPDX-License-Identifier: GPL-2.0
+# common clock support for Nuvoton SoC family.
+
+config COMMON_CLK_NUVOTON
+	bool "Nuvoton clock controller common support"
+	depends on ARCH_MA35 || COMPILE_TEST
+	default y
+	help
+	  Say y here to enable common clock controller for Nuvoton platforms.
+
+if COMMON_CLK_NUVOTON
+
+config CLK_MA35D1
+	bool "Nuvoton MA35D1 clock controller support"
+	default y
+	help
+	  Build the clock controller driver for MA35D1 SoC.
+
+endif
drivers/clk/nuvoton/Makefile new file +4 -0
new file mode 100644
index 000000000000..c3c59dd9f2aa
@@ -0,0 +1,4 @@
+# SPDX-License-Identifier: GPL-2.0-only
+obj-$(CONFIG_CLK_MA35D1) += clk-ma35d1.o
+obj-$(CONFIG_CLK_MA35D1) += clk-ma35d1-divider.o
+obj-$(CONFIG_CLK_MA35D1) += clk-ma35d1-pll.o
drivers/clk/nuvoton/clk-ma35d1-divider.c new file +135 -0

135 lines not on this page · raw message

drivers/clk/nuvoton/clk-ma35d1-pll.c new file +361 -0

361 lines not on this page · raw message

drivers/clk/nuvoton/clk-ma35d1.c new file +933 -0

933 lines not on this page · raw message

Signature · 1 line
2.34.1
#9 lore raw

PATCH v11 9/10 reset: Add Nuvoton ma35d1 reset driver support

In reply to Jacky Huang

From: Jacky Huang <[email protected]>

This driver supports individual IP reset for the MA35D1. The reset control registers are a subset of the system control registers.

---
 drivers/reset/Kconfig        |   6 +
 drivers/reset/Makefile       |   1 +
 drivers/reset/reset-ma35d1.c | 235 +++++++++++++++++++++++++++++++++++
 3 files changed, 242 insertions(+)
 create mode 100644 drivers/reset/reset-ma35d1.c
drivers/reset/Kconfig +6 -0
index 6aa8f243b30c..07499177a266 100644
@@ -143,6 +143,12 @@ config RESET_NPCM
 	  This enables the reset controller driver for Nuvoton NPCM
 	  BMC SoCs.
 
+config RESET_NUVOTON_MA35D1
+	bool "Nuvton MA35D1 Reset Driver"
+	default ARCH_MA35 || COMPILE_TEST
+	help
+	  This enables the reset controller driver for Nuvoton MA35D1 SoC.
+
 config RESET_OXNAS
 	bool
 
drivers/reset/Makefile +1 -0
index 7fec5af6c964..411b45ba0da7 100644
@@ -21,6 +21,7 @@ obj-$(CONFIG_RESET_MCHP_SPARX5) += reset-microchip-sparx5.o
 obj-$(CONFIG_RESET_MESON) += reset-meson.o
 obj-$(CONFIG_RESET_MESON_AUDIO_ARB) += reset-meson-audio-arb.o
 obj-$(CONFIG_RESET_NPCM) += reset-npcm.o
+obj-$(CONFIG_RESET_NUVOTON_MA35D1) += reset-ma35d1.o
 obj-$(CONFIG_RESET_OXNAS) += reset-oxnas.o
 obj-$(CONFIG_RESET_PISTACHIO) += reset-pistachio.o
 obj-$(CONFIG_RESET_POLARFIRE_SOC) += reset-mpfs.o
drivers/reset/reset-ma35d1.c new file +235 -0

235 lines not on this page · raw message

Signature · 1 line
2.34.1
#10 lore raw

PATCH v11 10/10 tty: serial: Add Nuvoton ma35d1 serial driver support

In reply to Jacky Huang

From: Jacky Huang <[email protected]>

This adds UART and console driver for Nuvoton ma35d1 Soc. It supports full-duplex communication, FIFO control, and hardware flow control.

---
 drivers/tty/serial/Kconfig         |  18 +
 drivers/tty/serial/Makefile        |   1 +
 drivers/tty/serial/ma35d1_serial.c | 800 +++++++++++++++++++++++++++++
 3 files changed, 819 insertions(+)
 create mode 100644 drivers/tty/serial/ma35d1_serial.c
drivers/tty/serial/Kconfig +18 -0
index 398e5aac2e77..85ac6fc1ff1d 100644
@@ -1555,6 +1555,24 @@ config SERIAL_SUNPLUS_CONSOLE
 	  you can alter that using a kernel command line option such as
 	  "console=ttySUPx".
 
+config SERIAL_NUVOTON_MA35D1
+	tristate "Nuvoton MA35D1 family UART support"
+	depends on ARCH_MA35 || COMPILE_TEST
+	select SERIAL_CORE
+	help
+	  This driver supports Nuvoton MA35D1 family UART ports. If you would
+	  like to use them, you must answer Y or M to this option. Note that
+	  for use as console, it must be included in kernel and not as a
+	  module
+
+config SERIAL_NUVOTON_MA35D1_CONSOLE
+	bool "Console on a Nuvotn MA35D1 family UART port"
+	depends on SERIAL_NUVOTON_MA35D1=y
+	select SERIAL_CORE_CONSOLE
+	help
+	  Select this options if you'd like to use the UART port0 of the
+	  Nuvoton MA35D1 family as a console.
+
 endmenu
 
 config SERIAL_MCTRL_GPIO
drivers/tty/serial/Makefile +1 -0
index cd9afd9e3018..0e823851c42c 100644
@@ -93,3 +93,4 @@ obj-$(CONFIG_SERIAL_MCTRL_GPIO)	+= serial_mctrl_gpio.o
 
 obj-$(CONFIG_SERIAL_KGDB_NMI) += kgdb_nmi.o
 obj-$(CONFIG_KGDB_SERIAL_CONSOLE) += kgdboc.o
+obj-$(CONFIG_SERIAL_NUVOTON_MA35D1) += ma35d1_serial.o
drivers/tty/serial/ma35d1_serial.c new file +800 -0

800 lines not on this page · raw message

Signature · 1 line
2.34.1
maintainer
#11 lore raw

Re: [PATCH v11 10/10] tty: serial: Add Nuvoton ma35d1 serial driver support

drivers/tty/serial/ma35d1_serial.c line 481

Quoted 8 lines · Jacky Huang
drivers/tty/serial/ma35d1_serial.c new file +8 -0
+static void ma35d1serial_config_port(struct uart_port *port, int flags)
+{
+	/*
+	 * Driver core for serial ports forces a non-zero value for port type.
+	 * Write an arbitrary value here to accommodate the serial core driver,
+	 * as ID part of UAPI is redundant.
+	 */
+	port->type = 1;

So this 1 translates to PORT_8250. Why not to use it directly? Or something more saner like PORT_16550A?

Quoted 9 lines
drivers/tty/serial/ma35d1_serial.c new file +9 -0
+}
+
+static int ma35d1serial_verify_port(struct uart_port *port, struct serial_struct *ser)
+{
+	if (port->type != PORT_UNKNOWN && ser->type != 1)
+		return -EINVAL;
+
+	return 0;
+}

...

drivers/tty/serial/ma35d1_serial.c line 579

Quoted 13 lines
drivers/tty/serial/ma35d1_serial.c new file +13 -0
+static int __init ma35d1serial_console_setup(struct console *co, char *options)
+{
+	struct device_node *np = ma35d1serial_uart_nodes[co->index];
+	struct uart_ma35d1_port *p = &ma35d1serial_ports[co->index];
+	u32 val32[4];
+	struct uart_port *port;
+	int baud = 115200;
+	int bits = 8;
+	int parity = 'n';
+	int flow = 'n';
+
+	/*
+	 * Check whether an invalid uart number has been specified, and

You dereferenced ma35d1serial_uart_nodes already. Doesn't console=ttyNVT1000 (or something like that) crash the system?

drivers/tty/serial/ma35d1_serial.c line 581

Quoted 2 lines
drivers/tty/serial/ma35d1_serial.c new file +2 -0
+	 * if so, search for the first available port that does have
+	 * console support.

The code below doesn't match this comment.

drivers/tty/serial/ma35d1_serial.c line 588

Quoted 7 lines
drivers/tty/serial/ma35d1_serial.c new file +7 -0
+	 */
+	if ((co->index < 0) || (co->index >= MA35_UART_NR)) {
+		pr_debug("Console Port%x out of range\n", co->index);
+		return -EINVAL;
+	}
+
+	if (of_property_read_u32_array(np, "reg", val32, 4) != 0)

Shouldn't that 4 be ARRAY_SIZE(val32) instead?

Review

Quoted 1 line
(quoted diff) +1 -0
+		return -EINVAL;

One \n here please.

drivers/tty/serial/ma35d1_serial.c line 591

Quoted 2 lines
drivers/tty/serial/ma35d1_serial.c new file +2 -0
+	p->port.iobase = val32[1];
+	p->port.membase = ioremap(p->port.iobase, MA35_UART_REG_SIZE);

What if this fails?

drivers/tty/serial/ma35d1_serial.c line 596

Quoted 5 lines
drivers/tty/serial/ma35d1_serial.c new file +5 -0
+	p->port.ops = &ma35d1serial_ops;
+	p->port.line = 0;
+	p->port.uartclk = MA35_UART_CONSOLE_CLK;
+
+	port = &ma35d1serial_ports[co->index].port;

Isn't this:
port = &p->port;
?

Either use port on all above lines or drop the "port" variable completely and use "p->port" below instead.

Quoted 5 lines
drivers/tty/serial/ma35d1_serial.c new file +5 -0
+
+	if (options)
+		uart_parse_options(options, &baud, &parity, &bits, &flow);
+
+	return uart_set_options(port, co, baud, parity, bits, flow);

drivers/tty/serial/ma35d1_serial.c line 611

Quoted 10 lines
drivers/tty/serial/ma35d1_serial.c new file +10 -0
+}
+
+static struct console ma35d1serial_console = {
+	.name    = "ttyNVT",
+	.write   = ma35d1serial_console_write,
+	.device  = uart_console_device,
+	.setup   = ma35d1serial_console_setup,
+	.flags   = CON_PRINTBUFFER | CON_ENABLED,
+	.index   = -1,
+	.data    = &ma35d1serial_reg,

I don't see console->data used anywhere in the driver?

Quoted 1 line

+};

...

Quoted 11 lines
drivers/tty/serial/ma35d1_serial.c new file +11 -0
+static int ma35d1serial_probe(struct platform_device *pdev)
+{
+	struct resource *res_mem;
+	struct uart_ma35d1_port *up;
+	int ret = 0;
+
+	if (pdev->dev.of_node) {
+		ret = of_alias_get_id(pdev->dev.of_node, "serial");
+		if (ret < 0) {
+			dev_err(&pdev->dev, "failed to get alias/pdev id, errno %d\n", ret);
+			return ret;

drivers/tty/serial/ma35d1_serial.c line 678

Quoted 10 lines
drivers/tty/serial/ma35d1_serial.c new file +10 -0
+		}
+	}
+	up = &ma35d1serial_ports[ret];
+	up->port.line = ret;
+	res_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res_mem)
+		return -ENODEV;
+
+	up->port.iobase = res_mem->start;
+	up->port.membase = ioremap(up->port.iobase, MA35_UART_REG_SIZE);

Check this too.

Quoted 34 lines
drivers/tty/serial/ma35d1_serial.c new file +34 -0
+	up->port.ops = &ma35d1serial_ops;
+
+	spin_lock_init(&up->port.lock);
+
+	up->clk = of_clk_get(pdev->dev.of_node, 0);
+	if (IS_ERR(up->clk)) {
+		ret = PTR_ERR(up->clk);
+		dev_err(&pdev->dev, "failed to get core clk: %d\n", ret);
+		goto err_iounmap;
+	}
+
+	ret = clk_prepare_enable(up->clk);
+	if (ret)
+		goto err_iounmap;
+
+	if (up->port.line != 0)
+		up->port.uartclk = clk_get_rate(up->clk);
+
+	ret = platform_get_irq(pdev, 0);
+	if (ret < 0)
+		goto err_clk_disable;
+
+	up->port.irq = ret;
+	up->port.dev = &pdev->dev;
+	up->port.flags = UPF_BOOT_AUTOCONF;
+
+	platform_set_drvdata(pdev, up);
+
+	ret = uart_add_one_port(&ma35d1serial_reg, &up->port);
+	if (ret < 0)
+		goto err_free_irq;
+
+	return 0;
+

drivers/tty/serial/ma35d1_serial.c line 722

Quoted 10 lines
drivers/tty/serial/ma35d1_serial.c new file +10 -0
+err_free_irq:
+	free_irq(up->port.irq, &up->port);
+
+err_clk_disable:
+	clk_disable_unprepare(up->clk);
+
+err_iounmap:
+	iounmap(up->port.membase);
+	return ret;
+}

thanks,

Signature · 2 lines
js
suse labs
#12 lore raw

Re: [PATCH v11 10/10] tty: serial: Add Nuvoton ma35d1 serial driver support

Dear Jiri,

Thanks for your advice.

Quoted 14 lines · Jiri Slaby
Quoted 10 lines · Jacky Huang
drivers/tty/serial/ma35d1_serial.c new file +4 -0
+static void ma35d1serial_config_port(struct uart_port *port, int flags)
+{
+    /*
+     * Driver core for serial ports forces a non-zero value for port 

type.
+     * Write an arbitrary value here to accommodate the serial core driver,
+     * as ID part of UAPI is redundant.
+     */
+    port->type = 1;

So this 1 translates to PORT_8250. Why not to use it directly? Or something more saner like PORT_16550A?

It's not actually 8250 or 16550A.
Can we add the following definition to 'include/uapi/linux/serial_core.h' and use PORT_MA35 instead?

#define PORT_MA35    124

Quoted 11 lines
Quoted 10 lines
drivers/tty/serial/ma35d1_serial.c new file +3 -0
+}
+
+static int ma35d1serial_verify_port(struct uart_port *port, struct 

serial_struct *ser)

drivers/tty/serial/ma35d1_serial.c new file +6 -0
+{
+    if (port->type != PORT_UNKNOWN && ser->type != 1)
+        return -EINVAL;
+
+    return 0;
+}

...

Quoted 17 lines
Quoted 4 lines

+static int __init ma35d1serial_console_setup(struct console *co, char *options)

drivers/tty/serial/ma35d1_serial.c new file +2 -0
+{
+    struct device_node *np = ma35d1serial_uart_nodes[co->index];

drivers/tty/serial/ma35d1_serial.c line 579

Quoted 10 lines
drivers/tty/serial/ma35d1_serial.c new file +10 -0
+    struct uart_ma35d1_port *p = &ma35d1serial_ports[co->index];
+    u32 val32[4];
+    struct uart_port *port;
+    int baud = 115200;
+    int bits = 8;
+    int parity = 'n';
+    int flow = 'n';
+
+    /*
+     * Check whether an invalid uart number has been specified, and

You dereferenced ma35d1serial_uart_nodes already. Doesn't console=ttyNVT1000 (or something like that) crash the system?

I will add the following check before np = "ma35d1serial_uart_nodes[co->index]".

if (co->index < 0 || co->index >= MA35_UART_NR)
    return -EINVAL;

Quoted 4 lines
Quoted 2 lines

+     * if so, search for the first available port that does have +     * console support.

The code below doesn't match this comment.

Yes, I will remove the above comment.

Quoted 11 lines
Quoted 8 lines

+     */
+    if ((co->index < 0) || (co->index >= MA35_UART_NR)) { +        pr_debug("Console Port%x out of range\n", co->index); +        return -EINVAL;
+    }
+
+    if (of_property_read_u32_array(np, "reg", val32, 4) != 0)

Shouldn't that 4 be ARRAY_SIZE(val32) instead?

Will be fixed.

Quoted 4 lines
Quoted 1 line

+        return -EINVAL;

One \n here please.

Okay, I will add it.

Quoted 5 lines
Quoted 2 lines

+    p->port.iobase = val32[1];
+    p->port.membase = ioremap(p->port.iobase, MA35_UART_REG_SIZE);

What if this fails?

I will add a check for the return value.

Quoted 6 lines
Quoted 5 lines

+    p->port.ops = &ma35d1serial_ops;
+    p->port.line = 0;
+    p->port.uartclk = MA35_UART_CONSOLE_CLK;
+
+    port = &ma35d1serial_ports[co->index].port;

Quoted 6 lines

Isn't this:
  port = &p->port;
?

Either use port on all above lines or drop the "port" variable completely and use "p->port" below instead.

I will remove port variable and use p->port only.

Quoted 9 lines
Quoted 9 lines
drivers/tty/serial/ma35d1_serial.c new file +9 -0
+
+    if (options)
+        uart_parse_options(options, &baud, &parity, &bits, &flow);
+
+    return uart_set_options(port, co, baud, parity, bits, flow);
+}
+
+static struct console ma35d1serial_console = {
+    .name    = "ttyNVT",
Quoted 9 lines
Quoted 6 lines

+    .write   = ma35d1serial_console_write,
+    .device  = uart_console_device,
+    .setup   = ma35d1serial_console_setup,
+    .flags   = CON_PRINTBUFFER | CON_ENABLED,
+    .index   = -1,
+    .data    = &ma35d1serial_reg,

I don't see console->data used anywhere in the driver?

I will remove it.

Quoted 18 lines
Quoted 1 line

+};

...

Quoted 16 lines
drivers/tty/serial/ma35d1_serial.c new file +10 -0
+static int ma35d1serial_probe(struct platform_device *pdev)
+{
+    struct resource *res_mem;
+    struct uart_ma35d1_port *up;
+    int ret = 0;
+
+    if (pdev->dev.of_node) {
+        ret = of_alias_get_id(pdev->dev.of_node, "serial");
+        if (ret < 0) {
+            dev_err(&pdev->dev, "failed to get alias/pdev id, errno 

%d\n", ret);
+            return ret;
+        }
+    }
+    up = &ma35d1serial_ports[ret];
+    up->port.line = ret;

Quoted 9 lines
Quoted 6 lines

+    res_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); +    if (!res_mem)
+        return -ENODEV;
+
+    up->port.iobase = res_mem->start;
+    up->port.membase = ioremap(up->port.iobase, MA35_UART_REG_SIZE);

Check this too.

Okay, sure.

Quoted 38 lines
Quoted 38 lines

+    up->port.ops = &ma35d1serial_ops;

drivers/tty/serial/ma35d1_serial.c new file +37 -0
+
+    spin_lock_init(&up->port.lock);
+
+    up->clk = of_clk_get(pdev->dev.of_node, 0);
+    if (IS_ERR(up->clk)) {
+        ret = PTR_ERR(up->clk);
+        dev_err(&pdev->dev, "failed to get core clk: %d\n", ret);
+        goto err_iounmap;
+    }
+
+    ret = clk_prepare_enable(up->clk);
+    if (ret)
+        goto err_iounmap;
+
+    if (up->port.line != 0)
+        up->port.uartclk = clk_get_rate(up->clk);
+
+    ret = platform_get_irq(pdev, 0);
+    if (ret < 0)
+        goto err_clk_disable;
+
+    up->port.irq = ret;
+    up->port.dev = &pdev->dev;
+    up->port.flags = UPF_BOOT_AUTOCONF;
+
+    platform_set_drvdata(pdev, up);
+
+    ret = uart_add_one_port(&ma35d1serial_reg, &up->port);
+    if (ret < 0)
+        goto err_free_irq;
+
+    return 0;
+
+err_free_irq:
+    free_irq(up->port.irq, &up->port);
+
+err_clk_disable:
Quoted 8 lines

drivers/tty/serial/ma35d1_serial.c line 722

Quoted 6 lines

+    clk_disable_unprepare(up->clk);

drivers/tty/serial/ma35d1_serial.c new file +5 -0
+
+err_iounmap:
+    iounmap(up->port.membase);
+    return ret;
+}

thanks,

Best regards,
Jacky Huang

#13 lore raw

Re: [PATCH v11 10/10] tty: serial: Add Nuvoton ma35d1 serial driver support

Quoted 16 lines · Jacky Huang
Quoted 15 lines · Jiri Slaby
Quoted 10 lines · Jacky Huang
drivers/tty/serial/ma35d1_serial.c new file +4 -0
+static void ma35d1serial_config_port(struct uart_port *port, int flags)
+{
+    /*
+     * Driver core for serial ports forces a non-zero value for port 

type.
+     * Write an arbitrary value here to accommodate the serial core driver,
+     * as ID part of UAPI is redundant.
+     */
+    port->type = 1;

So this 1 translates to PORT_8250. Why not to use it directly? Or something more saner like PORT_16550A?

Quoted 5 lines

It's not actually 8250 or 16550A.
Can we add the following definition to 'include/uapi/linux/serial_core.h' and use PORT_MA35 instead?

#define PORT_MA35    124

This was already in a previous version, until Greg commented that it was probably not needed:

https://lore.kernel.org/lkml/[email protected]/

Since leaving port->type at PORT_UNKNOWN doesn't work, and almost all other drivers have something in serial_core.h, it's probably best to do the same here. Checking the other drivers showed that drivers/tty/serial/lantiq.c is currently the only exception, it defines PORT_LTQ_ASC locally, which causes a conflict with PORT_SPRD.

Arnd

maintainer
#14 lore raw

Re: [PATCH v11 10/10] tty: serial: Add Nuvoton ma35d1 serial driver support

Quoted 26 lines · Arnd Bergmann
Quoted 16 lines · Jacky Huang
Quoted 15 lines · Jiri Slaby
Quoted 10 lines · Jacky Huang
drivers/tty/serial/ma35d1_serial.c new file +4 -0
+static void ma35d1serial_config_port(struct uart_port *port, int flags)
+{
+    /*
+     * Driver core for serial ports forces a non-zero value for port

type.
+     * Write an arbitrary value here to accommodate the serial core driver,
+     * as ID part of UAPI is redundant.
+     */
+    port->type = 1;

So this 1 translates to PORT_8250. Why not to use it directly? Or something more saner like PORT_16550A?

Quoted 5 lines

It's not actually 8250 or 16550A.
Can we add the following definition to 'include/uapi/linux/serial_core.h' and use PORT_MA35 instead?

#define PORT_MA35    124

This was already in a previous version, until Greg commented that it was probably not needed:

Quoted 8 lines

https://lore.kernel.org/lkml/[email protected]/

Since leaving port->type at PORT_UNKNOWN doesn't work, and almost all other drivers have something in serial_core.h, it's probably best to do the same here. Checking the other drivers showed that drivers/tty/serial/lantiq.c is currently the only exception, it defines PORT_LTQ_ASC locally, which causes a conflict with PORT_SPRD.

Hmm.

Anyone has an idea what this is really used for in userspace? Can we replace all of them by simply some sort of "PORT_OTHER"?

For example:

xdg-open `echo -n 'https://codesearch.debian.net/search?q=\b('; sed -n 's@#define\s\(\w\+\)\s.*@\1@ p' include/uapi/linux/serial_core.h | tail -20 | sed 's@.* \(.*\)[\x09 ][\x09 ]*.*@\1@'|paste -sd'|' | tr -d '\n'; echo ')\b'`

gives _no_ clue. FTR the above translates here into:
https://codesearch.debian.net/search?q=\b(PORT_HSCIF|PORT_ASC|PORT_TILEGX|PORT_MEN_Z135|PORT_SC16IS7XX|PORT_MESON|PORT_DIGICOLOR|PORT_SPRD|PORT_CRIS|PORT_STM32|PORT_MVEBU|PORT_PIC32|PORT_MPS2UART|PORT_MTK_BTIF|PORT_RDA|PORT_MLB_USIO|PORT_SIFIVE_V0|PORT_SUNIX|PORT_LINFLEXUART|PORT_SUNPLUS)\b

thanks,

Signature · 2 lines
js
suse labs
#15 lore raw

Re: [PATCH v11 10/10] tty: serial: Add Nuvoton ma35d1 serial driver support

In reply to Jacky Huang

Dear Jiri,

Quoted 131 lines · Jacky Huang

Dear Jiri,

Thanks for your advice.

Quoted 15 lines · Jiri Slaby
Quoted 11 lines · Jacky Huang

+static void ma35d1serial_config_port(struct uart_port *port, int flags)
+{
+    /*
+     * Driver core for serial ports forces a non-zero value for port type.
+     * Write an arbitrary value here to accommodate the serial core driver,
+     * as ID part of UAPI is redundant.
+     */
+    port->type = 1;

So this 1 translates to PORT_8250. Why not to use it directly? Or something more saner like PORT_16550A?

It's not actually 8250 or 16550A.
Can we add the following definition to 'include/uapi/linux/serial_core.h' and use PORT_MA35 instead?

#define PORT_MA35    124

Quoted 11 lines
Quoted 10 lines
drivers/tty/serial/ma35d1_serial.c new file +3 -0
+}
+
+static int ma35d1serial_verify_port(struct uart_port *port, struct 

serial_struct *ser)

drivers/tty/serial/ma35d1_serial.c new file +6 -0
+{
+    if (port->type != PORT_UNKNOWN && ser->type != 1)
+        return -EINVAL;
+
+    return 0;
+}

...

Quoted 17 lines
Quoted 4 lines

+static int __init ma35d1serial_console_setup(struct console *co, char *options)

drivers/tty/serial/ma35d1_serial.c new file +2 -0
+{
+    struct device_node *np = ma35d1serial_uart_nodes[co->index];

drivers/tty/serial/ma35d1_serial.c line 579

Quoted 10 lines
drivers/tty/serial/ma35d1_serial.c new file +10 -0
+    struct uart_ma35d1_port *p = &ma35d1serial_ports[co->index];
+    u32 val32[4];
+    struct uart_port *port;
+    int baud = 115200;
+    int bits = 8;
+    int parity = 'n';
+    int flow = 'n';
+
+    /*
+     * Check whether an invalid uart number has been specified, and

You dereferenced ma35d1serial_uart_nodes already. Doesn't console=ttyNVT1000 (or something like that) crash the system?

I will add the following check before np = "ma35d1serial_uart_nodes[co->index]".

if (co->index < 0 || co->index >= MA35_UART_NR)
    return -EINVAL;

Quoted 4 lines
Quoted 2 lines

+     * if so, search for the first available port that does have +     * console support.

The code below doesn't match this comment.

Yes, I will remove the above comment.

Quoted 11 lines
Quoted 8 lines

+     */
+    if ((co->index < 0) || (co->index >= MA35_UART_NR)) { +        pr_debug("Console Port%x out of range\n", co->index); +        return -EINVAL;
+    }
+
+    if (of_property_read_u32_array(np, "reg", val32, 4) != 0)

Shouldn't that 4 be ARRAY_SIZE(val32) instead?

Will be fixed.

Quoted 4 lines
Quoted 1 line

+        return -EINVAL;

One \n here please.

Okay, I will add it.

Quoted 5 lines
Quoted 2 lines

+    p->port.iobase = val32[1];
+    p->port.membase = ioremap(p->port.iobase, MA35_UART_REG_SIZE);

What if this fails?

I will add a check for the return value.

Quoted 6 lines
Quoted 5 lines

+    p->port.ops = &ma35d1serial_ops;
+    p->port.line = 0;
+    p->port.uartclk = MA35_UART_CONSOLE_CLK;
+
+    port = &ma35d1serial_ports[co->index].port;

Quoted 6 lines

Isn't this:
  port = &p->port;
?

Either use port on all above lines or drop the "port" variable completely and use "p->port" below instead.

I will remove port variable and use p->port only.

Quoted 9 lines
Quoted 9 lines
drivers/tty/serial/ma35d1_serial.c new file +9 -0
+
+    if (options)
+        uart_parse_options(options, &baud, &parity, &bits, &flow);
+
+    return uart_set_options(port, co, baud, parity, bits, flow);
+}
+
+static struct console ma35d1serial_console = {
+    .name    = "ttyNVT",
Quoted 9 lines
Quoted 6 lines

+    .write   = ma35d1serial_console_write,
+    .device  = uart_console_device,
+    .setup   = ma35d1serial_console_setup,
+    .flags   = CON_PRINTBUFFER | CON_ENABLED,
+    .index   = -1,
+    .data    = &ma35d1serial_reg,

I don't see console->data used anywhere in the driver?

Quoted 2 lines

I will remove it.

I removed the " .data    = &ma35d1serial_reg", but kernel crashed in 'drivers/tty/serial/serial_core.c'.

The variable 'p' of  uart_console_device() refer to a NULL, because co->data is NULL. As a result, kernel crashed at 'p->tty_driver'.

struct tty_driver *uart_console_device(struct console *co, int *index) {
    struct uart_driver *p = co->data;
    *index = co->index;
    return p->tty_driver;
}

We seem to be unable to remove it.
If there are no other considerations, I will keep it in the next version.

Quoted 77 lines
Quoted 18 lines
Quoted 1 line

+};

...

Quoted 16 lines
drivers/tty/serial/ma35d1_serial.c new file +10 -0
+static int ma35d1serial_probe(struct platform_device *pdev)
+{
+    struct resource *res_mem;
+    struct uart_ma35d1_port *up;
+    int ret = 0;
+
+    if (pdev->dev.of_node) {
+        ret = of_alias_get_id(pdev->dev.of_node, "serial");
+        if (ret < 0) {
+            dev_err(&pdev->dev, "failed to get alias/pdev id, errno 

%d\n", ret);
+            return ret;
+        }
+    }
+    up = &ma35d1serial_ports[ret];
+    up->port.line = ret;

Quoted 9 lines
Quoted 6 lines

+    res_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); +    if (!res_mem)
+        return -ENODEV;
+
+    up->port.iobase = res_mem->start;
+    up->port.membase = ioremap(up->port.iobase, MA35_UART_REG_SIZE);

Check this too.

Okay, sure.

Quoted 38 lines
Quoted 38 lines

+    up->port.ops = &ma35d1serial_ops;

drivers/tty/serial/ma35d1_serial.c new file +37 -0
+
+    spin_lock_init(&up->port.lock);
+
+    up->clk = of_clk_get(pdev->dev.of_node, 0);
+    if (IS_ERR(up->clk)) {
+        ret = PTR_ERR(up->clk);
+        dev_err(&pdev->dev, "failed to get core clk: %d\n", ret);
+        goto err_iounmap;
+    }
+
+    ret = clk_prepare_enable(up->clk);
+    if (ret)
+        goto err_iounmap;
+
+    if (up->port.line != 0)
+        up->port.uartclk = clk_get_rate(up->clk);
+
+    ret = platform_get_irq(pdev, 0);
+    if (ret < 0)
+        goto err_clk_disable;
+
+    up->port.irq = ret;
+    up->port.dev = &pdev->dev;
+    up->port.flags = UPF_BOOT_AUTOCONF;
+
+    platform_set_drvdata(pdev, up);
+
+    ret = uart_add_one_port(&ma35d1serial_reg, &up->port);
+    if (ret < 0)
+        goto err_free_irq;
+
+    return 0;
+
+err_free_irq:
+    free_irq(up->port.irq, &up->port);
+
+err_clk_disable:
Quoted 8 lines

drivers/tty/serial/ma35d1_serial.c line 722

Quoted 6 lines

+    clk_disable_unprepare(up->clk);

drivers/tty/serial/ma35d1_serial.c new file +5 -0
+
+err_iounmap:
+    iounmap(up->port.membase);
+    return ret;
+}

thanks,

Quoted 3 lines

Best regards,
Jacky Huang

Best regards,
Jacky Huang

maintainer
#16 lore raw

Re: [PATCH v11 10/10] tty: serial: Add Nuvoton ma35d1 serial driver support

Hi,

Quoted 34 lines · Jacky Huang
Quoted 19 lines
Quoted 9 lines
Quoted 9 lines
drivers/tty/serial/ma35d1_serial.c new file +9 -0
+
+    if (options)
+        uart_parse_options(options, &baud, &parity, &bits, &flow);
+
+    return uart_set_options(port, co, baud, parity, bits, flow);
+}
+
+static struct console ma35d1serial_console = {
+    .name    = "ttyNVT",
Quoted 9 lines
Quoted 6 lines

+    .write   = ma35d1serial_console_write,
+    .device  = uart_console_device,
+    .setup   = ma35d1serial_console_setup,
+    .flags   = CON_PRINTBUFFER | CON_ENABLED,
+    .index   = -1,
+    .data    = &ma35d1serial_reg,

I don't see console->data used anywhere in the driver?

Quoted 2 lines

I will remove it.

I removed the " .data    = &ma35d1serial_reg", but kernel crashed in 'drivers/tty/serial/serial_core.c'.

The variable 'p' of  uart_console_device() refer to a NULL, because co->data is NULL. As a result, kernel crashed at 'p->tty_driver'.

struct tty_driver *uart_console_device(struct console *co, int *index) {
    struct uart_driver *p = co->data;
    *index = co->index;
    return p->tty_driver;
}

Quoted 2 lines

We seem to be unable to remove it.
If there are no other considerations, I will keep it in the next version.

Ah, yeah. Sorry, my bad.

Signature · 2 lines
js
suse labs