Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

leds: pca9532: Add device tree support

This patch adds basic device tree support for the pca9532 LEDs.

Signed-off-by: Phil Reid <preid@electromag.com.au>
Signed-off-by: Jacek Anaszewski <j.anaszewski@samsung.com>

authored by

Phil Reid and committed by
Jacek Anaszewski
fa4191a6 85c90368

+131 -8
+39
Documentation/devicetree/bindings/leds/leds-pca9532.txt
··· 1 + *NXP - pca9532 PWM LED Driver 2 + 3 + The PCA9532 family is SMBus I/O expander optimized for dimming LEDs. 4 + The PWM support 256 steps. 5 + 6 + Required properties: 7 + - compatible: 8 + "nxp,pca9530" 9 + "nxp,pca9531" 10 + "nxp,pca9532" 11 + "nxp,pca9533" 12 + - reg - I2C slave address 13 + 14 + Each led is represented as a sub-node of the nxp,pca9530. 15 + 16 + Optional sub-node properties: 17 + - label: see Documentation/devicetree/bindings/leds/common.txt 18 + - type: Output configuration, see dt-bindings/leds/leds-pca9532.h (default NONE) 19 + - linux,default-trigger: see Documentation/devicetree/bindings/leds/common.txt 20 + 21 + Example: 22 + #include <dt-bindings/leds/leds-pca9532.h> 23 + 24 + leds: pca9530@60 { 25 + compatible = "nxp,pca9530"; 26 + reg = <0x60>; 27 + 28 + red-power { 29 + label = "pca:red:power"; 30 + type = <PCA9532_TYPE_LED>; 31 + }; 32 + green-power { 33 + label = "pca:green:power"; 34 + type = <PCA9532_TYPE_LED>; 35 + }; 36 + }; 37 + 38 + For more product information please see the link below: 39 + http://nxp.com/documents/data_sheet/PCA9532.pdf
+70 -3
drivers/leds/leds-pca9532.c
··· 21 21 #include <linux/workqueue.h> 22 22 #include <linux/leds-pca9532.h> 23 23 #include <linux/gpio.h> 24 + #include <linux/of.h> 25 + #include <linux/of_device.h> 24 26 25 27 /* m = num_leds*/ 26 28 #define PCA9532_REG_INPUT(i) ((i) >> 3) ··· 88 86 }, 89 87 }; 90 88 89 + #ifdef CONFIG_OF 90 + static const struct of_device_id of_pca9532_leds_match[] = { 91 + { .compatible = "nxp,pca9530", .data = (void *)pca9530 }, 92 + { .compatible = "nxp,pca9531", .data = (void *)pca9531 }, 93 + { .compatible = "nxp,pca9532", .data = (void *)pca9532 }, 94 + { .compatible = "nxp,pca9533", .data = (void *)pca9533 }, 95 + {}, 96 + }; 97 + 98 + MODULE_DEVICE_TABLE(of, of_pca9532_leds_match); 99 + #endif 100 + 91 101 static struct i2c_driver pca9532_driver = { 92 102 .driver = { 93 103 .name = "leds-pca953x", 104 + .of_match_table = of_match_ptr(of_pca9532_leds_match), 94 105 }, 95 106 .probe = pca9532_probe, 96 107 .remove = pca9532_remove, ··· 369 354 led->state = pled->state; 370 355 led->name = pled->name; 371 356 led->ldev.name = led->name; 357 + led->ldev.default_trigger = led->default_trigger; 372 358 led->ldev.brightness = LED_OFF; 373 359 led->ldev.brightness_set_blocking = 374 360 pca9532_set_brightness; ··· 448 432 return err; 449 433 } 450 434 435 + static struct pca9532_platform_data * 436 + pca9532_of_populate_pdata(struct device *dev, struct device_node *np) 437 + { 438 + struct pca9532_platform_data *pdata; 439 + struct device_node *child; 440 + const struct of_device_id *match; 441 + int devid, maxleds; 442 + int i = 0; 443 + 444 + match = of_match_device(of_pca9532_leds_match, dev); 445 + if (!match) 446 + return ERR_PTR(-ENODEV); 447 + 448 + devid = (int)(uintptr_t)match->data; 449 + maxleds = pca9532_chip_info_tbl[devid].num_leds; 450 + 451 + pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); 452 + if (!pdata) 453 + return ERR_PTR(-ENOMEM); 454 + 455 + for_each_child_of_node(np, child) { 456 + if (of_property_read_string(child, "label", 457 + &pdata->leds[i].name)) 458 + pdata->leds[i].name = child->name; 459 + of_property_read_u32(child, "type", &pdata->leds[i].type); 460 + of_property_read_string(child, "linux,default-trigger", 461 + &pdata->leds[i].default_trigger); 462 + if (++i >= maxleds) { 463 + of_node_put(child); 464 + break; 465 + } 466 + } 467 + 468 + return pdata; 469 + } 470 + 451 471 static int pca9532_probe(struct i2c_client *client, 452 472 const struct i2c_device_id *id) 453 473 { 474 + int devid; 454 475 struct pca9532_data *data = i2c_get_clientdata(client); 455 476 struct pca9532_platform_data *pca9532_pdata = 456 477 dev_get_platdata(&client->dev); 478 + struct device_node *np = client->dev.of_node; 457 479 458 - if (!pca9532_pdata) 459 - return -EIO; 480 + if (!pca9532_pdata) { 481 + if (np) { 482 + pca9532_pdata = 483 + pca9532_of_populate_pdata(&client->dev, np); 484 + if (IS_ERR(pca9532_pdata)) 485 + return PTR_ERR(pca9532_pdata); 486 + } else { 487 + dev_err(&client->dev, "no platform data\n"); 488 + return -EINVAL; 489 + } 490 + devid = (int)(uintptr_t)of_match_device( 491 + of_pca9532_leds_match, &client->dev)->data; 492 + } else { 493 + devid = id->driver_data; 494 + } 460 495 461 496 if (!i2c_check_functionality(client->adapter, 462 497 I2C_FUNC_SMBUS_BYTE_DATA)) ··· 517 450 if (!data) 518 451 return -ENOMEM; 519 452 520 - data->chip_info = &pca9532_chip_info_tbl[id->driver_data]; 453 + data->chip_info = &pca9532_chip_info_tbl[devid]; 521 454 522 455 dev_info(&client->dev, "setting platform data\n"); 523 456 i2c_set_clientdata(client, data);
+18
include/dt-bindings/leds/leds-pca9532.h
··· 1 + /* 2 + * This header provides constants for pca9532 LED bindings. 3 + * 4 + * This file is licensed under the terms of the GNU General Public 5 + * License version 2. This program is licensed "as is" without any 6 + * warranty of any kind, whether express or implied. 7 + */ 8 + 9 + #ifndef _DT_BINDINGS_LEDS_PCA9532_H 10 + #define _DT_BINDINGS_LEDS_PCA9532_H 11 + 12 + #define PCA9532_TYPE_NONE 0 13 + #define PCA9532_TYPE_LED 1 14 + #define PCA9532_TYPE_N2100_BEEP 2 15 + #define PCA9532_TYPE_GPIO 3 16 + #define PCA9532_LED_TIMER2 4 17 + 18 + #endif /* _DT_BINDINGS_LEDS_PCA9532_H */
+4 -5
include/linux/leds-pca9532.h
··· 16 16 17 17 #include <linux/leds.h> 18 18 #include <linux/workqueue.h> 19 + #include <dt-bindings/leds/leds-pca9532.h> 19 20 20 21 enum pca9532_state { 21 22 PCA9532_OFF = 0x0, ··· 25 24 PCA9532_PWM1 = 0x3 26 25 }; 27 26 28 - enum pca9532_type { PCA9532_TYPE_NONE, PCA9532_TYPE_LED, 29 - PCA9532_TYPE_N2100_BEEP, PCA9532_TYPE_GPIO }; 30 - 31 27 struct pca9532_led { 32 28 u8 id; 33 29 struct i2c_client *client; 34 - char *name; 30 + const char *name; 31 + const char *default_trigger; 35 32 struct led_classdev ldev; 36 33 struct work_struct work; 37 - enum pca9532_type type; 34 + u32 type; 38 35 enum pca9532_state state; 39 36 }; 40 37