ar71xx: add support for COMFAST CF-E355AC
[openwrt/openwrt.git] / target / linux / ar71xx / files / arch / mips / ath79 / mach-cf-e316n-v2.c
1 /*
2 * Support for COMFAST boards:
3 * - CF-E316N v2 (AR9341)
4 * - CF-E320N v2 (QCA9531)
5 * - CF-E355AC (QCA9531)
6 * - CF-E380AC v1/v2 (QCA9558)
7 * - CF-E520N/CF-E530N (QCA9531)
8 *
9 * Copyright (C) 2016 Piotr Dymacz <pepe2k@gmail.com>
10 * Copyright (C) 2016 Gareth Parker <gareth41@orcon.net.nz>
11 * Copyright (C) 2015 Paul Fertser <fercerpav@gmail.com>
12 *
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License version 2 as published
15 * by the Free Software Foundation.
16 */
17
18 #include <linux/gpio.h>
19 #include <linux/platform_data/phy-at803x.h>
20 #include <linux/platform_device.h>
21 #include <linux/timer.h>
22
23 #include <asm/mach-ath79/ath79.h>
24 #include <asm/mach-ath79/ar71xx_regs.h>
25
26 #include "common.h"
27 #include "dev-ap9x-pci.h"
28 #include "dev-eth.h"
29 #include "dev-gpio-buttons.h"
30 #include "dev-leds-gpio.h"
31 #include "dev-m25p80.h"
32 #include "dev-wmac.h"
33 #include "dev-usb.h"
34 #include "machtypes.h"
35
36 #define CF_EXXXN_KEYS_POLL_INTERVAL 20
37 #define CF_EXXXN_KEYS_DEBOUNCE_INTERVAL (3 * CF_EXXXN_KEYS_POLL_INTERVAL)
38
39 /* CF-E316N v2 */
40 #define CF_E316N_V2_GPIO_LED_DIAG_B 0
41 #define CF_E316N_V2_GPIO_LED_DIAG_R 2
42 #define CF_E316N_V2_GPIO_LED_DIAG_G 3
43 #define CF_E316N_V2_GPIO_LED_WLAN 12
44 #define CF_E316N_V2_GPIO_LED_WAN 17
45 #define CF_E316N_V2_GPIO_LED_LAN 19
46
47 #define CF_E316N_V2_GPIO_EXT_WDT 16
48
49 #define CF_E316N_V2_GPIO_EXTERNAL_PA0 13
50 #define CF_E316N_V2_GPIO_EXTERNAL_PA1 14
51
52 #define CF_E316N_V2_GPIO_BTN_RESET 20
53
54 static struct gpio_led cf_e316n_v2_leds_gpio[] __initdata = {
55 {
56 .name = "cf-e316n-v2:blue:diag",
57 .gpio = CF_E316N_V2_GPIO_LED_DIAG_B,
58 .active_low = 0,
59 }, {
60 .name = "cf-e316n-v2:red:diag",
61 .gpio = CF_E316N_V2_GPIO_LED_DIAG_R,
62 .active_low = 0,
63 }, {
64 .name = "cf-e316n-v2:green:diag",
65 .gpio = CF_E316N_V2_GPIO_LED_DIAG_G,
66 .active_low = 0,
67 }, {
68 .name = "cf-e316n-v2:blue:wlan",
69 .gpio = CF_E316N_V2_GPIO_LED_WLAN,
70 .active_low = 1,
71 }, {
72 .name = "cf-e316n-v2:blue:wan",
73 .gpio = CF_E316N_V2_GPIO_LED_WAN,
74 .active_low = 1,
75 }, {
76 .name = "cf-e316n-v2:blue:lan",
77 .gpio = CF_E316N_V2_GPIO_LED_LAN,
78 .active_low = 1,
79 },
80 };
81
82 static struct gpio_keys_button cf_e316n_v2_gpio_keys[] __initdata = {
83 {
84 .desc = "reset",
85 .type = EV_KEY,
86 .code = KEY_RESTART,
87 .debounce_interval = CF_EXXXN_KEYS_DEBOUNCE_INTERVAL,
88 .gpio = CF_E316N_V2_GPIO_BTN_RESET,
89 .active_low = 1,
90 },
91 };
92
93 /* CF-E320N v2 */
94 #define CF_E320N_V2_GPIO_LED_WLAN 0
95 #define CF_E320N_V2_GPIO_LED_WAN 2
96 #define CF_E320N_V2_GPIO_LED_LAN 3
97
98 #define CF_E320N_V2_GPIO_HEADER_J9_1 14
99 #define CF_E320N_V2_GPIO_HEADER_J9_2 12
100 #define CF_E320N_V2_GPIO_HEADER_J9_3 11
101 #define CF_E320N_V2_GPIO_HEADER_J9_4 16
102
103 #define CF_E320N_V2_GPIO_EXT_WDT 13
104
105 #define CF_E320N_V2_GPIO_BTN_RESET 17
106
107 static struct gpio_led cf_e320n_v2_leds_gpio[] __initdata = {
108 {
109 .name = "cf-e320n-v2:green:lan",
110 .gpio = CF_E320N_V2_GPIO_LED_LAN,
111 .active_low = 0,
112 }, {
113 .name = "cf-e320n-v2:red:wan",
114 .gpio = CF_E320N_V2_GPIO_LED_WAN,
115 .active_low = 0,
116 }, {
117 .name = "cf-e320n-v2:blue:wlan",
118 .gpio = CF_E320N_V2_GPIO_LED_WLAN,
119 .active_low = 0,
120 },
121 };
122
123 static struct gpio_keys_button cf_e320n_v2_gpio_keys[] __initdata = {
124 {
125 .desc = "Reset button",
126 .type = EV_KEY,
127 .code = KEY_RESTART,
128 .debounce_interval = CF_EXXXN_KEYS_DEBOUNCE_INTERVAL,
129 .gpio = CF_E320N_V2_GPIO_BTN_RESET,
130 .active_low = 1,
131 },
132 };
133
134 /* CF-E355AC */
135 #define CF_E355AC_GPIO_LED_LAN 3
136 #define CF_E355AC_GPIO_LED_WLAN2G 0
137 #define CF_E355AC_GPIO_LED_WLAN5G 2
138
139 #define CF_E355AC_GPIO_EXT_WDT 13
140
141 #define CF_E355AC_GPIO_BTN_RESET 17
142
143 static struct gpio_led cf_e355ac_leds_gpio[] __initdata = {
144 {
145 .name = "cf-e355ac:green:lan",
146 .gpio = CF_E355AC_GPIO_LED_LAN,
147 .active_low = 0,
148 }, {
149 .name = "cf-e355ac:blue:wlan2g",
150 .gpio = CF_E355AC_GPIO_LED_WLAN2G,
151 .active_low = 0,
152 }, {
153 .name = "cf-e355ac:red:wlan5g",
154 .gpio = CF_E355AC_GPIO_LED_WLAN5G,
155 .active_low = 0,
156 },
157 };
158
159 static struct gpio_keys_button cf_e355ac_gpio_keys[] __initdata = {
160 {
161 .desc = "Reset button",
162 .type = EV_KEY,
163 .code = KEY_RESTART,
164 .debounce_interval = CF_EXXXN_KEYS_DEBOUNCE_INTERVAL,
165 .gpio = CF_E355AC_GPIO_BTN_RESET,
166 .active_low = 1,
167 },
168 };
169
170 /* CF-E380AC v1/v2 */
171 #define CF_E380AC_V1V2_GPIO_LED_LAN 0
172 #define CF_E380AC_V1V2_GPIO_LED_WLAN2G 2
173 #define CF_E380AC_V1V2_GPIO_LED_WLAN5G 3
174
175 #define CF_E380AC_V1V2_GPIO_EXT_WDT 17
176
177 #define CF_E380AC_V1V2_GPIO_BTN_RESET 19
178
179 static struct gpio_led cf_e380ac_v1_leds_gpio[] __initdata = {
180 {
181 .name = "cf-e380ac-v1:green:lan",
182 .gpio = CF_E380AC_V1V2_GPIO_LED_LAN,
183 .active_low = 0,
184 }, {
185 .name = "cf-e380ac-v1:blue:wlan2g",
186 .gpio = CF_E380AC_V1V2_GPIO_LED_WLAN2G,
187 .active_low = 0,
188 }, {
189 .name = "cf-e380ac-v1:red:wlan5g",
190 .gpio = CF_E380AC_V1V2_GPIO_LED_WLAN5G,
191 .active_low = 0,
192 },
193 };
194
195 static struct gpio_led cf_e380ac_v2_leds_gpio[] __initdata = {
196 {
197 .name = "cf-e380ac-v2:green:lan",
198 .gpio = CF_E380AC_V1V2_GPIO_LED_LAN,
199 .active_low = 0,
200 }, {
201 .name = "cf-e380ac-v2:blue:wlan2g",
202 .gpio = CF_E380AC_V1V2_GPIO_LED_WLAN2G,
203 .active_low = 0,
204 }, {
205 .name = "cf-e380ac-v2:red:wlan5g",
206 .gpio = CF_E380AC_V1V2_GPIO_LED_WLAN5G,
207 .active_low = 0,
208 },
209 };
210
211 static struct gpio_keys_button cf_e380ac_v1v2_gpio_keys[] __initdata = {
212 {
213 .desc = "Reset button",
214 .type = EV_KEY,
215 .code = KEY_RESTART,
216 .debounce_interval = CF_EXXXN_KEYS_DEBOUNCE_INTERVAL,
217 .gpio = CF_E380AC_V1V2_GPIO_BTN_RESET,
218 .active_low = 1,
219 },
220 };
221
222 static struct at803x_platform_data cf_e380ac_v1v2_at803x_data = {
223 .disable_smarteee = 1,
224 };
225
226 static struct mdio_board_info cf_e380ac_v1v2_mdio0_info[] = {
227 {
228 .bus_id = "ag71xx-mdio.0",
229 .phy_addr = 0,
230 .platform_data = &cf_e380ac_v1v2_at803x_data,
231 },
232 };
233
234 /* CF-E520N/CF-E530N */
235 #define CF_E5X0N_GPIO_LED_WAN 11
236 #define CF_E5X0N_GPIO_BTN_RESET 17
237
238 static struct gpio_led cf_e520n_leds_gpio[] __initdata = {
239 {
240 .name = "cf-e520n:blue:wan",
241 .gpio = CF_E5X0N_GPIO_LED_WAN,
242 .active_low = 1,
243 }
244 };
245
246 static struct gpio_led cf_e530n_leds_gpio[] __initdata = {
247 {
248 .name = "cf-e530n:blue:wan",
249 .gpio = CF_E5X0N_GPIO_LED_WAN,
250 .active_low = 1,
251 }
252 };
253
254 /*
255 * Some COMFAST devices include external hardware watchdog chip,
256 * Pericon Technology PT7A7514, connected to a selected GPIO
257 * and WiSoC RESET_L input. Watchdog time-out is ~1.6 s.
258 */
259 #define CF_EXXXN_EXT_WDT_TIMEOUT_MS 500
260
261 static struct timer_list gpio_wdt_timer;
262
263 static void gpio_wdt_toggle(unsigned long gpio)
264 {
265 static int state;
266
267 state = !state;
268 gpio_set_value(gpio, state);
269
270 mod_timer(&gpio_wdt_timer,
271 jiffies + msecs_to_jiffies(CF_EXXXN_EXT_WDT_TIMEOUT_MS));
272 }
273
274 static void __init cf_exxxn_common_setup(unsigned long art_ofs, int gpio_wdt)
275 {
276 u8 *art = (u8 *) KSEG1ADDR(0x1f001000 + art_ofs);
277
278 if (gpio_wdt > -1) {
279 gpio_request_one(gpio_wdt, GPIOF_OUT_INIT_HIGH,
280 "PT7A7514 watchdog");
281
282 setup_timer(&gpio_wdt_timer, gpio_wdt_toggle, gpio_wdt);
283 gpio_wdt_toggle(gpio_wdt);
284 }
285
286 ath79_register_m25p80(NULL);
287
288 ath79_register_wmac(art, NULL);
289
290 ath79_register_usb();
291 }
292
293 static void __init cf_e316n_v2_setup(void)
294 {
295 u8 *mac = (u8 *) KSEG1ADDR(0x1f010000);
296
297 cf_exxxn_common_setup(0x10000, CF_E316N_V2_GPIO_EXT_WDT);
298
299 ath79_setup_ar934x_eth_cfg(AR934X_ETH_CFG_SW_PHY_SWAP);
300
301 ath79_register_mdio(1, 0x0);
302
303 /* GMAC0 is connected to the PHY0 of the internal switch */
304 ath79_switch_data.phy4_mii_en = 1;
305 ath79_switch_data.phy_poll_mask = BIT(0);
306 ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
307 ath79_eth0_data.phy_mask = BIT(0);
308 ath79_eth0_data.mii_bus_dev = &ath79_mdio1_device.dev;
309 ath79_init_mac(ath79_eth0_data.mac_addr, mac, 0);
310 ath79_register_eth(0);
311
312 /* GMAC1 is connected to the internal switch */
313 ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_GMII;
314 ath79_init_mac(ath79_eth1_data.mac_addr, mac, 2);
315 ath79_register_eth(1);
316
317 /* Enable 2x Skyworks SE2576L WLAN power amplifiers */
318 gpio_request_one(CF_E316N_V2_GPIO_EXTERNAL_PA0, GPIOF_OUT_INIT_HIGH,
319 "WLAN PA0");
320 gpio_request_one(CF_E316N_V2_GPIO_EXTERNAL_PA1, GPIOF_OUT_INIT_HIGH,
321 "WLAN PA1");
322
323 ath79_register_leds_gpio(-1, ARRAY_SIZE(cf_e316n_v2_leds_gpio),
324 cf_e316n_v2_leds_gpio);
325
326 ath79_register_gpio_keys_polled(1, CF_EXXXN_KEYS_POLL_INTERVAL,
327 ARRAY_SIZE(cf_e316n_v2_gpio_keys),
328 cf_e316n_v2_gpio_keys);
329 }
330
331 MIPS_MACHINE(ATH79_MACH_CF_E316N_V2, "CF-E316N-V2", "COMFAST CF-E316N v2",
332 cf_e316n_v2_setup);
333
334 static void __init cf_exxxn_qca953x_eth_setup(void)
335 {
336 u8 *mac = (u8 *) KSEG1ADDR(0x1f010000);
337
338 ath79_setup_ar933x_phy4_switch(false, false);
339
340 ath79_register_mdio(0, 0x0);
341
342 ath79_switch_data.phy4_mii_en = 1;
343 ath79_switch_data.phy_poll_mask |= BIT(4);
344
345 /* LAN */
346 ath79_eth1_data.duplex = DUPLEX_FULL;
347 ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_GMII;
348 ath79_eth1_data.speed = SPEED_1000;
349 ath79_init_mac(ath79_eth1_data.mac_addr, mac, 2);
350 ath79_register_eth(1);
351
352 /* WAN */
353 ath79_eth0_data.duplex = DUPLEX_FULL;
354 ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
355 ath79_eth0_data.speed = SPEED_100;
356 ath79_eth0_data.phy_mask = BIT(4);
357 ath79_init_mac(ath79_eth0_data.mac_addr, mac, 0);
358 ath79_register_eth(0);
359 }
360
361 static void __init cf_e320n_v2_setup(void)
362 {
363 cf_exxxn_common_setup(0x10000, CF_E320N_V2_GPIO_EXT_WDT);
364
365 cf_exxxn_qca953x_eth_setup();
366
367 /* Disable JTAG (enables GPIO0-3) */
368 ath79_gpio_function_enable(AR934X_GPIO_FUNC_JTAG_DISABLE);
369
370 ath79_gpio_direction_select(CF_E320N_V2_GPIO_LED_LAN, true);
371 ath79_gpio_direction_select(CF_E320N_V2_GPIO_LED_WAN, true);
372 ath79_gpio_direction_select(CF_E320N_V2_GPIO_LED_WLAN, true);
373
374 ath79_gpio_output_select(CF_E320N_V2_GPIO_LED_LAN, 0);
375 ath79_gpio_output_select(CF_E320N_V2_GPIO_LED_WAN, 0);
376 ath79_gpio_output_select(CF_E320N_V2_GPIO_LED_WLAN, 0);
377
378 /* Enable GPIO function for GPIOs in J9 header */
379 ath79_gpio_output_select(CF_E320N_V2_GPIO_HEADER_J9_1, 0);
380 ath79_gpio_output_select(CF_E320N_V2_GPIO_HEADER_J9_2, 0);
381 ath79_gpio_output_select(CF_E320N_V2_GPIO_HEADER_J9_3, 0);
382 ath79_gpio_output_select(CF_E320N_V2_GPIO_HEADER_J9_4, 0);
383
384 ath79_register_leds_gpio(-1, ARRAY_SIZE(cf_e320n_v2_leds_gpio),
385 cf_e320n_v2_leds_gpio);
386
387 ath79_register_gpio_keys_polled(-1, CF_EXXXN_KEYS_POLL_INTERVAL,
388 ARRAY_SIZE(cf_e320n_v2_gpio_keys),
389 cf_e320n_v2_gpio_keys);
390 }
391
392 MIPS_MACHINE(ATH79_MACH_CF_E320N_V2, "CF-E320N-V2", "COMFAST CF-E320N v2",
393 cf_e320n_v2_setup);
394
395 static void __init cf_e355ac_setup(void)
396 {
397 u8 *art = (u8 *) KSEG1ADDR(0x1f010000);
398
399 /* Disable JTAG, enabling GPIOs 0-3 */
400 ath79_gpio_function_setup(AR934X_GPIO_FUNC_JTAG_DISABLE, 0);
401
402 cf_exxxn_common_setup(0x10000, CF_E355AC_GPIO_EXT_WDT);
403
404 cf_exxxn_qca953x_eth_setup();
405
406 ath79_gpio_output_select(CF_E355AC_GPIO_LED_LAN, 0);
407 ath79_gpio_output_select(CF_E355AC_GPIO_LED_WLAN2G, 0);
408 ath79_gpio_output_select(CF_E355AC_GPIO_LED_WLAN5G, 0);
409
410 ap91_pci_init(art + 0x5000, NULL);
411
412 ath79_register_leds_gpio(-1, ARRAY_SIZE(cf_e355ac_leds_gpio),
413 cf_e355ac_leds_gpio);
414
415 ath79_register_gpio_keys_polled(1, CF_EXXXN_KEYS_POLL_INTERVAL,
416 ARRAY_SIZE(cf_e355ac_gpio_keys),
417 cf_e355ac_gpio_keys);
418 }
419
420 MIPS_MACHINE(ATH79_MACH_CF_E355AC, "CF-E355AC", "COMFAST CF-E355AC",
421 cf_e355ac_setup);
422
423 static void __init cf_e380ac_v1v2_common_setup(unsigned long art_ofs)
424 {
425 u8 *mac = (u8 *) KSEG1ADDR(0x1f000000 + art_ofs);
426
427 cf_exxxn_common_setup(art_ofs, CF_E380AC_V1V2_GPIO_EXT_WDT);
428
429 ath79_setup_qca955x_eth_cfg(QCA955X_ETH_CFG_RGMII_EN);
430
431 ath79_register_mdio(0, 0x0);
432 mdiobus_register_board_info(cf_e380ac_v1v2_mdio0_info,
433 ARRAY_SIZE(cf_e380ac_v1v2_mdio0_info));
434
435 /* LAN */
436 ath79_eth0_data.mii_bus_dev = &ath79_mdio0_device.dev;
437 ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
438 ath79_eth0_data.phy_mask = BIT(0);
439 ath79_eth0_pll_data.pll_1000 = 0xbe000000;
440 ath79_eth0_pll_data.pll_100 = 0xb0000101;
441 ath79_eth0_pll_data.pll_10 = 0xb0001313;
442 ath79_init_mac(ath79_eth0_data.mac_addr, mac, 0);
443 ath79_register_eth(0);
444
445 ap91_pci_init(mac + 0x5000, NULL);
446
447 /* Disable JTAG (enables GPIO0-3) */
448 ath79_gpio_function_enable(AR934X_GPIO_FUNC_JTAG_DISABLE);
449
450 ath79_gpio_direction_select(CF_E380AC_V1V2_GPIO_LED_LAN, true);
451 ath79_gpio_direction_select(CF_E380AC_V1V2_GPIO_LED_WLAN2G, true);
452 ath79_gpio_direction_select(CF_E380AC_V1V2_GPIO_LED_WLAN5G, true);
453
454 ath79_gpio_output_select(CF_E380AC_V1V2_GPIO_LED_LAN, 0);
455 ath79_gpio_output_select(CF_E380AC_V1V2_GPIO_LED_WLAN2G, 0);
456 ath79_gpio_output_select(CF_E380AC_V1V2_GPIO_LED_WLAN5G, 0);
457
458 /* For J7-4 */
459 ath79_gpio_function_disable(AR934X_GPIO_FUNC_CLK_OBS4_EN);
460
461 ath79_register_gpio_keys_polled(-1, CF_EXXXN_KEYS_POLL_INTERVAL,
462 ARRAY_SIZE(cf_e380ac_v1v2_gpio_keys),
463 cf_e380ac_v1v2_gpio_keys);
464 }
465
466 static void __init cf_e380ac_v1_setup(void)
467 {
468 cf_e380ac_v1v2_common_setup(0x20000);
469
470 ath79_register_leds_gpio(-1, ARRAY_SIZE(cf_e380ac_v1_leds_gpio),
471 cf_e380ac_v1_leds_gpio);
472 }
473
474 MIPS_MACHINE(ATH79_MACH_CF_E380AC_V1, "CF-E380AC-V1", "COMFAST CF-E380AC v1",
475 cf_e380ac_v1_setup);
476
477 static void __init cf_e380ac_v2_setup(void)
478 {
479 cf_e380ac_v1v2_common_setup(0x40000);
480
481 ath79_register_leds_gpio(-1, ARRAY_SIZE(cf_e380ac_v2_leds_gpio),
482 cf_e380ac_v2_leds_gpio);
483 }
484
485 MIPS_MACHINE(ATH79_MACH_CF_E380AC_V2, "CF-E380AC-V2", "COMFAST CF-E380AC v2",
486 cf_e380ac_v2_setup);
487
488 static void __init cf_e5x0n_gpio_setup(void)
489 {
490 ath79_gpio_direction_select(CF_E5X0N_GPIO_LED_WAN, true);
491
492 ath79_gpio_output_select(CF_E5X0N_GPIO_LED_WAN, 0);
493
494 ath79_register_gpio_keys_polled(-1, CF_EXXXN_KEYS_POLL_INTERVAL,
495 ARRAY_SIZE(cf_e320n_v2_gpio_keys),
496 cf_e320n_v2_gpio_keys);
497 }
498
499 static void __init cf_e520n_setup(void)
500 {
501 cf_exxxn_common_setup(0x10000, -1);
502
503 cf_exxxn_qca953x_eth_setup();
504
505 cf_e5x0n_gpio_setup();
506
507 ath79_register_leds_gpio(-1, ARRAY_SIZE(cf_e520n_leds_gpio),
508 cf_e520n_leds_gpio);
509 }
510
511 MIPS_MACHINE(ATH79_MACH_CF_E520N, "CF-E520N", "COMFAST CF-E520N",
512 cf_e520n_setup);
513
514 static void __init cf_e530n_setup(void)
515 {
516 cf_exxxn_common_setup(0x10000, -1);
517
518 cf_exxxn_qca953x_eth_setup();
519
520 cf_e5x0n_gpio_setup();
521
522 ath79_register_leds_gpio(-1, ARRAY_SIZE(cf_e530n_leds_gpio),
523 cf_e530n_leds_gpio);
524 }
525
526 MIPS_MACHINE(ATH79_MACH_CF_E530N, "CF-E530N", "COMFAST CF-E530N",
527 cf_e530n_setup);