linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] leds: leds-pwm: Convert to use devm_get_pwm
@ 2012-11-07 11:42 Peter Ujfalusi
  2012-11-10  1:48 ` Bryan Wu
  0 siblings, 1 reply; 3+ messages in thread
From: Peter Ujfalusi @ 2012-11-07 11:42 UTC (permalink / raw)
  To: Bryan Wu, Richard Purdie; +Cc: Luotao Fu, linux-leds, linux-kernel

Update the driver to use the new API for requesting pwm so we can take
advantage of the pwm_lookup table to find the correct pwm to be used for the
LED functionality.
If the devm_get_pwm fails we fall back to legacy mode to try to get the pwm.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
---
 drivers/leds/leds-pwm.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/drivers/leds/leds-pwm.c b/drivers/leds/leds-pwm.c
index f2e44c7..6bf9445 100644
--- a/drivers/leds/leds-pwm.c
+++ b/drivers/leds/leds-pwm.c
@@ -47,6 +47,19 @@ static void led_pwm_set(struct led_classdev *led_cdev,
 	}
 }
 
+static struct pwm_device *led_pwm_request_pwm(struct platform_device *pdev,
+					      struct led_pwm *cur_led)
+{
+	struct pwm_device *pwm;
+
+	pwm = devm_pwm_get(&pdev->dev, cur_led->name);
+	if (IS_ERR(pwm)) {
+		dev_err(&pdev->dev, "unable to request PWM, trying legacy API\n");
+		pwm = pwm_request(cur_led->pwm_id, cur_led->name);
+	}
+	return pwm;
+}
+
 static int led_pwm_probe(struct platform_device *pdev)
 {
 	struct led_pwm_platform_data *pdata = pdev->dev.platform_data;
@@ -67,8 +80,7 @@ static int led_pwm_probe(struct platform_device *pdev)
 		cur_led = &pdata->leds[i];
 		led_dat = &leds_data[i];
 
-		led_dat->pwm = pwm_request(cur_led->pwm_id,
-				cur_led->name);
+		led_dat->pwm = led_pwm_request_pwm(pdev, cur_led);
 		if (IS_ERR(led_dat->pwm)) {
 			ret = PTR_ERR(led_dat->pwm);
 			dev_err(&pdev->dev, "unable to request PWM %d\n",
-- 
1.8.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] leds: leds-pwm: Convert to use devm_get_pwm
  2012-11-07 11:42 [PATCH] leds: leds-pwm: Convert to use devm_get_pwm Peter Ujfalusi
@ 2012-11-10  1:48 ` Bryan Wu
  2012-11-12  8:40   ` Péter Ujfalusi
  0 siblings, 1 reply; 3+ messages in thread
From: Bryan Wu @ 2012-11-10  1:48 UTC (permalink / raw)
  To: Peter Ujfalusi; +Cc: Richard Purdie, Luotao Fu, linux-leds, linux-kernel

On Wed, Nov 7, 2012 at 3:42 AM, Peter Ujfalusi <peter.ujfalusi@ti.com> wrote:
> Update the driver to use the new API for requesting pwm so we can take
> advantage of the pwm_lookup table to find the correct pwm to be used for the
> LED functionality.
> If the devm_get_pwm fails we fall back to legacy mode to try to get the pwm.
>
> Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
> ---
>  drivers/leds/leds-pwm.c | 16 ++++++++++++++--
>  1 file changed, 14 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/leds/leds-pwm.c b/drivers/leds/leds-pwm.c
> index f2e44c7..6bf9445 100644
> --- a/drivers/leds/leds-pwm.c
> +++ b/drivers/leds/leds-pwm.c
> @@ -47,6 +47,19 @@ static void led_pwm_set(struct led_classdev *led_cdev,
>         }
>  }
>
> +static struct pwm_device *led_pwm_request_pwm(struct platform_device *pdev,
> +                                             struct led_pwm *cur_led)
> +{
> +       struct pwm_device *pwm;
> +
> +       pwm = devm_pwm_get(&pdev->dev, cur_led->name);
> +       if (IS_ERR(pwm)) {
> +               dev_err(&pdev->dev, "unable to request PWM, trying legacy API\n");
> +               pwm = pwm_request(cur_led->pwm_id, cur_led->name);

Looks good, but why we still need to keep the old API pwm_request(),
if devm_pwm_get() is the right replacement. AFAIK, devm_***() API will
help to clean up if device probing fails.

So if it is good enough, we can just replace pwm_request() to the devm_pwm_get()

Thanks,
-Bryan

> +       }
> +       return pwm;
> +}
> +
>  static int led_pwm_probe(struct platform_device *pdev)
>  {
>         struct led_pwm_platform_data *pdata = pdev->dev.platform_data;
> @@ -67,8 +80,7 @@ static int led_pwm_probe(struct platform_device *pdev)
>                 cur_led = &pdata->leds[i];
>                 led_dat = &leds_data[i];
>
> -               led_dat->pwm = pwm_request(cur_led->pwm_id,
> -                               cur_led->name);
> +               led_dat->pwm = led_pwm_request_pwm(pdev, cur_led);
>                 if (IS_ERR(led_dat->pwm)) {
>                         ret = PTR_ERR(led_dat->pwm);
>                         dev_err(&pdev->dev, "unable to request PWM %d\n",
> --
> 1.8.0
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] leds: leds-pwm: Convert to use devm_get_pwm
  2012-11-10  1:48 ` Bryan Wu
