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