mach-tl-wr841n-v9.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /*
  2. * TP-LINK TL-WR841N/ND v9/v11
  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_WR841NV9_KEYS_POLL_INTERVAL 20 /* msecs */
  45. #define TL_WR841NV9_KEYS_DEBOUNCE_INTERVAL (3 * TL_WR841NV9_KEYS_POLL_INTERVAL)
  46. static const char *tl_wr841n_v9_part_probes[] = {
  47. "tp-link",
  48. NULL,
  49. };
  50. static struct flash_platform_data tl_wr841n_v9_flash_data = {
  51. .part_probes = tl_wr841n_v9_part_probes,
  52. };
  53. static struct gpio_led tl_wr841n_v9_leds_gpio[] __initdata = {
  54. {
  55. .name = "tp-link:green:lan1",
  56. .gpio = TL_WR841NV9_GPIO_LED_LAN1,
  57. .active_low = 1,
  58. }, {
  59. .name = "tp-link:green:lan2",
  60. .gpio = TL_WR841NV9_GPIO_LED_LAN2,
  61. .active_low = 1,
  62. }, {
  63. .name = "tp-link:green:lan3",
  64. .gpio = TL_WR841NV9_GPIO_LED_LAN3,
  65. .active_low = 1,
  66. }, {
  67. .name = "tp-link:green:lan4",
  68. .gpio = TL_WR841NV9_GPIO_LED_LAN4,
  69. .active_low = 1,
  70. }, {
  71. .name = "tp-link:green:qss",
  72. .gpio = TL_WR841NV9_GPIO_LED_QSS,
  73. .active_low = 1,
  74. }, {
  75. .name = "tp-link:green:wan",
  76. .gpio = TL_WR841NV9_GPIO_LED_WAN,
  77. .active_low = 1,
  78. }, {
  79. .name = "tp-link:green:wlan",
  80. .gpio = TL_WR841NV9_GPIO_LED_WLAN,
  81. .active_low = 1,
  82. },
  83. };
  84. static struct gpio_keys_button tl_wr841n_v9_gpio_keys[] __initdata = {
  85. {
  86. .desc = "Reset button",
  87. .type = EV_KEY,
  88. .code = KEY_RESTART,
  89. .debounce_interval = TL_WR841NV9_KEYS_DEBOUNCE_INTERVAL,
  90. .gpio = TL_WR841NV9_GPIO_BTN_RESET,
  91. .active_low = 1,
  92. }, {
  93. .desc = "WIFI button",
  94. .type = EV_KEY,
  95. .code = KEY_RFKILL,
  96. .debounce_interval = TL_WR841NV9_KEYS_DEBOUNCE_INTERVAL,
  97. .gpio = TL_WR841NV9_GPIO_BTN_WIFI,
  98. .active_low = 1,
  99. }
  100. };
  101. static struct gpio_led tl_wr841n_v11_leds_gpio[] __initdata = {
  102. {
  103. .name = "tp-link:green:lan1",
  104. .gpio = TL_WR841NV9_GPIO_LED_LAN1,
  105. .active_low = 1,
  106. }, {
  107. .name = "tp-link:green:lan2",
  108. .gpio = TL_WR841NV9_GPIO_LED_LAN2,
  109. .active_low = 1,
  110. }, {
  111. .name = "tp-link:green:lan3",
  112. .gpio = TL_WR841NV9_GPIO_LED_LAN3,
  113. .active_low = 1,
  114. }, {
  115. .name = "tp-link:green:lan4",
  116. .gpio = TL_WR841NV9_GPIO_LED_LAN4,
  117. .active_low = 1,
  118. }, {
  119. .name = "tp-link:green:qss",
  120. .gpio = TL_WR841NV9_GPIO_LED_QSS,
  121. .active_low = 1,
  122. }, {
  123. .name = "tp-link:green:system",
  124. .gpio = TL_WR841NV11_GPIO_LED_SYSTEM,
  125. .active_low = 1,
  126. }, {
  127. .name = "tp-link:green:wan",
  128. .gpio = TL_WR841NV9_GPIO_LED_WAN,
  129. .active_low = 1,
  130. }, {
  131. .name = "tp-link:green:wan_status",
  132. .gpio = TL_WR841NV11_GPIO_LED_WAN_STATUS,
  133. .active_low = 1,
  134. }, {
  135. .name = "tp-link:green:wlan",
  136. .gpio = TL_WR841NV9_GPIO_LED_WLAN,
  137. .active_low = 1,
  138. },
  139. };
  140. static void __init tl_ap143_setup(void)
  141. {
  142. u8 *mac = (u8 *) KSEG1ADDR(0x1f01fc00);
  143. u8 *ee = (u8 *) KSEG1ADDR(0x1fff1000);
  144. u8 tmpmac[ETH_ALEN];
  145. ath79_register_m25p80(&tl_wr841n_v9_flash_data);
  146. ath79_setup_ar933x_phy4_switch(false, false);
  147. ath79_register_mdio(0, 0x0);
  148. /* LAN */
  149. ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_GMII;
  150. ath79_eth1_data.duplex = DUPLEX_FULL;
  151. ath79_switch_data.phy_poll_mask |= BIT(4);
  152. ath79_init_mac(ath79_eth1_data.mac_addr, mac, 0);
  153. ath79_register_eth(1);
  154. /* WAN */
  155. ath79_switch_data.phy4_mii_en = 1;
  156. ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
  157. ath79_eth0_data.duplex = DUPLEX_FULL;
  158. ath79_eth0_data.speed = SPEED_100;
  159. ath79_eth0_data.phy_mask = BIT(4);
  160. ath79_init_mac(ath79_eth0_data.mac_addr, mac, 1);
  161. ath79_register_eth(0);
  162. ath79_init_mac(tmpmac, mac, 0);
  163. ath79_register_wmac(ee, tmpmac);
  164. }
  165. static void __init tl_wr841n_v9_setup(void)
  166. {
  167. tl_ap143_setup();
  168. ath79_register_leds_gpio(-1, ARRAY_SIZE(tl_wr841n_v9_leds_gpio),
  169. tl_wr841n_v9_leds_gpio);
  170. ath79_register_gpio_keys_polled(1, TL_WR841NV9_KEYS_POLL_INTERVAL,
  171. ARRAY_SIZE(tl_wr841n_v9_gpio_keys),
  172. tl_wr841n_v9_gpio_keys);
  173. }
  174. MIPS_MACHINE(ATH79_MACH_TL_WR841N_V9, "TL-WR841N-v9", "TP-LINK TL-WR841N/ND v9",
  175. tl_wr841n_v9_setup);
  176. static void __init tl_wr841n_v11_setup(void)
  177. {
  178. tl_ap143_setup();
  179. ath79_register_leds_gpio(-1, ARRAY_SIZE(tl_wr841n_v11_leds_gpio),
  180. tl_wr841n_v11_leds_gpio);
  181. ath79_register_gpio_keys_polled(1, TL_WR841NV9_KEYS_POLL_INTERVAL,
  182. ARRAY_SIZE(tl_wr841n_v9_gpio_keys),
  183. tl_wr841n_v9_gpio_keys);
  184. }
  185. MIPS_MACHINE(ATH79_MACH_TL_WR841N_V11, "TL-WR841N-v11", "TP-LINK TL-WR841N/ND v11",
  186. tl_wr841n_v11_setup);