blob: b67a96a1e260fabc00cf784572c93c0981fd0f7d [file] [log] [blame]
Vladimir Serbinenko888d5592013-11-13 17:53:38 +01001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2008-2009 coresystems GmbH
5 * Copyright (C) 2013 Vladimir Serbinenko
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; version 2 of
10 * the License.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010016 */
17
18#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>
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010024#include <arch/io.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020025#include <device/pci_ops.h>
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010026
27static void usb_ehci_init(struct device *dev)
28{
29 u32 reg32;
Vladimir Serbinenko61f902d2014-06-07 16:41:14 +020030 struct resource *res;
31 u8 access_cntl;
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010032
33 /* Disable Wake on Disconnect in RMH */
34 reg32 = RCBA32(0x35b0);
35 reg32 |= 0x22;
36 RCBA32(0x35b0) = reg32;
37
38 printk(BIOS_DEBUG, "EHCI: Setting up controller.. ");
39
40 pci_write_config32(dev, 0x84, 0x130c8911);
41 pci_write_config32(dev, 0x88, 0xa0);
42 pci_write_config32(dev, 0xf4, 0x80808588);
43 pci_write_config32(dev, 0xf4, 0x00808588);
44 pci_write_config32(dev, 0xf4, 0x00808588);
45 pci_write_config32(dev, 0xfc, 0x301b1728);
46
47 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 Serbinenko61f902d2014-06-07 16:41:14 +020052 access_cntl = pci_read_config8(dev, 0x80);
53
54 /* Enable writes to protected registers. */
55 pci_write_config8(dev, 0x80, access_cntl | 1);
56
57 res = find_resource(dev, PCI_BASE_ADDRESS_0);
58 if (res) {
59 /* Number of ports and companion controllers. */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080060 reg32 = read32((u32 *)(uintptr_t)(res->base + 4));
61 write32((u32 *)(uintptr_t)(res->base + 4),
62 (reg32 & 0xfff00000) | 2);
Vladimir Serbinenko61f902d2014-06-07 16:41:14 +020063 }
64
65 /* Restore protection. */
66 pci_write_config8(dev, 0x80, access_cntl);
67
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010068 printk(BIOS_DEBUG, "done.\n");
69}
70
Elyes HAOUASbe841402018-05-13 13:40:39 +020071static void usb_ehci_set_subsystem(struct device *dev, unsigned vendor,
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010072 unsigned device)
73{
74 u8 access_cntl;
75
76 access_cntl = pci_read_config8(dev, 0x80);
77
78 /* Enable writes to protected registers. */
79 pci_write_config8(dev, 0x80, access_cntl | 1);
80
81 if (!vendor || !device) {
82 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
83 pci_read_config32(dev, PCI_VENDOR_ID));
84 } else {
85 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
86 ((device & 0xffff) << 16) | (vendor &
87 0xffff));
88 }
89
90 /* Restore protection. */
91 pci_write_config8(dev, 0x80, access_cntl);
92}
93
94
95static struct pci_operations lops_pci = {
96 .set_subsystem = &usb_ehci_set_subsystem,
97};
98
99static struct device_operations usb_ehci_ops = {
100 .read_resources = pci_ehci_read_resources,
101 .set_resources = pci_dev_set_resources,
Vladimir Serbinenko83ef7492014-03-03 23:21:12 +0100102 .enable_resources = pci_dev_enable_resources,
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100103 .init = usb_ehci_init,
104 .scan_bus = 0,
105 .ops_pci = &lops_pci,
106};
107
108static const unsigned short pci_device_ids[] = { 0x3b34, 0x3b3c, 0 };
109
110static const struct pci_driver pch_usb_ehci __pci_driver = {
111 .ops = &usb_ehci_ops,
112 .vendor = PCI_VENDOR_ID_INTEL,
113 .devices = pci_device_ids,
114};