mach-dir-869-a1.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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_ORANGE 15
  37. #define DIR869A1_GPIO_LED_WHITE 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. .name = "d-link:white:status",
  48. .gpio = DIR869A1_GPIO_LED_WHITE,
  49. .active_low = 1,
  50. },
  51. {
  52. .name = "d-link:orange:status",
  53. .gpio = DIR869A1_GPIO_LED_ORANGE,
  54. .active_low = 1,
  55. },
  56. };
  57. static struct gpio_keys_button dir869a1_gpio_keys[] __initdata = {
  58. {
  59. .desc = "reset",
  60. .type = EV_KEY,
  61. .code = KEY_RESTART,
  62. .debounce_interval = DIR869A1_KEYS_DEBOUNCE_INTERVAL,
  63. .gpio = DIR869A1_GPIO_BTN_RESET,
  64. .active_low = 1,
  65. },
  66. {
  67. .desc = "wps",
  68. .type = EV_KEY,
  69. .code = KEY_WPS_BUTTON,
  70. .debounce_interval = DIR869A1_KEYS_DEBOUNCE_INTERVAL,
  71. .gpio = DIR869A1_GPIO_BTN_WPS,
  72. .active_low = 1,
  73. },
  74. {
  75. .desc = "mode",
  76. .type = EV_SW,
  77. .code = BTN_0,
  78. .debounce_interval = DIR869A1_KEYS_DEBOUNCE_INTERVAL,
  79. .gpio = DIR869A1_GPIO_SWITCH_MODE,
  80. .active_low = 0,
  81. },
  82. };
  83. static struct ar8327_pad_cfg dir869a1_ar8327_pad0_cfg = {
  84. .mode = AR8327_PAD_MAC_SGMII,
  85. .sgmii_delay_en = true,
  86. };
  87. static struct ar8327_platform_data dir869a1_ar8327_data = {
  88. .pad0_cfg = &dir869a1_ar8327_pad0_cfg,
  89. .port0_cfg = {
  90. .force_link = 1,
  91. .speed = AR8327_PORT_SPEED_1000,
  92. .duplex = 1,
  93. .txpause = 1,
  94. .rxpause = 1,
  95. },
  96. };
  97. static struct mdio_board_info dir869a1_mdio0_info[] = {
  98. {
  99. .bus_id = "ag71xx-mdio.0",
  100. .phy_addr = 0,
  101. .platform_data = &dir869a1_ar8327_data,
  102. },
  103. };
  104. static void dir869a1_get_mac(const char *name, char *mac)
  105. {
  106. u8 *nvram = (u8 *) KSEG1ADDR(DIR869A1_DEVDATA_ADDR);
  107. int err;
  108. err = ath79_nvram_parse_mac_addr(nvram, DIR869A1_DEVDATA_SIZE,
  109. name, mac);
  110. if (err)
  111. pr_err("no MAC address found for %s\n", name);
  112. }
  113. static void __init dir869a1_setup(void)
  114. {
  115. u8 *eeprom = (u8 *) KSEG1ADDR(DIR869A1_EEPROM_ADDR);
  116. u8 wlan24mac[ETH_ALEN] = {}, wlan5mac[ETH_ALEN] = {};
  117. ath79_register_m25p80(NULL);
  118. gpio_request_one(DIR869A1_GPIO_ENABLE_SWITCH,
  119. GPIOF_OUT_INIT_HIGH | GPIOF_EXPORT_DIR_FIXED,
  120. "Switch power");
  121. dir869a1_get_mac("lanmac=", ath79_eth0_data.mac_addr);
  122. ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_SGMII;
  123. ath79_eth0_data.mii_bus_dev = &ath79_mdio0_device.dev;
  124. ath79_eth0_data.phy_mask = BIT(0);
  125. mdiobus_register_board_info(dir869a1_mdio0_info,
  126. ARRAY_SIZE(dir869a1_mdio0_info));
  127. ath79_register_mdio(0, 0);
  128. ath79_register_eth(0);
  129. dir869a1_get_mac("wlan24mac=", wlan24mac);
  130. ath79_register_wmac(eeprom + DIR869A1_WMAC_CALDATA_OFFSET, wlan24mac);
  131. dir869a1_get_mac("wlan5mac=", wlan5mac);
  132. ap91_pci_init(eeprom + DIR869A1_PCI_CALDATA_OFFSET, wlan5mac);
  133. ath79_register_leds_gpio(-1, ARRAY_SIZE(dir869a1_leds_gpio),
  134. dir869a1_leds_gpio);
  135. ath79_register_gpio_keys_polled(-1, DIR869A1_KEYS_POLL_INTERVAL,
  136. ARRAY_SIZE(dir869a1_gpio_keys),
  137. dir869a1_gpio_keys);
  138. }
  139. MIPS_MACHINE(ATH79_MACH_DIR_869_A1, "DIR-869-A1", "D-Link DIR-869 rev. A1",
  140. dir869a1_setup);