Skip to content

Commit c93d08f

Browse files
Milo(Woogyom) Kimcooloney
Milo(Woogyom) Kim
authored andcommitted
leds-lp55xx: add new common driver for lp5521/5523
This patch supports basic common driver code for LP5521, LP5523/55231 devices. ( Driver Structure Data ) lp55xx_led and lp55xx_chip In lp55xx common driver, two different data structure is used. o lp55xx_led control multi output LED channels such as led current, channel index. o lp55xx_chip general chip control such like the I2C and platform data. For example, LP5521 has maximum 3 LED channels. LP5523/55231 has 9 output channels. lp55xx_chip for LP5521 ... lp55xx_led #1 lp55xx_led raspberrypi#2 lp55xx_led raspberrypi#3 lp55xx_chip for LP5523 ... lp55xx_led #1 lp55xx_led raspberrypi#2 . . lp55xx_led raspberrypi#9 ( Platform Data ) LP5521 and LP5523/55231 have own specific platform data. However, this data can be handled with just one platform data structure. The lp55xx platform data is declared in the header. This structure is derived from leds-lp5521.h and leds-lp5523.h Signed-off-by: Milo(Woogyom) Kim <[email protected]> Signed-off-by: Bryan Wu <[email protected]>
1 parent f6c64c6 commit c93d08f

File tree

5 files changed

+217
-0
lines changed

5 files changed

+217
-0
lines changed

drivers/leds/Kconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,17 @@ config LEDS_LP3944
193193
To compile this driver as a module, choose M here: the
194194
module will be called leds-lp3944.
195195

196+
config LEDS_LP55XX_COMMON
197+
tristate "Common Driver for TI/National LP5521 and LP5523/55231"
198+
depends on LEDS_LP5521 || LEDS_LP5523
199+
help
200+
This option supports common operations for LP5521 and LP5523/55231
201+
devices.
202+
196203
config LEDS_LP5521
197204
tristate "LED Support for N.S. LP5521 LED driver chip"
198205
depends on LEDS_CLASS && I2C
206+
select LEDS_LP55XX_COMMON
199207
help
200208
If you say yes here you get support for the National Semiconductor
201209
LP5521 LED driver. It is 3 channel chip with programmable engines.
@@ -205,6 +213,7 @@ config LEDS_LP5521
205213
config LEDS_LP5523
206214
tristate "LED Support for TI/National LP5523/55231 LED driver chip"
207215
depends on LEDS_CLASS && I2C
216+
select LEDS_LP55XX_COMMON
208217
help
209218
If you say yes here you get support for TI/National Semiconductor
210219
LP5523/55231 LED driver.

drivers/leds/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ obj-$(CONFIG_LEDS_PCA9532) += leds-pca9532.o
2323
obj-$(CONFIG_LEDS_GPIO_REGISTER) += leds-gpio-register.o
2424
obj-$(CONFIG_LEDS_GPIO) += leds-gpio.o
2525
obj-$(CONFIG_LEDS_LP3944) += leds-lp3944.o
26+
obj-$(CONFIG_LEDS_LP55XX_COMMON) += leds-lp55xx-common.o
2627
obj-$(CONFIG_LEDS_LP5521) += leds-lp5521.o
2728
obj-$(CONFIG_LEDS_LP5523) += leds-lp5523.o
2829
obj-$(CONFIG_LEDS_LP8788) += leds-lp8788.o

