summaryrefslogtreecommitdiff
path: root/src/soc/amd/mendocino/xhci.c
blob: ed8be752b491f4cddcf2f3eb7032d04ef15597ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/* SPDX-License-Identifier: GPL-2.0-only */

/* TODO: Check if this is still correct */

#include <amdblocks/gpio.h>
#include <amdblocks/smi.h>
#include <amdblocks/xhci.h>
#include <bootstate.h>
#include <device/device.h>
#include <device/pci_ids.h>
#include <drivers/usb/pci_xhci/pci_xhci.h>
#include <soc/pci_devs.h>
#include <soc/smi.h>
#include <static.h>

static const struct sci_source xhci_sci_sources[] = {
	{
		.scimap = SMITYPE_XHC0_PME,
		.gpe = XHCI_GEVENT,
		.direction = SMI_SCI_LVL_HIGH,
		.level = SMI_SCI_EDG
	},
	{
		.scimap = SMITYPE_XHC1_PME,
		.gpe = XHCI_GEVENT,
		.direction = SMI_SCI_LVL_HIGH,
		.level = SMI_SCI_EDG
	},
	{
		.scimap = SMITYPE_XHC2_PME,
		.gpe = XHCI_GEVENT,
		.direction = SMI_SCI_LVL_HIGH,
		.level = SMI_SCI_EDG
	}
};

enum cb_err pci_xhci_get_wake_gpe(const struct device *dev, int *gpe)
{
	if (dev->upstream->dev->path.type != DEVICE_PATH_PCI)
		return CB_ERR_ARG;

	if (dev->path.type != DEVICE_PATH_PCI)
		return CB_ERR_ARG;

	if (dev->upstream->dev->path.pci.devfn == PCIE_ABC_A_DEVFN) {
		if (dev->path.pci.devfn == XHCI0_DEVFN) {
			*gpe = xhci_sci_sources[0].gpe;
			return CB_SUCCESS;
		} else if (dev->path.pci.devfn == XHCI1_DEVFN) {
			*gpe = xhci_sci_sources[1].gpe;
			return CB_SUCCESS;
		}
	} else if (dev->upstream->dev->path.pci.devfn == PCIE_ABC_C_DEVFN) {
		if (dev->path.pci.devfn == XHCI2_DEVFN
		    && dev->device == PCI_DID_AMD_FAM17H_MODELA0H_XHCI2) {
			*gpe = xhci_sci_sources[2].gpe;
			return CB_SUCCESS;
		}
	}

	return CB_ERR_ARG;
}

static void configure_xhci_sci(void *unused)
{
	const struct device *xhci_2 = DEV_PTR(xhci_2);
	if (xhci_2->device == PCI_DID_AMD_FAM17H_MODELA0H_XHCI2)
		gpe_configure_sci(xhci_sci_sources, ARRAY_SIZE(xhci_sci_sources));
	else
		gpe_configure_sci(xhci_sci_sources, ARRAY_SIZE(xhci_sci_sources) - 1);
}

BOOT_STATE_INIT_ENTRY(BS_POST_DEVICE, BS_ON_ENTRY, configure_xhci_sci, NULL);