2ab187d152be6cbc939994fe15791c2a002547d7
[openwrt/svn-archive/archive.git] / target / linux / ramips / files / arch / mips / ralink / common / dev-gpio-leds.c
1 /*
2 * Ralink SoC GPIO LED device support
3 *
4 * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published
8 * by the Free Software Foundation.
9 */
10
11 #include <linux/init.h>
12 #include <linux/platform_device.h>
13
14 #include <asm/mach-ralink/dev-gpio-leds.h>
15
16 void __init ramips_register_gpio_leds(int id, unsigned num_leds,
17 struct gpio_led *leds)
18 {
19 struct platform_device *pdev;
20 struct gpio_led_platform_data pdata;
21 struct gpio_led *p;
22 int err;
23
24 p = kmalloc(num_leds * sizeof(*p), GFP_KERNEL);
25 if (!p)
26 return;
27
28 memcpy(p, leds, num_leds * sizeof(*p));
29
30 pdev = platform_device_alloc("leds-gpio", id);
31 if (!pdev)
32 goto err_free_leds;
33
34 memset(&pdata, 0, sizeof(pdata));
35 pdata.num_leds = num_leds;
36 pdata.leds = p;
37
38 err = platform_device_add_data(pdev, &pdata, sizeof(pdata));
39 if (err)
40 goto err_put_pdev;
41
42 err = platform_device_add(pdev);
43 if (err)
44 goto err_put_pdev;
45
46 return;
47
48 err_put_pdev:
49 platform_device_put(pdev);
50
51 err_free_leds:
52 kfree(p);
53 }