All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] leds: Convert S3C24XX LED driver to devm_kzalloc()
@ 2012-06-30 12:30 Sylwester Nawrocki
  2012-06-30 12:30 ` [PATCH 2/2] leds: Convert S3C24XX LED driver to gpiolib API Sylwester Nawrocki
  0 siblings, 1 reply; 6+ messages in thread
From: Sylwester Nawrocki @ 2012-06-30 12:30 UTC (permalink / raw)
  To: bryan.wu, rpurdie
  Cc: linux-leds, linux-samsung-soc, Sylwester Nawrocki, Ben Dooks

Use the device managed resource API for simplifying
the error/driver remove paths.

Cc: Ben Dooks <ben-linux@fluff.org>
Signed-off-by: Sylwester Nawrocki <sylvester.nawrocki@gmail.com>
---
 drivers/leds/leds-s3c24xx.c |    8 +++-----
 1 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/leds/leds-s3c24xx.c b/drivers/leds/leds-s3c24xx.c
index e6ee105..b816ccb 100644
--- a/drivers/leds/leds-s3c24xx.c
+++ b/drivers/leds/leds-s3c24xx.c
@@ -63,7 +63,6 @@ static int s3c24xx_led_remove(struct platform_device *dev)
 	struct s3c24xx_gpio_led *led = pdev_to_gpio(dev);

 	led_classdev_unregister(&led->cdev);
-	kfree(led);

 	return 0;
 }
@@ -74,7 +73,8 @@ static int s3c24xx_led_probe(struct platform_device *dev)
 	struct s3c24xx_gpio_led *led;
 	int ret;

-	led = kzalloc(sizeof(struct s3c24xx_gpio_led), GFP_KERNEL);
+	led = devm_kzalloc(&dev->dev, sizeof(struct s3c24xx_gpio_led),
+			   GFP_KERNEL);
 	if (led == NULL) {
 		dev_err(&dev->dev, "No memory for device\n");
 		return -ENOMEM;
@@ -103,10 +103,8 @@ static int s3c24xx_led_probe(struct platform_device *dev)
 	/* register our new led device */

 	ret = led_classdev_register(&dev->dev, &led->cdev);
-	if (ret < 0) {
+	if (ret < 0)
 		dev_err(&dev->dev, "led_classdev_register failed\n");
-		kfree(led);
-	}

 	return ret;
 }
--
1.7.4.1

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

* [PATCH 2/2] leds: Convert S3C24XX LED driver to gpiolib API
  2012-06-30 12:30 [PATCH 1/2] leds: Convert S3C24XX LED driver to devm_kzalloc() Sylwester Nawrocki
@ 2012-06-30 12:30 ` Sylwester Nawrocki
  2012-07-02  3:35   ` Bryan Wu
  0 siblings, 1 reply; 6+ messages in thread
From: Sylwester Nawrocki @ 2012-06-30 12:30 UTC (permalink / raw)
  To: bryan.wu, rpurdie
  Cc: linux-leds, linux-samsung-soc, Sylwester Nawrocki, Ben Dooks

The s3c2410_gpio* calls are obsolete and have been scheduled for
removal since several kernel releases. Remove them and use common
gpiolib API instead.
This patch also adds gpio_request/gpio_free call for API corectness.

It is a prerequisite for removal of the S3C24XX SoC specific
arch/arm/plat-samsung/include/gpio-fns.h header.

Tested on Micro2440-SDK.

Cc: Ben Dooks <ben-linux@fluff.org>
Signed-off-by: Sylwester Nawrocki <sylvester.nawrocki@gmail.com>
---
 drivers/leds/leds-s3c24xx.c |   34 ++++++++++++++++++++--------------
 1 files changed, 20 insertions(+), 14 deletions(-)

diff --git a/drivers/leds/leds-s3c24xx.c b/drivers/leds/leds-s3c24xx.c
index b816ccb..e120640 100644
--- a/drivers/leds/leds-s3c24xx.c
+++ b/drivers/leds/leds-s3c24xx.c
@@ -45,17 +45,19 @@ static void s3c24xx_led_set(struct led_classdev *led_cdev,
 {
 	struct s3c24xx_gpio_led *led = to_gpio(led_cdev);
 	struct s3c24xx_led_platdata *pd = led->pdata;
+	int state = (value ? 1 : 0) ^ (pd->flags & S3C24XX_LEDF_ACTLOW);
 
 	/* there will be a short delay between setting the output and
 	 * going from output to input when using tristate. */
 
-	s3c2410_gpio_setpin(pd->gpio, (value ? 1 : 0) ^
-			    (pd->flags & S3C24XX_LEDF_ACTLOW));
-
-	if (pd->flags & S3C24XX_LEDF_TRISTATE)
-		s3c2410_gpio_cfgpin(pd->gpio,
-			value ? S3C2410_GPIO_OUTPUT : S3C2410_GPIO_INPUT);
+	gpio_set_value(pd->gpio, state);
 
+	if (pd->flags & S3C24XX_LEDF_TRISTATE) {
+		if (value)
+			gpio_direction_output(pd->gpio, state);
+		else
+			gpio_direction_input(pd->gpio);
+	}
 }
 
 static int s3c24xx_led_remove(struct platform_device *dev)
@@ -63,6 +65,7 @@ static int s3c24xx_led_remove(struct platform_device *dev)
 	struct s3c24xx_gpio_led *led = pdev_to_gpio(dev);
 
 	led_classdev_unregister(&led->cdev);
+	gpio_free(led->pdata->gpio);
 
 	return 0;
 }
@@ -89,16 +92,19 @@ static int s3c24xx_led_probe(struct platform_device *dev)
 
 	led->pdata = pdata;
 
+	ret = gpio_request(pdata->gpio, "S3C24XX_LED");
+	if (ret < 0)
+		return ret;
+
 	/* no point in having a pull-up if we are always driving */
 
-	if (pdata->flags & S3C24XX_LEDF_TRISTATE) {
-		s3c2410_gpio_setpin(pdata->gpio, 0);
-		s3c2410_gpio_cfgpin(pdata->gpio, S3C2410_GPIO_INPUT);
-	} else {
-		s3c2410_gpio_pullup(pdata->gpio, 0);
-		s3c2410_gpio_setpin(pdata->gpio, 0);
-		s3c2410_gpio_cfgpin(pdata->gpio, S3C2410_GPIO_OUTPUT);
-	}
+	s3c_gpio_setpull(pdata->gpio, S3C_GPIO_PULL_NONE);
+
+	if (pdata->flags & S3C24XX_LEDF_TRISTATE)
+		gpio_direction_input(pdata->gpio);
+	else
+		gpio_direction_output(pdata->gpio,
+			pdata->flags & S3C24XX_LEDF_ACTLOW ? 1 : 0);
 
 	/* register our new led device */
 
-- 
1.7.4.1

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

* Re: [PATCH 2/2] leds: Convert S3C24XX LED driver to gpiolib API
  2012-06-30 12:30 ` [PATCH 2/2] leds: Convert S3C24XX LED driver to gpiolib API Sylwester Nawrocki
