Skip to contentSkip to conversation

KTD2026 indicator LED for X86 Xiaomi Pad2

PATCH Superseded Kate Hsuan 2 participants 5 messages Feb 7, 2024 – Feb 15, 2024

Subsystems (4)

v1 of 7 Superseded Latest is v7 →

lore
Share & tools
lore

Kate Hsuan

author
#0 lore raw

cover KTD2026 indicator LED for X86 Xiaomi Pad2

This patch added the support for Xiaomi Pad2 indicator LED. This work included two parts.
1. Added the KTD2026 swnode description to describe the LED controller.
2. Migrated the original driver to fwnode to support x86 platform.

Moreover, the LED trigger is set to bq27520-0-charging for Xiaomi Pad2 so the LED will be turned on when charging.

Kate Hsuan (2):
platform: x86-android-tablets: other: Add swnode for Xiaomi pad2
indicator LED
leds: rgb: leds-ktd202x: Get device properties through fwnode to
support ACPI

 drivers/leds/rgb/Kconfig                      |  1 -
 drivers/leds/rgb/leds-ktd202x.c               | 68 ++++++++++-----
 .../platform/x86/x86-android-tablets/other.c  | 85 +++++++++++++++++++
 .../x86/x86-android-tablets/shared-psy-info.h |  2 +
 4 files changed, 132 insertions(+), 24 deletions(-)
Signature · 1 line
2.43.0
author
#1 lore raw

PATCH 1/2 platform: x86-android-tablets: other: Add swnode for Xiaomi pad2 indicator LED

The KTD2026 LED controller manages the indicator LED for Xiaomi pad2. This work added a description for this RGB LED controller and also set a trigger to indicate the charging event (bq27520-0-charging). When it is charging, the indicator LED will be turned on.

---
 .../platform/x86/x86-android-tablets/other.c  | 85 +++++++++++++++++++
 .../x86/x86-android-tablets/shared-psy-info.h |  2 +
 2 files changed, 87 insertions(+)
drivers/platform/x86/x86-android-tablets/other.c +85 -0
index bc6bbf7ec6ea..542ef6667b7b 100644
@@ -12,6 +12,7 @@
 #include <linux/gpio/machine.h>
 #include <linux/input.h>
 #include <linux/platform_device.h>
+#include <dt-bindings/leds/common.h>
 
 #include "shared-psy-info.h"
 #include "x86-android-tablets.h"
@@ -593,6 +594,87 @@ const struct x86_dev_info whitelabel_tm800a550l_info __initconst = {
 	.gpiod_lookup_tables = whitelabel_tm800a550l_gpios,
 };
 
