xhci-mvebu.c 2.4 KB

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