mach-dap-1330-a1.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. * D-Link DAP-1330
  3. *
  4. * Copyright (c) 2013-2015 The Linux Foundation. All rights reserved.
  5. * Copyright (c) 2017 Nicolò Veronese <nicveronese@gmail.com>
  6. * Copyright (c) 2017 Federico Cappon <dududede371@gmail.com>
  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/gpio.h>
  22. #include <linux/platform_device.h>
  23. #include <asm/mach-ath79/ath79.h>
  24. #include <asm/mach-ath79/ar71xx_regs.h>
  25. #include "common.h"
  26. #include "dev-eth.h"
  27. #include "dev-gpio-buttons.h"
  28. #include "dev-leds-gpio.h"
  29. #include "dev-m25p80.h"
  30. #include "dev-wmac.h"
  31. #include "machtypes.h"
  32. #include "nvram.h"
  33. #include <linux/kernel.h>
  34. #include <linux/vmalloc.h>
  35. #include <linux/errno.h>
  36. #include <linux/init.h>
  37. #include <linux/string.h>
  38. #define DAP_1330_GPIO_LED_GREEN_POWER 13
  39. #define DAP_1330_GPIO_LED_RED_POWER 3
  40. #define DAP_1330_GPIO_LED_GREEN_WIFI 14
  41. #define DAP_1330_GPIO_LED_RED_WIFI 11
  42. #define DAP_1330_GPIO_LED_SIGNAL1 15
  43. #define DAP_1330_GPIO_LED_SIGNAL2 16
  44. #define DAP_1330_GPIO_BTN_WPS 2
  45. #define DAP_1330_GPIO_BTN_RESET 17
  46. #define DAP_1330_KEYS_POLL_INTERVAL 20 /* msecs */
  47. #define DAP_1330_KEYS_DEBOUNCE_INTERVAL (3 * DAP_1330_KEYS_POLL_INTERVAL)
  48. #define DAP1330_MAC_ADDR 0x1f020001
  49. #define DAP1330_WMAC_CALDATA_ADDR 0x1f010000
  50. #define DAP_1330_WMAC_CALDATA_OFFSET 0x1000
  51. static struct gpio_led dap_1330_leds_gpio[] __initdata = {
  52. {
  53. .name = "d-link:green:power",
  54. .gpio = DAP_1330_GPIO_LED_GREEN_POWER,
  55. .active_low = 1,
  56. },
  57. {
  58. .name = "d-link:red:power",
  59. .gpio = DAP_1330_GPIO_LED_RED_POWER,
  60. .active_low = 1,
  61. },
  62. {
  63. .name = "d-link:green:wifi",
  64. .gpio = DAP_1330_GPIO_LED_GREEN_WIFI,
  65. .active_low = 1,
  66. },
  67. {
  68. .name = "d-link:red:wifi",
  69. .gpio = DAP_1330_GPIO_LED_RED_WIFI,
  70. .active_low = 1,
  71. },
  72. {
  73. .name = "d-link:green:signal1",
  74. .gpio = DAP_1330_GPIO_LED_SIGNAL1,
  75. .active_low = 1,
  76. },
  77. {
  78. .name = "d-link:green:signal2",
  79. .gpio = DAP_1330_GPIO_LED_SIGNAL2,
  80. .active_low = 1,
  81. }
  82. };
  83. static struct gpio_keys_button dap_1330_gpio_keys[] __initdata = {
  84. {
  85. .desc = "WPS button",
  86. .type = EV_KEY,
  87. .code = KEY_WPS_BUTTON,
  88. .debounce_interval = DAP_1330_KEYS_DEBOUNCE_INTERVAL,
  89. .gpio = DAP_1330_GPIO_BTN_WPS,
  90. .active_low = 1,
  91. },
  92. {
  93. .desc = "Reset button",
  94. .type = EV_KEY,
  95. .code = KEY_RESTART,
  96. .debounce_interval = DAP_1330_KEYS_DEBOUNCE_INTERVAL,
  97. .gpio = DAP_1330_GPIO_BTN_RESET,
  98. .active_low = 1,
  99. }
  100. };
  101. static void __init dap_1330_setup(void)
  102. {
  103. u8 *art = (u8 *) KSEG1ADDR(DAP1330_WMAC_CALDATA_ADDR);
  104. u8 *mac_ptr = (u8 *) KSEG1ADDR(DAP1330_MAC_ADDR);
  105. u8 mac[ETH_ALEN];
  106. ath79_parse_ascii_mac((char *) mac_ptr, mac);
  107. ath79_register_m25p80(NULL);
  108. ath79_register_leds_gpio(-1, ARRAY_SIZE(dap_1330_leds_gpio),
  109. dap_1330_leds_gpio);
  110. ath79_register_gpio_keys_polled(-1, DAP_1330_KEYS_POLL_INTERVAL,
  111. ARRAY_SIZE(dap_1330_gpio_keys),
  112. dap_1330_gpio_keys);
  113. ath79_register_wmac(art + DAP_1330_WMAC_CALDATA_OFFSET, mac);
  114. ath79_register_mdio(0, 0x0);
  115. ath79_init_mac(ath79_eth1_data.mac_addr, mac, 0);
  116. /* LAN ports */
  117. ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_GMII;
  118. ath79_eth1_data.speed = SPEED_1000;
  119. ath79_eth1_data.duplex = DUPLEX_FULL;
  120. ath79_switch_data.phy_poll_mask |= BIT(4);
  121. ath79_switch_data.phy4_mii_en = 1;
  122. ath79_register_eth(1);
  123. }
  124. MIPS_MACHINE(ATH79_MACH_DAP_1330_A1, "DAP-1330-A1",
  125. "D-Link DAP-1330 Rev. A1", dap_1330_setup);