aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMilo(Woogyom) Kim <milo.kim@ti.com>2013-02-05 05:11:18 -0500
committerBryan Wu <cooloney@gmail.com>2013-02-06 18:59:28 -0500
commitc3a68ebfcd22abc186f2328149732c801449b297 (patch)
tree253db155491541accda86b0900dce9856213a9ab
parenta96bfa135ddc8045166fc6311ce4d21bfcb8d13d (diff)
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: Milo(Woogyom) Kim <milo.kim@ti.com> Signed-off-by: Bryan Wu <cooloney@gmail.com>
-rw-r--r--drivers/leds/leds-lp5521.c24
-rw-r--r--drivers/leds/leds-lp5523.c25
-rw-r--r--drivers/leds/leds-lp55xx-common.c16
-rw-r--r--drivers/leds/leds-lp55xx-common.h2
4 files changed, 22 insertions, 45 deletions
diff --git a/drivers/leds/leds-lp5521.c b/drivers/leds/leds-lp5521.c
index 7133af824b5e..cec252eae716 100644
--- a/drivers/leds/leds-lp5521.c
+++ b/drivers/leds/leds-lp5521.c
@@ -567,9 +567,6 @@ static ssize_t store_led_pattern(struct device *dev,
567 return len; 567 return len;
568} 568}
569 569
570static struct attribute_group lp5521_led_attribute_group = {
571};
572
573/* device attributes */ 570/* device attributes */
574static DEVICE_ATTR(engine1_mode, S_IRUGO | S_IWUSR, 571static DEVICE_ATTR(engine1_mode, S_IRUGO | S_IWUSR,
575 show_engine1_mode, store_engine1_mode); 572 show_engine1_mode, store_engine1_mode);
@@ -607,25 +604,9 @@ static int lp5521_register_sysfs(struct i2c_client *client)
607 604
608static void lp5521_unregister_sysfs(struct i2c_client *client) 605static void lp5521_unregister_sysfs(struct i2c_client *client)
609{ 606{
610 struct lp5521_chip *chip = i2c_get_clientdata(client);
611 struct device *dev = &client->dev; 607 struct device *dev = &client->dev;
612 int i;
613 608
614 sysfs_remove_group(&dev->kobj, &lp5521_group); 609 sysfs_remove_group(&dev->kobj, &lp5521_group);
615
616 for (i = 0; i < chip->num_leds; i++)
617 sysfs_remove_group(&chip->leds[i].cdev.dev->kobj,
618 &lp5521_led_attribute_group);
619}
620
621static void lp5521_unregister_leds(struct lp5521_chip *chip)
622{
623 int i;
624
625 for (i = 0; i < chip->num_leds; i++) {
626 led_classdev_unregister(&chip->leds[i].cdev);
627 cancel_work_sync(&chip->leds[i].brightness_work);
628 }
629} 610}
630 611
631/* Chip specific configurations */ 612/* Chip specific configurations */
@@ -647,7 +628,6 @@ static struct lp55xx_device_config lp5521_cfg = {
647static int lp5521_probe(struct i2c_client *client, 628static int lp5521_probe(struct i2c_client *client,
648 const struct i2c_device_id *id) 629 const struct i2c_device_id *id)
649{ 630{
650 struct lp5521_chip *old_chip = NULL;
651 int ret; 631 int ret;
652 struct lp55xx_chip *chip; 632 struct lp55xx_chip *chip;
653 struct lp55xx_led *led; 633 struct lp55xx_led *led;
@@ -692,7 +672,7 @@ static int lp5521_probe(struct i2c_client *client,
692 } 672 }
693 return ret; 673 return ret;
694fail2: 674fail2:
695 lp5521_unregister_leds(old_chip); 675 lp55xx_unregister_leds(led, chip);
696err_register_leds: 676err_register_leds:
697 lp55xx_deinit_device(chip); 677 lp55xx_deinit_device(chip);
698err_init: 678err_init:
@@ -708,7 +688,7 @@ static int lp5521_remove(struct i2c_client *client)
708 lp5521_run_led_pattern(PATTERN_OFF, old_chip); 688 lp5521_run_led_pattern(PATTERN_OFF, old_chip);
709 lp5521_unregister_sysfs(client); 689 lp5521_unregister_sysfs(client);
710 690
711 lp5521_unregister_leds(old_chip); 691 lp55xx_unregister_leds(led, chip);
712 lp55xx_deinit_device(chip); 692 lp55xx_deinit_device(chip);
713 693
714 return 0; 694 return 0;
diff --git a/drivers/leds/leds-lp5523.c b/drivers/leds/leds-lp5523.c
index dfb335420568..70630156eff9 100644
--- a/drivers/leds/leds-lp5523.c
+++ b/drivers/leds/leds-lp5523.c
@@ -609,9 +609,6 @@ store_mode(1)
609store_mode(2) 609store_mode(2)
610store_mode(3) 610store_mode(3)
611 611
612static struct attribute_group lp5523_led_attribute_group = {
613};
614
615/* device attributes */ 612/* device attributes */
616static DEVICE_ATTR(engine1_mode, S_IRUGO | S_IWUSR, 613static DEVICE_ATTR(engine1_mode, S_IRUGO | S_IWUSR,
617 show_engine1_mode, store_engine1_mode); 614 show_engine1_mode, store_engine1_mode);
@@ -662,15 +659,9 @@ static int lp5523_register_sysfs(struct i2c_client *client)
662 659
663static void lp5523_unregister_sysfs(struct i2c_client *client) 660static void lp5523_unregister_sysfs(struct i2c_client *client)
664{ 661{
665 struct lp5523_chip *chip = i2c_get_clientdata(client);
666 struct device *dev = &client->dev; 662 struct device *dev = &client->dev;
667 int i;
668 663
669 sysfs_remove_group(&dev->kobj, &lp5523_group); 664 sysfs_remove_group(&dev->kobj, &lp5523_group);
670
671 for (i = 0; i < chip->num_leds; i++)
672 sysfs_remove_group(&chip->leds[i].cdev.dev->kobj,
673 &lp5523_led_attribute_group);
674} 665}
675 666
676/*--------------------------------------------------------------*/ 667/*--------------------------------------------------------------*/
@@ -703,16 +694,6 @@ static void lp5523_set_mode(struct lp5523_engine *engine, u8 mode)
703/*--------------------------------------------------------------*/ 694/*--------------------------------------------------------------*/
704/* Probe, Attach, Remove */ 695/* Probe, Attach, Remove */
705/*--------------------------------------------------------------*/ 696/*--------------------------------------------------------------*/
706static void lp5523_unregister_leds(struct lp5523_chip *chip)
707{
708 int i;
709
710 for (i = 0; i < chip->num_leds; i++) {
711 led_classdev_unregister(&chip->leds[i].cdev);
712 flush_work(&chip->leds[i].brightness_work);
713 }
714}
715
716/* Chip specific configurations */ 697/* Chip specific configurations */
717static struct lp55xx_device_config lp5523_cfg = { 698static struct lp55xx_device_config lp5523_cfg = {
718 .reset = { 699 .reset = {
@@ -732,7 +713,6 @@ static struct lp55xx_device_config lp5523_cfg = {
732static int lp5523_probe(struct i2c_client *client, 713static int lp5523_probe(struct i2c_client *client,
733 const struct i2c_device_id *id) 714 const struct i2c_device_id *id)
734{ 715{
735 struct lp5523_chip *old_chip = NULL;
736 int ret; 716 int ret;
737 struct lp55xx_chip *chip; 717 struct lp55xx_chip *chip;
738 struct lp55xx_led *led; 718 struct lp55xx_led *led;
@@ -777,7 +757,7 @@ static int lp5523_probe(struct i2c_client *client,
777 } 757 }
778 return ret; 758 return ret;
779fail2: 759fail2:
780 lp5523_unregister_leds(old_chip); 760 lp55xx_unregister_leds(led, chip);
781err_register_leds: 761err_register_leds:
782 lp55xx_deinit_device(chip); 762 lp55xx_deinit_device(chip);
783err_init: 763err_init:
@@ -786,7 +766,6 @@ err_init:
786 766
787static int lp5523_remove(struct i2c_client *client) 767static int lp5523_remove(struct i2c_client *client)
788{ 768{
789 struct lp5523_chip *old_chip = i2c_get_clientdata(client);
790 struct lp55xx_led *led = i2c_get_clientdata(client); 769 struct lp55xx_led *led = i2c_get_clientdata(client);
791 struct lp55xx_chip *chip = led->chip; 770 struct lp55xx_chip *chip = led->chip;
792 771
@@ -795,7 +774,7 @@ static int lp5523_remove(struct i2c_client *client)
795 774
796 lp5523_unregister_sysfs(client); 775 lp5523_unregister_sysfs(client);
797 776
798 lp5523_unregister_leds(old_chip); 777 lp55xx_unregister_leds(led, chip);
799 lp55xx_deinit_device(chip); 778 lp55xx_deinit_device(chip);
800 779
801 return 0; 780 return 0;
diff --git a/drivers/leds/leds-lp55xx-common.c b/drivers/leds/leds-lp55xx-common.c
index 6b3d03709f5f..dcd64f5285e8 100644
--- a/drivers/leds/leds-lp55xx-common.c
+++ b/drivers/leds/leds-lp55xx-common.c
@@ -353,6 +353,22 @@ err_init_led:
353} 353}
354EXPORT_SYMBOL_GPL(lp55xx_register_leds); 354EXPORT_SYMBOL_GPL(lp55xx_register_leds);
355 355
356void lp55xx_unregister_leds(struct lp55xx_led *led, struct lp55xx_chip *chip)
357{
358 int i;
359 struct lp55xx_led *each;
360 struct kobject *kobj;
361
362 for (i = 0; i < chip->num_leds; i++) {
363 each = led + i;
364 kobj = &led->cdev.dev->kobj;
365 sysfs_remove_group(kobj, &lp55xx_led_attr_group);
366 led_classdev_unregister(&each->cdev);
367 flush_work(&each->brightness_work);
368 }
369}
370EXPORT_SYMBOL_GPL(lp55xx_unregister_leds);
371
356MODULE_AUTHOR("Milo Kim <milo.kim@ti.com>"); 372MODULE_AUTHOR("Milo Kim <milo.kim@ti.com>");
357MODULE_DESCRIPTION("LP55xx Common Driver"); 373MODULE_DESCRIPTION("LP55xx Common Driver");
358MODULE_LICENSE("GPL"); 374MODULE_LICENSE("GPL");
diff --git a/drivers/leds/leds-lp55xx-common.h b/drivers/leds/leds-lp55xx-common.h
index 70d2bdf54b8e..32d96828cbc6 100644
--- a/drivers/leds/leds-lp55xx-common.h
+++ b/drivers/leds/leds-lp55xx-common.h
@@ -101,4 +101,6 @@ extern void lp55xx_deinit_device(struct lp55xx_chip *chip);
101/* common LED class device functions */ 101/* common LED class device functions */
102extern int lp55xx_register_leds(struct lp55xx_led *led, 102extern int lp55xx_register_leds(struct lp55xx_led *led,
103 struct lp55xx_chip *chip); 103 struct lp55xx_chip *chip);
104extern void lp55xx_unregister_leds(struct lp55xx_led *led,
105 struct lp55xx_chip *chip);
104#endif /* _LEDS_LP55XX_COMMON_H */ 106#endif /* _LEDS_LP55XX_COMMON_H */