mach-tl-wr841n-v9.c 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. /*
  2. * TP-LINK TL-WR841N/ND v9/v11 / TL-WR842N/ND v3
  3. *
  4. * Copyright (C) 2014 Matthias Schiffer <mschiffer@universe-factory.net>
  5. * Copyright (C) 2016 Cezary Jackiewicz <cezary@eko.one.pl>
  6. * Copyright (C) 2016 Stijn Segers <francesco.borromini@gmail.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License version 2 as published
  10. * by the Free Software Foundation.
  11. */
  12. #include <linux/gpio.h>
  13. #include <linux/platform_device.h>
  14. #include <asm/mach-ath79/ath79.h>
  15. #include <asm/mach-ath79/ar71xx_regs.h>
  16. #include "common.h"
  17. #include "dev-eth.h"
  18. #include "dev-gpio-buttons.h"
  19. #include "dev-leds-gpio.h"
  20. #include "dev-m25p80.h"
  21. #include "dev-usb.h"
  22. #include "dev-wmac.h"
  23. #include "machtypes.h"
  24. #define TL_WR841NV9_GPIO_LED_WLAN 13
  25. #define TL_WR841NV9_GPIO_LED_QSS 3
  26. #define TL_WR841NV9_GPIO_LED_WAN 4
  27. #define TL_WR841NV9_GPIO_LED_LAN1 16
  28. #define TL_WR841NV9_GPIO_LED_LAN2 15
  29. #define TL_WR841NV9_GPIO_LED_LAN3 14
  30. #define TL_WR841NV9_GPIO_LED_LAN4 11
  31. #define TL_WR841NV9_GPIO_BTN_RESET 12
  32. #define TL_WR841NV9_GPIO_BTN_WIFI 17
  33. #define TL_WR841NV11_GPIO_LED_SYSTEM 1
  34. #define TL_WR841NV11_GPIO_LED_QSS 3
  35. #define TL_WR841NV11_GPIO_LED_WAN 4
  36. #define TL_WR841NV11_GPIO_LED_WAN_STATUS 2
  37. #define TL_WR841NV11_GPIO_LED_WLAN 13
  38. #define TL_WR841NV11_GPIO_LED_LAN1 16
  39. #define TL_WR841NV11_GPIO_LED_LAN2 15
  40. #define TL_WR841NV11_GPIO_LED_LAN3 14
  41. #define TL_WR841NV11_GPIO_LED_LAN4 11
  42. #define TL_WR841NV11_GPIO_BTN_RESET 12
  43. #define TL_WR841NV11_GPIO_BTN_WIFI 17
  44. #define TL_WR842NV3_GPIO_LED_SYSTEM 2
  45. #define TL_WR842NV3_GPIO_LED_WLAN 3
  46. #define TL_WR842NV3_GPIO_LED_WAN_RED 4
  47. #define TL_WR842NV3_GPIO_LED_WAN_GREEN 11
  48. #define TL_WR842NV3_GPIO_LED_LAN1 12
  49. #define TL_WR842NV3_GPIO_LED_LAN2 13
  50. #define TL_WR842NV3_GPIO_LED_LAN3 14
  51. #define TL_WR842NV3_GPIO_LED_LAN4 15
  52. #define TL_WR842NV3_GPIO_LED_3G 16
  53. #define TL_WR842NV3_GPIO_LED_WPS 17
  54. #define TL_WR842NV3_GPIO_BTN_RESET 1
  55. #define TL_WR842NV3_GPIO_BTN_WIFI 0
  56. #define TL_WR841NV9_KEYS_POLL_INTERVAL 20 /* msecs */
  57. #define TL_WR841NV9_KEYS_DEBOUNCE_INTERVAL (3 * TL_WR841NV9_KEYS_POLL_INTERVAL)
  58. static const char *tl_wr841n_v9_part_probes[] = {
  59. "tp-link",
  60. NULL,
  61. };
  62. static struct flash_platform_data tl_wr841n_v9_flash_data = {
  63. .part_probes = tl_wr841n_v9_part_probes,
  64. };
  65. static struct gpio_led tl_wr841n_v9_leds_gpio[] __initdata = {
  66. {
  67. .name = "tp-link:green:lan1",
  68. .gpio = TL_WR841NV9_GPIO_LED_LAN1,
  69. .active_low = 1,
  70. }, {
  71. .name = "tp-link:green:lan2",
  72. .gpio = TL_WR841NV9_GPIO_LED_LAN2,
  73. .active_low = 1,
  74. }, {
  75. .name = "tp-link:green:lan3",
  76. .gpio = TL_WR841NV9_GPIO_LED_LAN3,
  77. .active_low = 1,
  78. }, {
  79. .name = "tp-link:green:lan4",
  80. .gpio = TL_WR841NV9_GPIO_LED_LAN4,
  81. .active_low = 1,
  82. }, {
  83. .name = "tp-link:green:qss",
  84. .gpio = TL_WR841NV9_GPIO_LED_QSS,
  85. .active_low = 1,
  86. }, {
  87. .name = "tp-link:green:wan",
  88. .gpio = TL_WR841NV9_GPIO_LED_WAN,
  89. .active_low = 1,
  90. }, {
  91. .name = "tp-link:green:wlan",
  92. .gpio = TL_WR841NV9_GPIO_LED_WLAN,
  93. .active_low = 1,
  94. },
  95. };
  96. static struct gpio_keys_button tl_wr841n_v9_gpio_keys[] __initdata = {
  97. {
  98. .desc = "Reset button",
  99. .type = EV_KEY,
  100. .code = KEY_RESTART,
  101. .debounce_interval = TL_WR841NV9_KEYS_DEBOUNCE_INTERVAL,
  102. .gpio = TL_WR841NV9_GPIO_BTN_RESET,
  103. .active_low = 1,
  104. }, {
  105. .desc = "WIFI button",
  106. .type = EV_KEY,
  107. .code = KEY_RFKILL,
  108. .debounce_interval = TL_WR841NV9_KEYS_DEBOUNCE_INTERVAL,
  109. .gpio = TL_WR841NV9_GPIO_BTN_WIFI,
  110. .active_low = 1,
  111. }
  112. };
  113. static struct gpio_led tl_wr841n_v11_leds_gpio[] __initdata = {
  114. {
  115. .name = "tp-link:green:lan1",
  116. .gpio = TL_WR841NV9_GPIO_LED_LAN1,
  117. .active_low = 1,
  118. }, {
  119. .name = "tp-link:green:lan2",
  120. .gpio = TL_WR841NV9_GPIO_LED_LAN2,
  121. .active_low = 1,
  122. }, {
  123. .name = "tp-link:green:lan3",
  124. .gpio = TL_WR841NV9_GPIO_LED_LAN3,
  125. .active_low = 1,
  126. }, {
  127. .name = "tp-link:green:lan4",
  128. .gpio = TL_WR841NV9_GPIO_LED_LAN4,
  129. .active_low = 1,
  130. }, {
  131. .name = "tp-link:green:qss",
  132. .gpio = TL_WR841NV9_GPIO_LED_QSS,
  133. .active_low = 1,
  134. }, {
  135. .name = "tp-link:green:system",
  136. .gpio = TL_WR841NV11_GPIO_LED_SYSTEM,
  137. .active_low = 1,
  138. }, {
  139. .name = "tp-link:green:wan",
  140. .gpio = TL_WR841NV9_GPIO_LED_WAN,
  141. .active_low = 1,
  142. }, {
  143. .name = "tp-link:green:wan_status",
  144. .gpio = TL_WR841NV11_GPIO_LED_WAN_STATUS,
  145. .active_low = 1,
  146. }, {
  147. .name = "tp-link:green:wlan",
  148. .gpio = TL_WR841NV9_GPIO_LED_WLAN,
  149. .active_low = 1,
  150. },
  151. };
  152. static struct gpio_led tl_wr842n_v3_leds_gpio[] __initdata = {
  153. {
  154. .name = "tp-link:green:lan1",
  155. .gpio = TL_WR842NV3_GPIO_LED_LAN1,
  156. .active_low = 1,
  157. }, {
  158. .name = "tp-link:green:lan2",
  159. .gpio = TL_WR842NV3_GPIO_LED_LAN2,
  160. .active_low = 1,
  161. }, {
  162. .name = "tp-link:green:lan3",
  163. .gpio = TL_WR842NV3_GPIO_LED_LAN3,
  164. .active_low = 1,
  165. }, {
  166. .name = "tp-link:green:lan4",
  167. .gpio = TL_WR842NV3_GPIO_LED_LAN4,
  168. .active_low = 1,
  169. }, {
  170. .name = "tp-link:green:wan",
  171. .gpio = TL_WR842NV3_GPIO_LED_WAN_GREEN,
  172. .active_low = 1,
  173. }, {
  174. .name = "tp-link:red:wan",
  175. .gpio = TL_WR842NV3_GPIO_LED_WAN_RED,
  176. .active_low = 1,
  177. }, {
  178. .name = "tp-link:green:wlan",
  179. .gpio = TL_WR842NV3_GPIO_LED_WLAN,
  180. .active_low = 1,
  181. }, {
  182. .name = "tp-link:green:system",
  183. .gpio = TL_WR842NV3_GPIO_LED_SYSTEM,
  184. .active_low = 1,
  185. }, {
  186. .name = "tp-link:green:3g",
  187. .gpio = TL_WR842NV3_GPIO_LED_3G,
  188. .active_low = 1,
  189. }, {
  190. .name = "tp-link:green:wps",
  191. .gpio = TL_WR842NV3_GPIO_LED_WPS,
  192. .active_low = 1,
  193. },
  194. };
  195. static struct gpio_keys_button tl_wr842n_v3_gpio_keys[] __initdata = {
  196. {
  197. .desc = "Reset button",
  198. .type = EV_KEY,
  199. .code = KEY_RESTART,
  200. .debounce_interval = TL_WR841NV9_KEYS_DEBOUNCE_INTERVAL,
  201. .gpio = TL_WR842NV3_GPIO_BTN_RESET,
  202. .active_low = 1,
  203. }, {
  204. .desc = "WIFI button",
  205. .type = EV_KEY,
  206. .code = KEY_RFKILL,
  207. .debounce_interval = TL_WR841NV9_KEYS_DEBOUNCE_INTERVAL,
  208. .gpio = TL_WR842NV3_GPIO_BTN_WIFI,
  209. .active_low = 1,
  210. }
  211. };
  212. static void __init tl_ap143_setup(void)
  213. {
  214. u8 *mac = (u8 *) KSEG1ADDR(0x1f01fc00);
  215. u8 *ee = (u8 *) KSEG1ADDR(0x1fff1000);
  216. u8 tmpmac[ETH_ALEN];
  217. ath79_register_m25p80(&tl_wr841n_v9_flash_data);
  218. ath79_setup_ar933x_phy4_switch(false, false);
  219. ath79_register_mdio(0, 0x0);
  220. /* LAN */
  221. ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_GMII;
  222. ath79_eth1_data.duplex = DUPLEX_FULL;
  223. ath79_switch_data.phy_poll_mask |= BIT(4);
  224. ath79_init_mac(ath79_eth1_data.mac_addr, mac, 0);
  225. ath79_register_eth(1);
  226. /* WAN */
  227. ath79_switch_data.phy4_mii_en = 1;
  228. ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
  229. ath79_eth0_data.duplex = DUPLEX_FULL;
  230. ath79_eth0_data.speed = SPEED_100;
  231. ath79_eth0_data.phy_mask = BIT(4);
  232. ath79_init_mac(ath79_eth0_data.mac_addr, mac, 1);
  233. ath79_register_eth(0);
  234. ath79_init_mac(tmpmac, mac, 0);
  235. ath79_register_wmac(ee, tmpmac);
  236. }
  237. static void __init tl_wr841n_v9_setup(void)
  238. {
  239. tl_ap143_setup();
  240. ath79_register_leds_gpio(-1, ARRAY_SIZE(tl_wr841n_v9_leds_gpio),
  241. tl_wr841n_v9_leds_gpio);
  242. ath79_register_gpio_keys_polled(1, TL_WR841NV9_KEYS_POLL_INTERVAL,
  243. ARRAY_SIZE(tl_wr841n_v9_gpio_keys),
  244. tl_wr841n_v9_gpio_keys);
  245. }
  246. MIPS_MACHINE(ATH79_MACH_TL_WR841N_V9, "TL-WR841N-v9", "TP-LINK TL-WR841N/ND v9",
  247. tl_wr841n_v9_setup);
  248. static void __init tl_wr841n_v11_setup(void)
  249. {
  250. tl_ap143_setup();
  251. ath79_register_leds_gpio(-1, ARRAY_SIZE(tl_wr841n_v11_leds_gpio),
  252. tl_wr841n_v11_leds_gpio);
  253. ath79_register_gpio_keys_polled(1, TL_WR841NV9_KEYS_POLL_INTERVAL,
  254. ARRAY_SIZE(tl_wr841n_v9_gpio_keys),
  255. tl_wr841n_v9_gpio_keys);
  256. }
  257. MIPS_MACHINE(ATH79_MACH_TL_WR841N_V11, "TL-WR841N-v11", "TP-LINK TL-WR841N/ND v11",
  258. tl_wr841n_v11_setup);
  259. static void __init tl_wr842n_v3_setup(void)
  260. {
  261. tl_ap143_setup();
  262. ath79_register_leds_gpio(-1, ARRAY_SIZE(tl_wr842n_v3_leds_gpio),
  263. tl_wr842n_v3_leds_gpio);
  264. ath79_register_gpio_keys_polled(1, TL_WR841NV9_KEYS_POLL_INTERVAL,
  265. ARRAY_SIZE(tl_wr842n_v3_gpio_keys),
  266. tl_wr842n_v3_gpio_keys);
  267. ath79_register_usb();
  268. }
  269. MIPS_MACHINE(ATH79_MACH_TL_WR842N_V3, "TL-WR842N-v3", "TP-LINK TL-WR842N/ND v3",
  270. tl_wr842n_v3_setup);