@ 2012-11-12  8:40   ` Péter Ujfalusi
  0 siblings, 0 replies; 3+ messages in thread
From: Péter Ujfalusi @ 2012-11-12  8:40 UTC (permalink / raw)
  To: Bryan Wu; +Cc: Richard Purdie, Luotao Fu, linux-leds, linux-kernel

On 11/10/2012 02:48 AM, Bryan Wu wrote:
> On Wed, Nov 7, 2012 at 3:42 AM, Peter Ujfalusi <peter.ujfalusi@ti.com> wrote:
>> Update the driver to use the new API for requesting pwm so we can take
>> advantage of the pwm_lookup table to find the correct pwm to be used for the
>> LED functionality.
>> If the devm_get_pwm fails we fall back to legacy mode to try to get the pwm.
>>
>> Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
>> ---
>>  drivers/leds/leds-pwm.c | 16 ++++++++++++++--
>>  1 file changed, 14 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/leds/leds-pwm.c b/drivers/leds/leds-pwm.c
>> index f2e44c7..6bf9445 100644
>> --- a/drivers/leds/leds-pwm.c
>> +++ b/drivers/leds/leds-pwm.c
>> @@ -47,6 +47,19 @@ static void led_pwm_set(struct led_classdev *led_cdev,
>>         }
>>  }
>>
>> +static struct pwm_device *led_pwm_request_pwm(struct platform_device *pdev,
>> +                                             struct led_pwm *cur_led)
>> +{
>> +       struct pwm_device *pwm;
>> +
>> +       pwm = devm_pwm_get(&pdev->dev, cur_led->name);
>> +       if (IS_ERR(pwm)) {
>> +               dev_err(&pdev->dev, "unable to request PWM, trying legacy API\n");
>> +               pwm = pwm_request(cur_led->pwm_id, cur_led->name);
> 
> Looks good, but why we still need to keep the old API pwm_request(),
> if devm_pwm_get() is the right replacement. AFAIK, devm_***() API will
> help to clean up if device probing fails.
> 
> So if it is good enough, we can just replace pwm_request() to the devm_pwm_get()

I have greped for "leds_pwm" in arch/ and the only place it is used is the
arch/arm/mach-omap2/board-sdp4430sdp.c and that is not working at all (using
wrong ID for the PWM).
I think I can remove the legacy way of requesting the pwm from the driver
safely (I can also mark the pwm_id in struct led_pwm as deprecated at the same
time).
Will send the v2 soon.

Thank you,
Péter

> 
> Thanks,
> -Bryan
> 
>> +       }
>> +       return pwm;
>> +}
>> +
>>  static int led_pwm_probe(struct platform_device *pdev)
>>  {
>>         struct led_pwm_platform_data *pdata = pdev->dev.platform_data;
>> @@ -67,8 +80,7 @@ static int led_pwm_probe(struct platform_device *pdev)
>>                 cur_led = &pdata->leds[i];
>>                 led_dat = &leds_data[i];
>>
>> -               led_dat->pwm = pwm_request(cur_led->pwm_id,
>> -                               cur_led->name);
>> +               led_dat->pwm = led_pwm_request_pwm(pdev, cur_led);
>>                 if (IS_ERR(led_dat->pwm)) {
>>                         ret = PTR_ERR(led_dat->pwm);
>>                         dev_err(&pdev->dev, "unable to request PWM %d\n",
>> --
>> 1.8.0
>>



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-11-12  8:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-11-07 11:42 [PATCH] leds: leds-pwm: Convert to use devm_get_pwm Peter Ujfalusi
2012-11-10  1:48 ` Bryan Wu
2012-11-12  8:40   ` Péter Ujfalusi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).