24d46646057e93e4e12e3c1b9ae0d8fe25c39b37
[openwrt/openwrt.git] / target / linux / ar71xx / files / arch / mips / ath79 / mach-tl-wr841n-v8.c
1 /*
2 * TP-LINK TL-WR841N/ND v8/TL-MR3420 v2/TL-WA801ND v2 board support
3 *
4 * Copyright (C) 2012 Gabor Juhos <juhosg@openwrt.org>
5 * Copyright (C) 2013 Jiri Pirko <jiri@resnulli.us>
6 *
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.
10 */
11
12 #include <linux/gpio.h>
13 #include <linux/platform_device.h>
14
15 #include <asm/mach-ath79/ath79.h>
16 #include <asm/mach-ath79/ar71xx_regs.h>
17
18 #include "common.h"
19 #include "dev-eth.h"
20 #include "dev-gpio-buttons.h"
21 #include "dev-leds-gpio.h"
22 #include "dev-m25p80.h"
23 #include "dev-usb.h"
24 #include "dev-wmac.h"
25 #include "machtypes.h"
26
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
35
36 #define TL_WR841NV8_GPIO_BTN_RESET 17
37 #define TL_WR841NV8_GPIO_SW_RFKILL 16 /* WPS for MR3420 v2 */
38
39 #define TL_MR3420V2_GPIO_LED_3G 11
40 #define TL_MR3420V2_GPIO_USB_POWER 4
41
42 #define TL_WR841NV8_KEYS_POLL_INTERVAL 20 /* msecs */
43 #define TL_WR841NV8_KEYS_DEBOUNCE_INTERVAL (3 * TL_WR841NV8_KEYS_POLL_INTERVAL)
44
45 static const char *tl_wr841n_v8_part_probes[] = {
46 "tp-link",
47 NULL,
48 };
49
50 static struct flash_platform_data tl_wr841n_v8_flash_data = {
51 .part_probes = tl_wr841n_v8_part_probes,
52 };
53
54 static struct gpio_led tl_wr841n_v8_leds_gpio[] __initdata = {
55 {
56 .name = "tp-link:green:lan1",
57 .gpio = TL_WR841NV8_GPIO_LED_LAN1,
58 .active_low = 1,
59 }, {
60 .name = "tp-link:green:lan2",
61 .gpio = TL_WR841NV8_GPIO_LED_LAN2,
62 .active_low = 1,
63 }, {
64 .name = "tp-link:green:lan3",
65 .gpio = TL_WR841NV8_GPIO_LED_LAN3,
66 .active_low = 1,
67 }, {
68 .name = "tp-link:green:lan4",
69 .gpio = TL_WR841NV8_GPIO_LED_LAN4,
70 .active_low = 1,
71 }, {
72 .name = "tp-link:green:qss",
73 .gpio = TL_WR841NV8_GPIO_LED_QSS,
74 .active_low = 1,
75 }, {
76 .name = "tp-link:green:system",
77 .gpio = TL_WR841NV8_GPIO_LED_SYSTEM,
78 .active_low = 1,
79 }, {
80 .name = "tp-link:green:wan",
81 .gpio = TL_WR841NV8_GPIO_LED_WAN,
82 .active_low = 1,
83 }, {
84 .name = "tp-link:green:wlan",
85 .gpio = TL_WR841NV8_GPIO_LED_WLAN,
86 .active_low = 1,
87 }, {
88 /* the 3G LED is only present on the MR3420 v2 */
89 .name = "tp-link:green:3g",
90 .gpio = TL_MR3420V2_GPIO_LED_3G,
91 .active_low = 1,
92 },
93 };
94
95 static struct gpio_led tl_wa801nd_v2_leds_gpio[] __initdata = {
96 {
97 .name = "tp-link:green:qss",
98 .gpio = TL_WR841NV8_GPIO_LED_QSS,
99 .active_low = 1,
100 }, {
101 .name = "tp-link:green:system",
102 .gpio = TL_WR841NV8_GPIO_LED_SYSTEM,
103 .active_low = 1,
104 }, {
105 .name = "tp-link:green:lan",
106 .gpio = TL_WR841NV8_GPIO_LED_WAN, /* LAN for wa801nd_v2 */
107 .active_low = 1,
108 }, {
109 .name = "tp-link:green:wlan",
110 .gpio = TL_WR841NV8_GPIO_LED_WLAN,
111 .active_low = 1,
112 },
113 };
114
115 static struct gpio_keys_button tl_wr841n_v8_gpio_keys[] __initdata = {
116 {
117 .desc = "Reset button",
118 .type = EV_KEY,
119 .code = KEY_RESTART,
120 .debounce_interval = TL_WR841NV8_KEYS_DEBOUNCE_INTERVAL,
121 .gpio = TL_WR841NV8_GPIO_BTN_RESET,
122 .active_low = 1,
123 }, {
124 .desc = "RFKILL switch",
125 .type = EV_SW,
126 .code = KEY_RFKILL,
127 .debounce_interval = TL_WR841NV8_KEYS_DEBOUNCE_INTERVAL,
128 .gpio = TL_WR841NV8_GPIO_SW_RFKILL,
129 .active_low = 0,
130 }
131 };
132
133 static struct gpio_keys_button tl_mr3420v2_gpio_keys[] __initdata = {
134 {
135 .desc = "Reset button",
136 .type = EV_KEY,
137 .code = KEY_RESTART,
138 .debounce_interval = TL_WR841NV8_KEYS_DEBOUNCE_INTERVAL,
139 .gpio = TL_WR841NV8_GPIO_BTN_RESET,
140 .active_low = 1,
141 }, {
142 .desc = "WPS",
143 .type = EV_KEY,
144 .code = KEY_WPS_BUTTON,
145 .debounce_interval = TL_WR841NV8_KEYS_DEBOUNCE_INTERVAL,
146 .gpio = TL_WR841NV8_GPIO_SW_RFKILL,
147 .active_low = 0,
148 }
149 };
150
151 static void __init tl_ap123_setup(bool setup_gmac1)
152 {
153 u8 *mac = (u8 *) KSEG1ADDR(0x1f01fc00);
154 u8 *ee = (u8 *) KSEG1ADDR(0x1fff1000);
155
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);
160
161 /* config gpio4 as normal gpio function */
162 ath79_gpio_output_select(TL_MR3420V2_GPIO_USB_POWER,
163 AR934X_GPIO_OUT_GPIO);
164
165 ath79_register_m25p80(&tl_wr841n_v8_flash_data);
166
167 ath79_setup_ar934x_eth_cfg(AR934X_ETH_CFG_SW_PHY_SWAP);
168
169 ath79_register_mdio(1, 0x0);
170
171 ath79_init_mac(ath79_eth0_data.mac_addr, mac, -1);
172 ath79_init_mac(ath79_eth1_data.mac_addr, mac, 0);
173
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);
181
182 if (setup_gmac1) {
183 /* GMAC1 is connected to the internal switch */
184 ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_GMII;
185 ath79_register_eth(1);
186 }
187
188 ath79_register_wmac(ee, mac);
189 }
190
191 static void __init tl_wr841n_v8_setup(void)
192 {
193 tl_ap123_setup(true);
194
195 ath79_register_leds_gpio(-1, ARRAY_SIZE(tl_wr841n_v8_leds_gpio) - 1,
196 tl_wr841n_v8_leds_gpio);
197
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);
201 }
202
203 MIPS_MACHINE(ATH79_MACH_TL_WR841N_V8, "TL-WR841N-v8", "TP-LINK TL-WR841N/ND v8",
204 tl_wr841n_v8_setup);
205
206
207 static void __init tl_wr842n_v2_setup(void)
208 {
209 tl_ap123_setup(true);
210
211 ath79_register_leds_gpio(-1, ARRAY_SIZE(tl_wr841n_v8_leds_gpio),
212 tl_wr841n_v8_leds_gpio);
213
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);
217
218 gpio_request_one(TL_MR3420V2_GPIO_USB_POWER,
219 GPIOF_OUT_INIT_HIGH | GPIOF_EXPORT_DIR_FIXED,
220 "USB power");
221
222 ath79_register_usb();
223 }
224
225 MIPS_MACHINE(ATH79_MACH_TL_WR842N_V2, "TL-WR842N-v2", "TP-LINK TL-WR842N/ND v2",
226 tl_wr842n_v2_setup);
227
228 static void __init tl_mr3420v2_setup(void)
229 {
230 tl_ap123_setup(true);
231
232 ath79_register_leds_gpio(-1, ARRAY_SIZE(tl_wr841n_v8_leds_gpio),
233 tl_wr841n_v8_leds_gpio);
234
235 ath79_register_gpio_keys_polled(1, TL_WR841NV8_KEYS_POLL_INTERVAL,
236 ARRAY_SIZE(tl_mr3420v2_gpio_keys),
237 tl_mr3420v2_gpio_keys);
238
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,
242 "USB power");
243
244 ath79_register_usb();
245 }
246
247 MIPS_MACHINE(ATH79_MACH_TL_MR3420_V2, "TL-MR3420-v2", "TP-LINK TL-MR3420 v2",
248 tl_mr3420v2_setup);
249
250 static void __init tl_wa801nd_v2_setup(void)
251 {
252 tl_ap123_setup(false);
253
254 ath79_register_leds_gpio(-1, ARRAY_SIZE(tl_wa801nd_v2_leds_gpio),
255 tl_wa801nd_v2_leds_gpio);
256
257 ath79_register_gpio_keys_polled(1, TL_WR841NV8_KEYS_POLL_INTERVAL,
258 ARRAY_SIZE(tl_mr3420v2_gpio_keys),
259 tl_mr3420v2_gpio_keys);
260 }
261
262 MIPS_MACHINE(ATH79_MACH_TL_WA801ND_V2, "TL-WA801ND-v2", "TP-LINK TL-WA801ND v2",
263 tl_wa801nd_v2_setup);