Skip to content

Commit f14aa5e

Browse files
Kate Hsuanlag-linaro
authored andcommitted
leds: rgb: leds-ktd202x: Get device properties through fwnode to support ACPI
This LED controller is installed on a Xiaomi pad2 and it is an x86 platform. The original driver is based on the device tree and can't be used for this ACPI based system. This patch migrated the driver to use fwnode to access the properties. Moreover, the fwnode API supports the device tree so this work won't affect the original implementations. Signed-off-by: Kate Hsuan <[email protected]> Tested-by: André Apitzsch <[email protected]> # on BQ Aquaris M5 Reviewed-by: Hans de Goede <[email protected]> Reviewed-by: Andy Shevchenko <[email protected]> Signed-off-by: Hans de Goede <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Lee Jones <[email protected]>
1 parent 1613e60 commit f14aa5e

File tree

2 files changed

+34
-31
lines changed

2 files changed

+34
-31
lines changed

drivers/leds/rgb/Kconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ config LEDS_GROUP_MULTICOLOR
1717
config LEDS_KTD202X
1818
tristate "LED support for KTD202x Chips"
1919
depends on I2C
20-
depends on OF
2120
select REGMAP_I2C
2221
help
2322
This option enables support for the Kinetic KTD2026/KTD2027

drivers/leds/rgb/leds-ktd202x.c

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ struct ktd202x {
9999
struct device *dev;
100100
struct regmap *regmap;
101101
bool enabled;
102-
int num_leds;
102+
unsigned long num_leds;
103103
struct ktd202x_led leds[] __counted_by(num_leds);
104104
};
105105

@@ -381,39 +381,42 @@ static int ktd202x_blink_mc_set(struct led_classdev *cdev,
381381
mc->num_colors);
382382
}
383383

