2 * TP-LINK TL-WR840N v2/v3 / TL-WR841N/ND v9/v11 / TL-WR842N/ND v3
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 * Copyright (C) 2017 Vaclav Svoboda <svoboda@neng.cz>
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License version 2 as published
11 * by the Free Software Foundation.
14 #include <linux/gpio.h>
15 #include <linux/platform_device.h>
17 #include <asm/mach-ath79/ath79.h>
18 #include <asm/mach-ath79/ar71xx_regs.h>
22 #include "dev-gpio-buttons.h"
23 #include "dev-leds-gpio.h"
24 #include "dev-m25p80.h"
27 #include "machtypes.h"
29 #define TL_WR840NV2_GPIO_LED_SYSTEM 15
30 #define TL_WR840NV2_GPIO_LED_WLAN 13
31 #define TL_WR840NV2_GPIO_LED_WPS 3
32 #define TL_WR840NV2_GPIO_LED_WAN 4
33 #define TL_WR840NV2_GPIO_LED_LAN 16
35 #define TL_WR840NV2_GPIO_BTN_RESET 12
37 #define TL_WR841NV9_GPIO_LED_WLAN 13
38 #define TL_WR841NV9_GPIO_LED_QSS 3
39 #define TL_WR841NV9_GPIO_LED_WAN 4
40 #define TL_WR841NV9_GPIO_LED_LAN1 16
41 #define TL_WR841NV9_GPIO_LED_LAN2 15
42 #define TL_WR841NV9_GPIO_LED_LAN3 14
43 #define TL_WR841NV9_GPIO_LED_LAN4 11
45 #define TL_WR841NV9_GPIO_BTN_RESET 12
46 #define TL_WR841NV9_GPIO_BTN_WIFI 17
48 #define TL_WR841NV11_GPIO_LED_SYSTEM 1
49 #define TL_WR841NV11_GPIO_LED_QSS 3
50 #define TL_WR841NV11_GPIO_LED_WAN 4
51 #define TL_WR841NV11_GPIO_LED_WAN_STATUS 2
52 #define TL_WR841NV11_GPIO_LED_WLAN 13
53 #define TL_WR841NV11_GPIO_LED_LAN1 16
54 #define TL_WR841NV11_GPIO_LED_LAN2 15
55 #define TL_WR841NV11_GPIO_LED_LAN3 14
56 #define TL_WR841NV11_GPIO_LED_LAN4 11
58 #define TL_WR841NV11_GPIO_BTN_RESET 12
59 #define TL_WR841NV11_GPIO_BTN_WIFI 17
61 #define TL_WR842NV3_GPIO_LED_SYSTEM 2
62 #define TL_WR842NV3_GPIO_LED_WLAN 3
63 #define TL_WR842NV3_GPIO_LED_WAN_RED 4
64 #define TL_WR842NV3_GPIO_LED_WAN_GREEN 11
65 #define TL_WR842NV3_GPIO_LED_LAN1 12
66 #define TL_WR842NV3_GPIO_LED_LAN2 13
67 #define TL_WR842NV3_GPIO_LED_LAN3 14
68 #define TL_WR842NV3_GPIO_LED_LAN4 15
69 #define TL_WR842NV3_GPIO_LED_3G 16
70 #define TL_WR842NV3_GPIO_LED_WPS 17
72 #define TL_WR842NV3_GPIO_BTN_RESET 1
73 #define TL_WR842NV3_GPIO_BTN_WIFI 0
75 #define TL_WR841NV9_KEYS_POLL_INTERVAL 20 /* msecs */
76 #define TL_WR841NV9_KEYS_DEBOUNCE_INTERVAL (3 * TL_WR841NV9_KEYS_POLL_INTERVAL)
78 static const char *tl_wr841n_v9_part_probes
[] = {
83 static struct flash_platform_data tl_wr841n_v9_flash_data
= {
84 .part_probes
= tl_wr841n_v9_part_probes
,
87 static struct gpio_led tl_wr840n_v2_leds_gpio
[] __initdata
= {
89 .name
= "tp-link:green:system",
90 .gpio
= TL_WR840NV2_GPIO_LED_SYSTEM
,
93 .name
= "tp-link:green:lan",
94 .gpio
= TL_WR840NV2_GPIO_LED_LAN
,
97 .name
= "tp-link:green:wps",
98 .gpio
= TL_WR840NV2_GPIO_LED_WPS
,
101 .name
= "tp-link:green:wan",
102 .gpio
= TL_WR840NV2_GPIO_LED_WAN
,
105 .name
= "tp-link:green:wlan",
106 .gpio
= TL_WR840NV2_GPIO_LED_WLAN
,
111 static struct gpio_keys_button tl_wr840n_v2_gpio_keys
[] __initdata
= {
113 .desc
= "Reset button",
116 .debounce_interval
= TL_WR841NV9_KEYS_DEBOUNCE_INTERVAL
,
117 .gpio
= TL_WR840NV2_GPIO_BTN_RESET
,
122 static struct gpio_led tl_wr841n_v9_leds_gpio
[] __initdata
= {
124 .name
= "tp-link:green:lan1",
125 .gpio
= TL_WR841NV9_GPIO_LED_LAN1
,
128 .name
= "tp-link:green:lan2",
129 .gpio
= TL_WR841NV9_GPIO_LED_LAN2
,
132 .name
= "tp-link:green:lan3",
133 .gpio
= TL_WR841NV9_GPIO_LED_LAN3
,
136 .name
= "tp-link:green:lan4",
137 .gpio
= TL_WR841NV9_GPIO_LED_LAN4
,
140 .name
= "tp-link:green:qss",
141 .gpio
= TL_WR841NV9_GPIO_LED_QSS
,
144 .name
= "tp-link:green:wan",
145 .gpio
= TL_WR841NV9_GPIO_LED_WAN
,
148 .name
= "tp-link:green:wlan",
149 .gpio
= TL_WR841NV9_GPIO_LED_WLAN
,
154 static struct gpio_keys_button tl_wr841n_v9_gpio_keys
[] __initdata
= {
156 .desc
= "Reset button",
159 .debounce_interval
= TL_WR841NV9_KEYS_DEBOUNCE_INTERVAL
,
160 .gpio
= TL_WR841NV9_GPIO_BTN_RESET
,
163 .desc
= "WIFI button",
166 .debounce_interval
= TL_WR841NV9_KEYS_DEBOUNCE_INTERVAL
,
167 .gpio
= TL_WR841NV9_GPIO_BTN_WIFI
,
172 static struct gpio_led tl_wr841n_v11_leds_gpio
[] __initdata
= {
174 .name
= "tp-link:green:lan1",
175 .gpio
= TL_WR841NV9_GPIO_LED_LAN1
,
178 .name
= "tp-link:green:lan2",
179 .gpio
= TL_WR841NV9_GPIO_LED_LAN2
,
182 .name
= "tp-link:green:lan3",
183 .gpio
= TL_WR841NV9_GPIO_LED_LAN3
,
186 .name
= "tp-link:green:lan4",
187 .gpio
= TL_WR841NV9_GPIO_LED_LAN4
,
190 .name
= "tp-link:green:qss",
191 .gpio
= TL_WR841NV9_GPIO_LED_QSS
,
194 .name
= "tp-link:green:system",
195 .gpio
= TL_WR841NV11_GPIO_LED_SYSTEM
,
198 .name
= "tp-link:green:wan",
199 .gpio
= TL_WR841NV9_GPIO_LED_WAN
,
202 .name
= "tp-link:green:wan_status",
203 .gpio
= TL_WR841NV11_GPIO_LED_WAN_STATUS
,
206 .name
= "tp-link:green:wlan",
207 .gpio
= TL_WR841NV9_GPIO_LED_WLAN
,
212 static struct gpio_led tl_wr842n_v3_leds_gpio
[] __initdata
= {
214 .name
= "tp-link:green:lan1",
215 .gpio
= TL_WR842NV3_GPIO_LED_LAN1
,
218 .name
= "tp-link:green:lan2",
219 .gpio
= TL_WR842NV3_GPIO_LED_LAN2
,
222 .name
= "tp-link:green:lan3",
223 .gpio
= TL_WR842NV3_GPIO_LED_LAN3
,
226 .name
= "tp-link:green:lan4",
227 .gpio
= TL_WR842NV3_GPIO_LED_LAN4
,
230 .name
= "tp-link:green:wan",
231 .gpio
= TL_WR842NV3_GPIO_LED_WAN_GREEN
,
234 .name
= "tp-link:red:wan",
235 .gpio
= TL_WR842NV3_GPIO_LED_WAN_RED
,
238 .name
= "tp-link:green:wlan",
239 .gpio
= TL_WR842NV3_GPIO_LED_WLAN
,
242 .name
= "tp-link:green:system",
243 .gpio
= TL_WR842NV3_GPIO_LED_SYSTEM
,
246 .name
= "tp-link:green:3g",
247 .gpio
= TL_WR842NV3_GPIO_LED_3G
,
250 .name
= "tp-link:green:wps",
251 .gpio
= TL_WR842NV3_GPIO_LED_WPS
,
256 static struct gpio_keys_button tl_wr842n_v3_gpio_keys
[] __initdata
= {
258 .desc
= "Reset button",
261 .debounce_interval
= TL_WR841NV9_KEYS_DEBOUNCE_INTERVAL
,
262 .gpio
= TL_WR842NV3_GPIO_BTN_RESET
,
265 .desc
= "WIFI button",
268 .debounce_interval
= TL_WR841NV9_KEYS_DEBOUNCE_INTERVAL
,
269 .gpio
= TL_WR842NV3_GPIO_BTN_WIFI
,
275 static void __init
tl_ap143_setup(void)
277 u8
*mac
= (u8
*) KSEG1ADDR(0x1f01fc00);
278 u8
*ee
= (u8
*) KSEG1ADDR(0x1fff1000);
281 ath79_register_m25p80(&tl_wr841n_v9_flash_data
);
283 ath79_setup_ar933x_phy4_switch(false, false);
285 ath79_register_mdio(0, 0x0);
288 ath79_eth1_data
.phy_if_mode
= PHY_INTERFACE_MODE_GMII
;
289 ath79_eth1_data
.duplex
= DUPLEX_FULL
;
290 ath79_switch_data
.phy_poll_mask
|= BIT(4);
291 ath79_init_mac(ath79_eth1_data
.mac_addr
, mac
, 0);
292 ath79_register_eth(1);
295 ath79_switch_data
.phy4_mii_en
= 1;
296 ath79_eth0_data
.phy_if_mode
= PHY_INTERFACE_MODE_MII
;
297 ath79_eth0_data
.duplex
= DUPLEX_FULL
;
298 ath79_eth0_data
.speed
= SPEED_100
;
299 ath79_eth0_data
.phy_mask
= BIT(4);
300 ath79_init_mac(ath79_eth0_data
.mac_addr
, mac
, 1);
301 ath79_register_eth(0);
303 ath79_init_mac(tmpmac
, mac
, 0);
304 ath79_register_wmac(ee
, tmpmac
);
308 static void __init
tl_wr840n_v2_setup(void)
312 ath79_register_leds_gpio(-1, ARRAY_SIZE(tl_wr840n_v2_leds_gpio
),
313 tl_wr840n_v2_leds_gpio
);
315 ath79_register_gpio_keys_polled(1, TL_WR841NV9_KEYS_POLL_INTERVAL
,
316 ARRAY_SIZE(tl_wr840n_v2_gpio_keys
),
317 tl_wr840n_v2_gpio_keys
);
320 MIPS_MACHINE(ATH79_MACH_TL_WR840N_V2
, "TL-WR840N-v2", "TP-LINK TL-WR840N v2",
323 MIPS_MACHINE(ATH79_MACH_TL_WR840N_V3
, "TL-WR840N-v3", "TP-LINK TL-WR840N v3",
326 static void __init
tl_wr841n_v9_setup(void)
330 ath79_register_leds_gpio(-1, ARRAY_SIZE(tl_wr841n_v9_leds_gpio
),
331 tl_wr841n_v9_leds_gpio
);
333 ath79_register_gpio_keys_polled(1, TL_WR841NV9_KEYS_POLL_INTERVAL
,
334 ARRAY_SIZE(tl_wr841n_v9_gpio_keys
),
335 tl_wr841n_v9_gpio_keys
);
338 MIPS_MACHINE(ATH79_MACH_TL_WR841N_V9
, "TL-WR841N-v9", "TP-LINK TL-WR841N/ND v9",
341 static void __init
tl_wr841n_v11_setup(void)
345 ath79_register_leds_gpio(-1, ARRAY_SIZE(tl_wr841n_v11_leds_gpio
),
346 tl_wr841n_v11_leds_gpio
);
348 ath79_register_gpio_keys_polled(1, TL_WR841NV9_KEYS_POLL_INTERVAL
,
349 ARRAY_SIZE(tl_wr841n_v9_gpio_keys
),
350 tl_wr841n_v9_gpio_keys
);
353 MIPS_MACHINE(ATH79_MACH_TL_WR841N_V11
, "TL-WR841N-v11", "TP-LINK TL-WR841N/ND v11",
354 tl_wr841n_v11_setup
);
356 static void __init
tl_wr842n_v3_setup(void)
360 ath79_register_leds_gpio(-1, ARRAY_SIZE(tl_wr842n_v3_leds_gpio
),
361 tl_wr842n_v3_leds_gpio
);
363 ath79_register_gpio_keys_polled(1, TL_WR841NV9_KEYS_POLL_INTERVAL
,
364 ARRAY_SIZE(tl_wr842n_v3_gpio_keys
),
365 tl_wr842n_v3_gpio_keys
);
367 ath79_register_usb();
370 MIPS_MACHINE(ATH79_MACH_TL_WR842N_V3
, "TL-WR842N-v3", "TP-LINK TL-WR842N/ND v3",