1b2be2b05SMika Westerberg // SPDX-License-Identifier: GPL-2.0 2b2be2b05SMika Westerberg /* 3b2be2b05SMika Westerberg * ACPI support 4b2be2b05SMika Westerberg * 5b2be2b05SMika Westerberg * Copyright (C) 2020, Intel Corporation 6b2be2b05SMika Westerberg * Author: Mika Westerberg <mika.westerberg@linux.intel.com> 7b2be2b05SMika Westerberg */ 8b2be2b05SMika Westerberg 9b2be2b05SMika Westerberg #include <linux/acpi.h> 10f3380cacSMika Westerberg #include <linux/pm_runtime.h> 11b2be2b05SMika Westerberg 12b2be2b05SMika Westerberg #include "tb.h" 13b2be2b05SMika Westerberg 14b2be2b05SMika Westerberg static acpi_status tb_acpi_add_link(acpi_handle handle, u32 level, void *data, 15b2be2b05SMika Westerberg void **return_value) 16b2be2b05SMika Westerberg { 177f7b571bSRafael J. Wysocki struct acpi_device *adev = acpi_fetch_acpi_dev(handle); 18b2be2b05SMika Westerberg struct fwnode_reference_args args; 19b2be2b05SMika Westerberg struct fwnode_handle *fwnode; 20b2be2b05SMika Westerberg struct tb_nhi *nhi = data; 21b2be2b05SMika Westerberg struct pci_dev *pdev; 22b2be2b05SMika Westerberg struct device *dev; 23b2be2b05SMika Westerberg int ret; 24b2be2b05SMika Westerberg 257f7b571bSRafael J. Wysocki if (!adev) 26b2be2b05SMika Westerberg return AE_OK; 27b2be2b05SMika Westerberg 28b2be2b05SMika Westerberg fwnode = acpi_fwnode_handle(adev); 29b2be2b05SMika Westerberg ret = fwnode_property_get_reference_args(fwnode, "usb4-host-interface", 30b2be2b05SMika Westerberg NULL, 0, 0, &args); 31b2be2b05SMika Westerberg if (ret) 32b2be2b05SMika Westerberg return AE_OK; 33b2be2b05SMika Westerberg 34b2be2b05SMika Westerberg /* It needs to reference this NHI */ 35fea783e6SAndy Shevchenko if (dev_fwnode(&nhi->pdev->dev) != args.fwnode) 36b2be2b05SMika Westerberg goto out_put; 37b2be2b05SMika Westerberg 38b2be2b05SMika Westerberg /* 39b2be2b05SMika Westerberg * Try to find physical device walking upwards to the hierarcy. 40b2be2b05SMika Westerberg * We need to do this because the xHCI driver might not yet be 41b2be2b05SMika Westerberg * bound so the USB3 SuperSpeed ports are not yet created. 42b2be2b05SMika Westerberg */ 43b2be2b05SMika Westerberg dev = acpi_get_first_physical_node(adev); 44b2be2b05SMika Westerberg while (!dev) { 45b2be2b05SMika Westerberg adev = adev->parent; 46b2be2b05SMika Westerberg if (!adev) 47b2be2b05SMika Westerberg break; 48b2be2b05SMika Westerberg dev = acpi_get_first_physical_node(adev); 49b2be2b05SMika Westerberg } 50b2be2b05SMika Westerberg 51b2be2b05SMika Westerberg if (!dev) 52b2be2b05SMika Westerberg goto out_put; 53b2be2b05SMika Westerberg 54b2be2b05SMika Westerberg /* 55b2be2b05SMika Westerberg * Check that the device is PCIe. This is because USB3 56b2be2b05SMika Westerberg * SuperSpeed ports have this property and they are not power 57b2be2b05SMika Westerberg * managed with the xHCI and the SuperSpeed hub so we create the 58b2be2b05SMika Westerberg * link from xHCI instead. 59b2be2b05SMika Westerberg */ 604d395c5eSMario Limonciello while (dev && !dev_is_pci(dev)) 61b2be2b05SMika Westerberg dev = dev->parent; 62b2be2b05SMika Westerberg 63b2be2b05SMika Westerberg if (!dev) 64b2be2b05SMika Westerberg goto out_put; 65b2be2b05SMika Westerberg 66b2be2b05SMika Westerberg /* 67b2be2b05SMika Westerberg * Check that this actually matches the type of device we 68b2be2b05SMika Westerberg * expect. It should either be xHCI or PCIe root/downstream 69b2be2b05SMika Westerberg * port. 70b2be2b05SMika Westerberg */ 71b2be2b05SMika Westerberg pdev = to_pci_dev(dev); 72b2be2b05SMika Westerberg if (pdev->class == PCI_CLASS_SERIAL_USB_XHCI || 73b2be2b05SMika Westerberg (pci_is_pcie(pdev) && 74b2be2b05SMika Westerberg (pci_pcie_type(pdev) == PCI_EXP_TYPE_ROOT_PORT || 75b2be2b05SMika Westerberg pci_pcie_type(pdev) == PCI_EXP_TYPE_DOWNSTREAM))) { 76b2be2b05SMika Westerberg const struct device_link *link; 77b2be2b05SMika Westerberg 78f3380cacSMika Westerberg /* 79f3380cacSMika Westerberg * Make them both active first to make sure the NHI does 80f3380cacSMika Westerberg * not runtime suspend before the consumer. The 81f3380cacSMika Westerberg * pm_runtime_put() below then allows the consumer to 82f3380cacSMika Westerberg * runtime suspend again (which then allows NHI runtime 83f3380cacSMika Westerberg * suspend too now that the device link is established). 84f3380cacSMika Westerberg */ 85f3380cacSMika Westerberg pm_runtime_get_sync(&pdev->dev); 86f3380cacSMika Westerberg 87b2be2b05SMika Westerberg link = device_link_add(&pdev->dev, &nhi->pdev->dev, 88b2be2b05SMika Westerberg DL_FLAG_AUTOREMOVE_SUPPLIER | 89f3380cacSMika Westerberg DL_FLAG_RPM_ACTIVE | 90b2be2b05SMika Westerberg DL_FLAG_PM_RUNTIME); 91b2be2b05SMika Westerberg if (link) { 92b2be2b05SMika Westerberg dev_dbg(&nhi->pdev->dev, "created link from %s\n", 93b2be2b05SMika Westerberg dev_name(&pdev->dev)); 94b2be2b05SMika Westerberg } else { 95b2be2b05SMika Westerberg dev_warn(&nhi->pdev->dev, "device link creation from %s failed\n", 96b2be2b05SMika Westerberg dev_name(&pdev->dev)); 97b2be2b05SMika Westerberg } 98f3380cacSMika Westerberg 99f3380cacSMika Westerberg pm_runtime_put(&pdev->dev); 100b2be2b05SMika Westerberg } 101b2be2b05SMika Westerberg 102b2be2b05SMika Westerberg out_put: 103b2be2b05SMika Westerberg fwnode_handle_put(args.fwnode); 104b2be2b05SMika Westerberg return AE_OK; 105b2be2b05SMika Westerberg } 106b2be2b05SMika Westerberg 107b2be2b05SMika Westerberg /** 108b2be2b05SMika Westerberg * tb_acpi_add_links() - Add device links based on ACPI description 109b2be2b05SMika Westerberg * @nhi: Pointer to NHI 110b2be2b05SMika Westerberg * 111b2be2b05SMika Westerberg * Goes over ACPI namespace finding tunneled ports that reference to 112b2be2b05SMika Westerberg * @nhi ACPI node. For each reference a device link is added. The link 113b2be2b05SMika Westerberg * is automatically removed by the driver core. 114b2be2b05SMika Westerberg */ 115b2be2b05SMika Westerberg void tb_acpi_add_links(struct tb_nhi *nhi) 116b2be2b05SMika Westerberg { 117b2be2b05SMika Westerberg acpi_status status; 118b2be2b05SMika Westerberg 119b2be2b05SMika Westerberg if (!has_acpi_companion(&nhi->pdev->dev)) 120b2be2b05SMika Westerberg return; 121b2be2b05SMika Westerberg 122b2be2b05SMika Westerberg /* 123b2be2b05SMika Westerberg * Find all devices that have usb4-host-controller interface 124b2be2b05SMika Westerberg * property that references to this NHI. 125b2be2b05SMika Westerberg */ 126b2be2b05SMika Westerberg status = acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT, 32, 127b2be2b05SMika Westerberg tb_acpi_add_link, NULL, nhi, NULL); 128b2be2b05SMika Westerberg if (ACPI_FAILURE(status)) 129b2be2b05SMika Westerberg dev_warn(&nhi->pdev->dev, "failed to enumerate tunneled ports\n"); 130b2be2b05SMika Westerberg } 131c6da62a2SMika Westerberg 132c6da62a2SMika Westerberg /** 133c6da62a2SMika Westerberg * tb_acpi_is_native() - Did the platform grant native TBT/USB4 control 134c6da62a2SMika Westerberg * 135c6da62a2SMika Westerberg * Returns %true if the platform granted OS native control over 136c6da62a2SMika Westerberg * TBT/USB4. In this case software based connection manager can be used, 137c6da62a2SMika Westerberg * otherwise there is firmware based connection manager running. 138c6da62a2SMika Westerberg */ 139c6da62a2SMika Westerberg bool tb_acpi_is_native(void) 140c6da62a2SMika Westerberg { 141c6da62a2SMika Westerberg return osc_sb_native_usb4_support_confirmed && 142c6da62a2SMika Westerberg osc_sb_native_usb4_control; 143c6da62a2SMika Westerberg } 144c6da62a2SMika Westerberg 145c6da62a2SMika Westerberg /** 146c6da62a2SMika Westerberg * tb_acpi_may_tunnel_usb3() - Is USB3 tunneling allowed by the platform 147c6da62a2SMika Westerberg * 148c6da62a2SMika Westerberg * When software based connection manager is used, this function 149c6da62a2SMika Westerberg * returns %true if platform allows native USB3 tunneling. 150c6da62a2SMika Westerberg */ 151c6da62a2SMika Westerberg bool tb_acpi_may_tunnel_usb3(void) 152c6da62a2SMika Westerberg { 153c6da62a2SMika Westerberg if (tb_acpi_is_native()) 154c6da62a2SMika Westerberg return osc_sb_native_usb4_control & OSC_USB_USB3_TUNNELING; 155c6da62a2SMika Westerberg return true; 156c6da62a2SMika Westerberg } 157c6da62a2SMika Westerberg 158c6da62a2SMika Westerberg /** 159c6da62a2SMika Westerberg * tb_acpi_may_tunnel_dp() - Is DisplayPort tunneling allowed by the platform 160c6da62a2SMika Westerberg * 161c6da62a2SMika Westerberg * When software based connection manager is used, this function 162c6da62a2SMika Westerberg * returns %true if platform allows native DP tunneling. 163c6da62a2SMika Westerberg */ 164c6da62a2SMika Westerberg bool tb_acpi_may_tunnel_dp(void) 165c6da62a2SMika Westerberg { 166c6da62a2SMika Westerberg if (tb_acpi_is_native()) 167c6da62a2SMika Westerberg return osc_sb_native_usb4_control & OSC_USB_DP_TUNNELING; 168c6da62a2SMika Westerberg return true; 169c6da62a2SMika Westerberg } 170c6da62a2SMika Westerberg 171c6da62a2SMika Westerberg /** 172c6da62a2SMika Westerberg * tb_acpi_may_tunnel_pcie() - Is PCIe tunneling allowed by the platform 173c6da62a2SMika Westerberg * 174c6da62a2SMika Westerberg * When software based connection manager is used, this function 175c6da62a2SMika Westerberg * returns %true if platform allows native PCIe tunneling. 176c6da62a2SMika Westerberg */ 177c6da62a2SMika Westerberg bool tb_acpi_may_tunnel_pcie(void) 178c6da62a2SMika Westerberg { 179c6da62a2SMika Westerberg if (tb_acpi_is_native()) 180c6da62a2SMika Westerberg return osc_sb_native_usb4_control & OSC_USB_PCIE_TUNNELING; 181c6da62a2SMika Westerberg return true; 182c6da62a2SMika Westerberg } 183c6da62a2SMika Westerberg 184c6da62a2SMika Westerberg /** 185c6da62a2SMika Westerberg * tb_acpi_is_xdomain_allowed() - Are XDomain connections allowed 186c6da62a2SMika Westerberg * 187c6da62a2SMika Westerberg * When software based connection manager is used, this function 188c6da62a2SMika Westerberg * returns %true if platform allows XDomain connections. 189c6da62a2SMika Westerberg */ 190c6da62a2SMika Westerberg bool tb_acpi_is_xdomain_allowed(void) 191c6da62a2SMika Westerberg { 192c6da62a2SMika Westerberg if (tb_acpi_is_native()) 193c6da62a2SMika Westerberg return osc_sb_native_usb4_control & OSC_USB_XDOMAIN; 194c6da62a2SMika Westerberg return true; 195c6da62a2SMika Westerberg } 196ccc5cb8aSRajmohan Mani 197ccc5cb8aSRajmohan Mani /* UUID for retimer _DSM: e0053122-795b-4122-8a5e-57be1d26acb3 */ 198ccc5cb8aSRajmohan Mani static const guid_t retimer_dsm_guid = 199ccc5cb8aSRajmohan Mani GUID_INIT(0xe0053122, 0x795b, 0x4122, 200ccc5cb8aSRajmohan Mani 0x8a, 0x5e, 0x57, 0xbe, 0x1d, 0x26, 0xac, 0xb3); 201ccc5cb8aSRajmohan Mani 202ccc5cb8aSRajmohan Mani #define RETIMER_DSM_QUERY_ONLINE_STATE 1 203ccc5cb8aSRajmohan Mani #define RETIMER_DSM_SET_ONLINE_STATE 2 204ccc5cb8aSRajmohan Mani 205ccc5cb8aSRajmohan Mani static int tb_acpi_retimer_set_power(struct tb_port *port, bool power) 206ccc5cb8aSRajmohan Mani { 207ccc5cb8aSRajmohan Mani struct usb4_port *usb4 = port->usb4; 208ccc5cb8aSRajmohan Mani union acpi_object argv4[2]; 209ccc5cb8aSRajmohan Mani struct acpi_device *adev; 210ccc5cb8aSRajmohan Mani union acpi_object *obj; 211ccc5cb8aSRajmohan Mani int ret; 212ccc5cb8aSRajmohan Mani 213ccc5cb8aSRajmohan Mani if (!usb4->can_offline) 214ccc5cb8aSRajmohan Mani return 0; 215ccc5cb8aSRajmohan Mani 216ccc5cb8aSRajmohan Mani adev = ACPI_COMPANION(&usb4->dev); 217ccc5cb8aSRajmohan Mani if (WARN_ON(!adev)) 218ccc5cb8aSRajmohan Mani return 0; 219ccc5cb8aSRajmohan Mani 220ccc5cb8aSRajmohan Mani /* Check if we are already powered on (and in correct mode) */ 221ccc5cb8aSRajmohan Mani obj = acpi_evaluate_dsm_typed(adev->handle, &retimer_dsm_guid, 1, 222ccc5cb8aSRajmohan Mani RETIMER_DSM_QUERY_ONLINE_STATE, NULL, 223ccc5cb8aSRajmohan Mani ACPI_TYPE_INTEGER); 224ccc5cb8aSRajmohan Mani if (!obj) { 225ccc5cb8aSRajmohan Mani tb_port_warn(port, "ACPI: query online _DSM failed\n"); 226ccc5cb8aSRajmohan Mani return -EIO; 227ccc5cb8aSRajmohan Mani } 228ccc5cb8aSRajmohan Mani 229ccc5cb8aSRajmohan Mani ret = obj->integer.value; 230ccc5cb8aSRajmohan Mani ACPI_FREE(obj); 231ccc5cb8aSRajmohan Mani 232ccc5cb8aSRajmohan Mani if (power == ret) 233ccc5cb8aSRajmohan Mani return 0; 234ccc5cb8aSRajmohan Mani 235ccc5cb8aSRajmohan Mani tb_port_dbg(port, "ACPI: calling _DSM to power %s retimers\n", 236ccc5cb8aSRajmohan Mani power ? "on" : "off"); 237ccc5cb8aSRajmohan Mani 238ccc5cb8aSRajmohan Mani argv4[0].type = ACPI_TYPE_PACKAGE; 239ccc5cb8aSRajmohan Mani argv4[0].package.count = 1; 240ccc5cb8aSRajmohan Mani argv4[0].package.elements = &argv4[1]; 241ccc5cb8aSRajmohan Mani argv4[1].integer.type = ACPI_TYPE_INTEGER; 242ccc5cb8aSRajmohan Mani argv4[1].integer.value = power; 243ccc5cb8aSRajmohan Mani 244ccc5cb8aSRajmohan Mani obj = acpi_evaluate_dsm_typed(adev->handle, &retimer_dsm_guid, 1, 245ccc5cb8aSRajmohan Mani RETIMER_DSM_SET_ONLINE_STATE, argv4, 246ccc5cb8aSRajmohan Mani ACPI_TYPE_INTEGER); 247ccc5cb8aSRajmohan Mani if (!obj) { 248ccc5cb8aSRajmohan Mani tb_port_warn(port, 249ccc5cb8aSRajmohan Mani "ACPI: set online state _DSM evaluation failed\n"); 250ccc5cb8aSRajmohan Mani return -EIO; 251ccc5cb8aSRajmohan Mani } 252ccc5cb8aSRajmohan Mani 253ccc5cb8aSRajmohan Mani ret = obj->integer.value; 254ccc5cb8aSRajmohan Mani ACPI_FREE(obj); 255ccc5cb8aSRajmohan Mani 256ccc5cb8aSRajmohan Mani if (ret >= 0) { 257ccc5cb8aSRajmohan Mani if (power) 258ccc5cb8aSRajmohan Mani return ret == 1 ? 0 : -EBUSY; 259ccc5cb8aSRajmohan Mani return 0; 260ccc5cb8aSRajmohan Mani } 261ccc5cb8aSRajmohan Mani 262ccc5cb8aSRajmohan Mani tb_port_warn(port, "ACPI: set online state _DSM failed with error %d\n", ret); 263ccc5cb8aSRajmohan Mani return -EIO; 264ccc5cb8aSRajmohan Mani } 265ccc5cb8aSRajmohan Mani 266ccc5cb8aSRajmohan Mani /** 267ccc5cb8aSRajmohan Mani * tb_acpi_power_on_retimers() - Call platform to power on retimers 268ccc5cb8aSRajmohan Mani * @port: USB4 port 269ccc5cb8aSRajmohan Mani * 270ccc5cb8aSRajmohan Mani * Calls platform to turn on power to all retimers behind this USB4 271ccc5cb8aSRajmohan Mani * port. After this function returns successfully the caller can 272ccc5cb8aSRajmohan Mani * continue with the normal retimer flows (as specified in the USB4 273ccc5cb8aSRajmohan Mani * spec). Note if this returns %-EBUSY it means the type-C port is in 274ccc5cb8aSRajmohan Mani * non-USB4/TBT mode (there is non-USB4/TBT device connected). 275ccc5cb8aSRajmohan Mani * 276ccc5cb8aSRajmohan Mani * This should only be called if the USB4/TBT link is not up. 277ccc5cb8aSRajmohan Mani * 278ccc5cb8aSRajmohan Mani * Returns %0 on success. 279ccc5cb8aSRajmohan Mani */ 280ccc5cb8aSRajmohan Mani int tb_acpi_power_on_retimers(struct tb_port *port) 281ccc5cb8aSRajmohan Mani { 282ccc5cb8aSRajmohan Mani return tb_acpi_retimer_set_power(port, true); 283ccc5cb8aSRajmohan Mani } 284ccc5cb8aSRajmohan Mani 285ccc5cb8aSRajmohan Mani /** 286ccc5cb8aSRajmohan Mani * tb_acpi_power_off_retimers() - Call platform to power off retimers 287ccc5cb8aSRajmohan Mani * @port: USB4 port 288ccc5cb8aSRajmohan Mani * 289ccc5cb8aSRajmohan Mani * This is the opposite of tb_acpi_power_on_retimers(). After returning 290ccc5cb8aSRajmohan Mani * successfully the normal operations with the @port can continue. 291ccc5cb8aSRajmohan Mani * 292ccc5cb8aSRajmohan Mani * Returns %0 on success. 293ccc5cb8aSRajmohan Mani */ 294ccc5cb8aSRajmohan Mani int tb_acpi_power_off_retimers(struct tb_port *port) 295ccc5cb8aSRajmohan Mani { 296ccc5cb8aSRajmohan Mani return tb_acpi_retimer_set_power(port, false); 297ccc5cb8aSRajmohan Mani } 298ccc5cb8aSRajmohan Mani 299ccc5cb8aSRajmohan Mani static bool tb_acpi_bus_match(struct device *dev) 300ccc5cb8aSRajmohan Mani { 301ccc5cb8aSRajmohan Mani return tb_is_switch(dev) || tb_is_usb4_port_device(dev); 302ccc5cb8aSRajmohan Mani } 303ccc5cb8aSRajmohan Mani 304ccc5cb8aSRajmohan Mani static struct acpi_device *tb_acpi_switch_find_companion(struct tb_switch *sw) 305ccc5cb8aSRajmohan Mani { 306ccc5cb8aSRajmohan Mani struct acpi_device *adev = NULL; 307ccc5cb8aSRajmohan Mani struct tb_switch *parent_sw; 308ccc5cb8aSRajmohan Mani 309*a73a204bSRafael J. Wysocki /* 310*a73a204bSRafael J. Wysocki * Device routers exists under the downstream facing USB4 port 311*a73a204bSRafael J. Wysocki * of the parent router. Their _ADR is always 0. 312*a73a204bSRafael J. Wysocki */ 313ccc5cb8aSRajmohan Mani parent_sw = tb_switch_parent(sw); 314ccc5cb8aSRajmohan Mani if (parent_sw) { 315ccc5cb8aSRajmohan Mani struct tb_port *port = tb_port_at(tb_route(sw), parent_sw); 316ccc5cb8aSRajmohan Mani struct acpi_device *port_adev; 317ccc5cb8aSRajmohan Mani 318*a73a204bSRafael J. Wysocki port_adev = acpi_find_child_by_adr(ACPI_COMPANION(&parent_sw->dev), 319*a73a204bSRafael J. Wysocki port->port); 320ccc5cb8aSRajmohan Mani if (port_adev) 321ccc5cb8aSRajmohan Mani adev = acpi_find_child_device(port_adev, 0, false); 322ccc5cb8aSRajmohan Mani } else { 323ccc5cb8aSRajmohan Mani struct tb_nhi *nhi = sw->tb->nhi; 324ccc5cb8aSRajmohan Mani struct acpi_device *parent_adev; 325ccc5cb8aSRajmohan Mani 326ccc5cb8aSRajmohan Mani parent_adev = ACPI_COMPANION(&nhi->pdev->dev); 327ccc5cb8aSRajmohan Mani if (parent_adev) 328ccc5cb8aSRajmohan Mani adev = acpi_find_child_device(parent_adev, 0, false); 329ccc5cb8aSRajmohan Mani } 330ccc5cb8aSRajmohan Mani 331ccc5cb8aSRajmohan Mani return adev; 332ccc5cb8aSRajmohan Mani } 333ccc5cb8aSRajmohan Mani 334ccc5cb8aSRajmohan Mani static struct acpi_device *tb_acpi_find_companion(struct device *dev) 335ccc5cb8aSRajmohan Mani { 336ccc5cb8aSRajmohan Mani /* 337ccc5cb8aSRajmohan Mani * The Thunderbolt/USB4 hierarchy looks like following: 338ccc5cb8aSRajmohan Mani * 339ccc5cb8aSRajmohan Mani * Device (NHI) 340ccc5cb8aSRajmohan Mani * Device (HR) // Host router _ADR == 0 341ccc5cb8aSRajmohan Mani * Device (DFP0) // Downstream port _ADR == lane 0 adapter 342ccc5cb8aSRajmohan Mani * Device (DR) // Device router _ADR == 0 343ccc5cb8aSRajmohan Mani * Device (UFP) // Upstream port _ADR == lane 0 adapter 344ccc5cb8aSRajmohan Mani * Device (DFP1) // Downstream port _ADR == lane 0 adapter number 345ccc5cb8aSRajmohan Mani * 346ccc5cb8aSRajmohan Mani * At the moment we bind the host router to the corresponding 347ccc5cb8aSRajmohan Mani * Linux device. 348ccc5cb8aSRajmohan Mani */ 349ccc5cb8aSRajmohan Mani if (tb_is_switch(dev)) 350ccc5cb8aSRajmohan Mani return tb_acpi_switch_find_companion(tb_to_switch(dev)); 351ccc5cb8aSRajmohan Mani else if (tb_is_usb4_port_device(dev)) 352*a73a204bSRafael J. Wysocki return acpi_find_child_by_adr(ACPI_COMPANION(dev->parent), 353*a73a204bSRafael J. Wysocki tb_to_usb4_port_device(dev)->port->port); 354ccc5cb8aSRajmohan Mani return NULL; 355ccc5cb8aSRajmohan Mani } 356ccc5cb8aSRajmohan Mani 357ccc5cb8aSRajmohan Mani static void tb_acpi_setup(struct device *dev) 358ccc5cb8aSRajmohan Mani { 359ccc5cb8aSRajmohan Mani struct acpi_device *adev = ACPI_COMPANION(dev); 360ccc5cb8aSRajmohan Mani struct usb4_port *usb4 = tb_to_usb4_port_device(dev); 361ccc5cb8aSRajmohan Mani 362ccc5cb8aSRajmohan Mani if (!adev || !usb4) 363ccc5cb8aSRajmohan Mani return; 364ccc5cb8aSRajmohan Mani 365ccc5cb8aSRajmohan Mani if (acpi_check_dsm(adev->handle, &retimer_dsm_guid, 1, 366ccc5cb8aSRajmohan Mani BIT(RETIMER_DSM_QUERY_ONLINE_STATE) | 367ccc5cb8aSRajmohan Mani BIT(RETIMER_DSM_SET_ONLINE_STATE))) 368ccc5cb8aSRajmohan Mani usb4->can_offline = true; 369ccc5cb8aSRajmohan Mani } 370ccc5cb8aSRajmohan Mani 371ccc5cb8aSRajmohan Mani static struct acpi_bus_type tb_acpi_bus = { 372ccc5cb8aSRajmohan Mani .name = "thunderbolt", 373ccc5cb8aSRajmohan Mani .match = tb_acpi_bus_match, 374ccc5cb8aSRajmohan Mani .find_companion = tb_acpi_find_companion, 375ccc5cb8aSRajmohan Mani .setup = tb_acpi_setup, 376ccc5cb8aSRajmohan Mani }; 377ccc5cb8aSRajmohan Mani 378ccc5cb8aSRajmohan Mani int tb_acpi_init(void) 379ccc5cb8aSRajmohan Mani { 380ccc5cb8aSRajmohan Mani return register_acpi_bus_type(&tb_acpi_bus); 381ccc5cb8aSRajmohan Mani } 382ccc5cb8aSRajmohan Mani 383ccc5cb8aSRajmohan Mani void tb_acpi_exit(void) 384ccc5cb8aSRajmohan Mani { 385ccc5cb8aSRajmohan Mani unregister_acpi_bus_type(&tb_acpi_bus); 386ccc5cb8aSRajmohan Mani } 387