2 * P&W (Shenzhen Progress&Win Technologies) R602N and CPE505N boards support
4 * Copyright (C) 2017 Piotr Dymacz <pepe2k@gmail.com>
6 * Based on mach-zbt-we1526.c
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.
13 #include <linux/gpio.h>
14 #include <linux/platform_device.h>
16 #include <asm/mach-ath79/ath79.h>
17 #include <asm/mach-ath79/ar71xx_regs.h>
21 #include "dev-gpio-buttons.h"
22 #include "dev-leds-gpio.h"
23 #include "dev-m25p80.h"
26 #include "machtypes.h"
28 #define PW_GPIO_BTN_RESET 17
30 #define PW_KEYS_POLL_INTERVAL 20 /* msecs */
31 #define PW_KEYS_DEBOUNCE_INTERVAL (3 * PW_KEYS_POLL_INTERVAL)
33 #define PW_MAC0_OFFSET 0x0
34 #define PW_MAC1_OFFSET 0x6
35 #define PW_WMAC_CALDATA_OFFSET 0x1000
37 /* CPE505N GPIO LEDs */
38 #define CPE505N_GPIO_LED_DIAG 12
39 #define CPE505N_GPIO_LED_LAN 11
40 #define CPE505N_GPIO_LED_STATUS 14
41 #define CPE505N_GPIO_LED_WAN 4
42 #define CPE505N_GPIO_LED_WLAN 15
44 static struct gpio_led cpe505n_leds_gpio[] __initdata = {
46 .name = "cpe505n:red:diag",
47 .gpio = CPE505N_GPIO_LED_DIAG,
50 .name = "cpe505n:green:lan",
51 .gpio = CPE505N_GPIO_LED_LAN,
54 .name = "cpe505n:green:status",
55 .gpio = CPE505N_GPIO_LED_STATUS,
58 .name = "cpe505n:green:wan",
59 .gpio = CPE505N_GPIO_LED_WAN,
62 .name = "cpe505n:blue:wlan",
63 .gpio = CPE505N_GPIO_LED_WLAN,
68 static void __init cpe505n_gpio_setup(void)
70 /* For LED on GPIO4 */
71 ath79_gpio_function_disable(AR934X_GPIO_FUNC_CLK_OBS4_EN);
72 ath79_gpio_output_select(CPE505N_GPIO_LED_WAN, 0);
74 ath79_gpio_direction_select(CPE505N_GPIO_LED_DIAG, true);
75 ath79_gpio_direction_select(CPE505N_GPIO_LED_LAN, true);
76 ath79_gpio_direction_select(CPE505N_GPIO_LED_STATUS, true);
77 ath79_gpio_direction_select(CPE505N_GPIO_LED_WAN, true);
78 ath79_gpio_direction_select(CPE505N_GPIO_LED_WLAN, true);
81 gpio_set_value(CPE505N_GPIO_LED_DIAG, 1);
82 gpio_set_value(CPE505N_GPIO_LED_LAN, 1);
83 gpio_set_value(CPE505N_GPIO_LED_STATUS, 1);
84 gpio_set_value(CPE505N_GPIO_LED_WAN, 1);
85 gpio_set_value(CPE505N_GPIO_LED_WLAN, 1);
87 ath79_register_leds_gpio(-1, ARRAY_SIZE(cpe505n_leds_gpio),
92 #define R602N_GPIO_LED_LAN1 16
93 #define R602N_GPIO_LED_LAN2 15
94 #define R602N_GPIO_LED_LAN3 14
95 #define R602N_GPIO_LED_LAN4 11
96 #define R602N_GPIO_LED_WAN 4
97 #define R602N_GPIO_LED_WLAN 12
99 static struct gpio_led r602n_leds_gpio[] __initdata = {
101 .name = "r602n:green:lan1",
102 .gpio = R602N_GPIO_LED_LAN1,
105 .name = "r602n:green:lan2",
106 .gpio = R602N_GPIO_LED_LAN2,
109 .name = "r602n:green:lan3",
110 .gpio = R602N_GPIO_LED_LAN3,
113 .name = "r602n:green:lan4",
114 .gpio = R602N_GPIO_LED_LAN4,
117 .name = "r602n:green:wan",
118 .gpio = R602N_GPIO_LED_WAN,
121 .name = "r602n:green:wlan",
122 .gpio = R602N_GPIO_LED_WLAN,
127 static void __init r602n_gpio_setup(void)
129 /* For LED on GPIO4 */
130 ath79_gpio_function_disable(AR934X_GPIO_FUNC_CLK_OBS4_EN);
131 ath79_gpio_output_select(R602N_GPIO_LED_WAN, 0);
133 ath79_gpio_direction_select(R602N_GPIO_LED_LAN1, true);
134 ath79_gpio_direction_select(R602N_GPIO_LED_LAN2, true);
135 ath79_gpio_direction_select(R602N_GPIO_LED_LAN3, true);
136 ath79_gpio_direction_select(R602N_GPIO_LED_LAN4, true);
137 ath79_gpio_direction_select(R602N_GPIO_LED_WAN, true);
138 ath79_gpio_direction_select(R602N_GPIO_LED_WLAN, true);
141 gpio_set_value(R602N_GPIO_LED_LAN1, 1);
142 gpio_set_value(R602N_GPIO_LED_LAN2, 1);
143 gpio_set_value(R602N_GPIO_LED_LAN3, 1);
144 gpio_set_value(R602N_GPIO_LED_LAN4, 1);
145 gpio_set_value(R602N_GPIO_LED_WAN, 1);
146 gpio_set_value(R602N_GPIO_LED_WLAN, 1);
148 ath79_register_leds_gpio(-1, ARRAY_SIZE(r602n_leds_gpio),
152 static struct gpio_keys_button pw_gpio_keys[] __initdata = {
157 .debounce_interval = PW_KEYS_DEBOUNCE_INTERVAL,
158 .gpio = PW_GPIO_BTN_RESET,
163 static void __init r602n_cpe505n_setup(void)
165 u8 *art = (u8 *) KSEG1ADDR(0x1fff0000);
167 ath79_register_m25p80(NULL);
169 ath79_setup_ar933x_phy4_switch(false, false);
171 ath79_register_mdio(0, 0x0);
174 ath79_eth1_data.duplex = DUPLEX_FULL;
175 ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_GMII;
176 ath79_switch_data.phy_poll_mask |= BIT(4);
177 ath79_init_mac(ath79_eth1_data.mac_addr, art + PW_MAC1_OFFSET, 0);
178 ath79_register_eth(1);
181 ath79_switch_data.phy4_mii_en = 1;
182 ath79_eth0_data.duplex = DUPLEX_FULL;
183 ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
184 ath79_eth0_data.phy_mask = BIT(4);
185 ath79_eth0_data.speed = SPEED_100;
186 ath79_init_mac(ath79_eth0_data.mac_addr, art + PW_MAC0_OFFSET, 0);
187 ath79_register_eth(0);
189 ath79_register_wmac(art + PW_WMAC_CALDATA_OFFSET, NULL);
191 ath79_register_gpio_keys_polled(-1, PW_KEYS_POLL_INTERVAL,
192 ARRAY_SIZE(pw_gpio_keys),
196 static void __init cpe505n_setup(void)
198 r602n_cpe505n_setup();
200 cpe505n_gpio_setup();
203 static void __init r602n_setup(void)
205 r602n_cpe505n_setup();
209 ath79_register_usb();
212 MIPS_MACHINE(ATH79_MACH_CPE505N, "CPE505N", "P&W CPE505N", cpe505n_setup);
213 MIPS_MACHINE(ATH79_MACH_R602N, "R602N", "P&W R602N", r602n_setup);