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