blob: 4c9be71873c3caaaf1fef983204f3adc8feea9b5 [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
Paul Menzela46a7122013-02-23 18:37:27 +010018 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000019 */
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 Reinauerda323732010-05-25 16:17:45 +000026#include <usbdebug.h>
Stefan Reinauera8e11682009-03-11 14:54:18 +000027#include <arch/io.h>
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000028
29static void usb_ehci_init(struct device *dev)
30{
Stefan Reinauera8e11682009-03-11 14:54:18 +000031 struct resource *res;
Stefan Reinauer573f7d42009-07-21 21:50:34 +000032 u32 base;
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000033 u32 reg32;
Stefan Reinauera8e11682009-03-11 14:54:18 +000034 u8 reg8;
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000035
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000036 printk(BIOS_DEBUG, "EHCI: Setting up controller.. ");
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000037 reg32 = pci_read_config32(dev, PCI_COMMAND);
Stefan Reinauera8e11682009-03-11 14:54:18 +000038 reg32 |= PCI_COMMAND_MASTER;
39 reg32 |= PCI_COMMAND_SERR;
40 pci_write_config32(dev, PCI_COMMAND, reg32);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000041
42 reg32 = pci_read_config32(dev, 0xdc);
43 reg32 |= (1 << 31) | (1 << 27);
44 pci_write_config32(dev, 0xdc, reg32);
45
46 reg32 = pci_read_config32(dev, 0xfc);
47 reg32 &= ~(3 << 2);
48 reg32 |= (2 << 2) | (1 << 29) | (1 << 17);
49 pci_write_config32(dev, 0xfc, reg32);
50
Stefan Reinauera8e11682009-03-11 14:54:18 +000051 /* Clear any pending port changes */
52 res = find_resource(dev, 0x10);
Stefan Reinauer573f7d42009-07-21 21:50:34 +000053 base = res->base;
Stefan Reinauerde3206a2010-02-22 06:09:43 +000054 reg32 = read32(base + 0x24) | (1 << 2);
55 write32(base + 0x24, reg32);
Stefan Reinauera8e11682009-03-11 14:54:18 +000056
57 /* workaround */
58 reg8 = pci_read_config8(dev, 0x84);
59 reg8 |= (1 << 4);
60 pci_write_config8(dev, 0x84, reg8);
61
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000062 printk(BIOS_DEBUG, "done.\n");
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000063}
64
Stefan Reinauera8e11682009-03-11 14:54:18 +000065static void usb_ehci_set_subsystem(device_t dev, unsigned vendor, unsigned device)
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000066{
67 u8 access_cntl;
68
69 access_cntl = pci_read_config8(dev, 0x80);
70
71 /* Enable writes to protected registers. */
72 pci_write_config8(dev, 0x80, access_cntl | 1);
73
Stefan Reinauera8e11682009-03-11 14:54:18 +000074 if (!vendor || !device) {
75 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
76 pci_read_config32(dev, PCI_VENDOR_ID));
77 } else {
78 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
79 ((device & 0xffff) << 16) | (vendor & 0xffff));
80 }
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000081
82 /* Restore protection. */
83 pci_write_config8(dev, 0x80, access_cntl);
84}
85
Stefan Reinauera8e11682009-03-11 14:54:18 +000086static void usb_ehci_set_resources(struct device *dev)
87{
Stefan Reinauer7e00a442010-05-25 17:09:05 +000088#if CONFIG_USBDEBUG
Stefan Reinauera8e11682009-03-11 14:54:18 +000089 struct resource *res;
90 u32 base;
91 u32 usb_debug;
92
93 usb_debug = get_ehci_debug();
94 set_ehci_debug(0);
95#endif
96 pci_dev_set_resources(dev);
97
Stefan Reinauer7e00a442010-05-25 17:09:05 +000098#if CONFIG_USBDEBUG
Stefan Reinauera8e11682009-03-11 14:54:18 +000099 res = find_resource(dev, 0x10);
100 set_ehci_debug(usb_debug);
101 if (!res) return;
102 base = res->base;
103 set_ehci_base(base);
104 report_resource_stored(dev, res, "");
105#endif
106}
107
108
109
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000110static struct pci_operations lops_pci = {
111 .set_subsystem = &usb_ehci_set_subsystem,
112};
113
114static struct device_operations usb_ehci_ops = {
115 .read_resources = pci_dev_read_resources,
Stefan Reinauer573f7d42009-07-21 21:50:34 +0000116 .set_resources = usb_ehci_set_resources,
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000117 .enable_resources = pci_dev_enable_resources,
118 .init = usb_ehci_init,
119 .scan_bus = 0,
120 .enable = i82801gx_enable,
121 .ops_pci = &lops_pci,
122};
123
Uwe Hermannbddc6932008-10-29 13:51:31 +0000124/* 82801GB/GR/GDH/GBM/GHM/GU (ICH7/ICH7R/ICH7DH/ICH7-M/ICH7-M DH/ICH7-U) */
125static const struct pci_driver i82801gx_usb_ehci __pci_driver = {
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000126 .ops = &usb_ehci_ops,
127 .vendor = PCI_VENDOR_ID_INTEL,
Uwe Hermann5d7a1c82008-10-31 18:41:09 +0000128 .device = 0x27cc,
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000129};