xhci-fsl.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. /*
  2. * Copyright 2015,2016 Freescale Semiconductor, Inc.
  3. *
  4. * FSL USB HOST xHCI Controller
  5. *
  6. * Author: Ramneek Mehresh<ramneek.mehresh@freescale.com>
  7. *
  8. * SPDX-License-Identifier: GPL-2.0+
  9. */
  10. #include <common.h>
  11. #include <usb.h>
  12. #include <linux/errno.h>
  13. #include <linux/compat.h>
  14. #include <linux/usb/xhci-fsl.h>
  15. #include <linux/usb/dwc3.h>
  16. #include "xhci.h"
  17. #include <fsl_errata.h>
  18. #include <fsl_usb.h>
  19. #include <dm.h>
  20. /* Declare global data pointer */
  21. DECLARE_GLOBAL_DATA_PTR;
  22. #ifndef CONFIG_DM_USB
  23. static struct fsl_xhci fsl_xhci;
  24. unsigned long ctr_addr[] = FSL_USB_XHCI_ADDR;
  25. #else
  26. struct xhci_fsl_priv {
  27. struct xhci_ctrl xhci;
  28. fdt_addr_t hcd_base;
  29. struct fsl_xhci ctx;
  30. };
  31. #endif
  32. __weak int __board_usb_init(int index, enum usb_init_type init)
  33. {
  34. return 0;
  35. }
  36. static int erratum_a008751(void)
  37. {
  38. #if defined(CONFIG_TARGET_LS2080AQDS) || defined(CONFIG_TARGET_LS2080ARDB)
  39. u32 __iomem *scfg = (u32 __iomem *)SCFG_BASE;
  40. writel(SCFG_USB3PRM1CR_INIT, scfg + SCFG_USB3PRM1CR / 4);
  41. return 0;
  42. #endif
  43. return 1;
  44. }
  45. static void fsl_apply_xhci_errata(void)
  46. {
  47. int ret;
  48. if (has_erratum_a008751()) {
  49. ret = erratum_a008751();
  50. if (ret != 0)
  51. puts("Failed to apply erratum a008751\n");
  52. }
  53. }
  54. static void fsl_xhci_set_beat_burst_length(struct dwc3 *dwc3_reg)
  55. {
  56. clrsetbits_le32(&dwc3_reg->g_sbuscfg0, USB3_ENABLE_BEAT_BURST_MASK,
  57. USB3_ENABLE_BEAT_BURST);
  58. setbits_le32(&dwc3_reg->g_sbuscfg1, USB3_SET_BEAT_BURST_LIMIT);
  59. }
  60. static int fsl_xhci_core_init(struct fsl_xhci *fsl_xhci)
  61. {
  62. int ret = 0;
  63. ret = dwc3_core_init(fsl_xhci->dwc3_reg);
  64. if (ret) {
  65. debug("%s:failed to initialize core\n", __func__);
  66. return ret;
  67. }
  68. /* We are hard-coding DWC3 core to Host Mode */
  69. dwc3_set_mode(fsl_xhci->dwc3_reg, DWC3_GCTL_PRTCAP_HOST);
  70. /* Set GFLADJ_30MHZ as 20h as per XHCI spec default value */
  71. dwc3_set_fladj(fsl_xhci->dwc3_reg, GFLADJ_30MHZ_DEFAULT);
  72. /* Change beat burst and outstanding pipelined transfers requests */
  73. fsl_xhci_set_beat_burst_length(fsl_xhci->dwc3_reg);
  74. /*
  75. * A-010151: The dwc3 phy TSMC 28-nm HPM 0.9/1.8 V does not
  76. * reliably support Rx Detect in P3 mode(P3 is the default
  77. * setting). Therefore, some USB3.0 devices may not be detected
  78. * reliably in Super Speed mode. So, USB controller to configure
  79. * USB in P2 mode whenever the Receive Detect feature is required.
  80. * whenever the Receive Detect feature is required.
  81. */
  82. if (has_erratum_a010151())
  83. clrsetbits_le32(&fsl_xhci->dwc3_reg->g_usb3pipectl[0],
  84. DWC3_GUSB3PIPECTL_DISRXDETP3,
  85. DWC3_GUSB3PIPECTL_DISRXDETP3);
  86. return ret;
  87. }
  88. static int fsl_xhci_core_exit(struct fsl_xhci *fsl_xhci)
  89. {
  90. /*
  91. * Currently fsl socs do not support PHY shutdown from
  92. * sw. But this support may be added in future socs.
  93. */
  94. return 0;
  95. }
  96. #ifdef CONFIG_DM_USB
  97. static int xhci_fsl_probe(struct udevice *dev)
  98. {
  99. struct xhci_fsl_priv *priv = dev_get_priv(dev);
  100. struct xhci_hccr *hccr;
  101. struct xhci_hcor *hcor;
  102. int ret = 0;
  103. /*
  104. * Get the base address for XHCI controller from the device node
  105. */
  106. priv->hcd_base = dev_get_addr(dev);
  107. if (priv->hcd_base == FDT_ADDR_T_NONE) {
  108. debug("Can't get the XHCI register base address\n");
  109. return -ENXIO;
  110. }
  111. priv->ctx.hcd = (struct xhci_hccr *)priv->hcd_base;
  112. priv->ctx.dwc3_reg = (struct dwc3 *)((char *)(priv->hcd_base) +
  113. DWC3_REG_OFFSET);
  114. fsl_apply_xhci_errata();
  115. ret = fsl_xhci_core_init(&priv->ctx);
  116. if (ret < 0) {
  117. puts("Failed to initialize xhci\n");
  118. return ret;
  119. }
  120. hccr = (struct xhci_hccr *)(priv->ctx.hcd);
  121. hcor = (struct xhci_hcor *)((uintptr_t) hccr
  122. + HC_LENGTH(xhci_readl(&hccr->cr_capbase)));
  123. debug("xhci-fsl: init hccr %lx and hcor %lx hc_length %lx\n",
  124. (uintptr_t)hccr, (uintptr_t)hcor,
  125. (uintptr_t)HC_LENGTH(xhci_readl(&hccr->cr_capbase)));
  126. return xhci_register(dev, hccr, hcor);
  127. }
  128. static int xhci_fsl_remove(struct udevice *dev)
  129. {
  130. struct xhci_fsl_priv *priv = dev_get_priv(dev);
  131. fsl_xhci_core_exit(&priv->ctx);
  132. return xhci_deregister(dev);
  133. }
  134. static const struct udevice_id xhci_usb_ids[] = {
  135. { .compatible = "fsl,layerscape-dwc3", },
  136. { }
  137. };
  138. U_BOOT_DRIVER(xhci_fsl) = {
  139. .name = "xhci_fsl",
  140. .id = UCLASS_USB,
  141. .of_match = xhci_usb_ids,
  142. .probe = xhci_fsl_probe,
  143. .remove = xhci_fsl_remove,
  144. .ops = &xhci_usb_ops,
  145. .platdata_auto_alloc_size = sizeof(struct usb_platdata),
  146. .priv_auto_alloc_size = sizeof(struct xhci_fsl_priv),
  147. .flags = DM_FLAG_ALLOC_PRIV_DMA,
  148. };
  149. #else
  150. int xhci_hcd_init(int index, struct xhci_hccr **hccr, struct xhci_hcor **hcor)
  151. {
  152. struct fsl_xhci *ctx = &fsl_xhci;
  153. int ret = 0;
  154. ctx->hcd = (struct xhci_hccr *)ctr_addr[index];
  155. ctx->dwc3_reg = (struct dwc3 *)((char *)(ctx->hcd) + DWC3_REG_OFFSET);
  156. ret = board_usb_init(index, USB_INIT_HOST);
  157. if (ret != 0) {
  158. puts("Failed to initialize board for USB\n");
  159. return ret;
  160. }
  161. fsl_apply_xhci_errata();
  162. ret = fsl_xhci_core_init(ctx);
  163. if (ret < 0) {
  164. puts("Failed to initialize xhci\n");
  165. return ret;
  166. }
  167. *hccr = (struct xhci_hccr *)ctx->hcd;
  168. *hcor = (struct xhci_hcor *)((uintptr_t) *hccr
  169. + HC_LENGTH(xhci_readl(&(*hccr)->cr_capbase)));
  170. debug("fsl-xhci: init hccr %lx and hcor %lx hc_length %lx\n",
  171. (uintptr_t)*hccr, (uintptr_t)*hcor,
  172. (uintptr_t)HC_LENGTH(xhci_readl(&(*hccr)->cr_capbase)));
  173. return ret;
  174. }
  175. void xhci_hcd_stop(int index)
  176. {
  177. struct fsl_xhci *ctx = &fsl_xhci;
  178. fsl_xhci_core_exit(ctx);
  179. }
  180. #endif