blob: e6d608e7dcf0765da702ed6026f2f57d8470206c [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
Aaron Durbin64031672018-04-21 14:45:32 -060016#include <compiler.h>
Marc Jones24484842017-05-04 21:17:45 -060017#include <console/console.h>
18#include <device/device.h>
19#include <device/pci.h>
20#include <device/pci_ids.h>
21#include <device/pci_ops.h>
22#include <device/pci_ehci.h>
23#include <arch/io.h>
Marc Jonesfb4c7d22017-11-22 22:16:31 -070024#include <soc/pci_devs.h>
Marc Jonesdfeb1c42017-08-07 19:08:24 -060025#include <soc/southbridge.h>
Marc Jones24484842017-05-04 21:17:45 -060026
Marc Jonesfb4c7d22017-11-22 22:16:31 -070027
28static void set_usb_over_current(struct device *dev)
29{
30 uint16_t map = USB_OC_DISABLE_ALL;
31
32 if (dev->path.pci.devfn == XHCI_DEVFN) {
33 if (mainboard_get_xhci_oc_map(&map) == 0) {
34 xhci_pm_write32(XHCI_PM_INDIRECT_INDEX,
35 XHCI_OVER_CURRENT_CONTROL);
36 xhci_pm_write16(XHCI_PM_INDIRECT_DATA, map);
37 }
38 }
39
40 if (dev->path.pci.devfn == EHCI1_DEVFN) {
41 if (mainboard_get_ehci_oc_map(&map) == 0)
42 pci_write_config16(dev, EHCI_OVER_CURRENT_CONTROL, map);
43 }
44}
45
Aaron Durbin64031672018-04-21 14:45:32 -060046int __weak mainboard_get_xhci_oc_map(uint16_t *map)
Marc Jonesfb4c7d22017-11-22 22:16:31 -070047{
48 printk(BIOS_DEBUG, "WEAK: %s/%s called\n", __FILE__, __func__);
49 return -1;
50}
51
Aaron Durbin64031672018-04-21 14:45:32 -060052int __weak mainboard_get_ehci_oc_map(uint16_t *map)
Marc Jonesfb4c7d22017-11-22 22:16:31 -070053{
54 printk(BIOS_DEBUG, "WEAK: %s/%s called\n", __FILE__, __func__);
55 return -1;
56}
57
Marc Jones24484842017-05-04 21:17:45 -060058static struct pci_operations lops_pci = {
59 .set_subsystem = pci_dev_set_subsystem,
60};
61
Marc Jones24484842017-05-04 21:17:45 -060062static struct device_operations usb_ops = {
63 .read_resources = pci_ehci_read_resources,
64 .set_resources = pci_dev_set_resources,
65 .enable_resources = pci_dev_enable_resources,
Marc Jonesfb4c7d22017-11-22 22:16:31 -070066 .init = set_usb_over_current,
Richard Spiegelc661c8e2017-09-11 15:21:14 -070067 .scan_bus = NULL,
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};