2 * TP-Link Archer C58/C59 v1 board support
4 * Copyright (C) 2017 Henryk Heisig <hyniu@o2.pl>
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.
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>
20 #include "dev-m25p80.h"
21 #include "machtypes.h"
23 #include "dev-ap9x-pci.h"
25 #include "dev-gpio-buttons.h"
26 #include "dev-leds-gpio.h"
31 #define ARCHER_C59_V1_KEYS_POLL_INTERVAL 20
32 #define ARCHER_C59_V1_KEYS_DEBOUNCE_INTERVAL (3 * ARCHER_C59_V1_KEYS_POLL_INTERVAL)
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
38 #define ARCHER_C59_V1_GPIO_USB_POWER 22
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
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)
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
65 #define ARCHER_C59_V1_WMAC_CALDATA_OFFSET 0x1000
66 #define ARCHER_C59_V1_PCI_CALDATA_OFFSET 0x5000
68 static struct gpio_led archer_c58_v1_leds_gpio
[] __initdata
= {
70 .name
= "archer-c58-v1:green:power",
71 .gpio
= ARCHER_C59_74HC_GPIO_LED_POWER
,
75 .name
= "archer-c58-v1:green:wlan2g",
76 .gpio
= ARCHER_C59_74HC_GPIO_LED_WLAN2
,
80 .name
= "archer-c58-v1:green:wlan5g",
81 .gpio
= ARCHER_C59_74HC_GPIO_LED_WLAN5
,
85 .name
= "archer-c58-v1:green:lan",
86 .gpio
= ARCHER_C59_74HC_GPIO_LED_LAN
,
90 .name
= "archer-c58-v1:green:wan",
91 .gpio
= ARCHER_C59_74HC_GPIO_LED_WAN_GREEN
,
95 .name
= "archer-c58-v1:amber:wan",
96 .gpio
= ARCHER_C59_74HC_GPIO_LED_WAN_AMBER
,
100 .name
= "archer-c58-v1:green:wps",
101 .gpio
= ARCHER_C59_74HC_GPIO_LED_WPS
,
106 static struct gpio_led archer_c59_v1_leds_gpio
[] __initdata
= {
108 .name
= "archer-c59-v1:green:power",
109 .gpio
= ARCHER_C59_74HC_GPIO_LED_POWER
,
113 .name
= "archer-c59-v1:green:wlan2g",
114 .gpio
= ARCHER_C59_74HC_GPIO_LED_WLAN2
,
118 .name
= "archer-c59-v1:green:wlan5g",
119 .gpio
= ARCHER_C59_74HC_GPIO_LED_WLAN5
,
123 .name
= "archer-c59-v1:green:lan",
124 .gpio
= ARCHER_C59_74HC_GPIO_LED_LAN
,
128 .name
= "archer-c59-v1:green:wan",
129 .gpio
= ARCHER_C59_74HC_GPIO_LED_WAN_GREEN
,
133 .name
= "archer-c59-v1:amber:wan",
134 .gpio
= ARCHER_C59_74HC_GPIO_LED_WAN_AMBER
,
138 .name
= "archer-c59-v1:green:wps",
139 .gpio
= ARCHER_C59_74HC_GPIO_LED_WPS
,
143 .name
= "archer-c59-v1:green:usb",
144 .gpio
= ARCHER_C59_74HC_GPIO_LED_USB
,
149 static struct gpio_led archer_c59_v2_leds_gpio
[] __initdata
= {
151 .name
= "archer-c59-v2:green:power",
152 .gpio
= ARCHER_C59_74HC_GPIO_LED_POWER
,
156 .name
= "archer-c59-v2:green:wlan2g",
157 .gpio
= ARCHER_C59_74HC_GPIO_LED_WLAN2
,
161 .name
= "archer-c59-v2:green:wlan5g",
162 .gpio
= ARCHER_C59_74HC_GPIO_LED_WLAN5
,
166 .name
= "archer-c59-v2:green:lan",
167 .gpio
= ARCHER_C59_74HC_GPIO_LED_LAN
,
171 .name
= "archer-c59-v2:green:wan",
172 .gpio
= ARCHER_C59_74HC_GPIO_LED_WAN_GREEN
,
176 .name
= "archer-c59-v2:amber:wan",
177 .gpio
= ARCHER_C59_74HC_GPIO_LED_WAN_AMBER
,
181 .name
= "archer-c59-v2:green:wps",
182 .gpio
= ARCHER_C59_74HC_GPIO_LED_WPS
,
186 .name
= "archer-c59-v2:green:usb",
187 .gpio
= ARCHER_C59_74HC_GPIO_LED_USB
,
192 static struct gpio_keys_button archer_c59_v1_gpio_keys
[] __initdata
= {
194 .desc
= "Reset button",
197 .debounce_interval
= ARCHER_C59_V1_KEYS_DEBOUNCE_INTERVAL
,
198 .gpio
= ARCHER_C59_V1_GPIO_BTN_RESET
,
202 .desc
= "RFKILL button",
205 .debounce_interval
= ARCHER_C59_V1_KEYS_DEBOUNCE_INTERVAL
,
206 .gpio
= ARCHER_C59_V1_GPIO_BTN_RFKILL
,
210 .desc
= "WPS button",
212 .code
= KEY_WPS_BUTTON
,
213 .debounce_interval
= ARCHER_C59_V1_KEYS_DEBOUNCE_INTERVAL
,
214 .gpio
= ARCHER_C59_V1_GPIO_BTN_WPS
,
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
,
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
)
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
,
242 static struct platform_device archer_c59_v1_spi_device
= {
246 .platform_data
= &archer_c59_v1_spi_data
,
250 static struct spi_board_info archer_c59_v1_spi_info
[] = {
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
,
261 static void __init
archer_c5x_v1_setup(u32 macLocation
)
263 u8
*mac
= (u8
*) KSEG1ADDR(macLocation
);
264 u8
*art
= (u8
*) KSEG1ADDR(0x1fff0000);
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
);
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
);
275 ath79_setup_qca956x_eth_cfg(QCA956X_ETH_CFG_SW_PHY_SWAP
|
276 QCA956X_ETH_CFG_SW_PHY_ADDR_SWAP
);
278 ath79_register_mdio(0, 0x0);
279 ath79_register_mdio(1, 0x0);
281 ath79_init_mac(ath79_eth0_data
.mac_addr
, mac
, 1);
282 ath79_init_mac(ath79_eth1_data
.mac_addr
, mac
, 0);
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);
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);
299 ath79_register_wmac(art
+ ARCHER_C59_V1_WMAC_CALDATA_OFFSET
, mac
);
300 ap91_pci_init(art
+ ARCHER_C59_V1_PCI_CALDATA_OFFSET
, NULL
);
302 ath79_register_usb();
303 gpio_request_one(ARCHER_C59_V1_GPIO_USB_POWER
,
304 GPIOF_OUT_INIT_HIGH
| GPIOF_EXPORT_DIR_FIXED
,
306 gpio_request_one(ARCHER_C59_GPIO_SHIFT_OE
,
307 GPIOF_OUT_INIT_LOW
| GPIOF_EXPORT_DIR_FIXED
,
309 gpio_request_one(ARCHER_C59_GPIO_SHIFT_SRCLR
,
310 GPIOF_OUT_INIT_HIGH
| GPIOF_EXPORT_DIR_FIXED
,
314 static void __init
archer_c58_v1_setup(void)
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
);
321 MIPS_MACHINE(ATH79_MACH_ARCHER_C58_V1
, "ARCHER-C58-V1",
322 "TP-LINK Archer C58 v1", archer_c58_v1_setup
);
324 static void __init
archer_c59_v1_setup(void)
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
);
331 MIPS_MACHINE(ATH79_MACH_ARCHER_C59_V1
, "ARCHER-C59-V1",
332 "TP-LINK Archer C59 v1", archer_c59_v1_setup
);
334 static void __init
archer_c59_v2_setup(void)
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
);
341 MIPS_MACHINE(ATH79_MACH_ARCHER_C59_V2
, "ARCHER-C59-V2",
342 "TP-LINK Archer C59 v2", archer_c59_v2_setup
);