ar71xx: fix lan ports on archer C59 and C60
[lede-git/.git] / target / linux / ar71xx / files / arch / mips / ath79 / mach-archer-c60-v1.c
1 /*
2  *  TP-Link Archer C60 v1 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 #include <linux/gpio.h>
15
16 #include "common.h"
17 #include "dev-m25p80.h"
18 #include "machtypes.h"
19 #include "pci.h"
20 #include "dev-ap9x-pci.h"
21 #include "dev-eth.h"
22 #include "dev-gpio-buttons.h"
23 #include "dev-leds-gpio.h"
24 #include "dev-spi.h"
25 #include "dev-usb.h"
26 #include "dev-wmac.h"
27
28 #define ARCHER_C60_V1_GPIO_LED_LAN              2
29 #define ARCHER_C60_V1_GPIO_LED_POWER            16
30 #define ARCHER_C60_V1_GPIO_LED_WLAN2            17
31 #define ARCHER_C60_V1_GPIO_LED_WLAN5            18
32 #define ARCHER_C60_V1_GPIO_LED_WPS              19
33 #define ARCHER_C60_V1_GPIO_LED_WAN_GREEN        20
34 #define ARCHER_C60_V1_GPIO_LED_WAN_AMBER        22
35
36
37 #define ARCHER_C60_V1_KEYS_POLL_INTERVAL        20
38 #define ARCHER_C60_V1_KEYS_DEBOUNCE_INTERVAL    (3 * ARCHER_C60_V1_KEYS_POLL_INTERVAL)
39
40 #define ARCHER_C60_V1_GPIO_BTN_RESET            21
41 #define ARCHER_C60_V1_GPIO_BTN_RFKILL           1
42
43
44
45 #define ARCHER_C60_V1_WMAC_CALDATA_OFFSET       0x1000
46 #define ARCHER_C60_V1_PCI_CALDATA_OFFSET        0x5000
47
48 static struct gpio_led archer_c60_v1_leds_gpio[] __initdata = {
49         {
50                 .name           = "archer-c60-v1:green:power",
51                 .gpio           = ARCHER_C60_V1_GPIO_LED_POWER,
52                 .active_low     = 1,
53         },
54         {
55                 .name           = "archer-c60-v1:green:wlan2g",
56                 .gpio           = ARCHER_C60_V1_GPIO_LED_WLAN2,
57                 .active_low     = 1,
58         },
59         {
60                 .name           = "archer-c60-v1:green:wlan5g",
61                 .gpio           = ARCHER_C60_V1_GPIO_LED_WLAN5,
62                 .active_low     = 1,
63         },
64         {
65                 .name           = "archer-c60-v1:green:lan",
66                 .gpio           = ARCHER_C60_V1_GPIO_LED_LAN,
67                 .active_low     = 1,
68         },
69         {
70                 .name           = "archer-c60-v1:green:wan",
71                 .gpio           = ARCHER_C60_V1_GPIO_LED_WAN_GREEN,
72                 .active_low     = 1,
73         },
74         {
75                 .name           = "archer-c60-v1:amber:wan",
76                 .gpio           = ARCHER_C60_V1_GPIO_LED_WAN_AMBER,
77                 .active_low     = 1,
78         },
79         {
80                 .name           = "archer-c60-v1:green:wps",
81                 .gpio           = ARCHER_C60_V1_GPIO_LED_WPS,
82                 .active_low     = 1,
83         },
84 };
85
86 static struct gpio_keys_button archer_c60_v1_gpio_keys[] __initdata = {
87         {
88                 .desc                   = "Reset button",
89                 .type                   = EV_KEY,
90                 .code                   = KEY_RESTART,
91                 .debounce_interval      = ARCHER_C60_V1_KEYS_DEBOUNCE_INTERVAL,
92                 .gpio                   = ARCHER_C60_V1_GPIO_BTN_RESET,
93                 .active_low             = 1,
94         },
95         {
96                 .desc                   = "RFKILL button",
97                 .type                   = EV_KEY,
98                 .code                   = KEY_RFKILL,
99                 .debounce_interval      = ARCHER_C60_V1_KEYS_DEBOUNCE_INTERVAL,
100                 .gpio                   = ARCHER_C60_V1_GPIO_BTN_RFKILL,
101                 .active_low             = 1,
102         },
103 };
104
105 static void __init archer_c60_v1_setup(void)
106 {
107         u8 *mac = (u8 *) KSEG1ADDR(0x1f010008);
108         u8 *art = (u8 *) KSEG1ADDR(0x1f7f0000);
109
110         ath79_register_m25p80(NULL);
111
112         ath79_register_leds_gpio(-1, ARRAY_SIZE(archer_c60_v1_leds_gpio),
113                                 archer_c60_v1_leds_gpio);
114
115         ath79_register_gpio_keys_polled(-1, ARCHER_C60_V1_KEYS_POLL_INTERVAL,
116                                         ARRAY_SIZE(archer_c60_v1_gpio_keys),
117                                         archer_c60_v1_gpio_keys);
118
119         ath79_register_mdio(0, 0x0);
120         ath79_register_mdio(1, 0x0);
121
122         ath79_init_mac(ath79_eth0_data.mac_addr, mac, 0);
123         ath79_init_mac(ath79_eth1_data.mac_addr, mac, 1);
124
125         /* WAN port */
126         ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
127         ath79_eth0_data.speed = SPEED_100;
128         ath79_eth0_data.duplex = DUPLEX_FULL;
129         ath79_eth0_data.phy_mask = BIT(4);
130         ath79_register_eth(0);
131
132         /* LAN ports */
133         ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_GMII;
134         ath79_eth1_data.speed = SPEED_1000;
135         ath79_eth1_data.duplex = DUPLEX_FULL;
136         ath79_switch_data.phy_poll_mask |= BIT(4);
137         ath79_switch_data.phy4_mii_en = 1;
138         ath79_register_eth(1);
139
140         ath79_register_wmac(art + ARCHER_C60_V1_WMAC_CALDATA_OFFSET, mac);
141         ap91_pci_init(art + ARCHER_C60_V1_PCI_CALDATA_OFFSET, NULL);
142 }
143
144 MIPS_MACHINE(ATH79_MACH_ARCHER_C60_V1, "ARCHER-C60-V1",
145         "TP-LINK Archer C60 v1", archer_c60_v1_setup);