1/*
2 *  Ubiquiti RouterStation support
3 *
4 *  Copyright (C) 2008-2012 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 <asm/mach-ath79/ath79.h>
14
15#include "dev-eth.h"
16#include "dev-gpio-buttons.h"
17#include "dev-leds-gpio.h"
18#include "dev-m25p80.h"
19#include "dev-usb.h"
20#include "machtypes.h"
21#include "pci.h"
22
23#define UBNT_RS_GPIO_LED_RF	2
24#define UBNT_RS_GPIO_SW4	8
25
26#define UBNT_LS_SR71_GPIO_LED_D25	0
27#define UBNT_LS_SR71_GPIO_LED_D26	1
28#define UBNT_LS_SR71_GPIO_LED_D24	2
29#define UBNT_LS_SR71_GPIO_LED_D23	4
30#define UBNT_LS_SR71_GPIO_LED_D22	5
31#define UBNT_LS_SR71_GPIO_LED_D27	6
32#define UBNT_LS_SR71_GPIO_LED_D28	7
33
34#define UBNT_KEYS_POLL_INTERVAL		20	/* msecs */
35#define UBNT_KEYS_DEBOUNCE_INTERVAL	(3 * UBNT_KEYS_POLL_INTERVAL)
36
37static struct gpio_led ubnt_rs_leds_gpio[] __initdata = {
38	{
39		.name		= "ubnt:green:rf",
40		.gpio		= UBNT_RS_GPIO_LED_RF,
41		.active_low	= 0,
42	}
43};
44
45static struct gpio_led ubnt_ls_sr71_leds_gpio[] __initdata = {
46	{
47		.name		= "ubnt:green:d22",
48		.gpio		= UBNT_LS_SR71_GPIO_LED_D22,
49		.active_low	= 0,
50	}, {
51		.name		= "ubnt:green:d23",
52		.gpio		= UBNT_LS_SR71_GPIO_LED_D23,
53		.active_low	= 0,
54	}, {
55		.name		= "ubnt:green:d24",
56		.gpio		= UBNT_LS_SR71_GPIO_LED_D24,
57		.active_low	= 0,
58	}, {
59		.name		= "ubnt:red:d25",
60		.gpio		= UBNT_LS_SR71_GPIO_LED_D25,
61		.active_low	= 0,
62	}, {
63		.name		= "ubnt:red:d26",
64		.gpio		= UBNT_LS_SR71_GPIO_LED_D26,
65		.active_low	= 0,
66	}, {
67		.name		= "ubnt:green:d27",
68		.gpio		= UBNT_LS_SR71_GPIO_LED_D27,
69		.active_low	= 0,
70	}, {
71		.name		= "ubnt:green:d28",
72		.gpio		= UBNT_LS_SR71_GPIO_LED_D28,
73		.active_low	= 0,
74	}
75};
76
77static struct gpio_keys_button ubnt_gpio_keys[] __initdata = {
78	{
79		.desc		= "sw4",
80		.type		= EV_KEY,
81		.code		= KEY_RESTART,
82		.debounce_interval = UBNT_KEYS_DEBOUNCE_INTERVAL,
83		.gpio		= UBNT_RS_GPIO_SW4,
84		.active_low	= 1,
85	}
86};
87
88static const char *ubnt_part_probes[] = {
89	"RedBoot",
90	NULL,
91};
92
93static struct flash_platform_data ubnt_flash_data = {
94	.part_probes	= ubnt_part_probes,
95};
96
97static void __init ubnt_generic_setup(void)
98{
99	ath79_register_m25p80(&ubnt_flash_data);
100
101	ath79_register_gpio_keys_polled(-1, UBNT_KEYS_POLL_INTERVAL,
102					ARRAY_SIZE(ubnt_gpio_keys),
103					ubnt_gpio_keys);
104	ath79_register_pci();
105}
106
107#define UBNT_RS_WAN_PHYMASK	BIT(20)
108#define UBNT_RS_LAN_PHYMASK	(BIT(16) | BIT(17) | BIT(18) | BIT(19))
109
110static void __init ubnt_rs_setup(void)
111{
112	ubnt_generic_setup();
113
114	ath79_register_mdio(0, ~(UBNT_RS_WAN_PHYMASK | UBNT_RS_LAN_PHYMASK));
115
116	ath79_init_mac(ath79_eth0_data.mac_addr, ath79_mac_base, 0);
117	ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
118	ath79_eth0_data.phy_mask = UBNT_RS_WAN_PHYMASK;
119
120	/*
121	 * There is Secondary MAC address duplicate problem with some
122	 * UBNT HW batches.  Do not increase Secondary MAC address by 1
123	 * but do workaround with 'Locally Administrated' bit.
124	 */
125	ath79_init_local_mac(ath79_eth1_data.mac_addr, ath79_mac_base);
126	ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
127	ath79_eth1_data.speed = SPEED_100;
128	ath79_eth1_data.duplex = DUPLEX_FULL;
129
130	ath79_register_eth(0);
131	ath79_register_eth(1);
132
133	ath79_register_usb();
134
135	ath79_register_leds_gpio(-1, ARRAY_SIZE(ubnt_rs_leds_gpio),
136				 ubnt_rs_leds_gpio);
137}
138
139MIPS_MACHINE(ATH79_MACH_UBNT_RS, "UBNT-RS", "Ubiquiti RouterStation",
140	     ubnt_rs_setup);
141
142#define UBNT_RSPRO_WAN_PHYMASK	BIT(4)
143#define UBNT_RSPRO_LAN_PHYMASK	(BIT(0) | BIT(1) | BIT(2) | BIT(3))
144
145static void __init ubnt_rspro_setup(void)
146{
147	ubnt_generic_setup();
148
149	ath79_register_mdio(0, ~(UBNT_RSPRO_WAN_PHYMASK |
150				 UBNT_RSPRO_LAN_PHYMASK));
151
152	ath79_init_mac(ath79_eth0_data.mac_addr, ath79_mac_base, 0);
153	ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
154	ath79_eth0_data.phy_mask = UBNT_RSPRO_WAN_PHYMASK;
155
156	/*
157	 * There is Secondary MAC address duplicate problem with some
158	 * UBNT HW batches.  Do not increase Secondary MAC address by 1
159	 * but do workaround with 'Locally Administrated' bit.
160	 */
161	ath79_init_local_mac(ath79_eth1_data.mac_addr, ath79_mac_base);
162	ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
163	ath79_eth1_data.phy_mask = UBNT_RSPRO_LAN_PHYMASK;
164	ath79_eth1_data.speed = SPEED_1000;
165	ath79_eth1_data.duplex = DUPLEX_FULL;
166
167	ath79_register_eth(0);
168	ath79_register_eth(1);
169
170	ath79_register_usb();
171
172	ath79_register_leds_gpio(-1, ARRAY_SIZE(ubnt_rs_leds_gpio),
173				 ubnt_rs_leds_gpio);
174}
175
176MIPS_MACHINE(ATH79_MACH_UBNT_RSPRO, "UBNT-RSPRO", "Ubiquiti RouterStation Pro",
177	     ubnt_rspro_setup);
178
179static void __init ubnt_lsx_setup(void)
180{
181	ubnt_generic_setup();
182}
183
184MIPS_MACHINE(ATH79_MACH_UBNT_LSX, "UBNT-LSX", "Ubiquiti LSX", ubnt_lsx_setup);
185
186#define UBNT_LSSR71_PHY_MASK	BIT(1)
187
188static void __init ubnt_lssr71_setup(void)
189{
190	ubnt_generic_setup();
191
192	ath79_register_mdio(0, ~UBNT_LSSR71_PHY_MASK);
193
194	ath79_init_mac(ath79_eth0_data.mac_addr, ath79_mac_base, 0);
195	ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
196	ath79_eth0_data.phy_mask = UBNT_LSSR71_PHY_MASK;
197
198	ath79_register_eth(0);
199
200	ath79_register_leds_gpio(-1, ARRAY_SIZE(ubnt_ls_sr71_leds_gpio),
201				 ubnt_ls_sr71_leds_gpio);
202}
203
204MIPS_MACHINE(ATH79_MACH_UBNT_LSSR71, "UBNT-LS-SR71", "Ubiquiti LS-SR71",
205	     ubnt_lssr71_setup);
206