Merge tag 'exfat-for-5.10-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/linki...
[linux-2.6-microblaze.git] / drivers / leds / leds-tca6507.c
index 3e01fe2..225b765 100644 (file)
  * defaulted.  Similarly the banks know if each time was explicit or a
  * default.  Defaults are permitted to be changed freely - they are
  * not recognised when matching.
- *
- *
- * An led-tca6507 device must be provided with platform data or
- * configured via devicetree.
- *
- * The platform-data lists for each output: the name, default trigger,
- * and whether the signal is being used as a GPIO rather than an LED.
- * 'struct led_plaform_data' is used for this.  If 'name' is NULL, the
- * output isn't used.  If 'flags' is TCA6507_MAKE_GPIO, the output is
- * a GPO.  The "struct led_platform_data" can be embedded in a "struct
- * tca6507_platform_data" which adds a 'gpio_base' for the GPIOs, and
- * a 'setup' callback which is called once the GPIOs are available.
- *
- * When configured via devicetree there is one child for each output.
- * The "reg" determines the output number and "compatible" determines
- * whether it is an LED or a GPIO.  "linux,default-trigger" can set a
- * default trigger.
  */
 
 #include <linux/module.h>
@@ -197,7 +180,6 @@ struct tca6507_chip {
        } leds[NUM_LEDS];
 #ifdef CONFIG_GPIOLIB
        struct gpio_chip                gpio;
-       const char                      *gpio_name[NUM_LEDS];
        int                             gpio_map[NUM_LEDS];
 #endif
 };
@@ -636,7 +618,7 @@ static int tca6507_gpio_direction_output(struct gpio_chip *gc,
        return 0;
 }
 
