Skip to content

Commit

Permalink
leds: an30259a: 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.

Signed-off-by: Jacek Anaszewski <[email protected]>
Cc: Simon Shields <[email protected]>
Acked-by: Pavel Machek <[email protected]>
  • Loading branch information
jacek-anaszewski committed Jul 25, 2019
1 parent 91f1be8 commit 1817208
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions drivers/leds/leds-an30259a.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include <linux/mutex.h>
#include <linux/of.h>
#include <linux/regmap.h>
#include <uapi/linux/uleds.h>

#define AN30259A_MAX_LEDS 3

Expand Down Expand Up @@ -54,6 +53,8 @@
#define AN30259A_BLINK_MAX_TIME 7500 /* ms */
#define AN30259A_SLOPE_RESOLUTION 500 /* ms */

#define AN30259A_NAME "an30259a"

#define STATE_OFF 0
#define STATE_KEEP 1
#define STATE_ON 2
Expand All @@ -62,11 +63,11 @@ struct an30259a;

struct an30259a_led {
struct an30259a *chip;
struct fwnode_handle *fwnode;
struct led_classdev cdev;
u32 num;
u32 default_state;
bool sloping;
char label[LED_MAX_NAME_SIZE];
};

struct an30259a {
Expand Down Expand Up @@ -226,14 +227,7 @@ static int an30259a_dt_init(struct i2c_client *client,

led->num = source;
led->chip = chip;

if (of_property_read_string(child, "label", &str))
snprintf(led->label, sizeof(led->label), "an30259a::");
else
snprintf(led->label, sizeof(led->label), "an30259a:%s",
str);

led->cdev.name = led->label;
led->fwnode = of_fwnode_handle(child);

if (!of_property_read_string(child, "default-state", &str)) {
if (!strcmp(str, "on"))
Expand Down Expand Up @@ -312,13 +306,20 @@ static int an30259a_probe(struct i2c_client *client)
chip->regmap = devm_regmap_init_i2c(client, &an30259a_regmap_config);

for (i = 0; i < chip->num_leds; i++) {
struct led_init_data init_data = {};

an30259a_init_default_state(&chip->leds[i]);
chip->leds[i].cdev.brightness_set_blocking =
an30259a_brightness_set;
chip->leds[i].cdev.blink_set = an30259a_blink_set;

err = devm_led_classdev_register(&client->dev,
&chip->leds[i].cdev);
init_data.fwnode = chip->leds[i].fwnode;
init_data.devicename = AN30259A_NAME;
init_data.default_label = ":";

err = devm_led_classdev_register_ext(&client->dev,
&chip->leds[i].cdev,
&init_data);
if (err < 0)
goto exit;
}
Expand Down

0 comments on commit 1817208

Please sign in to comment.