[ar71xx] improve Ubiquiti RouterStation support (based on a patch by Jonas <jmajau...
[openwrt.git] / target / linux / ar71xx / files / arch / mips / ar71xx / mach-ubnt.c
1 /*
2  *  Ubiquiti RouterStation support
3  *
4  *  Copyright (C) 2008 Gabor Juhos <juhosg@openwrt.org>
5  *  Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
6  *  Copyright (C) 2008 Ubiquiti <support@ubnt.com>
7  *
8  *  This program is free software; you can redistribute it and/or modify it
9  *  under the terms of the GNU General Public License version 2 as published
10  *  by the Free Software Foundation.
11  */
12
13 #include <linux/platform_device.h>
14 #include <linux/spi/spi.h>
15 #include <linux/spi/flash.h>
16 #include <linux/input.h>
17
18 #include <asm/mips_machine.h>
19 #include <asm/mach-ar71xx/ar71xx.h>
20 #include <asm/mach-ar71xx/pci.h>
21 #include <asm/mach-ar71xx/platform.h>
22
23 #define UBNT_RS_GPIO_LED_RF     2
24 #define UBNT_RS_GPIO_SW4        8
25
26 #define UBNT_BUTTONS_POLL_INTERVAL      20
27
28 static struct spi_board_info ubnt_rs_spi_info[] = {
29         {
30                 .bus_num        = 0,
31                 .chip_select    = 0,
32                 .max_speed_hz   = 25000000,
33                 .modalias       = "m25p80",
34         }
35 };
36
37 static struct ar71xx_pci_irq ubnt_rs_pci_irqs[] __initdata = {
38         {
39                 .slot   = 0,
40                 .pin    = 1,
41                 .irq    = AR71XX_PCI_IRQ_DEV0,
42         }, {
43                 .slot   = 1,
44                 .pin    = 1,
45                 .irq    = AR71XX_PCI_IRQ_DEV1,
46         }, {
47                 .slot   = 2,
48                 .pin    = 1,
49                 .irq    = AR71XX_PCI_IRQ_DEV2,
50         }
51 };
52
53 static struct gpio_led ubnt_rs_leds_gpio[] __initdata = {
54         {
55                 .name           = "ubnt:green:rf",
56                 .gpio           = UBNT_RS_GPIO_LED_RF,
57                 .active_low     = 0,
58         }
59 };
60
61 static struct gpio_button ubnt_rs_gpio_buttons[] __initdata = {
62         {
63                 .desc           = "sw4",
64                 .type           = EV_KEY,
65                 .code           = BTN_0,
66                 .threshold      = 5,
67                 .gpio           = UBNT_RS_GPIO_SW4,
68                 .active_low     = 1,
69         }
70 };
71
72 #define UBNT_RS_WAN_PHYMASK     (1 << 20)
73 #define UBNT_RS_LAN_PHYMASK     ((1 << 16) | (1 << 17) | (1 << 18) | (1 << 19))
74
75 static void __init ubnt_rs_setup(void)
76 {
77         ar71xx_add_device_spi(NULL, ubnt_rs_spi_info,
78                                     ARRAY_SIZE(ubnt_rs_spi_info));
79
80         ar71xx_add_device_mdio(~(UBNT_RS_WAN_PHYMASK | UBNT_RS_LAN_PHYMASK));
81
82         ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
83         ar71xx_eth0_data.phy_mask = UBNT_RS_WAN_PHYMASK;
84
85         ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
86         ar71xx_eth1_data.phy_mask = UBNT_RS_LAN_PHYMASK;
87
88         ar71xx_eth1_data.speed = SPEED_100;
89         ar71xx_eth1_data.duplex = DUPLEX_FULL;
90
91         ar71xx_add_device_eth(0);
92         ar71xx_add_device_eth(1);
93
94         ar71xx_add_device_usb();
95
96         ar71xx_pci_init(ARRAY_SIZE(ubnt_rs_pci_irqs), ubnt_rs_pci_irqs);
97
98         ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(ubnt_rs_leds_gpio),
99                                         ubnt_rs_leds_gpio);
100
101         ar71xx_add_device_gpio_buttons(-1, UBNT_BUTTONS_POLL_INTERVAL,
102                                         ARRAY_SIZE(ubnt_rs_gpio_buttons),
103                                         ubnt_rs_gpio_buttons);
104 }
105
106 MIPS_MACHINE(AR71XX_MACH_UBNT_RS, "Ubiquiti RouterStation", ubnt_rs_setup);