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