2 * NETGEAR WNR2200 board support
4 * Copyright (C) 2013 Aidan Kissane <aidankissane at googlemail.com>
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published
8 * by the Free Software Foundation.
11 #include <linux/gpio.h>
13 #include <linux/mtd/mtd.h>
14 #include <linux/mtd/partitions.h>
15 #include <linux/kernel.h> /* for max() macro */
17 #include <asm/mach-ath79/ath79.h>
19 #include "dev-ap9x-pci.h"
21 #include "dev-gpio-buttons.h"
22 #include "dev-leds-gpio.h"
23 #include "dev-m25p80.h"
25 #include "machtypes.h"
27 #define WNR2200_GPIO_LED_LAN2_AMBER 0
28 #define WNR2200_GPIO_LED_LAN4_AMBER 1
29 #define WNR2200_GPIO_LED_WPS 5
30 #define WNR2200_GPIO_LED_WAN_GREEN 7
31 #define WNR2200_GPIO_LED_USB 8
32 #define WNR2200_GPIO_LED_LAN3_AMBER 11
33 #define WNR2200_GPIO_LED_WAN_AMBER 12
34 #define WNR2200_GPIO_LED_LAN1_GREEN 13
35 #define WNR2200_GPIO_LED_LAN2_GREEN 14
36 #define WNR2200_GPIO_LED_LAN3_GREEN 15
37 #define WNR2200_GPIO_LED_LAN4_GREEN 16
38 #define WNR2200_GPIO_LED_PWR_AMBER 21
39 #define WNR2200_GPIO_LED_PWR_GREEN 22
40 #define WNR2200_GPIO_USB_5V 4
41 #define WNR2200_GPIO_USB_POWER 24
43 #define WNR2200_KEYS_POLL_INTERVAL 20 /* msecs */
44 #define WNR2200_KEYS_DEBOUNCE_INTERVAL (3 * WNR2200_KEYS_POLL_INTERVAL)
46 #define WNR2200_MAC0_OFFSET 0
47 #define WNR2200_MAC1_OFFSET 6
48 #define WNR2200_PCIE_CALDATA_OFFSET 0x1000
49 #define WNR2200_WMAC_OFFSET 0x108c /* wireless MAC is inside ART */
51 static struct gpio_led wnr2200_leds_gpio
[] __initdata
= {
53 .name
= "netgear:amber:lan2",
54 .gpio
= WNR2200_GPIO_LED_LAN2_AMBER
,
57 .name
= "netgear:amber:lan4",
58 .gpio
= WNR2200_GPIO_LED_LAN4_AMBER
,
61 .name
= "netgear:green:wps",
62 .gpio
= WNR2200_GPIO_LED_WPS
,
65 .name
= "netgear:green:wan",
66 .gpio
= WNR2200_GPIO_LED_WAN_GREEN
,
69 .name
= "netgear:green:usb",
70 .gpio
= WNR2200_GPIO_LED_USB
,
73 .name
= "netgear:amber:lan3",
74 .gpio
= WNR2200_GPIO_LED_LAN3_AMBER
,
77 .name
= "netgear:amber:wan",
78 .gpio
= WNR2200_GPIO_LED_WAN_AMBER
,
81 .name
= "netgear:green:lan1",
82 .gpio
= WNR2200_GPIO_LED_LAN1_GREEN
,
85 .name
= "netgear:green:lan2",
86 .gpio
= WNR2200_GPIO_LED_LAN2_GREEN
,
89 .name
= "netgear:green:lan3",
90 .gpio
= WNR2200_GPIO_LED_LAN3_GREEN
,
93 .name
= "netgear:green:lan4",
94 .gpio
= WNR2200_GPIO_LED_LAN4_GREEN
,
97 .name
= "netgear:amber:power",
98 .gpio
= WNR2200_GPIO_LED_PWR_AMBER
,
101 .name
= "netgear:green:power",
102 .gpio
= WNR2200_GPIO_LED_PWR_GREEN
,
108 * For WNR2200 ART flash area used for WLAN MAC is usually empty (0xff)
109 * so ath9k driver uses random MAC instead each time module is loaded.
110 * OpenWrt's original fix was to copy eth1 address to WLAN interface.
111 * New solution does not duplicate hardware addresses and is taken from
112 * WNR2000v3 code. It assigns permanent WLAN MAC equal to ethN's MAC
113 * plus 1, so network interfaces get sequential addresses.
114 * If ART wireless MAC address field has been filled by user, use it.
116 static void __init
wnr2200_get_wmac(u8
*wmac_gen_addr
, int mac0_art_offset
,
117 int mac1_art_offset
, int wmac_art_offset
)
119 u8
*art
= (u8
*) KSEG1ADDR(0x1fff0000);
120 u8
*eth0_mac_addr
= (u8
*) (art
+ mac0_art_offset
);
121 u8
*eth1_mac_addr
= (u8
*) (art
+ mac1_art_offset
);
122 u8
*wlan_mac_addr
= (u8
*) (art
+ wmac_art_offset
);
124 /* only 0xff if all bits are set - address is invalid, empty area */
125 if ((wlan_mac_addr
[0] & wlan_mac_addr
[1] & wlan_mac_addr
[2] &
126 wlan_mac_addr
[3] & wlan_mac_addr
[4] & wlan_mac_addr
[5]) == 0xff) {
127 memcpy(wmac_gen_addr
, eth0_mac_addr
, 5);
128 wmac_gen_addr
[5] = max(eth0_mac_addr
[5], eth1_mac_addr
[5]) + 1;
130 /* Avoid potential conflict in case max(0xff,0x00)+1==0x00 */
131 if (!wmac_gen_addr
[5])
132 wmac_gen_addr
[5] = 1;
134 memcpy(wmac_gen_addr
, wlan_mac_addr
, 6);
137 static void __init
wnr2200_setup(void)
139 u8
*art
= (u8
*) KSEG1ADDR(0x1fff0000);
142 ath79_register_mdio(0, 0x0);
144 ath79_init_mac(ath79_eth0_data
.mac_addr
, art
+WNR2200_MAC0_OFFSET
, 0);
145 ath79_eth0_data
.phy_if_mode
= PHY_INTERFACE_MODE_RMII
;
146 ath79_eth0_data
.speed
= SPEED_100
;
147 ath79_eth0_data
.duplex
= DUPLEX_FULL
;
149 ath79_init_mac(ath79_eth1_data
.mac_addr
, art
+WNR2200_MAC1_OFFSET
, 0);
150 ath79_eth1_data
.phy_if_mode
= PHY_INTERFACE_MODE_RMII
;
151 ath79_eth1_data
.phy_mask
= 0x10;
153 ath79_register_eth(0);
154 ath79_register_eth(1);
156 ath79_register_m25p80(NULL
);
158 wnr2200_get_wmac(wlan_mac_addr
, WNR2200_MAC0_OFFSET
,
159 WNR2200_MAC1_OFFSET
, WNR2200_WMAC_OFFSET
);
160 ap91_pci_init(art
+ WNR2200_PCIE_CALDATA_OFFSET
, wlan_mac_addr
);
162 ath79_register_leds_gpio(-1, ARRAY_SIZE(wnr2200_leds_gpio
),
165 /* enable power for the USB port */
166 ap9x_pci_setup_wmac_gpio(0,
167 BIT(WNR2200_GPIO_USB_5V
),
168 BIT(WNR2200_GPIO_USB_5V
));
170 ath79_register_usb();
173 MIPS_MACHINE(ATH79_MACH_WNR2200
, "WNR2200", "NETGEAR WNR2200", wnr2200_setup
);