diff options
author | Andreas Noever <andreas.noever@gmail.com> | 2014-06-03 16:04:04 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2014-06-19 17:07:47 -0400 |
commit | ca389f716f6140d5349583a716bc629d63b06b1f (patch) | |
tree | ee992c95fce4c62d721d1df9c55477b7d82802a4 /drivers/thunderbolt | |
parent | e2b8785ed312dad3a18279a3e88435fc269658c1 (diff) |
thunderbolt: Enable plug events
Thunderbolt switches have a plug events capability. This patch adds the
tb_plug_events_active method and uses it to activate plug events during
switch allocation.
Signed-off-by: Andreas Noever <andreas.noever@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/thunderbolt')
-rw-r--r-- | drivers/thunderbolt/switch.c | 52 | ||||
-rw-r--r-- | drivers/thunderbolt/tb.h | 1 |
2 files changed, 53 insertions, 0 deletions
diff --git a/drivers/thunderbolt/switch.c b/drivers/thunderbolt/switch.c index e89121ffe44e..6d193a230cf4 100644 --- a/drivers/thunderbolt/switch.c +++ b/drivers/thunderbolt/switch.c | |||
@@ -99,6 +99,45 @@ static void tb_dump_switch(struct tb *tb, struct tb_regs_switch_header *sw) | |||
99 | } | 99 | } |
100 | 100 | ||
101 | /** | 101 | /** |
102 | * tb_plug_events_active() - enable/disable plug events on a switch | ||
103 | * | ||
104 | * Also configures a sane plug_events_delay of 255ms. | ||
105 | * | ||
106 | * Return: Returns 0 on success or an error code on failure. | ||
107 | */ | ||
108 | static int tb_plug_events_active(struct tb_switch *sw, bool active) | ||
109 | { | ||
110 | u32 data; | ||
111 | int res; | ||
112 | |||
113 | sw->config.plug_events_delay = 0xff; | ||
114 | res = tb_sw_write(sw, ((u32 *) &sw->config) + 4, TB_CFG_SWITCH, 4, 1); | ||
115 | if (res) | ||
116 | return res; | ||
117 | |||
118 | res = tb_sw_read(sw, &data, TB_CFG_SWITCH, sw->cap_plug_events + 1, 1); | ||
119 | if (res) | ||
120 | return res; | ||
121 | |||
122 | if (active) { | ||
123 | data = data & 0xFFFFFF83; | ||
124 | switch (sw->config.device_id) { | ||
125 | case 0x1513: | ||
126 | case 0x151a: | ||
127 | case 0x1549: | ||
128 | break; | ||
129 | default: | ||
130 | data |= 4; | ||
131 | } | ||
132 | } else { | ||
133 | data = data | 0x7c; | ||
134 | } | ||
135 | return tb_sw_write(sw, &data, TB_CFG_SWITCH, | ||
136 | sw->cap_plug_events + 1, 1); | ||
137 | } | ||
138 | |||
139 | |||
140 | /** | ||
102 | * tb_switch_free() - free a tb_switch and all downstream switches | 141 | * tb_switch_free() - free a tb_switch and all downstream switches |
103 | */ | 142 | */ |
104 | void tb_switch_free(struct tb_switch *sw) | 143 | void tb_switch_free(struct tb_switch *sw) |
@@ -113,6 +152,8 @@ void tb_switch_free(struct tb_switch *sw) | |||
113 | sw->ports[i].remote = NULL; | 152 | sw->ports[i].remote = NULL; |
114 | } | 153 | } |
115 | 154 | ||
155 | tb_plug_events_active(sw, false); | ||
156 | |||
116 | kfree(sw->ports); | 157 | kfree(sw->ports); |
117 | kfree(sw); | 158 | kfree(sw); |
118 | } | 159 | } |
@@ -125,6 +166,7 @@ void tb_switch_free(struct tb_switch *sw) | |||
125 | struct tb_switch *tb_switch_alloc(struct tb *tb, u64 route) | 166 | struct tb_switch *tb_switch_alloc(struct tb *tb, u64 route) |
126 | { | 167 | { |
127 | int i; | 168 | int i; |
169 | int cap; | ||
128 | struct tb_switch *sw; | 170 | struct tb_switch *sw; |
129 | int upstream_port = tb_cfg_get_upstream_port(tb->ctl, route); | 171 | int upstream_port = tb_cfg_get_upstream_port(tb->ctl, route); |
130 | if (upstream_port < 0) | 172 | if (upstream_port < 0) |
@@ -177,6 +219,16 @@ struct tb_switch *tb_switch_alloc(struct tb *tb, u64 route) | |||
177 | 219 | ||
178 | /* TODO: I2C, IECS, EEPROM, link controller */ | 220 | /* TODO: I2C, IECS, EEPROM, link controller */ |
179 | 221 | ||
222 | cap = tb_find_cap(&sw->ports[0], TB_CFG_SWITCH, TB_CAP_PLUG_EVENTS); | ||
223 | if (cap < 0) { | ||
224 | tb_sw_warn(sw, "cannot find TB_CAP_PLUG_EVENTS aborting\n"); | ||
225 | goto err; | ||
226 | } | ||
227 | sw->cap_plug_events = cap; | ||
228 | |||
229 | if (tb_plug_events_active(sw, true)) | ||
230 | goto err; | ||
231 | |||
180 | return sw; | 232 | return sw; |
181 | err: | 233 | err: |
182 | kfree(sw->ports); | 234 | kfree(sw->ports); |
diff --git a/drivers/thunderbolt/tb.h b/drivers/thunderbolt/tb.h index 38e4c23c10fd..af123c4045e3 100644 --- a/drivers/thunderbolt/tb.h +++ b/drivers/thunderbolt/tb.h | |||
@@ -19,6 +19,7 @@ struct tb_switch { | |||
19 | struct tb_regs_switch_header config; | 19 | struct tb_regs_switch_header config; |
20 | struct tb_port *ports; | 20 | struct tb_port *ports; |
21 | struct tb *tb; | 21 | struct tb *tb; |
22 | int cap_plug_events; /* offset, zero if not found */ | ||
22 | }; | 23 | }; |
23 | 24 | ||
24 | /** | 25 | /** |