mach-wnr2200.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. /*
  2. * NETGEAR WNR2200 board support
  3. *
  4. * Copyright (C) 2013 Aidan Kissane <aidankissane at googlemail.com>
  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 <linux/mtd/mtd.h>
  12. #include <linux/mtd/partitions.h>
  13. #include <linux/kernel.h> /* for max() macro */
  14. #include <asm/mach-ath79/ath79.h>
  15. #include <asm/mach-ath79/ar71xx_regs.h> /* needed to disable switch LEDs */
  16. #include "common.h" /* needed to disable switch LEDs */
  17. #include "dev-ap9x-pci.h"
  18. #include "dev-eth.h"
  19. #include "dev-gpio-buttons.h"
  20. #include "dev-leds-gpio.h"
  21. #include "dev-m25p80.h"
  22. #include "dev-usb.h"
  23. #include "machtypes.h"
  24. /* WNR2200 - connected through AR7241 */
  25. #define WNR2200_GPIO_LED_LAN2_AMBER 0
  26. #define WNR2200_GPIO_LED_LAN4_AMBER 1
  27. #define WNR2200_GPIO_LED_LAN1_AMBER 6 /* AR724X_GPIO_FUNC_JTAG_DISABLE */
  28. #define WNR2200_GPIO_LED_WPS_GREEN 7 /* AR724X_GPIO_FUNC_JTAG_DISABLE */
  29. #define WNR2200_GPIO_LED_USB_GREEN 8 /* AR724X_GPIO_FUNC_JTAG_DISABLE */
  30. #define WNR2200_GPIO_LED_LAN3_AMBER 11
  31. #define WNR2200_GPIO_LED_WAN_AMBER 12
  32. #define WNR2200_GPIO_LED_LAN1_GREEN 13 /* AR724X_..._ETH_SWITCH_LED0 */
  33. #define WNR2200_GPIO_LED_LAN2_GREEN 14 /* AR724X_..._ETH_SWITCH_LED1 */
  34. #define WNR2200_GPIO_LED_LAN3_GREEN 15 /* AR724X_..._ETH_SWITCH_LED2 */
  35. #define WNR2200_GPIO_LED_LAN4_GREEN 16 /* AR724X_..._ETH_SWITCH_LED3 */
  36. #define WNR2200_GPIO_LED_WAN_GREEN 17 /* AR724X_..._ETH_SWITCH_LED4 */
  37. /* WNR2200 - connected through AR9287 */
  38. #define WNR2200_GPIO_WMAC_LED_WLAN_BLUE 0
  39. #define WNR2200_GPIO_WMAC_LED_TEST_AMBER 1
  40. #define WNR2200_GPIO_WMAC_LED_POWER_GREEN 2
  41. #define WNR2200_GPIO_WMAC_BTN_RFKILL 3
  42. #define WNR2200_GPIO_WMAC_USB_5V 4
  43. #define WNR2200_GPIO_WMAC_BTN_WPS 5
  44. #define WNR2200_GPIO_WMAC_BTN_RESET 6
  45. #define WNR2200_KEYS_POLL_INTERVAL 20 /* msecs */
  46. #define WNR2200_KEYS_DEBOUNCE_INTERVAL (3 * WNR2200_KEYS_POLL_INTERVAL)
  47. #define WNR2200_MAC0_OFFSET 0
  48. #define WNR2200_MAC1_OFFSET 6
  49. #define WNR2200_PCIE_CALDATA_OFFSET 0x1000
  50. #define WNR2200_WMAC_OFFSET 0x108c /* wireless MAC is inside ART */
  51. static struct gpio_led wnr2200_leds_gpio[] __initdata = {
  52. {
  53. .name = "netgear:amber:lan1",
  54. .gpio = WNR2200_GPIO_LED_LAN1_AMBER,
  55. .active_low = 1,
  56. }, {
  57. .name = "netgear:amber:lan2",
  58. .gpio = WNR2200_GPIO_LED_LAN2_AMBER,
  59. .active_low = 1,
  60. }, {
  61. .name = "netgear:amber:lan3",
  62. .gpio = WNR2200_GPIO_LED_LAN3_AMBER,
  63. .active_low = 1,
  64. }, {
  65. .name = "netgear:amber:lan4",
  66. .gpio = WNR2200_GPIO_LED_LAN4_AMBER,
  67. .active_low = 1,
  68. }, {
  69. .name = "netgear:amber:wan",
  70. .gpio = WNR2200_GPIO_LED_WAN_AMBER,
  71. .active_low = 1,
  72. }, {
  73. .name = "netgear:green:lan1",
  74. .gpio = WNR2200_GPIO_LED_LAN1_GREEN,
  75. .active_low = 1,
  76. }, {
  77. .name = "netgear:green:lan2",
  78. .gpio = WNR2200_GPIO_LED_LAN2_GREEN,
  79. .active_low = 1,
  80. }, {
  81. .name = "netgear:green:lan3",
  82. .gpio = WNR2200_GPIO_LED_LAN3_GREEN,
  83. .active_low = 1,
  84. }, {
  85. .name = "netgear:green:lan4",
  86. .gpio = WNR2200_GPIO_LED_LAN4_GREEN,
  87. .active_low = 1,
  88. }, {
  89. .name = "netgear:green:usb",
  90. .gpio = WNR2200_GPIO_LED_USB_GREEN,
  91. .active_low = 1,
  92. }, {
  93. .name = "netgear:green:wan",
  94. .gpio = WNR2200_GPIO_LED_WAN_GREEN,
  95. .active_low = 1,
  96. }, {
  97. .name = "netgear:green:wps",
  98. .gpio = WNR2200_GPIO_LED_WPS_GREEN,
  99. .active_low = 1,
  100. }
  101. };
  102. static const char *wnr2200_wmac_led_name = "netgear:blue:wlan";
  103. static struct gpio_led wnr2200_wmac_leds_gpio[] = {
  104. {
  105. .name = "netgear:amber:test",
  106. .gpio = WNR2200_GPIO_WMAC_LED_TEST_AMBER,
  107. .active_low = 1,
  108. }, {
  109. .name = "netgear:green:power",
  110. .gpio = WNR2200_GPIO_WMAC_LED_POWER_GREEN,
  111. .active_low = 1,
  112. .default_state = LEDS_GPIO_DEFSTATE_ON,
  113. }
  114. };
  115. static struct gpio_keys_button wnr2200_wmac_keys_gpio[] = {
  116. {
  117. .desc = "reset",
  118. .type = EV_KEY,
  119. .code = KEY_RESTART,
  120. .debounce_interval = WNR2200_KEYS_DEBOUNCE_INTERVAL,
  121. .gpio = WNR2200_GPIO_WMAC_BTN_RESET,
  122. .active_low = 1,
  123. }, {
  124. .desc = "rfkill",
  125. .type = EV_KEY,
  126. .code = KEY_RFKILL,
  127. .debounce_interval = WNR2200_KEYS_DEBOUNCE_INTERVAL,
  128. .gpio = WNR2200_GPIO_WMAC_BTN_RFKILL,
  129. .active_low = 1,
  130. }, {
  131. .desc = "wps",
  132. .type = EV_KEY,
  133. .code = KEY_WPS_BUTTON,
  134. .debounce_interval = WNR2200_KEYS_DEBOUNCE_INTERVAL,
  135. .gpio = WNR2200_GPIO_WMAC_BTN_WPS,
  136. .active_low = 1,
  137. }
  138. };
  139. /*
  140. * For WNR2200 ART flash area used for WLAN MAC is usually empty (0xff)
  141. * so ath9k driver uses random MAC instead each time module is loaded.
  142. * OpenWrt's original fix was to copy eth1 address to WLAN interface.
  143. * New solution does not duplicate hardware addresses and is taken from
  144. * WNR2000v3 code. It assigns permanent WLAN MAC equal to ethN's MAC
  145. * plus 1, so network interfaces get sequential addresses.
  146. * If ART wireless MAC address field has been filled by user, use it.
  147. */
  148. static void __init wnr2200_get_wmac(u8 *wmac_gen_addr, int mac0_art_offset,
  149. int mac1_art_offset, int wmac_art_offset)
  150. {
  151. u8 *art = (u8 *) KSEG1ADDR(0x1fff0000);
  152. u8 *eth0_mac_addr = (u8 *) (art + mac0_art_offset);
  153. u8 *eth1_mac_addr = (u8 *) (art + mac1_art_offset);
  154. u8 *wlan_mac_addr = (u8 *) (art + wmac_art_offset);
  155. /* only 0xff if all bits are set - address is invalid, empty area */
  156. if ((wlan_mac_addr[0] & wlan_mac_addr[1] & wlan_mac_addr[2] &
  157. wlan_mac_addr[3] & wlan_mac_addr[4] & wlan_mac_addr[5]) == 0xff) {
  158. memcpy(wmac_gen_addr, eth0_mac_addr, 5);
  159. wmac_gen_addr[5] = max(eth0_mac_addr[5], eth1_mac_addr[5]) + 1;
  160. /* Avoid potential conflict in case max(0xff,0x00)+1==0x00 */
  161. if (!wmac_gen_addr[5])
  162. wmac_gen_addr[5] = 1;
  163. } else
  164. memcpy(wmac_gen_addr, wlan_mac_addr, 6);
  165. }
  166. static void __init wnr2200_setup(void)
  167. {
  168. u8 *art = (u8 *) KSEG1ADDR(0x1fff0000);
  169. u8 wlan_mac_addr[6];
  170. /*
  171. * Disable JTAG to use all AR724X GPIO LEDs. Disable CLKs.
  172. * Allow OS to control all link LEDs.
  173. */
  174. ath79_gpio_function_setup(AR724X_GPIO_FUNC_JTAG_DISABLE |
  175. AR724X_GPIO_FUNC_UART_EN,
  176. AR724X_GPIO_FUNC_CLK_OBS1_EN |
  177. AR724X_GPIO_FUNC_CLK_OBS2_EN |
  178. AR724X_GPIO_FUNC_CLK_OBS3_EN |
  179. AR724X_GPIO_FUNC_CLK_OBS4_EN |
  180. AR724X_GPIO_FUNC_CLK_OBS5_EN |
  181. AR724X_GPIO_FUNC_GE0_MII_CLK_EN |
  182. AR724X_GPIO_FUNC_ETH_SWITCH_LED0_EN |
  183. AR724X_GPIO_FUNC_ETH_SWITCH_LED1_EN |
  184. AR724X_GPIO_FUNC_ETH_SWITCH_LED2_EN |
  185. AR724X_GPIO_FUNC_ETH_SWITCH_LED3_EN |
  186. AR724X_GPIO_FUNC_ETH_SWITCH_LED4_EN);
  187. ath79_register_mdio(0, 0x0);
  188. ath79_init_mac(ath79_eth0_data.mac_addr, art + WNR2200_MAC0_OFFSET, 0);
  189. ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  190. ath79_eth0_data.speed = SPEED_100;
  191. ath79_eth0_data.duplex = DUPLEX_FULL;
  192. ath79_init_mac(ath79_eth1_data.mac_addr, art + WNR2200_MAC1_OFFSET, 0);
  193. ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RMII;
  194. ath79_eth1_data.phy_mask = 0x10;
  195. ath79_register_eth(0);
  196. ath79_register_eth(1);
  197. ath79_register_m25p80(NULL);
  198. wnr2200_get_wmac(wlan_mac_addr, WNR2200_MAC0_OFFSET,
  199. WNR2200_MAC1_OFFSET, WNR2200_WMAC_OFFSET);
  200. ap91_pci_init(art + WNR2200_PCIE_CALDATA_OFFSET, wlan_mac_addr);
  201. ath79_register_leds_gpio(-1, ARRAY_SIZE(wnr2200_leds_gpio),
  202. wnr2200_leds_gpio);
  203. ap9x_pci_setup_wmac_led_pin(0, WNR2200_GPIO_WMAC_LED_WLAN_BLUE);
  204. ap9x_pci_setup_wmac_led_name(0, wnr2200_wmac_led_name);
  205. ap9x_pci_setup_wmac_leds(0, wnr2200_wmac_leds_gpio,
  206. ARRAY_SIZE(wnr2200_wmac_leds_gpio));
  207. /* All 3 buttons are connected to wireless chip */
  208. ap9x_pci_setup_wmac_btns(0, wnr2200_wmac_keys_gpio,
  209. ARRAY_SIZE(wnr2200_wmac_keys_gpio),
  210. WNR2200_KEYS_POLL_INTERVAL);
  211. /* enable power for the USB port */
  212. ap9x_pci_setup_wmac_gpio(0, BIT(WNR2200_GPIO_WMAC_USB_5V),
  213. BIT(WNR2200_GPIO_WMAC_USB_5V));
  214. ath79_register_usb();
  215. }
  216. MIPS_MACHINE(ATH79_MACH_WNR2200, "WNR2200", "NETGEAR WNR2200", wnr2200_setup);