3617ca7d5fc0fff00fce9741b5d9169fac8c83c8
[openwrt.git] / target / linux / ar71xx / files / arch / mips / ath79 / mach-ubnt-unifiac.c
1 /*
2  *  Ubiquiti UniFi AC (LITE) board support
3  *
4  *  Copyright (C) 2015-2016 P. Wassi <p.wassi at gmx.at>
5  *
6  *  Derived from: mach-ubnt-xm.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
19 #include <asm/mach-ath79/ath79.h>
20 #include <asm/mach-ath79/irq.h>
21 #include <asm/mach-ath79/ar71xx_regs.h>
22
23 #include <linux/platform_data/phy-at803x.h>
24
25 #include "common.h"
26 #include "dev-ap9x-pci.h"
27 #include "dev-eth.h"
28 #include "dev-gpio-buttons.h"
29 #include "dev-leds-gpio.h"
30 #include "dev-m25p80.h"
31 #include "dev-wmac.h"
32 #include "machtypes.h"
33
34
35 #define UNIFIAC_KEYS_POLL_INTERVAL      20
36 #define UNIFIAC_KEYS_DEBOUNCE_INTERVAL  (3 * UNIFIAC_KEYS_POLL_INTERVAL)
37
38 #define UNIFIAC_GPIO_LED_WHITE          7
39 #define UNIFIAC_GPIO_LED_BLUE           8
40
41 #define UNIFIAC_GPIO_BTN_RESET          2
42
43 #define UNIFIAC_MAC0_OFFSET             0x0000
44 #define UNIFIAC_WMAC_CALDATA_OFFSET     0x1000
45 #define UNIFIAC_PCI_CALDATA_OFFSET      0x5000
46
47
48 static struct flash_platform_data ubnt_unifiac_flash_data = {
49         /* mx25l12805d and mx25l12835f have the same JEDEC ID */
50         .type = "mx25l12805d",
51 };
52
53 static struct gpio_led ubnt_unifiac_leds_gpio[] __initdata = {
54         {
55                 .name           = "ubnt:white:dome",
56                 .gpio           = UNIFIAC_GPIO_LED_WHITE,
57                 .active_low     = 0,
58         }, {
59                 .name           = "ubnt:blue:dome",
60                 .gpio           = UNIFIAC_GPIO_LED_BLUE,
61                 .active_low     = 0,
62         }
63 };
64
65 static struct gpio_keys_button ubnt_unifiac_gpio_keys[] __initdata = {
66         {
67                 .desc                   = "reset",
68                 .type                   = EV_KEY,
69                 .code                   = KEY_RESTART,
70                 .debounce_interval      = UNIFIAC_KEYS_DEBOUNCE_INTERVAL,
71                 .gpio                   = UNIFIAC_GPIO_BTN_RESET,
72                 .active_low             = 1,
73         }
74 };
75
76 static void __init ubnt_unifiac_setup(void)
77 {
78         u8 *eeprom = (u8 *) KSEG1ADDR(0x1fff0000);
79
80         ath79_register_m25p80(&ubnt_unifiac_flash_data);
81
82
83         ath79_init_mac(ath79_eth0_data.mac_addr,
84                        eeprom + UNIFIAC_MAC0_OFFSET, 0);
85
86         ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_SGMII;
87         ath79_eth0_data.phy_mask = BIT(4);
88         ath79_eth0_pll_data.pll_10 = 0x00001313;
89
90         ath79_register_mdio(0, ~BIT(4));
91         ath79_register_eth(0);
92
93
94         ath79_register_wmac(eeprom + UNIFIAC_WMAC_CALDATA_OFFSET, NULL);
95
96
97         ap91_pci_init(eeprom + UNIFIAC_PCI_CALDATA_OFFSET, NULL);
98
99
100         ath79_register_leds_gpio(-1, ARRAY_SIZE(ubnt_unifiac_leds_gpio),
101                                  ubnt_unifiac_leds_gpio);
102
103         ath79_register_gpio_keys_polled(-1, UNIFIAC_KEYS_POLL_INTERVAL,
104                                         ARRAY_SIZE(ubnt_unifiac_gpio_keys),
105                                         ubnt_unifiac_gpio_keys);
106 }
107
108 MIPS_MACHINE(ATH79_MACH_UBNT_UNIFIAC, "UBNT-UF-AC", "Ubiquiti UniFi-AC",
109              ubnt_unifiac_setup);