ar71xx: add support for green LAN LEDS for wnr2000-v4
[oweals/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:amber:wan",
65                 .gpio           = WNR2000V4_GPIO_LED_WAN_AMBER,
66                 .active_low     = 1,
67         },
68         {
69                 .name           = "netgear:green:wps",
70                 .gpio           = WNR2000V4_GPIO_LED_WPS,
71                 .active_low     = 1,
72         },
73         {
74                 .name           = "netgear:amber:status",
75                 .gpio           = STATUS_LED_GPIO,
76                 .active_low     = 1,
77         },
78         {
79                 .name           = "netgear:blue:wlan",
80                 .gpio           = WNR2000V4_GPIO_LED_WLAN,
81                 .active_low     = 1,
82         },
83         /* LAN LEDS */
84         {
85                 .name           = "netgear:green:lan1",
86                 .gpio           = WNR2000V4_GPIO_LED_LAN1_GREEN,
87                 .active_low     = 1,
88         }, {
89                 .name           = "netgear:green:lan2",
90                 .gpio           = WNR2000V4_GPIO_LED_LAN2_GREEN,
91                 .active_low     = 1,
92         }, {
93                 .name           = "netgear:green:lan3",
94                 .gpio           = WNR2000V4_GPIO_LED_LAN3_GREEN,
95                 .active_low     = 1,
96         }, {
97                 .name           = "netgear:green:lan4",
98                 .gpio           = WNR2000V4_GPIO_LED_LAN4_GREEN,
99                 .active_low     = 1,
100         },
101         {
102                 .name           = "netgear:amber:lan1",
103                 .gpio           = WNR2000V4_GPIO_LED_LAN1_AMBER,
104                 .active_low     = 1,
105         }, {
106                 .name           = "netgear:amber:lan2",
107                 .gpio           = WNR2000V4_GPIO_LED_LAN2_AMBER,
108                 .active_low     = 1,
109         }, {
110                 .name           = "netgear:amber:lan3",
111                 .gpio           = WNR2000V4_GPIO_LED_LAN3_AMBER,
112                 .active_low     = 1,
113         }, {
114                 .name           = "netgear:amber:lan4",
115                 .gpio           = WNR2000V4_GPIO_LED_LAN4_AMBER,
116                 .active_low     = 1,
117         }
118 };
119
120 static struct gpio_keys_button wnr2000v4_gpio_keys[] __initdata = {
121         {
122                 .desc           = "WPS button",
123                 .type           = EV_KEY,
124                 .code           = KEY_WPS_BUTTON,
125                 .debounce_interval = WNR2000V4_KEYS_DEBOUNCE_INTERVAL,
126                 .gpio           = WNR2000V4_GPIO_BTN_WPS,
127                 .active_low     = 1,
128         },
129         {
130                 .desc           = "Reset button",
131                 .type           = EV_KEY,
132                 .code           = KEY_RESTART,
133                 .debounce_interval = WNR2000V4_KEYS_DEBOUNCE_INTERVAL,
134                 .gpio           = WNR2000V4_GPIO_BTN_RESET,
135                 .active_low     = 1,
136         },
137         {
138                 .desc           = "WLAN button",
139                 .type           = EV_KEY,
140                 .code           = KEY_RFKILL,
141                 .debounce_interval = WNR2000V4_KEYS_DEBOUNCE_INTERVAL,
142                 .gpio           = WNR2000V4_GPIO_BTN_WLAN,
143                 .active_low     = 1,
144         },
145 };
146
147 static void __init wnr_common_setup(void)
148 {
149         u8 *art = (u8 *) KSEG1ADDR(0x1fff0000);
150         u8 *ee  = (u8 *) KSEG1ADDR(0x1fff1000);
151
152         ath79_register_mdio(1, 0x0);
153
154         ath79_register_usb();
155
156         ath79_register_m25p80(NULL);
157
158         ath79_setup_ar934x_eth_cfg(AR934X_ETH_CFG_SW_ONLY_MODE);
159
160         ath79_init_mac(ath79_eth0_data.mac_addr, art+WNR2000V4_MAC0_OFFSET, 0);
161         ath79_init_mac(ath79_eth1_data.mac_addr, art+WNR2000V4_MAC1_OFFSET, 0);
162
163         /* GMAC0 is connected to the PHY0 of the internal switch, GE0 */
164         ath79_switch_data.phy4_mii_en = 1;
165         ath79_switch_data.phy_poll_mask = BIT(4);
166         ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
167         ath79_eth0_data.phy_mask = BIT(4);
168         ath79_eth0_data.mii_bus_dev = &ath79_mdio1_device.dev;
169         ath79_register_eth(0);
170
171         /* GMAC1 is connected to the internal switch, GE1 */
172         ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_GMII;
173         ath79_register_eth(1);
174
175         ath79_register_wmac(ee, art);
176 }
177
178 static void __init wnr2000v4_setup(void)
179 {
180         int i;
181
182         wnr_common_setup();
183
184         /* Ensure no LED has an internal MUX signal, otherwise
185         control of LED could be lost... This is especially important
186         for most green LEDS (Eth,WAN).. who arrive in this function with
187         MUX signals set. */
188         for (i = 0; i < ARRAY_SIZE(wnr2000v4_leds_gpio); i++)
189                 ath79_gpio_output_select(wnr2000v4_leds_gpio[i].gpio,
190                                         AR934X_GPIO_OUT_GPIO);
191
192         ath79_register_leds_gpio(-1, ARRAY_SIZE(wnr2000v4_leds_gpio),
193                                  wnr2000v4_leds_gpio);
194
195         ath79_register_gpio_keys_polled(-1, WNR2000V4_KEYS_POLL_INTERVAL,
196                                         ARRAY_SIZE(wnr2000v4_gpio_keys),
197                                         wnr2000v4_gpio_keys);
198 }
199
200 MIPS_MACHINE(ATH79_MACH_WNR2000_V4, "WNR2000V4", "NETGEAR WNR2000 V4", wnr2000v4_setup);