mach-mynet-rext.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /*
  2. * WD My Net WI-FI Range Extender (Codename:Starfish db12x) board support
  3. *
  4. * Copyright (C) 2013 Christian Lamparter <chunkeey@googlemail.com>
  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/pci.h>
  11. #include <linux/phy.h>
  12. #include <linux/gpio.h>
  13. #include <linux/platform_device.h>
  14. #include <linux/ath9k_platform.h>
  15. #include <linux/ar8216_platform.h>
  16. #include <linux/platform_data/phy-at803x.h>
  17. #include <asm/mach-ath79/ar71xx_regs.h>
  18. #include "common.h"
  19. #include "dev-ap9x-pci.h"
  20. #include "dev-eth.h"
  21. #include "dev-gpio-buttons.h"
  22. #include "dev-leds-gpio.h"
  23. #include "dev-m25p80.h"
  24. #include "dev-spi.h"
  25. #include "dev-usb.h"
  26. #include "dev-wmac.h"
  27. #include "machtypes.h"
  28. #include "nvram.h"
  29. #define MYNET_REXT_GPIO_LED_POWER 11
  30. #define MYNET_REXT_GPIO_LED_ETHERNET 12
  31. #define MYNET_REXT_GPIO_LED_WIFI 19
  32. #define MYNET_REXT_GPIO_LED_RF_QTY1 20
  33. #define MYNET_REXT_GPIO_LED_RF_QTY2 21
  34. #define MYNET_REXT_GPIO_LED_RF_QTY3 22
  35. #define MYNET_REXT_GPIO_BTN_RESET 13
  36. #define MYNET_REXT_GPIO_BTN_WPS 15
  37. #define MYNET_REXT_GPIO_SW_RF 14
  38. #define MYNET_REXT_GPIO_PHY_SWRST 16 /* disables Ethernet PHY */
  39. #define MYNET_REXT_GPIO_PHY_INT 17
  40. #define MYNET_REXT_GPIO_18 18
  41. #define MYNET_REXT_KEYS_POLL_INTERVAL 20 /* msecs */
  42. #define MYNET_REXT_KEYS_DEBOUNCE_INTERVAL (3 * MYNET_REXT_KEYS_POLL_INTERVAL)
  43. #define MYNET_REXT_WMAC_CALDATA_OFFSET 0x1000
  44. #define MYNET_REXT_NVRAM_ADDR 0x1f7e0010
  45. #define MYNET_REXT_NVRAM_SIZE 0xfff0
  46. #define MYNET_REXT_ART_ADDR 0x1f7f0000
  47. static const char *mynet_rext_part_probes[] = {
  48. "cybertan",
  49. NULL,
  50. };
  51. static struct flash_platform_data mynet_rext_flash_data = {
  52. .type = "s25fl064k",
  53. .part_probes = mynet_rext_part_probes,
  54. };
  55. static struct gpio_led mynet_rext_leds_gpio[] __initdata = {
  56. {
  57. .name = "wd:blue:power",
  58. .gpio = MYNET_REXT_GPIO_LED_POWER,
  59. .active_low = 0,
  60. },
  61. {
  62. .name = "wd:blue:wireless",
  63. .gpio = MYNET_REXT_GPIO_LED_WIFI,
  64. .active_low = 1,
  65. },
  66. {
  67. .name = "wd:blue:ethernet",
  68. .gpio = MYNET_REXT_GPIO_LED_ETHERNET,
  69. .active_low = 1,
  70. },
  71. {
  72. .name = "wd:blue:quality1",
  73. .gpio = MYNET_REXT_GPIO_LED_RF_QTY1,
  74. .active_low = 1,
  75. },
  76. {
  77. .name = "wd:blue:quality2",
  78. .gpio = MYNET_REXT_GPIO_LED_RF_QTY2,
  79. .active_low = 1,
  80. },
  81. {
  82. .name = "wd:blue:quality3",
  83. .gpio = MYNET_REXT_GPIO_LED_RF_QTY3,
  84. .active_low = 1,
  85. },
  86. };
  87. static struct gpio_keys_button mynet_rext_gpio_keys[] __initdata = {
  88. {
  89. .desc = "Reset button",
  90. .type = EV_KEY,
  91. .code = KEY_RESTART,
  92. .debounce_interval = MYNET_REXT_KEYS_DEBOUNCE_INTERVAL,
  93. .gpio = MYNET_REXT_GPIO_BTN_RESET,
  94. .active_low = 1,
  95. },
  96. {
  97. .desc = "WPS button",
  98. .type = EV_KEY,
  99. .code = KEY_WPS_BUTTON,
  100. .debounce_interval = MYNET_REXT_KEYS_DEBOUNCE_INTERVAL,
  101. .gpio = MYNET_REXT_GPIO_BTN_WPS,
  102. .active_low = 1,
  103. },
  104. {
  105. .desc = "RF Band switch",
  106. .type = EV_SW,
  107. .code = BTN_1,
  108. .debounce_interval = MYNET_REXT_KEYS_DEBOUNCE_INTERVAL,
  109. .gpio = MYNET_REXT_GPIO_SW_RF,
  110. },
  111. };
  112. static struct at803x_platform_data mynet_rext_at803x_data = {
  113. .disable_smarteee = 0,
  114. .enable_rgmii_rx_delay = 1,
  115. .enable_rgmii_tx_delay = 0,
  116. .fixup_rgmii_tx_delay = 1,
  117. };
  118. static struct mdio_board_info mynet_rext_mdio0_info[] = {
  119. {
  120. .bus_id = "ag71xx-mdio.0",
  121. .phy_addr = 4,
  122. .platform_data = &mynet_rext_at803x_data,
  123. },
  124. };
  125. static void mynet_rext_get_mac(const char *name, char *mac)
  126. {
  127. u8 *nvram = (u8 *) KSEG1ADDR(MYNET_REXT_NVRAM_ADDR);
  128. int err;
  129. err = ath79_nvram_parse_mac_addr(nvram, MYNET_REXT_NVRAM_SIZE,
  130. name, mac);
  131. if (err)
  132. pr_err("no MAC address found for %s\n", name);
  133. }
  134. static void __init mynet_rext_setup(void)
  135. {
  136. u8 *art = (u8 *) KSEG1ADDR(MYNET_REXT_ART_ADDR);
  137. u8 tmpmac[ETH_ALEN];
  138. ath79_register_m25p80(&mynet_rext_flash_data);
  139. /* GPIO configuration from drivers/char/GPIO8.c */
  140. ath79_gpio_output_select(MYNET_REXT_GPIO_LED_POWER,
  141. AR934X_GPIO_OUT_GPIO);
  142. ath79_gpio_output_select(MYNET_REXT_GPIO_LED_WIFI,
  143. AR934X_GPIO_OUT_GPIO);
  144. ath79_gpio_output_select(MYNET_REXT_GPIO_LED_RF_QTY1,
  145. AR934X_GPIO_OUT_GPIO);
  146. ath79_gpio_output_select(MYNET_REXT_GPIO_LED_RF_QTY2,
  147. AR934X_GPIO_OUT_GPIO);
  148. ath79_gpio_output_select(MYNET_REXT_GPIO_LED_RF_QTY3,
  149. AR934X_GPIO_OUT_GPIO);
  150. ath79_gpio_output_select(MYNET_REXT_GPIO_LED_ETHERNET,
  151. AR934X_GPIO_OUT_GPIO);
  152. ath79_register_leds_gpio(-1, ARRAY_SIZE(mynet_rext_leds_gpio),
  153. mynet_rext_leds_gpio);
  154. ath79_register_gpio_keys_polled(-1, MYNET_REXT_KEYS_POLL_INTERVAL,
  155. ARRAY_SIZE(mynet_rext_gpio_keys),
  156. mynet_rext_gpio_keys);
  157. ath79_setup_ar934x_eth_cfg(AR934X_ETH_CFG_RGMII_GMAC0 |
  158. AR934X_ETH_CFG_RXD_DELAY |
  159. AR934X_ETH_CFG_RDV_DELAY);
  160. ath79_register_mdio(0, 0x0);
  161. mdiobus_register_board_info(mynet_rext_mdio0_info,
  162. ARRAY_SIZE(mynet_rext_mdio0_info));
  163. /* LAN */
  164. mynet_rext_get_mac("et0macaddr=", ath79_eth0_data.mac_addr);
  165. /* GMAC0 is connected to an external PHY on Port 4 */
  166. ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  167. ath79_eth0_data.phy_mask = BIT(4);
  168. ath79_eth0_pll_data.pll_10 = 0x00001313; /* athrs_mac.c */
  169. ath79_eth0_pll_data.pll_1000 = 0x0e000000; /* athrs_mac.c */
  170. ath79_eth0_data.mii_bus_dev = &ath79_mdio0_device.dev;
  171. ath79_register_eth(0);
  172. /* WLAN */
  173. mynet_rext_get_mac("wl0_hwaddr=", tmpmac);
  174. ap91_pci_init(art + MYNET_REXT_WMAC_CALDATA_OFFSET, tmpmac);
  175. }
  176. MIPS_MACHINE(ATH79_MACH_MYNET_REXT, "MYNET-REXT",
  177. "WD My Net Wi-Fi Range Extender", mynet_rext_setup);