@ 2012-07-02  3:35   ` Bryan Wu
  2012-07-02 20:18     ` Sylwester Nawrocki
  0 siblings, 1 reply; 6+ messages in thread
From: Bryan Wu @ 2012-07-02  3:35 UTC (permalink / raw)
  To: Sylwester Nawrocki; +Cc: rpurdie, linux-leds, linux-samsung-soc, Ben Dooks

On Sat, Jun 30, 2012 at 8:30 PM, Sylwester Nawrocki
<sylvester.nawrocki@gmail.com> wrote:
> The s3c2410_gpio* calls are obsolete and have been scheduled for
> removal since several kernel releases. Remove them and use common
> gpiolib API instead.
> This patch also adds gpio_request/gpio_free call for API corectness.
>
> It is a prerequisite for removal of the S3C24XX SoC specific
> arch/arm/plat-samsung/include/gpio-fns.h header.
>
> Tested on Micro2440-SDK.
>

Overall, these 2 patches are good. I'm just curious why not we just
use generic led-gpio driver to replace this one.

-Bryan

> Cc: Ben Dooks <ben-linux@fluff.org>
> Signed-off-by: Sylwester Nawrocki <sylvester.nawrocki@gmail.com>
> ---
>  drivers/leds/leds-s3c24xx.c |   34 ++++++++++++++++++++--------------
>  1 files changed, 20 insertions(+), 14 deletions(-)
>
> diff --git a/drivers/leds/leds-s3c24xx.c b/drivers/leds/leds-s3c24xx.c
> index b816ccb..e120640 100644
> --- a/drivers/leds/leds-s3c24xx.c
> +++ b/drivers/leds/leds-s3c24xx.c
> @@ -45,17 +45,19 @@ static void s3c24xx_led_set(struct led_classdev *led_cdev,
>  {
>         struct s3c24xx_gpio_led *led = to_gpio(led_cdev);
>         struct s3c24xx_led_platdata *pd = led->pdata;
> +       int state = (value ? 1 : 0) ^ (pd->flags & S3C24XX_LEDF_ACTLOW);
>
>         /* there will be a short delay between setting the output and
>          * going from output to input when using tristate. */
>
> -       s3c2410_gpio_setpin(pd->gpio, (value ? 1 : 0) ^
> -                           (pd->flags & S3C24XX_LEDF_ACTLOW));
> -
> -       if (pd->flags & S3C24XX_LEDF_TRISTATE)
> -               s3c2410_gpio_cfgpin(pd->gpio,
> -                       value ? S3C2410_GPIO_OUTPUT : S3C2410_GPIO_INPUT);
> +       gpio_set_value(pd->gpio, state);
>
> +       if (pd->flags & S3C24XX_LEDF_TRISTATE) {
> +               if (value)
> +                       gpio_direction_output(pd->gpio, state);
> +               else
> +                       gpio_direction_input(pd->gpio);
> +       }
>  }
>
>  static int s3c24xx_led_remove(struct platform_device *dev)
> @@ -63,6 +65,7 @@ static int s3c24xx_led_remove(struct platform_device *dev)
>         struct s3c24xx_gpio_led *led = pdev_to_gpio(dev);
>
>         led_classdev_unregister(&led->cdev);
> +       gpio_free(led->pdata->gpio);
>
>         return 0;
>  }
> @@ -89,16 +92,19 @@ static int s3c24xx_led_probe(struct platform_device *dev)
>
>         led->pdata = pdata;
>
> +       ret = gpio_request(pdata->gpio, "S3C24XX_LED");
> +       if (ret < 0)
> +               return ret;
> +
>         /* no point in having a pull-up if we are always driving */
>
> -       if (pdata->flags & S3C24XX_LEDF_TRISTATE) {
> -               s3c2410_gpio_setpin(pdata->gpio, 0);
> -               s3c2410_gpio_cfgpin(pdata->gpio, S3C2410_GPIO_INPUT);
> -       } else {
> -               s3c2410_gpio_pullup(pdata->gpio, 0);
> -               s3c2410_gpio_setpin(pdata->gpio, 0);
> -               s3c2410_gpio_cfgpin(pdata->gpio, S3C2410_GPIO_OUTPUT);
> -       }
> +       s3c_gpio_setpull(pdata->gpio, S3C_GPIO_PULL_NONE);
> +
> +       if (pdata->flags & S3C24XX_LEDF_TRISTATE)
> +               gpio_direction_input(pdata->gpio);
> +       else
> +               gpio_direction_output(pdata->gpio,
> +                       pdata->flags & S3C24XX_LEDF_ACTLOW ? 1 : 0);
>
>         /* register our new led device */
>
> --
> 1.7.4.1
>



