Subrata Banik | a554b0c | 2017-02-16 16:08:49 +0530 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2014 Google Inc. |
praveen hodagatta pranesh | e26c4a4 | 2018-09-20 03:49:45 +0800 | [diff] [blame] | 5 | * Copyright (C) 2015-2018 Intel Corporation. |
Subrata Banik | a554b0c | 2017-02-16 16:08:49 +0530 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; version 2 of the License. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | */ |
| 16 | |
Karthikeyan Ramasubramanian | ef0c226 | 2019-06-06 15:35:11 -0600 | [diff] [blame] | 17 | #include <arch/acpi_device.h> |
| 18 | #include <console/console.h> |
Subrata Banik | a554b0c | 2017-02-16 16:08:49 +0530 | [diff] [blame] | 19 | #include <device/device.h> |
| 20 | #include <device/pci.h> |
| 21 | #include <device/pci_ids.h> |
Karthikeyan Ramasubramanian | ef0c226 | 2019-06-06 15:35:11 -0600 | [diff] [blame] | 22 | #include <drivers/usb/acpi/chip.h> |
Duncan Laurie | bf713b0 | 2018-05-07 15:33:18 -0700 | [diff] [blame] | 23 | #include <intelblocks/acpi.h> |
Subrata Banik | a554b0c | 2017-02-16 16:08:49 +0530 | [diff] [blame] | 24 | #include <intelblocks/xhci.h> |
Karthikeyan Ramasubramanian | ef0c226 | 2019-06-06 15:35:11 -0600 | [diff] [blame] | 25 | #include <soc/pci_devs.h> |
| 26 | |
| 27 | #define XHCI_USB2 2 |
| 28 | #define XHCI_USB3 3 |
| 29 | |
| 30 | /* Current Connect Status */ |
| 31 | #define XHCI_STATUS_CCS (1 << 0) |
| 32 | |
| 33 | static bool is_usb_port_connected(const struct xhci_usb_info *info, |
| 34 | unsigned int port_type, unsigned int port_id) |
| 35 | { |
| 36 | uintptr_t port_sts_reg; |
| 37 | uint32_t port_status; |
| 38 | const struct resource *res; |
| 39 | |
| 40 | /* Support only USB2 or USB3 ports */ |
| 41 | if (!(port_type == XHCI_USB2 || port_type == XHCI_USB3)) |
| 42 | return false; |
| 43 | |
| 44 | /* Mark out of bound port id as not connected */ |
| 45 | if ((port_type == XHCI_USB2 && port_id >= info->num_usb2_ports) || |
| 46 | (port_type == XHCI_USB3 && port_id >= info->num_usb3_ports)) |
| 47 | return false; |
| 48 | |
| 49 | /* Calculate port status register address and read the status */ |
| 50 | res = find_resource(PCH_DEV_XHCI, PCI_BASE_ADDRESS_0); |
| 51 | /* If the memory BAR is not allocated for XHCI, leave the devices enabled */ |
| 52 | if (!res) |
| 53 | return true; |
| 54 | |
| 55 | if (port_type == XHCI_USB2) |
| 56 | port_sts_reg = (uintptr_t)res->base + |
| 57 | info->usb2_port_status_reg + port_id * 0x10; |
| 58 | else |
| 59 | port_sts_reg = (uintptr_t)res->base + |
| 60 | info->usb3_port_status_reg + port_id * 0x10; |
| 61 | port_status = read32((void *)port_sts_reg); |
| 62 | |
| 63 | /* Ensure that the status is not all 1s */ |
| 64 | if (port_status == 0xffffffff) |
| 65 | return false; |
| 66 | |
| 67 | return !!(port_status & XHCI_STATUS_CCS); |
| 68 | } |
| 69 | |
| 70 | void usb_xhci_disable_unused(bool (*ext_usb_xhci_en_cb)(unsigned int port_type, |
| 71 | unsigned int port_id)) |
| 72 | { |
| 73 | struct device *xhci, *hub = NULL, *port = NULL; |
| 74 | const struct xhci_usb_info *info = soc_get_xhci_usb_info(); |
| 75 | struct drivers_usb_acpi_config *config; |
| 76 | bool enable; |
| 77 | |
| 78 | xhci = pcidev_path_on_root(PCH_DEVFN_XHCI); |
| 79 | if (!xhci) { |
| 80 | printk(BIOS_ERR, "%s: Could not locate XHCI device in DT\n", __func__); |
| 81 | return; |
| 82 | } |
| 83 | |
| 84 | while ((hub = dev_bus_each_child(xhci->link_list, hub)) != NULL) { |
| 85 | while ((port = dev_bus_each_child(hub->link_list, port)) != NULL) { |
| 86 | enable = true; |
| 87 | config = config_of(port); |
| 88 | if (config->type == UPC_TYPE_INTERNAL) { |
| 89 | /* Probe the connect status of internal ports */ |
| 90 | enable = is_usb_port_connected(info, port->path.usb.port_type, |
| 91 | port->path.usb.port_id); |
| 92 | } else if (ext_usb_xhci_en_cb) { |
| 93 | /* Check the mainboard for the status of external ports */ |
| 94 | enable = ext_usb_xhci_en_cb(port->path.usb.port_type, |
| 95 | port->path.usb.port_id); |
| 96 | } |
| 97 | |
| 98 | if (!enable) { |
| 99 | printk(BIOS_INFO, "%s: Disabling USB Type%d Id%d\n", |
| 100 | __func__, port->path.usb.port_type, |
| 101 | port->path.usb.port_id); |
| 102 | port->enabled = 0; |
| 103 | } |
| 104 | } |
| 105 | } |
| 106 | } |
Subrata Banik | a554b0c | 2017-02-16 16:08:49 +0530 | [diff] [blame] | 107 | |
Aaron Durbin | 6403167 | 2018-04-21 14:45:32 -0600 | [diff] [blame] | 108 | __weak void soc_xhci_init(struct device *dev) { /* no-op */ } |
Subrata Banik | a554b0c | 2017-02-16 16:08:49 +0530 | [diff] [blame] | 109 | |
| 110 | static struct device_operations usb_xhci_ops = { |
Elyes HAOUAS | 1d19127 | 2018-11-27 12:23:48 +0100 | [diff] [blame] | 111 | .read_resources = pci_dev_read_resources, |
| 112 | .set_resources = pci_dev_set_resources, |
| 113 | .enable_resources = pci_dev_enable_resources, |
Subrata Banik | a554b0c | 2017-02-16 16:08:49 +0530 | [diff] [blame] | 114 | .init = soc_xhci_init, |
Subrata Banik | 6bbc91a | 2017-12-07 14:55:51 +0530 | [diff] [blame] | 115 | .ops_pci = &pci_dev_ops_pci, |
Elyes HAOUAS | 1d19127 | 2018-11-27 12:23:48 +0100 | [diff] [blame] | 116 | .scan_bus = scan_usb_bus, |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 117 | #if CONFIG(HAVE_ACPI_TABLES) |
Elyes HAOUAS | 1d19127 | 2018-11-27 12:23:48 +0100 | [diff] [blame] | 118 | .acpi_name = soc_acpi_name, |
Subrata Banik | 98376b8 | 2018-05-22 16:18:16 +0530 | [diff] [blame] | 119 | #endif |
Subrata Banik | a554b0c | 2017-02-16 16:08:49 +0530 | [diff] [blame] | 120 | }; |
| 121 | |
| 122 | static const unsigned short pci_device_ids[] = { |
Aaron Durbin | f27d98f | 2017-05-05 16:52:52 -0500 | [diff] [blame] | 123 | PCI_DEVICE_ID_INTEL_APL_XHCI, |
Lijian Zhao | bbedef9 | 2017-07-29 16:38:38 -0700 | [diff] [blame] | 124 | PCI_DEVICE_ID_INTEL_CNL_LP_XHCI, |
Subrata Banik | fc98c01 | 2017-05-03 13:29:19 +0530 | [diff] [blame] | 125 | PCI_DEVICE_ID_INTEL_GLK_XHCI, |
| 126 | PCI_DEVICE_ID_INTEL_SPT_LP_XHCI, |
V Sowmya | 7c15047 | 2018-01-23 14:44:45 +0530 | [diff] [blame] | 127 | PCI_DEVICE_ID_INTEL_SPT_H_XHCI, |
Maxim Polyakov | 571d07d | 2019-08-22 13:11:32 +0300 | [diff] [blame] | 128 | PCI_DEVICE_ID_INTEL_LWB_XHCI, |
| 129 | PCI_DEVICE_ID_INTEL_LWB_XHCI_SUPER, |
V Sowmya | acc2a48 | 2018-01-23 15:27:23 +0530 | [diff] [blame] | 130 | PCI_DEVICE_ID_INTEL_KBP_H_XHCI, |
praveen hodagatta pranesh | e26c4a4 | 2018-09-20 03:49:45 +0800 | [diff] [blame] | 131 | PCI_DEVICE_ID_INTEL_CNP_H_XHCI, |
Aamir Bohra | 9eac039 | 2018-06-30 12:07:04 +0530 | [diff] [blame] | 132 | PCI_DEVICE_ID_INTEL_ICP_LP_XHCI, |
Ronak Kanabar | da7ffb48 | 2019-02-05 01:51:13 +0530 | [diff] [blame] | 133 | PCI_DEVICE_ID_INTEL_CMP_LP_XHCI, |
Subrata Banik | a554b0c | 2017-02-16 16:08:49 +0530 | [diff] [blame] | 134 | 0 |
| 135 | }; |
| 136 | |
| 137 | static const struct pci_driver pch_usb_xhci __pci_driver = { |
| 138 | .ops = &usb_xhci_ops, |
| 139 | .vendor = PCI_VENDOR_ID_INTEL, |
| 140 | .devices = pci_device_ids, |
| 141 | }; |