ar71xx: add latch_change field to rb750_led_platform_data
[openwrt.git] / target / linux / ar71xx / files / arch / mips / ath79 / mach-wzr-hp-g300nh.c
1 /*
2 * Buffalo WZR-HP-G300NH board support
3 *
4 * Copyright (C) 2010-2012 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/mtd/physmap.h>
15 #include <linux/nxp_74hc153.h>
16 #include <linux/rtl8366.h>
17
18 #include <asm/mach-ath79/ath79.h>
19
20 #include "dev-eth.h"
21 #include "dev-gpio-buttons.h"
22 #include "dev-leds-gpio.h"
23 #include "dev-usb.h"
24 #include "dev-wmac.h"
25 #include "machtypes.h"
26
27 #define WZRHPG300NH_GPIO_LED_USB 0
28 #define WZRHPG300NH_GPIO_LED_DIAG 1
29 #define WZRHPG300NH_GPIO_LED_WIRELESS 6
30 #define WZRHPG300NH_GPIO_LED_SECURITY 17
31 #define WZRHPG300NH_GPIO_LED_ROUTER 18
32
33 #define WZRHPG300NH_GPIO_RTL8366_SDA 19
34 #define WZRHPG300NH_GPIO_RTL8366_SCK 20
35
36 #define WZRHPG300NH_GPIO_74HC153_S0 9
37 #define WZRHPG300NH_GPIO_74HC153_S1 11
38 #define WZRHPG300NH_GPIO_74HC153_1Y 12
39 #define WZRHPG300NH_GPIO_74HC153_2Y 14
40
41 #define WZRHPG300NH_GPIO_EXP_BASE 32
42 #define WZRHPG300NH_GPIO_BTN_AOSS (WZRHPG300NH_GPIO_EXP_BASE + 0)
43 #define WZRHPG300NH_GPIO_BTN_RESET (WZRHPG300NH_GPIO_EXP_BASE + 1)
44 #define WZRHPG300NH_GPIO_BTN_ROUTER_ON (WZRHPG300NH_GPIO_EXP_BASE + 2)
45 #define WZRHPG300NH_GPIO_BTN_QOS_ON (WZRHPG300NH_GPIO_EXP_BASE + 3)
46 #define WZRHPG300NH_GPIO_BTN_USB (WZRHPG300NH_GPIO_EXP_BASE + 5)
47 #define WZRHPG300NH_GPIO_BTN_ROUTER_AUTO (WZRHPG300NH_GPIO_EXP_BASE + 6)
48 #define WZRHPG300NH_GPIO_BTN_QOS_OFF (WZRHPG300NH_GPIO_EXP_BASE + 7)
49
50 #define WZRHPG300NH_KEYS_POLL_INTERVAL 20 /* msecs */
51 #define WZRHPG300NH_KEYS_DEBOUNCE_INTERVAL (3 * WZRHPG300NH_KEYS_POLL_INTERVAL)
52
53 #define WZRHPG300NH_MAC_OFFSET 0x20c
54
55 static struct mtd_partition wzrhpg300nh_flash_partitions[] = {
56 {
57 .name = "u-boot",
58 .offset = 0,
59 .size = 0x0040000,
60 .mask_flags = MTD_WRITEABLE,
61 }, {
62 .name = "u-boot-env",
63 .offset = 0x0040000,
64 .size = 0x0020000,
65 .mask_flags = MTD_WRITEABLE,
66 }, {
67 .name = "kernel",
68 .offset = 0x0060000,
69 .size = 0x0100000,
70 }, {
71 .name = "rootfs",
72 .offset = 0x0160000,
73 .size = 0x1e60000,
74 }, {
75 .name = "user_property",
76 .offset = 0x1fc0000,
77 .size = 0x0020000,
78 .mask_flags = MTD_WRITEABLE,
79 }, {
80 .name = "art",
81 .offset = 0x1fe0000,
82 .size = 0x0020000,
83 .mask_flags = MTD_WRITEABLE,
84 }, {
85 .name = "firmware",
86 .offset = 0x0060000,
87 .size = 0x1f60000,
88 }
89 };
90
91 static struct physmap_flash_data wzrhpg300nh_flash_data = {
92 .width = 2,
93 .parts = wzrhpg300nh_flash_partitions,
94 .nr_parts = ARRAY_SIZE(wzrhpg300nh_flash_partitions),
95 };
96
97 #define WZRHPG300NH_FLASH_BASE 0x1e000000
98 #define WZRHPG300NH_FLASH_SIZE (32 * 1024 * 1024)
99
100 static struct resource wzrhpg300nh_flash_resources[] = {
101 [0] = {
102 .start = WZRHPG300NH_FLASH_BASE,
103 .end = WZRHPG300NH_FLASH_BASE + WZRHPG300NH_FLASH_SIZE - 1,
104 .flags = IORESOURCE_MEM,
105 },
106 };
107
108 static struct platform_device wzrhpg300nh_flash_device = {
109 .name = "physmap-flash",
110 .id = -1,
111 .resource = wzrhpg300nh_flash_resources,
112 .num_resources = ARRAY_SIZE(wzrhpg300nh_flash_resources),
113 .dev = {
114 .platform_data = &wzrhpg300nh_flash_data,
115 }
116 };
117
118 static struct gpio_led wzrhpg300nh_leds_gpio[] __initdata = {
119 {
120 .name = "buffalo:orange:security",
121 .gpio = WZRHPG300NH_GPIO_LED_SECURITY,
122 .active_low = 1,
123 }, {
124 .name = "buffalo:green:wireless",
125 .gpio = WZRHPG300NH_GPIO_LED_WIRELESS,
126 .active_low = 1,
127 }, {
128 .name = "buffalo:green:router",
129 .gpio = WZRHPG300NH_GPIO_LED_ROUTER,
130 .active_low = 1,
131 }, {
132 .name = "buffalo:red:diag",
133 .gpio = WZRHPG300NH_GPIO_LED_DIAG,
134 .active_low = 1,
135 }, {
136 .name = "buffalo:blue:usb",
137 .gpio = WZRHPG300NH_GPIO_LED_USB,
138 .active_low = 1,
139 }
140 };
141
142 static struct gpio_keys_button wzrhpg300nh_gpio_keys[] __initdata = {
143 {
144 .desc = "reset",
145 .type = EV_KEY,
146 .code = KEY_RESTART,
147 .debounce_interval = WZRHPG300NH_KEYS_DEBOUNCE_INTERVAL,
148 .gpio = WZRHPG300NH_GPIO_BTN_RESET,
149 .active_low = 1,
150 }, {
151 .desc = "aoss",
152 .type = EV_KEY,
153 .code = KEY_WPS_BUTTON,
154 .debounce_interval = WZRHPG300NH_KEYS_DEBOUNCE_INTERVAL,
155 .gpio = WZRHPG300NH_GPIO_BTN_AOSS,
156 .active_low = 1,
157 }, {
158 .desc = "usb",
159 .type = EV_KEY,
160 .code = BTN_2,
161 .debounce_interval = WZRHPG300NH_KEYS_DEBOUNCE_INTERVAL,
162 .gpio = WZRHPG300NH_GPIO_BTN_USB,
163 .active_low = 1,
164 }, {
165 .desc = "qos_on",
166 .type = EV_KEY,
167 .code = BTN_3,
168 .debounce_interval = WZRHPG300NH_KEYS_DEBOUNCE_INTERVAL,
169 .gpio = WZRHPG300NH_GPIO_BTN_QOS_ON,
170 .active_low = 0,
171 }, {
172 .desc = "qos_off",
173 .type = EV_KEY,
174 .code = BTN_4,
175 .debounce_interval = WZRHPG300NH_KEYS_DEBOUNCE_INTERVAL,
176 .gpio = WZRHPG300NH_GPIO_BTN_QOS_OFF,
177 .active_low = 0,
178 }, {
179 .desc = "router_on",
180 .type = EV_KEY,
181 .code = BTN_5,
182 .debounce_interval = WZRHPG300NH_KEYS_DEBOUNCE_INTERVAL,
183 .gpio = WZRHPG300NH_GPIO_BTN_ROUTER_ON,
184 .active_low = 0,
185 }, {
186 .desc = "router_auto",
187 .type = EV_KEY,
188 .code = BTN_6,
189 .debounce_interval = WZRHPG300NH_KEYS_DEBOUNCE_INTERVAL,
190 .gpio = WZRHPG300NH_GPIO_BTN_ROUTER_AUTO,
191 .active_low = 0,
192 }
193 };
194
195 static struct nxp_74hc153_platform_data wzrhpg300nh_74hc153_data = {
196 .gpio_base = WZRHPG300NH_GPIO_EXP_BASE,
197 .gpio_pin_s0 = WZRHPG300NH_GPIO_74HC153_S0,
198 .gpio_pin_s1 = WZRHPG300NH_GPIO_74HC153_S1,
199 .gpio_pin_1y = WZRHPG300NH_GPIO_74HC153_1Y,
200 .gpio_pin_2y = WZRHPG300NH_GPIO_74HC153_2Y,
201 };
202
203 static struct platform_device wzrhpg300nh_74hc153_device = {
204 .name = NXP_74HC153_DRIVER_NAME,
205 .id = -1,
206 .dev = {
207 .platform_data = &wzrhpg300nh_74hc153_data,
208 }
209 };
210
211 static struct rtl8366_platform_data wzrhpg300nh_rtl8366_data = {
212 .gpio_sda = WZRHPG300NH_GPIO_RTL8366_SDA,
213 .gpio_sck = WZRHPG300NH_GPIO_RTL8366_SCK,
214 };
215
216 static struct platform_device wzrhpg300nh_rtl8366s_device = {
217 .name = RTL8366S_DRIVER_NAME,
218 .id = -1,
219 .dev = {
220 .platform_data = &wzrhpg300nh_rtl8366_data,
221 }
222 };
223
224 static struct platform_device wzrhpg300nh_rtl8366rb_device = {
225 .name = RTL8366RB_DRIVER_NAME,
226 .id = -1,
227 .dev = {
228 .platform_data = &wzrhpg300nh_rtl8366_data,
229 }
230 };
231
232 static void __init wzrhpg300nh_setup(void)
233 {
234 u8 *eeprom = (u8 *) KSEG1ADDR(0x1fff1000);
235 u8 *mac = eeprom + WZRHPG300NH_MAC_OFFSET;
236 bool hasrtl8366rb = false;
237
238 ath79_init_mac(ath79_eth0_data.mac_addr, mac, 0);
239 ath79_init_mac(ath79_eth1_data.mac_addr, mac, 1);
240
241 if (rtl8366_smi_detect(&wzrhpg300nh_rtl8366_data) == RTL8366_TYPE_RB)
242 hasrtl8366rb = true;
243
244 if (hasrtl8366rb) {
245 ath79_eth0_pll_data.pll_1000 = 0x1f000000;
246 ath79_eth0_data.mii_bus_dev = &wzrhpg300nh_rtl8366rb_device.dev;
247 ath79_eth1_pll_data.pll_1000 = 0x100;
248 ath79_eth1_data.mii_bus_dev = &wzrhpg300nh_rtl8366rb_device.dev;
249 } else {
250 ath79_eth0_pll_data.pll_1000 = 0x1e000100;
251 ath79_eth0_data.mii_bus_dev = &wzrhpg300nh_rtl8366s_device.dev;
252 ath79_eth1_pll_data.pll_1000 = 0x1e000100;
253 ath79_eth1_data.mii_bus_dev = &wzrhpg300nh_rtl8366s_device.dev;
254 }
255
256 ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
257 ath79_eth0_data.speed = SPEED_1000;
258 ath79_eth0_data.duplex = DUPLEX_FULL;
259
260 ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
261 ath79_eth1_data.phy_mask = 0x10;
262
263 ath79_register_eth(0);
264 ath79_register_eth(1);
265
266 ath79_register_usb();
267 ath79_register_wmac(eeprom, NULL);
268
269 platform_device_register(&wzrhpg300nh_74hc153_device);
270 platform_device_register(&wzrhpg300nh_flash_device);
271
272 if (hasrtl8366rb)
273 platform_device_register(&wzrhpg300nh_rtl8366rb_device);
274 else
275 platform_device_register(&wzrhpg300nh_rtl8366s_device);
276
277 ath79_register_leds_gpio(-1, ARRAY_SIZE(wzrhpg300nh_leds_gpio),
278 wzrhpg300nh_leds_gpio);
279
280 ath79_register_gpio_keys_polled(-1, WZRHPG300NH_KEYS_POLL_INTERVAL,
281 ARRAY_SIZE(wzrhpg300nh_gpio_keys),
282 wzrhpg300nh_gpio_keys);
283
284 }
285
286 MIPS_MACHINE(ATH79_MACH_WZR_HP_G300NH, "WZR-HP-G300NH",
287 "Buffalo WZR-HP-G300NH", wzrhpg300nh_setup);
This page took 0.059726 seconds and 5 git commands to generate.