mach-cpe870.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /*
  2. * YunCore CPE870 board support
  3. *
  4. * Copyright (C) 2016 Piotr Dymacz <pepe2k@gmail.com>
  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 CPE870_GPIO_LED_LINK1 0
  23. #define CPE870_GPIO_LED_LINK2 1
  24. #define CPE870_GPIO_LED_LINK3 2
  25. #define CPE870_GPIO_LED_LINK4 3
  26. #define CPE870_GPIO_LED_WLAN 13
  27. #define CPE870_GPIO_LED_WAN 19
  28. #define CPE870_GPIO_LED_LAN 20
  29. #define CPE870_GPIO_BTN_RESET 16
  30. #define CPE870_KEYS_POLL_INTERVAL 20
  31. #define CPE870_KEYS_DEBOUNCE_INTERVAL (3 * CPE870_KEYS_POLL_INTERVAL)
  32. static struct gpio_led cpe870_leds_gpio[] __initdata = {
  33. {
  34. .name = "cpe870:green:lan",
  35. .gpio = CPE870_GPIO_LED_LAN,
  36. .active_low = 1,
  37. },
  38. {
  39. .name = "cpe870:green:wan",
  40. .gpio = CPE870_GPIO_LED_WAN,
  41. .active_low = 1,
  42. },
  43. {
  44. .name = "cpe870:green:wlan",
  45. .gpio = CPE870_GPIO_LED_WLAN,
  46. .active_low = 1,
  47. },
  48. {
  49. .name = "cpe870:green:link1",
  50. .gpio = CPE870_GPIO_LED_LINK1,
  51. .active_low = 1,
  52. },
  53. {
  54. .name = "cpe870:green:link2",
  55. .gpio = CPE870_GPIO_LED_LINK2,
  56. .active_low = 1,
  57. },
  58. {
  59. .name = "cpe870:green:link3",
  60. .gpio = CPE870_GPIO_LED_LINK3,
  61. .active_low = 1,
  62. },
  63. {
  64. .name = "cpe870:green:link4",
  65. .gpio = CPE870_GPIO_LED_LINK4,
  66. .active_low = 1,
  67. },
  68. };
  69. static struct gpio_keys_button cpe870_gpio_keys[] __initdata = {
  70. {
  71. .desc = "reset",
  72. .type = EV_KEY,
  73. .code = KEY_RESTART,
  74. .debounce_interval = CPE870_KEYS_DEBOUNCE_INTERVAL,
  75. .gpio = CPE870_GPIO_BTN_RESET,
  76. .active_low = 1,
  77. },
  78. };
  79. static void __init cpe870_gpio_setup(void)
  80. {
  81. /* Disable JTAG (enables GPIO0-3) */
  82. ath79_gpio_function_enable(AR934X_GPIO_FUNC_JTAG_DISABLE);
  83. ath79_gpio_direction_select(CPE870_GPIO_LED_LINK1, true);
  84. ath79_gpio_direction_select(CPE870_GPIO_LED_LINK2, true);
  85. ath79_gpio_direction_select(CPE870_GPIO_LED_LINK3, true);
  86. ath79_gpio_direction_select(CPE870_GPIO_LED_LINK4, true);
  87. /* Mute LEDs on boot */
  88. gpio_set_value(CPE870_GPIO_LED_LAN, 1);
  89. gpio_set_value(CPE870_GPIO_LED_WAN, 1);
  90. gpio_set_value(CPE870_GPIO_LED_LINK1, 1);
  91. gpio_set_value(CPE870_GPIO_LED_LINK2, 1);
  92. gpio_set_value(CPE870_GPIO_LED_LINK3, 1);
  93. gpio_set_value(CPE870_GPIO_LED_LINK4, 1);
  94. ath79_gpio_output_select(CPE870_GPIO_LED_LINK1, 0);
  95. ath79_gpio_output_select(CPE870_GPIO_LED_LINK2, 0);
  96. ath79_gpio_output_select(CPE870_GPIO_LED_LINK3, 0);
  97. ath79_gpio_output_select(CPE870_GPIO_LED_LINK4, 0);
  98. ath79_register_leds_gpio(-1, ARRAY_SIZE(cpe870_leds_gpio),
  99. cpe870_leds_gpio);
  100. ath79_register_gpio_keys_polled(-1, CPE870_KEYS_POLL_INTERVAL,
  101. ARRAY_SIZE(cpe870_gpio_keys),
  102. cpe870_gpio_keys);
  103. }
  104. static void __init cpe870_setup(void)
  105. {
  106. u8 *art = (u8 *) KSEG1ADDR(0x1fff1000);
  107. u8 *mac = (u8 *) KSEG1ADDR(0x1fff0000);
  108. ath79_register_m25p80(NULL);
  109. cpe870_gpio_setup();
  110. ath79_register_mdio(1, 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_eth0_data.mii_bus_dev = &ath79_mdio1_device.dev;
  125. ath79_init_mac(ath79_eth0_data.mac_addr, mac, 0);
  126. ath79_register_eth(0);
  127. ath79_register_wmac(art, NULL);
  128. }
  129. MIPS_MACHINE(ATH79_MACH_CPE870, "CPE870", "YunCore CPE870", cpe870_setup);