ar71xx: move PB42 specific PCI init code into a separate file
[openwrt/staging/yousong.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
17 #include <asm/mips_machine.h>
18 #include <asm/mach-ar71xx/ar71xx.h>
19
20 #include "devices.h"
21 #include "dev-m25p80.h"
22 #include "dev-ap91-pci.h"
23 #include "dev-pb42-pci.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 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
52 static 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
84 static 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
104 static struct gpio_button ubnt_gpio_buttons[] __initdata = {
105 {
106 .desc = "sw4",
107 .type = EV_KEY,
108 .code = BTN_0,
109 .threshold = 5,
110 .gpio = UBNT_RS_GPIO_SW4,
111 .active_low = 1,
112 }
113 };
114
115 static struct gpio_button ubnt_m_gpio_buttons[] __initdata = {
116 {
117 .desc = "reset",
118 .type = EV_KEY,
119 .code = BTN_0,
120 .threshold = 5,
121 .gpio = UBNT_M_GPIO_BTN_RESET,
122 .active_low = 1,
123 }
124 };
125
126 static void __init ubnt_generic_setup(void)
127 {
128 ar71xx_add_device_m25p80(NULL);
129
130 ar71xx_add_device_gpio_buttons(-1, UBNT_BUTTONS_POLL_INTERVAL,
131 ARRAY_SIZE(ubnt_gpio_buttons),
132 ubnt_gpio_buttons);
133
134 pb42_pci_init();
135 }
136
137 #define UBNT_RS_WAN_PHYMASK (1 << 20)
138 #define UBNT_RS_LAN_PHYMASK ((1 << 16) | (1 << 17) | (1 << 18) | (1 << 19))
139
140 #define UBNT_RSPRO_WAN_PHYMASK (1 << 4)
141 #define UBNT_RSPRO_LAN_PHYMASK ((1 << 0) | (1 << 1) | (1 << 2) | (1 << 3))
142
143 static void __init ubnt_rs_setup(void)
144 {
145 ubnt_generic_setup();
146
147 ar71xx_add_device_mdio(~(UBNT_RS_WAN_PHYMASK | UBNT_RS_LAN_PHYMASK));
148
149 ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
150 ar71xx_eth0_data.phy_mask = UBNT_RS_WAN_PHYMASK;
151
152 ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
153 ar71xx_eth1_data.phy_mask = UBNT_RS_LAN_PHYMASK;
154
155 ar71xx_eth1_data.speed = SPEED_100;
156 ar71xx_eth1_data.duplex = DUPLEX_FULL;
157
158 ar71xx_add_device_eth(0);
159 ar71xx_add_device_eth(1);
160
161 ar71xx_add_device_usb();
162
163 ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(ubnt_rs_leds_gpio),
164 ubnt_rs_leds_gpio);
165 }
166
167 MIPS_MACHINE(AR71XX_MACH_UBNT_RS, "Ubiquiti RouterStation", ubnt_rs_setup);
168
169 static void __init ubnt_rspro_setup(void)
170 {
171 ubnt_generic_setup();
172
173 ar71xx_add_device_mdio(~(UBNT_RSPRO_WAN_PHYMASK | UBNT_RSPRO_LAN_PHYMASK));
174
175 ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
176 ar71xx_eth0_data.phy_mask = UBNT_RSPRO_WAN_PHYMASK;
177
178 ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
179 ar71xx_eth1_data.phy_mask = UBNT_RSPRO_LAN_PHYMASK;
180
181 ar71xx_eth1_data.speed = SPEED_1000;
182 ar71xx_eth1_data.duplex = DUPLEX_FULL;
183
184 ar71xx_add_device_eth(0);
185 ar71xx_add_device_eth(1);
186
187 ar71xx_add_device_usb();
188
189 ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(ubnt_rs_leds_gpio),
190 ubnt_rs_leds_gpio);
191 }
192
193 MIPS_MACHINE(AR71XX_MACH_UBNT_RSPRO, "Ubiquiti RouterStation Pro",
194 ubnt_rspro_setup);
195
196 static void __init ubnt_lsx_setup(void)
197 {
198 ubnt_generic_setup();
199 }
200
201 MIPS_MACHINE(AR71XX_MACH_UBNT_LSX, "Ubiquiti LSX", ubnt_lsx_setup);
202
203 #define UBNT_LSSR71_PHY_MASK (1 << 1)
204
205 static void __init ubnt_lssr71_setup(void)
206 {
207 ubnt_generic_setup();
208
209 ar71xx_add_device_mdio(~UBNT_LSSR71_PHY_MASK);
210
211 ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
212 ar71xx_eth0_data.phy_mask = UBNT_LSSR71_PHY_MASK;
213
214 ar71xx_add_device_eth(0);
215
216 ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(ubnt_ls_sr71_leds_gpio),
217 ubnt_ls_sr71_leds_gpio);
218 }
219
220 MIPS_MACHINE(AR71XX_MACH_UBNT_LSSR71, "Ubiquiti LS-SR71", ubnt_lssr71_setup);
221
222 static void __init ubnt_m_setup(void)
223 {
224 u8 *mac = (u8 *) KSEG1ADDR(0x1fff0000);
225 u8 *ee = (u8 *) KSEG1ADDR(0x1fff1000);
226
227 ar71xx_set_mac_base(mac);
228
229 ar71xx_add_device_m25p80(NULL);
230
231 ar71xx_add_device_mdio(~0);
232
233 ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
234 ar71xx_eth0_data.phy_mask = 0;
235 ar71xx_eth0_data.speed = SPEED_100;
236 ar71xx_eth0_data.duplex = DUPLEX_FULL;
237 ar71xx_eth0_data.fifo_cfg1 = 0x0010ffff;
238 ar71xx_eth0_data.fifo_cfg2 = 0x015500aa;
239 ar71xx_eth0_data.fifo_cfg3 = 0x01f00140;
240
241 ar71xx_add_device_eth(0);
242
243 ap91_pci_init(ee, NULL);
244
245 ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(ubnt_m_leds_gpio),
246 ubnt_m_leds_gpio);
247
248 ar71xx_add_device_gpio_buttons(-1, UBNT_BUTTONS_POLL_INTERVAL,
249 ARRAY_SIZE(ubnt_m_gpio_buttons),
250 ubnt_m_gpio_buttons);
251 }
252
253 static void __init ubnt_rocket_m_setup(void)
254 {
255 ubnt_m_setup();
256 ar71xx_add_device_usb();
257 }
258
259 MIPS_MACHINE(AR71XX_MACH_UBNT_BULLET_M, "Ubiquiti Bullet M", ubnt_m_setup);
260 MIPS_MACHINE(AR71XX_MACH_UBNT_ROCKET_M, "Ubiquiti Rocket M", ubnt_rocket_m_setup);
261
262 /* TODO detect the second ethernet port and use one
263 init function for all Ubiquiti MIMO series products */
264 static void __init ubnt_nano_m_setup(void)
265 {
266 ubnt_m_setup();
267
268 ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
269 ar71xx_eth1_data.phy_mask = 0;
270 ar71xx_eth1_data.speed = SPEED_1000;
271 ar71xx_eth1_data.duplex = DUPLEX_FULL;
272 ar71xx_eth1_data.fifo_cfg1 = 0x0010ffff;
273 ar71xx_eth1_data.fifo_cfg2 = 0x015500aa;
274 ar71xx_eth1_data.fifo_cfg3 = 0x01f00140;
275
276 ar71xx_add_device_eth(1);
277 }
278
279 MIPS_MACHINE(AR71XX_MACH_UBNT_NANO_M, "Ubiquiti Nanostation M", ubnt_nano_m_setup);