ar71xx: fix MAC address swapping on WNR2200 and fix the WLAN MAC address
[openwrt/svn-archive/archive.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 .mac06_exchange_en = true,
101 };
102
103 static struct ar8327_platform_data esr1750_ar8327_data = {
104 .pad0_cfg = &esr1750_ar8327_pad0_cfg,
105 .port0_cfg = {
106 .force_link = 1,
107 .speed = AR8327_PORT_SPEED_1000,
108 .duplex = 1,
109 .txpause = 1,
110 .rxpause = 1,
111 },
112 };
113
114 static struct mdio_board_info esr1750_mdio0_info[] = {
115 {
116 .bus_id = "ag71xx-mdio.0",
117 .phy_addr = 0,
118 .platform_data = &esr1750_ar8327_data,
119 },
120 };
121
122 static int esr1750_get_mac(const char *name, char *mac)
123 {
124 u8 *nvram = (u8 *) KSEG1ADDR(ESR1750_NVRAM_ADDR);
125 int err;
126
127 err = ath79_nvram_parse_mac_addr(nvram, ESR1750_NVRAM_SIZE,
128 name, mac);
129 if (err) {
130 pr_err("no MAC address found for %s\n", name);
131 return false;
132 }
133
134 return true;
135 }
136
137 static void __init esr1750_setup(void)
138 {
139 u8 *caldata = (u8 *) KSEG1ADDR(ESR1750_CALDATA_ADDR);
140 u8 mac1[ETH_ALEN];
141
142 ath79_register_m25p80(NULL);
143
144 ath79_register_leds_gpio(-1, ARRAY_SIZE(esr1750_leds_gpio),
145 esr1750_leds_gpio);
146 ath79_register_gpio_keys_polled(-1, ESR1750_KEYS_POLL_INTERVAL,
147 ARRAY_SIZE(esr1750_gpio_keys),
148 esr1750_gpio_keys);
149
150 ath79_register_usb();
151
152 ath79_setup_qca955x_eth_cfg(QCA955X_ETH_CFG_RGMII_EN);
153
154 ath79_register_mdio(0, 0x0);
155
156 mdiobus_register_board_info(esr1750_mdio0_info,
157 ARRAY_SIZE(esr1750_mdio0_info));
158
159 /* GMAC0 is connected to an QCA8327N switch */
160 ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
161 ath79_eth0_data.phy_mask = BIT(0);
162 ath79_eth0_data.mii_bus_dev = &ath79_mdio0_device.dev;
163
164 if (esr1750_get_mac("ethaddr=", mac1))
165 ath79_init_mac(ath79_eth0_data.mac_addr, mac1, 0);
166
167 ath79_eth0_pll_data.pll_1000 = 0xa6000000;
168 ath79_register_eth(0);
169
170 ath79_register_wmac(caldata + ESR1750_WMAC_CALDATA_OFFSET, mac1);
171
172 ath79_register_pci();
173 }
174
175 MIPS_MACHINE(ATH79_MACH_ESR1750, "ESR1750",
176 "EnGenius ESR1750",
177 esr1750_setup);