aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/leds
diff options
context:
space:
mode:
authorMarek Belisko <marek.belisko@open-nandra.com>2012-11-30 17:00:49 -0500
committerBryan Wu <cooloney@gmail.com>2013-02-01 20:47:04 -0500
commit0c596a7ebb51b515b2d59a77b8cd37c5e98b1aa5 (patch)
treea36213039418df5b6d4116c7863e606c0799d099 /drivers/leds
parent88b62b915b0b7e25870eb0604ed9a92ba4bfc9f7 (diff)
leds/tca6507: Add support for devicetree.
Support added only for leds (not for gpio's). (cooloney@gmail.com: fix 2 building errors) Signed-off-by: Marek Belisko <marek.belisko@open-nandra.com> Signed-off-by: Bryan Wu <cooloney@gmail.com>
Diffstat (limited to 'drivers/leds')
-rw-r--r--drivers/leds/leds-tca6507.c76
1 files changed, 72 insertions, 4 deletions
diff --git a/drivers/leds/leds-tca6507.c b/drivers/leds/leds-tca6507.c
index b26a63bae16b..220fc7fbf1f0 100644
--- a/drivers/leds/leds-tca6507.c
+++ b/drivers/leds/leds-tca6507.c
@@ -667,8 +667,72 @@ static void tca6507_remove_gpio(struct tca6507_chip *tca)
667} 667}
668#endif /* CONFIG_GPIOLIB */ 668#endif /* CONFIG_GPIOLIB */
669 669
670#ifdef CONFIG_OF
671static struct tca6507_platform_data *
672tca6507_led_dt_init(struct i2c_client *client)
673{
674 struct device_node *np = client->dev.of_node, *child;
675 struct tca6507_platform_data *pdata;
676 struct led_info *tca_leds;
677 int count = 0;
678
679 for_each_child_of_node(np, child)
680 count++;
681 if (!count)
682 return ERR_PTR(-ENODEV);
683
684 if (count > NUM_LEDS)
685 return ERR_PTR(-ENODEV);
686
687 tca_leds = devm_kzalloc(&client->dev,
688 sizeof(struct led_info) * count, GFP_KERNEL);
689 if (!tca_leds)
690 return ERR_PTR(-ENOMEM);
691
692 for_each_child_of_node(np, child) {
693 struct led_info led;
694 u32 reg;
695 int ret;
696
697 led.name =
698 of_get_property(child, "label", NULL) ? : child->name;
699 led.default_trigger =
700 of_get_property(child, "linux,default-trigger", NULL);
701
702 ret = of_property_read_u32(child, "reg", &reg);
703 if (ret != 0)
704 continue;
705
706 tca_leds[reg] = led;
707 }
708 pdata = devm_kzalloc(&client->dev,
709 sizeof(struct tca6507_platform_data), GFP_KERNEL);
710 if (!pdata)
711 return ERR_PTR(-ENOMEM);
712
713 pdata->leds.leds = tca_leds;
714 pdata->leds.num_leds = count;
715
716 return pdata;
717}
718
719static const struct of_device_id of_tca6507_leds_match[] = {
720 { .compatible = "ti,tca6507", },
721 {},
722};
723
724#else
725static struct tca6507_platform_data *
726tca6507_led_dt_init(struct i2c_client *client)
727{
728 return ERR_PTR(-ENODEV);
729}
730
731#define of_tca6507_leds_match NULL
732#endif
733
670static int tca6507_probe(struct i2c_client *client, 734static int tca6507_probe(struct i2c_client *client,
671 const struct i2c_device_id *id) 735 const struct i2c_device_id *id)
672{ 736{
673 struct tca6507_chip *tca; 737 struct tca6507_chip *tca;
674 struct i2c_adapter *adapter; 738 struct i2c_adapter *adapter;
@@ -683,9 +747,12 @@ static int tca6507_probe(struct i2c_client *client,
683 return -EIO; 747 return -EIO;
684 748
685 if (!pdata || pdata->leds.num_leds != NUM_LEDS) { 749 if (!pdata || pdata->leds.num_leds != NUM_LEDS) {
686 dev_err(&client->dev, "Need %d entries in platform-data list\n", 750 pdata = tca6507_led_dt_init(client);
687 NUM_LEDS); 751 if (IS_ERR(pdata)) {
688 return -ENODEV; 752 dev_err(&client->dev, "Need %d entries in platform-data list\n",
753 NUM_LEDS);
754 return PTR_ERR(pdata);
755 }
689 } 756 }
690 tca = devm_kzalloc(&client->dev, sizeof(*tca), GFP_KERNEL); 757 tca = devm_kzalloc(&client->dev, sizeof(*tca), GFP_KERNEL);
691 if (!tca) 758 if (!tca)
@@ -750,6 +817,7 @@ static struct i2c_driver tca6507_driver = {
750 .driver = { 817 .driver = {
751 .name = "leds-tca6507", 818 .name = "leds-tca6507",
752 .owner = THIS_MODULE, 819 .owner = THIS_MODULE,
820 .of_match_table = of_tca6507_leds_match,
753 }, 821 },
754 .probe = tca6507_probe, 822 .probe = tca6507_probe,
755 .remove = tca6507_remove, 823 .remove = tca6507_remove,