ALSA: hda - Don't reset HP pinctl in patch_sigmatel.c
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / sound / pci / hda / patch_sigmatel.c
blob8b204b8ffdfcb007cc878b8e19eb523e640fac41
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_HP_DV5,
93 STAC_92HD71BXX_MODELS
96 enum {
97 STAC_925x_REF,
98 STAC_M2_2,
99 STAC_MA6,
100 STAC_PA6,
101 STAC_925x_MODELS
104 enum {
105 STAC_D945_REF,
106 STAC_D945GTP3,
107 STAC_D945GTP5,
108 STAC_INTEL_MAC_V1,
109 STAC_INTEL_MAC_V2,
110 STAC_INTEL_MAC_V3,
111 STAC_INTEL_MAC_V4,
112 STAC_INTEL_MAC_V5,
113 STAC_INTEL_MAC_AUTO, /* This model is selected if no module parameter
114 * is given, one of the above models will be
115 * chosen according to the subsystem id. */
116 /* for backward compatibility */
117 STAC_MACMINI,
118 STAC_MACBOOK,
119 STAC_MACBOOK_PRO_V1,
120 STAC_MACBOOK_PRO_V2,
121 STAC_IMAC_INTEL,
122 STAC_IMAC_INTEL_20,
123 STAC_ECS_202,
124 STAC_922X_DELL_D81,
125 STAC_922X_DELL_D82,
126 STAC_922X_DELL_M81,
127 STAC_922X_DELL_M82,
128 STAC_922X_MODELS
131 enum {
132 STAC_D965_REF_NO_JD, /* no jack-detection */
133 STAC_D965_REF,
134 STAC_D965_3ST,
135 STAC_D965_5ST,
136 STAC_DELL_3ST,
137 STAC_DELL_BIOS,
138 STAC_927X_MODELS
141 struct sigmatel_spec {
142 struct snd_kcontrol_new *mixers[4];
143 unsigned int num_mixers;
145 int board_config;
146 unsigned int eapd_switch: 1;
147 unsigned int surr_switch: 1;
148 unsigned int line_switch: 1;
149 unsigned int mic_switch: 1;
150 unsigned int alt_switch: 1;
151 unsigned int hp_detect: 1;
152 unsigned int spdif_mute: 1;
154 /* gpio lines */
155 unsigned int eapd_mask;
156 unsigned int gpio_mask;
157 unsigned int gpio_dir;
158 unsigned int gpio_data;
159 unsigned int gpio_mute;
161 /* stream */
162 unsigned int stream_delay;
164 /* analog loopback */
165 unsigned char aloopback_mask;
166 unsigned char aloopback_shift;
168 /* power management */
169 unsigned int num_pwrs;
170 unsigned int *pwr_mapping;
171 hda_nid_t *pwr_nids;
172 hda_nid_t *dac_list;
174 /* playback */
175 struct hda_input_mux *mono_mux;
176 struct hda_input_mux *amp_mux;
177 unsigned int cur_mmux;
178 struct hda_multi_out multiout;
179 hda_nid_t dac_nids[5];
181 /* capture */
182 hda_nid_t *adc_nids;
183 unsigned int num_adcs;
184 hda_nid_t *mux_nids;
185 unsigned int num_muxes;
186 hda_nid_t *dmic_nids;
187 unsigned int num_dmics;
188 hda_nid_t *dmux_nids;
189 unsigned int num_dmuxes;
190 hda_nid_t *smux_nids;
191 unsigned int num_smuxes;
192 const char **spdif_labels;
194 hda_nid_t dig_in_nid;
195 hda_nid_t mono_nid;
196 hda_nid_t anabeep_nid;
197 hda_nid_t digbeep_nid;
199 /* pin widgets */
200 hda_nid_t *pin_nids;
201 unsigned int num_pins;
202 unsigned int *pin_configs;
203 unsigned int *bios_pin_configs;
205 /* codec specific stuff */
206 struct hda_verb *init;
207 struct snd_kcontrol_new *mixer;
209 /* capture source */
210 struct hda_input_mux *dinput_mux;
211 unsigned int cur_dmux[2];
212 struct hda_input_mux *input_mux;
213 unsigned int cur_mux[3];
214 struct hda_input_mux *sinput_mux;
215 unsigned int cur_smux[2];
216 unsigned int cur_amux;
217 hda_nid_t *amp_nids;
218 unsigned int num_amps;
219 unsigned int powerdown_adcs;
221 /* i/o switches */
222 unsigned int io_switch[2];
223 unsigned int clfe_swap;
224 unsigned int hp_switch; /* NID of HP as line-out */
225 unsigned int aloopback;
227 struct hda_pcm pcm_rec[2]; /* PCM information */
229 /* dynamic controls and input_mux */
230 struct auto_pin_cfg autocfg;
231 unsigned int num_kctl_alloc, num_kctl_used;
232 struct snd_kcontrol_new *kctl_alloc;
233 struct hda_input_mux private_dimux;
234 struct hda_input_mux private_imux;
235 struct hda_input_mux private_smux;
236 struct hda_input_mux private_amp_mux;
237 struct hda_input_mux private_mono_mux;
240 static hda_nid_t stac9200_adc_nids[1] = {
241 0x03,
244 static hda_nid_t stac9200_mux_nids[1] = {
245 0x0c,
248 static hda_nid_t stac9200_dac_nids[1] = {
249 0x02,
252 static hda_nid_t stac92hd73xx_pwr_nids[8] = {
253 0x0a, 0x0b, 0x0c, 0xd, 0x0e,
254 0x0f, 0x10, 0x11
257 static hda_nid_t stac92hd73xx_slave_dig_outs[2] = {
258 0x26, 0,
261 static hda_nid_t stac92hd73xx_adc_nids[2] = {
262 0x1a, 0x1b
265 #define DELL_M6_AMP 2
266 static hda_nid_t stac92hd73xx_amp_nids[3] = {
267 0x0b, 0x0c, 0x0e
270 #define STAC92HD73XX_NUM_DMICS 2
271 static hda_nid_t stac92hd73xx_dmic_nids[STAC92HD73XX_NUM_DMICS + 1] = {
272 0x13, 0x14, 0
275 #define STAC92HD73_DAC_COUNT 5
276 static hda_nid_t stac92hd73xx_dac_nids[STAC92HD73_DAC_COUNT] = {
277 0x15, 0x16, 0x17, 0x18, 0x19,
280 static hda_nid_t stac92hd73xx_mux_nids[4] = {
281 0x28, 0x29, 0x2a, 0x2b,
284 static hda_nid_t stac92hd73xx_dmux_nids[2] = {
285 0x20, 0x21,
288 static hda_nid_t stac92hd73xx_smux_nids[2] = {
289 0x22, 0x23,
292 #define STAC92HD83XXX_NUM_DMICS 2
293 static hda_nid_t stac92hd83xxx_dmic_nids[STAC92HD83XXX_NUM_DMICS + 1] = {
294 0x11, 0x12, 0
297 #define STAC92HD81_DAC_COUNT 2
298 #define STAC92HD83_DAC_COUNT 3
299 static hda_nid_t stac92hd83xxx_dac_nids[STAC92HD73_DAC_COUNT] = {
300 0x13, 0x14, 0x22,
303 static hda_nid_t stac92hd83xxx_dmux_nids[2] = {
304 0x17, 0x18,
307 static hda_nid_t stac92hd83xxx_adc_nids[2] = {
308 0x15, 0x16,
311 static hda_nid_t stac92hd83xxx_pwr_nids[4] = {
312 0xa, 0xb, 0xd, 0xe,
315 static hda_nid_t stac92hd83xxx_slave_dig_outs[2] = {
316 0x1e, 0,
319 static unsigned int stac92hd83xxx_pwr_mapping[4] = {
320 0x03, 0x0c, 0x10, 0x40,
323 static hda_nid_t stac92hd71bxx_pwr_nids[3] = {
324 0x0a, 0x0d, 0x0f
327 static hda_nid_t stac92hd71bxx_adc_nids[2] = {
328 0x12, 0x13,
331 static hda_nid_t stac92hd71bxx_mux_nids[2] = {
332 0x1a, 0x1b
335 static hda_nid_t stac92hd71bxx_dmux_nids[2] = {
336 0x1c, 0x1d,
339 static hda_nid_t stac92hd71bxx_smux_nids[2] = {
340 0x24, 0x25,
343 static hda_nid_t stac92hd71bxx_dac_nids[1] = {
344 0x10, /*0x11, */
347 #define STAC92HD71BXX_NUM_DMICS 2
348 static hda_nid_t stac92hd71bxx_dmic_nids[STAC92HD71BXX_NUM_DMICS + 1] = {
349 0x18, 0x19, 0
352 static hda_nid_t stac92hd71bxx_slave_dig_outs[2] = {
353 0x22, 0
356 static hda_nid_t stac925x_adc_nids[1] = {
357 0x03,
360 static hda_nid_t stac925x_mux_nids[1] = {
361 0x0f,
364 static hda_nid_t stac925x_dac_nids[1] = {
365 0x02,
368 #define STAC925X_NUM_DMICS 1
369 static hda_nid_t stac925x_dmic_nids[STAC925X_NUM_DMICS + 1] = {
370 0x15, 0
373 static hda_nid_t stac925x_dmux_nids[1] = {
374 0x14,
377 static hda_nid_t stac922x_adc_nids[2] = {
378 0x06, 0x07,
381 static hda_nid_t stac922x_mux_nids[2] = {
382 0x12, 0x13,
385 static hda_nid_t stac927x_adc_nids[3] = {
386 0x07, 0x08, 0x09
389 static hda_nid_t stac927x_mux_nids[3] = {
390 0x15, 0x16, 0x17
393 static hda_nid_t stac927x_smux_nids[1] = {
394 0x21,
397 static hda_nid_t stac927x_dac_nids[6] = {
398 0x02, 0x03, 0x04, 0x05, 0x06, 0
401 static hda_nid_t stac927x_dmux_nids[1] = {
402 0x1b,
405 #define STAC927X_NUM_DMICS 2
406 static hda_nid_t stac927x_dmic_nids[STAC927X_NUM_DMICS + 1] = {
407 0x13, 0x14, 0
410 static const char *stac927x_spdif_labels[5] = {
411 "Digital Playback", "ADAT", "Analog Mux 1",
412 "Analog Mux 2", "Analog Mux 3"
415 static hda_nid_t stac9205_adc_nids[2] = {
416 0x12, 0x13
419 static hda_nid_t stac9205_mux_nids[2] = {
420 0x19, 0x1a
423 static hda_nid_t stac9205_dmux_nids[1] = {
424 0x1d,
427 static hda_nid_t stac9205_smux_nids[1] = {
428 0x21,
431 #define STAC9205_NUM_DMICS 2
432 static hda_nid_t stac9205_dmic_nids[STAC9205_NUM_DMICS + 1] = {
433 0x17, 0x18, 0
436 static hda_nid_t stac9200_pin_nids[8] = {
437 0x08, 0x09, 0x0d, 0x0e,
438 0x0f, 0x10, 0x11, 0x12,
441 static hda_nid_t stac925x_pin_nids[8] = {
442 0x07, 0x08, 0x0a, 0x0b,
443 0x0c, 0x0d, 0x10, 0x11,
446 static hda_nid_t stac922x_pin_nids[10] = {
447 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
448 0x0f, 0x10, 0x11, 0x15, 0x1b,
451 static hda_nid_t stac92hd73xx_pin_nids[13] = {
452 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
453 0x0f, 0x10, 0x11, 0x12, 0x13,
454 0x14, 0x22, 0x23
457 static hda_nid_t stac92hd83xxx_pin_nids[14] = {
458 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
459 0x0f, 0x10, 0x11, 0x12, 0x13,
460 0x1d, 0x1e, 0x1f, 0x20
462 static hda_nid_t stac92hd71bxx_pin_nids[11] = {
463 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
464 0x0f, 0x14, 0x18, 0x19, 0x1e,
465 0x1f,
468 static hda_nid_t stac927x_pin_nids[14] = {
469 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
470 0x0f, 0x10, 0x11, 0x12, 0x13,
471 0x14, 0x21, 0x22, 0x23,
474 static hda_nid_t stac9205_pin_nids[12] = {
475 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
476 0x0f, 0x14, 0x16, 0x17, 0x18,
477 0x21, 0x22,
480 #define stac92xx_amp_volume_info snd_hda_mixer_amp_volume_info
482 static int stac92xx_amp_volume_get(struct snd_kcontrol *kcontrol,
483 struct snd_ctl_elem_value *ucontrol)
485 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
486 struct sigmatel_spec *spec = codec->spec;
487 hda_nid_t nid = spec->amp_nids[spec->cur_amux];
489 kcontrol->private_value ^= get_amp_nid(kcontrol);
490 kcontrol->private_value |= nid;
492 return snd_hda_mixer_amp_volume_get(kcontrol, ucontrol);
495 static int stac92xx_amp_volume_put(struct snd_kcontrol *kcontrol,
496 struct snd_ctl_elem_value *ucontrol)
498 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
499 struct sigmatel_spec *spec = codec->spec;
500 hda_nid_t nid = spec->amp_nids[spec->cur_amux];
502 kcontrol->private_value ^= get_amp_nid(kcontrol);
503 kcontrol->private_value |= nid;
505 return snd_hda_mixer_amp_volume_put(kcontrol, ucontrol);
508 static int stac92xx_dmux_enum_info(struct snd_kcontrol *kcontrol,
509 struct snd_ctl_elem_info *uinfo)
511 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
512 struct sigmatel_spec *spec = codec->spec;
513 return snd_hda_input_mux_info(spec->dinput_mux, uinfo);
516 static int stac92xx_dmux_enum_get(struct snd_kcontrol *kcontrol,
517 struct snd_ctl_elem_value *ucontrol)
519 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
520 struct sigmatel_spec *spec = codec->spec;
521 unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
523 ucontrol->value.enumerated.item[0] = spec->cur_dmux[dmux_idx];
524 return 0;
527 static int stac92xx_dmux_enum_put(struct snd_kcontrol *kcontrol,
528 struct snd_ctl_elem_value *ucontrol)
530 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
531 struct sigmatel_spec *spec = codec->spec;
532 unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
534 return snd_hda_input_mux_put(codec, spec->dinput_mux, ucontrol,
535 spec->dmux_nids[dmux_idx], &spec->cur_dmux[dmux_idx]);
538 static int stac92xx_smux_enum_info(struct snd_kcontrol *kcontrol,
539 struct snd_ctl_elem_info *uinfo)
541 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
542 struct sigmatel_spec *spec = codec->spec;
543 return snd_hda_input_mux_info(spec->sinput_mux, uinfo);
546 static int stac92xx_smux_enum_get(struct snd_kcontrol *kcontrol,
547 struct snd_ctl_elem_value *ucontrol)
549 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
550 struct sigmatel_spec *spec = codec->spec;
551 unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
553 ucontrol->value.enumerated.item[0] = spec->cur_smux[smux_idx];
554 return 0;
557 static int stac92xx_smux_enum_put(struct snd_kcontrol *kcontrol,
558 struct snd_ctl_elem_value *ucontrol)
560 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
561 struct sigmatel_spec *spec = codec->spec;
562 struct hda_input_mux *smux = &spec->private_smux;
563 unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
564 int err, val;
565 hda_nid_t nid;
567 err = snd_hda_input_mux_put(codec, spec->sinput_mux, ucontrol,
568 spec->smux_nids[smux_idx], &spec->cur_smux[smux_idx]);
569 if (err < 0)
570 return err;
572 if (spec->spdif_mute) {
573 if (smux_idx == 0)
574 nid = spec->multiout.dig_out_nid;
575 else
576 nid = codec->slave_dig_outs[smux_idx - 1];
577 if (spec->cur_smux[smux_idx] == smux->num_items - 1)
578 val = AMP_OUT_MUTE;
579 else
580 val = AMP_OUT_UNMUTE;
581 /* un/mute SPDIF out */
582 snd_hda_codec_write_cache(codec, nid, 0,
583 AC_VERB_SET_AMP_GAIN_MUTE, val);
585 return 0;
588 static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
590 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
591 struct sigmatel_spec *spec = codec->spec;
592 return snd_hda_input_mux_info(spec->input_mux, uinfo);
595 static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
597 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
598 struct sigmatel_spec *spec = codec->spec;
599 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
601 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
602 return 0;
605 static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
607 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
608 struct sigmatel_spec *spec = codec->spec;
609 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
611 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
612 spec->mux_nids[adc_idx], &spec->cur_mux[adc_idx]);
615 static int stac92xx_mono_mux_enum_info(struct snd_kcontrol *kcontrol,
616 struct snd_ctl_elem_info *uinfo)
618 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
619 struct sigmatel_spec *spec = codec->spec;
620 return snd_hda_input_mux_info(spec->mono_mux, uinfo);
623 static int stac92xx_mono_mux_enum_get(struct snd_kcontrol *kcontrol,
624 struct snd_ctl_elem_value *ucontrol)
626 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
627 struct sigmatel_spec *spec = codec->spec;
629 ucontrol->value.enumerated.item[0] = spec->cur_mmux;
630 return 0;
633 static int stac92xx_mono_mux_enum_put(struct snd_kcontrol *kcontrol,
634 struct snd_ctl_elem_value *ucontrol)
636 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
637 struct sigmatel_spec *spec = codec->spec;
639 return snd_hda_input_mux_put(codec, spec->mono_mux, ucontrol,
640 spec->mono_nid, &spec->cur_mmux);
643 static int stac92xx_amp_mux_enum_info(struct snd_kcontrol *kcontrol,
644 struct snd_ctl_elem_info *uinfo)
646 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
647 struct sigmatel_spec *spec = codec->spec;
648 return snd_hda_input_mux_info(spec->amp_mux, uinfo);
651 static int stac92xx_amp_mux_enum_get(struct snd_kcontrol *kcontrol,
652 struct snd_ctl_elem_value *ucontrol)
654 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
655 struct sigmatel_spec *spec = codec->spec;
657 ucontrol->value.enumerated.item[0] = spec->cur_amux;
658 return 0;
661 static int stac92xx_amp_mux_enum_put(struct snd_kcontrol *kcontrol,
662 struct snd_ctl_elem_value *ucontrol)
664 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
665 struct sigmatel_spec *spec = codec->spec;
666 struct snd_kcontrol *ctl =
667 snd_hda_find_mixer_ctl(codec, "Amp Capture Volume");
668 if (!ctl)
669 return -EINVAL;
671 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE |
672 SNDRV_CTL_EVENT_MASK_INFO, &ctl->id);
674 return snd_hda_input_mux_put(codec, spec->amp_mux, ucontrol,
675 0, &spec->cur_amux);
678 #define stac92xx_aloopback_info snd_ctl_boolean_mono_info
680 static int stac92xx_aloopback_get(struct snd_kcontrol *kcontrol,
681 struct snd_ctl_elem_value *ucontrol)
683 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
684 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
685 struct sigmatel_spec *spec = codec->spec;
687 ucontrol->value.integer.value[0] = !!(spec->aloopback &
688 (spec->aloopback_mask << idx));
689 return 0;
692 static int stac92xx_aloopback_put(struct snd_kcontrol *kcontrol,
693 struct snd_ctl_elem_value *ucontrol)
695 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
696 struct sigmatel_spec *spec = codec->spec;
697 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
698 unsigned int dac_mode;
699 unsigned int val, idx_val;
701 idx_val = spec->aloopback_mask << idx;
702 if (ucontrol->value.integer.value[0])
703 val = spec->aloopback | idx_val;
704 else
705 val = spec->aloopback & ~idx_val;
706 if (spec->aloopback == val)
707 return 0;
709 spec->aloopback = val;
711 /* Only return the bits defined by the shift value of the
712 * first two bytes of the mask
714 dac_mode = snd_hda_codec_read(codec, codec->afg, 0,
715 kcontrol->private_value & 0xFFFF, 0x0);
716 dac_mode >>= spec->aloopback_shift;
718 if (spec->aloopback & idx_val) {
719 snd_hda_power_up(codec);
720 dac_mode |= idx_val;
721 } else {
722 snd_hda_power_down(codec);
723 dac_mode &= ~idx_val;
726 snd_hda_codec_write_cache(codec, codec->afg, 0,
727 kcontrol->private_value >> 16, dac_mode);
729 return 1;
732 static struct hda_verb stac9200_core_init[] = {
733 /* set dac0mux for dac converter */
734 { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
738 static struct hda_verb stac9200_eapd_init[] = {
739 /* set dac0mux for dac converter */
740 {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
741 {0x08, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
745 static struct hda_verb stac92hd73xx_6ch_core_init[] = {
746 /* set master volume and direct control */
747 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
748 /* setup audio connections */
749 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00},
750 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x01},
751 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x02},
752 /* setup adcs to point to mixer */
753 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
754 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
755 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
756 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
757 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
758 /* setup import muxs */
759 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
760 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
761 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
762 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x00},
766 static struct hda_verb dell_eq_core_init[] = {
767 /* set master volume to max value without distortion
768 * and direct control */
769 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xec},
770 /* setup audio connections */
771 { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
772 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x02},
773 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x01},
774 /* setup adcs to point to mixer */
775 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
776 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
777 /* setup import muxs */
778 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
779 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
780 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
781 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x00},
785 static struct hda_verb dell_m6_core_init[] = {
786 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
787 /* setup audio connections */
788 { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
789 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x01},
790 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x02},
791 /* setup adcs to point to mixer */
792 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
793 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
794 /* setup import muxs */
795 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
796 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
797 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
798 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x00},
802 static struct hda_verb stac92hd73xx_8ch_core_init[] = {
803 /* set master volume and direct control */
804 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
805 /* setup audio connections */
806 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00},
807 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x01},
808 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x02},
809 /* connect hp ports to dac3 */
810 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x03},
811 { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x03},
812 /* setup adcs to point to mixer */
813 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
814 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
815 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
816 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
817 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
818 /* setup import muxs */
819 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
820 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
821 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
822 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x03},
826 static struct hda_verb stac92hd73xx_10ch_core_init[] = {
827 /* set master volume and direct control */
828 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
829 /* setup audio connections */
830 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
831 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x01 },
832 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x02 },
833 /* dac3 is connected to import3 mux */
834 { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0xb07f},
835 /* connect hp ports to dac4 */
836 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x04},
837 { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x04},
838 /* setup adcs to point to mixer */
839 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
840 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
841 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
842 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
843 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
844 /* setup import muxs */
845 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
846 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
847 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
848 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x03},
852 static struct hda_verb stac92hd83xxx_core_init[] = {
853 /* start of config #1 */
854 { 0xe, AC_VERB_SET_CONNECT_SEL, 0x3},
856 /* start of config #2 */
857 { 0xa, AC_VERB_SET_CONNECT_SEL, 0x0},
858 { 0xb, AC_VERB_SET_CONNECT_SEL, 0x0},
859 { 0xd, AC_VERB_SET_CONNECT_SEL, 0x1},
861 /* power state controls amps */
862 { 0x01, AC_VERB_SET_EAPD, 1 << 2},
866 static struct hda_verb stac92hd71bxx_core_init[] = {
867 /* set master volume and direct control */
868 { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
869 /* connect headphone jack to dac1 */
870 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x01},
871 /* unmute right and left channels for nodes 0x0a, 0xd, 0x0f */
872 { 0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
873 { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
874 { 0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
878 #define HD_DISABLE_PORTF 2
879 static struct hda_verb stac92hd71bxx_analog_core_init[] = {
880 /* start of config #1 */
882 /* connect port 0f to audio mixer */
883 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x2},
884 /* unmute right and left channels for node 0x0f */
885 { 0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
886 /* start of config #2 */
888 /* set master volume and direct control */
889 { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
890 /* connect headphone jack to dac1 */
891 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x01},
892 /* unmute right and left channels for nodes 0x0a, 0xd */
893 { 0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
894 { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
898 static struct hda_verb stac925x_core_init[] = {
899 /* set dac0mux for dac converter */
900 { 0x06, AC_VERB_SET_CONNECT_SEL, 0x00},
904 static struct hda_verb stac922x_core_init[] = {
905 /* set master volume and direct control */
906 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
910 static struct hda_verb d965_core_init[] = {
911 /* set master volume and direct control */
912 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
913 /* unmute node 0x1b */
914 { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
915 /* select node 0x03 as DAC */
916 { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
920 static struct hda_verb stac927x_core_init[] = {
921 /* set master volume and direct control */
922 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
923 /* enable analog pc beep path */
924 { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
928 static struct hda_verb stac9205_core_init[] = {
929 /* set master volume and direct control */
930 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
931 /* enable analog pc beep path */
932 { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
936 #define STAC_MONO_MUX \
938 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
939 .name = "Mono Mux", \
940 .count = 1, \
941 .info = stac92xx_mono_mux_enum_info, \
942 .get = stac92xx_mono_mux_enum_get, \
943 .put = stac92xx_mono_mux_enum_put, \
946 #define STAC_AMP_MUX \
948 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
949 .name = "Amp Selector Capture Switch", \
950 .count = 1, \
951 .info = stac92xx_amp_mux_enum_info, \
952 .get = stac92xx_amp_mux_enum_get, \
953 .put = stac92xx_amp_mux_enum_put, \
956 #define STAC_AMP_VOL(xname, nid, chs, idx, dir) \
958 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
959 .name = xname, \
960 .index = 0, \
961 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
962 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
963 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
964 .info = stac92xx_amp_volume_info, \
965 .get = stac92xx_amp_volume_get, \
966 .put = stac92xx_amp_volume_put, \
967 .tlv = { .c = snd_hda_mixer_amp_tlv }, \
968 .private_value = HDA_COMPOSE_AMP_VAL(nid, chs, idx, dir) \
971 #define STAC_INPUT_SOURCE(cnt) \
973 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
974 .name = "Input Source", \
975 .count = cnt, \
976 .info = stac92xx_mux_enum_info, \
977 .get = stac92xx_mux_enum_get, \
978 .put = stac92xx_mux_enum_put, \
981 #define STAC_ANALOG_LOOPBACK(verb_read, verb_write, cnt) \
983 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
984 .name = "Analog Loopback", \
985 .count = cnt, \
986 .info = stac92xx_aloopback_info, \
987 .get = stac92xx_aloopback_get, \
988 .put = stac92xx_aloopback_put, \
989 .private_value = verb_read | (verb_write << 16), \
992 static struct snd_kcontrol_new stac9200_mixer[] = {
993 HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
994 HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
995 STAC_INPUT_SOURCE(1),
996 HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
997 HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
998 { } /* end */
1001 #define DELL_M6_MIXER 6
1002 static struct snd_kcontrol_new stac92hd73xx_6ch_mixer[] = {
1003 /* start of config #1 */
1004 HDA_CODEC_VOLUME("Front Mic Mixer Capture Volume", 0x1d, 0, HDA_INPUT),
1005 HDA_CODEC_MUTE("Front Mic Mixer Capture Switch", 0x1d, 0, HDA_INPUT),
1007 HDA_CODEC_VOLUME("Line In Mixer Capture Volume", 0x1d, 0x2, HDA_INPUT),
1008 HDA_CODEC_MUTE("Line In Mixer Capture Switch", 0x1d, 0x2, HDA_INPUT),
1010 HDA_CODEC_VOLUME("CD Mixer Capture Volume", 0x1d, 0x4, HDA_INPUT),
1011 HDA_CODEC_MUTE("CD Mixer Capture Switch", 0x1d, 0x4, HDA_INPUT),
1013 /* start of config #2 */
1014 HDA_CODEC_VOLUME("Mic Mixer Capture Volume", 0x1d, 0x1, HDA_INPUT),
1015 HDA_CODEC_MUTE("Mic Mixer Capture Switch", 0x1d, 0x1, HDA_INPUT),
1017 HDA_CODEC_VOLUME("DAC Mixer Capture Volume", 0x1d, 0x3, HDA_INPUT),
1018 HDA_CODEC_MUTE("DAC Mixer Capture Switch", 0x1d, 0x3, HDA_INPUT),
1020 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 3),
1022 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x20, 0x0, HDA_OUTPUT),
1023 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x20, 0x0, HDA_OUTPUT),
1025 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x21, 0x0, HDA_OUTPUT),
1026 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x21, 0x0, HDA_OUTPUT),
1028 { } /* end */
1031 static struct snd_kcontrol_new stac92hd73xx_8ch_mixer[] = {
1032 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 4),
1034 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x20, 0x0, HDA_OUTPUT),
1035 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x20, 0x0, HDA_OUTPUT),
1037 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x21, 0x0, HDA_OUTPUT),
1038 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x21, 0x0, HDA_OUTPUT),
1040 HDA_CODEC_VOLUME("Front Mic Mixer Capture Volume", 0x1d, 0, HDA_INPUT),
1041 HDA_CODEC_MUTE("Front Mic Mixer Capture Switch", 0x1d, 0, HDA_INPUT),
1043 HDA_CODEC_VOLUME("Mic Mixer Capture Volume", 0x1d, 0x1, HDA_INPUT),
1044 HDA_CODEC_MUTE("Mic Mixer Capture Switch", 0x1d, 0x1, HDA_INPUT),
1046 HDA_CODEC_VOLUME("Line In Mixer Capture Volume", 0x1d, 0x2, HDA_INPUT),
1047 HDA_CODEC_MUTE("Line In Mixer Capture Switch", 0x1d, 0x2, HDA_INPUT),
1049 HDA_CODEC_VOLUME("DAC Mixer Capture Volume", 0x1d, 0x3, HDA_INPUT),
1050 HDA_CODEC_MUTE("DAC Mixer Capture Switch", 0x1d, 0x3, HDA_INPUT),
1052 HDA_CODEC_VOLUME("CD Mixer Capture Volume", 0x1d, 0x4, HDA_INPUT),
1053 HDA_CODEC_MUTE("CD Mixer Capture Switch", 0x1d, 0x4, HDA_INPUT),
1054 { } /* end */
1057 static struct snd_kcontrol_new stac92hd73xx_10ch_mixer[] = {
1058 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 5),
1060 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x20, 0x0, HDA_OUTPUT),
1061 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x20, 0x0, HDA_OUTPUT),
1063 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x21, 0x0, HDA_OUTPUT),
1064 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x21, 0x0, HDA_OUTPUT),
1066 HDA_CODEC_VOLUME("Front Mic Mixer Capture Volume", 0x1d, 0, HDA_INPUT),
1067 HDA_CODEC_MUTE("Front Mic Mixer Capture Switch", 0x1d, 0, HDA_INPUT),
1069 HDA_CODEC_VOLUME("Mic Mixer Capture Volume", 0x1d, 0x1, HDA_INPUT),
1070 HDA_CODEC_MUTE("Mic Mixer Capture Switch", 0x1d, 0x1, HDA_INPUT),
1072 HDA_CODEC_VOLUME("Line In Mixer Capture Volume", 0x1d, 0x2, HDA_INPUT),
1073 HDA_CODEC_MUTE("Line In Mixer Capture Switch", 0x1d, 0x2, HDA_INPUT),
1075 HDA_CODEC_VOLUME("DAC Mixer Capture Volume", 0x1d, 0x3, HDA_INPUT),
1076 HDA_CODEC_MUTE("DAC Mixer Capture Switch", 0x1d, 0x3, HDA_INPUT),
1078 HDA_CODEC_VOLUME("CD Mixer Capture Volume", 0x1d, 0x4, HDA_INPUT),
1079 HDA_CODEC_MUTE("CD Mixer Capture Switch", 0x1d, 0x4, HDA_INPUT),
1080 { } /* end */
1084 static struct snd_kcontrol_new stac92hd83xxx_mixer[] = {
1085 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x17, 0x0, HDA_OUTPUT),
1086 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x17, 0x0, HDA_OUTPUT),
1088 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x18, 0x0, HDA_OUTPUT),
1089 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x18, 0x0, HDA_OUTPUT),
1091 HDA_CODEC_VOLUME("DAC0 Capture Volume", 0x1b, 0, HDA_INPUT),
1092 HDA_CODEC_MUTE("DAC0 Capture Switch", 0x1b, 0, HDA_INPUT),
1094 HDA_CODEC_VOLUME("DAC1 Capture Volume", 0x1b, 0x1, HDA_INPUT),
1095 HDA_CODEC_MUTE("DAC1 Capture Switch", 0x1b, 0x1, HDA_INPUT),
1097 HDA_CODEC_VOLUME("Front Mic Capture Volume", 0x1b, 0x2, HDA_INPUT),
1098 HDA_CODEC_MUTE("Front Mic Capture Switch", 0x1b, 0x2, HDA_INPUT),
1100 HDA_CODEC_VOLUME("Line In Capture Volume", 0x1b, 0x3, HDA_INPUT),
1101 HDA_CODEC_MUTE("Line In Capture Switch", 0x1b, 0x3, HDA_INPUT),
1104 HDA_CODEC_VOLUME("Mic Capture Volume", 0x1b, 0x4, HDA_INPUT),
1105 HDA_CODEC_MUTE("Mic Capture Switch", 0x1b 0x4, HDA_INPUT),
1107 { } /* end */
1110 static struct snd_kcontrol_new stac92hd71bxx_analog_mixer[] = {
1111 STAC_INPUT_SOURCE(2),
1112 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A0, 2),
1114 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1c, 0x0, HDA_OUTPUT),
1115 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1c, 0x0, HDA_OUTPUT),
1117 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x1d, 0x0, HDA_OUTPUT),
1118 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1d, 0x0, HDA_OUTPUT),
1119 /* analog pc-beep replaced with digital beep support */
1121 HDA_CODEC_VOLUME("PC Beep Volume", 0x17, 0x2, HDA_INPUT),
1122 HDA_CODEC_MUTE("PC Beep Switch", 0x17, 0x2, HDA_INPUT),
1125 HDA_CODEC_MUTE("Import0 Mux Capture Switch", 0x17, 0x0, HDA_INPUT),
1126 HDA_CODEC_VOLUME("Import0 Mux Capture Volume", 0x17, 0x0, HDA_INPUT),
1128 HDA_CODEC_MUTE("Import1 Mux Capture Switch", 0x17, 0x1, HDA_INPUT),
1129 HDA_CODEC_VOLUME("Import1 Mux Capture Volume", 0x17, 0x1, HDA_INPUT),
1131 HDA_CODEC_MUTE("DAC0 Capture Switch", 0x17, 0x3, HDA_INPUT),
1132 HDA_CODEC_VOLUME("DAC0 Capture Volume", 0x17, 0x3, HDA_INPUT),
1134 HDA_CODEC_MUTE("DAC1 Capture Switch", 0x17, 0x4, HDA_INPUT),
1135 HDA_CODEC_VOLUME("DAC1 Capture Volume", 0x17, 0x4, HDA_INPUT),
1136 { } /* end */
1139 static struct snd_kcontrol_new stac92hd71bxx_mixer[] = {
1140 STAC_INPUT_SOURCE(2),
1141 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A0, 2),
1143 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1c, 0x0, HDA_OUTPUT),
1144 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1c, 0x0, HDA_OUTPUT),
1146 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x1d, 0x0, HDA_OUTPUT),
1147 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1d, 0x0, HDA_OUTPUT),
1148 { } /* end */
1151 static struct snd_kcontrol_new stac925x_mixer[] = {
1152 STAC_INPUT_SOURCE(1),
1153 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_OUTPUT),
1154 HDA_CODEC_MUTE("Capture Switch", 0x14, 0, HDA_OUTPUT),
1155 { } /* end */
1158 static struct snd_kcontrol_new stac9205_mixer[] = {
1159 STAC_INPUT_SOURCE(2),
1160 STAC_ANALOG_LOOPBACK(0xFE0, 0x7E0, 1),
1162 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1b, 0x0, HDA_INPUT),
1163 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1d, 0x0, HDA_OUTPUT),
1165 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x1c, 0x0, HDA_INPUT),
1166 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1e, 0x0, HDA_OUTPUT),
1167 { } /* end */
1170 /* This needs to be generated dynamically based on sequence */
1171 static struct snd_kcontrol_new stac922x_mixer[] = {
1172 STAC_INPUT_SOURCE(2),
1173 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x17, 0x0, HDA_INPUT),
1174 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x17, 0x0, HDA_INPUT),
1176 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x18, 0x0, HDA_INPUT),
1177 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x18, 0x0, HDA_INPUT),
1178 { } /* end */
1182 static struct snd_kcontrol_new stac927x_mixer[] = {
1183 STAC_INPUT_SOURCE(3),
1184 STAC_ANALOG_LOOPBACK(0xFEB, 0x7EB, 1),
1186 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x18, 0x0, HDA_INPUT),
1187 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1b, 0x0, HDA_OUTPUT),
1189 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x19, 0x0, HDA_INPUT),
1190 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1c, 0x0, HDA_OUTPUT),
1192 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x2, 0x1A, 0x0, HDA_INPUT),
1193 HDA_CODEC_MUTE_IDX("Capture Switch", 0x2, 0x1d, 0x0, HDA_OUTPUT),
1194 { } /* end */
1197 static struct snd_kcontrol_new stac_dmux_mixer = {
1198 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1199 .name = "Digital Input Source",
1200 /* count set later */
1201 .info = stac92xx_dmux_enum_info,
1202 .get = stac92xx_dmux_enum_get,
1203 .put = stac92xx_dmux_enum_put,
1206 static struct snd_kcontrol_new stac_smux_mixer = {
1207 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1208 .name = "IEC958 Playback Source",
1209 /* count set later */
1210 .info = stac92xx_smux_enum_info,
1211 .get = stac92xx_smux_enum_get,
1212 .put = stac92xx_smux_enum_put,
1215 static const char *slave_vols[] = {
1216 "Front Playback Volume",
1217 "Surround Playback Volume",
1218 "Center Playback Volume",
1219 "LFE Playback Volume",
1220 "Side Playback Volume",
1221 "Headphone Playback Volume",
1222 "Headphone Playback Volume",
1223 "Speaker Playback Volume",
1224 "External Speaker Playback Volume",
1225 "Speaker2 Playback Volume",
1226 NULL
1229 static const char *slave_sws[] = {
1230 "Front Playback Switch",
1231 "Surround Playback Switch",
1232 "Center Playback Switch",
1233 "LFE Playback Switch",
1234 "Side Playback Switch",
1235 "Headphone Playback Switch",
1236 "Headphone Playback Switch",
1237 "Speaker Playback Switch",
1238 "External Speaker Playback Switch",
1239 "Speaker2 Playback Switch",
1240 "IEC958 Playback Switch",
1241 NULL
1244 static int stac92xx_build_controls(struct hda_codec *codec)
1246 struct sigmatel_spec *spec = codec->spec;
1247 int err;
1248 int i;
1250 err = snd_hda_add_new_ctls(codec, spec->mixer);
1251 if (err < 0)
1252 return err;
1254 for (i = 0; i < spec->num_mixers; i++) {
1255 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1256 if (err < 0)
1257 return err;
1259 if (spec->num_dmuxes > 0) {
1260 stac_dmux_mixer.count = spec->num_dmuxes;
1261 err = snd_ctl_add(codec->bus->card,
1262 snd_ctl_new1(&stac_dmux_mixer, codec));
1263 if (err < 0)
1264 return err;
1266 if (spec->num_smuxes > 0) {
1267 int wcaps = get_wcaps(codec, spec->multiout.dig_out_nid);
1268 struct hda_input_mux *smux = &spec->private_smux;
1269 /* check for mute support on SPDIF out */
1270 if (wcaps & AC_WCAP_OUT_AMP) {
1271 smux->items[smux->num_items].label = "Off";
1272 smux->items[smux->num_items].index = 0;
1273 smux->num_items++;
1274 spec->spdif_mute = 1;
1276 stac_smux_mixer.count = spec->num_smuxes;
1277 err = snd_ctl_add(codec->bus->card,
1278 snd_ctl_new1(&stac_smux_mixer, codec));
1279 if (err < 0)
1280 return err;
1283 if (spec->multiout.dig_out_nid) {
1284 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
1285 if (err < 0)
1286 return err;
1287 err = snd_hda_create_spdif_share_sw(codec,
1288 &spec->multiout);
1289 if (err < 0)
1290 return err;
1291 spec->multiout.share_spdif = 1;
1293 if (spec->dig_in_nid && !(spec->gpio_dir & 0x01)) {
1294 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1295 if (err < 0)
1296 return err;
1299 /* if we have no master control, let's create it */
1300 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
1301 unsigned int vmaster_tlv[4];
1302 snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0],
1303 HDA_OUTPUT, vmaster_tlv);
1304 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
1305 vmaster_tlv, slave_vols);
1306 if (err < 0)
1307 return err;
1309 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1310 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1311 NULL, slave_sws);
1312 if (err < 0)
1313 return err;
1316 return 0;
1319 static unsigned int ref9200_pin_configs[8] = {
1320 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
1321 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
1325 STAC 9200 pin configs for
1326 102801A8
1327 102801DE
1328 102801E8
1330 static unsigned int dell9200_d21_pin_configs[8] = {
1331 0x400001f0, 0x400001f1, 0x02214030, 0x01014010,
1332 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
1336 STAC 9200 pin configs for
1337 102801C0
1338 102801C1
1340 static unsigned int dell9200_d22_pin_configs[8] = {
1341 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
1342 0x01813020, 0x02a19021, 0x90100140, 0x400001f2,
1346 STAC 9200 pin configs for
1347 102801C4 (Dell Dimension E310)
1348 102801C5
1349 102801C7
1350 102801D9
1351 102801DA
1352 102801E3
1354 static unsigned int dell9200_d23_pin_configs[8] = {
1355 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
1356 0x01813020, 0x01a19021, 0x90100140, 0x400001f2,
1361 STAC 9200-32 pin configs for
1362 102801B5 (Dell Inspiron 630m)
1363 102801D8 (Dell Inspiron 640m)
1365 static unsigned int dell9200_m21_pin_configs[8] = {
1366 0x40c003fa, 0x03441340, 0x0321121f, 0x90170310,
1367 0x408003fb, 0x03a11020, 0x401003fc, 0x403003fd,
1371 STAC 9200-32 pin configs for
1372 102801C2 (Dell Latitude D620)
1373 102801C8
1374 102801CC (Dell Latitude D820)
1375 102801D4
1376 102801D6
1378 static unsigned int dell9200_m22_pin_configs[8] = {
1379 0x40c003fa, 0x0144131f, 0x0321121f, 0x90170310,
1380 0x90a70321, 0x03a11020, 0x401003fb, 0x40f000fc,
1384 STAC 9200-32 pin configs for
1385 102801CE (Dell XPS M1710)
1386 102801CF (Dell Precision M90)
1388 static unsigned int dell9200_m23_pin_configs[8] = {
1389 0x40c003fa, 0x01441340, 0x0421421f, 0x90170310,
1390 0x408003fb, 0x04a1102e, 0x90170311, 0x403003fc,
1394 STAC 9200-32 pin configs for
1395 102801C9
1396 102801CA
1397 102801CB (Dell Latitude 120L)
1398 102801D3
1400 static unsigned int dell9200_m24_pin_configs[8] = {
1401 0x40c003fa, 0x404003fb, 0x0321121f, 0x90170310,
1402 0x408003fc, 0x03a11020, 0x401003fd, 0x403003fe,
1406 STAC 9200-32 pin configs for
1407 102801BD (Dell Inspiron E1505n)
1408 102801EE
1409 102801EF
1411 static unsigned int dell9200_m25_pin_configs[8] = {
1412 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
1413 0x408003fb, 0x04a11020, 0x401003fc, 0x403003fd,
1417 STAC 9200-32 pin configs for
1418 102801F5 (Dell Inspiron 1501)
1419 102801F6
1421 static unsigned int dell9200_m26_pin_configs[8] = {
1422 0x40c003fa, 0x404003fb, 0x0421121f, 0x90170310,
1423 0x408003fc, 0x04a11020, 0x401003fd, 0x403003fe,
1427 STAC 9200-32
1428 102801CD (Dell Inspiron E1705/9400)
1430 static unsigned int dell9200_m27_pin_configs[8] = {
1431 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
1432 0x90170310, 0x04a11020, 0x90170310, 0x40f003fc,
1435 static unsigned int oqo9200_pin_configs[8] = {
1436 0x40c000f0, 0x404000f1, 0x0221121f, 0x02211210,
1437 0x90170111, 0x90a70120, 0x400000f2, 0x400000f3,
1441 static unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
1442 [STAC_REF] = ref9200_pin_configs,
1443 [STAC_9200_OQO] = oqo9200_pin_configs,
1444 [STAC_9200_DELL_D21] = dell9200_d21_pin_configs,
1445 [STAC_9200_DELL_D22] = dell9200_d22_pin_configs,
1446 [STAC_9200_DELL_D23] = dell9200_d23_pin_configs,
1447 [STAC_9200_DELL_M21] = dell9200_m21_pin_configs,
1448 [STAC_9200_DELL_M22] = dell9200_m22_pin_configs,
1449 [STAC_9200_DELL_M23] = dell9200_m23_pin_configs,
1450 [STAC_9200_DELL_M24] = dell9200_m24_pin_configs,
1451 [STAC_9200_DELL_M25] = dell9200_m25_pin_configs,
1452 [STAC_9200_DELL_M26] = dell9200_m26_pin_configs,
1453 [STAC_9200_DELL_M27] = dell9200_m27_pin_configs,
1454 [STAC_9200_PANASONIC] = ref9200_pin_configs,
1457 static const char *stac9200_models[STAC_9200_MODELS] = {
1458 [STAC_REF] = "ref",
1459 [STAC_9200_OQO] = "oqo",
1460 [STAC_9200_DELL_D21] = "dell-d21",
1461 [STAC_9200_DELL_D22] = "dell-d22",
1462 [STAC_9200_DELL_D23] = "dell-d23",
1463 [STAC_9200_DELL_M21] = "dell-m21",
1464 [STAC_9200_DELL_M22] = "dell-m22",
1465 [STAC_9200_DELL_M23] = "dell-m23",
1466 [STAC_9200_DELL_M24] = "dell-m24",
1467 [STAC_9200_DELL_M25] = "dell-m25",
1468 [STAC_9200_DELL_M26] = "dell-m26",
1469 [STAC_9200_DELL_M27] = "dell-m27",
1470 [STAC_9200_GATEWAY] = "gateway",
1471 [STAC_9200_PANASONIC] = "panasonic",
1474 static struct snd_pci_quirk stac9200_cfg_tbl[] = {
1475 /* SigmaTel reference board */
1476 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1477 "DFI LanParty", STAC_REF),
1478 /* Dell laptops have BIOS problem */
1479 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a8,
1480 "unknown Dell", STAC_9200_DELL_D21),
1481 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01b5,
1482 "Dell Inspiron 630m", STAC_9200_DELL_M21),
1483 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bd,
1484 "Dell Inspiron E1505n", STAC_9200_DELL_M25),
1485 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c0,
1486 "unknown Dell", STAC_9200_DELL_D22),
1487 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c1,
1488 "unknown Dell", STAC_9200_DELL_D22),
1489 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c2,
1490 "Dell Latitude D620", STAC_9200_DELL_M22),
1491 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c5,
1492 "unknown Dell", STAC_9200_DELL_D23),
1493 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c7,
1494 "unknown Dell", STAC_9200_DELL_D23),
1495 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c8,
1496 "unknown Dell", STAC_9200_DELL_M22),
1497 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c9,
1498 "unknown Dell", STAC_9200_DELL_M24),
1499 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ca,
1500 "unknown Dell", STAC_9200_DELL_M24),
1501 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cb,
1502 "Dell Latitude 120L", STAC_9200_DELL_M24),
1503 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cc,
1504 "Dell Latitude D820", STAC_9200_DELL_M22),
1505 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cd,
1506 "Dell Inspiron E1705/9400", STAC_9200_DELL_M27),
1507 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ce,
1508 "Dell XPS M1710", STAC_9200_DELL_M23),
1509 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cf,
1510 "Dell Precision M90", STAC_9200_DELL_M23),
1511 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d3,
1512 "unknown Dell", STAC_9200_DELL_M22),
1513 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d4,
1514 "unknown Dell", STAC_9200_DELL_M22),
1515 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d6,
1516 "unknown Dell", STAC_9200_DELL_M22),
1517 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d8,
1518 "Dell Inspiron 640m", STAC_9200_DELL_M21),
1519 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d9,
1520 "unknown Dell", STAC_9200_DELL_D23),
1521 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01da,
1522 "unknown Dell", STAC_9200_DELL_D23),
1523 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01de,
1524 "unknown Dell", STAC_9200_DELL_D21),
1525 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e3,
1526 "unknown Dell", STAC_9200_DELL_D23),
1527 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e8,
1528 "unknown Dell", STAC_9200_DELL_D21),
1529 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ee,
1530 "unknown Dell", STAC_9200_DELL_M25),
1531 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ef,
1532 "unknown Dell", STAC_9200_DELL_M25),
1533 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f5,
1534 "Dell Inspiron 1501", STAC_9200_DELL_M26),
1535 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f6,
1536 "unknown Dell", STAC_9200_DELL_M26),
1537 /* Panasonic */
1538 SND_PCI_QUIRK(0x10f7, 0x8338, "Panasonic CF-74", STAC_9200_PANASONIC),
1539 /* Gateway machines needs EAPD to be set on resume */
1540 SND_PCI_QUIRK(0x107b, 0x0205, "Gateway S-7110M", STAC_9200_GATEWAY),
1541 SND_PCI_QUIRK(0x107b, 0x0317, "Gateway MT3423, MX341*",
1542 STAC_9200_GATEWAY),
1543 SND_PCI_QUIRK(0x107b, 0x0318, "Gateway ML3019, MT3707",
1544 STAC_9200_GATEWAY),
1545 /* OQO Mobile */
1546 SND_PCI_QUIRK(0x1106, 0x3288, "OQO Model 2", STAC_9200_OQO),
1547 {} /* terminator */
1550 static unsigned int ref925x_pin_configs[8] = {
1551 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
1552 0x90a70320, 0x02214210, 0x01019020, 0x9033032e,
1555 static unsigned int stac925x_MA6_pin_configs[8] = {
1556 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
1557 0x90a70320, 0x90100211, 0x400003f1, 0x9033032e,
1560 static unsigned int stac925x_PA6_pin_configs[8] = {
1561 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
1562 0x50a103f0, 0x90100211, 0x400003f1, 0x9033032e,
1565 static unsigned int stac925xM2_2_pin_configs[8] = {
1566 0x40c003f3, 0x424503f2, 0x04180011, 0x02a19020,
1567 0x50a103f0, 0x90100212, 0x400003f1, 0x9033032e,
1570 static unsigned int *stac925x_brd_tbl[STAC_925x_MODELS] = {
1571 [STAC_REF] = ref925x_pin_configs,
1572 [STAC_M2_2] = stac925xM2_2_pin_configs,
1573 [STAC_MA6] = stac925x_MA6_pin_configs,
1574 [STAC_PA6] = stac925x_PA6_pin_configs,
1577 static const char *stac925x_models[STAC_925x_MODELS] = {
1578 [STAC_REF] = "ref",
1579 [STAC_M2_2] = "m2-2",
1580 [STAC_MA6] = "m6",
1581 [STAC_PA6] = "pa6",
1584 static struct snd_pci_quirk stac925x_cfg_tbl[] = {
1585 /* SigmaTel reference board */
1586 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, "DFI LanParty", STAC_REF),
1587 SND_PCI_QUIRK(0x8384, 0x7632, "Stac9202 Reference Board", STAC_REF),
1588 SND_PCI_QUIRK(0x107b, 0x0316, "Gateway M255", STAC_REF),
1589 SND_PCI_QUIRK(0x107b, 0x0366, "Gateway MP6954", STAC_REF),
1590 SND_PCI_QUIRK(0x107b, 0x0461, "Gateway NX560XL", STAC_MA6),
1591 SND_PCI_QUIRK(0x107b, 0x0681, "Gateway NX860", STAC_PA6),
1592 SND_PCI_QUIRK(0x1002, 0x437b, "Gateway MX6453", STAC_M2_2),
1593 {} /* terminator */
1596 static unsigned int ref92hd73xx_pin_configs[13] = {
1597 0x02214030, 0x02a19040, 0x01a19020, 0x02214030,
1598 0x0181302e, 0x01014010, 0x01014020, 0x01014030,
1599 0x02319040, 0x90a000f0, 0x90a000f0, 0x01452050,
1600 0x01452050,
1603 static unsigned int dell_m6_pin_configs[13] = {
1604 0x0321101f, 0x4f00000f, 0x4f0000f0, 0x90170110,
1605 0x03a11020, 0x0321101f, 0x4f0000f0, 0x4f0000f0,
1606 0x4f0000f0, 0x90a60160, 0x4f0000f0, 0x4f0000f0,
1607 0x4f0000f0,
1610 static unsigned int *stac92hd73xx_brd_tbl[STAC_92HD73XX_MODELS] = {
1611 [STAC_92HD73XX_REF] = ref92hd73xx_pin_configs,
1612 [STAC_DELL_M6_AMIC] = dell_m6_pin_configs,
1613 [STAC_DELL_M6_DMIC] = dell_m6_pin_configs,
1614 [STAC_DELL_M6_BOTH] = dell_m6_pin_configs,
1615 [STAC_DELL_EQ] = dell_m6_pin_configs,
1618 static const char *stac92hd73xx_models[STAC_92HD73XX_MODELS] = {
1619 [STAC_92HD73XX_NO_JD] = "no-jd",
1620 [STAC_92HD73XX_REF] = "ref",
1621 [STAC_DELL_M6_AMIC] = "dell-m6-amic",
1622 [STAC_DELL_M6_DMIC] = "dell-m6-dmic",
1623 [STAC_DELL_M6_BOTH] = "dell-m6",
1624 [STAC_DELL_EQ] = "dell-eq",
1627 static struct snd_pci_quirk stac92hd73xx_cfg_tbl[] = {
1628 /* SigmaTel reference board */
1629 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1630 "DFI LanParty", STAC_92HD73XX_REF),
1631 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0254,
1632 "Dell Studio 1535", STAC_DELL_M6_DMIC),
1633 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0255,
1634 "unknown Dell", STAC_DELL_M6_DMIC),
1635 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0256,
1636 "unknown Dell", STAC_DELL_M6_BOTH),
1637 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0257,
1638 "unknown Dell", STAC_DELL_M6_BOTH),
1639 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025e,
1640 "unknown Dell", STAC_DELL_M6_AMIC),
1641 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025f,
1642 "unknown Dell", STAC_DELL_M6_AMIC),
1643 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0271,
1644 "unknown Dell", STAC_DELL_M6_DMIC),
1645 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0272,
1646 "unknown Dell", STAC_DELL_M6_DMIC),
1647 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x029f,
1648 "Dell Studio 1537", STAC_DELL_M6_DMIC),
1649 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02a0,
1650 "Dell Studio 17", STAC_DELL_M6_DMIC),
1651 {} /* terminator */
1654 static unsigned int ref92hd83xxx_pin_configs[14] = {
1655 0x02214030, 0x02211010, 0x02a19020, 0x02170130,
1656 0x01014050, 0x01819040, 0x01014020, 0x90a3014e,
1657 0x40f000f0, 0x40f000f0, 0x40f000f0, 0x40f000f0,
1658 0x01451160, 0x98560170,
1661 static unsigned int *stac92hd83xxx_brd_tbl[STAC_92HD83XXX_MODELS] = {
1662 [STAC_92HD83XXX_REF] = ref92hd83xxx_pin_configs,
1665 static const char *stac92hd83xxx_models[STAC_92HD83XXX_MODELS] = {
1666 [STAC_92HD83XXX_REF] = "ref",
1669 static struct snd_pci_quirk stac92hd83xxx_cfg_tbl[] = {
1670 /* SigmaTel reference board */
1671 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1672 "DFI LanParty", STAC_92HD71BXX_REF),
1673 {} /* terminator */
1676 static unsigned int ref92hd71bxx_pin_configs[11] = {
1677 0x02214030, 0x02a19040, 0x01a19020, 0x01014010,
1678 0x0181302e, 0x01014010, 0x01019020, 0x90a000f0,
1679 0x90a000f0, 0x01452050, 0x01452050,
1682 static unsigned int dell_m4_1_pin_configs[11] = {
1683 0x0421101f, 0x04a11221, 0x40f000f0, 0x90170110,
1684 0x23a1902e, 0x23014250, 0x40f000f0, 0x90a000f0,
1685 0x40f000f0, 0x4f0000f0, 0x4f0000f0,
1688 static unsigned int dell_m4_2_pin_configs[11] = {
1689 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1690 0x23a1902e, 0x23014250, 0x40f000f0, 0x40f000f0,
1691 0x40f000f0, 0x044413b0, 0x044413b0,
1694 static unsigned int dell_m4_3_pin_configs[11] = {
1695 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1696 0x40f000f0, 0x40f000f0, 0x40f000f0, 0x90a000f0,
1697 0x40f000f0, 0x044413b0, 0x044413b0,
1700 static unsigned int *stac92hd71bxx_brd_tbl[STAC_92HD71BXX_MODELS] = {
1701 [STAC_92HD71BXX_REF] = ref92hd71bxx_pin_configs,
1702 [STAC_DELL_M4_1] = dell_m4_1_pin_configs,
1703 [STAC_DELL_M4_2] = dell_m4_2_pin_configs,
1704 [STAC_DELL_M4_3] = dell_m4_3_pin_configs,
1705 [STAC_HP_M4] = NULL,
1706 [STAC_HP_DV5] = NULL,
1709 static const char *stac92hd71bxx_models[STAC_92HD71BXX_MODELS] = {
1710 [STAC_92HD71BXX_REF] = "ref",
1711 [STAC_DELL_M4_1] = "dell-m4-1",
1712 [STAC_DELL_M4_2] = "dell-m4-2",
1713 [STAC_DELL_M4_3] = "dell-m4-3",
1714 [STAC_HP_M4] = "hp-m4",
1715 [STAC_HP_DV5] = "hp-dv5",
1718 static struct snd_pci_quirk stac92hd71bxx_cfg_tbl[] = {
1719 /* SigmaTel reference board */
1720 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1721 "DFI LanParty", STAC_92HD71BXX_REF),
1722 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x30f2,
1723 "HP dv5", STAC_HP_M4),
1724 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x30f4,
1725 "HP dv7", STAC_HP_M4),
1726 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x30fc,
1727 "HP dv7", STAC_HP_M4),
1728 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3603,
1729 "HP dv5", STAC_HP_DV5),
1730 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361a,
1731 "unknown HP", STAC_HP_M4),
1732 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0233,
1733 "unknown Dell", STAC_DELL_M4_1),
1734 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0234,
1735 "unknown Dell", STAC_DELL_M4_1),
1736 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0250,
1737 "unknown Dell", STAC_DELL_M4_1),
1738 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024f,
1739 "unknown Dell", STAC_DELL_M4_1),
1740 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024d,
1741 "unknown Dell", STAC_DELL_M4_1),
1742 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0251,
1743 "unknown Dell", STAC_DELL_M4_1),
1744 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0277,
1745 "unknown Dell", STAC_DELL_M4_1),
1746 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0263,
1747 "unknown Dell", STAC_DELL_M4_2),
1748 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0265,
1749 "unknown Dell", STAC_DELL_M4_2),
1750 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0262,
1751 "unknown Dell", STAC_DELL_M4_2),
1752 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0264,
1753 "unknown Dell", STAC_DELL_M4_2),
1754 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02aa,
1755 "unknown Dell", STAC_DELL_M4_3),
1756 {} /* terminator */
1759 static unsigned int ref922x_pin_configs[10] = {
1760 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
1761 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
1762 0x40000100, 0x40000100,
1766 STAC 922X pin configs for
1767 102801A7
1768 102801AB
1769 102801A9
1770 102801D1
1771 102801D2
1773 static unsigned int dell_922x_d81_pin_configs[10] = {
1774 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1775 0x02a19020, 0x01117011, 0x400001f0, 0x400001f1,
1776 0x01813122, 0x400001f2,
1780 STAC 922X pin configs for
1781 102801AC
1782 102801D0
1784 static unsigned int dell_922x_d82_pin_configs[10] = {
1785 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1786 0x02a19020, 0x01117011, 0x01451140, 0x400001f0,
1787 0x01813122, 0x400001f1,
1791 STAC 922X pin configs for
1792 102801BF
1794 static unsigned int dell_922x_m81_pin_configs[10] = {
1795 0x0321101f, 0x01112024, 0x01111222, 0x91174220,
1796 0x03a11050, 0x01116221, 0x90a70330, 0x01452340,
1797 0x40C003f1, 0x405003f0,
1801 STAC 9221 A1 pin configs for
1802 102801D7 (Dell XPS M1210)
1804 static unsigned int dell_922x_m82_pin_configs[10] = {
1805 0x02211211, 0x408103ff, 0x02a1123e, 0x90100310,
1806 0x408003f1, 0x0221121f, 0x03451340, 0x40c003f2,
1807 0x508003f3, 0x405003f4,
1810 static unsigned int d945gtp3_pin_configs[10] = {
1811 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
1812 0x40000100, 0x40000100, 0x40000100, 0x40000100,
1813 0x02a19120, 0x40000100,
1816 static unsigned int d945gtp5_pin_configs[10] = {
1817 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
1818 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
1819 0x02a19320, 0x40000100,
1822 static unsigned int intel_mac_v1_pin_configs[10] = {
1823 0x0121e21f, 0x400000ff, 0x9017e110, 0x400000fd,
1824 0x400000fe, 0x0181e020, 0x1145e030, 0x11c5e240,
1825 0x400000fc, 0x400000fb,
1828 static unsigned int intel_mac_v2_pin_configs[10] = {
1829 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
1830 0x400000fe, 0x0181e020, 0x1145e230, 0x500000fa,
1831 0x400000fc, 0x400000fb,
1834 static unsigned int intel_mac_v3_pin_configs[10] = {
1835 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
1836 0x400000fe, 0x0181e020, 0x1145e230, 0x11c5e240,
1837 0x400000fc, 0x400000fb,
1840 static unsigned int intel_mac_v4_pin_configs[10] = {
1841 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
1842 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
1843 0x400000fc, 0x400000fb,
1846 static unsigned int intel_mac_v5_pin_configs[10] = {
1847 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
1848 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
1849 0x400000fc, 0x400000fb,
1852 static unsigned int ecs202_pin_configs[10] = {
1853 0x0221401f, 0x02a19020, 0x01a19020, 0x01114010,
1854 0x408000f0, 0x01813022, 0x074510a0, 0x40c400f1,
1855 0x9037012e, 0x40e000f2,
1858 static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
1859 [STAC_D945_REF] = ref922x_pin_configs,
1860 [STAC_D945GTP3] = d945gtp3_pin_configs,
1861 [STAC_D945GTP5] = d945gtp5_pin_configs,
1862 [STAC_INTEL_MAC_V1] = intel_mac_v1_pin_configs,
1863 [STAC_INTEL_MAC_V2] = intel_mac_v2_pin_configs,
1864 [STAC_INTEL_MAC_V3] = intel_mac_v3_pin_configs,
1865 [STAC_INTEL_MAC_V4] = intel_mac_v4_pin_configs,
1866 [STAC_INTEL_MAC_V5] = intel_mac_v5_pin_configs,
1867 [STAC_INTEL_MAC_AUTO] = intel_mac_v3_pin_configs,
1868 /* for backward compatibility */
1869 [STAC_MACMINI] = intel_mac_v3_pin_configs,
1870 [STAC_MACBOOK] = intel_mac_v5_pin_configs,
1871 [STAC_MACBOOK_PRO_V1] = intel_mac_v3_pin_configs,
1872 [STAC_MACBOOK_PRO_V2] = intel_mac_v3_pin_configs,
1873 [STAC_IMAC_INTEL] = intel_mac_v2_pin_configs,
1874 [STAC_IMAC_INTEL_20] = intel_mac_v3_pin_configs,
1875 [STAC_ECS_202] = ecs202_pin_configs,
1876 [STAC_922X_DELL_D81] = dell_922x_d81_pin_configs,
1877 [STAC_922X_DELL_D82] = dell_922x_d82_pin_configs,
1878 [STAC_922X_DELL_M81] = dell_922x_m81_pin_configs,
1879 [STAC_922X_DELL_M82] = dell_922x_m82_pin_configs,
1882 static const char *stac922x_models[STAC_922X_MODELS] = {
1883 [STAC_D945_REF] = "ref",
1884 [STAC_D945GTP5] = "5stack",
1885 [STAC_D945GTP3] = "3stack",
1886 [STAC_INTEL_MAC_V1] = "intel-mac-v1",
1887 [STAC_INTEL_MAC_V2] = "intel-mac-v2",
1888 [STAC_INTEL_MAC_V3] = "intel-mac-v3",
1889 [STAC_INTEL_MAC_V4] = "intel-mac-v4",
1890 [STAC_INTEL_MAC_V5] = "intel-mac-v5",
1891 [STAC_INTEL_MAC_AUTO] = "intel-mac-auto",
1892 /* for backward compatibility */
1893 [STAC_MACMINI] = "macmini",
1894 [STAC_MACBOOK] = "macbook",
1895 [STAC_MACBOOK_PRO_V1] = "macbook-pro-v1",
1896 [STAC_MACBOOK_PRO_V2] = "macbook-pro",
1897 [STAC_IMAC_INTEL] = "imac-intel",
1898 [STAC_IMAC_INTEL_20] = "imac-intel-20",
1899 [STAC_ECS_202] = "ecs202",
1900 [STAC_922X_DELL_D81] = "dell-d81",
1901 [STAC_922X_DELL_D82] = "dell-d82",
1902 [STAC_922X_DELL_M81] = "dell-m81",
1903 [STAC_922X_DELL_M82] = "dell-m82",
1906 static struct snd_pci_quirk stac922x_cfg_tbl[] = {
1907 /* SigmaTel reference board */
1908 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1909 "DFI LanParty", STAC_D945_REF),
1910 /* Intel 945G based systems */
1911 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101,
1912 "Intel D945G", STAC_D945GTP3),
1913 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0202,
1914 "Intel D945G", STAC_D945GTP3),
1915 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0606,
1916 "Intel D945G", STAC_D945GTP3),
1917 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0601,
1918 "Intel D945G", STAC_D945GTP3),
1919 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0111,
1920 "Intel D945G", STAC_D945GTP3),
1921 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1115,
1922 "Intel D945G", STAC_D945GTP3),
1923 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1116,
1924 "Intel D945G", STAC_D945GTP3),
1925 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1117,
1926 "Intel D945G", STAC_D945GTP3),
1927 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1118,
1928 "Intel D945G", STAC_D945GTP3),
1929 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1119,
1930 "Intel D945G", STAC_D945GTP3),
1931 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x8826,
1932 "Intel D945G", STAC_D945GTP3),
1933 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5049,
1934 "Intel D945G", STAC_D945GTP3),
1935 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5055,
1936 "Intel D945G", STAC_D945GTP3),
1937 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5048,
1938 "Intel D945G", STAC_D945GTP3),
1939 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0110,
1940 "Intel D945G", STAC_D945GTP3),
1941 /* Intel D945G 5-stack systems */
1942 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0404,
1943 "Intel D945G", STAC_D945GTP5),
1944 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0303,
1945 "Intel D945G", STAC_D945GTP5),
1946 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0013,
1947 "Intel D945G", STAC_D945GTP5),
1948 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0417,
1949 "Intel D945G", STAC_D945GTP5),
1950 /* Intel 945P based systems */
1951 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0b0b,
1952 "Intel D945P", STAC_D945GTP3),
1953 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0112,
1954 "Intel D945P", STAC_D945GTP3),
1955 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0d0d,
1956 "Intel D945P", STAC_D945GTP3),
1957 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0909,
1958 "Intel D945P", STAC_D945GTP3),
1959 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0505,
1960 "Intel D945P", STAC_D945GTP3),
1961 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707,
1962 "Intel D945P", STAC_D945GTP5),
1963 /* other systems */
1964 /* Apple Intel Mac (Mac Mini, MacBook, MacBook Pro...) */
1965 SND_PCI_QUIRK(0x8384, 0x7680,
1966 "Mac", STAC_INTEL_MAC_AUTO),
1967 /* Dell systems */
1968 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a7,
1969 "unknown Dell", STAC_922X_DELL_D81),
1970 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a9,
1971 "unknown Dell", STAC_922X_DELL_D81),
1972 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ab,
1973 "unknown Dell", STAC_922X_DELL_D81),
1974 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ac,
1975 "unknown Dell", STAC_922X_DELL_D82),
1976 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bf,
1977 "unknown Dell", STAC_922X_DELL_M81),
1978 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d0,
1979 "unknown Dell", STAC_922X_DELL_D82),
1980 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d1,
1981 "unknown Dell", STAC_922X_DELL_D81),
1982 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d2,
1983 "unknown Dell", STAC_922X_DELL_D81),
1984 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d7,
1985 "Dell XPS M1210", STAC_922X_DELL_M82),
1986 /* ECS/PC Chips boards */
1987 SND_PCI_QUIRK(0x1019, 0x2144,
1988 "ECS/PC chips", STAC_ECS_202),
1989 SND_PCI_QUIRK(0x1019, 0x2608,
1990 "ECS/PC chips", STAC_ECS_202),
1991 SND_PCI_QUIRK(0x1019, 0x2633,
1992 "ECS/PC chips P17G/1333", STAC_ECS_202),
1993 SND_PCI_QUIRK(0x1019, 0x2811,
1994 "ECS/PC chips", STAC_ECS_202),
1995 SND_PCI_QUIRK(0x1019, 0x2812,
1996 "ECS/PC chips", STAC_ECS_202),
1997 SND_PCI_QUIRK(0x1019, 0x2813,
1998 "ECS/PC chips", STAC_ECS_202),
1999 SND_PCI_QUIRK(0x1019, 0x2814,
2000 "ECS/PC chips", STAC_ECS_202),
2001 SND_PCI_QUIRK(0x1019, 0x2815,
2002 "ECS/PC chips", STAC_ECS_202),
2003 SND_PCI_QUIRK(0x1019, 0x2816,
2004 "ECS/PC chips", STAC_ECS_202),
2005 SND_PCI_QUIRK(0x1019, 0x2817,
2006 "ECS/PC chips", STAC_ECS_202),
2007 SND_PCI_QUIRK(0x1019, 0x2818,
2008 "ECS/PC chips", STAC_ECS_202),
2009 SND_PCI_QUIRK(0x1019, 0x2819,
2010 "ECS/PC chips", STAC_ECS_202),
2011 SND_PCI_QUIRK(0x1019, 0x2820,
2012 "ECS/PC chips", STAC_ECS_202),
2013 {} /* terminator */
2016 static unsigned int ref927x_pin_configs[14] = {
2017 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2018 0x01a19040, 0x01011012, 0x01016011, 0x0101201f,
2019 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
2020 0x01c42190, 0x40000100,
2023 static unsigned int d965_3st_pin_configs[14] = {
2024 0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
2025 0x01a19021, 0x01813024, 0x40000100, 0x40000100,
2026 0x40000100, 0x40000100, 0x40000100, 0x40000100,
2027 0x40000100, 0x40000100
2030 static unsigned int d965_5st_pin_configs[14] = {
2031 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2032 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
2033 0x40000100, 0x40000100, 0x40000100, 0x01442070,
2034 0x40000100, 0x40000100
2037 static unsigned int dell_3st_pin_configs[14] = {
2038 0x02211230, 0x02a11220, 0x01a19040, 0x01114210,
2039 0x01111212, 0x01116211, 0x01813050, 0x01112214,
2040 0x403003fa, 0x90a60040, 0x90a60040, 0x404003fb,
2041 0x40c003fc, 0x40000100
2044 static unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
2045 [STAC_D965_REF_NO_JD] = ref927x_pin_configs,
2046 [STAC_D965_REF] = ref927x_pin_configs,
2047 [STAC_D965_3ST] = d965_3st_pin_configs,
2048 [STAC_D965_5ST] = d965_5st_pin_configs,
2049 [STAC_DELL_3ST] = dell_3st_pin_configs,
2050 [STAC_DELL_BIOS] = NULL,
2053 static const char *stac927x_models[STAC_927X_MODELS] = {
2054 [STAC_D965_REF_NO_JD] = "ref-no-jd",
2055 [STAC_D965_REF] = "ref",
2056 [STAC_D965_3ST] = "3stack",
2057 [STAC_D965_5ST] = "5stack",
2058 [STAC_DELL_3ST] = "dell-3stack",
2059 [STAC_DELL_BIOS] = "dell-bios",
2062 static struct snd_pci_quirk stac927x_cfg_tbl[] = {
2063 /* SigmaTel reference board */
2064 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2065 "DFI LanParty", STAC_D965_REF),
2066 /* Intel 946 based systems */
2067 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST),
2068 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST),
2069 /* 965 based 3 stack systems */
2070 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2116, "Intel D965", STAC_D965_3ST),
2071 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2115, "Intel D965", STAC_D965_3ST),
2072 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2114, "Intel D965", STAC_D965_3ST),
2073 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2113, "Intel D965", STAC_D965_3ST),
2074 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2112, "Intel D965", STAC_D965_3ST),
2075 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2111, "Intel D965", STAC_D965_3ST),
2076 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2110, "Intel D965", STAC_D965_3ST),
2077 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2009, "Intel D965", STAC_D965_3ST),
2078 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2008, "Intel D965", STAC_D965_3ST),
2079 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2007, "Intel D965", STAC_D965_3ST),
2080 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2006, "Intel D965", STAC_D965_3ST),
2081 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2005, "Intel D965", STAC_D965_3ST),
2082 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2004, "Intel D965", STAC_D965_3ST),
2083 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2003, "Intel D965", STAC_D965_3ST),
2084 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2002, "Intel D965", STAC_D965_3ST),
2085 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2001, "Intel D965", STAC_D965_3ST),
2086 /* Dell 3 stack systems */
2087 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f7, "Dell XPS M1730", STAC_DELL_3ST),
2088 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01dd, "Dell Dimension E520", STAC_DELL_3ST),
2089 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ed, "Dell ", STAC_DELL_3ST),
2090 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f4, "Dell ", STAC_DELL_3ST),
2091 /* Dell 3 stack systems with verb table in BIOS */
2092 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f3, "Dell Inspiron 1420", STAC_DELL_BIOS),
2093 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0227, "Dell Vostro 1400 ", STAC_DELL_BIOS),
2094 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022e, "Dell ", STAC_DELL_BIOS),
2095 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022f, "Dell Inspiron 1525", STAC_DELL_3ST),
2096 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0242, "Dell ", STAC_DELL_BIOS),
2097 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0243, "Dell ", STAC_DELL_BIOS),
2098 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ff, "Dell ", STAC_DELL_BIOS),
2099 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0209, "Dell XPS 1330", STAC_DELL_BIOS),
2100 /* 965 based 5 stack systems */
2101 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2301, "Intel D965", STAC_D965_5ST),
2102 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2302, "Intel D965", STAC_D965_5ST),
2103 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2303, "Intel D965", STAC_D965_5ST),
2104 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2304, "Intel D965", STAC_D965_5ST),
2105 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2305, "Intel D965", STAC_D965_5ST),
2106 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2501, "Intel D965", STAC_D965_5ST),
2107 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2502, "Intel D965", STAC_D965_5ST),
2108 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2503, "Intel D965", STAC_D965_5ST),
2109 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2504, "Intel D965", STAC_D965_5ST),
2110 {} /* terminator */
2113 static unsigned int ref9205_pin_configs[12] = {
2114 0x40000100, 0x40000100, 0x01016011, 0x01014010,
2115 0x01813122, 0x01a19021, 0x01019020, 0x40000100,
2116 0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
2120 STAC 9205 pin configs for
2121 102801F1
2122 102801F2
2123 102801FC
2124 102801FD
2125 10280204
2126 1028021F
2127 10280228 (Dell Vostro 1500)
2129 static unsigned int dell_9205_m42_pin_configs[12] = {
2130 0x0321101F, 0x03A11020, 0x400003FA, 0x90170310,
2131 0x400003FB, 0x400003FC, 0x400003FD, 0x40F000F9,
2132 0x90A60330, 0x400003FF, 0x0144131F, 0x40C003FE,
2136 STAC 9205 pin configs for
2137 102801F9
2138 102801FA
2139 102801FE
2140 102801FF (Dell Precision M4300)
2141 10280206
2142 10280200
2143 10280201
2145 static unsigned int dell_9205_m43_pin_configs[12] = {
2146 0x0321101f, 0x03a11020, 0x90a70330, 0x90170310,
2147 0x400000fe, 0x400000ff, 0x400000fd, 0x40f000f9,
2148 0x400000fa, 0x400000fc, 0x0144131f, 0x40c003f8,
2151 static unsigned int dell_9205_m44_pin_configs[12] = {
2152 0x0421101f, 0x04a11020, 0x400003fa, 0x90170310,
2153 0x400003fb, 0x400003fc, 0x400003fd, 0x400003f9,
2154 0x90a60330, 0x400003ff, 0x01441340, 0x40c003fe,
2157 static unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
2158 [STAC_9205_REF] = ref9205_pin_configs,
2159 [STAC_9205_DELL_M42] = dell_9205_m42_pin_configs,
2160 [STAC_9205_DELL_M43] = dell_9205_m43_pin_configs,
2161 [STAC_9205_DELL_M44] = dell_9205_m44_pin_configs,
2164 static const char *stac9205_models[STAC_9205_MODELS] = {
2165 [STAC_9205_REF] = "ref",
2166 [STAC_9205_DELL_M42] = "dell-m42",
2167 [STAC_9205_DELL_M43] = "dell-m43",
2168 [STAC_9205_DELL_M44] = "dell-m44",
2171 static struct snd_pci_quirk stac9205_cfg_tbl[] = {
2172 /* SigmaTel reference board */
2173 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2174 "DFI LanParty", STAC_9205_REF),
2175 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f1,
2176 "unknown Dell", STAC_9205_DELL_M42),
2177 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f2,
2178 "unknown Dell", STAC_9205_DELL_M42),
2179 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f8,
2180 "Dell Precision", STAC_9205_DELL_M43),
2181 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f9,
2182 "Dell Precision", STAC_9205_DELL_M43),
2183 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fa,
2184 "Dell Precision", STAC_9205_DELL_M43),
2185 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fc,
2186 "unknown Dell", STAC_9205_DELL_M42),
2187 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fd,
2188 "unknown Dell", STAC_9205_DELL_M42),
2189 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fe,
2190 "Dell Precision", STAC_9205_DELL_M43),
2191 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ff,
2192 "Dell Precision M4300", STAC_9205_DELL_M43),
2193 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0204,
2194 "unknown Dell", STAC_9205_DELL_M42),
2195 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0206,
2196 "Dell Precision", STAC_9205_DELL_M43),
2197 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021b,
2198 "Dell Precision", STAC_9205_DELL_M43),
2199 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021c,
2200 "Dell Precision", STAC_9205_DELL_M43),
2201 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021f,
2202 "Dell Inspiron", STAC_9205_DELL_M44),
2203 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0228,
2204 "Dell Vostro 1500", STAC_9205_DELL_M42),
2205 {} /* terminator */
2208 static int stac92xx_save_bios_config_regs(struct hda_codec *codec)
2210 int i;
2211 struct sigmatel_spec *spec = codec->spec;
2213 if (! spec->bios_pin_configs) {
2214 spec->bios_pin_configs = kcalloc(spec->num_pins,
2215 sizeof(*spec->bios_pin_configs), GFP_KERNEL);
2216 if (! spec->bios_pin_configs)
2217 return -ENOMEM;
2220 for (i = 0; i < spec->num_pins; i++) {
2221 hda_nid_t nid = spec->pin_nids[i];
2222 unsigned int pin_cfg;
2224 pin_cfg = snd_hda_codec_read(codec, nid, 0,
2225 AC_VERB_GET_CONFIG_DEFAULT, 0x00);
2226 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x bios pin config %8.8x\n",
2227 nid, pin_cfg);
2228 spec->bios_pin_configs[i] = pin_cfg;
2231 return 0;
2234 static void stac92xx_set_config_reg(struct hda_codec *codec,
2235 hda_nid_t pin_nid, unsigned int pin_config)
2237 int i;
2238 snd_hda_codec_write(codec, pin_nid, 0,
2239 AC_VERB_SET_CONFIG_DEFAULT_BYTES_0,
2240 pin_config & 0x000000ff);
2241 snd_hda_codec_write(codec, pin_nid, 0,
2242 AC_VERB_SET_CONFIG_DEFAULT_BYTES_1,
2243 (pin_config & 0x0000ff00) >> 8);
2244 snd_hda_codec_write(codec, pin_nid, 0,
2245 AC_VERB_SET_CONFIG_DEFAULT_BYTES_2,
2246 (pin_config & 0x00ff0000) >> 16);
2247 snd_hda_codec_write(codec, pin_nid, 0,
2248 AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
2249 pin_config >> 24);
2250 i = snd_hda_codec_read(codec, pin_nid, 0,
2251 AC_VERB_GET_CONFIG_DEFAULT,
2252 0x00);
2253 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x pin config %8.8x\n",
2254 pin_nid, i);
2257 static void stac92xx_set_config_regs(struct hda_codec *codec)
2259 int i;
2260 struct sigmatel_spec *spec = codec->spec;
2262 if (!spec->pin_configs)
2263 return;
2265 for (i = 0; i < spec->num_pins; i++)
2266 stac92xx_set_config_reg(codec, spec->pin_nids[i],
2267 spec->pin_configs[i]);
2271 * Analog playback callbacks
2273 static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
2274 struct hda_codec *codec,
2275 struct snd_pcm_substream *substream)
2277 struct sigmatel_spec *spec = codec->spec;
2278 if (spec->stream_delay)
2279 msleep(spec->stream_delay);
2280 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2281 hinfo);
2284 static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2285 struct hda_codec *codec,
2286 unsigned int stream_tag,
2287 unsigned int format,
2288 struct snd_pcm_substream *substream)
2290 struct sigmatel_spec *spec = codec->spec;
2291 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
2294 static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2295 struct hda_codec *codec,
2296 struct snd_pcm_substream *substream)
2298 struct sigmatel_spec *spec = codec->spec;
2299 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2303 * Digital playback callbacks
2305 static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2306 struct hda_codec *codec,
2307 struct snd_pcm_substream *substream)
2309 struct sigmatel_spec *spec = codec->spec;
2310 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2313 static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2314 struct hda_codec *codec,
2315 struct snd_pcm_substream *substream)
2317 struct sigmatel_spec *spec = codec->spec;
2318 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2321 static int stac92xx_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2322 struct hda_codec *codec,
2323 unsigned int stream_tag,
2324 unsigned int format,
2325 struct snd_pcm_substream *substream)
2327 struct sigmatel_spec *spec = codec->spec;
2328 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2329 stream_tag, format, substream);
2334 * Analog capture callbacks
2336 static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2337 struct hda_codec *codec,
2338 unsigned int stream_tag,
2339 unsigned int format,
2340 struct snd_pcm_substream *substream)
2342 struct sigmatel_spec *spec = codec->spec;
2343 hda_nid_t nid = spec->adc_nids[substream->number];
2345 if (spec->powerdown_adcs) {
2346 msleep(40);
2347 snd_hda_codec_write_cache(codec, nid, 0,
2348 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
2350 snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format);
2351 return 0;
2354 static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2355 struct hda_codec *codec,
2356 struct snd_pcm_substream *substream)
2358 struct sigmatel_spec *spec = codec->spec;
2359 hda_nid_t nid = spec->adc_nids[substream->number];
2361 snd_hda_codec_cleanup_stream(codec, nid);
2362 if (spec->powerdown_adcs)
2363 snd_hda_codec_write_cache(codec, nid, 0,
2364 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
2365 return 0;
2368 static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
2369 .substreams = 1,
2370 .channels_min = 2,
2371 .channels_max = 2,
2372 /* NID is set in stac92xx_build_pcms */
2373 .ops = {
2374 .open = stac92xx_dig_playback_pcm_open,
2375 .close = stac92xx_dig_playback_pcm_close,
2376 .prepare = stac92xx_dig_playback_pcm_prepare
2380 static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
2381 .substreams = 1,
2382 .channels_min = 2,
2383 .channels_max = 2,
2384 /* NID is set in stac92xx_build_pcms */
2387 static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
2388 .substreams = 1,
2389 .channels_min = 2,
2390 .channels_max = 8,
2391 .nid = 0x02, /* NID to query formats and rates */
2392 .ops = {
2393 .open = stac92xx_playback_pcm_open,
2394 .prepare = stac92xx_playback_pcm_prepare,
2395 .cleanup = stac92xx_playback_pcm_cleanup
2399 static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
2400 .substreams = 1,
2401 .channels_min = 2,
2402 .channels_max = 2,
2403 .nid = 0x06, /* NID to query formats and rates */
2404 .ops = {
2405 .open = stac92xx_playback_pcm_open,
2406 .prepare = stac92xx_playback_pcm_prepare,
2407 .cleanup = stac92xx_playback_pcm_cleanup
2411 static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
2412 .channels_min = 2,
2413 .channels_max = 2,
2414 /* NID + .substreams is set in stac92xx_build_pcms */
2415 .ops = {
2416 .prepare = stac92xx_capture_pcm_prepare,
2417 .cleanup = stac92xx_capture_pcm_cleanup
2421 static int stac92xx_build_pcms(struct hda_codec *codec)
2423 struct sigmatel_spec *spec = codec->spec;
2424 struct hda_pcm *info = spec->pcm_rec;
2426 codec->num_pcms = 1;
2427 codec->pcm_info = info;
2429 info->name = "STAC92xx Analog";
2430 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
2431 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
2432 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2433 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adcs;
2435 if (spec->alt_switch) {
2436 codec->num_pcms++;
2437 info++;
2438 info->name = "STAC92xx Analog Alt";
2439 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
2442 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2443 codec->num_pcms++;
2444 info++;
2445 info->name = "STAC92xx Digital";
2446 info->pcm_type = HDA_PCM_TYPE_SPDIF;
2447 if (spec->multiout.dig_out_nid) {
2448 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
2449 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2451 if (spec->dig_in_nid) {
2452 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
2453 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2457 return 0;
2460 static unsigned int stac92xx_get_vref(struct hda_codec *codec, hda_nid_t nid)
2462 unsigned int pincap = snd_hda_param_read(codec, nid,
2463 AC_PAR_PIN_CAP);
2464 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
2465 if (pincap & AC_PINCAP_VREF_100)
2466 return AC_PINCTL_VREF_100;
2467 if (pincap & AC_PINCAP_VREF_80)
2468 return AC_PINCTL_VREF_80;
2469 if (pincap & AC_PINCAP_VREF_50)
2470 return AC_PINCTL_VREF_50;
2471 if (pincap & AC_PINCAP_VREF_GRD)
2472 return AC_PINCTL_VREF_GRD;
2473 return 0;
2476 static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
2479 snd_hda_codec_write_cache(codec, nid, 0,
2480 AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
2483 #define stac92xx_hp_switch_info snd_ctl_boolean_mono_info
2485 static int stac92xx_hp_switch_get(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;
2491 ucontrol->value.integer.value[0] = !!spec->hp_switch;
2492 return 0;
2495 static int stac92xx_hp_switch_put(struct snd_kcontrol *kcontrol,
2496 struct snd_ctl_elem_value *ucontrol)
2498 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2499 struct sigmatel_spec *spec = codec->spec;
2500 int nid = kcontrol->private_value;
2502 spec->hp_switch = ucontrol->value.integer.value[0] ? nid : 0;
2504 /* check to be sure that the ports are upto date with
2505 * switch changes
2507 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
2509 return 1;
2512 #define stac92xx_io_switch_info snd_ctl_boolean_mono_info
2514 static int stac92xx_io_switch_get(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 int io_idx = kcontrol-> private_value & 0xff;
2520 ucontrol->value.integer.value[0] = spec->io_switch[io_idx];
2521 return 0;
2524 static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2526 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2527 struct sigmatel_spec *spec = codec->spec;
2528 hda_nid_t nid = kcontrol->private_value >> 8;
2529 int io_idx = kcontrol-> private_value & 0xff;
2530 unsigned short val = !!ucontrol->value.integer.value[0];
2532 spec->io_switch[io_idx] = val;
2534 if (val)
2535 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
2536 else {
2537 unsigned int pinctl = AC_PINCTL_IN_EN;
2538 if (io_idx) /* set VREF for mic */
2539 pinctl |= stac92xx_get_vref(codec, nid);
2540 stac92xx_auto_set_pinctl(codec, nid, pinctl);
2543 /* check the auto-mute again: we need to mute/unmute the speaker
2544 * appropriately according to the pin direction
2546 if (spec->hp_detect)
2547 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
2549 return 1;
2552 #define stac92xx_clfe_switch_info snd_ctl_boolean_mono_info
2554 static int stac92xx_clfe_switch_get(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;
2560 ucontrol->value.integer.value[0] = spec->clfe_swap;
2561 return 0;
2564 static int stac92xx_clfe_switch_put(struct snd_kcontrol *kcontrol,
2565 struct snd_ctl_elem_value *ucontrol)
2567 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2568 struct sigmatel_spec *spec = codec->spec;
2569 hda_nid_t nid = kcontrol->private_value & 0xff;
2570 unsigned int val = !!ucontrol->value.integer.value[0];
2572 if (spec->clfe_swap == val)
2573 return 0;
2575 spec->clfe_swap = val;
2577 snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
2578 spec->clfe_swap ? 0x4 : 0x0);
2580 return 1;
2583 #define STAC_CODEC_HP_SWITCH(xname) \
2584 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2585 .name = xname, \
2586 .index = 0, \
2587 .info = stac92xx_hp_switch_info, \
2588 .get = stac92xx_hp_switch_get, \
2589 .put = stac92xx_hp_switch_put, \
2592 #define STAC_CODEC_IO_SWITCH(xname, xpval) \
2593 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2594 .name = xname, \
2595 .index = 0, \
2596 .info = stac92xx_io_switch_info, \
2597 .get = stac92xx_io_switch_get, \
2598 .put = stac92xx_io_switch_put, \
2599 .private_value = xpval, \
2602 #define STAC_CODEC_CLFE_SWITCH(xname, xpval) \
2603 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2604 .name = xname, \
2605 .index = 0, \
2606 .info = stac92xx_clfe_switch_info, \
2607 .get = stac92xx_clfe_switch_get, \
2608 .put = stac92xx_clfe_switch_put, \
2609 .private_value = xpval, \
2612 enum {
2613 STAC_CTL_WIDGET_VOL,
2614 STAC_CTL_WIDGET_MUTE,
2615 STAC_CTL_WIDGET_MONO_MUX,
2616 STAC_CTL_WIDGET_AMP_MUX,
2617 STAC_CTL_WIDGET_AMP_VOL,
2618 STAC_CTL_WIDGET_HP_SWITCH,
2619 STAC_CTL_WIDGET_IO_SWITCH,
2620 STAC_CTL_WIDGET_CLFE_SWITCH
2623 static struct snd_kcontrol_new stac92xx_control_templates[] = {
2624 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2625 HDA_CODEC_MUTE(NULL, 0, 0, 0),
2626 STAC_MONO_MUX,
2627 STAC_AMP_MUX,
2628 STAC_AMP_VOL(NULL, 0, 0, 0, 0),
2629 STAC_CODEC_HP_SWITCH(NULL),
2630 STAC_CODEC_IO_SWITCH(NULL, 0),
2631 STAC_CODEC_CLFE_SWITCH(NULL, 0),
2634 /* add dynamic controls */
2635 static int stac92xx_add_control_temp(struct sigmatel_spec *spec,
2636 struct snd_kcontrol_new *ktemp,
2637 int idx, const char *name,
2638 unsigned long val)
2640 struct snd_kcontrol_new *knew;
2642 if (spec->num_kctl_used >= spec->num_kctl_alloc) {
2643 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
2645 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */
2646 if (! knew)
2647 return -ENOMEM;
2648 if (spec->kctl_alloc) {
2649 memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
2650 kfree(spec->kctl_alloc);
2652 spec->kctl_alloc = knew;
2653 spec->num_kctl_alloc = num;
2656 knew = &spec->kctl_alloc[spec->num_kctl_used];
2657 *knew = *ktemp;
2658 knew->index = idx;
2659 knew->name = kstrdup(name, GFP_KERNEL);
2660 if (!knew->name)
2661 return -ENOMEM;
2662 knew->private_value = val;
2663 spec->num_kctl_used++;
2664 return 0;
2667 static inline int stac92xx_add_control_idx(struct sigmatel_spec *spec,
2668 int type, int idx, const char *name,
2669 unsigned long val)
2671 return stac92xx_add_control_temp(spec,
2672 &stac92xx_control_templates[type],
2673 idx, name, val);
2677 /* add dynamic controls */
2678 static inline int stac92xx_add_control(struct sigmatel_spec *spec, int type,
2679 const char *name, unsigned long val)
2681 return stac92xx_add_control_idx(spec, type, 0, name, val);
2684 /* flag inputs as additional dynamic lineouts */
2685 static int stac92xx_add_dyn_out_pins(struct hda_codec *codec, struct auto_pin_cfg *cfg)
2687 struct sigmatel_spec *spec = codec->spec;
2688 unsigned int wcaps, wtype;
2689 int i, num_dacs = 0;
2691 /* use the wcaps cache to count all DACs available for line-outs */
2692 for (i = 0; i < codec->num_nodes; i++) {
2693 wcaps = codec->wcaps[i];
2694 wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
2696 if (wtype == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL))
2697 num_dacs++;
2700 snd_printdd("%s: total dac count=%d\n", __func__, num_dacs);
2702 switch (cfg->line_outs) {
2703 case 3:
2704 /* add line-in as side */
2705 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 3) {
2706 cfg->line_out_pins[cfg->line_outs] =
2707 cfg->input_pins[AUTO_PIN_LINE];
2708 spec->line_switch = 1;
2709 cfg->line_outs++;
2711 break;
2712 case 2:
2713 /* add line-in as clfe and mic as side */
2714 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 2) {
2715 cfg->line_out_pins[cfg->line_outs] =
2716 cfg->input_pins[AUTO_PIN_LINE];
2717 spec->line_switch = 1;
2718 cfg->line_outs++;
2720 if (cfg->input_pins[AUTO_PIN_MIC] && num_dacs > 3) {
2721 cfg->line_out_pins[cfg->line_outs] =
2722 cfg->input_pins[AUTO_PIN_MIC];
2723 spec->mic_switch = 1;
2724 cfg->line_outs++;
2726 break;
2727 case 1:
2728 /* add line-in as surr and mic as clfe */
2729 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 1) {
2730 cfg->line_out_pins[cfg->line_outs] =
2731 cfg->input_pins[AUTO_PIN_LINE];
2732 spec->line_switch = 1;
2733 cfg->line_outs++;
2735 if (cfg->input_pins[AUTO_PIN_MIC] && num_dacs > 2) {
2736 cfg->line_out_pins[cfg->line_outs] =
2737 cfg->input_pins[AUTO_PIN_MIC];
2738 spec->mic_switch = 1;
2739 cfg->line_outs++;
2741 break;
2744 return 0;
2748 static int is_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2750 int i;
2752 for (i = 0; i < spec->multiout.num_dacs; i++) {
2753 if (spec->multiout.dac_nids[i] == nid)
2754 return 1;
2757 return 0;
2761 * Fill in the dac_nids table from the parsed pin configuration
2762 * This function only works when every pin in line_out_pins[]
2763 * contains atleast one DAC in its connection list. Some 92xx
2764 * codecs are not connected directly to a DAC, such as the 9200
2765 * and 9202/925x. For those, dac_nids[] must be hard-coded.
2767 static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec,
2768 struct auto_pin_cfg *cfg)
2770 struct sigmatel_spec *spec = codec->spec;
2771 int i, j, conn_len = 0;
2772 hda_nid_t nid, conn[HDA_MAX_CONNECTIONS];
2773 unsigned int wcaps, wtype;
2775 for (i = 0; i < cfg->line_outs; i++) {
2776 nid = cfg->line_out_pins[i];
2777 conn_len = snd_hda_get_connections(codec, nid, conn,
2778 HDA_MAX_CONNECTIONS);
2779 for (j = 0; j < conn_len; j++) {
2780 wcaps = snd_hda_param_read(codec, conn[j],
2781 AC_PAR_AUDIO_WIDGET_CAP);
2782 wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
2783 if (wtype != AC_WID_AUD_OUT ||
2784 (wcaps & AC_WCAP_DIGITAL))
2785 continue;
2786 /* conn[j] is a DAC routed to this line-out */
2787 if (!is_in_dac_nids(spec, conn[j]))
2788 break;
2791 if (j == conn_len) {
2792 if (spec->multiout.num_dacs > 0) {
2793 /* we have already working output pins,
2794 * so let's drop the broken ones again
2796 cfg->line_outs = spec->multiout.num_dacs;
2797 break;
2799 /* error out, no available DAC found */
2800 snd_printk(KERN_ERR
2801 "%s: No available DAC for pin 0x%x\n",
2802 __func__, nid);
2803 return -ENODEV;
2806 spec->multiout.dac_nids[i] = conn[j];
2807 spec->multiout.num_dacs++;
2808 if (conn_len > 1) {
2809 /* select this DAC in the pin's input mux */
2810 snd_hda_codec_write_cache(codec, nid, 0,
2811 AC_VERB_SET_CONNECT_SEL, j);
2816 snd_printd("dac_nids=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
2817 spec->multiout.num_dacs,
2818 spec->multiout.dac_nids[0],
2819 spec->multiout.dac_nids[1],
2820 spec->multiout.dac_nids[2],
2821 spec->multiout.dac_nids[3],
2822 spec->multiout.dac_nids[4]);
2823 return 0;
2826 /* create volume control/switch for the given prefx type */
2827 static int create_controls(struct sigmatel_spec *spec, const char *pfx, hda_nid_t nid, int chs)
2829 char name[32];
2830 int err;
2832 sprintf(name, "%s Playback Volume", pfx);
2833 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, name,
2834 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
2835 if (err < 0)
2836 return err;
2837 sprintf(name, "%s Playback Switch", pfx);
2838 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, name,
2839 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
2840 if (err < 0)
2841 return err;
2842 return 0;
2845 static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
2847 if (!spec->multiout.hp_nid)
2848 spec->multiout.hp_nid = nid;
2849 else if (spec->multiout.num_dacs > 4) {
2850 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
2851 return 1;
2852 } else {
2853 spec->multiout.dac_nids[spec->multiout.num_dacs] = nid;
2854 spec->multiout.num_dacs++;
2856 return 0;
2859 static int check_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2861 if (is_in_dac_nids(spec, nid))
2862 return 1;
2863 if (spec->multiout.hp_nid == nid)
2864 return 1;
2865 return 0;
2868 /* add playback controls from the parsed DAC table */
2869 static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
2870 const struct auto_pin_cfg *cfg)
2872 static const char *chname[4] = {
2873 "Front", "Surround", NULL /*CLFE*/, "Side"
2875 hda_nid_t nid = 0;
2876 int i, err;
2878 struct sigmatel_spec *spec = codec->spec;
2879 unsigned int wid_caps, pincap;
2882 for (i = 0; i < cfg->line_outs && i < spec->multiout.num_dacs; i++) {
2883 if (!spec->multiout.dac_nids[i])
2884 continue;
2886 nid = spec->multiout.dac_nids[i];
2888 if (i == 2) {
2889 /* Center/LFE */
2890 err = create_controls(spec, "Center", nid, 1);
2891 if (err < 0)
2892 return err;
2893 err = create_controls(spec, "LFE", nid, 2);
2894 if (err < 0)
2895 return err;
2897 wid_caps = get_wcaps(codec, nid);
2899 if (wid_caps & AC_WCAP_LR_SWAP) {
2900 err = stac92xx_add_control(spec,
2901 STAC_CTL_WIDGET_CLFE_SWITCH,
2902 "Swap Center/LFE Playback Switch", nid);
2904 if (err < 0)
2905 return err;
2908 } else {
2909 err = create_controls(spec, chname[i], nid, 3);
2910 if (err < 0)
2911 return err;
2915 if ((spec->multiout.num_dacs - cfg->line_outs) > 0 &&
2916 cfg->hp_outs == 1 && !spec->multiout.hp_nid)
2917 spec->multiout.hp_nid = nid;
2919 if (cfg->hp_outs > 1 && cfg->line_out_type == AUTO_PIN_LINE_OUT) {
2920 err = stac92xx_add_control(spec,
2921 STAC_CTL_WIDGET_HP_SWITCH,
2922 "Headphone as Line Out Switch",
2923 cfg->hp_pins[cfg->hp_outs - 1]);
2924 if (err < 0)
2925 return err;
2928 if (spec->line_switch) {
2929 nid = cfg->input_pins[AUTO_PIN_LINE];
2930 pincap = snd_hda_param_read(codec, nid,
2931 AC_PAR_PIN_CAP);
2932 if (pincap & AC_PINCAP_OUT) {
2933 err = stac92xx_add_control(spec,
2934 STAC_CTL_WIDGET_IO_SWITCH,
2935 "Line In as Output Switch", nid << 8);
2936 if (err < 0)
2937 return err;
2941 if (spec->mic_switch) {
2942 unsigned int def_conf;
2943 unsigned int mic_pin = AUTO_PIN_MIC;
2944 again:
2945 nid = cfg->input_pins[mic_pin];
2946 def_conf = snd_hda_codec_read(codec, nid, 0,
2947 AC_VERB_GET_CONFIG_DEFAULT, 0);
2948 /* some laptops have an internal analog microphone
2949 * which can't be used as a output */
2950 if (get_defcfg_connect(def_conf) != AC_JACK_PORT_FIXED) {
2951 pincap = snd_hda_param_read(codec, nid,
2952 AC_PAR_PIN_CAP);
2953 if (pincap & AC_PINCAP_OUT) {
2954 err = stac92xx_add_control(spec,
2955 STAC_CTL_WIDGET_IO_SWITCH,
2956 "Mic as Output Switch", (nid << 8) | 1);
2957 nid = snd_hda_codec_read(codec, nid, 0,
2958 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
2959 if (!check_in_dac_nids(spec, nid))
2960 add_spec_dacs(spec, nid);
2961 if (err < 0)
2962 return err;
2964 } else if (mic_pin == AUTO_PIN_MIC) {
2965 mic_pin = AUTO_PIN_FRONT_MIC;
2966 goto again;
2970 return 0;
2973 /* add playback controls for Speaker and HP outputs */
2974 static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
2975 struct auto_pin_cfg *cfg)
2977 struct sigmatel_spec *spec = codec->spec;
2978 hda_nid_t nid;
2979 int i, old_num_dacs, err;
2981 old_num_dacs = spec->multiout.num_dacs;
2982 for (i = 0; i < cfg->hp_outs; i++) {
2983 unsigned int wid_caps = get_wcaps(codec, cfg->hp_pins[i]);
2984 if (wid_caps & AC_WCAP_UNSOL_CAP)
2985 spec->hp_detect = 1;
2986 nid = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
2987 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
2988 if (check_in_dac_nids(spec, nid))
2989 nid = 0;
2990 if (! nid)
2991 continue;
2992 add_spec_dacs(spec, nid);
2994 for (i = 0; i < cfg->speaker_outs; i++) {
2995 nid = snd_hda_codec_read(codec, cfg->speaker_pins[i], 0,
2996 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
2997 if (check_in_dac_nids(spec, nid))
2998 nid = 0;
2999 if (! nid)
3000 continue;
3001 add_spec_dacs(spec, nid);
3003 for (i = 0; i < cfg->line_outs; i++) {
3004 nid = snd_hda_codec_read(codec, cfg->line_out_pins[i], 0,
3005 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
3006 if (check_in_dac_nids(spec, nid))
3007 nid = 0;
3008 if (! nid)
3009 continue;
3010 add_spec_dacs(spec, nid);
3012 for (i = old_num_dacs; i < spec->multiout.num_dacs; i++) {
3013 static const char *pfxs[] = {
3014 "Speaker", "External Speaker", "Speaker2",
3016 err = create_controls(spec, pfxs[i - old_num_dacs],
3017 spec->multiout.dac_nids[i], 3);
3018 if (err < 0)
3019 return err;
3021 if (spec->multiout.hp_nid) {
3022 err = create_controls(spec, "Headphone",
3023 spec->multiout.hp_nid, 3);
3024 if (err < 0)
3025 return err;
3028 return 0;
3031 /* labels for mono mux outputs */
3032 static const char *stac92xx_mono_labels[4] = {
3033 "DAC0", "DAC1", "Mixer", "DAC2"
3036 /* create mono mux for mono out on capable codecs */
3037 static int stac92xx_auto_create_mono_output_ctls(struct hda_codec *codec)
3039 struct sigmatel_spec *spec = codec->spec;
3040 struct hda_input_mux *mono_mux = &spec->private_mono_mux;
3041 int i, num_cons;
3042 hda_nid_t con_lst[ARRAY_SIZE(stac92xx_mono_labels)];
3044 num_cons = snd_hda_get_connections(codec,
3045 spec->mono_nid,
3046 con_lst,
3047 HDA_MAX_NUM_INPUTS);
3048 if (!num_cons || num_cons > ARRAY_SIZE(stac92xx_mono_labels))
3049 return -EINVAL;
3051 for (i = 0; i < num_cons; i++) {
3052 mono_mux->items[mono_mux->num_items].label =
3053 stac92xx_mono_labels[i];
3054 mono_mux->items[mono_mux->num_items].index = i;
3055 mono_mux->num_items++;
3058 return stac92xx_add_control(spec, STAC_CTL_WIDGET_MONO_MUX,
3059 "Mono Mux", spec->mono_nid);
3062 /* labels for amp mux outputs */
3063 static const char *stac92xx_amp_labels[3] = {
3064 "Front Microphone", "Microphone", "Line In",
3067 /* create amp out controls mux on capable codecs */
3068 static int stac92xx_auto_create_amp_output_ctls(struct hda_codec *codec)
3070 struct sigmatel_spec *spec = codec->spec;
3071 struct hda_input_mux *amp_mux = &spec->private_amp_mux;
3072 int i, err;
3074 for (i = 0; i < spec->num_amps; i++) {
3075 amp_mux->items[amp_mux->num_items].label =
3076 stac92xx_amp_labels[i];
3077 amp_mux->items[amp_mux->num_items].index = i;
3078 amp_mux->num_items++;
3081 if (spec->num_amps > 1) {
3082 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_AMP_MUX,
3083 "Amp Selector Capture Switch", 0);
3084 if (err < 0)
3085 return err;
3087 return stac92xx_add_control(spec, STAC_CTL_WIDGET_AMP_VOL,
3088 "Amp Capture Volume",
3089 HDA_COMPOSE_AMP_VAL(spec->amp_nids[0], 3, 0, HDA_INPUT));
3093 /* create PC beep volume controls */
3094 static int stac92xx_auto_create_beep_ctls(struct hda_codec *codec,
3095 hda_nid_t nid)
3097 struct sigmatel_spec *spec = codec->spec;
3098 u32 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3099 int err;
3101 /* check for mute support for the the amp */
3102 if ((caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT) {
3103 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE,
3104 "PC Beep Playback Switch",
3105 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3106 if (err < 0)
3107 return err;
3110 /* check to see if there is volume support for the amp */
3111 if ((caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3112 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL,
3113 "PC Beep Playback Volume",
3114 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3115 if (err < 0)
3116 return err;
3118 return 0;
3121 #ifdef CONFIG_SND_HDA_INPUT_BEEP
3122 #define stac92xx_dig_beep_switch_info snd_ctl_boolean_mono_info
3124 static int stac92xx_dig_beep_switch_get(struct snd_kcontrol *kcontrol,
3125 struct snd_ctl_elem_value *ucontrol)
3127 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3128 ucontrol->value.integer.value[0] = codec->beep->enabled;
3129 return 0;
3132 static int stac92xx_dig_beep_switch_put(struct snd_kcontrol *kcontrol,
3133 struct snd_ctl_elem_value *ucontrol)
3135 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3136 int enabled = !!ucontrol->value.integer.value[0];
3137 if (codec->beep->enabled != enabled) {
3138 codec->beep->enabled = enabled;
3139 return 1;
3141 return 0;
3144 static struct snd_kcontrol_new stac92xx_dig_beep_ctrl = {
3145 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3146 .info = stac92xx_dig_beep_switch_info,
3147 .get = stac92xx_dig_beep_switch_get,
3148 .put = stac92xx_dig_beep_switch_put,
3151 static int stac92xx_beep_switch_ctl(struct hda_codec *codec)
3153 return stac92xx_add_control_temp(codec->spec, &stac92xx_dig_beep_ctrl,
3154 0, "PC Beep Playback Switch", 0);
3156 #endif
3158 static int stac92xx_auto_create_mux_input_ctls(struct hda_codec *codec)
3160 struct sigmatel_spec *spec = codec->spec;
3161 int wcaps, nid, i, err = 0;
3163 for (i = 0; i < spec->num_muxes; i++) {
3164 nid = spec->mux_nids[i];
3165 wcaps = get_wcaps(codec, nid);
3167 if (wcaps & AC_WCAP_OUT_AMP) {
3168 err = stac92xx_add_control_idx(spec,
3169 STAC_CTL_WIDGET_VOL, i, "Mux Capture Volume",
3170 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
3171 if (err < 0)
3172 return err;
3175 return 0;
3178 static const char *stac92xx_spdif_labels[3] = {
3179 "Digital Playback", "Analog Mux 1", "Analog Mux 2",
3182 static int stac92xx_auto_create_spdif_mux_ctls(struct hda_codec *codec)
3184 struct sigmatel_spec *spec = codec->spec;
3185 struct hda_input_mux *spdif_mux = &spec->private_smux;
3186 const char **labels = spec->spdif_labels;
3187 int i, num_cons;
3188 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
3190 num_cons = snd_hda_get_connections(codec,
3191 spec->smux_nids[0],
3192 con_lst,
3193 HDA_MAX_NUM_INPUTS);
3194 if (!num_cons)
3195 return -EINVAL;
3197 if (!labels)
3198 labels = stac92xx_spdif_labels;
3200 for (i = 0; i < num_cons; i++) {
3201 spdif_mux->items[spdif_mux->num_items].label = labels[i];
3202 spdif_mux->items[spdif_mux->num_items].index = i;
3203 spdif_mux->num_items++;
3206 return 0;
3209 /* labels for dmic mux inputs */
3210 static const char *stac92xx_dmic_labels[5] = {
3211 "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
3212 "Digital Mic 3", "Digital Mic 4"
3215 /* create playback/capture controls for input pins on dmic capable codecs */
3216 static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
3217 const struct auto_pin_cfg *cfg)
3219 struct sigmatel_spec *spec = codec->spec;
3220 struct hda_input_mux *dimux = &spec->private_dimux;
3221 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
3222 int err, i, j;
3223 char name[32];
3225 dimux->items[dimux->num_items].label = stac92xx_dmic_labels[0];
3226 dimux->items[dimux->num_items].index = 0;
3227 dimux->num_items++;
3229 for (i = 0; i < spec->num_dmics; i++) {
3230 hda_nid_t nid;
3231 int index;
3232 int num_cons;
3233 unsigned int wcaps;
3234 unsigned int def_conf;
3236 def_conf = snd_hda_codec_read(codec,
3237 spec->dmic_nids[i],
3239 AC_VERB_GET_CONFIG_DEFAULT,
3241 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
3242 continue;
3244 nid = spec->dmic_nids[i];
3245 num_cons = snd_hda_get_connections(codec,
3246 spec->dmux_nids[0],
3247 con_lst,
3248 HDA_MAX_NUM_INPUTS);
3249 for (j = 0; j < num_cons; j++)
3250 if (con_lst[j] == nid) {
3251 index = j;
3252 goto found;
3254 continue;
3255 found:
3256 wcaps = get_wcaps(codec, nid) &
3257 (AC_WCAP_OUT_AMP | AC_WCAP_IN_AMP);
3259 if (wcaps) {
3260 sprintf(name, "%s Capture Volume",
3261 stac92xx_dmic_labels[dimux->num_items]);
3263 err = stac92xx_add_control(spec,
3264 STAC_CTL_WIDGET_VOL,
3265 name,
3266 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3267 (wcaps & AC_WCAP_OUT_AMP) ?
3268 HDA_OUTPUT : HDA_INPUT));
3269 if (err < 0)
3270 return err;
3273 dimux->items[dimux->num_items].label =
3274 stac92xx_dmic_labels[dimux->num_items];
3275 dimux->items[dimux->num_items].index = index;
3276 dimux->num_items++;
3279 return 0;
3282 /* create playback/capture controls for input pins */
3283 static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
3285 struct sigmatel_spec *spec = codec->spec;
3286 struct hda_input_mux *imux = &spec->private_imux;
3287 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
3288 int i, j, k;
3290 for (i = 0; i < AUTO_PIN_LAST; i++) {
3291 int index;
3293 if (!cfg->input_pins[i])
3294 continue;
3295 index = -1;
3296 for (j = 0; j < spec->num_muxes; j++) {
3297 int num_cons;
3298 num_cons = snd_hda_get_connections(codec,
3299 spec->mux_nids[j],
3300 con_lst,
3301 HDA_MAX_NUM_INPUTS);
3302 for (k = 0; k < num_cons; k++)
3303 if (con_lst[k] == cfg->input_pins[i]) {
3304 index = k;
3305 goto found;
3308 continue;
3309 found:
3310 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
3311 imux->items[imux->num_items].index = index;
3312 imux->num_items++;
3315 if (imux->num_items) {
3317 * Set the current input for the muxes.
3318 * The STAC9221 has two input muxes with identical source
3319 * NID lists. Hopefully this won't get confused.
3321 for (i = 0; i < spec->num_muxes; i++) {
3322 snd_hda_codec_write_cache(codec, spec->mux_nids[i], 0,
3323 AC_VERB_SET_CONNECT_SEL,
3324 imux->items[0].index);
3328 return 0;
3331 static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
3333 struct sigmatel_spec *spec = codec->spec;
3334 int i;
3336 for (i = 0; i < spec->autocfg.line_outs; i++) {
3337 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3338 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
3342 static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
3344 struct sigmatel_spec *spec = codec->spec;
3345 int i;
3347 for (i = 0; i < spec->autocfg.hp_outs; i++) {
3348 hda_nid_t pin;
3349 pin = spec->autocfg.hp_pins[i];
3350 if (pin) /* connect to front */
3351 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
3353 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
3354 hda_nid_t pin;
3355 pin = spec->autocfg.speaker_pins[i];
3356 if (pin) /* connect to front */
3357 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
3361 static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out, hda_nid_t dig_in)
3363 struct sigmatel_spec *spec = codec->spec;
3364 int err;
3365 int hp_speaker_swap = 0;
3367 if ((err = snd_hda_parse_pin_def_config(codec,
3368 &spec->autocfg,
3369 spec->dmic_nids)) < 0)
3370 return err;
3371 if (! spec->autocfg.line_outs)
3372 return 0; /* can't find valid pin config */
3374 /* If we have no real line-out pin and multiple hp-outs, HPs should
3375 * be set up as multi-channel outputs.
3377 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT &&
3378 spec->autocfg.hp_outs > 1) {
3379 /* Copy hp_outs to line_outs, backup line_outs in
3380 * speaker_outs so that the following routines can handle
3381 * HP pins as primary outputs.
3383 memcpy(spec->autocfg.speaker_pins, spec->autocfg.line_out_pins,
3384 sizeof(spec->autocfg.line_out_pins));
3385 spec->autocfg.speaker_outs = spec->autocfg.line_outs;
3386 memcpy(spec->autocfg.line_out_pins, spec->autocfg.hp_pins,
3387 sizeof(spec->autocfg.hp_pins));
3388 spec->autocfg.line_outs = spec->autocfg.hp_outs;
3389 hp_speaker_swap = 1;
3391 if (spec->autocfg.mono_out_pin) {
3392 int dir = get_wcaps(codec, spec->autocfg.mono_out_pin) &
3393 (AC_WCAP_OUT_AMP | AC_WCAP_IN_AMP);
3394 u32 caps = query_amp_caps(codec,
3395 spec->autocfg.mono_out_pin, dir);
3396 hda_nid_t conn_list[1];
3398 /* get the mixer node and then the mono mux if it exists */
3399 if (snd_hda_get_connections(codec,
3400 spec->autocfg.mono_out_pin, conn_list, 1) &&
3401 snd_hda_get_connections(codec, conn_list[0],
3402 conn_list, 1)) {
3404 int wcaps = get_wcaps(codec, conn_list[0]);
3405 int wid_type = (wcaps & AC_WCAP_TYPE)
3406 >> AC_WCAP_TYPE_SHIFT;
3407 /* LR swap check, some stac925x have a mux that
3408 * changes the DACs output path instead of the
3409 * mono-mux path.
3411 if (wid_type == AC_WID_AUD_SEL &&
3412 !(wcaps & AC_WCAP_LR_SWAP))
3413 spec->mono_nid = conn_list[0];
3415 if (dir) {
3416 hda_nid_t nid = spec->autocfg.mono_out_pin;
3418 /* most mono outs have a least a mute/unmute switch */
3419 dir = (dir & AC_WCAP_OUT_AMP) ? HDA_OUTPUT : HDA_INPUT;
3420 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE,
3421 "Mono Playback Switch",
3422 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
3423 if (err < 0)
3424 return err;
3425 /* check for volume support for the amp */
3426 if ((caps & AC_AMPCAP_NUM_STEPS)
3427 >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3428 err = stac92xx_add_control(spec,
3429 STAC_CTL_WIDGET_VOL,
3430 "Mono Playback Volume",
3431 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
3432 if (err < 0)
3433 return err;
3437 stac92xx_auto_set_pinctl(codec, spec->autocfg.mono_out_pin,
3438 AC_PINCTL_OUT_EN);
3441 if ((err = stac92xx_add_dyn_out_pins(codec, &spec->autocfg)) < 0)
3442 return err;
3443 if (spec->multiout.num_dacs == 0)
3444 if ((err = stac92xx_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
3445 return err;
3447 err = stac92xx_auto_create_multi_out_ctls(codec, &spec->autocfg);
3449 if (err < 0)
3450 return err;
3452 /* setup analog beep controls */
3453 if (spec->anabeep_nid > 0) {
3454 err = stac92xx_auto_create_beep_ctls(codec,
3455 spec->anabeep_nid);
3456 if (err < 0)
3457 return err;
3460 /* setup digital beep controls and input device */
3461 #ifdef CONFIG_SND_HDA_INPUT_BEEP
3462 if (spec->digbeep_nid > 0) {
3463 hda_nid_t nid = spec->digbeep_nid;
3464 unsigned int caps;
3466 err = stac92xx_auto_create_beep_ctls(codec, nid);
3467 if (err < 0)
3468 return err;
3469 err = snd_hda_attach_beep_device(codec, nid);
3470 if (err < 0)
3471 return err;
3472 /* if no beep switch is available, make its own one */
3473 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3474 if (codec->beep &&
3475 !((caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT)) {
3476 err = stac92xx_beep_switch_ctl(codec);
3477 if (err < 0)
3478 return err;
3481 #endif
3483 if (hp_speaker_swap == 1) {
3484 /* Restore the hp_outs and line_outs */
3485 memcpy(spec->autocfg.hp_pins, spec->autocfg.line_out_pins,
3486 sizeof(spec->autocfg.line_out_pins));
3487 spec->autocfg.hp_outs = spec->autocfg.line_outs;
3488 memcpy(spec->autocfg.line_out_pins, spec->autocfg.speaker_pins,
3489 sizeof(spec->autocfg.speaker_pins));
3490 spec->autocfg.line_outs = spec->autocfg.speaker_outs;
3491 memset(spec->autocfg.speaker_pins, 0,
3492 sizeof(spec->autocfg.speaker_pins));
3493 spec->autocfg.speaker_outs = 0;
3496 err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg);
3498 if (err < 0)
3499 return err;
3501 err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg);
3503 if (err < 0)
3504 return err;
3506 if (spec->mono_nid > 0) {
3507 err = stac92xx_auto_create_mono_output_ctls(codec);
3508 if (err < 0)
3509 return err;
3511 if (spec->num_amps > 0) {
3512 err = stac92xx_auto_create_amp_output_ctls(codec);
3513 if (err < 0)
3514 return err;
3516 if (spec->num_dmics > 0 && !spec->dinput_mux)
3517 if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
3518 &spec->autocfg)) < 0)
3519 return err;
3520 if (spec->num_muxes > 0) {
3521 err = stac92xx_auto_create_mux_input_ctls(codec);
3522 if (err < 0)
3523 return err;
3525 if (spec->num_smuxes > 0) {
3526 err = stac92xx_auto_create_spdif_mux_ctls(codec);
3527 if (err < 0)
3528 return err;
3531 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3532 if (spec->multiout.max_channels > 2)
3533 spec->surr_switch = 1;
3535 if (spec->autocfg.dig_out_pin)
3536 spec->multiout.dig_out_nid = dig_out;
3537 if (dig_in && spec->autocfg.dig_in_pin)
3538 spec->dig_in_nid = dig_in;
3540 if (spec->kctl_alloc)
3541 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
3543 spec->input_mux = &spec->private_imux;
3544 spec->dinput_mux = &spec->private_dimux;
3545 spec->sinput_mux = &spec->private_smux;
3546 spec->mono_mux = &spec->private_mono_mux;
3547 spec->amp_mux = &spec->private_amp_mux;
3548 return 1;
3551 /* add playback controls for HP output */
3552 static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
3553 struct auto_pin_cfg *cfg)
3555 struct sigmatel_spec *spec = codec->spec;
3556 hda_nid_t pin = cfg->hp_pins[0];
3557 unsigned int wid_caps;
3559 if (! pin)
3560 return 0;
3562 wid_caps = get_wcaps(codec, pin);
3563 if (wid_caps & AC_WCAP_UNSOL_CAP)
3564 spec->hp_detect = 1;
3566 return 0;
3569 /* add playback controls for LFE output */
3570 static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
3571 struct auto_pin_cfg *cfg)
3573 struct sigmatel_spec *spec = codec->spec;
3574 int err;
3575 hda_nid_t lfe_pin = 0x0;
3576 int i;
3579 * search speaker outs and line outs for a mono speaker pin
3580 * with an amp. If one is found, add LFE controls
3581 * for it.
3583 for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
3584 hda_nid_t pin = spec->autocfg.speaker_pins[i];
3585 unsigned int wcaps = get_wcaps(codec, pin);
3586 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
3587 if (wcaps == AC_WCAP_OUT_AMP)
3588 /* found a mono speaker with an amp, must be lfe */
3589 lfe_pin = pin;
3592 /* if speaker_outs is 0, then speakers may be in line_outs */
3593 if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
3594 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
3595 hda_nid_t pin = spec->autocfg.line_out_pins[i];
3596 unsigned int defcfg;
3597 defcfg = snd_hda_codec_read(codec, pin, 0,
3598 AC_VERB_GET_CONFIG_DEFAULT,
3599 0x00);
3600 if (get_defcfg_device(defcfg) == AC_JACK_SPEAKER) {
3601 unsigned int wcaps = get_wcaps(codec, pin);
3602 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
3603 if (wcaps == AC_WCAP_OUT_AMP)
3604 /* found a mono speaker with an amp,
3605 must be lfe */
3606 lfe_pin = pin;
3611 if (lfe_pin) {
3612 err = create_controls(spec, "LFE", lfe_pin, 1);
3613 if (err < 0)
3614 return err;
3617 return 0;
3620 static int stac9200_parse_auto_config(struct hda_codec *codec)
3622 struct sigmatel_spec *spec = codec->spec;
3623 int err;
3625 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
3626 return err;
3628 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
3629 return err;
3631 if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
3632 return err;
3634 if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
3635 return err;
3637 if (spec->num_muxes > 0) {
3638 err = stac92xx_auto_create_mux_input_ctls(codec);
3639 if (err < 0)
3640 return err;
3643 if (spec->autocfg.dig_out_pin)
3644 spec->multiout.dig_out_nid = 0x05;
3645 if (spec->autocfg.dig_in_pin)
3646 spec->dig_in_nid = 0x04;
3648 if (spec->kctl_alloc)
3649 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
3651 spec->input_mux = &spec->private_imux;
3652 spec->dinput_mux = &spec->private_dimux;
3654 return 1;
3658 * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
3659 * funky external mute control using GPIO pins.
3662 static void stac_gpio_set(struct hda_codec *codec, unsigned int mask,
3663 unsigned int dir_mask, unsigned int data)
3665 unsigned int gpiostate, gpiomask, gpiodir;
3667 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
3668 AC_VERB_GET_GPIO_DATA, 0);
3669 gpiostate = (gpiostate & ~dir_mask) | (data & dir_mask);
3671 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
3672 AC_VERB_GET_GPIO_MASK, 0);
3673 gpiomask |= mask;
3675 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
3676 AC_VERB_GET_GPIO_DIRECTION, 0);
3677 gpiodir |= dir_mask;
3679 /* Configure GPIOx as CMOS */
3680 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
3682 snd_hda_codec_write(codec, codec->afg, 0,
3683 AC_VERB_SET_GPIO_MASK, gpiomask);
3684 snd_hda_codec_read(codec, codec->afg, 0,
3685 AC_VERB_SET_GPIO_DIRECTION, gpiodir); /* sync */
3687 msleep(1);
3689 snd_hda_codec_read(codec, codec->afg, 0,
3690 AC_VERB_SET_GPIO_DATA, gpiostate); /* sync */
3693 static void enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
3694 unsigned int event)
3696 if (get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP)
3697 snd_hda_codec_write_cache(codec, nid, 0,
3698 AC_VERB_SET_UNSOLICITED_ENABLE,
3699 (AC_USRSP_EN | event));
3702 static int is_nid_hp_pin(struct auto_pin_cfg *cfg, hda_nid_t nid)
3704 int i;
3705 for (i = 0; i < cfg->hp_outs; i++)
3706 if (cfg->hp_pins[i] == nid)
3707 return 1; /* nid is a HP-Out */
3709 return 0; /* nid is not a HP-Out */
3712 static void stac92xx_power_down(struct hda_codec *codec)
3714 struct sigmatel_spec *spec = codec->spec;
3716 /* power down inactive DACs */
3717 hda_nid_t *dac;
3718 for (dac = spec->dac_list; *dac; dac++)
3719 if (!is_in_dac_nids(spec, *dac) &&
3720 spec->multiout.hp_nid != *dac)
3721 snd_hda_codec_write_cache(codec, *dac, 0,
3722 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3725 static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
3726 int enable);
3728 static int stac92xx_init(struct hda_codec *codec)
3730 struct sigmatel_spec *spec = codec->spec;
3731 struct auto_pin_cfg *cfg = &spec->autocfg;
3732 unsigned int gpio;
3733 int i;
3735 snd_hda_sequence_write(codec, spec->init);
3737 /* power down adcs initially */
3738 if (spec->powerdown_adcs)
3739 for (i = 0; i < spec->num_adcs; i++)
3740 snd_hda_codec_write_cache(codec,
3741 spec->adc_nids[i], 0,
3742 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3744 /* set up GPIO */
3745 gpio = spec->gpio_data;
3746 /* turn on EAPD statically when spec->eapd_switch isn't set.
3747 * otherwise, unsol event will turn it on/off dynamically
3749 if (!spec->eapd_switch)
3750 gpio |= spec->eapd_mask;
3751 stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, gpio);
3753 /* set up pins */
3754 if (spec->hp_detect) {
3755 /* Enable unsolicited responses on the HP widget */
3756 for (i = 0; i < cfg->hp_outs; i++)
3757 enable_pin_detect(codec, cfg->hp_pins[i],
3758 STAC_HP_EVENT);
3759 /* force to enable the first line-out; the others are set up
3760 * in unsol_event
3762 stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
3763 AC_PINCTL_OUT_EN);
3764 stac92xx_auto_init_hp_out(codec);
3765 /* fake event to set up pins */
3766 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
3767 } else {
3768 stac92xx_auto_init_multi_out(codec);
3769 stac92xx_auto_init_hp_out(codec);
3771 for (i = 0; i < AUTO_PIN_LAST; i++) {
3772 hda_nid_t nid = cfg->input_pins[i];
3773 if (nid) {
3774 unsigned int pinctl;
3775 if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC) {
3776 /* for mic pins, force to initialize */
3777 pinctl = stac92xx_get_vref(codec, nid);
3778 } else {
3779 pinctl = snd_hda_codec_read(codec, nid, 0,
3780 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3781 /* if PINCTL already set then skip */
3782 if (pinctl & AC_PINCTL_IN_EN)
3783 continue;
3785 pinctl |= AC_PINCTL_IN_EN;
3786 stac92xx_auto_set_pinctl(codec, nid, pinctl);
3789 for (i = 0; i < spec->num_dmics; i++)
3790 stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
3791 AC_PINCTL_IN_EN);
3792 if (cfg->dig_out_pin)
3793 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pin,
3794 AC_PINCTL_OUT_EN);
3795 if (cfg->dig_in_pin)
3796 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
3797 AC_PINCTL_IN_EN);
3798 for (i = 0; i < spec->num_pwrs; i++) {
3799 hda_nid_t nid = spec->pwr_nids[i];
3800 int pinctl, def_conf;
3801 int event = STAC_PWR_EVENT;
3803 if (is_nid_hp_pin(cfg, nid) && spec->hp_detect)
3804 continue; /* already has an unsol event */
3806 pinctl = snd_hda_codec_read(codec, nid, 0,
3807 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3808 /* outputs are only ports capable of power management
3809 * any attempts on powering down a input port cause the
3810 * referenced VREF to act quirky.
3812 if (pinctl & AC_PINCTL_IN_EN)
3813 continue;
3814 def_conf = snd_hda_codec_read(codec, nid, 0,
3815 AC_VERB_GET_CONFIG_DEFAULT, 0);
3816 def_conf = get_defcfg_connect(def_conf);
3817 /* skip any ports that don't have jacks since presence
3818 * detection is useless */
3819 if (def_conf != AC_JACK_PORT_COMPLEX) {
3820 if (def_conf != AC_JACK_PORT_NONE)
3821 stac_toggle_power_map(codec, nid, 1);
3822 continue;
3824 enable_pin_detect(codec, spec->pwr_nids[i], event | i);
3825 codec->patch_ops.unsol_event(codec, (event | i) << 26);
3827 if (spec->dac_list)
3828 stac92xx_power_down(codec);
3829 return 0;
3832 static void stac92xx_free(struct hda_codec *codec)
3834 struct sigmatel_spec *spec = codec->spec;
3835 int i;
3837 if (! spec)
3838 return;
3840 if (spec->kctl_alloc) {
3841 for (i = 0; i < spec->num_kctl_used; i++)
3842 kfree(spec->kctl_alloc[i].name);
3843 kfree(spec->kctl_alloc);
3846 if (spec->bios_pin_configs)
3847 kfree(spec->bios_pin_configs);
3849 kfree(spec);
3850 snd_hda_detach_beep_device(codec);
3853 static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
3854 unsigned int flag)
3856 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
3857 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
3859 if (pin_ctl & AC_PINCTL_IN_EN) {
3861 * we need to check the current set-up direction of
3862 * shared input pins since they can be switched via
3863 * "xxx as Output" mixer switch
3865 struct sigmatel_spec *spec = codec->spec;
3866 struct auto_pin_cfg *cfg = &spec->autocfg;
3867 if ((nid == cfg->input_pins[AUTO_PIN_LINE] &&
3868 spec->line_switch) ||
3869 (nid == cfg->input_pins[AUTO_PIN_MIC] &&
3870 spec->mic_switch))
3871 return;
3874 /* if setting pin direction bits, clear the current
3875 direction bits first */
3876 if (flag & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))
3877 pin_ctl &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
3879 snd_hda_codec_write_cache(codec, nid, 0,
3880 AC_VERB_SET_PIN_WIDGET_CONTROL,
3881 pin_ctl | flag);
3884 static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
3885 unsigned int flag)
3887 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
3888 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
3889 snd_hda_codec_write_cache(codec, nid, 0,
3890 AC_VERB_SET_PIN_WIDGET_CONTROL,
3891 pin_ctl & ~flag);
3894 static int get_hp_pin_presence(struct hda_codec *codec, hda_nid_t nid)
3896 if (!nid)
3897 return 0;
3898 if (snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PIN_SENSE, 0x00)
3899 & (1 << 31)) {
3900 unsigned int pinctl;
3901 pinctl = snd_hda_codec_read(codec, nid, 0,
3902 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3903 if (pinctl & AC_PINCTL_IN_EN)
3904 return 0; /* mic- or line-input */
3905 else
3906 return 1; /* HP-output */
3908 return 0;
3911 /* return non-zero if the hp-pin of the given array index isn't
3912 * a jack-detection target
3914 static int no_hp_sensing(struct sigmatel_spec *spec, int i)
3916 struct auto_pin_cfg *cfg = &spec->autocfg;
3918 /* ignore sensing of shared line and mic jacks */
3919 if (spec->line_switch &&
3920 cfg->hp_pins[i] == cfg->input_pins[AUTO_PIN_LINE])
3921 return 1;
3922 if (spec->mic_switch &&
3923 cfg->hp_pins[i] == cfg->input_pins[AUTO_PIN_MIC])
3924 return 1;
3925 /* ignore if the pin is set as line-out */
3926 if (cfg->hp_pins[i] == spec->hp_switch)
3927 return 1;
3928 return 0;
3931 static void stac92xx_hp_detect(struct hda_codec *codec, unsigned int res)
3933 struct sigmatel_spec *spec = codec->spec;
3934 struct auto_pin_cfg *cfg = &spec->autocfg;
3935 int i, presence;
3937 presence = 0;
3938 if (spec->gpio_mute)
3939 presence = !(snd_hda_codec_read(codec, codec->afg, 0,
3940 AC_VERB_GET_GPIO_DATA, 0) & spec->gpio_mute);
3942 for (i = 0; i < cfg->hp_outs; i++) {
3943 if (presence)
3944 break;
3945 if (no_hp_sensing(spec, i))
3946 continue;
3947 presence = get_hp_pin_presence(codec, cfg->hp_pins[i]);
3950 if (presence) {
3951 /* disable lineouts */
3952 if (spec->hp_switch)
3953 stac92xx_reset_pinctl(codec, spec->hp_switch,
3954 AC_PINCTL_OUT_EN);
3955 for (i = 0; i < cfg->line_outs; i++)
3956 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
3957 AC_PINCTL_OUT_EN);
3958 for (i = 0; i < cfg->speaker_outs; i++)
3959 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
3960 AC_PINCTL_OUT_EN);
3961 if (spec->eapd_mask && spec->eapd_switch)
3962 stac_gpio_set(codec, spec->gpio_mask,
3963 spec->gpio_dir, spec->gpio_data &
3964 ~spec->eapd_mask);
3965 } else {
3966 /* enable lineouts */
3967 if (spec->hp_switch)
3968 stac92xx_set_pinctl(codec, spec->hp_switch,
3969 AC_PINCTL_OUT_EN);
3970 for (i = 0; i < cfg->line_outs; i++)
3971 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
3972 AC_PINCTL_OUT_EN);
3973 for (i = 0; i < cfg->speaker_outs; i++)
3974 stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
3975 AC_PINCTL_OUT_EN);
3976 if (spec->eapd_mask && spec->eapd_switch)
3977 stac_gpio_set(codec, spec->gpio_mask,
3978 spec->gpio_dir, spec->gpio_data |
3979 spec->eapd_mask);
3981 /* toggle hp outs */
3982 for (i = 0; i < cfg->hp_outs; i++) {
3983 unsigned int val = AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN;
3984 if (no_hp_sensing(spec, i))
3985 continue;
3986 if (presence)
3987 stac92xx_set_pinctl(codec, cfg->hp_pins[i], val);
3988 #if 0 /* FIXME */
3989 /* Resetting the pinctl like below may lead to (a sort of) regressions
3990 * on some devices since they use the HP pin actually for line/speaker
3991 * outs although the default pin config shows a different pin (that is
3992 * wrong and useless).
3994 * So, it's basically a problem of default pin configs, likely a BIOS issue.
3995 * But, disabling the code below just works around it, and I'm too tired of
3996 * bug reports with such devices...
3998 else
3999 stac92xx_reset_pinctl(codec, cfg->hp_pins[i], val);
4000 #endif /* FIXME */
4004 static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
4005 int enable)
4007 struct sigmatel_spec *spec = codec->spec;
4008 unsigned int idx, val;
4010 for (idx = 0; idx < spec->num_pwrs; idx++) {
4011 if (spec->pwr_nids[idx] == nid)
4012 break;
4014 if (idx >= spec->num_pwrs)
4015 return;
4017 /* several codecs have two power down bits */
4018 if (spec->pwr_mapping)
4019 idx = spec->pwr_mapping[idx];
4020 else
4021 idx = 1 << idx;
4023 val = snd_hda_codec_read(codec, codec->afg, 0, 0x0fec, 0x0) & 0xff;
4024 if (enable)
4025 val &= ~idx;
4026 else
4027 val |= idx;
4029 /* power down unused output ports */
4030 snd_hda_codec_write(codec, codec->afg, 0, 0x7ec, val);
4033 static void stac92xx_pin_sense(struct hda_codec *codec, hda_nid_t nid)
4035 stac_toggle_power_map(codec, nid, get_hp_pin_presence(codec, nid));
4038 static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
4040 struct sigmatel_spec *spec = codec->spec;
4041 int idx = res >> 26 & 0x0f;
4043 switch ((res >> 26) & 0x70) {
4044 case STAC_HP_EVENT:
4045 stac92xx_hp_detect(codec, res);
4046 /* fallthru */
4047 case STAC_PWR_EVENT:
4048 if (spec->num_pwrs > 0)
4049 stac92xx_pin_sense(codec, idx);
4050 break;
4051 case STAC_VREF_EVENT: {
4052 int data = snd_hda_codec_read(codec, codec->afg, 0,
4053 AC_VERB_GET_GPIO_DATA, 0);
4054 /* toggle VREF state based on GPIOx status */
4055 snd_hda_codec_write(codec, codec->afg, 0, 0x7e0,
4056 !!(data & (1 << idx)));
4057 break;
4062 #ifdef SND_HDA_NEEDS_RESUME
4063 static int stac92xx_resume(struct hda_codec *codec)
4065 struct sigmatel_spec *spec = codec->spec;
4067 stac92xx_set_config_regs(codec);
4068 snd_hda_sequence_write(codec, spec->init);
4069 stac_gpio_set(codec, spec->gpio_mask,
4070 spec->gpio_dir, spec->gpio_data);
4071 snd_hda_codec_resume_amp(codec);
4072 snd_hda_codec_resume_cache(codec);
4073 /* power down inactive DACs */
4074 if (spec->dac_list)
4075 stac92xx_power_down(codec);
4076 /* invoke unsolicited event to reset the HP state */
4077 if (spec->hp_detect)
4078 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
4079 return 0;
4081 #endif
4083 static struct hda_codec_ops stac92xx_patch_ops = {
4084 .build_controls = stac92xx_build_controls,
4085 .build_pcms = stac92xx_build_pcms,
4086 .init = stac92xx_init,
4087 .free = stac92xx_free,
4088 .unsol_event = stac92xx_unsol_event,
4089 #ifdef SND_HDA_NEEDS_RESUME
4090 .resume = stac92xx_resume,
4091 #endif
4094 static int patch_stac9200(struct hda_codec *codec)
4096 struct sigmatel_spec *spec;
4097 int err;
4099 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4100 if (spec == NULL)
4101 return -ENOMEM;
4103 codec->spec = spec;
4104 spec->num_pins = ARRAY_SIZE(stac9200_pin_nids);
4105 spec->pin_nids = stac9200_pin_nids;
4106 spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS,
4107 stac9200_models,
4108 stac9200_cfg_tbl);
4109 if (spec->board_config < 0) {
4110 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9200, using BIOS defaults\n");
4111 err = stac92xx_save_bios_config_regs(codec);
4112 if (err < 0) {
4113 stac92xx_free(codec);
4114 return err;
4116 spec->pin_configs = spec->bios_pin_configs;
4117 } else {
4118 spec->pin_configs = stac9200_brd_tbl[spec->board_config];
4119 stac92xx_set_config_regs(codec);
4122 spec->multiout.max_channels = 2;
4123 spec->multiout.num_dacs = 1;
4124 spec->multiout.dac_nids = stac9200_dac_nids;
4125 spec->adc_nids = stac9200_adc_nids;
4126 spec->mux_nids = stac9200_mux_nids;
4127 spec->num_muxes = 1;
4128 spec->num_dmics = 0;
4129 spec->num_adcs = 1;
4130 spec->num_pwrs = 0;
4132 if (spec->board_config == STAC_9200_GATEWAY ||
4133 spec->board_config == STAC_9200_OQO)
4134 spec->init = stac9200_eapd_init;
4135 else
4136 spec->init = stac9200_core_init;
4137 spec->mixer = stac9200_mixer;
4139 if (spec->board_config == STAC_9200_PANASONIC) {
4140 spec->gpio_mask = spec->gpio_dir = 0x09;
4141 spec->gpio_data = 0x00;
4144 err = stac9200_parse_auto_config(codec);
4145 if (err < 0) {
4146 stac92xx_free(codec);
4147 return err;
4150 codec->patch_ops = stac92xx_patch_ops;
4152 return 0;
4155 static int patch_stac925x(struct hda_codec *codec)
4157 struct sigmatel_spec *spec;
4158 int err;
4160 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4161 if (spec == NULL)
4162 return -ENOMEM;
4164 codec->spec = spec;
4165 spec->num_pins = ARRAY_SIZE(stac925x_pin_nids);
4166 spec->pin_nids = stac925x_pin_nids;
4167 spec->board_config = snd_hda_check_board_config(codec, STAC_925x_MODELS,
4168 stac925x_models,
4169 stac925x_cfg_tbl);
4170 again:
4171 if (spec->board_config < 0) {
4172 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC925x,"
4173 "using BIOS defaults\n");
4174 err = stac92xx_save_bios_config_regs(codec);
4175 if (err < 0) {
4176 stac92xx_free(codec);
4177 return err;
4179 spec->pin_configs = spec->bios_pin_configs;
4180 } else if (stac925x_brd_tbl[spec->board_config] != NULL){
4181 spec->pin_configs = stac925x_brd_tbl[spec->board_config];
4182 stac92xx_set_config_regs(codec);
4185 spec->multiout.max_channels = 2;
4186 spec->multiout.num_dacs = 1;
4187 spec->multiout.dac_nids = stac925x_dac_nids;
4188 spec->adc_nids = stac925x_adc_nids;
4189 spec->mux_nids = stac925x_mux_nids;
4190 spec->num_muxes = 1;
4191 spec->num_adcs = 1;
4192 spec->num_pwrs = 0;
4193 switch (codec->vendor_id) {
4194 case 0x83847632: /* STAC9202 */
4195 case 0x83847633: /* STAC9202D */
4196 case 0x83847636: /* STAC9251 */
4197 case 0x83847637: /* STAC9251D */
4198 spec->num_dmics = STAC925X_NUM_DMICS;
4199 spec->dmic_nids = stac925x_dmic_nids;
4200 spec->num_dmuxes = ARRAY_SIZE(stac925x_dmux_nids);
4201 spec->dmux_nids = stac925x_dmux_nids;
4202 break;
4203 default:
4204 spec->num_dmics = 0;
4205 break;
4208 spec->init = stac925x_core_init;
4209 spec->mixer = stac925x_mixer;
4211 err = stac92xx_parse_auto_config(codec, 0x8, 0x7);
4212 if (!err) {
4213 if (spec->board_config < 0) {
4214 printk(KERN_WARNING "hda_codec: No auto-config is "
4215 "available, default to model=ref\n");
4216 spec->board_config = STAC_925x_REF;
4217 goto again;
4219 err = -EINVAL;
4221 if (err < 0) {
4222 stac92xx_free(codec);
4223 return err;
4226 codec->patch_ops = stac92xx_patch_ops;
4228 return 0;
4231 static struct hda_input_mux stac92hd73xx_dmux = {
4232 .num_items = 4,
4233 .items = {
4234 { "Analog Inputs", 0x0b },
4235 { "Digital Mic 1", 0x09 },
4236 { "Digital Mic 2", 0x0a },
4237 { "CD", 0x08 },
4241 static int patch_stac92hd73xx(struct hda_codec *codec)
4243 struct sigmatel_spec *spec;
4244 hda_nid_t conn[STAC92HD73_DAC_COUNT + 2];
4245 int err = 0;
4247 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4248 if (spec == NULL)
4249 return -ENOMEM;
4251 codec->spec = spec;
4252 codec->slave_dig_outs = stac92hd73xx_slave_dig_outs;
4253 spec->num_pins = ARRAY_SIZE(stac92hd73xx_pin_nids);
4254 spec->pin_nids = stac92hd73xx_pin_nids;
4255 spec->board_config = snd_hda_check_board_config(codec,
4256 STAC_92HD73XX_MODELS,
4257 stac92hd73xx_models,
4258 stac92hd73xx_cfg_tbl);
4259 again:
4260 if (spec->board_config < 0) {
4261 snd_printdd(KERN_INFO "hda_codec: Unknown model for"
4262 " STAC92HD73XX, using BIOS defaults\n");
4263 err = stac92xx_save_bios_config_regs(codec);
4264 if (err < 0) {
4265 stac92xx_free(codec);
4266 return err;
4268 spec->pin_configs = spec->bios_pin_configs;
4269 } else {
4270 spec->pin_configs = stac92hd73xx_brd_tbl[spec->board_config];
4271 stac92xx_set_config_regs(codec);
4274 spec->multiout.num_dacs = snd_hda_get_connections(codec, 0x0a,
4275 conn, STAC92HD73_DAC_COUNT + 2) - 1;
4277 if (spec->multiout.num_dacs < 0) {
4278 printk(KERN_WARNING "hda_codec: Could not determine "
4279 "number of channels defaulting to DAC count\n");
4280 spec->multiout.num_dacs = STAC92HD73_DAC_COUNT;
4283 switch (spec->multiout.num_dacs) {
4284 case 0x3: /* 6 Channel */
4285 spec->multiout.hp_nid = 0x17;
4286 spec->mixer = stac92hd73xx_6ch_mixer;
4287 spec->init = stac92hd73xx_6ch_core_init;
4288 break;
4289 case 0x4: /* 8 Channel */
4290 spec->multiout.hp_nid = 0x18;
4291 spec->mixer = stac92hd73xx_8ch_mixer;
4292 spec->init = stac92hd73xx_8ch_core_init;
4293 break;
4294 case 0x5: /* 10 Channel */
4295 spec->multiout.hp_nid = 0x19;
4296 spec->mixer = stac92hd73xx_10ch_mixer;
4297 spec->init = stac92hd73xx_10ch_core_init;
4300 spec->multiout.dac_nids = stac92hd73xx_dac_nids;
4301 spec->aloopback_mask = 0x01;
4302 spec->aloopback_shift = 8;
4304 spec->digbeep_nid = 0x1c;
4305 spec->mux_nids = stac92hd73xx_mux_nids;
4306 spec->adc_nids = stac92hd73xx_adc_nids;
4307 spec->dmic_nids = stac92hd73xx_dmic_nids;
4308 spec->dmux_nids = stac92hd73xx_dmux_nids;
4309 spec->smux_nids = stac92hd73xx_smux_nids;
4310 spec->amp_nids = stac92hd73xx_amp_nids;
4311 spec->num_amps = ARRAY_SIZE(stac92hd73xx_amp_nids);
4313 spec->num_muxes = ARRAY_SIZE(stac92hd73xx_mux_nids);
4314 spec->num_adcs = ARRAY_SIZE(stac92hd73xx_adc_nids);
4315 spec->num_dmuxes = ARRAY_SIZE(stac92hd73xx_dmux_nids);
4316 memcpy(&spec->private_dimux, &stac92hd73xx_dmux,
4317 sizeof(stac92hd73xx_dmux));
4319 switch (spec->board_config) {
4320 case STAC_DELL_EQ:
4321 spec->init = dell_eq_core_init;
4322 /* fallthru */
4323 case STAC_DELL_M6_AMIC:
4324 case STAC_DELL_M6_DMIC:
4325 case STAC_DELL_M6_BOTH:
4326 spec->num_smuxes = 0;
4327 spec->mixer = &stac92hd73xx_6ch_mixer[DELL_M6_MIXER];
4328 spec->amp_nids = &stac92hd73xx_amp_nids[DELL_M6_AMP];
4329 spec->eapd_switch = 0;
4330 spec->num_amps = 1;
4331 spec->multiout.hp_nid = 0; /* dual HPs */
4333 if (!spec->init)
4334 spec->init = dell_m6_core_init;
4335 switch (spec->board_config) {
4336 case STAC_DELL_M6_AMIC: /* Analog Mics */
4337 stac92xx_set_config_reg(codec, 0x0b, 0x90A70170);
4338 spec->num_dmics = 0;
4339 spec->private_dimux.num_items = 1;
4340 break;
4341 case STAC_DELL_M6_DMIC: /* Digital Mics */
4342 stac92xx_set_config_reg(codec, 0x13, 0x90A60160);
4343 spec->num_dmics = 1;
4344 spec->private_dimux.num_items = 2;
4345 break;
4346 case STAC_DELL_M6_BOTH: /* Both */
4347 stac92xx_set_config_reg(codec, 0x0b, 0x90A70170);
4348 stac92xx_set_config_reg(codec, 0x13, 0x90A60160);
4349 spec->num_dmics = 1;
4350 spec->private_dimux.num_items = 2;
4351 break;
4353 break;
4354 default:
4355 spec->num_dmics = STAC92HD73XX_NUM_DMICS;
4356 spec->num_smuxes = ARRAY_SIZE(stac92hd73xx_smux_nids);
4357 spec->eapd_switch = 1;
4359 if (spec->board_config > STAC_92HD73XX_REF) {
4360 /* GPIO0 High = Enable EAPD */
4361 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
4362 spec->gpio_data = 0x01;
4364 spec->dinput_mux = &spec->private_dimux;
4366 spec->num_pwrs = ARRAY_SIZE(stac92hd73xx_pwr_nids);
4367 spec->pwr_nids = stac92hd73xx_pwr_nids;
4369 err = stac92xx_parse_auto_config(codec, 0x25, 0x27);
4371 if (!err) {
4372 if (spec->board_config < 0) {
4373 printk(KERN_WARNING "hda_codec: No auto-config is "
4374 "available, default to model=ref\n");
4375 spec->board_config = STAC_92HD73XX_REF;
4376 goto again;
4378 err = -EINVAL;
4381 if (err < 0) {
4382 stac92xx_free(codec);
4383 return err;
4386 if (spec->board_config == STAC_92HD73XX_NO_JD)
4387 spec->hp_detect = 0;
4389 codec->patch_ops = stac92xx_patch_ops;
4391 return 0;
4394 static struct hda_input_mux stac92hd83xxx_dmux = {
4395 .num_items = 3,
4396 .items = {
4397 { "Analog Inputs", 0x03 },
4398 { "Digital Mic 1", 0x04 },
4399 { "Digital Mic 2", 0x05 },
4403 static int patch_stac92hd83xxx(struct hda_codec *codec)
4405 struct sigmatel_spec *spec;
4406 int err;
4408 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4409 if (spec == NULL)
4410 return -ENOMEM;
4412 codec->spec = spec;
4413 codec->slave_dig_outs = stac92hd83xxx_slave_dig_outs;
4414 spec->mono_nid = 0x19;
4415 spec->digbeep_nid = 0x21;
4416 spec->dmic_nids = stac92hd83xxx_dmic_nids;
4417 spec->dmux_nids = stac92hd83xxx_dmux_nids;
4418 spec->adc_nids = stac92hd83xxx_adc_nids;
4419 spec->pwr_nids = stac92hd83xxx_pwr_nids;
4420 spec->pwr_mapping = stac92hd83xxx_pwr_mapping;
4421 spec->num_pwrs = ARRAY_SIZE(stac92hd83xxx_pwr_nids);
4422 spec->multiout.dac_nids = stac92hd83xxx_dac_nids;
4424 spec->init = stac92hd83xxx_core_init;
4425 switch (codec->vendor_id) {
4426 case 0x111d7605:
4427 spec->multiout.num_dacs = STAC92HD81_DAC_COUNT;
4428 break;
4429 default:
4430 spec->num_pwrs--;
4431 spec->init++; /* switch to config #2 */
4432 spec->multiout.num_dacs = STAC92HD83_DAC_COUNT;
4435 spec->mixer = stac92hd83xxx_mixer;
4436 spec->num_pins = ARRAY_SIZE(stac92hd83xxx_pin_nids);
4437 spec->num_dmuxes = ARRAY_SIZE(stac92hd83xxx_dmux_nids);
4438 spec->num_adcs = ARRAY_SIZE(stac92hd83xxx_adc_nids);
4439 spec->num_dmics = STAC92HD83XXX_NUM_DMICS;
4440 spec->dinput_mux = &stac92hd83xxx_dmux;
4441 spec->pin_nids = stac92hd83xxx_pin_nids;
4442 spec->board_config = snd_hda_check_board_config(codec,
4443 STAC_92HD83XXX_MODELS,
4444 stac92hd83xxx_models,
4445 stac92hd83xxx_cfg_tbl);
4446 again:
4447 if (spec->board_config < 0) {
4448 snd_printdd(KERN_INFO "hda_codec: Unknown model for"
4449 " STAC92HD83XXX, using BIOS defaults\n");
4450 err = stac92xx_save_bios_config_regs(codec);
4451 if (err < 0) {
4452 stac92xx_free(codec);
4453 return err;
4455 spec->pin_configs = spec->bios_pin_configs;
4456 } else {
4457 spec->pin_configs = stac92hd83xxx_brd_tbl[spec->board_config];
4458 stac92xx_set_config_regs(codec);
4461 err = stac92xx_parse_auto_config(codec, 0x1d, 0);
4462 if (!err) {
4463 if (spec->board_config < 0) {
4464 printk(KERN_WARNING "hda_codec: No auto-config is "
4465 "available, default to model=ref\n");
4466 spec->board_config = STAC_92HD83XXX_REF;
4467 goto again;
4469 err = -EINVAL;
4472 if (err < 0) {
4473 stac92xx_free(codec);
4474 return err;
4477 codec->patch_ops = stac92xx_patch_ops;
4479 return 0;
4482 #ifdef SND_HDA_NEEDS_RESUME
4483 static void stac92hd71xx_set_power_state(struct hda_codec *codec, int pwr)
4485 struct sigmatel_spec *spec = codec->spec;
4486 int i;
4487 snd_hda_codec_write_cache(codec, codec->afg, 0,
4488 AC_VERB_SET_POWER_STATE, pwr);
4490 msleep(1);
4491 for (i = 0; i < spec->num_adcs; i++) {
4492 snd_hda_codec_write_cache(codec,
4493 spec->adc_nids[i], 0,
4494 AC_VERB_SET_POWER_STATE, pwr);
4498 static int stac92hd71xx_resume(struct hda_codec *codec)
4500 stac92hd71xx_set_power_state(codec, AC_PWRST_D0);
4501 return stac92xx_resume(codec);
4504 static int stac92hd71xx_suspend(struct hda_codec *codec, pm_message_t state)
4506 struct sigmatel_spec *spec = codec->spec;
4508 stac92hd71xx_set_power_state(codec, AC_PWRST_D3);
4509 if (spec->eapd_mask)
4510 stac_gpio_set(codec, spec->gpio_mask,
4511 spec->gpio_dir, spec->gpio_data &
4512 ~spec->eapd_mask);
4513 return 0;
4516 #endif
4518 static struct hda_codec_ops stac92hd71bxx_patch_ops = {
4519 .build_controls = stac92xx_build_controls,
4520 .build_pcms = stac92xx_build_pcms,
4521 .init = stac92xx_init,
4522 .free = stac92xx_free,
4523 .unsol_event = stac92xx_unsol_event,
4524 #ifdef SND_HDA_NEEDS_RESUME
4525 .resume = stac92hd71xx_resume,
4526 .suspend = stac92hd71xx_suspend,
4527 #endif
4530 static struct hda_input_mux stac92hd71bxx_dmux = {
4531 .num_items = 4,
4532 .items = {
4533 { "Analog Inputs", 0x00 },
4534 { "Mixer", 0x01 },
4535 { "Digital Mic 1", 0x02 },
4536 { "Digital Mic 2", 0x03 },
4540 static int patch_stac92hd71bxx(struct hda_codec *codec)
4542 struct sigmatel_spec *spec;
4543 int err = 0;
4545 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4546 if (spec == NULL)
4547 return -ENOMEM;
4549 codec->spec = spec;
4550 codec->patch_ops = stac92xx_patch_ops;
4551 spec->num_pins = ARRAY_SIZE(stac92hd71bxx_pin_nids);
4552 spec->num_pwrs = ARRAY_SIZE(stac92hd71bxx_pwr_nids);
4553 spec->pin_nids = stac92hd71bxx_pin_nids;
4554 memcpy(&spec->private_dimux, &stac92hd71bxx_dmux,
4555 sizeof(stac92hd71bxx_dmux));
4556 spec->board_config = snd_hda_check_board_config(codec,
4557 STAC_92HD71BXX_MODELS,
4558 stac92hd71bxx_models,
4559 stac92hd71bxx_cfg_tbl);
4560 again:
4561 if (spec->board_config < 0) {
4562 snd_printdd(KERN_INFO "hda_codec: Unknown model for"
4563 " STAC92HD71BXX, using BIOS defaults\n");
4564 err = stac92xx_save_bios_config_regs(codec);
4565 if (err < 0) {
4566 stac92xx_free(codec);
4567 return err;
4569 spec->pin_configs = spec->bios_pin_configs;
4570 } else {
4571 spec->pin_configs = stac92hd71bxx_brd_tbl[spec->board_config];
4572 stac92xx_set_config_regs(codec);
4575 if (spec->board_config > STAC_92HD71BXX_REF) {
4576 /* GPIO0 = EAPD */
4577 spec->gpio_mask = 0x01;
4578 spec->gpio_dir = 0x01;
4579 spec->gpio_data = 0x01;
4582 switch (codec->vendor_id) {
4583 case 0x111d76b6: /* 4 Port without Analog Mixer */
4584 case 0x111d76b7:
4585 case 0x111d76b4: /* 6 Port without Analog Mixer */
4586 case 0x111d76b5:
4587 spec->mixer = stac92hd71bxx_mixer;
4588 spec->init = stac92hd71bxx_core_init;
4589 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
4590 break;
4591 case 0x111d7608: /* 5 Port with Analog Mixer */
4592 switch (spec->board_config) {
4593 case STAC_HP_M4:
4594 /* Enable VREF power saving on GPIO1 detect */
4595 snd_hda_codec_write_cache(codec, codec->afg, 0,
4596 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x02);
4597 snd_hda_codec_write_cache(codec, codec->afg, 0,
4598 AC_VERB_SET_UNSOLICITED_ENABLE,
4599 (AC_USRSP_EN | STAC_VREF_EVENT | 0x01));
4600 spec->gpio_mask |= 0x02;
4601 break;
4603 if ((codec->revision_id & 0xf) == 0 ||
4604 (codec->revision_id & 0xf) == 1) {
4605 #ifdef SND_HDA_NEEDS_RESUME
4606 codec->patch_ops = stac92hd71bxx_patch_ops;
4607 #endif
4608 spec->stream_delay = 40; /* 40 milliseconds */
4611 /* no output amps */
4612 spec->num_pwrs = 0;
4613 spec->mixer = stac92hd71bxx_analog_mixer;
4614 spec->dinput_mux = &spec->private_dimux;
4616 /* disable VSW */
4617 spec->init = &stac92hd71bxx_analog_core_init[HD_DISABLE_PORTF];
4618 stac92xx_set_config_reg(codec, 0xf, 0x40f000f0);
4619 break;
4620 case 0x111d7603: /* 6 Port with Analog Mixer */
4621 if ((codec->revision_id & 0xf) == 1) {
4622 #ifdef SND_HDA_NEEDS_RESUME
4623 codec->patch_ops = stac92hd71bxx_patch_ops;
4624 #endif
4625 spec->stream_delay = 40; /* 40 milliseconds */
4628 /* no output amps */
4629 spec->num_pwrs = 0;
4630 /* fallthru */
4631 default:
4632 spec->dinput_mux = &spec->private_dimux;
4633 spec->mixer = stac92hd71bxx_analog_mixer;
4634 spec->init = stac92hd71bxx_analog_core_init;
4635 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
4638 spec->aloopback_mask = 0x50;
4639 spec->aloopback_shift = 0;
4641 spec->powerdown_adcs = 1;
4642 spec->digbeep_nid = 0x26;
4643 spec->mux_nids = stac92hd71bxx_mux_nids;
4644 spec->adc_nids = stac92hd71bxx_adc_nids;
4645 spec->dmic_nids = stac92hd71bxx_dmic_nids;
4646 spec->dmux_nids = stac92hd71bxx_dmux_nids;
4647 spec->smux_nids = stac92hd71bxx_smux_nids;
4648 spec->pwr_nids = stac92hd71bxx_pwr_nids;
4650 spec->num_muxes = ARRAY_SIZE(stac92hd71bxx_mux_nids);
4651 spec->num_adcs = ARRAY_SIZE(stac92hd71bxx_adc_nids);
4653 switch (spec->board_config) {
4654 case STAC_HP_M4:
4655 /* enable internal microphone */
4656 stac92xx_set_config_reg(codec, 0x0e, 0x01813040);
4657 stac92xx_auto_set_pinctl(codec, 0x0e,
4658 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80);
4659 /* fallthru */
4660 case STAC_DELL_M4_2:
4661 spec->num_dmics = 0;
4662 spec->num_smuxes = 0;
4663 spec->num_dmuxes = 0;
4664 break;
4665 case STAC_DELL_M4_1:
4666 case STAC_DELL_M4_3:
4667 spec->num_dmics = 1;
4668 spec->num_smuxes = 0;
4669 spec->num_dmuxes = 0;
4670 break;
4671 default:
4672 spec->num_dmics = STAC92HD71BXX_NUM_DMICS;
4673 spec->num_smuxes = ARRAY_SIZE(stac92hd71bxx_smux_nids);
4674 spec->num_dmuxes = ARRAY_SIZE(stac92hd71bxx_dmux_nids);
4677 spec->multiout.num_dacs = 1;
4678 spec->multiout.hp_nid = 0x11;
4679 spec->multiout.dac_nids = stac92hd71bxx_dac_nids;
4680 if (spec->dinput_mux)
4681 spec->private_dimux.num_items +=
4682 spec->num_dmics -
4683 (ARRAY_SIZE(stac92hd71bxx_dmic_nids) - 1);
4685 err = stac92xx_parse_auto_config(codec, 0x21, 0x23);
4686 if (!err) {
4687 if (spec->board_config < 0) {
4688 printk(KERN_WARNING "hda_codec: No auto-config is "
4689 "available, default to model=ref\n");
4690 spec->board_config = STAC_92HD71BXX_REF;
4691 goto again;
4693 err = -EINVAL;
4696 if (err < 0) {
4697 stac92xx_free(codec);
4698 return err;
4701 return 0;
4704 static int patch_stac922x(struct hda_codec *codec)
4706 struct sigmatel_spec *spec;
4707 int err;
4709 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4710 if (spec == NULL)
4711 return -ENOMEM;
4713 codec->spec = spec;
4714 spec->num_pins = ARRAY_SIZE(stac922x_pin_nids);
4715 spec->pin_nids = stac922x_pin_nids;
4716 spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS,
4717 stac922x_models,
4718 stac922x_cfg_tbl);
4719 if (spec->board_config == STAC_INTEL_MAC_AUTO) {
4720 spec->gpio_mask = spec->gpio_dir = 0x03;
4721 spec->gpio_data = 0x03;
4722 /* Intel Macs have all same PCI SSID, so we need to check
4723 * codec SSID to distinguish the exact models
4725 printk(KERN_INFO "hda_codec: STAC922x, Apple subsys_id=%x\n", codec->subsystem_id);
4726 switch (codec->subsystem_id) {
4728 case 0x106b0800:
4729 spec->board_config = STAC_INTEL_MAC_V1;
4730 break;
4731 case 0x106b0600:
4732 case 0x106b0700:
4733 spec->board_config = STAC_INTEL_MAC_V2;
4734 break;
4735 case 0x106b0e00:
4736 case 0x106b0f00:
4737 case 0x106b1600:
4738 case 0x106b1700:
4739 case 0x106b0200:
4740 case 0x106b1e00:
4741 spec->board_config = STAC_INTEL_MAC_V3;
4742 break;
4743 case 0x106b1a00:
4744 case 0x00000100:
4745 spec->board_config = STAC_INTEL_MAC_V4;
4746 break;
4747 case 0x106b0a00:
4748 case 0x106b2200:
4749 spec->board_config = STAC_INTEL_MAC_V5;
4750 break;
4751 default:
4752 spec->board_config = STAC_INTEL_MAC_V3;
4753 break;
4757 again:
4758 if (spec->board_config < 0) {
4759 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC922x, "
4760 "using BIOS defaults\n");
4761 err = stac92xx_save_bios_config_regs(codec);
4762 if (err < 0) {
4763 stac92xx_free(codec);
4764 return err;
4766 spec->pin_configs = spec->bios_pin_configs;
4767 } else if (stac922x_brd_tbl[spec->board_config] != NULL) {
4768 spec->pin_configs = stac922x_brd_tbl[spec->board_config];
4769 stac92xx_set_config_regs(codec);
4772 spec->adc_nids = stac922x_adc_nids;
4773 spec->mux_nids = stac922x_mux_nids;
4774 spec->num_muxes = ARRAY_SIZE(stac922x_mux_nids);
4775 spec->num_adcs = ARRAY_SIZE(stac922x_adc_nids);
4776 spec->num_dmics = 0;
4777 spec->num_pwrs = 0;
4779 spec->init = stac922x_core_init;
4780 spec->mixer = stac922x_mixer;
4782 spec->multiout.dac_nids = spec->dac_nids;
4784 err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
4785 if (!err) {
4786 if (spec->board_config < 0) {
4787 printk(KERN_WARNING "hda_codec: No auto-config is "
4788 "available, default to model=ref\n");
4789 spec->board_config = STAC_D945_REF;
4790 goto again;
4792 err = -EINVAL;
4794 if (err < 0) {
4795 stac92xx_free(codec);
4796 return err;
4799 codec->patch_ops = stac92xx_patch_ops;
4801 /* Fix Mux capture level; max to 2 */
4802 snd_hda_override_amp_caps(codec, 0x12, HDA_OUTPUT,
4803 (0 << AC_AMPCAP_OFFSET_SHIFT) |
4804 (2 << AC_AMPCAP_NUM_STEPS_SHIFT) |
4805 (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4806 (0 << AC_AMPCAP_MUTE_SHIFT));
4808 return 0;
4811 static int patch_stac927x(struct hda_codec *codec)
4813 struct sigmatel_spec *spec;
4814 int err;
4816 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4817 if (spec == NULL)
4818 return -ENOMEM;
4820 codec->spec = spec;
4821 spec->num_pins = ARRAY_SIZE(stac927x_pin_nids);
4822 spec->pin_nids = stac927x_pin_nids;
4823 spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS,
4824 stac927x_models,
4825 stac927x_cfg_tbl);
4826 again:
4827 if (spec->board_config < 0 || !stac927x_brd_tbl[spec->board_config]) {
4828 if (spec->board_config < 0)
4829 snd_printdd(KERN_INFO "hda_codec: Unknown model for"
4830 "STAC927x, using BIOS defaults\n");
4831 err = stac92xx_save_bios_config_regs(codec);
4832 if (err < 0) {
4833 stac92xx_free(codec);
4834 return err;
4836 spec->pin_configs = spec->bios_pin_configs;
4837 } else {
4838 spec->pin_configs = stac927x_brd_tbl[spec->board_config];
4839 stac92xx_set_config_regs(codec);
4842 spec->digbeep_nid = 0x23;
4843 spec->adc_nids = stac927x_adc_nids;
4844 spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
4845 spec->mux_nids = stac927x_mux_nids;
4846 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
4847 spec->smux_nids = stac927x_smux_nids;
4848 spec->num_smuxes = ARRAY_SIZE(stac927x_smux_nids);
4849 spec->spdif_labels = stac927x_spdif_labels;
4850 spec->dac_list = stac927x_dac_nids;
4851 spec->multiout.dac_nids = spec->dac_nids;
4853 switch (spec->board_config) {
4854 case STAC_D965_3ST:
4855 case STAC_D965_5ST:
4856 /* GPIO0 High = Enable EAPD */
4857 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x01;
4858 spec->gpio_data = 0x01;
4859 spec->num_dmics = 0;
4861 spec->init = d965_core_init;
4862 spec->mixer = stac927x_mixer;
4863 break;
4864 case STAC_DELL_BIOS:
4865 switch (codec->subsystem_id) {
4866 case 0x10280209:
4867 case 0x1028022e:
4868 /* correct the device field to SPDIF out */
4869 stac92xx_set_config_reg(codec, 0x21, 0x01442070);
4870 break;
4872 /* configure the analog microphone on some laptops */
4873 stac92xx_set_config_reg(codec, 0x0c, 0x90a79130);
4874 /* correct the front output jack as a hp out */
4875 stac92xx_set_config_reg(codec, 0x0f, 0x0227011f);
4876 /* correct the front input jack as a mic */
4877 stac92xx_set_config_reg(codec, 0x0e, 0x02a79130);
4878 /* fallthru */
4879 case STAC_DELL_3ST:
4880 /* GPIO2 High = Enable EAPD */
4881 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x04;
4882 spec->gpio_data = 0x04;
4883 spec->dmic_nids = stac927x_dmic_nids;
4884 spec->num_dmics = STAC927X_NUM_DMICS;
4886 spec->init = d965_core_init;
4887 spec->mixer = stac927x_mixer;
4888 spec->dmux_nids = stac927x_dmux_nids;
4889 spec->num_dmuxes = ARRAY_SIZE(stac927x_dmux_nids);
4890 break;
4891 default:
4892 if (spec->board_config > STAC_D965_REF) {
4893 /* GPIO0 High = Enable EAPD */
4894 spec->eapd_mask = spec->gpio_mask = 0x01;
4895 spec->gpio_dir = spec->gpio_data = 0x01;
4897 spec->num_dmics = 0;
4899 spec->init = stac927x_core_init;
4900 spec->mixer = stac927x_mixer;
4903 spec->num_pwrs = 0;
4904 spec->aloopback_mask = 0x40;
4905 spec->aloopback_shift = 0;
4906 spec->eapd_switch = 1;
4908 err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
4909 if (!err) {
4910 if (spec->board_config < 0) {
4911 printk(KERN_WARNING "hda_codec: No auto-config is "
4912 "available, default to model=ref\n");
4913 spec->board_config = STAC_D965_REF;
4914 goto again;
4916 err = -EINVAL;
4918 if (err < 0) {
4919 stac92xx_free(codec);
4920 return err;
4923 codec->patch_ops = stac92xx_patch_ops;
4926 * !!FIXME!!
4927 * The STAC927x seem to require fairly long delays for certain
4928 * command sequences. With too short delays (even if the answer
4929 * is set to RIRB properly), it results in the silence output
4930 * on some hardwares like Dell.
4932 * The below flag enables the longer delay (see get_response
4933 * in hda_intel.c).
4935 codec->bus->needs_damn_long_delay = 1;
4937 /* no jack detecion for ref-no-jd model */
4938 if (spec->board_config == STAC_D965_REF_NO_JD)
4939 spec->hp_detect = 0;
4941 return 0;
4944 static int patch_stac9205(struct hda_codec *codec)
4946 struct sigmatel_spec *spec;
4947 int err;
4949 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4950 if (spec == NULL)
4951 return -ENOMEM;
4953 codec->spec = spec;
4954 spec->num_pins = ARRAY_SIZE(stac9205_pin_nids);
4955 spec->pin_nids = stac9205_pin_nids;
4956 spec->board_config = snd_hda_check_board_config(codec, STAC_9205_MODELS,
4957 stac9205_models,
4958 stac9205_cfg_tbl);
4959 again:
4960 if (spec->board_config < 0) {
4961 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9205, using BIOS defaults\n");
4962 err = stac92xx_save_bios_config_regs(codec);
4963 if (err < 0) {
4964 stac92xx_free(codec);
4965 return err;
4967 spec->pin_configs = spec->bios_pin_configs;
4968 } else {
4969 spec->pin_configs = stac9205_brd_tbl[spec->board_config];
4970 stac92xx_set_config_regs(codec);
4973 spec->digbeep_nid = 0x23;
4974 spec->adc_nids = stac9205_adc_nids;
4975 spec->num_adcs = ARRAY_SIZE(stac9205_adc_nids);
4976 spec->mux_nids = stac9205_mux_nids;
4977 spec->num_muxes = ARRAY_SIZE(stac9205_mux_nids);
4978 spec->smux_nids = stac9205_smux_nids;
4979 spec->num_smuxes = ARRAY_SIZE(stac9205_smux_nids);
4980 spec->dmic_nids = stac9205_dmic_nids;
4981 spec->num_dmics = STAC9205_NUM_DMICS;
4982 spec->dmux_nids = stac9205_dmux_nids;
4983 spec->num_dmuxes = ARRAY_SIZE(stac9205_dmux_nids);
4984 spec->num_pwrs = 0;
4986 spec->init = stac9205_core_init;
4987 spec->mixer = stac9205_mixer;
4989 spec->aloopback_mask = 0x40;
4990 spec->aloopback_shift = 0;
4991 spec->eapd_switch = 1;
4992 spec->multiout.dac_nids = spec->dac_nids;
4994 switch (spec->board_config){
4995 case STAC_9205_DELL_M43:
4996 /* Enable SPDIF in/out */
4997 stac92xx_set_config_reg(codec, 0x1f, 0x01441030);
4998 stac92xx_set_config_reg(codec, 0x20, 0x1c410030);
5000 /* Enable unsol response for GPIO4/Dock HP connection */
5001 snd_hda_codec_write_cache(codec, codec->afg, 0,
5002 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x10);
5003 snd_hda_codec_write_cache(codec, codec->afg, 0,
5004 AC_VERB_SET_UNSOLICITED_ENABLE,
5005 (AC_USRSP_EN | STAC_HP_EVENT));
5007 spec->gpio_dir = 0x0b;
5008 spec->eapd_mask = 0x01;
5009 spec->gpio_mask = 0x1b;
5010 spec->gpio_mute = 0x10;
5011 /* GPIO0 High = EAPD, GPIO1 Low = Headphone Mute,
5012 * GPIO3 Low = DRM
5014 spec->gpio_data = 0x01;
5015 break;
5016 case STAC_9205_REF:
5017 /* SPDIF-In enabled */
5018 break;
5019 default:
5020 /* GPIO0 High = EAPD */
5021 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
5022 spec->gpio_data = 0x01;
5023 break;
5026 err = stac92xx_parse_auto_config(codec, 0x1f, 0x20);
5027 if (!err) {
5028 if (spec->board_config < 0) {
5029 printk(KERN_WARNING "hda_codec: No auto-config is "
5030 "available, default to model=ref\n");
5031 spec->board_config = STAC_9205_REF;
5032 goto again;
5034 err = -EINVAL;
5036 if (err < 0) {
5037 stac92xx_free(codec);
5038 return err;
5041 codec->patch_ops = stac92xx_patch_ops;
5043 return 0;
5047 * STAC9872 hack
5050 /* static config for Sony VAIO FE550G and Sony VAIO AR */
5051 static hda_nid_t vaio_dacs[] = { 0x2 };
5052 #define VAIO_HP_DAC 0x5
5053 static hda_nid_t vaio_adcs[] = { 0x8 /*,0x6*/ };
5054 static hda_nid_t vaio_mux_nids[] = { 0x15 };
5056 static struct hda_input_mux vaio_mux = {
5057 .num_items = 3,
5058 .items = {
5059 /* { "HP", 0x0 }, */
5060 { "Mic Jack", 0x1 },
5061 { "Internal Mic", 0x2 },
5062 { "PCM", 0x3 },
5066 static struct hda_verb vaio_init[] = {
5067 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
5068 {0x0a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | STAC_HP_EVENT},
5069 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
5070 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
5071 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
5072 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
5073 {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
5074 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
5075 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
5076 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
5077 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
5078 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
5082 static struct hda_verb vaio_ar_init[] = {
5083 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
5084 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
5085 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
5086 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
5087 /* {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },*/ /* Optical Out */
5088 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
5089 {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
5090 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
5091 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
5092 /* {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},*/ /* Optical Out */
5093 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
5094 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
5095 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
5099 /* bind volumes of both NID 0x02 and 0x05 */
5100 static struct hda_bind_ctls vaio_bind_master_vol = {
5101 .ops = &snd_hda_bind_vol,
5102 .values = {
5103 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
5104 HDA_COMPOSE_AMP_VAL(0x05, 3, 0, HDA_OUTPUT),
5109 /* bind volumes of both NID 0x02 and 0x05 */
5110 static struct hda_bind_ctls vaio_bind_master_sw = {
5111 .ops = &snd_hda_bind_sw,
5112 .values = {
5113 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
5114 HDA_COMPOSE_AMP_VAL(0x05, 3, 0, HDA_OUTPUT),
5119 static struct snd_kcontrol_new vaio_mixer[] = {
5120 HDA_BIND_VOL("Master Playback Volume", &vaio_bind_master_vol),
5121 HDA_BIND_SW("Master Playback Switch", &vaio_bind_master_sw),
5122 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
5123 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
5124 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
5126 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5127 .name = "Capture Source",
5128 .count = 1,
5129 .info = stac92xx_mux_enum_info,
5130 .get = stac92xx_mux_enum_get,
5131 .put = stac92xx_mux_enum_put,
5136 static struct snd_kcontrol_new vaio_ar_mixer[] = {
5137 HDA_BIND_VOL("Master Playback Volume", &vaio_bind_master_vol),
5138 HDA_BIND_SW("Master Playback Switch", &vaio_bind_master_sw),
5139 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
5140 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
5141 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
5142 /*HDA_CODEC_MUTE("Optical Out Switch", 0x10, 0, HDA_OUTPUT),
5143 HDA_CODEC_VOLUME("Optical Out Volume", 0x10, 0, HDA_OUTPUT),*/
5145 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5146 .name = "Capture Source",
5147 .count = 1,
5148 .info = stac92xx_mux_enum_info,
5149 .get = stac92xx_mux_enum_get,
5150 .put = stac92xx_mux_enum_put,
5155 static struct hda_codec_ops stac9872_patch_ops = {
5156 .build_controls = stac92xx_build_controls,
5157 .build_pcms = stac92xx_build_pcms,
5158 .init = stac92xx_init,
5159 .free = stac92xx_free,
5160 #ifdef SND_HDA_NEEDS_RESUME
5161 .resume = stac92xx_resume,
5162 #endif
5165 static int stac9872_vaio_init(struct hda_codec *codec)
5167 int err;
5169 err = stac92xx_init(codec);
5170 if (err < 0)
5171 return err;
5172 if (codec->patch_ops.unsol_event)
5173 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
5174 return 0;
5177 static void stac9872_vaio_hp_detect(struct hda_codec *codec, unsigned int res)
5179 if (get_hp_pin_presence(codec, 0x0a)) {
5180 stac92xx_reset_pinctl(codec, 0x0f, AC_PINCTL_OUT_EN);
5181 stac92xx_set_pinctl(codec, 0x0a, AC_PINCTL_OUT_EN);
5182 } else {
5183 stac92xx_reset_pinctl(codec, 0x0a, AC_PINCTL_OUT_EN);
5184 stac92xx_set_pinctl(codec, 0x0f, AC_PINCTL_OUT_EN);
5188 static void stac9872_vaio_unsol_event(struct hda_codec *codec, unsigned int res)
5190 switch (res >> 26) {
5191 case STAC_HP_EVENT:
5192 stac9872_vaio_hp_detect(codec, res);
5193 break;
5197 static struct hda_codec_ops stac9872_vaio_patch_ops = {
5198 .build_controls = stac92xx_build_controls,
5199 .build_pcms = stac92xx_build_pcms,
5200 .init = stac9872_vaio_init,
5201 .free = stac92xx_free,
5202 .unsol_event = stac9872_vaio_unsol_event,
5203 #ifdef CONFIG_PM
5204 .resume = stac92xx_resume,
5205 #endif
5208 enum { /* FE and SZ series. id=0x83847661 and subsys=0x104D0700 or 104D1000. */
5209 CXD9872RD_VAIO,
5210 /* Unknown. id=0x83847662 and subsys=0x104D1200 or 104D1000. */
5211 STAC9872AK_VAIO,
5212 /* Unknown. id=0x83847661 and subsys=0x104D1200. */
5213 STAC9872K_VAIO,
5214 /* AR Series. id=0x83847664 and subsys=104D1300 */
5215 CXD9872AKD_VAIO,
5216 STAC_9872_MODELS,
5219 static const char *stac9872_models[STAC_9872_MODELS] = {
5220 [CXD9872RD_VAIO] = "vaio",
5221 [CXD9872AKD_VAIO] = "vaio-ar",
5224 static struct snd_pci_quirk stac9872_cfg_tbl[] = {
5225 SND_PCI_QUIRK(0x104d, 0x81e6, "Sony VAIO F/S", CXD9872RD_VAIO),
5226 SND_PCI_QUIRK(0x104d, 0x81ef, "Sony VAIO F/S", CXD9872RD_VAIO),
5227 SND_PCI_QUIRK(0x104d, 0x81fd, "Sony VAIO AR", CXD9872AKD_VAIO),
5228 SND_PCI_QUIRK(0x104d, 0x8205, "Sony VAIO AR", CXD9872AKD_VAIO),
5232 static int patch_stac9872(struct hda_codec *codec)
5234 struct sigmatel_spec *spec;
5235 int board_config;
5237 board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
5238 stac9872_models,
5239 stac9872_cfg_tbl);
5240 if (board_config < 0)
5241 /* unknown config, let generic-parser do its job... */
5242 return snd_hda_parse_generic_codec(codec);
5244 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5245 if (spec == NULL)
5246 return -ENOMEM;
5248 codec->spec = spec;
5249 switch (board_config) {
5250 case CXD9872RD_VAIO:
5251 case STAC9872AK_VAIO:
5252 case STAC9872K_VAIO:
5253 spec->mixer = vaio_mixer;
5254 spec->init = vaio_init;
5255 spec->multiout.max_channels = 2;
5256 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
5257 spec->multiout.dac_nids = vaio_dacs;
5258 spec->multiout.hp_nid = VAIO_HP_DAC;
5259 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
5260 spec->adc_nids = vaio_adcs;
5261 spec->num_pwrs = 0;
5262 spec->input_mux = &vaio_mux;
5263 spec->mux_nids = vaio_mux_nids;
5264 codec->patch_ops = stac9872_vaio_patch_ops;
5265 break;
5267 case CXD9872AKD_VAIO:
5268 spec->mixer = vaio_ar_mixer;
5269 spec->init = vaio_ar_init;
5270 spec->multiout.max_channels = 2;
5271 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
5272 spec->multiout.dac_nids = vaio_dacs;
5273 spec->multiout.hp_nid = VAIO_HP_DAC;
5274 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
5275 spec->num_pwrs = 0;
5276 spec->adc_nids = vaio_adcs;
5277 spec->input_mux = &vaio_mux;
5278 spec->mux_nids = vaio_mux_nids;
5279 codec->patch_ops = stac9872_patch_ops;
5280 break;
5283 return 0;
5288 * patch entries
5290 struct hda_codec_preset snd_hda_preset_sigmatel[] = {
5291 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
5292 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
5293 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
5294 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
5295 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
5296 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
5297 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
5298 { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
5299 { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
5300 { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
5301 { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
5302 { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
5303 { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
5304 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
5305 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
5306 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
5307 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
5308 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
5309 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
5310 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
5311 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
5312 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
5313 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
5314 { .id = 0x83847632, .name = "STAC9202", .patch = patch_stac925x },
5315 { .id = 0x83847633, .name = "STAC9202D", .patch = patch_stac925x },
5316 { .id = 0x83847634, .name = "STAC9250", .patch = patch_stac925x },
5317 { .id = 0x83847635, .name = "STAC9250D", .patch = patch_stac925x },
5318 { .id = 0x83847636, .name = "STAC9251", .patch = patch_stac925x },
5319 { .id = 0x83847637, .name = "STAC9250D", .patch = patch_stac925x },
5320 { .id = 0x83847645, .name = "92HD206X", .patch = patch_stac927x },
5321 { .id = 0x83847646, .name = "92HD206D", .patch = patch_stac927x },
5322 /* The following does not take into account .id=0x83847661 when subsys =
5323 * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
5324 * currently not fully supported.
5326 { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
5327 { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
5328 { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
5329 { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
5330 { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
5331 { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
5332 { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
5333 { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
5334 { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
5335 { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
5336 { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
5337 { .id = 0x111d7603, .name = "92HD75B3X5", .patch = patch_stac92hd71bxx},
5338 { .id = 0x111d7604, .name = "92HD83C1X5", .patch = patch_stac92hd83xxx},
5339 { .id = 0x111d7605, .name = "92HD81B1X5", .patch = patch_stac92hd83xxx},
5340 { .id = 0x111d7608, .name = "92HD75B2X5", .patch = patch_stac92hd71bxx},
5341 { .id = 0x111d7674, .name = "92HD73D1X5", .patch = patch_stac92hd73xx },
5342 { .id = 0x111d7675, .name = "92HD73C1X5", .patch = patch_stac92hd73xx },
5343 { .id = 0x111d7676, .name = "92HD73E1X5", .patch = patch_stac92hd73xx },
5344 { .id = 0x111d76b0, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
5345 { .id = 0x111d76b1, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
5346 { .id = 0x111d76b2, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
5347 { .id = 0x111d76b3, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
5348 { .id = 0x111d76b4, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
5349 { .id = 0x111d76b5, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
5350 { .id = 0x111d76b6, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
5351 { .id = 0x111d76b7, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
5352 {} /* terminator */