108cfee894284fc2347587606b50b71df43bea94
[coreboot.git] / src / southbridge / sis / sis966 / sis966_usb2.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2004 Tyan Computer
5  * Written by Yinghai Lu <yhlu@tyan.com> for Tyan Computer.
6  * Copyright (C) 2006,2007 AMD
7  * Written by Yinghai Lu <yinghai.lu@amd.com> for AMD.
8  * Copyright (C) 2007 Silicon Integrated Systems Corp. (SiS)
9  * Written by Morgan Tsai <my_tsai@sis.com> for SiS.
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
24  */
25
26 #include <console/console.h>
27 #include <device/device.h>
28 #include <device/pci.h>
29 #include <device/pci_ids.h>
30 #include <device/pci_ops.h>
31 #include <arch/io.h>
32 #include "sis966.h"
33 #if CONFIG_USBDEBUG_DIRECT
34 #include <usbdebug_direct.h>
35 #endif
36
37 extern struct ehci_debug_info dbg_info;
38
39 u8      SiS_SiS7002_init[22][3]={
40 {0x04, 0x00, 0x06},
41 {0x0D, 0x00, 0x00},
42
43 {0x2C, 0xFF, 0x39},
44 {0x2D, 0xFF, 0x10},
45 {0x2E, 0xFF, 0x02},
46 {0x2F, 0xFF, 0x70},
47
48 {0x74, 0x00, 0x00},
49 {0x75, 0x00, 0x00},
50 {0x76, 0x00, 0x00},
51 {0x77, 0x00, 0x00},
52
53 {0x7A, 0x00, 0x00},
54 {0x7B, 0x00, 0x00},
55
56 {0x40, 0x00, 0x20},
57 {0x41, 0x00, 0x00},
58 {0x42, 0x00, 0x00},
59 {0x43, 0x00, 0x08},
60
61 {0x44, 0x00, 0x04},
62
63 {0x48, 0x00, 0x10},
64 {0x49, 0x00, 0x80},
65 {0x4A, 0x00, 0x07},
66 {0x4B, 0x00, 0x00},
67
68 {0x00, 0x00, 0x00}                                      //End of table
69 };
70
71 static void usb2_init(struct device *dev)
72 {
73         u32 base;
74         struct resource *res;
75
76         print_debug("USB 2.0 INIT:---------->\n");
77
78 //-------------- enable USB2.0 (SiS7002) -------------------------
79 {
80         u8  temp8;
81         int i=0;
82
83         while(SiS_SiS7002_init[i][0] != 0)
84         {
85                 temp8 = pci_read_config8(dev, SiS_SiS7002_init[i][0]);
86                 temp8 &= SiS_SiS7002_init[i][1];
87                 temp8 |= SiS_SiS7002_init[i][2];
88                 pci_write_config8(dev, SiS_SiS7002_init[i][0], temp8);
89                 i++;
90         };
91 }
92
93         res = find_resource(dev, 0x10);
94         if(!res)
95                 return;
96
97         base = res->base;
98         printk(BIOS_DEBUG, "base = 0x%08x\n", base);
99         write32(base+0x20, 0x2);
100 //-----------------------------------------------------------
101
102 #if DEBUG_USB2
103 {
104         int i;
105
106         print_debug("****** USB 2.0 PCI config ******");
107         print_debug("\n    03020100  07060504  0B0A0908  0F0E0D0C");
108
109         for(i=0;i<0xff;i+=4){
110                 if((i%16)==0){
111                         print_debug("\n");
112                         print_debug_hex8(i);
113                         print_debug(": ");
114                 }
115                 print_debug_hex32(pci_read_config32(dev,i));
116                 print_debug("  ");
117         }
118         print_debug("\n");
119 }
120 #endif
121         print_debug("USB 2.0 INIT:<----------\n");
122 }
123
124 static void usb2_set_resources(struct device *dev)
125 {
126 #if CONFIG_USBDEBUG_DIRECT
127         struct resource *res;
128         unsigned base;
129         unsigned old_debug;
130
131         old_debug = get_ehci_debug();
132         set_ehci_debug(0);
133 #endif
134         pci_dev_set_resources(dev);
135
136 #if CONFIG_USBDEBUG_DIRECT
137         res = find_resource(dev, 0x10);
138         set_ehci_debug(old_debug);
139         if (!res) return;
140         base = res->base;
141         set_ehci_base(base);
142         report_resource_stored(dev, res, "");
143 #endif
144
145 }
146
147 static void lpci_set_subsystem(device_t dev, unsigned vendor, unsigned device)
148 {
149         pci_write_config32(dev, 0x40,
150                 ((device & 0xffff) << 16) | (vendor & 0xffff));
151 }
152 static struct pci_operations lops_pci = {
153         .set_subsystem  = lpci_set_subsystem,
154 };
155
156 static struct device_operations usb2_ops  = {
157         .read_resources = pci_dev_read_resources,
158         .set_resources  = usb2_set_resources,
159         .enable_resources       = pci_dev_enable_resources,
160         .init           = usb2_init,
161 //      .enable         = sis966_enable,
162         .scan_bus       = 0,
163         .ops_pci        = &lops_pci,
164 };
165
166 static const struct pci_driver usb2_driver __pci_driver = {
167         .ops    = &usb2_ops,
168         .vendor = PCI_VENDOR_ID_SIS,
169         .device = PCI_DEVICE_ID_SIS_SIS966_USB2,
170 };