2 * TRENDnet TEW-673GRU board support
4 * Copyright (C) 2012 Gabor Juhos <juhosg@openwrt.org>
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/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>
19 #include <asm/mach-ar71xx/ar71xx.h>
23 #include "dev-m25p80.h"
24 #include "dev-ap94-pci.h"
25 #include "dev-gpio-buttons.h"
26 #include "dev-leds-gpio.h"
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
34 #define TEW673GRU_GPIO_LED_WPS 9
36 #define TEW673GRU_GPIO_BTN_RESET 3
37 #define TEW673GRU_GPIO_BTN_WPS 8
39 #define TEW673GRU_GPIO_RTL8366_SDA 5
40 #define TEW673GRU_GPIO_RTL8366_SCK 7
42 #define TEW673GRU_KEYS_POLL_INTERVAL 20 /* msecs */
43 #define TEW673GRU_KEYS_DEBOUNCE_INTERVAL (3 * TEW673GRU_KEYS_POLL_INTERVAL)
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
50 #ifdef CONFIG_MTD_PARTITIONS
51 static struct mtd_partition tew673gru_partitions
[] = {
56 .mask_flags
= MTD_WRITEABLE
,
61 .mask_flags
= MTD_WRITEABLE
,
70 .mask_flags
= MTD_WRITEABLE
,
75 .mask_flags
= MTD_WRITEABLE
,
78 #endif /* CONFIG_MTD_PARTITIONS */
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
),
87 static struct gpio_led tew673gru_leds_gpio
[] __initdata
= {
89 .name
= "trendnet:blue:wps",
90 .gpio
= TEW673GRU_GPIO_LED_WPS
,
95 static struct gpio_keys_button tew673gru_gpio_keys
[] __initdata
= {
100 .debounce_interval
= TEW673GRU_KEYS_DEBOUNCE_INTERVAL
,
101 .gpio
= TEW673GRU_GPIO_BTN_RESET
,
106 .code
= KEY_WPS_BUTTON
,
107 .debounce_interval
= TEW673GRU_KEYS_DEBOUNCE_INTERVAL
,
108 .gpio
= TEW673GRU_GPIO_BTN_WPS
,
113 static struct rtl8366_initval tew673gru_rtl8366s_initvals
[] = {
114 { .reg
= 0x06, .val
= 0x0108 },
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
,
124 static struct platform_device tew673gru_rtl8366s_device
= {
125 .name
= RTL8366S_DRIVER_NAME
,
128 .platform_data
= &tew673gru_rtl8366s_data
,
132 static struct spi_board_info tew673gru_spi_info
[] = {
136 .max_speed_hz
= 400000,
137 .modalias
= "spidev",
139 .controller_data
= (void *) TEW673GRU_GPIO_LCD_CS
,
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
,
150 static struct platform_device tew673gru_spi_device
= {
154 .platform_data
= &tew673gru_spi_data
,
158 static void tew673gru_read_ascii_mac(u8
*dest
, unsigned int src_addr
)
161 u8
*src
= (u8
*)KSEG1ADDR(src_addr
);
163 ret
= sscanf(src
, "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx",
164 &dest
[0], &dest
[1], &dest
[2],
165 &dest
[3], &dest
[4], &dest
[5]);
167 if (ret
!= ETH_ALEN
) memset(dest
, 0, ETH_ALEN
);
170 static void __init
tew673gru_setup(void)
172 u8 mac1
[ETH_ALEN
], mac2
[ETH_ALEN
];
174 tew673gru_read_ascii_mac(mac1
, TEW673GRU_MAC_LOCATION_0
);
175 tew673gru_read_ascii_mac(mac2
, TEW673GRU_MAC_LOCATION_1
);
177 ar71xx_add_device_mdio(0, 0x0);
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;
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;
192 ar71xx_add_device_eth(0);
193 ar71xx_add_device_eth(1);
195 ar71xx_add_device_m25p80(&tew673gru_flash_data
);
197 ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(tew673gru_leds_gpio
),
198 tew673gru_leds_gpio
);
200 ar71xx_register_gpio_keys_polled(-1, TEW673GRU_KEYS_POLL_INTERVAL
,
201 ARRAY_SIZE(tew673gru_gpio_keys
),
202 tew673gru_gpio_keys
);
204 ar71xx_add_device_usb();
206 platform_device_register(&tew673gru_rtl8366s_device
);
208 ap94_pci_setup_wmac_led_pin(0, 5);
209 ap94_pci_setup_wmac_led_pin(1, 5);
211 ap94_pci_init((u8
*) KSEG1ADDR(TEW673GRU_CAL_LOCATION_0
), mac1
,
212 (u8
*) KSEG1ADDR(TEW673GRU_CAL_LOCATION_1
), mac2
);
214 spi_register_board_info(tew673gru_spi_info
,
215 ARRAY_SIZE(tew673gru_spi_info
));
216 platform_device_register(&tew673gru_spi_device
);
219 MIPS_MACHINE(AR71XX_MACH_TEW_673GRU
, "TEW-673GRU", "TRENDnet TEW-673GRU",