pwm: imx: Remove enabled field from struct imx_chip
Subsystems (2)
PATCH 1/3 pwm: imx: Remove enabled field from struct imx_chip
We can test PWMF_ENABLED bit to know if pwm is enabled or not. Thus remove enabled field from struct imx_chip.
--- drivers/pwm/pwm-imx.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/pwm/pwm-imx.c +1 -5
@@ -43,7 +43,6 @@ struct imx_chip {struct clk *clk_per;struct clk *clk_ipg; -int enabled;void __iomem *mmio_base;struct pwm_chip chip;
@@ -135,7 +134,7 @@ static int imx_pwm_config_v2(struct pwm_chip *chip,MX3_PWMCR_DOZEEN |MX3_PWMCR_WAITEN |MX3_PWMCR_DBGEN |MX3_PWMCR_CLKSRC_IPG_HIGH ; -if (imx->enabled) +if (test_bit (PWMF_ENABLED , &pwm->flags)) cr |=MX3_PWMCR_EN ;writel (cr, imx->mmio_base +MX3_PWMCR );
@@ -186,8 +185,6 @@ static int imx_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm) imx->set_enable (chip, true); - imx->enabled =1 ; -return 0 ; }
@@ -198,7 +195,6 @@ static void imx_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm) imx->set_enable (chip, false);clk_disable_unprepare (imx->clk_per); - imx->enabled =0 ; }static struct pwm_ops imx_pwm_ops = {
Signature · 1 line
1.7.10.4
PATCH 2/3 pwm: puv3: Remove unused enabled filed from struct puv3_pwm_chip
--- drivers/pwm/pwm-puv3.c | 1 - 1 file changed, 1 deletion(-)
drivers/pwm/pwm-puv3.c +0 -1
@@ -27,7 +27,6 @@ struct puv3_pwm_chip {struct pwm_chip chip;void __iomem *base;struct clk *clk; -bool enabled; };static inline struct puv3_pwm_chip *to_puv3 (struct pwm_chip *chip)
Signature · 1 line
1.7.10.4
PATCH 3/3 pwm: pxa: Remove clk_enabled field from struct pxa_pwm_chip
In reply to Axel Linclk_enable/clk_disable maintain an enable_count, clk_prepare and clk_unprepare also maintain a prepare_count. These APIs will do prepare/enable when the first user calling these APIs, and do disable/unprepare when the corresponding counter reach 0. Thus We don't need to maintain a clk_enabled counter here.
--- drivers/pwm/pwm-pxa.c | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-)
drivers/pwm/pwm-pxa.c +2 -14
@@ -48,7 +48,6 @@ struct pxa_pwm_chip {struct device *dev;struct clk *clk; -int clk_enabled;void __iomem *mmio_base; };
@@ -108,24 +107,15 @@ static int pxa_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,static int pxa_pwm_enable (struct pwm_chip *chip,struct pwm_device *pwm) {struct pxa_pwm_chip *pc =to_pxa_pwm_chip (chip); -int rc =0 ; -if (!pc->clk_enabled) { - rc =clk_prepare_enable (pc->clk); -if (!rc) - pc->clk_enabled++; - } -return rc; +return clk_prepare_enable (pc->clk); }static void pxa_pwm_disable (struct pwm_chip *chip,struct pwm_device *pwm) {struct pxa_pwm_chip *pc =to_pxa_pwm_chip (chip); -if (pc->clk_enabled) { -clk_disable_unprepare (pc->clk); - pc->clk_enabled--; - } +clk_disable_unprepare (pc->clk); }static struct pwm_ops pxa_pwm_ops = {
@@ -152,8 +142,6 @@ static int pwm_probe(struct platform_device *pdev)if (IS_ERR (pwm->clk))return PTR_ERR (pwm->clk); - pwm->clk_enabled =0 ; - pwm->chip.dev = &pdev->dev; pwm->chip.ops = &pxa_pwm_ops; pwm->chip.base =-1 ;
Signature · 1 line
1.7.10.4
Re: [PATCH 3/3] pwm: pxa: Remove clk_enabled field from struct pxa_pwm_chip
Quoted 4 lines · Axel Lin
clk_enable/clk_disable maintain an
enable_count,clk_prepareandclk_unpreparealso maintain aprepare_count. These APIs will do prepare/enable when the first user calling these APIs, and do disable/unprepare when the corresponding counter reach 0. Thus We don't need to maintain aclk_enabledcounter here.
The original intention is to keep a paired clk enable counter no matter how the user calls pwm_enable()/pwm_disable() in pair or not, if that's no longer the case.
Quoted 59 lines
Signed-off-by Axel Lin <[email protected]>--- drivers/pwm/pwm-pxa.c | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-)drivers/pwm/pwm-pxa.c +2
-15@@ -48,7 +48,6 @@ struct pxa_pwm_chip {struct device *dev;struct clk *clk; -int clk_enabled;void __iomem *mmio_base; };@@ -108,24 +107,15 @@ static int pxa_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,static int pxa_pwm_enable (struct pwm_chip *chip,struct pwm_device *pwm) {struct pxa_pwm_chip *pc =to_pxa_pwm_chip (chip); -int rc =0 ; -if (!pc->clk_enabled) { - rc =clk_prepare_enable (pc->clk); -if (!rc) - pc->clk_enabled++; - } -return rc; +return clk_prepare_enable (pc->clk); }static void pxa_pwm_disable (struct pwm_chip *chip,struct pwm_device *pwm) {struct pxa_pwm_chip *pc =to_pxa_pwm_chip (chip); -if (pc->clk_enabled) { -clk_disable_unprepare (pc->clk); - pc->clk_enabled--; - } +clk_disable_unprepare (pc->clk); }static struct pwm_ops pxa_pwm_ops = {@@ -152,8 +142,6 @@ static int pwm_probe(struct platform_device *pdev)if (IS_ERR (pwm->clk))return PTR_ERR (pwm->clk); - pwm->clk_enabled =0 ; - pwm->chip.dev = &pdev->dev; pwm->chip.ops = &pxa_pwm_ops; pwm->chip.base =-1 ; --1.7.10.4
Re: [PATCH 3/3] pwm: pxa: Remove clk_enabled field from struct pxa_pwm_chip
2013/4/1 Eric Miao <[email protected]>:
Quoted 9 lines · Axel Lin
Quoted 4 lines
clk_enable/clk_disable maintain an
enable_count,clk_prepareandclk_unpreparealso maintain aprepare_count. These APIs will do prepare/enable when the first user calling these APIs, and do disable/unprepare when the corresponding counter reach 0. Thus We don't need to maintain aclk_enabledcounter here.The original intention is to keep a paired clk enable counter no matter how the user calls pwm_enable()/pwm_disable() in pair or not, if that's no longer the case.
We don't need to worry that case:
In pwm core, both pwm_enable() and pwm_disable() will always check PWMF_ENABLED flag.
/**
* pwm_enable() - start a PWM output toggling
* @pwm: PWM device
*/
int pwm_enable(struct pwm_device *pwm)
{
if (pwm && !test_and_set_bit(PWMF_ENABLED, &pwm->flags))
return pwm->chip->ops->enable(pwm->chip, pwm);
return pwm ? 0 : -EINVAL;
}EXPORT_SYMBOL_GPL(pwm_enable);
/**
* pwm_disable() - stop a PWM output toggling
* @pwm: PWM device
*/
void pwm_disable(struct pwm_device *pwm)
{
if (pwm && test_and_clear_bit(PWMF_ENABLED, &pwm->flags))
pwm->chip->ops->disable(pwm->chip, pwm);
}EXPORT_SYMBOL_GPL(pwm_disable);
Eric Miao
Acked-byRe: [PATCH 3/3] pwm: pxa: Remove clk_enabled field from struct pxa_pwm_chip
Quoted 7 lines · Axel Lin
2013/4/1 Eric Miao <[email protected]>:
Quoted 6 lines · Axel Lin
Quoted 4 lines
clk_enable/clk_disable maintain an
enable_count,clk_prepareandclk_unpreparealso maintain aprepare_count. These APIs will do prepare/enable when the first user calling these APIs, and do disable/unprepare when the corresponding counter reach 0. Thus We don't need to maintain aclk_enabledcounter here.
Quoted 7 lines
Quoted 3 lines
The original intention is to keep a paired clk enable counter no matter how the user calls pwm_enable()/pwm_disable() in pair or not, if that's no longer the case.
We don't need to worry that case:
In pwm core, bothpwm_enable()andpwm_disable()will always checkPWMF_ENABLEDflag.
That's good then, this part of the code was dated before the pwm core, looks like this has been carefully handled. Have my ack on this one then:
Quoted 25 lines
/**
*pwm_enable()- start a PWM output toggling
* @pwm: PWM device
*/
intpwm_enable(struct pwm_device *pwm){ if (pwm && !test_and_set_bit(PWMF_ENABLED, &pwm->flags)) return pwm->chip->ops->enable(pwm->chip, pwm); return pwm ? 0 : -EINVAL; }
EXPORT_SYMBOL_GPL(pwm_enable);/**
*pwm_disable()- stop a PWM output toggling
* @pwm: PWM device
*/
voidpwm_disable(struct pwm_device *pwm){ if (pwm && test_and_clear_bit(PWMF_ENABLED, &pwm->flags)) pwm->chip->ops->disable(pwm->chip, pwm); }
EXPORT_SYMBOL_GPL(pwm_disable);
Quoted 4 lines · Axel Lin
We can test
PWMF_ENABLEDbit to know if pwm is enabled or not. Thus remove enabled field from structimx_chip.Signed-off-by Axel Lin <[email protected]>
Looks good.
Sascha
Quoted 48 lines
--- drivers/pwm/pwm-imx.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)drivers/pwm/pwm-imx.c +1
-5@@ -43,7 +43,6 @@ struct imx_chip {struct clk *clk_per;struct clk *clk_ipg; -int enabled;void __iomem *mmio_base;struct pwm_chip chip;@@ -135,7 +134,7 @@ static int imx_pwm_config_v2(struct pwm_chip *chip,MX3_PWMCR_DOZEEN |MX3_PWMCR_WAITEN |MX3_PWMCR_DBGEN |MX3_PWMCR_CLKSRC_IPG_HIGH ; -if (imx->enabled) +if (test_bit (PWMF_ENABLED , &pwm->flags)) cr |=MX3_PWMCR_EN ;writel (cr, imx->mmio_base +MX3_PWMCR );@@ -186,8 +185,6 @@ static int imx_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm) imx->set_enable (chip, true); - imx->enabled =1 ; -return 0 ; }@@ -198,7 +195,6 @@ static void imx_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm) imx->set_enable (chip, false);clk_disable_unprepare (imx->clk_per); - imx->enabled =0 ; }static struct pwm_ops imx_pwm_ops = {Signature · 1 line
1.7.10.4
Signature · 4 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
Quoted 7 lines · Axel Lin
We can test
PWMF_ENABLEDbit to know if pwm is enabled or not. Thus remove enabled field from structimx_chip.Signed-off-by Axel Lin <[email protected]>--- drivers/pwm/pwm-imx.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
All 3 patches applied, thanks.
Thierry