ar71xx: add support for gl-mifi
[openwrt/openwrt.git] / target / linux / ar71xx / files / arch / mips / ath79 / mach-dlan-pro-1200-ac.c
1 /*
2 * devolo dLAN pro 500 Wireless+ support
3 *
4 * Copyright (c) 2013-2015 devolo AG
5 * Copyright (c) 2011-2012 Gabor Juhos <juhosg@openwrt.org>
6 *
7 * Permission to use, copy, modify, and/or distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 *
19 */
20
21 #include <linux/pci.h>
22 #include <linux/phy.h>
23 #include <linux/platform_device.h>
24 #include <linux/ath9k_platform.h>
25 #include <linux/ar8216_platform.h>
26 #include <linux/gpio.h>
27
28 #include <asm/mach-ath79/ar71xx_regs.h>
29
30 #include "common.h"
31 #include "dev-ap9x-pci.h"
32 #include "dev-eth.h"
33 #include "dev-gpio-buttons.h"
34 #include "dev-leds-gpio.h"
35 #include "dev-m25p80.h"
36 #include "dev-nfc.h"
37 #include "dev-spi.h"
38 #include "dev-wmac.h"
39 #include "machtypes.h"
40
41 #define DLAN_PRO_1200_AC_GPIO_DLAN_POWER_ENABLE 13
42 #define DLAN_PRO_1200_AC_GPIO_WLAN_POWER_ENABLE 21
43 #define DLAN_PRO_1200_AC_GPIO_LED_WLAN 12
44 #define DLAN_PRO_1200_AC_GPIO_LED_DLAN 14
45 #define DLAN_PRO_1200_AC_GPIO_LED_DLAN_ERR 15
46
47 #define DLAN_PRO_1200_AC_GPIO_BTN_WLAN 20
48 #define DLAN_PRO_1200_AC_GPIO_BTN_DLAN 22
49 #define DLAN_PRO_1200_AC_GPIO_BTN_RESET 4
50 #define DLAN_PRO_1200_AC_GPIO_DLAN_IND 17
51 #define DLAN_PRO_1200_AC_GPIO_DLAN_ERR_IND 16
52
53 #define DLAN_PRO_1200_AC_KEYS_POLL_INTERVAL 20 /* msecs */
54 #define DLAN_PRO_1200_AC_KEYS_DEBOUNCE_INTERVAL (3 * DLAN_PRO_1200_AC_KEYS_POLL_INTERVAL)
55
56 #define DLAN_PRO_1200_AC_ART_ADDRESS 0x1fff0000
57 #define DLAN_PRO_1200_AC_CALDATA_OFFSET 0x1000
58 #define DLAN_PRO_1200_AC_WIFIMAC_OFFSET 0x1002
59 #define DLAN_PRO_1200_AC_PCIE_CALDATA_OFFSET 0x5000
60
61 static struct gpio_led dlan_pro_1200_ac_leds_gpio[] __initdata = {
62 {
63 .name = "devolo:status:wlan",
64 .gpio = DLAN_PRO_1200_AC_GPIO_LED_WLAN,
65 .active_low = 1,
66 },
67 {
68 .name = "devolo:status:dlan",
69 .gpio = DLAN_PRO_1200_AC_GPIO_LED_DLAN,
70 .active_low = 1,
71 },
72 {
73 .name = "devolo:error:dlan",
74 .gpio = DLAN_PRO_1200_AC_GPIO_LED_DLAN_ERR,
75 .active_low = 0,
76 }
77 };
78
79 static struct gpio_keys_button dlan_pro_1200_ac_gpio_keys[] __initdata = {
80 {
81 .desc = "dLAN button",
82 .type = EV_KEY,
83 .code = BTN_0,
84 .debounce_interval = DLAN_PRO_1200_AC_KEYS_DEBOUNCE_INTERVAL,
85 .gpio = DLAN_PRO_1200_AC_GPIO_BTN_DLAN,
86 .active_low = 1,
87 },
88 {
89 .desc = "WLAN button",
90 .type = EV_KEY,
91 .code = KEY_WPS_BUTTON,
92 .debounce_interval = DLAN_PRO_1200_AC_KEYS_DEBOUNCE_INTERVAL,
93 .gpio = DLAN_PRO_1200_AC_GPIO_BTN_WLAN,
94 .active_low = 0,
95 },
96 {
97 .desc = "Reset button",
98 .type = EV_KEY,
99 .code = KEY_RESTART,
100 .debounce_interval = DLAN_PRO_1200_AC_KEYS_DEBOUNCE_INTERVAL,
101 .gpio = DLAN_PRO_1200_AC_GPIO_BTN_RESET,
102 .active_low = 1,
103 }
104 };
105
106 static struct ar8327_pad_cfg dlan_pro_1200_ac_ar8327_pad0_cfg = {
107 .mode = AR8327_PAD_MAC_RGMII,
108 .txclk_delay_en = true,
109 .rxclk_delay_en = false,
110 .txclk_delay_sel = AR8327_CLK_DELAY_SEL1,
111 .rxclk_delay_sel = AR8327_CLK_DELAY_SEL0,
112 .mac06_exchange_dis = true,
113 };
114
115 static struct ar8327_pad_cfg dlan_pro_1200_ac_ar8327_pad5_cfg = {
116 .mode = 0,
117 .txclk_delay_en = 0,
118 .rxclk_delay_en = 0,
119 .txclk_delay_sel = 0,
120 .rxclk_delay_sel = 0,
121 };
122
123 static struct ar8327_platform_data dlan_pro_1200_ac_ar8327_data = {
124 .pad0_cfg = &dlan_pro_1200_ac_ar8327_pad0_cfg,
125 .pad5_cfg = &dlan_pro_1200_ac_ar8327_pad5_cfg,
126 .port0_cfg = {
127 .force_link = 1,
128 .speed = AR8327_PORT_SPEED_1000,
129 .duplex = 1,
130 .txpause = 1,
131 .rxpause = 1,
132 },
133 };
134
135 static struct mdio_board_info dlan_pro_1200_ac_mdio0_info[] = {
136 {
137 .bus_id = "ag71xx-mdio.0",
138 .phy_addr = 0,
139 .platform_data = &dlan_pro_1200_ac_ar8327_data,
140 },
141 };
142
143 static void __init dlan_pro_1200_ac_setup(void)
144 {
145 u8 *art = (u8 *) KSEG1ADDR(DLAN_PRO_1200_AC_ART_ADDRESS);
146 u8 *cal = art + DLAN_PRO_1200_AC_CALDATA_OFFSET;
147 u8 *wifi_mac = art + DLAN_PRO_1200_AC_WIFIMAC_OFFSET;
148
149 ath79_register_m25p80(NULL);
150
151 ath79_register_leds_gpio(-1, ARRAY_SIZE(dlan_pro_1200_ac_leds_gpio),
152 dlan_pro_1200_ac_leds_gpio);
153
154 ath79_register_gpio_keys_polled(-1, DLAN_PRO_1200_AC_KEYS_POLL_INTERVAL,
155 ARRAY_SIZE(dlan_pro_1200_ac_gpio_keys),
156 dlan_pro_1200_ac_gpio_keys);
157
158 /* dLAN power must be enabled from user-space as soon as the boot-from-host daemon is running */
159 gpio_request_one(DLAN_PRO_1200_AC_GPIO_DLAN_POWER_ENABLE,
160 GPIOF_OUT_INIT_LOW | GPIOF_EXPORT_DIR_FIXED,
161 "dLAN power");
162
163 /* WLAN power is turned on initially to allow the PCI bus scan to succeed */
164 gpio_request_one(DLAN_PRO_1200_AC_GPIO_WLAN_POWER_ENABLE,
165 GPIOF_OUT_INIT_HIGH | GPIOF_EXPORT_DIR_FIXED,
166 "WLAN power");
167
168 ath79_register_wmac(cal, wifi_mac);
169 ap91_pci_init(art + DLAN_PRO_1200_AC_PCIE_CALDATA_OFFSET, NULL);
170
171 ath79_setup_ar934x_eth_cfg(AR934X_ETH_CFG_RGMII_GMAC0 | AR934X_ETH_CFG_SW_ONLY_MODE);
172
173 ath79_register_mdio(1, 0x0);
174 ath79_register_mdio(0, 0x0);
175
176 ath79_init_mac(ath79_eth0_data.mac_addr, wifi_mac, 2);
177
178 mdiobus_register_board_info(dlan_pro_1200_ac_mdio0_info,
179 ARRAY_SIZE(dlan_pro_1200_ac_mdio0_info));
180
181 /* GMAC0 is connected to an AR8337 */
182 ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
183 ath79_eth0_data.phy_mask = BIT(0);
184 ath79_eth0_data.mii_bus_dev = &ath79_mdio0_device.dev;
185 ath79_eth0_pll_data.pll_1000 = 0x02000000;
186 ath79_register_eth(0);
187 }
188
189 MIPS_MACHINE(ATH79_MACH_DLAN_PRO_1200_AC, "dLAN-pro-1200-ac", "devolo dLAN pro 1200+ WiFi ac",
190 dlan_pro_1200_ac_setup);