69e25ce12138a4b0f7b1ac9a97f9dd42f37831a5
[openwrt/svn-archive/archive.git] / target / linux / ar71xx / files / arch / mips / ar71xx / mach-rb-4xx.c
1 /*
2 * MikroTik RouterBOARD 4xx series support
3 *
4 * Copyright (C) 2008 Gabor Juhos <juhosg@openwrt.org>
5 * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License version 2 as published
9 * by the Free Software Foundation.
10 */
11
12 #include <linux/platform_device.h>
13 #include <linux/irq.h>
14 #include <linux/mmc/host.h>
15 #include <linux/spi/spi.h>
16 #include <linux/spi/flash.h>
17 #include <linux/spi/mmc_spi.h>
18 #include <linux/input.h>
19
20 #include <asm/mips_machine.h>
21 #include <asm/mach-ar71xx/ar71xx.h>
22 #include <asm/mach-ar71xx/pci.h>
23
24 #include "devices.h"
25 #include "dev-leds-gpio.h"
26
27 #define RB4XX_GPIO_USER_LED 4
28 #define RB4XX_GPIO_RESET_SWITCH 7
29
30 #define RB4XX_BUTTONS_POLL_INTERVAL 20
31
32 static struct gpio_led rb4xx_leds_gpio[] __initdata = {
33 {
34 .name = "rb4xx:yellow:user",
35 .gpio = RB4XX_GPIO_USER_LED,
36 .active_low = 0,
37 },
38 };
39
40 static struct gpio_button rb4xx_gpio_buttons[] __initdata = {
41 {
42 .desc = "reset_switch",
43 .type = EV_KEY,
44 .code = BTN_0,
45 .threshold = 5,
46 .gpio = RB4XX_GPIO_RESET_SWITCH,
47 .active_low = 1,
48 }
49 };
50
51 static struct platform_device rb4xx_nand_device = {
52 .name = "rb4xx-nand",
53 .id = -1,
54 };
55
56 static struct ar71xx_pci_irq rb4xx_pci_irqs[] __initdata = {
57 {
58 .slot = 1,
59 .pin = 1,
60 .irq = AR71XX_PCI_IRQ_DEV0,
61 }, {
62 .slot = 1,
63 .pin = 2,
64 .irq = AR71XX_PCI_IRQ_DEV1,
65 }, {
66 .slot = 2,
67 .pin = 1,
68 .irq = AR71XX_PCI_IRQ_DEV1,
69 }, {
70 .slot = 3,
71 .pin = 1,
72 .irq = AR71XX_PCI_IRQ_DEV2,
73 }
74 };
75
76 #if 0
77 /*
78 * SPI device support is experimental
79 */
80 static struct flash_platform_data rb4xx_flash_data = {
81 .type = "pm25lv512",
82 };
83
84 static struct spi_board_info rb4xx_spi_info[] = {
85 {
86 .bus_num = 0,
87 .chip_select = 0,
88 .max_speed_hz = 25000000,
89 .modalias = "m25p80",
90 .platform_data = &rb4xx_flash_data,
91 }
92 };
93
94 static struct mmc_spi_platform_data rb433_mmc_data = {
95 .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34,
96 };
97
98 static struct spi_board_info rb433_spi_info[] = {
99 {
100 .bus_num = 0,
101 .chip_select = 0,
102 .max_speed_hz = 25000000,
103 .modalias = "m25p80",
104 .platform_data = &rb433_flash_data,
105 }, {
106 .bus_num = 0,
107 .chip_select = 2,
108 .max_speed_hz = 25000000,
109 .modalias = "mmc_spi",
110 .platform_data = &rb433_mmc_data,
111 }
112 };
113
114 static u32 rb433_spi_get_ioc_base(u8 chip_select, int cs_high, int is_on)
115 {
116 u32 ret;
117
118 if (is_on == AR71XX_SPI_CS_INACTIVE) {
119 ret = SPI_IOC_CS0 | SPI_IOC_CS1;
120 } else {
121 if (cs_high) {
122 ret = SPI_IOC_CS0 | SPI_IOC_CS1;
123 } else {
124 if ((chip_select ^ 2) == 0)
125 ret = SPI_IOC_CS1 ^ (SPI_IOC_CS0 | SPI_IOC_CS1);
126 else
127 ret = SPI_IOC_CS0 ^ (SPI_IOC_CS0 | SPI_IOC_CS1);
128 }
129 }
130
131 return ret;
132 }
133
134 struct ar71xx_spi_platform_data rb433_spi_data = {
135 .bus_num = 0,
136 .num_chipselect = 3,
137 .get_ioc_base = rb433_spi_get_ioc_base,
138 };
139
140 static void rb4xx_add_device_spi(void)
141 {
142 ar71xx_add_device_spi(NULL, rb4xx_spi_info, ARRAY_SIZE(rb4xx_spi_info));
143 }
144
145 static void rb433_add_device_spi(void)
146 {
147 ar71xx_add_device_spi(&rb433_spi_data, rb433_spi_info,
148 ARRAY_SIZE(rb433_spi_info));
149 }
150 #else
151 static inline void rb4xx_add_device_spi(void) {}
152 static inline void rb433_add_device_spi(void) {}
153 #endif
154
155 static void __init rb4xx_generic_setup(void)
156 {
157 ar71xx_gpio_function_enable(AR71XX_GPIO_FUNC_SPI_CS1_EN |
158 AR71XX_GPIO_FUNC_SPI_CS2_EN);
159
160 ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(rb4xx_leds_gpio),
161 rb4xx_leds_gpio);
162
163 ar71xx_add_device_gpio_buttons(-1, RB4XX_BUTTONS_POLL_INTERVAL,
164 ARRAY_SIZE(rb4xx_gpio_buttons),
165 rb4xx_gpio_buttons);
166
167 platform_device_register(&rb4xx_nand_device);
168 }
169
170 static void __init rb411_setup(void)
171 {
172 rb4xx_generic_setup();
173 rb4xx_add_device_spi();
174
175 ar71xx_add_device_mdio(0xfffffffe);
176
177 ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
178 ar71xx_eth0_data.phy_mask = 0x00000001;
179
180 ar71xx_add_device_eth(0);
181
182 ar71xx_pci_init(ARRAY_SIZE(rb4xx_pci_irqs), rb4xx_pci_irqs);
183 }
184
185 MIPS_MACHINE(AR71XX_MACH_RB_411, "MikroTik RouterBOARD 411/A/AH", rb411_setup);
186
187 static void __init rb411u_setup(void)
188 {
189 rb4xx_generic_setup();
190 rb4xx_add_device_spi();
191
192 ar71xx_add_device_mdio(0xfffffffd);
193
194 ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
195 ar71xx_eth0_data.phy_mask = 0x00000002;
196 ar71xx_add_device_eth(0);
197
198 ar71xx_pci_init(ARRAY_SIZE(rb4xx_pci_irqs), rb4xx_pci_irqs);
199 ar71xx_add_device_usb();
200 }
201
202 MIPS_MACHINE(AR71XX_MACH_RB_411U, "MikroTik RouterBOARD 411U", rb411u_setup);
203
204 static void __init rb433_setup(void)
205 {
206 rb4xx_generic_setup();
207 rb433_add_device_spi();
208
209 ar71xx_add_device_mdio(0xffffffe9);
210
211 ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
212 ar71xx_eth0_data.phy_mask = 0x00000006;
213 ar71xx_eth0_data.speed = SPEED_100;
214 ar71xx_eth0_data.duplex = DUPLEX_FULL;
215
216 ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
217 ar71xx_eth1_data.phy_mask = 0x00000010;
218
219 ar71xx_add_device_eth(1);
220 ar71xx_add_device_eth(0);
221
222 ar71xx_pci_init(ARRAY_SIZE(rb4xx_pci_irqs), rb4xx_pci_irqs);
223 }
224
225 MIPS_MACHINE(AR71XX_MACH_RB_433, "MikroTik RouterBOARD 433/AH", rb433_setup);
226
227 static void __init rb433u_setup(void)
228 {
229 rb433_setup();
230 ar71xx_add_device_usb();
231 }
232
233 MIPS_MACHINE(AR71XX_MACH_RB_433U, "MikroTik RouterBOARD 433UAH", rb433u_setup);
234
235 static void __init rb450_generic_setup(int gige)
236 {
237 rb4xx_generic_setup();
238 rb4xx_add_device_spi();
239
240 ar71xx_add_device_mdio(0xffffffe0);
241
242 ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
243 ar71xx_eth0_data.phy_mask = 0x0000000f;
244 ar71xx_eth0_data.speed = (gige) ? SPEED_1000 : SPEED_100;
245 ar71xx_eth0_data.duplex = DUPLEX_FULL;
246
247 ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
248 ar71xx_eth1_data.phy_mask = 0x00000010;
249
250 ar71xx_add_device_eth(1);
251 ar71xx_add_device_eth(0);
252 }
253
254 static void __init rb450_setup(void)
255 {
256 rb450_generic_setup(0);
257 }
258
259 MIPS_MACHINE(AR71XX_MACH_RB_450, "MikroTik RouterBOARD 450", rb450_setup);
260
261 static void __init rb450g_setup(void)
262 {
263 rb450_generic_setup(1);
264 }
265
266 MIPS_MACHINE(AR71XX_MACH_RB_450G, "MikroTik RouterBOARD 450G", rb450g_setup);
267
268 static void __init rb493_setup(void)
269 {
270 rb4xx_generic_setup();
271 rb4xx_add_device_spi();
272
273 ar71xx_add_device_mdio(0x3fffff00);
274
275 ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
276 ar71xx_eth0_data.phy_mask = 0;
277 ar71xx_eth0_data.speed = SPEED_100;
278 ar71xx_eth0_data.duplex = DUPLEX_FULL;
279
280 ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
281 ar71xx_eth1_data.phy_mask = 0x00000001;
282
283 ar71xx_add_device_eth(0);
284 ar71xx_add_device_eth(1);
285
286 ar71xx_pci_init(ARRAY_SIZE(rb4xx_pci_irqs), rb4xx_pci_irqs);
287 }
288
289 MIPS_MACHINE(AR71XX_MACH_RB_493, "MikroTik RouterBOARD 493/AH", rb493_setup);