Raul E Rangel | a5b7ddf | 2020-05-29 17:16:20 -0600 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
| 2 | |
| 3 | #ifndef __DEVICE_XHCI_H__ |
| 4 | #define __DEVICE_XHCI_H__ |
| 5 | |
Robert Zieba | 4428195 | 2022-08-10 16:31:27 -0600 | [diff] [blame] | 6 | #include <types.h> |
Raul E Rangel | a5b7ddf | 2020-05-29 17:16:20 -0600 | [diff] [blame] | 7 | #include <device/device.h> |
Raul E Rangel | a5b7ddf | 2020-05-29 17:16:20 -0600 | [diff] [blame] | 8 | |
| 9 | #define XHCI_HCCPARAMS1_XECP 0x12 |
| 10 | |
| 11 | #define XHCI_ECP_CAP_ID_LEGACY 1 |
| 12 | #define XHCI_ECP_CAP_ID_SUPP 2 |
| 13 | |
Robert Zieba | 4428195 | 2022-08-10 16:31:27 -0600 | [diff] [blame] | 14 | /* Status flags */ |
| 15 | /* Wake on disconnect enable */ |
| 16 | #define XHCI_STATUS_WDE BIT(26) |
| 17 | /* Wake on connect enable */ |
| 18 | #define XHCI_STATUS_WCE BIT(25) |
| 19 | /* Port link status change */ |
| 20 | #define XHCI_STATUS_PLC BIT(22) |
| 21 | /* Connect status change */ |
| 22 | #define XHCI_STATUS_CSC BIT(17) |
| 23 | /* Port link status */ |
| 24 | #define XHCI_STATUS_PLS_SHIFT 5 |
| 25 | #define XHCI_STATUS_PLS_MASK (0xf << XHCI_STATUS_PLS_SHIFT) |
| 26 | #define XHCI_STATUS_PLS_RESUME (15 << XHCI_STATUS_PLS_SHIFT) |
| 27 | |
| 28 | static inline bool xhci_portsc_csc(uint32_t port_status) |
| 29 | { |
| 30 | return port_status & XHCI_STATUS_CSC; |
| 31 | } |
| 32 | |
| 33 | static inline bool xhci_portsc_wake_capable(uint32_t port_status) |
| 34 | { |
| 35 | return (port_status & XHCI_STATUS_WCE) | |
| 36 | (port_status & XHCI_STATUS_WDE); |
| 37 | } |
| 38 | |
| 39 | static inline bool xhci_portsc_plc(uint32_t port_status) |
| 40 | { |
| 41 | return port_status & XHCI_STATUS_PLC; |
| 42 | } |
| 43 | |
| 44 | static inline bool xhci_portsc_resume(uint32_t port_status) |
| 45 | { |
| 46 | return (port_status & XHCI_STATUS_PLS_MASK) == XHCI_STATUS_PLS_RESUME; |
| 47 | } |
| 48 | |
| 49 | |
Raul E Rangel | a5b7ddf | 2020-05-29 17:16:20 -0600 | [diff] [blame] | 50 | struct xhci_supported_protocol { |
| 51 | union { |
| 52 | uint32_t reg0; |
| 53 | struct { |
| 54 | uint32_t cap_id : 8; |
| 55 | uint32_t next_ptr : 8; |
| 56 | uint32_t minor_rev : 8; |
| 57 | uint32_t major_rev : 8; |
| 58 | }; |
| 59 | }; |
| 60 | union { |
| 61 | uint32_t reg1; |
| 62 | char name[4]; |
| 63 | }; |
| 64 | union { |
| 65 | uint32_t reg2; |
| 66 | struct { |
| 67 | uint32_t port_offset : 8; |
| 68 | uint32_t port_count : 8; |
| 69 | uint32_t reserved : 12; |
| 70 | uint32_t protocol_speed_id_count : 4; |
| 71 | }; |
| 72 | }; |
| 73 | }; |
| 74 | |
| 75 | struct xhci_ext_cap { |
| 76 | uint32_t cap_id; |
| 77 | /* cap_id is used to select the correct struct in the union. */ |
| 78 | union { |
| 79 | struct xhci_supported_protocol supported_protocol; |
| 80 | }; |
| 81 | }; |
| 82 | |
Robert Zieba | a23aa1c | 2022-08-10 16:56:09 -0600 | [diff] [blame] | 83 | /* |
| 84 | * struct xhci_usb_info - Data containing number of USB ports & offset. |
| 85 | * @usb2_port_status_reg: Offset to USB2 port status register. |
| 86 | * @num_usb2_ports: Number of USB2 ports. |
| 87 | * @usb3_port_status_reg: Offset to USB3 port status register. |
| 88 | * @num_usb3_ports: Number of USB3 ports. |
| 89 | */ |
| 90 | struct xhci_usb_info { |
| 91 | uint32_t usb2_port_status_reg; |
| 92 | uint32_t num_usb2_ports; |
| 93 | uint32_t usb3_port_status_reg; |
| 94 | uint32_t num_usb3_ports; |
| 95 | }; |
| 96 | |
Robert Zieba | eb7b589 | 2022-11-21 22:25:53 +0000 | [diff] [blame] | 97 | struct xhci_capability_regs { |
| 98 | uint8_t caplength; |
| 99 | uint8_t reserved0; |
| 100 | uint16_t hciversion; |
| 101 | uint32_t hcsparams1; |
| 102 | uint32_t hcsparams2; |
| 103 | uint32_t hcsparams3; |
| 104 | uint32_t hccparams1; |
| 105 | uint32_t dboff; |
| 106 | uint32_t rtsoff; |
| 107 | uint32_t hccparams2; |
| 108 | } __packed; |
| 109 | |
Raul E Rangel | a5b7ddf | 2020-05-29 17:16:20 -0600 | [diff] [blame] | 110 | /** |
| 111 | * Iterates over the xHCI Extended Capabilities List. |
| 112 | */ |
Robert Zieba | 219cb95 | 2022-11-18 18:06:28 +0000 | [diff] [blame] | 113 | enum cb_err xhci_resource_for_each_ext_cap(const struct resource *res, void *context, |
| 114 | void (*callback)(void *context, |
| 115 | const struct xhci_ext_cap *cap)); |
Raul E Rangel | a5b7ddf | 2020-05-29 17:16:20 -0600 | [diff] [blame] | 116 | enum cb_err xhci_for_each_ext_cap(const struct device *device, void *context, |
| 117 | void (*callback)(void *context, |
| 118 | const struct xhci_ext_cap *cap)); |
| 119 | |
Raul E Rangel | 2c952d6 | 2020-07-10 13:58:48 -0600 | [diff] [blame] | 120 | /** |
| 121 | * Helper method that iterates over only the USB supported capabilities structures in the |
| 122 | * xHCI Extended Capabilities List. |
| 123 | */ |
| 124 | enum cb_err xhci_for_each_supported_usb_cap( |
| 125 | const struct device *device, void *context, |
| 126 | void (*callback)(void *context, const struct xhci_supported_protocol *data)); |
Robert Zieba | 219cb95 | 2022-11-18 18:06:28 +0000 | [diff] [blame] | 127 | enum cb_err xhci_resource_for_each_supported_usb_cap( |
| 128 | const struct resource *res, void *context, |
| 129 | void (*callback)(void *context, const struct xhci_supported_protocol *data)); |
Raul E Rangel | 2c952d6 | 2020-07-10 13:58:48 -0600 | [diff] [blame] | 130 | |
Raul E Rangel | a5b7ddf | 2020-05-29 17:16:20 -0600 | [diff] [blame] | 131 | void xhci_print_supported_protocol(const struct xhci_supported_protocol *supported_protocol); |
| 132 | |
| 133 | #endif /* __DEVICE_XHCI_H__ */ |