-- 
Bryan Wu <bryan.wu@canonical.com>
Kernel Developer    +86.186-168-78255 Mobile
Canonical Ltd.      www.canonical.com
Ubuntu - Linux for human beings | www.ubuntu.com

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

* Re: [PATCH 2/2] leds: Convert S3C24XX LED driver to gpiolib API
  2012-07-02  3:35   ` Bryan Wu
@ 2012-07-02 20:18     ` Sylwester Nawrocki
  2012-07-03  2:30       ` Bryan Wu
  0 siblings, 1 reply; 6+ messages in thread
From: Sylwester Nawrocki @ 2012-07-02 20:18 UTC (permalink / raw)
  To: Bryan Wu; +Cc: rpurdie, linux-leds, linux-samsung-soc, Ben Dooks

Hi,

On 07/02/2012 05:35 AM, Bryan Wu wrote:
> On Sat, Jun 30, 2012 at 8:30 PM, Sylwester Nawrocki
> <sylvester.nawrocki@gmail.com>  wrote:
>> The s3c2410_gpio* calls are obsolete and have been scheduled for
>> removal since several kernel releases. Remove them and use common
>> gpiolib API instead.
>> This patch also adds gpio_request/gpio_free call for API corectness.
>>
>> It is a prerequisite for removal of the S3C24XX SoC specific
>> arch/arm/plat-samsung/include/gpio-fns.h header.
>>
>> Tested on Micro2440-SDK.
>>
> 
> Overall, these 2 patches are good. I'm just curious why not we just
> use generic led-gpio driver to replace this one.

Thank you for the suggestion, I wasn't really aware of generic leds-gpio
driver... This could be nice optimization. However my intention was
to just clean up the GPIO bits, with minimal changes to other subsystems.
I could check and see how it could be done perhaps as a next step ? There
is a few (old) boards that use this driver and converting them would 
delay the GPIO patches even further...

Also generic led-gpio has some limitations, e.g. I couldn't see it supports
tri-stating a GPIO when a LED is off. Probably this feature could be added. 

--
Regards,
Sylwester

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

* Re: [PATCH 2/2] leds: Convert S3C24XX LED driver to gpiolib API
  2012-07-02 20:18     ` Sylwester Nawrocki
