f0b781955a0f8b98a603ee3d7fafb277f4d830d1
[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_BUTTONS_POLL_INTERVAL 20
42
43 #define WNDR3700_ETH0_MAC_OFFSET 0
44 #define WNDR3700_ETH1_MAC_OFFSET 0x6
45
46 #define WNDR3700_WMAC0_MAC_OFFSET 0
47 #define WNDR3700_WMAC1_MAC_OFFSET 0xc
48 #define WNDR3700_CALDATA0_OFFSET 0x1000
49 #define WNDR3700_CALDATA1_OFFSET 0x5000
50
51 #ifdef CONFIG_MTD_PARTITIONS
52 static struct mtd_partition wndr3700_partitions[] = {
53 {
54 .name = "uboot",
55 .offset = 0,
56 .size = 0x050000,
57 .mask_flags = MTD_WRITEABLE,
58 }, {
59 .name = "env",
60 .offset = 0x050000,
61 .size = 0x020000,
62 .mask_flags = MTD_WRITEABLE,
63 }, {
64 .name = "rootfs",
65 .offset = 0x070000,
66 .size = 0x720000,
67 }, {
68 .name = "config",
69 .offset = 0x790000,
70 .size = 0x010000,
71 .mask_flags = MTD_WRITEABLE,
72 }, {
73 .name = "config_bak",
74 .offset = 0x7a0000,
75 .size = 0x010000,
76 .mask_flags = MTD_WRITEABLE,
77 }, {
78 .name = "pot",
79 .offset = 0x7b0000,
80 .size = 0x010000,
81 .mask_flags = MTD_WRITEABLE,
82 }, {
83 .name = "traffic_meter",
84 .offset = 0x7c0000,
85 .size = 0x010000,
86 .mask_flags = MTD_WRITEABLE,
87 }, {
88 .name = "language",
89 .offset = 0x7d0000,
90 .size = 0x020000,
91 .mask_flags = MTD_WRITEABLE,
92 }, {
93 .name = "caldata",
94 .offset = 0x7f0000,
95 .size = 0x010000,
96 .mask_flags = MTD_WRITEABLE,
97 }
98 };
99
100 static struct mtd_partition wndr3700v2_partitions[] = {
101 {
102 .name = "uboot",
103 .offset = 0,
104 .size = 0x050000,
105 .mask_flags = MTD_WRITEABLE,
106 }, {
107 .name = "env",
108 .offset = 0x050000,
109 .size = 0x020000,
110 .mask_flags = MTD_WRITEABLE,
111 }, {
112 .name = "rootfs",
113 .offset = 0x070000,
114 .size = 0xe40000,
115 }, {
116 .name = "config",
117 .offset = 0xeb0000,
118 .size = 0x010000,
119 .mask_flags = MTD_WRITEABLE,
120 }, {
121 .name = "config_bak",
122 .offset = 0xec0000,
123 .size = 0x010000,
124 .mask_flags = MTD_WRITEABLE,
125 }, {
126 .name = "pot",
127 .offset = 0xed0000,
128 .size = 0x010000,
129 .mask_flags = MTD_WRITEABLE,
130 }, {
131 .name = "traffic_meter",
132 .offset = 0xee0000,
133 .size = 0x010000,
134 .mask_flags = MTD_WRITEABLE,
135 }, {
136 .name = "language",
137 .offset = 0xef0000,
138 .size = 0x100000,
139 .mask_flags = MTD_WRITEABLE,
140 }, {
141 .name = "caldata",
142 .offset = 0xff0000,
143 .size = 0x010000,
144 .mask_flags = MTD_WRITEABLE,
145 }
146 };
147 #define wndr3700_num_partitions ARRAY_SIZE(wndr3700_partitions)
148 #define wndr3700v2_num_partitions ARRAY_SIZE(wndr3700v2_partitions)
149 #else
150 #define wndr3700_partitions NULL
151 #define wndr3700_num_partitions 0
152 #define wndr3700v2_partitions NULL
153 #define wndr3700v2_num_partitions 0
154 #endif /* CONFIG_MTD_PARTITIONS */
155
156 static struct flash_platform_data wndr3700_flash_data;
157
158 static struct gpio_led wndr3700_leds_gpio[] __initdata = {
159 {
160 .name = "wndr3700:green:power",
161 .gpio = WNDR3700_GPIO_LED_POWER_GREEN,
162 .active_low = 1,
163 }, {
164 .name = "wndr3700:orange:power",
165 .gpio = WNDR3700_GPIO_LED_POWER_ORANGE,
166 .active_low = 1,
167 }, {
168 .name = "wndr3700:green:wps",
169 .gpio = WNDR3700_GPIO_LED_WPS_GREEN,
170 .active_low = 1,
171 }, {
172 .name = "wndr3700:orange:wps",
173 .gpio = WNDR3700_GPIO_LED_WPS_ORANGE,
174 .active_low = 1,
175 }, {
176 .name = "wndr3700:green:wan",
177 .gpio = WNDR3700_GPIO_LED_WAN_GREEN,
178 .active_low = 1,
179 }
180 };
181
182 static struct gpio_button wndr3700_gpio_buttons[] __initdata = {
183 {
184 .desc = "reset",
185 .type = EV_KEY,
186 .code = KEY_RESTART,
187 .threshold = 3,
188 .gpio = WNDR3700_GPIO_BTN_RESET,
189 .active_low = 1,
190 }, {
191 .desc = "wps",
192 .type = EV_KEY,
193 .code = KEY_WPS_BUTTON,
194 .threshold = 3,
195 .gpio = WNDR3700_GPIO_BTN_WPS,
196 .active_low = 1,
197 }, {
198 .desc = "wifi",
199 .type = EV_KEY,
200 .code = BTN_2,
201 .threshold = 3,
202 .gpio = WNDR3700_GPIO_BTN_WIFI,
203 .active_low = 1,
204 }
205 };
206
207 static struct rtl8366s_platform_data wndr3700_rtl8366s_data = {
208 .gpio_sda = WNDR3700_GPIO_RTL8366_SDA,
209 .gpio_sck = WNDR3700_GPIO_RTL8366_SCK,
210 };
211
212 static struct platform_device wndr3700_rtl8366s_device = {
213 .name = RTL8366S_DRIVER_NAME,
214 .id = -1,
215 .dev = {
216 .platform_data = &wndr3700_rtl8366s_data,
217 }
218 };
219
220 static void __init wndr3700_common_setup(void)
221 {
222 u8 *art = (u8 *) KSEG1ADDR(0x1fff0000);
223
224 ar71xx_init_mac(ar71xx_eth0_data.mac_addr,
225 art + WNDR3700_ETH0_MAC_OFFSET, 0);
226 ar71xx_eth0_pll_data.pll_1000 = 0x11110000;
227 ar71xx_eth0_data.mii_bus_dev = &wndr3700_rtl8366s_device.dev;
228 ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
229 ar71xx_eth0_data.speed = SPEED_1000;
230 ar71xx_eth0_data.duplex = DUPLEX_FULL;
231
232 ar71xx_init_mac(ar71xx_eth1_data.mac_addr,
233 art + WNDR3700_ETH1_MAC_OFFSET, 0);
234 ar71xx_eth1_pll_data.pll_1000 = 0x11110000;
235 ar71xx_eth1_data.mii_bus_dev = &wndr3700_rtl8366s_device.dev;
236 ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
237 ar71xx_eth1_data.phy_mask = 0x10;
238
239 ar71xx_add_device_eth(0);
240 ar71xx_add_device_eth(1);
241
242 ar71xx_add_device_usb();
243
244 ar71xx_add_device_m25p80(&wndr3700_flash_data);
245
246 ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(wndr3700_leds_gpio),
247 wndr3700_leds_gpio);
248
249 ar71xx_add_device_gpio_buttons(-1, WNDR3700_BUTTONS_POLL_INTERVAL,
250 ARRAY_SIZE(wndr3700_gpio_buttons),
251 wndr3700_gpio_buttons);
252
253 platform_device_register(&wndr3700_rtl8366s_device);
254 platform_device_register_simple("wndr3700-led-usb", -1, NULL, 0);
255
256 ap94_pci_setup_wmac_led_pin(0, 5);
257 ap94_pci_setup_wmac_led_pin(1, 5);
258
259 /* 2.4 GHz uses the first fixed antenna group (1, 0, 1, 0) */
260 ap94_pci_setup_wmac_gpio(0, (0xf << 6), (0xa << 6));
261
262 /* 5 GHz uses the second fixed antenna group (0, 1, 1, 0) */
263 ap94_pci_setup_wmac_gpio(1, (0xf << 6), (0x6 << 6));
264
265 ap94_pci_init(art + WNDR3700_CALDATA0_OFFSET,
266 art + WNDR3700_WMAC0_MAC_OFFSET,
267 art + WNDR3700_CALDATA1_OFFSET,
268 art + WNDR3700_WMAC1_MAC_OFFSET);
269 }
270
271 static void __init wndr3700_setup(void)
272 {
273 wndr3700_flash_data.parts = wndr3700_partitions,
274 wndr3700_flash_data.nr_parts = wndr3700_num_partitions,
275 wndr3700_common_setup();
276 }
277
278 MIPS_MACHINE(AR71XX_MACH_WNDR3700, "WNDR3700", "NETGEAR WNDR3700",
279 wndr3700_setup);
280
281 static void __init wndr3700v2_setup(void)
282 {
283 wndr3700_flash_data.parts = wndr3700v2_partitions,
284 wndr3700_flash_data.nr_parts = wndr3700v2_num_partitions,
285 wndr3700_common_setup();
286 }
287
288 MIPS_MACHINE(AR71XX_MACH_WNDR3700V2, "WNDR3700v2", "NETGEAR WNDR3700v2",
289 wndr3700v2_setup);