2 * Copyright (c) 2015, Google, Inc
3 * Written by Simon Glass <sjg@chromium.org>
6 * SPDX-License-Identifier: GPL-2.0
20 * Create the appropriate control structures to manage a new XHCI host
23 int xhci_hcd_init(int index, struct xhci_hccr **ret_hccr,
24 struct xhci_hcor **ret_hcor)
26 struct xhci_hccr *hccr;
27 struct xhci_hcor *hcor;
32 pdev = pci_find_class(PCI_CLASS_SERIAL_USB_XHCI, index);
34 printf("XHCI host controller not found\n");
38 hccr = (struct xhci_hccr *)pci_map_bar(pdev,
39 PCI_BASE_ADDRESS_0, PCI_REGION_MEM);
40 len = HC_LENGTH(xhci_readl(&hccr->cr_capbase));
41 hcor = (struct xhci_hcor *)((uint32_t)hccr + len);
43 debug("XHCI-PCI init hccr 0x%x and hcor 0x%x hc_length %d\n",
44 (uint32_t)hccr, (uint32_t)hcor, len);
49 /* enable busmaster */
50 pci_read_config_dword(pdev, PCI_COMMAND, &cmd);
51 cmd |= PCI_COMMAND_MASTER;
52 pci_write_config_dword(pdev, PCI_COMMAND, cmd);
58 * Destroy the appropriate control structures corresponding * to the XHCI host
61 void xhci_hcd_stop(int index)
67 struct xhci_pci_priv {
68 struct xhci_ctrl ctrl; /* Needs to come first in this struct! */
71 static void xhci_pci_init(struct udevice *dev, struct xhci_hccr **ret_hccr,
72 struct xhci_hcor **ret_hcor)
74 struct xhci_hccr *hccr;
75 struct xhci_hcor *hcor;
78 hccr = (struct xhci_hccr *)dm_pci_map_bar(dev,
79 PCI_BASE_ADDRESS_0, PCI_REGION_MEM);
80 hcor = (struct xhci_hcor *)((uintptr_t) hccr +
81 HC_LENGTH(xhci_readl(&hccr->cr_capbase)));
83 debug("XHCI-PCI init hccr 0x%x and hcor 0x%x hc_length %d\n",
85 (u32)HC_LENGTH(xhci_readl(&hccr->cr_capbase)));
90 /* enable busmaster */
91 dm_pci_read_config32(dev, PCI_COMMAND, &cmd);
92 cmd |= PCI_COMMAND_MASTER;
93 dm_pci_write_config32(dev, PCI_COMMAND, cmd);
96 static int xhci_pci_probe(struct udevice *dev)
98 struct xhci_hccr *hccr;
99 struct xhci_hcor *hcor;
101 xhci_pci_init(dev, &hccr, &hcor);
103 return xhci_register(dev, hccr, hcor);
106 static int xhci_pci_remove(struct udevice *dev)
110 ret = xhci_deregister(dev);
117 static const struct udevice_id xhci_pci_ids[] = {
118 { .compatible = "xhci-pci" },
122 U_BOOT_DRIVER(xhci_pci) = {
125 .probe = xhci_pci_probe,
126 .remove = xhci_pci_remove,
127 .of_match = xhci_pci_ids,
128 .ops = &xhci_usb_ops,
129 .platdata_auto_alloc_size = sizeof(struct usb_platdata),
130 .priv_auto_alloc_size = sizeof(struct xhci_pci_priv),
131 .flags = DM_FLAG_ALLOC_PRIV_DMA,
134 static struct pci_device_id xhci_pci_supported[] = {
135 { PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_XHCI, ~0) },
139 U_BOOT_PCI_DEVICE(xhci_pci, xhci_pci_supported);
141 #endif /* CONFIG_DM_USB */