mach-cpe510.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /*
  2. * TP-LINK CPE210/220/510/520 board support
  3. *
  4. * Copyright (C) 2014 Matthias Schiffer <mschiffer@universe-factory.net>
  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-wmac.h"
  20. #include "machtypes.h"
  21. #define CPE510_GPIO_LED_LAN0 11
  22. #define CPE510_GPIO_LED_LAN1 12
  23. #define CPE510_GPIO_LED_L1 13
  24. #define CPE510_GPIO_LED_L2 14
  25. #define CPE510_GPIO_LED_L3 15
  26. #define CPE510_GPIO_LED_L4 16
  27. /* All LEDs/button except for link4 are the same for CPE and WBS series */
  28. #define WBS510_GPIO_LED_L4 2
  29. #define CPE510_GPIO_EXTERNAL_LNA0 18
  30. #define CPE510_GPIO_EXTERNAL_LNA1 19
  31. #define CPE510_GPIO_BTN_RESET 4
  32. #define CPE510_KEYS_POLL_INTERVAL 20 /* msecs */
  33. #define CPE510_KEYS_DEBOUNCE_INTERVAL (3 * CPE510_KEYS_POLL_INTERVAL)
  34. static struct gpio_led cpe510_leds_gpio[] __initdata = {
  35. {
  36. .name = "tp-link:green:lan0",
  37. .gpio = CPE510_GPIO_LED_LAN0,
  38. .active_low = 1,
  39. }, {
  40. .name = "tp-link:green:lan1",
  41. .gpio = CPE510_GPIO_LED_LAN1,
  42. .active_low = 1,
  43. }, {
  44. .name = "tp-link:green:link1",
  45. .gpio = CPE510_GPIO_LED_L1,
  46. .active_low = 1,
  47. }, {
  48. .name = "tp-link:green:link2",
  49. .gpio = CPE510_GPIO_LED_L2,
  50. .active_low = 1,
  51. }, {
  52. .name = "tp-link:green:link3",
  53. .gpio = CPE510_GPIO_LED_L3,
  54. .active_low = 1,
  55. }, {
  56. .name = "tp-link:green:link4",
  57. .gpio = CPE510_GPIO_LED_L4,
  58. .active_low = 1,
  59. },
  60. };
  61. static struct gpio_led wbs510_leds_gpio[] __initdata = {
  62. {
  63. .name = "tp-link:green:lan0",
  64. .gpio = CPE510_GPIO_LED_LAN0,
  65. .active_low = 1,
  66. }, {
  67. .name = "tp-link:green:lan1",
  68. .gpio = CPE510_GPIO_LED_LAN1,
  69. .active_low = 1,
  70. }, {
  71. .name = "tp-link:green:link1",
  72. .gpio = CPE510_GPIO_LED_L1,
  73. .active_low = 1,
  74. }, {
  75. .name = "tp-link:green:link2",
  76. .gpio = CPE510_GPIO_LED_L2,
  77. .active_low = 1,
  78. }, {
  79. .name = "tp-link:green:link3",
  80. .gpio = CPE510_GPIO_LED_L3,
  81. .active_low = 1,
  82. }, {
  83. .name = "tp-link:green:link4",
  84. .gpio = WBS510_GPIO_LED_L4,
  85. .active_low = 1,
  86. },
  87. };
  88. static struct gpio_keys_button cpe510_gpio_keys[] __initdata = {
  89. {
  90. .desc = "Reset button",
  91. .type = EV_KEY,
  92. .code = KEY_RESTART,
  93. .debounce_interval = CPE510_KEYS_DEBOUNCE_INTERVAL,
  94. .gpio = CPE510_GPIO_BTN_RESET,
  95. .active_low = 1,
  96. }
  97. };
  98. static void __init cpe_setup(u8 *mac)
  99. {
  100. /* Disable JTAG, enabling GPIOs 0-3 */
  101. /* Configure OBS4 line, for GPIO 4*/
  102. ath79_gpio_function_setup(AR934X_GPIO_FUNC_JTAG_DISABLE,
  103. AR934X_GPIO_FUNC_CLK_OBS4_EN);
  104. ath79_register_gpio_keys_polled(1, CPE510_KEYS_POLL_INTERVAL,
  105. ARRAY_SIZE(cpe510_gpio_keys),
  106. cpe510_gpio_keys);
  107. ath79_wmac_set_ext_lna_gpio(0, CPE510_GPIO_EXTERNAL_LNA0);
  108. ath79_wmac_set_ext_lna_gpio(1, CPE510_GPIO_EXTERNAL_LNA1);
  109. ath79_register_m25p80(NULL);
  110. ath79_register_mdio(1, 0);
  111. ath79_init_mac(ath79_eth1_data.mac_addr, mac, 0);
  112. ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_GMII;
  113. ath79_register_eth(1);
  114. }
  115. static void __init cpe210_setup(void)
  116. {
  117. u8 *mac = (u8 *) KSEG1ADDR(0x1f830008);
  118. u8 *ee = (u8 *) KSEG1ADDR(0x1fff1000);
  119. ath79_register_leds_gpio(-1, ARRAY_SIZE(cpe510_leds_gpio),
  120. cpe510_leds_gpio);
  121. cpe_setup(mac);
  122. ath79_register_wmac(ee, mac);
  123. }
  124. static void __init cpe510_setup(void)
  125. {
  126. u8 *mac = (u8 *) KSEG1ADDR(0x1f830008);
  127. u8 *ee = (u8 *) KSEG1ADDR(0x1fff1000);
  128. ath79_register_leds_gpio(-1, ARRAY_SIZE(cpe510_leds_gpio),
  129. cpe510_leds_gpio);
  130. cpe_setup(mac);
  131. ath79_register_wmac(ee, mac);
  132. }
  133. static void __init wbs_setup(void)
  134. {
  135. u8 *mac = (u8 *) KSEG1ADDR(0x1f830008);
  136. u8 *ee = (u8 *) KSEG1ADDR(0x1fff1000);
  137. ath79_register_leds_gpio(-1, ARRAY_SIZE(wbs510_leds_gpio),
  138. wbs510_leds_gpio);
  139. cpe_setup(mac);
  140. ath79_register_wmac(ee, mac);
  141. }
  142. MIPS_MACHINE(ATH79_MACH_CPE210, "CPE210", "TP-LINK CPE210/220",
  143. cpe210_setup);
  144. MIPS_MACHINE(ATH79_MACH_CPE510, "CPE510", "TP-LINK CPE510/520",
  145. cpe510_setup);
  146. MIPS_MACHINE(ATH79_MACH_WBS210, "WBS210", "TP-LINK WBS210",
  147. wbs_setup);
  148. MIPS_MACHINE(ATH79_MACH_WBS510, "WBS510", "TP-LINK WBS510",
  149. wbs_setup);