mach-dragino2.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*
  2. * DRAGINO V2 board support, based on Atheros AP121 board support
  3. *
  4. * Copyright (C) 2011-2012 Gabor Juhos <juhosg@openwrt.org>
  5. * Copyright (C) 2012 Elektra Wagenrad <elektra@villagetelco.org>
  6. * Copyright (C) 2014 Vittorio Gambaletta <openwrt@vittgam.net>
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License version 2 as published
  10. * by the Free Software Foundation.
  11. */
  12. #include <linux/gpio.h>
  13. #include <asm/mach-ath79/ath79.h>
  14. #include <asm/mach-ath79/ar71xx_regs.h>
  15. #include "common.h"
  16. #include "dev-eth.h"
  17. #include "dev-gpio-buttons.h"
  18. #include "dev-leds-gpio.h"
  19. #include "dev-m25p80.h"
  20. #include "dev-spi.h"
  21. #include "dev-usb.h"
  22. #include "dev-wmac.h"
  23. #include "machtypes.h"
  24. #define DRAGINO2_GPIO_LED_WLAN 0
  25. #define DRAGINO2_GPIO_LED_LAN 13
  26. #define DRAGINO2_GPIO_LED_WAN 17
  27. /*
  28. * The following GPIO is named "SYS" on newer revisions of the the board.
  29. * It was previously used to indicate USB activity, even though it was
  30. * named "Router".
  31. */
  32. #define DRAGINO2_GPIO_LED_SYS 28
  33. #define DRAGINO2_GPIO_BTN_JUMPSTART 11
  34. #define DRAGINO2_GPIO_BTN_RESET 12
  35. #define DRAGINO2_KEYS_POLL_INTERVAL 20 /* msecs */
  36. #define DRAGINO2_KEYS_DEBOUNCE_INTERVAL (3 * DRAGINO2_KEYS_POLL_INTERVAL)
  37. #define DRAGINO2_MAC0_OFFSET 0x0000
  38. #define DRAGINO2_MAC1_OFFSET 0x0006
  39. #define DRAGINO2_CALDATA_OFFSET 0x1000
  40. #define DRAGINO2_WMAC_MAC_OFFSET 0x1002
  41. static struct gpio_led dragino2_leds_gpio[] __initdata = {
  42. {
  43. .name = "dragino2:red:wlan",
  44. .gpio = DRAGINO2_GPIO_LED_WLAN,
  45. .active_low = 0,
  46. },
  47. {
  48. .name = "dragino2:red:wan",
  49. .gpio = DRAGINO2_GPIO_LED_WAN,
  50. .active_low = 1,
  51. },
  52. {
  53. .name = "dragino2:red:lan",
  54. .gpio = DRAGINO2_GPIO_LED_LAN,
  55. .active_low = 1,
  56. },
  57. {
  58. .name = "dragino2:red:system",
  59. .gpio = DRAGINO2_GPIO_LED_SYS,
  60. .active_low = 0,
  61. },
  62. };
  63. static struct gpio_keys_button dragino2_gpio_keys[] __initdata = {
  64. {
  65. .desc = "jumpstart button",
  66. .type = EV_KEY,
  67. .code = KEY_WPS_BUTTON,
  68. .debounce_interval = DRAGINO2_KEYS_DEBOUNCE_INTERVAL,
  69. .gpio = DRAGINO2_GPIO_BTN_JUMPSTART,
  70. .active_low = 1,
  71. },
  72. {
  73. .desc = "reset button",
  74. .type = EV_KEY,
  75. .code = KEY_RESTART,
  76. .debounce_interval = DRAGINO2_KEYS_DEBOUNCE_INTERVAL,
  77. .gpio = DRAGINO2_GPIO_BTN_RESET,
  78. .active_low = 1,
  79. }
  80. };
  81. static void __init dragino2_common_setup(void)
  82. {
  83. u8 *art = (u8 *) KSEG1ADDR(0x1fff0000);
  84. ath79_register_m25p80(NULL);
  85. ath79_register_wmac(art + DRAGINO2_CALDATA_OFFSET,
  86. art + DRAGINO2_WMAC_MAC_OFFSET);
  87. ath79_init_mac(ath79_eth0_data.mac_addr, art + DRAGINO2_MAC0_OFFSET, 0);
  88. ath79_init_mac(ath79_eth1_data.mac_addr, art + DRAGINO2_MAC1_OFFSET, 0);
  89. ath79_register_mdio(0, 0x0);
  90. /* Enable GPIO13, GPIO14, GPIO15, GPIO16 and GPIO17 */
  91. ath79_gpio_function_disable(AR933X_GPIO_FUNC_ETH_SWITCH_LED0_EN |
  92. AR933X_GPIO_FUNC_ETH_SWITCH_LED1_EN |
  93. AR933X_GPIO_FUNC_ETH_SWITCH_LED2_EN |
  94. AR933X_GPIO_FUNC_ETH_SWITCH_LED3_EN |
  95. AR933X_GPIO_FUNC_ETH_SWITCH_LED4_EN);
  96. /* LAN port */
  97. ath79_register_eth(1);
  98. /* WAN port */
  99. ath79_register_eth(0);
  100. /* Enable GPIO26 and GPIO27 */
  101. ath79_reset_wr(AR933X_RESET_REG_BOOTSTRAP,
  102. ath79_reset_rr(AR933X_RESET_REG_BOOTSTRAP) |
  103. AR933X_BOOTSTRAP_MDIO_GPIO_EN);
  104. }
  105. static void __init dragino2_setup(void)
  106. {
  107. dragino2_common_setup();
  108. ath79_register_leds_gpio(-1, ARRAY_SIZE(dragino2_leds_gpio),
  109. dragino2_leds_gpio);
  110. ath79_register_gpio_keys_polled(-1, DRAGINO2_KEYS_POLL_INTERVAL,
  111. ARRAY_SIZE(dragino2_gpio_keys),
  112. dragino2_gpio_keys);
  113. ath79_register_usb();
  114. }
  115. MIPS_MACHINE(ATH79_MACH_DRAGINO2, "DRAGINO2", "Dragino Dragino v2",
  116. dragino2_setup);