xref: /openbmc/linux/drivers/thunderbolt/acpi.c (revision 7ce542219b6323764cb922722b677005404d9b60)
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_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));
87b2be2b05SMika Westerberg 		} else {
88b2be2b05SMika Westerberg 			dev_warn(&nhi->pdev->dev, "device link creation from %s failed\n",
89b2be2b05SMika Westerberg 				 dev_name(&pdev->dev));
90b2be2b05SMika Westerberg 		}
91f3380cacSMika Westerberg 
92f3380cacSMika Westerberg 		pm_runtime_put(&pdev->dev);
93b2be2b05SMika Westerberg 	}
94b2be2b05SMika Westerberg 
95b2be2b05SMika Westerberg out_put:
962ae18cc2SHeikki Krogerus 	fwnode_handle_put(fwnode);
97b2be2b05SMika Westerberg 	return AE_OK;
98b2be2b05SMika Westerberg }
99b2be2b05SMika Westerberg 
100b2be2b05SMika Westerberg /**
101b2be2b05SMika Westerberg  * tb_acpi_add_links() - Add device links based on ACPI description
102b2be2b05SMika Westerberg  * @nhi: Pointer to NHI
103b2be2b05SMika Westerberg  *
104b2be2b05SMika Westerberg  * Goes over ACPI namespace finding tunneled ports that reference to
105b2be2b05SMika Westerberg  * @nhi ACPI node. For each reference a device link is added. The link
106b2be2b05SMika Westerberg  * is automatically removed by the driver core.
107b2be2b05SMika Westerberg  */
108b2be2b05SMika Westerberg void tb_acpi_add_links(struct tb_nhi *nhi)
109b2be2b05SMika Westerberg {
110b2be2b05SMika Westerberg 	acpi_status status;
111b2be2b05SMika Westerberg 
112b2be2b05SMika Westerberg 	if (!has_acpi_companion(&nhi->pdev->dev))
113b2be2b05SMika Westerberg 		return;
114b2be2b05SMika Westerberg 
115b2be2b05SMika Westerberg 	/*
116b2be2b05SMika Westerberg 	 * Find all devices that have usb4-host-controller interface
117b2be2b05SMika Westerberg 	 * property that references to this NHI.
118b2be2b05SMika Westerberg 	 */
119b2be2b05SMika Westerberg 	status = acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT, 32,
120b2be2b05SMika Westerberg 				     tb_acpi_add_link, NULL, nhi, NULL);
121b2be2b05SMika Westerberg 	if (ACPI_FAILURE(status))
122b2be2b05SMika Westerberg 		dev_warn(&nhi->pdev->dev, "failed to enumerate tunneled ports\n");
123b2be2b05SMika Westerberg }
124c6da62a2SMika Westerberg 
125c6da62a2SMika Westerberg /**
126c6da62a2SMika Westerberg  * tb_acpi_is_native() - Did the platform grant native TBT/USB4 control
127c6da62a2SMika Westerberg  *
128c6da62a2SMika Westerberg  * Returns %true if the platform granted OS native control over
129c6da62a2SMika Westerberg  * TBT/USB4. In this case software based connection manager can be used,
130c6da62a2SMika Westerberg  * otherwise there is firmware based connection manager running.
131c6da62a2SMika Westerberg  */
132c6da62a2SMika Westerberg bool tb_acpi_is_native(void)
133c6da62a2SMika Westerberg {
134c6da62a2SMika Westerberg 	return osc_sb_native_usb4_support_confirmed &&
135c6da62a2SMika Westerberg 	       osc_sb_native_usb4_control;
136c6da62a2SMika Westerberg }
137c6da62a2SMika Westerberg 
138c6da62a2SMika Westerberg /**
139c6da62a2SMika Westerberg  * tb_acpi_may_tunnel_usb3() - Is USB3 tunneling allowed by the platform
140c6da62a2SMika Westerberg  *
141c6da62a2SMika Westerberg  * When software based connection manager is used, this function
142c6da62a2SMika Westerberg  * returns %true if platform allows native USB3 tunneling.
143c6da62a2SMika Westerberg  */
144c6da62a2SMika Westerberg bool tb_acpi_may_tunnel_usb3(void)
145c6da62a2SMika Westerberg {
146c6da62a2SMika Westerberg 	if (tb_acpi_is_native())
147c6da62a2SMika Westerberg 		return osc_sb_native_usb4_control & OSC_USB_USB3_TUNNELING;
148c6da62a2SMika Westerberg 	return true;
149c6da62a2SMika Westerberg }
150c6da62a2SMika Westerberg 
151c6da62a2SMika Westerberg /**
152c6da62a2SMika Westerberg  * tb_acpi_may_tunnel_dp() - Is DisplayPort tunneling allowed by the platform
153c6da62a2SMika Westerberg  *
154c6da62a2SMika Westerberg  * When software based connection manager is used, this function
155c6da62a2SMika Westerberg  * returns %true if platform allows native DP tunneling.
156c6da62a2SMika Westerberg  */
157c6da62a2SMika Westerberg bool tb_acpi_may_tunnel_dp(void)
158c6da62a2SMika Westerberg {
159c6da62a2SMika Westerberg 	if (tb_acpi_is_native())
160c6da62a2SMika Westerberg 		return osc_sb_native_usb4_control & OSC_USB_DP_TUNNELING;
161c6da62a2SMika Westerberg 	return true;
162c6da62a2SMika Westerberg }
163c6da62a2SMika Westerberg 
164c6da62a2SMika Westerberg /**
165c6da62a2SMika Westerberg  * tb_acpi_may_tunnel_pcie() - Is PCIe tunneling allowed by the platform
166c6da62a2SMika Westerberg  *
167c6da62a2SMika Westerberg  * When software based connection manager is used, this function
168c6da62a2SMika Westerberg  * returns %true if platform allows native PCIe tunneling.
169c6da62a2SMika Westerberg  */
170c6da62a2SMika Westerberg bool tb_acpi_may_tunnel_pcie(void)
171c6da62a2SMika Westerberg {
172c6da62a2SMika Westerberg 	if (tb_acpi_is_native())
173c6da62a2SMika Westerberg 		return osc_sb_native_usb4_control & OSC_USB_PCIE_TUNNELING;
174c6da62a2SMika Westerberg 	return true;
175c6da62a2SMika Westerberg }
176c6da62a2SMika Westerberg 
177c6da62a2SMika Westerberg /**
178c6da62a2SMika Westerberg  * tb_acpi_is_xdomain_allowed() - Are XDomain connections allowed
179c6da62a2SMika Westerberg  *
180c6da62a2SMika Westerberg  * When software based connection manager is used, this function
181c6da62a2SMika Westerberg  * returns %true if platform allows XDomain connections.
182c6da62a2SMika Westerberg  */
183c6da62a2SMika Westerberg bool tb_acpi_is_xdomain_allowed(void)
184c6da62a2SMika Westerberg {
185c6da62a2SMika Westerberg 	if (tb_acpi_is_native())
186c6da62a2SMika Westerberg 		return osc_sb_native_usb4_control & OSC_USB_XDOMAIN;
187c6da62a2SMika Westerberg 	return true;
188c6da62a2SMika Westerberg }
189ccc5cb8aSRajmohan Mani 
190ccc5cb8aSRajmohan Mani /* UUID for retimer _DSM: e0053122-795b-4122-8a5e-57be1d26acb3 */
191ccc5cb8aSRajmohan Mani static const guid_t retimer_dsm_guid =
192ccc5cb8aSRajmohan Mani 	GUID_INIT(0xe0053122, 0x795b, 0x4122,
193ccc5cb8aSRajmohan Mani 		  0x8a, 0x5e, 0x57, 0xbe, 0x1d, 0x26, 0xac, 0xb3);
194ccc5cb8aSRajmohan Mani 
195ccc5cb8aSRajmohan Mani #define RETIMER_DSM_QUERY_ONLINE_STATE	1
196ccc5cb8aSRajmohan Mani #define RETIMER_DSM_SET_ONLINE_STATE	2
197ccc5cb8aSRajmohan Mani 
198ccc5cb8aSRajmohan Mani static int tb_acpi_retimer_set_power(struct tb_port *port, bool power)
199ccc5cb8aSRajmohan Mani {
200ccc5cb8aSRajmohan Mani 	struct usb4_port *usb4 = port->usb4;
201ccc5cb8aSRajmohan Mani 	union acpi_object argv4[2];
202ccc5cb8aSRajmohan Mani 	struct acpi_device *adev;
203ccc5cb8aSRajmohan Mani 	union acpi_object *obj;
204ccc5cb8aSRajmohan Mani 	int ret;
205ccc5cb8aSRajmohan Mani 
206ccc5cb8aSRajmohan Mani 	if (!usb4->can_offline)
207ccc5cb8aSRajmohan Mani 		return 0;
208ccc5cb8aSRajmohan Mani 
209ccc5cb8aSRajmohan Mani 	adev = ACPI_COMPANION(&usb4->dev);
210ccc5cb8aSRajmohan Mani 	if (WARN_ON(!adev))
211ccc5cb8aSRajmohan Mani 		return 0;
212ccc5cb8aSRajmohan Mani 
213ccc5cb8aSRajmohan Mani 	/* Check if we are already powered on (and in correct mode) */
214ccc5cb8aSRajmohan Mani 	obj = acpi_evaluate_dsm_typed(adev->handle, &retimer_dsm_guid, 1,
215ccc5cb8aSRajmohan Mani 				      RETIMER_DSM_QUERY_ONLINE_STATE, NULL,
216ccc5cb8aSRajmohan Mani 				      ACPI_TYPE_INTEGER);
217ccc5cb8aSRajmohan Mani 	if (!obj) {
218ccc5cb8aSRajmohan Mani 		tb_port_warn(port, "ACPI: query online _DSM failed\n");
219ccc5cb8aSRajmohan Mani 		return -EIO;
220ccc5cb8aSRajmohan Mani 	}
221ccc5cb8aSRajmohan Mani 
222ccc5cb8aSRajmohan Mani 	ret = obj->integer.value;
223ccc5cb8aSRajmohan Mani 	ACPI_FREE(obj);
224ccc5cb8aSRajmohan Mani 
225ccc5cb8aSRajmohan Mani 	if (power == ret)
226ccc5cb8aSRajmohan Mani 		return 0;
227ccc5cb8aSRajmohan Mani 
228ccc5cb8aSRajmohan Mani 	tb_port_dbg(port, "ACPI: calling _DSM to power %s retimers\n",
229ccc5cb8aSRajmohan Mani 		    power ? "on" : "off");
230ccc5cb8aSRajmohan Mani 
231ccc5cb8aSRajmohan Mani 	argv4[0].type = ACPI_TYPE_PACKAGE;
232ccc5cb8aSRajmohan Mani 	argv4[0].package.count = 1;
233ccc5cb8aSRajmohan Mani 	argv4[0].package.elements = &argv4[1];
234ccc5cb8aSRajmohan Mani 	argv4[1].integer.type = ACPI_TYPE_INTEGER;
235ccc5cb8aSRajmohan Mani 	argv4[1].integer.value = power;
236ccc5cb8aSRajmohan Mani 
237ccc5cb8aSRajmohan Mani 	obj = acpi_evaluate_dsm_typed(adev->handle, &retimer_dsm_guid, 1,
238ccc5cb8aSRajmohan Mani 				      RETIMER_DSM_SET_ONLINE_STATE, argv4,
239ccc5cb8aSRajmohan Mani 				      ACPI_TYPE_INTEGER);
240ccc5cb8aSRajmohan Mani 	if (!obj) {
241ccc5cb8aSRajmohan Mani 		tb_port_warn(port,
242ccc5cb8aSRajmohan Mani 			     "ACPI: set online state _DSM evaluation failed\n");
243ccc5cb8aSRajmohan Mani 		return -EIO;
244ccc5cb8aSRajmohan Mani 	}
245ccc5cb8aSRajmohan Mani 
246ccc5cb8aSRajmohan Mani 	ret = obj->integer.value;
247ccc5cb8aSRajmohan Mani 	ACPI_FREE(obj);
248ccc5cb8aSRajmohan Mani 
249ccc5cb8aSRajmohan Mani 	if (ret >= 0) {
250ccc5cb8aSRajmohan Mani 		if (power)
251ccc5cb8aSRajmohan Mani 			return ret == 1 ? 0 : -EBUSY;
252ccc5cb8aSRajmohan Mani 		return 0;
253ccc5cb8aSRajmohan Mani 	}
254ccc5cb8aSRajmohan Mani 
255ccc5cb8aSRajmohan Mani 	tb_port_warn(port, "ACPI: set online state _DSM failed with error %d\n", ret);
256ccc5cb8aSRajmohan Mani 	return -EIO;
257ccc5cb8aSRajmohan Mani }
258ccc5cb8aSRajmohan Mani 
259ccc5cb8aSRajmohan Mani /**
260ccc5cb8aSRajmohan Mani  * tb_acpi_power_on_retimers() - Call platform to power on retimers
261ccc5cb8aSRajmohan Mani  * @port: USB4 port
262ccc5cb8aSRajmohan Mani  *
263ccc5cb8aSRajmohan Mani  * Calls platform to turn on power to all retimers behind this USB4
264ccc5cb8aSRajmohan Mani  * port. After this function returns successfully the caller can
265ccc5cb8aSRajmohan Mani  * continue with the normal retimer flows (as specified in the USB4
266ccc5cb8aSRajmohan Mani  * spec). Note if this returns %-EBUSY it means the type-C port is in
267ccc5cb8aSRajmohan Mani  * non-USB4/TBT mode (there is non-USB4/TBT device connected).
268ccc5cb8aSRajmohan Mani  *
269ccc5cb8aSRajmohan Mani  * This should only be called if the USB4/TBT link is not up.
270ccc5cb8aSRajmohan Mani  *
271ccc5cb8aSRajmohan Mani  * Returns %0 on success.
272ccc5cb8aSRajmohan Mani  */
273ccc5cb8aSRajmohan Mani int tb_acpi_power_on_retimers(struct tb_port *port)
274ccc5cb8aSRajmohan Mani {
275ccc5cb8aSRajmohan Mani 	return tb_acpi_retimer_set_power(port, true);
276ccc5cb8aSRajmohan Mani }
277ccc5cb8aSRajmohan Mani 
278ccc5cb8aSRajmohan Mani /**
279ccc5cb8aSRajmohan Mani  * tb_acpi_power_off_retimers() - Call platform to power off retimers
280ccc5cb8aSRajmohan Mani  * @port: USB4 port
281ccc5cb8aSRajmohan Mani  *
282ccc5cb8aSRajmohan Mani  * This is the opposite of tb_acpi_power_on_retimers(). After returning
283ccc5cb8aSRajmohan Mani  * successfully the normal operations with the @port can continue.
284ccc5cb8aSRajmohan Mani  *
285ccc5cb8aSRajmohan Mani  * Returns %0 on success.
286ccc5cb8aSRajmohan Mani  */
287ccc5cb8aSRajmohan Mani int tb_acpi_power_off_retimers(struct tb_port *port)
288ccc5cb8aSRajmohan Mani {
289ccc5cb8aSRajmohan Mani 	return tb_acpi_retimer_set_power(port, false);
290ccc5cb8aSRajmohan Mani }
291ccc5cb8aSRajmohan Mani 
292ccc5cb8aSRajmohan Mani static bool tb_acpi_bus_match(struct device *dev)
293ccc5cb8aSRajmohan Mani {
294ccc5cb8aSRajmohan Mani 	return tb_is_switch(dev) || tb_is_usb4_port_device(dev);
295ccc5cb8aSRajmohan Mani }
296ccc5cb8aSRajmohan Mani 
297ccc5cb8aSRajmohan Mani static struct acpi_device *tb_acpi_switch_find_companion(struct tb_switch *sw)
298ccc5cb8aSRajmohan Mani {
299*7ce54221SGil Fine 	struct tb_switch *parent_sw = tb_switch_parent(sw);
300ccc5cb8aSRajmohan Mani 	struct acpi_device *adev = NULL;
301ccc5cb8aSRajmohan Mani 
302a73a204bSRafael J. Wysocki 	/*
303a73a204bSRafael J. Wysocki 	 * Device routers exists under the downstream facing USB4 port
304a73a204bSRafael J. Wysocki 	 * of the parent router. Their _ADR is always 0.
305a73a204bSRafael J. Wysocki 	 */
306ccc5cb8aSRajmohan Mani 	if (parent_sw) {
307*7ce54221SGil Fine 		struct tb_port *port = tb_switch_downstream_port(sw);
308ccc5cb8aSRajmohan Mani 		struct acpi_device *port_adev;
309ccc5cb8aSRajmohan Mani 
310a73a204bSRafael J. Wysocki 		port_adev = acpi_find_child_by_adr(ACPI_COMPANION(&parent_sw->dev),
311a73a204bSRafael J. Wysocki 						   port->port);
312ccc5cb8aSRajmohan Mani 		if (port_adev)
313ccc5cb8aSRajmohan Mani 			adev = acpi_find_child_device(port_adev, 0, false);
314ccc5cb8aSRajmohan Mani 	} else {
315ccc5cb8aSRajmohan Mani 		struct tb_nhi *nhi = sw->tb->nhi;
316ccc5cb8aSRajmohan Mani 		struct acpi_device *parent_adev;
317ccc5cb8aSRajmohan Mani 
318ccc5cb8aSRajmohan Mani 		parent_adev = ACPI_COMPANION(&nhi->pdev->dev);
319ccc5cb8aSRajmohan Mani 		if (parent_adev)
320ccc5cb8aSRajmohan Mani 			adev = acpi_find_child_device(parent_adev, 0, false);
321ccc5cb8aSRajmohan Mani 	}
322ccc5cb8aSRajmohan Mani 
323ccc5cb8aSRajmohan Mani 	return adev;
324ccc5cb8aSRajmohan Mani }
325ccc5cb8aSRajmohan Mani 
326ccc5cb8aSRajmohan Mani static struct acpi_device *tb_acpi_find_companion(struct device *dev)
327ccc5cb8aSRajmohan Mani {
328ccc5cb8aSRajmohan Mani 	/*
329ccc5cb8aSRajmohan Mani 	 * The Thunderbolt/USB4 hierarchy looks like following:
330ccc5cb8aSRajmohan Mani 	 *
331ccc5cb8aSRajmohan Mani 	 * Device (NHI)
332ccc5cb8aSRajmohan Mani 	 *   Device (HR)		// Host router _ADR == 0
333ccc5cb8aSRajmohan Mani 	 *      Device (DFP0)		// Downstream port _ADR == lane 0 adapter
334ccc5cb8aSRajmohan Mani 	 *        Device (DR)		// Device router _ADR == 0
335ccc5cb8aSRajmohan Mani 	 *          Device (UFP)	// Upstream port _ADR == lane 0 adapter
336ccc5cb8aSRajmohan Mani 	 *      Device (DFP1)		// Downstream port _ADR == lane 0 adapter number
337ccc5cb8aSRajmohan Mani 	 *
338ccc5cb8aSRajmohan Mani 	 * At the moment we bind the host router to the corresponding
339ccc5cb8aSRajmohan Mani 	 * Linux device.
340ccc5cb8aSRajmohan Mani 	 */
341ccc5cb8aSRajmohan Mani 	if (tb_is_switch(dev))
342ccc5cb8aSRajmohan Mani 		return tb_acpi_switch_find_companion(tb_to_switch(dev));
3434e99c98eSAndy Shevchenko 	if (tb_is_usb4_port_device(dev))
344a73a204bSRafael J. Wysocki 		return acpi_find_child_by_adr(ACPI_COMPANION(dev->parent),
345a73a204bSRafael J. Wysocki 					      tb_to_usb4_port_device(dev)->port->port);
346ccc5cb8aSRajmohan Mani 	return NULL;
347ccc5cb8aSRajmohan Mani }
348ccc5cb8aSRajmohan Mani 
349ccc5cb8aSRajmohan Mani static void tb_acpi_setup(struct device *dev)
350ccc5cb8aSRajmohan Mani {
351ccc5cb8aSRajmohan Mani 	struct acpi_device *adev = ACPI_COMPANION(dev);
352ccc5cb8aSRajmohan Mani 	struct usb4_port *usb4 = tb_to_usb4_port_device(dev);
353ccc5cb8aSRajmohan Mani 
354ccc5cb8aSRajmohan Mani 	if (!adev || !usb4)
355ccc5cb8aSRajmohan Mani 		return;
356ccc5cb8aSRajmohan Mani 
357ccc5cb8aSRajmohan Mani 	if (acpi_check_dsm(adev->handle, &retimer_dsm_guid, 1,
358ccc5cb8aSRajmohan Mani 			   BIT(RETIMER_DSM_QUERY_ONLINE_STATE) |
359ccc5cb8aSRajmohan Mani 			   BIT(RETIMER_DSM_SET_ONLINE_STATE)))
360ccc5cb8aSRajmohan Mani 		usb4->can_offline = true;
361ccc5cb8aSRajmohan Mani }
362ccc5cb8aSRajmohan Mani 
363ccc5cb8aSRajmohan Mani static struct acpi_bus_type tb_acpi_bus = {
364ccc5cb8aSRajmohan Mani 	.name = "thunderbolt",
365ccc5cb8aSRajmohan Mani 	.match = tb_acpi_bus_match,
366ccc5cb8aSRajmohan Mani 	.find_companion = tb_acpi_find_companion,
367ccc5cb8aSRajmohan Mani 	.setup = tb_acpi_setup,
368ccc5cb8aSRajmohan Mani };
369ccc5cb8aSRajmohan Mani 
370ccc5cb8aSRajmohan Mani int tb_acpi_init(void)
371ccc5cb8aSRajmohan Mani {
372ccc5cb8aSRajmohan Mani 	return register_acpi_bus_type(&tb_acpi_bus);
373ccc5cb8aSRajmohan Mani }
374ccc5cb8aSRajmohan Mani 
375ccc5cb8aSRajmohan Mani void tb_acpi_exit(void)
376ccc5cb8aSRajmohan Mani {
377ccc5cb8aSRajmohan Mani 	unregister_acpi_bus_type(&tb_acpi_bus);
378ccc5cb8aSRajmohan Mani }
379