ramips: Add support for Wavlink WL-WN575A3
[openwrt/staging/wigyori.git] / target / linux / ar71xx / files / arch / mips / ath79 / mach-wpa8630.c
1 /*
2 * TP-Link WPA8630 board support
3 *
4 * Copyright (C) 2016 Henryk Heisig <hyniu@o2.pl>
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 #include <linux/platform_device.h>
11 #include <linux/ath9k_platform.h>
12 #include <linux/ar8216_platform.h>
13 #include <asm/mach-ath79/ar71xx_regs.h>
14
15 #include "common.h"
16 #include "dev-m25p80.h"
17 #include "machtypes.h"
18 #include "pci.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-spi.h"
24 #include "dev-wmac.h"
25
26 #define WPA8630_KEYS_POLL_INTERVAL 20
27 #define WPA8630_KEYS_DEBOUNCE_INTERVAL (3 * WPA8630_KEYS_POLL_INTERVAL)
28
29 #define WPA8630_GPIO_LED_POWER 1
30 #define WPA8630_GPIO_LED_LAN 5
31 #define WPA8630_GPIO_LED_WLAN 19
32 #define WPA8630_GPIO_LED_WLAN5 21
33
34 #define WPA8630_GPIO_BTN_RESET 2
35 #define WPA8630_GPIO_BTN_RFKILL 8
36 #define WPA8630_GPIO_BTN_0 6
37 #define WPA8630_GPIO_BTN_1 7
38
39 #define WPA8630_MAC0_OFFSET 0x0000
40 #define WPA8630_WMAC_CALDATA_OFFSET 0x1000
41 #define WPA8630_PCI_CALDATA_OFFSET 0x5000
42
43 static struct flash_platform_data wpa8630_flash_data = {
44 .type = "s25fl064k",
45 };
46
47 static struct gpio_led wpa8630_leds_gpio[] __initdata = {
48 {
49 .name = "wpa8630:green:power",
50 .gpio = WPA8630_GPIO_LED_POWER,
51 .active_low = 1,
52 },
53 {
54 .name = "wpa8630:green:lan",
55 .gpio = WPA8630_GPIO_LED_LAN,
56 .active_low = 1,
57 },
58 {
59 .name = "wpa8630:green:wlan",
60 .gpio = WPA8630_GPIO_LED_WLAN,
61 .active_low = 1,
62 },
63 {
64 .name = "wpa8630:green:wlan5",
65 .gpio = WPA8630_GPIO_LED_WLAN5,
66 .active_low = 1,
67 },
68 };
69
70 static struct gpio_keys_button wpa8630_gpio_keys[] __initdata = {
71 {
72 .desc = "Reset button",
73 .type = EV_KEY,
74 .code = KEY_RESTART,
75 .debounce_interval = WPA8630_KEYS_DEBOUNCE_INTERVAL,
76 .gpio = WPA8630_GPIO_BTN_RESET,
77 .active_low = 1,
78 },
79 {
80 .desc = "RFKILL button",
81 .type = EV_KEY,
82 .code = KEY_RFKILL,
83 .debounce_interval = WPA8630_KEYS_DEBOUNCE_INTERVAL,
84 .gpio = WPA8630_GPIO_BTN_RFKILL,
85 .active_low = 1,
86 },
87 {
88 .desc = "LED",
89 .type = EV_KEY,
90 .debounce_interval = WPA8630_KEYS_DEBOUNCE_INTERVAL,
91 .gpio = WPA8630_GPIO_BTN_0,
92 .active_low = 1,
93 },
94 {
95 .desc = "Pair",
96 .type = EV_KEY,
97 .debounce_interval = WPA8630_KEYS_DEBOUNCE_INTERVAL,
98 .gpio = WPA8630_GPIO_BTN_1,
99 .active_low = 1,
100 },
101 };
102
103 /* GMAC0 of the QCA8337 switch is connected to the QCA9563 SoC via SGMII */
104 static struct ar8327_pad_cfg wpa8630_qca8337_pad0_cfg = {
105 .mode = AR8327_PAD_MAC_SGMII,
106 .sgmii_delay_en = true,
107 };
108
109 static struct ar8327_platform_data wpa8630_qca8337_data = {
110 .pad0_cfg = &wpa8630_qca8337_pad0_cfg,
111 .port0_cfg = {
112 .force_link = 1,
113 .speed = AR8327_PORT_SPEED_1000,
114 .duplex = 1,
115 .txpause = 1,
116 .rxpause = 1,
117 },
118 };
119
120 static struct mdio_board_info wpa8630_mdio0_info[] = {
121 {
122 .bus_id = "ag71xx-mdio.0",
123 .phy_addr = 0,
124 .platform_data = &wpa8630_qca8337_data,
125 },
126 };
127
128 static void __init wpa8630_setup(void)
129 {
130 u8 *mac = (u8 *) KSEG1ADDR(0x1f00fc00);
131 u8 *art = (u8 *) KSEG1ADDR(0x1fff0000);
132
133 ath79_register_m25p80(&wpa8630_flash_data);
134
135 ath79_init_mac(ath79_eth0_data.mac_addr,
136 art + WPA8630_MAC0_OFFSET, 0);
137
138 platform_device_register(&ath79_mdio0_device);
139
140 mdiobus_register_board_info(wpa8630_mdio0_info,
141 ARRAY_SIZE(wpa8630_mdio0_info));
142
143 /* GMAC0 is connected to an AR8337 switch */
144 ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_SGMII;
145 ath79_eth0_data.mii_bus_dev = &ath79_mdio0_device.dev;
146 ath79_eth0_data.phy_mask = ~BIT(4);
147 ath79_init_mac(ath79_eth0_data.mac_addr, mac, 0);
148
149 ath79_register_eth(0);
150
151 ath79_register_wmac(art + WPA8630_WMAC_CALDATA_OFFSET, mac);
152
153 ap91_pci_init(art + WPA8630_PCI_CALDATA_OFFSET, NULL);
154
155 ath79_register_leds_gpio(-1, ARRAY_SIZE(wpa8630_leds_gpio),
156 wpa8630_leds_gpio);
157
158 ath79_register_gpio_keys_polled(-1, WPA8630_KEYS_POLL_INTERVAL,
159 ARRAY_SIZE(wpa8630_gpio_keys),
160 wpa8630_gpio_keys);
161 }
162
163 MIPS_MACHINE(ATH79_MACH_WPA8630, "WPA8630", "TP-Link WPA8630",
164 wpa8630_setup);