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