pwm: add PWM driver for atcpit100
Subsystems (2)
v3 cover pwm: add PWM driver for atcpit100
Re-introduce the driver for atcpit100. This device driver was previously part of the Linux Kernel, but was removed due to the deprecation of the NDS32 architecture [1]. Although Andes now dedicates our effort on RISC-V, ATCPIT100 is still one of our peripheral platform IPs, and that's why we are re-introducing it now.
This patch series includes DT-bindings(1/2) and PWM driver(2/2).
The ATCPIT100 Programmable Interval Timer (PIT) is a set of compact multi-function timers, which can be used as pulse width modulators (PWM) as well as simple timers. ATCPIT100 supports up to 4 PIT channels, and each PIT channel may be a simple timer or PWM, or a combination of the timer and the PWM.
[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=aec499c75cf8e0b599be4d559e6922b613085f8f
---
Changes in v3:
(1/2):
- modify the compatible string according to Krzysztof's review.
(2/2):
- add a check for the clock rate to prevent the overflow warning by
kernel test robot.
- remove the unnecessary check in .apply() reported by kernel test
robot.
Link to v2: https://lore.kernel.org/linux-pwm/[email protected]/T/#t
Changes in v2:
(1/2):
- change "title" in the yaml file.
- remove vendor-specific property, and add clocks property.
(2/2):
- add a description for hardware limitations.
- instead of statically configuring the clock source in the dtb, switch the clock parent depending on the requested setting.
- have some minor changes according to Uwe's suggestion.
Link to v1: https://lore.kernel.org/linux-pwm/[email protected]/T/#t
---
Ben Zong-You Xie (2):
dt-bindings: pwm: add atcpit100
pwm: atcpit100: add Andes PWM driver support
.../bindings/pwm/andestech,atcpit100-pwm.yaml | 51 +++ MAINTAINERS | 6 + drivers/pwm/Kconfig | 17 + drivers/pwm/Makefile | 1 + drivers/pwm/pwm-atcpit100.c | 296 ++++++++++++++++++ 5 files changed, 371 insertions(+) create mode 100644 Documentation/devicetree/bindings/pwm/andestech,atcpit100-pwm.yaml create mode 100644 drivers/pwm/pwm-atcpit100.c
---
2.34.1
PATCH v3 1/2 dt-bindings: pwm: add atcpit100
Document devicetree bindings for Andes PWM controller.
--- .../bindings/pwm/andestech,atcpit100-pwm.yaml | 51 +++++++++++++++++++ MAINTAINERS | 5 ++ 2 files changed, 56 insertions(+) create mode 100644 Documentation/devicetree/bindings/pwm/andestech,atcpit100-pwm.yaml
Documentation/devicetree/bindings/pwm/andestech,atcpit100-pwm.yaml new file +51 -0
@@ -0,0 +1,51 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/pwm/andestech,atcpit100-pwm.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Andes PWM controller + +maintainers: + - Ben Zong-You Xie <[email protected]> + +allOf: + - $ref: pwm.yaml# + +properties: + compatible: + const: andestech,atcpit100 + + reg: + maxItems: 1 + + "#pwm-cells": + const: 3 + + clocks: + maxItems: 2 + + clock-names: + items: + - const: ext + - const: apb + + +required: + - compatible + - reg + - "#pwm-cells" + - clocks + - clock-names + +unevaluatedProperties: false + +examples: + - | + pwm@f0400000 { + compatible = "andestech,atcpit100"; + reg = <0xf0400000 0x1000>; + #pwm-cells = <3>; + clocks = <&smu 1>, <&smu 7>; + clock-names = "ext", "apb"; + };
MAINTAINERS +5 -0
@@ -3588,6 +3588,11 @@ F: drivers/power/reset/atc260x-poweroff.c F: drivers/regulator/atc260x-regulator.c F: include/linux/mfd/atc260x/* +ATCPIT100 PWM DRIVER +M: Ben Zong-You Xie <[email protected]> +S: Supported +F: Documentation/devicetree/bindings/pwm/andestech,atcpit100-pwm.yaml + ATHEROS 71XX/9XXX GPIO DRIVER M: Alban Bedel <[email protected]> S: Maintained
Signature · 1 line
2.34.1
Re: [v3 1/2] dt-bindings: pwm: add atcpit100
Quoted 1 line · Ben Zong-You Xie
Document devicetree bindings for Andes PWM controller.
Please use standard email subjects, so with the PATCH keyword in the title. git format-patch -vX helps here to create proper versioned patches. Another useful tool is b4. Skipping the PATCH keyword makes filtering of emails more difficult thus making the review process less convenient.
Documentation/devicetree/bindings/pwm/andestech,atcpit100-pwm.yaml
Quoted 13 lines
Signed-off-by Ben Zong-You Xie <[email protected]>--- .../bindings/pwm/andestech,atcpit100-pwm.yaml | 51 +++++++++++++++++++ MAINTAINERS | 5 ++ 2 files changed, 56 insertions(+) create mode 100644 Documentation/devicetree/bindings/pwm/andestech,atcpit100-pwm.yamlDocumentation/devicetree/bindings/pwm/andestech,atcpit100-pwm.yaml new file +0
-0
Filename: andestech,atcpit100.yaml
Documentation/devicetree/bindings/pwm/andestech,atcpit100-pwm.yaml line 2
Quoted 3 lines
Documentation/devicetree/bindings/pwm/andestech,atcpit100-pwm.yaml new file +2
-0@@ -0,0 +1,51 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2
Best regards,
Krzysztof
PATCH v3 2/2 pwm: atcpit100: add Andes PWM driver support
In reply to Ben Zong-You XieAdd PWM driver support for atcpit100 on Andes AE350 platform.
--- MAINTAINERS | 1 + drivers/pwm/Kconfig | 17 +++ drivers/pwm/Makefile | 1 + drivers/pwm/pwm-atcpit100.c | 296 ++++++++++++++++++++++++++++++++++++ 4 files changed, 315 insertions(+) create mode 100644 drivers/pwm/pwm-atcpit100.c
MAINTAINERS +1 -0
@@ -3592,6 +3592,7 @@ ATCPIT100 PWM DRIVER M: Ben Zong-You Xie <[email protected]> S: Supported F: Documentation/devicetree/bindings/pwm/andestech,atcpit100-pwm.yaml +F: drivers/pwm/pwm-atcpit100.c ATHEROS 71XX/9XXX GPIO DRIVER M: Alban Bedel <[email protected]>
drivers/pwm/Kconfig +17 -0
@@ -66,6 +66,23 @@ config PWM_APPLE To compile this driver as a module, choose M here: the module will be called pwm-apple. +config PWM_ATCPIT100 + tristate "Andes ATCPIT100 PWM support" + depends on OF && HAS_IOMEM + depends on RISCV || COMPILE_TEST + select REGMAP_MMIO + help + Generic PWM framework driver for ATCPIT100 on Andes AE350 platform + + The ATCPIT100 Programmable Interval Timer (PIT) is a set of compact + multi-function timers, which can be used as pulse width + modulators (PWM) as well as simple timers. ATCPIT100 supports up to 4 + PIT channels. Each PIT channel can be a simple timer or PWM, or a + combination of timer and PWM. + + To compile this driver as a module, choose M here: the module + will be called pwm-atcpit100. + config PWM_ATMEL tristate "Atmel PWM support" depends on ARCH_AT91 || COMPILE_TEST
drivers/pwm/Makefile +1 -0
@@ -3,6 +3,7 @@ obj-$(CONFIG_PWM) += core.o obj-$(CONFIG_PWM_AB8500) += pwm-ab8500.o obj-$(CONFIG_PWM_ADP5585) += pwm-adp5585.o obj-$(CONFIG_PWM_APPLE) += pwm-apple.o +obj-$(CONFIG_PWM_ATCPIT100) += pwm-atcpit100.o obj-$(CONFIG_PWM_ATMEL) += pwm-atmel.o obj-$(CONFIG_PWM_ATMEL_HLCDC_PWM) += pwm-atmel-hlcdc.o obj-$(CONFIG_PWM_ATMEL_TCB) += pwm-atmel-tcb.o
drivers/pwm/pwm-atcpit100.c new file +296 -0
296 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [v3 2/2] pwm: atcpit100: add Andes PWM driver support
drivers/pwm/Kconfig config PWM_APPLE · line 75
Quoted 8 lines · Ben Zong-You Xie
drivers/pwm/Kconfig +7
-0+config PWM_ATCPIT100 + tristate "Andes ATCPIT100 PWM support" + depends on OF && HAS_IOMEM + depends on RISCV || COMPILE_TEST + select REGMAP_MMIO + help + Generic PWM framework driver for ATCPIT100 on Andes AE350 platform
Is AE350 a type of a SoC? Looks like. "depends on RISCV" is wrong - there is nothing RISC-V specific here. You must depend on given SoC/platform.
Quoted 8 lines
drivers/pwm/Kconfig +8
-0+ + The ATCPIT100 Programmable Interval Timer (PIT) is a set of compact + multi-function timers, which can be used as pulse width + modulators (PWM) as well as simple timers. ATCPIT100 supports up to 4 + PIT channels. Each PIT channel can be a simple timer or PWM, or a + combination of timer and PWM. + + To compile this driver as a module, choose M here: the module
...
Quoted 11 lines
drivers/pwm/pwm-atcpit100.c new file +11
-0+static int atcpit100_pwm_get_state (struct pwm_chip *chip, +struct pwm_device *pwm, +struct pwm_state *state) +{ +int clk; +int ret; +unsigned int ctrl_val; +unsigned int reload_val; +u16 pwm_high; +u16 pwm_low; +unsigned int channel = pwm->hwpwm;
drivers/pwm/pwm-atcpit100.c line 204
Quoted 10 lines
drivers/pwm/pwm-atcpit100.c new file +10
-0+struct atcpit100_pwm *ap =to_atcpit100_pwm (chip); + + ret =regmap_read (ap->regmap,ATCPIT100_CHANNEL_CTRL (channel), + &ctrl_val); +if (ret) +return ret; + + clk = (ctrl_val &ATCPIT100_CHANNEL_CTRL_CLK ) ?ATCPIT100_CLK_APB + :ATCPIT100_CLK_EXT ; + state->enabled =
Don't wrap here...
drivers/pwm/pwm-atcpit100.c line 205
Quoted 1 line
drivers/pwm/pwm-atcpit100.c new file +1
-0+ regmap_test_bits(ap->regmap, ATCPIT100_CHANNEL_ENABLE,
but wrap at arguments.
Quoted 39 lines
drivers/pwm/pwm-atcpit100.c new file +39
-0+ ATCPIT100_CHANNEL_ENABLE_PWM(channel)); + state->polarity =PWM_POLARITY_NORMAL ; + ret =regmap_read (ap->regmap,ATCPIT100_CHANNEL_RELOAD (channel), + &reload_val); +if (ret) +return ret; + + pwm_high =FIELD_GET (ATCPIT100_CHANNEL_RELOAD_HIGH , reload_val); + pwm_low =FIELD_GET (ATCPIT100_CHANNEL_RELOAD_LOW , reload_val); + state->duty_cycle = +DIV64_U64_ROUND_UP ((pwm_high +1 ) *NSEC_PER_SEC , + ap->clk_rate[clk]); + state->period = + state->duty_cycle + +DIV64_U64_ROUND_UP ((pwm_low +1 ) *NSEC_PER_SEC , + ap->clk_rate[clk]); + +return 0 ; +} + +static const struct pwm_ops atcpit_pwm_ops = { + .apply = atcpit100_pwm_apply, + .get_state = atcpit100_pwm_get_state, +}; + +static int atcpit100_pwm_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct atcpit100_pwm *ap; +struct pwm_chip *chip; +void __iomem *base; +int ret; + + chip =devm_pwmchip_alloc (dev,ATCPIT100_CHANNEL_MAX ,sizeof (*ap)); +if (IS_ERR (chip)) +return PTR_ERR (chip); + + ap =to_atcpit100_pwm (chip); + base =devm_platform_ioremap_resource (pdev,0 );
drivers/pwm/pwm-atcpit100.c line 254
Quoted 10 lines
drivers/pwm/pwm-atcpit100.c new file +10
-0+if (IS_ERR (base)) +return PTR_ERR (base); + + ap->ext_clk =devm_clk_get_enabled (dev,"ext" ); + ap->clk_rate[ATCPIT100_CLK_EXT ] = ap->ext_clk ? +clk_get_rate (ap->ext_clk) :0 ; + ap->apb_clk =devm_clk_get_enabled (dev,"apb" ); + ap->clk_rate[ATCPIT100_CLK_APB ] = ap->apb_clk ? +clk_get_rate (ap->apb_clk) :0 ; +if (IS_ERR (ap->ext_clk) &&IS_ERR (ap->apb_clk)) {
Drop {}. See Linux coding style.
drivers/pwm/pwm-atcpit100.c line 265
Quoted 11 lines
drivers/pwm/pwm-atcpit100.c new file +11
-0+return dev_err_probe (dev,PTR_ERR (ap->ext_clk), +"failed to obtain any clock\n" ); + } + +if (ap->clk_rate[ATCPIT100_CLK_EXT ] >NSEC_PER_SEC || + ap->clk_rate[ATCPIT100_CLK_APB ] >NSEC_PER_SEC ) +return dev_err_probe (dev, -EINVAL ,"pwm clock out of range\n" ); + + ap->regmap =devm_regmap_init_mmio (dev, base, + &atcpit100_pwm_regmap_config); +if (IS_ERR (ap->regmap)) {
Drop {}. See Linux coding style.
drivers/pwm/pwm-atcpit100.c line 275
Quoted 10 lines
drivers/pwm/pwm-atcpit100.c new file +10
-0+return dev_err_probe (dev,PTR_ERR (ap->regmap), +"failed to init register map\n" ); + } + + chip->ops = &atcpit_pwm_ops; + ret =devm_pwmchip_add (dev, chip); +if (ret) +return dev_err_probe (dev, ret,"failed to add pwm chip\n" ); + +dev_info (dev,"pwm driver probed\n" );
Drop all such "success" messages.
Best regards,
Krzysztof
Re: [v3 2/2] pwm: atcpit100: add Andes PWM driver support
Quoted 13 lines · Krzysztof Kozlowski
[EXTERNAL MAIL]
drivers/pwm/Kconfig config PWM_APPLE · line 75
Quoted 8 lines · Ben Zong-You Xie
drivers/pwm/Kconfig +7
-0+config PWM_ATCPIT100 + tristate "Andes ATCPIT100 PWM support" + depends on OF && HAS_IOMEM + depends on RISCV || COMPILE_TEST + select REGMAP_MMIO + help + Generic PWM framework driver for ATCPIT100 on Andes AE350 platform
Quoted 4 lines
Is AE350 a type of a SoC? Looks like. "depends on RISCV" is wrong - there is nothing RISC-V specific here. You must depend on given SoC/platform.
Hi Krzysztof,
AE350 is not a SoC. It's just a reference platform to verify Andes CPUs on FPGA. For further information on AE350, please refer to [1].
Also, I will remove "depends on RISCV" and fix the coding style problems in the next patch. Thanks for your review.
Best regards,
Ben
Quoted 12 lines
Quoted 8 lines
drivers/pwm/Kconfig +8
-0+ + The ATCPIT100 Programmable Interval Timer (PIT) is a set of compact + multi-function timers, which can be used as pulse width + modulators (PWM) as well as simple timers. ATCPIT100 supports up to 4 + PIT channels. Each PIT channel can be a simple timer or PWM, or a + combination of timer and PWM. + + To compile this driver as a module, choose M here: the module...
Uwe Kleine-König
maintainerRe: [v3 2/2] pwm: atcpit100: add Andes PWM driver support
Hello Ben,
Quoted 1 line · Ben Zong-You Xie
Also, I will remove "depends on RISCV" [...]
Krzysztof didn't say so explicitly, but I think he wanted the dependency to be more restrictive, not less. At least that would be my concern here.
The rational is: Don't annoy people who work on ARM or x86 with questions about this driver that they don't need anyhow. If there is no stricter dependency possible, I'm happy with
depends on RISCV || COMPILE_TEST
. If however your driver is implemented in an FPGA, adding a dependency on a set of SoCs that have the known FPGA that provides that device would be a good idea.
Best regards
Uwe
Re: [v3 2/2] pwm: atcpit100: add Andes PWM driver support
In reply to Ben Zong-You XieQuoted 19 lines · Ben Zong-You Xie
Quoted 13 lines · Krzysztof Kozlowski
[EXTERNAL MAIL]
drivers/pwm/Kconfig config PWM_APPLE · line 75
Quoted 8 lines · Ben Zong-You Xie
drivers/pwm/Kconfig +7
-0+config PWM_ATCPIT100 + tristate "Andes ATCPIT100 PWM support" + depends on OF && HAS_IOMEM + depends on RISCV || COMPILE_TEST + select REGMAP_MMIO + help + Generic PWM framework driver for ATCPIT100 on Andes AE350 platformQuoted 4 lines
Is AE350 a type of a SoC? Looks like. "depends on RISCV" is wrong - there is nothing RISC-V specific here. You must depend on given SoC/platform.
Quoted 4 lines
Hi Krzysztof,
AE350 is not a SoC. It's just a reference platform to verify Andes CPUs on FPGA. For further information on AE350, please refer to [1].
Then what is the SoC?
Quoted 2 lines
Also, I will remove "depends on RISCV" and fix the coding style problems
No, read the review again and implement it:
"You must depend on given SoC/platform."
Best regards,
Krzysztof