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 {
23 hda_jack_callback_fn func;
24 unsigned int private_data; /* arbitrary data */
25 unsigned int unsol_res; /* unsolicited event bits */
26 struct hda_jack_tbl *jack; /* associated jack entry */
27 struct hda_jack_callback *next;
33 unsigned char tag; /* unsol event tag */
34 struct hda_jack_callback *callback;
35 /* jack-detection stuff */
36 unsigned int pin_sense; /* cached pin-sense value */
37 unsigned int jack_detect:1; /* capable of jack-detection? */
38 unsigned int jack_dirty:1; /* needs to update? */
39 unsigned int phantom_jack:1; /* a fixed, always present port? */
40 unsigned int block_report:1; /* in a transitional state - do not report to userspace */
41 hda_nid_t gating_jack; /* valid when gating jack plugged */
42 hda_nid_t gated_jack; /* gated is dependent on this jack */
43 hda_nid_t key_report_jack; /* key reports to this jack */
46 struct snd_jack *jack;
49 struct hda_jack_keymap {
50 enum snd_jack_types type;
55 snd_hda_jack_tbl_get_mst(struct hda_codec *codec, hda_nid_t nid, int dev_id);
58 * snd_hda_jack_tbl_get - query the jack-table entry for the given NID
59 * @codec: the HDA codec
60 * @nid: pin NID to refer to
62 static inline struct hda_jack_tbl *
63 snd_hda_jack_tbl_get(struct hda_codec *codec, hda_nid_t nid)
65 return snd_hda_jack_tbl_get_mst(codec, nid, 0);
69 snd_hda_jack_tbl_get_from_tag(struct hda_codec *codec,
70 unsigned char tag, int dev_id);
72 void snd_hda_jack_tbl_clear(struct hda_codec *codec);
74 void snd_hda_jack_set_dirty_all(struct hda_codec *codec);
76 int snd_hda_jack_detect_enable(struct hda_codec *codec, hda_nid_t nid,
79 struct hda_jack_callback *
80 snd_hda_jack_detect_enable_callback_mst(struct hda_codec *codec, hda_nid_t nid,
81 int dev_id, hda_jack_callback_fn func);
84 * snd_hda_jack_detect_enable - enable the jack-detection
85 * @codec: the HDA codec
86 * @nid: pin NID to enable
87 * @func: callback function to register
89 * In the case of error, the return value will be a pointer embedded with
90 * errno. Check and handle the return value appropriately with standard
91 * macros such as @IS_ERR() and @PTR_ERR().
93 static inline struct hda_jack_callback *
94 snd_hda_jack_detect_enable_callback(struct hda_codec *codec, hda_nid_t nid,
95 hda_jack_callback_fn cb)
97 return snd_hda_jack_detect_enable_callback_mst(codec, nid, 0, cb);
100 int snd_hda_jack_set_gating_jack(struct hda_codec *codec, hda_nid_t gated_nid,
101 hda_nid_t gating_nid);
103 int snd_hda_jack_bind_keymap(struct hda_codec *codec, hda_nid_t key_nid,
104 const struct hda_jack_keymap *keymap,
107 void snd_hda_jack_set_button_state(struct hda_codec *codec, hda_nid_t jack_nid,
110 u32 snd_hda_jack_pin_sense(struct hda_codec *codec, hda_nid_t nid, int dev_id);
112 /* the jack state returned from snd_hda_jack_detect_state() */
114 HDA_JACK_NOT_PRESENT, HDA_JACK_PRESENT, HDA_JACK_PHANTOM,
117 int snd_hda_jack_detect_state_mst(struct hda_codec *codec, hda_nid_t nid,
121 * snd_hda_jack_detect_state - query pin Presence Detect status
122 * @codec: the CODEC to sense
123 * @nid: the pin NID to sense
125 * Query and return the pin's Presence Detect status, as either
126 * HDA_JACK_NOT_PRESENT, HDA_JACK_PRESENT or HDA_JACK_PHANTOM.
129 snd_hda_jack_detect_state(struct hda_codec *codec, hda_nid_t nid)
131 return snd_hda_jack_detect_state_mst(codec, nid, 0);
135 * snd_hda_jack_detect_mst - Detect the jack
136 * @codec: the HDA codec
137 * @nid: pin NID to check jack detection
138 * @dev_id: pin device entry id
141 snd_hda_jack_detect_mst(struct hda_codec *codec, hda_nid_t nid, int dev_id)
143 return snd_hda_jack_detect_state_mst(codec, nid, dev_id) !=
144 HDA_JACK_NOT_PRESENT;
148 * snd_hda_jack_detect - Detect the jack
149 * @codec: the HDA codec
150 * @nid: pin NID to check jack detection
153 snd_hda_jack_detect(struct hda_codec *codec, hda_nid_t nid)
155 return snd_hda_jack_detect_mst(codec, nid, 0);
158 bool is_jack_detectable(struct hda_codec *codec, hda_nid_t nid);
160 int snd_hda_jack_add_kctl_mst(struct hda_codec *codec, hda_nid_t nid,
161 int dev_id, const char *name, bool phantom_jack,
162 int type, const struct hda_jack_keymap *keymap);
165 * snd_hda_jack_add_kctl - Add a kctl for the given pin
166 * @codec: the HDA codec
167 * @nid: pin NID to assign
168 * @name: string name for the jack
169 * @phantom_jack: flag to deal as a phantom jack
170 * @type: jack type bits to be reported, 0 for guessing from pincfg
171 * @keymap: optional jack / key mapping
173 * This assigns a jack-detection kctl to the given pin. The kcontrol
174 * will have the given name and index.
177 snd_hda_jack_add_kctl(struct hda_codec *codec, hda_nid_t nid,
178 const char *name, bool phantom_jack,
179 int type, const struct hda_jack_keymap *keymap)
181 return snd_hda_jack_add_kctl_mst(codec, nid, 0,
182 name, phantom_jack, type, keymap);
185 int snd_hda_jack_add_kctls(struct hda_codec *codec,
186 const struct auto_pin_cfg *cfg);
188 void snd_hda_jack_report_sync(struct hda_codec *codec);
190 void snd_hda_jack_unsol_event(struct hda_codec *codec, unsigned int res);
192 void snd_hda_jack_poll_all(struct hda_codec *codec);
194 #endif /* __SOUND_HDA_JACK_H */