Angel Pons | 182dbde | 2020-04-02 23:49:05 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 2 | |
| 3 | #include <console/console.h> |
Duncan Laurie | 1f52908 | 2013-07-30 15:53:45 -0700 | [diff] [blame] | 4 | #include <delay.h> |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 5 | #include <device/device.h> |
| 6 | #include <device/pci.h> |
| 7 | #include <device/pci_ids.h> |
Kyösti Mälkki | e2227a2 | 2014-02-05 13:02:55 +0200 | [diff] [blame] | 8 | #include <device/pci_ehci.h> |
Kyösti Mälkki | 13f6650 | 2019-03-03 08:01:05 +0200 | [diff] [blame] | 9 | #include <device/mmio.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 10 | #include <device/pci_ops.h> |
Duncan Laurie | 1f52908 | 2013-07-30 15:53:45 -0700 | [diff] [blame] | 11 | #include "pch.h" |
| 12 | |
Kyösti Mälkki | 21d6a27 | 2019-11-05 18:50:38 +0200 | [diff] [blame] | 13 | #ifdef __SIMPLE_DEVICE__ |
Duncan Laurie | 1f52908 | 2013-07-30 15:53:45 -0700 | [diff] [blame] | 14 | |
Elyes HAOUAS | ab72fc2 | 2018-11-29 16:13:14 +0100 | [diff] [blame] | 15 | void usb_ehci_disable(pci_devfn_t dev) |
Duncan Laurie | 1f52908 | 2013-07-30 15:53:45 -0700 | [diff] [blame] | 16 | { |
Duncan Laurie | 1f52908 | 2013-07-30 15:53:45 -0700 | [diff] [blame] | 17 | /* Set 0xDC[0]=1 */ |
| 18 | pci_or_config32(dev, 0xdc, (1 << 0)); |
| 19 | |
| 20 | /* Set D3Hot state and disable PME */ |
Angel Pons | bf9bc50 | 2020-06-08 00:12:43 +0200 | [diff] [blame^] | 21 | pci_update_config16(dev, EHCI_PWR_CTL_STS, ~(PWR_CTL_ENABLE_PME | PWR_CTL_SET_MASK), |
| 22 | PWR_CTL_SET_D3); |
Duncan Laurie | 1f52908 | 2013-07-30 15:53:45 -0700 | [diff] [blame] | 23 | |
| 24 | /* Clear memory and bus master */ |
| 25 | pci_write_config32(dev, PCI_BASE_ADDRESS_0, 0); |
Angel Pons | bf9bc50 | 2020-06-08 00:12:43 +0200 | [diff] [blame^] | 26 | |
| 27 | pci_and_config16(dev, PCI_COMMAND, |
| 28 | ~(PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY | PCI_COMMAND_IO)); |
Duncan Laurie | 1f52908 | 2013-07-30 15:53:45 -0700 | [diff] [blame] | 29 | |
| 30 | /* Disable device */ |
| 31 | switch (dev) { |
| 32 | case PCH_EHCI1_DEV: |
| 33 | RCBA32_OR(FD, PCH_DISABLE_EHCI1); |
| 34 | break; |
| 35 | case PCH_EHCI2_DEV: |
| 36 | RCBA32_OR(FD, PCH_DISABLE_EHCI2); |
| 37 | break; |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | /* Handler for EHCI controller on entry to S3/S4/S5 */ |
Elyes HAOUAS | ab72fc2 | 2018-11-29 16:13:14 +0100 | [diff] [blame] | 42 | void usb_ehci_sleep_prepare(pci_devfn_t dev, u8 slp_typ) |
Duncan Laurie | 1f52908 | 2013-07-30 15:53:45 -0700 | [diff] [blame] | 43 | { |
| 44 | u32 reg32; |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 45 | u8 *bar0_base; |
Duncan Laurie | 1f52908 | 2013-07-30 15:53:45 -0700 | [diff] [blame] | 46 | u16 pwr_state; |
| 47 | u16 pci_cmd; |
| 48 | |
| 49 | /* Check if the controller is disabled or not present */ |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 50 | bar0_base = (u8 *)pci_read_config32(dev, PCI_BASE_ADDRESS_0); |
| 51 | if (bar0_base == 0 || bar0_base == (u8 *)0xffffffff) |
Duncan Laurie | 1f52908 | 2013-07-30 15:53:45 -0700 | [diff] [blame] | 52 | return; |
Elyes HAOUAS | 73ae076 | 2020-04-28 10:13:05 +0200 | [diff] [blame] | 53 | pci_cmd = pci_read_config16(dev, PCI_COMMAND); |
Duncan Laurie | 1f52908 | 2013-07-30 15:53:45 -0700 | [diff] [blame] | 54 | |
| 55 | switch (slp_typ) { |
Aaron Durbin | da5f509 | 2016-07-13 23:23:16 -0500 | [diff] [blame] | 56 | case ACPI_S4: |
| 57 | case ACPI_S5: |
Duncan Laurie | 1f52908 | 2013-07-30 15:53:45 -0700 | [diff] [blame] | 58 | /* Check if controller is in D3 power state */ |
| 59 | pwr_state = pci_read_config16(dev, EHCI_PWR_CTL_STS); |
| 60 | if ((pwr_state & PWR_CTL_SET_MASK) == PWR_CTL_SET_D3) { |
| 61 | /* Put in D0 */ |
| 62 | u32 new_state = pwr_state & ~PWR_CTL_SET_MASK; |
| 63 | new_state |= PWR_CTL_SET_D0; |
| 64 | pci_write_config16(dev, EHCI_PWR_CTL_STS, new_state); |
| 65 | |
| 66 | /* Make sure memory bar is set */ |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 67 | pci_write_config32(dev, PCI_BASE_ADDRESS_0, (u32)bar0_base); |
Duncan Laurie | 1f52908 | 2013-07-30 15:53:45 -0700 | [diff] [blame] | 68 | |
| 69 | /* Make sure memory space is enabled */ |
| 70 | pci_write_config16(dev, PCI_COMMAND, pci_cmd | |
| 71 | PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY); |
| 72 | } |
| 73 | |
| 74 | /* |
| 75 | * If Run/Stop (bit0) is clear in USB2.0_CMD: |
| 76 | * - Clear Async Schedule Enable (bit5) and |
| 77 | * - Clear Periodic Schedule Enable (bit4) and |
| 78 | * - Set Run/Stop (bit0) |
| 79 | */ |
| 80 | reg32 = read32(bar0_base + EHCI_USB_CMD); |
| 81 | if (reg32 & EHCI_USB_CMD_RUN) { |
| 82 | reg32 &= ~(EHCI_USB_CMD_PSE | EHCI_USB_CMD_ASE); |
| 83 | reg32 |= EHCI_USB_CMD_RUN; |
| 84 | write32(bar0_base + EHCI_USB_CMD, reg32); |
| 85 | } |
| 86 | |
| 87 | /* Check for Port Enabled in PORTSC(0) (RMH) */ |
| 88 | reg32 = read32(bar0_base + EHCI_PORTSC(0)); |
| 89 | if (reg32 & EHCI_PORTSC_ENABLED) { |
| 90 | /* Set suspend bit in PORTSC if not already set */ |
| 91 | if (!(reg32 & EHCI_PORTSC_SUSPEND)) { |
| 92 | reg32 |= EHCI_PORTSC_SUSPEND; |
| 93 | write32(bar0_base + EHCI_PORTSC(0), reg32); |
| 94 | } |
| 95 | |
| 96 | /* Delay 25ms !! */ |
| 97 | udelay(25 * 1000); |
| 98 | |
| 99 | /* Clear Run/Stop bit */ |
| 100 | reg32 = read32(bar0_base + EHCI_USB_CMD); |
| 101 | reg32 &= EHCI_USB_CMD_RUN; |
| 102 | write32(bar0_base + EHCI_USB_CMD, reg32); |
| 103 | } |
| 104 | |
| 105 | /* Restore state to D3 if that is what it was at the start */ |
| 106 | if ((pwr_state & PWR_CTL_SET_MASK) == PWR_CTL_SET_D3) { |
| 107 | /* Restore pci command reg */ |
| 108 | pci_write_config16(dev, PCI_COMMAND, pci_cmd); |
| 109 | |
| 110 | /* Enable D3 */ |
| 111 | pci_write_config16(dev, EHCI_PWR_CTL_STS, pwr_state); |
| 112 | } |
| 113 | } |
| 114 | } |
| 115 | |
Kyösti Mälkki | 21d6a27 | 2019-11-05 18:50:38 +0200 | [diff] [blame] | 116 | #else /* !__SIMPLE_DEVICE__ */ |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 117 | |
Duncan Laurie | 2d9d39a | 2013-05-29 15:27:55 -0700 | [diff] [blame] | 118 | static void usb_ehci_clock_gating(struct device *dev) |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 119 | { |
Duncan Laurie | 2d9d39a | 2013-05-29 15:27:55 -0700 | [diff] [blame] | 120 | /* IOBP 0xE5004001[7:6] = 11b */ |
| 121 | pch_iobp_update(0xe5004001, ~0, (1 << 7)|(1 << 6)); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 122 | |
Duncan Laurie | 2d9d39a | 2013-05-29 15:27:55 -0700 | [diff] [blame] | 123 | /* Dx:F0:DCh[5,2,1] = 111b |
| 124 | * Dx:F0:DCh[0] = 1b when EHCI controller is disabled */ |
Angel Pons | bf9bc50 | 2020-06-08 00:12:43 +0200 | [diff] [blame^] | 125 | pci_or_config32(dev, 0xdc, (1 << 5) | (1 << 2) | (1 << 1)); |
Duncan Laurie | 2d9d39a | 2013-05-29 15:27:55 -0700 | [diff] [blame] | 126 | |
| 127 | /* Dx:F0:78h[1:0] = 11b */ |
Angel Pons | bf9bc50 | 2020-06-08 00:12:43 +0200 | [diff] [blame^] | 128 | pci_or_config32(dev, 0x78, (1 << 1) | (1 << 0)); |
Duncan Laurie | 2d9d39a | 2013-05-29 15:27:55 -0700 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | static void usb_ehci_init(struct device *dev) |
| 132 | { |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 133 | printk(BIOS_DEBUG, "EHCI: Setting up controller.. "); |
Duncan Laurie | 2d9d39a | 2013-05-29 15:27:55 -0700 | [diff] [blame] | 134 | |
| 135 | usb_ehci_clock_gating(dev); |
| 136 | |
| 137 | /* Disable Wake on Disconnect in RMH */ |
| 138 | RCBA32_OR(0x35b0, 0x00000022); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 139 | |
| 140 | printk(BIOS_DEBUG, "done.\n"); |
| 141 | } |
| 142 | |
Elyes HAOUAS | ab72fc2 | 2018-11-29 16:13:14 +0100 | [diff] [blame] | 143 | static void usb_ehci_set_subsystem(struct device *dev, unsigned int vendor, |
| 144 | unsigned int device) |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 145 | { |
| 146 | u8 access_cntl; |
| 147 | |
| 148 | access_cntl = pci_read_config8(dev, 0x80); |
| 149 | |
| 150 | /* Enable writes to protected registers. */ |
| 151 | pci_write_config8(dev, 0x80, access_cntl | 1); |
| 152 | |
Subrata Banik | 4a0f071 | 2019-03-20 14:29:47 +0530 | [diff] [blame] | 153 | pci_dev_set_subsystem(dev, vendor, device); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 154 | |
| 155 | /* Restore protection. */ |
| 156 | pci_write_config8(dev, 0x80, access_cntl); |
| 157 | } |
| 158 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 159 | static struct pci_operations lops_pci = { |
| 160 | .set_subsystem = &usb_ehci_set_subsystem, |
| 161 | }; |
| 162 | |
| 163 | static struct device_operations usb_ehci_ops = { |
Kyösti Mälkki | fb387df | 2013-06-07 22:16:52 +0300 | [diff] [blame] | 164 | .read_resources = pci_ehci_read_resources, |
| 165 | .set_resources = pci_dev_set_resources, |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 166 | .enable_resources = pci_dev_enable_resources, |
| 167 | .init = usb_ehci_init, |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 168 | .ops_pci = &lops_pci, |
| 169 | }; |
| 170 | |
Kyösti Mälkki | f55a542 | 2013-06-14 11:16:25 +0300 | [diff] [blame] | 171 | static const unsigned short pci_device_ids[] = { 0x9c26, 0x8c26, 0x8c2d, 0 }; |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 172 | |
| 173 | static const struct pci_driver pch_usb_ehci __pci_driver = { |
| 174 | .ops = &usb_ehci_ops, |
| 175 | .vendor = PCI_VENDOR_ID_INTEL, |
| 176 | .devices = pci_device_ids, |
| 177 | }; |
Duncan Laurie | 1f52908 | 2013-07-30 15:53:45 -0700 | [diff] [blame] | 178 | |
Kyösti Mälkki | 21d6a27 | 2019-11-05 18:50:38 +0200 | [diff] [blame] | 179 | #endif /* !__SIMPLE_DEVICE__ */ |