Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 1 | /* |
| 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 Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | #include <console/console.h> |
| 18 | #include <device/device.h> |
| 19 | #include <device/pci.h> |
| 20 | #include <device/pci_ids.h> |
| 21 | #include "pch.h" |
Kyösti Mälkki | e2227a2 | 2014-02-05 13:02:55 +0200 | [diff] [blame] | 22 | #include <device/pci_ehci.h> |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 23 | #include <arch/io.h> |
| 24 | |
| 25 | static void usb_ehci_init(struct device *dev) |
| 26 | { |
| 27 | u32 reg32; |
| 28 | |
| 29 | /* Disable Wake on Disconnect in RMH */ |
| 30 | reg32 = RCBA32(0x35b0); |
| 31 | reg32 |= 0x22; |
| 32 | RCBA32(0x35b0) = reg32; |
| 33 | |
| 34 | printk(BIOS_DEBUG, "EHCI: Setting up controller.. "); |
Vladimir Serbinenko | 7686a56 | 2014-05-18 11:05:56 +0200 | [diff] [blame] | 35 | |
| 36 | /* For others, done in MRC. */ |
Vladimir Serbinenko | 144eea0 | 2016-02-10 02:36:04 +0100 | [diff] [blame] | 37 | #if IS_ENABLED(CONFIG_USE_NATIVE_RAMINIT) |
Vladimir Serbinenko | 7686a56 | 2014-05-18 11:05:56 +0200 | [diff] [blame] | 38 | 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 Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 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 Serbinenko | 7686a56 | 2014-05-18 11:05:56 +0200 | [diff] [blame] | 51 | /* For others, done in MRC. */ |
Vladimir Serbinenko | 144eea0 | 2016-02-10 02:36:04 +0100 | [diff] [blame] | 52 | #if IS_ENABLED(CONFIG_USE_NATIVE_RAMINIT) |
Vladimir Serbinenko | 7686a56 | 2014-05-18 11:05:56 +0200 | [diff] [blame] | 53 | 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 Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 64 | reg32 = read32((void *)(uintptr_t)(res->base + 4)); |
| 65 | write32((void *)(uintptr_t)(res->base + 4), |
| 66 | (reg32 & 0xfff00000) | 3); |
Vladimir Serbinenko | 7686a56 | 2014-05-18 11:05:56 +0200 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | /* Restore protection. */ |
| 70 | pci_write_config8(dev, 0x80, access_cntl); |
| 71 | #endif |
| 72 | |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 73 | printk(BIOS_DEBUG, "done.\n"); |
| 74 | } |
| 75 | |
| 76 | static void usb_ehci_set_subsystem(device_t dev, unsigned vendor, unsigned device) |
| 77 | { |
| 78 | u8 access_cntl; |
| 79 | |
| 80 | access_cntl = pci_read_config8(dev, 0x80); |
| 81 | |
| 82 | /* Enable writes to protected registers. */ |
| 83 | pci_write_config8(dev, 0x80, access_cntl | 1); |
| 84 | |
| 85 | if (!vendor || !device) { |
| 86 | pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID, |
| 87 | pci_read_config32(dev, PCI_VENDOR_ID)); |
| 88 | } else { |
| 89 | pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID, |
| 90 | ((device & 0xffff) << 16) | (vendor & 0xffff)); |
| 91 | } |
| 92 | |
| 93 | /* Restore protection. */ |
| 94 | pci_write_config8(dev, 0x80, access_cntl); |
| 95 | } |
| 96 | |
Aaron Durbin | aa090cb | 2017-09-13 16:01:52 -0600 | [diff] [blame^] | 97 | static const char *usb_ehci_acpi_name(const struct device *dev) |
Patrick Rudolph | 604f698 | 2017-06-07 09:46:52 +0200 | [diff] [blame] | 98 | { |
| 99 | switch (dev->path.pci.devfn) { |
| 100 | case PCI_DEVFN(0x1a, 0): |
| 101 | return "EHC2"; |
| 102 | case PCI_DEVFN(0x1d, 0): |
| 103 | return "EHC1"; |
| 104 | } |
| 105 | return NULL; |
| 106 | } |
| 107 | |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 108 | static struct pci_operations lops_pci = { |
| 109 | .set_subsystem = &usb_ehci_set_subsystem, |
| 110 | }; |
| 111 | |
| 112 | static struct device_operations usb_ehci_ops = { |
Kyösti Mälkki | fb387df | 2013-06-07 22:16:52 +0300 | [diff] [blame] | 113 | .read_resources = pci_ehci_read_resources, |
| 114 | .set_resources = pci_dev_set_resources, |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 115 | .enable_resources = pci_dev_enable_resources, |
| 116 | .init = usb_ehci_init, |
| 117 | .scan_bus = 0, |
| 118 | .ops_pci = &lops_pci, |
Patrick Rudolph | 604f698 | 2017-06-07 09:46:52 +0200 | [diff] [blame] | 119 | .acpi_name = usb_ehci_acpi_name, |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 120 | }; |
| 121 | |
Stefan Reinauer | 9a380ab | 2012-06-22 13:16:11 -0700 | [diff] [blame] | 122 | static const unsigned short pci_device_ids[] = { 0x1c26, 0x1c2d, 0x1e26, 0x1e2d, |
| 123 | 0 }; |
| 124 | |
| 125 | static const struct pci_driver pch_usb_ehci __pci_driver = { |
| 126 | .ops = &usb_ehci_ops, |
| 127 | .vendor = PCI_VENDOR_ID_INTEL, |
| 128 | .devices = pci_device_ids, |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 129 | }; |