ar71xx: fix DDR write buffer flushing issues with 4.4
[librecmc/librecmc.git] / target / linux / ar71xx / files / arch / mips / ath79 / mach-tl-wr841n-v9.c
1 /*
2  *  TP-LINK TL-WR841N/ND v9/TL-WR842N/ND v3
3  *
4  *  Copyright (C) 2014 Matthias Schiffer <mschiffer@universe-factory.net>
5  *  Copyright (C) 2016 Cezary Jackiewicz <cezary@eko.one.pl>
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/platform_device.h>
14
15 #include <asm/mach-ath79/ath79.h>
16 #include <asm/mach-ath79/ar71xx_regs.h>
17
18 #include "common.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 "dev-wmac.h"
25 #include "machtypes.h"
26
27 #define TL_WR841NV9_GPIO_LED_WLAN       13
28 #define TL_WR841NV9_GPIO_LED_QSS        3
29 #define TL_WR841NV9_GPIO_LED_WAN        4
30 #define TL_WR841NV9_GPIO_LED_LAN1       16
31 #define TL_WR841NV9_GPIO_LED_LAN2       15
32 #define TL_WR841NV9_GPIO_LED_LAN3       14
33 #define TL_WR841NV9_GPIO_LED_LAN4       11
34
35 #define TL_WR841NV9_GPIO_BTN_RESET      12
36 #define TL_WR841NV9_GPIO_BTN_WIFI       17
37
38 #define TL_WR842NV3_GPIO_LED_SYSTEM     2
39 #define TL_WR842NV3_GPIO_LED_WLAN       3
40 #define TL_WR842NV3_GPIO_LED_WAN_RED    4
41 #define TL_WR842NV3_GPIO_LED_WAN_GREEN  11
42 #define TL_WR842NV3_GPIO_LED_LAN1       12
43 #define TL_WR842NV3_GPIO_LED_LAN2       13
44 #define TL_WR842NV3_GPIO_LED_LAN3       14
45 #define TL_WR842NV3_GPIO_LED_LAN4       15
46 #define TL_WR842NV3_GPIO_LED_3G         16
47 #define TL_WR842NV3_GPIO_LED_WPS        17
48
49 #define TL_WR842NV3_GPIO_BTN_RESET      1
50 #define TL_WR842NV3_GPIO_BTN_WIFI       0
51
52 #define TL_WR841NV9_KEYS_POLL_INTERVAL  20      /* msecs */
53 #define TL_WR841NV9_KEYS_DEBOUNCE_INTERVAL (3 * TL_WR841NV9_KEYS_POLL_INTERVAL)
54
55 static const char *tl_wr841n_v9_part_probes[] = {
56         "tp-link",
57         NULL,
58 };
59
60 static struct flash_platform_data tl_wr841n_v9_flash_data = {
61         .part_probes    = tl_wr841n_v9_part_probes,
62 };
63
64 static struct gpio_led tl_wr841n_v9_leds_gpio[] __initdata = {
65         {
66                 .name           = "tp-link:green:lan1",
67                 .gpio           = TL_WR841NV9_GPIO_LED_LAN1,
68                 .active_low     = 1,
69         }, {
70                 .name           = "tp-link:green:lan2",
71                 .gpio           = TL_WR841NV9_GPIO_LED_LAN2,
72                 .active_low     = 1,
73         }, {
74                 .name           = "tp-link:green:lan3",
75                 .gpio           = TL_WR841NV9_GPIO_LED_LAN3,
76                 .active_low     = 1,
77         }, {
78                 .name           = "tp-link:green:lan4",
79                 .gpio           = TL_WR841NV9_GPIO_LED_LAN4,
80                 .active_low     = 1,
81         }, {
82                 .name           = "tp-link:green:qss",
83                 .gpio           = TL_WR841NV9_GPIO_LED_QSS,
84                 .active_low     = 1,
85         }, {
86                 .name           = "tp-link:green:wan",
87                 .gpio           = TL_WR841NV9_GPIO_LED_WAN,
88                 .active_low     = 1,
89         }, {
90                 .name           = "tp-link:green:wlan",
91                 .gpio           = TL_WR841NV9_GPIO_LED_WLAN,
92                 .active_low     = 1,
93         },
94 };
95
96 static struct gpio_keys_button tl_wr841n_v9_gpio_keys[] __initdata = {
97         {
98                 .desc           = "Reset button",
99                 .type           = EV_KEY,
100                 .code           = KEY_RESTART,
101                 .debounce_interval = TL_WR841NV9_KEYS_DEBOUNCE_INTERVAL,
102                 .gpio           = TL_WR841NV9_GPIO_BTN_RESET,
103                 .active_low     = 1,
104         }, {
105                 .desc           = "WIFI button",
106                 .type           = EV_KEY,
107                 .code           = KEY_RFKILL,
108                 .debounce_interval = TL_WR841NV9_KEYS_DEBOUNCE_INTERVAL,
109                 .gpio           = TL_WR841NV9_GPIO_BTN_WIFI,
110                 .active_low     = 1,
111         }
112 };
113
114 static struct gpio_led tl_wr842n_v3_leds_gpio[] __initdata = {
115         {
116                 .name           = "tp-link:green:lan1",
117                 .gpio           = TL_WR842NV3_GPIO_LED_LAN1,
118                 .active_low     = 1,
119         }, {
120                 .name           = "tp-link:green:lan2",
121                 .gpio           = TL_WR842NV3_GPIO_LED_LAN2,
122                 .active_low     = 1,
123         }, {
124                 .name           = "tp-link:green:lan3",
125                 .gpio           = TL_WR842NV3_GPIO_LED_LAN3,
126                 .active_low     = 1,
127         }, {
128                 .name           = "tp-link:green:lan4",
129                 .gpio           = TL_WR842NV3_GPIO_LED_LAN4,
130                 .active_low     = 1,
131         }, {
132                 .name           = "tp-link:green:wan",
133                 .gpio           = TL_WR842NV3_GPIO_LED_WAN_GREEN,
134                 .active_low     = 1,
135         }, {
136                 .name           = "tp-link:red:wan",
137                 .gpio           = TL_WR842NV3_GPIO_LED_WAN_RED,
138                 .active_low     = 1,
139         }, {
140                 .name           = "tp-link:green:wlan",
141                 .gpio           = TL_WR842NV3_GPIO_LED_WLAN,
142                 .active_low     = 1,
143         }, {
144                 .name           = "tp-link:green:system",
145                 .gpio           = TL_WR842NV3_GPIO_LED_SYSTEM,
146                 .active_low     = 1,
147         }, {
148                 .name           = "tp-link:green:3g",
149                 .gpio           = TL_WR842NV3_GPIO_LED_3G,
150                 .active_low     = 1,
151         }, {
152                 .name           = "tp-link:green:wps",
153                 .gpio           = TL_WR842NV3_GPIO_LED_WPS,
154                 .active_low     = 1,
155         },
156 };
157
158 static struct gpio_keys_button tl_wr842n_v3_gpio_keys[] __initdata = {
159         {
160                 .desc           = "Reset button",
161                 .type           = EV_KEY,
162                 .code           = KEY_RESTART,
163                 .debounce_interval = TL_WR841NV9_KEYS_DEBOUNCE_INTERVAL,
164                 .gpio           = TL_WR842NV3_GPIO_BTN_RESET,
165                 .active_low     = 1,
166         }, {
167                 .desc           = "WIFI button",
168                 .type           = EV_KEY,
169                 .code           = KEY_RFKILL,
170                 .debounce_interval = TL_WR841NV9_KEYS_DEBOUNCE_INTERVAL,
171                 .gpio           = TL_WR842NV3_GPIO_BTN_WIFI,
172                 .active_low     = 1,
173         }
174 };
175
176
177 static void __init tl_ap143_setup(void)
178 {
179         u8 *mac = (u8 *) KSEG1ADDR(0x1f01fc00);
180         u8 *ee = (u8 *) KSEG1ADDR(0x1fff1000);
181         u8 tmpmac[ETH_ALEN];
182
183         ath79_register_m25p80(&tl_wr841n_v9_flash_data);
184
185         ath79_setup_ar933x_phy4_switch(false, false);
186
187         ath79_register_mdio(0, 0x0);
188
189         /* LAN */
190         ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_GMII;
191         ath79_eth1_data.duplex = DUPLEX_FULL;
192         ath79_switch_data.phy_poll_mask |= BIT(4);
193         ath79_init_mac(ath79_eth1_data.mac_addr, mac, 0);
194         ath79_register_eth(1);
195
196         /* WAN */
197         ath79_switch_data.phy4_mii_en = 1;
198         ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
199         ath79_eth0_data.duplex = DUPLEX_FULL;
200         ath79_eth0_data.speed = SPEED_100;
201         ath79_eth0_data.phy_mask = BIT(4);
202         ath79_init_mac(ath79_eth0_data.mac_addr, mac, 1);
203         ath79_register_eth(0);
204
205         ath79_init_mac(tmpmac, mac, 0);
206         ath79_register_wmac(ee, tmpmac);
207 }
208
209 static void __init tl_wr841n_v9_setup(void)
210 {
211         tl_ap143_setup();
212
213         ath79_register_leds_gpio(-1, ARRAY_SIZE(tl_wr841n_v9_leds_gpio),
214                                  tl_wr841n_v9_leds_gpio);
215
216         ath79_register_gpio_keys_polled(1, TL_WR841NV9_KEYS_POLL_INTERVAL,
217                                         ARRAY_SIZE(tl_wr841n_v9_gpio_keys),
218                                         tl_wr841n_v9_gpio_keys);
219 }
220
221 MIPS_MACHINE(ATH79_MACH_TL_WR841N_V9, "TL-WR841N-v9", "TP-LINK TL-WR841N/ND v9",
222              tl_wr841n_v9_setup);
223
224 static void __init tl_wr842n_v3_setup(void)
225 {
226         tl_ap143_setup();
227
228         ath79_register_leds_gpio(-1, ARRAY_SIZE(tl_wr842n_v3_leds_gpio),
229                                  tl_wr842n_v3_leds_gpio);
230
231         ath79_register_gpio_keys_polled(1, TL_WR841NV9_KEYS_POLL_INTERVAL,
232                                         ARRAY_SIZE(tl_wr842n_v3_gpio_keys),
233                                         tl_wr842n_v3_gpio_keys);
234
235         ath79_register_usb();
236 }
237
238 MIPS_MACHINE(ATH79_MACH_TL_WR842N_V3, "TL-WR842N-v3", "TP-LINK TL-WR842N/ND v3",
239              tl_wr842n_v3_setup);