blob: 5c1bcb8cf56535006ad0f387c585c7edcfd00111 [file] [log] [blame]
Takashi Iwai1835a0f2011-10-27 22:12:46 +02001/*
2 * Jack-detection handling for HD-audio
3 *
4 * 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 */
11
12#ifndef __SOUND_HDA_JACK_H
13#define __SOUND_HDA_JACK_H
14
15struct hda_jack_tbl {
16 hda_nid_t nid;
17 unsigned int pin_sense; /* cached pin-sense value */
18 unsigned int jack_dirty:1; /* needs to update? */
19};
20
21struct hda_jack_tbl *
22snd_hda_jack_tbl_get(struct hda_codec *codec, hda_nid_t nid);
23
24struct hda_jack_tbl *
25snd_hda_jack_tbl_new(struct hda_codec *codec, hda_nid_t nid);
26void snd_hda_jack_tbl_clear(struct hda_codec *codec);
27
28/**
29 * snd_hda_jack_set_dirty - set the dirty flag for the given jack-entry
30 *
31 * Call this function when a pin-state may change, e.g. when the hardware
32 * notifies via an unsolicited event.
33 */
34static inline void snd_hda_jack_set_dirty(struct hda_codec *codec,
35 hda_nid_t nid)
36{
37 struct hda_jack_tbl *jack = snd_hda_jack_tbl_get(codec, nid);
38 if (jack)
39 jack->jack_dirty = 1;
40}
41
42void snd_hda_jack_set_dirty_all(struct hda_codec *codec);
43
44int snd_hda_jack_detect_enable(struct hda_codec *codec, hda_nid_t nid,
45 unsigned int tag);
46
47u32 snd_hda_pin_sense(struct hda_codec *codec, hda_nid_t nid);
48int snd_hda_jack_detect(struct hda_codec *codec, hda_nid_t nid);
49
50static inline bool is_jack_detectable(struct hda_codec *codec, hda_nid_t nid)
51{
52 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_PRES_DETECT))
53 return false;
54 if (!codec->ignore_misc_bit &&
55 (get_defcfg_misc(snd_hda_codec_get_pincfg(codec, nid)) &
56 AC_DEFCFG_MISC_NO_PRESENCE))
57 return false;
58 if (!(get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP))
59 return false;
60 return true;
61}
62
63#endif /* __SOUND_HDA_JACK_H */