diff options
Diffstat (limited to 'drivers/leds/led-triggers.c')
-rw-r--r-- | drivers/leds/led-triggers.c | 110 |
1 files changed, 55 insertions, 55 deletions
diff --git a/drivers/leds/led-triggers.c b/drivers/leds/led-triggers.c index 21dd96909444..0f242b3f09b6 100644 --- a/drivers/leds/led-triggers.c +++ b/drivers/leds/led-triggers.c | |||
@@ -29,6 +29,8 @@ | |||
29 | static DECLARE_RWSEM(triggers_list_lock); | 29 | static DECLARE_RWSEM(triggers_list_lock); |
30 | static LIST_HEAD(trigger_list); | 30 | static LIST_HEAD(trigger_list); |
31 | 31 | ||
32 | /* Used by LED Class */ | ||
33 | |||
32 | ssize_t led_trigger_store(struct device *dev, struct device_attribute *attr, | 34 | ssize_t led_trigger_store(struct device *dev, struct device_attribute *attr, |
33 | const char *buf, size_t count) | 35 | const char *buf, size_t count) |
34 | { | 36 | { |
@@ -64,7 +66,7 @@ ssize_t led_trigger_store(struct device *dev, struct device_attribute *attr, | |||
64 | 66 | ||
65 | return -EINVAL; | 67 | return -EINVAL; |
66 | } | 68 | } |
67 | 69 | EXPORT_SYMBOL_GPL(led_trigger_store); | |
68 | 70 | ||
69 | ssize_t led_trigger_show(struct device *dev, struct device_attribute *attr, | 71 | ssize_t led_trigger_show(struct device *dev, struct device_attribute *attr, |
70 | char *buf) | 72 | char *buf) |
@@ -94,24 +96,7 @@ ssize_t led_trigger_show(struct device *dev, struct device_attribute *attr, | |||
94 | len += sprintf(len+buf, "\n"); | 96 | len += sprintf(len+buf, "\n"); |
95 | return len; | 97 | return len; |
96 | } | 98 | } |
97 | 99 | EXPORT_SYMBOL_GPL(led_trigger_show); | |
98 | void led_trigger_event(struct led_trigger *trigger, | ||
99 | enum led_brightness brightness) | ||
100 | { | ||
101 | struct list_head *entry; | ||
102 | |||
103 | if (!trigger) | ||
104 | return; | ||
105 | |||
106 | read_lock(&trigger->leddev_list_lock); | ||
107 | list_for_each(entry, &trigger->led_cdevs) { | ||
108 | struct led_classdev *led_cdev; | ||
109 | |||
110 | led_cdev = list_entry(entry, struct led_classdev, trig_list); | ||
111 | led_set_brightness(led_cdev, brightness); | ||
112 | } | ||
113 | read_unlock(&trigger->leddev_list_lock); | ||
114 | } | ||
115 | 100 | ||
116 | /* Caller must ensure led_cdev->trigger_lock held */ | 101 | /* Caller must ensure led_cdev->trigger_lock held */ |
117 | void led_trigger_set(struct led_classdev *led_cdev, struct led_trigger *trigger) | 102 | void led_trigger_set(struct led_classdev *led_cdev, struct led_trigger *trigger) |
@@ -122,7 +107,8 @@ void led_trigger_set(struct led_classdev *led_cdev, struct led_trigger *trigger) | |||
122 | if (led_cdev->trigger) { | 107 | if (led_cdev->trigger) { |
123 | write_lock_irqsave(&led_cdev->trigger->leddev_list_lock, flags); | 108 | write_lock_irqsave(&led_cdev->trigger->leddev_list_lock, flags); |
124 | list_del(&led_cdev->trig_list); | 109 | list_del(&led_cdev->trig_list); |
125 | write_unlock_irqrestore(&led_cdev->trigger->leddev_list_lock, flags); | 110 | write_unlock_irqrestore(&led_cdev->trigger->leddev_list_lock, |
111 | flags); | ||
126 | if (led_cdev->trigger->deactivate) | 112 | if (led_cdev->trigger->deactivate) |
127 | led_cdev->trigger->deactivate(led_cdev); | 113 | led_cdev->trigger->deactivate(led_cdev); |
128 | led_set_brightness(led_cdev, LED_OFF); | 114 | led_set_brightness(led_cdev, LED_OFF); |
@@ -136,6 +122,7 @@ void led_trigger_set(struct led_classdev *led_cdev, struct led_trigger *trigger) | |||
136 | } | 122 | } |
137 | led_cdev->trigger = trigger; | 123 | led_cdev->trigger = trigger; |
138 | } | 124 | } |
125 | EXPORT_SYMBOL_GPL(led_trigger_set); | ||
139 | 126 | ||
140 | void led_trigger_remove(struct led_classdev *led_cdev) | 127 | void led_trigger_remove(struct led_classdev *led_cdev) |
141 | { | 128 | { |
@@ -143,6 +130,7 @@ void led_trigger_remove(struct led_classdev *led_cdev) | |||
143 | led_trigger_set(led_cdev, NULL); | 130 | led_trigger_set(led_cdev, NULL); |
144 | up_write(&led_cdev->trigger_lock); | 131 | up_write(&led_cdev->trigger_lock); |
145 | } | 132 | } |
133 | EXPORT_SYMBOL_GPL(led_trigger_remove); | ||
146 | 134 | ||
147 | void led_trigger_set_default(struct led_classdev *led_cdev) | 135 | void led_trigger_set_default(struct led_classdev *led_cdev) |
148 | { | 136 | { |
@@ -160,6 +148,9 @@ void led_trigger_set_default(struct led_classdev *led_cdev) | |||
160 | up_write(&led_cdev->trigger_lock); | 148 | up_write(&led_cdev->trigger_lock); |
161 | up_read(&triggers_list_lock); | 149 | up_read(&triggers_list_lock); |
162 | } | 150 | } |
151 | EXPORT_SYMBOL_GPL(led_trigger_set_default); | ||
152 | |||
153 | /* LED Trigger Interface */ | ||
163 | 154 | ||
164 | int led_trigger_register(struct led_trigger *trigger) | 155 | int led_trigger_register(struct led_trigger *trigger) |
165 | { | 156 | { |
@@ -186,26 +177,7 @@ int led_trigger_register(struct led_trigger *trigger) | |||
186 | 177 | ||
187 | return 0; | 178 | return 0; |
188 | } | 179 | } |
189 | 180 | EXPORT_SYMBOL_GPL(led_trigger_register); | |
190 | void led_trigger_register_simple(const char *name, struct led_trigger **tp) | ||
191 | { | ||
192 | struct led_trigger *trigger; | ||
193 | int err; | ||
194 | |||
195 | trigger = kzalloc(sizeof(struct led_trigger), GFP_KERNEL); | ||
196 | |||
197 | if (trigger) { | ||
198 | trigger->name = name; | ||
199 | err = led_trigger_register(trigger); | ||
200 | if (err < 0) | ||
201 | printk(KERN_WARNING "LED trigger %s failed to register" | ||
202 | " (%d)\n", name, err); | ||
203 | } else | ||
204 | printk(KERN_WARNING "LED trigger %s failed to register" | ||
205 | " (no memory)\n", name); | ||
206 | |||
207 | *tp = trigger; | ||
208 | } | ||
209 | 181 | ||
210 | void led_trigger_unregister(struct led_trigger *trigger) | 182 | void led_trigger_unregister(struct led_trigger *trigger) |
211 | { | 183 | { |
@@ -226,29 +198,57 @@ void led_trigger_unregister(struct led_trigger *trigger) | |||
226 | } | 198 | } |
227 | up_read(&leds_list_lock); | 199 | up_read(&leds_list_lock); |
228 | } | 200 | } |
201 | EXPORT_SYMBOL_GPL(led_trigger_unregister); | ||
229 | 202 | ||
230 | void led_trigger_unregister_simple(struct led_trigger *trigger) | 203 | /* Simple LED Tigger Interface */ |
204 | |||
205 | void led_trigger_event(struct led_trigger *trigger, | ||
206 | enum led_brightness brightness) | ||
231 | { | 207 | { |
232 | if (trigger) | 208 | struct list_head *entry; |
233 | led_trigger_unregister(trigger); | 209 | |
234 | kfree(trigger); | 210 | if (!trigger) |
211 | return; | ||
212 | |||
213 | read_lock(&trigger->leddev_list_lock); | ||
214 | list_for_each(entry, &trigger->led_cdevs) { | ||
215 | struct led_classdev *led_cdev; | ||
216 | |||
217 | led_cdev = list_entry(entry, struct led_classdev, trig_list); | ||
218 | led_set_brightness(led_cdev, brightness); | ||
219 | } | ||
220 | read_unlock(&trigger->leddev_list_lock); | ||
235 | } | 221 | } |
222 | EXPORT_SYMBOL_GPL(led_trigger_event); | ||
236 | 223 | ||
237 | /* Used by LED Class */ | 224 | void led_trigger_register_simple(const char *name, struct led_trigger **tp) |
238 | EXPORT_SYMBOL_GPL(led_trigger_set); | 225 | { |
239 | EXPORT_SYMBOL_GPL(led_trigger_remove); | 226 | struct led_trigger *trigger; |
240 | EXPORT_SYMBOL_GPL(led_trigger_set_default); | 227 | int err; |
241 | EXPORT_SYMBOL_GPL(led_trigger_show); | ||
242 | EXPORT_SYMBOL_GPL(led_trigger_store); | ||
243 | 228 | ||
244 | /* LED Trigger Interface */ | 229 | trigger = kzalloc(sizeof(struct led_trigger), GFP_KERNEL); |
245 | EXPORT_SYMBOL_GPL(led_trigger_register); | ||
246 | EXPORT_SYMBOL_GPL(led_trigger_unregister); | ||
247 | 230 | ||
248 | /* Simple LED Tigger Interface */ | 231 | if (trigger) { |
232 | trigger->name = name; | ||
233 | err = led_trigger_register(trigger); | ||
234 | if (err < 0) | ||
235 | printk(KERN_WARNING "LED trigger %s failed to register" | ||
236 | " (%d)\n", name, err); | ||
237 | } else | ||
238 | printk(KERN_WARNING "LED trigger %s failed to register" | ||
239 | " (no memory)\n", name); | ||
240 | |||
241 | *tp = trigger; | ||
242 | } | ||
249 | EXPORT_SYMBOL_GPL(led_trigger_register_simple); | 243 | EXPORT_SYMBOL_GPL(led_trigger_register_simple); |
244 | |||
245 | void led_trigger_unregister_simple(struct led_trigger *trigger) | ||
246 | { | ||
247 | if (trigger) | ||
248 | led_trigger_unregister(trigger); | ||
249 | kfree(trigger); | ||
250 | } | ||
250 | EXPORT_SYMBOL_GPL(led_trigger_unregister_simple); | 251 | EXPORT_SYMBOL_GPL(led_trigger_unregister_simple); |
251 | EXPORT_SYMBOL_GPL(led_trigger_event); | ||
252 | 252 | ||
253 | MODULE_AUTHOR("Richard Purdie"); | 253 | MODULE_AUTHOR("Richard Purdie"); |
254 | MODULE_LICENSE("GPL"); | 254 | MODULE_LICENSE("GPL"); |