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