[ar71xx] update board setup code of the RouterStation Pro (patch by Ubiquiti Networks)
[openwrt.git] / target / linux / ar71xx / files / arch / mips / ar71xx / mach-ubnt.c
1 /*
2  *  Ubiquiti RouterStation support
3  *
4  *  Copyright (C) 2008-2009 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
22 #include "devices.h"
23
24 #define UBNT_RS_GPIO_LED_RF     2
25 #define UBNT_RS_GPIO_SW4        8
26
27 #define UBNT_LS_SR71_GPIO_LED_D25       0
28 #define UBNT_LS_SR71_GPIO_LED_D26       1
29 #define UBNT_LS_SR71_GPIO_LED_D24       2
30 #define UBNT_LS_SR71_GPIO_LED_D23       4
31 #define UBNT_LS_SR71_GPIO_LED_D22       5
32 #define UBNT_LS_SR71_GPIO_LED_D27       6
33 #define UBNT_LS_SR71_GPIO_LED_D28       7
34
35 #define UBNT_BUTTONS_POLL_INTERVAL      20
36
37 static struct spi_board_info ubnt_spi_info[] = {
38         {
39                 .bus_num        = 0,
40                 .chip_select    = 0,
41                 .max_speed_hz   = 25000000,
42                 .modalias       = "m25p80",
43         }
44 };
45
46 static struct ar71xx_pci_irq ubnt_pci_irqs[] __initdata = {
47         {
48                 .slot   = 0,
49                 .pin    = 1,
50                 .irq    = AR71XX_PCI_IRQ_DEV0,
51         }, {
52                 .slot   = 1,
53                 .pin    = 1,
54                 .irq    = AR71XX_PCI_IRQ_DEV1,
55         }, {
56                 .slot   = 2,
57                 .pin    = 1,
58                 .irq    = AR71XX_PCI_IRQ_DEV2,
59         }
60 };
61
62 static struct gpio_led ubnt_rs_leds_gpio[] __initdata = {
63         {
64                 .name           = "ubnt:green:rf",
65                 .gpio           = UBNT_RS_GPIO_LED_RF,
66                 .active_low     = 0,
67         }
68 };
69
70 static struct gpio_led ubnt_ls_sr71_leds_gpio[] __initdata = {
71         {
72                 .name           = "ubnt:green:d22",
73                 .gpio           = UBNT_LS_SR71_GPIO_LED_D22,
74                 .active_low     = 0,
75         }, {
76                 .name           = "ubnt:green:d23",
77                 .gpio           = UBNT_LS_SR71_GPIO_LED_D23,
78                 .active_low     = 0,
79         }, {
80                 .name           = "ubnt:green:d24",
81                 .gpio           = UBNT_LS_SR71_GPIO_LED_D24,
82                 .active_low     = 0,
83         }, {
84                 .name           = "ubnt:red:d25",
85                 .gpio           = UBNT_LS_SR71_GPIO_LED_D25,
86                 .active_low     = 0,
87         }, {
88                 .name           = "ubnt:red:d26",
89                 .gpio           = UBNT_LS_SR71_GPIO_LED_D26,
90                 .active_low     = 0,
91         }, {
92                 .name           = "ubnt:green:d27",
93                 .gpio           = UBNT_LS_SR71_GPIO_LED_D27,
94                 .active_low     = 0,
95         }, {
96                 .name           = "ubnt:green:d28",
97                 .gpio           = UBNT_LS_SR71_GPIO_LED_D28,
98                 .active_low     = 0,
99         }
100 };
101
102 static struct gpio_button ubnt_gpio_buttons[] __initdata = {
103         {
104                 .desc           = "sw4",
105                 .type           = EV_KEY,
106                 .code           = BTN_0,
107                 .threshold      = 5,
108                 .gpio           = UBNT_RS_GPIO_SW4,
109                 .active_low     = 1,
110         }
111 };
112
113 static void __init ubnt_generic_setup(void)
114 {
115         ar71xx_add_device_spi(NULL, ubnt_spi_info,
116                                     ARRAY_SIZE(ubnt_spi_info));
117
118         ar71xx_add_device_gpio_buttons(-1, UBNT_BUTTONS_POLL_INTERVAL,
119                                         ARRAY_SIZE(ubnt_gpio_buttons),
120                                         ubnt_gpio_buttons);
121
122         ar71xx_pci_init(ARRAY_SIZE(ubnt_pci_irqs), ubnt_pci_irqs);
123 }
124
125 #define UBNT_RS_WAN_PHYMASK     (1 << 20)
126 #define UBNT_RS_LAN_PHYMASK     ((1 << 16) | (1 << 17) | (1 << 18) | (1 << 19))
127
128 #define UBNT_RSPRO_WAN_PHYMASK  (1 << 4)
129 #define UBNT_RSPRO_LAN_PHYMASK  ((1 << 0) | (1 << 1) | (1 << 2) | (1 << 3))
130
131 static void __init ubnt_rs_setup(void)
132 {
133         ubnt_generic_setup();
134
135         ar71xx_add_device_mdio(~(UBNT_RS_WAN_PHYMASK | UBNT_RS_LAN_PHYMASK));
136
137         ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
138         ar71xx_eth0_data.phy_mask = UBNT_RS_WAN_PHYMASK;
139
140         ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
141         ar71xx_eth1_data.phy_mask = UBNT_RS_LAN_PHYMASK;
142
143         ar71xx_eth1_data.speed = SPEED_100;
144         ar71xx_eth1_data.duplex = DUPLEX_FULL;
145
146         ar71xx_add_device_eth(0);
147         ar71xx_add_device_eth(1);
148
149         ar71xx_add_device_usb();
150
151         ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(ubnt_rs_leds_gpio),
152                                         ubnt_rs_leds_gpio);
153 }
154
155 MIPS_MACHINE(AR71XX_MACH_UBNT_RS, "Ubiquiti RouterStation", ubnt_rs_setup);
156
157 static void __init ubnt_rspro_setup(void)
158 {
159         ubnt_generic_setup();
160
161         ar71xx_add_device_mdio(~(UBNT_RSPRO_WAN_PHYMASK | UBNT_RSPRO_LAN_PHYMASK));
162
163         ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
164         ar71xx_eth0_data.phy_mask = UBNT_RSPRO_WAN_PHYMASK;
165
166         ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
167         ar71xx_eth1_data.phy_mask = UBNT_RSPRO_LAN_PHYMASK;
168
169         ar71xx_eth1_data.speed = SPEED_1000;
170         ar71xx_eth1_data.duplex = DUPLEX_FULL;
171
172         ar71xx_add_device_eth(0);
173         ar71xx_add_device_eth(1);
174
175         ar71xx_add_device_usb();
176
177         ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(ubnt_rs_leds_gpio),
178                                         ubnt_rs_leds_gpio);
179 }
180
181 MIPS_MACHINE(AR71XX_MACH_UBNT_RSPRO, "Ubiquiti RouterStation Pro",
182              ubnt_rspro_setup);
183
184 static void __init ubnt_lsx_setup(void)
185 {
186         ubnt_generic_setup();
187 }
188
189 MIPS_MACHINE(AR71XX_MACH_UBNT_LSX, "Ubiquiti LSX", ubnt_lsx_setup);
190
191 #define UBNT_LSSR71_PHY_MASK    (1 << 1)
192
193 static void __init ubnt_lssr71_setup(void)
194 {
195         ubnt_generic_setup();
196
197         ar71xx_add_device_mdio(~UBNT_LSSR71_PHY_MASK);
198
199         ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
200         ar71xx_eth0_data.phy_mask = UBNT_LSSR71_PHY_MASK;
201
202         ar71xx_add_device_eth(0);
203
204         ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(ubnt_ls_sr71_leds_gpio),
205                                         ubnt_ls_sr71_leds_gpio);
206 }
207
208 MIPS_MACHINE(AR71XX_MACH_UBNT_LSSR71, "Ubiquiti LS-SR71", ubnt_lssr71_setup);