a quick and dirty implementation of EAP220
[openwrt/staging/lynxis.git] / target / linux / ar71xx / files / arch / mips / ath79 / mach-eap120.c
1 /*
2 * TP-LINK EAP120 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
11 #include <linux/gpio.h>
12 #include <linux/platform_device.h>
13 #include <linux/platform_data/mdio-gpio.h>
14 #include <asm/mach-ath79/ath79.h>
15 #include <asm/mach-ath79/ar71xx_regs.h>
16 #include <linux/platform_data/phy-at803x.h>
17
18 #include "common.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-m25p80.h"
24 #include "dev-wmac.h"
25 #include "machtypes.h"
26
27
28 #define EAP120_GPIO_LED_RED 12
29 #define EAP120_GPIO_LED_YEL 13
30 #define EAP120_GPIO_LED_GRN 15
31 #define EAP120_GPIO_BTN_RESET 4
32
33 #define EAP120_KEYS_POLL_INTERVAL 20 /* msecs */
34 #define EAP120_KEYS_DEBOUNCE_INTERVAL (3 * EAP120_KEYS_POLL_INTERVAL)
35
36 #define EAP120_GPIO_SMI_MDIO 16
37 #define EAP120_GPIO_SMI_MDC 17
38
39 #define EAP120_LAN_PHYADDR 4
40
41 static struct gpio_led eap120_leds_gpio[] __initdata = {
42 {
43 .name = "eap120:red:system",
44 .gpio = EAP120_GPIO_LED_RED,
45 .active_low = 1,
46 }, {
47 .name = "eap120:yellow:system",
48 .gpio = EAP120_GPIO_LED_YEL,
49 .active_low = 1,
50 }, {
51 .name = "eap120:green:system",
52 .gpio = EAP120_GPIO_LED_GRN,
53 .active_low = 1,
54 },
55 };
56
57 static struct gpio_keys_button eap120_gpio_keys[] __initdata = {
58 {
59 .desc = "Reset button",
60 .type = EV_KEY,
61 .code = KEY_RESTART,
62 .debounce_interval = EAP120_KEYS_DEBOUNCE_INTERVAL,
63 .gpio = EAP120_GPIO_BTN_RESET,
64 .active_low = 1,
65 }
66 };
67
68 static struct mdio_gpio_platform_data eap120_mdio = {
69 .mdc = EAP120_GPIO_SMI_MDC,
70 .mdio = EAP120_GPIO_SMI_MDIO,
71 .phy_mask = ~BIT(EAP120_LAN_PHYADDR),
72 };
73
74 static struct at803x_platform_data eap120_ar8035_data = {
75 .disable_smarteee = 0,
76 .enable_rgmii_rx_delay = 1,
77 .enable_rgmii_tx_delay = 0,
78 .fixup_rgmii_tx_delay = 1,
79 };
80
81 static struct platform_device eap120_phy_device = {
82 .name = "mdio-gpio",
83 .id = 0,
84 .dev = {
85 .platform_data = &eap120_mdio, &eap120_ar8035_data
86 },
87 };
88
89 static void __init eap_setup(u8 *mac)
90 {
91 ath79_register_leds_gpio(-1, ARRAY_SIZE(eap120_leds_gpio),
92 eap120_leds_gpio);
93
94 ath79_register_gpio_keys_polled(1, EAP120_KEYS_POLL_INTERVAL,
95 ARRAY_SIZE(eap120_gpio_keys),
96 eap120_gpio_keys);
97
98 ath79_register_m25p80(NULL);
99
100 /* MDIO Interface */
101 platform_device_register(&eap120_phy_device);
102 ath79_setup_ar934x_eth_cfg(AR934X_ETH_CFG_RGMII_GMAC0);
103
104 /* GMAC0 is connected to the RGMII interface to an Atheros AR8035-A */
105 ath79_init_mac(ath79_eth0_data.mac_addr, mac, 0);
106 ath79_eth0_data.mii_bus_dev = &eap120_phy_device.dev;
107 ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
108 ath79_eth0_data.phy_mask = BIT(EAP120_LAN_PHYADDR);
109 ath79_eth0_pll_data.pll_1000 = 0x0e000000;
110 ath79_eth0_pll_data.pll_100 = 0x00000101;
111 ath79_eth0_pll_data.pll_10 = 0x00001313;
112 ath79_register_eth(0);
113 }
114
115 static void __init eap120_setup(void)
116 {
117 u8 *mac = (u8 *) KSEG1ADDR(0x1f030008);
118 u8 *ee = (u8 *) KSEG1ADDR(0x1fff1000);
119
120 eap_setup(mac);
121
122 ath79_register_wmac(ee, mac);
123 }
124
125 static void __init eap220_setup(void)
126 {
127 u8 second_wifi[ETH_ALEN] = { 0 };
128
129 u8 *mac = (u8 *) KSEG1ADDR(0x1f030008);
130 u8 *art = (u8 *) KSEG1ADDR(0x1fff0000);
131
132 eap_setup(mac);
133
134 /* first wifi / 2.4 GHz */
135 #define EAP220_WMAC_OFFSET 0x1000
136 ath79_register_wmac(art + EAP220_WMAC_OFFSET, mac);
137
138 /* second wifi / 5 GHz */
139 #define EAP220_PCIE_CALDATA_OFFSET 0x5000
140 ath79_init_mac(second_wifi, mac, 1);
141 ap91_pci_init(art + EAP220_PCIE_CALDATA_OFFSET, second_wifi);
142 }
143
144 MIPS_MACHINE(ATH79_MACH_EAP120, "EAP120", "TP-LINK EAP120",
145 eap120_setup);
146
147 MIPS_MACHINE(ATH79_MACH_EAP220, "EAP220", "TP-LINK EAP220",
148 eap220_setup);
149