ar71xx: add preliminary support for the Buffalo WZR-HP-G300NH
[openwrt/svn-archive/archive.git] / target / linux / ar71xx / files / arch / mips / ar71xx / mach-wzr-hp-g300nh.c
1 /*
2 * Buffalo WZR-HP-G300NH board support
3 *
4 * Copyright (C) 2010 Gabor Juhos <juhosg@openwrt.org>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published
8 * by the Free Software Foundation.
9 */
10
11 #include <linux/platform_device.h>
12 #include <linux/mtd/mtd.h>
13 #include <linux/mtd/partitions.h>
14 #include <linux/nxp_74hc153.h>
15 #include <linux/rtl8366_smi.h>
16
17 #include <asm/mips_machine.h>
18 #include <asm/mach-ar71xx/ar71xx.h>
19 #include <asm/mach-ar71xx/ar91xx_flash.h>
20
21 #include "machtype.h"
22 #include "devices.h"
23 #include "dev-ar913x-wmac.h"
24 #include "dev-gpio-buttons.h"
25 #include "dev-leds-gpio.h"
26 #include "dev-usb.h"
27
28 #define WZRHPG300NH_GPIO_LED_USB 0
29 #define WZRHPG300NH_GPIO_LED_DIAG 1
30 #define WZRHPG300NH_GPIO_LED_WIRELESS 6
31 #define WZRHPG300NH_GPIO_LED_SECURITY 17
32 #define WZRHPG300NH_GPIO_LED_ROUTER 18
33
34 #define WZRHPG300NH_GPIO_RTL8366_SDA 19
35 #define WZRHPG300NH_GPIO_RTL8366_SCK 20
36
37 #define WZRHPG300NH_GPIO_74HC153_S0 9
38 #define WZRHPG300NH_GPIO_74HC153_S1 11
39 #define WZRHPG300NH_GPIO_74HC153_1Y 12
40 #define WZRHPG300NH_GPIO_74HC153_2Y 14
41
42 #define WZRHPG300NH_GPIO_EXP_BASE 32
43 #define WZRHPG300NH_GPIO_BTN_AOSS (WZRHPG300NH_GPIO_EXP_BASE + 0)
44 #define WZRHPG300NH_GPIO_BTN_RESET (WZRHPG300NH_GPIO_EXP_BASE + 1)
45 #define WZRHPG300NH_GPIO_BTN_ROUTER_ON (WZRHPG300NH_GPIO_EXP_BASE + 2)
46 #define WZRHPG300NH_GPIO_BTN_QOS_ON (WZRHPG300NH_GPIO_EXP_BASE + 3)
47 #define WZRHPG300NH_GPIO_BTN_USB (WZRHPG300NH_GPIO_EXP_BASE + 5)
48 #define WZRHPG300NH_GPIO_BTN_ROUTER_AUTO (WZRHPG300NH_GPIO_EXP_BASE + 6)
49 #define WZRHPG300NH_GPIO_BTN_QOS_OFF (WZRHPG300NH_GPIO_EXP_BASE + 7)
50
51 #define WZRHPG300NH_BUTTONS_POLL_INTERVAL 20
52
53 #ifdef CONFIG_MTD_PARTITIONS
54 static struct mtd_partition wzrhpg300nh_flash_partitions[] = {
55 {
56 .name = "u-boot",
57 .offset = 0,
58 .size = 0x0040000,
59 .mask_flags = MTD_WRITEABLE,
60 }, {
61 .name = "u-boot-env",
62 .offset = 0x0040000,
63 .size = 0x0020000,
64 .mask_flags = MTD_WRITEABLE,
65 }, {
66 .name = "kernel",
67 .offset = 0x0060000,
68 .size = 0x0100000,
69 }, {
70 .name = "rootfs",
71 .offset = 0x0160000,
72 .size = 0x1e60000,
73 }, {
74 .name = "user_property",
75 .offset = 0x1fc0000,
76 .size = 0x0020000,
77 .mask_flags = MTD_WRITEABLE,
78 }, {
79 .name = "art",
80 .offset = 0x1fe0000,
81 .size = 0x0020000,
82 .mask_flags = MTD_WRITEABLE,
83 }, {
84 .name = "firmware",
85 .offset = 0x0060000,
86 .size = 0x1f60000,
87 }
88 };
89 #endif /* CONFIG_MTD_PARTITIONS */
90
91 static struct ar91xx_flash_platform_data wzrhpg300nh_flash_data = {
92 .width = 2,
93 #ifdef CONFIG_MTD_PARTITIONS
94 .parts = wzrhpg300nh_flash_partitions,
95 .nr_parts = ARRAY_SIZE(wzrhpg300nh_flash_partitions),
96 #endif
97 };
98
99 #define WZRHPG300NH_FLASH_BASE 0x1e000000
100 #define WZRHPG300NH_FLASH_SIZE (32 * 1024 * 1024)
101
102 static struct resource wzrhpg300nh_flash_resources[] = {
103 [0] = {
104 .start = WZRHPG300NH_FLASH_BASE,
105 .end = WZRHPG300NH_FLASH_BASE + WZRHPG300NH_FLASH_SIZE - 1,
106 .flags = IORESOURCE_MEM,
107 },
108 };
109
110 static struct platform_device wzrhpg300nh_flash_device = {
111 .name = "ar91xx-flash",
112 .id = -1,
113 .resource = wzrhpg300nh_flash_resources,
114 .num_resources = ARRAY_SIZE(wzrhpg300nh_flash_resources),
115 .dev = {
116 .platform_data = &wzrhpg300nh_flash_data,
117 }
118 };
119
120 static struct gpio_led wzrhpg300nh_leds_gpio[] __initdata = {
121 {
122 .name = "wzr-hp-g300nh:orange:security",
123 .gpio = WZRHPG300NH_GPIO_LED_SECURITY,
124 .active_low = 1,
125 }, {
126 .name = "wzr-hp-g300nh:green:wireless",
127 .gpio = WZRHPG300NH_GPIO_LED_WIRELESS,
128 .active_low = 1,
129 }, {
130 .name = "wzr-hp-g300nh:green:router",
131 .gpio = WZRHPG300NH_GPIO_LED_ROUTER,
132 .active_low = 1,
133 }, {
134 .name = "wzr-hp-g300nh:red:diag",
135 .gpio = WZRHPG300NH_GPIO_LED_DIAG,
136 .active_low = 1,
137 }, {
138 .name = "wzr-hp-g300nh:blue:usb",
139 .gpio = WZRHPG300NH_GPIO_LED_USB,
140 .active_low = 1,
141 }
142 };
143
144 static struct gpio_button wzrhpg300nh_gpio_buttons[] __initdata = {
145 {
146 .desc = "reset",
147 .type = EV_KEY,
148 .code = BTN_0,
149 .threshold = 3,
150 .gpio = WZRHPG300NH_GPIO_BTN_RESET,
151 .active_low = 1,
152 }, {
153 .desc = "aoss",
154 .type = EV_KEY,
155 .code = BTN_1,
156 .threshold = 3,
157 .gpio = WZRHPG300NH_GPIO_BTN_AOSS,
158 .active_low = 1,
159 }, {
160 .desc = "usb",
161 .type = EV_KEY,
162 .code = BTN_2,
163 .threshold = 3,
164 .gpio = WZRHPG300NH_GPIO_BTN_USB,
165 .active_low = 1,
166 }, {
167 .desc = "qos_on",
168 .type = EV_KEY,
169 .code = BTN_3,
170 .threshold = 3,
171 .gpio = WZRHPG300NH_GPIO_BTN_QOS_ON,
172 .active_low = 0,
173 }, {
174 .desc = "qos_off",
175 .type = EV_KEY,
176 .code = BTN_4,
177 .threshold = 3,
178 .gpio = WZRHPG300NH_GPIO_BTN_QOS_OFF,
179 .active_low = 0,
180 }, {
181 .desc = "router_on",
182 .type = EV_KEY,
183 .code = BTN_5,
184 .threshold = 3,
185 .gpio = WZRHPG300NH_GPIO_BTN_ROUTER_ON,
186 .active_low = 0,
187 }, {
188 .desc = "router_auto",
189 .type = EV_KEY,
190 .code = BTN_6,
191 .threshold = 3,
192 .gpio = WZRHPG300NH_GPIO_BTN_ROUTER_AUTO,
193 .active_low = 0,
194 }
195 };
196
197 static struct nxp_74hc153_platform_data wzrhpg300nh_74hc153_data = {
198 .gpio_base = WZRHPG300NH_GPIO_EXP_BASE,
199 .gpio_pin_s0 = WZRHPG300NH_GPIO_74HC153_S0,
200 .gpio_pin_s1 = WZRHPG300NH_GPIO_74HC153_S1,
201 .gpio_pin_1y = WZRHPG300NH_GPIO_74HC153_1Y,
202 .gpio_pin_2y = WZRHPG300NH_GPIO_74HC153_2Y,
203 };
204
205 static struct platform_device wzrhpg300nh_74hc153_device = {
206 .name = NXP_74HC153_DRIVER_NAME,
207 .id = -1,
208 .dev = {
209 .platform_data = &wzrhpg300nh_74hc153_data,
210 }
211 };
212
213 static struct rtl8366_smi_platform_data wzrhpg300nh_rtl8366_smi_data = {
214 .gpio_sda = WZRHPG300NH_GPIO_RTL8366_SDA,
215 .gpio_sck = WZRHPG300NH_GPIO_RTL8366_SCK,
216 };
217
218 static struct platform_device wzrhpg300nh_rtl8366_smi_device = {
219 .name = "rtl8366-smi",
220 .id = -1,
221 .dev = {
222 .platform_data = &wzrhpg300nh_rtl8366_smi_data,
223 }
224 };
225
226 static void __init wzrhpg300nh_setup(void)
227 {
228 u8 *eeprom = (u8 *) KSEG1ADDR(0x1fff1000);
229
230 ar71xx_set_mac_base(eeprom);
231
232 ar71xx_eth0_pll_data.pll_1000 = 0x1e000100;
233 ar71xx_eth0_data.mii_bus_dev = &wzrhpg300nh_rtl8366_smi_device.dev;
234 ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
235 ar71xx_eth0_data.phy_mask = 0xf;
236 ar71xx_eth0_data.speed = SPEED_1000;
237 ar71xx_eth0_data.duplex = DUPLEX_FULL;
238
239 ar71xx_eth1_pll_data.pll_1000 = 0x1e000100;
240 ar71xx_eth1_data.mii_bus_dev = &wzrhpg300nh_rtl8366_smi_device.dev;
241 ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
242 ar71xx_eth1_data.phy_mask = 0x10;
243
244 ar71xx_add_device_eth(0);
245 ar71xx_add_device_eth(1);
246
247 ar71xx_add_device_usb();
248 ar913x_add_device_wmac(eeprom, NULL);
249
250 platform_device_register(&wzrhpg300nh_74hc153_device);
251 platform_device_register(&wzrhpg300nh_flash_device);
252 platform_device_register(&wzrhpg300nh_rtl8366_smi_device);
253
254 ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(wzrhpg300nh_leds_gpio),
255 wzrhpg300nh_leds_gpio);
256
257 ar71xx_add_device_gpio_buttons(-1, WZRHPG300NH_BUTTONS_POLL_INTERVAL,
258 ARRAY_SIZE(wzrhpg300nh_gpio_buttons),
259 wzrhpg300nh_gpio_buttons);
260
261 }
262
263 MIPS_MACHINE(AR71XX_MACH_WZR_HP_G300NH, "WZR-HP-G300NH",
264 "Buffalo WZR-HP-G300NH", wzrhpg300nh_setup);