Angel Pons | ae59387 | 2020-04-04 18:50:57 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 2 | |
| 3 | #include <console/console.h> |
| 4 | #include <device/device.h> |
| 5 | #include <device/pci.h> |
| 6 | #include <device/pci_ids.h> |
| 7 | #include <device/pci_ops.h> |
| 8 | #include <device/pci_ehci.h> |
Duncan Laurie | 32bdffa | 2018-05-07 15:37:28 -0700 | [diff] [blame] | 9 | #include <soc/acpi.h> |
Marc Jones | fb4c7d2 | 2017-11-22 22:16:31 -0700 | [diff] [blame] | 10 | #include <soc/pci_devs.h> |
Marc Jones | dfeb1c4 | 2017-08-07 19:08:24 -0600 | [diff] [blame] | 11 | #include <soc/southbridge.h> |
Marshall Dawson | 69486ca | 2019-05-02 12:03:45 -0600 | [diff] [blame] | 12 | #include <amdblocks/acpimmio.h> |
Marc Jones | fb4c7d2 | 2017-11-22 22:16:31 -0700 | [diff] [blame] | 13 | |
| 14 | static void set_usb_over_current(struct device *dev) |
| 15 | { |
| 16 | uint16_t map = USB_OC_DISABLE_ALL; |
| 17 | |
| 18 | if (dev->path.pci.devfn == XHCI_DEVFN) { |
| 19 | if (mainboard_get_xhci_oc_map(&map) == 0) { |
| 20 | xhci_pm_write32(XHCI_PM_INDIRECT_INDEX, |
| 21 | XHCI_OVER_CURRENT_CONTROL); |
| 22 | xhci_pm_write16(XHCI_PM_INDIRECT_DATA, map); |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | if (dev->path.pci.devfn == EHCI1_DEVFN) { |
| 27 | if (mainboard_get_ehci_oc_map(&map) == 0) |
| 28 | pci_write_config16(dev, EHCI_OVER_CURRENT_CONTROL, map); |
| 29 | } |
| 30 | } |
| 31 | |
Aaron Durbin | 6403167 | 2018-04-21 14:45:32 -0600 | [diff] [blame] | 32 | int __weak mainboard_get_xhci_oc_map(uint16_t *map) |
Marc Jones | fb4c7d2 | 2017-11-22 22:16:31 -0700 | [diff] [blame] | 33 | { |
| 34 | printk(BIOS_DEBUG, "WEAK: %s/%s called\n", __FILE__, __func__); |
| 35 | return -1; |
| 36 | } |
| 37 | |
Aaron Durbin | 6403167 | 2018-04-21 14:45:32 -0600 | [diff] [blame] | 38 | int __weak mainboard_get_ehci_oc_map(uint16_t *map) |
Marc Jones | fb4c7d2 | 2017-11-22 22:16:31 -0700 | [diff] [blame] | 39 | { |
| 40 | printk(BIOS_DEBUG, "WEAK: %s/%s called\n", __FILE__, __func__); |
| 41 | return -1; |
| 42 | } |
| 43 | |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 44 | static struct device_operations usb_ops = { |
| 45 | .read_resources = pci_ehci_read_resources, |
| 46 | .set_resources = pci_dev_set_resources, |
| 47 | .enable_resources = pci_dev_enable_resources, |
Marc Jones | fb4c7d2 | 2017-11-22 22:16:31 -0700 | [diff] [blame] | 48 | .init = set_usb_over_current, |
Nico Huber | a89c82e | 2017-09-14 15:40:28 +0200 | [diff] [blame] | 49 | .scan_bus = scan_static_bus, |
Duncan Laurie | 32bdffa | 2018-05-07 15:37:28 -0700 | [diff] [blame] | 50 | .acpi_name = soc_acpi_name, |
Angel Pons | 1fc0edd | 2020-05-31 00:03:28 +0200 | [diff] [blame] | 51 | .ops_pci = &pci_dev_ops_pci, |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 52 | }; |
| 53 | |
| 54 | static const unsigned short pci_device_ids[] = { |
Felix Singer | 43b7f41 | 2022-03-07 04:34:52 +0100 | [diff] [blame] | 55 | PCI_DID_AMD_SB900_USB_18_0, |
| 56 | PCI_DID_AMD_SB900_USB_18_2, |
| 57 | PCI_DID_AMD_SB900_USB_20_5, |
| 58 | PCI_DID_AMD_CZ_USB_0, |
| 59 | PCI_DID_AMD_CZ_USB_1, |
| 60 | PCI_DID_AMD_CZ_USB3_0, |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 61 | 0 |
| 62 | }; |
| 63 | |
| 64 | static const struct pci_driver usb_0_driver __pci_driver = { |
| 65 | .ops = &usb_ops, |
Felix Singer | 43b7f41 | 2022-03-07 04:34:52 +0100 | [diff] [blame] | 66 | .vendor = PCI_VID_AMD, |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 67 | .devices = pci_device_ids, |
| 68 | }; |