ar71xx: add v4.14 support
[openwrt/openwrt.git] / target / linux / ar71xx / files / arch / mips / ath79 / mach-dlan-pro-500-wp.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-spi.h"
37 #include "dev-wmac.h"
38 #include "machtypes.h"
39
40 #define DLAN_PRO_500_WP_GPIO_DLAN_POWER_ENABLE 13
41 #define DLAN_PRO_500_WP_GPIO_DLAN_LED_ENABLE 17
42 #define DLAN_PRO_500_WP_GPIO_LED_WLAN_5G 11
43 #define DLAN_PRO_500_WP_GPIO_LED_WLAN_2G 12
44 #define DLAN_PRO_500_WP_GPIO_LED_STATUS 16
45 #define DLAN_PRO_500_WP_GPIO_LED_ETH 14
46
47 #define DLAN_PRO_500_WP_GPIO_BTN_WPS 20
48 #define DLAN_PRO_500_WP_GPIO_BTN_WLAN 22
49 #define DLAN_PRO_500_WP_GPIO_BTN_DLAN 21
50 #define DLAN_PRO_500_WP_GPIO_BTN_RESET 4
51
52 #define DLAN_PRO_500_WP_KEYS_POLL_INTERVAL 20 /* msecs */
53 #define DLAN_PRO_500_WP_KEYS_DEBOUNCE_INTERVAL (3 * DLAN_PRO_500_WP_KEYS_POLL_INTERVAL)
54
55 #define DLAN_PRO_500_WP_ART_ADDRESS 0x1fff0000
56 #define DLAN_PRO_500_WP_CALDATA_OFFSET 0x1000
57 #define DLAN_PRO_500_WP_MAC_ADDRESS_OFFSET 0x1002
58 #define DLAN_PRO_500_WP_PCIE_CALDATA_OFFSET 0x5000
59
60 static struct gpio_led dlan_pro_500_wp_leds_gpio[] __initdata = {
61 {
62 .name = "devolo:green:status",
63 .gpio = DLAN_PRO_500_WP_GPIO_LED_STATUS,
64 .active_low = 1,
65 },
66 {
67 .name = "devolo:green:eth",
68 .gpio = DLAN_PRO_500_WP_GPIO_LED_ETH,
69 .active_low = 1,
70 },
71 {
72 .name = "devolo:blue:wlan-5g",
73 .gpio = DLAN_PRO_500_WP_GPIO_LED_WLAN_5G,
74 .active_low = 1,
75 },
76 {
77 .name = "devolo:green:wlan-2g",
78 .gpio = DLAN_PRO_500_WP_GPIO_LED_WLAN_2G,
79 .active_low = 1,
80 }
81 };
82
83 static struct gpio_keys_button dlan_pro_500_wp_gpio_keys[] __initdata = {
84 {
85 .desc = "dLAN button",
86 .type = EV_KEY,
87 .code = BTN_0,
88 .debounce_interval = DLAN_PRO_500_WP_KEYS_DEBOUNCE_INTERVAL,
89 .gpio = DLAN_PRO_500_WP_GPIO_BTN_DLAN,
90 .active_low = 0,
91 },
92 {
93 .desc = "WPS button",
94 .type = EV_KEY,
95 .code = KEY_WPS_BUTTON,
96 .debounce_interval = DLAN_PRO_500_WP_KEYS_DEBOUNCE_INTERVAL,
97 .gpio = DLAN_PRO_500_WP_GPIO_BTN_WPS,
98 .active_low = 0,
99 },
100 {
101 .desc = "WLAN button",
102 .type = EV_KEY,
103 .code = BTN_2,
104 .debounce_interval = DLAN_PRO_500_WP_KEYS_DEBOUNCE_INTERVAL,
105 .gpio = DLAN_PRO_500_WP_GPIO_BTN_WLAN,
106 .active_low = 1,
107 },
108 {
109 .desc = "Reset button",
110 .type = EV_KEY,
111 .code = KEY_RESTART,
112 .debounce_interval = DLAN_PRO_500_WP_KEYS_DEBOUNCE_INTERVAL,
113 .gpio = DLAN_PRO_500_WP_GPIO_BTN_RESET,
114 .active_low = 1,
115 }
116 };
117
118 static struct ar8327_pad_cfg dlan_pro_500_wp_ar8327_pad0_cfg = {
119 .mode = AR8327_PAD_PHY_RGMII,
120 .txclk_delay_en = false,
121 .rxclk_delay_en = false,
122 .txclk_delay_sel = AR8327_CLK_DELAY_SEL0,
123 .rxclk_delay_sel = AR8327_CLK_DELAY_SEL0,
124 };
125
126 static struct ar8327_led_cfg dlan_pro_500_wp_ar8327_led_cfg = {
127 .led_ctrl0 = 0x00000000,
128 .led_ctrl1 = 0xc737c737,
129 .led_ctrl2 = 0x00000000,
130 .led_ctrl3 = 0x00c30c00,
131 .open_drain = true,
132 };
133
134 static struct ar8327_platform_data dlan_pro_500_wp_ar8327_data = {
135 .pad0_cfg = &dlan_pro_500_wp_ar8327_pad0_cfg,
136 .port0_cfg = {
137 .force_link = 1,
138 .speed = AR8327_PORT_SPEED_1000,
139 .duplex = 1,
140 .txpause = 0,
141 .rxpause = 0,
142 },
143 .led_cfg = &dlan_pro_500_wp_ar8327_led_cfg,
144 };
145
146 static struct mdio_board_info dlan_pro_500_wp_mdio0_info[] = {
147 {
148 .bus_id = "ag71xx-mdio.0",
149 .mdio_addr = 0,
150 .platform_data = &dlan_pro_500_wp_ar8327_data,
151 },
152 };
153
154 static void __init dlan_pro_500_wp_setup(void)
155 {
156 u8 *art = (u8 *) KSEG1ADDR(DLAN_PRO_500_WP_ART_ADDRESS);
157 u8 *cal = art + DLAN_PRO_500_WP_CALDATA_OFFSET;
158 u8 *wifi_mac = art + DLAN_PRO_500_WP_MAC_ADDRESS_OFFSET;
159
160 ath79_register_m25p80(NULL);
161
162 ath79_register_leds_gpio(-1, ARRAY_SIZE(dlan_pro_500_wp_leds_gpio),
163 dlan_pro_500_wp_leds_gpio);
164
165 ath79_register_gpio_keys_polled(-1, DLAN_PRO_500_WP_KEYS_POLL_INTERVAL,
166 ARRAY_SIZE(dlan_pro_500_wp_gpio_keys),
167 dlan_pro_500_wp_gpio_keys);
168
169 gpio_request_one(DLAN_PRO_500_WP_GPIO_DLAN_POWER_ENABLE,
170 GPIOF_OUT_INIT_LOW | GPIOF_EXPORT_DIR_FIXED,
171 "PLC power");
172 gpio_request_one(DLAN_PRO_500_WP_GPIO_DLAN_LED_ENABLE,
173 GPIOF_OUT_INIT_LOW | GPIOF_EXPORT_DIR_FIXED,
174 "PLC LEDs");
175
176 ath79_register_wmac(cal, wifi_mac);
177
178 ath79_setup_ar934x_eth_cfg(AR934X_ETH_CFG_RGMII_GMAC0);
179
180 ath79_register_mdio(1, 0x0);
181 ath79_register_mdio(0, 0x0);
182
183 mdiobus_register_board_info(dlan_pro_500_wp_mdio0_info,
184 ARRAY_SIZE(dlan_pro_500_wp_mdio0_info));
185
186 /* GMAC0 is connected to a AR7400 PLC in PHY mode */
187 ath79_init_mac(ath79_eth0_data.mac_addr, wifi_mac, 2);
188 ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
189 ath79_eth0_pll_data.pll_1000 = 0x0e000000;
190 ath79_eth0_data.speed = SPEED_1000;
191 ath79_eth0_data.duplex = DUPLEX_FULL;
192 ath79_register_eth(0);
193
194 /* GMAC1 is connected to the internal switch */
195 ath79_init_mac(ath79_eth1_data.mac_addr, wifi_mac, 1);
196 ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_GMII;
197 ath79_eth1_data.speed = SPEED_1000;
198 ath79_eth1_data.duplex = DUPLEX_FULL;
199 ath79_register_eth(1);
200 }
201
202 MIPS_MACHINE(ATH79_MACH_DLAN_PRO_500_WP, "dLAN-pro-500-wp", "devolo dLAN pro 500 Wireless+",
203 dlan_pro_500_wp_setup);