ar71xx: use ath79_setup_qca955x_eth_cfg helper for QCA955x based boards
[openwrt/staging/wigyori.git] / target / linux / ar71xx / files / arch / mips / ath79 / mach-nbg6716.c
1 /*
2 * ZyXEL NBG6716 board support
3 *
4 * Based on the Qualcomm Atheros AP135/AP136 reference board support code
5 * Copyright (c) 2012 Qualcomm Atheros
6 * Copyright (c) 2012-2013 Gabor Juhos <juhosg@openwrt.org>
7 * Copyright (c) 2013 Andre Valentin <avalentin@marcant.net>
8 *
9 * Permission to use, copy, modify, and/or distribute this software for any
10 * purpose with or without fee is hereby granted, provided that the above
11 * copyright notice and this permission notice appear in all copies.
12 *
13 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
14 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
16 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
18 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
19 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 *
21 */
22
23 #include <linux/platform_device.h>
24 #include <linux/ar8216_platform.h>
25 #include <linux/mtd/mtd.h>
26 #include <linux/mtd/nand.h>
27 #include <linux/platform/ar934x_nfc.h>
28
29 #include <asm/mach-ath79/ar71xx_regs.h>
30
31 #include "common.h"
32 #include "pci.h"
33 #include "dev-ap9x-pci.h"
34 #include "dev-gpio-buttons.h"
35 #include "dev-eth.h"
36 #include "dev-leds-gpio.h"
37 #include "dev-nfc.h"
38 #include "dev-m25p80.h"
39 #include "dev-usb.h"
40 #include "dev-wmac.h"
41 #include "machtypes.h"
42 #include "nvram.h"
43
44 #define NBG6716_GPIO_LED_INTERNET 18
45 #define NBG6716_GPIO_LED_POWER 15
46 #define NBG6716_GPIO_LED_USB0 4
47 #define NBG6716_GPIO_LED_USB1 13
48 #define NBG6716_GPIO_LED_WIFI2G 19
49 #define NBG6716_GPIO_LED_WIFI5G 17
50 #define NBG6716_GPIO_LED_WPS 21
51
52 #define NBG6716_GPIO_BTN_RESET 23
53 #define NBG6716_GPIO_BTN_RFKILL 1
54 #define NBG6716_GPIO_BTN_USB0 14
55 #define NBG6716_GPIO_BTN_USB1 0
56 #define NBG6716_GPIO_BTN_WPS 22
57
58 #define NBG6716_KEYS_POLL_INTERVAL 20 /* msecs */
59 #define NBG6716_KEYS_DEBOUNCE_INTERVAL (3 * NBG6716_KEYS_POLL_INTERVAL)
60
61 #define NBG6716_MAC0_OFFSET 0
62 #define NBG6716_MAC1_OFFSET 6
63 #define NBG6716_WMAC_CALDATA_OFFSET 0x1000
64 #define NBG6716_PCIE_CALDATA_OFFSET 0x5000
65
66 static struct gpio_led nbg6716_leds_gpio[] __initdata = {
67 {
68 .name = "zyxel:white:internet",
69 .gpio = NBG6716_GPIO_LED_INTERNET,
70 .active_low = 1,
71 },
72 {
73 .name = "zyxel:white:power",
74 .gpio = NBG6716_GPIO_LED_POWER,
75 .active_low = 1,
76 },
77 {
78 .name = "zyxel:white:usb0",
79 .gpio = NBG6716_GPIO_LED_USB0,
80 .active_low = 1,
81 },
82 {
83 .name = "zyxel:white:usb1",
84 .gpio = NBG6716_GPIO_LED_USB1,
85 .active_low = 1,
86 },
87 {
88 .name = "zyxel:white:wifi2g",
89 .gpio = NBG6716_GPIO_LED_WIFI2G,
90 .active_low = 1,
91 },
92 {
93 .name = "zyxel:white:wifi5g",
94 .gpio = NBG6716_GPIO_LED_WIFI5G,
95 .active_low = 1,
96 },
97 {
98 .name = "zyxel:white:wps",
99 .gpio = NBG6716_GPIO_LED_WPS,
100 .active_low = 1,
101 }
102 };
103
104 static struct gpio_keys_button nbg6716_gpio_keys[] __initdata = {
105 {
106 .desc = "RESET button",
107 .type = EV_KEY,
108 .code = KEY_RESTART,
109 .debounce_interval = NBG6716_KEYS_DEBOUNCE_INTERVAL,
110 .gpio = NBG6716_GPIO_BTN_RESET,
111 .active_low = 1,
112 },
113 {
114 .desc = "RFKILL button",
115 .type = EV_KEY,
116 .code = KEY_RFKILL,
117 .debounce_interval = NBG6716_KEYS_DEBOUNCE_INTERVAL,
118 .gpio = NBG6716_GPIO_BTN_RFKILL,
119 .active_low = 1,
120 },
121 {
122 .desc = "USB0 eject button",
123 .type = EV_KEY,
124 .code = BTN_0,
125 .debounce_interval = NBG6716_KEYS_DEBOUNCE_INTERVAL,
126 .gpio = NBG6716_GPIO_BTN_USB0,
127 .active_low = 1,
128 },
129 {
130 .desc = "USB1 eject button",
131 .type = EV_KEY,
132 .code = BTN_1,
133 .debounce_interval = NBG6716_KEYS_DEBOUNCE_INTERVAL,
134 .gpio = NBG6716_GPIO_BTN_USB1,
135 .active_low = 1,
136 },
137 {
138 .desc = "WPS button",
139 .type = EV_KEY,
140 .code = KEY_WPS_BUTTON,
141 .debounce_interval = NBG6716_KEYS_DEBOUNCE_INTERVAL,
142 .gpio = NBG6716_GPIO_BTN_WPS,
143 .active_low = 1,
144 },
145 };
146
147 static struct ar8327_pad_cfg nbg6716_ar8327_pad0_cfg;
148 static struct ar8327_pad_cfg nbg6716_ar8327_pad6_cfg;
149 static struct ar8327_led_cfg nbg6716_ar8327_led_cfg;
150
151 static struct ar8327_platform_data nbg6716_ar8327_data = {
152 .pad0_cfg = &nbg6716_ar8327_pad0_cfg,
153 .pad6_cfg = &nbg6716_ar8327_pad6_cfg,
154 .port0_cfg = {
155 .force_link = 1,
156 .speed = AR8327_PORT_SPEED_1000,
157 .duplex = 1,
158 .txpause = 1,
159 .rxpause = 1,
160 },
161 .port6_cfg = {
162 .force_link = 1,
163 .speed = AR8327_PORT_SPEED_1000,
164 .duplex = 1,
165 .txpause = 1,
166 .rxpause = 1,
167 },
168 .led_cfg = &nbg6716_ar8327_led_cfg
169 };
170
171 static struct mdio_board_info nbg6716_mdio0_info[] = {
172 {
173 .bus_id = "ag71xx-mdio.0",
174 .phy_addr = 0,
175 .platform_data = &nbg6716_ar8327_data,
176 },
177 };
178
179 static void nbg6716_get_mac(const char *name, char *mac)
180 {
181 u8 *nvram = (u8 *) KSEG1ADDR(0x1f040000);
182 int err;
183
184 err = ath79_nvram_parse_mac_addr(nvram, 0x10000,
185 name, mac);
186 if (err)
187 pr_err("no MAC address found for %s\n", name);
188 }
189
190 static void __init nbg6716_common_setup(void)
191 {
192 u8 *art = (u8 *) KSEG1ADDR(0x1f050000);
193 u8 tmpmac[ETH_ALEN];
194
195 ath79_register_m25p80(NULL);
196
197 ath79_register_leds_gpio(-1, ARRAY_SIZE(nbg6716_leds_gpio),
198 nbg6716_leds_gpio);
199 ath79_register_gpio_keys_polled(-1, NBG6716_KEYS_POLL_INTERVAL,
200 ARRAY_SIZE(nbg6716_gpio_keys),
201 nbg6716_gpio_keys);
202
203 ath79_nfc_set_ecc_mode(AR934X_NFC_ECC_HW);
204 ath79_register_nfc();
205
206 ath79_register_usb();
207
208 nbg6716_get_mac("ethaddr=", tmpmac);
209
210 ath79_register_pci();
211
212 ath79_register_wmac(art + NBG6716_WMAC_CALDATA_OFFSET, tmpmac);
213
214 ath79_setup_qca955x_eth_cfg(QCA955X_ETH_CFG_RGMII_EN);
215
216 ath79_register_mdio(0, 0x0);
217
218 ath79_init_mac(ath79_eth0_data.mac_addr, tmpmac, 2);
219 ath79_init_mac(ath79_eth1_data.mac_addr, tmpmac, 3);
220
221 mdiobus_register_board_info(nbg6716_mdio0_info,
222 ARRAY_SIZE(nbg6716_mdio0_info));
223
224 /* GMAC0 is connected to the RMGII interface */
225 ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
226 ath79_eth0_data.phy_mask = BIT(0);
227 ath79_eth0_data.mii_bus_dev = &ath79_mdio0_device.dev;
228
229 ath79_register_eth(0);
230
231 /* GMAC1 is connected to the SGMII interface */
232 ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_SGMII;
233 ath79_eth1_data.speed = SPEED_1000;
234 ath79_eth1_data.duplex = DUPLEX_FULL;
235
236 ath79_register_eth(1);
237 }
238
239 static void __init nbg6716_010_setup(void)
240 {
241 /* GMAC0 of the AR8337 switch is connected to GMAC0 via RGMII */
242 nbg6716_ar8327_pad0_cfg.mode = AR8327_PAD_MAC_RGMII;
243 nbg6716_ar8327_pad0_cfg.txclk_delay_en = true;
244 nbg6716_ar8327_pad0_cfg.rxclk_delay_en = true;
245 nbg6716_ar8327_pad0_cfg.txclk_delay_sel = AR8327_CLK_DELAY_SEL1;
246 nbg6716_ar8327_pad0_cfg.rxclk_delay_sel = AR8327_CLK_DELAY_SEL2;
247
248 /* GMAC6 of the AR8337 switch is connected to GMAC1 via SGMII */
249 nbg6716_ar8327_pad6_cfg.mode = AR8327_PAD_MAC_SGMII;
250 nbg6716_ar8327_pad6_cfg.rxclk_delay_en = true;
251 nbg6716_ar8327_pad6_cfg.rxclk_delay_sel = AR8327_CLK_DELAY_SEL0;
252
253 ath79_eth0_pll_data.pll_1000 = 0xa6000000;
254 ath79_eth1_pll_data.pll_1000 = 0x03000101;
255
256 nbg6716_ar8327_led_cfg.open_drain = 0;
257 nbg6716_ar8327_led_cfg.led_ctrl0 = 0xffb7ffb7;
258 nbg6716_ar8327_led_cfg.led_ctrl1 = 0xffb7ffb7;
259 nbg6716_ar8327_led_cfg.led_ctrl2 = 0xffb7ffb7;
260 nbg6716_ar8327_led_cfg.led_ctrl3 = 0x03ffff00;
261
262 nbg6716_common_setup();
263 }
264
265 MIPS_MACHINE(ATH79_MACH_NBG6716, "NBG6716",
266 "Zyxel NBG6716",
267 nbg6716_010_setup);
268