2 * This file is part of the coreboot project.
4 * Copyright (C) 2008 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>
25 #include <usbdebug_direct.h>
29 static struct pci_operations lops_pci = {
30 .set_subsystem = pci_dev_set_subsystem,
33 static void usb_init(struct device *dev)
39 /* Enable OHCI0-4 and EHCI Controllers */
40 struct device * sm_dev;
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 5.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 5.3 Support USB device wakeup from the S4/S5 state */
55 byte = pm_ioread(0x65);
57 pm_iowrite(0x65, byte);
59 /* RPR 5.6 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 /* RPR 5.11 Disable OHCI MSI Capability */
65 word = pci_read_config16(dev, 0x40);
67 pci_write_config16(dev, 0x40, word);
69 /* RPR 5.8 Disable the OHCI Dynamic Power Saving feature */
70 dword = pci_read_config32(dev, 0x50);
72 pci_write_config32(dev, 0x50, dword);
74 /* RPR 5.12 Enable prevention of OHCI accessing the invalid system memory address range */
75 word = pci_read_config16(dev, 0x50);
77 pci_write_config16(dev, 0x50, word);
79 /* RPR 5.15 Disable SMI handshake in between USB and ACPI for USB legacy support. */
80 /* The BIOS should always set this bit to prevent the malfunction on USB legacy keyboard/mouse support */
81 word = pci_read_config16(dev, 0x50);
83 pci_write_config16(dev, 0x50, word);
86 static void usb_init2(struct device *dev)
92 /* dword = pci_read_config32(dev, 0xf8); */
94 /* pci_write_config32(dev, 0xf8, dword); */
96 usb2_bar0 = (u8 *) (pci_read_config32(dev, 0x10) & ~0xFF);
97 printk_info("usb2_bar0=%x\n", usb2_bar0);
99 /* RPR5.4 Enables the USB PHY auto calibration resister to match 45ohm resistence */
101 writel(dword, usb2_bar0 + 0xC0);
103 /* RPR5.5 Sets In/OUT FIFO threshold for best performance */
105 writel(dword, usb2_bar0 + 0xA4);
107 /* RPR5.9 Disable the EHCI Dynamic Power Saving feature */
108 word = readl(usb2_bar0 + 0xBC);
110 writew(word, usb2_bar0 + 0xBC);
112 /* RPR5.10 Disable EHCI MSI support */
113 byte = pci_read_config8(dev, 0x50);
115 pci_write_config8(dev, 0x50, byte);
117 /* RPR5.13 Disable C3 time enhancement feature */
118 dword = pci_read_config32(dev, 0x50);
120 pci_write_config32(dev, 0x50, dword);
122 /* RPR5.14 Disable USB PHY PLL Reset signal to come from ACPI */
123 byte = pci_read_config8(dev, 0x54);
125 pci_write_config8(dev, 0x54, byte);
128 static void usb_set_resources(struct device *dev)
130 #ifdef CONFIG_USBDEBUG_DIRECT
131 struct resource *res;
135 old_debug = get_ehci_debug();
138 pci_dev_set_resources(dev);
140 #ifdef CONFIG_USBDEBUG_DIRECT
141 res = find_resource(dev, 0x10);
142 set_ehci_debug(old_debug);
147 report_resource_stored(dev, res, "");
152 /* note that below there are a lot of usb drivers. But we don't support linker sets
153 * What we need to do is has a phase 2 function that puts the many usb devices into the device tree.
154 * That's one of the purposes of phase 2. We will write this later.
157 #warning need USB phase 2 function to populate device tree
158 struct device_operations sb600_usb = {
159 .id = {.type = DEVICE_ID_PCI,
160 {.pci = {.vendor = PCI_VENDOR_ID_ATI,
161 .device = PCI_DEVICE_ID_ATI_SB600_USB_0}}},
162 .constructor = default_device_constructor,
163 .phase3_scan = scan_static_bus,
164 .phase4_read_resources = pci_dev_read_resources,
165 .phase4_set_resources = usb_set_resources,
166 .phase5_enable_resources = pci_dev_enable_resources,
167 .phase6_init = usb_init,
172 static struct pci_driver usb_1_driver __pci_driver = {
174 .vendor = PCI_VENDOR_ID_ATI,
175 .device = PCI_DEVICE_ID_ATI_SB600_USB_1,
177 static struct pci_driver usb_2_driver __pci_driver = {
179 .vendor = PCI_VENDOR_ID_ATI,
180 .device = PCI_DEVICE_ID_ATI_SB600_USB_2,
182 static struct pci_driver usb_3_driver __pci_driver = {
184 .vendor = PCI_VENDOR_ID_ATI,
185 .device = PCI_DEVICE_ID_ATI_SB600_USB_3,
187 static struct pci_driver usb_4_driver __pci_driver = {
189 .vendor = PCI_VENDOR_ID_ATI,
190 .device = PCI_DEVICE_ID_ATI_SB600_USB_4,
194 struct device_operations sb600_usb2 = {
195 .id = {.type = DEVICE_ID_PCI,
196 {.pci = {.vendor = PCI_VENDOR_ID_ATI,
197 .device = PCI_DEVICE_ID_ATI_SB600_USB2}}},
198 .constructor = default_device_constructor,
199 .phase3_scan = scan_static_bus,
200 .phase4_read_resources = pci_dev_read_resources,
201 .phase4_set_resources = usb_set_resources,
202 .phase5_enable_resources = pci_dev_enable_resources,
203 .phase6_init = usb_init,