Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 295185
b: refs/heads/master
c: 011af7b
h: refs/heads/master
i:
  295183: db5d1c2
v: v3
  • Loading branch information
Kim, Milo authored and Linus Torvalds committed Mar 23, 2012
1 parent 4d5be91 commit 3b9af25
Show file tree
Hide file tree
Showing 4 changed files with 151 additions and 2 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 3b49aacd0e56d5bf1b511f6554f17cd65eb8da64
refs/heads/master: 011af7bc7cd188a0310e2d26cdc2cc5d90148b0c
38 changes: 38 additions & 0 deletions trunk/Documentation/leds/leds-lp5521.txt
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,41 @@ static struct lp5521_platform_data lp5521_pdata = {
.clock_mode = LP5521_CLOCK_INT,
.update_config = LP5521_CONFIGS,
};

LED patterns : LP5521 has autonomous operation without external control.
Pattern data can be defined in the platform data.

example of led pattern data :

/* RGB(50,5,0) 500ms on, 500ms off, infinite loop */
static u8 pattern_red[] = {
0x40, 0x32, 0x60, 0x00, 0x40, 0x00, 0x60, 0x00,
};

static u8 pattern_green[] = {
0x40, 0x05, 0x60, 0x00, 0x40, 0x00, 0x60, 0x00,
};

static struct lp5521_led_pattern board_led_patterns[] = {
{
.r = pattern_red,
.g = pattern_green,
.size_r = ARRAY_SIZE(pattern_red),
.size_g = ARRAY_SIZE(pattern_green),
},
};

static struct lp5521_platform_data lp5521_platform_data = {
.led_config = lp5521_led_config,
.num_channels = ARRAY_SIZE(lp5521_led_config),
.clock_mode = LP5521_CLOCK_EXT,
.patterns = board_led_patterns,
.num_patterns = ARRAY_SIZE(board_led_patterns),
};

Then predefined led pattern(s) can be executed via the sysfs.
To start the pattern #1,
# echo 1 > /sys/bus/i2c/devices/xxxx/led_pattern
(xxxx : i2c bus & slave address)
To end the pattern,
# echo 0 > /sys/bus/i2c/devices/xxxx/led_pattern
102 changes: 101 additions & 1 deletion trunk/drivers/leds/leds-lp5521.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@
/* default R channel current register value */
#define LP5521_REG_R_CURR_DEFAULT 0xAF

/* Pattern Mode */
#define PATTERN_OFF 0

