target: ar71xx: add support for COMFAST CF-E316N v2 board
[openwrt/openwrt.git] / target / linux / ar71xx / files / arch / mips / ath79 / mach-cf-e316n-v2.c
1 /*
2 * COMFAST CF-E316N v2
3 * by Shenzhen Four Seas Global Link Network Technology Co., Ltd
4 *
5 * aka CF-E316V2, CF-E316N-V2 and CF-E316Nv2.0 (no FCC ID)
6 *
7 * Copyright (C) 2015 Paul Fertser <fercerpav@gmail.com>
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License version 2 as published
11 * by the Free Software Foundation.
12 */
13
14 #include <linux/gpio.h>
15 #include <linux/platform_device.h>
16 #include <linux/timer.h>
17
18 #include <asm/mach-ath79/ath79.h>
19 #include <asm/mach-ath79/ar71xx_regs.h>
20
21 #include "common.h"
22 #include "dev-eth.h"
23 #include "dev-gpio-buttons.h"
24 #include "dev-leds-gpio.h"
25 #include "dev-m25p80.h"
26 #include "dev-wmac.h"
27 #include "dev-usb.h"
28 #include "machtypes.h"
29
30 static struct gpio_led cf_e316n_v2_leds_gpio[] __initdata = {
31 {
32 .name = "cf-e316n-v2:blue:diag",
33 .gpio = 0,
34 .active_low = 0,
35 }, {
36 .name = "cf-e316n-v2:red:diag",
37 .gpio = 2,
38 .active_low = 0,
39 }, {
40 .name = "cf-e316n-v2:green:diag",
41 .gpio = 3,
42 .active_low = 0,
43 }, {
44 .name = "cf-e316n-v2:blue:wlan",
45 .gpio = 12,
46 .active_low = 1,
47 }, {
48 .name = "cf-e316n-v2:blue:wan",
49 .gpio = 17,
50 .active_low = 1,
51 }, {
52 .name = "cf-e316n-v2:blue:lan",
53 .gpio = 19,
54 .active_low = 1,
55 },
56 };
57
58 static struct gpio_keys_button cf_e316n_v2_gpio_keys[] __initdata = {
59 {
60 .desc = "Reset button",
61 .type = EV_KEY,
62 .code = KEY_RESTART,
63 .debounce_interval = 60,
64 .gpio = 20,
65 .active_low = 1,
66 },
67 };
68
69 /* There's a Pericon Technology PT7A7514 connected to GPIO 16 */
70 #define EXT_WATCHDOG_GPIO 16
71 static struct timer_list gpio_wdt_timer;
72
73 static void gpio_wdt_toggle(unsigned long period)
74 {
75 static int state;
76 state = !state;
77 gpio_set_value(EXT_WATCHDOG_GPIO, state);
78 mod_timer(&gpio_wdt_timer, jiffies + period);
79 }
80
81 static void __init cf_e316n_v2_setup(void)
82 {
83 u8 *maclan = (u8 *) KSEG1ADDR(0x1f010000);
84 u8 *macwlan = (u8 *) KSEG1ADDR(0x1f011002);
85 u8 *ee = (u8 *) KSEG1ADDR(0x1f011000);
86 u8 tmpmac[ETH_ALEN];
87
88 gpio_request(EXT_WATCHDOG_GPIO, "PT7A7514 watchdog");
89 gpio_direction_output(EXT_WATCHDOG_GPIO, 0);
90 setup_timer(&gpio_wdt_timer, gpio_wdt_toggle, msecs_to_jiffies(500));
91 gpio_wdt_toggle(msecs_to_jiffies(1));
92
93 ath79_register_m25p80(NULL);
94
95 ath79_setup_ar934x_eth_cfg(AR934X_ETH_CFG_SW_PHY_SWAP);
96 ath79_register_mdio(1, 0x0);
97
98 /* GMAC0 is connected to the PHY0 of the internal switch */
99 ath79_switch_data.phy4_mii_en = 1;
100 ath79_switch_data.phy_poll_mask = BIT(0);
101 ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
102 ath79_eth0_data.phy_mask = BIT(0);
103 ath79_eth0_data.mii_bus_dev = &ath79_mdio1_device.dev;
104 ath79_init_mac(ath79_eth0_data.mac_addr, maclan, 0);
105 ath79_register_eth(0);
106
107 /* GMAC1 is connected to the internal switch */
108 ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_GMII;
109 ath79_init_mac(ath79_eth1_data.mac_addr, maclan, 2);
110 ath79_register_eth(1);
111
112 /* Enable 2x Skyworks SE2576L WLAN power amplifiers */
113 gpio_request(13, "RF Amp 1");
114 gpio_direction_output(13, 1);
115 gpio_request(14, "RF Amp 2");
116 gpio_direction_output(14, 1);
117 ath79_init_mac(tmpmac, macwlan, 0);
118 ath79_register_wmac(ee, tmpmac);
119
120 ath79_register_leds_gpio(-1, ARRAY_SIZE(cf_e316n_v2_leds_gpio),
121 cf_e316n_v2_leds_gpio);
122
123 ath79_register_gpio_keys_polled(1, 20,
124 ARRAY_SIZE(cf_e316n_v2_gpio_keys),
125 cf_e316n_v2_gpio_keys);
126
127 /* J1 is a High-Speed USB port, pin 1 is Vcc */
128 ath79_register_usb();
129 }
130
131 MIPS_MACHINE(ATH79_MACH_CF_E316N_V2, "CF-E316N-V2", "COMFAST CF-E316N v2",
132 cf_e316n_v2_setup);