drivers/leds/leds-lp55xx-common.c

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* LP5521/LP5523/LP55231 Common Driver
3+
*
4+
* Copyright 2012 Texas Instruments
5+
*
6+
* Author: Milo(Woogyom) Kim <[email protected]>
7+
*
8+
* This program is free software; you can redistribute it and/or modify
9+
* it under the terms of the GNU General Public License version 2 as
10+
* published by the Free Software Foundation.
11+
*
12+
* Derived from leds-lp5521.c, leds-lp5523.c
13+
*/
14+
15+
#include <linux/i2c.h>
16+
#include <linux/leds.h>
17+
#include <linux/module.h>
18+
#include <linux/platform_data/leds-lp55xx.h>
19+
20+
#include "leds-lp55xx-common.h"
21+
22+
int lp55xx_write(struct lp55xx_chip *chip, u8 reg, u8 val)
23+
{
24+
return i2c_smbus_write_byte_data(chip->cl, reg, val);
25+
}
26+
EXPORT_SYMBOL_GPL(lp55xx_write);
27+
28+
int lp55xx_read(struct lp55xx_chip *chip, u8 reg, u8 *val)
29+
{
30+
s32 ret;
31+
32+
ret = i2c_smbus_read_byte_data(chip->cl, reg);
33+
if (ret < 0)
34+
return ret;
35+
36+
*val = ret;
37+
return 0;
38+
}
39+
EXPORT_SYMBOL_GPL(lp55xx_read);
40+
41+
int lp55xx_update_bits(struct lp55xx_chip *chip, u8 reg, u8 mask, u8 val)
42+
{
43+
int ret;
44+
u8 tmp;
45+
46+
ret = lp55xx_read(chip, reg, &tmp);
47+
if (ret)
48+
return ret;
49+
50+
tmp &= ~mask;
51+
tmp |= val & mask;
52+
53+
return lp55xx_write(chip, reg, tmp);
54+
}
55+
EXPORT_SYMBOL_GPL(lp55xx_update_bits);
56+
57+
MODULE_AUTHOR("Milo Kim <[email protected]>");
58+
MODULE_DESCRIPTION("LP55xx Common Driver");
59+
MODULE_LICENSE("GPL");

