Skip to content

Commit 7c48159

Browse files
Eddie Jamespavelmachek
authored andcommitted
leds: pca955x: Let the core process the fwnode
Much of the fwnode processing in the PCA955x driver is now in the LEDs core driver, so pass the fwnode in the init data when registering the LED device. In order to preserve the existing naming scheme, check for an empty name and set it to the LED number. Signed-off-by: Eddie James <[email protected]> Signed-off-by: Pavel Machek <[email protected]>
1 parent e46cb6d commit 7c48159

File tree

1 file changed

+30
-28
lines changed

1 file changed

+30
-28
lines changed

drivers/leds/leds-pca955x.c

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,9 @@ struct pca955x_led {
127127
struct pca955x *pca955x;
128128
struct led_classdev led_cdev;
129129
int led_num; /* 0 .. 15 potentially */
130-
char name[32];
131130
u32 type;
132131
int default_state;
133-
const char *default_trigger;
132+
struct fwnode_handle *fwnode;
134133
};
135134

136135
struct pca955x_platform_data {
@@ -439,7 +438,6 @@ pca955x_get_pdata(struct i2c_client *client, struct pca955x_chipdef *chip)
439438
return ERR_PTR(-ENOMEM);
440439

441440
device_for_each_child_node(&client->dev, child) {
442-
const char *name;
443441
const char *state;
444442
u32 reg;
445443
int res;
@@ -448,17 +446,10 @@ pca955x_get_pdata(struct i2c_client *client, struct pca955x_chipdef *chip)
448446
if ((res != 0) || (reg >= chip->bits))
449447
continue;
450448

451-
res = fwnode_property_read_string(child, "label", &name);
452-
if ((res != 0) && is_of_node(child))
453-
name = to_of_node(child)->name;
454-
455449
led = &pdata->leds[reg];
456-
snprintf(led->name, sizeof(led->name), "%s", name);
457-
458450
led->type = PCA955X_TYPE_LED;
451+
led->fwnode = child;
459452
fwnode_property_read_u32(child, "type", &led->type);
460-
fwnode_property_read_string(child, "linux,default-trigger",
461-
&led->default_trigger);
462453

463454
if (!fwnode_property_read_string(child, "default-state",
464455
&state)) {
@@ -495,11 +486,14 @@ static int pca955x_probe(struct i2c_client *client,
495486
struct pca955x_led *pca955x_led;
496487
struct pca955x_chipdef *chip;
497488
struct led_classdev *led;
489+
struct led_init_data init_data;
498490
struct i2c_adapter *adapter;
499491
int i, err;
500492
struct pca955x_platform_data *pdata;
501493
int ngpios = 0;
494+
bool set_default_label = false;
502495
bool keep_pwm = false;
496+
char default_label[8];
503497

504498
chip = &pca955x_chipdefs[id->driver_data];
505499
adapter = client->adapter;
@@ -547,6 +541,9 @@ static int pca955x_probe(struct i2c_client *client,
547541
pca955x->client = client;
548542
pca955x->chipdef = chip;
549543

544+
init_data.devname_mandatory = false;
545+
init_data.devicename = "pca955x";
546+
550547
for (i = 0; i < chip->bits; i++) {
551548
pca955x_led = &pca955x->leds[i];
552549
pca955x_led->led_num = i;
@@ -560,23 +557,7 @@ static int pca955x_probe(struct i2c_client *client,
560557
ngpios++;
561558
break;
562559
case PCA955X_TYPE_LED:
563-
/*
564-
* Platform data can specify LED names and
565-
* default triggers
566-
*/
567-
if (pdata->leds[i].name[0] == '\0')
568-
snprintf(pdata->leds[i].name,
569-
sizeof(pdata->leds[i].name), "%d", i);
570-
571-
snprintf(pca955x_led->name, sizeof(pca955x_led->name),
572-
"pca955x:%s", pdata->leds[i].name);
573-
574560
led = &pca955x_led->led_cdev;
575-
if (pdata->leds[i].default_trigger)
576-
led->default_trigger =
577-
pdata->leds[i].default_trigger;
578-
579-
led->name = pca955x_led->name;
580561
led->brightness_set_blocking = pca955x_led_set;
581562
led->brightness_get = pca955x_led_get;
582563

@@ -592,7 +573,28 @@ static int pca955x_probe(struct i2c_client *client,
592573
return err;
593574
}
594575

595-
err = devm_led_classdev_register(&client->dev, led);
576+
init_data.fwnode = pdata->leds[i].fwnode;
577+
578+
if (is_of_node(init_data.fwnode)) {
579+
if (to_of_node(init_data.fwnode)->name[0] ==
580+
'\0')
581+
set_default_label = true;
582+
else
583+
set_default_label = false;
584+
} else {
585+
set_default_label = true;
586+
}
587+
588+
if (set_default_label) {
589+
snprintf(default_label, sizeof(default_label),
590+
"%d", i);
591+
init_data.default_label = default_label;
592+
} else {
593+
init_data.default_label = NULL;
594+
}
595+
596+
err = devm_led_classdev_register_ext(&client->dev, led,
597+
&init_data);
596598
if (err)
597599
return err;
598600

0 commit comments

Comments
 (0)