ar71xx: rename ethernet pdata->builtin_switch to use_flow_control
[openwrt/openwrt.git] / target / linux / ar71xx / files / arch / mips / ath79 / mach-tl-wr741nd-v4.c
1 /*
2 * TP-LINK TL-WR741ND v4/TL-MR3220 v2 board support
3 *
4 * Copyright (C) 2011-2012 Gabor Juhos <juhosg@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
13 #include <asm/mach-ath79/ath79.h>
14 #include <asm/mach-ath79/ar71xx_regs.h>
15
16 #include "common.h"
17 #include "dev-eth.h"
18 #include "dev-gpio-buttons.h"
19 #include "dev-leds-gpio.h"
20 #include "dev-m25p80.h"
21 #include "dev-usb.h"
22 #include "dev-wmac.h"
23 #include "machtypes.h"
24
25 #define TL_WR741NDV4_GPIO_BTN_RESET 11
26 #define TL_WR741NDV4_GPIO_BTN_WPS 26
27
28 #define TL_WR741NDV4_GPIO_LED_WLAN 0
29 #define TL_WR741NDV4_GPIO_LED_QSS 1
30 #define TL_WR741NDV4_GPIO_LED_WAN 13
31 #define TL_WR741NDV4_GPIO_LED_LAN1 14
32 #define TL_WR741NDV4_GPIO_LED_LAN2 15
33 #define TL_WR741NDV4_GPIO_LED_LAN3 16
34 #define TL_WR741NDV4_GPIO_LED_LAN4 17
35 #define TL_WR741NDV4_GPIO_LED_SYSTEM 27
36
37 #define TL_MR3220V2_GPIO_BTN_WPS 11
38 #define TL_MR3220V2_GPIO_BTN_WIFI 24
39
40 #define TL_MR3220V2_GPIO_LED_3G 26
41 #define TL_MR3220V2_GPIO_USB_POWER 8
42
43 #define TL_WR741NDV4_KEYS_POLL_INTERVAL 20 /* msecs */
44 #define TL_WR741NDV4_KEYS_DEBOUNCE_INTERVAL (3 * TL_WR741NDV4_KEYS_POLL_INTERVAL)
45
46 static const char *tl_wr741ndv4_part_probes[] = {
47 "tp-link",
48 NULL,
49 };
50
51 static struct flash_platform_data tl_wr741ndv4_flash_data = {
52 .part_probes = tl_wr741ndv4_part_probes,
53 };
54
55 static struct gpio_led tl_wr741ndv4_leds_gpio[] __initdata = {
56 {
57 .name = "tp-link:green:lan1",
58 .gpio = TL_WR741NDV4_GPIO_LED_LAN1,
59 .active_low = 0,
60 }, {
61 .name = "tp-link:green:lan2",
62 .gpio = TL_WR741NDV4_GPIO_LED_LAN2,
63 .active_low = 0,
64 }, {
65 .name = "tp-link:green:lan3",
66 .gpio = TL_WR741NDV4_GPIO_LED_LAN3,
67 .active_low = 0,
68 }, {
69 .name = "tp-link:green:lan4",
70 .gpio = TL_WR741NDV4_GPIO_LED_LAN4,
71 .active_low = 1,
72 }, {
73 .name = "tp-link:green:qss",
74 .gpio = TL_WR741NDV4_GPIO_LED_QSS,
75 .active_low = 0,
76 }, {
77 .name = "tp-link:green:system",
78 .gpio = TL_WR741NDV4_GPIO_LED_SYSTEM,
79 .active_low = 1,
80 }, {
81 .name = "tp-link:green:wan",
82 .gpio = TL_WR741NDV4_GPIO_LED_WAN,
83 .active_low = 0,
84 }, {
85 .name = "tp-link:green:wlan",
86 .gpio = TL_WR741NDV4_GPIO_LED_WLAN,
87 .active_low = 0,
88 }, {
89 /* the 3G LED is only present on the MR3220 v2 */
90 .name = "tp-link:green:3g",
91 .gpio = TL_MR3220V2_GPIO_LED_3G,
92 .active_low = 0,
93 },
94 };
95
96 static struct gpio_keys_button tl_wr741ndv4_gpio_keys[] __initdata = {
97 {
98 .desc = "reset",
99 .type = EV_KEY,
100 .code = KEY_RESTART,
101 .debounce_interval = TL_WR741NDV4_KEYS_DEBOUNCE_INTERVAL,
102 .gpio = TL_WR741NDV4_GPIO_BTN_RESET,
103 .active_low = 0,
104 }, {
105 .desc = "WPS",
106 .type = EV_KEY,
107 .code = KEY_WPS_BUTTON,
108 .debounce_interval = TL_WR741NDV4_KEYS_DEBOUNCE_INTERVAL,
109 .gpio = TL_WR741NDV4_GPIO_BTN_WPS,
110 .active_low = 0,
111 }
112 };
113
114 static struct gpio_keys_button tl_mr3220v2_gpio_keys[] __initdata = {
115 {
116 .desc = "WPS",
117 .type = EV_KEY,
118 .code = KEY_WPS_BUTTON,
119 .debounce_interval = TL_WR741NDV4_KEYS_DEBOUNCE_INTERVAL,
120 .gpio = TL_MR3220V2_GPIO_BTN_WPS,
121 .active_low = 0,
122 }, {
123 .desc = "WIFI button",
124 .type = EV_KEY,
125 .code = KEY_RFKILL,
126 .debounce_interval = TL_WR741NDV4_KEYS_DEBOUNCE_INTERVAL,
127 .gpio = TL_MR3220V2_GPIO_BTN_WIFI,
128 .active_low = 0,
129 }
130 };
131
132 static void __init tl_ap121_setup(void)
133 {
134 u8 *mac = (u8 *) KSEG1ADDR(0x1f01fc00);
135 u8 *ee = (u8 *) KSEG1ADDR(0x1fff1000);
136
137 ath79_setup_ar933x_phy4_switch(true, true);
138
139 ath79_gpio_function_disable(AR933X_GPIO_FUNC_ETH_SWITCH_LED0_EN |
140 AR933X_GPIO_FUNC_ETH_SWITCH_LED1_EN |
141 AR933X_GPIO_FUNC_ETH_SWITCH_LED2_EN |
142 AR933X_GPIO_FUNC_ETH_SWITCH_LED3_EN |
143 AR933X_GPIO_FUNC_ETH_SWITCH_LED4_EN);
144
145 ath79_register_m25p80(&tl_wr741ndv4_flash_data);
146 ath79_init_mac(ath79_eth0_data.mac_addr, mac, 1);
147 ath79_init_mac(ath79_eth1_data.mac_addr, mac, -1);
148
149 ath79_register_mdio(0, 0x0);
150 ath79_register_eth(1);
151 ath79_register_eth(0);
152
153 ath79_register_wmac(ee, mac);
154 }
155
156 static void __init tl_wr741ndv4_setup(void)
157 {
158 tl_ap121_setup();
159
160 ath79_register_leds_gpio(-1, ARRAY_SIZE(tl_wr741ndv4_leds_gpio) - 1,
161 tl_wr741ndv4_leds_gpio);
162 ath79_register_gpio_keys_polled(1, TL_WR741NDV4_KEYS_POLL_INTERVAL,
163 ARRAY_SIZE(tl_wr741ndv4_gpio_keys),
164 tl_wr741ndv4_gpio_keys);
165 }
166
167 MIPS_MACHINE(ATH79_MACH_TL_WR741ND_V4, "TL-WR741ND-v4",
168 "TP-LINK TL-WR741ND v4", tl_wr741ndv4_setup);
169
170 static void __init tl_mr3220v2_setup(void)
171 {
172 tl_ap121_setup();
173
174 gpio_request_one(TL_MR3220V2_GPIO_USB_POWER,
175 GPIOF_OUT_INIT_HIGH | GPIOF_EXPORT_DIR_FIXED,
176 "USB power");
177 ath79_register_usb();
178
179 ath79_register_leds_gpio(-1, ARRAY_SIZE(tl_wr741ndv4_leds_gpio),
180 tl_wr741ndv4_leds_gpio);
181 ath79_register_gpio_keys_polled(1, TL_WR741NDV4_KEYS_POLL_INTERVAL,
182 ARRAY_SIZE(tl_mr3220v2_gpio_keys),
183 tl_mr3220v2_gpio_keys);
184 }
185
186 MIPS_MACHINE(ATH79_MACH_TL_MR3220_V2, "TL-MR3220-v2",
187 "TP-LINK TL-MR3220 v2", tl_mr3220v2_setup);