mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-09-04 20:19:47 +08:00
leds-lp55xx: clean up init leds in lp5521/5523
To make LED initialization code simple, new function, _register_leds() is added at each driver. This patch is a preceding step for lp55xx common driver architecture. Signed-off-by: Milo(Woogyom) Kim <milo.kim@ti.com> Signed-off-by: Bryan Wu <cooloney@gmail.com>
This commit is contained in:
parent
1a9914855d
commit
f652480802
@ -799,12 +799,50 @@ static int lp5521_init_led(struct lp5521_led *led,
|
|||||||
return 0;
|
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 int lp5521_probe(struct i2c_client *client,
|
static int lp5521_probe(struct i2c_client *client,
|
||||||
const struct i2c_device_id *id)
|
const struct i2c_device_id *id)
|
||||||
{
|
{
|
||||||
struct lp5521_chip *chip;
|
struct lp5521_chip *chip;
|
||||||
struct lp5521_platform_data *pdata;
|
struct lp5521_platform_data *pdata;
|
||||||
int ret, i, led;
|
int ret, i;
|
||||||
|
|
||||||
chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL);
|
chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL);
|
||||||
if (!chip)
|
if (!chip)
|
||||||
@ -836,32 +874,9 @@ static int lp5521_probe(struct i2c_client *client,
|
|||||||
goto fail1;
|
goto fail1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Initialize leds */
|
ret = lp5521_register_leds(chip);
|
||||||
chip->num_channels = pdata->num_channels;
|
if (ret)
|
||||||
chip->num_leds = 0;
|
goto fail2;
|
||||||
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");
|
|
||||||
goto fail2;
|
|
||||||
}
|
|
||||||
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++;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = lp5521_register_sysfs(client);
|
ret = lp5521_register_sysfs(client);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
|
@ -896,6 +896,46 @@ static int lp5523_init_led(struct lp5523_led *led, struct device *dev,
|
|||||||
return 0;
|
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 int lp5523_init_device(struct lp5523_chip *chip)
|
static int lp5523_init_device(struct lp5523_chip *chip)
|
||||||
{
|
{
|
||||||
struct lp5523_platform_data *pdata = chip->pdata;
|
struct lp5523_platform_data *pdata = chip->pdata;
|
||||||
@ -938,7 +978,7 @@ static int lp5523_probe(struct i2c_client *client,
|
|||||||
{
|
{
|
||||||
struct lp5523_chip *chip;
|
struct lp5523_chip *chip;
|
||||||
struct lp5523_platform_data *pdata;
|
struct lp5523_platform_data *pdata;
|
||||||
int ret, i, led;
|
int ret, i;
|
||||||
|
|
||||||
chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL);
|
chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL);
|
||||||
if (!chip)
|
if (!chip)
|
||||||
@ -978,34 +1018,9 @@ static int lp5523_probe(struct i2c_client *client,
|
|||||||
goto fail1;
|
goto fail1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Initialize leds */
|
ret = lp5523_register_leds(chip, id->name);
|
||||||
chip->num_channels = pdata->num_channels;
|
if (ret)
|
||||||
chip->num_leds = 0;
|
goto fail2;
|
||||||
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,
|
|
||||||
id->name);
|
|
||||||
if (ret) {
|
|
||||||
dev_err(&client->dev, "error initializing leds\n");
|
|
||||||
goto fail2;
|
|
||||||
}
|
|
||||||
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++;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = lp5523_register_sysfs(client);
|
ret = lp5523_register_sysfs(client);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
|
Loading…
Reference in New Issue
Block a user