1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * Jack-detection handling for HD-audio
5 * Copyright (c) 2011 Takashi Iwai <tiwai@suse.de>
8 #ifndef __SOUND_HDA_JACK_H
9 #define __SOUND_HDA_JACK_H
11 #include <linux/err.h>
12 #include <sound/jack.h>
16 struct hda_jack_callback;
18 typedef void (*hda_jack_callback_fn) (struct hda_codec *, struct hda_jack_callback *);
20 struct hda_jack_callback {
22 hda_jack_callback_fn func;
23 unsigned int private_data; /* arbitrary data */
24 unsigned int unsol_res; /* unsolicited event bits */
25 struct hda_jack_tbl *jack; /* associated jack entry */
26 struct hda_jack_callback *next;
31 unsigned char tag; /* unsol event tag */
32 struct hda_jack_callback *callback;
33 /* jack-detection stuff */
34 unsigned int pin_sense; /* cached pin-sense value */
35 unsigned int jack_detect:1; /* capable of jack-detection? */
36 unsigned int jack_dirty:1; /* needs to update? */
37 unsigned int phantom_jack:1; /* a fixed, always present port? */
38 unsigned int block_report:1; /* in a transitional state - do not report to userspace */
39 hda_nid_t gating_jack; /* valid when gating jack plugged */
40 hda_nid_t gated_jack; /* gated is dependent on this jack */
43 struct snd_jack *jack;
46 struct hda_jack_keymap {
47 enum snd_jack_types type;
52 snd_hda_jack_tbl_get(struct hda_codec *codec, hda_nid_t nid);
54 snd_hda_jack_tbl_get_from_tag(struct hda_codec *codec, unsigned char tag);
56 void snd_hda_jack_tbl_clear(struct hda_codec *codec);
58 void snd_hda_jack_set_dirty_all(struct hda_codec *codec);
60 int snd_hda_jack_detect_enable(struct hda_codec *codec, hda_nid_t nid);
61 struct hda_jack_callback *
62 snd_hda_jack_detect_enable_callback(struct hda_codec *codec, hda_nid_t nid,
63 hda_jack_callback_fn cb);
65 int snd_hda_jack_set_gating_jack(struct hda_codec *codec, hda_nid_t gated_nid,
66 hda_nid_t gating_nid);
68 u32 snd_hda_pin_sense(struct hda_codec *codec, hda_nid_t nid);
70 /* the jack state returned from snd_hda_jack_detect_state() */
72 HDA_JACK_NOT_PRESENT, HDA_JACK_PRESENT, HDA_JACK_PHANTOM,
75 int snd_hda_jack_detect_state(struct hda_codec *codec, hda_nid_t nid);
78 * snd_hda_jack_detect - Detect the jack
79 * @codec: the HDA codec
80 * @nid: pin NID to check jack detection
82 static inline bool snd_hda_jack_detect(struct hda_codec *codec, hda_nid_t nid)
84 return snd_hda_jack_detect_state(codec, nid) != HDA_JACK_NOT_PRESENT;
87 bool is_jack_detectable(struct hda_codec *codec, hda_nid_t nid);
89 int snd_hda_jack_add_kctl(struct hda_codec *codec, hda_nid_t nid,
90 const char *name, bool phantom_jack,
91 int type, const struct hda_jack_keymap *keymap);
92 int snd_hda_jack_add_kctls(struct hda_codec *codec,
93 const struct auto_pin_cfg *cfg);
95 void snd_hda_jack_report_sync(struct hda_codec *codec);
97 void snd_hda_jack_unsol_event(struct hda_codec *codec, unsigned int res);
99 void snd_hda_jack_poll_all(struct hda_codec *codec);
101 #endif /* __SOUND_HDA_JACK_H */