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/delay.h>
13 #include <linux/rtl8366.h>
14 #include <linux/spi/spi.h>
15 #include <linux/spi/spi_gpio.h>
17 #include <asm/mach-ath79/ath79.h>
19 #include "dev-ap9x-pci.h"
21 #include "dev-gpio-buttons.h"
22 #include "dev-leds-gpio.h"
23 #include "dev-m25p80.h"
25 #include "machtypes.h"
27 #define TEW673GRU_GPIO_LCD_SCK 0
28 #define TEW673GRU_GPIO_LCD_MOSI 1
29 #define TEW673GRU_GPIO_LCD_MISO 2
30 #define TEW673GRU_GPIO_LCD_CS 6
32 #define TEW673GRU_GPIO_LED_WPS 9
34 #define TEW673GRU_GPIO_BTN_RESET 3
35 #define TEW673GRU_GPIO_BTN_WPS 8
37 #define TEW673GRU_GPIO_RTL8366_SDA 5
38 #define TEW673GRU_GPIO_RTL8366_SCK 7
40 #define TEW673GRU_KEYS_POLL_INTERVAL 20 /* msecs */
41 #define TEW673GRU_KEYS_DEBOUNCE_INTERVAL (3 * TEW673GRU_KEYS_POLL_INTERVAL)
43 #define TEW673GRU_CAL0_OFFSET 0x1000
44 #define TEW673GRU_CAL1_OFFSET 0x5000
45 #define TEW673GRU_MAC0_OFFSET 0xffa0
46 #define TEW673GRU_MAC1_OFFSET 0xffb4
48 #define TEW673GRU_CAL_LOCATION_0 0x1f660000
49 #define TEW673GRU_CAL_LOCATION_1 0x1f7f0000
51 static struct gpio_led tew673gru_leds_gpio
[] __initdata
= {
53 .name
= "trendnet:blue:wps",
54 .gpio
= TEW673GRU_GPIO_LED_WPS
,
59 static struct gpio_keys_button tew673gru_gpio_keys
[] __initdata
= {
64 .debounce_interval
= TEW673GRU_KEYS_DEBOUNCE_INTERVAL
,
65 .gpio
= TEW673GRU_GPIO_BTN_RESET
,
70 .code
= KEY_WPS_BUTTON
,
71 .debounce_interval
= TEW673GRU_KEYS_DEBOUNCE_INTERVAL
,
72 .gpio
= TEW673GRU_GPIO_BTN_WPS
,
77 static struct rtl8366_initval tew673gru_rtl8366s_initvals
[] = {
78 { .reg
= 0x06, .val
= 0x0108 },
81 static struct rtl8366_platform_data tew673gru_rtl8366s_data
= {
82 .gpio_sda
= TEW673GRU_GPIO_RTL8366_SDA
,
83 .gpio_sck
= TEW673GRU_GPIO_RTL8366_SCK
,
84 .num_initvals
= ARRAY_SIZE(tew673gru_rtl8366s_initvals
),
85 .initvals
= tew673gru_rtl8366s_initvals
,
88 static struct platform_device tew673gru_rtl8366s_device
= {
89 .name
= RTL8366S_DRIVER_NAME
,
92 .platform_data
= &tew673gru_rtl8366s_data
,
96 static struct spi_board_info tew673gru_spi_info
[] = {
100 .max_speed_hz
= 400000,
101 .modalias
= "spidev",
103 .controller_data
= (void *) TEW673GRU_GPIO_LCD_CS
,
107 static struct spi_gpio_platform_data tew673gru_spi_data
= {
108 .sck
= TEW673GRU_GPIO_LCD_SCK
,
109 .miso
= TEW673GRU_GPIO_LCD_MISO
,
110 .mosi
= TEW673GRU_GPIO_LCD_MOSI
,
114 static struct platform_device tew673gru_spi_device
= {
118 .platform_data
= &tew673gru_spi_data
,
122 static bool __init
tew673gru_is_caldata_valid(u8
*p
)
124 u16
*magic0
, *magic1
;
126 magic0
= (u16
*)(p
+ TEW673GRU_CAL0_OFFSET
);
127 magic1
= (u16
*)(p
+ TEW673GRU_CAL1_OFFSET
);
129 return (*magic0
== 0xa55a && *magic1
== 0xa55a);
132 static void __init
tew673gru_wlan_init(void)
134 u8 mac1
[ETH_ALEN
], mac2
[ETH_ALEN
];
137 caldata
= (u8
*) KSEG1ADDR(TEW673GRU_CAL_LOCATION_0
);
138 if (!tew673gru_is_caldata_valid(caldata
)) {
139 caldata
= (u8
*)KSEG1ADDR(TEW673GRU_CAL_LOCATION_1
);
140 if (!tew673gru_is_caldata_valid(caldata
)) {
141 pr_err("no calibration data found\n");
146 ath79_parse_ascii_mac(caldata
+ TEW673GRU_MAC0_OFFSET
, mac1
);
147 ath79_parse_ascii_mac(caldata
+ TEW673GRU_MAC1_OFFSET
, mac2
);
149 ath79_init_mac(ath79_eth0_data
.mac_addr
, mac1
, 2);
150 ath79_init_mac(ath79_eth1_data
.mac_addr
, mac1
, 3);
152 ap9x_pci_setup_wmac_led_pin(0, 5);
153 ap9x_pci_setup_wmac_led_pin(1, 5);
155 ap94_pci_init(caldata
+ TEW673GRU_CAL0_OFFSET
, mac1
,
156 caldata
+ TEW673GRU_CAL1_OFFSET
, mac2
);
159 static void __init
tew673gru_setup(void)
161 tew673gru_wlan_init();
163 ath79_register_mdio(0, 0x0);
165 ath79_eth0_data
.mii_bus_dev
= &tew673gru_rtl8366s_device
.dev
;
166 ath79_eth0_data
.phy_if_mode
= PHY_INTERFACE_MODE_RGMII
;
167 ath79_eth0_data
.speed
= SPEED_1000
;
168 ath79_eth0_data
.duplex
= DUPLEX_FULL
;
169 ath79_eth0_pll_data
.pll_1000
= 0x11110000;
171 ath79_eth1_data
.mii_bus_dev
= &tew673gru_rtl8366s_device
.dev
;
172 ath79_eth1_data
.phy_if_mode
= PHY_INTERFACE_MODE_RGMII
;
173 ath79_eth1_data
.phy_mask
= 0x10;
174 ath79_eth1_pll_data
.pll_1000
= 0x11110000;
176 ath79_register_eth(0);
177 ath79_register_eth(1);
179 ath79_register_m25p80(NULL
);
181 ath79_register_leds_gpio(-1, ARRAY_SIZE(tew673gru_leds_gpio
),
182 tew673gru_leds_gpio
);
184 ath79_register_gpio_keys_polled(-1, TEW673GRU_KEYS_POLL_INTERVAL
,
185 ARRAY_SIZE(tew673gru_gpio_keys
),
186 tew673gru_gpio_keys
);
188 ath79_register_usb();
190 platform_device_register(&tew673gru_rtl8366s_device
);
192 spi_register_board_info(tew673gru_spi_info
,
193 ARRAY_SIZE(tew673gru_spi_info
));
194 platform_device_register(&tew673gru_spi_device
);
197 MIPS_MACHINE(ATH79_MACH_TEW_673GRU
, "TEW-673GRU", "TRENDnet TEW-673GRU",