mach-wnr2000-v4.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /*
  2. * NETGEAR WNR2000v4 board support
  3. *
  4. * Copyright (C) 2015 Michael Bazzinotti <mbazzinotti@gmail.com>
  5. * Copyright (C) 2014 Michaël Burtin <mburtin@gmail.com>
  6. * Copyright (C) 2013 Mathieu Olivari <mathieu.olivari@gmail.com>
  7. * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  8. * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  9. * Copyright (C) 2008-2009 Andy Boyett <agb@openwrt.org>
  10. *
  11. * This program is free software; you can redistribute it and/or modify it
  12. * under the terms of the GNU General Public License version 2 as published
  13. * by the Free Software Foundation.
  14. */
  15. #include <linux/mtd/mtd.h>
  16. #include <linux/mtd/partitions.h>
  17. #include <linux/platform_device.h>
  18. #include <asm/mach-ath79/ath79.h>
  19. #include <asm/mach-ath79/ar71xx_regs.h>
  20. #include "common.h"
  21. #include "dev-eth.h"
  22. #include "dev-gpio-buttons.h"
  23. #include "dev-leds-gpio.h"
  24. #include "dev-m25p80.h"
  25. #include "dev-usb.h"
  26. #include "dev-wmac.h"
  27. #include "machtypes.h"
  28. /* AR9341 GPIOs */
  29. #define WNR2000V4_GPIO_LED_PWR_GREEN 0
  30. #define WNR2000V4_GPIO_LED_PWR_AMBER 1
  31. #define WNR2000V4_GPIO_LED_WPS 2
  32. #define WNR2000V4_GPIO_LED_WLAN 12
  33. #define WNR2000V4_GPIO_LED_LAN1_GREEN 13
  34. #define WNR2000V4_GPIO_LED_LAN2_GREEN 14
  35. #define WNR2000V4_GPIO_LED_LAN3_GREEN 15
  36. #define WNR2000V4_GPIO_LED_LAN4_GREEN 16
  37. #define WNR2000V4_GPIO_LED_LAN1_AMBER 18
  38. #define WNR2000V4_GPIO_LED_LAN2_AMBER 19
  39. #define WNR2000V4_GPIO_LED_LAN3_AMBER 20
  40. #define WNR2000V4_GPIO_LED_LAN4_AMBER 21
  41. #define WNR2000V4_GPIO_LED_WAN_GREEN 17
  42. #define WNR2000V4_GPIO_LED_WAN_AMBER 22
  43. /* Buttons */
  44. #define WNR2000V4_GPIO_BTN_WPS 3
  45. #define WNR2000V4_GPIO_BTN_RESET 4
  46. #define WNR2000V4_GPIO_BTN_WLAN 11
  47. #define WNR2000V4_KEYS_POLL_INTERVAL 20 /* msecs */
  48. #define WNR2000V4_KEYS_DEBOUNCE_INTERVAL (3 * WNR2000V4_KEYS_POLL_INTERVAL)
  49. /* ART offsets */
  50. #define WNR2000V4_MAC0_OFFSET 0 /* WAN/WLAN0 MAC */
  51. #define WNR2000V4_MAC1_OFFSET 6 /* Eth-switch0 MAC */
  52. static struct gpio_led wnr2000v4_leds_gpio[] __initdata = {
  53. {
  54. .name = "netgear:green:power",
  55. .gpio = WNR2000V4_GPIO_LED_PWR_GREEN,
  56. .active_low = 1,
  57. .default_trigger = "default-on",
  58. },
  59. {
  60. .name = "netgear:amber:status",
  61. .gpio = WNR2000V4_GPIO_LED_PWR_AMBER,
  62. .active_low = 1,
  63. },
  64. {
  65. .name = "netgear:green:wan",
  66. .gpio = WNR2000V4_GPIO_LED_WAN_GREEN,
  67. .active_low = 1,
  68. },
  69. {
  70. .name = "netgear:amber:wan",
  71. .gpio = WNR2000V4_GPIO_LED_WAN_AMBER,
  72. .active_low = 1,
  73. },
  74. {
  75. .name = "netgear:blue:wlan",
  76. .gpio = WNR2000V4_GPIO_LED_WLAN,
  77. .active_low = 1,
  78. },
  79. /* LAN LEDS */
  80. {
  81. .name = "netgear:green:lan1",
  82. .gpio = WNR2000V4_GPIO_LED_LAN1_GREEN,
  83. .active_low = 1,
  84. },
  85. {
  86. .name = "netgear:green:lan2",
  87. .gpio = WNR2000V4_GPIO_LED_LAN2_GREEN,
  88. .active_low = 1,
  89. },
  90. {
  91. .name = "netgear:green:lan3",
  92. .gpio = WNR2000V4_GPIO_LED_LAN3_GREEN,
  93. .active_low = 1,
  94. },
  95. {
  96. .name = "netgear:green:lan4",
  97. .gpio = WNR2000V4_GPIO_LED_LAN4_GREEN,
  98. .active_low = 1,
  99. },
  100. {
  101. .name = "netgear:amber:lan1",
  102. .gpio = WNR2000V4_GPIO_LED_LAN1_AMBER,
  103. .active_low = 1,
  104. },
  105. {
  106. .name = "netgear:amber:lan2",
  107. .gpio = WNR2000V4_GPIO_LED_LAN2_AMBER,
  108. .active_low = 1,
  109. },
  110. {
  111. .name = "netgear:amber:lan3",
  112. .gpio = WNR2000V4_GPIO_LED_LAN3_AMBER,
  113. .active_low = 1,
  114. },
  115. {
  116. .name = "netgear:amber:lan4",
  117. .gpio = WNR2000V4_GPIO_LED_LAN4_AMBER,
  118. .active_low = 1,
  119. },
  120. {
  121. .name = "netgear:green:wps",
  122. .gpio = WNR2000V4_GPIO_LED_WPS,
  123. .active_low = 1,
  124. },
  125. };
  126. static struct gpio_keys_button wnr2000v4_gpio_keys[] __initdata = {
  127. {
  128. .desc = "WPS button",
  129. .type = EV_KEY,
  130. .code = KEY_WPS_BUTTON,
  131. .debounce_interval = WNR2000V4_KEYS_DEBOUNCE_INTERVAL,
  132. .gpio = WNR2000V4_GPIO_BTN_WPS,
  133. .active_low = 1,
  134. },
  135. {
  136. .desc = "Reset button",
  137. .type = EV_KEY,
  138. .code = KEY_RESTART,
  139. .debounce_interval = WNR2000V4_KEYS_DEBOUNCE_INTERVAL,
  140. .gpio = WNR2000V4_GPIO_BTN_RESET,
  141. .active_low = 1,
  142. },
  143. {
  144. .desc = "WLAN button",
  145. .type = EV_KEY,
  146. .code = KEY_RFKILL,
  147. .debounce_interval = WNR2000V4_KEYS_DEBOUNCE_INTERVAL,
  148. .gpio = WNR2000V4_GPIO_BTN_WLAN,
  149. .active_low = 1,
  150. },
  151. };
  152. static void __init wnr_common_setup(void)
  153. {
  154. u8 *art = (u8 *) KSEG1ADDR(0x1fff0000);
  155. u8 *ee = (u8 *) KSEG1ADDR(0x1fff1000);
  156. ath79_register_mdio(1, 0x0);
  157. ath79_register_usb();
  158. ath79_register_m25p80(NULL);
  159. ath79_setup_ar934x_eth_cfg(AR934X_ETH_CFG_SW_ONLY_MODE);
  160. ath79_init_mac(ath79_eth0_data.mac_addr, art+WNR2000V4_MAC0_OFFSET, 0);
  161. ath79_init_mac(ath79_eth1_data.mac_addr, art+WNR2000V4_MAC1_OFFSET, 0);
  162. /* GMAC0 is connected to the PHY0 of the internal switch, GE0 */
  163. ath79_switch_data.phy4_mii_en = 1;
  164. ath79_switch_data.phy_poll_mask = BIT(4);
  165. ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
  166. ath79_eth0_data.phy_mask = BIT(4);
  167. ath79_eth0_data.mii_bus_dev = &ath79_mdio1_device.dev;
  168. ath79_register_eth(0);
  169. /* GMAC1 is connected to the internal switch, GE1 */
  170. ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_GMII;
  171. ath79_register_eth(1);
  172. ath79_register_wmac(ee, art);
  173. }
  174. static void __init wnr2000v4_setup(void)
  175. {
  176. int i;
  177. wnr_common_setup();
  178. /* Ensure no LED has an internal MUX signal, otherwise
  179. control of LED could be lost... This is especially important
  180. for most green LEDS (Eth,WAN).. who arrive in this function with
  181. MUX signals set. */
  182. for (i = 0; i < ARRAY_SIZE(wnr2000v4_leds_gpio); i++)
  183. ath79_gpio_output_select(wnr2000v4_leds_gpio[i].gpio,
  184. AR934X_GPIO_OUT_GPIO);
  185. ath79_register_leds_gpio(-1, ARRAY_SIZE(wnr2000v4_leds_gpio),
  186. wnr2000v4_leds_gpio);
  187. ath79_register_gpio_keys_polled(-1, WNR2000V4_KEYS_POLL_INTERVAL,
  188. ARRAY_SIZE(wnr2000v4_gpio_keys),
  189. wnr2000v4_gpio_keys);
  190. }
  191. MIPS_MACHINE(ATH79_MACH_WNR2000_V4, "WNR2000V4", "NETGEAR WNR2000 V4", wnr2000v4_setup);