aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/leds/leds-88pm860x.c
diff options
context:
space:
mode:
authorHaojian Zhuang <haojian.zhuang@marvell.com>2011-03-07 10:43:10 -0500
committerSamuel Ortiz <sameo@linux.intel.com>2011-03-23 05:42:06 -0400
commit3154c344696e58b7e15317cd624816dbe3832ad1 (patch)
tree7b908eacd6a6d423105faa980a31af9be3692dbe /drivers/leds/leds-88pm860x.c
parentadb70483f4d560323db9aaca5f066fde4d96f339 (diff)
mfd: Adopt mfd_data in 88pm860x led
Copy 88pm860x platform data into different mfd_data structure for led driver. So move the identification of device node from led driver to mfd driver. Signed-off-by: Haojian Zhuang <haojian.zhuang@marvell.com> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
Diffstat (limited to 'drivers/leds/leds-88pm860x.c')
-rw-r--r--drivers/leds/leds-88pm860x.c60
1 files changed, 28 insertions, 32 deletions
diff --git a/drivers/leds/leds-88pm860x.c b/drivers/leds/leds-88pm860x.c
index e672b44ee172..416def84d045 100644
--- a/drivers/leds/leds-88pm860x.c
+++ b/drivers/leds/leds-88pm860x.c
@@ -17,6 +17,7 @@
17#include <linux/leds.h> 17#include <linux/leds.h>
18#include <linux/slab.h> 18#include <linux/slab.h>
19#include <linux/workqueue.h> 19#include <linux/workqueue.h>
20#include <linux/mfd/core.h>
20#include <linux/mfd/88pm860x.h> 21#include <linux/mfd/88pm860x.h>
21 22
22#define LED_PWM_SHIFT (3) 23#define LED_PWM_SHIFT (3)
@@ -118,7 +119,8 @@ static void pm860x_led_work(struct work_struct *work)
118 119
119 struct pm860x_led *led; 120 struct pm860x_led *led;
120 struct pm860x_chip *chip; 121 struct pm860x_chip *chip;
121 int mask; 122 unsigned char buf[3];
123 int mask, ret;
122 124
123 led = container_of(work, struct pm860x_led, work); 125 led = container_of(work, struct pm860x_led, work);
124 chip = led->chip; 126 chip = led->chip;
@@ -128,16 +130,27 @@ static void pm860x_led_work(struct work_struct *work)
128 pm860x_set_bits(led->i2c, __led_off(led->port), 130 pm860x_set_bits(led->i2c, __led_off(led->port),
129 LED_CURRENT_MASK, led->iset); 131 LED_CURRENT_MASK, led->iset);
130 } 132 }
133 pm860x_set_bits(led->i2c, __blink_off(led->port),
134 LED_BLINK_MASK, LED_ON_CONTINUOUS);
131 mask = __blink_ctl_mask(led->port); 135 mask = __blink_ctl_mask(led->port);
132 pm860x_set_bits(led->i2c, PM8606_WLED3B, mask, mask); 136 pm860x_set_bits(led->i2c, PM8606_WLED3B, mask, mask);
133 } else if (led->brightness == 0) {
134 pm860x_set_bits(led->i2c, __led_off(led->port),
135 LED_CURRENT_MASK, 0);
136 mask = __blink_ctl_mask(led->port);
137 pm860x_set_bits(led->i2c, PM8606_WLED3B, mask, 0);
138 } 137 }
139 pm860x_set_bits(led->i2c, __led_off(led->port), LED_PWM_MASK, 138 pm860x_set_bits(led->i2c, __led_off(led->port), LED_PWM_MASK,
140 led->brightness); 139 led->brightness);
140
141 if (led->brightness == 0) {
142 pm860x_bulk_read(led->i2c, __led_off(led->port), 3, buf);
143 ret = buf[0] & LED_PWM_MASK;
144 ret |= buf[1] & LED_PWM_MASK;
145 ret |= buf[2] & LED_PWM_MASK;
146 if (ret == 0) {
147 /* unset current since no led is lighting */
148 pm860x_set_bits(led->i2c, __led_off(led->port),
149 LED_CURRENT_MASK, 0);
150 mask = __blink_ctl_mask(led->port);
151 pm860x_set_bits(led->i2c, PM8606_WLED3B, mask, 0);
152 }
153 }
141 led->current_brightness = led->brightness; 154 led->current_brightness = led->brightness;
142 dev_dbg(chip->dev, "Update LED. (reg:%d, brightness:%d)\n", 155 dev_dbg(chip->dev, "Update LED. (reg:%d, brightness:%d)\n",
143 __led_off(led->port), led->brightness); 156 __led_off(led->port), led->brightness);
@@ -153,31 +166,12 @@ static void pm860x_led_set(struct led_classdev *cdev,
153 schedule_work(&data->work); 166 schedule_work(&data->work);
154} 167}
155 168
156static int __check_device(struct pm860x_led_pdata *pdata, char *name)
157{
158 struct pm860x_led_pdata *p = pdata;
159 int ret = -EINVAL;
160
161 while (p && p->id) {
162 if ((p->id != PM8606_ID_LED) || (p->flags < 0))
163 break;
164
165 if (!strncmp(name, pm860x_led_name[p->flags],
166 MFD_NAME_SIZE)) {
167 ret = (int)p->flags;
168 break;
169 }
170 p++;
171 }
172 return ret;
173}
174
175static int pm860x_led_probe(struct platform_device *pdev) 169static int pm860x_led_probe(struct platform_device *pdev)
176{ 170{
177 struct pm860x_chip *chip = dev_get_drvdata(pdev->dev.parent); 171 struct pm860x_chip *chip = dev_get_drvdata(pdev->dev.parent);
178 struct pm860x_platform_data *pm860x_pdata;
179 struct pm860x_led_pdata *pdata; 172 struct pm860x_led_pdata *pdata;
180 struct pm860x_led *data; 173 struct pm860x_led *data;
174 struct mfd_cell *cell;
181 struct resource *res; 175 struct resource *res;
182 int ret; 176 int ret;
183 177
@@ -187,10 +181,11 @@ static int pm860x_led_probe(struct platform_device *pdev)
187 return -EINVAL; 181 return -EINVAL;
188 } 182 }
189 183
190 if (pdev->dev.parent->platform_data) { 184 cell = pdev->dev.platform_data;
191 pm860x_pdata = pdev->dev.parent->platform_data; 185 if (cell == NULL)
192 pdata = pm860x_pdata->led; 186 return -ENODEV;
193 } else { 187 pdata = cell->mfd_data;
188 if (pdata == NULL) {
194 dev_err(&pdev->dev, "No platform data!\n"); 189 dev_err(&pdev->dev, "No platform data!\n");
195 return -EINVAL; 190 return -EINVAL;
196 } 191 }
@@ -198,12 +193,12 @@ static int pm860x_led_probe(struct platform_device *pdev)
198 data = kzalloc(sizeof(struct pm860x_led), GFP_KERNEL); 193 data = kzalloc(sizeof(struct pm860x_led), GFP_KERNEL);
199 if (data == NULL) 194 if (data == NULL)
200 return -ENOMEM; 195 return -ENOMEM;
201 strncpy(data->name, res->name, MFD_NAME_SIZE); 196 strncpy(data->name, res->name, MFD_NAME_SIZE - 1);
202 dev_set_drvdata(&pdev->dev, data); 197 dev_set_drvdata(&pdev->dev, data);
203 data->chip = chip; 198 data->chip = chip;
204 data->i2c = (chip->id == CHIP_PM8606) ? chip->client : chip->companion; 199 data->i2c = (chip->id == CHIP_PM8606) ? chip->client : chip->companion;
205 data->iset = pdata->iset; 200 data->iset = pdata->iset;
206 data->port = __check_device(pdata, data->name); 201 data->port = pdata->flags;
207 if (data->port < 0) { 202 if (data->port < 0) {
208 dev_err(&pdev->dev, "check device failed\n"); 203 dev_err(&pdev->dev, "check device failed\n");
209 kfree(data); 204 kfree(data);
@@ -221,6 +216,7 @@ static int pm860x_led_probe(struct platform_device *pdev)
221 dev_err(&pdev->dev, "Failed to register LED: %d\n", ret); 216 dev_err(&pdev->dev, "Failed to register LED: %d\n", ret);
222 goto out; 217 goto out;
223 } 218 }
219 pm860x_led_set(&data->cdev, 0);
224 return 0; 220 return 0;
225out: 221out:
226 kfree(data); 222 kfree(data);