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

leds: ns2: cosmetic variable rename

Rename variable led_dat to led in various functions.
Signed-off-by: default avatarMarek Behún <marek.behun@nic.cz>
Cc: Simon Guinot <simon.guinot@sequanux.org>
Cc: Simon Guinot <sguinot@lacie.com>
Cc: Vincent Donnefort <vdonnefort@gmail.com>
Cc: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
Cc: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: default avatarPavel Machek <pavel@ucw.cz>
parent 01026cec
...@@ -62,21 +62,20 @@ struct ns2_led { ...@@ -62,21 +62,20 @@ struct ns2_led {
struct ns2_led_modval *modval; struct ns2_led_modval *modval;
}; };
static int ns2_led_get_mode(struct ns2_led *led_dat, static int ns2_led_get_mode(struct ns2_led *led, enum ns2_led_modes *mode)
enum ns2_led_modes *mode)
{ {
int i; int i;
int ret = -EINVAL; int ret = -EINVAL;
int cmd_level; int cmd_level;
int slow_level; int slow_level;
cmd_level = gpiod_get_value_cansleep(led_dat->cmd); cmd_level = gpiod_get_value_cansleep(led->cmd);
slow_level = gpiod_get_value_cansleep(led_dat->slow); slow_level = gpiod_get_value_cansleep(led->slow);
for (i = 0; i < led_dat->num_modes; i++) { for (i = 0; i < led->num_modes; i++) {
if (cmd_level == led_dat->modval[i].cmd_level && if (cmd_level == led->modval[i].cmd_level &&
slow_level == led_dat->modval[i].slow_level) { slow_level == led->modval[i].slow_level) {
*mode = led_dat->modval[i].mode; *mode = led->modval[i].mode;
ret = 0; ret = 0;
break; break;
} }
...@@ -85,15 +84,14 @@ static int ns2_led_get_mode(struct ns2_led *led_dat, ...@@ -85,15 +84,14 @@ static int ns2_led_get_mode(struct ns2_led *led_dat,
return ret; return ret;
} }
static void ns2_led_set_mode(struct ns2_led *led_dat, static void ns2_led_set_mode(struct ns2_led *led, enum ns2_led_modes mode)
enum ns2_led_modes mode)
{ {
int i; int i;
bool found = false; bool found = false;
unsigned long flags; unsigned long flags;
for (i = 0; i < led_dat->num_modes; i++) for (i = 0; i < led->num_modes; i++)
if (mode == led_dat->modval[i].mode) { if (mode == led->modval[i].mode) {
found = true; found = true;
break; break;
} }
...@@ -101,38 +99,35 @@ static void ns2_led_set_mode(struct ns2_led *led_dat, ...@@ -101,38 +99,35 @@ static void ns2_led_set_mode(struct ns2_led *led_dat,
if (!found) if (!found)
return; return;
write_lock_irqsave(&led_dat->rw_lock, flags); write_lock_irqsave(&led->rw_lock, flags);
if (!led_dat->can_sleep) { if (!led->can_sleep) {
gpiod_set_value(led_dat->cmd, gpiod_set_value(led->cmd, led->modval[i].cmd_level);
led_dat->modval[i].cmd_level); gpiod_set_value(led->slow, led->modval[i].slow_level);
gpiod_set_value(led_dat->slow,
led_dat->modval[i].slow_level);
goto exit_unlock; goto exit_unlock;
} }
gpiod_set_value_cansleep(led_dat->cmd, led_dat->modval[i].cmd_level); gpiod_set_value_cansleep(led->cmd, led->modval[i].cmd_level);
gpiod_set_value_cansleep(led_dat->slow, led_dat->modval[i].slow_level); gpiod_set_value_cansleep(led->slow, led->modval[i].slow_level);
exit_unlock: exit_unlock:
write_unlock_irqrestore(&led_dat->rw_lock, flags); write_unlock_irqrestore(&led->rw_lock, flags);
} }
static void ns2_led_set(struct led_classdev *led_cdev, static void ns2_led_set(struct led_classdev *led_cdev,
enum led_brightness value) enum led_brightness value)
{ {
struct ns2_led *led_dat = struct ns2_led *led = container_of(led_cdev, struct ns2_led, cdev);
container_of(led_cdev, struct ns2_led, cdev);
enum ns2_led_modes mode; enum ns2_led_modes mode;
if (value == LED_OFF) if (value == LED_OFF)
mode = NS_V2_LED_OFF; mode = NS_V2_LED_OFF;
else if (led_dat->sata) else if (led->sata)
mode = NS_V2_LED_SATA; mode = NS_V2_LED_SATA;
else else
mode = NS_V2_LED_ON; mode = NS_V2_LED_ON;
ns2_led_set_mode(led_dat, mode); ns2_led_set_mode(led, mode);
} }
static int ns2_led_set_blocking(struct led_classdev *led_cdev, static int ns2_led_set_blocking(struct led_classdev *led_cdev,
...@@ -147,8 +142,7 @@ static ssize_t ns2_led_sata_store(struct device *dev, ...@@ -147,8 +142,7 @@ static ssize_t ns2_led_sata_store(struct device *dev,
const char *buff, size_t count) const char *buff, size_t count)
{ {
struct led_classdev *led_cdev = dev_get_drvdata(dev); struct led_classdev *led_cdev = dev_get_drvdata(dev);
struct ns2_led *led_dat = struct ns2_led *led = container_of(led_cdev, struct ns2_led, cdev);
container_of(led_cdev, struct ns2_led, cdev);
int ret; int ret;
unsigned long enable; unsigned long enable;
...@@ -158,18 +152,18 @@ static ssize_t ns2_led_sata_store(struct device *dev, ...@@ -158,18 +152,18 @@ static ssize_t ns2_led_sata_store(struct device *dev,
enable = !!enable; enable = !!enable;
if (led_dat->sata == enable) if (led->sata == enable)
goto exit; goto exit;
led_dat->sata = enable; led->sata = enable;
if (!led_get_brightness(led_cdev)) if (!led_get_brightness(led_cdev))
goto exit; goto exit;
if (enable) if (enable)
ns2_led_set_mode(led_dat, NS_V2_LED_SATA); ns2_led_set_mode(led, NS_V2_LED_SATA);
else else
ns2_led_set_mode(led_dat, NS_V2_LED_ON); ns2_led_set_mode(led, NS_V2_LED_ON);
exit: exit:
return count; return count;
...@@ -179,10 +173,9 @@ static ssize_t ns2_led_sata_show(struct device *dev, ...@@ -179,10 +173,9 @@ static ssize_t ns2_led_sata_show(struct device *dev,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
struct led_classdev *led_cdev = dev_get_drvdata(dev); struct led_classdev *led_cdev = dev_get_drvdata(dev);
struct ns2_led *led_dat = struct ns2_led *led = container_of(led_cdev, struct ns2_led, cdev);
container_of(led_cdev, struct ns2_led, cdev);
return sprintf(buf, "%d\n", led_dat->sata); return sprintf(buf, "%d\n", led->sata);
} }
static DEVICE_ATTR(sata, 0644, ns2_led_sata_show, ns2_led_sata_store); static DEVICE_ATTR(sata, 0644, ns2_led_sata_show, ns2_led_sata_store);
...@@ -194,40 +187,38 @@ static struct attribute *ns2_led_attrs[] = { ...@@ -194,40 +187,38 @@ static struct attribute *ns2_led_attrs[] = {
ATTRIBUTE_GROUPS(ns2_led); ATTRIBUTE_GROUPS(ns2_led);
static int static int
create_ns2_led(struct platform_device *pdev, struct ns2_led *led_dat, create_ns2_led(struct platform_device *pdev, struct ns2_led *led,
const struct ns2_led_of_one *template) const struct ns2_led_of_one *template)
{ {
int ret; int ret;
enum ns2_led_modes mode; enum ns2_led_modes mode;
rwlock_init(&led_dat->rw_lock); rwlock_init(&led->rw_lock);
led_dat->cdev.name = template->name; led->cdev.name = template->name;
led_dat->cdev.default_trigger = template->default_trigger; led->cdev.default_trigger = template->default_trigger;
led_dat->cdev.blink_set = NULL; led->cdev.blink_set = NULL;
led_dat->cdev.flags |= LED_CORE_SUSPENDRESUME; led->cdev.flags |= LED_CORE_SUSPENDRESUME;
led_dat->cdev.groups = ns2_led_groups; led->cdev.groups = ns2_led_groups;
led_dat->cmd = template->cmd; led->cmd = template->cmd;
led_dat->slow = template->slow; led->slow = template->slow;
led_dat->can_sleep = gpiod_cansleep(led_dat->cmd) | led->can_sleep = gpiod_cansleep(led->cmd) | gpiod_cansleep(led->slow);
gpiod_cansleep(led_dat->slow); if (led->can_sleep)
if (led_dat->can_sleep) led->cdev.brightness_set_blocking = ns2_led_set_blocking;
led_dat->cdev.brightness_set_blocking = ns2_led_set_blocking;
else else
led_dat->cdev.brightness_set = ns2_led_set; led->cdev.brightness_set = ns2_led_set;
led_dat->modval = template->modval; led->modval = template->modval;
led_dat->num_modes = template->num_modes; led->num_modes = template->num_modes;
ret = ns2_led_get_mode(led_dat, &mode); ret = ns2_led_get_mode(led, &mode);
if (ret < 0) if (ret < 0)
return ret; return ret;
/* Set LED initial state. */ /* Set LED initial state. */
led_dat->sata = (mode == NS_V2_LED_SATA) ? 1 : 0; led->sata = (mode == NS_V2_LED_SATA) ? 1 : 0;
led_dat->cdev.brightness = led->cdev.brightness = (mode == NS_V2_LED_OFF) ? LED_OFF : LED_FULL;
(mode == NS_V2_LED_OFF) ? LED_OFF : LED_FULL;
return devm_led_classdev_register(&pdev->dev, &led_dat->cdev); return devm_led_classdev_register(&pdev->dev, &led->cdev);
} }
static int ns2_leds_parse_one(struct device *dev, struct device_node *np, static int ns2_leds_parse_one(struct device *dev, struct device_node *np,
......
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