ar71xx: Fix LED polarity for the TP-LINK TL-MR13U.
[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 18
37 #define WNR2000V4_GPIO_LED_LAN2 19
38 #define WNR2000V4_GPIO_LED_LAN3 20
39 #define WNR2000V4_GPIO_LED_LAN4 21
40 #define STATUS_LED_GPIO         1
41 #define WNR2000V4_GPIO_LED_PWR_GREEN    0
42
43 #define WNR2000V4_GPIO_BTN_WPS      3
44 #define WNR2000V4_GPIO_BTN_RESET    4
45 #define WNR2000V4_GPIO_BTN_WLAN     11
46
47 #define WNR2000V4_KEYS_POLL_INTERVAL    20      /* msecs */
48 #define WNR2000V4_KEYS_DEBOUNCE_INTERVAL        (3 * WNR2000V4_KEYS_POLL_INTERVAL)
49
50 #define WNR2000V4_MAC0_OFFSET           0
51 #define WNR2000V4_MAC1_OFFSET           6
52
53 static struct gpio_led wnr2000v4_leds_gpio[] __initdata = {
54         {
55                 .name           = "wnr2000-v4:green:power",
56                 .gpio           = WNR2000V4_GPIO_LED_PWR_GREEN,
57                 .active_low     = 1,
58         .default_trigger = "default-on",
59         }, {
60                 .name           = "wnr2000-v4:green:wan",
61                 .gpio           = WNR2000V4_GPIO_LED_WAN_AMBER,
62                 .active_low     = 1,
63         },
64         {
65                 .name           = "wnr2000-v4:green:wps",
66                 .gpio           = WNR2000V4_GPIO_LED_WPS,
67                 .active_low     = 1,
68         },
69         {
70                 .name           = "wnr2000-v4:amber:status",
71                 .gpio           = STATUS_LED_GPIO,
72                 .active_low     = 1,
73         },
74         {
75                 .name           = "wnr2000-v4:blue:wlan",
76                 .gpio           = WNR2000V4_GPIO_LED_WLAN,
77                 .active_low     = 1,
78         },
79         {
80                 .name           = "wnr2000-v4:amber:lan1",
81                 .gpio           = WNR2000V4_GPIO_LED_LAN1,
82                 .active_low     = 1,
83         }, {
84                 .name           = "wnr2000-v4:amber:lan2",
85                 .gpio           = WNR2000V4_GPIO_LED_LAN2,
86                 .active_low     = 1,
87         }, {
88                 .name           = "wnr2000-v4:amber:lan3",
89                 .gpio           = WNR2000V4_GPIO_LED_LAN3,
90                 .active_low     = 1,
91         }, {
92                 .name           = "wnr2000-v4:amber:lan4",
93                 .gpio           = WNR2000V4_GPIO_LED_LAN4,
94                 .active_low     = 1,
95         }
96 };
97
98 static struct gpio_keys_button wnr2000v4_gpio_keys[] __initdata = {
99         {
100                 .desc           = "WPS button",
101                 .type           = EV_KEY,
102                 .code           = KEY_WPS_BUTTON,
103                 .debounce_interval = WNR2000V4_KEYS_DEBOUNCE_INTERVAL,
104                 .gpio           = WNR2000V4_GPIO_BTN_WPS,
105         },
106         {
107                 .desc           = "Reset button",
108                 .type           = EV_KEY,
109                 .code           = KEY_RESTART,
110                 .debounce_interval = WNR2000V4_KEYS_DEBOUNCE_INTERVAL,
111                 .gpio           = WNR2000V4_GPIO_BTN_RESET,
112         },
113         {
114                 .desc           = "WLAN button",
115                 .type           = EV_KEY,
116                 .code           = KEY_WLAN,
117                 .debounce_interval = WNR2000V4_KEYS_DEBOUNCE_INTERVAL,
118                 .gpio           = WNR2000V4_GPIO_BTN_WLAN,
119         },
120 };
121
122 static void __init wnr_common_setup(void)
123 {
124         u8 *art = (u8 *) KSEG1ADDR(0x1fff0000);
125         u8 *ee = (u8 *) KSEG1ADDR(0x1fff1000);
126
127         ath79_register_m25p80(NULL);
128
129         ath79_setup_ar934x_eth_cfg(AR934X_ETH_CFG_SW_ONLY_MODE |
130                                    AR934X_ETH_CFG_SW_PHY_SWAP);
131
132         ath79_register_mdio(1, 0x0);
133
134         /* LAN */
135         ath79_init_mac(ath79_eth1_data.mac_addr, art+WNR2000V4_MAC0_OFFSET, 0);
136
137         /* GMAC1 is connected to the internal switch */
138         ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_GMII;
139         ath79_register_eth(1);
140
141         /* WAN */
142         ath79_init_mac(ath79_eth0_data.mac_addr, art+WNR2000V4_MAC1_OFFSET, 0);
143
144         /* GMAC0 is connected to the PHY0 of the internal switch */
145         ath79_switch_data.phy4_mii_en = 1;
146         ath79_switch_data.phy_poll_mask = BIT(4);
147         ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
148         ath79_eth0_data.phy_mask = BIT(4);
149         ath79_eth0_data.mii_bus_dev = &ath79_mdio1_device.dev;
150
151         ath79_eth0_data.speed = SPEED_100;
152         ath79_eth0_data.duplex = DUPLEX_FULL;
153
154         ath79_register_eth(0);
155
156         /* WLAN */
157         ath79_register_wmac(ee, art+WNR2000V4_MAC0_OFFSET);
158
159         /* USB */
160         ath79_register_usb();
161 }
162
163 static void __init wnr2000v4_setup(void)
164 {
165         wnr_common_setup();
166
167         ath79_register_leds_gpio(-1, ARRAY_SIZE(wnr2000v4_leds_gpio),
168                                  wnr2000v4_leds_gpio);
169
170         ath79_register_gpio_keys_polled(-1, WNR2000V4_KEYS_POLL_INTERVAL,
171                                         ARRAY_SIZE(wnr2000v4_gpio_keys),
172                                         wnr2000v4_gpio_keys);
173 }
174
175 MIPS_MACHINE(ATH79_MACH_WNR2000_V4, "WNR2000V4", "NETGEAR WNR2000 V4", wnr2000v4_setup);