backlight: Add WM831x backlight driver
Subsystems (5)
PATCH 1/2 backlight: Add WM831x backlight driver
The WM831x series of PMICs provide DC-DC boost convertors and current sinks which can be used together to drive LEDs for use as backlights. Expose this functionality via the backlight API.
Since when used in this configuration the current sink and boost convertor are very tightly coupled with a multi-stage startup for the current sink which overlaps with the boost convertor startup this driver bypasses the regulator API. Machine inititialisation is responsible for ensuring that the regulators are not accessed via both APIs.
--- drivers/video/backlight/Kconfig | 7 + drivers/video/backlight/Makefile | 1 + drivers/video/backlight/wm831x_bl.c | 250 +++++++++++++++++++++++++++++++++++ 3 files changed, 258 insertions(+), 0 deletions(-) create mode 100644 drivers/video/backlight/wm831x_bl.c
drivers/video/backlight/Kconfig +7 -0
@@ -229,3 +229,10 @@ config BACKLIGHT_SAHARA help If you have a Tabletkiosk Sahara Touch-iT, say y to enable the backlight driver. + +config BACKLIGHT_WM831X + tristate "WM831x PMIC Backlight Driver" + depends on BACKLIGHT_CLASS_DEVICE && MFD_WM831X + help + If you have a backlight driven by the ISINK and DCDC of a + WM831x PMIC say y to enable the backlight driver for it.
drivers/video/backlight/Makefile +1 -0
@@ -24,4 +24,5 @@ obj-$(CONFIG_BACKLIGHT_DA903X) += da903x_bl.o obj-$(CONFIG_BACKLIGHT_MBP_NVIDIA) += mbp_nvidia_bl.o obj-$(CONFIG_BACKLIGHT_TOSA) += tosa_bl.o obj-$(CONFIG_BACKLIGHT_SAHARA) += kb3886_bl.o +obj-$(CONFIG_BACKLIGHT_WM831X) += wm831x_bl.o
drivers/video/backlight/wm831x_bl.c new file +250 -0
250 lines not on this page · raw message
Signature · 1 line
1.6.3.3
PATCH 2/2 leds: Add WM831x status LED driver
The WM831x devices feature two software controlled status LEDs with hardware assisted blinking.
The device can also autonomously control the LEDs based on a selection of sources. This can be configured at boot time using either platform data or the chip OTP. A sysfs file in the style of that for triggers allowing the control source to be configured at run time. Triggers can't be used here since they can't depend on the implementation details of a specific LED type.
--- drivers/leds/Kconfig | 7 + drivers/leds/Makefile | 1 + drivers/leds/leds-wm831x-status.c | 341 +++++++++++++++++++++++++++++++++++++ include/linux/mfd/wm831x/status.h | 34 ++++ 4 files changed, 383 insertions(+), 0 deletions(-) create mode 100644 drivers/leds/leds-wm831x-status.c create mode 100644 include/linux/mfd/wm831x/status.h
drivers/leds/Kconfig +7 -0
@@ -195,6 +195,13 @@ config LEDS_PCA955X LED driver chips accessed via the I2C bus. Supported devices include PCA9550, PCA9551, PCA9552, and PCA9553. +config LEDS_WM831X_STATUS + tristate "LED support for status LEDs on WM831x PMICs" + depends on LEDS_CLASS && MFD_WM831X + help + This option enables support for the status LEDs of the WM831x + series of PMICs. + config LEDS_WM8350 tristate "LED Support for WM8350 AudioPlus PMIC" depends on LEDS_CLASS && MFD_WM8350
drivers/leds/Makefile +1 -0
@@ -26,6 +26,7 @@ obj-$(CONFIG_LEDS_HP6XX) += leds-hp6xx.o obj-$(CONFIG_LEDS_FSG) += leds-fsg.o obj-$(CONFIG_LEDS_PCA955X) += leds-pca955x.o obj-$(CONFIG_LEDS_DA903X) += leds-da903x.o +obj-$(CONFIG_LEDS_WM831X_STATUS) += leds-wm831x-status.o obj-$(CONFIG_LEDS_WM8350) += leds-wm8350.o obj-$(CONFIG_LEDS_PWM) += leds-pwm.o
drivers/leds/leds-wm831x-status.c new file +341 -0
341 lines not on this page · raw message
include/linux/mfd/wm831x/status.h new file +34 -0
@@ -0,0 +1,34 @@ +/* +* include/linux/mfd/wm831x/status.h -- Status LEDs for WM831x +* +* Copyright 2009 Wolfson Microelectronics PLC. +* +* Author: Mark Brown <[email protected]> +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at your +* option) any later version. +* +*/ + +#ifndef __MFD_WM831X_STATUS_H__ +#define __MFD_WM831X_STATUS_H__ + +#define WM831X_LED_SRC_MASK 0xC000/* LED_SRC - [15:14] */ +#define WM831X_LED_SRC_SHIFT 14/* LED_SRC - [15:14] */ +#define WM831X_LED_SRC_WIDTH 2/* LED_SRC - [15:14] */ +#define WM831X_LED_MODE_MASK 0x0300/* LED_MODE - [9:8] */ +#define WM831X_LED_MODE_SHIFT 8/* LED_MODE - [9:8] */ +#define WM831X_LED_MODE_WIDTH 2/* LED_MODE - [9:8] */ +#define WM831X_LED_SEQ_LEN_MASK 0x0030/* LED_SEQ_LEN - [5:4] */ +#define WM831X_LED_SEQ_LEN_SHIFT 4/* LED_SEQ_LEN - [5:4] */ +#define WM831X_LED_SEQ_LEN_WIDTH 2/* LED_SEQ_LEN - [5:4] */ +#define WM831X_LED_DUR_MASK 0x000C/* LED_DUR - [3:2] */ +#define WM831X_LED_DUR_SHIFT 2/* LED_DUR - [3:2] */ +#define WM831X_LED_DUR_WIDTH 2/* LED_DUR - [3:2] */ +#define WM831X_LED_DUTY_CYC_MASK 0x0003/* LED_DUTY_CYC - [1:0] */ +#define WM831X_LED_DUTY_CYC_SHIFT 0/* LED_DUTY_CYC - [1:0] */ +#define WM831X_LED_DUTY_CYC_WIDTH 2/* LED_DUTY_CYC - [1:0] */ + +#endif
Signature · 1 line
1.6.3.3
Re: [PATCH 2/2] leds: Add WM831x status LED driver
Quoted 17 lines · Mark Brown
The WM831x devices feature two software controlled status LEDs with hardware assisted blinking.
The device can also autonomously control the LEDs based on a selection of sources. This can be configured at boot time using either platform data or the chip OTP. A sysfs file in the style of that for triggers allowing the control source to be configured at run time. Triggers can't be used here since they can't depend on the implementation details of a specific LED type.
Signed-off-by Mark Brown <[email protected]>drivers/leds/leds-wm831x-status.c new file +5
-0+static int wm831x_status_probe (struct platform_device *pdev) +{ +struct wm831x *wm831x =dev_get_drvdata (pdev->dev.parent); +struct wm831x_pdata *chip_pdata; +struct wm831x_status_pdata pdata;
drivers/leds/leds-wm831x-status.c line 235
Quoted 10 lines
drivers/leds/leds-wm831x-status.c new file +10
-0+struct wm831x_status *drvdata; +struct resource *res; +int id = pdev->id %ARRAY_SIZE (chip_pdata->status); +int ret; + + res =platform_get_resource (pdev,IORESOURCE_IO ,0 ); +if (res ==NULL ) { +dev_err (&pdev->dev,"No I/O resource\n" ); + ret = -EINVAL ; + goto err;
Why not return -EINVAL right here ?
Quoted 55 lines
drivers/leds/leds-wm831x-status.c new file +55
-0+ } + + drvdata =kzalloc (sizeof (struct wm831x_status ),GFP_KERNEL ); +if (!drvdata) +return -ENOMEM ; +dev_set_drvdata (&pdev->dev, drvdata); + + drvdata->wm831x = wm831x; + drvdata->reg = res->start; + +if (wm831x->dev->platform_data) + chip_pdata = wm831x->dev->platform_data; +else + chip_pdata =NULL ; + +memset (&pdata,0 ,sizeof (pdata)); +if (chip_pdata && chip_pdata->status[id]) +memcpy (&pdata, chip_pdata->status[id],sizeof (pdata)); +else + pdata.name =dev_name (&pdev->dev); + +mutex_init (&drvdata->mutex); +INIT_WORK (&drvdata->work, wm831x_status_work); +spin_lock_init (&drvdata->value_lock); + +/* We cache the configuration register and read startup values +* from it. */ + drvdata->reg_val =wm831x_reg_read (wm831x, drvdata->reg); + +if (drvdata->reg_val &WM831X_LED_MODE_MASK ) + drvdata->brightness =LED_FULL ; +else + drvdata->brightness =LED_OFF ; + +/* Set a default source if configured, otherwise leave the +* current hardware setting. +*/ +if (pdata.default_src ==WM831X_STATUS_PRESERVE ) { + drvdata->src = drvdata->reg_val; + drvdata->src &=WM831X_LED_SRC_MASK ; + drvdata->src >>=WM831X_LED_SRC_SHIFT ; + }else { + drvdata->src = pdata.default_src -1 ; + } + + drvdata->cdev.name = pdata.name; + drvdata->cdev.default_trigger = pdata.default_trigger; + drvdata->cdev.brightness_set = wm831x_status_set; + drvdata->cdev.blink_set = wm831x_status_blink_set; + + ret =led_classdev_register (wm831x->dev, &drvdata->cdev); +if (ret <0 ) { +dev_err (&pdev->dev,"Failed to register LED: %d\n" , ret); + goto err_led; + }
drivers/leds/leds-wm831x-status.c line 300
Quoted 10 lines
drivers/leds/leds-wm831x-status.c new file +10
-0+ + ret =device_create_file (drvdata->cdev.dev, &dev_attr_src); +if (ret !=0 ) +dev_err (&pdev->dev, +"No source control for LED: %d\n" , ret); + +return 0 ; + +err_led: +led_classdev_unregister (&drvdata->cdev);
This line looks useless and possibly unsafe, led device was not registered. Also this part of code can be removed if you move next line up.
Quoted 4 lines
drivers/leds/leds-wm831x-status.c new file +4
-0+kfree (drvdata); +err: +return ret; +}
Re: [PATCH 2/2] leds: Add WM831x status LED driver
Quoted 8 lines · Andrey Panin
drivers/leds/leds-wm831x-status.c line 235
Quoted 4 lines · Mark Brown
drivers/leds/leds-wm831x-status.c new file +4
-0+if (res ==NULL ) { +dev_err (&pdev->dev,"No I/O resource\n" ); + ret = -EINVAL ; + goto err;Why not return
-EINVALright here ?
For consistency with the rest of the function which uses this style for unwinding (though I see there's a cut'n'pasted return early on which it'd be nice to clean up).
Quoted 4 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+err_led: + led_classdev_unregister(&drvdata->cdev);This line looks useless and possibly unsafe, led device was not registered.
True.
Quoted 1 line
Also this part of code can be removed if you move next line up.
I'd prefer to keep the unwinding at the end, it makes the initialisation much easier to modify.
Re: [PATCH 2/2] leds: Add WM831x status LED driver
In reply to Mark BrownQuoted 9 lines · Mark Brown
The WM831x devices feature two software controlled status LEDs with hardware assisted blinking.
The device can also autonomously control the LEDs based on a selection of sources. This can be configured at boot time using either platform data or the chip OTP. A sysfs file in the style of that for triggers allowing the control source to be configured at run time. Triggers can't be used here since they can't depend on the implementation details of a specific LED type.
I believe people *were* doing that with triggers in other drivers...?
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: [PATCH 2/2] leds: Add WM831x status LED driver
Quoted 4 lines · Pavel Machek
Quoted 3 lines · Mark Brown
The WM831x devices feature two software controlled status LEDs with hardware assisted blinking.
Quoted 8 lines
Quoted 6 lines
The device can also autonomously control the LEDs based on a selection of sources. This can be configured at boot time using either platform data or the chip OTP. A sysfs file in the style of that for triggers allowing the control source to be configured at run time. Triggers can't be used here since they can't depend on the implementation details of a specific LED type.
I believe people *were* doing that with triggers in other drivers...?
We did talk about allowing the LED triggers to choose whether they were visible to a given LED. At present the mechanism doesn't exist because we've never had a user.
It would just be a case of adding a new optional function to the trigger to say whether it supported a given LED or not and calling that function from led_trigger_show().
I've queued this driver but that would be a nice enhancement.
Cheers,
Richard
Signature · 2 lines
Richard Purdie Intel Open Source Technology Centre
Re: [PATCH 2/2] leds: Add WM831x status LED driver
Hi Richard,
Quoted 18 lines · Richard Purdie
Quoted 4 lines · Pavel Machek
Quoted 3 lines · Mark Brown
The WM831x devices feature two software controlled status LEDs with hardware assisted blinking.
Quoted 8 lines
Quoted 6 lines
The device can also autonomously control the LEDs based on a selection of sources. This can be configured at boot time using either platform data or the chip OTP. A sysfs file in the style of that for triggers allowing the control source to be configured at run time. Triggers can't be used here since they can't depend on the implementation details of a specific LED type.
I believe people *were* doing that with triggers in other drivers...?
We did talk about allowing the LED triggers to choose whether they were visible to a given LED. At present the mechanism doesn't exist because we've never had a user.
Quoted 5 lines
It would just be a case of adding a new optional function to the trigger to say whether it supported a given LED or not and calling that function from
led_trigger_show().I've queued this driver but that would be a nice enhancement.
Unless you're basing your tree on linux-next, you may have issues applying this patch since the wm831x header is not in Linus tree yet. If you have troubles with this patch, let me know and I'll queue it.
Cheers,
Samuel.
Quoted 8 lines
Cheers,
Richard
Signature · 2 lines
Richard Purdie Intel Open Source Technology Centre
Signature · 2 lines
Intel Open Source Technology Centre http://oss.intel.com/
Re: [PATCH 2/2] leds: Add WM831x status LED driver
Quoted 3 lines · Samuel Ortiz
Unless you're basing your tree on linux-next, you may have issues applying this patch since the wm831x header is not in Linus tree yet. If you have troubles with this patch, let me know and I'll queue it.
It's fine, all the leaf drivers depend on the core driver (they need to anyway) so Kconfig won't try to build them until the core driver has been merged.
Re: [PATCH 2/2] leds: Add WM831x status LED driver
Quoted 9 lines · Mark Brown
Quoted 3 lines · Samuel Ortiz
Unless you're basing your tree on linux-next, you may have issues applying this patch since the wm831x header is not in Linus tree yet. If you have troubles with this patch, let me know and I'll queue it.
It's fine, all the leaf drivers depend on the core driver (they need to anyway) so
Kconfigwon't try to build them until the core driver has been merged.
I was thinking about actually being able to apply the patch, but this patch is creating status.h so it should be all fine, yes.
Cheers,
Samuel.
Signature · 2 lines
Intel Open Source Technology Centre http://oss.intel.com/