blob: b5983eaea51ef0982e0361831902a049924ba21b [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 */
Takashi Iwai01a61e12011-10-28 00:03:22 +020018 unsigned int jack_cachable:1; /* can be updated via unsol events */
Takashi Iwai1835a0f2011-10-27 22:12:46 +020019 unsigned int jack_dirty:1; /* needs to update? */
Takashi Iwai01a61e12011-10-28 00:03:22 +020020 unsigned int need_notify:1; /* to be notified? */
21 struct snd_kcontrol *kctl; /* assigned kctl for jack-detection */
Takashi Iwai1835a0f2011-10-27 22:12:46 +020022};
23
24struct hda_jack_tbl *
25snd_hda_jack_tbl_get(struct hda_codec *codec, hda_nid_t nid);
26
27struct hda_jack_tbl *
28snd_hda_jack_tbl_new(struct hda_codec *codec, hda_nid_t nid);
29void snd_hda_jack_tbl_clear(struct hda_codec *codec);
30
31/**
32 * snd_hda_jack_set_dirty - set the dirty flag for the given jack-entry
33 *
34 * Call this function when a pin-state may change, e.g. when the hardware
35 * notifies via an unsolicited event.
36 */
37static inline void snd_hda_jack_set_dirty(struct hda_codec *codec,
38 hda_nid_t nid)
39{
40 struct hda_jack_tbl *jack = snd_hda_jack_tbl_get(codec, nid);
41 if (jack)
42 jack->jack_dirty = 1;
43}
44
45void snd_hda_jack_set_dirty_all(struct hda_codec *codec);
46
47int snd_hda_jack_detect_enable(struct hda_codec *codec, hda_nid_t nid,
48 unsigned int tag);
49
50u32 snd_hda_pin_sense(struct hda_codec *codec, hda_nid_t nid);
51int snd_hda_jack_detect(struct hda_codec *codec, hda_nid_t nid);
52
53static inline bool is_jack_detectable(struct hda_codec *codec, hda_nid_t nid)
54{
55 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_PRES_DETECT))
56 return false;
57 if (!codec->ignore_misc_bit &&
58 (get_defcfg_misc(snd_hda_codec_get_pincfg(codec, nid)) &
59 AC_DEFCFG_MISC_NO_PRESENCE))
60 return false;
61 if (!(get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP))
62 return false;
63 return true;
64}
65
Takashi Iwai01a61e12011-10-28 00:03:22 +020066int snd_hda_jack_add_kctl(struct hda_codec *codec, hda_nid_t nid,
67 const char *name, int idx);
68int snd_hda_jack_add_kctls(struct hda_codec *codec,
69 const struct auto_pin_cfg *cfg);
70
71void snd_hda_jack_report(struct hda_codec *codec, hda_nid_t nid);
72void snd_hda_jack_report_sync(struct hda_codec *codec);
73
74
Takashi Iwai1835a0f2011-10-27 22:12:46 +020075#endif /* __SOUND_HDA_JACK_H */