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, 15*408e1d96SMika Westerberg void **ret) 16b2be2b05SMika Westerberg { 177f7b571bSRafael J. Wysocki struct acpi_device *adev = acpi_fetch_acpi_dev(handle); 18b2be2b05SMika Westerberg struct fwnode_handle *fwnode; 19b2be2b05SMika Westerberg struct tb_nhi *nhi = data; 20b2be2b05SMika Westerberg struct pci_dev *pdev; 21b2be2b05SMika Westerberg struct device *dev; 22b2be2b05SMika Westerberg 237f7b571bSRafael J. Wysocki if (!adev) 24b2be2b05SMika Westerberg return AE_OK; 25b2be2b05SMika Westerberg 262ae18cc2SHeikki Krogerus fwnode = fwnode_find_reference(acpi_fwnode_handle(adev), "usb4-host-interface", 0); 272ae18cc2SHeikki Krogerus if (IS_ERR(fwnode)) 28b2be2b05SMika Westerberg return AE_OK; 29b2be2b05SMika Westerberg 30b2be2b05SMika Westerberg /* It needs to reference this NHI */ 312ae18cc2SHeikki Krogerus if (dev_fwnode(&nhi->pdev->dev) != fwnode) 32b2be2b05SMika Westerberg goto out_put; 33b2be2b05SMika Westerberg 34b2be2b05SMika Westerberg /* 35b2be2b05SMika Westerberg * Try to find physical device walking upwards to the hierarcy. 36b2be2b05SMika Westerberg * We need to do this because the xHCI driver might not yet be 37b2be2b05SMika Westerberg * bound so the USB3 SuperSpeed ports are not yet created. 38b2be2b05SMika Westerberg */ 39953ff25fSAndy Shevchenko do { 40b2be2b05SMika Westerberg dev = acpi_get_first_physical_node(adev); 41953ff25fSAndy Shevchenko if (dev) 42b2be2b05SMika Westerberg break; 43b2be2b05SMika Westerberg 44953ff25fSAndy Shevchenko adev = acpi_dev_parent(adev); 45953ff25fSAndy Shevchenko } while (adev); 46b2be2b05SMika Westerberg 47b2be2b05SMika Westerberg /* 48b2be2b05SMika Westerberg * Check that the device is PCIe. This is because USB3 49b2be2b05SMika Westerberg * SuperSpeed ports have this property and they are not power 50b2be2b05SMika Westerberg * managed with the xHCI and the SuperSpeed hub so we create the 51b2be2b05SMika Westerberg * link from xHCI instead. 52b2be2b05SMika Westerberg */ 534d395c5eSMario Limonciello while (dev && !dev_is_pci(dev)) 54b2be2b05SMika Westerberg dev = dev->parent; 55b2be2b05SMika Westerberg 56b2be2b05SMika Westerberg if (!dev) 57b2be2b05SMika Westerberg goto out_put; 58b2be2b05SMika Westerberg 59b2be2b05SMika Westerberg /* 60b2be2b05SMika Westerberg * Check that this actually matches the type of device we 61b2be2b05SMika Westerberg * expect. It should either be xHCI or PCIe root/downstream 62b2be2b05SMika Westerberg * port. 63b2be2b05SMika Westerberg */ 64b2be2b05SMika Westerberg pdev = to_pci_dev(dev); 65b2be2b05SMika Westerberg if (pdev->class == PCI_CLASS_SERIAL_USB_XHCI || 66b2be2b05SMika Westerberg (pci_is_pcie(pdev) && 67b2be2b05SMika Westerberg (pci_pcie_type(pdev) == PCI_EXP_TYPE_ROOT_PORT || 68b2be2b05SMika Westerberg pci_pcie_type(pdev) == PCI_EXP_TYPE_DOWNSTREAM))) { 69b2be2b05SMika Westerberg const struct device_link *link; 70b2be2b05SMika Westerberg 71f3380cacSMika Westerberg /* 72f3380cacSMika Westerberg * Make them both active first to make sure the NHI does 73f3380cacSMika Westerberg * not runtime suspend before the consumer. The 74f3380cacSMika Westerberg * pm_runtime_put() below then allows the consumer to 75f3380cacSMika Westerberg * runtime suspend again (which then allows NHI runtime 76f3380cacSMika Westerberg * suspend too now that the device link is established). 77f3380cacSMika Westerberg */ 78f3380cacSMika Westerberg pm_runtime_get_sync(&pdev->dev); 79f3380cacSMika Westerberg 80b2be2b05SMika Westerberg link = device_link_add(&pdev->dev, &nhi->pdev->dev, 81b2be2b05SMika Westerberg DL_FLAG_AUTOREMOVE_SUPPLIER | 82f3380cacSMika Westerberg DL_FLAG_RPM_ACTIVE | 83b2be2b05SMika Westerberg DL_FLAG_PM_RUNTIME); 84b2be2b05SMika Westerberg if (link) { 85b2be2b05SMika Westerberg dev_dbg(&nhi->pdev->dev, "created link from %s\n", 86b2be2b05SMika Westerberg dev_name(&pdev->dev)); 87*408e1d96SMika Westerberg *(bool *)ret = true; 88b2be2b05SMika Westerberg } else { 89b2be2b05SMika Westerberg dev_warn(&nhi->pdev->dev, "device link creation from %s failed\n", 90b2be2b05SMika Westerberg dev_name(&pdev->dev)); 91b2be2b05SMika Westerberg } 92f3380cacSMika Westerberg 93f3380cacSMika Westerberg pm_runtime_put(&pdev->dev); 94b2be2b05SMika Westerberg } 95b2be2b05SMika Westerberg 96b2be2b05SMika Westerberg out_put: 972ae18cc2SHeikki Krogerus fwnode_handle_put(fwnode); 98b2be2b05SMika Westerberg return AE_OK; 99b2be2b05SMika Westerberg } 100b2be2b05SMika Westerberg 101b2be2b05SMika Westerberg /** 102b2be2b05SMika Westerberg * tb_acpi_add_links() - Add device links based on ACPI description 103b2be2b05SMika Westerberg * @nhi: Pointer to NHI 104b2be2b05SMika Westerberg * 105b2be2b05SMika Westerberg * Goes over ACPI namespace finding tunneled ports that reference to 106b2be2b05SMika Westerberg * @nhi ACPI node. For each reference a device link is added. The link 107b2be2b05SMika Westerberg * is automatically removed by the driver core. 108*408e1d96SMika Westerberg * 109*408e1d96SMika Westerberg * Returns %true if at least one link was created. 110b2be2b05SMika Westerberg */ 111*408e1d96SMika Westerberg bool tb_acpi_add_links(struct tb_nhi *nhi) 112b2be2b05SMika Westerberg { 113b2be2b05SMika Westerberg acpi_status status; 114*408e1d96SMika Westerberg bool ret = false; 115b2be2b05SMika Westerberg 116b2be2b05SMika Westerberg if (!has_acpi_companion(&nhi->pdev->dev)) 117*408e1d96SMika Westerberg return false; 118b2be2b05SMika Westerberg 119b2be2b05SMika Westerberg /* 120b2be2b05SMika Westerberg * Find all devices that have usb4-host-controller interface 121b2be2b05SMika Westerberg * property that references to this NHI. 122b2be2b05SMika Westerberg */ 123b2be2b05SMika Westerberg status = acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT, 32, 124*408e1d96SMika Westerberg tb_acpi_add_link, NULL, nhi, (void **)&ret); 125*408e1d96SMika Westerberg if (ACPI_FAILURE(status)) { 126b2be2b05SMika Westerberg dev_warn(&nhi->pdev->dev, "failed to enumerate tunneled ports\n"); 127*408e1d96SMika Westerberg return false; 128*408e1d96SMika Westerberg } 129*408e1d96SMika Westerberg 130*408e1d96SMika Westerberg return ret; 131b2be2b05SMika Westerberg } 132c6da62a2SMika Westerberg 133c6da62a2SMika Westerberg /** 134c6da62a2SMika Westerberg * tb_acpi_is_native() - Did the platform grant native TBT/USB4 control 135c6da62a2SMika Westerberg * 136c6da62a2SMika Westerberg * Returns %true if the platform granted OS native control over 137c6da62a2SMika Westerberg * TBT/USB4. In this case software based connection manager can be used, 138c6da62a2SMika Westerberg * otherwise there is firmware based connection manager running. 139c6da62a2SMika Westerberg */ 140c6da62a2SMika Westerberg bool tb_acpi_is_native(void) 141c6da62a2SMika Westerberg { 142c6da62a2SMika Westerberg return osc_sb_native_usb4_support_confirmed && 143c6da62a2SMika Westerberg osc_sb_native_usb4_control; 144c6da62a2SMika Westerberg } 145c6da62a2SMika Westerberg 146c6da62a2SMika Westerberg /** 147c6da62a2SMika Westerberg * tb_acpi_may_tunnel_usb3() - Is USB3 tunneling allowed by the platform 148c6da62a2SMika Westerberg * 149c6da62a2SMika Westerberg * When software based connection manager is used, this function 150c6da62a2SMika Westerberg * returns %true if platform allows native USB3 tunneling. 151c6da62a2SMika Westerberg */ 152c6da62a2SMika Westerberg bool tb_acpi_may_tunnel_usb3(void) 153c6da62a2SMika Westerberg { 154c6da62a2SMika Westerberg if (tb_acpi_is_native()) 155c6da62a2SMika Westerberg return osc_sb_native_usb4_control & OSC_USB_USB3_TUNNELING; 156c6da62a2SMika Westerberg return true; 157c6da62a2SMika Westerberg } 158c6da62a2SMika Westerberg 159c6da62a2SMika Westerberg /** 160c6da62a2SMika Westerberg * tb_acpi_may_tunnel_dp() - Is DisplayPort tunneling allowed by the platform 161c6da62a2SMika Westerberg * 162c6da62a2SMika Westerberg * When software based connection manager is used, this function 163c6da62a2SMika Westerberg * returns %true if platform allows native DP tunneling. 164c6da62a2SMika Westerberg */ 165c6da62a2SMika Westerberg bool tb_acpi_may_tunnel_dp(void) 166c6da62a2SMika Westerberg { 167c6da62a2SMika Westerberg if (tb_acpi_is_native()) 168c6da62a2SMika Westerberg return osc_sb_native_usb4_control & OSC_USB_DP_TUNNELING; 169c6da62a2SMika Westerberg return true; 170c6da62a2SMika Westerberg } 171c6da62a2SMika Westerberg 172c6da62a2SMika Westerberg /** 173c6da62a2SMika Westerberg * tb_acpi_may_tunnel_pcie() - Is PCIe tunneling allowed by the platform 174c6da62a2SMika Westerberg * 175c6da62a2SMika Westerberg * When software based connection manager is used, this function 176c6da62a2SMika Westerberg * returns %true if platform allows native PCIe tunneling. 177c6da62a2SMika Westerberg */ 178c6da62a2SMika Westerberg bool tb_acpi_may_tunnel_pcie(void) 179c6da62a2SMika Westerberg { 180c6da62a2SMika Westerberg if (tb_acpi_is_native()) 181c6da62a2SMika Westerberg return osc_sb_native_usb4_control & OSC_USB_PCIE_TUNNELING; 182c6da62a2SMika Westerberg return true; 183c6da62a2SMika Westerberg } 184c6da62a2SMika Westerberg 185c6da62a2SMika Westerberg /** 186c6da62a2SMika Westerberg * tb_acpi_is_xdomain_allowed() - Are XDomain connections allowed 187c6da62a2SMika Westerberg * 188c6da62a2SMika Westerberg * When software based connection manager is used, this function 189c6da62a2SMika Westerberg * returns %true if platform allows XDomain connections. 190c6da62a2SMika Westerberg */ 191c6da62a2SMika Westerberg bool tb_acpi_is_xdomain_allowed(void) 192c6da62a2SMika Westerberg { 193c6da62a2SMika Westerberg if (tb_acpi_is_native()) 194c6da62a2SMika Westerberg return osc_sb_native_usb4_control & OSC_USB_XDOMAIN; 195c6da62a2SMika Westerberg return true; 196c6da62a2SMika Westerberg } 197ccc5cb8aSRajmohan Mani 198ccc5cb8aSRajmohan Mani /* UUID for retimer _DSM: e0053122-795b-4122-8a5e-57be1d26acb3 */ 199ccc5cb8aSRajmohan Mani static const guid_t retimer_dsm_guid = 200ccc5cb8aSRajmohan Mani GUID_INIT(0xe0053122, 0x795b, 0x4122, 201ccc5cb8aSRajmohan Mani 0x8a, 0x5e, 0x57, 0xbe, 0x1d, 0x26, 0xac, 0xb3); 202ccc5cb8aSRajmohan Mani 203ccc5cb8aSRajmohan Mani #define RETIMER_DSM_QUERY_ONLINE_STATE 1 204ccc5cb8aSRajmohan Mani #define RETIMER_DSM_SET_ONLINE_STATE 2 205ccc5cb8aSRajmohan Mani 206ccc5cb8aSRajmohan Mani static int tb_acpi_retimer_set_power(struct tb_port *port, bool power) 207ccc5cb8aSRajmohan Mani { 208ccc5cb8aSRajmohan Mani struct usb4_port *usb4 = port->usb4; 209ccc5cb8aSRajmohan Mani union acpi_object argv4[2]; 210ccc5cb8aSRajmohan Mani struct acpi_device *adev; 211ccc5cb8aSRajmohan Mani union acpi_object *obj; 212ccc5cb8aSRajmohan Mani int ret; 213ccc5cb8aSRajmohan Mani 214ccc5cb8aSRajmohan Mani if (!usb4->can_offline) 215ccc5cb8aSRajmohan Mani return 0; 216ccc5cb8aSRajmohan Mani 217ccc5cb8aSRajmohan Mani adev = ACPI_COMPANION(&usb4->dev); 218ccc5cb8aSRajmohan Mani if (WARN_ON(!adev)) 219ccc5cb8aSRajmohan Mani return 0; 220ccc5cb8aSRajmohan Mani 221ccc5cb8aSRajmohan Mani /* Check if we are already powered on (and in correct mode) */ 222ccc5cb8aSRajmohan Mani obj = acpi_evaluate_dsm_typed(adev->handle, &retimer_dsm_guid, 1, 223ccc5cb8aSRajmohan Mani RETIMER_DSM_QUERY_ONLINE_STATE, NULL, 224ccc5cb8aSRajmohan Mani ACPI_TYPE_INTEGER); 225ccc5cb8aSRajmohan Mani if (!obj) { 226ccc5cb8aSRajmohan Mani tb_port_warn(port, "ACPI: query online _DSM failed\n"); 227ccc5cb8aSRajmohan Mani return -EIO; 228ccc5cb8aSRajmohan Mani } 229ccc5cb8aSRajmohan Mani 230ccc5cb8aSRajmohan Mani ret = obj->integer.value; 231ccc5cb8aSRajmohan Mani ACPI_FREE(obj); 232ccc5cb8aSRajmohan Mani 233ccc5cb8aSRajmohan Mani if (power == ret) 234ccc5cb8aSRajmohan Mani return 0; 235ccc5cb8aSRajmohan Mani 236ccc5cb8aSRajmohan Mani tb_port_dbg(port, "ACPI: calling _DSM to power %s retimers\n", 237ccc5cb8aSRajmohan Mani power ? "on" : "off"); 238ccc5cb8aSRajmohan Mani 239ccc5cb8aSRajmohan Mani argv4[0].type = ACPI_TYPE_PACKAGE; 240ccc5cb8aSRajmohan Mani argv4[0].package.count = 1; 241ccc5cb8aSRajmohan Mani argv4[0].package.elements = &argv4[1]; 242ccc5cb8aSRajmohan Mani argv4[1].integer.type = ACPI_TYPE_INTEGER; 243ccc5cb8aSRajmohan Mani argv4[1].integer.value = power; 244ccc5cb8aSRajmohan Mani 245ccc5cb8aSRajmohan Mani obj = acpi_evaluate_dsm_typed(adev->handle, &retimer_dsm_guid, 1, 246ccc5cb8aSRajmohan Mani RETIMER_DSM_SET_ONLINE_STATE, argv4, 247ccc5cb8aSRajmohan Mani ACPI_TYPE_INTEGER); 248ccc5cb8aSRajmohan Mani if (!obj) { 249ccc5cb8aSRajmohan Mani tb_port_warn(port, 250ccc5cb8aSRajmohan Mani "ACPI: set online state _DSM evaluation failed\n"); 251ccc5cb8aSRajmohan Mani return -EIO; 252ccc5cb8aSRajmohan Mani } 253ccc5cb8aSRajmohan Mani 254ccc5cb8aSRajmohan Mani ret = obj->integer.value; 255ccc5cb8aSRajmohan Mani ACPI_FREE(obj); 256ccc5cb8aSRajmohan Mani 257ccc5cb8aSRajmohan Mani if (ret >= 0) { 258ccc5cb8aSRajmohan Mani if (power) 259ccc5cb8aSRajmohan Mani return ret == 1 ? 0 : -EBUSY; 260ccc5cb8aSRajmohan Mani return 0; 261ccc5cb8aSRajmohan Mani } 262ccc5cb8aSRajmohan Mani 263ccc5cb8aSRajmohan Mani tb_port_warn(port, "ACPI: set online state _DSM failed with error %d\n", ret); 264ccc5cb8aSRajmohan Mani return -EIO; 265ccc5cb8aSRajmohan Mani } 266ccc5cb8aSRajmohan Mani 267ccc5cb8aSRajmohan Mani /** 268ccc5cb8aSRajmohan Mani * tb_acpi_power_on_retimers() - Call platform to power on retimers 269ccc5cb8aSRajmohan Mani * @port: USB4 port 270ccc5cb8aSRajmohan Mani * 271ccc5cb8aSRajmohan Mani * Calls platform to turn on power to all retimers behind this USB4 272ccc5cb8aSRajmohan Mani * port. After this function returns successfully the caller can 273ccc5cb8aSRajmohan Mani * continue with the normal retimer flows (as specified in the USB4 274ccc5cb8aSRajmohan Mani * spec). Note if this returns %-EBUSY it means the type-C port is in 275ccc5cb8aSRajmohan Mani * non-USB4/TBT mode (there is non-USB4/TBT device connected). 276ccc5cb8aSRajmohan Mani * 277ccc5cb8aSRajmohan Mani * This should only be called if the USB4/TBT link is not up. 278ccc5cb8aSRajmohan Mani * 279ccc5cb8aSRajmohan Mani * Returns %0 on success. 280ccc5cb8aSRajmohan Mani */ 281ccc5cb8aSRajmohan Mani int tb_acpi_power_on_retimers(struct tb_port *port) 282ccc5cb8aSRajmohan Mani { 283ccc5cb8aSRajmohan Mani return tb_acpi_retimer_set_power(port, true); 284ccc5cb8aSRajmohan Mani } 285ccc5cb8aSRajmohan Mani 286ccc5cb8aSRajmohan Mani /** 287ccc5cb8aSRajmohan Mani * tb_acpi_power_off_retimers() - Call platform to power off retimers 288ccc5cb8aSRajmohan Mani * @port: USB4 port 289ccc5cb8aSRajmohan Mani * 290ccc5cb8aSRajmohan Mani * This is the opposite of tb_acpi_power_on_retimers(). After returning 291ccc5cb8aSRajmohan Mani * successfully the normal operations with the @port can continue. 292ccc5cb8aSRajmohan Mani * 293ccc5cb8aSRajmohan Mani * Returns %0 on success. 294ccc5cb8aSRajmohan Mani */ 295ccc5cb8aSRajmohan Mani int tb_acpi_power_off_retimers(struct tb_port *port) 296ccc5cb8aSRajmohan Mani { 297ccc5cb8aSRajmohan Mani return tb_acpi_retimer_set_power(port, false); 298ccc5cb8aSRajmohan Mani } 299ccc5cb8aSRajmohan Mani 300ccc5cb8aSRajmohan Mani static bool tb_acpi_bus_match(struct device *dev) 301ccc5cb8aSRajmohan Mani { 302ccc5cb8aSRajmohan Mani return tb_is_switch(dev) || tb_is_usb4_port_device(dev); 303ccc5cb8aSRajmohan Mani } 304ccc5cb8aSRajmohan Mani 305ccc5cb8aSRajmohan Mani static struct acpi_device *tb_acpi_switch_find_companion(struct tb_switch *sw) 306ccc5cb8aSRajmohan Mani { 3077ce54221SGil Fine struct tb_switch *parent_sw = tb_switch_parent(sw); 308ccc5cb8aSRajmohan Mani struct acpi_device *adev = NULL; 309ccc5cb8aSRajmohan Mani 310a73a204bSRafael J. Wysocki /* 311a73a204bSRafael J. Wysocki * Device routers exists under the downstream facing USB4 port 312a73a204bSRafael J. Wysocki * of the parent router. Their _ADR is always 0. 313a73a204bSRafael J. Wysocki */ 314ccc5cb8aSRajmohan Mani if (parent_sw) { 3157ce54221SGil Fine struct tb_port *port = tb_switch_downstream_port(sw); 316ccc5cb8aSRajmohan Mani struct acpi_device *port_adev; 317ccc5cb8aSRajmohan Mani 318a73a204bSRafael J. Wysocki port_adev = acpi_find_child_by_adr(ACPI_COMPANION(&parent_sw->dev), 319a73a204bSRafael 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)); 3514e99c98eSAndy Shevchenko if (tb_is_usb4_port_device(dev)) 352a73a204bSRafael J. Wysocki return acpi_find_child_by_adr(ACPI_COMPANION(dev->parent), 353a73a204bSRafael 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