remove trailing whitespace
[coreboot.git] / src / southbridge / amd / sb700 / usb.c
1 /*
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.
14  *
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
18  */
19
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.h>
26 #include <arch/io.h>
27 #include "sb700.h"
28
29 static struct pci_operations lops_pci = {
30         .set_subsystem = pci_dev_set_subsystem,
31 };
32
33 static void usb_init(struct device *dev)
34 {
35         u8 byte;
36         u16 word;
37         u32 dword;
38
39         /* 6.1 Enable OHCI0-4 and EHCI Controllers */
40         device_t sm_dev;
41         sm_dev = dev_find_slot(0, PCI_DEVFN(0x14, 0));
42         byte = pci_read_config8(sm_dev, 0x68);
43         byte |= 0xFF;
44         pci_write_config8(sm_dev, 0x68, byte);
45
46         /* RPR 6.2 Enables the USB PME Event,Enable USB resume support */
47         byte = pm_ioread(0x61);
48         byte |= 1 << 6;
49         pm_iowrite(0x61, byte);
50         byte = pm_ioread(0x65);
51         byte |= 1 << 2;
52         pm_iowrite(0x65, byte);
53
54         /* RPR 6.3 Support USB device wakeup from the S4/S5 state */
55         byte = pm_ioread(0x65);
56         byte &= ~(1 << 0);
57         pm_iowrite(0x65, byte);
58
59         /* RPR 6.5 Enable the USB controller to get reset by any software that generate a PCIRst# condition */
60         byte = pm_ioread(0x65);
61         byte |= (1 << 4);
62         pm_iowrite(0x65, byte);
63
64         /* USB_ADVANCED_SLEEP_CONTROL */
65         byte = pm_ioread(0x95);
66         byte &= ~(7 << 0);
67         byte |= 6 << 0;         /* Advanced sleep up to 6 uframes */
68         pm_iowrite(0x95, byte);
69
70         /* RPR 6.10 Disable OHCI MSI Capability. */
71         word = pci_read_config16(dev, 0x40);
72         word |= (0x3 << 8);
73         pci_write_config16(dev, 0x40, word);
74
75         /* USB-1_OHCI0_Corner Case S3 Wake Up */
76         dword = pci_read_config32(dev, 0x50);
77         dword |= (1 << 16);
78         pci_write_config32(dev, 0x50, dword);
79 }
80
81 static void usb_init2(struct device *dev)
82 {
83         u32 dword;
84         u32 usb2_bar0;
85         device_t sm_dev;
86         u8 rev;
87
88         sm_dev = dev_find_slot(0, PCI_DEVFN(0x14, 0));
89         rev = get_sb700_revision(sm_dev);
90
91         /* dword = pci_read_config32(dev, 0xf8); */
92         /* dword |= 40; */
93         /* pci_write_config32(dev, 0xf8, dword); */
94
95         usb2_bar0 = pci_read_config32(dev, 0x10) & ~0xFF;
96         printk(BIOS_INFO, "usb2_bar0=0x%x\n", usb2_bar0);
97
98         /* RPR6.4 Enables the USB PHY auto calibration resister to match 45ohm resistance */
99         dword = 0x00020F00;
100         write32(usb2_bar0 + 0xC0, dword);
101
102         /* RPR6.9 Sets In/OUT FIFO threshold for best performance */
103         dword = 0x00400040;
104         write32(usb2_bar0 + 0xA4, dword);
105
106         /* RPR6.11 Disabling EHCI Advance Asynchronous Enhancement */
107         dword = pci_read_config32(dev, 0x50);
108         dword |= (1 << 28);
109         pci_write_config32(dev, 0x50, dword);
110
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);
115         dword |= 1 << 31;
116         pci_write_config32(dev, 0x50, dword);
117
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);
121         dword |= (1 << 20);
122         pci_write_config32(dev, 0x50, dword);
123
124         /* RPR6.15 EHCI Async Park Mode */
125         dword = pci_read_config32(dev, 0x50);
126         dword |= (1 << 23);
127         pci_write_config32(dev, 0x50, dword);
128
129         /* Each step below causes the linux crashes. Leave them here
130          * for future debugging. */
131         u8 byte;
132         u16 word;
133
134         /* RPR6.16 Disable EHCI MSI support */
135         byte = pci_read_config8(dev, 0x50);
136         byte |= (1 << 6);
137         pci_write_config8(dev, 0x50, byte);
138
139         /* RPR6.17 Disable the EHCI Dynamic Power Saving feature */
140         word = read32(usb2_bar0 + 0xBC);
141         word &= ~(1 << 12);
142         write16(usb2_bar0 + 0xBC, word);
143
144         /* RPR6.19 USB Controller DMA Read Delay Tolerant. */
145         if (rev >= REV_SB700_A14) {
146                 byte = pci_read_config8(dev, 0x50);
147                 byte |= (1 << 7);
148                 pci_write_config8(dev, 0x50, byte);
149         }
150
151         /* SB700_A15, USB-2_EHCI_PID_ERROR_CHECKING */
152         if (rev == REV_SB700_A15) {
153                 word = pci_read_config16(dev, 0x50);
154                 word |= (1 << 9);
155                 pci_write_config16(dev, 0x50, word);
156         }
157
158         /* RPR6.20 Async Park Mode. */
159         /* RPR recommends not to set these bits. */
160         #if 0
161         dword = pci_read_config32(dev, 0x50);
162         dword |= 1 << 23;
163         if (rev >= REV_SB700_A14) {
164                 dword &= ~(1 << 2);
165         }
166         pci_write_config32(dev, 0x50, dword);
167         #endif
168
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) {
176                 dword |= 1 << 3;
177                 dword &= ~(1 << 28); /* 6.22 */
178                 dword |= 1 << 8;
179                 dword &= ~(1 << 27); /* 6.23 */
180         }
181         pci_write_config32(dev, 0x50, dword);
182         printk(BIOS_DEBUG, "rpr 6.23, final dword=%x\n", dword);
183 }
184
185 static void usb_set_resources(struct device *dev)
186 {
187 #if CONFIG_USBDEBUG
188         struct resource *res;
189         u32 base;
190         u32 old_debug;
191
192         old_debug = get_ehci_debug();
193         set_ehci_debug(0);
194 #endif
195         pci_dev_set_resources(dev);
196
197 #if CONFIG_USBDEBUG
198         res = find_resource(dev, 0x10);
199         set_ehci_debug(old_debug);
200         if (!res)
201                 return;
202         base = res->base;
203         set_ehci_base(base);
204         report_resource_stored(dev, res, "");
205 #endif
206 }
207
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,
212         .init = usb_init,
213         .scan_bus = 0,
214         .ops_pci = &lops_pci,
215 };
216
217 static const struct pci_driver usb_0_driver __pci_driver = {
218         .ops = &usb_ops,
219         .vendor = PCI_VENDOR_ID_ATI,
220         .device = PCI_DEVICE_ID_ATI_SB700_USB_18_0,
221 };
222
223 static const struct pci_driver usb_1_driver __pci_driver = {
224         .ops = &usb_ops,
225         .vendor = PCI_VENDOR_ID_ATI,
226         .device = PCI_DEVICE_ID_ATI_SB700_USB_18_1,
227 };
228
229 /* the pci id of usb ctrl 0 and 1 are the same. */
230 /*
231  * static const struct pci_driver usb_3_driver __pci_driver = {
232  *      .ops = &usb_ops,
233  *      .vendor = PCI_VENDOR_ID_ATI,
234  *      .device = PCI_DEVICE_ID_ATI_SB700_USB_19_0,
235  * };
236  * static const struct pci_driver usb_4_driver __pci_driver = {
237  *      .ops = &usb_ops,
238  *      .vendor = PCI_VENDOR_ID_ATI,
239  *      .device = PCI_DEVICE_ID_ATI_SB700_USB_19_1,
240  * };
241  */
242
243 static const struct pci_driver usb_4_driver __pci_driver = {
244         .ops = &usb_ops,
245         .vendor = PCI_VENDOR_ID_ATI,
246         .device = PCI_DEVICE_ID_ATI_SB700_USB_20_5,
247 };
248
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,
253         .init = usb_init2,
254         .scan_bus = 0,
255         .ops_pci = &lops_pci,
256 };
257
258 static const struct pci_driver usb_5_driver __pci_driver = {
259         .ops = &usb_ops2,
260         .vendor = PCI_VENDOR_ID_ATI,
261         .device = PCI_DEVICE_ID_ATI_SB700_USB_18_2,
262 };
263 /*
264  * static const struct pci_driver usb_5_driver __pci_driver = {
265  *      .ops = &usb_ops2,
266  *      .vendor = PCI_VENDOR_ID_ATI,
267  *      .device = PCI_DEVICE_ID_ATI_SB700_USB_19_2,
268  * };
269  */