2 * TP-LINK TL-WR841N/ND v8/TL-MR3420 v2/TL-WA801ND v2 board support
4 * Copyright (C) 2012 Gabor Juhos <juhosg@openwrt.org>
5 * Copyright (C) 2013 Jiri Pirko <jiri@resnulli.us>
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License version 2 as published
9 * by the Free Software Foundation.
12 #include <linux/gpio.h>
13 #include <linux/platform_device.h>
15 #include <asm/mach-ath79/ath79.h>
16 #include <asm/mach-ath79/ar71xx_regs.h>
20 #include "dev-gpio-buttons.h"
21 #include "dev-leds-gpio.h"
22 #include "dev-m25p80.h"
25 #include "machtypes.h"
27 #define TL_WR841NV8_GPIO_LED_WLAN 13
28 #define TL_WR841NV8_GPIO_LED_QSS 15
29 #define TL_WR841NV8_GPIO_LED_WAN 18
30 #define TL_WR841NV8_GPIO_LED_LAN1 19
31 #define TL_WR841NV8_GPIO_LED_LAN2 20
32 #define TL_WR841NV8_GPIO_LED_LAN3 21
33 #define TL_WR841NV8_GPIO_LED_LAN4 12
34 #define TL_WR841NV8_GPIO_LED_SYSTEM 14
36 #define TL_WR841NV8_GPIO_BTN_RESET 17
37 #define TL_WR841NV8_GPIO_SW_RFKILL 16 /* WPS for MR3420 v2 */
39 #define TL_MR3420V2_GPIO_LED_3G 11
40 #define TL_MR3420V2_GPIO_USB_POWER 4
42 #define TL_WR841NV8_KEYS_POLL_INTERVAL 20 /* msecs */
43 #define TL_WR841NV8_KEYS_DEBOUNCE_INTERVAL (3 * TL_WR841NV8_KEYS_POLL_INTERVAL)
45 static const char *tl_wr841n_v8_part_probes[] = {
50 static struct flash_platform_data tl_wr841n_v8_flash_data = {
51 .part_probes = tl_wr841n_v8_part_probes,
54 static struct gpio_led tl_wr841n_v8_leds_gpio[] __initdata = {
56 .name = "tp-link:green:lan1",
57 .gpio = TL_WR841NV8_GPIO_LED_LAN1,
60 .name = "tp-link:green:lan2",
61 .gpio = TL_WR841NV8_GPIO_LED_LAN2,
64 .name = "tp-link:green:lan3",
65 .gpio = TL_WR841NV8_GPIO_LED_LAN3,
68 .name = "tp-link:green:lan4",
69 .gpio = TL_WR841NV8_GPIO_LED_LAN4,
72 .name = "tp-link:green:qss",
73 .gpio = TL_WR841NV8_GPIO_LED_QSS,
76 .name = "tp-link:green:system",
77 .gpio = TL_WR841NV8_GPIO_LED_SYSTEM,
80 .name = "tp-link:green:wan",
81 .gpio = TL_WR841NV8_GPIO_LED_WAN,
84 .name = "tp-link:green:wlan",
85 .gpio = TL_WR841NV8_GPIO_LED_WLAN,
88 /* the 3G LED is only present on the MR3420 v2 */
89 .name = "tp-link:green:3g",
90 .gpio = TL_MR3420V2_GPIO_LED_3G,
95 static struct gpio_led tl_wa801nd_v2_leds_gpio[] __initdata = {
97 .name = "tp-link:green:qss",
98 .gpio = TL_WR841NV8_GPIO_LED_QSS,
101 .name = "tp-link:green:system",
102 .gpio = TL_WR841NV8_GPIO_LED_SYSTEM,
105 .name = "tp-link:green:lan",
106 .gpio = TL_WR841NV8_GPIO_LED_WAN, /* LAN for wa801nd_v2 */
109 .name = "tp-link:green:wlan",
110 .gpio = TL_WR841NV8_GPIO_LED_WLAN,
115 static struct gpio_keys_button tl_wr841n_v8_gpio_keys[] __initdata = {
117 .desc = "Reset button",
120 .debounce_interval = TL_WR841NV8_KEYS_DEBOUNCE_INTERVAL,
121 .gpio = TL_WR841NV8_GPIO_BTN_RESET,
124 .desc = "RFKILL switch",
127 .debounce_interval = TL_WR841NV8_KEYS_DEBOUNCE_INTERVAL,
128 .gpio = TL_WR841NV8_GPIO_SW_RFKILL,
133 static struct gpio_keys_button tl_mr3420v2_gpio_keys[] __initdata = {
135 .desc = "Reset button",
138 .debounce_interval = TL_WR841NV8_KEYS_DEBOUNCE_INTERVAL,
139 .gpio = TL_WR841NV8_GPIO_BTN_RESET,
144 .code = KEY_WPS_BUTTON,
145 .debounce_interval = TL_WR841NV8_KEYS_DEBOUNCE_INTERVAL,
146 .gpio = TL_WR841NV8_GPIO_SW_RFKILL,
151 static void __init tl_ap123_setup(bool setup_gmac1)
153 u8 *mac = (u8 *) KSEG1ADDR(0x1f01fc00);
154 u8 *ee = (u8 *) KSEG1ADDR(0x1fff1000);
156 /* Disable JTAG, enabling GPIOs 0-3 */
157 /* Configure OBS4 line, for GPIO 4*/
158 ath79_gpio_function_setup(AR934X_GPIO_FUNC_JTAG_DISABLE,
159 AR934X_GPIO_FUNC_CLK_OBS4_EN);
161 /* config gpio4 as normal gpio function */
162 ath79_gpio_output_select(TL_MR3420V2_GPIO_USB_POWER,
163 AR934X_GPIO_OUT_GPIO);
165 ath79_register_m25p80(&tl_wr841n_v8_flash_data);
167 ath79_setup_ar934x_eth_cfg(AR934X_ETH_CFG_SW_PHY_SWAP);
169 ath79_register_mdio(1, 0x0);
171 ath79_init_mac(ath79_eth0_data.mac_addr, mac, -1);
172 ath79_init_mac(ath79_eth1_data.mac_addr, mac, 0);
174 /* GMAC0 is connected to the PHY0 of the internal switch */
175 ath79_switch_data.phy4_mii_en = 1;
176 ath79_switch_data.phy_poll_mask = BIT(0);
177 ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
178 ath79_eth0_data.phy_mask = BIT(0);
179 ath79_eth0_data.mii_bus_dev = &ath79_mdio1_device.dev;
180 ath79_register_eth(0);
183 /* GMAC1 is connected to the internal switch */
184 ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_GMII;
185 ath79_register_eth(1);
188 ath79_register_wmac(ee, mac);
191 static void __init tl_wr841n_v8_setup(void)
193 tl_ap123_setup(true);
195 ath79_register_leds_gpio(-1, ARRAY_SIZE(tl_wr841n_v8_leds_gpio) - 1,
196 tl_wr841n_v8_leds_gpio);
198 ath79_register_gpio_keys_polled(1, TL_WR841NV8_KEYS_POLL_INTERVAL,
199 ARRAY_SIZE(tl_wr841n_v8_gpio_keys),
200 tl_wr841n_v8_gpio_keys);
203 MIPS_MACHINE(ATH79_MACH_TL_WR841N_V8, "TL-WR841N-v8", "TP-LINK TL-WR841N/ND v8",
207 static void __init tl_wr842n_v2_setup(void)
209 tl_ap123_setup(true);
211 ath79_register_leds_gpio(-1, ARRAY_SIZE(tl_wr841n_v8_leds_gpio),
212 tl_wr841n_v8_leds_gpio);
214 ath79_register_gpio_keys_polled(1, TL_WR841NV8_KEYS_POLL_INTERVAL,
215 ARRAY_SIZE(tl_wr841n_v8_gpio_keys),
216 tl_wr841n_v8_gpio_keys);
218 gpio_request_one(TL_MR3420V2_GPIO_USB_POWER,
219 GPIOF_OUT_INIT_HIGH | GPIOF_EXPORT_DIR_FIXED,
222 ath79_register_usb();
225 MIPS_MACHINE(ATH79_MACH_TL_WR842N_V2, "TL-WR842N-v2", "TP-LINK TL-WR842N/ND v2",
228 static void __init tl_mr3420v2_setup(void)
230 tl_ap123_setup(true);
232 ath79_register_leds_gpio(-1, ARRAY_SIZE(tl_wr841n_v8_leds_gpio),
233 tl_wr841n_v8_leds_gpio);
235 ath79_register_gpio_keys_polled(1, TL_WR841NV8_KEYS_POLL_INTERVAL,
236 ARRAY_SIZE(tl_mr3420v2_gpio_keys),
237 tl_mr3420v2_gpio_keys);
239 /* enable power for the USB port */
240 gpio_request_one(TL_MR3420V2_GPIO_USB_POWER,
241 GPIOF_OUT_INIT_HIGH | GPIOF_EXPORT_DIR_FIXED,
244 ath79_register_usb();
247 MIPS_MACHINE(ATH79_MACH_TL_MR3420_V2, "TL-MR3420-v2", "TP-LINK TL-MR3420 v2",
250 static void __init tl_wa801nd_v2_setup(void)
252 tl_ap123_setup(false);
254 ath79_register_leds_gpio(-1, ARRAY_SIZE(tl_wa801nd_v2_leds_gpio),
255 tl_wa801nd_v2_leds_gpio);
257 ath79_register_gpio_keys_polled(1, TL_WR841NV8_KEYS_POLL_INTERVAL,
258 ARRAY_SIZE(tl_mr3420v2_gpio_keys),
259 tl_mr3420v2_gpio_keys);
262 MIPS_MACHINE(ATH79_MACH_TL_WA801ND_V2, "TL-WA801ND-v2", "TP-LINK TL-WA801ND v2",
263 tl_wa801nd_v2_setup);