ehci-zynq.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 <dm.h>
  10. #include <usb.h>
  11. #include <asm/arch/hardware.h>
  12. #include <asm/arch/sys_proto.h>
  13. #include <asm/io.h>
  14. #include <usb/ehci-ci.h>
  15. #include <usb/ulpi.h>
  16. #include "ehci.h"
  17. struct zynq_ehci_priv {
  18. struct ehci_ctrl ehcictrl;
  19. struct usb_ehci *ehci;
  20. };
  21. static int ehci_zynq_ofdata_to_platdata(struct udevice *dev)
  22. {
  23. struct zynq_ehci_priv *priv = dev_get_priv(dev);
  24. priv->ehci = (struct usb_ehci *)dev_get_addr_ptr(dev);
  25. if (!priv->ehci)
  26. return -EINVAL;
  27. return 0;
  28. }
  29. static int ehci_zynq_probe(struct udevice *dev)
  30. {
  31. struct usb_platdata *plat = dev_get_platdata(dev);
  32. struct zynq_ehci_priv *priv = dev_get_priv(dev);
  33. struct ehci_hccr *hccr;
  34. struct ehci_hcor *hcor;
  35. struct ulpi_viewport ulpi_vp;
  36. /* Used for writing the ULPI data address */
  37. struct ulpi_regs *ulpi = (struct ulpi_regs *)0;
  38. int ret;
  39. hccr = (struct ehci_hccr *)((uint32_t)&priv->ehci->caplength);
  40. hcor = (struct ehci_hcor *)((uint32_t) hccr +
  41. HC_LENGTH(ehci_readl(&hccr->cr_capbase)));
  42. ulpi_vp.viewport_addr = (u32)&priv->ehci->ulpi_viewpoint;
  43. ulpi_vp.port_num = 0;
  44. ret = ulpi_init(&ulpi_vp);
  45. if (ret) {
  46. puts("zynq ULPI viewport init failed\n");
  47. return -1;
  48. }
  49. /* ULPI set flags */
  50. ulpi_write(&ulpi_vp, &ulpi->otg_ctrl,
  51. ULPI_OTG_DP_PULLDOWN | ULPI_OTG_DM_PULLDOWN |
  52. ULPI_OTG_EXTVBUSIND);
  53. ulpi_write(&ulpi_vp, &ulpi->function_ctrl,
  54. ULPI_FC_FULL_SPEED | ULPI_FC_OPMODE_NORMAL |
  55. ULPI_FC_SUSPENDM);
  56. ulpi_write(&ulpi_vp, &ulpi->iface_ctrl, 0);
  57. /* Set VBus */
  58. ulpi_write(&ulpi_vp, &ulpi->otg_ctrl_set,
  59. ULPI_OTG_DRVVBUS | ULPI_OTG_DRVVBUS_EXT);
  60. return ehci_register(dev, hccr, hcor, NULL, 0, plat->init_type);
  61. }
  62. static const struct udevice_id ehci_zynq_ids[] = {
  63. { .compatible = "xlnx,zynq-usb-2.20a" },
  64. { }
  65. };
  66. U_BOOT_DRIVER(ehci_zynq) = {
  67. .name = "ehci_zynq",
  68. .id = UCLASS_USB,
  69. .of_match = ehci_zynq_ids,
  70. .ofdata_to_platdata = ehci_zynq_ofdata_to_platdata,
  71. .probe = ehci_zynq_probe,
  72. .remove = ehci_deregister,
  73. .ops = &ehci_usb_ops,
  74. .platdata_auto_alloc_size = sizeof(struct usb_platdata),
  75. .priv_auto_alloc_size = sizeof(struct zynq_ehci_priv),
  76. .flags = DM_FLAG_ALLOC_PRIV_DMA,
  77. };