2 * NETGEAR WNDR3700v4/WNDR4300 board support
4 * Copyright (C) 2012 Gabor Juhos <juhosg@openwrt.org>
5 * Copyright (C) 2014 Ralph Perlich <rpsoft@arcor.de>
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.
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>
22 #include <linux/mtd/rawnand.h>
24 #include <linux/platform/ar934x_nfc.h>
26 #include <asm/mach-ath79/ar71xx_regs.h>
29 #include "dev-ap9x-pci.h"
31 #include "dev-gpio-buttons.h"
32 #include "dev-leds-gpio.h"
36 #include "machtypes.h"
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
49 #define WNDR4300_GPIO_BTN_RESET 21
50 #define WNDR4300_GPIO_BTN_WIRELESS 15
51 #define WNDR4300_GPIO_BTN_WPS 12
54 #define WNDR4300_GPIO_USB_5V 0
56 #define WNDR4300_KEYS_POLL_INTERVAL 20 /* msecs */
57 #define WNDR4300_KEYS_DEBOUNCE_INTERVAL (3 * WNDR4300_KEYS_POLL_INTERVAL)
59 static struct gpio_led wndr4300_leds_gpio
[] __initdata
= {
61 .name
= "netgear:green:power",
62 .gpio
= WNDR4300_GPIO_LED_POWER_GREEN
,
66 .name
= "netgear:amber:power",
67 .gpio
= WNDR4300_GPIO_LED_POWER_AMBER
,
71 .name
= "netgear:green:wan",
72 .gpio
= WNDR4300_GPIO_LED_WAN_GREEN
,
76 .name
= "netgear:amber:wan",
77 .gpio
= WNDR4300_GPIO_LED_WAN_AMBER
,
81 .name
= "netgear:green:usb",
82 .gpio
= WNDR4300_GPIO_LED_USB
,
86 .name
= "netgear:green:wps",
87 .gpio
= WNDR4300_GPIO_LED_WPS_GREEN
,
91 .name
= "netgear:amber:wps",
92 .gpio
= WNDR4300_GPIO_LED_WPS_AMBER
,
96 .name
= "netgear:green:wlan2g",
97 .gpio
= WNDR4300_GPIO_LED_WLAN2G
,
101 .name
= "netgear:blue:wlan5g",
102 .gpio
= WNDR4300_GPIO_LED_WLAN5G
,
107 static struct gpio_keys_button wndr4300_gpio_keys
[] __initdata
= {
109 .desc
= "Reset button",
112 .debounce_interval
= WNDR4300_KEYS_DEBOUNCE_INTERVAL
,
113 .gpio
= WNDR4300_GPIO_BTN_RESET
,
117 .desc
= "WPS button",
119 .code
= KEY_WPS_BUTTON
,
120 .debounce_interval
= WNDR4300_KEYS_DEBOUNCE_INTERVAL
,
121 .gpio
= WNDR4300_GPIO_BTN_WPS
,
125 .desc
= "Wireless button",
128 .debounce_interval
= WNDR4300_KEYS_DEBOUNCE_INTERVAL
,
129 .gpio
= WNDR4300_GPIO_BTN_WIRELESS
,
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
,
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,
150 static struct ar8327_platform_data wndr4300_ar8327_data
= {
151 .pad0_cfg
= &wndr4300_ar8327_pad0_cfg
,
154 .speed
= AR8327_PORT_SPEED_1000
,
159 .led_cfg
= &wndr4300_ar8327_led_cfg
,
162 static struct mdio_board_info wndr4300_mdio0_info
[] = {
164 .bus_id
= "ag71xx-mdio.0",
166 .platform_data
= &wndr4300_ar8327_data
,
170 static void __init
wndr4300_setup(void)
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
);
178 ath79_register_leds_gpio(-1, ARRAY_SIZE(wndr4300_leds_gpio
),
180 ath79_register_gpio_keys_polled(-1, WNDR4300_KEYS_POLL_INTERVAL
,
181 ARRAY_SIZE(wndr4300_gpio_keys
),
184 ath79_setup_ar934x_eth_cfg(AR934X_ETH_CFG_RGMII_GMAC0
);
186 mdiobus_register_board_info(wndr4300_mdio0_info
,
187 ARRAY_SIZE(wndr4300_mdio0_info
));
189 ath79_register_mdio(0, 0x0);
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);
198 ath79_nfc_set_ecc_mode(AR934X_NFC_ECC_HW
);
199 ath79_register_nfc();
200 ath79_register_usb();
202 ath79_register_wmac_simple();
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
));
208 ap91_pci_init_simple();
211 MIPS_MACHINE(ATH79_MACH_WNDR3700_V4
, "WNDR3700_V4", "NETGEAR WNDR3700v4",
213 MIPS_MACHINE(ATH79_MACH_WNDR4300
, "WNDR4300", "NETGEAR WNDR4300",