blob: 574b6d17f501934eaee14261578162f9447cae03 [file] [log] [blame]
Aaron Durbin76c37002012-10-30 09:03:43 -05001/*
2 * This file is part of the coreboot project.
3 *
Aaron Durbin76c37002012-10-30 09:03:43 -05004 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; version 2 of
8 * the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
Aaron Durbin76c37002012-10-30 09:03:43 -050014 */
15
16#include <console/console.h>
Duncan Laurie1f529082013-07-30 15:53:45 -070017#include <delay.h>
Aaron Durbin76c37002012-10-30 09:03:43 -050018#include <device/device.h>
19#include <device/pci.h>
20#include <device/pci_ids.h>
Kyösti Mälkkie2227a22014-02-05 13:02:55 +020021#include <device/pci_ehci.h>
Kyösti Mälkki13f66502019-03-03 08:01:05 +020022#include <device/mmio.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020023#include <device/pci_ops.h>
Duncan Laurie1f529082013-07-30 15:53:45 -070024#include "pch.h"
25
Kyösti Mälkki21d6a272019-11-05 18:50:38 +020026#ifdef __SIMPLE_DEVICE__
Duncan Laurie1f529082013-07-30 15:53:45 -070027
Elyes HAOUASab72fc22018-11-29 16:13:14 +010028void usb_ehci_disable(pci_devfn_t dev)
Duncan Laurie1f529082013-07-30 15:53:45 -070029{
30 u16 reg16;
31 u32 reg32;
32
33 /* Set 0xDC[0]=1 */
34 pci_or_config32(dev, 0xdc, (1 << 0));
35
36 /* Set D3Hot state and disable PME */
37 reg16 = pci_read_config16(dev, EHCI_PWR_CTL_STS);
38 reg16 &= ~(PWR_CTL_ENABLE_PME | PWR_CTL_SET_MASK);
39 reg16 |= PWR_CTL_SET_D3;
40 pci_write_config16(dev, EHCI_PWR_CTL_STS, reg16);
41
42 /* Clear memory and bus master */
43 pci_write_config32(dev, PCI_BASE_ADDRESS_0, 0);
44 reg32 = pci_read_config32(dev, PCI_COMMAND);
45 reg32 &= ~(PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
46 pci_write_config32(dev, PCI_COMMAND, reg32);
47
48 /* Disable device */
49 switch (dev) {
50 case PCH_EHCI1_DEV:
51 RCBA32_OR(FD, PCH_DISABLE_EHCI1);
52 break;
53 case PCH_EHCI2_DEV:
54 RCBA32_OR(FD, PCH_DISABLE_EHCI2);
55 break;
56 }
57}
58
59/* Handler for EHCI controller on entry to S3/S4/S5 */
Elyes HAOUASab72fc22018-11-29 16:13:14 +010060void usb_ehci_sleep_prepare(pci_devfn_t dev, u8 slp_typ)
Duncan Laurie1f529082013-07-30 15:53:45 -070061{
62 u32 reg32;
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080063 u8 *bar0_base;
Duncan Laurie1f529082013-07-30 15:53:45 -070064 u16 pwr_state;
65 u16 pci_cmd;
66
67 /* Check if the controller is disabled or not present */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080068 bar0_base = (u8 *)pci_read_config32(dev, PCI_BASE_ADDRESS_0);
69 if (bar0_base == 0 || bar0_base == (u8 *)0xffffffff)
Duncan Laurie1f529082013-07-30 15:53:45 -070070 return;
71 pci_cmd = pci_read_config32(dev, PCI_COMMAND);
72
73 switch (slp_typ) {
Aaron Durbinda5f5092016-07-13 23:23:16 -050074 case ACPI_S4:
75 case ACPI_S5:
Duncan Laurie1f529082013-07-30 15:53:45 -070076 /* Check if controller is in D3 power state */
77 pwr_state = pci_read_config16(dev, EHCI_PWR_CTL_STS);
78 if ((pwr_state & PWR_CTL_SET_MASK) == PWR_CTL_SET_D3) {
79 /* Put in D0 */
80 u32 new_state = pwr_state & ~PWR_CTL_SET_MASK;
81 new_state |= PWR_CTL_SET_D0;
82 pci_write_config16(dev, EHCI_PWR_CTL_STS, new_state);
83
84 /* Make sure memory bar is set */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080085 pci_write_config32(dev, PCI_BASE_ADDRESS_0, (u32)bar0_base);
Duncan Laurie1f529082013-07-30 15:53:45 -070086
87 /* Make sure memory space is enabled */
88 pci_write_config16(dev, PCI_COMMAND, pci_cmd |
89 PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY);
90 }
91
92 /*
93 * If Run/Stop (bit0) is clear in USB2.0_CMD:
94 * - Clear Async Schedule Enable (bit5) and
95 * - Clear Periodic Schedule Enable (bit4) and
96 * - Set Run/Stop (bit0)
97 */
98 reg32 = read32(bar0_base + EHCI_USB_CMD);
99 if (reg32 & EHCI_USB_CMD_RUN) {
100 reg32 &= ~(EHCI_USB_CMD_PSE | EHCI_USB_CMD_ASE);
101 reg32 |= EHCI_USB_CMD_RUN;
102 write32(bar0_base + EHCI_USB_CMD, reg32);
103 }
104
105 /* Check for Port Enabled in PORTSC(0) (RMH) */
106 reg32 = read32(bar0_base + EHCI_PORTSC(0));
107 if (reg32 & EHCI_PORTSC_ENABLED) {
108 /* Set suspend bit in PORTSC if not already set */
109 if (!(reg32 & EHCI_PORTSC_SUSPEND)) {
110 reg32 |= EHCI_PORTSC_SUSPEND;
111 write32(bar0_base + EHCI_PORTSC(0), reg32);
112 }
113
114 /* Delay 25ms !! */
115 udelay(25 * 1000);
116
117 /* Clear Run/Stop bit */
118 reg32 = read32(bar0_base + EHCI_USB_CMD);
119 reg32 &= EHCI_USB_CMD_RUN;
120 write32(bar0_base + EHCI_USB_CMD, reg32);
121 }
122
123 /* Restore state to D3 if that is what it was at the start */
124 if ((pwr_state & PWR_CTL_SET_MASK) == PWR_CTL_SET_D3) {
125 /* Restore pci command reg */
126 pci_write_config16(dev, PCI_COMMAND, pci_cmd);
127
128 /* Enable D3 */
129 pci_write_config16(dev, EHCI_PWR_CTL_STS, pwr_state);
130 }
131 }
132}
133
Kyösti Mälkki21d6a272019-11-05 18:50:38 +0200134#else /* !__SIMPLE_DEVICE__ */
Aaron Durbin76c37002012-10-30 09:03:43 -0500135
Duncan Laurie2d9d39a2013-05-29 15:27:55 -0700136static void usb_ehci_clock_gating(struct device *dev)
Aaron Durbin76c37002012-10-30 09:03:43 -0500137{
138 u32 reg32;
139
Duncan Laurie2d9d39a2013-05-29 15:27:55 -0700140 /* IOBP 0xE5004001[7:6] = 11b */
141 pch_iobp_update(0xe5004001, ~0, (1 << 7)|(1 << 6));
Aaron Durbin76c37002012-10-30 09:03:43 -0500142
Duncan Laurie2d9d39a2013-05-29 15:27:55 -0700143 /* Dx:F0:DCh[5,2,1] = 111b
144 * Dx:F0:DCh[0] = 1b when EHCI controller is disabled */
145 reg32 = pci_read_config32(dev, 0xdc);
146 reg32 |= (1 << 5) | (1 << 2) | (1 << 1);
147 pci_write_config32(dev, 0xdc, reg32);
148
149 /* Dx:F0:78h[1:0] = 11b */
150 reg32 = pci_read_config32(dev, 0x78);
151 reg32 |= (1 << 1) | (1 << 0);
152 pci_write_config32(dev, 0x78, reg32);
153}
154
155static void usb_ehci_init(struct device *dev)
156{
Aaron Durbin76c37002012-10-30 09:03:43 -0500157 printk(BIOS_DEBUG, "EHCI: Setting up controller.. ");
Duncan Laurie2d9d39a2013-05-29 15:27:55 -0700158
159 usb_ehci_clock_gating(dev);
160
161 /* Disable Wake on Disconnect in RMH */
162 RCBA32_OR(0x35b0, 0x00000022);
Aaron Durbin76c37002012-10-30 09:03:43 -0500163
164 printk(BIOS_DEBUG, "done.\n");
165}
166
Elyes HAOUASab72fc22018-11-29 16:13:14 +0100167static void usb_ehci_set_subsystem(struct device *dev, unsigned int vendor,
168 unsigned int device)
Aaron Durbin76c37002012-10-30 09:03:43 -0500169{
170 u8 access_cntl;
171
172 access_cntl = pci_read_config8(dev, 0x80);
173
174 /* Enable writes to protected registers. */
175 pci_write_config8(dev, 0x80, access_cntl | 1);
176
Subrata Banik4a0f0712019-03-20 14:29:47 +0530177 pci_dev_set_subsystem(dev, vendor, device);
Aaron Durbin76c37002012-10-30 09:03:43 -0500178
179 /* Restore protection. */
180 pci_write_config8(dev, 0x80, access_cntl);
181}
182
Aaron Durbin76c37002012-10-30 09:03:43 -0500183static struct pci_operations lops_pci = {
184 .set_subsystem = &usb_ehci_set_subsystem,
185};
186
187static struct device_operations usb_ehci_ops = {
Kyösti Mälkkifb387df2013-06-07 22:16:52 +0300188 .read_resources = pci_ehci_read_resources,
189 .set_resources = pci_dev_set_resources,
Aaron Durbin76c37002012-10-30 09:03:43 -0500190 .enable_resources = pci_dev_enable_resources,
191 .init = usb_ehci_init,
192 .scan_bus = 0,
193 .ops_pci = &lops_pci,
194};
195
Kyösti Mälkkif55a5422013-06-14 11:16:25 +0300196static const unsigned short pci_device_ids[] = { 0x9c26, 0x8c26, 0x8c2d, 0 };
Aaron Durbin76c37002012-10-30 09:03:43 -0500197
198static const struct pci_driver pch_usb_ehci __pci_driver = {
199 .ops = &usb_ehci_ops,
200 .vendor = PCI_VENDOR_ID_INTEL,
201 .devices = pci_device_ids,
202};
Duncan Laurie1f529082013-07-30 15:53:45 -0700203
Kyösti Mälkki21d6a272019-11-05 18:50:38 +0200204#endif /* !__SIMPLE_DEVICE__ */