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