Skip to contentSkip to conversation

pwm: imx: Remove enabled field from struct imx_chip

PATCH In review Axel Lin 4 participants 8 messages Mar 31, 2013 – Apr 2, 2013

Subsystems (2)
lore
Share & tools
lore

Axel Lin

author
#0 lore raw

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
index 3f5677b..ec28798 100644
@@ -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
author
#1 lore raw

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
index db964e6..d1eb499 100644
@@ -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
author
#2 lore raw

PATCH 3/3 pwm: pxa: Remove clk_enabled field from struct pxa_pwm_chip

In reply to Axel Lin

clk_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
index 20370e6..b789882 100644
@@ -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
#3 lore raw

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_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.

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
---
 drivers/pwm/pwm-pxa.c |   16 ++--------------
 1 file changed, 2 insertions(+), 14 deletions(-)
drivers/pwm/pwm-pxa.c +2 -15
index 20370e6..b789882 100644
@@ -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

author
#4 lore raw

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_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.

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);

Acked-by
#5 lore raw

Re: [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_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.

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, both pwm_enable() and pwm_disable() will always check PWMF_ENABLED flag.

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
*/
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);

maintainer Acked-by on v1 1/3
#6 lore raw
In reply to Axel Lin
Quoted 4 lines · Axel Lin

We can test PWMF_ENABLED bit to know if pwm is enabled or not. Thus remove enabled field from struct imx_chip.

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
index 3f5677b..ec28798 100644
@@ -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 |
#7 lore raw
In reply to Axel Lin
Quoted 7 lines · Axel Lin

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(-)

All 3 patches applied, thanks.

Thierry