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