xhci-mvebu.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 <asm/gpio.h>
  13. #include "xhci.h"
  14. DECLARE_GLOBAL_DATA_PTR;
  15. struct mvebu_xhci_platdata {
  16. fdt_addr_t hcd_base;
  17. };
  18. /**
  19. * Contains pointers to register base addresses
  20. * for the usb controller.
  21. */
  22. struct mvebu_xhci {
  23. struct xhci_ctrl ctrl; /* Needs to come first in this struct! */
  24. struct usb_platdata usb_plat;
  25. struct xhci_hccr *hcd;
  26. };
  27. /*
  28. * Dummy implementation that can be overwritten by a board
  29. * specific function
  30. */
  31. __weak int board_xhci_enable(void)
  32. {
  33. return 0;
  34. }
  35. static int xhci_usb_probe(struct udevice *dev)
  36. {
  37. struct mvebu_xhci_platdata *plat = dev_get_platdata(dev);
  38. struct mvebu_xhci *ctx = dev_get_priv(dev);
  39. struct xhci_hcor *hcor;
  40. int len;
  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. /* Enable USB xHCI (VBUS, reset etc) in board specific code */
  45. board_xhci_enable();
  46. return xhci_register(dev, ctx->hcd, hcor);
  47. }
  48. static int xhci_usb_ofdata_to_platdata(struct udevice *dev)
  49. {
  50. struct mvebu_xhci_platdata *plat = dev_get_platdata(dev);
  51. /*
  52. * Get the base address for XHCI controller from the device node
  53. */
  54. plat->hcd_base = dev_get_addr(dev);
  55. if (plat->hcd_base == FDT_ADDR_T_NONE) {
  56. debug("Can't get the XHCI register base address\n");
  57. return -ENXIO;
  58. }
  59. return 0;
  60. }
  61. static const struct udevice_id xhci_usb_ids[] = {
  62. { .compatible = "marvell,armada3700-xhci" },
  63. { .compatible = "marvell,armada-8k-xhci" },
  64. { }
  65. };
  66. U_BOOT_DRIVER(usb_xhci) = {
  67. .name = "xhci_mvebu",
  68. .id = UCLASS_USB,
  69. .of_match = xhci_usb_ids,
  70. .ofdata_to_platdata = xhci_usb_ofdata_to_platdata,
  71. .probe = xhci_usb_probe,
  72. .remove = xhci_deregister,
  73. .ops = &xhci_usb_ops,
  74. .platdata_auto_alloc_size = sizeof(struct mvebu_xhci_platdata),
  75. .priv_auto_alloc_size = sizeof(struct mvebu_xhci),
  76. .flags = DM_FLAG_ALLOC_PRIV_DMA,
  77. };