2 * NETGEAR WNR2000v3/WNR612v2/WNR1000v2/WPN824N board support
4 * Copyright (C) 2015 Hartmut Knaack <knaack.h@gmx.de>
5 * Copyright (C) 2013 Mathieu Olivari <mathieu.olivari@gmail.com>
6 * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
7 * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
8 * Copyright (C) 2008-2009 Andy Boyett <agb@openwrt.org>
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License version 2 as published
12 * by the Free Software Foundation.
15 #include <linux/mtd/mtd.h>
16 #include <linux/mtd/partitions.h>
17 #include <linux/kernel.h> /* for max() macro */
19 #include <asm/mach-ath79/ath79.h>
20 #include <asm/mach-ath79/ar71xx_regs.h> /* needed to disable switch LEDs */
21 #include "common.h" /* needed to disable switch LEDs */
23 #include "dev-ap9x-pci.h"
25 #include "dev-gpio-buttons.h"
26 #include "dev-leds-gpio.h"
27 #include "dev-m25p80.h"
28 #include "machtypes.h"
30 #define WNR2000V3_GPIO_LED_WAN_GREEN 0
31 #define WNR2000V3_GPIO_LED_LAN1_AMBER 1
32 #define WNR2000V3_GPIO_LED_LAN4_AMBER 12
33 #define WNR2000V3_GPIO_LED_PWR_GREEN 14
34 #define WNR2000V3_GPIO_BTN_WPS 11
36 #define WNR612V2_GPIO_LED_PWR_GREEN 11
38 #define WNR1000V2_GPIO_LED_PWR_AMBER 1
39 #define WNR1000V2_GPIO_LED_PWR_GREEN 11
41 /* Connected through AR7240 */
42 #define WPN824N_GPIO_LED_WAN_AMBER 0
43 #define WPN824N_GPIO_LED_STATUS_AMBER 1
44 #define WPN824N_GPIO_LED_LAN1_AMBER 6 /* AR724X_GPIO_FUNC_JTAG_DISABLE */
45 #define WPN824N_GPIO_LED_LAN2_AMBER 7 /* AR724X_GPIO_FUNC_JTAG_DISABLE */
46 #define WPN824N_GPIO_LED_LAN3_AMBER 8 /* AR724X_GPIO_FUNC_JTAG_DISABLE */
47 #define WPN824N_GPIO_LED_LAN4_AMBER 12
48 #define WPN824N_GPIO_LED_LAN1_GREEN 13
49 #define WPN824N_GPIO_LED_LAN2_GREEN 14
50 #define WPN824N_GPIO_LED_LAN3_GREEN 15 /* AR724X_GPIO_FUNC_CLK_OBS3_EN */
51 #define WPN824N_GPIO_LED_LAN4_GREEN 16
52 #define WPN824N_GPIO_LED_WAN_GREEN 17
54 /* Connected through AR9285 */
55 #define WPN824N_WGPIO_LED_PWR_GREEN 0
56 #define WPN824N_WGPIO_LED_WLAN_BLUE 1
57 #define WPN824N_WGPIO_LED_WPS1_BLUE 5
58 #define WPN824N_WGPIO_LED_WPS2_BLUE 9
59 #define WPN824N_WGPIO_LED_TEST_AMBER 10
60 #define WPN824N_WGPIO_BTN_PUSH 6 /* currently unused */
61 #define WPN824N_WGPIO_BTN_RESET 7 /* currently unused */
62 #define WPN824N_WGPIO_BTN_WLAN 8 /* currently unused */
64 #define WNR2000V3_KEYS_POLL_INTERVAL 20 /* msecs */
65 #define WNR2000V3_KEYS_DEBOUNCE_INTERVAL (3 * WNR2000V3_KEYS_POLL_INTERVAL)
67 /* ART offsets for: WNR2000v3, WNR612v2 */
68 #define WNR2000V3_MAC0_OFFSET 0
69 #define WNR2000V3_MAC1_OFFSET 6
70 #define WNR2000V3_PCIE_CALDATA_OFFSET 0x1000
71 #define WNR2000V3_WMAC_OFFSET 0x108c /* wireless MAC is inside ART */
73 static struct gpio_led wnr2000v3_leds_gpio
[] __initdata
= {
75 .name
= "wnr2000v3:green:power",
76 .gpio
= WNR2000V3_GPIO_LED_PWR_GREEN
,
79 .name
= "wnr2000v3:green:wan",
80 .gpio
= WNR2000V3_GPIO_LED_WAN_GREEN
,
85 static struct gpio_led wnr612v2_leds_gpio
[] __initdata
= {
87 .name
= "netgear:green:power",
88 .gpio
= WNR612V2_GPIO_LED_PWR_GREEN
,
93 static struct gpio_led wnr1000v2_leds_gpio
[] __initdata
= {
95 .name
= "netgear:green:power",
96 .gpio
= WNR1000V2_GPIO_LED_PWR_GREEN
,
99 .name
= "netgear:amber:power",
100 .gpio
= WNR1000V2_GPIO_LED_PWR_AMBER
,
105 static struct gpio_led wpn824n_leds_gpio
[] __initdata
= {
107 .name
= "netgear:amber:wan",
108 .gpio
= WPN824N_GPIO_LED_WAN_AMBER
,
111 .name
= "netgear:amber:status",
112 .gpio
= WPN824N_GPIO_LED_STATUS_AMBER
,
115 .name
= "netgear:amber:lan1",
116 .gpio
= WPN824N_GPIO_LED_LAN1_AMBER
,
119 .name
= "netgear:amber:lan2",
120 .gpio
= WPN824N_GPIO_LED_LAN2_AMBER
,
123 .name
= "netgear:amber:lan3",
124 .gpio
= WPN824N_GPIO_LED_LAN3_AMBER
,
127 .name
= "netgear:amber:lan4",
128 .gpio
= WPN824N_GPIO_LED_LAN4_AMBER
,
131 .name
= "netgear:green:lan1",
132 .gpio
= WPN824N_GPIO_LED_LAN1_GREEN
,
135 .name
= "netgear:green:lan2",
136 .gpio
= WPN824N_GPIO_LED_LAN2_GREEN
,
139 .name
= "netgear:green:lan3",
140 .gpio
= WPN824N_GPIO_LED_LAN3_GREEN
,
143 .name
= "netgear:green:lan4",
144 .gpio
= WPN824N_GPIO_LED_LAN4_GREEN
,
147 .name
= "netgear:green:wan",
148 .gpio
= WPN824N_GPIO_LED_WAN_GREEN
,
153 static struct gpio_led wpn824n_wmac_leds_gpio
[] = {
155 .name
= "netgear:green:power",
156 .gpio
= WPN824N_WGPIO_LED_PWR_GREEN
,
159 .name
= "netgear:blue:wlan",
160 .gpio
= WPN824N_WGPIO_LED_WLAN_BLUE
,
163 .name
= "netgear:blue:wps1",
164 .gpio
= WPN824N_WGPIO_LED_WPS1_BLUE
,
167 .name
= "netgear:blue:wps2",
168 .gpio
= WPN824N_WGPIO_LED_WPS2_BLUE
,
171 .name
= "netgear:amber:test",
172 .gpio
= WPN824N_WGPIO_LED_TEST_AMBER
,
177 static struct gpio_keys_button wnr2000v3_gpio_keys
[] __initdata
= {
181 .code
= KEY_WPS_BUTTON
,
182 .debounce_interval
= WNR2000V3_KEYS_DEBOUNCE_INTERVAL
,
183 .gpio
= WNR2000V3_GPIO_BTN_WPS
,
188 * For WNR2000v3 ART flash area used for WLAN MAC is usually empty (0xff)
189 * so ath9k driver uses random MAC instead each time module is loaded.
190 * To fix that, assign permanent WLAN MAC equal to ethN's MAC plus 1,
191 * so network interfaces get sequential addresses.
192 * If ART wireless MAC address field has been filled by user, use it.
194 static void __init
wnr_get_wmac(u8
*wmac_gen_addr
, int mac0_art_offset
,
195 int mac1_art_offset
, int wmac_art_offset
)
197 u8
*art
= (u8
*) KSEG1ADDR(0x1fff0000);
198 u8
*eth0_mac_addr
= (u8
*) (art
+ mac0_art_offset
);
199 u8
*eth1_mac_addr
= (u8
*) (art
+ mac1_art_offset
);
200 u8
*wlan_mac_addr
= (u8
*) (art
+ wmac_art_offset
);
202 /* only 0xff if all bits are set - address is invalid, empty area */
203 if ((wlan_mac_addr
[0] & wlan_mac_addr
[1] & wlan_mac_addr
[2] &
204 wlan_mac_addr
[3] & wlan_mac_addr
[4] & wlan_mac_addr
[5]) == 0xff) {
205 memcpy(wmac_gen_addr
, eth0_mac_addr
, 5);
206 wmac_gen_addr
[5] = max(eth0_mac_addr
[5], eth1_mac_addr
[5]) + 1;
208 /* Avoid potential conflict in case max(0xff,0x00)+1==0x00 */
209 if (!wmac_gen_addr
[5])
210 wmac_gen_addr
[5] = 1;
212 memcpy(wmac_gen_addr
, wlan_mac_addr
, 6);
215 static void __init
wnr_common_setup(u8
*wmac_addr
)
217 u8
*art
= (u8
*) KSEG1ADDR(0x1fff0000);
219 ath79_register_mdio(0, 0x0);
221 ath79_init_mac(ath79_eth0_data
.mac_addr
, art
+WNR2000V3_MAC0_OFFSET
, 0);
222 ath79_eth0_data
.phy_if_mode
= PHY_INTERFACE_MODE_RMII
;
223 ath79_eth0_data
.speed
= SPEED_100
;
224 ath79_eth0_data
.duplex
= DUPLEX_FULL
;
226 ath79_init_mac(ath79_eth1_data
.mac_addr
, art
+WNR2000V3_MAC1_OFFSET
, 0);
227 ath79_eth1_data
.phy_if_mode
= PHY_INTERFACE_MODE_RMII
;
228 ath79_eth1_data
.phy_mask
= 0x10;
230 ath79_register_eth(0);
231 ath79_register_eth(1);
233 ath79_register_m25p80(NULL
);
234 ap91_pci_init(art
+ WNR2000V3_PCIE_CALDATA_OFFSET
, wmac_addr
);
237 static void __init
wnr2000v3_setup(void)
241 wnr_get_wmac(wlan_mac_addr
, WNR2000V3_MAC0_OFFSET
,
242 WNR2000V3_MAC1_OFFSET
, WNR2000V3_WMAC_OFFSET
);
244 wnr_common_setup(wlan_mac_addr
);
246 ath79_register_leds_gpio(-1, ARRAY_SIZE(wnr2000v3_leds_gpio
),
247 wnr2000v3_leds_gpio
);
249 ath79_register_gpio_keys_polled(-1, WNR2000V3_KEYS_POLL_INTERVAL
,
250 ARRAY_SIZE(wnr2000v3_gpio_keys
),
251 wnr2000v3_gpio_keys
);
254 MIPS_MACHINE(ATH79_MACH_WNR2000_V3
, "WNR2000V3", "NETGEAR WNR2000 V3", wnr2000v3_setup
);
256 static void __init
wnr612v2_setup(void)
260 wnr_get_wmac(wlan_mac_addr
, WNR2000V3_MAC0_OFFSET
,
261 WNR2000V3_MAC1_OFFSET
, WNR2000V3_WMAC_OFFSET
);
263 wnr_common_setup(wlan_mac_addr
);
265 ath79_register_leds_gpio(-1, ARRAY_SIZE(wnr612v2_leds_gpio
),
269 MIPS_MACHINE(ATH79_MACH_WNR612_V2
, "WNR612V2", "NETGEAR WNR612 V2", wnr612v2_setup
);
271 static void __init
wnr1000v2_setup(void)
273 wnr_common_setup(NULL
);
275 ath79_register_leds_gpio(-1, ARRAY_SIZE(wnr1000v2_leds_gpio
),
276 wnr1000v2_leds_gpio
);
279 MIPS_MACHINE(ATH79_MACH_WNR1000_V2
, "WNR1000V2", "NETGEAR WNR1000 V2", wnr1000v2_setup
);
281 static void __init
wpn824n_setup(void)
283 ath79_gpio_function_setup(AR724X_GPIO_FUNC_JTAG_DISABLE
,
284 AR724X_GPIO_FUNC_ETH_SWITCH_LED0_EN
|
285 AR724X_GPIO_FUNC_ETH_SWITCH_LED1_EN
|
286 AR724X_GPIO_FUNC_ETH_SWITCH_LED2_EN
|
287 AR724X_GPIO_FUNC_ETH_SWITCH_LED3_EN
|
288 AR724X_GPIO_FUNC_ETH_SWITCH_LED4_EN
|
289 AR724X_GPIO_FUNC_CLK_OBS3_EN
);
291 wnr_common_setup(NULL
);
293 ath79_register_leds_gpio(-1, ARRAY_SIZE(wpn824n_leds_gpio
),
296 ap9x_pci_setup_wmac_led_pin(0, WPN824N_WGPIO_LED_WLAN_BLUE
);
297 ap9x_pci_setup_wmac_leds(0, wpn824n_wmac_leds_gpio
,
298 ARRAY_SIZE(wpn824n_wmac_leds_gpio
));
301 MIPS_MACHINE(ATH79_MACH_WPN824N
, "WPN824N", "NETGEAR WPN824N", wpn824n_setup
);