+/*
+ * The fwnode for ktd2026 on Xaomi pad2. It composed of a RGB LED node
+ * with three subnodes for each color (B/G/R). The RGB LED node is named
+ * "multi-led" to align with the name in the device tree.
+ */
+
+/* main fwnode for ktd2026 */
+static const struct software_node ktd2026_node = {
+};
+
+static const struct property_entry ktd2026_rgb_led_props[] = {
+	PROPERTY_ENTRY_U32("reg", 0),
+	PROPERTY_ENTRY_U32("color", LED_COLOR_ID_RGB),
+	PROPERTY_ENTRY_STRING("function", "indicator"),
+	PROPERTY_ENTRY_STRING("linux,default-trigger",
+			      "bq27520-0-charging"),
+
+	{ }
+};
+
+static const struct software_node ktd2026_rgb_led_node = {
+	.name = "multi-led",
+	.properties = ktd2026_rgb_led_props,
+	.parent = &ktd2026_node,
+};
+
+/* B */
+static const struct property_entry ktd2026_red_led_props[] = {
+	PROPERTY_ENTRY_U32("reg", 0),
+	PROPERTY_ENTRY_U32("color", LED_COLOR_ID_BLUE),
+	{ }
+};
+
+static const struct software_node ktd2026_red_led_node = {
+	.properties = ktd2026_red_led_props,
+	.parent = &ktd2026_rgb_led_node,
+};
+
+/* G */
+static const struct property_entry ktd2026_green_led_props[] = {
+	PROPERTY_ENTRY_U32("reg", 1),
+	PROPERTY_ENTRY_U32("color", LED_COLOR_ID_GREEN),
+	{ }
+};
+
+static const struct software_node ktd2026_green_led_node = {
+	.properties = ktd2026_green_led_props,
+	.parent = &ktd2026_rgb_led_node,
+};
+
+/* R */
+static const struct property_entry ktd2026_blue_led_props[] = {
+	PROPERTY_ENTRY_U32("reg", 2),
+	PROPERTY_ENTRY_U32("color", LED_COLOR_ID_RED),
+	{ }
+};
+
+static const struct software_node ktd2026_blue_led_node = {
+	.properties = ktd2026_blue_led_props,
+	.parent = &ktd2026_rgb_led_node,
+};
+
+static const struct software_node *ktd2026_node_group[] = {
+	&ktd2026_node,
+	&ktd2026_rgb_led_node,
+	&ktd2026_red_led_node,
+	&ktd2026_green_led_node,
+	&ktd2026_blue_led_node,
+	NULL
+};
+
+static int __init xiaomi_mipad2_init(void)
+{
+	return software_node_register_node_group(ktd2026_node_group);
+}
+
+static void xiaomi_mipad2_exit(void)
+{
+	software_node_unregister_node_group(ktd2026_node_group);
+}
+
 /*
  * If the EFI bootloader is not Xiaomi's own signed Android loader, then the
  * Xiaomi Mi Pad 2 X86 tablet sets OSID in the DSDT to 1 (Windows), causing
@@ -616,6 +698,7 @@ static const struct x86_i2c_client_info xiaomi_mipad2_i2c_clients[] __initconst
 			.type = "ktd2026",
 			.addr = 0x30,
 			.dev_name = "ktd2026",
+			.swnode = &ktd2026_node,
 		},
 		.adapter_path = "\\_SB_.PCI0.I2C3",
 	},
@@ -624,4 +707,6 @@ static const struct x86_i2c_client_info xiaomi_mipad2_i2c_clients[] __initconst
 const struct x86_dev_info xiaomi_mipad2_info __initconst = {
 	.i2c_client_info = xiaomi_mipad2_i2c_clients,
 	.i2c_client_count = ARRAY_SIZE(xiaomi_mipad2_i2c_clients),
+	.init = xiaomi_mipad2_init,
+	.exit = xiaomi_mipad2_exit,
 };
drivers/platform/x86/x86-android-tablets/shared-psy-info.h +2 -0
index c2d2968cddc2..8c33ec47ee12 100644
@@ -29,4 +29,6 @@ extern const char * const bq24190_modules[];
 extern const struct platform_device_info int3496_pdevs[];
 extern struct gpiod_lookup_table int3496_reference_gpios;
 
+extern const struct software_node ktd2026_leds_node;
+
 #endif
Signature · 1 line
2.43.0
author
#2 lore raw

PATCH 2/2 leds: rgb: leds-ktd202x: Get device properties through fwnode to support ACPI

In reply to Kate Hsuan

This LED controller also 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 device tree so this work would affect the original implementations.

---
 drivers/leds/rgb/Kconfig        |  1 -
 drivers/leds/rgb/leds-ktd202x.c | 68 ++++++++++++++++++++++-----------
 2 files changed, 45 insertions(+), 24 deletions(-)
drivers/leds/rgb/Kconfig +0 -1
index a6a21f564673..f245dbd9a163 100644
@@ -17,7 +17,6 @@ config LEDS_GROUP_MULTICOLOR
 config LEDS_KTD202X
 	tristate "LED support for KTD202x Chips"
 	depends on I2C
-	depends on OF
 	select REGMAP_I2C
 	help
 	  This option enables support for the Kinetic KTD2026/KTD2027
drivers/leds/rgb/leds-ktd202x.c +45 -23

184 lines not on this page · raw message

Signature · 1 line
2.43.0
#3 lore raw

Re: [PATCH 2/2] leds: rgb: leds-ktd202x: Get device properties through fwnode to support ACPI

Hi,

Am Mittwoch, dem 07.02.2024 um 14:10 +0800 schrieb Kate Hsuan:

Quoted 5 lines

This LED controller also 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 device tree so this work would affect the original

would -> won't ?

Quoted 33 lines

implementations.

---
 drivers/leds/rgb/Kconfig        |  1 - drivers/leds/rgb/leds-ktd202x.c | 68 ++++++++++++++++++++++--------- --

 2 files changed, 45 insertions(+), 24 deletions(-)
drivers/leds/rgb/Kconfig +0 -0
index a6a21f564673..f245dbd9a163 100644
@@ -17,7 +17,6 @@ config LEDS_GROUP_MULTICOLOR

 config LEDS_KTD202X
  tristate "LED support for KTD202x Chips"
  depends on I2C

drivers/leds/rgb/Kconfig +0 -1
-	depends on OF

  select REGMAP_I2C
  help
    This option enables support for the Kinetic KTD2026/KTD2027

drivers/leds/rgb/leds- renamed from drivers/leds/rgb/leds-ktd202x.c +0 -0

ktd202x.c
index 514965795a10..a1aef62e3db5 100644

drivers/leds/rgb/leds-ktd202x.c +0 -0
@@ -112,6 +112,8 @@ static int ktd202x_chip_disable(struct ktd202x
 *chip)


  regmap_write(chip->regmap, KTD202X_REG_RESET_CONTROL, KTD202X_ENABLE_CTRL_SLEEP);

drivers/leds/rgb/leds-ktd202x.c static int ktd202x_chip_disable(struct ktd202x *chip) · line 115

Quoted 1 line
drivers/leds/rgb/leds-ktd202x.c +1 -0
+	usleep_range(500, 600);

Why have you added the sleep?

Quoted 19 lines

+
  ret = regulator_bulk_disable(ARRAY_SIZE(chip->regulators), chip->regulators);
  if (ret) {
  dev_err(chip->dev, "Failed to disable regulators:
%d\n", ret);

drivers/leds/rgb/leds-ktd202x.c +0 -0
@@ -381,16 +383,18 @@ static int ktd202x_blink_mc_set(struct
 led_classdev *cdev,
  				 mc->num_colors);
  }


-static int ktd202x_setup_led_rgb(struct ktd202x *chip, struct device_node *np,
+static int ktd202x_setup_led_rgb(struct ktd202x *chip, struct fwnode_handle *np,
  struct ktd202x_led *led, struct led_init_data *init_data)
 {
  struct led_classdev *cdev;

drivers/leds/rgb/leds-ktd202x.c static int ktd202x_blink_mc_set(struct led_classdev *cdev, · line 390

Quoted 2 lines
drivers/leds/rgb/leds-ktd202x.c +1 -1
-	struct device_node *child;
+	struct fwnode_handle *child;

Nit, swap the above lines for reverse Christmas tree.

Quoted 104 lines

  struct mc_subled *info;

drivers/leds/rgb/leds-ktd202x.c +1 -1
-	int num_channels;
+	int num_channels = 0;

  int i = 0;

drivers/leds/rgb/leds-ktd202x.c +3 -1
-	num_channels = of_get_available_child_count(np);
+	fwnode_for_each_available_child_node(np, child) {
+		num_channels++;
+	}

  if (!num_channels || num_channels > chip->num_leds) return -EINVAL;

drivers/leds/rgb/leds-ktd202x.c +0 -0
@@ -398,22 +402,22 @@ static int ktd202x_setup_led_rgb(struct ktd202x
 *chip, struct device_node *np,
  	if (!info)
  		return -ENOMEM;

drivers/leds/rgb/leds-ktd202x.c +1 -1
-	for_each_available_child_of_node(np, child) {
+	fwnode_for_each_available_child_node(np, child) {

  u32 mono_color;
  u32 reg;
  int ret;

drivers/leds/rgb/leds-ktd202x.c +1 -1
-		ret = of_property_read_u32(child, "reg", &reg);
+		ret = fwnode_property_read_u32(child, "reg", &reg);

  if (ret != 0 || reg >= chip->num_leds) { dev_err(chip->dev, "invalid 'reg' of %pOFn\n", child);

drivers/leds/rgb/leds-ktd202x.c +1 -1
-			of_node_put(child);
+			fwnode_handle_put(child);

  return -EINVAL;
  }

drivers/leds/rgb/leds-ktd202x.c +0 -1
-		ret = of_property_read_u32(child, "color",

&mono_color);

drivers/leds/rgb/leds-ktd202x.c +1 -0
+		ret = fwnode_property_read_u32(child, "color",

&mono_color);
  if (ret < 0 && ret != -EINVAL) { dev_err(chip->dev, "failed to parse 'color' of %pOF\n", child);

drivers/leds/rgb/leds-ktd202x.c +1 -1
-			of_node_put(child);
+			fwnode_handle_put(child);

  return ret;
  }

drivers/leds/rgb/leds-ktd202x.c +0 -0
@@ -433,14 +437,14 @@ static int ktd202x_setup_led_rgb(struct ktd202x
 *chip, struct device_node *np,
  	return devm_led_classdev_multicolor_register_ext(chip->dev,
 &led->mcdev, init_data);
  }


-static int ktd202x_setup_led_single(struct ktd202x *chip, struct device_node *np,
+static int ktd202x_setup_led_single(struct ktd202x *chip, struct fwnode_handle *np,
      struct ktd202x_led *led, struct led_init_data *init_data)
 {
  struct led_classdev *cdev;
  u32 reg;
  int ret;

drivers/leds/rgb/leds-ktd202x.c +1 -1
-	ret = of_property_read_u32(np, "reg", &reg);
+	ret = fwnode_property_read_u32(np, "reg", &reg);

  if (ret != 0 || reg >= chip->num_leds) { dev_err(chip->dev, "invalid 'reg' of %pOFn\n", np); return -EINVAL;

drivers/leds/rgb/leds-ktd202x.c +0 -0
@@ -454,7 +458,7 @@ static int ktd202x_setup_led_single(struct

ktd202x *chip, struct device_node *np
  return devm_led_classdev_register_ext(chip->dev, &led->cdev, init_data);
 }

-static int ktd202x_add_led(struct ktd202x *chip, struct device_node *np, unsigned int index)
+static int ktd202x_add_led(struct ktd202x *chip, struct fwnode_handle *np, unsigned int index)
 {
  struct ktd202x_led *led = &chip->leds[index]; struct led_init_data init_data = {};

drivers/leds/rgb/leds-ktd202x.c +0 -0
@@ -463,14 +467,14 @@ static int ktd202x_add_led(struct ktd202x
 *chip, struct device_node *np, unsigne
  	int ret;


  /* Color property is optional in single color case */

