Angel Pons | f94ac9a | 2020-04-05 15:46:48 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 2 | |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 3 | #include <device/device.h> |
| 4 | #include <device/pci.h> |
| 5 | #include <device/pci_ids.h> |
Georg Wicherski | 49ee5ef | 2015-10-13 16:27:15 +0200 | [diff] [blame] | 6 | #include <device/pci_ehci.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 7 | #include <device/pci_ops.h> |
Julius Werner | 4ee4bd5 | 2014-10-20 13:46:39 -0700 | [diff] [blame] | 8 | #include <soc/ehci.h> |
| 9 | #include <soc/pch.h> |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 10 | |
Elyes HAOUAS | 040aff2 | 2018-05-27 16:30:36 +0200 | [diff] [blame] | 11 | static void usb_ehci_set_subsystem(struct device *dev, unsigned int vendor, |
Lee Leahy | 23602df | 2017-03-16 19:00:37 -0700 | [diff] [blame] | 12 | unsigned int device) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 13 | { |
| 14 | u8 access_cntl; |
| 15 | |
| 16 | access_cntl = pci_read_config8(dev, 0x80); |
| 17 | |
| 18 | /* Enable writes to protected registers. */ |
| 19 | pci_write_config8(dev, 0x80, access_cntl | 1); |
| 20 | |
Subrata Banik | 4a0f071 | 2019-03-20 14:29:47 +0530 | [diff] [blame] | 21 | pci_dev_set_subsystem(dev, vendor, device); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 22 | |
| 23 | /* Restore protection. */ |
| 24 | pci_write_config8(dev, 0x80, access_cntl); |
| 25 | } |
| 26 | |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 27 | static void ehci_enable(struct device *dev) |
| 28 | { |
Kyösti Mälkki | fd15955 | 2019-03-20 18:46:30 +0200 | [diff] [blame] | 29 | if (CONFIG(USBDEBUG)) |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 30 | dev->enabled = 1; |
| 31 | else |
| 32 | pch_disable_devfn(dev); |
| 33 | } |
| 34 | |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 35 | static struct pci_operations ehci_ops_pci = { |
| 36 | .set_subsystem = &usb_ehci_set_subsystem, |
| 37 | }; |
| 38 | |
| 39 | static struct device_operations usb_ehci_ops = { |
Elyes HAOUAS | 1d19127 | 2018-11-27 12:23:48 +0100 | [diff] [blame] | 40 | .read_resources = pci_ehci_read_resources, |
| 41 | .set_resources = pci_dev_set_resources, |
| 42 | .enable_resources = pci_dev_enable_resources, |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 43 | .ops_pci = &ehci_ops_pci, |
Elyes HAOUAS | 1d19127 | 2018-11-27 12:23:48 +0100 | [diff] [blame] | 44 | .enable = ehci_enable, |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 45 | }; |
| 46 | |
| 47 | static const unsigned short pci_device_ids[] = { |
| 48 | 0x9c26, /* LynxPoint-LP */ |
| 49 | 0x9ca6, /* WildcatPoint */ |
| 50 | 0 |
| 51 | }; |
| 52 | |
| 53 | static const struct pci_driver pch_usb_ehci __pci_driver = { |
| 54 | .ops = &usb_ehci_ops, |
| 55 | .vendor = PCI_VENDOR_ID_INTEL, |
| 56 | .devices = pci_device_ids, |
| 57 | }; |