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>
This commit is contained in:
parent
1c310074ad
commit
967f69de81
|
@ -47,8 +47,8 @@
|
||||||
#include <linux/i2c.h>
|
#include <linux/i2c.h>
|
||||||
#include <linux/leds.h>
|
#include <linux/leds.h>
|
||||||
#include <linux/module.h>
|
#include <linux/module.h>
|
||||||
#include <linux/of_device.h>
|
|
||||||
#include <linux/of.h>
|
#include <linux/of.h>
|
||||||
|
#include <linux/property.h>
|
||||||
#include <linux/slab.h>
|
#include <linux/slab.h>
|
||||||
#include <linux/string.h>
|
#include <linux/string.h>
|
||||||
|
|
||||||
|
@ -363,16 +363,14 @@ static int pca955x_gpio_direction_output(struct gpio_chip *gc,
|
||||||
}
|
}
|
||||||
#endif /* CONFIG_LEDS_PCA955X_GPIO */
|
#endif /* CONFIG_LEDS_PCA955X_GPIO */
|
||||||
|
|
||||||
#if IS_ENABLED(CONFIG_OF)
|
|
||||||
static struct pca955x_platform_data *
|
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 pca955x_platform_data *pdata;
|
||||||
|
struct fwnode_handle *child;
|
||||||
int count;
|
int count;
|
||||||
|
|
||||||
count = of_get_child_count(np);
|
count = device_get_child_node_count(&client->dev);
|
||||||
if (!count || count > chip->bits)
|
if (!count || count > chip->bits)
|
||||||
return ERR_PTR(-ENODEV);
|
return ERR_PTR(-ENODEV);
|
||||||
|
|
||||||
|
@ -386,24 +384,25 @@ pca955x_pdata_of_init(struct i2c_client *client, struct pca955x_chipdef *chip)
|
||||||
if (!pdata->leds)
|
if (!pdata->leds)
|
||||||
return ERR_PTR(-ENOMEM);
|
return ERR_PTR(-ENOMEM);
|
||||||
|
|
||||||
for_each_child_of_node(np, child) {
|
device_for_each_child_node(&client->dev, child) {
|
||||||
const char *name;
|
const char *name;
|
||||||
u32 reg;
|
u32 reg;
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
res = of_property_read_u32(child, "reg", ®);
|
res = fwnode_property_read_u32(child, "reg", ®);
|
||||||
if ((res != 0) || (reg >= chip->bits))
|
if ((res != 0) || (reg >= chip->bits))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (of_property_read_string(child, "label", &name))
|
res = fwnode_property_read_string(child, "label", &name);
|
||||||
name = child->name;
|
if ((res != 0) && is_of_node(child))
|
||||||
|
name = to_of_node(child)->name;
|
||||||
|
|
||||||
snprintf(pdata->leds[reg].name, sizeof(pdata->leds[reg].name),
|
snprintf(pdata->leds[reg].name, sizeof(pdata->leds[reg].name),
|
||||||
"%s", name);
|
"%s", name);
|
||||||
|
|
||||||
pdata->leds[reg].type = PCA955X_TYPE_LED;
|
pdata->leds[reg].type = PCA955X_TYPE_LED;
|
||||||
of_property_read_u32(child, "type", &pdata->leds[reg].type);
|
fwnode_property_read_u32(child, "type", &pdata->leds[reg].type);
|
||||||
of_property_read_string(child, "linux,default-trigger",
|
fwnode_property_read_string(child, "linux,default-trigger",
|
||||||
&pdata->leds[reg].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 },
|
{ .compatible = "nxp,pca9553", .data = (void *)pca9553 },
|
||||||
{},
|
{},
|
||||||
};
|
};
|
||||||
|
|
||||||
MODULE_DEVICE_TABLE(of, of_pca955x_match);
|
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,
|
static int pca955x_probe(struct i2c_client *client,
|
||||||
const struct i2c_device_id *id)
|
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);
|
adapter = to_i2c_adapter(client->dev.parent);
|
||||||
pdata = dev_get_platdata(&client->dev);
|
pdata = dev_get_platdata(&client->dev);
|
||||||
if (!pdata) {
|
if (!pdata) {
|
||||||
pdata = pca955x_pdata_of_init(client, chip);
|
pdata = pca955x_get_pdata(client, chip);
|
||||||
if (IS_ERR(pdata))
|
if (IS_ERR(pdata))
|
||||||
return PTR_ERR(pdata);
|
return PTR_ERR(pdata);
|
||||||
}
|
}
|
||||||
|
@ -583,7 +574,7 @@ static int pca955x_probe(struct i2c_client *client,
|
||||||
static struct i2c_driver pca955x_driver = {
|
static struct i2c_driver pca955x_driver = {
|
||||||
.driver = {
|
.driver = {
|
||||||
.name = "leds-pca955x",
|
.name = "leds-pca955x",
|
||||||
.of_match_table = of_match_ptr(of_pca955x_match),
|
.of_match_table = of_pca955x_match,
|
||||||
},
|
},
|
||||||
.probe = pca955x_probe,
|
.probe = pca955x_probe,
|
||||||
.id_table = pca955x_id,
|
.id_table = pca955x_id,
|
||||||
|
|
Loading…
Reference in New Issue