1 From 04d0b82167574e134b822d80fd66b652ced46efd Mon Sep 17 00:00:00 2001
2 From: Phil Elwell <phil@raspberrypi.org>
3 Date: Fri, 6 Feb 2015 13:50:57 +0000
4 Subject: [PATCH 053/222] BCM270x_DT: Add pwr_led, and the required "input"
7 The "input" trigger makes the associated GPIO an input. This is to support
8 the Raspberry Pi PWR LED, which is driven by external hardware in normal use.
10 N.B. pwr_led is not available on Model A or B boards.
12 drivers/leds/trigger/Kconfig | 7 ++++
13 drivers/leds/trigger/Makefile | 1 +
14 drivers/leds/trigger/ledtrig-input.c | 65 ++++++++++++++++++++++++++++++++++++
15 3 files changed, 73 insertions(+)
16 create mode 100644 drivers/leds/trigger/ledtrig-input.c
18 --- a/drivers/leds/trigger/Kconfig
19 +++ b/drivers/leds/trigger/Kconfig
20 @@ -126,4 +126,11 @@ config LEDS_TRIGGER_USBDEV
21 This allows LEDs to be controlled by the presence/activity of
22 an USB device. If unsure, say N.
24 +config LEDS_TRIGGER_INPUT
25 + tristate "LED Input Trigger"
26 + depends on LEDS_TRIGGERS
28 + This allows the GPIOs assigned to be LEDs to be initialised to inputs.
32 --- a/drivers/leds/trigger/Makefile
33 +++ b/drivers/leds/trigger/Makefile
34 @@ -8,3 +8,4 @@ obj-$(CONFIG_LEDS_TRIGGER_CPU) += ledtr
35 obj-$(CONFIG_LEDS_TRIGGER_DEFAULT_ON) += ledtrig-default-on.o
36 obj-$(CONFIG_LEDS_TRIGGER_TRANSIENT) += ledtrig-transient.o
37 obj-$(CONFIG_LEDS_TRIGGER_CAMERA) += ledtrig-camera.o
38 +obj-$(CONFIG_LEDS_TRIGGER_INPUT) += ledtrig-input.o
40 +++ b/drivers/leds/trigger/ledtrig-input.c
43 + * Set LED GPIO to Input "Trigger"
45 + * Copyright 2015 Phil Elwell <phil@raspberrypi.org>
47 + * Based on Nick Forbes's ledtrig-default-on.c.
49 + * This program is free software; you can redistribute it and/or modify
50 + * it under the terms of the GNU General Public License version 2 as
51 + * published by the Free Software Foundation.
55 +#include <linux/module.h>
56 +#include <linux/kernel.h>
57 +#include <linux/init.h>
58 +#include <linux/leds.h>
59 +#include <linux/gpio.h>
62 +/* This is a hack to get at the private 'gpio' member */
64 +struct gpio_led_data {
65 + struct led_classdev cdev;
69 +static void input_trig_activate(struct led_classdev *led_cdev)
71 + struct gpio_led_data *led_dat =
72 + container_of(led_cdev, struct gpio_led_data, cdev);
73 + if (gpio_is_valid(led_dat->gpio))
74 + gpio_direction_input(led_dat->gpio);
77 +static void input_trig_deactivate(struct led_classdev *led_cdev)
79 + struct gpio_led_data *led_dat =
80 + container_of(led_cdev, struct gpio_led_data, cdev);
81 + if (gpio_is_valid(led_dat->gpio))
82 + gpio_direction_output(led_dat->gpio, 0);
85 +static struct led_trigger input_led_trigger = {
87 + .activate = input_trig_activate,
88 + .deactivate = input_trig_deactivate,
91 +static int __init input_trig_init(void)
93 + return led_trigger_register(&input_led_trigger);
96 +static void __exit input_trig_exit(void)
98 + led_trigger_unregister(&input_led_trigger);
101 +module_init(input_trig_init);
102 +module_exit(input_trig_exit);
104 +MODULE_AUTHOR("Phil Elwell <phil@raspberrypi.org>");
105 +MODULE_DESCRIPTION("Set LED GPIO to Input \"trigger\"");
106 +MODULE_LICENSE("GPL");