ar71xx: move DomyWifi DW33D to nand subtarget
[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-E380AC v1/v2 (QCA9558)
6  *  - CF-E520N/CF-E530N (QCA9531)
7  *
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>
11  *
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.
15  */
16
17 #include <linux/gpio.h>
18 #include <linux/platform_data/phy-at803x.h>
19 #include <linux/platform_device.h>
20 #include <linux/timer.h>
21
22 #include <asm/mach-ath79/ath79.h>
23 #include <asm/mach-ath79/ar71xx_regs.h>
24
25 #include "common.h"
26 #include "dev-ap9x-pci.h"
27 #include "dev-eth.h"
28 #include "dev-gpio-buttons.h"
29 #include "dev-leds-gpio.h"
30 #include "dev-m25p80.h"
31 #include "dev-wmac.h"
32 #include "dev-usb.h"
33 #include "machtypes.h"
34
35 #define CF_EXXXN_KEYS_POLL_INTERVAL     20
36 #define CF_EXXXN_KEYS_DEBOUNCE_INTERVAL (3 * CF_EXXXN_KEYS_POLL_INTERVAL)
37
38 /* CF-E316N v2 */
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
45
46 #define CF_E316N_V2_GPIO_EXT_WDT        16
47
48 #define CF_E316N_V2_GPIO_EXTERNAL_PA0   13
49 #define CF_E316N_V2_GPIO_EXTERNAL_PA1   14
50
51 #define CF_E316N_V2_GPIO_BTN_RESET      20
52
53 static struct gpio_led cf_e316n_v2_leds_gpio[] __initdata = {
54         {
55                 .name           = "cf-e316n-v2:blue:diag",
56                 .gpio           = CF_E316N_V2_GPIO_LED_DIAG_B,
57                 .active_low     = 0,
58         }, {
59                 .name           = "cf-e316n-v2:red:diag",
60                 .gpio           = CF_E316N_V2_GPIO_LED_DIAG_R,
61                 .active_low     = 0,
62         }, {
63                 .name           = "cf-e316n-v2:green:diag",
64                 .gpio           = CF_E316N_V2_GPIO_LED_DIAG_G,
65                 .active_low     = 0,
66         }, {
67                 .name           = "cf-e316n-v2:blue:wlan",
68                 .gpio           = CF_E316N_V2_GPIO_LED_WLAN,
69                 .active_low     = 1,
70         }, {
71                 .name           = "cf-e316n-v2:blue:wan",
72                 .gpio           = CF_E316N_V2_GPIO_LED_WAN,
73                 .active_low     = 1,
74         }, {
75                 .name           = "cf-e316n-v2:blue:lan",
76                 .gpio           = CF_E316N_V2_GPIO_LED_LAN,
77                 .active_low     = 1,
78         },
79 };
80
81 static struct gpio_keys_button cf_e316n_v2_gpio_keys[] __initdata = {
82         {
83                 .desc           = "reset",
84                 .type           = EV_KEY,
85                 .code           = KEY_RESTART,
86                 .debounce_interval = CF_EXXXN_KEYS_DEBOUNCE_INTERVAL,
87                 .gpio           = CF_E316N_V2_GPIO_BTN_RESET,
88                 .active_low     = 1,
89         },
90 };
91
92 /* CF-E320N v2 */
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
96
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
101
102 #define CF_E320N_V2_GPIO_EXT_WDT        13
103
104 #define CF_E320N_V2_GPIO_BTN_RESET      17
105
106 static struct gpio_led cf_e320n_v2_leds_gpio[] __initdata = {
107         {
108                 .name           = "cf-e320n-v2:green:lan",
109                 .gpio           = CF_E320N_V2_GPIO_LED_LAN,
110                 .active_low     = 0,
111         }, {
112                 .name           = "cf-e320n-v2:red:wan",
113                 .gpio           = CF_E320N_V2_GPIO_LED_WAN,
114                 .active_low     = 0,
115         }, {
116                 .name           = "cf-e320n-v2:blue:wlan",
117                 .gpio           = CF_E320N_V2_GPIO_LED_WLAN,
118                 .active_low     = 0,
119         },
120 };
121
122 static struct gpio_keys_button cf_e320n_v2_gpio_keys[] __initdata = {
123         {
124                 .desc           = "Reset button",
125                 .type           = EV_KEY,
126                 .code           = KEY_RESTART,
127                 .debounce_interval = CF_EXXXN_KEYS_DEBOUNCE_INTERVAL,
128                 .gpio           = CF_E320N_V2_GPIO_BTN_RESET,
129                 .active_low     = 1,
130         },
131 };
132
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
137
138 #define CF_E380AC_V1V2_GPIO_EXT_WDT     17
139
140 #define CF_E380AC_V1V2_GPIO_BTN_RESET   19
141
142 static struct gpio_led cf_e380ac_v1_leds_gpio[] __initdata = {
143         {
144                 .name           = "cf-e380ac-v1:green:lan",
145                 .gpio           = CF_E380AC_V1V2_GPIO_LED_LAN,
146                 .active_low     = 0,
147         }, {
148                 .name           = "cf-e380ac-v1:blue:wlan2g",
149                 .gpio           = CF_E380AC_V1V2_GPIO_LED_WLAN2G,
150                 .active_low     = 0,
151         }, {
152                 .name           = "cf-e380ac-v1:red:wlan5g",
153                 .gpio           = CF_E380AC_V1V2_GPIO_LED_WLAN5G,
154                 .active_low     = 0,
155         },
156 };
157
158 static struct gpio_led cf_e380ac_v2_leds_gpio[] __initdata = {
159         {
160                 .name           = "cf-e380ac-v2:green:lan",
161                 .gpio           = CF_E380AC_V1V2_GPIO_LED_LAN,
162                 .active_low     = 0,
163         }, {
164                 .name           = "cf-e380ac-v2:blue:wlan2g",
165                 .gpio           = CF_E380AC_V1V2_GPIO_LED_WLAN2G,
166                 .active_low     = 0,
167         }, {
168                 .name           = "cf-e380ac-v2:red:wlan5g",
169                 .gpio           = CF_E380AC_V1V2_GPIO_LED_WLAN5G,
170                 .active_low     = 0,
171         },
172 };
173
174 static struct gpio_keys_button cf_e380ac_v1v2_gpio_keys[] __initdata = {
175         {
176                 .desc           = "Reset button",
177                 .type           = EV_KEY,
178                 .code           = KEY_RESTART,
179                 .debounce_interval = CF_EXXXN_KEYS_DEBOUNCE_INTERVAL,
180                 .gpio           = CF_E380AC_V1V2_GPIO_BTN_RESET,
181                 .active_low     = 1,
182         },
183 };
184
185 static struct at803x_platform_data cf_e380ac_v1v2_at803x_data = {
186         .disable_smarteee = 1,
187 };
188
189 static struct mdio_board_info cf_e380ac_v1v2_mdio0_info[] = {
190         {
191                 .bus_id = "ag71xx-mdio.0",
192                 .phy_addr = 0,
193                 .platform_data = &cf_e380ac_v1v2_at803x_data,
194         },
195 };
196
197 /* CF-E520N/CF-E530N */
198 #define CF_E5X0N_GPIO_LED_WAN           11
199 #define CF_E5X0N_GPIO_BTN_RESET         17
200
201 static struct gpio_led cf_e520n_leds_gpio[] __initdata = {
202         {
203                 .name           = "cf-e520n:blue:wan",
204                 .gpio           = CF_E5X0N_GPIO_LED_WAN,
205                 .active_low     = 1,
206         }
207 };
208
209 static struct gpio_led cf_e530n_leds_gpio[] __initdata = {
210         {
211                 .name           = "cf-e530n:blue:wan",
212                 .gpio           = CF_E5X0N_GPIO_LED_WAN,
213                 .active_low     = 1,
214         }
215 };
216
217 /*
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.
221  */
222 #define CF_EXXXN_EXT_WDT_TIMEOUT_MS     500
223
224 static struct timer_list gpio_wdt_timer;
225
226 static void gpio_wdt_toggle(unsigned long gpio)
227 {
228         static int state;
229
230         state = !state;
231         gpio_set_value(gpio, state);
232
233         mod_timer(&gpio_wdt_timer,
234                   jiffies + msecs_to_jiffies(CF_EXXXN_EXT_WDT_TIMEOUT_MS));
235 }
236
237 static void __init cf_exxxn_common_setup(unsigned long art_ofs, int gpio_wdt)
238 {
239         u8 *art = (u8 *) KSEG1ADDR(0x1f001000 + art_ofs);
240
241         if (gpio_wdt > -1) {
242                 gpio_request_one(gpio_wdt, GPIOF_OUT_INIT_HIGH,
243                                  "PT7A7514 watchdog");
244
245                 setup_timer(&gpio_wdt_timer, gpio_wdt_toggle, gpio_wdt);
246                 gpio_wdt_toggle(gpio_wdt);
247         }
248
249         ath79_register_m25p80(NULL);
250
251         ath79_register_wmac(art, NULL);
252
253         ath79_register_usb();
254 }
255
256 static void __init cf_e316n_v2_setup(void)
257 {
258         u8 *mac = (u8 *) KSEG1ADDR(0x1f010000);
259
260         cf_exxxn_common_setup(0x10000, CF_E316N_V2_GPIO_EXT_WDT);
261
262         ath79_setup_ar934x_eth_cfg(AR934X_ETH_CFG_SW_PHY_SWAP);
263
264         ath79_register_mdio(1, 0x0);
265
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);
274
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);
279
280         /* Enable 2x Skyworks SE2576L WLAN power amplifiers */
281         gpio_request_one(CF_E316N_V2_GPIO_EXTERNAL_PA0, GPIOF_OUT_INIT_HIGH,
282                          "WLAN PA0");
283         gpio_request_one(CF_E316N_V2_GPIO_EXTERNAL_PA1, GPIOF_OUT_INIT_HIGH,
284                          "WLAN PA1");
285
286         ath79_register_leds_gpio(-1, ARRAY_SIZE(cf_e316n_v2_leds_gpio),
287                                  cf_e316n_v2_leds_gpio);
288
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);
292 }
293
294 MIPS_MACHINE(ATH79_MACH_CF_E316N_V2, "CF-E316N-V2", "COMFAST CF-E316N v2",
295              cf_e316n_v2_setup);
296
297 static void __init cf_exxxn_qca953x_eth_setup(void)
298 {
299         u8 *mac = (u8 *) KSEG1ADDR(0x1f010000);
300
301         ath79_setup_ar933x_phy4_switch(false, false);
302
303         ath79_register_mdio(0, 0x0);
304
305         ath79_switch_data.phy4_mii_en = 1;
306         ath79_switch_data.phy_poll_mask |= BIT(4);
307
308         /* LAN */
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);
314
315         /* WAN */
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);
322 }
323
324 static void __init cf_e320n_v2_setup(void)
325 {
326         cf_exxxn_common_setup(0x10000, CF_E320N_V2_GPIO_EXT_WDT);
327
328         cf_exxxn_qca953x_eth_setup();
329
330         /* Disable JTAG (enables GPIO0-3) */
331         ath79_gpio_function_enable(AR934X_GPIO_FUNC_JTAG_DISABLE);
332
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);
336
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);
340
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);
346
347         ath79_register_leds_gpio(-1, ARRAY_SIZE(cf_e320n_v2_leds_gpio),
348                                  cf_e320n_v2_leds_gpio);
349
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);
353 }
354
355 MIPS_MACHINE(ATH79_MACH_CF_E320N_V2, "CF-E320N-V2", "COMFAST CF-E320N v2",
356              cf_e320n_v2_setup);
357
358 static void __init cf_e380ac_v1v2_common_setup(unsigned long art_ofs)
359 {
360         u8 *mac = (u8 *) KSEG1ADDR(0x1f000000 + art_ofs);
361
362         cf_exxxn_common_setup(art_ofs, CF_E380AC_V1V2_GPIO_EXT_WDT);
363
364         ath79_setup_qca955x_eth_cfg(QCA955X_ETH_CFG_RGMII_EN);
365
366         ath79_register_mdio(0, 0x0);
367         mdiobus_register_board_info(cf_e380ac_v1v2_mdio0_info,
368                                     ARRAY_SIZE(cf_e380ac_v1v2_mdio0_info));
369
370         /* LAN */
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);
379
380         ap91_pci_init(mac + 0x5000, NULL);
381
382         /* Disable JTAG (enables GPIO0-3) */
383         ath79_gpio_function_enable(AR934X_GPIO_FUNC_JTAG_DISABLE);
384
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);
388
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);
392
393         /* For J7-4 */
394         ath79_gpio_function_disable(AR934X_GPIO_FUNC_CLK_OBS4_EN);
395
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);
399 }
400
401 static void __init cf_e380ac_v1_setup(void)
402 {
403         cf_e380ac_v1v2_common_setup(0x20000);
404
405         ath79_register_leds_gpio(-1, ARRAY_SIZE(cf_e380ac_v1_leds_gpio),
406                                  cf_e380ac_v1_leds_gpio);
407 }
408
409 MIPS_MACHINE(ATH79_MACH_CF_E380AC_V1, "CF-E380AC-V1", "COMFAST CF-E380AC v1",
410              cf_e380ac_v1_setup);
411
412 static void __init cf_e380ac_v2_setup(void)
413 {
414         cf_e380ac_v1v2_common_setup(0x40000);
415
416         ath79_register_leds_gpio(-1, ARRAY_SIZE(cf_e380ac_v2_leds_gpio),
417                                  cf_e380ac_v2_leds_gpio);
418 }
419
420 MIPS_MACHINE(ATH79_MACH_CF_E380AC_V2, "CF-E380AC-V2", "COMFAST CF-E380AC v2",
421              cf_e380ac_v2_setup);
422
423 static void __init cf_e5x0n_gpio_setup(void)
424 {
425         ath79_gpio_direction_select(CF_E5X0N_GPIO_LED_WAN, true);
426
427         ath79_gpio_output_select(CF_E5X0N_GPIO_LED_WAN, 0);
428
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);
432 }
433
434 static void __init cf_e520n_setup(void)
435 {
436         cf_exxxn_common_setup(0x10000, -1);
437
438         cf_exxxn_qca953x_eth_setup();
439
440         cf_e5x0n_gpio_setup();
441
442         ath79_register_leds_gpio(-1, ARRAY_SIZE(cf_e520n_leds_gpio),
443                                  cf_e520n_leds_gpio);
444 }
445
446 MIPS_MACHINE(ATH79_MACH_CF_E520N, "CF-E520N", "COMFAST CF-E520N",
447              cf_e520n_setup);
448
449 static void __init cf_e530n_setup(void)
450 {
451         cf_exxxn_common_setup(0x10000, -1);
452
453         cf_exxxn_qca953x_eth_setup();
454
455         cf_e5x0n_gpio_setup();
456
457         ath79_register_leds_gpio(-1, ARRAY_SIZE(cf_e530n_leds_gpio),
458                                  cf_e530n_leds_gpio);
459 }
460
461 MIPS_MACHINE(ATH79_MACH_CF_E530N, "CF-E530N", "COMFAST CF-E530N",
462              cf_e530n_setup);