mach-archer-c7-v5.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /*
  2. * Atheros ARCHER_C7 reference board support
  3. *
  4. * Copyright (c) 2018 Arvid E. Picciani <aep@exys.org>
  5. * Copyright (c) 2017 Felix Fietkau <nbd@nbd.name>
  6. * Copyright (c) 2014 The Linux Foundation. All rights reserved.
  7. * Copyright (c) 2012 Gabor Juhos <juhosg@openwrt.org>
  8. *
  9. * Permission to use, copy, modify, and/or distribute this software for any
  10. * purpose with or without fee is hereby granted, provided that the above
  11. * copyright notice and this permission notice appear in all copies.
  12. *
  13. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  14. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  15. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  16. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  17. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  18. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  19. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  20. *
  21. */
  22. #include <linux/platform_device.h>
  23. #include <linux/ath9k_platform.h>
  24. #include <linux/ar8216_platform.h>
  25. #include <linux/proc_fs.h>
  26. #include <linux/gpio.h>
  27. #include <linux/spi/spi_gpio.h>
  28. #include <linux/spi/74x164.h>
  29. #include <asm/mach-ath79/ar71xx_regs.h>
  30. #include "common.h"
  31. #include "dev-m25p80.h"
  32. #include "machtypes.h"
  33. #include "pci.h"
  34. #include "dev-eth.h"
  35. #include "dev-gpio-buttons.h"
  36. #include "dev-leds-gpio.h"
  37. #include "dev-spi.h"
  38. #include "dev-usb.h"
  39. #include "dev-wmac.h"
  40. #define ARCHER_C7_GPIO_BTN_RESET 5
  41. #define ARCHER_C7_GPIO_BTN_WPS_WIFI 2
  42. #define ARCHER_C7_GPIO_LED_WLAN5 9
  43. #define ARCHER_C7_GPIO_LED_POWER 6
  44. #define ARCHER_C7_GPIO_LED_USB 7
  45. #define ARCHER_C7_GPIO_LED_WPS 1
  46. #define ARCHER_C7_GPIO_LED_LAN1 8
  47. #define ARCHER_C7_GPIO_LED_LAN2 17
  48. #define ARCHER_C7_GPIO_LED_LAN3 16
  49. #define ARCHER_C7_GPIO_LED_LAN4 15
  50. #define ARCHER_C7_GPIO_LED_WAN_GREEN 21
  51. #define ARCHER_C7_GPIO_LED_WAN_AMBER 20
  52. #define ARCHER_C7_GPIO_LED_WLAN2 14
  53. #define ARCHER_C7_GPIO_USB_PWR 19
  54. #define ARCHER_C7_KEYS_POLL_INTERVAL 20 /* msecs */
  55. #define ARCHER_C7_KEYS_DEBOUNCE_INTERVAL (3 * ARCHER_C7_KEYS_POLL_INTERVAL)
  56. #define ARCHER_C7_MAC0_OFFSET 0
  57. #define ARCHER_C7_MAC1_OFFSET 6
  58. #define ARCHER_C7_WMAC_CALDATA_OFFSET 0x1000
  59. #define ARCHER_C7_GPIO_MDC 3
  60. #define ARCHER_C7_GPIO_MDIO 4
  61. static struct gpio_led archer_c7_v5_leds_gpio[] __initdata = {
  62. {
  63. .name = "archer-c7-v5:green:power",
  64. .gpio = ARCHER_C7_GPIO_LED_POWER,
  65. .active_low = 1,
  66. }, {
  67. .name = "archer-c7-v5:green:wps",
  68. .gpio = ARCHER_C7_GPIO_LED_WPS,
  69. .active_low = 1,
  70. }, {
  71. .name = "archer-c7-v5:green:wlan2g",
  72. .gpio = ARCHER_C7_GPIO_LED_WLAN2,
  73. .active_low = 1,
  74. }, {
  75. .name = "archer-c7-v5:green:wlan5g",
  76. .gpio = ARCHER_C7_GPIO_LED_WLAN5,
  77. .active_low = 1,
  78. }, {
  79. .name = "archer-c7-v5:green:lan1",
  80. .gpio = ARCHER_C7_GPIO_LED_LAN1,
  81. .active_low = 1,
  82. }, {
  83. .name = "archer-c7-v5:green:lan2",
  84. .gpio = ARCHER_C7_GPIO_LED_LAN2,
  85. .active_low = 1,
  86. }, {
  87. .name = "archer-c7-v5:green:lan3",
  88. .gpio = ARCHER_C7_GPIO_LED_LAN3,
  89. .active_low = 1,
  90. }, {
  91. .name = "archer-c7-v5:green:lan4",
  92. .gpio = ARCHER_C7_GPIO_LED_LAN4,
  93. .active_low = 1,
  94. }, {
  95. .name = "archer-c7-v5:green:wan",
  96. .gpio = ARCHER_C7_GPIO_LED_WAN_GREEN,
  97. .active_low = 1,
  98. }, {
  99. .name = "archer-c7-v5:amber:wan",
  100. .gpio = ARCHER_C7_GPIO_LED_WAN_AMBER,
  101. .active_low = 1,
  102. }, {
  103. .name = "archer-c7-v5:green:usb",
  104. .gpio = ARCHER_C7_GPIO_LED_USB,
  105. .active_low = 1,
  106. },
  107. };
  108. static struct gpio_keys_button archer_c7_v5_gpio_keys[] __initdata = {
  109. {
  110. .desc = "WPS and WIFI button",
  111. .type = EV_KEY,
  112. .code = KEY_WPS_BUTTON,
  113. .debounce_interval = ARCHER_C7_KEYS_DEBOUNCE_INTERVAL,
  114. .gpio = ARCHER_C7_GPIO_BTN_WPS_WIFI,
  115. .active_low = 1,
  116. },
  117. {
  118. .desc = "Reset button",
  119. .type = EV_KEY,
  120. .code = KEY_RESTART,
  121. .debounce_interval = ARCHER_C7_KEYS_DEBOUNCE_INTERVAL,
  122. .gpio = ARCHER_C7_GPIO_BTN_RESET,
  123. .active_low = 1,
  124. },
  125. };
  126. static struct ar8327_pad_cfg archer_c7_v5_ar8337_pad0_cfg = {
  127. .mode = AR8327_PAD_MAC_SGMII,
  128. .sgmii_delay_en = true,
  129. };
  130. static struct ar8327_platform_data archer_c7_v5_ar8337_data = {
  131. .pad0_cfg = &archer_c7_v5_ar8337_pad0_cfg,
  132. .port0_cfg = {
  133. .force_link = 1,
  134. .speed = AR8327_PORT_SPEED_1000,
  135. .duplex = 1,
  136. .txpause = 1,
  137. .rxpause = 1,
  138. },
  139. };
  140. static struct mdio_board_info archer_c7_v5_mdio0_info[] = {
  141. {
  142. .bus_id = "ag71xx-mdio.0",
  143. .mdio_addr = 0,
  144. .platform_data = &archer_c7_v5_ar8337_data,
  145. },
  146. };
  147. static void __init archer_c7_v5_setup(void)
  148. {
  149. u8 *art = (u8 *) KSEG1ADDR(0x1f050000);
  150. u8 *mac = (u8 *) KSEG1ADDR(0x1f060008);
  151. ath79_register_m25p80(NULL);
  152. ath79_register_leds_gpio(-1, ARRAY_SIZE(archer_c7_v5_leds_gpio),
  153. archer_c7_v5_leds_gpio);
  154. ath79_register_gpio_keys_polled(-1, ARCHER_C7_KEYS_POLL_INTERVAL,
  155. ARRAY_SIZE(archer_c7_v5_gpio_keys),
  156. archer_c7_v5_gpio_keys);
  157. ath79_register_usb();
  158. ath79_gpio_output_select(ARCHER_C7_GPIO_MDC, QCA956X_GPIO_OUT_MUX_GE0_MDC);
  159. ath79_gpio_output_select(ARCHER_C7_GPIO_MDIO, QCA956X_GPIO_OUT_MUX_GE0_MDO);
  160. ath79_register_mdio(0, 0x0);
  161. mdiobus_register_board_info(archer_c7_v5_mdio0_info,
  162. ARRAY_SIZE(archer_c7_v5_mdio0_info));
  163. gpio_request_one(ARCHER_C7_GPIO_USB_PWR,
  164. GPIOF_OUT_INIT_HIGH | GPIOF_EXPORT_DIR_FIXED,
  165. "USB power");
  166. ath79_register_wmac(art + ARCHER_C7_WMAC_CALDATA_OFFSET, mac);
  167. ath79_register_pci();
  168. /* GMAC0 is connected to an AR8337 switch */
  169. ath79_init_mac(ath79_eth0_data.mac_addr, mac, 0);
  170. ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_SGMII;
  171. ath79_eth0_data.speed = SPEED_1000;
  172. ath79_eth0_data.duplex = DUPLEX_FULL;
  173. ath79_eth0_data.phy_mask = BIT(0);
  174. ath79_eth0_data.mii_bus_dev = &ath79_mdio0_device.dev;
  175. ath79_register_eth(0);
  176. }
  177. MIPS_MACHINE(ATH79_MACH_ARCHER_C7_V5, "ARCHER-C7-V5", "TP-LINK Archer C7 v5",
  178. archer_c7_v5_setup);