ar71xx: add support for TP-Link TL-WR902AC v1
[openwrt/openwrt.git] / target / linux / ar71xx / files / 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 <asm/mach-ath79/ath79.h>
16 #include <asm/mach-ath79/ar71xx_regs.h>
17
18 #include "common.h"
19 #include "dev-ap9x-pci.h"
20 #include "dev-eth.h"
21 #include "dev-gpio-buttons.h"
22 #include "dev-leds-gpio.h"
23 #include "dev-m25p80.h"
24 #include "machtypes.h"
25
26 #define WHRHPG300N_GPIO_LED_SECURITY 0
27 #define WHRHPG300N_GPIO_LED_DIAG 1
28 #define WHRHPG300N_GPIO_LED_ROUTER 6
29
30 #define WHRHPG300N_GPIO_BTN_ROUTER_ON 7
31 #define WHRHPG300N_GPIO_BTN_ROUTER_AUTO 8
32 #define WHRHPG300N_GPIO_BTN_RESET 11
33 #define WHRHPG300N_GPIO_BTN_AOSS 12
34 #define WHRHPG300N_GPIO_LED_LAN1 13
35 #define WHRHPG300N_GPIO_LED_LAN2 14
36 #define WHRHPG300N_GPIO_LED_LAN3 15
37 #define WHRHPG300N_GPIO_LED_LAN4 16
38 #define WHRHPG300N_GPIO_LED_WAN 17
39
40 #define WHRHPG300N_KEYS_POLL_INTERVAL 20 /* msecs */
41 #define WHRHPG300N_KEYS_DEBOUNCE_INTERVAL (3 * WHRHPG300N_KEYS_POLL_INTERVAL)
42
43 #define WHRHPG300N_MAC_OFFSET 0x20c
44
45 static struct gpio_led whrhpg300n_leds_gpio[] __initdata = {
46 {
47 .name = "buffalo:orange:security",
48 .gpio = WHRHPG300N_GPIO_LED_SECURITY,
49 .active_low = 1,
50 }, {
51 .name = "buffalo:red:diag",
52 .gpio = WHRHPG300N_GPIO_LED_DIAG,
53 .active_low = 1,
54 }, {
55 .name = "buffalo:green:router",
56 .gpio = WHRHPG300N_GPIO_LED_ROUTER,
57 .active_low = 1,
58 }, {
59 .name = "buffalo:green:wan",
60 .gpio = WHRHPG300N_GPIO_LED_WAN,
61 .active_low = 1,
62 }, {
63 .name = "buffalo:green:lan1",
64 .gpio = WHRHPG300N_GPIO_LED_LAN1,
65 .active_low = 1,
66 }, {
67 .name = "buffalo:green:lan2",
68 .gpio = WHRHPG300N_GPIO_LED_LAN2,
69 .active_low = 1,
70 }, {
71 .name = "buffalo:green:lan3",
72 .gpio = WHRHPG300N_GPIO_LED_LAN3,
73 .active_low = 1,
74 }, {
75 .name = "buffalo:green:lan4",
76 .gpio = WHRHPG300N_GPIO_LED_LAN4,
77 .active_low = 1,
78 }
79 };
80
81 static struct gpio_keys_button whrhpg300n_gpio_keys[] __initdata = {
82 {
83 .desc = "reset",
84 .type = EV_KEY,
85 .code = KEY_RESTART,
86 .debounce_interval = WHRHPG300N_KEYS_DEBOUNCE_INTERVAL,
87 .gpio = WHRHPG300N_GPIO_BTN_RESET,
88 .active_low = 1,
89 }, {
90 .desc = "aoss/wps",
91 .type = EV_KEY,
92 .code = KEY_WPS_BUTTON,
93 .gpio = WHRHPG300N_GPIO_BTN_AOSS,
94 .debounce_interval = WHRHPG300N_KEYS_DEBOUNCE_INTERVAL,
95 .active_low = 1,
96 }, {
97 .desc = "router_on",
98 .type = EV_KEY,
99 .code = BTN_2,
100 .gpio = WHRHPG300N_GPIO_BTN_ROUTER_ON,
101 .debounce_interval = WHRHPG300N_KEYS_DEBOUNCE_INTERVAL,
102 .active_low = 1,
103 }, {
104 .desc = "router_auto",
105 .type = EV_KEY,
106 .code = BTN_3,
107 .gpio = WHRHPG300N_GPIO_BTN_ROUTER_AUTO,
108 .debounce_interval = WHRHPG300N_KEYS_DEBOUNCE_INTERVAL,
109 .active_low = 1,
110 }
111 };
112
113 static void __init whrhpg300n_setup(void)
114 {
115 u8 *ee = (u8 *) KSEG1ADDR(0x1fff1000);
116 u8 *mac = (u8 *) KSEG1ADDR(ee + WHRHPG300N_MAC_OFFSET);
117
118 ath79_register_m25p80(NULL);
119
120 ath79_gpio_function_disable(AR724X_GPIO_FUNC_ETH_SWITCH_LED0_EN |
121 AR724X_GPIO_FUNC_ETH_SWITCH_LED1_EN |
122 AR724X_GPIO_FUNC_ETH_SWITCH_LED2_EN |
123 AR724X_GPIO_FUNC_ETH_SWITCH_LED3_EN |
124 AR724X_GPIO_FUNC_ETH_SWITCH_LED4_EN);
125
126 ath79_register_leds_gpio(-1, ARRAY_SIZE(whrhpg300n_leds_gpio),
127 whrhpg300n_leds_gpio);
128
129 ath79_register_gpio_keys_polled(-1, WHRHPG300N_KEYS_POLL_INTERVAL,
130 ARRAY_SIZE(whrhpg300n_gpio_keys),
131 whrhpg300n_gpio_keys);
132
133 ath79_init_mac(ath79_eth0_data.mac_addr, mac, 0);
134 ath79_init_mac(ath79_eth1_data.mac_addr, mac, 1);
135
136 ath79_register_mdio(0, 0x0);
137
138 /* LAN ports */
139 ath79_register_eth(1);
140 /* WAN port */
141 ath79_register_eth(0);
142
143 ap9x_pci_setup_wmac_led_pin(0, 1);
144
145 ap91_pci_init(ee, mac);
146 }
147
148 MIPS_MACHINE(ATH79_MACH_WHR_HP_G300N, "WHR-HP-G300N", "Buffalo WHR-HP-G300N",
149 whrhpg300n_setup);
150
151 MIPS_MACHINE(ATH79_MACH_WHR_G301N, "WHR-G301N", "Buffalo WHR-G301N",
152 whrhpg300n_setup);
153
154 MIPS_MACHINE(ATH79_MACH_WHR_HP_GN, "WHR-HP-GN", "Buffalo WHR-HP-GN",
155 whrhpg300n_setup);