| 1 |
|
| 2 |
|
| 3 |
#include <device/mmio.h> |
| 4 |
#include <device/pci_ops.h> |
| 5 |
#include <device/xhci.h> |
| 6 |
#include <elog.h> |
| 7 |
#include <intelblocks/xhci.h> |
| 8 |
#include <soc/pci_devs.h> |
| 9 |
#include <stdint.h> |
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
static bool xhci_port_wake_check(uintptr_t base, uint8_t num, uint8_t host_event, uint8_t event) |
| 26 |
{ |
| 27 |
uint32_t i, port_status; |
| 28 |
bool found = false; |
| 29 |
|
| 30 |
for (i = 0; i < num; i++, base += 0x10) { |
| 31 |
|
| 32 |
port_status = read32p(base); |
| 33 |
|
| 34 |
|
| 35 |
if (port_status == 0xffffffff) |
| 36 |
continue; |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
if (xhci_portsc_csc(port_status) && |
| 44 |
xhci_portsc_wake_capable(port_status)) { |
| 45 |
elog_add_event_wake(host_event, 0); |
| 46 |
elog_add_event_wake(event, i + 1); |
| 47 |
found = true; |
| 48 |
continue; |
| 49 |
} |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
if (xhci_portsc_plc(port_status) && |
| 56 |
xhci_portsc_resume(port_status)) { |
| 57 |
elog_add_event_wake(host_event, 0); |
| 58 |
elog_add_event_wake(event, i + 1); |
| 59 |
found = true; |
| 60 |
} |
| 61 |
} |
| 62 |
return found; |
| 63 |
} |
| 64 |
|
| 65 |
bool xhci_update_wake_event(const struct xhci_wake_info *wake_info, |
| 66 |
size_t wake_info_count) |
| 67 |
{ |
| 68 |
const struct xhci_usb_info *usb_info; |
| 69 |
uintptr_t mmio_base; |
| 70 |
bool event_found = false; |
| 71 |
size_t i; |
| 72 |
|
| 73 |
for (i = 0; i < wake_info_count; ++i) { |
| 74 |
|
| 75 |
pci_devfn_t devfn = PCI_DEV(0, PCI_SLOT(wake_info[i].xhci_dev), |
| 76 |
PCI_FUNC(wake_info[i].xhci_dev)); |
| 77 |
mmio_base = pci_s_read_config32(devfn, PCI_BASE_ADDRESS_0); |
| 78 |
mmio_base &= ~PCI_BASE_ADDRESS_MEM_ATTR_MASK; |
| 79 |
usb_info = soc_get_xhci_usb_info(wake_info[i].xhci_dev); |
| 80 |
|
| 81 |
|
| 82 |
if (xhci_port_wake_check(mmio_base + usb_info->usb2_port_status_reg, |
| 83 |
usb_info->num_usb2_ports, |
| 84 |
wake_info[i].elog_wake_type_host, |
| 85 |
ELOG_WAKE_SOURCE_PME_XHCI_USB_2)) |
| 86 |
event_found = true; |
| 87 |
|
| 88 |
|
| 89 |
if (xhci_port_wake_check(mmio_base + usb_info->usb3_port_status_reg, |
| 90 |
usb_info->num_usb3_ports, |
| 91 |
wake_info[i].elog_wake_type_host, |
| 92 |
ELOG_WAKE_SOURCE_PME_XHCI_USB_3)) |
| 93 |
event_found = true; |
| 94 |
} |
| 95 |
|
| 96 |
return event_found; |
| 97 |
} |