2 * Support for COMFAST boards:
3 * - CF-E316N v2 (AR9341)
4 * - CF-E320N v2 (QCA9531)
5 * - CF-E380AC v1/v2 (QCA9558)
6 * - CF-E520N/CF-E530N (QCA9531)
8 * Copyright (C) 2016 Piotr Dymacz <pepe2k@gmail.com>
9 * Copyright (C) 2016 Gareth Parker <gareth41@orcon.net.nz>
10 * Copyright (C) 2015 Paul Fertser <fercerpav@gmail.com>
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License version 2 as published
14 * by the Free Software Foundation.
17 #include <linux/gpio.h>
18 #include <linux/platform_data/phy-at803x.h>
19 #include <linux/platform_device.h>
20 #include <linux/timer.h>
22 #include <asm/mach-ath79/ath79.h>
23 #include <asm/mach-ath79/ar71xx_regs.h>
26 #include "dev-ap9x-pci.h"
28 #include "dev-gpio-buttons.h"
29 #include "dev-leds-gpio.h"
30 #include "dev-m25p80.h"
33 #include "machtypes.h"
35 #define CF_EXXXN_KEYS_POLL_INTERVAL 20
36 #define CF_EXXXN_KEYS_DEBOUNCE_INTERVAL (3 * CF_EXXXN_KEYS_POLL_INTERVAL)
39 #define CF_E316N_V2_GPIO_LED_DIAG_B 0
40 #define CF_E316N_V2_GPIO_LED_DIAG_R 2
41 #define CF_E316N_V2_GPIO_LED_DIAG_G 3
42 #define CF_E316N_V2_GPIO_LED_WLAN 12
43 #define CF_E316N_V2_GPIO_LED_WAN 17
44 #define CF_E316N_V2_GPIO_LED_LAN 19
46 #define CF_E316N_V2_GPIO_EXT_WDT 16
48 #define CF_E316N_V2_GPIO_EXTERNAL_PA0 13
49 #define CF_E316N_V2_GPIO_EXTERNAL_PA1 14
51 #define CF_E316N_V2_GPIO_BTN_RESET 20
53 static struct gpio_led cf_e316n_v2_leds_gpio
[] __initdata
= {
55 .name
= "cf-e316n-v2:blue:diag",
56 .gpio
= CF_E316N_V2_GPIO_LED_DIAG_B
,
59 .name
= "cf-e316n-v2:red:diag",
60 .gpio
= CF_E316N_V2_GPIO_LED_DIAG_R
,
63 .name
= "cf-e316n-v2:green:diag",
64 .gpio
= CF_E316N_V2_GPIO_LED_DIAG_G
,
67 .name
= "cf-e316n-v2:blue:wlan",
68 .gpio
= CF_E316N_V2_GPIO_LED_WLAN
,
71 .name
= "cf-e316n-v2:blue:wan",
72 .gpio
= CF_E316N_V2_GPIO_LED_WAN
,
75 .name
= "cf-e316n-v2:blue:lan",
76 .gpio
= CF_E316N_V2_GPIO_LED_LAN
,
81 static struct gpio_keys_button cf_e316n_v2_gpio_keys
[] __initdata
= {
86 .debounce_interval
= CF_EXXXN_KEYS_DEBOUNCE_INTERVAL
,
87 .gpio
= CF_E316N_V2_GPIO_BTN_RESET
,
93 #define CF_E320N_V2_GPIO_LED_WLAN 0
94 #define CF_E320N_V2_GPIO_LED_WAN 2
95 #define CF_E320N_V2_GPIO_LED_LAN 3
97 #define CF_E320N_V2_GPIO_HEADER_J9_1 14
98 #define CF_E320N_V2_GPIO_HEADER_J9_2 12
99 #define CF_E320N_V2_GPIO_HEADER_J9_3 11
100 #define CF_E320N_V2_GPIO_HEADER_J9_4 16
102 #define CF_E320N_V2_GPIO_EXT_WDT 13
104 #define CF_E320N_V2_GPIO_BTN_RESET 17
106 static struct gpio_led cf_e320n_v2_leds_gpio
[] __initdata
= {
108 .name
= "cf-e320n-v2:green:lan",
109 .gpio
= CF_E320N_V2_GPIO_LED_LAN
,
112 .name
= "cf-e320n-v2:red:wan",
113 .gpio
= CF_E320N_V2_GPIO_LED_WAN
,
116 .name
= "cf-e320n-v2:blue:wlan",
117 .gpio
= CF_E320N_V2_GPIO_LED_WLAN
,
122 static struct gpio_keys_button cf_e320n_v2_gpio_keys
[] __initdata
= {
124 .desc
= "Reset button",
127 .debounce_interval
= CF_EXXXN_KEYS_DEBOUNCE_INTERVAL
,
128 .gpio
= CF_E320N_V2_GPIO_BTN_RESET
,
133 /* CF-E380AC v1/v2 */
134 #define CF_E380AC_V1V2_GPIO_LED_LAN 0
135 #define CF_E380AC_V1V2_GPIO_LED_WLAN2G 2
136 #define CF_E380AC_V1V2_GPIO_LED_WLAN5G 3
138 #define CF_E380AC_V1V2_GPIO_EXT_WDT 17
140 #define CF_E380AC_V1V2_GPIO_BTN_RESET 19
142 static struct gpio_led cf_e380ac_v1_leds_gpio
[] __initdata
= {
144 .name
= "cf-e380ac-v1:green:lan",
145 .gpio
= CF_E380AC_V1V2_GPIO_LED_LAN
,
148 .name
= "cf-e380ac-v1:blue:wlan2g",
149 .gpio
= CF_E380AC_V1V2_GPIO_LED_WLAN2G
,
152 .name
= "cf-e380ac-v1:red:wlan5g",
153 .gpio
= CF_E380AC_V1V2_GPIO_LED_WLAN5G
,
158 static struct gpio_led cf_e380ac_v2_leds_gpio
[] __initdata
= {
160 .name
= "cf-e380ac-v2:green:lan",
161 .gpio
= CF_E380AC_V1V2_GPIO_LED_LAN
,
164 .name
= "cf-e380ac-v2:blue:wlan2g",
165 .gpio
= CF_E380AC_V1V2_GPIO_LED_WLAN2G
,
168 .name
= "cf-e380ac-v2:red:wlan5g",
169 .gpio
= CF_E380AC_V1V2_GPIO_LED_WLAN5G
,
174 static struct gpio_keys_button cf_e380ac_v1v2_gpio_keys
[] __initdata
= {
176 .desc
= "Reset button",
179 .debounce_interval
= CF_EXXXN_KEYS_DEBOUNCE_INTERVAL
,
180 .gpio
= CF_E380AC_V1V2_GPIO_BTN_RESET
,
185 static struct at803x_platform_data cf_e380ac_v1v2_at803x_data
= {
186 .disable_smarteee
= 1,
189 static struct mdio_board_info cf_e380ac_v1v2_mdio0_info
[] = {
191 .bus_id
= "ag71xx-mdio.0",
193 .platform_data
= &cf_e380ac_v1v2_at803x_data
,
197 /* CF-E520N/CF-E530N */
198 #define CF_E5X0N_GPIO_LED_WAN 11
199 #define CF_E5X0N_GPIO_BTN_RESET 17
201 static struct gpio_led cf_e520n_leds_gpio
[] __initdata
= {
203 .name
= "cf-e520n:blue:wan",
204 .gpio
= CF_E5X0N_GPIO_LED_WAN
,
209 static struct gpio_led cf_e530n_leds_gpio
[] __initdata
= {
211 .name
= "cf-e530n:blue:wan",
212 .gpio
= CF_E5X0N_GPIO_LED_WAN
,
218 * Some COMFAST devices include external hardware watchdog chip,
219 * Pericon Technology PT7A7514, connected to a selected GPIO
220 * and WiSoC RESET_L input. Watchdog time-out is ~1.6 s.
222 #define CF_EXXXN_EXT_WDT_TIMEOUT_MS 500
224 static struct timer_list gpio_wdt_timer
;
226 static void gpio_wdt_toggle(unsigned long gpio
)
231 gpio_set_value(gpio
, state
);
233 mod_timer(&gpio_wdt_timer
,
234 jiffies
+ msecs_to_jiffies(CF_EXXXN_EXT_WDT_TIMEOUT_MS
));
237 static void __init
cf_exxxn_common_setup(unsigned long art_ofs
, int gpio_wdt
)
239 u8
*art
= (u8
*) KSEG1ADDR(0x1f001000 + art_ofs
);
242 gpio_request_one(gpio_wdt
, GPIOF_OUT_INIT_HIGH
,
243 "PT7A7514 watchdog");
245 setup_timer(&gpio_wdt_timer
, gpio_wdt_toggle
, gpio_wdt
);
246 gpio_wdt_toggle(gpio_wdt
);
249 ath79_register_m25p80(NULL
);
251 ath79_register_wmac(art
, NULL
);
253 ath79_register_usb();
256 static void __init
cf_e316n_v2_setup(void)
258 u8
*mac
= (u8
*) KSEG1ADDR(0x1f010000);
260 cf_exxxn_common_setup(0x10000, CF_E316N_V2_GPIO_EXT_WDT
);
262 ath79_setup_ar934x_eth_cfg(AR934X_ETH_CFG_SW_PHY_SWAP
);
264 ath79_register_mdio(1, 0x0);
266 /* GMAC0 is connected to the PHY0 of the internal switch */
267 ath79_switch_data
.phy4_mii_en
= 1;
268 ath79_switch_data
.phy_poll_mask
= BIT(0);
269 ath79_eth0_data
.phy_if_mode
= PHY_INTERFACE_MODE_MII
;
270 ath79_eth0_data
.phy_mask
= BIT(0);
271 ath79_eth0_data
.mii_bus_dev
= &ath79_mdio1_device
.dev
;
272 ath79_init_mac(ath79_eth0_data
.mac_addr
, mac
, 0);
273 ath79_register_eth(0);
275 /* GMAC1 is connected to the internal switch */
276 ath79_eth1_data
.phy_if_mode
= PHY_INTERFACE_MODE_GMII
;
277 ath79_init_mac(ath79_eth1_data
.mac_addr
, mac
, 2);
278 ath79_register_eth(1);
280 /* Enable 2x Skyworks SE2576L WLAN power amplifiers */
281 gpio_request_one(CF_E316N_V2_GPIO_EXTERNAL_PA0
, GPIOF_OUT_INIT_HIGH
,
283 gpio_request_one(CF_E316N_V2_GPIO_EXTERNAL_PA1
, GPIOF_OUT_INIT_HIGH
,
286 ath79_register_leds_gpio(-1, ARRAY_SIZE(cf_e316n_v2_leds_gpio
),
287 cf_e316n_v2_leds_gpio
);
289 ath79_register_gpio_keys_polled(1, CF_EXXXN_KEYS_POLL_INTERVAL
,
290 ARRAY_SIZE(cf_e316n_v2_gpio_keys
),
291 cf_e316n_v2_gpio_keys
);
294 MIPS_MACHINE(ATH79_MACH_CF_E316N_V2
, "CF-E316N-V2", "COMFAST CF-E316N v2",
297 static void __init
cf_exxxn_qca953x_eth_setup(void)
299 u8
*mac
= (u8
*) KSEG1ADDR(0x1f010000);
301 ath79_setup_ar933x_phy4_switch(false, false);
303 ath79_register_mdio(0, 0x0);
305 ath79_switch_data
.phy4_mii_en
= 1;
306 ath79_switch_data
.phy_poll_mask
|= BIT(4);
309 ath79_eth1_data
.duplex
= DUPLEX_FULL
;
310 ath79_eth1_data
.phy_if_mode
= PHY_INTERFACE_MODE_GMII
;
311 ath79_eth1_data
.speed
= SPEED_1000
;
312 ath79_init_mac(ath79_eth1_data
.mac_addr
, mac
, 2);
313 ath79_register_eth(1);
316 ath79_eth0_data
.duplex
= DUPLEX_FULL
;
317 ath79_eth0_data
.phy_if_mode
= PHY_INTERFACE_MODE_MII
;
318 ath79_eth0_data
.speed
= SPEED_100
;
319 ath79_eth0_data
.phy_mask
= BIT(4);
320 ath79_init_mac(ath79_eth0_data
.mac_addr
, mac
, 0);
321 ath79_register_eth(0);
324 static void __init
cf_e320n_v2_setup(void)
326 cf_exxxn_common_setup(0x10000, CF_E320N_V2_GPIO_EXT_WDT
);
328 cf_exxxn_qca953x_eth_setup();
330 /* Disable JTAG (enables GPIO0-3) */
331 ath79_gpio_function_enable(AR934X_GPIO_FUNC_JTAG_DISABLE
);
333 ath79_gpio_direction_select(CF_E320N_V2_GPIO_LED_LAN
, true);
334 ath79_gpio_direction_select(CF_E320N_V2_GPIO_LED_WAN
, true);
335 ath79_gpio_direction_select(CF_E320N_V2_GPIO_LED_WLAN
, true);
337 ath79_gpio_output_select(CF_E320N_V2_GPIO_LED_LAN
, 0);
338 ath79_gpio_output_select(CF_E320N_V2_GPIO_LED_WAN
, 0);
339 ath79_gpio_output_select(CF_E320N_V2_GPIO_LED_WLAN
, 0);
341 /* Enable GPIO function for GPIOs in J9 header */
342 ath79_gpio_output_select(CF_E320N_V2_GPIO_HEADER_J9_1
, 0);
343 ath79_gpio_output_select(CF_E320N_V2_GPIO_HEADER_J9_2
, 0);
344 ath79_gpio_output_select(CF_E320N_V2_GPIO_HEADER_J9_3
, 0);
345 ath79_gpio_output_select(CF_E320N_V2_GPIO_HEADER_J9_4
, 0);
347 ath79_register_leds_gpio(-1, ARRAY_SIZE(cf_e320n_v2_leds_gpio
),
348 cf_e320n_v2_leds_gpio
);
350 ath79_register_gpio_keys_polled(-1, CF_EXXXN_KEYS_POLL_INTERVAL
,
351 ARRAY_SIZE(cf_e320n_v2_gpio_keys
),
352 cf_e320n_v2_gpio_keys
);
355 MIPS_MACHINE(ATH79_MACH_CF_E320N_V2
, "CF-E320N-V2", "COMFAST CF-E320N v2",
358 static void __init
cf_e380ac_v1v2_common_setup(unsigned long art_ofs
)
360 u8
*mac
= (u8
*) KSEG1ADDR(0x1f000000 + art_ofs
);
362 cf_exxxn_common_setup(art_ofs
, CF_E380AC_V1V2_GPIO_EXT_WDT
);
364 ath79_setup_qca955x_eth_cfg(QCA955X_ETH_CFG_RGMII_EN
);
366 ath79_register_mdio(0, 0x0);
367 mdiobus_register_board_info(cf_e380ac_v1v2_mdio0_info
,
368 ARRAY_SIZE(cf_e380ac_v1v2_mdio0_info
));
371 ath79_eth0_data
.mii_bus_dev
= &ath79_mdio0_device
.dev
;
372 ath79_eth0_data
.phy_if_mode
= PHY_INTERFACE_MODE_RGMII
;
373 ath79_eth0_data
.phy_mask
= BIT(0);
374 ath79_eth0_pll_data
.pll_1000
= 0xbe000000;
375 ath79_eth0_pll_data
.pll_100
= 0xb0000101;
376 ath79_eth0_pll_data
.pll_10
= 0xb0001313;
377 ath79_init_mac(ath79_eth0_data
.mac_addr
, mac
, 0);
378 ath79_register_eth(0);
380 ap91_pci_init(mac
+ 0x5000, NULL
);
382 /* Disable JTAG (enables GPIO0-3) */
383 ath79_gpio_function_enable(AR934X_GPIO_FUNC_JTAG_DISABLE
);
385 ath79_gpio_direction_select(CF_E380AC_V1V2_GPIO_LED_LAN
, true);
386 ath79_gpio_direction_select(CF_E380AC_V1V2_GPIO_LED_WLAN2G
, true);
387 ath79_gpio_direction_select(CF_E380AC_V1V2_GPIO_LED_WLAN5G
, true);
389 ath79_gpio_output_select(CF_E380AC_V1V2_GPIO_LED_LAN
, 0);
390 ath79_gpio_output_select(CF_E380AC_V1V2_GPIO_LED_WLAN2G
, 0);
391 ath79_gpio_output_select(CF_E380AC_V1V2_GPIO_LED_WLAN5G
, 0);
394 ath79_gpio_function_disable(AR934X_GPIO_FUNC_CLK_OBS4_EN
);
396 ath79_register_gpio_keys_polled(-1, CF_EXXXN_KEYS_POLL_INTERVAL
,
397 ARRAY_SIZE(cf_e380ac_v1v2_gpio_keys
),
398 cf_e380ac_v1v2_gpio_keys
);
401 static void __init
cf_e380ac_v1_setup(void)
403 cf_e380ac_v1v2_common_setup(0x20000);
405 ath79_register_leds_gpio(-1, ARRAY_SIZE(cf_e380ac_v1_leds_gpio
),
406 cf_e380ac_v1_leds_gpio
);
409 MIPS_MACHINE(ATH79_MACH_CF_E380AC_V1
, "CF-E380AC-V1", "COMFAST CF-E380AC v1",
412 static void __init
cf_e380ac_v2_setup(void)
414 cf_e380ac_v1v2_common_setup(0x40000);
416 ath79_register_leds_gpio(-1, ARRAY_SIZE(cf_e380ac_v2_leds_gpio
),
417 cf_e380ac_v2_leds_gpio
);
420 MIPS_MACHINE(ATH79_MACH_CF_E380AC_V2
, "CF-E380AC-V2", "COMFAST CF-E380AC v2",
423 static void __init
cf_e5x0n_gpio_setup(void)
425 ath79_gpio_direction_select(CF_E5X0N_GPIO_LED_WAN
, true);
427 ath79_gpio_output_select(CF_E5X0N_GPIO_LED_WAN
, 0);
429 ath79_register_gpio_keys_polled(-1, CF_EXXXN_KEYS_POLL_INTERVAL
,
430 ARRAY_SIZE(cf_e320n_v2_gpio_keys
),
431 cf_e320n_v2_gpio_keys
);
434 static void __init
cf_e520n_setup(void)
436 cf_exxxn_common_setup(0x10000, -1);
438 cf_exxxn_qca953x_eth_setup();
440 cf_e5x0n_gpio_setup();
442 ath79_register_leds_gpio(-1, ARRAY_SIZE(cf_e520n_leds_gpio
),
446 MIPS_MACHINE(ATH79_MACH_CF_E520N
, "CF-E520N", "COMFAST CF-E520N",
449 static void __init
cf_e530n_setup(void)
451 cf_exxxn_common_setup(0x10000, -1);
453 cf_exxxn_qca953x_eth_setup();
455 cf_e5x0n_gpio_setup();
457 ath79_register_leds_gpio(-1, ARRAY_SIZE(cf_e530n_leds_gpio
),
461 MIPS_MACHINE(ATH79_MACH_CF_E530N
, "CF-E530N", "COMFAST CF-E530N",