brcm47xx: add new led and button support
[openwrt.git] / target / linux / brcm47xx / patches-3.10 / 120-MIPS-BCM47XX-Prepare-support-for-LEDs.patch
1 From 98e54a60a7346ef31cb851b670a238ad428b58fe Mon Sep 17 00:00:00 2001
2 From: Rafa? Mi?ecki <zajec5@gmail.com>
3 Date: Thu, 2 Jan 2014 13:27:15 +0100
4 Subject: [PATCH 029/110] MIPS: BCM47XX: Prepare support for LEDs
5
6 So far this is mostly just a proof of concept, database consists of a
7 single device. Creating a nice iterateable array wasn't an option
8 because devices have different amount of LEDs. And we don't want to
9 waste memory just because of support for a device with dozens on LEDs.
10
11 Signed-off-by: Rafa? Mi?ecki <zajec5@gmail.com>
12 Acked-by: Hauke Mehrtens <hauke@hauke-m.de>
13 Acked-by: John Crispin <blogic@openwrt.org>
14 Patchwork: http://patchwork.linux-mips.org/patch/6299/
15 ---
16  arch/mips/bcm47xx/Kconfig           |    2 +
17  arch/mips/bcm47xx/Makefile          |    2 +-
18  arch/mips/bcm47xx/bcm47xx_private.h |    9 +++++
19  arch/mips/bcm47xx/leds.c            |   73 +++++++++++++++++++++++++++++++++++
20  arch/mips/bcm47xx/setup.c           |    6 +++
21  5 files changed, 91 insertions(+), 1 deletion(-)
22  create mode 100644 arch/mips/bcm47xx/bcm47xx_private.h
23  create mode 100644 arch/mips/bcm47xx/leds.c
24
25 --- a/arch/mips/bcm47xx/Kconfig
26 +++ b/arch/mips/bcm47xx/Kconfig
27 @@ -12,6 +12,7 @@ config BCM47XX_SSB
28         select SSB_PCICORE_HOSTMODE if PCI
29         select SSB_DRIVER_GPIO
30         select GPIOLIB
31 +       select LEDS_GPIO_REGISTER
32         default y
33         help
34          Add support for old Broadcom BCM47xx boards with Sonics Silicon Backplane support.
35 @@ -29,6 +30,7 @@ config BCM47XX_BCMA
36         select BCMA_DRIVER_PCI_HOSTMODE if PCI
37         select BCMA_DRIVER_GPIO
38         select GPIOLIB
39 +       select LEDS_GPIO_REGISTER
40         default y
41         help
42          Add support for new Broadcom BCM47xx boards with Broadcom specific Advanced Microcontroller Bus.
43 --- a/arch/mips/bcm47xx/Makefile
44 +++ b/arch/mips/bcm47xx/Makefile
45 @@ -4,5 +4,5 @@
46  #
47  
48  obj-y                          += irq.o nvram.o prom.o serial.o setup.o time.o sprom.o
49 -obj-y                          += board.o
50 +obj-y                          += board.o leds.o
51  obj-$(CONFIG_BCM47XX_SSB)      += wgt634u.o
52 --- /dev/null
53 +++ b/arch/mips/bcm47xx/bcm47xx_private.h
54 @@ -0,0 +1,9 @@
55 +#ifndef LINUX_BCM47XX_PRIVATE_H_
56 +#define LINUX_BCM47XX_PRIVATE_H_
57 +
58 +#include <linux/kernel.h>
59 +
60 +/* leds.c */
61 +void __init bcm47xx_leds_register(void);
62 +
63 +#endif
64 --- /dev/null
65 +++ b/arch/mips/bcm47xx/leds.c
66 @@ -0,0 +1,73 @@
67 +#include "bcm47xx_private.h"
68 +
69 +#include <linux/leds.h>
70 +#include <bcm47xx_board.h>
71 +
72 +static const struct gpio_led
73 +bcm47xx_leds_netgear_wndr4500_v1_leds[] __initconst = {
74 +       {
75 +               .name           = "bcm47xx:green:wps",
76 +               .gpio           = 1,
77 +               .active_low     = 1,
78 +               .default_state  = LEDS_GPIO_DEFSTATE_KEEP,
79 +       },
80 +       {
81 +               .name           = "bcm47xx:green:power",
82 +               .gpio           = 2,
83 +               .active_low     = 1,
84 +               .default_state  = LEDS_GPIO_DEFSTATE_KEEP,
85 +       },
86 +       {
87 +               .name           = "bcm47xx:orange:power",
88 +               .gpio           = 3,
89 +               .active_low     = 1,
90 +               .default_state  = LEDS_GPIO_DEFSTATE_KEEP,
91 +       },
92 +       {
93 +               .name           = "bcm47xx:green:usb1",
94 +               .gpio           = 8,
95 +               .active_low     = 1,
96 +               .default_state  = LEDS_GPIO_DEFSTATE_KEEP,
97 +       },
98 +       {
99 +               .name           = "bcm47xx:green:2ghz",
100 +               .gpio           = 9,
101 +               .active_low     = 1,
102 +               .default_state  = LEDS_GPIO_DEFSTATE_KEEP,
103 +       },
104 +       {
105 +               .name           = "bcm47xx:blue:5ghz",
106 +               .gpio           = 11,
107 +               .active_low     = 1,
108 +               .default_state  = LEDS_GPIO_DEFSTATE_KEEP,
109 +       },
110 +       {
111 +               .name           = "bcm47xx:green:usb2",
112 +               .gpio           = 14,
113 +               .active_low     = 1,
114 +               .default_state  = LEDS_GPIO_DEFSTATE_KEEP,
115 +       },
116 +};
117 +
118 +static struct gpio_led_platform_data bcm47xx_leds_pdata;
119 +
120 +#define bcm47xx_set_pdata(dev_leds) do {                               \
121 +       bcm47xx_leds_pdata.leds = dev_leds;                             \
122 +       bcm47xx_leds_pdata.num_leds = ARRAY_SIZE(dev_leds);             \
123 +} while (0)
124 +
125 +void __init bcm47xx_leds_register(void)
126 +{
127 +       enum bcm47xx_board board = bcm47xx_board_get();
128 +
129 +       switch (board) {
130 +       case BCM47XX_BOARD_NETGEAR_WNDR4500V1:
131 +               bcm47xx_set_pdata(bcm47xx_leds_netgear_wndr4500_v1_leds);
132 +               break;
133 +       default:
134 +               pr_debug("No LEDs configuration found for this device\n");
135 +               return;
136 +       }
137 +
138 +       gpio_led_register_device(-1, &bcm47xx_leds_pdata);
139 +}
140 --- a/arch/mips/bcm47xx/setup.c
141 +++ b/arch/mips/bcm47xx/setup.c
142 @@ -26,6 +26,8 @@
143   *  675 Mass Ave, Cambridge, MA 02139, USA.
144   */
145  
146 +#include "bcm47xx_private.h"
147 +
148  #include <linux/export.h>
149  #include <linux/types.h>
150  #include <linux/ssb/ssb.h>
151 @@ -243,6 +245,9 @@ static int __init bcm47xx_register_bus_c
152                 break;
153  #endif
154         }
155 +
156 +       bcm47xx_leds_register();
157 +
158         return 0;
159  }
160  device_initcall(bcm47xx_register_bus_complete);