ar71xx: register GPIO button on the Bullet M
[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/platform_device.h>
14 #include <linux/spi/spi.h>
15 #include <linux/spi/flash.h>
16 #include <linux/input.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
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_BULLET_M_GPIO_LED_L1 0
36 #define UBNT_BULLET_M_GPIO_LED_L2 1
37 #define UBNT_BULLET_M_GPIO_LED_L3 11
38 #define UBNT_BULLET_M_GPIO_LED_L4 7
39 #define UBNT_BULLET_M_GPIO_BTN_RESET 12
40
41 #define UBNT_BUTTONS_POLL_INTERVAL 20
42
43 static struct spi_board_info ubnt_spi_info[] = {
44 {
45 .bus_num = 0,
46 .chip_select = 0,
47 .max_speed_hz = 25000000,
48 .modalias = "m25p80",
49 }
50 };
51
52 static struct ar71xx_pci_irq ubnt_pci_irqs[] __initdata = {
53 {
54 .slot = 0,
55 .pin = 1,
56 .irq = AR71XX_PCI_IRQ_DEV0,
57 }, {
58 .slot = 1,
59 .pin = 1,
60 .irq = AR71XX_PCI_IRQ_DEV1,
61 }, {
62 .slot = 2,
63 .pin = 1,
64 .irq = AR71XX_PCI_IRQ_DEV2,
65 }
66 };
67
68 static struct gpio_led ubnt_rs_leds_gpio[] __initdata = {
69 {
70 .name = "ubnt:green:rf",
71 .gpio = UBNT_RS_GPIO_LED_RF,
72 .active_low = 0,
73 }
74 };
75
76 static struct gpio_led ubnt_ls_sr71_leds_gpio[] __initdata = {
77 {
78 .name = "ubnt:green:d22",
79 .gpio = UBNT_LS_SR71_GPIO_LED_D22,
80 .active_low = 0,
81 }, {
82 .name = "ubnt:green:d23",
83 .gpio = UBNT_LS_SR71_GPIO_LED_D23,
84 .active_low = 0,
85 }, {
86 .name = "ubnt:green:d24",
87 .gpio = UBNT_LS_SR71_GPIO_LED_D24,
88 .active_low = 0,
89 }, {
90 .name = "ubnt:red:d25",
91 .gpio = UBNT_LS_SR71_GPIO_LED_D25,
92 .active_low = 0,
93 }, {
94 .name = "ubnt:red:d26",
95 .gpio = UBNT_LS_SR71_GPIO_LED_D26,
96 .active_low = 0,
97 }, {
98 .name = "ubnt:green:d27",
99 .gpio = UBNT_LS_SR71_GPIO_LED_D27,
100 .active_low = 0,
101 }, {
102 .name = "ubnt:green:d28",
103 .gpio = UBNT_LS_SR71_GPIO_LED_D28,
104 .active_low = 0,
105 }
106 };
107
108 static struct gpio_led ubnt_bullet_m_leds_gpio[] __initdata = {
109 {
110 .name = "ubnt:red:link1",
111 .gpio = UBNT_BULLET_M_GPIO_LED_L1,
112 .active_low = 0,
113 }, {
114 .name = "ubnt:orange:link2",
115 .gpio = UBNT_BULLET_M_GPIO_LED_L2,
116 .active_low = 0,
117 }, {
118 .name = "ubnt:green:link3",
119 .gpio = UBNT_BULLET_M_GPIO_LED_L3,
120 .active_low = 0,
121 }, {
122 .name = "ubnt:green:link4",
123 .gpio = UBNT_BULLET_M_GPIO_LED_L4,
124 .active_low = 0,
125 }
126 };
127
128 static struct gpio_button ubnt_gpio_buttons[] __initdata = {
129 {
130 .desc = "sw4",
131 .type = EV_KEY,
132 .code = BTN_0,
133 .threshold = 5,
134 .gpio = UBNT_RS_GPIO_SW4,
135 .active_low = 1,
136 }
137 };
138
139 static struct gpio_button ubnt_bullet_m_gpio_buttons[] __initdata = {
140 {
141 .desc = "reset",
142 .type = EV_KEY,
143 .code = BTN_0,
144 .threshold = 5,
145 .gpio = UBNT_BULLET_M_GPIO_BTN_RESET,
146 .active_low = 1,
147 }
148 };
149
150 static void __init ubnt_generic_setup(void)
151 {
152 ar71xx_add_device_spi(NULL, ubnt_spi_info,
153 ARRAY_SIZE(ubnt_spi_info));
154
155 ar71xx_add_device_gpio_buttons(-1, UBNT_BUTTONS_POLL_INTERVAL,
156 ARRAY_SIZE(ubnt_gpio_buttons),
157 ubnt_gpio_buttons);
158
159 ar71xx_pci_init(ARRAY_SIZE(ubnt_pci_irqs), ubnt_pci_irqs);
160 }
161
162 #define UBNT_RS_WAN_PHYMASK (1 << 20)
163 #define UBNT_RS_LAN_PHYMASK ((1 << 16) | (1 << 17) | (1 << 18) | (1 << 19))
164
165 #define UBNT_RSPRO_WAN_PHYMASK (1 << 4)
166 #define UBNT_RSPRO_LAN_PHYMASK ((1 << 0) | (1 << 1) | (1 << 2) | (1 << 3))
167
168 static void __init ubnt_rs_setup(void)
169 {
170 ubnt_generic_setup();
171
172 ar71xx_add_device_mdio(~(UBNT_RS_WAN_PHYMASK | UBNT_RS_LAN_PHYMASK));
173
174 ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
175 ar71xx_eth0_data.phy_mask = UBNT_RS_WAN_PHYMASK;
176
177 ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
178 ar71xx_eth1_data.phy_mask = UBNT_RS_LAN_PHYMASK;
179
180 ar71xx_eth1_data.speed = SPEED_100;
181 ar71xx_eth1_data.duplex = DUPLEX_FULL;
182
183 ar71xx_add_device_eth(0);
184 ar71xx_add_device_eth(1);
185
186 ar71xx_add_device_usb();
187
188 ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(ubnt_rs_leds_gpio),
189 ubnt_rs_leds_gpio);
190 }
191
192 MIPS_MACHINE(AR71XX_MACH_UBNT_RS, "Ubiquiti RouterStation", ubnt_rs_setup);
193
194 static void __init ubnt_rspro_setup(void)
195 {
196 ubnt_generic_setup();
197
198 ar71xx_add_device_mdio(~(UBNT_RSPRO_WAN_PHYMASK | UBNT_RSPRO_LAN_PHYMASK));
199
200 ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
201 ar71xx_eth0_data.phy_mask = UBNT_RSPRO_WAN_PHYMASK;
202
203 ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
204 ar71xx_eth1_data.phy_mask = UBNT_RSPRO_LAN_PHYMASK;
205
206 ar71xx_eth1_data.speed = SPEED_1000;
207 ar71xx_eth1_data.duplex = DUPLEX_FULL;
208
209 ar71xx_add_device_eth(0);
210 ar71xx_add_device_eth(1);
211
212 ar71xx_add_device_usb();
213
214 ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(ubnt_rs_leds_gpio),
215 ubnt_rs_leds_gpio);
216 }
217
218 MIPS_MACHINE(AR71XX_MACH_UBNT_RSPRO, "Ubiquiti RouterStation Pro",
219 ubnt_rspro_setup);
220
221 static void __init ubnt_lsx_setup(void)
222 {
223 ubnt_generic_setup();
224 }
225
226 MIPS_MACHINE(AR71XX_MACH_UBNT_LSX, "Ubiquiti LSX", ubnt_lsx_setup);
227
228 #define UBNT_LSSR71_PHY_MASK (1 << 1)
229
230 static void __init ubnt_lssr71_setup(void)
231 {
232 ubnt_generic_setup();
233
234 ar71xx_add_device_mdio(~UBNT_LSSR71_PHY_MASK);
235
236 ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
237 ar71xx_eth0_data.phy_mask = UBNT_LSSR71_PHY_MASK;
238
239 ar71xx_add_device_eth(0);
240
241 ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(ubnt_ls_sr71_leds_gpio),
242 ubnt_ls_sr71_leds_gpio);
243 }
244
245 MIPS_MACHINE(AR71XX_MACH_UBNT_LSSR71, "Ubiquiti LS-SR71", ubnt_lssr71_setup);
246
247 static void __init ubnt_bullet_m_setup(void)
248 {
249 ar71xx_add_device_spi(NULL, ubnt_spi_info,
250 ARRAY_SIZE(ubnt_spi_info));
251
252 ar71xx_add_device_mdio(~0);
253
254 ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
255 ar71xx_eth0_data.phy_mask = 0;
256
257 ar71xx_eth0_data.speed = SPEED_100;
258 ar71xx_eth0_data.duplex = DUPLEX_FULL;
259
260 ar71xx_add_device_eth(0);
261
262 ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(ubnt_bullet_m_leds_gpio),
263 ubnt_bullet_m_leds_gpio);
264
265 ar71xx_add_device_gpio_buttons(-1, UBNT_BUTTONS_POLL_INTERVAL,
266 ARRAY_SIZE(ubnt_bullet_m_gpio_buttons),
267 ubnt_bullet_m_gpio_buttons);
268 }
269
270 MIPS_MACHINE(AR71XX_MACH_UBNT_BULLET_M, "Ubiquiti Bullet M", ubnt_bullet_m_setup);