pwm: add ep93xx PWM support
Subsystems (2)
PATCH 1/1 pwm: add ep93xx PWM support
Remove the non-standard EP93xx pwm driver in drivers/misc and add a new driver for the PWM chips on the EP93xx platforms based on the PWM framework.
These PWM chips each support 1 PWM channel with programmable duty cycle, frequency, and polarity inversion.
--- drivers/misc/Kconfig | 13 --- drivers/misc/Makefile | 1 - drivers/misc/ep93xx_pwm.c | 286 ---------------------------------------------- drivers/pwm/Kconfig | 9 ++ drivers/pwm/Makefile | 1 + drivers/pwm/pwm-ep93xx.c | 218 +++++++++++++++++++++++++++++++++++ 6 files changed, 228 insertions(+), 300 deletions(-) delete mode 100644 drivers/misc/ep93xx_pwm.c create mode 100644 drivers/pwm/pwm-ep93xx.c
drivers/misc/Kconfig +0 -13
@@ -381,19 +381,6 @@ config HMC6352 This driver provides support for the Honeywell HMC6352 compass, providing configuration and heading data via sysfs. -config EP93XX_PWM - tristate "EP93xx PWM support" - depends on ARCH_EP93XX - help - This option enables device driver support for the PWM channels - on the Cirrus EP93xx processors. The EP9307 chip only has one - PWM channel all the others have two, the second channel is an - alternate function of the EGPIO14 pin. A sysfs interface is - provided to control the PWM channels. - - To compile this driver as a module, choose M here: the module will - be called ep93xx_pwm. - config DS1682 tristate "Dallas DS1682 Total Elapsed Time Recorder with Alarm" depends on I2C
drivers/misc/Makefile +0 -1
@@ -33,7 +33,6 @@ obj-$(CONFIG_APDS9802ALS) += apds9802als.o obj-$(CONFIG_ISL29003) += isl29003.o obj-$(CONFIG_ISL29020) += isl29020.o obj-$(CONFIG_SENSORS_TSL2550) += tsl2550.o -obj-$(CONFIG_EP93XX_PWM) += ep93xx_pwm.o obj-$(CONFIG_DS1682) += ds1682.o obj-$(CONFIG_TI_DAC7512) += ti_dac7512.o obj-$(CONFIG_C2PORT) += c2port/
drivers/misc/ep93xx_pwm.c deleted +0 -286
286 lines not on this page · raw message
drivers/pwm/Kconfig +9 -0
@@ -62,6 +62,15 @@ config PWM_BFIN To compile this driver as a module, choose M here: the module will be called pwm-bfin. +config PWM_EP93XX + tristate "Cirrus Logic EP93xx PWM support" + depends on ARCH_EP93XX + help + Generic PWM framework driver for Cirrus Logic EP93xx. + + To compile this driver as a module, choose M here: the module + will be called pwm-ep93xx. + config PWM_IMX tristate "i.MX PWM support" depends on ARCH_MXC
drivers/pwm/Makefile +1 -0
@@ -3,6 +3,7 @@ obj-$(CONFIG_PWM_SYSFS) += sysfs.o obj-$(CONFIG_PWM_AB8500) += pwm-ab8500.o obj-$(CONFIG_PWM_ATMEL_TCB) += pwm-atmel-tcb.o obj-$(CONFIG_PWM_BFIN) += pwm-bfin.o +obj-$(CONFIG_PWM_EP93XX) += pwm-ep93xx.o obj-$(CONFIG_PWM_IMX) += pwm-imx.o obj-$(CONFIG_PWM_JZ4740) += pwm-jz4740.o obj-$(CONFIG_PWM_LPC32XX) += pwm-lpc32xx.o
drivers/pwm/pwm-ep93xx.c new file +218 -0
218 lines not on this page · raw message
Signature · 1 line
1.8.3.2
Quoted 1 line · H Hartley Sweeten
Remove the non-standard EP93xx pwm driver in
drivers/miscand add
pwm -> PWM
Quoted 4 lines
a new driver for the PWM chips on the EP93xx platforms based on the PWM framework.
These PWM chips each support 1 PWM channel with programmable duty
Perhaps "chips" -> "controllers"?
Quoted 9 lines
cycle, frequency, and polarity inversion.
Signed-off-by H Hartley Sweeten <[email protected]>Cc Ryan Mallon <[email protected]>Cc Thierry Reding <[email protected]>Cc Arnd Bergmann <[email protected]>Cc Greg Kroah-Hartman <[email protected]>drivers/misc/ep93xx_pwm.c +0
-0
[...]
Quoted 2 lines
- * (c) Copyright 2009 Matthieu Crapet <[email protected]>
- * (c) Copyright 2009 H Hartley Sweeten <[email protected]>
[...]
Quoted 2 lines
drivers/misc/ep93xx_pwm.c +0
-2-MODULE_AUTHOR ("Matthieu Crapet <[email protected]>, " -"H Hartley Sweeten <[email protected]>" );
[...]
Quoted 1 line
drivers/pwm/pwm-ep93xx.c +0
-0
[...]
Quoted 1 line
+ * Copyright (C) 2013 H Hartley Sweeten <[email protected]>
[...]
Quoted 1 line
+MODULE_AUTHOR("H Hartley Sweeten <[email protected]>");
Why are you removing Matthieu from the list of authors and copyright here? From a brief look it seems like this new driver is still based on code from the old driver and not a complete rewrite.
Quoted 1 line
+#include <
mach/platform.h> /* for ep93xx_pwm_{acquire,release}_gpio() */
I'm not sure how well that will play together with multiplatform support but perhaps that's not an issue for ep93xx?
drivers/pwm/pwm-ep93xx.c line 67
Quoted 13 lines
drivers/pwm/pwm-ep93xx.c +13
-0+static int ep93xx_pwm_request (struct pwm_chip *chip,struct pwm_device *pwm) +{ +struct platform_device *pdev =to_platform_device (chip->dev); + +return ep93xx_pwm_acquire_gpio (pdev); +} + +static void ep93xx_pwm_free (struct pwm_chip *chip,struct pwm_device *pwm) +{ +struct platform_device *pdev =to_platform_device (chip->dev); + +ep93xx_pwm_release_gpio (pdev); +}
This looks like it would belong in the domain of pinctrl, but I suspect that ep93xx doesn't support that.
Quoted 7 lines
drivers/pwm/pwm-ep93xx.c +7
-0+static int ep93xx_pwm_config (struct pwm_chip *chip,struct pwm_device *pwm, +int duty_ns,int period_ns) +{ +struct ep93xx_pwm *ep93xx_pwm =to_ep93xx_pwm (chip); +void __iomem *base = ep93xx_pwm->base; +unsigned long long c; +unsigned long period_cycles;
drivers/pwm/pwm-ep93xx.c line 85
Quoted 10 lines
drivers/pwm/pwm-ep93xx.c +10
-0+unsigned long duty_cycles; +unsigned long term; +int ret =0 ; + +/* +* The clock needs to be enabled to access the PWM registers. +* Configuration can be changed at any time. +*/ +if (!test_bit (PWMF_ENABLED , &pwm->flags)) +clk_enable (ep93xx_pwm->clk);
clk_enable() can fail, so you should check the return value and propagate errors.
drivers/pwm/pwm-ep93xx.c line 126
Quoted 9 lines
drivers/pwm/pwm-ep93xx.c +9
-0+static int ep93xx_pwm_polarity (struct pwm_chip *chip,struct pwm_device *pwm, +enum pwm_polarity polarity) +{ +struct ep93xx_pwm *ep93xx_pwm =to_ep93xx_pwm (chip); + +/* +* The clock needs to be enabled to access the PWM registers. +* Polarity can only be changed when the PWM is disabled. +*/
Nit: the closing */ is wrongly aligned.
drivers/pwm/pwm-ep93xx.c
Quoted 1 line
drivers/pwm/pwm-ep93xx.c +1
-0+clk_enable (ep93xx_pwm->clk);
Needs a check of the return value.
drivers/pwm/pwm-ep93xx.c line 128
Quoted 1 line
drivers/pwm/pwm-ep93xx.c +1
-0+writew (polarity, ep93xx_pwm->base + EP93XX_PWMx_INVERT);
I'd prefer if this did some explicit conversion from the PWM framework value to the driver-specific value, even if they happen to be the same in this case.
drivers/pwm/pwm-ep93xx.c line 138
Quoted 5 lines
drivers/pwm/pwm-ep93xx.c +5
-0+static int ep93xx_pwm_enable (struct pwm_chip *chip,struct pwm_device *pwm) +{ +struct ep93xx_pwm *ep93xx_pwm =to_ep93xx_pwm (chip); + +clk_enable (ep93xx_pwm->clk);
Also needs to check the return value.
Quoted 1 line
+static struct
pwm_opsep93xx_pwm_ops= {
static const, please.
drivers/pwm/pwm-ep93xx.c line 200
Quoted 7 lines
drivers/pwm/pwm-ep93xx.c +7
-0+static int ep93xx_pwm_remove (struct platform_device *pdev) +{ +struct ep93xx_pwm *ep93xx_pwm; + + ep93xx_pwm =platform_get_drvdata (pdev); +if (!ep93xx_pwm) +return -ENODEV ;
No need for this check. It will never happen.
drivers/pwm/pwm-ep93xx.c line 208
Quoted 8 lines
drivers/pwm/pwm-ep93xx.c +8
-0+ +return pwmchip_remove (&ep93xx_pwm->chip); +} + +static struct platform_driver ep93xx_pwm_driver = { + .driver = { + .name ="ep93xx-pwm" , + .owner =THIS_MODULE ,
This is no longer required because the core sets it to the proper value.
drivers/pwm/pwm-ep93xx.c line 212
Quoted 4 lines
drivers/pwm/pwm-ep93xx.c +4
-0+ }, + .probe = ep93xx_pwm_probe, + .remove = ep93xx_pwm_remove, +};
Oh, and I didn't mention it before, but please get rid of all the needless tabs for alignment. It's completely useless and doesn't help with readability at all in my opinion.
Thierry
Quoted 4 lines · Thierry Reding
Quoted 1 line · H Hartley Sweeten
Remove the non-standard EP93xx pwm driver in
drivers/miscand addpwm -> PWM
OK
Quoted 6 lines
Quoted 4 lines
a new driver for the PWM chips on the EP93xx platforms based on the PWM framework.
These PWM chips each support 1 PWM channel with programmable duty
Perhaps "chips" -> "controllers"?
OK
Quoted 19 lines
Quoted 9 lines
cycle, frequency, and polarity inversion.
Signed-off-by H Hartley Sweeten <[email protected]>Cc Ryan Mallon <[email protected]>Cc Thierry Reding <[email protected]>Cc Arnd Bergmann <[email protected]>Cc Greg Kroah-Hartman <[email protected]>drivers/misc/ep93xx_pwm.c +0
-0[...]
Quoted 2 lines
- * (c) Copyright 2009 Matthieu Crapet <[email protected]>
- * (c) Copyright 2009 H Hartley Sweeten <[email protected]>[...]
Quoted 2 lines
drivers/misc/ep93xx_pwm.c +0
-2-MODULE_AUTHOR ("Matthieu Crapet <[email protected]>, " -"H Hartley Sweeten <[email protected]>" );[...]
Quoted 1 line
drivers/pwm/pwm-ep93xx.c +0
-0[...]
Quoted 7 lines
Quoted 1 line
+ * Copyright (C) 2013 H Hartley Sweeten <[email protected]>
[...]
Quoted 1 line
+MODULE_AUTHOR("H Hartley Sweeten <[email protected]>");
Why are you removing Matthieu from the list of authors and copyright here? From a brief look it seems like this new driver is still based on code from the old driver and not a complete rewrite.
My bad. It is based on the misc driver but I forgot to put Matthieu in as one of the original authors when I wrote it.
I'll fix that.
Quoted 4 lines
Quoted 1 line
+#include <
mach/platform.h> /* for ep93xx_pwm_{acquire,release}_gpio() */I'm not sure how well that will play together with multiplatform support but perhaps that's not an issue for ep93xx?
For multiplatform it would probably be a problem. But I don't think anyone would be including ep93xx in a multiplatform kernel. If the problem comes up I'll figure out some way to deal with it, probably with a pinctrl driver.
Quoted 8 lines
Quoted 8 lines
drivers/pwm/pwm-ep93xx.c +8
-0+static int ep93xx_pwm_request (struct pwm_chip *chip,struct pwm_device *pwm) +{ +struct platform_device *pdev =to_platform_device (chip->dev); + +return ep93xx_pwm_acquire_gpio (pdev); +} + +static void ep93xx_pwm_free (struct pwm_chip *chip,struct pwm_device *pwm)
Quoted 8 lines
drivers/pwm/pwm-ep93xx.c line 67
Quoted 5 lines
drivers/pwm/pwm-ep93xx.c +5
-0+{ +struct platform_device *pdev =to_platform_device (chip->dev); + +ep93xx_pwm_release_gpio (pdev); +}This looks like it would belong in the domain of pinctrl, but I suspect that ep93xx doesn't support that.
It should be but I have not worked out how to support EP93xx GPIOs with a pinctrl driver yet. The GPIOs are pretty limited on this platform compared to the other pinctrl users.
Quoted 12 lines
Quoted 12 lines
drivers/pwm/pwm-ep93xx.c +12
-0+static int ep93xx_pwm_config (struct pwm_chip *chip,struct pwm_device *pwm, +int duty_ns,int period_ns) +{ +struct ep93xx_pwm *ep93xx_pwm =to_ep93xx_pwm (chip); +void __iomem *base = ep93xx_pwm->base; +unsigned long long c; +unsigned long period_cycles; +unsigned long duty_cycles; +unsigned long term; +int ret =0 ; + +/*
Quoted 8 lines
drivers/pwm/pwm-ep93xx.c line 85
Quoted 5 lines
drivers/pwm/pwm-ep93xx.c +5
-0+* The clock needs to be enabled to access the PWM registers. +* Configuration can be changed at any time. +*/ +if (!test_bit (PWMF_ENABLED , &pwm->flags)) +clk_enable (ep93xx_pwm->clk);
clk_enable()can fail, so you should check the return value and propagate errors.
I overlooked that. This will be fixed in the next version.
Quoted 11 lines
drivers/pwm/pwm-ep93xx.c line 126
Quoted 9 lines
drivers/pwm/pwm-ep93xx.c +9
-0+static int ep93xx_pwm_polarity (struct pwm_chip *chip,struct pwm_device *pwm, +enum pwm_polarity polarity) +{ +struct ep93xx_pwm *ep93xx_pwm =to_ep93xx_pwm (chip); + +/* +* The clock needs to be enabled to access the PWM registers. +* Polarity can only be changed when the PWM is disabled. +*/ Nit: the closing */ is wrongly aligned.
OK
Quoted 3 lines
drivers/pwm/pwm-ep93xx.c
Quoted 1 line
drivers/pwm/pwm-ep93xx.c +1
-0+clk_enable (ep93xx_pwm->clk);Needs a check of the return value.
OK
Quoted 5 lines
drivers/pwm/pwm-ep93xx.c line 128
Quoted 1 line
drivers/pwm/pwm-ep93xx.c +1
-0+writew (polarity, ep93xx_pwm->base + EP93XX_PWMx_INVERT);I'd prefer if this did some explicit conversion from the PWM framework value to the driver-specific value, even if they happen to be the same in this case.
OK
Quoted 7 lines
drivers/pwm/pwm-ep93xx.c line 138
Quoted 5 lines
drivers/pwm/pwm-ep93xx.c +5
-0+static int ep93xx_pwm_enable (struct pwm_chip *chip,struct pwm_device *pwm) +{ +struct ep93xx_pwm *ep93xx_pwm =to_ep93xx_pwm (chip); + +clk_enable (ep93xx_pwm->clk);Also needs to check the return value.
OK
Quoted 3 lines
Quoted 1 line
+static struct
pwm_opsep93xx_pwm_ops= {static const, please.
OK
Quoted 9 lines
drivers/pwm/pwm-ep93xx.c line 200
Quoted 7 lines
drivers/pwm/pwm-ep93xx.c +7
-0+static int ep93xx_pwm_remove (struct platform_device *pdev) +{ +struct ep93xx_pwm *ep93xx_pwm; + + ep93xx_pwm =platform_get_drvdata (pdev); +if (!ep93xx_pwm) +return -ENODEV ;No need for this check. It will never happen.
OK
Quoted 10 lines
drivers/pwm/pwm-ep93xx.c line 208
Quoted 8 lines
drivers/pwm/pwm-ep93xx.c +8
-0+ +return pwmchip_remove (&ep93xx_pwm->chip); +} + +static struct platform_driver ep93xx_pwm_driver = { + .driver = { + .name ="ep93xx-pwm" , + .owner =THIS_MODULE ,This is no longer required because the core sets it to the proper value.
OK
Quoted 8 lines
drivers/pwm/pwm-ep93xx.c line 212
Quoted 4 lines
drivers/pwm/pwm-ep93xx.c +4
-0+ }, + .probe = ep93xx_pwm_probe, + .remove = ep93xx_pwm_remove, +};Oh, and I didn't mention it before, but please get rid of all the needless tabs for alignment. It's completely useless and doesn't help with readability at all in my opinion.
Opinions differ.. But I'll remove the tabs.
Thanks for the review,
Hartley