Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
hda_auto_parser.c
Go to the documentation of this file.
1 /*
2  * BIOS auto-parser helper functions for HD-audio
3  *
4  * Copyright (c) 2012 Takashi Iwai <[email protected]>
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>
14 #include <sound/core.h>
15 #include "hda_codec.h"
16 #include "hda_local.h"
17 #include "hda_auto_parser.h"
18 
19 #define SFX "hda_codec: "
20 
21 /*
22  * Helper for automatic pin configuration
23  */
24 
25 static int is_in_nid_list(hda_nid_t nid, const hda_nid_t *list)
26 {
27  for (; *list; list++)
28  if (*list == nid)
29  return 1;
30  return 0;
31 }
32 
33 
34 /*
35  * Sort an associated group of pins according to their sequence numbers.
36  */
37 static void sort_pins_by_sequence(hda_nid_t *pins, short *sequences,
38  int num_pins)
39 {
40  int i, j;
41  short seq;
42  hda_nid_t nid;
43 
44  for (i = 0; i < num_pins; i++) {
45  for (j = i + 1; j < num_pins; j++) {
46  if (sequences[i] > sequences[j]) {
47  seq = sequences[i];
48  sequences[i] = sequences[j];
49  sequences[j] = seq;
50  nid = pins[i];
51  pins[i] = pins[j];
52  pins[j] = nid;
53  }
54  }
55  }
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 
70 /* sort inputs in the order of AUTO_PIN_* type */
71 static void sort_autocfg_input_pins(struct auto_pin_cfg *cfg)
72 {
73  int i, j;
74 
75  for (i = 0; i < cfg->num_inputs; i++) {
76  for (j = i + 1; j < cfg->num_inputs; j++) {
77  if (cfg->inputs[i].type > cfg->inputs[j].type) {
78  struct auto_pin_cfg_item tmp;
79  tmp = cfg->inputs[i];
80  cfg->inputs[i] = cfg->inputs[j];
81  cfg->inputs[j] = tmp;
82  }
83  }
84  }
85 }
86 
87 /* Reorder the surround channels
88  * ALSA sequence is front/surr/clfe/side
89  * HDA sequence is:
90  * 4-ch: front/surr => OK as it is
91  * 6-ch: front/clfe/surr
92  * 8-ch: front/clfe/rear/side|fc
93  */
94 static void reorder_outputs(unsigned int nums, hda_nid_t *pins)
95 {
96  hda_nid_t nid;
97 
98  switch (nums) {
99  case 3:
100  case 4:
101  nid = pins[1];
102  pins[1] = pins[2];
103  pins[2] = nid;
104  break;
105  }
106 }
107 
108 /*
109  * Parse all pin widgets and store the useful pin nids to cfg
110  *
111  * The number of line-outs or any primary output is stored in line_outs,
112  * and the corresponding output pins are assigned to line_out_pins[],
113  * in the order of front, rear, CLFE, side, ...
114  *
115  * If more extra outputs (speaker and headphone) are found, the pins are
116  * assisnged to hp_pins[] and speaker_pins[], respectively. If no line-out jack
117  * is detected, one of speaker of HP pins is assigned as the primary
118  * output, i.e. to line_out_pins[0]. So, line_outs is always positive
119  * if any analog output exists.
120  *
121  * The analog input pins are assigned to inputs array.
122  * The digital input/output pins are assigned to dig_in_pin and dig_out_pin,
123  * respectively.
124  */
126  struct auto_pin_cfg *cfg,
127  const hda_nid_t *ignore_nids,
128  unsigned int cond_flags)
129 {
130  hda_nid_t nid, end_nid;
131  short seq, assoc_line_out;
132  short sequences_line_out[ARRAY_SIZE(cfg->line_out_pins)];
133  short sequences_speaker[ARRAY_SIZE(cfg->speaker_pins)];
134  short sequences_hp[ARRAY_SIZE(cfg->hp_pins)];
135  int i;
136 
137  memset(cfg, 0, sizeof(*cfg));
138 
139  memset(sequences_line_out, 0, sizeof(sequences_line_out));
140  memset(sequences_speaker, 0, sizeof(sequences_speaker));
141  memset(sequences_hp, 0, sizeof(sequences_hp));
142  assoc_line_out = 0;
143 
144  end_nid = codec->start_nid + codec->num_nodes;
145  for (nid = codec->start_nid; nid < end_nid; nid++) {
146  unsigned int wid_caps = get_wcaps(codec, nid);
147  unsigned int wid_type = get_wcaps_type(wid_caps);
148  unsigned int def_conf;
149  short assoc, loc, conn, dev;
150 
151  /* read all default configuration for pin complex */
152  if (wid_type != AC_WID_PIN)
153  continue;
154  /* ignore the given nids (e.g. pc-beep returns error) */
155  if (ignore_nids && is_in_nid_list(nid, ignore_nids))
156  continue;
157 
158  def_conf = snd_hda_codec_get_pincfg(codec, nid);
159  conn = get_defcfg_connect(def_conf);
160  if (conn == AC_JACK_PORT_NONE)
161  continue;
162  loc = get_defcfg_location(def_conf);
163  dev = get_defcfg_device(def_conf);
164 
165  /* workaround for buggy BIOS setups */
166  if (dev == AC_JACK_LINE_OUT) {
167  if (conn == AC_JACK_PORT_FIXED)
168  dev = AC_JACK_SPEAKER;
169  }
170 
171  switch (dev) {
172  case AC_JACK_LINE_OUT:
173  seq = get_defcfg_sequence(def_conf);
174  assoc = get_defcfg_association(def_conf);
175 
176  if (!(wid_caps & AC_WCAP_STEREO))
177  if (!cfg->mono_out_pin)
178  cfg->mono_out_pin = nid;
179  if (!assoc)
180  continue;
181  if (!assoc_line_out)
182  assoc_line_out = assoc;
183  else if (assoc_line_out != assoc)
184  continue;
185  if (cfg->line_outs >= ARRAY_SIZE(cfg->line_out_pins))
186  continue;
187  cfg->line_out_pins[cfg->line_outs] = nid;
188  sequences_line_out[cfg->line_outs] = seq;
189  cfg->line_outs++;
190  break;
191  case AC_JACK_SPEAKER:
192  seq = get_defcfg_sequence(def_conf);
193  assoc = get_defcfg_association(def_conf);
194  if (cfg->speaker_outs >= ARRAY_SIZE(cfg->speaker_pins))
195  continue;
196  cfg->speaker_pins[cfg->speaker_outs] = nid;
197  sequences_speaker[cfg->speaker_outs] = (assoc << 4) | seq;
198  cfg->speaker_outs++;
199  break;
200  case AC_JACK_HP_OUT:
201  seq = get_defcfg_sequence(def_conf);
202  assoc = get_defcfg_association(def_conf);
203  if (cfg->hp_outs >= ARRAY_SIZE(cfg->hp_pins))
204  continue;
205  cfg->hp_pins[cfg->hp_outs] = nid;
206  sequences_hp[cfg->hp_outs] = (assoc << 4) | seq;
207  cfg->hp_outs++;
208  break;
209  case AC_JACK_MIC_IN:
210  add_auto_cfg_input_pin(cfg, nid, AUTO_PIN_MIC);
211  break;
212  case AC_JACK_LINE_IN:
213  add_auto_cfg_input_pin(cfg, nid, AUTO_PIN_LINE_IN);
214  break;
215  case AC_JACK_CD:
216  add_auto_cfg_input_pin(cfg, nid, AUTO_PIN_CD);
217  break;
218  case AC_JACK_AUX:
219  add_auto_cfg_input_pin(cfg, nid, AUTO_PIN_AUX);
220  break;
221  case AC_JACK_SPDIF_OUT:
223  if (cfg->dig_outs >= ARRAY_SIZE(cfg->dig_out_pins))
224  continue;
225  cfg->dig_out_pins[cfg->dig_outs] = nid;
226  cfg->dig_out_type[cfg->dig_outs] =
227  (loc == AC_JACK_LOC_HDMI) ?
229  cfg->dig_outs++;
230  break;
231  case AC_JACK_SPDIF_IN:
233  cfg->dig_in_pin = nid;
234  if (loc == AC_JACK_LOC_HDMI)
236  else
238  break;
239  }
240  }
241 
242  /* FIX-UP:
243  * If no line-out is defined but multiple HPs are found,
244  * some of them might be the real line-outs.
245  */
246  if (!cfg->line_outs && cfg->hp_outs > 1 &&
247  !(cond_flags & HDA_PINCFG_NO_HP_FIXUP)) {
248  int i = 0;
249  while (i < cfg->hp_outs) {
250  /* The real HPs should have the sequence 0x0f */
251  if ((sequences_hp[i] & 0x0f) == 0x0f) {
252  i++;
253  continue;
254  }
255  /* Move it to the line-out table */
256  cfg->line_out_pins[cfg->line_outs] = cfg->hp_pins[i];
257  sequences_line_out[cfg->line_outs] = sequences_hp[i];
258  cfg->line_outs++;
259  cfg->hp_outs--;
260  memmove(cfg->hp_pins + i, cfg->hp_pins + i + 1,
261  sizeof(cfg->hp_pins[0]) * (cfg->hp_outs - i));
262  memmove(sequences_hp + i, sequences_hp + i + 1,
263  sizeof(sequences_hp[0]) * (cfg->hp_outs - i));
264  }
265  memset(cfg->hp_pins + cfg->hp_outs, 0,
266  sizeof(hda_nid_t) * (AUTO_CFG_MAX_OUTS - cfg->hp_outs));
267  if (!cfg->hp_outs)
269 
270  }
271 
272  /* sort by sequence */
273  sort_pins_by_sequence(cfg->line_out_pins, sequences_line_out,
274  cfg->line_outs);
275  sort_pins_by_sequence(cfg->speaker_pins, sequences_speaker,
276  cfg->speaker_outs);
277  sort_pins_by_sequence(cfg->hp_pins, sequences_hp,
278  cfg->hp_outs);
279 
280  /*
281  * FIX-UP: if no line-outs are detected, try to use speaker or HP pin
282  * as a primary output
283  */
284  if (!cfg->line_outs &&
285  !(cond_flags & HDA_PINCFG_NO_LO_FIXUP)) {
286  if (cfg->speaker_outs) {
287  cfg->line_outs = cfg->speaker_outs;
288  memcpy(cfg->line_out_pins, cfg->speaker_pins,
289  sizeof(cfg->speaker_pins));
290  cfg->speaker_outs = 0;
291  memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins));
293  } else if (cfg->hp_outs) {
294  cfg->line_outs = cfg->hp_outs;
295  memcpy(cfg->line_out_pins, cfg->hp_pins,
296  sizeof(cfg->hp_pins));
297  cfg->hp_outs = 0;
298  memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
300  }
301  }
302 
303  reorder_outputs(cfg->line_outs, cfg->line_out_pins);
304  reorder_outputs(cfg->hp_outs, cfg->hp_pins);
305  reorder_outputs(cfg->speaker_outs, cfg->speaker_pins);
306 
307  sort_autocfg_input_pins(cfg);
308 
309  /*
310  * debug prints of the parsed results
311  */
312  snd_printd("autoconfig: line_outs=%d (0x%x/0x%x/0x%x/0x%x/0x%x) type:%s\n",
313  cfg->line_outs, cfg->line_out_pins[0], cfg->line_out_pins[1],
314  cfg->line_out_pins[2], cfg->line_out_pins[3],
315  cfg->line_out_pins[4],
316  cfg->line_out_type == AUTO_PIN_HP_OUT ? "hp" :
318  "speaker" : "line"));
319  snd_printd(" speaker_outs=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
320  cfg->speaker_outs, cfg->speaker_pins[0],
321  cfg->speaker_pins[1], cfg->speaker_pins[2],
322  cfg->speaker_pins[3], cfg->speaker_pins[4]);
323  snd_printd(" hp_outs=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
324  cfg->hp_outs, cfg->hp_pins[0],
325  cfg->hp_pins[1], cfg->hp_pins[2],
326  cfg->hp_pins[3], cfg->hp_pins[4]);
327  snd_printd(" mono: mono_out=0x%x\n", cfg->mono_out_pin);
328  if (cfg->dig_outs)
329  snd_printd(" dig-out=0x%x/0x%x\n",
330  cfg->dig_out_pins[0], cfg->dig_out_pins[1]);
331  snd_printd(" inputs:\n");
332  for (i = 0; i < cfg->num_inputs; i++) {
333  snd_printd(" %s=0x%x\n",
334  hda_get_autocfg_input_label(codec, cfg, i),
335  cfg->inputs[i].pin);
336  }
337  if (cfg->dig_in_pin)
338  snd_printd(" dig-in=0x%x\n", cfg->dig_in_pin);
339 
340  return 0;
341 }
343 
344 int snd_hda_get_input_pin_attr(unsigned int def_conf)
345 {
346  unsigned int loc = get_defcfg_location(def_conf);
347  unsigned int conn = get_defcfg_connect(def_conf);
348  if (conn == AC_JACK_PORT_NONE)
349  return INPUT_PIN_ATTR_UNUSED;
350  /* Windows may claim the internal mic to be BOTH, too */
351  if (conn == AC_JACK_PORT_FIXED || conn == AC_JACK_PORT_BOTH)
352  return INPUT_PIN_ATTR_INT;
353  if ((loc & 0x30) == AC_JACK_LOC_INTERNAL)
354  return INPUT_PIN_ATTR_INT;
355  if ((loc & 0x30) == AC_JACK_LOC_SEPARATE)
356  return INPUT_PIN_ATTR_DOCK;
357  if (loc == AC_JACK_LOC_REAR)
358  return INPUT_PIN_ATTR_REAR;
359  if (loc == AC_JACK_LOC_FRONT)
360  return INPUT_PIN_ATTR_FRONT;
361  return INPUT_PIN_ATTR_NORMAL;
362 }
364 
373 static const char *hda_get_input_pin_label(struct hda_codec *codec,
374  hda_nid_t pin, bool check_location)
375 {
376  unsigned int def_conf;
377  static const char * const mic_names[] = {
378  "Internal Mic", "Dock Mic", "Mic", "Front Mic", "Rear Mic",
379  };
380  int attr;
381 
382  def_conf = snd_hda_codec_get_pincfg(codec, pin);
383 
384  switch (get_defcfg_device(def_conf)) {
385  case AC_JACK_MIC_IN:
386  if (!check_location)
387  return "Mic";
388  attr = snd_hda_get_input_pin_attr(def_conf);
389  if (!attr)
390  return "None";
391  return mic_names[attr - 1];
392  case AC_JACK_LINE_IN:
393  if (!check_location)
394  return "Line";
395  attr = snd_hda_get_input_pin_attr(def_conf);
396  if (!attr)
397  return "None";
398  if (attr == INPUT_PIN_ATTR_DOCK)
399  return "Dock Line";
400  return "Line";
401  case AC_JACK_AUX:
402  return "Aux";
403  case AC_JACK_CD:
404  return "CD";
405  case AC_JACK_SPDIF_IN:
406  return "SPDIF In";
408  return "Digital In";
409  default:
410  return "Misc";
411  }
412 }
413 
414 /* Check whether the location prefix needs to be added to the label.
415  * If all mic-jacks are in the same location (e.g. rear panel), we don't
416  * have to put "Front" prefix to each label. In such a case, returns false.
417  */
418 static int check_mic_location_need(struct hda_codec *codec,
419  const struct auto_pin_cfg *cfg,
420  int input)
421 {
422  unsigned int defc;
423  int i, attr, attr2;
424 
425  defc = snd_hda_codec_get_pincfg(codec, cfg->inputs[input].pin);
426  attr = snd_hda_get_input_pin_attr(defc);
427  /* for internal or docking mics, we need locations */
428  if (attr <= INPUT_PIN_ATTR_NORMAL)
429  return 1;
430 
431  attr = 0;
432  for (i = 0; i < cfg->num_inputs; i++) {
433  defc = snd_hda_codec_get_pincfg(codec, cfg->inputs[i].pin);
434  attr2 = snd_hda_get_input_pin_attr(defc);
435  if (attr2 >= INPUT_PIN_ATTR_NORMAL) {
436  if (attr && attr != attr2)
437  return 1; /* different locations found */
438  attr = attr2;
439  }
440  }
441  return 0;
442 }
443 
452 const char *hda_get_autocfg_input_label(struct hda_codec *codec,
453  const struct auto_pin_cfg *cfg,
454  int input)
455 {
456  int type = cfg->inputs[input].type;
457  int has_multiple_pins = 0;
458 
459  if ((input > 0 && cfg->inputs[input - 1].type == type) ||
460  (input < cfg->num_inputs - 1 && cfg->inputs[input + 1].type == type))
461  has_multiple_pins = 1;
462  if (has_multiple_pins && type == AUTO_PIN_MIC)
463  has_multiple_pins &= check_mic_location_need(codec, cfg, input);
464  return hda_get_input_pin_label(codec, cfg->inputs[input].pin,
465  has_multiple_pins);
466 }
468 
469 /* return the position of NID in the list, or -1 if not found */
470 static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
471 {
472  int i;
473  for (i = 0; i < nums; i++)
474  if (list[i] == nid)
475  return i;
476  return -1;
477 }
478 
479 /* get a unique suffix or an index number */
480 static const char *check_output_sfx(hda_nid_t nid, const hda_nid_t *pins,
481  int num_pins, int *indexp)
482 {
483  static const char * const channel_sfx[] = {
484  " Front", " Surround", " CLFE", " Side"
485  };
486  int i;
487 
488  i = find_idx_in_nid_list(nid, pins, num_pins);
489  if (i < 0)
490  return NULL;
491  if (num_pins == 1)
492  return "";
493  if (num_pins > ARRAY_SIZE(channel_sfx)) {
494  if (indexp)
495  *indexp = i;
496  return "";
497  }
498  return channel_sfx[i];
499 }
500 
501 static const char *check_output_pfx(struct hda_codec *codec, hda_nid_t nid)
502 {
503  unsigned int def_conf = snd_hda_codec_get_pincfg(codec, nid);
504  int attr = snd_hda_get_input_pin_attr(def_conf);
505 
506  /* check the location */
507  switch (attr) {
508  case INPUT_PIN_ATTR_DOCK:
509  return "Dock ";
511  return "Front ";
512  }
513  return "";
514 }
515 
516 static int get_hp_label_index(struct hda_codec *codec, hda_nid_t nid,
517  const hda_nid_t *pins, int num_pins)
518 {
519  int i, j, idx = 0;
520 
521  const char *pfx = check_output_pfx(codec, nid);
522 
523  i = find_idx_in_nid_list(nid, pins, num_pins);
524  if (i < 0)
525  return -1;
526  for (j = 0; j < i; j++)
527  if (pfx == check_output_pfx(codec, pins[j]))
528  idx++;
529 
530  return idx;
531 }
532 
533 static int fill_audio_out_name(struct hda_codec *codec, hda_nid_t nid,
534  const struct auto_pin_cfg *cfg,
535  const char *name, char *label, int maxlen,
536  int *indexp)
537 {
538  unsigned int def_conf = snd_hda_codec_get_pincfg(codec, nid);
539  int attr = snd_hda_get_input_pin_attr(def_conf);
540  const char *pfx, *sfx = "";
541 
542  /* handle as a speaker if it's a fixed line-out */
543  if (!strcmp(name, "Line Out") && attr == INPUT_PIN_ATTR_INT)
544  name = "Speaker";
545  pfx = check_output_pfx(codec, nid);
546 
547  if (cfg) {
548  /* try to give a unique suffix if needed */
549  sfx = check_output_sfx(nid, cfg->line_out_pins, cfg->line_outs,
550  indexp);
551  if (!sfx)
552  sfx = check_output_sfx(nid, cfg->speaker_pins, cfg->speaker_outs,
553  indexp);
554  if (!sfx) {
555  /* don't add channel suffix for Headphone controls */
556  int idx = get_hp_label_index(codec, nid, cfg->hp_pins,
557  cfg->hp_outs);
558  if (idx >= 0)
559  *indexp = idx;
560  sfx = "";
561  }
562  }
563  snprintf(label, maxlen, "%s%s%s", pfx, name, sfx);
564  return 1;
565 }
566 
581  const struct auto_pin_cfg *cfg,
582  char *label, int maxlen, int *indexp)
583 {
584  unsigned int def_conf = snd_hda_codec_get_pincfg(codec, nid);
585  const char *name = NULL;
586  int i;
587 
588  if (indexp)
589  *indexp = 0;
590  if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
591  return 0;
592 
593  switch (get_defcfg_device(def_conf)) {
594  case AC_JACK_LINE_OUT:
595  return fill_audio_out_name(codec, nid, cfg, "Line Out",
596  label, maxlen, indexp);
597  case AC_JACK_SPEAKER:
598  return fill_audio_out_name(codec, nid, cfg, "Speaker",
599  label, maxlen, indexp);
600  case AC_JACK_HP_OUT:
601  return fill_audio_out_name(codec, nid, cfg, "Headphone",
602  label, maxlen, indexp);
603  case AC_JACK_SPDIF_OUT:
605  if (get_defcfg_location(def_conf) == AC_JACK_LOC_HDMI)
606  name = "HDMI";
607  else
608  name = "SPDIF";
609  if (cfg && indexp) {
610  i = find_idx_in_nid_list(nid, cfg->dig_out_pins,
611  cfg->dig_outs);
612  if (i >= 0)
613  *indexp = i;
614  }
615  break;
616  default:
617  if (cfg) {
618  for (i = 0; i < cfg->num_inputs; i++) {
619  if (cfg->inputs[i].pin != nid)
620  continue;
621  name = hda_get_autocfg_input_label(codec, cfg, i);
622  if (name)
623  break;
624  }
625  }
626  if (!name)
627  name = hda_get_input_pin_label(codec, nid, true);
628  break;
629  }
630  if (!name)
631  return 0;
632  strlcpy(label, name, maxlen);
633  return 1;
634 }
636 
638  const struct hda_verb *list)
639 {
640  const struct hda_verb **v;
641  v = snd_array_new(&spec->verbs);
642  if (!v)
643  return -ENOMEM;
644  *v = list;
645  return 0;
646 }
648 
650 {
651  struct hda_gen_spec *spec = codec->spec;
652  int i;
653  for (i = 0; i < spec->verbs.used; i++) {
654  struct hda_verb **v = snd_array_elem(&spec->verbs, i);
655  snd_hda_sequence_write(codec, *v);
656  }
657 }
659 
660 void snd_hda_apply_pincfgs(struct hda_codec *codec,
661  const struct hda_pintbl *cfg)
662 {
663  for (; cfg->nid; cfg++)
664  snd_hda_codec_set_pincfg(codec, cfg->nid, cfg->val);
665 }
667 
668 void snd_hda_apply_fixup(struct hda_codec *codec, int action)
669 {
670  struct hda_gen_spec *spec = codec->spec;
671  int id = spec->fixup_id;
672 #ifdef CONFIG_SND_DEBUG_VERBOSE
673  const char *modelname = spec->fixup_name;
674 #endif
675  int depth = 0;
676 
677  if (!spec->fixup_list)
678  return;
679 
680  while (id >= 0) {
681  const struct hda_fixup *fix = spec->fixup_list + id;
682 
683  switch (fix->type) {
684  case HDA_FIXUP_PINS:
685  if (action != HDA_FIXUP_ACT_PRE_PROBE || !fix->v.pins)
686  break;
688  "%s: Apply pincfg for %s\n",
689  codec->chip_name, modelname);
690  snd_hda_apply_pincfgs(codec, fix->v.pins);
691  break;
692  case HDA_FIXUP_VERBS:
693  if (action != HDA_FIXUP_ACT_PROBE || !fix->v.verbs)
694  break;
696  "%s: Apply fix-verbs for %s\n",
697  codec->chip_name, modelname);
698  snd_hda_gen_add_verbs(codec->spec, fix->v.verbs);
699  break;
700  case HDA_FIXUP_FUNC:
701  if (!fix->v.func)
702  break;
704  "%s: Apply fix-func for %s\n",
705  codec->chip_name, modelname);
706  fix->v.func(codec, fix, action);
707  break;
708  default:
709  snd_printk(KERN_ERR SFX
710  "%s: Invalid fixup type %d\n",
711  codec->chip_name, fix->type);
712  break;
713  }
714  if (!fix->chained)
715  break;
716  if (++depth > 10)
717  break;
718  id = fix->chain_id;
719  }
720 }
722 
723 void snd_hda_pick_fixup(struct hda_codec *codec,
724  const struct hda_model_fixup *models,
725  const struct snd_pci_quirk *quirk,
726  const struct hda_fixup *fixlist)
727 {
728  struct hda_gen_spec *spec = codec->spec;
729  const struct snd_pci_quirk *q;
730  int id = -1;
731  const char *name = NULL;
732 
733  /* when model=nofixup is given, don't pick up any fixups */
734  if (codec->modelname && !strcmp(codec->modelname, "nofixup")) {
735  spec->fixup_list = NULL;
736  spec->fixup_id = -1;
737  return;
738  }
739 
740  if (codec->modelname && models) {
741  while (models->name) {
742  if (!strcmp(codec->modelname, models->name)) {
743  id = models->id;
744  name = models->name;
745  break;
746  }
747  models++;
748  }
749  }
750  if (id < 0 && quirk) {
751  q = snd_pci_quirk_lookup(codec->bus->pci, quirk);
752  if (q) {
753  id = q->value;
754 #ifdef CONFIG_SND_DEBUG_VERBOSE
755  name = q->name;
756 #endif
757  }
758  }
759  if (id < 0 && quirk) {
760  for (q = quirk; q->subvendor; q++) {
761  unsigned int vendorid =
762  q->subdevice | (q->subvendor << 16);
763  unsigned int mask = 0xffff0000 | q->subdevice_mask;
764  if ((codec->subsystem_id & mask) == (vendorid & mask)) {
765  id = q->value;
766 #ifdef CONFIG_SND_DEBUG_VERBOSE
767  name = q->name;
768 #endif
769  break;
770  }
771  }
772  }
773 
774  spec->fixup_id = id;
775  if (id >= 0) {
776  spec->fixup_list = fixlist;
777  spec->fixup_name = name;
778  }
779 }