blob: 13670b8ca198a3fa4b8180abd0aabbdf8b587f2e [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>
25
26static void usb_ehci_init(struct device *dev)
27{
28 u32 reg32;
Vladimir Serbinenko61f902d2014-06-07 16:41:14 +020029 struct resource *res;
30 u8 access_cntl;
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010031
32 /* Disable Wake on Disconnect in RMH */
33 reg32 = RCBA32(0x35b0);
34 reg32 |= 0x22;
35 RCBA32(0x35b0) = reg32;
36
37 printk(BIOS_DEBUG, "EHCI: Setting up controller.. ");
38
39 pci_write_config32(dev, 0x84, 0x130c8911);
40 pci_write_config32(dev, 0x88, 0xa0);
41 pci_write_config32(dev, 0xf4, 0x80808588);
42 pci_write_config32(dev, 0xf4, 0x00808588);
43 pci_write_config32(dev, 0xf4, 0x00808588);
44 pci_write_config32(dev, 0xfc, 0x301b1728);
45
46 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 Serbinenko61f902d2014-06-07 16:41:14 +020051 access_cntl = pci_read_config8(dev, 0x80);
52
53 /* Enable writes to protected registers. */
54 pci_write_config8(dev, 0x80, access_cntl | 1);
55
56 res = find_resource(dev, PCI_BASE_ADDRESS_0);
57 if (res) {
58 /* Number of ports and companion controllers. */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080059 reg32 = read32((u32 *)(uintptr_t)(res->base + 4));
60 write32((u32 *)(uintptr_t)(res->base + 4),
61 (reg32 & 0xfff00000) | 2);
Vladimir Serbinenko61f902d2014-06-07 16:41:14 +020062 }
63
64 /* Restore protection. */
65 pci_write_config8(dev, 0x80, access_cntl);
66
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010067 printk(BIOS_DEBUG, "done.\n");
68}
69
Elyes HAOUASbe841402018-05-13 13:40:39 +020070static void usb_ehci_set_subsystem(struct device *dev, unsigned vendor,
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010071 unsigned device)
72{
73 u8 access_cntl;
74
75 access_cntl = pci_read_config8(dev, 0x80);
76
77 /* Enable writes to protected registers. */
78 pci_write_config8(dev, 0x80, access_cntl | 1);
79
80 if (!vendor || !device) {
81 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
82 pci_read_config32(dev, PCI_VENDOR_ID));
83 } else {
84 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
85 ((device & 0xffff) << 16) | (vendor &
86 0xffff));
87 }
88
89 /* Restore protection. */
90 pci_write_config8(dev, 0x80, access_cntl);
91}
92
93
94static struct pci_operations lops_pci = {
95 .set_subsystem = &usb_ehci_set_subsystem,
96};
97
98static struct device_operations usb_ehci_ops = {
99 .read_resources = pci_ehci_read_resources,
100 .set_resources = pci_dev_set_resources,
Vladimir Serbinenko83ef7492014-03-03 23:21:12 +0100101 .enable_resources = pci_dev_enable_resources,
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100102 .init = usb_ehci_init,
103 .scan_bus = 0,
104 .ops_pci = &lops_pci,
105};
106
107static const unsigned short pci_device_ids[] = { 0x3b34, 0x3b3c, 0 };
108
109static const struct pci_driver pch_usb_ehci __pci_driver = {
110 .ops = &usb_ehci_ops,
111 .vendor = PCI_VENDOR_ID_INTEL,
112 .devices = pci_device_ids,
113};