Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2010 Advanced Micro Devices, Inc. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; version 2 of the License. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | */ |
| 15 | |
| 16 | #include <console/console.h> |
| 17 | #include <device/device.h> |
| 18 | #include <device/pci.h> |
| 19 | #include <device/pci_ids.h> |
| 20 | #include <device/pci_ops.h> |
| 21 | #include <device/pci_ehci.h> |
Duncan Laurie | 32bdffa | 2018-05-07 15:37:28 -0700 | [diff] [blame] | 22 | #include <soc/acpi.h> |
Marc Jones | fb4c7d2 | 2017-11-22 22:16:31 -0700 | [diff] [blame] | 23 | #include <soc/pci_devs.h> |
Marc Jones | dfeb1c4 | 2017-08-07 19:08:24 -0600 | [diff] [blame] | 24 | #include <soc/southbridge.h> |
Marshall Dawson | 69486ca | 2019-05-02 12:03:45 -0600 | [diff] [blame^] | 25 | #include <amdblocks/acpimmio.h> |
Marc Jones | fb4c7d2 | 2017-11-22 22:16:31 -0700 | [diff] [blame] | 26 | |
| 27 | static void set_usb_over_current(struct device *dev) |
| 28 | { |
| 29 | uint16_t map = USB_OC_DISABLE_ALL; |
| 30 | |
| 31 | if (dev->path.pci.devfn == XHCI_DEVFN) { |
| 32 | if (mainboard_get_xhci_oc_map(&map) == 0) { |
| 33 | xhci_pm_write32(XHCI_PM_INDIRECT_INDEX, |
| 34 | XHCI_OVER_CURRENT_CONTROL); |
| 35 | xhci_pm_write16(XHCI_PM_INDIRECT_DATA, map); |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | if (dev->path.pci.devfn == EHCI1_DEVFN) { |
| 40 | if (mainboard_get_ehci_oc_map(&map) == 0) |
| 41 | pci_write_config16(dev, EHCI_OVER_CURRENT_CONTROL, map); |
| 42 | } |
| 43 | } |
| 44 | |
Aaron Durbin | 6403167 | 2018-04-21 14:45:32 -0600 | [diff] [blame] | 45 | int __weak mainboard_get_xhci_oc_map(uint16_t *map) |
Marc Jones | fb4c7d2 | 2017-11-22 22:16:31 -0700 | [diff] [blame] | 46 | { |
| 47 | printk(BIOS_DEBUG, "WEAK: %s/%s called\n", __FILE__, __func__); |
| 48 | return -1; |
| 49 | } |
| 50 | |
Aaron Durbin | 6403167 | 2018-04-21 14:45:32 -0600 | [diff] [blame] | 51 | int __weak mainboard_get_ehci_oc_map(uint16_t *map) |
Marc Jones | fb4c7d2 | 2017-11-22 22:16:31 -0700 | [diff] [blame] | 52 | { |
| 53 | printk(BIOS_DEBUG, "WEAK: %s/%s called\n", __FILE__, __func__); |
| 54 | return -1; |
| 55 | } |
| 56 | |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 57 | static struct pci_operations lops_pci = { |
| 58 | .set_subsystem = pci_dev_set_subsystem, |
| 59 | }; |
| 60 | |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 61 | static struct device_operations usb_ops = { |
| 62 | .read_resources = pci_ehci_read_resources, |
| 63 | .set_resources = pci_dev_set_resources, |
| 64 | .enable_resources = pci_dev_enable_resources, |
Marc Jones | fb4c7d2 | 2017-11-22 22:16:31 -0700 | [diff] [blame] | 65 | .init = set_usb_over_current, |
Duncan Laurie | 32bdffa | 2018-05-07 15:37:28 -0700 | [diff] [blame] | 66 | .scan_bus = scan_usb_bus, |
| 67 | .acpi_name = soc_acpi_name, |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 68 | .ops_pci = &lops_pci, |
| 69 | }; |
| 70 | |
| 71 | static const unsigned short pci_device_ids[] = { |
| 72 | PCI_DEVICE_ID_AMD_SB900_USB_18_0, |
| 73 | PCI_DEVICE_ID_AMD_SB900_USB_18_2, |
| 74 | PCI_DEVICE_ID_AMD_SB900_USB_20_5, |
| 75 | PCI_DEVICE_ID_AMD_CZ_USB_0, |
| 76 | PCI_DEVICE_ID_AMD_CZ_USB_1, |
| 77 | PCI_DEVICE_ID_AMD_CZ_USB3_0, |
| 78 | 0 |
| 79 | }; |
| 80 | |
| 81 | static const struct pci_driver usb_0_driver __pci_driver = { |
| 82 | .ops = &usb_ops, |
| 83 | .vendor = PCI_VENDOR_ID_AMD, |
| 84 | .devices = pci_device_ids, |
| 85 | }; |