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