1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
|
From 5f1c4a04606c2fb2d0203bdbe364a6054b3bb0b7 Mon Sep 17 00:00:00 2001
From: Phil Elwell <phil@raspberrypi.org>
Date: Fri, 6 Feb 2015 13:50:57 +0000
Subject: [PATCH 110/114] BCM270x_DT: Add pwr_led, and the required "input"
trigger
The "input" trigger makes the associated GPIO an input. This is to support
the Raspberry Pi PWR LED, which is driven by external hardware in normal use.
N.B. pwr_led is not available on Model A or B boards.
---
arch/arm/boot/dts/bcm2708-rpi-b-plus.dts | 18 ++++++++-
arch/arm/boot/dts/bcm2708-rpi-b.dts | 8 +++-
arch/arm/boot/dts/bcm2708.dtsi | 5 ---
arch/arm/boot/dts/bcm2709-rpi-2-b.dts | 18 ++++++++-
arch/arm/boot/dts/bcm2709.dtsi | 5 ---
arch/arm/configs/bcm2709_defconfig | 1 +
arch/arm/configs/bcmrpi_defconfig | 1 +
drivers/leds/trigger/Kconfig | 7 ++++
drivers/leds/trigger/Makefile | 1 +
drivers/leds/trigger/ledtrig-input.c | 65 ++++++++++++++++++++++++++++++++
10 files changed, 113 insertions(+), 16 deletions(-)
create mode 100644 drivers/leds/trigger/ledtrig-input.c
--- a/arch/arm/boot/dts/bcm2708-rpi-b-plus.dts
+++ b/arch/arm/boot/dts/bcm2708-rpi-b-plus.dts
@@ -83,8 +83,18 @@
pinctrl-0 = <&i2s_pins>;
};
-&act_led {
- gpios = <&gpio 47 0>;
+&leds {
+ act_led: act {
+ label = "led0";
+ linux,default-trigger = "mmc0";
+ gpios = <&gpio 47 0>;
+ };
+
+ pwr_led: pwr {
+ label = "led1";
+ linux,default-trigger = "input";
+ gpios = <&gpio 35 0>;
+ };
};
/ {
@@ -99,5 +109,9 @@
act_led_gpio = <&act_led>,"gpios:4";
act_led_activelow = <&act_led>,"gpios:8";
act_led_trigger = <&act_led>,"linux,default-trigger";
+
+ pwr_led_gpio = <&pwr_led>,"gpios:4";
+ pwr_led_activelow = <&pwr_led>,"gpios:8";
+ pwr_led_trigger = <&pwr_led>,"linux,default-trigger";
};
};
--- a/arch/arm/boot/dts/bcm2708-rpi-b.dts
+++ b/arch/arm/boot/dts/bcm2708-rpi-b.dts
@@ -83,8 +83,12 @@
pinctrl-0 = <&i2s_pins>;
};
-&act_led {
- gpios = <&gpio 16 1>;
+&leds {
+ act_led: act {
+ label = "led0";
+ linux,default-trigger = "mmc0";
+ gpios = <&gpio 16 1>;
+ };
};
/ {
--- a/arch/arm/boot/dts/bcm2708.dtsi
+++ b/arch/arm/boot/dts/bcm2708.dtsi
@@ -79,11 +79,6 @@
leds: leds {
compatible = "gpio-leds";
-
- act_led: act {
- label = "led0";
- linux,default-trigger = "mmc0";
- };
};
};
--- a/arch/arm/boot/dts/bcm2709-rpi-2-b.dts
+++ b/arch/arm/boot/dts/bcm2709-rpi-2-b.dts
@@ -83,8 +83,18 @@
pinctrl-0 = <&i2s_pins>;
};
-&act_led {
- gpios = <&gpio 47 0>;
+&leds {
+ act_led: act {
+ label = "led0";
+ linux,default-trigger = "mmc0";
+ gpios = <&gpio 47 0>;
+ };
+
+ pwr_led: pwr {
+ label = "led1";
+ linux,default-trigger = "input";
+ gpios = <&gpio 35 0>;
+ };
};
/ {
@@ -99,5 +109,9 @@
act_led_gpio = <&act_led>,"gpios:4";
act_led_activelow = <&act_led>,"gpios:8";
act_led_trigger = <&act_led>,"linux,default-trigger";
+
+ pwr_led_gpio = <&pwr_led>,"gpios:4";
+ pwr_led_activelow = <&pwr_led>,"gpios:8";
+ pwr_led_trigger = <&pwr_led>,"linux,default-trigger";
};
};
--- a/arch/arm/boot/dts/bcm2709.dtsi
+++ b/arch/arm/boot/dts/bcm2709.dtsi
@@ -79,11 +79,6 @@
leds: leds {
compatible = "gpio-leds";
-
- act_led: act {
- label = "led0";
- linux,default-trigger = "mmc0";
- };
};
};
--- a/arch/arm/configs/bcm2709_defconfig
+++ b/arch/arm/configs/bcm2709_defconfig
@@ -959,6 +959,7 @@ CONFIG_LEDS_TRIGGER_GPIO=y
CONFIG_LEDS_TRIGGER_DEFAULT_ON=y
CONFIG_LEDS_TRIGGER_TRANSIENT=m
CONFIG_LEDS_TRIGGER_CAMERA=m
+CONFIG_LEDS_TRIGGER_INPUT=y
CONFIG_RTC_CLASS=y
# CONFIG_RTC_HCTOSYS is not set
CONFIG_RTC_DRV_DS1307=m
--- a/arch/arm/configs/bcmrpi_defconfig
+++ b/arch/arm/configs/bcmrpi_defconfig
@@ -952,6 +952,7 @@ CONFIG_LEDS_TRIGGER_GPIO=y
CONFIG_LEDS_TRIGGER_DEFAULT_ON=y
CONFIG_LEDS_TRIGGER_TRANSIENT=m
CONFIG_LEDS_TRIGGER_CAMERA=m
+CONFIG_LEDS_TRIGGER_INPUT=y
CONFIG_RTC_CLASS=y
# CONFIG_RTC_HCTOSYS is not set
CONFIG_RTC_DRV_DS1307=m
--- a/drivers/leds/trigger/Kconfig
+++ b/drivers/leds/trigger/Kconfig
@@ -126,4 +126,11 @@ config LEDS_TRIGGER_USBDEV
This allows LEDs to be controlled by the presence/activity of
an USB device. If unsure, say N.
+config LEDS_TRIGGER_INPUT
+ tristate "LED Input Trigger"
+ depends on LEDS_TRIGGERS
+ help
+ This allows the GPIOs assigned to be LEDs to be initialised to inputs.
+ If unsure, say Y.
+
endif # LEDS_TRIGGERS
--- a/drivers/leds/trigger/Makefile
+++ b/drivers/leds/trigger/Makefile
@@ -8,3 +8,4 @@ obj-$(CONFIG_LEDS_TRIGGER_CPU) += ledtr
obj-$(CONFIG_LEDS_TRIGGER_DEFAULT_ON) += ledtrig-default-on.o
obj-$(CONFIG_LEDS_TRIGGER_TRANSIENT) += ledtrig-transient.o
obj-$(CONFIG_LEDS_TRIGGER_CAMERA) += ledtrig-camera.o
+obj-$(CONFIG_LEDS_TRIGGER_INPUT) += ledtrig-input.o
--- /dev/null
+++ b/drivers/leds/trigger/ledtrig-input.c
@@ -0,0 +1,65 @@
+/*
+ * Set LED GPIO to Input "Trigger"
+ *
+ * Copyright 2015 Phil Elwell <phil@raspberrypi.org>
+ *
+ * Based on Nick Forbes's ledtrig-default-on.c.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/leds.h>
+#include <linux/gpio.h>
+#include "../leds.h"
+
+/* This is a hack to get at the private 'gpio' member */
+
+struct gpio_led_data {
+ struct led_classdev cdev;
+ unsigned gpio;
+};
+
+static void input_trig_activate(struct led_classdev *led_cdev)
+{
+ struct gpio_led_data *led_dat =
+ container_of(led_cdev, struct gpio_led_data, cdev);
+ if (gpio_is_valid(led_dat->gpio))
+ gpio_direction_input(led_dat->gpio);
+}
+
+static void input_trig_deactivate(struct led_classdev *led_cdev)
+{
+ struct gpio_led_data *led_dat =
+ container_of(led_cdev, struct gpio_led_data, cdev);
+ if (gpio_is_valid(led_dat->gpio))
+ gpio_direction_output(led_dat->gpio, 0);
+}
+
+static struct led_trigger input_led_trigger = {
+ .name = "input",
+ .activate = input_trig_activate,
+ .deactivate = input_trig_deactivate,
+};
+
+static int __init input_trig_init(void)
+{
+ return led_trigger_register(&input_led_trigger);
+}
+
+static void __exit input_trig_exit(void)
+{
+ led_trigger_unregister(&input_led_trigger);
+}
+
+module_init(input_trig_init);
+module_exit(input_trig_exit);
+
+MODULE_AUTHOR("Phil Elwell <phil@raspberrypi.org>");
+MODULE_DESCRIPTION("Set LED GPIO to Input \"trigger\"");
+MODULE_LICENSE("GPL");
|