leds: Add KTD20xx RGB LEDs driver from Kinetic
Subsystems (2)
cover leds: Add KTD20xx RGB LEDs driver from Kinetic
Introduce the KTD2061/58/59/60 RGB LEDs driver. The difference in these parts are the address number on the I2C bus the device is listen on.
All KT20xx device could control up to 12 LEDs. The chip can be operated in two variants.
Florian Eckert (2):
leds: ktd20xx: Add the KTD20xx family of the RGB LEDs driver from
Kinetic
dt: bindings: KTD20xx: Introduce the ktd20xx family of RGB drivers
.../bindings/leds/leds-ktd20xx.yaml | 123 +++ MAINTAINERS | 7 + drivers/leds/Kconfig | 13 + drivers/leds/Makefile | 1 + drivers/leds/leds-ktd20xx.c | 801 ++++++++++++++++++ 5 files changed, 945 insertions(+) create mode 100644 Documentation/devicetree/bindings/leds/leds-ktd20xx.yaml create mode 100644 drivers/leds/leds-ktd20xx.c
Signature · 1 line
2.20.1
PATCH 1/2 leds: ktd20xx: Add the KTD20xx family of the RGB LEDs driver from Kinetic
Introduce the KTD2061/58/59/60 RGB LEDs driver. The difference in these parts are the address number on the I2C bus the device is listen on.
All KT20xx device could control up to 12 LEDs. The chip can be operated in two variants.
Variant 1:
The device has the ability to group LED outputs into two banks so that the two LED banks can be controlled with the same color. This could not be done via the LEDs 'sysfs' entry because of the limitation on the color register count. The color of the two banks can be configured via device 'sysfs' entry for all LEDs at once [current_color0|current_color1]. Which color the LED is to be used can be set via the 'sysfs' of the individual LEDs via the 'multi_intensity' file. Valid values for the colors (RGB) are 0 | 1. The value 0 selects the color register 0 and the value 1 selects the color register 1.
Variant 2:
The device can also set the LED color independently. Since the chip only has two color registers, but we want to control the 12 LEDs independently via the 'led-class-multicolour' sysfs entry,
the full RGB color depth cannot be used. Due to this limitation, only 7 colors and the color black (off) can be set. To use this mode the color registers must be preset via the device tree or the device 'sysfs'. The color registers 0 must be preset with 0x00 (Red=0x00 Green=0x00 Blue=0x00). The color register1 should be preset all with the same value. This value depends on which light intensity is to be used in the setup.
--- MAINTAINERS | 6 + drivers/leds/Kconfig | 13 + drivers/leds/Makefile | 1 + drivers/leds/leds-ktd20xx.c | 801 ++++++++++++++++++++++++++++++++++++ 4 files changed, 821 insertions(+) create mode 100644 drivers/leds/leds-ktd20xx.c
MAINTAINERS +6 -0
@@ -10603,6 +10603,12 @@ S: Maintained F: Documentation/devicetree/bindings/leds/backlight/kinetic,ktd253.yaml F: drivers/video/backlight/ktd253-backlight.c +KTD20XX LED CONTROLLER DRIVER +M: Florian Eckert <[email protected]> +L: [email protected] +S: Maintained +F: drivers/leds/leds-ktd20xx.c + KTEST M: Steven Rostedt <[email protected]> M: John Hawley <[email protected]>
drivers/leds/Kconfig +13 -0
@@ -157,6 +157,19 @@ config LEDS_EL15203000 To compile this driver as a module, choose M here: the module will be called leds-el15203000. +config LEDS_KTD20XX + tristate "LED Support for KTD2061/58/59/60 LED driver chip" + depends on LEDS_CLASS && I2C + depends on LEDS_CLASS_MULTICOLOR || !LEDS_CLASS_MULTICOLOR + depends on OF + select REGMAP_I2C + help + If you say yes here you get support for the Kinetic + KTD2061, KTD2058, KTD2059 and KTD2060 LED driver. + + To compile this driver as a module, choose M here: the + module will be called leds-ktd20xx. + config LEDS_TURRIS_OMNIA tristate "LED support for CZ.NIC's Turris Omnia" depends on LEDS_CLASS_MULTICOLOR
drivers/leds/Makefile +1 -0
@@ -35,6 +35,7 @@ obj-$(CONFIG_LEDS_IP30) += leds-ip30.o obj-$(CONFIG_LEDS_IPAQ_MICRO) += leds-ipaq-micro.o obj-$(CONFIG_LEDS_IS31FL319X) += leds-is31fl319x.o obj-$(CONFIG_LEDS_IS31FL32XX) += leds-is31fl32xx.o +obj-${CONFIG_LEDS_KTD20XX} += leds-ktd20xx.o obj-$(CONFIG_LEDS_LM3530) += leds-lm3530.o obj-$(CONFIG_LEDS_LM3532) += leds-lm3532.o obj-$(CONFIG_LEDS_LM3533) += leds-lm3533.o
drivers/leds/leds-ktd20xx.c new file +801 -0
801 lines not on this page · raw message
Signature · 1 line
2.20.1
Re: [PATCH 1/2] leds: ktd20xx: Add the KTD20xx family of the RGB LEDs driver from Kinetic
hi!
Quoted 5 lines
Introduce the KTD2061/58/59/60 RGB LEDs driver. The difference in these parts are the address number on the I2C bus the device is listen on.
All KT20xx device could control up to 12 LEDs. The chip can be operated in two variants.
How are the variants selected?
Quoted 10 lines
Variant 1:
The device has the ability to group LED outputs into two banks so that the two LED banks can be controlled with the same color. This could not be done via the LEDs 'sysfs' entry because of the limitation on the color register count. The color of the two banks can be configured via device 'sysfs' entry for all LEDs at once [current_color0|current_color1]. Which color the LED is to be used can be set via the 'sysfs' of the individual LEDs via the 'multi_intensity' file. Valid values for the colors (RGB) are 0 | 1. The value 0 selects the color register 0 and the value 1 selects the color register 1.
So... you can select two colors (current_color0, current_color1), and then then each of the 12 LEDs get one of those colors. What about intensities? Can brightness be set arbitrarily for each LED?
Quoted 10 lines
Variant 2:
The device can also set the LED color independently. Since the chip only has two color registers, but we want to control the 12 LEDs independently via the 'led-class-multicolour' sysfs entry,
the full RGB color depth cannot be used. Due to this limitation, only 7 colors and the color black (off) can be set. To use this mode the color registers must be preset via the device tree or the device 'sysfs'. The color registers 0 must be preset with0x00(Red=0x00 Green=0x00 Blue=0x00). The color register1 should be preset all with the same value. This value depends on which light intensity is to be used in the setup.
So now we have 7 colors we can select from. That sounds better than two colors. Why would we ever want to use variant 1?
Can we simply pretend this is 7 LED RGB driver?
Quoted 3 lines
+/* Device attribute for color0 register
+ *
+ * The device attribute colour1 is intended to adjust the colour space.
Use color, not colour. Plus run this through checkpatch.
Quoted 1 line
+ * The colour strength can be controlled via the current in 125uA steps.
I don't know what "colour strength" is.
Quoted 6 lines
drivers/leds/leds-ktd20xx.c new file +6
-0+/* +* The chip also offers the option "Fade rate". +*/ +static ssize_t faderate_show (struct device *dev,struct device_attribute *a, +char *buf) +{
drivers/leds/leds-ktd20xx.c line 649
Quoted 10 lines
drivers/leds/leds-ktd20xx.c new file +10
-0+struct i2c_client *client =to_i2c_client (dev); +struct ktd20xx *chip =i2c_get_clientdata (client); +unsigned int value; + +mutex_lock (&chip->lock); +regmap_field_read (chip->faderate, &value); +mutex_unlock (&chip->lock); + +return sprintf (buf,"%d\n" , value); +}
That's way too hardware specific.
Best regards,
Pavel
Signature · 1 line
http://www.livejournal.com/~pavelmachek
Dan Carpenter
build botRe: [PATCH 1/2] leds: ktd20xx: Add the KTD20xx family of the RGB LEDs driver from Kinetic
In reply to Florian EckertCC: kbuild-all(a)lists.01.org In-Reply-To: <[email protected]> References: <[email protected]> TO: Florian Eckert <[email protected]> TO: pavel(a)ucw.cz TO…
CC: kbuild-all(a)lists.01.org
In-Reply-To: <[email protected]>
References: <[email protected]>
TO: Florian Eckert <[email protected]>
TO: pavel(a)ucw.cz
TO: robh+dt(a)kernel.org
TO: Eckert.Florian(a)googlemail.com
CC: linux-leds(a)vger.kernel.org
CC: devicetree(a)vger.kernel.org
CC: linux-kernel(a)vger.kernel.org
CC: Florian Eckert <[email protected]>
Hi Florian,
I love your patch! Perhaps something to improve:
[auto build test WARNING on pavel-leds/for-next]
[also build test WARNING on robh/for-next linus/master v5.16-rc1 next-20211118] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Florian-Eckert/leds-Add-KTD20xx-RGB-LEDs-driver-from-Kinetic/20211109-181728 base: git://git.kernel.org/pub/scm/linux/kernel/git/pavel/linux-leds.git for-next
:::::: branch date: 11 days ago
:::::: commit date: 11 days ago
config: i386-randconfig-m031-20211115 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
If you fix the issue, kindly add following tag as appropriate
smatch warnings:drivers/leds/leds-ktd20xx.c:304 ktd20xx_probe_dt() warn: missing error code 'ret' drivers/leds/leds-ktd20xx.c:492 current_color0_store() warn: unsigned 'value[i]' is never less than zero. drivers/leds/leds-ktd20xx.c:566 current_color1_store() warn: unsigned 'value[i]' is never less than zero. drivers/leds/leds-ktd20xx.c:661 faderate_store() warn: unsigned 'faderate' is never less than zero.
vim +/ret +304 drivers/leds/leds-ktd20xx.c
004e74105bb360 Florian Eckert 2021-11-09 280
004e74105bb360 Florian Eckert 2021-11-09 281 static int ktd20xx_probe_dt(struct ktd20xx *chip)
004e74105bb360 Florian Eckert 2021-11-09 282 {
004e74105bb360 Florian Eckert 2021-11-09 283 struct fwnode_handle *child = NULL;
004e74105bb360 Florian Eckert 2021-11-09 284 struct led_init_data init_data = {};
004e74105bb360 Florian Eckert 2021-11-09 285 struct led_classdev *led_cdev;
004e74105bb360 Florian Eckert 2021-11-09 286 struct ktd20xx_led *led;
004e74105bb360 Florian Eckert 2021-11-09 287 struct device *dev = &chip->client->dev;
004e74105bb360 Florian Eckert 2021-11-09 288 u8 value[3] = { 0, 0, 0 };
004e74105bb360 Florian Eckert 2021-11-09 289 int i = 0;
004e74105bb360 Florian Eckert 2021-11-09 290 int ret = -EINVAL;
004e74105bb360 Florian Eckert 2021-11-09 291 int color;
004e74105bb360 Florian Eckert 2021-11-09 292
004e74105bb360 Florian Eckert 2021-11-09 293 device_for_each_child_node(chip->dev, child) {
004e74105bb360 Florian Eckert 2021-11-09 294 led = &chip->leds[i];
004e74105bb360 Florian Eckert 2021-11-09 295
004e74105bb360 Florian Eckert 2021-11-09 296 ret = fwnode_property_read_u32(child, "reg", &led->index);
004e74105bb360 Florian Eckert 2021-11-09 297 if (ret) {
004e74105bb360 Florian Eckert 2021-11-09 298 dev_err(dev, "missing property: reg\n");
004e74105bb360 Florian Eckert 2021-11-09 299 goto child_out;
004e74105bb360 Florian Eckert 2021-11-09 300 }
004e74105bb360 Florian Eckert 2021-11-09 301 if (led->index >= KTD20XX_MAX_LEDS) {
004e74105bb360 Florian Eckert 2021-11-09 302 dev_warn(dev, "property 'reg' must contain value between '0' and '%i'\n",
004e74105bb360 Florian Eckert 2021-11-09 303 KTD20XX_MAX_LEDS);
004e74105bb360 Florian Eckert 2021-11-09 @304 goto child_out;
004e74105bb360 Florian Eckert 2021-11-09 305 }
004e74105bb360 Florian Eckert 2021-11-09 306
004e74105bb360 Florian Eckert 2021-11-09 307 ret = fwnode_property_read_u32(child, "color", &color);
004e74105bb360 Florian Eckert 2021-11-09 308 if (ret) {
004e74105bb360 Florian Eckert 2021-11-09 309 dev_err(dev, "missing property: color\n");
004e74105bb360 Florian Eckert 2021-11-09 310 goto child_out;
004e74105bb360 Florian Eckert 2021-11-09 311 }
004e74105bb360 Florian Eckert 2021-11-09 312 if (color != LED_COLOR_ID_RGB) {
004e74105bb360 Florian Eckert 2021-11-09 313 dev_warn(dev, "property 'color' must contain value 'LED_COLOR_ID_RGB'\n");
004e74105bb360 Florian Eckert 2021-11-09 314 goto child_out;
004e74105bb360 Florian Eckert 2021-11-09 315 }
004e74105bb360 Florian Eckert 2021-11-09 316
004e74105bb360 Florian Eckert 2021-11-09 317 /* Get default color register selection */
004e74105bb360 Florian Eckert 2021-11-09 318 if (fwnode_property_read_u8_array(child, "kinetic,color-selection", value, 3))
004e74105bb360 Florian Eckert 2021-11-09 319 dev_warn(dev, "no kinetic,color-selection property found, use default rgbt color selection from register 0.\n");
004e74105bb360 Florian Eckert 2021-11-09 320
004e74105bb360 Florian Eckert 2021-11-09 321 led->subled_info[0].color_index = LED_COLOR_ID_RED;
004e74105bb360 Florian Eckert 2021-11-09 322 led->subled_info[0].channel = 0;
004e74105bb360 Florian Eckert 2021-11-09 323 led->subled_info[0].intensity = value[0];
004e74105bb360 Florian Eckert 2021-11-09 324 led->subled_info[1].color_index = LED_COLOR_ID_GREEN;
004e74105bb360 Florian Eckert 2021-11-09 325 led->subled_info[1].channel = 1;
004e74105bb360 Florian Eckert 2021-11-09 326 led->subled_info[1].intensity = value[1];
004e74105bb360 Florian Eckert 2021-11-09 327 led->subled_info[2].color_index = LED_COLOR_ID_BLUE;
004e74105bb360 Florian Eckert 2021-11-09 328 led->subled_info[2].channel = 2;
004e74105bb360 Florian Eckert 2021-11-09 329 led->subled_info[2].intensity = value[2];
004e74105bb360 Florian Eckert 2021-11-09 330
004e74105bb360 Florian Eckert 2021-11-09 331 led->mc_cdev.subled_info = led->subled_info;
004e74105bb360 Florian Eckert 2021-11-09 332 led->mc_cdev.num_colors = KTD20XX_LED_CHANNELS;
004e74105bb360 Florian Eckert 2021-11-09 333
004e74105bb360 Florian Eckert 2021-11-09 334 init_data.fwnode = child;
004e74105bb360 Florian Eckert 2021-11-09 335
004e74105bb360 Florian Eckert 2021-11-09 336 led->chip = chip;
004e74105bb360 Florian Eckert 2021-11-09 337 led_cdev = &led->mc_cdev.led_cdev;
004e74105bb360 Florian Eckert 2021-11-09 338 led_cdev->brightness_set_blocking = ktd20xx_brightness_set;
004e74105bb360 Florian Eckert 2021-11-09 339
004e74105bb360 Florian Eckert 2021-11-09 340 switch (led->index) {
004e74105bb360 Florian Eckert 2021-11-09 341 case RGB_A1:
004e74105bb360 Florian Eckert 2021-11-09 342 led->select = devm_regmap_field_alloc(chip->dev,
004e74105bb360 Florian Eckert 2021-11-09 343 chip->regmap, kt20xx_a1_select);
004e74105bb360 Florian Eckert 2021-11-09 344 led->enable = devm_regmap_field_alloc(chip->dev,
004e74105bb360 Florian Eckert 2021-11-09 345 chip->regmap, kt20xx_a1_enable);
004e74105bb360 Florian Eckert 2021-11-09 346 break;
004e74105bb360 Florian Eckert 2021-11-09 347 case RGB_A2:
004e74105bb360 Florian Eckert 2021-11-09 348 led->select = devm_regmap_field_alloc(chip->dev,
004e74105bb360 Florian Eckert 2021-11-09 349 chip->regmap, kt20xx_a2_select);
004e74105bb360 Florian Eckert 2021-11-09 350 led->enable = devm_regmap_field_alloc(chip->dev,
004e74105bb360 Florian Eckert 2021-11-09 351 chip->regmap, kt20xx_a2_enable);
004e74105bb360 Florian Eckert 2021-11-09 352 break;
004e74105bb360 Florian Eckert 2021-11-09 353 case RGB_A3:
004e74105bb360 Florian Eckert 2021-11-09 354 led->select = devm_regmap_field_alloc(chip->dev,
004e74105bb360 Florian Eckert 2021-11-09 355 chip->regmap, kt20xx_a3_select);
004e74105bb360 Florian Eckert 2021-11-09 356 led->enable = devm_regmap_field_alloc(chip->dev,
004e74105bb360 Florian Eckert 2021-11-09 357 chip->regmap, kt20xx_a3_enable);
004e74105bb360 Florian Eckert 2021-11-09 358 break;
004e74105bb360 Florian Eckert 2021-11-09 359 case RGB_A4:
004e74105bb360 Florian Eckert 2021-11-09 360 led->select = devm_regmap_field_alloc(chip->dev,
004e74105bb360 Florian Eckert 2021-11-09 361 chip->regmap, kt20xx_a4_select);
004e74105bb360 Florian Eckert 2021-11-09 362 led->enable = devm_regmap_field_alloc(chip->dev,
004e74105bb360 Florian Eckert 2021-11-09 363 chip->regmap, kt20xx_a4_enable);
004e74105bb360 Florian Eckert 2021-11-09 364 break;
004e74105bb360 Florian Eckert 2021-11-09 365 case RGB_B1:
004e74105bb360 Florian Eckert 2021-11-09 366 led->select = devm_regmap_field_alloc(chip->dev,
004e74105bb360 Florian Eckert 2021-11-09 367 chip->regmap, kt20xx_b1_select);
004e74105bb360 Florian Eckert 2021-11-09 368 led->enable = devm_regmap_field_alloc(chip->dev,
004e74105bb360 Florian Eckert 2021-11-09 369 chip->regmap, kt20xx_b1_enable);
004e74105bb360 Florian Eckert 2021-11-09 370 break;
004e74105bb360 Florian Eckert 2021-11-09 371 case RGB_B2:
004e74105bb360 Florian Eckert 2021-11-09 372 led->select = devm_regmap_field_alloc(chip->dev,
004e74105bb360 Florian Eckert 2021-11-09 373 chip->regmap, kt20xx_b2_select);
004e74105bb360 Florian Eckert 2021-11-09 374 led->enable = devm_regmap_field_alloc(chip->dev,
004e74105bb360 Florian Eckert 2021-11-09 375 chip->regmap, kt20xx_b2_enable);
004e74105bb360 Florian Eckert 2021-11-09 376 break;
004e74105bb360 Florian Eckert 2021-11-09 377 case RGB_B3:
004e74105bb360 Florian Eckert 2021-11-09 378 led->select = devm_regmap_field_alloc(chip->dev,
004e74105bb360 Florian Eckert 2021-11-09 379 chip->regmap, kt20xx_b3_select);
004e74105bb360 Florian Eckert 2021-11-09 380 led->enable = devm_regmap_field_alloc(chip->dev,
004e74105bb360 Florian Eckert 2021-11-09 381 chip->regmap, kt20xx_b3_enable);
004e74105bb360 Florian Eckert 2021-11-09 382 break;
004e74105bb360 Florian Eckert 2021-11-09 383 case RGB_B4:
004e74105bb360 Florian Eckert 2021-11-09 384 led->select = devm_regmap_field_alloc(chip->dev,
004e74105bb360 Florian Eckert 2021-11-09 385 chip->regmap, kt20xx_b4_select);
004e74105bb360 Florian Eckert 2021-11-09 386 led->enable = devm_regmap_field_alloc(chip->dev,
004e74105bb360 Florian Eckert 2021-11-09 387 chip->regmap, kt20xx_b4_enable);
004e74105bb360 Florian Eckert 2021-11-09 388 break;
004e74105bb360 Florian Eckert 2021-11-09 389 case RGB_C1:
004e74105bb360 Florian Eckert 2021-11-09 390 led->select = devm_regmap_field_alloc(chip->dev,
004e74105bb360 Florian Eckert 2021-11-09 391 chip->regmap, kt20xx_c1_select);
004e74105bb360 Florian Eckert 2021-11-09 392 led->enable = devm_regmap_field_alloc(chip->dev,
004e74105bb360 Florian Eckert 2021-11-09 393 chip->regmap, kt20xx_c1_enable);
004e74105bb360 Florian Eckert 2021-11-09 394 break;
004e74105bb360 Florian Eckert 2021-11-09 395 case RGB_C2:
004e74105bb360 Florian Eckert 2021-11-09 396 led->select = devm_regmap_field_alloc(chip->dev,
004e74105bb360 Florian Eckert 2021-11-09 397 chip->regmap, kt20xx_c2_select);
004e74105bb360 Florian Eckert 2021-11-09 398 led->enable = devm_regmap_field_alloc(chip->dev,
004e74105bb360 Florian Eckert 2021-11-09 399 chip->regmap, kt20xx_c2_enable);
004e74105bb360 Florian Eckert 2021-11-09 400 break;
004e74105bb360 Florian Eckert 2021-11-09 401 case RGB_C3:
004e74105bb360 Florian Eckert 2021-11-09 402 led->select = devm_regmap_field_alloc(chip->dev,
004e74105bb360 Florian Eckert 2021-11-09 403 chip->regmap, kt20xx_c3_select);
004e74105bb360 Florian Eckert 2021-11-09 404 led->enable = devm_regmap_field_alloc(chip->dev,
004e74105bb360 Florian Eckert 2021-11-09 405 chip->regmap, kt20xx_c3_enable);
004e74105bb360 Florian Eckert 2021-11-09 406 break;
004e74105bb360 Florian Eckert 2021-11-09 407 case RGB_C4:
004e74105bb360 Florian Eckert 2021-11-09 408 led->select = devm_regmap_field_alloc(chip->dev,
004e74105bb360 Florian Eckert 2021-11-09 409 chip->regmap, kt20xx_c4_select);
004e74105bb360 Florian Eckert 2021-11-09 410 led->enable = devm_regmap_field_alloc(chip->dev,
004e74105bb360 Florian Eckert 2021-11-09 411 chip->regmap, kt20xx_c4_enable);
004e74105bb360 Florian Eckert 2021-11-09 412 break;
004e74105bb360 Florian Eckert 2021-11-09 413 }
004e74105bb360 Florian Eckert 2021-11-09 414
004e74105bb360 Florian Eckert 2021-11-09 415 ret = devm_led_classdev_multicolor_register_ext(&chip->client->dev,
004e74105bb360 Florian Eckert 2021-11-09 416 &led->mc_cdev,
004e74105bb360 Florian Eckert 2021-11-09 417 &init_data);
004e74105bb360 Florian Eckert 2021-11-09 418
004e74105bb360 Florian Eckert 2021-11-09 419 if (ret) {
004e74105bb360 Florian Eckert 2021-11-09 420 dev_err(&chip->client->dev, "led register err: %d\n", ret);
004e74105bb360 Florian Eckert 2021-11-09 421 goto child_out;
004e74105bb360 Florian Eckert 2021-11-09 422 }
004e74105bb360 Florian Eckert 2021-11-09 423
004e74105bb360 Florian Eckert 2021-11-09 424 i++;
004e74105bb360 Florian Eckert 2021-11-09 425 fwnode_handle_put(child);
004e74105bb360 Florian Eckert 2021-11-09 426 }
004e74105bb360 Florian Eckert 2021-11-09 427
004e74105bb360 Florian Eckert 2021-11-09 428 return 0;
004e74105bb360 Florian Eckert 2021-11-09 429
004e74105bb360 Florian Eckert 2021-11-09 430 child_out:
004e74105bb360 Florian Eckert 2021-11-09 431 fwnode_handle_put(child);
004e74105bb360 Florian Eckert 2021-11-09 432 return ret;
004e74105bb360 Florian Eckert 2021-11-09 433 }
004e74105bb360 Florian Eckert 2021-11-09 434
004e74105bb360 Florian Eckert 2021-11-09 435 /* Device attribute for color0 register
004e74105bb360 Florian Eckert 2021-11-09 436 *
004e74105bb360 Florian Eckert 2021-11-09 437 * The device attribute colour1 is intended to adjust the colour space.
004e74105bb360 Florian Eckert 2021-11-09 438 * The colour strength can be controlled via the current in 125uA steps.
004e74105bb360 Florian Eckert 2021-11-09 439 * The maximum current for the individual channels is limited to 24mA.
004e74105bb360 Florian Eckert 2021-11-09 440 * To set a new RGB value, 3 values must be passed. This value may not be
004e74105bb360 Florian Eckert 2021-11-09 441 * less than 0 and also not greater than 194. The chip can only process the
004e74105bb360 Florian Eckert 2021-11-09 442 * maximum current of 24mA. This means that any value greater than 194
004e74105bb360 Florian Eckert 2021-11-09 443 * cannot be set.
004e74105bb360 Florian Eckert 2021-11-09 444 */
004e74105bb360 Florian Eckert 2021-11-09 445 static ssize_t current_color0_show(struct device *dev,
004e74105bb360 Florian Eckert 2021-11-09 446 struct device_attribute *a,
004e74105bb360 Florian Eckert 2021-11-09 447 char *buf)
004e74105bb360 Florian Eckert 2021-11-09 448 {
004e74105bb360 Florian Eckert 2021-11-09 449 struct i2c_client *client = to_i2c_client(dev);
004e74105bb360 Florian Eckert 2021-11-09 450 struct ktd20xx *chip = i2c_get_clientdata(client);
004e74105bb360 Florian Eckert 2021-11-09 451 unsigned int value;
004e74105bb360 Florian Eckert 2021-11-09 452 int len = 0;
004e74105bb360 Florian Eckert 2021-11-09 453
004e74105bb360 Florian Eckert 2021-11-09 454 mutex_lock(&chip->lock);
004e74105bb360 Florian Eckert 2021-11-09 455 regmap_read(chip->regmap, KTD20XX_IRED0, &value);
004e74105bb360 Florian Eckert 2021-11-09 456 len += sprintf(buf + len, "%d", value);
004e74105bb360 Florian Eckert 2021-11-09 457 len += sprintf(buf + len, " ");
004e74105bb360 Florian Eckert 2021-11-09 458
004e74105bb360 Florian Eckert 2021-11-09 459 regmap_read(chip->regmap, KTD20XX_IGRN0, &value);
004e74105bb360 Florian Eckert 2021-11-09 460 len += sprintf(buf + len, "%d", value);
004e74105bb360 Florian Eckert 2021-11-09 461 len += sprintf(buf + len, " ");
004e74105bb360 Florian Eckert 2021-11-09 462
004e74105bb360 Florian Eckert 2021-11-09 463 regmap_read(chip->regmap, KTD20XX_IBLU0, &value);
004e74105bb360 Florian Eckert 2021-11-09 464 len += sprintf(buf + len, "%d", value);
004e74105bb360 Florian Eckert 2021-11-09 465 mutex_unlock(&chip->lock);
004e74105bb360 Florian Eckert 2021-11-09 466
004e74105bb360 Florian Eckert 2021-11-09 467 buf[len++] = '\n';
004e74105bb360 Florian Eckert 2021-11-09 468 return len;
004e74105bb360 Florian Eckert 2021-11-09 469 }
004e74105bb360 Florian Eckert 2021-11-09 470
004e74105bb360 Florian Eckert 2021-11-09 471 static ssize_t current_color0_store(struct device *dev,
004e74105bb360 Florian Eckert 2021-11-09 472 struct device_attribute *a,
004e74105bb360 Florian Eckert 2021-11-09 473 const char *buf, size_t size)
004e74105bb360 Florian Eckert 2021-11-09 474 {
004e74105bb360 Florian Eckert 2021-11-09 475 struct i2c_client *client = to_i2c_client(dev);
004e74105bb360 Florian Eckert 2021-11-09 476 struct ktd20xx *chip = i2c_get_clientdata(client);
004e74105bb360 Florian Eckert 2021-11-09 477 unsigned int value[3];
004e74105bb360 Florian Eckert 2021-11-09 478 int i;
004e74105bb360 Florian Eckert 2021-11-09 479 ssize_t ret;
004e74105bb360 Florian Eckert 2021-11-09 480
004e74105bb360 Florian Eckert 2021-11-09 481 ret = sscanf(buf, "%u %u %u", &value[0], &value[1], &value[2]);
004e74105bb360 Florian Eckert 2021-11-09 482 if (ret < 3) {
004e74105bb360 Florian Eckert 2021-11-09 483 ret = -EINVAL;
004e74105bb360 Florian Eckert 2021-11-09 484 goto err_out;
004e74105bb360 Florian Eckert 2021-11-09 485 }
004e74105bb360 Florian Eckert 2021-11-09 486
004e74105bb360 Florian Eckert 2021-11-09 487 for (i = 0; i < 3; i++) {
004e74105bb360 Florian Eckert 2021-11-09 488 if (value[i] > 194) {
004e74105bb360 Florian Eckert 2021-11-09 489 ret = -EINVAL;
004e74105bb360 Florian Eckert 2021-11-09 490 goto err_out;
004e74105bb360 Florian Eckert 2021-11-09 491 }
004e74105bb360 Florian Eckert 2021-11-09 @492 if (value[i] < 0) {
004e74105bb360 Florian Eckert 2021-11-09 493 ret = -EINVAL;
004e74105bb360 Florian Eckert 2021-11-09 494 goto err_out;
004e74105bb360 Florian Eckert 2021-11-09 495 }
004e74105bb360 Florian Eckert 2021-11-09 496 }
004e74105bb360 Florian Eckert 2021-11-09 497
004e74105bb360 Florian Eckert 2021-11-09 498 mutex_lock(&chip->lock);
004e74105bb360 Florian Eckert 2021-11-09 499 regmap_write(chip->regmap, KTD20XX_IRED0, value[0]);
004e74105bb360 Florian Eckert 2021-11-09 500 regmap_write(chip->regmap, KTD20XX_IGRN0, value[1]);
004e74105bb360 Florian Eckert 2021-11-09 501 regmap_write(chip->regmap, KTD20XX_IBLU0, value[2]);
004e74105bb360 Florian Eckert 2021-11-09 502 mutex_unlock(&chip->lock);
004e74105bb360 Florian Eckert 2021-11-09 503 return size;
004e74105bb360 Florian Eckert 2021-11-09 504
004e74105bb360 Florian Eckert 2021-11-09 505 err_out:
004e74105bb360 Florian Eckert 2021-11-09 506 return ret;
004e74105bb360 Florian Eckert 2021-11-09 507 }
004e74105bb360 Florian Eckert 2021-11-09 508 static DEVICE_ATTR_RW(current_color0);
004e74105bb360 Florian Eckert 2021-11-09 509 ---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
PATCH 2/2 dt: bindings: KTD20xx: Introduce the ktd20xx family of RGB drivers
In reply to Florian EckertIntroduce the bindings for the Kinetic KTD2061/58/59/60RGB LED device driver. The KTD20xx can control RGB LEDs individually or as part of a control bank group.
--- .../bindings/leds/leds-ktd20xx.yaml | 123 ++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 124 insertions(+) create mode 100644 Documentation/devicetree/bindings/leds/leds-ktd20xx.yaml
Documentation/devicetree/bindings/leds/leds-ktd20xx.yaml new file +123 -0
@@ -0,0 +1,123 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/leds/leds-ktd20xx.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: LED driver for KTD20xx RGB LED from Kinetic. + +maintainers: + - Florian Eckert <[email protected]> + +description: | + The KTD20XX is multi-channel, I2C RGB LED Drivers that can group RGB LEDs into + a LED group or control them individually. + + The difference in these RGB LED drivers is I2C address number the device is + listen on. + +properties: + compatible: + enum: + - kinetic,ktd20xx + + reg: + maxItems: 1 + description: + I2C slave address + ktd2061/58/59/60 0x68 0x69 0x6A 0x6B + + '#address-cells': + const: 1 + + '#size-cells': + const: 0 + + 'kinetic,color-current0': + description: + Specifies the current selection for the RGB color0. + Value 1 must be the current value for the color red. + Value 2 must be the current value for the color green. + Value 3 must be the current value for the color blue. + The current setting range is from 0mA to 24mA with 125uA steps. + $ref: /schemas/types.yaml#/definitions/uint8-array + items: + - minItems: 3 + - maxItems: 3 + + 'kinetic,color-current1': + description: + Specifies the current selection for the RGB color0. + Value 1 must be the current value for the color red. + Value 2 must be the current value for the color green. + Value 3 must be the current value for the color blue. + The current setting range is from 0mA to 24mA with 125uA steps. + $ref: /schemas/types.yaml#/definitions/uint8-array + items: + - minItems: 3 + - maxItems: 3 + +patternProperties: + '^multi-led@[0-9a-f]$': + type: object + allOf: + - $ref: leds-class-multicolor.yaml# + properties: + reg: + minItems: 1 + maxItems: 12 + description: + This property denotes the LED module number(s) that is used on the + for the child node. + 'kinetic,color-selection': + description: + Specifies the color selection for this LED. + Value 1 selects the color register for color red. + Value 2 selects the color register for color green. + Value 3 selects the color register for color blue. + The value can be either 0 or 1. If 0, the current for the color + from color register 0 is used. If 1, the current for the color + from color register 1 is used. + $ref: /schemas/types.yaml#/definitions/uint8-array + items: + - minItems: 3 + - maxItems: 3 + +required: + - compatible + - reg + +additionalProperties: false + +examples: + - | + #include <dt-bindings/leds/common.h> + + i2c { + #address-cells = <1>; + #size-cells = <0>; + + led-controller@14 { + compatible = "ti,lp5009"; + reg = <0x14>; + #address-cells = <1>; + #size-cells = <0>; + color-current0 = [ 00 00 00 ] // Current for RGB is 0mA + color-current1 = [ 28 28 28 ] // Current for RGB is 5mA + + multi-led@0 { + reg = <0x0>; + color = <LED_COLOR_ID_RGB>; + function = LED_FUNCTION_CHARGING; + kinetic,color-selection = [ 00 01 00 ]; // Red=0mA Green=5mA Blue=0mA + }; + + multi-led@2 { + reg = <0x2>; + color = <LED_COLOR_ID_RGB>; + function = LED_FUNCTION_STANDBY; + }; + }; + }; + +...
MAINTAINERS +1 -0
@@ -10607,6 +10607,7 @@ KTD20XX LED CONTROLLER DRIVER M: Florian Eckert <[email protected]> L: [email protected] S: Maintained +F: Documentation/devicetree/bindings/leds/leds-ktd20xx.yaml F: drivers/leds/leds-ktd20xx.c KTEST
Signature · 1 line
2.20.1
Hi!
Quoted 10 lines
Introduce the KTD2061/58/59/60 RGB LEDs driver. The difference in these parts are the address number on the I2C bus the device is listen on.
All KT20xx device could control up to 12 LEDs. The chip can be operated in two variants.
Florian Eckert (2):
leds: ktd20xx: Add the KTD20xx family of the RGB LEDs driver from
Kinetic
dt: bindings: KTD20xx: Introduce the ktd20xx family of RGB drivers
That's... not a nice piece of hardware.
We'll want dt changes first, driver next please.
If this uses non-standard interface, it will need to be documented. But I would like to understand the limitations first.
Do you have actual device where this is used?
Best regards,
Pavel
Signature · 1 line
http://www.livejournal.com/~pavelmachek
Quoted 1 line
Hi!
Thanks for reviewing my patchset.
Quoted 6 lines
Quoted 4 lines
Florian Eckert (2):
leds: ktd20xx: Add the KTD20xx family of the RGB LEDs driver from
Kinetic
dt: bindings: KTD20xx: Introduce the ktd20xx family of RGB driversThat's... not a nice piece of hardware.
Yes, that may be, but I have tried to use what the chip can do. So that it works for my use case. It would be great if we could integrate it into the color LED framework of the kernel.
Quoted 2 lines
If this uses non-standard interface, it will need to be documented. But I would like to understand the limitations first.
OK Then I will try it.
Register Layout:
| Address | Name | Type | Access | Default | B7 | B6 | B5 | B4 | B3 | B2 | B1 | B0 | |:-------:|:-------:|:------:|:------:|:-------:|:--:|:--:|:--:|:--:|:--:|:--:|:--:|:--:| | 0x00 | ID | Data | R | 0xA4 | VENDOR[2:0] | DIE_ID[4:0] | | 0x01 | MONITOR | Status | R | 0x30 | DIE_REV[3:0] | SC | BE | CE | UV | | 0x02 | CONTROL | Config | R/W | 0x00 |MODE[1:0]| BE |TEMP[1:0]|FADE_RATE[2:0]| | 0x03 | IRED0 | Config | R/W | 0x28 | IRED_SET0[7:0] | | 0x04 | IGRN0 | Config | R/W | 0x28 | IGRN_SET0[7:0] | | 0x05 | IBLU0 | Config | R/W | 0x28 | IBLU_SET0[7:0] | | 0x06 | IRED1 | Config | R/W | 0x60 | IRED_SET1[7:0] | | 0x07 | IGRN1 | Config | R/W | 0x60 | IGRN_SET1[7:0] | | 0x08 | IBLU1 | Config | R/W | 0x60 | IBLU_SET1[7:0] | | 0x09 | ISELA12 | Config | R/W | 0x00 |ENA1|RGBA1_SEL[2:0]|ENA2|RGBA2_SEL[2:0]| | 0x0A | ISELA34 | Config | R/W | 0x00 |ENA3|RGBA3_SEL[2:0]|ENA4|RGBA4_SEL[2:0]| | 0x0B | ISELB12 | Config | R/W | 0x00 |ENB1|RGBB1_SEL[2:0]|ENB2|RGBB2_SEL[2:0]| | 0x0C | ISELB34 | Config | R/W | 0x00 |ENB3|RGBB3_SEL[2:0]|ENB4|RGBB4_SEL[2:0]| | 0x0D | ISELC12 | Config | R/W | 0x00 |ENC1|RGBC1_SEL[2:0]|ENC2|RGBC2_SEL[2:0]| | 0x0E | ISELc34 | Config | R/W | 0x00 |ENC3|RGBC3_SEL[2:0]|ENC4|RGBC4_SEL[2:0]|
The registers 0x0A to 0x0E controls the LEDs. Each register controls two LEDs. The top bit [3] of each byte nibble controls whether the LED is on or off. The other bits [0:2] of each nibble, select which color register to use Ixxx_SET0 and Ixxx_SET1 (0x03 to 0x08).
Bit 0 -> Blue (RGBxx_SEL):
If this bit is set to 1 then use IBLU_SET1 value otherwise bit is 0 use IBLU_SET0 value.
Bit 1 -> Green RGBxx_SEL):
If this bit is set to 1 then use IGRN_SET1 value otherwise bit is 0 use IGRN_SET0 value.
Bit 2 -> Red RGBxx_SEL):
If this bit is set to 1 then use IRED_SET1 value otherwise bit is 0 use IRED_SET0 value.
This means that we can define two colors from the full RGB range in the Ixxx_SET0 and Ixxx_SET1 respectively. And the LEDs can select which RGB color, value they want to use for the individual basic color via the RGBxx_SEL. In reality, this is the electrical current that the LED gets. The different electric currents produce a color depending on the current ratio.
There are now various possibilities for the whole chip to fit into the color LED framework of the kernel.
Variant1:
Prefill Ixxx_SET0 with one value for example 0x28 and set Ixxx_SET1 to 0x00. Then we could select with the RGBxx_SEl[2:0] of an LED which color we want. But we only could have 8 colors because of the limition
This are the colors we could produce with this setup.
| Red | Green | Blue | Color | |:---:|:-----:|:----:|:-------:| | 0 | 0 | 1 | Blue | | 0 | 1 | 0 | Green | | 0 | 1 | 1 |Turquoise| | 1 | 0 | 0 | Red | | 1 | 0 | 1 | Purple | | 1 | 1 | 0 | Yellow | | 1 | 1 | 1 | White | | 0 | 0 | 0 | Black |
The color brightness for the eight RGB colors can only be changed together. To do this, the value of the entire Ixxx_SET0 must be changed at once, for example 0x28 -> 0x14 to halve the brightness. However, this applies to all LEDS! This variant would fit into the color LED framework of the kernel.
Variant2:
Prefill Ixxx_SET0 and Ixxx_SET1 via device sysfs with an RGB color, and the select for every LEDS with RGBxx[2:0] which color ratio we want to use. The problem with this is that we have to decide beforehand which color we want to use. We should not change the Ixxx_SET0 and Ixx_SET1 register value because that would affect all the LEDs! This variant would not fit so well into the color LED framework of the kernel, as we could not selectively change the color for each LED.
I hope I could make it understandable, if not please ask :-)
Quoted 1 line
Do you have actual device where this is used?
I don't know where the chip is installed, but we just have new hardware in the pipeline that has this chip for LED control. For our setup we only need 7 colors. Therefore, this chip is sufficient.
- Best regards
Florian
Hello Pavel,
Quoted 2 lines
If this uses non-standard interface, it will need to be documented. But I would like to understand the limitations first.
I have already sent you an explanation and the register description. Did you get it? Do you need anything else?
Best regards,
Florian