struct lp5521_engine {
int id;
u8 mode;
Expand Down Expand Up @@ -493,7 +496,7 @@ static ssize_t store_current(struct device *dev,
ssize_t ret;
unsigned long curr;

if (strict_strtoul(buf, 0, &curr))
if (kstrtoul(buf, 0, &curr))
return -EINVAL;

if (curr > led->max_current)
Expand Down Expand Up @@ -525,6 +528,100 @@ static ssize_t lp5521_selftest(struct device *dev,
return sprintf(buf, "%s\n", ret ? "FAIL" : "OK");
}

static void lp5521_clear_program_memory(struct i2c_client *cl)
{
int i;
u8 rgb_mem[] = {
LP5521_REG_R_PROG_MEM,
LP5521_REG_G_PROG_MEM,
LP5521_REG_B_PROG_MEM,
};

for (i = 0; i < ARRAY_SIZE(rgb_mem); i++) {
lp5521_write(cl, rgb_mem[i], 0);
lp5521_write(cl, rgb_mem[i] + 1, 0);
}
}

static void lp5521_write_program_memory(struct i2c_client *cl,
u8 base, u8 *rgb, int size)
{
int i;

if (!rgb || size <= 0)
return;

for (i = 0; i < size; i++)
lp5521_write(cl, base + i, *(rgb + i));

lp5521_write(cl, base + i, 0);
lp5521_write(cl, base + i + 1, 0);
}

static inline struct lp5521_led_pattern *lp5521_get_pattern
(struct lp5521_chip *chip, u8 offset)
{
struct lp5521_led_pattern *ptn;
ptn = chip->pdata->patterns + (offset - 1);
return ptn;
}

static void lp5521_run_led_pattern(int mode, struct lp5521_chip *chip)
{
struct lp5521_led_pattern *ptn;
struct i2c_client *cl = chip->client;
int num_patterns = chip->pdata->num_patterns;

if (mode > num_patterns || !(chip->pdata->patterns))
return;

if (mode == PATTERN_OFF) {
lp5521_write(cl, LP5521_REG_ENABLE,
LP5521_MASTER_ENABLE | LP5521_LOGARITHMIC_PWM);
usleep_range(1000, 2000);
lp5521_write(cl, LP5521_REG_OP_MODE, LP5521_CMD_DIRECT);
} else {
ptn = lp5521_get_pattern(chip, mode);
if (!ptn)
return;

lp5521_write(cl, LP5521_REG_OP_MODE, LP5521_CMD_LOAD);
usleep_range(1000, 2000);

lp5521_clear_program_memory(cl);

lp5521_write_program_memory(cl, LP5521_REG_R_PROG_MEM,
ptn->r, ptn->size_r);
lp5521_write_program_memory(cl, LP5521_REG_G_PROG_MEM,
ptn->g, ptn->size_g);
lp5521_write_program_memory(cl, LP5521_REG_B_PROG_MEM,
ptn->b, ptn->size_b);

lp5521_write(cl, LP5521_REG_OP_MODE, LP5521_CMD_RUN);
usleep_range(1000, 2000);
lp5521_write(cl, LP5521_REG_ENABLE,
LP5521_MASTER_ENABLE | LP5521_LOGARITHMIC_PWM |
LP5521_EXEC_RUN);
}
}

static ssize_t store_led_pattern(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t len)
{
struct lp5521_chip *chip = i2c_get_clientdata(to_i2c_client(dev));
unsigned long val;
int ret;

ret = strict_strtoul(buf, 16, &val);
if (ret)
return ret;

lp5521_run_led_pattern(val, chip);

return len;
}

/* led class device attributes */
static DEVICE_ATTR(led_current, S_IRUGO | S_IWUSR, show_current, store_current);
static DEVICE_ATTR(max_current, S_IRUGO , show_max_current, NULL);
Expand All @@ -550,6 +647,7 @@ static DEVICE_ATTR(engine1_load, S_IWUSR, NULL, store_engine1_load);
static DEVICE_ATTR(engine2_load, S_IWUSR, NULL, store_engine2_load);
static DEVICE_ATTR(engine3_load, S_IWUSR, NULL, store_engine3_load);
static DEVICE_ATTR(selftest, S_IRUGO, lp5521_selftest, NULL);
static DEVICE_ATTR(led_pattern, S_IWUSR, NULL, store_led_pattern);

static struct attribute *lp5521_attributes[] = {
&dev_attr_engine1_mode.attr,
Expand All @@ -559,6 +657,7 @@ static struct attribute *lp5521_attributes[] = {
&dev_attr_engine1_load.attr,
&dev_attr_engine2_load.attr,
&dev_attr_engine3_load.attr,
&dev_attr_led_pattern.attr,
NULL
};

Expand Down Expand Up @@ -761,6 +860,7 @@ static int __devexit lp5521_remove(struct i2c_client *client)
struct lp5521_chip *chip = i2c_get_clientdata(client);
int i;

lp5521_run_led_pattern(PATTERN_OFF, chip);
lp5521_unregister_sysfs(client);

for (i = 0; i < chip->num_leds; i++) {
Expand Down
11 changes: 11 additions & 0 deletions trunk/include/linux/leds-lp5521.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ struct lp5521_led_config {
u8 max_current;
};

struct lp5521_led_pattern {
u8 *r;
u8 *g;
u8 *b;
u8 size_r;
u8 size_g;
u8 size_b;
};

#define LP5521_CLOCK_AUTO 0
#define LP5521_CLOCK_INT 1
#define LP5521_CLOCK_EXT 2
Expand All @@ -57,6 +66,8 @@ struct lp5521_platform_data {
void (*enable)(bool state);
const char *label;
u8 update_config;
struct lp5521_led_pattern *patterns;
int num_patterns;
};

#endif /* __LINUX_LP5521_H */

0 comments on commit 3b9af25

Please sign in to comment.