blob: 22fe7ee43e8252eaca92dc0bca9b2b868cc25311 [file] [log] [blame]
Thomas Gleixner62810db2019-05-20 19:08:11 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
Takashi Iwai1835a0f2011-10-27 22:12:46 +02002/*
3 * Jack-detection handling for HD-audio
4 *
5 * Copyright (c) 2011 Takashi Iwai <tiwai@suse.de>
Takashi Iwai1835a0f2011-10-27 22:12:46 +02006 */
7
8#ifndef __SOUND_HDA_JACK_H
9#define __SOUND_HDA_JACK_H
10
David Henningssona5062de2014-09-23 09:04:49 +020011#include <linux/err.h>
Takashi Iwai911761c2018-11-28 14:25:37 +010012#include <sound/jack.h>
David Henningssona5062de2014-09-23 09:04:49 +020013
Takashi Iwai128bc4b2012-05-07 17:42:31 +020014struct auto_pin_cfg;
David Henningsson954df2a2012-09-25 11:30:59 +020015struct hda_jack_tbl;
Takashi Iwai1a4f69d2014-09-11 15:22:46 +020016struct hda_jack_callback;
David Henningsson954df2a2012-09-25 11:30:59 +020017
Takashi Iwai1a4f69d2014-09-11 15:22:46 +020018typedef void (*hda_jack_callback_fn) (struct hda_codec *, struct hda_jack_callback *);
19
20struct hda_jack_callback {
Takashi Iwai2ebab402016-02-09 10:23:52 +010021 hda_nid_t nid;
Takashi Iwai1a4f69d2014-09-11 15:22:46 +020022 hda_jack_callback_fn func;
23 unsigned int private_data; /* arbitrary data */
Takashi Iwaie6ce1802018-11-28 14:17:58 +010024 unsigned int unsol_res; /* unsolicited event bits */
25 struct hda_jack_tbl *jack; /* associated jack entry */
Takashi Iwai1a4f69d2014-09-11 15:22:46 +020026 struct hda_jack_callback *next;
27};
Takashi Iwai128bc4b2012-05-07 17:42:31 +020028
Takashi Iwai1835a0f2011-10-27 22:12:46 +020029struct hda_jack_tbl {
30 hda_nid_t nid;
Takashi Iwai3a938972011-10-28 01:16:55 +020031 unsigned char tag; /* unsol event tag */
Takashi Iwai1a4f69d2014-09-11 15:22:46 +020032 struct hda_jack_callback *callback;
Takashi Iwai3a938972011-10-28 01:16:55 +020033 /* jack-detection stuff */
Takashi Iwai1835a0f2011-10-27 22:12:46 +020034 unsigned int pin_sense; /* cached pin-sense value */
Takashi Iwai3a938972011-10-28 01:16:55 +020035 unsigned int jack_detect:1; /* capable of jack-detection? */
Takashi Iwai1835a0f2011-10-27 22:12:46 +020036 unsigned int jack_dirty:1; /* needs to update? */
David Henningsson80c8bfb2012-06-04 09:33:51 +020037 unsigned int phantom_jack:1; /* a fixed, always present port? */
David Henningsson0f568952013-11-07 13:38:24 +010038 unsigned int block_report:1; /* in a transitional state - do not report to userspace */
Dylan Reid0619ba82012-11-19 19:48:07 +010039 hda_nid_t gating_jack; /* valid when gating jack plugged */
40 hda_nid_t gated_jack; /* gated is dependent on this jack */
Takashi Iwaiaad37db2011-11-02 08:54:51 +010041 int type;
Takashi Iwai911761c2018-11-28 14:25:37 +010042 int button_state;
Takashi Iwaiaad37db2011-11-02 08:54:51 +010043 struct snd_jack *jack;
Takashi Iwai1835a0f2011-10-27 22:12:46 +020044};
45
Takashi Iwai911761c2018-11-28 14:25:37 +010046struct hda_jack_keymap {
47 enum snd_jack_types type;
48 int key;
49};
50
Takashi Iwai1835a0f2011-10-27 22:12:46 +020051struct hda_jack_tbl *
52snd_hda_jack_tbl_get(struct hda_codec *codec, hda_nid_t nid);
Takashi Iwai3a938972011-10-28 01:16:55 +020053struct hda_jack_tbl *
54snd_hda_jack_tbl_get_from_tag(struct hda_codec *codec, unsigned char tag);
Takashi Iwai1835a0f2011-10-27 22:12:46 +020055
Takashi Iwai1835a0f2011-10-27 22:12:46 +020056void snd_hda_jack_tbl_clear(struct hda_codec *codec);
57
Takashi Iwai1835a0f2011-10-27 22:12:46 +020058void snd_hda_jack_set_dirty_all(struct hda_codec *codec);
59
Takashi Iwai62f949b2014-09-11 14:06:53 +020060int snd_hda_jack_detect_enable(struct hda_codec *codec, hda_nid_t nid);
Takashi Iwai1a4f69d2014-09-11 15:22:46 +020061struct hda_jack_callback *
Takashi Iwaibda17b822014-09-11 14:39:09 +020062snd_hda_jack_detect_enable_callback(struct hda_codec *codec, hda_nid_t nid,
Takashi Iwai1a4f69d2014-09-11 15:22:46 +020063 hda_jack_callback_fn cb);
David Henningsson954df2a2012-09-25 11:30:59 +020064
Dylan Reid0619ba82012-11-19 19:48:07 +010065int snd_hda_jack_set_gating_jack(struct hda_codec *codec, hda_nid_t gated_nid,
66 hda_nid_t gating_nid);
Takashi Iwai1835a0f2011-10-27 22:12:46 +020067
68u32 snd_hda_pin_sense(struct hda_codec *codec, hda_nid_t nid);
Takashi Iwai60ea8ca2013-07-19 16:59:46 +020069
70/* the jack state returned from snd_hda_jack_detect_state() */
71enum {
72 HDA_JACK_NOT_PRESENT, HDA_JACK_PRESENT, HDA_JACK_PHANTOM,
73};
74
75int snd_hda_jack_detect_state(struct hda_codec *codec, hda_nid_t nid);
76
Takashi Iwai95a962c2014-10-29 16:03:58 +010077/**
78 * snd_hda_jack_detect - Detect the jack
79 * @codec: the HDA codec
80 * @nid: pin NID to check jack detection
81 */
Takashi Iwai60ea8ca2013-07-19 16:59:46 +020082static 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}
Takashi Iwai1835a0f2011-10-27 22:12:46 +020086
Takashi Iwaia9c74172012-02-13 11:41:42 +010087bool is_jack_detectable(struct hda_codec *codec, hda_nid_t nid);
Takashi Iwai1835a0f2011-10-27 22:12:46 +020088
Takashi Iwai01a61e12011-10-28 00:03:22 +020089int snd_hda_jack_add_kctl(struct hda_codec *codec, hda_nid_t nid,
Takashi Iwai911761c2018-11-28 14:25:37 +010090 const char *name, bool phantom_jack,
91 int type, const struct hda_jack_keymap *keymap);
Takashi Iwai01a61e12011-10-28 00:03:22 +020092int snd_hda_jack_add_kctls(struct hda_codec *codec,
93 const struct auto_pin_cfg *cfg);
94
Takashi Iwai01a61e12011-10-28 00:03:22 +020095void snd_hda_jack_report_sync(struct hda_codec *codec);
96
David Henningsson954df2a2012-09-25 11:30:59 +020097void snd_hda_jack_unsol_event(struct hda_codec *codec, unsigned int res);
Takashi Iwai01a61e12011-10-28 00:03:22 +020098
David Henningsson26a6cb62012-10-09 15:04:21 +020099void snd_hda_jack_poll_all(struct hda_codec *codec);
100
Takashi Iwai1835a0f2011-10-27 22:12:46 +0200101#endif /* __SOUND_HDA_JACK_H */