1
0

mach-zbt-we1526.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*
  2. * Zbtlink ZBT-WE1526 board support
  3. *
  4. * Copyright (C) 2016 Piotr Dymacz <pepe2k@gmail.com>
  5. *
  6. * Based on mach-dr531.c and mach-tl-wr841n-v9.c
  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. #define ZBT_WE1526_GPIO_LED_STATUS 13
  25. #define ZBT_WE1526_GPIO_LED_LAN1 16
  26. #define ZBT_WE1526_GPIO_LED_LAN2 15
  27. #define ZBT_WE1526_GPIO_LED_LAN3 14
  28. #define ZBT_WE1526_GPIO_LED_LAN4 11
  29. #define ZBT_WE1526_GPIO_LED_WAN 4
  30. #define ZBT_WE1526_GPIO_LED_WLAN 12
  31. #define ZBT_WE1526_GPIO_BTN_RESET 17
  32. #define ZBT_WE1526_KEYS_POLL_INTERVAL 20 /* msecs */
  33. #define ZBT_WE1526_KEYS_DEBOUNCE_INTERVAL \
  34. (3 * ZBT_WE1526_KEYS_POLL_INTERVAL)
  35. #define ZBT_WE1526_MAC0_OFFSET 0x0
  36. #define ZBT_WE1526_MAC1_OFFSET 0x6
  37. #define ZBT_WE1526_WMAC_CALDATA_OFFSET 0x1000
  38. static struct gpio_led zbt_we1526_leds_gpio[] __initdata = {
  39. {
  40. .name = "zbt-we1526:green:status",
  41. .gpio = ZBT_WE1526_GPIO_LED_STATUS,
  42. .active_low = 1,
  43. },
  44. {
  45. .name = "zbt-we1526:green:lan1",
  46. .gpio = ZBT_WE1526_GPIO_LED_LAN1,
  47. .active_low = 1,
  48. },
  49. {
  50. .name = "zbt-we1526:green:lan2",
  51. .gpio = ZBT_WE1526_GPIO_LED_LAN2,
  52. .active_low = 1,
  53. },
  54. {
  55. .name = "zbt-we1526:green:lan3",
  56. .gpio = ZBT_WE1526_GPIO_LED_LAN3,
  57. .active_low = 1,
  58. },
  59. {
  60. .name = "zbt-we1526:green:lan4",
  61. .gpio = ZBT_WE1526_GPIO_LED_LAN4,
  62. .active_low = 1,
  63. },
  64. {
  65. .name = "zbt-we1526:green:wan",
  66. .gpio = ZBT_WE1526_GPIO_LED_WAN,
  67. .active_low = 1,
  68. },
  69. {
  70. .name = "zbt-we1526:green:wlan",
  71. .gpio = ZBT_WE1526_GPIO_LED_WLAN,
  72. .active_low = 1,
  73. },
  74. };
  75. static struct gpio_keys_button zbt_we1526_gpio_keys[] __initdata = {
  76. {
  77. .desc = "reset",
  78. .type = EV_KEY,
  79. .code = KEY_RESTART,
  80. .debounce_interval = ZBT_WE1526_KEYS_DEBOUNCE_INTERVAL,
  81. .gpio = ZBT_WE1526_GPIO_BTN_RESET,
  82. .active_low = 1,
  83. },
  84. };
  85. static void __init zbt_we1526_gpio_setup(void)
  86. {
  87. /* For LED on GPIO4 */
  88. ath79_gpio_function_disable(AR934X_GPIO_FUNC_CLK_OBS4_EN);
  89. ath79_gpio_output_select(ZBT_WE1526_GPIO_LED_WAN, 0);
  90. ath79_gpio_direction_select(ZBT_WE1526_GPIO_LED_STATUS, true);
  91. ath79_gpio_direction_select(ZBT_WE1526_GPIO_LED_LAN1, true);
  92. ath79_gpio_direction_select(ZBT_WE1526_GPIO_LED_LAN2, true);
  93. ath79_gpio_direction_select(ZBT_WE1526_GPIO_LED_LAN3, true);
  94. ath79_gpio_direction_select(ZBT_WE1526_GPIO_LED_LAN4, true);
  95. ath79_gpio_direction_select(ZBT_WE1526_GPIO_LED_WAN, true);
  96. ath79_gpio_direction_select(ZBT_WE1526_GPIO_LED_WLAN, true);
  97. ath79_register_leds_gpio(-1, ARRAY_SIZE(zbt_we1526_leds_gpio),
  98. zbt_we1526_leds_gpio);
  99. ath79_register_gpio_keys_polled(-1, ZBT_WE1526_KEYS_POLL_INTERVAL,
  100. ARRAY_SIZE(zbt_we1526_gpio_keys),
  101. zbt_we1526_gpio_keys);
  102. }
  103. static void __init zbt_we1526_setup(void)
  104. {
  105. u8 *art = (u8 *) KSEG1ADDR(0x1fff0000);
  106. ath79_register_m25p80(NULL);
  107. zbt_we1526_gpio_setup();
  108. ath79_setup_ar933x_phy4_switch(false, false);
  109. ath79_register_mdio(0, 0x0);
  110. /* LAN */
  111. ath79_eth1_data.duplex = DUPLEX_FULL;
  112. ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_GMII;
  113. ath79_switch_data.phy_poll_mask |= BIT(4);
  114. ath79_init_mac(ath79_eth1_data.mac_addr,
  115. art + ZBT_WE1526_MAC0_OFFSET, 0);
  116. ath79_register_eth(1);
  117. /* WAN */
  118. ath79_switch_data.phy4_mii_en = 1;
  119. ath79_eth0_data.duplex = DUPLEX_FULL;
  120. ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
  121. ath79_eth0_data.phy_mask = BIT(4);
  122. ath79_eth0_data.speed = SPEED_100;
  123. ath79_init_mac(ath79_eth0_data.mac_addr,
  124. art + ZBT_WE1526_MAC1_OFFSET, 0);
  125. ath79_register_eth(0);
  126. ath79_register_wmac(art + ZBT_WE1526_WMAC_CALDATA_OFFSET, NULL);
  127. ath79_register_usb();
  128. }
  129. MIPS_MACHINE(ATH79_MACH_ZBT_WE1526, "ZBT-WE1526", "Zbtlink ZBT-WE1526",
  130. zbt_we1526_setup);