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)
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>
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.
18 #include <linux/gpio.h>
19 #include <linux/platform_data/phy-at803x.h>
20 #include <linux/platform_device.h>
21 #include <linux/timer.h>
23 #include <asm/mach-ath79/ath79.h>
24 #include <asm/mach-ath79/ar71xx_regs.h>
27 #include "dev-ap9x-pci.h"
29 #include "dev-gpio-buttons.h"
30 #include "dev-leds-gpio.h"
31 #include "dev-m25p80.h"
34 #include "machtypes.h"
36 #define CF_EXXXN_KEYS_POLL_INTERVAL 20
37 #define CF_EXXXN_KEYS_DEBOUNCE_INTERVAL (3 * CF_EXXXN_KEYS_POLL_INTERVAL)
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
47 #define CF_E316N_V2_GPIO_EXT_WDT 16
49 #define CF_E316N_V2_GPIO_EXTERNAL_PA0 13
50 #define CF_E316N_V2_GPIO_EXTERNAL_PA1 14
52 #define CF_E316N_V2_GPIO_BTN_RESET 20
54 static struct gpio_led cf_e316n_v2_leds_gpio
[] __initdata
= {
56 .name
= "cf-e316n-v2:blue:diag",
57 .gpio
= CF_E316N_V2_GPIO_LED_DIAG_B
,
60 .name
= "cf-e316n-v2:red:diag",
61 .gpio
= CF_E316N_V2_GPIO_LED_DIAG_R
,
64 .name
= "cf-e316n-v2:green:diag",
65 .gpio
= CF_E316N_V2_GPIO_LED_DIAG_G
,
68 .name
= "cf-e316n-v2:blue:wlan",
69 .gpio
= CF_E316N_V2_GPIO_LED_WLAN
,
72 .name
= "cf-e316n-v2:blue:wan",
73 .gpio
= CF_E316N_V2_GPIO_LED_WAN
,
76 .name
= "cf-e316n-v2:blue:lan",
77 .gpio
= CF_E316N_V2_GPIO_LED_LAN
,
82 static struct gpio_keys_button cf_e316n_v2_gpio_keys
[] __initdata
= {
87 .debounce_interval
= CF_EXXXN_KEYS_DEBOUNCE_INTERVAL
,
88 .gpio
= CF_E316N_V2_GPIO_BTN_RESET
,
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
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
103 #define CF_E320N_V2_GPIO_EXT_WDT 13
105 #define CF_E320N_V2_GPIO_BTN_RESET 17
107 static struct gpio_led cf_e320n_v2_leds_gpio
[] __initdata
= {
109 .name
= "cf-e320n-v2:green:lan",
110 .gpio
= CF_E320N_V2_GPIO_LED_LAN
,
113 .name
= "cf-e320n-v2:red:wan",
114 .gpio
= CF_E320N_V2_GPIO_LED_WAN
,
117 .name
= "cf-e320n-v2:blue:wlan",
118 .gpio
= CF_E320N_V2_GPIO_LED_WLAN
,
123 static struct gpio_keys_button cf_e320n_v2_gpio_keys
[] __initdata
= {
125 .desc
= "Reset button",
128 .debounce_interval
= CF_EXXXN_KEYS_DEBOUNCE_INTERVAL
,
129 .gpio
= CF_E320N_V2_GPIO_BTN_RESET
,
135 #define CF_E355AC_GPIO_LED_LAN 3
136 #define CF_E355AC_GPIO_LED_WLAN2G 0
137 #define CF_E355AC_GPIO_LED_WLAN5G 2
139 #define CF_E355AC_GPIO_EXT_WDT 13
141 #define CF_E355AC_GPIO_BTN_RESET 17
143 static struct gpio_led cf_e355ac_leds_gpio
[] __initdata
= {
145 .name
= "cf-e355ac:green:lan",
146 .gpio
= CF_E355AC_GPIO_LED_LAN
,
149 .name
= "cf-e355ac:blue:wlan2g",
150 .gpio
= CF_E355AC_GPIO_LED_WLAN2G
,
153 .name
= "cf-e355ac:red:wlan5g",
154 .gpio
= CF_E355AC_GPIO_LED_WLAN5G
,
159 static struct gpio_keys_button cf_e355ac_gpio_keys
[] __initdata
= {
161 .desc
= "Reset button",
164 .debounce_interval
= CF_EXXXN_KEYS_DEBOUNCE_INTERVAL
,
165 .gpio
= CF_E355AC_GPIO_BTN_RESET
,
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
175 #define CF_E380AC_V1V2_GPIO_EXT_WDT 17
177 #define CF_E380AC_V1V2_GPIO_BTN_RESET 19
179 static struct gpio_led cf_e380ac_v1_leds_gpio
[] __initdata
= {
181 .name
= "cf-e380ac-v1:green:lan",
182 .gpio
= CF_E380AC_V1V2_GPIO_LED_LAN
,
185 .name
= "cf-e380ac-v1:blue:wlan2g",
186 .gpio
= CF_E380AC_V1V2_GPIO_LED_WLAN2G
,
189 .name
= "cf-e380ac-v1:red:wlan5g",
190 .gpio
= CF_E380AC_V1V2_GPIO_LED_WLAN5G
,
195 static struct gpio_led cf_e380ac_v2_leds_gpio
[] __initdata
= {
197 .name
= "cf-e380ac-v2:green:lan",
198 .gpio
= CF_E380AC_V1V2_GPIO_LED_LAN
,
201 .name
= "cf-e380ac-v2:blue:wlan2g",
202 .gpio
= CF_E380AC_V1V2_GPIO_LED_WLAN2G
,
205 .name
= "cf-e380ac-v2:red:wlan5g",
206 .gpio
= CF_E380AC_V1V2_GPIO_LED_WLAN5G
,
211 static struct gpio_keys_button cf_e380ac_v1v2_gpio_keys
[] __initdata
= {
213 .desc
= "Reset button",
216 .debounce_interval
= CF_EXXXN_KEYS_DEBOUNCE_INTERVAL
,
217 .gpio
= CF_E380AC_V1V2_GPIO_BTN_RESET
,
222 static struct at803x_platform_data cf_e380ac_v1v2_at803x_data
= {
223 .disable_smarteee
= 1,
226 static struct mdio_board_info cf_e380ac_v1v2_mdio0_info
[] = {
228 .bus_id
= "ag71xx-mdio.0",
230 .platform_data
= &cf_e380ac_v1v2_at803x_data
,
234 /* CF-E520N/CF-E530N */
235 #define CF_E5X0N_GPIO_LED_WAN 11
236 #define CF_E5X0N_GPIO_BTN_RESET 17
238 static struct gpio_led cf_e520n_leds_gpio
[] __initdata
= {
240 .name
= "cf-e520n:blue:wan",
241 .gpio
= CF_E5X0N_GPIO_LED_WAN
,
246 static struct gpio_led cf_e530n_leds_gpio
[] __initdata
= {
248 .name
= "cf-e530n:blue:wan",
249 .gpio
= CF_E5X0N_GPIO_LED_WAN
,
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.
259 #define CF_EXXXN_EXT_WDT_TIMEOUT_MS 500
261 static struct timer_list gpio_wdt_timer
;
263 static void gpio_wdt_toggle(unsigned long gpio
)
268 gpio_set_value(gpio
, state
);
270 mod_timer(&gpio_wdt_timer
,
271 jiffies
+ msecs_to_jiffies(CF_EXXXN_EXT_WDT_TIMEOUT_MS
));
274 static void __init
cf_exxxn_common_setup(unsigned long art_ofs
, int gpio_wdt
)
276 u8
*art
= (u8
*) KSEG1ADDR(0x1f001000 + art_ofs
);
279 gpio_request_one(gpio_wdt
, GPIOF_OUT_INIT_HIGH
,
280 "PT7A7514 watchdog");
282 setup_timer(&gpio_wdt_timer
, gpio_wdt_toggle
, gpio_wdt
);
283 gpio_wdt_toggle(gpio_wdt
);
286 ath79_register_m25p80(NULL
);
288 ath79_register_wmac(art
, NULL
);
290 ath79_register_usb();
293 static void __init
cf_e316n_v2_setup(void)
295 u8
*mac
= (u8
*) KSEG1ADDR(0x1f010000);
297 cf_exxxn_common_setup(0x10000, CF_E316N_V2_GPIO_EXT_WDT
);
299 ath79_setup_ar934x_eth_cfg(AR934X_ETH_CFG_SW_PHY_SWAP
);
301 ath79_register_mdio(1, 0x0);
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);
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);
317 /* Enable 2x Skyworks SE2576L WLAN power amplifiers */
318 gpio_request_one(CF_E316N_V2_GPIO_EXTERNAL_PA0
, GPIOF_OUT_INIT_HIGH
,
320 gpio_request_one(CF_E316N_V2_GPIO_EXTERNAL_PA1
, GPIOF_OUT_INIT_HIGH
,
323 ath79_register_leds_gpio(-1, ARRAY_SIZE(cf_e316n_v2_leds_gpio
),
324 cf_e316n_v2_leds_gpio
);
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
);
331 MIPS_MACHINE(ATH79_MACH_CF_E316N_V2
, "CF-E316N-V2", "COMFAST CF-E316N v2",
334 static void __init
cf_exxxn_qca953x_eth_setup(void)
336 u8
*mac
= (u8
*) KSEG1ADDR(0x1f010000);
338 ath79_setup_ar933x_phy4_switch(false, false);
340 ath79_register_mdio(0, 0x0);
342 ath79_switch_data
.phy4_mii_en
= 1;
343 ath79_switch_data
.phy_poll_mask
|= BIT(4);
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);
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);
361 static void __init
cf_e320n_v2_setup(void)
363 cf_exxxn_common_setup(0x10000, CF_E320N_V2_GPIO_EXT_WDT
);
365 cf_exxxn_qca953x_eth_setup();
367 /* Disable JTAG (enables GPIO0-3) */
368 ath79_gpio_function_enable(AR934X_GPIO_FUNC_JTAG_DISABLE
);
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);
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);
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);
384 ath79_register_leds_gpio(-1, ARRAY_SIZE(cf_e320n_v2_leds_gpio
),
385 cf_e320n_v2_leds_gpio
);
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
);
392 MIPS_MACHINE(ATH79_MACH_CF_E320N_V2
, "CF-E320N-V2", "COMFAST CF-E320N v2",
395 static void __init
cf_e355ac_setup(void)
397 u8
*art
= (u8
*) KSEG1ADDR(0x1f010000);
399 /* Disable JTAG, enabling GPIOs 0-3 */
400 ath79_gpio_function_setup(AR934X_GPIO_FUNC_JTAG_DISABLE
, 0);
402 cf_exxxn_common_setup(0x10000, CF_E355AC_GPIO_EXT_WDT
);
404 cf_exxxn_qca953x_eth_setup();
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);
410 ap91_pci_init(art
+ 0x5000, NULL
);
412 ath79_register_leds_gpio(-1, ARRAY_SIZE(cf_e355ac_leds_gpio
),
413 cf_e355ac_leds_gpio
);
415 ath79_register_gpio_keys_polled(1, CF_EXXXN_KEYS_POLL_INTERVAL
,
416 ARRAY_SIZE(cf_e355ac_gpio_keys
),
417 cf_e355ac_gpio_keys
);
420 MIPS_MACHINE(ATH79_MACH_CF_E355AC
, "CF-E355AC", "COMFAST CF-E355AC",
423 static void __init
cf_e380ac_v1v2_common_setup(unsigned long art_ofs
)
425 u8
*mac
= (u8
*) KSEG1ADDR(0x1f000000 + art_ofs
);
427 cf_exxxn_common_setup(art_ofs
, CF_E380AC_V1V2_GPIO_EXT_WDT
);
429 ath79_setup_qca955x_eth_cfg(QCA955X_ETH_CFG_RGMII_EN
);
431 ath79_register_mdio(0, 0x0);
432 mdiobus_register_board_info(cf_e380ac_v1v2_mdio0_info
,
433 ARRAY_SIZE(cf_e380ac_v1v2_mdio0_info
));
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);
445 ap91_pci_init(mac
+ 0x5000, NULL
);
447 /* Disable JTAG (enables GPIO0-3) */
448 ath79_gpio_function_enable(AR934X_GPIO_FUNC_JTAG_DISABLE
);
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);
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);
459 ath79_gpio_function_disable(AR934X_GPIO_FUNC_CLK_OBS4_EN
);
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
);
466 static void __init
cf_e380ac_v1_setup(void)
468 cf_e380ac_v1v2_common_setup(0x20000);
470 ath79_register_leds_gpio(-1, ARRAY_SIZE(cf_e380ac_v1_leds_gpio
),
471 cf_e380ac_v1_leds_gpio
);
474 MIPS_MACHINE(ATH79_MACH_CF_E380AC_V1
, "CF-E380AC-V1", "COMFAST CF-E380AC v1",
477 static void __init
cf_e380ac_v2_setup(void)
479 cf_e380ac_v1v2_common_setup(0x40000);
481 ath79_register_leds_gpio(-1, ARRAY_SIZE(cf_e380ac_v2_leds_gpio
),
482 cf_e380ac_v2_leds_gpio
);
485 MIPS_MACHINE(ATH79_MACH_CF_E380AC_V2
, "CF-E380AC-V2", "COMFAST CF-E380AC v2",
488 static void __init
cf_e5x0n_gpio_setup(void)
490 ath79_gpio_direction_select(CF_E5X0N_GPIO_LED_WAN
, true);
492 ath79_gpio_output_select(CF_E5X0N_GPIO_LED_WAN
, 0);
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
);
499 static void __init
cf_e520n_setup(void)
501 cf_exxxn_common_setup(0x10000, -1);
503 cf_exxxn_qca953x_eth_setup();
505 cf_e5x0n_gpio_setup();
507 ath79_register_leds_gpio(-1, ARRAY_SIZE(cf_e520n_leds_gpio
),
511 MIPS_MACHINE(ATH79_MACH_CF_E520N
, "CF-E520N", "COMFAST CF-E520N",
514 static void __init
cf_e530n_setup(void)
516 cf_exxxn_common_setup(0x10000, -1);
518 cf_exxxn_qca953x_eth_setup();
520 cf_e5x0n_gpio_setup();
522 ath79_register_leds_gpio(-1, ARRAY_SIZE(cf_e530n_leds_gpio
),
526 MIPS_MACHINE(ATH79_MACH_CF_E530N
, "CF-E530N", "COMFAST CF-E530N",