ar71xx: add support for the wzr-hp-g300nh2
[openwrt/openwrt.git] / target / linux / ar71xx / files / arch / mips / ar71xx / mach-whr-hp-g300n.c
1 /*
2 * Buffalo WHR-HP-G300N board support
3 *
4 * based on ...
5 *
6 * TP-LINK TL-WR741ND board support
7 *
8 * Copyright (C) 2009-2010 Gabor Juhos <juhosg@openwrt.org>
9 *
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License version 2 as published
12 * by the Free Software Foundation.
13 */
14
15 #include <linux/mtd/mtd.h>
16 #include <linux/mtd/partitions.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-ap91-pci.h"
24 #include "dev-gpio-buttons.h"
25 #include "dev-leds-gpio.h"
26
27 #define WHRHPG300N_GPIO_LED_SECURITY 0
28 #define WHRHPG300N_GPIO_LED_DIAG 1
29 #define WHRHPG300N_GPIO_LED_ROUTER 6
30
31 #define WHRHPG300N_GPIO_BTN_ROUTER_ON 7
32 #define WHRHPG300N_GPIO_BTN_ROUTER_AUTO 8
33 #define WHRHPG300N_GPIO_BTN_RESET 11
34 #define WHRHPG300N_GPIO_BTN_AOSS 12
35
36 #define WHRHPG300N_KEYS_POLL_INTERVAL 20 /* msecs */
37 #define WHRHPG300N_KEYS_DEBOUNCE_INTERVAL (3 * WHRHPG300N_KEYS_POLL_INTERVAL)
38
39 #define WHRHPG300N_MAC_OFFSET 0x20c
40
41 #ifdef CONFIG_MTD_PARTITIONS
42 static struct mtd_partition whrhpg300n_partitions[] = {
43 {
44 .name = "u-boot",
45 .offset = 0,
46 .size = 0x03e000,
47 .mask_flags = MTD_WRITEABLE,
48 }, {
49 .name = "u-boot-env",
50 .offset = 0x03e000,
51 .size = 0x002000,
52 .mask_flags = MTD_WRITEABLE,
53 }, {
54 .name = "kernel",
55 .offset = 0x040000,
56 .size = 0x0e0000,
57 }, {
58 .name = "rootfs",
59 .offset = 0x120000,
60 .size = 0x2c0000,
61 }, {
62 .name = "user_property",
63 .offset = 0x3e0000,
64 .size = 0x010000,
65 }, {
66 .name = "ART",
67 .offset = 0x3f0000,
68 .size = 0x010000,
69 .mask_flags = MTD_WRITEABLE,
70 }, {
71 .name = "firmware",
72 .offset = 0x040000,
73 .size = 0x3a0000,
74 }
75 };
76 #endif /* CONFIG_MTD_PARTITIONS */
77
78 static struct flash_platform_data whrhpg300n_flash_data = {
79 #ifdef CONFIG_MTD_PARTITIONS
80 .parts = whrhpg300n_partitions,
81 .nr_parts = ARRAY_SIZE(whrhpg300n_partitions),
82 #endif
83 };
84
85 static struct gpio_led whrhpg300n_leds_gpio[] __initdata = {
86 {
87 .name = "buffalo:orange:security",
88 .gpio = WHRHPG300N_GPIO_LED_SECURITY,
89 .active_low = 1,
90 }, {
91 .name = "buffalo:red:diag",
92 .gpio = WHRHPG300N_GPIO_LED_DIAG,
93 .active_low = 1,
94 }, {
95 .name = "buffalo:green:router",
96 .gpio = WHRHPG300N_GPIO_LED_ROUTER,
97 .active_low = 1,
98 }
99 };
100
101 static struct gpio_keys_button whrhpg300n_gpio_keys[] __initdata = {
102 {
103 .desc = "reset",
104 .type = EV_KEY,
105 .code = KEY_RESTART,
106 .debounce_interval = WHRHPG300N_KEYS_DEBOUNCE_INTERVAL,
107 .gpio = WHRHPG300N_GPIO_BTN_RESET,
108 .active_low = 1,
109 }, {
110 .desc = "aoss/wps",
111 .type = EV_KEY,
112 .code = KEY_WPS_BUTTON,
113 .gpio = WHRHPG300N_GPIO_BTN_AOSS,
114 .debounce_interval = WHRHPG300N_KEYS_DEBOUNCE_INTERVAL,
115 .active_low = 1,
116 }, {
117 .desc = "router_on",
118 .type = EV_KEY,
119 .code = BTN_2,
120 .gpio = WHRHPG300N_GPIO_BTN_ROUTER_ON,
121 .debounce_interval = WHRHPG300N_KEYS_DEBOUNCE_INTERVAL,
122 .active_low = 1,
123 }, {
124 .desc = "router_auto",
125 .type = EV_KEY,
126 .code = BTN_3,
127 .gpio = WHRHPG300N_GPIO_BTN_ROUTER_AUTO,
128 .debounce_interval = WHRHPG300N_KEYS_DEBOUNCE_INTERVAL,
129 .active_low = 1,
130 }
131 };
132
133 static void __init whrhpg300n_setup(void)
134 {
135 u8 *ee = (u8 *) KSEG1ADDR(0x1fff1000);
136 u8 *mac = (u8 *) KSEG1ADDR(ee + WHRHPG300N_MAC_OFFSET);
137
138 ar71xx_add_device_m25p80(&whrhpg300n_flash_data);
139
140 ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(whrhpg300n_leds_gpio),
141 whrhpg300n_leds_gpio);
142
143 ar71xx_register_gpio_keys_polled(-1, WHRHPG300N_KEYS_POLL_INTERVAL,
144 ARRAY_SIZE(whrhpg300n_gpio_keys),
145 whrhpg300n_gpio_keys);
146
147 ar71xx_init_mac(ar71xx_eth0_data.mac_addr, mac, 0);
148 ar71xx_init_mac(ar71xx_eth1_data.mac_addr, mac, 1);
149
150 ar71xx_add_device_mdio(0, 0x0);
151
152 /* LAN ports */
153 ar71xx_add_device_eth(1);
154 /* WAN port */
155 ar71xx_add_device_eth(0);
156
157 ap91_pci_setup_wmac_led_pin(1);
158
159 ap91_pci_init(ee, mac);
160 }
161
162 MIPS_MACHINE(AR71XX_MACH_WHR_HP_G300N, "WHR-HP-G300N", "Buffalo WHR-HP-G300N",
163 whrhpg300n_setup);
164
165 MIPS_MACHINE(AR71XX_MACH_WHR_G301N, "WHR-G301N", "Buffalo WHR-G301N",
166 whrhpg300n_setup);
167
168 MIPS_MACHINE(AR71XX_MACH_WHR_HP_GN, "WHR-HP-GN", "Buffalo WHR-HP-GN",
169 whrhpg300n_setup);