12 #include <linux/module.h>
13 #include <linux/kernel.h>
19 #include <linux/slab.h>
31 static irqreturn_t gpio_trig_irq(
int irq,
void *_led)
57 __led_set_brightness(gpio_data->
led,
83 ret =
sscanf(buf,
"%u", &desired_brightness);
84 if (ret < 1 || desired_brightness > 255) {
85 dev_err(dev,
"invalid value\n");
93 static DEVICE_ATTR(desired_brightness, 0644, gpio_trig_brightness_show,
94 gpio_trig_brightness_store);
127 static DEVICE_ATTR(inverted, 0644, gpio_trig_inverted_show,
128 gpio_trig_inverted_store);
147 ret =
sscanf(buf,
"%u", &gpio);
149 dev_err(dev,
"couldn't read gpio number\n");
154 if (gpio_data->
gpio == gpio)
158 if (gpio_data->
gpio != 0)
168 dev_err(dev,
"request_irq failed with error %d\n", ret);
170 if (gpio_data->
gpio != 0)
175 return ret ? ret :
n;
177 static DEVICE_ATTR(gpio, 0644, gpio_trig_gpio_show, gpio_trig_gpio_store);
179 static void gpio_trig_activate(
struct led_classdev *led)
184 gpio_data = kzalloc(
sizeof(*gpio_data),
GFP_KERNEL);
201 led->trigger_data = gpio_data;
203 led->activated =
true;
217 static void gpio_trig_deactivate(
struct led_classdev *led)
221 if (led->activated) {
226 if (gpio_data->
gpio != 0)
229 led->activated =
false;
233 static struct led_trigger gpio_led_trigger = {
235 .activate = gpio_trig_activate,
236 .deactivate = gpio_trig_deactivate,
239 static int __init gpio_trig_init(
void)
245 static void __exit gpio_trig_exit(
void)