ar71xx: add v4.14 support
[openwrt/openwrt.git] / target / linux / ar71xx / files / arch / mips / ath79 / mach-esr1750.c
1 /*
2 * EnGenius ESR1750 board support
3 *
4 * Copyright (c) 2014 Jon Suphammer <jon@suphammer.net>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published
8 * by the Free Software Foundation.
9 */
10
11 #include <linux/platform_device.h>
12 #include <linux/ar8216_platform.h>
13
14 #include <asm/mach-ath79/ar71xx_regs.h>
15
16 #include "common.h"
17 #include "pci.h"
18 #include "dev-ap9x-pci.h"
19 #include "dev-gpio-buttons.h"
20 #include "dev-eth.h"
21 #include "dev-leds-gpio.h"
22 #include "dev-m25p80.h"
23 #include "dev-usb.h"
24 #include "dev-wmac.h"
25 #include "machtypes.h"
26 #include "nvram.h"
27
28 #define ESR1750_GPIO_LED_WLAN_5G 23
29 #define ESR1750_GPIO_LED_WLAN_2G 13
30 #define ESR1750_GPIO_LED_POWER_AMBER 2
31 #define ESR1750_GPIO_LED_WPS_AMBER 22
32 #define ESR1750_GPIO_LED_WPS_BLUE 19
33
34 #define ESR1750_GPIO_BTN_WPS 16
35 #define ESR1750_GPIO_BTN_RESET 17
36
37 #define ESR1750_KEYS_POLL_INTERVAL 20 /* msecs */
38 #define ESR1750_KEYS_DEBOUNCE_INTERVAL (3 * ESR1750_KEYS_POLL_INTERVAL)
39
40 #define ESR1750_CALDATA_ADDR 0x1fff0000
41 #define ESR1750_WMAC_CALDATA_OFFSET 0x1000
42 #define ESR1750_PCIE_CALDATA_OFFSET 0x5000
43
44 #define ESR1750_NVRAM_ADDR 0x1f030000
45 #define ESR1750_NVRAM_SIZE 0x10000
46
47 static struct gpio_led esr1750_leds_gpio[] __initdata = {
48 {
49 .name = "esr1750:amber:power",
50 .gpio = ESR1750_GPIO_LED_POWER_AMBER,
51 .active_low = 1,
52 },
53 {
54 .name = "esr1750:blue:wps",
55 .gpio = ESR1750_GPIO_LED_WPS_BLUE,
56 .active_low = 1,
57 },
58 {
59 .name = "esr1750:amber:wps",
60 .gpio = ESR1750_GPIO_LED_WPS_AMBER,
61 .active_low = 1,
62 },
63 {
64 .name = "esr1750:blue:wlan-2g",
65 .gpio = ESR1750_GPIO_LED_WLAN_2G,
66 .active_low = 1,
67 },
68 {
69 .name = "esr1750:blue:wlan-5g",
70 .gpio = ESR1750_GPIO_LED_WLAN_5G,
71 .active_low = 1,
72 }
73 };
74
75 static struct gpio_keys_button esr1750_gpio_keys[] __initdata = {
76 {
77 .desc = "WPS button",
78 .type = EV_KEY,
79 .code = KEY_WPS_BUTTON,
80 .debounce_interval = ESR1750_KEYS_DEBOUNCE_INTERVAL,
81 .gpio = ESR1750_GPIO_BTN_WPS,
82 .active_low = 1,
83 },
84 {
85 .desc = "Reset button",
86 .type = EV_KEY,
87 .code = KEY_RESTART,
88 .debounce_interval = ESR1750_KEYS_DEBOUNCE_INTERVAL,
89 .gpio = ESR1750_GPIO_BTN_RESET,
90 .active_low = 1,
91 },
92 };
93
94 static struct ar8327_pad_cfg esr1750_ar8327_pad0_cfg = {
95 .mode = AR8327_PAD_MAC_RGMII,
96 .txclk_delay_en = true,
97 .rxclk_delay_en = true,
98 .txclk_delay_sel = AR8327_CLK_DELAY_SEL2,
99 .rxclk_delay_sel = AR8327_CLK_DELAY_SEL2,
100 };
101
102 static struct ar8327_platform_data esr1750_ar8327_data = {
103 .pad0_cfg = &esr1750_ar8327_pad0_cfg,
104 .port0_cfg = {
105 .force_link = 1,
106 .speed = AR8327_PORT_SPEED_1000,
107 .duplex = 1,
108 .txpause = 1,
109 .rxpause = 1,
110 },
111 };
112
113 static struct mdio_board_info esr1750_mdio0_info[] = {
114 {
115 .bus_id = "ag71xx-mdio.0",
116 .mdio_addr = 0,
117 .platform_data = &esr1750_ar8327_data,
118 },
119 };
120
121 static int esr1750_get_mac(const char *name, char *mac)
122 {
123 u8 *nvram = (u8 *) KSEG1ADDR(ESR1750_NVRAM_ADDR);
124 int err;
125
126 err = ath79_nvram_parse_mac_addr(nvram, ESR1750_NVRAM_SIZE,
127 name, mac);
128 if (err) {
129 pr_err("no MAC address found for %s\n", name);
130 return false;
131 }
132
133 return true;
134 }
135
136 static void __init esr1750_setup(void)
137 {
138 u8 *caldata = (u8 *) KSEG1ADDR(ESR1750_CALDATA_ADDR);
139 u8 mac1[ETH_ALEN];
140
141 ath79_register_m25p80(NULL);
142
143 ath79_register_leds_gpio(-1, ARRAY_SIZE(esr1750_leds_gpio),
144 esr1750_leds_gpio);
145 ath79_register_gpio_keys_polled(-1, ESR1750_KEYS_POLL_INTERVAL,
146 ARRAY_SIZE(esr1750_gpio_keys),
147 esr1750_gpio_keys);
148
149 ath79_register_usb();
150
151 ath79_setup_qca955x_eth_cfg(QCA955X_ETH_CFG_RGMII_EN);
152
153 ath79_register_mdio(0, 0x0);
154
155 mdiobus_register_board_info(esr1750_mdio0_info,
156 ARRAY_SIZE(esr1750_mdio0_info));
157
158 /* GMAC0 is connected to an QCA8327N switch */
159 ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
160 ath79_eth0_data.phy_mask = BIT(0);
161 ath79_eth0_data.mii_bus_dev = &ath79_mdio0_device.dev;
162
163 if (esr1750_get_mac("ethaddr=", mac1))
164 ath79_init_mac(ath79_eth0_data.mac_addr, mac1, 0);
165
166 ath79_eth0_pll_data.pll_1000 = 0xa6000000;
167 ath79_register_eth(0);
168
169 ath79_register_wmac(caldata + ESR1750_WMAC_CALDATA_OFFSET, mac1);
170
171 ath79_register_pci();
172 }
173
174 MIPS_MACHINE(ATH79_MACH_ESR1750, "ESR1750",
175 "EnGenius ESR1750",
176 esr1750_setup);