ar71xx: WNR1000v2: enable control of all LEDs and buttons
[openwrt.git] / target / linux / ar71xx / files / arch / mips / ath79 / mach-tl-wax50re.c
1 /*
2  *  TP-LINK TL-WA750RE v1/TL-WA801ND v2/TL-WA850RE v1/TL-WA901ND v3
3  *  board support
4  *
5  *  Copyright (C) 2013 Martijn Zilverschoon <thefriedzombie@gmail.com>
6  *  Copyright (C) 2013 Jiri Pirko <jiri@resnulli.us>
7  *
8  *  This program is free software; you can redistribute it and/or modify it
9  *  under the terms of the GNU General Public License version 2 as published
10  *  by the Free Software Foundation.
11  */
12
13 #include <linux/gpio.h>
14 #include <linux/platform_device.h>
15
16 #include <asm/mach-ath79/ath79.h>
17 #include <asm/mach-ath79/ar71xx_regs.h>
18
19 #include "common.h"
20 #include "dev-eth.h"
21 #include "dev-gpio-buttons.h"
22 #include "dev-leds-gpio.h"
23 #include "dev-m25p80.h"
24 #include "dev-wmac.h"
25 #include "machtypes.h"
26
27 #define TL_WAX50RE_GPIO_LED_LAN         20
28 #define TL_WAX50RE_GPIO_LED_WLAN        13
29 #define TL_WAX50RE_GPIO_LED_RE          15
30 #define TL_WAX50RE_GPIO_LED_SIGNAL1     0
31 #define TL_WAX50RE_GPIO_LED_SIGNAL2     1
32 #define TL_WAX50RE_GPIO_LED_SIGNAL3     2
33 #define TL_WAX50RE_GPIO_LED_SIGNAL4     3
34 #define TL_WAX50RE_GPIO_LED_SIGNAL5     4
35
36 #define TL_WA860RE_GPIO_LED_WLAN_ORANGE 0
37 #define TL_WA860RE_GPIO_LED_WLAN_GREEN  2
38 #define TL_WA860RE_GPIO_LED_POWER_ORANGE        12
39 #define TL_WA860RE_GPIO_LED_POWER_GREEN 14
40 #define TL_WA860RE_GPIO_LED_LAN         20
41
42 #define TL_WA801ND_V2_GPIO_LED_LAN      18
43 #define TL_WA801ND_V2_GPIO_LED_SYSTEM   14
44
45 #define TL_WAX50RE_GPIO_BTN_RESET       17
46 #define TL_WAX50RE_GPIO_BTN_WPS         16
47
48 #define TL_WA860RE_GPIO_BTN_RESET       17
49 #define TL_WA860RE_GPIO_BTN_WPS         16
50 #define TL_WA860RE_GPIO_BTN_ONOFF       11
51
52 #define TL_WAX50RE_KEYS_POLL_INTERVAL   20      /* msecs */
53 #define TL_WAX50RE_KEYS_DEBOUNCE_INTERVAL (3 * TL_WAX50RE_KEYS_POLL_INTERVAL)
54
55 static const char *tl_wax50re_part_probes[] = {
56         "tp-link",
57         NULL,
58 };
59
60 static struct flash_platform_data tl_wax50re_flash_data = {
61         .part_probes    = tl_wax50re_part_probes,
62 };
63
64 static struct gpio_led tl_wa750re_leds_gpio[] __initdata = {
65         {
66                 .name           = "tp-link:orange:lan",
67                 .gpio           = TL_WAX50RE_GPIO_LED_LAN,
68                 .active_low     = 1,
69         }, {
70                 .name           = "tp-link:orange:wlan",
71                 .gpio           = TL_WAX50RE_GPIO_LED_WLAN,
72                 .active_low     = 1,
73         }, {
74                 .name           = "tp-link:orange:re",
75                 .gpio           = TL_WAX50RE_GPIO_LED_RE,
76                 .active_low     = 1,
77         }, {
78                 .name           = "tp-link:orange:signal1",
79                 .gpio           = TL_WAX50RE_GPIO_LED_SIGNAL1,
80                 .active_low     = 1,
81         }, {
82                 .name           = "tp-link:orange:signal2",
83                 .gpio           = TL_WAX50RE_GPIO_LED_SIGNAL2,
84                 .active_low     = 1,
85         }, {
86                 .name           = "tp-link:orange:signal3",
87                 .gpio           = TL_WAX50RE_GPIO_LED_SIGNAL3,
88                 .active_low     = 1,
89         }, {
90                 .name           = "tp-link:orange:signal4",
91                 .gpio           = TL_WAX50RE_GPIO_LED_SIGNAL4,
92                 .active_low     = 1,
93         }, {
94                 .name           = "tp-link:orange:signal5",
95                 .gpio           = TL_WAX50RE_GPIO_LED_SIGNAL5,
96                 .active_low     = 1,
97         },
98 };
99
100 static struct gpio_led tl_wa850re_leds_gpio[] __initdata = {
101         {
102                 .name           = "tp-link:blue:lan",
103                 .gpio           = TL_WAX50RE_GPIO_LED_LAN,
104                 .active_low     = 1,
105         }, {
106                 .name           = "tp-link:blue:wlan",
107                 .gpio           = TL_WAX50RE_GPIO_LED_WLAN,
108                 .active_low     = 1,
109         }, {
110                 .name           = "tp-link:blue:re",
111                 .gpio           = TL_WAX50RE_GPIO_LED_RE,
112                 .active_low     = 1,
113         }, {
114                 .name           = "tp-link:blue:signal1",
115                 .gpio           = TL_WAX50RE_GPIO_LED_SIGNAL1,
116                 .active_low     = 1,
117         }, {
118                 .name           = "tp-link:blue:signal2",
119                 .gpio           = TL_WAX50RE_GPIO_LED_SIGNAL2,
120                 .active_low     = 1,
121         }, {
122                 .name           = "tp-link:blue:signal3",
123                 .gpio           = TL_WAX50RE_GPIO_LED_SIGNAL3,
124                 .active_low     = 1,
125         }, {
126                 .name           = "tp-link:blue:signal4",
127                 .gpio           = TL_WAX50RE_GPIO_LED_SIGNAL4,
128                 .active_low     = 1,
129         }, {
130                 .name           = "tp-link:blue:signal5",
131                 .gpio           = TL_WAX50RE_GPIO_LED_SIGNAL5,
132                 .active_low     = 1,
133         },
134 };
135
136 static struct gpio_led tl_wa860re_leds_gpio[] __initdata = {
137         {
138                 .name           = "tp-link:green:lan",
139                 .gpio           = TL_WA860RE_GPIO_LED_LAN,
140                 .active_low     = 1,
141         }, {
142                 .name           = "tp-link:green:power",
143                 .gpio           = TL_WA860RE_GPIO_LED_POWER_GREEN,
144                 .active_low     = 1,
145         }, {
146                 .name           = "tp-link:orange:power",
147                 .gpio           = TL_WA860RE_GPIO_LED_POWER_ORANGE,
148                 .active_low     = 1,
149         }, {
150                 .name           = "tp-link:green:wlan",
151                 .gpio           = TL_WA860RE_GPIO_LED_WLAN_GREEN,
152                 .active_low     = 1,
153         }, {
154                 .name           = "tp-link:orange:wlan",
155                 .gpio           = TL_WA860RE_GPIO_LED_WLAN_ORANGE,
156                 .active_low     = 1,
157         },
158 };
159
160
161 static struct gpio_keys_button tl_wax50re_gpio_keys[] __initdata = {
162         {
163                 .desc              = "Reset button",
164                 .type              = EV_KEY,
165                 .code              = KEY_RESTART,
166                 .debounce_interval = TL_WAX50RE_KEYS_DEBOUNCE_INTERVAL,
167                 .gpio              = TL_WAX50RE_GPIO_BTN_RESET,
168                 .active_low        = 1,
169         }, {
170                 .desc              = "WPS",
171                 .type              = EV_KEY,
172                 .code              = KEY_WPS_BUTTON,
173                 .debounce_interval = TL_WAX50RE_KEYS_DEBOUNCE_INTERVAL,
174                 .gpio              = TL_WAX50RE_GPIO_BTN_WPS,
175                 .active_low        = 1,
176         },
177 };
178
179 static struct gpio_keys_button tl_wa860re_gpio_keys[] __initdata = {
180         {
181                 .desc              = "Reset button",
182                 .type              = EV_KEY,
183                 .code              = KEY_RESTART,
184                 .debounce_interval = TL_WAX50RE_KEYS_DEBOUNCE_INTERVAL,
185                 .gpio              = TL_WA860RE_GPIO_BTN_RESET,
186                 .active_low        = 1,
187         }, {
188                 .desc              = "WPS",
189                 .type              = EV_KEY,
190                 .code              = KEY_WPS_BUTTON,
191                 .debounce_interval = TL_WAX50RE_KEYS_DEBOUNCE_INTERVAL,
192                 .gpio              = TL_WA860RE_GPIO_BTN_WPS,
193                 .active_low        = 1,
194         }, {
195                 .desc              = "ONOFF",
196                 .type              = EV_KEY,
197                 .code              = BTN_1,
198                 .debounce_interval = TL_WAX50RE_KEYS_DEBOUNCE_INTERVAL,
199                 .gpio              = TL_WA860RE_GPIO_BTN_ONOFF,
200                 .active_low        = 1,
201         },
202 };
203
204 static struct gpio_led tl_wa801nd_v2_leds_gpio[] __initdata = {
205         {
206                 .name           = "tp-link:green:lan",
207                 .gpio           = TL_WA801ND_V2_GPIO_LED_LAN,
208                 .active_low     = 1,
209         }, {
210                 .name           = "tp-link:green:wlan",
211                 .gpio           = TL_WAX50RE_GPIO_LED_WLAN,
212                 .active_low     = 1,
213         }, {
214                 .name           = "tp-link:green:qss",
215                 .gpio           = TL_WAX50RE_GPIO_LED_RE,
216                 .active_low     = 1,
217         }, {
218                 .name           = "tp-link:green:system",
219                 .gpio           = TL_WA801ND_V2_GPIO_LED_SYSTEM,
220                 .active_low     = 1,
221         },
222 };
223
224 static void __init tl_ap123_setup(void)
225 {
226         u8 *mac = (u8 *) KSEG1ADDR(0x1f01fc00);
227         u8 *ee = (u8 *) KSEG1ADDR(0x1fff1000);
228
229         ath79_register_m25p80(&tl_wax50re_flash_data);
230
231         ath79_setup_ar934x_eth_cfg(AR934X_ETH_CFG_SW_PHY_SWAP);
232
233         ath79_register_mdio(1, 0x0);
234
235         ath79_init_mac(ath79_eth0_data.mac_addr, mac, 0);
236
237         ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
238         ath79_eth0_data.phy_mask = BIT(0);
239         ath79_eth0_data.mii_bus_dev = &ath79_mdio1_device.dev;
240         ath79_register_eth(0);
241
242         ath79_register_wmac(ee, mac);
243 }
244
245 static void  __init tl_wa750re_setup(void)
246 {
247         tl_ap123_setup();
248         ath79_register_leds_gpio(-1, ARRAY_SIZE(tl_wa750re_leds_gpio),
249                                  tl_wa750re_leds_gpio);
250
251         ath79_register_gpio_keys_polled(-1, TL_WAX50RE_KEYS_POLL_INTERVAL,
252                                         ARRAY_SIZE(tl_wax50re_gpio_keys),
253                                         tl_wax50re_gpio_keys);
254 }
255
256 MIPS_MACHINE(ATH79_MACH_TL_WA750RE, "TL-WA750RE", "TP-LINK TL-WA750RE",
257              tl_wa750re_setup);
258
259 static void __init tl_wa801nd_v2_setup(void)
260 {
261         tl_ap123_setup();
262         ath79_register_leds_gpio(-1, ARRAY_SIZE(tl_wa801nd_v2_leds_gpio),
263                         tl_wa801nd_v2_leds_gpio);
264
265         ath79_register_gpio_keys_polled(-1, TL_WAX50RE_KEYS_POLL_INTERVAL,
266                                         ARRAY_SIZE(tl_wax50re_gpio_keys),
267                                         tl_wax50re_gpio_keys);
268 }
269
270 MIPS_MACHINE(ATH79_MACH_TL_WA801ND_V2, "TL-WA801ND-v2", "TP-LINK TL-WA801ND v2",
271              tl_wa801nd_v2_setup);
272
273 static void  __init tl_wa850re_setup(void)
274 {
275         tl_ap123_setup();
276         ath79_register_leds_gpio(-1, ARRAY_SIZE(tl_wa850re_leds_gpio),
277                                  tl_wa850re_leds_gpio);
278
279         ath79_register_gpio_keys_polled(-1, TL_WAX50RE_KEYS_POLL_INTERVAL,
280                                         ARRAY_SIZE(tl_wax50re_gpio_keys),
281                                         tl_wax50re_gpio_keys);
282 }
283
284 MIPS_MACHINE(ATH79_MACH_TL_WA850RE, "TL-WA850RE", "TP-LINK TL-WA850RE",
285              tl_wa850re_setup);
286
287 static void  __init tl_wa860re_setup(void)
288 {
289         tl_ap123_setup();
290         ath79_register_leds_gpio(-1, ARRAY_SIZE(tl_wa860re_leds_gpio),
291                                  tl_wa860re_leds_gpio);
292
293         ath79_register_gpio_keys_polled(-1, TL_WAX50RE_KEYS_POLL_INTERVAL,
294                                         ARRAY_SIZE(tl_wa860re_gpio_keys),
295                                         tl_wa860re_gpio_keys);
296 }
297
298 MIPS_MACHINE(ATH79_MACH_TL_WA860RE, "TL-WA860RE", "TP-LINK TL-WA860RE",
299              tl_wa860re_setup);
300
301 static void __init tl_wa901nd_v3_setup(void)
302 {
303         tl_ap123_setup();
304         ath79_register_leds_gpio(-1, ARRAY_SIZE(tl_wa801nd_v2_leds_gpio),
305                         tl_wa801nd_v2_leds_gpio);
306
307         ath79_register_gpio_keys_polled(-1, TL_WAX50RE_KEYS_POLL_INTERVAL,
308                                         ARRAY_SIZE(tl_wax50re_gpio_keys) - 1,
309                                         tl_wax50re_gpio_keys);
310 }
311
312 MIPS_MACHINE(ATH79_MACH_TL_WA901ND_V3, "TL-WA901ND-v3", "TP-LINK TL-WA901ND v3",
313              tl_wa901nd_v3_setup);