[ixp4xx] refresh Avila/Cambria patches
[openwrt/svn-archive/archive.git] / target / linux / ixp4xx / patches-2.6.25 / 295-latch_led_driver.patch
1 Index: linux-2.6.25.4/drivers/leds/Kconfig
2 ===================================================================
3 --- linux-2.6.25.4.orig/drivers/leds/Kconfig
4 +++ linux-2.6.25.4/drivers/leds/Kconfig
5 @@ -125,6 +125,12 @@ config LEDS_GPIO
6 outputs. To be useful the particular board must have LEDs
7 and they must be connected to the GPIO lines.
8
9 +config LEDS_LATCH
10 + tristate "LED Support for Memory Latched LEDs"
11 + depends on LEDS_CLASS
12 + help
13 + -- To Do --
14 +
15 config LEDS_CM_X270
16 tristate "LED Support for the CM-X270 LEDs"
17 depends on LEDS_CLASS && MACH_ARMCORE
18 Index: linux-2.6.25.4/drivers/leds/leds-latch.c
19 ===================================================================
20 --- /dev/null
21 +++ linux-2.6.25.4/drivers/leds/leds-latch.c
22 @@ -0,0 +1,141 @@
23 +/*
24 + * LEDs driver for Memory Latched Devices
25 + *
26 + * Copyright (C) 2008 Gateworks Corp.
27 + * Chris Lang <clang@gateworks.com>
28 + *
29 + * This program is free software; you can redistribute it and/or modify
30 + * it under the terms of the GNU General Public License version 2 as
31 + * published by the Free Software Foundation.
32 + *
33 + */
34 +#include <linux/kernel.h>
35 +#include <linux/init.h>
36 +#include <linux/platform_device.h>
37 +#include <linux/leds.h>
38 +#include <linux/workqueue.h>
39 +#include <asm/io.h>
40 +#include <linux/spinlock.h>
41 +
42 +static unsigned int mem_keep = 0xFF;
43 +static spinlock_t mem_lock;
44 +static unsigned char *iobase;
45 +
46 +struct latch_led_data {
47 + struct led_classdev cdev;
48 + struct work_struct work;
49 + u8 new_level;
50 + u8 bit;
51 +};
52 +
53 +static void latch_led_set(struct led_classdev *led_cdev,
54 + enum led_brightness value)
55 +{
56 + struct latch_led_data *led_dat =
57 + container_of(led_cdev, struct latch_led_data, cdev);
58 +
59 + spin_lock(mem_lock);
60 +
61 + if (value == LED_OFF)
62 + mem_keep |= (0x1 << led_dat->bit);
63 + else
64 + mem_keep &= ~(0x1 << led_dat->bit);
65 +
66 + writeb(mem_keep, iobase);
67 +
68 + spin_unlock(mem_lock);
69 +}
70 +
71 +static int latch_led_probe(struct platform_device *pdev)
72 +{
73 + struct latch_led_platform_data *pdata = pdev->dev.platform_data;
74 + struct latch_led *cur_led;
75 + struct latch_led_data *leds_data, *led_dat;
76 + int i, ret = 0;
77 +
78 + if (!pdata)
79 + return -EBUSY;
80 +
81 + leds_data = kzalloc(sizeof(struct latch_led_data) * pdata->num_leds,
82 + GFP_KERNEL);
83 + if (!leds_data)
84 + return -ENOMEM;
85 +
86 + iobase = ioremap_nocache(pdata->mem, 0x1000);
87 + writeb(0xFF, iobase);
88 +
89 + for (i = 0; i < pdata->num_leds; i++) {
90 + cur_led = &pdata->leds[i];
91 + led_dat = &leds_data[i];
92 +
93 + led_dat->cdev.name = cur_led->name;
94 + led_dat->cdev.default_trigger = cur_led->default_trigger;
95 + led_dat->cdev.brightness_set = latch_led_set;
96 + led_dat->cdev.brightness = LED_OFF;
97 + led_dat->bit = cur_led->bit;
98 +
99 + ret = led_classdev_register(&pdev->dev, &led_dat->cdev);
100 + if (ret < 0) {
101 + goto err;
102 + }
103 + }
104 +
105 + platform_set_drvdata(pdev, leds_data);
106 +
107 + return 0;
108 +
109 +err:
110 + if (i > 0) {
111 + for (i = i - 1; i >= 0; i--) {
112 + led_classdev_unregister(&leds_data[i].cdev);
113 + }
114 + }
115 +
116 + kfree(leds_data);
117 +
118 + return ret;
119 +}
120 +
121 +static int __devexit latch_led_remove(struct platform_device *pdev)
122 +{
123 + int i;
124 + struct latch_led_platform_data *pdata = pdev->dev.platform_data;
125 + struct latch_led_data *leds_data;
126 +
127 + leds_data = platform_get_drvdata(pdev);
128 +
129 + for (i = 0; i < pdata->num_leds; i++) {
130 + led_classdev_unregister(&leds_data[i].cdev);
131 + cancel_work_sync(&leds_data[i].work);
132 + }
133 +
134 + kfree(leds_data);
135 +
136 + return 0;
137 +}
138 +
139 +static struct platform_driver latch_led_driver = {
140 + .probe = latch_led_probe,
141 + .remove = __devexit_p(latch_led_remove),
142 + .driver = {
143 + .name = "leds-latch",
144 + .owner = THIS_MODULE,
145 + },
146 +};
147 +
148 +static int __init latch_led_init(void)
149 +{
150 + return platform_driver_register(&latch_led_driver);
151 +}
152 +
153 +static void __exit latch_led_exit(void)
154 +{
155 + platform_driver_unregister(&latch_led_driver);
156 +}
157 +
158 +module_init(latch_led_init);
159 +module_exit(latch_led_exit);
160 +
161 +MODULE_AUTHOR("Chris Lang <clang@gateworks.com>");
162 +MODULE_DESCRIPTION("Latch LED driver");
163 +MODULE_LICENSE("GPL");
164 Index: linux-2.6.25.4/drivers/leds/Makefile
165 ===================================================================
166 --- linux-2.6.25.4.orig/drivers/leds/Makefile
167 +++ linux-2.6.25.4/drivers/leds/Makefile
168 @@ -19,6 +19,7 @@ obj-$(CONFIG_LEDS_H1940) += leds-h1940.
169 obj-$(CONFIG_LEDS_COBALT_QUBE) += leds-cobalt-qube.o
170 obj-$(CONFIG_LEDS_COBALT_RAQ) += leds-cobalt-raq.o
171 obj-$(CONFIG_LEDS_GPIO) += leds-gpio.o
172 +obj-$(CONFIG_LEDS_LATCH) += leds-latch.o
173 obj-$(CONFIG_LEDS_CM_X270) += leds-cm-x270.o
174 obj-$(CONFIG_LEDS_CLEVO_MAIL) += leds-clevo-mail.o
175 obj-$(CONFIG_LEDS_HP6XX) += leds-hp6xx.o
176 Index: linux-2.6.25.4/include/linux/leds.h
177 ===================================================================
178 --- linux-2.6.25.4.orig/include/linux/leds.h
179 +++ linux-2.6.25.4/include/linux/leds.h
180 @@ -136,5 +136,18 @@ struct gpio_led_platform_data {
181 struct gpio_led *leds;
182 };
183
184 +/* For the leds-latch driver */
185 +struct latch_led {
186 + const char *name;
187 + char *default_trigger;
188 + unsigned bit;
189 +};
190 +
191 +struct latch_led_platform_data {
192 + int num_leds;
193 + u32 mem;
194 + struct latch_led *leds;
195 +};
196 +
197
198 #endif /* __LINUX_LEDS_H_INCLUDED */