Angel Pons | 0612b27 | 2020-04-05 15:46:56 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Subrata Banik | a554b0c | 2017-02-16 16:08:49 +0530 | [diff] [blame] | 2 | |
Furquan Shaikh | 76cedd2 | 2020-05-02 10:24:23 -0700 | [diff] [blame] | 3 | #include <acpi/acpi_device.h> |
Karthikeyan Ramasubramanian | ef0c226 | 2019-06-06 15:35:11 -0600 | [diff] [blame] | 4 | #include <console/console.h> |
Subrata Banik | a554b0c | 2017-02-16 16:08:49 +0530 | [diff] [blame] | 5 | #include <device/device.h> |
| 6 | #include <device/pci.h> |
| 7 | #include <device/pci_ids.h> |
Karthikeyan Ramasubramanian | ef0c226 | 2019-06-06 15:35:11 -0600 | [diff] [blame] | 8 | #include <drivers/usb/acpi/chip.h> |
Duncan Laurie | bf713b0 | 2018-05-07 15:33:18 -0700 | [diff] [blame] | 9 | #include <intelblocks/acpi.h> |
Subrata Banik | a554b0c | 2017-02-16 16:08:49 +0530 | [diff] [blame] | 10 | #include <intelblocks/xhci.h> |
Karthikeyan Ramasubramanian | ef0c226 | 2019-06-06 15:35:11 -0600 | [diff] [blame] | 11 | #include <soc/pci_devs.h> |
| 12 | |
| 13 | #define XHCI_USB2 2 |
| 14 | #define XHCI_USB3 3 |
| 15 | |
| 16 | /* Current Connect Status */ |
| 17 | #define XHCI_STATUS_CCS (1 << 0) |
| 18 | |
| 19 | static bool is_usb_port_connected(const struct xhci_usb_info *info, |
| 20 | unsigned int port_type, unsigned int port_id) |
| 21 | { |
| 22 | uintptr_t port_sts_reg; |
| 23 | uint32_t port_status; |
| 24 | const struct resource *res; |
| 25 | |
| 26 | /* Support only USB2 or USB3 ports */ |
| 27 | if (!(port_type == XHCI_USB2 || port_type == XHCI_USB3)) |
| 28 | return false; |
| 29 | |
| 30 | /* Mark out of bound port id as not connected */ |
| 31 | if ((port_type == XHCI_USB2 && port_id >= info->num_usb2_ports) || |
| 32 | (port_type == XHCI_USB3 && port_id >= info->num_usb3_ports)) |
| 33 | return false; |
| 34 | |
| 35 | /* Calculate port status register address and read the status */ |
Angel Pons | c1bfbe0 | 2021-11-03 13:18:53 +0100 | [diff] [blame] | 36 | res = probe_resource(PCH_DEV_XHCI, PCI_BASE_ADDRESS_0); |
Karthikeyan Ramasubramanian | ef0c226 | 2019-06-06 15:35:11 -0600 | [diff] [blame] | 37 | /* If the memory BAR is not allocated for XHCI, leave the devices enabled */ |
| 38 | if (!res) |
| 39 | return true; |
| 40 | |
| 41 | if (port_type == XHCI_USB2) |
| 42 | port_sts_reg = (uintptr_t)res->base + |
| 43 | info->usb2_port_status_reg + port_id * 0x10; |
| 44 | else |
| 45 | port_sts_reg = (uintptr_t)res->base + |
| 46 | info->usb3_port_status_reg + port_id * 0x10; |
| 47 | port_status = read32((void *)port_sts_reg); |
| 48 | |
| 49 | /* Ensure that the status is not all 1s */ |
| 50 | if (port_status == 0xffffffff) |
| 51 | return false; |
| 52 | |
| 53 | return !!(port_status & XHCI_STATUS_CCS); |
| 54 | } |
| 55 | |
| 56 | void usb_xhci_disable_unused(bool (*ext_usb_xhci_en_cb)(unsigned int port_type, |
| 57 | unsigned int port_id)) |
| 58 | { |
| 59 | struct device *xhci, *hub = NULL, *port = NULL; |
Tim Wawrzynczak | 56fcfb5 | 2020-11-10 13:39:37 -0700 | [diff] [blame] | 60 | const struct xhci_usb_info *info = soc_get_xhci_usb_info(PCH_DEVFN_XHCI); |
Karthikeyan Ramasubramanian | ef0c226 | 2019-06-06 15:35:11 -0600 | [diff] [blame] | 61 | struct drivers_usb_acpi_config *config; |
| 62 | bool enable; |
| 63 | |
| 64 | xhci = pcidev_path_on_root(PCH_DEVFN_XHCI); |
| 65 | if (!xhci) { |
| 66 | printk(BIOS_ERR, "%s: Could not locate XHCI device in DT\n", __func__); |
| 67 | return; |
| 68 | } |
| 69 | |
| 70 | while ((hub = dev_bus_each_child(xhci->link_list, hub)) != NULL) { |
| 71 | while ((port = dev_bus_each_child(hub->link_list, port)) != NULL) { |
| 72 | enable = true; |
| 73 | config = config_of(port); |
| 74 | if (config->type == UPC_TYPE_INTERNAL) { |
| 75 | /* Probe the connect status of internal ports */ |
| 76 | enable = is_usb_port_connected(info, port->path.usb.port_type, |
| 77 | port->path.usb.port_id); |
| 78 | } else if (ext_usb_xhci_en_cb) { |
| 79 | /* Check the mainboard for the status of external ports */ |
| 80 | enable = ext_usb_xhci_en_cb(port->path.usb.port_type, |
| 81 | port->path.usb.port_id); |
| 82 | } |
| 83 | |
| 84 | if (!enable) { |
| 85 | printk(BIOS_INFO, "%s: Disabling USB Type%d Id%d\n", |
| 86 | __func__, port->path.usb.port_type, |
| 87 | port->path.usb.port_id); |
| 88 | port->enabled = 0; |
| 89 | } |
| 90 | } |
| 91 | } |
| 92 | } |
Subrata Banik | a554b0c | 2017-02-16 16:08:49 +0530 | [diff] [blame] | 93 | |
Aaron Durbin | 6403167 | 2018-04-21 14:45:32 -0600 | [diff] [blame] | 94 | __weak void soc_xhci_init(struct device *dev) { /* no-op */ } |
Subrata Banik | a554b0c | 2017-02-16 16:08:49 +0530 | [diff] [blame] | 95 | |
| 96 | static struct device_operations usb_xhci_ops = { |
Elyes HAOUAS | 1d19127 | 2018-11-27 12:23:48 +0100 | [diff] [blame] | 97 | .read_resources = pci_dev_read_resources, |
| 98 | .set_resources = pci_dev_set_resources, |
| 99 | .enable_resources = pci_dev_enable_resources, |
Subrata Banik | a554b0c | 2017-02-16 16:08:49 +0530 | [diff] [blame] | 100 | .init = soc_xhci_init, |
Subrata Banik | 6bbc91a | 2017-12-07 14:55:51 +0530 | [diff] [blame] | 101 | .ops_pci = &pci_dev_ops_pci, |
Nico Huber | a89c82e | 2017-09-14 15:40:28 +0200 | [diff] [blame] | 102 | .scan_bus = scan_static_bus, |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 103 | #if CONFIG(HAVE_ACPI_TABLES) |
Elyes HAOUAS | 1d19127 | 2018-11-27 12:23:48 +0100 | [diff] [blame] | 104 | .acpi_name = soc_acpi_name, |
Subrata Banik | 98376b8 | 2018-05-22 16:18:16 +0530 | [diff] [blame] | 105 | #endif |
Subrata Banik | a554b0c | 2017-02-16 16:08:49 +0530 | [diff] [blame] | 106 | }; |
| 107 | |
| 108 | static const unsigned short pci_device_ids[] = { |
Aaron Durbin | f27d98f | 2017-05-05 16:52:52 -0500 | [diff] [blame] | 109 | PCI_DEVICE_ID_INTEL_APL_XHCI, |
Lijian Zhao | bbedef9 | 2017-07-29 16:38:38 -0700 | [diff] [blame] | 110 | PCI_DEVICE_ID_INTEL_CNL_LP_XHCI, |
Subrata Banik | fc98c01 | 2017-05-03 13:29:19 +0530 | [diff] [blame] | 111 | PCI_DEVICE_ID_INTEL_GLK_XHCI, |
| 112 | PCI_DEVICE_ID_INTEL_SPT_LP_XHCI, |
V Sowmya | 7c15047 | 2018-01-23 14:44:45 +0530 | [diff] [blame] | 113 | PCI_DEVICE_ID_INTEL_SPT_H_XHCI, |
Maxim Polyakov | 571d07d | 2019-08-22 13:11:32 +0300 | [diff] [blame] | 114 | PCI_DEVICE_ID_INTEL_LWB_XHCI, |
| 115 | PCI_DEVICE_ID_INTEL_LWB_XHCI_SUPER, |
Angel Pons | f530e36 | 2021-04-27 10:20:04 +0200 | [diff] [blame] | 116 | PCI_DEVICE_ID_INTEL_UPT_H_XHCI, |
praveen hodagatta pranesh | e26c4a4 | 2018-09-20 03:49:45 +0800 | [diff] [blame] | 117 | PCI_DEVICE_ID_INTEL_CNP_H_XHCI, |
Aamir Bohra | 9eac039 | 2018-06-30 12:07:04 +0530 | [diff] [blame] | 118 | PCI_DEVICE_ID_INTEL_ICP_LP_XHCI, |
Ronak Kanabar | da7ffb48 | 2019-02-05 01:51:13 +0530 | [diff] [blame] | 119 | PCI_DEVICE_ID_INTEL_CMP_LP_XHCI, |
Gaggery Tsai | 12a651c | 2019-12-05 11:23:20 -0800 | [diff] [blame] | 120 | PCI_DEVICE_ID_INTEL_CMP_H_XHCI, |
Ravi Sarawadi | 6b5bf40 | 2019-10-21 22:25:04 -0700 | [diff] [blame] | 121 | PCI_DEVICE_ID_INTEL_TGP_LP_XHCI, |
Jeremy Soller | 191a8d7 | 2021-08-10 14:06:51 -0600 | [diff] [blame] | 122 | PCI_DEVICE_ID_INTEL_TGP_H_XHCI, |
Tan, Lean Sheng | 2613609 | 2020-01-20 19:13:56 -0800 | [diff] [blame] | 123 | PCI_DEVICE_ID_INTEL_MCC_XHCI, |
Meera Ravindranath | 3f4af0d | 2020-02-12 16:01:22 +0530 | [diff] [blame] | 124 | PCI_DEVICE_ID_INTEL_JSP_XHCI, |
Subrata Banik | f672f7f | 2020-08-03 14:29:25 +0530 | [diff] [blame] | 125 | PCI_DEVICE_ID_INTEL_ADP_P_XHCI, |
| 126 | PCI_DEVICE_ID_INTEL_ADP_S_XHCI, |
Varshit Pandya | f4d98fdd2 | 2021-01-17 18:39:29 +0530 | [diff] [blame] | 127 | PCI_DEVICE_ID_INTEL_ADP_M_XHCI, |
Subrata Banik | a554b0c | 2017-02-16 16:08:49 +0530 | [diff] [blame] | 128 | 0 |
| 129 | }; |
| 130 | |
| 131 | static const struct pci_driver pch_usb_xhci __pci_driver = { |
| 132 | .ops = &usb_xhci_ops, |
| 133 | .vendor = PCI_VENDOR_ID_INTEL, |
| 134 | .devices = pci_device_ids, |
| 135 | }; |