Introduce Nuvoton ma35d1 SoC
Subsystems (7)
v10 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-rc1-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
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 | 232 +++++
arch/arm64/configs/defconfig | 1 +
drivers/clk/Makefile | 1 +
drivers/clk/nuvoton/Kconfig | 19 +
drivers/clk/nuvoton/Makefile | 4 +
drivers/clk/nuvoton/clk-ma35d1-divider.c | 140 +++
drivers/clk/nuvoton/clk-ma35d1-pll.c | 365 +++++++
drivers/clk/nuvoton/clk-ma35d1.c | 948 ++++++++++++++++++
drivers/reset/Kconfig | 6 +
drivers/reset/Makefile | 1 +
drivers/reset/reset-ma35d1.c | 234 +++++
drivers/tty/serial/Kconfig | 18 +
drivers/tty/serial/Makefile | 1 +
drivers/tty/serial/ma35d1_serial.c | 796 +++++++++++++++
.../dt-bindings/clock/nuvoton,ma35d1-clk.h | 253 +++++
.../dt-bindings/reset/nuvoton,ma35d1-reset.h | 108 ++
27 files changed, 3449 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.hSignature · 1 line
2.34.1
PATCH v10 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
@@ -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
PATCH v10 2/10 arm64: defconfig: Add support for Nuvoton MA35 family SoCs
In reply to Jacky HuangFrom: 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
@@ -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
PATCH v10 3/10 dt-bindings: clock: nuvoton: add binding for ma35d1 clock controller
In reply to Jacky HuangFrom: 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
@@ -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
Rob Herring
maintainerRe: [PATCH v10 03/10] dt-bindings: clock: nuvoton: add binding for ma35d1 clock controller
Quoted 6 lines · 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.
Quoted 9 lines
Signed-off-by Jacky Huang <[email protected]>Reviewed-by Krzysztof Kozlowski <[email protected]>--- .../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
My bot found errors running 'make DT_CHECKER_FLAGS=-m dt_binding_check' on your patch (DT_CHECKER_FLAGS is new in v5.13):
yamllint warnings/errors:
dtschema/dtc warnings/errors:
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/media/i2c/ovti,ov2685.example.dtb: camera-sensor@3c: port:endpoint:data-lanes: [[1]] is too short
From schema: /builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/media/i2c/ovti,ov2685.yaml
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/media/rockchip-isp1.example.dtb: camera@3c: port:endpoint:data-lanes: [[1]] is too short
From schema: /builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/media/i2c/ovti,ov2685.yaml
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/pci/fsl,imx6q-pcie-ep.example.dtb: pcie-ep@33800000: Unevaluated properties are not allowed ('assigned-clock-parents', 'assigned-clock-rates', 'assigned-clocks' were unexpected)
From schema: /builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/pci/fsl,imx6q-pcie-ep.yaml
doc reference errors (make refcheckdocs):Documentation/usb/gadget_uvc.rst: Documentation/userspace-api/media/v4l/pixfmt-packed.yuv.rstMAINTAINERS: Documentation/devicetree/bindings/pwm/pwm-apple.yaml
See https://patchwork.ozlabs.org/project/devicetree-bindings/patch/[email protected]
The base for the series is generally the latest rc1. A different dependency should be noted in *this* patch.
If you already ran 'make dt_binding_check' and didn't see the above error(s), then make sure 'yamllint' is installed and dt-schema is up to date:
pip3 install dtschema --upgrade
Please check and re-submit after running the above command yourself. Note that DT_SCHEMA_FILES can be set to your schema file to speed up checking your schema. However, it must be unset to test all examples with your schema.
Re: [PATCH v10 03/10] dt-bindings: clock: nuvoton: add binding for ma35d1 clock controller
Quoted 23 lines · Rob Herring
Quoted 6 lines · 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.
Quoted 9 lines
Signed-off-by Jacky Huang <[email protected]>Reviewed-by Krzysztof Kozlowski <[email protected]>--- .../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.hMy bot found errors running 'make DT_CHECKER_FLAGS=-m
dt_binding_check' on your patch (DT_CHECKER_FLAGSis new in v5.13):yamllint warnings/errors:
Quoted 8 lines
dtschema/dtc warnings/errors:
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/media/i2c/ovti,ov2685.example.dtb: camera-sensor@3c: port:endpoint:data-lanes: [[1]] is too short
From schema: /builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/media/i2c/ovti,ov2685.yaml
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/media/rockchip-isp1.example.dtb: camera@3c: port:endpoint:data-lanes: [[1]] is too short
From schema: /builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/media/i2c/ovti,ov2685.yaml
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/pci/fsl,imx6q-pcie-ep.example.dtb: pcie-ep@33800000: Unevaluated properties are not allowed ('assigned-clock-parents', 'assigned-clock-rates', 'assigned-clocks' were unexpected)
From schema: /builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/pci/fsl,imx6q-pcie-ep.yaml
These are unrelated, you can ignore them.
Best regards,
Krzysztof
PATCH v10 4/10 dt-bindings: reset: nuvoton: Document ma35d1 reset control
In reply to Jacky HuangFrom: 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
@@ -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
Rob Herring
maintainerRe: [PATCH v10 04/10] dt-bindings: reset: nuvoton: Document ma35d1 reset control
Quoted 6 lines · 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.
Quoted 9 lines
Signed-off-by Jacky Huang <[email protected]>Reviewed-by Krzysztof Kozlowski <[email protected]>--- .../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
My bot found errors running 'make DT_CHECKER_FLAGS=-m dt_binding_check' on your patch (DT_CHECKER_FLAGS is new in v5.13):
yamllint warnings/errors:
dtschema/dtc warnings/errors:
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/media/i2c/ovti,ov2685.example.dtb: camera-sensor@3c: port:endpoint:data-lanes: [[1]] is too short
From schema: /builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/media/i2c/ovti,ov2685.yaml
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/media/rockchip-isp1.example.dtb: camera@3c: port:endpoint:data-lanes: [[1]] is too short
From schema: /builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/media/i2c/ovti,ov2685.yaml
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/pci/fsl,imx6q-pcie-ep.example.dtb: pcie-ep@33800000: Unevaluated properties are not allowed ('assigned-clock-parents', 'assigned-clock-rates', 'assigned-clocks' were unexpected)
From schema: /builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/pci/fsl,imx6q-pcie-ep.yaml
doc reference errors (make refcheckdocs):Documentation/usb/gadget_uvc.rst: Documentation/userspace-api/media/v4l/pixfmt-packed.yuv.rstMAINTAINERS: Documentation/devicetree/bindings/pwm/pwm-apple.yaml
See https://patchwork.ozlabs.org/project/devicetree-bindings/patch/[email protected]
The base for the series is generally the latest rc1. A different dependency should be noted in *this* patch.
If you already ran 'make dt_binding_check' and didn't see the above error(s), then make sure 'yamllint' is installed and dt-schema is up to date:
pip3 install dtschema --upgrade
Please check and re-submit after running the above command yourself. Note that DT_SCHEMA_FILES can be set to your schema file to speed up checking your schema. However, it must be unset to test all examples with your schema.
PATCH v10 5/10 dt-bindings: arm: Add initial bindings for Nuvoton platform
In reply to Jacky HuangFrom: 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
@@ -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
@@ -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
@@ -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
@@ -2509,6 +2509,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]>
@@ -2520,7 +2532,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
Rob Herring
maintainerRe: [PATCH v10 05/10] dt-bindings: arm: Add initial bindings for Nuvoton platform
Quoted 17 lines · 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.Signed-off-by Jacky Huang <[email protected]>Reviewed-by Krzysztof Kozlowski <[email protected]>Reviewed-by Rob Herring <[email protected]>
Quoted 10 lines
---
.../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%)My bot found errors running 'make DT_CHECKER_FLAGS=-m dt_binding_check' on your patch (DT_CHECKER_FLAGS is new in v5.13):
yamllint warnings/errors:
dtschema/dtc warnings/errors:
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/media/i2c/ovti,ov2685.example.dtb: camera-sensor@3c: port:endpoint:data-lanes: [[1]] is too short
From schema: /builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/media/i2c/ovti,ov2685.yaml
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/media/rockchip-isp1.example.dtb: camera@3c: port:endpoint:data-lanes: [[1]] is too short
From schema: /builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/media/i2c/ovti,ov2685.yaml
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/pci/fsl,imx6q-pcie-ep.example.dtb: pcie-ep@33800000: Unevaluated properties are not allowed ('assigned-clock-parents', 'assigned-clock-rates', 'assigned-clocks' were unexpected)
From schema: /builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/pci/fsl,imx6q-pcie-ep.yaml
doc reference errors (make refcheckdocs):Documentation/usb/gadget_uvc.rst: Documentation/userspace-api/media/v4l/pixfmt-packed.yuv.rstMAINTAINERS: Documentation/devicetree/bindings/pwm/pwm-apple.yaml
See https://patchwork.ozlabs.org/project/devicetree-bindings/patch/[email protected]
The base for the series is generally the latest rc1. A different dependency should be noted in *this* patch.
If you already ran 'make dt_binding_check' and didn't see the above error(s), then make sure 'yamllint' is installed and dt-schema is up to date:
pip3 install dtschema --upgrade
Please check and re-submit after running the above command yourself. Note that DT_SCHEMA_FILES can be set to your schema file to speed up checking your schema. However, it must be unset to test all examples with your schema.
PATCH v10 6/10 dt-bindings: serial: Document ma35d1 uart controller
In reply to Jacky HuangFrom: 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
@@ -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
Rob Herring
maintainerRe: [PATCH v10 06/10] dt-bindings: serial: Document ma35d1 uart controller
Quoted 11 lines · Jacky Huang
From: Jacky Huang <[email protected]>
Add documentation that describes the nuvoton ma35d1 UART driver bindings.
Signed-off-by Jacky Huang <[email protected]>Reviewed-by Krzysztof Kozlowski <[email protected]>--- .../serial/nuvoton,ma35d1-serial.yaml | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 Documentation/devicetree/bindings/serial/nuvoton,ma35d1-serial.yaml
My bot found errors running 'make DT_CHECKER_FLAGS=-m dt_binding_check' on your patch (DT_CHECKER_FLAGS is new in v5.13):
yamllint warnings/errors:
dtschema/dtc warnings/errors:
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/media/i2c/ovti,ov2685.example.dtb: camera-sensor@3c: port:endpoint:data-lanes: [[1]] is too short
From schema: /builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/media/i2c/ovti,ov2685.yaml
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/media/rockchip-isp1.example.dtb: camera@3c: port:endpoint:data-lanes: [[1]] is too short
From schema: /builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/media/i2c/ovti,ov2685.yaml
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/pci/fsl,imx6q-pcie-ep.example.dtb: pcie-ep@33800000: Unevaluated properties are not allowed ('assigned-clock-parents', 'assigned-clock-rates', 'assigned-clocks' were unexpected)
From schema: /builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/pci/fsl,imx6q-pcie-ep.yamlDocumentation/devicetree/bindings/serial/nuvoton,ma35d1-serial.example.dts:25:18: fatal error: dt-bindings/clock/nuvoton,ma35d1-clk.h: No such file or directory
25 | #include <dt-bindings/clock/nuvoton,ma35d1-clk.h>
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make[1]: *** [scripts/Makefile.lib:419: Documentation/devicetree/bindings/serial/nuvoton,ma35d1-serial.example.dtb] Error 1 make[1]: *** Waiting for unfinished jobs....
make: *** [Makefile:1512: dt_binding_check] Error 2
doc reference errors (make refcheckdocs):Documentation/usb/gadget_uvc.rst: Documentation/userspace-api/media/v4l/pixfmt-packed.yuv.rstMAINTAINERS: Documentation/devicetree/bindings/pwm/pwm-apple.yaml
See https://patchwork.ozlabs.org/project/devicetree-bindings/patch/[email protected]
The base for the series is generally the latest rc1. A different dependency should be noted in *this* patch.
If you already ran 'make dt_binding_check' and didn't see the above error(s), then make sure 'yamllint' is installed and dt-schema is up to date:
pip3 install dtschema --upgrade
Please check and re-submit after running the above command yourself. Note that DT_SCHEMA_FILES can be set to your schema file to speed up checking your schema. However, it must be unset to test all examples with your schema.
Re: [PATCH v10 06/10] dt-bindings: serial: Document ma35d1 uart controller
Quoted 28 lines · Rob Herring
Quoted 11 lines · Jacky Huang
From: Jacky Huang <[email protected]>
Add documentation that describes the nuvoton ma35d1 UART driver bindings.
Signed-off-by Jacky Huang <[email protected]>Reviewed-by Krzysztof Kozlowski <[email protected]>--- .../serial/nuvoton,ma35d1-serial.yaml | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 Documentation/devicetree/bindings/serial/nuvoton,ma35d1-serial.yamlMy bot found errors running 'make DT_CHECKER_FLAGS=-m
dt_binding_check' on your patch (DT_CHECKER_FLAGSis new in v5.13):yamllint warnings/errors:
dtschema/dtc warnings/errors:
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/media/i2c/ovti,ov2685.example.dtb: camera-sensor@3c: port:endpoint:data-lanes: [[1]] is too short
From schema: /builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/media/i2c/ovti,ov2685.yaml
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/media/rockchip-isp1.example.dtb: camera@3c: port:endpoint:data-lanes: [[1]] is too short
From schema: /builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/media/i2c/ovti,ov2685.yaml
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/pci/fsl,imx6q-pcie-ep.example.dtb: pcie-ep@33800000: Unevaluated properties are not allowed ('assigned-clock-parents', 'assigned-clock-rates', 'assigned-clocks' were unexpected)
From schema: /builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/pci/fsl,imx6q-pcie-ep.yamlDocumentation/devicetree/bindings/serial/nuvoton,ma35d1-serial.example.dts:25:18: fatal error:dt-bindings/clock/nuvoton,ma35d1-clk.h: No such file or directory
25 | #include <dt-bindings/clock/nuvoton,ma35d1-clk.h>
Quoted 3 lines
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~compilation terminated.
make[1]: *** [scripts/Makefile.lib:419:Documentation/devicetree/bindings/serial/nuvoton,ma35d1-serial.example.dtb] Error 1
This however is related, although might be coming from earlier failure. I assume you run the check and you do not see any errors?
Best regards,
Krzysztof
Re: [PATCH v10 06/10] dt-bindings: serial: Document ma35d1 uart controller
Quoted 30 lines · Krzysztof Kozlowski
Quoted 17 lines · Rob Herring
Quoted 11 lines · Jacky Huang
From: Jacky Huang <[email protected]>
Add documentation that describes the nuvoton ma35d1 UART driver bindings.
Signed-off-by Jacky Huang <[email protected]>Reviewed-by Krzysztof Kozlowski <[email protected]>--- .../serial/nuvoton,ma35d1-serial.yaml | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+)create mode 100644
Documentation/devicetree/bindings/serial/nuvoton,ma35d1-serial.yamlMy bot found errors running 'make DT_CHECKER_FLAGS=-m
dt_binding_check' on your patch (DT_CHECKER_FLAGSis new in v5.13):yamllint warnings/errors:
Quoted 12 lines
dtschema/dtc warnings/errors:
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/media/i2c/ovti,ov2685.example.dtb: camera-sensor@3c: port:endpoint:data-lanes: [[1]] is too short
From schema: /builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/media/i2c/ovti,ov2685.yaml
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/media/rockchip-isp1.example.dtb: camera@3c: port:endpoint:data-lanes: [[1]] is too short
From schema: /builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/media/i2c/ovti,ov2685.yaml
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/pci/fsl,imx6q-pcie-ep.example.dtb: pcie-ep@33800000: Unevaluated properties are not allowed ('assigned-clock-parents', 'assigned-clock-rates', 'assigned-clocks' were unexpected)
From schema: /builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/pci/fsl,imx6q-pcie-ep.yamlDocumentation/devicetree/bindings/serial/nuvoton,ma35d1-serial.example.dts:25:18: fatal error:dt-bindings/clock/nuvoton,ma35d1-clk.h: No such file or directory
25 | #include <dt-bindings/clock/nuvoton,ma35d1-clk.h>
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make[1]: *** [scripts/Makefile.lib:419:Documentation/devicetree/bindings/serial/nuvoton,ma35d1-serial.example.dtb] Error 1
Quoted 6 lines
This however is related, although might be coming from earlier failure. I assume you run the check and you do not see any errors?
Best regards,
Krzysztof
Dear Krzysztof,
Thank you for your review.
Of course I have run the check.
I did not see any errors, because I have "dt-bindings/clock/nuvoton,ma35d1-clk.h". This patch 6/10 depends on path 3/10 which include "dt-bindings/clock/nuvoton,ma35d1-clk.h". Should I combine this patch 6/10 into patch 3/10?
Best Regards,
Jacky Huang
Re: [PATCH v10 06/10] dt-bindings: serial: Document ma35d1 uart controller
Quoted 42 lines · Jacky Huang
Quoted 30 lines · Krzysztof Kozlowski
Quoted 17 lines · Rob Herring
Quoted 11 lines · Jacky Huang
From: Jacky Huang <[email protected]>
Add documentation that describes the nuvoton ma35d1 UART driver bindings.
Signed-off-by Jacky Huang <[email protected]>Reviewed-by Krzysztof Kozlowski <[email protected]>--- .../serial/nuvoton,ma35d1-serial.yaml | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+)create mode 100644
Documentation/devicetree/bindings/serial/nuvoton,ma35d1-serial.yamlMy bot found errors running 'make DT_CHECKER_FLAGS=-m
dt_binding_check' on your patch (DT_CHECKER_FLAGSis new in v5.13):yamllint warnings/errors:
Quoted 12 lines
dtschema/dtc warnings/errors:
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/media/i2c/ovti,ov2685.example.dtb: camera-sensor@3c: port:endpoint:data-lanes: [[1]] is too short
From schema: /builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/media/i2c/ovti,ov2685.yaml
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/media/rockchip-isp1.example.dtb: camera@3c: port:endpoint:data-lanes: [[1]] is too short
From schema: /builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/media/i2c/ovti,ov2685.yaml
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/pci/fsl,imx6q-pcie-ep.example.dtb: pcie-ep@33800000: Unevaluated properties are not allowed ('assigned-clock-parents', 'assigned-clock-rates', 'assigned-clocks' were unexpected)
From schema: /builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/pci/fsl,imx6q-pcie-ep.yamlDocumentation/devicetree/bindings/serial/nuvoton,ma35d1-serial.example.dts:25:18: fatal error:dt-bindings/clock/nuvoton,ma35d1-clk.h: No such file or directory
25 | #include <dt-bindings/clock/nuvoton,ma35d1-clk.h>
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make[1]: *** [scripts/Makefile.lib:419:Documentation/devicetree/bindings/serial/nuvoton,ma35d1-serial.example.dtb] Error 1Quoted 6 lines
This however is related, although might be coming from earlier failure. I assume you run the check and you do not see any errors?
Best regards,
KrzysztofDear Krzysztof,
Quoted 8 lines
Thank you for your review.
Of course I have run the check.
I did not see any errors, because I have "dt-bindings/clock/nuvoton,ma35d1-clk.h". This patch 6/10 depends on path 3/10 which include "dt-bindings/clock/nuvoton,ma35d1-clk.h". Should I combine this patch 6/10 into patch 3/10?
No, it's fine. If you got the reviews and acks and no reports from kernel test robot, you can go in few days with Arnd's request and send everything to soc@.
Best regards,
Krzysztof
Re: [PATCH v10 06/10] dt-bindings: serial: Document ma35d1 uart controller
Quoted 49 lines · Krzysztof Kozlowski
Quoted 40 lines · Jacky Huang
Quoted 30 lines · Krzysztof Kozlowski
Quoted 17 lines · Rob Herring
Quoted 11 lines · Jacky Huang
From: Jacky Huang <[email protected]>
Add documentation that describes the nuvoton ma35d1 UART driver bindings.
Signed-off-by Jacky Huang <[email protected]>Reviewed-by Krzysztof Kozlowski <[email protected]>--- .../serial/nuvoton,ma35d1-serial.yaml | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+)create mode 100644
Documentation/devicetree/bindings/serial/nuvoton,ma35d1-serial.yamlMy bot found errors running 'make DT_CHECKER_FLAGS=-m
dt_binding_check' on your patch (DT_CHECKER_FLAGSis new in v5.13):yamllint warnings/errors:
Quoted 12 lines
dtschema/dtc warnings/errors:
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/media/i2c/ovti,ov2685.example.dtb: camera-sensor@3c: port:endpoint:data-lanes: [[1]] is too short
From schema: /builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/media/i2c/ovti,ov2685.yaml
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/media/rockchip-isp1.example.dtb: camera@3c: port:endpoint:data-lanes: [[1]] is too short
From schema: /builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/media/i2c/ovti,ov2685.yaml
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/pci/fsl,imx6q-pcie-ep.example.dtb: pcie-ep@33800000: Unevaluated properties are not allowed ('assigned-clock-parents', 'assigned-clock-rates', 'assigned-clocks' were unexpected)
From schema: /builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/pci/fsl,imx6q-pcie-ep.yamlDocumentation/devicetree/bindings/serial/nuvoton,ma35d1-serial.example.dts:25:18: fatal error:dt-bindings/clock/nuvoton,ma35d1-clk.h: No such file or directory
25 | #include <dt-bindings/clock/nuvoton,ma35d1-clk.h>
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make[1]: *** [scripts/Makefile.lib:419:Documentation/devicetree/bindings/serial/nuvoton,ma35d1-serial.example.dtb] Error 1Quoted 6 lines
This however is related, although might be coming from earlier failure. I assume you run the check and you do not see any errors?
Best regards,
KrzysztofDear Krzysztof,
Quoted 8 lines
Thank you for your review.
Of course I have run the check.
I did not see any errors, because I have "dt-bindings/clock/nuvoton,ma35d1-clk.h". This patch 6/10 depends on path 3/10 which include "dt-bindings/clock/nuvoton,ma35d1-clk.h". Should I combine this patch 6/10 into patch 3/10?
Quoted 7 lines
No, it's fine. If you got the reviews and acks and no reports from kernel test robot, you can go in few days with Arnd's request and send everything to soc@.
Best regards,
Krzysztof
Dear Krzysztof,
I got it. Thank you very much.
Best Regards,
Jacky Huang
PATCH v10 7/10 arm64: dts: nuvoton: Add initial ma35d1 device tree
In reply to Jacky HuangFrom: 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 | 232 ++++++++++++++++++ 4 files changed, 346 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
@@ -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 +232 -0
232 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v10 8/10 clk: nuvoton: Add clock driver for ma35d1 clock controller
In reply to Jacky HuangFrom: 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/Makefile | 1 + drivers/clk/nuvoton/Kconfig | 19 + drivers/clk/nuvoton/Makefile | 4 + drivers/clk/nuvoton/clk-ma35d1-divider.c | 140 ++++ drivers/clk/nuvoton/clk-ma35d1-pll.c | 365 +++++++++ drivers/clk/nuvoton/clk-ma35d1.c | 948 +++++++++++++++++++++++ 6 files changed, 1477 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/Makefile +1 -0
@@ -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
@@ -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
@@ -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 +140 -0
140 lines not on this page · raw message
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +365 -0
365 lines not on this page · raw message
drivers/clk/nuvoton/clk-ma35d1.c new file +948 -0
948 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [PATCH v10 08/10] clk: nuvoton: Add clock driver for ma35d1 clock controller
Quoted 18 lines · 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.
Quoted 3 lines
Signed-off-by Jacky Huang <[email protected]>---
Hi,
A few small things still below.
Quoted 227 lines
drivers/clk/nuvoton/clk-ma35d1-divider.c new file +140
-0@@ -0,0 +1,140 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Copyright (C) 2023 Nuvoton Technology Corp. +* Author: Chi-Fang Li <[email protected]> +*/ + +#include <linux/clk-provider.h> +#include <linux/device.h> +#include <linux/regmap.h> +#include <linux/spinlock.h> + +struct ma35d1_adc_clk_div { +struct clk_hw hw; +void __iomem *reg; +u8 shift; +u8 width; +u32 mask; +const struct clk_div_table *table; +/* protects concurrent access to clock divider registers */ +spinlock_t *lock; +}; + +struct clk_hw *ma35d1_reg_adc_clkdiv (struct device *dev,const char *name, +struct clk_hw *parent_hw,spinlock_t *lock, +unsigned long flags,void __iomem *reg, +u8 shift,u8 width,u32 mask_bit); + +static inline struct ma35d1_adc_clk_div *to_ma35d1_adc_clk_div (struct clk_hw *_hw) +{ + return container_of(_hw, struct ma35d1_adc_clk_div, hw); +} + +static inline unsigned long ma35d1_clkdiv_recalc_rate (struct clk_hw *hw, +unsigned long parent_rate) +{ +unsigned int val; +struct ma35d1_adc_clk_div *dclk =to_ma35d1_adc_clk_div (hw); + + val =readl_relaxed (dclk->reg) >> dclk->shift; + val &=clk_div_mask (dclk->width); + val +=1 ; +return divider_recalc_rate (hw, parent_rate, val, dclk->table, +CLK_DIVIDER_ROUND_CLOSEST , dclk->width); +} + +static inline long ma35d1_clkdiv_round_rate (struct clk_hw *hw, +unsigned long rate, +unsigned long *prate) +{ +struct ma35d1_adc_clk_div *dclk =to_ma35d1_adc_clk_div (hw); + +return divider_round_rate (hw, rate, prate, dclk->table, + dclk->width,CLK_DIVIDER_ROUND_CLOSEST ); +} + +static inline int ma35d1_clkdiv_set_rate (struct clk_hw *hw, +unsigned long rate, +unsigned long parent_rate) +{ +int value; +unsigned long flags =0 ; +u32 data; +struct ma35d1_adc_clk_div *dclk =to_ma35d1_adc_clk_div (hw); + + value =divider_get_val (rate, parent_rate, dclk->table, + dclk->width,CLK_DIVIDER_ROUND_CLOSEST ); + +spin_lock_irqsave (dclk->lock, flags); + + data =readl_relaxed (dclk->reg); + data &= ~(clk_div_mask (dclk->width) << dclk->shift); + data |= (value -1 ) << dclk->shift; + data |= dclk->mask; +writel_relaxed (data, dclk->reg); + +spin_unlock_irqrestore (dclk->lock, flags); +return 0 ; +} + +static const struct clk_ops ma35d1_adc_clkdiv_ops = { + .recalc_rate = ma35d1_clkdiv_recalc_rate, + .round_rate = ma35d1_clkdiv_round_rate, + .set_rate = ma35d1_clkdiv_set_rate, +}; + +struct clk_hw *ma35d1_reg_adc_clkdiv (struct device *dev,const char *name, +struct clk_hw *parent_hw,spinlock_t *lock, +unsigned long flags,void __iomem *reg, +u8 shift,u8 width,u32 mask_bit) +{ +struct ma35d1_adc_clk_div *div; +struct clk_init_data init; +struct clk_div_table *table; +struct clk_parent_data pdata = { .index =0 }; +u32 max_div, min_div; +struct clk_hw *hw; +int ret; +int i; + + div =devm_kzalloc (dev,sizeof (*div),GFP_KERNEL ); +if (!div) +return ERR_PTR (-ENOMEM ); + + max_div =clk_div_mask (width) +1 ; + min_div =1 ; + + table =devm_kcalloc (dev, max_div +1 ,sizeof (*table),GFP_KERNEL ); +if (!table) +return ERR_PTR (-ENOMEM ); + +for (i =0 ; i < max_div; i++) { + table[i].val = min_div + i; + table[i].div =2 * table[i].val; + } + table[max_div].val =0 ; + table[max_div].div =0 ; + +memset (&init,0 ,sizeof (init)); + init.name = name; + init.ops = &ma35d1_adc_clkdiv_ops; + init.flags |= flags; + pdata.hw = parent_hw; + init.parent_data = &pdata; + init.num_parents =1 ; + + div->reg = reg; + div->shift = shift; + div->width = width; + div->mask = mask_bit ?BIT (mask_bit) :0 ; + div->lock = lock; + div->hw.init = &init; + div->table = table; + + hw = &div->hw; + ret =devm_clk_hw_register (dev, hw); +if (ret) +return ERR_PTR (ret); +return hw; +} +EXPORT_SYMBOL_GPL (ma35d1_reg_adc_clkdiv);drivers/clk/nuvoton/clk-ma35d1-pll.c new file +75
-0@@ -0,0 +1,365 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Copyright (C) 2023 Nuvoton Technology Corp. +* Author: Chi-Fang Li <[email protected]> +*/ + +#include <linux/bitfield.h> +#include <linux/clk-provider.h> +#include <linux/container_of.h> +#include <linux/device.h> +#include <linux/io.h> +#include <linux/kernel.h> +#include <linux/math64.h> +#include <linux/slab.h> +#include <linux/units.h> +#include <dt-bindings/clock/nuvoton,ma35d1-clk.h> + +/* PLL frequency limits */ +#define PLL_FREF_MAX_FREQ (200 * HZ_PER_MHZ) +#define PLL_FREF_MIN_FREQ (1 * HZ_PER_MHZ) +#define PLL_FREF_M_MAX_FREQ (40 * HZ_PER_MHZ) +#define PLL_FREF_M_MIN_FREQ (10 * HZ_PER_MHZ) +#define PLL_FCLK_MAX_FREQ (2400 * HZ_PER_MHZ) +#define PLL_FCLK_MIN_FREQ (600 * HZ_PER_MHZ) +#define PLL_FCLKO_MAX_FREQ (2400 * HZ_PER_MHZ) +#define PLL_FCLKO_MIN_FREQ (85700 * HZ_PER_KHZ) +#define PLL_SS_RATE 0x77 +#define PLL_SLOPE 0x58CFA + +#define REG_PLL_CTL0_OFFSET 0x0 +#define REG_PLL_CTL1_OFFSET 0x4 +#define REG_PLL_CTL2_OFFSET 0x8 + +/* bit fields for REG_CLK_PLL0CTL0, which is SMIC PLL design */ +#define SPLL0_CTL0_FBDIV GENMASK(7, 0) +#define SPLL0_CTL0_INDIV GENMASK(11, 8) +#define SPLL0_CTL0_OUTDIV GENMASK(13, 12) +#define SPLL0_CTL0_PD BIT(16) +#define SPLL0_CTL0_BP BIT(17) + +/* bit fields for REG_CLK_PLLxCTL0 ~ REG_CLK_PLLxCTL2, where x = 2 ~ 5 */ +#define PLL_CTL0_FBDIV GENMASK(10, 0) +#define PLL_CTL0_INDIV GENMASK(17, 12) +#define PLL_CTL0_MODE GENMASK(19, 18) +#define PLL_CTL0_SSRATE GENMASK(30, 20) +#define PLL_CTL1_PD BIT(0) +#define PLL_CTL1_BP BIT(1) +#define PLL_CTL1_OUTDIV GENMASK(6, 4) +#define PLL_CTL1_FRAC GENMASK(31, 24) +#define PLL_CTL2_SLOPE GENMASK(23, 0) + +#define INDIV_MIN 1 +#define INDIV_MAX 63 +#define FBDIV_MIN 16 +#define FBDIV_MAX 2047 +#define FBDIV_FRAC_MIN 1600 +#define FBDIV_FRAC_MAX 204700 +#define OUTDIV_MIN 1 +#define OUTDIV_MAX 7 + +#define PLL_MODE_INT 0 +#define PLL_MODE_FRAC 1 +#define PLL_MODE_SS 2 + +struct ma35d1_clk_pll { +struct clk_hw hw; +u32 id; +u8 mode; +void __iomem *ctl0_base; +void __iomem *ctl1_base; +void __iomem *ctl2_base; +}; + +struct clk_hw *ma35d1_reg_clk_pll (struct device *dev,u32 id,u8 u8mode,const char *name, +struct clk_hw *parent_hw,void __iomem *base);
drivers/clk/nuvoton/clk-ma35d1-pll.c line 85
Quoted 10 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +10
-0+ +static inline struct ma35d1_clk_pll *to_ma35d1_clk_pll (struct clk_hw *_hw) +{ + return container_of(_hw, struct ma35d1_clk_pll, hw); +} + +static unsigned long ma35d1_calc_smic_pll_freq (u32 pll0_ctl0, +unsigned long parent_rate) +{ +const u32 clk_div_table[] = {1 ,2 ,4 ,8 };
This is just 1 << n so the table doesn't seem necessary.
Quoted 26 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +26
-0+u32 m, n, p, outdiv; +u64 pll_freq; + +if (pll0_ctl0 &SPLL0_CTL0_BP ) +return parent_rate; + + n =FIELD_GET (SPLL0_CTL0_FBDIV , pll0_ctl0); + m =FIELD_GET (SPLL0_CTL0_INDIV , pll0_ctl0); + p =FIELD_GET (SPLL0_CTL0_OUTDIV , pll0_ctl0); + outdiv = clk_div_table[p]; + pll_freq = (u64 )parent_rate * n; +div_u64 (pll_freq, m * outdiv); +return pll_freq; +} + +static unsigned long ma35d1_calc_pll_freq (u8 mode,u32 *reg_ctl,unsigned long parent_rate) +{ +unsigned long pll_freq, x; +u32 m, n, p; + +if (reg_ctl[1 ] &PLL_CTL1_BP ) +return parent_rate; + + n =FIELD_GET (PLL_CTL0_FBDIV , reg_ctl[0 ]); + m =FIELD_GET (PLL_CTL0_INDIV , reg_ctl[0 ]); + p =FIELD_GET (PLL_CTL1_OUTDIV , reg_ctl[1 ]);
drivers/clk/nuvoton/clk-ma35d1-pll.c line 121
Quoted 10 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +10
-0+ +if (mode ==PLL_MODE_INT ) { + pll_freq = (u64 )parent_rate * n; +div_u64 (pll_freq, m * p); + }else { + x =FIELD_GET (PLL_CTL1_FRAC , reg_ctl[1 ]); +/* 2 decimal places floating to integer (ex. 1.23 to 123) */ + n = n *100 + ((x *100 ) /FIELD_MAX (PLL_CTL1_FRAC )); + +/* pll_freq = parent_rate * n / 100 / m / p */
Repeats what the code does, drop.
Quoted 67 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +67
-0+ pll_freq =div_u64 (parent_rate * n,100 * m * p); + } +return pll_freq; +} + +static int ma35d1_pll_find_closest (struct ma35d1_clk_pll *pll,unsigned long rate, +unsigned long parent_rate,u32 *reg_ctl, +unsigned long *freq) +{ +unsigned long min_diff =ULONG_MAX ; +int fbdiv_min, fbdiv_max; +int p, m, n; + + *freq =0 ; +if (rate <PLL_FCLKO_MIN_FREQ || rate >PLL_FCLKO_MAX_FREQ ) +return -EINVAL ; + +if (pll->mode ==PLL_MODE_INT ) { + fbdiv_min =FBDIV_MIN ; + fbdiv_max =FBDIV_MAX ; + }else { + fbdiv_min =FBDIV_FRAC_MIN ; + fbdiv_max =FBDIV_FRAC_MAX ; + } + +for (m =INDIV_MIN ; m <=INDIV_MAX ; m++) { +for (n = fbdiv_min; n <= fbdiv_max; n++) { +for (p =OUTDIV_MIN ; p <=OUTDIV_MAX ; p++) { +unsigned long tmp, fout, fclk, diff; + + tmp =div_u64 (parent_rate, m); +if (tmp <PLL_FREF_M_MIN_FREQ || + tmp >PLL_FREF_M_MAX_FREQ ) +continue ;/* constrain */ + + fclk =div_u64 (parent_rate * n, m); +/* for 2 decimal places */ +if (pll->mode !=PLL_MODE_INT ) + fclk =div_u64 (fclk,100 ); + +if (fclk <PLL_FCLK_MIN_FREQ || + fclk >PLL_FCLK_MAX_FREQ ) +continue ;/* constrain */ + + fout =div_u64 (fclk, p); +if (fout <PLL_FCLKO_MIN_FREQ || + fout >PLL_FCLKO_MAX_FREQ ) +continue ;/* constrain */ + + diff =abs (rate - fout); +if (diff < min_diff) { + reg_ctl[0 ] =FIELD_PREP (PLL_CTL0_INDIV , m) | +FIELD_PREP (PLL_CTL0_FBDIV , n); + reg_ctl[1 ] =FIELD_PREP (PLL_CTL1_OUTDIV , p); + *freq = fout; + min_diff = diff; +if (min_diff ==0 ) +break ; + } + } + } + } +if (*freq ==0 ) +return -EINVAL ;/* cannot find even one valid setting */ +return 0 ; +} +
drivers/clk/nuvoton/clk-ma35d1-pll.c line 198
Quoted 10 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +10
-0+static int ma35d1_clk_pll_set_rate (struct clk_hw *hw,unsigned long rate, +unsigned long parent_rate) +{ +struct ma35d1_clk_pll *pll =to_ma35d1_clk_pll (hw); +u32 reg_ctl[3 ] = {0 }; +unsigned long pll_freq; +int ret; + +if (parent_rate <PLL_FREF_MIN_FREQ || + parent_rate >PLL_FREF_MAX_FREQ )
One line.
Quoted 56 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +56
-0+return -EINVAL ; + + ret =ma35d1_pll_find_closest (pll, rate, parent_rate, reg_ctl, &pll_freq); +if (ret !=0 ) +return ret; + +switch (pll->mode) { +case PLL_MODE_INT : + reg_ctl[0 ] |=FIELD_PREP (PLL_CTL0_MODE ,PLL_MODE_INT ); +break ; +case PLL_MODE_FRAC : + reg_ctl[0 ] |=FIELD_PREP (PLL_CTL0_MODE ,PLL_MODE_FRAC ); +break ; +case PLL_MODE_SS : + reg_ctl[0 ] |=FIELD_PREP (PLL_CTL0_MODE ,PLL_MODE_SS ) | +FIELD_PREP (PLL_CTL0_SSRATE ,PLL_SS_RATE ); + reg_ctl[2 ] =FIELD_PREP (PLL_CTL2_SLOPE ,PLL_SLOPE ); +break ; + } + reg_ctl[1 ] |=PLL_CTL1_PD ; + +writel_relaxed (reg_ctl[0 ], pll->ctl0_base); +writel_relaxed (reg_ctl[1 ], pll->ctl1_base); +writel_relaxed (reg_ctl[2 ], pll->ctl2_base); +return 0 ; +} + +static unsigned long ma35d1_clk_pll_recalc_rate (struct clk_hw *hw,unsigned long parent_rate) +{ +struct ma35d1_clk_pll *pll =to_ma35d1_clk_pll (hw); +u32 reg_ctl[3 ]; +unsigned long pll_freq; + +if (parent_rate <PLL_FREF_MIN_FREQ || parent_rate >PLL_FREF_MAX_FREQ ) +return 0 ; + +switch (pll->id) { +case CAPLL : + reg_ctl[0 ] =readl_relaxed (pll->ctl0_base); + pll_freq =ma35d1_calc_smic_pll_freq (reg_ctl[0 ], parent_rate); +return pll_freq; +case DDRPLL : +case APLL : +case EPLL : +case VPLL : + reg_ctl[0 ] =readl_relaxed (pll->ctl0_base); + reg_ctl[1 ] =readl_relaxed (pll->ctl1_base); + pll_freq =ma35d1_calc_pll_freq (pll->mode, reg_ctl, parent_rate); +return pll_freq; + } +return 0 ; +} + +static long ma35d1_clk_pll_round_rate (struct clk_hw *hw,unsigned long rate, +unsigned long *parent_rate) +{
drivers/clk/nuvoton/clk-ma35d1-pll.c line 264
Quoted 10 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +10
-0+struct ma35d1_clk_pll *pll =to_ma35d1_clk_pll (hw); +u32 reg_ctl[3 ] = {0 }; +unsigned long pll_freq; +long ret; + +if (*parent_rate <PLL_FREF_MIN_FREQ || *parent_rate >PLL_FREF_MAX_FREQ ) +return -EINVAL ; + + ret =ma35d1_pll_find_closest (pll, rate, *parent_rate, reg_ctl, &pll_freq); +if (ret !=0 )
< 0
Quoted 179 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +101
-0+return ret; + +switch (pll->id) { +case CAPLL : + reg_ctl[0 ] =readl_relaxed (pll->ctl0_base); + pll_freq =ma35d1_calc_smic_pll_freq (reg_ctl[0 ], *parent_rate); +return pll_freq; +case DDRPLL : +case APLL : +case EPLL : +case VPLL : + reg_ctl[0 ] =readl_relaxed (pll->ctl0_base); + reg_ctl[1 ] =readl_relaxed (pll->ctl1_base); + pll_freq =ma35d1_calc_pll_freq (pll->mode, reg_ctl, *parent_rate); +return pll_freq; + } +return 0 ; +} + +static int ma35d1_clk_pll_is_prepared (struct clk_hw *hw) +{ +struct ma35d1_clk_pll *pll =to_ma35d1_clk_pll (hw); +u32 val =readl_relaxed (pll->ctl1_base); + +return !(val &PLL_CTL1_PD ); +} + +static int ma35d1_clk_pll_prepare (struct clk_hw *hw) +{ +struct ma35d1_clk_pll *pll =to_ma35d1_clk_pll (hw); +u32 val; + + val =readl_relaxed (pll->ctl1_base); + val &= ~PLL_CTL1_PD ; +writel_relaxed (val, pll->ctl1_base); +return 0 ; +} + +static void ma35d1_clk_pll_unprepare (struct clk_hw *hw) +{ +struct ma35d1_clk_pll *pll =to_ma35d1_clk_pll (hw); +u32 val; + + val =readl_relaxed (pll->ctl1_base); + val |=PLL_CTL1_PD ; +writel_relaxed (val, pll->ctl1_base); +} + +static const struct clk_ops ma35d1_clk_pll_ops = { + .is_prepared = ma35d1_clk_pll_is_prepared, + .prepare = ma35d1_clk_pll_prepare, + .unprepare = ma35d1_clk_pll_unprepare, + .set_rate = ma35d1_clk_pll_set_rate, + .recalc_rate = ma35d1_clk_pll_recalc_rate, + .round_rate = ma35d1_clk_pll_round_rate, +}; + +static const struct clk_ops ma35d1_clk_fixed_pll_ops = { + .recalc_rate = ma35d1_clk_pll_recalc_rate, + .round_rate = ma35d1_clk_pll_round_rate, +}; + +struct clk_hw *ma35d1_reg_clk_pll (struct device *dev,u32 id,u8 u8mode,const char *name, +struct clk_hw *parent_hw,void __iomem *base) +{ +struct clk_parent_data pdata = { .index =0 }; +struct clk_init_data init = {}; +struct ma35d1_clk_pll *pll; +struct clk_hw *hw; +int ret; + + pll =devm_kzalloc (dev,sizeof (*pll),GFP_KERNEL ); +if (!pll) +return ERR_PTR (-ENOMEM ); + + pll->id = id; + pll->mode = u8mode; + pll->ctl0_base = base +REG_PLL_CTL0_OFFSET ; + pll->ctl1_base = base +REG_PLL_CTL1_OFFSET ; + pll->ctl2_base = base +REG_PLL_CTL2_OFFSET ; + + init.name = name; + init.flags =0 ; + pdata.hw = parent_hw; + init.parent_data = &pdata; + init.num_parents =1 ; + +if (id ==CAPLL || id ==DDRPLL ) + init.ops = &ma35d1_clk_fixed_pll_ops; +else + init.ops = &ma35d1_clk_pll_ops; + + pll->hw.init = &init; + hw = &pll->hw; + + ret =devm_clk_hw_register (dev, hw); +if (ret) +return ERR_PTR (ret); +return hw; +} +EXPORT_SYMBOL_GPL (ma35d1_reg_clk_pll);drivers/clk/nuvoton/clk-ma35d1.c new file +70
-0@@ -0,0 +1,948 @@ +static inline struct clk_hw *ma35d1_clk_fixed (const char *name,int rate) +{ +return clk_hw_register_fixed_rate (NULL , name,NULL ,0 , rate); +} + +static inline struct clk_hw *ma35d1_clk_mux_parent (struct device *dev, +const char *name, +void __iomem *reg, +u8 shift,u8 width, +const struct clk_parent_data *pdata, +int num_pdata) +{ +return clk_hw_register_mux_parent_data (dev, name, pdata, num_pdata, +CLK_SET_RATE_NO_REPARENT , reg, shift, + width,0 , &ma35d1_lock); +} + +static inline struct clk_hw *ma35d1_clk_mux (struct device *dev, +const char *name, +void __iomem *reg, +u8 shift,u8 width, +const char *const *parents, +int num_parents) +{ +return devm_clk_hw_register_mux (dev, name, parents, num_parents, +CLK_SET_RATE_NO_REPARENT , reg, shift, + width,0 , &ma35d1_lock); +} + +static inline struct clk_hw *ma35d1_clk_divider (struct device *dev, +const char *name, +const char *parent, +void __iomem *reg,u8 shift, +u8 width) +{ +return devm_clk_hw_register_divider (dev, name, parent,CLK_SET_RATE_PARENT , + reg, shift, width,0 , &ma35d1_lock); +} + +static inline struct clk_hw *ma35d1_clk_divider_pow2 (struct device *dev, +const char *name, +const char *parent, +void __iomem *reg, +u8 shift,u8 width) +{ +return devm_clk_hw_register_divider (dev, name, parent, +CLK_DIVIDER_POWER_OF_TWO , reg, shift, + width,0 , &ma35d1_lock); +} + +static inline struct clk_hw *ma35d1_clk_divider_table (struct device *dev, +const char *name, +const char *parent, +void __iomem *reg, +u8 shift,u8 width, +const struct clk_div_table *table) +{ +return devm_clk_hw_register_divider_table (dev, name, parent,0 , + reg, shift, width,0 , + table, &ma35d1_lock); +} + +static inline struct clk_hw *ma35d1_clk_fixed_factor (struct device *dev, +const char *name, +const char *parent, +unsigned int mult, +unsigned int div) +{ +return devm_clk_hw_register_fixed_factor (dev, name, parent, +CLK_SET_RATE_PARENT , mult, div);
drivers/clk/nuvoton/clk-ma35d1.c line 326
Quoted 10 lines
drivers/clk/nuvoton/clk-ma35d1.c new file +10
-0+} + +static inline struct clk_hw *ma35d1_clk_gate (struct device *dev, +const char *name, +const char *parent, +void __iomem *reg,u8 shift) +{ +return devm_clk_hw_register_gate (dev, name, parent,CLK_SET_RATE_PARENT , + reg, shift,0 , &ma35d1_lock); +}
Inline is not something that should be used that much in .c files, just leave it up to the compiler to decide whether to inline or not. There were some other inlines in the other file I noted later but I didn't mark them but please check their inline usage too.
Quoted 25 lines
drivers/clk/nuvoton/clk-ma35d1.c new file +25
-0+static int ma35d1_get_pll_setting (struct device_node *clk_node,u32 *pllmode) +{ +const char *of_str; +int i; + +for (i =0 ; i <PLL_MAX_NUM ; i++) { +if (of_property_read_string_index (clk_node,"nuvoton,pll-mode" , i, &of_str)) +return -EINVAL ; +if (!strcmp (of_str,"integer" )) + pllmode[i] =PLL_MODE_INT ; +else if (!strcmp (of_str,"fractional" )) + pllmode[i] =PLL_MODE_FRAC ; +else if (!strcmp (of_str,"spread-spectrum" )) + pllmode[i] =PLL_MODE_SS ; +else +return -EINVAL ; + } +return 0 ; +} + +static int ma35d1_clocks_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct device_node *clk_node = pdev->dev.of_node; +struct resource *res =platform_get_resource (pdev,IORESOURCE_MEM ,0 );
drivers/clk/nuvoton/clk-ma35d1.c line 362
Quoted 10 lines
drivers/clk/nuvoton/clk-ma35d1.c new file +10
-0+void __iomem *clk_base; +static struct clk_hw **hws; +static struct clk_hw_onecell_data *ma35d1_hw_data; +u32 pllmode[PLL_MAX_NUM ]; +int ret; + + ma35d1_hw_data =devm_kzalloc (dev, +struct_size (ma35d1_hw_data, hws,CLK_MAX_IDX ), +GFP_KERNEL ); +if (WARN_ON (!ma35d1_hw_data))
Alloc error should not be WARN_ON()'ed, it's not a bug. If you want to notify about normal (non-programming) errors, use dev_err() instead.
Quoted 14 lines
drivers/clk/nuvoton/clk-ma35d1.c new file +14
-0+return -ENOMEM ; + + ma35d1_hw_data->num =CLK_MAX_IDX ; + hws = ma35d1_hw_data->hws; + + clk_base =devm_ioremap_resource (dev, res); +if (IS_ERR (clk_base)) +return PTR_ERR (clk_base); + + ret =ma35d1_get_pll_setting (clk_node, pllmode); +if (ret <0 ) { +dev_err (dev,"Invalid PLL setting!\n" ); +return -EINVAL ; + }
Signature · 1 line
i.
Re: [PATCH v10 08/10] clk: nuvoton: Add clock driver for ma35d1 clock controller
Dear Ilpo,
Thank you for the advice.
Quoted 295 lines · Ilpo Järvinen
Quoted 18 lines · 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.Quoted 3 lines
Signed-off-by Jacky Huang<[email protected]>---
Hi,
A few small things still below.
Quoted 227 lines
drivers/clk/nuvoton/clk-ma35d1-divider.c new file +140
-0@@ -0,0 +1,140 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Copyright (C) 2023 Nuvoton Technology Corp. +* Author: Chi-Fang Li<[email protected]> +*/ + +#include <linux/clk-provider.h> +#include <linux/device.h> +#include <linux/regmap.h> +#include <linux/spinlock.h> + +struct ma35d1_adc_clk_div { +struct clk_hw hw; +void __iomem *reg; +u8 shift; +u8 width; +u32 mask; +const struct clk_div_table *table; +/* protects concurrent access to clock divider registers */ +spinlock_t *lock; +}; + +struct clk_hw *ma35d1_reg_adc_clkdiv (struct device *dev,const char *name, +struct clk_hw *parent_hw,spinlock_t *lock, +unsigned long flags,void __iomem *reg, +u8 shift,u8 width,u32 mask_bit); + +static inline struct ma35d1_adc_clk_div *to_ma35d1_adc_clk_div (struct clk_hw *_hw) +{ + return container_of(_hw, struct ma35d1_adc_clk_div, hw); +} + +static inline unsigned long ma35d1_clkdiv_recalc_rate (struct clk_hw *hw, +unsigned long parent_rate) +{ +unsigned int val; +struct ma35d1_adc_clk_div *dclk =to_ma35d1_adc_clk_div (hw); + + val =readl_relaxed (dclk->reg) >> dclk->shift; + val &=clk_div_mask (dclk->width); + val +=1 ; +return divider_recalc_rate (hw, parent_rate, val, dclk->table, +CLK_DIVIDER_ROUND_CLOSEST , dclk->width); +} + +static inline long ma35d1_clkdiv_round_rate (struct clk_hw *hw, +unsigned long rate, +unsigned long *prate) +{ +struct ma35d1_adc_clk_div *dclk =to_ma35d1_adc_clk_div (hw); + +return divider_round_rate (hw, rate, prate, dclk->table, + dclk->width,CLK_DIVIDER_ROUND_CLOSEST ); +} + +static inline int ma35d1_clkdiv_set_rate (struct clk_hw *hw, +unsigned long rate, +unsigned long parent_rate) +{ +int value; +unsigned long flags =0 ; +u32 data; +struct ma35d1_adc_clk_div *dclk =to_ma35d1_adc_clk_div (hw); + + value =divider_get_val (rate, parent_rate, dclk->table, + dclk->width,CLK_DIVIDER_ROUND_CLOSEST ); + +spin_lock_irqsave (dclk->lock, flags); + + data =readl_relaxed (dclk->reg); + data &= ~(clk_div_mask (dclk->width) << dclk->shift); + data |= (value -1 ) << dclk->shift; + data |= dclk->mask; +writel_relaxed (data, dclk->reg); + +spin_unlock_irqrestore (dclk->lock, flags); +return 0 ; +} + +static const struct clk_ops ma35d1_adc_clkdiv_ops = { + .recalc_rate = ma35d1_clkdiv_recalc_rate, + .round_rate = ma35d1_clkdiv_round_rate, + .set_rate = ma35d1_clkdiv_set_rate, +}; + +struct clk_hw *ma35d1_reg_adc_clkdiv (struct device *dev,const char *name, +struct clk_hw *parent_hw,spinlock_t *lock, +unsigned long flags,void __iomem *reg, +u8 shift,u8 width,u32 mask_bit) +{ +struct ma35d1_adc_clk_div *div; +struct clk_init_data init; +struct clk_div_table *table; +struct clk_parent_data pdata = { .index =0 }; +u32 max_div, min_div; +struct clk_hw *hw; +int ret; +int i; + + div =devm_kzalloc (dev,sizeof (*div),GFP_KERNEL ); +if (!div) +return ERR_PTR (-ENOMEM ); + + max_div =clk_div_mask (width) +1 ; + min_div =1 ; + + table =devm_kcalloc (dev, max_div +1 ,sizeof (*table),GFP_KERNEL ); +if (!table) +return ERR_PTR (-ENOMEM ); + +for (i =0 ; i < max_div; i++) { + table[i].val = min_div + i; + table[i].div =2 * table[i].val; + } + table[max_div].val =0 ; + table[max_div].div =0 ; + +memset (&init,0 ,sizeof (init)); + init.name = name; + init.ops = &ma35d1_adc_clkdiv_ops; + init.flags |= flags; + pdata.hw = parent_hw; + init.parent_data = &pdata; + init.num_parents =1 ; + + div->reg = reg; + div->shift = shift; + div->width = width; + div->mask = mask_bit ?BIT (mask_bit) :0 ; + div->lock = lock; + div->hw.init = &init; + div->table = table; + + hw = &div->hw; + ret =devm_clk_hw_register (dev, hw); +if (ret) +return ERR_PTR (ret); +return hw; +} +EXPORT_SYMBOL_GPL (ma35d1_reg_adc_clkdiv);drivers/clk/nuvoton/clk-ma35d1-pll.c new file +75
-0@@ -0,0 +1,365 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Copyright (C) 2023 Nuvoton Technology Corp. +* Author: Chi-Fang Li<[email protected]> +*/ + +#include <linux/bitfield.h> +#include <linux/clk-provider.h> +#include <linux/container_of.h> +#include <linux/device.h> +#include <linux/io.h> +#include <linux/kernel.h> +#include <linux/math64.h> +#include <linux/slab.h> +#include <linux/units.h> +#include <dt-bindings/clock/nuvoton,ma35d1-clk.h> + +/* PLL frequency limits */ +#define PLL_FREF_MAX_FREQ (200 * HZ_PER_MHZ) +#define PLL_FREF_MIN_FREQ (1 * HZ_PER_MHZ) +#define PLL_FREF_M_MAX_FREQ (40 * HZ_PER_MHZ) +#define PLL_FREF_M_MIN_FREQ (10 * HZ_PER_MHZ) +#define PLL_FCLK_MAX_FREQ (2400 * HZ_PER_MHZ) +#define PLL_FCLK_MIN_FREQ (600 * HZ_PER_MHZ) +#define PLL_FCLKO_MAX_FREQ (2400 * HZ_PER_MHZ) +#define PLL_FCLKO_MIN_FREQ (85700 * HZ_PER_KHZ) +#define PLL_SS_RATE 0x77 +#define PLL_SLOPE 0x58CFA + +#define REG_PLL_CTL0_OFFSET 0x0 +#define REG_PLL_CTL1_OFFSET 0x4 +#define REG_PLL_CTL2_OFFSET 0x8 + +/* bit fields for REG_CLK_PLL0CTL0, which is SMIC PLL design */ +#define SPLL0_CTL0_FBDIV GENMASK(7, 0) +#define SPLL0_CTL0_INDIV GENMASK(11, 8) +#define SPLL0_CTL0_OUTDIV GENMASK(13, 12) +#define SPLL0_CTL0_PD BIT(16) +#define SPLL0_CTL0_BP BIT(17) + +/* bit fields for REG_CLK_PLLxCTL0 ~ REG_CLK_PLLxCTL2, where x = 2 ~ 5 */ +#define PLL_CTL0_FBDIV GENMASK(10, 0) +#define PLL_CTL0_INDIV GENMASK(17, 12) +#define PLL_CTL0_MODE GENMASK(19, 18) +#define PLL_CTL0_SSRATE GENMASK(30, 20) +#define PLL_CTL1_PD BIT(0) +#define PLL_CTL1_BP BIT(1) +#define PLL_CTL1_OUTDIV GENMASK(6, 4) +#define PLL_CTL1_FRAC GENMASK(31, 24) +#define PLL_CTL2_SLOPE GENMASK(23, 0) + +#define INDIV_MIN 1 +#define INDIV_MAX 63 +#define FBDIV_MIN 16 +#define FBDIV_MAX 2047 +#define FBDIV_FRAC_MIN 1600 +#define FBDIV_FRAC_MAX 204700 +#define OUTDIV_MIN 1 +#define OUTDIV_MAX 7 + +#define PLL_MODE_INT 0 +#define PLL_MODE_FRAC 1 +#define PLL_MODE_SS 2 + +struct ma35d1_clk_pll { +struct clk_hw hw; +u32 id; +u8 mode; +void __iomem *ctl0_base; +void __iomem *ctl1_base; +void __iomem *ctl2_base; +}; + +struct clk_hw *ma35d1_reg_clk_pll (struct device *dev,u32 id,u8 u8mode,const char *name, +struct clk_hw *parent_hw,void __iomem *base);drivers/clk/nuvoton/clk-ma35d1-pll.c line 85
Quoted 10 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +10
-0+ +static inline struct ma35d1_clk_pll *to_ma35d1_clk_pll (struct clk_hw *_hw) +{ + return container_of(_hw, struct ma35d1_clk_pll, hw); +} + +static unsigned long ma35d1_calc_smic_pll_freq (u32 pll0_ctl0, +unsigned long parent_rate) +{ +const u32 clk_div_table[] = {1 ,2 ,4 ,8 };This is just 1 << n so the table doesn't seem necessary.
Quoted 29 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +29
-0+u32 m, n, p, outdiv; +u64 pll_freq; + +if (pll0_ctl0 &SPLL0_CTL0_BP ) +return parent_rate; + + n =FIELD_GET (SPLL0_CTL0_FBDIV , pll0_ctl0); + m =FIELD_GET (SPLL0_CTL0_INDIV , pll0_ctl0); + p =FIELD_GET (SPLL0_CTL0_OUTDIV , pll0_ctl0); + outdiv = clk_div_table[p]; + pll_freq = (u64 )parent_rate * n; +div_u64 (pll_freq, m * outdiv); +return pll_freq; +} + +static unsigned long ma35d1_calc_pll_freq (u8 mode,u32 *reg_ctl,unsigned long parent_rate) +{ +unsigned long pll_freq, x; +u32 m, n, p; + +if (reg_ctl[1 ] &PLL_CTL1_BP ) +return parent_rate; + + n =FIELD_GET (PLL_CTL0_FBDIV , reg_ctl[0 ]); + m =FIELD_GET (PLL_CTL0_INDIV , reg_ctl[0 ]); + p =FIELD_GET (PLL_CTL1_OUTDIV , reg_ctl[1 ]); + +if (mode ==PLL_MODE_INT ) { + pll_freq = (u64 )parent_rate * n;
Quoted 8 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c line 121
Quoted 7 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +7
-0+div_u64 (pll_freq, m * p); + }else { + x =FIELD_GET (PLL_CTL1_FRAC , reg_ctl[1 ]); +/* 2 decimal places floating to integer (ex. 1.23 to 123) */ + n = n *100 + ((x *100 ) /FIELD_MAX (PLL_CTL1_FRAC )); + +/* pll_freq = parent_rate * n / 100 / m / p */ Repeats what the code does, drop.
I will remove it.
Quoted 70 lines
Quoted 70 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +70
-0+ pll_freq =div_u64 (parent_rate * n,100 * m * p); + } +return pll_freq; +} + +static int ma35d1_pll_find_closest (struct ma35d1_clk_pll *pll,unsigned long rate, +unsigned long parent_rate,u32 *reg_ctl, +unsigned long *freq) +{ +unsigned long min_diff =ULONG_MAX ; +int fbdiv_min, fbdiv_max; +int p, m, n; + + *freq =0 ; +if (rate <PLL_FCLKO_MIN_FREQ || rate >PLL_FCLKO_MAX_FREQ ) +return -EINVAL ; + +if (pll->mode ==PLL_MODE_INT ) { + fbdiv_min =FBDIV_MIN ; + fbdiv_max =FBDIV_MAX ; + }else { + fbdiv_min =FBDIV_FRAC_MIN ; + fbdiv_max =FBDIV_FRAC_MAX ; + } + +for (m =INDIV_MIN ; m <=INDIV_MAX ; m++) { +for (n = fbdiv_min; n <= fbdiv_max; n++) { +for (p =OUTDIV_MIN ; p <=OUTDIV_MAX ; p++) { +unsigned long tmp, fout, fclk, diff; + + tmp =div_u64 (parent_rate, m); +if (tmp <PLL_FREF_M_MIN_FREQ || + tmp >PLL_FREF_M_MAX_FREQ ) +continue ;/* constrain */ + + fclk =div_u64 (parent_rate * n, m); +/* for 2 decimal places */ +if (pll->mode !=PLL_MODE_INT ) + fclk =div_u64 (fclk,100 ); + +if (fclk <PLL_FCLK_MIN_FREQ || + fclk >PLL_FCLK_MAX_FREQ ) +continue ;/* constrain */ + + fout =div_u64 (fclk, p); +if (fout <PLL_FCLKO_MIN_FREQ || + fout >PLL_FCLKO_MAX_FREQ ) +continue ;/* constrain */ + + diff =abs (rate - fout); +if (diff < min_diff) { + reg_ctl[0 ] =FIELD_PREP (PLL_CTL0_INDIV , m) | +FIELD_PREP (PLL_CTL0_FBDIV , n); + reg_ctl[1 ] =FIELD_PREP (PLL_CTL1_OUTDIV , p); + *freq = fout; + min_diff = diff; +if (min_diff ==0 ) +break ; + } + } + } + } +if (*freq ==0 ) +return -EINVAL ;/* cannot find even one valid setting */ +return 0 ; +} + +static int ma35d1_clk_pll_set_rate (struct clk_hw *hw,unsigned long rate, +unsigned long parent_rate) +{
Quoted 8 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c line 198
Quoted 7 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +7
-0+struct ma35d1_clk_pll *pll =to_ma35d1_clk_pll (hw); +u32 reg_ctl[3 ] = {0 }; +unsigned long pll_freq; +int ret; + +if (parent_rate <PLL_FREF_MIN_FREQ || + parent_rate >PLL_FREF_MAX_FREQ )One line.
I will fix it.
Quoted 59 lines
Quoted 59 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +59
-0+return -EINVAL ; + + ret =ma35d1_pll_find_closest (pll, rate, parent_rate, reg_ctl, &pll_freq); +if (ret !=0 ) +return ret; + +switch (pll->mode) { +case PLL_MODE_INT : + reg_ctl[0 ] |=FIELD_PREP (PLL_CTL0_MODE ,PLL_MODE_INT ); +break ; +case PLL_MODE_FRAC : + reg_ctl[0 ] |=FIELD_PREP (PLL_CTL0_MODE ,PLL_MODE_FRAC ); +break ; +case PLL_MODE_SS : + reg_ctl[0 ] |=FIELD_PREP (PLL_CTL0_MODE ,PLL_MODE_SS ) | +FIELD_PREP (PLL_CTL0_SSRATE ,PLL_SS_RATE ); + reg_ctl[2 ] =FIELD_PREP (PLL_CTL2_SLOPE ,PLL_SLOPE ); +break ; + } + reg_ctl[1 ] |=PLL_CTL1_PD ; + +writel_relaxed (reg_ctl[0 ], pll->ctl0_base); +writel_relaxed (reg_ctl[1 ], pll->ctl1_base); +writel_relaxed (reg_ctl[2 ], pll->ctl2_base); +return 0 ; +} + +static unsigned long ma35d1_clk_pll_recalc_rate (struct clk_hw *hw,unsigned long parent_rate) +{ +struct ma35d1_clk_pll *pll =to_ma35d1_clk_pll (hw); +u32 reg_ctl[3 ]; +unsigned long pll_freq; + +if (parent_rate <PLL_FREF_MIN_FREQ || parent_rate >PLL_FREF_MAX_FREQ ) +return 0 ; + +switch (pll->id) { +case CAPLL : + reg_ctl[0 ] =readl_relaxed (pll->ctl0_base); + pll_freq =ma35d1_calc_smic_pll_freq (reg_ctl[0 ], parent_rate); +return pll_freq; +case DDRPLL : +case APLL : +case EPLL : +case VPLL : + reg_ctl[0 ] =readl_relaxed (pll->ctl0_base); + reg_ctl[1 ] =readl_relaxed (pll->ctl1_base); + pll_freq =ma35d1_calc_pll_freq (pll->mode, reg_ctl, parent_rate); +return pll_freq; + } +return 0 ; +} + +static long ma35d1_clk_pll_round_rate (struct clk_hw *hw,unsigned long rate, +unsigned long *parent_rate) +{ +struct ma35d1_clk_pll *pll =to_ma35d1_clk_pll (hw); +u32 reg_ctl[3 ] = {0 }; +unsigned long pll_freq;
Quoted 8 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c line 264
Quoted 7 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +7
-0+long ret; + +if (*parent_rate <PLL_FREF_MIN_FREQ || *parent_rate >PLL_FREF_MAX_FREQ ) +return -EINVAL ; + + ret =ma35d1_pll_find_closest (pll, rate, *parent_rate, reg_ctl, &pll_freq); +if (ret !=0 )< 0
I will fix it.
Quoted 183 lines
Quoted 183 lines
drivers/clk/nuvoton/clk-ma35d1-pll.c new file +101
-0+return ret; + +switch (pll->id) { +case CAPLL : + reg_ctl[0 ] =readl_relaxed (pll->ctl0_base); + pll_freq =ma35d1_calc_smic_pll_freq (reg_ctl[0 ], *parent_rate); +return pll_freq; +case DDRPLL : +case APLL : +case EPLL : +case VPLL : + reg_ctl[0 ] =readl_relaxed (pll->ctl0_base); + reg_ctl[1 ] =readl_relaxed (pll->ctl1_base); + pll_freq =ma35d1_calc_pll_freq (pll->mode, reg_ctl, *parent_rate); +return pll_freq; + } +return 0 ; +} + +static int ma35d1_clk_pll_is_prepared (struct clk_hw *hw) +{ +struct ma35d1_clk_pll *pll =to_ma35d1_clk_pll (hw); +u32 val =readl_relaxed (pll->ctl1_base); + +return !(val &PLL_CTL1_PD ); +} + +static int ma35d1_clk_pll_prepare (struct clk_hw *hw) +{ +struct ma35d1_clk_pll *pll =to_ma35d1_clk_pll (hw); +u32 val; + + val =readl_relaxed (pll->ctl1_base); + val &= ~PLL_CTL1_PD ; +writel_relaxed (val, pll->ctl1_base); +return 0 ; +} + +static void ma35d1_clk_pll_unprepare (struct clk_hw *hw) +{ +struct ma35d1_clk_pll *pll =to_ma35d1_clk_pll (hw); +u32 val; + + val =readl_relaxed (pll->ctl1_base); + val |=PLL_CTL1_PD ; +writel_relaxed (val, pll->ctl1_base); +} + +static const struct clk_ops ma35d1_clk_pll_ops = { + .is_prepared = ma35d1_clk_pll_is_prepared, + .prepare = ma35d1_clk_pll_prepare, + .unprepare = ma35d1_clk_pll_unprepare, + .set_rate = ma35d1_clk_pll_set_rate, + .recalc_rate = ma35d1_clk_pll_recalc_rate, + .round_rate = ma35d1_clk_pll_round_rate, +}; + +static const struct clk_ops ma35d1_clk_fixed_pll_ops = { + .recalc_rate = ma35d1_clk_pll_recalc_rate, + .round_rate = ma35d1_clk_pll_round_rate, +}; + +struct clk_hw *ma35d1_reg_clk_pll (struct device *dev,u32 id,u8 u8mode,const char *name, +struct clk_hw *parent_hw,void __iomem *base) +{ +struct clk_parent_data pdata = { .index =0 }; +struct clk_init_data init = {}; +struct ma35d1_clk_pll *pll; +struct clk_hw *hw; +int ret; + + pll =devm_kzalloc (dev,sizeof (*pll),GFP_KERNEL ); +if (!pll) +return ERR_PTR (-ENOMEM ); + + pll->id = id; + pll->mode = u8mode; + pll->ctl0_base = base +REG_PLL_CTL0_OFFSET ; + pll->ctl1_base = base +REG_PLL_CTL1_OFFSET ; + pll->ctl2_base = base +REG_PLL_CTL2_OFFSET ; + + init.name = name; + init.flags =0 ; + pdata.hw = parent_hw; + init.parent_data = &pdata; + init.num_parents =1 ; + +if (id ==CAPLL || id ==DDRPLL ) + init.ops = &ma35d1_clk_fixed_pll_ops; +else + init.ops = &ma35d1_clk_pll_ops; + + pll->hw.init = &init; + hw = &pll->hw; + + ret =devm_clk_hw_register (dev, hw); +if (ret) +return ERR_PTR (ret); +return hw; +} +EXPORT_SYMBOL_GPL (ma35d1_reg_clk_pll);drivers/clk/nuvoton/clk-ma35d1.c new file +76
-0@@ -0,0 +1,948 @@ +static inline struct clk_hw *ma35d1_clk_fixed (const char *name,int rate) +{ +return clk_hw_register_fixed_rate (NULL , name,NULL ,0 , rate); +} + +static inline struct clk_hw *ma35d1_clk_mux_parent (struct device *dev, +const char *name, +void __iomem *reg, +u8 shift,u8 width, +const struct clk_parent_data *pdata, +int num_pdata) +{ +return clk_hw_register_mux_parent_data (dev, name, pdata, num_pdata, +CLK_SET_RATE_NO_REPARENT , reg, shift, + width,0 , &ma35d1_lock); +} + +static inline struct clk_hw *ma35d1_clk_mux (struct device *dev, +const char *name, +void __iomem *reg, +u8 shift,u8 width, +const char *const *parents, +int num_parents) +{ +return devm_clk_hw_register_mux (dev, name, parents, num_parents, +CLK_SET_RATE_NO_REPARENT , reg, shift, + width,0 , &ma35d1_lock); +} + +static inline struct clk_hw *ma35d1_clk_divider (struct device *dev, +const char *name, +const char *parent, +void __iomem *reg,u8 shift, +u8 width) +{ +return devm_clk_hw_register_divider (dev, name, parent,CLK_SET_RATE_PARENT , + reg, shift, width,0 , &ma35d1_lock); +} + +static inline struct clk_hw *ma35d1_clk_divider_pow2 (struct device *dev, +const char *name, +const char *parent, +void __iomem *reg, +u8 shift,u8 width) +{ +return devm_clk_hw_register_divider (dev, name, parent, +CLK_DIVIDER_POWER_OF_TWO , reg, shift, + width,0 , &ma35d1_lock); +} + +static inline struct clk_hw *ma35d1_clk_divider_table (struct device *dev, +const char *name, +const char *parent, +void __iomem *reg, +u8 shift,u8 width, +const struct clk_div_table *table) +{ +return devm_clk_hw_register_divider_table (dev, name, parent,0 , + reg, shift, width,0 , + table, &ma35d1_lock); +} + +static inline struct clk_hw *ma35d1_clk_fixed_factor (struct device *dev, +const char *name, +const char *parent, +unsigned int mult, +unsigned int div) +{ +return devm_clk_hw_register_fixed_factor (dev, name, parent, +CLK_SET_RATE_PARENT , mult, div); +} + +static inline struct clk_hw *ma35d1_clk_gate (struct device *dev, +const char *name, +const char *parent, +void __iomem *reg,u8 shift)
Quoted 8 lines
drivers/clk/nuvoton/clk-ma35d1.c line 326
Quoted 4 lines
drivers/clk/nuvoton/clk-ma35d1.c new file +4
-0+{ +return devm_clk_hw_register_gate (dev, name, parent,CLK_SET_RATE_PARENT , + reg, shift,0 , &ma35d1_lock); +}Inline is not something that should be used that much in .c files, just leave it up to the compiler to decide whether to inline or not. There were some other inlines in the other file I noted later but I didn't mark them but please check their inline usage too.
Okay, I will check these .c files and remove the inline usage.
Quoted 29 lines
Quoted 29 lines
drivers/clk/nuvoton/clk-ma35d1.c new file +29
-0+static int ma35d1_get_pll_setting (struct device_node *clk_node,u32 *pllmode) +{ +const char *of_str; +int i; + +for (i =0 ; i <PLL_MAX_NUM ; i++) { +if (of_property_read_string_index (clk_node,"nuvoton,pll-mode" , i, &of_str)) +return -EINVAL ; +if (!strcmp (of_str,"integer" )) + pllmode[i] =PLL_MODE_INT ; +else if (!strcmp (of_str,"fractional" )) + pllmode[i] =PLL_MODE_FRAC ; +else if (!strcmp (of_str,"spread-spectrum" )) + pllmode[i] =PLL_MODE_SS ; +else +return -EINVAL ; + } +return 0 ; +} + +static int ma35d1_clocks_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct device_node *clk_node = pdev->dev.of_node; +struct resource *res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); +void __iomem *clk_base; +static struct clk_hw **hws; +static struct clk_hw_onecell_data *ma35d1_hw_data; +u32 pllmode[PLL_MAX_NUM ];
Quoted 8 lines
drivers/clk/nuvoton/clk-ma35d1.c line 362
Quoted 6 lines
drivers/clk/nuvoton/clk-ma35d1.c new file +6
-0+int ret; + + ma35d1_hw_data =devm_kzalloc (dev, +struct_size (ma35d1_hw_data, hws,CLK_MAX_IDX ), +GFP_KERNEL ); +if (WARN_ON (!ma35d1_hw_data))Alloc error should not be WARN_ON()'ed, it's not a bug. If you want to notify about normal (non-programming) errors, use
dev_err()instead.
Yes, I will use dev_err() instead.
Quoted 6 lines
Quoted 6 lines
drivers/clk/nuvoton/clk-ma35d1.c new file +6
-0+return -ENOMEM ; + + ma35d1_hw_data->num =CLK_MAX_IDX ; + hws = ma35d1_hw_data->hws; + + clk_base =devm_ioremap_resource (dev, res);
Quoted 8 lines
drivers/clk/nuvoton/clk-ma35d1.c line 376
Quoted 8 lines
drivers/clk/nuvoton/clk-ma35d1.c new file +8
-0+if (IS_ERR (clk_base)) +return PTR_ERR (clk_base); + + ret =ma35d1_get_pll_setting (clk_node, pllmode); +if (ret <0 ) { +dev_err (dev,"Invalid PLL setting!\n" ); +return -EINVAL ; + }
Best Regards,
Jacky Huang
PATCH v10 9/10 reset: Add Nuvoton ma35d1 reset driver support
In reply to Jacky HuangFrom: Jacky Huang <[email protected]>
This driver supports individual IP reset for ma35d1. The reset control registers is a subset of system control registers.
--- drivers/reset/Kconfig | 6 + drivers/reset/Makefile | 1 + drivers/reset/reset-ma35d1.c | 234 +++++++++++++++++++++++++++++++++++ 3 files changed, 241 insertions(+) create mode 100644 drivers/reset/reset-ma35d1.c
drivers/reset/Kconfig +6 -0
@@ -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
@@ -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 +234 -0
234 lines not on this page · raw message
Signature · 7 lines
2.34.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH v10 09/10] reset: Add Nuvoton ma35d1 reset driver support
Quoted 6 lines · Jacky Huang
From: Jacky Huang <[email protected]>
This driver supports individual IP reset for ma35d1. The reset control registers is a subset of system control registers.
Signed-off-by Jacky Huang <[email protected]>
regards
Philipp
Re: [PATCH v10 09/10] reset: Add Nuvoton ma35d1 reset driver support
In reply to Jacky HuangQuoted 4 lines · Jacky Huang
From: Jacky Huang <[email protected]>
This driver supports individual IP reset for ma35d1. The reset control registers is a subset of system control registers.
registers are
Quoted 23 lines
Signed-off-by Jacky Huang <[email protected]>---
drivers/reset/reset-ma35d1.c new file +14
-0@@ -0,0 +1,234 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Copyright (C) 2023 Nuvoton Technology Corp. +* Author: Chi-Fang Li <[email protected]> +*/ + +#include <linux/bits.h> +#include <linux/container_of.h> +#include <linux/device.h> +#include <linux/err.h> +#include <linux/io.h> +#include <linux/kernel.h> +#include <linux/of.h> +#include <linux/platform_device.h>
drivers/reset/reset-ma35d1.c line 24
Quoted 10 lines
drivers/reset/reset-ma35d1.c new file +10
-0+#include <linux/reboot.h> +#include <linux/reset-controller.h> +#include <linux/spinlock.h> +#include <dt-bindings/reset/nuvoton,ma35d1-reset.h> + +struct ma35d1_reset_data { +struct reset_controller_dev rcdev; +struct notifier_block restart_handler; +void __iomem *base; +spinlock_t lock;
Please add a comment about what this protects. After adding that, feel free to add also:
Signature · 1 line
i.
Re: [PATCH v10 09/10] reset: Add Nuvoton ma35d1 reset driver support
Quoted 43 lines · Ilpo Järvinen
Quoted 4 lines · Jacky Huang
From: Jacky Huang <[email protected]>
This driver supports individual IP reset for ma35d1. The reset control registers is a subset of system control registers.
registers are
Quoted 22 lines
Signed-off-by Jacky Huang <[email protected]>---
drivers/reset/reset-ma35d1.c new file +14
-0@@ -0,0 +1,234 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Copyright (C) 2023 Nuvoton Technology Corp. +* Author: Chi-Fang Li <[email protected]> +*/ + +#include <linux/bits.h> +#include <linux/container_of.h> +#include <linux/device.h> +#include <linux/err.h> +#include <linux/io.h> +#include <linux/kernel.h> +#include <linux/of.h> +#include <linux/platform_device.h> drivers/reset/reset-ma35d1.c line 24
Quoted 10 lines
drivers/reset/reset-ma35d1.c new file +10
-0+#include <linux/reboot.h> +#include <linux/reset-controller.h> +#include <linux/spinlock.h> +#include <dt-bindings/reset/nuvoton,ma35d1-reset.h> + +struct ma35d1_reset_data { +struct reset_controller_dev rcdev; +struct notifier_block restart_handler; +void __iomem *base; +spinlock_t lock;Please add a comment about what this protects. After adding that, feel free to add also:
Quoted 3 lines
Reviewed-by Ilpo Järvinen <[email protected]>
Dear Ilpo ,
Thanks for your review. I will fix them in the next version.
Best Regards,
Jacky Huang
PATCH v10 10/10 tty: serial: Add Nuvoton ma35d1 serial driver support
In reply to Jacky HuangFrom: 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 | 796 +++++++++++++++++++++++++++++ 3 files changed, 815 insertions(+) create mode 100644 drivers/tty/serial/ma35d1_serial.c
drivers/tty/serial/Kconfig +18 -0
@@ -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
@@ -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 +796 -0
796 lines not on this page · raw message
Signature · 7 lines
2.34.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH v10 10/10] tty: serial: Add Nuvoton ma35d1 serial driver support
Quoted 71 lines · 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.
Signed-off-by Jacky Huang <[email protected]>--- drivers/tty/serial/Kconfig | 18 + drivers/tty/serial/Makefile | 1 + drivers/tty/serial/ma35d1_serial.c | 796 +++++++++++++++++++++++++++++ 3 files changed, 815 insertions(+) create mode 100644 drivers/tty/serial/ma35d1_serial.cdrivers/tty/serial/Kconfig +18
-0@@ -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_GPIOdrivers/tty/serial/Makefile +1
-0@@ -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.odrivers/tty/serial/ma35d1_serial.c new file +13
-0@@ -0,0 +1,796 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* MA35D1 serial driver +* Copyright (C) 2023 Nuvoton Technology Corp. +*/ + +#include <linux/bitfield.h> +#include <linux/clk.h> +#include <linux/delay.h> +#include <linux/of.h> +#include <linux/of_platform.h> +#include <linux/serial_core.h> +#include <linux/slab.h>
drivers/tty/serial/ma35d1_serial.c line 23
Quoted 10 lines
drivers/tty/serial/ma35d1_serial.c new file +10
-0+#include <linux/tty_flip.h> + +#define UART_NR 17 + +#define UART_REG_RBR 0x00 +#define UART_REG_THR 0x00 +#define UART_REG_IER 0x04 +#define UART_REG_FCR 0x08 +#define UART_REG_LCR 0x0C +#define UART_REG_MCR 0x10
These duplicate include/uapi/linux/serial_reg.h ones, use the std ones directly.
Setup regshift too and use it in serial_in.
drivers/tty/serial/ma35d1_serial.c line 32
Quoted 9 lines
drivers/tty/serial/ma35d1_serial.c new file +9
-0+#define UART_REG_MSR 0x14 +#define UART_REG_FSR 0x18 +#define UART_REG_ISR 0x1C +#define UART_REG_TOR 0x20 +#define UART_REG_BAUD 0x24 +#define UART_REG_ALTCTL 0x2C +#define UART_FUN_SEL 0x30 +#define UART_REG_WKCTL 0x40 +#define UART_REG_WKSTS 0x44
It would be better to prefix HW specific defines with something HW related such as MA35D1. This applies to most of the below ones too:
drivers/tty/serial/ma35d1_serial.c line 37
Quoted 4 lines
drivers/tty/serial/ma35d1_serial.c new file +4
-0+/* UART_REG_IER - Interrupt Enable Register */ +#define IER_RDA_IEN BIT(0)/* RBR Available Interrupt Enable */ +#define IER_THRE_IEN BIT(1)/* THR Empty Interrupt Enable */ +#define IER_RLS_IEN BIT(2)/* RX Line Status Interrupt Enable */
These look same as UART_IER bits, use the std ones.
drivers/tty/serial/ma35d1_serial.c line 46
Quoted 9 lines
drivers/tty/serial/ma35d1_serial.c new file +9
-0+#define IER_RTO_IEN BIT(4)/* RX Time-out Interrupt Enable */ +#define IER_BUFERR_IEN BIT(5)/* Buffer Error Interrupt Enable */ +#define IER_TIME_OUT_EN BIT(11)/* RX Buffer Time-out Counter Enable */ +#define IER_AUTO_RTS BIT(12)/* nRTS Auto-flow Control Enable */ +#define IER_AUTO_CTS BIT(13)/* nCTS Auto-flow Control Enable */ + +/* UART_REG_FCR - FIFO Control Register */ +#define FCR_RFR BIT(1)/* RX Field Software Reset */ +#define FCR_TFR BIT(2)/* TX Field Software Reset */
Are these same as UART_FCR_CLEAR_* functionality wise? If they're use std ones.
Quoted 14 lines
drivers/tty/serial/ma35d1_serial.c new file +14
-0+#define FCR_RFITL_MASK GENMASK(7, 4)/* RX FIFO Interrupt Trigger Level */ +#define FCR_RFITL_1BYTE FIELD_PREP(FCR_RFITL_MASK, 0) +#define FCR_RFITL_4BYTES FIELD_PREP(FCR_RFITL_MASK, 1) +#define FCR_RFITL_8BYTES FIELD_PREP(FCR_RFITL_MASK, 2) +#define FCR_RFITL_14BYTES FIELD_PREP(FCR_RFITL_MASK, 3) +#define FCR_RFITL_30BYTES FIELD_PREP(FCR_RFITL_MASK, 4) +#define FCR_RTSTRGLV_MASK GENMASK(19, 16)/* nRTS Trigger Level */ +#define FCR_RTSTRGLV_1BYTE FIELD_PREP(FCR_RTSTRGLV_MASK, 0) +#define FCR_RTSTRGLV_4BYTES FIELD_PREP(FCR_RTSTRGLV_MASK, 1) +#define FCR_RTSTRGLV_8BYTES FIELD_PREP(FCR_RTSTRGLV_MASK, 2) +#define FCR_RTSTRGLV_14BYTES FIELD_PREP(FCR_RTSTRGLV_MASK, 3) +#define FCR_RTSTRGLVL_30BYTES FIELD_PREP(FCR_RTSTRGLV_MASK, 4) + +/* UART_REG_LCR - Line Control Register */
drivers/tty/serial/ma35d1_serial.c line 70
Quoted 10 lines
drivers/tty/serial/ma35d1_serial.c new file +10
-0+#define LCR_NSB BIT(2)/* Number of “STOP Bit” */ +#define LCR_PBE BIT(3)/* Parity Bit Enable */ +#define LCR_EPE BIT(4)/* Even Parity Enable */ +#define LCR_SPE BIT(5)/* Stick Parity Enable */ +#define LCR_BREAK BIT(6)/* Break Control */ +#define LCR_WLS_MASK GENMASK(1, 0)/* Word Length Selection */ +#define LCR_WLS_5BITS FIELD_PREP(LCR_WLS_MASK, 0) +#define LCR_WLS_6BITS FIELD_PREP(LCR_WLS_MASK, 1) +#define LCR_WLS_7BITS FIELD_PREP(LCR_WLS_MASK, 2) +#define LCR_WLS_8BITS FIELD_PREP(LCR_WLS_MASK, 3)
These look exact copies of UART_LCR_* bits.
drivers/tty/serial/ma35d1_serial.c line 73
Quoted 2 lines
drivers/tty/serial/ma35d1_serial.c new file +2
-0+/* UART_REG_MCR - Modem Control Register */ +#define MCR_RTS_CTRL BIT(1)/* nRTS Signal Control */
Is this same as UART_MCR_RTS?
Quoted 42 lines
drivers/tty/serial/ma35d1_serial.c new file +42
-0+#define MCR_RTSACTLV BIT(9)/* nRTS Pin Active Level */ +#define MCR_RTSSTS BIT(13)/* nRTS Pin Status (Read Only) */ + +/* UART_REG_MSR - Modem Status Register */ +#define MSR_CTSDETF BIT(0)/* Detect nCTS State Change Flag */ +#define MSR_CTSSTS BIT(4)/* nCTS Pin Status (Read Only) */ +#define MSR_CTSACTLV BIT(8)/* nCTS Pin Active Level */ + +/* UART_REG_FSR - FIFO Status Register */ +#define FSR_RX_OVER_IF BIT(0)/* RX Overflow Error Interrupt Flag */ +#define FSR_PEF BIT(4)/* Parity Error Flag*/ +#define FSR_FEF BIT(5)/* Framing Error Flag */ +#define FSR_BIF BIT(6)/* Break Interrupt Flag */ +#define FSR_RX_EMPTY BIT(14)/* Receiver FIFO Empty (Read Only) */ +#define FSR_RX_FULL BIT(15)/* Receiver FIFO Full (Read Only) */ +#define FSR_TX_EMPTY BIT(22)/* Transmitter FIFO Empty (Read Only) */ +#define FSR_TX_FULL BIT(23)/* Transmitter FIFO Full (Read Only) */ +#define FSR_TX_OVER_IF BIT(24)/* TX Overflow Error Interrupt Flag */ +#define FSR_TE_FLAG BIT(28)/* Transmitter Empty Flag (Read Only) */ +#define FSR_RXPTR_MSK GENMASK(13, 8)/* TX FIFO Pointer mask */ +#define FSR_TXPTR_MSK GENMASK(21, 16)/* RX FIFO Pointer mask */ + +/* UART_REG_ISR - Interrupt Status Register */ +#define ISR_RDA_IF BIT(0)/* RBR Available Interrupt Flag */ +#define ISR_THRE_IF BIT(1)/* THR Empty Interrupt Flag */ +#define ISR_RLSIF BIT(2)/* Receive Line Interrupt Flag */ +#define ISR_MODEMIF BIT(3)/* MODEM Interrupt Flag */ +#define ISR_RXTO_IF BIT(4)/* RX Time-out Interrupt Flag */ +#define ISR_BUFEIF BIT(5)/* Buffer Error Interrupt Flag */ +#define UART_ISR_WK_IF BIT(6)/* UART Wake-up Interrupt Flag */ +#define UART_ISR_RDAINT BIT(8)/* RBR Available Interrupt Indicator */ +#define ISR_THRE_INT BIT(9)/* THR Empty Interrupt Indicator */ +#define ISR_ALL 0xFFFFFFFF + +/* UART_REG_BAUD - Baud Rate Divider Register */ +#define BAUD_MODE_MASK GENMASK(29, 28) +#define BAUD_MODE0 FIELD_PREP(BAUD_MODE_MASK, 0) +#define BAUD_MODE1 FIELD_PREP(BAUD_MODE_MASK, 2) +#define BAUD_MODE2 FIELD_PREP(BAUD_MODE_MASK, 3) + +/* UART_REG_ALTCTL - Alternate Control/Status Register */ +#define ALTCTL_RS485AUD BIT(10)/* RS-485 Auto Direction Function */
drivers/tty/serial/ma35d1_serial.c line 125
Quoted 10 lines
drivers/tty/serial/ma35d1_serial.c new file +10
-0+ +/* UART_FUN_SEL - Function Select Register */ +#define FUN_SEL_MASK GENMASK(2, 0) +#define FUN_SEL_UART FIELD_PREP(FUN_SEL_MASK, 0) +#define FUN_SEL_RS485 FIELD_PREP(FUN_SEL_MASK, 3) + +/* UART FIFO depth */ +#define UART_FIFO_DEPTH 32 +/* UART console clock */ +#define UART_CONSOLE_CLK 24000000
* HZ_PER_MHZ ?
drivers/tty/serial/ma35d1_serial.c line 133
Quoted 8 lines
drivers/tty/serial/ma35d1_serial.c new file +8
-0+/* UART register ioremap size */ +#define UART_REG_SIZE 0x100 +/* Rx Timeout */ +#define UART_RX_TOUT 0x40 + +#define UART_ISR_IF_CHECK (ISR_RDA_IF | ISR_RXTO_IF | ISR_THRE_INT | ISR_BUFEIF) + +#define LOOP_TIMEOUT 1000
Unused.
Quoted 185 lines
drivers/tty/serial/ma35d1_serial.c new file +185
-0+static struct uart_driver ma35d1serial_reg; + +struct uart_ma35d1_port { +struct uart_port port; +struct clk *clk; +u16 capabilities;/* port capabilities */ +u8 ier; +u8 lcr; +u8 mcr; +u32 baud_rate; +u32 console_baud_rate; +u32 console_line; +u32 console_int; +}; + +static struct uart_ma35d1_port ma35d1serial_ports[UART_NR ]; + +static struct uart_ma35d1_port *to_ma35d1_uart_port (struct uart_port *uart) +{ + return container_of(uart, struct uart_ma35d1_port, port); +} + +static u32 serial_in (struct uart_ma35d1_port *p,u32 offset) +{ +return readl_relaxed (p->port.membase + offset); +} + +static void serial_out (struct uart_ma35d1_port *p,u32 offset,u32 value) +{ +writel_relaxed (value, p->port.membase + offset); +} + +static void __stop_tx (struct uart_ma35d1_port *p) +{ +u32 ier; + + ier =serial_in (p,UART_REG_IER ); +if (ier &IER_THRE_IEN ) +serial_out (p,UART_REG_IER , ier & ~IER_THRE_IEN ); +} + +static void ma35d1serial_stop_tx (struct uart_port *port) +{ +struct uart_ma35d1_port *up =to_ma35d1_uart_port (port); + +__stop_tx (up); +} + +static void transmit_chars (struct uart_ma35d1_port *up) +{ +u32 count; +u8 ch; + +if (uart_tx_stopped (&up->port)) { +ma35d1serial_stop_tx (&up->port); +return ; + } + count =UART_FIFO_DEPTH -FIELD_GET (FSR_TXPTR_MSK ,serial_in (up,UART_REG_FSR )); +uart_port_tx_limited (&up->port, ch, count, + !(serial_in (up,UART_REG_FSR ) &FSR_TX_FULL ), +serial_out (up,UART_REG_THR , ch), + ({})); +} + +static void ma35d1serial_start_tx (struct uart_port *port) +{ +struct uart_ma35d1_port *up =to_ma35d1_uart_port (port); +u32 ier; + + ier =serial_in (up,UART_REG_IER ); +serial_out (up,UART_REG_IER , ier & ~IER_THRE_IEN ); +transmit_chars (up); +serial_out (up,UART_REG_IER , ier |IER_THRE_IEN ); +} + +static void ma35d1serial_stop_rx (struct uart_port *port) +{ +struct uart_ma35d1_port *up =to_ma35d1_uart_port (port); + +serial_out (up,UART_REG_IER ,serial_in (up,UART_REG_IER ) & ~IER_RDA_IEN ); +} + +static void receive_chars (struct uart_ma35d1_port *up) +{ +u8 ch, flag; +u32 fsr; +int max_count =256 ; + + fsr =serial_in (up,UART_REG_FSR ); +do { + flag =TTY_NORMAL ; + up->port.icount.rx++; + +if (unlikely (fsr & (FSR_BIF |FSR_FEF |FSR_PEF |FSR_RX_OVER_IF ))) { +if (fsr &FSR_BIF ) { + up->port.icount.brk++; +if (uart_handle_break (&up->port)) +continue ; + } +if (fsr &FSR_FEF ) + up->port.icount.frame++; +if (fsr &FSR_PEF ) + up->port.icount.parity++; +if (fsr &FSR_RX_OVER_IF ) + up->port.icount.overrun++; + +serial_out (up,UART_REG_FSR , fsr & + (FSR_BIF |FSR_FEF |FSR_PEF |FSR_RX_OVER_IF )); + +if (fsr &FSR_BIF ) + flag =TTY_BREAK ; +else if (fsr &FSR_PEF ) + flag =TTY_PARITY ; +else if (fsr &FSR_FEF ) + flag =TTY_FRAME ; + } + + ch =serial_in (up,UART_REG_RBR ); +if (uart_handle_sysrq_char (&up->port, ch)) +continue ; + +spin_lock (&up->port.lock); +uart_insert_char (&up->port, fsr,FSR_RX_OVER_IF , ch, flag); +spin_unlock (&up->port.lock); + + fsr =serial_in (up,UART_REG_FSR ); + }while (!(fsr &FSR_RX_EMPTY ) && (max_count-- >0 )); + +spin_lock (&up->port.lock); +tty_flip_buffer_push (&up->port.state->port); +spin_unlock (&up->port.lock); +} + +static irqreturn_t ma35d1serial_interrupt (int irq,void *dev_id) +{ +struct uart_port *port = dev_id; +struct uart_ma35d1_port *up =to_ma35d1_uart_port (port); +u32 isr, fsr; + + isr =serial_in (up,UART_REG_ISR ); + fsr =serial_in (up,UART_REG_FSR ); + +if (!(isr &UART_ISR_IF_CHECK )) +return IRQ_NONE ; + +if (isr & (ISR_RDA_IF |ISR_RXTO_IF )) +receive_chars (up); +if (isr &ISR_THRE_INT ) +transmit_chars (up); +if (fsr &FSR_TX_OVER_IF ) +serial_out (up,UART_REG_FSR ,FSR_TX_OVER_IF ); + +return IRQ_HANDLED ; +} + +static u32 ma35d1serial_tx_empty (struct uart_port *port) +{ +struct uart_ma35d1_port *up =to_ma35d1_uart_port (port); +u32 fsr; + + fsr =serial_in (up,UART_REG_FSR ); +return (fsr & (FSR_TE_FLAG |FSR_TX_EMPTY )) == + (FSR_TE_FLAG |FSR_TX_EMPTY ) ?TIOCSER_TEMT :0 ; +} + +static u32 ma35d1serial_get_mctrl (struct uart_port *port) +{ +struct uart_ma35d1_port *up =to_ma35d1_uart_port (port); +u32 status; +u32 ret =0 ; + + status =serial_in (up,UART_REG_MSR ); +if (!(status &MSR_CTSSTS )) + ret |=TIOCM_CTS ; +return ret; +} + +static void ma35d1serial_set_mctrl (struct uart_port *port,u32 mctrl) +{ +struct uart_ma35d1_port *up =to_ma35d1_uart_port (port); +u32 mcr =0 ; +u32 ier =0 ; + +if (mctrl &TIOCM_RTS ) { + mcr =serial_in (up,UART_REG_MCR );
drivers/tty/serial/ma35d1_serial.c line 329
Quoted 10 lines
drivers/tty/serial/ma35d1_serial.c new file +10
-0+ mcr |=MCR_RTSACTLV ; + mcr &= ~MCR_RTS_CTRL ; + } +if (up->mcr &UART_MCR_AFE ) { + mcr =serial_in (up,UART_REG_MCR ); + mcr |=MCR_RTSACTLV ; + mcr &= ~MCR_RTS_CTRL ; + +serial_out (up,UART_REG_IER , + (serial_in (up,UART_REG_IER ) |IER_AUTO_RTS |IER_AUTO_CTS ));
Split to 3 lines.
drivers/tty/serial/ma35d1_serial.c line 339
Quoted 10 lines
drivers/tty/serial/ma35d1_serial.c new file +10
-0+ + up->port.flags |=UPF_HARD_FLOW ; + }else { + ier =serial_in (up,UART_REG_IER ); + ier &= ~(IER_AUTO_RTS |IER_AUTO_CTS ); +serial_out (up,UART_REG_IER , ier); + + up->port.flags &= ~UPF_HARD_FLOW ; + } +serial_out (up,UART_REG_MSR , (serial_in (up,UART_REG_MSR ) |MSR_CTSACTLV ));
Split this to 3 lines.
drivers/tty/serial/ma35d1_serial.c line 340
Quoted 1 line
drivers/tty/serial/ma35d1_serial.c new file +1
-0+serial_out (up,UART_REG_MCR , mcr);
Is it okay to write 0 to MCR here (when neither of the branches that read the previous value above are taken)?
Quoted 46 lines
drivers/tty/serial/ma35d1_serial.c new file +46
-0+} + +static void ma35d1serial_break_ctl (struct uart_port *port,int break_state) +{ +struct uart_ma35d1_port *up =to_ma35d1_uart_port (port); +unsigned long flags; +u32 lcr; + +spin_lock_irqsave (&up->port.lock, flags); + lcr =serial_in (up,UART_REG_LCR ); +if (break_state !=0 ) + lcr |=LCR_BREAK ; +else + lcr &= ~LCR_BREAK ; +serial_out (up,UART_REG_LCR , lcr); +spin_unlock_irqrestore (&up->port.lock, flags); +} + +static int ma35d1serial_startup (struct uart_port *port) +{ +struct uart_ma35d1_port *up =to_ma35d1_uart_port (port); +int retval; + +/* Reset FIFO */ +serial_out (up,UART_REG_FCR ,FCR_TFR |FCR_RFR ); + +/* Clear pending interrupts */ +serial_out (up,UART_REG_ISR ,ISR_ALL ); + + retval =request_irq (port->irq, ma35d1serial_interrupt,0 , +dev_name (port->dev), port); +if (retval) { +dev_err (up->port.dev,"request irq failed.\n" ); +return retval; + } + +serial_out (up,UART_REG_FCR ,serial_in (up,UART_REG_FCR ) | +FCR_RFITL_4BYTES |FCR_RTSTRGLV_8BYTES ); +serial_out (up,UART_REG_LCR ,LCR_WLS_8BITS ); +serial_out (up,UART_REG_TOR ,UART_RX_TOUT ); +serial_out (up,UART_REG_IER ,IER_RTO_IEN |IER_RDA_IEN | +IER_TIME_OUT_EN |IER_BUFERR_IEN ); +return 0 ; +} + +static void ma35d1serial_shutdown (struct uart_port *port)
drivers/tty/serial/ma35d1_serial.c line 396
Quoted 10 lines
drivers/tty/serial/ma35d1_serial.c new file +10
-0+{ +struct uart_ma35d1_port *up =to_ma35d1_uart_port (port); + +serial_out (up,UART_REG_IER ,0 ); +free_irq (port->irq, port); +} + +static u32 ma35d1serial_get_divisor (struct uart_port *port,u32 baud) +{ +return (port->uartclk / baud) -2 ;
What is the magic 2?
Quoted 13 lines
drivers/tty/serial/ma35d1_serial.c new file +13
-0+} + +static void ma35d1serial_set_termios (struct uart_port *port, +struct ktermios *termios, +const struct ktermios *old) +{ +struct uart_ma35d1_port *up =to_ma35d1_uart_port (port); +u32 lcr =0 ; +unsigned long flags; +u32 baud, quot; + + lcr =UART_LCR_WLEN (tty_get_char_size (termios->c_cflag)); +
drivers/tty/serial/ma35d1_serial.c line 419
Quoted 10 lines
drivers/tty/serial/ma35d1_serial.c new file +10
-0+if (termios->c_cflag &CSTOPB ) + lcr |=LCR_NSB ; +if (termios->c_cflag &PARENB ) + lcr |=LCR_PBE ; +if (!(termios->c_cflag &PARODD )) + lcr |=LCR_EPE ; +if (termios->c_cflag &CMSPAR ) + lcr |=LCR_SPE ; + + baud = uart_get_baud_rate(port, termios, old, port->uartclk / 0xffff,
UART_DIV_MAX ?
Quoted 217 lines
drivers/tty/serial/ma35d1_serial.c new file +217
-0+ port->uartclk / 11); + + quot =ma35d1serial_get_divisor (port, baud); + +/* +* Ok, we're now changing the port state. Do it with +* interrupts disabled. +*/ +spin_lock_irqsave (&up->port.lock, flags); + + up->port.read_status_mask =FSR_RX_OVER_IF ; +if (termios->c_iflag &INPCK ) + up->port.read_status_mask |=FSR_FEF |FSR_PEF ; +if (termios->c_iflag & (BRKINT |PARMRK )) + up->port.read_status_mask |=FSR_BIF ; + +/* Characteres to ignore */ + up->port.ignore_status_mask =0 ; +if (termios->c_iflag &IGNPAR ) + up->port.ignore_status_mask |=FSR_FEF |FSR_PEF ; +if (termios->c_iflag &IGNBRK ) { + up->port.ignore_status_mask |=FSR_BIF ; +/* +* If we're ignoring parity and break indicators, +* ignore overruns too (for real raw support). +*/ +if (termios->c_iflag &IGNPAR ) + up->port.ignore_status_mask |=FSR_RX_OVER_IF ; + } +if (termios->c_cflag &CRTSCTS ) + up->mcr |=UART_MCR_AFE ; +else + up->mcr &= ~UART_MCR_AFE ; + +uart_update_timeout (port, termios->c_cflag, baud); +ma35d1serial_set_mctrl (&up->port, up->port.mctrl); +serial_out (up,UART_REG_BAUD , quot |BAUD_MODE2 ); +serial_out (up,UART_REG_LCR , lcr); +spin_unlock_irqrestore (&up->port.lock, flags); +} + +static const char *ma35d1serial_type (struct uart_port *port) +{ +return "ma35d1-uart" ; +} + +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 ; +} + +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 ; +} + +static const struct uart_ops ma35d1serial_ops = { + .tx_empty = ma35d1serial_tx_empty, + .set_mctrl = ma35d1serial_set_mctrl, + .get_mctrl = ma35d1serial_get_mctrl, + .stop_tx = ma35d1serial_stop_tx, + .start_tx = ma35d1serial_start_tx, + .stop_rx = ma35d1serial_stop_rx, + .break_ctl = ma35d1serial_break_ctl, + .startup = ma35d1serial_startup, + .shutdown = ma35d1serial_shutdown, + .set_termios = ma35d1serial_set_termios, + .type = ma35d1serial_type, + .config_port = ma35d1serial_config_port, + .verify_port = ma35d1serial_verify_port, +}; + +static const struct of_device_id ma35d1_serial_of_match[] = { + { .compatible ="nuvoton,ma35d1-uart" }, + {}, +}; +MODULE_DEVICE_TABLE (of, ma35d1_serial_of_match); + +#ifdef CONFIG_SERIAL_NUVOTON_MA35D1_CONSOLE + +static struct device_node *ma35d1serial_uart_nodes[UART_NR ]; + +static void wait_for_xmitr (struct uart_ma35d1_port *up) +{ +unsigned int tmout; + +/* Wait up to 10ms for the character(s) to be sent. */ + tmout =10000 ; +while (--tmout) { +if (serial_in (up,UART_REG_FSR ) &FSR_TX_EMPTY ) +break ; +udelay (1 ); + } +} + +static void ma35d1serial_console_putchar (struct uart_port *port,unsigned char ch) +{ +struct uart_ma35d1_port *up =to_ma35d1_uart_port (port); + +wait_for_xmitr (up); +serial_out (up,UART_REG_THR , ch); +} + +/* +* Print a string to the serial port trying not to disturb +* any possible real use of the port... +* +* The console_lock must be held when we get here. +*/ +static void ma35d1serial_console_write (struct console *co, +const char *s,u32 count) +{ +struct uart_ma35d1_port *up = &ma35d1serial_ports[co->index]; +unsigned long flags; +u32 ier; + +spin_lock_irqsave (&up->port.lock, flags); + +/* +* First save the IER then disable the interrupts +*/ + ier =serial_in (up,UART_REG_IER ); +serial_out (up,UART_REG_IER ,0 ); + +uart_console_write (&up->port, s, count, ma35d1serial_console_putchar); + +wait_for_xmitr (up); +serial_out (up,UART_REG_IER , ier); + +spin_unlock_irqrestore (&up->port.lock, flags); +} + +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 +* if so, search for the first available port that does have +* console support. +*/ +if ((co->index <0 ) || (co->index >=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 ) +return -EINVAL ; + p->port.iobase = val32[1 ]; + p->port.membase =ioremap (p->port.iobase,UART_REG_SIZE ); + p->port.ops = &ma35d1serial_ops; + p->port.line =0 ; + p->port.uartclk =UART_CONSOLE_CLK ; + + port = &ma35d1serial_ports[co->index].port; + +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 ="ttyS" , + .write = ma35d1serial_console_write, + .device = uart_console_device, + .setup = ma35d1serial_console_setup, + .flags =CON_PRINTBUFFER |CON_ENABLED , + .index =-1 , + .data = &ma35d1serial_reg, +}; + +static void ma35d1serial_console_init_port (void ) +{ +u32 i =0 ; +struct device_node *np; + +for_each_matching_node (np, ma35d1_serial_of_match) { +if (ma35d1serial_uart_nodes[i] ==NULL ) { +of_node_get (np); + ma35d1serial_uart_nodes[i] = np; + i++; +if (i ==UART_NR ) +break ; + } + } +} + +static int __init ma35d1serial_console_init (void ) +{ +ma35d1serial_console_init_port (); +register_console (&ma35d1serial_console); +return 0 ; +} +console_initcall (ma35d1serial_console_init); + +#define MA35D1SERIAL_CONSOLE (&ma35d1serial_console) +#else +#define MA35D1SERIAL_CONSOLE NULL +#endif
drivers/tty/serial/ma35d1_serial.c line 646
Quoted 10 lines
drivers/tty/serial/ma35d1_serial.c new file +10
-0+ +static struct uart_driver ma35d1serial_reg = { + .owner =THIS_MODULE , + .driver_name ="serial" , + .dev_name ="ttyS" , + .major =TTY_MAJOR , + .minor =64 , + .cons =MA35D1SERIAL_CONSOLE , + .nr =UART_NR , +};
This doesn't seem necessary, 8250 core will have the uart_driver for you and most of the console stuff too. You just need to setup a few things correctly (see the setup functions in 8250_early for ideas/examples).
Quoted 45 lines
drivers/tty/serial/ma35d1_serial.c new file +45
-0+/* +* Register a set of serial devices attached to a platform device. +* The list is terminated with a zero flags entry, which means we expect +* all entries to have at least UPF_BOOT_AUTOCONF set. +*/ +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; + 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,UART_REG_SIZE ); + 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 );
drivers/tty/serial/ma35d1_serial.c line 702
Quoted 10 lines
drivers/tty/serial/ma35d1_serial.c new file +10
-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);
For 8250, you should be using serial8250_register_8250_port(). See the other drivers how to setup the console functions.
Quoted 15 lines
drivers/tty/serial/ma35d1_serial.c new file +15
-0+if (ret <0 ) + goto err_free_irq; + +return 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; +}
drivers/tty/serial/ma35d1_serial.c line 727
Quoted 10 lines
drivers/tty/serial/ma35d1_serial.c new file +10
-0+ +/* +* Remove serial ports registered against a platform device. +*/ +static int ma35d1serial_remove (struct platform_device *dev) +{ +struct uart_port *port =platform_get_drvdata (dev); +struct uart_ma35d1_port *up =to_ma35d1_uart_port (port); + +uart_remove_one_port (&ma35d1serial_reg, port);
serial8250_unregister_port()
Quoted 28 lines
drivers/tty/serial/ma35d1_serial.c new file +28
-0+clk_disable_unprepare (up->clk); +return 0 ; +} + +static int ma35d1serial_suspend (struct platform_device *dev,pm_message_t state) +{ +struct uart_port *port =platform_get_drvdata (dev); +struct uart_ma35d1_port *up =to_ma35d1_uart_port (port); + +uart_suspend_port (&ma35d1serial_reg, &up->port); +if (up->port.line ==0 ) { + up->console_baud_rate =serial_in (up,UART_REG_BAUD ); + up->console_line =serial_in (up,UART_REG_LCR ); + up->console_int =serial_in (up,UART_REG_IER ); + } +return 0 ; +} + +static int ma35d1serial_resume (struct platform_device *dev) +{ +struct uart_port *port =platform_get_drvdata (dev); +struct uart_ma35d1_port *up =to_ma35d1_uart_port (port); + +if (up->port.line ==0 ) { +serial_out (up,UART_REG_BAUD , up->console_baud_rate); +serial_out (up,UART_REG_LCR , up->console_line); +serial_out (up,UART_REG_IER , up->console_int); + }
drivers/tty/serial/ma35d1_serial.c line 764
Quoted 10 lines
drivers/tty/serial/ma35d1_serial.c new file +9
-0+uart_resume_port (&ma35d1serial_reg, &up->port); +return 0 ; +} + +static struct platform_driver ma35d1serial_driver = { + .probe = ma35d1serial_probe, + .remove = ma35d1serial_remove, + .suspend = ma35d1serial_suspend, + .resume = ma35d1serial_resume,
Shouldn't these be under .driver.pm instead?
Quoted 33 lines
drivers/tty/serial/ma35d1_serial.c new file +32
-0+ .driver = { + .name = "ma35d1-uart", + .owner = THIS_MODULE, + .of_match_table = of_match_ptr(ma35d1_serial_of_match), + }, +}; + +static int __init ma35d1serial_init (void ) +{ +int ret; + + ret =uart_register_driver (&ma35d1serial_reg); +if (ret) +return ret; + ret =platform_driver_register (&ma35d1serial_driver); +if (ret) +uart_unregister_driver (&ma35d1serial_reg); +return ret; +} + +static void __exit ma35d1serial_exit(void) +{ +platform_driver_unregister (&ma35d1serial_driver); +uart_unregister_driver (&ma35d1serial_reg); +} + +module_init (ma35d1serial_init); +module_exit (ma35d1serial_exit); + +MODULE_LICENSE ("GPL" ); +MODULE_DESCRIPTION ("MA35D1 serial driver" ); +
Signature · 1 line
i.
Re: [PATCH v10 10/10] tty: serial: Add Nuvoton ma35d1 serial driver support
Quoted 14 lines · Ilpo Järvinen
drivers/tty/serial/ma35d1_serial.c line 23
Quoted 9 lines · Jacky Huang
drivers/tty/serial/ma35d1_serial.c new file +9
-0+ +#define UART_NR 17 + +#define UART_REG_RBR 0x00 +#define UART_REG_THR 0x00 +#define UART_REG_IER 0x04 +#define UART_REG_FCR 0x08 +#define UART_REG_LCR 0x0C +#define UART_REG_MCR 0x10These duplicate
include/uapi/linux/serial_reg.hones, use the std ones directly.
Quoted 1 line
Setup regshift too and use it in
serial_in.
I think this came up in previous reviews, but it turned out that only the first six registers are compatible, while the later ones are all different, and it's not 8250 compatible.
It might be helpful to rename the registers to something with a prefix other than UART_REG_*, to avoid the confusion and possible namespace clash.
Quoted 7 lines
drivers/tty/serial/ma35d1_serial.c line 37
Quoted 5 lines
drivers/tty/serial/ma35d1_serial.c new file +4
-0+/* UART_REG_IER - Interrupt Enable Register */ +#define IER_RDA_IEN BIT(0)/* RBR Available Interrupt Enable */ +#define IER_THRE_IEN BIT(1)/* THR Empty Interrupt Enable */ +#define IER_RLS_IEN BIT(2)/* RX Line Status Interrupt Enable */ These look same as
UART_IERbits, use the std ones.
...
Quoted 2 lines
Are these same as UART_FCR_CLEAR_* functionality wise? If they're use std ones.
Again, I'd think we're better off having a distinct naming for them than trying to share the definitions with 8250.
Quoted 14 lines
drivers/tty/serial/ma35d1_serial.c line 646
Quoted 9 lines
drivers/tty/serial/ma35d1_serial.c new file +9
-0+static struct uart_driver ma35d1serial_reg = { + .owner =THIS_MODULE , + .driver_name ="serial" , + .dev_name ="ttyS" , + .major =TTY_MAJOR , + .minor =64 , + .cons =MA35D1SERIAL_CONSOLE , + .nr =UART_NR , +};This doesn't seem necessary, 8250 core will have the
uart_driverfor you and most of the console stuff too. You just need to setup a few things correctly (see the setup functions in 8250_early for ideas/examples).
...
Quoted 5 lines
drivers/tty/serial/ma35d1_serial.c line 702
Quoted 2 lines
drivers/tty/serial/ma35d1_serial.c new file +2
-0+ + ret =uart_add_one_port (&ma35d1serial_reg, &up->port);For 8250, you should be using
serial8250_register_8250_port(). See the other drivers how to setup the console functions.
Consequently, this should also be kept separate from the serial8250 driver, I don't see a way to fit the nuvoton code into the existing driver without making the resulting driver worse for everyone.
There is one thing that absolutely needs to be changed though:
the driver_name/dev_name/major/minor fields all clash with the 8250 driver, so you cannot have a kernel that has both drivers built-in. All of these should change to get out of the way of the existing drivers.
Arnd
Re: [PATCH v10 10/10] tty: serial: Add Nuvoton ma35d1 serial driver support
Quoted 15 lines · Arnd Bergmann
Quoted 14 lines · Ilpo Järvinen
drivers/tty/serial/ma35d1_serial.c line 23
Quoted 9 lines · Jacky Huang
drivers/tty/serial/ma35d1_serial.c new file +9
-0+ +#define UART_NR 17 + +#define UART_REG_RBR 0x00 +#define UART_REG_THR 0x00 +#define UART_REG_IER 0x04 +#define UART_REG_FCR 0x08 +#define UART_REG_LCR 0x0C +#define UART_REG_MCR 0x10These duplicate
include/uapi/linux/serial_reg.hones, use the std ones directly.
Quoted 5 lines
Quoted 1 line
Setup regshift too and use it in
serial_in.I think this came up in previous reviews, but it turned out that only the first six registers are compatible, while the later ones are all different, and it's not 8250 compatible.
So use the normal name for compatible ones and HW specific names for the others?
It might not be compatible in everything but surely 8250 influence is visible here and there.
Quoted 3 lines
It might be helpful to rename the registers to something with a prefix other than UART_REG_*, to avoid the confusion and possible namespace clash.
That is what I also suggested for the rest of the registers.
Signature · 1 line
i.
Quoted 45 lines
Quoted 6 lines
drivers/tty/serial/ma35d1_serial.c line 37
Quoted 4 lines
drivers/tty/serial/ma35d1_serial.c new file +4
-0+/* UART_REG_IER - Interrupt Enable Register */ +#define IER_RDA_IEN BIT(0)/* RBR Available Interrupt Enable */ +#define IER_THRE_IEN BIT(1)/* THR Empty Interrupt Enable */ +#define IER_RLS_IEN BIT(2)/* RX Line Status Interrupt Enable */ These look same as
UART_IERbits, use the std ones....
Quoted 2 lines
Are these same as UART_FCR_CLEAR_* functionality wise? If they're use std ones.
Again, I'd think we're better off having a distinct naming for them than trying to share the definitions with 8250.
Quoted 14 lines
drivers/tty/serial/ma35d1_serial.c line 646
Quoted 9 lines
drivers/tty/serial/ma35d1_serial.c new file +9
-0+static struct uart_driver ma35d1serial_reg = { + .owner =THIS_MODULE , + .driver_name ="serial" , + .dev_name ="ttyS" , + .major =TTY_MAJOR , + .minor =64 , + .cons =MA35D1SERIAL_CONSOLE , + .nr =UART_NR , +};This doesn't seem necessary, 8250 core will have the
uart_driverfor you and most of the console stuff too. You just need to setup a few things correctly (see the setup functions in 8250_early for ideas/examples).
...Quoted 5 lines
drivers/tty/serial/ma35d1_serial.c line 702
Quoted 2 lines
drivers/tty/serial/ma35d1_serial.c new file +2
-0+ + ret =uart_add_one_port (&ma35d1serial_reg, &up->port);For 8250, you should be using
serial8250_register_8250_port(). See the other drivers how to setup the console functions.Consequently, this should also be kept separate from the serial8250 driver, I don't see a way to fit the nuvoton code into the existing driver without making the resulting driver worse for everyone.
There is one thing that absolutely needs to be changed though:
the driver_name/dev_name/major/minor fields all clash with the 8250 driver, so you cannot have a kernel that has both drivers built-in. All of these should change to get out of the way of the existing drivers.Arnd
Re: [PATCH v10 10/10] tty: serial: Add Nuvoton ma35d1 serial driver support
Quoted 22 lines · Ilpo Järvinen
Quoted 15 lines · Arnd Bergmann
Quoted 14 lines · Ilpo Järvinen
drivers/tty/serial/ma35d1_serial.c line 23
Quoted 9 lines · Jacky Huang
drivers/tty/serial/ma35d1_serial.c new file +9
-0+ +#define UART_NR 17 + +#define UART_REG_RBR 0x00 +#define UART_REG_THR 0x00 +#define UART_REG_IER 0x04 +#define UART_REG_FCR 0x08 +#define UART_REG_LCR 0x0C +#define UART_REG_MCR 0x10These duplicate
include/uapi/linux/serial_reg.hones, use the std ones directly.Quoted 5 lines
Quoted 1 line
Setup regshift too and use it in
serial_in.I think this came up in previous reviews, but it turned out that only the first six registers are compatible, while the later ones are all different, and it's not 8250 compatible.
Quoted 5 lines
So use the normal name for compatible ones and HW specific names for the others?
It might not be compatible in everything but surely 8250 influence is visible here and there.
I'd rename all of them and share nothing. I had the same thought as you when I first looked at the driver, and thought of how we merged the omap uart into 8250 for this reason, but after I found a datasheet for this one, my impression was that it's a much more distant cousin of 8250 than the others,
There is clearly some family lineage, but there are differences everywhere, and I don't think it was designed by extending a 8250 compatible hardware block with extra features, but rather built from scratch (sigh) based only loosely on a register description but then extending it with no intent of retaining compatibility.
Arnd
Re: [PATCH v10 10/10] tty: serial: Add Nuvoton ma35d1 serial driver support
Dear Arnd and Ilpo,
Thank you for the comments.
Quoted 31 lines · Arnd Bergmann
Quoted 16 lines · Ilpo Järvinen
Quoted 15 lines · Arnd Bergmann
Quoted 14 lines · Ilpo Järvinen
drivers/tty/serial/ma35d1_serial.c line 23
Quoted 9 lines · Jacky Huang
drivers/tty/serial/ma35d1_serial.c new file +9
-0+ +#define UART_NR 17 + +#define UART_REG_RBR 0x00 +#define UART_REG_THR 0x00 +#define UART_REG_IER 0x04 +#define UART_REG_FCR 0x08 +#define UART_REG_LCR 0x0C +#define UART_REG_MCR 0x10These duplicate
include/uapi/linux/serial_reg.hones, use the std ones directly.Setup regshift too and use it in
serial_in.Quoted 8 lines
Quoted 3 lines
I think this came up in previous reviews, but it turned out that only the first six registers are compatible, while the later ones are all different, and it's not 8250 compatible.
So use the normal name for compatible ones and HW specific names for the others?
It might not be compatible in everything but surely 8250 influence is visible here and there.
I'd rename all of them and share nothing. I had the same thought as you when I first looked at the driver, and thought of how we merged the omap uart into 8250 for this reason, but after I found a datasheet for this one, my impression was that it's a much more distant cousin of 8250 than the others,
Quoted 7 lines
There is clearly some family lineage, but there are differences everywhere, and I don't think it was designed by extending a 8250 compatible hardware block with extra features, but rather built from scratch (sigh) based only loosely on a register description but then extending it with no intent of retaining compatibility.
Arnd
Yes, the design of this UART IP is indeed incompatible with the 8250, but it does imitate the 8250 in some register and register bit field naming, and even in usage definitions, which can easily lead to misunderstandings.
In order to distinguish it from the 8250 and make it clear that it has nothing to do with the 8250, I hope you can agree with me not to use the existing register and bit field definitions of the 8250 in this driver.
In fact, this UART design has been used for more than 15 years and is used in our M0/M23/M4, ARM7/ARM9 MCUs and MPUs. The MA35 series will also continue to use this design. I will add the MA35_ prefix to all registers and bit fields, and make the modifications suggested by Ilpo that are unrelated to this 8250 issue.
Best Regards,
Jacky Huang
Re: [PATCH v10 10/10] tty: serial: Add Nuvoton ma35d1 serial driver support
Quoted 16 lines · Jacky Huang
Quoted 15 lines · Arnd Bergmann
Quoted 14 lines · Ilpo Järvinen
Quoted 13 lines · Arnd Bergmann
Quoted 12 lines · Ilpo Järvinen
drivers/tty/serial/ma35d1_serial.c line 23
Quoted 9 lines · Jacky Huang
drivers/tty/serial/ma35d1_serial.c new file +9
-0+ +#define UART_NR 17 + +#define UART_REG_RBR 0x00 +#define UART_REG_THR 0x00 +#define UART_REG_IER 0x04 +#define UART_REG_FCR 0x08 +#define UART_REG_LCR 0x0C +#define UART_REG_MCR 0x10These duplicate
include/uapi/linux/serial_reg.hones, use the std ones directly.
...
Quoted 17 lines
Quoted 7 lines
There is clearly some family lineage, but there are differences everywhere, and I don't think it was designed by extending a 8250 compatible hardware block with extra features, but rather built from scratch (sigh) based only loosely on a register description but then extending it with no intent of retaining compatibility.
Yes, the design of this UART IP is indeed incompatible with the 8250, but it does imitate the 8250 in some register and register bit field naming, and even in usage definitions, which can easily lead to misunderstandings.
In order to distinguish it from the 8250 and make it clear that it has nothing
to do with the 8250, I hope you can agree with me not to use the existing register and bit field definitions of the 8250 in this driver.
Quoted 6 lines
In fact, this UART design has been used for more than 15 years and is used in our M0/M23/M4, ARM7/ARM9 MCUs and MPUs. The MA35 series will also continue to use this design. I will add the
MA35_prefix to all registers and bit
fields, and make the modifications suggested by Ilpo that are unrelated to this 8250 issue.
Sounds good to me, thanks! It would be good if Jiri or GregKH can also weigh in to make sure they agree on this approach.
On the topic of tty namespace, please also add the change that I suggested to pick an unused major/minor number range. I'm not entirely sure about whether using name="ttyS" is actually preferred here or if you should pick something else here as well. I see that "ttyN" has no other users are the moment, though "ttyn" is what drivers/tty/serial/jsm/ has.
Maybe Jiri can also recommend what to pick here.
Arnd