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 */
18 #include <linux/platform_device.h> /* PLATFORM_DEVID_AUTO is defined here */
20 #include <asm/mach-ath79/ath79.h>
21 #include <asm/mach-ath79/ar71xx_regs.h> /* needed to disable switch LEDs */
22 #include "common.h" /* needed to disable switch LEDs */
24 #include "dev-ap9x-pci.h"
26 #include "dev-gpio-buttons.h"
27 #include "dev-leds-gpio.h"
28 #include "dev-m25p80.h"
29 #include "machtypes.h"
31 /* WNR2000v3 - connected through AR7241 */
32 #define WNR2000V3_GPIO_LED_WAN_GREEN 0
33 #define WNR2000V3_GPIO_LED_LAN1_AMBER 1
34 #define WNR2000V3_GPIO_LED_LAN2_AMBER 6
35 #define WNR2000V3_GPIO_LED_WPS_GREEN 7
36 #define WNR2000V3_GPIO_LED_LAN3_AMBER 8
37 #define WNR2000V3_GPIO_BTN_WPS 11
38 #define WNR2000V3_GPIO_LED_LAN4_AMBER 12
39 #define WNR2000V3_GPIO_LED_LAN1_GREEN 13
40 #define WNR2000V3_GPIO_LED_LAN2_GREEN 14
41 #define WNR2000V3_GPIO_LED_LAN3_GREEN 15
42 #define WNR2000V3_GPIO_LED_LAN4_GREEN 16
43 #define WNR2000V3_GPIO_LED_WAN_AMBER 17
45 /* WNR2000v3 - connected through AR9287 */
46 #define WNR2000V3_GPIO_WMAC_LED_WLAN_BLUE 1
47 #define WNR2000V3_GPIO_WMAC_LED_TEST_AMBER 2
48 #define WNR2000V3_GPIO_WMAC_LED_POWER_GREEN 3
49 #define WNR2000V3_GPIO_WMAC_BTN_RESET 8
50 #define WNR2000V3_GPIO_WMAC_BTN_RFKILL 9
52 #define WNR612V2_GPIO_LED_PWR_GREEN 11
54 #define WNR1000V2_GPIO_LED_PWR_AMBER 1
55 #define WNR1000V2_GPIO_LED_PWR_GREEN 11
57 /* Connected through AR7240 */
58 #define WPN824N_GPIO_LED_WAN_AMBER 0
59 #define WPN824N_GPIO_LED_STATUS_AMBER 1
60 #define WPN824N_GPIO_LED_LAN1_AMBER 6 /* AR724X_GPIO_FUNC_JTAG_DISABLE */
61 #define WPN824N_GPIO_LED_LAN2_AMBER 7 /* AR724X_GPIO_FUNC_JTAG_DISABLE */
62 #define WPN824N_GPIO_LED_LAN3_AMBER 8 /* AR724X_GPIO_FUNC_JTAG_DISABLE */
63 #define WPN824N_GPIO_LED_LAN4_AMBER 12
64 #define WPN824N_GPIO_LED_LAN1_GREEN 13
65 #define WPN824N_GPIO_LED_LAN2_GREEN 14
66 #define WPN824N_GPIO_LED_LAN3_GREEN 15 /* AR724X_GPIO_FUNC_CLK_OBS3_EN */
67 #define WPN824N_GPIO_LED_LAN4_GREEN 16
68 #define WPN824N_GPIO_LED_WAN_GREEN 17
70 /* Connected through AR9285 */
71 #define WPN824N_WGPIO_LED_PWR_GREEN 0
72 #define WPN824N_WGPIO_LED_WLAN_BLUE 1
73 #define WPN824N_WGPIO_LED_WPS1_BLUE 5
74 #define WPN824N_WGPIO_LED_WPS2_BLUE 9
75 #define WPN824N_WGPIO_LED_TEST_AMBER 10
76 #define WPN824N_WGPIO_BTN_PUSH 6 /* currently unused */
77 #define WPN824N_WGPIO_BTN_RESET 7 /* currently unused */
78 #define WPN824N_WGPIO_BTN_WLAN 8 /* currently unused */
80 #define WNR2000V3_KEYS_POLL_INTERVAL 20 /* msecs */
81 #define WNR2000V3_KEYS_DEBOUNCE_INTERVAL (3 * WNR2000V3_KEYS_POLL_INTERVAL)
83 /* ART offsets for: WNR2000v3, WNR612v2 */
84 #define WNR2000V3_MAC0_OFFSET 0
85 #define WNR2000V3_MAC1_OFFSET 6
86 #define WNR2000V3_PCIE_CALDATA_OFFSET 0x1000
87 #define WNR2000V3_WMAC_OFFSET 0x108c /* wireless MAC is inside ART */
89 static struct gpio_led wnr2000v3_leds_gpio
[] __initdata
= {
91 .name
= "netgear:green:wan",
92 .gpio
= WNR2000V3_GPIO_LED_WAN_GREEN
,
95 .name
= "netgear:amber:lan1",
96 .gpio
= WNR2000V3_GPIO_LED_LAN1_AMBER
,
99 .name
= "netgear:amber:lan2",
100 .gpio
= WNR2000V3_GPIO_LED_LAN2_AMBER
,
103 .name
= "netgear:amber:lan3",
104 .gpio
= WNR2000V3_GPIO_LED_LAN3_AMBER
,
107 .name
= "netgear:amber:lan4",
108 .gpio
= WNR2000V3_GPIO_LED_LAN4_AMBER
,
111 .name
= "netgear:green:wps",
112 .gpio
= WNR2000V3_GPIO_LED_WPS_GREEN
,
115 .name
= "netgear:green:lan1",
116 .gpio
= WNR2000V3_GPIO_LED_LAN1_GREEN
,
119 .name
= "netgear:green:lan2",
120 .gpio
= WNR2000V3_GPIO_LED_LAN2_GREEN
,
123 .name
= "netgear:green:lan3",
124 .gpio
= WNR2000V3_GPIO_LED_LAN3_GREEN
,
127 .name
= "netgear:green:lan4",
128 .gpio
= WNR2000V3_GPIO_LED_LAN4_GREEN
,
131 .name
= "netgear:amber:wan",
132 .gpio
= WNR2000V3_GPIO_LED_WAN_AMBER
,
137 static struct gpio_led wnr2000v3_wmac_leds_gpio
[] = {
139 .name
= "netgear:green:power",
140 .gpio
= WNR2000V3_GPIO_WMAC_LED_POWER_GREEN
,
142 .default_state
= LEDS_GPIO_DEFSTATE_ON
,
144 .name
= "netgear:amber:test",
145 .gpio
= WNR2000V3_GPIO_WMAC_LED_TEST_AMBER
,
150 static const char *wnr2000v3_wmac_led_name
= "netgear:blue:wlan";
152 static struct gpio_led wnr612v2_leds_gpio
[] __initdata
= {
154 .name
= "netgear:green:power",
155 .gpio
= WNR612V2_GPIO_LED_PWR_GREEN
,
160 static struct gpio_led wnr1000v2_leds_gpio
[] __initdata
= {
162 .name
= "netgear:green:power",
163 .gpio
= WNR1000V2_GPIO_LED_PWR_GREEN
,
166 .name
= "netgear:amber:power",
167 .gpio
= WNR1000V2_GPIO_LED_PWR_AMBER
,
172 static struct gpio_led wpn824n_leds_gpio
[] __initdata
= {
174 .name
= "netgear:amber:wan",
175 .gpio
= WPN824N_GPIO_LED_WAN_AMBER
,
178 .name
= "netgear:amber:status",
179 .gpio
= WPN824N_GPIO_LED_STATUS_AMBER
,
182 .name
= "netgear:amber:lan1",
183 .gpio
= WPN824N_GPIO_LED_LAN1_AMBER
,
186 .name
= "netgear:amber:lan2",
187 .gpio
= WPN824N_GPIO_LED_LAN2_AMBER
,
190 .name
= "netgear:amber:lan3",
191 .gpio
= WPN824N_GPIO_LED_LAN3_AMBER
,
194 .name
= "netgear:amber:lan4",
195 .gpio
= WPN824N_GPIO_LED_LAN4_AMBER
,
198 .name
= "netgear:green:lan1",
199 .gpio
= WPN824N_GPIO_LED_LAN1_GREEN
,
202 .name
= "netgear:green:lan2",
203 .gpio
= WPN824N_GPIO_LED_LAN2_GREEN
,
206 .name
= "netgear:green:lan3",
207 .gpio
= WPN824N_GPIO_LED_LAN3_GREEN
,
210 .name
= "netgear:green:lan4",
211 .gpio
= WPN824N_GPIO_LED_LAN4_GREEN
,
214 .name
= "netgear:green:wan",
215 .gpio
= WPN824N_GPIO_LED_WAN_GREEN
,
220 static struct gpio_led wpn824n_wmac_leds_gpio
[] = {
222 .name
= "netgear:green:power",
223 .gpio
= WPN824N_WGPIO_LED_PWR_GREEN
,
226 .name
= "netgear:blue:wlan",
227 .gpio
= WPN824N_WGPIO_LED_WLAN_BLUE
,
230 .name
= "netgear:blue:wps1",
231 .gpio
= WPN824N_WGPIO_LED_WPS1_BLUE
,
234 .name
= "netgear:blue:wps2",
235 .gpio
= WPN824N_WGPIO_LED_WPS2_BLUE
,
238 .name
= "netgear:amber:test",
239 .gpio
= WPN824N_WGPIO_LED_TEST_AMBER
,
244 static struct gpio_keys_button wnr2000v3_keys_gpio
[] __initdata
= {
248 .code
= KEY_WPS_BUTTON
,
249 .debounce_interval
= WNR2000V3_KEYS_DEBOUNCE_INTERVAL
,
250 .gpio
= WNR2000V3_GPIO_BTN_WPS
,
255 static struct gpio_keys_button wnr2000v3_wmac_keys_gpio
[] = {
260 .debounce_interval
= WNR2000V3_KEYS_DEBOUNCE_INTERVAL
,
261 .gpio
= WNR2000V3_GPIO_WMAC_BTN_RESET
,
267 .debounce_interval
= WNR2000V3_KEYS_DEBOUNCE_INTERVAL
,
268 .gpio
= WNR2000V3_GPIO_WMAC_BTN_RFKILL
,
274 * For WNR2000v3 ART flash area used for WLAN MAC is usually empty (0xff)
275 * so ath9k driver uses random MAC instead each time module is loaded.
276 * To fix that, assign permanent WLAN MAC equal to ethN's MAC plus 1,
277 * so network interfaces get sequential addresses.
278 * If ART wireless MAC address field has been filled by user, use it.
280 static void __init
wnr_get_wmac(u8
*wmac_gen_addr
, int mac0_art_offset
,
281 int mac1_art_offset
, int wmac_art_offset
)
283 u8
*art
= (u8
*) KSEG1ADDR(0x1fff0000);
284 u8
*eth0_mac_addr
= (u8
*) (art
+ mac0_art_offset
);
285 u8
*eth1_mac_addr
= (u8
*) (art
+ mac1_art_offset
);
286 u8
*wlan_mac_addr
= (u8
*) (art
+ wmac_art_offset
);
288 /* only 0xff if all bits are set - address is invalid, empty area */
289 if ((wlan_mac_addr
[0] & wlan_mac_addr
[1] & wlan_mac_addr
[2] &
290 wlan_mac_addr
[3] & wlan_mac_addr
[4] & wlan_mac_addr
[5]) == 0xff) {
291 memcpy(wmac_gen_addr
, eth0_mac_addr
, 5);
292 wmac_gen_addr
[5] = max(eth0_mac_addr
[5], eth1_mac_addr
[5]) + 1;
294 /* Avoid potential conflict in case max(0xff,0x00)+1==0x00 */
295 if (!wmac_gen_addr
[5])
296 wmac_gen_addr
[5] = 1;
298 memcpy(wmac_gen_addr
, wlan_mac_addr
, 6);
301 static void __init
wnr_common_setup(u8
*wmac_addr
)
303 u8
*art
= (u8
*) KSEG1ADDR(0x1fff0000);
305 ath79_register_mdio(0, 0x0);
307 ath79_init_mac(ath79_eth0_data
.mac_addr
, art
+WNR2000V3_MAC0_OFFSET
, 0);
308 ath79_eth0_data
.phy_if_mode
= PHY_INTERFACE_MODE_RMII
;
309 ath79_eth0_data
.speed
= SPEED_100
;
310 ath79_eth0_data
.duplex
= DUPLEX_FULL
;
312 ath79_init_mac(ath79_eth1_data
.mac_addr
, art
+WNR2000V3_MAC1_OFFSET
, 0);
313 ath79_eth1_data
.phy_if_mode
= PHY_INTERFACE_MODE_RMII
;
314 ath79_eth1_data
.phy_mask
= 0x10;
316 ath79_register_eth(0);
317 ath79_register_eth(1);
319 ath79_register_m25p80(NULL
);
320 ap91_pci_init(art
+ WNR2000V3_PCIE_CALDATA_OFFSET
, wmac_addr
);
323 static void __init
wnr2000v3_setup(void)
328 * Disable JTAG to use all AR724X GPIO LEDs.
329 * Also disable CLKs and bit 20 as u-boot does.
330 * Finally, allow OS to control all link LEDs.
332 ath79_gpio_function_setup(AR724X_GPIO_FUNC_JTAG_DISABLE
|
333 AR724X_GPIO_FUNC_UART_EN
,
334 AR724X_GPIO_FUNC_CLK_OBS1_EN
|
335 AR724X_GPIO_FUNC_CLK_OBS2_EN
|
336 AR724X_GPIO_FUNC_CLK_OBS3_EN
|
337 AR724X_GPIO_FUNC_CLK_OBS4_EN
|
338 AR724X_GPIO_FUNC_CLK_OBS5_EN
|
339 AR724X_GPIO_FUNC_GE0_MII_CLK_EN
|
340 AR724X_GPIO_FUNC_ETH_SWITCH_LED0_EN
|
341 AR724X_GPIO_FUNC_ETH_SWITCH_LED1_EN
|
342 AR724X_GPIO_FUNC_ETH_SWITCH_LED2_EN
|
343 AR724X_GPIO_FUNC_ETH_SWITCH_LED3_EN
|
344 AR724X_GPIO_FUNC_ETH_SWITCH_LED4_EN
|
347 wnr_get_wmac(wlan_mac_addr
, WNR2000V3_MAC0_OFFSET
,
348 WNR2000V3_MAC1_OFFSET
, WNR2000V3_WMAC_OFFSET
);
350 wnr_common_setup(wlan_mac_addr
);
352 ath79_register_leds_gpio(-1, ARRAY_SIZE(wnr2000v3_leds_gpio
),
353 wnr2000v3_leds_gpio
);
355 /* Do not use id=-1, we can have more GPIO key-polled devices */
356 ath79_register_gpio_keys_polled(PLATFORM_DEVID_AUTO
,
357 WNR2000V3_KEYS_POLL_INTERVAL
,
358 ARRAY_SIZE(wnr2000v3_keys_gpio
),
359 wnr2000v3_keys_gpio
);
361 ap9x_pci_setup_wmac_led_pin(0, WNR2000V3_GPIO_WMAC_LED_WLAN_BLUE
);
362 ap9x_pci_setup_wmac_led_name(0, wnr2000v3_wmac_led_name
);
364 ap9x_pci_setup_wmac_leds(0, wnr2000v3_wmac_leds_gpio
,
365 ARRAY_SIZE(wnr2000v3_wmac_leds_gpio
));
367 ap9x_pci_setup_wmac_btns(0, wnr2000v3_wmac_keys_gpio
,
368 ARRAY_SIZE(wnr2000v3_wmac_keys_gpio
),
369 WNR2000V3_KEYS_POLL_INTERVAL
);
372 MIPS_MACHINE(ATH79_MACH_WNR2000_V3
, "WNR2000V3", "NETGEAR WNR2000 V3", wnr2000v3_setup
);
374 static void __init
wnr612v2_setup(void)
378 wnr_get_wmac(wlan_mac_addr
, WNR2000V3_MAC0_OFFSET
,
379 WNR2000V3_MAC1_OFFSET
, WNR2000V3_WMAC_OFFSET
);
381 wnr_common_setup(wlan_mac_addr
);
383 ath79_register_leds_gpio(-1, ARRAY_SIZE(wnr612v2_leds_gpio
),
387 MIPS_MACHINE(ATH79_MACH_WNR612_V2
, "WNR612V2", "NETGEAR WNR612 V2", wnr612v2_setup
);
389 static void __init
wnr1000v2_setup(void)
391 wnr_common_setup(NULL
);
393 ath79_register_leds_gpio(-1, ARRAY_SIZE(wnr1000v2_leds_gpio
),
394 wnr1000v2_leds_gpio
);
397 MIPS_MACHINE(ATH79_MACH_WNR1000_V2
, "WNR1000V2", "NETGEAR WNR1000 V2", wnr1000v2_setup
);
399 static void __init
wpn824n_setup(void)
401 ath79_gpio_function_setup(AR724X_GPIO_FUNC_JTAG_DISABLE
,
402 AR724X_GPIO_FUNC_ETH_SWITCH_LED0_EN
|
403 AR724X_GPIO_FUNC_ETH_SWITCH_LED1_EN
|
404 AR724X_GPIO_FUNC_ETH_SWITCH_LED2_EN
|
405 AR724X_GPIO_FUNC_ETH_SWITCH_LED3_EN
|
406 AR724X_GPIO_FUNC_ETH_SWITCH_LED4_EN
|
407 AR724X_GPIO_FUNC_CLK_OBS3_EN
);
409 wnr_common_setup(NULL
);
411 ath79_register_leds_gpio(-1, ARRAY_SIZE(wpn824n_leds_gpio
),
414 ap9x_pci_setup_wmac_led_pin(0, WPN824N_WGPIO_LED_WLAN_BLUE
);
415 ap9x_pci_setup_wmac_leds(0, wpn824n_wmac_leds_gpio
,
416 ARRAY_SIZE(wpn824n_wmac_leds_gpio
));
419 MIPS_MACHINE(ATH79_MACH_WPN824N
, "WPN824N", "NETGEAR WPN824N", wpn824n_setup
);