.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* |
---|
2 | 3 | * Jack-detection handling for HD-audio |
---|
3 | 4 | * |
---|
4 | 5 | * Copyright (c) 2011 Takashi Iwai <tiwai@suse.de> |
---|
5 | | - * |
---|
6 | | - * This driver is free software; you can redistribute it and/or modify |
---|
7 | | - * it under the terms of the GNU General Public License as published by |
---|
8 | | - * the Free Software Foundation; either version 2 of the License, or |
---|
9 | | - * (at your option) any later version. |
---|
10 | 6 | */ |
---|
11 | 7 | |
---|
12 | 8 | #include <linux/init.h> |
---|
.. | .. |
---|
15 | 11 | #include <sound/core.h> |
---|
16 | 12 | #include <sound/control.h> |
---|
17 | 13 | #include <sound/jack.h> |
---|
18 | | -#include "hda_codec.h" |
---|
| 14 | +#include <sound/hda_codec.h> |
---|
19 | 15 | #include "hda_local.h" |
---|
20 | 16 | #include "hda_auto_parser.h" |
---|
21 | 17 | #include "hda_jack.h" |
---|
.. | .. |
---|
47 | 43 | EXPORT_SYMBOL_GPL(is_jack_detectable); |
---|
48 | 44 | |
---|
49 | 45 | /* execute pin sense measurement */ |
---|
50 | | -static u32 read_pin_sense(struct hda_codec *codec, hda_nid_t nid) |
---|
| 46 | +static u32 read_pin_sense(struct hda_codec *codec, hda_nid_t nid, int dev_id) |
---|
51 | 47 | { |
---|
52 | 48 | u32 pincap; |
---|
53 | 49 | u32 val; |
---|
.. | .. |
---|
59 | 55 | AC_VERB_SET_PIN_SENSE, 0); |
---|
60 | 56 | } |
---|
61 | 57 | val = snd_hda_codec_read(codec, nid, 0, |
---|
62 | | - AC_VERB_GET_PIN_SENSE, 0); |
---|
| 58 | + AC_VERB_GET_PIN_SENSE, dev_id); |
---|
63 | 59 | if (codec->inv_jack_detect) |
---|
64 | 60 | val ^= AC_PINSENSE_PRESENCE; |
---|
65 | 61 | return val; |
---|
66 | 62 | } |
---|
67 | 63 | |
---|
68 | 64 | /** |
---|
69 | | - * snd_hda_jack_tbl_get - query the jack-table entry for the given NID |
---|
| 65 | + * snd_hda_jack_tbl_get_mst - query the jack-table entry for the given NID |
---|
70 | 66 | * @codec: the HDA codec |
---|
71 | 67 | * @nid: pin NID to refer to |
---|
| 68 | + * @dev_id: pin device entry id |
---|
72 | 69 | */ |
---|
73 | 70 | struct hda_jack_tbl * |
---|
74 | | -snd_hda_jack_tbl_get(struct hda_codec *codec, hda_nid_t nid) |
---|
| 71 | +snd_hda_jack_tbl_get_mst(struct hda_codec *codec, hda_nid_t nid, int dev_id) |
---|
| 72 | +{ |
---|
| 73 | + struct hda_jack_tbl *jack = codec->jacktbl.list; |
---|
| 74 | + int i; |
---|
| 75 | + |
---|
| 76 | + if (!nid || !jack) |
---|
| 77 | + return NULL; |
---|
| 78 | + for (i = 0; i < codec->jacktbl.used; i++, jack++) |
---|
| 79 | + if (jack->nid == nid && jack->dev_id == dev_id) |
---|
| 80 | + return jack; |
---|
| 81 | + return NULL; |
---|
| 82 | +} |
---|
| 83 | +EXPORT_SYMBOL_GPL(snd_hda_jack_tbl_get_mst); |
---|
| 84 | + |
---|
| 85 | +/** |
---|
| 86 | + * snd_hda_jack_tbl_get_from_tag - query the jack-table entry for the given tag |
---|
| 87 | + * @codec: the HDA codec |
---|
| 88 | + * @tag: tag value to refer to |
---|
| 89 | + * @dev_id: pin device entry id |
---|
| 90 | + */ |
---|
| 91 | +struct hda_jack_tbl * |
---|
| 92 | +snd_hda_jack_tbl_get_from_tag(struct hda_codec *codec, |
---|
| 93 | + unsigned char tag, int dev_id) |
---|
| 94 | +{ |
---|
| 95 | + struct hda_jack_tbl *jack = codec->jacktbl.list; |
---|
| 96 | + int i; |
---|
| 97 | + |
---|
| 98 | + if (!tag || !jack) |
---|
| 99 | + return NULL; |
---|
| 100 | + for (i = 0; i < codec->jacktbl.used; i++, jack++) |
---|
| 101 | + if (jack->tag == tag && jack->dev_id == dev_id) |
---|
| 102 | + return jack; |
---|
| 103 | + return NULL; |
---|
| 104 | +} |
---|
| 105 | +EXPORT_SYMBOL_GPL(snd_hda_jack_tbl_get_from_tag); |
---|
| 106 | + |
---|
| 107 | +static struct hda_jack_tbl * |
---|
| 108 | +any_jack_tbl_get_from_nid(struct hda_codec *codec, hda_nid_t nid) |
---|
75 | 109 | { |
---|
76 | 110 | struct hda_jack_tbl *jack = codec->jacktbl.list; |
---|
77 | 111 | int i; |
---|
.. | .. |
---|
83 | 117 | return jack; |
---|
84 | 118 | return NULL; |
---|
85 | 119 | } |
---|
86 | | -EXPORT_SYMBOL_GPL(snd_hda_jack_tbl_get); |
---|
87 | | - |
---|
88 | | -/** |
---|
89 | | - * snd_hda_jack_tbl_get_from_tag - query the jack-table entry for the given tag |
---|
90 | | - * @codec: the HDA codec |
---|
91 | | - * @tag: tag value to refer to |
---|
92 | | - */ |
---|
93 | | -struct hda_jack_tbl * |
---|
94 | | -snd_hda_jack_tbl_get_from_tag(struct hda_codec *codec, unsigned char tag) |
---|
95 | | -{ |
---|
96 | | - struct hda_jack_tbl *jack = codec->jacktbl.list; |
---|
97 | | - int i; |
---|
98 | | - |
---|
99 | | - if (!tag || !jack) |
---|
100 | | - return NULL; |
---|
101 | | - for (i = 0; i < codec->jacktbl.used; i++, jack++) |
---|
102 | | - if (jack->tag == tag) |
---|
103 | | - return jack; |
---|
104 | | - return NULL; |
---|
105 | | -} |
---|
106 | | -EXPORT_SYMBOL_GPL(snd_hda_jack_tbl_get_from_tag); |
---|
107 | 120 | |
---|
108 | 121 | /** |
---|
109 | 122 | * snd_hda_jack_tbl_new - create a jack-table entry for the given NID |
---|
110 | 123 | * @codec: the HDA codec |
---|
111 | 124 | * @nid: pin NID to assign |
---|
| 125 | + * @dev_id: pin device entry id |
---|
112 | 126 | */ |
---|
113 | 127 | static struct hda_jack_tbl * |
---|
114 | | -snd_hda_jack_tbl_new(struct hda_codec *codec, hda_nid_t nid) |
---|
| 128 | +snd_hda_jack_tbl_new(struct hda_codec *codec, hda_nid_t nid, int dev_id) |
---|
115 | 129 | { |
---|
116 | | - struct hda_jack_tbl *jack = snd_hda_jack_tbl_get(codec, nid); |
---|
| 130 | + struct hda_jack_tbl *jack = |
---|
| 131 | + snd_hda_jack_tbl_get_mst(codec, nid, dev_id); |
---|
| 132 | + struct hda_jack_tbl *existing_nid_jack = |
---|
| 133 | + any_jack_tbl_get_from_nid(codec, nid); |
---|
| 134 | + |
---|
| 135 | + WARN_ON(dev_id != 0 && !codec->dp_mst); |
---|
| 136 | + |
---|
117 | 137 | if (jack) |
---|
118 | 138 | return jack; |
---|
119 | 139 | jack = snd_array_new(&codec->jacktbl); |
---|
120 | 140 | if (!jack) |
---|
121 | 141 | return NULL; |
---|
122 | 142 | jack->nid = nid; |
---|
| 143 | + jack->dev_id = dev_id; |
---|
123 | 144 | jack->jack_dirty = 1; |
---|
124 | | - jack->tag = codec->jacktbl.used; |
---|
| 145 | + if (existing_nid_jack) { |
---|
| 146 | + jack->tag = existing_nid_jack->tag; |
---|
| 147 | + |
---|
| 148 | + /* |
---|
| 149 | + * Copy jack_detect from existing_nid_jack to avoid |
---|
| 150 | + * snd_hda_jack_detect_enable_callback_mst() making multiple |
---|
| 151 | + * SET_UNSOLICITED_ENABLE calls on the same pin. |
---|
| 152 | + */ |
---|
| 153 | + jack->jack_detect = existing_nid_jack->jack_detect; |
---|
| 154 | + } else { |
---|
| 155 | + jack->tag = codec->jacktbl.used; |
---|
| 156 | + } |
---|
| 157 | + |
---|
125 | 158 | return jack; |
---|
126 | 159 | } |
---|
127 | 160 | |
---|
.. | .. |
---|
157 | 190 | if (jack->phantom_jack) |
---|
158 | 191 | jack->pin_sense = AC_PINSENSE_PRESENCE; |
---|
159 | 192 | else |
---|
160 | | - jack->pin_sense = read_pin_sense(codec, jack->nid); |
---|
| 193 | + jack->pin_sense = read_pin_sense(codec, jack->nid, |
---|
| 194 | + jack->dev_id); |
---|
161 | 195 | |
---|
162 | 196 | /* A gating jack indicates the jack is invalid if gating is unplugged */ |
---|
163 | | - if (jack->gating_jack && !snd_hda_jack_detect(codec, jack->gating_jack)) |
---|
| 197 | + if (jack->gating_jack && |
---|
| 198 | + !snd_hda_jack_detect_mst(codec, jack->gating_jack, jack->dev_id)) |
---|
164 | 199 | jack->pin_sense &= ~AC_PINSENSE_PRESENCE; |
---|
165 | 200 | |
---|
166 | 201 | jack->jack_dirty = 0; |
---|
.. | .. |
---|
168 | 203 | /* If a jack is gated by this one update it. */ |
---|
169 | 204 | if (jack->gated_jack) { |
---|
170 | 205 | struct hda_jack_tbl *gated = |
---|
171 | | - snd_hda_jack_tbl_get(codec, jack->gated_jack); |
---|
| 206 | + snd_hda_jack_tbl_get_mst(codec, jack->gated_jack, |
---|
| 207 | + jack->dev_id); |
---|
172 | 208 | if (gated) { |
---|
173 | 209 | gated->jack_dirty = 1; |
---|
174 | 210 | jack_detect_update(codec, gated); |
---|
.. | .. |
---|
195 | 231 | EXPORT_SYMBOL_GPL(snd_hda_jack_set_dirty_all); |
---|
196 | 232 | |
---|
197 | 233 | /** |
---|
198 | | - * snd_hda_pin_sense - execute pin sense measurement |
---|
| 234 | + * snd_hda_jack_pin_sense - execute pin sense measurement |
---|
199 | 235 | * @codec: the CODEC to sense |
---|
200 | 236 | * @nid: the pin NID to sense |
---|
| 237 | + * @dev_id: pin device entry id |
---|
201 | 238 | * |
---|
202 | 239 | * Execute necessary pin sense measurement and return its Presence Detect, |
---|
203 | 240 | * Impedance, ELD Valid etc. status bits. |
---|
204 | 241 | */ |
---|
205 | | -u32 snd_hda_pin_sense(struct hda_codec *codec, hda_nid_t nid) |
---|
| 242 | +u32 snd_hda_jack_pin_sense(struct hda_codec *codec, hda_nid_t nid, int dev_id) |
---|
206 | 243 | { |
---|
207 | | - struct hda_jack_tbl *jack = snd_hda_jack_tbl_get(codec, nid); |
---|
| 244 | + struct hda_jack_tbl *jack = |
---|
| 245 | + snd_hda_jack_tbl_get_mst(codec, nid, dev_id); |
---|
208 | 246 | if (jack) { |
---|
209 | 247 | jack_detect_update(codec, jack); |
---|
210 | 248 | return jack->pin_sense; |
---|
211 | 249 | } |
---|
212 | | - return read_pin_sense(codec, nid); |
---|
| 250 | + return read_pin_sense(codec, nid, dev_id); |
---|
213 | 251 | } |
---|
214 | | -EXPORT_SYMBOL_GPL(snd_hda_pin_sense); |
---|
| 252 | +EXPORT_SYMBOL_GPL(snd_hda_jack_pin_sense); |
---|
215 | 253 | |
---|
216 | 254 | /** |
---|
217 | | - * snd_hda_jack_detect_state - query pin Presence Detect status |
---|
| 255 | + * snd_hda_jack_detect_state_mst - query pin Presence Detect status |
---|
218 | 256 | * @codec: the CODEC to sense |
---|
219 | 257 | * @nid: the pin NID to sense |
---|
| 258 | + * @dev_id: pin device entry id |
---|
220 | 259 | * |
---|
221 | 260 | * Query and return the pin's Presence Detect status, as either |
---|
222 | 261 | * HDA_JACK_NOT_PRESENT, HDA_JACK_PRESENT or HDA_JACK_PHANTOM. |
---|
223 | 262 | */ |
---|
224 | | -int snd_hda_jack_detect_state(struct hda_codec *codec, hda_nid_t nid) |
---|
| 263 | +int snd_hda_jack_detect_state_mst(struct hda_codec *codec, |
---|
| 264 | + hda_nid_t nid, int dev_id) |
---|
225 | 265 | { |
---|
226 | | - struct hda_jack_tbl *jack = snd_hda_jack_tbl_get(codec, nid); |
---|
| 266 | + struct hda_jack_tbl *jack = |
---|
| 267 | + snd_hda_jack_tbl_get_mst(codec, nid, dev_id); |
---|
227 | 268 | if (jack && jack->phantom_jack) |
---|
228 | 269 | return HDA_JACK_PHANTOM; |
---|
229 | | - else if (snd_hda_pin_sense(codec, nid) & AC_PINSENSE_PRESENCE) |
---|
| 270 | + else if (snd_hda_jack_pin_sense(codec, nid, dev_id) & |
---|
| 271 | + AC_PINSENSE_PRESENCE) |
---|
230 | 272 | return HDA_JACK_PRESENT; |
---|
231 | 273 | else |
---|
232 | 274 | return HDA_JACK_NOT_PRESENT; |
---|
233 | 275 | } |
---|
234 | | -EXPORT_SYMBOL_GPL(snd_hda_jack_detect_state); |
---|
| 276 | +EXPORT_SYMBOL_GPL(snd_hda_jack_detect_state_mst); |
---|
| 277 | + |
---|
| 278 | +static struct hda_jack_callback * |
---|
| 279 | +find_callback_from_list(struct hda_jack_tbl *jack, |
---|
| 280 | + hda_jack_callback_fn func) |
---|
| 281 | +{ |
---|
| 282 | + struct hda_jack_callback *cb; |
---|
| 283 | + |
---|
| 284 | + if (!func) |
---|
| 285 | + return NULL; |
---|
| 286 | + |
---|
| 287 | + for (cb = jack->callback; cb; cb = cb->next) { |
---|
| 288 | + if (cb->func == func) |
---|
| 289 | + return cb; |
---|
| 290 | + } |
---|
| 291 | + |
---|
| 292 | + return NULL; |
---|
| 293 | +} |
---|
235 | 294 | |
---|
236 | 295 | /** |
---|
237 | | - * snd_hda_jack_detect_enable - enable the jack-detection |
---|
| 296 | + * snd_hda_jack_detect_enable_mst - enable the jack-detection |
---|
238 | 297 | * @codec: the HDA codec |
---|
239 | 298 | * @nid: pin NID to enable |
---|
240 | 299 | * @func: callback function to register |
---|
| 300 | + * @dev_id: pin device entry id |
---|
241 | 301 | * |
---|
242 | 302 | * In the case of error, the return value will be a pointer embedded with |
---|
243 | 303 | * errno. Check and handle the return value appropriately with standard |
---|
244 | 304 | * macros such as @IS_ERR() and @PTR_ERR(). |
---|
245 | 305 | */ |
---|
246 | 306 | struct hda_jack_callback * |
---|
247 | | -snd_hda_jack_detect_enable_callback(struct hda_codec *codec, hda_nid_t nid, |
---|
248 | | - hda_jack_callback_fn func) |
---|
| 307 | +snd_hda_jack_detect_enable_callback_mst(struct hda_codec *codec, hda_nid_t nid, |
---|
| 308 | + int dev_id, hda_jack_callback_fn func) |
---|
249 | 309 | { |
---|
250 | 310 | struct hda_jack_tbl *jack; |
---|
251 | 311 | struct hda_jack_callback *callback = NULL; |
---|
252 | 312 | int err; |
---|
253 | 313 | |
---|
254 | | - jack = snd_hda_jack_tbl_new(codec, nid); |
---|
| 314 | + jack = snd_hda_jack_tbl_new(codec, nid, dev_id); |
---|
255 | 315 | if (!jack) |
---|
256 | 316 | return ERR_PTR(-ENOMEM); |
---|
257 | | - if (func) { |
---|
| 317 | + |
---|
| 318 | + callback = find_callback_from_list(jack, func); |
---|
| 319 | + |
---|
| 320 | + if (func && !callback) { |
---|
258 | 321 | callback = kzalloc(sizeof(*callback), GFP_KERNEL); |
---|
259 | 322 | if (!callback) |
---|
260 | 323 | return ERR_PTR(-ENOMEM); |
---|
261 | 324 | callback->func = func; |
---|
262 | 325 | callback->nid = jack->nid; |
---|
| 326 | + callback->dev_id = jack->dev_id; |
---|
263 | 327 | callback->next = jack->callback; |
---|
264 | 328 | jack->callback = callback; |
---|
265 | 329 | } |
---|
.. | .. |
---|
276 | 340 | return ERR_PTR(err); |
---|
277 | 341 | return callback; |
---|
278 | 342 | } |
---|
279 | | -EXPORT_SYMBOL_GPL(snd_hda_jack_detect_enable_callback); |
---|
| 343 | +EXPORT_SYMBOL_GPL(snd_hda_jack_detect_enable_callback_mst); |
---|
280 | 344 | |
---|
281 | 345 | /** |
---|
282 | 346 | * snd_hda_jack_detect_enable - Enable the jack detection on the given pin |
---|
283 | 347 | * @codec: the HDA codec |
---|
284 | 348 | * @nid: pin NID to enable jack detection |
---|
| 349 | + * @dev_id: pin device entry id |
---|
285 | 350 | * |
---|
286 | 351 | * Enable the jack detection with the default callback. Returns zero if |
---|
287 | 352 | * successful or a negative error code. |
---|
288 | 353 | */ |
---|
289 | | -int snd_hda_jack_detect_enable(struct hda_codec *codec, hda_nid_t nid) |
---|
| 354 | +int snd_hda_jack_detect_enable(struct hda_codec *codec, hda_nid_t nid, |
---|
| 355 | + int dev_id) |
---|
290 | 356 | { |
---|
291 | | - return PTR_ERR_OR_ZERO(snd_hda_jack_detect_enable_callback(codec, nid, NULL)); |
---|
| 357 | + return PTR_ERR_OR_ZERO(snd_hda_jack_detect_enable_callback_mst(codec, |
---|
| 358 | + nid, |
---|
| 359 | + dev_id, |
---|
| 360 | + NULL)); |
---|
292 | 361 | } |
---|
293 | 362 | EXPORT_SYMBOL_GPL(snd_hda_jack_detect_enable); |
---|
294 | 363 | |
---|
.. | .. |
---|
303 | 372 | int snd_hda_jack_set_gating_jack(struct hda_codec *codec, hda_nid_t gated_nid, |
---|
304 | 373 | hda_nid_t gating_nid) |
---|
305 | 374 | { |
---|
306 | | - struct hda_jack_tbl *gated = snd_hda_jack_tbl_new(codec, gated_nid); |
---|
307 | | - struct hda_jack_tbl *gating = snd_hda_jack_tbl_new(codec, gating_nid); |
---|
| 375 | + struct hda_jack_tbl *gated = snd_hda_jack_tbl_new(codec, gated_nid, 0); |
---|
| 376 | + struct hda_jack_tbl *gating = |
---|
| 377 | + snd_hda_jack_tbl_new(codec, gating_nid, 0); |
---|
| 378 | + |
---|
| 379 | + WARN_ON(codec->dp_mst); |
---|
308 | 380 | |
---|
309 | 381 | if (!gated || !gating) |
---|
310 | 382 | return -EINVAL; |
---|
.. | .. |
---|
339 | 411 | if (jack->nid) { |
---|
340 | 412 | if (!jack->jack || jack->block_report) |
---|
341 | 413 | continue; |
---|
342 | | - state = get_jack_plug_state(jack->pin_sense); |
---|
343 | | - snd_jack_report(jack->jack, |
---|
344 | | - state ? jack->type : 0); |
---|
| 414 | + state = jack->button_state; |
---|
| 415 | + if (get_jack_plug_state(jack->pin_sense)) |
---|
| 416 | + state |= jack->type; |
---|
| 417 | + snd_jack_report(jack->jack, state); |
---|
| 418 | + if (jack->button_state) { |
---|
| 419 | + snd_jack_report(jack->jack, |
---|
| 420 | + state & ~jack->button_state); |
---|
| 421 | + jack->button_state = 0; /* button released */ |
---|
| 422 | + } |
---|
345 | 423 | } |
---|
346 | 424 | } |
---|
347 | 425 | EXPORT_SYMBOL_GPL(snd_hda_jack_report_sync); |
---|
.. | .. |
---|
374 | 452 | } |
---|
375 | 453 | |
---|
376 | 454 | /** |
---|
377 | | - * snd_hda_jack_add_kctl - Add a kctl for the given pin |
---|
| 455 | + * snd_hda_jack_add_kctl_mst - Add a kctl for the given pin |
---|
378 | 456 | * @codec: the HDA codec |
---|
379 | 457 | * @nid: pin NID to assign |
---|
| 458 | + * @dev_id : pin device entry id |
---|
380 | 459 | * @name: string name for the jack |
---|
381 | 460 | * @phantom_jack: flag to deal as a phantom jack |
---|
| 461 | + * @type: jack type bits to be reported, 0 for guessing from pincfg |
---|
| 462 | + * @keymap: optional jack / key mapping |
---|
382 | 463 | * |
---|
383 | 464 | * This assigns a jack-detection kctl to the given pin. The kcontrol |
---|
384 | 465 | * will have the given name and index. |
---|
385 | 466 | */ |
---|
386 | | -int snd_hda_jack_add_kctl(struct hda_codec *codec, hda_nid_t nid, |
---|
387 | | - const char *name, bool phantom_jack) |
---|
| 467 | +int snd_hda_jack_add_kctl_mst(struct hda_codec *codec, hda_nid_t nid, |
---|
| 468 | + int dev_id, const char *name, bool phantom_jack, |
---|
| 469 | + int type, const struct hda_jack_keymap *keymap) |
---|
388 | 470 | { |
---|
389 | 471 | struct hda_jack_tbl *jack; |
---|
390 | | - int err, state, type; |
---|
| 472 | + const struct hda_jack_keymap *map; |
---|
| 473 | + int err, state, buttons; |
---|
391 | 474 | |
---|
392 | | - jack = snd_hda_jack_tbl_new(codec, nid); |
---|
| 475 | + jack = snd_hda_jack_tbl_new(codec, nid, dev_id); |
---|
393 | 476 | if (!jack) |
---|
394 | 477 | return 0; |
---|
395 | 478 | if (jack->jack) |
---|
396 | 479 | return 0; /* already created */ |
---|
397 | 480 | |
---|
398 | | - type = get_input_jack_type(codec, nid); |
---|
399 | | - err = snd_jack_new(codec->card, name, type, |
---|
| 481 | + if (!type) |
---|
| 482 | + type = get_input_jack_type(codec, nid); |
---|
| 483 | + |
---|
| 484 | + buttons = 0; |
---|
| 485 | + if (keymap) { |
---|
| 486 | + for (map = keymap; map->type; map++) |
---|
| 487 | + buttons |= map->type; |
---|
| 488 | + } |
---|
| 489 | + |
---|
| 490 | + err = snd_jack_new(codec->card, name, type | buttons, |
---|
400 | 491 | &jack->jack, true, phantom_jack); |
---|
401 | 492 | if (err < 0) |
---|
402 | 493 | return err; |
---|
403 | 494 | |
---|
404 | 495 | jack->phantom_jack = !!phantom_jack; |
---|
405 | 496 | jack->type = type; |
---|
| 497 | + jack->button_state = 0; |
---|
406 | 498 | jack->jack->private_data = jack; |
---|
407 | 499 | jack->jack->private_free = hda_free_jack_priv; |
---|
408 | | - state = snd_hda_jack_detect(codec, nid); |
---|
| 500 | + if (keymap) { |
---|
| 501 | + for (map = keymap; map->type; map++) |
---|
| 502 | + snd_jack_set_key(jack->jack, map->type, map->key); |
---|
| 503 | + } |
---|
| 504 | + |
---|
| 505 | + state = snd_hda_jack_detect_mst(codec, nid, dev_id); |
---|
409 | 506 | snd_jack_report(jack->jack, state ? jack->type : 0); |
---|
410 | 507 | |
---|
411 | 508 | return 0; |
---|
412 | 509 | } |
---|
413 | | -EXPORT_SYMBOL_GPL(snd_hda_jack_add_kctl); |
---|
| 510 | +EXPORT_SYMBOL_GPL(snd_hda_jack_add_kctl_mst); |
---|
414 | 511 | |
---|
415 | 512 | static int add_jack_kctl(struct hda_codec *codec, hda_nid_t nid, |
---|
416 | 513 | const struct auto_pin_cfg *cfg, |
---|
.. | .. |
---|
420 | 517 | char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; |
---|
421 | 518 | int err; |
---|
422 | 519 | bool phantom_jack; |
---|
| 520 | + |
---|
| 521 | + WARN_ON(codec->dp_mst); |
---|
423 | 522 | |
---|
424 | 523 | if (!nid) |
---|
425 | 524 | return 0; |
---|
.. | .. |
---|
437 | 536 | if (phantom_jack) |
---|
438 | 537 | /* Example final name: "Internal Mic Phantom Jack" */ |
---|
439 | 538 | strncat(name, " Phantom", sizeof(name) - strlen(name) - 1); |
---|
440 | | - err = snd_hda_jack_add_kctl(codec, nid, name, phantom_jack); |
---|
| 539 | + err = snd_hda_jack_add_kctl(codec, nid, name, phantom_jack, 0, NULL); |
---|
441 | 540 | if (err < 0) |
---|
442 | 541 | return err; |
---|
443 | 542 | |
---|
444 | 543 | if (!phantom_jack) |
---|
445 | | - return snd_hda_jack_detect_enable(codec, nid); |
---|
| 544 | + return snd_hda_jack_detect_enable(codec, nid, 0); |
---|
446 | 545 | return 0; |
---|
447 | 546 | } |
---|
448 | 547 | |
---|
.. | .. |
---|
508 | 607 | } |
---|
509 | 608 | EXPORT_SYMBOL_GPL(snd_hda_jack_add_kctls); |
---|
510 | 609 | |
---|
511 | | -static void call_jack_callback(struct hda_codec *codec, |
---|
| 610 | +static void call_jack_callback(struct hda_codec *codec, unsigned int res, |
---|
512 | 611 | struct hda_jack_tbl *jack) |
---|
513 | 612 | { |
---|
514 | 613 | struct hda_jack_callback *cb; |
---|
515 | 614 | |
---|
516 | | - for (cb = jack->callback; cb; cb = cb->next) |
---|
| 615 | + for (cb = jack->callback; cb; cb = cb->next) { |
---|
| 616 | + cb->jack = jack; |
---|
| 617 | + cb->unsol_res = res; |
---|
517 | 618 | cb->func(codec, cb); |
---|
| 619 | + } |
---|
518 | 620 | if (jack->gated_jack) { |
---|
519 | 621 | struct hda_jack_tbl *gated = |
---|
520 | | - snd_hda_jack_tbl_get(codec, jack->gated_jack); |
---|
| 622 | + snd_hda_jack_tbl_get_mst(codec, jack->gated_jack, |
---|
| 623 | + jack->dev_id); |
---|
521 | 624 | if (gated) { |
---|
522 | | - for (cb = gated->callback; cb; cb = cb->next) |
---|
| 625 | + for (cb = gated->callback; cb; cb = cb->next) { |
---|
| 626 | + cb->jack = gated; |
---|
| 627 | + cb->unsol_res = res; |
---|
523 | 628 | cb->func(codec, cb); |
---|
| 629 | + } |
---|
524 | 630 | } |
---|
525 | 631 | } |
---|
526 | 632 | } |
---|
.. | .. |
---|
533 | 639 | void snd_hda_jack_unsol_event(struct hda_codec *codec, unsigned int res) |
---|
534 | 640 | { |
---|
535 | 641 | struct hda_jack_tbl *event; |
---|
536 | | - int tag = (res >> AC_UNSOL_RES_TAG_SHIFT) & 0x7f; |
---|
| 642 | + int tag = (res & AC_UNSOL_RES_TAG) >> AC_UNSOL_RES_TAG_SHIFT; |
---|
537 | 643 | |
---|
538 | | - event = snd_hda_jack_tbl_get_from_tag(codec, tag); |
---|
| 644 | + if (codec->dp_mst) { |
---|
| 645 | + int dev_entry = |
---|
| 646 | + (res & AC_UNSOL_RES_DE) >> AC_UNSOL_RES_DE_SHIFT; |
---|
| 647 | + |
---|
| 648 | + event = snd_hda_jack_tbl_get_from_tag(codec, tag, dev_entry); |
---|
| 649 | + } else { |
---|
| 650 | + event = snd_hda_jack_tbl_get_from_tag(codec, tag, 0); |
---|
| 651 | + } |
---|
539 | 652 | if (!event) |
---|
540 | 653 | return; |
---|
541 | 654 | event->jack_dirty = 1; |
---|
542 | 655 | |
---|
543 | | - call_jack_callback(codec, event); |
---|
| 656 | + call_jack_callback(codec, res, event); |
---|
544 | 657 | snd_hda_jack_report_sync(codec); |
---|
545 | 658 | } |
---|
546 | 659 | EXPORT_SYMBOL_GPL(snd_hda_jack_unsol_event); |
---|
.. | .. |
---|
566 | 679 | if (old_sense == get_jack_plug_state(jack->pin_sense)) |
---|
567 | 680 | continue; |
---|
568 | 681 | changes = 1; |
---|
569 | | - call_jack_callback(codec, jack); |
---|
| 682 | + call_jack_callback(codec, 0, jack); |
---|
570 | 683 | } |
---|
571 | 684 | if (changes) |
---|
572 | 685 | snd_hda_jack_report_sync(codec); |
---|