blob: 8d11a5e23227105795d55c15c8379cc04e8145da [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001// SPDX-License-Identifier: GPL-2.0-only
Richard Purdiec3bc9952006-03-31 02:31:05 -08002/*
3 * LED Triggers Core
4 *
Richard Purdief8a7c6f2007-07-08 23:19:31 +01005 * Copyright 2005-2007 Openedhand Ltd.
Richard Purdiec3bc9952006-03-31 02:31:05 -08006 *
7 * Author: Richard Purdie <rpurdie@openedhand.com>
Richard Purdiec3bc9952006-03-31 02:31:05 -08008 */
9
Paul Gortmaker50237862016-08-15 16:54:48 -040010#include <linux/export.h>
Richard Purdiec3bc9952006-03-31 02:31:05 -080011#include <linux/kernel.h>
Richard Purdiec3bc9952006-03-31 02:31:05 -080012#include <linux/list.h>
13#include <linux/spinlock.h>
14#include <linux/device.h>
Richard Purdiec3bc9952006-03-31 02:31:05 -080015#include <linux/timer.h>
Richard Purdiedc472062007-11-10 13:29:04 +000016#include <linux/rwsem.h>
Richard Purdiec3bc9952006-03-31 02:31:05 -080017#include <linux/leds.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090018#include <linux/slab.h>
Richard Purdiec3bc9952006-03-31 02:31:05 -080019#include "leds.h"
20
21/*
22 * Nests outside led_cdev->trigger_lock
23 */
Richard Purdiedc472062007-11-10 13:29:04 +000024static DECLARE_RWSEM(triggers_list_lock);
Ezequiel Garciaba93cdc2016-04-28 19:03:38 -030025LIST_HEAD(trigger_list);
Richard Purdiec3bc9952006-03-31 02:31:05 -080026
Németh Márton4d404fd2008-03-09 20:59:57 +000027 /* Used by LED Class */
28
Richard Purdief8a7c6f2007-07-08 23:19:31 +010029ssize_t led_trigger_store(struct device *dev, struct device_attribute *attr,
30 const char *buf, size_t count)
Richard Purdiec3bc9952006-03-31 02:31:05 -080031{
Richard Purdief8a7c6f2007-07-08 23:19:31 +010032 struct led_classdev *led_cdev = dev_get_drvdata(dev);
Richard Purdiec3bc9952006-03-31 02:31:05 -080033 struct led_trigger *trig;
Jacek Anaszewskiacd899e2014-09-22 08:21:04 -070034 int ret = count;
35
36 mutex_lock(&led_cdev->led_access);
37
38 if (led_sysfs_is_disabled(led_cdev)) {
39 ret = -EBUSY;
40 goto unlock;
41 }
Richard Purdiec3bc9952006-03-31 02:31:05 -080042
Heiner Kallweit7296c332016-03-08 23:08:36 +010043 if (sysfs_streq(buf, "none")) {
Németh Márton0013b232008-03-09 20:54:37 +000044 led_trigger_remove(led_cdev);
Jacek Anaszewskiacd899e2014-09-22 08:21:04 -070045 goto unlock;
Richard Purdiec3bc9952006-03-31 02:31:05 -080046 }
47
Richard Purdiedc472062007-11-10 13:29:04 +000048 down_read(&triggers_list_lock);
Richard Purdiec3bc9952006-03-31 02:31:05 -080049 list_for_each_entry(trig, &trigger_list, next_trig) {
Heiner Kallweit7296c332016-03-08 23:08:36 +010050 if (sysfs_streq(buf, trig->name)) {
Richard Purdiedc472062007-11-10 13:29:04 +000051 down_write(&led_cdev->trigger_lock);
Richard Purdiec3bc9952006-03-31 02:31:05 -080052 led_trigger_set(led_cdev, trig);
Richard Purdiedc472062007-11-10 13:29:04 +000053 up_write(&led_cdev->trigger_lock);
Richard Purdiec3bc9952006-03-31 02:31:05 -080054
Richard Purdiedc472062007-11-10 13:29:04 +000055 up_read(&triggers_list_lock);
Jacek Anaszewskiacd899e2014-09-22 08:21:04 -070056 goto unlock;
Richard Purdiec3bc9952006-03-31 02:31:05 -080057 }
58 }
Heiner Kallweita3eac762016-07-01 23:08:54 +020059 /* we come here only if buf matches no trigger */
60 ret = -EINVAL;
Richard Purdiedc472062007-11-10 13:29:04 +000061 up_read(&triggers_list_lock);
Richard Purdiec3bc9952006-03-31 02:31:05 -080062
Jacek Anaszewskiacd899e2014-09-22 08:21:04 -070063unlock:
64 mutex_unlock(&led_cdev->led_access);
65 return ret;
Richard Purdiec3bc9952006-03-31 02:31:05 -080066}
Németh Márton4d404fd2008-03-09 20:59:57 +000067EXPORT_SYMBOL_GPL(led_trigger_store);
Richard Purdiec3bc9952006-03-31 02:31:05 -080068
Richard Purdief8a7c6f2007-07-08 23:19:31 +010069ssize_t led_trigger_show(struct device *dev, struct device_attribute *attr,
70 char *buf)
Richard Purdiec3bc9952006-03-31 02:31:05 -080071{
Richard Purdief8a7c6f2007-07-08 23:19:31 +010072 struct led_classdev *led_cdev = dev_get_drvdata(dev);
Richard Purdiec3bc9952006-03-31 02:31:05 -080073 struct led_trigger *trig;
74 int len = 0;
75
Richard Purdiedc472062007-11-10 13:29:04 +000076 down_read(&triggers_list_lock);
77 down_read(&led_cdev->trigger_lock);
Richard Purdiec3bc9952006-03-31 02:31:05 -080078
79 if (!led_cdev->trigger)
Nathan Sullivan3b9b9532016-08-15 17:20:14 -050080 len += scnprintf(buf+len, PAGE_SIZE - len, "[none] ");
Richard Purdiec3bc9952006-03-31 02:31:05 -080081 else
Nathan Sullivan3b9b9532016-08-15 17:20:14 -050082 len += scnprintf(buf+len, PAGE_SIZE - len, "none ");
Richard Purdiec3bc9952006-03-31 02:31:05 -080083
84 list_for_each_entry(trig, &trigger_list, next_trig) {
85 if (led_cdev->trigger && !strcmp(led_cdev->trigger->name,
86 trig->name))
Nathan Sullivan3b9b9532016-08-15 17:20:14 -050087 len += scnprintf(buf+len, PAGE_SIZE - len, "[%s] ",
88 trig->name);
Richard Purdiec3bc9952006-03-31 02:31:05 -080089 else
Nathan Sullivan3b9b9532016-08-15 17:20:14 -050090 len += scnprintf(buf+len, PAGE_SIZE - len, "%s ",
91 trig->name);
Richard Purdiec3bc9952006-03-31 02:31:05 -080092 }
Richard Purdiedc472062007-11-10 13:29:04 +000093 up_read(&led_cdev->trigger_lock);
94 up_read(&triggers_list_lock);
Richard Purdiec3bc9952006-03-31 02:31:05 -080095
Nathan Sullivan3b9b9532016-08-15 17:20:14 -050096 len += scnprintf(len+buf, PAGE_SIZE - len, "\n");
Richard Purdiec3bc9952006-03-31 02:31:05 -080097 return len;
98}
Németh Márton4d404fd2008-03-09 20:59:57 +000099EXPORT_SYMBOL_GPL(led_trigger_show);
Richard Purdiec3bc9952006-03-31 02:31:05 -0800100
101/* Caller must ensure led_cdev->trigger_lock held */
Uwe Kleine-König2282e1252018-07-02 22:05:21 +0200102int led_trigger_set(struct led_classdev *led_cdev, struct led_trigger *trig)
Richard Purdiec3bc9952006-03-31 02:31:05 -0800103{
104 unsigned long flags;
Colin Cross52c47742012-08-27 09:31:49 +0800105 char *event = NULL;
106 char *envp[2];
107 const char *name;
Uwe Kleine-König2282e1252018-07-02 22:05:21 +0200108 int ret;
Colin Cross52c47742012-08-27 09:31:49 +0800109
Jacek Anaszewskifbfa1972016-09-18 20:24:29 +0200110 if (!led_cdev->trigger && !trig)
Uwe Kleine-König2282e1252018-07-02 22:05:21 +0200111 return 0;
Jacek Anaszewskifbfa1972016-09-18 20:24:29 +0200112
Colin Cross52c47742012-08-27 09:31:49 +0800113 name = trig ? trig->name : "none";
114 event = kasprintf(GFP_KERNEL, "TRIGGER=%s", name);
Richard Purdiec3bc9952006-03-31 02:31:05 -0800115
116 /* Remove any existing trigger */
117 if (led_cdev->trigger) {
118 write_lock_irqsave(&led_cdev->trigger->leddev_list_lock, flags);
119 list_del(&led_cdev->trig_list);
Németh Márton4d404fd2008-03-09 20:59:57 +0000120 write_unlock_irqrestore(&led_cdev->trigger->leddev_list_lock,
121 flags);
Fabio Baltierid23a22a2012-08-15 21:44:34 +0800122 cancel_work_sync(&led_cdev->set_brightness_work);
123 led_stop_software_blink(led_cdev);
Richard Purdiec3bc9952006-03-31 02:31:05 -0800124 if (led_cdev->trigger->deactivate)
125 led_cdev->trigger->deactivate(led_cdev);
Uwe Kleine-Königa7e7a312018-07-02 22:05:22 +0200126 device_remove_groups(led_cdev->dev, led_cdev->trigger->groups);
Dmitry Baryshkovfe3025b2008-07-16 22:51:14 +0100127 led_cdev->trigger = NULL;
Uwe Kleine-Königa7d59042018-07-02 22:05:23 +0200128 led_cdev->trigger_data = NULL;
129 led_cdev->activated = false;
Shuah Khan19cd67e2012-06-14 04:34:30 +0800130 led_set_brightness(led_cdev, LED_OFF);
Richard Purdiec3bc9952006-03-31 02:31:05 -0800131 }
Bryan Wueb202622012-04-19 11:46:33 +0800132 if (trig) {
133 write_lock_irqsave(&trig->leddev_list_lock, flags);
134 list_add_tail(&led_cdev->trig_list, &trig->led_cdevs);
135 write_unlock_irqrestore(&trig->leddev_list_lock, flags);
136 led_cdev->trigger = trig;
Uwe Kleine-König2282e1252018-07-02 22:05:21 +0200137
Bryan Wueb202622012-04-19 11:46:33 +0800138 if (trig->activate)
Uwe Kleine-König2282e1252018-07-02 22:05:21 +0200139 ret = trig->activate(led_cdev);
140 else
141 ret = 0;
142
143 if (ret)
144 goto err_activate;
Uwe Kleine-Königa7e7a312018-07-02 22:05:22 +0200145
146 ret = device_add_groups(led_cdev->dev, trig->groups);
147 if (ret) {
148 dev_err(led_cdev->dev, "Failed to add trigger attributes\n");
149 goto err_add_groups;
150 }
Richard Purdiec3bc9952006-03-31 02:31:05 -0800151 }
Colin Cross52c47742012-08-27 09:31:49 +0800152
153 if (event) {
154 envp[0] = event;
155 envp[1] = NULL;
Jacek Anaszewski6f3bad92016-09-19 12:44:50 +0200156 if (kobject_uevent_env(&led_cdev->dev->kobj, KOBJ_CHANGE, envp))
157 dev_err(led_cdev->dev,
158 "%s: Error sending uevent\n", __func__);
Colin Cross52c47742012-08-27 09:31:49 +0800159 kfree(event);
160 }
Uwe Kleine-König2282e1252018-07-02 22:05:21 +0200161
162 return 0;
163
Uwe Kleine-Königa7e7a312018-07-02 22:05:22 +0200164err_add_groups:
165
166 if (trig->deactivate)
167 trig->deactivate(led_cdev);
Uwe Kleine-König2282e1252018-07-02 22:05:21 +0200168err_activate:
Uwe Kleine-Königa7e7a312018-07-02 22:05:22 +0200169
Uwe Kleine-König2282e1252018-07-02 22:05:21 +0200170 led_cdev->trigger = NULL;
Uwe Kleine-Königa7d59042018-07-02 22:05:23 +0200171 led_cdev->trigger_data = NULL;
Uwe Kleine-König2282e1252018-07-02 22:05:21 +0200172 write_lock_irqsave(&led_cdev->trigger->leddev_list_lock, flags);
173 list_del(&led_cdev->trig_list);
174 write_unlock_irqrestore(&led_cdev->trigger->leddev_list_lock, flags);
175 led_set_brightness(led_cdev, LED_OFF);
176
177 return ret;
Richard Purdiec3bc9952006-03-31 02:31:05 -0800178}
Németh Márton4d404fd2008-03-09 20:59:57 +0000179EXPORT_SYMBOL_GPL(led_trigger_set);
Richard Purdiec3bc9952006-03-31 02:31:05 -0800180
Németh Márton0013b232008-03-09 20:54:37 +0000181void led_trigger_remove(struct led_classdev *led_cdev)
182{
183 down_write(&led_cdev->trigger_lock);
184 led_trigger_set(led_cdev, NULL);
185 up_write(&led_cdev->trigger_lock);
186}
Németh Márton4d404fd2008-03-09 20:59:57 +0000187EXPORT_SYMBOL_GPL(led_trigger_remove);
Németh Márton0013b232008-03-09 20:54:37 +0000188
Richard Purdiec3bc9952006-03-31 02:31:05 -0800189void led_trigger_set_default(struct led_classdev *led_cdev)
190{
191 struct led_trigger *trig;
192
193 if (!led_cdev->default_trigger)
194 return;
195
Richard Purdiedc472062007-11-10 13:29:04 +0000196 down_read(&triggers_list_lock);
197 down_write(&led_cdev->trigger_lock);
Richard Purdiec3bc9952006-03-31 02:31:05 -0800198 list_for_each_entry(trig, &trigger_list, next_trig) {
Jacek Anaszewskic4f7bd42018-12-10 10:29:57 +0100199 if (!strcmp(led_cdev->default_trigger, trig->name)) {
Jacek Anaszewski02d31762018-12-10 10:29:58 +0100200 led_cdev->flags |= LED_INIT_DEFAULT_TRIGGER;
Richard Purdiec3bc9952006-03-31 02:31:05 -0800201 led_trigger_set(led_cdev, trig);
Jacek Anaszewskic4f7bd42018-12-10 10:29:57 +0100202 break;
203 }
Richard Purdiec3bc9952006-03-31 02:31:05 -0800204 }
Richard Purdiedc472062007-11-10 13:29:04 +0000205 up_write(&led_cdev->trigger_lock);
206 up_read(&triggers_list_lock);
Richard Purdiec3bc9952006-03-31 02:31:05 -0800207}
Németh Márton4d404fd2008-03-09 20:59:57 +0000208EXPORT_SYMBOL_GPL(led_trigger_set_default);
209
Fabio Baltieria8df7b12012-11-04 01:54:34 -0800210void led_trigger_rename_static(const char *name, struct led_trigger *trig)
211{
212 /* new name must be on a temporary string to prevent races */
213 BUG_ON(name == trig->name);
214
215 down_write(&triggers_list_lock);
216 /* this assumes that trig->name was originaly allocated to
217 * non constant storage */
218 strcpy((char *)trig->name, name);
219 up_write(&triggers_list_lock);
220}
221EXPORT_SYMBOL_GPL(led_trigger_rename_static);
222
Németh Márton4d404fd2008-03-09 20:59:57 +0000223/* LED Trigger Interface */
Richard Purdiec3bc9952006-03-31 02:31:05 -0800224
Bryan Wueb202622012-04-19 11:46:33 +0800225int led_trigger_register(struct led_trigger *trig)
Richard Purdiec3bc9952006-03-31 02:31:05 -0800226{
227 struct led_classdev *led_cdev;
Bryan Wueb202622012-04-19 11:46:33 +0800228 struct led_trigger *_trig;
Richard Purdiec3bc9952006-03-31 02:31:05 -0800229
Bryan Wueb202622012-04-19 11:46:33 +0800230 rwlock_init(&trig->leddev_list_lock);
231 INIT_LIST_HEAD(&trig->led_cdevs);
Richard Purdiec3bc9952006-03-31 02:31:05 -0800232
Richard Purdiedc472062007-11-10 13:29:04 +0000233 down_write(&triggers_list_lock);
Adam Nielsen700c6ea2009-02-18 08:18:04 +1000234 /* Make sure the trigger's name isn't already in use */
Bryan Wueb202622012-04-19 11:46:33 +0800235 list_for_each_entry(_trig, &trigger_list, next_trig) {
236 if (!strcmp(_trig->name, trig->name)) {
Adam Nielsen700c6ea2009-02-18 08:18:04 +1000237 up_write(&triggers_list_lock);
238 return -EEXIST;
239 }
240 }
241 /* Add to the list of led triggers */
Bryan Wueb202622012-04-19 11:46:33 +0800242 list_add_tail(&trig->next_trig, &trigger_list);
Richard Purdiedc472062007-11-10 13:29:04 +0000243 up_write(&triggers_list_lock);
Richard Purdiec3bc9952006-03-31 02:31:05 -0800244
245 /* Register with any LEDs that have this as a default trigger */
Richard Purdie72f8da32007-12-31 23:09:44 +0000246 down_read(&leds_list_lock);
Richard Purdiec3bc9952006-03-31 02:31:05 -0800247 list_for_each_entry(led_cdev, &leds_list, node) {
Richard Purdiedc472062007-11-10 13:29:04 +0000248 down_write(&led_cdev->trigger_lock);
Richard Purdiec3bc9952006-03-31 02:31:05 -0800249 if (!led_cdev->trigger && led_cdev->default_trigger &&
Krzysztof Kozlowski8146aac2018-12-10 10:29:59 +0100250 !strcmp(led_cdev->default_trigger, trig->name)) {
251 led_cdev->flags |= LED_INIT_DEFAULT_TRIGGER;
Bryan Wueb202622012-04-19 11:46:33 +0800252 led_trigger_set(led_cdev, trig);
Krzysztof Kozlowski8146aac2018-12-10 10:29:59 +0100253 }
Richard Purdiedc472062007-11-10 13:29:04 +0000254 up_write(&led_cdev->trigger_lock);
Richard Purdiec3bc9952006-03-31 02:31:05 -0800255 }
Richard Purdie72f8da32007-12-31 23:09:44 +0000256 up_read(&leds_list_lock);
Richard Purdiec3bc9952006-03-31 02:31:05 -0800257
258 return 0;
259}
Németh Márton4d404fd2008-03-09 20:59:57 +0000260EXPORT_SYMBOL_GPL(led_trigger_register);
Richard Purdiec3bc9952006-03-31 02:31:05 -0800261
Bryan Wueb202622012-04-19 11:46:33 +0800262void led_trigger_unregister(struct led_trigger *trig)
Richard Purdiec3bc9952006-03-31 02:31:05 -0800263{
264 struct led_classdev *led_cdev;
265
Sasha Levin14f57162014-04-04 10:01:13 -0700266 if (list_empty_careful(&trig->next_trig))
267 return;
268
Richard Purdiec3bc9952006-03-31 02:31:05 -0800269 /* Remove from the list of led triggers */
Richard Purdiedc472062007-11-10 13:29:04 +0000270 down_write(&triggers_list_lock);
Sasha Levin14f57162014-04-04 10:01:13 -0700271 list_del_init(&trig->next_trig);
Richard Purdiedc472062007-11-10 13:29:04 +0000272 up_write(&triggers_list_lock);
Richard Purdiec3bc9952006-03-31 02:31:05 -0800273
274 /* Remove anyone actively using this trigger */
Richard Purdie72f8da32007-12-31 23:09:44 +0000275 down_read(&leds_list_lock);
Richard Purdiec3bc9952006-03-31 02:31:05 -0800276 list_for_each_entry(led_cdev, &leds_list, node) {
Richard Purdiedc472062007-11-10 13:29:04 +0000277 down_write(&led_cdev->trigger_lock);
Bryan Wueb202622012-04-19 11:46:33 +0800278 if (led_cdev->trigger == trig)
Richard Purdiec3bc9952006-03-31 02:31:05 -0800279 led_trigger_set(led_cdev, NULL);
Richard Purdiedc472062007-11-10 13:29:04 +0000280 up_write(&led_cdev->trigger_lock);
Richard Purdiec3bc9952006-03-31 02:31:05 -0800281 }
Richard Purdie72f8da32007-12-31 23:09:44 +0000282 up_read(&leds_list_lock);
Richard Purdiec3bc9952006-03-31 02:31:05 -0800283}
Németh Márton4d404fd2008-03-09 20:59:57 +0000284EXPORT_SYMBOL_GPL(led_trigger_unregister);
285
Heiner Kallweit9534cc32016-01-02 01:36:41 +0100286static void devm_led_trigger_release(struct device *dev, void *res)
287{
288 led_trigger_unregister(*(struct led_trigger **)res);
289}
290
291int devm_led_trigger_register(struct device *dev,
292 struct led_trigger *trig)
293{
294 struct led_trigger **dr;
295 int rc;
296
297 dr = devres_alloc(devm_led_trigger_release, sizeof(*dr),
298 GFP_KERNEL);
299 if (!dr)
300 return -ENOMEM;
301
302 *dr = trig;
303
304 rc = led_trigger_register(trig);
305 if (rc)
306 devres_free(dr);
307 else
308 devres_add(dev, dr);
309
310 return rc;
311}
312EXPORT_SYMBOL_GPL(devm_led_trigger_register);
313
Németh Márton4d404fd2008-03-09 20:59:57 +0000314/* Simple LED Tigger Interface */
315
Bryan Wueb202622012-04-19 11:46:33 +0800316void led_trigger_event(struct led_trigger *trig,
Németh Márton4d404fd2008-03-09 20:59:57 +0000317 enum led_brightness brightness)
318{
ZHAO Gang11e043b2013-12-28 07:00:26 -0800319 struct led_classdev *led_cdev;
Németh Márton4d404fd2008-03-09 20:59:57 +0000320
Bryan Wueb202622012-04-19 11:46:33 +0800321 if (!trig)
Németh Márton4d404fd2008-03-09 20:59:57 +0000322 return;
323
Bryan Wueb202622012-04-19 11:46:33 +0800324 read_lock(&trig->leddev_list_lock);
ZHAO Gang11e043b2013-12-28 07:00:26 -0800325 list_for_each_entry(led_cdev, &trig->led_cdevs, trig_list)
Fabio Baltierid23a22a2012-08-15 21:44:34 +0800326 led_set_brightness(led_cdev, brightness);
Bryan Wueb202622012-04-19 11:46:33 +0800327 read_unlock(&trig->leddev_list_lock);
Németh Márton4d404fd2008-03-09 20:59:57 +0000328}
329EXPORT_SYMBOL_GPL(led_trigger_event);
330
Bryan Wu20c0e6b2012-06-15 22:15:27 +0800331static void led_trigger_blink_setup(struct led_trigger *trig,
Fabio Baltieri5bb629c2012-05-27 07:19:22 +0800332 unsigned long *delay_on,
333 unsigned long *delay_off,
334 int oneshot,
335 int invert)
Vasily Khoruzhick0b9536c2011-01-07 16:28:16 +0000336{
ZHAO Gang11e043b2013-12-28 07:00:26 -0800337 struct led_classdev *led_cdev;
Vasily Khoruzhick0b9536c2011-01-07 16:28:16 +0000338
Bryan Wueb202622012-04-19 11:46:33 +0800339 if (!trig)
Vasily Khoruzhick0b9536c2011-01-07 16:28:16 +0000340 return;
341
Bryan Wueb202622012-04-19 11:46:33 +0800342 read_lock(&trig->leddev_list_lock);
ZHAO Gang11e043b2013-12-28 07:00:26 -0800343 list_for_each_entry(led_cdev, &trig->led_cdevs, trig_list) {
Fabio Baltieri5bb629c2012-05-27 07:19:22 +0800344 if (oneshot)
345 led_blink_set_oneshot(led_cdev, delay_on, delay_off,
346 invert);
347 else
348 led_blink_set(led_cdev, delay_on, delay_off);
Vasily Khoruzhick0b9536c2011-01-07 16:28:16 +0000349 }
Bryan Wueb202622012-04-19 11:46:33 +0800350 read_unlock(&trig->leddev_list_lock);
Vasily Khoruzhick0b9536c2011-01-07 16:28:16 +0000351}
Fabio Baltieri5bb629c2012-05-27 07:19:22 +0800352
353void led_trigger_blink(struct led_trigger *trig,
354 unsigned long *delay_on,
355 unsigned long *delay_off)
356{
357 led_trigger_blink_setup(trig, delay_on, delay_off, 0, 0);
358}
Vasily Khoruzhick0b9536c2011-01-07 16:28:16 +0000359EXPORT_SYMBOL_GPL(led_trigger_blink);
360
Fabio Baltieri5bb629c2012-05-27 07:19:22 +0800361void led_trigger_blink_oneshot(struct led_trigger *trig,
362 unsigned long *delay_on,
363 unsigned long *delay_off,
364 int invert)
365{
366 led_trigger_blink_setup(trig, delay_on, delay_off, 1, invert);
367}
368EXPORT_SYMBOL_GPL(led_trigger_blink_oneshot);
369
Németh Márton4d404fd2008-03-09 20:59:57 +0000370void led_trigger_register_simple(const char *name, struct led_trigger **tp)
371{
Bryan Wueb202622012-04-19 11:46:33 +0800372 struct led_trigger *trig;
Németh Márton4d404fd2008-03-09 20:59:57 +0000373 int err;
374
Bryan Wueb202622012-04-19 11:46:33 +0800375 trig = kzalloc(sizeof(struct led_trigger), GFP_KERNEL);
Németh Márton4d404fd2008-03-09 20:59:57 +0000376
Bryan Wueb202622012-04-19 11:46:33 +0800377 if (trig) {
378 trig->name = name;
379 err = led_trigger_register(trig);
Masakazu Mokunocba4c2a2011-10-31 17:11:59 -0700380 if (err < 0) {
Bryan Wueb202622012-04-19 11:46:33 +0800381 kfree(trig);
382 trig = NULL;
Sachin Kamat09f5fe72012-11-25 13:00:44 +0530383 pr_warn("LED trigger %s failed to register (%d)\n",
384 name, err);
Masakazu Mokunocba4c2a2011-10-31 17:11:59 -0700385 }
Sachin Kamat09f5fe72012-11-25 13:00:44 +0530386 } else {
387 pr_warn("LED trigger %s failed to register (no memory)\n",
388 name);
389 }
Bryan Wueb202622012-04-19 11:46:33 +0800390 *tp = trig;
Németh Márton4d404fd2008-03-09 20:59:57 +0000391}
392EXPORT_SYMBOL_GPL(led_trigger_register_simple);
Richard Purdiec3bc9952006-03-31 02:31:05 -0800393
Bryan Wueb202622012-04-19 11:46:33 +0800394void led_trigger_unregister_simple(struct led_trigger *trig)
Richard Purdiec3bc9952006-03-31 02:31:05 -0800395{
Bryan Wueb202622012-04-19 11:46:33 +0800396 if (trig)
397 led_trigger_unregister(trig);
398 kfree(trig);
Richard Purdiec3bc9952006-03-31 02:31:05 -0800399}
Richard Purdiec3bc9952006-03-31 02:31:05 -0800400EXPORT_SYMBOL_GPL(led_trigger_unregister_simple);