mach-ap132.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /*
  2. * Atheros AP132 reference board support
  3. *
  4. * Copyright (c) 2012 Qualcomm Atheros
  5. * Copyright (c) 2012 Gabor Juhos <juhosg@openwrt.org>
  6. * Copyright (c) 2013 Embedded Wireless GmbH <info@embeddedwireless.de>
  7. *
  8. * Permission to use, copy, modify, and/or distribute this software for any
  9. * purpose with or without fee is hereby granted, provided that the above
  10. * copyright notice and this permission notice appear in all copies.
  11. *
  12. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  13. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  14. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  15. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  16. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  17. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  18. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  19. *
  20. */
  21. #include <linux/platform_device.h>
  22. #include <linux/ar8216_platform.h>
  23. #include <asm/mach-ath79/ar71xx_regs.h>
  24. #include "common.h"
  25. #include "dev-ap9x-pci.h"
  26. #include "dev-gpio-buttons.h"
  27. #include "dev-eth.h"
  28. #include "dev-leds-gpio.h"
  29. #include "dev-m25p80.h"
  30. #include "dev-usb.h"
  31. #include "dev-wmac.h"
  32. #include "machtypes.h"
  33. #define AP132_GPIO_LED_USB 4
  34. #define AP132_GPIO_LED_WLAN_5G 12
  35. #define AP132_GPIO_LED_WLAN_2G 13
  36. #define AP132_GPIO_LED_STATUS_RED 14
  37. #define AP132_GPIO_LED_WPS_RED 15
  38. #define AP132_GPIO_BTN_WPS 16
  39. #define AP132_KEYS_POLL_INTERVAL 20 /* msecs */
  40. #define AP132_KEYS_DEBOUNCE_INTERVAL (3 * AP132_KEYS_POLL_INTERVAL)
  41. #define AP132_MAC0_OFFSET 0
  42. #define AP132_WMAC_CALDATA_OFFSET 0x1000
  43. static struct gpio_led ap132_leds_gpio[] __initdata = {
  44. {
  45. .name = "ap132:red:status",
  46. .gpio = AP132_GPIO_LED_STATUS_RED,
  47. .active_low = 1,
  48. },
  49. {
  50. .name = "ap132:red:wps",
  51. .gpio = AP132_GPIO_LED_WPS_RED,
  52. .active_low = 1,
  53. },
  54. {
  55. .name = "ap132:red:wlan-2g",
  56. .gpio = AP132_GPIO_LED_WLAN_2G,
  57. .active_low = 1,
  58. },
  59. {
  60. .name = "ap132:red:usb",
  61. .gpio = AP132_GPIO_LED_USB,
  62. .active_low = 1,
  63. }
  64. };
  65. static struct gpio_keys_button ap132_gpio_keys[] __initdata = {
  66. {
  67. .desc = "WPS button",
  68. .type = EV_KEY,
  69. .code = KEY_WPS_BUTTON,
  70. .debounce_interval = AP132_KEYS_DEBOUNCE_INTERVAL,
  71. .gpio = AP132_GPIO_BTN_WPS,
  72. .active_low = 1,
  73. },
  74. };
  75. static struct ar8327_pad_cfg ap132_ar8327_pad0_cfg;
  76. static struct ar8327_platform_data ap132_ar8327_data = {
  77. .pad0_cfg = &ap132_ar8327_pad0_cfg,
  78. .port0_cfg = {
  79. .force_link = 1,
  80. .speed = AR8327_PORT_SPEED_1000,
  81. .duplex = 1,
  82. .txpause = 1,
  83. .rxpause = 1,
  84. },
  85. };
  86. static struct mdio_board_info ap132_mdio1_info[] = {
  87. {
  88. .bus_id = "ag71xx-mdio.1",
  89. .phy_addr = 0,
  90. .platform_data = &ap132_ar8327_data,
  91. },
  92. };
  93. static void __init ap132_mdio_setup(void)
  94. {
  95. void __iomem *base;
  96. u32 t;
  97. #define GPIO_IN_ENABLE3_ADDRESS 0x0050
  98. #define GPIO_IN_ENABLE3_MII_GE1_MDI_MASK 0x00ff0000
  99. #define GPIO_IN_ENABLE3_MII_GE1_MDI_LSB 16
  100. #define GPIO_IN_ENABLE3_MII_GE1_MDI_SET(x) (((x) << GPIO_IN_ENABLE3_MII_GE1_MDI_LSB) & GPIO_IN_ENABLE3_MII_GE1_MDI_MASK)
  101. #define GPIO_OUT_FUNCTION4_ADDRESS 0x003c
  102. #define GPIO_OUT_FUNCTION4_ENABLE_GPIO_19_MASK 0xff000000
  103. #define GPIO_OUT_FUNCTION4_ENABLE_GPIO_19_LSB 24
  104. #define GPIO_OUT_FUNCTION4_ENABLE_GPIO_19_SET(x) (((x) << GPIO_OUT_FUNCTION4_ENABLE_GPIO_19_LSB) & GPIO_OUT_FUNCTION4_ENABLE_GPIO_19_MASK)
  105. #define GPIO_OUT_FUNCTION4_ENABLE_GPIO_17_MASK 0x0000ff00
  106. #define GPIO_OUT_FUNCTION4_ENABLE_GPIO_17_LSB 8
  107. #define GPIO_OUT_FUNCTION4_ENABLE_GPIO_17_SET(x) (((x) << GPIO_OUT_FUNCTION4_ENABLE_GPIO_17_LSB) & GPIO_OUT_FUNCTION4_ENABLE_GPIO_17_MASK)
  108. base = ioremap(AR71XX_GPIO_BASE, AR71XX_GPIO_SIZE);
  109. t = __raw_readl(base + GPIO_IN_ENABLE3_ADDRESS);
  110. t &= ~GPIO_IN_ENABLE3_MII_GE1_MDI_MASK;
  111. t |= GPIO_IN_ENABLE3_MII_GE1_MDI_SET(19);
  112. __raw_writel(t, base + GPIO_IN_ENABLE3_ADDRESS);
  113. __raw_writel(__raw_readl(base + AR71XX_GPIO_REG_OE) & ~(1 << 19), base + AR71XX_GPIO_REG_OE);
  114. __raw_writel(__raw_readl(base + AR71XX_GPIO_REG_OE) & ~(1 << 17), base + AR71XX_GPIO_REG_OE);
  115. t = __raw_readl(base + GPIO_OUT_FUNCTION4_ADDRESS);
  116. t &= ~(GPIO_OUT_FUNCTION4_ENABLE_GPIO_19_MASK | GPIO_OUT_FUNCTION4_ENABLE_GPIO_17_MASK);
  117. t |= GPIO_OUT_FUNCTION4_ENABLE_GPIO_19_SET(0x20) | GPIO_OUT_FUNCTION4_ENABLE_GPIO_17_SET(0x21);
  118. __raw_writel(t, base + GPIO_OUT_FUNCTION4_ADDRESS);
  119. iounmap(base);
  120. }
  121. static void __init ap132_setup(void)
  122. {
  123. u8 *art = (u8 *) KSEG1ADDR(0x1fff0000);
  124. ath79_register_m25p80(NULL);
  125. ath79_register_leds_gpio(-1, ARRAY_SIZE(ap132_leds_gpio),
  126. ap132_leds_gpio);
  127. ath79_register_gpio_keys_polled(-1, AP132_KEYS_POLL_INTERVAL,
  128. ARRAY_SIZE(ap132_gpio_keys),
  129. ap132_gpio_keys);
  130. ath79_register_usb();
  131. ath79_register_wmac(art + AP132_WMAC_CALDATA_OFFSET, NULL);
  132. /* GMAC0 of the AR8327 switch is connected to GMAC1 via SGMII */
  133. ap132_ar8327_pad0_cfg.mode = AR8327_PAD_MAC_SGMII;
  134. ap132_ar8327_pad0_cfg.sgmii_delay_en = true;
  135. ath79_eth1_pll_data.pll_1000 = 0x03000101;
  136. ap132_mdio_setup();
  137. ath79_register_mdio(1, 0x0);
  138. ath79_init_mac(ath79_eth1_data.mac_addr, art + AP132_MAC0_OFFSET, 0);
  139. mdiobus_register_board_info(ap132_mdio1_info,
  140. ARRAY_SIZE(ap132_mdio1_info));
  141. /* GMAC1 is connected to the SGMII interface */
  142. ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_SGMII;
  143. ath79_eth1_data.speed = SPEED_1000;
  144. ath79_eth1_data.duplex = DUPLEX_FULL;
  145. ath79_eth1_data.phy_mask = BIT(0);
  146. ath79_eth1_data.mii_bus_dev = &ath79_mdio1_device.dev;
  147. ath79_register_eth(1);
  148. }
  149. MIPS_MACHINE(ATH79_MACH_AP132, "AP132",
  150. "Atheros AP132 reference board",
  151. ap132_setup);