blob: 8735ba57221b675741ed6f2a928728396e6df5db [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.
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000015 */
16
17#include <console/console.h>
18#include <device/device.h>
19#include <device/pci.h>
20#include <device/pci_ids.h>
21#include "i82801gx.h"
Kyösti Mälkkie2227a22014-02-05 13:02:55 +020022#include <device/pci_ehci.h>
Stefan Reinauera8e11682009-03-11 14:54:18 +000023#include <arch/io.h>
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000024
25static void usb_ehci_init(struct device *dev)
26{
Stefan Reinauera8e11682009-03-11 14:54:18 +000027 struct resource *res;
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080028 u8 *base;
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000029 u32 reg32;
Stefan Reinauera8e11682009-03-11 14:54:18 +000030 u8 reg8;
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000031
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000032 printk(BIOS_DEBUG, "EHCI: Setting up controller.. ");
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000033 reg32 = pci_read_config32(dev, PCI_COMMAND);
Stefan Reinauera8e11682009-03-11 14:54:18 +000034 reg32 |= PCI_COMMAND_MASTER;
35 reg32 |= PCI_COMMAND_SERR;
36 pci_write_config32(dev, PCI_COMMAND, reg32);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000037
38 reg32 = pci_read_config32(dev, 0xdc);
39 reg32 |= (1 << 31) | (1 << 27);
40 pci_write_config32(dev, 0xdc, reg32);
41
42 reg32 = pci_read_config32(dev, 0xfc);
43 reg32 &= ~(3 << 2);
44 reg32 |= (2 << 2) | (1 << 29) | (1 << 17);
45 pci_write_config32(dev, 0xfc, reg32);
46
Stefan Reinauera8e11682009-03-11 14:54:18 +000047 /* Clear any pending port changes */
48 res = find_resource(dev, 0x10);
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080049 base = res2mmio(res, 0, 0);
Stefan Reinauerde3206a2010-02-22 06:09:43 +000050 reg32 = read32(base + 0x24) | (1 << 2);
51 write32(base + 0x24, reg32);
Stefan Reinauera8e11682009-03-11 14:54:18 +000052
53 /* workaround */
54 reg8 = pci_read_config8(dev, 0x84);
55 reg8 |= (1 << 4);
56 pci_write_config8(dev, 0x84, reg8);
57
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000058 printk(BIOS_DEBUG, "done.\n");
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000059}
60
Stefan Reinauera8e11682009-03-11 14:54:18 +000061static void usb_ehci_set_subsystem(device_t dev, unsigned vendor, unsigned device)
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000062{
63 u8 access_cntl;
64
65 access_cntl = pci_read_config8(dev, 0x80);
66
67 /* Enable writes to protected registers. */
68 pci_write_config8(dev, 0x80, access_cntl | 1);
69
Stefan Reinauera8e11682009-03-11 14:54:18 +000070 if (!vendor || !device) {
71 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
72 pci_read_config32(dev, PCI_VENDOR_ID));
73 } else {
74 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
75 ((device & 0xffff) << 16) | (vendor & 0xffff));
76 }
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000077
78 /* Restore protection. */
79 pci_write_config8(dev, 0x80, access_cntl);
80}
81
82static struct pci_operations lops_pci = {
83 .set_subsystem = &usb_ehci_set_subsystem,
84};
85
86static struct device_operations usb_ehci_ops = {
Kyösti Mälkkifb387df2013-06-07 22:16:52 +030087 .read_resources = pci_ehci_read_resources,
88 .set_resources = pci_dev_set_resources,
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000089 .enable_resources = pci_dev_enable_resources,
90 .init = usb_ehci_init,
91 .scan_bus = 0,
92 .enable = i82801gx_enable,
93 .ops_pci = &lops_pci,
94};
95
Uwe Hermannbddc6932008-10-29 13:51:31 +000096/* 82801GB/GR/GDH/GBM/GHM/GU (ICH7/ICH7R/ICH7DH/ICH7-M/ICH7-M DH/ICH7-U) */
97static const struct pci_driver i82801gx_usb_ehci __pci_driver = {
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000098 .ops = &usb_ehci_ops,
99 .vendor = PCI_VENDOR_ID_INTEL,
Uwe Hermann5d7a1c82008-10-31 18:41:09 +0000100 .device = 0x27cc,
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000101};