leds: Add WM8350 LED driver
Subsystems (4)
PATCH 1/1 leds: Add WM8350 LED driver
The voltage and current regulators on the WM8350 AudioPlus PMIC can be used in concert to provide a power efficient LED driver. This driver implements support for this within the standard LED class.
Platform initialisation code should configure the LED hardware in the init callback provided by the WM8350 core driver. The callback should use wm8350_isink_set_flash(), wm8350_dcdc25_set_mode() and wm8350_dcdc_set_slot() to configure the operating parameters of the regulators for their hardware and then then use wm8350_register_led() to instantiate the LED driver.
This driver was originally written by Liam Girdwood, though it has been extensively modified since then.
--- drivers/leds/Kconfig | 7 + drivers/leds/Makefile | 1 + drivers/leds/leds-wm8350.c | 327 ++++++++++++++++++++++++++++++++++ drivers/mfd/wm8350-core.c | 3 + drivers/regulator/wm8350-regulator.c | 89 +++++++++ include/linux/mfd/wm8350/pmic.h | 35 ++++ 6 files changed, 462 insertions(+), 0 deletions(-) create mode 100644 drivers/leds/leds-wm8350.c
drivers/leds/Kconfig +7 -0
@@ -158,6 +158,13 @@ config LEDS_PCA955X LED driver chips accessed via the I2C bus. Supported devices include PCA9550, PCA9551, PCA9552, and PCA9553. +config LEDS_WM8350 + tristate "LED Support for WM8350 AudioPlus PMIC" + depends on LEDS_CLASS && MFD_WM8350 + help + This option enables support for LEDs driven by the Wolfson + Microelectronics WM8350 AudioPlus PMIC. + config LEDS_DA903X tristate "LED Support for DA9030/DA9034 PMIC" depends on LEDS_CLASS && PMIC_DA903X
drivers/leds/Makefile +1 -0
@@ -23,6 +23,7 @@ obj-$(CONFIG_LEDS_FSG) += leds-fsg.o obj-$(CONFIG_LEDS_PCA955X) += leds-pca955x.o obj-$(CONFIG_LEDS_DA903X) += leds-da903x.o obj-$(CONFIG_LEDS_HP_DISK) += leds-hp-disk.o +obj-$(CONFIG_LEDS_WM8350) += leds-wm8350.o # LED Triggers obj-$(CONFIG_LEDS_TRIGGER_TIMER) += ledtrig-timer.o
drivers/leds/leds-wm8350.c new file +327 -0
327 lines not on this page · raw message
drivers/mfd/wm8350-core.c +3 -0
@@ -1257,6 +1257,9 @@ void wm8350_device_exit(struct wm8350 *wm8350) {int i; +for (i =0 ; i <ARRAY_SIZE (wm8350->pmic.led); i++) +platform_device_unregister (wm8350->pmic.led[i].pdev); +for (i =0 ; i <ARRAY_SIZE (wm8350->pmic.pdev); i++)platform_device_unregister (wm8350->pmic.pdev[i]);
drivers/regulator/wm8350-regulator.c +89 -0
95 lines not on this page · raw message
include/linux/mfd/wm8350/pmic.h +35 -0
@@ -13,6 +13,10 @@#ifndef __LINUX_MFD_WM8350_PMIC_H#define __LINUX_MFD_WM8350_PMIC_H +#include <linux/platform_device.h> +#include <linux/leds.h> +#include <linux/regulator/machine.h> +/* * Register values. */
@@ -700,6 +704,32 @@ struct wm8350;struct platform_device ;struct regulator_init_data ; +/* +* WM8350 LED platform data +*/ +struct wm8350_led_platform_data { +const char *name; +const char *default_trigger; +int max_uA; +}; + +struct wm8350_led { +struct platform_device *pdev; +struct mutex mutex; +struct work_struct work; +enum led_brightness value; +struct led_classdev cdev; +int max_uA_index; +int enabled; + +struct regulator *isink; +struct regulator_consumer_supply isink_consumer; +struct regulator_init_data isink_init; +struct regulator *dcdc; +struct regulator_consumer_supply dcdc_consumer; +struct regulator_init_data dcdc_init; +}; +struct wm8350_pmic {/* ISINK to DCDC mapping */ int isink_A_dcdc;
@@ -713,10 +743,15 @@ struct wm8350_pmic {/* regulator devices */ struct platform_device *pdev[NUM_WM8350_REGULATORS ]; + +/* LED devices */ +struct wm8350_led led[2 ]; };int wm8350_register_regulator (struct wm8350 *wm8350,int reg,struct regulator_init_data *initdata); +int wm8350_register_led (struct wm8350 *wm8350,int lednum,int dcdc,int isink, +struct wm8350_led_platform_data *pdata);/* * Additional DCDC control not supported via regulator API
Signature · 1 line
1.5.6.5
PATCH 1/1 leds: Fix locking for WM8350
LED API functions aren't allowed to sleep so we can't take a lock when setting the brightness of the LED.
---
Sorry, I managed to drop this fix when moving the driver over to mainline for submission. I'll roll it into the original patch in any future submissions.
drivers/leds/leds-wm8350.c | 3 --- 1 files changed, 0 insertions(+), 3 deletions(-)
drivers/leds/leds-wm8350.c +0 -3
@@ -170,10 +170,7 @@ static void wm8350_led_set(struct led_classdev *led_cdev, {struct wm8350_led *led =to_wm8350_led (led_cdev); -mutex_lock (&led->mutex); led->value = value; -mutex_unlock (&led->mutex); -schedule_work (&led->work); }
Signature · 1 line
1.5.6.5
Re: [PATCH] leds: Fix locking for WM8350
Quoted 18 lines · Mark Brown
LED API functions aren't allowed to sleep so we can't take a lock when setting the brightness of the LED.
Signed-off-by Mark Brown <[email protected]>---
Sorry, I managed to drop this fix when moving the driver over to mainline for submission. I'll roll it into the original patch in any future submissions.
drivers/leds/leds-wm8350.c | 3 --- 1 files changed, 0 insertions(+), 3 deletions(-)drivers/leds/leds-wm8350.c +0
-0
drivers/leds/leds-wm8350.c static void wm8350_led_set(struct led_classdev *led_cdev, · line 175
Quoted 9 lines
drivers/leds/leds-wm8350.c +0
-3@@ -170,10 +170,7 @@ static void wm8350_led_set(struct led_classdev *led_cdev, {struct wm8350_led *led =to_wm8350_led (led_cdev); -mutex_lock (&led->mutex); led->value = value; -mutex_unlock (&led->mutex); -schedule_work (&led->work); }
Unfortunately, now you write to value w/o locking -> races possible. Maybe you need to make value atomic_t?
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: [PATCH] leds: Fix locking for WM8350
Quoted 2 lines · Pavel Machek
Unfortunately, now you write to value w/o locking -> races possible. Maybe you need to make value
atomic_t?
Yes, that'd be safer though I'd be surprised to see systems that could trigger it.
Re: [PATCH] leds: Fix locking for WM8350
Quoted 7 lines · Mark Brown
Quoted 2 lines · Pavel Machek
Unfortunately, now you write to value w/o locking -> races possible. Maybe you need to make value
atomic_t?Yes, that'd be safer though I'd be surprised to see systems that could trigger it.
Yes, they are uncommon. They exist; SPARC, IIRC. Plus you need barriers on anything SMP... Just use atomic_t.
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: [PATCH] leds: Fix locking for WM8350
Quoted 6 lines · Pavel Machek
Quoted 2 lines · Mark Brown
Yes, that'd be safer though I'd be surprised to see systems that could trigger it.
Yes, they are uncommon. They exist; SPARC, IIRC. Plus you need
Exceptionally uncommon with the systems the WM8350 gets used with - it's a primary PMIC for mobile devices so anything other than uniprocessor ARM would be surprising.
Quoted 1 line
barriers on anything SMP... Just use
atomic_t.
I was intending to do so next time I spin the patch. Andrew had some other comments and I don't have any test systems when I'm not in the office anyway.
Re: [PATCH] leds: Fix locking for WM8350
Quoted 12 lines · Mark Brown
Quoted 6 lines · Pavel Machek
Quoted 2 lines · Mark Brown
Yes, that'd be safer though I'd be surprised to see systems that could trigger it.
Yes, they are uncommon. They exist; SPARC, IIRC. Plus you need
Exceptionally uncommon with the systems the WM8350 gets used with - it's a primary PMIC for mobile devices so anything other than uniprocessor ARM would be surprising.
Quoted 5 lines
Quoted 1 line
barriers on anything SMP... Just use
atomic_t.I was intending to do so next time I spin the patch. Andrew had some other comments and I don't have any test systems when I'm not in the office anyway.
I've not looked in detail at the code but it looks like a maximum of a 32 bit value where you don't actually care which write succeeds as long as it takes one of the values written? I don't see why that particular variable needs any locking or to be atomic?
Cheers,
Richard
Re: [PATCH] leds: Fix locking for WM8350
Quoted 3 lines · Richard Purdie
I've not looked in detail at the code but it looks like a maximum of a 32 bit value where you don't actually care which write succeeds as long as it takes one of the values written? I don't see why that particular
Pretty much (it's an enum led_brightness) - it's just a standard LED that can't be written without taking interrupts along the lines of the GPIO LED driver.
Quoted 1 line
variable needs any locking or to be atomic?
I'd certainly be surprised if it were an issue in any practical system.
Re: [PATCH] leds: Fix locking for WM8350
In reply to Richard PurdieQuoted 15 lines · Richard Purdie
Quoted 14 lines · Mark Brown
Quoted 6 lines · Pavel Machek
Quoted 2 lines · Mark Brown
Yes, that'd be safer though I'd be surprised to see systems that could trigger it.
Yes, they are uncommon. They exist; SPARC, IIRC. Plus you need
Exceptionally uncommon with the systems the WM8350 gets used with - it's a primary PMIC for mobile devices so anything other than uniprocessor ARM would be surprising.
Quoted 1 line
barriers on anything SMP... Just use
atomic_t.
Quoted 8 lines
Quoted 3 lines
I was intending to do so next time I spin the patch. Andrew had some other comments and I don't have any test systems when I'm not in the office anyway.
I've not looked in detail at the code but it looks like a maximum of a 32 bit value where you don't actually care which write succeeds as long as it takes one of the values written? I don't see why that particular variable needs any locking or to be atomic?
Yes.. but it would hurt if you find 42 there, right? So atomic_t is safer. gcc is alowed to do fancy optimalizations on plain integers....
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Quoted 23 lines · On Thu, 13 Nov 2008 12:39:57 +0000 Mark Brown…
The voltage and current regulators on the WM8350 AudioPlus PMIC can be used in concert to provide a power efficient LED driver. This driver implements support for this within the standard LED class.
Platform initialisation code should configure the LED hardware in the init callback provided by the WM8350 core driver. The callback should use
wm8350_isink_set_flash(),wm8350_dcdc25_set_mode()andwm8350_dcdc_set_slot()to configure the operating parameters of the regulators for their hardware and then then usewm8350_register_led()to instantiate the LED driver.This driver was originally written by Liam Girdwood, though it has been extensively modified since then.
...
drivers/leds/leds-wm8350.c new file +7
-0+static void wm8350_led_disable (struct wm8350_led *led) +{ +int ret; + +if (!led->enabled) +return ; +
drivers/leds/leds-wm8350.c line 130
Quoted 10 lines
drivers/leds/leds-wm8350.c new file +10
-0+ ret =regulator_disable (led->dcdc); +if (ret !=0 ) { +dev_err (led->cdev.dev,"Failed to disable DCDC: %d\n" , ret); +return ; + } + + ret =regulator_disable (led->isink); +if (ret !=0 ) { +dev_err (led->cdev.dev,"Failed to disable ISINK: %d\n" , ret); +regulator_enable (led->isink);
Should be regulator_enable(led->dcdc), yes?
drivers/leds/leds-wm8350.c line 184
Quoted 13 lines
drivers/leds/leds-wm8350.c new file +10
-0+return ; + } + + led->enabled =0 ; +} + +static int wm8350_led_remove (struct platform_device *pdev) +{ +struct wm8350_led *led = + (struct wm8350_led *)platform_get_drvdata (pdev);
unneeded and undesirable cast of void*.
drivers/leds/leds-wm8350.c line 292
Quoted 3 lines
drivers/leds/leds-wm8350.c new file +3
-0+led_classdev_unregister (&led->cdev); +schedule_work (&led->work); +flush_scheduled_work ();
The schedule_work() is unexpected and I can't immediately see why it's here. If it is indeed correct, I'd suggest the addition of a comment.
Quoted 7 lines
drivers/leds/leds-wm8350.c new file +7
-0+wm8350_led_disable (led); +regulator_put (led->dcdc); +regulator_put (led->isink); +kfree (led); +return 0 ; +} +
Quoted 6 lines · Andrew Morton
drivers/leds/leds-wm8350.c line 292
Quoted 3 lines
drivers/leds/leds-wm8350.c new file +3
-0+led_classdev_unregister (&led->cdev); +schedule_work (&led->work); +flush_scheduled_work ();The
schedule_work()is unexpected and I can't immediately see why it's here. If it is indeed correct, I'd suggest the addition of a comment.
Me either, I'll remove it and fix the other things you raised too. Thanks.
Quoted 10 lines · Mark Brown
The voltage and current regulators on the WM8350 AudioPlus PMIC can be used in concert to provide a power efficient LED driver. This driver implements support for this within the standard LED class.
Platform initialisation code should configure the LED hardware in the init callback provided by the WM8350 core driver. The callback should use
wm8350_isink_set_flash(),wm8350_dcdc25_set_mode()andwm8350_dcdc_set_slot()to configure the operating parameters of the regulators for their hardware and then then usewm8350_register_led()to instantiate the LED driver.
What kind of hw is this? 1W led attached to some kind of PDA?
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Quoted 6 lines · Pavel Machek
Quoted 2 lines · Mark Brown
regulators for their hardware and then then use
wm8350_register_led()to instantiate the LED driver.What kind of hw is this? 1W led attached to some kind of PDA?
Depends on the hardware design - this is a generic component for battery powered devices (including PDAs). Typical applications include relatively high power things like backlights.