2 * MikroTik RouterBOARD 4xx series support
4 * Copyright (C) 2008 Gabor Juhos <juhosg@openwrt.org>
5 * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
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.
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>
20 #include <asm/mips_machine.h>
21 #include <asm/mach-ar71xx/ar71xx.h>
22 #include <asm/mach-ar71xx/pci.h>
26 #define RB4XX_GPIO_USER_LED 4
27 #define RB4XX_GPIO_RESET_SWITCH 7
29 #define RB4XX_BUTTONS_POLL_INTERVAL 20
31 static struct gpio_led rb4xx_leds_gpio
[] __initdata
= {
33 .name
= "rb4xx:yellow:user",
34 .gpio
= RB4XX_GPIO_USER_LED
,
39 static struct gpio_button rb4xx_gpio_buttons
[] __initdata
= {
41 .desc
= "reset_switch",
45 .gpio
= RB4XX_GPIO_RESET_SWITCH
,
50 static struct platform_device rb4xx_nand_device
= {
55 static struct ar71xx_pci_irq rb4xx_pci_irqs
[] __initdata
= {
59 .irq
= AR71XX_PCI_IRQ_DEV0
,
63 .irq
= AR71XX_PCI_IRQ_DEV1
,
67 .irq
= AR71XX_PCI_IRQ_DEV1
,
71 .irq
= AR71XX_PCI_IRQ_DEV2
,
77 * SPI device support is experimental
79 static struct flash_platform_data rb4xx_flash_data
= {
83 static struct spi_board_info rb4xx_spi_info
[] = {
87 .max_speed_hz
= 25000000,
89 .platform_data
= &rb4xx_flash_data
,
93 static struct mmc_spi_platform_data rb433_mmc_data
= {
94 .ocr_mask
= MMC_VDD_32_33
| MMC_VDD_33_34
,
97 static struct spi_board_info rb433_spi_info
[] = {
101 .max_speed_hz
= 25000000,
102 .modalias
= "m25p80",
103 .platform_data
= &rb433_flash_data
,
107 .max_speed_hz
= 25000000,
108 .modalias
= "mmc_spi",
109 .platform_data
= &rb433_mmc_data
,
113 static u32
rb433_spi_get_ioc_base(u8 chip_select
, int cs_high
, int is_on
)
117 if (is_on
== AR71XX_SPI_CS_INACTIVE
) {
118 ret
= SPI_IOC_CS0
| SPI_IOC_CS1
;
121 ret
= SPI_IOC_CS0
| SPI_IOC_CS1
;
123 if ((chip_select
^ 2) == 0)
124 ret
= SPI_IOC_CS1
^ (SPI_IOC_CS0
| SPI_IOC_CS1
);
126 ret
= SPI_IOC_CS0
^ (SPI_IOC_CS0
| SPI_IOC_CS1
);
133 struct ar71xx_spi_platform_data rb433_spi_data
= {
136 .get_ioc_base
= rb433_spi_get_ioc_base
,
139 static void rb4xx_add_device_spi(void)
141 ar71xx_add_device_spi(NULL
, rb4xx_spi_info
, ARRAY_SIZE(rb4xx_spi_info
));
144 static void rb433_add_device_spi(void)
146 ar71xx_add_device_spi(&rb433_spi_data
, rb433_spi_info
,
147 ARRAY_SIZE(rb433_spi_info
));
150 static inline void rb4xx_add_device_spi(void) {}
151 static inline void rb433_add_device_spi(void) {}
154 static void __init
rb4xx_generic_setup(void)
156 ar71xx_gpio_function_enable(AR71XX_GPIO_FUNC_SPI_CS1_EN
|
157 AR71XX_GPIO_FUNC_SPI_CS2_EN
);
159 ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(rb4xx_leds_gpio
),
162 ar71xx_add_device_gpio_buttons(-1, RB4XX_BUTTONS_POLL_INTERVAL
,
163 ARRAY_SIZE(rb4xx_gpio_buttons
),
166 platform_device_register(&rb4xx_nand_device
);
169 static void __init
rb411_setup(void)
171 rb4xx_generic_setup();
172 rb4xx_add_device_spi();
174 ar71xx_add_device_mdio(0xfffffffe);
176 ar71xx_eth0_data
.phy_if_mode
= PHY_INTERFACE_MODE_MII
;
177 ar71xx_eth0_data
.phy_mask
= 0x00000001;
179 ar71xx_add_device_eth(0);
181 ar71xx_pci_init(ARRAY_SIZE(rb4xx_pci_irqs
), rb4xx_pci_irqs
);
184 MIPS_MACHINE(AR71XX_MACH_RB_411
, "MikroTik RouterBOARD 411/A/AH", rb411_setup
);
186 static void __init
rb411u_setup(void)
188 rb4xx_generic_setup();
189 rb4xx_add_device_spi();
191 ar71xx_add_device_mdio(0xfffffffd);
193 ar71xx_eth0_data
.phy_if_mode
= PHY_INTERFACE_MODE_MII
;
194 ar71xx_eth0_data
.phy_mask
= 0x00000002;
195 ar71xx_add_device_eth(0);
197 ar71xx_pci_init(ARRAY_SIZE(rb4xx_pci_irqs
), rb4xx_pci_irqs
);
198 ar71xx_add_device_usb();
201 MIPS_MACHINE(AR71XX_MACH_RB_411U
, "MikroTik RouterBOARD 411U", rb411u_setup
);
203 static void __init
rb433_setup(void)
205 rb4xx_generic_setup();
206 rb433_add_device_spi();
208 ar71xx_add_device_mdio(0xffffffe9);
210 ar71xx_eth0_data
.phy_if_mode
= PHY_INTERFACE_MODE_MII
;
211 ar71xx_eth0_data
.phy_mask
= 0x00000006;
212 ar71xx_eth0_data
.speed
= SPEED_100
;
213 ar71xx_eth0_data
.duplex
= DUPLEX_FULL
;
215 ar71xx_eth1_data
.phy_if_mode
= PHY_INTERFACE_MODE_RMII
;
216 ar71xx_eth1_data
.phy_mask
= 0x00000010;
218 ar71xx_add_device_eth(1);
219 ar71xx_add_device_eth(0);
221 ar71xx_pci_init(ARRAY_SIZE(rb4xx_pci_irqs
), rb4xx_pci_irqs
);
224 MIPS_MACHINE(AR71XX_MACH_RB_433
, "MikroTik RouterBOARD 433/AH", rb433_setup
);
226 static void __init
rb433u_setup(void)
229 ar71xx_add_device_usb();
232 MIPS_MACHINE(AR71XX_MACH_RB_433U
, "MikroTik RouterBOARD 433UAH", rb433u_setup
);
234 static void __init
rb450_generic_setup(int gige
)
236 rb4xx_generic_setup();
237 rb4xx_add_device_spi();
239 ar71xx_add_device_mdio(0xffffffe0);
241 ar71xx_eth0_data
.phy_if_mode
= PHY_INTERFACE_MODE_MII
;
242 ar71xx_eth0_data
.phy_mask
= 0x0000000f;
243 ar71xx_eth0_data
.speed
= (gige
) ? SPEED_1000
: SPEED_100
;
244 ar71xx_eth0_data
.duplex
= DUPLEX_FULL
;
246 ar71xx_eth1_data
.phy_if_mode
= PHY_INTERFACE_MODE_RMII
;
247 ar71xx_eth1_data
.phy_mask
= 0x00000010;
249 ar71xx_add_device_eth(1);
250 ar71xx_add_device_eth(0);
253 static void __init
rb450_setup(void)
255 rb450_generic_setup(0);
258 MIPS_MACHINE(AR71XX_MACH_RB_450
, "MikroTik RouterBOARD 450", rb450_setup
);
260 static void __init
rb450g_setup(void)
262 rb450_generic_setup(1);
265 MIPS_MACHINE(AR71XX_MACH_RB_450G
, "MikroTik RouterBOARD 450G", rb450g_setup
);
267 static void __init
rb493_setup(void)
269 rb4xx_generic_setup();
270 rb4xx_add_device_spi();
272 ar71xx_add_device_mdio(0x3fffff00);
274 ar71xx_eth0_data
.phy_if_mode
= PHY_INTERFACE_MODE_MII
;
275 ar71xx_eth0_data
.phy_mask
= 0;
276 ar71xx_eth0_data
.speed
= SPEED_100
;
277 ar71xx_eth0_data
.duplex
= DUPLEX_FULL
;
279 ar71xx_eth1_data
.phy_if_mode
= PHY_INTERFACE_MODE_RMII
;
280 ar71xx_eth1_data
.phy_mask
= 0x00000001;
282 ar71xx_add_device_eth(0);
283 ar71xx_add_device_eth(1);
285 ar71xx_pci_init(ARRAY_SIZE(rb4xx_pci_irqs
), rb4xx_pci_irqs
);
288 MIPS_MACHINE(AR71XX_MACH_RB_493
, "MikroTik RouterBOARD 493/AH", rb493_setup
);