ar71xx: add support for YunCore CPE830
[oweals/openwrt.git] / target / linux / ar71xx / files / arch / mips / ath79 / mach-gl-ar300m.c
1 /*
2  *  GLI AR300M(D) board support
3  *
4  *  Copyright (C) 2011 dongyuqi <729650915@qq.com>
5  *  Copyright (C) 2011-2012 Gabor Juhos <juhosg@openwrt.org>
6  *  Copyright (C) 2013 alzhao <alzhao@gmail.com>
7  *  Copyright (C) 2014 Michel Stempin <michel.stempin@wanadoo.fr>
8  *
9  *  This program is free software; you can redistribute it and/or modify it
10  *  under the terms of the GNU General Public License version 2 as published
11  *  by the Free Software Foundation.
12  */
13
14 #include <linux/gpio.h>
15 #include <linux/pci.h>
16
17 #include <asm/mach-ath79/ath79.h>
18 #include <asm/mach-ath79/ar71xx_regs.h>
19
20 #include "common.h"
21 #include "dev-ap9x-pci.h"
22 #include "dev-eth.h"
23 #include "dev-gpio-buttons.h"
24 #include "dev-leds-gpio.h"
25 #include "dev-m25p80.h"
26 #include "dev-usb.h"
27 #include "dev-spi.h"
28 #include "dev-wmac.h"
29 #include "machtypes.h"
30 #include "pci.h"
31
32 #define GL_AR300M_GPIO_LED_USB          2
33 #define GL_AR300M_GPIO_LED_WLAN         14
34 #define GL_AR300M_GPIO_LED_LAN          13
35 #define GL_AR300M_GPIO_LED_SYSTEM       12
36 #define GL_AR300M_GPIO_BTN_RESET        3
37 #define GL_AR300M_GPIO_BTN_LEFT         0
38 #define GL_AR300M_GPIO_BTN_RIGHT        1
39
40 #define GL_AR300M_KEYS_POLL_INTERVAL        20  /* msecs */
41 #define GL_AR300M_KEYS_DEBOUNCE_INTERVAL    (3 * GL_AR300M_KEYS_POLL_INTERVAL)
42
43 #define GL_AR300M_MAC0_OFFSET   0
44 #define GL_AR300M_MAC1_OFFSET   6
45 #define GL_AR300M_WMAC_CALDATA_OFFSET   0x1000
46 #define GL_AR300M_PCIE_CALDATA_OFFSET   0x5000
47
48 static struct gpio_led gl_ar300m_leds_gpio[] __initdata = {
49     {
50         .name = "gl-ar300m:usb",
51         .gpio = GL_AR300M_GPIO_LED_USB,
52         .active_low = 0,
53         .default_state = 1,
54     },
55     {
56         .name = "gl-ar300m:wlan",
57         .gpio = GL_AR300M_GPIO_LED_WLAN,
58         .active_low = 1,
59     },
60     {
61         .name = "gl-ar300m:lan",
62         .gpio = GL_AR300M_GPIO_LED_LAN,
63         .active_low = 1,
64     },
65     {
66         .name = "gl-ar300m:system",
67         .gpio = GL_AR300M_GPIO_LED_SYSTEM,
68         .active_low = 1,
69         .default_state = 1,
70     },
71 };
72
73 static struct gpio_keys_button gl_ar300m_gpio_keys[] __initdata = {
74     {
75         .desc = "reset",
76         .type = EV_KEY,
77         .code = KEY_RESTART,
78         .debounce_interval = GL_AR300M_KEYS_DEBOUNCE_INTERVAL,
79         .gpio = GL_AR300M_GPIO_BTN_RESET,
80         .active_low = 1,
81     },
82     {
83         .desc = "button right",
84         .type = EV_KEY,
85         .code = BTN_0,
86         .debounce_interval = GL_AR300M_KEYS_DEBOUNCE_INTERVAL,
87         .gpio = GL_AR300M_GPIO_BTN_LEFT,
88         .active_low = 0,
89     },
90     {
91         .desc = "button left",
92         .type = EV_KEY,
93         .code = BTN_1,
94         .debounce_interval = GL_AR300M_KEYS_DEBOUNCE_INTERVAL,
95         .gpio = GL_AR300M_GPIO_BTN_RIGHT,
96         .active_low = 0,
97     },
98 };
99
100 static struct ath79_spi_controller_data gl_ar300m_spi0_cdata =
101 {
102     .cs_type    = ATH79_SPI_CS_TYPE_INTERNAL,
103     .is_flash   = true,
104     .cs_line    = 0,
105 };
106
107 static struct ath79_spi_controller_data gl_ar300m_spi1_cdata =
108 {
109     .cs_type    = ATH79_SPI_CS_TYPE_INTERNAL,
110     .is_flash   = false,
111     .cs_line    = 1,
112 };
113
114 static struct spi_board_info gl_ar300m_spi_info[] = {
115     {
116         .bus_num    = 0,
117         .chip_select    = 0,
118         .max_speed_hz   = 25000000,
119         .modalias   = "m25p80",
120         .controller_data = &gl_ar300m_spi0_cdata,
121         .platform_data  = NULL,
122     },
123     {
124         .bus_num    = 0,
125         .chip_select    = 1,
126         .max_speed_hz   = 25000000,
127         .modalias   = "ath79-spinand",
128         .controller_data = &gl_ar300m_spi1_cdata,
129         .platform_data  = NULL,
130     }
131 };
132
133 static struct ath79_spi_platform_data gl_ar300m_spi_data = {
134     .bus_num        = 0,
135     .num_chipselect     = 2,
136 };
137
138 static void __init gl_ar300m_setup(void)
139 {
140     u8 *art = (u8 *) KSEG1ADDR(0x1fff0000);
141     u8 tmpmac[ETH_ALEN];
142
143     ath79_gpio_function_enable(AR934X_GPIO_FUNC_JTAG_DISABLE);
144     ath79_register_spi(&gl_ar300m_spi_data, gl_ar300m_spi_info, 2);
145
146     /* register gpio LEDs and keys */
147     ath79_register_leds_gpio(-1, ARRAY_SIZE(gl_ar300m_leds_gpio),
148                  gl_ar300m_leds_gpio);
149     ath79_register_gpio_keys_polled(-1, GL_AR300M_KEYS_POLL_INTERVAL,
150                     ARRAY_SIZE(gl_ar300m_gpio_keys),
151                     gl_ar300m_gpio_keys);
152
153     ath79_register_mdio(0, 0x0);
154
155     /* WAN */
156     ath79_init_mac(ath79_eth0_data.mac_addr, art + GL_AR300M_MAC0_OFFSET, 0);
157     ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
158     ath79_eth0_data.speed = SPEED_100;
159     ath79_eth0_data.duplex = DUPLEX_FULL;
160     ath79_eth0_data.phy_mask = BIT(4);
161     ath79_register_eth(0);
162
163     /* LAN */
164     ath79_init_mac(ath79_eth1_data.mac_addr, art + GL_AR300M_MAC1_OFFSET, 0);
165     ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_GMII;
166     ath79_eth1_data.speed = SPEED_1000;
167     ath79_eth1_data.duplex = DUPLEX_FULL;
168     ath79_switch_data.phy_poll_mask |= BIT(4);
169     ath79_switch_data.phy4_mii_en = 1;
170     ath79_register_eth(1);
171
172     ath79_init_mac(tmpmac, art + GL_AR300M_WMAC_CALDATA_OFFSET + 2, 0);
173     ath79_register_wmac(art + GL_AR300M_WMAC_CALDATA_OFFSET, tmpmac);
174
175     /* enable usb */
176     ath79_register_usb();
177     /* enable pci */
178     ath79_register_pci();
179 }
180
181 MIPS_MACHINE(ATH79_MACH_GL_AR300M, "GL-AR300M", "GL-AR300M",
182          gl_ar300m_setup);