ar71xx: use the tp-link parser on the tp-link boards
[openwrt.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.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-ar9xxx-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_KEYS_POLL_INTERVAL  20      /* msecs */
52 #define WZRHPG300NH_KEYS_DEBOUNCE_INTERVAL (3 * WZRHPG300NH_KEYS_POLL_INTERVAL)
53
54 #define WZRHPG300NH_MAC_OFFSET          0x20c
55
56 #ifdef CONFIG_MTD_PARTITIONS
57 static struct mtd_partition wzrhpg300nh_flash_partitions[] = {
58         {
59                 .name           = "u-boot",
60                 .offset         = 0,
61                 .size           = 0x0040000,
62                 .mask_flags     = MTD_WRITEABLE,
63         }, {
64                 .name           = "u-boot-env",
65                 .offset         = 0x0040000,
66                 .size           = 0x0020000,
67                 .mask_flags     = MTD_WRITEABLE,
68         }, {
69                 .name           = "kernel",
70                 .offset         = 0x0060000,
71                 .size           = 0x0100000,
72         }, {
73                 .name           = "rootfs",
74                 .offset         = 0x0160000,
75                 .size           = 0x1e60000,
76         }, {
77                 .name           = "user_property",
78                 .offset         = 0x1fc0000,
79                 .size           = 0x0020000,
80                 .mask_flags     = MTD_WRITEABLE,
81         }, {
82                 .name           = "art",
83                 .offset         = 0x1fe0000,
84                 .size           = 0x0020000,
85                 .mask_flags     = MTD_WRITEABLE,
86         }, {
87                 .name           = "firmware",
88                 .offset         = 0x0060000,
89                 .size           = 0x1f60000,
90         }
91 };
92 #endif /* CONFIG_MTD_PARTITIONS */
93
94 static struct ar91xx_flash_platform_data wzrhpg300nh_flash_data = {
95         .width          = 2,
96 #ifdef CONFIG_MTD_PARTITIONS
97         .parts          = wzrhpg300nh_flash_partitions,
98         .nr_parts       = ARRAY_SIZE(wzrhpg300nh_flash_partitions),
99 #endif
100 };
101
102 #define WZRHPG300NH_FLASH_BASE  0x1e000000
103 #define WZRHPG300NH_FLASH_SIZE  (32 * 1024 * 1024)
104
105 static struct resource wzrhpg300nh_flash_resources[] = {
106         [0] = {
107                 .start  = WZRHPG300NH_FLASH_BASE,
108                 .end    = WZRHPG300NH_FLASH_BASE + WZRHPG300NH_FLASH_SIZE - 1,
109                 .flags  = IORESOURCE_MEM,
110         },
111 };
112
113 static struct platform_device wzrhpg300nh_flash_device = {
114         .name           = "ar91xx-flash",
115         .id             = -1,
116         .resource       = wzrhpg300nh_flash_resources,
117         .num_resources  = ARRAY_SIZE(wzrhpg300nh_flash_resources),
118         .dev            = {
119                 .platform_data = &wzrhpg300nh_flash_data,
120         }
121 };
122
123 static struct gpio_led wzrhpg300nh_leds_gpio[] __initdata = {
124         {
125                 .name           = "buffalo:orange:security",
126                 .gpio           = WZRHPG300NH_GPIO_LED_SECURITY,
127                 .active_low     = 1,
128         }, {
129                 .name           = "buffalo:green:wireless",
130                 .gpio           = WZRHPG300NH_GPIO_LED_WIRELESS,
131                 .active_low     = 1,
132         }, {
133                 .name           = "buffalo:green:router",
134                 .gpio           = WZRHPG300NH_GPIO_LED_ROUTER,
135                 .active_low     = 1,
136         }, {
137                 .name           = "buffalo:red:diag",
138                 .gpio           = WZRHPG300NH_GPIO_LED_DIAG,
139                 .active_low     = 1,
140         }, {
141                 .name           = "buffalo:blue:usb",
142                 .gpio           = WZRHPG300NH_GPIO_LED_USB,
143                 .active_low     = 1,
144         }
145 };
146
147 static struct gpio_keys_button wzrhpg300nh_gpio_keys[] __initdata = {
148         {
149                 .desc           = "reset",
150                 .type           = EV_KEY,
151                 .code           = KEY_RESTART,
152                 .debounce_interval = WZRHPG300NH_KEYS_DEBOUNCE_INTERVAL,
153                 .gpio           = WZRHPG300NH_GPIO_BTN_RESET,
154                 .active_low     = 1,
155         }, {
156                 .desc           = "aoss",
157                 .type           = EV_KEY,
158                 .code           = KEY_WPS_BUTTON,
159                 .debounce_interval = WZRHPG300NH_KEYS_DEBOUNCE_INTERVAL,
160                 .gpio           = WZRHPG300NH_GPIO_BTN_AOSS,
161                 .active_low     = 1,
162         }, {
163                 .desc           = "usb",
164                 .type           = EV_KEY,
165                 .code           = BTN_2,
166                 .debounce_interval = WZRHPG300NH_KEYS_DEBOUNCE_INTERVAL,
167                 .gpio           = WZRHPG300NH_GPIO_BTN_USB,
168                 .active_low     = 1,
169         }, {
170                 .desc           = "qos_on",
171                 .type           = EV_KEY,
172                 .code           = BTN_3,
173                 .debounce_interval = WZRHPG300NH_KEYS_DEBOUNCE_INTERVAL,
174                 .gpio           = WZRHPG300NH_GPIO_BTN_QOS_ON,
175                 .active_low     = 0,
176         }, {
177                 .desc           = "qos_off",
178                 .type           = EV_KEY,
179                 .code           = BTN_4,
180                 .debounce_interval = WZRHPG300NH_KEYS_DEBOUNCE_INTERVAL,
181                 .gpio           = WZRHPG300NH_GPIO_BTN_QOS_OFF,
182                 .active_low     = 0,
183         }, {
184                 .desc           = "router_on",
185                 .type           = EV_KEY,
186                 .code           = BTN_5,
187                 .debounce_interval = WZRHPG300NH_KEYS_DEBOUNCE_INTERVAL,
188                 .gpio           = WZRHPG300NH_GPIO_BTN_ROUTER_ON,
189                 .active_low     = 0,
190         }, {
191                 .desc           = "router_auto",
192                 .type           = EV_KEY,
193                 .code           = BTN_6,
194                 .debounce_interval = WZRHPG300NH_KEYS_DEBOUNCE_INTERVAL,
195                 .gpio           = WZRHPG300NH_GPIO_BTN_ROUTER_AUTO,
196                 .active_low     = 0,
197         }
198 };
199
200 static struct nxp_74hc153_platform_data wzrhpg300nh_74hc153_data = {
201         .gpio_base      = WZRHPG300NH_GPIO_EXP_BASE,
202         .gpio_pin_s0    = WZRHPG300NH_GPIO_74HC153_S0,
203         .gpio_pin_s1    = WZRHPG300NH_GPIO_74HC153_S1,
204         .gpio_pin_1y    = WZRHPG300NH_GPIO_74HC153_1Y,
205         .gpio_pin_2y    = WZRHPG300NH_GPIO_74HC153_2Y,
206 };
207
208 static struct platform_device wzrhpg300nh_74hc153_device = {
209         .name           = NXP_74HC153_DRIVER_NAME,
210         .id             = -1,
211         .dev = {
212                 .platform_data  = &wzrhpg300nh_74hc153_data,
213         }
214 };
215
216 static struct rtl8366_platform_data wzrhpg300nh_rtl8366_data = {
217         .gpio_sda       = WZRHPG300NH_GPIO_RTL8366_SDA,
218         .gpio_sck       = WZRHPG300NH_GPIO_RTL8366_SCK,
219 };
220
221 static struct platform_device wzrhpg300nh_rtl8366s_device = {
222         .name           = RTL8366S_DRIVER_NAME,
223         .id             = -1,
224         .dev = {
225                 .platform_data  = &wzrhpg300nh_rtl8366_data,
226         }
227 };
228
229 static struct platform_device wzrhpg300nh_rtl8366rb_device = {
230         .name           = RTL8366RB_DRIVER_NAME,
231         .id             = -1,
232         .dev = {
233                 .platform_data  = &wzrhpg300nh_rtl8366_data,
234         }
235 };
236
237 static void __init wzrhpg300nh_setup(void)
238 {
239         u8 *eeprom = (u8 *) KSEG1ADDR(0x1fff1000);
240         u8 *mac = eeprom + WZRHPG300NH_MAC_OFFSET;
241         bool hasrtl8366rb = false;
242
243         ar71xx_init_mac(ar71xx_eth0_data.mac_addr, mac, 0);
244         ar71xx_init_mac(ar71xx_eth1_data.mac_addr, mac, 1);
245
246         if (rtl8366_smi_detect(&wzrhpg300nh_rtl8366_data) == RTL8366_TYPE_RB)
247                 hasrtl8366rb = true;
248
249         if (hasrtl8366rb) {
250                 ar71xx_eth0_pll_data.pll_1000 = 0x1f000000;
251                 ar71xx_eth0_data.mii_bus_dev = &wzrhpg300nh_rtl8366rb_device.dev;
252                 ar71xx_eth1_pll_data.pll_1000 = 0x100;
253                 ar71xx_eth1_data.mii_bus_dev = &wzrhpg300nh_rtl8366rb_device.dev;
254         } else {
255                 ar71xx_eth0_pll_data.pll_1000 = 0x1e000100;
256                 ar71xx_eth0_data.mii_bus_dev = &wzrhpg300nh_rtl8366s_device.dev;
257                 ar71xx_eth1_pll_data.pll_1000 = 0x1e000100;
258                 ar71xx_eth1_data.mii_bus_dev = &wzrhpg300nh_rtl8366s_device.dev;
259         }
260
261         ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
262         ar71xx_eth0_data.speed = SPEED_1000;
263         ar71xx_eth0_data.duplex = DUPLEX_FULL;
264
265         ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
266         ar71xx_eth1_data.phy_mask = 0x10;
267
268         ar71xx_add_device_eth(0);
269         ar71xx_add_device_eth(1);
270
271         ar71xx_add_device_usb();
272         ar9xxx_add_device_wmac(eeprom, NULL);
273
274         platform_device_register(&wzrhpg300nh_74hc153_device);
275         platform_device_register(&wzrhpg300nh_flash_device);
276
277         if (hasrtl8366rb)
278                 platform_device_register(&wzrhpg300nh_rtl8366rb_device);
279         else
280                 platform_device_register(&wzrhpg300nh_rtl8366s_device);
281
282         ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(wzrhpg300nh_leds_gpio),
283                                         wzrhpg300nh_leds_gpio);
284
285         ar71xx_register_gpio_keys_polled(-1, WZRHPG300NH_KEYS_POLL_INTERVAL,
286                                          ARRAY_SIZE(wzrhpg300nh_gpio_keys),
287                                          wzrhpg300nh_gpio_keys);
288
289 }
290
291 MIPS_MACHINE(AR71XX_MACH_WZR_HP_G300NH, "WZR-HP-G300NH",
292              "Buffalo WZR-HP-G300NH", wzrhpg300nh_setup);