xhci-pci.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (c) 2015, Google, Inc
  4. * Written by Simon Glass <sjg@chromium.org>
  5. * All rights reserved.
  6. */
  7. #include <common.h>
  8. #include <dm.h>
  9. #include <pci.h>
  10. #include <usb.h>
  11. #include <usb/xhci.h>
  12. static void xhci_pci_init(struct udevice *dev, struct xhci_hccr **ret_hccr,
  13. struct xhci_hcor **ret_hcor)
  14. {
  15. struct xhci_hccr *hccr;
  16. struct xhci_hcor *hcor;
  17. u32 cmd;
  18. hccr = (struct xhci_hccr *)dm_pci_map_bar(dev,
  19. PCI_BASE_ADDRESS_0, PCI_REGION_MEM);
  20. hcor = (struct xhci_hcor *)((uintptr_t) hccr +
  21. HC_LENGTH(xhci_readl(&hccr->cr_capbase)));
  22. debug("XHCI-PCI init hccr %p and hcor %p hc_length %d\n",
  23. hccr, hcor, (u32)HC_LENGTH(xhci_readl(&hccr->cr_capbase)));
  24. *ret_hccr = hccr;
  25. *ret_hcor = hcor;
  26. /* enable busmaster */
  27. dm_pci_read_config32(dev, PCI_COMMAND, &cmd);
  28. cmd |= PCI_COMMAND_MASTER;
  29. dm_pci_write_config32(dev, PCI_COMMAND, cmd);
  30. }
  31. static int xhci_pci_probe(struct udevice *dev)
  32. {
  33. struct xhci_hccr *hccr;
  34. struct xhci_hcor *hcor;
  35. xhci_pci_init(dev, &hccr, &hcor);
  36. return xhci_register(dev, hccr, hcor);
  37. }
  38. static const struct udevice_id xhci_pci_ids[] = {
  39. { .compatible = "xhci-pci" },
  40. { }
  41. };
  42. U_BOOT_DRIVER(xhci_pci) = {
  43. .name = "xhci_pci",
  44. .id = UCLASS_USB,
  45. .probe = xhci_pci_probe,
  46. .remove = xhci_deregister,
  47. .of_match = xhci_pci_ids,
  48. .ops = &xhci_usb_ops,
  49. .platdata_auto_alloc_size = sizeof(struct usb_platdata),
  50. .priv_auto_alloc_size = sizeof(struct xhci_ctrl),
  51. .flags = DM_FLAG_ALLOC_PRIV_DMA,
  52. };
  53. static struct pci_device_id xhci_pci_supported[] = {
  54. { PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_XHCI, ~0) },
  55. {},
  56. };
  57. U_BOOT_PCI_DEVICE(xhci_pci, xhci_pci_supported);