mach-epg5000.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /*
  2. * EnGenius EPG5000 board support
  3. *
  4. * Copyright (c) 2014 Jon Suphammer <jon@suphammer.net>
  5. * Copyright (c) 2015 Christian Beier <cb@shoutrlabs.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License version 2 as published
  9. * by the Free Software Foundation.
  10. */
  11. #include <linux/platform_device.h>
  12. #include <linux/ar8216_platform.h>
  13. #include <asm/mach-ath79/ar71xx_regs.h>
  14. #include "common.h"
  15. #include "pci.h"
  16. #include "dev-ap9x-pci.h"
  17. #include "dev-gpio-buttons.h"
  18. #include "dev-eth.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. #include "nvram.h"
  25. #define EPG5000_GPIO_LED_WLAN_5G 23
  26. #define EPG5000_GPIO_LED_WLAN_2G 13
  27. #define EPG5000_GPIO_LED_POWER_AMBER 2
  28. #define EPG5000_GPIO_LED_WPS_AMBER 22
  29. #define EPG5000_GPIO_LED_WPS_BLUE 19
  30. #define EPG5000_GPIO_BTN_WPS 16
  31. #define EPG5000_GPIO_BTN_RESET 17
  32. #define EPG5000_KEYS_POLL_INTERVAL 20 /* msecs */
  33. #define EPG5000_KEYS_DEBOUNCE_INTERVAL (3 * EPG5000_KEYS_POLL_INTERVAL)
  34. #define EPG5000_CALDATA_ADDR 0x1fff0000
  35. #define EPG5000_WMAC_CALDATA_OFFSET 0x1000
  36. #define EPG5000_PCIE_CALDATA_OFFSET 0x5000
  37. #define EPG5000_NVRAM_ADDR 0x1f030000
  38. #define EPG5000_NVRAM_SIZE 0x10000
  39. static struct gpio_led epg5000_leds_gpio[] __initdata = {
  40. {
  41. .name = "epg5000:amber:power",
  42. .gpio = EPG5000_GPIO_LED_POWER_AMBER,
  43. .active_low = 1,
  44. },
  45. {
  46. .name = "epg5000:blue:wps",
  47. .gpio = EPG5000_GPIO_LED_WPS_BLUE,
  48. .active_low = 1,
  49. },
  50. {
  51. .name = "epg5000:amber:wps",
  52. .gpio = EPG5000_GPIO_LED_WPS_AMBER,
  53. .active_low = 1,
  54. },
  55. {
  56. .name = "epg5000:blue:wlan-2g",
  57. .gpio = EPG5000_GPIO_LED_WLAN_2G,
  58. .active_low = 1,
  59. },
  60. {
  61. .name = "epg5000:blue:wlan-5g",
  62. .gpio = EPG5000_GPIO_LED_WLAN_5G,
  63. .active_low = 1,
  64. }
  65. };
  66. static struct gpio_keys_button epg5000_gpio_keys[] __initdata = {
  67. {
  68. .desc = "WPS button",
  69. .type = EV_KEY,
  70. .code = KEY_WPS_BUTTON,
  71. .debounce_interval = EPG5000_KEYS_DEBOUNCE_INTERVAL,
  72. .gpio = EPG5000_GPIO_BTN_WPS,
  73. .active_low = 1,
  74. },
  75. {
  76. .desc = "Reset button",
  77. .type = EV_KEY,
  78. .code = KEY_RESTART,
  79. .debounce_interval = EPG5000_KEYS_DEBOUNCE_INTERVAL,
  80. .gpio = EPG5000_GPIO_BTN_RESET,
  81. .active_low = 1,
  82. },
  83. };
  84. static struct ar8327_pad_cfg epg5000_ar8327_pad0_cfg = {
  85. .mode = AR8327_PAD_MAC_RGMII,
  86. .txclk_delay_en = true,
  87. .rxclk_delay_en = true,
  88. .txclk_delay_sel = AR8327_CLK_DELAY_SEL2,
  89. .rxclk_delay_sel = AR8327_CLK_DELAY_SEL2,
  90. };
  91. static struct ar8327_platform_data epg5000_ar8327_data = {
  92. .pad0_cfg = &epg5000_ar8327_pad0_cfg,
  93. .port0_cfg = {
  94. .force_link = 1,
  95. .speed = AR8327_PORT_SPEED_1000,
  96. .duplex = 1,
  97. .txpause = 1,
  98. .rxpause = 1,
  99. },
  100. };
  101. static struct mdio_board_info epg5000_mdio0_info[] = {
  102. {
  103. .bus_id = "ag71xx-mdio.0",
  104. .phy_addr = 0,
  105. .platform_data = &epg5000_ar8327_data,
  106. },
  107. };
  108. static int epg5000_get_mac(const char *name, char *mac)
  109. {
  110. u8 *nvram = (u8 *) KSEG1ADDR(EPG5000_NVRAM_ADDR);
  111. int err;
  112. err = ath79_nvram_parse_mac_addr(nvram, EPG5000_NVRAM_SIZE,
  113. name, mac);
  114. if (err) {
  115. pr_err("no MAC address found for %s\n", name);
  116. return false;
  117. }
  118. return true;
  119. }
  120. static void __init epg5000_setup(void)
  121. {
  122. u8 *caldata = (u8 *) KSEG1ADDR(EPG5000_CALDATA_ADDR);
  123. u8 mac1[ETH_ALEN];
  124. ath79_register_m25p80(NULL);
  125. ath79_register_leds_gpio(-1, ARRAY_SIZE(epg5000_leds_gpio),
  126. epg5000_leds_gpio);
  127. ath79_register_gpio_keys_polled(-1, EPG5000_KEYS_POLL_INTERVAL,
  128. ARRAY_SIZE(epg5000_gpio_keys),
  129. epg5000_gpio_keys);
  130. ath79_register_usb();
  131. ath79_setup_qca955x_eth_cfg(QCA955X_ETH_CFG_RGMII_EN);
  132. ath79_register_mdio(0, 0x0);
  133. mdiobus_register_board_info(epg5000_mdio0_info,
  134. ARRAY_SIZE(epg5000_mdio0_info));
  135. /* GMAC0 is connected to an QCA8327N switch */
  136. ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  137. ath79_eth0_data.phy_mask = BIT(0);
  138. ath79_eth0_data.mii_bus_dev = &ath79_mdio0_device.dev;
  139. if (epg5000_get_mac("ethaddr=", mac1))
  140. ath79_init_mac(ath79_eth0_data.mac_addr, mac1, 0);
  141. ath79_eth0_pll_data.pll_1000 = 0xa6000000;
  142. ath79_register_eth(0);
  143. ath79_register_wmac(caldata + EPG5000_WMAC_CALDATA_OFFSET, mac1);
  144. ath79_register_pci();
  145. }
  146. MIPS_MACHINE(ATH79_MACH_EPG5000, "EPG5000",
  147. "EnGenius EPG5000",
  148. epg5000_setup);