aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/leds/leds-ns2.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2012-12-12 15:14:06 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2012-12-12 15:14:06 -0500
commitcf4af01221579a4e895f43dbfc47598fbfc5a731 (patch)
treeadc48fdc6ffb9d3d2a32a0f83df9e66066549963 /drivers/leds/leds-ns2.c
parentd027db132b395dabfac208e52a7e510e441bb9d2 (diff)
parent006309132f57ccc20dd69e971e2041ebd2cbb7e5 (diff)
Merge tag 'boards' of git://git.kernel.org/pub/scm/linux/kernel/git/arm/arm-soc
Pull ARM SoC board updates from Olof Johansson: "This branch contains a set of various board updates for ARM platforms. A few shmobile platforms that are stale have been removed, some defconfig updates for various boards selecting new features such as pinctrl subsystem support, and various updates enabling peripherals, etc." Fix up conflicts mostly as per Olof. * tag 'boards' of git://git.kernel.org/pub/scm/linux/kernel/git/arm/arm-soc: (58 commits) ARM: S3C64XX: Add dummy supplies for Glenfarclas LDOs ARM: S3C64XX: Add registration of WM2200 Bells device on Cragganmore ARM: kirkwood: Add Plat'Home OpenBlocks A6 support ARM: Dove: update defconfig ARM: Kirkwood: update defconfig for new boards arm: orion5x: add DT related options in defconfig arm: orion5x: convert 'LaCie Ethernet Disk mini v2' to Device Tree arm: orion5x: basic Device Tree support arm: orion5x: mechanical defconfig update ARM: kirkwood: Add support for the MPL CEC4 arm: kirkwood: add support for ZyXEL NSA310 ARM: Kirkwood: new board USI Topkick ARM: kirkwood: use gpio-fan DT binding on lsxl ARM: Kirkwood: add Netspace boards to defconfig ARM: kirkwood: DT board setup for Network Space Mini v2 ARM: kirkwood: DT board setup for Network Space Lite v2 ARM: kirkwood: DT board setup for Network Space v2 and parents leds: leds-ns2: add device tree binding ARM: Kirkwood: Enable the second I2C bus ARM: mmp: select pinctrl driver ...
Diffstat (limited to 'drivers/leds/leds-ns2.c')
-rw-r--r--drivers/leds/leds-ns2.c78
1 files changed, 75 insertions, 3 deletions
diff --git a/drivers/leds/leds-ns2.c b/drivers/leds/leds-ns2.c
index 6315e88d04fd..7b75affb308a 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 */
271static int
272ns2_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
317static const struct of_device_id of_ns2_leds_match[] = {
318 { .compatible = "lacie,ns2-leds", },
319 {},
320};
321#endif /* CONFIG_OF_GPIO */
322
266static int ns2_led_probe(struct platform_device *pdev) 323static int 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 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 = ns2_led_remove, 384 .remove = 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