384-
static int ktd202x_setup_led_rgb(struct ktd202x *chip, struct device_node *np,
384+
static int ktd202x_setup_led_rgb(struct ktd202x *chip, struct fwnode_handle *fwnode,
385385
struct ktd202x_led *led, struct led_init_data *init_data)
386386
{
387+
struct fwnode_handle *child;
387388
struct led_classdev *cdev;
388-
struct device_node *child;
389389
struct mc_subled *info;
390390
int num_channels;
391391
int i = 0;
392392

393-
num_channels = of_get_available_child_count(np);
393+
num_channels = 0;
394+
fwnode_for_each_available_child_node(fwnode, child)
395+
num_channels++;
396+
394397
if (!num_channels || num_channels > chip->num_leds)
395398
return -EINVAL;
396399

397400
info = devm_kcalloc(chip->dev, num_channels, sizeof(*info), GFP_KERNEL);
398401
if (!info)
399402
return -ENOMEM;
400403

401-
for_each_available_child_of_node(np, child) {
404+
fwnode_for_each_available_child_node(fwnode, child) {
402405
u32 mono_color;
403406
u32 reg;
404407
int ret;
405408

406-
ret = of_property_read_u32(child, "reg", &reg);
409+
ret = fwnode_property_read_u32(child, "reg", &reg);
407410
if (ret != 0 || reg >= chip->num_leds) {
408-
dev_err(chip->dev, "invalid 'reg' of %pOFn\n", child);
409-
of_node_put(child);
410-
return -EINVAL;
411+
dev_err(chip->dev, "invalid 'reg' of %pfw\n", child);
412+
fwnode_handle_put(child);
413+
return ret;
411414
}
412415

413-
ret = of_property_read_u32(child, "color", &mono_color);
416+
ret = fwnode_property_read_u32(child, "color", &mono_color);
414417
if (ret < 0 && ret != -EINVAL) {
415-
dev_err(chip->dev, "failed to parse 'color' of %pOF\n", child);
416-
of_node_put(child);
418+
dev_err(chip->dev, "failed to parse 'color' of %pfw\n", child);
419+
fwnode_handle_put(child);
417420
return ret;
418421
}
419422

@@ -433,16 +436,16 @@ static int ktd202x_setup_led_rgb(struct ktd202x *chip, struct device_node *np,
433436
return devm_led_classdev_multicolor_register_ext(chip->dev, &led->mcdev, init_data);
434437
}
435438

436-
static int ktd202x_setup_led_single(struct ktd202x *chip, struct device_node *np,
439+
static int ktd202x_setup_led_single(struct ktd202x *chip, struct fwnode_handle *fwnode,
437440
struct ktd202x_led *led, struct led_init_data *init_data)
438441
{
439442
struct led_classdev *cdev;
440443
u32 reg;
441444
int ret;
442445

443-
ret = of_property_read_u32(np, "reg", &reg);
446+
ret = fwnode_property_read_u32(fwnode, "reg", &reg);
444447
if (ret != 0 || reg >= chip->num_leds) {
445-
dev_err(chip->dev, "invalid 'reg' of %pOFn\n", np);
448+
dev_err(chip->dev, "invalid 'reg' of %pfw\n", fwnode);
446449
return -EINVAL;
447450
}
448451
led->index = reg;
@@ -454,7 +457,7 @@ static int ktd202x_setup_led_single(struct ktd202x *chip, struct device_node *np
454457
return devm_led_classdev_register_ext(chip->dev, &led->cdev, init_data);
455458
}
456459

457-
static int ktd202x_add_led(struct ktd202x *chip, struct device_node *np, unsigned int index)
460+
static int ktd202x_add_led(struct ktd202x *chip, struct fwnode_handle *fwnode, unsigned int index)
458461
{
459462
struct ktd202x_led *led = &chip->leds[index];
460463
struct led_init_data init_data = {};
@@ -463,21 +466,21 @@ static int ktd202x_add_led(struct ktd202x *chip, struct device_node *np, unsigne
463466
int ret;
464467

465468
/* Color property is optional in single color case */
466-
ret = of_property_read_u32(np, "color", &color);
469+
ret = fwnode_property_read_u32(fwnode, "color", &color);
467470
if (ret < 0 && ret != -EINVAL) {
468-
dev_err(chip->dev, "failed to parse 'color' of %pOF\n", np);
471+
dev_err(chip->dev, "failed to parse 'color' of %pfw\n", fwnode);
469472
return ret;
470473
}
471474

472475
led->chip = chip;
473-
init_data.fwnode = of_fwnode_handle(np);
476+
init_data.fwnode = fwnode;
474477

475478
if (color == LED_COLOR_ID_RGB) {
476479
cdev = &led->mcdev.led_cdev;
477-
ret = ktd202x_setup_led_rgb(chip, np, led, &init_data);
480+
ret = ktd202x_setup_led_rgb(chip, fwnode, led, &init_data);
478481
} else {
479482
cdev = &led->cdev;
480-
ret = ktd202x_setup_led_single(chip, np, led, &init_data);
483+
ret = ktd202x_setup_led_single(chip, fwnode, led, &init_data);
481484
}
482485

483486
if (ret) {
@@ -490,15 +493,14 @@ static int ktd202x_add_led(struct ktd202x *chip, struct device_node *np, unsigne
490493
return 0;
491494
}
492495

493-
static int ktd202x_probe_dt(struct ktd202x *chip)
496+
static int ktd202x_probe_fw(struct ktd202x *chip)
494497
{
495-
struct device_node *np = dev_of_node(chip->dev), *child;
498+
struct fwnode_handle *child;
499+
struct device *dev = chip->dev;
496500
int count;
497501
int i = 0;
498502

499-
chip->num_leds = (int)(unsigned long)of_device_get_match_data(chip->dev);
500-
501-
count = of_get_available_child_count(np);
503+
count = device_get_child_node_count(dev);
502504
if (!count || count > chip->num_leds)
503505
return -EINVAL;
504506

@@ -507,11 +509,11 @@ static int ktd202x_probe_dt(struct ktd202x *chip)
507509
/* Allow the device to execute the complete reset */
508510
usleep_range(200, 300);
509511

510-
for_each_available_child_of_node(np, child) {
512+
device_for_each_child_node(dev, child) {
511513
int ret = ktd202x_add_led(chip, child, i);
512514

513515
if (ret) {
514-
of_node_put(child);
516+
fwnode_handle_put(child);
515517
return ret;
516518
}
517519
i++;
@@ -554,6 +556,8 @@ static int ktd202x_probe(struct i2c_client *client)
554556
return ret;
555557
}
556558

559+
chip->num_leds = (unsigned long)i2c_get_match_data(client);
560+
557561
chip->regulators[0].supply = "vin";
558562
chip->regulators[1].supply = "vio";
559563
ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(chip->regulators), chip->regulators);
@@ -568,7 +572,7 @@ static int ktd202x_probe(struct i2c_client *client)
568572
return ret;
569573
}
570574

571-
ret = ktd202x_probe_dt(chip);
575+
ret = ktd202x_probe_fw(chip);
572576
if (ret < 0) {
573577
regulator_bulk_disable(ARRAY_SIZE(chip->regulators), chip->regulators);
574578
return ret;
@@ -605,7 +609,7 @@ static void ktd202x_shutdown(struct i2c_client *client)
605609
static const struct of_device_id ktd202x_match_table[] = {
606610
{ .compatible = "kinetic,ktd2026", .data = (void *)KTD2026_NUM_LEDS },
607611
{ .compatible = "kinetic,ktd2027", .data = (void *)KTD2027_NUM_LEDS },
608-
{},
612+
{}
609613
};
610614
MODULE_DEVICE_TABLE(of, ktd202x_match_table);
611615

0 commit comments

Comments
 (0)