[ramips] add GPIO configuration feature
[openwrt.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 #include <linux/leds.h>
14
15 #include <asm/mach-ralink/dev_gpio_leds.h>
16
17 void __init ramips_register_gpio_leds(int id, unsigned num_leds,
18 struct gpio_led *leds)
19 {
20 struct platform_device *pdev;
21 struct gpio_led_platform_data pdata;
22 struct gpio_led *p;
23 int err;
24
25 p = kmalloc(num_leds * sizeof(*p), GFP_KERNEL);
26 if (!p)
27 return;
28
29 memcpy(p, leds, num_leds * sizeof(*p));
30
31 pdev = platform_device_alloc("leds-gpio", id);
32 if (!pdev)
33 goto err_free_leds;
34
35 memset(&pdata, 0, sizeof(pdata));
36 pdata.num_leds = num_leds;
37 pdata.leds = p;
38
39 err = platform_device_add_data(pdev, &pdata, sizeof(pdata));
40 if (err)
41 goto err_put_pdev;
42
43 err = platform_device_add(pdev);
44 if (err)
45 goto err_put_pdev;
46
47 return;
48
49 err_put_pdev:
50 platform_device_put(pdev);
51
52 err_free_leds:
53 kfree(p);
54 }
This page took 0.045884 seconds and 5 git commands to generate.