Merge branch 'topic/misc' into for-next
[deliverable/linux.git] / sound / pci / hda / hda_auto_parser.c
CommitLineData
23d30f28
TI
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>
14#include <sound/core.h>
15#include "hda_codec.h"
128bc4ba 16#include "hda_local.h"
23d30f28
TI
17#include "hda_auto_parser.h"
18
19#define SFX "hda_codec: "
20
128bc4ba
TI
21/*
22 * Helper for automatic pin configuration
23 */
24
25static 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 */
37static 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 */
60static 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 */
71static 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 */
94static 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 */
125int snd_hda_parse_pin_defcfg(struct hda_codec *codec,
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 codec->ignore_misc_bit = true;
145 end_nid = codec->start_nid + codec->num_nodes;
146 for (nid = codec->start_nid; nid < end_nid; nid++) {
147 unsigned int wid_caps = get_wcaps(codec, nid);
148 unsigned int wid_type = get_wcaps_type(wid_caps);
149 unsigned int def_conf;
150 short assoc, loc, conn, dev;
151
152 /* read all default configuration for pin complex */
153 if (wid_type != AC_WID_PIN)
154 continue;
155 /* ignore the given nids (e.g. pc-beep returns error) */
156 if (ignore_nids && is_in_nid_list(nid, ignore_nids))
157 continue;
158
159 def_conf = snd_hda_codec_get_pincfg(codec, nid);
160 if (!(get_defcfg_misc(snd_hda_codec_get_pincfg(codec, nid)) &
161 AC_DEFCFG_MISC_NO_PRESENCE))
162 codec->ignore_misc_bit = false;
163 conn = get_defcfg_connect(def_conf);
164 if (conn == AC_JACK_PORT_NONE)
165 continue;
166 loc = get_defcfg_location(def_conf);
167 dev = get_defcfg_device(def_conf);
168
169 /* workaround for buggy BIOS setups */
170 if (dev == AC_JACK_LINE_OUT) {
171 if (conn == AC_JACK_PORT_FIXED)
172 dev = AC_JACK_SPEAKER;
173 }
174
175 switch (dev) {
176 case AC_JACK_LINE_OUT:
177 seq = get_defcfg_sequence(def_conf);
178 assoc = get_defcfg_association(def_conf);
179
180 if (!(wid_caps & AC_WCAP_STEREO))
181 if (!cfg->mono_out_pin)
182 cfg->mono_out_pin = nid;
183 if (!assoc)
184 continue;
185 if (!assoc_line_out)
186 assoc_line_out = assoc;
187 else if (assoc_line_out != assoc)
188 continue;
189 if (cfg->line_outs >= ARRAY_SIZE(cfg->line_out_pins))
190 continue;
191 cfg->line_out_pins[cfg->line_outs] = nid;
192 sequences_line_out[cfg->line_outs] = seq;
193 cfg->line_outs++;
194 break;
195 case AC_JACK_SPEAKER:
196 seq = get_defcfg_sequence(def_conf);
197 assoc = get_defcfg_association(def_conf);
198 if (cfg->speaker_outs >= ARRAY_SIZE(cfg->speaker_pins))
199 continue;
200 cfg->speaker_pins[cfg->speaker_outs] = nid;
201 sequences_speaker[cfg->speaker_outs] = (assoc << 4) | seq;
202 cfg->speaker_outs++;
203 break;
204 case AC_JACK_HP_OUT:
205 seq = get_defcfg_sequence(def_conf);
206 assoc = get_defcfg_association(def_conf);
207 if (cfg->hp_outs >= ARRAY_SIZE(cfg->hp_pins))
208 continue;
209 cfg->hp_pins[cfg->hp_outs] = nid;
210 sequences_hp[cfg->hp_outs] = (assoc << 4) | seq;
211 cfg->hp_outs++;
212 break;
213 case AC_JACK_MIC_IN:
214 add_auto_cfg_input_pin(cfg, nid, AUTO_PIN_MIC);
215 break;
216 case AC_JACK_LINE_IN:
217 add_auto_cfg_input_pin(cfg, nid, AUTO_PIN_LINE_IN);
218 break;
219 case AC_JACK_CD:
220 add_auto_cfg_input_pin(cfg, nid, AUTO_PIN_CD);
221 break;
222 case AC_JACK_AUX:
223 add_auto_cfg_input_pin(cfg, nid, AUTO_PIN_AUX);
224 break;
225 case AC_JACK_SPDIF_OUT:
226 case AC_JACK_DIG_OTHER_OUT:
227 if (cfg->dig_outs >= ARRAY_SIZE(cfg->dig_out_pins))
228 continue;
229 cfg->dig_out_pins[cfg->dig_outs] = nid;
230 cfg->dig_out_type[cfg->dig_outs] =
231 (loc == AC_JACK_LOC_HDMI) ?
232 HDA_PCM_TYPE_HDMI : HDA_PCM_TYPE_SPDIF;
233 cfg->dig_outs++;
234 break;
235 case AC_JACK_SPDIF_IN:
236 case AC_JACK_DIG_OTHER_IN:
237 cfg->dig_in_pin = nid;
238 if (loc == AC_JACK_LOC_HDMI)
239 cfg->dig_in_type = HDA_PCM_TYPE_HDMI;
240 else
241 cfg->dig_in_type = HDA_PCM_TYPE_SPDIF;
242 break;
243 }
244 }
245
246 /* FIX-UP:
247 * If no line-out is defined but multiple HPs are found,
248 * some of them might be the real line-outs.
249 */
250 if (!cfg->line_outs && cfg->hp_outs > 1 &&
251 !(cond_flags & HDA_PINCFG_NO_HP_FIXUP)) {
252 int i = 0;
253 while (i < cfg->hp_outs) {
254 /* The real HPs should have the sequence 0x0f */
255 if ((sequences_hp[i] & 0x0f) == 0x0f) {
256 i++;
257 continue;
258 }
259 /* Move it to the line-out table */
260 cfg->line_out_pins[cfg->line_outs] = cfg->hp_pins[i];
261 sequences_line_out[cfg->line_outs] = sequences_hp[i];
262 cfg->line_outs++;
263 cfg->hp_outs--;
264 memmove(cfg->hp_pins + i, cfg->hp_pins + i + 1,
265 sizeof(cfg->hp_pins[0]) * (cfg->hp_outs - i));
266 memmove(sequences_hp + i, sequences_hp + i + 1,
267 sizeof(sequences_hp[0]) * (cfg->hp_outs - i));
268 }
269 memset(cfg->hp_pins + cfg->hp_outs, 0,
270 sizeof(hda_nid_t) * (AUTO_CFG_MAX_OUTS - cfg->hp_outs));
271 if (!cfg->hp_outs)
272 cfg->line_out_type = AUTO_PIN_HP_OUT;
273
274 }
275
276 /* sort by sequence */
277 sort_pins_by_sequence(cfg->line_out_pins, sequences_line_out,
278 cfg->line_outs);
279 sort_pins_by_sequence(cfg->speaker_pins, sequences_speaker,
280 cfg->speaker_outs);
281 sort_pins_by_sequence(cfg->hp_pins, sequences_hp,
282 cfg->hp_outs);
283
284 /*
285 * FIX-UP: if no line-outs are detected, try to use speaker or HP pin
286 * as a primary output
287 */
288 if (!cfg->line_outs &&
289 !(cond_flags & HDA_PINCFG_NO_LO_FIXUP)) {
290 if (cfg->speaker_outs) {
291 cfg->line_outs = cfg->speaker_outs;
292 memcpy(cfg->line_out_pins, cfg->speaker_pins,
293 sizeof(cfg->speaker_pins));
294 cfg->speaker_outs = 0;
295 memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins));
296 cfg->line_out_type = AUTO_PIN_SPEAKER_OUT;
297 } else if (cfg->hp_outs) {
298 cfg->line_outs = cfg->hp_outs;
299 memcpy(cfg->line_out_pins, cfg->hp_pins,
300 sizeof(cfg->hp_pins));
301 cfg->hp_outs = 0;
302 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
303 cfg->line_out_type = AUTO_PIN_HP_OUT;
304 }
305 }
306
307 reorder_outputs(cfg->line_outs, cfg->line_out_pins);
308 reorder_outputs(cfg->hp_outs, cfg->hp_pins);
309 reorder_outputs(cfg->speaker_outs, cfg->speaker_pins);
310
311 sort_autocfg_input_pins(cfg);
312
313 /*
314 * debug prints of the parsed results
315 */
316 snd_printd("autoconfig: line_outs=%d (0x%x/0x%x/0x%x/0x%x/0x%x) type:%s\n",
317 cfg->line_outs, cfg->line_out_pins[0], cfg->line_out_pins[1],
318 cfg->line_out_pins[2], cfg->line_out_pins[3],
319 cfg->line_out_pins[4],
320 cfg->line_out_type == AUTO_PIN_HP_OUT ? "hp" :
321 (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT ?
322 "speaker" : "line"));
323 snd_printd(" speaker_outs=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
324 cfg->speaker_outs, cfg->speaker_pins[0],
325 cfg->speaker_pins[1], cfg->speaker_pins[2],
326 cfg->speaker_pins[3], cfg->speaker_pins[4]);
327 snd_printd(" hp_outs=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
328 cfg->hp_outs, cfg->hp_pins[0],
329 cfg->hp_pins[1], cfg->hp_pins[2],
330 cfg->hp_pins[3], cfg->hp_pins[4]);
331 snd_printd(" mono: mono_out=0x%x\n", cfg->mono_out_pin);
332 if (cfg->dig_outs)
333 snd_printd(" dig-out=0x%x/0x%x\n",
334 cfg->dig_out_pins[0], cfg->dig_out_pins[1]);
335 snd_printd(" inputs:");
336 for (i = 0; i < cfg->num_inputs; i++) {
337 snd_printd(" %s=0x%x",
338 hda_get_autocfg_input_label(codec, cfg, i),
339 cfg->inputs[i].pin);
340 }
341 snd_printd("\n");
342 if (cfg->dig_in_pin)
343 snd_printd(" dig-in=0x%x\n", cfg->dig_in_pin);
344
345 return 0;
346}
347EXPORT_SYMBOL_HDA(snd_hda_parse_pin_defcfg);
348
349int snd_hda_get_input_pin_attr(unsigned int def_conf)
350{
351 unsigned int loc = get_defcfg_location(def_conf);
352 unsigned int conn = get_defcfg_connect(def_conf);
353 if (conn == AC_JACK_PORT_NONE)
354 return INPUT_PIN_ATTR_UNUSED;
355 /* Windows may claim the internal mic to be BOTH, too */
356 if (conn == AC_JACK_PORT_FIXED || conn == AC_JACK_PORT_BOTH)
357 return INPUT_PIN_ATTR_INT;
358 if ((loc & 0x30) == AC_JACK_LOC_INTERNAL)
359 return INPUT_PIN_ATTR_INT;
360 if ((loc & 0x30) == AC_JACK_LOC_SEPARATE)
361 return INPUT_PIN_ATTR_DOCK;
362 if (loc == AC_JACK_LOC_REAR)
363 return INPUT_PIN_ATTR_REAR;
364 if (loc == AC_JACK_LOC_FRONT)
365 return INPUT_PIN_ATTR_FRONT;
366 return INPUT_PIN_ATTR_NORMAL;
367}
368EXPORT_SYMBOL_HDA(snd_hda_get_input_pin_attr);
369
370/**
371 * hda_get_input_pin_label - Give a label for the given input pin
372 *
373 * When check_location is true, the function checks the pin location
374 * for mic and line-in pins, and set an appropriate prefix like "Front",
375 * "Rear", "Internal".
376 */
377
378static const char *hda_get_input_pin_label(struct hda_codec *codec,
379 hda_nid_t pin, bool check_location)
380{
381 unsigned int def_conf;
382 static const char * const mic_names[] = {
383 "Internal Mic", "Dock Mic", "Mic", "Front Mic", "Rear Mic",
384 };
385 int attr;
386
387 def_conf = snd_hda_codec_get_pincfg(codec, pin);
388
389 switch (get_defcfg_device(def_conf)) {
390 case AC_JACK_MIC_IN:
391 if (!check_location)
392 return "Mic";
393 attr = snd_hda_get_input_pin_attr(def_conf);
394 if (!attr)
395 return "None";
396 return mic_names[attr - 1];
397 case AC_JACK_LINE_IN:
398 if (!check_location)
399 return "Line";
400 attr = snd_hda_get_input_pin_attr(def_conf);
401 if (!attr)
402 return "None";
403 if (attr == INPUT_PIN_ATTR_DOCK)
404 return "Dock Line";
405 return "Line";
406 case AC_JACK_AUX:
407 return "Aux";
408 case AC_JACK_CD:
409 return "CD";
410 case AC_JACK_SPDIF_IN:
411 return "SPDIF In";
412 case AC_JACK_DIG_OTHER_IN:
413 return "Digital In";
414 default:
415 return "Misc";
416 }
417}
418
419/* Check whether the location prefix needs to be added to the label.
420 * If all mic-jacks are in the same location (e.g. rear panel), we don't
421 * have to put "Front" prefix to each label. In such a case, returns false.
422 */
423static int check_mic_location_need(struct hda_codec *codec,
424 const struct auto_pin_cfg *cfg,
425 int input)
426{
427 unsigned int defc;
428 int i, attr, attr2;
429
430 defc = snd_hda_codec_get_pincfg(codec, cfg->inputs[input].pin);
431 attr = snd_hda_get_input_pin_attr(defc);
432 /* for internal or docking mics, we need locations */
433 if (attr <= INPUT_PIN_ATTR_NORMAL)
434 return 1;
435
436 attr = 0;
437 for (i = 0; i < cfg->num_inputs; i++) {
438 defc = snd_hda_codec_get_pincfg(codec, cfg->inputs[i].pin);
439 attr2 = snd_hda_get_input_pin_attr(defc);
440 if (attr2 >= INPUT_PIN_ATTR_NORMAL) {
441 if (attr && attr != attr2)
442 return 1; /* different locations found */
443 attr = attr2;
444 }
445 }
446 return 0;
447}
448
449/**
450 * hda_get_autocfg_input_label - Get a label for the given input
451 *
452 * Get a label for the given input pin defined by the autocfg item.
453 * Unlike hda_get_input_pin_label(), this function checks all inputs
454 * defined in autocfg and avoids the redundant mic/line prefix as much as
455 * possible.
456 */
457const char *hda_get_autocfg_input_label(struct hda_codec *codec,
458 const struct auto_pin_cfg *cfg,
459 int input)
460{
461 int type = cfg->inputs[input].type;
462 int has_multiple_pins = 0;
463
464 if ((input > 0 && cfg->inputs[input - 1].type == type) ||
465 (input < cfg->num_inputs - 1 && cfg->inputs[input + 1].type == type))
466 has_multiple_pins = 1;
467 if (has_multiple_pins && type == AUTO_PIN_MIC)
468 has_multiple_pins &= check_mic_location_need(codec, cfg, input);
469 return hda_get_input_pin_label(codec, cfg->inputs[input].pin,
470 has_multiple_pins);
471}
472EXPORT_SYMBOL_HDA(hda_get_autocfg_input_label);
473
474/* return the position of NID in the list, or -1 if not found */
475static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
476{
477 int i;
478 for (i = 0; i < nums; i++)
479 if (list[i] == nid)
480 return i;
481 return -1;
482}
483
484/* get a unique suffix or an index number */
485static const char *check_output_sfx(hda_nid_t nid, const hda_nid_t *pins,
486 int num_pins, int *indexp)
487{
488 static const char * const channel_sfx[] = {
489 " Front", " Surround", " CLFE", " Side"
490 };
491 int i;
492
493 i = find_idx_in_nid_list(nid, pins, num_pins);
494 if (i < 0)
495 return NULL;
496 if (num_pins == 1)
497 return "";
498 if (num_pins > ARRAY_SIZE(channel_sfx)) {
499 if (indexp)
500 *indexp = i;
501 return "";
502 }
503 return channel_sfx[i];
504}
505
506static int fill_audio_out_name(struct hda_codec *codec, hda_nid_t nid,
507 const struct auto_pin_cfg *cfg,
508 const char *name, char *label, int maxlen,
509 int *indexp)
510{
511 unsigned int def_conf = snd_hda_codec_get_pincfg(codec, nid);
512 int attr = snd_hda_get_input_pin_attr(def_conf);
513 const char *pfx = "", *sfx = "";
514
515 /* handle as a speaker if it's a fixed line-out */
516 if (!strcmp(name, "Line Out") && attr == INPUT_PIN_ATTR_INT)
517 name = "Speaker";
518 /* check the location */
519 switch (attr) {
520 case INPUT_PIN_ATTR_DOCK:
521 pfx = "Dock ";
522 break;
523 case INPUT_PIN_ATTR_FRONT:
524 pfx = "Front ";
525 break;
526 }
527 if (cfg) {
528 /* try to give a unique suffix if needed */
529 sfx = check_output_sfx(nid, cfg->line_out_pins, cfg->line_outs,
530 indexp);
531 if (!sfx)
532 sfx = check_output_sfx(nid, cfg->speaker_pins, cfg->speaker_outs,
533 indexp);
534 if (!sfx) {
535 /* don't add channel suffix for Headphone controls */
536 int idx = find_idx_in_nid_list(nid, cfg->hp_pins,
537 cfg->hp_outs);
538 if (idx >= 0)
539 *indexp = idx;
540 sfx = "";
541 }
542 }
543 snprintf(label, maxlen, "%s%s%s", pfx, name, sfx);
544 return 1;
545}
546
547/**
548 * snd_hda_get_pin_label - Get a label for the given I/O pin
549 *
550 * Get a label for the given pin. This function works for both input and
551 * output pins. When @cfg is given as non-NULL, the function tries to get
552 * an optimized label using hda_get_autocfg_input_label().
553 *
554 * This function tries to give a unique label string for the pin as much as
555 * possible. For example, when the multiple line-outs are present, it adds
556 * the channel suffix like "Front", "Surround", etc (only when @cfg is given).
557 * If no unique name with a suffix is available and @indexp is non-NULL, the
558 * index number is stored in the pointer.
559 */
560int snd_hda_get_pin_label(struct hda_codec *codec, hda_nid_t nid,
561 const struct auto_pin_cfg *cfg,
562 char *label, int maxlen, int *indexp)
563{
564 unsigned int def_conf = snd_hda_codec_get_pincfg(codec, nid);
565 const char *name = NULL;
566 int i;
567
568 if (indexp)
569 *indexp = 0;
570 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
571 return 0;
572
573 switch (get_defcfg_device(def_conf)) {
574 case AC_JACK_LINE_OUT:
575 return fill_audio_out_name(codec, nid, cfg, "Line Out",
576 label, maxlen, indexp);
577 case AC_JACK_SPEAKER:
578 return fill_audio_out_name(codec, nid, cfg, "Speaker",
579 label, maxlen, indexp);
580 case AC_JACK_HP_OUT:
581 return fill_audio_out_name(codec, nid, cfg, "Headphone",
582 label, maxlen, indexp);
583 case AC_JACK_SPDIF_OUT:
584 case AC_JACK_DIG_OTHER_OUT:
585 if (get_defcfg_location(def_conf) == AC_JACK_LOC_HDMI)
586 name = "HDMI";
587 else
588 name = "SPDIF";
589 if (cfg && indexp) {
590 i = find_idx_in_nid_list(nid, cfg->dig_out_pins,
591 cfg->dig_outs);
592 if (i >= 0)
593 *indexp = i;
594 }
595 break;
596 default:
597 if (cfg) {
598 for (i = 0; i < cfg->num_inputs; i++) {
599 if (cfg->inputs[i].pin != nid)
600 continue;
601 name = hda_get_autocfg_input_label(codec, cfg, i);
602 if (name)
603 break;
604 }
605 }
606 if (!name)
607 name = hda_get_input_pin_label(codec, nid, true);
608 break;
609 }
610 if (!name)
611 return 0;
612 strlcpy(label, name, maxlen);
613 return 1;
614}
615EXPORT_SYMBOL_HDA(snd_hda_get_pin_label);
616
23d30f28
TI
617int snd_hda_gen_add_verbs(struct hda_gen_spec *spec,
618 const struct hda_verb *list)
619{
620 const struct hda_verb **v;
23d30f28
TI
621 v = snd_array_new(&spec->verbs);
622 if (!v)
623 return -ENOMEM;
624 *v = list;
625 return 0;
626}
627EXPORT_SYMBOL_HDA(snd_hda_gen_add_verbs);
628
629void snd_hda_gen_apply_verbs(struct hda_codec *codec)
630{
631 struct hda_gen_spec *spec = codec->spec;
632 int i;
633 for (i = 0; i < spec->verbs.used; i++) {
634 struct hda_verb **v = snd_array_elem(&spec->verbs, i);
635 snd_hda_sequence_write(codec, *v);
636 }
637}
638EXPORT_SYMBOL_HDA(snd_hda_gen_apply_verbs);
639
640void snd_hda_apply_pincfgs(struct hda_codec *codec,
641 const struct hda_pintbl *cfg)
642{
643 for (; cfg->nid; cfg++)
644 snd_hda_codec_set_pincfg(codec, cfg->nid, cfg->val);
645}
646EXPORT_SYMBOL_HDA(snd_hda_apply_pincfgs);
647
648void snd_hda_apply_fixup(struct hda_codec *codec, int action)
649{
650 struct hda_gen_spec *spec = codec->spec;
651 int id = spec->fixup_id;
652#ifdef CONFIG_SND_DEBUG_VERBOSE
653 const char *modelname = spec->fixup_name;
654#endif
655 int depth = 0;
656
657 if (!spec->fixup_list)
658 return;
659
660 while (id >= 0) {
661 const struct hda_fixup *fix = spec->fixup_list + id;
662
663 switch (fix->type) {
664 case HDA_FIXUP_PINS:
665 if (action != HDA_FIXUP_ACT_PRE_PROBE || !fix->v.pins)
666 break;
667 snd_printdd(KERN_INFO SFX
668 "%s: Apply pincfg for %s\n",
669 codec->chip_name, modelname);
670 snd_hda_apply_pincfgs(codec, fix->v.pins);
671 break;
672 case HDA_FIXUP_VERBS:
673 if (action != HDA_FIXUP_ACT_PROBE || !fix->v.verbs)
674 break;
675 snd_printdd(KERN_INFO SFX
676 "%s: Apply fix-verbs for %s\n",
677 codec->chip_name, modelname);
678 snd_hda_gen_add_verbs(codec->spec, fix->v.verbs);
679 break;
680 case HDA_FIXUP_FUNC:
681 if (!fix->v.func)
682 break;
683 snd_printdd(KERN_INFO SFX
684 "%s: Apply fix-func for %s\n",
685 codec->chip_name, modelname);
686 fix->v.func(codec, fix, action);
687 break;
688 default:
689 snd_printk(KERN_ERR SFX
690 "%s: Invalid fixup type %d\n",
691 codec->chip_name, fix->type);
692 break;
693 }
694 if (!fix->chained)
695 break;
696 if (++depth > 10)
697 break;
698 id = fix->chain_id;
699 }
700}
701EXPORT_SYMBOL_HDA(snd_hda_apply_fixup);
702
703void snd_hda_pick_fixup(struct hda_codec *codec,
704 const struct hda_model_fixup *models,
705 const struct snd_pci_quirk *quirk,
706 const struct hda_fixup *fixlist)
707{
708 struct hda_gen_spec *spec = codec->spec;
709 const struct snd_pci_quirk *q;
710 int id = -1;
711 const char *name = NULL;
712
713 /* when model=nofixup is given, don't pick up any fixups */
714 if (codec->modelname && !strcmp(codec->modelname, "nofixup")) {
715 spec->fixup_list = NULL;
716 spec->fixup_id = -1;
717 return;
718 }
719
720 if (codec->modelname && models) {
721 while (models->name) {
722 if (!strcmp(codec->modelname, models->name)) {
723 id = models->id;
724 name = models->name;
725 break;
726 }
727 models++;
728 }
729 }
730 if (id < 0) {
731 q = snd_pci_quirk_lookup(codec->bus->pci, quirk);
732 if (q) {
733 id = q->value;
734#ifdef CONFIG_SND_DEBUG_VERBOSE
735 name = q->name;
736#endif
737 }
738 }
739 if (id < 0) {
740 for (q = quirk; q->subvendor; q++) {
741 unsigned int vendorid =
742 q->subdevice | (q->subvendor << 16);
743 if (vendorid == codec->subsystem_id) {
744 id = q->value;
745#ifdef CONFIG_SND_DEBUG_VERBOSE
746 name = q->name;
747#endif
748 break;
749 }
750 }
751 }
752
753 spec->fixup_id = id;
754 if (id >= 0) {
755 spec->fixup_list = fixlist;
756 spec->fixup_name = name;
757 }
758}
759EXPORT_SYMBOL_HDA(snd_hda_pick_fixup);
This page took 0.058226 seconds and 5 git commands to generate.