ar71xx: merge files-3.2 to files
[openwrt.git] / target / linux / ar71xx / files / arch / mips / ath79 / 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-ath79/ath79.h>
20
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 "machtypes.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
48 #define TEW673GRU_MAC_LOCATION_0 0x1f66ffa0
49 #define TEW673GRU_MAC_LOCATION_1 0x1f66ffb4
50
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
79 static struct flash_platform_data tew673gru_flash_data = {
80 .parts = tew673gru_partitions,
81 .nr_parts = ARRAY_SIZE(tew673gru_partitions),
82 };
83
84 static struct gpio_led tew673gru_leds_gpio[] __initdata = {
85 {
86 .name = "trendnet:blue:wps",
87 .gpio = TEW673GRU_GPIO_LED_WPS,
88 .active_low = 1,
89 }
90 };
91
92 static struct gpio_keys_button tew673gru_gpio_keys[] __initdata = {
93 {
94 .desc = "reset",
95 .type = EV_KEY,
96 .code = KEY_RESTART,
97 .debounce_interval = TEW673GRU_KEYS_DEBOUNCE_INTERVAL,
98 .gpio = TEW673GRU_GPIO_BTN_RESET,
99 .active_low = 1,
100 }, {
101 .desc = "wps",
102 .type = EV_KEY,
103 .code = KEY_WPS_BUTTON,
104 .debounce_interval = TEW673GRU_KEYS_DEBOUNCE_INTERVAL,
105 .gpio = TEW673GRU_GPIO_BTN_WPS,
106 .active_low = 1,
107 }
108 };
109
110 static struct rtl8366_initval tew673gru_rtl8366s_initvals[] = {
111 { .reg = 0x06, .val = 0x0108 },
112 };
113
114 static struct rtl8366_platform_data tew673gru_rtl8366s_data = {
115 .gpio_sda = TEW673GRU_GPIO_RTL8366_SDA,
116 .gpio_sck = TEW673GRU_GPIO_RTL8366_SCK,
117 .num_initvals = ARRAY_SIZE(tew673gru_rtl8366s_initvals),
118 .initvals = tew673gru_rtl8366s_initvals,
119 };
120
121 static struct platform_device tew673gru_rtl8366s_device = {
122 .name = RTL8366S_DRIVER_NAME,
123 .id = -1,
124 .dev = {
125 .platform_data = &tew673gru_rtl8366s_data,
126 }
127 };
128
129 static struct spi_board_info tew673gru_spi_info[] = {
130 {
131 .bus_num = 1,
132 .chip_select = 0,
133 .max_speed_hz = 400000,
134 .modalias = "spidev",
135 .mode = SPI_MODE_2,
136 .controller_data = (void *) TEW673GRU_GPIO_LCD_CS,
137 },
138 };
139
140 static struct spi_gpio_platform_data tew673gru_spi_data = {
141 .sck = TEW673GRU_GPIO_LCD_SCK,
142 .miso = TEW673GRU_GPIO_LCD_MISO,
143 .mosi = TEW673GRU_GPIO_LCD_MOSI,
144 .num_chipselect = 1,
145 };
146
147 static struct platform_device tew673gru_spi_device = {
148 .name = "spi_gpio",
149 .id = 1,
150 .dev = {
151 .platform_data = &tew673gru_spi_data,
152 },
153 };
154
155 static void tew673gru_read_ascii_mac(u8 *dest, unsigned int src_addr)
156 {
157 int ret;
158 u8 *src = (u8 *)KSEG1ADDR(src_addr);
159
160 ret = sscanf(src, "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx",
161 &dest[0], &dest[1], &dest[2],
162 &dest[3], &dest[4], &dest[5]);
163
164 if (ret != ETH_ALEN) memset(dest, 0, ETH_ALEN);
165 }
166
167 static void __init tew673gru_setup(void)
168 {
169 u8 mac1[ETH_ALEN], mac2[ETH_ALEN];
170
171 tew673gru_read_ascii_mac(mac1, TEW673GRU_MAC_LOCATION_0);
172 tew673gru_read_ascii_mac(mac2, TEW673GRU_MAC_LOCATION_1);
173
174 ath79_register_mdio(0, 0x0);
175
176 ath79_init_mac(ath79_eth0_data.mac_addr, mac1, 2);
177 ath79_eth0_data.mii_bus_dev = &tew673gru_rtl8366s_device.dev;
178 ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
179 ath79_eth0_data.speed = SPEED_1000;
180 ath79_eth0_data.duplex = DUPLEX_FULL;
181 ath79_eth0_pll_data.pll_1000 = 0x11110000;
182
183 ath79_init_mac(ath79_eth1_data.mac_addr, mac1, 3);
184 ath79_eth1_data.mii_bus_dev = &tew673gru_rtl8366s_device.dev;
185 ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
186 ath79_eth1_data.phy_mask = 0x10;
187 ath79_eth1_pll_data.pll_1000 = 0x11110000;
188
189 ath79_register_eth(0);
190 ath79_register_eth(1);
191
192 ath79_register_m25p80(&tew673gru_flash_data);
193
194 ath79_register_leds_gpio(-1, ARRAY_SIZE(tew673gru_leds_gpio),
195 tew673gru_leds_gpio);
196
197 ath79_register_gpio_keys_polled(-1, TEW673GRU_KEYS_POLL_INTERVAL,
198 ARRAY_SIZE(tew673gru_gpio_keys),
199 tew673gru_gpio_keys);
200
201 ath79_register_usb();
202
203 platform_device_register(&tew673gru_rtl8366s_device);
204
205 ap9x_pci_setup_wmac_led_pin(0, 5);
206 ap9x_pci_setup_wmac_led_pin(1, 5);
207
208 ap94_pci_init((u8 *) KSEG1ADDR(TEW673GRU_CAL_LOCATION_0), mac1,
209 (u8 *) KSEG1ADDR(TEW673GRU_CAL_LOCATION_1), mac2);
210
211 spi_register_board_info(tew673gru_spi_info,
212 ARRAY_SIZE(tew673gru_spi_info));
213 platform_device_register(&tew673gru_spi_device);
214 }
215
216 MIPS_MACHINE(ATH79_MACH_TEW_673GRU, "TEW-673GRU", "TRENDnet TEW-673GRU",
217 tew673gru_setup);
This page took 0.049309 seconds and 5 git commands to generate.