sync 8.09 with ar71xx changes from trunk
[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 #include <asm/mach-ar71xx/platform.h>
24
25 #define RB4XX_GPIO_USER_LED 4
26 #define RB4XX_GPIO_RESET_SWITCH 7
27
28 #define RB4XX_BUTTONS_POLL_INTERVAL 20
29
30 static struct gpio_led rb4xx_leds_gpio[] __initdata = {
31 {
32 .name = "rb4xx:yellow:user",
33 .gpio = RB4XX_GPIO_USER_LED,
34 .active_low = 0,
35 },
36 };
37
38 static struct gpio_button rb4xx_gpio_buttons[] __initdata = {
39 {
40 .desc = "reset_switch",
41 .type = EV_KEY,
42 .code = BTN_0,
43 .threshold = 5,
44 .gpio = RB4XX_GPIO_RESET_SWITCH,
45 .active_low = 1,
46 }
47 };
48
49 static struct platform_device rb4xx_nand_device = {
50 .name = "rb4xx-nand",
51 .id = -1,
52 };
53
54 static struct ar71xx_pci_irq rb4xx_pci_irqs[] __initdata = {
55 {
56 .slot = 1,
57 .pin = 1,
58 .irq = AR71XX_PCI_IRQ_DEV0,
59 }, {
60 .slot = 1,
61 .pin = 2,
62 .irq = AR71XX_PCI_IRQ_DEV1,
63 }, {
64 .slot = 2,
65 .pin = 1,
66 .irq = AR71XX_PCI_IRQ_DEV1,
67 }, {
68 .slot = 3,
69 .pin = 1,
70 .irq = AR71XX_PCI_IRQ_DEV2,
71 }
72 };
73
74 #if 0
75 /*
76 * SPI device support is experimental
77 */
78 static struct flash_platform_data rb4xx_flash_data = {
79 .type = "pm25lv512",
80 };
81
82 static struct spi_board_info rb4xx_spi_info[] = {
83 {
84 .bus_num = 0,
85 .chip_select = 0,
86 .max_speed_hz = 25000000,
87 .modalias = "m25p80",
88 .platform_data = &rb4xx_flash_data,
89 }
90 };
91
92 static struct mmc_spi_platform_data rb433_mmc_data = {
93 .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34,
94 };
95
96 static struct spi_board_info rb433_spi_info[] = {
97 {
98 .bus_num = 0,
99 .chip_select = 0,
100 .max_speed_hz = 25000000,
101 .modalias = "m25p80",
102 .platform_data = &rb433_flash_data,
103 }, {
104 .bus_num = 0,
105 .chip_select = 2,
106 .max_speed_hz = 25000000,
107 .modalias = "mmc_spi",
108 .platform_data = &rb433_mmc_data,
109 }
110 };
111
112 static u32 rb433_spi_get_ioc_base(u8 chip_select, int cs_high, int is_on)
113 {
114 u32 ret;
115
116 if (is_on == AR71XX_SPI_CS_INACTIVE) {
117 ret = SPI_IOC_CS0 | SPI_IOC_CS1;
118 } else {
119 if (cs_high) {
120 ret = SPI_IOC_CS0 | SPI_IOC_CS1;
121 } else {
122 if ((chip_select ^ 2) == 0)
123 ret = SPI_IOC_CS1 ^ (SPI_IOC_CS0 | SPI_IOC_CS1);
124 else
125 ret = SPI_IOC_CS0 ^ (SPI_IOC_CS0 | SPI_IOC_CS1);
126 }
127 }
128
129 return ret;
130 }
131
132 struct ar71xx_spi_platform_data rb433_spi_data = {
133 .bus_num = 0,
134 .num_chipselect = 3,
135 .get_ioc_base = rb433_spi_get_ioc_base,
136 };
137
138 static void rb4xx_add_device_spi(void)
139 {
140 ar71xx_add_device_spi(NULL, rb4xx_spi_info, ARRAY_SIZE(rb4xx_spi_info));
141 }
142
143 static void rb433_add_device_spi(void)
144 {
145 ar71xx_add_device_spi(&rb433_spi_data, rb433_spi_info,
146 ARRAY_SIZE(rb433_spi_info));
147 }
148 #else
149 static inline void rb4xx_add_device_spi(void) {}
150 static inline void rb433_add_device_spi(void) {}
151 #endif
152
153 static void __init rb411_setup(void)
154 {
155 rb4xx_add_device_spi();
156
157 ar71xx_add_device_mdio(0xfffffffe);
158
159 ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
160 ar71xx_eth0_data.phy_mask = 0x00000001;
161
162 ar71xx_add_device_eth(0);
163
164 ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(rb4xx_leds_gpio),
165 rb4xx_leds_gpio);
166
167 ar71xx_add_device_gpio_buttons(-1, RB4XX_BUTTONS_POLL_INTERVAL,
168 ARRAY_SIZE(rb4xx_gpio_buttons),
169 rb4xx_gpio_buttons);
170
171 platform_device_register(&rb4xx_nand_device);
172
173 ar71xx_pci_init(ARRAY_SIZE(rb4xx_pci_irqs), rb4xx_pci_irqs);
174 }
175
176 MIPS_MACHINE(MACH_AR71XX_RB_411, "MikroTik RouterBOARD 411/A/AH", rb411_setup);
177
178 static void __init rb433_setup(void)
179 {
180 rb433_add_device_spi();
181
182 ar71xx_add_device_mdio(0xffffffec);
183
184 ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
185 ar71xx_eth0_data.phy_mask = 0x00000003;
186
187 ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
188 ar71xx_eth1_data.phy_mask = 0x00000010;
189
190 ar71xx_add_device_eth(1);
191 ar71xx_add_device_eth(0);
192
193 ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(rb4xx_leds_gpio),
194 rb4xx_leds_gpio);
195
196 ar71xx_add_device_gpio_buttons(-1, RB4XX_BUTTONS_POLL_INTERVAL,
197 ARRAY_SIZE(rb4xx_gpio_buttons),
198 rb4xx_gpio_buttons);
199
200 platform_device_register(&rb4xx_nand_device);
201
202 ar71xx_pci_init(ARRAY_SIZE(rb4xx_pci_irqs), rb4xx_pci_irqs);
203 }
204
205 MIPS_MACHINE(MACH_AR71XX_RB_433, "MikroTik RouterBOARD 433/AH", rb433_setup);
206
207 static void __init rb450_setup(void)
208 {
209 rb4xx_add_device_spi();
210
211 ar71xx_add_device_mdio(0xffffffe0);
212
213 ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
214 ar71xx_eth0_data.phy_mask = 0x0000000f;
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_add_device_leds_gpio(-1, ARRAY_SIZE(rb4xx_leds_gpio),
223 rb4xx_leds_gpio);
224
225 ar71xx_add_device_gpio_buttons(-1, RB4XX_BUTTONS_POLL_INTERVAL,
226 ARRAY_SIZE(rb4xx_gpio_buttons),
227 rb4xx_gpio_buttons);
228
229 platform_device_register(&rb4xx_nand_device);
230 }
231
232 MIPS_MACHINE(MACH_AR71XX_RB_450, "MikroTik RouterBOARD 450", rb450_setup);
233
234 static void __init rb493_setup(void)
235 {
236 rb4xx_add_device_spi();
237
238 ar71xx_add_device_mdio(0x3fffff00);
239
240 #if 0
241 ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
242 ar71xx_eth0_data.phy_mask = 0;
243 ar71xx_eth0_data.speed = SPEED_100;
244 ar71xx_eth0_data.duplex = DUPLEX_FULL;
245
246 ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
247 ar71xx_eth1_data.phy_mask = 0x00000001;
248
249 ar71xx_add_device_eth(0);
250 ar71xx_add_device_eth(1);
251 #endif
252
253 ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(rb4xx_leds_gpio),
254 rb4xx_leds_gpio);
255
256 ar71xx_add_device_gpio_buttons(-1, RB4XX_BUTTONS_POLL_INTERVAL,
257 ARRAY_SIZE(rb4xx_gpio_buttons),
258 rb4xx_gpio_buttons);
259
260 platform_device_register(&rb4xx_nand_device);
261 }
262
263 MIPS_MACHINE(MACH_AR71XX_RB_493, "MikroTik RouterBOARD 493/AH", rb493_setup);
264