ar71xx: mach-rbspi: simplify reset button registration
[oweals/openwrt.git] / target / linux / ar71xx / files / arch / mips / ath79 / mach-ubnt-xm.c
1 /*
2  *  Ubiquiti Networks XM (rev 1.0) board support
3  *
4  *  Copyright (C) 2011 RenĂ© Bolldorf <xsecute@googlemail.com>
5  *
6  *  Derived from: mach-pb44.c
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/init.h>
14 #include <linux/pci.h>
15 #include <linux/platform_device.h>
16 #include <linux/ath9k_platform.h>
17 #include <linux/etherdevice.h>
18 #include <linux/ar8216_platform.h>
19 #include <linux/platform_data/phy-at803x.h>
20
21 #include <asm/mach-ath79/ath79.h>
22 #include <asm/mach-ath79/irq.h>
23 #include <asm/mach-ath79/ar71xx_regs.h>
24
25 #include <linux/platform_data/phy-at803x.h>
26
27 #include "common.h"
28 #include "dev-ap9x-pci.h"
29 #include "dev-eth.h"
30 #include "dev-gpio-buttons.h"
31 #include "dev-leds-gpio.h"
32 #include "dev-m25p80.h"
33 #include "dev-usb.h"
34 #include "dev-wmac.h"
35 #include "machtypes.h"
36
37 #define UBNT_XM_GPIO_LED_L1             0
38 #define UBNT_XM_GPIO_LED_L2             1
39 #define UBNT_XM_GPIO_LED_L3             11
40 #define UBNT_XM_GPIO_LED_L4             7
41
42 #define UBNT_XM_GPIO_BTN_RESET          12
43
44 #define UBNT_XM_KEYS_POLL_INTERVAL      20
45 #define UBNT_XM_KEYS_DEBOUNCE_INTERVAL  (3 * UBNT_XM_KEYS_POLL_INTERVAL)
46
47 #define UBNT_XM_EEPROM_ADDR             0x1fff1000
48
49 static struct gpio_led ubnt_xm_leds_gpio[] __initdata = {
50         {
51                 .name           = "ubnt:red:link1",
52                 .gpio           = UBNT_XM_GPIO_LED_L1,
53                 .active_low     = 0,
54         }, {
55                 .name           = "ubnt:orange:link2",
56                 .gpio           = UBNT_XM_GPIO_LED_L2,
57                 .active_low     = 0,
58         }, {
59                 .name           = "ubnt:green:link3",
60                 .gpio           = UBNT_XM_GPIO_LED_L3,
61                 .active_low     = 0,
62         }, {
63                 .name           = "ubnt:green:link4",
64                 .gpio           = UBNT_XM_GPIO_LED_L4,
65                 .active_low     = 0,
66         },
67 };
68
69 static struct gpio_keys_button ubnt_xm_gpio_keys[] __initdata = {
70         {
71                 .desc                   = "reset",
72                 .type                   = EV_KEY,
73                 .code                   = KEY_RESTART,
74                 .debounce_interval      = UBNT_XM_KEYS_DEBOUNCE_INTERVAL,
75                 .gpio                   = UBNT_XM_GPIO_BTN_RESET,
76                 .active_low             = 1,
77         }
78 };
79
80 #define UBNT_M_WAN_PHYMASK      BIT(4)
81
82 static void __init ubnt_xm_init(void)
83 {
84         u8 *eeprom = (u8 *) KSEG1ADDR(UBNT_XM_EEPROM_ADDR);
85         u8 *mac1 = (u8 *) KSEG1ADDR(0x1fff0000);
86         u8 *mac2 = (u8 *) KSEG1ADDR(0x1fff0000 + ETH_ALEN);
87
88         ath79_register_leds_gpio(-1, ARRAY_SIZE(ubnt_xm_leds_gpio),
89                                  ubnt_xm_leds_gpio);
90
91         ath79_register_gpio_keys_polled(-1, UBNT_XM_KEYS_POLL_INTERVAL,
92                                         ARRAY_SIZE(ubnt_xm_gpio_keys),
93                                         ubnt_xm_gpio_keys);
94
95         ath79_register_m25p80(NULL);
96         ap91_pci_init(eeprom, NULL);
97
98         ath79_register_mdio(0, ~UBNT_M_WAN_PHYMASK);
99         ath79_init_mac(ath79_eth0_data.mac_addr, mac1, 0);
100         ath79_init_mac(ath79_eth1_data.mac_addr, mac2, 0);
101         ath79_register_eth(0);
102 }
103
104 MIPS_MACHINE(ATH79_MACH_UBNT_XM,
105              "UBNT-XM",
106              "Ubiquiti Networks XM (rev 1.0) board",
107              ubnt_xm_init);
108
109 MIPS_MACHINE(ATH79_MACH_UBNT_BULLET_M, "UBNT-BM", "Ubiquiti Bullet M",
110              ubnt_xm_init);
111
112 static void __init ubnt_rocket_m_setup(void)
113 {
114         ubnt_xm_init();
115         ath79_register_usb();
116 }
117
118 MIPS_MACHINE(ATH79_MACH_UBNT_ROCKET_M, "UBNT-RM", "Ubiquiti Rocket M",
119              ubnt_rocket_m_setup);
120
121 static void __init ubnt_nano_m_setup(void)
122 {
123         ubnt_xm_init();
124         ath79_register_eth(1);
125 }
126
127 MIPS_MACHINE(ATH79_MACH_UBNT_NANO_M, "UBNT-NM", "Ubiquiti Nanostation M",
128              ubnt_nano_m_setup);
129
130 static struct gpio_led ubnt_airrouter_leds_gpio[] __initdata = {
131         {
132                 .name           = "ubnt:green:globe",
133                 .gpio           = 0,
134                 .active_low     = 1,
135         }, {
136                 .name           = "ubnt:green:power",
137                 .gpio           = 11,
138                 .active_low     = 1,
139                 .default_state  = LEDS_GPIO_DEFSTATE_ON,
140         }
141 };
142
143 static void __init ubnt_airrouter_setup(void)
144 {
145         u8 *mac1 = (u8 *) KSEG1ADDR(0x1fff0000);
146         u8 *ee = (u8 *) KSEG1ADDR(0x1fff1000);
147
148         ath79_register_m25p80(NULL);
149         ath79_register_mdio(0, ~UBNT_M_WAN_PHYMASK);
150
151         ath79_init_mac(ath79_eth0_data.mac_addr, mac1, 0);
152         ath79_init_local_mac(ath79_eth1_data.mac_addr, mac1);
153
154         ath79_register_eth(1);
155         ath79_register_eth(0);
156         ath79_register_usb();
157
158         ap91_pci_init(ee, NULL);
159         ath79_register_leds_gpio(-1, ARRAY_SIZE(ubnt_airrouter_leds_gpio),
160                                  ubnt_airrouter_leds_gpio);
161
162         ath79_register_gpio_keys_polled(-1, UBNT_XM_KEYS_POLL_INTERVAL,
163                                         ARRAY_SIZE(ubnt_xm_gpio_keys),
164                                         ubnt_xm_gpio_keys);
165 }
166
167 MIPS_MACHINE(ATH79_MACH_UBNT_AIRROUTER, "UBNT-AR", "Ubiquiti AirRouter",
168              ubnt_airrouter_setup);
169
170 static struct gpio_led ubnt_unifi_leds_gpio[] __initdata = {
171         {
172                 .name           = "ubnt:orange:dome",
173                 .gpio           = 1,
174                 .active_low     = 0,
175         }, {
176                 .name           = "ubnt:green:dome",
177                 .gpio           = 0,
178                 .active_low     = 0,
179         }
180 };
181
182 static struct gpio_led ubnt_unifi_outdoor_leds_gpio[] __initdata = {
183         {
184                 .name           = "ubnt:orange:front",
185                 .gpio           = 1,
186                 .active_low     = 0,
187         }, {
188                 .name           = "ubnt:green:front",
189                 .gpio           = 0,
190                 .active_low     = 0,
191         }
192 };
193
194 static struct gpio_led ubnt_unifi_outdoor_plus_leds_gpio[] __initdata = {
195         {
196                 .name           = "ubnt:white:front",
197                 .gpio           = 1,
198                 .active_low     = 0,
199         }, {
200                 .name           = "ubnt:blue:front",
201                 .gpio           = 0,
202                 .active_low     = 0,
203         }
204 };
205
206
207 static void __init ubnt_unifi_setup(void)
208 {
209         u8 *mac = (u8 *) KSEG1ADDR(0x1fff0000);
210         u8 *ee = (u8 *) KSEG1ADDR(0x1fff1000);
211
212         ath79_register_m25p80(NULL);
213
214         ath79_register_mdio(0, ~UBNT_M_WAN_PHYMASK);
215
216         ath79_init_mac(ath79_eth0_data.mac_addr, mac, 0);
217         ath79_register_eth(0);
218
219         ap91_pci_init(ee, NULL);
220
221         ath79_register_leds_gpio(-1, ARRAY_SIZE(ubnt_unifi_leds_gpio),
222                                  ubnt_unifi_leds_gpio);
223
224         ath79_register_gpio_keys_polled(-1, UBNT_XM_KEYS_POLL_INTERVAL,
225                                         ARRAY_SIZE(ubnt_xm_gpio_keys),
226                                         ubnt_xm_gpio_keys);
227 }
228
229 MIPS_MACHINE(ATH79_MACH_UBNT_UNIFI, "UBNT-UF", "Ubiquiti UniFi",
230              ubnt_unifi_setup);
231
232
233 #define UBNT_UNIFIOD_PRI_PHYMASK        BIT(4)
234 #define UBNT_UNIFIOD_2ND_PHYMASK        (BIT(0) | BIT(1) | BIT(2) | BIT(3))
235
236 static void __init ubnt_unifi_outdoor_setup(void)
237 {
238         u8 *mac1 = (u8 *) KSEG1ADDR(0x1fff0000);
239         u8 *mac2 = (u8 *) KSEG1ADDR(0x1fff0000 + ETH_ALEN);
240         u8 *ee = (u8 *) KSEG1ADDR(0x1fff1000);
241
242         ath79_register_m25p80(NULL);
243
244         ath79_register_mdio(0, ~(UBNT_UNIFIOD_PRI_PHYMASK |
245                                  UBNT_UNIFIOD_2ND_PHYMASK));
246
247         ath79_init_mac(ath79_eth0_data.mac_addr, mac1, 0);
248         ath79_init_mac(ath79_eth1_data.mac_addr, mac2, 0);
249         ath79_register_eth(0);
250         ath79_register_eth(1);
251
252         ap91_pci_init(ee, NULL);
253
254         ath79_register_leds_gpio(-1, ARRAY_SIZE(ubnt_unifi_outdoor_leds_gpio),
255                                  ubnt_unifi_outdoor_leds_gpio);
256
257         ath79_register_gpio_keys_polled(-1, UBNT_XM_KEYS_POLL_INTERVAL,
258                                         ARRAY_SIZE(ubnt_xm_gpio_keys),
259                                         ubnt_xm_gpio_keys);
260 }
261
262 MIPS_MACHINE(ATH79_MACH_UBNT_UNIFI_OUTDOOR, "UBNT-U20",
263              "Ubiquiti UniFiAP Outdoor",
264              ubnt_unifi_outdoor_setup);
265
266
267 static void __init ubnt_unifi_outdoor_plus_setup(void)
268 {
269         u8 *mac1 = (u8 *) KSEG1ADDR(0x1fff0000);
270         u8 *mac2 = (u8 *) KSEG1ADDR(0x1fff0000 + ETH_ALEN);
271         u8 *ee = (u8 *) KSEG1ADDR(0x1fff1000);
272
273         ath79_register_m25p80(NULL);
274
275         ath79_register_mdio(0, ~(UBNT_UNIFIOD_PRI_PHYMASK |
276                                  UBNT_UNIFIOD_2ND_PHYMASK));
277
278         ath79_init_mac(ath79_eth0_data.mac_addr, mac1, 0);
279         ath79_init_mac(ath79_eth1_data.mac_addr, mac2, 0);
280         ath79_register_eth(0);
281         ath79_register_eth(1);
282
283         ap9x_pci_get_wmac_data(0)->ubnt_hsr = true;
284         ap91_pci_init(ee, NULL);
285
286         ath79_register_leds_gpio(-1, ARRAY_SIZE(ubnt_unifi_outdoor_plus_leds_gpio),
287                                  ubnt_unifi_outdoor_plus_leds_gpio);
288
289         ath79_register_gpio_keys_polled(-1, UBNT_XM_KEYS_POLL_INTERVAL,
290                                         ARRAY_SIZE(ubnt_xm_gpio_keys),
291                                         ubnt_xm_gpio_keys);
292 }
293
294 MIPS_MACHINE(ATH79_MACH_UBNT_UNIFI_OUTDOOR_PLUS, "UBNT-UOP",
295              "Ubiquiti UniFiAP Outdoor+",
296              ubnt_unifi_outdoor_plus_setup);
297
298
299 static struct gpio_led ubnt_uap_pro_gpio_leds[] __initdata = {
300         {
301                 .name           = "ubnt:white:dome",
302                 .gpio           = 12,
303         }, {
304                 .name           = "ubnt:blue:dome",
305                 .gpio           = 13,
306         }
307 };
308
309 static struct gpio_keys_button uap_pro_gpio_keys[] __initdata = {
310         {
311                 .desc                   = "reset",
312                 .type                   = EV_KEY,
313                 .code                   = KEY_RESTART,
314                 .debounce_interval      = UBNT_XM_KEYS_DEBOUNCE_INTERVAL,
315                 .gpio                   = 17,
316                 .active_low             = 1,
317         }
318 };
319
320 static struct ar8327_pad_cfg uap_pro_ar8327_pad0_cfg = {
321         .mode = AR8327_PAD_MAC_RGMII,
322         .txclk_delay_en = true,
323         .rxclk_delay_en = true,
324         .txclk_delay_sel = AR8327_CLK_DELAY_SEL1,
325         .rxclk_delay_sel = AR8327_CLK_DELAY_SEL2,
326 };
327
328 static struct ar8327_platform_data uap_pro_ar8327_data = {
329         .pad0_cfg = &uap_pro_ar8327_pad0_cfg,
330         .port0_cfg = {
331                 .force_link = 1,
332                 .speed = AR8327_PORT_SPEED_1000,
333                 .duplex = 1,
334                 .txpause = 1,
335                 .rxpause = 1,
336         },
337 };
338
339 static struct mdio_board_info uap_pro_mdio0_info[] = {
340         {
341                 .bus_id = "ag71xx-mdio.0",
342                 .phy_addr = 0,
343                 .platform_data = &uap_pro_ar8327_data,
344         },
345 };
346
347 #define UAP_PRO_MAC0_OFFSET             0x0000
348 #define UAP_PRO_MAC1_OFFSET             0x0006
349 #define UAP_PRO_WMAC_CALDATA_OFFSET     0x1000
350 #define UAP_PRO_PCI_CALDATA_OFFSET      0x5000
351
352 static void __init ubnt_uap_pro_setup(void)
353 {
354         u8 *eeprom = (u8 *) KSEG1ADDR(0x1fff0000);
355
356         ath79_register_m25p80(NULL);
357
358         ath79_register_leds_gpio(-1, ARRAY_SIZE(ubnt_uap_pro_gpio_leds),
359                                  ubnt_uap_pro_gpio_leds);
360         ath79_register_gpio_keys_polled(-1, UBNT_XM_KEYS_POLL_INTERVAL,
361                                         ARRAY_SIZE(uap_pro_gpio_keys),
362                                         uap_pro_gpio_keys);
363
364         ath79_register_wmac(eeprom + UAP_PRO_WMAC_CALDATA_OFFSET, NULL);
365         ap91_pci_init(eeprom + UAP_PRO_PCI_CALDATA_OFFSET, NULL);
366
367         ath79_register_mdio(0, 0x0);
368         mdiobus_register_board_info(uap_pro_mdio0_info,
369                                     ARRAY_SIZE(uap_pro_mdio0_info));
370
371         ath79_setup_ar934x_eth_cfg(AR934X_ETH_CFG_RGMII_GMAC0);
372         ath79_init_mac(ath79_eth0_data.mac_addr,
373                        eeprom + UAP_PRO_MAC0_OFFSET, 0);
374
375         /* GMAC0 is connected to an AR8327 switch */
376         ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
377         ath79_eth0_data.phy_mask = BIT(0);
378         ath79_eth0_data.mii_bus_dev = &ath79_mdio0_device.dev;
379         ath79_eth0_pll_data.pll_1000 = 0x06000000;
380         ath79_register_eth(0);
381 }
382
383 MIPS_MACHINE(ATH79_MACH_UBNT_UAP_PRO, "UAP-PRO", "Ubiquiti UniFi AP Pro",
384              ubnt_uap_pro_setup);
385
386 #define UBNT_XW_GPIO_LED_L1             11
387 #define UBNT_XW_GPIO_LED_L2             16
388 #define UBNT_XW_GPIO_LED_L3             13
389 #define UBNT_XW_GPIO_LED_L4             14
390
391 static struct gpio_led ubnt_xw_leds_gpio[] __initdata = {
392         {
393                 .name           = "ubnt:red:link1",
394                 .gpio           = UBNT_XW_GPIO_LED_L1,
395                 .active_low     = 1,
396         }, {
397                 .name           = "ubnt:orange:link2",
398                 .gpio           = UBNT_XW_GPIO_LED_L2,
399                 .active_low     = 1,
400         }, {
401                 .name           = "ubnt:green:link3",
402                 .gpio           = UBNT_XW_GPIO_LED_L3,
403                 .active_low     = 1,
404         }, {
405                 .name           = "ubnt:green:link4",
406                 .gpio           = UBNT_XW_GPIO_LED_L4,
407                 .active_low     = 1,
408         },
409 };
410
411 #define UBNT_ROCKET_TI_GPIO_LED_L1      16
412 #define UBNT_ROCKET_TI_GPIO_LED_L2      17
413 #define UBNT_ROCKET_TI_GPIO_LED_L3      18
414 #define UBNT_ROCKET_TI_GPIO_LED_L4      19
415 #define UBNT_ROCKET_TI_GPIO_LED_L5      20
416 #define UBNT_ROCKET_TI_GPIO_LED_L6      21
417 static struct gpio_led ubnt_rocket_ti_leds_gpio[] __initdata = {
418         {
419                 .name           = "ubnt:green:link1",
420                 .gpio           = UBNT_ROCKET_TI_GPIO_LED_L1,
421                 .active_low     = 1,
422         }, {
423                 .name           = "ubnt:green:link2",
424                 .gpio           = UBNT_ROCKET_TI_GPIO_LED_L2,
425                 .active_low     = 1,
426         }, {
427                 .name           = "ubnt:green:link3",
428                 .gpio           = UBNT_ROCKET_TI_GPIO_LED_L3,
429                 .active_low     = 1,
430         }, {
431                 .name           = "ubnt:green:link4",
432                 .gpio           = UBNT_ROCKET_TI_GPIO_LED_L4,
433                 .active_low     = 0,
434         }, {
435                 .name           = "ubnt:green:link5",
436                 .gpio           = UBNT_ROCKET_TI_GPIO_LED_L5,
437                 .active_low     = 0,
438         }, {
439                 .name           = "ubnt:green:link6",
440                 .gpio           = UBNT_ROCKET_TI_GPIO_LED_L6,
441                 .active_low     = 0,
442         },
443 };
444
445 static void __init ubnt_xw_init(void)
446 {
447         u8 *eeprom = (u8 *) KSEG1ADDR(0x1fff0000);
448
449         ath79_register_m25p80(NULL);
450
451         ath79_register_leds_gpio(-1, ARRAY_SIZE(ubnt_xw_leds_gpio),
452                                  ubnt_xw_leds_gpio);
453         ath79_register_gpio_keys_polled(-1, UBNT_XM_KEYS_POLL_INTERVAL,
454                                         ARRAY_SIZE(ubnt_xm_gpio_keys),
455                                         ubnt_xm_gpio_keys);
456
457         ath79_register_wmac(eeprom + UAP_PRO_WMAC_CALDATA_OFFSET, NULL);
458         ap91_pci_init(eeprom + UAP_PRO_PCI_CALDATA_OFFSET, NULL);
459
460
461         ath79_setup_ar934x_eth_cfg(AR934X_ETH_CFG_MII_GMAC0 | AR934X_ETH_CFG_MII_GMAC0_SLAVE);
462         ath79_init_mac(ath79_eth0_data.mac_addr,
463                        eeprom + UAP_PRO_MAC0_OFFSET, 0);
464
465         ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
466         ath79_eth0_data.mii_bus_dev = &ath79_mdio0_device.dev;
467 }
468
469 static void __init ubnt_nano_m_xw_setup(void)
470 {
471         ubnt_xw_init();
472
473         /* GMAC0 is connected to an AR8326 switch */
474         ath79_register_mdio(0, ~(BIT(0) | BIT(1) | BIT(5)));
475         ath79_eth0_data.phy_mask = (BIT(0) | BIT(1) | BIT(5));
476         ath79_eth0_data.speed = SPEED_100;
477         ath79_eth0_data.duplex = DUPLEX_FULL;
478         ath79_register_eth(0);
479 }
480
481 static struct at803x_platform_data ubnt_loco_m_xw_at803x_data = {
482         .has_reset_gpio = 1,
483         .reset_gpio = 0,
484 };
485
486 static struct mdio_board_info ubnt_loco_m_xw_mdio_info[] = {
487         {
488                 .bus_id = "ag71xx-mdio.0",
489                 .phy_addr = 1,
490                 .platform_data = &ubnt_loco_m_xw_at803x_data,
491         },
492 };
493
494 static void __init ubnt_loco_m_xw_setup(void)
495 {
496         ubnt_xw_init();
497
498         mdiobus_register_board_info(ubnt_loco_m_xw_mdio_info,
499                                     ARRAY_SIZE(ubnt_loco_m_xw_mdio_info));
500
501         ath79_register_mdio(0, ~BIT(1));
502         ath79_eth0_data.phy_mask = BIT(1);
503         ath79_register_eth(0);
504 }
505
506 static void __init ubnt_rocket_m_xw_setup(void)
507 {
508         u8 *eeprom = (u8 *) KSEG1ADDR(0x1fff0000);
509
510         ath79_register_m25p80(NULL);
511
512         ath79_register_leds_gpio(-1, ARRAY_SIZE(ubnt_xw_leds_gpio),
513                                  ubnt_xw_leds_gpio);
514         ath79_register_gpio_keys_polled(-1, UBNT_XM_KEYS_POLL_INTERVAL,
515                                         ARRAY_SIZE(ubnt_xm_gpio_keys),
516                                         ubnt_xm_gpio_keys);
517
518         ath79_register_wmac(eeprom + UAP_PRO_WMAC_CALDATA_OFFSET, NULL);
519         ap91_pci_init(eeprom + UAP_PRO_PCI_CALDATA_OFFSET, NULL);
520
521         ath79_setup_ar934x_eth_cfg(AR934X_ETH_CFG_RGMII_GMAC0);
522         ath79_init_mac(ath79_eth0_data.mac_addr,
523                        eeprom + UAP_PRO_MAC0_OFFSET, 0);
524
525         ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
526         ath79_eth0_data.mii_bus_dev = &ath79_mdio0_device.dev;
527
528         ath79_register_mdio(0, ~BIT(4));
529         ath79_eth0_data.phy_mask = BIT(4);
530         ath79_eth0_pll_data.pll_1000 = 0x06000000;
531         ath79_register_eth(0);
532 }
533
534 static struct at803x_platform_data ubnt_rocket_m_ti_at803_data = {
535         .disable_smarteee = 1,
536         .enable_rgmii_rx_delay = 1,
537         .enable_rgmii_tx_delay = 1,
538 };
539 static struct mdio_board_info ubnt_rocket_m_ti_mdio_info[] = {
540         {
541                 .bus_id = "ag71xx-mdio.0",
542                 .phy_addr = 4,
543                 .platform_data = &ubnt_rocket_m_ti_at803_data,
544         },
545 };
546
547 static void __init ubnt_rocket_m_ti_setup(void)
548 {
549         u8 *eeprom = (u8 *) KSEG1ADDR(0x1fff0000);
550
551         ath79_register_m25p80(NULL);
552
553         ath79_register_leds_gpio(-1, ARRAY_SIZE(ubnt_rocket_ti_leds_gpio),
554                                  ubnt_rocket_ti_leds_gpio);
555         ath79_register_gpio_keys_polled(-1, UBNT_XM_KEYS_POLL_INTERVAL,
556                                         ARRAY_SIZE(ubnt_xm_gpio_keys),
557                                         ubnt_xm_gpio_keys);
558
559         ap91_pci_init(eeprom + 0x1000, NULL);
560
561         ath79_setup_ar934x_eth_cfg(AR934X_ETH_CFG_RGMII_GMAC0);
562         ath79_setup_ar934x_eth_rx_delay(3, 3);
563         ath79_init_mac(ath79_eth0_data.mac_addr,
564                        eeprom + UAP_PRO_MAC0_OFFSET, 0);
565         ath79_init_mac(ath79_eth1_data.mac_addr,
566                        eeprom + UAP_PRO_MAC1_OFFSET, 0);
567
568         ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
569         ath79_eth0_data.mii_bus_dev = &ath79_mdio0_device.dev;
570         ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_GMII;
571         ath79_eth1_data.mii_bus_dev = &ath79_mdio1_device.dev;
572
573         mdiobus_register_board_info(ubnt_rocket_m_ti_mdio_info,
574                         ARRAY_SIZE(ubnt_rocket_m_ti_mdio_info));
575         ath79_register_mdio(0, 0x0);
576
577
578         ath79_eth0_data.phy_mask = BIT(4);
579         /* read out from vendor */
580         ath79_eth0_pll_data.pll_1000 = 0x2000000;
581         ath79_eth0_pll_data.pll_10 = 0x1313;
582         ath79_register_eth(0);
583
584         ath79_register_mdio(1, 0x0);
585         ath79_eth1_data.phy_mask = BIT(3);
586         ath79_register_eth(1);
587 }
588
589
590 MIPS_MACHINE(ATH79_MACH_UBNT_NANO_M_XW, "UBNT-NM-XW", "Ubiquiti Nanostation M XW",
591              ubnt_nano_m_xw_setup);
592
593 MIPS_MACHINE(ATH79_MACH_UBNT_LOCO_M_XW, "UBNT-LOCO-XW", "Ubiquiti Loco M XW",
594              ubnt_loco_m_xw_setup);
595
596 MIPS_MACHINE(ATH79_MACH_UBNT_ROCKET_M_XW, "UBNT-RM-XW", "Ubiquiti Rocket M XW",
597              ubnt_rocket_m_xw_setup);
598
599 MIPS_MACHINE(ATH79_MACH_UBNT_ROCKET_M_TI, "UBNT-RM-TI", "Ubiquiti Rocket M TI",
600              ubnt_rocket_m_ti_setup);
601
602 static struct gpio_led ubnt_airgateway_gpio_leds[] __initdata = {
603         {
604                 .name      = "ubnt:blue:wlan",
605                 .gpio      = 0,
606         }, {
607                 .name      = "ubnt:white:status",
608                 .gpio      = 1,
609         },
610 };
611
612 static struct gpio_keys_button airgateway_gpio_keys[] __initdata = {
613         {
614                 .desc           = "reset",
615                 .type           = EV_KEY,
616                 .code           = KEY_RESTART,
617                 .debounce_interval      = UBNT_XM_KEYS_DEBOUNCE_INTERVAL,
618                 .gpio           = 12,
619                 .active_low     = 1,
620         }
621 };
622
623 static void __init ubnt_airgateway_setup(void)
624 {
625         u32 t;
626         u8 *mac0 = (u8 *) KSEG1ADDR(0x1fff0000);
627         u8 *mac1 = (u8 *) KSEG1ADDR(0x1fff0000 + ETH_ALEN);
628         u8 *ee = (u8 *) KSEG1ADDR(0x1fff1000);
629
630
631         ath79_gpio_function_disable(AR933X_GPIO_FUNC_ETH_SWITCH_LED0_EN |
632                                      AR933X_GPIO_FUNC_ETH_SWITCH_LED1_EN |
633                                      AR933X_GPIO_FUNC_ETH_SWITCH_LED2_EN |
634                                      AR933X_GPIO_FUNC_ETH_SWITCH_LED3_EN |
635                                      AR933X_GPIO_FUNC_ETH_SWITCH_LED4_EN);
636
637         t = ath79_reset_rr(AR933X_RESET_REG_BOOTSTRAP);
638         t |= AR933X_BOOTSTRAP_MDIO_GPIO_EN;
639         ath79_reset_wr(AR933X_RESET_REG_BOOTSTRAP, t);
640
641         ath79_register_m25p80(NULL);
642         ath79_register_leds_gpio(-1, ARRAY_SIZE(ubnt_airgateway_gpio_leds),
643                                  ubnt_airgateway_gpio_leds);
644
645         ath79_register_gpio_keys_polled(-1, UBNT_XM_KEYS_POLL_INTERVAL,
646                                         ARRAY_SIZE(airgateway_gpio_keys),
647                                         airgateway_gpio_keys);
648
649         ath79_init_mac(ath79_eth1_data.mac_addr, mac0, 0);
650         ath79_init_mac(ath79_eth0_data.mac_addr, mac1, 0);
651
652         ath79_register_mdio(0, 0x0);
653
654         ath79_register_eth(1);
655         ath79_register_eth(0);
656
657         ath79_register_wmac(ee, NULL);
658 }
659
660 MIPS_MACHINE(ATH79_MACH_UBNT_AIRGW, "UBNT-AGW", "Ubiquiti AirGateway",
661              ubnt_airgateway_setup);
662
663 static struct gpio_led ubnt_airgateway_pro_gpio_leds[] __initdata = {
664         {
665                 .name      = "ubnt:blue:wlan",
666                 .gpio      = 13,
667         }, {
668                 .name      = "ubnt:white:status",
669                 .gpio      = 17,
670         },
671 };
672
673
674 static struct gpio_keys_button airgateway_pro_gpio_keys[] __initdata = {
675         {
676                 .desc           = "reset",
677                 .type           = EV_KEY,
678                 .code           = KEY_RESTART,
679                 .debounce_interval      = UBNT_XM_KEYS_DEBOUNCE_INTERVAL,
680                 .gpio           = 12,
681                 .active_low     = 1,
682         }
683 };
684
685 static void __init ubnt_airgateway_pro_setup(void)
686 {
687         u8 *eeprom = (u8 *) KSEG1ADDR(0x1fff0000);
688         u8 *mac0 = (u8 *) KSEG1ADDR(0x1fff0000);
689
690         ath79_register_m25p80(NULL);
691         ath79_register_leds_gpio(-1, ARRAY_SIZE(ubnt_airgateway_pro_gpio_leds),
692                                  ubnt_airgateway_pro_gpio_leds);
693
694         ath79_register_gpio_keys_polled(-1, UBNT_XM_KEYS_POLL_INTERVAL,
695                                         ARRAY_SIZE(airgateway_pro_gpio_keys),
696                                         airgateway_pro_gpio_keys);
697
698         ath79_register_wmac(eeprom + UAP_PRO_WMAC_CALDATA_OFFSET, NULL);
699         ap91_pci_init(eeprom + UAP_PRO_PCI_CALDATA_OFFSET, NULL);
700
701
702         ath79_setup_ar934x_eth_cfg(AR934X_ETH_CFG_SW_ONLY_MODE);
703
704         ath79_register_mdio(1, 0x0);
705
706         /* GMAC0 is left unused in this configuration */
707
708         /* GMAC1 is connected to MAC0 on the internal switch */
709         /* The PoE/WAN port connects to port 5 on the internal switch */
710         /* The LAN port connects to port 4 on the internal switch */
711         ath79_init_mac(ath79_eth1_data.mac_addr, mac0, 0);
712         ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_GMII;
713         ath79_register_eth(1);
714
715 }
716
717 MIPS_MACHINE(ATH79_MACH_UBNT_AIRGWP, "UBNT-AGWP", "Ubiquiti AirGateway Pro",
718              ubnt_airgateway_pro_setup);