Commit 96f52410 authored by Marek Behún's avatar Marek Behún Committed by Pavel Machek

leds: tca6507: use fwnode API instead of OF

Convert to use fwnode API instead of OF. It is more generic and if
someone wants to use this driver without device-tree yet still, they
will be able to via swnode fwnodes.

Remove the gpio setup function from platdata.
Signed-off-by: default avatarMarek Behún <marek.behun@nic.cz>
Cc: NeilBrown <neilb@suse.de>
Cc: Linus Walleij <linus.walleij@linaro.org>
Tested-by: default avatarH. Nikolaus Schaller <hns@goldelico.com>
Signed-off-by: default avatarPavel Machek <pavel@ucw.cz>
parent 38b393fe
...@@ -94,8 +94,8 @@ ...@@ -94,8 +94,8 @@
#include <linux/err.h> #include <linux/err.h>
#include <linux/i2c.h> #include <linux/i2c.h>
#include <linux/gpio/driver.h> #include <linux/gpio/driver.h>
#include <linux/property.h>
#include <linux/workqueue.h> #include <linux/workqueue.h>
#include <linux/of.h>
/* LED select registers determine the source that drives LED outputs */ /* LED select registers determine the source that drives LED outputs */
#define TCA6507_LS_LED_OFF 0x0 /* Output HI-Z (off) */ #define TCA6507_LS_LED_OFF 0x0 /* Output HI-Z (off) */
...@@ -111,7 +111,6 @@ struct tca6507_platform_data { ...@@ -111,7 +111,6 @@ struct tca6507_platform_data {
struct led_platform_data leds; struct led_platform_data leds;
#ifdef CONFIG_GPIOLIB #ifdef CONFIG_GPIOLIB
int gpio_base; int gpio_base;
void (*setup)(unsigned gpio_base, unsigned ngpio);
#endif #endif
}; };
...@@ -672,8 +671,6 @@ static int tca6507_probe_gpios(struct i2c_client *client, ...@@ -672,8 +671,6 @@ static int tca6507_probe_gpios(struct i2c_client *client,
tca->gpio.ngpio = 0; tca->gpio.ngpio = 0;
return err; return err;
} }
if (pdata->setup)
pdata->setup(tca->gpio.base, tca->gpio.ngpio);
return 0; return 0;
} }
...@@ -694,44 +691,50 @@ static void tca6507_remove_gpio(struct tca6507_chip *tca) ...@@ -694,44 +691,50 @@ static void tca6507_remove_gpio(struct tca6507_chip *tca)
} }
#endif /* CONFIG_GPIOLIB */ #endif /* CONFIG_GPIOLIB */
#ifdef CONFIG_OF
static struct tca6507_platform_data * static struct tca6507_platform_data *
tca6507_led_dt_init(struct i2c_client *client) tca6507_led_dt_init(struct i2c_client *client)
{ {
struct device_node *np = dev_of_node(&client->dev), *child;
struct tca6507_platform_data *pdata; struct tca6507_platform_data *pdata;
struct fwnode_handle *child;
struct led_info *tca_leds; struct led_info *tca_leds;
int count; int count;
count = of_get_available_child_count(np); count = device_get_child_node_count(&client->dev);
if (!count || count > NUM_LEDS) if (!count || count > NUM_LEDS)
return ERR_PTR(-ENODEV); return ERR_PTR(-ENODEV);
tca_leds = devm_kcalloc(&client->dev, tca_leds = devm_kcalloc(&client->dev, NUM_LEDS, sizeof(struct led_info),
NUM_LEDS, sizeof(struct led_info), GFP_KERNEL); GFP_KERNEL);
if (!tca_leds) if (!tca_leds)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
for_each_available_child_of_node(np, child) { device_for_each_child_node(&client->dev, child) {
struct led_info led; struct led_info led;
u32 reg; u32 reg;
int ret; int ret;
led.name = if (fwnode_property_read_string(child, "label", &led.name))
of_get_property(child, "label", NULL) ? : child->name; led.name = fwnode_get_name(child);
led.default_trigger =
of_get_property(child, "linux,default-trigger", NULL); fwnode_property_read_string(child, "linux,default-trigger",
&led.default_trigger);
led.flags = 0; led.flags = 0;
if (of_property_match_string(child, "compatible", "gpio") >= 0) if (fwnode_property_match_string(child, "compatible",
"gpio") >= 0)
led.flags |= TCA6507_MAKE_GPIO; led.flags |= TCA6507_MAKE_GPIO;
ret = of_property_read_u32(child, "reg", &reg);
if (ret != 0 || reg >= NUM_LEDS) ret = fwnode_property_read_u32(child, "reg", &reg);
continue; if (ret || reg >= NUM_LEDS) {
fwnode_handle_put(child);
return ERR_PTR(ret);
}
tca_leds[reg] = led; tca_leds[reg] = led;
} }
pdata = devm_kzalloc(&client->dev,
sizeof(struct tca6507_platform_data), GFP_KERNEL); pdata = devm_kzalloc(&client->dev, sizeof(struct tca6507_platform_data),
GFP_KERNEL);
if (!pdata) if (!pdata)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
...@@ -740,6 +743,7 @@ tca6507_led_dt_init(struct i2c_client *client) ...@@ -740,6 +743,7 @@ tca6507_led_dt_init(struct i2c_client *client)
#ifdef CONFIG_GPIOLIB #ifdef CONFIG_GPIOLIB
pdata->gpio_base = -1; pdata->gpio_base = -1;
#endif #endif
return pdata; return pdata;
} }
...@@ -749,15 +753,6 @@ static const struct of_device_id of_tca6507_leds_match[] = { ...@@ -749,15 +753,6 @@ static const struct of_device_id of_tca6507_leds_match[] = {
}; };
MODULE_DEVICE_TABLE(of, of_tca6507_leds_match); MODULE_DEVICE_TABLE(of, of_tca6507_leds_match);
#else
static struct tca6507_platform_data *
tca6507_led_dt_init(struct i2c_client *client)
{
return ERR_PTR(-ENODEV);
}
#endif
static int tca6507_probe(struct i2c_client *client, static int tca6507_probe(struct i2c_client *client,
const struct i2c_device_id *id) const struct i2c_device_id *id)
{ {
...@@ -768,19 +763,16 @@ static int tca6507_probe(struct i2c_client *client, ...@@ -768,19 +763,16 @@ static int tca6507_probe(struct i2c_client *client,
int i = 0; int i = 0;
adapter = client->adapter; adapter = client->adapter;
pdata = dev_get_platdata(&client->dev);
if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) if (!i2c_check_functionality(adapter, I2C_FUNC_I2C))
return -EIO; return -EIO;
if (!pdata || pdata->leds.num_leds != NUM_LEDS) {
pdata = tca6507_led_dt_init(client); pdata = tca6507_led_dt_init(client);
if (IS_ERR(pdata)) { if (IS_ERR(pdata)) {
dev_err(&client->dev, "Need %d entries in platform-data list\n", dev_err(&client->dev, "Need %d entries in platform-data list\n",
NUM_LEDS); NUM_LEDS);
return PTR_ERR(pdata); return PTR_ERR(pdata);
} }
}
tca = devm_kzalloc(&client->dev, sizeof(*tca), GFP_KERNEL); tca = devm_kzalloc(&client->dev, sizeof(*tca), GFP_KERNEL);
if (!tca) if (!tca)
return -ENOMEM; return -ENOMEM;
......
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