v1.5 branch refresh based upon upstream master @ c8677ca89e53e3be7988d54280fce166cc894a7e
[librecmc/librecmc.git] / target / linux / ar71xx / files / arch / mips / ath79 / mach-gl-ar750s.c
1 /*
2  *  GL.iNet GL-AR750S board support
3  *
4  *  Copyright (C) 2018 luochongjun <luochongjun@gl-inet.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/init.h>
12 #include <linux/pci.h>
13 #include <linux/platform_device.h>
14 #include <linux/ath9k_platform.h>
15 #include <linux/etherdevice.h>
16
17 #include <linux/i2c.h>
18 #include <linux/i2c-gpio.h>
19
20 #include <asm/mach-ath79/ath79.h>
21 #include <asm/mach-ath79/irq.h>
22 #include <asm/mach-ath79/ar71xx_regs.h>
23
24 #include <linux/platform_data/phy-at803x.h>
25 #include <linux/ar8216_platform.h>
26
27 #include "common.h"
28 #include "dev-ap9x-pci.h"
29 #include "dev-eth.h"
30 #include "dev-gpio-buttons.h"
31 #include "dev-leds-gpio.h"
32 #include "dev-spi.h"
33 #include "dev-m25p80.h"
34 #include "dev-wmac.h"
35 #include "dev-usb.h"
36 #include "machtypes.h"
37
38
39 #define GL_AR750S_KEYS_POLL_INTERVAL    20
40 #define GL_AR750S_KEYS_DEBOUNCE_INTERVAL        (3 * GL_AR750S_KEYS_POLL_INTERVAL)
41
42
43 #define GL_AR750S_GPIO_LED_WLAN2G       19
44 #define GL_AR750S_GPIO_LED_WLAN5G       20
45 #define GL_AR750S_GPIO_LED_POWER        1
46 #define GL_AR750S_GPIO_USB_POWER        7
47
48 #define GL_AR750S_GPIO_BTN_RESET        2
49 #define GL_AR750S_GPIO_BTN_RIGHT        8
50
51 #define GL_AR750S_MAC0_OFFSET             0x0000
52 #define GL_AR750S_WMAC_CALDATA_OFFSET     0x1000
53 #define GL_AR750S_PCI_CALDATA_OFFSET      0x5000
54
55 #define GL_AR750S_GPIO_I2C_SDA  5
56 #define GL_AR750S_GPIO_I2C_SCL  21
57
58
59
60 static struct spi_board_info gl_ar750s_spi_info[] = {
61     {
62         .bus_num    = 0,
63         .chip_select    = 0,
64         .max_speed_hz   = 25000000,
65         .modalias   = "m25p80",
66         .platform_data  = NULL,
67     },
68 };
69
70 static struct ath79_spi_platform_data gl_ar750s_spi_data = {
71     .bus_num        = 0,
72     .num_chipselect     = 2,
73 };
74
75 static struct gpio_led gl_ar750s_leds_gpio[] __initdata = {
76         {
77                  .name           = "gl-ar750s:green:power",
78                  .gpio           = GL_AR750S_GPIO_LED_POWER,
79                 .default_state  = LEDS_GPIO_DEFSTATE_KEEP,
80                 .active_low     = 1,
81          },{
82                  .name           = "gl-ar750s:green:usbpower",
83                  .gpio           = GL_AR750S_GPIO_USB_POWER,
84                 .active_low     = 1,
85          },{
86                 .name           = "gl-ar750s:green:wlan2g",
87                 .gpio           = GL_AR750S_GPIO_LED_WLAN2G,
88                 .active_low     = 1,
89         },{
90                 .name           = "gl-ar750s:green:wlan5g",
91                 .gpio           = GL_AR750S_GPIO_LED_WLAN5G,
92                 .active_low     = 0,
93         }
94 };
95
96 static struct gpio_keys_button gl_ar750s_gpio_keys[] __initdata = {
97     {
98         .desc                   = "reset",
99         .type                   = EV_KEY,
100         .code                   = KEY_RESTART,
101         .debounce_interval      = GL_AR750S_KEYS_DEBOUNCE_INTERVAL,
102         .gpio                   = GL_AR750S_GPIO_BTN_RESET,
103         .active_low             = 1,
104        }, {
105         .desc                   = "right",
106         .type                   = EV_KEY,
107         .code                   = BTN_0,
108         .debounce_interval      = GL_AR750S_KEYS_DEBOUNCE_INTERVAL,
109         .gpio                   = GL_AR750S_GPIO_BTN_RIGHT,
110         .active_low             = 1,
111        },
112 };
113
114 static struct i2c_gpio_platform_data gl_ar750s_i2c_gpio_data = {
115         .sda_pin        = GL_AR750S_GPIO_I2C_SDA,
116         .scl_pin        = GL_AR750S_GPIO_I2C_SCL,
117 };
118
119 static struct platform_device gl_ar750s_i2c_gpio_device = {
120         .name           = "i2c-gpio",
121         .id             = 0,
122         .dev = {
123                 .platform_data  = &gl_ar750s_i2c_gpio_data,
124         }
125
126 };
127
128 static struct ar8327_pad_cfg gl_ar750s_ar8327_pad0_cfg = {
129         .mode = AR8327_PAD_MAC_SGMII,
130         .sgmii_delay_en = true,
131 };
132
133 static struct ar8327_platform_data gl_ar750s_ar8327_data = {
134         .pad0_cfg = &gl_ar750s_ar8327_pad0_cfg,
135         .port0_cfg = {
136                 .force_link = 1,
137                 .speed = AR8327_PORT_SPEED_1000,
138                 .duplex = 1,
139                 .txpause = 1,
140                 .rxpause = 1,
141         },
142 };
143
144
145 static struct mdio_board_info gl_ar750s_mdio0_info[] = {
146         {
147                 .bus_id = "ag71xx-mdio.0",
148                 .phy_addr = 0,
149                 .platform_data = &gl_ar750s_ar8327_data,
150         },
151 };
152
153 static void __init  gl_ar750s_setup(void)
154 {
155         u8 *eeprom = (u8 *) KSEG1ADDR(0x1f050000);
156
157         ath79_register_spi(&gl_ar750s_spi_data, gl_ar750s_spi_info, 1);
158
159         ath79_init_mac(ath79_eth0_data.mac_addr,
160                        eeprom + GL_AR750S_MAC0_OFFSET, 0);
161
162         ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_SGMII;
163         ath79_eth0_data.mii_bus_dev = &ath79_mdio0_device.dev;
164         ath79_eth0_data.phy_mask = BIT(0);
165
166         mdiobus_register_board_info(gl_ar750s_mdio0_info,
167                                     ARRAY_SIZE(gl_ar750s_mdio0_info));
168
169         ath79_register_mdio(0, 0x00);
170         ath79_register_eth(0);
171
172
173         ath79_register_usb();
174
175
176         ath79_register_wmac(eeprom + GL_AR750S_WMAC_CALDATA_OFFSET, NULL);
177
178
179         ap91_pci_init(eeprom + GL_AR750S_PCI_CALDATA_OFFSET, NULL);
180
181         platform_device_register(&gl_ar750s_i2c_gpio_device);
182
183         ath79_register_leds_gpio(-1, ARRAY_SIZE(gl_ar750s_leds_gpio),
184                                  gl_ar750s_leds_gpio);
185
186         ath79_register_gpio_keys_polled(-1, GL_AR750S_KEYS_POLL_INTERVAL,
187                                         ARRAY_SIZE(gl_ar750s_gpio_keys),
188                                         gl_ar750s_gpio_keys);
189 }
190
191
192 MIPS_MACHINE(ATH79_MACH_GL_AR750S, "GL-AR750S", "GL-AR750S",
193          gl_ar750s_setup);