2 * This file is part of the coreboot project.
4 * Copyright (C) 2010 Advanced Micro Devices, Inc.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
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.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 #include <console/console.h>
21 #include <device/device.h>
22 #include <device/pci.h>
23 #include <device/pci_ids.h>
24 #include <device/pci_ops.h>
29 static struct pci_operations lops_pci = {
30 .set_subsystem = pci_dev_set_subsystem,
33 static void usb_init(struct device *dev)
39 /* 6.1 Enable OHCI0-4 and EHCI Controllers */
41 sm_dev = dev_find_slot(0, PCI_DEVFN(0x14, 0));
42 byte = pci_read_config8(sm_dev, 0x68);
44 pci_write_config8(sm_dev, 0x68, byte);
46 /* RPR 6.2 Enables the USB PME Event,Enable USB resume support */
47 byte = pm_ioread(0x61);
49 pm_iowrite(0x61, byte);
50 byte = pm_ioread(0x65);
52 pm_iowrite(0x65, byte);
54 /* RPR 6.3 Support USB device wakeup from the S4/S5 state */
55 byte = pm_ioread(0x65);
57 pm_iowrite(0x65, byte);
59 /* RPR 6.5 Enable the USB controller to get reset by any software that generate a PCIRst# condition */
60 byte = pm_ioread(0x65);
62 pm_iowrite(0x65, byte);
64 /* USB_ADVANCED_SLEEP_CONTROL */
65 byte = pm_ioread(0x95);
67 byte |= 6 << 0; /* Advanced sleep up to 6 uframes */
68 pm_iowrite(0x95, byte);
70 /* RPR 6.10 Disable OHCI MSI Capability. */
71 word = pci_read_config16(dev, 0x40);
73 pci_write_config16(dev, 0x40, word);
75 /* USB-1_OHCI0_Corner Case S3 Wake Up */
76 dword = pci_read_config32(dev, 0x50);
78 pci_write_config32(dev, 0x50, dword);
81 static void usb_init2(struct device *dev)
88 sm_dev = dev_find_slot(0, PCI_DEVFN(0x14, 0));
89 rev = get_sb700_revision(sm_dev);
91 /* dword = pci_read_config32(dev, 0xf8); */
93 /* pci_write_config32(dev, 0xf8, dword); */
95 usb2_bar0 = pci_read_config32(dev, 0x10) & ~0xFF;
96 printk(BIOS_INFO, "usb2_bar0=0x%x\n", usb2_bar0);
98 /* RPR6.4 Enables the USB PHY auto calibration resister to match 45ohm resistance */
100 write32(usb2_bar0 + 0xC0, dword);
102 /* RPR6.9 Sets In/OUT FIFO threshold for best performance */
104 write32(usb2_bar0 + 0xA4, dword);
106 /* RPR6.11 Disabling EHCI Advance Asynchronous Enhancement */
107 dword = pci_read_config32(dev, 0x50);
109 pci_write_config32(dev, 0x50, dword);
111 /* RPR 6.12 EHCI Advance PHY Power Savings */
112 /* RPR says it is just for A12. CIMM sets it when it is above A11. */
113 /* But it makes the linux crash, so we skip it */
114 dword = pci_read_config32(dev, 0x50);
116 pci_write_config32(dev, 0x50, dword);
118 /* RPR6.13 Enabling Fix for EHCI Controller Driver Yellow Sign Issue */
119 /* RPR says it is just for A12. CIMx sets it when it is above A11. */
120 dword = pci_read_config32(dev, 0x50);
122 pci_write_config32(dev, 0x50, dword);
124 /* RPR6.15 EHCI Async Park Mode */
125 dword = pci_read_config32(dev, 0x50);
127 pci_write_config32(dev, 0x50, dword);
129 /* Each step below causes the linux crashes. Leave them here
130 * for future debugging. */
134 /* RPR6.16 Disable EHCI MSI support */
135 byte = pci_read_config8(dev, 0x50);
137 pci_write_config8(dev, 0x50, byte);
139 /* RPR6.17 Disable the EHCI Dynamic Power Saving feature */
140 word = read32(usb2_bar0 + 0xBC);
142 write16(usb2_bar0 + 0xBC, word);
144 /* RPR6.19 USB Controller DMA Read Delay Tolerant. */
145 if (rev >= REV_SB700_A14) {
146 byte = pci_read_config8(dev, 0x50);
148 pci_write_config8(dev, 0x50, byte);
151 /* SB700_A15, USB-2_EHCI_PID_ERROR_CHECKING */
152 if (rev == REV_SB700_A15) {
153 word = pci_read_config16(dev, 0x50);
155 pci_write_config16(dev, 0x50, word);
158 /* RPR6.20 Async Park Mode. */
159 /* RPR recommends not to set these bits. */
161 dword = pci_read_config32(dev, 0x50);
163 if (rev >= REV_SB700_A14) {
166 pci_write_config32(dev, 0x50, dword);
169 /* RPR6.22 Advance Async Enhancement */
170 /* RPR6.23 USB Periodic Cache Setting */
171 dword = pci_read_config32(dev, 0x50);
172 if (rev == REV_SB700_A12) {
173 dword |= 1 << 28; /* 6.22 */
174 dword |= 1 << 27; /* 6.23 */
175 } else if (rev >= REV_SB700_A14) {
177 dword &= ~(1 << 28); /* 6.22 */
179 dword &= ~(1 << 27); /* 6.23 */
181 pci_write_config32(dev, 0x50, dword);
182 printk(BIOS_DEBUG, "rpr 6.23, final dword=%x\n", dword);
185 static void usb_set_resources(struct device *dev)
188 struct resource *res;
192 old_debug = get_ehci_debug();
195 pci_dev_set_resources(dev);
198 res = find_resource(dev, 0x10);
199 set_ehci_debug(old_debug);
204 report_resource_stored(dev, res, "");
208 static struct device_operations usb_ops = {
209 .read_resources = pci_dev_read_resources,
210 .set_resources = usb_set_resources, /* pci_dev_set_resources, */
211 .enable_resources = pci_dev_enable_resources,
214 .ops_pci = &lops_pci,
217 static const struct pci_driver usb_0_driver __pci_driver = {
219 .vendor = PCI_VENDOR_ID_ATI,
220 .device = PCI_DEVICE_ID_ATI_SB700_USB_18_0,
223 static const struct pci_driver usb_1_driver __pci_driver = {
225 .vendor = PCI_VENDOR_ID_ATI,
226 .device = PCI_DEVICE_ID_ATI_SB700_USB_18_1,
229 /* the pci id of usb ctrl 0 and 1 are the same. */
231 * static const struct pci_driver usb_3_driver __pci_driver = {
233 * .vendor = PCI_VENDOR_ID_ATI,
234 * .device = PCI_DEVICE_ID_ATI_SB700_USB_19_0,
236 * static const struct pci_driver usb_4_driver __pci_driver = {
238 * .vendor = PCI_VENDOR_ID_ATI,
239 * .device = PCI_DEVICE_ID_ATI_SB700_USB_19_1,
243 static const struct pci_driver usb_4_driver __pci_driver = {
245 .vendor = PCI_VENDOR_ID_ATI,
246 .device = PCI_DEVICE_ID_ATI_SB700_USB_20_5,
249 static struct device_operations usb_ops2 = {
250 .read_resources = pci_dev_read_resources,
251 .set_resources = usb_set_resources, /* pci_dev_set_resources, */
252 .enable_resources = pci_dev_enable_resources,
255 .ops_pci = &lops_pci,
258 static const struct pci_driver usb_5_driver __pci_driver = {
260 .vendor = PCI_VENDOR_ID_ATI,
261 .device = PCI_DEVICE_ID_ATI_SB700_USB_18_2,
264 * static const struct pci_driver usb_5_driver __pci_driver = {
266 * .vendor = PCI_VENDOR_ID_ATI,
267 * .device = PCI_DEVICE_ID_ATI_SB700_USB_19_2,