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