mach-ubnt.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /*
  2. * Ubiquiti RouterStation support
  3. *
  4. * Copyright (C) 2008-2012 Gabor Juhos <juhosg@openwrt.org>
  5. * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  6. * Copyright (C) 2008 Ubiquiti <support@ubnt.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 <asm/mach-ath79/ath79.h>
  13. #include "dev-eth.h"
  14. #include "dev-gpio-buttons.h"
  15. #include "dev-leds-gpio.h"
  16. #include "dev-m25p80.h"
  17. #include "dev-usb.h"
  18. #include "machtypes.h"
  19. #include "pci.h"
  20. #define UBNT_RS_GPIO_LED_RF 2
  21. #define UBNT_RS_GPIO_SW4 8
  22. #define UBNT_LS_SR71_GPIO_LED_D25 0
  23. #define UBNT_LS_SR71_GPIO_LED_D26 1
  24. #define UBNT_LS_SR71_GPIO_LED_D24 2
  25. #define UBNT_LS_SR71_GPIO_LED_D23 4
  26. #define UBNT_LS_SR71_GPIO_LED_D22 5
  27. #define UBNT_LS_SR71_GPIO_LED_D27 6
  28. #define UBNT_LS_SR71_GPIO_LED_D28 7
  29. #define UBNT_KEYS_POLL_INTERVAL 20 /* msecs */
  30. #define UBNT_KEYS_DEBOUNCE_INTERVAL (3 * UBNT_KEYS_POLL_INTERVAL)
  31. static struct gpio_led ubnt_rs_leds_gpio[] __initdata = {
  32. {
  33. .name = "ubnt:green:rf",
  34. .gpio = UBNT_RS_GPIO_LED_RF,
  35. .active_low = 0,
  36. }
  37. };
  38. static struct gpio_led ubnt_ls_sr71_leds_gpio[] __initdata = {
  39. {
  40. .name = "ubnt:green:d22",
  41. .gpio = UBNT_LS_SR71_GPIO_LED_D22,
  42. .active_low = 0,
  43. }, {
  44. .name = "ubnt:green:d23",
  45. .gpio = UBNT_LS_SR71_GPIO_LED_D23,
  46. .active_low = 0,
  47. }, {
  48. .name = "ubnt:green:d24",
  49. .gpio = UBNT_LS_SR71_GPIO_LED_D24,
  50. .active_low = 0,
  51. }, {
  52. .name = "ubnt:red:d25",
  53. .gpio = UBNT_LS_SR71_GPIO_LED_D25,
  54. .active_low = 0,
  55. }, {
  56. .name = "ubnt:red:d26",
  57. .gpio = UBNT_LS_SR71_GPIO_LED_D26,
  58. .active_low = 0,
  59. }, {
  60. .name = "ubnt:green:d27",
  61. .gpio = UBNT_LS_SR71_GPIO_LED_D27,
  62. .active_low = 0,
  63. }, {
  64. .name = "ubnt:green:d28",
  65. .gpio = UBNT_LS_SR71_GPIO_LED_D28,
  66. .active_low = 0,
  67. }
  68. };
  69. static struct gpio_keys_button ubnt_gpio_keys[] __initdata = {
  70. {
  71. .desc = "sw4",
  72. .type = EV_KEY,
  73. .code = KEY_RESTART,
  74. .debounce_interval = UBNT_KEYS_DEBOUNCE_INTERVAL,
  75. .gpio = UBNT_RS_GPIO_SW4,
  76. .active_low = 1,
  77. }
  78. };
  79. static const char *ubnt_part_probes[] = {
  80. "RedBoot",
  81. NULL,
  82. };
  83. static struct flash_platform_data ubnt_flash_data = {
  84. .part_probes = ubnt_part_probes,
  85. };
  86. static void __init ubnt_generic_setup(void)
  87. {
  88. ath79_register_m25p80(&ubnt_flash_data);
  89. ath79_register_gpio_keys_polled(-1, UBNT_KEYS_POLL_INTERVAL,
  90. ARRAY_SIZE(ubnt_gpio_keys),
  91. ubnt_gpio_keys);
  92. ath79_register_pci();
  93. }
  94. #define UBNT_RS_WAN_PHYMASK BIT(20)
  95. #define UBNT_RS_LAN_PHYMASK (BIT(16) | BIT(17) | BIT(18) | BIT(19))
  96. static void __init ubnt_rs_setup(void)
  97. {
  98. ubnt_generic_setup();
  99. ath79_register_mdio(0, ~(UBNT_RS_WAN_PHYMASK | UBNT_RS_LAN_PHYMASK));
  100. ath79_init_mac(ath79_eth0_data.mac_addr, ath79_mac_base, 0);
  101. ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
  102. ath79_eth0_data.phy_mask = UBNT_RS_WAN_PHYMASK;
  103. /*
  104. * There is Secondary MAC address duplicate problem with some
  105. * UBNT HW batches. Do not increase Secondary MAC address by 1
  106. * but do workaround with 'Locally Administrated' bit.
  107. */
  108. ath79_init_local_mac(ath79_eth1_data.mac_addr, ath79_mac_base);
  109. ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  110. ath79_eth1_data.speed = SPEED_100;
  111. ath79_eth1_data.duplex = DUPLEX_FULL;
  112. ath79_register_eth(0);
  113. ath79_register_eth(1);
  114. ath79_register_usb();
  115. ath79_register_leds_gpio(-1, ARRAY_SIZE(ubnt_rs_leds_gpio),
  116. ubnt_rs_leds_gpio);
  117. }
  118. MIPS_MACHINE(ATH79_MACH_UBNT_RS, "UBNT-RS", "Ubiquiti RouterStation",
  119. ubnt_rs_setup);
  120. #define UBNT_RSPRO_WAN_PHYMASK BIT(4)
  121. #define UBNT_RSPRO_LAN_PHYMASK (BIT(0) | BIT(1) | BIT(2) | BIT(3))
  122. static void __init ubnt_rspro_setup(void)
  123. {
  124. ubnt_generic_setup();
  125. ath79_register_mdio(0, ~(UBNT_RSPRO_WAN_PHYMASK |
  126. UBNT_RSPRO_LAN_PHYMASK));
  127. ath79_init_mac(ath79_eth0_data.mac_addr, ath79_mac_base, 0);
  128. ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  129. ath79_eth0_data.phy_mask = UBNT_RSPRO_WAN_PHYMASK;
  130. /*
  131. * There is Secondary MAC address duplicate problem with some
  132. * UBNT HW batches. Do not increase Secondary MAC address by 1
  133. * but do workaround with 'Locally Administrated' bit.
  134. */
  135. ath79_init_local_mac(ath79_eth1_data.mac_addr, ath79_mac_base);
  136. ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  137. ath79_eth1_data.phy_mask = UBNT_RSPRO_LAN_PHYMASK;
  138. ath79_eth1_data.speed = SPEED_1000;
  139. ath79_eth1_data.duplex = DUPLEX_FULL;
  140. ath79_register_eth(0);
  141. ath79_register_eth(1);
  142. ath79_register_usb();
  143. ath79_register_leds_gpio(-1, ARRAY_SIZE(ubnt_rs_leds_gpio),
  144. ubnt_rs_leds_gpio);
  145. }
  146. MIPS_MACHINE(ATH79_MACH_UBNT_RSPRO, "UBNT-RSPRO", "Ubiquiti RouterStation Pro",
  147. ubnt_rspro_setup);
  148. static void __init ubnt_lsx_setup(void)
  149. {
  150. ubnt_generic_setup();
  151. }
  152. MIPS_MACHINE(ATH79_MACH_UBNT_LSX, "UBNT-LSX", "Ubiquiti LSX", ubnt_lsx_setup);
  153. #define UBNT_LSSR71_PHY_MASK BIT(1)
  154. static void __init ubnt_lssr71_setup(void)
  155. {
  156. ubnt_generic_setup();
  157. ath79_register_mdio(0, ~UBNT_LSSR71_PHY_MASK);
  158. ath79_init_mac(ath79_eth0_data.mac_addr, ath79_mac_base, 0);
  159. ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
  160. ath79_eth0_data.phy_mask = UBNT_LSSR71_PHY_MASK;
  161. ath79_register_eth(0);
  162. ath79_register_leds_gpio(-1, ARRAY_SIZE(ubnt_ls_sr71_leds_gpio),
  163. ubnt_ls_sr71_leds_gpio);
  164. }
  165. MIPS_MACHINE(ATH79_MACH_UBNT_LSSR71, "UBNT-LS-SR71", "Ubiquiti LS-SR71",
  166. ubnt_lssr71_setup);