Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 358605
b: refs/heads/master
c: 9e9b3db
h: refs/heads/master
i:
  358603: d95ef45
v: v3
  • Loading branch information
Milo(Woogyom) Kim authored and Bryan Wu committed Feb 6, 2013
1 parent 3e74b92 commit ab834aa
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 83 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: 6ce6176263393dd80b9a537c1e1462b8529f240b
refs/heads/master: 9e9b3db1b2f725bacaf1b7e8708a0c78265bde97
43 changes: 3 additions & 40 deletions trunk/drivers/leds/leds-lp5521.c
Original file line number Diff line number Diff line change
Expand Up @@ -738,44 +738,6 @@ static int lp5521_init_led(struct lp5521_led *led,
return 0;
}

static int lp5521_register_leds(struct lp5521_chip *chip)
{
struct lp5521_platform_data *pdata = chip->pdata;
struct i2c_client *client = chip->client;
int i;
int led;
int ret;

/* Initialize leds */
chip->num_channels = pdata->num_channels;
chip->num_leds = 0;
led = 0;
for (i = 0; i < pdata->num_channels; i++) {
/* Do not initialize channels that are not connected */
if (pdata->led_config[i].led_current == 0)
continue;

ret = lp5521_init_led(&chip->leds[led], client, i, pdata);
if (ret) {
dev_err(&client->dev, "error initializing leds\n");
return ret;
}
chip->num_leds++;

chip->leds[led].id = led;
/* Set initial LED current */
lp5521_set_led_current(chip, led,
chip->leds[led].led_current);

INIT_WORK(&(chip->leds[led].brightness_work),
lp5521_led_brightness_work);

led++;
}

return 0;
}

