ar71xx: add support for YunCore CPE830
[oweals/openwrt.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-eth.h"
20 #include "dev-gpio-buttons.h"
21 #include "dev-leds-gpio.h"
22 #include "dev-m25p80.h"
23 #include "dev-wmac.h"
24 #include "machtypes.h"
25
26
27 #define EAP120_GPIO_LED_RED     12
28 #define EAP120_GPIO_LED_YEL     13
29 #define EAP120_GPIO_LED_GRN     15
30 #define EAP120_GPIO_BTN_RESET   4
31
32 #define EAP120_KEYS_POLL_INTERVAL       20 /* msecs */
33 #define EAP120_KEYS_DEBOUNCE_INTERVAL   (3 * EAP120_KEYS_POLL_INTERVAL)
34
35 #define EAP120_GPIO_SMI_MDIO            16
36 #define EAP120_GPIO_SMI_MDC             17
37
38 #define EAP120_LAN_PHYADDR              4
39
40 static struct gpio_led eap120_leds_gpio[] __initdata = {
41         {
42                 .name           = "eap120:red:system",
43                 .gpio           = EAP120_GPIO_LED_RED,
44                 .active_low     = 1,
45         }, {
46                 .name           = "eap120:yellow:system",
47                 .gpio           = EAP120_GPIO_LED_YEL,
48                 .active_low     = 1,
49         }, {
50                 .name           = "eap120:green:system",
51                 .gpio           = EAP120_GPIO_LED_GRN,
52                 .active_low     = 1,
53         },
54 };
55
56 static struct gpio_keys_button eap120_gpio_keys[] __initdata = {
57         {
58                 .desc           = "Reset button",
59                 .type           = EV_KEY,
60                 .code           = KEY_RESTART,
61                 .debounce_interval = EAP120_KEYS_DEBOUNCE_INTERVAL,
62                 .gpio           = EAP120_GPIO_BTN_RESET,
63                 .active_low     = 1,
64         }
65 };
66
67 static struct mdio_gpio_platform_data eap120_mdio = {
68         .mdc            = EAP120_GPIO_SMI_MDC,
69         .mdio           = EAP120_GPIO_SMI_MDIO,
70         .phy_mask       = ~BIT(EAP120_LAN_PHYADDR),
71 };
72
73 static struct at803x_platform_data eap120_ar8035_data = {
74         .disable_smarteee = 0,
75         .enable_rgmii_rx_delay = 1,
76         .enable_rgmii_tx_delay = 0,
77         .fixup_rgmii_tx_delay = 1,
78 };
79
80 static struct platform_device eap120_phy_device = {
81         .name   = "mdio-gpio",
82         .id     = 0,
83         .dev    = {
84                 .platform_data = &eap120_mdio, &eap120_ar8035_data
85         },
86 };
87
88 static void __init eap_setup(u8 *mac)
89 {
90         ath79_register_leds_gpio(-1, ARRAY_SIZE(eap120_leds_gpio),
91                                  eap120_leds_gpio);
92
93         ath79_register_gpio_keys_polled(1, EAP120_KEYS_POLL_INTERVAL,
94                                         ARRAY_SIZE(eap120_gpio_keys),
95                                         eap120_gpio_keys);
96
97         ath79_register_m25p80(NULL);
98
99         /* MDIO Interface */
100         platform_device_register(&eap120_phy_device);
101         ath79_setup_ar934x_eth_cfg(AR934X_ETH_CFG_RGMII_GMAC0);
102
103         /* GMAC0 is connected to the RGMII interface to an Atheros AR8035-A */
104         ath79_init_mac(ath79_eth0_data.mac_addr, mac, 0);
105         ath79_eth0_data.mii_bus_dev = &eap120_phy_device.dev;
106         ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
107         ath79_eth0_data.phy_mask = BIT(EAP120_LAN_PHYADDR);
108         ath79_eth0_pll_data.pll_1000 = 0x0e000000;
109         ath79_eth0_pll_data.pll_100 = 0x00000101;
110         ath79_eth0_pll_data.pll_10 = 0x00001313;
111         ath79_register_eth(0);
112 }
113
114 static void __init eap120_setup(void)
115 {
116         u8 *mac = (u8 *) KSEG1ADDR(0x1f030008);
117         u8 *ee = (u8 *) KSEG1ADDR(0x1fff1000);
118
119         eap_setup(mac);
120
121         ath79_register_wmac(ee, mac);
122 }
123
124 MIPS_MACHINE(ATH79_MACH_EAP120, "EAP120", "TP-LINK EAP120",
125                 eap120_setup);
126