ALSA: hda - Add no-jd model for IDT 92HD73xx
[linux-2.6/libata-dev.git] / sound / pci / hda / patch_sigmatel.c
blobd7c622f944f6f393e7ba55c42653b28f2698e6f7
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 "hda_codec.h"
34 #include "hda_local.h"
35 #include "hda_patch.h"
36 #include "hda_beep.h"
38 #define NUM_CONTROL_ALLOC 32
40 #define STAC_VREF_EVENT 0x00
41 #define STAC_INSERT_EVENT 0x10
42 #define STAC_PWR_EVENT 0x20
43 #define STAC_HP_EVENT 0x30
45 enum {
46 STAC_REF,
47 STAC_9200_OQO,
48 STAC_9200_DELL_D21,
49 STAC_9200_DELL_D22,
50 STAC_9200_DELL_D23,
51 STAC_9200_DELL_M21,
52 STAC_9200_DELL_M22,
53 STAC_9200_DELL_M23,
54 STAC_9200_DELL_M24,
55 STAC_9200_DELL_M25,
56 STAC_9200_DELL_M26,
57 STAC_9200_DELL_M27,
58 STAC_9200_GATEWAY,
59 STAC_9200_PANASONIC,
60 STAC_9200_MODELS
63 enum {
64 STAC_9205_REF,
65 STAC_9205_DELL_M42,
66 STAC_9205_DELL_M43,
67 STAC_9205_DELL_M44,
68 STAC_9205_MODELS
71 enum {
72 STAC_92HD73XX_NO_JD, /* no jack-detection */
73 STAC_92HD73XX_REF,
74 STAC_DELL_M6_AMIC,
75 STAC_DELL_M6_DMIC,
76 STAC_DELL_M6_BOTH,
77 STAC_DELL_EQ,
78 STAC_92HD73XX_MODELS
81 enum {
82 STAC_92HD83XXX_REF,
83 STAC_92HD83XXX_MODELS
86 enum {
87 STAC_92HD71BXX_REF,
88 STAC_DELL_M4_1,
89 STAC_DELL_M4_2,
90 STAC_DELL_M4_3,
91 STAC_HP_M4,
92 STAC_92HD71BXX_MODELS
95 enum {
96 STAC_925x_REF,
97 STAC_M2_2,
98 STAC_MA6,
99 STAC_PA6,
100 STAC_925x_MODELS
103 enum {
104 STAC_D945_REF,
105 STAC_D945GTP3,
106 STAC_D945GTP5,
107 STAC_INTEL_MAC_V1,
108 STAC_INTEL_MAC_V2,
109 STAC_INTEL_MAC_V3,
110 STAC_INTEL_MAC_V4,
111 STAC_INTEL_MAC_V5,
112 STAC_INTEL_MAC_AUTO, /* This model is selected if no module parameter
113 * is given, one of the above models will be
114 * chosen according to the subsystem id. */
115 /* for backward compatibility */
116 STAC_MACMINI,
117 STAC_MACBOOK,
118 STAC_MACBOOK_PRO_V1,
119 STAC_MACBOOK_PRO_V2,
120 STAC_IMAC_INTEL,
121 STAC_IMAC_INTEL_20,
122 STAC_ECS_202,
123 STAC_922X_DELL_D81,
124 STAC_922X_DELL_D82,
125 STAC_922X_DELL_M81,
126 STAC_922X_DELL_M82,
127 STAC_922X_MODELS
130 enum {
131 STAC_D965_REF_NO_JD, /* no jack-detection */
132 STAC_D965_REF,
133 STAC_D965_3ST,
134 STAC_D965_5ST,
135 STAC_DELL_3ST,
136 STAC_DELL_BIOS,
137 STAC_927X_MODELS
140 struct sigmatel_spec {
141 struct snd_kcontrol_new *mixers[4];
142 unsigned int num_mixers;
144 int board_config;
145 unsigned int eapd_switch: 1;
146 unsigned int surr_switch: 1;
147 unsigned int line_switch: 1;
148 unsigned int mic_switch: 1;
149 unsigned int alt_switch: 1;
150 unsigned int hp_detect: 1;
151 unsigned int spdif_mute: 1;
153 /* gpio lines */
154 unsigned int eapd_mask;
155 unsigned int gpio_mask;
156 unsigned int gpio_dir;
157 unsigned int gpio_data;
158 unsigned int gpio_mute;
160 /* stream */
161 unsigned int stream_delay;
163 /* analog loopback */
164 unsigned char aloopback_mask;
165 unsigned char aloopback_shift;
167 /* power management */
168 unsigned int num_pwrs;
169 unsigned int *pwr_mapping;
170 hda_nid_t *pwr_nids;
171 hda_nid_t *dac_list;
173 /* playback */
174 struct hda_input_mux *mono_mux;
175 struct hda_input_mux *amp_mux;
176 unsigned int cur_mmux;
177 struct hda_multi_out multiout;
178 hda_nid_t dac_nids[5];
180 /* capture */
181 hda_nid_t *adc_nids;
182 unsigned int num_adcs;
183 hda_nid_t *mux_nids;
184 unsigned int num_muxes;
185 hda_nid_t *dmic_nids;
186 unsigned int num_dmics;
187 hda_nid_t *dmux_nids;
188 unsigned int num_dmuxes;
189 hda_nid_t *smux_nids;
190 unsigned int num_smuxes;
191 const char **spdif_labels;
193 hda_nid_t dig_in_nid;
194 hda_nid_t mono_nid;
195 hda_nid_t anabeep_nid;
196 hda_nid_t digbeep_nid;
198 /* pin widgets */
199 hda_nid_t *pin_nids;
200 unsigned int num_pins;
201 unsigned int *pin_configs;
202 unsigned int *bios_pin_configs;
204 /* codec specific stuff */
205 struct hda_verb *init;
206 struct snd_kcontrol_new *mixer;
208 /* capture source */
209 struct hda_input_mux *dinput_mux;
210 unsigned int cur_dmux[2];
211 struct hda_input_mux *input_mux;
212 unsigned int cur_mux[3];
213 struct hda_input_mux *sinput_mux;
214 unsigned int cur_smux[2];
215 unsigned int cur_amux;
216 hda_nid_t *amp_nids;
217 unsigned int num_amps;
218 unsigned int powerdown_adcs;
220 /* i/o switches */
221 unsigned int io_switch[2];
222 unsigned int clfe_swap;
223 unsigned int hp_switch; /* NID of HP as line-out */
224 unsigned int aloopback;
226 struct hda_pcm pcm_rec[2]; /* PCM information */
228 /* dynamic controls and input_mux */
229 struct auto_pin_cfg autocfg;
230 unsigned int num_kctl_alloc, num_kctl_used;
231 struct snd_kcontrol_new *kctl_alloc;
232 struct hda_input_mux private_dimux;
233 struct hda_input_mux private_imux;
234 struct hda_input_mux private_smux;
235 struct hda_input_mux private_amp_mux;
236 struct hda_input_mux private_mono_mux;
239 static hda_nid_t stac9200_adc_nids[1] = {
240 0x03,
243 static hda_nid_t stac9200_mux_nids[1] = {
244 0x0c,
247 static hda_nid_t stac9200_dac_nids[1] = {
248 0x02,
251 static hda_nid_t stac92hd73xx_pwr_nids[8] = {
252 0x0a, 0x0b, 0x0c, 0xd, 0x0e,
253 0x0f, 0x10, 0x11
256 static hda_nid_t stac92hd73xx_slave_dig_outs[2] = {
257 0x26, 0,
260 static hda_nid_t stac92hd73xx_adc_nids[2] = {
261 0x1a, 0x1b
264 #define DELL_M6_AMP 2
265 static hda_nid_t stac92hd73xx_amp_nids[3] = {
266 0x0b, 0x0c, 0x0e
269 #define STAC92HD73XX_NUM_DMICS 2
270 static hda_nid_t stac92hd73xx_dmic_nids[STAC92HD73XX_NUM_DMICS + 1] = {
271 0x13, 0x14, 0
274 #define STAC92HD73_DAC_COUNT 5
275 static hda_nid_t stac92hd73xx_dac_nids[STAC92HD73_DAC_COUNT] = {
276 0x15, 0x16, 0x17, 0x18, 0x19,
279 static hda_nid_t stac92hd73xx_mux_nids[4] = {
280 0x28, 0x29, 0x2a, 0x2b,
283 static hda_nid_t stac92hd73xx_dmux_nids[2] = {
284 0x20, 0x21,
287 static hda_nid_t stac92hd73xx_smux_nids[2] = {
288 0x22, 0x23,
291 #define STAC92HD83XXX_NUM_DMICS 2
292 static hda_nid_t stac92hd83xxx_dmic_nids[STAC92HD83XXX_NUM_DMICS + 1] = {
293 0x11, 0x12, 0
296 #define STAC92HD81_DAC_COUNT 2
297 #define STAC92HD83_DAC_COUNT 3
298 static hda_nid_t stac92hd83xxx_dac_nids[STAC92HD73_DAC_COUNT] = {
299 0x13, 0x14, 0x22,
302 static hda_nid_t stac92hd83xxx_dmux_nids[2] = {
303 0x17, 0x18,
306 static hda_nid_t stac92hd83xxx_adc_nids[2] = {
307 0x15, 0x16,
310 static hda_nid_t stac92hd83xxx_pwr_nids[4] = {
311 0xa, 0xb, 0xd, 0xe,
314 static hda_nid_t stac92hd83xxx_slave_dig_outs[2] = {
315 0x1e, 0,
318 static unsigned int stac92hd83xxx_pwr_mapping[4] = {
319 0x03, 0x0c, 0x10, 0x40,
322 static hda_nid_t stac92hd71bxx_pwr_nids[3] = {
323 0x0a, 0x0d, 0x0f
326 static hda_nid_t stac92hd71bxx_adc_nids[2] = {
327 0x12, 0x13,
330 static hda_nid_t stac92hd71bxx_mux_nids[2] = {
331 0x1a, 0x1b
334 static hda_nid_t stac92hd71bxx_dmux_nids[2] = {
335 0x1c, 0x1d,
338 static hda_nid_t stac92hd71bxx_smux_nids[2] = {
339 0x24, 0x25,
342 static hda_nid_t stac92hd71bxx_dac_nids[1] = {
343 0x10, /*0x11, */
346 #define STAC92HD71BXX_NUM_DMICS 2
347 static hda_nid_t stac92hd71bxx_dmic_nids[STAC92HD71BXX_NUM_DMICS + 1] = {
348 0x18, 0x19, 0
351 static hda_nid_t stac92hd71bxx_slave_dig_outs[2] = {
352 0x22, 0
355 static hda_nid_t stac925x_adc_nids[1] = {
356 0x03,
359 static hda_nid_t stac925x_mux_nids[1] = {
360 0x0f,
363 static hda_nid_t stac925x_dac_nids[1] = {
364 0x02,
367 #define STAC925X_NUM_DMICS 1
368 static hda_nid_t stac925x_dmic_nids[STAC925X_NUM_DMICS + 1] = {
369 0x15, 0
372 static hda_nid_t stac925x_dmux_nids[1] = {
373 0x14,
376 static hda_nid_t stac922x_adc_nids[2] = {
377 0x06, 0x07,
380 static hda_nid_t stac922x_mux_nids[2] = {
381 0x12, 0x13,
384 static hda_nid_t stac927x_adc_nids[3] = {
385 0x07, 0x08, 0x09
388 static hda_nid_t stac927x_mux_nids[3] = {
389 0x15, 0x16, 0x17
392 static hda_nid_t stac927x_smux_nids[1] = {
393 0x21,
396 static hda_nid_t stac927x_dac_nids[6] = {
397 0x02, 0x03, 0x04, 0x05, 0x06, 0
400 static hda_nid_t stac927x_dmux_nids[1] = {
401 0x1b,
404 #define STAC927X_NUM_DMICS 2
405 static hda_nid_t stac927x_dmic_nids[STAC927X_NUM_DMICS + 1] = {
406 0x13, 0x14, 0
409 static const char *stac927x_spdif_labels[5] = {
410 "Digital Playback", "ADAT", "Analog Mux 1",
411 "Analog Mux 2", "Analog Mux 3"
414 static hda_nid_t stac9205_adc_nids[2] = {
415 0x12, 0x13
418 static hda_nid_t stac9205_mux_nids[2] = {
419 0x19, 0x1a
422 static hda_nid_t stac9205_dmux_nids[1] = {
423 0x1d,
426 static hda_nid_t stac9205_smux_nids[1] = {
427 0x21,
430 #define STAC9205_NUM_DMICS 2
431 static hda_nid_t stac9205_dmic_nids[STAC9205_NUM_DMICS + 1] = {
432 0x17, 0x18, 0
435 static hda_nid_t stac9200_pin_nids[8] = {
436 0x08, 0x09, 0x0d, 0x0e,
437 0x0f, 0x10, 0x11, 0x12,
440 static hda_nid_t stac925x_pin_nids[8] = {
441 0x07, 0x08, 0x0a, 0x0b,
442 0x0c, 0x0d, 0x10, 0x11,
445 static hda_nid_t stac922x_pin_nids[10] = {
446 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
447 0x0f, 0x10, 0x11, 0x15, 0x1b,
450 static hda_nid_t stac92hd73xx_pin_nids[13] = {
451 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
452 0x0f, 0x10, 0x11, 0x12, 0x13,
453 0x14, 0x22, 0x23
456 static hda_nid_t stac92hd83xxx_pin_nids[14] = {
457 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
458 0x0f, 0x10, 0x11, 0x12, 0x13,
459 0x1d, 0x1e, 0x1f, 0x20
461 static hda_nid_t stac92hd71bxx_pin_nids[11] = {
462 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
463 0x0f, 0x14, 0x18, 0x19, 0x1e,
464 0x1f,
467 static hda_nid_t stac927x_pin_nids[14] = {
468 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
469 0x0f, 0x10, 0x11, 0x12, 0x13,
470 0x14, 0x21, 0x22, 0x23,
473 static hda_nid_t stac9205_pin_nids[12] = {
474 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
475 0x0f, 0x14, 0x16, 0x17, 0x18,
476 0x21, 0x22,
479 #define stac92xx_amp_volume_info snd_hda_mixer_amp_volume_info
481 static int stac92xx_amp_volume_get(struct snd_kcontrol *kcontrol,
482 struct snd_ctl_elem_value *ucontrol)
484 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
485 struct sigmatel_spec *spec = codec->spec;
486 hda_nid_t nid = spec->amp_nids[spec->cur_amux];
488 kcontrol->private_value ^= get_amp_nid(kcontrol);
489 kcontrol->private_value |= nid;
491 return snd_hda_mixer_amp_volume_get(kcontrol, ucontrol);
494 static int stac92xx_amp_volume_put(struct snd_kcontrol *kcontrol,
495 struct snd_ctl_elem_value *ucontrol)
497 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
498 struct sigmatel_spec *spec = codec->spec;
499 hda_nid_t nid = spec->amp_nids[spec->cur_amux];
501 kcontrol->private_value ^= get_amp_nid(kcontrol);
502 kcontrol->private_value |= nid;
504 return snd_hda_mixer_amp_volume_put(kcontrol, ucontrol);
507 static int stac92xx_dmux_enum_info(struct snd_kcontrol *kcontrol,
508 struct snd_ctl_elem_info *uinfo)
510 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
511 struct sigmatel_spec *spec = codec->spec;
512 return snd_hda_input_mux_info(spec->dinput_mux, uinfo);
515 static int stac92xx_dmux_enum_get(struct snd_kcontrol *kcontrol,
516 struct snd_ctl_elem_value *ucontrol)
518 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
519 struct sigmatel_spec *spec = codec->spec;
520 unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
522 ucontrol->value.enumerated.item[0] = spec->cur_dmux[dmux_idx];
523 return 0;
526 static int stac92xx_dmux_enum_put(struct snd_kcontrol *kcontrol,
527 struct snd_ctl_elem_value *ucontrol)
529 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
530 struct sigmatel_spec *spec = codec->spec;
531 unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
533 return snd_hda_input_mux_put(codec, spec->dinput_mux, ucontrol,
534 spec->dmux_nids[dmux_idx], &spec->cur_dmux[dmux_idx]);
537 static int stac92xx_smux_enum_info(struct snd_kcontrol *kcontrol,
538 struct snd_ctl_elem_info *uinfo)
540 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
541 struct sigmatel_spec *spec = codec->spec;
542 return snd_hda_input_mux_info(spec->sinput_mux, uinfo);
545 static int stac92xx_smux_enum_get(struct snd_kcontrol *kcontrol,
546 struct snd_ctl_elem_value *ucontrol)
548 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
549 struct sigmatel_spec *spec = codec->spec;
550 unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
552 ucontrol->value.enumerated.item[0] = spec->cur_smux[smux_idx];
553 return 0;
556 static int stac92xx_smux_enum_put(struct snd_kcontrol *kcontrol,
557 struct snd_ctl_elem_value *ucontrol)
559 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
560 struct sigmatel_spec *spec = codec->spec;
561 struct hda_input_mux *smux = &spec->private_smux;
562 unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
563 int err, val;
564 hda_nid_t nid;
566 err = snd_hda_input_mux_put(codec, spec->sinput_mux, ucontrol,
567 spec->smux_nids[smux_idx], &spec->cur_smux[smux_idx]);
568 if (err < 0)
569 return err;
571 if (spec->spdif_mute) {
572 if (smux_idx == 0)
573 nid = spec->multiout.dig_out_nid;
574 else
575 nid = codec->slave_dig_outs[smux_idx - 1];
576 if (spec->cur_smux[smux_idx] == smux->num_items - 1)
577 val = AMP_OUT_MUTE;
578 else
579 val = AMP_OUT_UNMUTE;
580 /* un/mute SPDIF out */
581 snd_hda_codec_write_cache(codec, nid, 0,
582 AC_VERB_SET_AMP_GAIN_MUTE, val);
584 return 0;
587 static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
589 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
590 struct sigmatel_spec *spec = codec->spec;
591 return snd_hda_input_mux_info(spec->input_mux, uinfo);
594 static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
596 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
597 struct sigmatel_spec *spec = codec->spec;
598 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
600 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
601 return 0;
604 static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
606 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
607 struct sigmatel_spec *spec = codec->spec;
608 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
610 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
611 spec->mux_nids[adc_idx], &spec->cur_mux[adc_idx]);
614 static int stac92xx_mono_mux_enum_info(struct snd_kcontrol *kcontrol,
615 struct snd_ctl_elem_info *uinfo)
617 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
618 struct sigmatel_spec *spec = codec->spec;
619 return snd_hda_input_mux_info(spec->mono_mux, uinfo);
622 static int stac92xx_mono_mux_enum_get(struct snd_kcontrol *kcontrol,
623 struct snd_ctl_elem_value *ucontrol)
625 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
626 struct sigmatel_spec *spec = codec->spec;
628 ucontrol->value.enumerated.item[0] = spec->cur_mmux;
629 return 0;
632 static int stac92xx_mono_mux_enum_put(struct snd_kcontrol *kcontrol,
633 struct snd_ctl_elem_value *ucontrol)
635 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
636 struct sigmatel_spec *spec = codec->spec;
638 return snd_hda_input_mux_put(codec, spec->mono_mux, ucontrol,
639 spec->mono_nid, &spec->cur_mmux);
642 static int stac92xx_amp_mux_enum_info(struct snd_kcontrol *kcontrol,
643 struct snd_ctl_elem_info *uinfo)
645 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
646 struct sigmatel_spec *spec = codec->spec;
647 return snd_hda_input_mux_info(spec->amp_mux, uinfo);
650 static int stac92xx_amp_mux_enum_get(struct snd_kcontrol *kcontrol,
651 struct snd_ctl_elem_value *ucontrol)
653 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
654 struct sigmatel_spec *spec = codec->spec;
656 ucontrol->value.enumerated.item[0] = spec->cur_amux;
657 return 0;
660 static int stac92xx_amp_mux_enum_put(struct snd_kcontrol *kcontrol,
661 struct snd_ctl_elem_value *ucontrol)
663 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
664 struct sigmatel_spec *spec = codec->spec;
665 struct snd_kcontrol *ctl =
666 snd_hda_find_mixer_ctl(codec, "Amp Capture Volume");
667 if (!ctl)
668 return -EINVAL;
670 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE |
671 SNDRV_CTL_EVENT_MASK_INFO, &ctl->id);
673 return snd_hda_input_mux_put(codec, spec->amp_mux, ucontrol,
674 0, &spec->cur_amux);
677 #define stac92xx_aloopback_info snd_ctl_boolean_mono_info
679 static int stac92xx_aloopback_get(struct snd_kcontrol *kcontrol,
680 struct snd_ctl_elem_value *ucontrol)
682 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
683 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
684 struct sigmatel_spec *spec = codec->spec;
686 ucontrol->value.integer.value[0] = !!(spec->aloopback &
687 (spec->aloopback_mask << idx));
688 return 0;
691 static int stac92xx_aloopback_put(struct snd_kcontrol *kcontrol,
692 struct snd_ctl_elem_value *ucontrol)
694 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
695 struct sigmatel_spec *spec = codec->spec;
696 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
697 unsigned int dac_mode;
698 unsigned int val, idx_val;
700 idx_val = spec->aloopback_mask << idx;
701 if (ucontrol->value.integer.value[0])
702 val = spec->aloopback | idx_val;
703 else
704 val = spec->aloopback & ~idx_val;
705 if (spec->aloopback == val)
706 return 0;
708 spec->aloopback = val;
710 /* Only return the bits defined by the shift value of the
711 * first two bytes of the mask
713 dac_mode = snd_hda_codec_read(codec, codec->afg, 0,
714 kcontrol->private_value & 0xFFFF, 0x0);
715 dac_mode >>= spec->aloopback_shift;
717 if (spec->aloopback & idx_val) {
718 snd_hda_power_up(codec);
719 dac_mode |= idx_val;
720 } else {
721 snd_hda_power_down(codec);
722 dac_mode &= ~idx_val;
725 snd_hda_codec_write_cache(codec, codec->afg, 0,
726 kcontrol->private_value >> 16, dac_mode);
728 return 1;
731 static struct hda_verb stac9200_core_init[] = {
732 /* set dac0mux for dac converter */
733 { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
737 static struct hda_verb stac9200_eapd_init[] = {
738 /* set dac0mux for dac converter */
739 {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
740 {0x08, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
744 static struct hda_verb stac92hd73xx_6ch_core_init[] = {
745 /* set master volume and direct control */
746 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
747 /* setup audio connections */
748 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00},
749 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x01},
750 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x02},
751 /* setup adcs to point to mixer */
752 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
753 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
754 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
755 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
756 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
757 /* setup import muxs */
758 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
759 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
760 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
761 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x00},
765 static struct hda_verb dell_eq_core_init[] = {
766 /* set master volume to max value without distortion
767 * and direct control */
768 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xec},
769 /* setup audio connections */
770 { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
771 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x02},
772 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x01},
773 /* setup adcs to point to mixer */
774 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
775 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
776 /* setup import muxs */
777 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
778 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
779 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
780 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x00},
784 static struct hda_verb dell_m6_core_init[] = {
785 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
786 /* setup audio connections */
787 { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
788 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x01},
789 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x02},
790 /* setup adcs to point to mixer */
791 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
792 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
793 /* setup import muxs */
794 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
795 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
796 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
797 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x00},
801 static struct hda_verb stac92hd73xx_8ch_core_init[] = {
802 /* set master volume and direct control */
803 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
804 /* setup audio connections */
805 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00},
806 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x01},
807 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x02},
808 /* connect hp ports to dac3 */
809 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x03},
810 { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x03},
811 /* setup adcs to point to mixer */
812 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
813 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
814 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
815 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
816 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
817 /* setup import muxs */
818 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
819 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
820 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
821 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x03},
825 static struct hda_verb stac92hd73xx_10ch_core_init[] = {
826 /* set master volume and direct control */
827 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
828 /* setup audio connections */
829 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
830 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x01 },
831 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x02 },
832 /* dac3 is connected to import3 mux */
833 { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0xb07f},
834 /* connect hp ports to dac4 */
835 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x04},
836 { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x04},
837 /* setup adcs to point to mixer */
838 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
839 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
840 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
841 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
842 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
843 /* setup import muxs */
844 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
845 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
846 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
847 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x03},
851 static struct hda_verb stac92hd83xxx_core_init[] = {
852 /* start of config #1 */
853 { 0xe, AC_VERB_SET_CONNECT_SEL, 0x3},
855 /* start of config #2 */
856 { 0xa, AC_VERB_SET_CONNECT_SEL, 0x0},
857 { 0xb, AC_VERB_SET_CONNECT_SEL, 0x0},
858 { 0xd, AC_VERB_SET_CONNECT_SEL, 0x1},
860 /* power state controls amps */
861 { 0x01, AC_VERB_SET_EAPD, 1 << 2},
864 static struct hda_verb stac92hd71bxx_core_init[] = {
865 /* set master volume and direct control */
866 { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
867 /* connect headphone jack to dac1 */
868 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x01},
869 /* unmute right and left channels for nodes 0x0a, 0xd, 0x0f */
870 { 0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
871 { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
872 { 0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
875 #define HD_DISABLE_PORTF 2
876 static struct hda_verb stac92hd71bxx_analog_core_init[] = {
877 /* start of config #1 */
879 /* connect port 0f to audio mixer */
880 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x2},
881 /* unmute right and left channels for node 0x0f */
882 { 0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
883 /* start of config #2 */
885 /* set master volume and direct control */
886 { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
887 /* connect headphone jack to dac1 */
888 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x01},
889 /* unmute right and left channels for nodes 0x0a, 0xd */
890 { 0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
891 { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
895 static struct hda_verb stac925x_core_init[] = {
896 /* set dac0mux for dac converter */
897 { 0x06, AC_VERB_SET_CONNECT_SEL, 0x00},
901 static struct hda_verb stac922x_core_init[] = {
902 /* set master volume and direct control */
903 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
907 static struct hda_verb d965_core_init[] = {
908 /* set master volume and direct control */
909 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
910 /* unmute node 0x1b */
911 { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
912 /* select node 0x03 as DAC */
913 { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
917 static struct hda_verb stac927x_core_init[] = {
918 /* set master volume and direct control */
919 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
920 /* enable analog pc beep path */
921 { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
925 static struct hda_verb stac9205_core_init[] = {
926 /* set master volume and direct control */
927 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
928 /* enable analog pc beep path */
929 { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
933 #define STAC_MONO_MUX \
935 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
936 .name = "Mono Mux", \
937 .count = 1, \
938 .info = stac92xx_mono_mux_enum_info, \
939 .get = stac92xx_mono_mux_enum_get, \
940 .put = stac92xx_mono_mux_enum_put, \
943 #define STAC_AMP_MUX \
945 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
946 .name = "Amp Selector Capture Switch", \
947 .count = 1, \
948 .info = stac92xx_amp_mux_enum_info, \
949 .get = stac92xx_amp_mux_enum_get, \
950 .put = stac92xx_amp_mux_enum_put, \
953 #define STAC_AMP_VOL(xname, nid, chs, idx, dir) \
955 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
956 .name = xname, \
957 .index = 0, \
958 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
959 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
960 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
961 .info = stac92xx_amp_volume_info, \
962 .get = stac92xx_amp_volume_get, \
963 .put = stac92xx_amp_volume_put, \
964 .tlv = { .c = snd_hda_mixer_amp_tlv }, \
965 .private_value = HDA_COMPOSE_AMP_VAL(nid, chs, idx, dir) \
968 #define STAC_INPUT_SOURCE(cnt) \
970 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
971 .name = "Input Source", \
972 .count = cnt, \
973 .info = stac92xx_mux_enum_info, \
974 .get = stac92xx_mux_enum_get, \
975 .put = stac92xx_mux_enum_put, \
978 #define STAC_ANALOG_LOOPBACK(verb_read, verb_write, cnt) \
980 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
981 .name = "Analog Loopback", \
982 .count = cnt, \
983 .info = stac92xx_aloopback_info, \
984 .get = stac92xx_aloopback_get, \
985 .put = stac92xx_aloopback_put, \
986 .private_value = verb_read | (verb_write << 16), \
989 static struct snd_kcontrol_new stac9200_mixer[] = {
990 HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
991 HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
992 STAC_INPUT_SOURCE(1),
993 HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
994 HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
995 { } /* end */
998 #define DELL_M6_MIXER 6
999 static struct snd_kcontrol_new stac92hd73xx_6ch_mixer[] = {
1000 /* start of config #1 */
1001 HDA_CODEC_VOLUME("Front Mic Mixer Capture Volume", 0x1d, 0, HDA_INPUT),
1002 HDA_CODEC_MUTE("Front Mic Mixer Capture Switch", 0x1d, 0, HDA_INPUT),
1004 HDA_CODEC_VOLUME("Line In Mixer Capture Volume", 0x1d, 0x2, HDA_INPUT),
1005 HDA_CODEC_MUTE("Line In Mixer Capture Switch", 0x1d, 0x2, HDA_INPUT),
1007 HDA_CODEC_VOLUME("CD Mixer Capture Volume", 0x1d, 0x4, HDA_INPUT),
1008 HDA_CODEC_MUTE("CD Mixer Capture Switch", 0x1d, 0x4, HDA_INPUT),
1010 /* start of config #2 */
1011 HDA_CODEC_VOLUME("Mic Mixer Capture Volume", 0x1d, 0x1, HDA_INPUT),
1012 HDA_CODEC_MUTE("Mic Mixer Capture Switch", 0x1d, 0x1, HDA_INPUT),
1014 HDA_CODEC_VOLUME("DAC Mixer Capture Volume", 0x1d, 0x3, HDA_INPUT),
1015 HDA_CODEC_MUTE("DAC Mixer Capture Switch", 0x1d, 0x3, HDA_INPUT),
1017 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 3),
1019 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x20, 0x0, HDA_OUTPUT),
1020 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x20, 0x0, HDA_OUTPUT),
1022 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x21, 0x0, HDA_OUTPUT),
1023 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x21, 0x0, HDA_OUTPUT),
1025 { } /* end */
1028 static struct snd_kcontrol_new stac92hd73xx_8ch_mixer[] = {
1029 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 4),
1031 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x20, 0x0, HDA_OUTPUT),
1032 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x20, 0x0, HDA_OUTPUT),
1034 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x21, 0x0, HDA_OUTPUT),
1035 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x21, 0x0, HDA_OUTPUT),
1037 HDA_CODEC_VOLUME("Front Mic Mixer Capture Volume", 0x1d, 0, HDA_INPUT),
1038 HDA_CODEC_MUTE("Front Mic Mixer Capture Switch", 0x1d, 0, HDA_INPUT),
1040 HDA_CODEC_VOLUME("Mic Mixer Capture Volume", 0x1d, 0x1, HDA_INPUT),
1041 HDA_CODEC_MUTE("Mic Mixer Capture Switch", 0x1d, 0x1, HDA_INPUT),
1043 HDA_CODEC_VOLUME("Line In Mixer Capture Volume", 0x1d, 0x2, HDA_INPUT),
1044 HDA_CODEC_MUTE("Line In Mixer Capture Switch", 0x1d, 0x2, HDA_INPUT),
1046 HDA_CODEC_VOLUME("DAC Mixer Capture Volume", 0x1d, 0x3, HDA_INPUT),
1047 HDA_CODEC_MUTE("DAC Mixer Capture Switch", 0x1d, 0x3, HDA_INPUT),
1049 HDA_CODEC_VOLUME("CD Mixer Capture Volume", 0x1d, 0x4, HDA_INPUT),
1050 HDA_CODEC_MUTE("CD Mixer Capture Switch", 0x1d, 0x4, HDA_INPUT),
1051 { } /* end */
1054 static struct snd_kcontrol_new stac92hd73xx_10ch_mixer[] = {
1055 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 5),
1057 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x20, 0x0, HDA_OUTPUT),
1058 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x20, 0x0, HDA_OUTPUT),
1060 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x21, 0x0, HDA_OUTPUT),
1061 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x21, 0x0, HDA_OUTPUT),
1063 HDA_CODEC_VOLUME("Front Mic Mixer Capture Volume", 0x1d, 0, HDA_INPUT),
1064 HDA_CODEC_MUTE("Front Mic Mixer Capture Switch", 0x1d, 0, HDA_INPUT),
1066 HDA_CODEC_VOLUME("Mic Mixer Capture Volume", 0x1d, 0x1, HDA_INPUT),
1067 HDA_CODEC_MUTE("Mic Mixer Capture Switch", 0x1d, 0x1, HDA_INPUT),
1069 HDA_CODEC_VOLUME("Line In Mixer Capture Volume", 0x1d, 0x2, HDA_INPUT),
1070 HDA_CODEC_MUTE("Line In Mixer Capture Switch", 0x1d, 0x2, HDA_INPUT),
1072 HDA_CODEC_VOLUME("DAC Mixer Capture Volume", 0x1d, 0x3, HDA_INPUT),
1073 HDA_CODEC_MUTE("DAC Mixer Capture Switch", 0x1d, 0x3, HDA_INPUT),
1075 HDA_CODEC_VOLUME("CD Mixer Capture Volume", 0x1d, 0x4, HDA_INPUT),
1076 HDA_CODEC_MUTE("CD Mixer Capture Switch", 0x1d, 0x4, HDA_INPUT),
1077 { } /* end */
1081 static struct snd_kcontrol_new stac92hd83xxx_mixer[] = {
1082 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x17, 0x0, HDA_OUTPUT),
1083 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x17, 0x0, HDA_OUTPUT),
1085 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x18, 0x0, HDA_OUTPUT),
1086 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x18, 0x0, HDA_OUTPUT),
1088 HDA_CODEC_VOLUME("DAC0 Capture Volume", 0x1b, 0, HDA_INPUT),
1089 HDA_CODEC_MUTE("DAC0 Capture Switch", 0x1b, 0, HDA_INPUT),
1091 HDA_CODEC_VOLUME("DAC1 Capture Volume", 0x1b, 0x1, HDA_INPUT),
1092 HDA_CODEC_MUTE("DAC1 Capture Switch", 0x1b, 0x1, HDA_INPUT),
1094 HDA_CODEC_VOLUME("Front Mic Capture Volume", 0x1b, 0x2, HDA_INPUT),
1095 HDA_CODEC_MUTE("Front Mic Capture Switch", 0x1b, 0x2, HDA_INPUT),
1097 HDA_CODEC_VOLUME("Line In Capture Volume", 0x1b, 0x3, HDA_INPUT),
1098 HDA_CODEC_MUTE("Line In Capture Switch", 0x1b, 0x3, HDA_INPUT),
1101 HDA_CODEC_VOLUME("Mic Capture Volume", 0x1b, 0x4, HDA_INPUT),
1102 HDA_CODEC_MUTE("Mic Capture Switch", 0x1b 0x4, HDA_INPUT),
1104 { } /* end */
1107 static struct snd_kcontrol_new stac92hd71bxx_analog_mixer[] = {
1108 STAC_INPUT_SOURCE(2),
1109 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A0, 2),
1111 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1c, 0x0, HDA_OUTPUT),
1112 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1c, 0x0, HDA_OUTPUT),
1114 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x1d, 0x0, HDA_OUTPUT),
1115 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1d, 0x0, HDA_OUTPUT),
1116 /* analog pc-beep replaced with digital beep support */
1118 HDA_CODEC_VOLUME("PC Beep Volume", 0x17, 0x2, HDA_INPUT),
1119 HDA_CODEC_MUTE("PC Beep Switch", 0x17, 0x2, HDA_INPUT),
1122 HDA_CODEC_MUTE("Import0 Mux Capture Switch", 0x17, 0x0, HDA_INPUT),
1123 HDA_CODEC_VOLUME("Import0 Mux Capture Volume", 0x17, 0x0, HDA_INPUT),
1125 HDA_CODEC_MUTE("Import1 Mux Capture Switch", 0x17, 0x1, HDA_INPUT),
1126 HDA_CODEC_VOLUME("Import1 Mux Capture Volume", 0x17, 0x1, HDA_INPUT),
1128 HDA_CODEC_MUTE("DAC0 Capture Switch", 0x17, 0x3, HDA_INPUT),
1129 HDA_CODEC_VOLUME("DAC0 Capture Volume", 0x17, 0x3, HDA_INPUT),
1131 HDA_CODEC_MUTE("DAC1 Capture Switch", 0x17, 0x4, HDA_INPUT),
1132 HDA_CODEC_VOLUME("DAC1 Capture Volume", 0x17, 0x4, HDA_INPUT),
1133 { } /* end */
1136 static struct snd_kcontrol_new stac92hd71bxx_mixer[] = {
1137 STAC_INPUT_SOURCE(2),
1138 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A0, 2),
1140 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1c, 0x0, HDA_OUTPUT),
1141 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1c, 0x0, HDA_OUTPUT),
1143 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x1d, 0x0, HDA_OUTPUT),
1144 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1d, 0x0, HDA_OUTPUT),
1145 { } /* end */
1148 static struct snd_kcontrol_new stac925x_mixer[] = {
1149 STAC_INPUT_SOURCE(1),
1150 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_OUTPUT),
1151 HDA_CODEC_MUTE("Capture Switch", 0x14, 0, HDA_OUTPUT),
1152 { } /* end */
1155 static struct snd_kcontrol_new stac9205_mixer[] = {
1156 STAC_INPUT_SOURCE(2),
1157 STAC_ANALOG_LOOPBACK(0xFE0, 0x7E0, 1),
1159 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1b, 0x0, HDA_INPUT),
1160 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1d, 0x0, HDA_OUTPUT),
1162 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x1c, 0x0, HDA_INPUT),
1163 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1e, 0x0, HDA_OUTPUT),
1164 { } /* end */
1167 /* This needs to be generated dynamically based on sequence */
1168 static struct snd_kcontrol_new stac922x_mixer[] = {
1169 STAC_INPUT_SOURCE(2),
1170 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x17, 0x0, HDA_INPUT),
1171 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x17, 0x0, HDA_INPUT),
1173 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x18, 0x0, HDA_INPUT),
1174 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x18, 0x0, HDA_INPUT),
1175 { } /* end */
1179 static struct snd_kcontrol_new stac927x_mixer[] = {
1180 STAC_INPUT_SOURCE(3),
1181 STAC_ANALOG_LOOPBACK(0xFEB, 0x7EB, 1),
1183 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x18, 0x0, HDA_INPUT),
1184 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1b, 0x0, HDA_OUTPUT),
1186 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x19, 0x0, HDA_INPUT),
1187 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1c, 0x0, HDA_OUTPUT),
1189 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x2, 0x1A, 0x0, HDA_INPUT),
1190 HDA_CODEC_MUTE_IDX("Capture Switch", 0x2, 0x1d, 0x0, HDA_OUTPUT),
1191 { } /* end */
1194 static struct snd_kcontrol_new stac_dmux_mixer = {
1195 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1196 .name = "Digital Input Source",
1197 /* count set later */
1198 .info = stac92xx_dmux_enum_info,
1199 .get = stac92xx_dmux_enum_get,
1200 .put = stac92xx_dmux_enum_put,
1203 static struct snd_kcontrol_new stac_smux_mixer = {
1204 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1205 .name = "IEC958 Playback Source",
1206 /* count set later */
1207 .info = stac92xx_smux_enum_info,
1208 .get = stac92xx_smux_enum_get,
1209 .put = stac92xx_smux_enum_put,
1212 static const char *slave_vols[] = {
1213 "Front Playback Volume",
1214 "Surround Playback Volume",
1215 "Center Playback Volume",
1216 "LFE Playback Volume",
1217 "Side Playback Volume",
1218 "Headphone Playback Volume",
1219 "Headphone Playback Volume",
1220 "Speaker Playback Volume",
1221 "External Speaker Playback Volume",
1222 "Speaker2 Playback Volume",
1223 NULL
1226 static const char *slave_sws[] = {
1227 "Front Playback Switch",
1228 "Surround Playback Switch",
1229 "Center Playback Switch",
1230 "LFE Playback Switch",
1231 "Side Playback Switch",
1232 "Headphone Playback Switch",
1233 "Headphone Playback Switch",
1234 "Speaker Playback Switch",
1235 "External Speaker Playback Switch",
1236 "Speaker2 Playback Switch",
1237 "IEC958 Playback Switch",
1238 NULL
1241 static int stac92xx_build_controls(struct hda_codec *codec)
1243 struct sigmatel_spec *spec = codec->spec;
1244 int err;
1245 int i;
1247 err = snd_hda_add_new_ctls(codec, spec->mixer);
1248 if (err < 0)
1249 return err;
1251 for (i = 0; i < spec->num_mixers; i++) {
1252 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1253 if (err < 0)
1254 return err;
1256 if (spec->num_dmuxes > 0) {
1257 stac_dmux_mixer.count = spec->num_dmuxes;
1258 err = snd_ctl_add(codec->bus->card,
1259 snd_ctl_new1(&stac_dmux_mixer, codec));
1260 if (err < 0)
1261 return err;
1263 if (spec->num_smuxes > 0) {
1264 int wcaps = get_wcaps(codec, spec->multiout.dig_out_nid);
1265 struct hda_input_mux *smux = &spec->private_smux;
1266 /* check for mute support on SPDIF out */
1267 if (wcaps & AC_WCAP_OUT_AMP) {
1268 smux->items[smux->num_items].label = "Off";
1269 smux->items[smux->num_items].index = 0;
1270 smux->num_items++;
1271 spec->spdif_mute = 1;
1273 stac_smux_mixer.count = spec->num_smuxes;
1274 err = snd_ctl_add(codec->bus->card,
1275 snd_ctl_new1(&stac_smux_mixer, codec));
1276 if (err < 0)
1277 return err;
1280 if (spec->multiout.dig_out_nid) {
1281 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
1282 if (err < 0)
1283 return err;
1284 err = snd_hda_create_spdif_share_sw(codec,
1285 &spec->multiout);
1286 if (err < 0)
1287 return err;
1288 spec->multiout.share_spdif = 1;
1290 if (spec->dig_in_nid && !(spec->gpio_dir & 0x01)) {
1291 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1292 if (err < 0)
1293 return err;
1296 /* if we have no master control, let's create it */
1297 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
1298 unsigned int vmaster_tlv[4];
1299 snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0],
1300 HDA_OUTPUT, vmaster_tlv);
1301 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
1302 vmaster_tlv, slave_vols);
1303 if (err < 0)
1304 return err;
1306 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1307 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1308 NULL, slave_sws);
1309 if (err < 0)
1310 return err;
1313 return 0;
1316 static unsigned int ref9200_pin_configs[8] = {
1317 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
1318 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
1322 STAC 9200 pin configs for
1323 102801A8
1324 102801DE
1325 102801E8
1327 static unsigned int dell9200_d21_pin_configs[8] = {
1328 0x400001f0, 0x400001f1, 0x02214030, 0x01014010,
1329 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
1333 STAC 9200 pin configs for
1334 102801C0
1335 102801C1
1337 static unsigned int dell9200_d22_pin_configs[8] = {
1338 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
1339 0x01813020, 0x02a19021, 0x90100140, 0x400001f2,
1343 STAC 9200 pin configs for
1344 102801C4 (Dell Dimension E310)
1345 102801C5
1346 102801C7
1347 102801D9
1348 102801DA
1349 102801E3
1351 static unsigned int dell9200_d23_pin_configs[8] = {
1352 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
1353 0x01813020, 0x01a19021, 0x90100140, 0x400001f2,
1358 STAC 9200-32 pin configs for
1359 102801B5 (Dell Inspiron 630m)
1360 102801D8 (Dell Inspiron 640m)
1362 static unsigned int dell9200_m21_pin_configs[8] = {
1363 0x40c003fa, 0x03441340, 0x0321121f, 0x90170310,
1364 0x408003fb, 0x03a11020, 0x401003fc, 0x403003fd,
1368 STAC 9200-32 pin configs for
1369 102801C2 (Dell Latitude D620)
1370 102801C8
1371 102801CC (Dell Latitude D820)
1372 102801D4
1373 102801D6
1375 static unsigned int dell9200_m22_pin_configs[8] = {
1376 0x40c003fa, 0x0144131f, 0x0321121f, 0x90170310,
1377 0x90a70321, 0x03a11020, 0x401003fb, 0x40f000fc,
1381 STAC 9200-32 pin configs for
1382 102801CE (Dell XPS M1710)
1383 102801CF (Dell Precision M90)
1385 static unsigned int dell9200_m23_pin_configs[8] = {
1386 0x40c003fa, 0x01441340, 0x0421421f, 0x90170310,
1387 0x408003fb, 0x04a1102e, 0x90170311, 0x403003fc,
1391 STAC 9200-32 pin configs for
1392 102801C9
1393 102801CA
1394 102801CB (Dell Latitude 120L)
1395 102801D3
1397 static unsigned int dell9200_m24_pin_configs[8] = {
1398 0x40c003fa, 0x404003fb, 0x0321121f, 0x90170310,
1399 0x408003fc, 0x03a11020, 0x401003fd, 0x403003fe,
1403 STAC 9200-32 pin configs for
1404 102801BD (Dell Inspiron E1505n)
1405 102801EE
1406 102801EF
1408 static unsigned int dell9200_m25_pin_configs[8] = {
1409 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
1410 0x408003fb, 0x04a11020, 0x401003fc, 0x403003fd,
1414 STAC 9200-32 pin configs for
1415 102801F5 (Dell Inspiron 1501)
1416 102801F6
1418 static unsigned int dell9200_m26_pin_configs[8] = {
1419 0x40c003fa, 0x404003fb, 0x0421121f, 0x90170310,
1420 0x408003fc, 0x04a11020, 0x401003fd, 0x403003fe,
1424 STAC 9200-32
1425 102801CD (Dell Inspiron E1705/9400)
1427 static unsigned int dell9200_m27_pin_configs[8] = {
1428 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
1429 0x90170310, 0x04a11020, 0x90170310, 0x40f003fc,
1432 static unsigned int oqo9200_pin_configs[8] = {
1433 0x40c000f0, 0x404000f1, 0x0221121f, 0x02211210,
1434 0x90170111, 0x90a70120, 0x400000f2, 0x400000f3,
1438 static unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
1439 [STAC_REF] = ref9200_pin_configs,
1440 [STAC_9200_OQO] = oqo9200_pin_configs,
1441 [STAC_9200_DELL_D21] = dell9200_d21_pin_configs,
1442 [STAC_9200_DELL_D22] = dell9200_d22_pin_configs,
1443 [STAC_9200_DELL_D23] = dell9200_d23_pin_configs,
1444 [STAC_9200_DELL_M21] = dell9200_m21_pin_configs,
1445 [STAC_9200_DELL_M22] = dell9200_m22_pin_configs,
1446 [STAC_9200_DELL_M23] = dell9200_m23_pin_configs,
1447 [STAC_9200_DELL_M24] = dell9200_m24_pin_configs,
1448 [STAC_9200_DELL_M25] = dell9200_m25_pin_configs,
1449 [STAC_9200_DELL_M26] = dell9200_m26_pin_configs,
1450 [STAC_9200_DELL_M27] = dell9200_m27_pin_configs,
1451 [STAC_9200_PANASONIC] = ref9200_pin_configs,
1454 static const char *stac9200_models[STAC_9200_MODELS] = {
1455 [STAC_REF] = "ref",
1456 [STAC_9200_OQO] = "oqo",
1457 [STAC_9200_DELL_D21] = "dell-d21",
1458 [STAC_9200_DELL_D22] = "dell-d22",
1459 [STAC_9200_DELL_D23] = "dell-d23",
1460 [STAC_9200_DELL_M21] = "dell-m21",
1461 [STAC_9200_DELL_M22] = "dell-m22",
1462 [STAC_9200_DELL_M23] = "dell-m23",
1463 [STAC_9200_DELL_M24] = "dell-m24",
1464 [STAC_9200_DELL_M25] = "dell-m25",
1465 [STAC_9200_DELL_M26] = "dell-m26",
1466 [STAC_9200_DELL_M27] = "dell-m27",
1467 [STAC_9200_GATEWAY] = "gateway",
1468 [STAC_9200_PANASONIC] = "panasonic",
1471 static struct snd_pci_quirk stac9200_cfg_tbl[] = {
1472 /* SigmaTel reference board */
1473 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1474 "DFI LanParty", STAC_REF),
1475 /* Dell laptops have BIOS problem */
1476 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a8,
1477 "unknown Dell", STAC_9200_DELL_D21),
1478 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01b5,
1479 "Dell Inspiron 630m", STAC_9200_DELL_M21),
1480 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bd,
1481 "Dell Inspiron E1505n", STAC_9200_DELL_M25),
1482 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c0,
1483 "unknown Dell", STAC_9200_DELL_D22),
1484 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c1,
1485 "unknown Dell", STAC_9200_DELL_D22),
1486 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c2,
1487 "Dell Latitude D620", STAC_9200_DELL_M22),
1488 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c5,
1489 "unknown Dell", STAC_9200_DELL_D23),
1490 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c7,
1491 "unknown Dell", STAC_9200_DELL_D23),
1492 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c8,
1493 "unknown Dell", STAC_9200_DELL_M22),
1494 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c9,
1495 "unknown Dell", STAC_9200_DELL_M24),
1496 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ca,
1497 "unknown Dell", STAC_9200_DELL_M24),
1498 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cb,
1499 "Dell Latitude 120L", STAC_9200_DELL_M24),
1500 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cc,
1501 "Dell Latitude D820", STAC_9200_DELL_M22),
1502 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cd,
1503 "Dell Inspiron E1705/9400", STAC_9200_DELL_M27),
1504 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ce,
1505 "Dell XPS M1710", STAC_9200_DELL_M23),
1506 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cf,
1507 "Dell Precision M90", STAC_9200_DELL_M23),
1508 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d3,
1509 "unknown Dell", STAC_9200_DELL_M22),
1510 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d4,
1511 "unknown Dell", STAC_9200_DELL_M22),
1512 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d6,
1513 "unknown Dell", STAC_9200_DELL_M22),
1514 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d8,
1515 "Dell Inspiron 640m", STAC_9200_DELL_M21),
1516 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d9,
1517 "unknown Dell", STAC_9200_DELL_D23),
1518 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01da,
1519 "unknown Dell", STAC_9200_DELL_D23),
1520 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01de,
1521 "unknown Dell", STAC_9200_DELL_D21),
1522 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e3,
1523 "unknown Dell", STAC_9200_DELL_D23),
1524 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e8,
1525 "unknown Dell", STAC_9200_DELL_D21),
1526 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ee,
1527 "unknown Dell", STAC_9200_DELL_M25),
1528 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ef,
1529 "unknown Dell", STAC_9200_DELL_M25),
1530 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f5,
1531 "Dell Inspiron 1501", STAC_9200_DELL_M26),
1532 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f6,
1533 "unknown Dell", STAC_9200_DELL_M26),
1534 /* Panasonic */
1535 SND_PCI_QUIRK(0x10f7, 0x8338, "Panasonic CF-74", STAC_9200_PANASONIC),
1536 /* Gateway machines needs EAPD to be set on resume */
1537 SND_PCI_QUIRK(0x107b, 0x0205, "Gateway S-7110M", STAC_9200_GATEWAY),
1538 SND_PCI_QUIRK(0x107b, 0x0317, "Gateway MT3423, MX341*",
1539 STAC_9200_GATEWAY),
1540 SND_PCI_QUIRK(0x107b, 0x0318, "Gateway ML3019, MT3707",
1541 STAC_9200_GATEWAY),
1542 /* OQO Mobile */
1543 SND_PCI_QUIRK(0x1106, 0x3288, "OQO Model 2", STAC_9200_OQO),
1544 {} /* terminator */
1547 static unsigned int ref925x_pin_configs[8] = {
1548 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
1549 0x90a70320, 0x02214210, 0x01019020, 0x9033032e,
1552 static unsigned int stac925x_MA6_pin_configs[8] = {
1553 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
1554 0x90a70320, 0x90100211, 0x400003f1, 0x9033032e,
1557 static unsigned int stac925x_PA6_pin_configs[8] = {
1558 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
1559 0x50a103f0, 0x90100211, 0x400003f1, 0x9033032e,
1562 static unsigned int stac925xM2_2_pin_configs[8] = {
1563 0x40c003f3, 0x424503f2, 0x04180011, 0x02a19020,
1564 0x50a103f0, 0x90100212, 0x400003f1, 0x9033032e,
1567 static unsigned int *stac925x_brd_tbl[STAC_925x_MODELS] = {
1568 [STAC_REF] = ref925x_pin_configs,
1569 [STAC_M2_2] = stac925xM2_2_pin_configs,
1570 [STAC_MA6] = stac925x_MA6_pin_configs,
1571 [STAC_PA6] = stac925x_PA6_pin_configs,
1574 static const char *stac925x_models[STAC_925x_MODELS] = {
1575 [STAC_REF] = "ref",
1576 [STAC_M2_2] = "m2-2",
1577 [STAC_MA6] = "m6",
1578 [STAC_PA6] = "pa6",
1581 static struct snd_pci_quirk stac925x_cfg_tbl[] = {
1582 /* SigmaTel reference board */
1583 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, "DFI LanParty", STAC_REF),
1584 SND_PCI_QUIRK(0x8384, 0x7632, "Stac9202 Reference Board", STAC_REF),
1585 SND_PCI_QUIRK(0x107b, 0x0316, "Gateway M255", STAC_REF),
1586 SND_PCI_QUIRK(0x107b, 0x0366, "Gateway MP6954", STAC_REF),
1587 SND_PCI_QUIRK(0x107b, 0x0461, "Gateway NX560XL", STAC_MA6),
1588 SND_PCI_QUIRK(0x107b, 0x0681, "Gateway NX860", STAC_PA6),
1589 SND_PCI_QUIRK(0x1002, 0x437b, "Gateway MX6453", STAC_M2_2),
1590 {} /* terminator */
1593 static unsigned int ref92hd73xx_pin_configs[13] = {
1594 0x02214030, 0x02a19040, 0x01a19020, 0x02214030,
1595 0x0181302e, 0x01014010, 0x01014020, 0x01014030,
1596 0x02319040, 0x90a000f0, 0x90a000f0, 0x01452050,
1597 0x01452050,
1600 static unsigned int dell_m6_pin_configs[13] = {
1601 0x0321101f, 0x4f00000f, 0x4f0000f0, 0x90170110,
1602 0x03a11020, 0x0321101f, 0x4f0000f0, 0x4f0000f0,
1603 0x4f0000f0, 0x90a60160, 0x4f0000f0, 0x4f0000f0,
1604 0x4f0000f0,
1607 static unsigned int *stac92hd73xx_brd_tbl[STAC_92HD73XX_MODELS] = {
1608 [STAC_92HD73XX_REF] = ref92hd73xx_pin_configs,
1609 [STAC_DELL_M6_AMIC] = dell_m6_pin_configs,
1610 [STAC_DELL_M6_DMIC] = dell_m6_pin_configs,
1611 [STAC_DELL_M6_BOTH] = dell_m6_pin_configs,
1612 [STAC_DELL_EQ] = dell_m6_pin_configs,
1615 static const char *stac92hd73xx_models[STAC_92HD73XX_MODELS] = {
1616 [STAC_92HD73XX_NO_JD] = "no-jd",
1617 [STAC_92HD73XX_REF] = "ref",
1618 [STAC_DELL_M6_AMIC] = "dell-m6-amic",
1619 [STAC_DELL_M6_DMIC] = "dell-m6-dmic",
1620 [STAC_DELL_M6_BOTH] = "dell-m6",
1621 [STAC_DELL_EQ] = "dell-eq",
1624 static struct snd_pci_quirk stac92hd73xx_cfg_tbl[] = {
1625 /* SigmaTel reference board */
1626 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1627 "DFI LanParty", STAC_92HD73XX_REF),
1628 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0254,
1629 "Dell Studio 1535", STAC_DELL_M6_DMIC),
1630 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0255,
1631 "unknown Dell", STAC_DELL_M6_DMIC),
1632 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0256,
1633 "unknown Dell", STAC_DELL_M6_BOTH),
1634 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0257,
1635 "unknown Dell", STAC_DELL_M6_BOTH),
1636 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025e,
1637 "unknown Dell", STAC_DELL_M6_AMIC),
1638 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025f,
1639 "unknown Dell", STAC_DELL_M6_AMIC),
1640 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0271,
1641 "unknown Dell", STAC_DELL_M6_DMIC),
1642 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0272,
1643 "unknown Dell", STAC_DELL_M6_DMIC),
1644 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x029f,
1645 "Dell Studio 1537", STAC_DELL_M6_DMIC),
1646 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02a0,
1647 "Dell Studio 17", STAC_DELL_M6_DMIC),
1648 {} /* terminator */
1651 static unsigned int ref92hd83xxx_pin_configs[14] = {
1652 0x02214030, 0x02211010, 0x02a19020, 0x02170130,
1653 0x01014050, 0x01819040, 0x01014020, 0x90a3014e,
1654 0x40f000f0, 0x40f000f0, 0x40f000f0, 0x40f000f0,
1655 0x01451160, 0x98560170,
1658 static unsigned int *stac92hd83xxx_brd_tbl[STAC_92HD83XXX_MODELS] = {
1659 [STAC_92HD83XXX_REF] = ref92hd83xxx_pin_configs,
1662 static const char *stac92hd83xxx_models[STAC_92HD83XXX_MODELS] = {
1663 [STAC_92HD83XXX_REF] = "ref",
1666 static struct snd_pci_quirk stac92hd83xxx_cfg_tbl[] = {
1667 /* SigmaTel reference board */
1668 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1669 "DFI LanParty", STAC_92HD71BXX_REF),
1672 static unsigned int ref92hd71bxx_pin_configs[11] = {
1673 0x02214030, 0x02a19040, 0x01a19020, 0x01014010,
1674 0x0181302e, 0x01014010, 0x01019020, 0x90a000f0,
1675 0x90a000f0, 0x01452050, 0x01452050,
1678 static unsigned int dell_m4_1_pin_configs[11] = {
1679 0x0421101f, 0x04a11221, 0x40f000f0, 0x90170110,
1680 0x23a1902e, 0x23014250, 0x40f000f0, 0x90a000f0,
1681 0x40f000f0, 0x4f0000f0, 0x4f0000f0,
1684 static unsigned int dell_m4_2_pin_configs[11] = {
1685 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1686 0x23a1902e, 0x23014250, 0x40f000f0, 0x40f000f0,
1687 0x40f000f0, 0x044413b0, 0x044413b0,
1690 static unsigned int dell_m4_3_pin_configs[11] = {
1691 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1692 0x40f000f0, 0x40f000f0, 0x40f000f0, 0x90a000f0,
1693 0x40f000f0, 0x044413b0, 0x044413b0,
1696 static unsigned int *stac92hd71bxx_brd_tbl[STAC_92HD71BXX_MODELS] = {
1697 [STAC_92HD71BXX_REF] = ref92hd71bxx_pin_configs,
1698 [STAC_DELL_M4_1] = dell_m4_1_pin_configs,
1699 [STAC_DELL_M4_2] = dell_m4_2_pin_configs,
1700 [STAC_DELL_M4_3] = dell_m4_3_pin_configs,
1701 [STAC_HP_M4] = NULL,
1704 static const char *stac92hd71bxx_models[STAC_92HD71BXX_MODELS] = {
1705 [STAC_92HD71BXX_REF] = "ref",
1706 [STAC_DELL_M4_1] = "dell-m4-1",
1707 [STAC_DELL_M4_2] = "dell-m4-2",
1708 [STAC_DELL_M4_3] = "dell-m4-3",
1709 [STAC_HP_M4] = "hp-m4",
1712 static struct snd_pci_quirk stac92hd71bxx_cfg_tbl[] = {
1713 /* SigmaTel reference board */
1714 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1715 "DFI LanParty", STAC_92HD71BXX_REF),
1716 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x30f2,
1717 "HP dv5", STAC_HP_M4),
1718 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x30f4,
1719 "HP dv7", STAC_HP_M4),
1720 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361a,
1721 "unknown HP", STAC_HP_M4),
1722 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0233,
1723 "unknown Dell", STAC_DELL_M4_1),
1724 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0234,
1725 "unknown Dell", STAC_DELL_M4_1),
1726 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0250,
1727 "unknown Dell", STAC_DELL_M4_1),
1728 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024f,
1729 "unknown Dell", STAC_DELL_M4_1),
1730 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024d,
1731 "unknown Dell", STAC_DELL_M4_1),
1732 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0251,
1733 "unknown Dell", STAC_DELL_M4_1),
1734 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0277,
1735 "unknown Dell", STAC_DELL_M4_1),
1736 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0263,
1737 "unknown Dell", STAC_DELL_M4_2),
1738 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0265,
1739 "unknown Dell", STAC_DELL_M4_2),
1740 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0262,
1741 "unknown Dell", STAC_DELL_M4_2),
1742 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0264,
1743 "unknown Dell", STAC_DELL_M4_2),
1744 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02aa,
1745 "unknown Dell", STAC_DELL_M4_3),
1746 {} /* terminator */
1749 static unsigned int ref922x_pin_configs[10] = {
1750 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
1751 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
1752 0x40000100, 0x40000100,
1756 STAC 922X pin configs for
1757 102801A7
1758 102801AB
1759 102801A9
1760 102801D1
1761 102801D2
1763 static unsigned int dell_922x_d81_pin_configs[10] = {
1764 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1765 0x02a19020, 0x01117011, 0x400001f0, 0x400001f1,
1766 0x01813122, 0x400001f2,
1770 STAC 922X pin configs for
1771 102801AC
1772 102801D0
1774 static unsigned int dell_922x_d82_pin_configs[10] = {
1775 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1776 0x02a19020, 0x01117011, 0x01451140, 0x400001f0,
1777 0x01813122, 0x400001f1,
1781 STAC 922X pin configs for
1782 102801BF
1784 static unsigned int dell_922x_m81_pin_configs[10] = {
1785 0x0321101f, 0x01112024, 0x01111222, 0x91174220,
1786 0x03a11050, 0x01116221, 0x90a70330, 0x01452340,
1787 0x40C003f1, 0x405003f0,
1791 STAC 9221 A1 pin configs for
1792 102801D7 (Dell XPS M1210)
1794 static unsigned int dell_922x_m82_pin_configs[10] = {
1795 0x02211211, 0x408103ff, 0x02a1123e, 0x90100310,
1796 0x408003f1, 0x0221121f, 0x03451340, 0x40c003f2,
1797 0x508003f3, 0x405003f4,
1800 static unsigned int d945gtp3_pin_configs[10] = {
1801 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
1802 0x40000100, 0x40000100, 0x40000100, 0x40000100,
1803 0x02a19120, 0x40000100,
1806 static unsigned int d945gtp5_pin_configs[10] = {
1807 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
1808 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
1809 0x02a19320, 0x40000100,
1812 static unsigned int intel_mac_v1_pin_configs[10] = {
1813 0x0121e21f, 0x400000ff, 0x9017e110, 0x400000fd,
1814 0x400000fe, 0x0181e020, 0x1145e030, 0x11c5e240,
1815 0x400000fc, 0x400000fb,
1818 static unsigned int intel_mac_v2_pin_configs[10] = {
1819 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
1820 0x400000fe, 0x0181e020, 0x1145e230, 0x500000fa,
1821 0x400000fc, 0x400000fb,
1824 static unsigned int intel_mac_v3_pin_configs[10] = {
1825 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
1826 0x400000fe, 0x0181e020, 0x1145e230, 0x11c5e240,
1827 0x400000fc, 0x400000fb,
1830 static unsigned int intel_mac_v4_pin_configs[10] = {
1831 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
1832 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
1833 0x400000fc, 0x400000fb,
1836 static unsigned int intel_mac_v5_pin_configs[10] = {
1837 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
1838 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
1839 0x400000fc, 0x400000fb,
1842 static unsigned int ecs202_pin_configs[10] = {
1843 0x0221401f, 0x02a19020, 0x01a19020, 0x01114010,
1844 0x408000f0, 0x01813022, 0x074510a0, 0x40c400f1,
1845 0x9037012e, 0x40e000f2,
1848 static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
1849 [STAC_D945_REF] = ref922x_pin_configs,
1850 [STAC_D945GTP3] = d945gtp3_pin_configs,
1851 [STAC_D945GTP5] = d945gtp5_pin_configs,
1852 [STAC_INTEL_MAC_V1] = intel_mac_v1_pin_configs,
1853 [STAC_INTEL_MAC_V2] = intel_mac_v2_pin_configs,
1854 [STAC_INTEL_MAC_V3] = intel_mac_v3_pin_configs,
1855 [STAC_INTEL_MAC_V4] = intel_mac_v4_pin_configs,
1856 [STAC_INTEL_MAC_V5] = intel_mac_v5_pin_configs,
1857 [STAC_INTEL_MAC_AUTO] = intel_mac_v3_pin_configs,
1858 /* for backward compatibility */
1859 [STAC_MACMINI] = intel_mac_v3_pin_configs,
1860 [STAC_MACBOOK] = intel_mac_v5_pin_configs,
1861 [STAC_MACBOOK_PRO_V1] = intel_mac_v3_pin_configs,
1862 [STAC_MACBOOK_PRO_V2] = intel_mac_v3_pin_configs,
1863 [STAC_IMAC_INTEL] = intel_mac_v2_pin_configs,
1864 [STAC_IMAC_INTEL_20] = intel_mac_v3_pin_configs,
1865 [STAC_ECS_202] = ecs202_pin_configs,
1866 [STAC_922X_DELL_D81] = dell_922x_d81_pin_configs,
1867 [STAC_922X_DELL_D82] = dell_922x_d82_pin_configs,
1868 [STAC_922X_DELL_M81] = dell_922x_m81_pin_configs,
1869 [STAC_922X_DELL_M82] = dell_922x_m82_pin_configs,
1872 static const char *stac922x_models[STAC_922X_MODELS] = {
1873 [STAC_D945_REF] = "ref",
1874 [STAC_D945GTP5] = "5stack",
1875 [STAC_D945GTP3] = "3stack",
1876 [STAC_INTEL_MAC_V1] = "intel-mac-v1",
1877 [STAC_INTEL_MAC_V2] = "intel-mac-v2",
1878 [STAC_INTEL_MAC_V3] = "intel-mac-v3",
1879 [STAC_INTEL_MAC_V4] = "intel-mac-v4",
1880 [STAC_INTEL_MAC_V5] = "intel-mac-v5",
1881 [STAC_INTEL_MAC_AUTO] = "intel-mac-auto",
1882 /* for backward compatibility */
1883 [STAC_MACMINI] = "macmini",
1884 [STAC_MACBOOK] = "macbook",
1885 [STAC_MACBOOK_PRO_V1] = "macbook-pro-v1",
1886 [STAC_MACBOOK_PRO_V2] = "macbook-pro",
1887 [STAC_IMAC_INTEL] = "imac-intel",
1888 [STAC_IMAC_INTEL_20] = "imac-intel-20",
1889 [STAC_ECS_202] = "ecs202",
1890 [STAC_922X_DELL_D81] = "dell-d81",
1891 [STAC_922X_DELL_D82] = "dell-d82",
1892 [STAC_922X_DELL_M81] = "dell-m81",
1893 [STAC_922X_DELL_M82] = "dell-m82",
1896 static struct snd_pci_quirk stac922x_cfg_tbl[] = {
1897 /* SigmaTel reference board */
1898 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1899 "DFI LanParty", STAC_D945_REF),
1900 /* Intel 945G based systems */
1901 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101,
1902 "Intel D945G", STAC_D945GTP3),
1903 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0202,
1904 "Intel D945G", STAC_D945GTP3),
1905 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0606,
1906 "Intel D945G", STAC_D945GTP3),
1907 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0601,
1908 "Intel D945G", STAC_D945GTP3),
1909 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0111,
1910 "Intel D945G", STAC_D945GTP3),
1911 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1115,
1912 "Intel D945G", STAC_D945GTP3),
1913 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1116,
1914 "Intel D945G", STAC_D945GTP3),
1915 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1117,
1916 "Intel D945G", STAC_D945GTP3),
1917 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1118,
1918 "Intel D945G", STAC_D945GTP3),
1919 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1119,
1920 "Intel D945G", STAC_D945GTP3),
1921 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x8826,
1922 "Intel D945G", STAC_D945GTP3),
1923 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5049,
1924 "Intel D945G", STAC_D945GTP3),
1925 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5055,
1926 "Intel D945G", STAC_D945GTP3),
1927 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5048,
1928 "Intel D945G", STAC_D945GTP3),
1929 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0110,
1930 "Intel D945G", STAC_D945GTP3),
1931 /* Intel D945G 5-stack systems */
1932 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0404,
1933 "Intel D945G", STAC_D945GTP5),
1934 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0303,
1935 "Intel D945G", STAC_D945GTP5),
1936 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0013,
1937 "Intel D945G", STAC_D945GTP5),
1938 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0417,
1939 "Intel D945G", STAC_D945GTP5),
1940 /* Intel 945P based systems */
1941 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0b0b,
1942 "Intel D945P", STAC_D945GTP3),
1943 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0112,
1944 "Intel D945P", STAC_D945GTP3),
1945 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0d0d,
1946 "Intel D945P", STAC_D945GTP3),
1947 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0909,
1948 "Intel D945P", STAC_D945GTP3),
1949 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0505,
1950 "Intel D945P", STAC_D945GTP3),
1951 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707,
1952 "Intel D945P", STAC_D945GTP5),
1953 /* other systems */
1954 /* Apple Intel Mac (Mac Mini, MacBook, MacBook Pro...) */
1955 SND_PCI_QUIRK(0x8384, 0x7680,
1956 "Mac", STAC_INTEL_MAC_AUTO),
1957 /* Dell systems */
1958 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a7,
1959 "unknown Dell", STAC_922X_DELL_D81),
1960 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a9,
1961 "unknown Dell", STAC_922X_DELL_D81),
1962 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ab,
1963 "unknown Dell", STAC_922X_DELL_D81),
1964 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ac,
1965 "unknown Dell", STAC_922X_DELL_D82),
1966 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bf,
1967 "unknown Dell", STAC_922X_DELL_M81),
1968 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d0,
1969 "unknown Dell", STAC_922X_DELL_D82),
1970 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d1,
1971 "unknown Dell", STAC_922X_DELL_D81),
1972 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d2,
1973 "unknown Dell", STAC_922X_DELL_D81),
1974 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d7,
1975 "Dell XPS M1210", STAC_922X_DELL_M82),
1976 /* ECS/PC Chips boards */
1977 SND_PCI_QUIRK(0x1019, 0x2144,
1978 "ECS/PC chips", STAC_ECS_202),
1979 SND_PCI_QUIRK(0x1019, 0x2608,
1980 "ECS/PC chips", STAC_ECS_202),
1981 SND_PCI_QUIRK(0x1019, 0x2633,
1982 "ECS/PC chips P17G/1333", STAC_ECS_202),
1983 SND_PCI_QUIRK(0x1019, 0x2811,
1984 "ECS/PC chips", STAC_ECS_202),
1985 SND_PCI_QUIRK(0x1019, 0x2812,
1986 "ECS/PC chips", STAC_ECS_202),
1987 SND_PCI_QUIRK(0x1019, 0x2813,
1988 "ECS/PC chips", STAC_ECS_202),
1989 SND_PCI_QUIRK(0x1019, 0x2814,
1990 "ECS/PC chips", STAC_ECS_202),
1991 SND_PCI_QUIRK(0x1019, 0x2815,
1992 "ECS/PC chips", STAC_ECS_202),
1993 SND_PCI_QUIRK(0x1019, 0x2816,
1994 "ECS/PC chips", STAC_ECS_202),
1995 SND_PCI_QUIRK(0x1019, 0x2817,
1996 "ECS/PC chips", STAC_ECS_202),
1997 SND_PCI_QUIRK(0x1019, 0x2818,
1998 "ECS/PC chips", STAC_ECS_202),
1999 SND_PCI_QUIRK(0x1019, 0x2819,
2000 "ECS/PC chips", STAC_ECS_202),
2001 SND_PCI_QUIRK(0x1019, 0x2820,
2002 "ECS/PC chips", STAC_ECS_202),
2003 {} /* terminator */
2006 static unsigned int ref927x_pin_configs[14] = {
2007 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2008 0x01a19040, 0x01011012, 0x01016011, 0x0101201f,
2009 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
2010 0x01c42190, 0x40000100,
2013 static unsigned int d965_3st_pin_configs[14] = {
2014 0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
2015 0x01a19021, 0x01813024, 0x40000100, 0x40000100,
2016 0x40000100, 0x40000100, 0x40000100, 0x40000100,
2017 0x40000100, 0x40000100
2020 static unsigned int d965_5st_pin_configs[14] = {
2021 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2022 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
2023 0x40000100, 0x40000100, 0x40000100, 0x01442070,
2024 0x40000100, 0x40000100
2027 static unsigned int dell_3st_pin_configs[14] = {
2028 0x02211230, 0x02a11220, 0x01a19040, 0x01114210,
2029 0x01111212, 0x01116211, 0x01813050, 0x01112214,
2030 0x403003fa, 0x90a60040, 0x90a60040, 0x404003fb,
2031 0x40c003fc, 0x40000100
2034 static unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
2035 [STAC_D965_REF_NO_JD] = ref927x_pin_configs,
2036 [STAC_D965_REF] = ref927x_pin_configs,
2037 [STAC_D965_3ST] = d965_3st_pin_configs,
2038 [STAC_D965_5ST] = d965_5st_pin_configs,
2039 [STAC_DELL_3ST] = dell_3st_pin_configs,
2040 [STAC_DELL_BIOS] = NULL,
2043 static const char *stac927x_models[STAC_927X_MODELS] = {
2044 [STAC_D965_REF_NO_JD] = "ref-no-jd",
2045 [STAC_D965_REF] = "ref",
2046 [STAC_D965_3ST] = "3stack",
2047 [STAC_D965_5ST] = "5stack",
2048 [STAC_DELL_3ST] = "dell-3stack",
2049 [STAC_DELL_BIOS] = "dell-bios",
2052 static struct snd_pci_quirk stac927x_cfg_tbl[] = {
2053 /* SigmaTel reference board */
2054 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2055 "DFI LanParty", STAC_D965_REF),
2056 /* Intel 946 based systems */
2057 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST),
2058 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST),
2059 /* 965 based 3 stack systems */
2060 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2116, "Intel D965", STAC_D965_3ST),
2061 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2115, "Intel D965", STAC_D965_3ST),
2062 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2114, "Intel D965", STAC_D965_3ST),
2063 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2113, "Intel D965", STAC_D965_3ST),
2064 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2112, "Intel D965", STAC_D965_3ST),
2065 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2111, "Intel D965", STAC_D965_3ST),
2066 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2110, "Intel D965", STAC_D965_3ST),
2067 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2009, "Intel D965", STAC_D965_3ST),
2068 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2008, "Intel D965", STAC_D965_3ST),
2069 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2007, "Intel D965", STAC_D965_3ST),
2070 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2006, "Intel D965", STAC_D965_3ST),
2071 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2005, "Intel D965", STAC_D965_3ST),
2072 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2004, "Intel D965", STAC_D965_3ST),
2073 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2003, "Intel D965", STAC_D965_3ST),
2074 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2002, "Intel D965", STAC_D965_3ST),
2075 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2001, "Intel D965", STAC_D965_3ST),
2076 /* Dell 3 stack systems */
2077 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f7, "Dell XPS M1730", STAC_DELL_3ST),
2078 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01dd, "Dell Dimension E520", STAC_DELL_3ST),
2079 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ed, "Dell ", STAC_DELL_3ST),
2080 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f4, "Dell ", STAC_DELL_3ST),
2081 /* Dell 3 stack systems with verb table in BIOS */
2082 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f3, "Dell Inspiron 1420", STAC_DELL_BIOS),
2083 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0227, "Dell Vostro 1400 ", STAC_DELL_BIOS),
2084 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022e, "Dell ", STAC_DELL_BIOS),
2085 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022f, "Dell Inspiron 1525", STAC_DELL_3ST),
2086 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0242, "Dell ", STAC_DELL_BIOS),
2087 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0243, "Dell ", STAC_DELL_BIOS),
2088 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ff, "Dell ", STAC_DELL_BIOS),
2089 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0209, "Dell XPS 1330", STAC_DELL_BIOS),
2090 /* 965 based 5 stack systems */
2091 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2301, "Intel D965", STAC_D965_5ST),
2092 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2302, "Intel D965", STAC_D965_5ST),
2093 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2303, "Intel D965", STAC_D965_5ST),
2094 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2304, "Intel D965", STAC_D965_5ST),
2095 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2305, "Intel D965", STAC_D965_5ST),
2096 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2501, "Intel D965", STAC_D965_5ST),
2097 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2502, "Intel D965", STAC_D965_5ST),
2098 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2503, "Intel D965", STAC_D965_5ST),
2099 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2504, "Intel D965", STAC_D965_5ST),
2100 {} /* terminator */
2103 static unsigned int ref9205_pin_configs[12] = {
2104 0x40000100, 0x40000100, 0x01016011, 0x01014010,
2105 0x01813122, 0x01a19021, 0x01019020, 0x40000100,
2106 0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
2110 STAC 9205 pin configs for
2111 102801F1
2112 102801F2
2113 102801FC
2114 102801FD
2115 10280204
2116 1028021F
2117 10280228 (Dell Vostro 1500)
2119 static unsigned int dell_9205_m42_pin_configs[12] = {
2120 0x0321101F, 0x03A11020, 0x400003FA, 0x90170310,
2121 0x400003FB, 0x400003FC, 0x400003FD, 0x40F000F9,
2122 0x90A60330, 0x400003FF, 0x0144131F, 0x40C003FE,
2126 STAC 9205 pin configs for
2127 102801F9
2128 102801FA
2129 102801FE
2130 102801FF (Dell Precision M4300)
2131 10280206
2132 10280200
2133 10280201
2135 static unsigned int dell_9205_m43_pin_configs[12] = {
2136 0x0321101f, 0x03a11020, 0x90a70330, 0x90170310,
2137 0x400000fe, 0x400000ff, 0x400000fd, 0x40f000f9,
2138 0x400000fa, 0x400000fc, 0x0144131f, 0x40c003f8,
2141 static unsigned int dell_9205_m44_pin_configs[12] = {
2142 0x0421101f, 0x04a11020, 0x400003fa, 0x90170310,
2143 0x400003fb, 0x400003fc, 0x400003fd, 0x400003f9,
2144 0x90a60330, 0x400003ff, 0x01441340, 0x40c003fe,
2147 static unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
2148 [STAC_9205_REF] = ref9205_pin_configs,
2149 [STAC_9205_DELL_M42] = dell_9205_m42_pin_configs,
2150 [STAC_9205_DELL_M43] = dell_9205_m43_pin_configs,
2151 [STAC_9205_DELL_M44] = dell_9205_m44_pin_configs,
2154 static const char *stac9205_models[STAC_9205_MODELS] = {
2155 [STAC_9205_REF] = "ref",
2156 [STAC_9205_DELL_M42] = "dell-m42",
2157 [STAC_9205_DELL_M43] = "dell-m43",
2158 [STAC_9205_DELL_M44] = "dell-m44",
2161 static struct snd_pci_quirk stac9205_cfg_tbl[] = {
2162 /* SigmaTel reference board */
2163 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2164 "DFI LanParty", STAC_9205_REF),
2165 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f1,
2166 "unknown Dell", STAC_9205_DELL_M42),
2167 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f2,
2168 "unknown Dell", STAC_9205_DELL_M42),
2169 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f8,
2170 "Dell Precision", STAC_9205_DELL_M43),
2171 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f9,
2172 "Dell Precision", STAC_9205_DELL_M43),
2173 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fa,
2174 "Dell Precision", STAC_9205_DELL_M43),
2175 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fc,
2176 "unknown Dell", STAC_9205_DELL_M42),
2177 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fd,
2178 "unknown Dell", STAC_9205_DELL_M42),
2179 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fe,
2180 "Dell Precision", STAC_9205_DELL_M43),
2181 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ff,
2182 "Dell Precision M4300", STAC_9205_DELL_M43),
2183 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0204,
2184 "unknown Dell", STAC_9205_DELL_M42),
2185 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0206,
2186 "Dell Precision", STAC_9205_DELL_M43),
2187 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021b,
2188 "Dell Precision", STAC_9205_DELL_M43),
2189 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021c,
2190 "Dell Precision", STAC_9205_DELL_M43),
2191 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021f,
2192 "Dell Inspiron", STAC_9205_DELL_M44),
2193 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0228,
2194 "Dell Vostro 1500", STAC_9205_DELL_M42),
2195 {} /* terminator */
2198 static int stac92xx_save_bios_config_regs(struct hda_codec *codec)
2200 int i;
2201 struct sigmatel_spec *spec = codec->spec;
2203 if (! spec->bios_pin_configs) {
2204 spec->bios_pin_configs = kcalloc(spec->num_pins,
2205 sizeof(*spec->bios_pin_configs), GFP_KERNEL);
2206 if (! spec->bios_pin_configs)
2207 return -ENOMEM;
2210 for (i = 0; i < spec->num_pins; i++) {
2211 hda_nid_t nid = spec->pin_nids[i];
2212 unsigned int pin_cfg;
2214 pin_cfg = snd_hda_codec_read(codec, nid, 0,
2215 AC_VERB_GET_CONFIG_DEFAULT, 0x00);
2216 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x bios pin config %8.8x\n",
2217 nid, pin_cfg);
2218 spec->bios_pin_configs[i] = pin_cfg;
2221 return 0;
2224 static void stac92xx_set_config_reg(struct hda_codec *codec,
2225 hda_nid_t pin_nid, unsigned int pin_config)
2227 int i;
2228 snd_hda_codec_write(codec, pin_nid, 0,
2229 AC_VERB_SET_CONFIG_DEFAULT_BYTES_0,
2230 pin_config & 0x000000ff);
2231 snd_hda_codec_write(codec, pin_nid, 0,
2232 AC_VERB_SET_CONFIG_DEFAULT_BYTES_1,
2233 (pin_config & 0x0000ff00) >> 8);
2234 snd_hda_codec_write(codec, pin_nid, 0,
2235 AC_VERB_SET_CONFIG_DEFAULT_BYTES_2,
2236 (pin_config & 0x00ff0000) >> 16);
2237 snd_hda_codec_write(codec, pin_nid, 0,
2238 AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
2239 pin_config >> 24);
2240 i = snd_hda_codec_read(codec, pin_nid, 0,
2241 AC_VERB_GET_CONFIG_DEFAULT,
2242 0x00);
2243 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x pin config %8.8x\n",
2244 pin_nid, i);
2247 static void stac92xx_set_config_regs(struct hda_codec *codec)
2249 int i;
2250 struct sigmatel_spec *spec = codec->spec;
2252 if (!spec->pin_configs)
2253 return;
2255 for (i = 0; i < spec->num_pins; i++)
2256 stac92xx_set_config_reg(codec, spec->pin_nids[i],
2257 spec->pin_configs[i]);
2261 * Analog playback callbacks
2263 static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
2264 struct hda_codec *codec,
2265 struct snd_pcm_substream *substream)
2267 struct sigmatel_spec *spec = codec->spec;
2268 if (spec->stream_delay)
2269 msleep(spec->stream_delay);
2270 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2271 hinfo);
2274 static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2275 struct hda_codec *codec,
2276 unsigned int stream_tag,
2277 unsigned int format,
2278 struct snd_pcm_substream *substream)
2280 struct sigmatel_spec *spec = codec->spec;
2281 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
2284 static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2285 struct hda_codec *codec,
2286 struct snd_pcm_substream *substream)
2288 struct sigmatel_spec *spec = codec->spec;
2289 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2293 * Digital playback callbacks
2295 static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2296 struct hda_codec *codec,
2297 struct snd_pcm_substream *substream)
2299 struct sigmatel_spec *spec = codec->spec;
2300 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2303 static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2304 struct hda_codec *codec,
2305 struct snd_pcm_substream *substream)
2307 struct sigmatel_spec *spec = codec->spec;
2308 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2311 static int stac92xx_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2312 struct hda_codec *codec,
2313 unsigned int stream_tag,
2314 unsigned int format,
2315 struct snd_pcm_substream *substream)
2317 struct sigmatel_spec *spec = codec->spec;
2318 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2319 stream_tag, format, substream);
2324 * Analog capture callbacks
2326 static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2327 struct hda_codec *codec,
2328 unsigned int stream_tag,
2329 unsigned int format,
2330 struct snd_pcm_substream *substream)
2332 struct sigmatel_spec *spec = codec->spec;
2333 hda_nid_t nid = spec->adc_nids[substream->number];
2335 if (spec->powerdown_adcs) {
2336 msleep(40);
2337 snd_hda_codec_write_cache(codec, nid, 0,
2338 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
2340 snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format);
2341 return 0;
2344 static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2345 struct hda_codec *codec,
2346 struct snd_pcm_substream *substream)
2348 struct sigmatel_spec *spec = codec->spec;
2349 hda_nid_t nid = spec->adc_nids[substream->number];
2351 snd_hda_codec_cleanup_stream(codec, nid);
2352 if (spec->powerdown_adcs)
2353 snd_hda_codec_write_cache(codec, nid, 0,
2354 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
2355 return 0;
2358 static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
2359 .substreams = 1,
2360 .channels_min = 2,
2361 .channels_max = 2,
2362 /* NID is set in stac92xx_build_pcms */
2363 .ops = {
2364 .open = stac92xx_dig_playback_pcm_open,
2365 .close = stac92xx_dig_playback_pcm_close,
2366 .prepare = stac92xx_dig_playback_pcm_prepare
2370 static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
2371 .substreams = 1,
2372 .channels_min = 2,
2373 .channels_max = 2,
2374 /* NID is set in stac92xx_build_pcms */
2377 static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
2378 .substreams = 1,
2379 .channels_min = 2,
2380 .channels_max = 8,
2381 .nid = 0x02, /* NID to query formats and rates */
2382 .ops = {
2383 .open = stac92xx_playback_pcm_open,
2384 .prepare = stac92xx_playback_pcm_prepare,
2385 .cleanup = stac92xx_playback_pcm_cleanup
2389 static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
2390 .substreams = 1,
2391 .channels_min = 2,
2392 .channels_max = 2,
2393 .nid = 0x06, /* NID to query formats and rates */
2394 .ops = {
2395 .open = stac92xx_playback_pcm_open,
2396 .prepare = stac92xx_playback_pcm_prepare,
2397 .cleanup = stac92xx_playback_pcm_cleanup
2401 static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
2402 .channels_min = 2,
2403 .channels_max = 2,
2404 /* NID + .substreams is set in stac92xx_build_pcms */
2405 .ops = {
2406 .prepare = stac92xx_capture_pcm_prepare,
2407 .cleanup = stac92xx_capture_pcm_cleanup
2411 static int stac92xx_build_pcms(struct hda_codec *codec)
2413 struct sigmatel_spec *spec = codec->spec;
2414 struct hda_pcm *info = spec->pcm_rec;
2416 codec->num_pcms = 1;
2417 codec->pcm_info = info;
2419 info->name = "STAC92xx Analog";
2420 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
2421 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
2422 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2423 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adcs;
2425 if (spec->alt_switch) {
2426 codec->num_pcms++;
2427 info++;
2428 info->name = "STAC92xx Analog Alt";
2429 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
2432 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2433 codec->num_pcms++;
2434 info++;
2435 info->name = "STAC92xx Digital";
2436 info->pcm_type = HDA_PCM_TYPE_SPDIF;
2437 if (spec->multiout.dig_out_nid) {
2438 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
2439 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2441 if (spec->dig_in_nid) {
2442 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
2443 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2447 return 0;
2450 static unsigned int stac92xx_get_vref(struct hda_codec *codec, hda_nid_t nid)
2452 unsigned int pincap = snd_hda_param_read(codec, nid,
2453 AC_PAR_PIN_CAP);
2454 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
2455 if (pincap & AC_PINCAP_VREF_100)
2456 return AC_PINCTL_VREF_100;
2457 if (pincap & AC_PINCAP_VREF_80)
2458 return AC_PINCTL_VREF_80;
2459 if (pincap & AC_PINCAP_VREF_50)
2460 return AC_PINCTL_VREF_50;
2461 if (pincap & AC_PINCAP_VREF_GRD)
2462 return AC_PINCTL_VREF_GRD;
2463 return 0;
2466 static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
2469 snd_hda_codec_write_cache(codec, nid, 0,
2470 AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
2473 #define stac92xx_hp_switch_info snd_ctl_boolean_mono_info
2475 static int stac92xx_hp_switch_get(struct snd_kcontrol *kcontrol,
2476 struct snd_ctl_elem_value *ucontrol)
2478 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2479 struct sigmatel_spec *spec = codec->spec;
2481 ucontrol->value.integer.value[0] = !!spec->hp_switch;
2482 return 0;
2485 static int stac92xx_hp_switch_put(struct snd_kcontrol *kcontrol,
2486 struct snd_ctl_elem_value *ucontrol)
2488 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2489 struct sigmatel_spec *spec = codec->spec;
2490 int nid = kcontrol->private_value;
2492 spec->hp_switch = ucontrol->value.integer.value[0] ? nid : 0;
2494 /* check to be sure that the ports are upto date with
2495 * switch changes
2497 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
2499 return 1;
2502 #define stac92xx_io_switch_info snd_ctl_boolean_mono_info
2504 static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2506 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2507 struct sigmatel_spec *spec = codec->spec;
2508 int io_idx = kcontrol-> private_value & 0xff;
2510 ucontrol->value.integer.value[0] = spec->io_switch[io_idx];
2511 return 0;
2514 static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2516 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2517 struct sigmatel_spec *spec = codec->spec;
2518 hda_nid_t nid = kcontrol->private_value >> 8;
2519 int io_idx = kcontrol-> private_value & 0xff;
2520 unsigned short val = !!ucontrol->value.integer.value[0];
2522 spec->io_switch[io_idx] = val;
2524 if (val)
2525 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
2526 else {
2527 unsigned int pinctl = AC_PINCTL_IN_EN;
2528 if (io_idx) /* set VREF for mic */
2529 pinctl |= stac92xx_get_vref(codec, nid);
2530 stac92xx_auto_set_pinctl(codec, nid, pinctl);
2533 /* check the auto-mute again: we need to mute/unmute the speaker
2534 * appropriately according to the pin direction
2536 if (spec->hp_detect)
2537 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
2539 return 1;
2542 #define stac92xx_clfe_switch_info snd_ctl_boolean_mono_info
2544 static int stac92xx_clfe_switch_get(struct snd_kcontrol *kcontrol,
2545 struct snd_ctl_elem_value *ucontrol)
2547 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2548 struct sigmatel_spec *spec = codec->spec;
2550 ucontrol->value.integer.value[0] = spec->clfe_swap;
2551 return 0;
2554 static int stac92xx_clfe_switch_put(struct snd_kcontrol *kcontrol,
2555 struct snd_ctl_elem_value *ucontrol)
2557 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2558 struct sigmatel_spec *spec = codec->spec;
2559 hda_nid_t nid = kcontrol->private_value & 0xff;
2560 unsigned int val = !!ucontrol->value.integer.value[0];
2562 if (spec->clfe_swap == val)
2563 return 0;
2565 spec->clfe_swap = val;
2567 snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
2568 spec->clfe_swap ? 0x4 : 0x0);
2570 return 1;
2573 #define STAC_CODEC_HP_SWITCH(xname) \
2574 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2575 .name = xname, \
2576 .index = 0, \
2577 .info = stac92xx_hp_switch_info, \
2578 .get = stac92xx_hp_switch_get, \
2579 .put = stac92xx_hp_switch_put, \
2582 #define STAC_CODEC_IO_SWITCH(xname, xpval) \
2583 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2584 .name = xname, \
2585 .index = 0, \
2586 .info = stac92xx_io_switch_info, \
2587 .get = stac92xx_io_switch_get, \
2588 .put = stac92xx_io_switch_put, \
2589 .private_value = xpval, \
2592 #define STAC_CODEC_CLFE_SWITCH(xname, xpval) \
2593 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2594 .name = xname, \
2595 .index = 0, \
2596 .info = stac92xx_clfe_switch_info, \
2597 .get = stac92xx_clfe_switch_get, \
2598 .put = stac92xx_clfe_switch_put, \
2599 .private_value = xpval, \
2602 enum {
2603 STAC_CTL_WIDGET_VOL,
2604 STAC_CTL_WIDGET_MUTE,
2605 STAC_CTL_WIDGET_MONO_MUX,
2606 STAC_CTL_WIDGET_AMP_MUX,
2607 STAC_CTL_WIDGET_AMP_VOL,
2608 STAC_CTL_WIDGET_HP_SWITCH,
2609 STAC_CTL_WIDGET_IO_SWITCH,
2610 STAC_CTL_WIDGET_CLFE_SWITCH
2613 static struct snd_kcontrol_new stac92xx_control_templates[] = {
2614 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2615 HDA_CODEC_MUTE(NULL, 0, 0, 0),
2616 STAC_MONO_MUX,
2617 STAC_AMP_MUX,
2618 STAC_AMP_VOL(NULL, 0, 0, 0, 0),
2619 STAC_CODEC_HP_SWITCH(NULL),
2620 STAC_CODEC_IO_SWITCH(NULL, 0),
2621 STAC_CODEC_CLFE_SWITCH(NULL, 0),
2624 /* add dynamic controls */
2625 static int stac92xx_add_control_temp(struct sigmatel_spec *spec,
2626 struct snd_kcontrol_new *ktemp,
2627 int idx, const char *name,
2628 unsigned long val)
2630 struct snd_kcontrol_new *knew;
2632 if (spec->num_kctl_used >= spec->num_kctl_alloc) {
2633 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
2635 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */
2636 if (! knew)
2637 return -ENOMEM;
2638 if (spec->kctl_alloc) {
2639 memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
2640 kfree(spec->kctl_alloc);
2642 spec->kctl_alloc = knew;
2643 spec->num_kctl_alloc = num;
2646 knew = &spec->kctl_alloc[spec->num_kctl_used];
2647 *knew = *ktemp;
2648 knew->index = idx;
2649 knew->name = kstrdup(name, GFP_KERNEL);
2650 if (!knew->name)
2651 return -ENOMEM;
2652 knew->private_value = val;
2653 spec->num_kctl_used++;
2654 return 0;
2657 static inline int stac92xx_add_control_idx(struct sigmatel_spec *spec,
2658 int type, int idx, const char *name,
2659 unsigned long val)
2661 return stac92xx_add_control_temp(spec,
2662 &stac92xx_control_templates[type],
2663 idx, name, val);
2667 /* add dynamic controls */
2668 static inline int stac92xx_add_control(struct sigmatel_spec *spec, int type,
2669 const char *name, unsigned long val)
2671 return stac92xx_add_control_idx(spec, type, 0, name, val);
2674 /* flag inputs as additional dynamic lineouts */
2675 static int stac92xx_add_dyn_out_pins(struct hda_codec *codec, struct auto_pin_cfg *cfg)
2677 struct sigmatel_spec *spec = codec->spec;
2678 unsigned int wcaps, wtype;
2679 int i, num_dacs = 0;
2681 /* use the wcaps cache to count all DACs available for line-outs */
2682 for (i = 0; i < codec->num_nodes; i++) {
2683 wcaps = codec->wcaps[i];
2684 wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
2686 if (wtype == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL))
2687 num_dacs++;
2690 snd_printdd("%s: total dac count=%d\n", __func__, num_dacs);
2692 switch (cfg->line_outs) {
2693 case 3:
2694 /* add line-in as side */
2695 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 3) {
2696 cfg->line_out_pins[cfg->line_outs] =
2697 cfg->input_pins[AUTO_PIN_LINE];
2698 spec->line_switch = 1;
2699 cfg->line_outs++;
2701 break;
2702 case 2:
2703 /* add line-in as clfe and mic as side */
2704 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 2) {
2705 cfg->line_out_pins[cfg->line_outs] =
2706 cfg->input_pins[AUTO_PIN_LINE];
2707 spec->line_switch = 1;
2708 cfg->line_outs++;
2710 if (cfg->input_pins[AUTO_PIN_MIC] && num_dacs > 3) {
2711 cfg->line_out_pins[cfg->line_outs] =
2712 cfg->input_pins[AUTO_PIN_MIC];
2713 spec->mic_switch = 1;
2714 cfg->line_outs++;
2716 break;
2717 case 1:
2718 /* add line-in as surr and mic as clfe */
2719 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 1) {
2720 cfg->line_out_pins[cfg->line_outs] =
2721 cfg->input_pins[AUTO_PIN_LINE];
2722 spec->line_switch = 1;
2723 cfg->line_outs++;
2725 if (cfg->input_pins[AUTO_PIN_MIC] && num_dacs > 2) {
2726 cfg->line_out_pins[cfg->line_outs] =
2727 cfg->input_pins[AUTO_PIN_MIC];
2728 spec->mic_switch = 1;
2729 cfg->line_outs++;
2731 break;
2734 return 0;
2738 static int is_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2740 int i;
2742 for (i = 0; i < spec->multiout.num_dacs; i++) {
2743 if (spec->multiout.dac_nids[i] == nid)
2744 return 1;
2747 return 0;
2751 * Fill in the dac_nids table from the parsed pin configuration
2752 * This function only works when every pin in line_out_pins[]
2753 * contains atleast one DAC in its connection list. Some 92xx
2754 * codecs are not connected directly to a DAC, such as the 9200
2755 * and 9202/925x. For those, dac_nids[] must be hard-coded.
2757 static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec,
2758 struct auto_pin_cfg *cfg)
2760 struct sigmatel_spec *spec = codec->spec;
2761 int i, j, conn_len = 0;
2762 hda_nid_t nid, conn[HDA_MAX_CONNECTIONS];
2763 unsigned int wcaps, wtype;
2765 for (i = 0; i < cfg->line_outs; i++) {
2766 nid = cfg->line_out_pins[i];
2767 conn_len = snd_hda_get_connections(codec, nid, conn,
2768 HDA_MAX_CONNECTIONS);
2769 for (j = 0; j < conn_len; j++) {
2770 wcaps = snd_hda_param_read(codec, conn[j],
2771 AC_PAR_AUDIO_WIDGET_CAP);
2772 wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
2773 if (wtype != AC_WID_AUD_OUT ||
2774 (wcaps & AC_WCAP_DIGITAL))
2775 continue;
2776 /* conn[j] is a DAC routed to this line-out */
2777 if (!is_in_dac_nids(spec, conn[j]))
2778 break;
2781 if (j == conn_len) {
2782 if (spec->multiout.num_dacs > 0) {
2783 /* we have already working output pins,
2784 * so let's drop the broken ones again
2786 cfg->line_outs = spec->multiout.num_dacs;
2787 break;
2789 /* error out, no available DAC found */
2790 snd_printk(KERN_ERR
2791 "%s: No available DAC for pin 0x%x\n",
2792 __func__, nid);
2793 return -ENODEV;
2796 spec->multiout.dac_nids[i] = conn[j];
2797 spec->multiout.num_dacs++;
2798 if (conn_len > 1) {
2799 /* select this DAC in the pin's input mux */
2800 snd_hda_codec_write_cache(codec, nid, 0,
2801 AC_VERB_SET_CONNECT_SEL, j);
2806 snd_printd("dac_nids=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
2807 spec->multiout.num_dacs,
2808 spec->multiout.dac_nids[0],
2809 spec->multiout.dac_nids[1],
2810 spec->multiout.dac_nids[2],
2811 spec->multiout.dac_nids[3],
2812 spec->multiout.dac_nids[4]);
2813 return 0;
2816 /* create volume control/switch for the given prefx type */
2817 static int create_controls(struct sigmatel_spec *spec, const char *pfx, hda_nid_t nid, int chs)
2819 char name[32];
2820 int err;
2822 sprintf(name, "%s Playback Volume", pfx);
2823 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, name,
2824 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
2825 if (err < 0)
2826 return err;
2827 sprintf(name, "%s Playback Switch", pfx);
2828 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, name,
2829 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
2830 if (err < 0)
2831 return err;
2832 return 0;
2835 static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
2837 if (!spec->multiout.hp_nid)
2838 spec->multiout.hp_nid = nid;
2839 else if (spec->multiout.num_dacs > 4) {
2840 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
2841 return 1;
2842 } else {
2843 spec->multiout.dac_nids[spec->multiout.num_dacs] = nid;
2844 spec->multiout.num_dacs++;
2846 return 0;
2849 static int check_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2851 if (is_in_dac_nids(spec, nid))
2852 return 1;
2853 if (spec->multiout.hp_nid == nid)
2854 return 1;
2855 return 0;
2858 /* add playback controls from the parsed DAC table */
2859 static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
2860 const struct auto_pin_cfg *cfg)
2862 static const char *chname[4] = {
2863 "Front", "Surround", NULL /*CLFE*/, "Side"
2865 hda_nid_t nid = 0;
2866 int i, err;
2868 struct sigmatel_spec *spec = codec->spec;
2869 unsigned int wid_caps, pincap;
2872 for (i = 0; i < cfg->line_outs && i < spec->multiout.num_dacs; i++) {
2873 if (!spec->multiout.dac_nids[i])
2874 continue;
2876 nid = spec->multiout.dac_nids[i];
2878 if (i == 2) {
2879 /* Center/LFE */
2880 err = create_controls(spec, "Center", nid, 1);
2881 if (err < 0)
2882 return err;
2883 err = create_controls(spec, "LFE", nid, 2);
2884 if (err < 0)
2885 return err;
2887 wid_caps = get_wcaps(codec, nid);
2889 if (wid_caps & AC_WCAP_LR_SWAP) {
2890 err = stac92xx_add_control(spec,
2891 STAC_CTL_WIDGET_CLFE_SWITCH,
2892 "Swap Center/LFE Playback Switch", nid);
2894 if (err < 0)
2895 return err;
2898 } else {
2899 err = create_controls(spec, chname[i], nid, 3);
2900 if (err < 0)
2901 return err;
2905 if ((spec->multiout.num_dacs - cfg->line_outs) > 0 &&
2906 cfg->hp_outs && !spec->multiout.hp_nid)
2907 spec->multiout.hp_nid = nid;
2909 if (cfg->hp_outs > 1 && cfg->line_out_type == AUTO_PIN_LINE_OUT) {
2910 err = stac92xx_add_control(spec,
2911 STAC_CTL_WIDGET_HP_SWITCH,
2912 "Headphone as Line Out Switch",
2913 cfg->hp_pins[cfg->hp_outs - 1]);
2914 if (err < 0)
2915 return err;
2918 if (spec->line_switch) {
2919 nid = cfg->input_pins[AUTO_PIN_LINE];
2920 pincap = snd_hda_param_read(codec, nid,
2921 AC_PAR_PIN_CAP);
2922 if (pincap & AC_PINCAP_OUT) {
2923 err = stac92xx_add_control(spec,
2924 STAC_CTL_WIDGET_IO_SWITCH,
2925 "Line In as Output Switch", nid << 8);
2926 if (err < 0)
2927 return err;
2931 if (spec->mic_switch) {
2932 unsigned int def_conf;
2933 unsigned int mic_pin = AUTO_PIN_MIC;
2934 again:
2935 nid = cfg->input_pins[mic_pin];
2936 def_conf = snd_hda_codec_read(codec, nid, 0,
2937 AC_VERB_GET_CONFIG_DEFAULT, 0);
2938 /* some laptops have an internal analog microphone
2939 * which can't be used as a output */
2940 if (get_defcfg_connect(def_conf) != AC_JACK_PORT_FIXED) {
2941 pincap = snd_hda_param_read(codec, nid,
2942 AC_PAR_PIN_CAP);
2943 if (pincap & AC_PINCAP_OUT) {
2944 err = stac92xx_add_control(spec,
2945 STAC_CTL_WIDGET_IO_SWITCH,
2946 "Mic as Output Switch", (nid << 8) | 1);
2947 nid = snd_hda_codec_read(codec, nid, 0,
2948 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
2949 if (!check_in_dac_nids(spec, nid))
2950 add_spec_dacs(spec, nid);
2951 if (err < 0)
2952 return err;
2954 } else if (mic_pin == AUTO_PIN_MIC) {
2955 mic_pin = AUTO_PIN_FRONT_MIC;
2956 goto again;
2960 return 0;
2963 /* add playback controls for Speaker and HP outputs */
2964 static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
2965 struct auto_pin_cfg *cfg)
2967 struct sigmatel_spec *spec = codec->spec;
2968 hda_nid_t nid;
2969 int i, old_num_dacs, err;
2971 old_num_dacs = spec->multiout.num_dacs;
2972 for (i = 0; i < cfg->hp_outs; i++) {
2973 unsigned int wid_caps = get_wcaps(codec, cfg->hp_pins[i]);
2974 if (wid_caps & AC_WCAP_UNSOL_CAP)
2975 spec->hp_detect = 1;
2976 nid = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
2977 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
2978 if (check_in_dac_nids(spec, nid))
2979 nid = 0;
2980 if (! nid)
2981 continue;
2982 add_spec_dacs(spec, nid);
2984 for (i = 0; i < cfg->speaker_outs; i++) {
2985 nid = snd_hda_codec_read(codec, cfg->speaker_pins[i], 0,
2986 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
2987 if (check_in_dac_nids(spec, nid))
2988 nid = 0;
2989 if (! nid)
2990 continue;
2991 add_spec_dacs(spec, nid);
2993 for (i = 0; i < cfg->line_outs; i++) {
2994 nid = snd_hda_codec_read(codec, cfg->line_out_pins[i], 0,
2995 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
2996 if (check_in_dac_nids(spec, nid))
2997 nid = 0;
2998 if (! nid)
2999 continue;
3000 add_spec_dacs(spec, nid);
3002 for (i = old_num_dacs; i < spec->multiout.num_dacs; i++) {
3003 static const char *pfxs[] = {
3004 "Speaker", "External Speaker", "Speaker2",
3006 err = create_controls(spec, pfxs[i - old_num_dacs],
3007 spec->multiout.dac_nids[i], 3);
3008 if (err < 0)
3009 return err;
3011 if (spec->multiout.hp_nid) {
3012 err = create_controls(spec, "Headphone",
3013 spec->multiout.hp_nid, 3);
3014 if (err < 0)
3015 return err;
3018 return 0;
3021 /* labels for mono mux outputs */
3022 static const char *stac92xx_mono_labels[4] = {
3023 "DAC0", "DAC1", "Mixer", "DAC2"
3026 /* create mono mux for mono out on capable codecs */
3027 static int stac92xx_auto_create_mono_output_ctls(struct hda_codec *codec)
3029 struct sigmatel_spec *spec = codec->spec;
3030 struct hda_input_mux *mono_mux = &spec->private_mono_mux;
3031 int i, num_cons;
3032 hda_nid_t con_lst[ARRAY_SIZE(stac92xx_mono_labels)];
3034 num_cons = snd_hda_get_connections(codec,
3035 spec->mono_nid,
3036 con_lst,
3037 HDA_MAX_NUM_INPUTS);
3038 if (!num_cons || num_cons > ARRAY_SIZE(stac92xx_mono_labels))
3039 return -EINVAL;
3041 for (i = 0; i < num_cons; i++) {
3042 mono_mux->items[mono_mux->num_items].label =
3043 stac92xx_mono_labels[i];
3044 mono_mux->items[mono_mux->num_items].index = i;
3045 mono_mux->num_items++;
3048 return stac92xx_add_control(spec, STAC_CTL_WIDGET_MONO_MUX,
3049 "Mono Mux", spec->mono_nid);
3052 /* labels for amp mux outputs */
3053 static const char *stac92xx_amp_labels[3] = {
3054 "Front Microphone", "Microphone", "Line In",
3057 /* create amp out controls mux on capable codecs */
3058 static int stac92xx_auto_create_amp_output_ctls(struct hda_codec *codec)
3060 struct sigmatel_spec *spec = codec->spec;
3061 struct hda_input_mux *amp_mux = &spec->private_amp_mux;
3062 int i, err;
3064 for (i = 0; i < spec->num_amps; i++) {
3065 amp_mux->items[amp_mux->num_items].label =
3066 stac92xx_amp_labels[i];
3067 amp_mux->items[amp_mux->num_items].index = i;
3068 amp_mux->num_items++;
3071 if (spec->num_amps > 1) {
3072 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_AMP_MUX,
3073 "Amp Selector Capture Switch", 0);
3074 if (err < 0)
3075 return err;
3077 return stac92xx_add_control(spec, STAC_CTL_WIDGET_AMP_VOL,
3078 "Amp Capture Volume",
3079 HDA_COMPOSE_AMP_VAL(spec->amp_nids[0], 3, 0, HDA_INPUT));
3083 /* create PC beep volume controls */
3084 static int stac92xx_auto_create_beep_ctls(struct hda_codec *codec,
3085 hda_nid_t nid)
3087 struct sigmatel_spec *spec = codec->spec;
3088 u32 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3089 int err;
3091 /* check for mute support for the the amp */
3092 if ((caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT) {
3093 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE,
3094 "PC Beep Playback Switch",
3095 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3096 if (err < 0)
3097 return err;
3100 /* check to see if there is volume support for the amp */
3101 if ((caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3102 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL,
3103 "PC Beep Playback Volume",
3104 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3105 if (err < 0)
3106 return err;
3108 return 0;
3111 #ifdef CONFIG_SND_HDA_INPUT_BEEP
3112 #define stac92xx_dig_beep_switch_info snd_ctl_boolean_mono_info
3114 static int stac92xx_dig_beep_switch_get(struct snd_kcontrol *kcontrol,
3115 struct snd_ctl_elem_value *ucontrol)
3117 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3118 ucontrol->value.integer.value[0] = codec->beep->enabled;
3119 return 0;
3122 static int stac92xx_dig_beep_switch_put(struct snd_kcontrol *kcontrol,
3123 struct snd_ctl_elem_value *ucontrol)
3125 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3126 int enabled = !!ucontrol->value.integer.value[0];
3127 if (codec->beep->enabled != enabled) {
3128 codec->beep->enabled = enabled;
3129 return 1;
3131 return 0;
3134 static struct snd_kcontrol_new stac92xx_dig_beep_ctrl = {
3135 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3136 .info = stac92xx_dig_beep_switch_info,
3137 .get = stac92xx_dig_beep_switch_get,
3138 .put = stac92xx_dig_beep_switch_put,
3141 static int stac92xx_beep_switch_ctl(struct hda_codec *codec)
3143 return stac92xx_add_control_temp(codec->spec, &stac92xx_dig_beep_ctrl,
3144 0, "PC Beep Playback Switch", 0);
3146 #endif
3148 static int stac92xx_auto_create_mux_input_ctls(struct hda_codec *codec)
3150 struct sigmatel_spec *spec = codec->spec;
3151 int wcaps, nid, i, err = 0;
3153 for (i = 0; i < spec->num_muxes; i++) {
3154 nid = spec->mux_nids[i];
3155 wcaps = get_wcaps(codec, nid);
3157 if (wcaps & AC_WCAP_OUT_AMP) {
3158 err = stac92xx_add_control_idx(spec,
3159 STAC_CTL_WIDGET_VOL, i, "Mux Capture Volume",
3160 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
3161 if (err < 0)
3162 return err;
3165 return 0;
3168 static const char *stac92xx_spdif_labels[3] = {
3169 "Digital Playback", "Analog Mux 1", "Analog Mux 2",
3172 static int stac92xx_auto_create_spdif_mux_ctls(struct hda_codec *codec)
3174 struct sigmatel_spec *spec = codec->spec;
3175 struct hda_input_mux *spdif_mux = &spec->private_smux;
3176 const char **labels = spec->spdif_labels;
3177 int i, num_cons;
3178 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
3180 num_cons = snd_hda_get_connections(codec,
3181 spec->smux_nids[0],
3182 con_lst,
3183 HDA_MAX_NUM_INPUTS);
3184 if (!num_cons)
3185 return -EINVAL;
3187 if (!labels)
3188 labels = stac92xx_spdif_labels;
3190 for (i = 0; i < num_cons; i++) {
3191 spdif_mux->items[spdif_mux->num_items].label = labels[i];
3192 spdif_mux->items[spdif_mux->num_items].index = i;
3193 spdif_mux->num_items++;
3196 return 0;
3199 /* labels for dmic mux inputs */
3200 static const char *stac92xx_dmic_labels[5] = {
3201 "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
3202 "Digital Mic 3", "Digital Mic 4"
3205 /* create playback/capture controls for input pins on dmic capable codecs */
3206 static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
3207 const struct auto_pin_cfg *cfg)
3209 struct sigmatel_spec *spec = codec->spec;
3210 struct hda_input_mux *dimux = &spec->private_dimux;
3211 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
3212 int err, i, j;
3213 char name[32];
3215 dimux->items[dimux->num_items].label = stac92xx_dmic_labels[0];
3216 dimux->items[dimux->num_items].index = 0;
3217 dimux->num_items++;
3219 for (i = 0; i < spec->num_dmics; i++) {
3220 hda_nid_t nid;
3221 int index;
3222 int num_cons;
3223 unsigned int wcaps;
3224 unsigned int def_conf;
3226 def_conf = snd_hda_codec_read(codec,
3227 spec->dmic_nids[i],
3229 AC_VERB_GET_CONFIG_DEFAULT,
3231 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
3232 continue;
3234 nid = spec->dmic_nids[i];
3235 num_cons = snd_hda_get_connections(codec,
3236 spec->dmux_nids[0],
3237 con_lst,
3238 HDA_MAX_NUM_INPUTS);
3239 for (j = 0; j < num_cons; j++)
3240 if (con_lst[j] == nid) {
3241 index = j;
3242 goto found;
3244 continue;
3245 found:
3246 wcaps = get_wcaps(codec, nid) &
3247 (AC_WCAP_OUT_AMP | AC_WCAP_IN_AMP);
3249 if (wcaps) {
3250 sprintf(name, "%s Capture Volume",
3251 stac92xx_dmic_labels[dimux->num_items]);
3253 err = stac92xx_add_control(spec,
3254 STAC_CTL_WIDGET_VOL,
3255 name,
3256 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3257 (wcaps & AC_WCAP_OUT_AMP) ?
3258 HDA_OUTPUT : HDA_INPUT));
3259 if (err < 0)
3260 return err;
3263 dimux->items[dimux->num_items].label =
3264 stac92xx_dmic_labels[dimux->num_items];
3265 dimux->items[dimux->num_items].index = index;
3266 dimux->num_items++;
3269 return 0;
3272 /* create playback/capture controls for input pins */
3273 static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
3275 struct sigmatel_spec *spec = codec->spec;
3276 struct hda_input_mux *imux = &spec->private_imux;
3277 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
3278 int i, j, k;
3280 for (i = 0; i < AUTO_PIN_LAST; i++) {
3281 int index;
3283 if (!cfg->input_pins[i])
3284 continue;
3285 index = -1;
3286 for (j = 0; j < spec->num_muxes; j++) {
3287 int num_cons;
3288 num_cons = snd_hda_get_connections(codec,
3289 spec->mux_nids[j],
3290 con_lst,
3291 HDA_MAX_NUM_INPUTS);
3292 for (k = 0; k < num_cons; k++)
3293 if (con_lst[k] == cfg->input_pins[i]) {
3294 index = k;
3295 goto found;
3298 continue;
3299 found:
3300 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
3301 imux->items[imux->num_items].index = index;
3302 imux->num_items++;
3305 if (imux->num_items) {
3307 * Set the current input for the muxes.
3308 * The STAC9221 has two input muxes with identical source
3309 * NID lists. Hopefully this won't get confused.
3311 for (i = 0; i < spec->num_muxes; i++) {
3312 snd_hda_codec_write_cache(codec, spec->mux_nids[i], 0,
3313 AC_VERB_SET_CONNECT_SEL,
3314 imux->items[0].index);
3318 return 0;
3321 static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
3323 struct sigmatel_spec *spec = codec->spec;
3324 int i;
3326 for (i = 0; i < spec->autocfg.line_outs; i++) {
3327 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3328 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
3332 static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
3334 struct sigmatel_spec *spec = codec->spec;
3335 int i;
3337 for (i = 0; i < spec->autocfg.hp_outs; i++) {
3338 hda_nid_t pin;
3339 pin = spec->autocfg.hp_pins[i];
3340 if (pin) /* connect to front */
3341 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
3343 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
3344 hda_nid_t pin;
3345 pin = spec->autocfg.speaker_pins[i];
3346 if (pin) /* connect to front */
3347 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
3351 static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out, hda_nid_t dig_in)
3353 struct sigmatel_spec *spec = codec->spec;
3354 int err;
3355 int hp_speaker_swap = 0;
3357 if ((err = snd_hda_parse_pin_def_config(codec,
3358 &spec->autocfg,
3359 spec->dmic_nids)) < 0)
3360 return err;
3361 if (! spec->autocfg.line_outs)
3362 return 0; /* can't find valid pin config */
3364 /* If we have no real line-out pin and multiple hp-outs, HPs should
3365 * be set up as multi-channel outputs.
3367 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT &&
3368 spec->autocfg.hp_outs > 1) {
3369 /* Copy hp_outs to line_outs, backup line_outs in
3370 * speaker_outs so that the following routines can handle
3371 * HP pins as primary outputs.
3373 memcpy(spec->autocfg.speaker_pins, spec->autocfg.line_out_pins,
3374 sizeof(spec->autocfg.line_out_pins));
3375 spec->autocfg.speaker_outs = spec->autocfg.line_outs;
3376 memcpy(spec->autocfg.line_out_pins, spec->autocfg.hp_pins,
3377 sizeof(spec->autocfg.hp_pins));
3378 spec->autocfg.line_outs = spec->autocfg.hp_outs;
3379 hp_speaker_swap = 1;
3381 if (spec->autocfg.mono_out_pin) {
3382 int dir = get_wcaps(codec, spec->autocfg.mono_out_pin) &
3383 (AC_WCAP_OUT_AMP | AC_WCAP_IN_AMP);
3384 u32 caps = query_amp_caps(codec,
3385 spec->autocfg.mono_out_pin, dir);
3386 hda_nid_t conn_list[1];
3388 /* get the mixer node and then the mono mux if it exists */
3389 if (snd_hda_get_connections(codec,
3390 spec->autocfg.mono_out_pin, conn_list, 1) &&
3391 snd_hda_get_connections(codec, conn_list[0],
3392 conn_list, 1)) {
3394 int wcaps = get_wcaps(codec, conn_list[0]);
3395 int wid_type = (wcaps & AC_WCAP_TYPE)
3396 >> AC_WCAP_TYPE_SHIFT;
3397 /* LR swap check, some stac925x have a mux that
3398 * changes the DACs output path instead of the
3399 * mono-mux path.
3401 if (wid_type == AC_WID_AUD_SEL &&
3402 !(wcaps & AC_WCAP_LR_SWAP))
3403 spec->mono_nid = conn_list[0];
3405 if (dir) {
3406 hda_nid_t nid = spec->autocfg.mono_out_pin;
3408 /* most mono outs have a least a mute/unmute switch */
3409 dir = (dir & AC_WCAP_OUT_AMP) ? HDA_OUTPUT : HDA_INPUT;
3410 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE,
3411 "Mono Playback Switch",
3412 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
3413 if (err < 0)
3414 return err;
3415 /* check for volume support for the amp */
3416 if ((caps & AC_AMPCAP_NUM_STEPS)
3417 >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3418 err = stac92xx_add_control(spec,
3419 STAC_CTL_WIDGET_VOL,
3420 "Mono Playback Volume",
3421 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
3422 if (err < 0)
3423 return err;
3427 stac92xx_auto_set_pinctl(codec, spec->autocfg.mono_out_pin,
3428 AC_PINCTL_OUT_EN);
3431 if ((err = stac92xx_add_dyn_out_pins(codec, &spec->autocfg)) < 0)
3432 return err;
3433 if (spec->multiout.num_dacs == 0)
3434 if ((err = stac92xx_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
3435 return err;
3437 err = stac92xx_auto_create_multi_out_ctls(codec, &spec->autocfg);
3439 if (err < 0)
3440 return err;
3442 /* setup analog beep controls */
3443 if (spec->anabeep_nid > 0) {
3444 err = stac92xx_auto_create_beep_ctls(codec,
3445 spec->anabeep_nid);
3446 if (err < 0)
3447 return err;
3450 /* setup digital beep controls and input device */
3451 #ifdef CONFIG_SND_HDA_INPUT_BEEP
3452 if (spec->digbeep_nid > 0) {
3453 hda_nid_t nid = spec->digbeep_nid;
3454 unsigned int caps;
3456 err = stac92xx_auto_create_beep_ctls(codec, nid);
3457 if (err < 0)
3458 return err;
3459 err = snd_hda_attach_beep_device(codec, nid);
3460 if (err < 0)
3461 return err;
3462 /* if no beep switch is available, make its own one */
3463 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3464 if (codec->beep &&
3465 !((caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT)) {
3466 err = stac92xx_beep_switch_ctl(codec);
3467 if (err < 0)
3468 return err;
3471 #endif
3473 if (hp_speaker_swap == 1) {
3474 /* Restore the hp_outs and line_outs */
3475 memcpy(spec->autocfg.hp_pins, spec->autocfg.line_out_pins,
3476 sizeof(spec->autocfg.line_out_pins));
3477 spec->autocfg.hp_outs = spec->autocfg.line_outs;
3478 memcpy(spec->autocfg.line_out_pins, spec->autocfg.speaker_pins,
3479 sizeof(spec->autocfg.speaker_pins));
3480 spec->autocfg.line_outs = spec->autocfg.speaker_outs;
3481 memset(spec->autocfg.speaker_pins, 0,
3482 sizeof(spec->autocfg.speaker_pins));
3483 spec->autocfg.speaker_outs = 0;
3486 err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg);
3488 if (err < 0)
3489 return err;
3491 err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg);
3493 if (err < 0)
3494 return err;
3496 if (spec->mono_nid > 0) {
3497 err = stac92xx_auto_create_mono_output_ctls(codec);
3498 if (err < 0)
3499 return err;
3501 if (spec->num_amps > 0) {
3502 err = stac92xx_auto_create_amp_output_ctls(codec);
3503 if (err < 0)
3504 return err;
3506 if (spec->num_dmics > 0 && !spec->dinput_mux)
3507 if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
3508 &spec->autocfg)) < 0)
3509 return err;
3510 if (spec->num_muxes > 0) {
3511 err = stac92xx_auto_create_mux_input_ctls(codec);
3512 if (err < 0)
3513 return err;
3515 if (spec->num_smuxes > 0) {
3516 err = stac92xx_auto_create_spdif_mux_ctls(codec);
3517 if (err < 0)
3518 return err;
3521 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3522 if (spec->multiout.max_channels > 2)
3523 spec->surr_switch = 1;
3525 if (spec->autocfg.dig_out_pin)
3526 spec->multiout.dig_out_nid = dig_out;
3527 if (dig_in && spec->autocfg.dig_in_pin)
3528 spec->dig_in_nid = dig_in;
3530 if (spec->kctl_alloc)
3531 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
3533 spec->input_mux = &spec->private_imux;
3534 spec->dinput_mux = &spec->private_dimux;
3535 spec->sinput_mux = &spec->private_smux;
3536 spec->mono_mux = &spec->private_mono_mux;
3537 spec->amp_mux = &spec->private_amp_mux;
3538 return 1;
3541 /* add playback controls for HP output */
3542 static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
3543 struct auto_pin_cfg *cfg)
3545 struct sigmatel_spec *spec = codec->spec;
3546 hda_nid_t pin = cfg->hp_pins[0];
3547 unsigned int wid_caps;
3549 if (! pin)
3550 return 0;
3552 wid_caps = get_wcaps(codec, pin);
3553 if (wid_caps & AC_WCAP_UNSOL_CAP)
3554 spec->hp_detect = 1;
3556 return 0;
3559 /* add playback controls for LFE output */
3560 static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
3561 struct auto_pin_cfg *cfg)
3563 struct sigmatel_spec *spec = codec->spec;
3564 int err;
3565 hda_nid_t lfe_pin = 0x0;
3566 int i;
3569 * search speaker outs and line outs for a mono speaker pin
3570 * with an amp. If one is found, add LFE controls
3571 * for it.
3573 for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
3574 hda_nid_t pin = spec->autocfg.speaker_pins[i];
3575 unsigned int wcaps = get_wcaps(codec, pin);
3576 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
3577 if (wcaps == AC_WCAP_OUT_AMP)
3578 /* found a mono speaker with an amp, must be lfe */
3579 lfe_pin = pin;
3582 /* if speaker_outs is 0, then speakers may be in line_outs */
3583 if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
3584 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
3585 hda_nid_t pin = spec->autocfg.line_out_pins[i];
3586 unsigned int defcfg;
3587 defcfg = snd_hda_codec_read(codec, pin, 0,
3588 AC_VERB_GET_CONFIG_DEFAULT,
3589 0x00);
3590 if (get_defcfg_device(defcfg) == AC_JACK_SPEAKER) {
3591 unsigned int wcaps = get_wcaps(codec, pin);
3592 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
3593 if (wcaps == AC_WCAP_OUT_AMP)
3594 /* found a mono speaker with an amp,
3595 must be lfe */
3596 lfe_pin = pin;
3601 if (lfe_pin) {
3602 err = create_controls(spec, "LFE", lfe_pin, 1);
3603 if (err < 0)
3604 return err;
3607 return 0;
3610 static int stac9200_parse_auto_config(struct hda_codec *codec)
3612 struct sigmatel_spec *spec = codec->spec;
3613 int err;
3615 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
3616 return err;
3618 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
3619 return err;
3621 if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
3622 return err;
3624 if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
3625 return err;
3627 if (spec->num_muxes > 0) {
3628 err = stac92xx_auto_create_mux_input_ctls(codec);
3629 if (err < 0)
3630 return err;
3633 if (spec->autocfg.dig_out_pin)
3634 spec->multiout.dig_out_nid = 0x05;
3635 if (spec->autocfg.dig_in_pin)
3636 spec->dig_in_nid = 0x04;
3638 if (spec->kctl_alloc)
3639 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
3641 spec->input_mux = &spec->private_imux;
3642 spec->dinput_mux = &spec->private_dimux;
3644 return 1;
3648 * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
3649 * funky external mute control using GPIO pins.
3652 static void stac_gpio_set(struct hda_codec *codec, unsigned int mask,
3653 unsigned int dir_mask, unsigned int data)
3655 unsigned int gpiostate, gpiomask, gpiodir;
3657 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
3658 AC_VERB_GET_GPIO_DATA, 0);
3659 gpiostate = (gpiostate & ~dir_mask) | (data & dir_mask);
3661 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
3662 AC_VERB_GET_GPIO_MASK, 0);
3663 gpiomask |= mask;
3665 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
3666 AC_VERB_GET_GPIO_DIRECTION, 0);
3667 gpiodir |= dir_mask;
3669 /* Configure GPIOx as CMOS */
3670 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
3672 snd_hda_codec_write(codec, codec->afg, 0,
3673 AC_VERB_SET_GPIO_MASK, gpiomask);
3674 snd_hda_codec_read(codec, codec->afg, 0,
3675 AC_VERB_SET_GPIO_DIRECTION, gpiodir); /* sync */
3677 msleep(1);
3679 snd_hda_codec_read(codec, codec->afg, 0,
3680 AC_VERB_SET_GPIO_DATA, gpiostate); /* sync */
3683 static void enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
3684 unsigned int event)
3686 if (get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP)
3687 snd_hda_codec_write_cache(codec, nid, 0,
3688 AC_VERB_SET_UNSOLICITED_ENABLE,
3689 (AC_USRSP_EN | event));
3692 static int is_nid_hp_pin(struct auto_pin_cfg *cfg, hda_nid_t nid)
3694 int i;
3695 for (i = 0; i < cfg->hp_outs; i++)
3696 if (cfg->hp_pins[i] == nid)
3697 return 1; /* nid is a HP-Out */
3699 return 0; /* nid is not a HP-Out */
3702 static void stac92xx_power_down(struct hda_codec *codec)
3704 struct sigmatel_spec *spec = codec->spec;
3706 /* power down inactive DACs */
3707 hda_nid_t *dac;
3708 for (dac = spec->dac_list; *dac; dac++)
3709 if (!is_in_dac_nids(spec, *dac) &&
3710 spec->multiout.hp_nid != *dac)
3711 snd_hda_codec_write_cache(codec, *dac, 0,
3712 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3715 static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
3716 int enable);
3718 static int stac92xx_init(struct hda_codec *codec)
3720 struct sigmatel_spec *spec = codec->spec;
3721 struct auto_pin_cfg *cfg = &spec->autocfg;
3722 unsigned int gpio;
3723 int i;
3725 snd_hda_sequence_write(codec, spec->init);
3727 /* power down adcs initially */
3728 if (spec->powerdown_adcs)
3729 for (i = 0; i < spec->num_adcs; i++)
3730 snd_hda_codec_write_cache(codec,
3731 spec->adc_nids[i], 0,
3732 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3734 /* set up GPIO */
3735 gpio = spec->gpio_data;
3736 /* turn on EAPD statically when spec->eapd_switch isn't set.
3737 * otherwise, unsol event will turn it on/off dynamically
3739 if (!spec->eapd_switch)
3740 gpio |= spec->eapd_mask;
3741 stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, gpio);
3743 /* set up pins */
3744 if (spec->hp_detect) {
3745 /* Enable unsolicited responses on the HP widget */
3746 for (i = 0; i < cfg->hp_outs; i++)
3747 enable_pin_detect(codec, cfg->hp_pins[i],
3748 STAC_HP_EVENT);
3749 /* force to enable the first line-out; the others are set up
3750 * in unsol_event
3752 stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
3753 AC_PINCTL_OUT_EN);
3754 stac92xx_auto_init_hp_out(codec);
3755 /* fake event to set up pins */
3756 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
3757 } else {
3758 stac92xx_auto_init_multi_out(codec);
3759 stac92xx_auto_init_hp_out(codec);
3761 for (i = 0; i < AUTO_PIN_LAST; i++) {
3762 hda_nid_t nid = cfg->input_pins[i];
3763 if (nid) {
3764 unsigned int pinctl;
3765 if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC) {
3766 /* for mic pins, force to initialize */
3767 pinctl = stac92xx_get_vref(codec, nid);
3768 } else {
3769 pinctl = snd_hda_codec_read(codec, nid, 0,
3770 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3771 /* if PINCTL already set then skip */
3772 if (pinctl & AC_PINCTL_IN_EN)
3773 continue;
3775 pinctl |= AC_PINCTL_IN_EN;
3776 stac92xx_auto_set_pinctl(codec, nid, pinctl);
3779 for (i = 0; i < spec->num_dmics; i++)
3780 stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
3781 AC_PINCTL_IN_EN);
3782 if (cfg->dig_out_pin)
3783 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pin,
3784 AC_PINCTL_OUT_EN);
3785 if (cfg->dig_in_pin)
3786 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
3787 AC_PINCTL_IN_EN);
3788 for (i = 0; i < spec->num_pwrs; i++) {
3789 hda_nid_t nid = spec->pwr_nids[i];
3790 int pinctl, def_conf;
3791 int event = STAC_PWR_EVENT;
3793 if (is_nid_hp_pin(cfg, nid) && spec->hp_detect)
3794 continue; /* already has an unsol event */
3796 pinctl = snd_hda_codec_read(codec, nid, 0,
3797 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3798 /* outputs are only ports capable of power management
3799 * any attempts on powering down a input port cause the
3800 * referenced VREF to act quirky.
3802 if (pinctl & AC_PINCTL_IN_EN)
3803 continue;
3804 def_conf = snd_hda_codec_read(codec, nid, 0,
3805 AC_VERB_GET_CONFIG_DEFAULT, 0);
3806 def_conf = get_defcfg_connect(def_conf);
3807 /* skip any ports that don't have jacks since presence
3808 * detection is useless */
3809 if (def_conf != AC_JACK_PORT_COMPLEX) {
3810 if (def_conf != AC_JACK_PORT_NONE)
3811 stac_toggle_power_map(codec, nid, 1);
3812 continue;
3814 enable_pin_detect(codec, spec->pwr_nids[i], event | i);
3815 codec->patch_ops.unsol_event(codec, (event | i) << 26);
3817 if (spec->dac_list)
3818 stac92xx_power_down(codec);
3819 return 0;
3822 static void stac92xx_free(struct hda_codec *codec)
3824 struct sigmatel_spec *spec = codec->spec;
3825 int i;
3827 if (! spec)
3828 return;
3830 if (spec->kctl_alloc) {
3831 for (i = 0; i < spec->num_kctl_used; i++)
3832 kfree(spec->kctl_alloc[i].name);
3833 kfree(spec->kctl_alloc);
3836 if (spec->bios_pin_configs)
3837 kfree(spec->bios_pin_configs);
3839 kfree(spec);
3840 snd_hda_detach_beep_device(codec);
3843 static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
3844 unsigned int flag)
3846 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
3847 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
3849 if (pin_ctl & AC_PINCTL_IN_EN) {
3851 * we need to check the current set-up direction of
3852 * shared input pins since they can be switched via
3853 * "xxx as Output" mixer switch
3855 struct sigmatel_spec *spec = codec->spec;
3856 struct auto_pin_cfg *cfg = &spec->autocfg;
3857 if ((nid == cfg->input_pins[AUTO_PIN_LINE] &&
3858 spec->line_switch) ||
3859 (nid == cfg->input_pins[AUTO_PIN_MIC] &&
3860 spec->mic_switch))
3861 return;
3864 /* if setting pin direction bits, clear the current
3865 direction bits first */
3866 if (flag & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))
3867 pin_ctl &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
3869 snd_hda_codec_write_cache(codec, nid, 0,
3870 AC_VERB_SET_PIN_WIDGET_CONTROL,
3871 pin_ctl | flag);
3874 static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
3875 unsigned int flag)
3877 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
3878 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
3879 snd_hda_codec_write_cache(codec, nid, 0,
3880 AC_VERB_SET_PIN_WIDGET_CONTROL,
3881 pin_ctl & ~flag);
3884 static int get_hp_pin_presence(struct hda_codec *codec, hda_nid_t nid)
3886 if (!nid)
3887 return 0;
3888 if (snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PIN_SENSE, 0x00)
3889 & (1 << 31)) {
3890 unsigned int pinctl;
3891 pinctl = snd_hda_codec_read(codec, nid, 0,
3892 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3893 if (pinctl & AC_PINCTL_IN_EN)
3894 return 0; /* mic- or line-input */
3895 else
3896 return 1; /* HP-output */
3898 return 0;
3901 /* return non-zero if the hp-pin of the given array index isn't
3902 * a jack-detection target
3904 static int no_hp_sensing(struct sigmatel_spec *spec, int i)
3906 struct auto_pin_cfg *cfg = &spec->autocfg;
3908 /* ignore sensing of shared line and mic jacks */
3909 if (spec->line_switch &&
3910 cfg->hp_pins[i] == cfg->input_pins[AUTO_PIN_LINE])
3911 return 1;
3912 if (spec->mic_switch &&
3913 cfg->hp_pins[i] == cfg->input_pins[AUTO_PIN_MIC])
3914 return 1;
3915 /* ignore if the pin is set as line-out */
3916 if (cfg->hp_pins[i] == spec->hp_switch)
3917 return 1;
3918 return 0;
3921 static void stac92xx_hp_detect(struct hda_codec *codec, unsigned int res)
3923 struct sigmatel_spec *spec = codec->spec;
3924 struct auto_pin_cfg *cfg = &spec->autocfg;
3925 int i, presence;
3927 presence = 0;
3928 if (spec->gpio_mute)
3929 presence = !(snd_hda_codec_read(codec, codec->afg, 0,
3930 AC_VERB_GET_GPIO_DATA, 0) & spec->gpio_mute);
3932 for (i = 0; i < cfg->hp_outs; i++) {
3933 if (presence)
3934 break;
3935 if (no_hp_sensing(spec, i))
3936 continue;
3937 presence = get_hp_pin_presence(codec, cfg->hp_pins[i]);
3940 if (presence) {
3941 /* disable lineouts */
3942 if (spec->hp_switch)
3943 stac92xx_reset_pinctl(codec, spec->hp_switch,
3944 AC_PINCTL_OUT_EN);
3945 for (i = 0; i < cfg->line_outs; i++)
3946 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
3947 AC_PINCTL_OUT_EN);
3948 for (i = 0; i < cfg->speaker_outs; i++)
3949 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
3950 AC_PINCTL_OUT_EN);
3951 if (spec->eapd_mask && spec->eapd_switch)
3952 stac_gpio_set(codec, spec->gpio_mask,
3953 spec->gpio_dir, spec->gpio_data &
3954 ~spec->eapd_mask);
3955 } else {
3956 /* enable lineouts */
3957 if (spec->hp_switch)
3958 stac92xx_set_pinctl(codec, spec->hp_switch,
3959 AC_PINCTL_OUT_EN);
3960 for (i = 0; i < cfg->line_outs; i++)
3961 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
3962 AC_PINCTL_OUT_EN);
3963 for (i = 0; i < cfg->speaker_outs; i++)
3964 stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
3965 AC_PINCTL_OUT_EN);
3966 if (spec->eapd_mask && spec->eapd_switch)
3967 stac_gpio_set(codec, spec->gpio_mask,
3968 spec->gpio_dir, spec->gpio_data |
3969 spec->eapd_mask);
3971 /* toggle hp outs */
3972 for (i = 0; i < cfg->hp_outs; i++) {
3973 unsigned int val = AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN;
3974 if (no_hp_sensing(spec, i))
3975 continue;
3976 if (presence)
3977 stac92xx_set_pinctl(codec, cfg->hp_pins[i], val);
3978 else
3979 stac92xx_reset_pinctl(codec, cfg->hp_pins[i], val);
3983 static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
3984 int enable)
3986 struct sigmatel_spec *spec = codec->spec;
3987 unsigned int idx, val;
3989 for (idx = 0; idx < spec->num_pwrs; idx++) {
3990 if (spec->pwr_nids[idx] == nid)
3991 break;
3993 if (idx >= spec->num_pwrs)
3994 return;
3996 /* several codecs have two power down bits */
3997 if (spec->pwr_mapping)
3998 idx = spec->pwr_mapping[idx];
3999 else
4000 idx = 1 << idx;
4002 val = snd_hda_codec_read(codec, codec->afg, 0, 0x0fec, 0x0) & 0xff;
4003 if (enable)
4004 val &= ~idx;
4005 else
4006 val |= idx;
4008 /* power down unused output ports */
4009 snd_hda_codec_write(codec, codec->afg, 0, 0x7ec, val);
4012 static void stac92xx_pin_sense(struct hda_codec *codec, hda_nid_t nid)
4014 stac_toggle_power_map(codec, nid, get_hp_pin_presence(codec, nid));
4017 static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
4019 struct sigmatel_spec *spec = codec->spec;
4020 int idx = res >> 26 & 0x0f;
4022 switch ((res >> 26) & 0x70) {
4023 case STAC_HP_EVENT:
4024 stac92xx_hp_detect(codec, res);
4025 /* fallthru */
4026 case STAC_PWR_EVENT:
4027 if (spec->num_pwrs > 0)
4028 stac92xx_pin_sense(codec, idx);
4029 break;
4030 case STAC_VREF_EVENT: {
4031 int data = snd_hda_codec_read(codec, codec->afg, 0,
4032 AC_VERB_GET_GPIO_DATA, 0);
4033 /* toggle VREF state based on GPIOx status */
4034 snd_hda_codec_write(codec, codec->afg, 0, 0x7e0,
4035 !!(data & (1 << idx)));
4036 break;
4041 #ifdef SND_HDA_NEEDS_RESUME
4042 static int stac92xx_resume(struct hda_codec *codec)
4044 struct sigmatel_spec *spec = codec->spec;
4046 stac92xx_set_config_regs(codec);
4047 snd_hda_sequence_write(codec, spec->init);
4048 stac_gpio_set(codec, spec->gpio_mask,
4049 spec->gpio_dir, spec->gpio_data);
4050 snd_hda_codec_resume_amp(codec);
4051 snd_hda_codec_resume_cache(codec);
4052 /* power down inactive DACs */
4053 if (spec->dac_list)
4054 stac92xx_power_down(codec);
4055 /* invoke unsolicited event to reset the HP state */
4056 if (spec->hp_detect)
4057 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
4058 return 0;
4060 #endif
4062 static struct hda_codec_ops stac92xx_patch_ops = {
4063 .build_controls = stac92xx_build_controls,
4064 .build_pcms = stac92xx_build_pcms,
4065 .init = stac92xx_init,
4066 .free = stac92xx_free,
4067 .unsol_event = stac92xx_unsol_event,
4068 #ifdef SND_HDA_NEEDS_RESUME
4069 .resume = stac92xx_resume,
4070 #endif
4073 static int patch_stac9200(struct hda_codec *codec)
4075 struct sigmatel_spec *spec;
4076 int err;
4078 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4079 if (spec == NULL)
4080 return -ENOMEM;
4082 codec->spec = spec;
4083 spec->num_pins = ARRAY_SIZE(stac9200_pin_nids);
4084 spec->pin_nids = stac9200_pin_nids;
4085 spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS,
4086 stac9200_models,
4087 stac9200_cfg_tbl);
4088 if (spec->board_config < 0) {
4089 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9200, using BIOS defaults\n");
4090 err = stac92xx_save_bios_config_regs(codec);
4091 if (err < 0) {
4092 stac92xx_free(codec);
4093 return err;
4095 spec->pin_configs = spec->bios_pin_configs;
4096 } else {
4097 spec->pin_configs = stac9200_brd_tbl[spec->board_config];
4098 stac92xx_set_config_regs(codec);
4101 spec->multiout.max_channels = 2;
4102 spec->multiout.num_dacs = 1;
4103 spec->multiout.dac_nids = stac9200_dac_nids;
4104 spec->adc_nids = stac9200_adc_nids;
4105 spec->mux_nids = stac9200_mux_nids;
4106 spec->num_muxes = 1;
4107 spec->num_dmics = 0;
4108 spec->num_adcs = 1;
4109 spec->num_pwrs = 0;
4111 if (spec->board_config == STAC_9200_GATEWAY ||
4112 spec->board_config == STAC_9200_OQO)
4113 spec->init = stac9200_eapd_init;
4114 else
4115 spec->init = stac9200_core_init;
4116 spec->mixer = stac9200_mixer;
4118 if (spec->board_config == STAC_9200_PANASONIC) {
4119 spec->gpio_mask = spec->gpio_dir = 0x09;
4120 spec->gpio_data = 0x00;
4123 err = stac9200_parse_auto_config(codec);
4124 if (err < 0) {
4125 stac92xx_free(codec);
4126 return err;
4129 codec->patch_ops = stac92xx_patch_ops;
4131 return 0;
4134 static int patch_stac925x(struct hda_codec *codec)
4136 struct sigmatel_spec *spec;
4137 int err;
4139 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4140 if (spec == NULL)
4141 return -ENOMEM;
4143 codec->spec = spec;
4144 spec->num_pins = ARRAY_SIZE(stac925x_pin_nids);
4145 spec->pin_nids = stac925x_pin_nids;
4146 spec->board_config = snd_hda_check_board_config(codec, STAC_925x_MODELS,
4147 stac925x_models,
4148 stac925x_cfg_tbl);
4149 again:
4150 if (spec->board_config < 0) {
4151 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC925x,"
4152 "using BIOS defaults\n");
4153 err = stac92xx_save_bios_config_regs(codec);
4154 if (err < 0) {
4155 stac92xx_free(codec);
4156 return err;
4158 spec->pin_configs = spec->bios_pin_configs;
4159 } else if (stac925x_brd_tbl[spec->board_config] != NULL){
4160 spec->pin_configs = stac925x_brd_tbl[spec->board_config];
4161 stac92xx_set_config_regs(codec);
4164 spec->multiout.max_channels = 2;
4165 spec->multiout.num_dacs = 1;
4166 spec->multiout.dac_nids = stac925x_dac_nids;
4167 spec->adc_nids = stac925x_adc_nids;
4168 spec->mux_nids = stac925x_mux_nids;
4169 spec->num_muxes = 1;
4170 spec->num_adcs = 1;
4171 spec->num_pwrs = 0;
4172 switch (codec->vendor_id) {
4173 case 0x83847632: /* STAC9202 */
4174 case 0x83847633: /* STAC9202D */
4175 case 0x83847636: /* STAC9251 */
4176 case 0x83847637: /* STAC9251D */
4177 spec->num_dmics = STAC925X_NUM_DMICS;
4178 spec->dmic_nids = stac925x_dmic_nids;
4179 spec->num_dmuxes = ARRAY_SIZE(stac925x_dmux_nids);
4180 spec->dmux_nids = stac925x_dmux_nids;
4181 break;
4182 default:
4183 spec->num_dmics = 0;
4184 break;
4187 spec->init = stac925x_core_init;
4188 spec->mixer = stac925x_mixer;
4190 err = stac92xx_parse_auto_config(codec, 0x8, 0x7);
4191 if (!err) {
4192 if (spec->board_config < 0) {
4193 printk(KERN_WARNING "hda_codec: No auto-config is "
4194 "available, default to model=ref\n");
4195 spec->board_config = STAC_925x_REF;
4196 goto again;
4198 err = -EINVAL;
4200 if (err < 0) {
4201 stac92xx_free(codec);
4202 return err;
4205 codec->patch_ops = stac92xx_patch_ops;
4207 return 0;
4210 static struct hda_input_mux stac92hd73xx_dmux = {
4211 .num_items = 4,
4212 .items = {
4213 { "Analog Inputs", 0x0b },
4214 { "Digital Mic 1", 0x09 },
4215 { "Digital Mic 2", 0x0a },
4216 { "CD", 0x08 },
4220 static int patch_stac92hd73xx(struct hda_codec *codec)
4222 struct sigmatel_spec *spec;
4223 hda_nid_t conn[STAC92HD73_DAC_COUNT + 2];
4224 int err = 0;
4226 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4227 if (spec == NULL)
4228 return -ENOMEM;
4230 codec->spec = spec;
4231 codec->slave_dig_outs = stac92hd73xx_slave_dig_outs;
4232 spec->num_pins = ARRAY_SIZE(stac92hd73xx_pin_nids);
4233 spec->pin_nids = stac92hd73xx_pin_nids;
4234 spec->board_config = snd_hda_check_board_config(codec,
4235 STAC_92HD73XX_MODELS,
4236 stac92hd73xx_models,
4237 stac92hd73xx_cfg_tbl);
4238 again:
4239 if (spec->board_config < 0) {
4240 snd_printdd(KERN_INFO "hda_codec: Unknown model for"
4241 " STAC92HD73XX, using BIOS defaults\n");
4242 err = stac92xx_save_bios_config_regs(codec);
4243 if (err < 0) {
4244 stac92xx_free(codec);
4245 return err;
4247 spec->pin_configs = spec->bios_pin_configs;
4248 } else {
4249 spec->pin_configs = stac92hd73xx_brd_tbl[spec->board_config];
4250 stac92xx_set_config_regs(codec);
4253 spec->multiout.num_dacs = snd_hda_get_connections(codec, 0x0a,
4254 conn, STAC92HD73_DAC_COUNT + 2) - 1;
4256 if (spec->multiout.num_dacs < 0) {
4257 printk(KERN_WARNING "hda_codec: Could not determine "
4258 "number of channels defaulting to DAC count\n");
4259 spec->multiout.num_dacs = STAC92HD73_DAC_COUNT;
4262 switch (spec->multiout.num_dacs) {
4263 case 0x3: /* 6 Channel */
4264 spec->multiout.hp_nid = 0x17;
4265 spec->mixer = stac92hd73xx_6ch_mixer;
4266 spec->init = stac92hd73xx_6ch_core_init;
4267 break;
4268 case 0x4: /* 8 Channel */
4269 spec->multiout.hp_nid = 0x18;
4270 spec->mixer = stac92hd73xx_8ch_mixer;
4271 spec->init = stac92hd73xx_8ch_core_init;
4272 break;
4273 case 0x5: /* 10 Channel */
4274 spec->multiout.hp_nid = 0x19;
4275 spec->mixer = stac92hd73xx_10ch_mixer;
4276 spec->init = stac92hd73xx_10ch_core_init;
4279 spec->multiout.dac_nids = stac92hd73xx_dac_nids;
4280 spec->aloopback_mask = 0x01;
4281 spec->aloopback_shift = 8;
4283 spec->digbeep_nid = 0x1c;
4284 spec->mux_nids = stac92hd73xx_mux_nids;
4285 spec->adc_nids = stac92hd73xx_adc_nids;
4286 spec->dmic_nids = stac92hd73xx_dmic_nids;
4287 spec->dmux_nids = stac92hd73xx_dmux_nids;
4288 spec->smux_nids = stac92hd73xx_smux_nids;
4289 spec->amp_nids = stac92hd73xx_amp_nids;
4290 spec->num_amps = ARRAY_SIZE(stac92hd73xx_amp_nids);
4292 spec->num_muxes = ARRAY_SIZE(stac92hd73xx_mux_nids);
4293 spec->num_adcs = ARRAY_SIZE(stac92hd73xx_adc_nids);
4294 spec->num_dmuxes = ARRAY_SIZE(stac92hd73xx_dmux_nids);
4295 memcpy(&spec->private_dimux, &stac92hd73xx_dmux,
4296 sizeof(stac92hd73xx_dmux));
4298 switch (spec->board_config) {
4299 case STAC_DELL_EQ:
4300 spec->init = dell_eq_core_init;
4301 /* fallthru */
4302 case STAC_DELL_M6_AMIC:
4303 case STAC_DELL_M6_DMIC:
4304 case STAC_DELL_M6_BOTH:
4305 spec->num_smuxes = 0;
4306 spec->mixer = &stac92hd73xx_6ch_mixer[DELL_M6_MIXER];
4307 spec->amp_nids = &stac92hd73xx_amp_nids[DELL_M6_AMP];
4308 spec->eapd_switch = 0;
4309 spec->num_amps = 1;
4311 if (!spec->init)
4312 spec->init = dell_m6_core_init;
4313 switch (spec->board_config) {
4314 case STAC_DELL_M6_AMIC: /* Analog Mics */
4315 stac92xx_set_config_reg(codec, 0x0b, 0x90A70170);
4316 spec->num_dmics = 0;
4317 spec->private_dimux.num_items = 1;
4318 break;
4319 case STAC_DELL_M6_DMIC: /* Digital Mics */
4320 stac92xx_set_config_reg(codec, 0x13, 0x90A60160);
4321 spec->num_dmics = 1;
4322 spec->private_dimux.num_items = 2;
4323 break;
4324 case STAC_DELL_M6_BOTH: /* Both */
4325 stac92xx_set_config_reg(codec, 0x0b, 0x90A70170);
4326 stac92xx_set_config_reg(codec, 0x13, 0x90A60160);
4327 spec->num_dmics = 1;
4328 spec->private_dimux.num_items = 2;
4329 break;
4331 break;
4332 default:
4333 spec->num_dmics = STAC92HD73XX_NUM_DMICS;
4334 spec->num_smuxes = ARRAY_SIZE(stac92hd73xx_smux_nids);
4335 spec->eapd_switch = 1;
4337 if (spec->board_config > STAC_92HD73XX_REF) {
4338 /* GPIO0 High = Enable EAPD */
4339 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
4340 spec->gpio_data = 0x01;
4342 spec->dinput_mux = &spec->private_dimux;
4344 spec->num_pwrs = ARRAY_SIZE(stac92hd73xx_pwr_nids);
4345 spec->pwr_nids = stac92hd73xx_pwr_nids;
4347 err = stac92xx_parse_auto_config(codec, 0x25, 0x27);
4349 if (!err) {
4350 if (spec->board_config < 0) {
4351 printk(KERN_WARNING "hda_codec: No auto-config is "
4352 "available, default to model=ref\n");
4353 spec->board_config = STAC_92HD73XX_REF;
4354 goto again;
4356 err = -EINVAL;
4359 if (err < 0) {
4360 stac92xx_free(codec);
4361 return err;
4364 if (spec->board_config == STAC_92HD73XX_NO_JD)
4365 spec->hp_detect = 0;
4367 codec->patch_ops = stac92xx_patch_ops;
4369 return 0;
4372 static struct hda_input_mux stac92hd83xxx_dmux = {
4373 .num_items = 3,
4374 .items = {
4375 { "Analog Inputs", 0x03 },
4376 { "Digital Mic 1", 0x04 },
4377 { "Digital Mic 2", 0x05 },
4381 static int patch_stac92hd83xxx(struct hda_codec *codec)
4383 struct sigmatel_spec *spec;
4384 int err;
4386 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4387 if (spec == NULL)
4388 return -ENOMEM;
4390 codec->spec = spec;
4391 codec->slave_dig_outs = stac92hd83xxx_slave_dig_outs;
4392 spec->mono_nid = 0x19;
4393 spec->digbeep_nid = 0x21;
4394 spec->dmic_nids = stac92hd83xxx_dmic_nids;
4395 spec->dmux_nids = stac92hd83xxx_dmux_nids;
4396 spec->adc_nids = stac92hd83xxx_adc_nids;
4397 spec->pwr_nids = stac92hd83xxx_pwr_nids;
4398 spec->pwr_mapping = stac92hd83xxx_pwr_mapping;
4399 spec->num_pwrs = ARRAY_SIZE(stac92hd83xxx_pwr_nids);
4400 spec->multiout.dac_nids = stac92hd83xxx_dac_nids;
4402 spec->init = stac92hd83xxx_core_init;
4403 switch (codec->vendor_id) {
4404 case 0x111d7605:
4405 spec->multiout.num_dacs = STAC92HD81_DAC_COUNT;
4406 break;
4407 default:
4408 spec->num_pwrs--;
4409 spec->init++; /* switch to config #2 */
4410 spec->multiout.num_dacs = STAC92HD83_DAC_COUNT;
4413 spec->mixer = stac92hd83xxx_mixer;
4414 spec->num_pins = ARRAY_SIZE(stac92hd83xxx_pin_nids);
4415 spec->num_dmuxes = ARRAY_SIZE(stac92hd83xxx_dmux_nids);
4416 spec->num_adcs = ARRAY_SIZE(stac92hd83xxx_adc_nids);
4417 spec->num_dmics = STAC92HD83XXX_NUM_DMICS;
4418 spec->dinput_mux = &stac92hd83xxx_dmux;
4419 spec->pin_nids = stac92hd83xxx_pin_nids;
4420 spec->board_config = snd_hda_check_board_config(codec,
4421 STAC_92HD83XXX_MODELS,
4422 stac92hd83xxx_models,
4423 stac92hd83xxx_cfg_tbl);
4424 again:
4425 if (spec->board_config < 0) {
4426 snd_printdd(KERN_INFO "hda_codec: Unknown model for"
4427 " STAC92HD83XXX, using BIOS defaults\n");
4428 err = stac92xx_save_bios_config_regs(codec);
4429 if (err < 0) {
4430 stac92xx_free(codec);
4431 return err;
4433 spec->pin_configs = spec->bios_pin_configs;
4434 } else {
4435 spec->pin_configs = stac92hd83xxx_brd_tbl[spec->board_config];
4436 stac92xx_set_config_regs(codec);
4439 err = stac92xx_parse_auto_config(codec, 0x1d, 0);
4440 if (!err) {
4441 if (spec->board_config < 0) {
4442 printk(KERN_WARNING "hda_codec: No auto-config is "
4443 "available, default to model=ref\n");
4444 spec->board_config = STAC_92HD83XXX_REF;
4445 goto again;
4447 err = -EINVAL;
4450 if (err < 0) {
4451 stac92xx_free(codec);
4452 return err;
4455 codec->patch_ops = stac92xx_patch_ops;
4457 return 0;
4460 #ifdef SND_HDA_NEEDS_RESUME
4461 static void stac92hd71xx_set_power_state(struct hda_codec *codec, int pwr)
4463 struct sigmatel_spec *spec = codec->spec;
4464 int i;
4465 snd_hda_codec_write_cache(codec, codec->afg, 0,
4466 AC_VERB_SET_POWER_STATE, pwr);
4468 msleep(1);
4469 for (i = 0; i < spec->num_adcs; i++) {
4470 snd_hda_codec_write_cache(codec,
4471 spec->adc_nids[i], 0,
4472 AC_VERB_SET_POWER_STATE, pwr);
4476 static int stac92hd71xx_resume(struct hda_codec *codec)
4478 stac92hd71xx_set_power_state(codec, AC_PWRST_D0);
4479 return stac92xx_resume(codec);
4482 static int stac92hd71xx_suspend(struct hda_codec *codec, pm_message_t state)
4484 struct sigmatel_spec *spec = codec->spec;
4486 stac92hd71xx_set_power_state(codec, AC_PWRST_D3);
4487 if (spec->eapd_mask)
4488 stac_gpio_set(codec, spec->gpio_mask,
4489 spec->gpio_dir, spec->gpio_data &
4490 ~spec->eapd_mask);
4491 return 0;
4494 #endif
4496 static struct hda_codec_ops stac92hd71bxx_patch_ops = {
4497 .build_controls = stac92xx_build_controls,
4498 .build_pcms = stac92xx_build_pcms,
4499 .init = stac92xx_init,
4500 .free = stac92xx_free,
4501 .unsol_event = stac92xx_unsol_event,
4502 #ifdef SND_HDA_NEEDS_RESUME
4503 .resume = stac92hd71xx_resume,
4504 .suspend = stac92hd71xx_suspend,
4505 #endif
4508 static struct hda_input_mux stac92hd71bxx_dmux = {
4509 .num_items = 4,
4510 .items = {
4511 { "Analog Inputs", 0x00 },
4512 { "Mixer", 0x01 },
4513 { "Digital Mic 1", 0x02 },
4514 { "Digital Mic 2", 0x03 },
4518 static int patch_stac92hd71bxx(struct hda_codec *codec)
4520 struct sigmatel_spec *spec;
4521 int err = 0;
4523 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4524 if (spec == NULL)
4525 return -ENOMEM;
4527 codec->spec = spec;
4528 codec->patch_ops = stac92xx_patch_ops;
4529 spec->num_pins = ARRAY_SIZE(stac92hd71bxx_pin_nids);
4530 spec->num_pwrs = ARRAY_SIZE(stac92hd71bxx_pwr_nids);
4531 spec->pin_nids = stac92hd71bxx_pin_nids;
4532 memcpy(&spec->private_dimux, &stac92hd71bxx_dmux,
4533 sizeof(stac92hd71bxx_dmux));
4534 spec->board_config = snd_hda_check_board_config(codec,
4535 STAC_92HD71BXX_MODELS,
4536 stac92hd71bxx_models,
4537 stac92hd71bxx_cfg_tbl);
4538 again:
4539 if (spec->board_config < 0) {
4540 snd_printdd(KERN_INFO "hda_codec: Unknown model for"
4541 " STAC92HD71BXX, using BIOS defaults\n");
4542 err = stac92xx_save_bios_config_regs(codec);
4543 if (err < 0) {
4544 stac92xx_free(codec);
4545 return err;
4547 spec->pin_configs = spec->bios_pin_configs;
4548 } else {
4549 spec->pin_configs = stac92hd71bxx_brd_tbl[spec->board_config];
4550 stac92xx_set_config_regs(codec);
4553 if (spec->board_config > STAC_92HD71BXX_REF) {
4554 /* GPIO0 = EAPD */
4555 spec->gpio_mask = 0x01;
4556 spec->gpio_dir = 0x01;
4557 spec->gpio_data = 0x01;
4560 switch (codec->vendor_id) {
4561 case 0x111d76b6: /* 4 Port without Analog Mixer */
4562 case 0x111d76b7:
4563 case 0x111d76b4: /* 6 Port without Analog Mixer */
4564 case 0x111d76b5:
4565 spec->mixer = stac92hd71bxx_mixer;
4566 spec->init = stac92hd71bxx_core_init;
4567 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
4568 break;
4569 case 0x111d7608: /* 5 Port with Analog Mixer */
4570 switch (spec->board_config) {
4571 case STAC_HP_M4:
4572 /* Enable VREF power saving on GPIO1 detect */
4573 snd_hda_codec_write_cache(codec, codec->afg, 0,
4574 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x02);
4575 snd_hda_codec_write_cache(codec, codec->afg, 0,
4576 AC_VERB_SET_UNSOLICITED_ENABLE,
4577 (AC_USRSP_EN | STAC_VREF_EVENT | 0x01));
4578 spec->gpio_mask |= 0x02;
4579 break;
4581 if ((codec->revision_id & 0xf) == 0 ||
4582 (codec->revision_id & 0xf) == 1) {
4583 #ifdef SND_HDA_NEEDS_RESUME
4584 codec->patch_ops = stac92hd71bxx_patch_ops;
4585 #endif
4586 spec->stream_delay = 40; /* 40 milliseconds */
4589 /* no output amps */
4590 spec->num_pwrs = 0;
4591 spec->mixer = stac92hd71bxx_analog_mixer;
4592 spec->dinput_mux = &spec->private_dimux;
4594 /* disable VSW */
4595 spec->init = &stac92hd71bxx_analog_core_init[HD_DISABLE_PORTF];
4596 stac92xx_set_config_reg(codec, 0xf, 0x40f000f0);
4597 break;
4598 case 0x111d7603: /* 6 Port with Analog Mixer */
4599 if ((codec->revision_id & 0xf) == 1) {
4600 #ifdef SND_HDA_NEEDS_RESUME
4601 codec->patch_ops = stac92hd71bxx_patch_ops;
4602 #endif
4603 spec->stream_delay = 40; /* 40 milliseconds */
4606 /* no output amps */
4607 spec->num_pwrs = 0;
4608 /* fallthru */
4609 default:
4610 spec->dinput_mux = &spec->private_dimux;
4611 spec->mixer = stac92hd71bxx_analog_mixer;
4612 spec->init = stac92hd71bxx_analog_core_init;
4613 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
4616 spec->aloopback_mask = 0x50;
4617 spec->aloopback_shift = 0;
4619 spec->powerdown_adcs = 1;
4620 spec->digbeep_nid = 0x26;
4621 spec->mux_nids = stac92hd71bxx_mux_nids;
4622 spec->adc_nids = stac92hd71bxx_adc_nids;
4623 spec->dmic_nids = stac92hd71bxx_dmic_nids;
4624 spec->dmux_nids = stac92hd71bxx_dmux_nids;
4625 spec->smux_nids = stac92hd71bxx_smux_nids;
4626 spec->pwr_nids = stac92hd71bxx_pwr_nids;
4628 spec->num_muxes = ARRAY_SIZE(stac92hd71bxx_mux_nids);
4629 spec->num_adcs = ARRAY_SIZE(stac92hd71bxx_adc_nids);
4631 switch (spec->board_config) {
4632 case STAC_HP_M4:
4633 /* enable internal microphone */
4634 stac92xx_set_config_reg(codec, 0x0e, 0x01813040);
4635 stac92xx_auto_set_pinctl(codec, 0x0e,
4636 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80);
4637 /* fallthru */
4638 case STAC_DELL_M4_2:
4639 spec->num_dmics = 0;
4640 spec->num_smuxes = 0;
4641 spec->num_dmuxes = 0;
4642 break;
4643 case STAC_DELL_M4_1:
4644 case STAC_DELL_M4_3:
4645 spec->num_dmics = 1;
4646 spec->num_smuxes = 0;
4647 spec->num_dmuxes = 0;
4648 break;
4649 default:
4650 spec->num_dmics = STAC92HD71BXX_NUM_DMICS;
4651 spec->num_smuxes = ARRAY_SIZE(stac92hd71bxx_smux_nids);
4652 spec->num_dmuxes = ARRAY_SIZE(stac92hd71bxx_dmux_nids);
4655 spec->multiout.num_dacs = 1;
4656 spec->multiout.hp_nid = 0x11;
4657 spec->multiout.dac_nids = stac92hd71bxx_dac_nids;
4658 if (spec->dinput_mux)
4659 spec->private_dimux.num_items +=
4660 spec->num_dmics -
4661 (ARRAY_SIZE(stac92hd71bxx_dmic_nids) - 1);
4663 err = stac92xx_parse_auto_config(codec, 0x21, 0x23);
4664 if (!err) {
4665 if (spec->board_config < 0) {
4666 printk(KERN_WARNING "hda_codec: No auto-config is "
4667 "available, default to model=ref\n");
4668 spec->board_config = STAC_92HD71BXX_REF;
4669 goto again;
4671 err = -EINVAL;
4674 if (err < 0) {
4675 stac92xx_free(codec);
4676 return err;
4679 return 0;
4682 static int patch_stac922x(struct hda_codec *codec)
4684 struct sigmatel_spec *spec;
4685 int err;
4687 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4688 if (spec == NULL)
4689 return -ENOMEM;
4691 codec->spec = spec;
4692 spec->num_pins = ARRAY_SIZE(stac922x_pin_nids);
4693 spec->pin_nids = stac922x_pin_nids;
4694 spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS,
4695 stac922x_models,
4696 stac922x_cfg_tbl);
4697 if (spec->board_config == STAC_INTEL_MAC_AUTO) {
4698 spec->gpio_mask = spec->gpio_dir = 0x03;
4699 spec->gpio_data = 0x03;
4700 /* Intel Macs have all same PCI SSID, so we need to check
4701 * codec SSID to distinguish the exact models
4703 printk(KERN_INFO "hda_codec: STAC922x, Apple subsys_id=%x\n", codec->subsystem_id);
4704 switch (codec->subsystem_id) {
4706 case 0x106b0800:
4707 spec->board_config = STAC_INTEL_MAC_V1;
4708 break;
4709 case 0x106b0600:
4710 case 0x106b0700:
4711 spec->board_config = STAC_INTEL_MAC_V2;
4712 break;
4713 case 0x106b0e00:
4714 case 0x106b0f00:
4715 case 0x106b1600:
4716 case 0x106b1700:
4717 case 0x106b0200:
4718 case 0x106b1e00:
4719 spec->board_config = STAC_INTEL_MAC_V3;
4720 break;
4721 case 0x106b1a00:
4722 case 0x00000100:
4723 spec->board_config = STAC_INTEL_MAC_V4;
4724 break;
4725 case 0x106b0a00:
4726 case 0x106b2200:
4727 spec->board_config = STAC_INTEL_MAC_V5;
4728 break;
4729 default:
4730 spec->board_config = STAC_INTEL_MAC_V3;
4731 break;
4735 again:
4736 if (spec->board_config < 0) {
4737 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC922x, "
4738 "using BIOS defaults\n");
4739 err = stac92xx_save_bios_config_regs(codec);
4740 if (err < 0) {
4741 stac92xx_free(codec);
4742 return err;
4744 spec->pin_configs = spec->bios_pin_configs;
4745 } else if (stac922x_brd_tbl[spec->board_config] != NULL) {
4746 spec->pin_configs = stac922x_brd_tbl[spec->board_config];
4747 stac92xx_set_config_regs(codec);
4750 spec->adc_nids = stac922x_adc_nids;
4751 spec->mux_nids = stac922x_mux_nids;
4752 spec->num_muxes = ARRAY_SIZE(stac922x_mux_nids);
4753 spec->num_adcs = ARRAY_SIZE(stac922x_adc_nids);
4754 spec->num_dmics = 0;
4755 spec->num_pwrs = 0;
4757 spec->init = stac922x_core_init;
4758 spec->mixer = stac922x_mixer;
4760 spec->multiout.dac_nids = spec->dac_nids;
4762 err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
4763 if (!err) {
4764 if (spec->board_config < 0) {
4765 printk(KERN_WARNING "hda_codec: No auto-config is "
4766 "available, default to model=ref\n");
4767 spec->board_config = STAC_D945_REF;
4768 goto again;
4770 err = -EINVAL;
4772 if (err < 0) {
4773 stac92xx_free(codec);
4774 return err;
4777 codec->patch_ops = stac92xx_patch_ops;
4779 /* Fix Mux capture level; max to 2 */
4780 snd_hda_override_amp_caps(codec, 0x12, HDA_OUTPUT,
4781 (0 << AC_AMPCAP_OFFSET_SHIFT) |
4782 (2 << AC_AMPCAP_NUM_STEPS_SHIFT) |
4783 (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4784 (0 << AC_AMPCAP_MUTE_SHIFT));
4786 return 0;
4789 static int patch_stac927x(struct hda_codec *codec)
4791 struct sigmatel_spec *spec;
4792 int err;
4794 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4795 if (spec == NULL)
4796 return -ENOMEM;
4798 codec->spec = spec;
4799 spec->num_pins = ARRAY_SIZE(stac927x_pin_nids);
4800 spec->pin_nids = stac927x_pin_nids;
4801 spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS,
4802 stac927x_models,
4803 stac927x_cfg_tbl);
4804 again:
4805 if (spec->board_config < 0 || !stac927x_brd_tbl[spec->board_config]) {
4806 if (spec->board_config < 0)
4807 snd_printdd(KERN_INFO "hda_codec: Unknown model for"
4808 "STAC927x, using BIOS defaults\n");
4809 err = stac92xx_save_bios_config_regs(codec);
4810 if (err < 0) {
4811 stac92xx_free(codec);
4812 return err;
4814 spec->pin_configs = spec->bios_pin_configs;
4815 } else {
4816 spec->pin_configs = stac927x_brd_tbl[spec->board_config];
4817 stac92xx_set_config_regs(codec);
4820 spec->digbeep_nid = 0x23;
4821 spec->adc_nids = stac927x_adc_nids;
4822 spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
4823 spec->mux_nids = stac927x_mux_nids;
4824 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
4825 spec->smux_nids = stac927x_smux_nids;
4826 spec->num_smuxes = ARRAY_SIZE(stac927x_smux_nids);
4827 spec->spdif_labels = stac927x_spdif_labels;
4828 spec->dac_list = stac927x_dac_nids;
4829 spec->multiout.dac_nids = spec->dac_nids;
4831 switch (spec->board_config) {
4832 case STAC_D965_3ST:
4833 case STAC_D965_5ST:
4834 /* GPIO0 High = Enable EAPD */
4835 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x01;
4836 spec->gpio_data = 0x01;
4837 spec->num_dmics = 0;
4839 spec->init = d965_core_init;
4840 spec->mixer = stac927x_mixer;
4841 break;
4842 case STAC_DELL_BIOS:
4843 switch (codec->subsystem_id) {
4844 case 0x10280209:
4845 case 0x1028022e:
4846 /* correct the device field to SPDIF out */
4847 stac92xx_set_config_reg(codec, 0x21, 0x01442070);
4848 break;
4850 /* configure the analog microphone on some laptops */
4851 stac92xx_set_config_reg(codec, 0x0c, 0x90a79130);
4852 /* correct the front output jack as a hp out */
4853 stac92xx_set_config_reg(codec, 0x0f, 0x0227011f);
4854 /* correct the front input jack as a mic */
4855 stac92xx_set_config_reg(codec, 0x0e, 0x02a79130);
4856 /* fallthru */
4857 case STAC_DELL_3ST:
4858 /* GPIO2 High = Enable EAPD */
4859 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x04;
4860 spec->gpio_data = 0x04;
4861 spec->dmic_nids = stac927x_dmic_nids;
4862 spec->num_dmics = STAC927X_NUM_DMICS;
4864 spec->init = d965_core_init;
4865 spec->mixer = stac927x_mixer;
4866 spec->dmux_nids = stac927x_dmux_nids;
4867 spec->num_dmuxes = ARRAY_SIZE(stac927x_dmux_nids);
4868 break;
4869 default:
4870 if (spec->board_config > STAC_D965_REF) {
4871 /* GPIO0 High = Enable EAPD */
4872 spec->eapd_mask = spec->gpio_mask = 0x01;
4873 spec->gpio_dir = spec->gpio_data = 0x01;
4875 spec->num_dmics = 0;
4877 spec->init = stac927x_core_init;
4878 spec->mixer = stac927x_mixer;
4881 spec->num_pwrs = 0;
4882 spec->aloopback_mask = 0x40;
4883 spec->aloopback_shift = 0;
4884 spec->eapd_switch = 1;
4886 err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
4887 if (!err) {
4888 if (spec->board_config < 0) {
4889 printk(KERN_WARNING "hda_codec: No auto-config is "
4890 "available, default to model=ref\n");
4891 spec->board_config = STAC_D965_REF;
4892 goto again;
4894 err = -EINVAL;
4896 if (err < 0) {
4897 stac92xx_free(codec);
4898 return err;
4901 codec->patch_ops = stac92xx_patch_ops;
4904 * !!FIXME!!
4905 * The STAC927x seem to require fairly long delays for certain
4906 * command sequences. With too short delays (even if the answer
4907 * is set to RIRB properly), it results in the silence output
4908 * on some hardwares like Dell.
4910 * The below flag enables the longer delay (see get_response
4911 * in hda_intel.c).
4913 codec->bus->needs_damn_long_delay = 1;
4915 /* no jack detecion for ref-no-jd model */
4916 if (spec->board_config == STAC_D965_REF_NO_JD)
4917 spec->hp_detect = 0;
4919 return 0;
4922 static int patch_stac9205(struct hda_codec *codec)
4924 struct sigmatel_spec *spec;
4925 int err;
4927 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4928 if (spec == NULL)
4929 return -ENOMEM;
4931 codec->spec = spec;
4932 spec->num_pins = ARRAY_SIZE(stac9205_pin_nids);
4933 spec->pin_nids = stac9205_pin_nids;
4934 spec->board_config = snd_hda_check_board_config(codec, STAC_9205_MODELS,
4935 stac9205_models,
4936 stac9205_cfg_tbl);
4937 again:
4938 if (spec->board_config < 0) {
4939 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9205, using BIOS defaults\n");
4940 err = stac92xx_save_bios_config_regs(codec);
4941 if (err < 0) {
4942 stac92xx_free(codec);
4943 return err;
4945 spec->pin_configs = spec->bios_pin_configs;
4946 } else {
4947 spec->pin_configs = stac9205_brd_tbl[spec->board_config];
4948 stac92xx_set_config_regs(codec);
4951 spec->digbeep_nid = 0x23;
4952 spec->adc_nids = stac9205_adc_nids;
4953 spec->num_adcs = ARRAY_SIZE(stac9205_adc_nids);
4954 spec->mux_nids = stac9205_mux_nids;
4955 spec->num_muxes = ARRAY_SIZE(stac9205_mux_nids);
4956 spec->smux_nids = stac9205_smux_nids;
4957 spec->num_smuxes = ARRAY_SIZE(stac9205_smux_nids);
4958 spec->dmic_nids = stac9205_dmic_nids;
4959 spec->num_dmics = STAC9205_NUM_DMICS;
4960 spec->dmux_nids = stac9205_dmux_nids;
4961 spec->num_dmuxes = ARRAY_SIZE(stac9205_dmux_nids);
4962 spec->num_pwrs = 0;
4964 spec->init = stac9205_core_init;
4965 spec->mixer = stac9205_mixer;
4967 spec->aloopback_mask = 0x40;
4968 spec->aloopback_shift = 0;
4969 spec->eapd_switch = 1;
4970 spec->multiout.dac_nids = spec->dac_nids;
4972 switch (spec->board_config){
4973 case STAC_9205_DELL_M43:
4974 /* Enable SPDIF in/out */
4975 stac92xx_set_config_reg(codec, 0x1f, 0x01441030);
4976 stac92xx_set_config_reg(codec, 0x20, 0x1c410030);
4978 /* Enable unsol response for GPIO4/Dock HP connection */
4979 snd_hda_codec_write_cache(codec, codec->afg, 0,
4980 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x10);
4981 snd_hda_codec_write_cache(codec, codec->afg, 0,
4982 AC_VERB_SET_UNSOLICITED_ENABLE,
4983 (AC_USRSP_EN | STAC_HP_EVENT));
4985 spec->gpio_dir = 0x0b;
4986 spec->eapd_mask = 0x01;
4987 spec->gpio_mask = 0x1b;
4988 spec->gpio_mute = 0x10;
4989 /* GPIO0 High = EAPD, GPIO1 Low = Headphone Mute,
4990 * GPIO3 Low = DRM
4992 spec->gpio_data = 0x01;
4993 break;
4994 case STAC_9205_REF:
4995 /* SPDIF-In enabled */
4996 break;
4997 default:
4998 /* GPIO0 High = EAPD */
4999 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
5000 spec->gpio_data = 0x01;
5001 break;
5004 err = stac92xx_parse_auto_config(codec, 0x1f, 0x20);
5005 if (!err) {
5006 if (spec->board_config < 0) {
5007 printk(KERN_WARNING "hda_codec: No auto-config is "
5008 "available, default to model=ref\n");
5009 spec->board_config = STAC_9205_REF;
5010 goto again;
5012 err = -EINVAL;
5014 if (err < 0) {
5015 stac92xx_free(codec);
5016 return err;
5019 codec->patch_ops = stac92xx_patch_ops;
5021 return 0;
5025 * STAC9872 hack
5028 /* static config for Sony VAIO FE550G and Sony VAIO AR */
5029 static hda_nid_t vaio_dacs[] = { 0x2 };
5030 #define VAIO_HP_DAC 0x5
5031 static hda_nid_t vaio_adcs[] = { 0x8 /*,0x6*/ };
5032 static hda_nid_t vaio_mux_nids[] = { 0x15 };
5034 static struct hda_input_mux vaio_mux = {
5035 .num_items = 3,
5036 .items = {
5037 /* { "HP", 0x0 }, */
5038 { "Mic Jack", 0x1 },
5039 { "Internal Mic", 0x2 },
5040 { "PCM", 0x3 },
5044 static struct hda_verb vaio_init[] = {
5045 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
5046 {0x0a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | STAC_HP_EVENT},
5047 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
5048 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
5049 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
5050 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
5051 {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
5052 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
5053 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
5054 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
5055 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
5056 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
5060 static struct hda_verb vaio_ar_init[] = {
5061 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
5062 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
5063 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
5064 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
5065 /* {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },*/ /* Optical Out */
5066 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
5067 {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
5068 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
5069 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
5070 /* {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},*/ /* Optical Out */
5071 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
5072 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
5073 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
5077 /* bind volumes of both NID 0x02 and 0x05 */
5078 static struct hda_bind_ctls vaio_bind_master_vol = {
5079 .ops = &snd_hda_bind_vol,
5080 .values = {
5081 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
5082 HDA_COMPOSE_AMP_VAL(0x05, 3, 0, HDA_OUTPUT),
5087 /* bind volumes of both NID 0x02 and 0x05 */
5088 static struct hda_bind_ctls vaio_bind_master_sw = {
5089 .ops = &snd_hda_bind_sw,
5090 .values = {
5091 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
5092 HDA_COMPOSE_AMP_VAL(0x05, 3, 0, HDA_OUTPUT),
5097 static struct snd_kcontrol_new vaio_mixer[] = {
5098 HDA_BIND_VOL("Master Playback Volume", &vaio_bind_master_vol),
5099 HDA_BIND_SW("Master Playback Switch", &vaio_bind_master_sw),
5100 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
5101 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
5102 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
5104 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5105 .name = "Capture Source",
5106 .count = 1,
5107 .info = stac92xx_mux_enum_info,
5108 .get = stac92xx_mux_enum_get,
5109 .put = stac92xx_mux_enum_put,
5114 static struct snd_kcontrol_new vaio_ar_mixer[] = {
5115 HDA_BIND_VOL("Master Playback Volume", &vaio_bind_master_vol),
5116 HDA_BIND_SW("Master Playback Switch", &vaio_bind_master_sw),
5117 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
5118 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
5119 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
5120 /*HDA_CODEC_MUTE("Optical Out Switch", 0x10, 0, HDA_OUTPUT),
5121 HDA_CODEC_VOLUME("Optical Out Volume", 0x10, 0, HDA_OUTPUT),*/
5123 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5124 .name = "Capture Source",
5125 .count = 1,
5126 .info = stac92xx_mux_enum_info,
5127 .get = stac92xx_mux_enum_get,
5128 .put = stac92xx_mux_enum_put,
5133 static struct hda_codec_ops stac9872_patch_ops = {
5134 .build_controls = stac92xx_build_controls,
5135 .build_pcms = stac92xx_build_pcms,
5136 .init = stac92xx_init,
5137 .free = stac92xx_free,
5138 #ifdef SND_HDA_NEEDS_RESUME
5139 .resume = stac92xx_resume,
5140 #endif
5143 static int stac9872_vaio_init(struct hda_codec *codec)
5145 int err;
5147 err = stac92xx_init(codec);
5148 if (err < 0)
5149 return err;
5150 if (codec->patch_ops.unsol_event)
5151 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
5152 return 0;
5155 static void stac9872_vaio_hp_detect(struct hda_codec *codec, unsigned int res)
5157 if (get_hp_pin_presence(codec, 0x0a)) {
5158 stac92xx_reset_pinctl(codec, 0x0f, AC_PINCTL_OUT_EN);
5159 stac92xx_set_pinctl(codec, 0x0a, AC_PINCTL_OUT_EN);
5160 } else {
5161 stac92xx_reset_pinctl(codec, 0x0a, AC_PINCTL_OUT_EN);
5162 stac92xx_set_pinctl(codec, 0x0f, AC_PINCTL_OUT_EN);
5166 static void stac9872_vaio_unsol_event(struct hda_codec *codec, unsigned int res)
5168 switch (res >> 26) {
5169 case STAC_HP_EVENT:
5170 stac9872_vaio_hp_detect(codec, res);
5171 break;
5175 static struct hda_codec_ops stac9872_vaio_patch_ops = {
5176 .build_controls = stac92xx_build_controls,
5177 .build_pcms = stac92xx_build_pcms,
5178 .init = stac9872_vaio_init,
5179 .free = stac92xx_free,
5180 .unsol_event = stac9872_vaio_unsol_event,
5181 #ifdef CONFIG_PM
5182 .resume = stac92xx_resume,
5183 #endif
5186 enum { /* FE and SZ series. id=0x83847661 and subsys=0x104D0700 or 104D1000. */
5187 CXD9872RD_VAIO,
5188 /* Unknown. id=0x83847662 and subsys=0x104D1200 or 104D1000. */
5189 STAC9872AK_VAIO,
5190 /* Unknown. id=0x83847661 and subsys=0x104D1200. */
5191 STAC9872K_VAIO,
5192 /* AR Series. id=0x83847664 and subsys=104D1300 */
5193 CXD9872AKD_VAIO,
5194 STAC_9872_MODELS,
5197 static const char *stac9872_models[STAC_9872_MODELS] = {
5198 [CXD9872RD_VAIO] = "vaio",
5199 [CXD9872AKD_VAIO] = "vaio-ar",
5202 static struct snd_pci_quirk stac9872_cfg_tbl[] = {
5203 SND_PCI_QUIRK(0x104d, 0x81e6, "Sony VAIO F/S", CXD9872RD_VAIO),
5204 SND_PCI_QUIRK(0x104d, 0x81ef, "Sony VAIO F/S", CXD9872RD_VAIO),
5205 SND_PCI_QUIRK(0x104d, 0x81fd, "Sony VAIO AR", CXD9872AKD_VAIO),
5206 SND_PCI_QUIRK(0x104d, 0x8205, "Sony VAIO AR", CXD9872AKD_VAIO),
5210 static int patch_stac9872(struct hda_codec *codec)
5212 struct sigmatel_spec *spec;
5213 int board_config;
5215 board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
5216 stac9872_models,
5217 stac9872_cfg_tbl);
5218 if (board_config < 0)
5219 /* unknown config, let generic-parser do its job... */
5220 return snd_hda_parse_generic_codec(codec);
5222 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5223 if (spec == NULL)
5224 return -ENOMEM;
5226 codec->spec = spec;
5227 switch (board_config) {
5228 case CXD9872RD_VAIO:
5229 case STAC9872AK_VAIO:
5230 case STAC9872K_VAIO:
5231 spec->mixer = vaio_mixer;
5232 spec->init = vaio_init;
5233 spec->multiout.max_channels = 2;
5234 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
5235 spec->multiout.dac_nids = vaio_dacs;
5236 spec->multiout.hp_nid = VAIO_HP_DAC;
5237 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
5238 spec->adc_nids = vaio_adcs;
5239 spec->num_pwrs = 0;
5240 spec->input_mux = &vaio_mux;
5241 spec->mux_nids = vaio_mux_nids;
5242 codec->patch_ops = stac9872_vaio_patch_ops;
5243 break;
5245 case CXD9872AKD_VAIO:
5246 spec->mixer = vaio_ar_mixer;
5247 spec->init = vaio_ar_init;
5248 spec->multiout.max_channels = 2;
5249 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
5250 spec->multiout.dac_nids = vaio_dacs;
5251 spec->multiout.hp_nid = VAIO_HP_DAC;
5252 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
5253 spec->num_pwrs = 0;
5254 spec->adc_nids = vaio_adcs;
5255 spec->input_mux = &vaio_mux;
5256 spec->mux_nids = vaio_mux_nids;
5257 codec->patch_ops = stac9872_patch_ops;
5258 break;
5261 return 0;
5266 * patch entries
5268 struct hda_codec_preset snd_hda_preset_sigmatel[] = {
5269 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
5270 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
5271 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
5272 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
5273 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
5274 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
5275 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
5276 { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
5277 { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
5278 { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
5279 { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
5280 { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
5281 { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
5282 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
5283 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
5284 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
5285 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
5286 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
5287 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
5288 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
5289 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
5290 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
5291 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
5292 { .id = 0x83847632, .name = "STAC9202", .patch = patch_stac925x },
5293 { .id = 0x83847633, .name = "STAC9202D", .patch = patch_stac925x },
5294 { .id = 0x83847634, .name = "STAC9250", .patch = patch_stac925x },
5295 { .id = 0x83847635, .name = "STAC9250D", .patch = patch_stac925x },
5296 { .id = 0x83847636, .name = "STAC9251", .patch = patch_stac925x },
5297 { .id = 0x83847637, .name = "STAC9250D", .patch = patch_stac925x },
5298 { .id = 0x83847645, .name = "92HD206X", .patch = patch_stac927x },
5299 { .id = 0x83847646, .name = "92HD206D", .patch = patch_stac927x },
5300 /* The following does not take into account .id=0x83847661 when subsys =
5301 * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
5302 * currently not fully supported.
5304 { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
5305 { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
5306 { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
5307 { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
5308 { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
5309 { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
5310 { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
5311 { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
5312 { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
5313 { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
5314 { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
5315 { .id = 0x111d7603, .name = "92HD75B3X5", .patch = patch_stac92hd71bxx},
5316 { .id = 0x111d7604, .name = "92HD83C1X5", .patch = patch_stac92hd83xxx},
5317 { .id = 0x111d7605, .name = "92HD81B1X5", .patch = patch_stac92hd83xxx},
5318 { .id = 0x111d7608, .name = "92HD75B2X5", .patch = patch_stac92hd71bxx},
5319 { .id = 0x111d7674, .name = "92HD73D1X5", .patch = patch_stac92hd73xx },
5320 { .id = 0x111d7675, .name = "92HD73C1X5", .patch = patch_stac92hd73xx },
5321 { .id = 0x111d7676, .name = "92HD73E1X5", .patch = patch_stac92hd73xx },
5322 { .id = 0x111d76b0, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
5323 { .id = 0x111d76b1, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
5324 { .id = 0x111d76b2, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
5325 { .id = 0x111d76b3, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
5326 { .id = 0x111d76b4, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
5327 { .id = 0x111d76b5, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
5328 { .id = 0x111d76b6, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
5329 { .id = 0x111d76b7, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
5330 {} /* terminator */