1
0

mach-wndr4300.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. /*
  2. * NETGEAR WNDR3700v4/WNDR4300 board support
  3. *
  4. * Copyright (C) 2012 Gabor Juhos <juhosg@openwrt.org>
  5. * Copyright (C) 2014 Ralph Perlich <rpsoft@arcor.de>
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License version 2 as published
  9. * by the Free Software Foundation.
  10. */
  11. #include <linux/pci.h>
  12. #include <linux/phy.h>
  13. #include <linux/gpio.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/ath9k_platform.h>
  16. #include <linux/ar8216_platform.h>
  17. #include <linux/mtd/mtd.h>
  18. #include <linux/mtd/nand.h>
  19. #include <linux/platform/ar934x_nfc.h>
  20. #include <asm/mach-ath79/ar71xx_regs.h>
  21. #include "common.h"
  22. #include "dev-ap9x-pci.h"
  23. #include "dev-eth.h"
  24. #include "dev-gpio-buttons.h"
  25. #include "dev-leds-gpio.h"
  26. #include "dev-nfc.h"
  27. #include "dev-usb.h"
  28. #include "dev-wmac.h"
  29. #include "machtypes.h"
  30. /* AR9344 GPIOs */
  31. #define WNDR4300_GPIO_LED_POWER_GREEN 0
  32. #define WNDR4300_GPIO_LED_POWER_AMBER 2
  33. #define WNDR4300_GPIO_LED_USB 13
  34. #define WNDR4300_GPIO_LED_WAN_GREEN 1
  35. #define WNDR4300_GPIO_LED_WAN_AMBER 3
  36. #define WNDR4300_GPIO_LED_WLAN2G 11
  37. #define WNDR4300_GPIO_LED_WLAN5G 14
  38. #define WNDR4300_GPIO_LED_WPS_GREEN 16
  39. #define WNDR4300_GPIO_LED_WPS_AMBER 17
  40. #define WNDR4300_GPIO_BTN_RESET 21
  41. #define WNDR4300_GPIO_BTN_WIRELESS 15
  42. #define WNDR4300_GPIO_BTN_WPS 12
  43. /* AR9580 GPIOs */
  44. #define WNDR4300_GPIO_USB_5V 0
  45. #define WNDR4300_KEYS_POLL_INTERVAL 20 /* msecs */
  46. #define WNDR4300_KEYS_DEBOUNCE_INTERVAL (3 * WNDR4300_KEYS_POLL_INTERVAL)
  47. static struct gpio_led wndr4300_leds_gpio[] __initdata = {
  48. {
  49. .name = "netgear:green:power",
  50. .gpio = WNDR4300_GPIO_LED_POWER_GREEN,
  51. .active_low = 1,
  52. },
  53. {
  54. .name = "netgear:amber:power",
  55. .gpio = WNDR4300_GPIO_LED_POWER_AMBER,
  56. .active_low = 1,
  57. },
  58. {
  59. .name = "netgear:green:wan",
  60. .gpio = WNDR4300_GPIO_LED_WAN_GREEN,
  61. .active_low = 1,
  62. },
  63. {
  64. .name = "netgear:amber:wan",
  65. .gpio = WNDR4300_GPIO_LED_WAN_AMBER,
  66. .active_low = 1,
  67. },
  68. {
  69. .name = "netgear:green:usb",
  70. .gpio = WNDR4300_GPIO_LED_USB,
  71. .active_low = 1,
  72. },
  73. {
  74. .name = "netgear:green:wps",
  75. .gpio = WNDR4300_GPIO_LED_WPS_GREEN,
  76. .active_low = 1,
  77. },
  78. {
  79. .name = "netgear:amber:wps",
  80. .gpio = WNDR4300_GPIO_LED_WPS_AMBER,
  81. .active_low = 1,
  82. },
  83. {
  84. .name = "netgear:green:wlan2g",
  85. .gpio = WNDR4300_GPIO_LED_WLAN2G,
  86. .active_low = 1,
  87. },
  88. {
  89. .name = "netgear:blue:wlan5g",
  90. .gpio = WNDR4300_GPIO_LED_WLAN5G,
  91. .active_low = 1,
  92. },
  93. };
  94. static struct gpio_keys_button wndr4300_gpio_keys[] __initdata = {
  95. {
  96. .desc = "Reset button",
  97. .type = EV_KEY,
  98. .code = KEY_RESTART,
  99. .debounce_interval = WNDR4300_KEYS_DEBOUNCE_INTERVAL,
  100. .gpio = WNDR4300_GPIO_BTN_RESET,
  101. .active_low = 1,
  102. },
  103. {
  104. .desc = "WPS button",
  105. .type = EV_KEY,
  106. .code = KEY_WPS_BUTTON,
  107. .debounce_interval = WNDR4300_KEYS_DEBOUNCE_INTERVAL,
  108. .gpio = WNDR4300_GPIO_BTN_WPS,
  109. .active_low = 1,
  110. },
  111. {
  112. .desc = "Wireless button",
  113. .type = EV_KEY,
  114. .code = KEY_RFKILL,
  115. .debounce_interval = WNDR4300_KEYS_DEBOUNCE_INTERVAL,
  116. .gpio = WNDR4300_GPIO_BTN_WIRELESS,
  117. .active_low = 1,
  118. },
  119. };
  120. static struct ar8327_pad_cfg wndr4300_ar8327_pad0_cfg = {
  121. .mode = AR8327_PAD_MAC_RGMII,
  122. .txclk_delay_en = true,
  123. .rxclk_delay_en = true,
  124. .txclk_delay_sel = AR8327_CLK_DELAY_SEL1,
  125. .rxclk_delay_sel = AR8327_CLK_DELAY_SEL2,
  126. };
  127. static struct ar8327_led_cfg wndr4300_ar8327_led_cfg = {
  128. .led_ctrl0 = 0xc737c737,
  129. .led_ctrl1 = 0x00000000,
  130. .led_ctrl2 = 0x00000000,
  131. .led_ctrl3 = 0x0030c300,
  132. .open_drain = false,
  133. };
  134. static struct ar8327_platform_data wndr4300_ar8327_data = {
  135. .pad0_cfg = &wndr4300_ar8327_pad0_cfg,
  136. .port0_cfg = {
  137. .force_link = 1,
  138. .speed = AR8327_PORT_SPEED_1000,
  139. .duplex = 1,
  140. .txpause = 1,
  141. .rxpause = 1,
  142. },
  143. .led_cfg = &wndr4300_ar8327_led_cfg,
  144. };
  145. static struct mdio_board_info wndr4300_mdio0_info[] = {
  146. {
  147. .bus_id = "ag71xx-mdio.0",
  148. .phy_addr = 0,
  149. .platform_data = &wndr4300_ar8327_data,
  150. },
  151. };
  152. static void __init wndr4300_setup(void)
  153. {
  154. int i;
  155. for (i = 0; i < ARRAY_SIZE(wndr4300_leds_gpio); i++)
  156. ath79_gpio_output_select(wndr4300_leds_gpio[i].gpio,
  157. AR934X_GPIO_OUT_GPIO);
  158. ath79_register_leds_gpio(-1, ARRAY_SIZE(wndr4300_leds_gpio),
  159. wndr4300_leds_gpio);
  160. ath79_register_gpio_keys_polled(-1, WNDR4300_KEYS_POLL_INTERVAL,
  161. ARRAY_SIZE(wndr4300_gpio_keys),
  162. wndr4300_gpio_keys);
  163. ath79_setup_ar934x_eth_cfg(AR934X_ETH_CFG_RGMII_GMAC0);
  164. mdiobus_register_board_info(wndr4300_mdio0_info,
  165. ARRAY_SIZE(wndr4300_mdio0_info));
  166. ath79_register_mdio(0, 0x0);
  167. /* GMAC0 is connected to an AR8327N switch */
  168. ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  169. ath79_eth0_data.phy_mask = BIT(0);
  170. ath79_eth0_data.mii_bus_dev = &ath79_mdio0_device.dev;
  171. ath79_eth0_pll_data.pll_1000 = 0x06000000;
  172. ath79_register_eth(0);
  173. ath79_nfc_set_ecc_mode(AR934X_NFC_ECC_HW);
  174. ath79_register_nfc();
  175. ath79_register_usb();
  176. ath79_register_wmac_simple();
  177. /* enable power for the USB port */
  178. ap9x_pci_setup_wmac_gpio(0, BIT(WNDR4300_GPIO_USB_5V),
  179. BIT(WNDR4300_GPIO_USB_5V));
  180. ap91_pci_init_simple();
  181. }
  182. MIPS_MACHINE(ATH79_MACH_WNDR3700_V4, "WNDR3700_V4", "NETGEAR WNDR3700v4",
  183. wndr4300_setup);
  184. MIPS_MACHINE(ATH79_MACH_WNDR4300, "WNDR4300", "NETGEAR WNDR4300",
  185. wndr4300_setup);