blob: cd7378e7b8b88e0008ff52e05d880b77bfef8e00 [file] [log] [blame]
Zheng Baoeff2ffd2010-03-16 01:38:54 +00001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2010 Advanced Micro Devices, Inc.
5 *
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.
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.
Zheng Baoeff2ffd2010-03-16 01:38:54 +000014 */
15
16#include <console/console.h>
17#include <device/device.h>
18#include <device/pci.h>
19#include <device/pci_ids.h>
20#include <device/pci_ops.h>
Kyösti Mälkkie2227a22014-02-05 13:02:55 +020021#include <device/pci_ehci.h>
Zheng Baoeff2ffd2010-03-16 01:38:54 +000022#include <arch/io.h>
23#include "sb700.h"
24
25static struct pci_operations lops_pci = {
26 .set_subsystem = pci_dev_set_subsystem,
27};
28
29static void usb_init(struct device *dev)
30{
31 u8 byte;
32 u16 word;
Zheng Baoc3422232011-03-28 03:33:10 +000033 u32 dword;
Zheng Baoeff2ffd2010-03-16 01:38:54 +000034
35 /* 6.1 Enable OHCI0-4 and EHCI Controllers */
36 device_t sm_dev;
37 sm_dev = dev_find_slot(0, PCI_DEVFN(0x14, 0));
38 byte = pci_read_config8(sm_dev, 0x68);
39 byte |= 0xFF;
40 pci_write_config8(sm_dev, 0x68, byte);
41
Zheng Baoeff2ffd2010-03-16 01:38:54 +000042 /* RPR 6.2 Enables the USB PME Event,Enable USB resume support */
43 byte = pm_ioread(0x61);
44 byte |= 1 << 6;
45 pm_iowrite(0x61, byte);
46 byte = pm_ioread(0x65);
47 byte |= 1 << 2;
48 pm_iowrite(0x65, byte);
49
50 /* RPR 6.3 Support USB device wakeup from the S4/S5 state */
51 byte = pm_ioread(0x65);
52 byte &= ~(1 << 0);
53 pm_iowrite(0x65, byte);
54
55 /* RPR 6.5 Enable the USB controller to get reset by any software that generate a PCIRst# condition */
56 byte = pm_ioread(0x65);
57 byte |= (1 << 4);
58 pm_iowrite(0x65, byte);
59
Zheng Baoc3422232011-03-28 03:33:10 +000060 /* USB_ADVANCED_SLEEP_CONTROL */
61 byte = pm_ioread(0x95);
62 byte &= ~(7 << 0);
63 byte |= 6 << 0; /* Advanced sleep up to 6 uframes */
64 pm_iowrite(0x95, byte);
65
Zheng Baoeff2ffd2010-03-16 01:38:54 +000066 /* RPR 6.10 Disable OHCI MSI Capability. */
67 word = pci_read_config16(dev, 0x40);
68 word |= (0x3 << 8);
69 pci_write_config16(dev, 0x40, word);
Zheng Baoc3422232011-03-28 03:33:10 +000070
71 /* USB-1_OHCI0_Corner Case S3 Wake Up */
72 dword = pci_read_config32(dev, 0x50);
73 dword |= (1 << 16);
74 pci_write_config32(dev, 0x50, dword);
Zheng Baoeff2ffd2010-03-16 01:38:54 +000075}
76
77static void usb_init2(struct device *dev)
78{
Zheng Baoeff2ffd2010-03-16 01:38:54 +000079 u32 dword;
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080080 void *usb2_bar0;
Zheng Baoeff2ffd2010-03-16 01:38:54 +000081 device_t sm_dev;
82 u8 rev;
83
84 sm_dev = dev_find_slot(0, PCI_DEVFN(0x14, 0));
85 rev = get_sb700_revision(sm_dev);
86
87 /* dword = pci_read_config32(dev, 0xf8); */
88 /* dword |= 40; */
89 /* pci_write_config32(dev, 0xf8, dword); */
90
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080091 usb2_bar0 = (void *)(pci_read_config32(dev, 0x10) & ~0xFF);
92 printk(BIOS_INFO, "usb2_bar0=0x%p\n", usb2_bar0);
Zheng Baoeff2ffd2010-03-16 01:38:54 +000093
Zheng Bao2a5101a2010-10-10 15:18:53 +000094 /* RPR6.4 Enables the USB PHY auto calibration resister to match 45ohm resistance */
Zheng Baoeff2ffd2010-03-16 01:38:54 +000095 dword = 0x00020F00;
96 write32(usb2_bar0 + 0xC0, dword);
97
98 /* RPR6.9 Sets In/OUT FIFO threshold for best performance */
99 dword = 0x00400040;
100 write32(usb2_bar0 + 0xA4, dword);
101
102 /* RPR6.11 Disabling EHCI Advance Asynchronous Enhancement */
103 dword = pci_read_config32(dev, 0x50);
104 dword |= (1 << 28);
105 pci_write_config32(dev, 0x50, dword);
106
107 /* RPR 6.12 EHCI Advance PHY Power Savings */
108 /* RPR says it is just for A12. CIMM sets it when it is above A11. */
109 /* But it makes the linux crash, so we skip it */
Zheng Baoeff2ffd2010-03-16 01:38:54 +0000110 dword = pci_read_config32(dev, 0x50);
111 dword |= 1 << 31;
112 pci_write_config32(dev, 0x50, dword);
Zheng Baoeff2ffd2010-03-16 01:38:54 +0000113
Zheng Bao2a5101a2010-10-10 15:18:53 +0000114 /* RPR6.13 Enabling Fix for EHCI Controller Driver Yellow Sign Issue */
115 /* RPR says it is just for A12. CIMx sets it when it is above A11. */
Zheng Baoeff2ffd2010-03-16 01:38:54 +0000116 dword = pci_read_config32(dev, 0x50);
117 dword |= (1 << 20);
118 pci_write_config32(dev, 0x50, dword);
119
120 /* RPR6.15 EHCI Async Park Mode */
121 dword = pci_read_config32(dev, 0x50);
122 dword |= (1 << 23);
123 pci_write_config32(dev, 0x50, dword);
124
125 /* Each step below causes the linux crashes. Leave them here
126 * for future debugging. */
Stefan Reinauer78b40332010-03-17 22:09:26 +0000127 u8 byte;
128 u16 word;
129
Zheng Baoeff2ffd2010-03-16 01:38:54 +0000130 /* RPR6.16 Disable EHCI MSI support */
131 byte = pci_read_config8(dev, 0x50);
132 byte |= (1 << 6);
133 pci_write_config8(dev, 0x50, byte);
134
135 /* RPR6.17 Disable the EHCI Dynamic Power Saving feature */
136 word = read32(usb2_bar0 + 0xBC);
137 word &= ~(1 << 12);
138 write16(usb2_bar0 + 0xBC, word);
139
140 /* RPR6.19 USB Controller DMA Read Delay Tolerant. */
141 if (rev >= REV_SB700_A14) {
142 byte = pci_read_config8(dev, 0x50);
143 byte |= (1 << 7);
144 pci_write_config8(dev, 0x50, byte);
145 }
146
Zheng Baoc3422232011-03-28 03:33:10 +0000147 /* SB700_A15, USB-2_EHCI_PID_ERROR_CHECKING */
148 if (rev == REV_SB700_A15) {
149 word = pci_read_config16(dev, 0x50);
150 word |= (1 << 9);
151 pci_write_config16(dev, 0x50, word);
152 }
153
Zheng Baoeff2ffd2010-03-16 01:38:54 +0000154 /* RPR6.20 Async Park Mode. */
155 /* RPR recommends not to set these bits. */
156 #if 0
157 dword = pci_read_config32(dev, 0x50);
158 dword |= 1 << 23;
159 if (rev >= REV_SB700_A14) {
160 dword &= ~(1 << 2);
161 }
162 pci_write_config32(dev, 0x50, dword);
163 #endif
164
165 /* RPR6.22 Advance Async Enhancement */
166 /* RPR6.23 USB Periodic Cache Setting */
167 dword = pci_read_config32(dev, 0x50);
168 if (rev == REV_SB700_A12) {
169 dword |= 1 << 28; /* 6.22 */
170 dword |= 1 << 27; /* 6.23 */
171 } else if (rev >= REV_SB700_A14) {
172 dword |= 1 << 3;
173 dword &= ~(1 << 28); /* 6.22 */
174 dword |= 1 << 8;
175 dword &= ~(1 << 27); /* 6.23 */
176 }
efdesign9800c8c4a2011-07-20 12:37:58 -0600177 pci_write_config32(dev, 0x50, dword);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000178 printk(BIOS_DEBUG, "rpr 6.23, final dword=%x\n", dword);
Zheng Baoeff2ffd2010-03-16 01:38:54 +0000179}
180
Zheng Baoeff2ffd2010-03-16 01:38:54 +0000181static struct device_operations usb_ops = {
Kyösti Mälkkifb387df2013-06-07 22:16:52 +0300182 .read_resources = pci_ehci_read_resources,
183 .set_resources = pci_dev_set_resources,
Zheng Baoeff2ffd2010-03-16 01:38:54 +0000184 .enable_resources = pci_dev_enable_resources,
185 .init = usb_init,
186 .scan_bus = 0,
187 .ops_pci = &lops_pci,
188};
189
Stefan Reinauer8e96ba22010-03-16 23:33:29 +0000190static const struct pci_driver usb_0_driver __pci_driver = {
Zheng Baoeff2ffd2010-03-16 01:38:54 +0000191 .ops = &usb_ops,
192 .vendor = PCI_VENDOR_ID_ATI,
193 .device = PCI_DEVICE_ID_ATI_SB700_USB_18_0,
194};
Zheng Baobfca8ef2010-06-19 06:55:17 +0000195
Stefan Reinauer8e96ba22010-03-16 23:33:29 +0000196static const struct pci_driver usb_1_driver __pci_driver = {
Zheng Baoeff2ffd2010-03-16 01:38:54 +0000197 .ops = &usb_ops,
198 .vendor = PCI_VENDOR_ID_ATI,
199 .device = PCI_DEVICE_ID_ATI_SB700_USB_18_1,
200};
201
202/* the pci id of usb ctrl 0 and 1 are the same. */
203/*
Stefan Reinauer8e96ba22010-03-16 23:33:29 +0000204 * static const struct pci_driver usb_3_driver __pci_driver = {
Zheng Baoeff2ffd2010-03-16 01:38:54 +0000205 * .ops = &usb_ops,
206 * .vendor = PCI_VENDOR_ID_ATI,
207 * .device = PCI_DEVICE_ID_ATI_SB700_USB_19_0,
208 * };
Stefan Reinauer8e96ba22010-03-16 23:33:29 +0000209 * static const struct pci_driver usb_4_driver __pci_driver = {
Zheng Baoeff2ffd2010-03-16 01:38:54 +0000210 * .ops = &usb_ops,
211 * .vendor = PCI_VENDOR_ID_ATI,
212 * .device = PCI_DEVICE_ID_ATI_SB700_USB_19_1,
213 * };
214 */
215
Stefan Reinauer8e96ba22010-03-16 23:33:29 +0000216static const struct pci_driver usb_4_driver __pci_driver = {
Zheng Baoeff2ffd2010-03-16 01:38:54 +0000217 .ops = &usb_ops,
218 .vendor = PCI_VENDOR_ID_ATI,
219 .device = PCI_DEVICE_ID_ATI_SB700_USB_20_5,
220};
221
222static struct device_operations usb_ops2 = {
Kyösti Mälkkifb387df2013-06-07 22:16:52 +0300223 .read_resources = pci_ehci_read_resources,
224 .set_resources = pci_dev_set_resources,
Zheng Baoeff2ffd2010-03-16 01:38:54 +0000225 .enable_resources = pci_dev_enable_resources,
226 .init = usb_init2,
227 .scan_bus = 0,
228 .ops_pci = &lops_pci,
229};
230
Stefan Reinauer8e96ba22010-03-16 23:33:29 +0000231static const struct pci_driver usb_5_driver __pci_driver = {
Zheng Baoeff2ffd2010-03-16 01:38:54 +0000232 .ops = &usb_ops2,
233 .vendor = PCI_VENDOR_ID_ATI,
234 .device = PCI_DEVICE_ID_ATI_SB700_USB_18_2,
235};
236/*
Stefan Reinauer8e96ba22010-03-16 23:33:29 +0000237 * static const struct pci_driver usb_5_driver __pci_driver = {
Zheng Baoeff2ffd2010-03-16 01:38:54 +0000238 * .ops = &usb_ops2,
239 * .vendor = PCI_VENDOR_ID_ATI,
240 * .device = PCI_DEVICE_ID_ATI_SB700_USB_19_2,
241 * };
242 */