ar71xx: add support for gl-mifi
[openwrt/openwrt.git] / target / linux / ar71xx / files / arch / mips / ath79 / mach-omy-g1.c
1 /*
2 * OMYlink OMY-G1 board support
3 *
4 * Copyright (C) 2016 L. D. Pinney <ldpinney@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 OMY_G1_GPIO_LED_WLAN 13
27 #define OMY_G1_GPIO_LED_WAN 18
28 #define OMY_G1_GPIO_LED_LAN 19
29
30 #define OMY_G1_GPIO_USB_POWER 4
31
32 #define OMY_G1_GPIO_BTN_RESET 17
33
34 #define OMY_G1_KEYS_POLL_INTERVAL 20 /* msecs */
35 #define OMY_G1_KEYS_DEBOUNCE_INTERVAL (3 * OMY_G1_KEYS_POLL_INTERVAL)
36
37 static const char *omy_g1_part_probes[] = {
38 "tp-link",
39 NULL,
40 };
41
42 static struct flash_platform_data omy_g1_flash_data = {
43 .part_probes = omy_g1_part_probes,
44 };
45
46 static struct gpio_led omy_g1_leds_gpio[] __initdata = {
47 {
48 .name = "omy:green:wlan",
49 .gpio = OMY_G1_GPIO_LED_WLAN,
50 .active_low = 1,
51 },{
52 .name = "omy:green:wan",
53 .gpio = OMY_G1_GPIO_LED_WAN,
54 .active_low = 1,
55 }, {
56 .name = "omy:green:lan",
57 .gpio = OMY_G1_GPIO_LED_LAN,
58 .active_low = 1,
59 },
60 };
61
62 static struct gpio_keys_button omy_g1_gpio_keys[] __initdata = {
63 {
64 .desc = "Reset button",
65 .type = EV_KEY,
66 .code = KEY_RESTART,
67 .debounce_interval = OMY_G1_KEYS_DEBOUNCE_INTERVAL,
68 .gpio = OMY_G1_GPIO_BTN_RESET,
69 .active_low = 1,
70 }
71 };
72
73 static void __init omy_g1_setup(void)
74 {
75 u8 *mac = (u8 *) KSEG1ADDR(0x1f01fc00);
76 u8 *ee = (u8 *) KSEG1ADDR(0x1fff1000);
77
78 ath79_gpio_function_setup(AR934X_GPIO_FUNC_JTAG_DISABLE,
79 AR934X_GPIO_FUNC_CLK_OBS4_EN);
80
81 ath79_register_m25p80(&omy_g1_flash_data);
82
83 ath79_register_leds_gpio(-1, ARRAY_SIZE(omy_g1_leds_gpio),
84 omy_g1_leds_gpio);
85
86 ath79_register_gpio_keys_polled(1, OMY_G1_KEYS_POLL_INTERVAL,
87 ARRAY_SIZE(omy_g1_gpio_keys),
88 omy_g1_gpio_keys);
89
90 ath79_gpio_output_select(OMY_G1_GPIO_USB_POWER,
91 AR934X_GPIO_OUT_GPIO);
92
93 ath79_setup_ar934x_eth_cfg(AR934X_ETH_CFG_SW_PHY_SWAP);
94
95 ath79_register_mdio(1, 0x0);
96
97 ath79_init_mac(ath79_eth0_data.mac_addr, mac, -1);
98 ath79_init_mac(ath79_eth1_data.mac_addr, mac, 0);
99
100 ath79_switch_data.phy4_mii_en = 1;
101 ath79_switch_data.phy_poll_mask = BIT(0);
102 ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
103 ath79_eth0_data.phy_mask = BIT(0);
104 ath79_eth0_data.mii_bus_dev = &ath79_mdio1_device.dev;
105 ath79_register_eth(0);
106
107 ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_GMII;
108 ath79_register_eth(1);
109
110 ath79_register_wmac(ee, mac);
111
112 ath79_gpio_output_select(OMY_G1_GPIO_USB_POWER,
113 AR934X_GPIO_OUT_GPIO);
114
115 gpio_request_one(OMY_G1_GPIO_USB_POWER,
116 GPIOF_OUT_INIT_HIGH | GPIOF_EXPORT_DIR_FIXED,
117 "USB power");
118
119 ath79_register_usb();
120 }
121
122 MIPS_MACHINE(ATH79_MACH_OMY_G1, "OMY-G1", "OMYlink OMY-G1",
123 omy_g1_setup);