2 * TP-LINK WR1043 V4 support
4 * Copyright (C) 2015-2016 P. Wassi <p.wassi at gmx.at>
5 * Copyright (C) 2016 Matthias Schiffer <mschiffer@universe-factory.net>
6 * Copyright (C) 2016 Andreas Ziegler <github@andreas-ziegler.de>
7 * Copyright (C) 2016 Ludwig Thomeczek <ledesrc@wxorx.net>
8 * Copyright (C) 2017 Tim Thorpe <tim@tfthorpe.net>
10 * Derived from: mach-dir-869-a1.c
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License version 2 as published
14 * by the Free Software Foundation.
18 #include <linux/gpio.h>
19 #include <linux/init.h>
20 #include <linux/pci.h>
21 #include <linux/platform_device.h>
22 #include <linux/ath9k_platform.h>
24 #include <asm/mach-ath79/ath79.h>
25 #include <asm/mach-ath79/irq.h>
26 #include <asm/mach-ath79/ar71xx_regs.h>
28 #include <linux/platform_data/phy-at803x.h>
29 #include <linux/ar8216_platform.h>
32 #include "dev-ap9x-pci.h"
34 #include "dev-gpio-buttons.h"
35 #include "dev-leds-gpio.h"
36 #include "dev-m25p80.h"
39 #include "machtypes.h"
42 #define TL_WR1043_V4_GPIO_BTN_RESET 2
43 #define TL_WR1043_V4_GPIO_BTN_RFKILL 5
45 #define TL_WR1043_V4_GPIO_LED_WLAN 19
46 #define TL_WR1043_V4_GPIO_LED_USB 7
47 #define TL_WR1043_V4_GPIO_LED_WPS 1
48 #define TL_WR1043_V4_GPIO_LED_SYSTEM 6
50 #define TL_WR1043_V4_GPIO_USB_POWER 8
52 #define TL_WR1043_V4_GPIO_LED_INET 15
53 #define TL_WR1043_V4_GPIO_LED_WAN 16
54 #define TL_WR1043_V4_GPIO_LED_LAN1 9
55 #define TL_WR1043_V4_GPIO_LED_LAN2 14
56 #define TL_WR1043_V4_GPIO_LED_LAN3 21
57 #define TL_WR1043_V4_GPIO_LED_LAN4 20
59 #define TL_WR1043_V4_KEYS_POLL_INTERVAL 20 /* msecs */
60 #define TL_WR1043_V4_KEYS_DEBOUNCE_INTERVAL (3 * TL_WR1043_V4_KEYS_POLL_INTERVAL)
62 #define TL_WR1043_V4_MAC_LOCATION 0x1ff50008
64 #define TL_WR1043_V4_EEPROM_ADDR 0x1fff0000
65 #define TL_WR1043_V4_WMAC_CALDATA_OFFSET 0x1000
67 #define TL_WR1043_V5_MAC_LOCATION 0x1ff00008
69 static struct gpio_led tl_wr1043nd_v4_leds_gpio[] __initdata = {
71 .name = "tp-link:green:wps",
72 .gpio = TL_WR1043_V4_GPIO_LED_WPS,
76 .name = "tp-link:green:system",
77 .gpio = TL_WR1043_V4_GPIO_LED_SYSTEM,
81 .name = "tp-link:green:wlan",
82 .gpio = TL_WR1043_V4_GPIO_LED_WLAN,
86 .name = "tp-link:green:usb",
87 .gpio = TL_WR1043_V4_GPIO_LED_USB,
91 .name = "tp-link:green:wan",
92 .gpio = TL_WR1043_V4_GPIO_LED_INET,
96 .name = "tp-link:orange:wan",
97 .gpio = TL_WR1043_V4_GPIO_LED_WAN,
101 .name = "tp-link:green:lan1",
102 .gpio = TL_WR1043_V4_GPIO_LED_LAN1,
106 .name = "tp-link:green:lan2",
107 .gpio = TL_WR1043_V4_GPIO_LED_LAN2,
111 .name = "tp-link:green:lan3",
112 .gpio = TL_WR1043_V4_GPIO_LED_LAN3,
116 .name = "tp-link:green:lan4",
117 .gpio = TL_WR1043_V4_GPIO_LED_LAN4,
122 static struct gpio_keys_button tl_wr1043nd_v4_gpio_keys[] __initdata = {
124 .desc = "Reset button",
127 .debounce_interval = TL_WR1043_V4_KEYS_DEBOUNCE_INTERVAL,
128 .gpio = TL_WR1043_V4_GPIO_BTN_RESET,
132 .desc = "RFKILL button",
135 .debounce_interval = TL_WR1043_V4_KEYS_DEBOUNCE_INTERVAL,
136 .gpio = TL_WR1043_V4_GPIO_BTN_RFKILL,
141 static struct ar8327_pad_cfg tl_wr1043nd_v4_ar8327_pad0_cfg = {
142 .mode = AR8327_PAD_MAC_SGMII,
143 .sgmii_delay_en = true,
146 static struct ar8327_platform_data tl_wr1043nd_v4_ar8327_data = {
147 .pad0_cfg = &tl_wr1043nd_v4_ar8327_pad0_cfg,
150 .speed = AR8327_PORT_SPEED_1000,
157 static struct mdio_board_info tl_wr1043nd_v4_mdio0_info[] = {
159 .bus_id = "ag71xx-mdio.0",
161 .platform_data = &tl_wr1043nd_v4_ar8327_data,
165 static void __init tl_wr1043nd_v4_setup(void)
167 u8 *mac = (u8 *) KSEG1ADDR(TL_WR1043_V4_MAC_LOCATION);
168 u8 *eeprom = (u8 *) KSEG1ADDR(TL_WR1043_V4_EEPROM_ADDR);
170 ath79_register_m25p80(NULL);
172 ath79_init_mac(ath79_eth0_data.mac_addr, mac, 0);
173 ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_SGMII;
174 ath79_eth0_data.mii_bus_dev = &ath79_mdio0_device.dev;
175 ath79_eth0_data.phy_mask = BIT(0);
177 mdiobus_register_board_info(tl_wr1043nd_v4_mdio0_info,
178 ARRAY_SIZE(tl_wr1043nd_v4_mdio0_info));
180 ath79_register_usb();
181 ath79_register_mdio(0, 0);
182 ath79_register_eth(0);
184 ath79_register_wmac(eeprom + TL_WR1043_V4_WMAC_CALDATA_OFFSET, mac);
186 ath79_register_leds_gpio(-1, ARRAY_SIZE(tl_wr1043nd_v4_leds_gpio),
187 tl_wr1043nd_v4_leds_gpio);
189 ath79_register_gpio_keys_polled(-1, TL_WR1043_V4_KEYS_POLL_INTERVAL,
190 ARRAY_SIZE(tl_wr1043nd_v4_gpio_keys),
191 tl_wr1043nd_v4_gpio_keys);
193 gpio_request_one(TL_WR1043_V4_GPIO_USB_POWER,
194 GPIOF_OUT_INIT_HIGH | GPIOF_EXPORT_DIR_FIXED,
198 MIPS_MACHINE(ATH79_MACH_TL_WR1043ND_V4, "TL-WR1043ND-v4",
199 "TP-LINK TL-WR1043ND v4", tl_wr1043nd_v4_setup);
201 static struct gpio_led tl_wr1043n_v5_leds_gpio[] __initdata = {
203 .name = "tp-link:green:wps",
204 .gpio = TL_WR1043_V4_GPIO_LED_WPS,
208 .name = "tp-link:green:system",
209 .gpio = TL_WR1043_V4_GPIO_LED_SYSTEM,
213 .name = "tp-link:green:wlan",
214 .gpio = TL_WR1043_V4_GPIO_LED_WLAN,
218 .name = "tp-link:green:wan",
219 .gpio = TL_WR1043_V4_GPIO_LED_INET,
223 .name = "tp-link:orange:wan",
224 .gpio = TL_WR1043_V4_GPIO_LED_WAN,
228 .name = "tp-link:orange:wan",
229 .gpio = TL_WR1043_V5_GPIO_LED_WANORANGE,
233 .name = "tp-link:green:lan1",
234 .gpio = TL_WR1043_V4_GPIO_LED_LAN1,
238 .name = "tp-link:green:lan2",
239 .gpio = TL_WR1043_V4_GPIO_LED_LAN2,
243 .name = "tp-link:green:lan3",
244 .gpio = TL_WR1043_V4_GPIO_LED_LAN3,
248 .name = "tp-link:green:lan4",
249 .gpio = TL_WR1043_V4_GPIO_LED_LAN4,
254 /* The 1043Nv5 is identical to the 1043NDv4,
255 * only missing the usb and small firmware layout changes */
256 static void __init tl_wr1043nv5_setup(void)
258 u8 *art = (u8 *) KSEG1ADDR(TL_WR1043_V4_EEPROM_ADDR);
259 u8 *mac = (u8 *) KSEG1ADDR(TL_WR1043_V5_MAC_LOCATION);
261 ath79_register_m25p80(NULL);
263 ath79_register_leds_gpio(-1, ARRAY_SIZE(tl_wr1043n_v5_leds_gpio),
264 tl_wr1043n_v5_leds_gpio);
265 ath79_register_gpio_keys_polled(-1, TL_WR1043_V4_KEYS_POLL_INTERVAL,
266 ARRAY_SIZE(tl_wr1043nd_v4_gpio_keys),
267 tl_wr1043nd_v4_gpio_keys);
269 platform_device_register(&ath79_mdio0_device);
271 mdiobus_register_board_info(tl_wr1043nd_v4_mdio0_info,
272 ARRAY_SIZE(tl_wr1043nd_v4_mdio0_info));
274 ath79_register_wmac(art + TL_WR1043_V4_WMAC_CALDATA_OFFSET, mac);
276 ath79_init_mac(ath79_eth0_data.mac_addr, mac, 0);
278 /* GMAC0 is connected to an AR8337 switch */
279 ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_SGMII;
280 ath79_eth0_data.speed = SPEED_1000;
281 ath79_eth0_data.duplex = DUPLEX_FULL;
282 ath79_eth0_data.phy_mask = BIT(0);
283 ath79_eth0_data.mii_bus_dev = &ath79_mdio0_device.dev;
284 ath79_register_eth(0);
287 MIPS_MACHINE(ATH79_MACH_TL_WR1043N_V5, "TL-WR1043N-v5", "TP-LINK TL-WR1043N v5",