brcm2708: update 4.1 patches
[openwrt/openwrt.git] / target / linux / brcm2708 / patches-4.1 / 0053-BCM270x_DT-Add-pwr_led-and-the-required-input-trigge.patch
1 From ade319d70297e1258ae65ff733ae56b6ad51ec96 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/171] BCM270x_DT: Add pwr_led, and the required "input"
5 trigger
6
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.
9
10 N.B. pwr_led is not available on Model A or B boards.
11 ---
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
17
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.
23
24 +config LEDS_TRIGGER_INPUT
25 + tristate "LED Input Trigger"
26 + depends on LEDS_TRIGGERS
27 + help
28 + This allows the GPIOs assigned to be LEDs to be initialised to inputs.
29 + If unsure, say Y.
30 +
31 endif # LEDS_TRIGGERS
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
39 --- /dev/null
40 +++ b/drivers/leds/trigger/ledtrig-input.c
41 @@ -0,0 +1,65 @@
42 +/*
43 + * Set LED GPIO to Input "Trigger"
44 + *
45 + * Copyright 2015 Phil Elwell <phil@raspberrypi.org>
46 + *
47 + * Based on Nick Forbes's ledtrig-default-on.c.
48 + *
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.
52 + *
53 + */
54 +
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>
60 +#include "../leds.h"
61 +
62 +/* This is a hack to get at the private 'gpio' member */
63 +
64 +struct gpio_led_data {
65 + struct led_classdev cdev;
66 + unsigned gpio;
67 +};
68 +
69 +static void input_trig_activate(struct led_classdev *led_cdev)
70 +{
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);
75 +}
76 +
77 +static void input_trig_deactivate(struct led_classdev *led_cdev)
78 +{
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);
83 +}
84 +
85 +static struct led_trigger input_led_trigger = {
86 + .name = "input",
87 + .activate = input_trig_activate,
88 + .deactivate = input_trig_deactivate,
89 +};
90 +
91 +static int __init input_trig_init(void)
92 +{
93 + return led_trigger_register(&input_led_trigger);
94 +}
95 +
96 +static void __exit input_trig_exit(void)
97 +{
98 + led_trigger_unregister(&input_led_trigger);
99 +}
100 +
101 +module_init(input_trig_init);
102 +module_exit(input_trig_exit);
103 +
104 +MODULE_AUTHOR("Phil Elwell <phil@raspberrypi.org>");
105 +MODULE_DESCRIPTION("Set LED GPIO to Input \"trigger\"");
106 +MODULE_LICENSE("GPL");