ar71xx: add support for TP-Link TL-MR11U
[openwrt.git] / target / linux / ar71xx / files-3.2 / arch / mips / ath79 / 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-ath79/ath79.h>
19
20 #include "dev-ap9x-pci.h"
21 #include "dev-eth.h"
22 #include "dev-gpio-buttons.h"
23 #include "dev-leds-gpio.h"
24 #include "dev-m25p80.h"
25 #include "machtypes.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 static struct mtd_partition whrhpg300n_partitions[] = {
42         {
43                 .name           = "u-boot",
44                 .offset         = 0,
45                 .size           = 0x03e000,
46                 .mask_flags     = MTD_WRITEABLE,
47         }, {
48                 .name           = "u-boot-env",
49                 .offset         = 0x03e000,
50                 .size           = 0x002000,
51                 .mask_flags     = MTD_WRITEABLE,
52         }, {
53                 .name           = "kernel",
54                 .offset         = 0x040000,
55                 .size           = 0x0e0000,
56         }, {
57                 .name           = "rootfs",
58                 .offset         = 0x120000,
59                 .size           = 0x2c0000,
60         }, {
61                 .name           = "user_property",
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
76 static struct flash_platform_data whrhpg300n_flash_data = {
77         .parts          = whrhpg300n_partitions,
78         .nr_parts       = ARRAY_SIZE(whrhpg300n_partitions),
79 };
80
81 static struct gpio_led whrhpg300n_leds_gpio[] __initdata = {
82         {
83                 .name           = "buffalo:orange:security",
84                 .gpio           = WHRHPG300N_GPIO_LED_SECURITY,
85                 .active_low     = 1,
86         }, {
87                 .name           = "buffalo:red:diag",
88                 .gpio           = WHRHPG300N_GPIO_LED_DIAG,
89                 .active_low     = 1,
90         }, {
91                 .name           = "buffalo:green:router",
92                 .gpio           = WHRHPG300N_GPIO_LED_ROUTER,
93                 .active_low     = 1,
94         }
95 };
96
97 static struct gpio_keys_button whrhpg300n_gpio_keys[] __initdata = {
98         {
99                 .desc           = "reset",
100                 .type           = EV_KEY,
101                 .code           = KEY_RESTART,
102                 .debounce_interval = WHRHPG300N_KEYS_DEBOUNCE_INTERVAL,
103                 .gpio           = WHRHPG300N_GPIO_BTN_RESET,
104                 .active_low     = 1,
105         }, {
106                 .desc           = "aoss/wps",
107                 .type           = EV_KEY,
108                 .code           = KEY_WPS_BUTTON,
109                 .gpio           = WHRHPG300N_GPIO_BTN_AOSS,
110                 .debounce_interval = WHRHPG300N_KEYS_DEBOUNCE_INTERVAL,
111                 .active_low     = 1,
112         }, {
113                 .desc           = "router_on",
114                 .type           = EV_KEY,
115                 .code           = BTN_2,
116                 .gpio           = WHRHPG300N_GPIO_BTN_ROUTER_ON,
117                 .debounce_interval = WHRHPG300N_KEYS_DEBOUNCE_INTERVAL,
118                 .active_low     = 1,
119         }, {
120                 .desc           = "router_auto",
121                 .type           = EV_KEY,
122                 .code           = BTN_3,
123                 .gpio           = WHRHPG300N_GPIO_BTN_ROUTER_AUTO,
124                 .debounce_interval = WHRHPG300N_KEYS_DEBOUNCE_INTERVAL,
125                 .active_low     = 1,
126         }
127 };
128
129 static void __init whrhpg300n_setup(void)
130 {
131         u8 *ee = (u8 *) KSEG1ADDR(0x1fff1000);
132         u8 *mac = (u8 *) KSEG1ADDR(ee + WHRHPG300N_MAC_OFFSET);
133
134         ath79_register_m25p80(&whrhpg300n_flash_data);
135
136         ath79_register_leds_gpio(-1, ARRAY_SIZE(whrhpg300n_leds_gpio),
137                                  whrhpg300n_leds_gpio);
138
139         ath79_register_gpio_keys_polled(-1, WHRHPG300N_KEYS_POLL_INTERVAL,
140                                         ARRAY_SIZE(whrhpg300n_gpio_keys),
141                                         whrhpg300n_gpio_keys);
142
143         ath79_init_mac(ath79_eth0_data.mac_addr, mac, 0);
144         ath79_init_mac(ath79_eth1_data.mac_addr, mac, 1);
145
146         ath79_register_mdio(0, 0x0);
147
148         /* LAN ports */
149         ath79_register_eth(1);
150         /* WAN port */
151         ath79_register_eth(0);
152
153         ap9x_pci_setup_wmac_led_pin(0, 1);
154
155         ap91_pci_init(ee, mac);
156 }
157
158 MIPS_MACHINE(ATH79_MACH_WHR_HP_G300N, "WHR-HP-G300N", "Buffalo WHR-HP-G300N",
159              whrhpg300n_setup);
160
161 MIPS_MACHINE(ATH79_MACH_WHR_G301N, "WHR-G301N", "Buffalo WHR-G301N",
162              whrhpg300n_setup);
163
164 MIPS_MACHINE(ATH79_MACH_WHR_HP_GN, "WHR-HP-GN", "Buffalo WHR-HP-GN",
165              whrhpg300n_setup);