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

Archive Download this file



interactive