xref: /openbmc/linux/sound/pci/hda/hda_jack.h (revision f519f0be)
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 #ifndef __SOUND_HDA_JACK_H
9 #define __SOUND_HDA_JACK_H
10 
11 #include <linux/err.h>
12 #include <sound/jack.h>
13 
14 struct auto_pin_cfg;
15 struct hda_jack_tbl;
16 struct hda_jack_callback;
17 
18 typedef void (*hda_jack_callback_fn) (struct hda_codec *, struct hda_jack_callback *);
19 
20 struct hda_jack_callback {
21 	hda_nid_t nid;
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;
27 };
28 
29 struct hda_jack_tbl {
30 	hda_nid_t nid;
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 */
41 	int type;
42 	int button_state;
43 	struct snd_jack *jack;
44 };
45 
46 struct hda_jack_keymap {
47 	enum snd_jack_types type;
48 	int key;
49 };
50 
51 struct hda_jack_tbl *
52 snd_hda_jack_tbl_get(struct hda_codec *codec, hda_nid_t nid);
53 struct hda_jack_tbl *
54 snd_hda_jack_tbl_get_from_tag(struct hda_codec *codec, unsigned char tag);
55 
56 void snd_hda_jack_tbl_clear(struct hda_codec *codec);
57 
58 void snd_hda_jack_set_dirty_all(struct hda_codec *codec);
59 
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);
64 
65 int snd_hda_jack_set_gating_jack(struct hda_codec *codec, hda_nid_t gated_nid,
66 				 hda_nid_t gating_nid);
67 
68 u32 snd_hda_pin_sense(struct hda_codec *codec, hda_nid_t nid);
69 
70 /* the jack state returned from snd_hda_jack_detect_state() */
71 enum {
72 	HDA_JACK_NOT_PRESENT, HDA_JACK_PRESENT, HDA_JACK_PHANTOM,
73 };
74 
75 int snd_hda_jack_detect_state(struct hda_codec *codec, hda_nid_t nid);
76 
77 /**
78  * snd_hda_jack_detect - Detect the jack
79  * @codec: the HDA codec
80  * @nid: pin NID to check jack detection
81  */
82 static inline bool snd_hda_jack_detect(struct hda_codec *codec, hda_nid_t nid)
83 {
84 	return snd_hda_jack_detect_state(codec, nid) != HDA_JACK_NOT_PRESENT;
85 }
86 
87 bool is_jack_detectable(struct hda_codec *codec, hda_nid_t nid);
88 
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);
94 
95 void snd_hda_jack_report_sync(struct hda_codec *codec);
96 
97 void snd_hda_jack_unsol_event(struct hda_codec *codec, unsigned int res);
98 
99 void snd_hda_jack_poll_all(struct hda_codec *codec);
100 
101 #endif /* __SOUND_HDA_JACK_H */
102