Skip to content

Commit

Permalink
leds: cr0014114: Use generic support for composing LED names
Browse files Browse the repository at this point in the history
Switch to using generic LED support for composing LED class
device name.

At this occassion remove initialization of struct led_classdev's
dev->of_node property in the driver, since now it will be taken from
fwnode assigned to struct led_init_data and passed to the new
devm_led_classdev_register_ext() API.

Signed-off-by: Jacek Anaszewski <[email protected]>
Cc: Oleh Kravchenko <[email protected]>
Acked-by: Pavel Machek <[email protected]>
  • Loading branch information
jacek-anaszewski committed Jul 25, 2019
1 parent 6c01a5c commit 889003c
Showing 1 changed file with 11 additions and 21 deletions.
32 changes: 11 additions & 21 deletions drivers/leds/leds-cr0014114.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <linux/of_device.h>
#include <linux/spi/spi.h>
#include <linux/workqueue.h>
#include <uapi/linux/uleds.h>

/*
* CR0014114 SPI protocol descrtiption:
Expand Down Expand Up @@ -40,8 +39,9 @@
#define CR_FW_DELAY_MSEC 10
#define CR_RECOUNT_DELAY (HZ * 3600)

#define CR_DEV_NAME "cr0014114"

struct cr0014114_led {
char name[LED_MAX_NAME_SIZE];
struct cr0014114 *priv;
struct led_classdev ldev;
u8 brightness;
Expand Down Expand Up @@ -167,8 +167,7 @@ static int cr0014114_set_sync(struct led_classdev *ldev,
struct cr0014114_led,
ldev);

dev_dbg(led->priv->dev, "Set brightness of %s to %d\n",
led->name, brightness);
dev_dbg(led->priv->dev, "Set brightness to %d\n", brightness);

mutex_lock(&led->priv->lock);
led->brightness = (u8)brightness;
Expand All @@ -183,41 +182,32 @@ static int cr0014114_probe_dt(struct cr0014114 *priv)
size_t i = 0;
struct cr0014114_led *led;
struct fwnode_handle *child;
struct device_node *np;
struct led_init_data init_data = {};
int ret;
const char *str;

device_for_each_child_node(priv->dev, child) {
np = to_of_node(child);
led = &priv->leds[i];

ret = fwnode_property_read_string(child, "label", &str);
if (ret)
snprintf(led->name, sizeof(led->name),
"cr0014114::");
else
snprintf(led->name, sizeof(led->name),
"cr0014114:%s", str);

fwnode_property_read_string(child, "linux,default-trigger",
&led->ldev.default_trigger);

led->priv = priv;
led->ldev.name = led->name;
led->ldev.max_brightness = CR_MAX_BRIGHTNESS;
led->ldev.brightness_set_blocking = cr0014114_set_sync;

ret = devm_led_classdev_register(priv->dev, &led->ldev);
init_data.fwnode = child;
init_data.devicename = CR_DEV_NAME;
init_data.default_label = ":";

ret = devm_led_classdev_register_ext(priv->dev, &led->ldev,
&init_data);
if (ret) {
dev_err(priv->dev,
"failed to register LED device %s, err %d",
led->name, ret);
"failed to register LED device, err %d", ret);
fwnode_handle_put(child);
return ret;
}

led->ldev.dev->of_node = np;

i++;
}

Expand Down

0 comments on commit 889003c

Please sign in to comment.