blob: 0f3a1b9ca35b980edfc0956300a959552abd4220 [file] [log] [blame]
Angel Pons182dbde2020-04-02 23:49:05 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Stefan Reinauer8e073822012-04-04 00:07:22 +02002
3#include <console/console.h>
4#include <device/device.h>
5#include <device/pci.h>
6#include <device/pci_ids.h>
7#include "pch.h"
Kyösti Mälkkie2227a22014-02-05 13:02:55 +02008#include <device/pci_ehci.h>
Kyösti Mälkki13f66502019-03-03 08:01:05 +02009#include <device/mmio.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020010#include <device/pci_ops.h>
Stefan Reinauer8e073822012-04-04 00:07:22 +020011
12static void usb_ehci_init(struct device *dev)
13{
14 u32 reg32;
15
16 /* Disable Wake on Disconnect in RMH */
Patrick Rudolph4f8b1082019-07-14 11:54:58 +020017 reg32 = RCBA32(RMHWKCTL);
Stefan Reinauer8e073822012-04-04 00:07:22 +020018 reg32 |= 0x22;
Patrick Rudolph4f8b1082019-07-14 11:54:58 +020019 RCBA32(RMHWKCTL) = reg32;
Stefan Reinauer8e073822012-04-04 00:07:22 +020020
21 printk(BIOS_DEBUG, "EHCI: Setting up controller.. ");
Vladimir Serbinenko7686a562014-05-18 11:05:56 +020022
23 /* For others, done in MRC. */
Julius Wernercd49cce2019-03-05 16:53:33 -080024#if CONFIG(USE_NATIVE_RAMINIT)
Vladimir Serbinenko7686a562014-05-18 11:05:56 +020025 pci_write_config32(dev, 0x84, 0x930c8811);
26 pci_write_config32(dev, 0x88, 0x24000d30);
27 pci_write_config32(dev, 0xf4, 0x80408588);
28 pci_write_config32(dev, 0xf4, 0x80808588);
29 pci_write_config32(dev, 0xf4, 0x00808588);
30 pci_write_config32(dev, 0xfc, 0x205b1708);
31#endif
32
Stefan Reinauer8e073822012-04-04 00:07:22 +020033 reg32 = pci_read_config32(dev, PCI_COMMAND);
34 reg32 |= PCI_COMMAND_MASTER;
35 //reg32 |= PCI_COMMAND_SERR;
36 pci_write_config32(dev, PCI_COMMAND, reg32);
37
Vladimir Serbinenko7686a562014-05-18 11:05:56 +020038 /* For others, done in MRC. */
Julius Wernercd49cce2019-03-05 16:53:33 -080039#if CONFIG(USE_NATIVE_RAMINIT)
Vladimir Serbinenko7686a562014-05-18 11:05:56 +020040 struct resource *res;
41 u8 access_cntl;
42
43 access_cntl = pci_read_config8(dev, 0x80);
44
45 /* Enable writes to protected registers. */
46 pci_write_config8(dev, 0x80, access_cntl | 1);
47
48 res = find_resource(dev, PCI_BASE_ADDRESS_0);
49 if (res) {
50 /* Number of ports and companion controllers. */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080051 reg32 = read32((void *)(uintptr_t)(res->base + 4));
52 write32((void *)(uintptr_t)(res->base + 4),
53 (reg32 & 0xfff00000) | 3);
Vladimir Serbinenko7686a562014-05-18 11:05:56 +020054 }
55
56 /* Restore protection. */
57 pci_write_config8(dev, 0x80, access_cntl);
58#endif
59
Stefan Reinauer8e073822012-04-04 00:07:22 +020060 printk(BIOS_DEBUG, "done.\n");
61}
62
Martin Rothff744bf2019-10-23 21:46:03 -060063static void usb_ehci_set_subsystem(struct device *dev, unsigned int vendor,
64 unsigned int device)
Stefan Reinauer8e073822012-04-04 00:07:22 +020065{
66 u8 access_cntl;
67
68 access_cntl = pci_read_config8(dev, 0x80);
69
70 /* Enable writes to protected registers. */
71 pci_write_config8(dev, 0x80, access_cntl | 1);
72
Subrata Banik4a0f0712019-03-20 14:29:47 +053073 pci_dev_set_subsystem(dev, vendor, device);
Stefan Reinauer8e073822012-04-04 00:07:22 +020074
75 /* Restore protection. */
76 pci_write_config8(dev, 0x80, access_cntl);
77}
78
Aaron Durbinaa090cb2017-09-13 16:01:52 -060079static const char *usb_ehci_acpi_name(const struct device *dev)
Patrick Rudolph604f6982017-06-07 09:46:52 +020080{
81 switch (dev->path.pci.devfn) {
82 case PCI_DEVFN(0x1a, 0):
83 return "EHC2";
84 case PCI_DEVFN(0x1d, 0):
85 return "EHC1";
86 }
87 return NULL;
88}
89
Stefan Reinauer8e073822012-04-04 00:07:22 +020090static struct pci_operations lops_pci = {
91 .set_subsystem = &usb_ehci_set_subsystem,
92};
93
94static struct device_operations usb_ehci_ops = {
Kyösti Mälkkifb387df2013-06-07 22:16:52 +030095 .read_resources = pci_ehci_read_resources,
96 .set_resources = pci_dev_set_resources,
Stefan Reinauer8e073822012-04-04 00:07:22 +020097 .enable_resources = pci_dev_enable_resources,
98 .init = usb_ehci_init,
Stefan Reinauer8e073822012-04-04 00:07:22 +020099 .ops_pci = &lops_pci,
Patrick Rudolph604f6982017-06-07 09:46:52 +0200100 .acpi_name = usb_ehci_acpi_name,
Stefan Reinauer8e073822012-04-04 00:07:22 +0200101};
102
Stefan Reinauer9a380ab2012-06-22 13:16:11 -0700103static const unsigned short pci_device_ids[] = { 0x1c26, 0x1c2d, 0x1e26, 0x1e2d,
104 0 };
105
106static const struct pci_driver pch_usb_ehci __pci_driver = {
107 .ops = &usb_ehci_ops,
108 .vendor = PCI_VENDOR_ID_INTEL,
109 .devices = pci_device_ids,
Stefan Reinauer8e073822012-04-04 00:07:22 +0200110};