From a99d76f9eb5336291fa6af713844d1c779484e30 Mon Sep 17 00:00:00 2001 From: Jingoo Han Date: Tue, 23 Oct 2012 05:17:11 -0700 Subject: leds: leds-gpio: use gpio_request_one Using gpio_request_one can make the code simpler because it can set the direction and initial value in one shot. Signed-off-by: Jingoo Han Signed-off-by: Bryan Wu --- drivers/leds/leds-gpio.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'drivers/leds/leds-gpio.c') diff --git a/drivers/leds/leds-gpio.c b/drivers/leds/leds-gpio.c index 087d1e66f4f7..0b4185315261 100644 --- a/drivers/leds/leds-gpio.c +++ b/drivers/leds/leds-gpio.c @@ -106,10 +106,6 @@ static int __devinit create_gpio_led(const struct gpio_led *template, return 0; } - ret = gpio_request(template->gpio, template->name); - if (ret < 0) - return ret; - led_dat->cdev.name = template->name; led_dat->cdev.default_trigger = template->default_trigger; led_dat->gpio = template->gpio; @@ -129,10 +125,12 @@ static int __devinit create_gpio_led(const struct gpio_led *template, if (!template->retain_state_suspended) led_dat->cdev.flags |= LED_CORE_SUSPENDRESUME; - ret = gpio_direction_output(led_dat->gpio, led_dat->active_low ^ state); + ret = gpio_request_one(template->gpio, + GPIOF_DIR_OUT | (led_dat->active_low ^ state), + template->name); if (ret < 0) - goto err; - + return ret; + INIT_WORK(&led_dat->work, gpio_led_work); ret = led_classdev_register(parent, &led_dat->cdev); -- cgit From 04553e925baaa815025c6fd3cdc301a794fa2c74 Mon Sep 17 00:00:00 2001 From: Roland Stigge Date: Sun, 28 Oct 2012 08:34:59 -0700 Subject: leds: leds-gpio: Defer probing in case of deferred gpio probing This patch makes leds-gpio's probe() return -EPROBE_DEFER if any of the gpios to register are deferred themselves. This makes a change of gpio_leds_create_of()'s return value necessary: Instead of returning NULL on error, we now use ERR_PTR() error coding. Signed-off-by: Roland Stigge Signed-off-by: Bryan Wu --- drivers/leds/leds-gpio.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'drivers/leds/leds-gpio.c') diff --git a/drivers/leds/leds-gpio.c b/drivers/leds/leds-gpio.c index 0b4185315261..6a2109638fbe 100644 --- a/drivers/leds/leds-gpio.c +++ b/drivers/leds/leds-gpio.c @@ -21,6 +21,7 @@ #include #include #include +#include struct gpio_led_data { struct led_classdev cdev; @@ -174,12 +175,16 @@ static struct gpio_leds_priv * __devinit gpio_leds_create_of(struct platform_dev /* count LEDs in this device, so we know how much to allocate */ count = of_get_child_count(np); if (!count) - return NULL; + return ERR_PTR(-ENODEV); + + for_each_child_of_node(np, child) + if (of_get_gpio(child, 0) == -EPROBE_DEFER) + return ERR_PTR(-EPROBE_DEFER); priv = devm_kzalloc(&pdev->dev, sizeof_gpio_leds_priv(count), GFP_KERNEL); if (!priv) - return NULL; + return ERR_PTR(-ENOMEM); for_each_child_of_node(np, child) { struct gpio_led led = {}; @@ -214,7 +219,7 @@ static struct gpio_leds_priv * __devinit gpio_leds_create_of(struct platform_dev err: for (count = priv->num_leds - 2; count >= 0; count--) delete_gpio_led(&priv->leds[count]); - return NULL; + return ERR_PTR(-ENODEV); } static const struct of_device_id of_gpio_leds_match[] = { @@ -224,7 +229,7 @@ static const struct of_device_id of_gpio_leds_match[] = { #else /* CONFIG_OF_GPIO */ static struct gpio_leds_priv * __devinit gpio_leds_create_of(struct platform_device *pdev) { - return NULL; + return ERR_PTR(-ENODEV); } #endif /* CONFIG_OF_GPIO */ @@ -262,8 +267,8 @@ static int __devinit gpio_led_probe(struct platform_device *pdev) } } else { priv = gpio_leds_create_of(pdev); - if (!priv) - return -ENODEV; + if (IS_ERR(priv)) + return PTR_ERR(priv); } platform_set_drvdata(pdev, priv); -- cgit From e3b1d44c3550e5badfa5b78ffec80e15d7d9b287 Mon Sep 17 00:00:00 2001 From: Sachin Kamat Date: Sun, 25 Nov 2012 10:10:20 +0530 Subject: leds: leds-gpio: use devm_gpio_request_one devm_gpio_request_one is device managed and makes error handling and cleanup simpler. Cc: Raphael Assenat Cc: Trent Piepho Signed-off-by: Sachin Kamat Signed-off-by: Bryan Wu --- drivers/leds/leds-gpio.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'drivers/leds/leds-gpio.c') diff --git a/drivers/leds/leds-gpio.c b/drivers/leds/leds-gpio.c index 6a2109638fbe..77e2e4057929 100644 --- a/drivers/leds/leds-gpio.c +++ b/drivers/leds/leds-gpio.c @@ -126,7 +126,7 @@ static int __devinit create_gpio_led(const struct gpio_led *template, if (!template->retain_state_suspended) led_dat->cdev.flags |= LED_CORE_SUSPENDRESUME; - ret = gpio_request_one(template->gpio, + ret = devm_gpio_request_one(parent, template->gpio, GPIOF_DIR_OUT | (led_dat->active_low ^ state), template->name); if (ret < 0) @@ -136,12 +136,9 @@ static int __devinit create_gpio_led(const struct gpio_led *template, ret = led_classdev_register(parent, &led_dat->cdev); if (ret < 0) - goto err; + return ret; return 0; -err: - gpio_free(led_dat->gpio); - return ret; } static void delete_gpio_led(struct gpio_led_data *led) @@ -150,7 +147,6 @@ static void delete_gpio_led(struct gpio_led_data *led) return; led_classdev_unregister(&led->cdev); cancel_work_sync(&led->work); - gpio_free(led->gpio); } struct gpio_leds_priv { -- cgit From 39de81a963ad261bcf2275ce5b1d6674a30c0428 Mon Sep 17 00:00:00 2001 From: Sachin Kamat Date: Sun, 25 Nov 2012 11:38:05 +0530 Subject: leds: leds-gpio: Use dev_info instead of printk Fixes the following checkpatch warning: WARNING: Prefer netdev_info(netdev, ... then dev_info(dev, ... then pr_info(... to printk(KERN_INFO ... FILE: leds/leds-gpio.c:105: printk(KERN_INFO "Skipping unavailable LED gpio %d (%s)\n", Signed-off-by: Sachin Kamat Signed-off-by: Bryan Wu --- drivers/leds/leds-gpio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/leds/leds-gpio.c') diff --git a/drivers/leds/leds-gpio.c b/drivers/leds/leds-gpio.c index 77e2e4057929..4f3179245ffe 100644 --- a/drivers/leds/leds-gpio.c +++ b/drivers/leds/leds-gpio.c @@ -102,7 +102,7 @@ static int __devinit create_gpio_led(const struct gpio_led *template, /* skip leds that aren't available */ if (!gpio_is_valid(template->gpio)) { - printk(KERN_INFO "Skipping unavailable LED gpio %d (%s)\n", + dev_info(parent, "Skipping unavailable LED gpio %d (%s)\n", template->gpio, template->name); return 0; } -- cgit