0110-BCM270x_DT-Add-pwr_led-and-the-required-input-trigge.patch 6.4 KB

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