perf tools: Don't clone maps from parent when synthesizing forks
[linux/fpc-iii.git] / drivers / leds / trigger / ledtrig-oneshot.c
blob95c9be4b6e7e7129aefcc047dcca0046a2ad3e21
1 /*
2 * One-shot LED Trigger
4 * Copyright 2012, Fabio Baltieri <fabio.baltieri@gmail.com>
6 * Based on ledtrig-timer.c by Richard Purdie <rpurdie@openedhand.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
13 #include <linux/module.h>
14 #include <linux/kernel.h>
15 #include <linux/init.h>
16 #include <linux/device.h>
17 #include <linux/ctype.h>
18 #include <linux/slab.h>
19 #include <linux/leds.h>
20 #include "../leds.h"
22 #define DEFAULT_DELAY 100
24 struct oneshot_trig_data {
25 unsigned int invert;
28 static ssize_t led_shot(struct device *dev,
29 struct device_attribute *attr, const char *buf, size_t size)
31 struct led_classdev *led_cdev = led_trigger_get_led(dev);
32 struct oneshot_trig_data *oneshot_data = led_trigger_get_drvdata(dev);
34 led_blink_set_oneshot(led_cdev,
35 &led_cdev->blink_delay_on, &led_cdev->blink_delay_off,
36 oneshot_data->invert);
38 /* content is ignored */
39 return size;
41 static ssize_t led_invert_show(struct device *dev,
42 struct device_attribute *attr, char *buf)
44 struct oneshot_trig_data *oneshot_data = led_trigger_get_drvdata(dev);
46 return sprintf(buf, "%u\n", oneshot_data->invert);
49 static ssize_t led_invert_store(struct device *dev,
50 struct device_attribute *attr, const char *buf, size_t size)
52 struct led_classdev *led_cdev = led_trigger_get_led(dev);
53 struct oneshot_trig_data *oneshot_data = led_trigger_get_drvdata(dev);
54 unsigned long state;
55 int ret;
57 ret = kstrtoul(buf, 0, &state);
58 if (ret)
59 return ret;
61 oneshot_data->invert = !!state;
63 if (oneshot_data->invert)
64 led_set_brightness_nosleep(led_cdev, LED_FULL);
65 else
66 led_set_brightness_nosleep(led_cdev, LED_OFF);
68 return size;
71 static ssize_t led_delay_on_show(struct device *dev,
72 struct device_attribute *attr, char *buf)
74 struct led_classdev *led_cdev = led_trigger_get_led(dev);
76 return sprintf(buf, "%lu\n", led_cdev->blink_delay_on);
79 static ssize_t led_delay_on_store(struct device *dev,
80 struct device_attribute *attr, const char *buf, size_t size)
82 struct led_classdev *led_cdev = led_trigger_get_led(dev);
83 unsigned long state;
84 int ret;
86 ret = kstrtoul(buf, 0, &state);
87 if (ret)
88 return ret;
90 led_cdev->blink_delay_on = state;
92 return size;
95 static ssize_t led_delay_off_show(struct device *dev,
96 struct device_attribute *attr, char *buf)
98 struct led_classdev *led_cdev = led_trigger_get_led(dev);
100 return sprintf(buf, "%lu\n", led_cdev->blink_delay_off);
103 static ssize_t led_delay_off_store(struct device *dev,
104 struct device_attribute *attr, const char *buf, size_t size)
106 struct led_classdev *led_cdev = led_trigger_get_led(dev);
107 unsigned long state;
108 int ret;
110 ret = kstrtoul(buf, 0, &state);
111 if (ret)
112 return ret;
114 led_cdev->blink_delay_off = state;
116 return size;
119 static DEVICE_ATTR(delay_on, 0644, led_delay_on_show, led_delay_on_store);
120 static DEVICE_ATTR(delay_off, 0644, led_delay_off_show, led_delay_off_store);
121 static DEVICE_ATTR(invert, 0644, led_invert_show, led_invert_store);
122 static DEVICE_ATTR(shot, 0200, NULL, led_shot);
124 static struct attribute *oneshot_trig_attrs[] = {
125 &dev_attr_delay_on.attr,
126 &dev_attr_delay_off.attr,
127 &dev_attr_invert.attr,
128 &dev_attr_shot.attr,
129 NULL
131 ATTRIBUTE_GROUPS(oneshot_trig);
133 static int oneshot_trig_activate(struct led_classdev *led_cdev)
135 struct oneshot_trig_data *oneshot_data;
137 oneshot_data = kzalloc(sizeof(*oneshot_data), GFP_KERNEL);
138 if (!oneshot_data)
139 return -ENOMEM;
141 led_set_trigger_data(led_cdev, oneshot_data);
143 led_cdev->blink_delay_on = DEFAULT_DELAY;
144 led_cdev->blink_delay_off = DEFAULT_DELAY;
146 return 0;
149 static void oneshot_trig_deactivate(struct led_classdev *led_cdev)
151 struct oneshot_trig_data *oneshot_data = led_get_trigger_data(led_cdev);
153 kfree(oneshot_data);
155 /* Stop blinking */
156 led_set_brightness(led_cdev, LED_OFF);
159 static struct led_trigger oneshot_led_trigger = {
160 .name = "oneshot",
161 .activate = oneshot_trig_activate,
162 .deactivate = oneshot_trig_deactivate,
163 .groups = oneshot_trig_groups,
165 module_led_trigger(oneshot_led_trigger);
167 MODULE_AUTHOR("Fabio Baltieri <fabio.baltieri@gmail.com>");
168 MODULE_DESCRIPTION("One-shot LED trigger");
169 MODULE_LICENSE("GPL v2");