xhci-mvebu.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2015 Marvell International Ltd.
  4. *
  5. * MVEBU USB HOST xHCI Controller
  6. */
  7. #include <common.h>
  8. #include <dm.h>
  9. #include <fdtdec.h>
  10. #include <usb.h>
  11. #include <power/regulator.h>
  12. #include <asm/gpio.h>
  13. #include <usb/xhci.h>
  14. struct mvebu_xhci_platdata {
  15. fdt_addr_t hcd_base;
  16. };
  17. /**
  18. * Contains pointers to register base addresses
  19. * for the usb controller.
  20. */
  21. struct mvebu_xhci {
  22. struct xhci_ctrl ctrl; /* Needs to come first in this struct! */
  23. struct usb_platdata usb_plat;
  24. struct xhci_hccr *hcd;
  25. };
  26. /*
  27. * Dummy implementation that can be overwritten by a board
  28. * specific function
  29. */
  30. __weak int board_xhci_enable(fdt_addr_t base)
  31. {
  32. return 0;
  33. }
  34. static int xhci_usb_probe(struct udevice *dev)
  35. {
  36. struct mvebu_xhci_platdata *plat = dev_get_platdata(dev);
  37. struct mvebu_xhci *ctx = dev_get_priv(dev);
  38. struct xhci_hcor *hcor;
  39. int len, ret;
  40. struct udevice *regulator;
  41. ctx->hcd = (struct xhci_hccr *)plat->hcd_base;
  42. len = HC_LENGTH(xhci_readl(&ctx->hcd->cr_capbase));
  43. hcor = (struct xhci_hcor *)((uintptr_t)ctx->hcd + len);
  44. ret = device_get_supply_regulator(dev, "vbus-supply", &regulator);
  45. if (!ret) {
  46. ret = regulator_set_enable(regulator, true);
  47. if (ret) {
  48. printf("Failed to turn ON the VBUS regulator\n");
  49. return ret;
  50. }
  51. }
  52. /* Enable USB xHCI (VBUS, reset etc) in board specific code */
  53. board_xhci_enable(devfdt_get_addr_index(dev, 1));
  54. return xhci_register(dev, ctx->hcd, hcor);
  55. }
  56. static int xhci_usb_ofdata_to_platdata(struct udevice *dev)
  57. {
  58. struct mvebu_xhci_platdata *plat = dev_get_platdata(dev);
  59. /*
  60. * Get the base address for XHCI controller from the device node
  61. */
  62. plat->hcd_base = devfdt_get_addr(dev);
  63. if (plat->hcd_base == FDT_ADDR_T_NONE) {
  64. debug("Can't get the XHCI register base address\n");
  65. return -ENXIO;
  66. }
  67. return 0;
  68. }
  69. static const struct udevice_id xhci_usb_ids[] = {
  70. { .compatible = "marvell,armada3700-xhci" },
  71. { .compatible = "marvell,armada-380-xhci" },
  72. { .compatible = "marvell,armada-8k-xhci" },
  73. { }
  74. };
  75. U_BOOT_DRIVER(usb_xhci) = {
  76. .name = "xhci_mvebu",
  77. .id = UCLASS_USB,
  78. .of_match = xhci_usb_ids,
  79. .ofdata_to_platdata = xhci_usb_ofdata_to_platdata,
  80. .probe = xhci_usb_probe,
  81. .remove = xhci_deregister,
  82. .ops = &xhci_usb_ops,
  83. .platdata_auto_alloc_size = sizeof(struct mvebu_xhci_platdata),
  84. .priv_auto_alloc_size = sizeof(struct mvebu_xhci),
  85. .flags = DM_FLAG_ALLOC_PRIV_DMA,
  86. };