blob: 00f82375e836faf59f7307bdf6d7819475e114f2 [file] [log] [blame]
Marc Jones24484842017-05-04 21:17:45 -06001/*
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 Laurie32bdffa2018-05-07 15:37:28 -070022#include <soc/acpi.h>
Marc Jonesfb4c7d22017-11-22 22:16:31 -070023#include <soc/pci_devs.h>
Marc Jonesdfeb1c42017-08-07 19:08:24 -060024#include <soc/southbridge.h>
Marshall Dawson69486ca2019-05-02 12:03:45 -060025#include <amdblocks/acpimmio.h>
Marc Jonesfb4c7d22017-11-22 22:16:31 -070026
27static 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 Durbin64031672018-04-21 14:45:32 -060045int __weak mainboard_get_xhci_oc_map(uint16_t *map)
Marc Jonesfb4c7d22017-11-22 22:16:31 -070046{
47 printk(BIOS_DEBUG, "WEAK: %s/%s called\n", __FILE__, __func__);
48 return -1;
49}
50
Aaron Durbin64031672018-04-21 14:45:32 -060051int __weak mainboard_get_ehci_oc_map(uint16_t *map)
Marc Jonesfb4c7d22017-11-22 22:16:31 -070052{
53 printk(BIOS_DEBUG, "WEAK: %s/%s called\n", __FILE__, __func__);
54 return -1;
55}
56
Marc Jones24484842017-05-04 21:17:45 -060057static struct pci_operations lops_pci = {
58 .set_subsystem = pci_dev_set_subsystem,
59};
60
Marc Jones24484842017-05-04 21:17:45 -060061static 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 Jonesfb4c7d22017-11-22 22:16:31 -070065 .init = set_usb_over_current,
Duncan Laurie32bdffa2018-05-07 15:37:28 -070066 .scan_bus = scan_usb_bus,
67 .acpi_name = soc_acpi_name,
Marc Jones24484842017-05-04 21:17:45 -060068 .ops_pci = &lops_pci,
69};
70
71static 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
81static 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};