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