Jonathan Zhang | 3ed903f | 2023-01-25 11:37:27 -0800 | [diff] [blame^] | 1 | /* 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 | |
| 9 | static 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 | |
| 20 | void 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 | |
| 33 | void 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 | } |