ar71xx: Buffalo WHR-HP-G300N kernel support
[openwrt/svn-archive/archive.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 }, {
53 .name = "kernel",
54 .offset = 0x040000,
55 .size = 0x0e0000,
56 }, {
57 .name = "rootfs",
58 .offset = 0x120000,
59 .size = 0x2c0000,
60 }, {
61 .name = "NVRAM",
62 .offset = 0x3e0000,
63 .size = 0x010000,
64 }, {
65 .name = "ART",
66 .offset = 0x3f0000,
67 .size = 0x010000,
68 .mask_flags = MTD_WRITEABLE,
69 }, {
70 .name = "firmware",
71 .offset = 0x040000,
72 .size = 0x3a0000,
73 }
74 };
75 #endif /* CONFIG_MTD_PARTITIONS */
76
77 static struct flash_platform_data whrhpg300n_flash_data = {
78 #ifdef CONFIG_MTD_PARTITIONS
79 .parts = whrhpg300n_partitions,
80 .nr_parts = ARRAY_SIZE(whrhpg300n_partitions),
81 #endif
82 };
83
84 static struct gpio_led whrhpg300n_leds_gpio[] __initdata = {
85 {
86 .name = "whr-hp-g300n:orange:security",
87 .gpio = WHRHPG300N_GPIO_LED_SECURITY,
88 .active_low = 1,
89 }, {
90 .name = "whr-hp-g300n:red:diag",
91 .gpio = WHRHPG300N_GPIO_LED_DIAG,
92 .active_low = 1,
93 }, {
94 .name = "whr-hp-g300n:green:router",
95 .gpio = WHRHPG300N_GPIO_LED_ROUTER,
96 .active_low = 1,
97 }
98 };
99
100 static struct gpio_keys_button whrhpg300n_gpio_keys[] __initdata = {
101 {
102 .desc = "reset",
103 .type = EV_KEY,
104 .code = KEY_RESTART,
105 .debounce_interval = WHRHPG300N_KEYS_DEBOUNCE_INTERVAL,
106 .gpio = WHRHPG300N_GPIO_BTN_RESET,
107 .active_low = 1,
108 }, {
109 .desc = "aoss/wps",
110 .type = EV_KEY,
111 .code = KEY_WPS_BUTTON,
112 .gpio = WHRHPG300N_GPIO_BTN_AOSS,
113 .debounce_interval = WHRHPG300N_KEYS_DEBOUNCE_INTERVAL,
114 .active_low = 1,
115 }, {
116 .desc = "router_on",
117 .type = EV_KEY,
118 .code = BTN_2,
119 .gpio = WHRHPG300N_GPIO_BTN_ROUTER_ON,
120 .debounce_interval = WHRHPG300N_KEYS_DEBOUNCE_INTERVAL,
121 .active_low = 1,
122 }, {
123 .desc = "router_auto",
124 .type = EV_KEY,
125 .code = BTN_3,
126 .gpio = WHRHPG300N_GPIO_BTN_ROUTER_AUTO,
127 .debounce_interval = WHRHPG300N_KEYS_DEBOUNCE_INTERVAL,
128 .active_low = 1,
129 }
130 };
131
132 static void __init whrhpg300n_setup(void)
133 {
134 u8 *ee = (u8 *) KSEG1ADDR(0x1fff1000);
135 u8 *mac = (u8 *) KSEG1ADDR(ee + WHRHPG300N_MAC_OFFSET);
136
137 ar71xx_add_device_m25p80(&whrhpg300n_flash_data);
138
139 ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(whrhpg300n_leds_gpio),
140 whrhpg300n_leds_gpio);
141
142 ar71xx_register_gpio_keys_polled(-1, WHRHPG300N_KEYS_POLL_INTERVAL,
143 ARRAY_SIZE(whrhpg300n_gpio_keys),
144 whrhpg300n_gpio_keys);
145
146 ar71xx_eth1_data.has_ar7240_switch = 1;
147 ar71xx_init_mac(ar71xx_eth0_data.mac_addr, mac, 0);
148 ar71xx_init_mac(ar71xx_eth1_data.mac_addr, mac, 1);
149
150 /* WAN port */
151 ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
152 ar71xx_eth0_data.speed = SPEED_100;
153 ar71xx_eth0_data.duplex = DUPLEX_FULL;
154 ar71xx_eth0_data.phy_mask = BIT(4);
155
156 /* LAN ports */
157 ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
158 ar71xx_eth1_data.speed = SPEED_1000;
159 ar71xx_eth1_data.duplex = DUPLEX_FULL;
160
161 ar71xx_add_device_mdio(0x0);
162 ar71xx_add_device_eth(1);
163 ar71xx_add_device_eth(0);
164
165 ap91_pci_setup_wmac_led_pin(1);
166
167 ap91_pci_init(ee, mac);
168 }
169
170 MIPS_MACHINE(AR71XX_MACH_WHR_HP_G300N, "WHR-HP-G300N", "Buffalo WHR-HP-G300N",
171 whrhpg300n_setup);