diff options
author | Simon Guinot <simon.guinot@sequanux.org> | 2012-10-17 06:09:03 -0400 |
---|---|---|
committer | Jason Cooper <jason@lakedaemon.net> | 2012-11-21 15:58:28 -0500 |
commit | 72052fcc10263817031dd96ea438c1f49eb39dd3 (patch) | |
tree | 2078db252bd107d97ebe8f9beb0cdcffee74b60e /drivers/leds/leds-ns2.c | |
parent | bff0844513f46e97e3cffa7b137c2eeb263810a6 (diff) |
leds: leds-ns2: add device tree binding
Signed-off-by: Simon Guinot <simon.guinot@sequanux.org>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: Jason Cooper <jason@lakedaemon.net>
Diffstat (limited to 'drivers/leds/leds-ns2.c')
-rw-r--r-- | drivers/leds/leds-ns2.c | 78 |
1 files changed, 75 insertions, 3 deletions
diff --git a/drivers/leds/leds-ns2.c b/drivers/leds/leds-ns2.c index d176ec83f5d9..d64cc2227fd9 100644 --- a/drivers/leds/leds-ns2.c +++ b/drivers/leds/leds-ns2.c | |||
@@ -30,6 +30,7 @@ | |||
30 | #include <linux/leds.h> | 30 | #include <linux/leds.h> |
31 | #include <linux/module.h> | 31 | #include <linux/module.h> |
32 | #include <linux/platform_data/leds-kirkwood-ns2.h> | 32 | #include <linux/platform_data/leds-kirkwood-ns2.h> |
33 | #include <linux/of_gpio.h> | ||
33 | 34 | ||
34 | /* | 35 | /* |
35 | * The Network Space v2 dual-GPIO LED is wired to a CPLD and can blink in | 36 | * The Network Space v2 dual-GPIO LED is wired to a CPLD and can blink in |
@@ -263,6 +264,62 @@ static void delete_ns2_led(struct ns2_led_data *led_dat) | |||
263 | gpio_free(led_dat->slow); | 264 | gpio_free(led_dat->slow); |
264 | } | 265 | } |
265 | 266 | ||
267 | #ifdef CONFIG_OF_GPIO | ||
268 | /* | ||
269 | * Translate OpenFirmware node properties into platform_data. | ||
270 | */ | ||
271 | static int __devinit | ||
272 | ns2_leds_get_of_pdata(struct device *dev, struct ns2_led_platform_data *pdata) | ||
273 | { | ||
274 | struct device_node *np = dev->of_node; | ||
275 | struct device_node *child; | ||
276 | struct ns2_led *leds; | ||
277 | int num_leds = 0; | ||
278 | int i = 0; | ||
279 | |||
280 | num_leds = of_get_child_count(np); | ||
281 | if (!num_leds) | ||
282 | return -ENODEV; | ||
283 | |||
284 | leds = devm_kzalloc(dev, num_leds * sizeof(struct ns2_led), | ||
285 | GFP_KERNEL); | ||
286 | if (!leds) | ||
287 | return -ENOMEM; | ||
288 | |||
289 | for_each_child_of_node(np, child) { | ||
290 | const char *string; | ||
291 | int ret; | ||
292 | |||
293 | ret = of_get_named_gpio(child, "cmd-gpio", 0); | ||
294 | if (ret < 0) | ||
295 | return ret; | ||
296 | leds[i].cmd = ret; | ||
297 | ret = of_get_named_gpio(child, "slow-gpio", 0); | ||
298 | if (ret < 0) | ||
299 | return ret; | ||
300 | leds[i].slow = ret; | ||
301 | ret = of_property_read_string(child, "label", &string); | ||
302 | leds[i].name = (ret == 0) ? string : child->name; | ||
303 | ret = of_property_read_string(child, "linux,default-trigger", | ||
304 | &string); | ||
305 | if (ret == 0) | ||
306 | leds[i].default_trigger = string; | ||
307 | |||
308 | i++; | ||
309 | } | ||
310 | |||
311 | pdata->leds = leds; | ||
312 | pdata->num_leds = num_leds; | ||
313 | |||
314 | return 0; | ||
315 | } | ||
316 | |||
317 | static const struct of_device_id of_ns2_leds_match[] = { | ||
318 | { .compatible = "lacie,ns2-leds", }, | ||
319 | {}, | ||
320 | }; | ||
321 | #endif /* CONFIG_OF_GPIO */ | ||
322 | |||
266 | static int __devinit ns2_led_probe(struct platform_device *pdev) | 323 | static int __devinit ns2_led_probe(struct platform_device *pdev) |
267 | { | 324 | { |
268 | struct ns2_led_platform_data *pdata = pdev->dev.platform_data; | 325 | struct ns2_led_platform_data *pdata = pdev->dev.platform_data; |
@@ -270,11 +327,25 @@ static int __devinit ns2_led_probe(struct platform_device *pdev) | |||
270 | int i; | 327 | int i; |
271 | int ret; | 328 | int ret; |
272 | 329 | ||
330 | #ifdef CONFIG_OF_GPIO | ||
331 | if (!pdata) { | ||
332 | pdata = devm_kzalloc(&pdev->dev, | ||
333 | sizeof(struct ns2_led_platform_data), | ||
334 | GFP_KERNEL); | ||
335 | if (!pdata) | ||
336 | return -ENOMEM; | ||
337 | |||
338 | ret = ns2_leds_get_of_pdata(&pdev->dev, pdata); | ||
339 | if (ret) | ||
340 | return ret; | ||
341 | } | ||
342 | #else | ||
273 | if (!pdata) | 343 | if (!pdata) |
274 | return -EINVAL; | 344 | return -EINVAL; |
345 | #endif /* CONFIG_OF_GPIO */ | ||
275 | 346 | ||
276 | leds_data = devm_kzalloc(&pdev->dev, sizeof(struct ns2_led_data) * | 347 | leds_data = devm_kzalloc(&pdev->dev, sizeof(struct ns2_led_data) * |
277 | pdata->num_leds, GFP_KERNEL); | 348 | pdata->num_leds, GFP_KERNEL); |
278 | if (!leds_data) | 349 | if (!leds_data) |
279 | return -ENOMEM; | 350 | return -ENOMEM; |
280 | 351 | ||
@@ -312,8 +383,9 @@ static struct platform_driver ns2_led_driver = { | |||
312 | .probe = ns2_led_probe, | 383 | .probe = ns2_led_probe, |
313 | .remove = __devexit_p(ns2_led_remove), | 384 | .remove = __devexit_p(ns2_led_remove), |
314 | .driver = { | 385 | .driver = { |
315 | .name = "leds-ns2", | 386 | .name = "leds-ns2", |
316 | .owner = THIS_MODULE, | 387 | .owner = THIS_MODULE, |
388 | .of_match_table = of_match_ptr(of_ns2_leds_match), | ||
317 | }, | 389 | }, |
318 | }; | 390 | }; |
319 | 391 | ||