a66dc0d858660def14d2521dd537b2eca23c4b6e
[openwrt/openwrt.git] / target / linux / lantiq / patches-2.6.39 / 560-dev-leds-gpio.patch
1 --- /dev/null
2 +++ b/arch/mips/include/asm/mach-lantiq/dev-leds-gpio.h
3 @@ -0,0 +1,21 @@
4 +/*
5 + * Lantiq GPIO LED device support
6 + *
7 + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
8 + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
9 + *
10 + * This program is free software; you can redistribute it and/or modify it
11 + * under the terms of the GNU General Public License version 2 as published
12 + * by the Free Software Foundation.
13 + */
14 +
15 +#ifndef _LANTIQ_DEV_LEDS_GPIO_H
16 +#define _LANTIQ_DEV_LEDS_GPIO_H
17 +
18 +#include <linux/leds.h>
19 +
20 +void ltq_add_device_leds_gpio(int id,
21 + unsigned num_leds,
22 + struct gpio_led *leds) __init;
23 +
24 +#endif /* _LANTIQ_DEV_LEDS_GPIO_H */
25 --- /dev/null
26 +++ b/arch/mips/lantiq/dev-leds-gpio.c
27 @@ -0,0 +1,57 @@
28 +/*
29 + * Lantiq GPIO LED device support
30 + *
31 + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
32 + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
33 + *
34 + * Parts of this file are based on Atheros' 2.6.15 BSP
35 + *
36 + * This program is free software; you can redistribute it and/or modify it
37 + * under the terms of the GNU General Public License version 2 as published
38 + * by the Free Software Foundation.
39 + */
40 +
41 +#include <linux/init.h>
42 +#include <linux/slab.h>
43 +#include <linux/platform_device.h>
44 +
45 +#include "dev-leds-gpio.h"
46 +
47 +void __init ltq_add_device_leds_gpio(int id, unsigned num_leds,
48 + struct gpio_led *leds)
49 +{
50 + struct platform_device *pdev;
51 + struct gpio_led_platform_data pdata;
52 + struct gpio_led *p;
53 + int err;
54 +
55 + p = kmalloc(num_leds * sizeof(*p), GFP_KERNEL);
56 + if (!p)
57 + return;
58 +
59 + memcpy(p, leds, num_leds * sizeof(*p));
60 +
61 + pdev = platform_device_alloc("leds-gpio", id);
62 + if (!pdev)
63 + goto err_free_leds;
64 +
65 + memset(&pdata, 0, sizeof(pdata));
66 + pdata.num_leds = num_leds;
67 + pdata.leds = p;
68 +
69 + err = platform_device_add_data(pdev, &pdata, sizeof(pdata));
70 + if (err)
71 + goto err_put_pdev;
72 +
73 + err = platform_device_add(pdev);
74 + if (err)
75 + goto err_put_pdev;
76 +
77 + return;
78 +
79 +err_put_pdev:
80 + platform_device_put(pdev);
81 +
82 +err_free_leds:
83 + kfree(p);
84 +}
85 --- a/arch/mips/lantiq/Makefile
86 +++ b/arch/mips/lantiq/Makefile
87 @@ -4,7 +4,7 @@
88 # under the terms of the GNU General Public License version 2 as published
89 # by the Free Software Foundation.
90
91 -obj-y := irq.o setup.o clk.o prom.o devices.o
92 +obj-y := irq.o setup.o clk.o prom.o devices.o dev-leds-gpio.o
93
94 obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
95