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