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>
19 #include <asm/mach-ar71xx/ar71xx.h>
20 #include <asm/mach-ar71xx/pci.h>
24 #include "dev-gpio-buttons.h"
25 #include "dev-leds-gpio.h"
28 #define RB4XX_GPIO_USER_LED 4
29 #define RB4XX_GPIO_RESET_SWITCH 7
31 #define RB4XX_BUTTONS_POLL_INTERVAL 20
33 static struct gpio_led rb4xx_leds_gpio
[] __initdata
= {
35 .name
= "rb4xx:yellow:user",
36 .gpio
= RB4XX_GPIO_USER_LED
,
41 static struct gpio_button rb4xx_gpio_buttons
[] __initdata
= {
43 .desc
= "reset_switch",
47 .gpio
= RB4XX_GPIO_RESET_SWITCH
,
52 static struct platform_device rb4xx_nand_device
= {
57 static struct ar71xx_pci_irq rb4xx_pci_irqs
[] __initdata
= {
61 .irq
= AR71XX_PCI_IRQ_DEV2
,
65 .irq
= AR71XX_PCI_IRQ_DEV0
,
69 .irq
= AR71XX_PCI_IRQ_DEV1
,
73 .irq
= AR71XX_PCI_IRQ_DEV1
,
77 .irq
= AR71XX_PCI_IRQ_DEV2
,
83 * SPI device support is experimental
85 static struct flash_platform_data rb4xx_flash_data
= {
89 static struct spi_board_info rb4xx_spi_info
[] = {
93 .max_speed_hz
= 25000000,
95 .platform_data
= &rb4xx_flash_data
,
99 static struct mmc_spi_platform_data rb433_mmc_data
= {
100 .ocr_mask
= MMC_VDD_32_33
| MMC_VDD_33_34
,
103 static struct spi_board_info rb433_spi_info
[] = {
107 .max_speed_hz
= 25000000,
108 .modalias
= "m25p80",
109 .platform_data
= &rb433_flash_data
,
113 .max_speed_hz
= 25000000,
114 .modalias
= "mmc_spi",
115 .platform_data
= &rb433_mmc_data
,
119 static u32
rb433_spi_get_ioc_base(u8 chip_select
, int cs_high
, int is_on
)
123 if (is_on
== AR71XX_SPI_CS_INACTIVE
) {
124 ret
= SPI_IOC_CS0
| SPI_IOC_CS1
;
127 ret
= SPI_IOC_CS0
| SPI_IOC_CS1
;
129 if ((chip_select
^ 2) == 0)
130 ret
= SPI_IOC_CS1
^ (SPI_IOC_CS0
| SPI_IOC_CS1
);
132 ret
= SPI_IOC_CS0
^ (SPI_IOC_CS0
| SPI_IOC_CS1
);
139 struct ar71xx_spi_platform_data rb433_spi_data
= {
142 .get_ioc_base
= rb433_spi_get_ioc_base
,
145 static void rb4xx_add_device_spi(void)
147 ar71xx_add_device_spi(NULL
, rb4xx_spi_info
, ARRAY_SIZE(rb4xx_spi_info
));
150 static void rb433_add_device_spi(void)
152 ar71xx_add_device_spi(&rb433_spi_data
, rb433_spi_info
,
153 ARRAY_SIZE(rb433_spi_info
));
156 static inline void rb4xx_add_device_spi(void) {}
157 static inline void rb433_add_device_spi(void) {}
160 static void __init
rb4xx_generic_setup(void)
162 ar71xx_gpio_function_enable(AR71XX_GPIO_FUNC_SPI_CS1_EN
|
163 AR71XX_GPIO_FUNC_SPI_CS2_EN
);
165 ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(rb4xx_leds_gpio
),
168 ar71xx_add_device_gpio_buttons(-1, RB4XX_BUTTONS_POLL_INTERVAL
,
169 ARRAY_SIZE(rb4xx_gpio_buttons
),
172 platform_device_register(&rb4xx_nand_device
);
175 static void __init
rb411_setup(void)
177 rb4xx_generic_setup();
178 rb4xx_add_device_spi();
180 ar71xx_add_device_mdio(0xfffffffc);
182 ar71xx_eth0_data
.phy_if_mode
= PHY_INTERFACE_MODE_MII
;
183 ar71xx_eth0_data
.phy_mask
= 0x00000003;
185 ar71xx_add_device_eth(0);
187 ar71xx_pci_init(ARRAY_SIZE(rb4xx_pci_irqs
), rb4xx_pci_irqs
);
190 MIPS_MACHINE(AR71XX_MACH_RB_411
, "411", "MikroTik RouterBOARD 411/A/AH",
193 static void __init
rb411u_setup(void)
195 rb4xx_generic_setup();
196 rb4xx_add_device_spi();
198 ar71xx_add_device_mdio(0xfffffffd);
200 ar71xx_eth0_data
.phy_if_mode
= PHY_INTERFACE_MODE_MII
;
201 ar71xx_eth0_data
.phy_mask
= 0x00000002;
202 ar71xx_add_device_eth(0);
204 ar71xx_pci_init(ARRAY_SIZE(rb4xx_pci_irqs
), rb4xx_pci_irqs
);
205 ar71xx_add_device_usb();
208 MIPS_MACHINE(AR71XX_MACH_RB_411U
, "411U", "MikroTik RouterBOARD 411U",
211 static void __init
rb433_setup(void)
213 rb4xx_generic_setup();
214 rb433_add_device_spi();
216 ar71xx_add_device_mdio(0xffffffe9);
218 ar71xx_eth0_data
.phy_if_mode
= PHY_INTERFACE_MODE_MII
;
219 ar71xx_eth0_data
.speed
= SPEED_100
;
220 ar71xx_eth0_data
.duplex
= DUPLEX_FULL
;
222 ar71xx_eth1_data
.phy_if_mode
= PHY_INTERFACE_MODE_RMII
;
223 ar71xx_eth1_data
.phy_mask
= 0x00000010;
225 ar71xx_add_device_eth(1);
226 ar71xx_add_device_eth(0);
228 ar71xx_pci_init(ARRAY_SIZE(rb4xx_pci_irqs
), rb4xx_pci_irqs
);
231 MIPS_MACHINE(AR71XX_MACH_RB_433
, "433", "MikroTik RouterBOARD 433/AH",
234 static void __init
rb433u_setup(void)
237 ar71xx_add_device_usb();
240 MIPS_MACHINE(AR71XX_MACH_RB_433U
, "433U", "MikroTik RouterBOARD 433UAH",
243 static void __init
rb450_generic_setup(int gige
)
245 rb4xx_generic_setup();
246 rb4xx_add_device_spi();
248 ar71xx_add_device_mdio(0xffffffe0);
250 ar71xx_eth0_data
.phy_if_mode
= (gige
) ? PHY_INTERFACE_MODE_RGMII
: PHY_INTERFACE_MODE_MII
;
251 ar71xx_eth0_data
.speed
= (gige
) ? SPEED_1000
: SPEED_100
;
252 ar71xx_eth0_data
.duplex
= DUPLEX_FULL
;
254 ar71xx_eth1_data
.phy_if_mode
= (gige
) ? PHY_INTERFACE_MODE_RGMII
: PHY_INTERFACE_MODE_RMII
;
255 ar71xx_eth1_data
.phy_mask
= 0x00000010;
257 ar71xx_add_device_eth(1);
258 ar71xx_add_device_eth(0);
261 static void __init
rb450_setup(void)
263 rb450_generic_setup(0);
266 MIPS_MACHINE(AR71XX_MACH_RB_450
, "450", "MikroTik RouterBOARD 450",
269 static void __init
rb450g_setup(void)
271 rb450_generic_setup(1);
274 MIPS_MACHINE(AR71XX_MACH_RB_450G
, "450G", "MikroTik RouterBOARD 450G",
277 static void __init
rb493_setup(void)
279 rb4xx_generic_setup();
280 rb4xx_add_device_spi();
282 ar71xx_add_device_mdio(0x3fffff00);
284 ar71xx_eth0_data
.phy_if_mode
= PHY_INTERFACE_MODE_MII
;
285 ar71xx_eth0_data
.speed
= SPEED_100
;
286 ar71xx_eth0_data
.duplex
= DUPLEX_FULL
;
288 ar71xx_eth1_data
.phy_if_mode
= PHY_INTERFACE_MODE_RMII
;
289 ar71xx_eth1_data
.phy_mask
= 0x00000001;
291 ar71xx_add_device_eth(0);
292 ar71xx_add_device_eth(1);
294 ar71xx_pci_init(ARRAY_SIZE(rb4xx_pci_irqs
), rb4xx_pci_irqs
);
297 MIPS_MACHINE(AR71XX_MACH_RB_493
, "493", "MikroTik RouterBOARD 493/AH",