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_WAN 15
53 #define TL_WR1043_V4_GPIO_LED_LAN1 9
54 #define TL_WR1043_V4_GPIO_LED_LAN2 14
55 #define TL_WR1043_V4_GPIO_LED_LAN3 21
56 #define TL_WR1043_V4_GPIO_LED_LAN4 20
58 #define TL_WR1043_V4_KEYS_POLL_INTERVAL 20 /* msecs */
59 #define TL_WR1043_V4_KEYS_DEBOUNCE_INTERVAL (3 * TL_WR1043_V4_KEYS_POLL_INTERVAL)
61 #define TL_WR1043_V4_MAC_LOCATION 0x1ff50008
63 #define TL_WR1043_V4_EEPROM_ADDR 0x1fff0000
64 #define TL_WR1043_V4_WMAC_CALDATA_OFFSET 0x1000
66 #define TL_WR1043N_V5_MAC_LOCATION 0x1ff00008
68 static struct gpio_led tl_wr1043nd_v4_leds_gpio
[] __initdata
= {
70 .name
= "tp-link:green:wps",
71 .gpio
= TL_WR1043_V4_GPIO_LED_WPS
,
75 .name
= "tp-link:green:system",
76 .gpio
= TL_WR1043_V4_GPIO_LED_SYSTEM
,
80 .name
= "tp-link:green:wlan",
81 .gpio
= TL_WR1043_V4_GPIO_LED_WLAN
,
85 .name
= "tp-link:green:usb",
86 .gpio
= TL_WR1043_V4_GPIO_LED_USB
,
90 .name
= "tp-link:green:wan",
91 .gpio
= TL_WR1043_V4_GPIO_LED_WAN
,
95 .name
= "tp-link:green:lan1",
96 .gpio
= TL_WR1043_V4_GPIO_LED_LAN1
,
100 .name
= "tp-link:green:lan2",
101 .gpio
= TL_WR1043_V4_GPIO_LED_LAN2
,
105 .name
= "tp-link:green:lan3",
106 .gpio
= TL_WR1043_V4_GPIO_LED_LAN3
,
110 .name
= "tp-link:green:lan4",
111 .gpio
= TL_WR1043_V4_GPIO_LED_LAN4
,
116 static struct gpio_keys_button tl_wr1043nd_v4_gpio_keys
[] __initdata
= {
118 .desc
= "Reset button",
121 .debounce_interval
= TL_WR1043_V4_KEYS_DEBOUNCE_INTERVAL
,
122 .gpio
= TL_WR1043_V4_GPIO_BTN_RESET
,
126 .desc
= "RFKILL button",
129 .debounce_interval
= TL_WR1043_V4_KEYS_DEBOUNCE_INTERVAL
,
130 .gpio
= TL_WR1043_V4_GPIO_BTN_RFKILL
,
135 static struct ar8327_pad_cfg tl_wr1043nd_v4_ar8327_pad0_cfg
= {
136 .mode
= AR8327_PAD_MAC_SGMII
,
137 .sgmii_delay_en
= true,
140 static struct ar8327_platform_data tl_wr1043nd_v4_ar8327_data
= {
141 .pad0_cfg
= &tl_wr1043nd_v4_ar8327_pad0_cfg
,
144 .speed
= AR8327_PORT_SPEED_1000
,
151 static struct mdio_board_info tl_wr1043nd_v4_mdio0_info
[] = {
153 .bus_id
= "ag71xx-mdio.0",
155 .platform_data
= &tl_wr1043nd_v4_ar8327_data
,
159 static void __init
tl_wr1043nd_v4_setup(void)
161 u8
*mac
= (u8
*) KSEG1ADDR(TL_WR1043_V4_MAC_LOCATION
);
162 u8
*eeprom
= (u8
*) KSEG1ADDR(TL_WR1043_V4_EEPROM_ADDR
);
164 ath79_register_m25p80(NULL
);
166 ath79_init_mac(ath79_eth0_data
.mac_addr
, mac
, 0);
167 ath79_eth0_data
.phy_if_mode
= PHY_INTERFACE_MODE_SGMII
;
168 ath79_eth0_data
.mii_bus_dev
= &ath79_mdio0_device
.dev
;
169 ath79_eth0_data
.phy_mask
= BIT(0);
171 mdiobus_register_board_info(tl_wr1043nd_v4_mdio0_info
,
172 ARRAY_SIZE(tl_wr1043nd_v4_mdio0_info
));
174 ath79_register_usb();
175 ath79_register_mdio(0, 0);
176 ath79_register_eth(0);
178 ath79_register_wmac(eeprom
+ TL_WR1043_V4_WMAC_CALDATA_OFFSET
, mac
);
180 ath79_register_leds_gpio(-1, ARRAY_SIZE(tl_wr1043nd_v4_leds_gpio
),
181 tl_wr1043nd_v4_leds_gpio
);
183 ath79_register_gpio_keys_polled(-1, TL_WR1043_V4_KEYS_POLL_INTERVAL
,
184 ARRAY_SIZE(tl_wr1043nd_v4_gpio_keys
),
185 tl_wr1043nd_v4_gpio_keys
);
187 gpio_request_one(TL_WR1043_V4_GPIO_USB_POWER
,
188 GPIOF_OUT_INIT_HIGH
| GPIOF_EXPORT_DIR_FIXED
,
192 MIPS_MACHINE(ATH79_MACH_TL_WR1043ND_V4
, "TL-WR1043ND-v4",
193 "TP-LINK TL-WR1043ND v4", tl_wr1043nd_v4_setup
);
195 static struct gpio_led tl_wr1043n_v5_leds_gpio
[] __initdata
= {
197 .name
= "tp-link:green:wps",
198 .gpio
= TL_WR1043_V4_GPIO_LED_WPS
,
202 .name
= "tp-link:green:system",
203 .gpio
= TL_WR1043_V4_GPIO_LED_SYSTEM
,
207 .name
= "tp-link:green:wlan",
208 .gpio
= TL_WR1043_V4_GPIO_LED_WLAN
,
212 .name
= "tp-link:green:wan",
213 .gpio
= TL_WR1043_V4_GPIO_LED_WAN
,
217 .name
= "tp-link:green:lan1",
218 .gpio
= TL_WR1043_V4_GPIO_LED_LAN1
,
222 .name
= "tp-link:green:lan2",
223 .gpio
= TL_WR1043_V4_GPIO_LED_LAN2
,
227 .name
= "tp-link:green:lan3",
228 .gpio
= TL_WR1043_V4_GPIO_LED_LAN3
,
232 .name
= "tp-link:green:lan4",
233 .gpio
= TL_WR1043_V4_GPIO_LED_LAN4
,
238 /* The 1043Nv5 is identical to the 1043NDv4,
239 * only missing the usb and small firmware layout changes */
240 static void __init
tl_wr1043nv5_setup(void)
242 u8
*art
= (u8
*) KSEG1ADDR(TL_WR1043_V4_EEPROM_ADDR
);
243 u8
*mac
= (u8
*) KSEG1ADDR(TL_WR1043N_V5_MAC_LOCATION
);
245 ath79_register_m25p80(NULL
);
247 ath79_register_leds_gpio(-1, ARRAY_SIZE(tl_wr1043n_v5_leds_gpio
),
248 tl_wr1043n_v5_leds_gpio
);
249 ath79_register_gpio_keys_polled(-1, TL_WR1043_V4_KEYS_POLL_INTERVAL
,
250 ARRAY_SIZE(tl_wr1043nd_v4_gpio_keys
),
251 tl_wr1043nd_v4_gpio_keys
);
253 platform_device_register(&ath79_mdio0_device
);
255 mdiobus_register_board_info(tl_wr1043nd_v4_mdio0_info
,
256 ARRAY_SIZE(tl_wr1043nd_v4_mdio0_info
));
258 ath79_register_wmac(art
+ TL_WR1043_V4_WMAC_CALDATA_OFFSET
, mac
);
260 ath79_init_mac(ath79_eth0_data
.mac_addr
, mac
, 0);
262 /* GMAC0 is connected to an AR8337 switch */
263 ath79_eth0_data
.phy_if_mode
= PHY_INTERFACE_MODE_SGMII
;
264 ath79_eth0_data
.speed
= SPEED_1000
;
265 ath79_eth0_data
.duplex
= DUPLEX_FULL
;
266 ath79_eth0_data
.phy_mask
= BIT(0);
267 ath79_eth0_data
.mii_bus_dev
= &ath79_mdio0_device
.dev
;
268 ath79_register_eth(0);
271 MIPS_MACHINE(ATH79_MACH_TL_WR1043N_V5
, "TL-WR1043N-v5", "TP-LINK TL-WR1043N v5",