2 * MikroTik RouterBOARD 4xx series support
4 * Copyright (C) 2008-2010 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/mtd/mtd.h>
19 #include <linux/mtd/partitions.h>
21 #include <asm/mach-ar71xx/ar71xx.h>
22 #include <asm/mach-ar71xx/pci.h>
23 #include <asm/mach-ar71xx/rb4xx_cpld.h>
27 #include "dev-gpio-buttons.h"
28 #include "dev-leds-gpio.h"
31 #define RB4XX_GPIO_USER_LED 4
32 #define RB4XX_GPIO_RESET_SWITCH 7
34 #define RB4XX_GPIO_CPLD_BASE 32
35 #define RB4XX_GPIO_CPLD_LED1 (RB4XX_GPIO_CPLD_BASE + CPLD_GPIO_nLED1)
36 #define RB4XX_GPIO_CPLD_LED2 (RB4XX_GPIO_CPLD_BASE + CPLD_GPIO_nLED2)
37 #define RB4XX_GPIO_CPLD_LED3 (RB4XX_GPIO_CPLD_BASE + CPLD_GPIO_nLED3)
38 #define RB4XX_GPIO_CPLD_LED4 (RB4XX_GPIO_CPLD_BASE + CPLD_GPIO_nLED4)
39 #define RB4XX_GPIO_CPLD_LED5 (RB4XX_GPIO_CPLD_BASE + CPLD_GPIO_nLED5)
41 #define RB4XX_BUTTONS_POLL_INTERVAL 20
43 static struct gpio_led rb4xx_leds_gpio[] __initdata = {
45 .name = "rb4xx:yellow:user",
46 .gpio = RB4XX_GPIO_USER_LED,
49 .name = "rb4xx:green:led1",
50 .gpio = RB4XX_GPIO_CPLD_LED1,
53 .name = "rb4xx:green:led2",
54 .gpio = RB4XX_GPIO_CPLD_LED2,
57 .name = "rb4xx:green:led3",
58 .gpio = RB4XX_GPIO_CPLD_LED3,
61 .name = "rb4xx:green:led4",
62 .gpio = RB4XX_GPIO_CPLD_LED4,
65 .name = "rb4xx:green:led5",
66 .gpio = RB4XX_GPIO_CPLD_LED5,
71 static struct gpio_button rb4xx_gpio_buttons[] __initdata = {
73 .desc = "reset_switch",
77 .gpio = RB4XX_GPIO_RESET_SWITCH,
82 static struct platform_device rb4xx_nand_device = {
87 static struct ar71xx_pci_irq rb4xx_pci_irqs[] __initdata = {
91 .irq = AR71XX_PCI_IRQ_DEV2,
95 .irq = AR71XX_PCI_IRQ_DEV0,
99 .irq = AR71XX_PCI_IRQ_DEV1,
103 .irq = AR71XX_PCI_IRQ_DEV1,
107 .irq = AR71XX_PCI_IRQ_DEV2,
111 #ifdef CONFIG_MTD_PARTITIONS
112 static struct mtd_partition rb4xx_partitions[] = {
114 .name = "routerboot",
117 .mask_flags = MTD_WRITEABLE,
119 .name = "hard_config",
122 .mask_flags = MTD_WRITEABLE,
127 .mask_flags = MTD_WRITEABLE,
129 .name = "soft_config",
134 #define rb4xx_num_partitions ARRAY_SIZE(rb4xx_partitions)
135 #else /* CONFIG_MTD_PARTITIONS */
136 #define rb4xx_partitions NULL
137 #define rb4xx_num_partitions 0
138 #endif /* CONFIG_MTD_PARTITIONS */
140 static struct flash_platform_data rb4xx_flash_data = {
142 .parts = rb4xx_partitions,
143 .nr_parts = rb4xx_num_partitions,
146 static struct rb4xx_cpld_platform_data rb4xx_cpld_data = {
147 .gpio_base = RB4XX_GPIO_CPLD_BASE,
150 static struct mmc_spi_platform_data rb4xx_mmc_data = {
151 .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34,
154 static struct spi_board_info rb4xx_spi_info[] = {
158 .max_speed_hz = 25000000,
159 .modalias = "m25p80",
160 .platform_data = &rb4xx_flash_data,
164 .max_speed_hz = 25000000,
165 .modalias = "spi-rb4xx-cpld",
166 .platform_data = &rb4xx_cpld_data,
170 static struct spi_board_info rb4xx_microsd_info[] = {
174 .max_speed_hz = 25000000,
175 .modalias = "mmc_spi",
176 .platform_data = &rb4xx_mmc_data,
181 static struct resource rb4xx_spi_resources[] = {
183 .start = AR71XX_SPI_BASE,
184 .end = AR71XX_SPI_BASE + AR71XX_SPI_SIZE - 1,
185 .flags = IORESOURCE_MEM,
189 static struct platform_device rb4xx_spi_device = {
192 .resource = rb4xx_spi_resources,
193 .num_resources = ARRAY_SIZE(rb4xx_spi_resources),
196 static void __init rb4xx_generic_setup(void)
198 ar71xx_gpio_function_enable(AR71XX_GPIO_FUNC_SPI_CS1_EN |
199 AR71XX_GPIO_FUNC_SPI_CS2_EN);
201 ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(rb4xx_leds_gpio),
204 ar71xx_add_device_gpio_buttons(-1, RB4XX_BUTTONS_POLL_INTERVAL,
205 ARRAY_SIZE(rb4xx_gpio_buttons),
208 spi_register_board_info(rb4xx_spi_info, ARRAY_SIZE(rb4xx_spi_info));
209 platform_device_register(&rb4xx_spi_device);
210 platform_device_register(&rb4xx_nand_device);
213 static void __init rb411_setup(void)
215 rb4xx_generic_setup();
216 spi_register_board_info(rb4xx_microsd_info,
217 ARRAY_SIZE(rb4xx_microsd_info));
219 ar71xx_add_device_mdio(0xfffffffc);
221 ar71xx_init_mac(ar71xx_eth0_data.mac_addr, ar71xx_mac_base, 0);
222 ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
223 ar71xx_eth0_data.phy_mask = 0x00000003;
225 ar71xx_add_device_eth(0);
227 ar71xx_pci_init(ARRAY_SIZE(rb4xx_pci_irqs), rb4xx_pci_irqs);
230 MIPS_MACHINE(AR71XX_MACH_RB_411, "411", "MikroTik RouterBOARD 411/A/AH",
233 static void __init rb411u_setup(void)
236 ar71xx_add_device_usb();
239 MIPS_MACHINE(AR71XX_MACH_RB_411U, "411U", "MikroTik RouterBOARD 411U",
242 #define RB433_LAN_PHYMASK BIT(0)
243 #define RB433_WAN_PHYMASK BIT(4)
244 #define RB433_MDIO_PHYMASK (RB433_LAN_PHYMASK | RB433_WAN_PHYMASK)
246 static void __init rb433_setup(void)
248 rb4xx_generic_setup();
249 spi_register_board_info(rb4xx_microsd_info,
250 ARRAY_SIZE(rb4xx_microsd_info));
252 ar71xx_add_device_mdio(~RB433_MDIO_PHYMASK);
254 ar71xx_init_mac(ar71xx_eth0_data.mac_addr, ar71xx_mac_base, 1);
255 ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
256 ar71xx_eth0_data.phy_mask = RB433_LAN_PHYMASK;
258 ar71xx_init_mac(ar71xx_eth1_data.mac_addr, ar71xx_mac_base, 0);
259 ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
260 ar71xx_eth1_data.phy_mask = RB433_WAN_PHYMASK;
262 ar71xx_add_device_eth(1);
263 ar71xx_add_device_eth(0);
265 ar71xx_pci_init(ARRAY_SIZE(rb4xx_pci_irqs), rb4xx_pci_irqs);
268 MIPS_MACHINE(AR71XX_MACH_RB_433, "433", "MikroTik RouterBOARD 433/AH",
271 static void __init rb433u_setup(void)
274 ar71xx_add_device_usb();
277 MIPS_MACHINE(AR71XX_MACH_RB_433U, "433U", "MikroTik RouterBOARD 433UAH",
280 #define RB450_LAN_PHYMASK BIT(0)
281 #define RB450_WAN_PHYMASK BIT(4)
282 #define RB450_MDIO_PHYMASK (RB450_LAN_PHYMASK | RB450_WAN_PHYMASK)
284 static void __init rb450_generic_setup(int gige)
286 rb4xx_generic_setup();
287 ar71xx_add_device_mdio(~RB450_MDIO_PHYMASK);
289 ar71xx_init_mac(ar71xx_eth0_data.mac_addr, ar71xx_mac_base, 1);
290 ar71xx_eth0_data.phy_if_mode = (gige) ? PHY_INTERFACE_MODE_RGMII : PHY_INTERFACE_MODE_MII;
291 ar71xx_eth0_data.phy_mask = RB450_LAN_PHYMASK;
293 ar71xx_init_mac(ar71xx_eth1_data.mac_addr, ar71xx_mac_base, 0);
294 ar71xx_eth1_data.phy_if_mode = (gige) ? PHY_INTERFACE_MODE_RGMII : PHY_INTERFACE_MODE_RMII;
295 ar71xx_eth1_data.phy_mask = RB450_WAN_PHYMASK;
297 ar71xx_add_device_eth(1);
298 ar71xx_add_device_eth(0);
301 static void __init rb450_setup(void)
303 rb450_generic_setup(0);
306 MIPS_MACHINE(AR71XX_MACH_RB_450, "450", "MikroTik RouterBOARD 450",
309 static void __init rb450g_setup(void)
311 rb450_generic_setup(1);
312 spi_register_board_info(rb4xx_microsd_info,
313 ARRAY_SIZE(rb4xx_microsd_info));
316 MIPS_MACHINE(AR71XX_MACH_RB_450G, "450G", "MikroTik RouterBOARD 450G",
319 static void __init rb493_setup(void)
321 rb4xx_generic_setup();
323 ar71xx_add_device_mdio(0x3fffff00);
325 ar71xx_init_mac(ar71xx_eth0_data.mac_addr, ar71xx_mac_base, 0);
326 ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
327 ar71xx_eth0_data.speed = SPEED_100;
328 ar71xx_eth0_data.duplex = DUPLEX_FULL;
330 ar71xx_init_mac(ar71xx_eth1_data.mac_addr, ar71xx_mac_base, 1);
331 ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
332 ar71xx_eth1_data.phy_mask = 0x00000001;
334 ar71xx_add_device_eth(0);
335 ar71xx_add_device_eth(1);
337 ar71xx_pci_init(ARRAY_SIZE(rb4xx_pci_irqs), rb4xx_pci_irqs);
340 MIPS_MACHINE(AR71XX_MACH_RB_493, "493", "MikroTik RouterBOARD 493/AH",