9b70f8ddc54848f225c65b7ebc47f53a891efbd9
[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 <linux/pci.h>
14 #include <linux/platform_device.h>
15 #include <linux/spi/spi.h>
16 #include <linux/spi/flash.h>
17 #include <linux/input.h>
18 #include <linux/ath9k_platform.h>
19
20 #include <asm/mips_machine.h>
21 #include <asm/mach-ar71xx/ar71xx.h>
22 #include <asm/mach-ar71xx/pci.h>
23
24 #include "devices.h"
25
26 #define UBNT_RS_GPIO_LED_RF 2
27 #define UBNT_RS_GPIO_SW4 8
28
29 #define UBNT_LS_SR71_GPIO_LED_D25 0
30 #define UBNT_LS_SR71_GPIO_LED_D26 1
31 #define UBNT_LS_SR71_GPIO_LED_D24 2
32 #define UBNT_LS_SR71_GPIO_LED_D23 4
33 #define UBNT_LS_SR71_GPIO_LED_D22 5
34 #define UBNT_LS_SR71_GPIO_LED_D27 6
35 #define UBNT_LS_SR71_GPIO_LED_D28 7
36
37 #define UBNT_M_GPIO_LED_L1 0
38 #define UBNT_M_GPIO_LED_L2 1
39 #define UBNT_M_GPIO_LED_L3 11
40 #define UBNT_M_GPIO_LED_L4 7
41 #define UBNT_M_GPIO_BTN_RESET 12
42
43 #define UBNT_BUTTONS_POLL_INTERVAL 20
44
45 static struct spi_board_info ubnt_spi_info[] = {
46 {
47 .bus_num = 0,
48 .chip_select = 0,
49 .max_speed_hz = 25000000,
50 .modalias = "m25p80",
51 }
52 };
53
54 static struct ar71xx_pci_irq ubnt_pci_irqs[] __initdata = {
55 {
56 .slot = 0,
57 .pin = 1,
58 .irq = AR71XX_PCI_IRQ_DEV0,
59 }, {
60 .slot = 1,
61 .pin = 1,
62 .irq = AR71XX_PCI_IRQ_DEV1,
63 }, {
64 .slot = 2,
65 .pin = 1,
66 .irq = AR71XX_PCI_IRQ_DEV2,
67 }
68 };
69
70 static struct gpio_led ubnt_rs_leds_gpio[] __initdata = {
71 {
72 .name = "ubnt:green:rf",
73 .gpio = UBNT_RS_GPIO_LED_RF,
74 .active_low = 0,
75 }
76 };
77
78 static struct gpio_led ubnt_ls_sr71_leds_gpio[] __initdata = {
79 {
80 .name = "ubnt:green:d22",
81 .gpio = UBNT_LS_SR71_GPIO_LED_D22,
82 .active_low = 0,
83 }, {
84 .name = "ubnt:green:d23",
85 .gpio = UBNT_LS_SR71_GPIO_LED_D23,
86 .active_low = 0,
87 }, {
88 .name = "ubnt:green:d24",
89 .gpio = UBNT_LS_SR71_GPIO_LED_D24,
90 .active_low = 0,
91 }, {
92 .name = "ubnt:red:d25",
93 .gpio = UBNT_LS_SR71_GPIO_LED_D25,
94 .active_low = 0,
95 }, {
96 .name = "ubnt:red:d26",
97 .gpio = UBNT_LS_SR71_GPIO_LED_D26,
98 .active_low = 0,
99 }, {
100 .name = "ubnt:green:d27",
101 .gpio = UBNT_LS_SR71_GPIO_LED_D27,
102 .active_low = 0,
103 }, {
104 .name = "ubnt:green:d28",
105 .gpio = UBNT_LS_SR71_GPIO_LED_D28,
106 .active_low = 0,
107 }
108 };
109
110 static struct gpio_led ubnt_m_leds_gpio[] __initdata = {
111 {
112 .name = "ubnt:red:link1",
113 .gpio = UBNT_M_GPIO_LED_L1,
114 .active_low = 0,
115 }, {
116 .name = "ubnt:orange:link2",
117 .gpio = UBNT_M_GPIO_LED_L2,
118 .active_low = 0,
119 }, {
120 .name = "ubnt:green:link3",
121 .gpio = UBNT_M_GPIO_LED_L3,
122 .active_low = 0,
123 }, {
124 .name = "ubnt:green:link4",
125 .gpio = UBNT_M_GPIO_LED_L4,
126 .active_low = 0,
127 }
128 };
129
130 static struct gpio_button ubnt_gpio_buttons[] __initdata = {
131 {
132 .desc = "sw4",
133 .type = EV_KEY,
134 .code = BTN_0,
135 .threshold = 5,
136 .gpio = UBNT_RS_GPIO_SW4,
137 .active_low = 1,
138 }
139 };
140
141 static struct gpio_button ubnt_m_gpio_buttons[] __initdata = {
142 {
143 .desc = "reset",
144 .type = EV_KEY,
145 .code = BTN_0,
146 .threshold = 5,
147 .gpio = UBNT_M_GPIO_BTN_RESET,
148 .active_low = 1,
149 }
150 };
151
152 static void __init ubnt_generic_setup(void)
153 {
154 ar71xx_add_device_spi(NULL, ubnt_spi_info,
155 ARRAY_SIZE(ubnt_spi_info));
156
157 ar71xx_add_device_gpio_buttons(-1, UBNT_BUTTONS_POLL_INTERVAL,
158 ARRAY_SIZE(ubnt_gpio_buttons),
159 ubnt_gpio_buttons);
160
161 ar71xx_pci_init(ARRAY_SIZE(ubnt_pci_irqs), ubnt_pci_irqs);
162 }
163
164 #define UBNT_RS_WAN_PHYMASK (1 << 20)
165 #define UBNT_RS_LAN_PHYMASK ((1 << 16) | (1 << 17) | (1 << 18) | (1 << 19))
166
167 #define UBNT_RSPRO_WAN_PHYMASK (1 << 4)
168 #define UBNT_RSPRO_LAN_PHYMASK ((1 << 0) | (1 << 1) | (1 << 2) | (1 << 3))
169
170 static void __init ubnt_rs_setup(void)
171 {
172 ubnt_generic_setup();
173
174 ar71xx_add_device_mdio(~(UBNT_RS_WAN_PHYMASK | UBNT_RS_LAN_PHYMASK));
175
176 ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
177 ar71xx_eth0_data.phy_mask = UBNT_RS_WAN_PHYMASK;
178
179 ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
180 ar71xx_eth1_data.phy_mask = UBNT_RS_LAN_PHYMASK;
181
182 ar71xx_eth1_data.speed = SPEED_100;
183 ar71xx_eth1_data.duplex = DUPLEX_FULL;
184
185 ar71xx_add_device_eth(0);
186 ar71xx_add_device_eth(1);
187
188 ar71xx_add_device_usb();
189
190 ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(ubnt_rs_leds_gpio),
191 ubnt_rs_leds_gpio);
192 }
193
194 MIPS_MACHINE(AR71XX_MACH_UBNT_RS, "Ubiquiti RouterStation", ubnt_rs_setup);
195
196 static void __init ubnt_rspro_setup(void)
197 {
198 ubnt_generic_setup();
199
200 ar71xx_add_device_mdio(~(UBNT_RSPRO_WAN_PHYMASK | UBNT_RSPRO_LAN_PHYMASK));
201
202 ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
203 ar71xx_eth0_data.phy_mask = UBNT_RSPRO_WAN_PHYMASK;
204
205 ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
206 ar71xx_eth1_data.phy_mask = UBNT_RSPRO_LAN_PHYMASK;
207
208 ar71xx_eth1_data.speed = SPEED_1000;
209 ar71xx_eth1_data.duplex = DUPLEX_FULL;
210
211 ar71xx_add_device_eth(0);
212 ar71xx_add_device_eth(1);
213
214 ar71xx_add_device_usb();
215
216 ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(ubnt_rs_leds_gpio),
217 ubnt_rs_leds_gpio);
218 }
219
220 MIPS_MACHINE(AR71XX_MACH_UBNT_RSPRO, "Ubiquiti RouterStation Pro",
221 ubnt_rspro_setup);
222
223 static void __init ubnt_lsx_setup(void)
224 {
225 ubnt_generic_setup();
226 }
227
228 MIPS_MACHINE(AR71XX_MACH_UBNT_LSX, "Ubiquiti LSX", ubnt_lsx_setup);
229
230 #define UBNT_LSSR71_PHY_MASK (1 << 1)
231
232 static void __init ubnt_lssr71_setup(void)
233 {
234 ubnt_generic_setup();
235
236 ar71xx_add_device_mdio(~UBNT_LSSR71_PHY_MASK);
237
238 ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
239 ar71xx_eth0_data.phy_mask = UBNT_LSSR71_PHY_MASK;
240
241 ar71xx_add_device_eth(0);
242
243 ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(ubnt_ls_sr71_leds_gpio),
244 ubnt_ls_sr71_leds_gpio);
245 }
246
247 MIPS_MACHINE(AR71XX_MACH_UBNT_LSSR71, "Ubiquiti LS-SR71", ubnt_lssr71_setup);
248
249 #ifdef CONFIG_PCI
250 static struct ar71xx_pci_irq ubnt_m_pci_irqs[] __initdata = {
251 {
252 .slot = 0,
253 .pin = 1,
254 .irq = AR71XX_PCI_IRQ_DEV0,
255 }
256 };
257
258 static struct ath9k_platform_data ubnt_m_wmac_data;
259
260 static int ubmnt_m_pci_plat_dev_init(struct pci_dev *dev)
261 {
262 dev->dev.platform_data = &ubnt_m_wmac_data;
263 return 0;
264 }
265
266 static void __init ubnt_m_pci_init(void)
267 {
268 u8 *ee = (u8 *) KSEG1ADDR(0x1fff1000);
269
270 memcpy(ubnt_m_wmac_data.eeprom_data, ee,
271 sizeof(ubnt_m_wmac_data.eeprom_data));
272
273 ar71xx_pci_plat_dev_init = ubmnt_m_pci_plat_dev_init;
274
275 ar71xx_pci_init(ARRAY_SIZE(ubnt_m_pci_irqs),
276 ubnt_m_pci_irqs);
277 }
278 #else
279 static inline void ubnt_m_pci_init(void) { };
280 #endif /* CONFIG_PCI */
281
282 static void __init ubnt_m_setup(void)
283 {
284 u8 *mac = (u8 *) KSEG1ADDR(0x1fff0000);
285
286 ar71xx_set_mac_base(mac);
287
288 ar71xx_add_device_spi(NULL, ubnt_spi_info,
289 ARRAY_SIZE(ubnt_spi_info));
290
291 ar71xx_add_device_mdio(~0);
292
293 ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
294 ar71xx_eth0_data.phy_mask = 0;
295
296 ar71xx_eth0_data.speed = SPEED_100;
297 ar71xx_eth0_data.duplex = DUPLEX_FULL;
298
299 ar71xx_add_device_eth(0);
300
301 ubnt_m_pci_init();
302
303 ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(ubnt_m_leds_gpio),
304 ubnt_m_leds_gpio);
305
306 ar71xx_add_device_gpio_buttons(-1, UBNT_BUTTONS_POLL_INTERVAL,
307 ARRAY_SIZE(ubnt_m_gpio_buttons),
308 ubnt_m_gpio_buttons);
309 }
310
311 static void __init ubnt_rocket_m_setup(void)
312 {
313 ubnt_m_setup();
314 ar71xx_add_device_usb();
315 }
316
317 MIPS_MACHINE(AR71XX_MACH_UBNT_BULLET_M, "Ubiquiti Bullet M", ubnt_m_setup);
318 MIPS_MACHINE(AR71XX_MACH_UBNT_ROCKET_M, "Ubiquiti Rocket M", ubnt_rocket_m_setup);
319
320 /* TODO detect the second ethernet port and use one
321 init function for all Ubiquiti MIMO series products */
322 static void __init ubnt_nano_m_setup(void)
323 {
324 ubnt_m_setup();
325
326 ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
327 ar71xx_eth1_data.phy_mask = 0;
328
329 ar71xx_eth1_data.speed = SPEED_1000;
330 ar71xx_eth1_data.duplex = DUPLEX_FULL;
331
332 ar71xx_add_device_eth(1);
333 }
334
335 MIPS_MACHINE(AR71XX_MACH_UBNT_NANO_M, "Ubiquiti Nanostation M", ubnt_nano_m_setup);