mach-tew-712br.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*
  2. * TRENDnet TEW-712BR board support
  3. *
  4. * Copyright (C) 2012 Gabor Juhos <juhosg@openwrt.org>
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License version 2 as published
  8. * by the Free Software Foundation.
  9. */
  10. #include <linux/gpio.h>
  11. #include <asm/mach-ath79/ath79.h>
  12. #include <asm/mach-ath79/ar71xx_regs.h>
  13. #include "common.h"
  14. #include "dev-eth.h"
  15. #include "dev-gpio-buttons.h"
  16. #include "dev-leds-gpio.h"
  17. #include "dev-m25p80.h"
  18. #include "dev-wmac.h"
  19. #include "machtypes.h"
  20. #define TEW_712BR_GPIO_BTN_WPS 11
  21. #define TEW_712BR_GPIO_BTN_RESET 12
  22. #define TEW_712BR_GPIO_LED_LAN1 13
  23. #define TEW_712BR_GPIO_LED_LAN2 14
  24. #define TEW_712BR_GPIO_LED_LAN3 15
  25. #define TEW_712BR_GPIO_LED_LAN4 16
  26. #define TEW_712BR_GPIO_LED_POWER_GREEN 20
  27. #define TEW_712BR_GPIO_LED_POWER_ORANGE 27
  28. #define TEW_712BR_GPIO_LED_WAN_GREEN 17
  29. #define TEW_712BR_GPIO_LED_WAN_ORANGE 23
  30. #define TEW_712BR_GPIO_LED_WLAN 0
  31. #define TEW_712BR_GPIO_LED_WPS 26
  32. #define TEW_712BR_GPIO_WAN_LED_ENABLE 1
  33. #define TEW_712BR_KEYS_POLL_INTERVAL 20 /* msecs */
  34. #define TEW_712BR_KEYS_DEBOUNCE_INTERVAL (3 * TEW_712BR_KEYS_POLL_INTERVAL)
  35. #define TEW_712BR_ART_ADDRESS 0x1f010000
  36. #define TEW_712BR_CALDATA_OFFSET 0x1000
  37. #define TEW_712BR_MAC_PART_ADDRESS 0x1f020000
  38. #define TEW_712BR_LAN_MAC_OFFSET 0x04
  39. #define TEW_712BR_WAN_MAC_OFFSET 0x16
  40. static struct gpio_led tew_712br_leds_gpio[] __initdata = {
  41. {
  42. .name = "trendnet:green:lan1",
  43. .gpio = TEW_712BR_GPIO_LED_LAN1,
  44. .active_low = 0,
  45. }, {
  46. .name = "trendnet:green:lan2",
  47. .gpio = TEW_712BR_GPIO_LED_LAN2,
  48. .active_low = 0,
  49. }, {
  50. .name = "trendnet:green:lan3",
  51. .gpio = TEW_712BR_GPIO_LED_LAN3,
  52. .active_low = 0,
  53. }, {
  54. .name = "trendnet:green:lan4",
  55. .gpio = TEW_712BR_GPIO_LED_LAN4,
  56. .active_low = 0,
  57. }, {
  58. .name = "trendnet:blue:wps",
  59. .gpio = TEW_712BR_GPIO_LED_WPS,
  60. .active_low = 1,
  61. }, {
  62. .name = "trendnet:green:power",
  63. .gpio = TEW_712BR_GPIO_LED_POWER_GREEN,
  64. .active_low = 0,
  65. }, {
  66. .name = "trendnet:orange:power",
  67. .gpio = TEW_712BR_GPIO_LED_POWER_ORANGE,
  68. .active_low = 0,
  69. }, {
  70. .name = "trendnet:green:wan",
  71. .gpio = TEW_712BR_GPIO_LED_WAN_GREEN,
  72. .active_low = 1,
  73. }, {
  74. .name = "trendnet:orange:wan",
  75. .gpio = TEW_712BR_GPIO_LED_WAN_ORANGE,
  76. .active_low = 0,
  77. }, {
  78. .name = "trendnet:green:wlan",
  79. .gpio = TEW_712BR_GPIO_LED_WLAN,
  80. .active_low = 0,
  81. },
  82. };
  83. static struct gpio_keys_button tew_712br_gpio_keys[] __initdata = {
  84. {
  85. .desc = "Reset button",
  86. .type = EV_KEY,
  87. .code = KEY_RESTART,
  88. .debounce_interval = TEW_712BR_KEYS_DEBOUNCE_INTERVAL,
  89. .gpio = TEW_712BR_GPIO_BTN_RESET,
  90. .active_low = 1,
  91. }, {
  92. .desc = "WPS button",
  93. .type = EV_KEY,
  94. .code = KEY_WPS_BUTTON,
  95. .debounce_interval = TEW_712BR_KEYS_DEBOUNCE_INTERVAL,
  96. .gpio = TEW_712BR_GPIO_BTN_WPS,
  97. .active_low = 1,
  98. }
  99. };
  100. static void __init tew_712br_setup(void)
  101. {
  102. u8 *art = (u8 *) KSEG1ADDR(TEW_712BR_ART_ADDRESS);
  103. u8 *mac = (u8 *) KSEG1ADDR(TEW_712BR_MAC_PART_ADDRESS);
  104. u8 lan_mac[ETH_ALEN];
  105. u8 wan_mac[ETH_ALEN];
  106. ath79_setup_ar933x_phy4_switch(false, false);
  107. ath79_gpio_function_disable(AR933X_GPIO_FUNC_ETH_SWITCH_LED0_EN |
  108. AR933X_GPIO_FUNC_ETH_SWITCH_LED1_EN |
  109. AR933X_GPIO_FUNC_ETH_SWITCH_LED2_EN |
  110. AR933X_GPIO_FUNC_ETH_SWITCH_LED3_EN |
  111. AR933X_GPIO_FUNC_ETH_SWITCH_LED4_EN);
  112. gpio_request_one(TEW_712BR_GPIO_WAN_LED_ENABLE,
  113. GPIOF_OUT_INIT_LOW, "WAN LED enable");
  114. ath79_register_leds_gpio(-1, ARRAY_SIZE(tew_712br_leds_gpio),
  115. tew_712br_leds_gpio);
  116. ath79_register_gpio_keys_polled(1, TEW_712BR_KEYS_POLL_INTERVAL,
  117. ARRAY_SIZE(tew_712br_gpio_keys),
  118. tew_712br_gpio_keys);
  119. ath79_register_m25p80(NULL);
  120. ath79_parse_ascii_mac(mac + TEW_712BR_LAN_MAC_OFFSET, lan_mac);
  121. ath79_parse_ascii_mac(mac + TEW_712BR_WAN_MAC_OFFSET, wan_mac);
  122. ath79_init_mac(ath79_eth0_data.mac_addr, wan_mac, 0);
  123. ath79_init_mac(ath79_eth1_data.mac_addr, lan_mac, 0);
  124. ath79_register_mdio(0, 0x0);
  125. ath79_register_eth(1);
  126. ath79_register_eth(0);
  127. ath79_register_wmac(art + TEW_712BR_CALDATA_OFFSET, wan_mac);
  128. }
  129. MIPS_MACHINE(ATH79_MACH_TEW_712BR, "TEW-712BR",
  130. "TRENDnet TEW-712BR", tew_712br_setup);