code style scripts/checkpatch.pl (linux-3.9-rc1) formatting
[linux-2.6.34.14-moxart.git] / sound / pci / hda / patch_sigmatel.c
blob6c06d17fb692772f4bc6393b8c080f237b3dfc90
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 <linux/dmi.h>
32 #include <sound/core.h>
33 #include <sound/asoundef.h>
34 #include <sound/jack.h>
35 #include "hda_codec.h"
36 #include "hda_local.h"
37 #include "hda_beep.h"
39 enum {
40 STAC_VREF_EVENT = 1,
41 STAC_INSERT_EVENT,
42 STAC_PWR_EVENT,
43 STAC_HP_EVENT,
44 STAC_LO_EVENT,
45 STAC_MIC_EVENT,
48 enum {
49 STAC_AUTO,
50 STAC_REF,
51 STAC_9200_OQO,
52 STAC_9200_DELL_D21,
53 STAC_9200_DELL_D22,
54 STAC_9200_DELL_D23,
55 STAC_9200_DELL_M21,
56 STAC_9200_DELL_M22,
57 STAC_9200_DELL_M23,
58 STAC_9200_DELL_M24,
59 STAC_9200_DELL_M25,
60 STAC_9200_DELL_M26,
61 STAC_9200_DELL_M27,
62 STAC_9200_M4,
63 STAC_9200_M4_2,
64 STAC_9200_PANASONIC,
65 STAC_9200_MODELS
68 enum {
69 STAC_9205_AUTO,
70 STAC_9205_REF,
71 STAC_9205_DELL_M42,
72 STAC_9205_DELL_M43,
73 STAC_9205_DELL_M44,
74 STAC_9205_EAPD,
75 STAC_9205_MODELS
78 enum {
79 STAC_92HD73XX_AUTO,
80 STAC_92HD73XX_NO_JD, /* no jack-detection */
81 STAC_92HD73XX_REF,
82 STAC_92HD73XX_INTEL,
83 STAC_DELL_M6_AMIC,
84 STAC_DELL_M6_DMIC,
85 STAC_DELL_M6_BOTH,
86 STAC_DELL_EQ,
87 STAC_ALIENWARE_M17X,
88 STAC_92HD73XX_MODELS
91 enum {
92 STAC_92HD83XXX_AUTO,
93 STAC_92HD83XXX_REF,
94 STAC_92HD83XXX_PWR_REF,
95 STAC_DELL_S14,
96 STAC_92HD83XXX_HP,
97 STAC_92HD83XXX_MODELS
100 enum {
101 STAC_92HD71BXX_AUTO,
102 STAC_92HD71BXX_REF,
103 STAC_DELL_M4_1,
104 STAC_DELL_M4_2,
105 STAC_DELL_M4_3,
106 STAC_HP_M4,
107 STAC_HP_DV4,
108 STAC_HP_DV5,
109 STAC_HP_HDX,
110 STAC_HP_DV4_1222NR,
111 STAC_92HD71BXX_MODELS
114 enum {
115 STAC_925x_AUTO,
116 STAC_925x_REF,
117 STAC_M1,
118 STAC_M1_2,
119 STAC_M2,
120 STAC_M2_2,
121 STAC_M3,
122 STAC_M5,
123 STAC_M6,
124 STAC_925x_MODELS
127 enum {
128 STAC_922X_AUTO,
129 STAC_D945_REF,
130 STAC_D945GTP3,
131 STAC_D945GTP5,
132 STAC_INTEL_MAC_V1,
133 STAC_INTEL_MAC_V2,
134 STAC_INTEL_MAC_V3,
135 STAC_INTEL_MAC_V4,
136 STAC_INTEL_MAC_V5,
137 STAC_INTEL_MAC_AUTO, /* This model is selected if no module parameter
138 * is given, one of the above models will be
139 * chosen according to the subsystem id. */
140 /* for backward compatibility */
141 STAC_MACMINI,
142 STAC_MACBOOK,
143 STAC_MACBOOK_PRO_V1,
144 STAC_MACBOOK_PRO_V2,
145 STAC_IMAC_INTEL,
146 STAC_IMAC_INTEL_20,
147 STAC_ECS_202,
148 STAC_922X_DELL_D81,
149 STAC_922X_DELL_D82,
150 STAC_922X_DELL_M81,
151 STAC_922X_DELL_M82,
152 STAC_922X_MODELS
155 enum {
156 STAC_927X_AUTO,
157 STAC_D965_REF_NO_JD, /* no jack-detection */
158 STAC_D965_REF,
159 STAC_D965_3ST,
160 STAC_D965_5ST,
161 STAC_D965_5ST_NO_FP,
162 STAC_DELL_3ST,
163 STAC_DELL_BIOS,
164 STAC_927X_VOLKNOB,
165 STAC_927X_MODELS
168 enum {
169 STAC_9872_AUTO,
170 STAC_9872_VAIO,
171 STAC_9872_MODELS
174 struct sigmatel_event {
175 hda_nid_t nid;
176 unsigned char type;
177 unsigned char tag;
178 int data;
181 struct sigmatel_jack {
182 hda_nid_t nid;
183 int type;
184 struct snd_jack *jack;
187 struct sigmatel_mic_route {
188 hda_nid_t pin;
189 signed char mux_idx;
190 signed char dmux_idx;
193 struct sigmatel_spec {
194 struct snd_kcontrol_new *mixers[4];
195 unsigned int num_mixers;
197 int board_config;
198 unsigned int eapd_switch: 1;
199 unsigned int surr_switch: 1;
200 unsigned int alt_switch: 1;
201 unsigned int hp_detect: 1;
202 unsigned int spdif_mute: 1;
203 unsigned int check_volume_offset:1;
204 unsigned int auto_mic:1;
206 /* gpio lines */
207 unsigned int eapd_mask;
208 unsigned int gpio_mask;
209 unsigned int gpio_dir;
210 unsigned int gpio_data;
211 unsigned int gpio_mute;
212 unsigned int gpio_led;
213 unsigned int gpio_led_polarity;
215 /* stream */
216 unsigned int stream_delay;
218 /* analog loopback */
219 struct snd_kcontrol_new *aloopback_ctl;
220 unsigned char aloopback_mask;
221 unsigned char aloopback_shift;
223 /* power management */
224 unsigned int num_pwrs;
225 unsigned int *pwr_mapping;
226 hda_nid_t *pwr_nids;
227 hda_nid_t *dac_list;
229 /* jack detection */
230 struct snd_array jacks;
232 /* events */
233 struct snd_array events;
235 /* playback */
236 struct hda_input_mux *mono_mux;
237 unsigned int cur_mmux;
238 struct hda_multi_out multiout;
239 hda_nid_t dac_nids[5];
240 hda_nid_t hp_dacs[5];
241 hda_nid_t speaker_dacs[5];
243 int volume_offset;
245 /* capture */
246 hda_nid_t *adc_nids;
247 unsigned int num_adcs;
248 hda_nid_t *mux_nids;
249 unsigned int num_muxes;
250 hda_nid_t *dmic_nids;
251 unsigned int num_dmics;
252 hda_nid_t *dmux_nids;
253 unsigned int num_dmuxes;
254 hda_nid_t *smux_nids;
255 unsigned int num_smuxes;
256 unsigned int num_analog_muxes;
258 unsigned long *capvols; /* amp-volume attr: HDA_COMPOSE_AMP_VAL() */
259 unsigned long *capsws; /* amp-mute attr: HDA_COMPOSE_AMP_VAL() */
260 unsigned int num_caps; /* number of capture volume/switch elements */
262 struct sigmatel_mic_route ext_mic;
263 struct sigmatel_mic_route int_mic;
265 const char **spdif_labels;
267 hda_nid_t dig_in_nid;
268 hda_nid_t mono_nid;
269 hda_nid_t anabeep_nid;
270 hda_nid_t digbeep_nid;
272 /* pin widgets */
273 hda_nid_t *pin_nids;
274 unsigned int num_pins;
276 /* codec specific stuff */
277 struct hda_verb *init;
278 struct snd_kcontrol_new *mixer;
280 /* capture source */
281 struct hda_input_mux *dinput_mux;
282 unsigned int cur_dmux[2];
283 struct hda_input_mux *input_mux;
284 unsigned int cur_mux[3];
285 struct hda_input_mux *sinput_mux;
286 unsigned int cur_smux[2];
287 unsigned int cur_amux;
288 hda_nid_t *amp_nids;
289 unsigned int powerdown_adcs;
291 /* i/o switches */
292 unsigned int io_switch[2];
293 unsigned int clfe_swap;
294 hda_nid_t line_switch; /* shared line-in for input and output */
295 hda_nid_t mic_switch; /* shared mic-in for input and output */
296 hda_nid_t hp_switch; /* NID of HP as line-out */
297 unsigned int aloopback;
299 struct hda_pcm pcm_rec[2]; /* PCM information */
301 /* dynamic controls and input_mux */
302 struct auto_pin_cfg autocfg;
303 struct snd_array kctls;
304 struct hda_input_mux private_dimux;
305 struct hda_input_mux private_imux;
306 struct hda_input_mux private_smux;
307 struct hda_input_mux private_mono_mux;
310 static hda_nid_t stac9200_adc_nids[1] = {
311 0x03,
314 static hda_nid_t stac9200_mux_nids[1] = {
315 0x0c,
318 static hda_nid_t stac9200_dac_nids[1] = {
319 0x02,
322 static hda_nid_t stac92hd73xx_pwr_nids[8] = {
323 0x0a, 0x0b, 0x0c, 0xd, 0x0e,
324 0x0f, 0x10, 0x11
327 static hda_nid_t stac92hd73xx_slave_dig_outs[2] = {
328 0x26, 0,
331 static hda_nid_t stac92hd73xx_adc_nids[2] = {
332 0x1a, 0x1b
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[2] = {
343 0x20, 0x21,
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 STAC92HD83_DAC_COUNT 3
363 static hda_nid_t stac92hd83xxx_mux_nids[2] = {
364 0x17, 0x18,
367 static hda_nid_t stac92hd83xxx_adc_nids[2] = {
368 0x15, 0x16,
371 static hda_nid_t stac92hd83xxx_pwr_nids[4] = {
372 0xa, 0xb, 0xd, 0xe,
375 static hda_nid_t stac92hd83xxx_slave_dig_outs[2] = {
376 0x1e, 0,
379 static unsigned int stac92hd83xxx_pwr_mapping[4] = {
380 0x03, 0x0c, 0x20, 0x40,
383 #define STAC92HD83XXX_NUM_CAPS 2
384 static unsigned long stac92hd83xxx_capvols[] = {
385 HDA_COMPOSE_AMP_VAL(0x17, 3, 0, HDA_OUTPUT),
386 HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_OUTPUT),
388 #define stac92hd83xxx_capsws stac92hd83xxx_capvols
390 static hda_nid_t stac92hd71bxx_pwr_nids[3] = {
391 0x0a, 0x0d, 0x0f
394 static hda_nid_t stac92hd71bxx_adc_nids[2] = {
395 0x12, 0x13,
398 static hda_nid_t stac92hd71bxx_mux_nids[2] = {
399 0x1a, 0x1b
402 static hda_nid_t stac92hd71bxx_dmux_nids[2] = {
403 0x1c, 0x1d,
406 static hda_nid_t stac92hd71bxx_smux_nids[2] = {
407 0x24, 0x25,
410 #define STAC92HD71BXX_NUM_DMICS 2
411 static hda_nid_t stac92hd71bxx_dmic_nids[STAC92HD71BXX_NUM_DMICS + 1] = {
412 0x18, 0x19, 0
415 static hda_nid_t stac92hd71bxx_slave_dig_outs[2] = {
416 0x22, 0
419 #define STAC92HD71BXX_NUM_CAPS 2
420 static unsigned long stac92hd71bxx_capvols[] = {
421 HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_OUTPUT),
422 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
424 #define stac92hd71bxx_capsws stac92hd71bxx_capvols
426 static hda_nid_t stac925x_adc_nids[1] = {
427 0x03,
430 static hda_nid_t stac925x_mux_nids[1] = {
431 0x0f,
434 static hda_nid_t stac925x_dac_nids[1] = {
435 0x02,
438 #define STAC925X_NUM_DMICS 1
439 static hda_nid_t stac925x_dmic_nids[STAC925X_NUM_DMICS + 1] = {
440 0x15, 0
443 static hda_nid_t stac925x_dmux_nids[1] = {
444 0x14,
447 static unsigned long stac925x_capvols[] = {
448 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_OUTPUT),
450 static unsigned long stac925x_capsws[] = {
451 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
454 static hda_nid_t stac922x_adc_nids[2] = {
455 0x06, 0x07,
458 static hda_nid_t stac922x_mux_nids[2] = {
459 0x12, 0x13,
462 #define STAC922X_NUM_CAPS 2
463 static unsigned long stac922x_capvols[] = {
464 HDA_COMPOSE_AMP_VAL(0x17, 3, 0, HDA_INPUT),
465 HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_INPUT),
467 #define stac922x_capsws stac922x_capvols
469 static hda_nid_t stac927x_slave_dig_outs[2] = {
470 0x1f, 0,
473 static hda_nid_t stac927x_adc_nids[3] = {
474 0x07, 0x08, 0x09
477 static hda_nid_t stac927x_mux_nids[3] = {
478 0x15, 0x16, 0x17
481 static hda_nid_t stac927x_smux_nids[1] = {
482 0x21,
485 static hda_nid_t stac927x_dac_nids[6] = {
486 0x02, 0x03, 0x04, 0x05, 0x06, 0
489 static hda_nid_t stac927x_dmux_nids[1] = {
490 0x1b,
493 #define STAC927X_NUM_DMICS 2
494 static hda_nid_t stac927x_dmic_nids[STAC927X_NUM_DMICS + 1] = {
495 0x13, 0x14, 0
498 #define STAC927X_NUM_CAPS 3
499 static unsigned long stac927x_capvols[] = {
500 HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_INPUT),
501 HDA_COMPOSE_AMP_VAL(0x19, 3, 0, HDA_INPUT),
502 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_INPUT),
504 static unsigned long stac927x_capsws[] = {
505 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
506 HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_OUTPUT),
507 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
510 static const char *stac927x_spdif_labels[5] = {
511 "Digital Playback", "ADAT", "Analog Mux 1",
512 "Analog Mux 2", "Analog Mux 3"
515 static hda_nid_t stac9205_adc_nids[2] = {
516 0x12, 0x13
519 static hda_nid_t stac9205_mux_nids[2] = {
520 0x19, 0x1a
523 static hda_nid_t stac9205_dmux_nids[1] = {
524 0x1d,
527 static hda_nid_t stac9205_smux_nids[1] = {
528 0x21,
531 #define STAC9205_NUM_DMICS 2
532 static hda_nid_t stac9205_dmic_nids[STAC9205_NUM_DMICS + 1] = {
533 0x17, 0x18, 0
536 #define STAC9205_NUM_CAPS 2
537 static unsigned long stac9205_capvols[] = {
538 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_INPUT),
539 HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_INPUT),
541 static unsigned long stac9205_capsws[] = {
542 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
543 HDA_COMPOSE_AMP_VAL(0x1e, 3, 0, HDA_OUTPUT),
546 static hda_nid_t stac9200_pin_nids[8] = {
547 0x08, 0x09, 0x0d, 0x0e,
548 0x0f, 0x10, 0x11, 0x12,
551 static hda_nid_t stac925x_pin_nids[8] = {
552 0x07, 0x08, 0x0a, 0x0b,
553 0x0c, 0x0d, 0x10, 0x11,
556 static hda_nid_t stac922x_pin_nids[10] = {
557 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
558 0x0f, 0x10, 0x11, 0x15, 0x1b,
561 static hda_nid_t stac92hd73xx_pin_nids[13] = {
562 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
563 0x0f, 0x10, 0x11, 0x12, 0x13,
564 0x14, 0x22, 0x23
567 static hda_nid_t stac92hd83xxx_pin_nids[10] = {
568 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
569 0x0f, 0x10, 0x11, 0x1f, 0x20,
572 static hda_nid_t stac92hd88xxx_pin_nids[10] = {
573 0x0a, 0x0b, 0x0c, 0x0d,
574 0x0f, 0x11, 0x1f, 0x20,
577 #define STAC92HD71BXX_NUM_PINS 13
578 static hda_nid_t stac92hd71bxx_pin_nids_4port[STAC92HD71BXX_NUM_PINS] = {
579 0x0a, 0x0b, 0x0c, 0x0d, 0x00,
580 0x00, 0x14, 0x18, 0x19, 0x1e,
581 0x1f, 0x20, 0x27
583 static hda_nid_t stac92hd71bxx_pin_nids_6port[STAC92HD71BXX_NUM_PINS] = {
584 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
585 0x0f, 0x14, 0x18, 0x19, 0x1e,
586 0x1f, 0x20, 0x27
589 static hda_nid_t stac927x_pin_nids[14] = {
590 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
591 0x0f, 0x10, 0x11, 0x12, 0x13,
592 0x14, 0x21, 0x22, 0x23,
595 static hda_nid_t stac9205_pin_nids[12] = {
596 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
597 0x0f, 0x14, 0x16, 0x17, 0x18,
598 0x21, 0x22,
601 static int stac92xx_dmux_enum_info(struct snd_kcontrol *kcontrol,
602 struct snd_ctl_elem_info *uinfo)
604 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
605 struct sigmatel_spec *spec = codec->spec;
606 return snd_hda_input_mux_info(spec->dinput_mux, uinfo);
609 static int stac92xx_dmux_enum_get(struct snd_kcontrol *kcontrol,
610 struct snd_ctl_elem_value *ucontrol)
612 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
613 struct sigmatel_spec *spec = codec->spec;
614 unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
616 ucontrol->value.enumerated.item[0] = spec->cur_dmux[dmux_idx];
617 return 0;
620 static int stac92xx_dmux_enum_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 unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
627 return snd_hda_input_mux_put(codec, spec->dinput_mux, ucontrol,
628 spec->dmux_nids[dmux_idx], &spec->cur_dmux[dmux_idx]);
631 static int stac92xx_smux_enum_info(struct snd_kcontrol *kcontrol,
632 struct snd_ctl_elem_info *uinfo)
634 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
635 struct sigmatel_spec *spec = codec->spec;
636 return snd_hda_input_mux_info(spec->sinput_mux, uinfo);
639 static int stac92xx_smux_enum_get(struct snd_kcontrol *kcontrol,
640 struct snd_ctl_elem_value *ucontrol)
642 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
643 struct sigmatel_spec *spec = codec->spec;
644 unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
646 ucontrol->value.enumerated.item[0] = spec->cur_smux[smux_idx];
647 return 0;
650 static int stac92xx_smux_enum_put(struct snd_kcontrol *kcontrol,
651 struct snd_ctl_elem_value *ucontrol)
653 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
654 struct sigmatel_spec *spec = codec->spec;
655 struct hda_input_mux *smux = &spec->private_smux;
656 unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
657 int err, val;
658 hda_nid_t nid;
660 err = snd_hda_input_mux_put(codec, spec->sinput_mux, ucontrol,
661 spec->smux_nids[smux_idx], &spec->cur_smux[smux_idx]);
662 if (err < 0)
663 return err;
665 if (spec->spdif_mute) {
666 if (smux_idx == 0)
667 nid = spec->multiout.dig_out_nid;
668 else
669 nid = codec->slave_dig_outs[smux_idx - 1];
670 if (spec->cur_smux[smux_idx] == smux->num_items - 1)
671 val = HDA_AMP_MUTE;
672 else
673 val = 0;
674 /* un/mute SPDIF out */
675 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
676 HDA_AMP_MUTE, val);
678 return 0;
681 static unsigned int stac92xx_vref_set(struct hda_codec *codec,
682 hda_nid_t nid, unsigned int new_vref)
684 int error;
685 unsigned int pincfg;
686 pincfg = snd_hda_codec_read(codec, nid, 0,
687 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
689 pincfg &= 0xff;
690 pincfg &= ~(AC_PINCTL_VREFEN | AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
691 pincfg |= new_vref;
693 if (new_vref == AC_PINCTL_VREF_HIZ)
694 pincfg |= AC_PINCTL_OUT_EN;
695 else
696 pincfg |= AC_PINCTL_IN_EN;
698 error = snd_hda_codec_write_cache(codec, nid, 0,
699 AC_VERB_SET_PIN_WIDGET_CONTROL, pincfg);
700 if (error < 0)
701 return error;
702 else
703 return 1;
706 static unsigned int stac92xx_vref_get(struct hda_codec *codec, hda_nid_t nid)
708 unsigned int vref;
709 vref = snd_hda_codec_read(codec, nid, 0,
710 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
711 vref &= AC_PINCTL_VREFEN;
712 return vref;
715 static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
717 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
718 struct sigmatel_spec *spec = codec->spec;
719 return snd_hda_input_mux_info(spec->input_mux, uinfo);
722 static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
724 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
725 struct sigmatel_spec *spec = codec->spec;
726 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
728 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
729 return 0;
732 static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
734 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
735 struct sigmatel_spec *spec = codec->spec;
736 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
737 const struct hda_input_mux *imux = spec->input_mux;
738 unsigned int idx, prev_idx, didx;
740 idx = ucontrol->value.enumerated.item[0];
741 if (idx >= imux->num_items)
742 idx = imux->num_items - 1;
743 prev_idx = spec->cur_mux[adc_idx];
744 if (prev_idx == idx)
745 return 0;
746 if (idx < spec->num_analog_muxes) {
747 snd_hda_codec_write_cache(codec, spec->mux_nids[adc_idx], 0,
748 AC_VERB_SET_CONNECT_SEL,
749 imux->items[idx].index);
750 if (prev_idx >= spec->num_analog_muxes &&
751 spec->mux_nids[adc_idx] != spec->dmux_nids[adc_idx]) {
752 imux = spec->dinput_mux;
753 /* 0 = analog */
754 snd_hda_codec_write_cache(codec,
755 spec->dmux_nids[adc_idx], 0,
756 AC_VERB_SET_CONNECT_SEL,
757 imux->items[0].index);
759 } else {
760 imux = spec->dinput_mux;
761 /* first dimux item is hardcoded to select analog imux,
762 * so lets skip it
764 didx = idx - spec->num_analog_muxes + 1;
765 snd_hda_codec_write_cache(codec, spec->dmux_nids[adc_idx], 0,
766 AC_VERB_SET_CONNECT_SEL,
767 imux->items[didx].index);
769 spec->cur_mux[adc_idx] = idx;
770 return 1;
773 static int stac92xx_mono_mux_enum_info(struct snd_kcontrol *kcontrol,
774 struct snd_ctl_elem_info *uinfo)
776 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
777 struct sigmatel_spec *spec = codec->spec;
778 return snd_hda_input_mux_info(spec->mono_mux, uinfo);
781 static int stac92xx_mono_mux_enum_get(struct snd_kcontrol *kcontrol,
782 struct snd_ctl_elem_value *ucontrol)
784 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
785 struct sigmatel_spec *spec = codec->spec;
787 ucontrol->value.enumerated.item[0] = spec->cur_mmux;
788 return 0;
791 static int stac92xx_mono_mux_enum_put(struct snd_kcontrol *kcontrol,
792 struct snd_ctl_elem_value *ucontrol)
794 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
795 struct sigmatel_spec *spec = codec->spec;
797 return snd_hda_input_mux_put(codec, spec->mono_mux, ucontrol,
798 spec->mono_nid, &spec->cur_mmux);
801 #define stac92xx_aloopback_info snd_ctl_boolean_mono_info
803 static int stac92xx_aloopback_get(struct snd_kcontrol *kcontrol,
804 struct snd_ctl_elem_value *ucontrol)
806 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
807 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
808 struct sigmatel_spec *spec = codec->spec;
810 ucontrol->value.integer.value[0] = !!(spec->aloopback &
811 (spec->aloopback_mask << idx));
812 return 0;
815 static int stac92xx_aloopback_put(struct snd_kcontrol *kcontrol,
816 struct snd_ctl_elem_value *ucontrol)
818 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
819 struct sigmatel_spec *spec = codec->spec;
820 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
821 unsigned int dac_mode;
822 unsigned int val, idx_val;
824 idx_val = spec->aloopback_mask << idx;
825 if (ucontrol->value.integer.value[0])
826 val = spec->aloopback | idx_val;
827 else
828 val = spec->aloopback & ~idx_val;
829 if (spec->aloopback == val)
830 return 0;
832 spec->aloopback = val;
834 /* Only return the bits defined by the shift value of the
835 * first two bytes of the mask
837 dac_mode = snd_hda_codec_read(codec, codec->afg, 0,
838 kcontrol->private_value & 0xFFFF, 0x0);
839 dac_mode >>= spec->aloopback_shift;
841 if (spec->aloopback & idx_val) {
842 snd_hda_power_up(codec);
843 dac_mode |= idx_val;
844 } else {
845 snd_hda_power_down(codec);
846 dac_mode &= ~idx_val;
849 snd_hda_codec_write_cache(codec, codec->afg, 0,
850 kcontrol->private_value >> 16, dac_mode);
852 return 1;
855 static struct hda_verb stac9200_core_init[] = {
856 /* set dac0mux for dac converter */
857 { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
861 static struct hda_verb stac9200_eapd_init[] = {
862 /* set dac0mux for dac converter */
863 {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
864 {0x08, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
868 static struct hda_verb dell_eq_core_init[] = {
869 /* set master volume to max value without distortion
870 * and direct control */
871 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xec},
875 static struct hda_verb stac92hd73xx_core_init[] = {
876 /* set master volume and direct control */
877 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
881 static struct hda_verb stac92hd83xxx_core_init[] = {
882 /* power state controls amps */
883 { 0x01, AC_VERB_SET_EAPD, 1 << 2},
887 static struct hda_verb stac92hd71bxx_core_init[] = {
888 /* set master volume and direct control */
889 { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
893 static struct hda_verb stac92hd71bxx_unmute_core_init[] = {
894 /* unmute right and left channels for nodes 0x0f, 0xa, 0x0d */
895 { 0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
896 { 0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
897 { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
901 static struct hda_verb stac925x_core_init[] = {
902 /* set dac0mux for dac converter */
903 { 0x06, AC_VERB_SET_CONNECT_SEL, 0x00},
904 /* mute the master volume */
905 { 0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
909 static struct hda_verb stac922x_core_init[] = {
910 /* set master volume and direct control */
911 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
915 static struct hda_verb d965_core_init[] = {
916 /* set master volume and direct control */
917 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
918 /* unmute node 0x1b */
919 { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
920 /* select node 0x03 as DAC */
921 { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
925 static struct hda_verb dell_3st_core_init[] = {
926 /* don't set delta bit */
927 {0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0x7f},
928 /* unmute node 0x1b */
929 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
930 /* select node 0x03 as DAC */
931 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
935 static struct hda_verb stac927x_core_init[] = {
936 /* set master volume and direct control */
937 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
938 /* enable analog pc beep path */
939 { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
943 static struct hda_verb stac927x_volknob_core_init[] = {
944 /* don't set delta bit */
945 {0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0x7f},
946 /* enable analog pc beep path */
947 {0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
951 static struct hda_verb stac9205_core_init[] = {
952 /* set master volume and direct control */
953 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
954 /* enable analog pc beep path */
955 { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
959 #define STAC_MONO_MUX \
961 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
962 .name = "Mono Mux", \
963 .count = 1, \
964 .info = stac92xx_mono_mux_enum_info, \
965 .get = stac92xx_mono_mux_enum_get, \
966 .put = stac92xx_mono_mux_enum_put, \
969 #define STAC_ANALOG_LOOPBACK(verb_read, verb_write, cnt) \
971 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
972 .name = "Analog Loopback", \
973 .count = cnt, \
974 .info = stac92xx_aloopback_info, \
975 .get = stac92xx_aloopback_get, \
976 .put = stac92xx_aloopback_put, \
977 .private_value = verb_read | (verb_write << 16), \
980 #define DC_BIAS(xname, idx, nid) \
982 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
983 .name = xname, \
984 .index = idx, \
985 .info = stac92xx_dc_bias_info, \
986 .get = stac92xx_dc_bias_get, \
987 .put = stac92xx_dc_bias_put, \
988 .private_value = nid, \
991 static struct snd_kcontrol_new stac9200_mixer[] = {
992 HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
993 HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
994 HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
995 HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
996 { } /* end */
999 static struct snd_kcontrol_new stac92hd73xx_6ch_loopback[] = {
1000 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 3),
1004 static struct snd_kcontrol_new stac92hd73xx_8ch_loopback[] = {
1005 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 4),
1009 static struct snd_kcontrol_new stac92hd73xx_10ch_loopback[] = {
1010 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 5),
1015 static struct snd_kcontrol_new stac92hd71bxx_loopback[] = {
1016 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A0, 2)
1019 static struct snd_kcontrol_new stac925x_mixer[] = {
1020 HDA_CODEC_VOLUME("Master Playback Volume", 0x0e, 0, HDA_OUTPUT),
1021 HDA_CODEC_MUTE("Master Playback Switch", 0x0e, 0, HDA_OUTPUT),
1022 { } /* end */
1025 static struct snd_kcontrol_new stac9205_loopback[] = {
1026 STAC_ANALOG_LOOPBACK(0xFE0, 0x7E0, 1),
1030 static struct snd_kcontrol_new stac927x_loopback[] = {
1031 STAC_ANALOG_LOOPBACK(0xFEB, 0x7EB, 1),
1035 static struct snd_kcontrol_new stac_dmux_mixer = {
1036 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1037 .name = "Digital Input Source",
1038 /* count set later */
1039 .info = stac92xx_dmux_enum_info,
1040 .get = stac92xx_dmux_enum_get,
1041 .put = stac92xx_dmux_enum_put,
1044 static struct snd_kcontrol_new stac_smux_mixer = {
1045 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1046 .name = "IEC958 Playback Source",
1047 /* count set later */
1048 .info = stac92xx_smux_enum_info,
1049 .get = stac92xx_smux_enum_get,
1050 .put = stac92xx_smux_enum_put,
1053 static const char *slave_vols[] = {
1054 "Front Playback Volume",
1055 "Surround Playback Volume",
1056 "Center Playback Volume",
1057 "LFE Playback Volume",
1058 "Side Playback Volume",
1059 "Headphone Playback Volume",
1060 "Speaker Playback Volume",
1061 NULL
1064 static const char *slave_sws[] = {
1065 "Front Playback Switch",
1066 "Surround Playback Switch",
1067 "Center Playback Switch",
1068 "LFE Playback Switch",
1069 "Side Playback Switch",
1070 "Headphone Playback Switch",
1071 "Speaker Playback Switch",
1072 "IEC958 Playback Switch",
1073 NULL
1076 static void stac92xx_free_kctls(struct hda_codec *codec);
1077 static int stac92xx_add_jack(struct hda_codec *codec, hda_nid_t nid, int type);
1079 static int stac92xx_build_controls(struct hda_codec *codec)
1081 struct sigmatel_spec *spec = codec->spec;
1082 struct auto_pin_cfg *cfg = &spec->autocfg;
1083 hda_nid_t nid;
1084 int err;
1085 int i;
1087 if (spec->mixer) {
1088 err = snd_hda_add_new_ctls(codec, spec->mixer);
1089 if (err < 0)
1090 return err;
1093 for (i = 0; i < spec->num_mixers; i++) {
1094 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1095 if (err < 0)
1096 return err;
1098 if (!spec->auto_mic && spec->num_dmuxes > 0 &&
1099 snd_hda_get_bool_hint(codec, "separate_dmux") == 1) {
1100 stac_dmux_mixer.count = spec->num_dmuxes;
1101 err = snd_hda_ctl_add(codec, 0,
1102 snd_ctl_new1(&stac_dmux_mixer, codec));
1103 if (err < 0)
1104 return err;
1106 if (spec->num_smuxes > 0) {
1107 int wcaps = get_wcaps(codec, spec->multiout.dig_out_nid);
1108 struct hda_input_mux *smux = &spec->private_smux;
1109 /* check for mute support on SPDIF out */
1110 if (wcaps & AC_WCAP_OUT_AMP) {
1111 smux->items[smux->num_items].label = "Off";
1112 smux->items[smux->num_items].index = 0;
1113 smux->num_items++;
1114 spec->spdif_mute = 1;
1116 stac_smux_mixer.count = spec->num_smuxes;
1117 err = snd_hda_ctl_add(codec, 0,
1118 snd_ctl_new1(&stac_smux_mixer, codec));
1119 if (err < 0)
1120 return err;
1123 if (spec->multiout.dig_out_nid) {
1124 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
1125 if (err < 0)
1126 return err;
1127 err = snd_hda_create_spdif_share_sw(codec,
1128 &spec->multiout);
1129 if (err < 0)
1130 return err;
1131 spec->multiout.share_spdif = 1;
1133 if (spec->dig_in_nid && !(spec->gpio_dir & 0x01)) {
1134 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1135 if (err < 0)
1136 return err;
1139 /* if we have no master control, let's create it */
1140 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
1141 unsigned int vmaster_tlv[4];
1142 snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0],
1143 HDA_OUTPUT, vmaster_tlv);
1144 /* correct volume offset */
1145 vmaster_tlv[2] += vmaster_tlv[3] * spec->volume_offset;
1146 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
1147 vmaster_tlv, slave_vols);
1148 if (err < 0)
1149 return err;
1151 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1152 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1153 NULL, slave_sws);
1154 if (err < 0)
1155 return err;
1158 if (spec->aloopback_ctl &&
1159 snd_hda_get_bool_hint(codec, "loopback") == 1) {
1160 err = snd_hda_add_new_ctls(codec, spec->aloopback_ctl);
1161 if (err < 0)
1162 return err;
1165 stac92xx_free_kctls(codec); /* no longer needed */
1167 /* create jack input elements */
1168 if (spec->hp_detect) {
1169 for (i = 0; i < cfg->hp_outs; i++) {
1170 int type = SND_JACK_HEADPHONE;
1171 nid = cfg->hp_pins[i];
1172 /* jack detection */
1173 if (cfg->hp_outs == i)
1174 type |= SND_JACK_LINEOUT;
1175 err = stac92xx_add_jack(codec, nid, type);
1176 if (err < 0)
1177 return err;
1180 for (i = 0; i < cfg->line_outs; i++) {
1181 err = stac92xx_add_jack(codec, cfg->line_out_pins[i],
1182 SND_JACK_LINEOUT);
1183 if (err < 0)
1184 return err;
1186 for (i = 0; i < AUTO_PIN_LAST; i++) {
1187 nid = cfg->input_pins[i];
1188 if (nid) {
1189 err = stac92xx_add_jack(codec, nid,
1190 SND_JACK_MICROPHONE);
1191 if (err < 0)
1192 return err;
1196 return 0;
1199 static unsigned int ref9200_pin_configs[8] = {
1200 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
1201 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
1204 static unsigned int gateway9200_m4_pin_configs[8] = {
1205 0x400000fe, 0x404500f4, 0x400100f0, 0x90110010,
1206 0x400100f1, 0x02a1902e, 0x500000f2, 0x500000f3,
1208 static unsigned int gateway9200_m4_2_pin_configs[8] = {
1209 0x400000fe, 0x404500f4, 0x400100f0, 0x90110010,
1210 0x400100f1, 0x02a1902e, 0x500000f2, 0x500000f3,
1214 STAC 9200 pin configs for
1215 102801A8
1216 102801DE
1217 102801E8
1219 static unsigned int dell9200_d21_pin_configs[8] = {
1220 0x400001f0, 0x400001f1, 0x02214030, 0x01014010,
1221 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
1225 STAC 9200 pin configs for
1226 102801C0
1227 102801C1
1229 static unsigned int dell9200_d22_pin_configs[8] = {
1230 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
1231 0x01813020, 0x02a19021, 0x90100140, 0x400001f2,
1235 STAC 9200 pin configs for
1236 102801C4 (Dell Dimension E310)
1237 102801C5
1238 102801C7
1239 102801D9
1240 102801DA
1241 102801E3
1243 static unsigned int dell9200_d23_pin_configs[8] = {
1244 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
1245 0x01813020, 0x01a19021, 0x90100140, 0x400001f2,
1250 STAC 9200-32 pin configs for
1251 102801B5 (Dell Inspiron 630m)
1252 102801D8 (Dell Inspiron 640m)
1254 static unsigned int dell9200_m21_pin_configs[8] = {
1255 0x40c003fa, 0x03441340, 0x0321121f, 0x90170310,
1256 0x408003fb, 0x03a11020, 0x401003fc, 0x403003fd,
1260 STAC 9200-32 pin configs for
1261 102801C2 (Dell Latitude D620)
1262 102801C8
1263 102801CC (Dell Latitude D820)
1264 102801D4
1265 102801D6
1267 static unsigned int dell9200_m22_pin_configs[8] = {
1268 0x40c003fa, 0x0144131f, 0x0321121f, 0x90170310,
1269 0x90a70321, 0x03a11020, 0x401003fb, 0x40f000fc,
1273 STAC 9200-32 pin configs for
1274 102801CE (Dell XPS M1710)
1275 102801CF (Dell Precision M90)
1277 static unsigned int dell9200_m23_pin_configs[8] = {
1278 0x40c003fa, 0x01441340, 0x0421421f, 0x90170310,
1279 0x408003fb, 0x04a1102e, 0x90170311, 0x403003fc,
1283 STAC 9200-32 pin configs for
1284 102801C9
1285 102801CA
1286 102801CB (Dell Latitude 120L)
1287 102801D3
1289 static unsigned int dell9200_m24_pin_configs[8] = {
1290 0x40c003fa, 0x404003fb, 0x0321121f, 0x90170310,
1291 0x408003fc, 0x03a11020, 0x401003fd, 0x403003fe,
1295 STAC 9200-32 pin configs for
1296 102801BD (Dell Inspiron E1505n)
1297 102801EE
1298 102801EF
1300 static unsigned int dell9200_m25_pin_configs[8] = {
1301 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
1302 0x408003fb, 0x04a11020, 0x401003fc, 0x403003fd,
1306 STAC 9200-32 pin configs for
1307 102801F5 (Dell Inspiron 1501)
1308 102801F6
1310 static unsigned int dell9200_m26_pin_configs[8] = {
1311 0x40c003fa, 0x404003fb, 0x0421121f, 0x90170310,
1312 0x408003fc, 0x04a11020, 0x401003fd, 0x403003fe,
1316 STAC 9200-32
1317 102801CD (Dell Inspiron E1705/9400)
1319 static unsigned int dell9200_m27_pin_configs[8] = {
1320 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
1321 0x90170310, 0x04a11020, 0x90170310, 0x40f003fc,
1324 static unsigned int oqo9200_pin_configs[8] = {
1325 0x40c000f0, 0x404000f1, 0x0221121f, 0x02211210,
1326 0x90170111, 0x90a70120, 0x400000f2, 0x400000f3,
1330 static unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
1331 [STAC_REF] = ref9200_pin_configs,
1332 [STAC_9200_OQO] = oqo9200_pin_configs,
1333 [STAC_9200_DELL_D21] = dell9200_d21_pin_configs,
1334 [STAC_9200_DELL_D22] = dell9200_d22_pin_configs,
1335 [STAC_9200_DELL_D23] = dell9200_d23_pin_configs,
1336 [STAC_9200_DELL_M21] = dell9200_m21_pin_configs,
1337 [STAC_9200_DELL_M22] = dell9200_m22_pin_configs,
1338 [STAC_9200_DELL_M23] = dell9200_m23_pin_configs,
1339 [STAC_9200_DELL_M24] = dell9200_m24_pin_configs,
1340 [STAC_9200_DELL_M25] = dell9200_m25_pin_configs,
1341 [STAC_9200_DELL_M26] = dell9200_m26_pin_configs,
1342 [STAC_9200_DELL_M27] = dell9200_m27_pin_configs,
1343 [STAC_9200_M4] = gateway9200_m4_pin_configs,
1344 [STAC_9200_M4_2] = gateway9200_m4_2_pin_configs,
1345 [STAC_9200_PANASONIC] = ref9200_pin_configs,
1348 static const char *stac9200_models[STAC_9200_MODELS] = {
1349 [STAC_AUTO] = "auto",
1350 [STAC_REF] = "ref",
1351 [STAC_9200_OQO] = "oqo",
1352 [STAC_9200_DELL_D21] = "dell-d21",
1353 [STAC_9200_DELL_D22] = "dell-d22",
1354 [STAC_9200_DELL_D23] = "dell-d23",
1355 [STAC_9200_DELL_M21] = "dell-m21",
1356 [STAC_9200_DELL_M22] = "dell-m22",
1357 [STAC_9200_DELL_M23] = "dell-m23",
1358 [STAC_9200_DELL_M24] = "dell-m24",
1359 [STAC_9200_DELL_M25] = "dell-m25",
1360 [STAC_9200_DELL_M26] = "dell-m26",
1361 [STAC_9200_DELL_M27] = "dell-m27",
1362 [STAC_9200_M4] = "gateway-m4",
1363 [STAC_9200_M4_2] = "gateway-m4-2",
1364 [STAC_9200_PANASONIC] = "panasonic",
1367 static struct snd_pci_quirk stac9200_cfg_tbl[] = {
1368 /* SigmaTel reference board */
1369 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1370 "DFI LanParty", STAC_REF),
1371 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1372 "DFI LanParty", STAC_REF),
1373 /* Dell laptops have BIOS problem */
1374 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a8,
1375 "unknown Dell", STAC_9200_DELL_D21),
1376 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01b5,
1377 "Dell Inspiron 630m", STAC_9200_DELL_M21),
1378 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bd,
1379 "Dell Inspiron E1505n", STAC_9200_DELL_M25),
1380 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c0,
1381 "unknown Dell", STAC_9200_DELL_D22),
1382 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c1,
1383 "unknown Dell", STAC_9200_DELL_D22),
1384 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c2,
1385 "Dell Latitude D620", STAC_9200_DELL_M22),
1386 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c5,
1387 "unknown Dell", STAC_9200_DELL_D23),
1388 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c7,
1389 "unknown Dell", STAC_9200_DELL_D23),
1390 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c8,
1391 "unknown Dell", STAC_9200_DELL_M22),
1392 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c9,
1393 "unknown Dell", STAC_9200_DELL_M24),
1394 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ca,
1395 "unknown Dell", STAC_9200_DELL_M24),
1396 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cb,
1397 "Dell Latitude 120L", STAC_9200_DELL_M24),
1398 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cc,
1399 "Dell Latitude D820", STAC_9200_DELL_M22),
1400 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cd,
1401 "Dell Inspiron E1705/9400", STAC_9200_DELL_M27),
1402 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ce,
1403 "Dell XPS M1710", STAC_9200_DELL_M23),
1404 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cf,
1405 "Dell Precision M90", STAC_9200_DELL_M23),
1406 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d3,
1407 "unknown Dell", STAC_9200_DELL_M22),
1408 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d4,
1409 "unknown Dell", STAC_9200_DELL_M22),
1410 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d6,
1411 "unknown Dell", STAC_9200_DELL_M22),
1412 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d8,
1413 "Dell Inspiron 640m", STAC_9200_DELL_M21),
1414 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d9,
1415 "unknown Dell", STAC_9200_DELL_D23),
1416 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01da,
1417 "unknown Dell", STAC_9200_DELL_D23),
1418 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01de,
1419 "unknown Dell", STAC_9200_DELL_D21),
1420 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e3,
1421 "unknown Dell", STAC_9200_DELL_D23),
1422 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e8,
1423 "unknown Dell", STAC_9200_DELL_D21),
1424 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ee,
1425 "unknown Dell", STAC_9200_DELL_M25),
1426 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ef,
1427 "unknown Dell", STAC_9200_DELL_M25),
1428 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f5,
1429 "Dell Inspiron 1501", STAC_9200_DELL_M26),
1430 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f6,
1431 "unknown Dell", STAC_9200_DELL_M26),
1432 /* Panasonic */
1433 SND_PCI_QUIRK(0x10f7, 0x8338, "Panasonic CF-74", STAC_9200_PANASONIC),
1434 /* Gateway machines needs EAPD to be set on resume */
1435 SND_PCI_QUIRK(0x107b, 0x0205, "Gateway S-7110M", STAC_9200_M4),
1436 SND_PCI_QUIRK(0x107b, 0x0317, "Gateway MT3423, MX341*", STAC_9200_M4_2),
1437 SND_PCI_QUIRK(0x107b, 0x0318, "Gateway ML3019, MT3707", STAC_9200_M4_2),
1438 /* OQO Mobile */
1439 SND_PCI_QUIRK(0x1106, 0x3288, "OQO Model 2", STAC_9200_OQO),
1440 {} /* terminator */
1443 static unsigned int ref925x_pin_configs[8] = {
1444 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
1445 0x90a70320, 0x02214210, 0x01019020, 0x9033032e,
1448 static unsigned int stac925xM1_pin_configs[8] = {
1449 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1450 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1453 static unsigned int stac925xM1_2_pin_configs[8] = {
1454 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1455 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1458 static unsigned int stac925xM2_pin_configs[8] = {
1459 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1460 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1463 static unsigned int stac925xM2_2_pin_configs[8] = {
1464 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1465 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1468 static unsigned int stac925xM3_pin_configs[8] = {
1469 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1470 0x40a000f0, 0x90100210, 0x400003f1, 0x503303f3,
1473 static unsigned int stac925xM5_pin_configs[8] = {
1474 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1475 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1478 static unsigned int stac925xM6_pin_configs[8] = {
1479 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1480 0x40a000f0, 0x90100210, 0x400003f1, 0x90330320,
1483 static unsigned int *stac925x_brd_tbl[STAC_925x_MODELS] = {
1484 [STAC_REF] = ref925x_pin_configs,
1485 [STAC_M1] = stac925xM1_pin_configs,
1486 [STAC_M1_2] = stac925xM1_2_pin_configs,
1487 [STAC_M2] = stac925xM2_pin_configs,
1488 [STAC_M2_2] = stac925xM2_2_pin_configs,
1489 [STAC_M3] = stac925xM3_pin_configs,
1490 [STAC_M5] = stac925xM5_pin_configs,
1491 [STAC_M6] = stac925xM6_pin_configs,
1494 static const char *stac925x_models[STAC_925x_MODELS] = {
1495 [STAC_925x_AUTO] = "auto",
1496 [STAC_REF] = "ref",
1497 [STAC_M1] = "m1",
1498 [STAC_M1_2] = "m1-2",
1499 [STAC_M2] = "m2",
1500 [STAC_M2_2] = "m2-2",
1501 [STAC_M3] = "m3",
1502 [STAC_M5] = "m5",
1503 [STAC_M6] = "m6",
1506 static struct snd_pci_quirk stac925x_codec_id_cfg_tbl[] = {
1507 SND_PCI_QUIRK(0x107b, 0x0316, "Gateway M255", STAC_M2),
1508 SND_PCI_QUIRK(0x107b, 0x0366, "Gateway MP6954", STAC_M5),
1509 SND_PCI_QUIRK(0x107b, 0x0461, "Gateway NX560XL", STAC_M1),
1510 SND_PCI_QUIRK(0x107b, 0x0681, "Gateway NX860", STAC_M2),
1511 SND_PCI_QUIRK(0x107b, 0x0367, "Gateway MX6453", STAC_M1_2),
1512 /* Not sure about the brand name for those */
1513 SND_PCI_QUIRK(0x107b, 0x0281, "Gateway mobile", STAC_M1),
1514 SND_PCI_QUIRK(0x107b, 0x0507, "Gateway mobile", STAC_M3),
1515 SND_PCI_QUIRK(0x107b, 0x0281, "Gateway mobile", STAC_M6),
1516 SND_PCI_QUIRK(0x107b, 0x0685, "Gateway mobile", STAC_M2_2),
1517 {} /* terminator */
1520 static struct snd_pci_quirk stac925x_cfg_tbl[] = {
1521 /* SigmaTel reference board */
1522 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, "DFI LanParty", STAC_REF),
1523 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101, "DFI LanParty", STAC_REF),
1524 SND_PCI_QUIRK(0x8384, 0x7632, "Stac9202 Reference Board", STAC_REF),
1526 /* Default table for unknown ID */
1527 SND_PCI_QUIRK(0x1002, 0x437b, "Gateway mobile", STAC_M2_2),
1529 {} /* terminator */
1532 static unsigned int ref92hd73xx_pin_configs[13] = {
1533 0x02214030, 0x02a19040, 0x01a19020, 0x02214030,
1534 0x0181302e, 0x01014010, 0x01014020, 0x01014030,
1535 0x02319040, 0x90a000f0, 0x90a000f0, 0x01452050,
1536 0x01452050,
1539 static unsigned int dell_m6_pin_configs[13] = {
1540 0x0321101f, 0x4f00000f, 0x4f0000f0, 0x90170110,
1541 0x03a11020, 0x0321101f, 0x4f0000f0, 0x4f0000f0,
1542 0x4f0000f0, 0x90a60160, 0x4f0000f0, 0x4f0000f0,
1543 0x4f0000f0,
1546 static unsigned int alienware_m17x_pin_configs[13] = {
1547 0x0321101f, 0x0321101f, 0x03a11020, 0x03014020,
1548 0x90170110, 0x4f0000f0, 0x4f0000f0, 0x4f0000f0,
1549 0x4f0000f0, 0x90a60160, 0x4f0000f0, 0x4f0000f0,
1550 0x904601b0,
1553 static unsigned int intel_dg45id_pin_configs[13] = {
1554 0x02214230, 0x02A19240, 0x01013214, 0x01014210,
1555 0x01A19250, 0x01011212, 0x01016211
1558 static unsigned int *stac92hd73xx_brd_tbl[STAC_92HD73XX_MODELS] = {
1559 [STAC_92HD73XX_REF] = ref92hd73xx_pin_configs,
1560 [STAC_DELL_M6_AMIC] = dell_m6_pin_configs,
1561 [STAC_DELL_M6_DMIC] = dell_m6_pin_configs,
1562 [STAC_DELL_M6_BOTH] = dell_m6_pin_configs,
1563 [STAC_DELL_EQ] = dell_m6_pin_configs,
1564 [STAC_ALIENWARE_M17X] = alienware_m17x_pin_configs,
1565 [STAC_92HD73XX_INTEL] = intel_dg45id_pin_configs,
1568 static const char *stac92hd73xx_models[STAC_92HD73XX_MODELS] = {
1569 [STAC_92HD73XX_AUTO] = "auto",
1570 [STAC_92HD73XX_NO_JD] = "no-jd",
1571 [STAC_92HD73XX_REF] = "ref",
1572 [STAC_92HD73XX_INTEL] = "intel",
1573 [STAC_DELL_M6_AMIC] = "dell-m6-amic",
1574 [STAC_DELL_M6_DMIC] = "dell-m6-dmic",
1575 [STAC_DELL_M6_BOTH] = "dell-m6",
1576 [STAC_DELL_EQ] = "dell-eq",
1577 [STAC_ALIENWARE_M17X] = "alienware",
1580 static struct snd_pci_quirk stac92hd73xx_cfg_tbl[] = {
1581 /* SigmaTel reference board */
1582 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1583 "DFI LanParty", STAC_92HD73XX_REF),
1584 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1585 "DFI LanParty", STAC_92HD73XX_REF),
1586 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5002,
1587 "Intel DG45ID", STAC_92HD73XX_INTEL),
1588 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5003,
1589 "Intel DG45FC", STAC_92HD73XX_INTEL),
1590 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0254,
1591 "Dell Studio 1535", STAC_DELL_M6_DMIC),
1592 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0255,
1593 "unknown Dell", STAC_DELL_M6_DMIC),
1594 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0256,
1595 "unknown Dell", STAC_DELL_M6_BOTH),
1596 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0257,
1597 "unknown Dell", STAC_DELL_M6_BOTH),
1598 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025e,
1599 "unknown Dell", STAC_DELL_M6_AMIC),
1600 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025f,
1601 "unknown Dell", STAC_DELL_M6_AMIC),
1602 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0271,
1603 "unknown Dell", STAC_DELL_M6_DMIC),
1604 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0272,
1605 "unknown Dell", STAC_DELL_M6_DMIC),
1606 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x029f,
1607 "Dell Studio 1537", STAC_DELL_M6_DMIC),
1608 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02a0,
1609 "Dell Studio 17", STAC_DELL_M6_DMIC),
1610 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02be,
1611 "Dell Studio 1555", STAC_DELL_M6_DMIC),
1612 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02bd,
1613 "Dell Studio 1557", STAC_DELL_M6_DMIC),
1614 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02fe,
1615 "Dell Studio XPS 1645", STAC_DELL_M6_BOTH),
1616 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0413,
1617 "Dell Studio 1558", STAC_DELL_M6_DMIC),
1618 {} /* terminator */
1621 static struct snd_pci_quirk stac92hd73xx_codec_id_cfg_tbl[] = {
1622 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02a1,
1623 "Alienware M17x", STAC_ALIENWARE_M17X),
1624 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x043a,
1625 "Alienware M17x", STAC_ALIENWARE_M17X),
1626 {} /* terminator */
1629 static unsigned int ref92hd83xxx_pin_configs[10] = {
1630 0x02214030, 0x02211010, 0x02a19020, 0x02170130,
1631 0x01014050, 0x01819040, 0x01014020, 0x90a3014e,
1632 0x01451160, 0x98560170,
1635 static unsigned int dell_s14_pin_configs[10] = {
1636 0x0221403f, 0x0221101f, 0x02a19020, 0x90170110,
1637 0x40f000f0, 0x40f000f0, 0x40f000f0, 0x90a60160,
1638 0x40f000f0, 0x40f000f0,
1641 static unsigned int *stac92hd83xxx_brd_tbl[STAC_92HD83XXX_MODELS] = {
1642 [STAC_92HD83XXX_REF] = ref92hd83xxx_pin_configs,
1643 [STAC_92HD83XXX_PWR_REF] = ref92hd83xxx_pin_configs,
1644 [STAC_DELL_S14] = dell_s14_pin_configs,
1647 static const char *stac92hd83xxx_models[STAC_92HD83XXX_MODELS] = {
1648 [STAC_92HD83XXX_AUTO] = "auto",
1649 [STAC_92HD83XXX_REF] = "ref",
1650 [STAC_92HD83XXX_PWR_REF] = "mic-ref",
1651 [STAC_DELL_S14] = "dell-s14",
1652 [STAC_92HD83XXX_HP] = "hp",
1655 static struct snd_pci_quirk stac92hd83xxx_cfg_tbl[] = {
1656 /* SigmaTel reference board */
1657 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1658 "DFI LanParty", STAC_92HD83XXX_REF),
1659 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1660 "DFI LanParty", STAC_92HD83XXX_REF),
1661 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ba,
1662 "unknown Dell", STAC_DELL_S14),
1663 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xff00, 0x3600,
1664 "HP", STAC_92HD83XXX_HP),
1665 {} /* terminator */
1668 static unsigned int ref92hd71bxx_pin_configs[STAC92HD71BXX_NUM_PINS] = {
1669 0x02214030, 0x02a19040, 0x01a19020, 0x01014010,
1670 0x0181302e, 0x01014010, 0x01019020, 0x90a000f0,
1671 0x90a000f0, 0x01452050, 0x01452050, 0x00000000,
1672 0x00000000
1675 static unsigned int dell_m4_1_pin_configs[STAC92HD71BXX_NUM_PINS] = {
1676 0x0421101f, 0x04a11221, 0x40f000f0, 0x90170110,
1677 0x23a1902e, 0x23014250, 0x40f000f0, 0x90a000f0,
1678 0x40f000f0, 0x4f0000f0, 0x4f0000f0, 0x00000000,
1679 0x00000000
1682 static unsigned int dell_m4_2_pin_configs[STAC92HD71BXX_NUM_PINS] = {
1683 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1684 0x23a1902e, 0x23014250, 0x40f000f0, 0x40f000f0,
1685 0x40f000f0, 0x044413b0, 0x044413b0, 0x00000000,
1686 0x00000000
1689 static unsigned int dell_m4_3_pin_configs[STAC92HD71BXX_NUM_PINS] = {
1690 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1691 0x40f000f0, 0x40f000f0, 0x40f000f0, 0x90a000f0,
1692 0x40f000f0, 0x044413b0, 0x044413b0, 0x00000000,
1693 0x00000000
1696 static unsigned int *stac92hd71bxx_brd_tbl[STAC_92HD71BXX_MODELS] = {
1697 [STAC_92HD71BXX_REF] = ref92hd71bxx_pin_configs,
1698 [STAC_DELL_M4_1] = dell_m4_1_pin_configs,
1699 [STAC_DELL_M4_2] = dell_m4_2_pin_configs,
1700 [STAC_DELL_M4_3] = dell_m4_3_pin_configs,
1701 [STAC_HP_M4] = NULL,
1702 [STAC_HP_DV4] = NULL,
1703 [STAC_HP_DV5] = NULL,
1704 [STAC_HP_HDX] = NULL,
1705 [STAC_HP_DV4_1222NR] = NULL,
1708 static const char *stac92hd71bxx_models[STAC_92HD71BXX_MODELS] = {
1709 [STAC_92HD71BXX_AUTO] = "auto",
1710 [STAC_92HD71BXX_REF] = "ref",
1711 [STAC_DELL_M4_1] = "dell-m4-1",
1712 [STAC_DELL_M4_2] = "dell-m4-2",
1713 [STAC_DELL_M4_3] = "dell-m4-3",
1714 [STAC_HP_M4] = "hp-m4",
1715 [STAC_HP_DV4] = "hp-dv4",
1716 [STAC_HP_DV5] = "hp-dv5",
1717 [STAC_HP_HDX] = "hp-hdx",
1718 [STAC_HP_DV4_1222NR] = "hp-dv4-1222nr",
1721 static struct snd_pci_quirk stac92hd71bxx_cfg_tbl[] = {
1722 /* SigmaTel reference board */
1723 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1724 "DFI LanParty", STAC_92HD71BXX_REF),
1725 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1726 "DFI LanParty", STAC_92HD71BXX_REF),
1727 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x30fb,
1728 "HP dv4-1222nr", STAC_HP_DV4_1222NR),
1729 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x1720,
1730 "HP", STAC_HP_DV5),
1731 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3080,
1732 "HP", STAC_HP_DV5),
1733 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x30f0,
1734 "HP dv4-7", STAC_HP_DV4),
1735 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3600,
1736 "HP dv4-7", STAC_HP_DV5),
1737 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3610,
1738 "HP HDX", STAC_HP_HDX), /* HDX18 */
1739 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361a,
1740 "HP mini 1000", STAC_HP_M4),
1741 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361b,
1742 "HP HDX", STAC_HP_HDX), /* HDX16 */
1743 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3620,
1744 "HP dv6", STAC_HP_DV5),
1745 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3061,
1746 "HP dv6", STAC_HP_DV5), /* HP dv6-1110ax */
1747 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x7010,
1748 "HP", STAC_HP_DV5),
1749 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0233,
1750 "unknown Dell", STAC_DELL_M4_1),
1751 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0234,
1752 "unknown Dell", STAC_DELL_M4_1),
1753 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0250,
1754 "unknown Dell", STAC_DELL_M4_1),
1755 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024f,
1756 "unknown Dell", STAC_DELL_M4_1),
1757 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024d,
1758 "unknown Dell", STAC_DELL_M4_1),
1759 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0251,
1760 "unknown Dell", STAC_DELL_M4_1),
1761 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0277,
1762 "unknown Dell", STAC_DELL_M4_1),
1763 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0263,
1764 "unknown Dell", STAC_DELL_M4_2),
1765 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0265,
1766 "unknown Dell", STAC_DELL_M4_2),
1767 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0262,
1768 "unknown Dell", STAC_DELL_M4_2),
1769 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0264,
1770 "unknown Dell", STAC_DELL_M4_2),
1771 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02aa,
1772 "unknown Dell", STAC_DELL_M4_3),
1773 {} /* terminator */
1776 static unsigned int ref922x_pin_configs[10] = {
1777 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
1778 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
1779 0x40000100, 0x40000100,
1783 STAC 922X pin configs for
1784 102801A7
1785 102801AB
1786 102801A9
1787 102801D1
1788 102801D2
1790 static unsigned int dell_922x_d81_pin_configs[10] = {
1791 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1792 0x02a19020, 0x01117011, 0x400001f0, 0x400001f1,
1793 0x01813122, 0x400001f2,
1797 STAC 922X pin configs for
1798 102801AC
1799 102801D0
1801 static unsigned int dell_922x_d82_pin_configs[10] = {
1802 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1803 0x02a19020, 0x01117011, 0x01451140, 0x400001f0,
1804 0x01813122, 0x400001f1,
1808 STAC 922X pin configs for
1809 102801BF
1811 static unsigned int dell_922x_m81_pin_configs[10] = {
1812 0x0321101f, 0x01112024, 0x01111222, 0x91174220,
1813 0x03a11050, 0x01116221, 0x90a70330, 0x01452340,
1814 0x40C003f1, 0x405003f0,
1818 STAC 9221 A1 pin configs for
1819 102801D7 (Dell XPS M1210)
1821 static unsigned int dell_922x_m82_pin_configs[10] = {
1822 0x02211211, 0x408103ff, 0x02a1123e, 0x90100310,
1823 0x408003f1, 0x0221121f, 0x03451340, 0x40c003f2,
1824 0x508003f3, 0x405003f4,
1827 static unsigned int d945gtp3_pin_configs[10] = {
1828 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
1829 0x40000100, 0x40000100, 0x40000100, 0x40000100,
1830 0x02a19120, 0x40000100,
1833 static unsigned int d945gtp5_pin_configs[10] = {
1834 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
1835 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
1836 0x02a19320, 0x40000100,
1839 static unsigned int intel_mac_v1_pin_configs[10] = {
1840 0x0121e21f, 0x400000ff, 0x9017e110, 0x400000fd,
1841 0x400000fe, 0x0181e020, 0x1145e030, 0x11c5e240,
1842 0x400000fc, 0x400000fb,
1845 static unsigned int intel_mac_v2_pin_configs[10] = {
1846 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
1847 0x400000fe, 0x0181e020, 0x1145e230, 0x500000fa,
1848 0x400000fc, 0x400000fb,
1851 static unsigned int intel_mac_v3_pin_configs[10] = {
1852 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
1853 0x400000fe, 0x0181e020, 0x1145e230, 0x11c5e240,
1854 0x400000fc, 0x400000fb,
1857 static unsigned int intel_mac_v4_pin_configs[10] = {
1858 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
1859 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
1860 0x400000fc, 0x400000fb,
1863 static unsigned int intel_mac_v5_pin_configs[10] = {
1864 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
1865 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
1866 0x400000fc, 0x400000fb,
1869 static unsigned int ecs202_pin_configs[10] = {
1870 0x0221401f, 0x02a19020, 0x01a19020, 0x01114010,
1871 0x408000f0, 0x01813022, 0x074510a0, 0x40c400f1,
1872 0x9037012e, 0x40e000f2,
1875 static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
1876 [STAC_D945_REF] = ref922x_pin_configs,
1877 [STAC_D945GTP3] = d945gtp3_pin_configs,
1878 [STAC_D945GTP5] = d945gtp5_pin_configs,
1879 [STAC_INTEL_MAC_V1] = intel_mac_v1_pin_configs,
1880 [STAC_INTEL_MAC_V2] = intel_mac_v2_pin_configs,
1881 [STAC_INTEL_MAC_V3] = intel_mac_v3_pin_configs,
1882 [STAC_INTEL_MAC_V4] = intel_mac_v4_pin_configs,
1883 [STAC_INTEL_MAC_V5] = intel_mac_v5_pin_configs,
1884 [STAC_INTEL_MAC_AUTO] = intel_mac_v3_pin_configs,
1885 /* for backward compatibility */
1886 [STAC_MACMINI] = intel_mac_v3_pin_configs,
1887 [STAC_MACBOOK] = intel_mac_v5_pin_configs,
1888 [STAC_MACBOOK_PRO_V1] = intel_mac_v3_pin_configs,
1889 [STAC_MACBOOK_PRO_V2] = intel_mac_v3_pin_configs,
1890 [STAC_IMAC_INTEL] = intel_mac_v2_pin_configs,
1891 [STAC_IMAC_INTEL_20] = intel_mac_v3_pin_configs,
1892 [STAC_ECS_202] = ecs202_pin_configs,
1893 [STAC_922X_DELL_D81] = dell_922x_d81_pin_configs,
1894 [STAC_922X_DELL_D82] = dell_922x_d82_pin_configs,
1895 [STAC_922X_DELL_M81] = dell_922x_m81_pin_configs,
1896 [STAC_922X_DELL_M82] = dell_922x_m82_pin_configs,
1899 static const char *stac922x_models[STAC_922X_MODELS] = {
1900 [STAC_922X_AUTO] = "auto",
1901 [STAC_D945_REF] = "ref",
1902 [STAC_D945GTP5] = "5stack",
1903 [STAC_D945GTP3] = "3stack",
1904 [STAC_INTEL_MAC_V1] = "intel-mac-v1",
1905 [STAC_INTEL_MAC_V2] = "intel-mac-v2",
1906 [STAC_INTEL_MAC_V3] = "intel-mac-v3",
1907 [STAC_INTEL_MAC_V4] = "intel-mac-v4",
1908 [STAC_INTEL_MAC_V5] = "intel-mac-v5",
1909 [STAC_INTEL_MAC_AUTO] = "intel-mac-auto",
1910 /* for backward compatibility */
1911 [STAC_MACMINI] = "macmini",
1912 [STAC_MACBOOK] = "macbook",
1913 [STAC_MACBOOK_PRO_V1] = "macbook-pro-v1",
1914 [STAC_MACBOOK_PRO_V2] = "macbook-pro",
1915 [STAC_IMAC_INTEL] = "imac-intel",
1916 [STAC_IMAC_INTEL_20] = "imac-intel-20",
1917 [STAC_ECS_202] = "ecs202",
1918 [STAC_922X_DELL_D81] = "dell-d81",
1919 [STAC_922X_DELL_D82] = "dell-d82",
1920 [STAC_922X_DELL_M81] = "dell-m81",
1921 [STAC_922X_DELL_M82] = "dell-m82",
1924 static struct snd_pci_quirk stac922x_cfg_tbl[] = {
1925 /* SigmaTel reference board */
1926 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1927 "DFI LanParty", STAC_D945_REF),
1928 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1929 "DFI LanParty", STAC_D945_REF),
1930 /* Intel 945G based systems */
1931 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101,
1932 "Intel D945G", STAC_D945GTP3),
1933 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0202,
1934 "Intel D945G", STAC_D945GTP3),
1935 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0606,
1936 "Intel D945G", STAC_D945GTP3),
1937 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0601,
1938 "Intel D945G", STAC_D945GTP3),
1939 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0111,
1940 "Intel D945G", STAC_D945GTP3),
1941 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1115,
1942 "Intel D945G", STAC_D945GTP3),
1943 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1116,
1944 "Intel D945G", STAC_D945GTP3),
1945 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1117,
1946 "Intel D945G", STAC_D945GTP3),
1947 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1118,
1948 "Intel D945G", STAC_D945GTP3),
1949 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1119,
1950 "Intel D945G", STAC_D945GTP3),
1951 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x8826,
1952 "Intel D945G", STAC_D945GTP3),
1953 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5049,
1954 "Intel D945G", STAC_D945GTP3),
1955 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5055,
1956 "Intel D945G", STAC_D945GTP3),
1957 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5048,
1958 "Intel D945G", STAC_D945GTP3),
1959 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0110,
1960 "Intel D945G", STAC_D945GTP3),
1961 /* Intel D945G 5-stack systems */
1962 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0404,
1963 "Intel D945G", STAC_D945GTP5),
1964 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0303,
1965 "Intel D945G", STAC_D945GTP5),
1966 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0013,
1967 "Intel D945G", STAC_D945GTP5),
1968 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0417,
1969 "Intel D945G", STAC_D945GTP5),
1970 /* Intel 945P based systems */
1971 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0b0b,
1972 "Intel D945P", STAC_D945GTP3),
1973 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0112,
1974 "Intel D945P", STAC_D945GTP3),
1975 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0d0d,
1976 "Intel D945P", STAC_D945GTP3),
1977 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0909,
1978 "Intel D945P", STAC_D945GTP3),
1979 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0505,
1980 "Intel D945P", STAC_D945GTP3),
1981 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707,
1982 "Intel D945P", STAC_D945GTP5),
1983 /* other intel */
1984 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0204,
1985 "Intel D945", STAC_D945_REF),
1986 /* other systems */
1987 /* Apple Intel Mac (Mac Mini, MacBook, MacBook Pro...) */
1988 SND_PCI_QUIRK(0x8384, 0x7680,
1989 "Mac", STAC_INTEL_MAC_AUTO),
1990 /* Dell systems */
1991 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a7,
1992 "unknown Dell", STAC_922X_DELL_D81),
1993 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a9,
1994 "unknown Dell", STAC_922X_DELL_D81),
1995 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ab,
1996 "unknown Dell", STAC_922X_DELL_D81),
1997 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ac,
1998 "unknown Dell", STAC_922X_DELL_D82),
1999 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bf,
2000 "unknown Dell", STAC_922X_DELL_M81),
2001 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d0,
2002 "unknown Dell", STAC_922X_DELL_D82),
2003 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d1,
2004 "unknown Dell", STAC_922X_DELL_D81),
2005 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d2,
2006 "unknown Dell", STAC_922X_DELL_D81),
2007 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d7,
2008 "Dell XPS M1210", STAC_922X_DELL_M82),
2009 /* ECS/PC Chips boards */
2010 SND_PCI_QUIRK_MASK(0x1019, 0xf000, 0x2000,
2011 "ECS/PC chips", STAC_ECS_202),
2012 {} /* terminator */
2015 static unsigned int ref927x_pin_configs[14] = {
2016 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2017 0x01a19040, 0x01011012, 0x01016011, 0x0101201f,
2018 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
2019 0x01c42190, 0x40000100,
2022 static unsigned int d965_3st_pin_configs[14] = {
2023 0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
2024 0x01a19021, 0x01813024, 0x40000100, 0x40000100,
2025 0x40000100, 0x40000100, 0x40000100, 0x40000100,
2026 0x40000100, 0x40000100
2029 static unsigned int d965_5st_pin_configs[14] = {
2030 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2031 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
2032 0x40000100, 0x40000100, 0x40000100, 0x01442070,
2033 0x40000100, 0x40000100
2036 static unsigned int d965_5st_no_fp_pin_configs[14] = {
2037 0x40000100, 0x40000100, 0x0181304e, 0x01014010,
2038 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
2039 0x40000100, 0x40000100, 0x40000100, 0x01442070,
2040 0x40000100, 0x40000100
2043 static unsigned int dell_3st_pin_configs[14] = {
2044 0x02211230, 0x02a11220, 0x01a19040, 0x01114210,
2045 0x01111212, 0x01116211, 0x01813050, 0x01112214,
2046 0x403003fa, 0x90a60040, 0x90a60040, 0x404003fb,
2047 0x40c003fc, 0x40000100
2050 static unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
2051 [STAC_D965_REF_NO_JD] = ref927x_pin_configs,
2052 [STAC_D965_REF] = ref927x_pin_configs,
2053 [STAC_D965_3ST] = d965_3st_pin_configs,
2054 [STAC_D965_5ST] = d965_5st_pin_configs,
2055 [STAC_D965_5ST_NO_FP] = d965_5st_no_fp_pin_configs,
2056 [STAC_DELL_3ST] = dell_3st_pin_configs,
2057 [STAC_DELL_BIOS] = NULL,
2058 [STAC_927X_VOLKNOB] = NULL,
2061 static const char *stac927x_models[STAC_927X_MODELS] = {
2062 [STAC_927X_AUTO] = "auto",
2063 [STAC_D965_REF_NO_JD] = "ref-no-jd",
2064 [STAC_D965_REF] = "ref",
2065 [STAC_D965_3ST] = "3stack",
2066 [STAC_D965_5ST] = "5stack",
2067 [STAC_D965_5ST_NO_FP] = "5stack-no-fp",
2068 [STAC_DELL_3ST] = "dell-3stack",
2069 [STAC_DELL_BIOS] = "dell-bios",
2070 [STAC_927X_VOLKNOB] = "volknob",
2073 static struct snd_pci_quirk stac927x_cfg_tbl[] = {
2074 /* SigmaTel reference board */
2075 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2076 "DFI LanParty", STAC_D965_REF),
2077 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2078 "DFI LanParty", STAC_D965_REF),
2079 /* Intel 946 based systems */
2080 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST),
2081 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST),
2082 /* 965 based 3 stack systems */
2083 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2100,
2084 "Intel D965", STAC_D965_3ST),
2085 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2000,
2086 "Intel D965", STAC_D965_3ST),
2087 /* Dell 3 stack systems */
2088 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01dd, "Dell Dimension E520", STAC_DELL_3ST),
2089 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ed, "Dell ", STAC_DELL_3ST),
2090 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f4, "Dell ", STAC_DELL_3ST),
2091 /* Dell 3 stack systems with verb table in BIOS */
2092 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f3, "Dell Inspiron 1420", STAC_DELL_BIOS),
2093 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f7, "Dell XPS M1730", STAC_DELL_BIOS),
2094 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0227, "Dell Vostro 1400 ", STAC_DELL_BIOS),
2095 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022e, "Dell ", STAC_DELL_BIOS),
2096 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022f, "Dell Inspiron 1525", STAC_DELL_BIOS),
2097 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0242, "Dell ", STAC_DELL_BIOS),
2098 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0243, "Dell ", STAC_DELL_BIOS),
2099 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ff, "Dell ", STAC_DELL_BIOS),
2100 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0209, "Dell XPS 1330", STAC_DELL_BIOS),
2101 /* 965 based 5 stack systems */
2102 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2300,
2103 "Intel D965", STAC_D965_5ST),
2104 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2500,
2105 "Intel D965", STAC_D965_5ST),
2106 /* volume-knob fixes */
2107 SND_PCI_QUIRK_VENDOR(0x10cf, "FSC", STAC_927X_VOLKNOB),
2108 {} /* terminator */
2111 static unsigned int ref9205_pin_configs[12] = {
2112 0x40000100, 0x40000100, 0x01016011, 0x01014010,
2113 0x01813122, 0x01a19021, 0x01019020, 0x40000100,
2114 0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
2118 STAC 9205 pin configs for
2119 102801F1
2120 102801F2
2121 102801FC
2122 102801FD
2123 10280204
2124 1028021F
2125 10280228 (Dell Vostro 1500)
2126 10280229 (Dell Vostro 1700)
2128 static unsigned int dell_9205_m42_pin_configs[12] = {
2129 0x0321101F, 0x03A11020, 0x400003FA, 0x90170310,
2130 0x400003FB, 0x400003FC, 0x400003FD, 0x40F000F9,
2131 0x90A60330, 0x400003FF, 0x0144131F, 0x40C003FE,
2135 STAC 9205 pin configs for
2136 102801F9
2137 102801FA
2138 102801FE
2139 102801FF (Dell Precision M4300)
2140 10280206
2141 10280200
2142 10280201
2144 static unsigned int dell_9205_m43_pin_configs[12] = {
2145 0x0321101f, 0x03a11020, 0x90a70330, 0x90170310,
2146 0x400000fe, 0x400000ff, 0x400000fd, 0x40f000f9,
2147 0x400000fa, 0x400000fc, 0x0144131f, 0x40c003f8,
2150 static unsigned int dell_9205_m44_pin_configs[12] = {
2151 0x0421101f, 0x04a11020, 0x400003fa, 0x90170310,
2152 0x400003fb, 0x400003fc, 0x400003fd, 0x400003f9,
2153 0x90a60330, 0x400003ff, 0x01441340, 0x40c003fe,
2156 static unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
2157 [STAC_9205_REF] = ref9205_pin_configs,
2158 [STAC_9205_DELL_M42] = dell_9205_m42_pin_configs,
2159 [STAC_9205_DELL_M43] = dell_9205_m43_pin_configs,
2160 [STAC_9205_DELL_M44] = dell_9205_m44_pin_configs,
2161 [STAC_9205_EAPD] = NULL,
2164 static const char *stac9205_models[STAC_9205_MODELS] = {
2165 [STAC_9205_AUTO] = "auto",
2166 [STAC_9205_REF] = "ref",
2167 [STAC_9205_DELL_M42] = "dell-m42",
2168 [STAC_9205_DELL_M43] = "dell-m43",
2169 [STAC_9205_DELL_M44] = "dell-m44",
2170 [STAC_9205_EAPD] = "eapd",
2173 static struct snd_pci_quirk stac9205_cfg_tbl[] = {
2174 /* SigmaTel reference board */
2175 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2176 "DFI LanParty", STAC_9205_REF),
2177 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xfb30,
2178 "SigmaTel", STAC_9205_REF),
2179 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2180 "DFI LanParty", STAC_9205_REF),
2181 /* Dell */
2182 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f1,
2183 "unknown Dell", STAC_9205_DELL_M42),
2184 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f2,
2185 "unknown Dell", STAC_9205_DELL_M42),
2186 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f8,
2187 "Dell Precision", STAC_9205_DELL_M43),
2188 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f9,
2189 "Dell Precision", STAC_9205_DELL_M43),
2190 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fa,
2191 "Dell Precision", STAC_9205_DELL_M43),
2192 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fc,
2193 "unknown Dell", STAC_9205_DELL_M42),
2194 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fd,
2195 "unknown Dell", STAC_9205_DELL_M42),
2196 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fe,
2197 "Dell Precision", STAC_9205_DELL_M43),
2198 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ff,
2199 "Dell Precision M4300", STAC_9205_DELL_M43),
2200 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0204,
2201 "unknown Dell", STAC_9205_DELL_M42),
2202 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0206,
2203 "Dell Precision", STAC_9205_DELL_M43),
2204 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021b,
2205 "Dell Precision", STAC_9205_DELL_M43),
2206 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021c,
2207 "Dell Precision", STAC_9205_DELL_M43),
2208 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021f,
2209 "Dell Inspiron", STAC_9205_DELL_M44),
2210 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0228,
2211 "Dell Vostro 1500", STAC_9205_DELL_M42),
2212 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0229,
2213 "Dell Vostro 1700", STAC_9205_DELL_M42),
2214 /* Gateway */
2215 SND_PCI_QUIRK(0x107b, 0x0560, "Gateway T6834c", STAC_9205_EAPD),
2216 SND_PCI_QUIRK(0x107b, 0x0565, "Gateway T1616", STAC_9205_EAPD),
2217 {} /* terminator */
2220 static void stac92xx_set_config_regs(struct hda_codec *codec,
2221 unsigned int *pincfgs)
2223 int i;
2224 struct sigmatel_spec *spec = codec->spec;
2226 if (!pincfgs)
2227 return;
2229 for (i = 0; i < spec->num_pins; i++)
2230 if (spec->pin_nids[i] && pincfgs[i])
2231 snd_hda_codec_set_pincfg(codec, spec->pin_nids[i],
2232 pincfgs[i]);
2236 * Analog playback callbacks
2238 static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
2239 struct hda_codec *codec,
2240 struct snd_pcm_substream *substream)
2242 struct sigmatel_spec *spec = codec->spec;
2243 if (spec->stream_delay)
2244 msleep(spec->stream_delay);
2245 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2246 hinfo);
2249 static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2250 struct hda_codec *codec,
2251 unsigned int stream_tag,
2252 unsigned int format,
2253 struct snd_pcm_substream *substream)
2255 struct sigmatel_spec *spec = codec->spec;
2256 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
2259 static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2260 struct hda_codec *codec,
2261 struct snd_pcm_substream *substream)
2263 struct sigmatel_spec *spec = codec->spec;
2264 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2268 * Digital playback callbacks
2270 static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2271 struct hda_codec *codec,
2272 struct snd_pcm_substream *substream)
2274 struct sigmatel_spec *spec = codec->spec;
2275 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2278 static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2279 struct hda_codec *codec,
2280 struct snd_pcm_substream *substream)
2282 struct sigmatel_spec *spec = codec->spec;
2283 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2286 static int stac92xx_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2287 struct hda_codec *codec,
2288 unsigned int stream_tag,
2289 unsigned int format,
2290 struct snd_pcm_substream *substream)
2292 struct sigmatel_spec *spec = codec->spec;
2293 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2294 stream_tag, format, substream);
2297 static int stac92xx_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2298 struct hda_codec *codec,
2299 struct snd_pcm_substream *substream)
2301 struct sigmatel_spec *spec = codec->spec;
2302 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2307 * Analog capture callbacks
2309 static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2310 struct hda_codec *codec,
2311 unsigned int stream_tag,
2312 unsigned int format,
2313 struct snd_pcm_substream *substream)
2315 struct sigmatel_spec *spec = codec->spec;
2316 hda_nid_t nid = spec->adc_nids[substream->number];
2318 if (spec->powerdown_adcs) {
2319 msleep(40);
2320 snd_hda_codec_write(codec, nid, 0,
2321 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
2323 snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format);
2324 return 0;
2327 static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2328 struct hda_codec *codec,
2329 struct snd_pcm_substream *substream)
2331 struct sigmatel_spec *spec = codec->spec;
2332 hda_nid_t nid = spec->adc_nids[substream->number];
2334 snd_hda_codec_cleanup_stream(codec, nid);
2335 if (spec->powerdown_adcs)
2336 snd_hda_codec_write(codec, nid, 0,
2337 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
2338 return 0;
2341 static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
2342 .substreams = 1,
2343 .channels_min = 2,
2344 .channels_max = 2,
2345 /* NID is set in stac92xx_build_pcms */
2346 .ops = {
2347 .open = stac92xx_dig_playback_pcm_open,
2348 .close = stac92xx_dig_playback_pcm_close,
2349 .prepare = stac92xx_dig_playback_pcm_prepare,
2350 .cleanup = stac92xx_dig_playback_pcm_cleanup
2354 static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
2355 .substreams = 1,
2356 .channels_min = 2,
2357 .channels_max = 2,
2358 /* NID is set in stac92xx_build_pcms */
2361 static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
2362 .substreams = 1,
2363 .channels_min = 2,
2364 .channels_max = 8,
2365 .nid = 0x02, /* NID to query formats and rates */
2366 .ops = {
2367 .open = stac92xx_playback_pcm_open,
2368 .prepare = stac92xx_playback_pcm_prepare,
2369 .cleanup = stac92xx_playback_pcm_cleanup
2373 static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
2374 .substreams = 1,
2375 .channels_min = 2,
2376 .channels_max = 2,
2377 .nid = 0x06, /* NID to query formats and rates */
2378 .ops = {
2379 .open = stac92xx_playback_pcm_open,
2380 .prepare = stac92xx_playback_pcm_prepare,
2381 .cleanup = stac92xx_playback_pcm_cleanup
2385 static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
2386 .channels_min = 2,
2387 .channels_max = 2,
2388 /* NID + .substreams is set in stac92xx_build_pcms */
2389 .ops = {
2390 .prepare = stac92xx_capture_pcm_prepare,
2391 .cleanup = stac92xx_capture_pcm_cleanup
2395 static int stac92xx_build_pcms(struct hda_codec *codec)
2397 struct sigmatel_spec *spec = codec->spec;
2398 struct hda_pcm *info = spec->pcm_rec;
2400 codec->num_pcms = 1;
2401 codec->pcm_info = info;
2403 info->name = "STAC92xx Analog";
2404 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
2405 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2406 spec->multiout.dac_nids[0];
2407 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
2408 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2409 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adcs;
2411 if (spec->alt_switch) {
2412 codec->num_pcms++;
2413 info++;
2414 info->name = "STAC92xx Analog Alt";
2415 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
2418 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2419 codec->num_pcms++;
2420 info++;
2421 info->name = "STAC92xx Digital";
2422 info->pcm_type = spec->autocfg.dig_out_type[0];
2423 if (spec->multiout.dig_out_nid) {
2424 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
2425 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2427 if (spec->dig_in_nid) {
2428 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
2429 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2433 return 0;
2436 static unsigned int stac92xx_get_default_vref(struct hda_codec *codec,
2437 hda_nid_t nid)
2439 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2440 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
2441 if (pincap & AC_PINCAP_VREF_100)
2442 return AC_PINCTL_VREF_100;
2443 if (pincap & AC_PINCAP_VREF_80)
2444 return AC_PINCTL_VREF_80;
2445 if (pincap & AC_PINCAP_VREF_50)
2446 return AC_PINCTL_VREF_50;
2447 if (pincap & AC_PINCAP_VREF_GRD)
2448 return AC_PINCTL_VREF_GRD;
2449 return 0;
2452 static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
2455 snd_hda_codec_write_cache(codec, nid, 0,
2456 AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
2459 #define stac92xx_hp_switch_info snd_ctl_boolean_mono_info
2461 static int stac92xx_hp_switch_get(struct snd_kcontrol *kcontrol,
2462 struct snd_ctl_elem_value *ucontrol)
2464 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2465 struct sigmatel_spec *spec = codec->spec;
2467 ucontrol->value.integer.value[0] = !!spec->hp_switch;
2468 return 0;
2471 static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid);
2473 static int stac92xx_hp_switch_put(struct snd_kcontrol *kcontrol,
2474 struct snd_ctl_elem_value *ucontrol)
2476 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2477 struct sigmatel_spec *spec = codec->spec;
2478 int nid = kcontrol->private_value;
2480 spec->hp_switch = ucontrol->value.integer.value[0] ? nid : 0;
2482 /* check to be sure that the ports are upto date with
2483 * switch changes
2485 stac_issue_unsol_event(codec, nid);
2487 return 1;
2490 static int stac92xx_dc_bias_info(struct snd_kcontrol *kcontrol,
2491 struct snd_ctl_elem_info *uinfo)
2493 int i;
2494 static char *texts[] = {
2495 "Mic In", "Line In", "Line Out"
2498 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2499 struct sigmatel_spec *spec = codec->spec;
2500 hda_nid_t nid = kcontrol->private_value;
2502 if (nid == spec->mic_switch || nid == spec->line_switch)
2503 i = 3;
2504 else
2505 i = 2;
2507 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2508 uinfo->value.enumerated.items = i;
2509 uinfo->count = 1;
2510 if (uinfo->value.enumerated.item >= i)
2511 uinfo->value.enumerated.item = i-1;
2512 strcpy(uinfo->value.enumerated.name,
2513 texts[uinfo->value.enumerated.item]);
2515 return 0;
2518 static int stac92xx_dc_bias_get(struct snd_kcontrol *kcontrol,
2519 struct snd_ctl_elem_value *ucontrol)
2521 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2522 hda_nid_t nid = kcontrol->private_value;
2523 unsigned int vref = stac92xx_vref_get(codec, nid);
2525 if (vref == stac92xx_get_default_vref(codec, nid))
2526 ucontrol->value.enumerated.item[0] = 0;
2527 else if (vref == AC_PINCTL_VREF_GRD)
2528 ucontrol->value.enumerated.item[0] = 1;
2529 else if (vref == AC_PINCTL_VREF_HIZ)
2530 ucontrol->value.enumerated.item[0] = 2;
2532 return 0;
2535 static int stac92xx_dc_bias_put(struct snd_kcontrol *kcontrol,
2536 struct snd_ctl_elem_value *ucontrol)
2538 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2539 unsigned int new_vref = 0;
2540 int error;
2541 hda_nid_t nid = kcontrol->private_value;
2543 if (ucontrol->value.enumerated.item[0] == 0)
2544 new_vref = stac92xx_get_default_vref(codec, nid);
2545 else if (ucontrol->value.enumerated.item[0] == 1)
2546 new_vref = AC_PINCTL_VREF_GRD;
2547 else if (ucontrol->value.enumerated.item[0] == 2)
2548 new_vref = AC_PINCTL_VREF_HIZ;
2549 else
2550 return 0;
2552 if (new_vref != stac92xx_vref_get(codec, nid)) {
2553 error = stac92xx_vref_set(codec, nid, new_vref);
2554 return error;
2557 return 0;
2560 static int stac92xx_io_switch_info(struct snd_kcontrol *kcontrol,
2561 struct snd_ctl_elem_info *uinfo)
2563 static char *texts[2];
2564 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2565 struct sigmatel_spec *spec = codec->spec;
2567 if (kcontrol->private_value == spec->line_switch)
2568 texts[0] = "Line In";
2569 else
2570 texts[0] = "Mic In";
2571 texts[1] = "Line Out";
2572 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2573 uinfo->value.enumerated.items = 2;
2574 uinfo->count = 1;
2576 if (uinfo->value.enumerated.item >= 2)
2577 uinfo->value.enumerated.item = 1;
2578 strcpy(uinfo->value.enumerated.name,
2579 texts[uinfo->value.enumerated.item]);
2581 return 0;
2584 static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2586 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2587 struct sigmatel_spec *spec = codec->spec;
2588 hda_nid_t nid = kcontrol->private_value;
2589 int io_idx = (nid == spec->mic_switch) ? 1 : 0;
2591 ucontrol->value.enumerated.item[0] = spec->io_switch[io_idx];
2592 return 0;
2595 static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2597 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2598 struct sigmatel_spec *spec = codec->spec;
2599 hda_nid_t nid = kcontrol->private_value;
2600 int io_idx = (nid == spec->mic_switch) ? 1 : 0;
2601 unsigned short val = !!ucontrol->value.enumerated.item[0];
2603 spec->io_switch[io_idx] = val;
2605 if (val)
2606 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
2607 else {
2608 unsigned int pinctl = AC_PINCTL_IN_EN;
2609 if (io_idx) /* set VREF for mic */
2610 pinctl |= stac92xx_get_default_vref(codec, nid);
2611 stac92xx_auto_set_pinctl(codec, nid, pinctl);
2614 /* check the auto-mute again: we need to mute/unmute the speaker
2615 * appropriately according to the pin direction
2617 if (spec->hp_detect)
2618 stac_issue_unsol_event(codec, nid);
2620 return 1;
2623 #define stac92xx_clfe_switch_info snd_ctl_boolean_mono_info
2625 static int stac92xx_clfe_switch_get(struct snd_kcontrol *kcontrol,
2626 struct snd_ctl_elem_value *ucontrol)
2628 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2629 struct sigmatel_spec *spec = codec->spec;
2631 ucontrol->value.integer.value[0] = spec->clfe_swap;
2632 return 0;
2635 static int stac92xx_clfe_switch_put(struct snd_kcontrol *kcontrol,
2636 struct snd_ctl_elem_value *ucontrol)
2638 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2639 struct sigmatel_spec *spec = codec->spec;
2640 hda_nid_t nid = kcontrol->private_value & 0xff;
2641 unsigned int val = !!ucontrol->value.integer.value[0];
2643 if (spec->clfe_swap == val)
2644 return 0;
2646 spec->clfe_swap = val;
2648 snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
2649 spec->clfe_swap ? 0x4 : 0x0);
2651 return 1;
2654 #define STAC_CODEC_HP_SWITCH(xname) \
2655 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2656 .name = xname, \
2657 .index = 0, \
2658 .info = stac92xx_hp_switch_info, \
2659 .get = stac92xx_hp_switch_get, \
2660 .put = stac92xx_hp_switch_put, \
2663 #define STAC_CODEC_IO_SWITCH(xname, xpval) \
2664 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2665 .name = xname, \
2666 .index = 0, \
2667 .info = stac92xx_io_switch_info, \
2668 .get = stac92xx_io_switch_get, \
2669 .put = stac92xx_io_switch_put, \
2670 .private_value = xpval, \
2673 #define STAC_CODEC_CLFE_SWITCH(xname, xpval) \
2674 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2675 .name = xname, \
2676 .index = 0, \
2677 .info = stac92xx_clfe_switch_info, \
2678 .get = stac92xx_clfe_switch_get, \
2679 .put = stac92xx_clfe_switch_put, \
2680 .private_value = xpval, \
2683 enum {
2684 STAC_CTL_WIDGET_VOL,
2685 STAC_CTL_WIDGET_MUTE,
2686 STAC_CTL_WIDGET_MUTE_BEEP,
2687 STAC_CTL_WIDGET_MONO_MUX,
2688 STAC_CTL_WIDGET_HP_SWITCH,
2689 STAC_CTL_WIDGET_IO_SWITCH,
2690 STAC_CTL_WIDGET_CLFE_SWITCH,
2691 STAC_CTL_WIDGET_DC_BIAS
2694 static struct snd_kcontrol_new stac92xx_control_templates[] = {
2695 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2696 HDA_CODEC_MUTE(NULL, 0, 0, 0),
2697 HDA_CODEC_MUTE_BEEP(NULL, 0, 0, 0),
2698 STAC_MONO_MUX,
2699 STAC_CODEC_HP_SWITCH(NULL),
2700 STAC_CODEC_IO_SWITCH(NULL, 0),
2701 STAC_CODEC_CLFE_SWITCH(NULL, 0),
2702 DC_BIAS(NULL, 0, 0),
2705 /* add dynamic controls */
2706 static struct snd_kcontrol_new *
2707 stac_control_new(struct sigmatel_spec *spec,
2708 struct snd_kcontrol_new *ktemp,
2709 const char *name,
2710 unsigned int subdev)
2712 struct snd_kcontrol_new *knew;
2714 snd_array_init(&spec->kctls, sizeof(*knew), 32);
2715 knew = snd_array_new(&spec->kctls);
2716 if (!knew)
2717 return NULL;
2718 *knew = *ktemp;
2719 knew->name = kstrdup(name, GFP_KERNEL);
2720 if (!knew->name) {
2721 /* roolback */
2722 memset(knew, 0, sizeof(*knew));
2723 spec->kctls.alloced--;
2724 return NULL;
2726 knew->subdevice = subdev;
2727 return knew;
2730 static int stac92xx_add_control_temp(struct sigmatel_spec *spec,
2731 struct snd_kcontrol_new *ktemp,
2732 int idx, const char *name,
2733 unsigned long val)
2735 struct snd_kcontrol_new *knew = stac_control_new(spec, ktemp, name,
2736 HDA_SUBDEV_AMP_FLAG);
2737 if (!knew)
2738 return -ENOMEM;
2739 knew->index = idx;
2740 knew->private_value = val;
2741 return 0;
2744 static inline int stac92xx_add_control_idx(struct sigmatel_spec *spec,
2745 int type, int idx, const char *name,
2746 unsigned long val)
2748 return stac92xx_add_control_temp(spec,
2749 &stac92xx_control_templates[type],
2750 idx, name, val);
2754 /* add dynamic controls */
2755 static inline int stac92xx_add_control(struct sigmatel_spec *spec, int type,
2756 const char *name, unsigned long val)
2758 return stac92xx_add_control_idx(spec, type, 0, name, val);
2761 static struct snd_kcontrol_new stac_input_src_temp = {
2762 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2763 .name = "Input Source",
2764 .info = stac92xx_mux_enum_info,
2765 .get = stac92xx_mux_enum_get,
2766 .put = stac92xx_mux_enum_put,
2769 static inline int stac92xx_add_jack_mode_control(struct hda_codec *codec,
2770 hda_nid_t nid, int idx)
2772 int def_conf = snd_hda_codec_get_pincfg(codec, nid);
2773 int control = 0;
2774 struct sigmatel_spec *spec = codec->spec;
2775 char name[22];
2777 if (!((get_defcfg_connect(def_conf)) & AC_JACK_PORT_FIXED)) {
2778 if (stac92xx_get_default_vref(codec, nid) == AC_PINCTL_VREF_GRD
2779 && nid == spec->line_switch)
2780 control = STAC_CTL_WIDGET_IO_SWITCH;
2781 else if (snd_hda_query_pin_caps(codec, nid)
2782 & (AC_PINCAP_VREF_GRD << AC_PINCAP_VREF_SHIFT))
2783 control = STAC_CTL_WIDGET_DC_BIAS;
2784 else if (nid == spec->mic_switch)
2785 control = STAC_CTL_WIDGET_IO_SWITCH;
2788 if (control) {
2789 strcpy(name, auto_pin_cfg_labels[idx]);
2790 return stac92xx_add_control(codec->spec, control,
2791 strcat(name, " Jack Mode"), nid);
2794 return 0;
2797 static int stac92xx_add_input_source(struct sigmatel_spec *spec)
2799 struct snd_kcontrol_new *knew;
2800 struct hda_input_mux *imux = &spec->private_imux;
2802 if (spec->auto_mic)
2803 return 0; /* no need for input source */
2804 if (!spec->num_adcs || imux->num_items <= 1)
2805 return 0; /* no need for input source control */
2806 knew = stac_control_new(spec, &stac_input_src_temp,
2807 stac_input_src_temp.name, 0);
2808 if (!knew)
2809 return -ENOMEM;
2810 knew->count = spec->num_adcs;
2811 return 0;
2814 /* check whether the line-input can be used as line-out */
2815 static hda_nid_t check_line_out_switch(struct hda_codec *codec)
2817 struct sigmatel_spec *spec = codec->spec;
2818 struct auto_pin_cfg *cfg = &spec->autocfg;
2819 hda_nid_t nid;
2820 unsigned int pincap;
2822 if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
2823 return 0;
2824 nid = cfg->input_pins[AUTO_PIN_LINE];
2825 pincap = snd_hda_query_pin_caps(codec, nid);
2826 if (pincap & AC_PINCAP_OUT)
2827 return nid;
2828 return 0;
2831 /* check whether the mic-input can be used as line-out */
2832 static hda_nid_t check_mic_out_switch(struct hda_codec *codec)
2834 struct sigmatel_spec *spec = codec->spec;
2835 struct auto_pin_cfg *cfg = &spec->autocfg;
2836 unsigned int def_conf, pincap;
2837 unsigned int mic_pin;
2839 if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
2840 return 0;
2841 mic_pin = AUTO_PIN_MIC;
2842 for (;;) {
2843 hda_nid_t nid = cfg->input_pins[mic_pin];
2844 def_conf = snd_hda_codec_get_pincfg(codec, nid);
2845 /* some laptops have an internal analog microphone
2846 * which can't be used as a output */
2847 if (get_defcfg_connect(def_conf) != AC_JACK_PORT_FIXED) {
2848 pincap = snd_hda_query_pin_caps(codec, nid);
2849 if (pincap & AC_PINCAP_OUT)
2850 return nid;
2852 if (mic_pin == AUTO_PIN_MIC)
2853 mic_pin = AUTO_PIN_FRONT_MIC;
2854 else
2855 break;
2857 return 0;
2860 static int is_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2862 int i;
2864 for (i = 0; i < spec->multiout.num_dacs; i++) {
2865 if (spec->multiout.dac_nids[i] == nid)
2866 return 1;
2869 return 0;
2872 static int check_all_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2874 int i;
2875 if (is_in_dac_nids(spec, nid))
2876 return 1;
2877 for (i = 0; i < spec->autocfg.hp_outs; i++)
2878 if (spec->hp_dacs[i] == nid)
2879 return 1;
2880 for (i = 0; i < spec->autocfg.speaker_outs; i++)
2881 if (spec->speaker_dacs[i] == nid)
2882 return 1;
2883 return 0;
2886 static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t nid)
2888 struct sigmatel_spec *spec = codec->spec;
2889 int j, conn_len;
2890 hda_nid_t conn[HDA_MAX_CONNECTIONS];
2891 unsigned int wcaps, wtype;
2893 conn_len = snd_hda_get_connections(codec, nid, conn,
2894 HDA_MAX_CONNECTIONS);
2895 /* 92HD88: trace back up the link of nids to find the DAC */
2896 while (conn_len == 1 && (get_wcaps_type(get_wcaps(codec, conn[0]))
2897 != AC_WID_AUD_OUT)) {
2898 nid = conn[0];
2899 conn_len = snd_hda_get_connections(codec, nid, conn,
2900 HDA_MAX_CONNECTIONS);
2902 for (j = 0; j < conn_len; j++) {
2903 wcaps = get_wcaps(codec, conn[j]);
2904 wtype = get_wcaps_type(wcaps);
2905 /* we check only analog outputs */
2906 if (wtype != AC_WID_AUD_OUT || (wcaps & AC_WCAP_DIGITAL))
2907 continue;
2908 /* if this route has a free DAC, assign it */
2909 if (!check_all_dac_nids(spec, conn[j])) {
2910 if (conn_len > 1) {
2911 /* select this DAC in the pin's input mux */
2912 snd_hda_codec_write_cache(codec, nid, 0,
2913 AC_VERB_SET_CONNECT_SEL, j);
2915 return conn[j];
2918 /* if all DACs are already assigned, connect to the primary DAC */
2919 if (conn_len > 1) {
2920 for (j = 0; j < conn_len; j++) {
2921 if (conn[j] == spec->multiout.dac_nids[0]) {
2922 snd_hda_codec_write_cache(codec, nid, 0,
2923 AC_VERB_SET_CONNECT_SEL, j);
2924 break;
2928 return 0;
2931 static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid);
2932 static int add_spec_extra_dacs(struct sigmatel_spec *spec, hda_nid_t nid);
2935 * Fill in the dac_nids table from the parsed pin configuration
2936 * This function only works when every pin in line_out_pins[]
2937 * contains atleast one DAC in its connection list. Some 92xx
2938 * codecs are not connected directly to a DAC, such as the 9200
2939 * and 9202/925x. For those, dac_nids[] must be hard-coded.
2941 static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec)
2943 struct sigmatel_spec *spec = codec->spec;
2944 struct auto_pin_cfg *cfg = &spec->autocfg;
2945 int i;
2946 hda_nid_t nid, dac;
2948 for (i = 0; i < cfg->line_outs; i++) {
2949 nid = cfg->line_out_pins[i];
2950 dac = get_unassigned_dac(codec, nid);
2951 if (!dac) {
2952 if (spec->multiout.num_dacs > 0) {
2953 /* we have already working output pins,
2954 * so let's drop the broken ones again
2956 cfg->line_outs = spec->multiout.num_dacs;
2957 break;
2959 /* error out, no available DAC found */
2960 snd_printk(KERN_ERR
2961 "%s: No available DAC for pin 0x%x\n",
2962 __func__, nid);
2963 return -ENODEV;
2965 add_spec_dacs(spec, dac);
2968 for (i = 0; i < cfg->hp_outs; i++) {
2969 nid = cfg->hp_pins[i];
2970 dac = get_unassigned_dac(codec, nid);
2971 if (dac) {
2972 if (!spec->multiout.hp_nid)
2973 spec->multiout.hp_nid = dac;
2974 else
2975 add_spec_extra_dacs(spec, dac);
2977 spec->hp_dacs[i] = dac;
2980 for (i = 0; i < cfg->speaker_outs; i++) {
2981 nid = cfg->speaker_pins[i];
2982 dac = get_unassigned_dac(codec, nid);
2983 if (dac)
2984 add_spec_extra_dacs(spec, dac);
2985 spec->speaker_dacs[i] = dac;
2988 /* add line-in as output */
2989 nid = check_line_out_switch(codec);
2990 if (nid) {
2991 dac = get_unassigned_dac(codec, nid);
2992 if (dac) {
2993 snd_printdd("STAC: Add line-in 0x%x as output %d\n",
2994 nid, cfg->line_outs);
2995 cfg->line_out_pins[cfg->line_outs] = nid;
2996 cfg->line_outs++;
2997 spec->line_switch = nid;
2998 add_spec_dacs(spec, dac);
3001 /* add mic as output */
3002 nid = check_mic_out_switch(codec);
3003 if (nid) {
3004 dac = get_unassigned_dac(codec, nid);
3005 if (dac) {
3006 snd_printdd("STAC: Add mic-in 0x%x as output %d\n",
3007 nid, cfg->line_outs);
3008 cfg->line_out_pins[cfg->line_outs] = nid;
3009 cfg->line_outs++;
3010 spec->mic_switch = nid;
3011 add_spec_dacs(spec, dac);
3015 snd_printd("stac92xx: dac_nids=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
3016 spec->multiout.num_dacs,
3017 spec->multiout.dac_nids[0],
3018 spec->multiout.dac_nids[1],
3019 spec->multiout.dac_nids[2],
3020 spec->multiout.dac_nids[3],
3021 spec->multiout.dac_nids[4]);
3023 return 0;
3026 /* create volume control/switch for the given prefx type */
3027 static int create_controls_idx(struct hda_codec *codec, const char *pfx,
3028 int idx, hda_nid_t nid, int chs)
3030 struct sigmatel_spec *spec = codec->spec;
3031 char name[32];
3032 int err;
3034 if (!spec->check_volume_offset) {
3035 unsigned int caps, step, nums, db_scale;
3036 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3037 step = (caps & AC_AMPCAP_STEP_SIZE) >>
3038 AC_AMPCAP_STEP_SIZE_SHIFT;
3039 step = (step + 1) * 25; /* in .01dB unit */
3040 nums = (caps & AC_AMPCAP_NUM_STEPS) >>
3041 AC_AMPCAP_NUM_STEPS_SHIFT;
3042 db_scale = nums * step;
3043 /* if dB scale is over -64dB, and finer enough,
3044 * let's reduce it to half
3046 if (db_scale > 6400 && nums >= 0x1f)
3047 spec->volume_offset = nums / 2;
3048 spec->check_volume_offset = 1;
3051 sprintf(name, "%s Playback Volume", pfx);
3052 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_VOL, idx, name,
3053 HDA_COMPOSE_AMP_VAL_OFS(nid, chs, 0, HDA_OUTPUT,
3054 spec->volume_offset));
3055 if (err < 0)
3056 return err;
3057 sprintf(name, "%s Playback Switch", pfx);
3058 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_MUTE, idx, name,
3059 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
3060 if (err < 0)
3061 return err;
3062 return 0;
3065 #define create_controls(codec, pfx, nid, chs) \
3066 create_controls_idx(codec, pfx, 0, nid, chs)
3068 static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
3070 if (spec->multiout.num_dacs > 4) {
3071 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
3072 return 1;
3073 } else {
3074 spec->multiout.dac_nids[spec->multiout.num_dacs] = nid;
3075 spec->multiout.num_dacs++;
3077 return 0;
3080 static int add_spec_extra_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
3082 int i;
3083 for (i = 0; i < ARRAY_SIZE(spec->multiout.extra_out_nid); i++) {
3084 if (!spec->multiout.extra_out_nid[i]) {
3085 spec->multiout.extra_out_nid[i] = nid;
3086 return 0;
3089 printk(KERN_WARNING "stac92xx: No space for extra DAC 0x%x\n", nid);
3090 return 1;
3093 /* Create output controls
3094 * The mixer elements are named depending on the given type (AUTO_PIN_XXX_OUT)
3096 static int create_multi_out_ctls(struct hda_codec *codec, int num_outs,
3097 const hda_nid_t *pins,
3098 const hda_nid_t *dac_nids,
3099 int type)
3101 struct sigmatel_spec *spec = codec->spec;
3102 static const char *chname[4] = {
3103 "Front", "Surround", NULL /*CLFE*/, "Side"
3105 hda_nid_t nid;
3106 int i, err;
3107 unsigned int wid_caps;
3109 for (i = 0; i < num_outs && i < ARRAY_SIZE(chname); i++) {
3110 if (type == AUTO_PIN_HP_OUT && !spec->hp_detect) {
3111 wid_caps = get_wcaps(codec, pins[i]);
3112 if (wid_caps & AC_WCAP_UNSOL_CAP)
3113 spec->hp_detect = 1;
3115 nid = dac_nids[i];
3116 if (!nid)
3117 continue;
3118 if (type != AUTO_PIN_HP_OUT && i == 2) {
3119 /* Center/LFE */
3120 err = create_controls(codec, "Center", nid, 1);
3121 if (err < 0)
3122 return err;
3123 err = create_controls(codec, "LFE", nid, 2);
3124 if (err < 0)
3125 return err;
3127 wid_caps = get_wcaps(codec, nid);
3129 if (wid_caps & AC_WCAP_LR_SWAP) {
3130 err = stac92xx_add_control(spec,
3131 STAC_CTL_WIDGET_CLFE_SWITCH,
3132 "Swap Center/LFE Playback Switch", nid);
3134 if (err < 0)
3135 return err;
3138 } else {
3139 const char *name;
3140 int idx;
3141 switch (type) {
3142 case AUTO_PIN_HP_OUT:
3143 name = "Headphone";
3144 idx = i;
3145 break;
3146 case AUTO_PIN_SPEAKER_OUT:
3147 name = "Speaker";
3148 idx = i;
3149 break;
3150 default:
3151 name = chname[i];
3152 idx = 0;
3153 break;
3155 err = create_controls_idx(codec, name, idx, nid, 3);
3156 if (err < 0)
3157 return err;
3160 return 0;
3163 static int stac92xx_add_capvol_ctls(struct hda_codec *codec, unsigned long vol,
3164 unsigned long sw, int idx)
3166 int err;
3167 err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_VOL, idx,
3168 "Capture Volume", vol);
3169 if (err < 0)
3170 return err;
3171 err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_MUTE, idx,
3172 "Capture Switch", sw);
3173 if (err < 0)
3174 return err;
3175 return 0;
3178 /* add playback controls from the parsed DAC table */
3179 static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
3180 const struct auto_pin_cfg *cfg)
3182 struct sigmatel_spec *spec = codec->spec;
3183 hda_nid_t nid;
3184 int err;
3185 int idx;
3187 err = create_multi_out_ctls(codec, cfg->line_outs, cfg->line_out_pins,
3188 spec->multiout.dac_nids,
3189 cfg->line_out_type);
3190 if (err < 0)
3191 return err;
3193 if (cfg->hp_outs > 1 && cfg->line_out_type == AUTO_PIN_LINE_OUT) {
3194 err = stac92xx_add_control(spec,
3195 STAC_CTL_WIDGET_HP_SWITCH,
3196 "Headphone as Line Out Switch",
3197 cfg->hp_pins[cfg->hp_outs - 1]);
3198 if (err < 0)
3199 return err;
3202 for (idx = AUTO_PIN_MIC; idx <= AUTO_PIN_FRONT_LINE; idx++) {
3203 nid = cfg->input_pins[idx];
3204 if (nid) {
3205 err = stac92xx_add_jack_mode_control(codec, nid, idx);
3206 if (err < 0)
3207 return err;
3211 return 0;
3214 /* add playback controls for Speaker and HP outputs */
3215 static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
3216 struct auto_pin_cfg *cfg)
3218 struct sigmatel_spec *spec = codec->spec;
3219 int err;
3221 err = create_multi_out_ctls(codec, cfg->hp_outs, cfg->hp_pins,
3222 spec->hp_dacs, AUTO_PIN_HP_OUT);
3223 if (err < 0)
3224 return err;
3226 err = create_multi_out_ctls(codec, cfg->speaker_outs, cfg->speaker_pins,
3227 spec->speaker_dacs, AUTO_PIN_SPEAKER_OUT);
3228 if (err < 0)
3229 return err;
3231 return 0;
3234 /* labels for mono mux outputs */
3235 static const char *stac92xx_mono_labels[4] = {
3236 "DAC0", "DAC1", "Mixer", "DAC2"
3239 /* create mono mux for mono out on capable codecs */
3240 static int stac92xx_auto_create_mono_output_ctls(struct hda_codec *codec)
3242 struct sigmatel_spec *spec = codec->spec;
3243 struct hda_input_mux *mono_mux = &spec->private_mono_mux;
3244 int i, num_cons;
3245 hda_nid_t con_lst[ARRAY_SIZE(stac92xx_mono_labels)];
3247 num_cons = snd_hda_get_connections(codec,
3248 spec->mono_nid,
3249 con_lst,
3250 HDA_MAX_NUM_INPUTS);
3251 if (num_cons <= 0 || num_cons > ARRAY_SIZE(stac92xx_mono_labels))
3252 return -EINVAL;
3254 for (i = 0; i < num_cons; i++) {
3255 mono_mux->items[mono_mux->num_items].label =
3256 stac92xx_mono_labels[i];
3257 mono_mux->items[mono_mux->num_items].index = i;
3258 mono_mux->num_items++;
3261 return stac92xx_add_control(spec, STAC_CTL_WIDGET_MONO_MUX,
3262 "Mono Mux", spec->mono_nid);
3265 /* create PC beep volume controls */
3266 static int stac92xx_auto_create_beep_ctls(struct hda_codec *codec,
3267 hda_nid_t nid)
3269 struct sigmatel_spec *spec = codec->spec;
3270 u32 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3271 int err, type = STAC_CTL_WIDGET_MUTE_BEEP;
3273 if (spec->anabeep_nid == nid)
3274 type = STAC_CTL_WIDGET_MUTE;
3276 /* check for mute support for the the amp */
3277 if ((caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT) {
3278 err = stac92xx_add_control(spec, type,
3279 "Beep Playback Switch",
3280 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3281 if (err < 0)
3282 return err;
3285 /* check to see if there is volume support for the amp */
3286 if ((caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3287 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL,
3288 "Beep Playback Volume",
3289 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3290 if (err < 0)
3291 return err;
3293 return 0;
3296 #ifdef CONFIG_SND_HDA_INPUT_BEEP
3297 #define stac92xx_dig_beep_switch_info snd_ctl_boolean_mono_info
3299 static int stac92xx_dig_beep_switch_get(struct snd_kcontrol *kcontrol,
3300 struct snd_ctl_elem_value *ucontrol)
3302 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3303 ucontrol->value.integer.value[0] = codec->beep->enabled;
3304 return 0;
3307 static int stac92xx_dig_beep_switch_put(struct snd_kcontrol *kcontrol,
3308 struct snd_ctl_elem_value *ucontrol)
3310 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3311 return snd_hda_enable_beep_device(codec, ucontrol->value.integer.value[0]);
3314 static struct snd_kcontrol_new stac92xx_dig_beep_ctrl = {
3315 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3316 .info = stac92xx_dig_beep_switch_info,
3317 .get = stac92xx_dig_beep_switch_get,
3318 .put = stac92xx_dig_beep_switch_put,
3321 static int stac92xx_beep_switch_ctl(struct hda_codec *codec)
3323 return stac92xx_add_control_temp(codec->spec, &stac92xx_dig_beep_ctrl,
3324 0, "Beep Playback Switch", 0);
3326 #endif
3328 static int stac92xx_auto_create_mux_input_ctls(struct hda_codec *codec)
3330 struct sigmatel_spec *spec = codec->spec;
3331 int i, j, err = 0;
3333 for (i = 0; i < spec->num_muxes; i++) {
3334 hda_nid_t nid;
3335 unsigned int wcaps;
3336 unsigned long val;
3338 nid = spec->mux_nids[i];
3339 wcaps = get_wcaps(codec, nid);
3340 if (!(wcaps & AC_WCAP_OUT_AMP))
3341 continue;
3343 /* check whether already the same control was created as
3344 * normal Capture Volume.
3346 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3347 for (j = 0; j < spec->num_caps; j++) {
3348 if (spec->capvols[j] == val)
3349 break;
3351 if (j < spec->num_caps)
3352 continue;
3354 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_VOL, i,
3355 "Mux Capture Volume", val);
3356 if (err < 0)
3357 return err;
3359 return 0;
3362 static const char *stac92xx_spdif_labels[3] = {
3363 "Digital Playback", "Analog Mux 1", "Analog Mux 2",
3366 static int stac92xx_auto_create_spdif_mux_ctls(struct hda_codec *codec)
3368 struct sigmatel_spec *spec = codec->spec;
3369 struct hda_input_mux *spdif_mux = &spec->private_smux;
3370 const char **labels = spec->spdif_labels;
3371 int i, num_cons;
3372 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
3374 num_cons = snd_hda_get_connections(codec,
3375 spec->smux_nids[0],
3376 con_lst,
3377 HDA_MAX_NUM_INPUTS);
3378 if (num_cons <= 0)
3379 return -EINVAL;
3381 if (!labels)
3382 labels = stac92xx_spdif_labels;
3384 for (i = 0; i < num_cons; i++) {
3385 spdif_mux->items[spdif_mux->num_items].label = labels[i];
3386 spdif_mux->items[spdif_mux->num_items].index = i;
3387 spdif_mux->num_items++;
3390 return 0;
3393 /* labels for dmic mux inputs */
3394 static const char *stac92xx_dmic_labels[5] = {
3395 "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
3396 "Digital Mic 3", "Digital Mic 4"
3399 static int get_connection_index(struct hda_codec *codec, hda_nid_t mux,
3400 hda_nid_t nid)
3402 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
3403 int i, nums;
3405 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
3406 for (i = 0; i < nums; i++)
3407 if (conn[i] == nid)
3408 return i;
3409 return -1;
3412 /* create a volume assigned to the given pin (only if supported) */
3413 /* return 1 if the volume control is created */
3414 static int create_elem_capture_vol(struct hda_codec *codec, hda_nid_t nid,
3415 const char *label, int direction)
3417 unsigned int caps, nums;
3418 char name[32];
3419 int err;
3421 if (direction == HDA_OUTPUT)
3422 caps = AC_WCAP_OUT_AMP;
3423 else
3424 caps = AC_WCAP_IN_AMP;
3425 if (!(get_wcaps(codec, nid) & caps))
3426 return 0;
3427 caps = query_amp_caps(codec, nid, direction);
3428 nums = (caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT;
3429 if (!nums)
3430 return 0;
3431 snprintf(name, sizeof(name), "%s Capture Volume", label);
3432 err = stac92xx_add_control(codec->spec, STAC_CTL_WIDGET_VOL, name,
3433 HDA_COMPOSE_AMP_VAL(nid, 3, 0, direction));
3434 if (err < 0)
3435 return err;
3436 return 1;
3439 /* create playback/capture controls for input pins on dmic capable codecs */
3440 static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
3441 const struct auto_pin_cfg *cfg)
3443 struct sigmatel_spec *spec = codec->spec;
3444 struct hda_input_mux *imux = &spec->private_imux;
3445 struct hda_input_mux *dimux = &spec->private_dimux;
3446 int err, i, active_mics;
3447 unsigned int def_conf;
3449 dimux->items[dimux->num_items].label = stac92xx_dmic_labels[0];
3450 dimux->items[dimux->num_items].index = 0;
3451 dimux->num_items++;
3453 active_mics = 0;
3454 for (i = 0; i < spec->num_dmics; i++) {
3455 /* check the validity: sometimes it's a dead vendor-spec node */
3456 if (get_wcaps_type(get_wcaps(codec, spec->dmic_nids[i]))
3457 != AC_WID_PIN)
3458 continue;
3459 def_conf = snd_hda_codec_get_pincfg(codec, spec->dmic_nids[i]);
3460 if (get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)
3461 active_mics++;
3464 for (i = 0; i < spec->num_dmics; i++) {
3465 hda_nid_t nid;
3466 int index;
3467 const char *label;
3469 nid = spec->dmic_nids[i];
3470 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
3471 continue;
3472 def_conf = snd_hda_codec_get_pincfg(codec, nid);
3473 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
3474 continue;
3476 index = get_connection_index(codec, spec->dmux_nids[0], nid);
3477 if (index < 0)
3478 continue;
3480 if (active_mics == 1)
3481 label = "Digital Mic";
3482 else
3483 label = stac92xx_dmic_labels[dimux->num_items];
3485 err = create_elem_capture_vol(codec, nid, label, HDA_INPUT);
3486 if (err < 0)
3487 return err;
3488 if (!err) {
3489 err = create_elem_capture_vol(codec, nid, label,
3490 HDA_OUTPUT);
3491 if (err < 0)
3492 return err;
3495 dimux->items[dimux->num_items].label = label;
3496 dimux->items[dimux->num_items].index = index;
3497 dimux->num_items++;
3498 if (snd_hda_get_bool_hint(codec, "separate_dmux") != 1) {
3499 imux->items[imux->num_items].label = label;
3500 imux->items[imux->num_items].index = index;
3501 imux->num_items++;
3505 return 0;
3508 static int check_mic_pin(struct hda_codec *codec, hda_nid_t nid,
3509 hda_nid_t *fixed, hda_nid_t *ext)
3511 unsigned int cfg;
3513 if (!nid)
3514 return 0;
3515 cfg = snd_hda_codec_get_pincfg(codec, nid);
3516 switch (get_defcfg_connect(cfg)) {
3517 case AC_JACK_PORT_FIXED:
3518 if (*fixed)
3519 return 1; /* already occupied */
3520 *fixed = nid;
3521 break;
3522 case AC_JACK_PORT_COMPLEX:
3523 if (*ext)
3524 return 1; /* already occupied */
3525 *ext = nid;
3526 break;
3528 return 0;
3531 static int set_mic_route(struct hda_codec *codec,
3532 struct sigmatel_mic_route *mic,
3533 hda_nid_t pin)
3535 struct sigmatel_spec *spec = codec->spec;
3536 struct auto_pin_cfg *cfg = &spec->autocfg;
3537 int i;
3539 mic->pin = pin;
3540 for (i = AUTO_PIN_MIC; i <= AUTO_PIN_FRONT_MIC; i++)
3541 if (pin == cfg->input_pins[i])
3542 break;
3543 if (i <= AUTO_PIN_FRONT_MIC) {
3544 /* analog pin */
3545 i = get_connection_index(codec, spec->mux_nids[0], pin);
3546 if (i < 0)
3547 return -1;
3548 mic->mux_idx = i;
3549 mic->dmux_idx = -1;
3550 if (spec->dmux_nids)
3551 mic->dmux_idx = get_connection_index(codec,
3552 spec->dmux_nids[0],
3553 spec->mux_nids[0]);
3554 } else if (spec->dmux_nids) {
3555 /* digital pin */
3556 i = get_connection_index(codec, spec->dmux_nids[0], pin);
3557 if (i < 0)
3558 return -1;
3559 mic->dmux_idx = i;
3560 mic->mux_idx = -1;
3561 if (spec->mux_nids)
3562 mic->mux_idx = get_connection_index(codec,
3563 spec->mux_nids[0],
3564 spec->dmux_nids[0]);
3566 return 0;
3569 /* return non-zero if the device is for automatic mic switch */
3570 static int stac_check_auto_mic(struct hda_codec *codec)
3572 struct sigmatel_spec *spec = codec->spec;
3573 struct auto_pin_cfg *cfg = &spec->autocfg;
3574 hda_nid_t fixed, ext;
3575 int i;
3577 for (i = AUTO_PIN_LINE; i < AUTO_PIN_LAST; i++) {
3578 if (cfg->input_pins[i])
3579 return 0; /* must be exclusively mics */
3581 fixed = ext = 0;
3582 for (i = AUTO_PIN_MIC; i <= AUTO_PIN_FRONT_MIC; i++)
3583 if (check_mic_pin(codec, cfg->input_pins[i], &fixed, &ext))
3584 return 0;
3585 for (i = 0; i < spec->num_dmics; i++)
3586 if (check_mic_pin(codec, spec->dmic_nids[i], &fixed, &ext))
3587 return 0;
3588 if (!fixed || !ext)
3589 return 0;
3590 if (!(get_wcaps(codec, ext) & AC_WCAP_UNSOL_CAP))
3591 return 0; /* no unsol support */
3592 if (set_mic_route(codec, &spec->ext_mic, ext) ||
3593 set_mic_route(codec, &spec->int_mic, fixed))
3594 return 0; /* something is wrong */
3595 return 1;
3598 /* create playback/capture controls for input pins */
3599 static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
3601 struct sigmatel_spec *spec = codec->spec;
3602 struct hda_input_mux *imux = &spec->private_imux;
3603 int i, j;
3605 for (i = 0; i < AUTO_PIN_LAST; i++) {
3606 hda_nid_t nid = cfg->input_pins[i];
3607 int index, err;
3609 if (!nid)
3610 continue;
3611 index = -1;
3612 for (j = 0; j < spec->num_muxes; j++) {
3613 index = get_connection_index(codec, spec->mux_nids[j],
3614 nid);
3615 if (index >= 0)
3616 break;
3618 if (index < 0)
3619 continue;
3621 err = create_elem_capture_vol(codec, nid,
3622 auto_pin_cfg_labels[i],
3623 HDA_INPUT);
3624 if (err < 0)
3625 return err;
3627 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
3628 imux->items[imux->num_items].index = index;
3629 imux->num_items++;
3631 spec->num_analog_muxes = imux->num_items;
3633 if (imux->num_items) {
3635 * Set the current input for the muxes.
3636 * The STAC9221 has two input muxes with identical source
3637 * NID lists. Hopefully this won't get confused.
3639 for (i = 0; i < spec->num_muxes; i++) {
3640 snd_hda_codec_write_cache(codec, spec->mux_nids[i], 0,
3641 AC_VERB_SET_CONNECT_SEL,
3642 imux->items[0].index);
3646 return 0;
3649 static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
3651 struct sigmatel_spec *spec = codec->spec;
3652 int i;
3654 for (i = 0; i < spec->autocfg.line_outs; i++) {
3655 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3656 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
3660 static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
3662 struct sigmatel_spec *spec = codec->spec;
3663 int i;
3665 for (i = 0; i < spec->autocfg.hp_outs; i++) {
3666 hda_nid_t pin;
3667 pin = spec->autocfg.hp_pins[i];
3668 if (pin) /* connect to front */
3669 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
3671 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
3672 hda_nid_t pin;
3673 pin = spec->autocfg.speaker_pins[i];
3674 if (pin) /* connect to front */
3675 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
3679 static int is_dual_headphones(struct hda_codec *codec)
3681 struct sigmatel_spec *spec = codec->spec;
3682 int i, valid_hps;
3684 if (spec->autocfg.line_out_type != AUTO_PIN_SPEAKER_OUT ||
3685 spec->autocfg.hp_outs <= 1)
3686 return 0;
3687 valid_hps = 0;
3688 for (i = 0; i < spec->autocfg.hp_outs; i++) {
3689 hda_nid_t nid = spec->autocfg.hp_pins[i];
3690 unsigned int cfg = snd_hda_codec_get_pincfg(codec, nid);
3691 if (get_defcfg_location(cfg) & AC_JACK_LOC_SEPARATE)
3692 continue;
3693 valid_hps++;
3695 return (valid_hps > 1);
3699 static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out, hda_nid_t dig_in)
3701 struct sigmatel_spec *spec = codec->spec;
3702 int hp_swap = 0;
3703 int i, err;
3705 if ((err = snd_hda_parse_pin_def_config(codec,
3706 &spec->autocfg,
3707 spec->dmic_nids)) < 0)
3708 return err;
3709 if (! spec->autocfg.line_outs)
3710 return 0; /* can't find valid pin config */
3712 /* If we have no real line-out pin and multiple hp-outs, HPs should
3713 * be set up as multi-channel outputs.
3715 if (is_dual_headphones(codec)) {
3716 /* Copy hp_outs to line_outs, backup line_outs in
3717 * speaker_outs so that the following routines can handle
3718 * HP pins as primary outputs.
3720 snd_printdd("stac92xx: Enabling multi-HPs workaround\n");
3721 memcpy(spec->autocfg.speaker_pins, spec->autocfg.line_out_pins,
3722 sizeof(spec->autocfg.line_out_pins));
3723 spec->autocfg.speaker_outs = spec->autocfg.line_outs;
3724 memcpy(spec->autocfg.line_out_pins, spec->autocfg.hp_pins,
3725 sizeof(spec->autocfg.hp_pins));
3726 spec->autocfg.line_outs = spec->autocfg.hp_outs;
3727 spec->autocfg.line_out_type = AUTO_PIN_HP_OUT;
3728 spec->autocfg.hp_outs = 0;
3729 hp_swap = 1;
3731 if (spec->autocfg.mono_out_pin) {
3732 int dir = get_wcaps(codec, spec->autocfg.mono_out_pin) &
3733 (AC_WCAP_OUT_AMP | AC_WCAP_IN_AMP);
3734 u32 caps = query_amp_caps(codec,
3735 spec->autocfg.mono_out_pin, dir);
3736 hda_nid_t conn_list[1];
3738 /* get the mixer node and then the mono mux if it exists */
3739 if (snd_hda_get_connections(codec,
3740 spec->autocfg.mono_out_pin, conn_list, 1) &&
3741 snd_hda_get_connections(codec, conn_list[0],
3742 conn_list, 1) > 0) {
3744 int wcaps = get_wcaps(codec, conn_list[0]);
3745 int wid_type = get_wcaps_type(wcaps);
3746 /* LR swap check, some stac925x have a mux that
3747 * changes the DACs output path instead of the
3748 * mono-mux path.
3750 if (wid_type == AC_WID_AUD_SEL &&
3751 !(wcaps & AC_WCAP_LR_SWAP))
3752 spec->mono_nid = conn_list[0];
3754 if (dir) {
3755 hda_nid_t nid = spec->autocfg.mono_out_pin;
3757 /* most mono outs have a least a mute/unmute switch */
3758 dir = (dir & AC_WCAP_OUT_AMP) ? HDA_OUTPUT : HDA_INPUT;
3759 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE,
3760 "Mono Playback Switch",
3761 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
3762 if (err < 0)
3763 return err;
3764 /* check for volume support for the amp */
3765 if ((caps & AC_AMPCAP_NUM_STEPS)
3766 >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3767 err = stac92xx_add_control(spec,
3768 STAC_CTL_WIDGET_VOL,
3769 "Mono Playback Volume",
3770 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
3771 if (err < 0)
3772 return err;
3776 stac92xx_auto_set_pinctl(codec, spec->autocfg.mono_out_pin,
3777 AC_PINCTL_OUT_EN);
3780 if (!spec->multiout.num_dacs) {
3781 err = stac92xx_auto_fill_dac_nids(codec);
3782 if (err < 0)
3783 return err;
3784 err = stac92xx_auto_create_multi_out_ctls(codec,
3785 &spec->autocfg);
3786 if (err < 0)
3787 return err;
3790 /* setup analog beep controls */
3791 if (spec->anabeep_nid > 0) {
3792 err = stac92xx_auto_create_beep_ctls(codec,
3793 spec->anabeep_nid);
3794 if (err < 0)
3795 return err;
3798 /* setup digital beep controls and input device */
3799 #ifdef CONFIG_SND_HDA_INPUT_BEEP
3800 if (spec->digbeep_nid > 0) {
3801 hda_nid_t nid = spec->digbeep_nid;
3802 unsigned int caps;
3804 err = stac92xx_auto_create_beep_ctls(codec, nid);
3805 if (err < 0)
3806 return err;
3807 err = snd_hda_attach_beep_device(codec, nid);
3808 if (err < 0)
3809 return err;
3810 if (codec->beep) {
3811 /* IDT/STAC codecs have linear beep tone parameter */
3812 codec->beep->linear_tone = 1;
3813 /* if no beep switch is available, make its own one */
3814 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3815 if (!(caps & AC_AMPCAP_MUTE)) {
3816 err = stac92xx_beep_switch_ctl(codec);
3817 if (err < 0)
3818 return err;
3822 #endif
3824 err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg);
3825 if (err < 0)
3826 return err;
3828 /* All output parsing done, now restore the swapped hp pins */
3829 if (hp_swap) {
3830 memcpy(spec->autocfg.hp_pins, spec->autocfg.line_out_pins,
3831 sizeof(spec->autocfg.hp_pins));
3832 spec->autocfg.hp_outs = spec->autocfg.line_outs;
3833 spec->autocfg.line_out_type = AUTO_PIN_HP_OUT;
3834 spec->autocfg.line_outs = 0;
3837 if (stac_check_auto_mic(codec)) {
3838 spec->auto_mic = 1;
3839 /* only one capture for auto-mic */
3840 spec->num_adcs = 1;
3841 spec->num_caps = 1;
3842 spec->num_muxes = 1;
3845 for (i = 0; i < spec->num_caps; i++) {
3846 err = stac92xx_add_capvol_ctls(codec, spec->capvols[i],
3847 spec->capsws[i], i);
3848 if (err < 0)
3849 return err;
3852 err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg);
3853 if (err < 0)
3854 return err;
3856 if (spec->mono_nid > 0) {
3857 err = stac92xx_auto_create_mono_output_ctls(codec);
3858 if (err < 0)
3859 return err;
3861 if (spec->num_dmics > 0 && !spec->dinput_mux)
3862 if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
3863 &spec->autocfg)) < 0)
3864 return err;
3865 if (spec->num_muxes > 0) {
3866 err = stac92xx_auto_create_mux_input_ctls(codec);
3867 if (err < 0)
3868 return err;
3870 if (spec->num_smuxes > 0) {
3871 err = stac92xx_auto_create_spdif_mux_ctls(codec);
3872 if (err < 0)
3873 return err;
3876 err = stac92xx_add_input_source(spec);
3877 if (err < 0)
3878 return err;
3880 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3881 if (spec->multiout.max_channels > 2)
3882 spec->surr_switch = 1;
3884 if (spec->autocfg.dig_outs)
3885 spec->multiout.dig_out_nid = dig_out;
3886 if (dig_in && spec->autocfg.dig_in_pin)
3887 spec->dig_in_nid = dig_in;
3889 if (spec->kctls.list)
3890 spec->mixers[spec->num_mixers++] = spec->kctls.list;
3892 spec->input_mux = &spec->private_imux;
3893 if (!spec->dinput_mux)
3894 spec->dinput_mux = &spec->private_dimux;
3895 spec->sinput_mux = &spec->private_smux;
3896 spec->mono_mux = &spec->private_mono_mux;
3897 return 1;
3900 /* add playback controls for HP output */
3901 static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
3902 struct auto_pin_cfg *cfg)
3904 struct sigmatel_spec *spec = codec->spec;
3905 hda_nid_t pin = cfg->hp_pins[0];
3906 unsigned int wid_caps;
3908 if (! pin)
3909 return 0;
3911 wid_caps = get_wcaps(codec, pin);
3912 if (wid_caps & AC_WCAP_UNSOL_CAP)
3913 spec->hp_detect = 1;
3915 return 0;
3918 /* add playback controls for LFE output */
3919 static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
3920 struct auto_pin_cfg *cfg)
3922 struct sigmatel_spec *spec = codec->spec;
3923 int err;
3924 hda_nid_t lfe_pin = 0x0;
3925 int i;
3928 * search speaker outs and line outs for a mono speaker pin
3929 * with an amp. If one is found, add LFE controls
3930 * for it.
3932 for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
3933 hda_nid_t pin = spec->autocfg.speaker_pins[i];
3934 unsigned int wcaps = get_wcaps(codec, pin);
3935 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
3936 if (wcaps == AC_WCAP_OUT_AMP)
3937 /* found a mono speaker with an amp, must be lfe */
3938 lfe_pin = pin;
3941 /* if speaker_outs is 0, then speakers may be in line_outs */
3942 if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
3943 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
3944 hda_nid_t pin = spec->autocfg.line_out_pins[i];
3945 unsigned int defcfg;
3946 defcfg = snd_hda_codec_get_pincfg(codec, pin);
3947 if (get_defcfg_device(defcfg) == AC_JACK_SPEAKER) {
3948 unsigned int wcaps = get_wcaps(codec, pin);
3949 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
3950 if (wcaps == AC_WCAP_OUT_AMP)
3951 /* found a mono speaker with an amp,
3952 must be lfe */
3953 lfe_pin = pin;
3958 if (lfe_pin) {
3959 err = create_controls(codec, "LFE", lfe_pin, 1);
3960 if (err < 0)
3961 return err;
3964 return 0;
3967 static int stac9200_parse_auto_config(struct hda_codec *codec)
3969 struct sigmatel_spec *spec = codec->spec;
3970 int err;
3972 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
3973 return err;
3975 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
3976 return err;
3978 if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
3979 return err;
3981 if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
3982 return err;
3984 if (spec->num_muxes > 0) {
3985 err = stac92xx_auto_create_mux_input_ctls(codec);
3986 if (err < 0)
3987 return err;
3990 err = stac92xx_add_input_source(spec);
3991 if (err < 0)
3992 return err;
3994 if (spec->autocfg.dig_outs)
3995 spec->multiout.dig_out_nid = 0x05;
3996 if (spec->autocfg.dig_in_pin)
3997 spec->dig_in_nid = 0x04;
3999 if (spec->kctls.list)
4000 spec->mixers[spec->num_mixers++] = spec->kctls.list;
4002 spec->input_mux = &spec->private_imux;
4003 spec->dinput_mux = &spec->private_dimux;
4005 return 1;
4009 * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
4010 * funky external mute control using GPIO pins.
4013 static void stac_gpio_set(struct hda_codec *codec, unsigned int mask,
4014 unsigned int dir_mask, unsigned int data)
4016 unsigned int gpiostate, gpiomask, gpiodir;
4018 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
4019 AC_VERB_GET_GPIO_DATA, 0);
4020 gpiostate = (gpiostate & ~dir_mask) | (data & dir_mask);
4022 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
4023 AC_VERB_GET_GPIO_MASK, 0);
4024 gpiomask |= mask;
4026 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
4027 AC_VERB_GET_GPIO_DIRECTION, 0);
4028 gpiodir |= dir_mask;
4030 /* Configure GPIOx as CMOS */
4031 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
4033 snd_hda_codec_write(codec, codec->afg, 0,
4034 AC_VERB_SET_GPIO_MASK, gpiomask);
4035 snd_hda_codec_read(codec, codec->afg, 0,
4036 AC_VERB_SET_GPIO_DIRECTION, gpiodir); /* sync */
4038 msleep(1);
4040 snd_hda_codec_read(codec, codec->afg, 0,
4041 AC_VERB_SET_GPIO_DATA, gpiostate); /* sync */
4044 #ifdef CONFIG_SND_HDA_INPUT_JACK
4045 static void stac92xx_free_jack_priv(struct snd_jack *jack)
4047 struct sigmatel_jack *jacks = jack->private_data;
4048 jacks->nid = 0;
4049 jacks->jack = NULL;
4051 #endif
4053 static int stac92xx_add_jack(struct hda_codec *codec,
4054 hda_nid_t nid, int type)
4056 #ifdef CONFIG_SND_HDA_INPUT_JACK
4057 struct sigmatel_spec *spec = codec->spec;
4058 struct sigmatel_jack *jack;
4059 int def_conf = snd_hda_codec_get_pincfg(codec, nid);
4060 int connectivity = get_defcfg_connect(def_conf);
4061 char name[32];
4062 int err;
4064 if (connectivity && connectivity != AC_JACK_PORT_FIXED)
4065 return 0;
4067 snd_array_init(&spec->jacks, sizeof(*jack), 32);
4068 jack = snd_array_new(&spec->jacks);
4069 if (!jack)
4070 return -ENOMEM;
4071 jack->nid = nid;
4072 jack->type = type;
4074 snprintf(name, sizeof(name), "%s at %s %s Jack",
4075 snd_hda_get_jack_type(def_conf),
4076 snd_hda_get_jack_connectivity(def_conf),
4077 snd_hda_get_jack_location(def_conf));
4079 err = snd_jack_new(codec->bus->card, name, type, &jack->jack);
4080 if (err < 0) {
4081 jack->nid = 0;
4082 return err;
4084 jack->jack->private_data = jack;
4085 jack->jack->private_free = stac92xx_free_jack_priv;
4086 #endif
4087 return 0;
4090 static int stac_add_event(struct sigmatel_spec *spec, hda_nid_t nid,
4091 unsigned char type, int data)
4093 struct sigmatel_event *event;
4095 snd_array_init(&spec->events, sizeof(*event), 32);
4096 event = snd_array_new(&spec->events);
4097 if (!event)
4098 return -ENOMEM;
4099 event->nid = nid;
4100 event->type = type;
4101 event->tag = spec->events.used;
4102 event->data = data;
4104 return event->tag;
4107 static struct sigmatel_event *stac_get_event(struct hda_codec *codec,
4108 hda_nid_t nid)
4110 struct sigmatel_spec *spec = codec->spec;
4111 struct sigmatel_event *event = spec->events.list;
4112 int i;
4114 for (i = 0; i < spec->events.used; i++, event++) {
4115 if (event->nid == nid)
4116 return event;
4118 return NULL;
4121 static struct sigmatel_event *stac_get_event_from_tag(struct hda_codec *codec,
4122 unsigned char tag)
4124 struct sigmatel_spec *spec = codec->spec;
4125 struct sigmatel_event *event = spec->events.list;
4126 int i;
4128 for (i = 0; i < spec->events.used; i++, event++) {
4129 if (event->tag == tag)
4130 return event;
4132 return NULL;
4135 /* check if given nid is a valid pin and no other events are assigned
4136 * to it. If OK, assign the event, set the unsol flag, and returns 1.
4137 * Otherwise, returns zero.
4139 static int enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
4140 unsigned int type)
4142 struct sigmatel_event *event;
4143 int tag;
4145 if (!(get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP))
4146 return 0;
4147 event = stac_get_event(codec, nid);
4148 if (event) {
4149 if (event->type != type)
4150 return 0;
4151 tag = event->tag;
4152 } else {
4153 tag = stac_add_event(codec->spec, nid, type, 0);
4154 if (tag < 0)
4155 return 0;
4157 snd_hda_codec_write_cache(codec, nid, 0,
4158 AC_VERB_SET_UNSOLICITED_ENABLE,
4159 AC_USRSP_EN | tag);
4160 return 1;
4163 static int is_nid_hp_pin(struct auto_pin_cfg *cfg, hda_nid_t nid)
4165 int i;
4166 for (i = 0; i < cfg->hp_outs; i++)
4167 if (cfg->hp_pins[i] == nid)
4168 return 1; /* nid is a HP-Out */
4170 return 0; /* nid is not a HP-Out */
4173 static void stac92xx_power_down(struct hda_codec *codec)
4175 struct sigmatel_spec *spec = codec->spec;
4177 /* power down inactive DACs */
4178 hda_nid_t *dac;
4179 for (dac = spec->dac_list; *dac; dac++)
4180 if (!check_all_dac_nids(spec, *dac))
4181 snd_hda_codec_write(codec, *dac, 0,
4182 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
4185 static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
4186 int enable);
4188 static inline int get_int_hint(struct hda_codec *codec, const char *key,
4189 int *valp)
4191 const char *p;
4192 p = snd_hda_get_hint(codec, key);
4193 if (p) {
4194 unsigned long val;
4195 if (!strict_strtoul(p, 0, &val)) {
4196 *valp = val;
4197 return 1;
4200 return 0;
4203 /* override some hints from the hwdep entry */
4204 static void stac_store_hints(struct hda_codec *codec)
4206 struct sigmatel_spec *spec = codec->spec;
4207 int val;
4209 val = snd_hda_get_bool_hint(codec, "hp_detect");
4210 if (val >= 0)
4211 spec->hp_detect = val;
4212 if (get_int_hint(codec, "gpio_mask", &spec->gpio_mask)) {
4213 spec->eapd_mask = spec->gpio_dir = spec->gpio_data =
4214 spec->gpio_mask;
4216 if (get_int_hint(codec, "gpio_dir", &spec->gpio_dir))
4217 spec->gpio_mask &= spec->gpio_mask;
4218 if (get_int_hint(codec, "gpio_data", &spec->gpio_data))
4219 spec->gpio_dir &= spec->gpio_mask;
4220 if (get_int_hint(codec, "eapd_mask", &spec->eapd_mask))
4221 spec->eapd_mask &= spec->gpio_mask;
4222 if (get_int_hint(codec, "gpio_mute", &spec->gpio_mute))
4223 spec->gpio_mute &= spec->gpio_mask;
4224 val = snd_hda_get_bool_hint(codec, "eapd_switch");
4225 if (val >= 0)
4226 spec->eapd_switch = val;
4227 get_int_hint(codec, "gpio_led_polarity", &spec->gpio_led_polarity);
4228 if (get_int_hint(codec, "gpio_led", &spec->gpio_led)) {
4229 spec->gpio_mask |= spec->gpio_led;
4230 spec->gpio_dir |= spec->gpio_led;
4231 if (spec->gpio_led_polarity)
4232 spec->gpio_data |= spec->gpio_led;
4236 static int stac92xx_init(struct hda_codec *codec)
4238 struct sigmatel_spec *spec = codec->spec;
4239 struct auto_pin_cfg *cfg = &spec->autocfg;
4240 unsigned int gpio;
4241 int i;
4243 snd_hda_sequence_write(codec, spec->init);
4245 /* power down adcs initially */
4246 if (spec->powerdown_adcs)
4247 for (i = 0; i < spec->num_adcs; i++)
4248 snd_hda_codec_write(codec,
4249 spec->adc_nids[i], 0,
4250 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
4252 /* override some hints */
4253 stac_store_hints(codec);
4255 /* set up GPIO */
4256 gpio = spec->gpio_data;
4257 /* turn on EAPD statically when spec->eapd_switch isn't set.
4258 * otherwise, unsol event will turn it on/off dynamically
4260 if (!spec->eapd_switch)
4261 gpio |= spec->eapd_mask;
4262 stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, gpio);
4264 /* set up pins */
4265 if (spec->hp_detect) {
4266 /* Enable unsolicited responses on the HP widget */
4267 for (i = 0; i < cfg->hp_outs; i++) {
4268 hda_nid_t nid = cfg->hp_pins[i];
4269 enable_pin_detect(codec, nid, STAC_HP_EVENT);
4271 if (cfg->line_out_type == AUTO_PIN_LINE_OUT &&
4272 cfg->speaker_outs > 0) {
4273 /* enable pin-detect for line-outs as well */
4274 for (i = 0; i < cfg->line_outs; i++) {
4275 hda_nid_t nid = cfg->line_out_pins[i];
4276 enable_pin_detect(codec, nid, STAC_LO_EVENT);
4280 /* force to enable the first line-out; the others are set up
4281 * in unsol_event
4283 stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
4284 AC_PINCTL_OUT_EN);
4285 /* fake event to set up pins */
4286 if (cfg->hp_pins[0])
4287 stac_issue_unsol_event(codec, cfg->hp_pins[0]);
4288 else if (cfg->line_out_pins[0])
4289 stac_issue_unsol_event(codec, cfg->line_out_pins[0]);
4290 } else {
4291 stac92xx_auto_init_multi_out(codec);
4292 stac92xx_auto_init_hp_out(codec);
4293 for (i = 0; i < cfg->hp_outs; i++)
4294 stac_toggle_power_map(codec, cfg->hp_pins[i], 1);
4296 if (spec->auto_mic) {
4297 /* initialize connection to analog input */
4298 if (spec->dmux_nids)
4299 snd_hda_codec_write_cache(codec, spec->dmux_nids[0], 0,
4300 AC_VERB_SET_CONNECT_SEL, 0);
4301 if (enable_pin_detect(codec, spec->ext_mic.pin, STAC_MIC_EVENT))
4302 stac_issue_unsol_event(codec, spec->ext_mic.pin);
4304 for (i = 0; i < AUTO_PIN_LAST; i++) {
4305 hda_nid_t nid = cfg->input_pins[i];
4306 if (nid) {
4307 unsigned int pinctl, conf;
4308 if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC) {
4309 /* for mic pins, force to initialize */
4310 pinctl = stac92xx_get_default_vref(codec, nid);
4311 pinctl |= AC_PINCTL_IN_EN;
4312 stac92xx_auto_set_pinctl(codec, nid, pinctl);
4313 } else {
4314 pinctl = snd_hda_codec_read(codec, nid, 0,
4315 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4316 /* if PINCTL already set then skip */
4317 /* Also, if both INPUT and OUTPUT are set,
4318 * it must be a BIOS bug; need to override, too
4320 if (!(pinctl & AC_PINCTL_IN_EN) ||
4321 (pinctl & AC_PINCTL_OUT_EN)) {
4322 pinctl &= ~AC_PINCTL_OUT_EN;
4323 pinctl |= AC_PINCTL_IN_EN;
4324 stac92xx_auto_set_pinctl(codec, nid,
4325 pinctl);
4328 conf = snd_hda_codec_get_pincfg(codec, nid);
4329 if (get_defcfg_connect(conf) != AC_JACK_PORT_FIXED) {
4330 if (enable_pin_detect(codec, nid,
4331 STAC_INSERT_EVENT))
4332 stac_issue_unsol_event(codec, nid);
4336 for (i = 0; i < spec->num_dmics; i++)
4337 stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
4338 AC_PINCTL_IN_EN);
4339 if (cfg->dig_out_pins[0])
4340 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pins[0],
4341 AC_PINCTL_OUT_EN);
4342 if (cfg->dig_in_pin)
4343 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
4344 AC_PINCTL_IN_EN);
4345 for (i = 0; i < spec->num_pwrs; i++) {
4346 hda_nid_t nid = spec->pwr_nids[i];
4347 int pinctl, def_conf;
4349 /* power on when no jack detection is available */
4350 if (!spec->hp_detect) {
4351 stac_toggle_power_map(codec, nid, 1);
4352 continue;
4355 if (is_nid_hp_pin(cfg, nid))
4356 continue; /* already has an unsol event */
4358 pinctl = snd_hda_codec_read(codec, nid, 0,
4359 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4360 /* outputs are only ports capable of power management
4361 * any attempts on powering down a input port cause the
4362 * referenced VREF to act quirky.
4364 if (pinctl & AC_PINCTL_IN_EN) {
4365 stac_toggle_power_map(codec, nid, 1);
4366 continue;
4368 def_conf = snd_hda_codec_get_pincfg(codec, nid);
4369 def_conf = get_defcfg_connect(def_conf);
4370 /* skip any ports that don't have jacks since presence
4371 * detection is useless */
4372 if (def_conf != AC_JACK_PORT_COMPLEX) {
4373 if (def_conf != AC_JACK_PORT_NONE)
4374 stac_toggle_power_map(codec, nid, 1);
4375 continue;
4377 if (enable_pin_detect(codec, nid, STAC_PWR_EVENT))
4378 stac_issue_unsol_event(codec, nid);
4381 #ifdef CONFIG_SND_HDA_POWER_SAVE
4382 /* sync mute LED */
4383 if (spec->gpio_led && codec->patch_ops.check_power_status)
4384 codec->patch_ops.check_power_status(codec, 0x01);
4385 #endif
4386 if (spec->dac_list)
4387 stac92xx_power_down(codec);
4388 return 0;
4391 static void stac92xx_free_jacks(struct hda_codec *codec)
4393 #ifdef CONFIG_SND_HDA_INPUT_JACK
4394 /* free jack instances manually when clearing/reconfiguring */
4395 struct sigmatel_spec *spec = codec->spec;
4396 if (!codec->bus->shutdown && spec->jacks.list) {
4397 struct sigmatel_jack *jacks = spec->jacks.list;
4398 int i;
4399 for (i = 0; i < spec->jacks.used; i++, jacks++) {
4400 if (jacks->jack)
4401 snd_device_free(codec->bus->card, jacks->jack);
4404 snd_array_free(&spec->jacks);
4405 #endif
4408 static void stac92xx_free_kctls(struct hda_codec *codec)
4410 struct sigmatel_spec *spec = codec->spec;
4412 if (spec->kctls.list) {
4413 struct snd_kcontrol_new *kctl = spec->kctls.list;
4414 int i;
4415 for (i = 0; i < spec->kctls.used; i++)
4416 kfree(kctl[i].name);
4418 snd_array_free(&spec->kctls);
4421 static void stac92xx_shutup(struct hda_codec *codec)
4423 struct sigmatel_spec *spec = codec->spec;
4425 snd_hda_shutup_pins(codec);
4427 if (spec->eapd_mask)
4428 stac_gpio_set(codec, spec->gpio_mask,
4429 spec->gpio_dir, spec->gpio_data &
4430 ~spec->eapd_mask);
4433 static void stac92xx_free(struct hda_codec *codec)
4435 struct sigmatel_spec *spec = codec->spec;
4437 if (! spec)
4438 return;
4440 stac92xx_shutup(codec);
4441 stac92xx_free_jacks(codec);
4442 snd_array_free(&spec->events);
4444 kfree(spec);
4445 snd_hda_detach_beep_device(codec);
4448 static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
4449 unsigned int flag)
4451 unsigned int old_ctl, pin_ctl;
4453 pin_ctl = snd_hda_codec_read(codec, nid,
4454 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
4456 if (pin_ctl & AC_PINCTL_IN_EN) {
4458 * we need to check the current set-up direction of
4459 * shared input pins since they can be switched via
4460 * "xxx as Output" mixer switch
4462 struct sigmatel_spec *spec = codec->spec;
4463 if (nid == spec->line_switch || nid == spec->mic_switch)
4464 return;
4467 old_ctl = pin_ctl;
4468 /* if setting pin direction bits, clear the current
4469 direction bits first */
4470 if (flag & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))
4471 pin_ctl &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
4473 pin_ctl |= flag;
4474 if (old_ctl != pin_ctl)
4475 snd_hda_codec_write_cache(codec, nid, 0,
4476 AC_VERB_SET_PIN_WIDGET_CONTROL,
4477 pin_ctl);
4480 static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
4481 unsigned int flag)
4483 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
4484 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
4485 if (pin_ctl & flag)
4486 snd_hda_codec_write_cache(codec, nid, 0,
4487 AC_VERB_SET_PIN_WIDGET_CONTROL,
4488 pin_ctl & ~flag);
4491 static inline int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
4493 if (!nid)
4494 return 0;
4495 return snd_hda_jack_detect(codec, nid);
4498 static void stac92xx_line_out_detect(struct hda_codec *codec,
4499 int presence)
4501 struct sigmatel_spec *spec = codec->spec;
4502 struct auto_pin_cfg *cfg = &spec->autocfg;
4503 int i;
4505 for (i = 0; i < cfg->line_outs; i++) {
4506 if (presence)
4507 break;
4508 presence = get_pin_presence(codec, cfg->line_out_pins[i]);
4509 if (presence) {
4510 unsigned int pinctl;
4511 pinctl = snd_hda_codec_read(codec,
4512 cfg->line_out_pins[i], 0,
4513 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4514 if (pinctl & AC_PINCTL_IN_EN)
4515 presence = 0; /* mic- or line-input */
4519 if (presence) {
4520 /* disable speakers */
4521 for (i = 0; i < cfg->speaker_outs; i++)
4522 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
4523 AC_PINCTL_OUT_EN);
4524 if (spec->eapd_mask && spec->eapd_switch)
4525 stac_gpio_set(codec, spec->gpio_mask,
4526 spec->gpio_dir, spec->gpio_data &
4527 ~spec->eapd_mask);
4528 } else {
4529 /* enable speakers */
4530 for (i = 0; i < cfg->speaker_outs; i++)
4531 stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
4532 AC_PINCTL_OUT_EN);
4533 if (spec->eapd_mask && spec->eapd_switch)
4534 stac_gpio_set(codec, spec->gpio_mask,
4535 spec->gpio_dir, spec->gpio_data |
4536 spec->eapd_mask);
4540 /* return non-zero if the hp-pin of the given array index isn't
4541 * a jack-detection target
4543 static int no_hp_sensing(struct sigmatel_spec *spec, int i)
4545 struct auto_pin_cfg *cfg = &spec->autocfg;
4547 /* ignore sensing of shared line and mic jacks */
4548 if (cfg->hp_pins[i] == spec->line_switch)
4549 return 1;
4550 if (cfg->hp_pins[i] == spec->mic_switch)
4551 return 1;
4552 /* ignore if the pin is set as line-out */
4553 if (cfg->hp_pins[i] == spec->hp_switch)
4554 return 1;
4555 return 0;
4558 static void stac92xx_hp_detect(struct hda_codec *codec)
4560 struct sigmatel_spec *spec = codec->spec;
4561 struct auto_pin_cfg *cfg = &spec->autocfg;
4562 int i, presence;
4564 presence = 0;
4565 if (spec->gpio_mute)
4566 presence = !(snd_hda_codec_read(codec, codec->afg, 0,
4567 AC_VERB_GET_GPIO_DATA, 0) & spec->gpio_mute);
4569 for (i = 0; i < cfg->hp_outs; i++) {
4570 if (presence)
4571 break;
4572 if (no_hp_sensing(spec, i))
4573 continue;
4574 presence = get_pin_presence(codec, cfg->hp_pins[i]);
4575 if (presence) {
4576 unsigned int pinctl;
4577 pinctl = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
4578 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4579 if (pinctl & AC_PINCTL_IN_EN)
4580 presence = 0; /* mic- or line-input */
4584 if (presence) {
4585 /* disable lineouts */
4586 if (spec->hp_switch)
4587 stac92xx_reset_pinctl(codec, spec->hp_switch,
4588 AC_PINCTL_OUT_EN);
4589 for (i = 0; i < cfg->line_outs; i++)
4590 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
4591 AC_PINCTL_OUT_EN);
4592 } else {
4593 /* enable lineouts */
4594 if (spec->hp_switch)
4595 stac92xx_set_pinctl(codec, spec->hp_switch,
4596 AC_PINCTL_OUT_EN);
4597 for (i = 0; i < cfg->line_outs; i++)
4598 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
4599 AC_PINCTL_OUT_EN);
4601 stac92xx_line_out_detect(codec, presence);
4602 /* toggle hp outs */
4603 for (i = 0; i < cfg->hp_outs; i++) {
4604 unsigned int val = AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN;
4605 if (no_hp_sensing(spec, i))
4606 continue;
4607 if (presence)
4608 stac92xx_set_pinctl(codec, cfg->hp_pins[i], val);
4609 #if 0 /* FIXME */
4610 /* Resetting the pinctl like below may lead to (a sort of) regressions
4611 * on some devices since they use the HP pin actually for line/speaker
4612 * outs although the default pin config shows a different pin (that is
4613 * wrong and useless).
4615 * So, it's basically a problem of default pin configs, likely a BIOS issue.
4616 * But, disabling the code below just works around it, and I'm too tired of
4617 * bug reports with such devices...
4619 else
4620 stac92xx_reset_pinctl(codec, cfg->hp_pins[i], val);
4621 #endif /* FIXME */
4625 static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
4626 int enable)
4628 struct sigmatel_spec *spec = codec->spec;
4629 unsigned int idx, val;
4631 for (idx = 0; idx < spec->num_pwrs; idx++) {
4632 if (spec->pwr_nids[idx] == nid)
4633 break;
4635 if (idx >= spec->num_pwrs)
4636 return;
4638 /* several codecs have two power down bits */
4639 if (spec->pwr_mapping)
4640 idx = spec->pwr_mapping[idx];
4641 else
4642 idx = 1 << idx;
4644 val = snd_hda_codec_read(codec, codec->afg, 0, 0x0fec, 0x0) & 0xff;
4645 if (enable)
4646 val &= ~idx;
4647 else
4648 val |= idx;
4650 /* power down unused output ports */
4651 snd_hda_codec_write(codec, codec->afg, 0, 0x7ec, val);
4654 static void stac92xx_pin_sense(struct hda_codec *codec, hda_nid_t nid)
4656 stac_toggle_power_map(codec, nid, get_pin_presence(codec, nid));
4659 static void stac92xx_report_jack(struct hda_codec *codec, hda_nid_t nid)
4661 struct sigmatel_spec *spec = codec->spec;
4662 struct sigmatel_jack *jacks = spec->jacks.list;
4664 if (jacks) {
4665 int i;
4666 for (i = 0; i < spec->jacks.used; i++) {
4667 if (jacks->nid == nid) {
4668 unsigned int pin_ctl =
4669 snd_hda_codec_read(codec, nid,
4670 0, AC_VERB_GET_PIN_WIDGET_CONTROL,
4671 0x00);
4672 int type = jacks->type;
4673 if (type == (SND_JACK_LINEOUT
4674 | SND_JACK_HEADPHONE))
4675 type = (pin_ctl & AC_PINCTL_HP_EN)
4676 ? SND_JACK_HEADPHONE : SND_JACK_LINEOUT;
4677 snd_jack_report(jacks->jack,
4678 get_pin_presence(codec, nid)
4679 ? type : 0);
4681 jacks++;
4686 static void stac92xx_mic_detect(struct hda_codec *codec)
4688 struct sigmatel_spec *spec = codec->spec;
4689 struct sigmatel_mic_route *mic;
4691 if (get_pin_presence(codec, spec->ext_mic.pin))
4692 mic = &spec->ext_mic;
4693 else
4694 mic = &spec->int_mic;
4695 if (mic->dmux_idx >= 0)
4696 snd_hda_codec_write_cache(codec, spec->dmux_nids[0], 0,
4697 AC_VERB_SET_CONNECT_SEL,
4698 mic->dmux_idx);
4699 if (mic->mux_idx >= 0)
4700 snd_hda_codec_write_cache(codec, spec->mux_nids[0], 0,
4701 AC_VERB_SET_CONNECT_SEL,
4702 mic->mux_idx);
4705 static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid)
4707 struct sigmatel_event *event = stac_get_event(codec, nid);
4708 if (!event)
4709 return;
4710 codec->patch_ops.unsol_event(codec, (unsigned)event->tag << 26);
4713 static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
4715 struct sigmatel_spec *spec = codec->spec;
4716 struct sigmatel_event *event;
4717 int tag, data;
4719 tag = (res >> 26) & 0x7f;
4720 event = stac_get_event_from_tag(codec, tag);
4721 if (!event)
4722 return;
4724 switch (event->type) {
4725 case STAC_HP_EVENT:
4726 case STAC_LO_EVENT:
4727 stac92xx_hp_detect(codec);
4728 break;
4729 case STAC_MIC_EVENT:
4730 stac92xx_mic_detect(codec);
4731 break;
4734 switch (event->type) {
4735 case STAC_HP_EVENT:
4736 case STAC_LO_EVENT:
4737 case STAC_MIC_EVENT:
4738 case STAC_INSERT_EVENT:
4739 case STAC_PWR_EVENT:
4740 if (spec->num_pwrs > 0)
4741 stac92xx_pin_sense(codec, event->nid);
4742 stac92xx_report_jack(codec, event->nid);
4744 switch (codec->subsystem_id) {
4745 case 0x103c308f:
4746 if (event->nid == 0xb) {
4747 int pin = AC_PINCTL_IN_EN;
4749 if (get_pin_presence(codec, 0xa)
4750 && get_pin_presence(codec, 0xb))
4751 pin |= AC_PINCTL_VREF_80;
4752 if (!get_pin_presence(codec, 0xb))
4753 pin |= AC_PINCTL_VREF_80;
4755 /* toggle VREF state based on mic + hp pin
4756 * status
4758 stac92xx_auto_set_pinctl(codec, 0x0a, pin);
4761 break;
4762 case STAC_VREF_EVENT:
4763 data = snd_hda_codec_read(codec, codec->afg, 0,
4764 AC_VERB_GET_GPIO_DATA, 0);
4765 /* toggle VREF state based on GPIOx status */
4766 snd_hda_codec_write(codec, codec->afg, 0, 0x7e0,
4767 !!(data & (1 << event->data)));
4768 break;
4772 static int hp_blike_system(u32 subsystem_id);
4774 static void set_hp_led_gpio(struct hda_codec *codec)
4776 struct sigmatel_spec *spec = codec->spec;
4777 unsigned int gpio;
4779 if (spec->gpio_led)
4780 return;
4782 gpio = snd_hda_param_read(codec, codec->afg, AC_PAR_GPIO_CAP);
4783 gpio &= AC_GPIO_IO_COUNT;
4784 if (gpio > 3)
4785 spec->gpio_led = 0x08; /* GPIO 3 */
4786 else
4787 spec->gpio_led = 0x01; /* GPIO 0 */
4791 * This method searches for the mute LED GPIO configuration
4792 * provided as OEM string in SMBIOS. The format of that string
4793 * is HP_Mute_LED_P_G or HP_Mute_LED_P
4794 * where P can be 0 or 1 and defines mute LED GPIO control state (low/high)
4795 * that corresponds to the NOT muted state of the master volume
4796 * and G is the index of the GPIO to use as the mute LED control (0..9)
4797 * If _G portion is missing it is assigned based on the codec ID
4799 * So, HP B-series like systems may have HP_Mute_LED_0 (current models)
4800 * or HP_Mute_LED_0_3 (future models) OEM SMBIOS strings
4803 * The dv-series laptops don't seem to have the HP_Mute_LED* strings in
4804 * SMBIOS - at least the ones I have seen do not have them - which include
4805 * my own system (HP Pavilion dv6-1110ax) and my cousin's
4806 * HP Pavilion dv9500t CTO.
4807 * Need more information on whether it is true across the entire series.
4808 * -- kunal
4810 static int find_mute_led_gpio(struct hda_codec *codec, int default_polarity)
4812 struct sigmatel_spec *spec = codec->spec;
4813 const struct dmi_device *dev = NULL;
4815 if ((codec->subsystem_id >> 16) == PCI_VENDOR_ID_HP) {
4816 while ((dev = dmi_find_device(DMI_DEV_TYPE_OEM_STRING,
4817 NULL, dev))) {
4818 if (sscanf(dev->name, "HP_Mute_LED_%d_%d",
4819 &spec->gpio_led_polarity,
4820 &spec->gpio_led) == 2) {
4821 spec->gpio_led = 1 << spec->gpio_led;
4822 return 1;
4824 if (sscanf(dev->name, "HP_Mute_LED_%d",
4825 &spec->gpio_led_polarity) == 1) {
4826 set_hp_led_gpio(codec);
4827 return 1;
4832 * Fallback case - if we don't find the DMI strings,
4833 * we statically set the GPIO - if not a B-series system.
4835 if (!hp_blike_system(codec->subsystem_id)) {
4836 set_hp_led_gpio(codec);
4837 spec->gpio_led_polarity = default_polarity;
4838 return 1;
4841 return 0;
4844 static int hp_blike_system(u32 subsystem_id)
4846 switch (subsystem_id) {
4847 case 0x103c1520:
4848 case 0x103c1521:
4849 case 0x103c1523:
4850 case 0x103c1524:
4851 case 0x103c1525:
4852 case 0x103c1722:
4853 case 0x103c1723:
4854 case 0x103c1724:
4855 case 0x103c1725:
4856 case 0x103c1726:
4857 case 0x103c1727:
4858 case 0x103c1728:
4859 case 0x103c1729:
4860 case 0x103c172a:
4861 case 0x103c172b:
4862 case 0x103c307e:
4863 case 0x103c307f:
4864 case 0x103c3080:
4865 case 0x103c3081:
4866 case 0x103c7007:
4867 case 0x103c7008:
4868 return 1;
4870 return 0;
4873 #ifdef CONFIG_PROC_FS
4874 static void stac92hd_proc_hook(struct snd_info_buffer *buffer,
4875 struct hda_codec *codec, hda_nid_t nid)
4877 if (nid == codec->afg)
4878 snd_iprintf(buffer, "Power-Map: 0x%02x\n",
4879 snd_hda_codec_read(codec, nid, 0, 0x0fec, 0x0));
4882 static void analog_loop_proc_hook(struct snd_info_buffer *buffer,
4883 struct hda_codec *codec,
4884 unsigned int verb)
4886 snd_iprintf(buffer, "Analog Loopback: 0x%02x\n",
4887 snd_hda_codec_read(codec, codec->afg, 0, verb, 0));
4890 /* stac92hd71bxx, stac92hd73xx */
4891 static void stac92hd7x_proc_hook(struct snd_info_buffer *buffer,
4892 struct hda_codec *codec, hda_nid_t nid)
4894 stac92hd_proc_hook(buffer, codec, nid);
4895 if (nid == codec->afg)
4896 analog_loop_proc_hook(buffer, codec, 0xfa0);
4899 static void stac9205_proc_hook(struct snd_info_buffer *buffer,
4900 struct hda_codec *codec, hda_nid_t nid)
4902 if (nid == codec->afg)
4903 analog_loop_proc_hook(buffer, codec, 0xfe0);
4906 static void stac927x_proc_hook(struct snd_info_buffer *buffer,
4907 struct hda_codec *codec, hda_nid_t nid)
4909 if (nid == codec->afg)
4910 analog_loop_proc_hook(buffer, codec, 0xfeb);
4912 #else
4913 #define stac92hd_proc_hook NULL
4914 #define stac92hd7x_proc_hook NULL
4915 #define stac9205_proc_hook NULL
4916 #define stac927x_proc_hook NULL
4917 #endif
4919 #ifdef SND_HDA_NEEDS_RESUME
4920 static int stac92xx_resume(struct hda_codec *codec)
4922 struct sigmatel_spec *spec = codec->spec;
4924 stac92xx_init(codec);
4925 snd_hda_codec_resume_amp(codec);
4926 snd_hda_codec_resume_cache(codec);
4927 /* fake event to set up pins again to override cached values */
4928 if (spec->hp_detect) {
4929 if (spec->autocfg.hp_pins[0])
4930 stac_issue_unsol_event(codec, spec->autocfg.hp_pins[0]);
4931 else if (spec->autocfg.line_out_pins[0])
4932 stac_issue_unsol_event(codec,
4933 spec->autocfg.line_out_pins[0]);
4935 #ifdef CONFIG_SND_HDA_POWER_SAVE
4936 /* sync mute LED */
4937 if (spec->gpio_led && codec->patch_ops.check_power_status)
4938 codec->patch_ops.check_power_status(codec, 0x01);
4939 #endif
4940 return 0;
4944 * using power check for controlling mute led of HP notebooks
4945 * check for mute state only on Speakers (nid = 0x10)
4947 * For this feature CONFIG_SND_HDA_POWER_SAVE is needed, otherwise
4948 * the LED is NOT working properly !
4950 * Changed name to reflect that it now works for any designated
4951 * model, not just HP HDX.
4954 #ifdef CONFIG_SND_HDA_POWER_SAVE
4955 static int stac92xx_hp_check_power_status(struct hda_codec *codec,
4956 hda_nid_t nid)
4958 struct sigmatel_spec *spec = codec->spec;
4959 int i, muted = 1;
4961 for (i = 0; i < spec->multiout.num_dacs; i++) {
4962 nid = spec->multiout.dac_nids[i];
4963 if (!(snd_hda_codec_amp_read(codec, nid, 0, HDA_OUTPUT, 0) &
4964 HDA_AMP_MUTE)) {
4965 muted = 0; /* something heard */
4966 break;
4969 if (muted)
4970 spec->gpio_data &= ~spec->gpio_led; /* orange */
4971 else
4972 spec->gpio_data |= spec->gpio_led; /* white */
4974 if (!spec->gpio_led_polarity) {
4975 /* LED state is inverted on these systems */
4976 spec->gpio_data ^= spec->gpio_led;
4979 stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, spec->gpio_data);
4980 return 0;
4982 #endif
4984 static int stac92xx_suspend(struct hda_codec *codec, pm_message_t state)
4986 stac92xx_shutup(codec);
4987 return 0;
4989 #endif
4991 static struct hda_codec_ops stac92xx_patch_ops = {
4992 .build_controls = stac92xx_build_controls,
4993 .build_pcms = stac92xx_build_pcms,
4994 .init = stac92xx_init,
4995 .free = stac92xx_free,
4996 .unsol_event = stac92xx_unsol_event,
4997 #ifdef SND_HDA_NEEDS_RESUME
4998 .suspend = stac92xx_suspend,
4999 .resume = stac92xx_resume,
5000 #endif
5001 .reboot_notify = stac92xx_shutup,
5004 static int patch_stac9200(struct hda_codec *codec)
5006 struct sigmatel_spec *spec;
5007 int err;
5009 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5010 if (spec == NULL)
5011 return -ENOMEM;
5013 codec->no_trigger_sense = 1;
5014 codec->spec = spec;
5015 spec->num_pins = ARRAY_SIZE(stac9200_pin_nids);
5016 spec->pin_nids = stac9200_pin_nids;
5017 spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS,
5018 stac9200_models,
5019 stac9200_cfg_tbl);
5020 if (spec->board_config < 0)
5021 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5022 codec->chip_name);
5023 else
5024 stac92xx_set_config_regs(codec,
5025 stac9200_brd_tbl[spec->board_config]);
5027 spec->multiout.max_channels = 2;
5028 spec->multiout.num_dacs = 1;
5029 spec->multiout.dac_nids = stac9200_dac_nids;
5030 spec->adc_nids = stac9200_adc_nids;
5031 spec->mux_nids = stac9200_mux_nids;
5032 spec->num_muxes = 1;
5033 spec->num_dmics = 0;
5034 spec->num_adcs = 1;
5035 spec->num_pwrs = 0;
5037 if (spec->board_config == STAC_9200_M4 ||
5038 spec->board_config == STAC_9200_M4_2 ||
5039 spec->board_config == STAC_9200_OQO)
5040 spec->init = stac9200_eapd_init;
5041 else
5042 spec->init = stac9200_core_init;
5043 spec->mixer = stac9200_mixer;
5045 if (spec->board_config == STAC_9200_PANASONIC) {
5046 spec->gpio_mask = spec->gpio_dir = 0x09;
5047 spec->gpio_data = 0x00;
5050 err = stac9200_parse_auto_config(codec);
5051 if (err < 0) {
5052 stac92xx_free(codec);
5053 return err;
5056 /* CF-74 has no headphone detection, and the driver should *NOT*
5057 * do detection and HP/speaker toggle because the hardware does it.
5059 if (spec->board_config == STAC_9200_PANASONIC)
5060 spec->hp_detect = 0;
5062 codec->patch_ops = stac92xx_patch_ops;
5064 return 0;
5067 static int patch_stac925x(struct hda_codec *codec)
5069 struct sigmatel_spec *spec;
5070 int err;
5072 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5073 if (spec == NULL)
5074 return -ENOMEM;
5076 codec->no_trigger_sense = 1;
5077 codec->spec = spec;
5078 spec->num_pins = ARRAY_SIZE(stac925x_pin_nids);
5079 spec->pin_nids = stac925x_pin_nids;
5081 /* Check first for codec ID */
5082 spec->board_config = snd_hda_check_board_codec_sid_config(codec,
5083 STAC_925x_MODELS,
5084 stac925x_models,
5085 stac925x_codec_id_cfg_tbl);
5087 /* Now checks for PCI ID, if codec ID is not found */
5088 if (spec->board_config < 0)
5089 spec->board_config = snd_hda_check_board_config(codec,
5090 STAC_925x_MODELS,
5091 stac925x_models,
5092 stac925x_cfg_tbl);
5093 again:
5094 if (spec->board_config < 0)
5095 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5096 codec->chip_name);
5097 else
5098 stac92xx_set_config_regs(codec,
5099 stac925x_brd_tbl[spec->board_config]);
5101 spec->multiout.max_channels = 2;
5102 spec->multiout.num_dacs = 1;
5103 spec->multiout.dac_nids = stac925x_dac_nids;
5104 spec->adc_nids = stac925x_adc_nids;
5105 spec->mux_nids = stac925x_mux_nids;
5106 spec->num_muxes = 1;
5107 spec->num_adcs = 1;
5108 spec->num_pwrs = 0;
5109 switch (codec->vendor_id) {
5110 case 0x83847632: /* STAC9202 */
5111 case 0x83847633: /* STAC9202D */
5112 case 0x83847636: /* STAC9251 */
5113 case 0x83847637: /* STAC9251D */
5114 spec->num_dmics = STAC925X_NUM_DMICS;
5115 spec->dmic_nids = stac925x_dmic_nids;
5116 spec->num_dmuxes = ARRAY_SIZE(stac925x_dmux_nids);
5117 spec->dmux_nids = stac925x_dmux_nids;
5118 break;
5119 default:
5120 spec->num_dmics = 0;
5121 break;
5124 spec->init = stac925x_core_init;
5125 spec->mixer = stac925x_mixer;
5126 spec->num_caps = 1;
5127 spec->capvols = stac925x_capvols;
5128 spec->capsws = stac925x_capsws;
5130 err = stac92xx_parse_auto_config(codec, 0x8, 0x7);
5131 if (!err) {
5132 if (spec->board_config < 0) {
5133 printk(KERN_WARNING "hda_codec: No auto-config is "
5134 "available, default to model=ref\n");
5135 spec->board_config = STAC_925x_REF;
5136 goto again;
5138 err = -EINVAL;
5140 if (err < 0) {
5141 stac92xx_free(codec);
5142 return err;
5145 codec->patch_ops = stac92xx_patch_ops;
5147 return 0;
5150 static int patch_stac92hd73xx(struct hda_codec *codec)
5152 struct sigmatel_spec *spec;
5153 hda_nid_t conn[STAC92HD73_DAC_COUNT + 2];
5154 int err = 0;
5155 int num_dacs;
5157 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5158 if (spec == NULL)
5159 return -ENOMEM;
5161 codec->no_trigger_sense = 1;
5162 codec->spec = spec;
5163 codec->slave_dig_outs = stac92hd73xx_slave_dig_outs;
5164 spec->num_pins = ARRAY_SIZE(stac92hd73xx_pin_nids);
5165 spec->pin_nids = stac92hd73xx_pin_nids;
5166 spec->board_config = snd_hda_check_board_config(codec,
5167 STAC_92HD73XX_MODELS,
5168 stac92hd73xx_models,
5169 stac92hd73xx_cfg_tbl);
5170 /* check codec subsystem id if not found */
5171 if (spec->board_config < 0)
5172 spec->board_config =
5173 snd_hda_check_board_codec_sid_config(codec,
5174 STAC_92HD73XX_MODELS, stac92hd73xx_models,
5175 stac92hd73xx_codec_id_cfg_tbl);
5176 again:
5177 if (spec->board_config < 0)
5178 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5179 codec->chip_name);
5180 else
5181 stac92xx_set_config_regs(codec,
5182 stac92hd73xx_brd_tbl[spec->board_config]);
5184 num_dacs = snd_hda_get_connections(codec, 0x0a,
5185 conn, STAC92HD73_DAC_COUNT + 2) - 1;
5187 if (num_dacs < 3 || num_dacs > 5) {
5188 printk(KERN_WARNING "hda_codec: Could not determine "
5189 "number of channels defaulting to DAC count\n");
5190 num_dacs = STAC92HD73_DAC_COUNT;
5192 spec->init = stac92hd73xx_core_init;
5193 switch (num_dacs) {
5194 case 0x3: /* 6 Channel */
5195 spec->aloopback_ctl = stac92hd73xx_6ch_loopback;
5196 break;
5197 case 0x4: /* 8 Channel */
5198 spec->aloopback_ctl = stac92hd73xx_8ch_loopback;
5199 break;
5200 case 0x5: /* 10 Channel */
5201 spec->aloopback_ctl = stac92hd73xx_10ch_loopback;
5202 break;
5204 spec->multiout.dac_nids = spec->dac_nids;
5206 spec->aloopback_mask = 0x01;
5207 spec->aloopback_shift = 8;
5209 spec->digbeep_nid = 0x1c;
5210 spec->mux_nids = stac92hd73xx_mux_nids;
5211 spec->adc_nids = stac92hd73xx_adc_nids;
5212 spec->dmic_nids = stac92hd73xx_dmic_nids;
5213 spec->dmux_nids = stac92hd73xx_dmux_nids;
5214 spec->smux_nids = stac92hd73xx_smux_nids;
5216 spec->num_muxes = ARRAY_SIZE(stac92hd73xx_mux_nids);
5217 spec->num_adcs = ARRAY_SIZE(stac92hd73xx_adc_nids);
5218 spec->num_dmuxes = ARRAY_SIZE(stac92hd73xx_dmux_nids);
5220 spec->num_caps = STAC92HD73XX_NUM_CAPS;
5221 spec->capvols = stac92hd73xx_capvols;
5222 spec->capsws = stac92hd73xx_capsws;
5224 switch (spec->board_config) {
5225 case STAC_DELL_EQ:
5226 spec->init = dell_eq_core_init;
5227 /* fallthru */
5228 case STAC_DELL_M6_AMIC:
5229 case STAC_DELL_M6_DMIC:
5230 case STAC_DELL_M6_BOTH:
5231 spec->num_smuxes = 0;
5232 spec->eapd_switch = 0;
5234 switch (spec->board_config) {
5235 case STAC_DELL_M6_AMIC: /* Analog Mics */
5236 snd_hda_codec_set_pincfg(codec, 0x0b, 0x90A70170);
5237 spec->num_dmics = 0;
5238 break;
5239 case STAC_DELL_M6_DMIC: /* Digital Mics */
5240 snd_hda_codec_set_pincfg(codec, 0x13, 0x90A60160);
5241 spec->num_dmics = 1;
5242 break;
5243 case STAC_DELL_M6_BOTH: /* Both */
5244 snd_hda_codec_set_pincfg(codec, 0x0b, 0x90A70170);
5245 snd_hda_codec_set_pincfg(codec, 0x13, 0x90A60160);
5246 spec->num_dmics = 1;
5247 break;
5249 break;
5250 case STAC_ALIENWARE_M17X:
5251 spec->num_dmics = STAC92HD73XX_NUM_DMICS;
5252 spec->num_smuxes = ARRAY_SIZE(stac92hd73xx_smux_nids);
5253 spec->eapd_switch = 0;
5254 break;
5255 default:
5256 spec->num_dmics = STAC92HD73XX_NUM_DMICS;
5257 spec->num_smuxes = ARRAY_SIZE(stac92hd73xx_smux_nids);
5258 spec->eapd_switch = 1;
5259 break;
5261 if (spec->board_config != STAC_92HD73XX_REF) {
5262 /* GPIO0 High = Enable EAPD */
5263 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
5264 spec->gpio_data = 0x01;
5267 spec->num_pwrs = ARRAY_SIZE(stac92hd73xx_pwr_nids);
5268 spec->pwr_nids = stac92hd73xx_pwr_nids;
5270 err = stac92xx_parse_auto_config(codec, 0x25, 0x27);
5272 if (!err) {
5273 if (spec->board_config < 0) {
5274 printk(KERN_WARNING "hda_codec: No auto-config is "
5275 "available, default to model=ref\n");
5276 spec->board_config = STAC_92HD73XX_REF;
5277 goto again;
5279 err = -EINVAL;
5282 if (err < 0) {
5283 stac92xx_free(codec);
5284 return err;
5287 if (spec->board_config == STAC_92HD73XX_NO_JD)
5288 spec->hp_detect = 0;
5290 codec->patch_ops = stac92xx_patch_ops;
5292 codec->proc_widget_hook = stac92hd7x_proc_hook;
5294 return 0;
5297 static int patch_stac92hd83xxx(struct hda_codec *codec)
5299 struct sigmatel_spec *spec;
5300 hda_nid_t conn[STAC92HD83_DAC_COUNT + 1];
5301 int err;
5302 int num_dacs;
5304 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5305 if (spec == NULL)
5306 return -ENOMEM;
5308 codec->no_trigger_sense = 1;
5309 codec->spec = spec;
5310 codec->slave_dig_outs = stac92hd83xxx_slave_dig_outs;
5311 spec->digbeep_nid = 0x21;
5312 spec->mux_nids = stac92hd83xxx_mux_nids;
5313 spec->num_muxes = ARRAY_SIZE(stac92hd83xxx_mux_nids);
5314 spec->adc_nids = stac92hd83xxx_adc_nids;
5315 spec->num_adcs = ARRAY_SIZE(stac92hd83xxx_adc_nids);
5316 spec->pwr_nids = stac92hd83xxx_pwr_nids;
5317 spec->pwr_mapping = stac92hd83xxx_pwr_mapping;
5318 spec->num_pwrs = ARRAY_SIZE(stac92hd83xxx_pwr_nids);
5319 spec->multiout.dac_nids = spec->dac_nids;
5321 spec->init = stac92hd83xxx_core_init;
5322 spec->num_pins = ARRAY_SIZE(stac92hd83xxx_pin_nids);
5323 spec->pin_nids = stac92hd83xxx_pin_nids;
5324 spec->num_caps = STAC92HD83XXX_NUM_CAPS;
5325 spec->capvols = stac92hd83xxx_capvols;
5326 spec->capsws = stac92hd83xxx_capsws;
5328 spec->board_config = snd_hda_check_board_config(codec,
5329 STAC_92HD83XXX_MODELS,
5330 stac92hd83xxx_models,
5331 stac92hd83xxx_cfg_tbl);
5332 again:
5333 if (spec->board_config < 0)
5334 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5335 codec->chip_name);
5336 else
5337 stac92xx_set_config_regs(codec,
5338 stac92hd83xxx_brd_tbl[spec->board_config]);
5340 switch (codec->vendor_id) {
5341 case 0x111d7666:
5342 case 0x111d7667:
5343 case 0x111d7668:
5344 case 0x111d7669:
5345 spec->num_pins = ARRAY_SIZE(stac92hd88xxx_pin_nids);
5346 spec->pin_nids = stac92hd88xxx_pin_nids;
5347 spec->mono_nid = 0;
5348 spec->digbeep_nid = 0;
5349 spec->num_pwrs = 0;
5350 break;
5351 case 0x111d7604:
5352 case 0x111d76d4:
5353 case 0x111d7605:
5354 case 0x111d76d5:
5355 if (spec->board_config == STAC_92HD83XXX_PWR_REF)
5356 break;
5357 spec->num_pwrs = 0;
5358 break;
5361 codec->patch_ops = stac92xx_patch_ops;
5363 if (find_mute_led_gpio(codec, 0))
5364 snd_printd("mute LED gpio %d polarity %d\n",
5365 spec->gpio_led,
5366 spec->gpio_led_polarity);
5368 #ifdef CONFIG_SND_HDA_POWER_SAVE
5369 if (spec->gpio_led) {
5370 spec->gpio_mask |= spec->gpio_led;
5371 spec->gpio_dir |= spec->gpio_led;
5372 spec->gpio_data |= spec->gpio_led;
5373 /* register check_power_status callback. */
5374 codec->patch_ops.check_power_status =
5375 stac92xx_hp_check_power_status;
5377 #endif
5379 err = stac92xx_parse_auto_config(codec, 0x1d, 0);
5380 if (!err) {
5381 if (spec->board_config < 0) {
5382 printk(KERN_WARNING "hda_codec: No auto-config is "
5383 "available, default to model=ref\n");
5384 spec->board_config = STAC_92HD83XXX_REF;
5385 goto again;
5387 err = -EINVAL;
5390 if (err < 0) {
5391 stac92xx_free(codec);
5392 return err;
5395 /* docking output support */
5396 num_dacs = snd_hda_get_connections(codec, 0xF,
5397 conn, STAC92HD83_DAC_COUNT + 1) - 1;
5398 /* skip non-DAC connections */
5399 while (num_dacs >= 0 &&
5400 (get_wcaps_type(get_wcaps(codec, conn[num_dacs]))
5401 != AC_WID_AUD_OUT))
5402 num_dacs--;
5403 /* set port E and F to select the last DAC */
5404 if (num_dacs >= 0) {
5405 snd_hda_codec_write_cache(codec, 0xE, 0,
5406 AC_VERB_SET_CONNECT_SEL, num_dacs);
5407 snd_hda_codec_write_cache(codec, 0xF, 0,
5408 AC_VERB_SET_CONNECT_SEL, num_dacs);
5411 codec->proc_widget_hook = stac92hd_proc_hook;
5413 return 0;
5416 /* get the pin connection (fixed, none, etc) */
5417 static unsigned int stac_get_defcfg_connect(struct hda_codec *codec, int idx)
5419 struct sigmatel_spec *spec = codec->spec;
5420 unsigned int cfg;
5422 cfg = snd_hda_codec_get_pincfg(codec, spec->pin_nids[idx]);
5423 return get_defcfg_connect(cfg);
5426 static int stac92hd71bxx_connected_ports(struct hda_codec *codec,
5427 hda_nid_t *nids, int num_nids)
5429 struct sigmatel_spec *spec = codec->spec;
5430 int idx, num;
5431 unsigned int def_conf;
5433 for (num = 0; num < num_nids; num++) {
5434 for (idx = 0; idx < spec->num_pins; idx++)
5435 if (spec->pin_nids[idx] == nids[num])
5436 break;
5437 if (idx >= spec->num_pins)
5438 break;
5439 def_conf = stac_get_defcfg_connect(codec, idx);
5440 if (def_conf == AC_JACK_PORT_NONE)
5441 break;
5443 return num;
5446 static int stac92hd71bxx_connected_smuxes(struct hda_codec *codec,
5447 hda_nid_t dig0pin)
5449 struct sigmatel_spec *spec = codec->spec;
5450 int idx;
5452 for (idx = 0; idx < spec->num_pins; idx++)
5453 if (spec->pin_nids[idx] == dig0pin)
5454 break;
5455 if ((idx + 2) >= spec->num_pins)
5456 return 0;
5458 /* dig1pin case */
5459 if (stac_get_defcfg_connect(codec, idx + 1) != AC_JACK_PORT_NONE)
5460 return 2;
5462 /* dig0pin + dig2pin case */
5463 if (stac_get_defcfg_connect(codec, idx + 2) != AC_JACK_PORT_NONE)
5464 return 2;
5465 if (stac_get_defcfg_connect(codec, idx) != AC_JACK_PORT_NONE)
5466 return 1;
5467 else
5468 return 0;
5471 /* HP dv7 bass switch - GPIO5 */
5472 #define stac_hp_bass_gpio_info snd_ctl_boolean_mono_info
5473 static int stac_hp_bass_gpio_get(struct snd_kcontrol *kcontrol,
5474 struct snd_ctl_elem_value *ucontrol)
5476 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5477 struct sigmatel_spec *spec = codec->spec;
5478 ucontrol->value.integer.value[0] = !!(spec->gpio_data & 0x20);
5479 return 0;
5482 static int stac_hp_bass_gpio_put(struct snd_kcontrol *kcontrol,
5483 struct snd_ctl_elem_value *ucontrol)
5485 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5486 struct sigmatel_spec *spec = codec->spec;
5487 unsigned int gpio_data;
5489 gpio_data = (spec->gpio_data & ~0x20) |
5490 (ucontrol->value.integer.value[0] ? 0x20 : 0);
5491 if (gpio_data == spec->gpio_data)
5492 return 0;
5493 spec->gpio_data = gpio_data;
5494 stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, spec->gpio_data);
5495 return 1;
5498 static struct snd_kcontrol_new stac_hp_bass_sw_ctrl = {
5499 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5500 .info = stac_hp_bass_gpio_info,
5501 .get = stac_hp_bass_gpio_get,
5502 .put = stac_hp_bass_gpio_put,
5505 static int stac_add_hp_bass_switch(struct hda_codec *codec)
5507 struct sigmatel_spec *spec = codec->spec;
5509 if (!stac_control_new(spec, &stac_hp_bass_sw_ctrl,
5510 "Bass Speaker Playback Switch", 0))
5511 return -ENOMEM;
5513 spec->gpio_mask |= 0x20;
5514 spec->gpio_dir |= 0x20;
5515 spec->gpio_data |= 0x20;
5516 return 0;
5519 static int patch_stac92hd71bxx(struct hda_codec *codec)
5521 struct sigmatel_spec *spec;
5522 struct hda_verb *unmute_init = stac92hd71bxx_unmute_core_init;
5523 unsigned int pin_cfg;
5524 int err = 0;
5526 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5527 if (spec == NULL)
5528 return -ENOMEM;
5530 codec->no_trigger_sense = 1;
5531 codec->spec = spec;
5532 codec->patch_ops = stac92xx_patch_ops;
5533 spec->num_pins = STAC92HD71BXX_NUM_PINS;
5534 switch (codec->vendor_id) {
5535 case 0x111d76b6:
5536 case 0x111d76b7:
5537 spec->pin_nids = stac92hd71bxx_pin_nids_4port;
5538 break;
5539 case 0x111d7603:
5540 case 0x111d7608:
5541 /* On 92HD75Bx 0x27 isn't a pin nid */
5542 spec->num_pins--;
5543 /* fallthrough */
5544 default:
5545 spec->pin_nids = stac92hd71bxx_pin_nids_6port;
5547 spec->num_pwrs = ARRAY_SIZE(stac92hd71bxx_pwr_nids);
5548 spec->board_config = snd_hda_check_board_config(codec,
5549 STAC_92HD71BXX_MODELS,
5550 stac92hd71bxx_models,
5551 stac92hd71bxx_cfg_tbl);
5552 again:
5553 if (spec->board_config < 0)
5554 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5555 codec->chip_name);
5556 else
5557 stac92xx_set_config_regs(codec,
5558 stac92hd71bxx_brd_tbl[spec->board_config]);
5560 if (spec->board_config != STAC_92HD71BXX_REF) {
5561 /* GPIO0 = EAPD */
5562 spec->gpio_mask = 0x01;
5563 spec->gpio_dir = 0x01;
5564 spec->gpio_data = 0x01;
5567 spec->dmic_nids = stac92hd71bxx_dmic_nids;
5568 spec->dmux_nids = stac92hd71bxx_dmux_nids;
5570 spec->num_caps = STAC92HD71BXX_NUM_CAPS;
5571 spec->capvols = stac92hd71bxx_capvols;
5572 spec->capsws = stac92hd71bxx_capsws;
5574 switch (codec->vendor_id) {
5575 case 0x111d76b6: /* 4 Port without Analog Mixer */
5576 case 0x111d76b7:
5577 unmute_init++;
5578 /* fallthru */
5579 case 0x111d76b4: /* 6 Port without Analog Mixer */
5580 case 0x111d76b5:
5581 spec->init = stac92hd71bxx_core_init;
5582 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
5583 spec->num_dmics = stac92hd71bxx_connected_ports(codec,
5584 stac92hd71bxx_dmic_nids,
5585 STAC92HD71BXX_NUM_DMICS);
5586 break;
5587 case 0x111d7608: /* 5 Port with Analog Mixer */
5588 switch (spec->board_config) {
5589 case STAC_HP_M4:
5590 /* Enable VREF power saving on GPIO1 detect */
5591 err = stac_add_event(spec, codec->afg,
5592 STAC_VREF_EVENT, 0x02);
5593 if (err < 0)
5594 return err;
5595 snd_hda_codec_write_cache(codec, codec->afg, 0,
5596 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x02);
5597 snd_hda_codec_write_cache(codec, codec->afg, 0,
5598 AC_VERB_SET_UNSOLICITED_ENABLE,
5599 AC_USRSP_EN | err);
5600 spec->gpio_mask |= 0x02;
5601 break;
5603 if ((codec->revision_id & 0xf) == 0 ||
5604 (codec->revision_id & 0xf) == 1)
5605 spec->stream_delay = 40; /* 40 milliseconds */
5607 /* no output amps */
5608 spec->num_pwrs = 0;
5609 /* disable VSW */
5610 spec->init = stac92hd71bxx_core_init;
5611 unmute_init++;
5612 snd_hda_codec_set_pincfg(codec, 0x0f, 0x40f000f0);
5613 snd_hda_codec_set_pincfg(codec, 0x19, 0x40f000f3);
5614 stac92hd71bxx_dmic_nids[STAC92HD71BXX_NUM_DMICS - 1] = 0;
5615 spec->num_dmics = stac92hd71bxx_connected_ports(codec,
5616 stac92hd71bxx_dmic_nids,
5617 STAC92HD71BXX_NUM_DMICS - 1);
5618 break;
5619 case 0x111d7603: /* 6 Port with Analog Mixer */
5620 if ((codec->revision_id & 0xf) == 1)
5621 spec->stream_delay = 40; /* 40 milliseconds */
5623 /* no output amps */
5624 spec->num_pwrs = 0;
5625 /* fallthru */
5626 default:
5627 spec->init = stac92hd71bxx_core_init;
5628 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
5629 spec->num_dmics = stac92hd71bxx_connected_ports(codec,
5630 stac92hd71bxx_dmic_nids,
5631 STAC92HD71BXX_NUM_DMICS);
5632 break;
5635 if (get_wcaps(codec, 0xa) & AC_WCAP_IN_AMP)
5636 snd_hda_sequence_write_cache(codec, unmute_init);
5638 /* Some HP machines seem to have unstable codec communications
5639 * especially with ATI fglrx driver. For recovering from the
5640 * CORB/RIRB stall, allow the BUS reset and keep always sync
5642 if (spec->board_config == STAC_HP_DV5) {
5643 codec->bus->sync_write = 1;
5644 codec->bus->allow_bus_reset = 1;
5647 spec->aloopback_ctl = stac92hd71bxx_loopback;
5648 spec->aloopback_mask = 0x50;
5649 spec->aloopback_shift = 0;
5651 spec->powerdown_adcs = 1;
5652 spec->digbeep_nid = 0x26;
5653 spec->mux_nids = stac92hd71bxx_mux_nids;
5654 spec->adc_nids = stac92hd71bxx_adc_nids;
5655 spec->smux_nids = stac92hd71bxx_smux_nids;
5656 spec->pwr_nids = stac92hd71bxx_pwr_nids;
5658 spec->num_muxes = ARRAY_SIZE(stac92hd71bxx_mux_nids);
5659 spec->num_adcs = ARRAY_SIZE(stac92hd71bxx_adc_nids);
5660 spec->num_dmuxes = ARRAY_SIZE(stac92hd71bxx_dmux_nids);
5661 spec->num_smuxes = stac92hd71bxx_connected_smuxes(codec, 0x1e);
5663 snd_printdd("Found board config: %d\n", spec->board_config);
5665 switch (spec->board_config) {
5666 case STAC_HP_M4:
5667 /* enable internal microphone */
5668 snd_hda_codec_set_pincfg(codec, 0x0e, 0x01813040);
5669 stac92xx_auto_set_pinctl(codec, 0x0e,
5670 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80);
5671 /* fallthru */
5672 case STAC_DELL_M4_2:
5673 spec->num_dmics = 0;
5674 spec->num_smuxes = 0;
5675 spec->num_dmuxes = 0;
5676 break;
5677 case STAC_DELL_M4_1:
5678 case STAC_DELL_M4_3:
5679 spec->num_dmics = 1;
5680 spec->num_smuxes = 0;
5681 spec->num_dmuxes = 1;
5682 break;
5683 case STAC_HP_DV4_1222NR:
5684 spec->num_dmics = 1;
5685 /* I don't know if it needs 1 or 2 smuxes - will wait for
5686 * bug reports to fix if needed
5688 spec->num_smuxes = 1;
5689 spec->num_dmuxes = 1;
5690 /* fallthrough */
5691 case STAC_HP_DV4:
5692 spec->gpio_led = 0x01;
5693 /* fallthrough */
5694 case STAC_HP_DV5:
5695 snd_hda_codec_set_pincfg(codec, 0x0d, 0x90170010);
5696 stac92xx_auto_set_pinctl(codec, 0x0d, AC_PINCTL_OUT_EN);
5697 /* HP dv6 gives the headphone pin as a line-out. Thus we
5698 * need to set hp_detect flag here to force to enable HP
5699 * detection.
5701 spec->hp_detect = 1;
5702 break;
5703 case STAC_HP_HDX:
5704 spec->num_dmics = 1;
5705 spec->num_dmuxes = 1;
5706 spec->num_smuxes = 1;
5707 spec->gpio_led = 0x08;
5708 break;
5711 if (hp_blike_system(codec->subsystem_id)) {
5712 pin_cfg = snd_hda_codec_get_pincfg(codec, 0x0f);
5713 if (get_defcfg_device(pin_cfg) == AC_JACK_LINE_OUT ||
5714 get_defcfg_device(pin_cfg) == AC_JACK_SPEAKER ||
5715 get_defcfg_device(pin_cfg) == AC_JACK_HP_OUT) {
5716 /* It was changed in the BIOS to just satisfy MS DTM.
5717 * Lets turn it back into slaved HP
5719 pin_cfg = (pin_cfg & (~AC_DEFCFG_DEVICE))
5720 | (AC_JACK_HP_OUT <<
5721 AC_DEFCFG_DEVICE_SHIFT);
5722 pin_cfg = (pin_cfg & (~(AC_DEFCFG_DEF_ASSOC
5723 | AC_DEFCFG_SEQUENCE)))
5724 | 0x1f;
5725 snd_hda_codec_set_pincfg(codec, 0x0f, pin_cfg);
5729 if (find_mute_led_gpio(codec, 1))
5730 snd_printd("mute LED gpio %d polarity %d\n",
5731 spec->gpio_led,
5732 spec->gpio_led_polarity);
5734 #ifdef CONFIG_SND_HDA_POWER_SAVE
5735 if (spec->gpio_led) {
5736 spec->gpio_mask |= spec->gpio_led;
5737 spec->gpio_dir |= spec->gpio_led;
5738 spec->gpio_data |= spec->gpio_led;
5739 /* register check_power_status callback. */
5740 codec->patch_ops.check_power_status =
5741 stac92xx_hp_check_power_status;
5743 #endif
5745 spec->multiout.dac_nids = spec->dac_nids;
5747 err = stac92xx_parse_auto_config(codec, 0x21, 0);
5748 if (!err) {
5749 if (spec->board_config < 0) {
5750 printk(KERN_WARNING "hda_codec: No auto-config is "
5751 "available, default to model=ref\n");
5752 spec->board_config = STAC_92HD71BXX_REF;
5753 goto again;
5755 err = -EINVAL;
5758 if (err < 0) {
5759 stac92xx_free(codec);
5760 return err;
5763 /* enable bass on HP dv7 */
5764 if (spec->board_config == STAC_HP_DV4 ||
5765 spec->board_config == STAC_HP_DV5) {
5766 unsigned int cap;
5767 cap = snd_hda_param_read(codec, 0x1, AC_PAR_GPIO_CAP);
5768 cap &= AC_GPIO_IO_COUNT;
5769 if (cap >= 6)
5770 stac_add_hp_bass_switch(codec);
5773 codec->proc_widget_hook = stac92hd7x_proc_hook;
5775 return 0;
5778 static int patch_stac922x(struct hda_codec *codec)
5780 struct sigmatel_spec *spec;
5781 int err;
5783 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5784 if (spec == NULL)
5785 return -ENOMEM;
5787 codec->no_trigger_sense = 1;
5788 codec->spec = spec;
5789 spec->num_pins = ARRAY_SIZE(stac922x_pin_nids);
5790 spec->pin_nids = stac922x_pin_nids;
5791 spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS,
5792 stac922x_models,
5793 stac922x_cfg_tbl);
5794 if (spec->board_config == STAC_INTEL_MAC_AUTO) {
5795 spec->gpio_mask = spec->gpio_dir = 0x03;
5796 spec->gpio_data = 0x03;
5797 /* Intel Macs have all same PCI SSID, so we need to check
5798 * codec SSID to distinguish the exact models
5800 printk(KERN_INFO "hda_codec: STAC922x, Apple subsys_id=%x\n", codec->subsystem_id);
5801 switch (codec->subsystem_id) {
5803 case 0x106b0800:
5804 spec->board_config = STAC_INTEL_MAC_V1;
5805 break;
5806 case 0x106b0600:
5807 case 0x106b0700:
5808 spec->board_config = STAC_INTEL_MAC_V2;
5809 break;
5810 case 0x106b0e00:
5811 case 0x106b0f00:
5812 case 0x106b1600:
5813 case 0x106b1700:
5814 case 0x106b0200:
5815 case 0x106b1e00:
5816 spec->board_config = STAC_INTEL_MAC_V3;
5817 break;
5818 case 0x106b1a00:
5819 case 0x00000100:
5820 spec->board_config = STAC_INTEL_MAC_V4;
5821 break;
5822 case 0x106b0a00:
5823 case 0x106b2200:
5824 spec->board_config = STAC_INTEL_MAC_V5;
5825 break;
5826 default:
5827 spec->board_config = STAC_INTEL_MAC_V3;
5828 break;
5832 again:
5833 if (spec->board_config < 0)
5834 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5835 codec->chip_name);
5836 else
5837 stac92xx_set_config_regs(codec,
5838 stac922x_brd_tbl[spec->board_config]);
5840 spec->adc_nids = stac922x_adc_nids;
5841 spec->mux_nids = stac922x_mux_nids;
5842 spec->num_muxes = ARRAY_SIZE(stac922x_mux_nids);
5843 spec->num_adcs = ARRAY_SIZE(stac922x_adc_nids);
5844 spec->num_dmics = 0;
5845 spec->num_pwrs = 0;
5847 spec->init = stac922x_core_init;
5849 spec->num_caps = STAC922X_NUM_CAPS;
5850 spec->capvols = stac922x_capvols;
5851 spec->capsws = stac922x_capsws;
5853 spec->multiout.dac_nids = spec->dac_nids;
5855 err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
5856 if (!err) {
5857 if (spec->board_config < 0) {
5858 printk(KERN_WARNING "hda_codec: No auto-config is "
5859 "available, default to model=ref\n");
5860 spec->board_config = STAC_D945_REF;
5861 goto again;
5863 err = -EINVAL;
5865 if (err < 0) {
5866 stac92xx_free(codec);
5867 return err;
5870 codec->patch_ops = stac92xx_patch_ops;
5872 /* Fix Mux capture level; max to 2 */
5873 snd_hda_override_amp_caps(codec, 0x12, HDA_OUTPUT,
5874 (0 << AC_AMPCAP_OFFSET_SHIFT) |
5875 (2 << AC_AMPCAP_NUM_STEPS_SHIFT) |
5876 (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5877 (0 << AC_AMPCAP_MUTE_SHIFT));
5879 return 0;
5882 static int patch_stac927x(struct hda_codec *codec)
5884 struct sigmatel_spec *spec;
5885 int err;
5887 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5888 if (spec == NULL)
5889 return -ENOMEM;
5891 codec->no_trigger_sense = 1;
5892 codec->spec = spec;
5893 codec->slave_dig_outs = stac927x_slave_dig_outs;
5894 spec->num_pins = ARRAY_SIZE(stac927x_pin_nids);
5895 spec->pin_nids = stac927x_pin_nids;
5896 spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS,
5897 stac927x_models,
5898 stac927x_cfg_tbl);
5899 again:
5900 if (spec->board_config < 0)
5901 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5902 codec->chip_name);
5903 else
5904 stac92xx_set_config_regs(codec,
5905 stac927x_brd_tbl[spec->board_config]);
5907 spec->digbeep_nid = 0x23;
5908 spec->adc_nids = stac927x_adc_nids;
5909 spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
5910 spec->mux_nids = stac927x_mux_nids;
5911 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
5912 spec->smux_nids = stac927x_smux_nids;
5913 spec->num_smuxes = ARRAY_SIZE(stac927x_smux_nids);
5914 spec->spdif_labels = stac927x_spdif_labels;
5915 spec->dac_list = stac927x_dac_nids;
5916 spec->multiout.dac_nids = spec->dac_nids;
5918 if (spec->board_config != STAC_D965_REF) {
5919 /* GPIO0 High = Enable EAPD */
5920 spec->eapd_mask = spec->gpio_mask = 0x01;
5921 spec->gpio_dir = spec->gpio_data = 0x01;
5924 switch (spec->board_config) {
5925 case STAC_D965_3ST:
5926 case STAC_D965_5ST:
5927 /* GPIO0 High = Enable EAPD */
5928 spec->num_dmics = 0;
5929 spec->init = d965_core_init;
5930 break;
5931 case STAC_DELL_BIOS:
5932 switch (codec->subsystem_id) {
5933 case 0x10280209:
5934 case 0x1028022e:
5935 /* correct the device field to SPDIF out */
5936 snd_hda_codec_set_pincfg(codec, 0x21, 0x01442070);
5937 break;
5939 /* configure the analog microphone on some laptops */
5940 snd_hda_codec_set_pincfg(codec, 0x0c, 0x90a79130);
5941 /* correct the front output jack as a hp out */
5942 snd_hda_codec_set_pincfg(codec, 0x0f, 0x0227011f);
5943 /* correct the front input jack as a mic */
5944 snd_hda_codec_set_pincfg(codec, 0x0e, 0x02a79130);
5945 /* fallthru */
5946 case STAC_DELL_3ST:
5947 if (codec->subsystem_id != 0x1028022f) {
5948 /* GPIO2 High = Enable EAPD */
5949 spec->eapd_mask = spec->gpio_mask = 0x04;
5950 spec->gpio_dir = spec->gpio_data = 0x04;
5952 spec->dmic_nids = stac927x_dmic_nids;
5953 spec->num_dmics = STAC927X_NUM_DMICS;
5955 spec->init = dell_3st_core_init;
5956 spec->dmux_nids = stac927x_dmux_nids;
5957 spec->num_dmuxes = ARRAY_SIZE(stac927x_dmux_nids);
5958 break;
5959 case STAC_927X_VOLKNOB:
5960 spec->num_dmics = 0;
5961 spec->init = stac927x_volknob_core_init;
5962 break;
5963 default:
5964 spec->num_dmics = 0;
5965 spec->init = stac927x_core_init;
5966 break;
5969 spec->num_caps = STAC927X_NUM_CAPS;
5970 spec->capvols = stac927x_capvols;
5971 spec->capsws = stac927x_capsws;
5973 spec->num_pwrs = 0;
5974 spec->aloopback_ctl = stac927x_loopback;
5975 spec->aloopback_mask = 0x40;
5976 spec->aloopback_shift = 0;
5977 spec->eapd_switch = 1;
5979 err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
5980 if (!err) {
5981 if (spec->board_config < 0) {
5982 printk(KERN_WARNING "hda_codec: No auto-config is "
5983 "available, default to model=ref\n");
5984 spec->board_config = STAC_D965_REF;
5985 goto again;
5987 err = -EINVAL;
5989 if (err < 0) {
5990 stac92xx_free(codec);
5991 return err;
5994 codec->patch_ops = stac92xx_patch_ops;
5996 codec->proc_widget_hook = stac927x_proc_hook;
5999 * !!FIXME!!
6000 * The STAC927x seem to require fairly long delays for certain
6001 * command sequences. With too short delays (even if the answer
6002 * is set to RIRB properly), it results in the silence output
6003 * on some hardwares like Dell.
6005 * The below flag enables the longer delay (see get_response
6006 * in hda_intel.c).
6008 codec->bus->needs_damn_long_delay = 1;
6010 /* no jack detecion for ref-no-jd model */
6011 if (spec->board_config == STAC_D965_REF_NO_JD)
6012 spec->hp_detect = 0;
6014 return 0;
6017 static int patch_stac9205(struct hda_codec *codec)
6019 struct sigmatel_spec *spec;
6020 int err;
6022 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6023 if (spec == NULL)
6024 return -ENOMEM;
6026 codec->no_trigger_sense = 1;
6027 codec->spec = spec;
6028 spec->num_pins = ARRAY_SIZE(stac9205_pin_nids);
6029 spec->pin_nids = stac9205_pin_nids;
6030 spec->board_config = snd_hda_check_board_config(codec, STAC_9205_MODELS,
6031 stac9205_models,
6032 stac9205_cfg_tbl);
6033 again:
6034 if (spec->board_config < 0)
6035 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6036 codec->chip_name);
6037 else
6038 stac92xx_set_config_regs(codec,
6039 stac9205_brd_tbl[spec->board_config]);
6041 spec->digbeep_nid = 0x23;
6042 spec->adc_nids = stac9205_adc_nids;
6043 spec->num_adcs = ARRAY_SIZE(stac9205_adc_nids);
6044 spec->mux_nids = stac9205_mux_nids;
6045 spec->num_muxes = ARRAY_SIZE(stac9205_mux_nids);
6046 spec->smux_nids = stac9205_smux_nids;
6047 spec->num_smuxes = ARRAY_SIZE(stac9205_smux_nids);
6048 spec->dmic_nids = stac9205_dmic_nids;
6049 spec->num_dmics = STAC9205_NUM_DMICS;
6050 spec->dmux_nids = stac9205_dmux_nids;
6051 spec->num_dmuxes = ARRAY_SIZE(stac9205_dmux_nids);
6052 spec->num_pwrs = 0;
6054 spec->init = stac9205_core_init;
6055 spec->aloopback_ctl = stac9205_loopback;
6057 spec->num_caps = STAC9205_NUM_CAPS;
6058 spec->capvols = stac9205_capvols;
6059 spec->capsws = stac9205_capsws;
6061 spec->aloopback_mask = 0x40;
6062 spec->aloopback_shift = 0;
6063 /* Turn on/off EAPD per HP plugging */
6064 if (spec->board_config != STAC_9205_EAPD)
6065 spec->eapd_switch = 1;
6066 spec->multiout.dac_nids = spec->dac_nids;
6068 switch (spec->board_config){
6069 case STAC_9205_DELL_M43:
6070 /* Enable SPDIF in/out */
6071 snd_hda_codec_set_pincfg(codec, 0x1f, 0x01441030);
6072 snd_hda_codec_set_pincfg(codec, 0x20, 0x1c410030);
6074 /* Enable unsol response for GPIO4/Dock HP connection */
6075 err = stac_add_event(spec, codec->afg, STAC_VREF_EVENT, 0x01);
6076 if (err < 0)
6077 return err;
6078 snd_hda_codec_write_cache(codec, codec->afg, 0,
6079 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x10);
6080 snd_hda_codec_write_cache(codec, codec->afg, 0,
6081 AC_VERB_SET_UNSOLICITED_ENABLE,
6082 AC_USRSP_EN | err);
6084 spec->gpio_dir = 0x0b;
6085 spec->eapd_mask = 0x01;
6086 spec->gpio_mask = 0x1b;
6087 spec->gpio_mute = 0x10;
6088 /* GPIO0 High = EAPD, GPIO1 Low = Headphone Mute,
6089 * GPIO3 Low = DRM
6091 spec->gpio_data = 0x01;
6092 break;
6093 case STAC_9205_REF:
6094 /* SPDIF-In enabled */
6095 break;
6096 default:
6097 /* GPIO0 High = EAPD */
6098 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
6099 spec->gpio_data = 0x01;
6100 break;
6103 err = stac92xx_parse_auto_config(codec, 0x1f, 0x20);
6104 if (!err) {
6105 if (spec->board_config < 0) {
6106 printk(KERN_WARNING "hda_codec: No auto-config is "
6107 "available, default to model=ref\n");
6108 spec->board_config = STAC_9205_REF;
6109 goto again;
6111 err = -EINVAL;
6113 if (err < 0) {
6114 stac92xx_free(codec);
6115 return err;
6118 codec->patch_ops = stac92xx_patch_ops;
6120 codec->proc_widget_hook = stac9205_proc_hook;
6122 return 0;
6126 * STAC9872 hack
6129 static struct hda_verb stac9872_core_init[] = {
6130 {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
6131 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
6135 static hda_nid_t stac9872_pin_nids[] = {
6136 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
6137 0x11, 0x13, 0x14,
6140 static hda_nid_t stac9872_adc_nids[] = {
6141 0x8 /*,0x6*/
6144 static hda_nid_t stac9872_mux_nids[] = {
6145 0x15
6148 static unsigned long stac9872_capvols[] = {
6149 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
6151 #define stac9872_capsws stac9872_capvols
6153 static unsigned int stac9872_vaio_pin_configs[9] = {
6154 0x03211020, 0x411111f0, 0x411111f0, 0x03a15030,
6155 0x411111f0, 0x90170110, 0x411111f0, 0x411111f0,
6156 0x90a7013e
6159 static const char *stac9872_models[STAC_9872_MODELS] = {
6160 [STAC_9872_AUTO] = "auto",
6161 [STAC_9872_VAIO] = "vaio",
6164 static unsigned int *stac9872_brd_tbl[STAC_9872_MODELS] = {
6165 [STAC_9872_VAIO] = stac9872_vaio_pin_configs,
6168 static struct snd_pci_quirk stac9872_cfg_tbl[] = {
6169 SND_PCI_QUIRK_MASK(0x104d, 0xfff0, 0x81e0,
6170 "Sony VAIO F/S", STAC_9872_VAIO),
6171 {} /* terminator */
6174 static int patch_stac9872(struct hda_codec *codec)
6176 struct sigmatel_spec *spec;
6177 int err;
6179 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6180 if (spec == NULL)
6181 return -ENOMEM;
6182 codec->no_trigger_sense = 1;
6183 codec->spec = spec;
6184 spec->num_pins = ARRAY_SIZE(stac9872_pin_nids);
6185 spec->pin_nids = stac9872_pin_nids;
6187 spec->board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
6188 stac9872_models,
6189 stac9872_cfg_tbl);
6190 if (spec->board_config < 0)
6191 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6192 codec->chip_name);
6193 else
6194 stac92xx_set_config_regs(codec,
6195 stac9872_brd_tbl[spec->board_config]);
6197 spec->multiout.dac_nids = spec->dac_nids;
6198 spec->num_adcs = ARRAY_SIZE(stac9872_adc_nids);
6199 spec->adc_nids = stac9872_adc_nids;
6200 spec->num_muxes = ARRAY_SIZE(stac9872_mux_nids);
6201 spec->mux_nids = stac9872_mux_nids;
6202 spec->init = stac9872_core_init;
6203 spec->num_caps = 1;
6204 spec->capvols = stac9872_capvols;
6205 spec->capsws = stac9872_capsws;
6207 err = stac92xx_parse_auto_config(codec, 0x10, 0x12);
6208 if (err < 0) {
6209 stac92xx_free(codec);
6210 return -EINVAL;
6212 spec->input_mux = &spec->private_imux;
6213 codec->patch_ops = stac92xx_patch_ops;
6214 return 0;
6219 * patch entries
6221 static struct hda_codec_preset snd_hda_preset_sigmatel[] = {
6222 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
6223 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
6224 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
6225 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
6226 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
6227 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
6228 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
6229 { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
6230 { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
6231 { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
6232 { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
6233 { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
6234 { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
6235 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
6236 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
6237 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
6238 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
6239 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
6240 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
6241 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
6242 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
6243 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
6244 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
6245 { .id = 0x83847632, .name = "STAC9202", .patch = patch_stac925x },
6246 { .id = 0x83847633, .name = "STAC9202D", .patch = patch_stac925x },
6247 { .id = 0x83847634, .name = "STAC9250", .patch = patch_stac925x },
6248 { .id = 0x83847635, .name = "STAC9250D", .patch = patch_stac925x },
6249 { .id = 0x83847636, .name = "STAC9251", .patch = patch_stac925x },
6250 { .id = 0x83847637, .name = "STAC9250D", .patch = patch_stac925x },
6251 { .id = 0x83847645, .name = "92HD206X", .patch = patch_stac927x },
6252 { .id = 0x83847646, .name = "92HD206D", .patch = patch_stac927x },
6253 /* The following does not take into account .id=0x83847661 when subsys =
6254 * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
6255 * currently not fully supported.
6257 { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
6258 { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
6259 { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
6260 { .id = 0x83847698, .name = "STAC9205", .patch = patch_stac9205 },
6261 { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
6262 { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
6263 { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
6264 { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
6265 { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
6266 { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
6267 { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
6268 { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
6269 { .id = 0x111d7603, .name = "92HD75B3X5", .patch = patch_stac92hd71bxx},
6270 { .id = 0x111d7604, .name = "92HD83C1X5", .patch = patch_stac92hd83xxx},
6271 { .id = 0x111d76d4, .name = "92HD83C1C5", .patch = patch_stac92hd83xxx},
6272 { .id = 0x111d7605, .name = "92HD81B1X5", .patch = patch_stac92hd83xxx},
6273 { .id = 0x111d76d5, .name = "92HD81B1C5", .patch = patch_stac92hd83xxx},
6274 { .id = 0x111d7666, .name = "92HD88B3", .patch = patch_stac92hd83xxx},
6275 { .id = 0x111d7667, .name = "92HD88B1", .patch = patch_stac92hd83xxx},
6276 { .id = 0x111d7668, .name = "92HD88B2", .patch = patch_stac92hd83xxx},
6277 { .id = 0x111d7669, .name = "92HD88B4", .patch = patch_stac92hd83xxx},
6278 { .id = 0x111d7608, .name = "92HD75B2X5", .patch = patch_stac92hd71bxx},
6279 { .id = 0x111d7674, .name = "92HD73D1X5", .patch = patch_stac92hd73xx },
6280 { .id = 0x111d7675, .name = "92HD73C1X5", .patch = patch_stac92hd73xx },
6281 { .id = 0x111d7676, .name = "92HD73E1X5", .patch = patch_stac92hd73xx },
6282 { .id = 0x111d76b0, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
6283 { .id = 0x111d76b1, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
6284 { .id = 0x111d76b2, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
6285 { .id = 0x111d76b3, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
6286 { .id = 0x111d76b4, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
6287 { .id = 0x111d76b5, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
6288 { .id = 0x111d76b6, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
6289 { .id = 0x111d76b7, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
6290 {} /* terminator */
6293 MODULE_ALIAS("snd-hda-codec-id:8384*");
6294 MODULE_ALIAS("snd-hda-codec-id:111d*");
6296 MODULE_LICENSE("GPL");
6297 MODULE_DESCRIPTION("IDT/Sigmatel HD-audio codec");
6299 static struct hda_codec_preset_list sigmatel_list = {
6300 .preset = snd_hda_preset_sigmatel,
6301 .owner = THIS_MODULE,
6304 static int __init patch_sigmatel_init(void)
6306 return snd_hda_add_codec_preset(&sigmatel_list);
6309 static void __exit patch_sigmatel_exit(void)
6311 snd_hda_delete_codec_preset(&sigmatel_list);
6314 module_init(patch_sigmatel_init)
6315 module_exit(patch_sigmatel_exit)