mach-dir-825-c1.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. /*
  2. * D-Link DIR-825 rev. C1 board support
  3. *
  4. * Copyright (C) 2013 Alexander Stadler
  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 DIR825C1_GPIO_LED_BLUE_USB 11
  28. #define DIR825C1_GPIO_LED_AMBER_POWER 14
  29. #define DIR825C1_GPIO_LED_BLUE_POWER 22
  30. #define DIR825C1_GPIO_LED_BLUE_WPS 15
  31. #define DIR825C1_GPIO_LED_AMBER_PLANET 19
  32. #define DIR825C1_GPIO_LED_BLUE_PLANET 18
  33. #define DIR825C1_GPIO_LED_WLAN_2G 13
  34. #define DIR825C1_GPIO_WAN_LED_ENABLE 20
  35. #define DIR825C1_GPIO_BTN_RESET 17
  36. #define DIR825C1_GPIO_BTN_WPS 16
  37. #define DIR825C1_KEYS_POLL_INTERVAL 20 /* msecs */
  38. #define DIR825C1_KEYS_DEBOUNCE_INTERVAL (3 * DIR825C1_KEYS_POLL_INTERVAL)
  39. #define DIR825C1_MAC0_OFFSET 0x4
  40. #define DIR825C1_MAC1_OFFSET 0x18
  41. #define DIR825C1_WMAC_CALDATA_OFFSET 0x1000
  42. #define DIR825C1_PCIE_CALDATA_OFFSET 0x5000
  43. static struct gpio_led dir825c1_leds_gpio[] __initdata = {
  44. {
  45. .name = "d-link:blue:usb",
  46. .gpio = DIR825C1_GPIO_LED_BLUE_USB,
  47. .active_low = 1,
  48. },
  49. {
  50. .name = "d-link:amber:power",
  51. .gpio = DIR825C1_GPIO_LED_AMBER_POWER,
  52. .active_low = 1,
  53. },
  54. {
  55. .name = "d-link:blue:power",
  56. .gpio = DIR825C1_GPIO_LED_BLUE_POWER,
  57. .active_low = 1,
  58. },
  59. {
  60. .name = "d-link:blue:wps",
  61. .gpio = DIR825C1_GPIO_LED_BLUE_WPS,
  62. .active_low = 1,
  63. },
  64. {
  65. .name = "d-link:amber:planet",
  66. .gpio = DIR825C1_GPIO_LED_AMBER_PLANET,
  67. .active_low = 1,
  68. },
  69. {
  70. .name = "d-link:blue:wlan2g",
  71. .gpio = DIR825C1_GPIO_LED_WLAN_2G,
  72. .active_low = 1,
  73. },
  74. };
  75. static struct gpio_led dir835a1_leds_gpio[] __initdata = {
  76. {
  77. .name = "d-link:amber:power",
  78. .gpio = DIR825C1_GPIO_LED_AMBER_POWER,
  79. .active_low = 1,
  80. },
  81. {
  82. .name = "d-link:green:power",
  83. .gpio = DIR825C1_GPIO_LED_BLUE_POWER,
  84. .active_low = 1,
  85. },
  86. {
  87. .name = "d-link:blue:wps",
  88. .gpio = DIR825C1_GPIO_LED_BLUE_WPS,
  89. .active_low = 1,
  90. },
  91. {
  92. .name = "d-link:amber:planet",
  93. .gpio = DIR825C1_GPIO_LED_AMBER_PLANET,
  94. .active_low = 1,
  95. },
  96. {
  97. .name = "d-link:green:planet",
  98. .gpio = DIR825C1_GPIO_LED_BLUE_PLANET,
  99. .active_low = 1,
  100. },
  101. };
  102. static struct gpio_keys_button dir825c1_gpio_keys[] __initdata = {
  103. {
  104. .desc = "Soft reset",
  105. .type = EV_KEY,
  106. .code = KEY_RESTART,
  107. .debounce_interval = DIR825C1_KEYS_DEBOUNCE_INTERVAL,
  108. .gpio = DIR825C1_GPIO_BTN_RESET,
  109. .active_low = 1,
  110. },
  111. {
  112. .desc = "WPS button",
  113. .type = EV_KEY,
  114. .code = KEY_WPS_BUTTON,
  115. .debounce_interval = DIR825C1_KEYS_DEBOUNCE_INTERVAL,
  116. .gpio = DIR825C1_GPIO_BTN_WPS,
  117. .active_low = 1,
  118. },
  119. };
  120. static struct ar8327_pad_cfg dir825c1_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 dir825c1_ar8327_led_cfg = {
  128. .led_ctrl0 = 0x00000000,
  129. .led_ctrl1 = 0xc737c737,
  130. .led_ctrl2 = 0x00000000,
  131. .led_ctrl3 = 0x00c30c00,
  132. .open_drain = true,
  133. };
  134. static struct ar8327_platform_data dir825c1_ar8327_data = {
  135. .pad0_cfg = &dir825c1_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 = &dir825c1_ar8327_led_cfg,
  144. };
  145. static struct mdio_board_info dir825c1_mdio0_info[] = {
  146. {
  147. .bus_id = "ag71xx-mdio.0",
  148. .phy_addr = 0,
  149. .platform_data = &dir825c1_ar8327_data,
  150. },
  151. };
  152. static void __init dir825c1_generic_setup(void)
  153. {
  154. u8 *mac = (u8 *) KSEG1ADDR(0x1ffe0000);
  155. u8 *art = (u8 *) KSEG1ADDR(0x1fff0000);
  156. u8 mac0[ETH_ALEN], mac1[ETH_ALEN];
  157. u8 wmac0[ETH_ALEN], wmac1[ETH_ALEN];
  158. ath79_parse_ascii_mac(mac + DIR825C1_MAC0_OFFSET, mac0);
  159. ath79_parse_ascii_mac(mac + DIR825C1_MAC1_OFFSET, mac1);
  160. ath79_register_m25p80(NULL);
  161. ath79_register_gpio_keys_polled(-1, DIR825C1_KEYS_POLL_INTERVAL,
  162. ARRAY_SIZE(dir825c1_gpio_keys),
  163. dir825c1_gpio_keys);
  164. ath79_init_mac(wmac0, mac0, 0);
  165. ath79_register_wmac(art + DIR825C1_WMAC_CALDATA_OFFSET, wmac0);
  166. ath79_init_mac(wmac1, mac1, 1);
  167. ap91_pci_init(art + DIR825C1_PCIE_CALDATA_OFFSET, wmac1);
  168. ath79_setup_ar934x_eth_cfg(AR934X_ETH_CFG_RGMII_GMAC0);
  169. mdiobus_register_board_info(dir825c1_mdio0_info,
  170. ARRAY_SIZE(dir825c1_mdio0_info));
  171. ath79_register_mdio(0, 0x0);
  172. ath79_init_mac(ath79_eth0_data.mac_addr, mac0, 0);
  173. /* GMAC0 is connected to an AR8327N switch */
  174. ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  175. ath79_eth0_data.phy_mask = BIT(0);
  176. ath79_eth0_data.mii_bus_dev = &ath79_mdio0_device.dev;
  177. ath79_eth0_pll_data.pll_1000 = 0x06000000;
  178. ath79_register_eth(0);
  179. ath79_register_usb();
  180. }
  181. static void __init dir825c1_setup(void)
  182. {
  183. ath79_gpio_output_select(DIR825C1_GPIO_LED_BLUE_USB,
  184. AR934X_GPIO_OUT_GPIO);
  185. gpio_request_one(DIR825C1_GPIO_WAN_LED_ENABLE,
  186. GPIOF_OUT_INIT_LOW, "WAN LED enable");
  187. ath79_register_leds_gpio(-1, ARRAY_SIZE(dir825c1_leds_gpio),
  188. dir825c1_leds_gpio);
  189. ap9x_pci_setup_wmac_led_pin(0, 0);
  190. dir825c1_generic_setup();
  191. }
  192. static void __init dir835a1_setup(void)
  193. {
  194. dir825c1_ar8327_data.led_cfg = NULL;
  195. ath79_register_leds_gpio(-1, ARRAY_SIZE(dir835a1_leds_gpio),
  196. dir835a1_leds_gpio);
  197. dir825c1_generic_setup();
  198. }
  199. MIPS_MACHINE(ATH79_MACH_DIR_825_C1, "DIR-825-C1",
  200. "D-Link DIR-825 rev. C1",
  201. dir825c1_setup);
  202. MIPS_MACHINE(ATH79_MACH_DIR_835_A1, "DIR-835-A1",
  203. "D-Link DIR-835 rev. A1",
  204. dir835a1_setup);