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