blob: fdd0118d7b5a9ac4864029bc415540da33341c91 [file] [log] [blame]
Felix Held3c44c622022-01-10 20:57:29 +01001/* SPDX-License-Identifier: GPL-2.0-only */
2
3/* TODO: Check if this is still correct */
4
5#include <amdblocks/gpio.h>
6#include <amdblocks/smi.h>
7#include <bootstate.h>
8#include <device/device.h>
Jon Murphy6e368f72022-02-24 14:37:04 -07009#include <device/pci_ids.h>
Felix Held3c44c622022-01-10 20:57:29 +010010#include <drivers/usb/pci_xhci/pci_xhci.h>
11#include <soc/pci_devs.h>
12#include <soc/smi.h>
13
14static const struct sci_source xhci_sci_sources[] = {
15 {
16 .scimap = SMITYPE_XHC0_PME,
17 .gpe = GEVENT_31,
18 .direction = SMI_SCI_LVL_HIGH,
19 .level = SMI_SCI_EDG
20 },
21 {
22 .scimap = SMITYPE_XHC1_PME,
23 .gpe = GEVENT_31,
24 .direction = SMI_SCI_LVL_HIGH,
25 .level = SMI_SCI_EDG
Jon Murphy6e368f72022-02-24 14:37:04 -070026 },
27 {
28 .scimap = SMITYPE_XHC2_PME,
29 .gpe = GEVENT_31,
30 .direction = SMI_SCI_LVL_HIGH,
31 .level = SMI_SCI_EDG
Felix Held3c44c622022-01-10 20:57:29 +010032 }
33};
34
35enum cb_err pci_xhci_get_wake_gpe(const struct device *dev, int *gpe)
36{
37 if (dev->bus->dev->path.type != DEVICE_PATH_PCI)
38 return CB_ERR_ARG;
39
Felix Held3c44c622022-01-10 20:57:29 +010040 if (dev->path.type != DEVICE_PATH_PCI)
41 return CB_ERR_ARG;
42
Jon Murphy6e368f72022-02-24 14:37:04 -070043 if (dev->bus->dev->path.pci.devfn == PCIE_ABC_A_DEVFN) {
44 if (dev->path.pci.devfn == XHCI0_DEVFN) {
45 *gpe = xhci_sci_sources[0].gpe;
46 return CB_SUCCESS;
47 } else if (dev->path.pci.devfn == XHCI1_DEVFN) {
48 *gpe = xhci_sci_sources[1].gpe;
49 return CB_SUCCESS;
50 }
51 } else if (dev->bus->dev->path.pci.devfn == PCIE_GPP_C_DEVFN) {
52 if (dev->path.pci.devfn == XHCI2_DEVFN
Felix Singer43b7f412022-03-07 04:34:52 +010053 && dev->device == PCI_DID_AMD_FAM17H_MODELA0H_XHCI2) {
Jon Murphy6e368f72022-02-24 14:37:04 -070054 *gpe = xhci_sci_sources[2].gpe;
55 return CB_SUCCESS;
56 }
57 }
Felix Held3c44c622022-01-10 20:57:29 +010058
Jon Murphy6e368f72022-02-24 14:37:04 -070059 return CB_ERR_ARG;
Felix Held3c44c622022-01-10 20:57:29 +010060}
61
62static void configure_xhci_sci(void *unused)
63{
Jon Murphy6e368f72022-02-24 14:37:04 -070064 const struct device *xhci_2 = DEV_PTR(xhci_2);
Felix Singer43b7f412022-03-07 04:34:52 +010065 if (xhci_2->device == PCI_DID_AMD_FAM17H_MODELA0H_XHCI2)
Jon Murphy6e368f72022-02-24 14:37:04 -070066 gpe_configure_sci(xhci_sci_sources, ARRAY_SIZE(xhci_sci_sources));
67 else
68 gpe_configure_sci(xhci_sci_sources, ARRAY_SIZE(xhci_sci_sources) - 1);
Felix Held3c44c622022-01-10 20:57:29 +010069}
70
71BOOT_STATE_INIT_ENTRY(BS_POST_DEVICE, BS_ON_ENTRY, configure_xhci_sci, NULL);