leds: lt3593: switch to gpiod interface

Clean up the code a bit and transition over to the gpiod based interface.

Signed-off-by: Daniel Mack <daniel@zonque.org>
Signed-off-by: Jacek Anaszewski <jacek.anaszewski@gmail.com>
This commit is contained in:
Daniel Mack 2018-06-27 20:52:35 +02:00 committed by Jacek Anaszewski
parent d8be286739
commit 73f103c952

View File

@ -21,12 +21,13 @@
#include <linux/leds.h>
#include <linux/delay.h>
#include <linux/gpio.h>
#include <linux/gpio/consumer.h>
#include <linux/slab.h>
#include <linux/module.h>
struct lt3593_led_data {
struct led_classdev cdev;
unsigned gpio;
struct gpio_desc *gpiod;
};
static int lt3593_led_set(struct led_classdev *led_cdev,
@ -46,25 +47,25 @@ static int lt3593_led_set(struct led_classdev *led_cdev,
*/
if (value == 0) {
gpio_set_value_cansleep(led_dat->gpio, 0);
gpiod_set_value_cansleep(led_dat->gpiod, 0);
return 0;
}
pulses = 32 - (value * 32) / 255;
if (pulses == 0) {
gpio_set_value_cansleep(led_dat->gpio, 0);
gpiod_set_value_cansleep(led_dat->gpiod, 0);
mdelay(1);
gpio_set_value_cansleep(led_dat->gpio, 1);
gpiod_set_value_cansleep(led_dat->gpiod, 1);
return 0;
}
gpio_set_value_cansleep(led_dat->gpio, 1);
gpiod_set_value_cansleep(led_dat->gpiod, 1);
while (pulses--) {
gpio_set_value_cansleep(led_dat->gpio, 0);
gpiod_set_value_cansleep(led_dat->gpiod, 0);
udelay(1);
gpio_set_value_cansleep(led_dat->gpio, 1);
gpiod_set_value_cansleep(led_dat->gpiod, 1);
udelay(1);
}
@ -85,15 +86,8 @@ static struct lt3593_led_data *lt3593_led_probe_pdata(struct device *dev)
if (!led_data)
return ERR_PTR(-ENOMEM);
if (!gpio_is_valid(template->gpio)) {
dev_info(dev, "skipping unavailable LT3593 LED at gpio "
"%d (%s)\n", template->gpio, template->name);
return ERR_PTR(-EINVAL);
}
led_data->cdev.name = template->name;
led_data->cdev.default_trigger = template->default_trigger;
led_data->gpio = template->gpio;
led_data->cdev.brightness_set_blocking = lt3593_led_set;
state = (template->default_state == LEDS_GPIO_DEFSTATE_ON);
@ -108,6 +102,10 @@ static struct lt3593_led_data *lt3593_led_probe_pdata(struct device *dev)
if (ret < 0)
return ERR_PTR(ret);
led_data->gpiod = gpio_to_desc(template->gpio);
if (!led_data->gpiod)
return ERR_PTR(-EPROBE_DEFER);
ret = devm_led_classdev_register(dev, &led_data->cdev);
if (ret < 0)
return ERR_PTR(ret);