0a1e6b4d91283d5bfec0cc8479af344530705c31
[openwrt/openwrt.git] / target / linux / ar71xx / files / arch / mips / ath79 / mach-tl-wpa8630.c
1 /*
2 * TP-Link TL-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 TL_WPA8630_KEYS_POLL_INTERVAL 20
27 #define TL_WPA8630_KEYS_DEBOUNCE_INTERVAL (3 * TL_WPA8630_KEYS_POLL_INTERVAL)
28
29 #define TL_WPA8630_GPIO_LED_POWER 1
30 #define TL_WPA8630_GPIO_LED_LAN 5
31 #define TL_WPA8630_GPIO_LED_WLAN 19
32 #define TL_WPA8630_GPIO_LED_WLAN5 21
33
34 #define TL_WPA8630_GPIO_BTN_RESET 2
35 #define TL_WPA8630_GPIO_BTN_RFKILL 8
36 #define TL_WPA8630_GPIO_BTN_LED 6
37 #define TL_WPA8630_GPIO_BTN_PAIR 7
38
39 #define TL_WPA8630_MAC0_OFFSET 0x0000
40 #define TL_WPA8630_WMAC_CALDATA_OFFSET 0x1000
41 #define TL_WPA8630_PCI_CALDATA_OFFSET 0x5000
42
43 static const char *tl_wpa8630_part_probes[] = {
44 "tp-link-64k",
45 NULL,
46 };
47
48 static struct flash_platform_data tl_wpa8630_flash_data = {
49 .part_probes = tl_wpa8630_part_probes,
50 .type = "s25fl064k",
51 };
52
53 static struct gpio_led tl_wpa8630_leds_gpio[] __initdata = {
54 {
55 .name = "tl-wpa8630:green:power",
56 .gpio = TL_WPA8630_GPIO_LED_POWER,
57 .active_low = 1,
58 },
59 {
60 .name = "tl-wpa8630:green:lan",
61 .gpio = TL_WPA8630_GPIO_LED_LAN,
62 .active_low = 1,
63 },
64 {
65 .name = "tl-wpa8630:green:wlan",
66 .gpio = TL_WPA8630_GPIO_LED_WLAN,
67 .active_low = 1,
68 },
69 {
70 .name = "tl-wpa8630:green:wlan5",
71 .gpio = TL_WPA8630_GPIO_LED_WLAN5,
72 .active_low = 1,
73 },
74 };
75
76 static struct gpio_keys_button tl_wpa8630_gpio_keys[] __initdata = {
77 {
78 .desc = "Reset button",
79 .type = EV_KEY,
80 .code = KEY_RESTART,
81 .debounce_interval = TL_WPA8630_KEYS_DEBOUNCE_INTERVAL,
82 .gpio = TL_WPA8630_GPIO_BTN_RESET,
83 .active_low = 1,
84 },
85 {
86 .desc = "RFKILL button",
87 .type = EV_KEY,
88 .code = KEY_RFKILL,
89 .debounce_interval = TL_WPA8630_KEYS_DEBOUNCE_INTERVAL,
90 .gpio = TL_WPA8630_GPIO_BTN_RFKILL,
91 .active_low = 1,
92 },
93 {
94 .desc = "LED",
95 .type = EV_KEY,
96 .code = BTN_0,
97 .debounce_interval = TL_WPA8630_KEYS_DEBOUNCE_INTERVAL,
98 .gpio = TL_WPA8630_GPIO_BTN_LED,
99 .active_low = 1,
100 },
101 {
102 .desc = "Pair",
103 .type = EV_KEY,
104 .code = BTN_1,
105 .debounce_interval = TL_WPA8630_KEYS_DEBOUNCE_INTERVAL,
106 .gpio = TL_WPA8630_GPIO_BTN_PAIR,
107 .active_low = 1,
108 },
109 };
110
111 /* GMAC0 of the QCA8337 switch is connected to the QCA9563 SoC via SGMII */
112 static struct ar8327_pad_cfg tl_wpa8630_qca8337_pad0_cfg = {
113 .mode = AR8327_PAD_MAC_SGMII,
114 .sgmii_delay_en = true,
115 };
116
117 static struct ar8327_platform_data tl_wpa8630_qca8337_data = {
118 .pad0_cfg = &tl_wpa8630_qca8337_pad0_cfg,
119 .port0_cfg = {
120 .force_link = 1,
121 .speed = AR8327_PORT_SPEED_1000,
122 .duplex = 1,
123 .txpause = 1,
124 .rxpause = 1,
125 },
126 };
127
128 static struct mdio_board_info tl_wpa8630_mdio0_info[] = {
129 {
130 .bus_id = "ag71xx-mdio.0",
131 .phy_addr = 0,
132 .platform_data = &tl_wpa8630_qca8337_data,
133 },
134 };
135
136 static void __init tl_wpa8630_setup(void)
137 {
138 u8 *mac = (u8 *) KSEG1ADDR(0x1f00fc00);
139 u8 *art = (u8 *) KSEG1ADDR(0x1fff0000);
140
141 ath79_register_m25p80(&tl_wpa8630_flash_data);
142
143 ath79_init_mac(ath79_eth0_data.mac_addr,
144 art + TL_WPA8630_MAC0_OFFSET, 0);
145
146 platform_device_register(&ath79_mdio0_device);
147
148 mdiobus_register_board_info(tl_wpa8630_mdio0_info,
149 ARRAY_SIZE(tl_wpa8630_mdio0_info));
150
151 /* GMAC0 is connected to an AR8337 switch */
152 ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_SGMII;
153 ath79_eth0_data.mii_bus_dev = &ath79_mdio0_device.dev;
154 ath79_eth0_data.phy_mask = ~BIT(4);
155 ath79_init_mac(ath79_eth0_data.mac_addr, mac, 0);
156
157 ath79_register_eth(0);
158
159 ath79_register_wmac(art + TL_WPA8630_WMAC_CALDATA_OFFSET, mac);
160
161 ap91_pci_init(art + TL_WPA8630_PCI_CALDATA_OFFSET, NULL);
162
163 ath79_register_leds_gpio(-1, ARRAY_SIZE(tl_wpa8630_leds_gpio),
164 tl_wpa8630_leds_gpio);
165
166 ath79_register_gpio_keys_polled(-1, TL_WPA8630_KEYS_POLL_INTERVAL,
167 ARRAY_SIZE(tl_wpa8630_gpio_keys),
168 tl_wpa8630_gpio_keys);
169 }
170
171 MIPS_MACHINE(ATH79_MACH_TL_WPA8630, "TL-WPA8630", "TP-Link TL-WPA8630",
172 tl_wpa8630_setup);