ar71xx: wpj531: fix SIG1/RSS1 LED GPIO
[oweals/openwrt.git] / target / linux / ar71xx / files / arch / mips / ath79 / mach-e600g-v2.c
1 /*
2  *  Qxwlan E600G/E600GAC v2 board support
3  *
4  *  Copyright (C) 2017 Peng Zhang <sd20@qxwlan.com>
5  *  Copyright (C) 2018 Piotr Dymacz <pepe2k@gmail.com>
6  *
7  *  This program is free software; you can redistribute it and/or modify it
8  *  under the terms of the GNU General Public License version 2 as published
9  *  by the Free Software Foundation.
10  */
11
12 #include "common.h"
13 #include "dev-eth.h"
14 #include "dev-gpio-buttons.h"
15 #include "dev-leds-gpio.h"
16 #include "dev-m25p80.h"
17 #include "dev-usb.h"
18 #include "dev-wmac.h"
19 #include "machtypes.h"
20 #include "pci.h"
21
22 #define E600G_V2_GPIO_LED_LAN           16
23 #define E600G_V2_GPIO_LED_SYS           13
24 #define E600G_V2_GPIO_LED_WAN_B         4
25 #define E600G_V2_GPIO_LED_WAN_G         15
26
27 #define E600GAC_V2_GPIO_LED_CTRL_B      14
28 #define E600GAC_V2_GPIO_LED_CTRL_G      11
29 #define E600GAC_V2_GPIO_LED_CTRL_R      12
30 #define E600GAC_V2_GPIO_LED_LAN         16
31 #define E600GAC_V2_GPIO_LED_SYS         13
32 #define E600GAC_V2_GPIO_LED_WAN_G       15
33 #define E600GAC_V2_GPIO_LED_WAN_O       4
34
35 #define E600G_V2_GPIO_BTN_RESET         17
36 #define E600GAC_V2_GPIO_BTN_WPS         1
37
38 #define E600G_V2_KEYS_POLL_INTERVAL     20 /* msecs */
39 #define E600G_V2_KEYS_DEBOUNCE_INTERVAL (3 * E600G_V2_KEYS_POLL_INTERVAL)
40
41 static struct gpio_led e600g_v2_leds_gpio[] __initdata = {
42         {
43                 .name           = "e600g-v2:blue:system",
44                 .gpio           = E600G_V2_GPIO_LED_SYS,
45                 .active_low     = 1,
46         }, {
47                 .name           = "e600g-v2:blue:wan",
48                 .gpio           = E600G_V2_GPIO_LED_WAN_B,
49                 .active_low     = 1,
50         }, {
51                 .name           = "e600g-v2:green:lan",
52                 .gpio           = E600G_V2_GPIO_LED_LAN,
53                 .active_low     = 1,
54         }, {
55                 .name           = "e600g-v2:green:wan",
56                 .gpio           = E600G_V2_GPIO_LED_WAN_G,
57                 .active_low     = 1,
58         },
59 };
60
61 static struct gpio_led e600gac_v2_leds_gpio[] __initdata = {
62         {
63                 .name           = "e600gac-v2:blue:control",
64                 .gpio           = E600GAC_V2_GPIO_LED_CTRL_B,
65                 .active_low     = 1,
66         }, {
67                 .name           = "e600gac-v2:green:control",
68                 .gpio           = E600GAC_V2_GPIO_LED_CTRL_G,
69                 .active_low     = 1,
70         }, {
71                 .name           = "e600gac-v2:red:control",
72                 .gpio           = E600GAC_V2_GPIO_LED_CTRL_R,
73                 .active_low     = 1,
74         }, {
75                 .name           = "e600gac-v2:green:system",
76                 .gpio           = E600GAC_V2_GPIO_LED_SYS,
77                 .active_low     = 1,
78         }, {
79                 .name           = "e600gac-v2:orange:wan",
80                 .gpio           = E600GAC_V2_GPIO_LED_WAN_O,
81                 .active_low     = 1,
82         }, {
83                 .name           = "e600gac-v2:green:lan",
84                 .gpio           = E600GAC_V2_GPIO_LED_LAN,
85                 .active_low     = 1,
86         }, {
87                 .name           = "e600gac-v2:green:wan",
88                 .gpio           = E600GAC_V2_GPIO_LED_WAN_G,
89                 .active_low     = 1,
90         },
91 };
92
93 static struct gpio_keys_button e600g_v2_gpio_keys[] __initdata = {
94         {
95                 .desc                   = "reset",
96                 .type                   = EV_KEY,
97                 .code                   = KEY_RESTART,
98                 .debounce_interval      = E600G_V2_KEYS_DEBOUNCE_INTERVAL,
99                 .gpio                   = E600G_V2_GPIO_BTN_RESET,
100                 .active_low             = 1,
101         },
102 };
103
104 static struct gpio_keys_button e600gac_v2_gpio_keys[] __initdata = {
105         {
106                 .desc                   = "reset",
107                 .type                   = EV_KEY,
108                 .code                   = KEY_RESTART,
109                 .debounce_interval      = E600G_V2_KEYS_DEBOUNCE_INTERVAL,
110                 .gpio                   = E600G_V2_GPIO_BTN_RESET,
111                 .active_low             = 1,
112         }, {
113                 .desc                   = "wps",
114                 .type                   = EV_KEY,
115                 .code                   = KEY_WPS_BUTTON,
116                 .debounce_interval      = E600G_V2_KEYS_DEBOUNCE_INTERVAL,
117                 .gpio                   = E600GAC_V2_GPIO_BTN_WPS,
118                 .active_low             = 1,
119         },
120 };
121
122 static void __init e600g_v2_common_setup(void)
123 {
124         u8 *mac = (u8 *) KSEG1ADDR(0x1f050400);
125         u8 *art = (u8 *) KSEG1ADDR(0x1f061000);
126
127         ath79_register_m25p80(NULL);
128
129         ath79_setup_ar933x_phy4_switch(false, false);
130
131         ath79_register_mdio(0, 0x0);
132
133         ath79_switch_data.phy4_mii_en = 1;
134         ath79_switch_data.phy_poll_mask = 0xfe;
135
136         /* LAN */
137         ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
138         ath79_eth0_data.phy_mask = BIT(4);
139         ath79_eth0_data.speed = SPEED_100;
140         ath79_init_mac(ath79_eth0_data.mac_addr, mac, 1);
141         ath79_register_eth(0);
142
143         /* WAN */
144         ath79_eth1_data.duplex = DUPLEX_FULL;
145         ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_GMII;
146         ath79_eth1_data.phy_mask = BIT(0);
147         ath79_eth1_data.speed = SPEED_1000;
148         ath79_init_mac(ath79_eth1_data.mac_addr, mac, 0);
149         ath79_register_eth(1);
150
151         ath79_register_pci();
152         ath79_register_usb();
153         ath79_register_wmac(art, NULL);
154 }
155
156 static void __init e600g_v2_setup(void)
157 {
158         e600g_v2_common_setup();
159
160         ath79_register_leds_gpio(-1, ARRAY_SIZE(e600g_v2_leds_gpio),
161                                  e600g_v2_leds_gpio);
162
163         ath79_register_gpio_keys_polled(-1, E600G_V2_KEYS_POLL_INTERVAL,
164                                         ARRAY_SIZE(e600g_v2_gpio_keys),
165                                         e600g_v2_gpio_keys);
166 }
167
168 static void __init e600gac_v2_setup(void)
169 {
170         e600g_v2_common_setup();
171
172         ath79_register_leds_gpio(-1, ARRAY_SIZE(e600gac_v2_leds_gpio),
173                                  e600gac_v2_leds_gpio);
174
175         ath79_register_gpio_keys_polled(-1, E600G_V2_KEYS_POLL_INTERVAL,
176                                         ARRAY_SIZE(e600gac_v2_gpio_keys),
177                                         e600gac_v2_gpio_keys);
178 }
179
180 MIPS_MACHINE(ATH79_MACH_E600G_V2, "E600G-V2", "Qxwlan E600G v2",
181              e600g_v2_setup);
182
183 MIPS_MACHINE(ATH79_MACH_E600GAC_V2, "E600GAC-V2", "Qxwlan E600GAC v2",
184              e600gac_v2_setup);