Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1586745 > unrolled thread

[PATCH 2/2] drivers: pwm: pwm-atmel: add support to allow run time changing of pwm parameters

Started byClaudiu Beznea <claudiu.beznea@microchip.com>
First post2017-02-23 09:50 +0100
Last post2017-02-23 11:40 +0100
Articles 6 — 4 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH 2/2] drivers: pwm: pwm-atmel: add support to allow run time changing of pwm parameters Claudiu Beznea <claudiu.beznea@microchip.com> - 2017-02-23 09:50 +0100
    Re: [PATCH 2/2] drivers: pwm: pwm-atmel: add support to allow run  time changing of pwm parameters Alexandre Belloni <alexandre.belloni@free-electrons.com> - 2017-02-23 10:30 +0100
      Re: [PATCH 2/2] drivers: pwm: pwm-atmel: add support to allow run  time changing of pwm parameters m18063 <Claudiu.Beznea@microchip.com> - 2017-02-23 11:30 +0100
        Re: [PATCH 2/2] drivers: pwm: pwm-atmel: add support to allow run  time changing of pwm parameters Alexandre Belloni <alexandre.belloni@free-electrons.com> - 2017-02-23 11:40 +0100
          Re: [PATCH 2/2] drivers: pwm: pwm-atmel: add support to allow run  time changing of pwm parameters m18063 <Claudiu.Beznea@microchip.com> - 2017-02-23 16:30 +0100
        Re: [PATCH 2/2] drivers: pwm: pwm-atmel: add support to allow run  time changing of pwm parameters Boris Brezillon <boris.brezillon@free-electrons.com> - 2017-02-23 11:40 +0100

#1586745 — [PATCH 2/2] drivers: pwm: pwm-atmel: add support to allow run time changing of pwm parameters

FromClaudiu Beznea <claudiu.beznea@microchip.com>
Date2017-02-23 09:50 +0100
Subject[PATCH 2/2] drivers: pwm: pwm-atmel: add support to allow run time changing of pwm parameters
Message-ID<tdXg7-7i8-35@gated-at.bofh.it>
sama5d2 supports changing of pwm parameters like period and
duty factor without first to disable pwm. Since pwm code
is supported by more than one SoC add allow_runtime_cfg
parameter to atmel_pwm_chip data structure. This will be
filled statically for every SoC, saved in pwm specific
structure at probing time and checked while configuring
the device. Based on this, pwm clock will not be
enabled/disabled while configuring if it still enabled.

Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
---
 drivers/pwm/pwm-atmel.c | 24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)

diff --git a/drivers/pwm/pwm-atmel.c b/drivers/pwm/pwm-atmel.c
index 4406639..9e1dece 100644
--- a/drivers/pwm/pwm-atmel.c
+++ b/drivers/pwm/pwm-atmel.c
@@ -68,6 +68,8 @@ struct atmel_pwm_chip {
 
 	void (*config)(struct pwm_chip *chip, struct pwm_device *pwm,
 		       unsigned long dty, unsigned long prd);
+
+	bool allow_runtime_cfg;
 };
 
 static inline struct atmel_pwm_chip *to_atmel_pwm_chip(struct pwm_chip *chip)
@@ -114,7 +116,8 @@ static int atmel_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
 	u32 val;
 	int ret;
 
