xref: /aosp_15_r20/external/coreboot/src/soc/intel/common/block/include/intelblocks/xhci.h (revision b9411a12aaaa7e1e6a6fb7c5e057f44ee179a49c)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #ifndef SOC_INTEL_COMMON_BLOCK_XHCI_H
4 #define SOC_INTEL_COMMON_BLOCK_XHCI_H
5 
6 #define PORTSCN_OFFSET 0x480
7 #define  PORTSCN_WAKE_ON_DISCONNECT_ENABLE 0x4000000
8 #define  PORTSCN_WAKE_ON_CONNECT_ENABLE 0x2000000
9 /* Set WDE and WCE bits */
10 #define  PORTSCN_WAKE_ON_BOTH_CONNECT_DISCONNECT_ENABLE 0x6000000
11 /*
12  * And port status/control reg with RO and RWS bits
13  * RO bits: 0, 2:3, 10:13, 24, 28:30
14  * RWS bits: 5:9, 14:16, 25:27
15  */
16 #define  PORTSCN_BITS_OFF_MASK ~0x80FE0012
17 #define PORTSCXUSB3_OFFSET 0x540
18 
19 /*
20  * Set bit corresponding to USB port in wake enable bitmap. Bit 0 corresponds
21  * to Port 1, Bit n corresponds to Port (n+1). This bitmap is later used to
22  * decide what ports need to set PORTSCN/PORTSCXUSB3 register bits.
23  */
24 #define USB_PORT_WAKE_ENABLE(x)		(1 << ((x) - 1))
25 
26 #if !defined(__ACPI__)
27 #include <device/device.h>
28 #include <device/xhci.h>
29 #include <stdint.h>
30 
31 /*
32  * struct xhci_wake_info - Relates an XHCI device to registers and wake types
33  * @xhci_dev: devfn of the XHCI device
34  * @elog_wake_type_host: the wake type for the controller device
35  */
36 struct xhci_wake_info {
37 	pci_devfn_t xhci_dev;
38 	uint8_t elog_wake_type_host;
39 };
40 
41 /*
42  * xhci_update_wake_event() - Identify and log XHCI wake events.
43  * @wake_info: A mapping of XHCI devfn to elog wake types
44  * @wake_info_count: Count of items in wake_info
45  * @info: Information about number of USB ports and their status reg offset.
46  *
47  * This function goes through individual USB port status registers within the
48  * XHCI block and identifies if any of those USB ports triggered a wake-up and
49  * log information about those ports to the event log.
50  *
51  * Return: True if any port is identified as a wake source, false if none.
52  */
53 bool xhci_update_wake_event(const struct xhci_wake_info *wake_info,
54 			    size_t wake_info_count);
55 
56 /* xhci_host_reset() - Function to reset the host controller */
57 void xhci_host_reset(void);
58 void soc_xhci_init(struct device *dev);
59 
60 /*
61  * soc_get_xhci_usb_info() - Get the information about USB2 & USB3 ports.
62  *
63  * This function is used to get USB ports and status register offset information
64  * within a XHCI controller.
65  *
66  * Return: USB ports and status register offset info for the SoC.
67  */
68 const struct xhci_usb_info *soc_get_xhci_usb_info(pci_devfn_t xhci_dev);
69 
70 /*
71  * usb_xhci_disable_unused() - Disable unused USB devices
72  * @ext_usb_xhci_en_cb: Callback function to be invoked, supplied by mainboard,
73  *			to identify the status of externally visible USB ports.
74  *			(Return true if port is present, false if port is absent)
75  *
76  * This function is used to disable unused USB devices/ports that are configured
77  * in the device tree. For the internal USB ports, the connect status of the port
78  * is probed from the XHCI controller block and the port is disabled if it is not
79  * connected. For the external USB ports, the mainboard provides the connect status
80  * of the concerned port depending on the variants and their SKUs. If the mainboard
81  * supplied callback function is NULL, then all the externally visible USB devices
82  * in the device tree are enabled.
83  */
84 void usb_xhci_disable_unused(bool (*ext_usb_xhci_en_cb)(unsigned int port_type,
85 							unsigned int port_id));
86 #endif /* if !defined(__ACPI__) */
87 #endif	/* SOC_INTEL_COMMON_BLOCK_XHCI_H */
88