Angel Pons | 182dbde | 2020-04-02 23:49:05 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Duncan Laurie | 2d9d39a | 2013-05-29 15:27:55 -0700 | [diff] [blame] | 2 | |
Kyösti Mälkki | b486f29 | 2020-06-18 14:05:35 +0300 | [diff] [blame] | 3 | #include <cpu/x86/smm.h> |
Duncan Laurie | 1f52908 | 2013-07-30 15:53:45 -0700 | [diff] [blame] | 4 | #include <delay.h> |
Duncan Laurie | 2d9d39a | 2013-05-29 15:27:55 -0700 | [diff] [blame] | 5 | #include <device/device.h> |
| 6 | #include <device/pci.h> |
| 7 | #include <device/pci_ids.h> |
Kyösti Mälkki | 13f6650 | 2019-03-03 08:01:05 +0200 | [diff] [blame] | 8 | #include <device/mmio.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 9 | #include <device/pci_ops.h> |
Kyösti Mälkki | 12b121c | 2019-08-18 16:33:39 +0300 | [diff] [blame] | 10 | #include "chip.h" |
Angel Pons | 2178b72 | 2020-05-31 00:55:35 +0200 | [diff] [blame] | 11 | #include "iobp.h" |
Duncan Laurie | 2d9d39a | 2013-05-29 15:27:55 -0700 | [diff] [blame] | 12 | #include "pch.h" |
| 13 | |
Stefan Reinauer | 6dbbe2e | 2013-10-17 17:00:26 -0700 | [diff] [blame] | 14 | typedef struct southbridge_intel_lynxpoint_config config_t; |
| 15 | |
Elyes HAOUAS | 1dcd8db | 2018-12-05 10:59:42 +0100 | [diff] [blame] | 16 | #ifdef __SIMPLE_DEVICE__ |
| 17 | static u8 *usb_xhci_mem_base(pci_devfn_t dev) |
| 18 | #else |
| 19 | static u8 *usb_xhci_mem_base(struct device *dev) |
| 20 | #endif |
Duncan Laurie | 1f52908 | 2013-07-30 15:53:45 -0700 | [diff] [blame] | 21 | { |
| 22 | u32 mem_base = pci_read_config32(dev, PCI_BASE_ADDRESS_0); |
| 23 | |
| 24 | /* Check if the controller is disabled or not present */ |
| 25 | if (mem_base == 0 || mem_base == 0xffffffff) |
| 26 | return 0; |
| 27 | |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 28 | return (u8 *)(mem_base & ~0xf); |
Duncan Laurie | 1f52908 | 2013-07-30 15:53:45 -0700 | [diff] [blame] | 29 | } |
| 30 | |
Elyes HAOUAS | 1dcd8db | 2018-12-05 10:59:42 +0100 | [diff] [blame] | 31 | #ifdef __SIMPLE_DEVICE__ |
| 32 | static int usb_xhci_port_count_usb3(pci_devfn_t dev) |
| 33 | #else |
| 34 | static int usb_xhci_port_count_usb3(struct device *dev) |
| 35 | #endif |
Duncan Laurie | 1f52908 | 2013-07-30 15:53:45 -0700 | [diff] [blame] | 36 | { |
| 37 | if (pch_is_lp()) { |
| 38 | /* LynxPoint-LP has 4 SS ports */ |
| 39 | return 4; |
Duncan Laurie | 1f52908 | 2013-07-30 15:53:45 -0700 | [diff] [blame] | 40 | } |
Elyes HAOUAS | 54f9424 | 2018-10-25 10:57:39 +0200 | [diff] [blame] | 41 | /* LynxPoint-H can have 0, 2, 4, or 6 SS ports */ |
| 42 | u8 *mem_base = usb_xhci_mem_base(dev); |
| 43 | u32 fus = read32(mem_base + XHCI_USB3FUS); |
| 44 | fus >>= XHCI_USB3FUS_SS_SHIFT; |
| 45 | fus &= XHCI_USB3FUS_SS_MASK; |
| 46 | switch (fus) { |
| 47 | case 3: return 0; |
| 48 | case 2: return 2; |
| 49 | case 1: return 4; |
| 50 | case 0: |
| 51 | default: return 6; |
| 52 | } |
Duncan Laurie | 1f52908 | 2013-07-30 15:53:45 -0700 | [diff] [blame] | 53 | } |
| 54 | |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 55 | static void usb_xhci_reset_status_usb3(u8 *mem_base, int port) |
Duncan Laurie | 1f52908 | 2013-07-30 15:53:45 -0700 | [diff] [blame] | 56 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 57 | u8 *portsc = mem_base + XHCI_USB3_PORTSC(port); |
Duncan Laurie | 0bf1dea | 2013-08-13 13:32:28 -0700 | [diff] [blame] | 58 | u32 status = read32(portsc); |
| 59 | /* Do not set Port Enabled/Disabled field */ |
| 60 | status &= ~XHCI_USB3_PORTSC_PED; |
| 61 | /* Clear all change status bits */ |
| 62 | status |= XHCI_USB3_PORTSC_CHST; |
| 63 | write32(portsc, status); |
Duncan Laurie | 1f52908 | 2013-07-30 15:53:45 -0700 | [diff] [blame] | 64 | } |
| 65 | |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 66 | static void usb_xhci_reset_port_usb3(u8 *mem_base, int port) |
Duncan Laurie | 1f52908 | 2013-07-30 15:53:45 -0700 | [diff] [blame] | 67 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 68 | u8 *portsc = mem_base + XHCI_USB3_PORTSC(port); |
Duncan Laurie | 1f52908 | 2013-07-30 15:53:45 -0700 | [diff] [blame] | 69 | write32(portsc, read32(portsc) | XHCI_USB3_PORTSC_WPR); |
| 70 | } |
| 71 | |
| 72 | #define XHCI_RESET_DELAY_US 1000 /* 1ms */ |
| 73 | #define XHCI_RESET_TIMEOUT 100 /* 100ms */ |
| 74 | |
| 75 | /* |
| 76 | * 1) Wait until port is done polling |
| 77 | * 2) If port is disconnected |
| 78 | * a) Issue warm port reset |
| 79 | * b) Poll for warm reset complete |
| 80 | * c) Write 1 to port change status bits |
| 81 | */ |
Elyes HAOUAS | 1dcd8db | 2018-12-05 10:59:42 +0100 | [diff] [blame] | 82 | #ifdef __SIMPLE_DEVICE__ |
| 83 | static void usb_xhci_reset_usb3(pci_devfn_t dev, int all) |
| 84 | #else |
| 85 | static void usb_xhci_reset_usb3(struct device *dev, int all) |
| 86 | #endif |
Duncan Laurie | 1f52908 | 2013-07-30 15:53:45 -0700 | [diff] [blame] | 87 | { |
| 88 | u32 status, port_disabled; |
| 89 | int timeout, port; |
| 90 | int port_count = usb_xhci_port_count_usb3(dev); |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 91 | u8 *mem_base = usb_xhci_mem_base(dev); |
Duncan Laurie | 1f52908 | 2013-07-30 15:53:45 -0700 | [diff] [blame] | 92 | |
| 93 | if (!mem_base || !port_count) |
| 94 | return; |
| 95 | |
| 96 | /* Get mask of disabled ports */ |
| 97 | port_disabled = pci_read_config32(dev, XHCI_USB3PDO); |
| 98 | |
| 99 | /* Wait until all enabled ports are done polling */ |
| 100 | for (timeout = XHCI_RESET_TIMEOUT; timeout; timeout--) { |
| 101 | int complete = 1; |
| 102 | for (port = 0; port < port_count; port++) { |
| 103 | /* Skip disabled ports */ |
| 104 | if (port_disabled & (1 << port)) |
| 105 | continue; |
| 106 | /* Read port link status field */ |
| 107 | status = read32(mem_base + XHCI_USB3_PORTSC(port)); |
| 108 | status &= XHCI_USB3_PORTSC_PLS; |
| 109 | if (status == XHCI_PLSR_POLLING) |
| 110 | complete = 0; |
| 111 | } |
| 112 | /* Exit if all ports not polling */ |
| 113 | if (complete) |
| 114 | break; |
| 115 | udelay(XHCI_RESET_DELAY_US); |
| 116 | } |
| 117 | |
| 118 | /* Reset all requested ports */ |
| 119 | for (port = 0; port < port_count; port++) { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 120 | u8 *portsc = mem_base + XHCI_USB3_PORTSC(port); |
Duncan Laurie | 1f52908 | 2013-07-30 15:53:45 -0700 | [diff] [blame] | 121 | /* Skip disabled ports */ |
| 122 | if (port_disabled & (1 << port)) |
| 123 | continue; |
| 124 | status = read32(portsc) & XHCI_USB3_PORTSC_PLS; |
| 125 | /* Reset all or only disconnected ports */ |
Duncan Laurie | 32d2e2b | 2013-09-25 14:08:32 -0700 | [diff] [blame] | 126 | if (all || (status == XHCI_PLSR_RXDETECT || |
| 127 | status == XHCI_PLSR_POLLING)) |
Duncan Laurie | 16a0f5c | 2013-09-25 14:08:16 -0700 | [diff] [blame] | 128 | usb_xhci_reset_port_usb3(mem_base, port); |
| 129 | else |
| 130 | port_disabled |= 1 << port; |
Duncan Laurie | 1f52908 | 2013-07-30 15:53:45 -0700 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | /* Wait for warm reset complete on all reset ports */ |
| 134 | for (timeout = XHCI_RESET_TIMEOUT; timeout; timeout--) { |
| 135 | int complete = 1; |
| 136 | for (port = 0; port < port_count; port++) { |
| 137 | /* Only check ports that were reset */ |
| 138 | if (port_disabled & (1 << port)) |
| 139 | continue; |
| 140 | /* Check if warm reset is complete */ |
| 141 | status = read32(mem_base + XHCI_USB3_PORTSC(port)); |
| 142 | if (!(status & XHCI_USB3_PORTSC_WRC)) |
| 143 | complete = 0; |
| 144 | } |
| 145 | /* Check for warm reset complete in any port */ |
| 146 | if (complete) |
| 147 | break; |
| 148 | udelay(XHCI_RESET_DELAY_US); |
| 149 | } |
| 150 | |
| 151 | /* Clear port change status bits */ |
| 152 | for (port = 0; port < port_count; port++) |
| 153 | usb_xhci_reset_status_usb3(mem_base, port); |
| 154 | } |
| 155 | |
Kyösti Mälkki | 21d6a27 | 2019-11-05 18:50:38 +0200 | [diff] [blame] | 156 | #ifdef __SIMPLE_DEVICE__ |
Duncan Laurie | 32d2e2b | 2013-09-25 14:08:32 -0700 | [diff] [blame] | 157 | |
Duncan Laurie | 1f52908 | 2013-07-30 15:53:45 -0700 | [diff] [blame] | 158 | /* Handler for XHCI controller on entry to S3/S4/S5 */ |
Elyes HAOUAS | ab72fc2 | 2018-11-29 16:13:14 +0100 | [diff] [blame] | 159 | void usb_xhci_sleep_prepare(pci_devfn_t dev, u8 slp_typ) |
Duncan Laurie | 1f52908 | 2013-07-30 15:53:45 -0700 | [diff] [blame] | 160 | { |
Duncan Laurie | 1f52908 | 2013-07-30 15:53:45 -0700 | [diff] [blame] | 161 | u32 reg32; |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 162 | u8 *mem_base = usb_xhci_mem_base(dev); |
Duncan Laurie | 1f52908 | 2013-07-30 15:53:45 -0700 | [diff] [blame] | 163 | |
Aaron Durbin | da5f509 | 2016-07-13 23:23:16 -0500 | [diff] [blame] | 164 | if (!mem_base || slp_typ < ACPI_S3) |
Duncan Laurie | 1f52908 | 2013-07-30 15:53:45 -0700 | [diff] [blame] | 165 | return; |
| 166 | |
| 167 | if (pch_is_lp()) { |
| 168 | /* Set D0 state */ |
Angel Pons | bf9bc50 | 2020-06-08 00:12:43 +0200 | [diff] [blame] | 169 | pci_update_config16(dev, XHCI_PWR_CTL_STS, ~PWR_CTL_SET_MASK, PWR_CTL_SET_D0); |
Duncan Laurie | 1f52908 | 2013-07-30 15:53:45 -0700 | [diff] [blame] | 170 | |
| 171 | /* Clear PCI 0xB0[14:13] */ |
Angel Pons | bf9bc50 | 2020-06-08 00:12:43 +0200 | [diff] [blame] | 172 | pci_and_config32(dev, 0xb0, ~((1 << 14) | (1 << 13))); |
Duncan Laurie | 1f52908 | 2013-07-30 15:53:45 -0700 | [diff] [blame] | 173 | |
| 174 | /* Clear MMIO 0x816c[14,2] */ |
| 175 | reg32 = read32(mem_base + 0x816c); |
| 176 | reg32 &= ~((1 << 14) | (1 << 2)); |
| 177 | write32(mem_base + 0x816c, reg32); |
| 178 | |
Duncan Laurie | 0bf1dea | 2013-08-13 13:32:28 -0700 | [diff] [blame] | 179 | /* Reset disconnected USB3 ports */ |
Duncan Laurie | 16a0f5c | 2013-09-25 14:08:16 -0700 | [diff] [blame] | 180 | usb_xhci_reset_usb3(dev, 0); |
Duncan Laurie | 0bf1dea | 2013-08-13 13:32:28 -0700 | [diff] [blame] | 181 | |
Duncan Laurie | 1f52908 | 2013-07-30 15:53:45 -0700 | [diff] [blame] | 182 | /* Set MMIO 0x80e0[15] */ |
| 183 | reg32 = read32(mem_base + 0x80e0); |
| 184 | reg32 |= (1 << 15); |
| 185 | write32(mem_base + 0x80e0, reg32); |
| 186 | } |
| 187 | |
| 188 | /* Set D3Hot state and enable PME */ |
| 189 | pci_or_config16(dev, XHCI_PWR_CTL_STS, PWR_CTL_SET_D3); |
Duncan Laurie | 0bf1dea | 2013-08-13 13:32:28 -0700 | [diff] [blame] | 190 | pci_or_config16(dev, XHCI_PWR_CTL_STS, PWR_CTL_STATUS_PME); |
Duncan Laurie | 1f52908 | 2013-07-30 15:53:45 -0700 | [diff] [blame] | 191 | pci_or_config16(dev, XHCI_PWR_CTL_STS, PWR_CTL_ENABLE_PME); |
| 192 | } |
| 193 | |
Duncan Laurie | 911cedf | 2013-07-30 16:05:55 -0700 | [diff] [blame] | 194 | /* Route all ports to XHCI controller */ |
| 195 | void usb_xhci_route_all(void) |
| 196 | { |
| 197 | u32 port_mask, route; |
Duncan Laurie | 911cedf | 2013-07-30 16:05:55 -0700 | [diff] [blame] | 198 | |
| 199 | /* Skip if EHCI is already disabled */ |
| 200 | if (RCBA32(FD) & PCH_DISABLE_EHCI1) |
| 201 | return; |
| 202 | |
| 203 | /* Set D0 state */ |
Angel Pons | bf9bc50 | 2020-06-08 00:12:43 +0200 | [diff] [blame] | 204 | pci_update_config16(PCH_XHCI_DEV, XHCI_PWR_CTL_STS, ~PWR_CTL_SET_MASK, PWR_CTL_SET_D0); |
Duncan Laurie | 911cedf | 2013-07-30 16:05:55 -0700 | [diff] [blame] | 205 | |
| 206 | /* Set USB3 superspeed enable */ |
| 207 | port_mask = pci_read_config32(PCH_XHCI_DEV, XHCI_USB3PRM); |
| 208 | route = pci_read_config32(PCH_XHCI_DEV, XHCI_USB3PR); |
| 209 | route &= ~XHCI_USB3PR_SSEN; |
| 210 | route |= XHCI_USB3PR_SSEN & port_mask; |
| 211 | pci_write_config32(PCH_XHCI_DEV, XHCI_USB3PR, route); |
| 212 | |
| 213 | /* Route USB2 ports to XHCI controller */ |
| 214 | port_mask = pci_read_config32(PCH_XHCI_DEV, XHCI_USB2PRM); |
| 215 | route = pci_read_config32(PCH_XHCI_DEV, XHCI_USB2PR); |
| 216 | route &= ~XHCI_USB2PR_HCSEL; |
| 217 | route |= XHCI_USB2PR_HCSEL & port_mask; |
| 218 | pci_write_config32(PCH_XHCI_DEV, XHCI_USB2PR, route); |
| 219 | |
| 220 | /* Disable EHCI controller */ |
| 221 | usb_ehci_disable(PCH_EHCI1_DEV); |
| 222 | |
| 223 | /* LynxPoint-H has a second EHCI controller */ |
| 224 | if (!pch_is_lp()) |
| 225 | usb_ehci_disable(PCH_EHCI2_DEV); |
| 226 | |
| 227 | /* Reset and clear port change status */ |
Duncan Laurie | 16a0f5c | 2013-09-25 14:08:16 -0700 | [diff] [blame] | 228 | usb_xhci_reset_usb3(PCH_XHCI_DEV, 1); |
Duncan Laurie | 911cedf | 2013-07-30 16:05:55 -0700 | [diff] [blame] | 229 | } |
| 230 | |
Kyösti Mälkki | 21d6a27 | 2019-11-05 18:50:38 +0200 | [diff] [blame] | 231 | #else /* !__SIMPLE_DEVICE__ */ |
Duncan Laurie | 1f52908 | 2013-07-30 15:53:45 -0700 | [diff] [blame] | 232 | |
Elyes HAOUAS | ab72fc2 | 2018-11-29 16:13:14 +0100 | [diff] [blame] | 233 | static void usb_xhci_clock_gating(struct device *dev) |
Duncan Laurie | 2d9d39a | 2013-05-29 15:27:55 -0700 | [diff] [blame] | 234 | { |
| 235 | u32 reg32; |
| 236 | |
| 237 | /* IOBP 0xE5004001[7:6] = 11b */ |
Angel Pons | 84fa224 | 2020-10-24 11:53:47 +0200 | [diff] [blame] | 238 | pch_iobp_update(0xe5004001, ~0, (1 << 7) | (1 << 6)); |
Duncan Laurie | 2d9d39a | 2013-05-29 15:27:55 -0700 | [diff] [blame] | 239 | |
| 240 | reg32 = pci_read_config32(dev, 0x40); |
| 241 | reg32 &= ~(1 << 23); /* unsupported request */ |
| 242 | |
| 243 | if (pch_is_lp()) { |
| 244 | /* D20:F0:40h[18,17,8] = 111b */ |
| 245 | reg32 |= (1 << 18) | (1 << 17) | (1 << 8); |
| 246 | /* D20:F0:40h[21,20,19] = 110b to enable XHCI Idle L1 */ |
| 247 | reg32 &= ~(1 << 19); |
| 248 | reg32 |= (1 << 21) | (1 << 20); |
| 249 | } else { |
| 250 | /* D20:F0:40h[21,20,18,17,8] = 11111b */ |
Angel Pons | 84fa224 | 2020-10-24 11:53:47 +0200 | [diff] [blame] | 251 | reg32 |= (1 << 21) | (1 << 20) | (1 << 18) | (1 << 17) | (1 << 8); |
Duncan Laurie | 2d9d39a | 2013-05-29 15:27:55 -0700 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | /* Avoid writing upper byte as it is write-once */ |
| 255 | pci_write_config16(dev, 0x40, (u16)(reg32 & 0xffff)); |
| 256 | pci_write_config8(dev, 0x40 + 2, (u8)((reg32 >> 16) & 0xff)); |
| 257 | |
| 258 | /* D20:F0:44h[9,7,3] = 111b */ |
Angel Pons | bf9bc50 | 2020-06-08 00:12:43 +0200 | [diff] [blame] | 259 | pci_or_config16(dev, 0x44, (1 << 9) | (1 << 7) | (1 << 3)); |
Duncan Laurie | 2d9d39a | 2013-05-29 15:27:55 -0700 | [diff] [blame] | 260 | |
| 261 | reg32 = pci_read_config32(dev, 0xa0); |
| 262 | if (pch_is_lp()) { |
| 263 | /* D20:F0:A0h[18] = 1 */ |
| 264 | reg32 |= (1 << 18); |
| 265 | } else { |
| 266 | /* D20:F0:A0h[6] = 1 */ |
| 267 | reg32 |= (1 << 6); |
| 268 | } |
| 269 | pci_write_config32(dev, 0xa0, reg32); |
| 270 | |
| 271 | /* D20:F0:A4h[13] = 0 */ |
Angel Pons | bf9bc50 | 2020-06-08 00:12:43 +0200 | [diff] [blame] | 272 | pci_and_config32(dev, 0xa4, ~(1 << 13)); |
Duncan Laurie | 2d9d39a | 2013-05-29 15:27:55 -0700 | [diff] [blame] | 273 | } |
| 274 | |
Elyes HAOUAS | ab72fc2 | 2018-11-29 16:13:14 +0100 | [diff] [blame] | 275 | static void usb_xhci_init(struct device *dev) |
Duncan Laurie | 2d9d39a | 2013-05-29 15:27:55 -0700 | [diff] [blame] | 276 | { |
Duncan Laurie | 2d9d39a | 2013-05-29 15:27:55 -0700 | [diff] [blame] | 277 | u32 reg32; |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 278 | u8 *mem_base = usb_xhci_mem_base(dev); |
Stefan Reinauer | 6dbbe2e | 2013-10-17 17:00:26 -0700 | [diff] [blame] | 279 | config_t *config = dev->chip_info; |
Duncan Laurie | 2d9d39a | 2013-05-29 15:27:55 -0700 | [diff] [blame] | 280 | |
Duncan Laurie | 0dcb577 | 2013-07-30 15:58:18 -0700 | [diff] [blame] | 281 | /* D20:F0:74h[1:0] = 00b (set D0 state) */ |
Angel Pons | bf9bc50 | 2020-06-08 00:12:43 +0200 | [diff] [blame] | 282 | pci_update_config16(dev, XHCI_PWR_CTL_STS, ~PWR_CTL_SET_MASK, PWR_CTL_SET_D0); |
Duncan Laurie | 2d9d39a | 2013-05-29 15:27:55 -0700 | [diff] [blame] | 283 | |
| 284 | /* Enable clock gating first */ |
| 285 | usb_xhci_clock_gating(dev); |
| 286 | |
Duncan Laurie | 0dcb577 | 2013-07-30 15:58:18 -0700 | [diff] [blame] | 287 | reg32 = read32(mem_base + 0x8144); |
Duncan Laurie | 2d9d39a | 2013-05-29 15:27:55 -0700 | [diff] [blame] | 288 | if (pch_is_lp()) { |
| 289 | /* XHCIBAR + 8144h[8,7,6] = 111b */ |
| 290 | reg32 |= (1 << 8) | (1 << 7) | (1 << 6); |
| 291 | } else { |
| 292 | /* XHCIBAR + 8144h[8,7,6] = 100b */ |
| 293 | reg32 &= ~((1 << 7) | (1 << 6)); |
| 294 | reg32 |= (1 << 8); |
| 295 | } |
Duncan Laurie | 0dcb577 | 2013-07-30 15:58:18 -0700 | [diff] [blame] | 296 | write32(mem_base + 0x8144, reg32); |
Duncan Laurie | 2d9d39a | 2013-05-29 15:27:55 -0700 | [diff] [blame] | 297 | |
| 298 | if (pch_is_lp()) { |
Duncan Laurie | 527b03a | 2013-08-28 09:53:50 -0700 | [diff] [blame] | 299 | /* XHCIBAR + 816Ch[19:0] = 000e0038h */ |
Duncan Laurie | 0dcb577 | 2013-07-30 15:58:18 -0700 | [diff] [blame] | 300 | reg32 = read32(mem_base + 0x816c); |
Duncan Laurie | 2d9d39a | 2013-05-29 15:27:55 -0700 | [diff] [blame] | 301 | reg32 &= ~0x000fffff; |
Duncan Laurie | 527b03a | 2013-08-28 09:53:50 -0700 | [diff] [blame] | 302 | reg32 |= 0x000e0038; |
Duncan Laurie | 0dcb577 | 2013-07-30 15:58:18 -0700 | [diff] [blame] | 303 | write32(mem_base + 0x816c, reg32); |
Duncan Laurie | 2d9d39a | 2013-05-29 15:27:55 -0700 | [diff] [blame] | 304 | |
| 305 | /* D20:F0:B0h[17,14,13] = 100b */ |
Angel Pons | bf9bc50 | 2020-06-08 00:12:43 +0200 | [diff] [blame] | 306 | pci_update_config32(dev, 0xb0, ~((1 << 14) | (1 << 13)), 1 << 17); |
Duncan Laurie | 2d9d39a | 2013-05-29 15:27:55 -0700 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | reg32 = pci_read_config32(dev, 0x50); |
| 310 | if (pch_is_lp()) { |
| 311 | /* D20:F0:50h[28:0] = 0FCE2E5Fh */ |
| 312 | reg32 &= ~0x1fffffff; |
| 313 | reg32 |= 0x0fce2e5f; |
| 314 | } else { |
| 315 | /* D20:F0:50h[26:0] = 07886E9Fh */ |
| 316 | reg32 &= ~0x07ffffff; |
| 317 | reg32 |= 0x07886e9f; |
| 318 | } |
| 319 | pci_write_config32(dev, 0x50, reg32); |
| 320 | |
| 321 | /* D20:F0:44h[31] = 1 (Access Control Bit) */ |
Angel Pons | bf9bc50 | 2020-06-08 00:12:43 +0200 | [diff] [blame] | 322 | pci_or_config32(dev, 0x44, 1 << 31); |
Duncan Laurie | 2d9d39a | 2013-05-29 15:27:55 -0700 | [diff] [blame] | 323 | |
| 324 | /* D20:F0:40h[31,23] = 10b (OC Configuration Done) */ |
Angel Pons | bf9bc50 | 2020-06-08 00:12:43 +0200 | [diff] [blame] | 325 | pci_update_config32(dev, 0x40, ~(1 << 23), 1 << 31); /* unsupported request */ |
Duncan Laurie | 32d2e2b | 2013-09-25 14:08:32 -0700 | [diff] [blame] | 326 | |
| 327 | if (acpi_is_wakeup_s3()) { |
| 328 | /* Reset ports that are disabled or |
| 329 | * polling before returning to the OS. */ |
| 330 | usb_xhci_reset_usb3(dev, 0); |
Angel Pons | cbcbb67 | 2020-10-23 00:11:26 +0200 | [diff] [blame] | 331 | } else if (config && config->xhci_default) { |
Stefan Reinauer | 6dbbe2e | 2013-10-17 17:00:26 -0700 | [diff] [blame] | 332 | /* Route all ports to XHCI */ |
Kyösti Mälkki | b486f29 | 2020-06-18 14:05:35 +0300 | [diff] [blame] | 333 | apm_control(APM_CNT_ROUTE_ALL_XHCI); |
Duncan Laurie | 32d2e2b | 2013-09-25 14:08:32 -0700 | [diff] [blame] | 334 | } |
Duncan Laurie | 2d9d39a | 2013-05-29 15:27:55 -0700 | [diff] [blame] | 335 | } |
| 336 | |
Duncan Laurie | 2d9d39a | 2013-05-29 15:27:55 -0700 | [diff] [blame] | 337 | static struct device_operations usb_xhci_ops = { |
| 338 | .read_resources = pci_dev_read_resources, |
| 339 | .set_resources = pci_dev_set_resources, |
| 340 | .enable_resources = pci_dev_enable_resources, |
| 341 | .init = usb_xhci_init, |
Angel Pons | 1fc0edd | 2020-05-31 00:03:28 +0200 | [diff] [blame] | 342 | .ops_pci = &pci_dev_ops_pci, |
Duncan Laurie | 2d9d39a | 2013-05-29 15:27:55 -0700 | [diff] [blame] | 343 | }; |
| 344 | |
Felix Singer | 4ea08f9 | 2020-11-20 12:56:44 +0000 | [diff] [blame] | 345 | static const unsigned short pci_device_ids[] = { |
| 346 | PCI_DEVICE_ID_INTEL_LPT_H_XHCI, |
| 347 | PCI_DEVICE_ID_INTEL_LPT_LP_XHCI, |
| 348 | 0 |
| 349 | }; |
Duncan Laurie | 2d9d39a | 2013-05-29 15:27:55 -0700 | [diff] [blame] | 350 | |
| 351 | static const struct pci_driver pch_usb_xhci __pci_driver = { |
| 352 | .ops = &usb_xhci_ops, |
| 353 | .vendor = PCI_VENDOR_ID_INTEL, |
| 354 | .devices = pci_device_ids, |
| 355 | }; |
Kyösti Mälkki | 21d6a27 | 2019-11-05 18:50:38 +0200 | [diff] [blame] | 356 | #endif /* !__SIMPLE_DEVICE__ */ |