blob: 544ea16ba9b32980ee2ad867667e0461218d8a91 [file] [log] [blame]
Jonathan Zhang3ed903f2023-01-25 11:37:27 -08001/* SPDX-License-Identifier: GPL-2.0-only */
2
3#include <console/console.h>
4#include <device/pci.h>
5#include <soc/pci_devs.h>
6#include <soc/xhci.h>
7#include <types.h>
8
9static uint8_t *get_xhci_bar(void)
10{
11 const struct resource *res;
12 res = probe_resource(PCH_DEV_XHCI, PCI_BASE_ADDRESS_0);
13 if (!res) {
14 printk(BIOS_ERR, "XHCI BAR is not found\n");
15 return NULL;
16 }
17 return (void *)(uintptr_t)res->base;
18}
19
20void write_usb_oc_mapping(const struct usb_oc_mapping *config, uint8_t pins)
21{
22 uint8_t *mbar = get_xhci_bar();
23 uint8_t i;
24
25 if (mbar == NULL) {
26 printk(BIOS_ERR, "XHCI BAR is invalid, skip USB OC mapping configuration\n");
27 return;
28 }
29 for (i = 0; i < pins; i++)
30 write32(mbar + config[i].pin, config[i].port);
31}
32
33void lock_oc_cfg(bool lock)
34{
35 uint32_t cfg = pci_read_config32(PCH_DEV_XHCI, SYS_BUS_CFG2);
36
37 if (lock)
38 cfg |= OCCFGDONE;
39 else
40 cfg &= ~(OCCFGDONE);
41 pci_write_config32(PCH_DEV_XHCI, SYS_BUS_CFG2, cfg);
42}