ALSA: hda - Integrate Digital Input Source to Input Source
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / sound / pci / hda / patch_sigmatel.c
blob3457f619bad1c4306917cf17172140bace289c0e
1 /*
2 * Universal Interface for Intel High Definition Audio Codec
4 * HD audio interface patch for SigmaTel STAC92xx
6 * Copyright (c) 2005 Embedded Alley Solutions, Inc.
7 * Matt Porter <mporter@embeddedalley.com>
9 * Based on patch_cmedia.c and patch_realtek.c
10 * Copyright (c) 2004 Takashi Iwai <tiwai@suse.de>
12 * This driver is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This driver is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #include <linux/init.h>
28 #include <linux/delay.h>
29 #include <linux/slab.h>
30 #include <linux/pci.h>
31 #include <sound/core.h>
32 #include <sound/asoundef.h>
33 #include <sound/jack.h>
34 #include "hda_codec.h"
35 #include "hda_local.h"
36 #include "hda_beep.h"
38 enum {
39 STAC_VREF_EVENT = 1,
40 STAC_INSERT_EVENT,
41 STAC_PWR_EVENT,
42 STAC_HP_EVENT,
43 STAC_MIC_EVENT,
46 enum {
47 STAC_AUTO,
48 STAC_REF,
49 STAC_9200_OQO,
50 STAC_9200_DELL_D21,
51 STAC_9200_DELL_D22,
52 STAC_9200_DELL_D23,
53 STAC_9200_DELL_M21,
54 STAC_9200_DELL_M22,
55 STAC_9200_DELL_M23,
56 STAC_9200_DELL_M24,
57 STAC_9200_DELL_M25,
58 STAC_9200_DELL_M26,
59 STAC_9200_DELL_M27,
60 STAC_9200_M4,
61 STAC_9200_M4_2,
62 STAC_9200_PANASONIC,
63 STAC_9200_MODELS
66 enum {
67 STAC_9205_AUTO,
68 STAC_9205_REF,
69 STAC_9205_DELL_M42,
70 STAC_9205_DELL_M43,
71 STAC_9205_DELL_M44,
72 STAC_9205_EAPD,
73 STAC_9205_MODELS
76 enum {
77 STAC_92HD73XX_AUTO,
78 STAC_92HD73XX_NO_JD, /* no jack-detection */
79 STAC_92HD73XX_REF,
80 STAC_DELL_M6_AMIC,
81 STAC_DELL_M6_DMIC,
82 STAC_DELL_M6_BOTH,
83 STAC_DELL_EQ,
84 STAC_92HD73XX_MODELS
87 enum {
88 STAC_92HD83XXX_AUTO,
89 STAC_92HD83XXX_REF,
90 STAC_92HD83XXX_PWR_REF,
91 STAC_DELL_S14,
92 STAC_92HD83XXX_MODELS
95 enum {
96 STAC_92HD71BXX_AUTO,
97 STAC_92HD71BXX_REF,
98 STAC_DELL_M4_1,
99 STAC_DELL_M4_2,
100 STAC_DELL_M4_3,
101 STAC_HP_M4,
102 STAC_HP_DV5,
103 STAC_HP_HDX,
104 STAC_HP_DV4_1222NR,
105 STAC_92HD71BXX_MODELS
108 enum {
109 STAC_925x_AUTO,
110 STAC_925x_REF,
111 STAC_M1,
112 STAC_M1_2,
113 STAC_M2,
114 STAC_M2_2,
115 STAC_M3,
116 STAC_M5,
117 STAC_M6,
118 STAC_925x_MODELS
121 enum {
122 STAC_922X_AUTO,
123 STAC_D945_REF,
124 STAC_D945GTP3,
125 STAC_D945GTP5,
126 STAC_INTEL_MAC_V1,
127 STAC_INTEL_MAC_V2,
128 STAC_INTEL_MAC_V3,
129 STAC_INTEL_MAC_V4,
130 STAC_INTEL_MAC_V5,
131 STAC_INTEL_MAC_AUTO, /* This model is selected if no module parameter
132 * is given, one of the above models will be
133 * chosen according to the subsystem id. */
134 /* for backward compatibility */
135 STAC_MACMINI,
136 STAC_MACBOOK,
137 STAC_MACBOOK_PRO_V1,
138 STAC_MACBOOK_PRO_V2,
139 STAC_IMAC_INTEL,
140 STAC_IMAC_INTEL_20,
141 STAC_ECS_202,
142 STAC_922X_DELL_D81,
143 STAC_922X_DELL_D82,
144 STAC_922X_DELL_M81,
145 STAC_922X_DELL_M82,
146 STAC_922X_MODELS
149 enum {
150 STAC_927X_AUTO,
151 STAC_D965_REF_NO_JD, /* no jack-detection */
152 STAC_D965_REF,
153 STAC_D965_3ST,
154 STAC_D965_5ST,
155 STAC_D965_5ST_NO_FP,
156 STAC_DELL_3ST,
157 STAC_DELL_BIOS,
158 STAC_927X_MODELS
161 enum {
162 STAC_9872_AUTO,
163 STAC_9872_VAIO,
164 STAC_9872_MODELS
167 struct sigmatel_event {
168 hda_nid_t nid;
169 unsigned char type;
170 unsigned char tag;
171 int data;
174 struct sigmatel_jack {
175 hda_nid_t nid;
176 int type;
177 struct snd_jack *jack;
180 struct sigmatel_mic_route {
181 hda_nid_t pin;
182 unsigned char mux_idx;
183 unsigned char dmux_idx;
186 struct sigmatel_spec {
187 struct snd_kcontrol_new *mixers[4];
188 unsigned int num_mixers;
190 int board_config;
191 unsigned int eapd_switch: 1;
192 unsigned int surr_switch: 1;
193 unsigned int alt_switch: 1;
194 unsigned int hp_detect: 1;
195 unsigned int spdif_mute: 1;
196 unsigned int check_volume_offset:1;
197 unsigned int auto_mic:1;
199 /* gpio lines */
200 unsigned int eapd_mask;
201 unsigned int gpio_mask;
202 unsigned int gpio_dir;
203 unsigned int gpio_data;
204 unsigned int gpio_mute;
205 unsigned int gpio_led;
207 /* stream */
208 unsigned int stream_delay;
210 /* analog loopback */
211 struct snd_kcontrol_new *aloopback_ctl;
212 unsigned char aloopback_mask;
213 unsigned char aloopback_shift;
215 /* power management */
216 unsigned int num_pwrs;
217 unsigned int *pwr_mapping;
218 hda_nid_t *pwr_nids;
219 hda_nid_t *dac_list;
221 /* jack detection */
222 struct snd_array jacks;
224 /* events */
225 struct snd_array events;
227 /* playback */
228 struct hda_input_mux *mono_mux;
229 struct hda_input_mux *amp_mux;
230 unsigned int cur_mmux;
231 struct hda_multi_out multiout;
232 hda_nid_t dac_nids[5];
233 hda_nid_t hp_dacs[5];
234 hda_nid_t speaker_dacs[5];
236 int volume_offset;
238 /* capture */
239 hda_nid_t *adc_nids;
240 unsigned int num_adcs;
241 hda_nid_t *mux_nids;
242 unsigned int num_muxes;
243 hda_nid_t *dmic_nids;
244 unsigned int num_dmics;
245 hda_nid_t *dmux_nids;
246 unsigned int num_dmuxes;
247 hda_nid_t *smux_nids;
248 unsigned int num_smuxes;
249 unsigned int num_analog_muxes;
251 unsigned long *capvols; /* amp-volume attr: HDA_COMPOSE_AMP_VAL() */
252 unsigned long *capsws; /* amp-mute attr: HDA_COMPOSE_AMP_VAL() */
253 unsigned int num_caps; /* number of capture volume/switch elements */
255 struct sigmatel_mic_route ext_mic;
256 struct sigmatel_mic_route int_mic;
258 const char **spdif_labels;
260 hda_nid_t dig_in_nid;
261 hda_nid_t mono_nid;
262 hda_nid_t anabeep_nid;
263 hda_nid_t digbeep_nid;
265 /* pin widgets */
266 hda_nid_t *pin_nids;
267 unsigned int num_pins;
269 /* codec specific stuff */
270 struct hda_verb *init;
271 struct snd_kcontrol_new *mixer;
273 /* capture source */
274 struct hda_input_mux *dinput_mux;
275 unsigned int cur_dmux[2];
276 struct hda_input_mux *input_mux;
277 unsigned int cur_mux[3];
278 struct hda_input_mux *sinput_mux;
279 unsigned int cur_smux[2];
280 unsigned int cur_amux;
281 hda_nid_t *amp_nids;
282 unsigned int num_amps;
283 unsigned int powerdown_adcs;
285 /* i/o switches */
286 unsigned int io_switch[2];
287 unsigned int clfe_swap;
288 hda_nid_t line_switch; /* shared line-in for input and output */
289 hda_nid_t mic_switch; /* shared mic-in for input and output */
290 hda_nid_t hp_switch; /* NID of HP as line-out */
291 unsigned int aloopback;
293 struct hda_pcm pcm_rec[2]; /* PCM information */
295 /* dynamic controls and input_mux */
296 struct auto_pin_cfg autocfg;
297 struct snd_array kctls;
298 struct hda_input_mux private_dimux;
299 struct hda_input_mux private_imux;
300 struct hda_input_mux private_smux;
301 struct hda_input_mux private_amp_mux;
302 struct hda_input_mux private_mono_mux;
305 static hda_nid_t stac9200_adc_nids[1] = {
306 0x03,
309 static hda_nid_t stac9200_mux_nids[1] = {
310 0x0c,
313 static hda_nid_t stac9200_dac_nids[1] = {
314 0x02,
317 static hda_nid_t stac92hd73xx_pwr_nids[8] = {
318 0x0a, 0x0b, 0x0c, 0xd, 0x0e,
319 0x0f, 0x10, 0x11
322 static hda_nid_t stac92hd73xx_slave_dig_outs[2] = {
323 0x26, 0,
326 static hda_nid_t stac92hd73xx_adc_nids[2] = {
327 0x1a, 0x1b
330 #define DELL_M6_AMP 2
331 static hda_nid_t stac92hd73xx_amp_nids[3] = {
332 0x0b, 0x0c, 0x0e
335 #define STAC92HD73XX_NUM_DMICS 2
336 static hda_nid_t stac92hd73xx_dmic_nids[STAC92HD73XX_NUM_DMICS + 1] = {
337 0x13, 0x14, 0
340 #define STAC92HD73_DAC_COUNT 5
342 static hda_nid_t stac92hd73xx_mux_nids[4] = {
343 0x28, 0x29, 0x2a, 0x2b,
346 static hda_nid_t stac92hd73xx_dmux_nids[2] = {
347 0x20, 0x21,
350 static hda_nid_t stac92hd73xx_smux_nids[2] = {
351 0x22, 0x23,
354 #define STAC92HD73XX_NUM_CAPS 2
355 static unsigned long stac92hd73xx_capvols[] = {
356 HDA_COMPOSE_AMP_VAL(0x20, 3, 0, HDA_OUTPUT),
357 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
359 #define stac92hd73xx_capsws stac92hd73xx_capvols
361 #define STAC92HD83XXX_NUM_DMICS 2
362 static hda_nid_t stac92hd83xxx_dmic_nids[STAC92HD83XXX_NUM_DMICS + 1] = {
363 0x11, 0x12, 0
366 #define STAC92HD83_DAC_COUNT 3
368 static hda_nid_t stac92hd83xxx_dmux_nids[2] = {
369 0x17, 0x18,
372 static hda_nid_t stac92hd83xxx_adc_nids[2] = {
373 0x15, 0x16,
376 static hda_nid_t stac92hd83xxx_pwr_nids[4] = {
377 0xa, 0xb, 0xd, 0xe,
380 static hda_nid_t stac92hd83xxx_slave_dig_outs[2] = {
381 0x1e, 0,
384 static unsigned int stac92hd83xxx_pwr_mapping[4] = {
385 0x03, 0x0c, 0x20, 0x40,
388 static hda_nid_t stac92hd83xxx_amp_nids[1] = {
389 0xc,
392 #define STAC92HD83XXX_NUM_CAPS 2
393 static unsigned long stac92hd83xxx_capvols[] = {
394 HDA_COMPOSE_AMP_VAL(0x17, 3, 0, HDA_OUTPUT),
395 HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_OUTPUT),
397 #define stac92hd83xxx_capsws stac92hd83xxx_capvols
399 static hda_nid_t stac92hd71bxx_pwr_nids[3] = {
400 0x0a, 0x0d, 0x0f
403 static hda_nid_t stac92hd71bxx_adc_nids[2] = {
404 0x12, 0x13,
407 static hda_nid_t stac92hd71bxx_mux_nids[2] = {
408 0x1a, 0x1b
411 static hda_nid_t stac92hd71bxx_dmux_nids[2] = {
412 0x1c, 0x1d,
415 static hda_nid_t stac92hd71bxx_smux_nids[2] = {
416 0x24, 0x25,
419 #define STAC92HD71BXX_NUM_DMICS 2
420 static hda_nid_t stac92hd71bxx_dmic_nids[STAC92HD71BXX_NUM_DMICS + 1] = {
421 0x18, 0x19, 0
424 static hda_nid_t stac92hd71bxx_slave_dig_outs[2] = {
425 0x22, 0
428 #define STAC92HD71BXX_NUM_CAPS 2
429 static unsigned long stac92hd71bxx_capvols[] = {
430 HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_OUTPUT),
431 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
433 #define stac92hd71bxx_capsws stac92hd71bxx_capvols
435 static hda_nid_t stac925x_adc_nids[1] = {
436 0x03,
439 static hda_nid_t stac925x_mux_nids[1] = {
440 0x0f,
443 static hda_nid_t stac925x_dac_nids[1] = {
444 0x02,
447 #define STAC925X_NUM_DMICS 1
448 static hda_nid_t stac925x_dmic_nids[STAC925X_NUM_DMICS + 1] = {
449 0x15, 0
452 static hda_nid_t stac925x_dmux_nids[1] = {
453 0x14,
456 static unsigned long stac925x_capvols[] = {
457 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_OUTPUT),
459 static unsigned long stac925x_capsws[] = {
460 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
463 static hda_nid_t stac922x_adc_nids[2] = {
464 0x06, 0x07,
467 static hda_nid_t stac922x_mux_nids[2] = {
468 0x12, 0x13,
471 #define STAC922X_NUM_CAPS 2
472 static unsigned long stac922x_capvols[] = {
473 HDA_COMPOSE_AMP_VAL(0x17, 3, 0, HDA_INPUT),
474 HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_INPUT),
476 #define stac922x_capsws stac922x_capvols
478 static hda_nid_t stac927x_slave_dig_outs[2] = {
479 0x1f, 0,
482 static hda_nid_t stac927x_adc_nids[3] = {
483 0x07, 0x08, 0x09
486 static hda_nid_t stac927x_mux_nids[3] = {
487 0x15, 0x16, 0x17
490 static hda_nid_t stac927x_smux_nids[1] = {
491 0x21,
494 static hda_nid_t stac927x_dac_nids[6] = {
495 0x02, 0x03, 0x04, 0x05, 0x06, 0
498 static hda_nid_t stac927x_dmux_nids[1] = {
499 0x1b,
502 #define STAC927X_NUM_DMICS 2
503 static hda_nid_t stac927x_dmic_nids[STAC927X_NUM_DMICS + 1] = {
504 0x13, 0x14, 0
507 #define STAC927X_NUM_CAPS 3
508 static unsigned long stac927x_capvols[] = {
509 HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_INPUT),
510 HDA_COMPOSE_AMP_VAL(0x19, 3, 0, HDA_INPUT),
511 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_INPUT),
513 static unsigned long stac927x_capsws[] = {
514 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
515 HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_OUTPUT),
516 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
519 static const char *stac927x_spdif_labels[5] = {
520 "Digital Playback", "ADAT", "Analog Mux 1",
521 "Analog Mux 2", "Analog Mux 3"
524 static hda_nid_t stac9205_adc_nids[2] = {
525 0x12, 0x13
528 static hda_nid_t stac9205_mux_nids[2] = {
529 0x19, 0x1a
532 static hda_nid_t stac9205_dmux_nids[1] = {
533 0x1d,
536 static hda_nid_t stac9205_smux_nids[1] = {
537 0x21,
540 #define STAC9205_NUM_DMICS 2
541 static hda_nid_t stac9205_dmic_nids[STAC9205_NUM_DMICS + 1] = {
542 0x17, 0x18, 0
545 #define STAC9205_NUM_CAPS 2
546 static unsigned long stac9205_capvols[] = {
547 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_INPUT),
548 HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_INPUT),
550 static unsigned long stac9205_capsws[] = {
551 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
552 HDA_COMPOSE_AMP_VAL(0x1e, 3, 0, HDA_OUTPUT),
555 static hda_nid_t stac9200_pin_nids[8] = {
556 0x08, 0x09, 0x0d, 0x0e,
557 0x0f, 0x10, 0x11, 0x12,
560 static hda_nid_t stac925x_pin_nids[8] = {
561 0x07, 0x08, 0x0a, 0x0b,
562 0x0c, 0x0d, 0x10, 0x11,
565 static hda_nid_t stac922x_pin_nids[10] = {
566 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
567 0x0f, 0x10, 0x11, 0x15, 0x1b,
570 static hda_nid_t stac92hd73xx_pin_nids[13] = {
571 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
572 0x0f, 0x10, 0x11, 0x12, 0x13,
573 0x14, 0x22, 0x23
576 static hda_nid_t stac92hd83xxx_pin_nids[10] = {
577 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
578 0x0f, 0x10, 0x11, 0x1f, 0x20,
581 #define STAC92HD71BXX_NUM_PINS 13
582 static hda_nid_t stac92hd71bxx_pin_nids_4port[STAC92HD71BXX_NUM_PINS] = {
583 0x0a, 0x0b, 0x0c, 0x0d, 0x00,
584 0x00, 0x14, 0x18, 0x19, 0x1e,
585 0x1f, 0x20, 0x27
587 static hda_nid_t stac92hd71bxx_pin_nids_6port[STAC92HD71BXX_NUM_PINS] = {
588 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
589 0x0f, 0x14, 0x18, 0x19, 0x1e,
590 0x1f, 0x20, 0x27
593 static hda_nid_t stac927x_pin_nids[14] = {
594 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
595 0x0f, 0x10, 0x11, 0x12, 0x13,
596 0x14, 0x21, 0x22, 0x23,
599 static hda_nid_t stac9205_pin_nids[12] = {
600 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
601 0x0f, 0x14, 0x16, 0x17, 0x18,
602 0x21, 0x22,
605 #define stac92xx_amp_volume_info snd_hda_mixer_amp_volume_info
607 static int stac92xx_amp_volume_get(struct snd_kcontrol *kcontrol,
608 struct snd_ctl_elem_value *ucontrol)
610 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
611 struct sigmatel_spec *spec = codec->spec;
612 hda_nid_t nid = spec->amp_nids[spec->cur_amux];
614 kcontrol->private_value ^= get_amp_nid(kcontrol);
615 kcontrol->private_value |= nid;
617 return snd_hda_mixer_amp_volume_get(kcontrol, ucontrol);
620 static int stac92xx_amp_volume_put(struct snd_kcontrol *kcontrol,
621 struct snd_ctl_elem_value *ucontrol)
623 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
624 struct sigmatel_spec *spec = codec->spec;
625 hda_nid_t nid = spec->amp_nids[spec->cur_amux];
627 kcontrol->private_value ^= get_amp_nid(kcontrol);
628 kcontrol->private_value |= nid;
630 return snd_hda_mixer_amp_volume_put(kcontrol, ucontrol);
633 static int stac92xx_dmux_enum_info(struct snd_kcontrol *kcontrol,
634 struct snd_ctl_elem_info *uinfo)
636 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
637 struct sigmatel_spec *spec = codec->spec;
638 return snd_hda_input_mux_info(spec->dinput_mux, uinfo);
641 static int stac92xx_dmux_enum_get(struct snd_kcontrol *kcontrol,
642 struct snd_ctl_elem_value *ucontrol)
644 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
645 struct sigmatel_spec *spec = codec->spec;
646 unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
648 ucontrol->value.enumerated.item[0] = spec->cur_dmux[dmux_idx];
649 return 0;
652 static int stac92xx_dmux_enum_put(struct snd_kcontrol *kcontrol,
653 struct snd_ctl_elem_value *ucontrol)
655 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
656 struct sigmatel_spec *spec = codec->spec;
657 unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
659 return snd_hda_input_mux_put(codec, spec->dinput_mux, ucontrol,
660 spec->dmux_nids[dmux_idx], &spec->cur_dmux[dmux_idx]);
663 static int stac92xx_smux_enum_info(struct snd_kcontrol *kcontrol,
664 struct snd_ctl_elem_info *uinfo)
666 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
667 struct sigmatel_spec *spec = codec->spec;
668 return snd_hda_input_mux_info(spec->sinput_mux, uinfo);
671 static int stac92xx_smux_enum_get(struct snd_kcontrol *kcontrol,
672 struct snd_ctl_elem_value *ucontrol)
674 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
675 struct sigmatel_spec *spec = codec->spec;
676 unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
678 ucontrol->value.enumerated.item[0] = spec->cur_smux[smux_idx];
679 return 0;
682 static int stac92xx_smux_enum_put(struct snd_kcontrol *kcontrol,
683 struct snd_ctl_elem_value *ucontrol)
685 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
686 struct sigmatel_spec *spec = codec->spec;
687 struct hda_input_mux *smux = &spec->private_smux;
688 unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
689 int err, val;
690 hda_nid_t nid;
692 err = snd_hda_input_mux_put(codec, spec->sinput_mux, ucontrol,
693 spec->smux_nids[smux_idx], &spec->cur_smux[smux_idx]);
694 if (err < 0)
695 return err;
697 if (spec->spdif_mute) {
698 if (smux_idx == 0)
699 nid = spec->multiout.dig_out_nid;
700 else
701 nid = codec->slave_dig_outs[smux_idx - 1];
702 if (spec->cur_smux[smux_idx] == smux->num_items - 1)
703 val = HDA_AMP_MUTE;
704 else
705 val = 0;
706 /* un/mute SPDIF out */
707 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
708 HDA_AMP_MUTE, val);
710 return 0;
713 static unsigned int stac92xx_vref_set(struct hda_codec *codec,
714 hda_nid_t nid, unsigned int new_vref)
716 int error;
717 unsigned int pincfg;
718 pincfg = snd_hda_codec_read(codec, nid, 0,
719 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
721 pincfg &= 0xff;
722 pincfg &= ~(AC_PINCTL_VREFEN | AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
723 pincfg |= new_vref;
725 if (new_vref == AC_PINCTL_VREF_HIZ)
726 pincfg |= AC_PINCTL_OUT_EN;
727 else
728 pincfg |= AC_PINCTL_IN_EN;
730 error = snd_hda_codec_write_cache(codec, nid, 0,
731 AC_VERB_SET_PIN_WIDGET_CONTROL, pincfg);
732 if (error < 0)
733 return error;
734 else
735 return 1;
738 static unsigned int stac92xx_vref_get(struct hda_codec *codec, hda_nid_t nid)
740 unsigned int vref;
741 vref = snd_hda_codec_read(codec, nid, 0,
742 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
743 vref &= AC_PINCTL_VREFEN;
744 return vref;
747 static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
749 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
750 struct sigmatel_spec *spec = codec->spec;
751 return snd_hda_input_mux_info(spec->input_mux, uinfo);
754 static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
756 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
757 struct sigmatel_spec *spec = codec->spec;
758 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
760 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
761 return 0;
764 static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
766 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
767 struct sigmatel_spec *spec = codec->spec;
768 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
769 const struct hda_input_mux *imux = spec->input_mux;
770 unsigned int idx, prev_idx;
772 idx = ucontrol->value.enumerated.item[0];
773 if (idx >= imux->num_items)
774 idx = imux->num_items - 1;
775 prev_idx = spec->cur_mux[adc_idx];
776 if (prev_idx == idx)
777 return 0;
778 if (idx < spec->num_analog_muxes) {
779 snd_hda_codec_write_cache(codec, spec->mux_nids[adc_idx], 0,
780 AC_VERB_SET_CONNECT_SEL,
781 imux->items[idx].index);
782 if (prev_idx >= spec->num_analog_muxes) {
783 imux = spec->dinput_mux;
784 /* 0 = analog */
785 snd_hda_codec_write_cache(codec,
786 spec->dmux_nids[adc_idx], 0,
787 AC_VERB_SET_CONNECT_SEL,
788 imux->items[0].index);
790 } else {
791 imux = spec->dinput_mux;
792 snd_hda_codec_write_cache(codec, spec->dmux_nids[adc_idx], 0,
793 AC_VERB_SET_CONNECT_SEL,
794 imux->items[idx - 1].index);
796 spec->cur_mux[adc_idx] = idx;
797 return 1;
800 static int stac92xx_mono_mux_enum_info(struct snd_kcontrol *kcontrol,
801 struct snd_ctl_elem_info *uinfo)
803 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
804 struct sigmatel_spec *spec = codec->spec;
805 return snd_hda_input_mux_info(spec->mono_mux, uinfo);
808 static int stac92xx_mono_mux_enum_get(struct snd_kcontrol *kcontrol,
809 struct snd_ctl_elem_value *ucontrol)
811 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
812 struct sigmatel_spec *spec = codec->spec;
814 ucontrol->value.enumerated.item[0] = spec->cur_mmux;
815 return 0;
818 static int stac92xx_mono_mux_enum_put(struct snd_kcontrol *kcontrol,
819 struct snd_ctl_elem_value *ucontrol)
821 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
822 struct sigmatel_spec *spec = codec->spec;
824 return snd_hda_input_mux_put(codec, spec->mono_mux, ucontrol,
825 spec->mono_nid, &spec->cur_mmux);
828 static int stac92xx_amp_mux_enum_info(struct snd_kcontrol *kcontrol,
829 struct snd_ctl_elem_info *uinfo)
831 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
832 struct sigmatel_spec *spec = codec->spec;
833 return snd_hda_input_mux_info(spec->amp_mux, uinfo);
836 static int stac92xx_amp_mux_enum_get(struct snd_kcontrol *kcontrol,
837 struct snd_ctl_elem_value *ucontrol)
839 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
840 struct sigmatel_spec *spec = codec->spec;
842 ucontrol->value.enumerated.item[0] = spec->cur_amux;
843 return 0;
846 static int stac92xx_amp_mux_enum_put(struct snd_kcontrol *kcontrol,
847 struct snd_ctl_elem_value *ucontrol)
849 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
850 struct sigmatel_spec *spec = codec->spec;
851 struct snd_kcontrol *ctl =
852 snd_hda_find_mixer_ctl(codec, "Amp Capture Volume");
853 if (!ctl)
854 return -EINVAL;
856 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE |
857 SNDRV_CTL_EVENT_MASK_INFO, &ctl->id);
859 return snd_hda_input_mux_put(codec, spec->amp_mux, ucontrol,
860 0, &spec->cur_amux);
863 #define stac92xx_aloopback_info snd_ctl_boolean_mono_info
865 static int stac92xx_aloopback_get(struct snd_kcontrol *kcontrol,
866 struct snd_ctl_elem_value *ucontrol)
868 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
869 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
870 struct sigmatel_spec *spec = codec->spec;
872 ucontrol->value.integer.value[0] = !!(spec->aloopback &
873 (spec->aloopback_mask << idx));
874 return 0;
877 static int stac92xx_aloopback_put(struct snd_kcontrol *kcontrol,
878 struct snd_ctl_elem_value *ucontrol)
880 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
881 struct sigmatel_spec *spec = codec->spec;
882 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
883 unsigned int dac_mode;
884 unsigned int val, idx_val;
886 idx_val = spec->aloopback_mask << idx;
887 if (ucontrol->value.integer.value[0])
888 val = spec->aloopback | idx_val;
889 else
890 val = spec->aloopback & ~idx_val;
891 if (spec->aloopback == val)
892 return 0;
894 spec->aloopback = val;
896 /* Only return the bits defined by the shift value of the
897 * first two bytes of the mask
899 dac_mode = snd_hda_codec_read(codec, codec->afg, 0,
900 kcontrol->private_value & 0xFFFF, 0x0);
901 dac_mode >>= spec->aloopback_shift;
903 if (spec->aloopback & idx_val) {
904 snd_hda_power_up(codec);
905 dac_mode |= idx_val;
906 } else {
907 snd_hda_power_down(codec);
908 dac_mode &= ~idx_val;
911 snd_hda_codec_write_cache(codec, codec->afg, 0,
912 kcontrol->private_value >> 16, dac_mode);
914 return 1;
917 static struct hda_verb stac9200_core_init[] = {
918 /* set dac0mux for dac converter */
919 { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
923 static struct hda_verb stac9200_eapd_init[] = {
924 /* set dac0mux for dac converter */
925 {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
926 {0x08, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
930 static struct hda_verb stac92hd73xx_6ch_core_init[] = {
931 /* set master volume and direct control */
932 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
933 /* setup adcs to point to mixer */
934 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
935 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
936 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
937 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
938 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
939 /* setup import muxs */
940 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
941 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
942 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
943 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x00},
947 static struct hda_verb dell_eq_core_init[] = {
948 /* set master volume to max value without distortion
949 * and direct control */
950 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xec},
951 /* setup adcs to point to mixer */
952 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
953 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
954 /* setup import muxs */
955 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
956 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
957 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
958 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x00},
962 static struct hda_verb dell_m6_core_init[] = {
963 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
964 /* setup adcs to point to mixer */
965 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
966 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
967 /* setup import muxs */
968 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
969 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
970 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
971 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x00},
975 static struct hda_verb stac92hd73xx_8ch_core_init[] = {
976 /* set master volume and direct control */
977 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
978 /* setup adcs to point to mixer */
979 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
980 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
981 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
982 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
983 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
984 /* setup import muxs */
985 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
986 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
987 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
988 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x03},
992 static struct hda_verb stac92hd73xx_10ch_core_init[] = {
993 /* set master volume and direct control */
994 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
995 /* dac3 is connected to import3 mux */
996 { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0xb07f},
997 /* setup adcs to point to mixer */
998 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
999 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
1000 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1001 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1002 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1003 /* setup import muxs */
1004 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
1005 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
1006 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
1007 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x03},
1011 static struct hda_verb stac92hd83xxx_core_init[] = {
1012 { 0xa, AC_VERB_SET_CONNECT_SEL, 0x1},
1013 { 0xb, AC_VERB_SET_CONNECT_SEL, 0x1},
1014 { 0xd, AC_VERB_SET_CONNECT_SEL, 0x0},
1016 /* power state controls amps */
1017 { 0x01, AC_VERB_SET_EAPD, 1 << 2},
1021 static struct hda_verb stac92hd71bxx_core_init[] = {
1022 /* set master volume and direct control */
1023 { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
1027 static struct hda_verb stac92hd71bxx_unmute_core_init[] = {
1028 /* unmute right and left channels for nodes 0x0f, 0xa, 0x0d */
1029 { 0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1030 { 0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1031 { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1035 static struct hda_verb stac925x_core_init[] = {
1036 /* set dac0mux for dac converter */
1037 { 0x06, AC_VERB_SET_CONNECT_SEL, 0x00},
1038 /* mute the master volume */
1039 { 0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1043 static struct hda_verb stac922x_core_init[] = {
1044 /* set master volume and direct control */
1045 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
1049 static struct hda_verb d965_core_init[] = {
1050 /* set master volume and direct control */
1051 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
1052 /* unmute node 0x1b */
1053 { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1054 /* select node 0x03 as DAC */
1055 { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
1059 static struct hda_verb stac927x_core_init[] = {
1060 /* set master volume and direct control */
1061 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
1062 /* enable analog pc beep path */
1063 { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
1067 static struct hda_verb stac9205_core_init[] = {
1068 /* set master volume and direct control */
1069 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
1070 /* enable analog pc beep path */
1071 { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
1075 #define STAC_MONO_MUX \
1077 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1078 .name = "Mono Mux", \
1079 .count = 1, \
1080 .info = stac92xx_mono_mux_enum_info, \
1081 .get = stac92xx_mono_mux_enum_get, \
1082 .put = stac92xx_mono_mux_enum_put, \
1085 #define STAC_AMP_MUX \
1087 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1088 .name = "Amp Selector Capture Switch", \
1089 .count = 1, \
1090 .info = stac92xx_amp_mux_enum_info, \
1091 .get = stac92xx_amp_mux_enum_get, \
1092 .put = stac92xx_amp_mux_enum_put, \
1095 #define STAC_AMP_VOL(xname, nid, chs, idx, dir) \
1097 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1098 .name = xname, \
1099 .index = 0, \
1100 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1101 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1102 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
1103 .info = stac92xx_amp_volume_info, \
1104 .get = stac92xx_amp_volume_get, \
1105 .put = stac92xx_amp_volume_put, \
1106 .tlv = { .c = snd_hda_mixer_amp_tlv }, \
1107 .private_value = HDA_COMPOSE_AMP_VAL(nid, chs, idx, dir) \
1110 #define STAC_ANALOG_LOOPBACK(verb_read, verb_write, cnt) \
1112 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1113 .name = "Analog Loopback", \
1114 .count = cnt, \
1115 .info = stac92xx_aloopback_info, \
1116 .get = stac92xx_aloopback_get, \
1117 .put = stac92xx_aloopback_put, \
1118 .private_value = verb_read | (verb_write << 16), \
1121 #define DC_BIAS(xname, idx, nid) \
1123 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1124 .name = xname, \
1125 .index = idx, \
1126 .info = stac92xx_dc_bias_info, \
1127 .get = stac92xx_dc_bias_get, \
1128 .put = stac92xx_dc_bias_put, \
1129 .private_value = nid, \
1132 static struct snd_kcontrol_new stac9200_mixer[] = {
1133 HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
1134 HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
1135 HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
1136 HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
1137 { } /* end */
1140 #define DELL_M6_MIXER 6
1141 static struct snd_kcontrol_new stac92hd73xx_6ch_mixer[] = {
1142 /* start of config #1 */
1143 HDA_CODEC_VOLUME("Front Mic Mixer Capture Volume", 0x1d, 0, HDA_INPUT),
1144 HDA_CODEC_MUTE("Front Mic Mixer Capture Switch", 0x1d, 0, HDA_INPUT),
1146 HDA_CODEC_VOLUME("Line In Mixer Capture Volume", 0x1d, 0x2, HDA_INPUT),
1147 HDA_CODEC_MUTE("Line In Mixer Capture Switch", 0x1d, 0x2, HDA_INPUT),
1149 HDA_CODEC_VOLUME("CD Mixer Capture Volume", 0x1d, 0x4, HDA_INPUT),
1150 HDA_CODEC_MUTE("CD Mixer Capture Switch", 0x1d, 0x4, HDA_INPUT),
1152 /* start of config #2 */
1153 HDA_CODEC_VOLUME("Mic Mixer Capture Volume", 0x1d, 0x1, HDA_INPUT),
1154 HDA_CODEC_MUTE("Mic Mixer Capture Switch", 0x1d, 0x1, HDA_INPUT),
1156 HDA_CODEC_VOLUME("DAC Mixer Capture Volume", 0x1d, 0x3, HDA_INPUT),
1157 HDA_CODEC_MUTE("DAC Mixer Capture Switch", 0x1d, 0x3, HDA_INPUT),
1159 { } /* end */
1162 static struct snd_kcontrol_new stac92hd73xx_6ch_loopback[] = {
1163 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 3),
1167 static struct snd_kcontrol_new stac92hd73xx_8ch_loopback[] = {
1168 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 4),
1172 static struct snd_kcontrol_new stac92hd73xx_10ch_loopback[] = {
1173 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 5),
1177 static struct snd_kcontrol_new stac92hd73xx_8ch_mixer[] = {
1178 HDA_CODEC_VOLUME("Front Mic Mixer Capture Volume", 0x1d, 0, HDA_INPUT),
1179 HDA_CODEC_MUTE("Front Mic Mixer Capture Switch", 0x1d, 0, HDA_INPUT),
1181 HDA_CODEC_VOLUME("Mic Mixer Capture Volume", 0x1d, 0x1, HDA_INPUT),
1182 HDA_CODEC_MUTE("Mic Mixer Capture Switch", 0x1d, 0x1, HDA_INPUT),
1184 HDA_CODEC_VOLUME("Line In Mixer Capture Volume", 0x1d, 0x2, HDA_INPUT),
1185 HDA_CODEC_MUTE("Line In Mixer Capture Switch", 0x1d, 0x2, HDA_INPUT),
1187 HDA_CODEC_VOLUME("DAC Mixer Capture Volume", 0x1d, 0x3, HDA_INPUT),
1188 HDA_CODEC_MUTE("DAC Mixer Capture Switch", 0x1d, 0x3, HDA_INPUT),
1190 HDA_CODEC_VOLUME("CD Mixer Capture Volume", 0x1d, 0x4, HDA_INPUT),
1191 HDA_CODEC_MUTE("CD Mixer Capture Switch", 0x1d, 0x4, HDA_INPUT),
1192 { } /* end */
1195 static struct snd_kcontrol_new stac92hd73xx_10ch_mixer[] = {
1196 HDA_CODEC_VOLUME("Front Mic Mixer Capture Volume", 0x1d, 0, HDA_INPUT),
1197 HDA_CODEC_MUTE("Front Mic Mixer Capture Switch", 0x1d, 0, HDA_INPUT),
1199 HDA_CODEC_VOLUME("Mic Mixer Capture Volume", 0x1d, 0x1, HDA_INPUT),
1200 HDA_CODEC_MUTE("Mic Mixer Capture Switch", 0x1d, 0x1, HDA_INPUT),
1202 HDA_CODEC_VOLUME("Line In Mixer Capture Volume", 0x1d, 0x2, HDA_INPUT),
1203 HDA_CODEC_MUTE("Line In Mixer Capture Switch", 0x1d, 0x2, HDA_INPUT),
1205 HDA_CODEC_VOLUME("DAC Mixer Capture Volume", 0x1d, 0x3, HDA_INPUT),
1206 HDA_CODEC_MUTE("DAC Mixer Capture Switch", 0x1d, 0x3, HDA_INPUT),
1208 HDA_CODEC_VOLUME("CD Mixer Capture Volume", 0x1d, 0x4, HDA_INPUT),
1209 HDA_CODEC_MUTE("CD Mixer Capture Switch", 0x1d, 0x4, HDA_INPUT),
1210 { } /* end */
1214 static struct snd_kcontrol_new stac92hd83xxx_mixer[] = {
1215 HDA_CODEC_VOLUME("DAC0 Capture Volume", 0x1b, 0x3, HDA_INPUT),
1216 HDA_CODEC_MUTE("DAC0 Capture Switch", 0x1b, 0x3, HDA_INPUT),
1218 HDA_CODEC_VOLUME("DAC1 Capture Volume", 0x1b, 0x4, HDA_INPUT),
1219 HDA_CODEC_MUTE("DAC1 Capture Switch", 0x1b, 0x4, HDA_INPUT),
1221 HDA_CODEC_VOLUME("Front Mic Capture Volume", 0x1b, 0x0, HDA_INPUT),
1222 HDA_CODEC_MUTE("Front Mic Capture Switch", 0x1b, 0x0, HDA_INPUT),
1224 HDA_CODEC_VOLUME("Line In Capture Volume", 0x1b, 0x2, HDA_INPUT),
1225 HDA_CODEC_MUTE("Line In Capture Switch", 0x1b, 0x2, HDA_INPUT),
1228 HDA_CODEC_VOLUME("Mic Capture Volume", 0x1b, 0x1, HDA_INPUT),
1229 HDA_CODEC_MUTE("Mic Capture Switch", 0x1b 0x1, HDA_INPUT),
1231 { } /* end */
1234 static struct snd_kcontrol_new stac92hd71bxx_loopback[] = {
1235 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A0, 2)
1238 static struct snd_kcontrol_new stac925x_mixer[] = {
1239 HDA_CODEC_VOLUME("Master Playback Volume", 0x0e, 0, HDA_OUTPUT),
1240 HDA_CODEC_MUTE("Master Playback Switch", 0x0e, 0, HDA_OUTPUT),
1241 { } /* end */
1244 static struct snd_kcontrol_new stac9205_loopback[] = {
1245 STAC_ANALOG_LOOPBACK(0xFE0, 0x7E0, 1),
1249 static struct snd_kcontrol_new stac927x_loopback[] = {
1250 STAC_ANALOG_LOOPBACK(0xFEB, 0x7EB, 1),
1254 static struct snd_kcontrol_new stac_dmux_mixer = {
1255 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1256 .name = "Digital Input Source",
1257 /* count set later */
1258 .info = stac92xx_dmux_enum_info,
1259 .get = stac92xx_dmux_enum_get,
1260 .put = stac92xx_dmux_enum_put,
1263 static struct snd_kcontrol_new stac_smux_mixer = {
1264 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1265 .name = "IEC958 Playback Source",
1266 /* count set later */
1267 .info = stac92xx_smux_enum_info,
1268 .get = stac92xx_smux_enum_get,
1269 .put = stac92xx_smux_enum_put,
1272 static const char *slave_vols[] = {
1273 "Front Playback Volume",
1274 "Surround Playback Volume",
1275 "Center Playback Volume",
1276 "LFE Playback Volume",
1277 "Side Playback Volume",
1278 "Headphone Playback Volume",
1279 "Speaker Playback Volume",
1280 NULL
1283 static const char *slave_sws[] = {
1284 "Front Playback Switch",
1285 "Surround Playback Switch",
1286 "Center Playback Switch",
1287 "LFE Playback Switch",
1288 "Side Playback Switch",
1289 "Headphone Playback Switch",
1290 "Speaker Playback Switch",
1291 "IEC958 Playback Switch",
1292 NULL
1295 static void stac92xx_free_kctls(struct hda_codec *codec);
1296 static int stac92xx_add_jack(struct hda_codec *codec, hda_nid_t nid, int type);
1298 static int stac92xx_build_controls(struct hda_codec *codec)
1300 struct sigmatel_spec *spec = codec->spec;
1301 struct auto_pin_cfg *cfg = &spec->autocfg;
1302 hda_nid_t nid;
1303 int err;
1304 int i;
1306 if (spec->mixer) {
1307 err = snd_hda_add_new_ctls(codec, spec->mixer);
1308 if (err < 0)
1309 return err;
1312 for (i = 0; i < spec->num_mixers; i++) {
1313 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1314 if (err < 0)
1315 return err;
1317 if (!spec->auto_mic && spec->num_dmuxes > 0 &&
1318 snd_hda_get_bool_hint(codec, "separate_dmux") == 1) {
1319 stac_dmux_mixer.count = spec->num_dmuxes;
1320 err = snd_hda_ctl_add(codec,
1321 snd_ctl_new1(&stac_dmux_mixer, codec));
1322 if (err < 0)
1323 return err;
1325 if (spec->num_smuxes > 0) {
1326 int wcaps = get_wcaps(codec, spec->multiout.dig_out_nid);
1327 struct hda_input_mux *smux = &spec->private_smux;
1328 /* check for mute support on SPDIF out */
1329 if (wcaps & AC_WCAP_OUT_AMP) {
1330 smux->items[smux->num_items].label = "Off";
1331 smux->items[smux->num_items].index = 0;
1332 smux->num_items++;
1333 spec->spdif_mute = 1;
1335 stac_smux_mixer.count = spec->num_smuxes;
1336 err = snd_hda_ctl_add(codec,
1337 snd_ctl_new1(&stac_smux_mixer, codec));
1338 if (err < 0)
1339 return err;
1342 if (spec->multiout.dig_out_nid) {
1343 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
1344 if (err < 0)
1345 return err;
1346 err = snd_hda_create_spdif_share_sw(codec,
1347 &spec->multiout);
1348 if (err < 0)
1349 return err;
1350 spec->multiout.share_spdif = 1;
1352 if (spec->dig_in_nid && !(spec->gpio_dir & 0x01)) {
1353 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1354 if (err < 0)
1355 return err;
1358 /* if we have no master control, let's create it */
1359 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
1360 unsigned int vmaster_tlv[4];
1361 snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0],
1362 HDA_OUTPUT, vmaster_tlv);
1363 /* correct volume offset */
1364 vmaster_tlv[2] += vmaster_tlv[3] * spec->volume_offset;
1365 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
1366 vmaster_tlv, slave_vols);
1367 if (err < 0)
1368 return err;
1370 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1371 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1372 NULL, slave_sws);
1373 if (err < 0)
1374 return err;
1377 if (spec->aloopback_ctl &&
1378 snd_hda_get_bool_hint(codec, "loopback") == 1) {
1379 err = snd_hda_add_new_ctls(codec, spec->aloopback_ctl);
1380 if (err < 0)
1381 return err;
1384 stac92xx_free_kctls(codec); /* no longer needed */
1386 /* create jack input elements */
1387 if (spec->hp_detect) {
1388 for (i = 0; i < cfg->hp_outs; i++) {
1389 int type = SND_JACK_HEADPHONE;
1390 nid = cfg->hp_pins[i];
1391 /* jack detection */
1392 if (cfg->hp_outs == i)
1393 type |= SND_JACK_LINEOUT;
1394 err = stac92xx_add_jack(codec, nid, type);
1395 if (err < 0)
1396 return err;
1399 for (i = 0; i < cfg->line_outs; i++) {
1400 err = stac92xx_add_jack(codec, cfg->line_out_pins[i],
1401 SND_JACK_LINEOUT);
1402 if (err < 0)
1403 return err;
1405 for (i = 0; i < AUTO_PIN_LAST; i++) {
1406 nid = cfg->input_pins[i];
1407 if (nid) {
1408 err = stac92xx_add_jack(codec, nid,
1409 SND_JACK_MICROPHONE);
1410 if (err < 0)
1411 return err;
1415 return 0;
1418 static unsigned int ref9200_pin_configs[8] = {
1419 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
1420 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
1423 static unsigned int gateway9200_m4_pin_configs[8] = {
1424 0x400000fe, 0x404500f4, 0x400100f0, 0x90110010,
1425 0x400100f1, 0x02a1902e, 0x500000f2, 0x500000f3,
1427 static unsigned int gateway9200_m4_2_pin_configs[8] = {
1428 0x400000fe, 0x404500f4, 0x400100f0, 0x90110010,
1429 0x400100f1, 0x02a1902e, 0x500000f2, 0x500000f3,
1433 STAC 9200 pin configs for
1434 102801A8
1435 102801DE
1436 102801E8
1438 static unsigned int dell9200_d21_pin_configs[8] = {
1439 0x400001f0, 0x400001f1, 0x02214030, 0x01014010,
1440 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
1444 STAC 9200 pin configs for
1445 102801C0
1446 102801C1
1448 static unsigned int dell9200_d22_pin_configs[8] = {
1449 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
1450 0x01813020, 0x02a19021, 0x90100140, 0x400001f2,
1454 STAC 9200 pin configs for
1455 102801C4 (Dell Dimension E310)
1456 102801C5
1457 102801C7
1458 102801D9
1459 102801DA
1460 102801E3
1462 static unsigned int dell9200_d23_pin_configs[8] = {
1463 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
1464 0x01813020, 0x01a19021, 0x90100140, 0x400001f2,
1469 STAC 9200-32 pin configs for
1470 102801B5 (Dell Inspiron 630m)
1471 102801D8 (Dell Inspiron 640m)
1473 static unsigned int dell9200_m21_pin_configs[8] = {
1474 0x40c003fa, 0x03441340, 0x0321121f, 0x90170310,
1475 0x408003fb, 0x03a11020, 0x401003fc, 0x403003fd,
1479 STAC 9200-32 pin configs for
1480 102801C2 (Dell Latitude D620)
1481 102801C8
1482 102801CC (Dell Latitude D820)
1483 102801D4
1484 102801D6
1486 static unsigned int dell9200_m22_pin_configs[8] = {
1487 0x40c003fa, 0x0144131f, 0x0321121f, 0x90170310,
1488 0x90a70321, 0x03a11020, 0x401003fb, 0x40f000fc,
1492 STAC 9200-32 pin configs for
1493 102801CE (Dell XPS M1710)
1494 102801CF (Dell Precision M90)
1496 static unsigned int dell9200_m23_pin_configs[8] = {
1497 0x40c003fa, 0x01441340, 0x0421421f, 0x90170310,
1498 0x408003fb, 0x04a1102e, 0x90170311, 0x403003fc,
1502 STAC 9200-32 pin configs for
1503 102801C9
1504 102801CA
1505 102801CB (Dell Latitude 120L)
1506 102801D3
1508 static unsigned int dell9200_m24_pin_configs[8] = {
1509 0x40c003fa, 0x404003fb, 0x0321121f, 0x90170310,
1510 0x408003fc, 0x03a11020, 0x401003fd, 0x403003fe,
1514 STAC 9200-32 pin configs for
1515 102801BD (Dell Inspiron E1505n)
1516 102801EE
1517 102801EF
1519 static unsigned int dell9200_m25_pin_configs[8] = {
1520 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
1521 0x408003fb, 0x04a11020, 0x401003fc, 0x403003fd,
1525 STAC 9200-32 pin configs for
1526 102801F5 (Dell Inspiron 1501)
1527 102801F6
1529 static unsigned int dell9200_m26_pin_configs[8] = {
1530 0x40c003fa, 0x404003fb, 0x0421121f, 0x90170310,
1531 0x408003fc, 0x04a11020, 0x401003fd, 0x403003fe,
1535 STAC 9200-32
1536 102801CD (Dell Inspiron E1705/9400)
1538 static unsigned int dell9200_m27_pin_configs[8] = {
1539 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
1540 0x90170310, 0x04a11020, 0x90170310, 0x40f003fc,
1543 static unsigned int oqo9200_pin_configs[8] = {
1544 0x40c000f0, 0x404000f1, 0x0221121f, 0x02211210,
1545 0x90170111, 0x90a70120, 0x400000f2, 0x400000f3,
1549 static unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
1550 [STAC_REF] = ref9200_pin_configs,
1551 [STAC_9200_OQO] = oqo9200_pin_configs,
1552 [STAC_9200_DELL_D21] = dell9200_d21_pin_configs,
1553 [STAC_9200_DELL_D22] = dell9200_d22_pin_configs,
1554 [STAC_9200_DELL_D23] = dell9200_d23_pin_configs,
1555 [STAC_9200_DELL_M21] = dell9200_m21_pin_configs,
1556 [STAC_9200_DELL_M22] = dell9200_m22_pin_configs,
1557 [STAC_9200_DELL_M23] = dell9200_m23_pin_configs,
1558 [STAC_9200_DELL_M24] = dell9200_m24_pin_configs,
1559 [STAC_9200_DELL_M25] = dell9200_m25_pin_configs,
1560 [STAC_9200_DELL_M26] = dell9200_m26_pin_configs,
1561 [STAC_9200_DELL_M27] = dell9200_m27_pin_configs,
1562 [STAC_9200_M4] = gateway9200_m4_pin_configs,
1563 [STAC_9200_M4_2] = gateway9200_m4_2_pin_configs,
1564 [STAC_9200_PANASONIC] = ref9200_pin_configs,
1567 static const char *stac9200_models[STAC_9200_MODELS] = {
1568 [STAC_AUTO] = "auto",
1569 [STAC_REF] = "ref",
1570 [STAC_9200_OQO] = "oqo",
1571 [STAC_9200_DELL_D21] = "dell-d21",
1572 [STAC_9200_DELL_D22] = "dell-d22",
1573 [STAC_9200_DELL_D23] = "dell-d23",
1574 [STAC_9200_DELL_M21] = "dell-m21",
1575 [STAC_9200_DELL_M22] = "dell-m22",
1576 [STAC_9200_DELL_M23] = "dell-m23",
1577 [STAC_9200_DELL_M24] = "dell-m24",
1578 [STAC_9200_DELL_M25] = "dell-m25",
1579 [STAC_9200_DELL_M26] = "dell-m26",
1580 [STAC_9200_DELL_M27] = "dell-m27",
1581 [STAC_9200_M4] = "gateway-m4",
1582 [STAC_9200_M4_2] = "gateway-m4-2",
1583 [STAC_9200_PANASONIC] = "panasonic",
1586 static struct snd_pci_quirk stac9200_cfg_tbl[] = {
1587 /* SigmaTel reference board */
1588 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1589 "DFI LanParty", STAC_REF),
1590 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1591 "DFI LanParty", STAC_REF),
1592 /* Dell laptops have BIOS problem */
1593 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a8,
1594 "unknown Dell", STAC_9200_DELL_D21),
1595 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01b5,
1596 "Dell Inspiron 630m", STAC_9200_DELL_M21),
1597 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bd,
1598 "Dell Inspiron E1505n", STAC_9200_DELL_M25),
1599 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c0,
1600 "unknown Dell", STAC_9200_DELL_D22),
1601 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c1,
1602 "unknown Dell", STAC_9200_DELL_D22),
1603 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c2,
1604 "Dell Latitude D620", STAC_9200_DELL_M22),
1605 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c5,
1606 "unknown Dell", STAC_9200_DELL_D23),
1607 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c7,
1608 "unknown Dell", STAC_9200_DELL_D23),
1609 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c8,
1610 "unknown Dell", STAC_9200_DELL_M22),
1611 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c9,
1612 "unknown Dell", STAC_9200_DELL_M24),
1613 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ca,
1614 "unknown Dell", STAC_9200_DELL_M24),
1615 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cb,
1616 "Dell Latitude 120L", STAC_9200_DELL_M24),
1617 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cc,
1618 "Dell Latitude D820", STAC_9200_DELL_M22),
1619 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cd,
1620 "Dell Inspiron E1705/9400", STAC_9200_DELL_M27),
1621 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ce,
1622 "Dell XPS M1710", STAC_9200_DELL_M23),
1623 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cf,
1624 "Dell Precision M90", STAC_9200_DELL_M23),
1625 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d3,
1626 "unknown Dell", STAC_9200_DELL_M22),
1627 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d4,
1628 "unknown Dell", STAC_9200_DELL_M22),
1629 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d6,
1630 "unknown Dell", STAC_9200_DELL_M22),
1631 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d8,
1632 "Dell Inspiron 640m", STAC_9200_DELL_M21),
1633 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d9,
1634 "unknown Dell", STAC_9200_DELL_D23),
1635 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01da,
1636 "unknown Dell", STAC_9200_DELL_D23),
1637 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01de,
1638 "unknown Dell", STAC_9200_DELL_D21),
1639 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e3,
1640 "unknown Dell", STAC_9200_DELL_D23),
1641 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e8,
1642 "unknown Dell", STAC_9200_DELL_D21),
1643 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ee,
1644 "unknown Dell", STAC_9200_DELL_M25),
1645 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ef,
1646 "unknown Dell", STAC_9200_DELL_M25),
1647 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f5,
1648 "Dell Inspiron 1501", STAC_9200_DELL_M26),
1649 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f6,
1650 "unknown Dell", STAC_9200_DELL_M26),
1651 /* Panasonic */
1652 SND_PCI_QUIRK(0x10f7, 0x8338, "Panasonic CF-74", STAC_9200_PANASONIC),
1653 /* Gateway machines needs EAPD to be set on resume */
1654 SND_PCI_QUIRK(0x107b, 0x0205, "Gateway S-7110M", STAC_9200_M4),
1655 SND_PCI_QUIRK(0x107b, 0x0317, "Gateway MT3423, MX341*", STAC_9200_M4_2),
1656 SND_PCI_QUIRK(0x107b, 0x0318, "Gateway ML3019, MT3707", STAC_9200_M4_2),
1657 /* OQO Mobile */
1658 SND_PCI_QUIRK(0x1106, 0x3288, "OQO Model 2", STAC_9200_OQO),
1659 {} /* terminator */
1662 static unsigned int ref925x_pin_configs[8] = {
1663 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
1664 0x90a70320, 0x02214210, 0x01019020, 0x9033032e,
1667 static unsigned int stac925xM1_pin_configs[8] = {
1668 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1669 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1672 static unsigned int stac925xM1_2_pin_configs[8] = {
1673 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1674 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1677 static unsigned int stac925xM2_pin_configs[8] = {
1678 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1679 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1682 static unsigned int stac925xM2_2_pin_configs[8] = {
1683 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1684 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1687 static unsigned int stac925xM3_pin_configs[8] = {
1688 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1689 0x40a000f0, 0x90100210, 0x400003f1, 0x503303f3,
1692 static unsigned int stac925xM5_pin_configs[8] = {
1693 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1694 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1697 static unsigned int stac925xM6_pin_configs[8] = {
1698 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1699 0x40a000f0, 0x90100210, 0x400003f1, 0x90330320,
1702 static unsigned int *stac925x_brd_tbl[STAC_925x_MODELS] = {
1703 [STAC_REF] = ref925x_pin_configs,
1704 [STAC_M1] = stac925xM1_pin_configs,
1705 [STAC_M1_2] = stac925xM1_2_pin_configs,
1706 [STAC_M2] = stac925xM2_pin_configs,
1707 [STAC_M2_2] = stac925xM2_2_pin_configs,
1708 [STAC_M3] = stac925xM3_pin_configs,
1709 [STAC_M5] = stac925xM5_pin_configs,
1710 [STAC_M6] = stac925xM6_pin_configs,
1713 static const char *stac925x_models[STAC_925x_MODELS] = {
1714 [STAC_925x_AUTO] = "auto",
1715 [STAC_REF] = "ref",
1716 [STAC_M1] = "m1",
1717 [STAC_M1_2] = "m1-2",
1718 [STAC_M2] = "m2",
1719 [STAC_M2_2] = "m2-2",
1720 [STAC_M3] = "m3",
1721 [STAC_M5] = "m5",
1722 [STAC_M6] = "m6",
1725 static struct snd_pci_quirk stac925x_codec_id_cfg_tbl[] = {
1726 SND_PCI_QUIRK(0x107b, 0x0316, "Gateway M255", STAC_M2),
1727 SND_PCI_QUIRK(0x107b, 0x0366, "Gateway MP6954", STAC_M5),
1728 SND_PCI_QUIRK(0x107b, 0x0461, "Gateway NX560XL", STAC_M1),
1729 SND_PCI_QUIRK(0x107b, 0x0681, "Gateway NX860", STAC_M2),
1730 SND_PCI_QUIRK(0x107b, 0x0367, "Gateway MX6453", STAC_M1_2),
1731 /* Not sure about the brand name for those */
1732 SND_PCI_QUIRK(0x107b, 0x0281, "Gateway mobile", STAC_M1),
1733 SND_PCI_QUIRK(0x107b, 0x0507, "Gateway mobile", STAC_M3),
1734 SND_PCI_QUIRK(0x107b, 0x0281, "Gateway mobile", STAC_M6),
1735 SND_PCI_QUIRK(0x107b, 0x0685, "Gateway mobile", STAC_M2_2),
1736 {} /* terminator */
1739 static struct snd_pci_quirk stac925x_cfg_tbl[] = {
1740 /* SigmaTel reference board */
1741 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, "DFI LanParty", STAC_REF),
1742 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101, "DFI LanParty", STAC_REF),
1743 SND_PCI_QUIRK(0x8384, 0x7632, "Stac9202 Reference Board", STAC_REF),
1745 /* Default table for unknown ID */
1746 SND_PCI_QUIRK(0x1002, 0x437b, "Gateway mobile", STAC_M2_2),
1748 {} /* terminator */
1751 static unsigned int ref92hd73xx_pin_configs[13] = {
1752 0x02214030, 0x02a19040, 0x01a19020, 0x02214030,
1753 0x0181302e, 0x01014010, 0x01014020, 0x01014030,
1754 0x02319040, 0x90a000f0, 0x90a000f0, 0x01452050,
1755 0x01452050,
1758 static unsigned int dell_m6_pin_configs[13] = {
1759 0x0321101f, 0x4f00000f, 0x4f0000f0, 0x90170110,
1760 0x03a11020, 0x0321101f, 0x4f0000f0, 0x4f0000f0,
1761 0x4f0000f0, 0x90a60160, 0x4f0000f0, 0x4f0000f0,
1762 0x4f0000f0,
1765 static unsigned int *stac92hd73xx_brd_tbl[STAC_92HD73XX_MODELS] = {
1766 [STAC_92HD73XX_REF] = ref92hd73xx_pin_configs,
1767 [STAC_DELL_M6_AMIC] = dell_m6_pin_configs,
1768 [STAC_DELL_M6_DMIC] = dell_m6_pin_configs,
1769 [STAC_DELL_M6_BOTH] = dell_m6_pin_configs,
1770 [STAC_DELL_EQ] = dell_m6_pin_configs,
1773 static const char *stac92hd73xx_models[STAC_92HD73XX_MODELS] = {
1774 [STAC_92HD73XX_AUTO] = "auto",
1775 [STAC_92HD73XX_NO_JD] = "no-jd",
1776 [STAC_92HD73XX_REF] = "ref",
1777 [STAC_DELL_M6_AMIC] = "dell-m6-amic",
1778 [STAC_DELL_M6_DMIC] = "dell-m6-dmic",
1779 [STAC_DELL_M6_BOTH] = "dell-m6",
1780 [STAC_DELL_EQ] = "dell-eq",
1783 static struct snd_pci_quirk stac92hd73xx_cfg_tbl[] = {
1784 /* SigmaTel reference board */
1785 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1786 "DFI LanParty", STAC_92HD73XX_REF),
1787 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1788 "DFI LanParty", STAC_92HD73XX_REF),
1789 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0254,
1790 "Dell Studio 1535", STAC_DELL_M6_DMIC),
1791 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0255,
1792 "unknown Dell", STAC_DELL_M6_DMIC),
1793 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0256,
1794 "unknown Dell", STAC_DELL_M6_BOTH),
1795 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0257,
1796 "unknown Dell", STAC_DELL_M6_BOTH),
1797 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025e,
1798 "unknown Dell", STAC_DELL_M6_AMIC),
1799 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025f,
1800 "unknown Dell", STAC_DELL_M6_AMIC),
1801 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0271,
1802 "unknown Dell", STAC_DELL_M6_DMIC),
1803 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0272,
1804 "unknown Dell", STAC_DELL_M6_DMIC),
1805 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x029f,
1806 "Dell Studio 1537", STAC_DELL_M6_DMIC),
1807 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02a0,
1808 "Dell Studio 17", STAC_DELL_M6_DMIC),
1809 {} /* terminator */
1812 static unsigned int ref92hd83xxx_pin_configs[10] = {
1813 0x02214030, 0x02211010, 0x02a19020, 0x02170130,
1814 0x01014050, 0x01819040, 0x01014020, 0x90a3014e,
1815 0x01451160, 0x98560170,
1818 static unsigned int dell_s14_pin_configs[10] = {
1819 0x02214030, 0x02211010, 0x02a19020, 0x01014050,
1820 0x40f000f0, 0x01819040, 0x40f000f0, 0x90a60160,
1821 0x40f000f0, 0x40f000f0,
1824 static unsigned int *stac92hd83xxx_brd_tbl[STAC_92HD83XXX_MODELS] = {
1825 [STAC_92HD83XXX_REF] = ref92hd83xxx_pin_configs,
1826 [STAC_92HD83XXX_PWR_REF] = ref92hd83xxx_pin_configs,
1827 [STAC_DELL_S14] = dell_s14_pin_configs,
1830 static const char *stac92hd83xxx_models[STAC_92HD83XXX_MODELS] = {
1831 [STAC_92HD83XXX_AUTO] = "auto",
1832 [STAC_92HD83XXX_REF] = "ref",
1833 [STAC_92HD83XXX_PWR_REF] = "mic-ref",
1834 [STAC_DELL_S14] = "dell-s14",
1837 static struct snd_pci_quirk stac92hd83xxx_cfg_tbl[] = {
1838 /* SigmaTel reference board */
1839 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1840 "DFI LanParty", STAC_92HD83XXX_REF),
1841 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1842 "DFI LanParty", STAC_92HD83XXX_REF),
1843 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ba,
1844 "unknown Dell", STAC_DELL_S14),
1845 {} /* terminator */
1848 static unsigned int ref92hd71bxx_pin_configs[STAC92HD71BXX_NUM_PINS] = {
1849 0x02214030, 0x02a19040, 0x01a19020, 0x01014010,
1850 0x0181302e, 0x01014010, 0x01019020, 0x90a000f0,
1851 0x90a000f0, 0x01452050, 0x01452050, 0x00000000,
1852 0x00000000
1855 static unsigned int dell_m4_1_pin_configs[STAC92HD71BXX_NUM_PINS] = {
1856 0x0421101f, 0x04a11221, 0x40f000f0, 0x90170110,
1857 0x23a1902e, 0x23014250, 0x40f000f0, 0x90a000f0,
1858 0x40f000f0, 0x4f0000f0, 0x4f0000f0, 0x00000000,
1859 0x00000000
1862 static unsigned int dell_m4_2_pin_configs[STAC92HD71BXX_NUM_PINS] = {
1863 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1864 0x23a1902e, 0x23014250, 0x40f000f0, 0x40f000f0,
1865 0x40f000f0, 0x044413b0, 0x044413b0, 0x00000000,
1866 0x00000000
1869 static unsigned int dell_m4_3_pin_configs[STAC92HD71BXX_NUM_PINS] = {
1870 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1871 0x40f000f0, 0x40f000f0, 0x40f000f0, 0x90a000f0,
1872 0x40f000f0, 0x044413b0, 0x044413b0, 0x00000000,
1873 0x00000000
1876 static unsigned int *stac92hd71bxx_brd_tbl[STAC_92HD71BXX_MODELS] = {
1877 [STAC_92HD71BXX_REF] = ref92hd71bxx_pin_configs,
1878 [STAC_DELL_M4_1] = dell_m4_1_pin_configs,
1879 [STAC_DELL_M4_2] = dell_m4_2_pin_configs,
1880 [STAC_DELL_M4_3] = dell_m4_3_pin_configs,
1881 [STAC_HP_M4] = NULL,
1882 [STAC_HP_DV5] = NULL,
1883 [STAC_HP_HDX] = NULL,
1884 [STAC_HP_DV4_1222NR] = NULL,
1887 static const char *stac92hd71bxx_models[STAC_92HD71BXX_MODELS] = {
1888 [STAC_92HD71BXX_AUTO] = "auto",
1889 [STAC_92HD71BXX_REF] = "ref",
1890 [STAC_DELL_M4_1] = "dell-m4-1",
1891 [STAC_DELL_M4_2] = "dell-m4-2",
1892 [STAC_DELL_M4_3] = "dell-m4-3",
1893 [STAC_HP_M4] = "hp-m4",
1894 [STAC_HP_DV5] = "hp-dv5",
1895 [STAC_HP_HDX] = "hp-hdx",
1896 [STAC_HP_DV4_1222NR] = "hp-dv4-1222nr",
1899 static struct snd_pci_quirk stac92hd71bxx_cfg_tbl[] = {
1900 /* SigmaTel reference board */
1901 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1902 "DFI LanParty", STAC_92HD71BXX_REF),
1903 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1904 "DFI LanParty", STAC_92HD71BXX_REF),
1905 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x30fb,
1906 "HP dv4-1222nr", STAC_HP_DV4_1222NR),
1907 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3080,
1908 "HP", STAC_HP_DV5),
1909 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x30f0,
1910 "HP dv4-7", STAC_HP_DV5),
1911 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3600,
1912 "HP dv4-7", STAC_HP_DV5),
1913 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3610,
1914 "HP HDX", STAC_HP_HDX), /* HDX18 */
1915 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361a,
1916 "HP mini 1000", STAC_HP_M4),
1917 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361b,
1918 "HP HDX", STAC_HP_HDX), /* HDX16 */
1919 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0233,
1920 "unknown Dell", STAC_DELL_M4_1),
1921 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0234,
1922 "unknown Dell", STAC_DELL_M4_1),
1923 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0250,
1924 "unknown Dell", STAC_DELL_M4_1),
1925 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024f,
1926 "unknown Dell", STAC_DELL_M4_1),
1927 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024d,
1928 "unknown Dell", STAC_DELL_M4_1),
1929 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0251,
1930 "unknown Dell", STAC_DELL_M4_1),
1931 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0277,
1932 "unknown Dell", STAC_DELL_M4_1),
1933 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0263,
1934 "unknown Dell", STAC_DELL_M4_2),
1935 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0265,
1936 "unknown Dell", STAC_DELL_M4_2),
1937 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0262,
1938 "unknown Dell", STAC_DELL_M4_2),
1939 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0264,
1940 "unknown Dell", STAC_DELL_M4_2),
1941 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02aa,
1942 "unknown Dell", STAC_DELL_M4_3),
1943 {} /* terminator */
1946 static unsigned int ref922x_pin_configs[10] = {
1947 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
1948 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
1949 0x40000100, 0x40000100,
1953 STAC 922X pin configs for
1954 102801A7
1955 102801AB
1956 102801A9
1957 102801D1
1958 102801D2
1960 static unsigned int dell_922x_d81_pin_configs[10] = {
1961 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1962 0x02a19020, 0x01117011, 0x400001f0, 0x400001f1,
1963 0x01813122, 0x400001f2,
1967 STAC 922X pin configs for
1968 102801AC
1969 102801D0
1971 static unsigned int dell_922x_d82_pin_configs[10] = {
1972 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1973 0x02a19020, 0x01117011, 0x01451140, 0x400001f0,
1974 0x01813122, 0x400001f1,
1978 STAC 922X pin configs for
1979 102801BF
1981 static unsigned int dell_922x_m81_pin_configs[10] = {
1982 0x0321101f, 0x01112024, 0x01111222, 0x91174220,
1983 0x03a11050, 0x01116221, 0x90a70330, 0x01452340,
1984 0x40C003f1, 0x405003f0,
1988 STAC 9221 A1 pin configs for
1989 102801D7 (Dell XPS M1210)
1991 static unsigned int dell_922x_m82_pin_configs[10] = {
1992 0x02211211, 0x408103ff, 0x02a1123e, 0x90100310,
1993 0x408003f1, 0x0221121f, 0x03451340, 0x40c003f2,
1994 0x508003f3, 0x405003f4,
1997 static unsigned int d945gtp3_pin_configs[10] = {
1998 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
1999 0x40000100, 0x40000100, 0x40000100, 0x40000100,
2000 0x02a19120, 0x40000100,
2003 static unsigned int d945gtp5_pin_configs[10] = {
2004 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
2005 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
2006 0x02a19320, 0x40000100,
2009 static unsigned int intel_mac_v1_pin_configs[10] = {
2010 0x0121e21f, 0x400000ff, 0x9017e110, 0x400000fd,
2011 0x400000fe, 0x0181e020, 0x1145e030, 0x11c5e240,
2012 0x400000fc, 0x400000fb,
2015 static unsigned int intel_mac_v2_pin_configs[10] = {
2016 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
2017 0x400000fe, 0x0181e020, 0x1145e230, 0x500000fa,
2018 0x400000fc, 0x400000fb,
2021 static unsigned int intel_mac_v3_pin_configs[10] = {
2022 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
2023 0x400000fe, 0x0181e020, 0x1145e230, 0x11c5e240,
2024 0x400000fc, 0x400000fb,
2027 static unsigned int intel_mac_v4_pin_configs[10] = {
2028 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
2029 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
2030 0x400000fc, 0x400000fb,
2033 static unsigned int intel_mac_v5_pin_configs[10] = {
2034 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
2035 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
2036 0x400000fc, 0x400000fb,
2039 static unsigned int ecs202_pin_configs[10] = {
2040 0x0221401f, 0x02a19020, 0x01a19020, 0x01114010,
2041 0x408000f0, 0x01813022, 0x074510a0, 0x40c400f1,
2042 0x9037012e, 0x40e000f2,
2045 static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
2046 [STAC_D945_REF] = ref922x_pin_configs,
2047 [STAC_D945GTP3] = d945gtp3_pin_configs,
2048 [STAC_D945GTP5] = d945gtp5_pin_configs,
2049 [STAC_INTEL_MAC_V1] = intel_mac_v1_pin_configs,
2050 [STAC_INTEL_MAC_V2] = intel_mac_v2_pin_configs,
2051 [STAC_INTEL_MAC_V3] = intel_mac_v3_pin_configs,
2052 [STAC_INTEL_MAC_V4] = intel_mac_v4_pin_configs,
2053 [STAC_INTEL_MAC_V5] = intel_mac_v5_pin_configs,
2054 [STAC_INTEL_MAC_AUTO] = intel_mac_v3_pin_configs,
2055 /* for backward compatibility */
2056 [STAC_MACMINI] = intel_mac_v3_pin_configs,
2057 [STAC_MACBOOK] = intel_mac_v5_pin_configs,
2058 [STAC_MACBOOK_PRO_V1] = intel_mac_v3_pin_configs,
2059 [STAC_MACBOOK_PRO_V2] = intel_mac_v3_pin_configs,
2060 [STAC_IMAC_INTEL] = intel_mac_v2_pin_configs,
2061 [STAC_IMAC_INTEL_20] = intel_mac_v3_pin_configs,
2062 [STAC_ECS_202] = ecs202_pin_configs,
2063 [STAC_922X_DELL_D81] = dell_922x_d81_pin_configs,
2064 [STAC_922X_DELL_D82] = dell_922x_d82_pin_configs,
2065 [STAC_922X_DELL_M81] = dell_922x_m81_pin_configs,
2066 [STAC_922X_DELL_M82] = dell_922x_m82_pin_configs,
2069 static const char *stac922x_models[STAC_922X_MODELS] = {
2070 [STAC_922X_AUTO] = "auto",
2071 [STAC_D945_REF] = "ref",
2072 [STAC_D945GTP5] = "5stack",
2073 [STAC_D945GTP3] = "3stack",
2074 [STAC_INTEL_MAC_V1] = "intel-mac-v1",
2075 [STAC_INTEL_MAC_V2] = "intel-mac-v2",
2076 [STAC_INTEL_MAC_V3] = "intel-mac-v3",
2077 [STAC_INTEL_MAC_V4] = "intel-mac-v4",
2078 [STAC_INTEL_MAC_V5] = "intel-mac-v5",
2079 [STAC_INTEL_MAC_AUTO] = "intel-mac-auto",
2080 /* for backward compatibility */
2081 [STAC_MACMINI] = "macmini",
2082 [STAC_MACBOOK] = "macbook",
2083 [STAC_MACBOOK_PRO_V1] = "macbook-pro-v1",
2084 [STAC_MACBOOK_PRO_V2] = "macbook-pro",
2085 [STAC_IMAC_INTEL] = "imac-intel",
2086 [STAC_IMAC_INTEL_20] = "imac-intel-20",
2087 [STAC_ECS_202] = "ecs202",
2088 [STAC_922X_DELL_D81] = "dell-d81",
2089 [STAC_922X_DELL_D82] = "dell-d82",
2090 [STAC_922X_DELL_M81] = "dell-m81",
2091 [STAC_922X_DELL_M82] = "dell-m82",
2094 static struct snd_pci_quirk stac922x_cfg_tbl[] = {
2095 /* SigmaTel reference board */
2096 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2097 "DFI LanParty", STAC_D945_REF),
2098 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2099 "DFI LanParty", STAC_D945_REF),
2100 /* Intel 945G based systems */
2101 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101,
2102 "Intel D945G", STAC_D945GTP3),
2103 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0202,
2104 "Intel D945G", STAC_D945GTP3),
2105 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0606,
2106 "Intel D945G", STAC_D945GTP3),
2107 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0601,
2108 "Intel D945G", STAC_D945GTP3),
2109 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0111,
2110 "Intel D945G", STAC_D945GTP3),
2111 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1115,
2112 "Intel D945G", STAC_D945GTP3),
2113 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1116,
2114 "Intel D945G", STAC_D945GTP3),
2115 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1117,
2116 "Intel D945G", STAC_D945GTP3),
2117 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1118,
2118 "Intel D945G", STAC_D945GTP3),
2119 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1119,
2120 "Intel D945G", STAC_D945GTP3),
2121 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x8826,
2122 "Intel D945G", STAC_D945GTP3),
2123 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5049,
2124 "Intel D945G", STAC_D945GTP3),
2125 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5055,
2126 "Intel D945G", STAC_D945GTP3),
2127 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5048,
2128 "Intel D945G", STAC_D945GTP3),
2129 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0110,
2130 "Intel D945G", STAC_D945GTP3),
2131 /* Intel D945G 5-stack systems */
2132 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0404,
2133 "Intel D945G", STAC_D945GTP5),
2134 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0303,
2135 "Intel D945G", STAC_D945GTP5),
2136 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0013,
2137 "Intel D945G", STAC_D945GTP5),
2138 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0417,
2139 "Intel D945G", STAC_D945GTP5),
2140 /* Intel 945P based systems */
2141 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0b0b,
2142 "Intel D945P", STAC_D945GTP3),
2143 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0112,
2144 "Intel D945P", STAC_D945GTP3),
2145 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0d0d,
2146 "Intel D945P", STAC_D945GTP3),
2147 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0909,
2148 "Intel D945P", STAC_D945GTP3),
2149 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0505,
2150 "Intel D945P", STAC_D945GTP3),
2151 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707,
2152 "Intel D945P", STAC_D945GTP5),
2153 /* other intel */
2154 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0204,
2155 "Intel D945", STAC_D945_REF),
2156 /* other systems */
2157 /* Apple Intel Mac (Mac Mini, MacBook, MacBook Pro...) */
2158 SND_PCI_QUIRK(0x8384, 0x7680,
2159 "Mac", STAC_INTEL_MAC_AUTO),
2160 /* Dell systems */
2161 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a7,
2162 "unknown Dell", STAC_922X_DELL_D81),
2163 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a9,
2164 "unknown Dell", STAC_922X_DELL_D81),
2165 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ab,
2166 "unknown Dell", STAC_922X_DELL_D81),
2167 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ac,
2168 "unknown Dell", STAC_922X_DELL_D82),
2169 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bf,
2170 "unknown Dell", STAC_922X_DELL_M81),
2171 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d0,
2172 "unknown Dell", STAC_922X_DELL_D82),
2173 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d1,
2174 "unknown Dell", STAC_922X_DELL_D81),
2175 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d2,
2176 "unknown Dell", STAC_922X_DELL_D81),
2177 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d7,
2178 "Dell XPS M1210", STAC_922X_DELL_M82),
2179 /* ECS/PC Chips boards */
2180 SND_PCI_QUIRK_MASK(0x1019, 0xf000, 0x2000,
2181 "ECS/PC chips", STAC_ECS_202),
2182 {} /* terminator */
2185 static unsigned int ref927x_pin_configs[14] = {
2186 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2187 0x01a19040, 0x01011012, 0x01016011, 0x0101201f,
2188 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
2189 0x01c42190, 0x40000100,
2192 static unsigned int d965_3st_pin_configs[14] = {
2193 0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
2194 0x01a19021, 0x01813024, 0x40000100, 0x40000100,
2195 0x40000100, 0x40000100, 0x40000100, 0x40000100,
2196 0x40000100, 0x40000100
2199 static unsigned int d965_5st_pin_configs[14] = {
2200 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2201 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
2202 0x40000100, 0x40000100, 0x40000100, 0x01442070,
2203 0x40000100, 0x40000100
2206 static unsigned int d965_5st_no_fp_pin_configs[14] = {
2207 0x40000100, 0x40000100, 0x0181304e, 0x01014010,
2208 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
2209 0x40000100, 0x40000100, 0x40000100, 0x01442070,
2210 0x40000100, 0x40000100
2213 static unsigned int dell_3st_pin_configs[14] = {
2214 0x02211230, 0x02a11220, 0x01a19040, 0x01114210,
2215 0x01111212, 0x01116211, 0x01813050, 0x01112214,
2216 0x403003fa, 0x90a60040, 0x90a60040, 0x404003fb,
2217 0x40c003fc, 0x40000100
2220 static unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
2221 [STAC_D965_REF_NO_JD] = ref927x_pin_configs,
2222 [STAC_D965_REF] = ref927x_pin_configs,
2223 [STAC_D965_3ST] = d965_3st_pin_configs,
2224 [STAC_D965_5ST] = d965_5st_pin_configs,
2225 [STAC_D965_5ST_NO_FP] = d965_5st_no_fp_pin_configs,
2226 [STAC_DELL_3ST] = dell_3st_pin_configs,
2227 [STAC_DELL_BIOS] = NULL,
2230 static const char *stac927x_models[STAC_927X_MODELS] = {
2231 [STAC_927X_AUTO] = "auto",
2232 [STAC_D965_REF_NO_JD] = "ref-no-jd",
2233 [STAC_D965_REF] = "ref",
2234 [STAC_D965_3ST] = "3stack",
2235 [STAC_D965_5ST] = "5stack",
2236 [STAC_D965_5ST_NO_FP] = "5stack-no-fp",
2237 [STAC_DELL_3ST] = "dell-3stack",
2238 [STAC_DELL_BIOS] = "dell-bios",
2241 static struct snd_pci_quirk stac927x_cfg_tbl[] = {
2242 /* SigmaTel reference board */
2243 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2244 "DFI LanParty", STAC_D965_REF),
2245 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2246 "DFI LanParty", STAC_D965_REF),
2247 /* Intel 946 based systems */
2248 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST),
2249 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST),
2250 /* 965 based 3 stack systems */
2251 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2100,
2252 "Intel D965", STAC_D965_3ST),
2253 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2000,
2254 "Intel D965", STAC_D965_3ST),
2255 /* Dell 3 stack systems */
2256 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f7, "Dell XPS M1730", STAC_DELL_3ST),
2257 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01dd, "Dell Dimension E520", STAC_DELL_3ST),
2258 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ed, "Dell ", STAC_DELL_3ST),
2259 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f4, "Dell ", STAC_DELL_3ST),
2260 /* Dell 3 stack systems with verb table in BIOS */
2261 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f3, "Dell Inspiron 1420", STAC_DELL_BIOS),
2262 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0227, "Dell Vostro 1400 ", STAC_DELL_BIOS),
2263 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022e, "Dell ", STAC_DELL_BIOS),
2264 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022f, "Dell Inspiron 1525", STAC_DELL_3ST),
2265 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0242, "Dell ", STAC_DELL_BIOS),
2266 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0243, "Dell ", STAC_DELL_BIOS),
2267 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ff, "Dell ", STAC_DELL_BIOS),
2268 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0209, "Dell XPS 1330", STAC_DELL_BIOS),
2269 /* 965 based 5 stack systems */
2270 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2300,
2271 "Intel D965", STAC_D965_5ST),
2272 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2500,
2273 "Intel D965", STAC_D965_5ST),
2274 {} /* terminator */
2277 static unsigned int ref9205_pin_configs[12] = {
2278 0x40000100, 0x40000100, 0x01016011, 0x01014010,
2279 0x01813122, 0x01a19021, 0x01019020, 0x40000100,
2280 0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
2284 STAC 9205 pin configs for
2285 102801F1
2286 102801F2
2287 102801FC
2288 102801FD
2289 10280204
2290 1028021F
2291 10280228 (Dell Vostro 1500)
2293 static unsigned int dell_9205_m42_pin_configs[12] = {
2294 0x0321101F, 0x03A11020, 0x400003FA, 0x90170310,
2295 0x400003FB, 0x400003FC, 0x400003FD, 0x40F000F9,
2296 0x90A60330, 0x400003FF, 0x0144131F, 0x40C003FE,
2300 STAC 9205 pin configs for
2301 102801F9
2302 102801FA
2303 102801FE
2304 102801FF (Dell Precision M4300)
2305 10280206
2306 10280200
2307 10280201
2309 static unsigned int dell_9205_m43_pin_configs[12] = {
2310 0x0321101f, 0x03a11020, 0x90a70330, 0x90170310,
2311 0x400000fe, 0x400000ff, 0x400000fd, 0x40f000f9,
2312 0x400000fa, 0x400000fc, 0x0144131f, 0x40c003f8,
2315 static unsigned int dell_9205_m44_pin_configs[12] = {
2316 0x0421101f, 0x04a11020, 0x400003fa, 0x90170310,
2317 0x400003fb, 0x400003fc, 0x400003fd, 0x400003f9,
2318 0x90a60330, 0x400003ff, 0x01441340, 0x40c003fe,
2321 static unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
2322 [STAC_9205_REF] = ref9205_pin_configs,
2323 [STAC_9205_DELL_M42] = dell_9205_m42_pin_configs,
2324 [STAC_9205_DELL_M43] = dell_9205_m43_pin_configs,
2325 [STAC_9205_DELL_M44] = dell_9205_m44_pin_configs,
2326 [STAC_9205_EAPD] = NULL,
2329 static const char *stac9205_models[STAC_9205_MODELS] = {
2330 [STAC_9205_AUTO] = "auto",
2331 [STAC_9205_REF] = "ref",
2332 [STAC_9205_DELL_M42] = "dell-m42",
2333 [STAC_9205_DELL_M43] = "dell-m43",
2334 [STAC_9205_DELL_M44] = "dell-m44",
2335 [STAC_9205_EAPD] = "eapd",
2338 static struct snd_pci_quirk stac9205_cfg_tbl[] = {
2339 /* SigmaTel reference board */
2340 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2341 "DFI LanParty", STAC_9205_REF),
2342 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xfb30,
2343 "SigmaTel", STAC_9205_REF),
2344 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2345 "DFI LanParty", STAC_9205_REF),
2346 /* Dell */
2347 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f1,
2348 "unknown Dell", STAC_9205_DELL_M42),
2349 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f2,
2350 "unknown Dell", STAC_9205_DELL_M42),
2351 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f8,
2352 "Dell Precision", STAC_9205_DELL_M43),
2353 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f9,
2354 "Dell Precision", STAC_9205_DELL_M43),
2355 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fa,
2356 "Dell Precision", STAC_9205_DELL_M43),
2357 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fc,
2358 "unknown Dell", STAC_9205_DELL_M42),
2359 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fd,
2360 "unknown Dell", STAC_9205_DELL_M42),
2361 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fe,
2362 "Dell Precision", STAC_9205_DELL_M43),
2363 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ff,
2364 "Dell Precision M4300", STAC_9205_DELL_M43),
2365 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0204,
2366 "unknown Dell", STAC_9205_DELL_M42),
2367 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0206,
2368 "Dell Precision", STAC_9205_DELL_M43),
2369 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021b,
2370 "Dell Precision", STAC_9205_DELL_M43),
2371 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021c,
2372 "Dell Precision", STAC_9205_DELL_M43),
2373 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021f,
2374 "Dell Inspiron", STAC_9205_DELL_M44),
2375 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0228,
2376 "Dell Vostro 1500", STAC_9205_DELL_M42),
2377 /* Gateway */
2378 SND_PCI_QUIRK(0x107b, 0x0560, "Gateway T6834c", STAC_9205_EAPD),
2379 SND_PCI_QUIRK(0x107b, 0x0565, "Gateway T1616", STAC_9205_EAPD),
2380 {} /* terminator */
2383 static void stac92xx_set_config_regs(struct hda_codec *codec,
2384 unsigned int *pincfgs)
2386 int i;
2387 struct sigmatel_spec *spec = codec->spec;
2389 if (!pincfgs)
2390 return;
2392 for (i = 0; i < spec->num_pins; i++)
2393 if (spec->pin_nids[i] && pincfgs[i])
2394 snd_hda_codec_set_pincfg(codec, spec->pin_nids[i],
2395 pincfgs[i]);
2399 * Analog playback callbacks
2401 static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
2402 struct hda_codec *codec,
2403 struct snd_pcm_substream *substream)
2405 struct sigmatel_spec *spec = codec->spec;
2406 if (spec->stream_delay)
2407 msleep(spec->stream_delay);
2408 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2409 hinfo);
2412 static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2413 struct hda_codec *codec,
2414 unsigned int stream_tag,
2415 unsigned int format,
2416 struct snd_pcm_substream *substream)
2418 struct sigmatel_spec *spec = codec->spec;
2419 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
2422 static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2423 struct hda_codec *codec,
2424 struct snd_pcm_substream *substream)
2426 struct sigmatel_spec *spec = codec->spec;
2427 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2431 * Digital playback callbacks
2433 static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2434 struct hda_codec *codec,
2435 struct snd_pcm_substream *substream)
2437 struct sigmatel_spec *spec = codec->spec;
2438 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2441 static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2442 struct hda_codec *codec,
2443 struct snd_pcm_substream *substream)
2445 struct sigmatel_spec *spec = codec->spec;
2446 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2449 static int stac92xx_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2450 struct hda_codec *codec,
2451 unsigned int stream_tag,
2452 unsigned int format,
2453 struct snd_pcm_substream *substream)
2455 struct sigmatel_spec *spec = codec->spec;
2456 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2457 stream_tag, format, substream);
2460 static int stac92xx_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2461 struct hda_codec *codec,
2462 struct snd_pcm_substream *substream)
2464 struct sigmatel_spec *spec = codec->spec;
2465 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2470 * Analog capture callbacks
2472 static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2473 struct hda_codec *codec,
2474 unsigned int stream_tag,
2475 unsigned int format,
2476 struct snd_pcm_substream *substream)
2478 struct sigmatel_spec *spec = codec->spec;
2479 hda_nid_t nid = spec->adc_nids[substream->number];
2481 if (spec->powerdown_adcs) {
2482 msleep(40);
2483 snd_hda_codec_write(codec, nid, 0,
2484 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
2486 snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format);
2487 return 0;
2490 static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2491 struct hda_codec *codec,
2492 struct snd_pcm_substream *substream)
2494 struct sigmatel_spec *spec = codec->spec;
2495 hda_nid_t nid = spec->adc_nids[substream->number];
2497 snd_hda_codec_cleanup_stream(codec, nid);
2498 if (spec->powerdown_adcs)
2499 snd_hda_codec_write(codec, nid, 0,
2500 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
2501 return 0;
2504 static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
2505 .substreams = 1,
2506 .channels_min = 2,
2507 .channels_max = 2,
2508 /* NID is set in stac92xx_build_pcms */
2509 .ops = {
2510 .open = stac92xx_dig_playback_pcm_open,
2511 .close = stac92xx_dig_playback_pcm_close,
2512 .prepare = stac92xx_dig_playback_pcm_prepare,
2513 .cleanup = stac92xx_dig_playback_pcm_cleanup
2517 static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
2518 .substreams = 1,
2519 .channels_min = 2,
2520 .channels_max = 2,
2521 /* NID is set in stac92xx_build_pcms */
2524 static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
2525 .substreams = 1,
2526 .channels_min = 2,
2527 .channels_max = 8,
2528 .nid = 0x02, /* NID to query formats and rates */
2529 .ops = {
2530 .open = stac92xx_playback_pcm_open,
2531 .prepare = stac92xx_playback_pcm_prepare,
2532 .cleanup = stac92xx_playback_pcm_cleanup
2536 static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
2537 .substreams = 1,
2538 .channels_min = 2,
2539 .channels_max = 2,
2540 .nid = 0x06, /* NID to query formats and rates */
2541 .ops = {
2542 .open = stac92xx_playback_pcm_open,
2543 .prepare = stac92xx_playback_pcm_prepare,
2544 .cleanup = stac92xx_playback_pcm_cleanup
2548 static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
2549 .channels_min = 2,
2550 .channels_max = 2,
2551 /* NID + .substreams is set in stac92xx_build_pcms */
2552 .ops = {
2553 .prepare = stac92xx_capture_pcm_prepare,
2554 .cleanup = stac92xx_capture_pcm_cleanup
2558 static int stac92xx_build_pcms(struct hda_codec *codec)
2560 struct sigmatel_spec *spec = codec->spec;
2561 struct hda_pcm *info = spec->pcm_rec;
2563 codec->num_pcms = 1;
2564 codec->pcm_info = info;
2566 info->name = "STAC92xx Analog";
2567 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
2568 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2569 spec->multiout.dac_nids[0];
2570 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
2571 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2572 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adcs;
2574 if (spec->alt_switch) {
2575 codec->num_pcms++;
2576 info++;
2577 info->name = "STAC92xx Analog Alt";
2578 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
2581 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2582 codec->num_pcms++;
2583 info++;
2584 info->name = "STAC92xx Digital";
2585 info->pcm_type = spec->autocfg.dig_out_type[0];
2586 if (spec->multiout.dig_out_nid) {
2587 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
2588 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2590 if (spec->dig_in_nid) {
2591 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
2592 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2596 return 0;
2599 static unsigned int stac92xx_get_default_vref(struct hda_codec *codec,
2600 hda_nid_t nid)
2602 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2603 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
2604 if (pincap & AC_PINCAP_VREF_100)
2605 return AC_PINCTL_VREF_100;
2606 if (pincap & AC_PINCAP_VREF_80)
2607 return AC_PINCTL_VREF_80;
2608 if (pincap & AC_PINCAP_VREF_50)
2609 return AC_PINCTL_VREF_50;
2610 if (pincap & AC_PINCAP_VREF_GRD)
2611 return AC_PINCTL_VREF_GRD;
2612 return 0;
2615 static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
2618 snd_hda_codec_write_cache(codec, nid, 0,
2619 AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
2622 #define stac92xx_hp_switch_info snd_ctl_boolean_mono_info
2624 static int stac92xx_hp_switch_get(struct snd_kcontrol *kcontrol,
2625 struct snd_ctl_elem_value *ucontrol)
2627 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2628 struct sigmatel_spec *spec = codec->spec;
2630 ucontrol->value.integer.value[0] = !!spec->hp_switch;
2631 return 0;
2634 static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid);
2636 static int stac92xx_hp_switch_put(struct snd_kcontrol *kcontrol,
2637 struct snd_ctl_elem_value *ucontrol)
2639 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2640 struct sigmatel_spec *spec = codec->spec;
2641 int nid = kcontrol->private_value;
2643 spec->hp_switch = ucontrol->value.integer.value[0] ? nid : 0;
2645 /* check to be sure that the ports are upto date with
2646 * switch changes
2648 stac_issue_unsol_event(codec, nid);
2650 return 1;
2653 static int stac92xx_dc_bias_info(struct snd_kcontrol *kcontrol,
2654 struct snd_ctl_elem_info *uinfo)
2656 int i;
2657 static char *texts[] = {
2658 "Mic In", "Line In", "Line Out"
2661 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2662 struct sigmatel_spec *spec = codec->spec;
2663 hda_nid_t nid = kcontrol->private_value;
2665 if (nid == spec->mic_switch || nid == spec->line_switch)
2666 i = 3;
2667 else
2668 i = 2;
2670 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2671 uinfo->value.enumerated.items = i;
2672 uinfo->count = 1;
2673 if (uinfo->value.enumerated.item >= i)
2674 uinfo->value.enumerated.item = i-1;
2675 strcpy(uinfo->value.enumerated.name,
2676 texts[uinfo->value.enumerated.item]);
2678 return 0;
2681 static int stac92xx_dc_bias_get(struct snd_kcontrol *kcontrol,
2682 struct snd_ctl_elem_value *ucontrol)
2684 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2685 hda_nid_t nid = kcontrol->private_value;
2686 unsigned int vref = stac92xx_vref_get(codec, nid);
2688 if (vref == stac92xx_get_default_vref(codec, nid))
2689 ucontrol->value.enumerated.item[0] = 0;
2690 else if (vref == AC_PINCTL_VREF_GRD)
2691 ucontrol->value.enumerated.item[0] = 1;
2692 else if (vref == AC_PINCTL_VREF_HIZ)
2693 ucontrol->value.enumerated.item[0] = 2;
2695 return 0;
2698 static int stac92xx_dc_bias_put(struct snd_kcontrol *kcontrol,
2699 struct snd_ctl_elem_value *ucontrol)
2701 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2702 unsigned int new_vref = 0;
2703 int error;
2704 hda_nid_t nid = kcontrol->private_value;
2706 if (ucontrol->value.enumerated.item[0] == 0)
2707 new_vref = stac92xx_get_default_vref(codec, nid);
2708 else if (ucontrol->value.enumerated.item[0] == 1)
2709 new_vref = AC_PINCTL_VREF_GRD;
2710 else if (ucontrol->value.enumerated.item[0] == 2)
2711 new_vref = AC_PINCTL_VREF_HIZ;
2712 else
2713 return 0;
2715 if (new_vref != stac92xx_vref_get(codec, nid)) {
2716 error = stac92xx_vref_set(codec, nid, new_vref);
2717 return error;
2720 return 0;
2723 static int stac92xx_io_switch_info(struct snd_kcontrol *kcontrol,
2724 struct snd_ctl_elem_info *uinfo)
2726 static char *texts[2];
2727 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2728 struct sigmatel_spec *spec = codec->spec;
2730 if (kcontrol->private_value == spec->line_switch)
2731 texts[0] = "Line In";
2732 else
2733 texts[0] = "Mic In";
2734 texts[1] = "Line Out";
2735 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2736 uinfo->value.enumerated.items = 2;
2737 uinfo->count = 1;
2739 if (uinfo->value.enumerated.item >= 2)
2740 uinfo->value.enumerated.item = 1;
2741 strcpy(uinfo->value.enumerated.name,
2742 texts[uinfo->value.enumerated.item]);
2744 return 0;
2747 static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2749 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2750 struct sigmatel_spec *spec = codec->spec;
2751 hda_nid_t nid = kcontrol->private_value;
2752 int io_idx = (nid == spec->mic_switch) ? 1 : 0;
2754 ucontrol->value.enumerated.item[0] = spec->io_switch[io_idx];
2755 return 0;
2758 static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2760 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2761 struct sigmatel_spec *spec = codec->spec;
2762 hda_nid_t nid = kcontrol->private_value;
2763 int io_idx = (nid == spec->mic_switch) ? 1 : 0;
2764 unsigned short val = !!ucontrol->value.enumerated.item[0];
2766 spec->io_switch[io_idx] = val;
2768 if (val)
2769 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
2770 else {
2771 unsigned int pinctl = AC_PINCTL_IN_EN;
2772 if (io_idx) /* set VREF for mic */
2773 pinctl |= stac92xx_get_default_vref(codec, nid);
2774 stac92xx_auto_set_pinctl(codec, nid, pinctl);
2777 /* check the auto-mute again: we need to mute/unmute the speaker
2778 * appropriately according to the pin direction
2780 if (spec->hp_detect)
2781 stac_issue_unsol_event(codec, nid);
2783 return 1;
2786 #define stac92xx_clfe_switch_info snd_ctl_boolean_mono_info
2788 static int stac92xx_clfe_switch_get(struct snd_kcontrol *kcontrol,
2789 struct snd_ctl_elem_value *ucontrol)
2791 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2792 struct sigmatel_spec *spec = codec->spec;
2794 ucontrol->value.integer.value[0] = spec->clfe_swap;
2795 return 0;
2798 static int stac92xx_clfe_switch_put(struct snd_kcontrol *kcontrol,
2799 struct snd_ctl_elem_value *ucontrol)
2801 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2802 struct sigmatel_spec *spec = codec->spec;
2803 hda_nid_t nid = kcontrol->private_value & 0xff;
2804 unsigned int val = !!ucontrol->value.integer.value[0];
2806 if (spec->clfe_swap == val)
2807 return 0;
2809 spec->clfe_swap = val;
2811 snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
2812 spec->clfe_swap ? 0x4 : 0x0);
2814 return 1;
2817 #define STAC_CODEC_HP_SWITCH(xname) \
2818 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2819 .name = xname, \
2820 .index = 0, \
2821 .info = stac92xx_hp_switch_info, \
2822 .get = stac92xx_hp_switch_get, \
2823 .put = stac92xx_hp_switch_put, \
2826 #define STAC_CODEC_IO_SWITCH(xname, xpval) \
2827 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2828 .name = xname, \
2829 .index = 0, \
2830 .info = stac92xx_io_switch_info, \
2831 .get = stac92xx_io_switch_get, \
2832 .put = stac92xx_io_switch_put, \
2833 .private_value = xpval, \
2836 #define STAC_CODEC_CLFE_SWITCH(xname, xpval) \
2837 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2838 .name = xname, \
2839 .index = 0, \
2840 .info = stac92xx_clfe_switch_info, \
2841 .get = stac92xx_clfe_switch_get, \
2842 .put = stac92xx_clfe_switch_put, \
2843 .private_value = xpval, \
2846 enum {
2847 STAC_CTL_WIDGET_VOL,
2848 STAC_CTL_WIDGET_MUTE,
2849 STAC_CTL_WIDGET_MONO_MUX,
2850 STAC_CTL_WIDGET_AMP_MUX,
2851 STAC_CTL_WIDGET_AMP_VOL,
2852 STAC_CTL_WIDGET_HP_SWITCH,
2853 STAC_CTL_WIDGET_IO_SWITCH,
2854 STAC_CTL_WIDGET_CLFE_SWITCH,
2855 STAC_CTL_WIDGET_DC_BIAS
2858 static struct snd_kcontrol_new stac92xx_control_templates[] = {
2859 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2860 HDA_CODEC_MUTE(NULL, 0, 0, 0),
2861 STAC_MONO_MUX,
2862 STAC_AMP_MUX,
2863 STAC_AMP_VOL(NULL, 0, 0, 0, 0),
2864 STAC_CODEC_HP_SWITCH(NULL),
2865 STAC_CODEC_IO_SWITCH(NULL, 0),
2866 STAC_CODEC_CLFE_SWITCH(NULL, 0),
2867 DC_BIAS(NULL, 0, 0),
2870 /* add dynamic controls */
2871 static struct snd_kcontrol_new *
2872 stac_control_new(struct sigmatel_spec *spec,
2873 struct snd_kcontrol_new *ktemp,
2874 const char *name)
2876 struct snd_kcontrol_new *knew;
2878 snd_array_init(&spec->kctls, sizeof(*knew), 32);
2879 knew = snd_array_new(&spec->kctls);
2880 if (!knew)
2881 return NULL;
2882 *knew = *ktemp;
2883 knew->name = kstrdup(name, GFP_KERNEL);
2884 if (!knew->name) {
2885 /* roolback */
2886 memset(knew, 0, sizeof(*knew));
2887 spec->kctls.alloced--;
2888 return NULL;
2890 return knew;
2893 static int stac92xx_add_control_temp(struct sigmatel_spec *spec,
2894 struct snd_kcontrol_new *ktemp,
2895 int idx, const char *name,
2896 unsigned long val)
2898 struct snd_kcontrol_new *knew = stac_control_new(spec, ktemp, name);
2899 if (!knew)
2900 return -ENOMEM;
2901 knew->index = idx;
2902 knew->private_value = val;
2903 return 0;
2906 static inline int stac92xx_add_control_idx(struct sigmatel_spec *spec,
2907 int type, int idx, const char *name,
2908 unsigned long val)
2910 return stac92xx_add_control_temp(spec,
2911 &stac92xx_control_templates[type],
2912 idx, name, val);
2916 /* add dynamic controls */
2917 static inline int stac92xx_add_control(struct sigmatel_spec *spec, int type,
2918 const char *name, unsigned long val)
2920 return stac92xx_add_control_idx(spec, type, 0, name, val);
2923 static struct snd_kcontrol_new stac_input_src_temp = {
2924 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2925 .name = "Input Source",
2926 .info = stac92xx_mux_enum_info,
2927 .get = stac92xx_mux_enum_get,
2928 .put = stac92xx_mux_enum_put,
2931 static inline int stac92xx_add_jack_mode_control(struct hda_codec *codec,
2932 hda_nid_t nid, int idx)
2934 int def_conf = snd_hda_codec_get_pincfg(codec, nid);
2935 int control = 0;
2936 struct sigmatel_spec *spec = codec->spec;
2937 char name[22];
2939 if (!((get_defcfg_connect(def_conf)) & AC_JACK_PORT_FIXED)) {
2940 if (stac92xx_get_default_vref(codec, nid) == AC_PINCTL_VREF_GRD
2941 && nid == spec->line_switch)
2942 control = STAC_CTL_WIDGET_IO_SWITCH;
2943 else if (snd_hda_query_pin_caps(codec, nid)
2944 & (AC_PINCAP_VREF_GRD << AC_PINCAP_VREF_SHIFT))
2945 control = STAC_CTL_WIDGET_DC_BIAS;
2946 else if (nid == spec->mic_switch)
2947 control = STAC_CTL_WIDGET_IO_SWITCH;
2950 if (control) {
2951 strcpy(name, auto_pin_cfg_labels[idx]);
2952 return stac92xx_add_control(codec->spec, control,
2953 strcat(name, " Jack Mode"), nid);
2956 return 0;
2959 static int stac92xx_add_input_source(struct sigmatel_spec *spec)
2961 struct snd_kcontrol_new *knew;
2962 struct hda_input_mux *imux = &spec->private_imux;
2964 if (spec->auto_mic)
2965 return 0; /* no need for input source */
2966 if (!spec->num_adcs || imux->num_items <= 1)
2967 return 0; /* no need for input source control */
2968 knew = stac_control_new(spec, &stac_input_src_temp,
2969 stac_input_src_temp.name);
2970 if (!knew)
2971 return -ENOMEM;
2972 knew->count = spec->num_adcs;
2973 return 0;
2976 /* check whether the line-input can be used as line-out */
2977 static hda_nid_t check_line_out_switch(struct hda_codec *codec)
2979 struct sigmatel_spec *spec = codec->spec;
2980 struct auto_pin_cfg *cfg = &spec->autocfg;
2981 hda_nid_t nid;
2982 unsigned int pincap;
2984 if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
2985 return 0;
2986 nid = cfg->input_pins[AUTO_PIN_LINE];
2987 pincap = snd_hda_query_pin_caps(codec, nid);
2988 if (pincap & AC_PINCAP_OUT)
2989 return nid;
2990 return 0;
2993 /* check whether the mic-input can be used as line-out */
2994 static hda_nid_t check_mic_out_switch(struct hda_codec *codec)
2996 struct sigmatel_spec *spec = codec->spec;
2997 struct auto_pin_cfg *cfg = &spec->autocfg;
2998 unsigned int def_conf, pincap;
2999 unsigned int mic_pin;
3001 if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
3002 return 0;
3003 mic_pin = AUTO_PIN_MIC;
3004 for (;;) {
3005 hda_nid_t nid = cfg->input_pins[mic_pin];
3006 def_conf = snd_hda_codec_get_pincfg(codec, nid);
3007 /* some laptops have an internal analog microphone
3008 * which can't be used as a output */
3009 if (get_defcfg_connect(def_conf) != AC_JACK_PORT_FIXED) {
3010 pincap = snd_hda_query_pin_caps(codec, nid);
3011 if (pincap & AC_PINCAP_OUT)
3012 return nid;
3014 if (mic_pin == AUTO_PIN_MIC)
3015 mic_pin = AUTO_PIN_FRONT_MIC;
3016 else
3017 break;
3019 return 0;
3022 static int is_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
3024 int i;
3026 for (i = 0; i < spec->multiout.num_dacs; i++) {
3027 if (spec->multiout.dac_nids[i] == nid)
3028 return 1;
3031 return 0;
3034 static int check_all_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
3036 int i;
3037 if (is_in_dac_nids(spec, nid))
3038 return 1;
3039 for (i = 0; i < spec->autocfg.hp_outs; i++)
3040 if (spec->hp_dacs[i] == nid)
3041 return 1;
3042 for (i = 0; i < spec->autocfg.speaker_outs; i++)
3043 if (spec->speaker_dacs[i] == nid)
3044 return 1;
3045 return 0;
3048 static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t nid)
3050 struct sigmatel_spec *spec = codec->spec;
3051 int j, conn_len;
3052 hda_nid_t conn[HDA_MAX_CONNECTIONS];
3053 unsigned int wcaps, wtype;
3055 conn_len = snd_hda_get_connections(codec, nid, conn,
3056 HDA_MAX_CONNECTIONS);
3057 for (j = 0; j < conn_len; j++) {
3058 wcaps = get_wcaps(codec, conn[j]);
3059 wtype = get_wcaps_type(wcaps);
3060 /* we check only analog outputs */
3061 if (wtype != AC_WID_AUD_OUT || (wcaps & AC_WCAP_DIGITAL))
3062 continue;
3063 /* if this route has a free DAC, assign it */
3064 if (!check_all_dac_nids(spec, conn[j])) {
3065 if (conn_len > 1) {
3066 /* select this DAC in the pin's input mux */
3067 snd_hda_codec_write_cache(codec, nid, 0,
3068 AC_VERB_SET_CONNECT_SEL, j);
3070 return conn[j];
3073 /* if all DACs are already assigned, connect to the primary DAC */
3074 if (conn_len > 1) {
3075 for (j = 0; j < conn_len; j++) {
3076 if (conn[j] == spec->multiout.dac_nids[0]) {
3077 snd_hda_codec_write_cache(codec, nid, 0,
3078 AC_VERB_SET_CONNECT_SEL, j);
3079 break;
3083 return 0;
3086 static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid);
3087 static int add_spec_extra_dacs(struct sigmatel_spec *spec, hda_nid_t nid);
3090 * Fill in the dac_nids table from the parsed pin configuration
3091 * This function only works when every pin in line_out_pins[]
3092 * contains atleast one DAC in its connection list. Some 92xx
3093 * codecs are not connected directly to a DAC, such as the 9200
3094 * and 9202/925x. For those, dac_nids[] must be hard-coded.
3096 static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec)
3098 struct sigmatel_spec *spec = codec->spec;
3099 struct auto_pin_cfg *cfg = &spec->autocfg;
3100 int i;
3101 hda_nid_t nid, dac;
3103 for (i = 0; i < cfg->line_outs; i++) {
3104 nid = cfg->line_out_pins[i];
3105 dac = get_unassigned_dac(codec, nid);
3106 if (!dac) {
3107 if (spec->multiout.num_dacs > 0) {
3108 /* we have already working output pins,
3109 * so let's drop the broken ones again
3111 cfg->line_outs = spec->multiout.num_dacs;
3112 break;
3114 /* error out, no available DAC found */
3115 snd_printk(KERN_ERR
3116 "%s: No available DAC for pin 0x%x\n",
3117 __func__, nid);
3118 return -ENODEV;
3120 add_spec_dacs(spec, dac);
3123 for (i = 0; i < cfg->hp_outs; i++) {
3124 nid = cfg->hp_pins[i];
3125 dac = get_unassigned_dac(codec, nid);
3126 if (dac) {
3127 if (!spec->multiout.hp_nid)
3128 spec->multiout.hp_nid = dac;
3129 else
3130 add_spec_extra_dacs(spec, dac);
3132 spec->hp_dacs[i] = dac;
3135 for (i = 0; i < cfg->speaker_outs; i++) {
3136 nid = cfg->speaker_pins[i];
3137 dac = get_unassigned_dac(codec, nid);
3138 if (dac)
3139 add_spec_extra_dacs(spec, dac);
3140 spec->speaker_dacs[i] = dac;
3143 /* add line-in as output */
3144 nid = check_line_out_switch(codec);
3145 if (nid) {
3146 dac = get_unassigned_dac(codec, nid);
3147 if (dac) {
3148 snd_printdd("STAC: Add line-in 0x%x as output %d\n",
3149 nid, cfg->line_outs);
3150 cfg->line_out_pins[cfg->line_outs] = nid;
3151 cfg->line_outs++;
3152 spec->line_switch = nid;
3153 add_spec_dacs(spec, dac);
3156 /* add mic as output */
3157 nid = check_mic_out_switch(codec);
3158 if (nid) {
3159 dac = get_unassigned_dac(codec, nid);
3160 if (dac) {
3161 snd_printdd("STAC: Add mic-in 0x%x as output %d\n",
3162 nid, cfg->line_outs);
3163 cfg->line_out_pins[cfg->line_outs] = nid;
3164 cfg->line_outs++;
3165 spec->mic_switch = nid;
3166 add_spec_dacs(spec, dac);
3170 snd_printd("stac92xx: dac_nids=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
3171 spec->multiout.num_dacs,
3172 spec->multiout.dac_nids[0],
3173 spec->multiout.dac_nids[1],
3174 spec->multiout.dac_nids[2],
3175 spec->multiout.dac_nids[3],
3176 spec->multiout.dac_nids[4]);
3178 return 0;
3181 /* create volume control/switch for the given prefx type */
3182 static int create_controls_idx(struct hda_codec *codec, const char *pfx,
3183 int idx, hda_nid_t nid, int chs)
3185 struct sigmatel_spec *spec = codec->spec;
3186 char name[32];
3187 int err;
3189 if (!spec->check_volume_offset) {
3190 unsigned int caps, step, nums, db_scale;
3191 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3192 step = (caps & AC_AMPCAP_STEP_SIZE) >>
3193 AC_AMPCAP_STEP_SIZE_SHIFT;
3194 step = (step + 1) * 25; /* in .01dB unit */
3195 nums = (caps & AC_AMPCAP_NUM_STEPS) >>
3196 AC_AMPCAP_NUM_STEPS_SHIFT;
3197 db_scale = nums * step;
3198 /* if dB scale is over -64dB, and finer enough,
3199 * let's reduce it to half
3201 if (db_scale > 6400 && nums >= 0x1f)
3202 spec->volume_offset = nums / 2;
3203 spec->check_volume_offset = 1;
3206 sprintf(name, "%s Playback Volume", pfx);
3207 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_VOL, idx, name,
3208 HDA_COMPOSE_AMP_VAL_OFS(nid, chs, 0, HDA_OUTPUT,
3209 spec->volume_offset));
3210 if (err < 0)
3211 return err;
3212 sprintf(name, "%s Playback Switch", pfx);
3213 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_MUTE, idx, name,
3214 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
3215 if (err < 0)
3216 return err;
3217 return 0;
3220 #define create_controls(codec, pfx, nid, chs) \
3221 create_controls_idx(codec, pfx, 0, nid, chs)
3223 static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
3225 if (spec->multiout.num_dacs > 4) {
3226 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
3227 return 1;
3228 } else {
3229 spec->multiout.dac_nids[spec->multiout.num_dacs] = nid;
3230 spec->multiout.num_dacs++;
3232 return 0;
3235 static int add_spec_extra_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
3237 int i;
3238 for (i = 0; i < ARRAY_SIZE(spec->multiout.extra_out_nid); i++) {
3239 if (!spec->multiout.extra_out_nid[i]) {
3240 spec->multiout.extra_out_nid[i] = nid;
3241 return 0;
3244 printk(KERN_WARNING "stac92xx: No space for extra DAC 0x%x\n", nid);
3245 return 1;
3248 /* Create output controls
3249 * The mixer elements are named depending on the given type (AUTO_PIN_XXX_OUT)
3251 static int create_multi_out_ctls(struct hda_codec *codec, int num_outs,
3252 const hda_nid_t *pins,
3253 const hda_nid_t *dac_nids,
3254 int type)
3256 struct sigmatel_spec *spec = codec->spec;
3257 static const char *chname[4] = {
3258 "Front", "Surround", NULL /*CLFE*/, "Side"
3260 hda_nid_t nid;
3261 int i, err;
3262 unsigned int wid_caps;
3264 for (i = 0; i < num_outs && i < ARRAY_SIZE(chname); i++) {
3265 if (type == AUTO_PIN_HP_OUT && !spec->hp_detect) {
3266 wid_caps = get_wcaps(codec, pins[i]);
3267 if (wid_caps & AC_WCAP_UNSOL_CAP)
3268 spec->hp_detect = 1;
3270 nid = dac_nids[i];
3271 if (!nid)
3272 continue;
3273 if (type != AUTO_PIN_HP_OUT && i == 2) {
3274 /* Center/LFE */
3275 err = create_controls(codec, "Center", nid, 1);
3276 if (err < 0)
3277 return err;
3278 err = create_controls(codec, "LFE", nid, 2);
3279 if (err < 0)
3280 return err;
3282 wid_caps = get_wcaps(codec, nid);
3284 if (wid_caps & AC_WCAP_LR_SWAP) {
3285 err = stac92xx_add_control(spec,
3286 STAC_CTL_WIDGET_CLFE_SWITCH,
3287 "Swap Center/LFE Playback Switch", nid);
3289 if (err < 0)
3290 return err;
3293 } else {
3294 const char *name;
3295 int idx;
3296 switch (type) {
3297 case AUTO_PIN_HP_OUT:
3298 name = "Headphone";
3299 idx = i;
3300 break;
3301 case AUTO_PIN_SPEAKER_OUT:
3302 name = "Speaker";
3303 idx = i;
3304 break;
3305 default:
3306 name = chname[i];
3307 idx = 0;
3308 break;
3310 err = create_controls_idx(codec, name, idx, nid, 3);
3311 if (err < 0)
3312 return err;
3315 return 0;
3318 static int stac92xx_add_capvol_ctls(struct hda_codec *codec, unsigned long vol,
3319 unsigned long sw, int idx)
3321 int err;
3322 err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_VOL, idx,
3323 "Captuer Volume", vol);
3324 if (err < 0)
3325 return err;
3326 err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_MUTE, idx,
3327 "Captuer Switch", sw);
3328 if (err < 0)
3329 return err;
3330 return 0;
3333 /* add playback controls from the parsed DAC table */
3334 static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
3335 const struct auto_pin_cfg *cfg)
3337 struct sigmatel_spec *spec = codec->spec;
3338 hda_nid_t nid;
3339 int err;
3340 int idx;
3342 err = create_multi_out_ctls(codec, cfg->line_outs, cfg->line_out_pins,
3343 spec->multiout.dac_nids,
3344 cfg->line_out_type);
3345 if (err < 0)
3346 return err;
3348 if (cfg->hp_outs > 1 && cfg->line_out_type == AUTO_PIN_LINE_OUT) {
3349 err = stac92xx_add_control(spec,
3350 STAC_CTL_WIDGET_HP_SWITCH,
3351 "Headphone as Line Out Switch",
3352 cfg->hp_pins[cfg->hp_outs - 1]);
3353 if (err < 0)
3354 return err;
3357 for (idx = AUTO_PIN_MIC; idx <= AUTO_PIN_FRONT_LINE; idx++) {
3358 nid = cfg->input_pins[idx];
3359 if (nid) {
3360 err = stac92xx_add_jack_mode_control(codec, nid, idx);
3361 if (err < 0)
3362 return err;
3366 return 0;
3369 /* add playback controls for Speaker and HP outputs */
3370 static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
3371 struct auto_pin_cfg *cfg)
3373 struct sigmatel_spec *spec = codec->spec;
3374 int err;
3376 err = create_multi_out_ctls(codec, cfg->hp_outs, cfg->hp_pins,
3377 spec->hp_dacs, AUTO_PIN_HP_OUT);
3378 if (err < 0)
3379 return err;
3381 err = create_multi_out_ctls(codec, cfg->speaker_outs, cfg->speaker_pins,
3382 spec->speaker_dacs, AUTO_PIN_SPEAKER_OUT);
3383 if (err < 0)
3384 return err;
3386 return 0;
3389 /* labels for mono mux outputs */
3390 static const char *stac92xx_mono_labels[4] = {
3391 "DAC0", "DAC1", "Mixer", "DAC2"
3394 /* create mono mux for mono out on capable codecs */
3395 static int stac92xx_auto_create_mono_output_ctls(struct hda_codec *codec)
3397 struct sigmatel_spec *spec = codec->spec;
3398 struct hda_input_mux *mono_mux = &spec->private_mono_mux;
3399 int i, num_cons;
3400 hda_nid_t con_lst[ARRAY_SIZE(stac92xx_mono_labels)];
3402 num_cons = snd_hda_get_connections(codec,
3403 spec->mono_nid,
3404 con_lst,
3405 HDA_MAX_NUM_INPUTS);
3406 if (num_cons <= 0 || num_cons > ARRAY_SIZE(stac92xx_mono_labels))
3407 return -EINVAL;
3409 for (i = 0; i < num_cons; i++) {
3410 mono_mux->items[mono_mux->num_items].label =
3411 stac92xx_mono_labels[i];
3412 mono_mux->items[mono_mux->num_items].index = i;
3413 mono_mux->num_items++;
3416 return stac92xx_add_control(spec, STAC_CTL_WIDGET_MONO_MUX,
3417 "Mono Mux", spec->mono_nid);
3420 /* labels for amp mux outputs */
3421 static const char *stac92xx_amp_labels[3] = {
3422 "Front Microphone", "Microphone", "Line In",
3425 /* create amp out controls mux on capable codecs */
3426 static int stac92xx_auto_create_amp_output_ctls(struct hda_codec *codec)
3428 struct sigmatel_spec *spec = codec->spec;
3429 struct hda_input_mux *amp_mux = &spec->private_amp_mux;
3430 int i, err;
3432 for (i = 0; i < spec->num_amps; i++) {
3433 amp_mux->items[amp_mux->num_items].label =
3434 stac92xx_amp_labels[i];
3435 amp_mux->items[amp_mux->num_items].index = i;
3436 amp_mux->num_items++;
3439 if (spec->num_amps > 1) {
3440 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_AMP_MUX,
3441 "Amp Selector Capture Switch", 0);
3442 if (err < 0)
3443 return err;
3445 return stac92xx_add_control(spec, STAC_CTL_WIDGET_AMP_VOL,
3446 "Amp Capture Volume",
3447 HDA_COMPOSE_AMP_VAL(spec->amp_nids[0], 3, 0, HDA_INPUT));
3451 /* create PC beep volume controls */
3452 static int stac92xx_auto_create_beep_ctls(struct hda_codec *codec,
3453 hda_nid_t nid)
3455 struct sigmatel_spec *spec = codec->spec;
3456 u32 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3457 int err;
3459 /* check for mute support for the the amp */
3460 if ((caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT) {
3461 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE,
3462 "PC Beep Playback Switch",
3463 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3464 if (err < 0)
3465 return err;
3468 /* check to see if there is volume support for the amp */
3469 if ((caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3470 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL,
3471 "PC Beep Playback Volume",
3472 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3473 if (err < 0)
3474 return err;
3476 return 0;
3479 #ifdef CONFIG_SND_HDA_INPUT_BEEP
3480 #define stac92xx_dig_beep_switch_info snd_ctl_boolean_mono_info
3482 static int stac92xx_dig_beep_switch_get(struct snd_kcontrol *kcontrol,
3483 struct snd_ctl_elem_value *ucontrol)
3485 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3486 ucontrol->value.integer.value[0] = codec->beep->enabled;
3487 return 0;
3490 static int stac92xx_dig_beep_switch_put(struct snd_kcontrol *kcontrol,
3491 struct snd_ctl_elem_value *ucontrol)
3493 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3494 int enabled = !!ucontrol->value.integer.value[0];
3495 if (codec->beep->enabled != enabled) {
3496 codec->beep->enabled = enabled;
3497 return 1;
3499 return 0;
3502 static struct snd_kcontrol_new stac92xx_dig_beep_ctrl = {
3503 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3504 .info = stac92xx_dig_beep_switch_info,
3505 .get = stac92xx_dig_beep_switch_get,
3506 .put = stac92xx_dig_beep_switch_put,
3509 static int stac92xx_beep_switch_ctl(struct hda_codec *codec)
3511 return stac92xx_add_control_temp(codec->spec, &stac92xx_dig_beep_ctrl,
3512 0, "PC Beep Playback Switch", 0);
3514 #endif
3516 static int stac92xx_auto_create_mux_input_ctls(struct hda_codec *codec)
3518 struct sigmatel_spec *spec = codec->spec;
3519 int wcaps, nid, i, err = 0;
3521 for (i = 0; i < spec->num_muxes; i++) {
3522 nid = spec->mux_nids[i];
3523 wcaps = get_wcaps(codec, nid);
3525 if (wcaps & AC_WCAP_OUT_AMP) {
3526 err = stac92xx_add_control_idx(spec,
3527 STAC_CTL_WIDGET_VOL, i, "Mux Capture Volume",
3528 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
3529 if (err < 0)
3530 return err;
3533 return 0;
3536 static const char *stac92xx_spdif_labels[3] = {
3537 "Digital Playback", "Analog Mux 1", "Analog Mux 2",
3540 static int stac92xx_auto_create_spdif_mux_ctls(struct hda_codec *codec)
3542 struct sigmatel_spec *spec = codec->spec;
3543 struct hda_input_mux *spdif_mux = &spec->private_smux;
3544 const char **labels = spec->spdif_labels;
3545 int i, num_cons;
3546 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
3548 num_cons = snd_hda_get_connections(codec,
3549 spec->smux_nids[0],
3550 con_lst,
3551 HDA_MAX_NUM_INPUTS);
3552 if (num_cons <= 0)
3553 return -EINVAL;
3555 if (!labels)
3556 labels = stac92xx_spdif_labels;
3558 for (i = 0; i < num_cons; i++) {
3559 spdif_mux->items[spdif_mux->num_items].label = labels[i];
3560 spdif_mux->items[spdif_mux->num_items].index = i;
3561 spdif_mux->num_items++;
3564 return 0;
3567 /* labels for dmic mux inputs */
3568 static const char *stac92xx_dmic_labels[5] = {
3569 "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
3570 "Digital Mic 3", "Digital Mic 4"
3573 static int get_connection_index(struct hda_codec *codec, hda_nid_t mux,
3574 hda_nid_t nid)
3576 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
3577 int i, nums;
3579 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
3580 for (i = 0; i < nums; i++)
3581 if (conn[i] == nid)
3582 return i;
3583 return -1;
3586 /* create playback/capture controls for input pins on dmic capable codecs */
3587 static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
3588 const struct auto_pin_cfg *cfg)
3590 struct sigmatel_spec *spec = codec->spec;
3591 struct hda_input_mux *imux = &spec->private_imux;
3592 struct hda_input_mux *dimux = &spec->private_dimux;
3593 int err, i, active_mics;
3594 unsigned int def_conf;
3595 char name[32];
3597 dimux->items[dimux->num_items].label = stac92xx_dmic_labels[0];
3598 dimux->items[dimux->num_items].index = 0;
3599 dimux->num_items++;
3601 active_mics = 0;
3602 for (i = 0; i < spec->num_dmics; i++) {
3603 def_conf = snd_hda_codec_get_pincfg(codec, spec->dmic_nids[i]);
3604 if (get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)
3605 active_mics++;
3608 for (i = 0; i < spec->num_dmics; i++) {
3609 hda_nid_t nid;
3610 int index;
3611 unsigned int wcaps;
3612 const char *label;
3614 def_conf = snd_hda_codec_get_pincfg(codec, spec->dmic_nids[i]);
3615 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
3616 continue;
3618 nid = spec->dmic_nids[i];
3619 index = get_connection_index(codec, spec->dmux_nids[0], nid);
3620 if (index < 0)
3621 continue;
3623 if (active_mics == 1)
3624 label = "Digital Mic";
3625 else
3626 label = stac92xx_dmic_labels[dimux->num_items];
3628 wcaps = get_wcaps(codec, nid) &
3629 (AC_WCAP_OUT_AMP | AC_WCAP_IN_AMP);
3631 if (wcaps) {
3632 sprintf(name, "%s Capture Volume", label);
3634 err = stac92xx_add_control(spec,
3635 STAC_CTL_WIDGET_VOL,
3636 name,
3637 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3638 (wcaps & AC_WCAP_OUT_AMP) ?
3639 HDA_OUTPUT : HDA_INPUT));
3640 if (err < 0)
3641 return err;
3644 dimux->items[dimux->num_items].label = label;
3645 dimux->items[dimux->num_items].index = index;
3646 dimux->num_items++;
3647 if (snd_hda_get_bool_hint(codec, "separate_dmux") != 1) {
3648 imux->items[imux->num_items].label = label;
3649 imux->items[imux->num_items].index = index;
3650 imux->num_items++;
3654 return 0;
3657 static int check_mic_pin(struct hda_codec *codec, hda_nid_t nid,
3658 hda_nid_t *fixed, hda_nid_t *ext)
3660 unsigned int cfg;
3662 if (!nid)
3663 return 0;
3664 cfg = snd_hda_codec_get_pincfg(codec, nid);
3665 switch (get_defcfg_connect(cfg)) {
3666 case AC_JACK_PORT_FIXED:
3667 if (*fixed)
3668 return 1; /* already occupied */
3669 *fixed = nid;
3670 break;
3671 case AC_JACK_PORT_COMPLEX:
3672 if (*ext)
3673 return 1; /* already occupied */
3674 *ext = nid;
3675 break;
3677 return 0;
3680 static int set_mic_route(struct hda_codec *codec,
3681 struct sigmatel_mic_route *mic,
3682 hda_nid_t pin)
3684 struct sigmatel_spec *spec = codec->spec;
3685 struct auto_pin_cfg *cfg = &spec->autocfg;
3686 int i;
3688 mic->pin = pin;
3689 for (i = AUTO_PIN_MIC; i <= AUTO_PIN_FRONT_MIC; i++)
3690 if (pin == cfg->input_pins[i])
3691 break;
3692 if (i <= AUTO_PIN_FRONT_MIC) {
3693 /* analog pin */
3694 mic->dmux_idx = 0;
3695 i = get_connection_index(codec, spec->mux_nids[0], pin);
3696 if (i < 0)
3697 return -1;
3698 mic->mux_idx = i;
3699 } else {
3700 /* digital pin */
3701 mic->mux_idx = 0;
3702 i = get_connection_index(codec, spec->dmux_nids[0], pin);
3703 if (i < 0)
3704 return -1;
3705 mic->dmux_idx = i;
3707 return 0;
3710 /* return non-zero if the device is for automatic mic switch */
3711 static int stac_check_auto_mic(struct hda_codec *codec)
3713 struct sigmatel_spec *spec = codec->spec;
3714 struct auto_pin_cfg *cfg = &spec->autocfg;
3715 hda_nid_t fixed, ext;
3716 int i;
3718 for (i = AUTO_PIN_LINE; i < AUTO_PIN_LAST; i++) {
3719 if (cfg->input_pins[i])
3720 return 0; /* must be exclusively mics */
3722 fixed = ext = 0;
3723 for (i = AUTO_PIN_MIC; i <= AUTO_PIN_FRONT_MIC; i++)
3724 if (check_mic_pin(codec, cfg->input_pins[i], &fixed, &ext))
3725 return 0;
3726 for (i = 0; i < spec->num_dmics; i++)
3727 if (check_mic_pin(codec, spec->dmic_nids[i], &fixed, &ext))
3728 return 0;
3729 if (!fixed || !ext)
3730 return 0;
3731 if (!(get_wcaps(codec, ext) & AC_WCAP_UNSOL_CAP))
3732 return 0; /* no unsol support */
3733 if (set_mic_route(codec, &spec->ext_mic, ext) ||
3734 set_mic_route(codec, &spec->int_mic, fixed))
3735 return 0; /* something is wrong */
3736 return 1;
3739 /* create playback/capture controls for input pins */
3740 static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
3742 struct sigmatel_spec *spec = codec->spec;
3743 struct hda_input_mux *imux = &spec->private_imux;
3744 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
3745 int i, j, k;
3747 for (i = 0; i < AUTO_PIN_LAST; i++) {
3748 int index;
3750 if (!cfg->input_pins[i])
3751 continue;
3752 index = -1;
3753 for (j = 0; j < spec->num_muxes; j++) {
3754 int num_cons;
3755 num_cons = snd_hda_get_connections(codec,
3756 spec->mux_nids[j],
3757 con_lst,
3758 HDA_MAX_NUM_INPUTS);
3759 for (k = 0; k < num_cons; k++)
3760 if (con_lst[k] == cfg->input_pins[i]) {
3761 index = k;
3762 goto found;
3765 continue;
3766 found:
3767 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
3768 imux->items[imux->num_items].index = index;
3769 imux->num_items++;
3771 spec->num_analog_muxes = imux->num_items;
3773 if (imux->num_items) {
3775 * Set the current input for the muxes.
3776 * The STAC9221 has two input muxes with identical source
3777 * NID lists. Hopefully this won't get confused.
3779 for (i = 0; i < spec->num_muxes; i++) {
3780 snd_hda_codec_write_cache(codec, spec->mux_nids[i], 0,
3781 AC_VERB_SET_CONNECT_SEL,
3782 imux->items[0].index);
3786 return 0;
3789 static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
3791 struct sigmatel_spec *spec = codec->spec;
3792 int i;
3794 for (i = 0; i < spec->autocfg.line_outs; i++) {
3795 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3796 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
3800 static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
3802 struct sigmatel_spec *spec = codec->spec;
3803 int i;
3805 for (i = 0; i < spec->autocfg.hp_outs; i++) {
3806 hda_nid_t pin;
3807 pin = spec->autocfg.hp_pins[i];
3808 if (pin) /* connect to front */
3809 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
3811 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
3812 hda_nid_t pin;
3813 pin = spec->autocfg.speaker_pins[i];
3814 if (pin) /* connect to front */
3815 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
3819 static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out, hda_nid_t dig_in)
3821 struct sigmatel_spec *spec = codec->spec;
3822 int hp_swap = 0;
3823 int i, err;
3825 if ((err = snd_hda_parse_pin_def_config(codec,
3826 &spec->autocfg,
3827 spec->dmic_nids)) < 0)
3828 return err;
3829 if (! spec->autocfg.line_outs)
3830 return 0; /* can't find valid pin config */
3832 /* If we have no real line-out pin and multiple hp-outs, HPs should
3833 * be set up as multi-channel outputs.
3835 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT &&
3836 spec->autocfg.hp_outs > 1) {
3837 /* Copy hp_outs to line_outs, backup line_outs in
3838 * speaker_outs so that the following routines can handle
3839 * HP pins as primary outputs.
3841 snd_printdd("stac92xx: Enabling multi-HPs workaround\n");
3842 memcpy(spec->autocfg.speaker_pins, spec->autocfg.line_out_pins,
3843 sizeof(spec->autocfg.line_out_pins));
3844 spec->autocfg.speaker_outs = spec->autocfg.line_outs;
3845 memcpy(spec->autocfg.line_out_pins, spec->autocfg.hp_pins,
3846 sizeof(spec->autocfg.hp_pins));
3847 spec->autocfg.line_outs = spec->autocfg.hp_outs;
3848 spec->autocfg.line_out_type = AUTO_PIN_HP_OUT;
3849 spec->autocfg.hp_outs = 0;
3850 hp_swap = 1;
3852 if (spec->autocfg.mono_out_pin) {
3853 int dir = get_wcaps(codec, spec->autocfg.mono_out_pin) &
3854 (AC_WCAP_OUT_AMP | AC_WCAP_IN_AMP);
3855 u32 caps = query_amp_caps(codec,
3856 spec->autocfg.mono_out_pin, dir);
3857 hda_nid_t conn_list[1];
3859 /* get the mixer node and then the mono mux if it exists */
3860 if (snd_hda_get_connections(codec,
3861 spec->autocfg.mono_out_pin, conn_list, 1) &&
3862 snd_hda_get_connections(codec, conn_list[0],
3863 conn_list, 1) > 0) {
3865 int wcaps = get_wcaps(codec, conn_list[0]);
3866 int wid_type = get_wcaps_type(wcaps);
3867 /* LR swap check, some stac925x have a mux that
3868 * changes the DACs output path instead of the
3869 * mono-mux path.
3871 if (wid_type == AC_WID_AUD_SEL &&
3872 !(wcaps & AC_WCAP_LR_SWAP))
3873 spec->mono_nid = conn_list[0];
3875 if (dir) {
3876 hda_nid_t nid = spec->autocfg.mono_out_pin;
3878 /* most mono outs have a least a mute/unmute switch */
3879 dir = (dir & AC_WCAP_OUT_AMP) ? HDA_OUTPUT : HDA_INPUT;
3880 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE,
3881 "Mono Playback Switch",
3882 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
3883 if (err < 0)
3884 return err;
3885 /* check for volume support for the amp */
3886 if ((caps & AC_AMPCAP_NUM_STEPS)
3887 >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3888 err = stac92xx_add_control(spec,
3889 STAC_CTL_WIDGET_VOL,
3890 "Mono Playback Volume",
3891 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
3892 if (err < 0)
3893 return err;
3897 stac92xx_auto_set_pinctl(codec, spec->autocfg.mono_out_pin,
3898 AC_PINCTL_OUT_EN);
3901 if (!spec->multiout.num_dacs) {
3902 err = stac92xx_auto_fill_dac_nids(codec);
3903 if (err < 0)
3904 return err;
3905 err = stac92xx_auto_create_multi_out_ctls(codec,
3906 &spec->autocfg);
3907 if (err < 0)
3908 return err;
3911 /* setup analog beep controls */
3912 if (spec->anabeep_nid > 0) {
3913 err = stac92xx_auto_create_beep_ctls(codec,
3914 spec->anabeep_nid);
3915 if (err < 0)
3916 return err;
3919 /* setup digital beep controls and input device */
3920 #ifdef CONFIG_SND_HDA_INPUT_BEEP
3921 if (spec->digbeep_nid > 0) {
3922 hda_nid_t nid = spec->digbeep_nid;
3923 unsigned int caps;
3925 err = stac92xx_auto_create_beep_ctls(codec, nid);
3926 if (err < 0)
3927 return err;
3928 err = snd_hda_attach_beep_device(codec, nid);
3929 if (err < 0)
3930 return err;
3931 /* IDT/STAC codecs have linear beep tone parameter */
3932 codec->beep->linear_tone = 1;
3933 /* if no beep switch is available, make its own one */
3934 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3935 if (codec->beep &&
3936 !((caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT)) {
3937 err = stac92xx_beep_switch_ctl(codec);
3938 if (err < 0)
3939 return err;
3942 #endif
3944 err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg);
3945 if (err < 0)
3946 return err;
3948 /* All output parsing done, now restore the swapped hp pins */
3949 if (hp_swap) {
3950 memcpy(spec->autocfg.hp_pins, spec->autocfg.line_out_pins,
3951 sizeof(spec->autocfg.hp_pins));
3952 spec->autocfg.hp_outs = spec->autocfg.line_outs;
3953 spec->autocfg.line_out_type = AUTO_PIN_HP_OUT;
3954 spec->autocfg.line_outs = 0;
3957 if (stac_check_auto_mic(codec)) {
3958 spec->auto_mic = 1;
3959 /* only one capture for auto-mic */
3960 spec->num_adcs = 1;
3961 spec->num_caps = 1;
3962 spec->num_muxes = 1;
3965 for (i = 0; i < spec->num_caps; i++) {
3966 err = stac92xx_add_capvol_ctls(codec, spec->capvols[i],
3967 spec->capsws[i], i);
3968 if (err < 0)
3969 return err;
3972 err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg);
3973 if (err < 0)
3974 return err;
3976 if (spec->mono_nid > 0) {
3977 err = stac92xx_auto_create_mono_output_ctls(codec);
3978 if (err < 0)
3979 return err;
3981 if (spec->num_amps > 0) {
3982 err = stac92xx_auto_create_amp_output_ctls(codec);
3983 if (err < 0)
3984 return err;
3986 if (spec->num_dmics > 0 && !spec->dinput_mux)
3987 if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
3988 &spec->autocfg)) < 0)
3989 return err;
3990 if (spec->num_muxes > 0) {
3991 err = stac92xx_auto_create_mux_input_ctls(codec);
3992 if (err < 0)
3993 return err;
3995 if (spec->num_smuxes > 0) {
3996 err = stac92xx_auto_create_spdif_mux_ctls(codec);
3997 if (err < 0)
3998 return err;
4001 err = stac92xx_add_input_source(spec);
4002 if (err < 0)
4003 return err;
4005 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4006 if (spec->multiout.max_channels > 2)
4007 spec->surr_switch = 1;
4009 if (spec->autocfg.dig_outs)
4010 spec->multiout.dig_out_nid = dig_out;
4011 if (dig_in && spec->autocfg.dig_in_pin)
4012 spec->dig_in_nid = dig_in;
4014 if (spec->kctls.list)
4015 spec->mixers[spec->num_mixers++] = spec->kctls.list;
4017 spec->input_mux = &spec->private_imux;
4018 if (!spec->dinput_mux)
4019 spec->dinput_mux = &spec->private_dimux;
4020 spec->sinput_mux = &spec->private_smux;
4021 spec->mono_mux = &spec->private_mono_mux;
4022 spec->amp_mux = &spec->private_amp_mux;
4023 return 1;
4026 /* add playback controls for HP output */
4027 static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
4028 struct auto_pin_cfg *cfg)
4030 struct sigmatel_spec *spec = codec->spec;
4031 hda_nid_t pin = cfg->hp_pins[0];
4032 unsigned int wid_caps;
4034 if (! pin)
4035 return 0;
4037 wid_caps = get_wcaps(codec, pin);
4038 if (wid_caps & AC_WCAP_UNSOL_CAP)
4039 spec->hp_detect = 1;
4041 return 0;
4044 /* add playback controls for LFE output */
4045 static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
4046 struct auto_pin_cfg *cfg)
4048 struct sigmatel_spec *spec = codec->spec;
4049 int err;
4050 hda_nid_t lfe_pin = 0x0;
4051 int i;
4054 * search speaker outs and line outs for a mono speaker pin
4055 * with an amp. If one is found, add LFE controls
4056 * for it.
4058 for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
4059 hda_nid_t pin = spec->autocfg.speaker_pins[i];
4060 unsigned int wcaps = get_wcaps(codec, pin);
4061 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
4062 if (wcaps == AC_WCAP_OUT_AMP)
4063 /* found a mono speaker with an amp, must be lfe */
4064 lfe_pin = pin;
4067 /* if speaker_outs is 0, then speakers may be in line_outs */
4068 if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
4069 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
4070 hda_nid_t pin = spec->autocfg.line_out_pins[i];
4071 unsigned int defcfg;
4072 defcfg = snd_hda_codec_get_pincfg(codec, pin);
4073 if (get_defcfg_device(defcfg) == AC_JACK_SPEAKER) {
4074 unsigned int wcaps = get_wcaps(codec, pin);
4075 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
4076 if (wcaps == AC_WCAP_OUT_AMP)
4077 /* found a mono speaker with an amp,
4078 must be lfe */
4079 lfe_pin = pin;
4084 if (lfe_pin) {
4085 err = create_controls(codec, "LFE", lfe_pin, 1);
4086 if (err < 0)
4087 return err;
4090 return 0;
4093 static int stac9200_parse_auto_config(struct hda_codec *codec)
4095 struct sigmatel_spec *spec = codec->spec;
4096 int err;
4098 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
4099 return err;
4101 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
4102 return err;
4104 if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
4105 return err;
4107 if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
4108 return err;
4110 if (spec->num_muxes > 0) {
4111 err = stac92xx_auto_create_mux_input_ctls(codec);
4112 if (err < 0)
4113 return err;
4116 err = stac92xx_add_input_source(spec);
4117 if (err < 0)
4118 return err;
4120 if (spec->autocfg.dig_outs)
4121 spec->multiout.dig_out_nid = 0x05;
4122 if (spec->autocfg.dig_in_pin)
4123 spec->dig_in_nid = 0x04;
4125 if (spec->kctls.list)
4126 spec->mixers[spec->num_mixers++] = spec->kctls.list;
4128 spec->input_mux = &spec->private_imux;
4129 spec->dinput_mux = &spec->private_dimux;
4131 return 1;
4135 * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
4136 * funky external mute control using GPIO pins.
4139 static void stac_gpio_set(struct hda_codec *codec, unsigned int mask,
4140 unsigned int dir_mask, unsigned int data)
4142 unsigned int gpiostate, gpiomask, gpiodir;
4144 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
4145 AC_VERB_GET_GPIO_DATA, 0);
4146 gpiostate = (gpiostate & ~dir_mask) | (data & dir_mask);
4148 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
4149 AC_VERB_GET_GPIO_MASK, 0);
4150 gpiomask |= mask;
4152 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
4153 AC_VERB_GET_GPIO_DIRECTION, 0);
4154 gpiodir |= dir_mask;
4156 /* Configure GPIOx as CMOS */
4157 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
4159 snd_hda_codec_write(codec, codec->afg, 0,
4160 AC_VERB_SET_GPIO_MASK, gpiomask);
4161 snd_hda_codec_read(codec, codec->afg, 0,
4162 AC_VERB_SET_GPIO_DIRECTION, gpiodir); /* sync */
4164 msleep(1);
4166 snd_hda_codec_read(codec, codec->afg, 0,
4167 AC_VERB_SET_GPIO_DATA, gpiostate); /* sync */
4170 #ifdef CONFIG_SND_HDA_INPUT_JACK
4171 static void stac92xx_free_jack_priv(struct snd_jack *jack)
4173 struct sigmatel_jack *jacks = jack->private_data;
4174 jacks->nid = 0;
4175 jacks->jack = NULL;
4177 #endif
4179 static int stac92xx_add_jack(struct hda_codec *codec,
4180 hda_nid_t nid, int type)
4182 #ifdef CONFIG_SND_HDA_INPUT_JACK
4183 struct sigmatel_spec *spec = codec->spec;
4184 struct sigmatel_jack *jack;
4185 int def_conf = snd_hda_codec_get_pincfg(codec, nid);
4186 int connectivity = get_defcfg_connect(def_conf);
4187 char name[32];
4188 int err;
4190 if (connectivity && connectivity != AC_JACK_PORT_FIXED)
4191 return 0;
4193 snd_array_init(&spec->jacks, sizeof(*jack), 32);
4194 jack = snd_array_new(&spec->jacks);
4195 if (!jack)
4196 return -ENOMEM;
4197 jack->nid = nid;
4198 jack->type = type;
4200 snprintf(name, sizeof(name), "%s at %s %s Jack",
4201 snd_hda_get_jack_type(def_conf),
4202 snd_hda_get_jack_connectivity(def_conf),
4203 snd_hda_get_jack_location(def_conf));
4205 err = snd_jack_new(codec->bus->card, name, type, &jack->jack);
4206 if (err < 0) {
4207 jack->nid = 0;
4208 return err;
4210 jack->jack->private_data = jack;
4211 jack->jack->private_free = stac92xx_free_jack_priv;
4212 #endif
4213 return 0;
4216 static int stac_add_event(struct sigmatel_spec *spec, hda_nid_t nid,
4217 unsigned char type, int data)
4219 struct sigmatel_event *event;
4221 snd_array_init(&spec->events, sizeof(*event), 32);
4222 event = snd_array_new(&spec->events);
4223 if (!event)
4224 return -ENOMEM;
4225 event->nid = nid;
4226 event->type = type;
4227 event->tag = spec->events.used;
4228 event->data = data;
4230 return event->tag;
4233 static struct sigmatel_event *stac_get_event(struct hda_codec *codec,
4234 hda_nid_t nid)
4236 struct sigmatel_spec *spec = codec->spec;
4237 struct sigmatel_event *event = spec->events.list;
4238 int i;
4240 for (i = 0; i < spec->events.used; i++, event++) {
4241 if (event->nid == nid)
4242 return event;
4244 return NULL;
4247 static struct sigmatel_event *stac_get_event_from_tag(struct hda_codec *codec,
4248 unsigned char tag)
4250 struct sigmatel_spec *spec = codec->spec;
4251 struct sigmatel_event *event = spec->events.list;
4252 int i;
4254 for (i = 0; i < spec->events.used; i++, event++) {
4255 if (event->tag == tag)
4256 return event;
4258 return NULL;
4261 /* check if given nid is a valid pin and no other events are assigned
4262 * to it. If OK, assign the event, set the unsol flag, and returns 1.
4263 * Otherwise, returns zero.
4265 static int enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
4266 unsigned int type)
4268 struct sigmatel_event *event;
4269 int tag;
4271 if (!(get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP))
4272 return 0;
4273 event = stac_get_event(codec, nid);
4274 if (event) {
4275 if (event->type != type)
4276 return 0;
4277 tag = event->tag;
4278 } else {
4279 tag = stac_add_event(codec->spec, nid, type, 0);
4280 if (tag < 0)
4281 return 0;
4283 snd_hda_codec_write_cache(codec, nid, 0,
4284 AC_VERB_SET_UNSOLICITED_ENABLE,
4285 AC_USRSP_EN | tag);
4286 return 1;
4289 static int is_nid_hp_pin(struct auto_pin_cfg *cfg, hda_nid_t nid)
4291 int i;
4292 for (i = 0; i < cfg->hp_outs; i++)
4293 if (cfg->hp_pins[i] == nid)
4294 return 1; /* nid is a HP-Out */
4296 return 0; /* nid is not a HP-Out */
4299 static void stac92xx_power_down(struct hda_codec *codec)
4301 struct sigmatel_spec *spec = codec->spec;
4303 /* power down inactive DACs */
4304 hda_nid_t *dac;
4305 for (dac = spec->dac_list; *dac; dac++)
4306 if (!check_all_dac_nids(spec, *dac))
4307 snd_hda_codec_write(codec, *dac, 0,
4308 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
4311 static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
4312 int enable);
4314 /* override some hints from the hwdep entry */
4315 static void stac_store_hints(struct hda_codec *codec)
4317 struct sigmatel_spec *spec = codec->spec;
4318 const char *p;
4319 int val;
4321 val = snd_hda_get_bool_hint(codec, "hp_detect");
4322 if (val >= 0)
4323 spec->hp_detect = val;
4324 p = snd_hda_get_hint(codec, "gpio_mask");
4325 if (p) {
4326 spec->gpio_mask = simple_strtoul(p, NULL, 0);
4327 spec->eapd_mask = spec->gpio_dir = spec->gpio_data =
4328 spec->gpio_mask;
4330 p = snd_hda_get_hint(codec, "gpio_dir");
4331 if (p)
4332 spec->gpio_dir = simple_strtoul(p, NULL, 0) & spec->gpio_mask;
4333 p = snd_hda_get_hint(codec, "gpio_data");
4334 if (p)
4335 spec->gpio_data = simple_strtoul(p, NULL, 0) & spec->gpio_mask;
4336 p = snd_hda_get_hint(codec, "eapd_mask");
4337 if (p)
4338 spec->eapd_mask = simple_strtoul(p, NULL, 0) & spec->gpio_mask;
4339 val = snd_hda_get_bool_hint(codec, "eapd_switch");
4340 if (val >= 0)
4341 spec->eapd_switch = val;
4344 static int stac92xx_init(struct hda_codec *codec)
4346 struct sigmatel_spec *spec = codec->spec;
4347 struct auto_pin_cfg *cfg = &spec->autocfg;
4348 unsigned int gpio;
4349 int i;
4351 snd_hda_sequence_write(codec, spec->init);
4353 /* power down adcs initially */
4354 if (spec->powerdown_adcs)
4355 for (i = 0; i < spec->num_adcs; i++)
4356 snd_hda_codec_write(codec,
4357 spec->adc_nids[i], 0,
4358 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
4360 /* override some hints */
4361 stac_store_hints(codec);
4363 /* set up GPIO */
4364 gpio = spec->gpio_data;
4365 /* turn on EAPD statically when spec->eapd_switch isn't set.
4366 * otherwise, unsol event will turn it on/off dynamically
4368 if (!spec->eapd_switch)
4369 gpio |= spec->eapd_mask;
4370 stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, gpio);
4372 /* set up pins */
4373 if (spec->hp_detect) {
4374 /* Enable unsolicited responses on the HP widget */
4375 for (i = 0; i < cfg->hp_outs; i++) {
4376 hda_nid_t nid = cfg->hp_pins[i];
4377 enable_pin_detect(codec, nid, STAC_HP_EVENT);
4379 /* force to enable the first line-out; the others are set up
4380 * in unsol_event
4382 stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
4383 AC_PINCTL_OUT_EN);
4384 /* fake event to set up pins */
4385 stac_issue_unsol_event(codec, spec->autocfg.hp_pins[0]);
4386 } else {
4387 stac92xx_auto_init_multi_out(codec);
4388 stac92xx_auto_init_hp_out(codec);
4389 for (i = 0; i < cfg->hp_outs; i++)
4390 stac_toggle_power_map(codec, cfg->hp_pins[i], 1);
4392 if (spec->auto_mic) {
4393 /* initialize connection to analog input */
4394 snd_hda_codec_write_cache(codec, spec->dmux_nids[0], 0,
4395 AC_VERB_SET_CONNECT_SEL, 0);
4396 if (enable_pin_detect(codec, spec->ext_mic.pin, STAC_MIC_EVENT))
4397 stac_issue_unsol_event(codec, spec->ext_mic.pin);
4399 for (i = 0; i < AUTO_PIN_LAST; i++) {
4400 hda_nid_t nid = cfg->input_pins[i];
4401 if (nid) {
4402 unsigned int pinctl, conf;
4403 if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC) {
4404 /* for mic pins, force to initialize */
4405 pinctl = stac92xx_get_default_vref(codec, nid);
4406 pinctl |= AC_PINCTL_IN_EN;
4407 stac92xx_auto_set_pinctl(codec, nid, pinctl);
4408 } else {
4409 pinctl = snd_hda_codec_read(codec, nid, 0,
4410 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4411 /* if PINCTL already set then skip */
4412 /* Also, if both INPUT and OUTPUT are set,
4413 * it must be a BIOS bug; need to override, too
4415 if (!(pinctl & AC_PINCTL_IN_EN) ||
4416 (pinctl & AC_PINCTL_OUT_EN)) {
4417 pinctl &= ~AC_PINCTL_OUT_EN;
4418 pinctl |= AC_PINCTL_IN_EN;
4419 stac92xx_auto_set_pinctl(codec, nid,
4420 pinctl);
4423 conf = snd_hda_codec_get_pincfg(codec, nid);
4424 if (get_defcfg_connect(conf) != AC_JACK_PORT_FIXED) {
4425 if (enable_pin_detect(codec, nid,
4426 STAC_INSERT_EVENT))
4427 stac_issue_unsol_event(codec, nid);
4431 for (i = 0; i < spec->num_dmics; i++)
4432 stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
4433 AC_PINCTL_IN_EN);
4434 if (cfg->dig_out_pins[0])
4435 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pins[0],
4436 AC_PINCTL_OUT_EN);
4437 if (cfg->dig_in_pin)
4438 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
4439 AC_PINCTL_IN_EN);
4440 for (i = 0; i < spec->num_pwrs; i++) {
4441 hda_nid_t nid = spec->pwr_nids[i];
4442 int pinctl, def_conf;
4444 /* power on when no jack detection is available */
4445 if (!spec->hp_detect) {
4446 stac_toggle_power_map(codec, nid, 1);
4447 continue;
4450 if (is_nid_hp_pin(cfg, nid))
4451 continue; /* already has an unsol event */
4453 pinctl = snd_hda_codec_read(codec, nid, 0,
4454 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4455 /* outputs are only ports capable of power management
4456 * any attempts on powering down a input port cause the
4457 * referenced VREF to act quirky.
4459 if (pinctl & AC_PINCTL_IN_EN) {
4460 stac_toggle_power_map(codec, nid, 1);
4461 continue;
4463 def_conf = snd_hda_codec_get_pincfg(codec, nid);
4464 def_conf = get_defcfg_connect(def_conf);
4465 /* skip any ports that don't have jacks since presence
4466 * detection is useless */
4467 if (def_conf != AC_JACK_PORT_COMPLEX) {
4468 if (def_conf != AC_JACK_PORT_NONE)
4469 stac_toggle_power_map(codec, nid, 1);
4470 continue;
4472 if (enable_pin_detect(codec, nid, STAC_PWR_EVENT))
4473 stac_issue_unsol_event(codec, nid);
4475 if (spec->dac_list)
4476 stac92xx_power_down(codec);
4477 return 0;
4480 static void stac92xx_free_jacks(struct hda_codec *codec)
4482 #ifdef CONFIG_SND_HDA_INPUT_JACK
4483 /* free jack instances manually when clearing/reconfiguring */
4484 struct sigmatel_spec *spec = codec->spec;
4485 if (!codec->bus->shutdown && spec->jacks.list) {
4486 struct sigmatel_jack *jacks = spec->jacks.list;
4487 int i;
4488 for (i = 0; i < spec->jacks.used; i++, jacks++) {
4489 if (jacks->jack)
4490 snd_device_free(codec->bus->card, jacks->jack);
4493 snd_array_free(&spec->jacks);
4494 #endif
4497 static void stac92xx_free_kctls(struct hda_codec *codec)
4499 struct sigmatel_spec *spec = codec->spec;
4501 if (spec->kctls.list) {
4502 struct snd_kcontrol_new *kctl = spec->kctls.list;
4503 int i;
4504 for (i = 0; i < spec->kctls.used; i++)
4505 kfree(kctl[i].name);
4507 snd_array_free(&spec->kctls);
4510 static void stac92xx_free(struct hda_codec *codec)
4512 struct sigmatel_spec *spec = codec->spec;
4514 if (! spec)
4515 return;
4517 stac92xx_free_jacks(codec);
4518 snd_array_free(&spec->events);
4520 kfree(spec);
4521 snd_hda_detach_beep_device(codec);
4524 static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
4525 unsigned int flag)
4527 unsigned int old_ctl, pin_ctl;
4529 pin_ctl = snd_hda_codec_read(codec, nid,
4530 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
4532 if (pin_ctl & AC_PINCTL_IN_EN) {
4534 * we need to check the current set-up direction of
4535 * shared input pins since they can be switched via
4536 * "xxx as Output" mixer switch
4538 struct sigmatel_spec *spec = codec->spec;
4539 if (nid == spec->line_switch || nid == spec->mic_switch)
4540 return;
4543 old_ctl = pin_ctl;
4544 /* if setting pin direction bits, clear the current
4545 direction bits first */
4546 if (flag & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))
4547 pin_ctl &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
4549 pin_ctl |= flag;
4550 if (old_ctl != pin_ctl)
4551 snd_hda_codec_write_cache(codec, nid, 0,
4552 AC_VERB_SET_PIN_WIDGET_CONTROL,
4553 pin_ctl);
4556 static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
4557 unsigned int flag)
4559 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
4560 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
4561 if (pin_ctl & flag)
4562 snd_hda_codec_write_cache(codec, nid, 0,
4563 AC_VERB_SET_PIN_WIDGET_CONTROL,
4564 pin_ctl & ~flag);
4567 static int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
4569 if (!nid)
4570 return 0;
4571 if (snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PIN_SENSE, 0x00)
4572 & (1 << 31))
4573 return 1;
4574 return 0;
4577 /* return non-zero if the hp-pin of the given array index isn't
4578 * a jack-detection target
4580 static int no_hp_sensing(struct sigmatel_spec *spec, int i)
4582 struct auto_pin_cfg *cfg = &spec->autocfg;
4584 /* ignore sensing of shared line and mic jacks */
4585 if (cfg->hp_pins[i] == spec->line_switch)
4586 return 1;
4587 if (cfg->hp_pins[i] == spec->mic_switch)
4588 return 1;
4589 /* ignore if the pin is set as line-out */
4590 if (cfg->hp_pins[i] == spec->hp_switch)
4591 return 1;
4592 return 0;
4595 static void stac92xx_hp_detect(struct hda_codec *codec)
4597 struct sigmatel_spec *spec = codec->spec;
4598 struct auto_pin_cfg *cfg = &spec->autocfg;
4599 int i, presence;
4601 presence = 0;
4602 if (spec->gpio_mute)
4603 presence = !(snd_hda_codec_read(codec, codec->afg, 0,
4604 AC_VERB_GET_GPIO_DATA, 0) & spec->gpio_mute);
4606 for (i = 0; i < cfg->hp_outs; i++) {
4607 if (presence)
4608 break;
4609 if (no_hp_sensing(spec, i))
4610 continue;
4611 presence = get_pin_presence(codec, cfg->hp_pins[i]);
4612 if (presence) {
4613 unsigned int pinctl;
4614 pinctl = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
4615 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4616 if (pinctl & AC_PINCTL_IN_EN)
4617 presence = 0; /* mic- or line-input */
4621 if (presence) {
4622 /* disable lineouts */
4623 if (spec->hp_switch)
4624 stac92xx_reset_pinctl(codec, spec->hp_switch,
4625 AC_PINCTL_OUT_EN);
4626 for (i = 0; i < cfg->line_outs; i++)
4627 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
4628 AC_PINCTL_OUT_EN);
4629 for (i = 0; i < cfg->speaker_outs; i++)
4630 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
4631 AC_PINCTL_OUT_EN);
4632 if (spec->eapd_mask && spec->eapd_switch)
4633 stac_gpio_set(codec, spec->gpio_mask,
4634 spec->gpio_dir, spec->gpio_data &
4635 ~spec->eapd_mask);
4636 } else {
4637 /* enable lineouts */
4638 if (spec->hp_switch)
4639 stac92xx_set_pinctl(codec, spec->hp_switch,
4640 AC_PINCTL_OUT_EN);
4641 for (i = 0; i < cfg->line_outs; i++)
4642 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
4643 AC_PINCTL_OUT_EN);
4644 for (i = 0; i < cfg->speaker_outs; i++)
4645 stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
4646 AC_PINCTL_OUT_EN);
4647 if (spec->eapd_mask && spec->eapd_switch)
4648 stac_gpio_set(codec, spec->gpio_mask,
4649 spec->gpio_dir, spec->gpio_data |
4650 spec->eapd_mask);
4652 /* toggle hp outs */
4653 for (i = 0; i < cfg->hp_outs; i++) {
4654 unsigned int val = AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN;
4655 if (no_hp_sensing(spec, i))
4656 continue;
4657 if (presence)
4658 stac92xx_set_pinctl(codec, cfg->hp_pins[i], val);
4659 #if 0 /* FIXME */
4660 /* Resetting the pinctl like below may lead to (a sort of) regressions
4661 * on some devices since they use the HP pin actually for line/speaker
4662 * outs although the default pin config shows a different pin (that is
4663 * wrong and useless).
4665 * So, it's basically a problem of default pin configs, likely a BIOS issue.
4666 * But, disabling the code below just works around it, and I'm too tired of
4667 * bug reports with such devices...
4669 else
4670 stac92xx_reset_pinctl(codec, cfg->hp_pins[i], val);
4671 #endif /* FIXME */
4675 static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
4676 int enable)
4678 struct sigmatel_spec *spec = codec->spec;
4679 unsigned int idx, val;
4681 for (idx = 0; idx < spec->num_pwrs; idx++) {
4682 if (spec->pwr_nids[idx] == nid)
4683 break;
4685 if (idx >= spec->num_pwrs)
4686 return;
4688 /* several codecs have two power down bits */
4689 if (spec->pwr_mapping)
4690 idx = spec->pwr_mapping[idx];
4691 else
4692 idx = 1 << idx;
4694 val = snd_hda_codec_read(codec, codec->afg, 0, 0x0fec, 0x0) & 0xff;
4695 if (enable)
4696 val &= ~idx;
4697 else
4698 val |= idx;
4700 /* power down unused output ports */
4701 snd_hda_codec_write(codec, codec->afg, 0, 0x7ec, val);
4704 static void stac92xx_pin_sense(struct hda_codec *codec, hda_nid_t nid)
4706 stac_toggle_power_map(codec, nid, get_pin_presence(codec, nid));
4709 static void stac92xx_report_jack(struct hda_codec *codec, hda_nid_t nid)
4711 struct sigmatel_spec *spec = codec->spec;
4712 struct sigmatel_jack *jacks = spec->jacks.list;
4714 if (jacks) {
4715 int i;
4716 for (i = 0; i < spec->jacks.used; i++) {
4717 if (jacks->nid == nid) {
4718 unsigned int pin_ctl =
4719 snd_hda_codec_read(codec, nid,
4720 0, AC_VERB_GET_PIN_WIDGET_CONTROL,
4721 0x00);
4722 int type = jacks->type;
4723 if (type == (SND_JACK_LINEOUT
4724 | SND_JACK_HEADPHONE))
4725 type = (pin_ctl & AC_PINCTL_HP_EN)
4726 ? SND_JACK_HEADPHONE : SND_JACK_LINEOUT;
4727 snd_jack_report(jacks->jack,
4728 get_pin_presence(codec, nid)
4729 ? type : 0);
4731 jacks++;
4736 static void stac92xx_mic_detect(struct hda_codec *codec)
4738 struct sigmatel_spec *spec = codec->spec;
4739 struct sigmatel_mic_route *mic;
4741 if (get_pin_presence(codec, spec->ext_mic.pin))
4742 mic = &spec->ext_mic;
4743 else
4744 mic = &spec->int_mic;
4745 if (mic->dmux_idx)
4746 snd_hda_codec_write_cache(codec, spec->dmux_nids[0], 0,
4747 AC_VERB_SET_CONNECT_SEL,
4748 mic->dmux_idx);
4749 else
4750 snd_hda_codec_write_cache(codec, spec->mux_nids[0], 0,
4751 AC_VERB_SET_CONNECT_SEL,
4752 mic->mux_idx);
4755 static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid)
4757 struct sigmatel_event *event = stac_get_event(codec, nid);
4758 if (!event)
4759 return;
4760 codec->patch_ops.unsol_event(codec, (unsigned)event->tag << 26);
4763 static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
4765 struct sigmatel_spec *spec = codec->spec;
4766 struct sigmatel_event *event;
4767 int tag, data;
4769 tag = (res >> 26) & 0x7f;
4770 event = stac_get_event_from_tag(codec, tag);
4771 if (!event)
4772 return;
4774 switch (event->type) {
4775 case STAC_HP_EVENT:
4776 stac92xx_hp_detect(codec);
4777 break;
4778 case STAC_MIC_EVENT:
4779 stac92xx_mic_detect(codec);
4780 break;
4783 switch (event->type) {
4784 case STAC_HP_EVENT:
4785 case STAC_MIC_EVENT:
4786 case STAC_INSERT_EVENT:
4787 case STAC_PWR_EVENT:
4788 if (spec->num_pwrs > 0)
4789 stac92xx_pin_sense(codec, event->nid);
4790 stac92xx_report_jack(codec, event->nid);
4792 switch (codec->subsystem_id) {
4793 case 0x103c308f:
4794 if (event->nid == 0xb) {
4795 int pin = AC_PINCTL_IN_EN;
4797 if (get_pin_presence(codec, 0xa)
4798 && get_pin_presence(codec, 0xb))
4799 pin |= AC_PINCTL_VREF_80;
4800 if (!get_pin_presence(codec, 0xb))
4801 pin |= AC_PINCTL_VREF_80;
4803 /* toggle VREF state based on mic + hp pin
4804 * status
4806 stac92xx_auto_set_pinctl(codec, 0x0a, pin);
4809 break;
4810 case STAC_VREF_EVENT:
4811 data = snd_hda_codec_read(codec, codec->afg, 0,
4812 AC_VERB_GET_GPIO_DATA, 0);
4813 /* toggle VREF state based on GPIOx status */
4814 snd_hda_codec_write(codec, codec->afg, 0, 0x7e0,
4815 !!(data & (1 << event->data)));
4816 break;
4820 #ifdef CONFIG_PROC_FS
4821 static void stac92hd_proc_hook(struct snd_info_buffer *buffer,
4822 struct hda_codec *codec, hda_nid_t nid)
4824 if (nid == codec->afg)
4825 snd_iprintf(buffer, "Power-Map: 0x%02x\n",
4826 snd_hda_codec_read(codec, nid, 0, 0x0fec, 0x0));
4829 static void analog_loop_proc_hook(struct snd_info_buffer *buffer,
4830 struct hda_codec *codec,
4831 unsigned int verb)
4833 snd_iprintf(buffer, "Analog Loopback: 0x%02x\n",
4834 snd_hda_codec_read(codec, codec->afg, 0, verb, 0));
4837 /* stac92hd71bxx, stac92hd73xx */
4838 static void stac92hd7x_proc_hook(struct snd_info_buffer *buffer,
4839 struct hda_codec *codec, hda_nid_t nid)
4841 stac92hd_proc_hook(buffer, codec, nid);
4842 if (nid == codec->afg)
4843 analog_loop_proc_hook(buffer, codec, 0xfa0);
4846 static void stac9205_proc_hook(struct snd_info_buffer *buffer,
4847 struct hda_codec *codec, hda_nid_t nid)
4849 if (nid == codec->afg)
4850 analog_loop_proc_hook(buffer, codec, 0xfe0);
4853 static void stac927x_proc_hook(struct snd_info_buffer *buffer,
4854 struct hda_codec *codec, hda_nid_t nid)
4856 if (nid == codec->afg)
4857 analog_loop_proc_hook(buffer, codec, 0xfeb);
4859 #else
4860 #define stac92hd_proc_hook NULL
4861 #define stac92hd7x_proc_hook NULL
4862 #define stac9205_proc_hook NULL
4863 #define stac927x_proc_hook NULL
4864 #endif
4866 #ifdef SND_HDA_NEEDS_RESUME
4867 static int stac92xx_resume(struct hda_codec *codec)
4869 struct sigmatel_spec *spec = codec->spec;
4871 stac92xx_init(codec);
4872 snd_hda_codec_resume_amp(codec);
4873 snd_hda_codec_resume_cache(codec);
4874 /* fake event to set up pins again to override cached values */
4875 if (spec->hp_detect)
4876 stac_issue_unsol_event(codec, spec->autocfg.hp_pins[0]);
4877 return 0;
4881 * using power check for controlling mute led of HP notebooks
4882 * check for mute state only on Speakers (nid = 0x10)
4884 * For this feature CONFIG_SND_HDA_POWER_SAVE is needed, otherwise
4885 * the LED is NOT working properly !
4887 * Changed name to reflect that it now works for any designated
4888 * model, not just HP HDX.
4891 #ifdef CONFIG_SND_HDA_POWER_SAVE
4892 static int stac92xx_hp_check_power_status(struct hda_codec *codec,
4893 hda_nid_t nid)
4895 struct sigmatel_spec *spec = codec->spec;
4897 if (nid == 0x10) {
4898 if (snd_hda_codec_amp_read(codec, nid, 0, HDA_OUTPUT, 0) &
4899 HDA_AMP_MUTE)
4900 spec->gpio_data &= ~spec->gpio_led; /* orange */
4901 else
4902 spec->gpio_data |= spec->gpio_led; /* white */
4904 stac_gpio_set(codec, spec->gpio_mask,
4905 spec->gpio_dir,
4906 spec->gpio_data);
4909 return 0;
4911 #endif
4913 static int stac92xx_suspend(struct hda_codec *codec, pm_message_t state)
4915 struct sigmatel_spec *spec = codec->spec;
4916 int i;
4917 hda_nid_t nid;
4919 /* reset each pin before powering down DAC/ADC to avoid click noise */
4920 nid = codec->start_nid;
4921 for (i = 0; i < codec->num_nodes; i++, nid++) {
4922 unsigned int wcaps = get_wcaps(codec, nid);
4923 unsigned int wid_type = get_wcaps_type(wcaps);
4924 if (wid_type == AC_WID_PIN)
4925 snd_hda_codec_read(codec, nid, 0,
4926 AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
4929 if (spec->eapd_mask)
4930 stac_gpio_set(codec, spec->gpio_mask,
4931 spec->gpio_dir, spec->gpio_data &
4932 ~spec->eapd_mask);
4933 return 0;
4935 #endif
4937 static struct hda_codec_ops stac92xx_patch_ops = {
4938 .build_controls = stac92xx_build_controls,
4939 .build_pcms = stac92xx_build_pcms,
4940 .init = stac92xx_init,
4941 .free = stac92xx_free,
4942 .unsol_event = stac92xx_unsol_event,
4943 #ifdef SND_HDA_NEEDS_RESUME
4944 .suspend = stac92xx_suspend,
4945 .resume = stac92xx_resume,
4946 #endif
4949 static int patch_stac9200(struct hda_codec *codec)
4951 struct sigmatel_spec *spec;
4952 int err;
4954 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4955 if (spec == NULL)
4956 return -ENOMEM;
4958 codec->spec = spec;
4959 spec->num_pins = ARRAY_SIZE(stac9200_pin_nids);
4960 spec->pin_nids = stac9200_pin_nids;
4961 spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS,
4962 stac9200_models,
4963 stac9200_cfg_tbl);
4964 if (spec->board_config < 0)
4965 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4966 codec->chip_name);
4967 else
4968 stac92xx_set_config_regs(codec,
4969 stac9200_brd_tbl[spec->board_config]);
4971 spec->multiout.max_channels = 2;
4972 spec->multiout.num_dacs = 1;
4973 spec->multiout.dac_nids = stac9200_dac_nids;
4974 spec->adc_nids = stac9200_adc_nids;
4975 spec->mux_nids = stac9200_mux_nids;
4976 spec->num_muxes = 1;
4977 spec->num_dmics = 0;
4978 spec->num_adcs = 1;
4979 spec->num_pwrs = 0;
4981 if (spec->board_config == STAC_9200_M4 ||
4982 spec->board_config == STAC_9200_M4_2 ||
4983 spec->board_config == STAC_9200_OQO)
4984 spec->init = stac9200_eapd_init;
4985 else
4986 spec->init = stac9200_core_init;
4987 spec->mixer = stac9200_mixer;
4989 if (spec->board_config == STAC_9200_PANASONIC) {
4990 spec->gpio_mask = spec->gpio_dir = 0x09;
4991 spec->gpio_data = 0x00;
4994 err = stac9200_parse_auto_config(codec);
4995 if (err < 0) {
4996 stac92xx_free(codec);
4997 return err;
5000 /* CF-74 has no headphone detection, and the driver should *NOT*
5001 * do detection and HP/speaker toggle because the hardware does it.
5003 if (spec->board_config == STAC_9200_PANASONIC)
5004 spec->hp_detect = 0;
5006 codec->patch_ops = stac92xx_patch_ops;
5008 return 0;
5011 static int patch_stac925x(struct hda_codec *codec)
5013 struct sigmatel_spec *spec;
5014 int err;
5016 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5017 if (spec == NULL)
5018 return -ENOMEM;
5020 codec->spec = spec;
5021 spec->num_pins = ARRAY_SIZE(stac925x_pin_nids);
5022 spec->pin_nids = stac925x_pin_nids;
5024 /* Check first for codec ID */
5025 spec->board_config = snd_hda_check_board_codec_sid_config(codec,
5026 STAC_925x_MODELS,
5027 stac925x_models,
5028 stac925x_codec_id_cfg_tbl);
5030 /* Now checks for PCI ID, if codec ID is not found */
5031 if (spec->board_config < 0)
5032 spec->board_config = snd_hda_check_board_config(codec,
5033 STAC_925x_MODELS,
5034 stac925x_models,
5035 stac925x_cfg_tbl);
5036 again:
5037 if (spec->board_config < 0)
5038 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5039 codec->chip_name);
5040 else
5041 stac92xx_set_config_regs(codec,
5042 stac925x_brd_tbl[spec->board_config]);
5044 spec->multiout.max_channels = 2;
5045 spec->multiout.num_dacs = 1;
5046 spec->multiout.dac_nids = stac925x_dac_nids;
5047 spec->adc_nids = stac925x_adc_nids;
5048 spec->mux_nids = stac925x_mux_nids;
5049 spec->num_muxes = 1;
5050 spec->num_adcs = 1;
5051 spec->num_pwrs = 0;
5052 switch (codec->vendor_id) {
5053 case 0x83847632: /* STAC9202 */
5054 case 0x83847633: /* STAC9202D */
5055 case 0x83847636: /* STAC9251 */
5056 case 0x83847637: /* STAC9251D */
5057 spec->num_dmics = STAC925X_NUM_DMICS;
5058 spec->dmic_nids = stac925x_dmic_nids;
5059 spec->num_dmuxes = ARRAY_SIZE(stac925x_dmux_nids);
5060 spec->dmux_nids = stac925x_dmux_nids;
5061 break;
5062 default:
5063 spec->num_dmics = 0;
5064 break;
5067 spec->init = stac925x_core_init;
5068 spec->mixer = stac925x_mixer;
5069 spec->num_caps = 1;
5070 spec->capvols = stac925x_capvols;
5071 spec->capsws = stac925x_capsws;
5073 err = stac92xx_parse_auto_config(codec, 0x8, 0x7);
5074 if (!err) {
5075 if (spec->board_config < 0) {
5076 printk(KERN_WARNING "hda_codec: No auto-config is "
5077 "available, default to model=ref\n");
5078 spec->board_config = STAC_925x_REF;
5079 goto again;
5081 err = -EINVAL;
5083 if (err < 0) {
5084 stac92xx_free(codec);
5085 return err;
5088 codec->patch_ops = stac92xx_patch_ops;
5090 return 0;
5093 static int patch_stac92hd73xx(struct hda_codec *codec)
5095 struct sigmatel_spec *spec;
5096 hda_nid_t conn[STAC92HD73_DAC_COUNT + 2];
5097 int err = 0;
5098 int num_dacs;
5100 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5101 if (spec == NULL)
5102 return -ENOMEM;
5104 codec->spec = spec;
5105 codec->slave_dig_outs = stac92hd73xx_slave_dig_outs;
5106 spec->num_pins = ARRAY_SIZE(stac92hd73xx_pin_nids);
5107 spec->pin_nids = stac92hd73xx_pin_nids;
5108 spec->board_config = snd_hda_check_board_config(codec,
5109 STAC_92HD73XX_MODELS,
5110 stac92hd73xx_models,
5111 stac92hd73xx_cfg_tbl);
5112 again:
5113 if (spec->board_config < 0)
5114 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5115 codec->chip_name);
5116 else
5117 stac92xx_set_config_regs(codec,
5118 stac92hd73xx_brd_tbl[spec->board_config]);
5120 num_dacs = snd_hda_get_connections(codec, 0x0a,
5121 conn, STAC92HD73_DAC_COUNT + 2) - 1;
5123 if (num_dacs < 3 || num_dacs > 5) {
5124 printk(KERN_WARNING "hda_codec: Could not determine "
5125 "number of channels defaulting to DAC count\n");
5126 num_dacs = STAC92HD73_DAC_COUNT;
5128 switch (num_dacs) {
5129 case 0x3: /* 6 Channel */
5130 spec->mixer = stac92hd73xx_6ch_mixer;
5131 spec->init = stac92hd73xx_6ch_core_init;
5132 spec->aloopback_ctl = stac92hd73xx_6ch_loopback;
5133 break;
5134 case 0x4: /* 8 Channel */
5135 spec->mixer = stac92hd73xx_8ch_mixer;
5136 spec->init = stac92hd73xx_8ch_core_init;
5137 spec->aloopback_ctl = stac92hd73xx_8ch_loopback;
5138 break;
5139 case 0x5: /* 10 Channel */
5140 spec->mixer = stac92hd73xx_10ch_mixer;
5141 spec->init = stac92hd73xx_10ch_core_init;
5142 spec->aloopback_ctl = stac92hd73xx_10ch_loopback;
5143 break;
5145 spec->multiout.dac_nids = spec->dac_nids;
5147 spec->aloopback_mask = 0x01;
5148 spec->aloopback_shift = 8;
5150 spec->digbeep_nid = 0x1c;
5151 spec->mux_nids = stac92hd73xx_mux_nids;
5152 spec->adc_nids = stac92hd73xx_adc_nids;
5153 spec->dmic_nids = stac92hd73xx_dmic_nids;
5154 spec->dmux_nids = stac92hd73xx_dmux_nids;
5155 spec->smux_nids = stac92hd73xx_smux_nids;
5156 spec->amp_nids = stac92hd73xx_amp_nids;
5157 spec->num_amps = ARRAY_SIZE(stac92hd73xx_amp_nids);
5159 spec->num_muxes = ARRAY_SIZE(stac92hd73xx_mux_nids);
5160 spec->num_adcs = ARRAY_SIZE(stac92hd73xx_adc_nids);
5161 spec->num_dmuxes = ARRAY_SIZE(stac92hd73xx_dmux_nids);
5163 spec->num_caps = STAC92HD73XX_NUM_CAPS;
5164 spec->capvols = stac92hd73xx_capvols;
5165 spec->capsws = stac92hd73xx_capsws;
5167 switch (spec->board_config) {
5168 case STAC_DELL_EQ:
5169 spec->init = dell_eq_core_init;
5170 /* fallthru */
5171 case STAC_DELL_M6_AMIC:
5172 case STAC_DELL_M6_DMIC:
5173 case STAC_DELL_M6_BOTH:
5174 spec->num_smuxes = 0;
5175 spec->mixer = &stac92hd73xx_6ch_mixer[DELL_M6_MIXER];
5176 spec->amp_nids = &stac92hd73xx_amp_nids[DELL_M6_AMP];
5177 spec->eapd_switch = 0;
5178 spec->num_amps = 1;
5180 if (spec->board_config != STAC_DELL_EQ)
5181 spec->init = dell_m6_core_init;
5182 switch (spec->board_config) {
5183 case STAC_DELL_M6_AMIC: /* Analog Mics */
5184 snd_hda_codec_set_pincfg(codec, 0x0b, 0x90A70170);
5185 spec->num_dmics = 0;
5186 break;
5187 case STAC_DELL_M6_DMIC: /* Digital Mics */
5188 snd_hda_codec_set_pincfg(codec, 0x13, 0x90A60160);
5189 spec->num_dmics = 1;
5190 break;
5191 case STAC_DELL_M6_BOTH: /* Both */
5192 snd_hda_codec_set_pincfg(codec, 0x0b, 0x90A70170);
5193 snd_hda_codec_set_pincfg(codec, 0x13, 0x90A60160);
5194 spec->num_dmics = 1;
5195 break;
5197 break;
5198 default:
5199 spec->num_dmics = STAC92HD73XX_NUM_DMICS;
5200 spec->num_smuxes = ARRAY_SIZE(stac92hd73xx_smux_nids);
5201 spec->eapd_switch = 1;
5202 break;
5204 if (spec->board_config > STAC_92HD73XX_REF) {
5205 /* GPIO0 High = Enable EAPD */
5206 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
5207 spec->gpio_data = 0x01;
5210 spec->num_pwrs = ARRAY_SIZE(stac92hd73xx_pwr_nids);
5211 spec->pwr_nids = stac92hd73xx_pwr_nids;
5213 err = stac92xx_parse_auto_config(codec, 0x25, 0x27);
5215 if (!err) {
5216 if (spec->board_config < 0) {
5217 printk(KERN_WARNING "hda_codec: No auto-config is "
5218 "available, default to model=ref\n");
5219 spec->board_config = STAC_92HD73XX_REF;
5220 goto again;
5222 err = -EINVAL;
5225 if (err < 0) {
5226 stac92xx_free(codec);
5227 return err;
5230 if (spec->board_config == STAC_92HD73XX_NO_JD)
5231 spec->hp_detect = 0;
5233 codec->patch_ops = stac92xx_patch_ops;
5235 codec->proc_widget_hook = stac92hd7x_proc_hook;
5237 return 0;
5240 static int patch_stac92hd83xxx(struct hda_codec *codec)
5242 struct sigmatel_spec *spec;
5243 hda_nid_t conn[STAC92HD83_DAC_COUNT + 1];
5244 int err;
5245 int num_dacs;
5246 hda_nid_t nid;
5248 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5249 if (spec == NULL)
5250 return -ENOMEM;
5252 codec->spec = spec;
5253 codec->slave_dig_outs = stac92hd83xxx_slave_dig_outs;
5254 spec->mono_nid = 0x19;
5255 spec->digbeep_nid = 0x21;
5256 spec->dmic_nids = stac92hd83xxx_dmic_nids;
5257 spec->dmux_nids = stac92hd83xxx_dmux_nids;
5258 spec->adc_nids = stac92hd83xxx_adc_nids;
5259 spec->pwr_nids = stac92hd83xxx_pwr_nids;
5260 spec->amp_nids = stac92hd83xxx_amp_nids;
5261 spec->pwr_mapping = stac92hd83xxx_pwr_mapping;
5262 spec->num_pwrs = ARRAY_SIZE(stac92hd83xxx_pwr_nids);
5263 spec->multiout.dac_nids = spec->dac_nids;
5265 spec->init = stac92hd83xxx_core_init;
5266 spec->mixer = stac92hd83xxx_mixer;
5267 spec->num_pins = ARRAY_SIZE(stac92hd83xxx_pin_nids);
5268 spec->num_dmuxes = ARRAY_SIZE(stac92hd83xxx_dmux_nids);
5269 spec->num_adcs = ARRAY_SIZE(stac92hd83xxx_adc_nids);
5270 spec->num_amps = ARRAY_SIZE(stac92hd83xxx_amp_nids);
5271 spec->num_dmics = STAC92HD83XXX_NUM_DMICS;
5272 spec->pin_nids = stac92hd83xxx_pin_nids;
5273 spec->num_caps = STAC92HD83XXX_NUM_CAPS;
5274 spec->capvols = stac92hd83xxx_capvols;
5275 spec->capsws = stac92hd83xxx_capsws;
5277 spec->board_config = snd_hda_check_board_config(codec,
5278 STAC_92HD83XXX_MODELS,
5279 stac92hd83xxx_models,
5280 stac92hd83xxx_cfg_tbl);
5281 again:
5282 if (spec->board_config < 0)
5283 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5284 codec->chip_name);
5285 else
5286 stac92xx_set_config_regs(codec,
5287 stac92hd83xxx_brd_tbl[spec->board_config]);
5289 switch (codec->vendor_id) {
5290 case 0x111d7604:
5291 case 0x111d7605:
5292 case 0x111d76d5:
5293 if (spec->board_config == STAC_92HD83XXX_PWR_REF)
5294 break;
5295 spec->num_pwrs = 0;
5296 break;
5299 err = stac92xx_parse_auto_config(codec, 0x1d, 0);
5300 if (!err) {
5301 if (spec->board_config < 0) {
5302 printk(KERN_WARNING "hda_codec: No auto-config is "
5303 "available, default to model=ref\n");
5304 spec->board_config = STAC_92HD83XXX_REF;
5305 goto again;
5307 err = -EINVAL;
5310 if (err < 0) {
5311 stac92xx_free(codec);
5312 return err;
5315 switch (spec->board_config) {
5316 case STAC_DELL_S14:
5317 nid = 0xf;
5318 break;
5319 default:
5320 nid = 0xe;
5321 break;
5324 num_dacs = snd_hda_get_connections(codec, nid,
5325 conn, STAC92HD83_DAC_COUNT + 1) - 1;
5326 if (num_dacs < 0)
5327 num_dacs = STAC92HD83_DAC_COUNT;
5329 /* set port X to select the last DAC
5331 snd_hda_codec_write_cache(codec, nid, 0,
5332 AC_VERB_SET_CONNECT_SEL, num_dacs);
5334 codec->patch_ops = stac92xx_patch_ops;
5336 codec->proc_widget_hook = stac92hd_proc_hook;
5338 return 0;
5341 /* get the pin connection (fixed, none, etc) */
5342 static unsigned int stac_get_defcfg_connect(struct hda_codec *codec, int idx)
5344 struct sigmatel_spec *spec = codec->spec;
5345 unsigned int cfg;
5347 cfg = snd_hda_codec_get_pincfg(codec, spec->pin_nids[idx]);
5348 return get_defcfg_connect(cfg);
5351 static int stac92hd71bxx_connected_ports(struct hda_codec *codec,
5352 hda_nid_t *nids, int num_nids)
5354 struct sigmatel_spec *spec = codec->spec;
5355 int idx, num;
5356 unsigned int def_conf;
5358 for (num = 0; num < num_nids; num++) {
5359 for (idx = 0; idx < spec->num_pins; idx++)
5360 if (spec->pin_nids[idx] == nids[num])
5361 break;
5362 if (idx >= spec->num_pins)
5363 break;
5364 def_conf = stac_get_defcfg_connect(codec, idx);
5365 if (def_conf == AC_JACK_PORT_NONE)
5366 break;
5368 return num;
5371 static int stac92hd71bxx_connected_smuxes(struct hda_codec *codec,
5372 hda_nid_t dig0pin)
5374 struct sigmatel_spec *spec = codec->spec;
5375 int idx;
5377 for (idx = 0; idx < spec->num_pins; idx++)
5378 if (spec->pin_nids[idx] == dig0pin)
5379 break;
5380 if ((idx + 2) >= spec->num_pins)
5381 return 0;
5383 /* dig1pin case */
5384 if (stac_get_defcfg_connect(codec, idx + 1) != AC_JACK_PORT_NONE)
5385 return 2;
5387 /* dig0pin + dig2pin case */
5388 if (stac_get_defcfg_connect(codec, idx + 2) != AC_JACK_PORT_NONE)
5389 return 2;
5390 if (stac_get_defcfg_connect(codec, idx) != AC_JACK_PORT_NONE)
5391 return 1;
5392 else
5393 return 0;
5396 static int patch_stac92hd71bxx(struct hda_codec *codec)
5398 struct sigmatel_spec *spec;
5399 struct hda_verb *unmute_init = stac92hd71bxx_unmute_core_init;
5400 int err = 0;
5402 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5403 if (spec == NULL)
5404 return -ENOMEM;
5406 codec->spec = spec;
5407 codec->patch_ops = stac92xx_patch_ops;
5408 spec->num_pins = STAC92HD71BXX_NUM_PINS;
5409 switch (codec->vendor_id) {
5410 case 0x111d76b6:
5411 case 0x111d76b7:
5412 spec->pin_nids = stac92hd71bxx_pin_nids_4port;
5413 break;
5414 case 0x111d7603:
5415 case 0x111d7608:
5416 /* On 92HD75Bx 0x27 isn't a pin nid */
5417 spec->num_pins--;
5418 /* fallthrough */
5419 default:
5420 spec->pin_nids = stac92hd71bxx_pin_nids_6port;
5422 spec->num_pwrs = ARRAY_SIZE(stac92hd71bxx_pwr_nids);
5423 spec->board_config = snd_hda_check_board_config(codec,
5424 STAC_92HD71BXX_MODELS,
5425 stac92hd71bxx_models,
5426 stac92hd71bxx_cfg_tbl);
5427 again:
5428 if (spec->board_config < 0)
5429 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5430 codec->chip_name);
5431 else
5432 stac92xx_set_config_regs(codec,
5433 stac92hd71bxx_brd_tbl[spec->board_config]);
5435 if (spec->board_config > STAC_92HD71BXX_REF) {
5436 /* GPIO0 = EAPD */
5437 spec->gpio_mask = 0x01;
5438 spec->gpio_dir = 0x01;
5439 spec->gpio_data = 0x01;
5442 spec->dmic_nids = stac92hd71bxx_dmic_nids;
5443 spec->dmux_nids = stac92hd71bxx_dmux_nids;
5445 spec->num_caps = STAC92HD71BXX_NUM_CAPS;
5446 spec->capvols = stac92hd71bxx_capvols;
5447 spec->capsws = stac92hd71bxx_capsws;
5449 switch (codec->vendor_id) {
5450 case 0x111d76b6: /* 4 Port without Analog Mixer */
5451 case 0x111d76b7:
5452 unmute_init++;
5453 /* fallthru */
5454 case 0x111d76b4: /* 6 Port without Analog Mixer */
5455 case 0x111d76b5:
5456 spec->init = stac92hd71bxx_core_init;
5457 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
5458 spec->num_dmics = stac92hd71bxx_connected_ports(codec,
5459 stac92hd71bxx_dmic_nids,
5460 STAC92HD71BXX_NUM_DMICS);
5461 break;
5462 case 0x111d7608: /* 5 Port with Analog Mixer */
5463 switch (spec->board_config) {
5464 case STAC_HP_M4:
5465 /* Enable VREF power saving on GPIO1 detect */
5466 err = stac_add_event(spec, codec->afg,
5467 STAC_VREF_EVENT, 0x02);
5468 if (err < 0)
5469 return err;
5470 snd_hda_codec_write_cache(codec, codec->afg, 0,
5471 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x02);
5472 snd_hda_codec_write_cache(codec, codec->afg, 0,
5473 AC_VERB_SET_UNSOLICITED_ENABLE,
5474 AC_USRSP_EN | err);
5475 spec->gpio_mask |= 0x02;
5476 break;
5478 if ((codec->revision_id & 0xf) == 0 ||
5479 (codec->revision_id & 0xf) == 1)
5480 spec->stream_delay = 40; /* 40 milliseconds */
5482 /* no output amps */
5483 spec->num_pwrs = 0;
5484 /* disable VSW */
5485 spec->init = stac92hd71bxx_core_init;
5486 unmute_init++;
5487 snd_hda_codec_set_pincfg(codec, 0x0f, 0x40f000f0);
5488 snd_hda_codec_set_pincfg(codec, 0x19, 0x40f000f3);
5489 stac92hd71bxx_dmic_nids[STAC92HD71BXX_NUM_DMICS - 1] = 0;
5490 spec->num_dmics = stac92hd71bxx_connected_ports(codec,
5491 stac92hd71bxx_dmic_nids,
5492 STAC92HD71BXX_NUM_DMICS - 1);
5493 break;
5494 case 0x111d7603: /* 6 Port with Analog Mixer */
5495 if ((codec->revision_id & 0xf) == 1)
5496 spec->stream_delay = 40; /* 40 milliseconds */
5498 /* no output amps */
5499 spec->num_pwrs = 0;
5500 /* fallthru */
5501 default:
5502 spec->init = stac92hd71bxx_core_init;
5503 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
5504 spec->num_dmics = stac92hd71bxx_connected_ports(codec,
5505 stac92hd71bxx_dmic_nids,
5506 STAC92HD71BXX_NUM_DMICS);
5507 break;
5510 if (get_wcaps(codec, 0xa) & AC_WCAP_IN_AMP)
5511 snd_hda_sequence_write_cache(codec, unmute_init);
5513 /* Some HP machines seem to have unstable codec communications
5514 * especially with ATI fglrx driver. For recovering from the
5515 * CORB/RIRB stall, allow the BUS reset and keep always sync
5517 if (spec->board_config == STAC_HP_DV5) {
5518 codec->bus->sync_write = 1;
5519 codec->bus->allow_bus_reset = 1;
5522 spec->aloopback_ctl = stac92hd71bxx_loopback;
5523 spec->aloopback_mask = 0x50;
5524 spec->aloopback_shift = 0;
5526 spec->powerdown_adcs = 1;
5527 spec->digbeep_nid = 0x26;
5528 spec->mux_nids = stac92hd71bxx_mux_nids;
5529 spec->adc_nids = stac92hd71bxx_adc_nids;
5530 spec->smux_nids = stac92hd71bxx_smux_nids;
5531 spec->pwr_nids = stac92hd71bxx_pwr_nids;
5533 spec->num_muxes = ARRAY_SIZE(stac92hd71bxx_mux_nids);
5534 spec->num_adcs = ARRAY_SIZE(stac92hd71bxx_adc_nids);
5535 spec->num_dmuxes = ARRAY_SIZE(stac92hd71bxx_dmux_nids);
5536 spec->num_smuxes = stac92hd71bxx_connected_smuxes(codec, 0x1e);
5538 switch (spec->board_config) {
5539 case STAC_HP_M4:
5540 /* enable internal microphone */
5541 snd_hda_codec_set_pincfg(codec, 0x0e, 0x01813040);
5542 stac92xx_auto_set_pinctl(codec, 0x0e,
5543 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80);
5544 /* fallthru */
5545 case STAC_DELL_M4_2:
5546 spec->num_dmics = 0;
5547 spec->num_smuxes = 0;
5548 spec->num_dmuxes = 0;
5549 break;
5550 case STAC_DELL_M4_1:
5551 case STAC_DELL_M4_3:
5552 spec->num_dmics = 1;
5553 spec->num_smuxes = 0;
5554 spec->num_dmuxes = 1;
5555 break;
5556 case STAC_HP_DV4_1222NR:
5557 spec->num_dmics = 1;
5558 /* I don't know if it needs 1 or 2 smuxes - will wait for
5559 * bug reports to fix if needed
5561 spec->num_smuxes = 1;
5562 spec->num_dmuxes = 1;
5563 spec->gpio_led = 0x01;
5564 /* fallthrough */
5565 case STAC_HP_DV5:
5566 snd_hda_codec_set_pincfg(codec, 0x0d, 0x90170010);
5567 stac92xx_auto_set_pinctl(codec, 0x0d, AC_PINCTL_OUT_EN);
5568 break;
5569 case STAC_HP_HDX:
5570 spec->num_dmics = 1;
5571 spec->num_dmuxes = 1;
5572 spec->num_smuxes = 1;
5573 /* orange/white mute led on GPIO3, orange=0, white=1 */
5574 spec->gpio_led = 0x08;
5575 break;
5578 #ifdef CONFIG_SND_HDA_POWER_SAVE
5579 if (spec->gpio_led) {
5580 spec->gpio_mask |= spec->gpio_led;
5581 spec->gpio_dir |= spec->gpio_led;
5582 spec->gpio_data |= spec->gpio_led;
5583 /* register check_power_status callback. */
5584 codec->patch_ops.check_power_status =
5585 stac92xx_hp_check_power_status;
5587 #endif
5589 spec->multiout.dac_nids = spec->dac_nids;
5591 err = stac92xx_parse_auto_config(codec, 0x21, 0);
5592 if (!err) {
5593 if (spec->board_config < 0) {
5594 printk(KERN_WARNING "hda_codec: No auto-config is "
5595 "available, default to model=ref\n");
5596 spec->board_config = STAC_92HD71BXX_REF;
5597 goto again;
5599 err = -EINVAL;
5602 if (err < 0) {
5603 stac92xx_free(codec);
5604 return err;
5607 codec->proc_widget_hook = stac92hd7x_proc_hook;
5609 return 0;
5612 static int patch_stac922x(struct hda_codec *codec)
5614 struct sigmatel_spec *spec;
5615 int err;
5617 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5618 if (spec == NULL)
5619 return -ENOMEM;
5621 codec->spec = spec;
5622 spec->num_pins = ARRAY_SIZE(stac922x_pin_nids);
5623 spec->pin_nids = stac922x_pin_nids;
5624 spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS,
5625 stac922x_models,
5626 stac922x_cfg_tbl);
5627 if (spec->board_config == STAC_INTEL_MAC_AUTO) {
5628 spec->gpio_mask = spec->gpio_dir = 0x03;
5629 spec->gpio_data = 0x03;
5630 /* Intel Macs have all same PCI SSID, so we need to check
5631 * codec SSID to distinguish the exact models
5633 printk(KERN_INFO "hda_codec: STAC922x, Apple subsys_id=%x\n", codec->subsystem_id);
5634 switch (codec->subsystem_id) {
5636 case 0x106b0800:
5637 spec->board_config = STAC_INTEL_MAC_V1;
5638 break;
5639 case 0x106b0600:
5640 case 0x106b0700:
5641 spec->board_config = STAC_INTEL_MAC_V2;
5642 break;
5643 case 0x106b0e00:
5644 case 0x106b0f00:
5645 case 0x106b1600:
5646 case 0x106b1700:
5647 case 0x106b0200:
5648 case 0x106b1e00:
5649 spec->board_config = STAC_INTEL_MAC_V3;
5650 break;
5651 case 0x106b1a00:
5652 case 0x00000100:
5653 spec->board_config = STAC_INTEL_MAC_V4;
5654 break;
5655 case 0x106b0a00:
5656 case 0x106b2200:
5657 spec->board_config = STAC_INTEL_MAC_V5;
5658 break;
5659 default:
5660 spec->board_config = STAC_INTEL_MAC_V3;
5661 break;
5665 again:
5666 if (spec->board_config < 0)
5667 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5668 codec->chip_name);
5669 else
5670 stac92xx_set_config_regs(codec,
5671 stac922x_brd_tbl[spec->board_config]);
5673 spec->adc_nids = stac922x_adc_nids;
5674 spec->mux_nids = stac922x_mux_nids;
5675 spec->num_muxes = ARRAY_SIZE(stac922x_mux_nids);
5676 spec->num_adcs = ARRAY_SIZE(stac922x_adc_nids);
5677 spec->num_dmics = 0;
5678 spec->num_pwrs = 0;
5680 spec->init = stac922x_core_init;
5682 spec->num_caps = STAC922X_NUM_CAPS;
5683 spec->capvols = stac922x_capvols;
5684 spec->capsws = stac922x_capsws;
5686 spec->multiout.dac_nids = spec->dac_nids;
5688 err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
5689 if (!err) {
5690 if (spec->board_config < 0) {
5691 printk(KERN_WARNING "hda_codec: No auto-config is "
5692 "available, default to model=ref\n");
5693 spec->board_config = STAC_D945_REF;
5694 goto again;
5696 err = -EINVAL;
5698 if (err < 0) {
5699 stac92xx_free(codec);
5700 return err;
5703 codec->patch_ops = stac92xx_patch_ops;
5705 /* Fix Mux capture level; max to 2 */
5706 snd_hda_override_amp_caps(codec, 0x12, HDA_OUTPUT,
5707 (0 << AC_AMPCAP_OFFSET_SHIFT) |
5708 (2 << AC_AMPCAP_NUM_STEPS_SHIFT) |
5709 (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5710 (0 << AC_AMPCAP_MUTE_SHIFT));
5712 return 0;
5715 static int patch_stac927x(struct hda_codec *codec)
5717 struct sigmatel_spec *spec;
5718 int err;
5720 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5721 if (spec == NULL)
5722 return -ENOMEM;
5724 codec->spec = spec;
5725 codec->slave_dig_outs = stac927x_slave_dig_outs;
5726 spec->num_pins = ARRAY_SIZE(stac927x_pin_nids);
5727 spec->pin_nids = stac927x_pin_nids;
5728 spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS,
5729 stac927x_models,
5730 stac927x_cfg_tbl);
5731 again:
5732 if (spec->board_config < 0)
5733 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5734 codec->chip_name);
5735 else
5736 stac92xx_set_config_regs(codec,
5737 stac927x_brd_tbl[spec->board_config]);
5739 spec->digbeep_nid = 0x23;
5740 spec->adc_nids = stac927x_adc_nids;
5741 spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
5742 spec->mux_nids = stac927x_mux_nids;
5743 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
5744 spec->smux_nids = stac927x_smux_nids;
5745 spec->num_smuxes = ARRAY_SIZE(stac927x_smux_nids);
5746 spec->spdif_labels = stac927x_spdif_labels;
5747 spec->dac_list = stac927x_dac_nids;
5748 spec->multiout.dac_nids = spec->dac_nids;
5750 switch (spec->board_config) {
5751 case STAC_D965_3ST:
5752 case STAC_D965_5ST:
5753 /* GPIO0 High = Enable EAPD */
5754 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x01;
5755 spec->gpio_data = 0x01;
5756 spec->num_dmics = 0;
5758 spec->init = d965_core_init;
5759 break;
5760 case STAC_DELL_BIOS:
5761 switch (codec->subsystem_id) {
5762 case 0x10280209:
5763 case 0x1028022e:
5764 /* correct the device field to SPDIF out */
5765 snd_hda_codec_set_pincfg(codec, 0x21, 0x01442070);
5766 break;
5768 /* configure the analog microphone on some laptops */
5769 snd_hda_codec_set_pincfg(codec, 0x0c, 0x90a79130);
5770 /* correct the front output jack as a hp out */
5771 snd_hda_codec_set_pincfg(codec, 0x0f, 0x0227011f);
5772 /* correct the front input jack as a mic */
5773 snd_hda_codec_set_pincfg(codec, 0x0e, 0x02a79130);
5774 /* fallthru */
5775 case STAC_DELL_3ST:
5776 /* GPIO2 High = Enable EAPD */
5777 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x04;
5778 spec->gpio_data = 0x04;
5779 spec->dmic_nids = stac927x_dmic_nids;
5780 spec->num_dmics = STAC927X_NUM_DMICS;
5782 spec->init = d965_core_init;
5783 spec->dmux_nids = stac927x_dmux_nids;
5784 spec->num_dmuxes = ARRAY_SIZE(stac927x_dmux_nids);
5785 break;
5786 default:
5787 if (spec->board_config > STAC_D965_REF) {
5788 /* GPIO0 High = Enable EAPD */
5789 spec->eapd_mask = spec->gpio_mask = 0x01;
5790 spec->gpio_dir = spec->gpio_data = 0x01;
5792 spec->num_dmics = 0;
5794 spec->init = stac927x_core_init;
5797 spec->num_caps = STAC927X_NUM_CAPS;
5798 spec->capvols = stac927x_capvols;
5799 spec->capsws = stac927x_capsws;
5801 spec->num_pwrs = 0;
5802 spec->aloopback_ctl = stac927x_loopback;
5803 spec->aloopback_mask = 0x40;
5804 spec->aloopback_shift = 0;
5805 spec->eapd_switch = 1;
5807 err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
5808 if (!err) {
5809 if (spec->board_config < 0) {
5810 printk(KERN_WARNING "hda_codec: No auto-config is "
5811 "available, default to model=ref\n");
5812 spec->board_config = STAC_D965_REF;
5813 goto again;
5815 err = -EINVAL;
5817 if (err < 0) {
5818 stac92xx_free(codec);
5819 return err;
5822 codec->patch_ops = stac92xx_patch_ops;
5824 codec->proc_widget_hook = stac927x_proc_hook;
5827 * !!FIXME!!
5828 * The STAC927x seem to require fairly long delays for certain
5829 * command sequences. With too short delays (even if the answer
5830 * is set to RIRB properly), it results in the silence output
5831 * on some hardwares like Dell.
5833 * The below flag enables the longer delay (see get_response
5834 * in hda_intel.c).
5836 codec->bus->needs_damn_long_delay = 1;
5838 /* no jack detecion for ref-no-jd model */
5839 if (spec->board_config == STAC_D965_REF_NO_JD)
5840 spec->hp_detect = 0;
5842 return 0;
5845 static int patch_stac9205(struct hda_codec *codec)
5847 struct sigmatel_spec *spec;
5848 int err;
5850 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5851 if (spec == NULL)
5852 return -ENOMEM;
5854 codec->spec = spec;
5855 spec->num_pins = ARRAY_SIZE(stac9205_pin_nids);
5856 spec->pin_nids = stac9205_pin_nids;
5857 spec->board_config = snd_hda_check_board_config(codec, STAC_9205_MODELS,
5858 stac9205_models,
5859 stac9205_cfg_tbl);
5860 again:
5861 if (spec->board_config < 0)
5862 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5863 codec->chip_name);
5864 else
5865 stac92xx_set_config_regs(codec,
5866 stac9205_brd_tbl[spec->board_config]);
5868 spec->digbeep_nid = 0x23;
5869 spec->adc_nids = stac9205_adc_nids;
5870 spec->num_adcs = ARRAY_SIZE(stac9205_adc_nids);
5871 spec->mux_nids = stac9205_mux_nids;
5872 spec->num_muxes = ARRAY_SIZE(stac9205_mux_nids);
5873 spec->smux_nids = stac9205_smux_nids;
5874 spec->num_smuxes = ARRAY_SIZE(stac9205_smux_nids);
5875 spec->dmic_nids = stac9205_dmic_nids;
5876 spec->num_dmics = STAC9205_NUM_DMICS;
5877 spec->dmux_nids = stac9205_dmux_nids;
5878 spec->num_dmuxes = ARRAY_SIZE(stac9205_dmux_nids);
5879 spec->num_pwrs = 0;
5881 spec->init = stac9205_core_init;
5882 spec->aloopback_ctl = stac9205_loopback;
5884 spec->num_caps = STAC9205_NUM_CAPS;
5885 spec->capvols = stac9205_capvols;
5886 spec->capsws = stac9205_capsws;
5888 spec->aloopback_mask = 0x40;
5889 spec->aloopback_shift = 0;
5890 /* Turn on/off EAPD per HP plugging */
5891 if (spec->board_config != STAC_9205_EAPD)
5892 spec->eapd_switch = 1;
5893 spec->multiout.dac_nids = spec->dac_nids;
5895 switch (spec->board_config){
5896 case STAC_9205_DELL_M43:
5897 /* Enable SPDIF in/out */
5898 snd_hda_codec_set_pincfg(codec, 0x1f, 0x01441030);
5899 snd_hda_codec_set_pincfg(codec, 0x20, 0x1c410030);
5901 /* Enable unsol response for GPIO4/Dock HP connection */
5902 err = stac_add_event(spec, codec->afg, STAC_VREF_EVENT, 0x01);
5903 if (err < 0)
5904 return err;
5905 snd_hda_codec_write_cache(codec, codec->afg, 0,
5906 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x10);
5907 snd_hda_codec_write_cache(codec, codec->afg, 0,
5908 AC_VERB_SET_UNSOLICITED_ENABLE,
5909 AC_USRSP_EN | err);
5911 spec->gpio_dir = 0x0b;
5912 spec->eapd_mask = 0x01;
5913 spec->gpio_mask = 0x1b;
5914 spec->gpio_mute = 0x10;
5915 /* GPIO0 High = EAPD, GPIO1 Low = Headphone Mute,
5916 * GPIO3 Low = DRM
5918 spec->gpio_data = 0x01;
5919 break;
5920 case STAC_9205_REF:
5921 /* SPDIF-In enabled */
5922 break;
5923 default:
5924 /* GPIO0 High = EAPD */
5925 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
5926 spec->gpio_data = 0x01;
5927 break;
5930 err = stac92xx_parse_auto_config(codec, 0x1f, 0x20);
5931 if (!err) {
5932 if (spec->board_config < 0) {
5933 printk(KERN_WARNING "hda_codec: No auto-config is "
5934 "available, default to model=ref\n");
5935 spec->board_config = STAC_9205_REF;
5936 goto again;
5938 err = -EINVAL;
5940 if (err < 0) {
5941 stac92xx_free(codec);
5942 return err;
5945 codec->patch_ops = stac92xx_patch_ops;
5947 codec->proc_widget_hook = stac9205_proc_hook;
5949 return 0;
5953 * STAC9872 hack
5956 static struct hda_verb stac9872_core_init[] = {
5957 {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
5958 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
5962 static hda_nid_t stac9872_pin_nids[] = {
5963 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
5964 0x11, 0x13, 0x14,
5967 static hda_nid_t stac9872_adc_nids[] = {
5968 0x8 /*,0x6*/
5971 static hda_nid_t stac9872_mux_nids[] = {
5972 0x15
5975 static unsigned long stac9872_capvols[] = {
5976 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
5978 #define stac9872_capsws stac9872_capvols
5980 static unsigned int stac9872_vaio_pin_configs[9] = {
5981 0x03211020, 0x411111f0, 0x411111f0, 0x03a15030,
5982 0x411111f0, 0x90170110, 0x411111f0, 0x411111f0,
5983 0x90a7013e
5986 static const char *stac9872_models[STAC_9872_MODELS] = {
5987 [STAC_9872_AUTO] = "auto",
5988 [STAC_9872_VAIO] = "vaio",
5991 static unsigned int *stac9872_brd_tbl[STAC_9872_MODELS] = {
5992 [STAC_9872_VAIO] = stac9872_vaio_pin_configs,
5995 static struct snd_pci_quirk stac9872_cfg_tbl[] = {
5996 SND_PCI_QUIRK_MASK(0x104d, 0xfff0, 0x81e0,
5997 "Sony VAIO F/S", STAC_9872_VAIO),
5998 {} /* terminator */
6001 static int patch_stac9872(struct hda_codec *codec)
6003 struct sigmatel_spec *spec;
6004 int err;
6006 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6007 if (spec == NULL)
6008 return -ENOMEM;
6009 codec->spec = spec;
6010 spec->num_pins = ARRAY_SIZE(stac9872_pin_nids);
6011 spec->pin_nids = stac9872_pin_nids;
6013 spec->board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
6014 stac9872_models,
6015 stac9872_cfg_tbl);
6016 if (spec->board_config < 0)
6017 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6018 codec->chip_name);
6019 else
6020 stac92xx_set_config_regs(codec,
6021 stac9872_brd_tbl[spec->board_config]);
6023 spec->multiout.dac_nids = spec->dac_nids;
6024 spec->num_adcs = ARRAY_SIZE(stac9872_adc_nids);
6025 spec->adc_nids = stac9872_adc_nids;
6026 spec->num_muxes = ARRAY_SIZE(stac9872_mux_nids);
6027 spec->mux_nids = stac9872_mux_nids;
6028 spec->init = stac9872_core_init;
6029 spec->num_caps = 1;
6030 spec->capvols = stac9872_capvols;
6031 spec->capsws = stac9872_capsws;
6033 err = stac92xx_parse_auto_config(codec, 0x10, 0x12);
6034 if (err < 0) {
6035 stac92xx_free(codec);
6036 return -EINVAL;
6038 spec->input_mux = &spec->private_imux;
6039 codec->patch_ops = stac92xx_patch_ops;
6040 return 0;
6045 * patch entries
6047 static struct hda_codec_preset snd_hda_preset_sigmatel[] = {
6048 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
6049 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
6050 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
6051 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
6052 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
6053 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
6054 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
6055 { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
6056 { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
6057 { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
6058 { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
6059 { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
6060 { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
6061 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
6062 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
6063 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
6064 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
6065 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
6066 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
6067 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
6068 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
6069 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
6070 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
6071 { .id = 0x83847632, .name = "STAC9202", .patch = patch_stac925x },
6072 { .id = 0x83847633, .name = "STAC9202D", .patch = patch_stac925x },
6073 { .id = 0x83847634, .name = "STAC9250", .patch = patch_stac925x },
6074 { .id = 0x83847635, .name = "STAC9250D", .patch = patch_stac925x },
6075 { .id = 0x83847636, .name = "STAC9251", .patch = patch_stac925x },
6076 { .id = 0x83847637, .name = "STAC9250D", .patch = patch_stac925x },
6077 { .id = 0x83847645, .name = "92HD206X", .patch = patch_stac927x },
6078 { .id = 0x83847646, .name = "92HD206D", .patch = patch_stac927x },
6079 /* The following does not take into account .id=0x83847661 when subsys =
6080 * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
6081 * currently not fully supported.
6083 { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
6084 { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
6085 { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
6086 { .id = 0x83847698, .name = "STAC9205", .patch = patch_stac9205 },
6087 { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
6088 { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
6089 { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
6090 { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
6091 { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
6092 { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
6093 { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
6094 { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
6095 { .id = 0x111d7603, .name = "92HD75B3X5", .patch = patch_stac92hd71bxx},
6096 { .id = 0x111d7604, .name = "92HD83C1X5", .patch = patch_stac92hd83xxx},
6097 { .id = 0x111d7605, .name = "92HD81B1X5", .patch = patch_stac92hd83xxx},
6098 { .id = 0x111d76d5, .name = "92HD81B1C5", .patch = patch_stac92hd83xxx},
6099 { .id = 0x111d7608, .name = "92HD75B2X5", .patch = patch_stac92hd71bxx},
6100 { .id = 0x111d7674, .name = "92HD73D1X5", .patch = patch_stac92hd73xx },
6101 { .id = 0x111d7675, .name = "92HD73C1X5", .patch = patch_stac92hd73xx },
6102 { .id = 0x111d7676, .name = "92HD73E1X5", .patch = patch_stac92hd73xx },
6103 { .id = 0x111d76b0, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
6104 { .id = 0x111d76b1, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
6105 { .id = 0x111d76b2, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
6106 { .id = 0x111d76b3, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
6107 { .id = 0x111d76b4, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
6108 { .id = 0x111d76b5, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
6109 { .id = 0x111d76b6, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
6110 { .id = 0x111d76b7, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
6111 {} /* terminator */
6114 MODULE_ALIAS("snd-hda-codec-id:8384*");
6115 MODULE_ALIAS("snd-hda-codec-id:111d*");
6117 MODULE_LICENSE("GPL");
6118 MODULE_DESCRIPTION("IDT/Sigmatel HD-audio codec");
6120 static struct hda_codec_preset_list sigmatel_list = {
6121 .preset = snd_hda_preset_sigmatel,
6122 .owner = THIS_MODULE,
6125 static int __init patch_sigmatel_init(void)
6127 return snd_hda_add_codec_preset(&sigmatel_list);
6130 static void __exit patch_sigmatel_exit(void)
6132 snd_hda_delete_codec_preset(&sigmatel_list);
6135 module_init(patch_sigmatel_init)
6136 module_exit(patch_sigmatel_exit)