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