blob: 39a5799ed9ed47e6466f46fddfddc07879bcbb94 [file] [log] [blame]
Stefan Reinauerdebb11f2008-10-29 04:46:52 +00001/*
2 * This file is part of the coreboot project.
3 *
Stefan Reinauera8e11682009-03-11 14:54:18 +00004 * Copyright (C) 2008-2009 coresystems GmbH
Stefan Reinauerdebb11f2008-10-29 04:46:52 +00005 *
Stefan Reinauera8e11682009-03-11 14:54:18 +00006 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; version 2 of
9 * the License.
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000010 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include <console/console.h>
22#include <device/device.h>
23#include <device/pci.h>
24#include <device/pci_ids.h>
25#include "i82801gx.h"
Stefan Reinauera8e11682009-03-11 14:54:18 +000026#if CONFIG_USBDEBUG_DIRECT
27#include <usbdebug_direct.h>
28#endif
29#include <arch/io.h>
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000030
31static void usb_ehci_init(struct device *dev)
32{
Stefan Reinauera8e11682009-03-11 14:54:18 +000033 struct resource *res;
34 u8 *base;
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000035 u32 reg32;
Stefan Reinauera8e11682009-03-11 14:54:18 +000036 u8 reg8;
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000037
38 printk_debug("EHCI: Setting up controller.. ");
39 reg32 = pci_read_config32(dev, PCI_COMMAND);
Stefan Reinauera8e11682009-03-11 14:54:18 +000040 reg32 |= PCI_COMMAND_MASTER;
41 reg32 |= PCI_COMMAND_SERR;
42 pci_write_config32(dev, PCI_COMMAND, reg32);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000043
44 reg32 = pci_read_config32(dev, 0xdc);
45 reg32 |= (1 << 31) | (1 << 27);
46 pci_write_config32(dev, 0xdc, reg32);
47
48 reg32 = pci_read_config32(dev, 0xfc);
49 reg32 &= ~(3 << 2);
50 reg32 |= (2 << 2) | (1 << 29) | (1 << 17);
51 pci_write_config32(dev, 0xfc, reg32);
52
Stefan Reinauera8e11682009-03-11 14:54:18 +000053 /* Clear any pending port changes */
54 res = find_resource(dev, 0x10);
55 base =(u8 *)res->base;
56 reg32 = readl(base + 0x24) | (1 << 2);
57 writel(base + 0x24, reg32);
58
59 /* workaround */
60 reg8 = pci_read_config8(dev, 0x84);
61 reg8 |= (1 << 4);
62 pci_write_config8(dev, 0x84, reg8);
63
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000064 printk_debug("done.\n");
65}
66
Stefan Reinauera8e11682009-03-11 14:54:18 +000067static void usb_ehci_set_subsystem(device_t dev, unsigned vendor, unsigned device)
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000068{
69 u8 access_cntl;
70
71 access_cntl = pci_read_config8(dev, 0x80);
72
73 /* Enable writes to protected registers. */
74 pci_write_config8(dev, 0x80, access_cntl | 1);
75
Stefan Reinauera8e11682009-03-11 14:54:18 +000076 if (!vendor || !device) {
77 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
78 pci_read_config32(dev, PCI_VENDOR_ID));
79 } else {
80 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
81 ((device & 0xffff) << 16) | (vendor & 0xffff));
82 }
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000083
84 /* Restore protection. */
85 pci_write_config8(dev, 0x80, access_cntl);
86}
87
Stefan Reinauera8e11682009-03-11 14:54:18 +000088static void usb_ehci_set_resources(struct device *dev)
89{
90#if CONFIG_USBDEBUG_DIRECT
91 struct resource *res;
92 u32 base;
93 u32 usb_debug;
94
95 usb_debug = get_ehci_debug();
96 set_ehci_debug(0);
97#endif
98 pci_dev_set_resources(dev);
99
100#if CONFIG_USBDEBUG_DIRECT
101 res = find_resource(dev, 0x10);
102 set_ehci_debug(usb_debug);
103 if (!res) return;
104 base = res->base;
105 set_ehci_base(base);
106 report_resource_stored(dev, res, "");
107#endif
108}
109
110
111
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000112static struct pci_operations lops_pci = {
113 .set_subsystem = &usb_ehci_set_subsystem,
114};
115
116static struct device_operations usb_ehci_ops = {
117 .read_resources = pci_dev_read_resources,
118 .set_resources = pci_dev_set_resources,
119 .enable_resources = pci_dev_enable_resources,
120 .init = usb_ehci_init,
121 .scan_bus = 0,
122 .enable = i82801gx_enable,
123 .ops_pci = &lops_pci,
124};
125
Uwe Hermannbddc6932008-10-29 13:51:31 +0000126/* 82801GB/GR/GDH/GBM/GHM/GU (ICH7/ICH7R/ICH7DH/ICH7-M/ICH7-M DH/ICH7-U) */
127static const struct pci_driver i82801gx_usb_ehci __pci_driver = {
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000128 .ops = &usb_ehci_ops,
129 .vendor = PCI_VENDOR_ID_INTEL,
Uwe Hermann5d7a1c82008-10-31 18:41:09 +0000130 .device = 0x27cc,
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000131};