mach-esr1750.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /*
  2. * EnGenius ESR1750 board support
  3. *
  4. * Copyright (c) 2014 Jon Suphammer <jon@suphammer.net>
  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/platform_device.h>
  11. #include <linux/ar8216_platform.h>
  12. #include <asm/mach-ath79/ar71xx_regs.h>
  13. #include "common.h"
  14. #include "pci.h"
  15. #include "dev-ap9x-pci.h"
  16. #include "dev-gpio-buttons.h"
  17. #include "dev-eth.h"
  18. #include "dev-leds-gpio.h"
  19. #include "dev-m25p80.h"
  20. #include "dev-usb.h"
  21. #include "dev-wmac.h"
  22. #include "machtypes.h"
  23. #include "nvram.h"
  24. #define ESR1750_GPIO_LED_WLAN_5G 23
  25. #define ESR1750_GPIO_LED_WLAN_2G 13
  26. #define ESR1750_GPIO_LED_POWER_AMBER 2
  27. #define ESR1750_GPIO_LED_WPS_AMBER 22
  28. #define ESR1750_GPIO_LED_WPS_BLUE 19
  29. #define ESR1750_GPIO_BTN_WPS 16
  30. #define ESR1750_GPIO_BTN_RESET 17
  31. #define ESR1750_KEYS_POLL_INTERVAL 20 /* msecs */
  32. #define ESR1750_KEYS_DEBOUNCE_INTERVAL (3 * ESR1750_KEYS_POLL_INTERVAL)
  33. #define ESR1750_CALDATA_ADDR 0x1fff0000
  34. #define ESR1750_WMAC_CALDATA_OFFSET 0x1000
  35. #define ESR1750_PCIE_CALDATA_OFFSET 0x5000
  36. #define ESR1750_NVRAM_ADDR 0x1f030000
  37. #define ESR1750_NVRAM_SIZE 0x10000
  38. static struct gpio_led esr1750_leds_gpio[] __initdata = {
  39. {
  40. .name = "esr1750:amber:power",
  41. .gpio = ESR1750_GPIO_LED_POWER_AMBER,
  42. .active_low = 1,
  43. },
  44. {
  45. .name = "esr1750:blue:wps",
  46. .gpio = ESR1750_GPIO_LED_WPS_BLUE,
  47. .active_low = 1,
  48. },
  49. {
  50. .name = "esr1750:amber:wps",
  51. .gpio = ESR1750_GPIO_LED_WPS_AMBER,
  52. .active_low = 1,
  53. },
  54. {
  55. .name = "esr1750:blue:wlan-2g",
  56. .gpio = ESR1750_GPIO_LED_WLAN_2G,
  57. .active_low = 1,
  58. },
  59. {
  60. .name = "esr1750:blue:wlan-5g",
  61. .gpio = ESR1750_GPIO_LED_WLAN_5G,
  62. .active_low = 1,
  63. }
  64. };
  65. static struct gpio_keys_button esr1750_gpio_keys[] __initdata = {
  66. {
  67. .desc = "WPS button",
  68. .type = EV_KEY,
  69. .code = KEY_WPS_BUTTON,
  70. .debounce_interval = ESR1750_KEYS_DEBOUNCE_INTERVAL,
  71. .gpio = ESR1750_GPIO_BTN_WPS,
  72. .active_low = 1,
  73. },
  74. {
  75. .desc = "Reset button",
  76. .type = EV_KEY,
  77. .code = KEY_RESTART,
  78. .debounce_interval = ESR1750_KEYS_DEBOUNCE_INTERVAL,
  79. .gpio = ESR1750_GPIO_BTN_RESET,
  80. .active_low = 1,
  81. },
  82. };
  83. static struct ar8327_pad_cfg esr1750_ar8327_pad0_cfg = {
  84. .mode = AR8327_PAD_MAC_RGMII,
  85. .txclk_delay_en = true,
  86. .rxclk_delay_en = true,
  87. .txclk_delay_sel = AR8327_CLK_DELAY_SEL2,
  88. .rxclk_delay_sel = AR8327_CLK_DELAY_SEL2,
  89. };
  90. static struct ar8327_platform_data esr1750_ar8327_data = {
  91. .pad0_cfg = &esr1750_ar8327_pad0_cfg,
  92. .port0_cfg = {
  93. .force_link = 1,
  94. .speed = AR8327_PORT_SPEED_1000,
  95. .duplex = 1,
  96. .txpause = 1,
  97. .rxpause = 1,
  98. },
  99. };
  100. static struct mdio_board_info esr1750_mdio0_info[] = {
  101. {
  102. .bus_id = "ag71xx-mdio.0",
  103. .phy_addr = 0,
  104. .platform_data = &esr1750_ar8327_data,
  105. },
  106. };
  107. static int esr1750_get_mac(const char *name, char *mac)
  108. {
  109. u8 *nvram = (u8 *) KSEG1ADDR(ESR1750_NVRAM_ADDR);
  110. int err;
  111. err = ath79_nvram_parse_mac_addr(nvram, ESR1750_NVRAM_SIZE,
  112. name, mac);
  113. if (err) {
  114. pr_err("no MAC address found for %s\n", name);
  115. return false;
  116. }
  117. return true;
  118. }
  119. static void __init esr1750_setup(void)
  120. {
  121. u8 *caldata = (u8 *) KSEG1ADDR(ESR1750_CALDATA_ADDR);
  122. u8 mac1[ETH_ALEN];
  123. ath79_register_m25p80(NULL);
  124. ath79_register_leds_gpio(-1, ARRAY_SIZE(esr1750_leds_gpio),
  125. esr1750_leds_gpio);
  126. ath79_register_gpio_keys_polled(-1, ESR1750_KEYS_POLL_INTERVAL,
  127. ARRAY_SIZE(esr1750_gpio_keys),
  128. esr1750_gpio_keys);
  129. ath79_register_usb();
  130. ath79_setup_qca955x_eth_cfg(QCA955X_ETH_CFG_RGMII_EN);
  131. ath79_register_mdio(0, 0x0);
  132. mdiobus_register_board_info(esr1750_mdio0_info,
  133. ARRAY_SIZE(esr1750_mdio0_info));
  134. /* GMAC0 is connected to an QCA8327N switch */
  135. ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  136. ath79_eth0_data.phy_mask = BIT(0);
  137. ath79_eth0_data.mii_bus_dev = &ath79_mdio0_device.dev;
  138. if (esr1750_get_mac("ethaddr=", mac1))
  139. ath79_init_mac(ath79_eth0_data.mac_addr, mac1, 0);
  140. ath79_eth0_pll_data.pll_1000 = 0xa6000000;
  141. ath79_register_eth(0);
  142. ath79_register_wmac(caldata + ESR1750_WMAC_CALDATA_OFFSET, mac1);
  143. ath79_register_pci();
  144. }
  145. MIPS_MACHINE(ATH79_MACH_ESR1750, "ESR1750",
  146. "EnGenius ESR1750",
  147. esr1750_setup);