Commit 2b69703f authored by Linus Torvalds's avatar Linus Torvalds
Browse files

Merge branch 'for-next' of git://

Pull LED subsystem updates from Bryan Wu:
 - move LED trigger drivers into a new directory
 - lp55xx common driver updates
 - other led drivers updates and bug fixing

* 'for-next' of git://
  leds: leds-asic3: switch to using SIMPLE_DEV_PM_OPS
  leds: leds-bd2802: add CONFIG_PM_SLEEP to suspend/resume functions
  leds: lp55xx: configure the clock detection
  leds: lp55xx: use common clock framework when external clock is used
  leds: leds-ns2: fix oops at module removal
  leds: leds-pwm: Defer led_pwm_set() if PWM can sleep
  leds: lp55xx: fix the sysfs read operation
  leds: lm355x, lm3642: support camera LED triggers for flash and torch
  leds: add camera LED triggers
  leds: trigger: use inline functions instead of macros
  leds: tca6507: Use of_match_ptr() macro
  leds: wm8350: Complain if we fail to reenable DCDC
  leds: renesas: set gpio_request_one() flags param correctly
  leds: leds-ns2: set devm_gpio_request_one() flags param correctly
  leds: leds-lt3593: set devm_gpio_request_one() flags param correctly
  leds: leds-bd2802: remove erroneous __exit annotation
  leds: atmel-pwm: remove erroneous __exit annotation
  leds: move LED trigger drivers into new subdirectory
  leds: add new LP5562 LED driver
