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