Vladimir Serbinenko | 888d559 | 2013-11-13 17:53:38 +0100 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
Vladimir Serbinenko | 888d559 | 2013-11-13 17:53:38 +0100 | [diff] [blame] | 4 | * |
| 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License as |
| 7 | * published by the Free Software Foundation; version 2 of |
| 8 | * the License. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
Vladimir Serbinenko | 888d559 | 2013-11-13 17:53:38 +0100 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #include <console/console.h> |
| 17 | #include <device/device.h> |
| 18 | #include <device/pci.h> |
| 19 | #include <device/pci_ids.h> |
| 20 | #include "pch.h" |
Kyösti Mälkki | e2227a2 | 2014-02-05 13:02:55 +0200 | [diff] [blame] | 21 | #include <device/pci_ehci.h> |
Kyösti Mälkki | 13f6650 | 2019-03-03 08:01:05 +0200 | [diff] [blame] | 22 | #include <device/mmio.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 23 | #include <device/pci_ops.h> |
Vladimir Serbinenko | 888d559 | 2013-11-13 17:53:38 +0100 | [diff] [blame] | 24 | |
| 25 | static void usb_ehci_init(struct device *dev) |
| 26 | { |
| 27 | u32 reg32; |
Vladimir Serbinenko | 61f902d | 2014-06-07 16:41:14 +0200 | [diff] [blame] | 28 | struct resource *res; |
| 29 | u8 access_cntl; |
Vladimir Serbinenko | 888d559 | 2013-11-13 17:53:38 +0100 | [diff] [blame] | 30 | |
| 31 | /* Disable Wake on Disconnect in RMH */ |
| 32 | reg32 = RCBA32(0x35b0); |
| 33 | reg32 |= 0x22; |
| 34 | RCBA32(0x35b0) = reg32; |
| 35 | |
| 36 | printk(BIOS_DEBUG, "EHCI: Setting up controller.. "); |
| 37 | |
| 38 | pci_write_config32(dev, 0x84, 0x130c8911); |
| 39 | pci_write_config32(dev, 0x88, 0xa0); |
| 40 | pci_write_config32(dev, 0xf4, 0x80808588); |
| 41 | pci_write_config32(dev, 0xf4, 0x00808588); |
| 42 | pci_write_config32(dev, 0xf4, 0x00808588); |
| 43 | pci_write_config32(dev, 0xfc, 0x301b1728); |
| 44 | |
| 45 | reg32 = pci_read_config32(dev, PCI_COMMAND); |
| 46 | reg32 |= PCI_COMMAND_MASTER; |
| 47 | //reg32 |= PCI_COMMAND_SERR; |
| 48 | pci_write_config32(dev, PCI_COMMAND, reg32); |
| 49 | |
Vladimir Serbinenko | 61f902d | 2014-06-07 16:41:14 +0200 | [diff] [blame] | 50 | access_cntl = pci_read_config8(dev, 0x80); |
| 51 | |
| 52 | /* Enable writes to protected registers. */ |
| 53 | pci_write_config8(dev, 0x80, access_cntl | 1); |
| 54 | |
| 55 | res = find_resource(dev, PCI_BASE_ADDRESS_0); |
| 56 | if (res) { |
| 57 | /* Number of ports and companion controllers. */ |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 58 | reg32 = read32((u32 *)(uintptr_t)(res->base + 4)); |
| 59 | write32((u32 *)(uintptr_t)(res->base + 4), |
| 60 | (reg32 & 0xfff00000) | 2); |
Vladimir Serbinenko | 61f902d | 2014-06-07 16:41:14 +0200 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | /* Restore protection. */ |
| 64 | pci_write_config8(dev, 0x80, access_cntl); |
| 65 | |
Vladimir Serbinenko | 888d559 | 2013-11-13 17:53:38 +0100 | [diff] [blame] | 66 | printk(BIOS_DEBUG, "done.\n"); |
| 67 | } |
| 68 | |
Martin Roth | ff744bf | 2019-10-23 21:46:03 -0600 | [diff] [blame] | 69 | static void usb_ehci_set_subsystem(struct device *dev, unsigned int vendor, |
| 70 | unsigned int device) |
Vladimir Serbinenko | 888d559 | 2013-11-13 17:53:38 +0100 | [diff] [blame] | 71 | { |
| 72 | u8 access_cntl; |
| 73 | |
| 74 | access_cntl = pci_read_config8(dev, 0x80); |
| 75 | |
| 76 | /* Enable writes to protected registers. */ |
| 77 | pci_write_config8(dev, 0x80, access_cntl | 1); |
| 78 | |
Subrata Banik | 4a0f071 | 2019-03-20 14:29:47 +0530 | [diff] [blame] | 79 | pci_dev_set_subsystem(dev, vendor, device); |
Vladimir Serbinenko | 888d559 | 2013-11-13 17:53:38 +0100 | [diff] [blame] | 80 | |
| 81 | /* Restore protection. */ |
| 82 | pci_write_config8(dev, 0x80, access_cntl); |
| 83 | } |
| 84 | |
| 85 | |
| 86 | static struct pci_operations lops_pci = { |
| 87 | .set_subsystem = &usb_ehci_set_subsystem, |
| 88 | }; |
| 89 | |
| 90 | static struct device_operations usb_ehci_ops = { |
| 91 | .read_resources = pci_ehci_read_resources, |
| 92 | .set_resources = pci_dev_set_resources, |
Vladimir Serbinenko | 83ef749 | 2014-03-03 23:21:12 +0100 | [diff] [blame] | 93 | .enable_resources = pci_dev_enable_resources, |
Vladimir Serbinenko | 888d559 | 2013-11-13 17:53:38 +0100 | [diff] [blame] | 94 | .init = usb_ehci_init, |
| 95 | .scan_bus = 0, |
| 96 | .ops_pci = &lops_pci, |
| 97 | }; |
| 98 | |
| 99 | static const unsigned short pci_device_ids[] = { 0x3b34, 0x3b3c, 0 }; |
| 100 | |
| 101 | static const struct pci_driver pch_usb_ehci __pci_driver = { |
| 102 | .ops = &usb_ehci_ops, |
| 103 | .vendor = PCI_VENDOR_ID_INTEL, |
| 104 | .devices = pci_device_ids, |
| 105 | }; |