aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Meerwald <p.meerwald@bct-electronic.com>2012-09-24 02:53:49 -0400
committerBryan Wu <bryan.wu@canonical.com>2012-09-24 07:12:29 -0400
commit2f73c3927318abe3d7fcaecadfbad89e2d12f881 (patch)
treee0a20d875f7d35efcd34a00a7be7deeb849684da
parente76a322af16ba7be9b303239352e140209bf3822 (diff)
leds: add output driver configuration for pca9633 led driver
the pca9633 leds driver can be used in open-drain or totem pole (a.k.a. push/pull) output driver mode; default is the later the patch allows to set the output driver mode using platform data (similar to configuration inferface provided by the tca6507 led driver) v2: move leds-pca9633.h to include/linux/platform_data/ (Bryan Wu) Signed-off-by: Peter Meerwald <p.meerwald@bct-electronic.com> Signed-off-by: Bryan Wu <bryan.wu@canonical.com>
-rw-r--r--drivers/leds/leds-pca9633.c19
-rw-r--r--include/linux/platform_data/leds-pca9633.h35
2 files changed, 47 insertions, 7 deletions
diff --git a/drivers/leds/leds-pca9633.c b/drivers/leds/leds-pca9633.c
index edcd706c5631..2f2f9c43535d 100644
--- a/drivers/leds/leds-pca9633.c
+++ b/drivers/leds/leds-pca9633.c
@@ -22,6 +22,7 @@
22#include <linux/i2c.h> 22#include <linux/i2c.h>
23#include <linux/workqueue.h> 23#include <linux/workqueue.h>
24#include <linux/slab.h> 24#include <linux/slab.h>
25#include <linux/platform_data/leds-pca9633.h>
25 26
26/* LED select registers determine the source that drives LED outputs */ 27/* LED select registers determine the source that drives LED outputs */
27#define PCA9633_LED_OFF 0x0 /* LED driver off */ 28#define PCA9633_LED_OFF 0x0 /* LED driver off */
@@ -96,13 +97,13 @@ static int __devinit pca9633_probe(struct i2c_client *client,
96 const struct i2c_device_id *id) 97 const struct i2c_device_id *id)
97{ 98{
98 struct pca9633_led *pca9633; 99 struct pca9633_led *pca9633;
99 struct led_platform_data *pdata; 100 struct pca9633_platform_data *pdata;
100 int i, err; 101 int i, err;
101 102
102 pdata = client->dev.platform_data; 103 pdata = client->dev.platform_data;
103 104
104 if (pdata) { 105 if (pdata) {
105 if (pdata->num_leds <= 0 || pdata->num_leds > 4) { 106 if (pdata->leds.num_leds <= 0 || pdata->leds.num_leds > 4) {
106 dev_err(&client->dev, "board info must claim at most 4 LEDs"); 107 dev_err(&client->dev, "board info must claim at most 4 LEDs");
107 return -EINVAL; 108 return -EINVAL;
108 } 109 }
@@ -119,14 +120,14 @@ static int __devinit pca9633_probe(struct i2c_client *client,
119 pca9633[i].led_num = i; 120 pca9633[i].led_num = i;
120 121
121 /* Platform data can specify LED names and default triggers */ 122 /* Platform data can specify LED names and default triggers */
122 if (pdata && i < pdata->num_leds) { 123 if (pdata && i < pdata->leds.num_leds) {
123 if (pdata->leds[i].name) 124 if (pdata->leds.leds[i].name)
124 snprintf(pca9633[i].name, 125 snprintf(pca9633[i].name,
125 sizeof(pca9633[i].name), "pca9633:%s", 126 sizeof(pca9633[i].name), "pca9633:%s",
126 pdata->leds[i].name); 127 pdata->leds.leds[i].name);
127 if (pdata->leds[i].default_trigger) 128 if (pdata->leds.leds[i].default_trigger)
128 pca9633[i].led_cdev.default_trigger = 129 pca9633[i].led_cdev.default_trigger =
129 pdata->leds[i].default_trigger; 130 pdata->leds.leds[i].default_trigger;
130 } else { 131 } else {
131 snprintf(pca9633[i].name, sizeof(pca9633[i].name), 132 snprintf(pca9633[i].name, sizeof(pca9633[i].name),
132 "pca9633:%d", i); 133 "pca9633:%d", i);
@@ -145,6 +146,10 @@ static int __devinit pca9633_probe(struct i2c_client *client,
145 /* Disable LED all-call address and set normal mode */ 146 /* Disable LED all-call address and set normal mode */
146 i2c_smbus_write_byte_data(client, PCA9633_MODE1, 0x00); 147 i2c_smbus_write_byte_data(client, PCA9633_MODE1, 0x00);
147 148
149 /* Configure output: open-drain or totem pole (push-pull) */
150 if (pdata && pdata->outdrv == PCA9633_OPEN_DRAIN)
151 i2c_smbus_write_byte_data(client, PCA9633_MODE2, 0x01);
152
148 /* Turn off LEDs */ 153 /* Turn off LEDs */
149 i2c_smbus_write_byte_data(client, PCA9633_LEDOUT, 0x00); 154 i2c_smbus_write_byte_data(client, PCA9633_LEDOUT, 0x00);
150 155
diff --git a/include/linux/platform_data/leds-pca9633.h b/include/linux/platform_data/leds-pca9633.h
new file mode 100644
index 000000000000..c5bf29b6fa7f
--- /dev/null
+++ b/include/linux/platform_data/leds-pca9633.h
@@ -0,0 +1,35 @@
1/*
2 * PCA9633 LED chip driver.
3 *
4 * Copyright 2012 bct electronic GmbH
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * version 2 as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18 * 02110-1301 USA
19 */
20
21#ifndef __LINUX_PCA9633_H
22#define __LINUX_PCA9633_H
23#include <linux/leds.h>
24
25enum pca9633_outdrv {
26 PCA9633_OPEN_DRAIN,
27 PCA9633_TOTEM_POLE, /* aka push-pull */
28};
29
30struct pca9633_platform_data {
31 struct led_platform_data leds;
32 enum pca9633_outdrv outdrv;
33};
34
35#endif /* __LINUX_PCA9633_H*/