First git repo commit for the libreCMC project
[librecmc/librecmc.git] / target / linux / ar71xx / files / arch / mips / ath79 / mach-tl-wr841n-v9.c
1 /*
2  *  TP-LINK TL-WR841N/ND v9/v11 / TL-WR842N/ND v3
3  *
4  *  Copyright (C) 2014 Matthias Schiffer <mschiffer@universe-factory.net>
5  *  Copyright (C) 2016 Cezary Jackiewicz <cezary@eko.one.pl>
6  *  Copyright (C) 2016 Stijn Segers <francesco.borromini@gmail.com>
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-usb.h"
25 #include "dev-wmac.h"
26 #include "machtypes.h"
27
28 #define TL_WR841NV9_GPIO_LED_WLAN       13
29 #define TL_WR841NV9_GPIO_LED_QSS        3
30 #define TL_WR841NV9_GPIO_LED_WAN        4
31 #define TL_WR841NV9_GPIO_LED_LAN1       16
32 #define TL_WR841NV9_GPIO_LED_LAN2       15
33 #define TL_WR841NV9_GPIO_LED_LAN3       14
34 #define TL_WR841NV9_GPIO_LED_LAN4       11
35
36 #define TL_WR841NV9_GPIO_BTN_RESET      12
37 #define TL_WR841NV9_GPIO_BTN_WIFI       17
38
39 #define TL_WR841NV11_GPIO_LED_SYSTEM    1
40 #define TL_WR841NV11_GPIO_LED_QSS       3
41 #define TL_WR841NV11_GPIO_LED_WAN       4
42 #define TL_WR841NV11_GPIO_LED_WAN_STATUS        2
43 #define TL_WR841NV11_GPIO_LED_WLAN      13
44 #define TL_WR841NV11_GPIO_LED_LAN1      16
45 #define TL_WR841NV11_GPIO_LED_LAN2      15
46 #define TL_WR841NV11_GPIO_LED_LAN3      14
47 #define TL_WR841NV11_GPIO_LED_LAN4      11
48
49 #define TL_WR841NV11_GPIO_BTN_RESET     12
50 #define TL_WR841NV11_GPIO_BTN_WIFI      17
51
52 #define TL_WR842NV3_GPIO_LED_SYSTEM     2
53 #define TL_WR842NV3_GPIO_LED_WLAN       3
54 #define TL_WR842NV3_GPIO_LED_WAN_RED    4
55 #define TL_WR842NV3_GPIO_LED_WAN_GREEN  11
56 #define TL_WR842NV3_GPIO_LED_LAN1       12
57 #define TL_WR842NV3_GPIO_LED_LAN2       13
58 #define TL_WR842NV3_GPIO_LED_LAN3       14
59 #define TL_WR842NV3_GPIO_LED_LAN4       15
60 #define TL_WR842NV3_GPIO_LED_3G         16
61 #define TL_WR842NV3_GPIO_LED_WPS        17
62
63 #define TL_WR842NV3_GPIO_BTN_RESET      1
64 #define TL_WR842NV3_GPIO_BTN_WIFI       0
65
66 #define TL_WR841NV9_KEYS_POLL_INTERVAL  20      /* msecs */
67 #define TL_WR841NV9_KEYS_DEBOUNCE_INTERVAL (3 * TL_WR841NV9_KEYS_POLL_INTERVAL)
68
69 static const char *tl_wr841n_v9_part_probes[] = {
70         "tp-link",
71         NULL,
72 };
73
74 static struct flash_platform_data tl_wr841n_v9_flash_data = {
75         .part_probes    = tl_wr841n_v9_part_probes,
76 };
77
78 static struct gpio_led tl_wr841n_v9_leds_gpio[] __initdata = {
79         {
80                 .name           = "tp-link:green:lan1",
81                 .gpio           = TL_WR841NV9_GPIO_LED_LAN1,
82                 .active_low     = 1,
83         }, {
84                 .name           = "tp-link:green:lan2",
85                 .gpio           = TL_WR841NV9_GPIO_LED_LAN2,
86                 .active_low     = 1,
87         }, {
88                 .name           = "tp-link:green:lan3",
89                 .gpio           = TL_WR841NV9_GPIO_LED_LAN3,
90                 .active_low     = 1,
91         }, {
92                 .name           = "tp-link:green:lan4",
93                 .gpio           = TL_WR841NV9_GPIO_LED_LAN4,
94                 .active_low     = 1,
95         }, {
96                 .name           = "tp-link:green:qss",
97                 .gpio           = TL_WR841NV9_GPIO_LED_QSS,
98                 .active_low     = 1,
99         }, {
100                 .name           = "tp-link:green:wan",
101                 .gpio           = TL_WR841NV9_GPIO_LED_WAN,
102                 .active_low     = 1,
103         }, {
104                 .name           = "tp-link:green:wlan",
105                 .gpio           = TL_WR841NV9_GPIO_LED_WLAN,
106                 .active_low     = 1,
107         },
108 };
109
110 static struct gpio_keys_button tl_wr841n_v9_gpio_keys[] __initdata = {
111         {
112                 .desc           = "Reset button",
113                 .type           = EV_KEY,
114                 .code           = KEY_RESTART,
115                 .debounce_interval = TL_WR841NV9_KEYS_DEBOUNCE_INTERVAL,
116                 .gpio           = TL_WR841NV9_GPIO_BTN_RESET,
117                 .active_low     = 1,
118         }, {
119                 .desc           = "WIFI button",
120                 .type           = EV_KEY,
121                 .code           = KEY_RFKILL,
122                 .debounce_interval = TL_WR841NV9_KEYS_DEBOUNCE_INTERVAL,
123                 .gpio           = TL_WR841NV9_GPIO_BTN_WIFI,
124                 .active_low     = 1,
125         }
126 };
127
128 static struct gpio_led tl_wr841n_v11_leds_gpio[] __initdata = {
129         {
130                 .name           = "tp-link:green:lan1",
131                 .gpio           = TL_WR841NV9_GPIO_LED_LAN1,
132                 .active_low     = 1,
133         }, {
134                 .name           = "tp-link:green:lan2",
135                 .gpio           = TL_WR841NV9_GPIO_LED_LAN2,
136                 .active_low     = 1,
137         }, {
138                 .name           = "tp-link:green:lan3",
139                 .gpio           = TL_WR841NV9_GPIO_LED_LAN3,
140                 .active_low     = 1,
141         }, {
142                 .name           = "tp-link:green:lan4",
143                 .gpio           = TL_WR841NV9_GPIO_LED_LAN4,
144                 .active_low     = 1,
145         }, {
146                 .name           = "tp-link:green:qss",
147                 .gpio           = TL_WR841NV9_GPIO_LED_QSS,
148                 .active_low     = 1,
149         }, {
150                 .name           = "tp-link:green:system",
151                 .gpio           = TL_WR841NV11_GPIO_LED_SYSTEM,
152                 .active_low     = 1,
153         }, {
154                 .name           = "tp-link:green:wan",
155                 .gpio           = TL_WR841NV9_GPIO_LED_WAN,
156                 .active_low     = 1,
157         }, {
158                 .name           = "tp-link:green:wan_status",
159                 .gpio           = TL_WR841NV11_GPIO_LED_WAN_STATUS,
160                 .active_low     = 1,
161         }, {
162                 .name           = "tp-link:green:wlan",
163                 .gpio           = TL_WR841NV9_GPIO_LED_WLAN,
164                 .active_low     = 1,
165         },
166 };
167
168 static struct gpio_led tl_wr842n_v3_leds_gpio[] __initdata = {
169         {
170                 .name           = "tp-link:green:lan1",
171                 .gpio           = TL_WR842NV3_GPIO_LED_LAN1,
172                 .active_low     = 1,
173         }, {
174                 .name           = "tp-link:green:lan2",
175                 .gpio           = TL_WR842NV3_GPIO_LED_LAN2,
176                 .active_low     = 1,
177         }, {
178                 .name           = "tp-link:green:lan3",
179                 .gpio           = TL_WR842NV3_GPIO_LED_LAN3,
180                 .active_low     = 1,
181         }, {
182                 .name           = "tp-link:green:lan4",
183                 .gpio           = TL_WR842NV3_GPIO_LED_LAN4,
184                 .active_low     = 1,
185         }, {
186                 .name           = "tp-link:green:wan",
187                 .gpio           = TL_WR842NV3_GPIO_LED_WAN_GREEN,
188                 .active_low     = 1,
189         }, {
190                 .name           = "tp-link:red:wan",
191                 .gpio           = TL_WR842NV3_GPIO_LED_WAN_RED,
192                 .active_low     = 1,
193         }, {
194                 .name           = "tp-link:green:wlan",
195                 .gpio           = TL_WR842NV3_GPIO_LED_WLAN,
196                 .active_low     = 1,
197         }, {
198                 .name           = "tp-link:green:system",
199                 .gpio           = TL_WR842NV3_GPIO_LED_SYSTEM,
200                 .active_low     = 1,
201         }, {
202                 .name           = "tp-link:green:3g",
203                 .gpio           = TL_WR842NV3_GPIO_LED_3G,
204                 .active_low     = 1,
205         }, {
206                 .name           = "tp-link:green:wps",
207                 .gpio           = TL_WR842NV3_GPIO_LED_WPS,
208                 .active_low     = 1,
209         },
210 };
211
212 static struct gpio_keys_button tl_wr842n_v3_gpio_keys[] __initdata = {
213         {
214                 .desc           = "Reset button",
215                 .type           = EV_KEY,
216                 .code           = KEY_RESTART,
217                 .debounce_interval = TL_WR841NV9_KEYS_DEBOUNCE_INTERVAL,
218                 .gpio           = TL_WR842NV3_GPIO_BTN_RESET,
219                 .active_low     = 1,
220         }, {
221                 .desc           = "WIFI button",
222                 .type           = EV_KEY,
223                 .code           = KEY_RFKILL,
224                 .debounce_interval = TL_WR841NV9_KEYS_DEBOUNCE_INTERVAL,
225                 .gpio           = TL_WR842NV3_GPIO_BTN_WIFI,
226                 .active_low     = 1,
227         }
228 };
229
230
231 static void __init tl_ap143_setup(void)
232 {
233         u8 *mac = (u8 *) KSEG1ADDR(0x1f01fc00);
234         u8 *ee = (u8 *) KSEG1ADDR(0x1fff1000);
235         u8 tmpmac[ETH_ALEN];
236
237         ath79_register_m25p80(&tl_wr841n_v9_flash_data);
238
239         ath79_setup_ar933x_phy4_switch(false, false);
240
241         ath79_register_mdio(0, 0x0);
242
243         /* LAN */
244         ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_GMII;
245         ath79_eth1_data.duplex = DUPLEX_FULL;
246         ath79_switch_data.phy_poll_mask |= BIT(4);
247         ath79_init_mac(ath79_eth1_data.mac_addr, mac, 0);
248         ath79_register_eth(1);
249
250         /* WAN */
251         ath79_switch_data.phy4_mii_en = 1;
252         ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
253         ath79_eth0_data.duplex = DUPLEX_FULL;
254         ath79_eth0_data.speed = SPEED_100;
255         ath79_eth0_data.phy_mask = BIT(4);
256         ath79_init_mac(ath79_eth0_data.mac_addr, mac, 1);
257         ath79_register_eth(0);
258
259         ath79_init_mac(tmpmac, mac, 0);
260         ath79_register_wmac(ee, tmpmac);
261 }
262
263 static void __init tl_wr841n_v9_setup(void)
264 {
265         tl_ap143_setup();
266
267         ath79_register_leds_gpio(-1, ARRAY_SIZE(tl_wr841n_v9_leds_gpio),
268                                  tl_wr841n_v9_leds_gpio);
269
270         ath79_register_gpio_keys_polled(1, TL_WR841NV9_KEYS_POLL_INTERVAL,
271                                         ARRAY_SIZE(tl_wr841n_v9_gpio_keys),
272                                         tl_wr841n_v9_gpio_keys);
273 }
274
275 MIPS_MACHINE(ATH79_MACH_TL_WR841N_V9, "TL-WR841N-v9", "TP-LINK TL-WR841N/ND v9",
276              tl_wr841n_v9_setup);
277
278 static void __init tl_wr841n_v11_setup(void)
279 {
280         tl_ap143_setup();
281
282         ath79_register_leds_gpio(-1, ARRAY_SIZE(tl_wr841n_v11_leds_gpio),
283                                  tl_wr841n_v11_leds_gpio);
284
285         ath79_register_gpio_keys_polled(1, TL_WR841NV9_KEYS_POLL_INTERVAL,
286                                         ARRAY_SIZE(tl_wr841n_v9_gpio_keys),
287                                         tl_wr841n_v9_gpio_keys);
288 }
289
290 MIPS_MACHINE(ATH79_MACH_TL_WR841N_V11, "TL-WR841N-v11", "TP-LINK TL-WR841N/ND v11",
291              tl_wr841n_v11_setup);
292
293 static void __init tl_wr842n_v3_setup(void)
294 {
295         tl_ap143_setup();
296
297         ath79_register_leds_gpio(-1, ARRAY_SIZE(tl_wr842n_v3_leds_gpio),
298                                  tl_wr842n_v3_leds_gpio);
299
300         ath79_register_gpio_keys_polled(1, TL_WR841NV9_KEYS_POLL_INTERVAL,
301                                         ARRAY_SIZE(tl_wr842n_v3_gpio_keys),
302                                         tl_wr842n_v3_gpio_keys);
303
304         ath79_register_usb();
305 }
306
307 MIPS_MACHINE(ATH79_MACH_TL_WR842N_V3, "TL-WR842N-v3", "TP-LINK TL-WR842N/ND v3",
308              tl_wr842n_v3_setup);