aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/thunderbolt/tb.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/thunderbolt/tb.c')
-rw-r--r--drivers/thunderbolt/tb.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/drivers/thunderbolt/tb.c b/drivers/thunderbolt/tb.c
index f1b6100b6cf0..3b716fd123f6 100644
--- a/drivers/thunderbolt/tb.c
+++ b/drivers/thunderbolt/tb.c
@@ -11,6 +11,47 @@
11#include "tb.h" 11#include "tb.h"
12#include "tb_regs.h" 12#include "tb_regs.h"
13 13
14
15/* enumeration & hot plug handling */
16
17
18static void tb_scan_port(struct tb_port *port);
19
20/**
21 * tb_scan_switch() - scan for and initialize downstream switches
22 */
23static void tb_scan_switch(struct tb_switch *sw)
24{
25 int i;
26 for (i = 1; i <= sw->config.max_port_number; i++)
27 tb_scan_port(&sw->ports[i]);
28}
29
30/**
31 * tb_scan_port() - check for and initialize switches below port
32 */
33static void tb_scan_port(struct tb_port *port)
34{
35 struct tb_switch *sw;
36 if (tb_is_upstream_port(port))
37 return;
38 if (port->config.type != TB_TYPE_PORT)
39 return;
40 if (tb_wait_for_port(port, false) <= 0)
41 return;
42 if (port->remote) {
43 tb_port_WARN(port, "port already has a remote!\n");
44 return;
45 }
46 sw = tb_switch_alloc(port->sw->tb, tb_downstream_route(port));
47 if (!sw)
48 return;
49 port->remote = tb_upstream_port(sw);
50 tb_upstream_port(sw)->remote = port;
51 tb_scan_switch(sw);
52}
53
54
14/* hotplug handling */ 55/* hotplug handling */
15 56
16struct tb_hotplug_event { 57struct tb_hotplug_event {
@@ -134,6 +175,9 @@ struct tb *thunderbolt_alloc_and_start(struct tb_nhi *nhi)
134 if (!tb->root_switch) 175 if (!tb->root_switch)
135 goto err_locked; 176 goto err_locked;
136 177
178 /* Full scan to discover devices added before the driver was loaded. */
179 tb_scan_switch(tb->root_switch);
180
137 /* Allow tb_handle_hotplug to progress events */ 181 /* Allow tb_handle_hotplug to progress events */
138 tb->hotplug_active = true; 182 tb->hotplug_active = true;
139 mutex_unlock(&tb->lock); 183 mutex_unlock(&tb->lock);