aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhil Reid <preid@electromag.com.au>2016-06-14 03:36:17 -0400
committerJacek Anaszewski <j.anaszewski@samsung.com>2016-06-20 03:43:33 -0400
commitfa4191a609f219262a18dd8b02ab7dc30896b707 (patch)
tree7a6844e998b523e8c229e657dbf9635cbb7ab591
parent85c90368d00190ee4ec3a84866b68fa3e2106284 (diff)
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>
-rw-r--r--Documentation/devicetree/bindings/leds/leds-pca9532.txt39
-rw-r--r--drivers/leds/leds-pca9532.c75
-rw-r--r--include/dt-bindings/leds/leds-pca9532.h18
-rw-r--r--include/linux/leds-pca9532.h9
4 files changed, 132 insertions, 9 deletions
diff --git a/Documentation/devicetree/bindings/leds/leds-pca9532.txt b/Documentation/devicetree/bindings/leds/leds-pca9532.txt
new file mode 100644
index 000000000000..198f3ba0e01f
--- /dev/null
+++ b/Documentation/devicetree/bindings/leds/leds-pca9532.txt
@@ -0,0 +1,39 @@
1*NXP - pca9532 PWM LED Driver
2
3The PCA9532 family is SMBus I/O expander optimized for dimming LEDs.
4The PWM support 256 steps.
5
6Required properties:
7 - compatible:
8 "nxp,pca9530"
9 "nxp,pca9531"
10 "nxp,pca9532"
11 "nxp,pca9533"
12 - reg - I2C slave address
13
14Each led is represented as a sub-node of the nxp,pca9530.
15
16Optional 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
21Example:
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
38For more product information please see the link below:
39http://nxp.com/documents/data_sheet/PCA9532.pdf
diff --git a/drivers/leds/leds-pca9532.c b/drivers/leds/leds-pca9532.c
index e3d3b1aaa9e0..09a7cffbc46f 100644
--- a/drivers/leds/leds-pca9532.c
+++ b/drivers/leds/leds-pca9532.c
@@ -21,6 +21,8 @@
21#include <linux/workqueue.h> 21#include <linux/workqueue.h>
22#include <linux/leds-pca9532.h> 22#include <linux/leds-pca9532.h>
23#include <linux/gpio.h> 23#include <linux/gpio.h>
24#include <linux/of.h>
25#include <linux/of_device.h>
24 26
25/* m = num_leds*/ 27/* m = num_leds*/
26#define PCA9532_REG_INPUT(i) ((i) >> 3) 28#define PCA9532_REG_INPUT(i) ((i) >> 3)
@@ -86,9 +88,22 @@ static const struct pca9532_chip_info pca9532_chip_info_tbl[] = {
86 }, 88 },
87}; 89};
88 90
91#ifdef CONFIG_OF
92static const struct of_device_id of_pca9532_leds_match[] = {
93 { .compatible = "nxp,pca9530", .data = (void *)pca9530 },
94 { .compatible = "nxp,pca9531", .data = (void *)pca9531 },
95 { .compatible = "nxp,pca9532", .data = (void *)pca9532 },
96 { .compatible = "nxp,pca9533", .data = (void *)pca9533 },
97 {},
98};
99
100MODULE_DEVICE_TABLE(of, of_pca9532_leds_match);
101#endif
102
89static struct i2c_driver pca9532_driver = { 103static struct i2c_driver pca9532_driver = {
90 .driver = { 104 .driver = {
91 .name = "leds-pca953x", 105 .name = "leds-pca953x",
106 .of_match_table = of_match_ptr(of_pca9532_leds_match),
92 }, 107 },
93 .probe = pca9532_probe, 108 .probe = pca9532_probe,
94 .remove = pca9532_remove, 109 .remove = pca9532_remove,
@@ -354,6 +369,7 @@ static int pca9532_configure(struct i2c_client *client,
354 led->state = pled->state; 369 led->state = pled->state;
355 led->name = pled->name; 370 led->name = pled->name;
356 led->ldev.name = led->name; 371 led->ldev.name = led->name;
372 led->ldev.default_trigger = led->default_trigger;
357 led->ldev.brightness = LED_OFF; 373 led->ldev.brightness = LED_OFF;
358 led->ldev.brightness_set_blocking = 374 led->ldev.brightness_set_blocking =
359 pca9532_set_brightness; 375 pca9532_set_brightness;
@@ -432,15 +448,66 @@ exit:
432 return err; 448 return err;
433} 449}
434 450
451static struct pca9532_platform_data *
452pca9532_of_populate_pdata(struct device *dev, struct device_node *np)
453{
454 struct pca9532_platform_data *pdata;
455 struct device_node *child;
456 const struct of_device_id *match;
457 int devid, maxleds;
458 int i = 0;
459
460 match = of_match_device(of_pca9532_leds_match, dev);
461 if (!match)
462 return ERR_PTR(-ENODEV);
463
464 devid = (int)(uintptr_t)match->data;
465 maxleds = pca9532_chip_info_tbl[devid].num_leds;
466
467 pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
468 if (!pdata)
469 return ERR_PTR(-ENOMEM);
470
471 for_each_child_of_node(np, child) {
472 if (of_property_read_string(child, "label",
473 &pdata->leds[i].name))
474 pdata->leds[i].name = child->name;
475 of_property_read_u32(child, "type", &pdata->leds[i].type);
476 of_property_read_string(child, "linux,default-trigger",
477 &pdata->leds[i].default_trigger);
478 if (++i >= maxleds) {
479 of_node_put(child);
480 break;
481 }
482 }
483
484 return pdata;
485}
486
435static int pca9532_probe(struct i2c_client *client, 487static int pca9532_probe(struct i2c_client *client,
436 const struct i2c_device_id *id) 488 const struct i2c_device_id *id)
437{ 489{
490 int devid;
438 struct pca9532_data *data = i2c_get_clientdata(client); 491 struct pca9532_data *data = i2c_get_clientdata(client);
439 struct pca9532_platform_data *pca9532_pdata = 492 struct pca9532_platform_data *pca9532_pdata =
440 dev_get_platdata(&client->dev); 493 dev_get_platdata(&client->dev);
441 494 struct device_node *np = client->dev.of_node;
442 if (!pca9532_pdata) 495
443 return -EIO; 496 if (!pca9532_pdata) {
497 if (np) {
498 pca9532_pdata =
499 pca9532_of_populate_pdata(&client->dev, np);
500 if (IS_ERR(pca9532_pdata))
501 return PTR_ERR(pca9532_pdata);
502 } else {
503 dev_err(&client->dev, "no platform data\n");
504 return -EINVAL;
505 }
506 devid = (int)(uintptr_t)of_match_device(
507 of_pca9532_leds_match, &client->dev)->data;
508 } else {
509 devid = id->driver_data;
510 }
444 511
445 if (!i2c_check_functionality(client->adapter, 512 if (!i2c_check_functionality(client->adapter,
446 I2C_FUNC_SMBUS_BYTE_DATA)) 513 I2C_FUNC_SMBUS_BYTE_DATA))
@@ -450,7 +517,7 @@ static int pca9532_probe(struct i2c_client *client,
450 if (!data) 517 if (!data)
451 return -ENOMEM; 518 return -ENOMEM;
452 519
453 data->chip_info = &pca9532_chip_info_tbl[id->driver_data]; 520 data->chip_info = &pca9532_chip_info_tbl[devid];
454 521
455 dev_info(&client->dev, "setting platform data\n"); 522 dev_info(&client->dev, "setting platform data\n");
456 i2c_set_clientdata(client, data); 523 i2c_set_clientdata(client, data);
diff --git a/include/dt-bindings/leds/leds-pca9532.h b/include/dt-bindings/leds/leds-pca9532.h
new file mode 100644
index 000000000000..4d917aab7e1e
--- /dev/null
+++ b/include/dt-bindings/leds/leds-pca9532.h
@@ -0,0 +1,18 @@
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 */
diff --git a/include/linux/leds-pca9532.h b/include/linux/leds-pca9532.h
index b8d6fffed4d8..d215b4561180 100644
--- a/include/linux/leds-pca9532.h
+++ b/include/linux/leds-pca9532.h
@@ -16,6 +16,7 @@
16 16
17#include <linux/leds.h> 17#include <linux/leds.h>
18#include <linux/workqueue.h> 18#include <linux/workqueue.h>
19#include <dt-bindings/leds/leds-pca9532.h>
19 20
20enum pca9532_state { 21enum pca9532_state {
21 PCA9532_OFF = 0x0, 22 PCA9532_OFF = 0x0,
@@ -24,16 +25,14 @@ enum pca9532_state {
24 PCA9532_PWM1 = 0x3 25 PCA9532_PWM1 = 0x3
25}; 26};
26 27
27enum pca9532_type { PCA9532_TYPE_NONE, PCA9532_TYPE_LED,
28 PCA9532_TYPE_N2100_BEEP, PCA9532_TYPE_GPIO };
29
30struct pca9532_led { 28struct pca9532_led {
31 u8 id; 29 u8 id;
32 struct i2c_client *client; 30 struct i2c_client *client;
33 char *name; 31 const char *name;
32 const char *default_trigger;
34 struct led_classdev ldev; 33 struct led_classdev ldev;
35 struct work_struct work; 34 struct work_struct work;
36 enum pca9532_type type; 35 u32 type;
37 enum pca9532_state state; 36 enum pca9532_state state;
38}; 37};
39 38