X-Git-Url: https://git.archive.openwrt.org/?a=blobdiff_plain;f=target%2Flinux%2Far71xx%2Ffiles%2Farch%2Fmips%2Far71xx%2Fmach-rb4xx.c;h=02fcaa47b9c229101d6fcf9601892ebe55e9d6f4;hb=3db28f95612c6624080170a8ad73192e579f82ea;hp=dc3c2005dfad0e0f61eac454bd99cbbb1e9737e1;hpb=2a528006a3931eadc2a9595315d0dd1c86aa9683;p=openwrt.git diff --git a/target/linux/ar71xx/files/arch/mips/ar71xx/mach-rb4xx.c b/target/linux/ar71xx/files/arch/mips/ar71xx/mach-rb4xx.c index dc3c2005df..02fcaa47b9 100644 --- a/target/linux/ar71xx/files/arch/mips/ar71xx/mach-rb4xx.c +++ b/target/linux/ar71xx/files/arch/mips/ar71xx/mach-rb4xx.c @@ -1,7 +1,7 @@ /* * MikroTik RouterBOARD 4xx series support * - * Copyright (C) 2008 Gabor Juhos + * Copyright (C) 2008-2010 Gabor Juhos * Copyright (C) 2008 Imre Kaloz * * This program is free software; you can redistribute it and/or modify it @@ -15,9 +15,12 @@ #include #include #include +#include +#include #include #include +#include #include "machtype.h" #include "devices.h" @@ -28,22 +31,50 @@ #define RB4XX_GPIO_USER_LED 4 #define RB4XX_GPIO_RESET_SWITCH 7 -#define RB4XX_BUTTONS_POLL_INTERVAL 20 +#define RB4XX_GPIO_CPLD_BASE 32 +#define RB4XX_GPIO_CPLD_LED1 (RB4XX_GPIO_CPLD_BASE + CPLD_GPIO_nLED1) +#define RB4XX_GPIO_CPLD_LED2 (RB4XX_GPIO_CPLD_BASE + CPLD_GPIO_nLED2) +#define RB4XX_GPIO_CPLD_LED3 (RB4XX_GPIO_CPLD_BASE + CPLD_GPIO_nLED3) +#define RB4XX_GPIO_CPLD_LED4 (RB4XX_GPIO_CPLD_BASE + CPLD_GPIO_nLED4) +#define RB4XX_GPIO_CPLD_LED5 (RB4XX_GPIO_CPLD_BASE + CPLD_GPIO_nLED5) + +#define RB4XX_KEYS_POLL_INTERVAL 20 /* msecs */ +#define RB4XX_KEYS_DEBOUNCE_INTERVAL (3 * RB4XX_KEYS_POLL_INTERVAL) static struct gpio_led rb4xx_leds_gpio[] __initdata = { { .name = "rb4xx:yellow:user", .gpio = RB4XX_GPIO_USER_LED, .active_low = 0, + }, { + .name = "rb4xx:green:led1", + .gpio = RB4XX_GPIO_CPLD_LED1, + .active_low = 1, + }, { + .name = "rb4xx:green:led2", + .gpio = RB4XX_GPIO_CPLD_LED2, + .active_low = 1, + }, { + .name = "rb4xx:green:led3", + .gpio = RB4XX_GPIO_CPLD_LED3, + .active_low = 1, + }, { + .name = "rb4xx:green:led4", + .gpio = RB4XX_GPIO_CPLD_LED4, + .active_low = 1, + }, { + .name = "rb4xx:green:led5", + .gpio = RB4XX_GPIO_CPLD_LED5, + .active_low = 0, }, }; -static struct gpio_button rb4xx_gpio_buttons[] __initdata = { +static struct gpio_keys_button rb4xx_gpio_keys[] __initdata = { { .desc = "reset_switch", .type = EV_KEY, .code = KEY_RESTART, - .threshold = 3, + .debounce_interval = RB4XX_KEYS_DEBOUNCE_INTERVAL, .gpio = RB4XX_GPIO_RESET_SWITCH, .active_low = 1, } @@ -78,107 +109,117 @@ static struct ar71xx_pci_irq rb4xx_pci_irqs[] __initdata = { } }; -#if 0 -/* - * SPI device support is experimental - */ +#ifdef CONFIG_MTD_PARTITIONS +static struct mtd_partition rb4xx_partitions[] = { + { + .name = "routerboot", + .offset = 0, + .size = 0x0b000, + .mask_flags = MTD_WRITEABLE, + }, { + .name = "hard_config", + .offset = 0x0b000, + .size = 0x01000, + .mask_flags = MTD_WRITEABLE, + }, { + .name = "bios", + .offset = 0x0d000, + .size = 0x02000, + .mask_flags = MTD_WRITEABLE, + }, { + .name = "soft_config", + .offset = 0x0f000, + .size = 0x01000, + } +}; +#define rb4xx_num_partitions ARRAY_SIZE(rb4xx_partitions) +#else /* CONFIG_MTD_PARTITIONS */ +#define rb4xx_partitions NULL +#define rb4xx_num_partitions 0 +#endif /* CONFIG_MTD_PARTITIONS */ + static struct flash_platform_data rb4xx_flash_data = { - .type = "pm25lv512", + .type = "pm25lv512", + .parts = rb4xx_partitions, + .nr_parts = rb4xx_num_partitions, }; -static struct spi_board_info rb4xx_spi_info[] = { - { - .bus_num = 0, - .chip_select = 0, - .max_speed_hz = 25000000, - .modalias = "m25p80", - .platform_data = &rb4xx_flash_data, - } +static struct rb4xx_cpld_platform_data rb4xx_cpld_data = { + .gpio_base = RB4XX_GPIO_CPLD_BASE, }; -static struct mmc_spi_platform_data rb433_mmc_data = { +static struct mmc_spi_platform_data rb4xx_mmc_data = { .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34, }; -static struct spi_board_info rb433_spi_info[] = { +static struct spi_board_info rb4xx_spi_info[] = { { .bus_num = 0, .chip_select = 0, .max_speed_hz = 25000000, .modalias = "m25p80", - .platform_data = &rb433_flash_data, + .platform_data = &rb4xx_flash_data, }, { .bus_num = 0, - .chip_select = 2, + .chip_select = 1, .max_speed_hz = 25000000, - .modalias = "mmc_spi", - .platform_data = &rb433_mmc_data, + .modalias = "spi-rb4xx-cpld", + .platform_data = &rb4xx_cpld_data, } }; -static u32 rb433_spi_get_ioc_base(u8 chip_select, int cs_high, int is_on) -{ - u32 ret; - - if (is_on == AR71XX_SPI_CS_INACTIVE) { - ret = SPI_IOC_CS0 | SPI_IOC_CS1; - } else { - if (cs_high) { - ret = SPI_IOC_CS0 | SPI_IOC_CS1; - } else { - if ((chip_select ^ 2) == 0) - ret = SPI_IOC_CS1 ^ (SPI_IOC_CS0 | SPI_IOC_CS1); - else - ret = SPI_IOC_CS0 ^ (SPI_IOC_CS0 | SPI_IOC_CS1); - } +static struct spi_board_info rb4xx_microsd_info[] = { + { + .bus_num = 0, + .chip_select = 2, + .max_speed_hz = 25000000, + .modalias = "mmc_spi", + .platform_data = &rb4xx_mmc_data, } +}; - return ret; -} -struct ar71xx_spi_platform_data rb433_spi_data = { - .bus_num = 0, - .num_chipselect = 3, - .get_ioc_base = rb433_spi_get_ioc_base, +static struct resource rb4xx_spi_resources[] = { + { + .start = AR71XX_SPI_BASE, + .end = AR71XX_SPI_BASE + AR71XX_SPI_SIZE - 1, + .flags = IORESOURCE_MEM, + }, }; -static void rb4xx_add_device_spi(void) -{ - ar71xx_add_device_spi(NULL, rb4xx_spi_info, ARRAY_SIZE(rb4xx_spi_info)); -} - -static void rb433_add_device_spi(void) -{ - ar71xx_add_device_spi(&rb433_spi_data, rb433_spi_info, - ARRAY_SIZE(rb433_spi_info)); -} -#else -static inline void rb4xx_add_device_spi(void) {} -static inline void rb433_add_device_spi(void) {} -#endif +static struct platform_device rb4xx_spi_device = { + .name = "rb4xx-spi", + .id = -1, + .resource = rb4xx_spi_resources, + .num_resources = ARRAY_SIZE(rb4xx_spi_resources), +}; static void __init rb4xx_generic_setup(void) { ar71xx_gpio_function_enable(AR71XX_GPIO_FUNC_SPI_CS1_EN | - AR71XX_GPIO_FUNC_SPI_CS2_EN); + AR71XX_GPIO_FUNC_SPI_CS2_EN); ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(rb4xx_leds_gpio), rb4xx_leds_gpio); - ar71xx_add_device_gpio_buttons(-1, RB4XX_BUTTONS_POLL_INTERVAL, - ARRAY_SIZE(rb4xx_gpio_buttons), - rb4xx_gpio_buttons); + ar71xx_register_gpio_keys_polled(-1, RB4XX_KEYS_POLL_INTERVAL, + ARRAY_SIZE(rb4xx_gpio_keys), + rb4xx_gpio_keys); + spi_register_board_info(rb4xx_spi_info, ARRAY_SIZE(rb4xx_spi_info)); + platform_device_register(&rb4xx_spi_device); platform_device_register(&rb4xx_nand_device); } static void __init rb411_setup(void) { rb4xx_generic_setup(); - rb4xx_add_device_spi(); + spi_register_board_info(rb4xx_microsd_info, + ARRAY_SIZE(rb4xx_microsd_info)); ar71xx_add_device_mdio(0xfffffffc); + ar71xx_init_mac(ar71xx_eth0_data.mac_addr, ar71xx_mac_base, 0); ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII; ar71xx_eth0_data.phy_mask = 0x00000003; @@ -206,13 +247,16 @@ MIPS_MACHINE(AR71XX_MACH_RB_411U, "411U", "MikroTik RouterBOARD 411U", static void __init rb433_setup(void) { rb4xx_generic_setup(); - rb433_add_device_spi(); + spi_register_board_info(rb4xx_microsd_info, + ARRAY_SIZE(rb4xx_microsd_info)); ar71xx_add_device_mdio(~RB433_MDIO_PHYMASK); + ar71xx_init_mac(ar71xx_eth0_data.mac_addr, ar71xx_mac_base, 1); ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII; ar71xx_eth0_data.phy_mask = RB433_LAN_PHYMASK; + ar71xx_init_mac(ar71xx_eth1_data.mac_addr, ar71xx_mac_base, 0); ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII; ar71xx_eth1_data.phy_mask = RB433_WAN_PHYMASK; @@ -241,14 +285,16 @@ MIPS_MACHINE(AR71XX_MACH_RB_433U, "433U", "MikroTik RouterBOARD 433UAH", static void __init rb450_generic_setup(int gige) { rb4xx_generic_setup(); - rb4xx_add_device_spi(); - ar71xx_add_device_mdio(~RB450_MDIO_PHYMASK); - ar71xx_eth0_data.phy_if_mode = (gige) ? PHY_INTERFACE_MODE_RGMII : PHY_INTERFACE_MODE_MII; + ar71xx_init_mac(ar71xx_eth0_data.mac_addr, ar71xx_mac_base, 1); + ar71xx_eth0_data.phy_if_mode = (gige) ? + PHY_INTERFACE_MODE_RGMII : PHY_INTERFACE_MODE_MII; ar71xx_eth0_data.phy_mask = RB450_LAN_PHYMASK; - ar71xx_eth1_data.phy_if_mode = (gige) ? PHY_INTERFACE_MODE_RGMII : PHY_INTERFACE_MODE_RMII; + ar71xx_init_mac(ar71xx_eth1_data.mac_addr, ar71xx_mac_base, 0); + ar71xx_eth1_data.phy_if_mode = (gige) ? + PHY_INTERFACE_MODE_RGMII : PHY_INTERFACE_MODE_RMII; ar71xx_eth1_data.phy_mask = RB450_WAN_PHYMASK; ar71xx_add_device_eth(1); @@ -266,6 +312,8 @@ MIPS_MACHINE(AR71XX_MACH_RB_450, "450", "MikroTik RouterBOARD 450", static void __init rb450g_setup(void) { rb450_generic_setup(1); + spi_register_board_info(rb4xx_microsd_info, + ARRAY_SIZE(rb4xx_microsd_info)); } MIPS_MACHINE(AR71XX_MACH_RB_450G, "450G", "MikroTik RouterBOARD 450G", @@ -274,14 +322,15 @@ MIPS_MACHINE(AR71XX_MACH_RB_450G, "450G", "MikroTik RouterBOARD 450G", static void __init rb493_setup(void) { rb4xx_generic_setup(); - rb4xx_add_device_spi(); ar71xx_add_device_mdio(0x3fffff00); + ar71xx_init_mac(ar71xx_eth0_data.mac_addr, ar71xx_mac_base, 0); ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII; ar71xx_eth0_data.speed = SPEED_100; ar71xx_eth0_data.duplex = DUPLEX_FULL; + ar71xx_init_mac(ar71xx_eth1_data.mac_addr, ar71xx_mac_base, 1); ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII; ar71xx_eth1_data.phy_mask = 0x00000001;