ar71xx: add support for YunCore AP90Q
[openwrt/staging/wigyori.git] / target / linux / ar71xx / files / arch / mips / ath79 / mach-ap90q.c
1 /*
2 * YunCore AP90Q board support
3 *
4 * Copyright (C) 2016 Piotr Dymacz <pepe2k@gmail.com>
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-usb.h"
23 #include "dev-wmac.h"
24 #include "machtypes.h"
25
26 #define AP90Q_GPIO_LED_WAN 4
27 #define AP90Q_GPIO_LED_WLAN 12
28 #define AP90Q_GPIO_LED_LAN 16
29
30 #define AP90Q_GPIO_BTN_RESET 17
31
32 #define AP90Q_KEYS_POLL_INTERVAL 20
33 #define AP90Q_KEYS_DEBOUNCE_INTERVAL (3 * AP90Q_KEYS_POLL_INTERVAL)
34
35 static struct gpio_led ap90q_leds_gpio[] __initdata = {
36 {
37 .name = "ap90q:green:lan",
38 .gpio = AP90Q_GPIO_LED_LAN,
39 .active_low = 1,
40 },
41 {
42 .name = "ap90q:green:wan",
43 .gpio = AP90Q_GPIO_LED_WAN,
44 .active_low = 1,
45 },
46 {
47 .name = "ap90q:green:wlan",
48 .gpio = AP90Q_GPIO_LED_WLAN,
49 .active_low = 1,
50 },
51 };
52
53 static struct gpio_keys_button ap90q_gpio_keys[] __initdata = {
54 {
55 .desc = "reset",
56 .type = EV_KEY,
57 .code = KEY_RESTART,
58 .debounce_interval = AP90Q_KEYS_DEBOUNCE_INTERVAL,
59 .gpio = AP90Q_GPIO_BTN_RESET,
60 .active_low = 1,
61 },
62 };
63
64 static void __init ap90q_gpio_setup(void)
65 {
66 /* For LED on GPIO4 */
67 ath79_gpio_function_disable(AR934X_GPIO_FUNC_CLK_OBS4_EN);
68
69 ath79_gpio_direction_select(AP90Q_GPIO_LED_LAN, true);
70 ath79_gpio_direction_select(AP90Q_GPIO_LED_WAN, true);
71 ath79_gpio_direction_select(AP90Q_GPIO_LED_WLAN, true);
72
73 /* Mute LEDs on boot */
74 gpio_set_value(AP90Q_GPIO_LED_LAN, 1);
75 gpio_set_value(AP90Q_GPIO_LED_WAN, 1);
76
77 ath79_gpio_output_select(AP90Q_GPIO_LED_LAN, 0);
78 ath79_gpio_output_select(AP90Q_GPIO_LED_WAN, 0);
79 ath79_gpio_output_select(AP90Q_GPIO_LED_WLAN, 0);
80
81 ath79_register_leds_gpio(-1, ARRAY_SIZE(ap90q_leds_gpio),
82 ap90q_leds_gpio);
83
84 ath79_register_gpio_keys_polled(-1, AP90Q_KEYS_POLL_INTERVAL,
85 ARRAY_SIZE(ap90q_gpio_keys),
86 ap90q_gpio_keys);
87 }
88
89 static void __init ap90q_setup(void)
90 {
91 u8 *art = (u8 *) KSEG1ADDR(0x1fff1000);
92 u8 *mac = (u8 *) KSEG1ADDR(0x1fff0000);
93
94 ath79_register_m25p80(NULL);
95
96 ap90q_gpio_setup();
97
98 ath79_setup_ar933x_phy4_switch(false, false);
99
100 ath79_register_mdio(0, 0x0);
101
102 ath79_switch_data.phy4_mii_en = 1;
103 ath79_switch_data.phy_poll_mask |= BIT(4);
104
105 /* LAN */
106 ath79_eth1_data.duplex = DUPLEX_FULL;
107 ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_GMII;
108 ath79_eth1_data.speed = SPEED_1000;
109 ath79_init_mac(ath79_eth1_data.mac_addr, mac, 1);
110 ath79_register_eth(1);
111
112 /* WAN */
113 ath79_eth0_data.duplex = DUPLEX_FULL;
114 ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
115 ath79_eth0_data.speed = SPEED_100;
116 ath79_eth0_data.phy_mask = BIT(4);
117 ath79_init_mac(ath79_eth0_data.mac_addr, mac, 0);
118 ath79_register_eth(0);
119
120 ath79_register_wmac(art, NULL);
121 }
122
123 MIPS_MACHINE(ATH79_MACH_AP90Q, "AP90Q", "YunCore AP90Q", ap90q_setup);