/** * 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)
{ if (codec->no_jack_detect) returnfalse; if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_PRES_DETECT)) returnfalse; if (get_defcfg_misc(snd_hda_codec_get_pincfg(codec, nid)) &
AC_DEFCFG_MISC_NO_PRESENCE) returnfalse; if (!(get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP) &&
!codec->jackpoll_interval) returnfalse; returntrue;
}
EXPORT_SYMBOL_GPL(is_jack_detectable);
/* execute pin sense measurement */ static u32 read_pin_sense(struct hda_codec *codec, hda_nid_t nid, int dev_id)
{
u32 pincap;
u32 val;
if (!codec->no_trigger_sense) {
pincap = snd_hda_query_pin_caps(codec, nid); if (pincap & AC_PINCAP_TRIG_REQ) /* need trigger? */
snd_hda_codec_read(codec, nid, 0,
AC_VERB_SET_PIN_SENSE, 0);
}
val = snd_hda_codec_read(codec, nid, 0,
AC_VERB_GET_PIN_SENSE, dev_id); if (codec->inv_jack_detect)
val ^= AC_PINSENSE_PRESENCE; return val;
}
/** * 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)
{ struct hda_jack_tbl *jack = codec->jacktbl.list; int i;
if (!nid || !jack) return NULL; for (i = 0; i < codec->jacktbl.used; i++, jack++) if (jack->nid == nid && jack->dev_id == dev_id) return jack; return NULL;
}
EXPORT_SYMBOL_GPL(snd_hda_jack_tbl_get_mst);
/** * 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, unsignedchar tag, int dev_id)
{ struct hda_jack_tbl *jack = codec->jacktbl.list; int i;
if (!tag || !jack) return NULL; for (i = 0; i < codec->jacktbl.used; i++, jack++) if (jack->tag == tag && jack->dev_id == dev_id) return jack; return NULL;
}
EXPORT_SYMBOL_GPL(snd_hda_jack_tbl_get_from_tag);
if (!nid || !jack) return NULL; for (i = 0; i < codec->jacktbl.used; i++, jack++) if (jack->nid == nid) return jack; return NULL;
}
/** * 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
*/ staticstruct hda_jack_tbl *
snd_hda_jack_tbl_new(struct hda_codec *codec, hda_nid_t nid, int dev_id)
{ struct hda_jack_tbl *jack =
snd_hda_jack_tbl_get_mst(codec, nid, dev_id); struct hda_jack_tbl *existing_nid_jack =
any_jack_tbl_get_from_nid(codec, nid);
WARN_ON(dev_id != 0 && !codec->dp_mst);
if (jack) return jack;
jack = snd_array_new(&codec->jacktbl); if (!jack) return NULL;
jack->nid = nid;
jack->dev_id = dev_id;
jack->jack_dirty = 1; if (existing_nid_jack) {
jack->tag = existing_nid_jack->tag;
/* * Copy jack_detect from existing_nid_jack to avoid * snd_hda_jack_detect_enable_callback_mst() making multiple * SET_UNSOLICITED_ENABLE calls on the same pin.
*/
jack->jack_detect = existing_nid_jack->jack_detect;
} else {
jack->tag = codec->jacktbl.used;
}
/* update the cached value and notification flag if needed */ staticvoid jack_detect_update(struct hda_codec *codec, struct hda_jack_tbl *jack)
{ if (!jack->jack_dirty) return;
/* A gating jack indicates the jack is invalid if gating is unplugged */ if (jack->gating_jack &&
!snd_hda_jack_detect_mst(codec, jack->gating_jack, jack->dev_id))
jack->pin_sense &= ~AC_PINSENSE_PRESENCE;
jack->jack_dirty = 0;
/* If a jack is gated by this one update it. */ if (jack->gated_jack) { struct hda_jack_tbl *gated =
snd_hda_jack_tbl_get_mst(codec, jack->gated_jack,
jack->dev_id); if (gated) {
gated->jack_dirty = 1;
jack_detect_update(codec, gated);
}
}
}
/** * 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)
{ struct hda_jack_tbl *jack = codec->jacktbl.list; int i;
for (i = 0; i < codec->jacktbl.used; i++, jack++) if (jack->nid)
jack->jack_dirty = 1;
}
EXPORT_SYMBOL_GPL(snd_hda_jack_set_dirty_all);
/** * 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)
{ struct hda_jack_tbl *jack =
snd_hda_jack_tbl_get_mst(codec, nid, dev_id); if (jack) {
jack_detect_update(codec, jack); return jack->pin_sense;
} return read_pin_sense(codec, nid, dev_id);
}
EXPORT_SYMBOL_GPL(snd_hda_jack_pin_sense);
/** * 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)
{ struct hda_jack_tbl *jack =
snd_hda_jack_tbl_get_mst(codec, nid, dev_id); if (jack && jack->phantom_jack) return HDA_JACK_PHANTOM; elseif (snd_hda_jack_pin_sense(codec, nid, dev_id) &
AC_PINSENSE_PRESENCE) return HDA_JACK_PRESENT; else return HDA_JACK_NOT_PRESENT;
}
EXPORT_SYMBOL_GPL(snd_hda_jack_detect_state_mst);
for (cb = jack->callback; cb; cb = cb->next) { if (cb->func == func) return cb;
}
return NULL;
}
/** * 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)
{ struct hda_jack_tbl *jack; struct hda_jack_callback *callback = NULL; int err;
jack = snd_hda_jack_tbl_new(codec, nid, dev_id); if (!jack) return ERR_PTR(-ENOMEM);
if (jack->jack_detect) return callback; /* already registered */
jack->jack_detect = 1; if (codec->jackpoll_interval > 0) return callback; /* No unsol if we're polling instead */
err = snd_hda_codec_write_cache(codec, nid, 0,
AC_VERB_SET_UNSOLICITED_ENABLE,
AC_USRSP_EN | jack->tag); if (err < 0) return ERR_PTR(err); return callback;
}
EXPORT_SYMBOL_GPL(snd_hda_jack_detect_enable_callback_mst);
/** * 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)
{ return PTR_ERR_OR_ZERO(snd_hda_jack_detect_enable_callback_mst(codec,
nid,
dev_id,
NULL));
}
EXPORT_SYMBOL_GPL(snd_hda_jack_detect_enable);
/** * 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)
{ struct hda_jack_tbl *gated = snd_hda_jack_tbl_new(codec, gated_nid, 0); struct hda_jack_tbl *gating =
snd_hda_jack_tbl_new(codec, gating_nid, 0);
/** * 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, conststruct hda_jack_keymap *keymap,
hda_nid_t jack_nid)
{ conststruct hda_jack_keymap *map; struct hda_jack_tbl *key_gen = snd_hda_jack_tbl_get(codec, key_nid); struct hda_jack_tbl *report_to = snd_hda_jack_tbl_get(codec, jack_nid);
WARN_ON(codec->dp_mst);
if (!key_gen || !report_to || !report_to->jack) return -EINVAL;
key_gen->key_report_jack = jack_nid;
if (keymap) for (map = keymap; map->type; map++)
snd_jack_set_key(report_to->jack, map->type, map->key);
/** * 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)
{ struct hda_jack_tbl *jack = snd_hda_jack_tbl_get(codec, jack_nid);
if (!jack) return;
if (jack->key_report_jack) { struct hda_jack_tbl *report_to =
snd_hda_jack_tbl_get(codec, jack->key_report_jack);
if (report_to) {
report_to->button_state = button_state; return;
}
}
/** * 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)
{ struct hda_jack_tbl *jack; int i, state;
/* update all jacks at first */
jack = codec->jacktbl.list; for (i = 0; i < codec->jacktbl.used; i++, jack++) if (jack->nid)
jack_detect_update(codec, jack);
/* report the updated jacks; it's done after updating all jacks * to make sure that all gating jacks properly have been set
*/
jack = codec->jacktbl.list; for (i = 0; i < codec->jacktbl.used; i++, jack++) if (jack->nid) { if (!jack->jack || jack->block_report) continue;
state = jack->button_state; if (get_jack_plug_state(jack->pin_sense))
state |= jack->type;
snd_jack_report(jack->jack, state); if (jack->button_state) {
snd_jack_report(jack->jack,
state & ~jack->button_state);
jack->button_state = 0; /* button released */
}
}
}
EXPORT_SYMBOL_GPL(snd_hda_jack_report_sync);
/* guess the jack type from the pin-config */ staticint get_input_jack_type(struct hda_codec *codec, hda_nid_t nid)
{ unsignedint def_conf = snd_hda_codec_get_pincfg(codec, nid); switch (get_defcfg_device(def_conf)) { case AC_JACK_LINE_OUT: case AC_JACK_SPEAKER: return SND_JACK_LINEOUT; case AC_JACK_HP_OUT: return SND_JACK_HEADPHONE; case AC_JACK_SPDIF_OUT: case AC_JACK_DIG_OTHER_OUT: return SND_JACK_AVOUT; case AC_JACK_MIC_IN: return SND_JACK_MICROPHONE; default: return SND_JACK_LINEIN;
}
}
/** * 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, constchar *name, bool phantom_jack, int type, conststruct hda_jack_keymap *keymap)
{ struct hda_jack_tbl *jack; conststruct hda_jack_keymap *map; int err, state, buttons;
jack = snd_hda_jack_tbl_new(codec, nid, dev_id); if (!jack) return 0; if (jack->jack) return 0; /* already created */
if (!type)
type = get_input_jack_type(codec, nid);
buttons = 0; if (keymap) { for (map = keymap; map->type; map++)
buttons |= map->type;
}
err = snd_jack_new(codec->card, name, type | buttons,
&jack->jack, true, phantom_jack); if (err < 0) return err;
if (base_name)
strscpy(name, base_name, sizeof(name)); else
snd_hda_get_pin_label(codec, nid, cfg, name, sizeof(name), NULL); if (phantom_jack) /* Example final name: "Internal Mic Phantom Jack" */
strncat(name, " Phantom", sizeof(name) - strlen(name) - 1);
err = snd_hda_jack_add_kctl(codec, nid, name, phantom_jack, 0, NULL); if (err < 0) return err;
if (!phantom_jack) return snd_hda_jack_detect_enable(codec, nid, 0); return 0;
}
/** * 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, conststruct auto_pin_cfg *cfg)
{ const hda_nid_t *p; int i, err;
for (i = 0; i < cfg->num_inputs; i++) { /* If we have headphone mics; make sure they get the right name
before grabbed by output pins */ if (cfg->inputs[i].is_headphone_mic) { if (auto_cfg_hp_outs(cfg) == 1)
err = add_jack_kctl(codec, auto_cfg_hp_pins(cfg)[0],
cfg, "Headphone Mic"); else
err = add_jack_kctl(codec, cfg->inputs[i].pin,
cfg, "Headphone Mic");
} else
err = add_jack_kctl(codec, cfg->inputs[i].pin, cfg,
NULL); if (err < 0) return err;
}
for (i = 0, p = cfg->line_out_pins; i < cfg->line_outs; i++, p++) {
err = add_jack_kctl(codec, *p, cfg, NULL); if (err < 0) return err;
} for (i = 0, p = cfg->hp_pins; i < cfg->hp_outs; i++, p++) { if (*p == *cfg->line_out_pins) /* might be duplicated */ break;
err = add_jack_kctl(codec, *p, cfg, NULL); if (err < 0) return err;
} for (i = 0, p = cfg->speaker_pins; i < cfg->speaker_outs; i++, p++) { if (*p == *cfg->line_out_pins) /* might be duplicated */ break;
err = add_jack_kctl(codec, *p, cfg, NULL); if (err < 0) return err;
} for (i = 0, p = cfg->dig_out_pins; i < cfg->dig_outs; i++, p++) {
err = add_jack_kctl(codec, *p, cfg, NULL); if (err < 0) return err;
}
err = add_jack_kctl(codec, cfg->dig_in_pin, cfg, NULL); if (err < 0) return err;
err = add_jack_kctl(codec, cfg->mono_out_pin, cfg, NULL); if (err < 0) return err; return 0;
}
EXPORT_SYMBOL_GPL(snd_hda_jack_add_kctls);
/** * 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)
{ struct hda_jack_tbl *jack = codec->jacktbl.list; int i, changes = 0;
for (i = 0; i < codec->jacktbl.used; i++, jack++) { unsignedint old_sense; if (!jack->nid || !jack->jack_dirty || jack->phantom_jack) continue;
old_sense = get_jack_plug_state(jack->pin_sense);
jack_detect_update(codec, jack); if (old_sense == get_jack_plug_state(jack->pin_sense)) continue;
changes = 1;
call_jack_callback(codec, 0, jack);
} if (changes)
snd_hda_jack_report_sync(codec);
}
EXPORT_SYMBOL_GPL(snd_hda_jack_poll_all);
Messung V0.5
¤ Dauer der Verarbeitung: 0.16 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.