diff options
Diffstat (limited to 'drivers/leds/leds-lp8860.c')
-rw-r--r-- | drivers/leds/leds-lp8860.c | 66 |
1 files changed, 45 insertions, 21 deletions
diff --git a/drivers/leds/leds-lp8860.c b/drivers/leds/leds-lp8860.c index 3e70775a2d54..39c72a908f3b 100644 --- a/drivers/leds/leds-lp8860.c +++ b/drivers/leds/leds-lp8860.c @@ -22,6 +22,7 @@ #include <linux/of_gpio.h> #include <linux/gpio/consumer.h> #include <linux/slab.h> +#include <uapi/linux/uleds.h> #define LP8860_DISP_CL1_BRT_MSB 0x00 #define LP8860_DISP_CL1_BRT_LSB 0x01 @@ -86,8 +87,6 @@ #define LP8860_CLEAR_FAULTS 0x01 -#define LP8860_DISP_LED_NAME "display_cluster" - /** * struct lp8860_led - * @lock - Lock for reading/writing the device @@ -98,7 +97,7 @@ * @enable_gpio - VDDIO/EN gpio to enable communication interface * @regulator - LED supply regulator pointer * @label - LED label -**/ + */ struct lp8860_led { struct mutex lock; struct i2c_client *client; @@ -107,7 +106,7 @@ struct lp8860_led { struct regmap *eeprom_regmap; struct gpio_desc *enable_gpio; struct regulator *regulator; - const char *label; + char label[LED_MAX_NAME_SIZE]; }; struct lp8860_eeprom_reg { @@ -247,6 +246,15 @@ static int lp8860_init(struct lp8860_led *led) unsigned int read_buf; int ret, i, reg_count; + if (led->regulator) { + ret = regulator_enable(led->regulator); + if (ret) { + dev_err(&led->client->dev, + "Failed to enable regulator\n"); + return ret; + } + } + if (led->enable_gpio) gpiod_direction_output(led->enable_gpio, 1); @@ -282,12 +290,25 @@ static int lp8860_init(struct lp8860_led *led) ret = regmap_write(led->regmap, LP8860_EEPROM_CNTRL, LP8860_PROGRAM_EEPROM); - if (ret) + if (ret) { dev_err(&led->client->dev, "Failed programming EEPROM\n"); + goto out; + } + + return ret; + out: if (ret) if (led->enable_gpio) gpiod_direction_output(led->enable_gpio, 0); + + if (led->regulator) { + ret = regulator_disable(led->regulator); + if (ret) + dev_err(&led->client->dev, + "Failed to disable regulator\n"); + } + return ret; } @@ -365,19 +386,25 @@ static int lp8860_probe(struct i2c_client *client, int ret; struct lp8860_led *led; struct device_node *np = client->dev.of_node; + struct device_node *child_node; + const char *name; led = devm_kzalloc(&client->dev, sizeof(*led), GFP_KERNEL); if (!led) return -ENOMEM; - led->label = LP8860_DISP_LED_NAME; - - if (client->dev.of_node) { - ret = of_property_read_string(np, "label", &led->label); - if (ret) { - dev_err(&client->dev, "Missing label in dt\n"); - return -EINVAL; - } + for_each_available_child_of_node(np, child_node) { + led->led_dev.default_trigger = of_get_property(child_node, + "linux,default-trigger", + NULL); + + ret = of_property_read_string(child_node, "label", &name); + if (!ret) + snprintf(led->label, sizeof(led->label), "%s:%s", + id->name, name); + else + snprintf(led->label, sizeof(led->label), + "%s::display_cluster", id->name); } led->enable_gpio = devm_gpiod_get_optional(&client->dev, @@ -394,7 +421,6 @@ static int lp8860_probe(struct i2c_client *client, led->client = client; led->led_dev.name = led->label; - led->led_dev.max_brightness = LED_FULL; led->led_dev.brightness_set_blocking = lp8860_brightness_set; mutex_init(&led->lock); @@ -421,7 +447,7 @@ static int lp8860_probe(struct i2c_client *client, if (ret) return ret; - ret = led_classdev_register(&client->dev, &led->led_dev); + ret = devm_led_classdev_register(&client->dev, &led->led_dev); if (ret) { dev_err(&client->dev, "led register err: %d\n", ret); return ret; @@ -435,8 +461,6 @@ static int lp8860_remove(struct i2c_client *client) struct lp8860_led *led = i2c_get_clientdata(client); int ret; - led_classdev_unregister(&led->led_dev); - if (led->enable_gpio) gpiod_direction_output(led->enable_gpio, 0); @@ -447,6 +471,8 @@ static int lp8860_remove(struct i2c_client *client) "Failed to disable regulator\n"); } + mutex_destroy(&led->lock); + return 0; } @@ -456,18 +482,16 @@ static const struct i2c_device_id lp8860_id[] = { }; MODULE_DEVICE_TABLE(i2c, lp8860_id); -#ifdef CONFIG_OF static const struct of_device_id of_lp8860_leds_match[] = { { .compatible = "ti,lp8860", }, {}, }; MODULE_DEVICE_TABLE(of, of_lp8860_leds_match); -#endif static struct i2c_driver lp8860_driver = { .driver = { .name = "lp8860", - .of_match_table = of_match_ptr(of_lp8860_leds_match), + .of_match_table = of_lp8860_leds_match, }, .probe = lp8860_probe, .remove = lp8860_remove, @@ -477,4 +501,4 @@ module_i2c_driver(lp8860_driver); MODULE_DESCRIPTION("Texas Instruments LP8860 LED driver"); MODULE_AUTHOR("Dan Murphy <dmurphy@ti.com>"); -MODULE_LICENSE("GPL"); +MODULE_LICENSE("GPL v2"); |