ar71xx: WNR2000v3: fix for random WLAN MAC
[openwrt/svn-archive/archive.git] / target / linux / ar71xx / files / arch / mips / ath79 / mach-wnr2000-v4.c
1 /*
2 * NETGEAR WNR2000v4 board support
3 *
4 * Copyright (C) 2015 Michael Bazzinotti <mbazzinotti@gmail.com>
5 * Copyright (C) 2014 Michaƫl Burtin <mburtin@gmail.com>
6 * Copyright (C) 2013 Mathieu Olivari <mathieu.olivari@gmail.com>
7 * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
8 * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
9 * Copyright (C) 2008-2009 Andy Boyett <agb@openwrt.org>
10 *
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License version 2 as published
13 * by the Free Software Foundation.
14 */
15
16 #include <linux/mtd/mtd.h>
17 #include <linux/mtd/partitions.h>
18 #include <linux/platform_device.h>
19
20 #include <asm/mach-ath79/ath79.h>
21 #include <asm/mach-ath79/ar71xx_regs.h>
22
23 #include "common.h"
24 #include "dev-eth.h"
25 #include "dev-gpio-buttons.h"
26 #include "dev-leds-gpio.h"
27 #include "dev-m25p80.h"
28 #include "dev-usb.h"
29 #include "dev-wmac.h"
30 #include "machtypes.h"
31
32 /* AR9341 GPIOs */
33 #define WNR2000V4_GPIO_LED_PWR_GREEN 0
34 #define WNR2000V4_GPIO_LED_PWR_AMBER 1
35 #define WNR2000V4_GPIO_LED_WPS 2
36 #define WNR2000V4_GPIO_LED_WLAN 12
37 #define WNR2000V4_GPIO_LED_LAN1_GREEN 13
38 #define WNR2000V4_GPIO_LED_LAN2_GREEN 14
39 #define WNR2000V4_GPIO_LED_LAN3_GREEN 15
40 #define WNR2000V4_GPIO_LED_LAN4_GREEN 16
41 #define WNR2000V4_GPIO_LED_LAN1_AMBER 18
42 #define WNR2000V4_GPIO_LED_LAN2_AMBER 19
43 #define WNR2000V4_GPIO_LED_LAN3_AMBER 20
44 #define WNR2000V4_GPIO_LED_LAN4_AMBER 21
45 #define WNR2000V4_GPIO_LED_WAN_GREEN 17
46 #define WNR2000V4_GPIO_LED_WAN_AMBER 22
47 /* Buttons */
48 #define WNR2000V4_GPIO_BTN_WPS 3
49 #define WNR2000V4_GPIO_BTN_RESET 4
50 #define WNR2000V4_GPIO_BTN_WLAN 11
51 #define WNR2000V4_KEYS_POLL_INTERVAL 20 /* msecs */
52 #define WNR2000V4_KEYS_DEBOUNCE_INTERVAL (3 * WNR2000V4_KEYS_POLL_INTERVAL)
53
54
55 /* ART offsets */
56 #define WNR2000V4_MAC0_OFFSET 0 /* WAN/WLAN0 MAC */
57 #define WNR2000V4_MAC1_OFFSET 6 /* Eth-switch0 MAC */
58
59 static struct gpio_led wnr2000v4_leds_gpio[] __initdata = {
60 {
61 .name = "netgear:green:power",
62 .gpio = WNR2000V4_GPIO_LED_PWR_GREEN,
63 .active_low = 1,
64 .default_trigger = "default-on",
65 },
66 {
67 .name = "netgear:amber:status",
68 .gpio = WNR2000V4_GPIO_LED_PWR_AMBER,
69 .active_low = 1,
70 },
71 {
72 .name = "netgear:green:wan",
73 .gpio = WNR2000V4_GPIO_LED_WAN_GREEN,
74 .active_low = 1,
75 },
76 {
77 .name = "netgear:amber:wan",
78 .gpio = WNR2000V4_GPIO_LED_WAN_AMBER,
79 .active_low = 1,
80 },
81 {
82 .name = "netgear:blue:wlan",
83 .gpio = WNR2000V4_GPIO_LED_WLAN,
84 .active_low = 1,
85 },
86 /* LAN LEDS */
87 {
88 .name = "netgear:green:lan1",
89 .gpio = WNR2000V4_GPIO_LED_LAN1_GREEN,
90 .active_low = 1,
91 },
92 {
93 .name = "netgear:green:lan2",
94 .gpio = WNR2000V4_GPIO_LED_LAN2_GREEN,
95 .active_low = 1,
96 },
97 {
98 .name = "netgear:green:lan3",
99 .gpio = WNR2000V4_GPIO_LED_LAN3_GREEN,
100 .active_low = 1,
101 },
102 {
103 .name = "netgear:green:lan4",
104 .gpio = WNR2000V4_GPIO_LED_LAN4_GREEN,
105 .active_low = 1,
106 },
107 {
108 .name = "netgear:amber:lan1",
109 .gpio = WNR2000V4_GPIO_LED_LAN1_AMBER,
110 .active_low = 1,
111 },
112 {
113 .name = "netgear:amber:lan2",
114 .gpio = WNR2000V4_GPIO_LED_LAN2_AMBER,
115 .active_low = 1,
116 },
117 {
118 .name = "netgear:amber:lan3",
119 .gpio = WNR2000V4_GPIO_LED_LAN3_AMBER,
120 .active_low = 1,
121 },
122 {
123 .name = "netgear:amber:lan4",
124 .gpio = WNR2000V4_GPIO_LED_LAN4_AMBER,
125 .active_low = 1,
126 },
127 {
128 .name = "netgear:green:wps",
129 .gpio = WNR2000V4_GPIO_LED_WPS,
130 .active_low = 1,
131 },
132 };
133
134 static struct gpio_keys_button wnr2000v4_gpio_keys[] __initdata = {
135 {
136 .desc = "WPS button",
137 .type = EV_KEY,
138 .code = KEY_WPS_BUTTON,
139 .debounce_interval = WNR2000V4_KEYS_DEBOUNCE_INTERVAL,
140 .gpio = WNR2000V4_GPIO_BTN_WPS,
141 .active_low = 1,
142 },
143 {
144 .desc = "Reset button",
145 .type = EV_KEY,
146 .code = KEY_RESTART,
147 .debounce_interval = WNR2000V4_KEYS_DEBOUNCE_INTERVAL,
148 .gpio = WNR2000V4_GPIO_BTN_RESET,
149 .active_low = 1,
150 },
151 {
152 .desc = "WLAN button",
153 .type = EV_KEY,
154 .code = KEY_RFKILL,
155 .debounce_interval = WNR2000V4_KEYS_DEBOUNCE_INTERVAL,
156 .gpio = WNR2000V4_GPIO_BTN_WLAN,
157 .active_low = 1,
158 },
159 };
160
161 static void __init wnr_common_setup(void)
162 {
163 u8 *art = (u8 *) KSEG1ADDR(0x1fff0000);
164 u8 *ee = (u8 *) KSEG1ADDR(0x1fff1000);
165
166 ath79_register_mdio(1, 0x0);
167
168 ath79_register_usb();
169
170 ath79_register_m25p80(NULL);
171
172 ath79_setup_ar934x_eth_cfg(AR934X_ETH_CFG_SW_ONLY_MODE);
173
174 ath79_init_mac(ath79_eth0_data.mac_addr, art+WNR2000V4_MAC0_OFFSET, 0);
175 ath79_init_mac(ath79_eth1_data.mac_addr, art+WNR2000V4_MAC1_OFFSET, 0);
176
177 /* GMAC0 is connected to the PHY0 of the internal switch, GE0 */
178 ath79_switch_data.phy4_mii_en = 1;
179 ath79_switch_data.phy_poll_mask = BIT(4);
180 ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
181 ath79_eth0_data.phy_mask = BIT(4);
182 ath79_eth0_data.mii_bus_dev = &ath79_mdio1_device.dev;
183 ath79_register_eth(0);
184
185 /* GMAC1 is connected to the internal switch, GE1 */
186 ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_GMII;
187 ath79_register_eth(1);
188
189 ath79_register_wmac(ee, art);
190 }
191
192 static void __init wnr2000v4_setup(void)
193 {
194 int i;
195
196 wnr_common_setup();
197
198 /* Ensure no LED has an internal MUX signal, otherwise
199 control of LED could be lost... This is especially important
200 for most green LEDS (Eth,WAN).. who arrive in this function with
201 MUX signals set. */
202 for (i = 0; i < ARRAY_SIZE(wnr2000v4_leds_gpio); i++)
203 ath79_gpio_output_select(wnr2000v4_leds_gpio[i].gpio,
204 AR934X_GPIO_OUT_GPIO);
205
206 ath79_register_leds_gpio(-1, ARRAY_SIZE(wnr2000v4_leds_gpio),
207 wnr2000v4_leds_gpio);
208
209 ath79_register_gpio_keys_polled(-1, WNR2000V4_KEYS_POLL_INTERVAL,
210 ARRAY_SIZE(wnr2000v4_gpio_keys),
211 wnr2000v4_gpio_keys);
212 }
213
214 MIPS_MACHINE(ATH79_MACH_WNR2000_V4, "WNR2000V4", "NETGEAR WNR2000 V4", wnr2000v4_setup);