From: Russell King <rmk+kernel@arm.linux.org.uk>
To: Bryan Wu <cooloney@gmail.com>, Richard Purdie <rpurdie@rpsys.net>
Cc: linux-leds@vger.kernel.org
Subject: [PATCH 2/5] leds: leds-pwm: provide a common function to setup a single led-pwm device
Date: Sun, 06 Apr 2014 23:20:08 +0100 [thread overview]
Message-ID: <E1WWvQ8-00049T-NP@rmk-PC.arm.linux.org.uk> (raw)
In-Reply-To: <20140406221854.GS7528@n2100.arm.linux.org.uk>
Provide a common function to setup a single led-pwm device, replacing
the platform data initialisation path with this function. This allows
us to have a common method of creating these devices in a consistent
manner, which then allows us to place the probe failure cleanup in one
place.
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
---
drivers/leds/leds-pwm.c | 85 ++++++++++++++++++++++++++-----------------------
1 file changed, 46 insertions(+), 39 deletions(-)
diff --git a/drivers/leds/leds-pwm.c b/drivers/leds/leds-pwm.c
index a7b369fc3554..2e6b6c5ca0e9 100644
--- a/drivers/leds/leds-pwm.c
+++ b/drivers/leds/leds-pwm.c
@@ -93,6 +93,44 @@ static void led_pwm_cleanup(struct led_pwm_priv *priv)
}
}
+static int led_pwm_add(struct device *dev, struct led_pwm_priv *priv,
+ struct led_pwm *led)
+{
+ struct led_pwm_data *led_data = &priv->leds[priv->num_leds];
+ int ret;
+
+ led_data->active_low = led->active_low;
+ led_data->period = led->pwm_period_ns;
+ led_data->cdev.name = led->name;
+ led_data->cdev.default_trigger = led->default_trigger;
+ led_data->cdev.brightness_set = led_pwm_set;
+ led_data->cdev.brightness = LED_OFF;
+ led_data->cdev.max_brightness = led->max_brightness;
+ led_data->cdev.flags = LED_CORE_SUSPENDRESUME;
+
+ led_data->pwm = devm_pwm_get(dev, led->name);
+ if (IS_ERR(led_data->pwm)) {
+ ret = PTR_ERR(led_data->pwm);
+ dev_err(dev, "unable to request PWM for %s: %d\n",
+ led->name, ret);
+ return ret;
+ }
+
+ led_data->can_sleep = pwm_can_sleep(led_data->pwm);
+ if (led_data->can_sleep)
+ INIT_WORK(&led_data->work, led_pwm_work);
+
+ ret = led_classdev_register(dev, &led_data->cdev);
+ if (ret == 0) {
+ priv->num_leds++;
+ } else {
+ dev_err(dev, "failed to register PWM led for %s: %d\n",
+ led->name, ret);
+ }
+
+ return ret;
+}
+
static int led_pwm_create_of(struct platform_device *pdev,
struct led_pwm_priv *priv)
{
@@ -140,8 +178,6 @@ static int led_pwm_create_of(struct platform_device *pdev,
return 0;
err:
- led_pwm_cleanup(priv);
-
return ret;
}
@@ -167,51 +203,22 @@ static int led_pwm_probe(struct platform_device *pdev)
if (pdata) {
for (i = 0; i < count; i++) {
- struct led_pwm *cur_led = &pdata->leds[i];
- struct led_pwm_data *led_dat = &priv->leds[i];
-
- led_dat->pwm = devm_pwm_get(&pdev->dev, cur_led->name);
- if (IS_ERR(led_dat->pwm)) {
- ret = PTR_ERR(led_dat->pwm);
- dev_err(&pdev->dev,
- "unable to request PWM for %s\n",
- cur_led->name);
- goto err;
- }
-
- led_dat->cdev.name = cur_led->name;
- led_dat->cdev.default_trigger = cur_led->default_trigger;
- led_dat->active_low = cur_led->active_low;
- led_dat->period = cur_led->pwm_period_ns;
- led_dat->cdev.brightness_set = led_pwm_set;
- led_dat->cdev.brightness = LED_OFF;
- led_dat->cdev.max_brightness = cur_led->max_brightness;
- led_dat->cdev.flags |= LED_CORE_SUSPENDRESUME;
-
- led_dat->can_sleep = pwm_can_sleep(led_dat->pwm);
- if (led_dat->can_sleep)
- INIT_WORK(&led_dat->work, led_pwm_work);
-
- ret = led_classdev_register(&pdev->dev, &led_dat->cdev);
- if (ret < 0)
- goto err;
+ ret = led_pwm_add(&pdev->dev, priv, &pdata->leds[i]);
+ if (ret)
+ break;
}
- priv->num_leds = count;
} else {
ret = led_pwm_create_of(pdev, priv);
- if (ret)
- return ret;
+ }
+
+ if (ret) {
+ led_pwm_cleanup(priv);
+ return ret;
}
platform_set_drvdata(pdev, priv);
return 0;
-
-err:
- priv->num_leds = i;
- led_pwm_cleanup(priv);
-
- return ret;
}
static int led_pwm_remove(struct platform_device *pdev)
--
1.8.3.1
next prev parent reply other threads:[~2014-04-06 22:20 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-06 22:18 [PATCH 0/5] Fix various issues with leds-pwm Russell King - ARM Linux
2014-04-06 22:20 ` [PATCH 1/5] leds: leds-pwm: properly clean up after probe failure Russell King
2014-04-06 22:20 ` Russell King [this message]
2014-04-06 22:20 ` [PATCH 3/5] leds: leds-pwm: convert OF parsing code to use led_pwm_add() Russell King
2014-04-06 22:20 ` [PATCH 4/5] leds: leds-pwm: implement PWM inversion Russell King
2014-04-07 8:46 ` Alexandre Belloni
2014-04-07 8:52 ` Russell King - ARM Linux
2014-04-07 9:28 ` Alexandre Belloni
2014-04-07 9:42 ` Russell King - ARM Linux
2014-04-07 11:10 ` Thierry Reding
2014-04-07 11:35 ` Russell King - ARM Linux
2014-04-07 12:01 ` Thierry Reding
2014-04-07 12:37 ` Russell King - ARM Linux
2014-04-07 13:37 ` Thierry Reding
2014-04-07 14:20 ` Alexandre Belloni
2014-04-07 15:01 ` Russell King - ARM Linux
2014-04-06 22:20 ` [PATCH 5/5] leds: leds-pwm: add DT support for LEDs wired to supply Russell King
2014-04-07 21:31 ` [PATCH 0/5] Fix various issues with leds-pwm Bryan Wu
2014-04-07 21:33 ` Russell King - ARM Linux
2014-04-07 21:36 ` Bryan Wu
2014-06-12 17:12 ` Russell King - ARM Linux
2014-06-12 17:37 ` Bryan Wu
2014-06-12 17:56 ` Alexandre Belloni
2014-06-12 18:01 ` Bryan Wu
2014-06-12 18:03 ` Russell King - ARM Linux
2014-06-12 18:16 ` Bryan Wu
2014-06-12 18:21 ` Russell King - ARM Linux
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=E1WWvQ8-00049T-NP@rmk-PC.arm.linux.org.uk \
--to=rmk+kernel@arm.linux.org.uk \
--cc=cooloney@gmail.com \
--cc=linux-leds@vger.kernel.org \
--cc=rpurdie@rpsys.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).