blob: 26d2bd16889c4c7ae3a2cd04abf5d6bb451eef19 [file] [log] [blame]
Stefan Reinauer8e073822012-04-04 00:07:22 +02001/*
2 * This file is part of the coreboot project.
3 *
Stefan Reinauer8e073822012-04-04 00:07:22 +02004 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; version 2 of
8 * the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
Stefan Reinauer8e073822012-04-04 00:07:22 +020014 */
15
16#include <console/console.h>
17#include <device/device.h>
18#include <device/pci.h>
19#include <device/pci_ids.h>
20#include "pch.h"
Kyösti Mälkkie2227a22014-02-05 13:02:55 +020021#include <device/pci_ehci.h>
Kyösti Mälkki13f66502019-03-03 08:01:05 +020022#include <device/mmio.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020023#include <device/pci_ops.h>
Stefan Reinauer8e073822012-04-04 00:07:22 +020024
25static void usb_ehci_init(struct device *dev)
26{
27 u32 reg32;
28
29 /* Disable Wake on Disconnect in RMH */
Patrick Rudolph4f8b1082019-07-14 11:54:58 +020030 reg32 = RCBA32(RMHWKCTL);
Stefan Reinauer8e073822012-04-04 00:07:22 +020031 reg32 |= 0x22;
Patrick Rudolph4f8b1082019-07-14 11:54:58 +020032 RCBA32(RMHWKCTL) = reg32;
Stefan Reinauer8e073822012-04-04 00:07:22 +020033
34 printk(BIOS_DEBUG, "EHCI: Setting up controller.. ");
Vladimir Serbinenko7686a562014-05-18 11:05:56 +020035
36 /* For others, done in MRC. */
Julius Wernercd49cce2019-03-05 16:53:33 -080037#if CONFIG(USE_NATIVE_RAMINIT)
Vladimir Serbinenko7686a562014-05-18 11:05:56 +020038 pci_write_config32(dev, 0x84, 0x930c8811);
39 pci_write_config32(dev, 0x88, 0x24000d30);
40 pci_write_config32(dev, 0xf4, 0x80408588);
41 pci_write_config32(dev, 0xf4, 0x80808588);
42 pci_write_config32(dev, 0xf4, 0x00808588);
43 pci_write_config32(dev, 0xfc, 0x205b1708);
44#endif
45
Stefan Reinauer8e073822012-04-04 00:07:22 +020046 reg32 = pci_read_config32(dev, PCI_COMMAND);
47 reg32 |= PCI_COMMAND_MASTER;
48 //reg32 |= PCI_COMMAND_SERR;
49 pci_write_config32(dev, PCI_COMMAND, reg32);
50
Vladimir Serbinenko7686a562014-05-18 11:05:56 +020051 /* For others, done in MRC. */
Julius Wernercd49cce2019-03-05 16:53:33 -080052#if CONFIG(USE_NATIVE_RAMINIT)
Vladimir Serbinenko7686a562014-05-18 11:05:56 +020053 struct resource *res;
54 u8 access_cntl;
55
56 access_cntl = pci_read_config8(dev, 0x80);
57
58 /* Enable writes to protected registers. */
59 pci_write_config8(dev, 0x80, access_cntl | 1);
60
61 res = find_resource(dev, PCI_BASE_ADDRESS_0);
62 if (res) {
63 /* Number of ports and companion controllers. */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080064 reg32 = read32((void *)(uintptr_t)(res->base + 4));
65 write32((void *)(uintptr_t)(res->base + 4),
66 (reg32 & 0xfff00000) | 3);
Vladimir Serbinenko7686a562014-05-18 11:05:56 +020067 }
68
69 /* Restore protection. */
70 pci_write_config8(dev, 0x80, access_cntl);
71#endif
72
Stefan Reinauer8e073822012-04-04 00:07:22 +020073 printk(BIOS_DEBUG, "done.\n");
74}
75
Martin Rothff744bf2019-10-23 21:46:03 -060076static void usb_ehci_set_subsystem(struct device *dev, unsigned int vendor,
77 unsigned int device)
Stefan Reinauer8e073822012-04-04 00:07:22 +020078{
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
Subrata Banik4a0f0712019-03-20 14:29:47 +053086 pci_dev_set_subsystem(dev, vendor, device);
Stefan Reinauer8e073822012-04-04 00:07:22 +020087
88 /* Restore protection. */
89 pci_write_config8(dev, 0x80, access_cntl);
90}
91
Aaron Durbinaa090cb2017-09-13 16:01:52 -060092static const char *usb_ehci_acpi_name(const struct device *dev)
Patrick Rudolph604f6982017-06-07 09:46:52 +020093{
94 switch (dev->path.pci.devfn) {
95 case PCI_DEVFN(0x1a, 0):
96 return "EHC2";
97 case PCI_DEVFN(0x1d, 0):
98 return "EHC1";
99 }
100 return NULL;
101}
102
Stefan Reinauer8e073822012-04-04 00:07:22 +0200103static struct pci_operations lops_pci = {
104 .set_subsystem = &usb_ehci_set_subsystem,
105};
106
107static struct device_operations usb_ehci_ops = {
Kyösti Mälkkifb387df2013-06-07 22:16:52 +0300108 .read_resources = pci_ehci_read_resources,
109 .set_resources = pci_dev_set_resources,
Stefan Reinauer8e073822012-04-04 00:07:22 +0200110 .enable_resources = pci_dev_enable_resources,
111 .init = usb_ehci_init,
112 .scan_bus = 0,
113 .ops_pci = &lops_pci,
Patrick Rudolph604f6982017-06-07 09:46:52 +0200114 .acpi_name = usb_ehci_acpi_name,
Stefan Reinauer8e073822012-04-04 00:07:22 +0200115};
116
Stefan Reinauer9a380ab2012-06-22 13:16:11 -0700117static const unsigned short pci_device_ids[] = { 0x1c26, 0x1c2d, 0x1e26, 0x1e2d,
118 0 };
119
120static const struct pci_driver pch_usb_ehci __pci_driver = {
121 .ops = &usb_ehci_ops,
122 .vendor = PCI_VENDOR_ID_INTEL,
123 .devices = pci_device_ids,
Stefan Reinauer8e073822012-04-04 00:07:22 +0200124};