Rebased from upstream / out of band repository.
[librecmc/librecmc.git] / target / linux / ar71xx / files / arch / mips / ath79 / mach-wzr-hp-g300nh2.c
1 /*
2  *  Buffalo WZR-HP-G300NH2 board support
3  *
4  *  Copyright (C) 2011 Felix Fietkau <nbd@nbd.name>
5  *  Copyright (C) 2011 Mark Deneen <mdeneen@gmail.com>
6  *
7  *  This program is free software; you can redistribute it and/or modify it
8  *  under the terms of the GNU General Public License version 2 as published
9  *  by the Free Software Foundation.
10  */
11
12 #include <linux/gpio.h>
13 #include <linux/mtd/mtd.h>
14 #include <linux/mtd/partitions.h>
15
16 #include <asm/mach-ath79/ath79.h>
17
18 #include "dev-ap9x-pci.h"
19 #include "dev-eth.h"
20 #include "dev-gpio-buttons.h"
21 #include "dev-leds-gpio.h"
22 #include "dev-m25p80.h"
23 #include "dev-usb.h"
24 #include "machtypes.h"
25
26 #define WZRHPG300NH2_MAC_OFFSET         0x20c
27 #define WZRHPG300NH2_KEYS_POLL_INTERVAL     20      /* msecs */
28 #define WZRHPG300NH2_KEYS_DEBOUNCE_INTERVAL (3 * WZRHPG300NH2_KEYS_POLL_INTERVAL)
29
30 static struct mtd_partition wzrhpg300nh2_flash_partitions[] = {
31         {
32                 .name           = "u-boot",
33                 .offset         = 0,
34                 .size           = 0x0040000,
35                 .mask_flags     = MTD_WRITEABLE,
36         }, {
37                 .name           = "u-boot-env",
38                 .offset         = 0x0040000,
39                 .size           = 0x0010000,
40                 .mask_flags     = MTD_WRITEABLE,
41         }, {
42                 .name           = "art",
43                 .offset         = 0x0050000,
44                 .size           = 0x0010000,
45                 .mask_flags     = MTD_WRITEABLE,
46         }, {
47                 .name           = "firmware",
48                 .offset         = 0x0060000,
49                 .size           = 0x1f90000,
50         }, {
51                 .name           = "user_property",
52                 .offset         = 0x1ff0000,
53                 .size           = 0x0010000,
54                 .mask_flags     = MTD_WRITEABLE,
55         }
56 };
57
58 static struct flash_platform_data wzrhpg300nh2_flash_data = {
59         .parts          = wzrhpg300nh2_flash_partitions,
60         .nr_parts       = ARRAY_SIZE(wzrhpg300nh2_flash_partitions),
61 };
62
63 static struct gpio_led wzrhpg300nh2_leds_gpio[] __initdata = {
64         {
65                 .name           = "buffalo:red:diag",
66                 .gpio           = 16,
67                 .active_low     = 1,
68         },
69 };
70
71 static struct gpio_led wzrhpg300nh2_wmac_leds_gpio[] = {
72         {
73                 .name           = "buffalo:blue:usb",
74                 .gpio           = 4,
75                 .active_low     = 1,
76         },
77         {
78                 .name           = "buffalo:green:wireless",
79                 .gpio           = 5,
80                 .active_low     = 1,
81         },
82         {
83                 .name           = "buffalo:orange:security",
84                 .gpio           = 6,
85                 .active_low     = 1,
86         },
87         {
88                 .name           = "buffalo:green:router",
89                 .gpio           = 7,
90                 .active_low     = 1,
91         },
92         {
93                 .name           = "buffalo:blue:movie_engine_on",
94                 .gpio           = 8,
95                 .active_low     = 1,
96         },
97         {
98                 .name           = "buffalo:blue:movie_engine_off",
99                 .gpio           = 9,
100                 .active_low     = 1,
101         },
102 };
103
104 /* The AOSS button is wmac gpio 12 */
105 static struct gpio_keys_button wzrhpg300nh2_gpio_keys[] __initdata = {
106         {
107                 .desc           = "reset",
108                 .type           = EV_KEY,
109                 .code           = KEY_RESTART,
110                 .debounce_interval = WZRHPG300NH2_KEYS_DEBOUNCE_INTERVAL,
111                 .gpio           = 1,
112                 .active_low     = 1,
113         }, {
114                 .desc           = "usb",
115                 .type           = EV_KEY,
116                 .code           = BTN_2,
117                 .debounce_interval = WZRHPG300NH2_KEYS_DEBOUNCE_INTERVAL,
118                 .gpio           = 7,
119                 .active_low     = 1,
120         }, {
121                 .desc           = "qos",
122                 .type           = EV_KEY,
123                 .code           = BTN_3,
124                 .debounce_interval = WZRHPG300NH2_KEYS_DEBOUNCE_INTERVAL,
125                 .gpio           = 11,
126                 .active_low     = 0,
127         }, {
128                 .desc           = "router_on",
129                 .type           = EV_KEY,
130                 .code           = BTN_5,
131                 .debounce_interval = WZRHPG300NH2_KEYS_DEBOUNCE_INTERVAL,
132                 .gpio           = 8,
133                 .active_low     = 0,
134         },
135 };
136
137 static void __init wzrhpg300nh2_setup(void)
138 {
139
140         u8 *eeprom = (u8 *)   KSEG1ADDR(0x1f051000);
141         u8 *mac0   = eeprom + WZRHPG300NH2_MAC_OFFSET;
142         /* There is an eth1 but it is not connected to the switch */
143
144         ath79_register_m25p80_multi(&wzrhpg300nh2_flash_data);
145
146         ath79_init_mac(ath79_eth0_data.mac_addr, mac0, 0);
147         ath79_register_mdio(0, ~(BIT(0)));
148
149         ath79_init_mac(ath79_eth0_data.mac_addr, mac0, 0);
150         ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
151         ath79_eth0_data.speed = SPEED_1000;
152         ath79_eth0_data.duplex = DUPLEX_FULL;
153         ath79_eth0_data.phy_mask = BIT(0);
154
155         ath79_register_eth(0);
156
157         /* gpio13 is usb power.  Turn it on. */
158         gpio_request_one(13, GPIOF_OUT_INIT_HIGH | GPIOF_EXPORT_DIR_FIXED,
159                          "USB power");
160         ath79_register_usb();
161
162         ath79_register_leds_gpio(-1, ARRAY_SIZE(wzrhpg300nh2_leds_gpio),
163                                  wzrhpg300nh2_leds_gpio);
164         ath79_register_gpio_keys_polled(-1, WZRHPG300NH2_KEYS_POLL_INTERVAL,
165                                         ARRAY_SIZE(wzrhpg300nh2_gpio_keys),
166                                         wzrhpg300nh2_gpio_keys);
167         ap9x_pci_setup_wmac_leds(0, wzrhpg300nh2_wmac_leds_gpio,
168                                 ARRAY_SIZE(wzrhpg300nh2_wmac_leds_gpio));
169
170         ap91_pci_init(eeprom, mac0);
171 }
172
173 MIPS_MACHINE(ATH79_MACH_WZR_HP_G300NH2, "WZR-HP-G300NH2",
174              "Buffalo WZR-HP-G300NH2", wzrhpg300nh2_setup);