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