blob: 8f46374fce0572e34c4a80127819113a1fbfd81e [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>
Robert Zieba88fb0a12022-11-18 18:24:00 +00007#include <amdblocks/xhci.h>
Felix Held3c44c622022-01-10 20:57:29 +01008#include <bootstate.h>
9#include <device/device.h>
Jon Murphy6e368f72022-02-24 14:37:04 -070010#include <device/pci_ids.h>
Felix Held3c44c622022-01-10 20:57:29 +010011#include <drivers/usb/pci_xhci/pci_xhci.h>
12#include <soc/pci_devs.h>
13#include <soc/smi.h>
14
15static const struct sci_source xhci_sci_sources[] = {
16 {
17 .scimap = SMITYPE_XHC0_PME,
Robert Zieba88fb0a12022-11-18 18:24:00 +000018 .gpe = XHCI_GEVENT,
Felix Held3c44c622022-01-10 20:57:29 +010019 .direction = SMI_SCI_LVL_HIGH,
20 .level = SMI_SCI_EDG
21 },
22 {
23 .scimap = SMITYPE_XHC1_PME,
Robert Zieba88fb0a12022-11-18 18:24:00 +000024 .gpe = XHCI_GEVENT,
Felix Held3c44c622022-01-10 20:57:29 +010025 .direction = SMI_SCI_LVL_HIGH,
26 .level = SMI_SCI_EDG
Jon Murphy6e368f72022-02-24 14:37:04 -070027 },
28 {
29 .scimap = SMITYPE_XHC2_PME,
Robert Zieba88fb0a12022-11-18 18:24:00 +000030 .gpe = XHCI_GEVENT,
Jon Murphy6e368f72022-02-24 14:37:04 -070031 .direction = SMI_SCI_LVL_HIGH,
32 .level = SMI_SCI_EDG
Felix Held3c44c622022-01-10 20:57:29 +010033 }
34};
35
36enum cb_err pci_xhci_get_wake_gpe(const struct device *dev, int *gpe)
37{
Arthur Heymans7fcd4d52023-08-24 15:12:19 +020038 if (dev->upstream->dev->path.type != DEVICE_PATH_PCI)
Felix Held3c44c622022-01-10 20:57:29 +010039 return CB_ERR_ARG;
40
Felix Held3c44c622022-01-10 20:57:29 +010041 if (dev->path.type != DEVICE_PATH_PCI)
42 return CB_ERR_ARG;
43
Arthur Heymans7fcd4d52023-08-24 15:12:19 +020044 if (dev->upstream->dev->path.pci.devfn == PCIE_ABC_A_DEVFN) {
Jon Murphy6e368f72022-02-24 14:37:04 -070045 if (dev->path.pci.devfn == XHCI0_DEVFN) {
46 *gpe = xhci_sci_sources[0].gpe;
47 return CB_SUCCESS;
48 } else if (dev->path.pci.devfn == XHCI1_DEVFN) {
49 *gpe = xhci_sci_sources[1].gpe;
50 return CB_SUCCESS;
51 }
Arthur Heymans7fcd4d52023-08-24 15:12:19 +020052 } else if (dev->upstream->dev->path.pci.devfn == PCIE_ABC_C_DEVFN) {
Jon Murphy6e368f72022-02-24 14:37:04 -070053 if (dev->path.pci.devfn == XHCI2_DEVFN
Felix Singer43b7f412022-03-07 04:34:52 +010054 && dev->device == PCI_DID_AMD_FAM17H_MODELA0H_XHCI2) {
Jon Murphy6e368f72022-02-24 14:37:04 -070055 *gpe = xhci_sci_sources[2].gpe;
56 return CB_SUCCESS;
57 }
58 }
Felix Held3c44c622022-01-10 20:57:29 +010059
Jon Murphy6e368f72022-02-24 14:37:04 -070060 return CB_ERR_ARG;
Felix Held3c44c622022-01-10 20:57:29 +010061}
62
63static void configure_xhci_sci(void *unused)
64{
Jon Murphy6e368f72022-02-24 14:37:04 -070065 const struct device *xhci_2 = DEV_PTR(xhci_2);
Felix Singer43b7f412022-03-07 04:34:52 +010066 if (xhci_2->device == PCI_DID_AMD_FAM17H_MODELA0H_XHCI2)
Jon Murphy6e368f72022-02-24 14:37:04 -070067 gpe_configure_sci(xhci_sci_sources, ARRAY_SIZE(xhci_sci_sources));
68 else
69 gpe_configure_sci(xhci_sci_sources, ARRAY_SIZE(xhci_sci_sources) - 1);
Felix Held3c44c622022-01-10 20:57:29 +010070}
71
72BOOT_STATE_INIT_ENTRY(BS_POST_DEVICE, BS_ON_ENTRY, configure_xhci_sci, NULL);