Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /*
0003  * Jack-detection handling for HD-audio
0004  *
0005  * Copyright (c) 2011 Takashi Iwai <tiwai@suse.de>
0006  */
0007 
0008 #ifndef __SOUND_HDA_JACK_H
0009 #define __SOUND_HDA_JACK_H
0010 
0011 #include <linux/err.h>
0012 #include <sound/jack.h>
0013 
0014 struct auto_pin_cfg;
0015 struct hda_jack_tbl;
0016 struct hda_jack_callback;
0017 
0018 typedef void (*hda_jack_callback_fn) (struct hda_codec *, struct hda_jack_callback *);
0019 
0020 struct hda_jack_callback {
0021     hda_nid_t nid;
0022     int dev_id;
0023     hda_jack_callback_fn func;
0024     unsigned int private_data;  /* arbitrary data */
0025     unsigned int unsol_res;     /* unsolicited event bits */
0026     struct hda_jack_tbl *jack;  /* associated jack entry */
0027     struct hda_jack_callback *next;
0028 };
0029 
0030 struct hda_jack_tbl {
0031     hda_nid_t nid;
0032     int dev_id;
0033     unsigned char tag;      /* unsol event tag */
0034     struct hda_jack_callback *callback;
0035     /* jack-detection stuff */
0036     unsigned int pin_sense;     /* cached pin-sense value */
0037     unsigned int jack_detect:1; /* capable of jack-detection? */
0038     unsigned int jack_dirty:1;  /* needs to update? */
0039     unsigned int phantom_jack:1;    /* a fixed, always present port? */
0040     unsigned int block_report:1;    /* in a transitional state - do not report to userspace */
0041     hda_nid_t gating_jack;      /* valid when gating jack plugged */
0042     hda_nid_t gated_jack;       /* gated is dependent on this jack */
0043     hda_nid_t key_report_jack;  /* key reports to this jack */
0044     int type;
0045     int button_state;
0046     struct snd_jack *jack;
0047 };
0048 
0049 struct hda_jack_keymap {
0050     enum snd_jack_types type;
0051     int key;
0052 };
0053 
0054 struct hda_jack_tbl *
0055 snd_hda_jack_tbl_get_mst(struct hda_codec *codec, hda_nid_t nid, int dev_id);
0056 
0057 /**
0058  * snd_hda_jack_tbl_get - query the jack-table entry for the given NID
0059  * @codec: the HDA codec
0060  * @nid: pin NID to refer to
0061  */
0062 static inline struct hda_jack_tbl *
0063 snd_hda_jack_tbl_get(struct hda_codec *codec, hda_nid_t nid)
0064 {
0065     return snd_hda_jack_tbl_get_mst(codec, nid, 0);
0066 }
0067 
0068 struct hda_jack_tbl *
0069 snd_hda_jack_tbl_get_from_tag(struct hda_codec *codec,
0070                   unsigned char tag, int dev_id);
0071 
0072 void snd_hda_jack_tbl_disconnect(struct hda_codec *codec);
0073 void snd_hda_jack_tbl_clear(struct hda_codec *codec);
0074 
0075 void snd_hda_jack_set_dirty_all(struct hda_codec *codec);
0076 
0077 int snd_hda_jack_detect_enable(struct hda_codec *codec, hda_nid_t nid,
0078                    int dev_id);
0079 
0080 struct hda_jack_callback *
0081 snd_hda_jack_detect_enable_callback_mst(struct hda_codec *codec, hda_nid_t nid,
0082                     int dev_id, hda_jack_callback_fn func);
0083 
0084 /**
0085  * snd_hda_jack_detect_enable - enable the jack-detection
0086  * @codec: the HDA codec
0087  * @nid: pin NID to enable
0088  * @func: callback function to register
0089  *
0090  * In the case of error, the return value will be a pointer embedded with
0091  * errno.  Check and handle the return value appropriately with standard
0092  * macros such as @IS_ERR() and @PTR_ERR().
0093  */
0094 static inline struct hda_jack_callback *
0095 snd_hda_jack_detect_enable_callback(struct hda_codec *codec, hda_nid_t nid,
0096                     hda_jack_callback_fn cb)
0097 {
0098     return snd_hda_jack_detect_enable_callback_mst(codec, nid, 0, cb);
0099 }
0100 
0101 int snd_hda_jack_set_gating_jack(struct hda_codec *codec, hda_nid_t gated_nid,
0102                  hda_nid_t gating_nid);
0103 
0104 int snd_hda_jack_bind_keymap(struct hda_codec *codec, hda_nid_t key_nid,
0105                  const struct hda_jack_keymap *keymap,
0106                  hda_nid_t jack_nid);
0107 
0108 void snd_hda_jack_set_button_state(struct hda_codec *codec, hda_nid_t jack_nid,
0109                    int button_state);
0110 
0111 u32 snd_hda_jack_pin_sense(struct hda_codec *codec, hda_nid_t nid, int dev_id);
0112 
0113 /* the jack state returned from snd_hda_jack_detect_state() */
0114 enum {
0115     HDA_JACK_NOT_PRESENT, HDA_JACK_PRESENT, HDA_JACK_PHANTOM,
0116 };
0117 
0118 int snd_hda_jack_detect_state_mst(struct hda_codec *codec, hda_nid_t nid,
0119                   int dev_id);
0120 
0121 /**
0122  * snd_hda_jack_detect_state - query pin Presence Detect status
0123  * @codec: the CODEC to sense
0124  * @nid: the pin NID to sense
0125  *
0126  * Query and return the pin's Presence Detect status, as either
0127  * HDA_JACK_NOT_PRESENT, HDA_JACK_PRESENT or HDA_JACK_PHANTOM.
0128  */
0129 static inline int
0130 snd_hda_jack_detect_state(struct hda_codec *codec, hda_nid_t nid)
0131 {
0132     return snd_hda_jack_detect_state_mst(codec, nid, 0);
0133 }
0134 
0135 /**
0136  * snd_hda_jack_detect_mst - Detect the jack
0137  * @codec: the HDA codec
0138  * @nid: pin NID to check jack detection
0139  * @dev_id: pin device entry id
0140  */
0141 static inline bool
0142 snd_hda_jack_detect_mst(struct hda_codec *codec, hda_nid_t nid, int dev_id)
0143 {
0144     return snd_hda_jack_detect_state_mst(codec, nid, dev_id) !=
0145             HDA_JACK_NOT_PRESENT;
0146 }
0147 
0148 /**
0149  * snd_hda_jack_detect - Detect the jack
0150  * @codec: the HDA codec
0151  * @nid: pin NID to check jack detection
0152  */
0153 static inline bool
0154 snd_hda_jack_detect(struct hda_codec *codec, hda_nid_t nid)
0155 {
0156     return snd_hda_jack_detect_mst(codec, nid, 0);
0157 }
0158 
0159 bool is_jack_detectable(struct hda_codec *codec, hda_nid_t nid);
0160 
0161 int snd_hda_jack_add_kctl_mst(struct hda_codec *codec, hda_nid_t nid,
0162                   int dev_id, const char *name, bool phantom_jack,
0163                   int type, const struct hda_jack_keymap *keymap);
0164 
0165 /**
0166  * snd_hda_jack_add_kctl - Add a kctl for the given pin
0167  * @codec: the HDA codec
0168  * @nid: pin NID to assign
0169  * @name: string name for the jack
0170  * @phantom_jack: flag to deal as a phantom jack
0171  * @type: jack type bits to be reported, 0 for guessing from pincfg
0172  * @keymap: optional jack / key mapping
0173  *
0174  * This assigns a jack-detection kctl to the given pin.  The kcontrol
0175  * will have the given name and index.
0176  */
0177 static inline int
0178 snd_hda_jack_add_kctl(struct hda_codec *codec, hda_nid_t nid,
0179               const char *name, bool phantom_jack,
0180               int type, const struct hda_jack_keymap *keymap)
0181 {
0182     return snd_hda_jack_add_kctl_mst(codec, nid, 0,
0183                      name, phantom_jack, type, keymap);
0184 }
0185 
0186 int snd_hda_jack_add_kctls(struct hda_codec *codec,
0187                const struct auto_pin_cfg *cfg);
0188 
0189 void snd_hda_jack_report_sync(struct hda_codec *codec);
0190 
0191 void snd_hda_jack_unsol_event(struct hda_codec *codec, unsigned int res);
0192 
0193 void snd_hda_jack_poll_all(struct hda_codec *codec);
0194 
0195 #endif /* __SOUND_HDA_JACK_H */