ramips: support jumbo frame on mt7621 up to 2k
[openwrt/staging/lynxis.git] / target / linux / ar71xx / files / arch / mips / ath79 / mach-tlt-rut900.c
1 /*
2 * TELTONIKA TLT-RUT900 board support
3 *
4 * Copyright (C) 2014 Teltonika
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/phy.h>
12 #include <linux/gpio.h>
13 #include <linux/platform_device.h>
14 #include <linux/ath9k_platform.h>
15 #include <linux/ar8216_platform.h>
16 #include <linux/mmc/host.h>
17 #include <linux/spi/spi.h>
18 #include <linux/spi/mmc_spi.h>
19
20 #include <asm/mach-ath79/ar71xx_regs.h>
21
22 #include "common.h"
23 #include "dev-eth.h"
24 #include "dev-gpio-buttons.h"
25 #include "dev-leds-gpio.h"
26 #include "dev-m25p80.h"
27 #include "dev-spi.h"
28 #include "dev-usb.h"
29 #include "dev-wmac.h"
30 #include "machtypes.h"
31
32 #include <linux/i2c.h>
33 #include <linux/i2c-algo-bit.h>
34 #include <linux/i2c-gpio.h>
35
36 /* I2C interface */
37 #define rut900_GPIO_SDA 17
38 #define rut900_GPIO_SCK 16
39
40 #define RUT900_GPIO_LED_BAR0 48
41 #define RUT900_GPIO_LED_BAR1 49
42 #define RUT900_GPIO_LED_BAR2 50
43 #define RUT900_GPIO_LED_BAR3 51
44 #define RUT900_GPIO_LED_BAR4 52
45 #define RUT900_GPIO_LED_ST_GRE 54
46 #define RUT900_GPIO_LED_ST_RED 53
47 //#define RUT900_GPIO_LED_WAN 18
48 #define RUT900_GPIO_LED_LAN1 14
49 #define RUT900_GPIO_LED_LAN2 13
50 #define RUT900_GPIO_LED_LAN3 22
51 #define RUT900_GPIO_LED_WAN 1
52
53 #define RUT900_GPIO_EXTERNAL_LNA0 2
54 //#define RUT900_GPIO_EXTERNAL_LNA1 3
55
56 #define RUT900_GPIO_BTN_RESET 15
57 #define RUT900_GPIO_BTN_EXPANDER 4
58 #define RUT900_GPIO_BTN_TEST 58
59 #define RUT900_GPIO_MMC_CS 3
60
61 //#define RUT900_GPIO_EXPANDER_POWER 11
62
63 #define RUT900_KEYS_POLL_INTERVAL 20 /* msecs */
64 #define RUT900_KEYS_DEBOUNCE_INTERVAL (3 * RUT900_KEYS_POLL_INTERVAL)
65 #define RUT900_KEYS_DEBOUNCE_INTERVAL_DIN 20
66
67 #define RUT900_MAC0_OFFSET 0
68 #define RUT900_MAC1_OFFSET 6
69 #define RUT900_WMAC_CALDATA_OFFSET 0x1000
70 #define RUT900_PCIE_CALDATA_OFFSET 0x5000
71
72 static struct i2c_gpio_platform_data rut900_i2c_device_platdata = {
73 .sda_pin = rut900_GPIO_SDA,
74 .scl_pin = rut900_GPIO_SCK,
75 .udelay = 10,
76 };
77
78 static struct platform_device rut900_i2c_device = {
79 .name = "i2c-gpio",
80 .id = 0,
81 .num_resources = 0,
82 .resource = NULL,
83 .dev = {
84 .platform_data = &rut900_i2c_device_platdata,
85 },
86 };
87
88 static struct i2c_board_info rut900_i2c_devs[] __initdata = {
89 {
90 I2C_BOARD_INFO("pca9539", 0x74),
91 },
92 {
93 I2C_BOARD_INFO("mcp3221", 0x4D),
94 },
95 };
96
97 static void rut900_i2c_init(void)
98 {
99 /* The gpio interface */
100 platform_device_register(&rut900_i2c_device);
101 /* I2C devices */
102 i2c_register_board_info(0, rut900_i2c_devs, ARRAY_SIZE(rut900_i2c_devs));
103 }
104
105 //Flash partitions are calcutated in drivers/mtd/tltpart.c
106 static const char *rut900_part_probes[] = {
107 "tlt",
108 NULL,
109 };
110
111 static struct flash_platform_data rut900_flash_data = {
112 .part_probes = rut900_part_probes,
113 };
114
115 static struct gpio_led rut900_leds_gpio[] __initdata = {
116 {
117 .name = "tlt:green:signal_bar0",
118 .gpio = RUT900_GPIO_LED_BAR0,
119 .active_low = 0,
120 },
121 {
122 .name = "tlt:green:signal_bar1",
123 .gpio = RUT900_GPIO_LED_BAR1,
124 .active_low = 0,
125 },
126 {
127 .name = "tlt:green:signal_bar2",
128 .gpio = RUT900_GPIO_LED_BAR2,
129 .active_low = 0,
130 },
131 {
132 .name = "tlt:green:signal_bar3",
133 .gpio = RUT900_GPIO_LED_BAR3,
134 .active_low = 0,
135 },
136 {
137 .name = "tlt:green:signal_bar4",
138 .gpio = RUT900_GPIO_LED_BAR4,
139 .active_low = 0,
140 },
141 {
142 .name = "tlt:green:status",
143 .gpio = RUT900_GPIO_LED_ST_GRE,
144 .active_low = 0,
145 },
146 {
147 .name = "tlt:red:status",
148 .gpio = RUT900_GPIO_LED_ST_RED,
149 .active_low = 0,
150 },
151
152 };
153
154 static struct gpio_keys_button rut900_gpio_keys[] __initdata = {
155 {
156 .desc = "Reset button",
157 .type = EV_KEY,
158 .code = KEY_RESTART,
159 .debounce_interval = RUT900_KEYS_DEBOUNCE_INTERVAL,
160 .gpio = RUT900_GPIO_BTN_RESET,
161 .active_low = 1,
162 },
163 {
164 .desc = "Expander interrupt",
165 .type = EV_KEY,
166 .code = KEY_RFKILL,
167 .debounce_interval = RUT900_KEYS_DEBOUNCE_INTERVAL_DIN,
168 .gpio = RUT900_GPIO_BTN_EXPANDER,
169 },
170 };
171
172 static struct spi_board_info ath79_spi_info[] = {
173 {
174 .bus_num = 0,
175 .chip_select = 0,
176 .max_speed_hz = 25000000,
177 .modalias = "m25p80",
178 .platform_data = &rut900_flash_data,
179 },
180 {
181 .bus_num = 0,
182 .chip_select = 1,
183 .max_speed_hz = 25000000,
184 .modalias = "mmc_spi",
185 }
186 };
187
188 static struct ath79_spi_platform_data ath79_spi_data = {
189 .bus_num = 0,
190 .num_chipselect = 2,
191 };
192
193 static void __init rut900_setup(void)
194 {
195 u8 *mac = (u8 *) KSEG1ADDR(0x1f020000);
196 u8 *art = (u8 *) KSEG1ADDR(0x1f030000);
197 u8 tmpmac[ETH_ALEN];
198
199 ath79_register_spi(&ath79_spi_data, ath79_spi_info, 2);
200 ath79_register_leds_gpio(-1, ARRAY_SIZE(rut900_leds_gpio),
201 rut900_leds_gpio);
202 ath79_register_gpio_keys_polled(-1, RUT900_KEYS_POLL_INTERVAL,
203 ARRAY_SIZE(rut900_gpio_keys),
204 rut900_gpio_keys);
205
206 ath79_wmac_set_ext_lna_gpio(0, RUT900_GPIO_EXTERNAL_LNA0);
207
208 ath79_init_mac(tmpmac, mac, 2);
209 ath79_register_wmac(art + RUT900_WMAC_CALDATA_OFFSET, tmpmac);
210
211
212 ath79_setup_ar934x_eth_cfg(AR934X_ETH_CFG_SW_ONLY_MODE);
213
214 ath79_register_mdio(1, 0x0);
215
216 /* LAN */
217 ath79_init_mac(ath79_eth1_data.mac_addr, mac, 0);
218
219 /* GMAC1 is connected to the internal switch */
220 ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_GMII;
221
222 ath79_register_eth(1);
223
224 /* WAN */
225 ath79_init_mac(ath79_eth0_data.mac_addr, mac, 1);
226
227 /* GMAC0 is connected to the PHY4 of the internal switch */
228 ath79_switch_data.phy4_mii_en = 1;
229 ath79_switch_data.phy_poll_mask = BIT(4);
230 ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
231 ath79_eth0_data.phy_mask = BIT(4);
232 ath79_eth0_data.mii_bus_dev = &ath79_mdio1_device.dev;
233
234 ath79_register_eth(0);
235
236 ath79_register_usb();
237
238 ath79_gpio_output_select(RUT900_GPIO_LED_LAN1,
239 AR934X_GPIO_OUT_LED_LINK3);
240 ath79_gpio_output_select(RUT900_GPIO_LED_LAN2,
241 AR934X_GPIO_OUT_LED_LINK2);
242 ath79_gpio_output_select(RUT900_GPIO_LED_LAN3,
243 AR934X_GPIO_OUT_LED_LINK1);
244 ath79_gpio_output_select(RUT900_GPIO_LED_WAN,
245 AR934X_GPIO_OUT_LED_LINK4);
246
247 //SPI CS1
248 ath79_gpio_output_select(RUT900_GPIO_MMC_CS,
249 7);
250
251 //HS UART
252 ath79_gpio_output_select(18, 79);
253
254 /* Init I2C interface */
255 rut900_i2c_init();
256 }
257
258 MIPS_MACHINE(ATH79_MACH_TLT_RUT900, "TLT-RUT900",
259 "TELTONIKA TLT-RUT900",
260 rut900_setup);