Takashi Iwai | 23d30f2 | 2012-05-07 17:17:32 +0200 | [diff] [blame] | 1 | /* |
| 2 | * BIOS auto-parser helper functions for HD-audio |
| 3 | * |
| 4 | * Copyright (c) 2012 Takashi Iwai <tiwai@suse.de> |
| 5 | * |
| 6 | * This driver is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | */ |
| 11 | |
| 12 | #include <linux/slab.h> |
| 13 | #include <linux/export.h> |
Takashi Iwai | b9030a0 | 2012-11-29 10:18:57 +0100 | [diff] [blame] | 14 | #include <linux/sort.h> |
Takashi Iwai | 23d30f2 | 2012-05-07 17:17:32 +0200 | [diff] [blame] | 15 | #include <sound/core.h> |
| 16 | #include "hda_codec.h" |
Takashi Iwai | 128bc4b | 2012-05-07 17:42:31 +0200 | [diff] [blame] | 17 | #include "hda_local.h" |
Takashi Iwai | 23d30f2 | 2012-05-07 17:17:32 +0200 | [diff] [blame] | 18 | #include "hda_auto_parser.h" |
| 19 | |
Takashi Iwai | 128bc4b | 2012-05-07 17:42:31 +0200 | [diff] [blame] | 20 | /* |
| 21 | * Helper for automatic pin configuration |
| 22 | */ |
| 23 | |
| 24 | static int is_in_nid_list(hda_nid_t nid, const hda_nid_t *list) |
| 25 | { |
| 26 | for (; *list; list++) |
| 27 | if (*list == nid) |
| 28 | return 1; |
| 29 | return 0; |
| 30 | } |
| 31 | |
Takashi Iwai | b9030a0 | 2012-11-29 10:18:57 +0100 | [diff] [blame] | 32 | /* a pair of input pin and its sequence */ |
| 33 | struct auto_out_pin { |
| 34 | hda_nid_t pin; |
| 35 | short seq; |
| 36 | }; |
| 37 | |
| 38 | static int compare_seq(const void *ap, const void *bp) |
| 39 | { |
| 40 | const struct auto_out_pin *a = ap; |
| 41 | const struct auto_out_pin *b = bp; |
| 42 | return (int)(a->seq - b->seq); |
| 43 | } |
Takashi Iwai | 128bc4b | 2012-05-07 17:42:31 +0200 | [diff] [blame] | 44 | |
| 45 | /* |
| 46 | * Sort an associated group of pins according to their sequence numbers. |
Takashi Iwai | b9030a0 | 2012-11-29 10:18:57 +0100 | [diff] [blame] | 47 | * then store it to a pin array. |
Takashi Iwai | 128bc4b | 2012-05-07 17:42:31 +0200 | [diff] [blame] | 48 | */ |
Takashi Iwai | b9030a0 | 2012-11-29 10:18:57 +0100 | [diff] [blame] | 49 | static void sort_pins_by_sequence(hda_nid_t *pins, struct auto_out_pin *list, |
Takashi Iwai | 128bc4b | 2012-05-07 17:42:31 +0200 | [diff] [blame] | 50 | int num_pins) |
| 51 | { |
Takashi Iwai | b9030a0 | 2012-11-29 10:18:57 +0100 | [diff] [blame] | 52 | int i; |
| 53 | sort(list, num_pins, sizeof(list[0]), compare_seq, NULL); |
| 54 | for (i = 0; i < num_pins; i++) |
| 55 | pins[i] = list[i].pin; |
Takashi Iwai | 128bc4b | 2012-05-07 17:42:31 +0200 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | |
| 59 | /* add the found input-pin to the cfg->inputs[] table */ |
| 60 | static void add_auto_cfg_input_pin(struct auto_pin_cfg *cfg, hda_nid_t nid, |
| 61 | int type) |
| 62 | { |
| 63 | if (cfg->num_inputs < AUTO_CFG_MAX_INS) { |
| 64 | cfg->inputs[cfg->num_inputs].pin = nid; |
| 65 | cfg->inputs[cfg->num_inputs].type = type; |
| 66 | cfg->num_inputs++; |
| 67 | } |
| 68 | } |
| 69 | |
Takashi Iwai | b9030a0 | 2012-11-29 10:18:57 +0100 | [diff] [blame] | 70 | static int compare_input_type(const void *ap, const void *bp) |
Takashi Iwai | 128bc4b | 2012-05-07 17:42:31 +0200 | [diff] [blame] | 71 | { |
Takashi Iwai | b9030a0 | 2012-11-29 10:18:57 +0100 | [diff] [blame] | 72 | const struct auto_pin_cfg_item *a = ap; |
| 73 | const struct auto_pin_cfg_item *b = bp; |
| 74 | return (int)(a->type - b->type); |
Takashi Iwai | 128bc4b | 2012-05-07 17:42:31 +0200 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | /* Reorder the surround channels |
| 78 | * ALSA sequence is front/surr/clfe/side |
| 79 | * HDA sequence is: |
| 80 | * 4-ch: front/surr => OK as it is |
| 81 | * 6-ch: front/clfe/surr |
| 82 | * 8-ch: front/clfe/rear/side|fc |
| 83 | */ |
| 84 | static void reorder_outputs(unsigned int nums, hda_nid_t *pins) |
| 85 | { |
| 86 | hda_nid_t nid; |
| 87 | |
| 88 | switch (nums) { |
| 89 | case 3: |
| 90 | case 4: |
| 91 | nid = pins[1]; |
| 92 | pins[1] = pins[2]; |
| 93 | pins[2] = nid; |
| 94 | break; |
| 95 | } |
| 96 | } |
| 97 | |
Takashi Iwai | 52fd5cb | 2013-01-15 08:45:33 +0100 | [diff] [blame] | 98 | /* check whether the given pin has a proper pin I/O capability bit */ |
| 99 | static bool check_pincap_validity(struct hda_codec *codec, hda_nid_t pin, |
| 100 | unsigned int dev) |
| 101 | { |
| 102 | unsigned int pincap = snd_hda_query_pin_caps(codec, pin); |
| 103 | |
| 104 | /* some old hardware don't return the proper pincaps */ |
| 105 | if (!pincap) |
| 106 | return true; |
| 107 | |
| 108 | switch (dev) { |
| 109 | case AC_JACK_LINE_OUT: |
| 110 | case AC_JACK_SPEAKER: |
| 111 | case AC_JACK_HP_OUT: |
| 112 | case AC_JACK_SPDIF_OUT: |
| 113 | case AC_JACK_DIG_OTHER_OUT: |
| 114 | return !!(pincap & AC_PINCAP_OUT); |
| 115 | default: |
| 116 | return !!(pincap & AC_PINCAP_IN); |
| 117 | } |
| 118 | } |
| 119 | |
David Henningsson | cb420b1 | 2013-04-11 11:30:28 +0200 | [diff] [blame] | 120 | static bool can_be_headset_mic(struct hda_codec *codec, |
| 121 | struct auto_pin_cfg_item *item, |
| 122 | int seq_number) |
| 123 | { |
| 124 | int attr; |
| 125 | unsigned int def_conf; |
| 126 | if (item->type != AUTO_PIN_MIC) |
| 127 | return false; |
| 128 | |
| 129 | if (item->is_headset_mic || item->is_headphone_mic) |
| 130 | return false; /* Already assigned */ |
| 131 | |
| 132 | def_conf = snd_hda_codec_get_pincfg(codec, item->pin); |
| 133 | attr = snd_hda_get_input_pin_attr(def_conf); |
| 134 | if (attr <= INPUT_PIN_ATTR_DOCK) |
| 135 | return false; |
| 136 | |
| 137 | if (seq_number >= 0) { |
| 138 | int seq = get_defcfg_sequence(def_conf); |
| 139 | if (seq != seq_number) |
| 140 | return false; |
| 141 | } |
| 142 | |
| 143 | return true; |
| 144 | } |
| 145 | |
Takashi Iwai | 128bc4b | 2012-05-07 17:42:31 +0200 | [diff] [blame] | 146 | /* |
| 147 | * Parse all pin widgets and store the useful pin nids to cfg |
| 148 | * |
| 149 | * The number of line-outs or any primary output is stored in line_outs, |
| 150 | * and the corresponding output pins are assigned to line_out_pins[], |
| 151 | * in the order of front, rear, CLFE, side, ... |
| 152 | * |
| 153 | * If more extra outputs (speaker and headphone) are found, the pins are |
| 154 | * assisnged to hp_pins[] and speaker_pins[], respectively. If no line-out jack |
| 155 | * is detected, one of speaker of HP pins is assigned as the primary |
| 156 | * output, i.e. to line_out_pins[0]. So, line_outs is always positive |
| 157 | * if any analog output exists. |
| 158 | * |
| 159 | * The analog input pins are assigned to inputs array. |
| 160 | * The digital input/output pins are assigned to dig_in_pin and dig_out_pin, |
| 161 | * respectively. |
| 162 | */ |
| 163 | int snd_hda_parse_pin_defcfg(struct hda_codec *codec, |
| 164 | struct auto_pin_cfg *cfg, |
| 165 | const hda_nid_t *ignore_nids, |
| 166 | unsigned int cond_flags) |
| 167 | { |
| 168 | hda_nid_t nid, end_nid; |
| 169 | short seq, assoc_line_out; |
Takashi Iwai | b9030a0 | 2012-11-29 10:18:57 +0100 | [diff] [blame] | 170 | struct auto_out_pin line_out[ARRAY_SIZE(cfg->line_out_pins)]; |
| 171 | struct auto_out_pin speaker_out[ARRAY_SIZE(cfg->speaker_pins)]; |
| 172 | struct auto_out_pin hp_out[ARRAY_SIZE(cfg->hp_pins)]; |
Takashi Iwai | 128bc4b | 2012-05-07 17:42:31 +0200 | [diff] [blame] | 173 | int i; |
| 174 | |
Takashi Iwai | 1c70a58 | 2013-01-11 17:48:22 +0100 | [diff] [blame] | 175 | if (!snd_hda_get_int_hint(codec, "parser_flags", &i)) |
| 176 | cond_flags = i; |
| 177 | |
Takashi Iwai | 128bc4b | 2012-05-07 17:42:31 +0200 | [diff] [blame] | 178 | memset(cfg, 0, sizeof(*cfg)); |
| 179 | |
Takashi Iwai | b9030a0 | 2012-11-29 10:18:57 +0100 | [diff] [blame] | 180 | memset(line_out, 0, sizeof(line_out)); |
| 181 | memset(speaker_out, 0, sizeof(speaker_out)); |
| 182 | memset(hp_out, 0, sizeof(hp_out)); |
Takashi Iwai | 128bc4b | 2012-05-07 17:42:31 +0200 | [diff] [blame] | 183 | assoc_line_out = 0; |
| 184 | |
Takashi Iwai | 128bc4b | 2012-05-07 17:42:31 +0200 | [diff] [blame] | 185 | end_nid = codec->start_nid + codec->num_nodes; |
| 186 | for (nid = codec->start_nid; nid < end_nid; nid++) { |
| 187 | unsigned int wid_caps = get_wcaps(codec, nid); |
| 188 | unsigned int wid_type = get_wcaps_type(wid_caps); |
| 189 | unsigned int def_conf; |
| 190 | short assoc, loc, conn, dev; |
| 191 | |
| 192 | /* read all default configuration for pin complex */ |
| 193 | if (wid_type != AC_WID_PIN) |
| 194 | continue; |
| 195 | /* ignore the given nids (e.g. pc-beep returns error) */ |
| 196 | if (ignore_nids && is_in_nid_list(nid, ignore_nids)) |
| 197 | continue; |
| 198 | |
| 199 | def_conf = snd_hda_codec_get_pincfg(codec, nid); |
Takashi Iwai | 128bc4b | 2012-05-07 17:42:31 +0200 | [diff] [blame] | 200 | conn = get_defcfg_connect(def_conf); |
| 201 | if (conn == AC_JACK_PORT_NONE) |
| 202 | continue; |
| 203 | loc = get_defcfg_location(def_conf); |
| 204 | dev = get_defcfg_device(def_conf); |
| 205 | |
| 206 | /* workaround for buggy BIOS setups */ |
| 207 | if (dev == AC_JACK_LINE_OUT) { |
Takashi Iwai | fb690cf | 2013-01-07 18:21:47 +0100 | [diff] [blame] | 208 | if (conn == AC_JACK_PORT_FIXED || |
| 209 | conn == AC_JACK_PORT_BOTH) |
Takashi Iwai | 128bc4b | 2012-05-07 17:42:31 +0200 | [diff] [blame] | 210 | dev = AC_JACK_SPEAKER; |
| 211 | } |
| 212 | |
Takashi Iwai | 52fd5cb | 2013-01-15 08:45:33 +0100 | [diff] [blame] | 213 | if (!check_pincap_validity(codec, nid, dev)) |
| 214 | continue; |
| 215 | |
Takashi Iwai | 128bc4b | 2012-05-07 17:42:31 +0200 | [diff] [blame] | 216 | switch (dev) { |
| 217 | case AC_JACK_LINE_OUT: |
| 218 | seq = get_defcfg_sequence(def_conf); |
| 219 | assoc = get_defcfg_association(def_conf); |
| 220 | |
| 221 | if (!(wid_caps & AC_WCAP_STEREO)) |
| 222 | if (!cfg->mono_out_pin) |
| 223 | cfg->mono_out_pin = nid; |
| 224 | if (!assoc) |
| 225 | continue; |
| 226 | if (!assoc_line_out) |
| 227 | assoc_line_out = assoc; |
Takashi Iwai | 9b7564a | 2014-03-25 10:02:01 +0100 | [diff] [blame] | 228 | else if (assoc_line_out != assoc) { |
| 229 | codec_info(codec, |
| 230 | "ignore pin 0x%x with mismatching assoc# 0x%x vs 0x%x\n", |
| 231 | nid, assoc, assoc_line_out); |
Takashi Iwai | 128bc4b | 2012-05-07 17:42:31 +0200 | [diff] [blame] | 232 | continue; |
Takashi Iwai | 9b7564a | 2014-03-25 10:02:01 +0100 | [diff] [blame] | 233 | } |
| 234 | if (cfg->line_outs >= ARRAY_SIZE(cfg->line_out_pins)) { |
| 235 | codec_info(codec, |
| 236 | "ignore pin 0x%x, too many assigned pins\n", |
| 237 | nid); |
Takashi Iwai | 128bc4b | 2012-05-07 17:42:31 +0200 | [diff] [blame] | 238 | continue; |
Takashi Iwai | 9b7564a | 2014-03-25 10:02:01 +0100 | [diff] [blame] | 239 | } |
Takashi Iwai | b9030a0 | 2012-11-29 10:18:57 +0100 | [diff] [blame] | 240 | line_out[cfg->line_outs].pin = nid; |
| 241 | line_out[cfg->line_outs].seq = seq; |
Takashi Iwai | 128bc4b | 2012-05-07 17:42:31 +0200 | [diff] [blame] | 242 | cfg->line_outs++; |
| 243 | break; |
| 244 | case AC_JACK_SPEAKER: |
| 245 | seq = get_defcfg_sequence(def_conf); |
| 246 | assoc = get_defcfg_association(def_conf); |
Takashi Iwai | 9b7564a | 2014-03-25 10:02:01 +0100 | [diff] [blame] | 247 | if (cfg->speaker_outs >= ARRAY_SIZE(cfg->speaker_pins)) { |
| 248 | codec_info(codec, |
| 249 | "ignore pin 0x%x, too many assigned pins\n", |
| 250 | nid); |
Takashi Iwai | 128bc4b | 2012-05-07 17:42:31 +0200 | [diff] [blame] | 251 | continue; |
Takashi Iwai | 9b7564a | 2014-03-25 10:02:01 +0100 | [diff] [blame] | 252 | } |
Takashi Iwai | b9030a0 | 2012-11-29 10:18:57 +0100 | [diff] [blame] | 253 | speaker_out[cfg->speaker_outs].pin = nid; |
| 254 | speaker_out[cfg->speaker_outs].seq = (assoc << 4) | seq; |
Takashi Iwai | 128bc4b | 2012-05-07 17:42:31 +0200 | [diff] [blame] | 255 | cfg->speaker_outs++; |
| 256 | break; |
| 257 | case AC_JACK_HP_OUT: |
| 258 | seq = get_defcfg_sequence(def_conf); |
| 259 | assoc = get_defcfg_association(def_conf); |
Takashi Iwai | 9b7564a | 2014-03-25 10:02:01 +0100 | [diff] [blame] | 260 | if (cfg->hp_outs >= ARRAY_SIZE(cfg->hp_pins)) { |
| 261 | codec_info(codec, |
| 262 | "ignore pin 0x%x, too many assigned pins\n", |
| 263 | nid); |
Takashi Iwai | 128bc4b | 2012-05-07 17:42:31 +0200 | [diff] [blame] | 264 | continue; |
Takashi Iwai | 9b7564a | 2014-03-25 10:02:01 +0100 | [diff] [blame] | 265 | } |
Takashi Iwai | b9030a0 | 2012-11-29 10:18:57 +0100 | [diff] [blame] | 266 | hp_out[cfg->hp_outs].pin = nid; |
| 267 | hp_out[cfg->hp_outs].seq = (assoc << 4) | seq; |
Takashi Iwai | 128bc4b | 2012-05-07 17:42:31 +0200 | [diff] [blame] | 268 | cfg->hp_outs++; |
| 269 | break; |
| 270 | case AC_JACK_MIC_IN: |
| 271 | add_auto_cfg_input_pin(cfg, nid, AUTO_PIN_MIC); |
| 272 | break; |
| 273 | case AC_JACK_LINE_IN: |
| 274 | add_auto_cfg_input_pin(cfg, nid, AUTO_PIN_LINE_IN); |
| 275 | break; |
| 276 | case AC_JACK_CD: |
| 277 | add_auto_cfg_input_pin(cfg, nid, AUTO_PIN_CD); |
| 278 | break; |
| 279 | case AC_JACK_AUX: |
| 280 | add_auto_cfg_input_pin(cfg, nid, AUTO_PIN_AUX); |
| 281 | break; |
| 282 | case AC_JACK_SPDIF_OUT: |
| 283 | case AC_JACK_DIG_OTHER_OUT: |
Takashi Iwai | 9b7564a | 2014-03-25 10:02:01 +0100 | [diff] [blame] | 284 | if (cfg->dig_outs >= ARRAY_SIZE(cfg->dig_out_pins)) { |
| 285 | codec_info(codec, |
| 286 | "ignore pin 0x%x, too many assigned pins\n", |
| 287 | nid); |
Takashi Iwai | 128bc4b | 2012-05-07 17:42:31 +0200 | [diff] [blame] | 288 | continue; |
Takashi Iwai | 9b7564a | 2014-03-25 10:02:01 +0100 | [diff] [blame] | 289 | } |
Takashi Iwai | 128bc4b | 2012-05-07 17:42:31 +0200 | [diff] [blame] | 290 | cfg->dig_out_pins[cfg->dig_outs] = nid; |
| 291 | cfg->dig_out_type[cfg->dig_outs] = |
| 292 | (loc == AC_JACK_LOC_HDMI) ? |
| 293 | HDA_PCM_TYPE_HDMI : HDA_PCM_TYPE_SPDIF; |
| 294 | cfg->dig_outs++; |
| 295 | break; |
| 296 | case AC_JACK_SPDIF_IN: |
| 297 | case AC_JACK_DIG_OTHER_IN: |
| 298 | cfg->dig_in_pin = nid; |
| 299 | if (loc == AC_JACK_LOC_HDMI) |
| 300 | cfg->dig_in_type = HDA_PCM_TYPE_HDMI; |
| 301 | else |
| 302 | cfg->dig_in_type = HDA_PCM_TYPE_SPDIF; |
| 303 | break; |
| 304 | } |
| 305 | } |
| 306 | |
David Henningsson | cb420b1 | 2013-04-11 11:30:28 +0200 | [diff] [blame] | 307 | /* Find a pin that could be a headset or headphone mic */ |
| 308 | if (cond_flags & HDA_PINCFG_HEADSET_MIC || cond_flags & HDA_PINCFG_HEADPHONE_MIC) { |
| 309 | bool hsmic = !!(cond_flags & HDA_PINCFG_HEADSET_MIC); |
| 310 | bool hpmic = !!(cond_flags & HDA_PINCFG_HEADPHONE_MIC); |
| 311 | for (i = 0; (hsmic || hpmic) && (i < cfg->num_inputs); i++) |
| 312 | if (hsmic && can_be_headset_mic(codec, &cfg->inputs[i], 0xc)) { |
| 313 | cfg->inputs[i].is_headset_mic = 1; |
| 314 | hsmic = false; |
| 315 | } else if (hpmic && can_be_headset_mic(codec, &cfg->inputs[i], 0xd)) { |
| 316 | cfg->inputs[i].is_headphone_mic = 1; |
| 317 | hpmic = false; |
| 318 | } |
| 319 | |
| 320 | /* If we didn't find our sequence number mark, fall back to any sequence number */ |
| 321 | for (i = 0; (hsmic || hpmic) && (i < cfg->num_inputs); i++) { |
| 322 | if (!can_be_headset_mic(codec, &cfg->inputs[i], -1)) |
David Henningsson | a385d97 | 2013-03-21 12:16:29 +0100 | [diff] [blame] | 323 | continue; |
David Henningsson | cb420b1 | 2013-04-11 11:30:28 +0200 | [diff] [blame] | 324 | if (hsmic) { |
| 325 | cfg->inputs[i].is_headset_mic = 1; |
| 326 | hsmic = false; |
| 327 | } else if (hpmic) { |
| 328 | cfg->inputs[i].is_headphone_mic = 1; |
| 329 | hpmic = false; |
| 330 | } |
David Henningsson | a385d97 | 2013-03-21 12:16:29 +0100 | [diff] [blame] | 331 | } |
David Henningsson | cb420b1 | 2013-04-11 11:30:28 +0200 | [diff] [blame] | 332 | |
| 333 | if (hsmic) |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 334 | codec_dbg(codec, "Told to look for a headset mic, but didn't find any.\n"); |
David Henningsson | cb420b1 | 2013-04-11 11:30:28 +0200 | [diff] [blame] | 335 | if (hpmic) |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 336 | codec_dbg(codec, "Told to look for a headphone mic, but didn't find any.\n"); |
David Henningsson | a385d97 | 2013-03-21 12:16:29 +0100 | [diff] [blame] | 337 | } |
| 338 | |
Takashi Iwai | 128bc4b | 2012-05-07 17:42:31 +0200 | [diff] [blame] | 339 | /* FIX-UP: |
| 340 | * If no line-out is defined but multiple HPs are found, |
| 341 | * some of them might be the real line-outs. |
| 342 | */ |
| 343 | if (!cfg->line_outs && cfg->hp_outs > 1 && |
| 344 | !(cond_flags & HDA_PINCFG_NO_HP_FIXUP)) { |
| 345 | int i = 0; |
| 346 | while (i < cfg->hp_outs) { |
| 347 | /* The real HPs should have the sequence 0x0f */ |
Takashi Iwai | b9030a0 | 2012-11-29 10:18:57 +0100 | [diff] [blame] | 348 | if ((hp_out[i].seq & 0x0f) == 0x0f) { |
Takashi Iwai | 128bc4b | 2012-05-07 17:42:31 +0200 | [diff] [blame] | 349 | i++; |
| 350 | continue; |
| 351 | } |
| 352 | /* Move it to the line-out table */ |
Takashi Iwai | b9030a0 | 2012-11-29 10:18:57 +0100 | [diff] [blame] | 353 | line_out[cfg->line_outs++] = hp_out[i]; |
Takashi Iwai | 128bc4b | 2012-05-07 17:42:31 +0200 | [diff] [blame] | 354 | cfg->hp_outs--; |
Takashi Iwai | b9030a0 | 2012-11-29 10:18:57 +0100 | [diff] [blame] | 355 | memmove(hp_out + i, hp_out + i + 1, |
| 356 | sizeof(hp_out[0]) * (cfg->hp_outs - i)); |
Takashi Iwai | 128bc4b | 2012-05-07 17:42:31 +0200 | [diff] [blame] | 357 | } |
Takashi Iwai | b9030a0 | 2012-11-29 10:18:57 +0100 | [diff] [blame] | 358 | memset(hp_out + cfg->hp_outs, 0, |
| 359 | sizeof(hp_out[0]) * (AUTO_CFG_MAX_OUTS - cfg->hp_outs)); |
Takashi Iwai | 128bc4b | 2012-05-07 17:42:31 +0200 | [diff] [blame] | 360 | if (!cfg->hp_outs) |
| 361 | cfg->line_out_type = AUTO_PIN_HP_OUT; |
| 362 | |
| 363 | } |
| 364 | |
| 365 | /* sort by sequence */ |
Takashi Iwai | b9030a0 | 2012-11-29 10:18:57 +0100 | [diff] [blame] | 366 | sort_pins_by_sequence(cfg->line_out_pins, line_out, cfg->line_outs); |
| 367 | sort_pins_by_sequence(cfg->speaker_pins, speaker_out, |
Takashi Iwai | 128bc4b | 2012-05-07 17:42:31 +0200 | [diff] [blame] | 368 | cfg->speaker_outs); |
Takashi Iwai | b9030a0 | 2012-11-29 10:18:57 +0100 | [diff] [blame] | 369 | sort_pins_by_sequence(cfg->hp_pins, hp_out, cfg->hp_outs); |
Takashi Iwai | 128bc4b | 2012-05-07 17:42:31 +0200 | [diff] [blame] | 370 | |
| 371 | /* |
| 372 | * FIX-UP: if no line-outs are detected, try to use speaker or HP pin |
| 373 | * as a primary output |
| 374 | */ |
| 375 | if (!cfg->line_outs && |
| 376 | !(cond_flags & HDA_PINCFG_NO_LO_FIXUP)) { |
| 377 | if (cfg->speaker_outs) { |
| 378 | cfg->line_outs = cfg->speaker_outs; |
| 379 | memcpy(cfg->line_out_pins, cfg->speaker_pins, |
| 380 | sizeof(cfg->speaker_pins)); |
| 381 | cfg->speaker_outs = 0; |
| 382 | memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins)); |
| 383 | cfg->line_out_type = AUTO_PIN_SPEAKER_OUT; |
| 384 | } else if (cfg->hp_outs) { |
| 385 | cfg->line_outs = cfg->hp_outs; |
| 386 | memcpy(cfg->line_out_pins, cfg->hp_pins, |
| 387 | sizeof(cfg->hp_pins)); |
| 388 | cfg->hp_outs = 0; |
| 389 | memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins)); |
| 390 | cfg->line_out_type = AUTO_PIN_HP_OUT; |
| 391 | } |
| 392 | } |
| 393 | |
| 394 | reorder_outputs(cfg->line_outs, cfg->line_out_pins); |
| 395 | reorder_outputs(cfg->hp_outs, cfg->hp_pins); |
| 396 | reorder_outputs(cfg->speaker_outs, cfg->speaker_pins); |
| 397 | |
Takashi Iwai | b9030a0 | 2012-11-29 10:18:57 +0100 | [diff] [blame] | 398 | /* sort inputs in the order of AUTO_PIN_* type */ |
| 399 | sort(cfg->inputs, cfg->num_inputs, sizeof(cfg->inputs[0]), |
| 400 | compare_input_type, NULL); |
Takashi Iwai | 128bc4b | 2012-05-07 17:42:31 +0200 | [diff] [blame] | 401 | |
| 402 | /* |
| 403 | * debug prints of the parsed results |
| 404 | */ |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 405 | codec_info(codec, "autoconfig: line_outs=%d (0x%x/0x%x/0x%x/0x%x/0x%x) type:%s\n", |
Takashi Iwai | 128bc4b | 2012-05-07 17:42:31 +0200 | [diff] [blame] | 406 | cfg->line_outs, cfg->line_out_pins[0], cfg->line_out_pins[1], |
| 407 | cfg->line_out_pins[2], cfg->line_out_pins[3], |
| 408 | cfg->line_out_pins[4], |
| 409 | cfg->line_out_type == AUTO_PIN_HP_OUT ? "hp" : |
| 410 | (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT ? |
| 411 | "speaker" : "line")); |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 412 | codec_info(codec, " speaker_outs=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n", |
Takashi Iwai | 128bc4b | 2012-05-07 17:42:31 +0200 | [diff] [blame] | 413 | cfg->speaker_outs, cfg->speaker_pins[0], |
| 414 | cfg->speaker_pins[1], cfg->speaker_pins[2], |
| 415 | cfg->speaker_pins[3], cfg->speaker_pins[4]); |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 416 | codec_info(codec, " hp_outs=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n", |
Takashi Iwai | 128bc4b | 2012-05-07 17:42:31 +0200 | [diff] [blame] | 417 | cfg->hp_outs, cfg->hp_pins[0], |
| 418 | cfg->hp_pins[1], cfg->hp_pins[2], |
| 419 | cfg->hp_pins[3], cfg->hp_pins[4]); |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 420 | codec_info(codec, " mono: mono_out=0x%x\n", cfg->mono_out_pin); |
Takashi Iwai | 128bc4b | 2012-05-07 17:42:31 +0200 | [diff] [blame] | 421 | if (cfg->dig_outs) |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 422 | codec_info(codec, " dig-out=0x%x/0x%x\n", |
Takashi Iwai | 128bc4b | 2012-05-07 17:42:31 +0200 | [diff] [blame] | 423 | cfg->dig_out_pins[0], cfg->dig_out_pins[1]); |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 424 | codec_info(codec, " inputs:\n"); |
Takashi Iwai | 128bc4b | 2012-05-07 17:42:31 +0200 | [diff] [blame] | 425 | for (i = 0; i < cfg->num_inputs; i++) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 426 | codec_info(codec, " %s=0x%x\n", |
Takashi Iwai | 128bc4b | 2012-05-07 17:42:31 +0200 | [diff] [blame] | 427 | hda_get_autocfg_input_label(codec, cfg, i), |
| 428 | cfg->inputs[i].pin); |
| 429 | } |
Takashi Iwai | 128bc4b | 2012-05-07 17:42:31 +0200 | [diff] [blame] | 430 | if (cfg->dig_in_pin) |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 431 | codec_info(codec, " dig-in=0x%x\n", cfg->dig_in_pin); |
Takashi Iwai | 128bc4b | 2012-05-07 17:42:31 +0200 | [diff] [blame] | 432 | |
| 433 | return 0; |
| 434 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 435 | EXPORT_SYMBOL_GPL(snd_hda_parse_pin_defcfg); |
Takashi Iwai | 128bc4b | 2012-05-07 17:42:31 +0200 | [diff] [blame] | 436 | |
| 437 | int snd_hda_get_input_pin_attr(unsigned int def_conf) |
| 438 | { |
| 439 | unsigned int loc = get_defcfg_location(def_conf); |
| 440 | unsigned int conn = get_defcfg_connect(def_conf); |
| 441 | if (conn == AC_JACK_PORT_NONE) |
| 442 | return INPUT_PIN_ATTR_UNUSED; |
| 443 | /* Windows may claim the internal mic to be BOTH, too */ |
| 444 | if (conn == AC_JACK_PORT_FIXED || conn == AC_JACK_PORT_BOTH) |
| 445 | return INPUT_PIN_ATTR_INT; |
| 446 | if ((loc & 0x30) == AC_JACK_LOC_INTERNAL) |
| 447 | return INPUT_PIN_ATTR_INT; |
| 448 | if ((loc & 0x30) == AC_JACK_LOC_SEPARATE) |
| 449 | return INPUT_PIN_ATTR_DOCK; |
| 450 | if (loc == AC_JACK_LOC_REAR) |
| 451 | return INPUT_PIN_ATTR_REAR; |
| 452 | if (loc == AC_JACK_LOC_FRONT) |
| 453 | return INPUT_PIN_ATTR_FRONT; |
| 454 | return INPUT_PIN_ATTR_NORMAL; |
| 455 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 456 | EXPORT_SYMBOL_GPL(snd_hda_get_input_pin_attr); |
Takashi Iwai | 128bc4b | 2012-05-07 17:42:31 +0200 | [diff] [blame] | 457 | |
| 458 | /** |
| 459 | * hda_get_input_pin_label - Give a label for the given input pin |
| 460 | * |
| 461 | * When check_location is true, the function checks the pin location |
| 462 | * for mic and line-in pins, and set an appropriate prefix like "Front", |
| 463 | * "Rear", "Internal". |
| 464 | */ |
| 465 | |
| 466 | static const char *hda_get_input_pin_label(struct hda_codec *codec, |
David Henningsson | a385d97 | 2013-03-21 12:16:29 +0100 | [diff] [blame] | 467 | const struct auto_pin_cfg_item *item, |
Takashi Iwai | 128bc4b | 2012-05-07 17:42:31 +0200 | [diff] [blame] | 468 | hda_nid_t pin, bool check_location) |
| 469 | { |
| 470 | unsigned int def_conf; |
| 471 | static const char * const mic_names[] = { |
Takashi Iwai | 5ec16d1 | 2012-11-28 18:11:59 +0100 | [diff] [blame] | 472 | "Internal Mic", "Dock Mic", "Mic", "Rear Mic", "Front Mic" |
Takashi Iwai | 128bc4b | 2012-05-07 17:42:31 +0200 | [diff] [blame] | 473 | }; |
| 474 | int attr; |
| 475 | |
| 476 | def_conf = snd_hda_codec_get_pincfg(codec, pin); |
| 477 | |
| 478 | switch (get_defcfg_device(def_conf)) { |
| 479 | case AC_JACK_MIC_IN: |
David Henningsson | a385d97 | 2013-03-21 12:16:29 +0100 | [diff] [blame] | 480 | if (item && item->is_headset_mic) |
| 481 | return "Headset Mic"; |
David Henningsson | cb420b1 | 2013-04-11 11:30:28 +0200 | [diff] [blame] | 482 | if (item && item->is_headphone_mic) |
| 483 | return "Headphone Mic"; |
Takashi Iwai | 128bc4b | 2012-05-07 17:42:31 +0200 | [diff] [blame] | 484 | if (!check_location) |
| 485 | return "Mic"; |
| 486 | attr = snd_hda_get_input_pin_attr(def_conf); |
| 487 | if (!attr) |
| 488 | return "None"; |
| 489 | return mic_names[attr - 1]; |
| 490 | case AC_JACK_LINE_IN: |
| 491 | if (!check_location) |
| 492 | return "Line"; |
| 493 | attr = snd_hda_get_input_pin_attr(def_conf); |
| 494 | if (!attr) |
| 495 | return "None"; |
| 496 | if (attr == INPUT_PIN_ATTR_DOCK) |
| 497 | return "Dock Line"; |
| 498 | return "Line"; |
| 499 | case AC_JACK_AUX: |
| 500 | return "Aux"; |
| 501 | case AC_JACK_CD: |
| 502 | return "CD"; |
| 503 | case AC_JACK_SPDIF_IN: |
| 504 | return "SPDIF In"; |
| 505 | case AC_JACK_DIG_OTHER_IN: |
| 506 | return "Digital In"; |
Takashi Iwai | 54d778b | 2013-01-09 08:46:34 +0100 | [diff] [blame] | 507 | case AC_JACK_HP_OUT: |
| 508 | return "Headphone Mic"; |
Takashi Iwai | 128bc4b | 2012-05-07 17:42:31 +0200 | [diff] [blame] | 509 | default: |
| 510 | return "Misc"; |
| 511 | } |
| 512 | } |
| 513 | |
| 514 | /* Check whether the location prefix needs to be added to the label. |
| 515 | * If all mic-jacks are in the same location (e.g. rear panel), we don't |
| 516 | * have to put "Front" prefix to each label. In such a case, returns false. |
| 517 | */ |
| 518 | static int check_mic_location_need(struct hda_codec *codec, |
| 519 | const struct auto_pin_cfg *cfg, |
| 520 | int input) |
| 521 | { |
| 522 | unsigned int defc; |
| 523 | int i, attr, attr2; |
| 524 | |
| 525 | defc = snd_hda_codec_get_pincfg(codec, cfg->inputs[input].pin); |
| 526 | attr = snd_hda_get_input_pin_attr(defc); |
| 527 | /* for internal or docking mics, we need locations */ |
| 528 | if (attr <= INPUT_PIN_ATTR_NORMAL) |
| 529 | return 1; |
| 530 | |
| 531 | attr = 0; |
| 532 | for (i = 0; i < cfg->num_inputs; i++) { |
| 533 | defc = snd_hda_codec_get_pincfg(codec, cfg->inputs[i].pin); |
| 534 | attr2 = snd_hda_get_input_pin_attr(defc); |
| 535 | if (attr2 >= INPUT_PIN_ATTR_NORMAL) { |
| 536 | if (attr && attr != attr2) |
| 537 | return 1; /* different locations found */ |
| 538 | attr = attr2; |
| 539 | } |
| 540 | } |
| 541 | return 0; |
| 542 | } |
| 543 | |
| 544 | /** |
| 545 | * hda_get_autocfg_input_label - Get a label for the given input |
| 546 | * |
| 547 | * Get a label for the given input pin defined by the autocfg item. |
| 548 | * Unlike hda_get_input_pin_label(), this function checks all inputs |
| 549 | * defined in autocfg and avoids the redundant mic/line prefix as much as |
| 550 | * possible. |
| 551 | */ |
| 552 | const char *hda_get_autocfg_input_label(struct hda_codec *codec, |
| 553 | const struct auto_pin_cfg *cfg, |
| 554 | int input) |
| 555 | { |
| 556 | int type = cfg->inputs[input].type; |
| 557 | int has_multiple_pins = 0; |
| 558 | |
| 559 | if ((input > 0 && cfg->inputs[input - 1].type == type) || |
| 560 | (input < cfg->num_inputs - 1 && cfg->inputs[input + 1].type == type)) |
| 561 | has_multiple_pins = 1; |
| 562 | if (has_multiple_pins && type == AUTO_PIN_MIC) |
| 563 | has_multiple_pins &= check_mic_location_need(codec, cfg, input); |
David Henningsson | a385d97 | 2013-03-21 12:16:29 +0100 | [diff] [blame] | 564 | return hda_get_input_pin_label(codec, &cfg->inputs[input], |
| 565 | cfg->inputs[input].pin, |
Takashi Iwai | 128bc4b | 2012-05-07 17:42:31 +0200 | [diff] [blame] | 566 | has_multiple_pins); |
| 567 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 568 | EXPORT_SYMBOL_GPL(hda_get_autocfg_input_label); |
Takashi Iwai | 128bc4b | 2012-05-07 17:42:31 +0200 | [diff] [blame] | 569 | |
| 570 | /* return the position of NID in the list, or -1 if not found */ |
| 571 | static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums) |
| 572 | { |
| 573 | int i; |
| 574 | for (i = 0; i < nums; i++) |
| 575 | if (list[i] == nid) |
| 576 | return i; |
| 577 | return -1; |
| 578 | } |
| 579 | |
| 580 | /* get a unique suffix or an index number */ |
| 581 | static const char *check_output_sfx(hda_nid_t nid, const hda_nid_t *pins, |
| 582 | int num_pins, int *indexp) |
| 583 | { |
| 584 | static const char * const channel_sfx[] = { |
| 585 | " Front", " Surround", " CLFE", " Side" |
| 586 | }; |
| 587 | int i; |
| 588 | |
| 589 | i = find_idx_in_nid_list(nid, pins, num_pins); |
| 590 | if (i < 0) |
| 591 | return NULL; |
| 592 | if (num_pins == 1) |
| 593 | return ""; |
| 594 | if (num_pins > ARRAY_SIZE(channel_sfx)) { |
| 595 | if (indexp) |
| 596 | *indexp = i; |
| 597 | return ""; |
| 598 | } |
| 599 | return channel_sfx[i]; |
| 600 | } |
| 601 | |
David Henningsson | eee3ed4 | 2012-10-03 11:12:53 +0200 | [diff] [blame] | 602 | static const char *check_output_pfx(struct hda_codec *codec, hda_nid_t nid) |
| 603 | { |
| 604 | unsigned int def_conf = snd_hda_codec_get_pincfg(codec, nid); |
| 605 | int attr = snd_hda_get_input_pin_attr(def_conf); |
| 606 | |
| 607 | /* check the location */ |
| 608 | switch (attr) { |
| 609 | case INPUT_PIN_ATTR_DOCK: |
| 610 | return "Dock "; |
| 611 | case INPUT_PIN_ATTR_FRONT: |
| 612 | return "Front "; |
| 613 | } |
| 614 | return ""; |
| 615 | } |
| 616 | |
| 617 | static int get_hp_label_index(struct hda_codec *codec, hda_nid_t nid, |
| 618 | const hda_nid_t *pins, int num_pins) |
| 619 | { |
| 620 | int i, j, idx = 0; |
| 621 | |
| 622 | const char *pfx = check_output_pfx(codec, nid); |
| 623 | |
| 624 | i = find_idx_in_nid_list(nid, pins, num_pins); |
| 625 | if (i < 0) |
| 626 | return -1; |
| 627 | for (j = 0; j < i; j++) |
| 628 | if (pfx == check_output_pfx(codec, pins[j])) |
| 629 | idx++; |
| 630 | |
| 631 | return idx; |
| 632 | } |
| 633 | |
Takashi Iwai | 128bc4b | 2012-05-07 17:42:31 +0200 | [diff] [blame] | 634 | static int fill_audio_out_name(struct hda_codec *codec, hda_nid_t nid, |
| 635 | const struct auto_pin_cfg *cfg, |
| 636 | const char *name, char *label, int maxlen, |
| 637 | int *indexp) |
| 638 | { |
| 639 | unsigned int def_conf = snd_hda_codec_get_pincfg(codec, nid); |
| 640 | int attr = snd_hda_get_input_pin_attr(def_conf); |
David Henningsson | eee3ed4 | 2012-10-03 11:12:53 +0200 | [diff] [blame] | 641 | const char *pfx, *sfx = ""; |
Takashi Iwai | 128bc4b | 2012-05-07 17:42:31 +0200 | [diff] [blame] | 642 | |
| 643 | /* handle as a speaker if it's a fixed line-out */ |
| 644 | if (!strcmp(name, "Line Out") && attr == INPUT_PIN_ATTR_INT) |
| 645 | name = "Speaker"; |
David Henningsson | eee3ed4 | 2012-10-03 11:12:53 +0200 | [diff] [blame] | 646 | pfx = check_output_pfx(codec, nid); |
| 647 | |
Takashi Iwai | 128bc4b | 2012-05-07 17:42:31 +0200 | [diff] [blame] | 648 | if (cfg) { |
| 649 | /* try to give a unique suffix if needed */ |
| 650 | sfx = check_output_sfx(nid, cfg->line_out_pins, cfg->line_outs, |
| 651 | indexp); |
| 652 | if (!sfx) |
| 653 | sfx = check_output_sfx(nid, cfg->speaker_pins, cfg->speaker_outs, |
| 654 | indexp); |
| 655 | if (!sfx) { |
| 656 | /* don't add channel suffix for Headphone controls */ |
David Henningsson | eee3ed4 | 2012-10-03 11:12:53 +0200 | [diff] [blame] | 657 | int idx = get_hp_label_index(codec, nid, cfg->hp_pins, |
| 658 | cfg->hp_outs); |
Takashi Iwai | 728deec | 2013-10-28 11:39:23 +0100 | [diff] [blame] | 659 | if (idx >= 0 && indexp) |
Takashi Iwai | 128bc4b | 2012-05-07 17:42:31 +0200 | [diff] [blame] | 660 | *indexp = idx; |
| 661 | sfx = ""; |
| 662 | } |
| 663 | } |
| 664 | snprintf(label, maxlen, "%s%s%s", pfx, name, sfx); |
| 665 | return 1; |
| 666 | } |
| 667 | |
David Henningsson | 3f25dcf | 2013-01-18 15:43:03 +0100 | [diff] [blame] | 668 | #define is_hdmi_cfg(conf) \ |
| 669 | (get_defcfg_location(conf) == AC_JACK_LOC_HDMI) |
| 670 | |
Takashi Iwai | 128bc4b | 2012-05-07 17:42:31 +0200 | [diff] [blame] | 671 | /** |
| 672 | * snd_hda_get_pin_label - Get a label for the given I/O pin |
| 673 | * |
| 674 | * Get a label for the given pin. This function works for both input and |
| 675 | * output pins. When @cfg is given as non-NULL, the function tries to get |
| 676 | * an optimized label using hda_get_autocfg_input_label(). |
| 677 | * |
| 678 | * This function tries to give a unique label string for the pin as much as |
| 679 | * possible. For example, when the multiple line-outs are present, it adds |
| 680 | * the channel suffix like "Front", "Surround", etc (only when @cfg is given). |
| 681 | * If no unique name with a suffix is available and @indexp is non-NULL, the |
| 682 | * index number is stored in the pointer. |
| 683 | */ |
| 684 | int snd_hda_get_pin_label(struct hda_codec *codec, hda_nid_t nid, |
| 685 | const struct auto_pin_cfg *cfg, |
| 686 | char *label, int maxlen, int *indexp) |
| 687 | { |
| 688 | unsigned int def_conf = snd_hda_codec_get_pincfg(codec, nid); |
| 689 | const char *name = NULL; |
| 690 | int i; |
David Henningsson | 3f25dcf | 2013-01-18 15:43:03 +0100 | [diff] [blame] | 691 | bool hdmi; |
Takashi Iwai | 128bc4b | 2012-05-07 17:42:31 +0200 | [diff] [blame] | 692 | |
| 693 | if (indexp) |
| 694 | *indexp = 0; |
| 695 | if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE) |
| 696 | return 0; |
| 697 | |
| 698 | switch (get_defcfg_device(def_conf)) { |
| 699 | case AC_JACK_LINE_OUT: |
| 700 | return fill_audio_out_name(codec, nid, cfg, "Line Out", |
| 701 | label, maxlen, indexp); |
| 702 | case AC_JACK_SPEAKER: |
| 703 | return fill_audio_out_name(codec, nid, cfg, "Speaker", |
| 704 | label, maxlen, indexp); |
| 705 | case AC_JACK_HP_OUT: |
| 706 | return fill_audio_out_name(codec, nid, cfg, "Headphone", |
| 707 | label, maxlen, indexp); |
| 708 | case AC_JACK_SPDIF_OUT: |
| 709 | case AC_JACK_DIG_OTHER_OUT: |
David Henningsson | 3f25dcf | 2013-01-18 15:43:03 +0100 | [diff] [blame] | 710 | hdmi = is_hdmi_cfg(def_conf); |
| 711 | name = hdmi ? "HDMI" : "SPDIF"; |
| 712 | if (cfg && indexp) |
| 713 | for (i = 0; i < cfg->dig_outs; i++) { |
| 714 | hda_nid_t pin = cfg->dig_out_pins[i]; |
| 715 | unsigned int c; |
| 716 | if (pin == nid) |
| 717 | break; |
| 718 | c = snd_hda_codec_get_pincfg(codec, pin); |
| 719 | if (hdmi == is_hdmi_cfg(c)) |
| 720 | (*indexp)++; |
| 721 | } |
Takashi Iwai | 128bc4b | 2012-05-07 17:42:31 +0200 | [diff] [blame] | 722 | break; |
| 723 | default: |
| 724 | if (cfg) { |
| 725 | for (i = 0; i < cfg->num_inputs; i++) { |
| 726 | if (cfg->inputs[i].pin != nid) |
| 727 | continue; |
| 728 | name = hda_get_autocfg_input_label(codec, cfg, i); |
| 729 | if (name) |
| 730 | break; |
| 731 | } |
| 732 | } |
| 733 | if (!name) |
David Henningsson | a385d97 | 2013-03-21 12:16:29 +0100 | [diff] [blame] | 734 | name = hda_get_input_pin_label(codec, NULL, nid, true); |
Takashi Iwai | 128bc4b | 2012-05-07 17:42:31 +0200 | [diff] [blame] | 735 | break; |
| 736 | } |
| 737 | if (!name) |
| 738 | return 0; |
| 739 | strlcpy(label, name, maxlen); |
| 740 | return 1; |
| 741 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 742 | EXPORT_SYMBOL_GPL(snd_hda_get_pin_label); |
Takashi Iwai | 128bc4b | 2012-05-07 17:42:31 +0200 | [diff] [blame] | 743 | |
Takashi Iwai | c9ce6b2 | 2012-12-18 18:12:44 +0100 | [diff] [blame] | 744 | int snd_hda_add_verbs(struct hda_codec *codec, |
| 745 | const struct hda_verb *list) |
Takashi Iwai | 23d30f2 | 2012-05-07 17:17:32 +0200 | [diff] [blame] | 746 | { |
| 747 | const struct hda_verb **v; |
Takashi Iwai | c9ce6b2 | 2012-12-18 18:12:44 +0100 | [diff] [blame] | 748 | v = snd_array_new(&codec->verbs); |
Takashi Iwai | 23d30f2 | 2012-05-07 17:17:32 +0200 | [diff] [blame] | 749 | if (!v) |
| 750 | return -ENOMEM; |
| 751 | *v = list; |
| 752 | return 0; |
| 753 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 754 | EXPORT_SYMBOL_GPL(snd_hda_add_verbs); |
Takashi Iwai | 23d30f2 | 2012-05-07 17:17:32 +0200 | [diff] [blame] | 755 | |
Takashi Iwai | c9ce6b2 | 2012-12-18 18:12:44 +0100 | [diff] [blame] | 756 | void snd_hda_apply_verbs(struct hda_codec *codec) |
Takashi Iwai | 23d30f2 | 2012-05-07 17:17:32 +0200 | [diff] [blame] | 757 | { |
Takashi Iwai | 23d30f2 | 2012-05-07 17:17:32 +0200 | [diff] [blame] | 758 | int i; |
Takashi Iwai | c9ce6b2 | 2012-12-18 18:12:44 +0100 | [diff] [blame] | 759 | for (i = 0; i < codec->verbs.used; i++) { |
| 760 | struct hda_verb **v = snd_array_elem(&codec->verbs, i); |
Takashi Iwai | 23d30f2 | 2012-05-07 17:17:32 +0200 | [diff] [blame] | 761 | snd_hda_sequence_write(codec, *v); |
| 762 | } |
| 763 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 764 | EXPORT_SYMBOL_GPL(snd_hda_apply_verbs); |
Takashi Iwai | 23d30f2 | 2012-05-07 17:17:32 +0200 | [diff] [blame] | 765 | |
| 766 | void snd_hda_apply_pincfgs(struct hda_codec *codec, |
| 767 | const struct hda_pintbl *cfg) |
| 768 | { |
| 769 | for (; cfg->nid; cfg++) |
| 770 | snd_hda_codec_set_pincfg(codec, cfg->nid, cfg->val); |
| 771 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 772 | EXPORT_SYMBOL_GPL(snd_hda_apply_pincfgs); |
Takashi Iwai | 23d30f2 | 2012-05-07 17:17:32 +0200 | [diff] [blame] | 773 | |
Takashi Iwai | fd10821 | 2013-01-10 10:18:14 +0100 | [diff] [blame] | 774 | static void set_pin_targets(struct hda_codec *codec, |
| 775 | const struct hda_pintbl *cfg) |
| 776 | { |
| 777 | for (; cfg->nid; cfg++) |
| 778 | snd_hda_set_pin_ctl_cache(codec, cfg->nid, cfg->val); |
| 779 | } |
| 780 | |
Takashi Iwai | 1f57825 | 2013-01-23 18:10:10 +0100 | [diff] [blame] | 781 | static void apply_fixup(struct hda_codec *codec, int id, int action, int depth) |
Takashi Iwai | 23d30f2 | 2012-05-07 17:17:32 +0200 | [diff] [blame] | 782 | { |
Takashi Iwai | c9ce6b2 | 2012-12-18 18:12:44 +0100 | [diff] [blame] | 783 | const char *modelname = codec->fixup_name; |
Takashi Iwai | 23d30f2 | 2012-05-07 17:17:32 +0200 | [diff] [blame] | 784 | |
| 785 | while (id >= 0) { |
Takashi Iwai | c9ce6b2 | 2012-12-18 18:12:44 +0100 | [diff] [blame] | 786 | const struct hda_fixup *fix = codec->fixup_list + id; |
Takashi Iwai | 23d30f2 | 2012-05-07 17:17:32 +0200 | [diff] [blame] | 787 | |
Takashi Iwai | 1f57825 | 2013-01-23 18:10:10 +0100 | [diff] [blame] | 788 | if (fix->chained_before) |
| 789 | apply_fixup(codec, fix->chain_id, action, depth + 1); |
| 790 | |
Takashi Iwai | 23d30f2 | 2012-05-07 17:17:32 +0200 | [diff] [blame] | 791 | switch (fix->type) { |
| 792 | case HDA_FIXUP_PINS: |
| 793 | if (action != HDA_FIXUP_ACT_PRE_PROBE || !fix->v.pins) |
| 794 | break; |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 795 | codec_dbg(codec, "%s: Apply pincfg for %s\n", |
Takashi Iwai | 23d30f2 | 2012-05-07 17:17:32 +0200 | [diff] [blame] | 796 | codec->chip_name, modelname); |
| 797 | snd_hda_apply_pincfgs(codec, fix->v.pins); |
| 798 | break; |
| 799 | case HDA_FIXUP_VERBS: |
| 800 | if (action != HDA_FIXUP_ACT_PROBE || !fix->v.verbs) |
| 801 | break; |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 802 | codec_dbg(codec, "%s: Apply fix-verbs for %s\n", |
Takashi Iwai | 23d30f2 | 2012-05-07 17:17:32 +0200 | [diff] [blame] | 803 | codec->chip_name, modelname); |
Takashi Iwai | c9ce6b2 | 2012-12-18 18:12:44 +0100 | [diff] [blame] | 804 | snd_hda_add_verbs(codec, fix->v.verbs); |
Takashi Iwai | 23d30f2 | 2012-05-07 17:17:32 +0200 | [diff] [blame] | 805 | break; |
| 806 | case HDA_FIXUP_FUNC: |
| 807 | if (!fix->v.func) |
| 808 | break; |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 809 | codec_dbg(codec, "%s: Apply fix-func for %s\n", |
Takashi Iwai | 23d30f2 | 2012-05-07 17:17:32 +0200 | [diff] [blame] | 810 | codec->chip_name, modelname); |
| 811 | fix->v.func(codec, fix, action); |
| 812 | break; |
Takashi Iwai | fd10821 | 2013-01-10 10:18:14 +0100 | [diff] [blame] | 813 | case HDA_FIXUP_PINCTLS: |
| 814 | if (action != HDA_FIXUP_ACT_PROBE || !fix->v.pins) |
| 815 | break; |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 816 | codec_dbg(codec, "%s: Apply pinctl for %s\n", |
Takashi Iwai | fd10821 | 2013-01-10 10:18:14 +0100 | [diff] [blame] | 817 | codec->chip_name, modelname); |
| 818 | set_pin_targets(codec, fix->v.pins); |
| 819 | break; |
Takashi Iwai | 23d30f2 | 2012-05-07 17:17:32 +0200 | [diff] [blame] | 820 | default: |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 821 | codec_err(codec, "%s: Invalid fixup type %d\n", |
Takashi Iwai | 23d30f2 | 2012-05-07 17:17:32 +0200 | [diff] [blame] | 822 | codec->chip_name, fix->type); |
| 823 | break; |
| 824 | } |
Takashi Iwai | 1f57825 | 2013-01-23 18:10:10 +0100 | [diff] [blame] | 825 | if (!fix->chained || fix->chained_before) |
Takashi Iwai | 23d30f2 | 2012-05-07 17:17:32 +0200 | [diff] [blame] | 826 | break; |
| 827 | if (++depth > 10) |
| 828 | break; |
| 829 | id = fix->chain_id; |
| 830 | } |
| 831 | } |
Takashi Iwai | 1f57825 | 2013-01-23 18:10:10 +0100 | [diff] [blame] | 832 | |
| 833 | void snd_hda_apply_fixup(struct hda_codec *codec, int action) |
| 834 | { |
| 835 | if (codec->fixup_list) |
| 836 | apply_fixup(codec, codec->fixup_id, action, 0); |
| 837 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 838 | EXPORT_SYMBOL_GPL(snd_hda_apply_fixup); |
Takashi Iwai | 23d30f2 | 2012-05-07 17:17:32 +0200 | [diff] [blame] | 839 | |
David Henningsson | 2053141 | 2014-05-26 16:22:41 +0800 | [diff] [blame] | 840 | static bool pin_config_match(struct hda_codec *codec, |
| 841 | const struct hda_pintbl *pins) |
| 842 | { |
| 843 | for (; pins->nid; pins++) { |
| 844 | u32 def_conf = snd_hda_codec_get_pincfg(codec, pins->nid); |
Hui Wang | 37df094 | 2014-05-29 15:59:17 +0800 | [diff] [blame] | 845 | if (pins->val != def_conf) |
David Henningsson | 2053141 | 2014-05-26 16:22:41 +0800 | [diff] [blame] | 846 | return false; |
| 847 | } |
| 848 | return true; |
| 849 | } |
| 850 | |
| 851 | void snd_hda_pick_pin_fixup(struct hda_codec *codec, |
| 852 | const struct snd_hda_pin_quirk *pin_quirk, |
| 853 | const struct hda_fixup *fixlist) |
| 854 | { |
| 855 | const struct snd_hda_pin_quirk *pq; |
| 856 | |
David Henningsson | f5662e1 | 2014-07-22 14:09:34 +0200 | [diff] [blame] | 857 | if (codec->fixup_id != HDA_FIXUP_ID_NOT_SET) |
David Henningsson | 2053141 | 2014-05-26 16:22:41 +0800 | [diff] [blame] | 858 | return; |
| 859 | |
| 860 | for (pq = pin_quirk; pq->subvendor; pq++) { |
Hui Wang | 621b5a0 | 2014-05-26 16:22:42 +0800 | [diff] [blame] | 861 | if ((codec->subsystem_id & 0xffff0000) != (pq->subvendor << 16)) |
David Henningsson | 2053141 | 2014-05-26 16:22:41 +0800 | [diff] [blame] | 862 | continue; |
| 863 | if (codec->vendor_id != pq->codec) |
| 864 | continue; |
| 865 | if (pin_config_match(codec, pq->pins)) { |
| 866 | codec->fixup_id = pq->value; |
| 867 | #ifdef CONFIG_SND_DEBUG_VERBOSE |
| 868 | codec->fixup_name = pq->name; |
| 869 | #endif |
| 870 | codec->fixup_list = fixlist; |
| 871 | return; |
| 872 | } |
| 873 | } |
| 874 | } |
| 875 | EXPORT_SYMBOL_GPL(snd_hda_pick_pin_fixup); |
| 876 | |
Takashi Iwai | 23d30f2 | 2012-05-07 17:17:32 +0200 | [diff] [blame] | 877 | void snd_hda_pick_fixup(struct hda_codec *codec, |
| 878 | const struct hda_model_fixup *models, |
| 879 | const struct snd_pci_quirk *quirk, |
| 880 | const struct hda_fixup *fixlist) |
| 881 | { |
Takashi Iwai | 23d30f2 | 2012-05-07 17:17:32 +0200 | [diff] [blame] | 882 | const struct snd_pci_quirk *q; |
David Henningsson | f5662e1 | 2014-07-22 14:09:34 +0200 | [diff] [blame] | 883 | int id = HDA_FIXUP_ID_NOT_SET; |
Takashi Iwai | 23d30f2 | 2012-05-07 17:17:32 +0200 | [diff] [blame] | 884 | const char *name = NULL; |
| 885 | |
David Henningsson | f5662e1 | 2014-07-22 14:09:34 +0200 | [diff] [blame] | 886 | if (codec->fixup_id != HDA_FIXUP_ID_NOT_SET) |
| 887 | return; |
| 888 | |
Takashi Iwai | 23d30f2 | 2012-05-07 17:17:32 +0200 | [diff] [blame] | 889 | /* when model=nofixup is given, don't pick up any fixups */ |
| 890 | if (codec->modelname && !strcmp(codec->modelname, "nofixup")) { |
Takashi Iwai | c9ce6b2 | 2012-12-18 18:12:44 +0100 | [diff] [blame] | 891 | codec->fixup_list = NULL; |
David Henningsson | f5662e1 | 2014-07-22 14:09:34 +0200 | [diff] [blame] | 892 | codec->fixup_name = NULL; |
| 893 | codec->fixup_id = HDA_FIXUP_ID_NO_FIXUP; |
Takashi Iwai | 23d30f2 | 2012-05-07 17:17:32 +0200 | [diff] [blame] | 894 | return; |
| 895 | } |
| 896 | |
| 897 | if (codec->modelname && models) { |
| 898 | while (models->name) { |
| 899 | if (!strcmp(codec->modelname, models->name)) { |
David Henningsson | c21c8cf | 2014-05-26 16:22:40 +0800 | [diff] [blame] | 900 | codec->fixup_id = models->id; |
| 901 | codec->fixup_name = models->name; |
David Henningsson | 8fffe7d | 2014-06-19 22:07:19 +0200 | [diff] [blame] | 902 | codec->fixup_list = fixlist; |
David Henningsson | c21c8cf | 2014-05-26 16:22:40 +0800 | [diff] [blame] | 903 | return; |
Takashi Iwai | 23d30f2 | 2012-05-07 17:17:32 +0200 | [diff] [blame] | 904 | } |
| 905 | models++; |
| 906 | } |
| 907 | } |
David Henningsson | f5662e1 | 2014-07-22 14:09:34 +0200 | [diff] [blame] | 908 | if (quirk) { |
Takashi Iwai | 23d30f2 | 2012-05-07 17:17:32 +0200 | [diff] [blame] | 909 | q = snd_pci_quirk_lookup(codec->bus->pci, quirk); |
| 910 | if (q) { |
| 911 | id = q->value; |
| 912 | #ifdef CONFIG_SND_DEBUG_VERBOSE |
| 913 | name = q->name; |
| 914 | #endif |
| 915 | } |
| 916 | } |
David Henningsson | 639aa4b | 2012-07-18 18:02:53 +0200 | [diff] [blame] | 917 | if (id < 0 && quirk) { |
Takashi Iwai | 697aeba | 2013-08-01 08:38:27 +0200 | [diff] [blame] | 918 | for (q = quirk; q->subvendor || q->subdevice; q++) { |
Takashi Iwai | 23d30f2 | 2012-05-07 17:17:32 +0200 | [diff] [blame] | 919 | unsigned int vendorid = |
| 920 | q->subdevice | (q->subvendor << 16); |
Takashi Iwai | a33b7b0 | 2012-09-11 16:42:18 +0200 | [diff] [blame] | 921 | unsigned int mask = 0xffff0000 | q->subdevice_mask; |
| 922 | if ((codec->subsystem_id & mask) == (vendorid & mask)) { |
Takashi Iwai | 23d30f2 | 2012-05-07 17:17:32 +0200 | [diff] [blame] | 923 | id = q->value; |
| 924 | #ifdef CONFIG_SND_DEBUG_VERBOSE |
| 925 | name = q->name; |
| 926 | #endif |
| 927 | break; |
| 928 | } |
| 929 | } |
| 930 | } |
| 931 | |
Takashi Iwai | c9ce6b2 | 2012-12-18 18:12:44 +0100 | [diff] [blame] | 932 | codec->fixup_id = id; |
Takashi Iwai | 23d30f2 | 2012-05-07 17:17:32 +0200 | [diff] [blame] | 933 | if (id >= 0) { |
Takashi Iwai | c9ce6b2 | 2012-12-18 18:12:44 +0100 | [diff] [blame] | 934 | codec->fixup_list = fixlist; |
| 935 | codec->fixup_name = name; |
Takashi Iwai | 23d30f2 | 2012-05-07 17:17:32 +0200 | [diff] [blame] | 936 | } |
| 937 | } |
Takashi Iwai | 2698ea9 | 2013-12-18 07:45:52 +0100 | [diff] [blame] | 938 | EXPORT_SYMBOL_GPL(snd_hda_pick_fixup); |