-static int tca6507_probe_gpios(struct i2c_client *client,
+static int tca6507_probe_gpios(struct device *dev,
                               struct tca6507_chip *tca,
                               struct tca6507_platform_data *pdata)
 {
@@ -647,7 +629,6 @@ static int tca6507_probe_gpios(struct i2c_client *client,
        for (i = 0; i < NUM_LEDS; i++)
                if (pdata->leds.leds[i].name && pdata->leds.leds[i].flags) {
                        /* Configure as a gpio */
-                       tca->gpio_name[gpios] = pdata->leds.leds[i].name;
                        tca->gpio_map[gpios] = i;
                        gpios++;
                }
@@ -656,15 +637,14 @@ static int tca6507_probe_gpios(struct i2c_client *client,
                return 0;
 
        tca->gpio.label = "gpio-tca6507";
-       tca->gpio.names = tca->gpio_name;
        tca->gpio.ngpio = gpios;
        tca->gpio.base = pdata->gpio_base;
        tca->gpio.owner = THIS_MODULE;
        tca->gpio.direction_output = tca6507_gpio_direction_output;
        tca->gpio.set = tca6507_gpio_set_value;
-       tca->gpio.parent = &client->dev;
+       tca->gpio.parent = dev;
 #ifdef CONFIG_OF_GPIO
-       tca->gpio.of_node = of_node_get(dev_of_node(&client->dev));
+       tca->gpio.of_node = of_node_get(dev_of_node(dev));
 #endif
        err = gpiochip_add_data(&tca->gpio, tca);
        if (err) {
@@ -680,7 +660,7 @@ static void tca6507_remove_gpio(struct tca6507_chip *tca)
                gpiochip_remove(&tca->gpio);
 }
 #else /* CONFIG_GPIOLIB */
-static int tca6507_probe_gpios(struct i2c_client *client,
+static int tca6507_probe_gpios(struct device *dev,
                               struct tca6507_chip *tca,
                               struct tca6507_platform_data *pdata)
 {
@@ -692,23 +672,23 @@ static void tca6507_remove_gpio(struct tca6507_chip *tca)
 #endif /* CONFIG_GPIOLIB */
 
 static struct tca6507_platform_data *
-tca6507_led_dt_init(struct i2c_client *client)
+tca6507_led_dt_init(struct device *dev)
 {
        struct tca6507_platform_data *pdata;
        struct fwnode_handle *child;
        struct led_info *tca_leds;
        int count;
 
-       count = device_get_child_node_count(&client->dev);
+       count = device_get_child_node_count(dev);
        if (!count || count > NUM_LEDS)
                return ERR_PTR(-ENODEV);
 
-       tca_leds = devm_kcalloc(&client->dev, NUM_LEDS, sizeof(struct led_info),
+       tca_leds = devm_kcalloc(dev, NUM_LEDS, sizeof(struct led_info),
                                GFP_KERNEL);
        if (!tca_leds)
                return ERR_PTR(-ENOMEM);
 
-       device_for_each_child_node(&client->dev, child) {
+       device_for_each_child_node(dev, child) {
                struct led_info led;
                u32 reg;
                int ret;
@@ -727,13 +707,13 @@ tca6507_led_dt_init(struct i2c_client *client)
                ret = fwnode_property_read_u32(child, "reg", &reg);
                if (ret || reg >= NUM_LEDS) {
                        fwnode_handle_put(child);
-                       return ERR_PTR(ret);
+                       return ERR_PTR(ret ? : -EINVAL);
                }
 
                tca_leds[reg] = led;
        }
 
-       pdata = devm_kzalloc(&client->dev, sizeof(struct tca6507_platform_data),
+       pdata = devm_kzalloc(dev, sizeof(struct tca6507_platform_data),
                             GFP_KERNEL);
        if (!pdata)
                return ERR_PTR(-ENOMEM);
@@ -747,7 +727,7 @@ tca6507_led_dt_init(struct i2c_client *client)
        return pdata;
 }
 
-static const struct of_device_id of_tca6507_leds_match[] = {
+static const struct of_device_id __maybe_unused of_tca6507_leds_match[] = {
        { .compatible = "ti,tca6507", },
        {},
 };
@@ -756,8 +736,9 @@ MODULE_DEVICE_TABLE(of, of_tca6507_leds_match);
 static int tca6507_probe(struct i2c_client *client,
                const struct i2c_device_id *id)
 {
-       struct tca6507_chip *tca;
+       struct device *dev = &client->dev;
        struct i2c_adapter *adapter;
+       struct tca6507_chip *tca;
        struct tca6507_platform_data *pdata;
        int err;
        int i = 0;
@@ -767,13 +748,12 @@ static int tca6507_probe(struct i2c_client *client,
        if (!i2c_check_functionality(adapter, I2C_FUNC_I2C))
                return -EIO;
 
-       pdata = tca6507_led_dt_init(client);
+       pdata = tca6507_led_dt_init(dev);
        if (IS_ERR(pdata)) {
-               dev_err(&client->dev, "Need %d entries in platform-data list\n",
-                       NUM_LEDS);
+               dev_err(dev, "Need %d entries in platform-data list\n", NUM_LEDS);
                return PTR_ERR(pdata);
        }
-       tca = devm_kzalloc(&client->dev, sizeof(*tca), GFP_KERNEL);
+       tca = devm_kzalloc(dev, sizeof(*tca), GFP_KERNEL);
        if (!tca)
                return -ENOMEM;
 
@@ -794,13 +774,12 @@ static int tca6507_probe(struct i2c_client *client,
                        l->led_cdev.brightness_set = tca6507_brightness_set;
                        l->led_cdev.blink_set = tca6507_blink_set;
                        l->bank = -1;
-                       err = led_classdev_register(&client->dev,
-                                                   &l->led_cdev);
+                       err = led_classdev_register(dev, &l->led_cdev);
                        if (err < 0)
                                goto exit;
                }
        }
-       err = tca6507_probe_gpios(client, tca, pdata);
+       err = tca6507_probe_gpios(dev, tca, pdata);
        if (err)
                goto exit;
        /* set all registers to known state - zero */