1
0

mach-tl-wr841n-v8.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. /*
  2. * TP-LINK TL-WR841N/ND v8/TL-MR3420 v2 board support
  3. *
  4. * Copyright (C) 2012 Gabor Juhos <juhosg@openwrt.org>
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License version 2 as published
  8. * by the Free Software Foundation.
  9. */
  10. #include <linux/gpio.h>
  11. #include <linux/platform_device.h>
  12. #include <asm/mach-ath79/ath79.h>
  13. #include <asm/mach-ath79/ar71xx_regs.h>
  14. #include "common.h"
  15. #include "dev-eth.h"
  16. #include "dev-gpio-buttons.h"
  17. #include "dev-leds-gpio.h"
  18. #include "dev-m25p80.h"
  19. #include "dev-usb.h"
  20. #include "dev-wmac.h"
  21. #include "machtypes.h"
  22. #define TL_WR841NV8_GPIO_LED_WLAN 13
  23. #define TL_WR841NV8_GPIO_LED_QSS 15
  24. #define TL_WR841NV8_GPIO_LED_WAN 18
  25. #define TL_WR841NV8_GPIO_LED_LAN1 19
  26. #define TL_WR841NV8_GPIO_LED_LAN2 20
  27. #define TL_WR841NV8_GPIO_LED_LAN3 21
  28. #define TL_WR841NV8_GPIO_LED_LAN4 12
  29. #define TL_WR841NV8_GPIO_LED_SYSTEM 14
  30. #define TL_WR841NV8_GPIO_BTN_RESET 17
  31. #define TL_WR841NV8_GPIO_SW_RFKILL 16 /* WPS for MR3420 v2 */
  32. #define TL_MR3420V2_GPIO_LED_3G 11
  33. #define TL_MR3420V2_GPIO_USB_POWER 4
  34. #define TL_WR941NDV5_GPIO_LED_WLAN 13
  35. #define TL_WR941NDV5_GPIO_LED_QSS 15
  36. #define TL_WR941NDV5_GPIO_LED_WAN 18
  37. #define TL_WR941NDV5_GPIO_LED_LAN1 19
  38. #define TL_WR941NDV5_GPIO_LED_LAN2 20
  39. #define TL_WR941NDV5_GPIO_LED_LAN3 2
  40. #define TL_WR941NDV5_GPIO_LED_LAN4 3
  41. #define TL_WR941NDV5_GPIO_LED_SYSTEM 14
  42. #define TL_WR841NV8_KEYS_POLL_INTERVAL 20 /* msecs */
  43. #define TL_WR841NV8_KEYS_DEBOUNCE_INTERVAL (3 * TL_WR841NV8_KEYS_POLL_INTERVAL)
  44. static const char *tl_wr841n_v8_part_probes[] = {
  45. "tp-link",
  46. NULL,
  47. };
  48. static struct flash_platform_data tl_wr841n_v8_flash_data = {
  49. .part_probes = tl_wr841n_v8_part_probes,
  50. };
  51. static struct gpio_led tl_wr841n_v8_leds_gpio[] __initdata = {
  52. {
  53. .name = "tp-link:green:lan1",
  54. .gpio = TL_WR841NV8_GPIO_LED_LAN1,
  55. .active_low = 1,
  56. }, {
  57. .name = "tp-link:green:lan2",
  58. .gpio = TL_WR841NV8_GPIO_LED_LAN2,
  59. .active_low = 1,
  60. }, {
  61. .name = "tp-link:green:lan3",
  62. .gpio = TL_WR841NV8_GPIO_LED_LAN3,
  63. .active_low = 1,
  64. }, {
  65. .name = "tp-link:green:lan4",
  66. .gpio = TL_WR841NV8_GPIO_LED_LAN4,
  67. .active_low = 1,
  68. }, {
  69. .name = "tp-link:green:qss",
  70. .gpio = TL_WR841NV8_GPIO_LED_QSS,
  71. .active_low = 1,
  72. }, {
  73. .name = "tp-link:green:system",
  74. .gpio = TL_WR841NV8_GPIO_LED_SYSTEM,
  75. .active_low = 1,
  76. }, {
  77. .name = "tp-link:green:wan",
  78. .gpio = TL_WR841NV8_GPIO_LED_WAN,
  79. .active_low = 1,
  80. }, {
  81. .name = "tp-link:green:wlan",
  82. .gpio = TL_WR841NV8_GPIO_LED_WLAN,
  83. .active_low = 1,
  84. }, {
  85. /* the 3G LED is only present on the MR3420 v2 */
  86. .name = "tp-link:green:3g",
  87. .gpio = TL_MR3420V2_GPIO_LED_3G,
  88. .active_low = 1,
  89. },
  90. };
  91. static struct gpio_keys_button tl_wr841n_v8_gpio_keys[] __initdata = {
  92. {
  93. .desc = "Reset button",
  94. .type = EV_KEY,
  95. .code = KEY_RESTART,
  96. .debounce_interval = TL_WR841NV8_KEYS_DEBOUNCE_INTERVAL,
  97. .gpio = TL_WR841NV8_GPIO_BTN_RESET,
  98. .active_low = 1,
  99. }, {
  100. .desc = "RFKILL switch",
  101. .type = EV_SW,
  102. .code = KEY_RFKILL,
  103. .debounce_interval = TL_WR841NV8_KEYS_DEBOUNCE_INTERVAL,
  104. .gpio = TL_WR841NV8_GPIO_SW_RFKILL,
  105. .active_low = 0,
  106. }
  107. };
  108. static struct gpio_keys_button tl_mr3420v2_gpio_keys[] __initdata = {
  109. {
  110. .desc = "Reset button",
  111. .type = EV_KEY,
  112. .code = KEY_RESTART,
  113. .debounce_interval = TL_WR841NV8_KEYS_DEBOUNCE_INTERVAL,
  114. .gpio = TL_WR841NV8_GPIO_BTN_RESET,
  115. .active_low = 1,
  116. }, {
  117. .desc = "WPS",
  118. .type = EV_KEY,
  119. .code = KEY_WPS_BUTTON,
  120. .debounce_interval = TL_WR841NV8_KEYS_DEBOUNCE_INTERVAL,
  121. .gpio = TL_WR841NV8_GPIO_SW_RFKILL,
  122. .active_low = 0,
  123. }
  124. };
  125. static struct gpio_led tl_wr941nd_v5_leds_gpio[] __initdata = {
  126. {
  127. .name = "tp-link:green:lan1",
  128. .gpio = TL_WR941NDV5_GPIO_LED_LAN1,
  129. .active_low = 1,
  130. }, {
  131. .name = "tp-link:green:lan2",
  132. .gpio = TL_WR941NDV5_GPIO_LED_LAN2,
  133. .active_low = 1,
  134. }, {
  135. .name = "tp-link:green:lan3",
  136. .gpio = TL_WR941NDV5_GPIO_LED_LAN3,
  137. .active_low = 1,
  138. }, {
  139. .name = "tp-link:green:lan4",
  140. .gpio = TL_WR941NDV5_GPIO_LED_LAN4,
  141. .active_low = 1,
  142. }, {
  143. .name = "tp-link:green:qss",
  144. .gpio = TL_WR941NDV5_GPIO_LED_QSS,
  145. .active_low = 1,
  146. }, {
  147. .name = "tp-link:green:system",
  148. .gpio = TL_WR941NDV5_GPIO_LED_SYSTEM,
  149. .active_low = 1,
  150. }, {
  151. .name = "tp-link:green:wan",
  152. .gpio = TL_WR941NDV5_GPIO_LED_WAN,
  153. .active_low = 1,
  154. }, {
  155. .name = "tp-link:green:wlan",
  156. .gpio = TL_WR941NDV5_GPIO_LED_WLAN,
  157. .active_low = 1,
  158. },
  159. };
  160. static void __init tl_ap123_setup(void)
  161. {
  162. u8 *mac = (u8 *) KSEG1ADDR(0x1f01fc00);
  163. u8 *ee = (u8 *) KSEG1ADDR(0x1fff1000);
  164. /* Disable JTAG, enabling GPIOs 0-3 */
  165. /* Configure OBS4 line, for GPIO 4*/
  166. ath79_gpio_function_setup(AR934X_GPIO_FUNC_JTAG_DISABLE,
  167. AR934X_GPIO_FUNC_CLK_OBS4_EN);
  168. /* config gpio4 as normal gpio function */
  169. ath79_gpio_output_select(TL_MR3420V2_GPIO_USB_POWER,
  170. AR934X_GPIO_OUT_GPIO);
  171. ath79_register_m25p80(&tl_wr841n_v8_flash_data);
  172. ath79_setup_ar934x_eth_cfg(AR934X_ETH_CFG_SW_PHY_SWAP);
  173. ath79_register_mdio(1, 0x0);
  174. ath79_init_mac(ath79_eth0_data.mac_addr, mac, -1);
  175. ath79_init_mac(ath79_eth1_data.mac_addr, mac, 0);
  176. /* GMAC0 is connected to the PHY0 of the internal switch */
  177. ath79_switch_data.phy4_mii_en = 1;
  178. ath79_switch_data.phy_poll_mask = BIT(0);
  179. ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
  180. ath79_eth0_data.phy_mask = BIT(0);
  181. ath79_eth0_data.mii_bus_dev = &ath79_mdio1_device.dev;
  182. ath79_register_eth(0);
  183. /* GMAC1 is connected to the internal switch */
  184. ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_GMII;
  185. ath79_register_eth(1);
  186. ath79_register_wmac(ee, mac);
  187. }
  188. static void __init tl_wr841n_v8_setup(void)
  189. {
  190. tl_ap123_setup();
  191. ath79_register_leds_gpio(-1, ARRAY_SIZE(tl_wr841n_v8_leds_gpio) - 1,
  192. tl_wr841n_v8_leds_gpio);
  193. ath79_register_gpio_keys_polled(1, TL_WR841NV8_KEYS_POLL_INTERVAL,
  194. ARRAY_SIZE(tl_wr841n_v8_gpio_keys),
  195. tl_wr841n_v8_gpio_keys);
  196. }
  197. MIPS_MACHINE(ATH79_MACH_TL_WR841N_V8, "TL-WR841N-v8", "TP-LINK TL-WR841N/ND v8",
  198. tl_wr841n_v8_setup);
  199. static void __init tl_wr842n_v2_setup(void)
  200. {
  201. tl_ap123_setup();
  202. ath79_register_leds_gpio(-1, ARRAY_SIZE(tl_wr841n_v8_leds_gpio),
  203. tl_wr841n_v8_leds_gpio);
  204. ath79_register_gpio_keys_polled(1, TL_WR841NV8_KEYS_POLL_INTERVAL,
  205. ARRAY_SIZE(tl_wr841n_v8_gpio_keys),
  206. tl_wr841n_v8_gpio_keys);
  207. gpio_request_one(TL_MR3420V2_GPIO_USB_POWER,
  208. GPIOF_OUT_INIT_HIGH | GPIOF_EXPORT_DIR_FIXED,
  209. "USB power");
  210. ath79_register_usb();
  211. }
  212. MIPS_MACHINE(ATH79_MACH_TL_WR842N_V2, "TL-WR842N-v2", "TP-LINK TL-WR842N/ND v2",
  213. tl_wr842n_v2_setup);
  214. static void __init tl_mr3420v2_setup(void)
  215. {
  216. tl_ap123_setup();
  217. ath79_register_leds_gpio(-1, ARRAY_SIZE(tl_wr841n_v8_leds_gpio),
  218. tl_wr841n_v8_leds_gpio);
  219. ath79_register_gpio_keys_polled(1, TL_WR841NV8_KEYS_POLL_INTERVAL,
  220. ARRAY_SIZE(tl_mr3420v2_gpio_keys),
  221. tl_mr3420v2_gpio_keys);
  222. /* enable power for the USB port */
  223. gpio_request_one(TL_MR3420V2_GPIO_USB_POWER,
  224. GPIOF_OUT_INIT_HIGH | GPIOF_EXPORT_DIR_FIXED,
  225. "USB power");
  226. ath79_register_usb();
  227. }
  228. MIPS_MACHINE(ATH79_MACH_TL_MR3420_V2, "TL-MR3420-v2", "TP-LINK TL-MR3420 v2",
  229. tl_mr3420v2_setup);
  230. static void __init tl_wr941nd_v5_setup(void)
  231. {
  232. tl_ap123_setup();
  233. ath79_register_leds_gpio(-1, ARRAY_SIZE(tl_wr941nd_v5_leds_gpio),
  234. tl_wr941nd_v5_leds_gpio);
  235. ath79_register_gpio_keys_polled(1, TL_WR841NV8_KEYS_POLL_INTERVAL,
  236. ARRAY_SIZE(tl_wr841n_v8_gpio_keys),
  237. tl_wr841n_v8_gpio_keys);
  238. }
  239. MIPS_MACHINE(ATH79_MACH_TL_WR941ND_V5, "TL-WR941ND-v5", "TP-LINK TL-WR941N/ND v5",
  240. tl_wr941nd_v5_setup);