static void lp5521_unregister_leds(struct lp5521_chip *chip)
{
int i;
Expand Down Expand Up @@ -836,9 +798,9 @@ static int lp5521_probe(struct i2c_client *client,

dev_info(&client->dev, "%s programmable led chip found\n", id->name);

ret = lp5521_register_leds(old_chip);
ret = lp55xx_register_leds(led, chip);
if (ret)
goto fail2;
goto err_register_leds;

ret = lp5521_register_sysfs(client);
if (ret) {
Expand All @@ -848,6 +810,7 @@ static int lp5521_probe(struct i2c_client *client,
return ret;
fail2:
lp5521_unregister_leds(old_chip);
err_register_leds:
lp55xx_deinit_device(chip);
err_init:
return ret;
Expand Down
45 changes: 3 additions & 42 deletions trunk/drivers/leds/leds-lp5523.c
Original file line number Diff line number Diff line change
Expand Up @@ -822,46 +822,6 @@ static int lp5523_init_led(struct lp5523_led *led, struct device *dev,
return 0;
}

static int lp5523_register_leds(struct lp5523_chip *chip, const char *name)
{
struct lp5523_platform_data *pdata = chip->pdata;
struct i2c_client *client = chip->client;
int i;
int led;
int ret;

/* Initialize leds */
chip->num_channels = pdata->num_channels;
chip->num_leds = 0;
led = 0;
for (i = 0; i < pdata->num_channels; i++) {
/* Do not initialize channels that are not connected */
if (pdata->led_config[i].led_current == 0)
continue;

INIT_WORK(&chip->leds[led].brightness_work,
lp5523_led_brightness_work);

ret = lp5523_init_led(&chip->leds[led], &client->dev, i, pdata,
name);
if (ret) {
dev_err(&client->dev, "error initializing leds\n");
return ret;
}
chip->num_leds++;

chip->leds[led].id = led;
/* Set LED current */
lp5523_write(client,
LP5523_REG_LED_CURRENT_BASE + chip->leds[led].chan_nr,
chip->leds[led].led_current);

led++;
}

return 0;
}

static void lp5523_unregister_leds(struct lp5523_chip *chip)
{
int i;
Expand Down Expand Up @@ -922,9 +882,9 @@ static int lp5523_probe(struct i2c_client *client,

dev_info(&client->dev, "%s Programmable led chip found\n", id->name);

ret = lp5523_register_leds(old_chip, id->name);
ret = lp55xx_register_leds(led, chip);
if (ret)
goto fail2;
goto err_register_leds;

ret = lp5523_register_sysfs(client);
if (ret) {
Expand All @@ -934,6 +894,7 @@ static int lp5523_probe(struct i2c_client *client,
return ret;
fail2:
lp5523_unregister_leds(old_chip);
err_register_leds:
lp55xx_deinit_device(chip);
err_init:
return ret;
Expand Down
55 changes: 55 additions & 0 deletions trunk/drivers/leds/leds-lp55xx-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ static int lp55xx_post_init_device(struct lp55xx_chip *chip)
return cfg->post_init_device(chip);
}

static int lp55xx_init_led(struct lp55xx_led *led,
struct lp55xx_chip *chip, int chan)
{
return 0;
}

int lp55xx_write(struct lp55xx_chip *chip, u8 reg, u8 val)
{
return i2c_smbus_write_byte_data(chip->cl, reg, val);
Expand Down Expand Up @@ -170,6 +176,55 @@ void lp55xx_deinit_device(struct lp55xx_chip *chip)
}
EXPORT_SYMBOL_GPL(lp55xx_deinit_device);

int lp55xx_register_leds(struct lp55xx_led *led, struct lp55xx_chip *chip)
{
struct lp55xx_platform_data *pdata = chip->pdata;
struct lp55xx_device_config *cfg = chip->cfg;
int num_channels = pdata->num_channels;
struct lp55xx_led *each;
u8 led_current;
int ret;
int i;

if (!cfg->brightness_work_fn) {
dev_err(&chip->cl->dev, "empty brightness configuration\n");
return -EINVAL;
}

for (i = 0; i < num_channels; i++) {

/* do not initialize channels that are not connected */
if (pdata->led_config[i].led_current == 0)
continue;

led_current = pdata->led_config[i].led_current;
each = led + i;
ret = lp55xx_init_led(each, chip, i);
if (ret)
goto err_init_led;

INIT_WORK(&each->brightness_work, cfg->brightness_work_fn);

chip->num_leds++;
each->chip = chip;

/* setting led current at each channel */
if (cfg->set_led_current)
cfg->set_led_current(each, led_current);
}

return 0;

err_init_led:
for (i = 0; i < chip->num_leds; i++) {
each = led + i;
led_classdev_unregister(&each->cdev);
flush_work(&each->brightness_work);
}
return ret;
}
EXPORT_SYMBOL_GPL(lp55xx_register_leds);

MODULE_AUTHOR("Milo Kim <milo.kim@ti.com>");
MODULE_DESCRIPTION("LP55xx Common Driver");
MODULE_LICENSE("GPL");
11 changes: 11 additions & 0 deletions trunk/drivers/leds/leds-lp55xx-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,21 @@ struct lp55xx_reg {
* @reset : Chip specific reset command
* @enable : Chip specific enable command
* @post_init_device : Chip specific initialization code
* @brightness_work_fn : Brightness work function
* @set_led_current : LED current set function
*/
struct lp55xx_device_config {
const struct lp55xx_reg reset;
const struct lp55xx_reg enable;

/* define if the device has specific initialization process */
int (*post_init_device) (struct lp55xx_chip *chip);

/* access brightness register */
void (*brightness_work_fn)(struct work_struct *work);

/* current setting function */
void (*set_led_current) (struct lp55xx_led *led, u8 led_current);
};

/*
Expand Down Expand Up @@ -88,4 +96,7 @@ extern int lp55xx_update_bits(struct lp55xx_chip *chip, u8 reg,
extern int lp55xx_init_device(struct lp55xx_chip *chip);
extern void lp55xx_deinit_device(struct lp55xx_chip *chip);

/* common LED class device functions */
extern int lp55xx_register_leds(struct lp55xx_led *led,
struct lp55xx_chip *chip);
#endif /* _LEDS_LP55XX_COMMON_H */

0 comments on commit ab834aa

Please sign in to comment.