ar71xx: add support for the TRENDNet TEW-673GRU board
[openwrt/svn-archive/archive.git] / target / linux / ar71xx / files-2.6.39 / arch / mips / ar71xx / mach-tew-673gru.c
1 /*
2 * TRENDnet TEW-673GRU board support
3 *
4 * Copyright (C) 2012 Gabor Juhos <juhosg@openwrt.org>
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/platform_device.h>
12 #include <linux/mtd/mtd.h>
13 #include <linux/mtd/partitions.h>
14 #include <linux/delay.h>
15 #include <linux/rtl8366.h>
16 #include <linux/spi/spi.h>
17 #include <linux/spi/spi_gpio.h>
18
19 #include <asm/mach-ar71xx/ar71xx.h>
20
21 #include "machtype.h"
22 #include "devices.h"
23 #include "dev-m25p80.h"
24 #include "dev-ap94-pci.h"
25 #include "dev-gpio-buttons.h"
26 #include "dev-leds-gpio.h"
27 #include "dev-usb.h"
28
29 #define TEW673GRU_GPIO_LCD_SCK 0
30 #define TEW673GRU_GPIO_LCD_MOSI 1
31 #define TEW673GRU_GPIO_LCD_MISO 2
32 #define TEW673GRU_GPIO_LCD_CS 6
33
34 #define TEW673GRU_GPIO_LED_WPS 9
35
36 #define TEW673GRU_GPIO_BTN_RESET 3
37 #define TEW673GRU_GPIO_BTN_WPS 8
38
39 #define TEW673GRU_GPIO_RTL8366_SDA 5
40 #define TEW673GRU_GPIO_RTL8366_SCK 7
41
42 #define TEW673GRU_KEYS_POLL_INTERVAL 20 /* msecs */
43 #define TEW673GRU_KEYS_DEBOUNCE_INTERVAL (3 * TEW673GRU_KEYS_POLL_INTERVAL)
44
45 #define TEW673GRU_CAL_LOCATION_0 0x1f661000
46 #define TEW673GRU_CAL_LOCATION_1 0x1f665000
47 #define TEW673GRU_MAC_LOCATION_0 0x1f66ffa0
48 #define TEW673GRU_MAC_LOCATION_1 0x1f66ffb4
49
50 #ifdef CONFIG_MTD_PARTITIONS
51 static struct mtd_partition tew673gru_partitions[] = {
52 {
53 .name = "uboot",
54 .offset = 0,
55 .size = 0x040000,
56 .mask_flags = MTD_WRITEABLE,
57 }, {
58 .name = "config",
59 .offset = 0x040000,
60 .size = 0x010000,
61 .mask_flags = MTD_WRITEABLE,
62 }, {
63 .name = "firmware",
64 .offset = 0x050000,
65 .size = 0x610000,
66 }, {
67 .name = "caldata",
68 .offset = 0x660000,
69 .size = 0x010000,
70 .mask_flags = MTD_WRITEABLE,
71 }, {
72 .name = "unknown",
73 .offset = 0x670000,
74 .size = 0x190000,
75 .mask_flags = MTD_WRITEABLE,
76 }
77 };
78 #endif /* CONFIG_MTD_PARTITIONS */
79
80 static struct flash_platform_data tew673gru_flash_data = {
81 #ifdef CONFIG_MTD_PARTITIONS
82 .parts = tew673gru_partitions,
83 .nr_parts = ARRAY_SIZE(tew673gru_partitions),
84 #endif
85 };
86
87 static struct gpio_led tew673gru_leds_gpio[] __initdata = {
88 {
89 .name = "trendnet:blue:wps",
90 .gpio = TEW673GRU_GPIO_LED_WPS,
91 .active_low = 1,
92 }
93 };
94
95 static struct gpio_keys_button tew673gru_gpio_keys[] __initdata = {
96 {
97 .desc = "reset",
98 .type = EV_KEY,
99 .code = KEY_RESTART,
100 .debounce_interval = TEW673GRU_KEYS_DEBOUNCE_INTERVAL,
101 .gpio = TEW673GRU_GPIO_BTN_RESET,
102 .active_low = 1,
103 }, {
104 .desc = "wps",
105 .type = EV_KEY,
106 .code = KEY_WPS_BUTTON,
107 .debounce_interval = TEW673GRU_KEYS_DEBOUNCE_INTERVAL,
108 .gpio = TEW673GRU_GPIO_BTN_WPS,
109 .active_low = 1,
110 }
111 };
112
113 static struct rtl8366_initval tew673gru_rtl8366s_initvals[] = {
114 { .reg = 0x06, .val = 0x0108 },
115 };
116
117 static struct rtl8366_platform_data tew673gru_rtl8366s_data = {
118 .gpio_sda = TEW673GRU_GPIO_RTL8366_SDA,
119 .gpio_sck = TEW673GRU_GPIO_RTL8366_SCK,
120 .num_initvals = ARRAY_SIZE(tew673gru_rtl8366s_initvals),
121 .initvals = tew673gru_rtl8366s_initvals,
122 };
123
124 static struct platform_device tew673gru_rtl8366s_device = {
125 .name = RTL8366S_DRIVER_NAME,
126 .id = -1,
127 .dev = {
128 .platform_data = &tew673gru_rtl8366s_data,
129 }
130 };
131
132 static struct spi_board_info tew673gru_spi_info[] = {
133 {
134 .bus_num = 1,
135 .chip_select = 0,
136 .max_speed_hz = 400000,
137 .modalias = "spidev",
138 .mode = SPI_MODE_2,
139 .controller_data = (void *) TEW673GRU_GPIO_LCD_CS,
140 },
141 };
142
143 static struct spi_gpio_platform_data tew673gru_spi_data = {
144 .sck = TEW673GRU_GPIO_LCD_SCK,
145 .miso = TEW673GRU_GPIO_LCD_MISO,
146 .mosi = TEW673GRU_GPIO_LCD_MOSI,
147 .num_chipselect = 1,
148 };
149
150 static struct platform_device tew673gru_spi_device = {
151 .name = "spi_gpio",
152 .id = 1,
153 .dev = {
154 .platform_data = &tew673gru_spi_data,
155 },
156 };
157
158 static void tew673gru_read_ascii_mac(u8 *dest, unsigned int src_addr)
159 {
160 int ret;
161 u8 *src = (u8 *)KSEG1ADDR(src_addr);
162
163 ret = sscanf(src, "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx",
164 &dest[0], &dest[1], &dest[2],
165 &dest[3], &dest[4], &dest[5]);
166
167 if (ret != ETH_ALEN) memset(dest, 0, ETH_ALEN);
168 }
169
170 static void __init tew673gru_setup(void)
171 {
172 u8 mac1[ETH_ALEN], mac2[ETH_ALEN];
173
174 tew673gru_read_ascii_mac(mac1, TEW673GRU_MAC_LOCATION_0);
175 tew673gru_read_ascii_mac(mac2, TEW673GRU_MAC_LOCATION_1);
176
177 ar71xx_add_device_mdio(0, 0x0);
178
179 ar71xx_init_mac(ar71xx_eth0_data.mac_addr, mac1, 2);
180 ar71xx_eth0_data.mii_bus_dev = &tew673gru_rtl8366s_device.dev;
181 ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
182 ar71xx_eth0_data.speed = SPEED_1000;
183 ar71xx_eth0_data.duplex = DUPLEX_FULL;
184 ar71xx_eth0_pll_data.pll_1000 = 0x11110000;
185
186 ar71xx_init_mac(ar71xx_eth1_data.mac_addr, mac1, 3);
187 ar71xx_eth1_data.mii_bus_dev = &tew673gru_rtl8366s_device.dev;
188 ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
189 ar71xx_eth1_data.phy_mask = 0x10;
190 ar71xx_eth1_pll_data.pll_1000 = 0x11110000;
191
192 ar71xx_add_device_eth(0);
193 ar71xx_add_device_eth(1);
194
195 ar71xx_add_device_m25p80(&tew673gru_flash_data);
196
197 ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(tew673gru_leds_gpio),
198 tew673gru_leds_gpio);
199
200 ar71xx_register_gpio_keys_polled(-1, TEW673GRU_KEYS_POLL_INTERVAL,
201 ARRAY_SIZE(tew673gru_gpio_keys),
202 tew673gru_gpio_keys);
203
204 ar71xx_add_device_usb();
205
206 platform_device_register(&tew673gru_rtl8366s_device);
207
208 ap94_pci_setup_wmac_led_pin(0, 5);
209 ap94_pci_setup_wmac_led_pin(1, 5);
210
211 ap94_pci_init((u8 *) KSEG1ADDR(TEW673GRU_CAL_LOCATION_0), mac1,
212 (u8 *) KSEG1ADDR(TEW673GRU_CAL_LOCATION_1), mac2);
213
214 spi_register_board_info(tew673gru_spi_info,
215 ARRAY_SIZE(tew673gru_spi_info));
216 platform_device_register(&tew673gru_spi_device);
217 }
218
219 MIPS_MACHINE(AR71XX_MACH_TEW_673GRU, "TEW-673GRU", "TRENDnet TEW-673GRU",
220 tew673gru_setup);