mach-ap90q.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /*
  2. * Support for YunCore boards:
  3. * - AP90Q
  4. * - CPE830
  5. *
  6. * Copyright (C) 2016 Piotr Dymacz <pepe2k@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. /* AP90Q */
  25. #define AP90Q_GPIO_LED_WAN 4
  26. #define AP90Q_GPIO_LED_WLAN 12
  27. #define AP90Q_GPIO_LED_LAN 16
  28. #define AP90Q_GPIO_BTN_RESET 17
  29. #define AP90Q_KEYS_POLL_INTERVAL 20
  30. #define AP90Q_KEYS_DEBOUNCE_INTERVAL (3 * AP90Q_KEYS_POLL_INTERVAL)
  31. static struct gpio_led ap90q_leds_gpio[] __initdata = {
  32. {
  33. .name = "ap90q:green:lan",
  34. .gpio = AP90Q_GPIO_LED_LAN,
  35. .active_low = 1,
  36. },
  37. {
  38. .name = "ap90q:green:wan",
  39. .gpio = AP90Q_GPIO_LED_WAN,
  40. .active_low = 1,
  41. },
  42. {
  43. .name = "ap90q:green:wlan",
  44. .gpio = AP90Q_GPIO_LED_WLAN,
  45. .active_low = 1,
  46. },
  47. };
  48. static struct gpio_keys_button ap90q_gpio_keys[] __initdata = {
  49. {
  50. .desc = "reset",
  51. .type = EV_KEY,
  52. .code = KEY_RESTART,
  53. .debounce_interval = AP90Q_KEYS_DEBOUNCE_INTERVAL,
  54. .gpio = AP90Q_GPIO_BTN_RESET,
  55. .active_low = 1,
  56. },
  57. };
  58. /* CPE830 */
  59. #define CPE830_GPIO_LED_LINK4 0
  60. #define CPE830_GPIO_LED_LINK1 1
  61. #define CPE830_GPIO_LED_LINK2 2
  62. #define CPE830_GPIO_LED_LINK3 3
  63. #define CPE830_GPIO_LED_WAN 4
  64. #define CPE830_GPIO_LED_WLAN 12
  65. #define CPE830_GPIO_LED_LAN 16
  66. #define CPE830_GPIO_BTN_RESET 17
  67. static struct gpio_led cpe830_leds_gpio[] __initdata = {
  68. {
  69. .name = "cpe830:green:lan",
  70. .gpio = CPE830_GPIO_LED_LAN,
  71. .active_low = 1,
  72. },
  73. {
  74. .name = "cpe830:green:wan",
  75. .gpio = CPE830_GPIO_LED_WAN,
  76. .active_low = 1,
  77. },
  78. {
  79. .name = "cpe830:green:wlan",
  80. .gpio = CPE830_GPIO_LED_WLAN,
  81. .active_low = 1,
  82. },
  83. {
  84. .name = "cpe830:green:link1",
  85. .gpio = CPE830_GPIO_LED_LINK1,
  86. .active_low = 1,
  87. },
  88. {
  89. .name = "cpe830:green:link2",
  90. .gpio = CPE830_GPIO_LED_LINK2,
  91. .active_low = 1,
  92. },
  93. {
  94. .name = "cpe830:green:link3",
  95. .gpio = CPE830_GPIO_LED_LINK3,
  96. .active_low = 1,
  97. },
  98. {
  99. .name = "cpe830:green:link4",
  100. .gpio = CPE830_GPIO_LED_LINK4,
  101. .active_low = 1,
  102. },
  103. };
  104. static void __init ap90q_cpe830_common_setup(void)
  105. {
  106. u8 *art = (u8 *) KSEG1ADDR(0x1fff1000);
  107. u8 *mac = (u8 *) KSEG1ADDR(0x1fff0000);
  108. ath79_register_m25p80(NULL);
  109. ath79_setup_ar933x_phy4_switch(false, false);
  110. ath79_register_mdio(0, 0x0);
  111. ath79_switch_data.phy4_mii_en = 1;
  112. ath79_switch_data.phy_poll_mask |= BIT(4);
  113. /* LAN */
  114. ath79_eth1_data.duplex = DUPLEX_FULL;
  115. ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_GMII;
  116. ath79_eth1_data.speed = SPEED_1000;
  117. ath79_init_mac(ath79_eth1_data.mac_addr, mac, 1);
  118. ath79_register_eth(1);
  119. /* WAN */
  120. ath79_eth0_data.duplex = DUPLEX_FULL;
  121. ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
  122. ath79_eth0_data.speed = SPEED_100;
  123. ath79_eth0_data.phy_mask = BIT(4);
  124. ath79_init_mac(ath79_eth0_data.mac_addr, mac, 0);
  125. ath79_register_eth(0);
  126. ath79_register_wmac(art, NULL);
  127. /* For LED on GPIO4 */
  128. ath79_gpio_function_disable(AR934X_GPIO_FUNC_CLK_OBS4_EN);
  129. ath79_gpio_direction_select(AP90Q_GPIO_LED_LAN, true);
  130. ath79_gpio_direction_select(AP90Q_GPIO_LED_WAN, true);
  131. ath79_gpio_direction_select(AP90Q_GPIO_LED_WLAN, true);
  132. /* Mute LEDs on boot */
  133. gpio_set_value(AP90Q_GPIO_LED_LAN, 1);
  134. gpio_set_value(AP90Q_GPIO_LED_WAN, 1);
  135. ath79_gpio_output_select(AP90Q_GPIO_LED_LAN, 0);
  136. ath79_gpio_output_select(AP90Q_GPIO_LED_WAN, 0);
  137. ath79_gpio_output_select(AP90Q_GPIO_LED_WLAN, 0);
  138. ath79_register_gpio_keys_polled(-1, AP90Q_KEYS_POLL_INTERVAL,
  139. ARRAY_SIZE(ap90q_gpio_keys),
  140. ap90q_gpio_keys);
  141. }
  142. static void __init ap90q_setup(void)
  143. {
  144. ap90q_cpe830_common_setup();
  145. ath79_register_leds_gpio(-1, ARRAY_SIZE(ap90q_leds_gpio),
  146. ap90q_leds_gpio);
  147. }
  148. MIPS_MACHINE(ATH79_MACH_AP90Q, "AP90Q", "YunCore AP90Q", ap90q_setup);
  149. static void __init cpe830_setup(void)
  150. {
  151. ap90q_cpe830_common_setup();
  152. ath79_gpio_direction_select(CPE830_GPIO_LED_LINK1, true);
  153. ath79_gpio_direction_select(CPE830_GPIO_LED_LINK2, true);
  154. ath79_gpio_direction_select(CPE830_GPIO_LED_LINK3, true);
  155. ath79_gpio_direction_select(CPE830_GPIO_LED_LINK4, true);
  156. /* Mute LEDs on boot */
  157. gpio_set_value(CPE830_GPIO_LED_LINK1, 1);
  158. gpio_set_value(CPE830_GPIO_LED_LINK2, 1);
  159. gpio_set_value(CPE830_GPIO_LED_LINK3, 1);
  160. gpio_set_value(CPE830_GPIO_LED_LINK4, 1);
  161. ath79_gpio_output_select(CPE830_GPIO_LED_LINK1, 0);
  162. ath79_gpio_output_select(CPE830_GPIO_LED_LINK2, 0);
  163. ath79_gpio_output_select(CPE830_GPIO_LED_LINK3, 0);
  164. ath79_gpio_output_select(CPE830_GPIO_LED_LINK4, 0);
  165. ath79_register_leds_gpio(-1, ARRAY_SIZE(cpe830_leds_gpio),
  166. cpe830_leds_gpio);
  167. }
  168. MIPS_MACHINE(ATH79_MACH_CPE830, "CPE830", "YunCore CPE830", cpe830_setup);