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_keys_button archer_c59_v1_gpio_keys
[] __initdata
= {
151 .desc
= "Reset button",
154 .debounce_interval
= ARCHER_C59_V1_KEYS_DEBOUNCE_INTERVAL
,
155 .gpio
= ARCHER_C59_V1_GPIO_BTN_RESET
,
159 .desc
= "RFKILL button",
162 .debounce_interval
= ARCHER_C59_V1_KEYS_DEBOUNCE_INTERVAL
,
163 .gpio
= ARCHER_C59_V1_GPIO_BTN_RFKILL
,
167 .desc
= "WPS button",
169 .code
= KEY_WPS_BUTTON
,
170 .debounce_interval
= ARCHER_C59_V1_KEYS_DEBOUNCE_INTERVAL
,
171 .gpio
= ARCHER_C59_V1_GPIO_BTN_WPS
,
176 static struct spi_gpio_platform_data archer_c59_v1_spi_data
= {
177 .sck
= ARCHER_C59_GPIO_SHIFT_SRCLK
,
178 .miso
= SPI_GPIO_NO_MISO
,
179 .mosi
= ARCHER_C59_GPIO_SHIFT_SER
,
183 static u8 archer_c59_v1_ssr_initdata
[] = {
184 BIT(ARCHER_C59_V1_SSR_BIT_7
) |
185 BIT(ARCHER_C59_V1_SSR_BIT_6
) |
186 BIT(ARCHER_C59_V1_SSR_BIT_5
) |
187 BIT(ARCHER_C59_V1_SSR_BIT_4
) |
188 BIT(ARCHER_C59_V1_SSR_BIT_3
) |
189 BIT(ARCHER_C59_V1_SSR_BIT_2
) |
190 BIT(ARCHER_C59_V1_SSR_BIT_1
)
193 static struct gen_74x164_chip_platform_data archer_c59_v1_ssr_data
= {
194 .base
= ARCHER_C59_74HC_GPIO_BASE
,
195 .num_registers
= ARRAY_SIZE(archer_c59_v1_ssr_initdata
),
196 .init_data
= archer_c59_v1_ssr_initdata
,
199 static struct platform_device archer_c59_v1_spi_device
= {
203 .platform_data
= &archer_c59_v1_spi_data
,
207 static struct spi_board_info archer_c59_v1_spi_info
[] = {
211 .max_speed_hz
= 10000000,
212 .modalias
= "74x164",
213 .platform_data
= &archer_c59_v1_ssr_data
,
214 .controller_data
= (void *) ARCHER_C59_GPIO_SHIFT_RCLK
,
218 static void __init
archer_c5x_v1_setup(void)
220 u8
*mac
= (u8
*) KSEG1ADDR(0x1f010008);
221 u8
*art
= (u8
*) KSEG1ADDR(0x1fff0000);
223 ath79_register_m25p80(NULL
);
224 spi_register_board_info(archer_c59_v1_spi_info
,
225 ARRAY_SIZE(archer_c59_v1_spi_info
));
226 platform_device_register(&archer_c59_v1_spi_device
);
228 ath79_register_gpio_keys_polled(-1, ARCHER_C59_V1_KEYS_POLL_INTERVAL
,
229 ARRAY_SIZE(archer_c59_v1_gpio_keys
),
230 archer_c59_v1_gpio_keys
);
232 ath79_setup_qca956x_eth_cfg(QCA956X_ETH_CFG_SW_PHY_SWAP
|
233 QCA956X_ETH_CFG_SW_PHY_ADDR_SWAP
);
235 ath79_register_mdio(0, 0x0);
236 ath79_register_mdio(1, 0x0);
238 ath79_init_mac(ath79_eth0_data
.mac_addr
, mac
, 1);
239 ath79_init_mac(ath79_eth1_data
.mac_addr
, mac
, 0);
242 ath79_eth0_data
.phy_if_mode
= PHY_INTERFACE_MODE_MII
;
243 ath79_eth0_data
.speed
= SPEED_100
;
244 ath79_eth0_data
.duplex
= DUPLEX_FULL
;
245 ath79_eth0_data
.phy_mask
= BIT(0);
246 ath79_register_eth(0);
249 ath79_eth1_data
.phy_if_mode
= PHY_INTERFACE_MODE_GMII
;
250 ath79_eth1_data
.speed
= SPEED_1000
;
251 ath79_eth1_data
.duplex
= DUPLEX_FULL
;
252 ath79_switch_data
.phy_poll_mask
|= BIT(4);
253 ath79_switch_data
.phy4_mii_en
= 1;
254 ath79_register_eth(1);
256 ath79_register_wmac(art
+ ARCHER_C59_V1_WMAC_CALDATA_OFFSET
, mac
);
257 ap91_pci_init(art
+ ARCHER_C59_V1_PCI_CALDATA_OFFSET
, NULL
);
259 ath79_register_usb();
260 gpio_request_one(ARCHER_C59_V1_GPIO_USB_POWER
,
261 GPIOF_OUT_INIT_HIGH
| GPIOF_EXPORT_DIR_FIXED
,
263 gpio_request_one(ARCHER_C59_GPIO_SHIFT_OE
,
264 GPIOF_OUT_INIT_LOW
| GPIOF_EXPORT_DIR_FIXED
,
266 gpio_request_one(ARCHER_C59_GPIO_SHIFT_SRCLR
,
267 GPIOF_OUT_INIT_HIGH
| GPIOF_EXPORT_DIR_FIXED
,
271 static void __init
archer_c58_v1_setup(void)
273 archer_c5x_v1_setup();
274 ath79_register_leds_gpio(-1, ARRAY_SIZE(archer_c58_v1_leds_gpio
),
275 archer_c58_v1_leds_gpio
);
278 MIPS_MACHINE(ATH79_MACH_ARCHER_C58_V1
, "ARCHER-C58-V1",
279 "TP-LINK Archer C58 v1", archer_c58_v1_setup
);
281 static void __init
archer_c59_v1_setup(void)
283 archer_c5x_v1_setup();
284 ath79_register_leds_gpio(-1, ARRAY_SIZE(archer_c59_v1_leds_gpio
),
285 archer_c59_v1_leds_gpio
);
288 MIPS_MACHINE(ATH79_MACH_ARCHER_C59_V1
, "ARCHER-C59-V1",
289 "TP-LINK Archer C59 v1", archer_c59_v1_setup
);