mach-tl-wr1043nd-v4.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /*
  2. * TP-LINK WR1043 V4 support
  3. *
  4. * Copyright (C) 2015-2016 P. Wassi <p.wassi at gmx.at>
  5. * Copyright (C) 2016 Matthias Schiffer <mschiffer@universe-factory.net>
  6. * Copyright (C) 2016 Andreas Ziegler <github@andreas-ziegler.de>
  7. * Copyright (C) 2016 Ludwig Thomeczek <ledesrc@wxorx.net>
  8. *
  9. * Derived from: mach-dir-869-a1.c
  10. *
  11. * This program is free software; you can redistribute it and/or modify it
  12. * under the terms of the GNU General Public License version 2 as published
  13. * by the Free Software Foundation.
  14. */
  15. #include <linux/gpio.h>
  16. #include <linux/init.h>
  17. #include <linux/pci.h>
  18. #include <linux/platform_device.h>
  19. #include <linux/ath9k_platform.h>
  20. #include <asm/mach-ath79/ath79.h>
  21. #include <asm/mach-ath79/irq.h>
  22. #include <asm/mach-ath79/ar71xx_regs.h>
  23. #include <linux/platform_data/phy-at803x.h>
  24. #include <linux/ar8216_platform.h>
  25. #include "common.h"
  26. #include "dev-ap9x-pci.h"
  27. #include "dev-eth.h"
  28. #include "dev-gpio-buttons.h"
  29. #include "dev-leds-gpio.h"
  30. #include "dev-m25p80.h"
  31. #include "dev-wmac.h"
  32. #include "dev-usb.h"
  33. #include "machtypes.h"
  34. #include "nvram.h"
  35. #define TL_WR1043_V4_GPIO_BTN_RESET 2
  36. #define TL_WR1043_V4_GPIO_BTN_RFKILL 5
  37. #define TL_WR1043_V4_GPIO_LED_WLAN 19
  38. #define TL_WR1043_V4_GPIO_LED_USB 7
  39. #define TL_WR1043_V4_GPIO_LED_WPS 1
  40. #define TL_WR1043_V4_GPIO_LED_SYSTEM 6
  41. #define TL_WR1043_V4_GPIO_USB_POWER 8
  42. #define TL_WR1043_V4_GPIO_LED_WAN 15
  43. #define TL_WR1043_V4_GPIO_LED_LAN1 9
  44. #define TL_WR1043_V4_GPIO_LED_LAN2 14
  45. #define TL_WR1043_V4_GPIO_LED_LAN3 21
  46. #define TL_WR1043_V4_GPIO_LED_LAN4 20
  47. #define TL_WR1043_V4_KEYS_POLL_INTERVAL 20 /* msecs */
  48. #define TL_WR1043_V4_KEYS_DEBOUNCE_INTERVAL (3 * TL_WR1043_V4_KEYS_POLL_INTERVAL)
  49. #define TL_WR1043_V4_MAC_LOCATION 0x1ff50008
  50. #define TL_WR1043_V4_EEPROM_ADDR 0x1fff0000
  51. #define TL_WR1043_V4_WMAC_CALDATA_OFFSET 0x1000
  52. static struct gpio_led tl_wr1043nd_v4_leds_gpio[] __initdata = {
  53. {
  54. .name = "tp-link:green:wps",
  55. .gpio = TL_WR1043_V4_GPIO_LED_WPS,
  56. .active_low = 1,
  57. },
  58. {
  59. .name = "tp-link:green:system",
  60. .gpio = TL_WR1043_V4_GPIO_LED_SYSTEM,
  61. .active_low = 1,
  62. },
  63. {
  64. .name = "tp-link:green:wlan",
  65. .gpio = TL_WR1043_V4_GPIO_LED_WLAN,
  66. .active_low = 1,
  67. },
  68. {
  69. .name = "tp-link:green:usb",
  70. .gpio = TL_WR1043_V4_GPIO_LED_USB,
  71. .active_low = 1,
  72. },
  73. {
  74. .name = "tp-link:green:wan",
  75. .gpio = TL_WR1043_V4_GPIO_LED_WAN,
  76. .active_low = 1,
  77. },
  78. {
  79. .name = "tp-link:green:lan1",
  80. .gpio = TL_WR1043_V4_GPIO_LED_LAN1,
  81. .active_low = 1,
  82. },
  83. {
  84. .name = "tp-link:green:lan2",
  85. .gpio = TL_WR1043_V4_GPIO_LED_LAN2,
  86. .active_low = 1,
  87. },
  88. {
  89. .name = "tp-link:green:lan3",
  90. .gpio = TL_WR1043_V4_GPIO_LED_LAN3,
  91. .active_low = 1,
  92. },
  93. {
  94. .name = "tp-link:green:lan4",
  95. .gpio = TL_WR1043_V4_GPIO_LED_LAN4,
  96. .active_low = 1,
  97. },
  98. };
  99. static struct gpio_keys_button tl_wr1043nd_v4_gpio_keys[] __initdata = {
  100. {
  101. .desc = "Reset button",
  102. .type = EV_KEY,
  103. .code = KEY_RESTART,
  104. .debounce_interval = TL_WR1043_V4_KEYS_DEBOUNCE_INTERVAL,
  105. .gpio = TL_WR1043_V4_GPIO_BTN_RESET,
  106. .active_low = 1,
  107. },
  108. {
  109. .desc = "RFKILL button",
  110. .type = EV_KEY,
  111. .code = KEY_RFKILL,
  112. .debounce_interval = TL_WR1043_V4_KEYS_DEBOUNCE_INTERVAL,
  113. .gpio = TL_WR1043_V4_GPIO_BTN_RFKILL,
  114. .active_low = 1,
  115. },
  116. };
  117. static struct ar8327_pad_cfg tl_wr1043nd_v4_ar8327_pad0_cfg = {
  118. .mode = AR8327_PAD_MAC_SGMII,
  119. .sgmii_delay_en = true,
  120. };
  121. static struct ar8327_platform_data tl_wr1043nd_v4_ar8327_data = {
  122. .pad0_cfg = &tl_wr1043nd_v4_ar8327_pad0_cfg,
  123. .port0_cfg = {
  124. .force_link = 1,
  125. .speed = AR8327_PORT_SPEED_1000,
  126. .duplex = 1,
  127. .txpause = 1,
  128. .rxpause = 1,
  129. },
  130. };
  131. static struct mdio_board_info tl_wr1043nd_v4_mdio0_info[] = {
  132. {
  133. .bus_id = "ag71xx-mdio.0",
  134. .phy_addr = 0,
  135. .platform_data = &tl_wr1043nd_v4_ar8327_data,
  136. },
  137. };
  138. static void __init tl_wr1043nd_v4_setup(void)
  139. {
  140. u8 *mac = (u8 *) KSEG1ADDR(TL_WR1043_V4_MAC_LOCATION);
  141. u8 *eeprom = (u8 *) KSEG1ADDR(TL_WR1043_V4_EEPROM_ADDR);
  142. ath79_register_m25p80(NULL);
  143. ath79_init_mac(ath79_eth0_data.mac_addr, mac, 0);
  144. ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_SGMII;
  145. ath79_eth0_data.mii_bus_dev = &ath79_mdio0_device.dev;
  146. ath79_eth0_data.phy_mask = BIT(0);
  147. mdiobus_register_board_info(tl_wr1043nd_v4_mdio0_info,
  148. ARRAY_SIZE(tl_wr1043nd_v4_mdio0_info));
  149. ath79_register_usb();
  150. ath79_register_mdio(0, 0);
  151. ath79_register_eth(0);
  152. ath79_register_wmac(eeprom + TL_WR1043_V4_WMAC_CALDATA_OFFSET, mac);
  153. ath79_register_leds_gpio(-1, ARRAY_SIZE(tl_wr1043nd_v4_leds_gpio),
  154. tl_wr1043nd_v4_leds_gpio);
  155. ath79_register_gpio_keys_polled(-1, TL_WR1043_V4_KEYS_POLL_INTERVAL,
  156. ARRAY_SIZE(tl_wr1043nd_v4_gpio_keys),
  157. tl_wr1043nd_v4_gpio_keys);
  158. gpio_request_one(TL_WR1043_V4_GPIO_USB_POWER,
  159. GPIOF_OUT_INIT_HIGH | GPIOF_EXPORT_DIR_FIXED,
  160. "USB power");
  161. }
  162. MIPS_MACHINE(ATH79_MACH_TL_WR1043ND_V4, "TL-WR1043ND-v4",
  163. "TP-LINK TL-WR1043ND v4", tl_wr1043nd_v4_setup);