ALSA: hda - add controls to toggle DC bias on mic ports
[linux-2.6/mini2440.git] / sound / pci / hda / patch_sigmatel.c
blob02950980778e41142ef851f98d144029d3f9ab87
1 /*
2 * Universal Interface for Intel High Definition Audio Codec
4 * HD audio interface patch for SigmaTel STAC92xx
6 * Copyright (c) 2005 Embedded Alley Solutions, Inc.
7 * Matt Porter <mporter@embeddedalley.com>
9 * Based on patch_cmedia.c and patch_realtek.c
10 * Copyright (c) 2004 Takashi Iwai <tiwai@suse.de>
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.
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.
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
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"
38 enum {
39 STAC_VREF_EVENT = 1,
40 STAC_INSERT_EVENT,
41 STAC_PWR_EVENT,
42 STAC_HP_EVENT,
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
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
75 enum {
76 STAC_92HD73XX_AUTO,
77 STAC_92HD73XX_NO_JD, /* no jack-detection */
78 STAC_92HD73XX_REF,
79 STAC_DELL_M6_AMIC,
80 STAC_DELL_M6_DMIC,
81 STAC_DELL_M6_BOTH,
82 STAC_DELL_EQ,
83 STAC_92HD73XX_MODELS
86 enum {
87 STAC_92HD83XXX_AUTO,
88 STAC_92HD83XXX_REF,
89 STAC_92HD83XXX_PWR_REF,
90 STAC_DELL_S14,
91 STAC_92HD83XXX_MODELS
94 enum {
95 STAC_92HD71BXX_AUTO,
96 STAC_92HD71BXX_REF,
97 STAC_DELL_M4_1,
98 STAC_DELL_M4_2,
99 STAC_DELL_M4_3,
100 STAC_HP_M4,
101 STAC_HP_DV5,
102 STAC_HP_HDX,
103 STAC_HP_DV4_1222NR,
104 STAC_92HD71BXX_MODELS
107 enum {
108 STAC_925x_AUTO,
109 STAC_925x_REF,
110 STAC_M1,
111 STAC_M1_2,
112 STAC_M2,
113 STAC_M2_2,
114 STAC_M3,
115 STAC_M5,
116 STAC_M6,
117 STAC_925x_MODELS
120 enum {
121 STAC_922X_AUTO,
122 STAC_D945_REF,
123 STAC_D945GTP3,
124 STAC_D945GTP5,
125 STAC_INTEL_MAC_V1,
126 STAC_INTEL_MAC_V2,
127 STAC_INTEL_MAC_V3,
128 STAC_INTEL_MAC_V4,
129 STAC_INTEL_MAC_V5,
130 STAC_INTEL_MAC_AUTO, /* This model is selected if no module parameter
131 * is given, one of the above models will be
132 * chosen according to the subsystem id. */
133 /* for backward compatibility */
134 STAC_MACMINI,
135 STAC_MACBOOK,
136 STAC_MACBOOK_PRO_V1,
137 STAC_MACBOOK_PRO_V2,
138 STAC_IMAC_INTEL,
139 STAC_IMAC_INTEL_20,
140 STAC_ECS_202,
141 STAC_922X_DELL_D81,
142 STAC_922X_DELL_D82,
143 STAC_922X_DELL_M81,
144 STAC_922X_DELL_M82,
145 STAC_922X_MODELS
148 enum {
149 STAC_927X_AUTO,
150 STAC_D965_REF_NO_JD, /* no jack-detection */
151 STAC_D965_REF,
152 STAC_D965_3ST,
153 STAC_D965_5ST,
154 STAC_DELL_3ST,
155 STAC_DELL_BIOS,
156 STAC_927X_MODELS
159 enum {
160 STAC_9872_AUTO,
161 STAC_9872_VAIO,
162 STAC_9872_MODELS
165 struct sigmatel_event {
166 hda_nid_t nid;
167 unsigned char type;
168 unsigned char tag;
169 int data;
172 struct sigmatel_jack {
173 hda_nid_t nid;
174 int type;
175 struct snd_jack *jack;
178 struct sigmatel_spec {
179 struct snd_kcontrol_new *mixers[4];
180 unsigned int num_mixers;
182 int board_config;
183 unsigned int eapd_switch: 1;
184 unsigned int surr_switch: 1;
185 unsigned int alt_switch: 1;
186 unsigned int hp_detect: 1;
187 unsigned int spdif_mute: 1;
188 unsigned int check_volume_offset:1;
190 /* gpio lines */
191 unsigned int eapd_mask;
192 unsigned int gpio_mask;
193 unsigned int gpio_dir;
194 unsigned int gpio_data;
195 unsigned int gpio_mute;
197 /* stream */
198 unsigned int stream_delay;
200 /* analog loopback */
201 struct snd_kcontrol_new *aloopback_ctl;
202 unsigned char aloopback_mask;
203 unsigned char aloopback_shift;
205 /* power management */
206 unsigned int num_pwrs;
207 unsigned int *pwr_mapping;
208 hda_nid_t *pwr_nids;
209 hda_nid_t *dac_list;
211 /* jack detection */
212 struct snd_array jacks;
214 /* events */
215 struct snd_array events;
217 /* playback */
218 struct hda_input_mux *mono_mux;
219 struct hda_input_mux *amp_mux;
220 unsigned int cur_mmux;
221 struct hda_multi_out multiout;
222 hda_nid_t dac_nids[5];
223 hda_nid_t hp_dacs[5];
224 hda_nid_t speaker_dacs[5];
226 int volume_offset;
228 /* capture */
229 hda_nid_t *adc_nids;
230 unsigned int num_adcs;
231 hda_nid_t *mux_nids;
232 unsigned int num_muxes;
233 hda_nid_t *dmic_nids;
234 unsigned int num_dmics;
235 hda_nid_t *dmux_nids;
236 unsigned int num_dmuxes;
237 hda_nid_t *smux_nids;
238 unsigned int num_smuxes;
239 const char **spdif_labels;
241 hda_nid_t dig_in_nid;
242 hda_nid_t mono_nid;
243 hda_nid_t anabeep_nid;
244 hda_nid_t digbeep_nid;
246 /* pin widgets */
247 hda_nid_t *pin_nids;
248 unsigned int num_pins;
250 /* codec specific stuff */
251 struct hda_verb *init;
252 struct snd_kcontrol_new *mixer;
254 /* capture source */
255 struct hda_input_mux *dinput_mux;
256 unsigned int cur_dmux[2];
257 struct hda_input_mux *input_mux;
258 unsigned int cur_mux[3];
259 struct hda_input_mux *sinput_mux;
260 unsigned int cur_smux[2];
261 unsigned int cur_amux;
262 hda_nid_t *amp_nids;
263 unsigned int num_amps;
264 unsigned int powerdown_adcs;
266 /* i/o switches */
267 unsigned int io_switch[2];
268 unsigned int clfe_swap;
269 hda_nid_t line_switch; /* shared line-in for input and output */
270 hda_nid_t mic_switch; /* shared mic-in for input and output */
271 hda_nid_t hp_switch; /* NID of HP as line-out */
272 unsigned int aloopback;
274 struct hda_pcm pcm_rec[2]; /* PCM information */
276 /* dynamic controls and input_mux */
277 struct auto_pin_cfg autocfg;
278 struct snd_array kctls;
279 struct hda_input_mux private_dimux;
280 struct hda_input_mux private_imux;
281 struct hda_input_mux private_smux;
282 struct hda_input_mux private_amp_mux;
283 struct hda_input_mux private_mono_mux;
286 static hda_nid_t stac9200_adc_nids[1] = {
287 0x03,
290 static hda_nid_t stac9200_mux_nids[1] = {
291 0x0c,
294 static hda_nid_t stac9200_dac_nids[1] = {
295 0x02,
298 static hda_nid_t stac92hd73xx_pwr_nids[8] = {
299 0x0a, 0x0b, 0x0c, 0xd, 0x0e,
300 0x0f, 0x10, 0x11
303 static hda_nid_t stac92hd73xx_slave_dig_outs[2] = {
304 0x26, 0,
307 static hda_nid_t stac92hd73xx_adc_nids[2] = {
308 0x1a, 0x1b
311 #define DELL_M6_AMP 2
312 static hda_nid_t stac92hd73xx_amp_nids[3] = {
313 0x0b, 0x0c, 0x0e
316 #define STAC92HD73XX_NUM_DMICS 2
317 static hda_nid_t stac92hd73xx_dmic_nids[STAC92HD73XX_NUM_DMICS + 1] = {
318 0x13, 0x14, 0
321 #define STAC92HD73_DAC_COUNT 5
323 static hda_nid_t stac92hd73xx_mux_nids[4] = {
324 0x28, 0x29, 0x2a, 0x2b,
327 static hda_nid_t stac92hd73xx_dmux_nids[2] = {
328 0x20, 0x21,
331 static hda_nid_t stac92hd73xx_smux_nids[2] = {
332 0x22, 0x23,
335 #define STAC92HD83XXX_NUM_DMICS 2
336 static hda_nid_t stac92hd83xxx_dmic_nids[STAC92HD83XXX_NUM_DMICS + 1] = {
337 0x11, 0x12, 0
340 #define STAC92HD83_DAC_COUNT 3
342 static hda_nid_t stac92hd83xxx_dmux_nids[2] = {
343 0x17, 0x18,
346 static hda_nid_t stac92hd83xxx_adc_nids[2] = {
347 0x15, 0x16,
350 static hda_nid_t stac92hd83xxx_pwr_nids[4] = {
351 0xa, 0xb, 0xd, 0xe,
354 static hda_nid_t stac92hd83xxx_slave_dig_outs[2] = {
355 0x1e, 0,
358 static unsigned int stac92hd83xxx_pwr_mapping[4] = {
359 0x03, 0x0c, 0x20, 0x40,
362 static hda_nid_t stac92hd83xxx_amp_nids[1] = {
363 0xc,
366 static hda_nid_t stac92hd71bxx_pwr_nids[3] = {
367 0x0a, 0x0d, 0x0f
370 static hda_nid_t stac92hd71bxx_adc_nids[2] = {
371 0x12, 0x13,
374 static hda_nid_t stac92hd71bxx_mux_nids[2] = {
375 0x1a, 0x1b
378 static hda_nid_t stac92hd71bxx_dmux_nids[2] = {
379 0x1c, 0x1d,
382 static hda_nid_t stac92hd71bxx_smux_nids[2] = {
383 0x24, 0x25,
386 #define STAC92HD71BXX_NUM_DMICS 2
387 static hda_nid_t stac92hd71bxx_dmic_nids[STAC92HD71BXX_NUM_DMICS + 1] = {
388 0x18, 0x19, 0
391 static hda_nid_t stac92hd71bxx_slave_dig_outs[2] = {
392 0x22, 0
395 static hda_nid_t stac925x_adc_nids[1] = {
396 0x03,
399 static hda_nid_t stac925x_mux_nids[1] = {
400 0x0f,
403 static hda_nid_t stac925x_dac_nids[1] = {
404 0x02,
407 #define STAC925X_NUM_DMICS 1
408 static hda_nid_t stac925x_dmic_nids[STAC925X_NUM_DMICS + 1] = {
409 0x15, 0
412 static hda_nid_t stac925x_dmux_nids[1] = {
413 0x14,
416 static hda_nid_t stac922x_adc_nids[2] = {
417 0x06, 0x07,
420 static hda_nid_t stac922x_mux_nids[2] = {
421 0x12, 0x13,
424 static hda_nid_t stac927x_slave_dig_outs[2] = {
425 0x1f, 0,
428 static hda_nid_t stac927x_adc_nids[3] = {
429 0x07, 0x08, 0x09
432 static hda_nid_t stac927x_mux_nids[3] = {
433 0x15, 0x16, 0x17
436 static hda_nid_t stac927x_smux_nids[1] = {
437 0x21,
440 static hda_nid_t stac927x_dac_nids[6] = {
441 0x02, 0x03, 0x04, 0x05, 0x06, 0
444 static hda_nid_t stac927x_dmux_nids[1] = {
445 0x1b,
448 #define STAC927X_NUM_DMICS 2
449 static hda_nid_t stac927x_dmic_nids[STAC927X_NUM_DMICS + 1] = {
450 0x13, 0x14, 0
453 static const char *stac927x_spdif_labels[5] = {
454 "Digital Playback", "ADAT", "Analog Mux 1",
455 "Analog Mux 2", "Analog Mux 3"
458 static hda_nid_t stac9205_adc_nids[2] = {
459 0x12, 0x13
462 static hda_nid_t stac9205_mux_nids[2] = {
463 0x19, 0x1a
466 static hda_nid_t stac9205_dmux_nids[1] = {
467 0x1d,
470 static hda_nid_t stac9205_smux_nids[1] = {
471 0x21,
474 #define STAC9205_NUM_DMICS 2
475 static hda_nid_t stac9205_dmic_nids[STAC9205_NUM_DMICS + 1] = {
476 0x17, 0x18, 0
479 static hda_nid_t stac9200_pin_nids[8] = {
480 0x08, 0x09, 0x0d, 0x0e,
481 0x0f, 0x10, 0x11, 0x12,
484 static hda_nid_t stac925x_pin_nids[8] = {
485 0x07, 0x08, 0x0a, 0x0b,
486 0x0c, 0x0d, 0x10, 0x11,
489 static hda_nid_t stac922x_pin_nids[10] = {
490 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
491 0x0f, 0x10, 0x11, 0x15, 0x1b,
494 static hda_nid_t stac92hd73xx_pin_nids[13] = {
495 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
496 0x0f, 0x10, 0x11, 0x12, 0x13,
497 0x14, 0x22, 0x23
500 static hda_nid_t stac92hd83xxx_pin_nids[10] = {
501 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
502 0x0f, 0x10, 0x11, 0x1f, 0x20,
505 #define STAC92HD71BXX_NUM_PINS 13
506 static hda_nid_t stac92hd71bxx_pin_nids_4port[STAC92HD71BXX_NUM_PINS] = {
507 0x0a, 0x0b, 0x0c, 0x0d, 0x00,
508 0x00, 0x14, 0x18, 0x19, 0x1e,
509 0x1f, 0x20, 0x27
511 static hda_nid_t stac92hd71bxx_pin_nids_6port[STAC92HD71BXX_NUM_PINS] = {
512 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
513 0x0f, 0x14, 0x18, 0x19, 0x1e,
514 0x1f, 0x20, 0x27
517 static hda_nid_t stac927x_pin_nids[14] = {
518 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
519 0x0f, 0x10, 0x11, 0x12, 0x13,
520 0x14, 0x21, 0x22, 0x23,
523 static hda_nid_t stac9205_pin_nids[12] = {
524 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
525 0x0f, 0x14, 0x16, 0x17, 0x18,
526 0x21, 0x22,
529 #define stac92xx_amp_volume_info snd_hda_mixer_amp_volume_info
531 static int stac92xx_amp_volume_get(struct snd_kcontrol *kcontrol,
532 struct snd_ctl_elem_value *ucontrol)
534 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
535 struct sigmatel_spec *spec = codec->spec;
536 hda_nid_t nid = spec->amp_nids[spec->cur_amux];
538 kcontrol->private_value ^= get_amp_nid(kcontrol);
539 kcontrol->private_value |= nid;
541 return snd_hda_mixer_amp_volume_get(kcontrol, ucontrol);
544 static int stac92xx_amp_volume_put(struct snd_kcontrol *kcontrol,
545 struct snd_ctl_elem_value *ucontrol)
547 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
548 struct sigmatel_spec *spec = codec->spec;
549 hda_nid_t nid = spec->amp_nids[spec->cur_amux];
551 kcontrol->private_value ^= get_amp_nid(kcontrol);
552 kcontrol->private_value |= nid;
554 return snd_hda_mixer_amp_volume_put(kcontrol, ucontrol);
557 static int stac92xx_dmux_enum_info(struct snd_kcontrol *kcontrol,
558 struct snd_ctl_elem_info *uinfo)
560 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
561 struct sigmatel_spec *spec = codec->spec;
562 return snd_hda_input_mux_info(spec->dinput_mux, uinfo);
565 static int stac92xx_dmux_enum_get(struct snd_kcontrol *kcontrol,
566 struct snd_ctl_elem_value *ucontrol)
568 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
569 struct sigmatel_spec *spec = codec->spec;
570 unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
572 ucontrol->value.enumerated.item[0] = spec->cur_dmux[dmux_idx];
573 return 0;
576 static int stac92xx_dmux_enum_put(struct snd_kcontrol *kcontrol,
577 struct snd_ctl_elem_value *ucontrol)
579 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
580 struct sigmatel_spec *spec = codec->spec;
581 unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
583 return snd_hda_input_mux_put(codec, spec->dinput_mux, ucontrol,
584 spec->dmux_nids[dmux_idx], &spec->cur_dmux[dmux_idx]);
587 static int stac92xx_smux_enum_info(struct snd_kcontrol *kcontrol,
588 struct snd_ctl_elem_info *uinfo)
590 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
591 struct sigmatel_spec *spec = codec->spec;
592 return snd_hda_input_mux_info(spec->sinput_mux, uinfo);
595 static int stac92xx_smux_enum_get(struct snd_kcontrol *kcontrol,
596 struct snd_ctl_elem_value *ucontrol)
598 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
599 struct sigmatel_spec *spec = codec->spec;
600 unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
602 ucontrol->value.enumerated.item[0] = spec->cur_smux[smux_idx];
603 return 0;
606 static int stac92xx_smux_enum_put(struct snd_kcontrol *kcontrol,
607 struct snd_ctl_elem_value *ucontrol)
609 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
610 struct sigmatel_spec *spec = codec->spec;
611 struct hda_input_mux *smux = &spec->private_smux;
612 unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
613 int err, val;
614 hda_nid_t nid;
616 err = snd_hda_input_mux_put(codec, spec->sinput_mux, ucontrol,
617 spec->smux_nids[smux_idx], &spec->cur_smux[smux_idx]);
618 if (err < 0)
619 return err;
621 if (spec->spdif_mute) {
622 if (smux_idx == 0)
623 nid = spec->multiout.dig_out_nid;
624 else
625 nid = codec->slave_dig_outs[smux_idx - 1];
626 if (spec->cur_smux[smux_idx] == smux->num_items - 1)
627 val = HDA_AMP_MUTE;
628 else
629 val = 0;
630 /* un/mute SPDIF out */
631 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
632 HDA_AMP_MUTE, val);
634 return 0;
637 static unsigned int stac92xx_vref_set(struct hda_codec *codec,
638 hda_nid_t nid, unsigned int new_vref)
640 unsigned int error;
641 unsigned int pincfg;
642 pincfg = snd_hda_codec_read(codec, nid, 0,
643 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
645 pincfg &= 0xff;
646 pincfg &= ~(AC_PINCTL_VREFEN | AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
647 pincfg |= new_vref;
649 if (new_vref == AC_PINCTL_VREF_HIZ)
650 pincfg |= AC_PINCTL_OUT_EN;
651 else
652 pincfg |= AC_PINCTL_IN_EN;
654 error = snd_hda_codec_write_cache(codec, nid, 0,
655 AC_VERB_SET_PIN_WIDGET_CONTROL, pincfg);
656 if (error < 0)
657 return error;
658 else
659 return 1;
662 static unsigned int stac92xx_vref_get(struct hda_codec *codec, hda_nid_t nid)
664 unsigned int vref;
665 vref = snd_hda_codec_read(codec, nid, 0,
666 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
667 vref &= AC_PINCTL_VREFEN;
668 return vref;
671 static int stac92xx_dc_bias_put(struct snd_kcontrol *kcontrol,
672 struct snd_ctl_elem_value *ucontrol)
674 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
675 unsigned int new_vref;
676 unsigned int error;
678 if (ucontrol->value.enumerated.item[0] == 0)
679 new_vref = AC_PINCTL_VREF_80;
680 else if (ucontrol->value.enumerated.item[0] == 1)
681 new_vref = AC_PINCTL_VREF_GRD;
682 else
683 new_vref = AC_PINCTL_VREF_HIZ;
685 if (new_vref != stac92xx_vref_get(codec, kcontrol->private_value)) {
686 error = stac92xx_vref_set(codec,
687 kcontrol->private_value, new_vref);
688 return error;
691 return 0;
694 static int stac92xx_dc_bias_get(struct snd_kcontrol *kcontrol,
695 struct snd_ctl_elem_value *ucontrol)
697 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
698 unsigned int vref = stac92xx_vref_get(codec, kcontrol->private_value);
699 if (vref == AC_PINCTL_VREF_80)
700 ucontrol->value.enumerated.item[0] = 0;
701 else if (vref == AC_PINCTL_VREF_GRD)
702 ucontrol->value.enumerated.item[0] = 1;
703 else if (vref == AC_PINCTL_VREF_HIZ)
704 ucontrol->value.enumerated.item[0] = 2;
706 return 0;
709 static int stac92xx_dc_bias_info(struct snd_kcontrol *kcontrol,
710 struct snd_ctl_elem_info *uinfo)
712 static char *texts[] = {
713 "Mic In", "Line In", "Line Out"
716 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
717 uinfo->value.enumerated.items = 3;
718 uinfo->count = 1;
719 if (uinfo->value.enumerated.item >= 3)
720 uinfo->value.enumerated.item = 2;
721 strcpy(uinfo->value.enumerated.name,
722 texts[uinfo->value.enumerated.item]);
724 return 0;
727 static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
729 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
730 struct sigmatel_spec *spec = codec->spec;
731 return snd_hda_input_mux_info(spec->input_mux, uinfo);
734 static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
736 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
737 struct sigmatel_spec *spec = codec->spec;
738 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
740 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
741 return 0;
744 static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
746 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
747 struct sigmatel_spec *spec = codec->spec;
748 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
750 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
751 spec->mux_nids[adc_idx], &spec->cur_mux[adc_idx]);
754 static int stac92xx_mono_mux_enum_info(struct snd_kcontrol *kcontrol,
755 struct snd_ctl_elem_info *uinfo)
757 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
758 struct sigmatel_spec *spec = codec->spec;
759 return snd_hda_input_mux_info(spec->mono_mux, uinfo);
762 static int stac92xx_mono_mux_enum_get(struct snd_kcontrol *kcontrol,
763 struct snd_ctl_elem_value *ucontrol)
765 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
766 struct sigmatel_spec *spec = codec->spec;
768 ucontrol->value.enumerated.item[0] = spec->cur_mmux;
769 return 0;
772 static int stac92xx_mono_mux_enum_put(struct snd_kcontrol *kcontrol,
773 struct snd_ctl_elem_value *ucontrol)
775 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
776 struct sigmatel_spec *spec = codec->spec;
778 return snd_hda_input_mux_put(codec, spec->mono_mux, ucontrol,
779 spec->mono_nid, &spec->cur_mmux);
782 static int stac92xx_amp_mux_enum_info(struct snd_kcontrol *kcontrol,
783 struct snd_ctl_elem_info *uinfo)
785 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
786 struct sigmatel_spec *spec = codec->spec;
787 return snd_hda_input_mux_info(spec->amp_mux, uinfo);
790 static int stac92xx_amp_mux_enum_get(struct snd_kcontrol *kcontrol,
791 struct snd_ctl_elem_value *ucontrol)
793 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
794 struct sigmatel_spec *spec = codec->spec;
796 ucontrol->value.enumerated.item[0] = spec->cur_amux;
797 return 0;
800 static int stac92xx_amp_mux_enum_put(struct snd_kcontrol *kcontrol,
801 struct snd_ctl_elem_value *ucontrol)
803 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
804 struct sigmatel_spec *spec = codec->spec;
805 struct snd_kcontrol *ctl =
806 snd_hda_find_mixer_ctl(codec, "Amp Capture Volume");
807 if (!ctl)
808 return -EINVAL;
810 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE |
811 SNDRV_CTL_EVENT_MASK_INFO, &ctl->id);
813 return snd_hda_input_mux_put(codec, spec->amp_mux, ucontrol,
814 0, &spec->cur_amux);
817 #define stac92xx_aloopback_info snd_ctl_boolean_mono_info
819 static int stac92xx_aloopback_get(struct snd_kcontrol *kcontrol,
820 struct snd_ctl_elem_value *ucontrol)
822 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
823 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
824 struct sigmatel_spec *spec = codec->spec;
826 ucontrol->value.integer.value[0] = !!(spec->aloopback &
827 (spec->aloopback_mask << idx));
828 return 0;
831 static int stac92xx_aloopback_put(struct snd_kcontrol *kcontrol,
832 struct snd_ctl_elem_value *ucontrol)
834 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
835 struct sigmatel_spec *spec = codec->spec;
836 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
837 unsigned int dac_mode;
838 unsigned int val, idx_val;
840 idx_val = spec->aloopback_mask << idx;
841 if (ucontrol->value.integer.value[0])
842 val = spec->aloopback | idx_val;
843 else
844 val = spec->aloopback & ~idx_val;
845 if (spec->aloopback == val)
846 return 0;
848 spec->aloopback = val;
850 /* Only return the bits defined by the shift value of the
851 * first two bytes of the mask
853 dac_mode = snd_hda_codec_read(codec, codec->afg, 0,
854 kcontrol->private_value & 0xFFFF, 0x0);
855 dac_mode >>= spec->aloopback_shift;
857 if (spec->aloopback & idx_val) {
858 snd_hda_power_up(codec);
859 dac_mode |= idx_val;
860 } else {
861 snd_hda_power_down(codec);
862 dac_mode &= ~idx_val;
865 snd_hda_codec_write_cache(codec, codec->afg, 0,
866 kcontrol->private_value >> 16, dac_mode);
868 return 1;
871 static struct hda_verb stac9200_core_init[] = {
872 /* set dac0mux for dac converter */
873 { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
877 static struct hda_verb stac9200_eapd_init[] = {
878 /* set dac0mux for dac converter */
879 {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
880 {0x08, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
884 static struct hda_verb stac92hd73xx_6ch_core_init[] = {
885 /* set master volume and direct control */
886 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
887 /* setup adcs to point to mixer */
888 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
889 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
890 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
891 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
892 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
893 /* setup import muxs */
894 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
895 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
896 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
897 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x00},
901 static struct hda_verb dell_eq_core_init[] = {
902 /* set master volume to max value without distortion
903 * and direct control */
904 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xec},
905 /* setup adcs to point to mixer */
906 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
907 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
908 /* setup import muxs */
909 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
910 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
911 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
912 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x00},
916 static struct hda_verb dell_m6_core_init[] = {
917 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
918 /* setup adcs to point to mixer */
919 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
920 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
921 /* setup import muxs */
922 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
923 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
924 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
925 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x00},
929 static struct hda_verb stac92hd73xx_8ch_core_init[] = {
930 /* set master volume and direct control */
931 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
932 /* setup adcs to point to mixer */
933 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
934 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
935 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
936 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
937 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
938 /* setup import muxs */
939 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
940 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
941 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
942 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x03},
946 static struct hda_verb stac92hd73xx_10ch_core_init[] = {
947 /* set master volume and direct control */
948 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
949 /* dac3 is connected to import3 mux */
950 { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0xb07f},
951 /* setup adcs to point to mixer */
952 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
953 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
954 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
955 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
956 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
957 /* setup import muxs */
958 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
959 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
960 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
961 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x03},
965 static struct hda_verb stac92hd83xxx_core_init[] = {
966 { 0xa, AC_VERB_SET_CONNECT_SEL, 0x1},
967 { 0xb, AC_VERB_SET_CONNECT_SEL, 0x1},
968 { 0xd, AC_VERB_SET_CONNECT_SEL, 0x0},
970 /* power state controls amps */
971 { 0x01, AC_VERB_SET_EAPD, 1 << 2},
975 static struct hda_verb stac92hd71bxx_core_init[] = {
976 /* set master volume and direct control */
977 { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
981 #define HD_DISABLE_PORTF 1
982 static struct hda_verb stac92hd71bxx_analog_core_init[] = {
983 /* start of config #1 */
985 /* connect port 0f to audio mixer */
986 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x2},
987 /* start of config #2 */
989 /* set master volume and direct control */
990 { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
994 static struct hda_verb stac92hd71bxx_unmute_core_init[] = {
995 /* unmute right and left channels for nodes 0x0f, 0xa, 0x0d */
996 { 0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
997 { 0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
998 { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1002 static struct hda_verb stac925x_core_init[] = {
1003 /* set dac0mux for dac converter */
1004 { 0x06, AC_VERB_SET_CONNECT_SEL, 0x00},
1005 /* mute the master volume */
1006 { 0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1010 static struct hda_verb stac922x_core_init[] = {
1011 /* set master volume and direct control */
1012 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
1016 static struct hda_verb d965_core_init[] = {
1017 /* set master volume and direct control */
1018 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
1019 /* unmute node 0x1b */
1020 { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1021 /* select node 0x03 as DAC */
1022 { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
1026 static struct hda_verb stac927x_core_init[] = {
1027 /* set master volume and direct control */
1028 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
1029 /* enable analog pc beep path */
1030 { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
1034 static struct hda_verb stac9205_core_init[] = {
1035 /* set master volume and direct control */
1036 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
1037 /* enable analog pc beep path */
1038 { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
1042 #define STAC_MONO_MUX \
1044 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1045 .name = "Mono Mux", \
1046 .count = 1, \
1047 .info = stac92xx_mono_mux_enum_info, \
1048 .get = stac92xx_mono_mux_enum_get, \
1049 .put = stac92xx_mono_mux_enum_put, \
1052 #define STAC_AMP_MUX \
1054 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1055 .name = "Amp Selector Capture Switch", \
1056 .count = 1, \
1057 .info = stac92xx_amp_mux_enum_info, \
1058 .get = stac92xx_amp_mux_enum_get, \
1059 .put = stac92xx_amp_mux_enum_put, \
1062 #define STAC_AMP_VOL(xname, nid, chs, idx, dir) \
1064 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1065 .name = xname, \
1066 .index = 0, \
1067 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1068 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1069 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
1070 .info = stac92xx_amp_volume_info, \
1071 .get = stac92xx_amp_volume_get, \
1072 .put = stac92xx_amp_volume_put, \
1073 .tlv = { .c = snd_hda_mixer_amp_tlv }, \
1074 .private_value = HDA_COMPOSE_AMP_VAL(nid, chs, idx, dir) \
1077 #define STAC_ANALOG_LOOPBACK(verb_read, verb_write, cnt) \
1079 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1080 .name = "Analog Loopback", \
1081 .count = cnt, \
1082 .info = stac92xx_aloopback_info, \
1083 .get = stac92xx_aloopback_get, \
1084 .put = stac92xx_aloopback_put, \
1085 .private_value = verb_read | (verb_write << 16), \
1088 #define DC_BIAS(xname, idx, nid) \
1090 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1091 .name = xname, \
1092 .index = idx, \
1093 .info = stac92xx_dc_bias_info, \
1094 .get = stac92xx_dc_bias_get, \
1095 .put = stac92xx_dc_bias_put, \
1096 .private_value = nid, \
1099 static struct snd_kcontrol_new stac9200_mixer[] = {
1100 HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
1101 HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
1102 HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
1103 HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
1104 { } /* end */
1107 #define DELL_M6_MIXER 6
1108 static struct snd_kcontrol_new stac92hd73xx_6ch_mixer[] = {
1109 /* start of config #1 */
1110 HDA_CODEC_VOLUME("Front Mic Mixer Capture Volume", 0x1d, 0, HDA_INPUT),
1111 HDA_CODEC_MUTE("Front Mic Mixer Capture Switch", 0x1d, 0, HDA_INPUT),
1113 HDA_CODEC_VOLUME("Line In Mixer Capture Volume", 0x1d, 0x2, HDA_INPUT),
1114 HDA_CODEC_MUTE("Line In Mixer Capture Switch", 0x1d, 0x2, HDA_INPUT),
1116 HDA_CODEC_VOLUME("CD Mixer Capture Volume", 0x1d, 0x4, HDA_INPUT),
1117 HDA_CODEC_MUTE("CD Mixer Capture Switch", 0x1d, 0x4, HDA_INPUT),
1119 /* start of config #2 */
1120 HDA_CODEC_VOLUME("Mic Mixer Capture Volume", 0x1d, 0x1, HDA_INPUT),
1121 HDA_CODEC_MUTE("Mic Mixer Capture Switch", 0x1d, 0x1, HDA_INPUT),
1123 HDA_CODEC_VOLUME("DAC Mixer Capture Volume", 0x1d, 0x3, HDA_INPUT),
1124 HDA_CODEC_MUTE("DAC Mixer Capture Switch", 0x1d, 0x3, HDA_INPUT),
1126 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x20, 0x0, HDA_OUTPUT),
1127 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x20, 0x0, HDA_OUTPUT),
1129 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x21, 0x0, HDA_OUTPUT),
1130 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x21, 0x0, HDA_OUTPUT),
1132 { } /* end */
1135 static struct snd_kcontrol_new stac92hd73xx_6ch_loopback[] = {
1136 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 3),
1140 static struct snd_kcontrol_new stac92hd73xx_8ch_loopback[] = {
1141 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 4),
1145 static struct snd_kcontrol_new stac92hd73xx_10ch_loopback[] = {
1146 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 5),
1150 static struct snd_kcontrol_new stac92hd73xx_8ch_mixer[] = {
1151 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x20, 0x0, HDA_OUTPUT),
1152 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x20, 0x0, HDA_OUTPUT),
1154 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x21, 0x0, HDA_OUTPUT),
1155 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x21, 0x0, HDA_OUTPUT),
1157 HDA_CODEC_VOLUME("Front Mic Mixer Capture Volume", 0x1d, 0, HDA_INPUT),
1158 HDA_CODEC_MUTE("Front Mic Mixer Capture Switch", 0x1d, 0, HDA_INPUT),
1160 HDA_CODEC_VOLUME("Mic Mixer Capture Volume", 0x1d, 0x1, HDA_INPUT),
1161 HDA_CODEC_MUTE("Mic Mixer Capture Switch", 0x1d, 0x1, HDA_INPUT),
1163 HDA_CODEC_VOLUME("Line In Mixer Capture Volume", 0x1d, 0x2, HDA_INPUT),
1164 HDA_CODEC_MUTE("Line In Mixer Capture Switch", 0x1d, 0x2, HDA_INPUT),
1166 HDA_CODEC_VOLUME("DAC Mixer Capture Volume", 0x1d, 0x3, HDA_INPUT),
1167 HDA_CODEC_MUTE("DAC Mixer Capture Switch", 0x1d, 0x3, HDA_INPUT),
1169 HDA_CODEC_VOLUME("CD Mixer Capture Volume", 0x1d, 0x4, HDA_INPUT),
1170 HDA_CODEC_MUTE("CD Mixer Capture Switch", 0x1d, 0x4, HDA_INPUT),
1171 { } /* end */
1174 static struct snd_kcontrol_new stac92hd73xx_10ch_mixer[] = {
1175 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x20, 0x0, HDA_OUTPUT),
1176 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x20, 0x0, HDA_OUTPUT),
1178 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x21, 0x0, HDA_OUTPUT),
1179 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x21, 0x0, HDA_OUTPUT),
1181 HDA_CODEC_VOLUME("Front Mic Mixer Capture Volume", 0x1d, 0, HDA_INPUT),
1182 HDA_CODEC_MUTE("Front Mic Mixer Capture Switch", 0x1d, 0, HDA_INPUT),
1184 HDA_CODEC_VOLUME("Mic Mixer Capture Volume", 0x1d, 0x1, HDA_INPUT),
1185 HDA_CODEC_MUTE("Mic Mixer Capture Switch", 0x1d, 0x1, HDA_INPUT),
1187 HDA_CODEC_VOLUME("Line In Mixer Capture Volume", 0x1d, 0x2, HDA_INPUT),
1188 HDA_CODEC_MUTE("Line In Mixer Capture Switch", 0x1d, 0x2, HDA_INPUT),
1190 HDA_CODEC_VOLUME("DAC Mixer Capture Volume", 0x1d, 0x3, HDA_INPUT),
1191 HDA_CODEC_MUTE("DAC Mixer Capture Switch", 0x1d, 0x3, HDA_INPUT),
1193 HDA_CODEC_VOLUME("CD Mixer Capture Volume", 0x1d, 0x4, HDA_INPUT),
1194 HDA_CODEC_MUTE("CD Mixer Capture Switch", 0x1d, 0x4, HDA_INPUT),
1195 { } /* end */
1199 static struct snd_kcontrol_new stac92hd83xxx_mixer[] = {
1200 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x17, 0x0, HDA_OUTPUT),
1201 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x17, 0x0, HDA_OUTPUT),
1203 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x18, 0x0, HDA_OUTPUT),
1204 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x18, 0x0, HDA_OUTPUT),
1206 HDA_CODEC_VOLUME("DAC0 Capture Volume", 0x1b, 0x3, HDA_INPUT),
1207 HDA_CODEC_MUTE("DAC0 Capture Switch", 0x1b, 0x3, HDA_INPUT),
1209 HDA_CODEC_VOLUME("DAC1 Capture Volume", 0x1b, 0x4, HDA_INPUT),
1210 HDA_CODEC_MUTE("DAC1 Capture Switch", 0x1b, 0x4, HDA_INPUT),
1212 HDA_CODEC_VOLUME("Front Mic Capture Volume", 0x1b, 0x0, HDA_INPUT),
1213 HDA_CODEC_MUTE("Front Mic Capture Switch", 0x1b, 0x0, HDA_INPUT),
1215 HDA_CODEC_VOLUME("Line In Capture Volume", 0x1b, 0x2, HDA_INPUT),
1216 HDA_CODEC_MUTE("Line In Capture Switch", 0x1b, 0x2, HDA_INPUT),
1219 HDA_CODEC_VOLUME("Mic Capture Volume", 0x1b, 0x1, HDA_INPUT),
1220 HDA_CODEC_MUTE("Mic Capture Switch", 0x1b 0x1, HDA_INPUT),
1222 { } /* end */
1225 static struct snd_kcontrol_new stac92hd71bxx_analog_mixer[] = {
1226 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1c, 0x0, HDA_OUTPUT),
1227 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1c, 0x0, HDA_OUTPUT),
1229 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x1d, 0x0, HDA_OUTPUT),
1230 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1d, 0x0, HDA_OUTPUT),
1231 /* analog pc-beep replaced with digital beep support */
1233 HDA_CODEC_VOLUME("PC Beep Volume", 0x17, 0x2, HDA_INPUT),
1234 HDA_CODEC_MUTE("PC Beep Switch", 0x17, 0x2, HDA_INPUT),
1237 HDA_CODEC_MUTE("Import0 Mux Capture Switch", 0x17, 0x0, HDA_INPUT),
1238 HDA_CODEC_VOLUME("Import0 Mux Capture Volume", 0x17, 0x0, HDA_INPUT),
1240 HDA_CODEC_MUTE("Import1 Mux Capture Switch", 0x17, 0x1, HDA_INPUT),
1241 HDA_CODEC_VOLUME("Import1 Mux Capture Volume", 0x17, 0x1, HDA_INPUT),
1243 HDA_CODEC_MUTE("DAC0 Capture Switch", 0x17, 0x3, HDA_INPUT),
1244 HDA_CODEC_VOLUME("DAC0 Capture Volume", 0x17, 0x3, HDA_INPUT),
1246 HDA_CODEC_MUTE("DAC1 Capture Switch", 0x17, 0x4, HDA_INPUT),
1247 HDA_CODEC_VOLUME("DAC1 Capture Volume", 0x17, 0x4, HDA_INPUT),
1248 { } /* end */
1251 static struct snd_kcontrol_new stac92hd71bxx_loopback[] = {
1252 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A0, 2)
1255 static struct snd_kcontrol_new stac92hd71bxx_mixer[] = {
1256 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1c, 0x0, HDA_OUTPUT),
1257 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1c, 0x0, HDA_OUTPUT),
1259 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x1d, 0x0, HDA_OUTPUT),
1260 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1d, 0x0, HDA_OUTPUT),
1261 { } /* end */
1264 static struct snd_kcontrol_new stac925x_mixer[] = {
1265 HDA_CODEC_VOLUME("Master Playback Volume", 0x0e, 0, HDA_OUTPUT),
1266 HDA_CODEC_MUTE("Master Playback Switch", 0x0e, 0, HDA_OUTPUT),
1267 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_OUTPUT),
1268 HDA_CODEC_MUTE("Capture Switch", 0x14, 0, HDA_OUTPUT),
1269 { } /* end */
1272 static struct snd_kcontrol_new stac9205_mixer[] = {
1273 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1b, 0x0, HDA_INPUT),
1274 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1d, 0x0, HDA_OUTPUT),
1276 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x1c, 0x0, HDA_INPUT),
1277 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1e, 0x0, HDA_OUTPUT),
1278 { } /* end */
1281 static struct snd_kcontrol_new stac9205_loopback[] = {
1282 STAC_ANALOG_LOOPBACK(0xFE0, 0x7E0, 1),
1286 /* This needs to be generated dynamically based on sequence */
1287 static struct snd_kcontrol_new stac922x_mixer[] = {
1288 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x17, 0x0, HDA_INPUT),
1289 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x17, 0x0, HDA_INPUT),
1291 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x18, 0x0, HDA_INPUT),
1292 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x18, 0x0, HDA_INPUT),
1293 { } /* end */
1297 static struct snd_kcontrol_new stac927x_mixer[] = {
1298 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x18, 0x0, HDA_INPUT),
1299 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1b, 0x0, HDA_OUTPUT),
1301 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x19, 0x0, HDA_INPUT),
1302 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1c, 0x0, HDA_OUTPUT),
1304 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x2, 0x1A, 0x0, HDA_INPUT),
1305 HDA_CODEC_MUTE_IDX("Capture Switch", 0x2, 0x1d, 0x0, HDA_OUTPUT),
1306 { } /* end */
1309 static struct snd_kcontrol_new stac927x_loopback[] = {
1310 STAC_ANALOG_LOOPBACK(0xFEB, 0x7EB, 1),
1314 static struct snd_kcontrol_new stac_dmux_mixer = {
1315 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1316 .name = "Digital Input Source",
1317 /* count set later */
1318 .info = stac92xx_dmux_enum_info,
1319 .get = stac92xx_dmux_enum_get,
1320 .put = stac92xx_dmux_enum_put,
1323 static struct snd_kcontrol_new stac_smux_mixer = {
1324 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1325 .name = "IEC958 Playback Source",
1326 /* count set later */
1327 .info = stac92xx_smux_enum_info,
1328 .get = stac92xx_smux_enum_get,
1329 .put = stac92xx_smux_enum_put,
1332 static const char *slave_vols[] = {
1333 "Front Playback Volume",
1334 "Surround Playback Volume",
1335 "Center Playback Volume",
1336 "LFE Playback Volume",
1337 "Side Playback Volume",
1338 "Headphone Playback Volume",
1339 "Speaker Playback Volume",
1340 NULL
1343 static const char *slave_sws[] = {
1344 "Front Playback Switch",
1345 "Surround Playback Switch",
1346 "Center Playback Switch",
1347 "LFE Playback Switch",
1348 "Side Playback Switch",
1349 "Headphone Playback Switch",
1350 "Speaker Playback Switch",
1351 "IEC958 Playback Switch",
1352 NULL
1355 static void stac92xx_free_kctls(struct hda_codec *codec);
1356 static int stac92xx_add_jack(struct hda_codec *codec, hda_nid_t nid, int type);
1358 static int stac92xx_build_controls(struct hda_codec *codec)
1360 struct sigmatel_spec *spec = codec->spec;
1361 struct auto_pin_cfg *cfg = &spec->autocfg;
1362 hda_nid_t nid;
1363 int err;
1364 int i;
1366 err = snd_hda_add_new_ctls(codec, spec->mixer);
1367 if (err < 0)
1368 return err;
1370 for (i = 0; i < spec->num_mixers; i++) {
1371 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1372 if (err < 0)
1373 return err;
1375 if (spec->num_dmuxes > 0) {
1376 stac_dmux_mixer.count = spec->num_dmuxes;
1377 err = snd_hda_ctl_add(codec,
1378 snd_ctl_new1(&stac_dmux_mixer, codec));
1379 if (err < 0)
1380 return err;
1382 if (spec->num_smuxes > 0) {
1383 int wcaps = get_wcaps(codec, spec->multiout.dig_out_nid);
1384 struct hda_input_mux *smux = &spec->private_smux;
1385 /* check for mute support on SPDIF out */
1386 if (wcaps & AC_WCAP_OUT_AMP) {
1387 smux->items[smux->num_items].label = "Off";
1388 smux->items[smux->num_items].index = 0;
1389 smux->num_items++;
1390 spec->spdif_mute = 1;
1392 stac_smux_mixer.count = spec->num_smuxes;
1393 err = snd_hda_ctl_add(codec,
1394 snd_ctl_new1(&stac_smux_mixer, codec));
1395 if (err < 0)
1396 return err;
1399 if (spec->multiout.dig_out_nid) {
1400 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
1401 if (err < 0)
1402 return err;
1403 err = snd_hda_create_spdif_share_sw(codec,
1404 &spec->multiout);
1405 if (err < 0)
1406 return err;
1407 spec->multiout.share_spdif = 1;
1409 if (spec->dig_in_nid && !(spec->gpio_dir & 0x01)) {
1410 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1411 if (err < 0)
1412 return err;
1415 /* if we have no master control, let's create it */
1416 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
1417 unsigned int vmaster_tlv[4];
1418 snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0],
1419 HDA_OUTPUT, vmaster_tlv);
1420 /* correct volume offset */
1421 vmaster_tlv[2] += vmaster_tlv[3] * spec->volume_offset;
1422 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
1423 vmaster_tlv, slave_vols);
1424 if (err < 0)
1425 return err;
1427 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1428 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1429 NULL, slave_sws);
1430 if (err < 0)
1431 return err;
1434 if (spec->aloopback_ctl &&
1435 snd_hda_get_bool_hint(codec, "loopback") == 1) {
1436 err = snd_hda_add_new_ctls(codec, spec->aloopback_ctl);
1437 if (err < 0)
1438 return err;
1441 stac92xx_free_kctls(codec); /* no longer needed */
1443 /* create jack input elements */
1444 if (spec->hp_detect) {
1445 for (i = 0; i < cfg->hp_outs; i++) {
1446 int type = SND_JACK_HEADPHONE;
1447 nid = cfg->hp_pins[i];
1448 /* jack detection */
1449 if (cfg->hp_outs == i)
1450 type |= SND_JACK_LINEOUT;
1451 err = stac92xx_add_jack(codec, nid, type);
1452 if (err < 0)
1453 return err;
1456 for (i = 0; i < cfg->line_outs; i++) {
1457 err = stac92xx_add_jack(codec, cfg->line_out_pins[i],
1458 SND_JACK_LINEOUT);
1459 if (err < 0)
1460 return err;
1462 for (i = 0; i < AUTO_PIN_LAST; i++) {
1463 nid = cfg->input_pins[i];
1464 if (nid) {
1465 err = stac92xx_add_jack(codec, nid,
1466 SND_JACK_MICROPHONE);
1467 if (err < 0)
1468 return err;
1472 return 0;
1475 static unsigned int ref9200_pin_configs[8] = {
1476 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
1477 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
1480 static unsigned int gateway9200_m4_pin_configs[8] = {
1481 0x400000fe, 0x404500f4, 0x400100f0, 0x90110010,
1482 0x400100f1, 0x02a1902e, 0x500000f2, 0x500000f3,
1484 static unsigned int gateway9200_m4_2_pin_configs[8] = {
1485 0x400000fe, 0x404500f4, 0x400100f0, 0x90110010,
1486 0x400100f1, 0x02a1902e, 0x500000f2, 0x500000f3,
1490 STAC 9200 pin configs for
1491 102801A8
1492 102801DE
1493 102801E8
1495 static unsigned int dell9200_d21_pin_configs[8] = {
1496 0x400001f0, 0x400001f1, 0x02214030, 0x01014010,
1497 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
1501 STAC 9200 pin configs for
1502 102801C0
1503 102801C1
1505 static unsigned int dell9200_d22_pin_configs[8] = {
1506 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
1507 0x01813020, 0x02a19021, 0x90100140, 0x400001f2,
1511 STAC 9200 pin configs for
1512 102801C4 (Dell Dimension E310)
1513 102801C5
1514 102801C7
1515 102801D9
1516 102801DA
1517 102801E3
1519 static unsigned int dell9200_d23_pin_configs[8] = {
1520 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
1521 0x01813020, 0x01a19021, 0x90100140, 0x400001f2,
1526 STAC 9200-32 pin configs for
1527 102801B5 (Dell Inspiron 630m)
1528 102801D8 (Dell Inspiron 640m)
1530 static unsigned int dell9200_m21_pin_configs[8] = {
1531 0x40c003fa, 0x03441340, 0x0321121f, 0x90170310,
1532 0x408003fb, 0x03a11020, 0x401003fc, 0x403003fd,
1536 STAC 9200-32 pin configs for
1537 102801C2 (Dell Latitude D620)
1538 102801C8
1539 102801CC (Dell Latitude D820)
1540 102801D4
1541 102801D6
1543 static unsigned int dell9200_m22_pin_configs[8] = {
1544 0x40c003fa, 0x0144131f, 0x0321121f, 0x90170310,
1545 0x90a70321, 0x03a11020, 0x401003fb, 0x40f000fc,
1549 STAC 9200-32 pin configs for
1550 102801CE (Dell XPS M1710)
1551 102801CF (Dell Precision M90)
1553 static unsigned int dell9200_m23_pin_configs[8] = {
1554 0x40c003fa, 0x01441340, 0x0421421f, 0x90170310,
1555 0x408003fb, 0x04a1102e, 0x90170311, 0x403003fc,
1559 STAC 9200-32 pin configs for
1560 102801C9
1561 102801CA
1562 102801CB (Dell Latitude 120L)
1563 102801D3
1565 static unsigned int dell9200_m24_pin_configs[8] = {
1566 0x40c003fa, 0x404003fb, 0x0321121f, 0x90170310,
1567 0x408003fc, 0x03a11020, 0x401003fd, 0x403003fe,
1571 STAC 9200-32 pin configs for
1572 102801BD (Dell Inspiron E1505n)
1573 102801EE
1574 102801EF
1576 static unsigned int dell9200_m25_pin_configs[8] = {
1577 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
1578 0x408003fb, 0x04a11020, 0x401003fc, 0x403003fd,
1582 STAC 9200-32 pin configs for
1583 102801F5 (Dell Inspiron 1501)
1584 102801F6
1586 static unsigned int dell9200_m26_pin_configs[8] = {
1587 0x40c003fa, 0x404003fb, 0x0421121f, 0x90170310,
1588 0x408003fc, 0x04a11020, 0x401003fd, 0x403003fe,
1592 STAC 9200-32
1593 102801CD (Dell Inspiron E1705/9400)
1595 static unsigned int dell9200_m27_pin_configs[8] = {
1596 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
1597 0x90170310, 0x04a11020, 0x90170310, 0x40f003fc,
1600 static unsigned int oqo9200_pin_configs[8] = {
1601 0x40c000f0, 0x404000f1, 0x0221121f, 0x02211210,
1602 0x90170111, 0x90a70120, 0x400000f2, 0x400000f3,
1606 static unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
1607 [STAC_REF] = ref9200_pin_configs,
1608 [STAC_9200_OQO] = oqo9200_pin_configs,
1609 [STAC_9200_DELL_D21] = dell9200_d21_pin_configs,
1610 [STAC_9200_DELL_D22] = dell9200_d22_pin_configs,
1611 [STAC_9200_DELL_D23] = dell9200_d23_pin_configs,
1612 [STAC_9200_DELL_M21] = dell9200_m21_pin_configs,
1613 [STAC_9200_DELL_M22] = dell9200_m22_pin_configs,
1614 [STAC_9200_DELL_M23] = dell9200_m23_pin_configs,
1615 [STAC_9200_DELL_M24] = dell9200_m24_pin_configs,
1616 [STAC_9200_DELL_M25] = dell9200_m25_pin_configs,
1617 [STAC_9200_DELL_M26] = dell9200_m26_pin_configs,
1618 [STAC_9200_DELL_M27] = dell9200_m27_pin_configs,
1619 [STAC_9200_M4] = gateway9200_m4_pin_configs,
1620 [STAC_9200_M4_2] = gateway9200_m4_2_pin_configs,
1621 [STAC_9200_PANASONIC] = ref9200_pin_configs,
1624 static const char *stac9200_models[STAC_9200_MODELS] = {
1625 [STAC_AUTO] = "auto",
1626 [STAC_REF] = "ref",
1627 [STAC_9200_OQO] = "oqo",
1628 [STAC_9200_DELL_D21] = "dell-d21",
1629 [STAC_9200_DELL_D22] = "dell-d22",
1630 [STAC_9200_DELL_D23] = "dell-d23",
1631 [STAC_9200_DELL_M21] = "dell-m21",
1632 [STAC_9200_DELL_M22] = "dell-m22",
1633 [STAC_9200_DELL_M23] = "dell-m23",
1634 [STAC_9200_DELL_M24] = "dell-m24",
1635 [STAC_9200_DELL_M25] = "dell-m25",
1636 [STAC_9200_DELL_M26] = "dell-m26",
1637 [STAC_9200_DELL_M27] = "dell-m27",
1638 [STAC_9200_M4] = "gateway-m4",
1639 [STAC_9200_M4_2] = "gateway-m4-2",
1640 [STAC_9200_PANASONIC] = "panasonic",
1643 static struct snd_pci_quirk stac9200_cfg_tbl[] = {
1644 /* SigmaTel reference board */
1645 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1646 "DFI LanParty", STAC_REF),
1647 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1648 "DFI LanParty", STAC_REF),
1649 /* Dell laptops have BIOS problem */
1650 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a8,
1651 "unknown Dell", STAC_9200_DELL_D21),
1652 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01b5,
1653 "Dell Inspiron 630m", STAC_9200_DELL_M21),
1654 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bd,
1655 "Dell Inspiron E1505n", STAC_9200_DELL_M25),
1656 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c0,
1657 "unknown Dell", STAC_9200_DELL_D22),
1658 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c1,
1659 "unknown Dell", STAC_9200_DELL_D22),
1660 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c2,
1661 "Dell Latitude D620", STAC_9200_DELL_M22),
1662 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c5,
1663 "unknown Dell", STAC_9200_DELL_D23),
1664 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c7,
1665 "unknown Dell", STAC_9200_DELL_D23),
1666 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c8,
1667 "unknown Dell", STAC_9200_DELL_M22),
1668 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c9,
1669 "unknown Dell", STAC_9200_DELL_M24),
1670 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ca,
1671 "unknown Dell", STAC_9200_DELL_M24),
1672 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cb,
1673 "Dell Latitude 120L", STAC_9200_DELL_M24),
1674 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cc,
1675 "Dell Latitude D820", STAC_9200_DELL_M22),
1676 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cd,
1677 "Dell Inspiron E1705/9400", STAC_9200_DELL_M27),
1678 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ce,
1679 "Dell XPS M1710", STAC_9200_DELL_M23),
1680 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cf,
1681 "Dell Precision M90", STAC_9200_DELL_M23),
1682 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d3,
1683 "unknown Dell", STAC_9200_DELL_M22),
1684 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d4,
1685 "unknown Dell", STAC_9200_DELL_M22),
1686 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d6,
1687 "unknown Dell", STAC_9200_DELL_M22),
1688 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d8,
1689 "Dell Inspiron 640m", STAC_9200_DELL_M21),
1690 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d9,
1691 "unknown Dell", STAC_9200_DELL_D23),
1692 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01da,
1693 "unknown Dell", STAC_9200_DELL_D23),
1694 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01de,
1695 "unknown Dell", STAC_9200_DELL_D21),
1696 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e3,
1697 "unknown Dell", STAC_9200_DELL_D23),
1698 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e8,
1699 "unknown Dell", STAC_9200_DELL_D21),
1700 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ee,
1701 "unknown Dell", STAC_9200_DELL_M25),
1702 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ef,
1703 "unknown Dell", STAC_9200_DELL_M25),
1704 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f5,
1705 "Dell Inspiron 1501", STAC_9200_DELL_M26),
1706 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f6,
1707 "unknown Dell", STAC_9200_DELL_M26),
1708 /* Panasonic */
1709 SND_PCI_QUIRK(0x10f7, 0x8338, "Panasonic CF-74", STAC_9200_PANASONIC),
1710 /* Gateway machines needs EAPD to be set on resume */
1711 SND_PCI_QUIRK(0x107b, 0x0205, "Gateway S-7110M", STAC_9200_M4),
1712 SND_PCI_QUIRK(0x107b, 0x0317, "Gateway MT3423, MX341*", STAC_9200_M4_2),
1713 SND_PCI_QUIRK(0x107b, 0x0318, "Gateway ML3019, MT3707", STAC_9200_M4_2),
1714 /* OQO Mobile */
1715 SND_PCI_QUIRK(0x1106, 0x3288, "OQO Model 2", STAC_9200_OQO),
1716 {} /* terminator */
1719 static unsigned int ref925x_pin_configs[8] = {
1720 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
1721 0x90a70320, 0x02214210, 0x01019020, 0x9033032e,
1724 static unsigned int stac925xM1_pin_configs[8] = {
1725 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1726 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1729 static unsigned int stac925xM1_2_pin_configs[8] = {
1730 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1731 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1734 static unsigned int stac925xM2_pin_configs[8] = {
1735 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1736 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1739 static unsigned int stac925xM2_2_pin_configs[8] = {
1740 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1741 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1744 static unsigned int stac925xM3_pin_configs[8] = {
1745 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1746 0x40a000f0, 0x90100210, 0x400003f1, 0x503303f3,
1749 static unsigned int stac925xM5_pin_configs[8] = {
1750 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1751 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1754 static unsigned int stac925xM6_pin_configs[8] = {
1755 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1756 0x40a000f0, 0x90100210, 0x400003f1, 0x90330320,
1759 static unsigned int *stac925x_brd_tbl[STAC_925x_MODELS] = {
1760 [STAC_REF] = ref925x_pin_configs,
1761 [STAC_M1] = stac925xM1_pin_configs,
1762 [STAC_M1_2] = stac925xM1_2_pin_configs,
1763 [STAC_M2] = stac925xM2_pin_configs,
1764 [STAC_M2_2] = stac925xM2_2_pin_configs,
1765 [STAC_M3] = stac925xM3_pin_configs,
1766 [STAC_M5] = stac925xM5_pin_configs,
1767 [STAC_M6] = stac925xM6_pin_configs,
1770 static const char *stac925x_models[STAC_925x_MODELS] = {
1771 [STAC_925x_AUTO] = "auto",
1772 [STAC_REF] = "ref",
1773 [STAC_M1] = "m1",
1774 [STAC_M1_2] = "m1-2",
1775 [STAC_M2] = "m2",
1776 [STAC_M2_2] = "m2-2",
1777 [STAC_M3] = "m3",
1778 [STAC_M5] = "m5",
1779 [STAC_M6] = "m6",
1782 static struct snd_pci_quirk stac925x_codec_id_cfg_tbl[] = {
1783 SND_PCI_QUIRK(0x107b, 0x0316, "Gateway M255", STAC_M2),
1784 SND_PCI_QUIRK(0x107b, 0x0366, "Gateway MP6954", STAC_M5),
1785 SND_PCI_QUIRK(0x107b, 0x0461, "Gateway NX560XL", STAC_M1),
1786 SND_PCI_QUIRK(0x107b, 0x0681, "Gateway NX860", STAC_M2),
1787 SND_PCI_QUIRK(0x107b, 0x0367, "Gateway MX6453", STAC_M1_2),
1788 /* Not sure about the brand name for those */
1789 SND_PCI_QUIRK(0x107b, 0x0281, "Gateway mobile", STAC_M1),
1790 SND_PCI_QUIRK(0x107b, 0x0507, "Gateway mobile", STAC_M3),
1791 SND_PCI_QUIRK(0x107b, 0x0281, "Gateway mobile", STAC_M6),
1792 SND_PCI_QUIRK(0x107b, 0x0685, "Gateway mobile", STAC_M2_2),
1793 {} /* terminator */
1796 static struct snd_pci_quirk stac925x_cfg_tbl[] = {
1797 /* SigmaTel reference board */
1798 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, "DFI LanParty", STAC_REF),
1799 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101, "DFI LanParty", STAC_REF),
1800 SND_PCI_QUIRK(0x8384, 0x7632, "Stac9202 Reference Board", STAC_REF),
1802 /* Default table for unknown ID */
1803 SND_PCI_QUIRK(0x1002, 0x437b, "Gateway mobile", STAC_M2_2),
1805 {} /* terminator */
1808 static unsigned int ref92hd73xx_pin_configs[13] = {
1809 0x02214030, 0x02a19040, 0x01a19020, 0x02214030,
1810 0x0181302e, 0x01014010, 0x01014020, 0x01014030,
1811 0x02319040, 0x90a000f0, 0x90a000f0, 0x01452050,
1812 0x01452050,
1815 static unsigned int dell_m6_pin_configs[13] = {
1816 0x0321101f, 0x4f00000f, 0x4f0000f0, 0x90170110,
1817 0x03a11020, 0x0321101f, 0x4f0000f0, 0x4f0000f0,
1818 0x4f0000f0, 0x90a60160, 0x4f0000f0, 0x4f0000f0,
1819 0x4f0000f0,
1822 static unsigned int *stac92hd73xx_brd_tbl[STAC_92HD73XX_MODELS] = {
1823 [STAC_92HD73XX_REF] = ref92hd73xx_pin_configs,
1824 [STAC_DELL_M6_AMIC] = dell_m6_pin_configs,
1825 [STAC_DELL_M6_DMIC] = dell_m6_pin_configs,
1826 [STAC_DELL_M6_BOTH] = dell_m6_pin_configs,
1827 [STAC_DELL_EQ] = dell_m6_pin_configs,
1830 static const char *stac92hd73xx_models[STAC_92HD73XX_MODELS] = {
1831 [STAC_92HD73XX_AUTO] = "auto",
1832 [STAC_92HD73XX_NO_JD] = "no-jd",
1833 [STAC_92HD73XX_REF] = "ref",
1834 [STAC_DELL_M6_AMIC] = "dell-m6-amic",
1835 [STAC_DELL_M6_DMIC] = "dell-m6-dmic",
1836 [STAC_DELL_M6_BOTH] = "dell-m6",
1837 [STAC_DELL_EQ] = "dell-eq",
1840 static struct snd_pci_quirk stac92hd73xx_cfg_tbl[] = {
1841 /* SigmaTel reference board */
1842 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1843 "DFI LanParty", STAC_92HD73XX_REF),
1844 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1845 "DFI LanParty", STAC_92HD73XX_REF),
1846 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0254,
1847 "Dell Studio 1535", STAC_DELL_M6_DMIC),
1848 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0255,
1849 "unknown Dell", STAC_DELL_M6_DMIC),
1850 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0256,
1851 "unknown Dell", STAC_DELL_M6_BOTH),
1852 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0257,
1853 "unknown Dell", STAC_DELL_M6_BOTH),
1854 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025e,
1855 "unknown Dell", STAC_DELL_M6_AMIC),
1856 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025f,
1857 "unknown Dell", STAC_DELL_M6_AMIC),
1858 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0271,
1859 "unknown Dell", STAC_DELL_M6_DMIC),
1860 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0272,
1861 "unknown Dell", STAC_DELL_M6_DMIC),
1862 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x029f,
1863 "Dell Studio 1537", STAC_DELL_M6_DMIC),
1864 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02a0,
1865 "Dell Studio 17", STAC_DELL_M6_DMIC),
1866 {} /* terminator */
1869 static unsigned int ref92hd83xxx_pin_configs[10] = {
1870 0x02214030, 0x02211010, 0x02a19020, 0x02170130,
1871 0x01014050, 0x01819040, 0x01014020, 0x90a3014e,
1872 0x01451160, 0x98560170,
1875 static unsigned int dell_s14_pin_configs[10] = {
1876 0x02214030, 0x02211010, 0x02a19020, 0x01014050,
1877 0x40f000f0, 0x01819040, 0x40f000f0, 0x90a60160,
1878 0x40f000f0, 0x40f000f0,
1881 static unsigned int *stac92hd83xxx_brd_tbl[STAC_92HD83XXX_MODELS] = {
1882 [STAC_92HD83XXX_REF] = ref92hd83xxx_pin_configs,
1883 [STAC_92HD83XXX_PWR_REF] = ref92hd83xxx_pin_configs,
1884 [STAC_DELL_S14] = dell_s14_pin_configs,
1887 static const char *stac92hd83xxx_models[STAC_92HD83XXX_MODELS] = {
1888 [STAC_92HD83XXX_AUTO] = "auto",
1889 [STAC_92HD83XXX_REF] = "ref",
1890 [STAC_92HD83XXX_PWR_REF] = "mic-ref",
1891 [STAC_DELL_S14] = "dell-s14",
1894 static struct snd_pci_quirk stac92hd83xxx_cfg_tbl[] = {
1895 /* SigmaTel reference board */
1896 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1897 "DFI LanParty", STAC_92HD83XXX_REF),
1898 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1899 "DFI LanParty", STAC_92HD83XXX_REF),
1900 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ba,
1901 "unknown Dell", STAC_DELL_S14),
1902 {} /* terminator */
1905 static unsigned int ref92hd71bxx_pin_configs[STAC92HD71BXX_NUM_PINS] = {
1906 0x02214030, 0x02a19040, 0x01a19020, 0x01014010,
1907 0x0181302e, 0x01014010, 0x01019020, 0x90a000f0,
1908 0x90a000f0, 0x01452050, 0x01452050, 0x00000000,
1909 0x00000000
1912 static unsigned int dell_m4_1_pin_configs[STAC92HD71BXX_NUM_PINS] = {
1913 0x0421101f, 0x04a11221, 0x40f000f0, 0x90170110,
1914 0x23a1902e, 0x23014250, 0x40f000f0, 0x90a000f0,
1915 0x40f000f0, 0x4f0000f0, 0x4f0000f0, 0x00000000,
1916 0x00000000
1919 static unsigned int dell_m4_2_pin_configs[STAC92HD71BXX_NUM_PINS] = {
1920 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1921 0x23a1902e, 0x23014250, 0x40f000f0, 0x40f000f0,
1922 0x40f000f0, 0x044413b0, 0x044413b0, 0x00000000,
1923 0x00000000
1926 static unsigned int dell_m4_3_pin_configs[STAC92HD71BXX_NUM_PINS] = {
1927 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1928 0x40f000f0, 0x40f000f0, 0x40f000f0, 0x90a000f0,
1929 0x40f000f0, 0x044413b0, 0x044413b0, 0x00000000,
1930 0x00000000
1933 static unsigned int *stac92hd71bxx_brd_tbl[STAC_92HD71BXX_MODELS] = {
1934 [STAC_92HD71BXX_REF] = ref92hd71bxx_pin_configs,
1935 [STAC_DELL_M4_1] = dell_m4_1_pin_configs,
1936 [STAC_DELL_M4_2] = dell_m4_2_pin_configs,
1937 [STAC_DELL_M4_3] = dell_m4_3_pin_configs,
1938 [STAC_HP_M4] = NULL,
1939 [STAC_HP_DV5] = NULL,
1940 [STAC_HP_HDX] = NULL,
1941 [STAC_HP_DV4_1222NR] = NULL,
1944 static const char *stac92hd71bxx_models[STAC_92HD71BXX_MODELS] = {
1945 [STAC_92HD71BXX_AUTO] = "auto",
1946 [STAC_92HD71BXX_REF] = "ref",
1947 [STAC_DELL_M4_1] = "dell-m4-1",
1948 [STAC_DELL_M4_2] = "dell-m4-2",
1949 [STAC_DELL_M4_3] = "dell-m4-3",
1950 [STAC_HP_M4] = "hp-m4",
1951 [STAC_HP_DV5] = "hp-dv5",
1952 [STAC_HP_HDX] = "hp-hdx",
1953 [STAC_HP_DV4_1222NR] = "hp-dv4-1222nr",
1956 static struct snd_pci_quirk stac92hd71bxx_cfg_tbl[] = {
1957 /* SigmaTel reference board */
1958 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1959 "DFI LanParty", STAC_92HD71BXX_REF),
1960 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1961 "DFI LanParty", STAC_92HD71BXX_REF),
1962 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x30fb,
1963 "HP dv4-1222nr", STAC_HP_DV4_1222NR),
1964 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3080,
1965 "HP", STAC_HP_DV5),
1966 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x30f0,
1967 "HP dv4-7", STAC_HP_DV5),
1968 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3600,
1969 "HP dv4-7", STAC_HP_DV5),
1970 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3610,
1971 "HP HDX", STAC_HP_HDX), /* HDX18 */
1972 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361a,
1973 "HP mini 1000", STAC_HP_M4),
1974 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361b,
1975 "HP HDX", STAC_HP_HDX), /* HDX16 */
1976 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0233,
1977 "unknown Dell", STAC_DELL_M4_1),
1978 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0234,
1979 "unknown Dell", STAC_DELL_M4_1),
1980 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0250,
1981 "unknown Dell", STAC_DELL_M4_1),
1982 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024f,
1983 "unknown Dell", STAC_DELL_M4_1),
1984 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024d,
1985 "unknown Dell", STAC_DELL_M4_1),
1986 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0251,
1987 "unknown Dell", STAC_DELL_M4_1),
1988 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0277,
1989 "unknown Dell", STAC_DELL_M4_1),
1990 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0263,
1991 "unknown Dell", STAC_DELL_M4_2),
1992 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0265,
1993 "unknown Dell", STAC_DELL_M4_2),
1994 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0262,
1995 "unknown Dell", STAC_DELL_M4_2),
1996 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0264,
1997 "unknown Dell", STAC_DELL_M4_2),
1998 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02aa,
1999 "unknown Dell", STAC_DELL_M4_3),
2000 {} /* terminator */
2003 static unsigned int ref922x_pin_configs[10] = {
2004 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
2005 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
2006 0x40000100, 0x40000100,
2010 STAC 922X pin configs for
2011 102801A7
2012 102801AB
2013 102801A9
2014 102801D1
2015 102801D2
2017 static unsigned int dell_922x_d81_pin_configs[10] = {
2018 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
2019 0x02a19020, 0x01117011, 0x400001f0, 0x400001f1,
2020 0x01813122, 0x400001f2,
2024 STAC 922X pin configs for
2025 102801AC
2026 102801D0
2028 static unsigned int dell_922x_d82_pin_configs[10] = {
2029 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
2030 0x02a19020, 0x01117011, 0x01451140, 0x400001f0,
2031 0x01813122, 0x400001f1,
2035 STAC 922X pin configs for
2036 102801BF
2038 static unsigned int dell_922x_m81_pin_configs[10] = {
2039 0x0321101f, 0x01112024, 0x01111222, 0x91174220,
2040 0x03a11050, 0x01116221, 0x90a70330, 0x01452340,
2041 0x40C003f1, 0x405003f0,
2045 STAC 9221 A1 pin configs for
2046 102801D7 (Dell XPS M1210)
2048 static unsigned int dell_922x_m82_pin_configs[10] = {
2049 0x02211211, 0x408103ff, 0x02a1123e, 0x90100310,
2050 0x408003f1, 0x0221121f, 0x03451340, 0x40c003f2,
2051 0x508003f3, 0x405003f4,
2054 static unsigned int d945gtp3_pin_configs[10] = {
2055 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
2056 0x40000100, 0x40000100, 0x40000100, 0x40000100,
2057 0x02a19120, 0x40000100,
2060 static unsigned int d945gtp5_pin_configs[10] = {
2061 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
2062 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
2063 0x02a19320, 0x40000100,
2066 static unsigned int intel_mac_v1_pin_configs[10] = {
2067 0x0121e21f, 0x400000ff, 0x9017e110, 0x400000fd,
2068 0x400000fe, 0x0181e020, 0x1145e030, 0x11c5e240,
2069 0x400000fc, 0x400000fb,
2072 static unsigned int intel_mac_v2_pin_configs[10] = {
2073 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
2074 0x400000fe, 0x0181e020, 0x1145e230, 0x500000fa,
2075 0x400000fc, 0x400000fb,
2078 static unsigned int intel_mac_v3_pin_configs[10] = {
2079 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
2080 0x400000fe, 0x0181e020, 0x1145e230, 0x11c5e240,
2081 0x400000fc, 0x400000fb,
2084 static unsigned int intel_mac_v4_pin_configs[10] = {
2085 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
2086 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
2087 0x400000fc, 0x400000fb,
2090 static unsigned int intel_mac_v5_pin_configs[10] = {
2091 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
2092 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
2093 0x400000fc, 0x400000fb,
2096 static unsigned int ecs202_pin_configs[10] = {
2097 0x0221401f, 0x02a19020, 0x01a19020, 0x01114010,
2098 0x408000f0, 0x01813022, 0x074510a0, 0x40c400f1,
2099 0x9037012e, 0x40e000f2,
2102 static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
2103 [STAC_D945_REF] = ref922x_pin_configs,
2104 [STAC_D945GTP3] = d945gtp3_pin_configs,
2105 [STAC_D945GTP5] = d945gtp5_pin_configs,
2106 [STAC_INTEL_MAC_V1] = intel_mac_v1_pin_configs,
2107 [STAC_INTEL_MAC_V2] = intel_mac_v2_pin_configs,
2108 [STAC_INTEL_MAC_V3] = intel_mac_v3_pin_configs,
2109 [STAC_INTEL_MAC_V4] = intel_mac_v4_pin_configs,
2110 [STAC_INTEL_MAC_V5] = intel_mac_v5_pin_configs,
2111 [STAC_INTEL_MAC_AUTO] = intel_mac_v3_pin_configs,
2112 /* for backward compatibility */
2113 [STAC_MACMINI] = intel_mac_v3_pin_configs,
2114 [STAC_MACBOOK] = intel_mac_v5_pin_configs,
2115 [STAC_MACBOOK_PRO_V1] = intel_mac_v3_pin_configs,
2116 [STAC_MACBOOK_PRO_V2] = intel_mac_v3_pin_configs,
2117 [STAC_IMAC_INTEL] = intel_mac_v2_pin_configs,
2118 [STAC_IMAC_INTEL_20] = intel_mac_v3_pin_configs,
2119 [STAC_ECS_202] = ecs202_pin_configs,
2120 [STAC_922X_DELL_D81] = dell_922x_d81_pin_configs,
2121 [STAC_922X_DELL_D82] = dell_922x_d82_pin_configs,
2122 [STAC_922X_DELL_M81] = dell_922x_m81_pin_configs,
2123 [STAC_922X_DELL_M82] = dell_922x_m82_pin_configs,
2126 static const char *stac922x_models[STAC_922X_MODELS] = {
2127 [STAC_922X_AUTO] = "auto",
2128 [STAC_D945_REF] = "ref",
2129 [STAC_D945GTP5] = "5stack",
2130 [STAC_D945GTP3] = "3stack",
2131 [STAC_INTEL_MAC_V1] = "intel-mac-v1",
2132 [STAC_INTEL_MAC_V2] = "intel-mac-v2",
2133 [STAC_INTEL_MAC_V3] = "intel-mac-v3",
2134 [STAC_INTEL_MAC_V4] = "intel-mac-v4",
2135 [STAC_INTEL_MAC_V5] = "intel-mac-v5",
2136 [STAC_INTEL_MAC_AUTO] = "intel-mac-auto",
2137 /* for backward compatibility */
2138 [STAC_MACMINI] = "macmini",
2139 [STAC_MACBOOK] = "macbook",
2140 [STAC_MACBOOK_PRO_V1] = "macbook-pro-v1",
2141 [STAC_MACBOOK_PRO_V2] = "macbook-pro",
2142 [STAC_IMAC_INTEL] = "imac-intel",
2143 [STAC_IMAC_INTEL_20] = "imac-intel-20",
2144 [STAC_ECS_202] = "ecs202",
2145 [STAC_922X_DELL_D81] = "dell-d81",
2146 [STAC_922X_DELL_D82] = "dell-d82",
2147 [STAC_922X_DELL_M81] = "dell-m81",
2148 [STAC_922X_DELL_M82] = "dell-m82",
2151 static struct snd_pci_quirk stac922x_cfg_tbl[] = {
2152 /* SigmaTel reference board */
2153 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2154 "DFI LanParty", STAC_D945_REF),
2155 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2156 "DFI LanParty", STAC_D945_REF),
2157 /* Intel 945G based systems */
2158 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101,
2159 "Intel D945G", STAC_D945GTP3),
2160 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0202,
2161 "Intel D945G", STAC_D945GTP3),
2162 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0606,
2163 "Intel D945G", STAC_D945GTP3),
2164 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0601,
2165 "Intel D945G", STAC_D945GTP3),
2166 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0111,
2167 "Intel D945G", STAC_D945GTP3),
2168 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1115,
2169 "Intel D945G", STAC_D945GTP3),
2170 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1116,
2171 "Intel D945G", STAC_D945GTP3),
2172 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1117,
2173 "Intel D945G", STAC_D945GTP3),
2174 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1118,
2175 "Intel D945G", STAC_D945GTP3),
2176 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1119,
2177 "Intel D945G", STAC_D945GTP3),
2178 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x8826,
2179 "Intel D945G", STAC_D945GTP3),
2180 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5049,
2181 "Intel D945G", STAC_D945GTP3),
2182 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5055,
2183 "Intel D945G", STAC_D945GTP3),
2184 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5048,
2185 "Intel D945G", STAC_D945GTP3),
2186 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0110,
2187 "Intel D945G", STAC_D945GTP3),
2188 /* Intel D945G 5-stack systems */
2189 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0404,
2190 "Intel D945G", STAC_D945GTP5),
2191 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0303,
2192 "Intel D945G", STAC_D945GTP5),
2193 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0013,
2194 "Intel D945G", STAC_D945GTP5),
2195 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0417,
2196 "Intel D945G", STAC_D945GTP5),
2197 /* Intel 945P based systems */
2198 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0b0b,
2199 "Intel D945P", STAC_D945GTP3),
2200 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0112,
2201 "Intel D945P", STAC_D945GTP3),
2202 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0d0d,
2203 "Intel D945P", STAC_D945GTP3),
2204 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0909,
2205 "Intel D945P", STAC_D945GTP3),
2206 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0505,
2207 "Intel D945P", STAC_D945GTP3),
2208 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707,
2209 "Intel D945P", STAC_D945GTP5),
2210 /* other intel */
2211 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0204,
2212 "Intel D945", STAC_D945_REF),
2213 /* other systems */
2214 /* Apple Intel Mac (Mac Mini, MacBook, MacBook Pro...) */
2215 SND_PCI_QUIRK(0x8384, 0x7680,
2216 "Mac", STAC_INTEL_MAC_AUTO),
2217 /* Dell systems */
2218 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a7,
2219 "unknown Dell", STAC_922X_DELL_D81),
2220 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a9,
2221 "unknown Dell", STAC_922X_DELL_D81),
2222 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ab,
2223 "unknown Dell", STAC_922X_DELL_D81),
2224 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ac,
2225 "unknown Dell", STAC_922X_DELL_D82),
2226 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bf,
2227 "unknown Dell", STAC_922X_DELL_M81),
2228 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d0,
2229 "unknown Dell", STAC_922X_DELL_D82),
2230 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d1,
2231 "unknown Dell", STAC_922X_DELL_D81),
2232 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d2,
2233 "unknown Dell", STAC_922X_DELL_D81),
2234 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d7,
2235 "Dell XPS M1210", STAC_922X_DELL_M82),
2236 /* ECS/PC Chips boards */
2237 SND_PCI_QUIRK_MASK(0x1019, 0xf000, 0x2000,
2238 "ECS/PC chips", STAC_ECS_202),
2239 {} /* terminator */
2242 static unsigned int ref927x_pin_configs[14] = {
2243 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2244 0x01a19040, 0x01011012, 0x01016011, 0x0101201f,
2245 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
2246 0x01c42190, 0x40000100,
2249 static unsigned int d965_3st_pin_configs[14] = {
2250 0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
2251 0x01a19021, 0x01813024, 0x40000100, 0x40000100,
2252 0x40000100, 0x40000100, 0x40000100, 0x40000100,
2253 0x40000100, 0x40000100
2256 static unsigned int d965_5st_pin_configs[14] = {
2257 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2258 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
2259 0x40000100, 0x40000100, 0x40000100, 0x01442070,
2260 0x40000100, 0x40000100
2263 static unsigned int dell_3st_pin_configs[14] = {
2264 0x02211230, 0x02a11220, 0x01a19040, 0x01114210,
2265 0x01111212, 0x01116211, 0x01813050, 0x01112214,
2266 0x403003fa, 0x90a60040, 0x90a60040, 0x404003fb,
2267 0x40c003fc, 0x40000100
2270 static unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
2271 [STAC_D965_REF_NO_JD] = ref927x_pin_configs,
2272 [STAC_D965_REF] = ref927x_pin_configs,
2273 [STAC_D965_3ST] = d965_3st_pin_configs,
2274 [STAC_D965_5ST] = d965_5st_pin_configs,
2275 [STAC_DELL_3ST] = dell_3st_pin_configs,
2276 [STAC_DELL_BIOS] = NULL,
2279 static const char *stac927x_models[STAC_927X_MODELS] = {
2280 [STAC_927X_AUTO] = "auto",
2281 [STAC_D965_REF_NO_JD] = "ref-no-jd",
2282 [STAC_D965_REF] = "ref",
2283 [STAC_D965_3ST] = "3stack",
2284 [STAC_D965_5ST] = "5stack",
2285 [STAC_DELL_3ST] = "dell-3stack",
2286 [STAC_DELL_BIOS] = "dell-bios",
2289 static struct snd_pci_quirk stac927x_cfg_tbl[] = {
2290 /* SigmaTel reference board */
2291 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2292 "DFI LanParty", STAC_D965_REF),
2293 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2294 "DFI LanParty", STAC_D965_REF),
2295 /* Intel 946 based systems */
2296 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST),
2297 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST),
2298 /* 965 based 3 stack systems */
2299 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2100,
2300 "Intel D965", STAC_D965_3ST),
2301 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2000,
2302 "Intel D965", STAC_D965_3ST),
2303 /* Dell 3 stack systems */
2304 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f7, "Dell XPS M1730", STAC_DELL_3ST),
2305 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01dd, "Dell Dimension E520", STAC_DELL_3ST),
2306 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ed, "Dell ", STAC_DELL_3ST),
2307 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f4, "Dell ", STAC_DELL_3ST),
2308 /* Dell 3 stack systems with verb table in BIOS */
2309 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f3, "Dell Inspiron 1420", STAC_DELL_BIOS),
2310 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0227, "Dell Vostro 1400 ", STAC_DELL_BIOS),
2311 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022e, "Dell ", STAC_DELL_BIOS),
2312 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022f, "Dell Inspiron 1525", STAC_DELL_3ST),
2313 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0242, "Dell ", STAC_DELL_BIOS),
2314 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0243, "Dell ", STAC_DELL_BIOS),
2315 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ff, "Dell ", STAC_DELL_BIOS),
2316 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0209, "Dell XPS 1330", STAC_DELL_BIOS),
2317 /* 965 based 5 stack systems */
2318 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2300,
2319 "Intel D965", STAC_D965_5ST),
2320 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2500,
2321 "Intel D965", STAC_D965_5ST),
2322 {} /* terminator */
2325 static unsigned int ref9205_pin_configs[12] = {
2326 0x40000100, 0x40000100, 0x01016011, 0x01014010,
2327 0x01813122, 0x01a19021, 0x01019020, 0x40000100,
2328 0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
2332 STAC 9205 pin configs for
2333 102801F1
2334 102801F2
2335 102801FC
2336 102801FD
2337 10280204
2338 1028021F
2339 10280228 (Dell Vostro 1500)
2341 static unsigned int dell_9205_m42_pin_configs[12] = {
2342 0x0321101F, 0x03A11020, 0x400003FA, 0x90170310,
2343 0x400003FB, 0x400003FC, 0x400003FD, 0x40F000F9,
2344 0x90A60330, 0x400003FF, 0x0144131F, 0x40C003FE,
2348 STAC 9205 pin configs for
2349 102801F9
2350 102801FA
2351 102801FE
2352 102801FF (Dell Precision M4300)
2353 10280206
2354 10280200
2355 10280201
2357 static unsigned int dell_9205_m43_pin_configs[12] = {
2358 0x0321101f, 0x03a11020, 0x90a70330, 0x90170310,
2359 0x400000fe, 0x400000ff, 0x400000fd, 0x40f000f9,
2360 0x400000fa, 0x400000fc, 0x0144131f, 0x40c003f8,
2363 static unsigned int dell_9205_m44_pin_configs[12] = {
2364 0x0421101f, 0x04a11020, 0x400003fa, 0x90170310,
2365 0x400003fb, 0x400003fc, 0x400003fd, 0x400003f9,
2366 0x90a60330, 0x400003ff, 0x01441340, 0x40c003fe,
2369 static unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
2370 [STAC_9205_REF] = ref9205_pin_configs,
2371 [STAC_9205_DELL_M42] = dell_9205_m42_pin_configs,
2372 [STAC_9205_DELL_M43] = dell_9205_m43_pin_configs,
2373 [STAC_9205_DELL_M44] = dell_9205_m44_pin_configs,
2374 [STAC_9205_EAPD] = NULL,
2377 static const char *stac9205_models[STAC_9205_MODELS] = {
2378 [STAC_9205_AUTO] = "auto",
2379 [STAC_9205_REF] = "ref",
2380 [STAC_9205_DELL_M42] = "dell-m42",
2381 [STAC_9205_DELL_M43] = "dell-m43",
2382 [STAC_9205_DELL_M44] = "dell-m44",
2383 [STAC_9205_EAPD] = "eapd",
2386 static struct snd_pci_quirk stac9205_cfg_tbl[] = {
2387 /* SigmaTel reference board */
2388 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2389 "DFI LanParty", STAC_9205_REF),
2390 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2391 "DFI LanParty", STAC_9205_REF),
2392 /* Dell */
2393 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f1,
2394 "unknown Dell", STAC_9205_DELL_M42),
2395 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f2,
2396 "unknown Dell", STAC_9205_DELL_M42),
2397 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f8,
2398 "Dell Precision", STAC_9205_DELL_M43),
2399 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f9,
2400 "Dell Precision", STAC_9205_DELL_M43),
2401 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fa,
2402 "Dell Precision", STAC_9205_DELL_M43),
2403 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fc,
2404 "unknown Dell", STAC_9205_DELL_M42),
2405 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fd,
2406 "unknown Dell", STAC_9205_DELL_M42),
2407 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fe,
2408 "Dell Precision", STAC_9205_DELL_M43),
2409 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ff,
2410 "Dell Precision M4300", STAC_9205_DELL_M43),
2411 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0204,
2412 "unknown Dell", STAC_9205_DELL_M42),
2413 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0206,
2414 "Dell Precision", STAC_9205_DELL_M43),
2415 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021b,
2416 "Dell Precision", STAC_9205_DELL_M43),
2417 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021c,
2418 "Dell Precision", STAC_9205_DELL_M43),
2419 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021f,
2420 "Dell Inspiron", STAC_9205_DELL_M44),
2421 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0228,
2422 "Dell Vostro 1500", STAC_9205_DELL_M42),
2423 /* Gateway */
2424 SND_PCI_QUIRK(0x107b, 0x0565, "Gateway T1616", STAC_9205_EAPD),
2425 {} /* terminator */
2428 static void stac92xx_set_config_regs(struct hda_codec *codec,
2429 unsigned int *pincfgs)
2431 int i;
2432 struct sigmatel_spec *spec = codec->spec;
2434 if (!pincfgs)
2435 return;
2437 for (i = 0; i < spec->num_pins; i++)
2438 if (spec->pin_nids[i] && pincfgs[i])
2439 snd_hda_codec_set_pincfg(codec, spec->pin_nids[i],
2440 pincfgs[i]);
2444 * Analog playback callbacks
2446 static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
2447 struct hda_codec *codec,
2448 struct snd_pcm_substream *substream)
2450 struct sigmatel_spec *spec = codec->spec;
2451 if (spec->stream_delay)
2452 msleep(spec->stream_delay);
2453 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2454 hinfo);
2457 static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2458 struct hda_codec *codec,
2459 unsigned int stream_tag,
2460 unsigned int format,
2461 struct snd_pcm_substream *substream)
2463 struct sigmatel_spec *spec = codec->spec;
2464 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
2467 static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2468 struct hda_codec *codec,
2469 struct snd_pcm_substream *substream)
2471 struct sigmatel_spec *spec = codec->spec;
2472 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2476 * Digital playback callbacks
2478 static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2479 struct hda_codec *codec,
2480 struct snd_pcm_substream *substream)
2482 struct sigmatel_spec *spec = codec->spec;
2483 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2486 static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2487 struct hda_codec *codec,
2488 struct snd_pcm_substream *substream)
2490 struct sigmatel_spec *spec = codec->spec;
2491 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2494 static int stac92xx_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2495 struct hda_codec *codec,
2496 unsigned int stream_tag,
2497 unsigned int format,
2498 struct snd_pcm_substream *substream)
2500 struct sigmatel_spec *spec = codec->spec;
2501 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2502 stream_tag, format, substream);
2505 static int stac92xx_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2506 struct hda_codec *codec,
2507 struct snd_pcm_substream *substream)
2509 struct sigmatel_spec *spec = codec->spec;
2510 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2515 * Analog capture callbacks
2517 static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2518 struct hda_codec *codec,
2519 unsigned int stream_tag,
2520 unsigned int format,
2521 struct snd_pcm_substream *substream)
2523 struct sigmatel_spec *spec = codec->spec;
2524 hda_nid_t nid = spec->adc_nids[substream->number];
2526 if (spec->powerdown_adcs) {
2527 msleep(40);
2528 snd_hda_codec_write(codec, nid, 0,
2529 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
2531 snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format);
2532 return 0;
2535 static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2536 struct hda_codec *codec,
2537 struct snd_pcm_substream *substream)
2539 struct sigmatel_spec *spec = codec->spec;
2540 hda_nid_t nid = spec->adc_nids[substream->number];
2542 snd_hda_codec_cleanup_stream(codec, nid);
2543 if (spec->powerdown_adcs)
2544 snd_hda_codec_write(codec, nid, 0,
2545 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
2546 return 0;
2549 static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
2550 .substreams = 1,
2551 .channels_min = 2,
2552 .channels_max = 2,
2553 /* NID is set in stac92xx_build_pcms */
2554 .ops = {
2555 .open = stac92xx_dig_playback_pcm_open,
2556 .close = stac92xx_dig_playback_pcm_close,
2557 .prepare = stac92xx_dig_playback_pcm_prepare,
2558 .cleanup = stac92xx_dig_playback_pcm_cleanup
2562 static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
2563 .substreams = 1,
2564 .channels_min = 2,
2565 .channels_max = 2,
2566 /* NID is set in stac92xx_build_pcms */
2569 static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
2570 .substreams = 1,
2571 .channels_min = 2,
2572 .channels_max = 8,
2573 .nid = 0x02, /* NID to query formats and rates */
2574 .ops = {
2575 .open = stac92xx_playback_pcm_open,
2576 .prepare = stac92xx_playback_pcm_prepare,
2577 .cleanup = stac92xx_playback_pcm_cleanup
2581 static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
2582 .substreams = 1,
2583 .channels_min = 2,
2584 .channels_max = 2,
2585 .nid = 0x06, /* NID to query formats and rates */
2586 .ops = {
2587 .open = stac92xx_playback_pcm_open,
2588 .prepare = stac92xx_playback_pcm_prepare,
2589 .cleanup = stac92xx_playback_pcm_cleanup
2593 static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
2594 .channels_min = 2,
2595 .channels_max = 2,
2596 /* NID + .substreams is set in stac92xx_build_pcms */
2597 .ops = {
2598 .prepare = stac92xx_capture_pcm_prepare,
2599 .cleanup = stac92xx_capture_pcm_cleanup
2603 static int stac92xx_build_pcms(struct hda_codec *codec)
2605 struct sigmatel_spec *spec = codec->spec;
2606 struct hda_pcm *info = spec->pcm_rec;
2608 codec->num_pcms = 1;
2609 codec->pcm_info = info;
2611 info->name = "STAC92xx Analog";
2612 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
2613 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2614 spec->multiout.dac_nids[0];
2615 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
2616 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2617 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adcs;
2619 if (spec->alt_switch) {
2620 codec->num_pcms++;
2621 info++;
2622 info->name = "STAC92xx Analog Alt";
2623 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
2626 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2627 codec->num_pcms++;
2628 info++;
2629 info->name = "STAC92xx Digital";
2630 info->pcm_type = spec->autocfg.dig_out_type[0];
2631 if (spec->multiout.dig_out_nid) {
2632 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
2633 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2635 if (spec->dig_in_nid) {
2636 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
2637 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2641 return 0;
2644 static unsigned int stac92xx_get_vref(struct hda_codec *codec, hda_nid_t nid)
2646 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2647 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
2648 if (pincap & AC_PINCAP_VREF_100)
2649 return AC_PINCTL_VREF_100;
2650 if (pincap & AC_PINCAP_VREF_80)
2651 return AC_PINCTL_VREF_80;
2652 if (pincap & AC_PINCAP_VREF_50)
2653 return AC_PINCTL_VREF_50;
2654 if (pincap & AC_PINCAP_VREF_GRD)
2655 return AC_PINCTL_VREF_GRD;
2656 return 0;
2659 static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
2662 snd_hda_codec_write_cache(codec, nid, 0,
2663 AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
2666 #define stac92xx_hp_switch_info snd_ctl_boolean_mono_info
2668 static int stac92xx_hp_switch_get(struct snd_kcontrol *kcontrol,
2669 struct snd_ctl_elem_value *ucontrol)
2671 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2672 struct sigmatel_spec *spec = codec->spec;
2674 ucontrol->value.integer.value[0] = !!spec->hp_switch;
2675 return 0;
2678 static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid,
2679 unsigned char type);
2681 static int stac92xx_hp_switch_put(struct snd_kcontrol *kcontrol,
2682 struct snd_ctl_elem_value *ucontrol)
2684 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2685 struct sigmatel_spec *spec = codec->spec;
2686 int nid = kcontrol->private_value;
2688 spec->hp_switch = ucontrol->value.integer.value[0] ? nid : 0;
2690 /* check to be sure that the ports are upto date with
2691 * switch changes
2693 stac_issue_unsol_event(codec, nid, STAC_HP_EVENT);
2695 return 1;
2698 #define stac92xx_io_switch_info snd_ctl_boolean_mono_info
2700 static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2702 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2703 struct sigmatel_spec *spec = codec->spec;
2704 int io_idx = kcontrol-> private_value & 0xff;
2706 ucontrol->value.integer.value[0] = spec->io_switch[io_idx];
2707 return 0;
2710 static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2712 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2713 struct sigmatel_spec *spec = codec->spec;
2714 hda_nid_t nid = kcontrol->private_value >> 8;
2715 int io_idx = kcontrol-> private_value & 0xff;
2716 unsigned short val = !!ucontrol->value.integer.value[0];
2718 spec->io_switch[io_idx] = val;
2720 if (val)
2721 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
2722 else {
2723 unsigned int pinctl = AC_PINCTL_IN_EN;
2724 if (io_idx) /* set VREF for mic */
2725 pinctl |= stac92xx_get_vref(codec, nid);
2726 stac92xx_auto_set_pinctl(codec, nid, pinctl);
2729 /* check the auto-mute again: we need to mute/unmute the speaker
2730 * appropriately according to the pin direction
2732 if (spec->hp_detect)
2733 stac_issue_unsol_event(codec, nid, STAC_HP_EVENT);
2735 return 1;
2738 #define stac92xx_clfe_switch_info snd_ctl_boolean_mono_info
2740 static int stac92xx_clfe_switch_get(struct snd_kcontrol *kcontrol,
2741 struct snd_ctl_elem_value *ucontrol)
2743 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2744 struct sigmatel_spec *spec = codec->spec;
2746 ucontrol->value.integer.value[0] = spec->clfe_swap;
2747 return 0;
2750 static int stac92xx_clfe_switch_put(struct snd_kcontrol *kcontrol,
2751 struct snd_ctl_elem_value *ucontrol)
2753 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2754 struct sigmatel_spec *spec = codec->spec;
2755 hda_nid_t nid = kcontrol->private_value & 0xff;
2756 unsigned int val = !!ucontrol->value.integer.value[0];
2758 if (spec->clfe_swap == val)
2759 return 0;
2761 spec->clfe_swap = val;
2763 snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
2764 spec->clfe_swap ? 0x4 : 0x0);
2766 return 1;
2769 #define STAC_CODEC_HP_SWITCH(xname) \
2770 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2771 .name = xname, \
2772 .index = 0, \
2773 .info = stac92xx_hp_switch_info, \
2774 .get = stac92xx_hp_switch_get, \
2775 .put = stac92xx_hp_switch_put, \
2778 #define STAC_CODEC_IO_SWITCH(xname, xpval) \
2779 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2780 .name = xname, \
2781 .index = 0, \
2782 .info = stac92xx_io_switch_info, \
2783 .get = stac92xx_io_switch_get, \
2784 .put = stac92xx_io_switch_put, \
2785 .private_value = xpval, \
2788 #define STAC_CODEC_CLFE_SWITCH(xname, xpval) \
2789 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2790 .name = xname, \
2791 .index = 0, \
2792 .info = stac92xx_clfe_switch_info, \
2793 .get = stac92xx_clfe_switch_get, \
2794 .put = stac92xx_clfe_switch_put, \
2795 .private_value = xpval, \
2798 enum {
2799 STAC_CTL_WIDGET_VOL,
2800 STAC_CTL_WIDGET_MUTE,
2801 STAC_CTL_WIDGET_MONO_MUX,
2802 STAC_CTL_WIDGET_AMP_MUX,
2803 STAC_CTL_WIDGET_AMP_VOL,
2804 STAC_CTL_WIDGET_HP_SWITCH,
2805 STAC_CTL_WIDGET_IO_SWITCH,
2806 STAC_CTL_WIDGET_CLFE_SWITCH,
2807 STAC_CTL_WIDGET_DC_BIAS
2810 static struct snd_kcontrol_new stac92xx_control_templates[] = {
2811 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2812 HDA_CODEC_MUTE(NULL, 0, 0, 0),
2813 STAC_MONO_MUX,
2814 STAC_AMP_MUX,
2815 STAC_AMP_VOL(NULL, 0, 0, 0, 0),
2816 STAC_CODEC_HP_SWITCH(NULL),
2817 STAC_CODEC_IO_SWITCH(NULL, 0),
2818 STAC_CODEC_CLFE_SWITCH(NULL, 0),
2819 DC_BIAS(NULL, 0, 0),
2822 /* add dynamic controls */
2823 static struct snd_kcontrol_new *
2824 stac_control_new(struct sigmatel_spec *spec,
2825 struct snd_kcontrol_new *ktemp,
2826 const char *name)
2828 struct snd_kcontrol_new *knew;
2830 snd_array_init(&spec->kctls, sizeof(*knew), 32);
2831 knew = snd_array_new(&spec->kctls);
2832 if (!knew)
2833 return NULL;
2834 *knew = *ktemp;
2835 knew->name = kstrdup(name, GFP_KERNEL);
2836 if (!knew->name) {
2837 /* roolback */
2838 memset(knew, 0, sizeof(*knew));
2839 spec->kctls.alloced--;
2840 return NULL;
2842 return knew;
2845 static int stac92xx_add_control_temp(struct sigmatel_spec *spec,
2846 struct snd_kcontrol_new *ktemp,
2847 int idx, const char *name,
2848 unsigned long val)
2850 struct snd_kcontrol_new *knew = stac_control_new(spec, ktemp, name);
2851 if (!knew)
2852 return -ENOMEM;
2853 knew->index = idx;
2854 knew->private_value = val;
2855 return 0;
2858 static inline int stac92xx_add_control_idx(struct sigmatel_spec *spec,
2859 int type, int idx, const char *name,
2860 unsigned long val)
2862 return stac92xx_add_control_temp(spec,
2863 &stac92xx_control_templates[type],
2864 idx, name, val);
2868 /* add dynamic controls */
2869 static inline int stac92xx_add_control(struct sigmatel_spec *spec, int type,
2870 const char *name, unsigned long val)
2872 return stac92xx_add_control_idx(spec, type, 0, name, val);
2875 static struct snd_kcontrol_new stac_input_src_temp = {
2876 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2877 .name = "Input Source",
2878 .info = stac92xx_mux_enum_info,
2879 .get = stac92xx_mux_enum_get,
2880 .put = stac92xx_mux_enum_put,
2883 static int stac92xx_add_input_source(struct sigmatel_spec *spec)
2885 struct snd_kcontrol_new *knew;
2886 struct hda_input_mux *imux = &spec->private_imux;
2888 if (!spec->num_adcs || imux->num_items <= 1)
2889 return 0; /* no need for input source control */
2890 knew = stac_control_new(spec, &stac_input_src_temp,
2891 stac_input_src_temp.name);
2892 if (!knew)
2893 return -ENOMEM;
2894 knew->count = spec->num_adcs;
2895 return 0;
2898 /* check whether the line-input can be used as line-out */
2899 static hda_nid_t check_line_out_switch(struct hda_codec *codec)
2901 struct sigmatel_spec *spec = codec->spec;
2902 struct auto_pin_cfg *cfg = &spec->autocfg;
2903 hda_nid_t nid;
2904 unsigned int pincap;
2906 if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
2907 return 0;
2908 nid = cfg->input_pins[AUTO_PIN_LINE];
2909 pincap = snd_hda_query_pin_caps(codec, nid);
2910 if (pincap & AC_PINCAP_OUT)
2911 return nid;
2912 return 0;
2915 /* check whether the mic-input can be used as line-out */
2916 static hda_nid_t check_mic_out_switch(struct hda_codec *codec)
2918 struct sigmatel_spec *spec = codec->spec;
2919 struct auto_pin_cfg *cfg = &spec->autocfg;
2920 unsigned int def_conf, pincap;
2921 unsigned int mic_pin;
2923 if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
2924 return 0;
2925 mic_pin = AUTO_PIN_MIC;
2926 for (;;) {
2927 hda_nid_t nid = cfg->input_pins[mic_pin];
2928 def_conf = snd_hda_codec_get_pincfg(codec, nid);
2929 /* some laptops have an internal analog microphone
2930 * which can't be used as a output */
2931 if (get_defcfg_connect(def_conf) != AC_JACK_PORT_FIXED) {
2932 pincap = snd_hda_query_pin_caps(codec, nid);
2933 if (pincap & AC_PINCAP_OUT)
2934 return nid;
2936 if (mic_pin == AUTO_PIN_MIC)
2937 mic_pin = AUTO_PIN_FRONT_MIC;
2938 else
2939 break;
2941 return 0;
2944 static int is_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2946 int i;
2948 for (i = 0; i < spec->multiout.num_dacs; i++) {
2949 if (spec->multiout.dac_nids[i] == nid)
2950 return 1;
2953 return 0;
2956 static int check_all_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2958 int i;
2959 if (is_in_dac_nids(spec, nid))
2960 return 1;
2961 for (i = 0; i < spec->autocfg.hp_outs; i++)
2962 if (spec->hp_dacs[i] == nid)
2963 return 1;
2964 for (i = 0; i < spec->autocfg.speaker_outs; i++)
2965 if (spec->speaker_dacs[i] == nid)
2966 return 1;
2967 return 0;
2970 static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t nid)
2972 struct sigmatel_spec *spec = codec->spec;
2973 int j, conn_len;
2974 hda_nid_t conn[HDA_MAX_CONNECTIONS];
2975 unsigned int wcaps, wtype;
2977 conn_len = snd_hda_get_connections(codec, nid, conn,
2978 HDA_MAX_CONNECTIONS);
2979 for (j = 0; j < conn_len; j++) {
2980 wcaps = get_wcaps(codec, conn[j]);
2981 wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
2982 /* we check only analog outputs */
2983 if (wtype != AC_WID_AUD_OUT || (wcaps & AC_WCAP_DIGITAL))
2984 continue;
2985 /* if this route has a free DAC, assign it */
2986 if (!check_all_dac_nids(spec, conn[j])) {
2987 if (conn_len > 1) {
2988 /* select this DAC in the pin's input mux */
2989 snd_hda_codec_write_cache(codec, nid, 0,
2990 AC_VERB_SET_CONNECT_SEL, j);
2992 return conn[j];
2995 /* if all DACs are already assigned, connect to the primary DAC */
2996 if (conn_len > 1) {
2997 for (j = 0; j < conn_len; j++) {
2998 if (conn[j] == spec->multiout.dac_nids[0]) {
2999 snd_hda_codec_write_cache(codec, nid, 0,
3000 AC_VERB_SET_CONNECT_SEL, j);
3001 break;
3005 return 0;
3008 static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid);
3009 static int add_spec_extra_dacs(struct sigmatel_spec *spec, hda_nid_t nid);
3012 * Fill in the dac_nids table from the parsed pin configuration
3013 * This function only works when every pin in line_out_pins[]
3014 * contains atleast one DAC in its connection list. Some 92xx
3015 * codecs are not connected directly to a DAC, such as the 9200
3016 * and 9202/925x. For those, dac_nids[] must be hard-coded.
3018 static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec)
3020 struct sigmatel_spec *spec = codec->spec;
3021 struct auto_pin_cfg *cfg = &spec->autocfg;
3022 int i;
3023 hda_nid_t nid, dac;
3025 for (i = 0; i < cfg->line_outs; i++) {
3026 nid = cfg->line_out_pins[i];
3027 dac = get_unassigned_dac(codec, nid);
3028 if (!dac) {
3029 if (spec->multiout.num_dacs > 0) {
3030 /* we have already working output pins,
3031 * so let's drop the broken ones again
3033 cfg->line_outs = spec->multiout.num_dacs;
3034 break;
3036 /* error out, no available DAC found */
3037 snd_printk(KERN_ERR
3038 "%s: No available DAC for pin 0x%x\n",
3039 __func__, nid);
3040 return -ENODEV;
3042 add_spec_dacs(spec, dac);
3045 for (i = 0; i < cfg->hp_outs; i++) {
3046 nid = cfg->hp_pins[i];
3047 dac = get_unassigned_dac(codec, nid);
3048 if (dac) {
3049 if (!spec->multiout.hp_nid)
3050 spec->multiout.hp_nid = dac;
3051 else
3052 add_spec_extra_dacs(spec, dac);
3054 spec->hp_dacs[i] = dac;
3057 for (i = 0; i < cfg->speaker_outs; i++) {
3058 nid = cfg->speaker_pins[i];
3059 dac = get_unassigned_dac(codec, nid);
3060 if (dac)
3061 add_spec_extra_dacs(spec, dac);
3062 spec->speaker_dacs[i] = dac;
3065 /* add line-in as output */
3066 nid = check_line_out_switch(codec);
3067 if (nid) {
3068 dac = get_unassigned_dac(codec, nid);
3069 if (dac) {
3070 snd_printdd("STAC: Add line-in 0x%x as output %d\n",
3071 nid, cfg->line_outs);
3072 cfg->line_out_pins[cfg->line_outs] = nid;
3073 cfg->line_outs++;
3074 spec->line_switch = nid;
3075 add_spec_dacs(spec, dac);
3078 /* add mic as output */
3079 nid = check_mic_out_switch(codec);
3080 if (nid) {
3081 dac = get_unassigned_dac(codec, nid);
3082 if (dac) {
3083 snd_printdd("STAC: Add mic-in 0x%x as output %d\n",
3084 nid, cfg->line_outs);
3085 cfg->line_out_pins[cfg->line_outs] = nid;
3086 cfg->line_outs++;
3087 spec->mic_switch = nid;
3088 add_spec_dacs(spec, dac);
3092 snd_printd("stac92xx: dac_nids=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
3093 spec->multiout.num_dacs,
3094 spec->multiout.dac_nids[0],
3095 spec->multiout.dac_nids[1],
3096 spec->multiout.dac_nids[2],
3097 spec->multiout.dac_nids[3],
3098 spec->multiout.dac_nids[4]);
3100 return 0;
3103 /* create volume control/switch for the given prefx type */
3104 static int create_controls_idx(struct hda_codec *codec, const char *pfx,
3105 int idx, hda_nid_t nid, int chs)
3107 struct sigmatel_spec *spec = codec->spec;
3108 char name[32];
3109 int err;
3111 if (!spec->check_volume_offset) {
3112 unsigned int caps, step, nums, db_scale;
3113 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3114 step = (caps & AC_AMPCAP_STEP_SIZE) >>
3115 AC_AMPCAP_STEP_SIZE_SHIFT;
3116 step = (step + 1) * 25; /* in .01dB unit */
3117 nums = (caps & AC_AMPCAP_NUM_STEPS) >>
3118 AC_AMPCAP_NUM_STEPS_SHIFT;
3119 db_scale = nums * step;
3120 /* if dB scale is over -64dB, and finer enough,
3121 * let's reduce it to half
3123 if (db_scale > 6400 && nums >= 0x1f)
3124 spec->volume_offset = nums / 2;
3125 spec->check_volume_offset = 1;
3128 sprintf(name, "%s Playback Volume", pfx);
3129 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_VOL, idx, name,
3130 HDA_COMPOSE_AMP_VAL_OFS(nid, chs, 0, HDA_OUTPUT,
3131 spec->volume_offset));
3132 if (err < 0)
3133 return err;
3134 sprintf(name, "%s Playback Switch", pfx);
3135 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_MUTE, idx, name,
3136 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
3137 if (err < 0)
3138 return err;
3139 return 0;
3142 #define create_controls(codec, pfx, nid, chs) \
3143 create_controls_idx(codec, pfx, 0, nid, chs)
3145 static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
3147 if (spec->multiout.num_dacs > 4) {
3148 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
3149 return 1;
3150 } else {
3151 spec->multiout.dac_nids[spec->multiout.num_dacs] = nid;
3152 spec->multiout.num_dacs++;
3154 return 0;
3157 static int add_spec_extra_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
3159 int i;
3160 for (i = 0; i < ARRAY_SIZE(spec->multiout.extra_out_nid); i++) {
3161 if (!spec->multiout.extra_out_nid[i]) {
3162 spec->multiout.extra_out_nid[i] = nid;
3163 return 0;
3166 printk(KERN_WARNING "stac92xx: No space for extra DAC 0x%x\n", nid);
3167 return 1;
3170 /* Create output controls
3171 * The mixer elements are named depending on the given type (AUTO_PIN_XXX_OUT)
3173 static int create_multi_out_ctls(struct hda_codec *codec, int num_outs,
3174 const hda_nid_t *pins,
3175 const hda_nid_t *dac_nids,
3176 int type)
3178 struct sigmatel_spec *spec = codec->spec;
3179 static const char *chname[4] = {
3180 "Front", "Surround", NULL /*CLFE*/, "Side"
3182 hda_nid_t nid;
3183 int i, err;
3184 unsigned int wid_caps;
3186 for (i = 0; i < num_outs && i < ARRAY_SIZE(chname); i++) {
3187 if (type == AUTO_PIN_HP_OUT && !spec->hp_detect) {
3188 wid_caps = get_wcaps(codec, pins[i]);
3189 if (wid_caps & AC_WCAP_UNSOL_CAP)
3190 spec->hp_detect = 1;
3192 nid = dac_nids[i];
3193 if (!nid)
3194 continue;
3195 if (type != AUTO_PIN_HP_OUT && i == 2) {
3196 /* Center/LFE */
3197 err = create_controls(codec, "Center", nid, 1);
3198 if (err < 0)
3199 return err;
3200 err = create_controls(codec, "LFE", nid, 2);
3201 if (err < 0)
3202 return err;
3204 wid_caps = get_wcaps(codec, nid);
3206 if (wid_caps & AC_WCAP_LR_SWAP) {
3207 err = stac92xx_add_control(spec,
3208 STAC_CTL_WIDGET_CLFE_SWITCH,
3209 "Swap Center/LFE Playback Switch", nid);
3211 if (err < 0)
3212 return err;
3215 } else {
3216 const char *name;
3217 int idx;
3218 switch (type) {
3219 case AUTO_PIN_HP_OUT:
3220 name = "Headphone";
3221 idx = i;
3222 break;
3223 case AUTO_PIN_SPEAKER_OUT:
3224 name = "Speaker";
3225 idx = i;
3226 break;
3227 default:
3228 name = chname[i];
3229 idx = 0;
3230 break;
3232 err = create_controls_idx(codec, name, idx, nid, 3);
3233 if (err < 0)
3234 return err;
3237 return 0;
3240 /* add playback controls from the parsed DAC table */
3241 static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
3242 const struct auto_pin_cfg *cfg)
3244 struct sigmatel_spec *spec = codec->spec;
3245 int err;
3247 err = create_multi_out_ctls(codec, cfg->line_outs, cfg->line_out_pins,
3248 spec->multiout.dac_nids,
3249 cfg->line_out_type);
3250 if (err < 0)
3251 return err;
3253 if (cfg->hp_outs > 1 && cfg->line_out_type == AUTO_PIN_LINE_OUT) {
3254 err = stac92xx_add_control(spec,
3255 STAC_CTL_WIDGET_HP_SWITCH,
3256 "Headphone as Line Out Switch",
3257 cfg->hp_pins[cfg->hp_outs - 1]);
3258 if (err < 0)
3259 return err;
3262 if (spec->line_switch) {
3263 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH,
3264 "Line In as Output Switch",
3265 spec->line_switch << 8);
3266 if (err < 0)
3267 return err;
3270 if (spec->mic_switch) {
3271 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_DC_BIAS,
3272 "Mic Jack Mode",
3273 spec->mic_switch);
3274 if (err < 0)
3275 return err;
3278 return 0;
3281 /* add playback controls for Speaker and HP outputs */
3282 static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
3283 struct auto_pin_cfg *cfg)
3285 struct sigmatel_spec *spec = codec->spec;
3286 int err;
3288 err = create_multi_out_ctls(codec, cfg->hp_outs, cfg->hp_pins,
3289 spec->hp_dacs, AUTO_PIN_HP_OUT);
3290 if (err < 0)
3291 return err;
3293 err = create_multi_out_ctls(codec, cfg->speaker_outs, cfg->speaker_pins,
3294 spec->speaker_dacs, AUTO_PIN_SPEAKER_OUT);
3295 if (err < 0)
3296 return err;
3298 return 0;
3301 /* labels for mono mux outputs */
3302 static const char *stac92xx_mono_labels[4] = {
3303 "DAC0", "DAC1", "Mixer", "DAC2"
3306 /* create mono mux for mono out on capable codecs */
3307 static int stac92xx_auto_create_mono_output_ctls(struct hda_codec *codec)
3309 struct sigmatel_spec *spec = codec->spec;
3310 struct hda_input_mux *mono_mux = &spec->private_mono_mux;
3311 int i, num_cons;
3312 hda_nid_t con_lst[ARRAY_SIZE(stac92xx_mono_labels)];
3314 num_cons = snd_hda_get_connections(codec,
3315 spec->mono_nid,
3316 con_lst,
3317 HDA_MAX_NUM_INPUTS);
3318 if (!num_cons || num_cons > ARRAY_SIZE(stac92xx_mono_labels))
3319 return -EINVAL;
3321 for (i = 0; i < num_cons; i++) {
3322 mono_mux->items[mono_mux->num_items].label =
3323 stac92xx_mono_labels[i];
3324 mono_mux->items[mono_mux->num_items].index = i;
3325 mono_mux->num_items++;
3328 return stac92xx_add_control(spec, STAC_CTL_WIDGET_MONO_MUX,
3329 "Mono Mux", spec->mono_nid);
3332 /* labels for amp mux outputs */
3333 static const char *stac92xx_amp_labels[3] = {
3334 "Front Microphone", "Microphone", "Line In",
3337 /* create amp out controls mux on capable codecs */
3338 static int stac92xx_auto_create_amp_output_ctls(struct hda_codec *codec)
3340 struct sigmatel_spec *spec = codec->spec;
3341 struct hda_input_mux *amp_mux = &spec->private_amp_mux;
3342 int i, err;
3344 for (i = 0; i < spec->num_amps; i++) {
3345 amp_mux->items[amp_mux->num_items].label =
3346 stac92xx_amp_labels[i];
3347 amp_mux->items[amp_mux->num_items].index = i;
3348 amp_mux->num_items++;
3351 if (spec->num_amps > 1) {
3352 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_AMP_MUX,
3353 "Amp Selector Capture Switch", 0);
3354 if (err < 0)
3355 return err;
3357 return stac92xx_add_control(spec, STAC_CTL_WIDGET_AMP_VOL,
3358 "Amp Capture Volume",
3359 HDA_COMPOSE_AMP_VAL(spec->amp_nids[0], 3, 0, HDA_INPUT));
3363 /* create PC beep volume controls */
3364 static int stac92xx_auto_create_beep_ctls(struct hda_codec *codec,
3365 hda_nid_t nid)
3367 struct sigmatel_spec *spec = codec->spec;
3368 u32 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3369 int err;
3371 /* check for mute support for the the amp */
3372 if ((caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT) {
3373 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE,
3374 "PC Beep Playback Switch",
3375 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3376 if (err < 0)
3377 return err;
3380 /* check to see if there is volume support for the amp */
3381 if ((caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3382 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL,
3383 "PC Beep Playback Volume",
3384 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3385 if (err < 0)
3386 return err;
3388 return 0;
3391 #ifdef CONFIG_SND_HDA_INPUT_BEEP
3392 #define stac92xx_dig_beep_switch_info snd_ctl_boolean_mono_info
3394 static int stac92xx_dig_beep_switch_get(struct snd_kcontrol *kcontrol,
3395 struct snd_ctl_elem_value *ucontrol)
3397 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3398 ucontrol->value.integer.value[0] = codec->beep->enabled;
3399 return 0;
3402 static int stac92xx_dig_beep_switch_put(struct snd_kcontrol *kcontrol,
3403 struct snd_ctl_elem_value *ucontrol)
3405 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3406 int enabled = !!ucontrol->value.integer.value[0];
3407 if (codec->beep->enabled != enabled) {
3408 codec->beep->enabled = enabled;
3409 return 1;
3411 return 0;
3414 static struct snd_kcontrol_new stac92xx_dig_beep_ctrl = {
3415 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3416 .info = stac92xx_dig_beep_switch_info,
3417 .get = stac92xx_dig_beep_switch_get,
3418 .put = stac92xx_dig_beep_switch_put,
3421 static int stac92xx_beep_switch_ctl(struct hda_codec *codec)
3423 return stac92xx_add_control_temp(codec->spec, &stac92xx_dig_beep_ctrl,
3424 0, "PC Beep Playback Switch", 0);
3426 #endif
3428 static int stac92xx_auto_create_mux_input_ctls(struct hda_codec *codec)
3430 struct sigmatel_spec *spec = codec->spec;
3431 int wcaps, nid, i, err = 0;
3433 for (i = 0; i < spec->num_muxes; i++) {
3434 nid = spec->mux_nids[i];
3435 wcaps = get_wcaps(codec, nid);
3437 if (wcaps & AC_WCAP_OUT_AMP) {
3438 err = stac92xx_add_control_idx(spec,
3439 STAC_CTL_WIDGET_VOL, i, "Mux Capture Volume",
3440 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
3441 if (err < 0)
3442 return err;
3445 return 0;
3448 static const char *stac92xx_spdif_labels[3] = {
3449 "Digital Playback", "Analog Mux 1", "Analog Mux 2",
3452 static int stac92xx_auto_create_spdif_mux_ctls(struct hda_codec *codec)
3454 struct sigmatel_spec *spec = codec->spec;
3455 struct hda_input_mux *spdif_mux = &spec->private_smux;
3456 const char **labels = spec->spdif_labels;
3457 int i, num_cons;
3458 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
3460 num_cons = snd_hda_get_connections(codec,
3461 spec->smux_nids[0],
3462 con_lst,
3463 HDA_MAX_NUM_INPUTS);
3464 if (!num_cons)
3465 return -EINVAL;
3467 if (!labels)
3468 labels = stac92xx_spdif_labels;
3470 for (i = 0; i < num_cons; i++) {
3471 spdif_mux->items[spdif_mux->num_items].label = labels[i];
3472 spdif_mux->items[spdif_mux->num_items].index = i;
3473 spdif_mux->num_items++;
3476 return 0;
3479 /* labels for dmic mux inputs */
3480 static const char *stac92xx_dmic_labels[5] = {
3481 "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
3482 "Digital Mic 3", "Digital Mic 4"
3485 /* create playback/capture controls for input pins on dmic capable codecs */
3486 static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
3487 const struct auto_pin_cfg *cfg)
3489 struct sigmatel_spec *spec = codec->spec;
3490 struct hda_input_mux *dimux = &spec->private_dimux;
3491 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
3492 int err, i, j;
3493 char name[32];
3495 dimux->items[dimux->num_items].label = stac92xx_dmic_labels[0];
3496 dimux->items[dimux->num_items].index = 0;
3497 dimux->num_items++;
3499 for (i = 0; i < spec->num_dmics; i++) {
3500 hda_nid_t nid;
3501 int index;
3502 int num_cons;
3503 unsigned int wcaps;
3504 unsigned int def_conf;
3506 def_conf = snd_hda_codec_get_pincfg(codec, spec->dmic_nids[i]);
3507 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
3508 continue;
3510 nid = spec->dmic_nids[i];
3511 num_cons = snd_hda_get_connections(codec,
3512 spec->dmux_nids[0],
3513 con_lst,
3514 HDA_MAX_NUM_INPUTS);
3515 for (j = 0; j < num_cons; j++)
3516 if (con_lst[j] == nid) {
3517 index = j;
3518 goto found;
3520 continue;
3521 found:
3522 wcaps = get_wcaps(codec, nid) &
3523 (AC_WCAP_OUT_AMP | AC_WCAP_IN_AMP);
3525 if (wcaps) {
3526 sprintf(name, "%s Capture Volume",
3527 stac92xx_dmic_labels[dimux->num_items]);
3529 err = stac92xx_add_control(spec,
3530 STAC_CTL_WIDGET_VOL,
3531 name,
3532 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3533 (wcaps & AC_WCAP_OUT_AMP) ?
3534 HDA_OUTPUT : HDA_INPUT));
3535 if (err < 0)
3536 return err;
3539 dimux->items[dimux->num_items].label =
3540 stac92xx_dmic_labels[dimux->num_items];
3541 dimux->items[dimux->num_items].index = index;
3542 dimux->num_items++;
3545 return 0;
3548 /* create playback/capture controls for input pins */
3549 static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
3551 struct sigmatel_spec *spec = codec->spec;
3552 struct hda_input_mux *imux = &spec->private_imux;
3553 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
3554 int i, j, k;
3556 for (i = 0; i < AUTO_PIN_LAST; i++) {
3557 int index;
3559 if (!cfg->input_pins[i])
3560 continue;
3561 index = -1;
3562 for (j = 0; j < spec->num_muxes; j++) {
3563 int num_cons;
3564 num_cons = snd_hda_get_connections(codec,
3565 spec->mux_nids[j],
3566 con_lst,
3567 HDA_MAX_NUM_INPUTS);
3568 for (k = 0; k < num_cons; k++)
3569 if (con_lst[k] == cfg->input_pins[i]) {
3570 index = k;
3571 goto found;
3574 continue;
3575 found:
3576 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
3577 imux->items[imux->num_items].index = index;
3578 imux->num_items++;
3581 if (imux->num_items) {
3583 * Set the current input for the muxes.
3584 * The STAC9221 has two input muxes with identical source
3585 * NID lists. Hopefully this won't get confused.
3587 for (i = 0; i < spec->num_muxes; i++) {
3588 snd_hda_codec_write_cache(codec, spec->mux_nids[i], 0,
3589 AC_VERB_SET_CONNECT_SEL,
3590 imux->items[0].index);
3594 return 0;
3597 static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
3599 struct sigmatel_spec *spec = codec->spec;
3600 int i;
3602 for (i = 0; i < spec->autocfg.line_outs; i++) {
3603 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3604 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
3608 static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
3610 struct sigmatel_spec *spec = codec->spec;
3611 int i;
3613 for (i = 0; i < spec->autocfg.hp_outs; i++) {
3614 hda_nid_t pin;
3615 pin = spec->autocfg.hp_pins[i];
3616 if (pin) /* connect to front */
3617 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
3619 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
3620 hda_nid_t pin;
3621 pin = spec->autocfg.speaker_pins[i];
3622 if (pin) /* connect to front */
3623 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
3627 static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out, hda_nid_t dig_in)
3629 struct sigmatel_spec *spec = codec->spec;
3630 int hp_swap = 0;
3631 int err;
3633 if ((err = snd_hda_parse_pin_def_config(codec,
3634 &spec->autocfg,
3635 spec->dmic_nids)) < 0)
3636 return err;
3637 if (! spec->autocfg.line_outs)
3638 return 0; /* can't find valid pin config */
3640 /* If we have no real line-out pin and multiple hp-outs, HPs should
3641 * be set up as multi-channel outputs.
3643 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT &&
3644 spec->autocfg.hp_outs > 1) {
3645 /* Copy hp_outs to line_outs, backup line_outs in
3646 * speaker_outs so that the following routines can handle
3647 * HP pins as primary outputs.
3649 snd_printdd("stac92xx: Enabling multi-HPs workaround\n");
3650 memcpy(spec->autocfg.speaker_pins, spec->autocfg.line_out_pins,
3651 sizeof(spec->autocfg.line_out_pins));
3652 spec->autocfg.speaker_outs = spec->autocfg.line_outs;
3653 memcpy(spec->autocfg.line_out_pins, spec->autocfg.hp_pins,
3654 sizeof(spec->autocfg.hp_pins));
3655 spec->autocfg.line_outs = spec->autocfg.hp_outs;
3656 spec->autocfg.line_out_type = AUTO_PIN_HP_OUT;
3657 spec->autocfg.hp_outs = 0;
3658 hp_swap = 1;
3660 if (spec->autocfg.mono_out_pin) {
3661 int dir = get_wcaps(codec, spec->autocfg.mono_out_pin) &
3662 (AC_WCAP_OUT_AMP | AC_WCAP_IN_AMP);
3663 u32 caps = query_amp_caps(codec,
3664 spec->autocfg.mono_out_pin, dir);
3665 hda_nid_t conn_list[1];
3667 /* get the mixer node and then the mono mux if it exists */
3668 if (snd_hda_get_connections(codec,
3669 spec->autocfg.mono_out_pin, conn_list, 1) &&
3670 snd_hda_get_connections(codec, conn_list[0],
3671 conn_list, 1)) {
3673 int wcaps = get_wcaps(codec, conn_list[0]);
3674 int wid_type = (wcaps & AC_WCAP_TYPE)
3675 >> AC_WCAP_TYPE_SHIFT;
3676 /* LR swap check, some stac925x have a mux that
3677 * changes the DACs output path instead of the
3678 * mono-mux path.
3680 if (wid_type == AC_WID_AUD_SEL &&
3681 !(wcaps & AC_WCAP_LR_SWAP))
3682 spec->mono_nid = conn_list[0];
3684 if (dir) {
3685 hda_nid_t nid = spec->autocfg.mono_out_pin;
3687 /* most mono outs have a least a mute/unmute switch */
3688 dir = (dir & AC_WCAP_OUT_AMP) ? HDA_OUTPUT : HDA_INPUT;
3689 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE,
3690 "Mono Playback Switch",
3691 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
3692 if (err < 0)
3693 return err;
3694 /* check for volume support for the amp */
3695 if ((caps & AC_AMPCAP_NUM_STEPS)
3696 >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3697 err = stac92xx_add_control(spec,
3698 STAC_CTL_WIDGET_VOL,
3699 "Mono Playback Volume",
3700 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
3701 if (err < 0)
3702 return err;
3706 stac92xx_auto_set_pinctl(codec, spec->autocfg.mono_out_pin,
3707 AC_PINCTL_OUT_EN);
3710 if (!spec->multiout.num_dacs) {
3711 err = stac92xx_auto_fill_dac_nids(codec);
3712 if (err < 0)
3713 return err;
3714 err = stac92xx_auto_create_multi_out_ctls(codec,
3715 &spec->autocfg);
3716 if (err < 0)
3717 return err;
3720 /* setup analog beep controls */
3721 if (spec->anabeep_nid > 0) {
3722 err = stac92xx_auto_create_beep_ctls(codec,
3723 spec->anabeep_nid);
3724 if (err < 0)
3725 return err;
3728 /* setup digital beep controls and input device */
3729 #ifdef CONFIG_SND_HDA_INPUT_BEEP
3730 if (spec->digbeep_nid > 0) {
3731 hda_nid_t nid = spec->digbeep_nid;
3732 unsigned int caps;
3734 err = stac92xx_auto_create_beep_ctls(codec, nid);
3735 if (err < 0)
3736 return err;
3737 err = snd_hda_attach_beep_device(codec, nid);
3738 if (err < 0)
3739 return err;
3740 /* if no beep switch is available, make its own one */
3741 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3742 if (codec->beep &&
3743 !((caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT)) {
3744 err = stac92xx_beep_switch_ctl(codec);
3745 if (err < 0)
3746 return err;
3749 #endif
3751 err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg);
3752 if (err < 0)
3753 return err;
3755 /* All output parsing done, now restore the swapped hp pins */
3756 if (hp_swap) {
3757 memcpy(spec->autocfg.hp_pins, spec->autocfg.line_out_pins,
3758 sizeof(spec->autocfg.hp_pins));
3759 spec->autocfg.hp_outs = spec->autocfg.line_outs;
3760 spec->autocfg.line_out_type = AUTO_PIN_HP_OUT;
3761 spec->autocfg.line_outs = 0;
3764 err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg);
3765 if (err < 0)
3766 return err;
3768 if (spec->mono_nid > 0) {
3769 err = stac92xx_auto_create_mono_output_ctls(codec);
3770 if (err < 0)
3771 return err;
3773 if (spec->num_amps > 0) {
3774 err = stac92xx_auto_create_amp_output_ctls(codec);
3775 if (err < 0)
3776 return err;
3778 if (spec->num_dmics > 0 && !spec->dinput_mux)
3779 if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
3780 &spec->autocfg)) < 0)
3781 return err;
3782 if (spec->num_muxes > 0) {
3783 err = stac92xx_auto_create_mux_input_ctls(codec);
3784 if (err < 0)
3785 return err;
3787 if (spec->num_smuxes > 0) {
3788 err = stac92xx_auto_create_spdif_mux_ctls(codec);
3789 if (err < 0)
3790 return err;
3793 err = stac92xx_add_input_source(spec);
3794 if (err < 0)
3795 return err;
3797 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3798 if (spec->multiout.max_channels > 2)
3799 spec->surr_switch = 1;
3801 if (spec->autocfg.dig_outs)
3802 spec->multiout.dig_out_nid = dig_out;
3803 if (dig_in && spec->autocfg.dig_in_pin)
3804 spec->dig_in_nid = dig_in;
3806 if (spec->kctls.list)
3807 spec->mixers[spec->num_mixers++] = spec->kctls.list;
3809 spec->input_mux = &spec->private_imux;
3810 if (!spec->dinput_mux)
3811 spec->dinput_mux = &spec->private_dimux;
3812 spec->sinput_mux = &spec->private_smux;
3813 spec->mono_mux = &spec->private_mono_mux;
3814 spec->amp_mux = &spec->private_amp_mux;
3815 return 1;
3818 /* add playback controls for HP output */
3819 static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
3820 struct auto_pin_cfg *cfg)
3822 struct sigmatel_spec *spec = codec->spec;
3823 hda_nid_t pin = cfg->hp_pins[0];
3824 unsigned int wid_caps;
3826 if (! pin)
3827 return 0;
3829 wid_caps = get_wcaps(codec, pin);
3830 if (wid_caps & AC_WCAP_UNSOL_CAP)
3831 spec->hp_detect = 1;
3833 return 0;
3836 /* add playback controls for LFE output */
3837 static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
3838 struct auto_pin_cfg *cfg)
3840 struct sigmatel_spec *spec = codec->spec;
3841 int err;
3842 hda_nid_t lfe_pin = 0x0;
3843 int i;
3846 * search speaker outs and line outs for a mono speaker pin
3847 * with an amp. If one is found, add LFE controls
3848 * for it.
3850 for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
3851 hda_nid_t pin = spec->autocfg.speaker_pins[i];
3852 unsigned int wcaps = get_wcaps(codec, pin);
3853 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
3854 if (wcaps == AC_WCAP_OUT_AMP)
3855 /* found a mono speaker with an amp, must be lfe */
3856 lfe_pin = pin;
3859 /* if speaker_outs is 0, then speakers may be in line_outs */
3860 if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
3861 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
3862 hda_nid_t pin = spec->autocfg.line_out_pins[i];
3863 unsigned int defcfg;
3864 defcfg = snd_hda_codec_get_pincfg(codec, pin);
3865 if (get_defcfg_device(defcfg) == AC_JACK_SPEAKER) {
3866 unsigned int wcaps = get_wcaps(codec, pin);
3867 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
3868 if (wcaps == AC_WCAP_OUT_AMP)
3869 /* found a mono speaker with an amp,
3870 must be lfe */
3871 lfe_pin = pin;
3876 if (lfe_pin) {
3877 err = create_controls(codec, "LFE", lfe_pin, 1);
3878 if (err < 0)
3879 return err;
3882 return 0;
3885 static int stac9200_parse_auto_config(struct hda_codec *codec)
3887 struct sigmatel_spec *spec = codec->spec;
3888 int err;
3890 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
3891 return err;
3893 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
3894 return err;
3896 if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
3897 return err;
3899 if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
3900 return err;
3902 if (spec->num_muxes > 0) {
3903 err = stac92xx_auto_create_mux_input_ctls(codec);
3904 if (err < 0)
3905 return err;
3908 err = stac92xx_add_input_source(spec);
3909 if (err < 0)
3910 return err;
3912 if (spec->autocfg.dig_outs)
3913 spec->multiout.dig_out_nid = 0x05;
3914 if (spec->autocfg.dig_in_pin)
3915 spec->dig_in_nid = 0x04;
3917 if (spec->kctls.list)
3918 spec->mixers[spec->num_mixers++] = spec->kctls.list;
3920 spec->input_mux = &spec->private_imux;
3921 spec->dinput_mux = &spec->private_dimux;
3923 return 1;
3927 * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
3928 * funky external mute control using GPIO pins.
3931 static void stac_gpio_set(struct hda_codec *codec, unsigned int mask,
3932 unsigned int dir_mask, unsigned int data)
3934 unsigned int gpiostate, gpiomask, gpiodir;
3936 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
3937 AC_VERB_GET_GPIO_DATA, 0);
3938 gpiostate = (gpiostate & ~dir_mask) | (data & dir_mask);
3940 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
3941 AC_VERB_GET_GPIO_MASK, 0);
3942 gpiomask |= mask;
3944 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
3945 AC_VERB_GET_GPIO_DIRECTION, 0);
3946 gpiodir |= dir_mask;
3948 /* Configure GPIOx as CMOS */
3949 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
3951 snd_hda_codec_write(codec, codec->afg, 0,
3952 AC_VERB_SET_GPIO_MASK, gpiomask);
3953 snd_hda_codec_read(codec, codec->afg, 0,
3954 AC_VERB_SET_GPIO_DIRECTION, gpiodir); /* sync */
3956 msleep(1);
3958 snd_hda_codec_read(codec, codec->afg, 0,
3959 AC_VERB_SET_GPIO_DATA, gpiostate); /* sync */
3962 #ifdef CONFIG_SND_JACK
3963 static void stac92xx_free_jack_priv(struct snd_jack *jack)
3965 struct sigmatel_jack *jacks = jack->private_data;
3966 jacks->nid = 0;
3967 jacks->jack = NULL;
3969 #endif
3971 static int stac92xx_add_jack(struct hda_codec *codec,
3972 hda_nid_t nid, int type)
3974 #ifdef CONFIG_SND_JACK
3975 struct sigmatel_spec *spec = codec->spec;
3976 struct sigmatel_jack *jack;
3977 int def_conf = snd_hda_codec_get_pincfg(codec, nid);
3978 int connectivity = get_defcfg_connect(def_conf);
3979 char name[32];
3980 int err;
3982 if (connectivity && connectivity != AC_JACK_PORT_FIXED)
3983 return 0;
3985 snd_array_init(&spec->jacks, sizeof(*jack), 32);
3986 jack = snd_array_new(&spec->jacks);
3987 if (!jack)
3988 return -ENOMEM;
3989 jack->nid = nid;
3990 jack->type = type;
3992 sprintf(name, "%s at %s %s Jack",
3993 snd_hda_get_jack_type(def_conf),
3994 snd_hda_get_jack_connectivity(def_conf),
3995 snd_hda_get_jack_location(def_conf));
3997 err = snd_jack_new(codec->bus->card, name, type, &jack->jack);
3998 if (err < 0) {
3999 jack->nid = 0;
4000 return err;
4002 jack->jack->private_data = jack;
4003 jack->jack->private_free = stac92xx_free_jack_priv;
4004 #endif
4005 return 0;
4008 static int stac_add_event(struct sigmatel_spec *spec, hda_nid_t nid,
4009 unsigned char type, int data)
4011 struct sigmatel_event *event;
4013 snd_array_init(&spec->events, sizeof(*event), 32);
4014 event = snd_array_new(&spec->events);
4015 if (!event)
4016 return -ENOMEM;
4017 event->nid = nid;
4018 event->type = type;
4019 event->tag = spec->events.used;
4020 event->data = data;
4022 return event->tag;
4025 static struct sigmatel_event *stac_get_event(struct hda_codec *codec,
4026 hda_nid_t nid, unsigned char type)
4028 struct sigmatel_spec *spec = codec->spec;
4029 struct sigmatel_event *event = spec->events.list;
4030 int i;
4032 for (i = 0; i < spec->events.used; i++, event++) {
4033 if (event->nid == nid && event->type == type)
4034 return event;
4036 return NULL;
4039 static struct sigmatel_event *stac_get_event_from_tag(struct hda_codec *codec,
4040 unsigned char tag)
4042 struct sigmatel_spec *spec = codec->spec;
4043 struct sigmatel_event *event = spec->events.list;
4044 int i;
4046 for (i = 0; i < spec->events.used; i++, event++) {
4047 if (event->tag == tag)
4048 return event;
4050 return NULL;
4053 static void enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
4054 unsigned int type)
4056 struct sigmatel_event *event;
4057 int tag;
4059 if (!(get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP))
4060 return;
4061 event = stac_get_event(codec, nid, type);
4062 if (event)
4063 tag = event->tag;
4064 else
4065 tag = stac_add_event(codec->spec, nid, type, 0);
4066 if (tag < 0)
4067 return;
4068 snd_hda_codec_write_cache(codec, nid, 0,
4069 AC_VERB_SET_UNSOLICITED_ENABLE,
4070 AC_USRSP_EN | tag);
4073 static int is_nid_hp_pin(struct auto_pin_cfg *cfg, hda_nid_t nid)
4075 int i;
4076 for (i = 0; i < cfg->hp_outs; i++)
4077 if (cfg->hp_pins[i] == nid)
4078 return 1; /* nid is a HP-Out */
4080 return 0; /* nid is not a HP-Out */
4083 static void stac92xx_power_down(struct hda_codec *codec)
4085 struct sigmatel_spec *spec = codec->spec;
4087 /* power down inactive DACs */
4088 hda_nid_t *dac;
4089 for (dac = spec->dac_list; *dac; dac++)
4090 if (!check_all_dac_nids(spec, *dac))
4091 snd_hda_codec_write(codec, *dac, 0,
4092 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
4095 static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
4096 int enable);
4098 /* override some hints from the hwdep entry */
4099 static void stac_store_hints(struct hda_codec *codec)
4101 struct sigmatel_spec *spec = codec->spec;
4102 const char *p;
4103 int val;
4105 val = snd_hda_get_bool_hint(codec, "hp_detect");
4106 if (val >= 0)
4107 spec->hp_detect = val;
4108 p = snd_hda_get_hint(codec, "gpio_mask");
4109 if (p) {
4110 spec->gpio_mask = simple_strtoul(p, NULL, 0);
4111 spec->eapd_mask = spec->gpio_dir = spec->gpio_data =
4112 spec->gpio_mask;
4114 p = snd_hda_get_hint(codec, "gpio_dir");
4115 if (p)
4116 spec->gpio_dir = simple_strtoul(p, NULL, 0) & spec->gpio_mask;
4117 p = snd_hda_get_hint(codec, "gpio_data");
4118 if (p)
4119 spec->gpio_data = simple_strtoul(p, NULL, 0) & spec->gpio_mask;
4120 p = snd_hda_get_hint(codec, "eapd_mask");
4121 if (p)
4122 spec->eapd_mask = simple_strtoul(p, NULL, 0) & spec->gpio_mask;
4123 val = snd_hda_get_bool_hint(codec, "eapd_switch");
4124 if (val >= 0)
4125 spec->eapd_switch = val;
4128 static int stac92xx_init(struct hda_codec *codec)
4130 struct sigmatel_spec *spec = codec->spec;
4131 struct auto_pin_cfg *cfg = &spec->autocfg;
4132 unsigned int gpio;
4133 int i;
4135 snd_hda_sequence_write(codec, spec->init);
4137 /* power down adcs initially */
4138 if (spec->powerdown_adcs)
4139 for (i = 0; i < spec->num_adcs; i++)
4140 snd_hda_codec_write(codec,
4141 spec->adc_nids[i], 0,
4142 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
4144 /* override some hints */
4145 stac_store_hints(codec);
4147 /* set up GPIO */
4148 gpio = spec->gpio_data;
4149 /* turn on EAPD statically when spec->eapd_switch isn't set.
4150 * otherwise, unsol event will turn it on/off dynamically
4152 if (!spec->eapd_switch)
4153 gpio |= spec->eapd_mask;
4154 stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, gpio);
4156 /* set up pins */
4157 if (spec->hp_detect) {
4158 /* Enable unsolicited responses on the HP widget */
4159 for (i = 0; i < cfg->hp_outs; i++) {
4160 hda_nid_t nid = cfg->hp_pins[i];
4161 enable_pin_detect(codec, nid, STAC_HP_EVENT);
4163 /* force to enable the first line-out; the others are set up
4164 * in unsol_event
4166 stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
4167 AC_PINCTL_OUT_EN);
4168 /* fake event to set up pins */
4169 stac_issue_unsol_event(codec, spec->autocfg.hp_pins[0],
4170 STAC_HP_EVENT);
4171 } else {
4172 stac92xx_auto_init_multi_out(codec);
4173 stac92xx_auto_init_hp_out(codec);
4174 for (i = 0; i < cfg->hp_outs; i++)
4175 stac_toggle_power_map(codec, cfg->hp_pins[i], 1);
4177 for (i = 0; i < AUTO_PIN_LAST; i++) {
4178 hda_nid_t nid = cfg->input_pins[i];
4179 if (nid) {
4180 unsigned int pinctl, conf;
4181 if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC) {
4182 /* for mic pins, force to initialize */
4183 pinctl = stac92xx_get_vref(codec, nid);
4184 pinctl |= AC_PINCTL_IN_EN;
4185 stac92xx_auto_set_pinctl(codec, nid, pinctl);
4186 } else {
4187 pinctl = snd_hda_codec_read(codec, nid, 0,
4188 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4189 /* if PINCTL already set then skip */
4190 /* Also, if both INPUT and OUTPUT are set,
4191 * it must be a BIOS bug; need to override, too
4193 if (!(pinctl & AC_PINCTL_IN_EN) ||
4194 (pinctl & AC_PINCTL_OUT_EN)) {
4195 pinctl &= ~AC_PINCTL_OUT_EN;
4196 pinctl |= AC_PINCTL_IN_EN;
4197 stac92xx_auto_set_pinctl(codec, nid,
4198 pinctl);
4201 conf = snd_hda_codec_get_pincfg(codec, nid);
4202 if (get_defcfg_connect(conf) != AC_JACK_PORT_FIXED) {
4203 enable_pin_detect(codec, nid,
4204 STAC_INSERT_EVENT);
4205 stac_issue_unsol_event(codec, nid,
4206 STAC_INSERT_EVENT);
4210 for (i = 0; i < spec->num_dmics; i++)
4211 stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
4212 AC_PINCTL_IN_EN);
4213 if (cfg->dig_out_pins[0])
4214 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pins[0],
4215 AC_PINCTL_OUT_EN);
4216 if (cfg->dig_in_pin)
4217 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
4218 AC_PINCTL_IN_EN);
4219 for (i = 0; i < spec->num_pwrs; i++) {
4220 hda_nid_t nid = spec->pwr_nids[i];
4221 int pinctl, def_conf;
4223 /* power on when no jack detection is available */
4224 if (!spec->hp_detect) {
4225 stac_toggle_power_map(codec, nid, 1);
4226 continue;
4229 if (is_nid_hp_pin(cfg, nid))
4230 continue; /* already has an unsol event */
4232 pinctl = snd_hda_codec_read(codec, nid, 0,
4233 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4234 /* outputs are only ports capable of power management
4235 * any attempts on powering down a input port cause the
4236 * referenced VREF to act quirky.
4238 if (pinctl & AC_PINCTL_IN_EN) {
4239 stac_toggle_power_map(codec, nid, 1);
4240 continue;
4242 def_conf = snd_hda_codec_get_pincfg(codec, nid);
4243 def_conf = get_defcfg_connect(def_conf);
4244 /* skip any ports that don't have jacks since presence
4245 * detection is useless */
4246 if (def_conf != AC_JACK_PORT_COMPLEX) {
4247 if (def_conf != AC_JACK_PORT_NONE)
4248 stac_toggle_power_map(codec, nid, 1);
4249 continue;
4251 if (!stac_get_event(codec, nid, STAC_INSERT_EVENT)) {
4252 enable_pin_detect(codec, nid, STAC_PWR_EVENT);
4253 stac_issue_unsol_event(codec, nid, STAC_PWR_EVENT);
4256 if (spec->dac_list)
4257 stac92xx_power_down(codec);
4258 return 0;
4261 static void stac92xx_free_jacks(struct hda_codec *codec)
4263 #ifdef CONFIG_SND_JACK
4264 /* free jack instances manually when clearing/reconfiguring */
4265 struct sigmatel_spec *spec = codec->spec;
4266 if (!codec->bus->shutdown && spec->jacks.list) {
4267 struct sigmatel_jack *jacks = spec->jacks.list;
4268 int i;
4269 for (i = 0; i < spec->jacks.used; i++, jacks++) {
4270 if (jacks->jack)
4271 snd_device_free(codec->bus->card, jacks->jack);
4274 snd_array_free(&spec->jacks);
4275 #endif
4278 static void stac92xx_free_kctls(struct hda_codec *codec)
4280 struct sigmatel_spec *spec = codec->spec;
4282 if (spec->kctls.list) {
4283 struct snd_kcontrol_new *kctl = spec->kctls.list;
4284 int i;
4285 for (i = 0; i < spec->kctls.used; i++)
4286 kfree(kctl[i].name);
4288 snd_array_free(&spec->kctls);
4291 static void stac92xx_free(struct hda_codec *codec)
4293 struct sigmatel_spec *spec = codec->spec;
4295 if (! spec)
4296 return;
4298 stac92xx_free_jacks(codec);
4299 snd_array_free(&spec->events);
4301 kfree(spec);
4302 snd_hda_detach_beep_device(codec);
4305 static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
4306 unsigned int flag)
4308 unsigned int old_ctl, pin_ctl;
4310 pin_ctl = snd_hda_codec_read(codec, nid,
4311 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
4313 if (pin_ctl & AC_PINCTL_IN_EN) {
4315 * we need to check the current set-up direction of
4316 * shared input pins since they can be switched via
4317 * "xxx as Output" mixer switch
4319 struct sigmatel_spec *spec = codec->spec;
4320 if (nid == spec->line_switch || nid == spec->mic_switch)
4321 return;
4324 old_ctl = pin_ctl;
4325 /* if setting pin direction bits, clear the current
4326 direction bits first */
4327 if (flag & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))
4328 pin_ctl &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
4330 pin_ctl |= flag;
4331 if (old_ctl != pin_ctl)
4332 snd_hda_codec_write_cache(codec, nid, 0,
4333 AC_VERB_SET_PIN_WIDGET_CONTROL,
4334 pin_ctl);
4337 static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
4338 unsigned int flag)
4340 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
4341 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
4342 if (pin_ctl & flag)
4343 snd_hda_codec_write_cache(codec, nid, 0,
4344 AC_VERB_SET_PIN_WIDGET_CONTROL,
4345 pin_ctl & ~flag);
4348 static int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
4350 if (!nid)
4351 return 0;
4352 if (snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PIN_SENSE, 0x00)
4353 & (1 << 31))
4354 return 1;
4355 return 0;
4358 /* return non-zero if the hp-pin of the given array index isn't
4359 * a jack-detection target
4361 static int no_hp_sensing(struct sigmatel_spec *spec, int i)
4363 struct auto_pin_cfg *cfg = &spec->autocfg;
4365 /* ignore sensing of shared line and mic jacks */
4366 if (cfg->hp_pins[i] == spec->line_switch)
4367 return 1;
4368 if (cfg->hp_pins[i] == spec->mic_switch)
4369 return 1;
4370 /* ignore if the pin is set as line-out */
4371 if (cfg->hp_pins[i] == spec->hp_switch)
4372 return 1;
4373 return 0;
4376 static void stac92xx_hp_detect(struct hda_codec *codec)
4378 struct sigmatel_spec *spec = codec->spec;
4379 struct auto_pin_cfg *cfg = &spec->autocfg;
4380 int i, presence;
4382 presence = 0;
4383 if (spec->gpio_mute)
4384 presence = !(snd_hda_codec_read(codec, codec->afg, 0,
4385 AC_VERB_GET_GPIO_DATA, 0) & spec->gpio_mute);
4387 for (i = 0; i < cfg->hp_outs; i++) {
4388 if (presence)
4389 break;
4390 if (no_hp_sensing(spec, i))
4391 continue;
4392 presence = get_pin_presence(codec, cfg->hp_pins[i]);
4393 if (presence) {
4394 unsigned int pinctl;
4395 pinctl = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
4396 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4397 if (pinctl & AC_PINCTL_IN_EN)
4398 presence = 0; /* mic- or line-input */
4402 if (presence) {
4403 /* disable lineouts */
4404 if (spec->hp_switch)
4405 stac92xx_reset_pinctl(codec, spec->hp_switch,
4406 AC_PINCTL_OUT_EN);
4407 for (i = 0; i < cfg->line_outs; i++)
4408 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
4409 AC_PINCTL_OUT_EN);
4410 for (i = 0; i < cfg->speaker_outs; i++)
4411 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
4412 AC_PINCTL_OUT_EN);
4413 if (spec->eapd_mask && spec->eapd_switch)
4414 stac_gpio_set(codec, spec->gpio_mask,
4415 spec->gpio_dir, spec->gpio_data &
4416 ~spec->eapd_mask);
4417 } else {
4418 /* enable lineouts */
4419 if (spec->hp_switch)
4420 stac92xx_set_pinctl(codec, spec->hp_switch,
4421 AC_PINCTL_OUT_EN);
4422 for (i = 0; i < cfg->line_outs; i++)
4423 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
4424 AC_PINCTL_OUT_EN);
4425 for (i = 0; i < cfg->speaker_outs; i++)
4426 stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
4427 AC_PINCTL_OUT_EN);
4428 if (spec->eapd_mask && spec->eapd_switch)
4429 stac_gpio_set(codec, spec->gpio_mask,
4430 spec->gpio_dir, spec->gpio_data |
4431 spec->eapd_mask);
4433 /* toggle hp outs */
4434 for (i = 0; i < cfg->hp_outs; i++) {
4435 unsigned int val = AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN;
4436 if (no_hp_sensing(spec, i))
4437 continue;
4438 if (presence)
4439 stac92xx_set_pinctl(codec, cfg->hp_pins[i], val);
4440 #if 0 /* FIXME */
4441 /* Resetting the pinctl like below may lead to (a sort of) regressions
4442 * on some devices since they use the HP pin actually for line/speaker
4443 * outs although the default pin config shows a different pin (that is
4444 * wrong and useless).
4446 * So, it's basically a problem of default pin configs, likely a BIOS issue.
4447 * But, disabling the code below just works around it, and I'm too tired of
4448 * bug reports with such devices...
4450 else
4451 stac92xx_reset_pinctl(codec, cfg->hp_pins[i], val);
4452 #endif /* FIXME */
4456 static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
4457 int enable)
4459 struct sigmatel_spec *spec = codec->spec;
4460 unsigned int idx, val;
4462 for (idx = 0; idx < spec->num_pwrs; idx++) {
4463 if (spec->pwr_nids[idx] == nid)
4464 break;
4466 if (idx >= spec->num_pwrs)
4467 return;
4469 /* several codecs have two power down bits */
4470 if (spec->pwr_mapping)
4471 idx = spec->pwr_mapping[idx];
4472 else
4473 idx = 1 << idx;
4475 val = snd_hda_codec_read(codec, codec->afg, 0, 0x0fec, 0x0) & 0xff;
4476 if (enable)
4477 val &= ~idx;
4478 else
4479 val |= idx;
4481 /* power down unused output ports */
4482 snd_hda_codec_write(codec, codec->afg, 0, 0x7ec, val);
4485 static void stac92xx_pin_sense(struct hda_codec *codec, hda_nid_t nid)
4487 stac_toggle_power_map(codec, nid, get_pin_presence(codec, nid));
4490 static void stac92xx_report_jack(struct hda_codec *codec, hda_nid_t nid)
4492 struct sigmatel_spec *spec = codec->spec;
4493 struct sigmatel_jack *jacks = spec->jacks.list;
4495 if (jacks) {
4496 int i;
4497 for (i = 0; i < spec->jacks.used; i++) {
4498 if (jacks->nid == nid) {
4499 unsigned int pin_ctl =
4500 snd_hda_codec_read(codec, nid,
4501 0, AC_VERB_GET_PIN_WIDGET_CONTROL,
4502 0x00);
4503 int type = jacks->type;
4504 if (type == (SND_JACK_LINEOUT
4505 | SND_JACK_HEADPHONE))
4506 type = (pin_ctl & AC_PINCTL_HP_EN)
4507 ? SND_JACK_HEADPHONE : SND_JACK_LINEOUT;
4508 snd_jack_report(jacks->jack,
4509 get_pin_presence(codec, nid)
4510 ? type : 0);
4512 jacks++;
4517 static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid,
4518 unsigned char type)
4520 struct sigmatel_event *event = stac_get_event(codec, nid, type);
4521 if (!event)
4522 return;
4523 codec->patch_ops.unsol_event(codec, (unsigned)event->tag << 26);
4526 static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
4528 struct sigmatel_spec *spec = codec->spec;
4529 struct sigmatel_event *event;
4530 int tag, data;
4532 tag = (res >> 26) & 0x7f;
4533 event = stac_get_event_from_tag(codec, tag);
4534 if (!event)
4535 return;
4537 switch (event->type) {
4538 case STAC_HP_EVENT:
4539 stac92xx_hp_detect(codec);
4540 /* fallthru */
4541 case STAC_INSERT_EVENT:
4542 case STAC_PWR_EVENT:
4543 if (spec->num_pwrs > 0)
4544 stac92xx_pin_sense(codec, event->nid);
4545 stac92xx_report_jack(codec, event->nid);
4547 switch (codec->subsystem_id) {
4548 case 0x103c308f:
4549 if (event->nid == 0xb) {
4550 int pin = AC_PINCTL_IN_EN;
4552 if (get_pin_presence(codec, 0xa)
4553 && get_pin_presence(codec, 0xb))
4554 pin |= AC_PINCTL_VREF_80;
4555 if (!get_pin_presence(codec, 0xb))
4556 pin |= AC_PINCTL_VREF_80;
4558 /* toggle VREF state based on mic + hp pin
4559 * status
4561 stac92xx_auto_set_pinctl(codec, 0x0a, pin);
4564 break;
4565 case STAC_VREF_EVENT:
4566 data = snd_hda_codec_read(codec, codec->afg, 0,
4567 AC_VERB_GET_GPIO_DATA, 0);
4568 /* toggle VREF state based on GPIOx status */
4569 snd_hda_codec_write(codec, codec->afg, 0, 0x7e0,
4570 !!(data & (1 << event->data)));
4571 break;
4575 #ifdef CONFIG_PROC_FS
4576 static void stac92hd_proc_hook(struct snd_info_buffer *buffer,
4577 struct hda_codec *codec, hda_nid_t nid)
4579 if (nid == codec->afg)
4580 snd_iprintf(buffer, "Power-Map: 0x%02x\n",
4581 snd_hda_codec_read(codec, nid, 0, 0x0fec, 0x0));
4584 static void analog_loop_proc_hook(struct snd_info_buffer *buffer,
4585 struct hda_codec *codec,
4586 unsigned int verb)
4588 snd_iprintf(buffer, "Analog Loopback: 0x%02x\n",
4589 snd_hda_codec_read(codec, codec->afg, 0, verb, 0));
4592 /* stac92hd71bxx, stac92hd73xx */
4593 static void stac92hd7x_proc_hook(struct snd_info_buffer *buffer,
4594 struct hda_codec *codec, hda_nid_t nid)
4596 stac92hd_proc_hook(buffer, codec, nid);
4597 if (nid == codec->afg)
4598 analog_loop_proc_hook(buffer, codec, 0xfa0);
4601 static void stac9205_proc_hook(struct snd_info_buffer *buffer,
4602 struct hda_codec *codec, hda_nid_t nid)
4604 if (nid == codec->afg)
4605 analog_loop_proc_hook(buffer, codec, 0xfe0);
4608 static void stac927x_proc_hook(struct snd_info_buffer *buffer,
4609 struct hda_codec *codec, hda_nid_t nid)
4611 if (nid == codec->afg)
4612 analog_loop_proc_hook(buffer, codec, 0xfeb);
4614 #else
4615 #define stac92hd_proc_hook NULL
4616 #define stac92hd7x_proc_hook NULL
4617 #define stac9205_proc_hook NULL
4618 #define stac927x_proc_hook NULL
4619 #endif
4621 #ifdef SND_HDA_NEEDS_RESUME
4622 static int stac92xx_resume(struct hda_codec *codec)
4624 struct sigmatel_spec *spec = codec->spec;
4626 stac92xx_init(codec);
4627 snd_hda_codec_resume_amp(codec);
4628 snd_hda_codec_resume_cache(codec);
4629 /* fake event to set up pins again to override cached values */
4630 if (spec->hp_detect)
4631 stac_issue_unsol_event(codec, spec->autocfg.hp_pins[0],
4632 STAC_HP_EVENT);
4633 return 0;
4637 * using power check for controlling mute led of HP notebooks
4638 * check for mute state only on Speakers (nid = 0x10)
4640 * For this feature CONFIG_SND_HDA_POWER_SAVE is needed, otherwise
4641 * the LED is NOT working properly !
4643 * Changed name to reflect that it now works for any designated
4644 * model, not just HP HDX.
4647 #ifdef CONFIG_SND_HDA_POWER_SAVE
4648 static int stac92xx_hp_check_power_status(struct hda_codec *codec,
4649 hda_nid_t nid)
4651 struct sigmatel_spec *spec = codec->spec;
4652 unsigned int gpio_bit = 0; /* gets rid of compiler warning */
4654 switch (spec->board_config) {
4655 case STAC_HP_DV4_1222NR:
4656 gpio_bit = 0x01;
4657 break;
4658 case STAC_HP_HDX:
4659 gpio_bit = 0x08;
4662 if (nid == 0x10) {
4663 if (snd_hda_codec_amp_read(codec, nid, 0, HDA_OUTPUT, 0) &
4664 HDA_AMP_MUTE)
4665 spec->gpio_data &= ~gpio_bit; /* orange */
4666 else
4667 spec->gpio_data |= gpio_bit; /* white */
4669 stac_gpio_set(codec, spec->gpio_mask,
4670 spec->gpio_dir,
4671 spec->gpio_data);
4674 return 0;
4676 #endif
4678 static int stac92xx_suspend(struct hda_codec *codec, pm_message_t state)
4680 struct sigmatel_spec *spec = codec->spec;
4681 if (spec->eapd_mask)
4682 stac_gpio_set(codec, spec->gpio_mask,
4683 spec->gpio_dir, spec->gpio_data &
4684 ~spec->eapd_mask);
4685 return 0;
4687 #endif
4689 static struct hda_codec_ops stac92xx_patch_ops = {
4690 .build_controls = stac92xx_build_controls,
4691 .build_pcms = stac92xx_build_pcms,
4692 .init = stac92xx_init,
4693 .free = stac92xx_free,
4694 .unsol_event = stac92xx_unsol_event,
4695 #ifdef SND_HDA_NEEDS_RESUME
4696 .suspend = stac92xx_suspend,
4697 .resume = stac92xx_resume,
4698 #endif
4701 static int patch_stac9200(struct hda_codec *codec)
4703 struct sigmatel_spec *spec;
4704 int err;
4706 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4707 if (spec == NULL)
4708 return -ENOMEM;
4710 codec->spec = spec;
4711 spec->num_pins = ARRAY_SIZE(stac9200_pin_nids);
4712 spec->pin_nids = stac9200_pin_nids;
4713 spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS,
4714 stac9200_models,
4715 stac9200_cfg_tbl);
4716 if (spec->board_config < 0)
4717 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9200, using BIOS defaults\n");
4718 else
4719 stac92xx_set_config_regs(codec,
4720 stac9200_brd_tbl[spec->board_config]);
4722 spec->multiout.max_channels = 2;
4723 spec->multiout.num_dacs = 1;
4724 spec->multiout.dac_nids = stac9200_dac_nids;
4725 spec->adc_nids = stac9200_adc_nids;
4726 spec->mux_nids = stac9200_mux_nids;
4727 spec->num_muxes = 1;
4728 spec->num_dmics = 0;
4729 spec->num_adcs = 1;
4730 spec->num_pwrs = 0;
4732 if (spec->board_config == STAC_9200_M4 ||
4733 spec->board_config == STAC_9200_M4_2 ||
4734 spec->board_config == STAC_9200_OQO)
4735 spec->init = stac9200_eapd_init;
4736 else
4737 spec->init = stac9200_core_init;
4738 spec->mixer = stac9200_mixer;
4740 if (spec->board_config == STAC_9200_PANASONIC) {
4741 spec->gpio_mask = spec->gpio_dir = 0x09;
4742 spec->gpio_data = 0x00;
4745 err = stac9200_parse_auto_config(codec);
4746 if (err < 0) {
4747 stac92xx_free(codec);
4748 return err;
4751 /* CF-74 has no headphone detection, and the driver should *NOT*
4752 * do detection and HP/speaker toggle because the hardware does it.
4754 if (spec->board_config == STAC_9200_PANASONIC)
4755 spec->hp_detect = 0;
4757 codec->patch_ops = stac92xx_patch_ops;
4759 return 0;
4762 static int patch_stac925x(struct hda_codec *codec)
4764 struct sigmatel_spec *spec;
4765 int err;
4767 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4768 if (spec == NULL)
4769 return -ENOMEM;
4771 codec->spec = spec;
4772 spec->num_pins = ARRAY_SIZE(stac925x_pin_nids);
4773 spec->pin_nids = stac925x_pin_nids;
4775 /* Check first for codec ID */
4776 spec->board_config = snd_hda_check_board_codec_sid_config(codec,
4777 STAC_925x_MODELS,
4778 stac925x_models,
4779 stac925x_codec_id_cfg_tbl);
4781 /* Now checks for PCI ID, if codec ID is not found */
4782 if (spec->board_config < 0)
4783 spec->board_config = snd_hda_check_board_config(codec,
4784 STAC_925x_MODELS,
4785 stac925x_models,
4786 stac925x_cfg_tbl);
4787 again:
4788 if (spec->board_config < 0)
4789 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC925x,"
4790 "using BIOS defaults\n");
4791 else
4792 stac92xx_set_config_regs(codec,
4793 stac925x_brd_tbl[spec->board_config]);
4795 spec->multiout.max_channels = 2;
4796 spec->multiout.num_dacs = 1;
4797 spec->multiout.dac_nids = stac925x_dac_nids;
4798 spec->adc_nids = stac925x_adc_nids;
4799 spec->mux_nids = stac925x_mux_nids;
4800 spec->num_muxes = 1;
4801 spec->num_adcs = 1;
4802 spec->num_pwrs = 0;
4803 switch (codec->vendor_id) {
4804 case 0x83847632: /* STAC9202 */
4805 case 0x83847633: /* STAC9202D */
4806 case 0x83847636: /* STAC9251 */
4807 case 0x83847637: /* STAC9251D */
4808 spec->num_dmics = STAC925X_NUM_DMICS;
4809 spec->dmic_nids = stac925x_dmic_nids;
4810 spec->num_dmuxes = ARRAY_SIZE(stac925x_dmux_nids);
4811 spec->dmux_nids = stac925x_dmux_nids;
4812 break;
4813 default:
4814 spec->num_dmics = 0;
4815 break;
4818 spec->init = stac925x_core_init;
4819 spec->mixer = stac925x_mixer;
4821 err = stac92xx_parse_auto_config(codec, 0x8, 0x7);
4822 if (!err) {
4823 if (spec->board_config < 0) {
4824 printk(KERN_WARNING "hda_codec: No auto-config is "
4825 "available, default to model=ref\n");
4826 spec->board_config = STAC_925x_REF;
4827 goto again;
4829 err = -EINVAL;
4831 if (err < 0) {
4832 stac92xx_free(codec);
4833 return err;
4836 codec->patch_ops = stac92xx_patch_ops;
4838 return 0;
4841 static struct hda_input_mux stac92hd73xx_dmux = {
4842 .num_items = 4,
4843 .items = {
4844 { "Analog Inputs", 0x0b },
4845 { "Digital Mic 1", 0x09 },
4846 { "Digital Mic 2", 0x0a },
4847 { "CD", 0x08 },
4851 static int patch_stac92hd73xx(struct hda_codec *codec)
4853 struct sigmatel_spec *spec;
4854 hda_nid_t conn[STAC92HD73_DAC_COUNT + 2];
4855 int err = 0;
4856 int num_dacs;
4858 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4859 if (spec == NULL)
4860 return -ENOMEM;
4862 codec->spec = spec;
4863 codec->slave_dig_outs = stac92hd73xx_slave_dig_outs;
4864 spec->num_pins = ARRAY_SIZE(stac92hd73xx_pin_nids);
4865 spec->pin_nids = stac92hd73xx_pin_nids;
4866 spec->board_config = snd_hda_check_board_config(codec,
4867 STAC_92HD73XX_MODELS,
4868 stac92hd73xx_models,
4869 stac92hd73xx_cfg_tbl);
4870 again:
4871 if (spec->board_config < 0)
4872 snd_printdd(KERN_INFO "hda_codec: Unknown model for"
4873 " STAC92HD73XX, using BIOS defaults\n");
4874 else
4875 stac92xx_set_config_regs(codec,
4876 stac92hd73xx_brd_tbl[spec->board_config]);
4878 num_dacs = snd_hda_get_connections(codec, 0x0a,
4879 conn, STAC92HD73_DAC_COUNT + 2) - 1;
4881 if (num_dacs < 3 || num_dacs > 5) {
4882 printk(KERN_WARNING "hda_codec: Could not determine "
4883 "number of channels defaulting to DAC count\n");
4884 num_dacs = STAC92HD73_DAC_COUNT;
4886 switch (num_dacs) {
4887 case 0x3: /* 6 Channel */
4888 spec->mixer = stac92hd73xx_6ch_mixer;
4889 spec->init = stac92hd73xx_6ch_core_init;
4890 spec->aloopback_ctl = stac92hd73xx_6ch_loopback;
4891 break;
4892 case 0x4: /* 8 Channel */
4893 spec->mixer = stac92hd73xx_8ch_mixer;
4894 spec->init = stac92hd73xx_8ch_core_init;
4895 spec->aloopback_ctl = stac92hd73xx_8ch_loopback;
4896 break;
4897 case 0x5: /* 10 Channel */
4898 spec->mixer = stac92hd73xx_10ch_mixer;
4899 spec->init = stac92hd73xx_10ch_core_init;
4900 spec->aloopback_ctl = stac92hd73xx_10ch_loopback;
4901 break;
4903 spec->multiout.dac_nids = spec->dac_nids;
4905 spec->aloopback_mask = 0x01;
4906 spec->aloopback_shift = 8;
4908 spec->digbeep_nid = 0x1c;
4909 spec->mux_nids = stac92hd73xx_mux_nids;
4910 spec->adc_nids = stac92hd73xx_adc_nids;
4911 spec->dmic_nids = stac92hd73xx_dmic_nids;
4912 spec->dmux_nids = stac92hd73xx_dmux_nids;
4913 spec->smux_nids = stac92hd73xx_smux_nids;
4914 spec->amp_nids = stac92hd73xx_amp_nids;
4915 spec->num_amps = ARRAY_SIZE(stac92hd73xx_amp_nids);
4917 spec->num_muxes = ARRAY_SIZE(stac92hd73xx_mux_nids);
4918 spec->num_adcs = ARRAY_SIZE(stac92hd73xx_adc_nids);
4919 spec->num_dmuxes = ARRAY_SIZE(stac92hd73xx_dmux_nids);
4920 memcpy(&spec->private_dimux, &stac92hd73xx_dmux,
4921 sizeof(stac92hd73xx_dmux));
4923 switch (spec->board_config) {
4924 case STAC_DELL_EQ:
4925 spec->init = dell_eq_core_init;
4926 /* fallthru */
4927 case STAC_DELL_M6_AMIC:
4928 case STAC_DELL_M6_DMIC:
4929 case STAC_DELL_M6_BOTH:
4930 spec->num_smuxes = 0;
4931 spec->mixer = &stac92hd73xx_6ch_mixer[DELL_M6_MIXER];
4932 spec->amp_nids = &stac92hd73xx_amp_nids[DELL_M6_AMP];
4933 spec->eapd_switch = 0;
4934 spec->num_amps = 1;
4936 if (spec->board_config != STAC_DELL_EQ)
4937 spec->init = dell_m6_core_init;
4938 switch (spec->board_config) {
4939 case STAC_DELL_M6_AMIC: /* Analog Mics */
4940 snd_hda_codec_set_pincfg(codec, 0x0b, 0x90A70170);
4941 spec->num_dmics = 0;
4942 spec->private_dimux.num_items = 1;
4943 break;
4944 case STAC_DELL_M6_DMIC: /* Digital Mics */
4945 snd_hda_codec_set_pincfg(codec, 0x13, 0x90A60160);
4946 spec->num_dmics = 1;
4947 spec->private_dimux.num_items = 2;
4948 break;
4949 case STAC_DELL_M6_BOTH: /* Both */
4950 snd_hda_codec_set_pincfg(codec, 0x0b, 0x90A70170);
4951 snd_hda_codec_set_pincfg(codec, 0x13, 0x90A60160);
4952 spec->num_dmics = 1;
4953 spec->private_dimux.num_items = 2;
4954 break;
4956 break;
4957 default:
4958 spec->num_dmics = STAC92HD73XX_NUM_DMICS;
4959 spec->num_smuxes = ARRAY_SIZE(stac92hd73xx_smux_nids);
4960 spec->eapd_switch = 1;
4962 if (spec->board_config > STAC_92HD73XX_REF) {
4963 /* GPIO0 High = Enable EAPD */
4964 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
4965 spec->gpio_data = 0x01;
4967 spec->dinput_mux = &spec->private_dimux;
4969 spec->num_pwrs = ARRAY_SIZE(stac92hd73xx_pwr_nids);
4970 spec->pwr_nids = stac92hd73xx_pwr_nids;
4972 err = stac92xx_parse_auto_config(codec, 0x25, 0x27);
4974 if (!err) {
4975 if (spec->board_config < 0) {
4976 printk(KERN_WARNING "hda_codec: No auto-config is "
4977 "available, default to model=ref\n");
4978 spec->board_config = STAC_92HD73XX_REF;
4979 goto again;
4981 err = -EINVAL;
4984 if (err < 0) {
4985 stac92xx_free(codec);
4986 return err;
4989 if (spec->board_config == STAC_92HD73XX_NO_JD)
4990 spec->hp_detect = 0;
4992 codec->patch_ops = stac92xx_patch_ops;
4994 codec->proc_widget_hook = stac92hd7x_proc_hook;
4996 return 0;
4999 static struct hda_input_mux stac92hd83xxx_dmux = {
5000 .num_items = 3,
5001 .items = {
5002 { "Analog Inputs", 0x03 },
5003 { "Digital Mic 1", 0x04 },
5004 { "Digital Mic 2", 0x05 },
5008 static int patch_stac92hd83xxx(struct hda_codec *codec)
5010 struct sigmatel_spec *spec;
5011 hda_nid_t conn[STAC92HD83_DAC_COUNT + 1];
5012 int err;
5013 int num_dacs;
5014 hda_nid_t nid;
5016 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5017 if (spec == NULL)
5018 return -ENOMEM;
5020 codec->spec = spec;
5021 codec->slave_dig_outs = stac92hd83xxx_slave_dig_outs;
5022 spec->mono_nid = 0x19;
5023 spec->digbeep_nid = 0x21;
5024 spec->dmic_nids = stac92hd83xxx_dmic_nids;
5025 spec->dmux_nids = stac92hd83xxx_dmux_nids;
5026 spec->adc_nids = stac92hd83xxx_adc_nids;
5027 spec->pwr_nids = stac92hd83xxx_pwr_nids;
5028 spec->amp_nids = stac92hd83xxx_amp_nids;
5029 spec->pwr_mapping = stac92hd83xxx_pwr_mapping;
5030 spec->num_pwrs = ARRAY_SIZE(stac92hd83xxx_pwr_nids);
5031 spec->multiout.dac_nids = spec->dac_nids;
5033 spec->init = stac92hd83xxx_core_init;
5034 spec->mixer = stac92hd83xxx_mixer;
5035 spec->num_pins = ARRAY_SIZE(stac92hd83xxx_pin_nids);
5036 spec->num_dmuxes = ARRAY_SIZE(stac92hd83xxx_dmux_nids);
5037 spec->num_adcs = ARRAY_SIZE(stac92hd83xxx_adc_nids);
5038 spec->num_amps = ARRAY_SIZE(stac92hd83xxx_amp_nids);
5039 spec->num_dmics = STAC92HD83XXX_NUM_DMICS;
5040 spec->dinput_mux = &stac92hd83xxx_dmux;
5041 spec->pin_nids = stac92hd83xxx_pin_nids;
5042 spec->board_config = snd_hda_check_board_config(codec,
5043 STAC_92HD83XXX_MODELS,
5044 stac92hd83xxx_models,
5045 stac92hd83xxx_cfg_tbl);
5046 again:
5047 if (spec->board_config < 0)
5048 snd_printdd(KERN_INFO "hda_codec: Unknown model for"
5049 " STAC92HD83XXX, using BIOS defaults\n");
5050 else
5051 stac92xx_set_config_regs(codec,
5052 stac92hd83xxx_brd_tbl[spec->board_config]);
5054 switch (codec->vendor_id) {
5055 case 0x111d7604:
5056 case 0x111d7605:
5057 case 0x111d76d5:
5058 if (spec->board_config == STAC_92HD83XXX_PWR_REF)
5059 break;
5060 spec->num_pwrs = 0;
5061 break;
5064 err = stac92xx_parse_auto_config(codec, 0x1d, 0);
5065 if (!err) {
5066 if (spec->board_config < 0) {
5067 printk(KERN_WARNING "hda_codec: No auto-config is "
5068 "available, default to model=ref\n");
5069 spec->board_config = STAC_92HD83XXX_REF;
5070 goto again;
5072 err = -EINVAL;
5075 if (err < 0) {
5076 stac92xx_free(codec);
5077 return err;
5080 switch (spec->board_config) {
5081 case STAC_DELL_S14:
5082 nid = 0xf;
5083 break;
5084 default:
5085 nid = 0xe;
5086 break;
5089 num_dacs = snd_hda_get_connections(codec, nid,
5090 conn, STAC92HD83_DAC_COUNT + 1) - 1;
5092 /* set port X to select the last DAC
5094 snd_hda_codec_write_cache(codec, nid, 0,
5095 AC_VERB_SET_CONNECT_SEL, num_dacs);
5097 codec->patch_ops = stac92xx_patch_ops;
5099 codec->proc_widget_hook = stac92hd_proc_hook;
5101 return 0;
5104 static struct hda_input_mux stac92hd71bxx_dmux_nomixer = {
5105 .num_items = 3,
5106 .items = {
5107 { "Analog Inputs", 0x00 },
5108 { "Digital Mic 1", 0x02 },
5109 { "Digital Mic 2", 0x03 },
5113 static struct hda_input_mux stac92hd71bxx_dmux_amixer = {
5114 .num_items = 4,
5115 .items = {
5116 { "Analog Inputs", 0x00 },
5117 { "Mixer", 0x01 },
5118 { "Digital Mic 1", 0x02 },
5119 { "Digital Mic 2", 0x03 },
5123 /* get the pin connection (fixed, none, etc) */
5124 static unsigned int stac_get_defcfg_connect(struct hda_codec *codec, int idx)
5126 struct sigmatel_spec *spec = codec->spec;
5127 unsigned int cfg;
5129 cfg = snd_hda_codec_get_pincfg(codec, spec->pin_nids[idx]);
5130 return get_defcfg_connect(cfg);
5133 static int stac92hd71bxx_connected_ports(struct hda_codec *codec,
5134 hda_nid_t *nids, int num_nids)
5136 struct sigmatel_spec *spec = codec->spec;
5137 int idx, num;
5138 unsigned int def_conf;
5140 for (num = 0; num < num_nids; num++) {
5141 for (idx = 0; idx < spec->num_pins; idx++)
5142 if (spec->pin_nids[idx] == nids[num])
5143 break;
5144 if (idx >= spec->num_pins)
5145 break;
5146 def_conf = stac_get_defcfg_connect(codec, idx);
5147 if (def_conf == AC_JACK_PORT_NONE)
5148 break;
5150 return num;
5153 static int stac92hd71bxx_connected_smuxes(struct hda_codec *codec,
5154 hda_nid_t dig0pin)
5156 struct sigmatel_spec *spec = codec->spec;
5157 int idx;
5159 for (idx = 0; idx < spec->num_pins; idx++)
5160 if (spec->pin_nids[idx] == dig0pin)
5161 break;
5162 if ((idx + 2) >= spec->num_pins)
5163 return 0;
5165 /* dig1pin case */
5166 if (stac_get_defcfg_connect(codec, idx + 1) != AC_JACK_PORT_NONE)
5167 return 2;
5169 /* dig0pin + dig2pin case */
5170 if (stac_get_defcfg_connect(codec, idx + 2) != AC_JACK_PORT_NONE)
5171 return 2;
5172 if (stac_get_defcfg_connect(codec, idx) != AC_JACK_PORT_NONE)
5173 return 1;
5174 else
5175 return 0;
5178 static int patch_stac92hd71bxx(struct hda_codec *codec)
5180 struct sigmatel_spec *spec;
5181 struct hda_verb *unmute_init = stac92hd71bxx_unmute_core_init;
5182 int err = 0;
5183 unsigned int ndmic_nids = 0;
5185 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5186 if (spec == NULL)
5187 return -ENOMEM;
5189 codec->spec = spec;
5190 codec->patch_ops = stac92xx_patch_ops;
5191 spec->num_pins = STAC92HD71BXX_NUM_PINS;
5192 switch (codec->vendor_id) {
5193 case 0x111d76b6:
5194 case 0x111d76b7:
5195 spec->pin_nids = stac92hd71bxx_pin_nids_4port;
5196 break;
5197 case 0x111d7603:
5198 case 0x111d7608:
5199 /* On 92HD75Bx 0x27 isn't a pin nid */
5200 spec->num_pins--;
5201 /* fallthrough */
5202 default:
5203 spec->pin_nids = stac92hd71bxx_pin_nids_6port;
5205 spec->num_pwrs = ARRAY_SIZE(stac92hd71bxx_pwr_nids);
5206 spec->board_config = snd_hda_check_board_config(codec,
5207 STAC_92HD71BXX_MODELS,
5208 stac92hd71bxx_models,
5209 stac92hd71bxx_cfg_tbl);
5210 again:
5211 if (spec->board_config < 0)
5212 snd_printdd(KERN_INFO "hda_codec: Unknown model for"
5213 " STAC92HD71BXX, using BIOS defaults\n");
5214 else
5215 stac92xx_set_config_regs(codec,
5216 stac92hd71bxx_brd_tbl[spec->board_config]);
5218 if (spec->board_config > STAC_92HD71BXX_REF) {
5219 /* GPIO0 = EAPD */
5220 spec->gpio_mask = 0x01;
5221 spec->gpio_dir = 0x01;
5222 spec->gpio_data = 0x01;
5225 spec->dmic_nids = stac92hd71bxx_dmic_nids;
5226 spec->dmux_nids = stac92hd71bxx_dmux_nids;
5228 switch (codec->vendor_id) {
5229 case 0x111d76b6: /* 4 Port without Analog Mixer */
5230 case 0x111d76b7:
5231 unmute_init++;
5232 /* fallthru */
5233 case 0x111d76b4: /* 6 Port without Analog Mixer */
5234 case 0x111d76b5:
5235 memcpy(&spec->private_dimux, &stac92hd71bxx_dmux_nomixer,
5236 sizeof(stac92hd71bxx_dmux_nomixer));
5237 spec->mixer = stac92hd71bxx_mixer;
5238 spec->init = stac92hd71bxx_core_init;
5239 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
5240 spec->num_dmics = stac92hd71bxx_connected_ports(codec,
5241 stac92hd71bxx_dmic_nids,
5242 STAC92HD71BXX_NUM_DMICS);
5243 if (spec->num_dmics) {
5244 spec->num_dmuxes = ARRAY_SIZE(stac92hd71bxx_dmux_nids);
5245 spec->dinput_mux = &spec->private_dimux;
5246 ndmic_nids = ARRAY_SIZE(stac92hd71bxx_dmic_nids) - 1;
5248 break;
5249 case 0x111d7608: /* 5 Port with Analog Mixer */
5250 memcpy(&spec->private_dimux, &stac92hd71bxx_dmux_amixer,
5251 sizeof(stac92hd71bxx_dmux_amixer));
5252 spec->private_dimux.num_items--;
5253 switch (spec->board_config) {
5254 case STAC_HP_M4:
5255 /* Enable VREF power saving on GPIO1 detect */
5256 err = stac_add_event(spec, codec->afg,
5257 STAC_VREF_EVENT, 0x02);
5258 if (err < 0)
5259 return err;
5260 snd_hda_codec_write_cache(codec, codec->afg, 0,
5261 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x02);
5262 snd_hda_codec_write_cache(codec, codec->afg, 0,
5263 AC_VERB_SET_UNSOLICITED_ENABLE,
5264 AC_USRSP_EN | err);
5265 spec->gpio_mask |= 0x02;
5266 break;
5268 if ((codec->revision_id & 0xf) == 0 ||
5269 (codec->revision_id & 0xf) == 1)
5270 spec->stream_delay = 40; /* 40 milliseconds */
5272 /* no output amps */
5273 spec->num_pwrs = 0;
5274 spec->mixer = stac92hd71bxx_analog_mixer;
5275 spec->dinput_mux = &spec->private_dimux;
5277 /* disable VSW */
5278 spec->init = &stac92hd71bxx_analog_core_init[HD_DISABLE_PORTF];
5279 unmute_init++;
5280 snd_hda_codec_set_pincfg(codec, 0x0f, 0x40f000f0);
5281 snd_hda_codec_set_pincfg(codec, 0x19, 0x40f000f3);
5282 stac92hd71bxx_dmic_nids[STAC92HD71BXX_NUM_DMICS - 1] = 0;
5283 spec->num_dmics = stac92hd71bxx_connected_ports(codec,
5284 stac92hd71bxx_dmic_nids,
5285 STAC92HD71BXX_NUM_DMICS - 1);
5286 spec->num_dmuxes = ARRAY_SIZE(stac92hd71bxx_dmux_nids);
5287 ndmic_nids = ARRAY_SIZE(stac92hd71bxx_dmic_nids) - 2;
5288 break;
5289 case 0x111d7603: /* 6 Port with Analog Mixer */
5290 if ((codec->revision_id & 0xf) == 1)
5291 spec->stream_delay = 40; /* 40 milliseconds */
5293 /* no output amps */
5294 spec->num_pwrs = 0;
5295 /* fallthru */
5296 default:
5297 memcpy(&spec->private_dimux, &stac92hd71bxx_dmux_amixer,
5298 sizeof(stac92hd71bxx_dmux_amixer));
5299 spec->dinput_mux = &spec->private_dimux;
5300 spec->mixer = stac92hd71bxx_analog_mixer;
5301 spec->init = stac92hd71bxx_analog_core_init;
5302 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
5303 spec->num_dmics = stac92hd71bxx_connected_ports(codec,
5304 stac92hd71bxx_dmic_nids,
5305 STAC92HD71BXX_NUM_DMICS);
5306 spec->num_dmuxes = ARRAY_SIZE(stac92hd71bxx_dmux_nids);
5307 ndmic_nids = ARRAY_SIZE(stac92hd71bxx_dmic_nids) - 1;
5310 if (get_wcaps(codec, 0xa) & AC_WCAP_IN_AMP)
5311 snd_hda_sequence_write_cache(codec, unmute_init);
5313 spec->aloopback_ctl = stac92hd71bxx_loopback;
5314 spec->aloopback_mask = 0x50;
5315 spec->aloopback_shift = 0;
5317 spec->powerdown_adcs = 1;
5318 spec->digbeep_nid = 0x26;
5319 spec->mux_nids = stac92hd71bxx_mux_nids;
5320 spec->adc_nids = stac92hd71bxx_adc_nids;
5321 spec->smux_nids = stac92hd71bxx_smux_nids;
5322 spec->pwr_nids = stac92hd71bxx_pwr_nids;
5324 spec->num_muxes = ARRAY_SIZE(stac92hd71bxx_mux_nids);
5325 spec->num_adcs = ARRAY_SIZE(stac92hd71bxx_adc_nids);
5326 spec->num_smuxes = stac92hd71bxx_connected_smuxes(codec, 0x1e);
5328 switch (spec->board_config) {
5329 case STAC_HP_M4:
5330 /* enable internal microphone */
5331 snd_hda_codec_set_pincfg(codec, 0x0e, 0x01813040);
5332 stac92xx_auto_set_pinctl(codec, 0x0e,
5333 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80);
5334 /* fallthru */
5335 case STAC_DELL_M4_2:
5336 spec->num_dmics = 0;
5337 spec->num_smuxes = 0;
5338 spec->num_dmuxes = 0;
5339 break;
5340 case STAC_DELL_M4_1:
5341 case STAC_DELL_M4_3:
5342 spec->num_dmics = 1;
5343 spec->num_smuxes = 0;
5344 spec->num_dmuxes = 1;
5345 break;
5346 case STAC_HP_DV4_1222NR:
5347 spec->num_dmics = 1;
5348 /* I don't know if it needs 1 or 2 smuxes - will wait for
5349 * bug reports to fix if needed
5351 spec->num_smuxes = 1;
5352 spec->num_dmuxes = 1;
5353 #ifdef CONFIG_SND_HDA_POWER_SAVE
5354 /* This controls MUTE LED */
5355 spec->gpio_mask |= 0x01;
5356 spec->gpio_dir |= 0x01;
5357 spec->gpio_data |= 0x01;
5358 codec->patch_ops.check_power_status =
5359 stac92xx_hp_check_power_status;
5360 #endif
5361 /* fallthrough */
5362 case STAC_HP_DV5:
5363 snd_hda_codec_set_pincfg(codec, 0x0d, 0x90170010);
5364 stac92xx_auto_set_pinctl(codec, 0x0d, AC_PINCTL_OUT_EN);
5365 break;
5366 case STAC_HP_HDX:
5367 spec->num_dmics = 1;
5368 spec->num_dmuxes = 1;
5369 spec->num_smuxes = 1;
5371 * For controlling MUTE LED on HP HDX16/HDX18 notebooks,
5372 * the CONFIG_SND_HDA_POWER_SAVE is needed to be set.
5374 #ifdef CONFIG_SND_HDA_POWER_SAVE
5375 /* orange/white mute led on GPIO3, orange=0, white=1 */
5376 spec->gpio_mask |= 0x08;
5377 spec->gpio_dir |= 0x08;
5378 spec->gpio_data |= 0x08; /* set to white */
5380 /* register check_power_status callback. */
5381 codec->patch_ops.check_power_status =
5382 stac92xx_hp_check_power_status;
5383 #endif
5384 break;
5387 spec->multiout.dac_nids = spec->dac_nids;
5388 if (spec->dinput_mux)
5389 spec->private_dimux.num_items += spec->num_dmics - ndmic_nids;
5391 err = stac92xx_parse_auto_config(codec, 0x21, 0);
5392 if (!err) {
5393 if (spec->board_config < 0) {
5394 printk(KERN_WARNING "hda_codec: No auto-config is "
5395 "available, default to model=ref\n");
5396 spec->board_config = STAC_92HD71BXX_REF;
5397 goto again;
5399 err = -EINVAL;
5402 if (err < 0) {
5403 stac92xx_free(codec);
5404 return err;
5407 codec->proc_widget_hook = stac92hd7x_proc_hook;
5409 return 0;
5412 static int patch_stac922x(struct hda_codec *codec)
5414 struct sigmatel_spec *spec;
5415 int err;
5417 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5418 if (spec == NULL)
5419 return -ENOMEM;
5421 codec->spec = spec;
5422 spec->num_pins = ARRAY_SIZE(stac922x_pin_nids);
5423 spec->pin_nids = stac922x_pin_nids;
5424 spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS,
5425 stac922x_models,
5426 stac922x_cfg_tbl);
5427 if (spec->board_config == STAC_INTEL_MAC_AUTO) {
5428 spec->gpio_mask = spec->gpio_dir = 0x03;
5429 spec->gpio_data = 0x03;
5430 /* Intel Macs have all same PCI SSID, so we need to check
5431 * codec SSID to distinguish the exact models
5433 printk(KERN_INFO "hda_codec: STAC922x, Apple subsys_id=%x\n", codec->subsystem_id);
5434 switch (codec->subsystem_id) {
5436 case 0x106b0800:
5437 spec->board_config = STAC_INTEL_MAC_V1;
5438 break;
5439 case 0x106b0600:
5440 case 0x106b0700:
5441 spec->board_config = STAC_INTEL_MAC_V2;
5442 break;
5443 case 0x106b0e00:
5444 case 0x106b0f00:
5445 case 0x106b1600:
5446 case 0x106b1700:
5447 case 0x106b0200:
5448 case 0x106b1e00:
5449 spec->board_config = STAC_INTEL_MAC_V3;
5450 break;
5451 case 0x106b1a00:
5452 case 0x00000100:
5453 spec->board_config = STAC_INTEL_MAC_V4;
5454 break;
5455 case 0x106b0a00:
5456 case 0x106b2200:
5457 spec->board_config = STAC_INTEL_MAC_V5;
5458 break;
5459 default:
5460 spec->board_config = STAC_INTEL_MAC_V3;
5461 break;
5465 again:
5466 if (spec->board_config < 0)
5467 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC922x, "
5468 "using BIOS defaults\n");
5469 else
5470 stac92xx_set_config_regs(codec,
5471 stac922x_brd_tbl[spec->board_config]);
5473 spec->adc_nids = stac922x_adc_nids;
5474 spec->mux_nids = stac922x_mux_nids;
5475 spec->num_muxes = ARRAY_SIZE(stac922x_mux_nids);
5476 spec->num_adcs = ARRAY_SIZE(stac922x_adc_nids);
5477 spec->num_dmics = 0;
5478 spec->num_pwrs = 0;
5480 spec->init = stac922x_core_init;
5481 spec->mixer = stac922x_mixer;
5483 spec->multiout.dac_nids = spec->dac_nids;
5485 err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
5486 if (!err) {
5487 if (spec->board_config < 0) {
5488 printk(KERN_WARNING "hda_codec: No auto-config is "
5489 "available, default to model=ref\n");
5490 spec->board_config = STAC_D945_REF;
5491 goto again;
5493 err = -EINVAL;
5495 if (err < 0) {
5496 stac92xx_free(codec);
5497 return err;
5500 codec->patch_ops = stac92xx_patch_ops;
5502 /* Fix Mux capture level; max to 2 */
5503 snd_hda_override_amp_caps(codec, 0x12, HDA_OUTPUT,
5504 (0 << AC_AMPCAP_OFFSET_SHIFT) |
5505 (2 << AC_AMPCAP_NUM_STEPS_SHIFT) |
5506 (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5507 (0 << AC_AMPCAP_MUTE_SHIFT));
5509 return 0;
5512 static int patch_stac927x(struct hda_codec *codec)
5514 struct sigmatel_spec *spec;
5515 int err;
5517 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5518 if (spec == NULL)
5519 return -ENOMEM;
5521 codec->spec = spec;
5522 codec->slave_dig_outs = stac927x_slave_dig_outs;
5523 spec->num_pins = ARRAY_SIZE(stac927x_pin_nids);
5524 spec->pin_nids = stac927x_pin_nids;
5525 spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS,
5526 stac927x_models,
5527 stac927x_cfg_tbl);
5528 again:
5529 if (spec->board_config < 0)
5530 snd_printdd(KERN_INFO "hda_codec: Unknown model for"
5531 "STAC927x, using BIOS defaults\n");
5532 else
5533 stac92xx_set_config_regs(codec,
5534 stac927x_brd_tbl[spec->board_config]);
5536 spec->digbeep_nid = 0x23;
5537 spec->adc_nids = stac927x_adc_nids;
5538 spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
5539 spec->mux_nids = stac927x_mux_nids;
5540 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
5541 spec->smux_nids = stac927x_smux_nids;
5542 spec->num_smuxes = ARRAY_SIZE(stac927x_smux_nids);
5543 spec->spdif_labels = stac927x_spdif_labels;
5544 spec->dac_list = stac927x_dac_nids;
5545 spec->multiout.dac_nids = spec->dac_nids;
5547 switch (spec->board_config) {
5548 case STAC_D965_3ST:
5549 case STAC_D965_5ST:
5550 /* GPIO0 High = Enable EAPD */
5551 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x01;
5552 spec->gpio_data = 0x01;
5553 spec->num_dmics = 0;
5555 spec->init = d965_core_init;
5556 spec->mixer = stac927x_mixer;
5557 break;
5558 case STAC_DELL_BIOS:
5559 switch (codec->subsystem_id) {
5560 case 0x10280209:
5561 case 0x1028022e:
5562 /* correct the device field to SPDIF out */
5563 snd_hda_codec_set_pincfg(codec, 0x21, 0x01442070);
5564 break;
5566 /* configure the analog microphone on some laptops */
5567 snd_hda_codec_set_pincfg(codec, 0x0c, 0x90a79130);
5568 /* correct the front output jack as a hp out */
5569 snd_hda_codec_set_pincfg(codec, 0x0f, 0x0227011f);
5570 /* correct the front input jack as a mic */
5571 snd_hda_codec_set_pincfg(codec, 0x0e, 0x02a79130);
5572 /* fallthru */
5573 case STAC_DELL_3ST:
5574 /* GPIO2 High = Enable EAPD */
5575 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x04;
5576 spec->gpio_data = 0x04;
5577 spec->dmic_nids = stac927x_dmic_nids;
5578 spec->num_dmics = STAC927X_NUM_DMICS;
5580 spec->init = d965_core_init;
5581 spec->mixer = stac927x_mixer;
5582 spec->dmux_nids = stac927x_dmux_nids;
5583 spec->num_dmuxes = ARRAY_SIZE(stac927x_dmux_nids);
5584 break;
5585 default:
5586 if (spec->board_config > STAC_D965_REF) {
5587 /* GPIO0 High = Enable EAPD */
5588 spec->eapd_mask = spec->gpio_mask = 0x01;
5589 spec->gpio_dir = spec->gpio_data = 0x01;
5591 spec->num_dmics = 0;
5593 spec->init = stac927x_core_init;
5594 spec->mixer = stac927x_mixer;
5597 spec->num_pwrs = 0;
5598 spec->aloopback_ctl = stac927x_loopback;
5599 spec->aloopback_mask = 0x40;
5600 spec->aloopback_shift = 0;
5601 spec->eapd_switch = 1;
5603 err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
5604 if (!err) {
5605 if (spec->board_config < 0) {
5606 printk(KERN_WARNING "hda_codec: No auto-config is "
5607 "available, default to model=ref\n");
5608 spec->board_config = STAC_D965_REF;
5609 goto again;
5611 err = -EINVAL;
5613 if (err < 0) {
5614 stac92xx_free(codec);
5615 return err;
5618 codec->patch_ops = stac92xx_patch_ops;
5620 codec->proc_widget_hook = stac927x_proc_hook;
5623 * !!FIXME!!
5624 * The STAC927x seem to require fairly long delays for certain
5625 * command sequences. With too short delays (even if the answer
5626 * is set to RIRB properly), it results in the silence output
5627 * on some hardwares like Dell.
5629 * The below flag enables the longer delay (see get_response
5630 * in hda_intel.c).
5632 codec->bus->needs_damn_long_delay = 1;
5634 /* no jack detecion for ref-no-jd model */
5635 if (spec->board_config == STAC_D965_REF_NO_JD)
5636 spec->hp_detect = 0;
5638 return 0;
5641 static int patch_stac9205(struct hda_codec *codec)
5643 struct sigmatel_spec *spec;
5644 int err;
5646 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5647 if (spec == NULL)
5648 return -ENOMEM;
5650 codec->spec = spec;
5651 spec->num_pins = ARRAY_SIZE(stac9205_pin_nids);
5652 spec->pin_nids = stac9205_pin_nids;
5653 spec->board_config = snd_hda_check_board_config(codec, STAC_9205_MODELS,
5654 stac9205_models,
5655 stac9205_cfg_tbl);
5656 again:
5657 if (spec->board_config < 0)
5658 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9205, using BIOS defaults\n");
5659 else
5660 stac92xx_set_config_regs(codec,
5661 stac9205_brd_tbl[spec->board_config]);
5663 spec->digbeep_nid = 0x23;
5664 spec->adc_nids = stac9205_adc_nids;
5665 spec->num_adcs = ARRAY_SIZE(stac9205_adc_nids);
5666 spec->mux_nids = stac9205_mux_nids;
5667 spec->num_muxes = ARRAY_SIZE(stac9205_mux_nids);
5668 spec->smux_nids = stac9205_smux_nids;
5669 spec->num_smuxes = ARRAY_SIZE(stac9205_smux_nids);
5670 spec->dmic_nids = stac9205_dmic_nids;
5671 spec->num_dmics = STAC9205_NUM_DMICS;
5672 spec->dmux_nids = stac9205_dmux_nids;
5673 spec->num_dmuxes = ARRAY_SIZE(stac9205_dmux_nids);
5674 spec->num_pwrs = 0;
5676 spec->init = stac9205_core_init;
5677 spec->mixer = stac9205_mixer;
5678 spec->aloopback_ctl = stac9205_loopback;
5680 spec->aloopback_mask = 0x40;
5681 spec->aloopback_shift = 0;
5682 /* Turn on/off EAPD per HP plugging */
5683 if (spec->board_config != STAC_9205_EAPD)
5684 spec->eapd_switch = 1;
5685 spec->multiout.dac_nids = spec->dac_nids;
5687 switch (spec->board_config){
5688 case STAC_9205_DELL_M43:
5689 /* Enable SPDIF in/out */
5690 snd_hda_codec_set_pincfg(codec, 0x1f, 0x01441030);
5691 snd_hda_codec_set_pincfg(codec, 0x20, 0x1c410030);
5693 /* Enable unsol response for GPIO4/Dock HP connection */
5694 err = stac_add_event(spec, codec->afg, STAC_VREF_EVENT, 0x01);
5695 if (err < 0)
5696 return err;
5697 snd_hda_codec_write_cache(codec, codec->afg, 0,
5698 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x10);
5699 snd_hda_codec_write_cache(codec, codec->afg, 0,
5700 AC_VERB_SET_UNSOLICITED_ENABLE,
5701 AC_USRSP_EN | err);
5703 spec->gpio_dir = 0x0b;
5704 spec->eapd_mask = 0x01;
5705 spec->gpio_mask = 0x1b;
5706 spec->gpio_mute = 0x10;
5707 /* GPIO0 High = EAPD, GPIO1 Low = Headphone Mute,
5708 * GPIO3 Low = DRM
5710 spec->gpio_data = 0x01;
5711 break;
5712 case STAC_9205_REF:
5713 /* SPDIF-In enabled */
5714 break;
5715 default:
5716 /* GPIO0 High = EAPD */
5717 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
5718 spec->gpio_data = 0x01;
5719 break;
5722 err = stac92xx_parse_auto_config(codec, 0x1f, 0x20);
5723 if (!err) {
5724 if (spec->board_config < 0) {
5725 printk(KERN_WARNING "hda_codec: No auto-config is "
5726 "available, default to model=ref\n");
5727 spec->board_config = STAC_9205_REF;
5728 goto again;
5730 err = -EINVAL;
5732 if (err < 0) {
5733 stac92xx_free(codec);
5734 return err;
5737 codec->patch_ops = stac92xx_patch_ops;
5739 codec->proc_widget_hook = stac9205_proc_hook;
5741 return 0;
5745 * STAC9872 hack
5748 static struct hda_verb stac9872_core_init[] = {
5749 {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
5750 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
5754 static struct snd_kcontrol_new stac9872_mixer[] = {
5755 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
5756 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
5757 { } /* end */
5760 static hda_nid_t stac9872_pin_nids[] = {
5761 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
5762 0x11, 0x13, 0x14,
5765 static hda_nid_t stac9872_adc_nids[] = {
5766 0x8 /*,0x6*/
5769 static hda_nid_t stac9872_mux_nids[] = {
5770 0x15
5773 static unsigned int stac9872_vaio_pin_configs[9] = {
5774 0x03211020, 0x411111f0, 0x411111f0, 0x03a15030,
5775 0x411111f0, 0x90170110, 0x411111f0, 0x411111f0,
5776 0x90a7013e
5779 static const char *stac9872_models[STAC_9872_MODELS] = {
5780 [STAC_9872_AUTO] = "auto",
5781 [STAC_9872_VAIO] = "vaio",
5784 static unsigned int *stac9872_brd_tbl[STAC_9872_MODELS] = {
5785 [STAC_9872_VAIO] = stac9872_vaio_pin_configs,
5788 static struct snd_pci_quirk stac9872_cfg_tbl[] = {
5789 {} /* terminator */
5792 static int patch_stac9872(struct hda_codec *codec)
5794 struct sigmatel_spec *spec;
5795 int err;
5797 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5798 if (spec == NULL)
5799 return -ENOMEM;
5800 codec->spec = spec;
5802 spec->board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
5803 stac9872_models,
5804 stac9872_cfg_tbl);
5805 if (spec->board_config < 0)
5806 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9872, "
5807 "using BIOS defaults\n");
5808 else
5809 stac92xx_set_config_regs(codec,
5810 stac9872_brd_tbl[spec->board_config]);
5812 spec->num_pins = ARRAY_SIZE(stac9872_pin_nids);
5813 spec->pin_nids = stac9872_pin_nids;
5814 spec->multiout.dac_nids = spec->dac_nids;
5815 spec->num_adcs = ARRAY_SIZE(stac9872_adc_nids);
5816 spec->adc_nids = stac9872_adc_nids;
5817 spec->num_muxes = ARRAY_SIZE(stac9872_mux_nids);
5818 spec->mux_nids = stac9872_mux_nids;
5819 spec->mixer = stac9872_mixer;
5820 spec->init = stac9872_core_init;
5822 err = stac92xx_parse_auto_config(codec, 0x10, 0x12);
5823 if (err < 0) {
5824 stac92xx_free(codec);
5825 return -EINVAL;
5827 spec->input_mux = &spec->private_imux;
5828 codec->patch_ops = stac92xx_patch_ops;
5829 return 0;
5834 * patch entries
5836 static struct hda_codec_preset snd_hda_preset_sigmatel[] = {
5837 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
5838 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
5839 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
5840 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
5841 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
5842 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
5843 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
5844 { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
5845 { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
5846 { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
5847 { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
5848 { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
5849 { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
5850 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
5851 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
5852 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
5853 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
5854 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
5855 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
5856 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
5857 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
5858 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
5859 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
5860 { .id = 0x83847632, .name = "STAC9202", .patch = patch_stac925x },
5861 { .id = 0x83847633, .name = "STAC9202D", .patch = patch_stac925x },
5862 { .id = 0x83847634, .name = "STAC9250", .patch = patch_stac925x },
5863 { .id = 0x83847635, .name = "STAC9250D", .patch = patch_stac925x },
5864 { .id = 0x83847636, .name = "STAC9251", .patch = patch_stac925x },
5865 { .id = 0x83847637, .name = "STAC9250D", .patch = patch_stac925x },
5866 { .id = 0x83847645, .name = "92HD206X", .patch = patch_stac927x },
5867 { .id = 0x83847646, .name = "92HD206D", .patch = patch_stac927x },
5868 /* The following does not take into account .id=0x83847661 when subsys =
5869 * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
5870 * currently not fully supported.
5872 { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
5873 { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
5874 { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
5875 { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
5876 { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
5877 { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
5878 { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
5879 { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
5880 { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
5881 { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
5882 { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
5883 { .id = 0x111d7603, .name = "92HD75B3X5", .patch = patch_stac92hd71bxx},
5884 { .id = 0x111d7604, .name = "92HD83C1X5", .patch = patch_stac92hd83xxx},
5885 { .id = 0x111d7605, .name = "92HD81B1X5", .patch = patch_stac92hd83xxx},
5886 { .id = 0x111d76d5, .name = "92HD81B1C5", .patch = patch_stac92hd83xxx},
5887 { .id = 0x111d7608, .name = "92HD75B2X5", .patch = patch_stac92hd71bxx},
5888 { .id = 0x111d7674, .name = "92HD73D1X5", .patch = patch_stac92hd73xx },
5889 { .id = 0x111d7675, .name = "92HD73C1X5", .patch = patch_stac92hd73xx },
5890 { .id = 0x111d7676, .name = "92HD73E1X5", .patch = patch_stac92hd73xx },
5891 { .id = 0x111d76b0, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
5892 { .id = 0x111d76b1, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
5893 { .id = 0x111d76b2, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
5894 { .id = 0x111d76b3, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
5895 { .id = 0x111d76b4, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
5896 { .id = 0x111d76b5, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
5897 { .id = 0x111d76b6, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
5898 { .id = 0x111d76b7, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
5899 {} /* terminator */
5902 MODULE_ALIAS("snd-hda-codec-id:8384*");
5903 MODULE_ALIAS("snd-hda-codec-id:111d*");
5905 MODULE_LICENSE("GPL");
5906 MODULE_DESCRIPTION("IDT/Sigmatel HD-audio codec");
5908 static struct hda_codec_preset_list sigmatel_list = {
5909 .preset = snd_hda_preset_sigmatel,
5910 .owner = THIS_MODULE,
5913 static int __init patch_sigmatel_init(void)
5915 return snd_hda_add_codec_preset(&sigmatel_list);
5918 static void __exit patch_sigmatel_exit(void)
5920 snd_hda_delete_codec_preset(&sigmatel_list);
5923 module_init(patch_sigmatel_init)
5924 module_exit(patch_sigmatel_exit)