blob: e4a0ef4a1a5963a9281abd836070b909d3b4abec [file] [log] [blame]
Simon Glass316328f2015-01-27 22:13:31 -07001/*
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>
Stefan Roese555a3472016-07-18 12:51:39 +020010#include <dm.h>
Simon Glass316328f2015-01-27 22:13:31 -070011#include <pci.h>
12#include <usb.h>
Simon Glass316328f2015-01-27 22:13:31 -070013#include "xhci.h"
14
Stefan Roese555a3472016-07-18 12:51:39 +020015static 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 0x%x and hcor 0x%x hc_length %d\n",
28 (u32)hccr, (u32)hcor,
29 (u32)HC_LENGTH(xhci_readl(&hccr->cr_capbase)));
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
40static 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 Roese555a3472016-07-18 12:51:39 +020050static const struct udevice_id xhci_pci_ids[] = {
51 { .compatible = "xhci-pci" },
52 { }
53};
54
55U_BOOT_DRIVER(xhci_pci) = {
56 .name = "xhci_pci",
57 .id = UCLASS_USB,
58 .probe = xhci_pci_probe,
Bin Meng5e941942017-07-19 21:51:08 +080059 .remove = xhci_deregister,
Stefan Roese555a3472016-07-18 12:51:39 +020060 .of_match = xhci_pci_ids,
61 .ops = &xhci_usb_ops,
62 .platdata_auto_alloc_size = sizeof(struct usb_platdata),
Bin Meng5e941942017-07-19 21:51:08 +080063 .priv_auto_alloc_size = sizeof(struct xhci_ctrl),
Stefan Roese555a3472016-07-18 12:51:39 +020064 .flags = DM_FLAG_ALLOC_PRIV_DMA,
65};
66
67static struct pci_device_id xhci_pci_supported[] = {
68 { PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_XHCI, ~0) },
69 {},
70};
71
72U_BOOT_PCI_DEVICE(xhci_pci, xhci_pci_supported);