ar71xx: add v4.14 support
[openwrt/staging/chunkeey.git] / target / linux / ar71xx / files / arch / mips / ath79 / mach-wndr4300.c
1 /*
2 * NETGEAR WNDR3700v4/WNDR4300 board support
3 *
4 * Copyright (C) 2012 Gabor Juhos <juhosg@openwrt.org>
5 * Copyright (C) 2014 Ralph Perlich <rpsoft@arcor.de>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License version 2 as published
9 * by the Free Software Foundation.
10 */
11
12 #include <linux/pci.h>
13 #include <linux/phy.h>
14 #include <linux/gpio.h>
15 #include <linux/platform_device.h>
16 #include <linux/ath9k_platform.h>
17 #include <linux/ar8216_platform.h>
18 #include <linux/mtd/mtd.h>
19 #if LINUX_VERSION_CODE < KERNEL_VERSION(4,14,0)
20 #include <linux/mtd/nand.h>
21 #else
22 #include <linux/mtd/rawnand.h>
23 #endif
24 #include <linux/platform/ar934x_nfc.h>
25
26 #include <asm/mach-ath79/ar71xx_regs.h>
27
28 #include "common.h"
29 #include "dev-ap9x-pci.h"
30 #include "dev-eth.h"
31 #include "dev-gpio-buttons.h"
32 #include "dev-leds-gpio.h"
33 #include "dev-nfc.h"
34 #include "dev-usb.h"
35 #include "dev-wmac.h"
36 #include "machtypes.h"
37
38 /* AR9344 GPIOs */
39 #define WNDR4300_GPIO_LED_POWER_GREEN 0
40 #define WNDR4300_GPIO_LED_POWER_AMBER 2
41 #define WNDR4300_GPIO_LED_USB 13
42 #define WNDR4300_GPIO_LED_WAN_GREEN 1
43 #define WNDR4300_GPIO_LED_WAN_AMBER 3
44 #define WNDR4300_GPIO_LED_WLAN2G 11
45 #define WNDR4300_GPIO_LED_WLAN5G 14
46 #define WNDR4300_GPIO_LED_WPS_GREEN 16
47 #define WNDR4300_GPIO_LED_WPS_AMBER 17
48
49 #define WNDR4300_GPIO_BTN_RESET 21
50 #define WNDR4300_GPIO_BTN_WIRELESS 15
51 #define WNDR4300_GPIO_BTN_WPS 12
52
53 /* AR9580 GPIOs */
54 #define WNDR4300_GPIO_USB_5V 0
55
56 #define WNDR4300_KEYS_POLL_INTERVAL 20 /* msecs */
57 #define WNDR4300_KEYS_DEBOUNCE_INTERVAL (3 * WNDR4300_KEYS_POLL_INTERVAL)
58
59 static struct gpio_led wndr4300_leds_gpio[] __initdata = {
60 {
61 .name = "netgear:green:power",
62 .gpio = WNDR4300_GPIO_LED_POWER_GREEN,
63 .active_low = 1,
64 },
65 {
66 .name = "netgear:amber:power",
67 .gpio = WNDR4300_GPIO_LED_POWER_AMBER,
68 .active_low = 1,
69 },
70 {
71 .name = "netgear:green:wan",
72 .gpio = WNDR4300_GPIO_LED_WAN_GREEN,
73 .active_low = 1,
74 },
75 {
76 .name = "netgear:amber:wan",
77 .gpio = WNDR4300_GPIO_LED_WAN_AMBER,
78 .active_low = 1,
79 },
80 {
81 .name = "netgear:green:usb",
82 .gpio = WNDR4300_GPIO_LED_USB,
83 .active_low = 1,
84 },
85 {
86 .name = "netgear:green:wps",
87 .gpio = WNDR4300_GPIO_LED_WPS_GREEN,
88 .active_low = 1,
89 },
90 {
91 .name = "netgear:amber:wps",
92 .gpio = WNDR4300_GPIO_LED_WPS_AMBER,
93 .active_low = 1,
94 },
95 {
96 .name = "netgear:green:wlan2g",
97 .gpio = WNDR4300_GPIO_LED_WLAN2G,
98 .active_low = 1,
99 },
100 {
101 .name = "netgear:blue:wlan5g",
102 .gpio = WNDR4300_GPIO_LED_WLAN5G,
103 .active_low = 1,
104 },
105 };
106
107 static struct gpio_keys_button wndr4300_gpio_keys[] __initdata = {
108 {
109 .desc = "Reset button",
110 .type = EV_KEY,
111 .code = KEY_RESTART,
112 .debounce_interval = WNDR4300_KEYS_DEBOUNCE_INTERVAL,
113 .gpio = WNDR4300_GPIO_BTN_RESET,
114 .active_low = 1,
115 },
116 {
117 .desc = "WPS button",
118 .type = EV_KEY,
119 .code = KEY_WPS_BUTTON,
120 .debounce_interval = WNDR4300_KEYS_DEBOUNCE_INTERVAL,
121 .gpio = WNDR4300_GPIO_BTN_WPS,
122 .active_low = 1,
123 },
124 {
125 .desc = "Wireless button",
126 .type = EV_KEY,
127 .code = KEY_RFKILL,
128 .debounce_interval = WNDR4300_KEYS_DEBOUNCE_INTERVAL,
129 .gpio = WNDR4300_GPIO_BTN_WIRELESS,
130 .active_low = 1,
131 },
132 };
133
134 static struct ar8327_pad_cfg wndr4300_ar8327_pad0_cfg = {
135 .mode = AR8327_PAD_MAC_RGMII,
136 .txclk_delay_en = true,
137 .rxclk_delay_en = true,
138 .txclk_delay_sel = AR8327_CLK_DELAY_SEL1,
139 .rxclk_delay_sel = AR8327_CLK_DELAY_SEL2,
140 };
141
142 static struct ar8327_led_cfg wndr4300_ar8327_led_cfg = {
143 .led_ctrl0 = 0xcc35cc35,
144 .led_ctrl1 = 0xcb37cb37,
145 .led_ctrl2 = 0x00000000,
146 .led_ctrl3 = 0x00f3cf00,
147 .open_drain = true,
148 };
149
150 static struct ar8327_platform_data wndr4300_ar8327_data = {
151 .pad0_cfg = &wndr4300_ar8327_pad0_cfg,
152 .port0_cfg = {
153 .force_link = 1,
154 .speed = AR8327_PORT_SPEED_1000,
155 .duplex = 1,
156 .txpause = 1,
157 .rxpause = 1,
158 },
159 .led_cfg = &wndr4300_ar8327_led_cfg,
160 };
161
162 static struct mdio_board_info wndr4300_mdio0_info[] = {
163 {
164 .bus_id = "ag71xx-mdio.0",
165 .mdio_addr = 0,
166 .platform_data = &wndr4300_ar8327_data,
167 },
168 };
169
170 static void __init wndr4300_setup(void)
171 {
172 int i;
173
174 for (i = 0; i < ARRAY_SIZE(wndr4300_leds_gpio); i++)
175 ath79_gpio_output_select(wndr4300_leds_gpio[i].gpio,
176 AR934X_GPIO_OUT_GPIO);
177
178 ath79_register_leds_gpio(-1, ARRAY_SIZE(wndr4300_leds_gpio),
179 wndr4300_leds_gpio);
180 ath79_register_gpio_keys_polled(-1, WNDR4300_KEYS_POLL_INTERVAL,
181 ARRAY_SIZE(wndr4300_gpio_keys),
182 wndr4300_gpio_keys);
183
184 ath79_setup_ar934x_eth_cfg(AR934X_ETH_CFG_RGMII_GMAC0);
185
186 mdiobus_register_board_info(wndr4300_mdio0_info,
187 ARRAY_SIZE(wndr4300_mdio0_info));
188
189 ath79_register_mdio(0, 0x0);
190
191 /* GMAC0 is connected to an AR8327N switch */
192 ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
193 ath79_eth0_data.phy_mask = BIT(0);
194 ath79_eth0_data.mii_bus_dev = &ath79_mdio0_device.dev;
195 ath79_eth0_pll_data.pll_1000 = 0x06000000;
196 ath79_register_eth(0);
197
198 ath79_nfc_set_ecc_mode(AR934X_NFC_ECC_HW);
199 ath79_register_nfc();
200 ath79_register_usb();
201
202 ath79_register_wmac_simple();
203
204 /* enable power for the USB port */
205 ap9x_pci_setup_wmac_gpio(0, BIT(WNDR4300_GPIO_USB_5V),
206 BIT(WNDR4300_GPIO_USB_5V));
207
208 ap91_pci_init_simple();
209 }
210
211 MIPS_MACHINE(ATH79_MACH_WNDR3700_V4, "WNDR3700_V4", "NETGEAR WNDR3700v4",
212 wndr4300_setup);
213 MIPS_MACHINE(ATH79_MACH_WNDR4300, "WNDR4300", "NETGEAR WNDR4300",
214 wndr4300_setup);