Skip to content

Commit 2f73c39

Browse files
Peter MeerwaldBryan Wu
authored andcommitted
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>
1 parent e76a322 commit 2f73c39

File tree

2 files changed

+47
-7
lines changed

2 files changed

+47
-7
lines changed

drivers/leds/leds-pca9633.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <linux/i2c.h>
2323
#include <linux/workqueue.h>
2424
#include <linux/slab.h>
25+
#include <linux/platform_data/leds-pca9633.h>
2526

2627
/* LED select registers determine the source that drives LED outputs */
2728
#define PCA9633_LED_OFF 0x0 /* LED driver off */
@@ -96,13 +97,13 @@ static int __devinit pca9633_probe(struct i2c_client *client,
9697
const struct i2c_device_id *id)
9798
{
9899
struct pca9633_led *pca9633;
99-
struct led_platform_data *pdata;
100+
struct pca9633_platform_data *pdata;
100101
int i, err;
101102

102103
pdata = client->dev.platform_data;
103104

104105
if (pdata) {
105-
if (pdata->num_leds <= 0 || pdata->num_leds > 4) {
106+
if (pdata->leds.num_leds <= 0 || pdata->leds.num_leds > 4) {
106107
dev_err(&client->dev, "board info must claim at most 4 LEDs");
107108
return -EINVAL;
108109
}
@@ -119,14 +120,14 @@ static int __devinit pca9633_probe(struct i2c_client *client,
119120
pca9633[i].led_num = i;
120121

121122
/* Platform data can specify LED names and default triggers */
122-
if (pdata && i < pdata->num_leds) {
123-
if (pdata->leds[i].name)
123+
if (pdata && i < pdata->leds.num_leds) {
124+
if (pdata->leds.leds[i].name)
124125
snprintf(pca9633[i].name,
125126
sizeof(pca9633[i].name), "pca9633:%s",
126-
pdata->leds[i].name);
127-
if (pdata->leds[i].default_trigger)
127+
pdata->leds.leds[i].name);
128+
if (pdata->leds.leds[i].default_trigger)
128129
pca9633[i].led_cdev.default_trigger =
129-
pdata->leds[i].default_trigger;
130+
pdata->leds.leds[i].default_trigger;
130131
} else {
131132
snprintf(pca9633[i].name, sizeof(pca9633[i].name),
132133
"pca9633:%d", i);
@@ -145,6 +146,10 @@ static int __devinit pca9633_probe(struct i2c_client *client,
145146
/* Disable LED all-call address and set normal mode */
146147
i2c_smbus_write_byte_data(client, PCA9633_MODE1, 0x00);
147148

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+
148153
/* Turn off LEDs */
149154
i2c_smbus_write_byte_data(client, PCA9633_LEDOUT, 0x00);
150155

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
25+
enum pca9633_outdrv {
26+
PCA9633_OPEN_DRAIN,
27+
PCA9633_TOTEM_POLE, /* aka push-pull */
28+
};
29+
30+
struct pca9633_platform_data {
31+
struct led_platform_data leds;
32+
enum pca9633_outdrv outdrv;
33+
};
34+
35+
#endif /* __LINUX_PCA9633_H*/

0 commit comments

Comments
 (0)