xhci-pci.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 "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 0x%x and hcor 0x%x hc_length %d\n",
  23. (u32)hccr, (u32)hcor,
  24. (u32)HC_LENGTH(xhci_readl(&hccr->cr_capbase)));
  25. *ret_hccr = hccr;
  26. *ret_hcor = hcor;
  27. /* enable busmaster */
  28. dm_pci_read_config32(dev, PCI_COMMAND, &cmd);
  29. cmd |= PCI_COMMAND_MASTER;
  30. dm_pci_write_config32(dev, PCI_COMMAND, cmd);
  31. }
  32. static int xhci_pci_probe(struct udevice *dev)
  33. {
  34. struct xhci_hccr *hccr;
  35. struct xhci_hcor *hcor;
  36. xhci_pci_init(dev, &hccr, &hcor);
  37. return xhci_register(dev, hccr, hcor);
  38. }
  39. static const struct udevice_id xhci_pci_ids[] = {
  40. { .compatible = "xhci-pci" },
  41. { }
  42. };
  43. U_BOOT_DRIVER(xhci_pci) = {
  44. .name = "xhci_pci",
  45. .id = UCLASS_USB,
  46. .probe = xhci_pci_probe,
  47. .remove = xhci_deregister,
  48. .of_match = xhci_pci_ids,
  49. .ops = &xhci_usb_ops,
  50. .platdata_auto_alloc_size = sizeof(struct usb_platdata),
  51. .priv_auto_alloc_size = sizeof(struct xhci_ctrl),
  52. .flags = DM_FLAG_ALLOC_PRIV_DMA,
  53. };
  54. static struct pci_device_id xhci_pci_supported[] = {
  55. { PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_XHCI, ~0) },
  56. {},
  57. };
  58. U_BOOT_PCI_DEVICE(xhci_pci, xhci_pci_supported);