2 * TELTONIKA TLT-RUT900 board support
4 * Copyright (C) 2014 Teltonika
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.
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>
20 #include <asm/mach-ath79/ar71xx_regs.h>
24 #include "dev-gpio-buttons.h"
25 #include "dev-leds-gpio.h"
26 #include "dev-m25p80.h"
30 #include "machtypes.h"
32 #include <linux/i2c.h>
33 #include <linux/i2c-algo-bit.h>
34 #include <linux/i2c-gpio.h>
37 #define rut900_GPIO_SDA 17
38 #define rut900_GPIO_SCK 16
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
53 #define RUT900_GPIO_EXTERNAL_LNA0 2
54 //#define RUT900_GPIO_EXTERNAL_LNA1 3
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
61 //#define RUT900_GPIO_EXPANDER_POWER 11
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
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
72 static struct i2c_gpio_platform_data rut900_i2c_device_platdata
= {
73 .sda_pin
= rut900_GPIO_SDA
,
74 .scl_pin
= rut900_GPIO_SCK
,
78 static struct platform_device rut900_i2c_device
= {
84 .platform_data
= &rut900_i2c_device_platdata
,
88 static struct i2c_board_info rut900_i2c_devs
[] __initdata
= {
90 I2C_BOARD_INFO("pca9539", 0x74),
93 I2C_BOARD_INFO("mcp3221", 0x4D),
97 static void rut900_i2c_init(void)
99 /* The gpio interface */
100 platform_device_register(&rut900_i2c_device
);
102 i2c_register_board_info(0, rut900_i2c_devs
, ARRAY_SIZE(rut900_i2c_devs
));
105 //Flash partitions are calcutated in drivers/mtd/tltpart.c
106 static const char *rut900_part_probes
[] = {
111 static struct flash_platform_data rut900_flash_data
= {
112 .part_probes
= rut900_part_probes
,
115 static struct gpio_led rut900_leds_gpio
[] __initdata
= {
117 .name
= "tlt:green:signal_bar0",
118 .gpio
= RUT900_GPIO_LED_BAR0
,
122 .name
= "tlt:green:signal_bar1",
123 .gpio
= RUT900_GPIO_LED_BAR1
,
127 .name
= "tlt:green:signal_bar2",
128 .gpio
= RUT900_GPIO_LED_BAR2
,
132 .name
= "tlt:green:signal_bar3",
133 .gpio
= RUT900_GPIO_LED_BAR3
,
137 .name
= "tlt:green:signal_bar4",
138 .gpio
= RUT900_GPIO_LED_BAR4
,
142 .name
= "tlt:green:status",
143 .gpio
= RUT900_GPIO_LED_ST_GRE
,
147 .name
= "tlt:red:status",
148 .gpio
= RUT900_GPIO_LED_ST_RED
,
154 static struct gpio_keys_button rut900_gpio_keys
[] __initdata
= {
156 .desc
= "Reset button",
159 .debounce_interval
= RUT900_KEYS_DEBOUNCE_INTERVAL
,
160 .gpio
= RUT900_GPIO_BTN_RESET
,
164 .desc
= "Expander interrupt",
167 .debounce_interval
= RUT900_KEYS_DEBOUNCE_INTERVAL_DIN
,
168 .gpio
= RUT900_GPIO_BTN_EXPANDER
,
172 static struct spi_board_info ath79_spi_info
[] = {
176 .max_speed_hz
= 25000000,
177 .modalias
= "m25p80",
178 .platform_data
= &rut900_flash_data
,
183 .max_speed_hz
= 25000000,
184 .modalias
= "mmc_spi",
188 static struct ath79_spi_platform_data ath79_spi_data
= {
193 static void __init
rut900_setup(void)
195 u8
*mac
= (u8
*) KSEG1ADDR(0x1f020000);
196 u8
*art
= (u8
*) KSEG1ADDR(0x1f030000);
199 ath79_register_spi(&ath79_spi_data
, ath79_spi_info
, 2);
200 ath79_register_leds_gpio(-1, ARRAY_SIZE(rut900_leds_gpio
),
202 ath79_register_gpio_keys_polled(-1, RUT900_KEYS_POLL_INTERVAL
,
203 ARRAY_SIZE(rut900_gpio_keys
),
206 ath79_wmac_set_ext_lna_gpio(0, RUT900_GPIO_EXTERNAL_LNA0
);
208 ath79_init_mac(tmpmac
, mac
, 2);
209 ath79_register_wmac(art
+ RUT900_WMAC_CALDATA_OFFSET
, tmpmac
);
212 ath79_setup_ar934x_eth_cfg(AR934X_ETH_CFG_SW_ONLY_MODE
);
214 ath79_register_mdio(1, 0x0);
217 ath79_init_mac(ath79_eth1_data
.mac_addr
, mac
, 0);
219 /* GMAC1 is connected to the internal switch */
220 ath79_eth1_data
.phy_if_mode
= PHY_INTERFACE_MODE_GMII
;
222 ath79_register_eth(1);
225 ath79_init_mac(ath79_eth0_data
.mac_addr
, mac
, 1);
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
;
234 ath79_register_eth(0);
236 ath79_register_usb();
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
);
248 ath79_gpio_output_select(RUT900_GPIO_MMC_CS
,
252 ath79_gpio_output_select(18, 79);
254 /* Init I2C interface */
258 MIPS_MACHINE(ATH79_MACH_TLT_RUT900
, "TLT-RUT900",
259 "TELTONIKA TLT-RUT900",