ar71xx: fix MAC addresses on TP-Link TL-WR1043ND v4
[openwrt/openwrt.git] / target / linux / ar71xx / files / arch / mips / ath79 / mach-tl-wr1043nd-v4.c
1 /*
2 * TP-LINK WR1043 V4 support
3 *
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 *
9 * Derived from: mach-dir-869-a1.c
10 *
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.
14 */
15
16
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>
22
23 #include <asm/mach-ath79/ath79.h>
24 #include <asm/mach-ath79/irq.h>
25 #include <asm/mach-ath79/ar71xx_regs.h>
26
27 #include <linux/platform_data/phy-at803x.h>
28 #include <linux/ar8216_platform.h>
29
30 #include "common.h"
31 #include "dev-ap9x-pci.h"
32 #include "dev-eth.h"
33 #include "dev-gpio-buttons.h"
34 #include "dev-leds-gpio.h"
35 #include "dev-m25p80.h"
36 #include "dev-wmac.h"
37 #include "dev-usb.h"
38 #include "machtypes.h"
39 #include "nvram.h"
40
41 #define TL_WR1043_V4_GPIO_BTN_RESET 2
42 #define TL_WR1043_V4_GPIO_BTN_RFKILL 5
43
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
48
49 #define TL_WR1043_V4_GPIO_USB_POWER 8
50
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
56
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)
59
60 #define TL_WR1043_V4_MAC_LOCATION 0x1ff50008
61
62 #define TL_WR1043_V4_EEPROM_ADDR 0x1fff0000
63 #define TL_WR1043_V4_WMAC_CALDATA_OFFSET 0x1000
64
65 static struct gpio_led tl_wr1043nd_v4_leds_gpio[] __initdata = {
66 {
67 .name = "tp-link:green:wps",
68 .gpio = TL_WR1043_V4_GPIO_LED_WPS,
69 .active_low = 1,
70 },
71 {
72 .name = "tp-link:green:system",
73 .gpio = TL_WR1043_V4_GPIO_LED_SYSTEM,
74 .active_low = 1,
75 },
76 {
77 .name = "tp-link:green:wlan",
78 .gpio = TL_WR1043_V4_GPIO_LED_WLAN,
79 .active_low = 1,
80 },
81 {
82 .name = "tp-link:green:usb",
83 .gpio = TL_WR1043_V4_GPIO_LED_USB,
84 .active_low = 1,
85 },
86 {
87 .name = "tp-link:green:wan",
88 .gpio = TL_WR1043_V4_GPIO_LED_WAN,
89 .active_low = 1,
90 },
91 {
92 .name = "tp-link:green:lan1",
93 .gpio = TL_WR1043_V4_GPIO_LED_LAN1,
94 .active_low = 1,
95 },
96 {
97 .name = "tp-link:green:lan2",
98 .gpio = TL_WR1043_V4_GPIO_LED_LAN2,
99 .active_low = 1,
100 },
101 {
102 .name = "tp-link:green:lan3",
103 .gpio = TL_WR1043_V4_GPIO_LED_LAN3,
104 .active_low = 1,
105 },
106 {
107 .name = "tp-link:green:lan4",
108 .gpio = TL_WR1043_V4_GPIO_LED_LAN4,
109 .active_low = 1,
110 },
111 };
112
113 static struct gpio_keys_button tl_wr1043nd_v4_gpio_keys[] __initdata = {
114 {
115 .desc = "Reset button",
116 .type = EV_KEY,
117 .code = KEY_RESTART,
118 .debounce_interval = TL_WR1043_V4_KEYS_DEBOUNCE_INTERVAL,
119 .gpio = TL_WR1043_V4_GPIO_BTN_RESET,
120 .active_low = 1,
121 },
122 {
123 .desc = "RFKILL button",
124 .type = EV_KEY,
125 .code = KEY_RFKILL,
126 .debounce_interval = TL_WR1043_V4_KEYS_DEBOUNCE_INTERVAL,
127 .gpio = TL_WR1043_V4_GPIO_BTN_RFKILL,
128 .active_low = 1,
129 },
130 };
131
132 static struct ar8327_pad_cfg tl_wr1043nd_v4_ar8327_pad0_cfg = {
133 .mode = AR8327_PAD_MAC_SGMII,
134 .sgmii_delay_en = true,
135 };
136
137 static struct ar8327_platform_data tl_wr1043nd_v4_ar8327_data = {
138 .pad0_cfg = &tl_wr1043nd_v4_ar8327_pad0_cfg,
139 .port0_cfg = {
140 .force_link = 1,
141 .speed = AR8327_PORT_SPEED_1000,
142 .duplex = 1,
143 .txpause = 1,
144 .rxpause = 1,
145 },
146 };
147
148 static struct mdio_board_info tl_wr1043nd_v4_mdio0_info[] = {
149 {
150 .bus_id = "ag71xx-mdio.0",
151 .phy_addr = 0,
152 .platform_data = &tl_wr1043nd_v4_ar8327_data,
153 },
154 };
155
156 static void __init tl_wr1043nd_v4_setup(void)
157 {
158 u8 *mac = (u8 *) KSEG1ADDR(TL_WR1043_V4_MAC_LOCATION);
159 u8 *eeprom = (u8 *) KSEG1ADDR(TL_WR1043_V4_EEPROM_ADDR);
160
161 ath79_register_m25p80(NULL);
162
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);
167
168 mdiobus_register_board_info(tl_wr1043nd_v4_mdio0_info,
169 ARRAY_SIZE(tl_wr1043nd_v4_mdio0_info));
170
171 ath79_register_usb();
172 ath79_register_mdio(0, 0);
173 ath79_register_eth(0);
174
175 ath79_register_wmac(eeprom + TL_WR1043_V4_WMAC_CALDATA_OFFSET, mac);
176
177 ath79_register_leds_gpio(-1, ARRAY_SIZE(tl_wr1043nd_v4_leds_gpio),
178 tl_wr1043nd_v4_leds_gpio);
179
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);
183
184 gpio_request_one(TL_WR1043_V4_GPIO_USB_POWER,
185 GPIOF_OUT_INIT_HIGH | GPIOF_EXPORT_DIR_FIXED,
186 "USB power");
187 }
188
189 MIPS_MACHINE(ATH79_MACH_TL_WR1043ND_V4, "TL-WR1043ND-v4",
190 "TP-LINK TL-WR1043ND v4", tl_wr1043nd_v4_setup);