1 /*
2 * Universal Interface for Intel High Definition Audio Codec
3 *
4 * HD audio interface patch for SigmaTel STAC92xx
5 *
6 * Copyright (c) 2005 Embedded Alley Solutions, Inc.
7 * Matt Porter <mporter@embeddedalley.com>
8 *
9 * Based on patch_cmedia.c and patch_realtek.c
10 * Copyright (c) 2004 Takashi Iwai <tiwai@suse.de>
11 *
12 * This driver is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This driver is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 */
26
27 #include <linux/init.h>
28 #include <linux/delay.h>
29 #include <linux/slab.h>
30 #include <linux/pci.h>
31 #include <sound/core.h>
32 #include <sound/asoundef.h>
33 #include <sound/jack.h>
34 #include "hda_codec.h"
35 #include "hda_local.h"
36 #include "hda_beep.h"
37
38 enum {
39 STAC_VREF_EVENT = 1,
40 STAC_INSERT_EVENT,
41 STAC_PWR_EVENT,
42 STAC_HP_EVENT,
43 };
44
45 enum {
46 STAC_AUTO,
47 STAC_REF,
48 STAC_9200_OQO,
49 STAC_9200_DELL_D21,
50 STAC_9200_DELL_D22,
51 STAC_9200_DELL_D23,
52 STAC_9200_DELL_M21,
53 STAC_9200_DELL_M22,
54 STAC_9200_DELL_M23,
55 STAC_9200_DELL_M24,
56 STAC_9200_DELL_M25,
57 STAC_9200_DELL_M26,
58 STAC_9200_DELL_M27,
59 STAC_9200_M4,
60 STAC_9200_M4_2,
61 STAC_9200_PANASONIC,
62 STAC_9200_MODELS
63 };
64
65 enum {
66 STAC_9205_AUTO,
67 STAC_9205_REF,
68 STAC_9205_DELL_M42,
69 STAC_9205_DELL_M43,
70 STAC_9205_DELL_M44,
71 STAC_9205_EAPD,
72 STAC_9205_MODELS
73 };
74
75 enum {
76 STAC_92HD73XX_AUTO,
77 STAC_92HD73XX_NO_JD, /* no jack-detection */
78 STAC_92HD73XX_REF,
79 STAC_92HD73XX_INTEL,
80 STAC_DELL_M6_AMIC,
81 STAC_DELL_M6_DMIC,
82 STAC_DELL_M6_BOTH,
83 STAC_DELL_EQ,
84 STAC_92HD73XX_MODELS
85 };
86
87 enum {
88 STAC_92HD83XXX_AUTO,
89 STAC_92HD83XXX_REF,
90 STAC_92HD83XXX_PWR_REF,
91 STAC_DELL_S14,
92 STAC_92HD83XXX_MODELS
93 };
94
95 enum {
96 STAC_92HD71BXX_AUTO,
97 STAC_92HD71BXX_REF,
98 STAC_DELL_M4_1,
99 STAC_DELL_M4_2,
100 STAC_DELL_M4_3,
101 STAC_HP_M4,
102 STAC_HP_DV5,
103 STAC_HP_HDX,
104 STAC_HP_DV4_1222NR,
105 STAC_92HD71BXX_MODELS
106 };
107
108 enum {
109 STAC_925x_AUTO,
110 STAC_925x_REF,
111 STAC_M1,
112 STAC_M1_2,
113 STAC_M2,
114 STAC_M2_2,
115 STAC_M3,
116 STAC_M5,
117 STAC_M6,
118 STAC_925x_MODELS
119 };
120
121 enum {
122 STAC_922X_AUTO,
123 STAC_D945_REF,
124 STAC_D945GTP3,
125 STAC_D945GTP5,
126 STAC_INTEL_MAC_V1,
127 STAC_INTEL_MAC_V2,
128 STAC_INTEL_MAC_V3,
129 STAC_INTEL_MAC_V4,
130 STAC_INTEL_MAC_V5,
131 STAC_INTEL_MAC_AUTO, /* This model is selected if no module parameter
132 * is given, one of the above models will be
133 * chosen according to the subsystem id. */
134 /* for backward compatibility */
135 STAC_MACMINI,
136 STAC_MACBOOK,
137 STAC_MACBOOK_PRO_V1,
138 STAC_MACBOOK_PRO_V2,
139 STAC_IMAC_INTEL,
140 STAC_IMAC_INTEL_20,
141 STAC_ECS_202,
142 STAC_922X_DELL_D81,
143 STAC_922X_DELL_D82,
144 STAC_922X_DELL_M81,
145 STAC_922X_DELL_M82,
146 STAC_922X_MODELS
147 };
148
149 enum {
150 STAC_927X_AUTO,
151 STAC_D965_REF_NO_JD, /* no jack-detection */
152 STAC_D965_REF,
153 STAC_D965_3ST,
154 STAC_D965_5ST,
155 STAC_D965_5ST_NO_FP,
156 STAC_DELL_3ST,
157 STAC_DELL_BIOS,
158 STAC_927X_MODELS
159 };
160
161 enum {
162 STAC_9872_AUTO,
163 STAC_9872_VAIO,
164 STAC_9872_MODELS
165 };
166
167 struct sigmatel_event {
168 hda_nid_t nid;
169 unsigned char type;
170 unsigned char tag;
171 int data;
172 };
173
174 struct sigmatel_jack {
175 hda_nid_t nid;
176 int type;
177 struct snd_jack *jack;
178 };
179
180 struct sigmatel_spec {
181 struct snd_kcontrol_new *mixers[4];
182 unsigned int num_mixers;
183
184 int board_config;
185 unsigned int eapd_switch: 1;
186 unsigned int surr_switch: 1;
187 unsigned int alt_switch: 1;
188 unsigned int hp_detect: 1;
189 unsigned int spdif_mute: 1;
190 unsigned int check_volume_offset:1;
191
192 /* gpio lines */
193 unsigned int eapd_mask;
194 unsigned int gpio_mask;
195 unsigned int gpio_dir;
196 unsigned int gpio_data;
197 unsigned int gpio_mute;
198 unsigned int gpio_led;
199
200 /* stream */
201 unsigned int stream_delay;
202
203 /* analog loopback */
204 struct snd_kcontrol_new *aloopback_ctl;
205 unsigned char aloopback_mask;
206 unsigned char aloopback_shift;
207
208 /* power management */
209 unsigned int num_pwrs;
210 unsigned int *pwr_mapping;
211 hda_nid_t *pwr_nids;
212 hda_nid_t *dac_list;
213
214 /* jack detection */
215 struct snd_array jacks;
216
217 /* events */
218 struct snd_array events;
219
220 /* playback */
221 struct hda_input_mux *mono_mux;
222 struct hda_input_mux *amp_mux;
223 unsigned int cur_mmux;
224 struct hda_multi_out multiout;
225 hda_nid_t dac_nids[5];
226 hda_nid_t hp_dacs[5];
227 hda_nid_t speaker_dacs[5];
228
229 int volume_offset;
230
231 /* capture */
232 hda_nid_t *adc_nids;
233 unsigned int num_adcs;
234 hda_nid_t *mux_nids;
235 unsigned int num_muxes;
236 hda_nid_t *dmic_nids;
237 unsigned int num_dmics;
238 hda_nid_t *dmux_nids;
239 unsigned int num_dmuxes;
240 hda_nid_t *smux_nids;
241 unsigned int num_smuxes;
242 const char **spdif_labels;
243
244 hda_nid_t dig_in_nid;
245 hda_nid_t mono_nid;
246 hda_nid_t anabeep_nid;
247 hda_nid_t digbeep_nid;
248
249 /* pin widgets */
250 hda_nid_t *pin_nids;
251 unsigned int num_pins;
252
253 /* codec specific stuff */
254 struct hda_verb *init;
255 struct snd_kcontrol_new *mixer;
256
257 /* capture source */
258 struct hda_input_mux *dinput_mux;
259 unsigned int cur_dmux[2];
260 struct hda_input_mux *input_mux;
261 unsigned int cur_mux[3];
262 struct hda_input_mux *sinput_mux;
263 unsigned int cur_smux[2];
264 unsigned int cur_amux;
265 hda_nid_t *amp_nids;
266 unsigned int num_amps;
267 unsigned int powerdown_adcs;
268
269 /* i/o switches */
270 unsigned int io_switch[2];
271 unsigned int clfe_swap;
272 hda_nid_t line_switch; /* shared line-in for input and output */
273 hda_nid_t mic_switch; /* shared mic-in for input and output */
274 hda_nid_t hp_switch; /* NID of HP as line-out */
275 unsigned int aloopback;
276
277 struct hda_pcm pcm_rec[2]; /* PCM information */
278
279 /* dynamic controls and input_mux */
280 struct auto_pin_cfg autocfg;
281 struct snd_array kctls;
282 struct hda_input_mux private_dimux;
283 struct hda_input_mux private_imux;
284 struct hda_input_mux private_smux;
285 struct hda_input_mux private_amp_mux;
286 struct hda_input_mux private_mono_mux;
287 };
288
289 static hda_nid_t stac9200_adc_nids[1] = {
290 0x03,
291 };
292
293 static hda_nid_t stac9200_mux_nids[1] = {
294 0x0c,
295 };
296
297 static hda_nid_t stac9200_dac_nids[1] = {
298 0x02,
299 };
300
301 static hda_nid_t stac92hd73xx_pwr_nids[8] = {
302 0x0a, 0x0b, 0x0c, 0xd, 0x0e,
303 0x0f, 0x10, 0x11
304 };
305
306 static hda_nid_t stac92hd73xx_slave_dig_outs[2] = {
307 0x26, 0,
308 };
309
310 static hda_nid_t stac92hd73xx_adc_nids[2] = {
311 0x1a, 0x1b
312 };
313
314 #define DELL_M6_AMP 2
315 static hda_nid_t stac92hd73xx_amp_nids[3] = {
316 0x0b, 0x0c, 0x0e
317 };
318
319 #define STAC92HD73XX_NUM_DMICS 2
320 static hda_nid_t stac92hd73xx_dmic_nids[STAC92HD73XX_NUM_DMICS + 1] = {
321 0x13, 0x14, 0
322 };
323
324 #define STAC92HD73_DAC_COUNT 5
325
326 static hda_nid_t stac92hd73xx_mux_nids[4] = {
327 0x28, 0x29, 0x2a, 0x2b,
328 };
329
330 static hda_nid_t stac92hd73xx_dmux_nids[2] = {
331 0x20, 0x21,
332 };
333
334 static hda_nid_t stac92hd73xx_smux_nids[2] = {
335 0x22, 0x23,
336 };
337
338 #define STAC92HD83XXX_NUM_DMICS 2
339 static hda_nid_t stac92hd83xxx_dmic_nids[STAC92HD83XXX_NUM_DMICS + 1] = {
340 0x11, 0x12, 0
341 };
342
343 #define STAC92HD83_DAC_COUNT 3
344
345 static hda_nid_t stac92hd83xxx_dmux_nids[2] = {
346 0x17, 0x18,
347 };
348
349 static hda_nid_t stac92hd83xxx_adc_nids[2] = {
350 0x15, 0x16,
351 };
352
353 static hda_nid_t stac92hd83xxx_pwr_nids[4] = {
354 0xa, 0xb, 0xd, 0xe,
355 };
356
357 static hda_nid_t stac92hd83xxx_slave_dig_outs[2] = {
358 0x1e, 0,
359 };
360
361 static unsigned int stac92hd83xxx_pwr_mapping[4] = {
362 0x03, 0x0c, 0x20, 0x40,
363 };
364
365 static hda_nid_t stac92hd83xxx_amp_nids[1] = {
366 0xc,
367 };
368
369 static hda_nid_t stac92hd71bxx_pwr_nids[3] = {
370 0x0a, 0x0d, 0x0f
371 };
372
373 static hda_nid_t stac92hd71bxx_adc_nids[2] = {
374 0x12, 0x13,
375 };
376
377 static hda_nid_t stac92hd71bxx_mux_nids[2] = {
378 0x1a, 0x1b
379 };
380
381 static hda_nid_t stac92hd71bxx_dmux_nids[2] = {
382 0x1c, 0x1d,
383 };
384
385 static hda_nid_t stac92hd71bxx_smux_nids[2] = {
386 0x24, 0x25,
387 };
388
389 #define STAC92HD71BXX_NUM_DMICS 2
390 static hda_nid_t stac92hd71bxx_dmic_nids[STAC92HD71BXX_NUM_DMICS + 1] = {
391 0x18, 0x19, 0
392 };
393
394 static hda_nid_t stac92hd71bxx_slave_dig_outs[2] = {
395 0x22, 0
396 };
397
398 static hda_nid_t stac925x_adc_nids[1] = {
399 0x03,
400 };
401
402 static hda_nid_t stac925x_mux_nids[1] = {
403 0x0f,
404 };
405
406 static hda_nid_t stac925x_dac_nids[1] = {
407 0x02,
408 };
409
410 #define STAC925X_NUM_DMICS 1
411 static hda_nid_t stac925x_dmic_nids[STAC925X_NUM_DMICS + 1] = {
412 0x15, 0
413 };
414
415 static hda_nid_t stac925x_dmux_nids[1] = {
416 0x14,
417 };
418
419 static hda_nid_t stac922x_adc_nids[2] = {
420 0x06, 0x07,
421 };
422
423 static hda_nid_t stac922x_mux_nids[2] = {
424 0x12, 0x13,
425 };
426
427 static hda_nid_t stac927x_slave_dig_outs[2] = {
428 0x1f, 0,
429 };
430
431 static hda_nid_t stac927x_adc_nids[3] = {
432 0x07, 0x08, 0x09
433 };
434
435 static hda_nid_t stac927x_mux_nids[3] = {
436 0x15, 0x16, 0x17
437 };
438
439 static hda_nid_t stac927x_smux_nids[1] = {
440 0x21,
441 };
442
443 static hda_nid_t stac927x_dac_nids[6] = {
444 0x02, 0x03, 0x04, 0x05, 0x06, 0
445 };
446
447 static hda_nid_t stac927x_dmux_nids[1] = {
448 0x1b,
449 };
450
451 #define STAC927X_NUM_DMICS 2
452 static hda_nid_t stac927x_dmic_nids[STAC927X_NUM_DMICS + 1] = {
453 0x13, 0x14, 0
454 };
455
456 static const char *stac927x_spdif_labels[5] = {
457 "Digital Playback", "ADAT", "Analog Mux 1",
458 "Analog Mux 2", "Analog Mux 3"
459 };
460
461 static hda_nid_t stac9205_adc_nids[2] = {
462 0x12, 0x13
463 };
464
465 static hda_nid_t stac9205_mux_nids[2] = {
466 0x19, 0x1a
467 };
468
469 static hda_nid_t stac9205_dmux_nids[1] = {
470 0x1d,
471 };
472
473 static hda_nid_t stac9205_smux_nids[1] = {
474 0x21,
475 };
476
477 #define STAC9205_NUM_DMICS 2
478 static hda_nid_t stac9205_dmic_nids[STAC9205_NUM_DMICS + 1] = {
479 0x17, 0x18, 0
480 };
481
482 static hda_nid_t stac9200_pin_nids[8] = {
483 0x08, 0x09, 0x0d, 0x0e,
484 0x0f, 0x10, 0x11, 0x12,
485 };
486
487 static hda_nid_t stac925x_pin_nids[8] = {
488 0x07, 0x08, 0x0a, 0x0b,
489 0x0c, 0x0d, 0x10, 0x11,
490 };
491
492 static hda_nid_t stac922x_pin_nids[10] = {
493 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
494 0x0f, 0x10, 0x11, 0x15, 0x1b,
495 };
496
497 static hda_nid_t stac92hd73xx_pin_nids[13] = {
498 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
499 0x0f, 0x10, 0x11, 0x12, 0x13,
500 0x14, 0x22, 0x23
501 };
502
503 static hda_nid_t stac92hd83xxx_pin_nids[10] = {
504 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
505 0x0f, 0x10, 0x11, 0x1f, 0x20,
506 };
507
508 #define STAC92HD71BXX_NUM_PINS 13
509 static hda_nid_t stac92hd71bxx_pin_nids_4port[STAC92HD71BXX_NUM_PINS] = {
510 0x0a, 0x0b, 0x0c, 0x0d, 0x00,
511 0x00, 0x14, 0x18, 0x19, 0x1e,
512 0x1f, 0x20, 0x27
513 };
514 static hda_nid_t stac92hd71bxx_pin_nids_6port[STAC92HD71BXX_NUM_PINS] = {
515 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
516 0x0f, 0x14, 0x18, 0x19, 0x1e,
517 0x1f, 0x20, 0x27
518 };
519
520 static hda_nid_t stac927x_pin_nids[14] = {
521 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
522 0x0f, 0x10, 0x11, 0x12, 0x13,
523 0x14, 0x21, 0x22, 0x23,
524 };
525
526 static hda_nid_t stac9205_pin_nids[12] = {
527 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
528 0x0f, 0x14, 0x16, 0x17, 0x18,
529 0x21, 0x22,
530 };
531
532 #define stac92xx_amp_volume_info snd_hda_mixer_amp_volume_info
533
534 static int stac92xx_amp_volume_get(struct snd_kcontrol *kcontrol,
535 struct snd_ctl_elem_value *ucontrol)
536 {
537 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
538 struct sigmatel_spec *spec = codec->spec;
539 hda_nid_t nid = spec->amp_nids[spec->cur_amux];
540
541 kcontrol->private_value ^= get_amp_nid(kcontrol);
542 kcontrol->private_value |= nid;
543
544 return snd_hda_mixer_amp_volume_get(kcontrol, ucontrol);
545 }
546
547 static int stac92xx_amp_volume_put(struct snd_kcontrol *kcontrol,
548 struct snd_ctl_elem_value *ucontrol)
549 {
550 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
551 struct sigmatel_spec *spec = codec->spec;
552 hda_nid_t nid = spec->amp_nids[spec->cur_amux];
553
554 kcontrol->private_value ^= get_amp_nid(kcontrol);
555 kcontrol->private_value |= nid;
556
557 return snd_hda_mixer_amp_volume_put(kcontrol, ucontrol);
558 }
559
560 static int stac92xx_dmux_enum_info(struct snd_kcontrol *kcontrol,
561 struct snd_ctl_elem_info *uinfo)
562 {
563 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
564 struct sigmatel_spec *spec = codec->spec;
565 return snd_hda_input_mux_info(spec->dinput_mux, uinfo);
566 }
567
568 static int stac92xx_dmux_enum_get(struct snd_kcontrol *kcontrol,
569 struct snd_ctl_elem_value *ucontrol)
570 {
571 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
572 struct sigmatel_spec *spec = codec->spec;
573 unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
574
575 ucontrol->value.enumerated.item[0] = spec->cur_dmux[dmux_idx];
576 return 0;
577 }
578
579 static int stac92xx_dmux_enum_put(struct snd_kcontrol *kcontrol,
580 struct snd_ctl_elem_value *ucontrol)
581 {
582 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
583 struct sigmatel_spec *spec = codec->spec;
584 unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
585
586 return snd_hda_input_mux_put(codec, spec->dinput_mux, ucontrol,
587 spec->dmux_nids[dmux_idx], &spec->cur_dmux[dmux_idx]);
588 }
589
590 static int stac92xx_smux_enum_info(struct snd_kcontrol *kcontrol,
591 struct snd_ctl_elem_info *uinfo)
592 {
593 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
594 struct sigmatel_spec *spec = codec->spec;
595 return snd_hda_input_mux_info(spec->sinput_mux, uinfo);
596 }
597
598 static int stac92xx_smux_enum_get(struct snd_kcontrol *kcontrol,
599 struct snd_ctl_elem_value *ucontrol)
600 {
601 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
602 struct sigmatel_spec *spec = codec->spec;
603 unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
604
605 ucontrol->value.enumerated.item[0] = spec->cur_smux[smux_idx];
606 return 0;
607 }
608
609 static int stac92xx_smux_enum_put(struct snd_kcontrol *kcontrol,
610 struct snd_ctl_elem_value *ucontrol)
611 {
612 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
613 struct sigmatel_spec *spec = codec->spec;
614 struct hda_input_mux *smux = &spec->private_smux;
615 unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
616 int err, val;
617 hda_nid_t nid;
618
619 err = snd_hda_input_mux_put(codec, spec->sinput_mux, ucontrol,
620 spec->smux_nids[smux_idx], &spec->cur_smux[smux_idx]);
621 if (err < 0)
622 return err;
623
624 if (spec->spdif_mute) {
625 if (smux_idx == 0)
626 nid = spec->multiout.dig_out_nid;
627 else
628 nid = codec->slave_dig_outs[smux_idx - 1];
629 if (spec->cur_smux[smux_idx] == smux->num_items - 1)
630 val = HDA_AMP_MUTE;
631 else
632 val = 0;
633 /* un/mute SPDIF out */
634 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
635 HDA_AMP_MUTE, val);
636 }
637 return 0;
638 }
639
640 static unsigned int stac92xx_vref_set(struct hda_codec *codec,
641 hda_nid_t nid, unsigned int new_vref)
642 {
643 int error;
644 unsigned int pincfg;
645 pincfg = snd_hda_codec_read(codec, nid, 0,
646 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
647
648 pincfg &= 0xff;
649 pincfg &= ~(AC_PINCTL_VREFEN | AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
650 pincfg |= new_vref;
651
652 if (new_vref == AC_PINCTL_VREF_HIZ)
653 pincfg |= AC_PINCTL_OUT_EN;
654 else
655 pincfg |= AC_PINCTL_IN_EN;
656
657 error = snd_hda_codec_write_cache(codec, nid, 0,
658 AC_VERB_SET_PIN_WIDGET_CONTROL, pincfg);
659 if (error < 0)
660 return error;
661 else
662 return 1;
663 }
664
665 static unsigned int stac92xx_vref_get(struct hda_codec *codec, hda_nid_t nid)
666 {
667 unsigned int vref;
668 vref = snd_hda_codec_read(codec, nid, 0,
669 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
670 vref &= AC_PINCTL_VREFEN;
671 return vref;
672 }
673
674 static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
675 {
676 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
677 struct sigmatel_spec *spec = codec->spec;
678 return snd_hda_input_mux_info(spec->input_mux, uinfo);
679 }
680
681 static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
682 {
683 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
684 struct sigmatel_spec *spec = codec->spec;
685 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
686
687 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
688 return 0;
689 }
690
691 static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
692 {
693 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
694 struct sigmatel_spec *spec = codec->spec;
695 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
696
697 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
698 spec->mux_nids[adc_idx], &spec->cur_mux[adc_idx]);
699 }
700
701 static int stac92xx_mono_mux_enum_info(struct snd_kcontrol *kcontrol,
702 struct snd_ctl_elem_info *uinfo)
703 {
704 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
705 struct sigmatel_spec *spec = codec->spec;
706 return snd_hda_input_mux_info(spec->mono_mux, uinfo);
707 }
708
709 static int stac92xx_mono_mux_enum_get(struct snd_kcontrol *kcontrol,
710 struct snd_ctl_elem_value *ucontrol)
711 {
712 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
713 struct sigmatel_spec *spec = codec->spec;
714
715 ucontrol->value.enumerated.item[0] = spec->cur_mmux;
716 return 0;
717 }
718
719 static int stac92xx_mono_mux_enum_put(struct snd_kcontrol *kcontrol,
720 struct snd_ctl_elem_value *ucontrol)
721 {
722 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
723 struct sigmatel_spec *spec = codec->spec;
724
725 return snd_hda_input_mux_put(codec, spec->mono_mux, ucontrol,
726 spec->mono_nid, &spec->cur_mmux);
727 }
728
729 static int stac92xx_amp_mux_enum_info(struct snd_kcontrol *kcontrol,
730 struct snd_ctl_elem_info *uinfo)
731 {
732 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
733 struct sigmatel_spec *spec = codec->spec;
734 return snd_hda_input_mux_info(spec->amp_mux, uinfo);
735 }
736
737 static int stac92xx_amp_mux_enum_get(struct snd_kcontrol *kcontrol,
738 struct snd_ctl_elem_value *ucontrol)
739 {
740 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
741 struct sigmatel_spec *spec = codec->spec;
742
743 ucontrol->value.enumerated.item[0] = spec->cur_amux;
744 return 0;
745 }
746
747 static int stac92xx_amp_mux_enum_put(struct snd_kcontrol *kcontrol,
748 struct snd_ctl_elem_value *ucontrol)
749 {
750 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
751 struct sigmatel_spec *spec = codec->spec;
752 struct snd_kcontrol *ctl =
753 snd_hda_find_mixer_ctl(codec, "Amp Capture Volume");
754 if (!ctl)
755 return -EINVAL;
756
757 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE |
758 SNDRV_CTL_EVENT_MASK_INFO, &ctl->id);
759
760 return snd_hda_input_mux_put(codec, spec->amp_mux, ucontrol,
761 0, &spec->cur_amux);
762 }
763
764 #define stac92xx_aloopback_info snd_ctl_boolean_mono_info
765
766 static int stac92xx_aloopback_get(struct snd_kcontrol *kcontrol,
767 struct snd_ctl_elem_value *ucontrol)
768 {
769 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
770 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
771 struct sigmatel_spec *spec = codec->spec;
772
773 ucontrol->value.integer.value[0] = !!(spec->aloopback &
774 (spec->aloopback_mask << idx));
775 return 0;
776 }
777
778 static int stac92xx_aloopback_put(struct snd_kcontrol *kcontrol,
779 struct snd_ctl_elem_value *ucontrol)
780 {
781 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
782 struct sigmatel_spec *spec = codec->spec;
783 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
784 unsigned int dac_mode;
785 unsigned int val, idx_val;
786
787 idx_val = spec->aloopback_mask << idx;
788 if (ucontrol->value.integer.value[0])
789 val = spec->aloopback | idx_val;
790 else
791 val = spec->aloopback & ~idx_val;
792 if (spec->aloopback == val)
793 return 0;
794
795 spec->aloopback = val;
796
797 /* Only return the bits defined by the shift value of the
798 * first two bytes of the mask
799 */
800 dac_mode = snd_hda_codec_read(codec, codec->afg, 0,
801 kcontrol->private_value & 0xFFFF, 0x0);
802 dac_mode >>= spec->aloopback_shift;
803
804 if (spec->aloopback & idx_val) {
805 snd_hda_power_up(codec);
806 dac_mode |= idx_val;
807 } else {
808 snd_hda_power_down(codec);
809 dac_mode &= ~idx_val;
810 }
811
812 snd_hda_codec_write_cache(codec, codec->afg, 0,
813 kcontrol->private_value >> 16, dac_mode);
814
815 return 1;
816 }
817
818 static struct hda_verb stac9200_core_init[] = {
819 /* set dac0mux for dac converter */
820 { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
821 {}
822 };
823
824 static struct hda_verb stac9200_eapd_init[] = {
825 /* set dac0mux for dac converter */
826 {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
827 {0x08, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
828 {}
829 };
830
831 static struct hda_verb stac92hd73xx_6ch_core_init[] = {
832 /* set master volume and direct control */
833 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
834 /* setup adcs to point to mixer */
835 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
836 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
837 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
838 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
839 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
840 /* setup import muxs */
841 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
842 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
843 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
844 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x00},
845 {}
846 };
847
848 static struct hda_verb dell_eq_core_init[] = {
849 /* set master volume to max value without distortion
850 * and direct control */
851 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xec},
852 /* setup adcs to point to mixer */
853 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
854 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
855 /* setup import muxs */
856 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
857 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
858 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
859 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x00},
860 {}
861 };
862
863 static struct hda_verb dell_m6_core_init[] = {
864 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
865 /* setup adcs to point to mixer */
866 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
867 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
868 /* setup import muxs */
869 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
870 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
871 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
872 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x00},
873 {}
874 };
875
876 static struct hda_verb stac92hd73xx_8ch_core_init[] = {
877 /* set master volume and direct control */
878 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
879 /* setup adcs to point to mixer */
880 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
881 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
882 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
883 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
884 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
885 /* setup import muxs */
886 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
887 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
888 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
889 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x03},
890 {}
891 };
892
893 static struct hda_verb stac92hd73xx_10ch_core_init[] = {
894 /* set master volume and direct control */
895 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
896 /* dac3 is connected to import3 mux */
897 { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0xb07f},
898 /* setup adcs to point to mixer */
899 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
900 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
901 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
902 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
903 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
904 /* setup import muxs */
905 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
906 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
907 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
908 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x03},
909 {}
910 };
911
912 static struct hda_verb stac92hd83xxx_core_init[] = {
913 { 0xa, AC_VERB_SET_CONNECT_SEL, 0x1},
914 { 0xb, AC_VERB_SET_CONNECT_SEL, 0x1},
915 { 0xd, AC_VERB_SET_CONNECT_SEL, 0x0},
916
917 /* power state controls amps */
918 { 0x01, AC_VERB_SET_EAPD, 1 << 2},
919 {}
920 };
921
922 static struct hda_verb stac92hd71bxx_core_init[] = {
923 /* set master volume and direct control */
924 { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
925 {}
926 };
927
928 #define HD_DISABLE_PORTF 1
929 static struct hda_verb stac92hd71bxx_analog_core_init[] = {
930 /* start of config #1 */
931
932 /* connect port 0f to audio mixer */
933 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x2},
934 /* start of config #2 */
935
936 /* set master volume and direct control */
937 { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
938 {}
939 };
940
941 static struct hda_verb stac92hd71bxx_unmute_core_init[] = {
942 /* unmute right and left channels for nodes 0x0f, 0xa, 0x0d */
943 { 0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
944 { 0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
945 { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
946 {}
947 };
948
949 static struct hda_verb stac925x_core_init[] = {
950 /* set dac0mux for dac converter */
951 { 0x06, AC_VERB_SET_CONNECT_SEL, 0x00},
952 /* mute the master volume */
953 { 0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
954 {}
955 };
956
957 static struct hda_verb stac922x_core_init[] = {
958 /* set master volume and direct control */
959 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
960 {}
961 };
962
963 static struct hda_verb d965_core_init[] = {
964 /* set master volume and direct control */
965 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
966 /* unmute node 0x1b */
967 { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
968 /* select node 0x03 as DAC */
969 { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
970 {}
971 };
972
973 static struct hda_verb stac927x_core_init[] = {
974 /* set master volume and direct control */
975 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
976 /* enable analog pc beep path */
977 { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
978 {}
979 };
980
981 static struct hda_verb stac9205_core_init[] = {
982 /* set master volume and direct control */
983 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
984 /* enable analog pc beep path */
985 { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
986 {}
987 };
988
989 #define STAC_MONO_MUX \
990 { \
991 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
992 .name = "Mono Mux", \
993 .count = 1, \
994 .info = stac92xx_mono_mux_enum_info, \
995 .get = stac92xx_mono_mux_enum_get, \
996 .put = stac92xx_mono_mux_enum_put, \
997 }
998
999 #define STAC_AMP_MUX \
1000 { \
1001 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1002 .name = "Amp Selector Capture Switch", \
1003 .count = 1, \
1004 .info = stac92xx_amp_mux_enum_info, \
1005 .get = stac92xx_amp_mux_enum_get, \
1006 .put = stac92xx_amp_mux_enum_put, \
1007 }
1008
1009 #define STAC_AMP_VOL(xname, nid, chs, idx, dir) \
1010 { \
1011 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1012 .name = xname, \
1013 .index = 0, \
1014 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1015 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1016 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
1017 .info = stac92xx_amp_volume_info, \
1018 .get = stac92xx_amp_volume_get, \
1019 .put = stac92xx_amp_volume_put, \
1020 .tlv = { .c = snd_hda_mixer_amp_tlv }, \
1021 .private_value = HDA_COMPOSE_AMP_VAL(nid, chs, idx, dir) \
1022 }
1023
1024 #define STAC_ANALOG_LOOPBACK(verb_read, verb_write, cnt) \
1025 { \
1026 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1027 .name = "Analog Loopback", \
1028 .count = cnt, \
1029 .info = stac92xx_aloopback_info, \
1030 .get = stac92xx_aloopback_get, \
1031 .put = stac92xx_aloopback_put, \
1032 .private_value = verb_read | (verb_write << 16), \
1033 }
1034
1035 #define DC_BIAS(xname, idx, nid) \
1036 { \
1037 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1038 .name = xname, \
1039 .index = idx, \
1040 .info = stac92xx_dc_bias_info, \
1041 .get = stac92xx_dc_bias_get, \
1042 .put = stac92xx_dc_bias_put, \
1043 .private_value = nid, \
1044 }
1045
1046 static struct snd_kcontrol_new stac9200_mixer[] = {
1047 HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
1048 HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
1049 HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
1050 HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
1051 { } /* end */
1052 };
1053
1054 #define DELL_M6_MIXER 6
1055 static struct snd_kcontrol_new stac92hd73xx_6ch_mixer[] = {
1056 /* start of config #1 */
1057 HDA_CODEC_VOLUME("Front Mic Mixer Capture Volume", 0x1d, 0, HDA_INPUT),
1058 HDA_CODEC_MUTE("Front Mic Mixer Capture Switch", 0x1d, 0, HDA_INPUT),
1059
1060 HDA_CODEC_VOLUME("Line In Mixer Capture Volume", 0x1d, 0x2, HDA_INPUT),
1061 HDA_CODEC_MUTE("Line In Mixer Capture Switch", 0x1d, 0x2, HDA_INPUT),
1062
1063 HDA_CODEC_VOLUME("CD Mixer Capture Volume", 0x1d, 0x4, HDA_INPUT),
1064 HDA_CODEC_MUTE("CD Mixer Capture Switch", 0x1d, 0x4, HDA_INPUT),
1065
1066 /* start of config #2 */
1067 HDA_CODEC_VOLUME("Mic Mixer Capture Volume", 0x1d, 0x1, HDA_INPUT),
1068 HDA_CODEC_MUTE("Mic Mixer Capture Switch", 0x1d, 0x1, HDA_INPUT),
1069
1070 HDA_CODEC_VOLUME("DAC Mixer Capture Volume", 0x1d, 0x3, HDA_INPUT),
1071 HDA_CODEC_MUTE("DAC Mixer Capture Switch", 0x1d, 0x3, HDA_INPUT),
1072
1073 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x20, 0x0, HDA_OUTPUT),
1074 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x20, 0x0, HDA_OUTPUT),
1075
1076 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x21, 0x0, HDA_OUTPUT),
1077 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x21, 0x0, HDA_OUTPUT),
1078
1079 { } /* end */
1080 };
1081
1082 static struct snd_kcontrol_new stac92hd73xx_6ch_loopback[] = {
1083 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 3),
1084 {}
1085 };
1086
1087 static struct snd_kcontrol_new stac92hd73xx_8ch_loopback[] = {
1088 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 4),
1089 {}
1090 };
1091
1092 static struct snd_kcontrol_new stac92hd73xx_10ch_loopback[] = {
1093 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 5),
1094 {}
1095 };
1096
1097 static struct snd_kcontrol_new stac92hd73xx_8ch_mixer[] = {
1098 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x20, 0x0, HDA_OUTPUT),
1099 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x20, 0x0, HDA_OUTPUT),
1100
1101 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x21, 0x0, HDA_OUTPUT),
1102 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x21, 0x0, HDA_OUTPUT),
1103
1104 HDA_CODEC_VOLUME("Front Mic Mixer Capture Volume", 0x1d, 0, HDA_INPUT),
1105 HDA_CODEC_MUTE("Front Mic Mixer Capture Switch", 0x1d, 0, HDA_INPUT),
1106
1107 HDA_CODEC_VOLUME("Mic Mixer Capture Volume", 0x1d, 0x1, HDA_INPUT),
1108 HDA_CODEC_MUTE("Mic Mixer Capture Switch", 0x1d, 0x1, HDA_INPUT),
1109
1110 HDA_CODEC_VOLUME("Line In Mixer Capture Volume", 0x1d, 0x2, HDA_INPUT),
1111 HDA_CODEC_MUTE("Line In Mixer Capture Switch", 0x1d, 0x2, HDA_INPUT),
1112
1113 HDA_CODEC_VOLUME("DAC Mixer Capture Volume", 0x1d, 0x3, HDA_INPUT),
1114 HDA_CODEC_MUTE("DAC Mixer Capture Switch", 0x1d, 0x3, HDA_INPUT),
1115
1116 HDA_CODEC_VOLUME("CD Mixer Capture Volume", 0x1d, 0x4, HDA_INPUT),
1117 HDA_CODEC_MUTE("CD Mixer Capture Switch", 0x1d, 0x4, HDA_INPUT),
1118 { } /* end */
1119 };
1120
1121 static struct snd_kcontrol_new stac92hd73xx_10ch_mixer[] = {
1122 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x20, 0x0, HDA_OUTPUT),
1123 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x20, 0x0, HDA_OUTPUT),
1124
1125 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x21, 0x0, HDA_OUTPUT),
1126 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x21, 0x0, HDA_OUTPUT),
1127
1128 HDA_CODEC_VOLUME("Front Mic Mixer Capture Volume", 0x1d, 0, HDA_INPUT),
1129 HDA_CODEC_MUTE("Front Mic Mixer Capture Switch", 0x1d, 0, HDA_INPUT),
1130
1131 HDA_CODEC_VOLUME("Mic Mixer Capture Volume", 0x1d, 0x1, HDA_INPUT),
1132 HDA_CODEC_MUTE("Mic Mixer Capture Switch", 0x1d, 0x1, HDA_INPUT),
1133
1134 HDA_CODEC_VOLUME("Line In Mixer Capture Volume", 0x1d, 0x2, HDA_INPUT),
1135 HDA_CODEC_MUTE("Line In Mixer Capture Switch", 0x1d, 0x2, HDA_INPUT),
1136
1137 HDA_CODEC_VOLUME("DAC Mixer Capture Volume", 0x1d, 0x3, HDA_INPUT),
1138 HDA_CODEC_MUTE("DAC Mixer Capture Switch", 0x1d, 0x3, HDA_INPUT),
1139
1140 HDA_CODEC_VOLUME("CD Mixer Capture Volume", 0x1d, 0x4, HDA_INPUT),
1141 HDA_CODEC_MUTE("CD Mixer Capture Switch", 0x1d, 0x4, HDA_INPUT),
1142 { } /* end */
1143 };
1144
1145
1146 static struct snd_kcontrol_new stac92hd83xxx_mixer[] = {
1147 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x17, 0x0, HDA_OUTPUT),
1148 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x17, 0x0, HDA_OUTPUT),
1149
1150 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x18, 0x0, HDA_OUTPUT),
1151 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x18, 0x0, HDA_OUTPUT),
1152
1153 HDA_CODEC_VOLUME("DAC0 Capture Volume", 0x1b, 0x3, HDA_INPUT),
1154 HDA_CODEC_MUTE("DAC0 Capture Switch", 0x1b, 0x3, HDA_INPUT),
1155
1156 HDA_CODEC_VOLUME("DAC1 Capture Volume", 0x1b, 0x4, HDA_INPUT),
1157 HDA_CODEC_MUTE("DAC1 Capture Switch", 0x1b, 0x4, HDA_INPUT),
1158
1159 HDA_CODEC_VOLUME("Front Mic Capture Volume", 0x1b, 0x0, HDA_INPUT),
1160 HDA_CODEC_MUTE("Front Mic Capture Switch", 0x1b, 0x0, HDA_INPUT),
1161
1162 HDA_CODEC_VOLUME("Line In Capture Volume", 0x1b, 0x2, HDA_INPUT),
1163 HDA_CODEC_MUTE("Line In Capture Switch", 0x1b, 0x2, HDA_INPUT),
1164
1165 /*
1166 HDA_CODEC_VOLUME("Mic Capture Volume", 0x1b, 0x1, HDA_INPUT),
1167 HDA_CODEC_MUTE("Mic Capture Switch", 0x1b 0x1, HDA_INPUT),
1168 */
1169 { } /* end */
1170 };
1171
1172 static struct snd_kcontrol_new stac92hd71bxx_analog_mixer[] = {
1173 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1c, 0x0, HDA_OUTPUT),
1174 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1c, 0x0, HDA_OUTPUT),
1175
1176 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x1d, 0x0, HDA_OUTPUT),
1177 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1d, 0x0, HDA_OUTPUT),
1178 /* analog pc-beep replaced with digital beep support */
1179 /*
1180 HDA_CODEC_VOLUME("PC Beep Volume", 0x17, 0x2, HDA_INPUT),
1181 HDA_CODEC_MUTE("PC Beep Switch", 0x17, 0x2, HDA_INPUT),
1182 */
1183
1184 HDA_CODEC_MUTE("Import0 Mux Capture Switch", 0x17, 0x0, HDA_INPUT),
1185 HDA_CODEC_VOLUME("Import0 Mux Capture Volume", 0x17, 0x0, HDA_INPUT),
1186
1187 HDA_CODEC_MUTE("Import1 Mux Capture Switch", 0x17, 0x1, HDA_INPUT),
1188 HDA_CODEC_VOLUME("Import1 Mux Capture Volume", 0x17, 0x1, HDA_INPUT),
1189
1190 HDA_CODEC_MUTE("DAC0 Capture Switch", 0x17, 0x3, HDA_INPUT),
1191 HDA_CODEC_VOLUME("DAC0 Capture Volume", 0x17, 0x3, HDA_INPUT),
1192
1193 HDA_CODEC_MUTE("DAC1 Capture Switch", 0x17, 0x4, HDA_INPUT),
1194 HDA_CODEC_VOLUME("DAC1 Capture Volume", 0x17, 0x4, HDA_INPUT),
1195 { } /* end */
1196 };
1197
1198 static struct snd_kcontrol_new stac92hd71bxx_loopback[] = {
1199 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A0, 2)
1200 };
1201
1202 static struct snd_kcontrol_new stac92hd71bxx_mixer[] = {
1203 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1c, 0x0, HDA_OUTPUT),
1204 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1c, 0x0, HDA_OUTPUT),
1205
1206 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x1d, 0x0, HDA_OUTPUT),
1207 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1d, 0x0, HDA_OUTPUT),
1208 { } /* end */
1209 };
1210
1211 static struct snd_kcontrol_new stac925x_mixer[] = {
1212 HDA_CODEC_VOLUME("Master Playback Volume", 0x0e, 0, HDA_OUTPUT),
1213 HDA_CODEC_MUTE("Master Playback Switch", 0x0e, 0, HDA_OUTPUT),
1214 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_OUTPUT),
1215 HDA_CODEC_MUTE("Capture Switch", 0x14, 0, HDA_OUTPUT),
1216 { } /* end */
1217 };
1218
1219 static struct snd_kcontrol_new stac9205_mixer[] = {
1220 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1b, 0x0, HDA_INPUT),
1221 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1d, 0x0, HDA_OUTPUT),
1222
1223 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x1c, 0x0, HDA_INPUT),
1224 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1e, 0x0, HDA_OUTPUT),
1225 { } /* end */
1226 };
1227
1228 static struct snd_kcontrol_new stac9205_loopback[] = {
1229 STAC_ANALOG_LOOPBACK(0xFE0, 0x7E0, 1),
1230 {}
1231 };
1232
1233 /* This needs to be generated dynamically based on sequence */
1234 static struct snd_kcontrol_new stac922x_mixer[] = {
1235 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x17, 0x0, HDA_INPUT),
1236 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x17, 0x0, HDA_INPUT),
1237
1238 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x18, 0x0, HDA_INPUT),
1239 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x18, 0x0, HDA_INPUT),
1240 { } /* end */
1241 };
1242
1243
1244 static struct snd_kcontrol_new stac927x_mixer[] = {
1245 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x18, 0x0, HDA_INPUT),
1246 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1b, 0x0, HDA_OUTPUT),
1247
1248 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x19, 0x0, HDA_INPUT),
1249 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1c, 0x0, HDA_OUTPUT),
1250
1251 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x2, 0x1A, 0x0, HDA_INPUT),
1252 HDA_CODEC_MUTE_IDX("Capture Switch", 0x2, 0x1d, 0x0, HDA_OUTPUT),
1253 { } /* end */
1254 };
1255
1256 static struct snd_kcontrol_new stac927x_loopback[] = {
1257 STAC_ANALOG_LOOPBACK(0xFEB, 0x7EB, 1),
1258 {}
1259 };
1260
1261 static struct snd_kcontrol_new stac_dmux_mixer = {
1262 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1263 .name = "Digital Input Source",
1264 /* count set later */
1265 .info = stac92xx_dmux_enum_info,
1266 .get = stac92xx_dmux_enum_get,
1267 .put = stac92xx_dmux_enum_put,
1268 };
1269
1270 static struct snd_kcontrol_new stac_smux_mixer = {
1271 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1272 .name = "IEC958 Playback Source",
1273 /* count set later */
1274 .info = stac92xx_smux_enum_info,
1275 .get = stac92xx_smux_enum_get,
1276 .put = stac92xx_smux_enum_put,
1277 };
1278
1279 static const char *slave_vols[] = {
1280 "Front Playback Volume",
1281 "Surround Playback Volume",
1282 "Center Playback Volume",
1283 "LFE Playback Volume",
1284 "Side Playback Volume",
1285 "Headphone Playback Volume",
1286 "Speaker Playback Volume",
1287 NULL
1288 };
1289
1290 static const char *slave_sws[] = {
1291 "Front Playback Switch",
1292 "Surround Playback Switch",
1293 "Center Playback Switch",
1294 "LFE Playback Switch",
1295 "Side Playback Switch",
1296 "Headphone Playback Switch",
1297 "Speaker Playback Switch",
1298 "IEC958 Playback Switch",
1299 NULL
1300 };
1301
1302 static void stac92xx_free_kctls(struct hda_codec *codec);
1303 static int stac92xx_add_jack(struct hda_codec *codec, hda_nid_t nid, int type);
1304
1305 static int stac92xx_build_controls(struct hda_codec *codec)
1306 {
1307 struct sigmatel_spec *spec = codec->spec;
1308 struct auto_pin_cfg *cfg = &spec->autocfg;
1309 hda_nid_t nid;
1310 int err;
1311 int i;
1312
1313 err = snd_hda_add_new_ctls(codec, spec->mixer);
1314 if (err < 0)
1315 return err;
1316
1317 for (i = 0; i < spec->num_mixers; i++) {
1318 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1319 if (err < 0)
1320 return err;
1321 }
1322 if (spec->num_dmuxes > 0) {
1323 stac_dmux_mixer.count = spec->num_dmuxes;
1324 err = snd_hda_ctl_add(codec,
1325 snd_ctl_new1(&stac_dmux_mixer, codec));
1326 if (err < 0)
1327 return err;
1328 }
1329 if (spec->num_smuxes > 0) {
1330 int wcaps = get_wcaps(codec, spec->multiout.dig_out_nid);
1331 struct hda_input_mux *smux = &spec->private_smux;
1332 /* check for mute support on SPDIF out */
1333 if (wcaps & AC_WCAP_OUT_AMP) {
1334 smux->items[smux->num_items].label = "Off";
1335 smux->items[smux->num_items].index = 0;
1336 smux->num_items++;
1337 spec->spdif_mute = 1;
1338 }
1339 stac_smux_mixer.count = spec->num_smuxes;
1340 err = snd_hda_ctl_add(codec,
1341 snd_ctl_new1(&stac_smux_mixer, codec));
1342 if (err < 0)
1343 return err;
1344 }
1345
1346 if (spec->multiout.dig_out_nid) {
1347 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
1348 if (err < 0)
1349 return err;
1350 err = snd_hda_create_spdif_share_sw(codec,
1351 &spec->multiout);
1352 if (err < 0)
1353 return err;
1354 spec->multiout.share_spdif = 1;
1355 }
1356 if (spec->dig_in_nid && !(spec->gpio_dir & 0x01)) {
1357 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1358 if (err < 0)
1359 return err;
1360 }
1361
1362 /* if we have no master control, let's create it */
1363 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
1364 unsigned int vmaster_tlv[4];
1365 snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0],
1366 HDA_OUTPUT, vmaster_tlv);
1367 /* correct volume offset */
1368 vmaster_tlv[2] += vmaster_tlv[3] * spec->volume_offset;
1369 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
1370 vmaster_tlv, slave_vols);
1371 if (err < 0)
1372 return err;
1373 }
1374 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1375 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1376 NULL, slave_sws);
1377 if (err < 0)
1378 return err;
1379 }
1380
1381 if (spec->aloopback_ctl &&
1382 snd_hda_get_bool_hint(codec, "loopback") == 1) {
1383 err = snd_hda_add_new_ctls(codec, spec->aloopback_ctl);
1384 if (err < 0)
1385 return err;
1386 }
1387
1388 stac92xx_free_kctls(codec); /* no longer needed */
1389
1390 /* create jack input elements */
1391 if (spec->hp_detect) {
1392 for (i = 0; i < cfg->hp_outs; i++) {
1393 int type = SND_JACK_HEADPHONE;
1394 nid = cfg->hp_pins[i];
1395 /* jack detection */
1396 if (cfg->hp_outs == i)
1397 type |= SND_JACK_LINEOUT;
1398 err = stac92xx_add_jack(codec, nid, type);
1399 if (err < 0)
1400 return err;
1401 }
1402 }
1403 for (i = 0; i < cfg->line_outs; i++) {
1404 err = stac92xx_add_jack(codec, cfg->line_out_pins[i],
1405 SND_JACK_LINEOUT);
1406 if (err < 0)
1407 return err;
1408 }
1409 for (i = 0; i < AUTO_PIN_LAST; i++) {
1410 nid = cfg->input_pins[i];
1411 if (nid) {
1412 err = stac92xx_add_jack(codec, nid,
1413 SND_JACK_MICROPHONE);
1414 if (err < 0)
1415 return err;
1416 }
1417 }
1418
1419 return 0;
1420 }
1421
1422 static unsigned int ref9200_pin_configs[8] = {
1423 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
1424 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
1425 };
1426
1427 static unsigned int gateway9200_m4_pin_configs[8] = {
1428 0x400000fe, 0x404500f4, 0x400100f0, 0x90110010,
1429 0x400100f1, 0x02a1902e, 0x500000f2, 0x500000f3,
1430 };
1431 static unsigned int gateway9200_m4_2_pin_configs[8] = {
1432 0x400000fe, 0x404500f4, 0x400100f0, 0x90110010,
1433 0x400100f1, 0x02a1902e, 0x500000f2, 0x500000f3,
1434 };
1435
1436 /*
1437 STAC 9200 pin configs for
1438 102801A8
1439 102801DE
1440 102801E8
1441 */
1442 static unsigned int dell9200_d21_pin_configs[8] = {
1443 0x400001f0, 0x400001f1, 0x02214030, 0x01014010,
1444 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
1445 };
1446
1447 /*
1448 STAC 9200 pin configs for
1449 102801C0
1450 102801C1
1451 */
1452 static unsigned int dell9200_d22_pin_configs[8] = {
1453 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
1454 0x01813020, 0x02a19021, 0x90100140, 0x400001f2,
1455 };
1456
1457 /*
1458 STAC 9200 pin configs for
1459 102801C4 (Dell Dimension E310)
1460 102801C5
1461 102801C7
1462 102801D9
1463 102801DA
1464 102801E3
1465 */
1466 static unsigned int dell9200_d23_pin_configs[8] = {
1467 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
1468 0x01813020, 0x01a19021, 0x90100140, 0x400001f2,
1469 };
1470
1471
1472 /*
1473 STAC 9200-32 pin configs for
1474 102801B5 (Dell Inspiron 630m)
1475 102801D8 (Dell Inspiron 640m)
1476 */
1477 static unsigned int dell9200_m21_pin_configs[8] = {
1478 0x40c003fa, 0x03441340, 0x0321121f, 0x90170310,
1479 0x408003fb, 0x03a11020, 0x401003fc, 0x403003fd,
1480 };
1481
1482 /*
1483 STAC 9200-32 pin configs for
1484 102801C2 (Dell Latitude D620)
1485 102801C8
1486 102801CC (Dell Latitude D820)
1487 102801D4
1488 102801D6
1489 */
1490 static unsigned int dell9200_m22_pin_configs[8] = {
1491 0x40c003fa, 0x0144131f, 0x0321121f, 0x90170310,
1492 0x90a70321, 0x03a11020, 0x401003fb, 0x40f000fc,
1493 };
1494
1495 /*
1496 STAC 9200-32 pin configs for
1497 102801CE (Dell XPS M1710)
1498 102801CF (Dell Precision M90)
1499 */
1500 static unsigned int dell9200_m23_pin_configs[8] = {
1501 0x40c003fa, 0x01441340, 0x0421421f, 0x90170310,
1502 0x408003fb, 0x04a1102e, 0x90170311, 0x403003fc,
1503 };
1504
1505 /*
1506 STAC 9200-32 pin configs for
1507 102801C9
1508 102801CA
1509 102801CB (Dell Latitude 120L)
1510 102801D3
1511 */
1512 static unsigned int dell9200_m24_pin_configs[8] = {
1513 0x40c003fa, 0x404003fb, 0x0321121f, 0x90170310,
1514 0x408003fc, 0x03a11020, 0x401003fd, 0x403003fe,
1515 };
1516
1517 /*
1518 STAC 9200-32 pin configs for
1519 102801BD (Dell Inspiron E1505n)
1520 102801EE
1521 102801EF
1522 */
1523 static unsigned int dell9200_m25_pin_configs[8] = {
1524 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
1525 0x408003fb, 0x04a11020, 0x401003fc, 0x403003fd,
1526 };
1527
1528 /*
1529 STAC 9200-32 pin configs for
1530 102801F5 (Dell Inspiron 1501)
1531 102801F6
1532 */
1533 static unsigned int dell9200_m26_pin_configs[8] = {
1534 0x40c003fa, 0x404003fb, 0x0421121f, 0x90170310,
1535 0x408003fc, 0x04a11020, 0x401003fd, 0x403003fe,
1536 };
1537
1538 /*
1539 STAC 9200-32
1540 102801CD (Dell Inspiron E1705/9400)
1541 */
1542 static unsigned int dell9200_m27_pin_configs[8] = {
1543 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
1544 0x90170310, 0x04a11020, 0x90170310, 0x40f003fc,
1545 };
1546
1547 static unsigned int oqo9200_pin_configs[8] = {
1548 0x40c000f0, 0x404000f1, 0x0221121f, 0x02211210,
1549 0x90170111, 0x90a70120, 0x400000f2, 0x400000f3,
1550 };
1551
1552
1553 static unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
1554 [STAC_REF] = ref9200_pin_configs,
1555 [STAC_9200_OQO] = oqo9200_pin_configs,
1556 [STAC_9200_DELL_D21] = dell9200_d21_pin_configs,
1557 [STAC_9200_DELL_D22] = dell9200_d22_pin_configs,
1558 [STAC_9200_DELL_D23] = dell9200_d23_pin_configs,
1559 [STAC_9200_DELL_M21] = dell9200_m21_pin_configs,
1560 [STAC_9200_DELL_M22] = dell9200_m22_pin_configs,
1561 [STAC_9200_DELL_M23] = dell9200_m23_pin_configs,
1562 [STAC_9200_DELL_M24] = dell9200_m24_pin_configs,
1563 [STAC_9200_DELL_M25] = dell9200_m25_pin_configs,
1564 [STAC_9200_DELL_M26] = dell9200_m26_pin_configs,
1565 [STAC_9200_DELL_M27] = dell9200_m27_pin_configs,
1566 [STAC_9200_M4] = gateway9200_m4_pin_configs,
1567 [STAC_9200_M4_2] = gateway9200_m4_2_pin_configs,
1568 [STAC_9200_PANASONIC] = ref9200_pin_configs,
1569 };
1570
1571 static const char *stac9200_models[STAC_9200_MODELS] = {
1572 [STAC_AUTO] = "auto",
1573 [STAC_REF] = "ref",
1574 [STAC_9200_OQO] = "oqo",
1575 [STAC_9200_DELL_D21] = "dell-d21",
1576 [STAC_9200_DELL_D22] = "dell-d22",
1577 [STAC_9200_DELL_D23] = "dell-d23",
1578 [STAC_9200_DELL_M21] = "dell-m21",
1579 [STAC_9200_DELL_M22] = "dell-m22",
1580 [STAC_9200_DELL_M23] = "dell-m23",
1581 [STAC_9200_DELL_M24] = "dell-m24",
1582 [STAC_9200_DELL_M25] = "dell-m25",
1583 [STAC_9200_DELL_M26] = "dell-m26",
1584 [STAC_9200_DELL_M27] = "dell-m27",
1585 [STAC_9200_M4] = "gateway-m4",
1586 [STAC_9200_M4_2] = "gateway-m4-2",
1587 [STAC_9200_PANASONIC] = "panasonic",
1588 };
1589
1590 static struct snd_pci_quirk stac9200_cfg_tbl[] = {
1591 /* SigmaTel reference board */
1592 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1593 "DFI LanParty", STAC_REF),
1594 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1595 "DFI LanParty", STAC_REF),
1596 /* Dell laptops have BIOS problem */
1597 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a8,
1598 "unknown Dell", STAC_9200_DELL_D21),
1599 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01b5,
1600 "Dell Inspiron 630m", STAC_9200_DELL_M21),
1601 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bd,
1602 "Dell Inspiron E1505n", STAC_9200_DELL_M25),
1603 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c0,
1604 "unknown Dell", STAC_9200_DELL_D22),
1605 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c1,
1606 "unknown Dell", STAC_9200_DELL_D22),
1607 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c2,
1608 "Dell Latitude D620", STAC_9200_DELL_M22),
1609 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c5,
1610 "unknown Dell", STAC_9200_DELL_D23),
1611 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c7,
1612 "unknown Dell", STAC_9200_DELL_D23),
1613 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c8,
1614 "unknown Dell", STAC_9200_DELL_M22),
1615 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c9,
1616 "unknown Dell", STAC_9200_DELL_M24),
1617 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ca,
1618 "unknown Dell", STAC_9200_DELL_M24),
1619 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cb,
1620 "Dell Latitude 120L", STAC_9200_DELL_M24),
1621 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cc,
1622 "Dell Latitude D820", STAC_9200_DELL_M22),
1623 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cd,
1624 "Dell Inspiron E1705/9400", STAC_9200_DELL_M27),
1625 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ce,
1626 "Dell XPS M1710", STAC_9200_DELL_M23),
1627 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cf,
1628 "Dell Precision M90", STAC_9200_DELL_M23),
1629 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d3,
1630 "unknown Dell", STAC_9200_DELL_M22),
1631 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d4,
1632 "unknown Dell", STAC_9200_DELL_M22),
1633 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d6,
1634 "unknown Dell", STAC_9200_DELL_M22),
1635 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d8,
1636 "Dell Inspiron 640m", STAC_9200_DELL_M21),
1637 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d9,
1638 "unknown Dell", STAC_9200_DELL_D23),
1639 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01da,
1640 "unknown Dell", STAC_9200_DELL_D23),
1641 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01de,
1642 "unknown Dell", STAC_9200_DELL_D21),
1643 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e3,
1644 "unknown Dell", STAC_9200_DELL_D23),
1645 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e8,
1646 "unknown Dell", STAC_9200_DELL_D21),
1647 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ee,
1648 "unknown Dell", STAC_9200_DELL_M25),
1649 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ef,
1650 "unknown Dell", STAC_9200_DELL_M25),
1651 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f5,
1652 "Dell Inspiron 1501", STAC_9200_DELL_M26),
1653 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f6,
1654 "unknown Dell", STAC_9200_DELL_M26),
1655 /* Panasonic */
1656 SND_PCI_QUIRK(0x10f7, 0x8338, "Panasonic CF-74", STAC_9200_PANASONIC),
1657 /* Gateway machines needs EAPD to be set on resume */
1658 SND_PCI_QUIRK(0x107b, 0x0205, "Gateway S-7110M", STAC_9200_M4),
1659 SND_PCI_QUIRK(0x107b, 0x0317, "Gateway MT3423, MX341*", STAC_9200_M4_2),
1660 SND_PCI_QUIRK(0x107b, 0x0318, "Gateway ML3019, MT3707", STAC_9200_M4_2),
1661 /* OQO Mobile */
1662 SND_PCI_QUIRK(0x1106, 0x3288, "OQO Model 2", STAC_9200_OQO),
1663 {} /* terminator */
1664 };
1665
1666 static unsigned int ref925x_pin_configs[8] = {
1667 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
1668 0x90a70320, 0x02214210, 0x01019020, 0x9033032e,
1669 };
1670
1671 static unsigned int stac925xM1_pin_configs[8] = {
1672 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1673 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1674 };
1675
1676 static unsigned int stac925xM1_2_pin_configs[8] = {
1677 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1678 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1679 };
1680
1681 static unsigned int stac925xM2_pin_configs[8] = {
1682 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1683 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1684 };
1685
1686 static unsigned int stac925xM2_2_pin_configs[8] = {
1687 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1688 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1689 };
1690
1691 static unsigned int stac925xM3_pin_configs[8] = {
1692 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1693 0x40a000f0, 0x90100210, 0x400003f1, 0x503303f3,
1694 };
1695
1696 static unsigned int stac925xM5_pin_configs[8] = {
1697 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1698 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1699 };
1700
1701 static unsigned int stac925xM6_pin_configs[8] = {
1702 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1703 0x40a000f0, 0x90100210, 0x400003f1, 0x90330320,
1704 };
1705
1706 static unsigned int *stac925x_brd_tbl[STAC_925x_MODELS] = {
1707 [STAC_REF] = ref925x_pin_configs,
1708 [STAC_M1] = stac925xM1_pin_configs,
1709 [STAC_M1_2] = stac925xM1_2_pin_configs,
1710 [STAC_M2] = stac925xM2_pin_configs,
1711 [STAC_M2_2] = stac925xM2_2_pin_configs,
1712 [STAC_M3] = stac925xM3_pin_configs,
1713 [STAC_M5] = stac925xM5_pin_configs,
1714 [STAC_M6] = stac925xM6_pin_configs,
1715 };
1716
1717 static const char *stac925x_models[STAC_925x_MODELS] = {
1718 [STAC_925x_AUTO] = "auto",
1719 [STAC_REF] = "ref",
1720 [STAC_M1] = "m1",
1721 [STAC_M1_2] = "m1-2",
1722 [STAC_M2] = "m2",
1723 [STAC_M2_2] = "m2-2",
1724 [STAC_M3] = "m3",
1725 [STAC_M5] = "m5",
1726 [STAC_M6] = "m6",
1727 };
1728
1729 static struct snd_pci_quirk stac925x_codec_id_cfg_tbl[] = {
1730 SND_PCI_QUIRK(0x107b, 0x0316, "Gateway M255", STAC_M2),
1731 SND_PCI_QUIRK(0x107b, 0x0366, "Gateway MP6954", STAC_M5),
1732 SND_PCI_QUIRK(0x107b, 0x0461, "Gateway NX560XL", STAC_M1),
1733 SND_PCI_QUIRK(0x107b, 0x0681, "Gateway NX860", STAC_M2),
1734 SND_PCI_QUIRK(0x107b, 0x0367, "Gateway MX6453", STAC_M1_2),
1735 /* Not sure about the brand name for those */
1736 SND_PCI_QUIRK(0x107b, 0x0281, "Gateway mobile", STAC_M1),
1737 SND_PCI_QUIRK(0x107b, 0x0507, "Gateway mobile", STAC_M3),
1738 SND_PCI_QUIRK(0x107b, 0x0281, "Gateway mobile", STAC_M6),
1739 SND_PCI_QUIRK(0x107b, 0x0685, "Gateway mobile", STAC_M2_2),
1740 {} /* terminator */
1741 };
1742
1743 static struct snd_pci_quirk stac925x_cfg_tbl[] = {
1744 /* SigmaTel reference board */
1745 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, "DFI LanParty", STAC_REF),
1746 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101, "DFI LanParty", STAC_REF),
1747 SND_PCI_QUIRK(0x8384, 0x7632, "Stac9202 Reference Board", STAC_REF),
1748
1749 /* Default table for unknown ID */
1750 SND_PCI_QUIRK(0x1002, 0x437b, "Gateway mobile", STAC_M2_2),
1751
1752 {} /* terminator */
1753 };
1754
1755 static unsigned int ref92hd73xx_pin_configs[13] = {
1756 0x02214030, 0x02a19040, 0x01a19020, 0x02214030,
1757 0x0181302e, 0x01014010, 0x01014020, 0x01014030,
1758 0x02319040, 0x90a000f0, 0x90a000f0, 0x01452050,
1759 0x01452050,
1760 };
1761
1762 static unsigned int dell_m6_pin_configs[13] = {
1763 0x0321101f, 0x4f00000f, 0x4f0000f0, 0x90170110,
1764 0x03a11020, 0x0321101f, 0x4f0000f0, 0x4f0000f0,
1765 0x4f0000f0, 0x90a60160, 0x4f0000f0, 0x4f0000f0,
1766 0x4f0000f0,
1767 };
1768
1769 static unsigned int *stac92hd73xx_brd_tbl[STAC_92HD73XX_MODELS] = {
1770 [STAC_92HD73XX_REF] = ref92hd73xx_pin_configs,
1771 [STAC_DELL_M6_AMIC] = dell_m6_pin_configs,
1772 [STAC_DELL_M6_DMIC] = dell_m6_pin_configs,
1773 [STAC_DELL_M6_BOTH] = dell_m6_pin_configs,
1774 [STAC_DELL_EQ] = dell_m6_pin_configs,
1775 };
1776
1777 static const char *stac92hd73xx_models[STAC_92HD73XX_MODELS] = {
1778 [STAC_92HD73XX_AUTO] = "auto",
1779 [STAC_92HD73XX_NO_JD] = "no-jd",
1780 [STAC_92HD73XX_REF] = "ref",
1781 [STAC_92HD73XX_INTEL] = "intel",
1782 [STAC_DELL_M6_AMIC] = "dell-m6-amic",
1783 [STAC_DELL_M6_DMIC] = "dell-m6-dmic",
1784 [STAC_DELL_M6_BOTH] = "dell-m6",
1785 [STAC_DELL_EQ] = "dell-eq",
1786 };
1787
1788 static struct snd_pci_quirk stac92hd73xx_cfg_tbl[] = {
1789 /* SigmaTel reference board */
1790 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1791 "DFI LanParty", STAC_92HD73XX_REF),
1792 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1793 "DFI LanParty", STAC_92HD73XX_REF),
1794 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5002,
1795 "Intel DG45ID", STAC_92HD73XX_INTEL),
1796 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5003,
1797 "Intel DG45FC", STAC_92HD73XX_INTEL),
1798 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0254,
1799 "Dell Studio 1535", STAC_DELL_M6_DMIC),
1800 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0255,
1801 "unknown Dell", STAC_DELL_M6_DMIC),
1802 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0256,
1803 "unknown Dell", STAC_DELL_M6_BOTH),
1804 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0257,
1805 "unknown Dell", STAC_DELL_M6_BOTH),
1806 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025e,
1807 "unknown Dell", STAC_DELL_M6_AMIC),
1808 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025f,
1809 "unknown Dell", STAC_DELL_M6_AMIC),
1810 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0271,
1811 "unknown Dell", STAC_DELL_M6_DMIC),
1812 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0272,
1813 "unknown Dell", STAC_DELL_M6_DMIC),
1814 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x029f,
1815 "Dell Studio 1537", STAC_DELL_M6_DMIC),
1816 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02a0,
1817 "Dell Studio 17", STAC_DELL_M6_DMIC),
1818 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02be,
1819 "Dell Studio 1555", STAC_DELL_M6_DMIC),
1820 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02bd,
1821 "Dell Studio 1557", STAC_DELL_M6_DMIC),
1822 {} /* terminator */
1823 };
1824
1825 static unsigned int ref92hd83xxx_pin_configs[10] = {
1826 0x02214030, 0x02211010, 0x02a19020, 0x02170130,
1827 0x01014050, 0x01819040, 0x01014020, 0x90a3014e,
1828 0x01451160, 0x98560170,
1829 };
1830
1831 static unsigned int dell_s14_pin_configs[10] = {
1832 0x02214030, 0x02211010, 0x02a19020, 0x01014050,
1833 0x40f000f0, 0x01819040, 0x40f000f0, 0x90a60160,
1834 0x40f000f0, 0x40f000f0,
1835 };
1836
1837 static unsigned int *stac92hd83xxx_brd_tbl[STAC_92HD83XXX_MODELS] = {
1838 [STAC_92HD83XXX_REF] = ref92hd83xxx_pin_configs,
1839 [STAC_92HD83XXX_PWR_REF] = ref92hd83xxx_pin_configs,
1840 [STAC_DELL_S14] = dell_s14_pin_configs,
1841 };
1842
1843 static const char *stac92hd83xxx_models[STAC_92HD83XXX_MODELS] = {
1844 [STAC_92HD83XXX_AUTO] = "auto",
1845 [STAC_92HD83XXX_REF] = "ref",
1846 [STAC_92HD83XXX_PWR_REF] = "mic-ref",
1847 [STAC_DELL_S14] = "dell-s14",
1848 };
1849
1850 static struct snd_pci_quirk stac92hd83xxx_cfg_tbl[] = {
1851 /* SigmaTel reference board */
1852 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1853 "DFI LanParty", STAC_92HD83XXX_REF),
1854 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1855 "DFI LanParty", STAC_92HD83XXX_REF),
1856 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ba,
1857 "unknown Dell", STAC_DELL_S14),
1858 {} /* terminator */
1859 };
1860
1861 static unsigned int ref92hd71bxx_pin_configs[STAC92HD71BXX_NUM_PINS] = {
1862 0x02214030, 0x02a19040, 0x01a19020, 0x01014010,
1863 0x0181302e, 0x01014010, 0x01019020, 0x90a000f0,
1864 0x90a000f0, 0x01452050, 0x01452050, 0x00000000,
1865 0x00000000
1866 };
1867
1868 static unsigned int dell_m4_1_pin_configs[STAC92HD71BXX_NUM_PINS] = {
1869 0x0421101f, 0x04a11221, 0x40f000f0, 0x90170110,
1870 0x23a1902e, 0x23014250, 0x40f000f0, 0x90a000f0,
1871 0x40f000f0, 0x4f0000f0, 0x4f0000f0, 0x00000000,
1872 0x00000000
1873 };
1874
1875 static unsigned int dell_m4_2_pin_configs[STAC92HD71BXX_NUM_PINS] = {
1876 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1877 0x23a1902e, 0x23014250, 0x40f000f0, 0x40f000f0,
1878 0x40f000f0, 0x044413b0, 0x044413b0, 0x00000000,
1879 0x00000000
1880 };
1881
1882 static unsigned int dell_m4_3_pin_configs[STAC92HD71BXX_NUM_PINS] = {
1883 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1884 0x40f000f0, 0x40f000f0, 0x40f000f0, 0x90a000f0,
1885 0x40f000f0, 0x044413b0, 0x044413b0, 0x00000000,
1886 0x00000000
1887 };
1888
1889 static unsigned int *stac92hd71bxx_brd_tbl[STAC_92HD71BXX_MODELS] = {
1890 [STAC_92HD71BXX_REF] = ref92hd71bxx_pin_configs,
1891 [STAC_DELL_M4_1] = dell_m4_1_pin_configs,
1892 [STAC_DELL_M4_2] = dell_m4_2_pin_configs,
1893 [STAC_DELL_M4_3] = dell_m4_3_pin_configs,
1894 [STAC_HP_M4] = NULL,
1895 [STAC_HP_DV5] = NULL,
1896 [STAC_HP_HDX] = NULL,
1897 [STAC_HP_DV4_1222NR] = NULL,
1898 };
1899
1900 static const char *stac92hd71bxx_models[STAC_92HD71BXX_MODELS] = {
1901 [STAC_92HD71BXX_AUTO] = "auto",
1902 [STAC_92HD71BXX_REF] = "ref",
1903 [STAC_DELL_M4_1] = "dell-m4-1",
1904 [STAC_DELL_M4_2] = "dell-m4-2",
1905 [STAC_DELL_M4_3] = "dell-m4-3",
1906 [STAC_HP_M4] = "hp-m4",
1907 [STAC_HP_DV5] = "hp-dv5",
1908 [STAC_HP_HDX] = "hp-hdx",
1909 [STAC_HP_DV4_1222NR] = "hp-dv4-1222nr",
1910 };
1911
1912 static struct snd_pci_quirk stac92hd71bxx_cfg_tbl[] = {
1913 /* SigmaTel reference board */
1914 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1915 "DFI LanParty", STAC_92HD71BXX_REF),
1916 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1917 "DFI LanParty", STAC_92HD71BXX_REF),
1918 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x30fb,
1919 "HP dv4-1222nr", STAC_HP_DV4_1222NR),
1920 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3080,
1921 "HP", STAC_HP_DV5),
1922 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x30f0,
1923 "HP dv4-7", STAC_HP_DV5),
1924 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3600,
1925 "HP dv4-7", STAC_HP_DV5),
1926 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3610,
1927 "HP HDX", STAC_HP_HDX), /* HDX18 */
1928 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361a,
1929 "HP mini 1000", STAC_HP_M4),
1930 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361b,
1931 "HP HDX", STAC_HP_HDX), /* HDX16 */
1932 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0233,
1933 "unknown Dell", STAC_DELL_M4_1),
1934 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0234,
1935 "unknown Dell", STAC_DELL_M4_1),
1936 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0250,
1937 "unknown Dell", STAC_DELL_M4_1),
1938 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024f,
1939 "unknown Dell", STAC_DELL_M4_1),
1940 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024d,
1941 "unknown Dell", STAC_DELL_M4_1),
1942 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0251,
1943 "unknown Dell", STAC_DELL_M4_1),
1944 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0277,
1945 "unknown Dell", STAC_DELL_M4_1),
1946 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0263,
1947 "unknown Dell", STAC_DELL_M4_2),
1948 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0265,
1949 "unknown Dell", STAC_DELL_M4_2),
1950 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0262,
1951 "unknown Dell", STAC_DELL_M4_2),
1952 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0264,
1953 "unknown Dell", STAC_DELL_M4_2),
1954 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02aa,
1955 "unknown Dell", STAC_DELL_M4_3),
1956 {} /* terminator */
1957 };
1958
1959 static unsigned int ref922x_pin_configs[10] = {
1960 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
1961 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
1962 0x40000100, 0x40000100,
1963 };
1964
1965 /*
1966 STAC 922X pin configs for
1967 102801A7
1968 102801AB
1969 102801A9
1970 102801D1
1971 102801D2
1972 */
1973 static unsigned int dell_922x_d81_pin_configs[10] = {
1974 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1975 0x02a19020, 0x01117011, 0x400001f0, 0x400001f1,
1976 0x01813122, 0x400001f2,
1977 };
1978
1979 /*
1980 STAC 922X pin configs for
1981 102801AC
1982 102801D0
1983 */
1984 static unsigned int dell_922x_d82_pin_configs[10] = {
1985 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1986 0x02a19020, 0x01117011, 0x01451140, 0x400001f0,
1987 0x01813122, 0x400001f1,
1988 };
1989
1990 /*
1991 STAC 922X pin configs for
1992 102801BF
1993 */
1994 static unsigned int dell_922x_m81_pin_configs[10] = {
1995 0x0321101f, 0x01112024, 0x01111222, 0x91174220,
1996 0x03a11050, 0x01116221, 0x90a70330, 0x01452340,
1997 0x40C003f1, 0x405003f0,
1998 };
1999
2000 /*
2001 STAC 9221 A1 pin configs for
2002 102801D7 (Dell XPS M1210)
2003 */
2004 static unsigned int dell_922x_m82_pin_configs[10] = {
2005 0x02211211, 0x408103ff, 0x02a1123e, 0x90100310,
2006 0x408003f1, 0x0221121f, 0x03451340, 0x40c003f2,
2007 0x508003f3, 0x405003f4,
2008 };
2009
2010 static unsigned int d945gtp3_pin_configs[10] = {
2011 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
2012 0x40000100, 0x40000100, 0x40000100, 0x40000100,
2013 0x02a19120, 0x40000100,
2014 };
2015
2016 static unsigned int d945gtp5_pin_configs[10] = {
2017 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
2018 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
2019 0x02a19320, 0x40000100,
2020 };
2021
2022 static unsigned int intel_mac_v1_pin_configs[10] = {
2023 0x0121e21f, 0x400000ff, 0x9017e110, 0x400000fd,
2024 0x400000fe, 0x0181e020, 0x1145e030, 0x11c5e240,
2025 0x400000fc, 0x400000fb,
2026 };
2027
2028 static unsigned int intel_mac_v2_pin_configs[10] = {
2029 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
2030 0x400000fe, 0x0181e020, 0x1145e230, 0x500000fa,
2031 0x400000fc, 0x400000fb,
2032 };
2033
2034 static unsigned int intel_mac_v3_pin_configs[10] = {
2035 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
2036 0x400000fe, 0x0181e020, 0x1145e230, 0x11c5e240,
2037 0x400000fc, 0x400000fb,
2038 };
2039
2040 static unsigned int intel_mac_v4_pin_configs[10] = {
2041 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
2042 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
2043 0x400000fc, 0x400000fb,
2044 };
2045
2046 static unsigned int intel_mac_v5_pin_configs[10] = {
2047 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
2048 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
2049 0x400000fc, 0x400000fb,
2050 };
2051
2052 static unsigned int ecs202_pin_configs[10] = {
2053 0x0221401f, 0x02a19020, 0x01a19020, 0x01114010,
2054 0x408000f0, 0x01813022, 0x074510a0, 0x40c400f1,
2055 0x9037012e, 0x40e000f2,
2056 };
2057
2058 static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
2059 [STAC_D945_REF] = ref922x_pin_configs,
2060 [STAC_D945GTP3] = d945gtp3_pin_configs,
2061 [STAC_D945GTP5] = d945gtp5_pin_configs,
2062 [STAC_INTEL_MAC_V1] = intel_mac_v1_pin_configs,
2063 [STAC_INTEL_MAC_V2] = intel_mac_v2_pin_configs,
2064 [STAC_INTEL_MAC_V3] = intel_mac_v3_pin_configs,
2065 [STAC_INTEL_MAC_V4] = intel_mac_v4_pin_configs,
2066 [STAC_INTEL_MAC_V5] = intel_mac_v5_pin_configs,
2067 [STAC_INTEL_MAC_AUTO] = intel_mac_v3_pin_configs,
2068 /* for backward compatibility */
2069 [STAC_MACMINI] = intel_mac_v3_pin_configs,
2070 [STAC_MACBOOK] = intel_mac_v5_pin_configs,
2071 [STAC_MACBOOK_PRO_V1] = intel_mac_v3_pin_configs,
2072 [STAC_MACBOOK_PRO_V2] = intel_mac_v3_pin_configs,
2073 [STAC_IMAC_INTEL] = intel_mac_v2_pin_configs,
2074 [STAC_IMAC_INTEL_20] = intel_mac_v3_pin_configs,
2075 [STAC_ECS_202] = ecs202_pin_configs,
2076 [STAC_922X_DELL_D81] = dell_922x_d81_pin_configs,
2077 [STAC_922X_DELL_D82] = dell_922x_d82_pin_configs,
2078 [STAC_922X_DELL_M81] = dell_922x_m81_pin_configs,
2079 [STAC_922X_DELL_M82] = dell_922x_m82_pin_configs,
2080 };
2081
2082 static const char *stac922x_models[STAC_922X_MODELS] = {
2083 [STAC_922X_AUTO] = "auto",
2084 [STAC_D945_REF] = "ref",
2085 [STAC_D945GTP5] = "5stack",
2086 [STAC_D945GTP3] = "3stack",
2087 [STAC_INTEL_MAC_V1] = "intel-mac-v1",
2088 [STAC_INTEL_MAC_V2] = "intel-mac-v2",
2089 [STAC_INTEL_MAC_V3] = "intel-mac-v3",
2090 [STAC_INTEL_MAC_V4] = "intel-mac-v4",
2091 [STAC_INTEL_MAC_V5] = "intel-mac-v5",
2092 [STAC_INTEL_MAC_AUTO] = "intel-mac-auto",
2093 /* for backward compatibility */
2094 [STAC_MACMINI] = "macmini",
2095 [STAC_MACBOOK] = "macbook",
2096 [STAC_MACBOOK_PRO_V1] = "macbook-pro-v1",
2097 [STAC_MACBOOK_PRO_V2] = "macbook-pro",
2098 [STAC_IMAC_INTEL] = "imac-intel",
2099 [STAC_IMAC_INTEL_20] = "imac-intel-20",
2100 [STAC_ECS_202] = "ecs202",
2101 [STAC_922X_DELL_D81] = "dell-d81",
2102 [STAC_922X_DELL_D82] = "dell-d82",
2103 [STAC_922X_DELL_M81] = "dell-m81",
2104 [STAC_922X_DELL_M82] = "dell-m82",
2105 };
2106
2107 static struct snd_pci_quirk stac922x_cfg_tbl[] = {
2108 /* SigmaTel reference board */
2109 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2110 "DFI LanParty", STAC_D945_REF),
2111 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2112 "DFI LanParty", STAC_D945_REF),
2113 /* Intel 945G based systems */
2114 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101,
2115 "Intel D945G", STAC_D945GTP3),
2116 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0202,
2117 "Intel D945G", STAC_D945GTP3),
2118 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0606,
2119 "Intel D945G", STAC_D945GTP3),
2120 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0601,
2121 "Intel D945G", STAC_D945GTP3),
2122 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0111,
2123 "Intel D945G", STAC_D945GTP3),
2124 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1115,
2125 "Intel D945G", STAC_D945GTP3),
2126 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1116,
2127 "Intel D945G", STAC_D945GTP3),
2128 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1117,
2129 "Intel D945G", STAC_D945GTP3),
2130 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1118,
2131 "Intel D945G", STAC_D945GTP3),
2132 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1119,
2133 "Intel D945G", STAC_D945GTP3),
2134 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x8826,
2135 "Intel D945G", STAC_D945GTP3),
2136 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5049,
2137 "Intel D945G", STAC_D945GTP3),
2138 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5055,
2139 "Intel D945G", STAC_D945GTP3),
2140 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5048,
2141 "Intel D945G", STAC_D945GTP3),
2142 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0110,
2143 "Intel D945G", STAC_D945GTP3),
2144 /* Intel D945G 5-stack systems */
2145 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0404,
2146 "Intel D945G", STAC_D945GTP5),
2147 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0303,
2148 "Intel D945G", STAC_D945GTP5),
2149 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0013,
2150 "Intel D945G", STAC_D945GTP5),
2151 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0417,
2152 "Intel D945G", STAC_D945GTP5),
2153 /* Intel 945P based systems */
2154 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0b0b,
2155 "Intel D945P", STAC_D945GTP3),
2156 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0112,
2157 "Intel D945P", STAC_D945GTP3),
2158 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0d0d,
2159 "Intel D945P", STAC_D945GTP3),
2160 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0909,
2161 "Intel D945P", STAC_D945GTP3),
2162 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0505,
2163 "Intel D945P", STAC_D945GTP3),
2164 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707,
2165 "Intel D945P", STAC_D945GTP5),
2166 /* other intel */
2167 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0204,
2168 "Intel D945", STAC_D945_REF),
2169 /* other systems */
2170 /* Apple Intel Mac (Mac Mini, MacBook, MacBook Pro...) */
2171 SND_PCI_QUIRK(0x8384, 0x7680,
2172 "Mac", STAC_INTEL_MAC_AUTO),
2173 /* Dell systems */
2174 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a7,
2175 "unknown Dell", STAC_922X_DELL_D81),
2176 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a9,
2177 "unknown Dell", STAC_922X_DELL_D81),
2178 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ab,
2179 "unknown Dell", STAC_922X_DELL_D81),
2180 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ac,
2181 "unknown Dell", STAC_922X_DELL_D82),
2182 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bf,
2183 "unknown Dell", STAC_922X_DELL_M81),
2184 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d0,
2185 "unknown Dell", STAC_922X_DELL_D82),
2186 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d1,
2187 "unknown Dell", STAC_922X_DELL_D81),
2188 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d2,
2189 "unknown Dell", STAC_922X_DELL_D81),
2190 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d7,
2191 "Dell XPS M1210", STAC_922X_DELL_M82),
2192 /* ECS/PC Chips boards */
2193 SND_PCI_QUIRK_MASK(0x1019, 0xf000, 0x2000,
2194 "ECS/PC chips", STAC_ECS_202),
2195 {} /* terminator */
2196 };
2197
2198 static unsigned int ref927x_pin_configs[14] = {
2199 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2200 0x01a19040, 0x01011012, 0x01016011, 0x0101201f,
2201 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
2202 0x01c42190, 0x40000100,
2203 };
2204
2205 static unsigned int d965_3st_pin_configs[14] = {
2206 0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
2207 0x01a19021, 0x01813024, 0x40000100, 0x40000100,
2208 0x40000100, 0x40000100, 0x40000100, 0x40000100,
2209 0x40000100, 0x40000100
2210 };
2211
2212 static unsigned int d965_5st_pin_configs[14] = {
2213 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2214 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
2215 0x40000100, 0x40000100, 0x40000100, 0x01442070,
2216 0x40000100, 0x40000100
2217 };
2218
2219 static unsigned int d965_5st_no_fp_pin_configs[14] = {
2220 0x40000100, 0x40000100, 0x0181304e, 0x01014010,
2221 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
2222 0x40000100, 0x40000100, 0x40000100, 0x01442070,
2223 0x40000100, 0x40000100
2224 };
2225
2226 static unsigned int dell_3st_pin_configs[14] = {
2227 0x02211230, 0x02a11220, 0x01a19040, 0x01114210,
2228 0x01111212, 0x01116211, 0x01813050, 0x01112214,
2229 0x403003fa, 0x90a60040, 0x90a60040, 0x404003fb,
2230 0x40c003fc, 0x40000100
2231 };
2232
2233 static unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
2234 [STAC_D965_REF_NO_JD] = ref927x_pin_configs,
2235 [STAC_D965_REF] = ref927x_pin_configs,
2236 [STAC_D965_3ST] = d965_3st_pin_configs,
2237 [STAC_D965_5ST] = d965_5st_pin_configs,
2238 [STAC_D965_5ST_NO_FP] = d965_5st_no_fp_pin_configs,
2239 [STAC_DELL_3ST] = dell_3st_pin_configs,
2240 [STAC_DELL_BIOS] = NULL,
2241 };
2242
2243 static const char *stac927x_models[STAC_927X_MODELS] = {
2244 [STAC_927X_AUTO] = "auto",
2245 [STAC_D965_REF_NO_JD] = "ref-no-jd",
2246 [STAC_D965_REF] = "ref",
2247 [STAC_D965_3ST] = "3stack",
2248 [STAC_D965_5ST] = "5stack",
2249 [STAC_D965_5ST_NO_FP] = "5stack-no-fp",
2250 [STAC_DELL_3ST] = "dell-3stack",
2251 [STAC_DELL_BIOS] = "dell-bios",
2252 };
2253
2254 static struct snd_pci_quirk stac927x_cfg_tbl[] = {
2255 /* SigmaTel reference board */
2256 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2257 "DFI LanParty", STAC_D965_REF),
2258 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2259 "DFI LanParty", STAC_D965_REF),
2260 /* Intel 946 based systems */
2261 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST),
2262 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST),
2263 /* 965 based 3 stack systems */
2264 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2100,
2265 "Intel D965", STAC_D965_3ST),
2266 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2000,
2267 "Intel D965", STAC_D965_3ST),
2268 /* Dell 3 stack systems */
2269 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f7, "Dell XPS M1730", STAC_DELL_3ST),
2270 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01dd, "Dell Dimension E520", STAC_DELL_3ST),
2271 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ed, "Dell ", STAC_DELL_3ST),
2272 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f4, "Dell ", STAC_DELL_3ST),
2273 /* Dell 3 stack systems with verb table in BIOS */
2274 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f3, "Dell Inspiron 1420", STAC_DELL_BIOS),
2275 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0227, "Dell Vostro 1400 ", STAC_DELL_BIOS),
2276 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022e, "Dell ", STAC_DELL_BIOS),
2277 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022f, "Dell Inspiron 1525", STAC_DELL_BIOS),
2278 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0242, "Dell ", STAC_DELL_BIOS),
2279 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0243, "Dell ", STAC_DELL_BIOS),
2280 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ff, "Dell ", STAC_DELL_BIOS),
2281 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0209, "Dell XPS 1330", STAC_DELL_BIOS),
2282 /* 965 based 5 stack systems */
2283 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2300,
2284 "Intel D965", STAC_D965_5ST),
2285 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2500,
2286 "Intel D965", STAC_D965_5ST),
2287 {} /* terminator */
2288 };
2289
2290 static unsigned int ref9205_pin_configs[12] = {
2291 0x40000100, 0x40000100, 0x01016011, 0x01014010,
2292 0x01813122, 0x01a19021, 0x01019020, 0x40000100,
2293 0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
2294 };
2295
2296 /*
2297 STAC 9205 pin configs for
2298 102801F1
2299 102801F2
2300 102801FC
2301 102801FD
2302 10280204
2303 1028021F
2304 10280228 (Dell Vostro 1500)
2305 */
2306 static unsigned int dell_9205_m42_pin_configs[12] = {
2307 0x0321101F, 0x03A11020, 0x400003FA, 0x90170310,
2308 0x400003FB, 0x400003FC, 0x400003FD, 0x40F000F9,
2309 0x90A60330, 0x400003FF, 0x0144131F, 0x40C003FE,
2310 };
2311
2312 /*
2313 STAC 9205 pin configs for
2314 102801F9
2315 102801FA
2316 102801FE
2317 102801FF (Dell Precision M4300)
2318 10280206
2319 10280200
2320 10280201
2321 */
2322 static unsigned int dell_9205_m43_pin_configs[12] = {
2323 0x0321101f, 0x03a11020, 0x90a70330, 0x90170310,
2324 0x400000fe, 0x400000ff, 0x400000fd, 0x40f000f9,
2325 0x400000fa, 0x400000fc, 0x0144131f, 0x40c003f8,
2326 };
2327
2328 static unsigned int dell_9205_m44_pin_configs[12] = {
2329 0x0421101f, 0x04a11020, 0x400003fa, 0x90170310,
2330 0x400003fb, 0x400003fc, 0x400003fd, 0x400003f9,
2331 0x90a60330, 0x400003ff, 0x01441340, 0x40c003fe,
2332 };
2333
2334 static unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
2335 [STAC_9205_REF] = ref9205_pin_configs,
2336 [STAC_9205_DELL_M42] = dell_9205_m42_pin_configs,
2337 [STAC_9205_DELL_M43] = dell_9205_m43_pin_configs,
2338 [STAC_9205_DELL_M44] = dell_9205_m44_pin_configs,
2339 [STAC_9205_EAPD] = NULL,
2340 };
2341
2342 static const char *stac9205_models[STAC_9205_MODELS] = {
2343 [STAC_9205_AUTO] = "auto",
2344 [STAC_9205_REF] = "ref",
2345 [STAC_9205_DELL_M42] = "dell-m42",
2346 [STAC_9205_DELL_M43] = "dell-m43",
2347 [STAC_9205_DELL_M44] = "dell-m44",
2348 [STAC_9205_EAPD] = "eapd",
2349 };
2350
2351 static struct snd_pci_quirk stac9205_cfg_tbl[] = {
2352 /* SigmaTel reference board */
2353 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2354 "DFI LanParty", STAC_9205_REF),
2355 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xfb30,
2356 "SigmaTel", STAC_9205_REF),
2357 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2358 "DFI LanParty", STAC_9205_REF),
2359 /* Dell */
2360 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f1,
2361 "unknown Dell", STAC_9205_DELL_M42),
2362 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f2,
2363 "unknown Dell", STAC_9205_DELL_M42),
2364 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f8,
2365 "Dell Precision", STAC_9205_DELL_M43),
2366 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f9,
2367 "Dell Precision", STAC_9205_DELL_M43),
2368 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fa,
2369 "Dell Precision", STAC_9205_DELL_M43),
2370 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fc,
2371 "unknown Dell", STAC_9205_DELL_M42),
2372 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fd,
2373 "unknown Dell", STAC_9205_DELL_M42),
2374 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fe,
2375 "Dell Precision", STAC_9205_DELL_M43),
2376 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ff,
2377 "Dell Precision M4300", STAC_9205_DELL_M43),
2378 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0204,
2379 "unknown Dell", STAC_9205_DELL_M42),
2380 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0206,
2381 "Dell Precision", STAC_9205_DELL_M43),
2382 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021b,
2383 "Dell Precision", STAC_9205_DELL_M43),
2384 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021c,
2385 "Dell Precision", STAC_9205_DELL_M43),
2386 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021f,
2387 "Dell Inspiron", STAC_9205_DELL_M44),
2388 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0228,
2389 "Dell Vostro 1500", STAC_9205_DELL_M42),
2390 /* Gateway */
2391 SND_PCI_QUIRK(0x107b, 0x0560, "Gateway T6834c", STAC_9205_EAPD),
2392 SND_PCI_QUIRK(0x107b, 0x0565, "Gateway T1616", STAC_9205_EAPD),
2393 {} /* terminator */
2394 };
2395
2396 static void stac92xx_set_config_regs(struct hda_codec *codec,
2397 unsigned int *pincfgs)
2398 {
2399 int i;
2400 struct sigmatel_spec *spec = codec->spec;
2401
2402 if (!pincfgs)
2403 return;
2404
2405 for (i = 0; i < spec->num_pins; i++)
2406 if (spec->pin_nids[i] && pincfgs[i])
2407 snd_hda_codec_set_pincfg(codec, spec->pin_nids[i],
2408 pincfgs[i]);
2409 }
2410
2411 /*
2412 * Analog playback callbacks
2413 */
2414 static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
2415 struct hda_codec *codec,
2416 struct snd_pcm_substream *substream)
2417 {
2418 struct sigmatel_spec *spec = codec->spec;
2419 if (spec->stream_delay)
2420 msleep(spec->stream_delay);
2421 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2422 hinfo);
2423 }
2424
2425 static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2426 struct hda_codec *codec,
2427 unsigned int stream_tag,
2428 unsigned int format,
2429 struct snd_pcm_substream *substream)
2430 {
2431 struct sigmatel_spec *spec = codec->spec;
2432 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
2433 }
2434
2435 static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2436 struct hda_codec *codec,
2437 struct snd_pcm_substream *substream)
2438 {
2439 struct sigmatel_spec *spec = codec->spec;
2440 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2441 }
2442
2443 /*
2444 * Digital playback callbacks
2445 */
2446 static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2447 struct hda_codec *codec,
2448 struct snd_pcm_substream *substream)
2449 {
2450 struct sigmatel_spec *spec = codec->spec;
2451 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2452 }
2453
2454 static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2455 struct hda_codec *codec,
2456 struct snd_pcm_substream *substream)
2457 {
2458 struct sigmatel_spec *spec = codec->spec;
2459 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2460 }
2461
2462 static int stac92xx_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2463 struct hda_codec *codec,
2464 unsigned int stream_tag,
2465 unsigned int format,
2466 struct snd_pcm_substream *substream)
2467 {
2468 struct sigmatel_spec *spec = codec->spec;
2469 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2470 stream_tag, format, substream);
2471 }
2472
2473 static int stac92xx_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2474 struct hda_codec *codec,
2475 struct snd_pcm_substream *substream)
2476 {
2477 struct sigmatel_spec *spec = codec->spec;
2478 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2479 }
2480
2481
2482 /*
2483 * Analog capture callbacks
2484 */
2485 static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2486 struct hda_codec *codec,
2487 unsigned int stream_tag,
2488 unsigned int format,
2489 struct snd_pcm_substream *substream)
2490 {
2491 struct sigmatel_spec *spec = codec->spec;
2492 hda_nid_t nid = spec->adc_nids[substream->number];
2493
2494 if (spec->powerdown_adcs) {
2495 msleep(40);
2496 snd_hda_codec_write(codec, nid, 0,
2497 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
2498 }
2499 snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format);
2500 return 0;
2501 }
2502
2503 static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2504 struct hda_codec *codec,
2505 struct snd_pcm_substream *substream)
2506 {
2507 struct sigmatel_spec *spec = codec->spec;
2508 hda_nid_t nid = spec->adc_nids[substream->number];
2509
2510 snd_hda_codec_cleanup_stream(codec, nid);
2511 if (spec->powerdown_adcs)
2512 snd_hda_codec_write(codec, nid, 0,
2513 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
2514 return 0;
2515 }
2516
2517 static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
2518 .substreams = 1,
2519 .channels_min = 2,
2520 .channels_max = 2,
2521 /* NID is set in stac92xx_build_pcms */
2522 .ops = {
2523 .open = stac92xx_dig_playback_pcm_open,
2524 .close = stac92xx_dig_playback_pcm_close,
2525 .prepare = stac92xx_dig_playback_pcm_prepare,
2526 .cleanup = stac92xx_dig_playback_pcm_cleanup
2527 },
2528 };
2529
2530 static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
2531 .substreams = 1,
2532 .channels_min = 2,
2533 .channels_max = 2,
2534 /* NID is set in stac92xx_build_pcms */
2535 };
2536
2537 static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
2538 .substreams = 1,
2539 .channels_min = 2,
2540 .channels_max = 8,
2541 .nid = 0x02, /* NID to query formats and rates */
2542 .ops = {
2543 .open = stac92xx_playback_pcm_open,
2544 .prepare = stac92xx_playback_pcm_prepare,
2545 .cleanup = stac92xx_playback_pcm_cleanup
2546 },
2547 };
2548
2549 static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
2550 .substreams = 1,
2551 .channels_min = 2,
2552 .channels_max = 2,
2553 .nid = 0x06, /* NID to query formats and rates */
2554 .ops = {
2555 .open = stac92xx_playback_pcm_open,
2556 .prepare = stac92xx_playback_pcm_prepare,
2557 .cleanup = stac92xx_playback_pcm_cleanup
2558 },
2559 };
2560
2561 static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
2562 .channels_min = 2,
2563 .channels_max = 2,
2564 /* NID + .substreams is set in stac92xx_build_pcms */
2565 .ops = {
2566 .prepare = stac92xx_capture_pcm_prepare,
2567 .cleanup = stac92xx_capture_pcm_cleanup
2568 },
2569 };
2570
2571 static int stac92xx_build_pcms(struct hda_codec *codec)
2572 {
2573 struct sigmatel_spec *spec = codec->spec;
2574 struct hda_pcm *info = spec->pcm_rec;
2575
2576 codec->num_pcms = 1;
2577 codec->pcm_info = info;
2578
2579 info->name = "STAC92xx Analog";
2580 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
2581 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2582 spec->multiout.dac_nids[0];
2583 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
2584 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2585 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adcs;
2586
2587 if (spec->alt_switch) {
2588 codec->num_pcms++;
2589 info++;
2590 info->name = "STAC92xx Analog Alt";
2591 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
2592 }
2593
2594 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2595 codec->num_pcms++;
2596 info++;
2597 info->name = "STAC92xx Digital";
2598 info->pcm_type = spec->autocfg.dig_out_type[0];
2599 if (spec->multiout.dig_out_nid) {
2600 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
2601 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2602 }
2603 if (spec->dig_in_nid) {
2604 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
2605 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2606 }
2607 }
2608
2609 return 0;
2610 }
2611
2612 static unsigned int stac92xx_get_default_vref(struct hda_codec *codec,
2613 hda_nid_t nid)
2614 {
2615 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2616 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
2617 if (pincap & AC_PINCAP_VREF_100)
2618 return AC_PINCTL_VREF_100;
2619 if (pincap & AC_PINCAP_VREF_80)
2620 return AC_PINCTL_VREF_80;
2621 if (pincap & AC_PINCAP_VREF_50)
2622 return AC_PINCTL_VREF_50;
2623 if (pincap & AC_PINCAP_VREF_GRD)
2624 return AC_PINCTL_VREF_GRD;
2625 return 0;
2626 }
2627
2628 static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
2629
2630 {
2631 snd_hda_codec_write_cache(codec, nid, 0,
2632 AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
2633 }
2634
2635 #define stac92xx_hp_switch_info snd_ctl_boolean_mono_info
2636
2637 static int stac92xx_hp_switch_get(struct snd_kcontrol *kcontrol,
2638 struct snd_ctl_elem_value *ucontrol)
2639 {
2640 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2641 struct sigmatel_spec *spec = codec->spec;
2642
2643 ucontrol->value.integer.value[0] = !!spec->hp_switch;
2644 return 0;
2645 }
2646
2647 static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid,
2648 unsigned char type);
2649
2650 static int stac92xx_hp_switch_put(struct snd_kcontrol *kcontrol,
2651 struct snd_ctl_elem_value *ucontrol)
2652 {
2653 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2654 struct sigmatel_spec *spec = codec->spec;
2655 int nid = kcontrol->private_value;
2656
2657 spec->hp_switch = ucontrol->value.integer.value[0] ? nid : 0;
2658
2659 /* check to be sure that the ports are upto date with
2660 * switch changes
2661 */
2662 stac_issue_unsol_event(codec, nid, STAC_HP_EVENT);
2663
2664 return 1;
2665 }
2666
2667 static int stac92xx_dc_bias_info(struct snd_kcontrol *kcontrol,
2668 struct snd_ctl_elem_info *uinfo)
2669 {
2670 int i;
2671 static char *texts[] = {
2672 "Mic In", "Line In", "Line Out"
2673 };
2674
2675 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2676 struct sigmatel_spec *spec = codec->spec;
2677 hda_nid_t nid = kcontrol->private_value;
2678
2679 if (nid == spec->mic_switch || nid == spec->line_switch)
2680 i = 3;
2681 else
2682 i = 2;
2683
2684 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2685 uinfo->value.enumerated.items = i;
2686 uinfo->count = 1;
2687 if (uinfo->value.enumerated.item >= i)
2688 uinfo->value.enumerated.item = i-1;
2689 strcpy(uinfo->value.enumerated.name,
2690 texts[uinfo->value.enumerated.item]);
2691
2692 return 0;
2693 }
2694
2695 static int stac92xx_dc_bias_get(struct snd_kcontrol *kcontrol,
2696 struct snd_ctl_elem_value *ucontrol)
2697 {
2698 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2699 hda_nid_t nid = kcontrol->private_value;
2700 unsigned int vref = stac92xx_vref_get(codec, nid);
2701
2702 if (vref == stac92xx_get_default_vref(codec, nid))
2703 ucontrol->value.enumerated.item[0] = 0;
2704 else if (vref == AC_PINCTL_VREF_GRD)
2705 ucontrol->value.enumerated.item[0] = 1;
2706 else if (vref == AC_PINCTL_VREF_HIZ)
2707 ucontrol->value.enumerated.item[0] = 2;
2708
2709 return 0;
2710 }
2711
2712 static int stac92xx_dc_bias_put(struct snd_kcontrol *kcontrol,
2713 struct snd_ctl_elem_value *ucontrol)
2714 {
2715 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2716 unsigned int new_vref = 0;
2717 int error;
2718 hda_nid_t nid = kcontrol->private_value;
2719
2720 if (ucontrol->value.enumerated.item[0] == 0)
2721 new_vref = stac92xx_get_default_vref(codec, nid);
2722 else if (ucontrol->value.enumerated.item[0] == 1)
2723 new_vref = AC_PINCTL_VREF_GRD;
2724 else if (ucontrol->value.enumerated.item[0] == 2)
2725 new_vref = AC_PINCTL_VREF_HIZ;
2726 else
2727 return 0;
2728
2729 if (new_vref != stac92xx_vref_get(codec, nid)) {
2730 error = stac92xx_vref_set(codec, nid, new_vref);
2731 return error;
2732 }
2733
2734 return 0;
2735 }
2736
2737 static int stac92xx_io_switch_info(struct snd_kcontrol *kcontrol,
2738 struct snd_ctl_elem_info *uinfo)
2739 {
2740 static char *texts[2];
2741 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2742 struct sigmatel_spec *spec = codec->spec;
2743
2744 if (kcontrol->private_value == spec->line_switch)
2745 texts[0] = "Line In";
2746 else
2747 texts[0] = "Mic In";
2748 texts[1] = "Line Out";
2749 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2750 uinfo->value.enumerated.items = 2;
2751 uinfo->count = 1;
2752
2753 if (uinfo->value.enumerated.item >= 2)
2754 uinfo->value.enumerated.item = 1;
2755 strcpy(uinfo->value.enumerated.name,
2756 texts[uinfo->value.enumerated.item]);
2757
2758 return 0;
2759 }
2760
2761 static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2762 {
2763 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2764 struct sigmatel_spec *spec = codec->spec;
2765 hda_nid_t nid = kcontrol->private_value;
2766 int io_idx = (nid == spec->mic_switch) ? 1 : 0;
2767
2768 ucontrol->value.enumerated.item[0] = spec->io_switch[io_idx];
2769 return 0;
2770 }
2771
2772 static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2773 {
2774 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2775 struct sigmatel_spec *spec = codec->spec;
2776 hda_nid_t nid = kcontrol->private_value;
2777 int io_idx = (nid == spec->mic_switch) ? 1 : 0;
2778 unsigned short val = !!ucontrol->value.enumerated.item[0];
2779
2780 spec->io_switch[io_idx] = val;
2781
2782 if (val)
2783 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
2784 else {
2785 unsigned int pinctl = AC_PINCTL_IN_EN;
2786 if (io_idx) /* set VREF for mic */
2787 pinctl |= stac92xx_get_default_vref(codec, nid);
2788 stac92xx_auto_set_pinctl(codec, nid, pinctl);
2789 }
2790
2791 /* check the auto-mute again: we need to mute/unmute the speaker
2792 * appropriately according to the pin direction
2793 */
2794 if (spec->hp_detect)
2795 stac_issue_unsol_event(codec, nid, STAC_HP_EVENT);
2796
2797 return 1;
2798 }
2799
2800 #define stac92xx_clfe_switch_info snd_ctl_boolean_mono_info
2801
2802 static int stac92xx_clfe_switch_get(struct snd_kcontrol *kcontrol,
2803 struct snd_ctl_elem_value *ucontrol)
2804 {
2805 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2806 struct sigmatel_spec *spec = codec->spec;
2807
2808 ucontrol->value.integer.value[0] = spec->clfe_swap;
2809 return 0;
2810 }
2811
2812 static int stac92xx_clfe_switch_put(struct snd_kcontrol *kcontrol,
2813 struct snd_ctl_elem_value *ucontrol)
2814 {
2815 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2816 struct sigmatel_spec *spec = codec->spec;
2817 hda_nid_t nid = kcontrol->private_value & 0xff;
2818 unsigned int val = !!ucontrol->value.integer.value[0];
2819
2820 if (spec->clfe_swap == val)
2821 return 0;
2822
2823 spec->clfe_swap = val;
2824
2825 snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
2826 spec->clfe_swap ? 0x4 : 0x0);
2827
2828 return 1;
2829 }
2830
2831 #define STAC_CODEC_HP_SWITCH(xname) \
2832 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2833 .name = xname, \
2834 .index = 0, \
2835 .info = stac92xx_hp_switch_info, \
2836 .get = stac92xx_hp_switch_get, \
2837 .put = stac92xx_hp_switch_put, \
2838 }
2839
2840 #define STAC_CODEC_IO_SWITCH(xname, xpval) \
2841 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2842 .name = xname, \
2843 .index = 0, \
2844 .info = stac92xx_io_switch_info, \
2845 .get = stac92xx_io_switch_get, \
2846 .put = stac92xx_io_switch_put, \
2847 .private_value = xpval, \
2848 }
2849
2850 #define STAC_CODEC_CLFE_SWITCH(xname, xpval) \
2851 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2852 .name = xname, \
2853 .index = 0, \
2854 .info = stac92xx_clfe_switch_info, \
2855 .get = stac92xx_clfe_switch_get, \
2856 .put = stac92xx_clfe_switch_put, \
2857 .private_value = xpval, \
2858 }
2859
2860 enum {
2861 STAC_CTL_WIDGET_VOL,
2862 STAC_CTL_WIDGET_MUTE,
2863 STAC_CTL_WIDGET_MONO_MUX,
2864 STAC_CTL_WIDGET_AMP_MUX,
2865 STAC_CTL_WIDGET_AMP_VOL,
2866 STAC_CTL_WIDGET_HP_SWITCH,
2867 STAC_CTL_WIDGET_IO_SWITCH,
2868 STAC_CTL_WIDGET_CLFE_SWITCH,
2869 STAC_CTL_WIDGET_DC_BIAS
2870 };
2871
2872 static struct snd_kcontrol_new stac92xx_control_templates[] = {
2873 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2874 HDA_CODEC_MUTE(NULL, 0, 0, 0),
2875 STAC_MONO_MUX,
2876 STAC_AMP_MUX,
2877 STAC_AMP_VOL(NULL, 0, 0, 0, 0),
2878 STAC_CODEC_HP_SWITCH(NULL),
2879 STAC_CODEC_IO_SWITCH(NULL, 0),
2880 STAC_CODEC_CLFE_SWITCH(NULL, 0),
2881 DC_BIAS(NULL, 0, 0),
2882 };
2883
2884 /* add dynamic controls */
2885 static struct snd_kcontrol_new *
2886 stac_control_new(struct sigmatel_spec *spec,
2887 struct snd_kcontrol_new *ktemp,
2888 const char *name)
2889 {
2890 struct snd_kcontrol_new *knew;
2891
2892 snd_array_init(&spec->kctls, sizeof(*knew), 32);
2893 knew = snd_array_new(&spec->kctls);
2894 if (!knew)
2895 return NULL;
2896 *knew = *ktemp;
2897 knew->name = kstrdup(name, GFP_KERNEL);
2898 if (!knew->name) {
2899 /* roolback */
2900 memset(knew, 0, sizeof(*knew));
2901 spec->kctls.alloced--;
2902 return NULL;
2903 }
2904 return knew;
2905 }
2906
2907 static int stac92xx_add_control_temp(struct sigmatel_spec *spec,
2908 struct snd_kcontrol_new *ktemp,
2909 int idx, const char *name,
2910 unsigned long val)
2911 {
2912 struct snd_kcontrol_new *knew = stac_control_new(spec, ktemp, name);
2913 if (!knew)
2914 return -ENOMEM;
2915 knew->index = idx;
2916 knew->private_value = val;
2917 return 0;
2918 }
2919
2920 static inline int stac92xx_add_control_idx(struct sigmatel_spec *spec,
2921 int type, int idx, const char *name,
2922 unsigned long val)
2923 {
2924 return stac92xx_add_control_temp(spec,
2925 &stac92xx_control_templates[type],
2926 idx, name, val);
2927 }
2928
2929
2930 /* add dynamic controls */
2931 static inline int stac92xx_add_control(struct sigmatel_spec *spec, int type,
2932 const char *name, unsigned long val)
2933 {
2934 return stac92xx_add_control_idx(spec, type, 0, name, val);
2935 }
2936
2937 static struct snd_kcontrol_new stac_input_src_temp = {
2938 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2939 .name = "Input Source",
2940 .info = stac92xx_mux_enum_info,
2941 .get = stac92xx_mux_enum_get,
2942 .put = stac92xx_mux_enum_put,
2943 };
2944
2945 static inline int stac92xx_add_jack_mode_control(struct hda_codec *codec,
2946 hda_nid_t nid, int idx)
2947 {
2948 int def_conf = snd_hda_codec_get_pincfg(codec, nid);
2949 int control = 0;
2950 struct sigmatel_spec *spec = codec->spec;
2951 char name[22];
2952
2953 if (!((get_defcfg_connect(def_conf)) & AC_JACK_PORT_FIXED)) {
2954 if (stac92xx_get_default_vref(codec, nid) == AC_PINCTL_VREF_GRD
2955 && nid == spec->line_switch)
2956 control = STAC_CTL_WIDGET_IO_SWITCH;
2957 else if (snd_hda_query_pin_caps(codec, nid)
2958 & (AC_PINCAP_VREF_GRD << AC_PINCAP_VREF_SHIFT))
2959 control = STAC_CTL_WIDGET_DC_BIAS;
2960 else if (nid == spec->mic_switch)
2961 control = STAC_CTL_WIDGET_IO_SWITCH;
2962 }
2963
2964 if (control) {
2965 strcpy(name, auto_pin_cfg_labels[idx]);
2966 return stac92xx_add_control(codec->spec, control,
2967 strcat(name, " Jack Mode"), nid);
2968 }
2969
2970 return 0;
2971 }
2972
2973 static int stac92xx_add_input_source(struct sigmatel_spec *spec)
2974 {
2975 struct snd_kcontrol_new *knew;
2976 struct hda_input_mux *imux = &spec->private_imux;
2977
2978 if (!spec->num_adcs || imux->num_items <= 1)
2979 return 0; /* no need for input source control */
2980 knew = stac_control_new(spec, &stac_input_src_temp,
2981 stac_input_src_temp.name);
2982 if (!knew)
2983 return -ENOMEM;
2984 knew->count = spec->num_adcs;
2985 return 0;
2986 }
2987
2988 /* check whether the line-input can be used as line-out */
2989 static hda_nid_t check_line_out_switch(struct hda_codec *codec)
2990 {
2991 struct sigmatel_spec *spec = codec->spec;
2992 struct auto_pin_cfg *cfg = &spec->autocfg;
2993 hda_nid_t nid;
2994 unsigned int pincap;
2995
2996 if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
2997 return 0;
2998 nid = cfg->input_pins[AUTO_PIN_LINE];
2999 pincap = snd_hda_query_pin_caps(codec, nid);
3000 if (pincap & AC_PINCAP_OUT)
3001 return nid;
3002 return 0;
3003 }
3004
3005 /* check whether the mic-input can be used as line-out */
3006 static hda_nid_t check_mic_out_switch(struct hda_codec *codec)
3007 {
3008 struct sigmatel_spec *spec = codec->spec;
3009 struct auto_pin_cfg *cfg = &spec->autocfg;
3010 unsigned int def_conf, pincap;
3011 unsigned int mic_pin;
3012
3013 if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
3014 return 0;
3015 mic_pin = AUTO_PIN_MIC;
3016 for (;;) {
3017 hda_nid_t nid = cfg->input_pins[mic_pin];
3018 def_conf = snd_hda_codec_get_pincfg(codec, nid);
3019 /* some laptops have an internal analog microphone
3020 * which can't be used as a output */
3021 if (get_defcfg_connect(def_conf) != AC_JACK_PORT_FIXED) {
3022 pincap = snd_hda_query_pin_caps(codec, nid);
3023 if (pincap & AC_PINCAP_OUT)
3024 return nid;
3025 }
3026 if (mic_pin == AUTO_PIN_MIC)
3027 mic_pin = AUTO_PIN_FRONT_MIC;
3028 else
3029 break;
3030 }
3031 return 0;
3032 }
3033
3034 static int is_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
3035 {
3036 int i;
3037
3038 for (i = 0; i < spec->multiout.num_dacs; i++) {
3039 if (spec->multiout.dac_nids[i] == nid)
3040 return 1;
3041 }
3042
3043 return 0;
3044 }
3045
3046 static int check_all_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
3047 {
3048 int i;
3049 if (is_in_dac_nids(spec, nid))
3050 return 1;
3051 for (i = 0; i < spec->autocfg.hp_outs; i++)
3052 if (spec->hp_dacs[i] == nid)
3053 return 1;
3054 for (i = 0; i < spec->autocfg.speaker_outs; i++)
3055 if (spec->speaker_dacs[i] == nid)
3056 return 1;
3057 return 0;
3058 }
3059
3060 static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t nid)
3061 {
3062 struct sigmatel_spec *spec = codec->spec;
3063 int j, conn_len;
3064 hda_nid_t conn[HDA_MAX_CONNECTIONS];
3065 unsigned int wcaps, wtype;
3066
3067 conn_len = snd_hda_get_connections(codec, nid, conn,
3068 HDA_MAX_CONNECTIONS);
3069 for (j = 0; j < conn_len; j++) {
3070 wcaps = get_wcaps(codec, conn[j]);
3071 wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
3072 /* we check only analog outputs */
3073 if (wtype != AC_WID_AUD_OUT || (wcaps & AC_WCAP_DIGITAL))
3074 continue;
3075 /* if this route has a free DAC, assign it */
3076 if (!check_all_dac_nids(spec, conn[j])) {
3077 if (conn_len > 1) {
3078 /* select this DAC in the pin's input mux */
3079 snd_hda_codec_write_cache(codec, nid, 0,
3080 AC_VERB_SET_CONNECT_SEL, j);
3081 }
3082 return conn[j];
3083 }
3084 }
3085 /* if all DACs are already assigned, connect to the primary DAC */
3086 if (conn_len > 1) {
3087 for (j = 0; j < conn_len; j++) {
3088 if (conn[j] == spec->multiout.dac_nids[0]) {
3089 snd_hda_codec_write_cache(codec, nid, 0,
3090 AC_VERB_SET_CONNECT_SEL, j);
3091 break;
3092 }
3093 }
3094 }
3095 return 0;
3096 }
3097
3098 static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid);
3099 static int add_spec_extra_dacs(struct sigmatel_spec *spec, hda_nid_t nid);
3100
3101 /*
3102 * Fill in the dac_nids table from the parsed pin configuration
3103 * This function only works when every pin in line_out_pins[]
3104 * contains atleast one DAC in its connection list. Some 92xx
3105 * codecs are not connected directly to a DAC, such as the 9200
3106 * and 9202/925x. For those, dac_nids[] must be hard-coded.
3107 */
3108 static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec)
3109 {
3110 struct sigmatel_spec *spec = codec->spec;
3111 struct auto_pin_cfg *cfg = &spec->autocfg;
3112 int i;
3113 hda_nid_t nid, dac;
3114
3115 for (i = 0; i < cfg->line_outs; i++) {
3116 nid = cfg->line_out_pins[i];
3117 dac = get_unassigned_dac(codec, nid);
3118 if (!dac) {
3119 if (spec->multiout.num_dacs > 0) {
3120 /* we have already working output pins,
3121 * so let's drop the broken ones again
3122 */
3123 cfg->line_outs = spec->multiout.num_dacs;
3124 break;
3125 }
3126 /* error out, no available DAC found */
3127 snd_printk(KERN_ERR
3128 "%s: No available DAC for pin 0x%x\n",
3129 __func__, nid);
3130 return -ENODEV;
3131 }
3132 add_spec_dacs(spec, dac);
3133 }
3134
3135 for (i = 0; i < cfg->hp_outs; i++) {
3136 nid = cfg->hp_pins[i];
3137 dac = get_unassigned_dac(codec, nid);
3138 if (dac) {
3139 if (!spec->multiout.hp_nid)
3140 spec->multiout.hp_nid = dac;
3141 else
3142 add_spec_extra_dacs(spec, dac);
3143 }
3144 spec->hp_dacs[i] = dac;
3145 }
3146
3147 for (i = 0; i < cfg->speaker_outs; i++) {
3148 nid = cfg->speaker_pins[i];
3149 dac = get_unassigned_dac(codec, nid);
3150 if (dac)
3151 add_spec_extra_dacs(spec, dac);
3152 spec->speaker_dacs[i] = dac;
3153 }
3154
3155 /* add line-in as output */
3156 nid = check_line_out_switch(codec);
3157 if (nid) {
3158 dac = get_unassigned_dac(codec, nid);
3159 if (dac) {
3160 snd_printdd("STAC: Add line-in 0x%x as output %d\n",
3161 nid, cfg->line_outs);
3162 cfg->line_out_pins[cfg->line_outs] = nid;
3163 cfg->line_outs++;
3164 spec->line_switch = nid;
3165 add_spec_dacs(spec, dac);
3166 }
3167 }
3168 /* add mic as output */
3169 nid = check_mic_out_switch(codec);
3170 if (nid) {
3171 dac = get_unassigned_dac(codec, nid);
3172 if (dac) {
3173 snd_printdd("STAC: Add mic-in 0x%x as output %d\n",
3174 nid, cfg->line_outs);
3175 cfg->line_out_pins[cfg->line_outs] = nid;
3176 cfg->line_outs++;
3177 spec->mic_switch = nid;
3178 add_spec_dacs(spec, dac);
3179 }
3180 }
3181
3182 snd_printd("stac92xx: dac_nids=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
3183 spec->multiout.num_dacs,
3184 spec->multiout.dac_nids[0],
3185 spec->multiout.dac_nids[1],
3186 spec->multiout.dac_nids[2],
3187 spec->multiout.dac_nids[3],
3188 spec->multiout.dac_nids[4]);
3189
3190 return 0;
3191 }
3192
3193 /* create volume control/switch for the given prefx type */
3194 static int create_controls_idx(struct hda_codec *codec, const char *pfx,
3195 int idx, hda_nid_t nid, int chs)
3196 {
3197 struct sigmatel_spec *spec = codec->spec;
3198 char name[32];
3199 int err;
3200
3201 if (!spec->check_volume_offset) {
3202 unsigned int caps, step, nums, db_scale;
3203 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3204 step = (caps & AC_AMPCAP_STEP_SIZE) >>
3205 AC_AMPCAP_STEP_SIZE_SHIFT;
3206 step = (step + 1) * 25; /* in .01dB unit */
3207 nums = (caps & AC_AMPCAP_NUM_STEPS) >>
3208 AC_AMPCAP_NUM_STEPS_SHIFT;
3209 db_scale = nums * step;
3210 /* if dB scale is over -64dB, and finer enough,
3211 * let's reduce it to half
3212 */
3213 if (db_scale > 6400 && nums >= 0x1f)
3214 spec->volume_offset = nums / 2;
3215 spec->check_volume_offset = 1;
3216 }
3217
3218 sprintf(name, "%s Playback Volume", pfx);
3219 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_VOL, idx, name,
3220 HDA_COMPOSE_AMP_VAL_OFS(nid, chs, 0, HDA_OUTPUT,
3221 spec->volume_offset));
3222 if (err < 0)
3223 return err;
3224 sprintf(name, "%s Playback Switch", pfx);
3225 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_MUTE, idx, name,
3226 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
3227 if (err < 0)
3228 return err;
3229 return 0;
3230 }
3231
3232 #define create_controls(codec, pfx, nid, chs) \
3233 create_controls_idx(codec, pfx, 0, nid, chs)
3234
3235 static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
3236 {
3237 if (spec->multiout.num_dacs > 4) {
3238 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
3239 return 1;
3240 } else {
3241 spec->multiout.dac_nids[spec->multiout.num_dacs] = nid;
3242 spec->multiout.num_dacs++;
3243 }
3244 return 0;
3245 }
3246
3247 static int add_spec_extra_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
3248 {
3249 int i;
3250 for (i = 0; i < ARRAY_SIZE(spec->multiout.extra_out_nid); i++) {
3251 if (!spec->multiout.extra_out_nid[i]) {
3252 spec->multiout.extra_out_nid[i] = nid;
3253 return 0;
3254 }
3255 }
3256 printk(KERN_WARNING "stac92xx: No space for extra DAC 0x%x\n", nid);
3257 return 1;
3258 }
3259
3260 /* Create output controls
3261 * The mixer elements are named depending on the given type (AUTO_PIN_XXX_OUT)
3262 */
3263 static int create_multi_out_ctls(struct hda_codec *codec, int num_outs,
3264 const hda_nid_t *pins,
3265 const hda_nid_t *dac_nids,
3266 int type)
3267 {
3268 struct sigmatel_spec *spec = codec->spec;
3269 static const char *chname[4] = {
3270 "Front", "Surround", NULL /*CLFE*/, "Side"
3271 };
3272 hda_nid_t nid;
3273 int i, err;
3274 unsigned int wid_caps;
3275
3276 for (i = 0; i < num_outs && i < ARRAY_SIZE(chname); i++) {
3277 if (type == AUTO_PIN_HP_OUT && !spec->hp_detect) {
3278 wid_caps = get_wcaps(codec, pins[i]);
3279 if (wid_caps & AC_WCAP_UNSOL_CAP)
3280 spec->hp_detect = 1;
3281 }
3282 nid = dac_nids[i];
3283 if (!nid)
3284 continue;
3285 if (type != AUTO_PIN_HP_OUT && i == 2) {
3286 /* Center/LFE */
3287 err = create_controls(codec, "Center", nid, 1);
3288 if (err < 0)
3289 return err;
3290 err = create_controls(codec, "LFE", nid, 2);
3291 if (err < 0)
3292 return err;
3293
3294 wid_caps = get_wcaps(codec, nid);
3295
3296 if (wid_caps & AC_WCAP_LR_SWAP) {
3297 err = stac92xx_add_control(spec,
3298 STAC_CTL_WIDGET_CLFE_SWITCH,
3299 "Swap Center/LFE Playback Switch", nid);
3300
3301 if (err < 0)
3302 return err;
3303 }
3304
3305 } else {
3306 const char *name;
3307 int idx;
3308 switch (type) {
3309 case AUTO_PIN_HP_OUT:
3310 name = "Headphone";
3311 idx = i;
3312 break;
3313 case AUTO_PIN_SPEAKER_OUT:
3314 name = "Speaker";
3315 idx = i;
3316 break;
3317 default:
3318 name = chname[i];
3319 idx = 0;
3320 break;
3321 }
3322 err = create_controls_idx(codec, name, idx, nid, 3);
3323 if (err < 0)
3324 return err;
3325 }
3326 }
3327 return 0;
3328 }
3329
3330 /* add playback controls from the parsed DAC table */
3331 static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
3332 const struct auto_pin_cfg *cfg)
3333 {
3334 struct sigmatel_spec *spec = codec->spec;
3335 hda_nid_t nid;
3336 int err;
3337 int idx;
3338
3339 err = create_multi_out_ctls(codec, cfg->line_outs, cfg->line_out_pins,
3340 spec->multiout.dac_nids,
3341 cfg->line_out_type);
3342 if (err < 0)
3343 return err;
3344
3345 if (cfg->hp_outs > 1 && cfg->line_out_type == AUTO_PIN_LINE_OUT) {
3346 err = stac92xx_add_control(spec,
3347 STAC_CTL_WIDGET_HP_SWITCH,
3348 "Headphone as Line Out Switch",
3349 cfg->hp_pins[cfg->hp_outs - 1]);
3350 if (err < 0)
3351 return err;
3352 }
3353
3354 for (idx = AUTO_PIN_MIC; idx <= AUTO_PIN_FRONT_LINE; idx++) {
3355 nid = cfg->input_pins[idx];
3356 if (nid) {
3357 err = stac92xx_add_jack_mode_control(codec, nid, idx);
3358 if (err < 0)
3359 return err;
3360 }
3361 }
3362
3363 return 0;
3364 }
3365
3366 /* add playback controls for Speaker and HP outputs */
3367 static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
3368 struct auto_pin_cfg *cfg)
3369 {
3370 struct sigmatel_spec *spec = codec->spec;
3371 int err;
3372
3373 err = create_multi_out_ctls(codec, cfg->hp_outs, cfg->hp_pins,
3374 spec->hp_dacs, AUTO_PIN_HP_OUT);
3375 if (err < 0)
3376 return err;
3377
3378 err = create_multi_out_ctls(codec, cfg->speaker_outs, cfg->speaker_pins,
3379 spec->speaker_dacs, AUTO_PIN_SPEAKER_OUT);
3380 if (err < 0)
3381 return err;
3382
3383 return 0;
3384 }
3385
3386 /* labels for mono mux outputs */
3387 static const char *stac92xx_mono_labels[4] = {
3388 "DAC0", "DAC1", "Mixer", "DAC2"
3389 };
3390
3391 /* create mono mux for mono out on capable codecs */
3392 static int stac92xx_auto_create_mono_output_ctls(struct hda_codec *codec)
3393 {
3394 struct sigmatel_spec *spec = codec->spec;
3395 struct hda_input_mux *mono_mux = &spec->private_mono_mux;
3396 int i, num_cons;
3397 hda_nid_t con_lst[ARRAY_SIZE(stac92xx_mono_labels)];
3398
3399 num_cons = snd_hda_get_connections(codec,
3400 spec->mono_nid,
3401 con_lst,
3402 HDA_MAX_NUM_INPUTS);
3403 if (!num_cons || num_cons > ARRAY_SIZE(stac92xx_mono_labels))
3404 return -EINVAL;
3405
3406 for (i = 0; i < num_cons; i++) {
3407 mono_mux->items[mono_mux->num_items].label =
3408 stac92xx_mono_labels[i];
3409 mono_mux->items[mono_mux->num_items].index = i;
3410 mono_mux->num_items++;
3411 }
3412
3413 return stac92xx_add_control(spec, STAC_CTL_WIDGET_MONO_MUX,
3414 "Mono Mux", spec->mono_nid);
3415 }
3416
3417 /* labels for amp mux outputs */
3418 static const char *stac92xx_amp_labels[3] = {
3419 "Front Microphone", "Microphone", "Line In",
3420 };
3421
3422 /* create amp out controls mux on capable codecs */
3423 static int stac92xx_auto_create_amp_output_ctls(struct hda_codec *codec)
3424 {
3425 struct sigmatel_spec *spec = codec->spec;
3426 struct hda_input_mux *amp_mux = &spec->private_amp_mux;
3427 int i, err;
3428
3429 for (i = 0; i < spec->num_amps; i++) {
3430 amp_mux->items[amp_mux->num_items].label =
3431 stac92xx_amp_labels[i];
3432 amp_mux->items[amp_mux->num_items].index = i;
3433 amp_mux->num_items++;
3434 }
3435
3436 if (spec->num_amps > 1) {
3437 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_AMP_MUX,
3438 "Amp Selector Capture Switch", 0);
3439 if (err < 0)
3440 return err;
3441 }
3442 return stac92xx_add_control(spec, STAC_CTL_WIDGET_AMP_VOL,
3443 "Amp Capture Volume",
3444 HDA_COMPOSE_AMP_VAL(spec->amp_nids[0], 3, 0, HDA_INPUT));
3445 }
3446
3447
3448 /* create PC beep volume controls */
3449 static int stac92xx_auto_create_beep_ctls(struct hda_codec *codec,
3450 hda_nid_t nid)
3451 {
3452 struct sigmatel_spec *spec = codec->spec;
3453 u32 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3454 int err;
3455
3456 /* check for mute support for the the amp */
3457 if ((caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT) {
3458 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE,
3459 "PC Beep Playback Switch",
3460 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3461 if (err < 0)
3462 return err;
3463 }
3464
3465 /* check to see if there is volume support for the amp */
3466 if ((caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3467 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL,
3468 "PC Beep Playback Volume",
3469 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3470 if (err < 0)
3471 return err;
3472 }
3473 return 0;
3474 }
3475
3476 #ifdef CONFIG_SND_HDA_INPUT_BEEP
3477 #define stac92xx_dig_beep_switch_info snd_ctl_boolean_mono_info
3478
3479 static int stac92xx_dig_beep_switch_get(struct snd_kcontrol *kcontrol,
3480 struct snd_ctl_elem_value *ucontrol)
3481 {
3482 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3483 ucontrol->value.integer.value[0] = codec->beep->enabled;
3484 return 0;
3485 }
3486
3487 static int stac92xx_dig_beep_switch_put(struct snd_kcontrol *kcontrol,
3488 struct snd_ctl_elem_value *ucontrol)
3489 {
3490 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3491 int enabled = !!ucontrol->value.integer.value[0];
3492 if (codec->beep->enabled != enabled) {
3493 codec->beep->enabled = enabled;
3494 return 1;
3495 }
3496 return 0;
3497 }
3498
3499 static struct snd_kcontrol_new stac92xx_dig_beep_ctrl = {
3500 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3501 .info = stac92xx_dig_beep_switch_info,
3502 .get = stac92xx_dig_beep_switch_get,
3503 .put = stac92xx_dig_beep_switch_put,
3504 };
3505
3506 static int stac92xx_beep_switch_ctl(struct hda_codec *codec)
3507 {
3508 return stac92xx_add_control_temp(codec->spec, &stac92xx_dig_beep_ctrl,
3509 0, "PC Beep Playback Switch", 0);
3510 }
3511 #endif
3512
3513 static int stac92xx_auto_create_mux_input_ctls(struct hda_codec *codec)
3514 {
3515 struct sigmatel_spec *spec = codec->spec;
3516 int wcaps, nid, i, err = 0;
3517
3518 for (i = 0; i < spec->num_muxes; i++) {
3519 nid = spec->mux_nids[i];
3520 wcaps = get_wcaps(codec, nid);
3521
3522 if (wcaps & AC_WCAP_OUT_AMP) {
3523 err = stac92xx_add_control_idx(spec,
3524 STAC_CTL_WIDGET_VOL, i, "Mux Capture Volume",
3525 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
3526 if (err < 0)
3527 return err;
3528 }
3529 }
3530 return 0;
3531 };
3532
3533 static const char *stac92xx_spdif_labels[3] = {
3534 "Digital Playback", "Analog Mux 1", "Analog Mux 2",
3535 };
3536
3537 static int stac92xx_auto_create_spdif_mux_ctls(struct hda_codec *codec)
3538 {
3539 struct sigmatel_spec *spec = codec->spec;
3540 struct hda_input_mux *spdif_mux = &spec->private_smux;
3541 const char **labels = spec->spdif_labels;
3542 int i, num_cons;
3543 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
3544
3545 num_cons = snd_hda_get_connections(codec,
3546 spec->smux_nids[0],
3547 con_lst,
3548 HDA_MAX_NUM_INPUTS);
3549 if (!num_cons)
3550 return -EINVAL;
3551
3552 if (!labels)
3553 labels = stac92xx_spdif_labels;
3554
3555 for (i = 0; i < num_cons; i++) {
3556 spdif_mux->items[spdif_mux->num_items].label = labels[i];
3557 spdif_mux->items[spdif_mux->num_items].index = i;
3558 spdif_mux->num_items++;
3559 }
3560
3561 return 0;
3562 }
3563
3564 /* labels for dmic mux inputs */
3565 static const char *stac92xx_dmic_labels[5] = {
3566 "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
3567 "Digital Mic 3", "Digital Mic 4"
3568 };
3569
3570 /* create playback/capture controls for input pins on dmic capable codecs */
3571 static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
3572 const struct auto_pin_cfg *cfg)
3573 {
3574 struct sigmatel_spec *spec = codec->spec;
3575 struct hda_input_mux *dimux = &spec->private_dimux;
3576 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
3577 int err, i, j;
3578 char name[32];
3579
3580 dimux->items[dimux->num_items].label = stac92xx_dmic_labels[0];
3581 dimux->items[dimux->num_items].index = 0;
3582 dimux->num_items++;
3583
3584 for (i = 0; i < spec->num_dmics; i++) {
3585 hda_nid_t nid;
3586 int index;
3587 int num_cons;
3588 unsigned int wcaps;
3589 unsigned int def_conf;
3590
3591 def_conf = snd_hda_codec_get_pincfg(codec, spec->dmic_nids[i]);
3592 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
3593 continue;
3594
3595 nid = spec->dmic_nids[i];
3596 num_cons = snd_hda_get_connections(codec,
3597 spec->dmux_nids[0],
3598 con_lst,
3599 HDA_MAX_NUM_INPUTS);
3600 for (j = 0; j < num_cons; j++)
3601 if (con_lst[j] == nid) {
3602 index = j;
3603 goto found;
3604 }
3605 continue;
3606 found:
3607 wcaps = get_wcaps(codec, nid) &
3608 (AC_WCAP_OUT_AMP | AC_WCAP_IN_AMP);
3609
3610 if (wcaps) {
3611 sprintf(name, "%s Capture Volume",
3612 stac92xx_dmic_labels[dimux->num_items]);
3613
3614 err = stac92xx_add_control(spec,
3615 STAC_CTL_WIDGET_VOL,
3616 name,
3617 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3618 (wcaps & AC_WCAP_OUT_AMP) ?
3619 HDA_OUTPUT : HDA_INPUT));
3620 if (err < 0)
3621 return err;
3622 }
3623
3624 dimux->items[dimux->num_items].label =
3625 stac92xx_dmic_labels[dimux->num_items];
3626 dimux->items[dimux->num_items].index = index;
3627 dimux->num_items++;
3628 }
3629
3630 return 0;
3631 }
3632
3633 /* create playback/capture controls for input pins */
3634 static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
3635 {
3636 struct sigmatel_spec *spec = codec->spec;
3637 struct hda_input_mux *imux = &spec->private_imux;
3638 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
3639 int i, j, k;
3640
3641 for (i = 0; i < AUTO_PIN_LAST; i++) {
3642 int index;
3643
3644 if (!cfg->input_pins[i])
3645 continue;
3646 index = -1;
3647 for (j = 0; j < spec->num_muxes; j++) {
3648 int num_cons;
3649 num_cons = snd_hda_get_connections(codec,
3650 spec->mux_nids[j],
3651 con_lst,
3652 HDA_MAX_NUM_INPUTS);
3653 for (k = 0; k < num_cons; k++)
3654 if (con_lst[k] == cfg->input_pins[i]) {
3655 index = k;
3656 goto found;
3657 }
3658 }
3659 continue;
3660 found:
3661 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
3662 imux->items[imux->num_items].index = index;
3663 imux->num_items++;
3664 }
3665
3666 if (imux->num_items) {
3667 /*
3668 * Set the current input for the muxes.
3669 * The STAC9221 has two input muxes with identical source
3670 * NID lists. Hopefully this won't get confused.
3671 */
3672 for (i = 0; i < spec->num_muxes; i++) {
3673 snd_hda_codec_write_cache(codec, spec->mux_nids[i], 0,
3674 AC_VERB_SET_CONNECT_SEL,
3675 imux->items[0].index);
3676 }
3677 }
3678
3679 return 0;
3680 }
3681
3682 static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
3683 {
3684 struct sigmatel_spec *spec = codec->spec;
3685 int i;
3686
3687 for (i = 0; i < spec->autocfg.line_outs; i++) {
3688 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3689 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
3690 }
3691 }
3692
3693 static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
3694 {
3695 struct sigmatel_spec *spec = codec->spec;
3696 int i;
3697
3698 for (i = 0; i < spec->autocfg.hp_outs; i++) {
3699 hda_nid_t pin;
3700 pin = spec->autocfg.hp_pins[i];
3701 if (pin) /* connect to front */
3702 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
3703 }
3704 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
3705 hda_nid_t pin;
3706 pin = spec->autocfg.speaker_pins[i];
3707 if (pin) /* connect to front */
3708 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
3709 }
3710 }
3711
3712 static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out, hda_nid_t dig_in)
3713 {
3714 struct sigmatel_spec *spec = codec->spec;
3715 int hp_swap = 0;
3716 int err;
3717
3718 if ((err = snd_hda_parse_pin_def_config(codec,
3719 &spec->autocfg,
3720 spec->dmic_nids)) < 0)
3721 return err;
3722 if (! spec->autocfg.line_outs)
3723 return 0; /* can't find valid pin config */
3724
3725 /* If we have no real line-out pin and multiple hp-outs, HPs should
3726 * be set up as multi-channel outputs.
3727 */
3728 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT &&
3729 spec->autocfg.hp_outs > 1) {
3730 /* Copy hp_outs to line_outs, backup line_outs in
3731 * speaker_outs so that the following routines can handle
3732 * HP pins as primary outputs.
3733 */
3734 snd_printdd("stac92xx: Enabling multi-HPs workaround\n");
3735 memcpy(spec->autocfg.speaker_pins, spec->autocfg.line_out_pins,
3736 sizeof(spec->autocfg.line_out_pins));
3737 spec->autocfg.speaker_outs = spec->autocfg.line_outs;
3738 memcpy(spec->autocfg.line_out_pins, spec->autocfg.hp_pins,
3739 sizeof(spec->autocfg.hp_pins));
3740 spec->autocfg.line_outs = spec->autocfg.hp_outs;
3741 spec->autocfg.line_out_type = AUTO_PIN_HP_OUT;
3742 spec->autocfg.hp_outs = 0;
3743 hp_swap = 1;
3744 }
3745 if (spec->autocfg.mono_out_pin) {
3746 int dir = get_wcaps(codec, spec->autocfg.mono_out_pin) &
3747 (AC_WCAP_OUT_AMP | AC_WCAP_IN_AMP);
3748 u32 caps = query_amp_caps(codec,
3749 spec->autocfg.mono_out_pin, dir);
3750 hda_nid_t conn_list[1];
3751
3752 /* get the mixer node and then the mono mux if it exists */
3753 if (snd_hda_get_connections(codec,
3754 spec->autocfg.mono_out_pin, conn_list, 1) &&
3755 snd_hda_get_connections(codec, conn_list[0],
3756 conn_list, 1)) {
3757
3758 int wcaps = get_wcaps(codec, conn_list[0]);
3759 int wid_type = (wcaps & AC_WCAP_TYPE)
3760 >> AC_WCAP_TYPE_SHIFT;
3761 /* LR swap check, some stac925x have a mux that
3762 * changes the DACs output path instead of the
3763 * mono-mux path.
3764 */
3765 if (wid_type == AC_WID_AUD_SEL &&
3766 !(wcaps & AC_WCAP_LR_SWAP))
3767 spec->mono_nid = conn_list[0];
3768 }
3769 if (dir) {
3770 hda_nid_t nid = spec->autocfg.mono_out_pin;
3771
3772 /* most mono outs have a least a mute/unmute switch */
3773 dir = (dir & AC_WCAP_OUT_AMP) ? HDA_OUTPUT : HDA_INPUT;
3774 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE,
3775 "Mono Playback Switch",
3776 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
3777 if (err < 0)
3778 return err;
3779 /* check for volume support for the amp */
3780 if ((caps & AC_AMPCAP_NUM_STEPS)
3781 >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3782 err = stac92xx_add_control(spec,
3783 STAC_CTL_WIDGET_VOL,
3784 "Mono Playback Volume",
3785 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
3786 if (err < 0)
3787 return err;
3788 }
3789 }
3790
3791 stac92xx_auto_set_pinctl(codec, spec->autocfg.mono_out_pin,
3792 AC_PINCTL_OUT_EN);
3793 }
3794
3795 if (!spec->multiout.num_dacs) {
3796 err = stac92xx_auto_fill_dac_nids(codec);
3797 if (err < 0)
3798 return err;
3799 err = stac92xx_auto_create_multi_out_ctls(codec,
3800 &spec->autocfg);
3801 if (err < 0)
3802 return err;
3803 }
3804
3805 /* setup analog beep controls */
3806 if (spec->anabeep_nid > 0) {
3807 err = stac92xx_auto_create_beep_ctls(codec,
3808 spec->anabeep_nid);
3809 if (err < 0)
3810 return err;
3811 }
3812
3813 /* setup digital beep controls and input device */
3814 #ifdef CONFIG_SND_HDA_INPUT_BEEP
3815 if (spec->digbeep_nid > 0) {
3816 hda_nid_t nid = spec->digbeep_nid;
3817 unsigned int caps;
3818
3819 err = stac92xx_auto_create_beep_ctls(codec, nid);
3820 if (err < 0)
3821 return err;
3822 err = snd_hda_attach_beep_device(codec, nid);
3823 if (err < 0)
3824 return err;
3825 /* IDT/STAC codecs have linear beep tone parameter */
3826 codec->beep->linear_tone = 1;
3827 /* if no beep switch is available, make its own one */
3828 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3829 if (codec->beep &&
3830 !((caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT)) {
3831 err = stac92xx_beep_switch_ctl(codec);
3832 if (err < 0)
3833 return err;
3834 }
3835 }
3836 #endif
3837
3838 err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg);
3839 if (err < 0)
3840 return err;
3841
3842 /* All output parsing done, now restore the swapped hp pins */
3843 if (hp_swap) {
3844 memcpy(spec->autocfg.hp_pins, spec->autocfg.line_out_pins,
3845 sizeof(spec->autocfg.hp_pins));
3846 spec->autocfg.hp_outs = spec->autocfg.line_outs;
3847 spec->autocfg.line_out_type = AUTO_PIN_HP_OUT;
3848 spec->autocfg.line_outs = 0;
3849 }
3850
3851 err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg);
3852 if (err < 0)
3853 return err;
3854
3855 if (spec->mono_nid > 0) {
3856 err = stac92xx_auto_create_mono_output_ctls(codec);
3857 if (err < 0)
3858 return err;
3859 }
3860 if (spec->num_amps > 0) {
3861 err = stac92xx_auto_create_amp_output_ctls(codec);
3862 if (err < 0)
3863 return err;
3864 }
3865 if (spec->num_dmics > 0 && !spec->dinput_mux)
3866 if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
3867 &spec->autocfg)) < 0)
3868 return err;
3869 if (spec->num_muxes > 0) {
3870 err = stac92xx_auto_create_mux_input_ctls(codec);
3871 if (err < 0)
3872 return err;
3873 }
3874 if (spec->num_smuxes > 0) {
3875 err = stac92xx_auto_create_spdif_mux_ctls(codec);
3876 if (err < 0)
3877 return err;
3878 }
3879
3880 err = stac92xx_add_input_source(spec);
3881 if (err < 0)
3882 return err;
3883
3884 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3885 if (spec->multiout.max_channels > 2)
3886 spec->surr_switch = 1;
3887
3888 if (spec->autocfg.dig_outs)
3889 spec->multiout.dig_out_nid = dig_out;
3890 if (dig_in && spec->autocfg.dig_in_pin)
3891 spec->dig_in_nid = dig_in;
3892
3893 if (spec->kctls.list)
3894 spec->mixers[spec->num_mixers++] = spec->kctls.list;
3895
3896 spec->input_mux = &spec->private_imux;
3897 if (!spec->dinput_mux)
3898 spec->dinput_mux = &spec->private_dimux;
3899 spec->sinput_mux = &spec->private_smux;
3900 spec->mono_mux = &spec->private_mono_mux;
3901 spec->amp_mux = &spec->private_amp_mux;
3902 return 1;
3903 }
3904
3905 /* add playback controls for HP output */
3906 static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
3907 struct auto_pin_cfg *cfg)
3908 {
3909 struct sigmatel_spec *spec = codec->spec;
3910 hda_nid_t pin = cfg->hp_pins[0];
3911 unsigned int wid_caps;
3912
3913 if (! pin)
3914 return 0;
3915
3916 wid_caps = get_wcaps(codec, pin);
3917 if (wid_caps & AC_WCAP_UNSOL_CAP)
3918 spec->hp_detect = 1;
3919
3920 return 0;
3921 }
3922
3923 /* add playback controls for LFE output */
3924 static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
3925 struct auto_pin_cfg *cfg)
3926 {
3927 struct sigmatel_spec *spec = codec->spec;
3928 int err;
3929 hda_nid_t lfe_pin = 0x0;
3930 int i;
3931
3932 /*
3933 * search speaker outs and line outs for a mono speaker pin
3934 * with an amp. If one is found, add LFE controls
3935 * for it.
3936 */
3937 for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
3938 hda_nid_t pin = spec->autocfg.speaker_pins[i];
3939 unsigned int wcaps = get_wcaps(codec, pin);
3940 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
3941 if (wcaps == AC_WCAP_OUT_AMP)
3942 /* found a mono speaker with an amp, must be lfe */
3943 lfe_pin = pin;
3944 }
3945
3946 /* if speaker_outs is 0, then speakers may be in line_outs */
3947 if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
3948 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
3949 hda_nid_t pin = spec->autocfg.line_out_pins[i];
3950 unsigned int defcfg;
3951 defcfg = snd_hda_codec_get_pincfg(codec, pin);
3952 if (get_defcfg_device(defcfg) == AC_JACK_SPEAKER) {
3953 unsigned int wcaps = get_wcaps(codec, pin);
3954 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
3955 if (wcaps == AC_WCAP_OUT_AMP)
3956 /* found a mono speaker with an amp,
3957 must be lfe */
3958 lfe_pin = pin;
3959 }
3960 }
3961 }
3962
3963 if (lfe_pin) {
3964 err = create_controls(codec, "LFE", lfe_pin, 1);
3965 if (err < 0)
3966 return err;
3967 }
3968
3969 return 0;
3970 }
3971
3972 static int stac9200_parse_auto_config(struct hda_codec *codec)
3973 {
3974 struct sigmatel_spec *spec = codec->spec;
3975 int err;
3976
3977 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
3978 return err;
3979
3980 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
3981 return err;
3982
3983 if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
3984 return err;
3985
3986 if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
3987 return err;
3988
3989 if (spec->num_muxes > 0) {
3990 err = stac92xx_auto_create_mux_input_ctls(codec);
3991 if (err < 0)
3992 return err;
3993 }
3994
3995 err = stac92xx_add_input_source(spec);
3996 if (err < 0)
3997 return err;
3998
3999 if (spec->autocfg.dig_outs)
4000 spec->multiout.dig_out_nid = 0x05;
4001 if (spec->autocfg.dig_in_pin)
4002 spec->dig_in_nid = 0x04;
4003
4004 if (spec->kctls.list)
4005 spec->mixers[spec->num_mixers++] = spec->kctls.list;
4006
4007 spec->input_mux = &spec->private_imux;
4008 spec->dinput_mux = &spec->private_dimux;
4009
4010 return 1;
4011 }
4012
4013 /*
4014 * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
4015 * funky external mute control using GPIO pins.
4016 */
4017
4018 static void stac_gpio_set(struct hda_codec *codec, unsigned int mask,
4019 unsigned int dir_mask, unsigned int data)
4020 {
4021 unsigned int gpiostate, gpiomask, gpiodir;
4022
4023 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
4024 AC_VERB_GET_GPIO_DATA, 0);
4025 gpiostate = (gpiostate & ~dir_mask) | (data & dir_mask);
4026
4027 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
4028 AC_VERB_GET_GPIO_MASK, 0);
4029 gpiomask |= mask;
4030
4031 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
4032 AC_VERB_GET_GPIO_DIRECTION, 0);
4033 gpiodir |= dir_mask;
4034
4035 /* Configure GPIOx as CMOS */
4036 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
4037
4038 snd_hda_codec_write(codec, codec->afg, 0,
4039 AC_VERB_SET_GPIO_MASK, gpiomask);
4040 snd_hda_codec_read(codec, codec->afg, 0,
4041 AC_VERB_SET_GPIO_DIRECTION, gpiodir); /* sync */
4042
4043 msleep(1);
4044
4045 snd_hda_codec_read(codec, codec->afg, 0,
4046 AC_VERB_SET_GPIO_DATA, gpiostate); /* sync */
4047 }
4048
4049 #ifdef CONFIG_SND_HDA_INPUT_JACK
4050 static void stac92xx_free_jack_priv(struct snd_jack *jack)
4051 {
4052 struct sigmatel_jack *jacks = jack->private_data;
4053 jacks->nid = 0;
4054 jacks->jack = NULL;
4055 }
4056 #endif
4057
4058 static int stac92xx_add_jack(struct hda_codec *codec,
4059 hda_nid_t nid, int type)
4060 {
4061 #ifdef CONFIG_SND_HDA_INPUT_JACK
4062 struct sigmatel_spec *spec = codec->spec;
4063 struct sigmatel_jack *jack;
4064 int def_conf = snd_hda_codec_get_pincfg(codec, nid);
4065 int connectivity = get_defcfg_connect(def_conf);
4066 char name[32];
4067 int err;
4068
4069 if (connectivity && connectivity != AC_JACK_PORT_FIXED)
4070 return 0;
4071
4072 snd_array_init(&spec->jacks, sizeof(*jack), 32);
4073 jack = snd_array_new(&spec->jacks);
4074 if (!jack)
4075 return -ENOMEM;
4076 jack->nid = nid;
4077 jack->type = type;
4078
4079 snprintf(name, sizeof(name), "%s at %s %s Jack",
4080 snd_hda_get_jack_type(def_conf),
4081 snd_hda_get_jack_connectivity(def_conf),
4082 snd_hda_get_jack_location(def_conf));
4083
4084 err = snd_jack_new(codec->bus->card, name, type, &jack->jack);
4085 if (err < 0) {
4086 jack->nid = 0;
4087 return err;
4088 }
4089 jack->jack->private_data = jack;
4090 jack->jack->private_free = stac92xx_free_jack_priv;
4091 #endif
4092 return 0;
4093 }
4094
4095 static int stac_add_event(struct sigmatel_spec *spec, hda_nid_t nid,
4096 unsigned char type, int data)
4097 {
4098 struct sigmatel_event *event;
4099
4100 snd_array_init(&spec->events, sizeof(*event), 32);
4101 event = snd_array_new(&spec->events);
4102 if (!event)
4103 return -ENOMEM;
4104 event->nid = nid;
4105 event->type = type;
4106 event->tag = spec->events.used;
4107 event->data = data;
4108
4109 return event->tag;
4110 }
4111
4112 static struct sigmatel_event *stac_get_event(struct hda_codec *codec,
4113 hda_nid_t nid, unsigned char type)
4114 {
4115 struct sigmatel_spec *spec = codec->spec;
4116 struct sigmatel_event *event = spec->events.list;
4117 int i;
4118
4119 for (i = 0; i < spec->events.used; i++, event++) {
4120 if (event->nid == nid && event->type == type)
4121 return event;
4122 }
4123 return NULL;
4124 }
4125
4126 static struct sigmatel_event *stac_get_event_from_tag(struct hda_codec *codec,
4127 unsigned char tag)
4128 {
4129 struct sigmatel_spec *spec = codec->spec;
4130 struct sigmatel_event *event = spec->events.list;
4131 int i;
4132
4133 for (i = 0; i < spec->events.used; i++, event++) {
4134 if (event->tag == tag)
4135 return event;
4136 }
4137 return NULL;
4138 }
4139
4140 static void enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
4141 unsigned int type)
4142 {
4143 struct sigmatel_event *event;
4144 int tag;
4145
4146 if (!(get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP))
4147 return;
4148 event = stac_get_event(codec, nid, type);
4149 if (event)
4150 tag = event->tag;
4151 else
4152 tag = stac_add_event(codec->spec, nid, type, 0);
4153 if (tag < 0)
4154 return;
4155 snd_hda_codec_write_cache(codec, nid, 0,
4156 AC_VERB_SET_UNSOLICITED_ENABLE,
4157 AC_USRSP_EN | tag);
4158 }
4159
4160 static int is_nid_hp_pin(struct auto_pin_cfg *cfg, hda_nid_t nid)
4161 {
4162 int i;
4163 for (i = 0; i < cfg->hp_outs; i++)
4164 if (cfg->hp_pins[i] == nid)
4165 return 1; /* nid is a HP-Out */
4166
4167 return 0; /* nid is not a HP-Out */
4168 };
4169
4170 static void stac92xx_power_down(struct hda_codec *codec)
4171 {
4172 struct sigmatel_spec *spec = codec->spec;
4173
4174 /* power down inactive DACs */
4175 hda_nid_t *dac;
4176 for (dac = spec->dac_list; *dac; dac++)
4177 if (!check_all_dac_nids(spec, *dac))
4178 snd_hda_codec_write(codec, *dac, 0,
4179 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
4180 }
4181
4182 static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
4183 int enable);
4184
4185 /* override some hints from the hwdep entry */
4186 static void stac_store_hints(struct hda_codec *codec)
4187 {
4188 struct sigmatel_spec *spec = codec->spec;
4189 const char *p;
4190 int val;
4191
4192 val = snd_hda_get_bool_hint(codec, "hp_detect");
4193 if (val >= 0)
4194 spec->hp_detect = val;
4195 p = snd_hda_get_hint(codec, "gpio_mask");
4196 if (p) {
4197 spec->gpio_mask = simple_strtoul(p, NULL, 0);
4198 spec->eapd_mask = spec->gpio_dir = spec->gpio_data =
4199 spec->gpio_mask;
4200 }
4201 p = snd_hda_get_hint(codec, "gpio_dir");
4202 if (p)
4203 spec->gpio_dir = simple_strtoul(p, NULL, 0) & spec->gpio_mask;
4204 p = snd_hda_get_hint(codec, "gpio_data");
4205 if (p)
4206 spec->gpio_data = simple_strtoul(p, NULL, 0) & spec->gpio_mask;
4207 p = snd_hda_get_hint(codec, "eapd_mask");
4208 if (p)
4209 spec->eapd_mask = simple_strtoul(p, NULL, 0) & spec->gpio_mask;
4210 val = snd_hda_get_bool_hint(codec, "eapd_switch");
4211 if (val >= 0)
4212 spec->eapd_switch = val;
4213 }
4214
4215 static int stac92xx_init(struct hda_codec *codec)
4216 {
4217 struct sigmatel_spec *spec = codec->spec;
4218 struct auto_pin_cfg *cfg = &spec->autocfg;
4219 unsigned int gpio;
4220 int i;
4221
4222 snd_hda_sequence_write(codec, spec->init);
4223
4224 /* power down adcs initially */
4225 if (spec->powerdown_adcs)
4226 for (i = 0; i < spec->num_adcs; i++)
4227 snd_hda_codec_write(codec,
4228 spec->adc_nids[i], 0,
4229 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
4230
4231 /* override some hints */
4232 stac_store_hints(codec);
4233
4234 /* set up GPIO */
4235 gpio = spec->gpio_data;
4236 /* turn on EAPD statically when spec->eapd_switch isn't set.
4237 * otherwise, unsol event will turn it on/off dynamically
4238 */
4239 if (!spec->eapd_switch)
4240 gpio |= spec->eapd_mask;
4241 stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, gpio);
4242
4243 /* set up pins */
4244 if (spec->hp_detect) {
4245 /* Enable unsolicited responses on the HP widget */
4246 for (i = 0; i < cfg->hp_outs; i++) {
4247 hda_nid_t nid = cfg->hp_pins[i];
4248 enable_pin_detect(codec, nid, STAC_HP_EVENT);
4249 }
4250 /* force to enable the first line-out; the others are set up
4251 * in unsol_event
4252 */
4253 stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
4254 AC_PINCTL_OUT_EN);
4255 /* fake event to set up pins */
4256 stac_issue_unsol_event(codec, spec->autocfg.hp_pins[0],
4257 STAC_HP_EVENT);
4258 } else {
4259 stac92xx_auto_init_multi_out(codec);
4260 stac92xx_auto_init_hp_out(codec);
4261 for (i = 0; i < cfg->hp_outs; i++)
4262 stac_toggle_power_map(codec, cfg->hp_pins[i], 1);
4263 }
4264 for (i = 0; i < AUTO_PIN_LAST; i++) {
4265 hda_nid_t nid = cfg->input_pins[i];
4266 if (nid) {
4267 unsigned int pinctl, conf;
4268 if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC) {
4269 /* for mic pins, force to initialize */
4270 pinctl = stac92xx_get_default_vref(codec, nid);
4271 pinctl |= AC_PINCTL_IN_EN;
4272 stac92xx_auto_set_pinctl(codec, nid, pinctl);
4273 } else {
4274 pinctl = snd_hda_codec_read(codec, nid, 0,
4275 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4276 /* if PINCTL already set then skip */
4277 /* Also, if both INPUT and OUTPUT are set,
4278 * it must be a BIOS bug; need to override, too
4279 */
4280 if (!(pinctl & AC_PINCTL_IN_EN) ||
4281 (pinctl & AC_PINCTL_OUT_EN)) {
4282 pinctl &= ~AC_PINCTL_OUT_EN;
4283 pinctl |= AC_PINCTL_IN_EN;
4284 stac92xx_auto_set_pinctl(codec, nid,
4285 pinctl);
4286 }
4287 }
4288 conf = snd_hda_codec_get_pincfg(codec, nid);
4289 if (get_defcfg_connect(conf) != AC_JACK_PORT_FIXED) {
4290 enable_pin_detect(codec, nid,
4291 STAC_INSERT_EVENT);
4292 stac_issue_unsol_event(codec, nid,
4293 STAC_INSERT_EVENT);
4294 }
4295 }
4296 }
4297 for (i = 0; i < spec->num_dmics; i++)
4298 stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
4299 AC_PINCTL_IN_EN);
4300 if (cfg->dig_out_pins[0])
4301 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pins[0],
4302 AC_PINCTL_OUT_EN);
4303 if (cfg->dig_in_pin)
4304 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
4305 AC_PINCTL_IN_EN);
4306 for (i = 0; i < spec->num_pwrs; i++) {
4307 hda_nid_t nid = spec->pwr_nids[i];
4308 int pinctl, def_conf;
4309
4310 /* power on when no jack detection is available */
4311 if (!spec->hp_detect) {
4312 stac_toggle_power_map(codec, nid, 1);
4313 continue;
4314 }
4315
4316 if (is_nid_hp_pin(cfg, nid))
4317 continue; /* already has an unsol event */
4318
4319 pinctl = snd_hda_codec_read(codec, nid, 0,
4320 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4321 /* outputs are only ports capable of power management
4322 * any attempts on powering down a input port cause the
4323 * referenced VREF to act quirky.
4324 */
4325 if (pinctl & AC_PINCTL_IN_EN) {
4326 stac_toggle_power_map(codec, nid, 1);
4327 continue;
4328 }
4329 def_conf = snd_hda_codec_get_pincfg(codec, nid);
4330 def_conf = get_defcfg_connect(def_conf);
4331 /* skip any ports that don't have jacks since presence
4332 * detection is useless */
4333 if (def_conf != AC_JACK_PORT_COMPLEX) {
4334 if (def_conf != AC_JACK_PORT_NONE)
4335 stac_toggle_power_map(codec, nid, 1);
4336 continue;
4337 }
4338 if (!stac_get_event(codec, nid, STAC_INSERT_EVENT)) {
4339 enable_pin_detect(codec, nid, STAC_PWR_EVENT);
4340 stac_issue_unsol_event(codec, nid, STAC_PWR_EVENT);
4341 }
4342 }
4343 if (spec->dac_list)
4344 stac92xx_power_down(codec);
4345 return 0;
4346 }
4347
4348 static void stac92xx_free_jacks(struct hda_codec *codec)
4349 {
4350 #ifdef CONFIG_SND_HDA_INPUT_JACK
4351 /* free jack instances manually when clearing/reconfiguring */
4352 struct sigmatel_spec *spec = codec->spec;
4353 if (!codec->bus->shutdown && spec->jacks.list) {
4354 struct sigmatel_jack *jacks = spec->jacks.list;
4355 int i;
4356 for (i = 0; i < spec->jacks.used; i++, jacks++) {
4357 if (jacks->jack)
4358 snd_device_free(codec->bus->card, jacks->jack);
4359 }
4360 }
4361 snd_array_free(&spec->jacks);
4362 #endif
4363 }
4364
4365 static void stac92xx_free_kctls(struct hda_codec *codec)
4366 {
4367 struct sigmatel_spec *spec = codec->spec;
4368
4369 if (spec->kctls.list) {
4370 struct snd_kcontrol_new *kctl = spec->kctls.list;
4371 int i;
4372 for (i = 0; i < spec->kctls.used; i++)
4373 kfree(kctl[i].name);
4374 }
4375 snd_array_free(&spec->kctls);
4376 }
4377
4378 static void stac92xx_free(struct hda_codec *codec)
4379 {
4380 struct sigmatel_spec *spec = codec->spec;
4381
4382 if (! spec)
4383 return;
4384
4385 stac92xx_free_jacks(codec);
4386 snd_array_free(&spec->events);
4387
4388 kfree(spec);
4389 snd_hda_detach_beep_device(codec);
4390 }
4391
4392 static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
4393 unsigned int flag)
4394 {
4395 unsigned int old_ctl, pin_ctl;
4396
4397 pin_ctl = snd_hda_codec_read(codec, nid,
4398 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
4399
4400 if (pin_ctl & AC_PINCTL_IN_EN) {
4401 /*
4402 * we need to check the current set-up direction of
4403 * shared input pins since they can be switched via
4404 * "xxx as Output" mixer switch
4405 */
4406 struct sigmatel_spec *spec = codec->spec;
4407 if (nid == spec->line_switch || nid == spec->mic_switch)
4408 return;
4409 }
4410
4411 old_ctl = pin_ctl;
4412 /* if setting pin direction bits, clear the current
4413 direction bits first */
4414 if (flag & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))
4415 pin_ctl &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
4416
4417 pin_ctl |= flag;
4418 if (old_ctl != pin_ctl)
4419 snd_hda_codec_write_cache(codec, nid, 0,
4420 AC_VERB_SET_PIN_WIDGET_CONTROL,
4421 pin_ctl);
4422 }
4423
4424 static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
4425 unsigned int flag)
4426 {
4427 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
4428 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
4429 if (pin_ctl & flag)
4430 snd_hda_codec_write_cache(codec, nid, 0,
4431 AC_VERB_SET_PIN_WIDGET_CONTROL,
4432 pin_ctl & ~flag);
4433 }
4434
4435 static int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
4436 {
4437 if (!nid)
4438 return 0;
4439 if (snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PIN_SENSE, 0x00)
4440 & (1 << 31))
4441 return 1;
4442 return 0;
4443 }
4444
4445 /* return non-zero if the hp-pin of the given array index isn't
4446 * a jack-detection target
4447 */
4448 static int no_hp_sensing(struct sigmatel_spec *spec, int i)
4449 {
4450 struct auto_pin_cfg *cfg = &spec->autocfg;
4451
4452 /* ignore sensing of shared line and mic jacks */
4453 if (cfg->hp_pins[i] == spec->line_switch)
4454 return 1;
4455 if (cfg->hp_pins[i] == spec->mic_switch)
4456 return 1;
4457 /* ignore if the pin is set as line-out */
4458 if (cfg->hp_pins[i] == spec->hp_switch)
4459 return 1;
4460 return 0;
4461 }
4462
4463 static void stac92xx_hp_detect(struct hda_codec *codec)
4464 {
4465 struct sigmatel_spec *spec = codec->spec;
4466 struct auto_pin_cfg *cfg = &spec->autocfg;
4467 int i, presence;
4468
4469 presence = 0;
4470 if (spec->gpio_mute)
4471 presence = !(snd_hda_codec_read(codec, codec->afg, 0,
4472 AC_VERB_GET_GPIO_DATA, 0) & spec->gpio_mute);
4473
4474 for (i = 0; i < cfg->hp_outs; i++) {
4475 if (presence)
4476 break;
4477 if (no_hp_sensing(spec, i))
4478 continue;
4479 presence = get_pin_presence(codec, cfg->hp_pins[i]);
4480 if (presence) {
4481 unsigned int pinctl;
4482 pinctl = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
4483 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4484 if (pinctl & AC_PINCTL_IN_EN)
4485 presence = 0; /* mic- or line-input */
4486 }
4487 }
4488
4489 if (presence) {
4490 /* disable lineouts */
4491 if (spec->hp_switch)
4492 stac92xx_reset_pinctl(codec, spec->hp_switch,
4493 AC_PINCTL_OUT_EN);
4494 for (i = 0; i < cfg->line_outs; i++)
4495 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
4496 AC_PINCTL_OUT_EN);
4497 for (i = 0; i < cfg->speaker_outs; i++)
4498 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
4499 AC_PINCTL_OUT_EN);
4500 if (spec->eapd_mask && spec->eapd_switch)
4501 stac_gpio_set(codec, spec->gpio_mask,
4502 spec->gpio_dir, spec->gpio_data &
4503 ~spec->eapd_mask);
4504 } else {
4505 /* enable lineouts */
4506 if (spec->hp_switch)
4507 stac92xx_set_pinctl(codec, spec->hp_switch,
4508 AC_PINCTL_OUT_EN);
4509 for (i = 0; i < cfg->line_outs; i++)
4510 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
4511 AC_PINCTL_OUT_EN);
4512 for (i = 0; i < cfg->speaker_outs; i++)
4513 stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
4514 AC_PINCTL_OUT_EN);
4515 if (spec->eapd_mask && spec->eapd_switch)
4516 stac_gpio_set(codec, spec->gpio_mask,
4517 spec->gpio_dir, spec->gpio_data |
4518 spec->eapd_mask);
4519 }
4520 /* toggle hp outs */
4521 for (i = 0; i < cfg->hp_outs; i++) {
4522 unsigned int val = AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN;
4523 if (no_hp_sensing(spec, i))
4524 continue;
4525 if (presence)
4526 stac92xx_set_pinctl(codec, cfg->hp_pins[i], val);
4527 #if 0 /* FIXME */
4528 /* Resetting the pinctl like below may lead to (a sort of) regressions
4529 * on some devices since they use the HP pin actually for line/speaker
4530 * outs although the default pin config shows a different pin (that is
4531 * wrong and useless).
4532 *
4533 * So, it's basically a problem of default pin configs, likely a BIOS issue.
4534 * But, disabling the code below just works around it, and I'm too tired of
4535 * bug reports with such devices...
4536 */
4537 else
4538 stac92xx_reset_pinctl(codec, cfg->hp_pins[i], val);
4539 #endif /* FIXME */
4540 }
4541 }
4542
4543 static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
4544 int enable)
4545 {
4546 struct sigmatel_spec *spec = codec->spec;
4547 unsigned int idx, val;
4548
4549 for (idx = 0; idx < spec->num_pwrs; idx++) {
4550 if (spec->pwr_nids[idx] == nid)
4551 break;
4552 }
4553 if (idx >= spec->num_pwrs)
4554 return;
4555
4556 /* several codecs have two power down bits */
4557 if (spec->pwr_mapping)
4558 idx = spec->pwr_mapping[idx];
4559 else
4560 idx = 1 << idx;
4561
4562 val = snd_hda_codec_read(codec, codec->afg, 0, 0x0fec, 0x0) & 0xff;
4563 if (enable)
4564 val &= ~idx;
4565 else
4566 val |= idx;
4567
4568 /* power down unused output ports */
4569 snd_hda_codec_write(codec, codec->afg, 0, 0x7ec, val);
4570 }
4571
4572 static void stac92xx_pin_sense(struct hda_codec *codec, hda_nid_t nid)
4573 {
4574 stac_toggle_power_map(codec, nid, get_pin_presence(codec, nid));
4575 }
4576
4577 static void stac92xx_report_jack(struct hda_codec *codec, hda_nid_t nid)
4578 {
4579 struct sigmatel_spec *spec = codec->spec;
4580 struct sigmatel_jack *jacks = spec->jacks.list;
4581
4582 if (jacks) {
4583 int i;
4584 for (i = 0; i < spec->jacks.used; i++) {
4585 if (jacks->nid == nid) {
4586 unsigned int pin_ctl =
4587 snd_hda_codec_read(codec, nid,
4588 0, AC_VERB_GET_PIN_WIDGET_CONTROL,
4589 0x00);
4590 int type = jacks->type;
4591 if (type == (SND_JACK_LINEOUT
4592 | SND_JACK_HEADPHONE))
4593 type = (pin_ctl & AC_PINCTL_HP_EN)
4594 ? SND_JACK_HEADPHONE : SND_JACK_LINEOUT;
4595 snd_jack_report(jacks->jack,
4596 get_pin_presence(codec, nid)
4597 ? type : 0);
4598 }
4599 jacks++;
4600 }
4601 }
4602 }
4603
4604 static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid,
4605 unsigned char type)
4606 {
4607 struct sigmatel_event *event = stac_get_event(codec, nid, type);
4608 if (!event)
4609 return;
4610 codec->patch_ops.unsol_event(codec, (unsigned)event->tag << 26);
4611 }
4612
4613 static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
4614 {
4615 struct sigmatel_spec *spec = codec->spec;
4616 struct sigmatel_event *event;
4617 int tag, data;
4618
4619 tag = (res >> 26) & 0x7f;
4620 event = stac_get_event_from_tag(codec, tag);
4621 if (!event)
4622 return;
4623
4624 switch (event->type) {
4625 case STAC_HP_EVENT:
4626 stac92xx_hp_detect(codec);
4627 /* fallthru */
4628 case STAC_INSERT_EVENT:
4629 case STAC_PWR_EVENT:
4630 if (spec->num_pwrs > 0)
4631 stac92xx_pin_sense(codec, event->nid);
4632 stac92xx_report_jack(codec, event->nid);
4633
4634 switch (codec->subsystem_id) {
4635 case 0x103c308f:
4636 if (event->nid == 0xb) {
4637 int pin = AC_PINCTL_IN_EN;
4638
4639 if (get_pin_presence(codec, 0xa)
4640 && get_pin_presence(codec, 0xb))
4641 pin |= AC_PINCTL_VREF_80;
4642 if (!get_pin_presence(codec, 0xb))
4643 pin |= AC_PINCTL_VREF_80;
4644
4645 /* toggle VREF state based on mic + hp pin
4646 * status
4647 */
4648 stac92xx_auto_set_pinctl(codec, 0x0a, pin);
4649 }
4650 }
4651 break;
4652 case STAC_VREF_EVENT:
4653 data = snd_hda_codec_read(codec, codec->afg, 0,
4654 AC_VERB_GET_GPIO_DATA, 0);
4655 /* toggle VREF state based on GPIOx status */
4656 snd_hda_codec_write(codec, codec->afg, 0, 0x7e0,
4657 !!(data & (1 << event->data)));
4658 break;
4659 }
4660 }
4661
4662 #ifdef CONFIG_PROC_FS
4663 static void stac92hd_proc_hook(struct snd_info_buffer *buffer,
4664 struct hda_codec *codec, hda_nid_t nid)
4665 {
4666 if (nid == codec->afg)
4667 snd_iprintf(buffer, "Power-Map: 0x%02x\n",
4668 snd_hda_codec_read(codec, nid, 0, 0x0fec, 0x0));
4669 }
4670
4671 static void analog_loop_proc_hook(struct snd_info_buffer *buffer,
4672 struct hda_codec *codec,
4673 unsigned int verb)
4674 {
4675 snd_iprintf(buffer, "Analog Loopback: 0x%02x\n",
4676 snd_hda_codec_read(codec, codec->afg, 0, verb, 0));
4677 }
4678
4679 /* stac92hd71bxx, stac92hd73xx */
4680 static void stac92hd7x_proc_hook(struct snd_info_buffer *buffer,
4681 struct hda_codec *codec, hda_nid_t nid)
4682 {
4683 stac92hd_proc_hook(buffer, codec, nid);
4684 if (nid == codec->afg)
4685 analog_loop_proc_hook(buffer, codec, 0xfa0);
4686 }
4687
4688 static void stac9205_proc_hook(struct snd_info_buffer *buffer,
4689 struct hda_codec *codec, hda_nid_t nid)
4690 {
4691 if (nid == codec->afg)
4692 analog_loop_proc_hook(buffer, codec, 0xfe0);
4693 }
4694
4695 static void stac927x_proc_hook(struct snd_info_buffer *buffer,
4696 struct hda_codec *codec, hda_nid_t nid)
4697 {
4698 if (nid == codec->afg)
4699 analog_loop_proc_hook(buffer, codec, 0xfeb);
4700 }
4701 #else
4702 #define stac92hd_proc_hook NULL
4703 #define stac92hd7x_proc_hook NULL
4704 #define stac9205_proc_hook NULL
4705 #define stac927x_proc_hook NULL
4706 #endif
4707
4708 #ifdef SND_HDA_NEEDS_RESUME
4709 static int stac92xx_resume(struct hda_codec *codec)
4710 {
4711 struct sigmatel_spec *spec = codec->spec;
4712
4713 stac92xx_init(codec);
4714 snd_hda_codec_resume_amp(codec);
4715 snd_hda_codec_resume_cache(codec);
4716 /* fake event to set up pins again to override cached values */
4717 if (spec->hp_detect)
4718 stac_issue_unsol_event(codec, spec->autocfg.hp_pins[0],
4719 STAC_HP_EVENT);
4720 return 0;
4721 }
4722
4723 /*
4724 * using power check for controlling mute led of HP notebooks
4725 * check for mute state only on Speakers (nid = 0x10)
4726 *
4727 * For this feature CONFIG_SND_HDA_POWER_SAVE is needed, otherwise
4728 * the LED is NOT working properly !
4729 *
4730 * Changed name to reflect that it now works for any designated
4731 * model, not just HP HDX.
4732 */
4733
4734 #ifdef CONFIG_SND_HDA_POWER_SAVE
4735 static int stac92xx_hp_check_power_status(struct hda_codec *codec,
4736 hda_nid_t nid)
4737 {
4738 struct sigmatel_spec *spec = codec->spec;
4739
4740 if (nid == 0x10) {
4741 if (snd_hda_codec_amp_read(codec, nid, 0, HDA_OUTPUT, 0) &
4742 HDA_AMP_MUTE)
4743 spec->gpio_data &= ~spec->gpio_led; /* orange */
4744 else
4745 spec->gpio_data |= spec->gpio_led; /* white */
4746
4747 stac_gpio_set(codec, spec->gpio_mask,
4748 spec->gpio_dir,
4749 spec->gpio_data);
4750 }
4751
4752 return 0;
4753 }
4754 #endif
4755
4756 static int stac92xx_suspend(struct hda_codec *codec, pm_message_t state)
4757 {
4758 struct sigmatel_spec *spec = codec->spec;
4759 if (spec->eapd_mask)
4760 stac_gpio_set(codec, spec->gpio_mask,
4761 spec->gpio_dir, spec->gpio_data &
4762 ~spec->eapd_mask);
4763 return 0;
4764 }
4765 #endif
4766
4767 static struct hda_codec_ops stac92xx_patch_ops = {
4768 .build_controls = stac92xx_build_controls,
4769 .build_pcms = stac92xx_build_pcms,
4770 .init = stac92xx_init,
4771 .free = stac92xx_free,
4772 .unsol_event = stac92xx_unsol_event,
4773 #ifdef SND_HDA_NEEDS_RESUME
4774 .suspend = stac92xx_suspend,
4775 .resume = stac92xx_resume,
4776 #endif
4777 };
4778
4779 static int patch_stac9200(struct hda_codec *codec)
4780 {
4781 struct sigmatel_spec *spec;
4782 int err;
4783
4784 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4785 if (spec == NULL)
4786 return -ENOMEM;
4787
4788 codec->spec = spec;
4789 spec->num_pins = ARRAY_SIZE(stac9200_pin_nids);
4790 spec->pin_nids = stac9200_pin_nids;
4791 spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS,
4792 stac9200_models,
4793 stac9200_cfg_tbl);
4794 if (spec->board_config < 0)
4795 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9200, using BIOS defaults\n");
4796 else
4797 stac92xx_set_config_regs(codec,
4798 stac9200_brd_tbl[spec->board_config]);
4799
4800 spec->multiout.max_channels = 2;
4801 spec->multiout.num_dacs = 1;
4802 spec->multiout.dac_nids = stac9200_dac_nids;
4803 spec->adc_nids = stac9200_adc_nids;
4804 spec->mux_nids = stac9200_mux_nids;
4805 spec->num_muxes = 1;
4806 spec->num_dmics = 0;
4807 spec->num_adcs = 1;
4808 spec->num_pwrs = 0;
4809
4810 if (spec->board_config == STAC_9200_M4 ||
4811 spec->board_config == STAC_9200_M4_2 ||
4812 spec->board_config == STAC_9200_OQO)
4813 spec->init = stac9200_eapd_init;
4814 else
4815 spec->init = stac9200_core_init;
4816 spec->mixer = stac9200_mixer;
4817
4818 if (spec->board_config == STAC_9200_PANASONIC) {
4819 spec->gpio_mask = spec->gpio_dir = 0x09;
4820 spec->gpio_data = 0x00;
4821 }
4822
4823 err = stac9200_parse_auto_config(codec);
4824 if (err < 0) {
4825 stac92xx_free(codec);
4826 return err;
4827 }
4828
4829 /* CF-74 has no headphone detection, and the driver should *NOT*
4830 * do detection and HP/speaker toggle because the hardware does it.
4831 */
4832 if (spec->board_config == STAC_9200_PANASONIC)
4833 spec->hp_detect = 0;
4834
4835 codec->patch_ops = stac92xx_patch_ops;
4836
4837 return 0;
4838 }
4839
4840 static int patch_stac925x(struct hda_codec *codec)
4841 {
4842 struct sigmatel_spec *spec;
4843 int err;
4844
4845 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4846 if (spec == NULL)
4847 return -ENOMEM;
4848
4849 codec->spec = spec;
4850 spec->num_pins = ARRAY_SIZE(stac925x_pin_nids);
4851 spec->pin_nids = stac925x_pin_nids;
4852
4853 /* Check first for codec ID */
4854 spec->board_config = snd_hda_check_board_codec_sid_config(codec,
4855 STAC_925x_MODELS,
4856 stac925x_models,
4857 stac925x_codec_id_cfg_tbl);
4858
4859 /* Now checks for PCI ID, if codec ID is not found */
4860 if (spec->board_config < 0)
4861 spec->board_config = snd_hda_check_board_config(codec,
4862 STAC_925x_MODELS,
4863 stac925x_models,
4864 stac925x_cfg_tbl);
4865 again:
4866 if (spec->board_config < 0)
4867 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC925x,"
4868 "using BIOS defaults\n");
4869 else
4870 stac92xx_set_config_regs(codec,
4871 stac925x_brd_tbl[spec->board_config]);
4872
4873 spec->multiout.max_channels = 2;
4874 spec->multiout.num_dacs = 1;
4875 spec->multiout.dac_nids = stac925x_dac_nids;
4876 spec->adc_nids = stac925x_adc_nids;
4877 spec->mux_nids = stac925x_mux_nids;
4878 spec->num_muxes = 1;
4879 spec->num_adcs = 1;
4880 spec->num_pwrs = 0;
4881 switch (codec->vendor_id) {
4882 case 0x83847632: /* STAC9202 */
4883 case 0x83847633: /* STAC9202D */
4884 case 0x83847636: /* STAC9251 */
4885 case 0x83847637: /* STAC9251D */
4886 spec->num_dmics = STAC925X_NUM_DMICS;
4887 spec->dmic_nids = stac925x_dmic_nids;
4888 spec->num_dmuxes = ARRAY_SIZE(stac925x_dmux_nids);
4889 spec->dmux_nids = stac925x_dmux_nids;
4890 break;
4891 default:
4892 spec->num_dmics = 0;
4893 break;
4894 }
4895
4896 spec->init = stac925x_core_init;
4897 spec->mixer = stac925x_mixer;
4898
4899 err = stac92xx_parse_auto_config(codec, 0x8, 0x7);
4900 if (!err) {
4901 if (spec->board_config < 0) {
4902 printk(KERN_WARNING "hda_codec: No auto-config is "
4903 "available, default to model=ref\n");
4904 spec->board_config = STAC_925x_REF;
4905 goto again;
4906 }
4907 err = -EINVAL;
4908 }
4909 if (err < 0) {
4910 stac92xx_free(codec);
4911 return err;
4912 }
4913
4914 codec->patch_ops = stac92xx_patch_ops;
4915
4916 return 0;
4917 }
4918
4919 static struct hda_input_mux stac92hd73xx_dmux = {
4920 .num_items = 4,
4921 .items = {
4922 { "Analog Inputs", 0x0b },
4923 { "Digital Mic 1", 0x09 },
4924 { "Digital Mic 2", 0x0a },
4925 { "CD", 0x08 },
4926 }
4927 };
4928
4929 static int patch_stac92hd73xx(struct hda_codec *codec)
4930 {
4931 struct sigmatel_spec *spec;
4932 hda_nid_t conn[STAC92HD73_DAC_COUNT + 2];
4933 int err = 0;
4934 int num_dacs;
4935
4936 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4937 if (spec == NULL)
4938 return -ENOMEM;
4939
4940 codec->spec = spec;
4941 codec->slave_dig_outs = stac92hd73xx_slave_dig_outs;
4942 spec->num_pins = ARRAY_SIZE(stac92hd73xx_pin_nids);
4943 spec->pin_nids = stac92hd73xx_pin_nids;
4944 spec->board_config = snd_hda_check_board_config(codec,
4945 STAC_92HD73XX_MODELS,
4946 stac92hd73xx_models,
4947 stac92hd73xx_cfg_tbl);
4948 again:
4949 if (spec->board_config < 0)
4950 snd_printdd(KERN_INFO "hda_codec: Unknown model for"
4951 " STAC92HD73XX, using BIOS defaults\n");
4952 else
4953 stac92xx_set_config_regs(codec,
4954 stac92hd73xx_brd_tbl[spec->board_config]);
4955
4956 num_dacs = snd_hda_get_connections(codec, 0x0a,
4957 conn, STAC92HD73_DAC_COUNT + 2) - 1;
4958
4959 if (num_dacs < 3 || num_dacs > 5) {
4960 printk(KERN_WARNING "hda_codec: Could not determine "
4961 "number of channels defaulting to DAC count\n");
4962 num_dacs = STAC92HD73_DAC_COUNT;
4963 }
4964 switch (num_dacs) {
4965 case 0x3: /* 6 Channel */
4966 spec->mixer = stac92hd73xx_6ch_mixer;
4967 spec->init = stac92hd73xx_6ch_core_init;
4968 spec->aloopback_ctl = stac92hd73xx_6ch_loopback;
4969 break;
4970 case 0x4: /* 8 Channel */
4971 spec->mixer = stac92hd73xx_8ch_mixer;
4972 spec->init = stac92hd73xx_8ch_core_init;
4973 spec->aloopback_ctl = stac92hd73xx_8ch_loopback;
4974 break;
4975 case 0x5: /* 10 Channel */
4976 spec->mixer = stac92hd73xx_10ch_mixer;
4977 spec->init = stac92hd73xx_10ch_core_init;
4978 spec->aloopback_ctl = stac92hd73xx_10ch_loopback;
4979 break;
4980 }
4981 spec->multiout.dac_nids = spec->dac_nids;
4982
4983 spec->aloopback_mask = 0x01;
4984 spec->aloopback_shift = 8;
4985
4986 spec->digbeep_nid = 0x1c;
4987 spec->mux_nids = stac92hd73xx_mux_nids;
4988 spec->adc_nids = stac92hd73xx_adc_nids;
4989 spec->dmic_nids = stac92hd73xx_dmic_nids;
4990 spec->dmux_nids = stac92hd73xx_dmux_nids;
4991 spec->smux_nids = stac92hd73xx_smux_nids;
4992 spec->amp_nids = stac92hd73xx_amp_nids;
4993 spec->num_amps = ARRAY_SIZE(stac92hd73xx_amp_nids);
4994
4995 spec->num_muxes = ARRAY_SIZE(stac92hd73xx_mux_nids);
4996 spec->num_adcs = ARRAY_SIZE(stac92hd73xx_adc_nids);
4997 spec->num_dmuxes = ARRAY_SIZE(stac92hd73xx_dmux_nids);
4998 memcpy(&spec->private_dimux, &stac92hd73xx_dmux,
4999 sizeof(stac92hd73xx_dmux));
5000
5001 switch (spec->board_config) {
5002 case STAC_DELL_EQ:
5003 spec->init = dell_eq_core_init;
5004 /* fallthru */
5005 case STAC_DELL_M6_AMIC:
5006 case STAC_DELL_M6_DMIC:
5007 case STAC_DELL_M6_BOTH:
5008 spec->num_smuxes = 0;
5009 spec->mixer = &stac92hd73xx_6ch_mixer[DELL_M6_MIXER];
5010 spec->amp_nids = &stac92hd73xx_amp_nids[DELL_M6_AMP];
5011 spec->eapd_switch = 0;
5012 spec->num_amps = 1;
5013
5014 if (spec->board_config != STAC_DELL_EQ)
5015 spec->init = dell_m6_core_init;
5016 switch (spec->board_config) {
5017 case STAC_DELL_M6_AMIC: /* Analog Mics */
5018 snd_hda_codec_set_pincfg(codec, 0x0b, 0x90A70170);
5019 spec->num_dmics = 0;
5020 spec->private_dimux.num_items = 1;
5021 break;
5022 case STAC_DELL_M6_DMIC: /* Digital Mics */
5023 snd_hda_codec_set_pincfg(codec, 0x13, 0x90A60160);
5024 spec->num_dmics = 1;
5025 spec->private_dimux.num_items = 2;
5026 break;
5027 case STAC_DELL_M6_BOTH: /* Both */
5028 snd_hda_codec_set_pincfg(codec, 0x0b, 0x90A70170);
5029 snd_hda_codec_set_pincfg(codec, 0x13, 0x90A60160);
5030 spec->num_dmics = 1;
5031 spec->private_dimux.num_items = 2;
5032 break;
5033 }
5034 break;
5035 default:
5036 spec->num_dmics = STAC92HD73XX_NUM_DMICS;
5037 spec->num_smuxes = ARRAY_SIZE(stac92hd73xx_smux_nids);
5038 spec->eapd_switch = 1;
5039 }
5040 if (spec->board_config > STAC_92HD73XX_REF) {
5041 /* GPIO0 High = Enable EAPD */
5042 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
5043 spec->gpio_data = 0x01;
5044 }
5045 spec->dinput_mux = &spec->private_dimux;
5046
5047 spec->num_pwrs = ARRAY_SIZE(stac92hd73xx_pwr_nids);
5048 spec->pwr_nids = stac92hd73xx_pwr_nids;
5049
5050 err = stac92xx_parse_auto_config(codec, 0x25, 0x27);
5051
5052 if (!err) {
5053 if (spec->board_config < 0) {
5054 printk(KERN_WARNING "hda_codec: No auto-config is "
5055 "available, default to model=ref\n");
5056 spec->board_config = STAC_92HD73XX_REF;
5057 goto again;
5058 }
5059 err = -EINVAL;
5060 }
5061
5062 if (err < 0) {
5063 stac92xx_free(codec);
5064 return err;
5065 }
5066
5067 if (spec->board_config == STAC_92HD73XX_NO_JD)
5068 spec->hp_detect = 0;
5069
5070 codec->patch_ops = stac92xx_patch_ops;
5071
5072 codec->proc_widget_hook = stac92hd7x_proc_hook;
5073
5074 return 0;
5075 }
5076
5077 static struct hda_input_mux stac92hd83xxx_dmux = {
5078 .num_items = 3,
5079 .items = {
5080 { "Analog Inputs", 0x03 },
5081 { "Digital Mic 1", 0x04 },
5082 { "Digital Mic 2", 0x05 },
5083 }
5084 };
5085
5086 static int patch_stac92hd83xxx(struct hda_codec *codec)
5087 {
5088 struct sigmatel_spec *spec;
5089 hda_nid_t conn[STAC92HD83_DAC_COUNT + 1];
5090 int err;
5091 int num_dacs;
5092 hda_nid_t nid;
5093
5094 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5095 if (spec == NULL)
5096 return -ENOMEM;
5097
5098 codec->spec = spec;
5099 codec->slave_dig_outs = stac92hd83xxx_slave_dig_outs;
5100 spec->mono_nid = 0x19;
5101 spec->digbeep_nid = 0x21;
5102 spec->dmic_nids = stac92hd83xxx_dmic_nids;
5103 spec->dmux_nids = stac92hd83xxx_dmux_nids;
5104 spec->adc_nids = stac92hd83xxx_adc_nids;
5105 spec->pwr_nids = stac92hd83xxx_pwr_nids;
5106 spec->amp_nids = stac92hd83xxx_amp_nids;
5107 spec->pwr_mapping = stac92hd83xxx_pwr_mapping;
5108 spec->num_pwrs = ARRAY_SIZE(stac92hd83xxx_pwr_nids);
5109 spec->multiout.dac_nids = spec->dac_nids;
5110
5111 spec->init = stac92hd83xxx_core_init;
5112 spec->mixer = stac92hd83xxx_mixer;
5113 spec->num_pins = ARRAY_SIZE(stac92hd83xxx_pin_nids);
5114 spec->num_dmuxes = ARRAY_SIZE(stac92hd83xxx_dmux_nids);
5115 spec->num_adcs = ARRAY_SIZE(stac92hd83xxx_adc_nids);
5116 spec->num_amps = ARRAY_SIZE(stac92hd83xxx_amp_nids);
5117 spec->num_dmics = STAC92HD83XXX_NUM_DMICS;
5118 spec->dinput_mux = &stac92hd83xxx_dmux;
5119 spec->pin_nids = stac92hd83xxx_pin_nids;
5120 spec->board_config = snd_hda_check_board_config(codec,
5121 STAC_92HD83XXX_MODELS,
5122 stac92hd83xxx_models,
5123 stac92hd83xxx_cfg_tbl);
5124 again:
5125 if (spec->board_config < 0)
5126 snd_printdd(KERN_INFO "hda_codec: Unknown model for"
5127 " STAC92HD83XXX, using BIOS defaults\n");
5128 else
5129 stac92xx_set_config_regs(codec,
5130 stac92hd83xxx_brd_tbl[spec->board_config]);
5131
5132 switch (codec->vendor_id) {
5133 case 0x111d7604:
5134 case 0x111d7605:
5135 case 0x111d76d5:
5136 if (spec->board_config == STAC_92HD83XXX_PWR_REF)
5137 break;
5138 spec->num_pwrs = 0;
5139 break;
5140 }
5141
5142 err = stac92xx_parse_auto_config(codec, 0x1d, 0);
5143 if (!err) {
5144 if (spec->board_config < 0) {
5145 printk(KERN_WARNING "hda_codec: No auto-config is "
5146 "available, default to model=ref\n");
5147 spec->board_config = STAC_92HD83XXX_REF;
5148 goto again;
5149 }
5150 err = -EINVAL;
5151 }
5152
5153 if (err < 0) {
5154 stac92xx_free(codec);
5155 return err;
5156 }
5157
5158 switch (spec->board_config) {
5159 case STAC_DELL_S14:
5160 nid = 0xf;
5161 break;
5162 default:
5163 nid = 0xe;
5164 break;
5165 }
5166
5167 num_dacs = snd_hda_get_connections(codec, nid,
5168 conn, STAC92HD83_DAC_COUNT + 1) - 1;
5169
5170 /* set port X to select the last DAC
5171 */
5172 snd_hda_codec_write_cache(codec, nid, 0,
5173 AC_VERB_SET_CONNECT_SEL, num_dacs);
5174
5175 codec->patch_ops = stac92xx_patch_ops;
5176
5177 codec->proc_widget_hook = stac92hd_proc_hook;
5178
5179 return 0;
5180 }
5181
5182 static struct hda_input_mux stac92hd71bxx_dmux_nomixer = {
5183 .num_items = 3,
5184 .items = {
5185 { "Analog Inputs", 0x00 },
5186 { "Digital Mic 1", 0x02 },
5187 { "Digital Mic 2", 0x03 },
5188 }
5189 };
5190
5191 static struct hda_input_mux stac92hd71bxx_dmux_amixer = {
5192 .num_items = 4,
5193 .items = {
5194 { "Analog Inputs", 0x00 },
5195 { "Mixer", 0x01 },
5196 { "Digital Mic 1", 0x02 },
5197 { "Digital Mic 2", 0x03 },
5198 }
5199 };
5200
5201 /* get the pin connection (fixed, none, etc) */
5202 static unsigned int stac_get_defcfg_connect(struct hda_codec *codec, int idx)
5203 {
5204 struct sigmatel_spec *spec = codec->spec;
5205 unsigned int cfg;
5206
5207 cfg = snd_hda_codec_get_pincfg(codec, spec->pin_nids[idx]);
5208 return get_defcfg_connect(cfg);
5209 }
5210
5211 static int stac92hd71bxx_connected_ports(struct hda_codec *codec,
5212 hda_nid_t *nids, int num_nids)
5213 {
5214 struct sigmatel_spec *spec = codec->spec;
5215 int idx, num;
5216 unsigned int def_conf;
5217
5218 for (num = 0; num < num_nids; num++) {
5219 for (idx = 0; idx < spec->num_pins; idx++)
5220 if (spec->pin_nids[idx] == nids[num])
5221 break;
5222 if (idx >= spec->num_pins)
5223 break;
5224 def_conf = stac_get_defcfg_connect(codec, idx);
5225 if (def_conf == AC_JACK_PORT_NONE)
5226 break;
5227 }
5228 return num;
5229 }
5230
5231 static int stac92hd71bxx_connected_smuxes(struct hda_codec *codec,
5232 hda_nid_t dig0pin)
5233 {
5234 struct sigmatel_spec *spec = codec->spec;
5235 int idx;
5236
5237 for (idx = 0; idx < spec->num_pins; idx++)
5238 if (spec->pin_nids[idx] == dig0pin)
5239 break;
5240 if ((idx + 2) >= spec->num_pins)
5241 return 0;
5242
5243 /* dig1pin case */
5244 if (stac_get_defcfg_connect(codec, idx + 1) != AC_JACK_PORT_NONE)
5245 return 2;
5246
5247 /* dig0pin + dig2pin case */
5248 if (stac_get_defcfg_connect(codec, idx + 2) != AC_JACK_PORT_NONE)
5249 return 2;
5250 if (stac_get_defcfg_connect(codec, idx) != AC_JACK_PORT_NONE)
5251 return 1;
5252 else
5253 return 0;
5254 }
5255
5256 static int patch_stac92hd71bxx(struct hda_codec *codec)
5257 {
5258 struct sigmatel_spec *spec;
5259 struct hda_verb *unmute_init = stac92hd71bxx_unmute_core_init;
5260 int err = 0;
5261 unsigned int ndmic_nids = 0;
5262
5263 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5264 if (spec == NULL)
5265 return -ENOMEM;
5266
5267 codec->spec = spec;
5268 codec->patch_ops = stac92xx_patch_ops;
5269 spec->num_pins = STAC92HD71BXX_NUM_PINS;
5270 switch (codec->vendor_id) {
5271 case 0x111d76b6:
5272 case 0x111d76b7:
5273 spec->pin_nids = stac92hd71bxx_pin_nids_4port;
5274 break;
5275 case 0x111d7603:
5276 case 0x111d7608:
5277 /* On 92HD75Bx 0x27 isn't a pin nid */
5278 spec->num_pins--;
5279 /* fallthrough */
5280 default:
5281 spec->pin_nids = stac92hd71bxx_pin_nids_6port;
5282 }
5283 spec->num_pwrs = ARRAY_SIZE(stac92hd71bxx_pwr_nids);
5284 spec->board_config = snd_hda_check_board_config(codec,
5285 STAC_92HD71BXX_MODELS,
5286 stac92hd71bxx_models,
5287 stac92hd71bxx_cfg_tbl);
5288 again:
5289 if (spec->board_config < 0)
5290 snd_printdd(KERN_INFO "hda_codec: Unknown model for"
5291 " STAC92HD71BXX, using BIOS defaults\n");
5292 else
5293 stac92xx_set_config_regs(codec,
5294 stac92hd71bxx_brd_tbl[spec->board_config]);
5295
5296 if (spec->board_config > STAC_92HD71BXX_REF) {
5297 /* GPIO0 = EAPD */
5298 spec->gpio_mask = 0x01;
5299 spec->gpio_dir = 0x01;
5300 spec->gpio_data = 0x01;
5301 }
5302
5303 spec->dmic_nids = stac92hd71bxx_dmic_nids;
5304 spec->dmux_nids = stac92hd71bxx_dmux_nids;
5305
5306 switch (codec->vendor_id) {
5307 case 0x111d76b6: /* 4 Port without Analog Mixer */
5308 case 0x111d76b7:
5309 unmute_init++;
5310 /* fallthru */
5311 case 0x111d76b4: /* 6 Port without Analog Mixer */
5312 case 0x111d76b5:
5313 memcpy(&spec->private_dimux, &stac92hd71bxx_dmux_nomixer,
5314 sizeof(stac92hd71bxx_dmux_nomixer));
5315 spec->mixer = stac92hd71bxx_mixer;
5316 spec->init = stac92hd71bxx_core_init;
5317 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
5318 spec->num_dmics = stac92hd71bxx_connected_ports(codec,
5319 stac92hd71bxx_dmic_nids,
5320 STAC92HD71BXX_NUM_DMICS);
5321 if (spec->num_dmics) {
5322 spec->num_dmuxes = ARRAY_SIZE(stac92hd71bxx_dmux_nids);
5323 spec->dinput_mux = &spec->private_dimux;
5324 ndmic_nids = ARRAY_SIZE(stac92hd71bxx_dmic_nids) - 1;
5325 }
5326 break;
5327 case 0x111d7608: /* 5 Port with Analog Mixer */
5328 memcpy(&spec->private_dimux, &stac92hd71bxx_dmux_amixer,
5329 sizeof(stac92hd71bxx_dmux_amixer));
5330 spec->private_dimux.num_items--;
5331 switch (spec->board_config) {
5332 case STAC_HP_M4:
5333 /* Enable VREF power saving on GPIO1 detect */
5334 err = stac_add_event(spec, codec->afg,
5335 STAC_VREF_EVENT, 0x02);
5336 if (err < 0)
5337 return err;
5338 snd_hda_codec_write_cache(codec, codec->afg, 0,
5339 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x02);
5340 snd_hda_codec_write_cache(codec, codec->afg, 0,
5341 AC_VERB_SET_UNSOLICITED_ENABLE,
5342 AC_USRSP_EN | err);
5343 spec->gpio_mask |= 0x02;
5344 break;
5345 }
5346 if ((codec->revision_id & 0xf) == 0 ||
5347 (codec->revision_id & 0xf) == 1)
5348 spec->stream_delay = 40; /* 40 milliseconds */
5349
5350 /* no output amps */
5351 spec->num_pwrs = 0;
5352 spec->mixer = stac92hd71bxx_analog_mixer;
5353 spec->dinput_mux = &spec->private_dimux;
5354
5355 /* disable VSW */
5356 spec->init = &stac92hd71bxx_analog_core_init[HD_DISABLE_PORTF];
5357 unmute_init++;
5358 snd_hda_codec_set_pincfg(codec, 0x0f, 0x40f000f0);
5359 snd_hda_codec_set_pincfg(codec, 0x19, 0x40f000f3);
5360 stac92hd71bxx_dmic_nids[STAC92HD71BXX_NUM_DMICS - 1] = 0;
5361 spec->num_dmics = stac92hd71bxx_connected_ports(codec,
5362 stac92hd71bxx_dmic_nids,
5363 STAC92HD71BXX_NUM_DMICS - 1);
5364 spec->num_dmuxes = ARRAY_SIZE(stac92hd71bxx_dmux_nids);
5365 ndmic_nids = ARRAY_SIZE(stac92hd71bxx_dmic_nids) - 2;
5366 break;
5367 case 0x111d7603: /* 6 Port with Analog Mixer */
5368 if ((codec->revision_id & 0xf) == 1)
5369 spec->stream_delay = 40; /* 40 milliseconds */
5370
5371 /* no output amps */
5372 spec->num_pwrs = 0;
5373 /* fallthru */
5374 default:
5375 memcpy(&spec->private_dimux, &stac92hd71bxx_dmux_amixer,
5376 sizeof(stac92hd71bxx_dmux_amixer));
5377 spec->dinput_mux = &spec->private_dimux;
5378 spec->mixer = stac92hd71bxx_analog_mixer;
5379 spec->init = stac92hd71bxx_analog_core_init;
5380 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
5381 spec->num_dmics = stac92hd71bxx_connected_ports(codec,
5382 stac92hd71bxx_dmic_nids,
5383 STAC92HD71BXX_NUM_DMICS);
5384 spec->num_dmuxes = ARRAY_SIZE(stac92hd71bxx_dmux_nids);
5385 ndmic_nids = ARRAY_SIZE(stac92hd71bxx_dmic_nids) - 1;
5386 }
5387
5388 if (get_wcaps(codec, 0xa) & AC_WCAP_IN_AMP)
5389 snd_hda_sequence_write_cache(codec, unmute_init);
5390
5391 /* Some HP machines seem to have unstable codec communications
5392 * especially with ATI fglrx driver. For recovering from the
5393 * CORB/RIRB stall, allow the BUS reset and keep always sync
5394 */
5395 if (spec->board_config == STAC_HP_DV5) {
5396 codec->bus->sync_write = 1;
5397 codec->bus->allow_bus_reset = 1;
5398 }
5399
5400 spec->aloopback_ctl = stac92hd71bxx_loopback;
5401 spec->aloopback_mask = 0x50;
5402 spec->aloopback_shift = 0;
5403
5404 spec->powerdown_adcs = 1;
5405 spec->digbeep_nid = 0x26;
5406 spec->mux_nids = stac92hd71bxx_mux_nids;
5407 spec->adc_nids = stac92hd71bxx_adc_nids;
5408 spec->smux_nids = stac92hd71bxx_smux_nids;
5409 spec->pwr_nids = stac92hd71bxx_pwr_nids;
5410
5411 spec->num_muxes = ARRAY_SIZE(stac92hd71bxx_mux_nids);
5412 spec->num_adcs = ARRAY_SIZE(stac92hd71bxx_adc_nids);
5413 spec->num_smuxes = stac92hd71bxx_connected_smuxes(codec, 0x1e);
5414
5415 switch (spec->board_config) {
5416 case STAC_HP_M4:
5417 /* enable internal microphone */
5418 snd_hda_codec_set_pincfg(codec, 0x0e, 0x01813040);
5419 stac92xx_auto_set_pinctl(codec, 0x0e,
5420 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80);
5421 /* fallthru */
5422 case STAC_DELL_M4_2:
5423 spec->num_dmics = 0;
5424 spec->num_smuxes = 0;
5425 spec->num_dmuxes = 0;
5426 break;
5427 case STAC_DELL_M4_1:
5428 case STAC_DELL_M4_3:
5429 spec->num_dmics = 1;
5430 spec->num_smuxes = 0;
5431 spec->num_dmuxes = 1;
5432 break;
5433 case STAC_HP_DV4_1222NR:
5434 spec->num_dmics = 1;
5435 /* I don't know if it needs 1 or 2 smuxes - will wait for
5436 * bug reports to fix if needed
5437 */
5438 spec->num_smuxes = 1;
5439 spec->num_dmuxes = 1;
5440 spec->gpio_led = 0x01;
5441 /* fallthrough */
5442 case STAC_HP_DV5:
5443 snd_hda_codec_set_pincfg(codec, 0x0d, 0x90170010);
5444 stac92xx_auto_set_pinctl(codec, 0x0d, AC_PINCTL_OUT_EN);
5445 break;
5446 case STAC_HP_HDX:
5447 spec->num_dmics = 1;
5448 spec->num_dmuxes = 1;
5449 spec->num_smuxes = 1;
5450 /* orange/white mute led on GPIO3, orange=0, white=1 */
5451 spec->gpio_led = 0x08;
5452 break;
5453 }
5454
5455 #ifdef CONFIG_SND_HDA_POWER_SAVE
5456 if (spec->gpio_led) {
5457 spec->gpio_mask |= spec->gpio_led;
5458 spec->gpio_dir |= spec->gpio_led;
5459 spec->gpio_data |= spec->gpio_led;
5460 /* register check_power_status callback. */
5461 codec->patch_ops.check_power_status =
5462 stac92xx_hp_check_power_status;
5463 }
5464 #endif
5465
5466 spec->multiout.dac_nids = spec->dac_nids;
5467 if (spec->dinput_mux)
5468 spec->private_dimux.num_items += spec->num_dmics - ndmic_nids;
5469
5470 err = stac92xx_parse_auto_config(codec, 0x21, 0);
5471 if (!err) {
5472 if (spec->board_config < 0) {
5473 printk(KERN_WARNING "hda_codec: No auto-config is "
5474 "available, default to model=ref\n");
5475 spec->board_config = STAC_92HD71BXX_REF;
5476 goto again;
5477 }
5478 err = -EINVAL;
5479 }
5480
5481 if (err < 0) {
5482 stac92xx_free(codec);
5483 return err;
5484 }
5485
5486 codec->proc_widget_hook = stac92hd7x_proc_hook;
5487
5488 return 0;
5489 }
5490
5491 static int patch_stac922x(struct hda_codec *codec)
5492 {
5493 struct sigmatel_spec *spec;
5494 int err;
5495
5496 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5497 if (spec == NULL)
5498 return -ENOMEM;
5499
5500 codec->spec = spec;
5501 spec->num_pins = ARRAY_SIZE(stac922x_pin_nids);
5502 spec->pin_nids = stac922x_pin_nids;
5503 spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS,
5504 stac922x_models,
5505 stac922x_cfg_tbl);
5506 if (spec->board_config == STAC_INTEL_MAC_AUTO) {
5507 spec->gpio_mask = spec->gpio_dir = 0x03;
5508 spec->gpio_data = 0x03;
5509 /* Intel Macs have all same PCI SSID, so we need to check
5510 * codec SSID to distinguish the exact models
5511 */
5512 printk(KERN_INFO "hda_codec: STAC922x, Apple subsys_id=%x\n", codec->subsystem_id);
5513 switch (codec->subsystem_id) {
5514
5515 case 0x106b0800:
5516 spec->board_config = STAC_INTEL_MAC_V1;
5517 break;
5518 case 0x106b0600:
5519 case 0x106b0700:
5520 spec->board_config = STAC_INTEL_MAC_V2;
5521 break;
5522 case 0x106b0e00:
5523 case 0x106b0f00:
5524 case 0x106b1600:
5525 case 0x106b1700:
5526 case 0x106b0200:
5527 case 0x106b1e00:
5528 spec->board_config = STAC_INTEL_MAC_V3;
5529 break;
5530 case 0x106b1a00:
5531 case 0x00000100:
5532 spec->board_config = STAC_INTEL_MAC_V4;
5533 break;
5534 case 0x106b0a00:
5535 case 0x106b2200:
5536 spec->board_config = STAC_INTEL_MAC_V5;
5537 break;
5538 default:
5539 spec->board_config = STAC_INTEL_MAC_V3;
5540 break;
5541 }
5542 }
5543
5544 again:
5545 if (spec->board_config < 0)
5546 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC922x, "
5547 "using BIOS defaults\n");
5548 else
5549 stac92xx_set_config_regs(codec,
5550 stac922x_brd_tbl[spec->board_config]);
5551
5552 spec->adc_nids = stac922x_adc_nids;
5553 spec->mux_nids = stac922x_mux_nids;
5554 spec->num_muxes = ARRAY_SIZE(stac922x_mux_nids);
5555 spec->num_adcs = ARRAY_SIZE(stac922x_adc_nids);
5556 spec->num_dmics = 0;
5557 spec->num_pwrs = 0;
5558
5559 spec->init = stac922x_core_init;
5560 spec->mixer = stac922x_mixer;
5561
5562 spec->multiout.dac_nids = spec->dac_nids;
5563
5564 err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
5565 if (!err) {
5566 if (spec->board_config < 0) {
5567 printk(KERN_WARNING "hda_codec: No auto-config is "
5568 "available, default to model=ref\n");
5569 spec->board_config = STAC_D945_REF;
5570 goto again;
5571 }
5572 err = -EINVAL;
5573 }
5574 if (err < 0) {
5575 stac92xx_free(codec);
5576 return err;
5577 }
5578
5579 codec->patch_ops = stac92xx_patch_ops;
5580
5581 /* Fix Mux capture level; max to 2 */
5582 snd_hda_override_amp_caps(codec, 0x12, HDA_OUTPUT,
5583 (0 << AC_AMPCAP_OFFSET_SHIFT) |
5584 (2 << AC_AMPCAP_NUM_STEPS_SHIFT) |
5585 (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5586 (0 << AC_AMPCAP_MUTE_SHIFT));
5587
5588 return 0;
5589 }
5590
5591 static int patch_stac927x(struct hda_codec *codec)
5592 {
5593 struct sigmatel_spec *spec;
5594 int err;
5595
5596 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5597 if (spec == NULL)
5598 return -ENOMEM;
5599
5600 codec->spec = spec;
5601 codec->slave_dig_outs = stac927x_slave_dig_outs;
5602 spec->num_pins = ARRAY_SIZE(stac927x_pin_nids);
5603 spec->pin_nids = stac927x_pin_nids;
5604 spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS,
5605 stac927x_models,
5606 stac927x_cfg_tbl);
5607 again:
5608 if (spec->board_config < 0)
5609 snd_printdd(KERN_INFO "hda_codec: Unknown model for"
5610 "STAC927x, using BIOS defaults\n");
5611 else
5612 stac92xx_set_config_regs(codec,
5613 stac927x_brd_tbl[spec->board_config]);
5614
5615 spec->digbeep_nid = 0x23;
5616 spec->adc_nids = stac927x_adc_nids;
5617 spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
5618 spec->mux_nids = stac927x_mux_nids;
5619 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
5620 spec->smux_nids = stac927x_smux_nids;
5621 spec->num_smuxes = ARRAY_SIZE(stac927x_smux_nids);
5622 spec->spdif_labels = stac927x_spdif_labels;
5623 spec->dac_list = stac927x_dac_nids;
5624 spec->multiout.dac_nids = spec->dac_nids;
5625
5626 switch (spec->board_config) {
5627 case STAC_D965_3ST:
5628 case STAC_D965_5ST:
5629 /* GPIO0 High = Enable EAPD */
5630 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x01;
5631 spec->gpio_data = 0x01;
5632 spec->num_dmics = 0;
5633
5634 spec->init = d965_core_init;
5635 spec->mixer = stac927x_mixer;
5636 break;
5637 case STAC_DELL_BIOS:
5638 switch (codec->subsystem_id) {
5639 case 0x10280209:
5640 case 0x1028022e:
5641 /* correct the device field to SPDIF out */
5642 snd_hda_codec_set_pincfg(codec, 0x21, 0x01442070);
5643 break;
5644 }
5645 /* configure the analog microphone on some laptops */
5646 snd_hda_codec_set_pincfg(codec, 0x0c, 0x90a79130);
5647 /* correct the front output jack as a hp out */
5648 snd_hda_codec_set_pincfg(codec, 0x0f, 0x0227011f);
5649 /* correct the front input jack as a mic */
5650 snd_hda_codec_set_pincfg(codec, 0x0e, 0x02a79130);
5651 /* fallthru */
5652 case STAC_DELL_3ST:
5653 /* GPIO2 High = Enable EAPD */
5654 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x04;
5655 spec->gpio_data = 0x04;
5656 switch (codec->subsystem_id) {
5657 case 0x1028022f:
5658 /* correct EAPD to be GPIO0 */
5659 spec->eapd_mask = spec->gpio_mask = 0x01;
5660 spec->gpio_dir = spec->gpio_data = 0x01;
5661 break;
5662 };
5663 spec->dmic_nids = stac927x_dmic_nids;
5664 spec->num_dmics = STAC927X_NUM_DMICS;
5665
5666 spec->init = d965_core_init;
5667 spec->mixer = stac927x_mixer;
5668 spec->dmux_nids = stac927x_dmux_nids;
5669 spec->num_dmuxes = ARRAY_SIZE(stac927x_dmux_nids);
5670 break;
5671 default:
5672 if (spec->board_config > STAC_D965_REF) {
5673 /* GPIO0 High = Enable EAPD */
5674 spec->eapd_mask = spec->gpio_mask = 0x01;
5675 spec->gpio_dir = spec->gpio_data = 0x01;
5676 }
5677 spec->num_dmics = 0;
5678
5679 spec->init = stac927x_core_init;
5680 spec->mixer = stac927x_mixer;
5681 }
5682
5683 spec->num_pwrs = 0;
5684 spec->aloopback_ctl = stac927x_loopback;
5685 spec->aloopback_mask = 0x40;
5686 spec->aloopback_shift = 0;
5687 spec->eapd_switch = 1;
5688
5689 err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
5690 if (!err) {
5691 if (spec->board_config < 0) {
5692 printk(KERN_WARNING "hda_codec: No auto-config is "
5693 "available, default to model=ref\n");
5694 spec->board_config = STAC_D965_REF;
5695 goto again;
5696 }
5697 err = -EINVAL;
5698 }
5699 if (err < 0) {
5700 stac92xx_free(codec);
5701 return err;
5702 }
5703
5704 codec->patch_ops = stac92xx_patch_ops;
5705
5706 codec->proc_widget_hook = stac927x_proc_hook;
5707
5708 /*
5709 * !!FIXME!!
5710 * The STAC927x seem to require fairly long delays for certain
5711 * command sequences. With too short delays (even if the answer
5712 * is set to RIRB properly), it results in the silence output
5713 * on some hardwares like Dell.
5714 *
5715 * The below flag enables the longer delay (see get_response
5716 * in hda_intel.c).
5717 */
5718 codec->bus->needs_damn_long_delay = 1;
5719
5720 /* no jack detecion for ref-no-jd model */
5721 if (spec->board_config == STAC_D965_REF_NO_JD)
5722 spec->hp_detect = 0;
5723
5724 return 0;
5725 }
5726
5727 static int patch_stac9205(struct hda_codec *codec)
5728 {
5729 struct sigmatel_spec *spec;
5730 int err;
5731
5732 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5733 if (spec == NULL)
5734 return -ENOMEM;
5735
5736 codec->spec = spec;
5737 spec->num_pins = ARRAY_SIZE(stac9205_pin_nids);
5738 spec->pin_nids = stac9205_pin_nids;
5739 spec->board_config = snd_hda_check_board_config(codec, STAC_9205_MODELS,
5740 stac9205_models,
5741 stac9205_cfg_tbl);
5742 again:
5743 if (spec->board_config < 0)
5744 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9205, using BIOS defaults\n");
5745 else
5746 stac92xx_set_config_regs(codec,
5747 stac9205_brd_tbl[spec->board_config]);
5748
5749 spec->digbeep_nid = 0x23;
5750 spec->adc_nids = stac9205_adc_nids;
5751 spec->num_adcs = ARRAY_SIZE(stac9205_adc_nids);
5752 spec->mux_nids = stac9205_mux_nids;
5753 spec->num_muxes = ARRAY_SIZE(stac9205_mux_nids);
5754 spec->smux_nids = stac9205_smux_nids;
5755 spec->num_smuxes = ARRAY_SIZE(stac9205_smux_nids);
5756 spec->dmic_nids = stac9205_dmic_nids;
5757 spec->num_dmics = STAC9205_NUM_DMICS;
5758 spec->dmux_nids = stac9205_dmux_nids;
5759 spec->num_dmuxes = ARRAY_SIZE(stac9205_dmux_nids);
5760 spec->num_pwrs = 0;
5761
5762 spec->init = stac9205_core_init;
5763 spec->mixer = stac9205_mixer;
5764 spec->aloopback_ctl = stac9205_loopback;
5765
5766 spec->aloopback_mask = 0x40;
5767 spec->aloopback_shift = 0;
5768 /* Turn on/off EAPD per HP plugging */
5769 if (spec->board_config != STAC_9205_EAPD)
5770 spec->eapd_switch = 1;
5771 spec->multiout.dac_nids = spec->dac_nids;
5772
5773 switch (spec->board_config){
5774 case STAC_9205_DELL_M43:
5775 /* Enable SPDIF in/out */
5776 snd_hda_codec_set_pincfg(codec, 0x1f, 0x01441030);
5777 snd_hda_codec_set_pincfg(codec, 0x20, 0x1c410030);
5778
5779 /* Enable unsol response for GPIO4/Dock HP connection */
5780 err = stac_add_event(spec, codec->afg, STAC_VREF_EVENT, 0x01);
5781 if (err < 0)
5782 return err;
5783 snd_hda_codec_write_cache(codec, codec->afg, 0,
5784 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x10);
5785 snd_hda_codec_write_cache(codec, codec->afg, 0,
5786 AC_VERB_SET_UNSOLICITED_ENABLE,
5787 AC_USRSP_EN | err);
5788
5789 spec->gpio_dir = 0x0b;
5790 spec->eapd_mask = 0x01;
5791 spec->gpio_mask = 0x1b;
5792 spec->gpio_mute = 0x10;
5793 /* GPIO0 High = EAPD, GPIO1 Low = Headphone Mute,
5794 * GPIO3 Low = DRM
5795 */
5796 spec->gpio_data = 0x01;
5797 break;
5798 case STAC_9205_REF:
5799 /* SPDIF-In enabled */
5800 break;
5801 default:
5802 /* GPIO0 High = EAPD */
5803 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
5804 spec->gpio_data = 0x01;
5805 break;
5806 }
5807
5808 err = stac92xx_parse_auto_config(codec, 0x1f, 0x20);
5809 if (!err) {
5810 if (spec->board_config < 0) {
5811 printk(KERN_WARNING "hda_codec: No auto-config is "
5812 "available, default to model=ref\n");
5813 spec->board_config = STAC_9205_REF;
5814 goto again;
5815 }
5816 err = -EINVAL;
5817 }
5818 if (err < 0) {
5819 stac92xx_free(codec);
5820 return err;
5821 }
5822
5823 codec->patch_ops = stac92xx_patch_ops;
5824
5825 codec->proc_widget_hook = stac9205_proc_hook;
5826
5827 return 0;
5828 }
5829
5830 /*
5831 * STAC9872 hack
5832 */
5833
5834 static struct hda_verb stac9872_core_init[] = {
5835 {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
5836 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
5837 {}
5838 };
5839
5840 static struct snd_kcontrol_new stac9872_mixer[] = {
5841 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
5842 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
5843 { } /* end */
5844 };
5845
5846 static hda_nid_t stac9872_pin_nids[] = {
5847 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
5848 0x11, 0x13, 0x14,
5849 };
5850
5851 static hda_nid_t stac9872_adc_nids[] = {
5852 0x8 /*,0x6*/
5853 };
5854
5855 static hda_nid_t stac9872_mux_nids[] = {
5856 0x15
5857 };
5858
5859 static unsigned int stac9872_vaio_pin_configs[9] = {
5860 0x03211020, 0x411111f0, 0x411111f0, 0x03a15030,
5861 0x411111f0, 0x90170110, 0x411111f0, 0x411111f0,
5862 0x90a7013e
5863 };
5864
5865 static const char *stac9872_models[STAC_9872_MODELS] = {
5866 [STAC_9872_AUTO] = "auto",
5867 [STAC_9872_VAIO] = "vaio",
5868 };
5869
5870 static unsigned int *stac9872_brd_tbl[STAC_9872_MODELS] = {
5871 [STAC_9872_VAIO] = stac9872_vaio_pin_configs,
5872 };
5873
5874 static struct snd_pci_quirk stac9872_cfg_tbl[] = {
5875 SND_PCI_QUIRK_MASK(0x104d, 0xfff0, 0x81e0,
5876 "Sony VAIO F/S", STAC_9872_VAIO),
5877 {} /* terminator */
5878 };
5879
5880 static int patch_stac9872(struct hda_codec *codec)
5881 {
5882 struct sigmatel_spec *spec;
5883 int err;
5884
5885 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5886 if (spec == NULL)
5887 return -ENOMEM;
5888 codec->spec = spec;
5889 spec->num_pins = ARRAY_SIZE(stac9872_pin_nids);
5890 spec->pin_nids = stac9872_pin_nids;
5891
5892 spec->board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
5893 stac9872_models,
5894 stac9872_cfg_tbl);
5895 if (spec->board_config < 0)
5896 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9872, "
5897 "using BIOS defaults\n");
5898 else
5899 stac92xx_set_config_regs(codec,
5900 stac9872_brd_tbl[spec->board_config]);
5901
5902 spec->multiout.dac_nids = spec->dac_nids;
5903 spec->num_adcs = ARRAY_SIZE(stac9872_adc_nids);
5904 spec->adc_nids = stac9872_adc_nids;
5905 spec->num_muxes = ARRAY_SIZE(stac9872_mux_nids);
5906 spec->mux_nids = stac9872_mux_nids;
5907 spec->mixer = stac9872_mixer;
5908 spec->init = stac9872_core_init;
5909
5910 err = stac92xx_parse_auto_config(codec, 0x10, 0x12);
5911 if (err < 0) {
5912 stac92xx_free(codec);
5913 return -EINVAL;
5914 }
5915 spec->input_mux = &spec->private_imux;
5916 codec->patch_ops = stac92xx_patch_ops;
5917 return 0;
5918 }
5919
5920
5921 /*
5922 * patch entries
5923 */
5924 static struct hda_codec_preset snd_hda_preset_sigmatel[] = {
5925 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
5926 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
5927 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
5928 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
5929 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
5930 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
5931 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
5932 { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
5933 { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
5934 { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
5935 { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
5936 { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
5937 { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
5938 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
5939 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
5940 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
5941 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
5942 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
5943 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
5944 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
5945 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
5946 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
5947 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
5948 { .id = 0x83847632, .name = "STAC9202", .patch = patch_stac925x },
5949 { .id = 0x83847633, .name = "STAC9202D", .patch = patch_stac925x },
5950 { .id = 0x83847634, .name = "STAC9250", .patch = patch_stac925x },
5951 { .id = 0x83847635, .name = "STAC9250D", .patch = patch_stac925x },
5952 { .id = 0x83847636, .name = "STAC9251", .patch = patch_stac925x },
5953 { .id = 0x83847637, .name = "STAC9250D", .patch = patch_stac925x },
5954 { .id = 0x83847645, .name = "92HD206X", .patch = patch_stac927x },
5955 { .id = 0x83847646, .name = "92HD206D", .patch = patch_stac927x },
5956 /* The following does not take into account .id=0x83847661 when subsys =
5957 * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
5958 * currently not fully supported.
5959 */
5960 { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
5961 { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
5962 { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
5963 { .id = 0x83847698, .name = "STAC9205", .patch = patch_stac9205 },
5964 { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
5965 { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
5966 { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
5967 { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
5968 { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
5969 { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
5970 { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
5971 { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
5972 { .id = 0x111d7603, .name = "92HD75B3X5", .patch = patch_stac92hd71bxx},
5973 { .id = 0x111d7604, .name = "92HD83C1X5", .patch = patch_stac92hd83xxx},
5974 { .id = 0x111d7605, .name = "92HD81B1X5", .patch = patch_stac92hd83xxx},
5975 { .id = 0x111d76d5, .name = "92HD81B1C5", .patch = patch_stac92hd83xxx},
5976 { .id = 0x111d7608, .name = "92HD75B2X5", .patch = patch_stac92hd71bxx},
5977 { .id = 0x111d7674, .name = "92HD73D1X5", .patch = patch_stac92hd73xx },
5978 { .id = 0x111d7675, .name = "92HD73C1X5", .patch = patch_stac92hd73xx },
5979 { .id = 0x111d7676, .name = "92HD73E1X5", .patch = patch_stac92hd73xx },
5980 { .id = 0x111d76b0, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
5981 { .id = 0x111d76b1, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
5982 { .id = 0x111d76b2, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
5983 { .id = 0x111d76b3, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
5984 { .id = 0x111d76b4, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
5985 { .id = 0x111d76b5, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
5986 { .id = 0x111d76b6, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
5987 { .id = 0x111d76b7, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
5988 {} /* terminator */
5989 };
5990
5991 MODULE_ALIAS("snd-hda-codec-id:8384*");
5992 MODULE_ALIAS("snd-hda-codec-id:111d*");
5993
5994 MODULE_LICENSE("GPL");
5995 MODULE_DESCRIPTION("IDT/Sigmatel HD-audio codec");
5996
5997 static struct hda_codec_preset_list sigmatel_list = {
5998 .preset = snd_hda_preset_sigmatel,
5999 .owner = THIS_MODULE,
6000 };
6001
6002 static int __init patch_sigmatel_init(void)
6003 {
6004 return snd_hda_add_codec_preset(&sigmatel_list);
6005 }
6006
6007 static void __exit patch_sigmatel_exit(void)
6008 {
6009 snd_hda_delete_codec_preset(&sigmatel_list);
6010 }
6011
6012 module_init(patch_sigmatel_init)
6013 module_exit(patch_sigmatel_exit)
6014
|
This page was automatically generated by the
LXR engine.
|