ar71xx: fix section mismatch
[openwrt/svn-archive/archive.git] / target / linux / ar71xx / files / arch / mips / ar71xx / mach-ubnt.c
1 /*
2 * Ubiquiti RouterStation support
3 *
4 * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
5 * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
6 * Copyright (C) 2008 Ubiquiti <support@ubnt.com>
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 2 as published
10 * by the Free Software Foundation.
11 */
12
13 #include <asm/mach-ar71xx/ar71xx.h>
14
15 #include "machtype.h"
16 #include "devices.h"
17 #include "dev-m25p80.h"
18 #include "dev-ap91-pci.h"
19 #include "dev-gpio-buttons.h"
20 #include "dev-pb42-pci.h"
21 #include "dev-leds-gpio.h"
22 #include "dev-usb.h"
23
24 #define UBNT_RS_GPIO_LED_RF 2
25 #define UBNT_RS_GPIO_SW4 8
26
27 #define UBNT_LS_SR71_GPIO_LED_D25 0
28 #define UBNT_LS_SR71_GPIO_LED_D26 1
29 #define UBNT_LS_SR71_GPIO_LED_D24 2
30 #define UBNT_LS_SR71_GPIO_LED_D23 4
31 #define UBNT_LS_SR71_GPIO_LED_D22 5
32 #define UBNT_LS_SR71_GPIO_LED_D27 6
33 #define UBNT_LS_SR71_GPIO_LED_D28 7
34
35 #define UBNT_M_GPIO_LED_L1 0
36 #define UBNT_M_GPIO_LED_L2 1
37 #define UBNT_M_GPIO_LED_L3 11
38 #define UBNT_M_GPIO_LED_L4 7
39 #define UBNT_M_GPIO_BTN_RESET 12
40
41 #define UBNT_BUTTONS_POLL_INTERVAL 20
42
43 static struct gpio_led ubnt_rs_leds_gpio[] __initdata = {
44 {
45 .name = "ubnt:green:rf",
46 .gpio = UBNT_RS_GPIO_LED_RF,
47 .active_low = 0,
48 }
49 };
50
51 static struct gpio_led ubnt_ls_sr71_leds_gpio[] __initdata = {
52 {
53 .name = "ubnt:green:d22",
54 .gpio = UBNT_LS_SR71_GPIO_LED_D22,
55 .active_low = 0,
56 }, {
57 .name = "ubnt:green:d23",
58 .gpio = UBNT_LS_SR71_GPIO_LED_D23,
59 .active_low = 0,
60 }, {
61 .name = "ubnt:green:d24",
62 .gpio = UBNT_LS_SR71_GPIO_LED_D24,
63 .active_low = 0,
64 }, {
65 .name = "ubnt:red:d25",
66 .gpio = UBNT_LS_SR71_GPIO_LED_D25,
67 .active_low = 0,
68 }, {
69 .name = "ubnt:red:d26",
70 .gpio = UBNT_LS_SR71_GPIO_LED_D26,
71 .active_low = 0,
72 }, {
73 .name = "ubnt:green:d27",
74 .gpio = UBNT_LS_SR71_GPIO_LED_D27,
75 .active_low = 0,
76 }, {
77 .name = "ubnt:green:d28",
78 .gpio = UBNT_LS_SR71_GPIO_LED_D28,
79 .active_low = 0,
80 }
81 };
82
83 static struct gpio_led ubnt_m_leds_gpio[] __initdata = {
84 {
85 .name = "ubnt:red:link1",
86 .gpio = UBNT_M_GPIO_LED_L1,
87 .active_low = 0,
88 }, {
89 .name = "ubnt:orange:link2",
90 .gpio = UBNT_M_GPIO_LED_L2,
91 .active_low = 0,
92 }, {
93 .name = "ubnt:green:link3",
94 .gpio = UBNT_M_GPIO_LED_L3,
95 .active_low = 0,
96 }, {
97 .name = "ubnt:green:link4",
98 .gpio = UBNT_M_GPIO_LED_L4,
99 .active_low = 0,
100 }
101 };
102
103 static struct gpio_button ubnt_gpio_buttons[] __initdata = {
104 {
105 .desc = "sw4",
106 .type = EV_KEY,
107 .code = KEY_RESTART,
108 .threshold = 3,
109 .gpio = UBNT_RS_GPIO_SW4,
110 .active_low = 1,
111 }
112 };
113
114 static struct gpio_button ubnt_m_gpio_buttons[] __initdata = {
115 {
116 .desc = "reset",
117 .type = EV_KEY,
118 .code = KEY_RESTART,
119 .threshold = 3,
120 .gpio = UBNT_M_GPIO_BTN_RESET,
121 .active_low = 1,
122 }
123 };
124
125 static void __init ubnt_generic_setup(void)
126 {
127 ar71xx_add_device_m25p80(NULL);
128
129 ar71xx_add_device_gpio_buttons(-1, UBNT_BUTTONS_POLL_INTERVAL,
130 ARRAY_SIZE(ubnt_gpio_buttons),
131 ubnt_gpio_buttons);
132
133 pb42_pci_init();
134 }
135
136 /*
137 * There is Secondary MAC address duplicate problem with some UBNT HW batches.
138 * Do not increase Secondary MAC address by 1 but do workaround
139 * with 'Locally Administrated' bit.
140 */
141 static void __init ubnt_init_secondary_mac(unsigned char *mac_base)
142 {
143 ar71xx_init_mac(ar71xx_eth1_data.mac_addr, mac_base, 0);
144 ar71xx_eth1_data.mac_addr[0] |= 0x02;
145 }
146
147 #define UBNT_RS_WAN_PHYMASK (1 << 20)
148 #define UBNT_RS_LAN_PHYMASK ((1 << 16) | (1 << 17) | (1 << 18) | (1 << 19))
149
150 static void __init ubnt_rs_setup(void)
151 {
152 ubnt_generic_setup();
153
154 ar71xx_add_device_mdio(~(UBNT_RS_WAN_PHYMASK | UBNT_RS_LAN_PHYMASK));
155
156 ar71xx_init_mac(ar71xx_eth0_data.mac_addr, ar71xx_mac_base, 0);
157 ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
158 ar71xx_eth0_data.phy_mask = UBNT_RS_WAN_PHYMASK;
159
160 ubnt_init_secondary_mac(ar71xx_mac_base);
161 ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
162 ar71xx_eth1_data.speed = SPEED_100;
163 ar71xx_eth1_data.duplex = DUPLEX_FULL;
164
165 ar71xx_add_device_eth(0);
166 ar71xx_add_device_eth(1);
167
168 ar71xx_add_device_usb();
169
170 ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(ubnt_rs_leds_gpio),
171 ubnt_rs_leds_gpio);
172 }
173
174 MIPS_MACHINE(AR71XX_MACH_UBNT_RS, "UBNT-RS", "Ubiquiti RouterStation",
175 ubnt_rs_setup);
176
177 #define UBNT_RSPRO_WAN_PHYMASK (1 << 4)
178 #define UBNT_RSPRO_LAN_PHYMASK ((1 << 0) | (1 << 1) | (1 << 2) | (1 << 3))
179
180 static void __init ubnt_rspro_setup(void)
181 {
182 ubnt_generic_setup();
183
184 ar71xx_add_device_mdio(~(UBNT_RSPRO_WAN_PHYMASK |
185 UBNT_RSPRO_LAN_PHYMASK));
186
187 ar71xx_init_mac(ar71xx_eth0_data.mac_addr, ar71xx_mac_base, 0);
188 ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
189 ar71xx_eth0_data.phy_mask = UBNT_RSPRO_WAN_PHYMASK;
190
191 ubnt_init_secondary_mac(ar71xx_mac_base);
192 ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
193 ar71xx_eth1_data.phy_mask = UBNT_RSPRO_LAN_PHYMASK;
194 ar71xx_eth1_data.speed = SPEED_1000;
195 ar71xx_eth1_data.duplex = DUPLEX_FULL;
196
197 ar71xx_add_device_eth(0);
198 ar71xx_add_device_eth(1);
199
200 ar71xx_add_device_usb();
201
202 ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(ubnt_rs_leds_gpio),
203 ubnt_rs_leds_gpio);
204 }
205
206 MIPS_MACHINE(AR71XX_MACH_UBNT_RSPRO, "UBNT-RSPRO", "Ubiquiti RouterStation Pro",
207 ubnt_rspro_setup);
208
209 static void __init ubnt_lsx_setup(void)
210 {
211 ubnt_generic_setup();
212 }
213
214 MIPS_MACHINE(AR71XX_MACH_UBNT_LSX, "UBNT-LSX", "Ubiquiti LSX", ubnt_lsx_setup);
215
216 #define UBNT_LSSR71_PHY_MASK (1 << 1)
217
218 static void __init ubnt_lssr71_setup(void)
219 {
220 ubnt_generic_setup();
221
222 ar71xx_add_device_mdio(~UBNT_LSSR71_PHY_MASK);
223
224 ar71xx_init_mac(ar71xx_eth0_data.mac_addr, ar71xx_mac_base, 0);
225 ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
226 ar71xx_eth0_data.phy_mask = UBNT_LSSR71_PHY_MASK;
227
228 ar71xx_add_device_eth(0);
229
230 ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(ubnt_ls_sr71_leds_gpio),
231 ubnt_ls_sr71_leds_gpio);
232 }
233
234 MIPS_MACHINE(AR71XX_MACH_UBNT_LSSR71, "UBNT-LS-SR71", "Ubiquiti LS-SR71",
235 ubnt_lssr71_setup);
236
237 static void __init ubnt_m_setup(void)
238 {
239 u8 *mac1 = (u8 *) KSEG1ADDR(0x1fff0000);
240 u8 *mac2 = (u8 *) KSEG1ADDR(0x1fff0000 + ETH_ALEN);
241 u8 *ee = (u8 *) KSEG1ADDR(0x1fff1000);
242
243 ar71xx_add_device_m25p80(NULL);
244
245 ar71xx_add_device_mdio(~0);
246
247 ar71xx_init_mac(ar71xx_eth0_data.mac_addr, mac1, 0);
248 ar71xx_init_mac(ar71xx_eth1_data.mac_addr, mac2, 0);
249 ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
250 ar71xx_eth0_data.speed = SPEED_100;
251 ar71xx_eth0_data.duplex = DUPLEX_FULL;
252 ar71xx_eth0_data.fifo_cfg1 = 0x0010ffff;
253 ar71xx_eth0_data.fifo_cfg2 = 0x015500aa;
254 ar71xx_eth0_data.fifo_cfg3 = 0x01f00140;
255
256 ar71xx_add_device_eth(0);
257
258 ap91_pci_init(ee, NULL);
259
260 ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(ubnt_m_leds_gpio),
261 ubnt_m_leds_gpio);
262
263 ar71xx_add_device_gpio_buttons(-1, UBNT_BUTTONS_POLL_INTERVAL,
264 ARRAY_SIZE(ubnt_m_gpio_buttons),
265 ubnt_m_gpio_buttons);
266 }
267
268 static void __init ubnt_rocket_m_setup(void)
269 {
270 ubnt_m_setup();
271 ar71xx_add_device_usb();
272 }
273
274 MIPS_MACHINE(AR71XX_MACH_UBNT_BULLET_M, "UBNT-BM", "Ubiquiti Bullet M",
275 ubnt_m_setup);
276 MIPS_MACHINE(AR71XX_MACH_UBNT_ROCKET_M, "UBNT-RM", "Ubiquiti Rocket M",
277 ubnt_rocket_m_setup);
278
279 /* TODO detect the second ethernet port and use one
280 init function for all Ubiquiti MIMO series products */
281 static void __init ubnt_nano_m_setup(void)
282 {
283 ubnt_m_setup();
284
285 ar71xx_eth1_data.has_ar7240_switch = 1;
286 ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
287 ar71xx_eth1_data.speed = SPEED_1000;
288 ar71xx_eth1_data.duplex = DUPLEX_FULL;
289 ar71xx_eth1_data.fifo_cfg1 = 0x0010ffff;
290 ar71xx_eth1_data.fifo_cfg2 = 0x015500aa;
291 ar71xx_eth1_data.fifo_cfg3 = 0x01f00140;
292
293 ar71xx_add_device_eth(1);
294 }
295
296 MIPS_MACHINE(AR71XX_MACH_UBNT_NANO_M, "UBNT-NM", "Ubiquiti Nanostation M",
297 ubnt_nano_m_setup);
298
299 static struct gpio_led ubnt_unifi_leds_gpio[] __initdata = {
300 {
301 .name = "ubnt:orange:dome",
302 .gpio = 1,
303 .active_low = 0,
304 }, {
305 .name = "ubnt:green:dome",
306 .gpio = 0,
307 .active_low = 0,
308 }
309 };
310
311 static void __init ubnt_unifi_setup(void)
312 {
313 u8 *mac = (u8 *) KSEG1ADDR(0x1fff0000);
314 u8 *ee = (u8 *) KSEG1ADDR(0x1fff1000);
315
316 ar71xx_add_device_m25p80(NULL);
317
318 ar71xx_add_device_mdio(~0);
319
320 ar71xx_init_mac(ar71xx_eth0_data.mac_addr, mac, 0);
321 ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
322 ar71xx_eth0_data.speed = SPEED_100;
323 ar71xx_eth0_data.duplex = DUPLEX_FULL;
324
325 ar71xx_add_device_eth(0);
326
327 ap91_pci_init(ee, NULL);
328
329 ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(ubnt_unifi_leds_gpio),
330 ubnt_unifi_leds_gpio);
331 }
332
333 MIPS_MACHINE(AR71XX_MACH_UBNT_UNIFI, "UBNT-XM", "Ubiquiti UniFi",
334 ubnt_unifi_setup);