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 <errno.h> 12 #include <pci.h> 13 #include <usb.h> 14 15 #include "xhci.h" 16 17 struct xhci_pci_priv { 18 struct xhci_ctrl ctrl; /* Needs to come first in this struct! */ 19 }; 20 21 static void xhci_pci_init(struct udevice *dev, struct xhci_hccr **ret_hccr, 22 struct xhci_hcor **ret_hcor) 23 { 24 struct xhci_hccr *hccr; 25 struct xhci_hcor *hcor; 26 u32 cmd; 27 28 hccr = (struct xhci_hccr *)dm_pci_map_bar(dev, 29 PCI_BASE_ADDRESS_0, PCI_REGION_MEM); 30 hcor = (struct xhci_hcor *)((uintptr_t) hccr + 31 HC_LENGTH(xhci_readl(&hccr->cr_capbase))); 32 33 debug("XHCI-PCI init hccr 0x%x and hcor 0x%x hc_length %d\n", 34 (u32)hccr, (u32)hcor, 35 (u32)HC_LENGTH(xhci_readl(&hccr->cr_capbase))); 36 37 *ret_hccr = hccr; 38 *ret_hcor = hcor; 39 40 /* enable busmaster */ 41 dm_pci_read_config32(dev, PCI_COMMAND, &cmd); 42 cmd |= PCI_COMMAND_MASTER; 43 dm_pci_write_config32(dev, PCI_COMMAND, cmd); 44 } 45 46 static int xhci_pci_probe(struct udevice *dev) 47 { 48 struct xhci_hccr *hccr; 49 struct xhci_hcor *hcor; 50 51 xhci_pci_init(dev, &hccr, &hcor); 52 53 return xhci_register(dev, hccr, hcor); 54 } 55 56 static int xhci_pci_remove(struct udevice *dev) 57 { 58 int ret; 59 60 ret = xhci_deregister(dev); 61 if (ret) 62 return ret; 63 64 return 0; 65 } 66 67 static const struct udevice_id xhci_pci_ids[] = { 68 { .compatible = "xhci-pci" }, 69 { } 70 }; 71 72 U_BOOT_DRIVER(xhci_pci) = { 73 .name = "xhci_pci", 74 .id = UCLASS_USB, 75 .probe = xhci_pci_probe, 76 .remove = xhci_pci_remove, 77 .of_match = xhci_pci_ids, 78 .ops = &xhci_usb_ops, 79 .platdata_auto_alloc_size = sizeof(struct usb_platdata), 80 .priv_auto_alloc_size = sizeof(struct xhci_pci_priv), 81 .flags = DM_FLAG_ALLOC_PRIV_DMA, 82 }; 83 84 static struct pci_device_id xhci_pci_supported[] = { 85 { PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_XHCI, ~0) }, 86 {}, 87 }; 88 89 U_BOOT_PCI_DEVICE(xhci_pci, xhci_pci_supported); 90