xhci-omap.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * OMAP USB HOST xHCI Controller
  3. *
  4. * (C) Copyright 2013
  5. * Texas Instruments, <www.ti.com>
  6. *
  7. * Author: Dan Murphy <dmurphy@ti.com>
  8. *
  9. * SPDX-License-Identifier: GPL-2.0+
  10. */
  11. #include <common.h>
  12. #include <usb.h>
  13. #include <linux/errno.h>
  14. #include <asm/omap_common.h>
  15. #include <asm/arch/cpu.h>
  16. #include <asm/arch/sys_proto.h>
  17. #include <linux/compat.h>
  18. #include <linux/usb/dwc3.h>
  19. #include <linux/usb/xhci-omap.h>
  20. #include "xhci.h"
  21. /* Declare global data pointer */
  22. DECLARE_GLOBAL_DATA_PTR;
  23. static struct omap_xhci omap;
  24. __weak int __board_usb_init(int index, enum usb_init_type init)
  25. {
  26. return 0;
  27. }
  28. int board_usb_init(int index, enum usb_init_type init)
  29. __attribute__((weak, alias("__board_usb_init")));
  30. static int omap_xhci_core_init(struct omap_xhci *omap)
  31. {
  32. int ret = 0;
  33. usb_phy_power(1);
  34. omap_enable_phy(omap);
  35. ret = dwc3_core_init(omap->dwc3_reg);
  36. if (ret) {
  37. debug("%s:failed to initialize core\n", __func__);
  38. return ret;
  39. }
  40. /* We are hard-coding DWC3 core to Host Mode */
  41. dwc3_set_mode(omap->dwc3_reg, DWC3_GCTL_PRTCAP_HOST);
  42. return ret;
  43. }
  44. static void omap_xhci_core_exit(struct omap_xhci *omap)
  45. {
  46. usb_phy_power(0);
  47. }
  48. int xhci_hcd_init(int index, struct xhci_hccr **hccr, struct xhci_hcor **hcor)
  49. {
  50. struct omap_xhci *ctx = &omap;
  51. int ret = 0;
  52. ctx->hcd = (struct xhci_hccr *)OMAP_XHCI_BASE;
  53. ctx->dwc3_reg = (struct dwc3 *)((char *)(ctx->hcd) + DWC3_REG_OFFSET);
  54. ctx->usb3_phy = (struct omap_usb3_phy *)OMAP_OCP1_SCP_BASE;
  55. ctx->otg_wrapper = (struct omap_dwc_wrapper *)OMAP_OTG_WRAPPER_BASE;
  56. ret = board_usb_init(index, USB_INIT_HOST);
  57. if (ret != 0) {
  58. puts("Failed to initialize board for USB\n");
  59. return ret;
  60. }
  61. ret = omap_xhci_core_init(ctx);
  62. if (ret < 0) {
  63. puts("Failed to initialize xhci\n");
  64. return ret;
  65. }
  66. *hccr = (struct xhci_hccr *)(OMAP_XHCI_BASE);
  67. *hcor = (struct xhci_hcor *)((uint32_t) *hccr
  68. + HC_LENGTH(xhci_readl(&(*hccr)->cr_capbase)));
  69. debug("omap-xhci: init hccr %x and hcor %x hc_length %d\n",
  70. (uint32_t)*hccr, (uint32_t)*hcor,
  71. (uint32_t)HC_LENGTH(xhci_readl(&(*hccr)->cr_capbase)));
  72. return ret;
  73. }
  74. void xhci_hcd_stop(int index)
  75. {
  76. struct omap_xhci *ctx = &omap;
  77. omap_xhci_core_exit(ctx);
  78. board_usb_cleanup(index, USB_INIT_HOST);
  79. }