mach-cpe510.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. /*
  2. * TP-LINK CPE210/210 v2/220/510/520 board support
  3. *
  4. * Copyright (C) 2014 Matthias Schiffer <[email protected]>
  5. * Copyright (C) 2017 Robert Marko <[email protected]>
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License version 2 as published
  9. * by the Free Software Foundation.
  10. */
  11. #include <linux/gpio.h>
  12. #include <linux/platform_device.h>
  13. #include <asm/mach-ath79/ath79.h>
  14. #include <asm/mach-ath79/ar71xx_regs.h>
  15. #include "common.h"
  16. #include "dev-eth.h"
  17. #include "dev-gpio-buttons.h"
  18. #include "dev-leds-gpio.h"
  19. #include "dev-m25p80.h"
  20. #include "dev-wmac.h"
  21. #include "machtypes.h"
  22. #define CPE510_GPIO_LED_LAN0 11
  23. #define CPE510_GPIO_LED_LAN1 12
  24. #define CPE510_GPIO_LED_L1 13
  25. #define CPE510_GPIO_LED_L2 14
  26. #define CPE510_GPIO_LED_L3 15
  27. #define CPE510_GPIO_LED_L4 16
  28. /* All LEDs/button except for link4 are the same for CPE and WBS series */
  29. #define WBS510_GPIO_LED_L4 2
  30. #define CPE510_GPIO_EXTERNAL_LNA0 18
  31. #define CPE510_GPIO_EXTERNAL_LNA1 19
  32. #define CPE510_GPIO_BTN_RESET 4
  33. #define CPE510_KEYS_POLL_INTERVAL 20 /* msecs */
  34. #define CPE510_KEYS_DEBOUNCE_INTERVAL (3 * CPE510_KEYS_POLL_INTERVAL)
  35. /* CPE210 v2 reset GPIO */
  36. #define CPE210_V2_GPIO_BTN_RESET 17
  37. static struct gpio_led cpe510_leds_gpio[] __initdata = {
  38. {
  39. .name = "tp-link:green:lan0",
  40. .gpio = CPE510_GPIO_LED_LAN0,
  41. .active_low = 1,
  42. }, {
  43. .name = "tp-link:green:lan1",
  44. .gpio = CPE510_GPIO_LED_LAN1,
  45. .active_low = 1,
  46. }, {
  47. .name = "tp-link:green:link1",
  48. .gpio = CPE510_GPIO_LED_L1,
  49. .active_low = 1,
  50. }, {
  51. .name = "tp-link:green:link2",
  52. .gpio = CPE510_GPIO_LED_L2,
  53. .active_low = 1,
  54. }, {
  55. .name = "tp-link:green:link3",
  56. .gpio = CPE510_GPIO_LED_L3,
  57. .active_low = 1,
  58. }, {
  59. .name = "tp-link:green:link4",
  60. .gpio = CPE510_GPIO_LED_L4,
  61. .active_low = 1,
  62. },
  63. };
  64. static struct gpio_led wbs510_leds_gpio[] __initdata = {
  65. {
  66. .name = "tp-link:green:lan0",
  67. .gpio = CPE510_GPIO_LED_LAN0,
  68. .active_low = 1,
  69. }, {
  70. .name = "tp-link:green:lan1",
  71. .gpio = CPE510_GPIO_LED_LAN1,
  72. .active_low = 1,
  73. }, {
  74. .name = "tp-link:green:link1",
  75. .gpio = CPE510_GPIO_LED_L1,
  76. .active_low = 1,
  77. }, {
  78. .name = "tp-link:green:link2",
  79. .gpio = CPE510_GPIO_LED_L2,
  80. .active_low = 1,
  81. }, {
  82. .name = "tp-link:green:link3",
  83. .gpio = CPE510_GPIO_LED_L3,
  84. .active_low = 1,
  85. }, {
  86. .name = "tp-link:green:link4",
  87. .gpio = WBS510_GPIO_LED_L4,
  88. .active_low = 1,
  89. },
  90. };
  91. static struct gpio_led cpe210_v2_leds_gpio[] __initdata = {
  92. {
  93. .name = "tp-link:green:lan0",
  94. .gpio = CPE510_GPIO_LED_LAN0,
  95. .active_low = 1,
  96. }, {
  97. .name = "tp-link:green:link1",
  98. .gpio = CPE510_GPIO_LED_L1,
  99. .active_low = 1,
  100. }, {
  101. .name = "tp-link:green:link2",
  102. .gpio = CPE510_GPIO_LED_L2,
  103. .active_low = 1,
  104. }, {
  105. .name = "tp-link:green:link3",
  106. .gpio = CPE510_GPIO_LED_L3,
  107. .active_low = 1,
  108. }, {
  109. .name = "tp-link:green:link4",
  110. .gpio = CPE510_GPIO_LED_L4,
  111. .active_low = 1,
  112. },
  113. };
  114. static struct gpio_keys_button cpe510_gpio_keys[] __initdata = {
  115. {
  116. .desc = "Reset button",
  117. .type = EV_KEY,
  118. .code = KEY_RESTART,
  119. .debounce_interval = CPE510_KEYS_DEBOUNCE_INTERVAL,
  120. .gpio = CPE510_GPIO_BTN_RESET,
  121. .active_low = 1,
  122. }
  123. };
  124. static struct gpio_keys_button cpe210_v2_gpio_keys[] __initdata = {
  125. {
  126. .desc = "Reset button",
  127. .type = EV_KEY,
  128. .code = KEY_RESTART,
  129. .debounce_interval = CPE510_KEYS_DEBOUNCE_INTERVAL,
  130. .gpio = CPE210_V2_GPIO_BTN_RESET,
  131. .active_low = 1,
  132. }
  133. };
  134. static void __init cpe_setup(u8 *mac)
  135. {
  136. /* Disable JTAG, enabling GPIOs 0-3 */
  137. /* Configure OBS4 line, for GPIO 4*/
  138. ath79_gpio_function_setup(AR934X_GPIO_FUNC_JTAG_DISABLE,
  139. AR934X_GPIO_FUNC_CLK_OBS4_EN);
  140. ath79_register_gpio_keys_polled(1, CPE510_KEYS_POLL_INTERVAL,
  141. ARRAY_SIZE(cpe510_gpio_keys),
  142. cpe510_gpio_keys);
  143. ath79_wmac_set_ext_lna_gpio(0, CPE510_GPIO_EXTERNAL_LNA0);
  144. ath79_wmac_set_ext_lna_gpio(1, CPE510_GPIO_EXTERNAL_LNA1);
  145. ath79_register_m25p80(NULL);
  146. ath79_register_mdio(1, 0);
  147. ath79_init_mac(ath79_eth1_data.mac_addr, mac, 0);
  148. ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_GMII;
  149. ath79_register_eth(1);
  150. }
  151. static void __init cpe210_setup(void)
  152. {
  153. u8 *mac = (u8 *) KSEG1ADDR(0x1f830008);
  154. u8 *ee = (u8 *) KSEG1ADDR(0x1fff1000);
  155. ath79_register_leds_gpio(-1, ARRAY_SIZE(cpe510_leds_gpio),
  156. cpe510_leds_gpio);
  157. cpe_setup(mac);
  158. ath79_register_wmac(ee, mac);
  159. }
  160. static void __init cpe510_setup(void)
  161. {
  162. u8 *mac = (u8 *) KSEG1ADDR(0x1f830008);
  163. u8 *ee = (u8 *) KSEG1ADDR(0x1fff1000);
  164. ath79_register_leds_gpio(-1, ARRAY_SIZE(cpe510_leds_gpio),
  165. cpe510_leds_gpio);
  166. cpe_setup(mac);
  167. ath79_register_wmac(ee, mac);
  168. }
  169. static void __init wbs_setup(void)
  170. {
  171. u8 *mac = (u8 *) KSEG1ADDR(0x1f830008);
  172. u8 *ee = (u8 *) KSEG1ADDR(0x1fff1000);
  173. ath79_register_leds_gpio(-1, ARRAY_SIZE(wbs510_leds_gpio),
  174. wbs510_leds_gpio);
  175. cpe_setup(mac);
  176. ath79_register_wmac(ee, mac);
  177. }
  178. static void __init cpe210_v2_setup(void)
  179. {
  180. u8 *mac = (u8 *) KSEG1ADDR(0x1f830008);
  181. u8 *ee = (u8 *) KSEG1ADDR(0x1fff1000);
  182. ath79_register_leds_gpio(-1, ARRAY_SIZE(cpe210_v2_leds_gpio),
  183. cpe210_v2_leds_gpio);
  184. ath79_register_gpio_keys_polled(-1, CPE510_KEYS_POLL_INTERVAL,
  185. ARRAY_SIZE(cpe210_v2_gpio_keys),
  186. cpe210_v2_gpio_keys);
  187. ath79_register_m25p80(NULL);
  188. ath79_register_mdio(0, 0x0);
  189. ath79_init_mac(ath79_eth0_data.mac_addr, mac, 0);
  190. ath79_eth0_data.duplex = DUPLEX_FULL;
  191. ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
  192. ath79_eth0_data.speed = SPEED_100;
  193. ath79_eth0_data.phy_mask = BIT(4);
  194. ath79_register_eth(0);
  195. ath79_register_wmac(ee, mac);
  196. }
  197. MIPS_MACHINE(ATH79_MACH_CPE210, "CPE210", "TP-LINK CPE210/220",
  198. cpe210_setup);
  199. MIPS_MACHINE(ATH79_MACH_CPE210_V2, "CPE210V2", "TP-LINK CPE210 v2",
  200. cpe210_v2_setup);
  201. MIPS_MACHINE(ATH79_MACH_CPE510, "CPE510", "TP-LINK CPE510/520",
  202. cpe510_setup);
  203. MIPS_MACHINE(ATH79_MACH_WBS210, "WBS210", "TP-LINK WBS210",
  204. wbs_setup);
  205. MIPS_MACHINE(ATH79_MACH_WBS510, "WBS510", "TP-LINK WBS510",
  206. wbs_setup);