wireguard-tools: add tunlink option for hostroute
[openwrt/openwrt.git] / target / linux / ar71xx / files / arch / mips / ath79 / mach-archer-c60-v1.c
1 /*
2 * TP-Link Archer C60 v1 board support
3 *
4 * Copyright (C) 2017 Henryk Heisig <hyniu@o2.pl>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published
8 * by the Free Software Foundation.
9 */
10 #include <linux/platform_device.h>
11 #include <linux/ath9k_platform.h>
12 #include <linux/ar8216_platform.h>
13 #include <asm/mach-ath79/ar71xx_regs.h>
14 #include <linux/gpio.h>
15
16 #include "common.h"
17 #include "dev-m25p80.h"
18 #include "machtypes.h"
19 #include "pci.h"
20 #include "dev-ap9x-pci.h"
21 #include "dev-eth.h"
22 #include "dev-gpio-buttons.h"
23 #include "dev-leds-gpio.h"
24 #include "dev-spi.h"
25 #include "dev-usb.h"
26 #include "dev-wmac.h"
27
28 #define ARCHER_C60_V1_GPIO_LED_LAN 2
29 #define ARCHER_C60_V1_GPIO_LED_POWER 16
30 #define ARCHER_C60_V1_GPIO_LED_WLAN2 17
31 #define ARCHER_C60_V1_GPIO_LED_WLAN5 18
32 #define ARCHER_C60_V1_GPIO_LED_WPS 19
33 #define ARCHER_C60_V1_GPIO_LED_WAN_GREEN 20
34 #define ARCHER_C60_V1_GPIO_LED_WAN_AMBER 22
35
36
37 #define ARCHER_C60_V1_KEYS_POLL_INTERVAL 20
38 #define ARCHER_C60_V1_KEYS_DEBOUNCE_INTERVAL (3 * ARCHER_C60_V1_KEYS_POLL_INTERVAL)
39
40 #define ARCHER_C60_V1_GPIO_BTN_RESET 21
41 #define ARCHER_C60_V1_GPIO_BTN_RFKILL 1
42
43
44
45 #define ARCHER_C60_V1_WMAC_CALDATA_OFFSET 0x1000
46 #define ARCHER_C60_V1_PCI_CALDATA_OFFSET 0x5000
47
48 static struct gpio_led archer_c60_v1_leds_gpio[] __initdata = {
49 {
50 .name = "archer-c60-v1:green:power",
51 .gpio = ARCHER_C60_V1_GPIO_LED_POWER,
52 .active_low = 1,
53 },
54 {
55 .name = "archer-c60-v1:green:wlan2g",
56 .gpio = ARCHER_C60_V1_GPIO_LED_WLAN2,
57 .active_low = 1,
58 },
59 {
60 .name = "archer-c60-v1:green:wlan5g",
61 .gpio = ARCHER_C60_V1_GPIO_LED_WLAN5,
62 .active_low = 1,
63 },
64 {
65 .name = "archer-c60-v1:green:lan",
66 .gpio = ARCHER_C60_V1_GPIO_LED_LAN,
67 .active_low = 1,
68 },
69 {
70 .name = "archer-c60-v1:green:wan",
71 .gpio = ARCHER_C60_V1_GPIO_LED_WAN_GREEN,
72 .active_low = 1,
73 },
74 {
75 .name = "archer-c60-v1:amber:wan",
76 .gpio = ARCHER_C60_V1_GPIO_LED_WAN_AMBER,
77 .active_low = 1,
78 },
79 {
80 .name = "archer-c60-v1:green:wps",
81 .gpio = ARCHER_C60_V1_GPIO_LED_WPS,
82 .active_low = 1,
83 },
84 };
85
86 static struct gpio_led archer_c60_v2_leds_gpio[] __initdata = {
87 {
88 .name = "archer-c60-v2:green:power",
89 .gpio = ARCHER_C60_V1_GPIO_LED_POWER,
90 .active_low = 1,
91 },
92 {
93 .name = "archer-c60-v2:green:wlan2g",
94 .gpio = ARCHER_C60_V1_GPIO_LED_WLAN2,
95 .active_low = 1,
96 },
97 {
98 .name = "archer-c60-v2:green:wlan5g",
99 .gpio = ARCHER_C60_V1_GPIO_LED_WLAN5,
100 .active_low = 1,
101 },
102 {
103 .name = "archer-c60-v2:green:lan",
104 .gpio = ARCHER_C60_V1_GPIO_LED_LAN,
105 .active_low = 1,
106 },
107 {
108 .name = "archer-c60-v2:green:wan",
109 .gpio = ARCHER_C60_V1_GPIO_LED_WAN_GREEN,
110 .active_low = 1,
111 },
112 {
113 .name = "archer-c60-v2:amber:wan",
114 .gpio = ARCHER_C60_V1_GPIO_LED_WAN_AMBER,
115 .active_low = 1,
116 },
117 {
118 .name = "archer-c60-v2:green:wps",
119 .gpio = ARCHER_C60_V1_GPIO_LED_WPS,
120 .active_low = 1,
121 },
122 };
123
124 static struct gpio_keys_button archer_c60_v1_gpio_keys[] __initdata = {
125 {
126 .desc = "Reset button",
127 .type = EV_KEY,
128 .code = KEY_RESTART,
129 .debounce_interval = ARCHER_C60_V1_KEYS_DEBOUNCE_INTERVAL,
130 .gpio = ARCHER_C60_V1_GPIO_BTN_RESET,
131 .active_low = 1,
132 },
133 {
134 .desc = "RFKILL button",
135 .type = EV_KEY,
136 .code = KEY_RFKILL,
137 .debounce_interval = ARCHER_C60_V1_KEYS_DEBOUNCE_INTERVAL,
138 .gpio = ARCHER_C60_V1_GPIO_BTN_RFKILL,
139 .active_low = 1,
140 },
141 };
142
143 static void __init archer_c60_v1_setup(void)
144 {
145 u8 *mac = (u8 *) KSEG1ADDR(0x1f010008);
146 u8 *art = (u8 *) KSEG1ADDR(0x1f7f0000);
147
148 ath79_register_m25p80(NULL);
149
150 ath79_register_leds_gpio(-1, ARRAY_SIZE(archer_c60_v1_leds_gpio),
151 archer_c60_v1_leds_gpio);
152
153 ath79_register_gpio_keys_polled(-1, ARCHER_C60_V1_KEYS_POLL_INTERVAL,
154 ARRAY_SIZE(archer_c60_v1_gpio_keys),
155 archer_c60_v1_gpio_keys);
156
157 ath79_register_mdio(0, 0x0);
158 ath79_register_mdio(1, 0x0);
159
160 ath79_init_mac(ath79_eth1_data.mac_addr, mac, 0);
161 ath79_init_mac(ath79_eth0_data.mac_addr, mac, 1);
162
163 /* WAN port */
164 ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
165 ath79_eth0_data.speed = SPEED_100;
166 ath79_eth0_data.duplex = DUPLEX_FULL;
167 ath79_eth0_data.phy_mask = BIT(4);
168 ath79_register_eth(0);
169
170 /* LAN ports */
171 ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_GMII;
172 ath79_eth1_data.speed = SPEED_1000;
173 ath79_eth1_data.duplex = DUPLEX_FULL;
174 ath79_switch_data.phy_poll_mask |= BIT(4);
175 ath79_switch_data.phy4_mii_en = 1;
176 ath79_register_eth(1);
177
178 ath79_register_wmac(art + ARCHER_C60_V1_WMAC_CALDATA_OFFSET, mac);
179 ap91_pci_init(art + ARCHER_C60_V1_PCI_CALDATA_OFFSET, NULL);
180 }
181
182 MIPS_MACHINE(ATH79_MACH_ARCHER_C60_V1, "ARCHER-C60-V1",
183 "TP-LINK Archer C60 v1", archer_c60_v1_setup);
184
185 static void __init archer_c60_v2_setup(void)
186 {
187 u8 *mac = (u8 *) KSEG1ADDR(0x1f01fb08);
188 u8 *art = (u8 *) KSEG1ADDR(0x1f7f0000);
189
190 ath79_register_m25p80(NULL);
191
192 ath79_register_leds_gpio(-1, ARRAY_SIZE(archer_c60_v2_leds_gpio),
193 archer_c60_v2_leds_gpio);
194
195 ath79_register_gpio_keys_polled(-1, ARCHER_C60_V1_KEYS_POLL_INTERVAL,
196 ARRAY_SIZE(archer_c60_v1_gpio_keys),
197 archer_c60_v1_gpio_keys);
198
199 ath79_register_mdio(0, 0x0);
200 ath79_register_mdio(1, 0x0);
201
202 ath79_init_mac(ath79_eth1_data.mac_addr, mac, 0);
203 ath79_init_mac(ath79_eth0_data.mac_addr, mac, 1);
204
205 /* WAN port */
206 ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
207 ath79_eth0_data.speed = SPEED_100;
208 ath79_eth0_data.duplex = DUPLEX_FULL;
209 ath79_eth0_data.phy_mask = BIT(4);
210 ath79_register_eth(0);
211
212 /* LAN ports */
213 ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_GMII;
214 ath79_eth1_data.speed = SPEED_1000;
215 ath79_eth1_data.duplex = DUPLEX_FULL;
216 ath79_switch_data.phy_poll_mask |= BIT(4);
217 ath79_switch_data.phy4_mii_en = 1;
218 ath79_register_eth(1);
219
220 ath79_register_wmac(art + ARCHER_C60_V1_WMAC_CALDATA_OFFSET, mac);
221 ap91_pci_init(art + ARCHER_C60_V1_PCI_CALDATA_OFFSET, NULL);
222 }
223
224 MIPS_MACHINE(ATH79_MACH_ARCHER_C60_V2, "ARCHER-C60-V2",
225 "TP-LINK Archer C60 v2", archer_c60_v2_setup);