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 | |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 17 | #include <delay.h> |
| 18 | #include <device/device.h> |
| 19 | #include <device/pci.h> |
| 20 | #include <device/pci_ids.h> |
Georg Wicherski | 49ee5ef | 2015-10-13 16:27:15 +0200 | [diff] [blame] | 21 | #include <device/pci_ehci.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 22 | #include <device/pci_ops.h> |
Julius Werner | 4ee4bd5 | 2014-10-20 13:46:39 -0700 | [diff] [blame] | 23 | #include <soc/ehci.h> |
| 24 | #include <soc/pch.h> |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 25 | |
Elyes HAOUAS | 040aff2 | 2018-05-27 16:30:36 +0200 | [diff] [blame] | 26 | static void usb_ehci_set_subsystem(struct device *dev, unsigned int vendor, |
Lee Leahy | 23602df | 2017-03-16 19:00:37 -0700 | [diff] [blame] | 27 | unsigned int device) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 28 | { |
| 29 | u8 access_cntl; |
| 30 | |
| 31 | access_cntl = pci_read_config8(dev, 0x80); |
| 32 | |
| 33 | /* Enable writes to protected registers. */ |
| 34 | pci_write_config8(dev, 0x80, access_cntl | 1); |
| 35 | |
| 36 | if (!vendor || !device) { |
| 37 | pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID, |
| 38 | pci_read_config32(dev, PCI_VENDOR_ID)); |
| 39 | } else { |
| 40 | pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID, |
| 41 | ((device & 0xffff) << 16) | (vendor & 0xffff)); |
| 42 | } |
| 43 | |
| 44 | /* Restore protection. */ |
| 45 | pci_write_config8(dev, 0x80, access_cntl); |
| 46 | } |
| 47 | |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 48 | static void ehci_enable(struct device *dev) |
| 49 | { |
| 50 | if (CONFIG_USBDEBUG) |
| 51 | dev->enabled = 1; |
| 52 | else |
| 53 | pch_disable_devfn(dev); |
| 54 | } |
| 55 | |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 56 | static struct pci_operations ehci_ops_pci = { |
| 57 | .set_subsystem = &usb_ehci_set_subsystem, |
| 58 | }; |
| 59 | |
| 60 | static struct device_operations usb_ehci_ops = { |
Elyes HAOUAS | 1d19127 | 2018-11-27 12:23:48 +0100 | [diff] [blame] | 61 | .read_resources = pci_ehci_read_resources, |
| 62 | .set_resources = pci_dev_set_resources, |
| 63 | .enable_resources = pci_dev_enable_resources, |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 64 | .ops_pci = &ehci_ops_pci, |
Elyes HAOUAS | 1d19127 | 2018-11-27 12:23:48 +0100 | [diff] [blame] | 65 | .enable = ehci_enable, |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 66 | }; |
| 67 | |
| 68 | static const unsigned short pci_device_ids[] = { |
| 69 | 0x9c26, /* LynxPoint-LP */ |
| 70 | 0x9ca6, /* WildcatPoint */ |
| 71 | 0 |
| 72 | }; |
| 73 | |
| 74 | static const struct pci_driver pch_usb_ehci __pci_driver = { |
| 75 | .ops = &usb_ehci_ops, |
| 76 | .vendor = PCI_VENDOR_ID_INTEL, |
| 77 | .devices = pci_device_ids, |
| 78 | }; |