summaryrefslogtreecommitdiff
path: root/drivers/leds
diff options
context:
space:
mode:
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>2019-03-25 16:05:00 +0200
committerJacek Anaszewski <jacek.anaszewski@gmail.com>2019-03-31 20:12:30 +0200
commit967f69de81478c491f49681d10c71c66b6e7fb96 (patch)
treeb4a8d5f4f100c6aaf7973f25520ba0fd4f42a66c /drivers/leds
parent1c310074ad6cf5197d47b83cc64c272c538d7e1d (diff)
leds: pca955x: Make use of device property API
Make use of device property API in this driver so that both OF based system and ACPI based system can use this driver. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Signed-off-by: Jacek Anaszewski <jacek.anaszewski@gmail.com>
Diffstat (limited to 'drivers/leds')
-rw-r--r--drivers/leds/leds-pca955x.c35
1 files changed, 13 insertions, 22 deletions
diff --git a/drivers/leds/leds-pca955x.c b/drivers/leds/leds-pca955x.c
index f023729353b5..a9f5dad55956 100644
--- a/drivers/leds/leds-pca955x.c
+++ b/drivers/leds/leds-pca955x.c
@@ -47,8 +47,8 @@
#include <linux/i2c.h>
#include <linux/leds.h>
#include <linux/module.h>
-#include <linux/of_device.h>
#include <linux/of.h>
+#include <linux/property.h>
#include <linux/slab.h>
#include <linux/string.h>
@@ -363,16 +363,14 @@ static int pca955x_gpio_direction_output(struct gpio_chip *gc,
}
#endif /* CONFIG_LEDS_PCA955X_GPIO */
-#if IS_ENABLED(CONFIG_OF)
static struct pca955x_platform_data *
-pca955x_pdata_of_init(struct i2c_client *client, struct pca955x_chipdef *chip)
+pca955x_get_pdata(struct i2c_client *client, struct pca955x_chipdef *chip)
{
- struct device_node *np = client->dev.of_node;
- struct device_node *child;
struct pca955x_platform_data *pdata;
+ struct fwnode_handle *child;
int count;
- count = of_get_child_count(np);
+ count = device_get_child_node_count(&client->dev);
if (!count || count > chip->bits)
return ERR_PTR(-ENODEV);
@@ -386,24 +384,25 @@ pca955x_pdata_of_init(struct i2c_client *client, struct pca955x_chipdef *chip)
if (!pdata->leds)
return ERR_PTR(-ENOMEM);
- for_each_child_of_node(np, child) {
+ device_for_each_child_node(&client->dev, child) {
const char *name;
u32 reg;
int res;
- res = of_property_read_u32(child, "reg", &reg);
+ res = fwnode_property_read_u32(child, "reg", &reg);
if ((res != 0) || (reg >= chip->bits))
continue;
- if (of_property_read_string(child, "label", &name))
- name = child->name;
+ res = fwnode_property_read_string(child, "label", &name);
+ if ((res != 0) && is_of_node(child))
+ name = to_of_node(child)->name;
snprintf(pdata->leds[reg].name, sizeof(pdata->leds[reg].name),
"%s", name);
pdata->leds[reg].type = PCA955X_TYPE_LED;
- of_property_read_u32(child, "type", &pdata->leds[reg].type);
- of_property_read_string(child, "linux,default-trigger",
+ fwnode_property_read_u32(child, "type", &pdata->leds[reg].type);
+ fwnode_property_read_string(child, "linux,default-trigger",
&pdata->leds[reg].default_trigger);
}
@@ -419,15 +418,7 @@ static const struct of_device_id of_pca955x_match[] = {
{ .compatible = "nxp,pca9553", .data = (void *)pca9553 },
{},
};
-
MODULE_DEVICE_TABLE(of, of_pca955x_match);
-#else
-static struct pca955x_platform_data *
-pca955x_pdata_of_init(struct i2c_client *client, struct pca955x_chipdef *chip)
-{
- return ERR_PTR(-ENODEV);
-}
-#endif
static int pca955x_probe(struct i2c_client *client,
const struct i2c_device_id *id)
@@ -444,7 +435,7 @@ static int pca955x_probe(struct i2c_client *client,
adapter = to_i2c_adapter(client->dev.parent);
pdata = dev_get_platdata(&client->dev);
if (!pdata) {
- pdata = pca955x_pdata_of_init(client, chip);
+ pdata = pca955x_get_pdata(client, chip);
if (IS_ERR(pdata))
return PTR_ERR(pdata);
}
@@ -583,7 +574,7 @@ static int pca955x_probe(struct i2c_client *client,
static struct i2c_driver pca955x_driver = {
.driver = {
.name = "leds-pca955x",
- .of_match_table = of_match_ptr(of_pca955x_match),
+ .of_match_table = of_pca955x_match,
},
.probe = pca955x_probe,
.id_table = pca955x_id,