mach-tew-673gru.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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. #include <linux/platform_device.h>
  11. #include <linux/delay.h>
  12. #include <linux/rtl8366.h>
  13. #include <linux/spi/spi.h>
  14. #include <linux/spi/spi_gpio.h>
  15. #include <asm/mach-ath79/ath79.h>
  16. #include "dev-ap9x-pci.h"
  17. #include "dev-eth.h"
  18. #include "dev-gpio-buttons.h"
  19. #include "dev-leds-gpio.h"
  20. #include "dev-m25p80.h"
  21. #include "dev-usb.h"
  22. #include "machtypes.h"
  23. #define TEW673GRU_GPIO_LCD_SCK 0
  24. #define TEW673GRU_GPIO_LCD_MOSI 1
  25. #define TEW673GRU_GPIO_LCD_MISO 2
  26. #define TEW673GRU_GPIO_LCD_CS 6
  27. #define TEW673GRU_GPIO_LED_WPS 9
  28. #define TEW673GRU_GPIO_BTN_RESET 3
  29. #define TEW673GRU_GPIO_BTN_WPS 8
  30. #define TEW673GRU_GPIO_RTL8366_SDA 5
  31. #define TEW673GRU_GPIO_RTL8366_SCK 7
  32. #define TEW673GRU_KEYS_POLL_INTERVAL 20 /* msecs */
  33. #define TEW673GRU_KEYS_DEBOUNCE_INTERVAL (3 * TEW673GRU_KEYS_POLL_INTERVAL)
  34. #define TEW673GRU_CAL0_OFFSET 0x1000
  35. #define TEW673GRU_CAL1_OFFSET 0x5000
  36. #define TEW673GRU_MAC0_OFFSET 0xffa0
  37. #define TEW673GRU_MAC1_OFFSET 0xffb4
  38. #define TEW673GRU_CAL_LOCATION_0 0x1f660000
  39. #define TEW673GRU_CAL_LOCATION_1 0x1f7f0000
  40. static struct gpio_led tew673gru_leds_gpio[] __initdata = {
  41. {
  42. .name = "trendnet:blue:wps",
  43. .gpio = TEW673GRU_GPIO_LED_WPS,
  44. .active_low = 1,
  45. }
  46. };
  47. static struct gpio_keys_button tew673gru_gpio_keys[] __initdata = {
  48. {
  49. .desc = "reset",
  50. .type = EV_KEY,
  51. .code = KEY_RESTART,
  52. .debounce_interval = TEW673GRU_KEYS_DEBOUNCE_INTERVAL,
  53. .gpio = TEW673GRU_GPIO_BTN_RESET,
  54. .active_low = 1,
  55. }, {
  56. .desc = "wps",
  57. .type = EV_KEY,
  58. .code = KEY_WPS_BUTTON,
  59. .debounce_interval = TEW673GRU_KEYS_DEBOUNCE_INTERVAL,
  60. .gpio = TEW673GRU_GPIO_BTN_WPS,
  61. .active_low = 1,
  62. }
  63. };
  64. static struct rtl8366_initval tew673gru_rtl8366s_initvals[] = {
  65. { .reg = 0x06, .val = 0x0108 },
  66. };
  67. static struct rtl8366_platform_data tew673gru_rtl8366s_data = {
  68. .gpio_sda = TEW673GRU_GPIO_RTL8366_SDA,
  69. .gpio_sck = TEW673GRU_GPIO_RTL8366_SCK,
  70. .num_initvals = ARRAY_SIZE(tew673gru_rtl8366s_initvals),
  71. .initvals = tew673gru_rtl8366s_initvals,
  72. };
  73. static struct platform_device tew673gru_rtl8366s_device = {
  74. .name = RTL8366S_DRIVER_NAME,
  75. .id = -1,
  76. .dev = {
  77. .platform_data = &tew673gru_rtl8366s_data,
  78. }
  79. };
  80. static struct spi_board_info tew673gru_spi_info[] = {
  81. {
  82. .bus_num = 1,
  83. .chip_select = 0,
  84. .max_speed_hz = 400000,
  85. .modalias = "spidev",
  86. .mode = SPI_MODE_2,
  87. .controller_data = (void *) TEW673GRU_GPIO_LCD_CS,
  88. },
  89. };
  90. static struct spi_gpio_platform_data tew673gru_spi_data = {
  91. .sck = TEW673GRU_GPIO_LCD_SCK,
  92. .miso = TEW673GRU_GPIO_LCD_MISO,
  93. .mosi = TEW673GRU_GPIO_LCD_MOSI,
  94. .num_chipselect = 1,
  95. };
  96. static struct platform_device tew673gru_spi_device = {
  97. .name = "spi_gpio",
  98. .id = 1,
  99. .dev = {
  100. .platform_data = &tew673gru_spi_data,
  101. },
  102. };
  103. static bool __init tew673gru_is_caldata_valid(u8 *p)
  104. {
  105. u16 *magic0, *magic1;
  106. magic0 = (u16 *)(p + TEW673GRU_CAL0_OFFSET);
  107. magic1 = (u16 *)(p + TEW673GRU_CAL1_OFFSET);
  108. return (*magic0 == 0xa55a && *magic1 == 0xa55a);
  109. }
  110. static void __init tew673gru_wlan_init(void)
  111. {
  112. u8 mac1[ETH_ALEN], mac2[ETH_ALEN];
  113. u8 *caldata;
  114. caldata = (u8 *) KSEG1ADDR(TEW673GRU_CAL_LOCATION_0);
  115. if (!tew673gru_is_caldata_valid(caldata)) {
  116. caldata = (u8 *)KSEG1ADDR(TEW673GRU_CAL_LOCATION_1);
  117. if (!tew673gru_is_caldata_valid(caldata)) {
  118. pr_err("no calibration data found\n");
  119. return;
  120. }
  121. }
  122. ath79_parse_ascii_mac(caldata + TEW673GRU_MAC0_OFFSET, mac1);
  123. ath79_parse_ascii_mac(caldata + TEW673GRU_MAC1_OFFSET, mac2);
  124. ath79_init_mac(ath79_eth0_data.mac_addr, mac1, 2);
  125. ath79_init_mac(ath79_eth1_data.mac_addr, mac1, 3);
  126. ap9x_pci_setup_wmac_led_pin(0, 5);
  127. ap9x_pci_setup_wmac_led_pin(1, 5);
  128. ap94_pci_init(caldata + TEW673GRU_CAL0_OFFSET, mac1,
  129. caldata + TEW673GRU_CAL1_OFFSET, mac2);
  130. }
  131. static void __init tew673gru_setup(void)
  132. {
  133. tew673gru_wlan_init();
  134. ath79_register_mdio(0, 0x0);
  135. ath79_eth0_data.mii_bus_dev = &tew673gru_rtl8366s_device.dev;
  136. ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  137. ath79_eth0_data.speed = SPEED_1000;
  138. ath79_eth0_data.duplex = DUPLEX_FULL;
  139. ath79_eth0_pll_data.pll_1000 = 0x11110000;
  140. ath79_eth1_data.mii_bus_dev = &tew673gru_rtl8366s_device.dev;
  141. ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  142. ath79_eth1_data.phy_mask = 0x10;
  143. ath79_eth1_pll_data.pll_1000 = 0x11110000;
  144. ath79_register_eth(0);
  145. ath79_register_eth(1);
  146. ath79_register_m25p80(NULL);
  147. ath79_register_leds_gpio(-1, ARRAY_SIZE(tew673gru_leds_gpio),
  148. tew673gru_leds_gpio);
  149. ath79_register_gpio_keys_polled(-1, TEW673GRU_KEYS_POLL_INTERVAL,
  150. ARRAY_SIZE(tew673gru_gpio_keys),
  151. tew673gru_gpio_keys);
  152. ath79_register_usb();
  153. platform_device_register(&tew673gru_rtl8366s_device);
  154. spi_register_board_info(tew673gru_spi_info,
  155. ARRAY_SIZE(tew673gru_spi_info));
  156. platform_device_register(&tew673gru_spi_device);
  157. }
  158. MIPS_MACHINE(ATH79_MACH_TEW_673GRU, "TEW-673GRU", "TRENDnet TEW-673GRU",
  159. tew673gru_setup);