blob: c0cb1a9092035ba2023a18f79589da14b1d5fb6c [file] [log] [blame]
Stefan Reinauer8e073822012-04-04 00:07:22 +02001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2008-2009 coresystems GmbH
5 *
6 * 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.
10 *
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 Reinauer8e073822012-04-04 00:07:22 +020015 */
16
Vladimir Serbinenko7686a562014-05-18 11:05:56 +020017#include <kconfig.h>
Stefan Reinauer8e073822012-04-04 00:07:22 +020018#include <console/console.h>
19#include <device/device.h>
20#include <device/pci.h>
21#include <device/pci_ids.h>
22#include "pch.h"
Kyösti Mälkkie2227a22014-02-05 13:02:55 +020023#include <device/pci_ehci.h>
Stefan Reinauer8e073822012-04-04 00:07:22 +020024#include <arch/io.h>
25
26static void usb_ehci_init(struct device *dev)
27{
28 u32 reg32;
29
30 /* Disable Wake on Disconnect in RMH */
31 reg32 = RCBA32(0x35b0);
32 reg32 |= 0x22;
33 RCBA32(0x35b0) = reg32;
34
35 printk(BIOS_DEBUG, "EHCI: Setting up controller.. ");
Vladimir Serbinenko7686a562014-05-18 11:05:56 +020036
37 /* For others, done in MRC. */
Vladimir Serbinenko144eea02016-02-10 02:36:04 +010038#if IS_ENABLED(CONFIG_USE_NATIVE_RAMINIT)
Vladimir Serbinenko7686a562014-05-18 11:05:56 +020039 pci_write_config32(dev, 0x84, 0x930c8811);
40 pci_write_config32(dev, 0x88, 0x24000d30);
41 pci_write_config32(dev, 0xf4, 0x80408588);
42 pci_write_config32(dev, 0xf4, 0x80808588);
43 pci_write_config32(dev, 0xf4, 0x00808588);
44 pci_write_config32(dev, 0xfc, 0x205b1708);
45#endif
46
Stefan Reinauer8e073822012-04-04 00:07:22 +020047 reg32 = pci_read_config32(dev, PCI_COMMAND);
48 reg32 |= PCI_COMMAND_MASTER;
49 //reg32 |= PCI_COMMAND_SERR;
50 pci_write_config32(dev, PCI_COMMAND, reg32);
51
Vladimir Serbinenko7686a562014-05-18 11:05:56 +020052 /* For others, done in MRC. */
Vladimir Serbinenko144eea02016-02-10 02:36:04 +010053#if IS_ENABLED(CONFIG_USE_NATIVE_RAMINIT)
Vladimir Serbinenko7686a562014-05-18 11:05:56 +020054 struct resource *res;
55 u8 access_cntl;
56
57 access_cntl = pci_read_config8(dev, 0x80);
58
59 /* Enable writes to protected registers. */
60 pci_write_config8(dev, 0x80, access_cntl | 1);
61
62 res = find_resource(dev, PCI_BASE_ADDRESS_0);
63 if (res) {
64 /* Number of ports and companion controllers. */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080065 reg32 = read32((void *)(uintptr_t)(res->base + 4));
66 write32((void *)(uintptr_t)(res->base + 4),
67 (reg32 & 0xfff00000) | 3);
Vladimir Serbinenko7686a562014-05-18 11:05:56 +020068 }
69
70 /* Restore protection. */
71 pci_write_config8(dev, 0x80, access_cntl);
72#endif
73
Stefan Reinauer8e073822012-04-04 00:07:22 +020074 printk(BIOS_DEBUG, "done.\n");
75}
76
77static void usb_ehci_set_subsystem(device_t dev, unsigned vendor, unsigned device)
78{
79 u8 access_cntl;
80
81 access_cntl = pci_read_config8(dev, 0x80);
82
83 /* Enable writes to protected registers. */
84 pci_write_config8(dev, 0x80, access_cntl | 1);
85
86 if (!vendor || !device) {
87 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
88 pci_read_config32(dev, PCI_VENDOR_ID));
89 } else {
90 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
91 ((device & 0xffff) << 16) | (vendor & 0xffff));
92 }
93
94 /* Restore protection. */
95 pci_write_config8(dev, 0x80, access_cntl);
96}
97
Stefan Reinauer8e073822012-04-04 00:07:22 +020098static struct pci_operations lops_pci = {
99 .set_subsystem = &usb_ehci_set_subsystem,
100};
101
102static struct device_operations usb_ehci_ops = {
Kyösti Mälkkifb387df2013-06-07 22:16:52 +0300103 .read_resources = pci_ehci_read_resources,
104 .set_resources = pci_dev_set_resources,
Stefan Reinauer8e073822012-04-04 00:07:22 +0200105 .enable_resources = pci_dev_enable_resources,
106 .init = usb_ehci_init,
107 .scan_bus = 0,
108 .ops_pci = &lops_pci,
109};
110
Stefan Reinauer9a380ab2012-06-22 13:16:11 -0700111static const unsigned short pci_device_ids[] = { 0x1c26, 0x1c2d, 0x1e26, 0x1e2d,
112 0 };
113
114static const struct pci_driver pch_usb_ehci __pci_driver = {
115 .ops = &usb_ehci_ops,
116 .vendor = PCI_VENDOR_ID_INTEL,
117 .devices = pci_device_ids,
Stefan Reinauer8e073822012-04-04 00:07:22 +0200118};