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