ehci-zynq.c 2.2 KB

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