ehci-zynq.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * (C) Copyright 2014, Xilinx, Inc
  3. *
  4. * USB Low level initialization(Specific to zynq)
  5. *
  6. * SPDX-License-Identifier: GPL-2.0+
  7. */
  8. #include <common.h>
  9. #include <asm/arch/hardware.h>
  10. #include <asm/arch/sys_proto.h>
  11. #include <asm/io.h>
  12. #include <usb.h>
  13. #include <usb/ehci-fsl.h>
  14. #include <usb/ulpi.h>
  15. #include "ehci.h"
  16. #define ZYNQ_USB_USBCMD_RST 0x0000002
  17. #define ZYNQ_USB_USBCMD_STOP 0x0000000
  18. #define ZYNQ_USB_NUM_MIO 12
  19. /*
  20. * Create the appropriate control structures to manage
  21. * a new EHCI host controller.
  22. */
  23. int ehci_hcd_init(int index, enum usb_init_type init, struct ehci_hccr **hccr,
  24. struct ehci_hcor **hcor)
  25. {
  26. struct usb_ehci *ehci;
  27. struct ulpi_viewport ulpi_vp;
  28. int ret, mio_usb;
  29. /* Used for writing the ULPI data address */
  30. struct ulpi_regs *ulpi = (struct ulpi_regs *)0;
  31. if (!index) {
  32. mio_usb = zynq_slcr_get_mio_pin_status("usb0");
  33. if (mio_usb != ZYNQ_USB_NUM_MIO) {
  34. printf("usb0 wrong num MIO: %d, Index %d\n", mio_usb,
  35. index);
  36. return -1;
  37. }
  38. ehci = (struct usb_ehci *)ZYNQ_USB_BASEADDR0;
  39. } else {
  40. mio_usb = zynq_slcr_get_mio_pin_status("usb1");
  41. if (mio_usb != ZYNQ_USB_NUM_MIO) {
  42. printf("usb1 wrong num MIO: %d, Index %d\n", mio_usb,
  43. index);
  44. return -1;
  45. }
  46. ehci = (struct usb_ehci *)ZYNQ_USB_BASEADDR1;
  47. }
  48. *hccr = (struct ehci_hccr *)((uint32_t)&ehci->caplength);
  49. *hcor = (struct ehci_hcor *)((uint32_t) *hccr +
  50. HC_LENGTH(ehci_readl(&(*hccr)->cr_capbase)));
  51. ulpi_vp.viewport_addr = (u32)&ehci->ulpi_viewpoint;
  52. ulpi_vp.port_num = 0;
  53. ret = ulpi_init(&ulpi_vp);
  54. if (ret) {
  55. puts("zynq ULPI viewport init failed\n");
  56. return -1;
  57. }
  58. /* ULPI set flags */
  59. ulpi_write(&ulpi_vp, &ulpi->otg_ctrl,
  60. ULPI_OTG_DP_PULLDOWN | ULPI_OTG_DM_PULLDOWN |
  61. ULPI_OTG_EXTVBUSIND);
  62. ulpi_write(&ulpi_vp, &ulpi->function_ctrl,
  63. ULPI_FC_FULL_SPEED | ULPI_FC_OPMODE_NORMAL |
  64. ULPI_FC_SUSPENDM);
  65. ulpi_write(&ulpi_vp, &ulpi->iface_ctrl, 0);
  66. /* Set VBus */
  67. ulpi_write(&ulpi_vp, &ulpi->otg_ctrl_set,
  68. ULPI_OTG_DRVVBUS | ULPI_OTG_DRVVBUS_EXT);
  69. return 0;
  70. }
  71. /*
  72. * Destroy the appropriate control structures corresponding
  73. * the the EHCI host controller.
  74. */
  75. int ehci_hcd_stop(int index)
  76. {
  77. struct usb_ehci *ehci;
  78. if (!index)
  79. ehci = (struct usb_ehci *)ZYNQ_USB_BASEADDR0;
  80. else
  81. ehci = (struct usb_ehci *)ZYNQ_USB_BASEADDR1;
  82. /* Stop controller */
  83. writel(ZYNQ_USB_USBCMD_STOP, &ehci->usbcmd);
  84. udelay(1000);
  85. /* Initiate controller reset */
  86. writel(ZYNQ_USB_USBCMD_RST, &ehci->usbcmd);
  87. return 0;
  88. }