Martin Roth | 1a3de8e | 2022-10-06 15:57:21 -0600 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
Martin Roth | 1a3de8e | 2022-10-06 15:57:21 -0600 | [diff] [blame] | 3 | #include <amdblocks/gpio.h> |
| 4 | #include <amdblocks/smi.h> |
Jon Murphy | df2edde | 2023-04-06 17:15:14 -0600 | [diff] [blame] | 5 | #include <amdblocks/xhci.h> |
Martin Roth | 1a3de8e | 2022-10-06 15:57:21 -0600 | [diff] [blame] | 6 | #include <bootstate.h> |
| 7 | #include <device/device.h> |
| 8 | #include <device/pci_ids.h> |
| 9 | #include <drivers/usb/pci_xhci/pci_xhci.h> |
| 10 | #include <soc/pci_devs.h> |
| 11 | #include <soc/smi.h> |
| 12 | |
| 13 | static const struct sci_source xhci_sci_sources[] = { |
| 14 | { |
| 15 | .scimap = SMITYPE_XHC0_PME, |
Jon Murphy | df2edde | 2023-04-06 17:15:14 -0600 | [diff] [blame] | 16 | .gpe = XHCI_GEVENT, |
Martin Roth | 1a3de8e | 2022-10-06 15:57:21 -0600 | [diff] [blame] | 17 | .direction = SMI_SCI_LVL_HIGH, |
| 18 | .level = SMI_SCI_EDG |
| 19 | }, |
| 20 | { |
| 21 | .scimap = SMITYPE_XHC1_PME, |
Jon Murphy | df2edde | 2023-04-06 17:15:14 -0600 | [diff] [blame] | 22 | .gpe = XHCI_GEVENT, |
Martin Roth | 1a3de8e | 2022-10-06 15:57:21 -0600 | [diff] [blame] | 23 | .direction = SMI_SCI_LVL_HIGH, |
| 24 | .level = SMI_SCI_EDG |
Felix Held | 5cabc29 | 2023-04-21 16:17:21 +0200 | [diff] [blame^] | 25 | }, |
| 26 | { |
| 27 | .scimap = SMITYPE_XHC3_PME, |
| 28 | .gpe = XHCI_GEVENT, |
| 29 | .direction = SMI_SCI_LVL_HIGH, |
| 30 | .level = SMI_SCI_EDG |
| 31 | }, |
| 32 | { |
| 33 | .scimap = SMITYPE_XHC4_PME, |
| 34 | .gpe = XHCI_GEVENT, |
| 35 | .direction = SMI_SCI_LVL_HIGH, |
| 36 | .level = SMI_SCI_EDG |
Martin Roth | 1a3de8e | 2022-10-06 15:57:21 -0600 | [diff] [blame] | 37 | } |
| 38 | }; |
| 39 | |
| 40 | enum cb_err pci_xhci_get_wake_gpe(const struct device *dev, int *gpe) |
| 41 | { |
| 42 | if (dev->bus->dev->path.type != DEVICE_PATH_PCI) |
| 43 | return CB_ERR_ARG; |
| 44 | |
| 45 | if (dev->path.type != DEVICE_PATH_PCI) |
| 46 | return CB_ERR_ARG; |
| 47 | |
| 48 | if (dev->bus->dev->path.pci.devfn == PCIE_ABC_A_DEVFN) { |
| 49 | if (dev->path.pci.devfn == XHCI0_DEVFN) { |
| 50 | *gpe = xhci_sci_sources[0].gpe; |
| 51 | return CB_SUCCESS; |
| 52 | } else if (dev->path.pci.devfn == XHCI1_DEVFN) { |
| 53 | *gpe = xhci_sci_sources[1].gpe; |
| 54 | return CB_SUCCESS; |
| 55 | } |
Martin Roth | 1a3de8e | 2022-10-06 15:57:21 -0600 | [diff] [blame] | 56 | } |
| 57 | |
Felix Held | 5cabc29 | 2023-04-21 16:17:21 +0200 | [diff] [blame^] | 58 | if (dev->bus->dev->path.pci.devfn == PCIE_ABC_C_DEVFN) { |
| 59 | if (dev->path.pci.devfn == USB4_XHCI0_DEVFN) { |
| 60 | *gpe = xhci_sci_sources[2].gpe; |
| 61 | return CB_SUCCESS; |
| 62 | } else if (dev->path.pci.devfn == USB4_XHCI1_DEVFN) { |
| 63 | *gpe = xhci_sci_sources[3].gpe; |
| 64 | return CB_SUCCESS; |
| 65 | } |
| 66 | } |
| 67 | |
Martin Roth | 1a3de8e | 2022-10-06 15:57:21 -0600 | [diff] [blame] | 68 | return CB_ERR_ARG; |
| 69 | } |
| 70 | |
| 71 | static void configure_xhci_sci(void *unused) |
| 72 | { |
Fred Reitberger | 88fefd4 | 2023-04-19 16:06:38 -0400 | [diff] [blame] | 73 | gpe_configure_sci(xhci_sci_sources, ARRAY_SIZE(xhci_sci_sources)); |
Martin Roth | 1a3de8e | 2022-10-06 15:57:21 -0600 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | BOOT_STATE_INIT_ENTRY(BS_POST_DEVICE, BS_ON_ENTRY, configure_xhci_sci, NULL); |