Commit c3a68ebf authored by Milo(Woogyom) Kim's avatar Milo(Woogyom) Kim Committed by Bryan Wu

leds-lp55xx: use lp55xx_unregister_leds()

 To unregister led class devices and sysfs attributes,
 LP5521 and LP5523 have each driver function.
 This patch makes both drivers simple using common driver function,
 lp55xx_unregister_leds().

 And some unused variables are removed.
Signed-off-by: default avatarMilo(Woogyom) Kim <milo.kim@ti.com>
Signed-off-by: default avatarBryan Wu <cooloney@gmail.com>
parent a96bfa13
...@@ -567,9 +567,6 @@ static ssize_t store_led_pattern(struct device *dev, ...@@ -567,9 +567,6 @@ static ssize_t store_led_pattern(struct device *dev,
return len; return len;
} }
static struct attribute_group lp5521_led_attribute_group = {
};
/* device attributes */ /* device attributes */
static DEVICE_ATTR(engine1_mode, S_IRUGO | S_IWUSR, static DEVICE_ATTR(engine1_mode, S_IRUGO | S_IWUSR,
show_engine1_mode, store_engine1_mode); show_engine1_mode, store_engine1_mode);
...@@ -607,25 +604,9 @@ static int lp5521_register_sysfs(struct i2c_client *client) ...@@ -607,25 +604,9 @@ static int lp5521_register_sysfs(struct i2c_client *client)
static void lp5521_unregister_sysfs(struct i2c_client *client) static void lp5521_unregister_sysfs(struct i2c_client *client)
{ {
struct lp5521_chip *chip = i2c_get_clientdata(client);
struct device *dev = &client->dev; struct device *dev = &client->dev;
int i;
sysfs_remove_group(&dev->kobj, &lp5521_group); sysfs_remove_group(&dev->kobj, &lp5521_group);
for (i = 0; i < chip->num_leds; i++)
sysfs_remove_group(&chip->leds[i].cdev.dev->kobj,
&lp5521_led_attribute_group);
}
static void lp5521_unregister_leds(struct lp5521_chip *chip)
{
int i;
for (i = 0; i < chip->num_leds; i++) {
led_classdev_unregister(&chip->leds[i].cdev);
cancel_work_sync(&chip->leds[i].brightness_work);
}
} }
/* Chip specific configurations */ /* Chip specific configurations */
...@@ -647,7 +628,6 @@ static struct lp55xx_device_config lp5521_cfg = { ...@@ -647,7 +628,6 @@ static struct lp55xx_device_config lp5521_cfg = {
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 *old_chip = NULL;
int ret; int ret;
struct lp55xx_chip *chip; struct lp55xx_chip *chip;
struct lp55xx_led *led; struct lp55xx_led *led;
...@@ -692,7 +672,7 @@ static int lp5521_probe(struct i2c_client *client, ...@@ -692,7 +672,7 @@ static int lp5521_probe(struct i2c_client *client,
} }
return ret; return ret;
fail2: fail2:
lp5521_unregister_leds(old_chip); lp55xx_unregister_leds(led, chip);
err_register_leds: err_register_leds:
lp55xx_deinit_device(chip); lp55xx_deinit_device(chip);
err_init: err_init:
...@@ -708,7 +688,7 @@ static int lp5521_remove(struct i2c_client *client) ...@@ -708,7 +688,7 @@ static int lp5521_remove(struct i2c_client *client)
lp5521_run_led_pattern(PATTERN_OFF, old_chip); lp5521_run_led_pattern(PATTERN_OFF, old_chip);
lp5521_unregister_sysfs(client); lp5521_unregister_sysfs(client);
lp5521_unregister_leds(old_chip); lp55xx_unregister_leds(led, chip);
lp55xx_deinit_device(chip); lp55xx_deinit_device(chip);
return 0; return 0;
......
...@@ -609,9 +609,6 @@ store_mode(1) ...@@ -609,9 +609,6 @@ store_mode(1)
store_mode(2) store_mode(2)
store_mode(3) store_mode(3)
static struct attribute_group lp5523_led_attribute_group = {
};
/* device attributes */ /* device attributes */
static DEVICE_ATTR(engine1_mode, S_IRUGO | S_IWUSR, static DEVICE_ATTR(engine1_mode, S_IRUGO | S_IWUSR,
show_engine1_mode, store_engine1_mode); show_engine1_mode, store_engine1_mode);
...@@ -662,15 +659,9 @@ static int lp5523_register_sysfs(struct i2c_client *client) ...@@ -662,15 +659,9 @@ static int lp5523_register_sysfs(struct i2c_client *client)
static void lp5523_unregister_sysfs(struct i2c_client *client) static void lp5523_unregister_sysfs(struct i2c_client *client)
{ {
struct lp5523_chip *chip = i2c_get_clientdata(client);
struct device *dev = &client->dev; struct device *dev = &client->dev;
int i;
sysfs_remove_group(&dev->kobj, &lp5523_group); sysfs_remove_group(&dev->kobj, &lp5523_group);
for (i = 0; i < chip->num_leds; i++)
sysfs_remove_group(&chip->leds[i].cdev.dev->kobj,
&lp5523_led_attribute_group);
} }
/*--------------------------------------------------------------*/ /*--------------------------------------------------------------*/
...@@ -703,16 +694,6 @@ static void lp5523_set_mode(struct lp5523_engine *engine, u8 mode) ...@@ -703,16 +694,6 @@ static void lp5523_set_mode(struct lp5523_engine *engine, u8 mode)
/*--------------------------------------------------------------*/ /*--------------------------------------------------------------*/
/* Probe, Attach, Remove */ /* Probe, Attach, Remove */
/*--------------------------------------------------------------*/ /*--------------------------------------------------------------*/
static void lp5523_unregister_leds(struct lp5523_chip *chip)
{
int i;
for (i = 0; i < chip->num_leds; i++) {
led_classdev_unregister(&chip->leds[i].cdev);
flush_work(&chip->leds[i].brightness_work);
}
}
/* Chip specific configurations */ /* Chip specific configurations */
static struct lp55xx_device_config lp5523_cfg = { static struct lp55xx_device_config lp5523_cfg = {
.reset = { .reset = {
...@@ -732,7 +713,6 @@ static struct lp55xx_device_config lp5523_cfg = { ...@@ -732,7 +713,6 @@ static struct lp55xx_device_config lp5523_cfg = {
static int lp5523_probe(struct i2c_client *client, static int lp5523_probe(struct i2c_client *client,
const struct i2c_device_id *id) const struct i2c_device_id *id)
{ {
struct lp5523_chip *old_chip = NULL;
int ret; int ret;
struct lp55xx_chip *chip; struct lp55xx_chip *chip;
struct lp55xx_led *led; struct lp55xx_led *led;
...@@ -777,7 +757,7 @@ static int lp5523_probe(struct i2c_client *client, ...@@ -777,7 +757,7 @@ static int lp5523_probe(struct i2c_client *client,
} }
return ret; return ret;
fail2: fail2:
lp5523_unregister_leds(old_chip); lp55xx_unregister_leds(led, chip);
err_register_leds: err_register_leds:
lp55xx_deinit_device(chip); lp55xx_deinit_device(chip);
err_init: err_init:
...@@ -786,7 +766,6 @@ static int lp5523_probe(struct i2c_client *client, ...@@ -786,7 +766,6 @@ static int lp5523_probe(struct i2c_client *client,
static int lp5523_remove(struct i2c_client *client) static int lp5523_remove(struct i2c_client *client)
{ {
struct lp5523_chip *old_chip = i2c_get_clientdata(client);
struct lp55xx_led *led = i2c_get_clientdata(client); struct lp55xx_led *led = i2c_get_clientdata(client);
struct lp55xx_chip *chip = led->chip; struct lp55xx_chip *chip = led->chip;
...@@ -795,7 +774,7 @@ static int lp5523_remove(struct i2c_client *client) ...@@ -795,7 +774,7 @@ static int lp5523_remove(struct i2c_client *client)
lp5523_unregister_sysfs(client); lp5523_unregister_sysfs(client);
lp5523_unregister_leds(old_chip); lp55xx_unregister_leds(led, chip);
lp55xx_deinit_device(chip); lp55xx_deinit_device(chip);
return 0; return 0;
......
...@@ -353,6 +353,22 @@ int lp55xx_register_leds(struct lp55xx_led *led, struct lp55xx_chip *chip) ...@@ -353,6 +353,22 @@ int lp55xx_register_leds(struct lp55xx_led *led, struct lp55xx_chip *chip)
} }
EXPORT_SYMBOL_GPL(lp55xx_register_leds); EXPORT_SYMBOL_GPL(lp55xx_register_leds);
void lp55xx_unregister_leds(struct lp55xx_led *led, struct lp55xx_chip *chip)
{
int i;
struct lp55xx_led *each;
struct kobject *kobj;
for (i = 0; i < chip->num_leds; i++) {
each = led + i;
kobj = &led->cdev.dev->kobj;
sysfs_remove_group(kobj, &lp55xx_led_attr_group);
led_classdev_unregister(&each->cdev);
flush_work(&each->brightness_work);
}
}
EXPORT_SYMBOL_GPL(lp55xx_unregister_leds);
MODULE_AUTHOR("Milo Kim <milo.kim@ti.com>"); MODULE_AUTHOR("Milo Kim <milo.kim@ti.com>");
MODULE_DESCRIPTION("LP55xx Common Driver"); MODULE_DESCRIPTION("LP55xx Common Driver");
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
...@@ -101,4 +101,6 @@ extern void lp55xx_deinit_device(struct lp55xx_chip *chip); ...@@ -101,4 +101,6 @@ extern void lp55xx_deinit_device(struct lp55xx_chip *chip);
/* common LED class device functions */ /* common LED class device functions */
extern int lp55xx_register_leds(struct lp55xx_led *led, extern int lp55xx_register_leds(struct lp55xx_led *led,
struct lp55xx_chip *chip); struct lp55xx_chip *chip);
extern void lp55xx_unregister_leds(struct lp55xx_led *led,
struct lp55xx_chip *chip);
#endif /* _LEDS_LP55XX_COMMON_H */ #endif /* _LEDS_LP55XX_COMMON_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment