1724
1725
EXPORT_SYMBOL_HDA(snd_hda_override_pin_caps);
1727
* snd_hda_pin_sense - execute pin sense measurement
1728
* @codec: the CODEC to sense
1729
* @nid: the pin NID to sense
1731
* Execute necessary pin sense measurement and return its Presence Detect,
1732
* Impedance, ELD Valid etc. status bits.
1734
u32 snd_hda_pin_sense(struct hda_codec *codec, hda_nid_t nid)
1738
if (!codec->no_trigger_sense) {
1739
pincap = snd_hda_query_pin_caps(codec, nid);
1740
if (pincap & AC_PINCAP_TRIG_REQ) /* need trigger? */
1741
snd_hda_codec_read(codec, nid, 0,
1742
AC_VERB_SET_PIN_SENSE, 0);
1744
return snd_hda_codec_read(codec, nid, 0,
1745
AC_VERB_GET_PIN_SENSE, 0);
1747
EXPORT_SYMBOL_HDA(snd_hda_pin_sense);
1750
* snd_hda_jack_detect - query pin Presence Detect status
1751
* @codec: the CODEC to sense
1752
* @nid: the pin NID to sense
1754
* Query and return the pin's Presence Detect status.
1756
int snd_hda_jack_detect(struct hda_codec *codec, hda_nid_t nid)
1758
u32 sense = snd_hda_pin_sense(codec, nid);
1759
return !!(sense & AC_PINSENSE_PRESENCE);
1761
EXPORT_SYMBOL_HDA(snd_hda_jack_detect);
1764
1728
* read the current volume to info
1765
1729
* if the cache exists, read the cache value.
5102
5067
EXPORT_SYMBOL_HDA(hda_get_autocfg_input_label);
5069
/* return the position of NID in the list, or -1 if not found */
5070
static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
5073
for (i = 0; i < nums; i++)
5079
/* get a unique suffix or an index number */
5080
static const char *check_output_sfx(hda_nid_t nid, const hda_nid_t *pins,
5081
int num_pins, int *indexp)
5083
static const char * const channel_sfx[] = {
5084
" Front", " Surround", " CLFE", " Side"
5088
i = find_idx_in_nid_list(nid, pins, num_pins);
5093
if (num_pins > ARRAY_SIZE(channel_sfx)) {
5098
return channel_sfx[i];
5101
static int fill_audio_out_name(struct hda_codec *codec, hda_nid_t nid,
5102
const struct auto_pin_cfg *cfg,
5103
const char *name, char *label, int maxlen,
5106
unsigned int def_conf = snd_hda_codec_get_pincfg(codec, nid);
5107
int attr = snd_hda_get_input_pin_attr(def_conf);
5108
const char *pfx = "", *sfx = "";
5110
/* handle as a speaker if it's a fixed line-out */
5111
if (!strcmp(name, "Line-Out") && attr == INPUT_PIN_ATTR_INT)
5113
/* check the location */
5115
case INPUT_PIN_ATTR_DOCK:
5118
case INPUT_PIN_ATTR_FRONT:
5123
/* try to give a unique suffix if needed */
5124
sfx = check_output_sfx(nid, cfg->line_out_pins, cfg->line_outs,
5127
sfx = check_output_sfx(nid, cfg->speaker_pins, cfg->speaker_outs,
5130
/* don't add channel suffix for Headphone controls */
5131
int idx = find_idx_in_nid_list(nid, cfg->hp_pins,
5138
snprintf(label, maxlen, "%s%s%s", pfx, name, sfx);
5143
* snd_hda_get_pin_label - Get a label for the given I/O pin
5145
* Get a label for the given pin. This function works for both input and
5146
* output pins. When @cfg is given as non-NULL, the function tries to get
5147
* an optimized label using hda_get_autocfg_input_label().
5149
* This function tries to give a unique label string for the pin as much as
5150
* possible. For example, when the multiple line-outs are present, it adds
5151
* the channel suffix like "Front", "Surround", etc (only when @cfg is given).
5152
* If no unique name with a suffix is available and @indexp is non-NULL, the
5153
* index number is stored in the pointer.
5155
int snd_hda_get_pin_label(struct hda_codec *codec, hda_nid_t nid,
5156
const struct auto_pin_cfg *cfg,
5157
char *label, int maxlen, int *indexp)
5159
unsigned int def_conf = snd_hda_codec_get_pincfg(codec, nid);
5160
const char *name = NULL;
5165
if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
5168
switch (get_defcfg_device(def_conf)) {
5169
case AC_JACK_LINE_OUT:
5170
return fill_audio_out_name(codec, nid, cfg, "Line-Out",
5171
label, maxlen, indexp);
5172
case AC_JACK_SPEAKER:
5173
return fill_audio_out_name(codec, nid, cfg, "Speaker",
5174
label, maxlen, indexp);
5175
case AC_JACK_HP_OUT:
5176
return fill_audio_out_name(codec, nid, cfg, "Headphone",
5177
label, maxlen, indexp);
5178
case AC_JACK_SPDIF_OUT:
5179
case AC_JACK_DIG_OTHER_OUT:
5180
if (get_defcfg_location(def_conf) == AC_JACK_LOC_HDMI)
5184
if (cfg && indexp) {
5185
i = find_idx_in_nid_list(nid, cfg->dig_out_pins,
5193
for (i = 0; i < cfg->num_inputs; i++) {
5194
if (cfg->inputs[i].pin != nid)
5196
name = hda_get_autocfg_input_label(codec, cfg, i);
5202
name = hda_get_input_pin_label(codec, nid, true);
5207
strlcpy(label, name, maxlen);
5210
EXPORT_SYMBOL_HDA(snd_hda_get_pin_label);
5105
5213
* snd_hda_add_imux_item - Add an item to input_mux
5253
5361
EXPORT_SYMBOL_HDA(snd_print_pcm_bits);
5255
#ifdef CONFIG_SND_HDA_INPUT_JACK
5257
* Input-jack notification support
5259
struct hda_jack_item {
5262
struct snd_jack *jack;
5265
static const char *get_jack_default_name(struct hda_codec *codec, hda_nid_t nid,
5269
case SND_JACK_HEADPHONE:
5271
case SND_JACK_MICROPHONE:
5273
case SND_JACK_LINEOUT:
5275
case SND_JACK_LINEIN:
5277
case SND_JACK_HEADSET:
5279
case SND_JACK_VIDEOOUT:
5286
static void hda_free_jack_priv(struct snd_jack *jack)
5288
struct hda_jack_item *jacks = jack->private_data;
5293
int snd_hda_input_jack_add(struct hda_codec *codec, hda_nid_t nid, int type,
5296
struct hda_jack_item *jack;
5299
snd_array_init(&codec->jacks, sizeof(*jack), 32);
5300
jack = snd_array_new(&codec->jacks);
5307
name = get_jack_default_name(codec, nid, type);
5308
err = snd_jack_new(codec->bus->card, name, type, &jack->jack);
5313
jack->jack->private_data = jack;
5314
jack->jack->private_free = hda_free_jack_priv;
5317
EXPORT_SYMBOL_HDA(snd_hda_input_jack_add);
5319
void snd_hda_input_jack_report(struct hda_codec *codec, hda_nid_t nid)
5321
struct hda_jack_item *jacks = codec->jacks.list;
5327
for (i = 0; i < codec->jacks.used; i++, jacks++) {
5328
unsigned int pin_ctl;
5329
unsigned int present;
5332
if (jacks->nid != nid)
5334
present = snd_hda_jack_detect(codec, nid);
5336
if (type == (SND_JACK_HEADPHONE | SND_JACK_LINEOUT)) {
5337
pin_ctl = snd_hda_codec_read(codec, nid, 0,
5338
AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5339
type = (pin_ctl & AC_PINCTL_HP_EN) ?
5340
SND_JACK_HEADPHONE : SND_JACK_LINEOUT;
5342
snd_jack_report(jacks->jack, present ? type : 0);
5345
EXPORT_SYMBOL_HDA(snd_hda_input_jack_report);
5347
/* free jack instances manually when clearing/reconfiguring */
5348
void snd_hda_input_jack_free(struct hda_codec *codec)
5350
if (!codec->bus->shutdown && codec->jacks.list) {
5351
struct hda_jack_item *jacks = codec->jacks.list;
5353
for (i = 0; i < codec->jacks.used; i++, jacks++) {
5355
snd_device_free(codec->bus->card, jacks->jack);
5358
snd_array_free(&codec->jacks);
5360
EXPORT_SYMBOL_HDA(snd_hda_input_jack_free);
5361
#endif /* CONFIG_SND_HDA_INPUT_JACK */
5363
5363
MODULE_DESCRIPTION("HDA codec core");
5364
5364
MODULE_LICENSE("GPL");