drivers/leds/leds-lp55xx-common.h

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* LP55XX Common Driver Header
3+
*
4+
* Copyright (C) 2012 Texas Instruments
5+
*
6+
* Author: Milo(Woogyom) Kim <[email protected]>
7+
*
8+
* This program is free software; you can redistribute it and/or
9+
* modify it under the terms of the GNU General Public License
10+
* version 2 as published by the Free Software Foundation.
11+
*
12+
* Derived from leds-lp5521.c, leds-lp5523.c
13+
*/
14+
15+
#ifndef _LEDS_LP55XX_COMMON_H
16+
#define _LEDS_LP55XX_COMMON_H
17+
18+
struct lp55xx_led;
19+
struct lp55xx_chip;
20+
21+
/*
22+
* struct lp55xx_chip
23+
* @cl : I2C communication for access registers
24+
* @pdata : Platform specific data
25+
* @lock : Lock for user-space interface
26+
* @num_leds : Number of registered LEDs
27+
*/
28+
struct lp55xx_chip {
29+
struct i2c_client *cl;
30+
struct lp55xx_platform_data *pdata;
31+
struct mutex lock; /* lock for user-space interface */
32+
int num_leds;
33+
};
34+
35+
/*
36+
* struct lp55xx_led
37+
* @chan_nr : Channel number
38+
* @cdev : LED class device
39+
* @led_current : Current setting at each led channel
40+
* @max_current : Maximun current at each led channel
41+
* @brightness_work : Workqueue for brightness control
42+
* @brightness : Brightness value
43+
* @chip : The lp55xx chip data
44+
*/
45+
struct lp55xx_led {
46+
int chan_nr;
47+
struct led_classdev cdev;
48+
u8 led_current;
49+
u8 max_current;
50+
struct work_struct brightness_work;
51+
u8 brightness;
52+
struct lp55xx_chip *chip;
53+
};
54+
55+
/* register access */
56+
extern int lp55xx_write(struct lp55xx_chip *chip, u8 reg, u8 val);
57+
extern int lp55xx_read(struct lp55xx_chip *chip, u8 reg, u8 *val);
58+
extern int lp55xx_update_bits(struct lp55xx_chip *chip, u8 reg,
59+
u8 mask, u8 val);
60+
61+
#endif /* _LEDS_LP55XX_COMMON_H */
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
* LP55XX Platform Data Header
3+
*
4+
* Copyright (C) 2012 Texas Instruments
5+
*
6+
* Author: Milo(Woogyom) Kim <[email protected]>
7+
*
8+
* This program is free software; you can redistribute it and/or
9+
* modify it under the terms of the GNU General Public License
10+
* version 2 as published by the Free Software Foundation.
11+
*
12+
* Derived from leds-lp5521.h, leds-lp5523.h
13+
*/
14+
15+
#ifndef _LEDS_LP55XX_H
16+
#define _LEDS_LP55XX_H
17+
18+
/* Clock configuration */
19+
#define LP55XX_CLOCK_AUTO 0
20+
#define LP55XX_CLOCK_INT 1
21+
#define LP55XX_CLOCK_EXT 2
22+
23+
/* Bits in LP5521 CONFIG register. 'update_config' in lp55xx_platform_data */
24+
#define LP5521_PWM_HF 0x40 /* PWM: 0 = 256Hz, 1 = 558Hz */
25+
#define LP5521_PWRSAVE_EN 0x20 /* 1 = Power save mode */
26+
#define LP5521_CP_MODE_OFF 0 /* Charge pump (CP) off */
27+
#define LP5521_CP_MODE_BYPASS 8 /* CP forced to bypass mode */
28+
#define LP5521_CP_MODE_1X5 0x10 /* CP forced to 1.5x mode */
29+
#define LP5521_CP_MODE_AUTO 0x18 /* Automatic mode selection */
30+
#define LP5521_R_TO_BATT 4 /* R out: 0 = CP, 1 = Vbat */
31+
#define LP5521_CLK_SRC_EXT 0 /* Ext-clk source (CLK_32K) */
32+
#define LP5521_CLK_INT 1 /* Internal clock */
33+
#define LP5521_CLK_AUTO 2 /* Automatic clock selection */
34+
35+
struct lp55xx_led_config {
36+
const char *name;
37+
u8 chan_nr;
38+
u8 led_current; /* mA x10, 0 if led is not connected */
39+
u8 max_current;
40+
};
41+
42+
struct lp55xx_predef_pattern {
43+
u8 *r;
44+
u8 *g;
45+
u8 *b;
46+
u8 size_r;
47+
u8 size_g;
48+
u8 size_b;
49+
};
50+
51+
/*
52+
* struct lp55xx_platform_data
53+
* @led_config : Configurable led class device
54+
* @num_channels : Number of LED channels
55+
* @label : Used for naming LEDs
56+
* @clock_mode : Input clock mode. LP55XX_CLOCK_AUTO or _INT or _EXT
57+
* @setup_resources : Platform specific function before enabling the chip
58+
* @release_resources : Platform specific function after disabling the chip
59+
* @enable : EN pin control by platform side
60+
* @patterns : Predefined pattern data for RGB channels
61+
* @num_patterns : Number of patterns
62+
* @update_config : Value of CONFIG register
63+
*/
64+
struct lp55xx_platform_data {
65+
66+
/* LED channel configuration */
67+
struct lp55xx_led_config *led_config;
68+
u8 num_channels;
69+
const char *label;
70+
71+
/* Clock configuration */
72+
u8 clock_mode;
73+
74+
/* Platform specific functions */
75+
int (*setup_resources)(void);
76+
void (*release_resources)(void);
77+
void (*enable)(bool state);
78+
79+
/* Predefined pattern data */
80+
struct lp55xx_predef_pattern *patterns;
81+
unsigned int num_patterns;
82+
83+
/* _CONFIG register */
84+
u8 update_config;
85+
};
86+
87+
#endif /* _LEDS_LP55XX_H */

0 commit comments

Comments
 (0)