ar71xx: merge files-3.2 to files
[openwrt/openwrt.git] / target / linux / ar71xx / files / arch / mips / ath79 / mach-wzr-hp-ag300h.c
1 /*
2 * Buffalo WZR-HP-AG300H board support
3 *
4 * Copyright (C) 2011 Felix Fietkau <nbd@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/gpio.h>
12 #include <linux/mtd/mtd.h>
13 #include <linux/mtd/partitions.h>
14
15 #include <asm/mach-ath79/ath79.h>
16
17 #include "dev-eth.h"
18 #include "dev-ap9x-pci.h"
19 #include "dev-gpio-buttons.h"
20 #include "dev-leds-gpio.h"
21 #include "dev-m25p80.h"
22 #include "dev-usb.h"
23 #include "machtypes.h"
24
25 #define WZRHPAG300H_MAC_OFFSET 0x20c
26 #define WZRHPAG300H_KEYS_POLL_INTERVAL 20 /* msecs */
27 #define WZRHPAG300H_KEYS_DEBOUNCE_INTERVAL (3 * WZRHPAG300H_KEYS_POLL_INTERVAL)
28
29 static struct mtd_partition wzrhpag300h_flash_partitions[] = {
30 {
31 .name = "u-boot",
32 .offset = 0,
33 .size = 0x0040000,
34 .mask_flags = MTD_WRITEABLE,
35 }, {
36 .name = "u-boot-env",
37 .offset = 0x0040000,
38 .size = 0x0010000,
39 .mask_flags = MTD_WRITEABLE,
40 }, {
41 .name = "art",
42 .offset = 0x0050000,
43 .size = 0x0010000,
44 .mask_flags = MTD_WRITEABLE,
45 }, {
46 .name = "kernel",
47 .offset = 0x0060000,
48 .size = 0x0100000,
49 }, {
50 .name = "rootfs",
51 .offset = 0x0160000,
52 .size = 0x1e90000,
53 }, {
54 .name = "user_property",
55 .offset = 0x1ff0000,
56 .size = 0x0010000,
57 .mask_flags = MTD_WRITEABLE,
58 }, {
59 .name = "firmware",
60 .offset = 0x0060000,
61 .size = 0x1f90000,
62 }
63 };
64
65 static struct flash_platform_data wzrhpag300h_flash_data = {
66 .parts = wzrhpag300h_flash_partitions,
67 .nr_parts = ARRAY_SIZE(wzrhpag300h_flash_partitions),
68 };
69
70 static struct gpio_led wzrhpag300h_leds_gpio[] __initdata = {
71 {
72 .name = "buffalo:red:diag",
73 .gpio = 1,
74 .active_low = 1,
75 },
76 };
77
78 static struct gpio_keys_button wzrhpag300h_gpio_keys[] __initdata = {
79 {
80 .desc = "reset",
81 .type = EV_KEY,
82 .code = KEY_RESTART,
83 .debounce_interval = WZRHPAG300H_KEYS_DEBOUNCE_INTERVAL,
84 .gpio = 11,
85 .active_low = 1,
86 }, {
87 .desc = "usb",
88 .type = EV_KEY,
89 .code = BTN_2,
90 .debounce_interval = WZRHPAG300H_KEYS_DEBOUNCE_INTERVAL,
91 .gpio = 3,
92 .active_low = 1,
93 }, {
94 .desc = "aoss",
95 .type = EV_KEY,
96 .code = KEY_WPS_BUTTON,
97 .debounce_interval = WZRHPAG300H_KEYS_DEBOUNCE_INTERVAL,
98 .gpio = 5,
99 .active_low = 1,
100 }, {
101 .desc = "router_auto",
102 .type = EV_KEY,
103 .code = BTN_6,
104 .debounce_interval = WZRHPAG300H_KEYS_DEBOUNCE_INTERVAL,
105 .gpio = 6,
106 .active_low = 1,
107 }, {
108 .desc = "router_off",
109 .type = EV_KEY,
110 .code = BTN_5,
111 .debounce_interval = WZRHPAG300H_KEYS_DEBOUNCE_INTERVAL,
112 .gpio = 7,
113 .active_low = 1,
114 }
115 };
116
117 static void __init wzrhpag300h_setup(void)
118 {
119 u8 *eeprom1 = (u8 *) KSEG1ADDR(0x1f051000);
120 u8 *eeprom2 = (u8 *) KSEG1ADDR(0x1f055000);
121 u8 *mac1 = eeprom1 + WZRHPAG300H_MAC_OFFSET;
122 u8 *mac2 = eeprom2 + WZRHPAG300H_MAC_OFFSET;
123
124 ath79_init_mac(ath79_eth0_data.mac_addr, mac1, 0);
125 ath79_init_mac(ath79_eth1_data.mac_addr, mac2, 1);
126
127 ath79_register_mdio(0, ~(BIT(0) | BIT(4)));
128
129 ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
130 ath79_eth0_data.speed = SPEED_1000;
131 ath79_eth0_data.duplex = DUPLEX_FULL;
132 ath79_eth0_data.phy_mask = BIT(0);
133
134 ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
135 ath79_eth1_data.phy_mask = BIT(4);
136
137 ath79_register_eth(0);
138 ath79_register_eth(1);
139
140 ath79_register_usb();
141 gpio_request(2, "usb");
142 gpio_direction_output(2, 1);
143
144 ath79_register_leds_gpio(-1, ARRAY_SIZE(wzrhpag300h_leds_gpio),
145 wzrhpag300h_leds_gpio);
146
147 ath79_register_gpio_keys_polled(-1, WZRHPAG300H_KEYS_POLL_INTERVAL,
148 ARRAY_SIZE(wzrhpag300h_gpio_keys),
149 wzrhpag300h_gpio_keys);
150
151 ath79_register_m25p80_multi(&wzrhpag300h_flash_data);
152
153 ap94_pci_init(eeprom1, mac1, eeprom2, mac2);
154 }
155
156 MIPS_MACHINE(ATH79_MACH_WZR_HP_AG300H, "WZR-HP-AG300H",
157 "Buffalo WZR-HP-AG300H", wzrhpag300h_setup);
158