summaryrefslogtreecommitdiff
path: root/src/soc/intel/jasperlake/xhci.c
blob: 75663795d372da53c600e134d0917206e6bcca37 (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
/* SPDX-License-Identifier: GPL-2.0-only */

#include <console/console.h>
#include <device/mmio.h>
#include <intelblocks/xhci.h>
#include <soc/soc_chip.h>

#define XHCI_USB2_PORT_STATUS_REG	0x480
#define XHCI_USB3_PORT_STATUS_REG	0x500
#define XHCI_USB2_PORT_NUM		8
#define XHCI_USB3_PORT_NUM		6

#define XHCI_PMCTRL			0x80A4
/* BIT[7:4] LFPS periodic sampling off time for USB3 Ports */
#define PMCTRL_LFPS_OFFTIME_SHIFT	4
#define PMCTRL_LFPS_OFFTIME_MAX		0xF

static const struct xhci_usb_info usb_info = {
	.usb2_port_status_reg = XHCI_USB2_PORT_STATUS_REG,
	.num_usb2_ports = XHCI_USB2_PORT_NUM,
	.usb3_port_status_reg = XHCI_USB3_PORT_STATUS_REG,
	.num_usb3_ports = XHCI_USB3_PORT_NUM,
};

const struct xhci_usb_info *soc_get_xhci_usb_info(pci_devfn_t xhci_dev)
{
	/* Jasper Lake only has one XHCI controller */
	return &usb_info;
}

static void set_xhci_lfps_sampling_offtime(struct device *dev, uint8_t time_ms)
{
	void *addr;
	const struct resource *res = find_resource(dev, PCI_BASE_ADDRESS_0);

	if (!res)
		return;

	if (time_ms > PMCTRL_LFPS_OFFTIME_MAX) {
		printk(BIOS_ERR,
			"XHCI: The maximum LFPS sampling OFF time is %u ms, "
			"cannot set it to %u ms\n",
			PMCTRL_LFPS_OFFTIME_MAX, time_ms);

		return;
	}

	addr = (void *)(uintptr_t)(res->base + XHCI_PMCTRL);
	clrsetbits32(addr,
		PMCTRL_LFPS_OFFTIME_MAX << PMCTRL_LFPS_OFFTIME_SHIFT,
		time_ms << PMCTRL_LFPS_OFFTIME_SHIFT);
	printk(BIOS_DEBUG,
		"XHCI: Updated LFPS sampling OFF time to %u ms\n", time_ms);
}

void soc_xhci_init(struct device *dev)
{
	const config_t *config = config_of_soc();

	/* Set xHCI LFPS period sampling off time */
	set_xhci_lfps_sampling_offtime(dev,
		config->xhci_lfps_sampling_offtime_ms);
}