ar71xx: move gpio-buttons support into a spearate file
[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
16 #include <asm/mips_machine.h>
17 #include <asm/mach-ar71xx/ar71xx.h>
18
19 #include "devices.h"
20 #include "dev-m25p80.h"
21 #include "dev-ap91-pci.h"
22 #include "dev-gpio-buttons.h"
23 #include "dev-pb42-pci.h"
24 #include "dev-leds-gpio.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 gpio_led ubnt_rs_leds_gpio[] __initdata = {
46 {
47 .name = "ubnt:green:rf",
48 .gpio = UBNT_RS_GPIO_LED_RF,
49 .active_low = 0,
50 }
51 };
52
53 static struct gpio_led ubnt_ls_sr71_leds_gpio[] __initdata = {
54 {
55 .name = "ubnt:green:d22",
56 .gpio = UBNT_LS_SR71_GPIO_LED_D22,
57 .active_low = 0,
58 }, {
59 .name = "ubnt:green:d23",
60 .gpio = UBNT_LS_SR71_GPIO_LED_D23,
61 .active_low = 0,
62 }, {
63 .name = "ubnt:green:d24",
64 .gpio = UBNT_LS_SR71_GPIO_LED_D24,
65 .active_low = 0,
66 }, {
67 .name = "ubnt:red:d25",
68 .gpio = UBNT_LS_SR71_GPIO_LED_D25,
69 .active_low = 0,
70 }, {
71 .name = "ubnt:red:d26",
72 .gpio = UBNT_LS_SR71_GPIO_LED_D26,
73 .active_low = 0,
74 }, {
75 .name = "ubnt:green:d27",
76 .gpio = UBNT_LS_SR71_GPIO_LED_D27,
77 .active_low = 0,
78 }, {
79 .name = "ubnt:green:d28",
80 .gpio = UBNT_LS_SR71_GPIO_LED_D28,
81 .active_low = 0,
82 }
83 };
84
85 static struct gpio_led ubnt_m_leds_gpio[] __initdata = {
86 {
87 .name = "ubnt:red:link1",
88 .gpio = UBNT_M_GPIO_LED_L1,
89 .active_low = 0,
90 }, {
91 .name = "ubnt:orange:link2",
92 .gpio = UBNT_M_GPIO_LED_L2,
93 .active_low = 0,
94 }, {
95 .name = "ubnt:green:link3",
96 .gpio = UBNT_M_GPIO_LED_L3,
97 .active_low = 0,
98 }, {
99 .name = "ubnt:green:link4",
100 .gpio = UBNT_M_GPIO_LED_L4,
101 .active_low = 0,
102 }
103 };
104
105 static struct gpio_button ubnt_gpio_buttons[] __initdata = {
106 {
107 .desc = "sw4",
108 .type = EV_KEY,
109 .code = BTN_0,
110 .threshold = 5,
111 .gpio = UBNT_RS_GPIO_SW4,
112 .active_low = 1,
113 }
114 };
115
116 static struct gpio_button ubnt_m_gpio_buttons[] __initdata = {
117 {
118 .desc = "reset",
119 .type = EV_KEY,
120 .code = BTN_0,
121 .threshold = 5,
122 .gpio = UBNT_M_GPIO_BTN_RESET,
123 .active_low = 1,
124 }
125 };
126
127 static void __init ubnt_generic_setup(void)
128 {
129 ar71xx_add_device_m25p80(NULL);
130
131 ar71xx_add_device_gpio_buttons(-1, UBNT_BUTTONS_POLL_INTERVAL,
132 ARRAY_SIZE(ubnt_gpio_buttons),
133 ubnt_gpio_buttons);
134
135 pb42_pci_init();
136 }
137
138 #define UBNT_RS_WAN_PHYMASK (1 << 20)
139 #define UBNT_RS_LAN_PHYMASK ((1 << 16) | (1 << 17) | (1 << 18) | (1 << 19))
140
141 #define UBNT_RSPRO_WAN_PHYMASK (1 << 4)
142 #define UBNT_RSPRO_LAN_PHYMASK ((1 << 0) | (1 << 1) | (1 << 2) | (1 << 3))
143
144 static void __init ubnt_rs_setup(void)
145 {
146 ubnt_generic_setup();
147
148 ar71xx_add_device_mdio(~(UBNT_RS_WAN_PHYMASK | UBNT_RS_LAN_PHYMASK));
149
150 ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
151 ar71xx_eth0_data.phy_mask = UBNT_RS_WAN_PHYMASK;
152
153 ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
154 ar71xx_eth1_data.phy_mask = UBNT_RS_LAN_PHYMASK;
155
156 ar71xx_eth1_data.speed = SPEED_100;
157 ar71xx_eth1_data.duplex = DUPLEX_FULL;
158
159 ar71xx_add_device_eth(0);
160 ar71xx_add_device_eth(1);
161
162 ar71xx_add_device_usb();
163
164 ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(ubnt_rs_leds_gpio),
165 ubnt_rs_leds_gpio);
166 }
167
168 MIPS_MACHINE(AR71XX_MACH_UBNT_RS, "Ubiquiti RouterStation", ubnt_rs_setup);
169
170 static void __init ubnt_rspro_setup(void)
171 {
172 ubnt_generic_setup();
173
174 ar71xx_add_device_mdio(~(UBNT_RSPRO_WAN_PHYMASK | UBNT_RSPRO_LAN_PHYMASK));
175
176 ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
177 ar71xx_eth0_data.phy_mask = UBNT_RSPRO_WAN_PHYMASK;
178
179 ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
180 ar71xx_eth1_data.phy_mask = UBNT_RSPRO_LAN_PHYMASK;
181
182 ar71xx_eth1_data.speed = SPEED_1000;
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_RSPRO, "Ubiquiti RouterStation Pro",
195 ubnt_rspro_setup);
196
197 static void __init ubnt_lsx_setup(void)
198 {
199 ubnt_generic_setup();
200 }
201
202 MIPS_MACHINE(AR71XX_MACH_UBNT_LSX, "Ubiquiti LSX", ubnt_lsx_setup);
203
204 #define UBNT_LSSR71_PHY_MASK (1 << 1)
205
206 static void __init ubnt_lssr71_setup(void)
207 {
208 ubnt_generic_setup();
209
210 ar71xx_add_device_mdio(~UBNT_LSSR71_PHY_MASK);
211
212 ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
213 ar71xx_eth0_data.phy_mask = UBNT_LSSR71_PHY_MASK;
214
215 ar71xx_add_device_eth(0);
216
217 ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(ubnt_ls_sr71_leds_gpio),
218 ubnt_ls_sr71_leds_gpio);
219 }
220
221 MIPS_MACHINE(AR71XX_MACH_UBNT_LSSR71, "Ubiquiti LS-SR71", ubnt_lssr71_setup);
222
223 static void __init ubnt_m_setup(void)
224 {
225 u8 *mac = (u8 *) KSEG1ADDR(0x1fff0000);
226 u8 *ee = (u8 *) KSEG1ADDR(0x1fff1000);
227
228 ar71xx_set_mac_base(mac);
229
230 ar71xx_add_device_m25p80(NULL);
231
232 ar71xx_add_device_mdio(~0);
233
234 ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
235 ar71xx_eth0_data.phy_mask = 0;
236 ar71xx_eth0_data.speed = SPEED_100;
237 ar71xx_eth0_data.duplex = DUPLEX_FULL;
238 ar71xx_eth0_data.fifo_cfg1 = 0x0010ffff;
239 ar71xx_eth0_data.fifo_cfg2 = 0x015500aa;
240 ar71xx_eth0_data.fifo_cfg3 = 0x01f00140;
241
242 ar71xx_add_device_eth(0);
243
244 ap91_pci_init(ee, NULL);
245
246 ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(ubnt_m_leds_gpio),
247 ubnt_m_leds_gpio);
248
249 ar71xx_add_device_gpio_buttons(-1, UBNT_BUTTONS_POLL_INTERVAL,
250 ARRAY_SIZE(ubnt_m_gpio_buttons),
251 ubnt_m_gpio_buttons);
252 }
253
254 static void __init ubnt_rocket_m_setup(void)
255 {
256 ubnt_m_setup();
257 ar71xx_add_device_usb();
258 }
259
260 MIPS_MACHINE(AR71XX_MACH_UBNT_BULLET_M, "Ubiquiti Bullet M", ubnt_m_setup);
261 MIPS_MACHINE(AR71XX_MACH_UBNT_ROCKET_M, "Ubiquiti Rocket M", ubnt_rocket_m_setup);
262
263 /* TODO detect the second ethernet port and use one
264 init function for all Ubiquiti MIMO series products */
265 static void __init ubnt_nano_m_setup(void)
266 {
267 ubnt_m_setup();
268
269 ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
270 ar71xx_eth1_data.phy_mask = 0;
271 ar71xx_eth1_data.speed = SPEED_1000;
272 ar71xx_eth1_data.duplex = DUPLEX_FULL;
273 ar71xx_eth1_data.fifo_cfg1 = 0x0010ffff;
274 ar71xx_eth1_data.fifo_cfg2 = 0x015500aa;
275 ar71xx_eth1_data.fifo_cfg3 = 0x01f00140;
276
277 ar71xx_add_device_eth(1);
278 }
279
280 MIPS_MACHINE(AR71XX_MACH_UBNT_NANO_M, "Ubiquiti Nanostation M", ubnt_nano_m_setup);