blob: e8fd6bf6ae08fdcad981259ff09aa8d8444dc4fe [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0
Simon Glass40ffb682015-01-27 22:13:31 -07002/*
3 * Copyright (c) 2015, Google, Inc
4 * Written by Simon Glass <sjg@chromium.org>
5 * All rights reserved.
Simon Glass40ffb682015-01-27 22:13:31 -07006 */
7
8#include <common.h>
Stefan Roeseb0ff2c12016-07-18 12:51:39 +02009#include <dm.h>
Simon Glass40ffb682015-01-27 22:13:31 -070010#include <pci.h>
11#include <usb.h>
Simon Glass40ffb682015-01-27 22:13:31 -070012#include "xhci.h"
13
Stefan Roeseb0ff2c12016-07-18 12:51:39 +020014static 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
26 debug("XHCI-PCI init hccr 0x%x and hcor 0x%x hc_length %d\n",
27 (u32)hccr, (u32)hcor,
28 (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
39static 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
Stefan Roeseb0ff2c12016-07-18 12:51:39 +020049static const struct udevice_id xhci_pci_ids[] = {
50 { .compatible = "xhci-pci" },
51 { }
52};
53
54U_BOOT_DRIVER(xhci_pci) = {
55 .name = "xhci_pci",
56 .id = UCLASS_USB,
57 .probe = xhci_pci_probe,
Bin Mengaff38b92017-07-19 21:51:08 +080058 .remove = xhci_deregister,
Stefan Roeseb0ff2c12016-07-18 12:51:39 +020059 .of_match = xhci_pci_ids,
60 .ops = &xhci_usb_ops,
61 .platdata_auto_alloc_size = sizeof(struct usb_platdata),
Bin Mengaff38b92017-07-19 21:51:08 +080062 .priv_auto_alloc_size = sizeof(struct xhci_ctrl),
Stefan Roeseb0ff2c12016-07-18 12:51:39 +020063 .flags = DM_FLAG_ALLOC_PRIV_DMA,
64};
65
66static struct pci_device_id xhci_pci_supported[] = {
67 { PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_XHCI, ~0) },
68 {},
69};
70
71U_BOOT_PCI_DEVICE(xhci_pci, xhci_pci_supported);