mach-tl-wr1043nd-v4.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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. * Copyright (C) 2017 Tim Thorpe <tim@tfthorpe.net>
  9. *
  10. * Derived from: mach-dir-869-a1.c
  11. *
  12. * This program is free software; you can redistribute it and/or modify it
  13. * under the terms of the GNU General Public License version 2 as published
  14. * by the Free Software Foundation.
  15. */
  16. #include <linux/gpio.h>
  17. #include <linux/init.h>
  18. #include <linux/pci.h>
  19. #include <linux/platform_device.h>
  20. #include <linux/ath9k_platform.h>
  21. #include <asm/mach-ath79/ath79.h>
  22. #include <asm/mach-ath79/irq.h>
  23. #include <asm/mach-ath79/ar71xx_regs.h>
  24. #include <linux/platform_data/phy-at803x.h>
  25. #include <linux/ar8216_platform.h>
  26. #include "common.h"
  27. #include "dev-ap9x-pci.h"
  28. #include "dev-eth.h"
  29. #include "dev-gpio-buttons.h"
  30. #include "dev-leds-gpio.h"
  31. #include "dev-m25p80.h"
  32. #include "dev-wmac.h"
  33. #include "dev-usb.h"
  34. #include "machtypes.h"
  35. #include "nvram.h"
  36. #define TL_WR1043_V4_GPIO_BTN_RESET 2
  37. #define TL_WR1043_V4_GPIO_BTN_RFKILL 5
  38. #define TL_WR1043_V4_GPIO_LED_WLAN 19
  39. #define TL_WR1043_V4_GPIO_LED_USB 7
  40. #define TL_WR1043_V4_GPIO_LED_WPS 1
  41. #define TL_WR1043_V4_GPIO_LED_SYSTEM 6
  42. #define TL_WR1043_V4_GPIO_USB_POWER 8
  43. #define TL_WR1043_V4_GPIO_LED_INET 15
  44. #define TL_WR1043_V4_GPIO_LED_WAN 16
  45. #define TL_WR1043_V4_GPIO_LED_LAN1 9
  46. #define TL_WR1043_V4_GPIO_LED_LAN2 14
  47. #define TL_WR1043_V4_GPIO_LED_LAN3 21
  48. #define TL_WR1043_V4_GPIO_LED_LAN4 20
  49. #define TL_WR1043_V4_KEYS_POLL_INTERVAL 20 /* msecs */
  50. #define TL_WR1043_V4_KEYS_DEBOUNCE_INTERVAL (3 * TL_WR1043_V4_KEYS_POLL_INTERVAL)
  51. #define TL_WR1043_V4_MAC_LOCATION 0x1ff50008
  52. #define TL_WR1043_V4_EEPROM_ADDR 0x1fff0000
  53. #define TL_WR1043_V4_WMAC_CALDATA_OFFSET 0x1000
  54. #define TL_WR1043_V5_MAC_LOCATION 0x1ff00008
  55. static struct gpio_led tl_wr1043nd_v4_leds_gpio[] __initdata = {
  56. {
  57. .name = "tp-link:green:wps",
  58. .gpio = TL_WR1043_V4_GPIO_LED_WPS,
  59. .active_low = 1,
  60. },
  61. {
  62. .name = "tp-link:green:system",
  63. .gpio = TL_WR1043_V4_GPIO_LED_SYSTEM,
  64. .active_low = 1,
  65. },
  66. {
  67. .name = "tp-link:green:wlan",
  68. .gpio = TL_WR1043_V4_GPIO_LED_WLAN,
  69. .active_low = 1,
  70. },
  71. {
  72. .name = "tp-link:green:usb",
  73. .gpio = TL_WR1043_V4_GPIO_LED_USB,
  74. .active_low = 1,
  75. },
  76. {
  77. .name = "tp-link:green:wan",
  78. .gpio = TL_WR1043_V4_GPIO_LED_INET,
  79. .active_low = 1,
  80. },
  81. {
  82. .name = "tp-link:orange:wan",
  83. .gpio = TL_WR1043_V4_GPIO_LED_WAN,
  84. .active_low = 1,
  85. },
  86. {
  87. .name = "tp-link:green:lan1",
  88. .gpio = TL_WR1043_V4_GPIO_LED_LAN1,
  89. .active_low = 1,
  90. },
  91. {
  92. .name = "tp-link:green:lan2",
  93. .gpio = TL_WR1043_V4_GPIO_LED_LAN2,
  94. .active_low = 1,
  95. },
  96. {
  97. .name = "tp-link:green:lan3",
  98. .gpio = TL_WR1043_V4_GPIO_LED_LAN3,
  99. .active_low = 1,
  100. },
  101. {
  102. .name = "tp-link:green:lan4",
  103. .gpio = TL_WR1043_V4_GPIO_LED_LAN4,
  104. .active_low = 1,
  105. },
  106. };
  107. static struct gpio_keys_button tl_wr1043nd_v4_gpio_keys[] __initdata = {
  108. {
  109. .desc = "Reset button",
  110. .type = EV_KEY,
  111. .code = KEY_RESTART,
  112. .debounce_interval = TL_WR1043_V4_KEYS_DEBOUNCE_INTERVAL,
  113. .gpio = TL_WR1043_V4_GPIO_BTN_RESET,
  114. .active_low = 1,
  115. },
  116. {
  117. .desc = "RFKILL button",
  118. .type = EV_KEY,
  119. .code = KEY_RFKILL,
  120. .debounce_interval = TL_WR1043_V4_KEYS_DEBOUNCE_INTERVAL,
  121. .gpio = TL_WR1043_V4_GPIO_BTN_RFKILL,
  122. .active_low = 1,
  123. },
  124. };
  125. static struct ar8327_pad_cfg tl_wr1043nd_v4_ar8327_pad0_cfg = {
  126. .mode = AR8327_PAD_MAC_SGMII,
  127. .sgmii_delay_en = true,
  128. };
  129. static struct ar8327_platform_data tl_wr1043nd_v4_ar8327_data = {
  130. .pad0_cfg = &tl_wr1043nd_v4_ar8327_pad0_cfg,
  131. .port0_cfg = {
  132. .force_link = 1,
  133. .speed = AR8327_PORT_SPEED_1000,
  134. .duplex = 1,
  135. .txpause = 1,
  136. .rxpause = 1,
  137. },
  138. };
  139. static struct mdio_board_info tl_wr1043nd_v4_mdio0_info[] = {
  140. {
  141. .bus_id = "ag71xx-mdio.0",
  142. .mdio_addr = 0,
  143. .platform_data = &tl_wr1043nd_v4_ar8327_data,
  144. },
  145. };
  146. static void __init tl_wr1043nd_v4_setup(void)
  147. {
  148. u8 *mac = (u8 *) KSEG1ADDR(TL_WR1043_V4_MAC_LOCATION);
  149. u8 *eeprom = (u8 *) KSEG1ADDR(TL_WR1043_V4_EEPROM_ADDR);
  150. ath79_register_m25p80(NULL);
  151. ath79_init_mac(ath79_eth0_data.mac_addr, mac, 0);
  152. ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_SGMII;
  153. ath79_eth0_data.mii_bus_dev = &ath79_mdio0_device.dev;
  154. ath79_eth0_data.phy_mask = BIT(0);
  155. mdiobus_register_board_info(tl_wr1043nd_v4_mdio0_info,
  156. ARRAY_SIZE(tl_wr1043nd_v4_mdio0_info));
  157. ath79_register_usb();
  158. ath79_register_mdio(0, 0);
  159. ath79_register_eth(0);
  160. ath79_register_wmac(eeprom + TL_WR1043_V4_WMAC_CALDATA_OFFSET, mac);
  161. ath79_register_leds_gpio(-1, ARRAY_SIZE(tl_wr1043nd_v4_leds_gpio),
  162. tl_wr1043nd_v4_leds_gpio);
  163. ath79_register_gpio_keys_polled(-1, TL_WR1043_V4_KEYS_POLL_INTERVAL,
  164. ARRAY_SIZE(tl_wr1043nd_v4_gpio_keys),
  165. tl_wr1043nd_v4_gpio_keys);
  166. gpio_request_one(TL_WR1043_V4_GPIO_USB_POWER,
  167. GPIOF_OUT_INIT_HIGH | GPIOF_EXPORT_DIR_FIXED,
  168. "USB power");
  169. }
  170. MIPS_MACHINE(ATH79_MACH_TL_WR1043ND_V4, "TL-WR1043ND-v4",
  171. "TP-LINK TL-WR1043ND v4", tl_wr1043nd_v4_setup);
  172. static struct gpio_led tl_wr1043n_v5_leds_gpio[] __initdata = {
  173. {
  174. .name = "tp-link:green:wps",
  175. .gpio = TL_WR1043_V4_GPIO_LED_WPS,
  176. .active_low = 1,
  177. },
  178. {
  179. .name = "tp-link:green:system",
  180. .gpio = TL_WR1043_V4_GPIO_LED_SYSTEM,
  181. .active_low = 1,
  182. },
  183. {
  184. .name = "tp-link:green:wlan",
  185. .gpio = TL_WR1043_V4_GPIO_LED_WLAN,
  186. .active_low = 1,
  187. },
  188. {
  189. .name = "tp-link:green:wan",
  190. .gpio = TL_WR1043_V4_GPIO_LED_INET,
  191. .active_low = 1,
  192. },
  193. {
  194. .name = "tp-link:orange:wan",
  195. .gpio = TL_WR1043_V4_GPIO_LED_WAN,
  196. .active_low = 1,
  197. },
  198. {
  199. .name = "tp-link:green:lan1",
  200. .gpio = TL_WR1043_V4_GPIO_LED_LAN1,
  201. .active_low = 1,
  202. },
  203. {
  204. .name = "tp-link:green:lan2",
  205. .gpio = TL_WR1043_V4_GPIO_LED_LAN2,
  206. .active_low = 1,
  207. },
  208. {
  209. .name = "tp-link:green:lan3",
  210. .gpio = TL_WR1043_V4_GPIO_LED_LAN3,
  211. .active_low = 1,
  212. },
  213. {
  214. .name = "tp-link:green:lan4",
  215. .gpio = TL_WR1043_V4_GPIO_LED_LAN4,
  216. .active_low = 1,
  217. },
  218. };
  219. /* The 1043Nv5 is identical to the 1043NDv4,
  220. * only missing the usb and small firmware layout changes */
  221. static void __init tl_wr1043nv5_setup(void)
  222. {
  223. u8 *art = (u8 *) KSEG1ADDR(TL_WR1043_V4_EEPROM_ADDR);
  224. u8 *mac = (u8 *) KSEG1ADDR(TL_WR1043_V5_MAC_LOCATION);
  225. ath79_register_m25p80(NULL);
  226. ath79_register_leds_gpio(-1, ARRAY_SIZE(tl_wr1043n_v5_leds_gpio),
  227. tl_wr1043n_v5_leds_gpio);
  228. ath79_register_gpio_keys_polled(-1, TL_WR1043_V4_KEYS_POLL_INTERVAL,
  229. ARRAY_SIZE(tl_wr1043nd_v4_gpio_keys),
  230. tl_wr1043nd_v4_gpio_keys);
  231. platform_device_register(&ath79_mdio0_device);
  232. mdiobus_register_board_info(tl_wr1043nd_v4_mdio0_info,
  233. ARRAY_SIZE(tl_wr1043nd_v4_mdio0_info));
  234. ath79_register_wmac(art + TL_WR1043_V4_WMAC_CALDATA_OFFSET, mac);
  235. ath79_init_mac(ath79_eth0_data.mac_addr, mac, 0);
  236. /* GMAC0 is connected to an AR8337 switch */
  237. ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_SGMII;
  238. ath79_eth0_data.speed = SPEED_1000;
  239. ath79_eth0_data.duplex = DUPLEX_FULL;
  240. ath79_eth0_data.phy_mask = BIT(0);
  241. ath79_eth0_data.mii_bus_dev = &ath79_mdio0_device.dev;
  242. ath79_register_eth(0);
  243. }
  244. MIPS_MACHINE(ATH79_MACH_TL_WR1043N_V5, "TL-WR1043N-v5", "TP-LINK TL-WR1043N v5",
  245. tl_wr1043nv5_setup);