mach-mynet-n600.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /*
  2. * WD My Net N600 board support
  3. *
  4. * Copyright (C) 2013 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/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 <asm/mach-ath79/ar71xx_regs.h>
  17. #include "common.h"
  18. #include "dev-ap9x-pci.h"
  19. #include "dev-eth.h"
  20. #include "dev-gpio-buttons.h"
  21. #include "dev-leds-gpio.h"
  22. #include "dev-m25p80.h"
  23. #include "dev-spi.h"
  24. #include "dev-usb.h"
  25. #include "dev-wmac.h"
  26. #include "machtypes.h"
  27. #include "nvram.h"
  28. #define MYNET_N600_GPIO_LED_WIFI 0
  29. #define MYNET_N600_GPIO_LED_POWER 11
  30. #define MYNET_N600_GPIO_LED_INTERNET 12
  31. #define MYNET_N600_GPIO_LED_WPS 13
  32. #define MYNET_N600_GPIO_LED_LAN1 4
  33. #define MYNET_N600_GPIO_LED_LAN2 3
  34. #define MYNET_N600_GPIO_LED_LAN3 2
  35. #define MYNET_N600_GPIO_LED_LAN4 1
  36. #define MYNET_N600_GPIO_BTN_RESET 16
  37. #define MYNET_N600_GPIO_BTN_WPS 17
  38. #define MYNET_N600_GPIO_EXTERNAL_LNA0 14
  39. #define MYNET_N600_GPIO_EXTERNAL_LNA1 15
  40. #define MYNET_N600_KEYS_POLL_INTERVAL 20 /* msecs */
  41. #define MYNET_N600_KEYS_DEBOUNCE_INTERVAL (3 * MYNET_N600_KEYS_POLL_INTERVAL)
  42. #define MYNET_N600_MAC0_OFFSET 0
  43. #define MYNET_N600_MAC1_OFFSET 6
  44. #define MYNET_N600_WMAC_CALDATA_OFFSET 0x1000
  45. #define MYNET_N600_PCIE_CALDATA_OFFSET 0x5000
  46. #define MYNET_N600_NVRAM_ADDR 0x1f058010
  47. #define MYNET_N600_NVRAM_SIZE 0x7ff0
  48. static struct gpio_led mynet_n600_leds_gpio[] __initdata = {
  49. {
  50. .name = "wd:blue:power",
  51. .gpio = MYNET_N600_GPIO_LED_POWER,
  52. .active_low = 0,
  53. },
  54. {
  55. .name = "wd:blue:wps",
  56. .gpio = MYNET_N600_GPIO_LED_WPS,
  57. .active_low = 0,
  58. },
  59. {
  60. .name = "wd:blue:wireless",
  61. .gpio = MYNET_N600_GPIO_LED_WIFI,
  62. .active_low = 0,
  63. },
  64. {
  65. .name = "wd:blue:internet",
  66. .gpio = MYNET_N600_GPIO_LED_INTERNET,
  67. .active_low = 0,
  68. },
  69. {
  70. .name = "wd:green:lan1",
  71. .gpio = MYNET_N600_GPIO_LED_LAN1,
  72. .active_low = 1,
  73. },
  74. {
  75. .name = "wd:green:lan2",
  76. .gpio = MYNET_N600_GPIO_LED_LAN2,
  77. .active_low = 1,
  78. },
  79. {
  80. .name = "wd:green:lan3",
  81. .gpio = MYNET_N600_GPIO_LED_LAN3,
  82. .active_low = 1,
  83. },
  84. {
  85. .name = "wd:green:lan4",
  86. .gpio = MYNET_N600_GPIO_LED_LAN4,
  87. .active_low = 1,
  88. },
  89. };
  90. static struct gpio_keys_button mynet_n600_gpio_keys[] __initdata = {
  91. {
  92. .desc = "Reset button",
  93. .type = EV_KEY,
  94. .code = KEY_RESTART,
  95. .debounce_interval = MYNET_N600_KEYS_DEBOUNCE_INTERVAL,
  96. .gpio = MYNET_N600_GPIO_BTN_RESET,
  97. .active_low = 1,
  98. },
  99. {
  100. .desc = "WPS button",
  101. .type = EV_KEY,
  102. .code = KEY_WPS_BUTTON,
  103. .debounce_interval = MYNET_N600_KEYS_DEBOUNCE_INTERVAL,
  104. .gpio = MYNET_N600_GPIO_BTN_WPS,
  105. .active_low = 1,
  106. },
  107. };
  108. static void mynet_n600_get_mac(const char *name, char *mac)
  109. {
  110. u8 *nvram = (u8 *) KSEG1ADDR(MYNET_N600_NVRAM_ADDR);
  111. int err;
  112. err = ath79_nvram_parse_mac_addr(nvram, MYNET_N600_NVRAM_SIZE,
  113. name, mac);
  114. if (err)
  115. pr_err("no MAC address found for %s\n", name);
  116. }
  117. #define MYNET_N600_WAN_PHY_MASK BIT(0)
  118. static void __init mynet_n600_setup(void)
  119. {
  120. u8 *art = (u8 *) KSEG1ADDR(0x1fff0000);
  121. u8 tmpmac[ETH_ALEN];
  122. ath79_register_m25p80(NULL);
  123. ath79_gpio_output_select(MYNET_N600_GPIO_LED_LAN1,
  124. AR934X_GPIO_OUT_GPIO);
  125. ath79_gpio_output_select(MYNET_N600_GPIO_LED_LAN2,
  126. AR934X_GPIO_OUT_GPIO);
  127. ath79_gpio_output_select(MYNET_N600_GPIO_LED_LAN3,
  128. AR934X_GPIO_OUT_GPIO);
  129. ath79_gpio_output_select(MYNET_N600_GPIO_LED_LAN4,
  130. AR934X_GPIO_OUT_GPIO);
  131. ath79_gpio_output_select(MYNET_N600_GPIO_LED_INTERNET,
  132. AR934X_GPIO_OUT_GPIO);
  133. ath79_register_leds_gpio(-1, ARRAY_SIZE(mynet_n600_leds_gpio),
  134. mynet_n600_leds_gpio);
  135. ath79_register_gpio_keys_polled(-1, MYNET_N600_KEYS_POLL_INTERVAL,
  136. ARRAY_SIZE(mynet_n600_gpio_keys),
  137. mynet_n600_gpio_keys);
  138. /*
  139. * Control signal for external LNAs 0 and 1
  140. * Taken from GPL bootloader source:
  141. * board/ar7240/db12x/alpha_gpio.c
  142. */
  143. ath79_wmac_set_ext_lna_gpio(0, MYNET_N600_GPIO_EXTERNAL_LNA0);
  144. ath79_wmac_set_ext_lna_gpio(1, MYNET_N600_GPIO_EXTERNAL_LNA1);
  145. mynet_n600_get_mac("wlan24mac=", tmpmac);
  146. ath79_register_wmac(art + MYNET_N600_WMAC_CALDATA_OFFSET, tmpmac);
  147. mynet_n600_get_mac("wlan5mac=", tmpmac);
  148. ap91_pci_init(art + MYNET_N600_PCIE_CALDATA_OFFSET, tmpmac);
  149. ath79_setup_ar934x_eth_cfg(AR934X_ETH_CFG_SW_ONLY_MODE |
  150. AR934X_ETH_CFG_SW_PHY_SWAP);
  151. ath79_register_mdio(1, 0x0);
  152. /* LAN */
  153. mynet_n600_get_mac("lanmac=", ath79_eth1_data.mac_addr);
  154. /* GMAC1 is connected to the internal switch */
  155. ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_GMII;
  156. ath79_register_eth(1);
  157. /* WAN */
  158. mynet_n600_get_mac("wanmac=", ath79_eth0_data.mac_addr);
  159. /* GMAC0 is connected to the PHY4 of the internal switch */
  160. ath79_switch_data.phy4_mii_en = 1;
  161. ath79_switch_data.phy_poll_mask = MYNET_N600_WAN_PHY_MASK;
  162. ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
  163. ath79_eth0_data.phy_mask = MYNET_N600_WAN_PHY_MASK;
  164. ath79_eth0_data.mii_bus_dev = &ath79_mdio1_device.dev;
  165. ath79_register_eth(0);
  166. ath79_register_usb();
  167. }
  168. MIPS_MACHINE(ATH79_MACH_MYNET_N600, "MYNET-N600", "WD My Net N600",
  169. mynet_n600_setup);