ar71xx: wpj531: fix SIG1/RSS1 LED GPIO
[oweals/openwrt.git] / target / linux / ar71xx / files / arch / mips / ath79 / mach-tl-mr6400.c
1 /*
2  * TP-LINK TL-MR6400 board support
3  *
4  *  Copyright (C) 2017 Filip Moc <lede@moc6.cz>
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *     * The name of the author may not be used to endorse or promote products
9  *       derived from this software without specific prior written permission.
10  *
11  * THIS SOFTWARE IS PROVIDED BY AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
12  * WARRANTIES, ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
13  * DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE.
14  */
15
16 #include <linux/gpio.h>
17 #include <linux/platform_device.h>
18
19 #include <asm/mach-ath79/ar71xx_regs.h>
20
21 #include "common.h"
22 #include "dev-gpio-buttons.h"
23 #include "dev-eth.h"
24 #include "dev-leds-gpio.h"
25 #include "dev-m25p80.h"
26 #include "dev-usb.h"
27 #include "dev-wmac.h"
28 #include "machtypes.h"
29
30 #define TL_MR6400_GPIO_LTE_POWER        4
31 #define TL_MR6400_GPIO_BTN_RESET        12      /* SW2 */
32 #define TL_MR6400_GPIO_BTN_RFKILL       14      /* SW3 */
33 #define TL_MR6400_GPIO_LED_WAN          0       /* D12 */
34 #define TL_MR6400_GPIO_LED_4G           1       /* D11 */
35 #define TL_MR6400_GPIO_LED_WPS          3       /* D5  */
36 #define TL_MR6400_GPIO_LED_WLAN         11      /* D3  */
37 #define TL_MR6400_GPIO_LED_POWER        13      /* D2  */
38 #define TL_MR6400_GPIO_LED_LAN          16      /* D4  */
39
40 #define TL_MR6400_KEYS_POLL_INTERVAL    20 /* msecs */
41 #define TL_MR6400_KEYS_DEBOUNCE_INTERVAL (3 * TL_MR6400_KEYS_POLL_INTERVAL)
42
43 #define TL_MR6400_WMAC_CALDATA_OFFSET   0x1000
44
45 static const char *tl_mr6400_part_probes[] = {
46         "tp-link",
47         NULL,
48 };
49
50 static struct flash_platform_data tl_mr6400_flash_data = {
51         .part_probes    = tl_mr6400_part_probes,
52         .type           = "w25q64",
53 };
54
55 static struct gpio_led tl_mr6400_leds_gpio[] __initdata = {
56         {
57                 .name           = "tp-link:white:wan",
58                 .gpio           = TL_MR6400_GPIO_LED_WAN,
59                 .active_low     = 0,
60         },
61         {
62                 .name           = "tp-link:white:4g",
63                 .gpio           = TL_MR6400_GPIO_LED_4G,
64                 .active_low     = 0,
65         },
66         {
67                 .name           = "tp-link:white:wps",
68                 .gpio           = TL_MR6400_GPIO_LED_WPS,
69                 .active_low     = 0,
70         },
71         {
72                 .name           = "tp-link:white:wlan",
73                 .gpio           = TL_MR6400_GPIO_LED_WLAN,
74                 .active_low     = 0,
75         },
76         {
77                 .name           = "tp-link:white:power",
78                 .gpio           = TL_MR6400_GPIO_LED_POWER,
79                 .active_low     = 0,
80         },
81         {
82                 .name           = "tp-link:white:lan",
83                 .gpio           = TL_MR6400_GPIO_LED_LAN,
84                 .active_low     = 0,
85         },
86 };
87
88 static struct gpio_keys_button tl_mr6400_gpio_keys[] __initdata = {
89         {
90                 .desc           = "reset",
91                 .type           = EV_KEY,
92                 .code           = KEY_RESTART,
93                 .debounce_interval = TL_MR6400_KEYS_DEBOUNCE_INTERVAL,
94                 .gpio           = TL_MR6400_GPIO_BTN_RESET,
95                 .active_low     = 1,
96         },
97         {
98                 .desc           = "rfkill",
99                 .type           = EV_KEY,
100                 .code           = KEY_RFKILL,
101                 .debounce_interval = TL_MR6400_KEYS_DEBOUNCE_INTERVAL,
102                 .gpio           = TL_MR6400_GPIO_BTN_RFKILL,
103                 .active_low     = 1,
104         },
105 };
106
107 static void __init tl_mr6400_setup(void)
108 {
109         u8 *mac = (u8 *) KSEG1ADDR(0x1f01fc00);
110         u8 *art = (u8 *) KSEG1ADDR(0x1fff0000);
111
112         ath79_register_m25p80(&tl_mr6400_flash_data);
113
114         ath79_register_mdio(0, 0x0);
115
116         /* LAN1, LAN2, LAN3 */
117         ath79_switch_data.phy4_mii_en = 1;
118         ath79_switch_data.phy_poll_mask |= BIT(0);
119         ath79_eth1_data.duplex = DUPLEX_FULL;
120         ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_GMII;
121         ath79_eth1_data.speed = SPEED_1000;
122         ath79_init_mac(ath79_eth1_data.mac_addr, mac, -1);
123         ath79_register_eth(1);
124
125         /* LAN4 / WAN */
126         ath79_eth0_data.phy_mask = BIT(0);
127         ath79_eth0_data.duplex = DUPLEX_FULL;
128         ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
129         ath79_eth0_data.speed = SPEED_100;
130         ath79_init_mac(ath79_eth0_data.mac_addr, mac, 1);
131         ath79_register_eth(0);
132
133         ath79_register_wmac(art + TL_MR6400_WMAC_CALDATA_OFFSET, mac);
134
135         ath79_register_leds_gpio(-1,
136                                  ARRAY_SIZE(tl_mr6400_leds_gpio),
137                                  tl_mr6400_leds_gpio);
138
139         ath79_register_gpio_keys_polled(-1,
140                                         TL_MR6400_KEYS_POLL_INTERVAL,
141                                         ARRAY_SIZE(tl_mr6400_gpio_keys),
142                                         tl_mr6400_gpio_keys);
143
144         gpio_request_one(TL_MR6400_GPIO_LTE_POWER,
145                          GPIOF_OUT_INIT_LOW | GPIOF_EXPORT_DIR_FIXED | GPIOF_ACTIVE_LOW,
146                          "LTE power");
147         ath79_register_usb();
148 }
149
150 MIPS_MACHINE(ATH79_MACH_TL_MR6400, "TL-MR6400", "TP-LINK TL-MR6400",
151              tl_mr6400_setup);