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/mdio-gpio.h>
15 #include <linux/mmc/host.h>
16 #include <linux/spi/spi.h>
17 #include <linux/spi/flash.h>
18 #include <linux/spi/mmc_spi.h>
19 #include <linux/mtd/mtd.h>
20 #include <linux/mtd/partitions.h>
22 #include <asm/mach-ar71xx/ar71xx.h>
23 #include <asm/mach-ar71xx/pci.h>
24 #include <asm/mach-ar71xx/rb4xx_cpld.h>
28 #include "dev-gpio-buttons.h"
29 #include "dev-leds-gpio.h"
32 #define RB4XX_GPIO_USER_LED 4
33 #define RB4XX_GPIO_RESET_SWITCH 7
35 #define RB4XX_GPIO_CPLD_BASE 32
36 #define RB4XX_GPIO_CPLD_LED1 (RB4XX_GPIO_CPLD_BASE + CPLD_GPIO_nLED1)
37 #define RB4XX_GPIO_CPLD_LED2 (RB4XX_GPIO_CPLD_BASE + CPLD_GPIO_nLED2)
38 #define RB4XX_GPIO_CPLD_LED3 (RB4XX_GPIO_CPLD_BASE + CPLD_GPIO_nLED3)
39 #define RB4XX_GPIO_CPLD_LED4 (RB4XX_GPIO_CPLD_BASE + CPLD_GPIO_nLED4)
40 #define RB4XX_GPIO_CPLD_LED5 (RB4XX_GPIO_CPLD_BASE + CPLD_GPIO_nLED5)
42 #define RB4XX_KEYS_POLL_INTERVAL 20 /* msecs */
43 #define RB4XX_KEYS_DEBOUNCE_INTERVAL (3 * RB4XX_KEYS_POLL_INTERVAL)
45 static struct gpio_led rb4xx_leds_gpio
[] __initdata
= {
47 .name
= "rb4xx:yellow:user",
48 .gpio
= RB4XX_GPIO_USER_LED
,
51 .name
= "rb4xx:green:led1",
52 .gpio
= RB4XX_GPIO_CPLD_LED1
,
55 .name
= "rb4xx:green:led2",
56 .gpio
= RB4XX_GPIO_CPLD_LED2
,
59 .name
= "rb4xx:green:led3",
60 .gpio
= RB4XX_GPIO_CPLD_LED3
,
63 .name
= "rb4xx:green:led4",
64 .gpio
= RB4XX_GPIO_CPLD_LED4
,
67 .name
= "rb4xx:green:led5",
68 .gpio
= RB4XX_GPIO_CPLD_LED5
,
73 static struct gpio_keys_button rb4xx_gpio_keys
[] __initdata
= {
75 .desc
= "reset_switch",
78 .debounce_interval
= RB4XX_KEYS_DEBOUNCE_INTERVAL
,
79 .gpio
= RB4XX_GPIO_RESET_SWITCH
,
84 static struct platform_device rb4xx_nand_device
= {
89 static struct ar71xx_pci_irq rb4xx_pci_irqs
[] __initdata
= {
93 .irq
= AR71XX_PCI_IRQ_DEV2
,
97 .irq
= AR71XX_PCI_IRQ_DEV0
,
101 .irq
= AR71XX_PCI_IRQ_DEV1
,
105 .irq
= AR71XX_PCI_IRQ_DEV1
,
109 .irq
= AR71XX_PCI_IRQ_DEV2
,
113 #ifdef CONFIG_MTD_PARTITIONS
114 static struct mtd_partition rb4xx_partitions
[] = {
116 .name
= "routerboot",
119 .mask_flags
= MTD_WRITEABLE
,
121 .name
= "hard_config",
124 .mask_flags
= MTD_WRITEABLE
,
129 .mask_flags
= MTD_WRITEABLE
,
131 .name
= "soft_config",
136 #define rb4xx_num_partitions ARRAY_SIZE(rb4xx_partitions)
137 #else /* CONFIG_MTD_PARTITIONS */
138 #define rb4xx_partitions NULL
139 #define rb4xx_num_partitions 0
140 #endif /* CONFIG_MTD_PARTITIONS */
142 static struct flash_platform_data rb4xx_flash_data
= {
144 .parts
= rb4xx_partitions
,
145 .nr_parts
= rb4xx_num_partitions
,
148 static struct rb4xx_cpld_platform_data rb4xx_cpld_data
= {
149 .gpio_base
= RB4XX_GPIO_CPLD_BASE
,
152 static struct mmc_spi_platform_data rb4xx_mmc_data
= {
153 .ocr_mask
= MMC_VDD_32_33
| MMC_VDD_33_34
,
156 static struct spi_board_info rb4xx_spi_info
[] = {
160 .max_speed_hz
= 25000000,
161 .modalias
= "m25p80",
162 .platform_data
= &rb4xx_flash_data
,
166 .max_speed_hz
= 25000000,
167 .modalias
= "spi-rb4xx-cpld",
168 .platform_data
= &rb4xx_cpld_data
,
172 static struct spi_board_info rb4xx_microsd_info
[] = {
176 .max_speed_hz
= 25000000,
177 .modalias
= "mmc_spi",
178 .platform_data
= &rb4xx_mmc_data
,
183 static struct resource rb4xx_spi_resources
[] = {
185 .start
= AR71XX_SPI_BASE
,
186 .end
= AR71XX_SPI_BASE
+ AR71XX_SPI_SIZE
- 1,
187 .flags
= IORESOURCE_MEM
,
191 static struct platform_device rb4xx_spi_device
= {
194 .resource
= rb4xx_spi_resources
,
195 .num_resources
= ARRAY_SIZE(rb4xx_spi_resources
),
198 static void __init
rb4xx_generic_setup(void)
200 ar71xx_gpio_function_enable(AR71XX_GPIO_FUNC_SPI_CS1_EN
|
201 AR71XX_GPIO_FUNC_SPI_CS2_EN
);
203 ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(rb4xx_leds_gpio
),
206 ar71xx_register_gpio_keys_polled(-1, RB4XX_KEYS_POLL_INTERVAL
,
207 ARRAY_SIZE(rb4xx_gpio_keys
),
210 spi_register_board_info(rb4xx_spi_info
, ARRAY_SIZE(rb4xx_spi_info
));
211 platform_device_register(&rb4xx_spi_device
);
212 platform_device_register(&rb4xx_nand_device
);
215 static void __init
rb411_setup(void)
217 rb4xx_generic_setup();
218 spi_register_board_info(rb4xx_microsd_info
,
219 ARRAY_SIZE(rb4xx_microsd_info
));
221 ar71xx_add_device_mdio(0, 0xfffffffc);
223 ar71xx_init_mac(ar71xx_eth0_data
.mac_addr
, ar71xx_mac_base
, 0);
224 ar71xx_eth0_data
.phy_if_mode
= PHY_INTERFACE_MODE_MII
;
225 ar71xx_eth0_data
.phy_mask
= 0x00000003;
227 ar71xx_add_device_eth(0);
229 ar71xx_pci_init(ARRAY_SIZE(rb4xx_pci_irqs
), rb4xx_pci_irqs
);
232 MIPS_MACHINE(AR71XX_MACH_RB_411
, "411", "MikroTik RouterBOARD 411/A/AH",
235 static void __init
rb411u_setup(void)
238 ar71xx_add_device_usb();
241 MIPS_MACHINE(AR71XX_MACH_RB_411U
, "411U", "MikroTik RouterBOARD 411U",
244 #define RB433_LAN_PHYMASK BIT(0)
245 #define RB433_WAN_PHYMASK BIT(4)
246 #define RB433_MDIO_PHYMASK (RB433_LAN_PHYMASK | RB433_WAN_PHYMASK)
248 static void __init
rb433_setup(void)
250 rb4xx_generic_setup();
251 spi_register_board_info(rb4xx_microsd_info
,
252 ARRAY_SIZE(rb4xx_microsd_info
));
254 ar71xx_add_device_mdio(0, ~RB433_MDIO_PHYMASK
);
256 ar71xx_init_mac(ar71xx_eth0_data
.mac_addr
, ar71xx_mac_base
, 1);
257 ar71xx_eth0_data
.phy_if_mode
= PHY_INTERFACE_MODE_MII
;
258 ar71xx_eth0_data
.phy_mask
= RB433_LAN_PHYMASK
;
260 ar71xx_init_mac(ar71xx_eth1_data
.mac_addr
, ar71xx_mac_base
, 0);
261 ar71xx_eth1_data
.phy_if_mode
= PHY_INTERFACE_MODE_RMII
;
262 ar71xx_eth1_data
.phy_mask
= RB433_WAN_PHYMASK
;
264 ar71xx_add_device_eth(1);
265 ar71xx_add_device_eth(0);
267 ar71xx_pci_init(ARRAY_SIZE(rb4xx_pci_irqs
), rb4xx_pci_irqs
);
270 MIPS_MACHINE(AR71XX_MACH_RB_433
, "433", "MikroTik RouterBOARD 433/AH",
273 static void __init
rb433u_setup(void)
276 ar71xx_add_device_usb();
279 MIPS_MACHINE(AR71XX_MACH_RB_433U
, "433U", "MikroTik RouterBOARD 433UAH",
282 #define RB450_LAN_PHYMASK BIT(0)
283 #define RB450_WAN_PHYMASK BIT(4)
284 #define RB450_MDIO_PHYMASK (RB450_LAN_PHYMASK | RB450_WAN_PHYMASK)
286 static void __init
rb450_generic_setup(int gige
)
288 rb4xx_generic_setup();
289 ar71xx_add_device_mdio(0, ~RB450_MDIO_PHYMASK
);
291 ar71xx_init_mac(ar71xx_eth0_data
.mac_addr
, ar71xx_mac_base
, 1);
292 ar71xx_eth0_data
.phy_if_mode
= (gige
) ?
293 PHY_INTERFACE_MODE_RGMII
: PHY_INTERFACE_MODE_MII
;
294 ar71xx_eth0_data
.phy_mask
= RB450_LAN_PHYMASK
;
296 ar71xx_init_mac(ar71xx_eth1_data
.mac_addr
, ar71xx_mac_base
, 0);
297 ar71xx_eth1_data
.phy_if_mode
= (gige
) ?
298 PHY_INTERFACE_MODE_RGMII
: PHY_INTERFACE_MODE_RMII
;
299 ar71xx_eth1_data
.phy_mask
= RB450_WAN_PHYMASK
;
301 ar71xx_add_device_eth(1);
302 ar71xx_add_device_eth(0);
305 static void __init
rb450_setup(void)
307 rb450_generic_setup(0);
310 MIPS_MACHINE(AR71XX_MACH_RB_450
, "450", "MikroTik RouterBOARD 450",
313 static void __init
rb450g_setup(void)
315 rb450_generic_setup(1);
316 spi_register_board_info(rb4xx_microsd_info
,
317 ARRAY_SIZE(rb4xx_microsd_info
));
320 MIPS_MACHINE(AR71XX_MACH_RB_450G
, "450G", "MikroTik RouterBOARD 450G",
323 static void __init
rb493_setup(void)
325 rb4xx_generic_setup();
327 ar71xx_add_device_mdio(0, 0x3fffff00);
329 ar71xx_init_mac(ar71xx_eth0_data
.mac_addr
, ar71xx_mac_base
, 0);
330 ar71xx_eth0_data
.phy_if_mode
= PHY_INTERFACE_MODE_MII
;
331 ar71xx_eth0_data
.speed
= SPEED_100
;
332 ar71xx_eth0_data
.duplex
= DUPLEX_FULL
;
334 ar71xx_init_mac(ar71xx_eth1_data
.mac_addr
, ar71xx_mac_base
, 1);
335 ar71xx_eth1_data
.phy_if_mode
= PHY_INTERFACE_MODE_RMII
;
336 ar71xx_eth1_data
.phy_mask
= 0x00000001;
338 ar71xx_add_device_eth(0);
339 ar71xx_add_device_eth(1);
341 ar71xx_pci_init(ARRAY_SIZE(rb4xx_pci_irqs
), rb4xx_pci_irqs
);
344 MIPS_MACHINE(AR71XX_MACH_RB_493
, "493", "MikroTik RouterBOARD 493/AH",
347 #define RB493G_GPIO_MDIO_MDC 7
348 #define RB493G_GPIO_MDIO_DATA 8
350 #define RB493G_MDIO_PHYMASK BIT(0)
352 static struct mdio_gpio_platform_data rb493g_mdio_data
= {
353 .mdc
= RB493G_GPIO_MDIO_MDC
,
354 .mdio
= RB493G_GPIO_MDIO_DATA
,
356 .phy_mask
= ~RB493G_MDIO_PHYMASK
,
359 static struct platform_device rb493g_mdio_device
= {
363 .platform_data
= &rb493g_mdio_data
,
367 static void __init
rb493g_setup(void)
369 ar71xx_gpio_function_enable(AR71XX_GPIO_FUNC_SPI_CS1_EN
|
370 AR71XX_GPIO_FUNC_SPI_CS2_EN
);
372 ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(rb4xx_leds_gpio
),
375 spi_register_board_info(rb4xx_spi_info
, ARRAY_SIZE(rb4xx_spi_info
));
376 platform_device_register(&rb4xx_spi_device
);
377 platform_device_register(&rb4xx_nand_device
);
379 ar71xx_add_device_mdio(0, ~RB493G_MDIO_PHYMASK
);
381 ar71xx_init_mac(ar71xx_eth0_data
.mac_addr
, ar71xx_mac_base
, 0);
382 ar71xx_eth0_data
.phy_if_mode
= PHY_INTERFACE_MODE_RGMII
;
383 ar71xx_eth0_data
.phy_mask
= RB493G_MDIO_PHYMASK
;
384 ar71xx_eth0_data
.speed
= SPEED_1000
;
385 ar71xx_eth0_data
.duplex
= DUPLEX_FULL
;
387 ar71xx_init_mac(ar71xx_eth1_data
.mac_addr
, ar71xx_mac_base
, 1);
388 ar71xx_eth1_data
.phy_if_mode
= PHY_INTERFACE_MODE_RGMII
;
389 ar71xx_eth1_data
.mii_bus_dev
= &rb493g_mdio_device
.dev
;
390 ar71xx_eth1_data
.phy_mask
= RB493G_MDIO_PHYMASK
;
391 ar71xx_eth1_data
.speed
= SPEED_1000
;
392 ar71xx_eth1_data
.duplex
= DUPLEX_FULL
;
395 platform_device_register(&rb493g_mdio_device
);
397 ar71xx_add_device_eth(1);
398 ar71xx_add_device_eth(0);
400 ar71xx_add_device_usb();
402 ar71xx_pci_init(ARRAY_SIZE(rb4xx_pci_irqs
), rb4xx_pci_irqs
);
405 MIPS_MACHINE(AR71XX_MACH_RB_493G
, "493G", "MikroTik RouterBOARD 493G",