xref: /linux/sound/pci/hda/hda_jack.c (revision 8a79db5e83a5d52c74e6f3c40d6f312cf899213e)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Jack-detection handling for HD-audio
4  *
5  * Copyright (c) 2011 Takashi Iwai <tiwai@suse.de>
6  */
7 
8 #include <linux/init.h>
9 #include <linux/slab.h>
10 #include <linux/export.h>
11 #include <sound/core.h>
12 #include <sound/control.h>
13 #include <sound/jack.h>
14 #include <sound/hda_codec.h>
15 #include "hda_local.h"
16 #include "hda_auto_parser.h"
17 #include "hda_jack.h"
18 
19 /**
20  * is_jack_detectable - Check whether the given pin is jack-detectable
21  * @codec: the HDA codec
22  * @nid: pin NID
23  *
24  * Check whether the given pin is capable to report the jack detection.
25  * The jack detection might not work by various reasons, e.g. the jack
26  * detection is prohibited in the codec level, the pin config has
27  * AC_DEFCFG_MISC_NO_PRESENCE bit, no unsol support, etc.
28  */
29 bool is_jack_detectable(struct hda_codec *codec, hda_nid_t nid)
30 {
31 	if (codec->no_jack_detect)
32 		return false;
33 	if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_PRES_DETECT))
34 		return false;
35 	if (get_defcfg_misc(snd_hda_codec_get_pincfg(codec, nid)) &
36 	     AC_DEFCFG_MISC_NO_PRESENCE)
37 		return false;
38 	if (!(get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP) &&
39 	    !codec->jackpoll_interval)
40 		return false;
41 	return true;
42 }
43 EXPORT_SYMBOL_GPL(is_jack_detectable);
44 
45 /* execute pin sense measurement */
46 static u32 read_pin_sense(struct hda_codec *codec, hda_nid_t nid, int dev_id)
47 {
48 	u32 pincap;
49 	u32 val;
50 
51 	if (!codec->no_trigger_sense) {
52 		pincap = snd_hda_query_pin_caps(codec, nid);
53 		if (pincap & AC_PINCAP_TRIG_REQ) /* need trigger? */
54 			snd_hda_codec_read(codec, nid, 0,
55 					AC_VERB_SET_PIN_SENSE, 0);
56 	}
57 	val = snd_hda_codec_read(codec, nid, 0,
58 				  AC_VERB_GET_PIN_SENSE, dev_id);
59 	if (codec->inv_jack_detect)
60 		val ^= AC_PINSENSE_PRESENCE;
61 	return val;
62 }
63 
64 /**
65  * snd_hda_jack_tbl_get_mst - query the jack-table entry for the given NID
66  * @codec: the HDA codec
67  * @nid: pin NID to refer to
68  * @dev_id: pin device entry id
69  */
70 struct hda_jack_tbl *
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)
109 {
110 	struct hda_jack_tbl *jack = codec->jacktbl.list;
111 	int i;
112 
113 	if (!nid || !jack)
114 		return NULL;
115 	for (i = 0; i < codec->jacktbl.used; i++, jack++)
116 		if (jack->nid == nid)
117 			return jack;
118 	return NULL;
119 }
120 
121 /**
122  * snd_hda_jack_tbl_new - create a jack-table entry for the given NID
123  * @codec: the HDA codec
124  * @nid: pin NID to assign
125  */
126 static struct hda_jack_tbl *
127 snd_hda_jack_tbl_new(struct hda_codec *codec, hda_nid_t nid, int dev_id)
128 {
129 	struct hda_jack_tbl *jack =
130 		snd_hda_jack_tbl_get_mst(codec, nid, dev_id);
131 	struct hda_jack_tbl *existing_nid_jack =
132 		any_jack_tbl_get_from_nid(codec, nid);
133 
134 	WARN_ON(dev_id != 0 && !codec->dp_mst);
135 
136 	if (jack)
137 		return jack;
138 	jack = snd_array_new(&codec->jacktbl);
139 	if (!jack)
140 		return NULL;
141 	jack->nid = nid;
142 	jack->dev_id = dev_id;
143 	jack->jack_dirty = 1;
144 	if (existing_nid_jack) {
145 		jack->tag = existing_nid_jack->tag;
146 
147 		/*
148 		 * Copy jack_detect from existing_nid_jack to avoid
149 		 * snd_hda_jack_detect_enable_callback_mst() making multiple
150 		 * SET_UNSOLICITED_ENABLE calls on the same pin.
151 		 */
152 		jack->jack_detect = existing_nid_jack->jack_detect;
153 	} else {
154 		jack->tag = codec->jacktbl.used;
155 	}
156 
157 	return jack;
158 }
159 
160 void snd_hda_jack_tbl_clear(struct hda_codec *codec)
161 {
162 	struct hda_jack_tbl *jack = codec->jacktbl.list;
163 	int i;
164 
165 	for (i = 0; i < codec->jacktbl.used; i++, jack++) {
166 		struct hda_jack_callback *cb, *next;
167 
168 		/* free jack instances manually when clearing/reconfiguring */
169 		if (!codec->bus->shutdown && jack->jack)
170 			snd_device_free(codec->card, jack->jack);
171 
172 		for (cb = jack->callback; cb; cb = next) {
173 			next = cb->next;
174 			kfree(cb);
175 		}
176 	}
177 	snd_array_free(&codec->jacktbl);
178 }
179 
180 #define get_jack_plug_state(sense) !!(sense & AC_PINSENSE_PRESENCE)
181 
182 /* update the cached value and notification flag if needed */
183 static void jack_detect_update(struct hda_codec *codec,
184 			       struct hda_jack_tbl *jack)
185 {
186 	if (!jack->jack_dirty)
187 		return;
188 
189 	if (jack->phantom_jack)
190 		jack->pin_sense = AC_PINSENSE_PRESENCE;
191 	else
192 		jack->pin_sense = read_pin_sense(codec, jack->nid,
193 						 jack->dev_id);
194 
195 	/* A gating jack indicates the jack is invalid if gating is unplugged */
196 	if (jack->gating_jack &&
197 	    !snd_hda_jack_detect_mst(codec, jack->gating_jack, jack->dev_id))
198 		jack->pin_sense &= ~AC_PINSENSE_PRESENCE;
199 
200 	jack->jack_dirty = 0;
201 
202 	/* If a jack is gated by this one update it. */
203 	if (jack->gated_jack) {
204 		struct hda_jack_tbl *gated =
205 			snd_hda_jack_tbl_get_mst(codec, jack->gated_jack,
206 						 jack->dev_id);
207 		if (gated) {
208 			gated->jack_dirty = 1;
209 			jack_detect_update(codec, gated);
210 		}
211 	}
212 }
213 
214 /**
215  * snd_hda_set_dirty_all - Mark all the cached as dirty
216  * @codec: the HDA codec
217  *
218  * This function sets the dirty flag to all entries of jack table.
219  * It's called from the resume path in hda_codec.c.
220  */
221 void snd_hda_jack_set_dirty_all(struct hda_codec *codec)
222 {
223 	struct hda_jack_tbl *jack = codec->jacktbl.list;
224 	int i;
225 
226 	for (i = 0; i < codec->jacktbl.used; i++, jack++)
227 		if (jack->nid)
228 			jack->jack_dirty = 1;
229 }
230 EXPORT_SYMBOL_GPL(snd_hda_jack_set_dirty_all);
231 
232 /**
233  * snd_hda_jack_pin_sense - execute pin sense measurement
234  * @codec: the CODEC to sense
235  * @nid: the pin NID to sense
236  *
237  * Execute necessary pin sense measurement and return its Presence Detect,
238  * Impedance, ELD Valid etc. status bits.
239  */
240 u32 snd_hda_jack_pin_sense(struct hda_codec *codec, hda_nid_t nid, int dev_id)
241 {
242 	struct hda_jack_tbl *jack =
243 		snd_hda_jack_tbl_get_mst(codec, nid, dev_id);
244 	if (jack) {
245 		jack_detect_update(codec, jack);
246 		return jack->pin_sense;
247 	}
248 	return read_pin_sense(codec, nid, dev_id);
249 }
250 EXPORT_SYMBOL_GPL(snd_hda_jack_pin_sense);
251 
252 /**
253  * snd_hda_jack_detect_state_mst - query pin Presence Detect status
254  * @codec: the CODEC to sense
255  * @nid: the pin NID to sense
256  * @dev_id: pin device entry id
257  *
258  * Query and return the pin's Presence Detect status, as either
259  * HDA_JACK_NOT_PRESENT, HDA_JACK_PRESENT or HDA_JACK_PHANTOM.
260  */
261 int snd_hda_jack_detect_state_mst(struct hda_codec *codec,
262 				  hda_nid_t nid, int dev_id)
263 {
264 	struct hda_jack_tbl *jack =
265 		snd_hda_jack_tbl_get_mst(codec, nid, dev_id);
266 	if (jack && jack->phantom_jack)
267 		return HDA_JACK_PHANTOM;
268 	else if (snd_hda_jack_pin_sense(codec, nid, dev_id) &
269 		 AC_PINSENSE_PRESENCE)
270 		return HDA_JACK_PRESENT;
271 	else
272 		return HDA_JACK_NOT_PRESENT;
273 }
274 EXPORT_SYMBOL_GPL(snd_hda_jack_detect_state_mst);
275 
276 /**
277  * snd_hda_jack_detect_enable_mst - enable the jack-detection
278  * @codec: the HDA codec
279  * @nid: pin NID to enable
280  * @func: callback function to register
281  * @dev_id: pin device entry id
282  *
283  * In the case of error, the return value will be a pointer embedded with
284  * errno.  Check and handle the return value appropriately with standard
285  * macros such as @IS_ERR() and @PTR_ERR().
286  */
287 struct hda_jack_callback *
288 snd_hda_jack_detect_enable_callback_mst(struct hda_codec *codec, hda_nid_t nid,
289 					int dev_id, hda_jack_callback_fn func)
290 {
291 	struct hda_jack_tbl *jack;
292 	struct hda_jack_callback *callback = NULL;
293 	int err;
294 
295 	jack = snd_hda_jack_tbl_new(codec, nid, dev_id);
296 	if (!jack)
297 		return ERR_PTR(-ENOMEM);
298 	if (func) {
299 		callback = kzalloc(sizeof(*callback), GFP_KERNEL);
300 		if (!callback)
301 			return ERR_PTR(-ENOMEM);
302 		callback->func = func;
303 		callback->nid = jack->nid;
304 		callback->dev_id = jack->dev_id;
305 		callback->next = jack->callback;
306 		jack->callback = callback;
307 	}
308 
309 	if (jack->jack_detect)
310 		return callback; /* already registered */
311 	jack->jack_detect = 1;
312 	if (codec->jackpoll_interval > 0)
313 		return callback; /* No unsol if we're polling instead */
314 	err = snd_hda_codec_write_cache(codec, nid, 0,
315 					 AC_VERB_SET_UNSOLICITED_ENABLE,
316 					 AC_USRSP_EN | jack->tag);
317 	if (err < 0)
318 		return ERR_PTR(err);
319 	return callback;
320 }
321 EXPORT_SYMBOL_GPL(snd_hda_jack_detect_enable_callback_mst);
322 
323 /**
324  * snd_hda_jack_detect_enable - Enable the jack detection on the given pin
325  * @codec: the HDA codec
326  * @nid: pin NID to enable jack detection
327  * @dev_id: pin device entry id
328  *
329  * Enable the jack detection with the default callback.  Returns zero if
330  * successful or a negative error code.
331  */
332 int snd_hda_jack_detect_enable(struct hda_codec *codec, hda_nid_t nid,
333 			       int dev_id)
334 {
335 	return PTR_ERR_OR_ZERO(snd_hda_jack_detect_enable_callback_mst(codec,
336 								       nid,
337 								       dev_id,
338 								       NULL));
339 }
340 EXPORT_SYMBOL_GPL(snd_hda_jack_detect_enable);
341 
342 /**
343  * snd_hda_jack_set_gating_jack - Set gating jack.
344  * @codec: the HDA codec
345  * @gated_nid: gated pin NID
346  * @gating_nid: gating pin NID
347  *
348  * Indicates the gated jack is only valid when the gating jack is plugged.
349  */
350 int snd_hda_jack_set_gating_jack(struct hda_codec *codec, hda_nid_t gated_nid,
351 				 hda_nid_t gating_nid)
352 {
353 	struct hda_jack_tbl *gated = snd_hda_jack_tbl_new(codec, gated_nid, 0);
354 	struct hda_jack_tbl *gating =
355 		snd_hda_jack_tbl_new(codec, gating_nid, 0);
356 
357 	WARN_ON(codec->dp_mst);
358 
359 	if (!gated || !gating)
360 		return -EINVAL;
361 
362 	gated->gating_jack = gating_nid;
363 	gating->gated_jack = gated_nid;
364 
365 	return 0;
366 }
367 EXPORT_SYMBOL_GPL(snd_hda_jack_set_gating_jack);
368 
369 /**
370  * snd_hda_jack_report_sync - sync the states of all jacks and report if changed
371  * @codec: the HDA codec
372  */
373 void snd_hda_jack_report_sync(struct hda_codec *codec)
374 {
375 	struct hda_jack_tbl *jack;
376 	int i, state;
377 
378 	/* update all jacks at first */
379 	jack = codec->jacktbl.list;
380 	for (i = 0; i < codec->jacktbl.used; i++, jack++)
381 		if (jack->nid)
382 			jack_detect_update(codec, jack);
383 
384 	/* report the updated jacks; it's done after updating all jacks
385 	 * to make sure that all gating jacks properly have been set
386 	 */
387 	jack = codec->jacktbl.list;
388 	for (i = 0; i < codec->jacktbl.used; i++, jack++)
389 		if (jack->nid) {
390 			if (!jack->jack || jack->block_report)
391 				continue;
392 			state = jack->button_state;
393 			if (get_jack_plug_state(jack->pin_sense))
394 				state |= jack->type;
395 			snd_jack_report(jack->jack, state);
396 			if (jack->button_state) {
397 				snd_jack_report(jack->jack,
398 						state & ~jack->button_state);
399 				jack->button_state = 0; /* button released */
400 			}
401 		}
402 }
403 EXPORT_SYMBOL_GPL(snd_hda_jack_report_sync);
404 
405 /* guess the jack type from the pin-config */
406 static int get_input_jack_type(struct hda_codec *codec, hda_nid_t nid)
407 {
408 	unsigned int def_conf = snd_hda_codec_get_pincfg(codec, nid);
409 	switch (get_defcfg_device(def_conf)) {
410 	case AC_JACK_LINE_OUT:
411 	case AC_JACK_SPEAKER:
412 		return SND_JACK_LINEOUT;
413 	case AC_JACK_HP_OUT:
414 		return SND_JACK_HEADPHONE;
415 	case AC_JACK_SPDIF_OUT:
416 	case AC_JACK_DIG_OTHER_OUT:
417 		return SND_JACK_AVOUT;
418 	case AC_JACK_MIC_IN:
419 		return SND_JACK_MICROPHONE;
420 	default:
421 		return SND_JACK_LINEIN;
422 	}
423 }
424 
425 static void hda_free_jack_priv(struct snd_jack *jack)
426 {
427 	struct hda_jack_tbl *jacks = jack->private_data;
428 	jacks->nid = 0;
429 	jacks->jack = NULL;
430 }
431 
432 /**
433  * snd_hda_jack_add_kctl_mst - Add a kctl for the given pin
434  * @codec: the HDA codec
435  * @nid: pin NID to assign
436  * @dev_id : pin device entry id
437  * @name: string name for the jack
438  * @phantom_jack: flag to deal as a phantom jack
439  * @type: jack type bits to be reported, 0 for guessing from pincfg
440  * @keymap: optional jack / key mapping
441  *
442  * This assigns a jack-detection kctl to the given pin.  The kcontrol
443  * will have the given name and index.
444  */
445 int snd_hda_jack_add_kctl_mst(struct hda_codec *codec, hda_nid_t nid,
446 			      int dev_id, const char *name, bool phantom_jack,
447 			      int type, const struct hda_jack_keymap *keymap)
448 {
449 	struct hda_jack_tbl *jack;
450 	const struct hda_jack_keymap *map;
451 	int err, state, buttons;
452 
453 	jack = snd_hda_jack_tbl_new(codec, nid, dev_id);
454 	if (!jack)
455 		return 0;
456 	if (jack->jack)
457 		return 0; /* already created */
458 
459 	if (!type)
460 		type = get_input_jack_type(codec, nid);
461 
462 	buttons = 0;
463 	if (keymap) {
464 		for (map = keymap; map->type; map++)
465 			buttons |= map->type;
466 	}
467 
468 	err = snd_jack_new(codec->card, name, type | buttons,
469 			   &jack->jack, true, phantom_jack);
470 	if (err < 0)
471 		return err;
472 
473 	jack->phantom_jack = !!phantom_jack;
474 	jack->type = type;
475 	jack->button_state = 0;
476 	jack->jack->private_data = jack;
477 	jack->jack->private_free = hda_free_jack_priv;
478 	if (keymap) {
479 		for (map = keymap; map->type; map++)
480 			snd_jack_set_key(jack->jack, map->type, map->key);
481 	}
482 
483 	state = snd_hda_jack_detect_mst(codec, nid, dev_id);
484 	snd_jack_report(jack->jack, state ? jack->type : 0);
485 
486 	return 0;
487 }
488 EXPORT_SYMBOL_GPL(snd_hda_jack_add_kctl_mst);
489 
490 static int add_jack_kctl(struct hda_codec *codec, hda_nid_t nid,
491 			 const struct auto_pin_cfg *cfg,
492 			 const char *base_name)
493 {
494 	unsigned int def_conf, conn;
495 	char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
496 	int err;
497 	bool phantom_jack;
498 
499 	WARN_ON(codec->dp_mst);
500 
501 	if (!nid)
502 		return 0;
503 	def_conf = snd_hda_codec_get_pincfg(codec, nid);
504 	conn = get_defcfg_connect(def_conf);
505 	if (conn == AC_JACK_PORT_NONE)
506 		return 0;
507 	phantom_jack = (conn != AC_JACK_PORT_COMPLEX) ||
508 		       !is_jack_detectable(codec, nid);
509 
510 	if (base_name)
511 		strlcpy(name, base_name, sizeof(name));
512 	else
513 		snd_hda_get_pin_label(codec, nid, cfg, name, sizeof(name), NULL);
514 	if (phantom_jack)
515 		/* Example final name: "Internal Mic Phantom Jack" */
516 		strncat(name, " Phantom", sizeof(name) - strlen(name) - 1);
517 	err = snd_hda_jack_add_kctl(codec, nid, name, phantom_jack, 0, NULL);
518 	if (err < 0)
519 		return err;
520 
521 	if (!phantom_jack)
522 		return snd_hda_jack_detect_enable(codec, nid, 0);
523 	return 0;
524 }
525 
526 /**
527  * snd_hda_jack_add_kctls - Add kctls for all pins included in the given pincfg
528  * @codec: the HDA codec
529  * @cfg: pin config table to parse
530  */
531 int snd_hda_jack_add_kctls(struct hda_codec *codec,
532 			   const struct auto_pin_cfg *cfg)
533 {
534 	const hda_nid_t *p;
535 	int i, err;
536 
537 	for (i = 0; i < cfg->num_inputs; i++) {
538 		/* If we have headphone mics; make sure they get the right name
539 		   before grabbed by output pins */
540 		if (cfg->inputs[i].is_headphone_mic) {
541 			if (auto_cfg_hp_outs(cfg) == 1)
542 				err = add_jack_kctl(codec, auto_cfg_hp_pins(cfg)[0],
543 						    cfg, "Headphone Mic");
544 			else
545 				err = add_jack_kctl(codec, cfg->inputs[i].pin,
546 						    cfg, "Headphone Mic");
547 		} else
548 			err = add_jack_kctl(codec, cfg->inputs[i].pin, cfg,
549 					    NULL);
550 		if (err < 0)
551 			return err;
552 	}
553 
554 	for (i = 0, p = cfg->line_out_pins; i < cfg->line_outs; i++, p++) {
555 		err = add_jack_kctl(codec, *p, cfg, NULL);
556 		if (err < 0)
557 			return err;
558 	}
559 	for (i = 0, p = cfg->hp_pins; i < cfg->hp_outs; i++, p++) {
560 		if (*p == *cfg->line_out_pins) /* might be duplicated */
561 			break;
562 		err = add_jack_kctl(codec, *p, cfg, NULL);
563 		if (err < 0)
564 			return err;
565 	}
566 	for (i = 0, p = cfg->speaker_pins; i < cfg->speaker_outs; i++, p++) {
567 		if (*p == *cfg->line_out_pins) /* might be duplicated */
568 			break;
569 		err = add_jack_kctl(codec, *p, cfg, NULL);
570 		if (err < 0)
571 			return err;
572 	}
573 	for (i = 0, p = cfg->dig_out_pins; i < cfg->dig_outs; i++, p++) {
574 		err = add_jack_kctl(codec, *p, cfg, NULL);
575 		if (err < 0)
576 			return err;
577 	}
578 	err = add_jack_kctl(codec, cfg->dig_in_pin, cfg, NULL);
579 	if (err < 0)
580 		return err;
581 	err = add_jack_kctl(codec, cfg->mono_out_pin, cfg, NULL);
582 	if (err < 0)
583 		return err;
584 	return 0;
585 }
586 EXPORT_SYMBOL_GPL(snd_hda_jack_add_kctls);
587 
588 static void call_jack_callback(struct hda_codec *codec, unsigned int res,
589 			       struct hda_jack_tbl *jack)
590 {
591 	struct hda_jack_callback *cb;
592 
593 	for (cb = jack->callback; cb; cb = cb->next) {
594 		cb->jack = jack;
595 		cb->unsol_res = res;
596 		cb->func(codec, cb);
597 	}
598 	if (jack->gated_jack) {
599 		struct hda_jack_tbl *gated =
600 			snd_hda_jack_tbl_get_mst(codec, jack->gated_jack,
601 						 jack->dev_id);
602 		if (gated) {
603 			for (cb = gated->callback; cb; cb = cb->next) {
604 				cb->jack = gated;
605 				cb->unsol_res = res;
606 				cb->func(codec, cb);
607 			}
608 		}
609 	}
610 }
611 
612 /**
613  * snd_hda_jack_unsol_event - Handle an unsolicited event
614  * @codec: the HDA codec
615  * @res: the unsolicited event data
616  */
617 void snd_hda_jack_unsol_event(struct hda_codec *codec, unsigned int res)
618 {
619 	struct hda_jack_tbl *event;
620 	int tag = (res & AC_UNSOL_RES_TAG) >> AC_UNSOL_RES_TAG_SHIFT;
621 
622 	if (codec->dp_mst) {
623 		int dev_entry =
624 			(res & AC_UNSOL_RES_DE) >> AC_UNSOL_RES_DE_SHIFT;
625 
626 		event = snd_hda_jack_tbl_get_from_tag(codec, tag, dev_entry);
627 	} else {
628 		event = snd_hda_jack_tbl_get_from_tag(codec, tag, 0);
629 	}
630 	if (!event)
631 		return;
632 	event->jack_dirty = 1;
633 
634 	call_jack_callback(codec, res, event);
635 	snd_hda_jack_report_sync(codec);
636 }
637 EXPORT_SYMBOL_GPL(snd_hda_jack_unsol_event);
638 
639 /**
640  * snd_hda_jack_poll_all - Poll all jacks
641  * @codec: the HDA codec
642  *
643  * Poll all detectable jacks with dirty flag, update the status, call
644  * callbacks and call snd_hda_jack_report_sync() if any changes are found.
645  */
646 void snd_hda_jack_poll_all(struct hda_codec *codec)
647 {
648 	struct hda_jack_tbl *jack = codec->jacktbl.list;
649 	int i, changes = 0;
650 
651 	for (i = 0; i < codec->jacktbl.used; i++, jack++) {
652 		unsigned int old_sense;
653 		if (!jack->nid || !jack->jack_dirty || jack->phantom_jack)
654 			continue;
655 		old_sense = get_jack_plug_state(jack->pin_sense);
656 		jack_detect_update(codec, jack);
657 		if (old_sense == get_jack_plug_state(jack->pin_sense))
658 			continue;
659 		changes = 1;
660 		call_jack_callback(codec, 0, jack);
661 	}
662 	if (changes)
663 		snd_hda_jack_report_sync(codec);
664 }
665 EXPORT_SYMBOL_GPL(snd_hda_jack_poll_all);
666 
667