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