mach-dir-869-a1.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /*
  2. * D-Link DIR-869 A1 support
  3. *
  4. * Copyright (C) 2015-2016 P. Wassi <p.wassi at gmx.at>
  5. * Copyright (C) 2016 Matthias Schiffer <mschiffer@universe-factory.net>
  6. *
  7. * Derived from: mach-ubnt-unifiac.c
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License version 2 as published
  11. * by the Free Software Foundation.
  12. */
  13. #include <linux/gpio.h>
  14. #include <linux/init.h>
  15. #include <linux/pci.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/ath9k_platform.h>
  18. #include <asm/mach-ath79/ath79.h>
  19. #include <asm/mach-ath79/irq.h>
  20. #include <asm/mach-ath79/ar71xx_regs.h>
  21. #include <linux/platform_data/phy-at803x.h>
  22. #include <linux/ar8216_platform.h>
  23. #include "common.h"
  24. #include "dev-ap9x-pci.h"
  25. #include "dev-eth.h"
  26. #include "dev-gpio-buttons.h"
  27. #include "dev-leds-gpio.h"
  28. #include "dev-m25p80.h"
  29. #include "dev-wmac.h"
  30. #include "machtypes.h"
  31. #include "nvram.h"
  32. #define DIR869A1_GPIO_BTN_RESET 1
  33. #define DIR869A1_GPIO_BTN_WPS 2
  34. #define DIR869A1_GPIO_SWITCH_MODE 8
  35. #define DIR869A1_GPIO_ENABLE_SWITCH 11
  36. #define DIR869A1_GPIO_LED_POWER 15
  37. #define DIR869A1_GPIO_LED_ORANGE 16
  38. #define DIR869A1_KEYS_POLL_INTERVAL 20 /* msecs */
  39. #define DIR869A1_KEYS_DEBOUNCE_INTERVAL (3 * DIR869A1_KEYS_POLL_INTERVAL)
  40. #define DIR869A1_DEVDATA_ADDR 0x1f050000
  41. #define DIR869A1_DEVDATA_SIZE 0x10000
  42. #define DIR869A1_EEPROM_ADDR 0x1fff0000
  43. #define DIR869A1_WMAC_CALDATA_OFFSET 0x1000
  44. #define DIR869A1_PCI_CALDATA_OFFSET 0x5000
  45. static struct gpio_led dir869a1_leds_gpio[] __initdata = {
  46. {
  47. /* Actually, this GPIO controls the LED power,
  48. * while d-link:orange:status switches it between
  49. * orange and white */
  50. .name = "d-link:white:status",
  51. .gpio = DIR869A1_GPIO_LED_POWER,
  52. .active_low = 1,
  53. },
  54. {
  55. .name = "d-link:orange:status",
  56. .gpio = DIR869A1_GPIO_LED_ORANGE,
  57. .active_low = 0,
  58. },
  59. };
  60. static struct gpio_keys_button dir869a1_gpio_keys[] __initdata = {
  61. {
  62. .desc = "reset",
  63. .type = EV_KEY,
  64. .code = KEY_RESTART,
  65. .debounce_interval = DIR869A1_KEYS_DEBOUNCE_INTERVAL,
  66. .gpio = DIR869A1_GPIO_BTN_RESET,
  67. .active_low = 1,
  68. },
  69. {
  70. .desc = "wps",
  71. .type = EV_KEY,
  72. .code = KEY_WPS_BUTTON,
  73. .debounce_interval = DIR869A1_KEYS_DEBOUNCE_INTERVAL,
  74. .gpio = DIR869A1_GPIO_BTN_WPS,
  75. .active_low = 1,
  76. },
  77. {
  78. .desc = "mode",
  79. .type = EV_SW,
  80. .code = BTN_0,
  81. .debounce_interval = DIR869A1_KEYS_DEBOUNCE_INTERVAL,
  82. .gpio = DIR869A1_GPIO_SWITCH_MODE,
  83. .active_low = 0,
  84. },
  85. };
  86. static struct ar8327_pad_cfg dir869a1_ar8327_pad0_cfg = {
  87. .mode = AR8327_PAD_MAC_SGMII,
  88. .sgmii_delay_en = true,
  89. };
  90. static struct ar8327_platform_data dir869a1_ar8327_data = {
  91. .pad0_cfg = &dir869a1_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 dir869a1_mdio0_info[] = {
  101. {
  102. .bus_id = "ag71xx-mdio.0",
  103. .phy_addr = 0,
  104. .platform_data = &dir869a1_ar8327_data,
  105. },
  106. };
  107. static void dir869a1_get_mac(const char *name, char *mac)
  108. {
  109. u8 *nvram = (u8 *) KSEG1ADDR(DIR869A1_DEVDATA_ADDR);
  110. int err;
  111. err = ath79_nvram_parse_mac_addr(nvram, DIR869A1_DEVDATA_SIZE,
  112. name, mac);
  113. if (err)
  114. pr_err("no MAC address found for %s\n", name);
  115. }
  116. static void __init dir869a1_setup(void)
  117. {
  118. u8 *eeprom = (u8 *) KSEG1ADDR(DIR869A1_EEPROM_ADDR);
  119. u8 wlan24mac[ETH_ALEN] = {}, wlan5mac[ETH_ALEN] = {};
  120. ath79_register_m25p80(NULL);
  121. gpio_request_one(DIR869A1_GPIO_ENABLE_SWITCH,
  122. GPIOF_OUT_INIT_HIGH | GPIOF_EXPORT_DIR_FIXED,
  123. "Switch power");
  124. dir869a1_get_mac("lanmac=", ath79_eth0_data.mac_addr);
  125. ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_SGMII;
  126. ath79_eth0_data.mii_bus_dev = &ath79_mdio0_device.dev;
  127. ath79_eth0_data.phy_mask = BIT(0);
  128. mdiobus_register_board_info(dir869a1_mdio0_info,
  129. ARRAY_SIZE(dir869a1_mdio0_info));
  130. ath79_register_mdio(0, 0);
  131. ath79_register_eth(0);
  132. dir869a1_get_mac("wlan24mac=", wlan24mac);
  133. ath79_register_wmac(eeprom + DIR869A1_WMAC_CALDATA_OFFSET, wlan24mac);
  134. dir869a1_get_mac("wlan5mac=", wlan5mac);
  135. ap91_pci_init(eeprom + DIR869A1_PCI_CALDATA_OFFSET, wlan5mac);
  136. ath79_register_leds_gpio(-1, ARRAY_SIZE(dir869a1_leds_gpio),
  137. dir869a1_leds_gpio);
  138. ath79_register_gpio_keys_polled(-1, DIR869A1_KEYS_POLL_INTERVAL,
  139. ARRAY_SIZE(dir869a1_gpio_keys),
  140. dir869a1_gpio_keys);
  141. }
  142. MIPS_MACHINE(ATH79_MACH_DIR_869_A1, "DIR-869-A1", "D-Link DIR-869 rev. A1",
  143. dir869a1_setup);