modules: Add kernel module for MV88E6xxx DSA switch
[openwrt/openwrt.git] / target / linux / ar71xx / files / arch / mips / ath79 / mach-archer-c59-v1.c
1 /*
2 * TP-Link Archer C58/C59 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 #include <linux/init.h>
16 #include <linux/spi/spi_gpio.h>
17 #include <linux/spi/74x164.h>
18
19 #include "common.h"
20 #include "dev-m25p80.h"
21 #include "machtypes.h"
22 #include "pci.h"
23 #include "dev-ap9x-pci.h"
24 #include "dev-eth.h"
25 #include "dev-gpio-buttons.h"
26 #include "dev-leds-gpio.h"
27 #include "dev-spi.h"
28 #include "dev-usb.h"
29 #include "dev-wmac.h"
30
31 #define ARCHER_C59_V1_KEYS_POLL_INTERVAL 20
32 #define ARCHER_C59_V1_KEYS_DEBOUNCE_INTERVAL (3 * ARCHER_C59_V1_KEYS_POLL_INTERVAL)
33
34 #define ARCHER_C59_V1_GPIO_BTN_RESET 21
35 #define ARCHER_C59_V1_GPIO_BTN_RFKILL 2
36 #define ARCHER_C59_V1_GPIO_BTN_WPS 1
37
38 #define ARCHER_C59_V1_GPIO_USB_POWER 22
39
40 #define ARCHER_C59_GPIO_SHIFT_OE 16
41 #define ARCHER_C59_GPIO_SHIFT_SER 17
42 #define ARCHER_C59_GPIO_SHIFT_SRCLK 18
43 #define ARCHER_C59_GPIO_SHIFT_SRCLR 19
44 #define ARCHER_C59_GPIO_SHIFT_RCLK 20
45
46 #define ARCHER_C59_74HC_GPIO_BASE 32
47 #define ARCHER_C59_74HC_GPIO_LED_POWER (ARCHER_C59_74HC_GPIO_BASE + 0)
48 #define ARCHER_C59_74HC_GPIO_LED_WLAN2 (ARCHER_C59_74HC_GPIO_BASE + 1)
49 #define ARCHER_C59_74HC_GPIO_LED_WLAN5 (ARCHER_C59_74HC_GPIO_BASE + 2)
50 #define ARCHER_C59_74HC_GPIO_LED_LAN (ARCHER_C59_74HC_GPIO_BASE + 3)
51 #define ARCHER_C59_74HC_GPIO_LED_WAN_GREEN (ARCHER_C59_74HC_GPIO_BASE + 4)
52 #define ARCHER_C59_74HC_GPIO_LED_WAN_AMBER (ARCHER_C59_74HC_GPIO_BASE + 5)
53 #define ARCHER_C59_74HC_GPIO_LED_WPS (ARCHER_C59_74HC_GPIO_BASE + 6)
54 #define ARCHER_C59_74HC_GPIO_LED_USB (ARCHER_C59_74HC_GPIO_BASE + 7)
55
56 #define ARCHER_C59_V1_SSR_BIT_0 0
57 #define ARCHER_C59_V1_SSR_BIT_1 1
58 #define ARCHER_C59_V1_SSR_BIT_2 2
59 #define ARCHER_C59_V1_SSR_BIT_3 3
60 #define ARCHER_C59_V1_SSR_BIT_4 4
61 #define ARCHER_C59_V1_SSR_BIT_5 5
62 #define ARCHER_C59_V1_SSR_BIT_6 6
63 #define ARCHER_C59_V1_SSR_BIT_7 7
64
65 #define ARCHER_C59_V1_WMAC_CALDATA_OFFSET 0x1000
66 #define ARCHER_C59_V1_PCI_CALDATA_OFFSET 0x5000
67
68 static struct gpio_led archer_c58_v1_leds_gpio[] __initdata = {
69 {
70 .name = "archer-c58-v1:green:power",
71 .gpio = ARCHER_C59_74HC_GPIO_LED_POWER,
72 .active_low = 1,
73 },
74 {
75 .name = "archer-c58-v1:green:wlan2g",
76 .gpio = ARCHER_C59_74HC_GPIO_LED_WLAN2,
77 .active_low = 1,
78 },
79 {
80 .name = "archer-c58-v1:green:wlan5g",
81 .gpio = ARCHER_C59_74HC_GPIO_LED_WLAN5,
82 .active_low = 1,
83 },
84 {
85 .name = "archer-c58-v1:green:lan",
86 .gpio = ARCHER_C59_74HC_GPIO_LED_LAN,
87 .active_low = 1,
88 },
89 {
90 .name = "archer-c58-v1:green:wan",
91 .gpio = ARCHER_C59_74HC_GPIO_LED_WAN_GREEN,
92 .active_low = 1,
93 },
94 {
95 .name = "archer-c58-v1:amber:wan",
96 .gpio = ARCHER_C59_74HC_GPIO_LED_WAN_AMBER,
97 .active_low = 1,
98 },
99 {
100 .name = "archer-c58-v1:green:wps",
101 .gpio = ARCHER_C59_74HC_GPIO_LED_WPS,
102 .active_low = 1,
103 },
104 };
105
106 static struct gpio_led archer_c59_v1_leds_gpio[] __initdata = {
107 {
108 .name = "archer-c59-v1:green:power",
109 .gpio = ARCHER_C59_74HC_GPIO_LED_POWER,
110 .active_low = 1,
111 },
112 {
113 .name = "archer-c59-v1:green:wlan2g",
114 .gpio = ARCHER_C59_74HC_GPIO_LED_WLAN2,
115 .active_low = 1,
116 },
117 {
118 .name = "archer-c59-v1:green:wlan5g",
119 .gpio = ARCHER_C59_74HC_GPIO_LED_WLAN5,
120 .active_low = 1,
121 },
122 {
123 .name = "archer-c59-v1:green:lan",
124 .gpio = ARCHER_C59_74HC_GPIO_LED_LAN,
125 .active_low = 1,
126 },
127 {
128 .name = "archer-c59-v1:green:wan",
129 .gpio = ARCHER_C59_74HC_GPIO_LED_WAN_GREEN,
130 .active_low = 1,
131 },
132 {
133 .name = "archer-c59-v1:amber:wan",
134 .gpio = ARCHER_C59_74HC_GPIO_LED_WAN_AMBER,
135 .active_low = 1,
136 },
137 {
138 .name = "archer-c59-v1:green:wps",
139 .gpio = ARCHER_C59_74HC_GPIO_LED_WPS,
140 .active_low = 1,
141 },
142 {
143 .name = "archer-c59-v1:green:usb",
144 .gpio = ARCHER_C59_74HC_GPIO_LED_USB,
145 .active_low = 1,
146 },
147 };
148
149 static struct gpio_led archer_c59_v2_leds_gpio[] __initdata = {
150 {
151 .name = "archer-c59-v2:green:power",
152 .gpio = ARCHER_C59_74HC_GPIO_LED_POWER,
153 .active_low = 1,
154 },
155 {
156 .name = "archer-c59-v2:green:wlan2g",
157 .gpio = ARCHER_C59_74HC_GPIO_LED_WLAN2,
158 .active_low = 1,
159 },
160 {
161 .name = "archer-c59-v2:green:wlan5g",
162 .gpio = ARCHER_C59_74HC_GPIO_LED_WLAN5,
163 .active_low = 1,
164 },
165 {
166 .name = "archer-c59-v2:green:lan",
167 .gpio = ARCHER_C59_74HC_GPIO_LED_LAN,
168 .active_low = 1,
169 },
170 {
171 .name = "archer-c59-v2:green:wan",
172 .gpio = ARCHER_C59_74HC_GPIO_LED_WAN_GREEN,
173 .active_low = 1,
174 },
175 {
176 .name = "archer-c59-v2:amber:wan",
177 .gpio = ARCHER_C59_74HC_GPIO_LED_WAN_AMBER,
178 .active_low = 1,
179 },
180 {
181 .name = "archer-c59-v2:green:wps",
182 .gpio = ARCHER_C59_74HC_GPIO_LED_WPS,
183 .active_low = 1,
184 },
185 {
186 .name = "archer-c59-v2:green:usb",
187 .gpio = ARCHER_C59_74HC_GPIO_LED_USB,
188 .active_low = 1,
189 },
190 };
191
192 static struct gpio_keys_button archer_c59_v1_gpio_keys[] __initdata = {
193 {
194 .desc = "Reset button",
195 .type = EV_KEY,
196 .code = KEY_RESTART,
197 .debounce_interval = ARCHER_C59_V1_KEYS_DEBOUNCE_INTERVAL,
198 .gpio = ARCHER_C59_V1_GPIO_BTN_RESET,
199 .active_low = 1,
200 },
201 {
202 .desc = "RFKILL button",
203 .type = EV_KEY,
204 .code = KEY_RFKILL,
205 .debounce_interval = ARCHER_C59_V1_KEYS_DEBOUNCE_INTERVAL,
206 .gpio = ARCHER_C59_V1_GPIO_BTN_RFKILL,
207 .active_low = 1,
208 },
209 {
210 .desc = "WPS button",
211 .type = EV_KEY,
212 .code = KEY_WPS_BUTTON,
213 .debounce_interval = ARCHER_C59_V1_KEYS_DEBOUNCE_INTERVAL,
214 .gpio = ARCHER_C59_V1_GPIO_BTN_WPS,
215 .active_low = 1,
216 },
217 };
218
219 static struct spi_gpio_platform_data archer_c59_v1_spi_data = {
220 .sck = ARCHER_C59_GPIO_SHIFT_SRCLK,
221 .miso = SPI_GPIO_NO_MISO,
222 .mosi = ARCHER_C59_GPIO_SHIFT_SER,
223 .num_chipselect = 1,
224 };
225
226 static u8 archer_c59_v1_ssr_initdata[] = {
227 BIT(ARCHER_C59_V1_SSR_BIT_7) |
228 BIT(ARCHER_C59_V1_SSR_BIT_6) |
229 BIT(ARCHER_C59_V1_SSR_BIT_5) |
230 BIT(ARCHER_C59_V1_SSR_BIT_4) |
231 BIT(ARCHER_C59_V1_SSR_BIT_3) |
232 BIT(ARCHER_C59_V1_SSR_BIT_2) |
233 BIT(ARCHER_C59_V1_SSR_BIT_1)
234 };
235
236 static struct gen_74x164_chip_platform_data archer_c59_v1_ssr_data = {
237 .base = ARCHER_C59_74HC_GPIO_BASE,
238 .num_registers = ARRAY_SIZE(archer_c59_v1_ssr_initdata),
239 .init_data = archer_c59_v1_ssr_initdata,
240 };
241
242 static struct platform_device archer_c59_v1_spi_device = {
243 .name = "spi_gpio",
244 .id = 1,
245 .dev = {
246 .platform_data = &archer_c59_v1_spi_data,
247 },
248 };
249
250 static struct spi_board_info archer_c59_v1_spi_info[] = {
251 {
252 .bus_num = 1,
253 .chip_select = 0,
254 .max_speed_hz = 10000000,
255 .modalias = "74x164",
256 .platform_data = &archer_c59_v1_ssr_data,
257 .controller_data = (void *) ARCHER_C59_GPIO_SHIFT_RCLK,
258 },
259 };
260
261 static void __init archer_c5x_v1_setup(u32 macLocation)
262 {
263 u8 *mac = (u8 *) KSEG1ADDR(macLocation);
264 u8 *art = (u8 *) KSEG1ADDR(0x1fff0000);
265
266 ath79_register_m25p80(NULL);
267 spi_register_board_info(archer_c59_v1_spi_info,
268 ARRAY_SIZE(archer_c59_v1_spi_info));
269 platform_device_register(&archer_c59_v1_spi_device);
270
271 ath79_register_gpio_keys_polled(-1, ARCHER_C59_V1_KEYS_POLL_INTERVAL,
272 ARRAY_SIZE(archer_c59_v1_gpio_keys),
273 archer_c59_v1_gpio_keys);
274
275 ath79_setup_qca956x_eth_cfg(QCA956X_ETH_CFG_SW_PHY_SWAP |
276 QCA956X_ETH_CFG_SW_PHY_ADDR_SWAP);
277
278 ath79_register_mdio(0, 0x0);
279 ath79_register_mdio(1, 0x0);
280
281 ath79_init_mac(ath79_eth0_data.mac_addr, mac, 1);
282 ath79_init_mac(ath79_eth1_data.mac_addr, mac, 0);
283
284 /* WAN port */
285 ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
286 ath79_eth0_data.speed = SPEED_100;
287 ath79_eth0_data.duplex = DUPLEX_FULL;
288 ath79_eth0_data.phy_mask = BIT(0);
289 ath79_register_eth(0);
290
291 /* LAN ports */
292 ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_GMII;
293 ath79_eth1_data.speed = SPEED_1000;
294 ath79_eth1_data.duplex = DUPLEX_FULL;
295 ath79_switch_data.phy_poll_mask |= BIT(0);
296 ath79_switch_data.phy4_mii_en = 1;
297 ath79_register_eth(1);
298
299 ath79_register_wmac(art + ARCHER_C59_V1_WMAC_CALDATA_OFFSET, mac);
300 ap91_pci_init(art + ARCHER_C59_V1_PCI_CALDATA_OFFSET, NULL);
301
302 ath79_register_usb();
303 gpio_request_one(ARCHER_C59_V1_GPIO_USB_POWER,
304 GPIOF_OUT_INIT_HIGH | GPIOF_EXPORT_DIR_FIXED,
305 "USB power");
306 gpio_request_one(ARCHER_C59_GPIO_SHIFT_OE,
307 GPIOF_OUT_INIT_LOW | GPIOF_EXPORT_DIR_FIXED,
308 "LED control");
309 gpio_request_one(ARCHER_C59_GPIO_SHIFT_SRCLR,
310 GPIOF_OUT_INIT_HIGH | GPIOF_EXPORT_DIR_FIXED,
311 "LED reset");
312 }
313
314 static void __init archer_c58_v1_setup(void)
315 {
316 archer_c5x_v1_setup(0x1f010008);
317 ath79_register_leds_gpio(-1, ARRAY_SIZE(archer_c58_v1_leds_gpio),
318 archer_c58_v1_leds_gpio);
319 }
320
321 MIPS_MACHINE(ATH79_MACH_ARCHER_C58_V1, "ARCHER-C58-V1",
322 "TP-LINK Archer C58 v1", archer_c58_v1_setup);
323
324 static void __init archer_c59_v1_setup(void)
325 {
326 archer_c5x_v1_setup(0x1f010008);
327 ath79_register_leds_gpio(-1, ARRAY_SIZE(archer_c59_v1_leds_gpio),
328 archer_c59_v1_leds_gpio);
329 }
330
331 MIPS_MACHINE(ATH79_MACH_ARCHER_C59_V1, "ARCHER-C59-V1",
332 "TP-LINK Archer C59 v1", archer_c59_v1_setup);
333
334 static void __init archer_c59_v2_setup(void)
335 {
336 archer_c5x_v1_setup(0x1f030008);
337 ath79_register_leds_gpio(-1, ARRAY_SIZE(archer_c59_v2_leds_gpio),
338 archer_c59_v2_leds_gpio);
339 }
340
341 MIPS_MACHINE(ATH79_MACH_ARCHER_C59_V2, "ARCHER-C59-V2",
342 "TP-LINK Archer C59 v2", archer_c59_v2_setup);