mach-nbg6716.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. /*
  2. * ZyXEL NBG6716 board support
  3. *
  4. * Based on the Qualcomm Atheros AP135/AP136 reference board support code
  5. * Copyright (c) 2012 Qualcomm Atheros
  6. * Copyright (c) 2012-2013 Gabor Juhos <juhosg@openwrt.org>
  7. * Copyright (c) 2013 Andre Valentin <avalentin@marcant.net>
  8. *
  9. * Permission to use, copy, modify, and/or distribute this software for any
  10. * purpose with or without fee is hereby granted, provided that the above
  11. * copyright notice and this permission notice appear in all copies.
  12. *
  13. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  14. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  15. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  16. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  17. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  18. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  19. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  20. *
  21. */
  22. #include <linux/platform_device.h>
  23. #include <linux/ar8216_platform.h>
  24. #include <linux/gpio.h>
  25. #include <linux/mtd/mtd.h>
  26. #include <linux/mtd/nand.h>
  27. #include <linux/platform/ar934x_nfc.h>
  28. #include <asm/mach-ath79/ar71xx_regs.h>
  29. #include "common.h"
  30. #include "pci.h"
  31. #include "dev-ap9x-pci.h"
  32. #include "dev-gpio-buttons.h"
  33. #include "dev-eth.h"
  34. #include "dev-leds-gpio.h"
  35. #include "dev-nfc.h"
  36. #include "dev-m25p80.h"
  37. #include "dev-usb.h"
  38. #include "dev-wmac.h"
  39. #include "machtypes.h"
  40. #include "nvram.h"
  41. #define NBG6716_GPIO_LED_INTERNET 18
  42. #define NBG6716_GPIO_LED_POWER 15
  43. #define NBG6716_GPIO_LED_USB1 4
  44. #define NBG6716_GPIO_LED_USB2 13
  45. #define NBG6716_GPIO_LED_WIFI2G 19
  46. #define NBG6716_GPIO_LED_WIFI5G 17
  47. #define NBG6716_GPIO_LED_WPS 21
  48. #define NBG6716_GPIO_BTN_RESET 23
  49. #define NBG6716_GPIO_BTN_RFKILL 1
  50. #define NBG6716_GPIO_BTN_USB1 0
  51. #define NBG6716_GPIO_BTN_USB2 14
  52. #define NBG6716_GPIO_BTN_WPS 22
  53. #define NBG6716_GPIO_USB_POWER 16
  54. #define NBG6716_KEYS_POLL_INTERVAL 20 /* msecs */
  55. #define NBG6716_KEYS_DEBOUNCE_INTERVAL (3 * NBG6716_KEYS_POLL_INTERVAL)
  56. #define NBG6716_MAC0_OFFSET 0
  57. #define NBG6716_MAC1_OFFSET 6
  58. #define NBG6716_WMAC_CALDATA_OFFSET 0x1000
  59. #define NBG6716_PCIE_CALDATA_OFFSET 0x5000
  60. static struct gpio_led nbg6716_leds_gpio[] __initdata = {
  61. {
  62. .name = "zyxel:white:internet",
  63. .gpio = NBG6716_GPIO_LED_INTERNET,
  64. .active_low = 1,
  65. },
  66. {
  67. .name = "zyxel:white:power",
  68. .gpio = NBG6716_GPIO_LED_POWER,
  69. .active_low = 1,
  70. },
  71. {
  72. .name = "zyxel:white:usb1",
  73. .gpio = NBG6716_GPIO_LED_USB1,
  74. .active_low = 1,
  75. },
  76. {
  77. .name = "zyxel:white:usb2",
  78. .gpio = NBG6716_GPIO_LED_USB2,
  79. .active_low = 1,
  80. },
  81. {
  82. .name = "zyxel:white:wifi2g",
  83. .gpio = NBG6716_GPIO_LED_WIFI2G,
  84. .active_low = 1,
  85. },
  86. {
  87. .name = "zyxel:white:wifi5g",
  88. .gpio = NBG6716_GPIO_LED_WIFI5G,
  89. .active_low = 1,
  90. },
  91. {
  92. .name = "zyxel:white:wps",
  93. .gpio = NBG6716_GPIO_LED_WPS,
  94. .active_low = 1,
  95. }
  96. };
  97. static struct gpio_keys_button nbg6716_gpio_keys[] __initdata = {
  98. {
  99. .desc = "RESET button",
  100. .type = EV_KEY,
  101. .code = KEY_RESTART,
  102. .debounce_interval = NBG6716_KEYS_DEBOUNCE_INTERVAL,
  103. .gpio = NBG6716_GPIO_BTN_RESET,
  104. .active_low = 1,
  105. },
  106. {
  107. .desc = "RFKILL button",
  108. .type = EV_SW,
  109. .code = KEY_RFKILL,
  110. .debounce_interval = NBG6716_KEYS_DEBOUNCE_INTERVAL,
  111. .gpio = NBG6716_GPIO_BTN_RFKILL,
  112. .active_low = 0,
  113. },
  114. {
  115. .desc = "USB1 eject button",
  116. .type = EV_KEY,
  117. .code = BTN_1,
  118. .debounce_interval = NBG6716_KEYS_DEBOUNCE_INTERVAL,
  119. .gpio = NBG6716_GPIO_BTN_USB1,
  120. .active_low = 1,
  121. },
  122. {
  123. .desc = "USB2 eject button",
  124. .type = EV_KEY,
  125. .code = BTN_2,
  126. .debounce_interval = NBG6716_KEYS_DEBOUNCE_INTERVAL,
  127. .gpio = NBG6716_GPIO_BTN_USB2,
  128. .active_low = 1,
  129. },
  130. {
  131. .desc = "WPS button",
  132. .type = EV_KEY,
  133. .code = KEY_WPS_BUTTON,
  134. .debounce_interval = NBG6716_KEYS_DEBOUNCE_INTERVAL,
  135. .gpio = NBG6716_GPIO_BTN_WPS,
  136. .active_low = 1,
  137. },
  138. };
  139. static struct ar8327_pad_cfg nbg6716_ar8327_pad0_cfg;
  140. static struct ar8327_pad_cfg nbg6716_ar8327_pad6_cfg;
  141. static struct ar8327_led_cfg nbg6716_ar8327_led_cfg;
  142. static struct ar8327_platform_data nbg6716_ar8327_data = {
  143. .pad0_cfg = &nbg6716_ar8327_pad0_cfg,
  144. .pad6_cfg = &nbg6716_ar8327_pad6_cfg,
  145. .port0_cfg = {
  146. .force_link = 1,
  147. .speed = AR8327_PORT_SPEED_1000,
  148. .duplex = 1,
  149. .txpause = 1,
  150. .rxpause = 1,
  151. },
  152. .port6_cfg = {
  153. .force_link = 1,
  154. .speed = AR8327_PORT_SPEED_1000,
  155. .duplex = 1,
  156. .txpause = 1,
  157. .rxpause = 1,
  158. },
  159. .led_cfg = &nbg6716_ar8327_led_cfg
  160. };
  161. static struct mdio_board_info nbg6716_mdio0_info[] = {
  162. {
  163. .bus_id = "ag71xx-mdio.0",
  164. .phy_addr = 0,
  165. .platform_data = &nbg6716_ar8327_data,
  166. },
  167. };
  168. static void nbg6716_get_mac(const char *name, char *mac)
  169. {
  170. u8 *nvram = (u8 *) KSEG1ADDR(0x1f040000);
  171. int err;
  172. err = ath79_nvram_parse_mac_addr(nvram, 0x10000,
  173. name, mac);
  174. if (err)
  175. pr_err("no MAC address found for %s\n", name);
  176. }
  177. static void __init nbg6716_common_setup(void)
  178. {
  179. u8 *art = (u8 *) KSEG1ADDR(0x1f050000);
  180. u8 tmpmac[ETH_ALEN];
  181. ath79_register_m25p80(NULL);
  182. ath79_register_leds_gpio(-1, ARRAY_SIZE(nbg6716_leds_gpio),
  183. nbg6716_leds_gpio);
  184. ath79_register_gpio_keys_polled(-1, NBG6716_KEYS_POLL_INTERVAL,
  185. ARRAY_SIZE(nbg6716_gpio_keys),
  186. nbg6716_gpio_keys);
  187. ath79_nfc_set_ecc_mode(AR934X_NFC_ECC_HW);
  188. ath79_register_nfc();
  189. gpio_request_one(NBG6716_GPIO_USB_POWER,
  190. GPIOF_OUT_INIT_HIGH | GPIOF_EXPORT_DIR_FIXED,
  191. "USB power");
  192. ath79_register_usb();
  193. nbg6716_get_mac("ethaddr=", tmpmac);
  194. ath79_register_pci();
  195. ath79_register_wmac(art + NBG6716_WMAC_CALDATA_OFFSET, tmpmac);
  196. ath79_setup_qca955x_eth_cfg(QCA955X_ETH_CFG_RGMII_EN);
  197. ath79_register_mdio(0, 0x0);
  198. ath79_init_mac(ath79_eth0_data.mac_addr, tmpmac, 2);
  199. ath79_init_mac(ath79_eth1_data.mac_addr, tmpmac, 3);
  200. mdiobus_register_board_info(nbg6716_mdio0_info,
  201. ARRAY_SIZE(nbg6716_mdio0_info));
  202. /* GMAC0 is connected to the RMGII interface */
  203. ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  204. ath79_eth0_data.phy_mask = BIT(0);
  205. ath79_eth0_data.mii_bus_dev = &ath79_mdio0_device.dev;
  206. ath79_register_eth(0);
  207. /* GMAC1 is connected to the SGMII interface */
  208. ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_SGMII;
  209. ath79_eth1_data.speed = SPEED_1000;
  210. ath79_eth1_data.duplex = DUPLEX_FULL;
  211. ath79_register_eth(1);
  212. }
  213. static void __init nbg6716_010_setup(void)
  214. {
  215. /* GMAC0 of the AR8337 switch is connected to GMAC0 via RGMII */
  216. nbg6716_ar8327_pad0_cfg.mode = AR8327_PAD_MAC_RGMII;
  217. nbg6716_ar8327_pad0_cfg.txclk_delay_en = true;
  218. nbg6716_ar8327_pad0_cfg.rxclk_delay_en = true;
  219. nbg6716_ar8327_pad0_cfg.txclk_delay_sel = AR8327_CLK_DELAY_SEL1;
  220. nbg6716_ar8327_pad0_cfg.rxclk_delay_sel = AR8327_CLK_DELAY_SEL2;
  221. nbg6716_ar8327_pad0_cfg.mac06_exchange_en = true;
  222. /* GMAC6 of the AR8337 switch is connected to GMAC1 via SGMII */
  223. nbg6716_ar8327_pad6_cfg.mode = AR8327_PAD_MAC_SGMII;
  224. nbg6716_ar8327_pad6_cfg.rxclk_delay_en = true;
  225. nbg6716_ar8327_pad6_cfg.rxclk_delay_sel = AR8327_CLK_DELAY_SEL0;
  226. ath79_eth0_pll_data.pll_1000 = 0xa6000000;
  227. ath79_eth1_pll_data.pll_1000 = 0x03000101;
  228. nbg6716_ar8327_led_cfg.open_drain = 0;
  229. nbg6716_ar8327_led_cfg.led_ctrl0 = 0xffb7ffb7;
  230. nbg6716_ar8327_led_cfg.led_ctrl1 = 0xffb7ffb7;
  231. nbg6716_ar8327_led_cfg.led_ctrl2 = 0xffb7ffb7;
  232. nbg6716_ar8327_led_cfg.led_ctrl3 = 0x03ffff00;
  233. nbg6716_common_setup();
  234. }
  235. MIPS_MACHINE(ATH79_MACH_NBG6716, "NBG6716",
  236. "Zyxel NBG6716",
  237. nbg6716_010_setup);