mach-alfa-ap120c.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. * ALFA Network AP120C board support
  3. *
  4. * Copyright (C) 2012 Gabor Juhos <juhosg@openwrt.org>
  5. * Copyright (C) 2016 Luka Perkov <luka@openwrt.org>
  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/init.h>
  12. #include <linux/bitops.h>
  13. #include <linux/gpio.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/spi/spi.h>
  16. #include <linux/ar8216_platform.h>
  17. #include <linux/ath9k_platform.h>
  18. #include <asm/mach-ath79/ath79.h>
  19. #include <asm/mach-ath79/ar71xx_regs.h>
  20. #include "common.h"
  21. #include "dev-eth.h"
  22. #include "dev-gpio-buttons.h"
  23. #include "dev-leds-gpio.h"
  24. #include "dev-m25p80.h"
  25. #include "dev-spi.h"
  26. #include "dev-ap9x-pci.h"
  27. #include "dev-wmac.h"
  28. #include "machtypes.h"
  29. #define ALFA_AP120C_GPIO_LED 0
  30. #define ALFA_AP120C_GPIO_BUTTON_WIFI 16
  31. #define ALFA_AP120C_GPIO_WATCH_DOG 20
  32. #define ALFA_AP120C_KEYS_POLL_INTERVAL 20 /* msecs */
  33. #define ALFA_AP120C_KEYS_DEBOUNCE_INTERVAL (3 * ALFA_AP120C_KEYS_POLL_INTERVAL)
  34. #define ALFA_AP120C_MAC_OFFSET 0x1002
  35. #define ALFA_AP120C_CAL0_OFFSET 0x1000
  36. static struct gpio_keys_button alfa_ap120c_gpio_keys[] __initdata = {
  37. {
  38. .desc = "Wireless button",
  39. .type = EV_KEY,
  40. .code = KEY_RFKILL,
  41. .debounce_interval = ALFA_AP120C_KEYS_DEBOUNCE_INTERVAL,
  42. .gpio = ALFA_AP120C_GPIO_BUTTON_WIFI,
  43. .active_low = 1,
  44. }
  45. };
  46. static struct gpio_led alfa_ap120c_leds_gpio[] __initdata = {
  47. {
  48. .name = "ap120c:red:wlan",
  49. .gpio = ALFA_AP120C_GPIO_LED,
  50. .active_low = 0,
  51. }
  52. };
  53. static struct ar8327_pad_cfg ap120c_ar8327_pad0_cfg = {
  54. .mode = AR8327_PAD_MAC_RGMII,
  55. .txclk_delay_en = true,
  56. .rxclk_delay_en = true,
  57. .txclk_delay_sel = AR8327_CLK_DELAY_SEL1,
  58. .rxclk_delay_sel = AR8327_CLK_DELAY_SEL2,
  59. };
  60. static struct ar8327_platform_data ap120c_ar8327_data = {
  61. .pad0_cfg = &ap120c_ar8327_pad0_cfg,
  62. .port0_cfg = {
  63. .force_link = 1,
  64. .speed = AR8327_PORT_SPEED_1000,
  65. .duplex = 1,
  66. .txpause = 1,
  67. .rxpause = 1,
  68. },
  69. };
  70. static struct mdio_board_info ap120c_mdio0_info[] = {
  71. {
  72. .bus_id = "ag71xx-mdio.0",
  73. .phy_addr = 0,
  74. .platform_data = &ap120c_ar8327_data,
  75. },
  76. };
  77. static struct flash_platform_data flash __initdata = { NULL, NULL, 0 };
  78. #define ALFA_AP120C_LAN_PHYMASK BIT(5)
  79. #define ALFA_AP120C_MDIO_PHYMASK ALFA_AP120C_LAN_PHYMASK
  80. static void __init alfa_ap120c_init(void)
  81. {
  82. u8 *art = (u8 *) KSEG1ADDR(0x1fff0000);
  83. u8 mac[ETH_ALEN];
  84. struct ath9k_platform_data *pdata;
  85. ath79_register_leds_gpio(-1, ARRAY_SIZE(alfa_ap120c_leds_gpio),
  86. alfa_ap120c_leds_gpio);
  87. ath79_register_gpio_keys_polled(-1, ALFA_AP120C_KEYS_POLL_INTERVAL,
  88. ARRAY_SIZE(alfa_ap120c_gpio_keys),
  89. alfa_ap120c_gpio_keys);
  90. ath79_gpio_function_enable(AR71XX_GPIO_FUNC_SPI_CS1_EN |
  91. AR71XX_GPIO_FUNC_SPI_CS2_EN);
  92. ath79_register_m25p80_multi(&flash);
  93. ath79_init_mac(mac, art + ALFA_AP120C_MAC_OFFSET, 1);
  94. ath79_register_wmac(art + ALFA_AP120C_CAL0_OFFSET, mac);
  95. ath79_init_mac(mac, art + ALFA_AP120C_MAC_OFFSET, 2);
  96. ap91_pci_init(NULL, mac);
  97. pdata = ap9x_pci_get_wmac_data(0);
  98. if (!pdata) {
  99. pr_err("ap120c: unable to get address of wlan data\n");
  100. return;
  101. }
  102. pdata->use_eeprom = true;
  103. ath79_setup_ar934x_eth_cfg(AR934X_ETH_CFG_RGMII_GMAC0 |
  104. BIT(15) | BIT(17) | BIT(19) | BIT(21));
  105. ath79_register_mdio(0, 0x0);
  106. ath79_init_mac(ath79_eth0_data.mac_addr, art + ALFA_AP120C_MAC_OFFSET, 0);
  107. mdiobus_register_board_info(ap120c_mdio0_info, ARRAY_SIZE(ap120c_mdio0_info));
  108. ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  109. ath79_eth0_data.phy_mask = ALFA_AP120C_LAN_PHYMASK;
  110. ath79_eth0_pll_data.pll_1000 = 0x42000000;
  111. ath79_eth0_pll_data.pll_10 = 0x00001313;
  112. ath79_eth0_data.mii_bus_dev = &ath79_mdio0_device.dev;
  113. ath79_register_eth(0);
  114. }
  115. MIPS_MACHINE(ATH79_MACH_ALFA_AP120C, "ALFA-AP120C", "ALFA Network AP120C",
  116. alfa_ap120c_init);