First git repo commit for the libreCMC project
[librecmc/librecmc.git] / target / linux / ar71xx / files / arch / mips / ath79 / mach-ap90q.c
1 /*
2  * Support for YunCore boards:
3  * - AP90Q
4  * - CPE830
5  *
6  * Copyright (C) 2016 Piotr Dymacz <pepe2k@gmail.com>
7  *
8  * This program is free software; you can redistribute it and/or modify it
9  * under the terms of the GNU General Public License version 2 as published
10  * by the Free Software Foundation.
11  */
12
13 #include <linux/gpio.h>
14 #include <linux/platform_device.h>
15
16 #include <asm/mach-ath79/ath79.h>
17 #include <asm/mach-ath79/ar71xx_regs.h>
18
19 #include "common.h"
20 #include "dev-eth.h"
21 #include "dev-gpio-buttons.h"
22 #include "dev-leds-gpio.h"
23 #include "dev-m25p80.h"
24 #include "dev-usb.h"
25 #include "dev-wmac.h"
26 #include "machtypes.h"
27
28 /* AP90Q */
29 #define AP90Q_GPIO_LED_WAN      4
30 #define AP90Q_GPIO_LED_WLAN     12
31 #define AP90Q_GPIO_LED_LAN      16
32
33 #define AP90Q_GPIO_BTN_RESET    17
34
35 #define AP90Q_KEYS_POLL_INTERVAL        20
36 #define AP90Q_KEYS_DEBOUNCE_INTERVAL    (3 * AP90Q_KEYS_POLL_INTERVAL)
37
38 static struct gpio_led ap90q_leds_gpio[] __initdata = {
39         {
40                 .name           = "ap90q:green:lan",
41                 .gpio           = AP90Q_GPIO_LED_LAN,
42                 .active_low     = 1,
43         },
44         {
45                 .name           = "ap90q:green:wan",
46                 .gpio           = AP90Q_GPIO_LED_WAN,
47                 .active_low     = 1,
48         },
49         {
50                 .name           = "ap90q:green:wlan",
51                 .gpio           = AP90Q_GPIO_LED_WLAN,
52                 .active_low     = 1,
53         },
54 };
55
56 static struct gpio_keys_button ap90q_gpio_keys[] __initdata = {
57         {
58                 .desc           = "reset",
59                 .type           = EV_KEY,
60                 .code           = KEY_RESTART,
61                 .debounce_interval = AP90Q_KEYS_DEBOUNCE_INTERVAL,
62                 .gpio           = AP90Q_GPIO_BTN_RESET,
63                 .active_low     = 1,
64         },
65 };
66
67 /* CPE830 */
68 #define CPE830_GPIO_LED_LINK4   0
69 #define CPE830_GPIO_LED_LINK1   1
70 #define CPE830_GPIO_LED_LINK2   2
71 #define CPE830_GPIO_LED_LINK3   3
72 #define CPE830_GPIO_LED_WAN     4
73 #define CPE830_GPIO_LED_WLAN    12
74 #define CPE830_GPIO_LED_LAN     16
75
76 #define CPE830_GPIO_BTN_RESET   17
77
78 static struct gpio_led cpe830_leds_gpio[] __initdata = {
79         {
80                 .name           = "cpe830:green:lan",
81                 .gpio           = CPE830_GPIO_LED_LAN,
82                 .active_low     = 1,
83         },
84         {
85                 .name           = "cpe830:green:wan",
86                 .gpio           = CPE830_GPIO_LED_WAN,
87                 .active_low     = 1,
88         },
89         {
90                 .name           = "cpe830:green:wlan",
91                 .gpio           = CPE830_GPIO_LED_WLAN,
92                 .active_low     = 1,
93         },
94         {
95                 .name           = "cpe830:green:link1",
96                 .gpio           = CPE830_GPIO_LED_LINK1,
97                 .active_low     = 1,
98         },
99         {
100                 .name           = "cpe830:green:link2",
101                 .gpio           = CPE830_GPIO_LED_LINK2,
102                 .active_low     = 1,
103         },
104         {
105                 .name           = "cpe830:green:link3",
106                 .gpio           = CPE830_GPIO_LED_LINK3,
107                 .active_low     = 1,
108         },
109         {
110                 .name           = "cpe830:green:link4",
111                 .gpio           = CPE830_GPIO_LED_LINK4,
112                 .active_low     = 1,
113         },
114 };
115
116 static void __init ap90q_cpe830_common_setup(void)
117 {
118         u8 *art = (u8 *) KSEG1ADDR(0x1fff1000);
119         u8 *mac = (u8 *) KSEG1ADDR(0x1fff0000);
120
121         ath79_register_m25p80(NULL);
122
123         ath79_setup_ar933x_phy4_switch(false, false);
124
125         ath79_register_mdio(0, 0x0);
126
127         ath79_switch_data.phy4_mii_en = 1;
128         ath79_switch_data.phy_poll_mask |= BIT(4);
129
130         /* LAN */
131         ath79_eth1_data.duplex = DUPLEX_FULL;
132         ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_GMII;
133         ath79_eth1_data.speed = SPEED_1000;
134         ath79_init_mac(ath79_eth1_data.mac_addr, mac, 1);
135         ath79_register_eth(1);
136
137         /* WAN */
138         ath79_eth0_data.duplex = DUPLEX_FULL;
139         ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
140         ath79_eth0_data.speed = SPEED_100;
141         ath79_eth0_data.phy_mask = BIT(4);
142         ath79_init_mac(ath79_eth0_data.mac_addr, mac, 0);
143         ath79_register_eth(0);
144
145         ath79_register_wmac(art, NULL);
146
147         /* For LED on GPIO4 */
148         ath79_gpio_function_disable(AR934X_GPIO_FUNC_CLK_OBS4_EN);
149
150         ath79_gpio_direction_select(AP90Q_GPIO_LED_LAN, true);
151         ath79_gpio_direction_select(AP90Q_GPIO_LED_WAN, true);
152         ath79_gpio_direction_select(AP90Q_GPIO_LED_WLAN, true);
153
154         /* Mute LEDs on boot */
155         gpio_set_value(AP90Q_GPIO_LED_LAN, 1);
156         gpio_set_value(AP90Q_GPIO_LED_WAN, 1);
157
158         ath79_gpio_output_select(AP90Q_GPIO_LED_LAN, 0);
159         ath79_gpio_output_select(AP90Q_GPIO_LED_WAN, 0);
160         ath79_gpio_output_select(AP90Q_GPIO_LED_WLAN, 0);
161
162         ath79_register_gpio_keys_polled(-1, AP90Q_KEYS_POLL_INTERVAL,
163                                         ARRAY_SIZE(ap90q_gpio_keys),
164                                         ap90q_gpio_keys);
165 }
166
167 static void __init ap90q_setup(void)
168 {
169         ap90q_cpe830_common_setup();
170
171         ath79_register_leds_gpio(-1, ARRAY_SIZE(ap90q_leds_gpio),
172                                  ap90q_leds_gpio);
173 }
174
175 MIPS_MACHINE(ATH79_MACH_AP90Q, "AP90Q", "YunCore AP90Q", ap90q_setup);
176
177 static void __init cpe830_setup(void)
178 {
179         ap90q_cpe830_common_setup();
180
181         ath79_gpio_direction_select(CPE830_GPIO_LED_LINK1, true);
182         ath79_gpio_direction_select(CPE830_GPIO_LED_LINK2, true);
183         ath79_gpio_direction_select(CPE830_GPIO_LED_LINK3, true);
184         ath79_gpio_direction_select(CPE830_GPIO_LED_LINK4, true);
185
186         /* Mute LEDs on boot */
187         gpio_set_value(CPE830_GPIO_LED_LINK1, 1);
188         gpio_set_value(CPE830_GPIO_LED_LINK2, 1);
189         gpio_set_value(CPE830_GPIO_LED_LINK3, 1);
190         gpio_set_value(CPE830_GPIO_LED_LINK4, 1);
191
192         ath79_gpio_output_select(CPE830_GPIO_LED_LINK1, 0);
193         ath79_gpio_output_select(CPE830_GPIO_LED_LINK2, 0);
194         ath79_gpio_output_select(CPE830_GPIO_LED_LINK3, 0);
195         ath79_gpio_output_select(CPE830_GPIO_LED_LINK4, 0);
196
197         ath79_register_leds_gpio(-1, ARRAY_SIZE(cpe830_leds_gpio),
198                                  cpe830_leds_gpio);
199 }
200
201 MIPS_MACHINE(ATH79_MACH_CPE830, "CPE830", "YunCore CPE830", cpe830_setup);