| 1 |
|
| 2 |
|
| 3 |
#include <console/console.h> |
| 4 |
#include <device/pci.h> |
| 5 |
#include <soc/pch_pci_devs.h> |
| 6 |
#include <soc/xhci.h> |
| 7 |
#include <types.h> |
| 8 |
|
| 9 |
|
| 10 |
#define SYS_BUS_CFG2 0x44 |
| 11 |
|
| 12 |
static uint8_t *get_xhci_bar(void) |
| 13 |
{ |
| 14 |
const struct resource *res; |
| 15 |
res = probe_resource(PCH_DEV_XHCI, PCI_BASE_ADDRESS_0); |
| 16 |
if (!res) { |
| 17 |
printk(BIOS_ERR, "XHCI BAR is not found\n"); |
| 18 |
return NULL; |
| 19 |
} |
| 20 |
|
| 21 |
#if ENV_X86_32 |
| 22 |
assert(res->base < 0x100000000ULL); |
| 23 |
if (res->base >= 0x100000000ULL) |
| 24 |
return NULL; |
| 25 |
#endif |
| 26 |
|
| 27 |
return (void *)(uintptr_t)res->base; |
| 28 |
} |
| 29 |
|
| 30 |
void write_usb_oc_mapping(const struct usb_oc_mapping *config, uint8_t pins) |
| 31 |
{ |
| 32 |
uint8_t *mbar = get_xhci_bar(); |
| 33 |
uint8_t i; |
| 34 |
|
| 35 |
if (mbar == NULL) { |
| 36 |
printk(BIOS_ERR, "XHCI BAR is invalid, skip USB OC mapping configuration\n"); |
| 37 |
return; |
| 38 |
} |
| 39 |
for (i = 0; i < pins; i++) |
| 40 |
write32(mbar + config[i].pin, config[i].port); |
| 41 |
} |
| 42 |
|
| 43 |
void lock_oc_cfg(bool lock) |
| 44 |
{ |
| 45 |
uint32_t cfg = pci_read_config32(PCH_DEV_XHCI, SYS_BUS_CFG2); |
| 46 |
|
| 47 |
if (lock) |
| 48 |
cfg |= OCCFGDONE; |
| 49 |
else |
| 50 |
cfg &= ~(OCCFGDONE); |
| 51 |
pci_write_config32(PCH_DEV_XHCI, SYS_BUS_CFG2, cfg); |
| 52 |
} |