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