OpenWrt – Blame information for rev 4
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
4 | office | 1 | /* |
2 | * Teltonika RUT900 series boards support |
||
3 | * |
||
4 | * Copyright (C) 2018 Piotr Dymacz <pepe2k@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/i2c.h> |
||
13 | #include <linux/i2c-algo-bit.h> |
||
14 | #include <linux/i2c-gpio.h> |
||
15 | #include <linux/platform_data/pca953x.h> |
||
16 | #include <linux/platform_device.h> |
||
17 | |||
18 | #include <asm/mach-ath79/ath79.h> |
||
19 | #include <asm/mach-ath79/ar71xx_regs.h> |
||
20 | |||
21 | #include "common.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-wmac.h" |
||
28 | #include "machtypes.h" |
||
29 | |||
30 | #define RUT9XX_GPIO_LED_LAN1 14 |
||
31 | #define RUT9XX_GPIO_LED_LAN2 13 |
||
32 | #define RUT9XX_GPIO_LED_LAN3 22 |
||
33 | #define RUT9XX_GPIO_LED_WAN 1 |
||
34 | |||
35 | #define RUT9XX_PCA9539_GPIO_BASE 32 |
||
36 | #define RUT9XX_PCA9539_GPIO_SIGNAL1 (0 + RUT9XX_PCA9539_GPIO_BASE) |
||
37 | #define RUT9XX_PCA9539_GPIO_SIGNAL2 (1 + RUT9XX_PCA9539_GPIO_BASE) |
||
38 | #define RUT9XX_PCA9539_GPIO_SIGNAL3 (2 + RUT9XX_PCA9539_GPIO_BASE) |
||
39 | #define RUT9XX_PCA9539_GPIO_SIGNAL4 (3 + RUT9XX_PCA9539_GPIO_BASE) |
||
40 | #define RUT9XX_PCA9539_GPIO_SIGNAL5 (4 + RUT9XX_PCA9539_GPIO_BASE) |
||
41 | #define RUT9XX_PCA9539_GPIO_STATUS_R (5 + RUT9XX_PCA9539_GPIO_BASE) |
||
42 | #define RUT9XX_PCA9539_GPIO_STATUS_G (6 + RUT9XX_PCA9539_GPIO_BASE) |
||
43 | |||
44 | #define RUT9XX_GPIO_BTN_RESET 15 |
||
45 | |||
46 | #define RUT9XX_GPIO_I2C_SCK 16 |
||
47 | #define RUT9XX_GPIO_I2C_SDA 17 |
||
48 | |||
49 | #define RUT9XX_GPIO_EXT_LNA0 2 |
||
50 | |||
51 | #define RUT9XX_WMAC_CALDATA_OFFSET 0x1000 |
||
52 | |||
53 | #define RUT9XX_KEYS_POLL_INTERVAL 20 |
||
54 | #define RUT9XX_KEYS_DEBOUNCE_INTERVAL (3 * RUT9XX_KEYS_POLL_INTERVAL) |
||
55 | |||
56 | static struct gpio_led rut900_leds_gpio[] __initdata = { |
||
57 | { |
||
58 | .name = "rut900:green:lan1", |
||
59 | .gpio = RUT9XX_GPIO_LED_LAN1, |
||
60 | .active_low = 1, |
||
61 | }, { |
||
62 | .name = "rut900:green:lan2", |
||
63 | .gpio = RUT9XX_GPIO_LED_LAN2, |
||
64 | .active_low = 1, |
||
65 | }, { |
||
66 | .name = "rut900:green:lan3", |
||
67 | .gpio = RUT9XX_GPIO_LED_LAN3, |
||
68 | .active_low = 1, |
||
69 | }, { |
||
70 | .name = "rut900:green:signal1", |
||
71 | .gpio = RUT9XX_PCA9539_GPIO_SIGNAL1, |
||
72 | .active_low = 0, |
||
73 | }, { |
||
74 | .name = "rut900:green:signal2", |
||
75 | .gpio = RUT9XX_PCA9539_GPIO_SIGNAL2, |
||
76 | .active_low = 0, |
||
77 | }, { |
||
78 | .name = "rut900:green:signal3", |
||
79 | .gpio = RUT9XX_PCA9539_GPIO_SIGNAL3, |
||
80 | .active_low = 0, |
||
81 | }, { |
||
82 | .name = "rut900:green:signal4", |
||
83 | .gpio = RUT9XX_PCA9539_GPIO_SIGNAL4, |
||
84 | .active_low = 0, |
||
85 | }, { |
||
86 | .name = "rut900:green:signal5", |
||
87 | .gpio = RUT9XX_PCA9539_GPIO_SIGNAL5, |
||
88 | .active_low = 0, |
||
89 | }, { |
||
90 | .name = "rut900:green:status", |
||
91 | .gpio = RUT9XX_PCA9539_GPIO_STATUS_G, |
||
92 | .active_low = 0, |
||
93 | }, { |
||
94 | .name = "rut900:green:wan", |
||
95 | .gpio = RUT9XX_GPIO_LED_WAN, |
||
96 | .active_low = 1, |
||
97 | }, { |
||
98 | .name = "rut900:red:status", |
||
99 | .gpio = RUT9XX_PCA9539_GPIO_STATUS_R, |
||
100 | .active_low = 0, |
||
101 | }, |
||
102 | }; |
||
103 | |||
104 | static struct gpio_keys_button rut900_gpio_keys[] __initdata = { |
||
105 | { |
||
106 | .desc = "reset", |
||
107 | .type = EV_KEY, |
||
108 | .code = KEY_RESTART, |
||
109 | .debounce_interval = RUT9XX_KEYS_DEBOUNCE_INTERVAL, |
||
110 | .gpio = RUT9XX_GPIO_BTN_RESET, |
||
111 | .active_low = 1, |
||
112 | }, |
||
113 | }; |
||
114 | |||
115 | static struct i2c_gpio_platform_data rut900_i2c_gpio_data = { |
||
116 | .sda_pin = RUT9XX_GPIO_I2C_SDA, |
||
117 | .scl_pin = RUT9XX_GPIO_I2C_SCK, |
||
118 | .udelay = 10, |
||
119 | }; |
||
120 | |||
121 | static struct platform_device rut900_i2c_device = { |
||
122 | .name = "i2c-gpio", |
||
123 | .id = 0, |
||
124 | .dev = { |
||
125 | .platform_data = &rut900_i2c_gpio_data, |
||
126 | }, |
||
127 | }; |
||
128 | |||
129 | static struct pca953x_platform_data rut9xx_pca9539_data = { |
||
130 | .gpio_base = RUT9XX_PCA9539_GPIO_BASE, |
||
131 | .irq_base = -1, |
||
132 | }; |
||
133 | |||
134 | static struct i2c_board_info rut900_i2c_devs[] __initdata = { |
||
135 | { |
||
136 | I2C_BOARD_INFO("pca9539", 0x74), |
||
137 | .platform_data = &rut9xx_pca9539_data, |
||
138 | }, |
||
139 | }; |
||
140 | |||
141 | static void __init rut900_setup(void) |
||
142 | { |
||
143 | u8 *art = (u8 *) KSEG1ADDR(0x1f030000); |
||
144 | u8 *mac = (u8 *) KSEG1ADDR(0x1f020000); |
||
145 | u8 wlan_mac[ETH_ALEN]; |
||
146 | |||
147 | ath79_register_m25p80(NULL); |
||
148 | |||
149 | ath79_register_mdio(1, 0x0); |
||
150 | |||
151 | ath79_switch_data.phy4_mii_en = 1; |
||
152 | ath79_switch_data.phy_poll_mask = 0xf1; |
||
153 | |||
154 | /* LAN */ |
||
155 | ath79_eth1_data.duplex = DUPLEX_FULL; |
||
156 | ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_GMII; |
||
157 | ath79_init_mac(ath79_eth1_data.mac_addr, mac, 0); |
||
158 | ath79_register_eth(1); |
||
159 | |||
160 | /* WAN */ |
||
161 | ath79_eth0_data.duplex = DUPLEX_FULL; |
||
162 | ath79_eth0_data.mii_bus_dev = &ath79_mdio1_device.dev; |
||
163 | ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII; |
||
164 | ath79_eth0_data.phy_mask = BIT(4); |
||
165 | ath79_eth0_data.speed = SPEED_100; |
||
166 | ath79_init_mac(ath79_eth0_data.mac_addr, mac, 1); |
||
167 | ath79_register_eth(0); |
||
168 | |||
169 | platform_device_register(&rut900_i2c_device); |
||
170 | i2c_register_board_info(0, rut900_i2c_devs, |
||
171 | ARRAY_SIZE(rut900_i2c_devs)); |
||
172 | |||
173 | /* Disable JTAG (enables GPIO0-3) */ |
||
174 | ath79_gpio_function_enable(AR934X_GPIO_FUNC_JTAG_DISABLE); |
||
175 | |||
176 | ath79_register_leds_gpio(-1, ARRAY_SIZE(rut900_leds_gpio), |
||
177 | rut900_leds_gpio); |
||
178 | |||
179 | ath79_register_gpio_keys_polled(-1, RUT9XX_KEYS_POLL_INTERVAL, |
||
180 | ARRAY_SIZE(rut900_gpio_keys), |
||
181 | rut900_gpio_keys); |
||
182 | |||
183 | ath79_wmac_set_ext_lna_gpio(0, RUT9XX_GPIO_EXT_LNA0); |
||
184 | |||
185 | ath79_init_mac(wlan_mac, mac, 2); |
||
186 | ath79_register_wmac(art + RUT9XX_WMAC_CALDATA_OFFSET, wlan_mac); |
||
187 | |||
188 | ath79_register_usb(); |
||
189 | } |
||
190 | |||
191 | MIPS_MACHINE(ATH79_MACH_RUT9XX, "RUT900", "Teltonika RUT900", rut900_setup); |