ar71xx: wpj531: fix SIG1/RSS1 LED GPIO
[oweals/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 v1 (QCA9531 + QCA9882)
6  *  - CF-E355AC v2 (QCA9531 + QCA9886)
7  *  - CF-E375AC (QCA9563 + QCA9886 + QCA8337)
8  *  - CF-E380AC v1/v2 (QCA9558)
9  *  - CF-E385AC (QCA9558 + QCA9984 + QCA8337)
10  *  - CF-E520N/CF-E530N (QCA9531)
11  *
12  *  Copyright (C) 2016 Piotr Dymacz <pepe2k@gmail.com>
13  *  Copyright (C) 2016 Gareth Parker <gareth41@orcon.net.nz>
14  *  Copyright (C) 2015 Paul Fertser <fercerpav@gmail.com>
15  *
16  *  This program is free software; you can redistribute it and/or modify it
17  *  under the terms of the GNU General Public License version 2 as published
18  *  by the Free Software Foundation.
19  */
20
21 #include <linux/gpio.h>
22 #include <linux/ar8216_platform.h>
23 #include <linux/platform_data/phy-at803x.h>
24 #include <linux/platform_device.h>
25 #include <linux/timer.h>
26
27 #include <asm/mach-ath79/ath79.h>
28 #include <asm/mach-ath79/ar71xx_regs.h>
29
30 #include "common.h"
31 #include "dev-ap9x-pci.h"
32 #include "dev-eth.h"
33 #include "dev-gpio-buttons.h"
34 #include "dev-leds-gpio.h"
35 #include "dev-m25p80.h"
36 #include "dev-wmac.h"
37 #include "dev-usb.h"
38 #include "machtypes.h"
39 #include "pci.h"
40
41 #define CF_EXXXN_KEYS_POLL_INTERVAL     20
42 #define CF_EXXXN_KEYS_DEBOUNCE_INTERVAL (3 * CF_EXXXN_KEYS_POLL_INTERVAL)
43
44 /* CF-E316N v2 */
45 #define CF_E316N_V2_GPIO_LED_DIAG_B     0
46 #define CF_E316N_V2_GPIO_LED_DIAG_R     2
47 #define CF_E316N_V2_GPIO_LED_DIAG_G     3
48 #define CF_E316N_V2_GPIO_LED_WLAN       12
49 #define CF_E316N_V2_GPIO_LED_WAN        17
50 #define CF_E316N_V2_GPIO_LED_LAN        19
51
52 #define CF_E316N_V2_GPIO_EXT_WDT        16
53
54 #define CF_E316N_V2_GPIO_EXTERNAL_PA0   13
55 #define CF_E316N_V2_GPIO_EXTERNAL_PA1   14
56
57 #define CF_E316N_V2_GPIO_BTN_RESET      20
58
59 static struct gpio_led cf_e316n_v2_leds_gpio[] __initdata = {
60         {
61                 .name           = "cf-e316n-v2:blue:diag",
62                 .gpio           = CF_E316N_V2_GPIO_LED_DIAG_B,
63                 .active_low     = 0,
64         }, {
65                 .name           = "cf-e316n-v2:red:diag",
66                 .gpio           = CF_E316N_V2_GPIO_LED_DIAG_R,
67                 .active_low     = 0,
68         }, {
69                 .name           = "cf-e316n-v2:green:diag",
70                 .gpio           = CF_E316N_V2_GPIO_LED_DIAG_G,
71                 .active_low     = 0,
72         }, {
73                 .name           = "cf-e316n-v2:blue:wlan",
74                 .gpio           = CF_E316N_V2_GPIO_LED_WLAN,
75                 .active_low     = 1,
76         }, {
77                 .name           = "cf-e316n-v2:blue:wan",
78                 .gpio           = CF_E316N_V2_GPIO_LED_WAN,
79                 .active_low     = 1,
80         }, {
81                 .name           = "cf-e316n-v2:blue:lan",
82                 .gpio           = CF_E316N_V2_GPIO_LED_LAN,
83                 .active_low     = 1,
84         },
85 };
86
87 static struct gpio_keys_button cf_e316n_v2_gpio_keys[] __initdata = {
88         {
89                 .desc           = "reset",
90                 .type           = EV_KEY,
91                 .code           = KEY_RESTART,
92                 .debounce_interval = CF_EXXXN_KEYS_DEBOUNCE_INTERVAL,
93                 .gpio           = CF_E316N_V2_GPIO_BTN_RESET,
94                 .active_low     = 1,
95         },
96 };
97
98 /* CF-E320N v2 */
99 #define CF_E320N_V2_GPIO_LED_WLAN       0
100 #define CF_E320N_V2_GPIO_LED_WAN        2
101 #define CF_E320N_V2_GPIO_LED_LAN        3
102
103 #define CF_E320N_V2_GPIO_HEADER_J9_1    14
104 #define CF_E320N_V2_GPIO_HEADER_J9_2    12
105 #define CF_E320N_V2_GPIO_HEADER_J9_3    11
106 #define CF_E320N_V2_GPIO_HEADER_J9_4    16
107
108 #define CF_E320N_V2_GPIO_EXT_WDT        13
109
110 #define CF_E320N_V2_GPIO_BTN_RESET      17
111
112 static struct gpio_led cf_e320n_v2_leds_gpio[] __initdata = {
113         {
114                 .name           = "cf-e320n-v2:green:lan",
115                 .gpio           = CF_E320N_V2_GPIO_LED_LAN,
116                 .active_low     = 0,
117         }, {
118                 .name           = "cf-e320n-v2:red:wan",
119                 .gpio           = CF_E320N_V2_GPIO_LED_WAN,
120                 .active_low     = 0,
121         }, {
122                 .name           = "cf-e320n-v2:blue:wlan",
123                 .gpio           = CF_E320N_V2_GPIO_LED_WLAN,
124                 .active_low     = 0,
125         },
126 };
127
128 static struct gpio_keys_button cf_e320n_v2_gpio_keys[] __initdata = {
129         {
130                 .desc           = "Reset button",
131                 .type           = EV_KEY,
132                 .code           = KEY_RESTART,
133                 .debounce_interval = CF_EXXXN_KEYS_DEBOUNCE_INTERVAL,
134                 .gpio           = CF_E320N_V2_GPIO_BTN_RESET,
135                 .active_low     = 1,
136         },
137 };
138
139 /* CF-E355AC v1/v2 */
140 #define CF_E355AC_GPIO_LED_LAN          3
141 #define CF_E355AC_GPIO_LED_WLAN2G       0
142 #define CF_E355AC_GPIO_LED_WLAN5G       2
143
144 #define CF_E355AC_GPIO_EXT_WDT          13
145
146 #define CF_E355AC_GPIO_BTN_RESET        17
147
148 static struct gpio_led cf_e355ac_v1_leds_gpio[] __initdata = {
149         {
150                 .name           = "cf-e355ac-v1:green:lan",
151                 .gpio           = CF_E355AC_GPIO_LED_LAN,
152                 .active_low     = 0,
153         }, {
154                 .name           = "cf-e355ac-v1:blue:wlan2g",
155                 .gpio           = CF_E355AC_GPIO_LED_WLAN2G,
156                 .active_low     = 0,
157         }, {
158                 .name           = "cf-e355ac-v1:red:wlan5g",
159                 .gpio           = CF_E355AC_GPIO_LED_WLAN5G,
160                 .active_low     = 0,
161         },
162 };
163
164 static struct gpio_led cf_e355ac_v2_leds_gpio[] __initdata = {
165         {
166                 .name           = "cf-e355ac-v2:green:lan",
167                 .gpio           = CF_E355AC_GPIO_LED_LAN,
168                 .active_low     = 0,
169         }, {
170                 .name           = "cf-e355ac-v2:blue:wlan2g",
171                 .gpio           = CF_E355AC_GPIO_LED_WLAN2G,
172                 .active_low     = 0,
173         }, {
174                 .name           = "cf-e355ac-v2:red:wlan5g",
175                 .gpio           = CF_E355AC_GPIO_LED_WLAN5G,
176                 .active_low     = 0,
177         },
178 };
179
180 static struct gpio_keys_button cf_e355ac_gpio_keys[] __initdata = {
181         {
182                 .desc           = "Reset button",
183                 .type           = EV_KEY,
184                 .code           = KEY_RESTART,
185                 .debounce_interval = CF_EXXXN_KEYS_DEBOUNCE_INTERVAL,
186                 .gpio           = CF_E355AC_GPIO_BTN_RESET,
187                 .active_low     = 1,
188         },
189 };
190
191 /* CF-E375AC */
192 #define CF_E375AC_GPIO_LED_LAN          17
193 #define CF_E375AC_GPIO_LED_WLAN2G       16
194 #define CF_E375AC_GPIO_LED_WLAN5G       15
195
196 #define CF_E375AC_GPIO_EXT_WDT          6
197
198 #define CF_E375AC_GPIO_BTN_RESET        2
199
200 static struct gpio_led cf_e375ac_leds_gpio[] __initdata = {
201         {
202                 .name           = "cf-e375ac:green:lan",
203                 .gpio           = CF_E375AC_GPIO_LED_LAN,
204                 .active_low     = 0,
205         }, {
206                 .name           = "cf-e375ac:red:wlan5g",
207                 .gpio           = CF_E375AC_GPIO_LED_WLAN5G,
208                 .active_low     = 0,
209         }, {
210                 .name           = "cf-e375ac:blue:wlan2g",
211                 .gpio           = CF_E375AC_GPIO_LED_WLAN2G,
212                 .active_low     = 0,
213         },
214 };
215
216 static struct gpio_keys_button cf_e375ac_gpio_keys[] __initdata = {
217         {
218                 .desc           = "Reset button",
219                 .type           = EV_KEY,
220                 .code           = KEY_RESTART,
221                 .debounce_interval = CF_EXXXN_KEYS_DEBOUNCE_INTERVAL,
222                 .gpio           = CF_E375AC_GPIO_BTN_RESET,
223                 .active_low     = 1,
224         },
225 };
226
227 static struct ar8327_pad_cfg cf_e375ac_ar8337_pad0_cfg = {
228         .mode = AR8327_PAD_MAC_SGMII,
229         .sgmii_delay_en = true,
230 };
231
232 static struct ar8327_platform_data cf_e375ac_ar8337_data = {
233         .pad0_cfg = &cf_e375ac_ar8337_pad0_cfg,
234         .port0_cfg = {
235                 .force_link = 1,
236                 .speed = AR8327_PORT_SPEED_1000,
237                 .duplex = 1,
238                 .txpause = 1,
239                 .rxpause = 1,
240         },
241 };
242
243 static struct mdio_board_info cf_e375ac_mdio0_info[] = {
244         {
245                 .bus_id = "ag71xx-mdio.0",
246                 .mdio_addr = 0,
247                 .platform_data = &cf_e375ac_ar8337_data,
248         },
249 };
250
251 /* CF-E380AC v1/v2, CF-E385AC */
252 #define CF_E38XAC_GPIO_LED_LAN          0
253 #define CF_E38XAC_GPIO_LED_WLAN2G       2
254 #define CF_E38XAC_GPIO_LED_WLAN5G       3
255
256 #define CF_E38XAC_GPIO_EXT_WDT          17
257
258 #define CF_E38XAC_GPIO_BTN_RESET        19
259
260 static struct gpio_led cf_e380ac_v1_leds_gpio[] __initdata = {
261         {
262                 .name           = "cf-e380ac-v1:green:lan",
263                 .gpio           = CF_E38XAC_GPIO_LED_LAN,
264                 .active_low     = 0,
265         }, {
266                 .name           = "cf-e380ac-v1:blue:wlan2g",
267                 .gpio           = CF_E38XAC_GPIO_LED_WLAN2G,
268                 .active_low     = 0,
269         }, {
270                 .name           = "cf-e380ac-v1:red:wlan5g",
271                 .gpio           = CF_E38XAC_GPIO_LED_WLAN5G,
272                 .active_low     = 0,
273         },
274 };
275
276 static struct gpio_led cf_e380ac_v2_leds_gpio[] __initdata = {
277         {
278                 .name           = "cf-e380ac-v2:green:lan",
279                 .gpio           = CF_E38XAC_GPIO_LED_LAN,
280                 .active_low     = 0,
281         }, {
282                 .name           = "cf-e380ac-v2:blue:wlan2g",
283                 .gpio           = CF_E38XAC_GPIO_LED_WLAN2G,
284                 .active_low     = 0,
285         }, {
286                 .name           = "cf-e380ac-v2:red:wlan5g",
287                 .gpio           = CF_E38XAC_GPIO_LED_WLAN5G,
288                 .active_low     = 0,
289         },
290 };
291
292 static struct gpio_led cf_e385ac_leds_gpio[] __initdata = {
293         {
294                 .name           = "cf-e385ac:green:lan",
295                 .gpio           = CF_E38XAC_GPIO_LED_LAN,
296                 .active_low     = 0,
297         }, {
298                 .name           = "cf-e385ac:blue:wlan2g",
299                 .gpio           = CF_E38XAC_GPIO_LED_WLAN2G,
300                 .active_low     = 0,
301         }, {
302                 .name           = "cf-e385ac:red:wlan5g",
303                 .gpio           = CF_E38XAC_GPIO_LED_WLAN5G,
304                 .active_low     = 0,
305         },
306 };
307
308 static struct gpio_keys_button cf_e38xac_gpio_keys[] __initdata = {
309         {
310                 .desc           = "Reset button",
311                 .type           = EV_KEY,
312                 .code           = KEY_RESTART,
313                 .debounce_interval = CF_EXXXN_KEYS_DEBOUNCE_INTERVAL,
314                 .gpio           = CF_E38XAC_GPIO_BTN_RESET,
315                 .active_low     = 1,
316         },
317 };
318
319 static struct at803x_platform_data cf_e380ac_v1v2_at803x_data = {
320         .disable_smarteee = 1,
321 };
322
323 static struct mdio_board_info cf_e380ac_v1v2_mdio0_info[] = {
324         {
325                 .bus_id = "ag71xx-mdio.0",
326                 .mdio_addr = 0,
327                 .platform_data = &cf_e380ac_v1v2_at803x_data,
328         },
329 };
330
331 /* CF-E520N/CF-E530N */
332 #define CF_E5X0N_GPIO_LED_WAN           11
333 #define CF_E5X0N_GPIO_BTN_RESET         17
334
335 static struct gpio_led cf_e520n_leds_gpio[] __initdata = {
336         {
337                 .name           = "cf-e520n:blue:wan",
338                 .gpio           = CF_E5X0N_GPIO_LED_WAN,
339                 .active_low     = 1,
340         }
341 };
342
343 static struct gpio_led cf_e530n_leds_gpio[] __initdata = {
344         {
345                 .name           = "cf-e530n:blue:wan",
346                 .gpio           = CF_E5X0N_GPIO_LED_WAN,
347                 .active_low     = 1,
348         }
349 };
350
351 /*
352  * Some COMFAST devices include external hardware watchdog chip,
353  * Pericon Technology PT7A7514, connected to a selected GPIO
354  * and WiSoC RESET_L input. Watchdog time-out is ~1.6 s.
355  */
356 #define CF_EXXXN_EXT_WDT_TIMEOUT_MS     500
357
358 static struct timer_list gpio_wdt_timer;
359
360 static void gpio_wdt_toggle(unsigned long gpio)
361 {
362         static int state;
363
364         state = !state;
365         gpio_set_value(gpio, state);
366
367         mod_timer(&gpio_wdt_timer,
368                   jiffies + msecs_to_jiffies(CF_EXXXN_EXT_WDT_TIMEOUT_MS));
369 }
370
371 static void __init cf_exxxn_common_setup(unsigned long art_ofs, int gpio_wdt)
372 {
373         u8 *art = (u8 *) KSEG1ADDR(0x1f001000 + art_ofs);
374
375         if (gpio_wdt > -1) {
376                 gpio_request_one(gpio_wdt, GPIOF_OUT_INIT_HIGH,
377                                  "PT7A7514 watchdog");
378
379                 setup_timer(&gpio_wdt_timer, gpio_wdt_toggle, gpio_wdt);
380                 gpio_wdt_toggle(gpio_wdt);
381         }
382
383         ath79_register_m25p80(NULL);
384
385         ath79_register_wmac(art, NULL);
386
387         ath79_register_usb();
388 }
389
390 static void __init cf_e316n_v2_setup(void)
391 {
392         u8 *mac = (u8 *) KSEG1ADDR(0x1f010000);
393
394         cf_exxxn_common_setup(0x10000, CF_E316N_V2_GPIO_EXT_WDT);
395
396         ath79_setup_ar934x_eth_cfg(AR934X_ETH_CFG_SW_PHY_SWAP);
397
398         ath79_register_mdio(1, 0x0);
399
400         /* GMAC0 is connected to the PHY0 of the internal switch */
401         ath79_switch_data.phy4_mii_en = 1;
402         ath79_switch_data.phy_poll_mask = BIT(0);
403         ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
404         ath79_eth0_data.phy_mask = BIT(0);
405         ath79_eth0_data.mii_bus_dev = &ath79_mdio1_device.dev;
406         ath79_init_mac(ath79_eth0_data.mac_addr, mac, 0);
407         ath79_register_eth(0);
408
409         /* GMAC1 is connected to the internal switch */
410         ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_GMII;
411         ath79_init_mac(ath79_eth1_data.mac_addr, mac, 2);
412         ath79_register_eth(1);
413
414         /* Enable 2x Skyworks SE2576L WLAN power amplifiers */
415         gpio_request_one(CF_E316N_V2_GPIO_EXTERNAL_PA0, GPIOF_OUT_INIT_HIGH,
416                          "WLAN PA0");
417         gpio_request_one(CF_E316N_V2_GPIO_EXTERNAL_PA1, GPIOF_OUT_INIT_HIGH,
418                          "WLAN PA1");
419
420         ath79_register_leds_gpio(-1, ARRAY_SIZE(cf_e316n_v2_leds_gpio),
421                                  cf_e316n_v2_leds_gpio);
422
423         ath79_register_gpio_keys_polled(1, CF_EXXXN_KEYS_POLL_INTERVAL,
424                                         ARRAY_SIZE(cf_e316n_v2_gpio_keys),
425                                         cf_e316n_v2_gpio_keys);
426 }
427
428 MIPS_MACHINE(ATH79_MACH_CF_E316N_V2, "CF-E316N-V2", "COMFAST CF-E316N v2",
429              cf_e316n_v2_setup);
430
431 static void __init cf_exxxn_qca953x_eth_setup(void)
432 {
433         u8 *mac = (u8 *) KSEG1ADDR(0x1f010000);
434
435         ath79_setup_ar933x_phy4_switch(false, false);
436
437         ath79_register_mdio(0, 0x0);
438
439         ath79_switch_data.phy4_mii_en = 1;
440         ath79_switch_data.phy_poll_mask |= BIT(4);
441
442         /* LAN */
443         ath79_eth1_data.duplex = DUPLEX_FULL;
444         ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_GMII;
445         ath79_eth1_data.speed = SPEED_1000;
446         ath79_init_mac(ath79_eth1_data.mac_addr, mac, 2);
447         ath79_register_eth(1);
448
449         /* WAN */
450         ath79_eth0_data.duplex = DUPLEX_FULL;
451         ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
452         ath79_eth0_data.speed = SPEED_100;
453         ath79_eth0_data.phy_mask = BIT(4);
454         ath79_init_mac(ath79_eth0_data.mac_addr, mac, 0);
455         ath79_register_eth(0);
456 }
457
458 static void __init cf_e320n_v2_setup(void)
459 {
460         cf_exxxn_common_setup(0x10000, CF_E320N_V2_GPIO_EXT_WDT);
461
462         cf_exxxn_qca953x_eth_setup();
463
464         /* Disable JTAG (enables GPIO0-3) */
465         ath79_gpio_function_enable(AR934X_GPIO_FUNC_JTAG_DISABLE);
466
467         ath79_gpio_direction_select(CF_E320N_V2_GPIO_LED_LAN, true);
468         ath79_gpio_direction_select(CF_E320N_V2_GPIO_LED_WAN, true);
469         ath79_gpio_direction_select(CF_E320N_V2_GPIO_LED_WLAN, true);
470
471         ath79_gpio_output_select(CF_E320N_V2_GPIO_LED_LAN, 0);
472         ath79_gpio_output_select(CF_E320N_V2_GPIO_LED_WAN, 0);
473         ath79_gpio_output_select(CF_E320N_V2_GPIO_LED_WLAN, 0);
474
475         /* Enable GPIO function for GPIOs in J9 header */
476         ath79_gpio_output_select(CF_E320N_V2_GPIO_HEADER_J9_1, 0);
477         ath79_gpio_output_select(CF_E320N_V2_GPIO_HEADER_J9_2, 0);
478         ath79_gpio_output_select(CF_E320N_V2_GPIO_HEADER_J9_3, 0);
479         ath79_gpio_output_select(CF_E320N_V2_GPIO_HEADER_J9_4, 0);
480
481         ath79_register_leds_gpio(-1, ARRAY_SIZE(cf_e320n_v2_leds_gpio),
482                                  cf_e320n_v2_leds_gpio);
483
484         ath79_register_gpio_keys_polled(-1, CF_EXXXN_KEYS_POLL_INTERVAL,
485                                         ARRAY_SIZE(cf_e320n_v2_gpio_keys),
486                                         cf_e320n_v2_gpio_keys);
487 }
488
489 MIPS_MACHINE(ATH79_MACH_CF_E320N_V2, "CF-E320N-V2", "COMFAST CF-E320N v2",
490              cf_e320n_v2_setup);
491
492 static void __init cf_e355ac_setup(void)
493 {
494         u8 *art = (u8 *) KSEG1ADDR(0x1f010000);
495
496         /* Disable JTAG, enabling GPIOs 0-3 */
497         ath79_gpio_function_setup(AR934X_GPIO_FUNC_JTAG_DISABLE, 0);
498
499         cf_exxxn_common_setup(0x10000, CF_E355AC_GPIO_EXT_WDT);
500
501         cf_exxxn_qca953x_eth_setup();
502
503         ath79_gpio_output_select(CF_E355AC_GPIO_LED_LAN, 0);
504         ath79_gpio_output_select(CF_E355AC_GPIO_LED_WLAN2G, 0);
505         ath79_gpio_output_select(CF_E355AC_GPIO_LED_WLAN5G, 0);
506
507         ap91_pci_init(art + 0x5000, NULL);
508
509         ath79_register_gpio_keys_polled(1, CF_EXXXN_KEYS_POLL_INTERVAL,
510                                         ARRAY_SIZE(cf_e355ac_gpio_keys),
511                                         cf_e355ac_gpio_keys);
512 }
513
514 static void __init cf_e355ac_v1_setup(void)
515 {
516         cf_e355ac_setup();
517
518         ath79_register_leds_gpio(-1, ARRAY_SIZE(cf_e355ac_v1_leds_gpio),
519                                  cf_e355ac_v1_leds_gpio);
520 }
521
522 static void __init cf_e355ac_v2_setup(void)
523 {
524         cf_e355ac_setup();
525
526         ath79_register_leds_gpio(-1, ARRAY_SIZE(cf_e355ac_v2_leds_gpio),
527                                  cf_e355ac_v2_leds_gpio);
528 }
529
530 MIPS_MACHINE(ATH79_MACH_CF_E355AC, "CF-E355AC-V1", "COMFAST CF-E355AC v1",
531              cf_e355ac_v1_setup);
532
533 MIPS_MACHINE(ATH79_MACH_CF_E355AC_V2, "CF-E355AC-V2", "COMFAST CF-E355AC v2",
534              cf_e355ac_v2_setup);
535
536 static void __init cf_e375ac_setup(void)
537 {
538         u8 *mac = (u8 *) KSEG1ADDR(0x1f040000);
539
540         /* Disable JTAG, enabling GPIOs 0-3 */
541         ath79_gpio_function_setup(AR934X_GPIO_FUNC_JTAG_DISABLE, 0);
542
543         cf_exxxn_common_setup(0x40000, CF_E375AC_GPIO_EXT_WDT);
544
545         ath79_gpio_output_select(CF_E375AC_GPIO_LED_LAN, 0);
546         ath79_gpio_output_select(CF_E375AC_GPIO_LED_WLAN2G, 0);
547         ath79_gpio_output_select(CF_E375AC_GPIO_LED_WLAN5G, 0);
548
549         ath79_register_leds_gpio(-1, ARRAY_SIZE(cf_e375ac_leds_gpio),
550                                  cf_e375ac_leds_gpio);
551
552         ath79_register_gpio_keys_polled(-1, CF_EXXXN_KEYS_POLL_INTERVAL,
553                                         ARRAY_SIZE(cf_e375ac_gpio_keys),
554                                         cf_e375ac_gpio_keys);
555
556         platform_device_register(&ath79_mdio0_device);
557
558         mdiobus_register_board_info(cf_e375ac_mdio0_info,
559                                     ARRAY_SIZE(cf_e375ac_mdio0_info));
560
561         /* GMAC0 is connected to an AR8337 switch */
562         ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_SGMII;
563         ath79_eth0_data.speed = SPEED_1000;
564         ath79_eth0_data.duplex = DUPLEX_FULL;
565         ath79_eth0_data.phy_mask = BIT(0);
566         ath79_eth0_data.mii_bus_dev = &ath79_mdio0_device.dev;
567         ath79_init_mac(ath79_eth0_data.mac_addr, mac, 0);
568         ath79_register_eth(0);
569
570         ath79_register_pci();
571 }
572
573 MIPS_MACHINE(ATH79_MACH_CF_E375AC, "CF-E375AC", "COMFAST CF-E375AC",
574              cf_e375ac_setup);
575
576 static void __init cf_e38xac_common_setup(unsigned long art_ofs)
577 {
578         cf_exxxn_common_setup(art_ofs, CF_E38XAC_GPIO_EXT_WDT);
579
580         ath79_register_pci();
581
582         /* Disable JTAG (enables GPIO0-3) */
583         ath79_gpio_function_enable(AR934X_GPIO_FUNC_JTAG_DISABLE);
584
585         ath79_gpio_direction_select(CF_E38XAC_GPIO_LED_LAN, true);
586         ath79_gpio_direction_select(CF_E38XAC_GPIO_LED_WLAN2G, true);
587         ath79_gpio_direction_select(CF_E38XAC_GPIO_LED_WLAN5G, true);
588
589         ath79_gpio_output_select(CF_E38XAC_GPIO_LED_LAN, 0);
590         ath79_gpio_output_select(CF_E38XAC_GPIO_LED_WLAN2G, 0);
591         ath79_gpio_output_select(CF_E38XAC_GPIO_LED_WLAN5G, 0);
592
593         /* For J7-4 */
594         ath79_gpio_function_disable(AR934X_GPIO_FUNC_CLK_OBS4_EN);
595
596         ath79_register_gpio_keys_polled(-1, CF_EXXXN_KEYS_POLL_INTERVAL,
597                                         ARRAY_SIZE(cf_e38xac_gpio_keys),
598                                         cf_e38xac_gpio_keys);
599 }
600
601 static void __init cf_e380ac_v1v2_common_setup(unsigned long art_ofs)
602 {
603         u8 *mac = (u8 *) KSEG1ADDR(0x1f000000 + art_ofs);
604
605         cf_e38xac_common_setup(art_ofs);
606
607         ath79_setup_qca955x_eth_cfg(QCA955X_ETH_CFG_RGMII_EN);
608
609         ath79_register_mdio(0, 0x0);
610         mdiobus_register_board_info(cf_e380ac_v1v2_mdio0_info,
611                                     ARRAY_SIZE(cf_e380ac_v1v2_mdio0_info));
612
613         /* LAN */
614         ath79_eth0_data.mii_bus_dev = &ath79_mdio0_device.dev;
615         ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
616         ath79_eth0_data.phy_mask = BIT(0);
617         ath79_eth0_pll_data.pll_1000 = 0xbe000000;
618         ath79_eth0_pll_data.pll_100 = 0xb0000101;
619         ath79_eth0_pll_data.pll_10 = 0xb0001313;
620         ath79_init_mac(ath79_eth0_data.mac_addr, mac, 0);
621         ath79_register_eth(0);
622 }
623
624 static void __init cf_e380ac_v1_setup(void)
625 {
626         cf_e380ac_v1v2_common_setup(0x20000);
627
628         ath79_register_leds_gpio(-1, ARRAY_SIZE(cf_e380ac_v1_leds_gpio),
629                                  cf_e380ac_v1_leds_gpio);
630 }
631
632 MIPS_MACHINE(ATH79_MACH_CF_E380AC_V1, "CF-E380AC-V1", "COMFAST CF-E380AC v1",
633              cf_e380ac_v1_setup);
634
635 static void __init cf_e380ac_v2_setup(void)
636 {
637         cf_e380ac_v1v2_common_setup(0x40000);
638
639         ath79_register_leds_gpio(-1, ARRAY_SIZE(cf_e380ac_v2_leds_gpio),
640                                  cf_e380ac_v2_leds_gpio);
641 }
642
643 MIPS_MACHINE(ATH79_MACH_CF_E380AC_V2, "CF-E380AC-V2", "COMFAST CF-E380AC v2",
644              cf_e380ac_v2_setup);
645
646 /* QCA8337 GMAC0 is connected with QCA9558 over RGMII */
647 static struct ar8327_pad_cfg cf_e385ac_qca8337_pad0_cfg = {
648         .mode = AR8327_PAD_MAC_RGMII,
649         .txclk_delay_en = true,
650         .rxclk_delay_en = true,
651         .txclk_delay_sel = AR8327_CLK_DELAY_SEL1,
652         .rxclk_delay_sel = AR8327_CLK_DELAY_SEL1,
653 };
654
655 /* QCA8337 GMAC6 is connected with QCA9558 over SGMII */
656 static struct ar8327_pad_cfg cf_e385ac_qca8337_pad6_cfg = {
657         .mode = AR8327_PAD_MAC_SGMII,
658         .sgmii_delay_en = true,
659         .rxclk_delay_sel = AR8327_CLK_DELAY_SEL0,
660 };
661
662 static struct ar8327_platform_data cf_e385ac_qca8337_data = {
663         .pad0_cfg = &cf_e385ac_qca8337_pad0_cfg,
664         .pad6_cfg = &cf_e385ac_qca8337_pad6_cfg,
665         .port0_cfg = {
666                 .force_link = 1,
667                 .speed = AR8327_PORT_SPEED_1000,
668                 .duplex = 1,
669                 .txpause = 1,
670                 .rxpause = 1,
671         },
672         .port6_cfg = {
673                 .force_link = 1,
674                 .speed = AR8327_PORT_SPEED_1000,
675                 .duplex = 1,
676                 .txpause = 1,
677                 .rxpause = 1,
678         },
679 };
680
681 static struct mdio_board_info cf_e385ac_mdio0_info[] = {
682         {
683                 .bus_id = "ag71xx-mdio.0",
684                 .mdio_addr = 0,
685                 .platform_data = &cf_e385ac_qca8337_data,
686         },
687 };
688
689 static void __init cf_e385ac_setup(void)
690 {
691         u8 *mac = (u8 *) KSEG1ADDR(0x1f040000);
692
693         cf_e38xac_common_setup(0x40000);
694
695         ath79_register_leds_gpio(-1, ARRAY_SIZE(cf_e385ac_leds_gpio),
696                                  cf_e385ac_leds_gpio);
697
698         mdiobus_register_board_info(cf_e385ac_mdio0_info,
699                                     ARRAY_SIZE(cf_e385ac_mdio0_info));
700         ath79_register_mdio(0, 0x0);
701
702         ath79_setup_qca955x_eth_cfg(QCA955X_ETH_CFG_RGMII_EN);
703
704         /* QCA9558 GMAC0 is connected to RMGII interface */
705         ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
706         ath79_eth0_data.phy_mask = BIT(0);
707         ath79_eth0_data.mii_bus_dev = &ath79_mdio0_device.dev;
708         ath79_eth0_pll_data.pll_1000 = 0x96000000;
709
710         ath79_init_mac(ath79_eth0_data.mac_addr, mac, 0);
711         ath79_register_eth(0);
712
713         /* QCA9558 GMAC1 is connected to SGMII interface */
714         ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_SGMII;
715         ath79_eth1_data.speed = SPEED_1000;
716         ath79_eth1_data.duplex = DUPLEX_FULL;
717         ath79_eth1_pll_data.pll_1000 = 0x03000101;
718
719         ath79_init_mac(ath79_eth1_data.mac_addr, mac, 1);
720         ath79_register_eth(1);
721 }
722
723 MIPS_MACHINE(ATH79_MACH_CF_E385AC, "CF-E385AC", "COMFAST CF-E385AC",
724              cf_e385ac_setup);
725
726 static void __init cf_e5x0n_gpio_setup(void)
727 {
728         ath79_gpio_direction_select(CF_E5X0N_GPIO_LED_WAN, true);
729
730         ath79_gpio_output_select(CF_E5X0N_GPIO_LED_WAN, 0);
731
732         ath79_register_gpio_keys_polled(-1, CF_EXXXN_KEYS_POLL_INTERVAL,
733                                         ARRAY_SIZE(cf_e320n_v2_gpio_keys),
734                                         cf_e320n_v2_gpio_keys);
735 }
736
737 static void __init cf_e520n_setup(void)
738 {
739         cf_exxxn_common_setup(0x10000, -1);
740
741         cf_exxxn_qca953x_eth_setup();
742
743         cf_e5x0n_gpio_setup();
744
745         ath79_register_leds_gpio(-1, ARRAY_SIZE(cf_e520n_leds_gpio),
746                                  cf_e520n_leds_gpio);
747 }
748
749 MIPS_MACHINE(ATH79_MACH_CF_E520N, "CF-E520N", "COMFAST CF-E520N",
750              cf_e520n_setup);
751
752 static void __init cf_e530n_setup(void)
753 {
754         cf_exxxn_common_setup(0x10000, -1);
755
756         cf_exxxn_qca953x_eth_setup();
757
758         cf_e5x0n_gpio_setup();
759
760         ath79_register_leds_gpio(-1, ARRAY_SIZE(cf_e530n_leds_gpio),
761                                  cf_e530n_leds_gpio);
762 }
763
764 MIPS_MACHINE(ATH79_MACH_CF_E530N, "CF-E530N", "COMFAST CF-E530N",
765              cf_e530n_setup);