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>
9 * Derived from: mach-dir-869-a1.c
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License version 2 as published
13 * by the Free Software Foundation.
17 #include <linux/gpio.h>
18 #include <linux/init.h>
19 #include <linux/pci.h>
20 #include <linux/platform_device.h>
21 #include <linux/ath9k_platform.h>
23 #include <asm/mach-ath79/ath79.h>
24 #include <asm/mach-ath79/irq.h>
25 #include <asm/mach-ath79/ar71xx_regs.h>
27 #include <linux/platform_data/phy-at803x.h>
28 #include <linux/ar8216_platform.h>
31 #include "dev-ap9x-pci.h"
33 #include "dev-gpio-buttons.h"
34 #include "dev-leds-gpio.h"
35 #include "dev-m25p80.h"
38 #include "machtypes.h"
41 #define TL_WR1043_V4_GPIO_BTN_RESET 2
42 #define TL_WR1043_V4_GPIO_BTN_RFKILL 5
44 #define TL_WR1043_V4_GPIO_LED_WLAN 19
45 #define TL_WR1043_V4_GPIO_LED_USB 7
46 #define TL_WR1043_V4_GPIO_LED_WPS 1
47 #define TL_WR1043_V4_GPIO_LED_SYSTEM 6
49 #define TL_WR1043_V4_GPIO_USB_POWER 8
51 #define TL_WR1043_V4_GPIO_LED_WAN 15
52 #define TL_WR1043_V4_GPIO_LED_LAN1 9
53 #define TL_WR1043_V4_GPIO_LED_LAN2 14
54 #define TL_WR1043_V4_GPIO_LED_LAN3 21
55 #define TL_WR1043_V4_GPIO_LED_LAN4 20
57 #define TL_WR1043_V4_KEYS_POLL_INTERVAL 20 /* msecs */
58 #define TL_WR1043_V4_KEYS_DEBOUNCE_INTERVAL (3 * TL_WR1043_V4_KEYS_POLL_INTERVAL)
60 #define TL_WR1043_V4_MAC_LOCATION 0x1ff80174
62 #define TL_WR1043_V4_EEPROM_ADDR 0x1fff0000
63 #define TL_WR1043_V4_WMAC_CALDATA_OFFSET 0x1000
65 static struct gpio_led tl_wr1043nd_v4_leds_gpio[] __initdata = {
67 .name = "tp-link:green:wps",
68 .gpio = TL_WR1043_V4_GPIO_LED_WPS,
72 .name = "tp-link:green:system",
73 .gpio = TL_WR1043_V4_GPIO_LED_SYSTEM,
77 .name = "tp-link:green:wlan",
78 .gpio = TL_WR1043_V4_GPIO_LED_WLAN,
82 .name = "tp-link:green:usb",
83 .gpio = TL_WR1043_V4_GPIO_LED_USB,
87 .name = "tp-link:green:wan",
88 .gpio = TL_WR1043_V4_GPIO_LED_WAN,
92 .name = "tp-link:green:lan1",
93 .gpio = TL_WR1043_V4_GPIO_LED_LAN1,
97 .name = "tp-link:green:lan2",
98 .gpio = TL_WR1043_V4_GPIO_LED_LAN2,
102 .name = "tp-link:green:lan3",
103 .gpio = TL_WR1043_V4_GPIO_LED_LAN3,
107 .name = "tp-link:green:lan4",
108 .gpio = TL_WR1043_V4_GPIO_LED_LAN4,
113 static struct gpio_keys_button tl_wr1043nd_v4_gpio_keys[] __initdata = {
115 .desc = "Reset button",
118 .debounce_interval = TL_WR1043_V4_KEYS_DEBOUNCE_INTERVAL,
119 .gpio = TL_WR1043_V4_GPIO_BTN_RESET,
123 .desc = "RFKILL button",
126 .debounce_interval = TL_WR1043_V4_KEYS_DEBOUNCE_INTERVAL,
127 .gpio = TL_WR1043_V4_GPIO_BTN_RFKILL,
132 static struct ar8327_pad_cfg tl_wr1043nd_v4_ar8327_pad0_cfg = {
133 .mode = AR8327_PAD_MAC_SGMII,
134 .sgmii_delay_en = true,
137 static struct ar8327_platform_data tl_wr1043nd_v4_ar8327_data = {
138 .pad0_cfg = &tl_wr1043nd_v4_ar8327_pad0_cfg,
141 .speed = AR8327_PORT_SPEED_1000,
148 static struct mdio_board_info tl_wr1043nd_v4_mdio0_info[] = {
150 .bus_id = "ag71xx-mdio.0",
152 .platform_data = &tl_wr1043nd_v4_ar8327_data,
156 static void __init tl_wr1043nd_v4_setup(void)
158 u8 *mac = (u8 *) KSEG1ADDR(TL_WR1043_V4_MAC_LOCATION);
159 u8 *eeprom = (u8 *) KSEG1ADDR(TL_WR1043_V4_EEPROM_ADDR);
161 ath79_register_m25p80(NULL);
163 ath79_init_mac(ath79_eth0_data.mac_addr, mac, 0);
164 ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_SGMII;
165 ath79_eth0_data.mii_bus_dev = &ath79_mdio0_device.dev;
166 ath79_eth0_data.phy_mask = BIT(0);
168 mdiobus_register_board_info(tl_wr1043nd_v4_mdio0_info,
169 ARRAY_SIZE(tl_wr1043nd_v4_mdio0_info));
171 ath79_register_usb();
172 ath79_register_mdio(0, 0);
173 ath79_register_eth(0);
175 ath79_register_wmac(eeprom + TL_WR1043_V4_WMAC_CALDATA_OFFSET, mac);
177 ath79_register_leds_gpio(-1, ARRAY_SIZE(tl_wr1043nd_v4_leds_gpio),
178 tl_wr1043nd_v4_leds_gpio);
180 ath79_register_gpio_keys_polled(-1, TL_WR1043_V4_KEYS_POLL_INTERVAL,
181 ARRAY_SIZE(tl_wr1043nd_v4_gpio_keys),
182 tl_wr1043nd_v4_gpio_keys);
184 gpio_request_one(TL_WR1043_V4_GPIO_USB_POWER,
185 GPIOF_OUT_INIT_HIGH | GPIOF_EXPORT_DIR_FIXED,
189 MIPS_MACHINE(ATH79_MACH_TL_WR1043ND_V4, "TL-WR1043ND-v4",
190 "TP-LINK TL-WR1043ND v4", tl_wr1043nd_v4_setup);