blob: fc1c11920efb2f3e3907fa9bc77a97a5526b8c3f [file] [log] [blame]
Felix Helde77d9392021-03-11 19:37:32 +01001/* SPDX-License-Identifier: GPL-2.0-only */
2
Felix Helddea4e0f2021-09-22 20:05:53 +02003#include <amdblocks/gpio.h>
Felix Helde77d9392021-03-11 19:37:32 +01004#include <amdblocks/smi.h>
Robert Zieba3db7b462022-11-18 18:28:55 +00005#include <amdblocks/xhci.h>
Felix Helde77d9392021-03-11 19:37:32 +01006#include <bootstate.h>
7#include <device/device.h>
8#include <drivers/usb/pci_xhci/pci_xhci.h>
9#include <soc/pci_devs.h>
10#include <soc/smi.h>
11
12static const struct sci_source xhci_sci_sources[] = {
13 {
14 .scimap = SMITYPE_XHC0_PME,
Robert Zieba3db7b462022-11-18 18:28:55 +000015 .gpe = XHCI_GEVENT,
Felix Helde77d9392021-03-11 19:37:32 +010016 .direction = SMI_SCI_LVL_HIGH,
17 .level = SMI_SCI_EDG
18 },
19 {
20 .scimap = SMITYPE_XHC1_PME,
Robert Zieba3db7b462022-11-18 18:28:55 +000021 .gpe = XHCI_GEVENT,
Felix Helde77d9392021-03-11 19:37:32 +010022 .direction = SMI_SCI_LVL_HIGH,
23 .level = SMI_SCI_EDG
24 }
25};
26
27enum cb_err pci_xhci_get_wake_gpe(const struct device *dev, int *gpe)
28{
Arthur Heymans7fcd4d52023-08-24 15:12:19 +020029 if (dev->upstream->dev->path.type != DEVICE_PATH_PCI)
Felix Helde77d9392021-03-11 19:37:32 +010030 return CB_ERR_ARG;
31
Arthur Heymans7fcd4d52023-08-24 15:12:19 +020032 if (dev->upstream->dev->path.pci.devfn != PCIE_ABC_A_DEVFN)
Felix Helde77d9392021-03-11 19:37:32 +010033 return CB_ERR_ARG;
34
35 if (dev->path.type != DEVICE_PATH_PCI)
36 return CB_ERR_ARG;
37
38 if (dev->path.pci.devfn == XHCI0_DEVFN)
39 *gpe = xhci_sci_sources[0].gpe;
40 else if (dev->path.pci.devfn == XHCI1_DEVFN)
41 *gpe = xhci_sci_sources[1].gpe;
42 else
43 return CB_ERR_ARG;
44
45 return CB_SUCCESS;
46}
47
48static void configure_xhci_sci(void *unused)
49{
50 gpe_configure_sci(xhci_sci_sources, ARRAY_SIZE(xhci_sci_sources));
51}
52
53BOOT_STATE_INIT_ENTRY(BS_POST_DEVICE, BS_ON_ENTRY, configure_xhci_sci, NULL);