drivers/leds/rgb/leds-ktd202x.c +1 -1
-	ret = of_property_read_u32(np, "color", &color);
+	ret = fwnode_property_read_u32(np, "color", &color);

  if (ret < 0 && ret != -EINVAL) { dev_err(chip->dev, "failed to parse 'color' of %pOF\n", np);
  return ret;
  }

  led->chip = chip;

drivers/leds/rgb/leds-ktd202x.c +1 -1
-	init_data.fwnode = of_fwnode_handle(np);
+	init_data.fwnode = np;


  if (color == LED_COLOR_ID_RGB) {
  cdev = &led->mcdev.led_cdev;

drivers/leds/rgb/leds-ktd202x.c +0 -0
@@ -492,26 +496,30 @@ static int ktd202x_add_led(struct ktd202x
 *chip, struct device_node *np, unsigne


 static int ktd202x_probe_dt(struct ktd202x *chip) {

drivers/leds/rgb/leds-ktd202x.c static int ktd202x_add_led(struct ktd202x *chip, struct device_node *np, unsigne · line 500

Quoted 4 lines
drivers/leds/rgb/leds-ktd202x.c +2 -2
-	struct device_node *np = dev_of_node(chip->dev), *child;
-	int count;
+	struct device *dev = chip->dev;
+	struct fwnode_handle *np, *child;

Nit, swap the above lines.

drivers/leds/rgb/leds-ktd202x.c

Quoted 1 line
drivers/leds/rgb/leds-ktd202x.c +1 -0
+	int count = 0;

Un-needed init.

Quoted 31 lines

  int i = 0;

drivers/leds/rgb/leds-ktd202x.c +0 -1
-	chip->num_leds = (int)(unsigned

long)of_device_get_match_data(chip->dev);

drivers/leds/rgb/leds-ktd202x.c +1 -0
+	count = device_get_child_node_count(dev);

drivers/leds/rgb/leds-ktd202x.c +0 -1
-	count = of_get_available_child_count(np);

  if (!count || count > chip->num_leds)
  return -EINVAL;

drivers/leds/rgb/leds-ktd202x.c +4 -0
+	np = dev_fwnode(chip->dev);
+	if (!np)
+		return -ENODEV;
+

  regmap_write(chip->regmap, KTD202X_REG_RESET_CONTROL, KTD202X_RSTR_RESET);

  /* Allow the device to execute the complete reset */ usleep_range(200, 300);

drivers/leds/rgb/leds-ktd202x.c +1 -1
-	for_each_available_child_of_node(np, child) {
+	fwnode_for_each_available_child_node(np, child) {

  int ret = ktd202x_add_led(chip, child, i);
  if (ret) {

drivers/leds/rgb/leds-ktd202x.c +1 -1
-			of_node_put(child);
+			fwnode_handle_put(child);

  return ret;
  }
  i++;

drivers/leds/rgb/leds-ktd202x.c static int ktd202x_probe(struct i2c_client · line 545

Quoted 6 lines
drivers/leds/rgb/leds-ktd202x.c +1 -1
@@ -533,7 +541,7 @@ static int ktd202x_probe(struct i2c_client
 *client)
  {
  	struct device *dev = &client->dev;
  	struct ktd202x *chip;
-	int count;
+	int count = 0;

Un-needed init.

Quoted 41 lines
drivers/leds/rgb/leds-ktd202x.c +0 -0
  	int ret;


  count = device_get_child_node_count(dev);

drivers/leds/rgb/leds-ktd202x.c +0 -0
@@ -568,6 +576,8 @@ static int ktd202x_probe(struct i2c_client
 *client)
  		return ret;
  	}

drivers/leds/rgb/leds-ktd202x.c +1 -0
+	chip->num_leds = (int) (unsigned

long)i2c_get_match_data(client);
+
  ret = ktd202x_probe_dt(chip);
  if (ret < 0) { regulator_bulk_disable(ARRAY_SIZE(chip->regulators), chip->regulators);

drivers/leds/rgb/leds-ktd202x.c +0 -0
@@ -602,21 +612,33 @@ static void ktd202x_shutdown(struct i2c_client
 *client)
  	regmap_write(chip->regmap, KTD202X_REG_RESET_CONTROL,
 KTD202X_RSTR_RESET);
  }

drivers/leds/rgb/leds-ktd202x.c +8 -0
+static const struct i2c_device_id ktd202x_id[] = {
+	{"ktd2026", KTD2026_NUM_LEDS},
+	{"ktd2027", KTD2027_NUM_LEDS},
+	{},
+};
+MODULE_DEVICE_TABLE(i2c, ktd202x_id);
+
+#ifndef CONFIG_ACPI

 static const struct of_device_id ktd202x_match_table[] = { { .compatible = "kinetic,ktd2026", .data = (void *)KTD2026_NUM_LEDS },
  { .compatible = "kinetic,ktd2027", .data = (void *)KTD2027_NUM_LEDS },
  {},
 };
 MODULE_DEVICE_TABLE(of, ktd202x_match_table); +#endif

 static struct i2c_driver ktd202x_driver = { .driver = {

drivers/leds/rgb/leds-ktd202x.c static void ktd202x_shutdown(struct i2c_client *client) · line 633

Quoted 3 lines
drivers/leds/rgb/leds-ktd202x.c +1 -2
-		.name = "leds-ktd202x",
-		.of_match_table = ktd202x_match_table,
+		.name	= "leds-ktd202x",

Why was the space after "name" replaced by tab?

drivers/leds/rgb/leds-ktd202x.c

Quoted 2 lines
drivers/leds/rgb/leds-ktd202x.c +2 -0
+#ifndef CONFIG_ACPI
+		.of_match_table = ktd20xx_match_table,

Typo: ktd20xx_match_table -> ktd202x_match_table

André

Quoted 9 lines

+#endif
  },
  .probe = ktd202x_probe,
  .remove = ktd202x_remove,
  .shutdown = ktd202x_shutdown,

drivers/leds/rgb/leds-ktd202x.c +1 -0
+	.id_table = ktd202x_id,

 };
 module_i2c_driver(ktd202x_driver);

author
#4 lore raw

Re: [PATCH 2/2] leds: rgb: leds-ktd202x: Get device properties through fwnode to support ACPI

Hi,

Thank you for your review.

Sorry for the late reply. I came back from holiday.

Quoted 10 lines · André Apitzsch

Hi,

Am Mittwoch, dem 07.02.2024 um 14:10 +0800 schrieb Kate Hsuan:

Quoted 5 lines

This LED controller also 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 device tree so this work would affect the original

would -> won't ?

won't

Quoted 31 lines
Quoted 31 lines

implementations.

---
 drivers/leds/rgb/Kconfig        |  1 -
 drivers/leds/rgb/leds-ktd202x.c | 68 ++++++++++++++++++++++---------
--
 2 files changed, 45 insertions(+), 24 deletions(-)
drivers/leds/rgb/Kconfig +0 -1
index a6a21f564673..f245dbd9a163 100644
@@ -17,7 +17,6 @@ config LEDS_GROUP_MULTICOLOR
 config LEDS_KTD202X
      tristate "LED support for KTD202x Chips"
      depends on I2C
-     depends on OF
      select REGMAP_I2C
      help
        This option enables support for the Kinetic

KTD2026/KTD2027

drivers/leds/rgb/leds- renamed from drivers/leds/rgb/leds-ktd202x.c +0 -0

ktd202x.c
index 514965795a10..a1aef62e3db5 100644

drivers/leds/rgb/leds-ktd202x.c +0 -0
@@ -112,6 +112,8 @@ static int ktd202x_chip_disable(struct ktd202x
 *chip)
 
Quoted 5 lines

drivers/leds/rgb/leds-ktd202x.c static int ktd202x_chip_disable(struct ktd202x *chip) · line 115

Quoted 4 lines
drivers/leds/rgb/leds-ktd202x.c +1 -0
      regmap_write(chip->regmap, KTD202X_REG_RESET_CONTROL,
 KTD202X_ENABLE_CTRL_SLEEP);
 
+     usleep_range(500, 600);

Why have you added the sleep?

When removing the module, a WARN_ON() shown as the following URL will be triggered. It happens randomly.
I tried to mitigate it through a sleep.
https://elixir.bootlin.com/linux/latest/source/drivers/regulator/core.c#L2396

Quoted 12 lines
Quoted 12 lines
drivers/leds/rgb/leds-ktd202x.c +1 -0
+
      ret = regulator_bulk_disable(ARRAY_SIZE(chip->regulators),
chip->regulators);
      if (ret) {
              dev_err(chip->dev, "Failed to disable regulators:

%d\n", ret);

drivers/leds/rgb/leds-ktd202x.c +0 -0
@@ -381,16 +383,18 @@ static int ktd202x_blink_mc_set(struct
 led_classdev *cdev,
                               mc->num_colors);
 }
 
Quoted 11 lines

drivers/leds/rgb/leds-ktd202x.c static int ktd202x_blink_mc_set(struct · line 394

Quoted 10 lines
drivers/leds/rgb/leds-ktd202x.c +2 -2
-static int ktd202x_setup_led_rgb(struct ktd202x *chip, struct
 device_node *np,
+static int ktd202x_setup_led_rgb(struct ktd202x *chip, struct
 fwnode_handle *np,
                               struct ktd202x_led *led, struct
 led_init_data *init_data)
 {
      struct led_classdev *cdev;
-     struct device_node *child;
+     struct fwnode_handle *child;

Nit, swap the above lines for reverse Christmas tree.

okay

Quoted 111 lines
Quoted 101 lines
drivers/leds/rgb/leds-ktd202x.c +8 -6
      struct mc_subled *info;
-     int num_channels;
+     int num_channels = 0;
      int i = 0;
 
-     num_channels = of_get_available_child_count(np);
+     fwnode_for_each_available_child_node(np, child) {
+             num_channels++;
+     }
      if (!num_channels || num_channels > chip->num_leds)
              return -EINVAL;
@@ -398,22 +402,22 @@ static int ktd202x_setup_led_rgb(struct ktd202x
 *chip, struct device_node *np,
      if (!info)
              return -ENOMEM;
 
-     for_each_available_child_of_node(np, child) {
+     fwnode_for_each_available_child_node(np, child) {
              u32 mono_color;
              u32 reg;
              int ret;
 
-             ret = of_property_read_u32(child, "reg", &reg);
+             ret = fwnode_property_read_u32(child, "reg", &reg);
              if (ret != 0 || reg >= chip->num_leds) {
                      dev_err(chip->dev, "invalid 'reg' of
 %pOFn\n", child);
-                     of_node_put(child);
+                     fwnode_handle_put(child);
                      return -EINVAL;
              }
 
-             ret = of_property_read_u32(child, "color",
 &mono_color);
+             ret = fwnode_property_read_u32(child, "color",
 &mono_color);
              if (ret < 0 && ret != -EINVAL) {
                      dev_err(chip->dev, "failed to parse 'color'

of %pOF\n", child);

drivers/leds/rgb/leds-ktd202x.c +3 -3
-                     of_node_put(child);
+                     fwnode_handle_put(child);
                      return ret;
              }
@@ -433,14 +437,14 @@ static int ktd202x_setup_led_rgb(struct ktd202x
 *chip, struct device_node *np,
      return devm_led_classdev_multicolor_register_ext(chip->dev,
 &led->mcdev, init_data);
 }
 
-static int ktd202x_setup_led_single(struct ktd202x *chip, struct
 device_node *np,
+static int ktd202x_setup_led_single(struct ktd202x *chip, struct
 fwnode_handle *np,
                                  struct ktd202x_led *led, struct
 led_init_data *init_data)
 {
      struct led_classdev *cdev;
      u32 reg;
      int ret;
 
-     ret = of_property_read_u32(np, "reg", &reg);
+     ret = fwnode_property_read_u32(np, "reg", &reg);
      if (ret != 0 || reg >= chip->num_leds) {
              dev_err(chip->dev, "invalid 'reg' of %pOFn\n", np);
              return -EINVAL;
@@ -454,7 +458,7 @@ static int ktd202x_setup_led_single(struct

ktd202x *chip, struct device_node *np

      return devm_led_classdev_register_ext(chip->dev, &led->cdev,

init_data);
}

-static int ktd202x_add_led(struct ktd202x *chip, struct device_node *np, unsigned int index)
+static int ktd202x_add_led(struct ktd202x *chip, struct fwnode_handle *np, unsigned int index)

 {
      struct ktd202x_led *led = &chip->leds[index];
      struct led_init_data init_data = {};
drivers/leds/rgb/leds-ktd202x.c +2 -2
@@ -463,14 +467,14 @@ static int ktd202x_add_led(struct ktd202x
 *chip, struct device_node *np, unsigne
      int ret;
 
      /* Color property is optional in single color case */
-     ret = of_property_read_u32(np, "color", &color);
+     ret = fwnode_property_read_u32(np, "color", &color);
      if (ret < 0 && ret != -EINVAL) {
              dev_err(chip->dev, "failed to parse 'color' of
 %pOF\n", np);
              return ret;
      }
 
      led->chip = chip;
-     init_data.fwnode = of_fwnode_handle(np);
+     init_data.fwnode = np;
 
      if (color == LED_COLOR_ID_RGB) {
              cdev = &led->mcdev.led_cdev;

drivers/leds/rgb/leds-ktd202x.c static int ktd202x_add_led(struct ktd202x · line 501

Quoted 8 lines
drivers/leds/rgb/leds-ktd202x.c +2 -2
@@ -492,26 +496,30 @@ static int ktd202x_add_led(struct ktd202x
 *chip, struct device_node *np, unsigne
 
 static int ktd202x_probe_dt(struct ktd202x *chip)
 {
-     struct device_node *np = dev_of_node(chip->dev), *child;
-     int count;
+     struct device *dev = chip->dev;
+     struct fwnode_handle *np, *child;

Nit, swap the above lines.

Quoted 2 lines

drivers/leds/rgb/leds-ktd202x.c static int ktd202x_add_led(struct ktd202x · line 502

Quoted 1 line
drivers/leds/rgb/leds-ktd202x.c +1 -0
+     int count = 0;

Un-needed init.

Okay

Quoted 25 lines
Quoted 25 lines
drivers/leds/rgb/leds-ktd202x.c +6 -3
      int i = 0;
 
-     chip->num_leds = (int)(unsigned
 long)of_device_get_match_data(chip->dev);
+     count = device_get_child_node_count(dev);
 
-     count = of_get_available_child_count(np);
      if (!count || count > chip->num_leds)
              return -EINVAL;
 
+     np = dev_fwnode(chip->dev);
+     if (!np)
+             return -ENODEV;
+
      regmap_write(chip->regmap, KTD202X_REG_RESET_CONTROL,
 KTD202X_RSTR_RESET);
 
      /* Allow the device to execute the complete reset */
      usleep_range(200, 300);
 
-     for_each_available_child_of_node(np, child) {
+     fwnode_for_each_available_child_node(np, child) {
              int ret = ktd202x_add_led(chip, child, i);
 
Quoted 14 lines

drivers/leds/rgb/leds-ktd202x.c static int ktd202x_probe(struct i2c_client · line 545

Quoted 13 lines
drivers/leds/rgb/leds-ktd202x.c +1 -1
              if (ret) {
-                     of_node_put(child);
+                     fwnode_handle_put(child);
                      return ret;
              }
              i++;
drivers/leds/rgb/leds-ktd202x.c +1 -1
@@ -533,7 +541,7 @@ static int ktd202x_probe(struct i2c_client
 *client)
 {
      struct device *dev = &client->dev;
      struct ktd202x *chip;
-     int count;
+     int count = 0;

Un-needed init.

Okay.

Quoted 40 lines
Quoted 40 lines
drivers/leds/rgb/leds-ktd202x.c +0 -0
      int ret;
 
      count = device_get_child_node_count(dev);
drivers/leds/rgb/leds-ktd202x.c +2 -0
@@ -568,6 +576,8 @@ static int ktd202x_probe(struct i2c_client
 *client)
              return ret;
      }
 
+     chip->num_leds = (int) (unsigned
 long)i2c_get_match_data(client);
+
      ret = ktd202x_probe_dt(chip);
      if (ret < 0) {
              regulator_bulk_disable(ARRAY_SIZE(chip->regulators),

chip->regulators);

drivers/leds/rgb/leds-ktd202x.c +9 -0
@@ -602,21 +612,33 @@ static void ktd202x_shutdown(struct i2c_client
 *client)
      regmap_write(chip->regmap, KTD202X_REG_RESET_CONTROL,
 KTD202X_RSTR_RESET);
 }
 
+static const struct i2c_device_id ktd202x_id[] = {
+     {"ktd2026", KTD2026_NUM_LEDS},
+     {"ktd2027", KTD2027_NUM_LEDS},
+     {},
+};
+MODULE_DEVICE_TABLE(i2c, ktd202x_id);
+
+#ifndef CONFIG_ACPI
 static const struct of_device_id ktd202x_match_table[] = {
      { .compatible = "kinetic,ktd2026", .data = (void
 *)KTD2026_NUM_LEDS },
      { .compatible = "kinetic,ktd2027", .data = (void
 *)KTD2027_NUM_LEDS },
      {},
 };
 MODULE_DEVICE_TABLE(of, ktd202x_match_table);
+#endif
 
Quoted 6 lines

drivers/leds/rgb/leds-ktd202x.c static void ktd202x_shutdown(struct i2c_client *client) · line 633

Quoted 5 lines
drivers/leds/rgb/leds-ktd202x.c +1 -2
 static struct i2c_driver ktd202x_driver = {
      .driver = {
-             .name = "leds-ktd202x",
-             .of_match_table = ktd202x_match_table,
+             .name   = "leds-ktd202x",

Why was the space after "name" replaced by tab?

I'll remove it.

Quoted 4 lines

drivers/leds/rgb/leds-ktd202x.c static void ktd202x_shutdown(struct i2c_client · line 639

Quoted 3 lines
drivers/leds/rgb/leds-ktd202x.c +2 -0
+#ifndef CONFIG_ACPI
+             .of_match_table = ktd20xx_match_table,

Typo: ktd20xx_match_table -> ktd202x_match_table

Ops. I'll fix it.

Quoted 13 lines

André

Quoted 9 lines
drivers/leds/rgb/leds-ktd202x.c +2 -0
+#endif
      },
      .probe = ktd202x_probe,
      .remove = ktd202x_remove,
      .shutdown = ktd202x_shutdown,
+     .id_table = ktd202x_id,
 };
 module_i2c_driver(ktd202x_driver);

I'll propose a v2 patch to improve the code according to your suggestions.

Signature · 2 lines
BR,
Kate