first round name simplification. drop the <component>_ prefix.
[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
38         /* 6.1 Enable OHCI0-4 and EHCI Controllers */
39         device_t sm_dev;
40         sm_dev = dev_find_slot(0, PCI_DEVFN(0x14, 0));
41         byte = pci_read_config8(sm_dev, 0x68);
42         byte |= 0xFF;
43         pci_write_config8(sm_dev, 0x68, byte);
44
45         /* RPR 6.2 Enables the USB PME Event,Enable USB resume support */
46         byte = pm_ioread(0x61);
47         byte |= 1 << 6;
48         pm_iowrite(0x61, byte);
49         byte = pm_ioread(0x65);
50         byte |= 1 << 2;
51         pm_iowrite(0x65, byte);
52
53         /* RPR 6.3 Support USB device wakeup from the S4/S5 state */
54         byte = pm_ioread(0x65);
55         byte &= ~(1 << 0);
56         pm_iowrite(0x65, byte);
57
58         /* RPR 6.5 Enable the USB controller to get reset by any software that generate a PCIRst# condition */
59         byte = pm_ioread(0x65);
60         byte |= (1 << 4);
61         pm_iowrite(0x65, byte);
62
63         /* RPR 6.10 Disable OHCI MSI Capability. */
64         word = pci_read_config16(dev, 0x40);
65         word |= (0x3 << 8);
66         pci_write_config16(dev, 0x40, word);
67 }
68
69 static void usb_init2(struct device *dev)
70 {
71         u32 dword;
72         u32 usb2_bar0;
73         device_t sm_dev;
74         u8 rev;
75
76         sm_dev = dev_find_slot(0, PCI_DEVFN(0x14, 0));
77         rev = get_sb700_revision(sm_dev);
78
79         /* dword = pci_read_config32(dev, 0xf8); */
80         /* dword |= 40; */
81         /* pci_write_config32(dev, 0xf8, dword); */
82
83         usb2_bar0 = pci_read_config32(dev, 0x10) & ~0xFF;
84         printk(BIOS_INFO, "usb2_bar0=0x%x\n", usb2_bar0);
85
86         /* RPR6.4 Enables the USB PHY auto calibration resister to match 45ohm resistance */
87         dword = 0x00020F00;
88         write32(usb2_bar0 + 0xC0, dword);
89
90         /* RPR6.9 Sets In/OUT FIFO threshold for best performance */
91         dword = 0x00400040;
92         write32(usb2_bar0 + 0xA4, dword);
93
94         /* RPR6.11 Disabling EHCI Advance Asynchronous Enhancement */
95         dword = pci_read_config32(dev, 0x50);
96         dword |= (1 << 28);
97         pci_write_config32(dev, 0x50, dword);
98
99         /* RPR 6.12 EHCI Advance PHY Power Savings */
100         /* RPR says it is just for A12. CIMM sets it when it is above A11. */
101         /* But it makes the linux crash, so we skip it */
102         #if 0
103         dword = pci_read_config32(dev, 0x50);
104         dword |= 1 << 31;
105         pci_write_config32(dev, 0x50, dword);
106         #endif
107
108         /* RPR6.13 Enabling Fix for EHCI Controller Driver Yellow Sign Issue */
109         /* RPR says it is just for A12. CIMx sets it when it is above A11. */
110         dword = pci_read_config32(dev, 0x50);
111         dword |= (1 << 20);
112         pci_write_config32(dev, 0x50, dword);
113
114         /* RPR6.15 EHCI Async Park Mode */
115         dword = pci_read_config32(dev, 0x50);
116         dword |= (1 << 23);
117         pci_write_config32(dev, 0x50, dword);
118
119         /* Each step below causes the linux crashes. Leave them here
120          * for future debugging. */
121 #if 0
122         u8 byte;
123         u16 word;
124
125         /* RPR6.16 Disable EHCI MSI support */
126         byte = pci_read_config8(dev, 0x50);
127         byte |= (1 << 6);
128         pci_write_config8(dev, 0x50, byte);
129
130         /* RPR6.17 Disable the EHCI Dynamic Power Saving feature */
131         word = read32(usb2_bar0 + 0xBC);
132         word &= ~(1 << 12);
133         write16(usb2_bar0 + 0xBC, word);
134
135         /* RPR6.19 USB Controller DMA Read Delay Tolerant. */
136         if (rev >= REV_SB700_A14) {
137                 byte = pci_read_config8(dev, 0x50);
138                 byte |= (1 << 7);
139                 pci_write_config8(dev, 0x50, byte);
140         }
141
142         /* RPR6.20 Async Park Mode. */
143         /* RPR recommends not to set these bits. */
144         #if 0
145         dword = pci_read_config32(dev, 0x50);
146         dword |= 1 << 23;
147         if (rev >= REV_SB700_A14) {
148                 dword &= ~(1 << 2);
149         }
150         pci_write_config32(dev, 0x50, dword);
151         #endif
152
153         /* RPR6.22 Advance Async Enhancement */
154         /* RPR6.23 USB Periodic Cache Setting */
155         dword = pci_read_config32(dev, 0x50);
156         if (rev == REV_SB700_A12) {
157                 dword |= 1 << 28; /* 6.22 */
158                 dword |= 1 << 27; /* 6.23 */
159         } else if (rev >= REV_SB700_A14) {
160                 dword |= 1 << 3;
161                 dword &= ~(1 << 28); /* 6.22 */
162                 dword |= 1 << 8;
163                 dword &= ~(1 << 27); /* 6.23 */
164         }
165         printk(BIOS_DEBUG, "rpr 6.23, final dword=%x\n", dword);
166 #endif
167 }
168
169 static void usb_set_resources(struct device *dev)
170 {
171 #if CONFIG_USBDEBUG
172         struct resource *res;
173         u32 base;
174         u32 old_debug;
175
176         old_debug = get_ehci_debug();
177         set_ehci_debug(0);
178 #endif
179         pci_dev_set_resources(dev);
180
181 #if CONFIG_USBDEBUG
182         res = find_resource(dev, 0x10);
183         set_ehci_debug(old_debug);
184         if (!res)
185                 return;
186         base = res->base;
187         set_ehci_base(base);
188         report_resource_stored(dev, res, "");
189 #endif
190 }
191
192 static struct device_operations usb_ops = {
193         .read_resources = pci_dev_read_resources,
194         .set_resources = usb_set_resources, /* pci_dev_set_resources, */
195         .enable_resources = pci_dev_enable_resources,
196         .init = usb_init,
197         .scan_bus = 0,
198         .ops_pci = &lops_pci,
199 };
200
201 static const struct pci_driver usb_0_driver __pci_driver = {
202         .ops = &usb_ops,
203         .vendor = PCI_VENDOR_ID_ATI,
204         .device = PCI_DEVICE_ID_ATI_SB700_USB_18_0,
205 };
206
207 static const struct pci_driver usb_1_driver __pci_driver = {
208         .ops = &usb_ops,
209         .vendor = PCI_VENDOR_ID_ATI,
210         .device = PCI_DEVICE_ID_ATI_SB700_USB_18_1,
211 };
212
213 /* the pci id of usb ctrl 0 and 1 are the same. */
214 /*
215  * static const struct pci_driver usb_3_driver __pci_driver = {
216  *      .ops = &usb_ops,
217  *      .vendor = PCI_VENDOR_ID_ATI,
218  *      .device = PCI_DEVICE_ID_ATI_SB700_USB_19_0,
219  * };
220  * static const struct pci_driver usb_4_driver __pci_driver = {
221  *      .ops = &usb_ops,
222  *      .vendor = PCI_VENDOR_ID_ATI,
223  *      .device = PCI_DEVICE_ID_ATI_SB700_USB_19_1,
224  * };
225  */
226
227 static const struct pci_driver usb_4_driver __pci_driver = {
228         .ops = &usb_ops,
229         .vendor = PCI_VENDOR_ID_ATI,
230         .device = PCI_DEVICE_ID_ATI_SB700_USB_20_5,
231 };
232
233 static struct device_operations usb_ops2 = {
234         .read_resources = pci_dev_read_resources,
235         .set_resources = usb_set_resources, /* pci_dev_set_resources, */
236         .enable_resources = pci_dev_enable_resources,
237         .init = usb_init2,
238         .scan_bus = 0,
239         .ops_pci = &lops_pci,
240 };
241
242 static const struct pci_driver usb_5_driver __pci_driver = {
243         .ops = &usb_ops2,
244         .vendor = PCI_VENDOR_ID_ATI,
245         .device = PCI_DEVICE_ID_ATI_SB700_USB_18_2,
246 };
247 /*
248  * static const struct pci_driver usb_5_driver __pci_driver = {
249  *      .ops = &usb_ops2,
250  *      .vendor = PCI_VENDOR_ID_ATI,
251  *      .device = PCI_DEVICE_ID_ATI_SB700_USB_19_2,
252  * };
253  */