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