ar71xx: wpj531: fix SIG1/RSS1 LED GPIO
[oweals/openwrt.git] / target / linux / ar71xx / files / arch / mips / ath79 / mach-archer-c7-v5.c
1 /*
2  * Atheros ARCHER_C7 reference board support
3  *
4  * Copyright (c) 2018 Arvid E. Picciani <aep@exys.org>
5  * Copyright (c) 2017 Felix Fietkau <nbd@nbd.name>
6  * Copyright (c) 2014 The Linux Foundation. All rights reserved.
7  * Copyright (c) 2012 Gabor Juhos <juhosg@openwrt.org>
8  *
9  * Permission to use, copy, modify, and/or distribute this software for any
10  * purpose with or without fee is hereby granted, provided that the above
11  * copyright notice and this permission notice appear in all copies.
12  *
13  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
14  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
16  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
18  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
19  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20  *
21  */
22
23 #include <linux/platform_device.h>
24 #include <linux/ath9k_platform.h>
25 #include <linux/ar8216_platform.h>
26 #include <linux/proc_fs.h>
27 #include <linux/gpio.h>
28 #include <linux/spi/spi_gpio.h>
29 #include <linux/spi/74x164.h>
30
31 #include <asm/mach-ath79/ar71xx_regs.h>
32
33 #include "common.h"
34 #include "dev-m25p80.h"
35 #include "machtypes.h"
36 #include "pci.h"
37 #include "dev-eth.h"
38 #include "dev-gpio-buttons.h"
39 #include "dev-leds-gpio.h"
40 #include "dev-spi.h"
41 #include "dev-usb.h"
42 #include "dev-wmac.h"
43
44
45 #define ARCHER_C7_GPIO_BTN_RESET        5
46 #define ARCHER_C7_GPIO_BTN_WPS_WIFI     2
47
48 #define ARCHER_C7_GPIO_LED_WLAN5        9
49 #define ARCHER_C7_GPIO_LED_POWER        6
50 #define ARCHER_C7_GPIO_LED_USB          7
51 #define ARCHER_C7_GPIO_LED_WPS          1
52 #define ARCHER_C7_GPIO_LED_LAN1         8
53 #define ARCHER_C7_GPIO_LED_LAN2         17
54 #define ARCHER_C7_GPIO_LED_LAN3         16
55 #define ARCHER_C7_GPIO_LED_LAN4         15
56 #define ARCHER_C7_GPIO_LED_WAN_GREEN    21
57 #define ARCHER_C7_GPIO_LED_WAN_AMBER    20
58 #define ARCHER_C7_GPIO_LED_WLAN2        14
59 #define ARCHER_C7_GPIO_USB_PWR   19
60
61 #define ARCHER_C7_KEYS_POLL_INTERVAL        20     /* msecs */
62 #define ARCHER_C7_KEYS_DEBOUNCE_INTERVAL    (3 * ARCHER_C7_KEYS_POLL_INTERVAL)
63
64 #define ARCHER_C7_MAC0_OFFSET               0
65 #define ARCHER_C7_MAC1_OFFSET               6
66 #define ARCHER_C7_WMAC_CALDATA_OFFSET       0x1000
67
68 #define ARCHER_C7_GPIO_MDC                      3
69 #define ARCHER_C7_GPIO_MDIO                     4
70
71 static struct gpio_led archer_c7_v5_leds_gpio[] __initdata = {
72         {
73                 .name           = "archer-c7-v5:green:power",
74                 .gpio           = ARCHER_C7_GPIO_LED_POWER,
75                 .active_low     = 1,
76         }, {
77                 .name           = "archer-c7-v5:green:wps",
78                 .gpio           = ARCHER_C7_GPIO_LED_WPS,
79                 .active_low     = 1,
80         }, {
81                 .name           = "archer-c7-v5:green:wlan2g",
82                 .gpio           = ARCHER_C7_GPIO_LED_WLAN2,
83                 .active_low     = 1,
84         }, {
85                 .name           = "archer-c7-v5:green:wlan5g",
86                 .gpio           = ARCHER_C7_GPIO_LED_WLAN5,
87                 .active_low     = 1,
88         }, {
89                 .name           = "archer-c7-v5:green:lan1",
90                 .gpio           = ARCHER_C7_GPIO_LED_LAN1,
91                 .active_low     = 1,
92         }, {
93                 .name           = "archer-c7-v5:green:lan2",
94                 .gpio           = ARCHER_C7_GPIO_LED_LAN2,
95                 .active_low     = 1,
96         }, {
97                 .name           = "archer-c7-v5:green:lan3",
98                 .gpio           = ARCHER_C7_GPIO_LED_LAN3,
99                 .active_low     = 1,
100         }, {
101                 .name           = "archer-c7-v5:green:lan4",
102                 .gpio           = ARCHER_C7_GPIO_LED_LAN4,
103                 .active_low     = 1,
104         }, {
105                 .name           = "archer-c7-v5:green:wan",
106                 .gpio           =  ARCHER_C7_GPIO_LED_WAN_GREEN,
107                 .active_low     = 1,
108         }, {
109                 .name           = "archer-c7-v5:amber:wan",
110                 .gpio           =  ARCHER_C7_GPIO_LED_WAN_AMBER,
111                 .active_low     = 1,
112         }, {
113                 .name           = "archer-c7-v5:green:usb",
114                 .gpio           =  ARCHER_C7_GPIO_LED_USB,
115                 .active_low     = 1,
116         },
117 };
118
119 static struct gpio_keys_button archer_c7_v5_gpio_keys[] __initdata = {
120         {
121                 .desc           = "WPS and WIFI button",
122                 .type           = EV_KEY,
123                 .code           = KEY_WPS_BUTTON,
124                 .debounce_interval = ARCHER_C7_KEYS_DEBOUNCE_INTERVAL,
125                 .gpio           = ARCHER_C7_GPIO_BTN_WPS_WIFI,
126                 .active_low     = 1,
127         },
128         {
129                 .desc           = "Reset button",
130                 .type           = EV_KEY,
131                 .code           = KEY_RESTART,
132                 .debounce_interval = ARCHER_C7_KEYS_DEBOUNCE_INTERVAL,
133                 .gpio           = ARCHER_C7_GPIO_BTN_RESET,
134                 .active_low     = 1,
135         },
136 };
137
138
139 static struct ar8327_pad_cfg archer_c7_v5_ar8337_pad0_cfg = {
140         .mode = AR8327_PAD_MAC_SGMII,
141         .sgmii_delay_en = true,
142 };
143
144 static struct ar8327_platform_data archer_c7_v5_ar8337_data = {
145         .pad0_cfg = &archer_c7_v5_ar8337_pad0_cfg,
146         .port0_cfg = {
147                 .force_link = 1,
148                 .speed = AR8327_PORT_SPEED_1000,
149                 .duplex = 1,
150                 .txpause = 1,
151                 .rxpause = 1,
152         },
153 };
154
155 static struct mdio_board_info archer_c7_v5_mdio0_info[] = {
156         {
157                 .bus_id = "ag71xx-mdio.0",
158                 .mdio_addr = 0,
159                 .platform_data = &archer_c7_v5_ar8337_data,
160         },
161 };
162
163
164 static void __init archer_c7_v5_setup(void)
165 {
166         u8 *art = (u8 *) KSEG1ADDR(0x1f050000);
167         u8 *mac = (u8 *) KSEG1ADDR(0x1f060008);
168
169         ath79_register_m25p80(NULL);
170
171
172         ath79_register_leds_gpio(-1, ARRAY_SIZE(archer_c7_v5_leds_gpio),
173                                 archer_c7_v5_leds_gpio);
174
175         ath79_register_gpio_keys_polled(-1, ARCHER_C7_KEYS_POLL_INTERVAL,
176                                         ARRAY_SIZE(archer_c7_v5_gpio_keys),
177                                         archer_c7_v5_gpio_keys);
178
179         ath79_register_usb();
180
181         ath79_gpio_output_select(ARCHER_C7_GPIO_MDC, QCA956X_GPIO_OUT_MUX_GE0_MDC);
182         ath79_gpio_output_select(ARCHER_C7_GPIO_MDIO, QCA956X_GPIO_OUT_MUX_GE0_MDO);
183
184         ath79_register_mdio(0, 0x0);
185
186         mdiobus_register_board_info(archer_c7_v5_mdio0_info,
187                                     ARRAY_SIZE(archer_c7_v5_mdio0_info));
188
189         gpio_request_one(ARCHER_C7_GPIO_USB_PWR,
190                          GPIOF_OUT_INIT_HIGH | GPIOF_EXPORT_DIR_FIXED,
191                          "USB power");
192
193         ath79_register_wmac(art + ARCHER_C7_WMAC_CALDATA_OFFSET, mac);
194         ath79_register_pci();
195
196         /* GMAC0 is connected to an AR8337 switch */
197         ath79_init_mac(ath79_eth0_data.mac_addr, mac, 0);
198         ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_SGMII;
199         ath79_eth0_data.speed = SPEED_1000;
200         ath79_eth0_data.duplex = DUPLEX_FULL;
201         ath79_eth0_data.phy_mask = BIT(0);
202         ath79_eth0_data.mii_bus_dev = &ath79_mdio0_device.dev;
203         ath79_register_eth(0);
204 }
205
206 MIPS_MACHINE(ATH79_MACH_ARCHER_C7_V5, "ARCHER-C7-V5", "TP-LINK Archer C7 v5",
207              archer_c7_v5_setup);