Felix Held | 3c44c62 | 2022-01-10 20:57:29 +0100 | [diff] [blame] | 1 | /* 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 Zieba | 88fb0a1 | 2022-11-18 18:24:00 +0000 | [diff] [blame] | 7 | #include <amdblocks/xhci.h> |
Felix Held | 3c44c62 | 2022-01-10 20:57:29 +0100 | [diff] [blame] | 8 | #include <bootstate.h> |
| 9 | #include <device/device.h> |
Jon Murphy | 6e368f7 | 2022-02-24 14:37:04 -0700 | [diff] [blame] | 10 | #include <device/pci_ids.h> |
Felix Held | 3c44c62 | 2022-01-10 20:57:29 +0100 | [diff] [blame] | 11 | #include <drivers/usb/pci_xhci/pci_xhci.h> |
| 12 | #include <soc/pci_devs.h> |
| 13 | #include <soc/smi.h> |
| 14 | |
| 15 | static const struct sci_source xhci_sci_sources[] = { |
| 16 | { |
| 17 | .scimap = SMITYPE_XHC0_PME, |
Robert Zieba | 88fb0a1 | 2022-11-18 18:24:00 +0000 | [diff] [blame] | 18 | .gpe = XHCI_GEVENT, |
Felix Held | 3c44c62 | 2022-01-10 20:57:29 +0100 | [diff] [blame] | 19 | .direction = SMI_SCI_LVL_HIGH, |
| 20 | .level = SMI_SCI_EDG |
| 21 | }, |
| 22 | { |
| 23 | .scimap = SMITYPE_XHC1_PME, |
Robert Zieba | 88fb0a1 | 2022-11-18 18:24:00 +0000 | [diff] [blame] | 24 | .gpe = XHCI_GEVENT, |
Felix Held | 3c44c62 | 2022-01-10 20:57:29 +0100 | [diff] [blame] | 25 | .direction = SMI_SCI_LVL_HIGH, |
| 26 | .level = SMI_SCI_EDG |
Jon Murphy | 6e368f7 | 2022-02-24 14:37:04 -0700 | [diff] [blame] | 27 | }, |
| 28 | { |
| 29 | .scimap = SMITYPE_XHC2_PME, |
Robert Zieba | 88fb0a1 | 2022-11-18 18:24:00 +0000 | [diff] [blame] | 30 | .gpe = XHCI_GEVENT, |
Jon Murphy | 6e368f7 | 2022-02-24 14:37:04 -0700 | [diff] [blame] | 31 | .direction = SMI_SCI_LVL_HIGH, |
| 32 | .level = SMI_SCI_EDG |
Felix Held | 3c44c62 | 2022-01-10 20:57:29 +0100 | [diff] [blame] | 33 | } |
| 34 | }; |
| 35 | |
| 36 | enum cb_err pci_xhci_get_wake_gpe(const struct device *dev, int *gpe) |
| 37 | { |
| 38 | if (dev->bus->dev->path.type != DEVICE_PATH_PCI) |
| 39 | return CB_ERR_ARG; |
| 40 | |
Felix Held | 3c44c62 | 2022-01-10 20:57:29 +0100 | [diff] [blame] | 41 | if (dev->path.type != DEVICE_PATH_PCI) |
| 42 | return CB_ERR_ARG; |
| 43 | |
Jon Murphy | 6e368f7 | 2022-02-24 14:37:04 -0700 | [diff] [blame] | 44 | if (dev->bus->dev->path.pci.devfn == PCIE_ABC_A_DEVFN) { |
| 45 | 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 | } |
Felix Held | e8a21e7 | 2023-04-21 16:12:22 +0200 | [diff] [blame^] | 52 | } else if (dev->bus->dev->path.pci.devfn == PCIE_ABC_C_DEVFN) { |
Jon Murphy | 6e368f7 | 2022-02-24 14:37:04 -0700 | [diff] [blame] | 53 | if (dev->path.pci.devfn == XHCI2_DEVFN |
Felix Singer | 43b7f41 | 2022-03-07 04:34:52 +0100 | [diff] [blame] | 54 | && dev->device == PCI_DID_AMD_FAM17H_MODELA0H_XHCI2) { |
Jon Murphy | 6e368f7 | 2022-02-24 14:37:04 -0700 | [diff] [blame] | 55 | *gpe = xhci_sci_sources[2].gpe; |
| 56 | return CB_SUCCESS; |
| 57 | } |
| 58 | } |
Felix Held | 3c44c62 | 2022-01-10 20:57:29 +0100 | [diff] [blame] | 59 | |
Jon Murphy | 6e368f7 | 2022-02-24 14:37:04 -0700 | [diff] [blame] | 60 | return CB_ERR_ARG; |
Felix Held | 3c44c62 | 2022-01-10 20:57:29 +0100 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | static void configure_xhci_sci(void *unused) |
| 64 | { |
Jon Murphy | 6e368f7 | 2022-02-24 14:37:04 -0700 | [diff] [blame] | 65 | const struct device *xhci_2 = DEV_PTR(xhci_2); |
Felix Singer | 43b7f41 | 2022-03-07 04:34:52 +0100 | [diff] [blame] | 66 | if (xhci_2->device == PCI_DID_AMD_FAM17H_MODELA0H_XHCI2) |
Jon Murphy | 6e368f7 | 2022-02-24 14:37:04 -0700 | [diff] [blame] | 67 | 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 Held | 3c44c62 | 2022-01-10 20:57:29 +0100 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | BOOT_STATE_INIT_ENTRY(BS_POST_DEVICE, BS_ON_ENTRY, configure_xhci_sci, NULL); |