parents 30c67e93 df92d5ff
......@@ -6,6 +6,8 @@ leds-lp5521.txt
- notes on how to use the leds-lp5521 driver.
- notes on how to use the leds-lp5523 driver.
- notes on how to use the leds-lp5562 driver.
- description about lp55xx common driver.
......@@ -81,22 +81,3 @@ static struct lp55xx_platform_data lp5521_platform_data = {
If the current is set to 0 in the platform data, that channel is
disabled and it is not visible in the sysfs.
The 'update_config' : CONFIG register (ADDR 08h)
This value is platform-specific data.
If update_config is not defined, the CONFIG register is set with
(Enable auto-powersave, set charge pump to auto, red to battery)
example of update_config :
#define LP5521_CONFIGS (LP5521_PWM_HF | LP5521_PWRSAVE_EN | \
LP5521_CP_MODE_AUTO | LP5521_R_TO_BATT | \
static struct lp55xx_platform_data lp5521_pdata = {
.led_config = lp5521_led_config,
.num_channels = ARRAY_SIZE(lp5521_led_config),
.clock_mode = LP55XX_CLOCK_INT,
.update_config = LP5521_CONFIGS,
Kernel driver for LP5562
* TI LP5562 LED Driver
Author: Milo(Woogyom) Kim <>
LP5562 can drive up to 4 channels. R/G/B and White.
LEDs can be controlled directly via the led class control interface.
All four channels can be also controlled using the engine micro programs.
LP5562 has the internal program memory for running various LED patterns.
For the details, please refer to 'firmware' section in leds-lp55xx.txt
Device attribute: engine_mux
3 Engines are allocated in LP5562, but the number of channel is 4.
Therefore each channel should be mapped to the engine number.
Value : RGB or W
This attribute is used for programming LED data with the firmware interface.
Unlike the LP5521/LP5523/55231, LP5562 has unique feature for the engine mux,
so additional sysfs is required.
Red ... Engine 1 (fixed)
Green ... Engine 2 (fixed)
Blue ... Engine 3 (fixed)
White ... Engine 1 or 2 or 3 (selective)
How to load the program data using engine_mux
Before loading the LP5562 program data, engine_mux should be written between
the engine selection and loading the firmware.
Engine mux has two different mode, RGB and W.
RGB is used for loading RGB program data, W is used for W program data.
For example, run blinking green channel pattern,
echo 2 > /sys/bus/i2c/devices/xxxx/select_engine # 2 is for green channel
echo "RGB" > /sys/bus/i2c/devices/xxxx/engine_mux # engine mux for RGB
echo 1 > /sys/class/firmware/lp5562/loading
echo "4000600040FF6000" > /sys/class/firmware/lp5562/data
echo 0 > /sys/class/firmware/lp5562/loading
echo 1 > /sys/bus/i2c/devices/xxxx/run_engine
To run a blinking white pattern,
echo 1 or 2 or 3 > /sys/bus/i2c/devices/xxxx/select_engine
echo "W" > /sys/bus/i2c/devices/xxxx/engine_mux
echo 1 > /sys/class/firmware/lp5562/loading
echo "4000600040FF6000" > /sys/class/firmware/lp5562/data
echo 0 > /sys/class/firmware/lp5562/loading
echo 1 > /sys/bus/i2c/devices/xxxx/run_engine
How to load the predefined patterns
Please refer to 'leds-lp55xx.txt"
Setting Current of Each Channel
Like LP5521 and LP5523/55231, LP5562 provides LED current settings.
The 'led_current' and 'max_current' are used.
(Example of Platform data)
To configure the platform specific data, lp55xx_platform_data structure is used.
static struct lp55xx_led_config lp5562_led_config[] = {
.name = "R",
.chan_nr = 0,
.led_current = 20,
.max_current = 40,
.name = "G",
.chan_nr = 1,
.led_current = 20,
.max_current = 40,
.name = "B",
.chan_nr = 2,
.led_current = 20,
.max_current = 40,
.name = "W",
.chan_nr = 3,
.led_current = 20,
.max_current = 40,
static int lp5562_setup(void)
/* setup HW resources */
static void lp5562_release(void)
/* Release HW resources */
static void lp5562_enable(bool state)
/* Control of chip enable signal */
static struct lp55xx_platform_data lp5562_platform_data = {
.led_config = lp5562_led_config,
.num_channels = ARRAY_SIZE(lp5562_led_config),
.setup_resources = lp5562_setup,
.release_resources = lp5562_release,
.enable = lp5562_enable,
If the current is set to 0 in the platform data, that channel is
disabled and it is not visible in the sysfs.
......@@ -5,7 +5,7 @@ Authors: Milo(Woogyom) Kim <>
LP5521, LP5523/55231 have common features as below.
LP5521, LP5523/55231 and LP5562 have common features as below.
Register access via the I2C
Device initialization/deinitialization
......@@ -116,3 +116,47 @@ To support this, 'run_engine' and 'firmware_cb' are configurable in each driver.
run_engine : Control the selected engine
firmware_cb : The callback function after loading the firmware is done.
Chip specific commands for loading and updating program memory.
( Predefined pattern data )
Without the firmware interface, LP55xx driver provides another method for
loading a LED pattern. That is 'predefined' pattern.
A predefined pattern is defined in the platform data and load it(or them)
via the sysfs if needed.
To use the predefined pattern concept, 'patterns' and 'num_patterns' should be
Example of predefined pattern data:
/* mode_1: blinking data */
static const u8 mode_1[] = {
0x40, 0x00, 0x60, 0x00, 0x40, 0xFF, 0x60, 0x00,
/* mode_2: always on */
static const u8 mode_2[] = { 0x40, 0xFF, };
struct lp55xx_predef_pattern board_led_patterns[] = {
.r = mode_1,
.size_r = ARRAY_SIZE(mode_1),
.b = mode_2,
.size_b = ARRAY_SIZE(mode_2),
struct lp55xx_platform_data lp5562_pdata = {
.patterns = board_led_patterns,
.num_patterns = ARRAY_SIZE(board_led_patterns),
Then, mode_1 and mode_2 can be run via through the sysfs.
echo 1 > /sys/bus/i2c/devices/xxxx/led_pattern # red blinking LED pattern
echo 2 > /sys/bus/i2c/devices/xxxx/led_pattern # blue LED always on
To stop running pattern,
echo 0 > /sys/bus/i2c/devices/xxxx/led_pattern
......@@ -194,8 +194,8 @@ config LEDS_LP3944
module will be called leds-lp3944.
tristate "Common Driver for TI/National LP5521 and LP5523/55231"
depends on LEDS_LP5521 || LEDS_LP5523
tristate "Common Driver for TI/National LP5521, LP5523/55231 and LP5562"
depends on LEDS_LP5521 || LEDS_LP5523 || LEDS_LP5562
select FW_LOADER
This option supports common operations for LP5521 and LP5523/55231
......@@ -222,6 +222,16 @@ config LEDS_LP5523
Driver provides direct control via LED class and interface for
programming the engines.
config LEDS_LP5562
tristate "LED Support for TI LP5562 LED driver chip"
depends on LEDS_CLASS && I2C
If you say yes here you get support for TI LP5562 LED driver.
It is 4 channels chip with programmable engines.
Driver provides direct control via LED class and interface for
programming the engines.
config LEDS_LP8788
tristate "LED support for the TI LP8788 PMIC"
depends on LEDS_CLASS
......@@ -469,106 +479,7 @@ config LEDS_BLINKM
This option enables support for the BlinkM RGB LED connected
through I2C. Say Y to enable support for the BlinkM LED.
bool "LED Trigger support"
depends on LEDS_CLASS
This option enables trigger support for the leds class.
These triggers allow kernel events to drive the LEDs and can
be configured via sysfs. If unsure, say Y.
comment "LED Triggers"
tristate "LED Timer Trigger"
depends on LEDS_TRIGGERS
This allows LEDs to be controlled by a programmable timer
via sysfs. Some LED hardware can be programmed to start
blinking the LED without any further software interaction.
For more details read Documentation/leds/leds-class.txt.
If unsure, say Y.
tristate "LED One-shot Trigger"
depends on LEDS_TRIGGERS
This allows LEDs to blink in one-shot pulses with parameters
controlled via sysfs. It's useful to notify the user on
sporadic events, when there are no clear begin and end trap points,
or on dense events, where this blinks the LED at constant rate if
rearmed continuously.
It also shows how to use the led_blink_set_oneshot() function.
If unsure, say Y.
bool "LED IDE Disk Trigger"
depends on IDE_GD_ATA
depends on LEDS_TRIGGERS
This allows LEDs to be controlled by IDE disk activity.
If unsure, say Y.
tristate "LED Heartbeat Trigger"
depends on LEDS_TRIGGERS
This allows LEDs to be controlled by a CPU load average.
The flash frequency is a hyperbolic function of the 1-minute
load average.
If unsure, say Y.
tristate "LED backlight Trigger"
depends on LEDS_TRIGGERS
This allows LEDs to be controlled as a backlight device: they
turn off and on when the display is blanked and unblanked.
If unsure, say N.
bool "LED CPU Trigger"
depends on LEDS_TRIGGERS
This allows LEDs to be controlled by active CPUs. This shows
the active CPUs across an array of LEDs so you can see which
CPUs are active on the system at any given moment.
If unsure, say N.
tristate "LED GPIO Trigger"
depends on LEDS_TRIGGERS
depends on GPIOLIB
This allows LEDs to be controlled by gpio events. It's good
when using gpios as switches and triggering the needed LEDs
from there. One use case is n810's keypad LEDs that could
be triggered by this trigger when user slides up to show
If unsure, say N.
tristate "LED Default ON Trigger"
depends on LEDS_TRIGGERS
This allows LEDs to be initialised in the ON state.
If unsure, say Y.
comment "iptables trigger is under Netfilter config (LED target)"
depends on LEDS_TRIGGERS
tristate "LED Transient Trigger"
depends on LEDS_TRIGGERS
This allows one time activation of a transient state on
GPIO/PWM based hardware.
If unsure, say Y.
source "drivers/leds/trigger/Kconfig"
endif # NEW_LEDS
......@@ -26,6 +26,7 @@ obj-$(CONFIG_LEDS_LP3944) += leds-lp3944.o
obj-$(CONFIG_LEDS_LP55XX_COMMON) += leds-lp55xx-common.o
obj-$(CONFIG_LEDS_LP5521) += leds-lp5521.o
obj-$(CONFIG_LEDS_LP5523) += leds-lp5523.o
obj-$(CONFIG_LEDS_LP5562) += leds-lp5562.o
obj-$(CONFIG_LEDS_LP8788) += leds-lp8788.o
obj-$(CONFIG_LEDS_TCA6507) += leds-tca6507.o
obj-$(CONFIG_LEDS_CLEVO_MAIL) += leds-clevo-mail.o
......@@ -57,12 +58,4 @@ obj-$(CONFIG_LEDS_BLINKM) += leds-blinkm.o
obj-$(CONFIG_LEDS_DAC124S085) += leds-dac124s085.o
# LED Triggers
obj-$(CONFIG_LEDS_TRIGGER_TIMER) += ledtrig-timer.o
obj-$(CONFIG_LEDS_TRIGGER_ONESHOT) += ledtrig-oneshot.o
obj-$(CONFIG_LEDS_TRIGGER_IDE_DISK) += ledtrig-ide-disk.o
obj-$(CONFIG_LEDS_TRIGGER_HEARTBEAT) += ledtrig-heartbeat.o
obj-$(CONFIG_LEDS_TRIGGER_BACKLIGHT) += ledtrig-backlight.o
obj-$(CONFIG_LEDS_TRIGGER_GPIO) += ledtrig-gpio.o
obj-$(CONFIG_LEDS_TRIGGER_CPU) += ledtrig-cpu.o
obj-$(CONFIG_LEDS_TRIGGER_DEFAULT_ON) += ledtrig-default-on.o
obj-$(CONFIG_LEDS_TRIGGER_TRANSIENT) += ledtrig-transient.o
obj-$(CONFIG_LEDS_TRIGGERS) += trigger/
......@@ -134,6 +134,7 @@ static int asic3_led_remove(struct platform_device *pdev)
return mfd_cell_disable(pdev);
static int asic3_led_suspend(struct device *dev)
struct platform_device *pdev = to_platform_device(dev);
......@@ -159,11 +160,9 @@ static int asic3_led_resume(struct device *dev)
return ret;
static const struct dev_pm_ops asic3_led_pm_ops = {
.suspend = asic3_led_suspend,
.resume = asic3_led_resume,
static SIMPLE_DEV_PM_OPS(asic3_led_pm_ops, asic3_led_suspend, asic3_led_resume);
static struct platform_driver asic3_led_driver = {
.probe = asic3_led_probe,
......@@ -113,7 +113,7 @@ static int pwmled_probe(struct platform_device *pdev)
return status;
static int __exit pwmled_remove(struct platform_device *pdev)
static int pwmled_remove(struct platform_device *pdev)
const struct gpio_led_platform_data *pdata;
struct pwmled *leds;
......@@ -140,7 +140,7 @@ static struct platform_driver pwmled_driver = {
/* REVISIT add suspend() and resume() methods */
.probe = pwmled_probe,
.remove = __exit_p(pwmled_remove),
.remove = pwmled_remove,
......@@ -732,7 +732,7 @@ static int bd2802_probe(struct i2c_client *client,
return ret;
static int __exit bd2802_remove(struct i2c_client *client)
static int bd2802_remove(struct i2c_client *client)
struct bd2802_led *led = i2c_get_clientdata(client);
int i;
......@@ -747,8 +747,7 @@ static int __exit bd2802_remove(struct i2c_client *client)
return 0;
#ifdef CONFIG_PM
static void bd2802_restore_state(struct bd2802_led *led)
int i;
......@@ -785,12 +784,9 @@ static int bd2802_resume(struct device *dev)
return 0;
static SIMPLE_DEV_PM_OPS(bd2802_pm, bd2802_suspend, bd2802_resume);
#define BD2802_PM (&bd2802_pm)
#else /* CONFIG_PM */
#define BD2802_PM NULL
static const struct i2c_device_id bd2802_id[] = {
{ "BD2802", 0 },
......@@ -801,10 +797,10 @@ MODULE_DEVICE_TABLE(i2c, bd2802_id);
static struct i2c_driver bd2802_i2c_driver = {
.driver = {
.name = "BD2802",
.pm = BD2802_PM,
.pm = &bd2802_pm,
.probe = bd2802_probe,
.remove = __exit_p(bd2802_remove),
.remove = bd2802_remove,
.id_table = bd2802_id,
......@@ -477,6 +477,7 @@ static int lm355x_probe(struct i2c_client *client,
chip-> = "flash";
chip->cdev_flash.max_brightness = 16;
chip->cdev_flash.brightness_set = lm355x_strobe_brightness_set;
chip->cdev_flash.default_trigger = "flash";
err = led_classdev_register((struct device *)
&client->dev, &chip->cdev_flash);
if (err < 0)
......@@ -486,6 +487,7 @@ static int lm355x_probe(struct i2c_client *client,
chip-> = "torch";
chip->cdev_torch.max_brightness = 8;
chip->cdev_torch.brightness_set = lm355x_torch_brightness_set;
chip->cdev_torch.default_trigger = "torch";
err = led_classdev_register((struct device *)
&client->dev, &chip->cdev_torch);
if (err < 0)
......@@ -363,6 +363,7 @@ static int lm3642_probe(struct i2c_client *client,
chip-> = "flash";
chip->cdev_flash.max_brightness = 16;
chip->cdev_flash.brightness_set = lm3642_strobe_brightness_set;
chip->cdev_flash.default_trigger = "flash";
err = led_classdev_register((struct device *)
&client->dev, &chip->cdev_flash);
if (err < 0) {
......@@ -380,6 +381,7 @@ static int lm3642_probe(struct i2c_client *client,
chip-> = "torch";
chip->cdev_torch.max_brightness = 8;
chip->cdev_torch.brightness_set = lm3642_torch_brightness_set;
chip->cdev_torch.default_trigger = "torch";
err = led_classdev_register((struct device *)
&client->dev, &chip->cdev_torch);
if (err < 0) {
......@@ -68,6 +68,18 @@
/* CONFIG register */
#define LP5521_PWM_HF 0x40 /* PWM: 0 = 256Hz, 1 = 558Hz */
#define LP5521_PWRSAVE_EN 0x20 /* 1 = Power save mode */
#define LP5521_CP_MODE_OFF 0 /* Charge pump (CP) off */
#define LP5521_CP_MODE_BYPASS 8 /* CP forced to bypass mode */
#define LP5521_CP_MODE_1X5 0x10 /* CP forced to 1.5x mode */
#define LP5521_CP_MODE_AUTO 0x18 /* Automatic mode selection */
#define LP5521_R_TO_BATT 0x04 /* R out: 0 = CP, 1 = Vbat */
#define LP5521_CLK_INT 0x01 /* Internal clock */
#define LP5521_DEFAULT_CFG \
/* Status */
#define LP5521_EXT_CLK_USED 0x08
......@@ -296,8 +308,11 @@ static int lp5521_post_init_device(struct lp55xx_chip *chip)
/* Set all PWMs to direct control mode */
ret = lp55xx_write(chip, LP5521_REG_OP_MODE, LP5521_CMD_DIRECT);
val = chip->pdata->update_config ?
/* Update configuration for the clock setting */
val = LP5521_DEFAULT_CFG;
if (!lp55xx_is_extclk_used(chip))
val |= LP5521_CLK_INT;
ret = lp55xx_write(chip, LP5521_REG_CONFIG, val);
if (ret)
return ret;
......@@ -360,7 +375,8 @@ static ssize_t lp5521_selftest(struct device *dev,
ret = lp5521_run_selftest(chip, buf);
return sprintf(buf, "%s\n", ret ? "FAIL" : "OK");
return scnprintf(buf, PAGE_SIZE, "%s\n", ret ? "FAIL" : "OK");
/* device attributes */
* LP5562 LED driver
* Copyright (C) 2013 Texas Instruments
* Author: Milo(Woogyom) Kim <>
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
#include <linux/delay.h>
#include <linux/firmware.h>
#include <linux/i2c.h>
#include <linux/init.h>
#include <linux/leds.h>
#include <linux/module.h>
#include <linux/mutex.h>
#include <linux/platform_data/leds-lp55xx.h>
#include <linux/slab.h>
#include "leds-lp55xx-common.h"
#define LP5562_PROGRAM_LENGTH 32
#define LP5562_MAX_LEDS 4
/* ENABLE Register 00h */
#define LP5562_REG_ENABLE 0x00
#define LP5562_EXEC_ENG1_M 0x30
#define LP5562_EXEC_ENG2_M 0x0C
#define LP5562_EXEC_ENG3_M 0x03
#define LP5562_EXEC_M 0x3F
#define LP5562_MASTER_ENABLE 0x40 /* Chip master enable */
#define LP5562_LOGARITHMIC_PWM 0x80 /* Logarithmic PWM adjustment */
#define LP5562_EXEC_RUN 0x2A
#define LP5562_ENABLE_DEFAULT \
/* OPMODE Register 01h */
#define LP5562_REG_OP_MODE 0x01
#define LP5562_MODE_ENG1_M 0x30
#define LP5562_MODE_ENG2_M 0x0C
#define LP5562_MODE_ENG3_M 0x03
#define LP5562_LOAD_ENG1 0x10
#define LP5562_LOAD_ENG2 0x04
#define LP5562_LOAD_ENG3 0x01
#define LP5562_RUN_ENG1 0x20
#define LP5562_RUN_ENG2 0x08
#define LP5562_RUN_ENG3 0x02
#define LP5562_ENG1_IS_LOADING(mode) \
((mode & LP5562_MODE_ENG1_M) == LP5562_LOAD_ENG1)
#define LP5562_ENG2_IS_LOADING(mode) \
((mode & LP5562_MODE_ENG2_M) == LP5562_LOAD_ENG2)
#define LP5562_ENG3_IS_LOADING(mode) \
((mode & LP5562_MODE_ENG3_M) == LP5562_LOAD_ENG3)
/* BRIGHTNESS Registers */
#define LP5562_REG_R_PWM 0x04
#define LP5562_REG_G_PWM 0x03
#define LP5562_REG_B_PWM 0x02
#define LP5562_REG_W_PWM 0x0E
/* CURRENT Registers */
#define LP5562_REG_R_CURRENT 0x07
#define LP5562_REG_G_CURRENT 0x06
#define LP5562_REG_B_CURRENT 0x05
#define LP5562_REG_W_CURRENT 0x0F
/* CONFIG Register 08h */
#define LP5562_REG_CONFIG 0x08
#define LP5562_PWM_HF 0x40
#define LP5562_PWRSAVE_EN 0x20
#define LP5562_CLK_INT 0x01 /* Internal clock */
#define LP5562_DEFAULT_CFG (LP5562_PWM_HF | LP5562_PWRSAVE_EN)
/* RESET Register 0Dh */
#define LP5562_REG_RESET 0x0D
#define LP5562_RESET 0xFF
/* PROGRAM ENGINE Registers */
#define LP5562_REG_PROG_MEM_ENG1 0x10
#define LP5562_REG_PROG_MEM_ENG2 0x30
#define LP5562_REG_PROG_MEM_ENG3 0x50
/* LEDMAP Register 70h */
#define LP5562_REG_ENG_SEL 0x70
#define LP5562_ENG_SEL_PWM 0
#define LP5562_ENG_FOR_RGB_M 0x3F
#define LP5562_ENG_SEL_RGB 0x1B /* R:ENG1, G:ENG2, B:ENG3 */
#define LP5562_ENG_FOR_W_M 0xC0
#define LP5562_ENG1_FOR_W 0x40 /* W:ENG1 */
#define LP5562_ENG2_FOR_W 0x80 /* W:ENG2 */
#define LP5562_ENG3_FOR_W 0xC0 /* W:ENG3 */
/* Program Commands */
#define LP5562_CMD_DISABLE 0x00
#define LP5562_CMD_LOAD 0x15
#define LP5562_CMD_RUN 0x2A
#define LP5562_CMD_DIRECT 0x3F
#define LP5562_PATTERN_OFF 0
static inline void lp5562_wait_opmode_done(void)
/* operation mode change needs to be longer than 153 us */
usleep_range(200, 300);
static inline void lp5562_wait_enable_done(void)