@ 2012-07-03  2:30       ` Bryan Wu
  2012-07-03 21:10         ` Sylwester Nawrocki
  0 siblings, 1 reply; 6+ messages in thread
From: Bryan Wu @ 2012-07-03  2:30 UTC (permalink / raw)
  To: Sylwester Nawrocki; +Cc: rpurdie, linux-leds, linux-samsung-soc, Ben Dooks

On Tue, Jul 3, 2012 at 4:18 AM, Sylwester Nawrocki
<sylvester.nawrocki@gmail.com> wrote:
> Hi,
>
> On 07/02/2012 05:35 AM, Bryan Wu wrote:
>> On Sat, Jun 30, 2012 at 8:30 PM, Sylwester Nawrocki
>> <sylvester.nawrocki@gmail.com>  wrote:
>>> The s3c2410_gpio* calls are obsolete and have been scheduled for
>>> removal since several kernel releases. Remove them and use common
>>> gpiolib API instead.
>>> This patch also adds gpio_request/gpio_free call for API corectness.
>>>
>>> It is a prerequisite for removal of the S3C24XX SoC specific
>>> arch/arm/plat-samsung/include/gpio-fns.h header.
>>>
>>> Tested on Micro2440-SDK.
>>>
>>
>> Overall, these 2 patches are good. I'm just curious why not we just
>> use generic led-gpio driver to replace this one.
>
> Thank you for the suggestion, I wasn't really aware of generic leds-gpio
> driver... This could be nice optimization. However my intention was
> to just clean up the GPIO bits, with minimal changes to other subsystems.
> I could check and see how it could be done perhaps as a next step ?

Sure, no problem. I will merge these 2 patches soon.

> There is a few (old) boards that use this driver and converting them would
> delay the GPIO patches even further...
>
> Also generic led-gpio has some limitations, e.g. I couldn't see it supports
> tri-stating a GPIO when a LED is off. Probably this feature could be added.
>

Good point, I will help to take a look.

Thanks,
-- 
Bryan Wu <bryan.wu@canonical.com>
Kernel Developer    +86.186-168-78255 Mobile
Canonical Ltd.      www.canonical.com
Ubuntu - Linux for human beings | www.ubuntu.com

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

* Re: [PATCH 2/2] leds: Convert S3C24XX LED driver to gpiolib API
  2012-07-03  2:30       ` Bryan Wu
@ 2012-07-03 21:10         ` Sylwester Nawrocki
  0 siblings, 0 replies; 6+ messages in thread
From: Sylwester Nawrocki @ 2012-07-03 21:10 UTC (permalink / raw)
  To: Bryan Wu; +Cc: rpurdie, linux-leds, linux-samsung-soc, Ben Dooks

On 07/03/2012 04:30 AM, Bryan Wu wrote:
...
>>> Overall, these 2 patches are good. I'm just curious why not we just
>>> use generic led-gpio driver to replace this one.
>>
>> Thank you for the suggestion, I wasn't really aware of generic leds-gpio
>> driver... This could be nice optimization. However my intention was
>> to just clean up the GPIO bits, with minimal changes to other subsystems.
>> I could check and see how it could be done perhaps as a next step ?
> 
> Sure, no problem. I will merge these 2 patches soon.

Thank you.

>> There is a few (old) boards that use this driver and converting them would
>> delay the GPIO patches even further...
>>
>> Also generic led-gpio has some limitations, e.g. I couldn't see it supports
>> tri-stating a GPIO when a LED is off. Probably this feature could be added.
>>
> 
> Good point, I will help to take a look.

I should get back to this when I find some more time.

That might not be difficult, probably gpio_request_one() with GPIOF_OPEN_DRAIN/
GPIOF_OPEN_SOURCE flag instead of gpio_request() would do.

--
Regards,
Sylwester

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

end of thread, other threads:[~2012-07-03 21:10 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-30 12:30 [PATCH 1/2] leds: Convert S3C24XX LED driver to devm_kzalloc() Sylwester Nawrocki
2012-06-30 12:30 ` [PATCH 2/2] leds: Convert S3C24XX LED driver to gpiolib API Sylwester Nawrocki
2012-07-02  3:35   ` Bryan Wu
2012-07-02 20:18     ` Sylwester Nawrocki
2012-07-03  2:30       ` Bryan Wu
2012-07-03 21:10         ` Sylwester Nawrocki

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.