Angel Pons | 182dbde | 2020-04-02 23:49:05 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | /* This file is part of the coreboot project. */ |
Vladimir Serbinenko | 888d559 | 2013-11-13 17:53:38 +0100 | [diff] [blame] | 3 | |
| 4 | #include <console/console.h> |
| 5 | #include <device/device.h> |
| 6 | #include <device/pci.h> |
| 7 | #include <device/pci_ids.h> |
| 8 | #include "pch.h" |
Kyösti Mälkki | e2227a2 | 2014-02-05 13:02:55 +0200 | [diff] [blame] | 9 | #include <device/pci_ehci.h> |
Kyösti Mälkki | 13f6650 | 2019-03-03 08:01:05 +0200 | [diff] [blame] | 10 | #include <device/mmio.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 11 | #include <device/pci_ops.h> |
Vladimir Serbinenko | 888d559 | 2013-11-13 17:53:38 +0100 | [diff] [blame] | 12 | |
| 13 | static void usb_ehci_init(struct device *dev) |
| 14 | { |
| 15 | u32 reg32; |
Vladimir Serbinenko | 61f902d | 2014-06-07 16:41:14 +0200 | [diff] [blame] | 16 | struct resource *res; |
| 17 | u8 access_cntl; |
Vladimir Serbinenko | 888d559 | 2013-11-13 17:53:38 +0100 | [diff] [blame] | 18 | |
| 19 | /* Disable Wake on Disconnect in RMH */ |
| 20 | reg32 = RCBA32(0x35b0); |
| 21 | reg32 |= 0x22; |
| 22 | RCBA32(0x35b0) = reg32; |
| 23 | |
| 24 | printk(BIOS_DEBUG, "EHCI: Setting up controller.. "); |
| 25 | |
| 26 | pci_write_config32(dev, 0x84, 0x130c8911); |
| 27 | pci_write_config32(dev, 0x88, 0xa0); |
| 28 | pci_write_config32(dev, 0xf4, 0x80808588); |
| 29 | pci_write_config32(dev, 0xf4, 0x00808588); |
| 30 | pci_write_config32(dev, 0xf4, 0x00808588); |
| 31 | pci_write_config32(dev, 0xfc, 0x301b1728); |
| 32 | |
| 33 | reg32 = pci_read_config32(dev, PCI_COMMAND); |
| 34 | reg32 |= PCI_COMMAND_MASTER; |
| 35 | //reg32 |= PCI_COMMAND_SERR; |
| 36 | pci_write_config32(dev, PCI_COMMAND, reg32); |
| 37 | |
Vladimir Serbinenko | 61f902d | 2014-06-07 16:41:14 +0200 | [diff] [blame] | 38 | access_cntl = pci_read_config8(dev, 0x80); |
| 39 | |
| 40 | /* Enable writes to protected registers. */ |
| 41 | pci_write_config8(dev, 0x80, access_cntl | 1); |
| 42 | |
| 43 | res = find_resource(dev, PCI_BASE_ADDRESS_0); |
| 44 | if (res) { |
| 45 | /* Number of ports and companion controllers. */ |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 46 | reg32 = read32((u32 *)(uintptr_t)(res->base + 4)); |
| 47 | write32((u32 *)(uintptr_t)(res->base + 4), |
| 48 | (reg32 & 0xfff00000) | 2); |
Vladimir Serbinenko | 61f902d | 2014-06-07 16:41:14 +0200 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | /* Restore protection. */ |
| 52 | pci_write_config8(dev, 0x80, access_cntl); |
| 53 | |
Vladimir Serbinenko | 888d559 | 2013-11-13 17:53:38 +0100 | [diff] [blame] | 54 | printk(BIOS_DEBUG, "done.\n"); |
| 55 | } |
| 56 | |
Martin Roth | ff744bf | 2019-10-23 21:46:03 -0600 | [diff] [blame] | 57 | static void usb_ehci_set_subsystem(struct device *dev, unsigned int vendor, |
| 58 | unsigned int device) |
Vladimir Serbinenko | 888d559 | 2013-11-13 17:53:38 +0100 | [diff] [blame] | 59 | { |
| 60 | u8 access_cntl; |
| 61 | |
| 62 | access_cntl = pci_read_config8(dev, 0x80); |
| 63 | |
| 64 | /* Enable writes to protected registers. */ |
| 65 | pci_write_config8(dev, 0x80, access_cntl | 1); |
| 66 | |
Subrata Banik | 4a0f071 | 2019-03-20 14:29:47 +0530 | [diff] [blame] | 67 | pci_dev_set_subsystem(dev, vendor, device); |
Vladimir Serbinenko | 888d559 | 2013-11-13 17:53:38 +0100 | [diff] [blame] | 68 | |
| 69 | /* Restore protection. */ |
| 70 | pci_write_config8(dev, 0x80, access_cntl); |
| 71 | } |
| 72 | |
| 73 | |
| 74 | static struct pci_operations lops_pci = { |
| 75 | .set_subsystem = &usb_ehci_set_subsystem, |
| 76 | }; |
| 77 | |
| 78 | static struct device_operations usb_ehci_ops = { |
| 79 | .read_resources = pci_ehci_read_resources, |
| 80 | .set_resources = pci_dev_set_resources, |
Vladimir Serbinenko | 83ef749 | 2014-03-03 23:21:12 +0100 | [diff] [blame] | 81 | .enable_resources = pci_dev_enable_resources, |
Vladimir Serbinenko | 888d559 | 2013-11-13 17:53:38 +0100 | [diff] [blame] | 82 | .init = usb_ehci_init, |
Vladimir Serbinenko | 888d559 | 2013-11-13 17:53:38 +0100 | [diff] [blame] | 83 | .ops_pci = &lops_pci, |
| 84 | }; |
| 85 | |
Felix Singer | 838fbc7 | 2019-11-21 21:23:32 +0100 | [diff] [blame] | 86 | static const unsigned short pci_device_ids[] = { |
| 87 | PCI_DID_INTEL_IBEXPEAK_EHCI_1, |
| 88 | PCI_DID_INTEL_IBEXPEAK_EHCI_2, |
| 89 | 0 |
| 90 | }; |
Vladimir Serbinenko | 888d559 | 2013-11-13 17:53:38 +0100 | [diff] [blame] | 91 | |
| 92 | static const struct pci_driver pch_usb_ehci __pci_driver = { |
| 93 | .ops = &usb_ehci_ops, |
| 94 | .vendor = PCI_VENDOR_ID_INTEL, |
| 95 | .devices = pci_device_ids, |
| 96 | }; |