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