8d2074f4b8c5324c3534164be9171162c5912070
[openwrt.git] / target / linux / ar71xx / files / arch / mips / ath79 / mach-tl-wax50re.c
1 /*
2  *  TP-LINK TL-WA750RE v1/TL-WA801ND v2/TL-WA850RE v1 board support
3  *
4  *  Copyright (C) 2013 Martijn Zilverschoon <thefriedzombie@gmail.com>
5  *  Copyright (C) 2013 Jiri Pirko <jiri@resnulli.us>
6  *
7  *  This program is free software; you can redistribute it and/or modify it
8  *  under the terms of the GNU General Public License version 2 as published
9  *  by the Free Software Foundation.
10  */
11
12 #include <linux/gpio.h>
13 #include <linux/platform_device.h>
14
15 #include <asm/mach-ath79/ath79.h>
16 #include <asm/mach-ath79/ar71xx_regs.h>
17
18 #include "common.h"
19 #include "dev-eth.h"
20 #include "dev-gpio-buttons.h"
21 #include "dev-leds-gpio.h"
22 #include "dev-m25p80.h"
23 #include "dev-wmac.h"
24 #include "machtypes.h"
25
26 #define TL_WAX50RE_GPIO_LED_LAN         20
27 #define TL_WAX50RE_GPIO_LED_WLAN        13
28 #define TL_WAX50RE_GPIO_LED_RE          15
29 #define TL_WAX50RE_GPIO_LED_SIGNAL1     0
30 #define TL_WAX50RE_GPIO_LED_SIGNAL2     1
31 #define TL_WAX50RE_GPIO_LED_SIGNAL3     2
32 #define TL_WAX50RE_GPIO_LED_SIGNAL4     3
33 #define TL_WAX50RE_GPIO_LED_SIGNAL5     4
34
35 #define TL_WA801ND_V2_GPIO_LED_LAN      18
36 #define TL_WA801ND_V2_GPIO_LED_SYSTEM   14
37
38 #define TL_WAX50RE_GPIO_BTN_RESET       17
39 #define TL_WAX50RE_GPIO_BTN_WPS         16
40
41 #define TL_WAX50RE_KEYS_POLL_INTERVAL   20      /* msecs */
42 #define TL_WAX50RE_KEYS_DEBOUNCE_INTERVAL (3 * TL_WAX50RE_KEYS_POLL_INTERVAL)
43
44 static const char *tl_wax50re_part_probes[] = {
45         "tp-link",
46         NULL,
47 };
48
49 static struct flash_platform_data tl_wax50re_flash_data = {
50         .part_probes    = tl_wax50re_part_probes,
51 };
52
53 static struct gpio_led tl_wa750re_leds_gpio[] __initdata = {
54         {
55                 .name           = "tp-link:orange:lan",
56                 .gpio           = TL_WAX50RE_GPIO_LED_LAN,
57                 .active_low     = 1,
58         }, {
59                 .name           = "tp-link:orange:wlan",
60                 .gpio           = TL_WAX50RE_GPIO_LED_WLAN,
61                 .active_low     = 1,
62         }, {
63                 .name           = "tp-link:orange:re",
64                 .gpio           = TL_WAX50RE_GPIO_LED_RE,
65                 .active_low     = 1,
66         }, {
67                 .name           = "tp-link:orange:signal1",
68                 .gpio           = TL_WAX50RE_GPIO_LED_SIGNAL1,
69                 .active_low     = 1,
70         }, {
71                 .name           = "tp-link:orange:signal2",
72                 .gpio           = TL_WAX50RE_GPIO_LED_SIGNAL2,
73                 .active_low     = 1,
74         }, {
75                 .name           = "tp-link:orange:signal3",
76                 .gpio           = TL_WAX50RE_GPIO_LED_SIGNAL3,
77                 .active_low     = 1,
78         }, {
79                 .name           = "tp-link:orange:signal4",
80                 .gpio           = TL_WAX50RE_GPIO_LED_SIGNAL4,
81                 .active_low     = 1,
82         }, {
83                 .name           = "tp-link:orange:signal5",
84                 .gpio           = TL_WAX50RE_GPIO_LED_SIGNAL5,
85                 .active_low     = 1,
86         },
87 };
88
89 static struct gpio_led tl_wa850re_leds_gpio[] __initdata = {
90         {
91                 .name           = "tp-link:blue:lan",
92                 .gpio           = TL_WAX50RE_GPIO_LED_LAN,
93                 .active_low     = 1,
94         }, {
95                 .name           = "tp-link:blue:wlan",
96                 .gpio           = TL_WAX50RE_GPIO_LED_WLAN,
97                 .active_low     = 1,
98         }, {
99                 .name           = "tp-link:blue:re",
100                 .gpio           = TL_WAX50RE_GPIO_LED_RE,
101                 .active_low     = 1,
102         }, {
103                 .name           = "tp-link:blue:signal1",
104                 .gpio           = TL_WAX50RE_GPIO_LED_SIGNAL1,
105                 .active_low     = 1,
106         }, {
107                 .name           = "tp-link:blue:signal2",
108                 .gpio           = TL_WAX50RE_GPIO_LED_SIGNAL2,
109                 .active_low     = 1,
110         }, {
111                 .name           = "tp-link:blue:signal3",
112                 .gpio           = TL_WAX50RE_GPIO_LED_SIGNAL3,
113                 .active_low     = 1,
114         }, {
115                 .name           = "tp-link:blue:signal4",
116                 .gpio           = TL_WAX50RE_GPIO_LED_SIGNAL4,
117                 .active_low     = 1,
118         }, {
119                 .name           = "tp-link:blue:signal5",
120                 .gpio           = TL_WAX50RE_GPIO_LED_SIGNAL5,
121                 .active_low     = 1,
122         },
123 };
124
125
126 static struct gpio_keys_button tl_wax50re_gpio_keys[] __initdata = {
127         {
128                 .desc              = "Reset button",
129                 .type              = EV_KEY,
130                 .code              = KEY_RESTART,
131                 .debounce_interval = TL_WAX50RE_KEYS_DEBOUNCE_INTERVAL,
132                 .gpio              = TL_WAX50RE_GPIO_BTN_RESET,
133                 .active_low        = 1,
134         }, {
135                 .desc              = "WPS",
136                 .type              = EV_KEY,
137                 .code              = KEY_WPS_BUTTON,
138                 .debounce_interval = TL_WAX50RE_KEYS_DEBOUNCE_INTERVAL,
139                 .gpio              = TL_WAX50RE_GPIO_BTN_WPS,
140                 .active_low        = 1,
141         },
142 };
143
144 static struct gpio_led tl_wa801nd_v2_leds_gpio[] __initdata = {
145         {
146                 .name           = "tp-link:green:lan",
147                 .gpio           = TL_WA801ND_V2_GPIO_LED_LAN,
148                 .active_low     = 1,
149         }, {
150                 .name           = "tp-link:green:wlan",
151                 .gpio           = TL_WAX50RE_GPIO_LED_WLAN,
152                 .active_low     = 1,
153         }, {
154                 .name           = "tp-link:green:qss",
155                 .gpio           = TL_WAX50RE_GPIO_LED_RE,
156                 .active_low     = 1,
157         }, {
158                 .name           = "tp-link:green:system",
159                 .gpio           = TL_WA801ND_V2_GPIO_LED_SYSTEM,
160                 .active_low     = 1,
161         },
162 };
163
164 static void __init tl_ap123_setup(void)
165 {
166         u8 *mac = (u8 *) KSEG1ADDR(0x1f01fc00);
167         u8 *ee = (u8 *) KSEG1ADDR(0x1fff1000);
168
169         ath79_register_m25p80(&tl_wax50re_flash_data);
170
171         ath79_setup_ar934x_eth_cfg(AR934X_ETH_CFG_SW_PHY_SWAP);
172
173         ath79_register_mdio(1, 0x0);
174
175         ath79_init_mac(ath79_eth0_data.mac_addr, mac, 0);
176
177         ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
178         ath79_eth0_data.phy_mask = BIT(0);
179         ath79_eth0_data.mii_bus_dev = &ath79_mdio1_device.dev;
180         ath79_register_eth(0);
181
182         ath79_register_wmac(ee, mac);
183 }
184
185 static void  __init tl_wa750re_setup(void)
186 {
187         tl_ap123_setup();
188         ath79_register_leds_gpio(-1, ARRAY_SIZE(tl_wa750re_leds_gpio),
189                                  tl_wa750re_leds_gpio);
190
191         ath79_register_gpio_keys_polled(-1, TL_WAX50RE_KEYS_POLL_INTERVAL,
192                                         ARRAY_SIZE(tl_wax50re_gpio_keys),
193                                         tl_wax50re_gpio_keys);
194 }
195
196 MIPS_MACHINE(ATH79_MACH_TL_WA750RE, "TL-WA750RE", "TP-LINK TL-WA750RE",
197              tl_wa750re_setup);
198
199 static void __init tl_wa801nd_v2_setup(void)
200 {
201         tl_ap123_setup();
202         ath79_register_leds_gpio(-1, ARRAY_SIZE(tl_wa801nd_v2_leds_gpio),
203                         tl_wa801nd_v2_leds_gpio);
204
205         ath79_register_gpio_keys_polled(-1, TL_WAX50RE_KEYS_POLL_INTERVAL,
206                                         ARRAY_SIZE(tl_wax50re_gpio_keys),
207                                         tl_wax50re_gpio_keys);
208 }
209
210 MIPS_MACHINE(ATH79_MACH_TL_WA801ND_V2, "TL-WA801ND-v2", "TP-LINK TL-WA801ND v2",
211              tl_wa801nd_v2_setup);
212
213 static void  __init tl_wa850re_setup(void)
214 {
215         tl_ap123_setup();
216         ath79_register_leds_gpio(-1, ARRAY_SIZE(tl_wa850re_leds_gpio),
217                                  tl_wa850re_leds_gpio);
218
219         ath79_register_gpio_keys_polled(-1, TL_WAX50RE_KEYS_POLL_INTERVAL,
220                                         ARRAY_SIZE(tl_wax50re_gpio_keys),
221                                         tl_wax50re_gpio_keys);
222 }
223
224 MIPS_MACHINE(ATH79_MACH_TL_WA850RE, "TL-WA850RE", "TP-LINK TL-WA850RE",
225              tl_wa850re_setup);