mach-tl-wdr4300.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. /*
  2. * TP-LINK TL-WDR4300 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/pci.h>
  11. #include <linux/phy.h>
  12. #include <linux/gpio.h>
  13. #include <linux/platform_device.h>
  14. #include <linux/ath9k_platform.h>
  15. #include <linux/ar8216_platform.h>
  16. #include <asm/mach-ath79/ar71xx_regs.h>
  17. #include "common.h"
  18. #include "dev-ap9x-pci.h"
  19. #include "dev-eth.h"
  20. #include "dev-gpio-buttons.h"
  21. #include "dev-leds-gpio.h"
  22. #include "dev-m25p80.h"
  23. #include "dev-spi.h"
  24. #include "dev-usb.h"
  25. #include "dev-wmac.h"
  26. #include "machtypes.h"
  27. #define WDR4300_GPIO_LED_USB1 11
  28. #define WDR4300_GPIO_LED_USB2 12
  29. #define WDR4300_GPIO_LED_WLAN2G 13
  30. #define WDR4300_GPIO_LED_SYSTEM 14
  31. #define WDR4300_GPIO_LED_QSS 15
  32. #define WDR4300_GPIO_BTN_WPS 16
  33. #define WDR4300_GPIO_BTN_RFKILL 17
  34. #define WDR4300_GPIO_EXTERNAL_LNA0 18
  35. #define WDR4300_GPIO_EXTERNAL_LNA1 19
  36. #define WDR4300_GPIO_USB1_POWER 22
  37. #define WDR4300_GPIO_USB2_POWER 21
  38. #define WDR4300_KEYS_POLL_INTERVAL 20 /* msecs */
  39. #define WDR4300_KEYS_DEBOUNCE_INTERVAL (3 * WDR4300_KEYS_POLL_INTERVAL)
  40. #define WDR4300_MAC0_OFFSET 0
  41. #define WDR4300_MAC1_OFFSET 6
  42. #define WDR4300_WMAC_CALDATA_OFFSET 0x1000
  43. #define WDR4300_PCIE_CALDATA_OFFSET 0x5000
  44. static const char *wdr4300_part_probes[] = {
  45. "tp-link",
  46. NULL,
  47. };
  48. static struct flash_platform_data wdr4300_flash_data = {
  49. .part_probes = wdr4300_part_probes,
  50. };
  51. static struct gpio_led wdr4300_leds_gpio[] __initdata = {
  52. {
  53. .name = "tp-link:blue:qss",
  54. .gpio = WDR4300_GPIO_LED_QSS,
  55. .active_low = 1,
  56. },
  57. {
  58. .name = "tp-link:blue:system",
  59. .gpio = WDR4300_GPIO_LED_SYSTEM,
  60. .active_low = 1,
  61. },
  62. {
  63. .name = "tp-link:green:usb1",
  64. .gpio = WDR4300_GPIO_LED_USB1,
  65. .active_low = 1,
  66. },
  67. {
  68. .name = "tp-link:green:usb2",
  69. .gpio = WDR4300_GPIO_LED_USB2,
  70. .active_low = 1,
  71. },
  72. {
  73. .name = "tp-link:blue:wlan2g",
  74. .gpio = WDR4300_GPIO_LED_WLAN2G,
  75. .active_low = 1,
  76. },
  77. };
  78. static struct gpio_keys_button wdr4300_gpio_keys[] __initdata = {
  79. {
  80. .desc = "QSS button",
  81. .type = EV_KEY,
  82. .code = KEY_WPS_BUTTON,
  83. .debounce_interval = WDR4300_KEYS_DEBOUNCE_INTERVAL,
  84. .gpio = WDR4300_GPIO_BTN_WPS,
  85. .active_low = 1,
  86. },
  87. {
  88. .desc = "RFKILL switch",
  89. .type = EV_SW,
  90. .code = KEY_RFKILL,
  91. .debounce_interval = WDR4300_KEYS_DEBOUNCE_INTERVAL,
  92. .gpio = WDR4300_GPIO_BTN_RFKILL,
  93. .active_low = 1,
  94. },
  95. };
  96. static const struct ar8327_led_info wdr4300_leds_ar8327[] __initconst = {
  97. AR8327_LED_INFO(PHY0_0, HW, "tp-link:blue:wan"),
  98. AR8327_LED_INFO(PHY1_0, HW, "tp-link:blue:lan1"),
  99. AR8327_LED_INFO(PHY2_0, HW, "tp-link:blue:lan2"),
  100. AR8327_LED_INFO(PHY3_0, HW, "tp-link:blue:lan3"),
  101. AR8327_LED_INFO(PHY4_0, HW, "tp-link:blue:lan4"),
  102. };
  103. static struct ar8327_pad_cfg wdr4300_ar8327_pad0_cfg = {
  104. .mode = AR8327_PAD_MAC_RGMII,
  105. .txclk_delay_en = true,
  106. .rxclk_delay_en = true,
  107. .txclk_delay_sel = AR8327_CLK_DELAY_SEL1,
  108. .rxclk_delay_sel = AR8327_CLK_DELAY_SEL2,
  109. };
  110. static struct ar8327_led_cfg wdr4300_ar8327_led_cfg = {
  111. .led_ctrl0 = 0xc737c737,
  112. .led_ctrl1 = 0x00000000,
  113. .led_ctrl2 = 0x00000000,
  114. .led_ctrl3 = 0x0030c300,
  115. .open_drain = false,
  116. };
  117. static struct ar8327_platform_data wdr4300_ar8327_data = {
  118. .pad0_cfg = &wdr4300_ar8327_pad0_cfg,
  119. .port0_cfg = {
  120. .force_link = 1,
  121. .speed = AR8327_PORT_SPEED_1000,
  122. .duplex = 1,
  123. .txpause = 1,
  124. .rxpause = 1,
  125. },
  126. .led_cfg = &wdr4300_ar8327_led_cfg,
  127. .num_leds = ARRAY_SIZE(wdr4300_leds_ar8327),
  128. .leds = wdr4300_leds_ar8327,
  129. };
  130. static struct mdio_board_info wdr4300_mdio0_info[] = {
  131. {
  132. .bus_id = "ag71xx-mdio.0",
  133. .phy_addr = 0,
  134. .platform_data = &wdr4300_ar8327_data,
  135. },
  136. };
  137. static void __init wdr4300_setup(void)
  138. {
  139. u8 *mac = (u8 *) KSEG1ADDR(0x1f01fc00);
  140. u8 *art = (u8 *) KSEG1ADDR(0x1fff0000);
  141. u8 tmpmac[ETH_ALEN];
  142. ath79_register_m25p80(&wdr4300_flash_data);
  143. ath79_register_leds_gpio(-1, ARRAY_SIZE(wdr4300_leds_gpio),
  144. wdr4300_leds_gpio);
  145. ath79_register_gpio_keys_polled(-1, WDR4300_KEYS_POLL_INTERVAL,
  146. ARRAY_SIZE(wdr4300_gpio_keys),
  147. wdr4300_gpio_keys);
  148. ath79_wmac_set_ext_lna_gpio(0, WDR4300_GPIO_EXTERNAL_LNA0);
  149. ath79_wmac_set_ext_lna_gpio(1, WDR4300_GPIO_EXTERNAL_LNA1);
  150. ath79_init_mac(tmpmac, mac, -1);
  151. ath79_register_wmac(art + WDR4300_WMAC_CALDATA_OFFSET, tmpmac);
  152. ath79_init_mac(tmpmac, mac, 0);
  153. ap9x_pci_setup_wmac_led_pin(0, 0);
  154. ap91_pci_init(art + WDR4300_PCIE_CALDATA_OFFSET, tmpmac);
  155. ath79_setup_ar934x_eth_cfg(AR934X_ETH_CFG_RGMII_GMAC0);
  156. mdiobus_register_board_info(wdr4300_mdio0_info,
  157. ARRAY_SIZE(wdr4300_mdio0_info));
  158. ath79_register_mdio(0, 0x0);
  159. ath79_init_mac(ath79_eth0_data.mac_addr, mac, -2);
  160. /* GMAC0 is connected to an AR8327N switch */
  161. ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  162. ath79_eth0_data.phy_mask = BIT(0);
  163. ath79_eth0_data.mii_bus_dev = &ath79_mdio0_device.dev;
  164. ath79_eth0_pll_data.pll_1000 = 0x06000000;
  165. ath79_register_eth(0);
  166. gpio_request_one(WDR4300_GPIO_USB1_POWER,
  167. GPIOF_OUT_INIT_HIGH | GPIOF_EXPORT_DIR_FIXED,
  168. "USB1 power");
  169. gpio_request_one(WDR4300_GPIO_USB2_POWER,
  170. GPIOF_OUT_INIT_HIGH | GPIOF_EXPORT_DIR_FIXED,
  171. "USB2 power");
  172. ath79_register_usb();
  173. }
  174. MIPS_MACHINE(ATH79_MACH_TL_WDR4300, "TL-WDR4300",
  175. "TP-LINK TL-WDR3600/4300/4310",
  176. wdr4300_setup);