Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2008-2009 coresystems GmbH |
| 5 | * Copyright (C) 2014 Google Inc. |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; version 2 of the License. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | #include <console/console.h> |
| 18 | #include <delay.h> |
| 19 | #include <device/device.h> |
| 20 | #include <device/pci.h> |
| 21 | #include <device/pci_ids.h> |
Georg Wicherski | 49ee5ef | 2015-10-13 16:27:15 +0200 | [diff] [blame] | 22 | #include <device/pci_ehci.h> |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 23 | #include <arch/io.h> |
Julius Werner | 4ee4bd5 | 2014-10-20 13:46:39 -0700 | [diff] [blame] | 24 | #include <soc/ehci.h> |
| 25 | #include <soc/pch.h> |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 26 | |
Lee Leahy | 23602df | 2017-03-16 19:00:37 -0700 | [diff] [blame] | 27 | static void usb_ehci_set_subsystem(device_t dev, unsigned int vendor, |
| 28 | unsigned int device) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 29 | { |
| 30 | u8 access_cntl; |
| 31 | |
| 32 | access_cntl = pci_read_config8(dev, 0x80); |
| 33 | |
| 34 | /* Enable writes to protected registers. */ |
| 35 | pci_write_config8(dev, 0x80, access_cntl | 1); |
| 36 | |
| 37 | if (!vendor || !device) { |
| 38 | pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID, |
| 39 | pci_read_config32(dev, PCI_VENDOR_ID)); |
| 40 | } else { |
| 41 | pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID, |
| 42 | ((device & 0xffff) << 16) | (vendor & 0xffff)); |
| 43 | } |
| 44 | |
| 45 | /* Restore protection. */ |
| 46 | pci_write_config8(dev, 0x80, access_cntl); |
| 47 | } |
| 48 | |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 49 | static void ehci_enable(struct device *dev) |
| 50 | { |
| 51 | if (CONFIG_USBDEBUG) |
| 52 | dev->enabled = 1; |
| 53 | else |
| 54 | pch_disable_devfn(dev); |
| 55 | } |
| 56 | |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 57 | static struct pci_operations ehci_ops_pci = { |
| 58 | .set_subsystem = &usb_ehci_set_subsystem, |
| 59 | }; |
| 60 | |
| 61 | static struct device_operations usb_ehci_ops = { |
Georg Wicherski | 49ee5ef | 2015-10-13 16:27:15 +0200 | [diff] [blame] | 62 | .read_resources = &pci_ehci_read_resources, |
| 63 | .set_resources = &pci_dev_set_resources, |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 64 | .enable_resources = &pci_dev_enable_resources, |
| 65 | .ops_pci = &ehci_ops_pci, |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 66 | .enable = &ehci_enable, |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 67 | }; |
| 68 | |
| 69 | static const unsigned short pci_device_ids[] = { |
| 70 | 0x9c26, /* LynxPoint-LP */ |
| 71 | 0x9ca6, /* WildcatPoint */ |
| 72 | 0 |
| 73 | }; |
| 74 | |
| 75 | static const struct pci_driver pch_usb_ehci __pci_driver = { |
| 76 | .ops = &usb_ehci_ops, |
| 77 | .vendor = PCI_VENDOR_ID_INTEL, |
| 78 | .devices = pci_device_ids, |
| 79 | }; |