ar71xx: wpj531: fix SIG1/RSS1 LED GPIO
[oweals/openwrt.git] / target / linux / ar71xx / files / arch / mips / ath79 / mach-tl-wr940n-v4.c
1 /*
2  *  TP-LINK TL-WR940N v4 and v6 board support
3  *
4  *  Copyright (C) 2016 David Lutz <kpanic@ff3l.net>
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
14 #include <asm/mach-ath79/ath79.h>
15 #include <asm/mach-ath79/ar71xx_regs.h>
16
17 #include "common.h"
18 #include "dev-eth.h"
19 #include "dev-gpio-buttons.h"
20 #include "dev-leds-gpio.h"
21 #include "dev-m25p80.h"
22 #include "dev-wmac.h"
23 #include "machtypes.h"
24
25
26 #define TL_WR940N_V4_GPIO_LED_QSS               3
27 #define TL_WR940N_V4_GPIO_LED_WAN               14
28 #define TL_WR940N_V4_GPIO_LED_WAN_RED           15
29 #define TL_WR940N_V4_GPIO_LED_LAN4              4
30 #define TL_WR940N_V4_GPIO_LED_LAN3              18
31 #define TL_WR940N_V4_GPIO_LED_LAN2              6
32 #define TL_WR940N_V4_GPIO_LED_LAN1              8
33 #define TL_WR940N_V4_GPIO_LED_WLAN              7
34 #define TL_WR940N_V4_GPIO_LED_SYSTEM            5
35 /* WR940N v6 specific GPIO*/
36 #define TL_WR940N_V6_GPIO_LED_DIAG_ORANGE       15
37 #define TL_WR940N_V6_GPIO_LED_WAN_BLUE          14
38
39 #define TL_WR940N_V4_GPIO_BTN_RESET             1
40 #define TL_WR940N_V4_GPIO_BTN_RFKILL            2
41
42 #define TL_WR940N_KEYS_POLL_INTERVAL            20
43 #define TL_WR940N_KEYS_DEBOUNCE_INTERVAL        (3 * TL_WR940N_KEYS_POLL_INTERVAL)
44
45
46 static struct gpio_led tl_wr940n_v4_leds_gpio[] __initdata = {
47         {
48                 .name           = "tp-link:blue:qss",
49                 .gpio           = TL_WR940N_V4_GPIO_LED_QSS,
50                 .active_low     = 1,
51         },
52         {
53                 .name           = "tp-link:blue:wan",
54                 .gpio           = TL_WR940N_V4_GPIO_LED_WAN,
55                 .active_low     = 1,
56         },
57         {
58                 .name           = "tp-link:red:wan",
59                 .gpio           = TL_WR940N_V4_GPIO_LED_WAN_RED,
60                 .active_low     = 0,
61         },
62         {
63                 .name           = "tp-link:blue:lan1",
64                 .gpio           = TL_WR940N_V4_GPIO_LED_LAN1,
65                 .active_low     = 1,
66         },
67         {
68                 .name           = "tp-link:blue:lan2",
69                 .gpio           = TL_WR940N_V4_GPIO_LED_LAN2,
70                 .active_low     = 1,
71         },
72         {
73                 .name           = "tp-link:blue:lan3",
74                 .gpio           = TL_WR940N_V4_GPIO_LED_LAN3,
75                 .active_low     = 1,
76         },
77         {
78                 .name           = "tp-link:blue:lan4",
79                 .gpio           = TL_WR940N_V4_GPIO_LED_LAN4,
80                 .active_low     = 1,
81         },
82         {
83                 .name           = "tp-link:blue:wlan",
84                 .gpio           = TL_WR940N_V4_GPIO_LED_WLAN,
85                 .active_low     = 1,
86         },
87         {
88                 .name           = "tp-link:blue:system",
89                 .gpio           = TL_WR940N_V4_GPIO_LED_SYSTEM,
90                 .active_low     = 1,
91         },
92 };
93
94 static struct gpio_keys_button tl_wr940n_v4_gpio_keys[] __initdata = {
95         {
96                 .desc           = "Reset button",
97                 .type           = EV_KEY,
98                 .code           = KEY_RESTART,
99                 .debounce_interval = TL_WR940N_KEYS_DEBOUNCE_INTERVAL,
100                 .gpio           = TL_WR940N_V4_GPIO_BTN_RESET,
101                 .active_low     = 1,
102         }, {
103                 .desc           = "RFKILL button",
104                 .type           = EV_KEY,
105                 .code           = KEY_RFKILL,
106                 .debounce_interval = TL_WR940N_KEYS_DEBOUNCE_INTERVAL,
107                 .gpio           = TL_WR940N_V4_GPIO_BTN_RFKILL,
108                 .active_low     = 1,
109         }
110 };
111
112 static struct gpio_led tl_wr940n_v6_leds_gpio[] __initdata = {
113         {
114                 .name           = "tp-link:blue:wan",
115                 .gpio           = TL_WR940N_V6_GPIO_LED_WAN_BLUE,
116                 .active_low     = 1,
117         },
118         {
119                 .name           = "tp-link:orange:diag",
120                 .gpio           = TL_WR940N_V6_GPIO_LED_DIAG_ORANGE,
121                 .active_low     = 0,
122         },
123 };
124
125
126 static const char *tl_wr940n_part_probes[] = {
127         "tp-link",
128         NULL,
129 };
130
131 static struct flash_platform_data tl_wr940n_flash_data = {
132         .part_probes    = tl_wr940n_part_probes,
133 };
134
135
136 static void __init tl_wr940n_setup(void)
137 {
138         u8 *mac = (u8 *) KSEG1ADDR(0x1f01fc00);
139         u8 *ee = (u8 *) KSEG1ADDR(0x1fff1000);
140
141         ath79_register_m25p80(&tl_wr940n_flash_data);
142
143         ath79_register_mdio(0, 0x0);
144
145         ath79_init_mac(ath79_eth0_data.mac_addr, mac, 1);
146         ath79_init_mac(ath79_eth1_data.mac_addr, mac, 0);
147
148         ath79_switch_data.phy4_mii_en = 1;
149
150         ath79_register_eth(0);
151         ath79_register_eth(1);
152
153         ath79_register_wmac(ee, mac);
154
155 }
156
157 static void __init tl_wr940n_v4_setup(void)
158 {
159         tl_wr940n_setup();
160
161         ath79_register_leds_gpio(-1, ARRAY_SIZE(tl_wr940n_v4_leds_gpio),
162                                  tl_wr940n_v4_leds_gpio);
163
164         ath79_register_gpio_keys_polled(-1, TL_WR940N_KEYS_POLL_INTERVAL,
165                                         ARRAY_SIZE(tl_wr940n_v4_gpio_keys),
166                                         tl_wr940n_v4_gpio_keys);
167 }
168
169 static void __init tl_wr940n_v6_setup(void)
170 {
171         tl_wr940n_setup();
172
173         ath79_register_leds_gpio(-1, ARRAY_SIZE(tl_wr940n_v6_leds_gpio),
174                                  tl_wr940n_v6_leds_gpio);
175
176         ath79_register_gpio_keys_polled(-1, TL_WR940N_KEYS_POLL_INTERVAL,
177                                         ARRAY_SIZE(tl_wr940n_v4_gpio_keys),
178                                         tl_wr940n_v4_gpio_keys);
179 }
180
181 MIPS_MACHINE(ATH79_MACH_TL_WR940N_V4, "TL-WR940N-v4", "TP-LINK TL-WR940N v4",
182              tl_wr940n_v4_setup);
183 MIPS_MACHINE(ATH79_MACH_TL_WR940N_V6, "TL-WR940N-v6", "TP-LINK TL-WR940N v6",
184              tl_wr940n_v6_setup);