ar71xx: add support for Netgear WPN824N
[openwrt.git] / target / linux / ar71xx / files / arch / mips / ath79 / mach-wnr2000-v3.c
1 /*
2  *  NETGEAR WNR2000v3/WNR612v2/WNR1000v2/WPN824N board support
3  *
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>
9  *
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.
13  */
14
15 #include <linux/mtd/mtd.h>
16 #include <linux/mtd/partitions.h>
17
18 #include <asm/mach-ath79/ath79.h>
19 #include <asm/mach-ath79/ar71xx_regs.h> /* needed to disable switch LEDs */
20 #include "common.h" /* needed to disable switch LEDs */
21
22 #include "dev-ap9x-pci.h"
23 #include "dev-eth.h"
24 #include "dev-gpio-buttons.h"
25 #include "dev-leds-gpio.h"
26 #include "dev-m25p80.h"
27 #include "machtypes.h"
28
29 #define WNR2000V3_GPIO_LED_WAN_GREEN    0
30 #define WNR2000V3_GPIO_LED_LAN1_AMBER   1
31 #define WNR2000V3_GPIO_LED_LAN4_AMBER   12
32 #define WNR2000V3_GPIO_LED_PWR_GREEN    14
33 #define WNR2000V3_GPIO_BTN_WPS          11
34
35 #define WNR612V2_GPIO_LED_PWR_GREEN     11
36
37 #define WNR1000V2_GPIO_LED_PWR_AMBER    1
38 #define WNR1000V2_GPIO_LED_PWR_GREEN    11
39
40 /* Connected through AR7240 */
41 #define WPN824N_GPIO_LED_WAN_AMBER      0
42 #define WPN824N_GPIO_LED_STATUS_AMBER   1
43 #define WPN824N_GPIO_LED_LAN1_AMBER     6 /* AR724X_GPIO_FUNC_JTAG_DISABLE */
44 #define WPN824N_GPIO_LED_LAN2_AMBER     7 /* AR724X_GPIO_FUNC_JTAG_DISABLE */
45 #define WPN824N_GPIO_LED_LAN3_AMBER     8 /* AR724X_GPIO_FUNC_JTAG_DISABLE */
46 #define WPN824N_GPIO_LED_LAN4_AMBER     12
47 #define WPN824N_GPIO_LED_LAN1_GREEN     13
48 #define WPN824N_GPIO_LED_LAN2_GREEN     14
49 #define WPN824N_GPIO_LED_LAN3_GREEN     15 /* AR724X_GPIO_FUNC_CLK_OBS3_EN */
50 #define WPN824N_GPIO_LED_LAN4_GREEN     16
51 #define WPN824N_GPIO_LED_WAN_GREEN      17
52
53 /* Connected through AR9285 */
54 #define WPN824N_WGPIO_LED_PWR_GREEN     0
55 #define WPN824N_WGPIO_LED_WLAN_BLUE     1
56 #define WPN824N_WGPIO_LED_WPS1_BLUE     5
57 #define WPN824N_WGPIO_LED_WPS2_BLUE     9
58 #define WPN824N_WGPIO_LED_TEST_AMBER    10
59 #define WPN824N_WGPIO_BTN_PUSH          6       /* currently unused */
60 #define WPN824N_WGPIO_BTN_RESET         7       /* currently unused */
61 #define WPN824N_WGPIO_BTN_WLAN          8       /* currently unused */
62
63 #define WNR2000V3_KEYS_POLL_INTERVAL    20      /* msecs */
64 #define WNR2000V3_KEYS_DEBOUNCE_INTERVAL        (3 * WNR2000V3_KEYS_POLL_INTERVAL)
65
66 #define WNR2000V3_MAC0_OFFSET           0
67 #define WNR2000V3_MAC1_OFFSET           6
68 #define WNR2000V3_PCIE_CALDATA_OFFSET   0x1000
69
70 static struct gpio_led wnr2000v3_leds_gpio[] __initdata = {
71         {
72                 .name           = "wnr2000v3:green:power",
73                 .gpio           = WNR2000V3_GPIO_LED_PWR_GREEN,
74                 .active_low     = 1,
75         }, {
76                 .name           = "wnr2000v3:green:wan",
77                 .gpio           = WNR2000V3_GPIO_LED_WAN_GREEN,
78                 .active_low     = 1,
79         }
80 };
81
82 static struct gpio_led wnr612v2_leds_gpio[] __initdata = {
83         {
84                 .name           = "netgear:green:power",
85                 .gpio           = WNR612V2_GPIO_LED_PWR_GREEN,
86                 .active_low     = 1,
87         }
88 };
89
90 static struct gpio_led wnr1000v2_leds_gpio[] __initdata = {
91         {
92                 .name           = "netgear:green:power",
93                 .gpio           = WNR1000V2_GPIO_LED_PWR_GREEN,
94                 .active_low     = 1,
95         }, {
96                 .name           = "netgear:amber:power",
97                 .gpio           = WNR1000V2_GPIO_LED_PWR_AMBER,
98                 .active_low     = 1,
99         }
100 };
101
102 static struct gpio_led wpn824n_leds_gpio[] __initdata = {
103         {
104                 .name           = "netgear:amber:wan",
105                 .gpio           = WPN824N_GPIO_LED_WAN_AMBER,
106                 .active_low     = 1,
107         }, {
108                 .name           = "netgear:amber:status",
109                 .gpio           = WPN824N_GPIO_LED_STATUS_AMBER,
110                 .active_low     = 1,
111         }, {
112                 .name           = "netgear:amber:lan1",
113                 .gpio           = WPN824N_GPIO_LED_LAN1_AMBER,
114                 .active_low     = 1,
115         }, {
116                 .name           = "netgear:amber:lan2",
117                 .gpio           = WPN824N_GPIO_LED_LAN2_AMBER,
118                 .active_low     = 1,
119         }, {
120                 .name           = "netgear:amber:lan3",
121                 .gpio           = WPN824N_GPIO_LED_LAN3_AMBER,
122                 .active_low     = 1,
123         }, {
124                 .name           = "netgear:amber:lan4",
125                 .gpio           = WPN824N_GPIO_LED_LAN4_AMBER,
126                 .active_low     = 1,
127         }, {
128                 .name           = "netgear:green:lan1",
129                 .gpio           = WPN824N_GPIO_LED_LAN1_GREEN,
130                 .active_low     = 1,
131         }, {
132                 .name           = "netgear:green:lan2",
133                 .gpio           = WPN824N_GPIO_LED_LAN2_GREEN,
134                 .active_low     = 1,
135         }, {
136                 .name           = "netgear:green:lan3",
137                 .gpio           = WPN824N_GPIO_LED_LAN3_GREEN,
138                 .active_low     = 1,
139         }, {
140                 .name           = "netgear:green:lan4",
141                 .gpio           = WPN824N_GPIO_LED_LAN4_GREEN,
142                 .active_low     = 1,
143         }, {
144                 .name           = "netgear:green:wan",
145                 .gpio           = WPN824N_GPIO_LED_WAN_GREEN,
146                 .active_low     = 1,
147         }
148 };
149
150 static struct gpio_led wpn824n_wmac_leds_gpio[] = {
151         {
152                 .name           = "netgear:green:power",
153                 .gpio           = WPN824N_WGPIO_LED_PWR_GREEN,
154                 .active_low     = 1,
155         }, {
156                 .name           = "netgear:blue:wlan",
157                 .gpio           = WPN824N_WGPIO_LED_WLAN_BLUE,
158                 .active_low     = 1,
159         }, {
160                 .name           = "netgear:blue:wps1",
161                 .gpio           = WPN824N_WGPIO_LED_WPS1_BLUE,
162                 .active_low     = 1,
163         }, {
164                 .name           = "netgear:blue:wps2",
165                 .gpio           = WPN824N_WGPIO_LED_WPS2_BLUE,
166                 .active_low     = 1,
167         }, {
168                 .name           = "netgear:amber:test",
169                 .gpio           = WPN824N_WGPIO_LED_TEST_AMBER,
170                 .active_low     = 1,
171         }
172 };
173
174 static struct gpio_keys_button wnr2000v3_gpio_keys[] __initdata = {
175         {
176                 .desc           = "wps",
177                 .type           = EV_KEY,
178                 .code           = KEY_WPS_BUTTON,
179                 .debounce_interval = WNR2000V3_KEYS_DEBOUNCE_INTERVAL,
180                 .gpio           = WNR2000V3_GPIO_BTN_WPS,
181         }
182 };
183
184 static void __init wnr_common_setup(void)
185 {
186         u8 *art = (u8 *) KSEG1ADDR(0x1fff0000);
187
188         ath79_register_mdio(0, 0x0);
189
190         ath79_init_mac(ath79_eth0_data.mac_addr, art+WNR2000V3_MAC0_OFFSET, 0);
191         ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
192         ath79_eth0_data.speed = SPEED_100;
193         ath79_eth0_data.duplex = DUPLEX_FULL;
194
195         ath79_init_mac(ath79_eth1_data.mac_addr, art+WNR2000V3_MAC1_OFFSET, 0);
196         ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
197         ath79_eth1_data.phy_mask = 0x10;
198
199         ath79_register_eth(0);
200         ath79_register_eth(1);
201
202         ath79_register_m25p80(NULL);
203         ap91_pci_init(art + WNR2000V3_PCIE_CALDATA_OFFSET, NULL);
204 }
205
206 static void __init wnr2000v3_setup(void)
207 {
208         wnr_common_setup();
209
210         ath79_register_leds_gpio(-1, ARRAY_SIZE(wnr2000v3_leds_gpio),
211                                  wnr2000v3_leds_gpio);
212
213         ath79_register_gpio_keys_polled(-1, WNR2000V3_KEYS_POLL_INTERVAL,
214                                         ARRAY_SIZE(wnr2000v3_gpio_keys),
215                                         wnr2000v3_gpio_keys);
216 }
217
218 MIPS_MACHINE(ATH79_MACH_WNR2000_V3, "WNR2000V3", "NETGEAR WNR2000 V3", wnr2000v3_setup);
219
220 static void __init wnr612v2_setup(void)
221 {
222         wnr_common_setup();
223
224         ath79_register_leds_gpio(-1, ARRAY_SIZE(wnr612v2_leds_gpio),
225                                  wnr612v2_leds_gpio);
226 }
227
228 MIPS_MACHINE(ATH79_MACH_WNR612_V2, "WNR612V2", "NETGEAR WNR612 V2", wnr612v2_setup);
229
230 static void __init wnr1000v2_setup(void)
231 {
232         wnr_common_setup();
233
234         ath79_register_leds_gpio(-1, ARRAY_SIZE(wnr1000v2_leds_gpio),
235                                  wnr1000v2_leds_gpio);
236 }
237
238 MIPS_MACHINE(ATH79_MACH_WNR1000_V2, "WNR1000V2", "NETGEAR WNR1000 V2", wnr1000v2_setup);
239
240 static void __init wpn824n_setup(void)
241 {
242         ath79_gpio_function_setup(AR724X_GPIO_FUNC_JTAG_DISABLE,
243                                   AR724X_GPIO_FUNC_ETH_SWITCH_LED0_EN |
244                                   AR724X_GPIO_FUNC_ETH_SWITCH_LED1_EN |
245                                   AR724X_GPIO_FUNC_ETH_SWITCH_LED2_EN |
246                                   AR724X_GPIO_FUNC_ETH_SWITCH_LED3_EN |
247                                   AR724X_GPIO_FUNC_ETH_SWITCH_LED4_EN |
248                                   AR724X_GPIO_FUNC_CLK_OBS3_EN);
249
250         wnr_common_setup();
251
252         ath79_register_leds_gpio(-1, ARRAY_SIZE(wpn824n_leds_gpio),
253                                  wpn824n_leds_gpio);
254
255         ap9x_pci_setup_wmac_led_pin(0, WPN824N_WGPIO_LED_WLAN_BLUE);
256         ap9x_pci_setup_wmac_leds(0, wpn824n_wmac_leds_gpio,
257                                  ARRAY_SIZE(wpn824n_wmac_leds_gpio));
258 }
259
260 MIPS_MACHINE(ATH79_MACH_WPN824N, "WPN824N", "NETGEAR WPN824N", wpn824n_setup);