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> |
Kyösti Mälkki | 13f6650 | 2019-03-03 08:01:05 +0200 | [diff] [blame] | 23 | #include <device/mmio.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 24 | #include <device/pci_ops.h> |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 25 | |
| 26 | static void usb_ehci_init(struct device *dev) |
| 27 | { |
| 28 | u32 reg32; |
| 29 | |
| 30 | /* Disable Wake on Disconnect in RMH */ |
Patrick Rudolph | 4f8b108 | 2019-07-14 11:54:58 +0200 | [diff] [blame] | 31 | reg32 = RCBA32(RMHWKCTL); |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 32 | reg32 |= 0x22; |
Patrick Rudolph | 4f8b108 | 2019-07-14 11:54:58 +0200 | [diff] [blame] | 33 | RCBA32(RMHWKCTL) = reg32; |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 34 | |
| 35 | printk(BIOS_DEBUG, "EHCI: Setting up controller.. "); |
Vladimir Serbinenko | 7686a56 | 2014-05-18 11:05:56 +0200 | [diff] [blame] | 36 | |
| 37 | /* For others, done in MRC. */ |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 38 | #if CONFIG(USE_NATIVE_RAMINIT) |
Vladimir Serbinenko | 7686a56 | 2014-05-18 11:05:56 +0200 | [diff] [blame] | 39 | pci_write_config32(dev, 0x84, 0x930c8811); |
| 40 | pci_write_config32(dev, 0x88, 0x24000d30); |
| 41 | pci_write_config32(dev, 0xf4, 0x80408588); |
| 42 | pci_write_config32(dev, 0xf4, 0x80808588); |
| 43 | pci_write_config32(dev, 0xf4, 0x00808588); |
| 44 | pci_write_config32(dev, 0xfc, 0x205b1708); |
| 45 | #endif |
| 46 | |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 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 Serbinenko | 7686a56 | 2014-05-18 11:05:56 +0200 | [diff] [blame] | 52 | /* For others, done in MRC. */ |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 53 | #if CONFIG(USE_NATIVE_RAMINIT) |
Vladimir Serbinenko | 7686a56 | 2014-05-18 11:05:56 +0200 | [diff] [blame] | 54 | struct resource *res; |
| 55 | u8 access_cntl; |
| 56 | |
| 57 | access_cntl = pci_read_config8(dev, 0x80); |
| 58 | |
| 59 | /* Enable writes to protected registers. */ |
| 60 | pci_write_config8(dev, 0x80, access_cntl | 1); |
| 61 | |
| 62 | res = find_resource(dev, PCI_BASE_ADDRESS_0); |
| 63 | if (res) { |
| 64 | /* Number of ports and companion controllers. */ |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 65 | reg32 = read32((void *)(uintptr_t)(res->base + 4)); |
| 66 | write32((void *)(uintptr_t)(res->base + 4), |
| 67 | (reg32 & 0xfff00000) | 3); |
Vladimir Serbinenko | 7686a56 | 2014-05-18 11:05:56 +0200 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | /* Restore protection. */ |
| 71 | pci_write_config8(dev, 0x80, access_cntl); |
| 72 | #endif |
| 73 | |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 74 | printk(BIOS_DEBUG, "done.\n"); |
| 75 | } |
| 76 | |
Martin Roth | ff744bf | 2019-10-23 21:46:03 -0600 | [diff] [blame^] | 77 | static void usb_ehci_set_subsystem(struct device *dev, unsigned int vendor, |
| 78 | unsigned int device) |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 79 | { |
| 80 | u8 access_cntl; |
| 81 | |
| 82 | access_cntl = pci_read_config8(dev, 0x80); |
| 83 | |
| 84 | /* Enable writes to protected registers. */ |
| 85 | pci_write_config8(dev, 0x80, access_cntl | 1); |
| 86 | |
Subrata Banik | 4a0f071 | 2019-03-20 14:29:47 +0530 | [diff] [blame] | 87 | pci_dev_set_subsystem(dev, vendor, device); |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 88 | |
| 89 | /* Restore protection. */ |
| 90 | pci_write_config8(dev, 0x80, access_cntl); |
| 91 | } |
| 92 | |
Aaron Durbin | aa090cb | 2017-09-13 16:01:52 -0600 | [diff] [blame] | 93 | static const char *usb_ehci_acpi_name(const struct device *dev) |
Patrick Rudolph | 604f698 | 2017-06-07 09:46:52 +0200 | [diff] [blame] | 94 | { |
| 95 | switch (dev->path.pci.devfn) { |
| 96 | case PCI_DEVFN(0x1a, 0): |
| 97 | return "EHC2"; |
| 98 | case PCI_DEVFN(0x1d, 0): |
| 99 | return "EHC1"; |
| 100 | } |
| 101 | return NULL; |
| 102 | } |
| 103 | |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 104 | static struct pci_operations lops_pci = { |
| 105 | .set_subsystem = &usb_ehci_set_subsystem, |
| 106 | }; |
| 107 | |
| 108 | static struct device_operations usb_ehci_ops = { |
Kyösti Mälkki | fb387df | 2013-06-07 22:16:52 +0300 | [diff] [blame] | 109 | .read_resources = pci_ehci_read_resources, |
| 110 | .set_resources = pci_dev_set_resources, |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 111 | .enable_resources = pci_dev_enable_resources, |
| 112 | .init = usb_ehci_init, |
| 113 | .scan_bus = 0, |
| 114 | .ops_pci = &lops_pci, |
Patrick Rudolph | 604f698 | 2017-06-07 09:46:52 +0200 | [diff] [blame] | 115 | .acpi_name = usb_ehci_acpi_name, |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 116 | }; |
| 117 | |
Stefan Reinauer | 9a380ab | 2012-06-22 13:16:11 -0700 | [diff] [blame] | 118 | static const unsigned short pci_device_ids[] = { 0x1c26, 0x1c2d, 0x1e26, 0x1e2d, |
| 119 | 0 }; |
| 120 | |
| 121 | static const struct pci_driver pch_usb_ehci __pci_driver = { |
| 122 | .ops = &usb_ehci_ops, |
| 123 | .vendor = PCI_VENDOR_ID_INTEL, |
| 124 | .devices = pci_device_ids, |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 125 | }; |