ar71xx: use the gpio_keys_polled driver instead of gpio_buttons
[openwrt/svn-archive/archive.git] / target / linux / ar71xx / files / arch / mips / ar71xx / mach-wndr3700.c
1 /*
2 * Netgear WNDR3700 board support
3 *
4 * Copyright (C) 2009 Marco Porsch
5 * Copyright (C) 2009-2010 Gabor Juhos <juhosg@openwrt.org>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License version 2 as published
9 * by the Free Software Foundation.
10 */
11
12 #include <linux/platform_device.h>
13 #include <linux/mtd/mtd.h>
14 #include <linux/mtd/partitions.h>
15 #include <linux/delay.h>
16 #include <linux/rtl8366s.h>
17
18 #include <asm/mach-ar71xx/ar71xx.h>
19
20 #include "machtype.h"
21 #include "devices.h"
22 #include "dev-m25p80.h"
23 #include "dev-ap94-pci.h"
24 #include "dev-gpio-buttons.h"
25 #include "dev-leds-gpio.h"
26 #include "dev-usb.h"
27
28 #define WNDR3700_GPIO_LED_WPS_ORANGE 0
29 #define WNDR3700_GPIO_LED_POWER_ORANGE 1
30 #define WNDR3700_GPIO_LED_POWER_GREEN 2
31 #define WNDR3700_GPIO_LED_WPS_GREEN 4
32 #define WNDR3700_GPIO_LED_WAN_GREEN 6
33
34 #define WNDR3700_GPIO_BTN_WPS 3
35 #define WNDR3700_GPIO_BTN_RESET 8
36 #define WNDR3700_GPIO_BTN_WIFI 11
37
38 #define WNDR3700_GPIO_RTL8366_SDA 5
39 #define WNDR3700_GPIO_RTL8366_SCK 7
40
41 #define WNDR3700_KEYS_POLL_INTERVAL 20 /* msecs */
42 #define WNDR3700_KEYS_DEBOUNCE_INTERVAL (3 * WNDR3700_KEYS_POLL_INTERVAL)
43
44 #define WNDR3700_ETH0_MAC_OFFSET 0
45 #define WNDR3700_ETH1_MAC_OFFSET 0x6
46
47 #define WNDR3700_WMAC0_MAC_OFFSET 0
48 #define WNDR3700_WMAC1_MAC_OFFSET 0xc
49 #define WNDR3700_CALDATA0_OFFSET 0x1000
50 #define WNDR3700_CALDATA1_OFFSET 0x5000
51
52 #ifdef CONFIG_MTD_PARTITIONS
53 static struct mtd_partition wndr3700_partitions[] = {
54 {
55 .name = "uboot",
56 .offset = 0,
57 .size = 0x050000,
58 .mask_flags = MTD_WRITEABLE,
59 }, {
60 .name = "env",
61 .offset = 0x050000,
62 .size = 0x020000,
63 .mask_flags = MTD_WRITEABLE,
64 }, {
65 .name = "rootfs",
66 .offset = 0x070000,
67 .size = 0x720000,
68 }, {
69 .name = "config",
70 .offset = 0x790000,
71 .size = 0x010000,
72 .mask_flags = MTD_WRITEABLE,
73 }, {
74 .name = "config_bak",
75 .offset = 0x7a0000,
76 .size = 0x010000,
77 .mask_flags = MTD_WRITEABLE,
78 }, {
79 .name = "pot",
80 .offset = 0x7b0000,
81 .size = 0x010000,
82 .mask_flags = MTD_WRITEABLE,
83 }, {
84 .name = "traffic_meter",
85 .offset = 0x7c0000,
86 .size = 0x010000,
87 .mask_flags = MTD_WRITEABLE,
88 }, {
89 .name = "language",
90 .offset = 0x7d0000,
91 .size = 0x020000,
92 .mask_flags = MTD_WRITEABLE,
93 }, {
94 .name = "caldata",
95 .offset = 0x7f0000,
96 .size = 0x010000,
97 .mask_flags = MTD_WRITEABLE,
98 }
99 };
100
101 static struct mtd_partition wndr3700v2_partitions[] = {
102 {
103 .name = "uboot",
104 .offset = 0,
105 .size = 0x050000,
106 .mask_flags = MTD_WRITEABLE,
107 }, {
108 .name = "env",
109 .offset = 0x050000,
110 .size = 0x020000,
111 .mask_flags = MTD_WRITEABLE,
112 }, {
113 .name = "rootfs",
114 .offset = 0x070000,
115 .size = 0xe40000,
116 }, {
117 .name = "config",
118 .offset = 0xeb0000,
119 .size = 0x010000,
120 .mask_flags = MTD_WRITEABLE,
121 }, {
122 .name = "config_bak",
123 .offset = 0xec0000,
124 .size = 0x010000,
125 .mask_flags = MTD_WRITEABLE,
126 }, {
127 .name = "pot",
128 .offset = 0xed0000,
129 .size = 0x010000,
130 .mask_flags = MTD_WRITEABLE,
131 }, {
132 .name = "traffic_meter",
133 .offset = 0xee0000,
134 .size = 0x010000,
135 .mask_flags = MTD_WRITEABLE,
136 }, {
137 .name = "language",
138 .offset = 0xef0000,
139 .size = 0x100000,
140 .mask_flags = MTD_WRITEABLE,
141 }, {
142 .name = "caldata",
143 .offset = 0xff0000,
144 .size = 0x010000,
145 .mask_flags = MTD_WRITEABLE,
146 }
147 };
148 #define wndr3700_num_partitions ARRAY_SIZE(wndr3700_partitions)
149 #define wndr3700v2_num_partitions ARRAY_SIZE(wndr3700v2_partitions)
150 #else
151 #define wndr3700_partitions NULL
152 #define wndr3700_num_partitions 0
153 #define wndr3700v2_partitions NULL
154 #define wndr3700v2_num_partitions 0
155 #endif /* CONFIG_MTD_PARTITIONS */
156
157 static struct flash_platform_data wndr3700_flash_data;
158
159 static struct gpio_led wndr3700_leds_gpio[] __initdata = {
160 {
161 .name = "wndr3700:green:power",
162 .gpio = WNDR3700_GPIO_LED_POWER_GREEN,
163 .active_low = 1,
164 }, {
165 .name = "wndr3700:orange:power",
166 .gpio = WNDR3700_GPIO_LED_POWER_ORANGE,
167 .active_low = 1,
168 }, {
169 .name = "wndr3700:green:wps",
170 .gpio = WNDR3700_GPIO_LED_WPS_GREEN,
171 .active_low = 1,
172 }, {
173 .name = "wndr3700:orange:wps",
174 .gpio = WNDR3700_GPIO_LED_WPS_ORANGE,
175 .active_low = 1,
176 }, {
177 .name = "wndr3700:green:wan",
178 .gpio = WNDR3700_GPIO_LED_WAN_GREEN,
179 .active_low = 1,
180 }
181 };
182
183 static struct gpio_keys_button wndr3700_gpio_keys[] __initdata = {
184 {
185 .desc = "reset",
186 .type = EV_KEY,
187 .code = KEY_RESTART,
188 .debounce_interval = WNDR3700_KEYS_DEBOUNCE_INTERVAL,
189 .gpio = WNDR3700_GPIO_BTN_RESET,
190 .active_low = 1,
191 }, {
192 .desc = "wps",
193 .type = EV_KEY,
194 .code = KEY_WPS_BUTTON,
195 .debounce_interval = WNDR3700_KEYS_DEBOUNCE_INTERVAL,
196 .gpio = WNDR3700_GPIO_BTN_WPS,
197 .active_low = 1,
198 }, {
199 .desc = "wifi",
200 .type = EV_KEY,
201 .code = BTN_2,
202 .debounce_interval = WNDR3700_KEYS_DEBOUNCE_INTERVAL,
203 .gpio = WNDR3700_GPIO_BTN_WIFI,
204 .active_low = 1,
205 }
206 };
207
208 static struct rtl8366s_platform_data wndr3700_rtl8366s_data = {
209 .gpio_sda = WNDR3700_GPIO_RTL8366_SDA,
210 .gpio_sck = WNDR3700_GPIO_RTL8366_SCK,
211 };
212
213 static struct platform_device wndr3700_rtl8366s_device = {
214 .name = RTL8366S_DRIVER_NAME,
215 .id = -1,
216 .dev = {
217 .platform_data = &wndr3700_rtl8366s_data,
218 }
219 };
220
221 static void __init wndr3700_common_setup(void)
222 {
223 u8 *art = (u8 *) KSEG1ADDR(0x1fff0000);
224
225 ar71xx_init_mac(ar71xx_eth0_data.mac_addr,
226 art + WNDR3700_ETH0_MAC_OFFSET, 0);
227 ar71xx_eth0_pll_data.pll_1000 = 0x11110000;
228 ar71xx_eth0_data.mii_bus_dev = &wndr3700_rtl8366s_device.dev;
229 ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
230 ar71xx_eth0_data.speed = SPEED_1000;
231 ar71xx_eth0_data.duplex = DUPLEX_FULL;
232
233 ar71xx_init_mac(ar71xx_eth1_data.mac_addr,
234 art + WNDR3700_ETH1_MAC_OFFSET, 0);
235 ar71xx_eth1_pll_data.pll_1000 = 0x11110000;
236 ar71xx_eth1_data.mii_bus_dev = &wndr3700_rtl8366s_device.dev;
237 ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
238 ar71xx_eth1_data.phy_mask = 0x10;
239
240 ar71xx_add_device_eth(0);
241 ar71xx_add_device_eth(1);
242
243 ar71xx_add_device_usb();
244
245 ar71xx_add_device_m25p80(&wndr3700_flash_data);
246
247 ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(wndr3700_leds_gpio),
248 wndr3700_leds_gpio);
249
250 ar71xx_register_gpio_keys_polled(-1, WNDR3700_KEYS_POLL_INTERVAL,
251 ARRAY_SIZE(wndr3700_gpio_keys),
252 wndr3700_gpio_keys);
253
254 platform_device_register(&wndr3700_rtl8366s_device);
255 platform_device_register_simple("wndr3700-led-usb", -1, NULL, 0);
256
257 ap94_pci_setup_wmac_led_pin(0, 5);
258 ap94_pci_setup_wmac_led_pin(1, 5);
259
260 /* 2.4 GHz uses the first fixed antenna group (1, 0, 1, 0) */
261 ap94_pci_setup_wmac_gpio(0, (0xf << 6), (0xa << 6));
262
263 /* 5 GHz uses the second fixed antenna group (0, 1, 1, 0) */
264 ap94_pci_setup_wmac_gpio(1, (0xf << 6), (0x6 << 6));
265
266 ap94_pci_init(art + WNDR3700_CALDATA0_OFFSET,
267 art + WNDR3700_WMAC0_MAC_OFFSET,
268 art + WNDR3700_CALDATA1_OFFSET,
269 art + WNDR3700_WMAC1_MAC_OFFSET);
270 }
271
272 static void __init wndr3700_setup(void)
273 {
274 wndr3700_flash_data.parts = wndr3700_partitions,
275 wndr3700_flash_data.nr_parts = wndr3700_num_partitions,
276 wndr3700_common_setup();
277 }
278
279 MIPS_MACHINE(AR71XX_MACH_WNDR3700, "WNDR3700", "NETGEAR WNDR3700",
280 wndr3700_setup);
281
282 static void __init wndr3700v2_setup(void)
283 {
284 wndr3700_flash_data.parts = wndr3700v2_partitions,
285 wndr3700_flash_data.nr_parts = wndr3700v2_num_partitions,
286 wndr3700_common_setup();
287 }
288
289 MIPS_MACHINE(AR71XX_MACH_WNDR3700V2, "WNDR3700v2", "NETGEAR WNDR3700v2",
290 wndr3700v2_setup);