9c10b9512833524d428814efa915af1736eb4c45
[openwrt/staging/lynxis/omap.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 = "netgear:green:power",
56 .gpio = WNR2000V4_GPIO_LED_PWR_GREEN,
57 .active_low = 1,
58 .default_trigger = "default-on",
59 }, {
60 .name = "netgear:green:wan",
61 .gpio = WNR2000V4_GPIO_LED_WAN_AMBER,
62 .active_low = 1,
63 },
64 {
65 .name = "netgear:green:wps",
66 .gpio = WNR2000V4_GPIO_LED_WPS,
67 .active_low = 1,
68 },
69 {
70 .name = "netgear:amber:status",
71 .gpio = STATUS_LED_GPIO,
72 .active_low = 1,
73 },
74 {
75 .name = "netgear:blue:wlan",
76 .gpio = WNR2000V4_GPIO_LED_WLAN,
77 .active_low = 1,
78 },
79 {
80 .name = "netgear:amber:lan1",
81 .gpio = WNR2000V4_GPIO_LED_LAN1,
82 .active_low = 1,
83 }, {
84 .name = "netgear:amber:lan2",
85 .gpio = WNR2000V4_GPIO_LED_LAN2,
86 .active_low = 1,
87 }, {
88 .name = "netgear:amber:lan3",
89 .gpio = WNR2000V4_GPIO_LED_LAN3,
90 .active_low = 1,
91 }, {
92 .name = "netgear: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 .active_low = 1,
106 },
107 {
108 .desc = "Reset button",
109 .type = EV_KEY,
110 .code = KEY_RESTART,
111 .debounce_interval = WNR2000V4_KEYS_DEBOUNCE_INTERVAL,
112 .gpio = WNR2000V4_GPIO_BTN_RESET,
113 .active_low = 1,
114 },
115 {
116 .desc = "WLAN button",
117 .type = EV_KEY,
118 .code = KEY_RFKILL,
119 .debounce_interval = WNR2000V4_KEYS_DEBOUNCE_INTERVAL,
120 .gpio = WNR2000V4_GPIO_BTN_WLAN,
121 .active_low = 1,
122 },
123 };
124
125 static void __init wnr_common_setup(void)
126 {
127 u8 *art = (u8 *) KSEG1ADDR(0x1fff0000);
128 u8 *ee = (u8 *) KSEG1ADDR(0x1fff1000);
129
130 ath79_register_mdio(1, 0x0);
131
132 ath79_register_usb();
133
134 ath79_register_m25p80(NULL);
135
136 ath79_setup_ar934x_eth_cfg(AR934X_ETH_CFG_SW_ONLY_MODE);
137
138 ath79_init_mac(ath79_eth0_data.mac_addr, art+WNR2000V4_MAC0_OFFSET, 0);
139 ath79_init_mac(ath79_eth1_data.mac_addr, art+WNR2000V4_MAC1_OFFSET, 0);
140
141 /* GMAC0 is connected to the PHY0 of the internal switch, GE0 */
142 ath79_switch_data.phy4_mii_en = 1;
143 ath79_switch_data.phy_poll_mask = BIT(4);
144 ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
145 ath79_eth0_data.phy_mask = BIT(4);
146 ath79_eth0_data.mii_bus_dev = &ath79_mdio1_device.dev;
147 ath79_register_eth(0);
148
149 /* GMAC1 is connected to the internal switch, GE1 */
150 ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_GMII;
151 ath79_register_eth(1);
152
153 ath79_register_wmac(ee, art);
154 }
155
156 static void __init wnr2000v4_setup(void)
157 {
158 wnr_common_setup();
159
160 ath79_register_leds_gpio(-1, ARRAY_SIZE(wnr2000v4_leds_gpio),
161 wnr2000v4_leds_gpio);
162
163 ath79_register_gpio_keys_polled(-1, WNR2000V4_KEYS_POLL_INTERVAL,
164 ARRAY_SIZE(wnr2000v4_gpio_keys),
165 wnr2000v4_gpio_keys);
166 }
167
168 MIPS_MACHINE(ATH79_MACH_WNR2000_V4, "WNR2000V4", "NETGEAR WNR2000 V4", wnr2000v4_setup);