// SPDX-License-Identifier: GPL-2.0-or-later /* * Jack-detection handling for HD-audio * * Copyright (c) 2011 Takashi Iwai <[email protected]> */ #include <linux/init.h> #include <linux/slab.h> #include <linux/export.h> #include <sound/core.h> #include <sound/control.h> #include <sound/jack.h> #include <sound/hda_codec.h> #include "hda_local.h" #include "hda_auto_parser.h" #include "hda_jack.h" /** * is_jack_detectable - Check whether the given pin is jack-detectable * @codec: the HDA codec * @nid: pin NID * * Check whether the given pin is capable to report the jack detection. * The jack detection might not work by various reasons, e.g. the jack * detection is prohibited in the codec level, the pin config has * AC_DEFCFG_MISC_NO_PRESENCE bit, no unsol support, etc. */ bool is_jack_detectable(struct hda_codec *codec, hda_nid_t nid) { … } EXPORT_SYMBOL_GPL(…); /* execute pin sense measurement */ static u32 read_pin_sense(struct hda_codec *codec, hda_nid_t nid, int dev_id) { … } /** * snd_hda_jack_tbl_get_mst - query the jack-table entry for the given NID * @codec: the HDA codec * @nid: pin NID to refer to * @dev_id: pin device entry id */ struct hda_jack_tbl * snd_hda_jack_tbl_get_mst(struct hda_codec *codec, hda_nid_t nid, int dev_id) { … } EXPORT_SYMBOL_GPL(…); /** * snd_hda_jack_tbl_get_from_tag - query the jack-table entry for the given tag * @codec: the HDA codec * @tag: tag value to refer to * @dev_id: pin device entry id */ struct hda_jack_tbl * snd_hda_jack_tbl_get_from_tag(struct hda_codec *codec, unsigned char tag, int dev_id) { … } EXPORT_SYMBOL_GPL(…); static struct hda_jack_tbl * any_jack_tbl_get_from_nid(struct hda_codec *codec, hda_nid_t nid) { … } /** * snd_hda_jack_tbl_new - create a jack-table entry for the given NID * @codec: the HDA codec * @nid: pin NID to assign * @dev_id: pin device entry id */ static struct hda_jack_tbl * snd_hda_jack_tbl_new(struct hda_codec *codec, hda_nid_t nid, int dev_id) { … } void snd_hda_jack_tbl_disconnect(struct hda_codec *codec) { … } void snd_hda_jack_tbl_clear(struct hda_codec *codec) { … } #define get_jack_plug_state(sense) … /* update the cached value and notification flag if needed */ static void jack_detect_update(struct hda_codec *codec, struct hda_jack_tbl *jack) { … } /** * snd_hda_jack_set_dirty_all - Mark all the cached as dirty * @codec: the HDA codec * * This function sets the dirty flag to all entries of jack table. * It's called from the resume path in hda_codec.c. */ void snd_hda_jack_set_dirty_all(struct hda_codec *codec) { … } EXPORT_SYMBOL_GPL(…); /** * snd_hda_jack_pin_sense - execute pin sense measurement * @codec: the CODEC to sense * @nid: the pin NID to sense * @dev_id: pin device entry id * * Execute necessary pin sense measurement and return its Presence Detect, * Impedance, ELD Valid etc. status bits. */ u32 snd_hda_jack_pin_sense(struct hda_codec *codec, hda_nid_t nid, int dev_id) { … } EXPORT_SYMBOL_GPL(…); /** * snd_hda_jack_detect_state_mst - query pin Presence Detect status * @codec: the CODEC to sense * @nid: the pin NID to sense * @dev_id: pin device entry id * * Query and return the pin's Presence Detect status, as either * HDA_JACK_NOT_PRESENT, HDA_JACK_PRESENT or HDA_JACK_PHANTOM. */ int snd_hda_jack_detect_state_mst(struct hda_codec *codec, hda_nid_t nid, int dev_id) { … } EXPORT_SYMBOL_GPL(…); static struct hda_jack_callback * find_callback_from_list(struct hda_jack_tbl *jack, hda_jack_callback_fn func) { … } /** * snd_hda_jack_detect_enable_callback_mst - enable the jack-detection * @codec: the HDA codec * @nid: pin NID to enable * @func: callback function to register * @dev_id: pin device entry id * * In the case of error, the return value will be a pointer embedded with * errno. Check and handle the return value appropriately with standard * macros such as @IS_ERR() and @PTR_ERR(). */ struct hda_jack_callback * snd_hda_jack_detect_enable_callback_mst(struct hda_codec *codec, hda_nid_t nid, int dev_id, hda_jack_callback_fn func) { … } EXPORT_SYMBOL_GPL(…); /** * snd_hda_jack_detect_enable - Enable the jack detection on the given pin * @codec: the HDA codec * @nid: pin NID to enable jack detection * @dev_id: pin device entry id * * Enable the jack detection with the default callback. Returns zero if * successful or a negative error code. */ int snd_hda_jack_detect_enable(struct hda_codec *codec, hda_nid_t nid, int dev_id) { … } EXPORT_SYMBOL_GPL(…); /** * snd_hda_jack_set_gating_jack - Set gating jack. * @codec: the HDA codec * @gated_nid: gated pin NID * @gating_nid: gating pin NID * * Indicates the gated jack is only valid when the gating jack is plugged. */ int snd_hda_jack_set_gating_jack(struct hda_codec *codec, hda_nid_t gated_nid, hda_nid_t gating_nid) { … } EXPORT_SYMBOL_GPL(…); /** * snd_hda_jack_bind_keymap - bind keys generated from one NID to another jack. * @codec: the HDA codec * @key_nid: key event is generated by this pin NID * @keymap: map of key type and key code * @jack_nid: key reports to the jack of this pin NID * * This function is used in the case of key is generated from one NID while is * reported to the jack of another NID. */ int snd_hda_jack_bind_keymap(struct hda_codec *codec, hda_nid_t key_nid, const struct hda_jack_keymap *keymap, hda_nid_t jack_nid) { … } EXPORT_SYMBOL_GPL(…); /** * snd_hda_jack_set_button_state - report button event to the hda_jack_tbl button_state. * @codec: the HDA codec * @jack_nid: the button event reports to the jack_tbl of this NID * @button_state: the button event captured by codec * * Codec driver calls this function to report the button event. */ void snd_hda_jack_set_button_state(struct hda_codec *codec, hda_nid_t jack_nid, int button_state) { … } EXPORT_SYMBOL_GPL(…); /** * snd_hda_jack_report_sync - sync the states of all jacks and report if changed * @codec: the HDA codec */ void snd_hda_jack_report_sync(struct hda_codec *codec) { … } EXPORT_SYMBOL_GPL(…); /* guess the jack type from the pin-config */ static int get_input_jack_type(struct hda_codec *codec, hda_nid_t nid) { … } static void hda_free_jack_priv(struct snd_jack *jack) { … } /** * snd_hda_jack_add_kctl_mst - Add a kctl for the given pin * @codec: the HDA codec * @nid: pin NID to assign * @dev_id : pin device entry id * @name: string name for the jack * @phantom_jack: flag to deal as a phantom jack * @type: jack type bits to be reported, 0 for guessing from pincfg * @keymap: optional jack / key mapping * * This assigns a jack-detection kctl to the given pin. The kcontrol * will have the given name and index. */ int snd_hda_jack_add_kctl_mst(struct hda_codec *codec, hda_nid_t nid, int dev_id, const char *name, bool phantom_jack, int type, const struct hda_jack_keymap *keymap) { … } EXPORT_SYMBOL_GPL(…); static int add_jack_kctl(struct hda_codec *codec, hda_nid_t nid, const struct auto_pin_cfg *cfg, const char *base_name) { … } /** * snd_hda_jack_add_kctls - Add kctls for all pins included in the given pincfg * @codec: the HDA codec * @cfg: pin config table to parse */ int snd_hda_jack_add_kctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg) { … } EXPORT_SYMBOL_GPL(…); static void call_jack_callback(struct hda_codec *codec, unsigned int res, struct hda_jack_tbl *jack) { … } /** * snd_hda_jack_unsol_event - Handle an unsolicited event * @codec: the HDA codec * @res: the unsolicited event data */ void snd_hda_jack_unsol_event(struct hda_codec *codec, unsigned int res) { … } EXPORT_SYMBOL_GPL(…); /** * snd_hda_jack_poll_all - Poll all jacks * @codec: the HDA codec * * Poll all detectable jacks with dirty flag, update the status, call * callbacks and call snd_hda_jack_report_sync() if any changes are found. */ void snd_hda_jack_poll_all(struct hda_codec *codec) { … } EXPORT_SYMBOL_GPL(…);