The RTC on the Routerstation Pro is connected through SPI and shares
its line with the flash. Linux' SPI driver does not allow more than
one device per CS, so create special handling so CS1 high is handled
internally as CS0 high.
---
 .../ar71xx/files/arch/mips/ar71xx/mach-ubnt.c      |   54 +++++++++++++++++++-
 1 files changed, 53 insertions(+), 1 deletions(-)

diff --git a/target/linux/ar71xx/files/arch/mips/ar71xx/mach-ubnt.c 
b/target/linux/ar71xx/files/arch/mips/ar71xx/mach-ubnt.c
index 5b1c504..bcdbc5a 100644
--- a/target/linux/ar71xx/files/arch/mips/ar71xx/mach-ubnt.c
+++ b/target/linux/ar71xx/files/arch/mips/ar71xx/mach-ubnt.c
@@ -122,6 +122,49 @@ static struct gpio_button ubnt_m_gpio_buttons[] __initdata 
= {
        }
 };
 
+
+static struct spi_board_info ubnt_rspro_spi_devices[] = {
+        {
+                .bus_num        = 0,
+                .chip_select    = 0,
+                .max_speed_hz   = 25000000,
+                .modalias       = "m25p80",
+        },
+       {
+               .bus_num        = 0,
+               .chip_select    = 1,
+               .max_speed_hz   = 1000000,
+               .modalias       = "rtc-pcf2123",
+               .mode           = SPI_CS_HIGH,
+       }
+};
+
+/* Linux does not allow devices sharing a cs, fake cs 0 high to be cs 1 high */
+static u32 ubnt_rspro_get_ioc_base(u8 chip_select, int cs_high, int is_on)
+{
+        u32 ret;
+
+        /* ugly workaround */
+        if (cs_high && chip_select == 1)
+                chip_select = 0;
+
+        if ((is_on == AR71XX_SPI_CS_INACTIVE && !cs_high)
+               || (is_on == AR71XX_SPI_CS_ACTIVE && cs_high))
+                ret = SPI_IOC_CS_ALL;
+        else
+                ret = SPI_IOC_CS_ALL & ~SPI_IOC_CS(chip_select);
+
+        return ret;
+}
+
+static struct ar71xx_spi_platform_data ubnt_rspro_spi_master = {
+        .bus_num       = 0,
+        .num_chipselect        = 3,
+       .mode_bits      = SPI_CS_HIGH,
+        .get_ioc_base  = ubnt_rspro_get_ioc_base,
+};
+
+
 static void __init ubnt_generic_setup(void)
 {
        ar71xx_add_device_m25p80(NULL);
@@ -171,7 +214,16 @@ MIPS_MACHINE(AR71XX_MACH_UBNT_AR71XX, "Ubiquiti 
AR71xx-based board",
 
 static void __init ubnt_rspro_setup(void)
 {
-       ubnt_generic_setup();
+
+       ar71xx_add_device_spi(&ubnt_rspro_spi_master,
+                               ubnt_rspro_spi_devices,
+                               ARRAY_SIZE(ubnt_rspro_spi_devices));
+
+       ar71xx_add_device_gpio_buttons(-1, UBNT_BUTTONS_POLL_INTERVAL,
+                                       ARRAY_SIZE(ubnt_gpio_buttons),
+                                       ubnt_gpio_buttons);
+
+       pb42_pci_init();
 
        ar71xx_add_device_mdio(~(UBNT_RSPRO_WAN_PHYMASK | 
UBNT_RSPRO_LAN_PHYMASK));
 
-- 
1.6.5

_______________________________________________
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel

Reply via email to