-	if (pwm_is_enabled(pwm) && (period_ns != pwm_get_period(pwm))) {
+	if (!atmel_pwm->allow_runtime_cfg &&
+	    pwm_is_enabled(pwm) && (period_ns != pwm_get_period(pwm))) {
 		dev_err(chip->dev, "cannot change PWM period while enabled\n");
 		return -EBUSY;
 	}
@@ -139,10 +142,12 @@ static int atmel_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
 	do_div(div, period_ns);
 	dty = prd - div;
 
-	ret = clk_enable(atmel_pwm->clk);
-	if (ret) {
-		dev_err(chip->dev, "failed to enable PWM clock\n");
-		return ret;
+	if (!pwm_is_enabled(pwm)) {
+		ret = clk_enable(atmel_pwm->clk);
+		if (ret) {
+			dev_err(chip->dev, "failed to enable PWM clock\n");
+			return ret;
+		}
 	}
 
 	/* It is necessary to preserve CPOL, inside CMR */
@@ -155,7 +160,9 @@ static int atmel_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
 	atmel_pwm->updated_pwms &= ~(1 << pwm->hwpwm);
 	mutex_unlock(&atmel_pwm->isr_lock);
 
-	clk_disable(atmel_pwm->clk);
+	if (!pwm_is_enabled(pwm))
+		clk_disable(atmel_pwm->clk);
+
 	return ret;
 }
 
@@ -294,18 +301,22 @@ static const struct pwm_ops atmel_pwm_ops = {
 struct atmel_pwm_data {
 	void (*config)(struct pwm_chip *chip, struct pwm_device *pwm,
 		       unsigned long dty, unsigned long prd);
+	bool allow_runtime_cfg;
 };
 
 static const struct atmel_pwm_data atmel_pwm_data_v1 = {
 	.config = atmel_pwm_config_v1,
+	.allow_runtime_cfg = false,
 };
 
 static const struct atmel_pwm_data atmel_pwm_data_v2 = {
 	.config = atmel_pwm_config_v2,
+	.allow_runtime_cfg = false,
 };
 
 static const struct atmel_pwm_data atmel_pwm_data_v3 = {
 	.config = atmel_pwm_config_v3,
+	.allow_runtime_cfg = true,
 };
 
 static const struct platform_device_id atmel_pwm_devtypes[] = {
@@ -399,6 +410,7 @@ static int atmel_pwm_probe(struct platform_device *pdev)
 	atmel_pwm->chip.npwm = 4;
 	atmel_pwm->chip.can_sleep = true;
 	atmel_pwm->config = data->config;
+	atmel_pwm->allow_runtime_cfg = data->allow_runtime_cfg;
 	atmel_pwm->updated_pwms = 0;
 	mutex_init(&atmel_pwm->isr_lock);
 
-- 
2.7.4

[toc] | [next] | [standalone]


#1586776 — Re: [PATCH 2/2] drivers: pwm: pwm-atmel: add support to allow run time changing of pwm parameters

FromAlexandre Belloni <alexandre.belloni@free-electrons.com>
Date2017-02-23 10:30 +0100
SubjectRe: [PATCH 2/2] drivers: pwm: pwm-atmel: add support to allow run time changing of pwm parameters
Message-ID<tdXSO-7Pd-15@gated-at.bofh.it>
In reply to#1586745
On 23/02/2017 at 10:38:40 +0200, Claudiu Beznea wrote:
> sama5d2 supports changing of pwm parameters like period and
> duty factor without first to disable pwm. Since pwm code
> is supported by more than one SoC add allow_runtime_cfg
> parameter to atmel_pwm_chip data structure. This will be
> filled statically for every SoC, saved in pwm specific
> structure at probing time and checked while configuring
> the device. Based on this, pwm clock will not be
> enabled/disabled while configuring if it still enabled.
> 
> Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
> ---
>  drivers/pwm/pwm-atmel.c | 24 ++++++++++++++++++------
>  1 file changed, 18 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/pwm/pwm-atmel.c b/drivers/pwm/pwm-atmel.c
> index 4406639..9e1dece 100644
> --- a/drivers/pwm/pwm-atmel.c
> +++ b/drivers/pwm/pwm-atmel.c
> @@ -68,6 +68,8 @@ struct atmel_pwm_chip {
>  
>  	void (*config)(struct pwm_chip *chip, struct pwm_device *pwm,
>  		       unsigned long dty, unsigned long prd);
> +
> +	bool allow_runtime_cfg;
>  };
>  
>  static inline struct atmel_pwm_chip *to_atmel_pwm_chip(struct pwm_chip *chip)
> @@ -114,7 +116,8 @@ static int atmel_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
>  	u32 val;
>  	int ret;
>  
> -	if (pwm_is_enabled(pwm) && (period_ns != pwm_get_period(pwm))) {
> +	if (!atmel_pwm->allow_runtime_cfg &&
> +	    pwm_is_enabled(pwm) && (period_ns != pwm_get_period(pwm))) {
>  		dev_err(chip->dev, "cannot change PWM period while enabled\n");
>  		return -EBUSY;
>  	}
> @@ -139,10 +142,12 @@ static int atmel_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
>  	do_div(div, period_ns);
>  	dty = prd - div;
>  
> -	ret = clk_enable(atmel_pwm->clk);
> -	if (ret) {
> -		dev_err(chip->dev, "failed to enable PWM clock\n");
> -		return ret;
> +	if (!pwm_is_enabled(pwm)) {
> +		ret = clk_enable(atmel_pwm->clk);
> +		if (ret) {
> +			dev_err(chip->dev, "failed to enable PWM clock\n");
> +			return ret;
> +		}
>  	}
>  

It is probably worth switching to atomic PWM instead of changing this
function. This would simplify the whole driver.

>  	/* It is necessary to preserve CPOL, inside CMR */
> @@ -155,7 +160,9 @@ static int atmel_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
>  	atmel_pwm->updated_pwms &= ~(1 << pwm->hwpwm);
>  	mutex_unlock(&atmel_pwm->isr_lock);
>  
> -	clk_disable(atmel_pwm->clk);
> +	if (!pwm_is_enabled(pwm))
> +		clk_disable(atmel_pwm->clk);
> +
>  	return ret;
>  }
>  
> @@ -294,18 +301,22 @@ static const struct pwm_ops atmel_pwm_ops = {
>  struct atmel_pwm_data {
>  	void (*config)(struct pwm_chip *chip, struct pwm_device *pwm,
>  		       unsigned long dty, unsigned long prd);
> +	bool allow_runtime_cfg;
>  };
>  
>  static const struct atmel_pwm_data atmel_pwm_data_v1 = {
>  	.config = atmel_pwm_config_v1,
> +	.allow_runtime_cfg = false,

This is useless as it is false even if not explicitly set.

>  };
>  
>  static const struct atmel_pwm_data atmel_pwm_data_v2 = {
>  	.config = atmel_pwm_config_v2,
> +	.allow_runtime_cfg = false,

ditto.

>  };
>  
>  static const struct atmel_pwm_data atmel_pwm_data_v3 = {
>  	.config = atmel_pwm_config_v3,
> +	.allow_runtime_cfg = true,
>  };
>  
>  static const struct platform_device_id atmel_pwm_devtypes[] = {
> @@ -399,6 +410,7 @@ static int atmel_pwm_probe(struct platform_device *pdev)
>  	atmel_pwm->chip.npwm = 4;
>  	atmel_pwm->chip.can_sleep = true;
>  	atmel_pwm->config = data->config;
> +	atmel_pwm->allow_runtime_cfg = data->allow_runtime_cfg;

It is probably worth having a pointer to the atmel_pwm_data instead of
having to copy all the members.

>  	atmel_pwm->updated_pwms = 0;
>  	mutex_init(&atmel_pwm->isr_lock);
>  
> -- 
> 2.7.4
> 

-- 
Alexandre Belloni, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com

[toc] | [prev] | [next] | [standalone]


#1586799 — Re: [PATCH 2/2] drivers: pwm: pwm-atmel: add support to allow run time changing of pwm parameters

Fromm18063 <Claudiu.Beznea@microchip.com>
Date2017-02-23 11:30 +0100
SubjectRe: [PATCH 2/2] drivers: pwm: pwm-atmel: add support to allow run time changing of pwm parameters
Message-ID<tdYOS-8mZ-19@gated-at.bofh.it>
In reply to#1586776
Hi,


On 23.02.2017 11:21, Alexandre Belloni wrote:
> On 23/02/2017 at 10:38:40 +0200, Claudiu Beznea wrote:
>> sama5d2 supports changing of pwm parameters like period and
>> duty factor without first to disable pwm. Since pwm code
>> is supported by more than one SoC add allow_runtime_cfg
>> parameter to atmel_pwm_chip data structure. This will be
>> filled statically for every SoC, saved in pwm specific
>> structure at probing time and checked while configuring
>> the device. Based on this, pwm clock will not be
>> enabled/disabled while configuring if it still enabled.
>>
>> Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
>> ---
>>  drivers/pwm/pwm-atmel.c | 24 ++++++++++++++++++------
>>  1 file changed, 18 insertions(+), 6 deletions(-)
>>
>> diff --git a/drivers/pwm/pwm-atmel.c b/drivers/pwm/pwm-atmel.c
>> index 4406639..9e1dece 100644
>> --- a/drivers/pwm/pwm-atmel.c
>> +++ b/drivers/pwm/pwm-atmel.c
>> @@ -68,6 +68,8 @@ struct atmel_pwm_chip {
>>  
>>  	void (*config)(struct pwm_chip *chip, struct pwm_device *pwm,
>>  		       unsigned long dty, unsigned long prd);
>> +
>> +	bool allow_runtime_cfg;
>>  };
>>  
>>  static inline struct atmel_pwm_chip *to_atmel_pwm_chip(struct pwm_chip *chip)
>> @@ -114,7 +116,8 @@ static int atmel_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
>>  	u32 val;
>>  	int ret;
>>  
>> -	if (pwm_is_enabled(pwm) && (period_ns != pwm_get_period(pwm))) {
>> +	if (!atmel_pwm->allow_runtime_cfg &&
>> +	    pwm_is_enabled(pwm) && (period_ns != pwm_get_period(pwm))) {
>>  		dev_err(chip->dev, "cannot change PWM period while enabled\n");
>>  		return -EBUSY;
>>  	}
>> @@ -139,10 +142,12 @@ static int atmel_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
>>  	do_div(div, period_ns);
>>  	dty = prd - div;
>>  
>> -	ret = clk_enable(atmel_pwm->clk);
>> -	if (ret) {
>> -		dev_err(chip->dev, "failed to enable PWM clock\n");
>> -		return ret;
>> +	if (!pwm_is_enabled(pwm)) {
>> +		ret = clk_enable(atmel_pwm->clk);
>> +		if (ret) {
>> +			dev_err(chip->dev, "failed to enable PWM clock\n");
>> +			return ret;
>> +		}
>>  	}
>>  
> It is probably worth switching to atomic PWM instead of changing this
> function. This would simplify the whole driver.
I was thinking to switch to atomic PWM in a future patch.
>
>>  	/* It is necessary to preserve CPOL, inside CMR */
>> @@ -155,7 +160,9 @@ static int atmel_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
>>  	atmel_pwm->updated_pwms &= ~(1 << pwm->hwpwm);
>>  	mutex_unlock(&atmel_pwm->isr_lock);
>>  
>> -	clk_disable(atmel_pwm->clk);
>> +	if (!pwm_is_enabled(pwm))
>> +		clk_disable(atmel_pwm->clk);
>> +
>>  	return ret;
>>  }
>>  
>> @@ -294,18 +301,22 @@ static const struct pwm_ops atmel_pwm_ops = {
>>  struct atmel_pwm_data {
>>  	void (*config)(struct pwm_chip *chip, struct pwm_device *pwm,
>>  		       unsigned long dty, unsigned long prd);
>> +	bool allow_runtime_cfg;
>>  };
>>  
>>  static const struct atmel_pwm_data atmel_pwm_data_v1 = {
>>  	.config = atmel_pwm_config_v1,
>> +	.allow_runtime_cfg = false,
> This is useless as it is false even if not explicitly set.
Ok. I will do it in v2.
>
>>  };
>>  
>>  static const struct atmel_pwm_data atmel_pwm_data_v2 = {
>>  	.config = atmel_pwm_config_v2,
>> +	.allow_runtime_cfg = false,
> ditto.
>
>>  };
>>  
>>  static const struct atmel_pwm_data atmel_pwm_data_v3 = {
>>  	.config = atmel_pwm_config_v3,
>> +	.allow_runtime_cfg = true,
>>  };
>>  
>>  static const struct platform_device_id atmel_pwm_devtypes[] = {
>> @@ -399,6 +410,7 @@ static int atmel_pwm_probe(struct platform_device *pdev)
>>  	atmel_pwm->chip.npwm = 4;
>>  	atmel_pwm->chip.can_sleep = true;
>>  	atmel_pwm->config = data->config;
>> +	atmel_pwm->allow_runtime_cfg = data->allow_runtime_cfg;
> It is probably worth having a pointer to the atmel_pwm_data instead of
> having to copy all the members.
Ok. I will do it in v2.
>
>>  	atmel_pwm->updated_pwms = 0;
>>  	mutex_init(&atmel_pwm->isr_lock);
>>  
>> -- 
>> 2.7.4
>>

Thank you,
Claudiu Beznea

[toc] | [prev] | [next] | [standalone]


#1586807 — Re: [PATCH 2/2] drivers: pwm: pwm-atmel: add support to allow run time changing of pwm parameters

FromAlexandre Belloni <alexandre.belloni@free-electrons.com>
Date2017-02-23 11:40 +0100
SubjectRe: [PATCH 2/2] drivers: pwm: pwm-atmel: add support to allow run time changing of pwm parameters
Message-ID<tdYYy-8q5-27@gated-at.bofh.it>
In reply to#1586799
On 23/02/2017 at 12:25:58 +0200, m18063 wrote:
> > It is probably worth switching to atomic PWM instead of changing this
> > function. This would simplify the whole driver.
> I was thinking to switch to atomic PWM in a future patch.

Then why wait ?


-- 
Alexandre Belloni, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com

[toc] | [prev] | [next] | [standalone]


#1586954 — Re: [PATCH 2/2] drivers: pwm: pwm-atmel: add support to allow run time changing of pwm parameters

Fromm18063 <Claudiu.Beznea@microchip.com>
Date2017-02-23 16:30 +0100
SubjectRe: [PATCH 2/2] drivers: pwm: pwm-atmel: add support to allow run time changing of pwm parameters
Message-ID<te3vb-35q-11@gated-at.bofh.it>
In reply to#1586807
On 23.02.2017 12:32, Alexandre Belloni wrote:
> On 23/02/2017 at 12:25:58 +0200, m18063 wrote:
>>> It is probably worth switching to atomic PWM instead of changing this
>>> function. This would simplify the whole driver.
>> I was thinking to switch to atomic PWM in a future patch.
> Then why wait ?
>
>
I wanted to do it in progressively:
- enable the support for SAMA5d2
- make it work based on what is currently implemented
- add atomic PWM support.

Anyway, please ignore this patch. I will do it in atomic
PWM way.

Thank you,
Claudiu

[toc] | [prev] | [next] | [standalone]


#1586808 — Re: [PATCH 2/2] drivers: pwm: pwm-atmel: add support to allow run time changing of pwm parameters

FromBoris Brezillon <boris.brezillon@free-electrons.com>
Date2017-02-23 11:40 +0100
SubjectRe: [PATCH 2/2] drivers: pwm: pwm-atmel: add support to allow run time changing of pwm parameters
Message-ID<tdYYz-8q5-31@gated-at.bofh.it>
In reply to#1586799
Hi Claudiu,

On Thu, 23 Feb 2017 12:25:58 +0200
m18063 <Claudiu.Beznea@microchip.com> wrote:

> Hi,
> 
> 
> On 23.02.2017 11:21, Alexandre Belloni wrote:
> > On 23/02/2017 at 10:38:40 +0200, Claudiu Beznea wrote:  
> >> sama5d2 supports changing of pwm parameters like period and
> >> duty factor without first to disable pwm. Since pwm code
> >> is supported by more than one SoC add allow_runtime_cfg
> >> parameter to atmel_pwm_chip data structure. This will be
> >> filled statically for every SoC, saved in pwm specific
> >> structure at probing time and checked while configuring
> >> the device. Based on this, pwm clock will not be
> >> enabled/disabled while configuring if it still enabled.
> >>
> >> Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
> >> ---
> >>  drivers/pwm/pwm-atmel.c | 24 ++++++++++++++++++------
> >>  1 file changed, 18 insertions(+), 6 deletions(-)
> >>
> >> diff --git a/drivers/pwm/pwm-atmel.c b/drivers/pwm/pwm-atmel.c
> >> index 4406639..9e1dece 100644
> >> --- a/drivers/pwm/pwm-atmel.c
> >> +++ b/drivers/pwm/pwm-atmel.c
> >> @@ -68,6 +68,8 @@ struct atmel_pwm_chip {
> >>  
> >>  	void (*config)(struct pwm_chip *chip, struct pwm_device *pwm,
> >>  		       unsigned long dty, unsigned long prd);
> >> +
> >> +	bool allow_runtime_cfg;
> >>  };
> >>  
> >>  static inline struct atmel_pwm_chip *to_atmel_pwm_chip(struct pwm_chip *chip)
> >> @@ -114,7 +116,8 @@ static int atmel_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
> >>  	u32 val;
> >>  	int ret;
> >>  
> >> -	if (pwm_is_enabled(pwm) && (period_ns != pwm_get_period(pwm))) {
> >> +	if (!atmel_pwm->allow_runtime_cfg &&
> >> +	    pwm_is_enabled(pwm) && (period_ns != pwm_get_period(pwm))) {
> >>  		dev_err(chip->dev, "cannot change PWM period while enabled\n");
> >>  		return -EBUSY;
> >>  	}
> >> @@ -139,10 +142,12 @@ static int atmel_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
> >>  	do_div(div, period_ns);
> >>  	dty = prd - div;
> >>  
> >> -	ret = clk_enable(atmel_pwm->clk);
> >> -	if (ret) {
> >> -		dev_err(chip->dev, "failed to enable PWM clock\n");
> >> -		return ret;
> >> +	if (!pwm_is_enabled(pwm)) {
> >> +		ret = clk_enable(atmel_pwm->clk);
> >> +		if (ret) {
> >> +			dev_err(chip->dev, "failed to enable PWM clock\n");
> >> +			return ret;
> >> +		}
> >>  	}
> >>    
> > It is probably worth switching to atomic PWM instead of changing this
> > function. This would simplify the whole driver.  
> I was thinking to switch to atomic PWM in a future patch.

Actually, I think it's better to do it before adding support for the
new IP (even before patch 1), but maybe I'm the only one to think
so :-).

Note that switching to the atomic API is not a big (actually, it should
even simplify the code).

Regards,

Boris

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web