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. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 19 | */ |
| 20 | |
| 21 | #include <console/console.h> |
| 22 | #include <delay.h> |
| 23 | #include <device/device.h> |
| 24 | #include <device/pci.h> |
| 25 | #include <device/pci_ids.h> |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 26 | #include <arch/io.h> |
| 27 | #include <broadwell/ehci.h> |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 28 | #include <broadwell/pch.h> |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 29 | |
| 30 | static void usb_ehci_set_subsystem(device_t dev, unsigned vendor, unsigned device) |
| 31 | { |
| 32 | u8 access_cntl; |
| 33 | |
| 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 | if (!vendor || !device) { |
| 40 | pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID, |
| 41 | pci_read_config32(dev, PCI_VENDOR_ID)); |
| 42 | } else { |
| 43 | pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID, |
| 44 | ((device & 0xffff) << 16) | (vendor & 0xffff)); |
| 45 | } |
| 46 | |
| 47 | /* Restore protection. */ |
| 48 | pci_write_config8(dev, 0x80, access_cntl); |
| 49 | } |
| 50 | |
| 51 | static void usb_ehci_set_resources(struct device *dev) |
| 52 | { |
| 53 | #if CONFIG_USBDEBUG |
| 54 | struct resource *res; |
| 55 | u32 base; |
| 56 | u32 usb_debug; |
| 57 | |
| 58 | usb_debug = get_ehci_debug(); |
| 59 | set_ehci_debug(0); |
| 60 | #endif |
| 61 | pci_dev_set_resources(dev); |
| 62 | |
| 63 | #if CONFIG_USBDEBUG |
| 64 | res = find_resource(dev, 0x10); |
| 65 | set_ehci_debug(usb_debug); |
| 66 | if (!res) return; |
| 67 | base = res->base; |
| 68 | set_ehci_base(base); |
| 69 | report_resource_stored(dev, res, ""); |
| 70 | #endif |
| 71 | } |
| 72 | |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 73 | static void ehci_enable(struct device *dev) |
| 74 | { |
| 75 | if (CONFIG_USBDEBUG) |
| 76 | dev->enabled = 1; |
| 77 | else |
| 78 | pch_disable_devfn(dev); |
| 79 | } |
| 80 | |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 81 | static struct pci_operations ehci_ops_pci = { |
| 82 | .set_subsystem = &usb_ehci_set_subsystem, |
| 83 | }; |
| 84 | |
| 85 | static struct device_operations usb_ehci_ops = { |
| 86 | .read_resources = &pci_dev_read_resources, |
| 87 | .set_resources = &usb_ehci_set_resources, |
| 88 | .enable_resources = &pci_dev_enable_resources, |
| 89 | .ops_pci = &ehci_ops_pci, |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 90 | .enable = &ehci_enable, |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 91 | }; |
| 92 | |
| 93 | static const unsigned short pci_device_ids[] = { |
| 94 | 0x9c26, /* LynxPoint-LP */ |
| 95 | 0x9ca6, /* WildcatPoint */ |
| 96 | 0 |
| 97 | }; |
| 98 | |
| 99 | static const struct pci_driver pch_usb_ehci __pci_driver = { |
| 100 | .ops = &usb_ehci_ops, |
| 101 | .vendor = PCI_VENDOR_ID_INTEL, |
| 102 | .devices = pci_device_ids, |
| 103 | }; |