1 --- a/compat/compat-2.6.37.c
2 +++ b/compat/compat-2.6.37.c
3 @@ -152,3 +152,175 @@ int compat_genl_unregister_family(struct
5 EXPORT_SYMBOL(compat_genl_unregister_family);
7 +#ifdef CONFIG_LEDS_CLASS
9 +#undef led_brightness_set
10 +#undef led_classdev_unregister
13 +static LIST_HEAD(led_timers);
16 + struct list_head list;
17 + struct led_classdev *cdev;
18 + struct timer_list blink_timer;
19 + unsigned long blink_delay_on;
20 + unsigned long blink_delay_off;
21 + int blink_brightness;
24 +static void led_brightness_set(struct led_classdev *led_cdev,
25 + enum led_brightness brightness)
27 + led_cdev->brightness = brightness;
28 + led_cdev->brightness_set(led_cdev, brightness);
31 +static struct led_timer *led_get_timer(struct led_classdev *led_cdev)
33 + struct led_timer *p;
34 + unsigned long flags;
36 + spin_lock_irqsave(&led_lock, flags);
37 + list_for_each_entry(p, &led_timers, list) {
38 + if (p->cdev == led_cdev)
43 + spin_unlock_irqrestore(&led_lock, flags);
47 +static void led_stop_software_blink(struct led_timer *led)
49 + del_timer_sync(&led->blink_timer);
50 + led->blink_delay_on = 0;
51 + led->blink_delay_off = 0;
54 +static void led_timer_function(unsigned long data)
56 + struct led_timer *led = (struct led_timer *)data;
57 + unsigned long brightness;
58 + unsigned long delay;
60 + if (!led->blink_delay_on || !led->blink_delay_off) {
61 + led->cdev->brightness_set(led->cdev, LED_OFF);
65 + brightness = led->cdev->brightness;
67 + /* Time to switch the LED on. */
68 + brightness = led->blink_brightness;
69 + delay = led->blink_delay_on;
71 + /* Store the current brightness value to be able
72 + * to restore it when the delay_off period is over.
74 + led->blink_brightness = brightness;
75 + brightness = LED_OFF;
76 + delay = led->blink_delay_off;
79 + led_brightness_set(led->cdev, brightness);
80 + mod_timer(&led->blink_timer, jiffies + msecs_to_jiffies(delay));
83 +static struct led_timer *led_new_timer(struct led_classdev *led_cdev)
85 + struct led_timer *led;
86 + unsigned long flags;
88 + led = kzalloc(sizeof(struct led_timer), GFP_ATOMIC);
92 + led->cdev = led_cdev;
93 + init_timer(&led->blink_timer);
94 + led->blink_timer.function = led_timer_function;
95 + led->blink_timer.data = (unsigned long) led;
97 + spin_lock_irqsave(&led_lock, flags);
98 + list_add(&led->list, &led_timers);
99 + spin_unlock_irqrestore(&led_lock, flags);
104 +void led_blink_set(struct led_classdev *led_cdev,
105 + unsigned long *delay_on,
106 + unsigned long *delay_off)
108 + struct led_timer *led = led_get_timer(led_cdev);
109 + int current_brightness;
112 + led = led_new_timer(led_cdev);
117 + /* blink with 1 Hz as default if nothing specified */
118 + if (!*delay_on && !*delay_off)
119 + *delay_on = *delay_off = 500;
121 + if (led->blink_delay_on == *delay_on &&
122 + led->blink_delay_off == *delay_off)
125 + current_brightness = led_cdev->brightness;
126 + if (current_brightness)
127 + led->blink_brightness = current_brightness;
128 + if (!led->blink_brightness)
129 + led->blink_brightness = led_cdev->max_brightness;
131 + led_stop_software_blink(led);
132 + led->blink_delay_on = *delay_on;
133 + led->blink_delay_off = *delay_off;
135 + /* never on - don't blink */
139 + /* never off - just set to brightness */
141 + led_brightness_set(led_cdev, led->blink_brightness);
145 + mod_timer(&led->blink_timer, jiffies + 1);
147 +EXPORT_SYMBOL(led_blink_set);
149 +void compat_led_brightness_set(struct led_classdev *led_cdev,
150 + enum led_brightness brightness)
152 + struct led_timer *led = led_get_timer(led_cdev);
155 + led_stop_software_blink(led);
157 + return led_cdev->brightness_set(led_cdev, brightness);
159 +EXPORT_SYMBOL(compat_led_brightness_set);
161 +void compat_led_classdev_unregister(struct led_classdev *led_cdev)
163 + struct led_timer *led = led_get_timer(led_cdev);
164 + unsigned long flags;
167 + del_timer_sync(&led->blink_timer);
168 + spin_lock_irqsave(&led_lock, flags);
169 + list_del(&led->list);
170 + spin_unlock_irqrestore(&led_lock, flags);
174 + led_classdev_unregister(led_cdev);
176 +EXPORT_SYMBOL(compat_led_classdev_unregister);
179 --- a/include/linux/compat-2.6.37.h
180 +++ b/include/linux/compat-2.6.37.h
182 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,37))
184 #include <linux/skbuff.h>
185 +#include <linux/leds.h>
187 #define SDIO_CLASS_BT_AMP 0x09 /* Type-A Bluetooth AMP interface */
189 @@ -93,6 +94,18 @@ int genl_unregister_family(struct genl_f
190 #define genl_register_mc_group(_fam, _grp) genl_register_mc_group(&(_fam)->family, _grp)
191 #define genl_unregister_mc_group(_fam, _grp) genl_unregister_mc_group(&(_fam)->family, _grp)
194 +extern void led_blink_set(struct led_classdev *led_cdev,
195 + unsigned long *delay_on,
196 + unsigned long *delay_off);
198 +#define led_classdev_unregister compat_led_classdev_unregister
199 +extern void led_classdev_unregister(struct led_classdev *led_cdev);
201 +#define led_brightness_set compat_led_brightness_set
202 +extern void led_brightness_set(struct led_classdev *led_cdev,
203 + enum led_brightness brightness);
205 #endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,37)) */
207 #endif /* LINUX_26_37_COMPAT_H */