ar71xx: mach-rbspi: simplify reset button registration
[oweals/openwrt.git] / target / linux / ar71xx / files / arch / mips / ath79 / mach-tl-wr1043nd-v4.c
1 /*
2  *  TP-LINK WR1043 V4 support
3  *
4  *  Copyright (C) 2015-2016 P. Wassi <p.wassi at gmx.at>
5  *  Copyright (C) 2016 Matthias Schiffer <mschiffer@universe-factory.net>
6  *  Copyright (C) 2016 Andreas Ziegler <github@andreas-ziegler.de>
7  *  Copyright (C) 2016 Ludwig Thomeczek <ledesrc@wxorx.net>
8  *  Copyright (C) 2017 Tim Thorpe <tim@tfthorpe.net>
9  *
10  *  Derived from: mach-dir-869-a1.c
11  *
12  *  This program is free software; you can redistribute it and/or modify it
13  *  under the terms of the GNU General Public License version 2 as published
14  *  by the Free Software Foundation.
15  */
16
17
18 #include <linux/gpio.h>
19 #include <linux/init.h>
20 #include <linux/pci.h>
21 #include <linux/platform_device.h>
22 #include <linux/ath9k_platform.h>
23
24 #include <asm/mach-ath79/ath79.h>
25 #include <asm/mach-ath79/irq.h>
26 #include <asm/mach-ath79/ar71xx_regs.h>
27
28 #include <linux/platform_data/phy-at803x.h>
29 #include <linux/ar8216_platform.h>
30
31 #include "common.h"
32 #include "dev-ap9x-pci.h"
33 #include "dev-eth.h"
34 #include "dev-gpio-buttons.h"
35 #include "dev-leds-gpio.h"
36 #include "dev-m25p80.h"
37 #include "dev-wmac.h"
38 #include "dev-usb.h"
39 #include "machtypes.h"
40 #include "nvram.h"
41
42 #define TL_WR1043_V4_GPIO_BTN_RESET             2
43 #define TL_WR1043_V4_GPIO_BTN_RFKILL            5
44
45 #define TL_WR1043_V4_GPIO_LED_WLAN              19
46 #define TL_WR1043_V4_GPIO_LED_USB               7
47 #define TL_WR1043_V4_GPIO_LED_WPS               1
48 #define TL_WR1043_V4_GPIO_LED_SYSTEM            6
49
50 #define TL_WR1043_V4_GPIO_USB_POWER             8
51
52 #define TL_WR1043_V4_GPIO_LED_WAN               15
53 #define TL_WR1043_V4_GPIO_LED_LAN1              9
54 #define TL_WR1043_V4_GPIO_LED_LAN2              14
55 #define TL_WR1043_V4_GPIO_LED_LAN3              21
56 #define TL_WR1043_V4_GPIO_LED_LAN4              20
57
58 #define TL_WR1043_V4_KEYS_POLL_INTERVAL         20 /* msecs */
59 #define TL_WR1043_V4_KEYS_DEBOUNCE_INTERVAL     (3 * TL_WR1043_V4_KEYS_POLL_INTERVAL)
60
61 #define TL_WR1043_V4_MAC_LOCATION               0x1ff50008
62
63 #define TL_WR1043_V4_EEPROM_ADDR                0x1fff0000
64 #define TL_WR1043_V4_WMAC_CALDATA_OFFSET        0x1000
65
66 #define TL_WR1043N_V5_MAC_LOCATION              0x1ff00008
67
68 static struct gpio_led tl_wr1043nd_v4_leds_gpio[] __initdata = {
69         {
70                 .name           = "tp-link:green:wps",
71                 .gpio           = TL_WR1043_V4_GPIO_LED_WPS,
72                 .active_low     = 1,
73         },
74         {
75                 .name           = "tp-link:green:system",
76                 .gpio           = TL_WR1043_V4_GPIO_LED_SYSTEM,
77                 .active_low     = 1,
78         },
79         {
80                 .name           = "tp-link:green:wlan",
81                 .gpio           = TL_WR1043_V4_GPIO_LED_WLAN,
82                 .active_low     = 1,
83         },
84         {
85                 .name           = "tp-link:green:usb",
86                 .gpio           = TL_WR1043_V4_GPIO_LED_USB,
87                 .active_low     = 1,
88         },
89         {
90                 .name           = "tp-link:green:wan",
91                 .gpio           = TL_WR1043_V4_GPIO_LED_WAN,
92                 .active_low     = 1,
93         },
94         {
95                 .name           = "tp-link:green:lan1",
96                 .gpio           = TL_WR1043_V4_GPIO_LED_LAN1,
97                 .active_low     = 1,
98         },
99         {
100                 .name           = "tp-link:green:lan2",
101                 .gpio           = TL_WR1043_V4_GPIO_LED_LAN2,
102                 .active_low     = 1,
103         },
104         {
105                 .name           = "tp-link:green:lan3",
106                 .gpio           = TL_WR1043_V4_GPIO_LED_LAN3,
107                 .active_low     = 1,
108         },
109         {
110                 .name           = "tp-link:green:lan4",
111                 .gpio           = TL_WR1043_V4_GPIO_LED_LAN4,
112                 .active_low     = 1,
113         },
114 };
115
116 static struct gpio_keys_button tl_wr1043nd_v4_gpio_keys[] __initdata = {
117         {
118                 .desc           = "Reset button",
119                 .type           = EV_KEY,
120                 .code           = KEY_RESTART,
121                 .debounce_interval = TL_WR1043_V4_KEYS_DEBOUNCE_INTERVAL,
122                 .gpio           = TL_WR1043_V4_GPIO_BTN_RESET,
123                 .active_low     = 1,
124         },
125         {
126                 .desc           = "RFKILL button",
127                 .type           = EV_KEY,
128                 .code           = KEY_RFKILL,
129                 .debounce_interval = TL_WR1043_V4_KEYS_DEBOUNCE_INTERVAL,
130                 .gpio           = TL_WR1043_V4_GPIO_BTN_RFKILL,
131                 .active_low     = 1,
132         },
133 };
134
135 static struct ar8327_pad_cfg tl_wr1043nd_v4_ar8327_pad0_cfg = {
136         .mode = AR8327_PAD_MAC_SGMII,
137         .sgmii_delay_en = true,
138 };
139
140 static struct ar8327_platform_data tl_wr1043nd_v4_ar8327_data = {
141         .pad0_cfg = &tl_wr1043nd_v4_ar8327_pad0_cfg,
142         .port0_cfg = {
143                 .force_link = 1,
144                 .speed = AR8327_PORT_SPEED_1000,
145                 .duplex = 1,
146                 .txpause = 1,
147                 .rxpause = 1,
148         },
149 };
150
151 static struct mdio_board_info tl_wr1043nd_v4_mdio0_info[] = {
152         {
153                 .bus_id = "ag71xx-mdio.0",
154                 .phy_addr = 0,
155                 .platform_data = &tl_wr1043nd_v4_ar8327_data,
156         },
157 };
158
159 static void __init tl_wr1043nd_v4_setup(void)
160 {
161         u8 *mac = (u8 *) KSEG1ADDR(TL_WR1043_V4_MAC_LOCATION);
162         u8 *eeprom = (u8 *) KSEG1ADDR(TL_WR1043_V4_EEPROM_ADDR);
163
164         ath79_register_m25p80(NULL);
165
166         ath79_init_mac(ath79_eth0_data.mac_addr, mac, 0);
167         ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_SGMII;
168         ath79_eth0_data.mii_bus_dev = &ath79_mdio0_device.dev;
169         ath79_eth0_data.phy_mask = BIT(0);
170
171         mdiobus_register_board_info(tl_wr1043nd_v4_mdio0_info,
172                                     ARRAY_SIZE(tl_wr1043nd_v4_mdio0_info));
173
174         ath79_register_usb();
175         ath79_register_mdio(0, 0);
176         ath79_register_eth(0);
177
178         ath79_register_wmac(eeprom + TL_WR1043_V4_WMAC_CALDATA_OFFSET, mac);
179
180         ath79_register_leds_gpio(-1, ARRAY_SIZE(tl_wr1043nd_v4_leds_gpio),
181                                  tl_wr1043nd_v4_leds_gpio);
182
183         ath79_register_gpio_keys_polled(-1, TL_WR1043_V4_KEYS_POLL_INTERVAL,
184                                         ARRAY_SIZE(tl_wr1043nd_v4_gpio_keys),
185                                         tl_wr1043nd_v4_gpio_keys);
186
187         gpio_request_one(TL_WR1043_V4_GPIO_USB_POWER,
188                          GPIOF_OUT_INIT_HIGH | GPIOF_EXPORT_DIR_FIXED,
189                          "USB power");
190 }
191
192 MIPS_MACHINE(ATH79_MACH_TL_WR1043ND_V4, "TL-WR1043ND-v4",
193              "TP-LINK TL-WR1043ND v4", tl_wr1043nd_v4_setup);
194
195 static struct gpio_led tl_wr1043n_v5_leds_gpio[] __initdata = {
196         {
197                 .name           = "tp-link:green:wps",
198                 .gpio           = TL_WR1043_V4_GPIO_LED_WPS,
199                 .active_low     = 1,
200         },
201         {
202                 .name           = "tp-link:green:system",
203                 .gpio           = TL_WR1043_V4_GPIO_LED_SYSTEM,
204                 .active_low     = 1,
205         },
206         {
207                 .name           = "tp-link:green:wlan",
208                 .gpio           = TL_WR1043_V4_GPIO_LED_WLAN,
209                 .active_low     = 1,
210         },
211         {
212                 .name           = "tp-link:green:wan",
213                 .gpio           = TL_WR1043_V4_GPIO_LED_WAN,
214                 .active_low     = 1,
215         },
216         {
217                 .name           = "tp-link:green:lan1",
218                 .gpio           = TL_WR1043_V4_GPIO_LED_LAN1,
219                 .active_low     = 1,
220         },
221         {
222                 .name           = "tp-link:green:lan2",
223                 .gpio           = TL_WR1043_V4_GPIO_LED_LAN2,
224                 .active_low     = 1,
225         },
226         {
227                 .name           = "tp-link:green:lan3",
228                 .gpio           = TL_WR1043_V4_GPIO_LED_LAN3,
229                 .active_low     = 1,
230         },
231         {
232                 .name           = "tp-link:green:lan4",
233                 .gpio           = TL_WR1043_V4_GPIO_LED_LAN4,
234                 .active_low     = 1,
235         },
236 };
237
238 /* The 1043Nv5 is identical to the 1043NDv4,
239  *  only missing the usb and small firmware layout changes  */
240 static void __init tl_wr1043nv5_setup(void)
241 {
242         u8 *art = (u8 *) KSEG1ADDR(TL_WR1043_V4_EEPROM_ADDR);
243         u8 *mac = (u8 *) KSEG1ADDR(TL_WR1043N_V5_MAC_LOCATION);
244
245         ath79_register_m25p80(NULL);
246
247         ath79_register_leds_gpio(-1, ARRAY_SIZE(tl_wr1043n_v5_leds_gpio),
248                                  tl_wr1043n_v5_leds_gpio);
249         ath79_register_gpio_keys_polled(-1, TL_WR1043_V4_KEYS_POLL_INTERVAL,
250                                         ARRAY_SIZE(tl_wr1043nd_v4_gpio_keys),
251                                         tl_wr1043nd_v4_gpio_keys);
252
253         platform_device_register(&ath79_mdio0_device);
254
255         mdiobus_register_board_info(tl_wr1043nd_v4_mdio0_info,
256                                     ARRAY_SIZE(tl_wr1043nd_v4_mdio0_info));
257
258         ath79_register_wmac(art + TL_WR1043_V4_WMAC_CALDATA_OFFSET, mac);
259
260         ath79_init_mac(ath79_eth0_data.mac_addr, mac, 0);
261
262         /* GMAC0 is connected to an AR8337 switch */
263         ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_SGMII;
264         ath79_eth0_data.speed = SPEED_1000;
265         ath79_eth0_data.duplex = DUPLEX_FULL;
266         ath79_eth0_data.phy_mask = BIT(0);
267         ath79_eth0_data.mii_bus_dev = &ath79_mdio0_device.dev;
268         ath79_register_eth(0);
269 }
270
271 MIPS_MACHINE(ATH79_MACH_TL_WR1043N_V5, "TL-WR1043N-v5", "TP-LINK TL-WR1043N v5",
272              tl_wr1043nv5_setup);