pwm: add CSR SiRFSoC PWM driver
PATCH v2 1/1 pwm: add CSR SiRFSoC PWM driver
From: Rongjun Ying <[email protected]>
PWM controller of CSR SiRFSoC can generate 7 independent outputs. Each output duty cycle can be adjusted by setting the corresponding wait & hold registers.
Supports 7 independent channel output: 6 for external(channel0-5) and 1 for internal(channel6).
Supports wide frequency range: divide by 2 to 65536*2 of source clock.
---
-v2: clean the source clock of PWM wave, use OSC(26MHz)
drivers/pwm/Kconfig | 9 ++ drivers/pwm/Makefile | 1 + drivers/pwm/pwm-sirf.c | 294 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 304 insertions(+), 0 deletions(-) create mode 100644 drivers/pwm/pwm-sirf.c
drivers/pwm/Kconfig +9 -0
@@ -166,6 +166,15 @@ config PWM_SAMSUNG To compile this driver as a module, choose M here: the module will be called pwm-samsung. +config PWM_SIRF + tristate "SiRF PWM support" + depends on ARCH_SIRF + help + Generic PWM framework driver for SiRF SoC. + + To compile this driver as a module, choose M here: the module + will be called pwm-sirf. + config PWM_SPEAR tristate "STMicroelectronics SPEAr PWM support" depends on PLAT_SPEAR
drivers/pwm/Makefile +1 -0
@@ -14,6 +14,7 @@ obj-$(CONFIG_PWM_PUV3) += pwm-puv3.o obj-$(CONFIG_PWM_PXA) += pwm-pxa.o obj-$(CONFIG_PWM_RENESAS_TPU) += pwm-renesas-tpu.o obj-$(CONFIG_PWM_SAMSUNG) += pwm-samsung.o +obj-$(CONFIG_PWM_SIRF) += pwm-sirf.o obj-$(CONFIG_PWM_SPEAR) += pwm-spear.o obj-$(CONFIG_PWM_TEGRA) += pwm-tegra.o obj-$(CONFIG_PWM_TIECAP) += pwm-tiecap.o
drivers/pwm/pwm-sirf.c new file +294 -0
294 lines not on this page · raw message
Signature · 1 line
1.7.5.4
PATCH v2 1/1 pwm: add CSR SiRFSoC PWM driver
drivers/pwm/Kconfig config PWM_SAMSUNG · line 172
Quoted 12 lines · Barry Song
drivers/pwm/Kconfig +4
-0@@ -166,6 +166,15 @@ config PWM_SAMSUNG To compile this driver as a module, choose M here: the module will be called pwm-samsung. +config PWM_SIRF + tristate "SiRF PWM support" + depends on ARCH_SIRF + help
please make this "depends on ARCH_SIRF || COMPILE_TEST" if you can, so we can build it on other platforms for test purposes. If you do this, you have to list the full set of dependencies, so probably another "depends on HAVE_CLK".
Quoted 10 lines
drivers/pwm/Kconfig +10
-0+ +#define to_sirf_chip(chip) container_of(chip, struct sirf_pwm, chip) + +static unsigned int sirf_pwm_ns_to_cycles(struct pwm_chip *chip, unsigned int time_ns) +{ + u64 dividend; + unsigned int cycle; + /* + * on SiRFSoC, OSC input is const, we use it as the source to generate + * PWM wave
drivers/pwm/Kconfig config PWM_SAMSUNG
Quoted 10 lines
drivers/pwm/Kconfig +10
-0+ */ +#define SRC_OSC_RATE 26000000ULL + dividend = SRC_OSC_RATE * time_ns + NSEC_PER_SEC / 2; + do_div(dividend, NSEC_PER_SEC); + + cycle = dividend & 0xFFFFFFFFUL; + + return cycle > 1 ? cycle : 1; +} +
Is SRC_OSC_RATE the rate of spwm->clk? If so, it would be nice to just call clk_get_rate() here, in case you ever have a chip with a different rate.
This is a very nice driver otherwise!
Arnd
PATCH v2 1/1 pwm: add CSR SiRFSoC PWM driver
2014-01-31 Arnd Bergmann <[email protected]>:
Quoted 9 lines · Barry Song
Quoted 8 lines
drivers/pwm/Kconfig +0
-0@@ -166,6 +166,15 @@ config PWM_SAMSUNG To compile this driver as a module, choose M here: the module will be called pwm-samsung.
Quoted 9 lines
drivers/pwm/Kconfig config PWM_SAMSUNG · line 172
Quoted 4 lines
drivers/pwm/Kconfig +4
-0+config PWM_SIRF + tristate "SiRF PWM support" + depends on ARCH_SIRF + helpplease make this "depends on
ARCH_SIRF||COMPILE_TEST" if you can, so we can build it on other platforms for test purposes. If you do this, you have to list the full set of dependencies, so probably another "depends onHAVE_CLK".
sounds good. it seems we can have this for other PWM drivers as well?
Quoted 16 lines
Quoted 16 lines
drivers/pwm/Kconfig +15
-0+ +#define to_sirf_chip(chip) container_of(chip, struct sirf_pwm, chip) + +static unsigned int sirf_pwm_ns_to_cycles(struct pwm_chip *chip, unsigned int time_ns) +{ + u64 dividend; + unsigned int cycle; + /* + * on SiRFSoC, OSC input is const, we use it as the source to generate + * PWM wave + */ +#define SRC_OSC_RATE 26000000ULL + dividend = SRC_OSC_RATE * time_ns + NSEC_PER_SEC / 2; + do_div(dividend, NSEC_PER_SEC); +
Quoted 9 lines
drivers/pwm/Kconfig
Quoted 5 lines
drivers/pwm/Kconfig +5
-0+ cycle = dividend & 0xFFFFFFFFUL; + + return cycle > 1 ? cycle : 1; +} +Is
SRC_OSC_RATEthe rate ofspwm->clk? If so, it would be nice to just callclk_get_rate()here, in case you ever have a chip with a different rate.
SRC_OSC_RATE is the fixed frequency of crystal oscillator, but spwm->clk comes from the IO bus. the design is a little strange, pwm channels don't use the clock of PWM controller to generate period/duty, but use other sources.
Quoted 3 lines
This is a very nice driver otherwise!
Arnd
-barry
PATCH v2 1/1 pwm: add CSR SiRFSoC PWM driver
Quoted 9 lines · Barry Song
Quoted 4 lines
Is
SRC_OSC_RATEthe rate ofspwm->clk? If so, it would be nice to just callclk_get_rate()here, in case you ever have a chip with a different rate.
SRC_OSC_RATEis the fixed frequency of crystal oscillator, butspwm->clkcomes from the IO bus. the design is a little strange, pwm channels don't use the clock of PWM controller to generate period/duty, but use other sources.
How about modeling that other source as a fixed-rate clock in DT then?
Arnd
PATCH v2 1/1 pwm: add CSR SiRFSoC PWM driver
2014-01-31 23:23 GMT+08:00 Arnd Bergmann <[email protected]>:
Quoted 6 lines · Barry Song
Quoted 5 lines
Quoted 4 lines
Is
SRC_OSC_RATEthe rate ofspwm->clk? If so, it would be nice to just callclk_get_rate()here, in case you ever have a chip with a different rate.
Quoted 7 lines
Quoted 4 lines
SRC_OSC_RATEis the fixed frequency of crystal oscillator, butspwm->clkcomes from the IO bus. the design is a little strange, pwm channels don't use the clock of PWM controller to generate period/duty, but use other sources.How about modeling that other source as a fixed-rate clock in DT then?
sirfsoc clock drivers have a clock node for OSC whose index is "1". do you think the following is the right way to handle?
in dts, put both pwm controller clock and OSC
672 pwm: pwm at b0130000 {
673 compatible = "sirf,prima2-pwm"; 674 #pwm-cells = <2>; 675 reg = <0xb0130000 0x10000>; 676 clocks = <&clks 21>, <&clks 1>; 677 clock-names = "pwmc", "osc";
678 };
and in pwm-sirf.c driver, use
clk = clk_get(dev, "osc");clk_get_rate(clk);
to get the rate in probe()?
Quoted 2 lines
Arnd
-barry
PATCH v2 1/1 pwm: add CSR SiRFSoC PWM driver
Quoted 13 lines · Barry Song
Quoted 2 lines
How about modeling that other source as a fixed-rate clock in DT then?
sirfsoc clock drivers have a clock node for OSC whose index is "1". do you think the following is the right way to handle?
in dts, put both pwm controller clock and OSC
672 pwm: pwm atb0130000{673 compatible = "sirf,prima2-pwm"; 674 #pwm-cells = <2>; 675 reg = <0xb0130000 0x10000>; 676 clocks = <&clks 21>, <&clks 1>; 677 clock-names = "pwmc", "osc";
Quoted 7 lines
678 };
and in
pwm-sirf.cdriver, use
clk =clk_get(dev, "osc");clk_get_rate(clk);to get the rate in
probe()?
Ah, if that's the right clock, it sounds great, yes.
Just make sure that the clock-names values make sense from the point of view of the pwm node, rather than referring to the name given in the clock provider.
Arnd
PATCH v2 1/1 pwm: add CSR SiRFSoC PWM driver
2014-02-06 23:27 GMT+08:00 Arnd Bergmann <[email protected]>:
Quoted 20 lines · Barry Song
Quoted 19 lines
Quoted 2 lines
How about modeling that other source as a fixed-rate clock in DT then?
sirfsoc clock drivers have a clock node for OSC whose index is "1". do you think the following is the right way to handle?
in dts, put both pwm controller clock and OSC
672 pwm: pwm atb0130000{673 compatible = "sirf,prima2-pwm"; 674 #pwm-cells = <2>; 675 reg = <0xb0130000 0x10000>; 676 clocks = <&clks 21>, <&clks 1>; 677 clock-names = "pwmc", "osc";678 };
and in
pwm-sirf.cdriver, use
clk =clk_get(dev, "osc");clk_get_rate(clk);
Quoted 7 lines
Quoted 1 line
to get the rate in
probe()?Ah, if that's the right clock, it sounds great, yes.
Just make sure that the clock-names values make sense from the point of view of the pwm node, rather than referring to the name given in the clock provider.
from the point of clock provider, it is "osc", from the view of pwm, it is the clock source of PWM waves.
so i guess "clk_pwm_source" is preferred?
Quoted 2 lines
Arnd
-barry