ASoC: multi-component - ASoC Multi-Component Support
[linux-2.6/cjktty.git] / sound / pci / hda / patch_sigmatel.c
blobf1e7babd6920048b5238b21e5a31ee936ab4b3a0
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;
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 imux = spec->dinput_mux;
752 /* 0 = analog */
753 snd_hda_codec_write_cache(codec,
754 spec->dmux_nids[adc_idx], 0,
755 AC_VERB_SET_CONNECT_SEL,
756 imux->items[0].index);
758 } else {
759 imux = spec->dinput_mux;
760 snd_hda_codec_write_cache(codec, spec->dmux_nids[adc_idx], 0,
761 AC_VERB_SET_CONNECT_SEL,
762 imux->items[idx - 1].index);
764 spec->cur_mux[adc_idx] = idx;
765 return 1;
768 static int stac92xx_mono_mux_enum_info(struct snd_kcontrol *kcontrol,
769 struct snd_ctl_elem_info *uinfo)
771 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
772 struct sigmatel_spec *spec = codec->spec;
773 return snd_hda_input_mux_info(spec->mono_mux, uinfo);
776 static int stac92xx_mono_mux_enum_get(struct snd_kcontrol *kcontrol,
777 struct snd_ctl_elem_value *ucontrol)
779 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
780 struct sigmatel_spec *spec = codec->spec;
782 ucontrol->value.enumerated.item[0] = spec->cur_mmux;
783 return 0;
786 static int stac92xx_mono_mux_enum_put(struct snd_kcontrol *kcontrol,
787 struct snd_ctl_elem_value *ucontrol)
789 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
790 struct sigmatel_spec *spec = codec->spec;
792 return snd_hda_input_mux_put(codec, spec->mono_mux, ucontrol,
793 spec->mono_nid, &spec->cur_mmux);
796 #define stac92xx_aloopback_info snd_ctl_boolean_mono_info
798 static int stac92xx_aloopback_get(struct snd_kcontrol *kcontrol,
799 struct snd_ctl_elem_value *ucontrol)
801 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
802 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
803 struct sigmatel_spec *spec = codec->spec;
805 ucontrol->value.integer.value[0] = !!(spec->aloopback &
806 (spec->aloopback_mask << idx));
807 return 0;
810 static int stac92xx_aloopback_put(struct snd_kcontrol *kcontrol,
811 struct snd_ctl_elem_value *ucontrol)
813 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
814 struct sigmatel_spec *spec = codec->spec;
815 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
816 unsigned int dac_mode;
817 unsigned int val, idx_val;
819 idx_val = spec->aloopback_mask << idx;
820 if (ucontrol->value.integer.value[0])
821 val = spec->aloopback | idx_val;
822 else
823 val = spec->aloopback & ~idx_val;
824 if (spec->aloopback == val)
825 return 0;
827 spec->aloopback = val;
829 /* Only return the bits defined by the shift value of the
830 * first two bytes of the mask
832 dac_mode = snd_hda_codec_read(codec, codec->afg, 0,
833 kcontrol->private_value & 0xFFFF, 0x0);
834 dac_mode >>= spec->aloopback_shift;
836 if (spec->aloopback & idx_val) {
837 snd_hda_power_up(codec);
838 dac_mode |= idx_val;
839 } else {
840 snd_hda_power_down(codec);
841 dac_mode &= ~idx_val;
844 snd_hda_codec_write_cache(codec, codec->afg, 0,
845 kcontrol->private_value >> 16, dac_mode);
847 return 1;
850 static struct hda_verb stac9200_core_init[] = {
851 /* set dac0mux for dac converter */
852 { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
856 static struct hda_verb stac9200_eapd_init[] = {
857 /* set dac0mux for dac converter */
858 {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
859 {0x08, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
863 static struct hda_verb dell_eq_core_init[] = {
864 /* set master volume to max value without distortion
865 * and direct control */
866 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xec},
870 static struct hda_verb stac92hd73xx_core_init[] = {
871 /* set master volume and direct control */
872 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
876 static struct hda_verb stac92hd83xxx_core_init[] = {
877 /* power state controls amps */
878 { 0x01, AC_VERB_SET_EAPD, 1 << 2},
882 static struct hda_verb stac92hd71bxx_core_init[] = {
883 /* set master volume and direct control */
884 { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
888 static struct hda_verb stac92hd71bxx_unmute_core_init[] = {
889 /* unmute right and left channels for nodes 0x0f, 0xa, 0x0d */
890 { 0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
891 { 0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
892 { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
896 static struct hda_verb stac925x_core_init[] = {
897 /* set dac0mux for dac converter */
898 { 0x06, AC_VERB_SET_CONNECT_SEL, 0x00},
899 /* mute the master volume */
900 { 0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
904 static struct hda_verb stac922x_core_init[] = {
905 /* set master volume and direct control */
906 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
910 static struct hda_verb d965_core_init[] = {
911 /* set master volume and direct control */
912 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
913 /* unmute node 0x1b */
914 { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
915 /* select node 0x03 as DAC */
916 { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
920 static struct hda_verb dell_3st_core_init[] = {
921 /* don't set delta bit */
922 {0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0x7f},
923 /* unmute node 0x1b */
924 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
925 /* select node 0x03 as DAC */
926 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
930 static struct hda_verb stac927x_core_init[] = {
931 /* set master volume and direct control */
932 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
933 /* enable analog pc beep path */
934 { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
938 static struct hda_verb stac927x_volknob_core_init[] = {
939 /* don't set delta bit */
940 {0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0x7f},
941 /* enable analog pc beep path */
942 {0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
946 static struct hda_verb stac9205_core_init[] = {
947 /* set master volume and direct control */
948 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
949 /* enable analog pc beep path */
950 { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
954 #define STAC_MONO_MUX \
956 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
957 .name = "Mono Mux", \
958 .count = 1, \
959 .info = stac92xx_mono_mux_enum_info, \
960 .get = stac92xx_mono_mux_enum_get, \
961 .put = stac92xx_mono_mux_enum_put, \
964 #define STAC_ANALOG_LOOPBACK(verb_read, verb_write, cnt) \
966 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
967 .name = "Analog Loopback", \
968 .count = cnt, \
969 .info = stac92xx_aloopback_info, \
970 .get = stac92xx_aloopback_get, \
971 .put = stac92xx_aloopback_put, \
972 .private_value = verb_read | (verb_write << 16), \
975 #define DC_BIAS(xname, idx, nid) \
977 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
978 .name = xname, \
979 .index = idx, \
980 .info = stac92xx_dc_bias_info, \
981 .get = stac92xx_dc_bias_get, \
982 .put = stac92xx_dc_bias_put, \
983 .private_value = nid, \
986 static struct snd_kcontrol_new stac9200_mixer[] = {
987 HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
988 HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
989 HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
990 HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
991 { } /* end */
994 static struct snd_kcontrol_new stac92hd73xx_6ch_loopback[] = {
995 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 3),
999 static struct snd_kcontrol_new stac92hd73xx_8ch_loopback[] = {
1000 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 4),
1004 static struct snd_kcontrol_new stac92hd73xx_10ch_loopback[] = {
1005 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 5),
1010 static struct snd_kcontrol_new stac92hd71bxx_loopback[] = {
1011 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A0, 2)
1014 static struct snd_kcontrol_new stac925x_mixer[] = {
1015 HDA_CODEC_VOLUME("Master Playback Volume", 0x0e, 0, HDA_OUTPUT),
1016 HDA_CODEC_MUTE("Master Playback Switch", 0x0e, 0, HDA_OUTPUT),
1017 { } /* end */
1020 static struct snd_kcontrol_new stac9205_loopback[] = {
1021 STAC_ANALOG_LOOPBACK(0xFE0, 0x7E0, 1),
1025 static struct snd_kcontrol_new stac927x_loopback[] = {
1026 STAC_ANALOG_LOOPBACK(0xFEB, 0x7EB, 1),
1030 static struct snd_kcontrol_new stac_dmux_mixer = {
1031 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1032 .name = "Digital Input Source",
1033 /* count set later */
1034 .info = stac92xx_dmux_enum_info,
1035 .get = stac92xx_dmux_enum_get,
1036 .put = stac92xx_dmux_enum_put,
1039 static struct snd_kcontrol_new stac_smux_mixer = {
1040 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1041 .name = "IEC958 Playback Source",
1042 /* count set later */
1043 .info = stac92xx_smux_enum_info,
1044 .get = stac92xx_smux_enum_get,
1045 .put = stac92xx_smux_enum_put,
1048 static const char *slave_vols[] = {
1049 "Front Playback Volume",
1050 "Surround Playback Volume",
1051 "Center Playback Volume",
1052 "LFE Playback Volume",
1053 "Side Playback Volume",
1054 "Headphone Playback Volume",
1055 "Speaker Playback Volume",
1056 NULL
1059 static const char *slave_sws[] = {
1060 "Front Playback Switch",
1061 "Surround Playback Switch",
1062 "Center Playback Switch",
1063 "LFE Playback Switch",
1064 "Side Playback Switch",
1065 "Headphone Playback Switch",
1066 "Speaker Playback Switch",
1067 "IEC958 Playback Switch",
1068 NULL
1071 static void stac92xx_free_kctls(struct hda_codec *codec);
1072 static int stac92xx_add_jack(struct hda_codec *codec, hda_nid_t nid, int type);
1074 static int stac92xx_build_controls(struct hda_codec *codec)
1076 struct sigmatel_spec *spec = codec->spec;
1077 struct auto_pin_cfg *cfg = &spec->autocfg;
1078 hda_nid_t nid;
1079 int err;
1080 int i;
1082 if (spec->mixer) {
1083 err = snd_hda_add_new_ctls(codec, spec->mixer);
1084 if (err < 0)
1085 return err;
1088 for (i = 0; i < spec->num_mixers; i++) {
1089 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1090 if (err < 0)
1091 return err;
1093 if (!spec->auto_mic && spec->num_dmuxes > 0 &&
1094 snd_hda_get_bool_hint(codec, "separate_dmux") == 1) {
1095 stac_dmux_mixer.count = spec->num_dmuxes;
1096 err = snd_hda_ctl_add(codec, 0,
1097 snd_ctl_new1(&stac_dmux_mixer, codec));
1098 if (err < 0)
1099 return err;
1101 if (spec->num_smuxes > 0) {
1102 int wcaps = get_wcaps(codec, spec->multiout.dig_out_nid);
1103 struct hda_input_mux *smux = &spec->private_smux;
1104 /* check for mute support on SPDIF out */
1105 if (wcaps & AC_WCAP_OUT_AMP) {
1106 smux->items[smux->num_items].label = "Off";
1107 smux->items[smux->num_items].index = 0;
1108 smux->num_items++;
1109 spec->spdif_mute = 1;
1111 stac_smux_mixer.count = spec->num_smuxes;
1112 err = snd_hda_ctl_add(codec, 0,
1113 snd_ctl_new1(&stac_smux_mixer, codec));
1114 if (err < 0)
1115 return err;
1118 if (spec->multiout.dig_out_nid) {
1119 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
1120 if (err < 0)
1121 return err;
1122 err = snd_hda_create_spdif_share_sw(codec,
1123 &spec->multiout);
1124 if (err < 0)
1125 return err;
1126 spec->multiout.share_spdif = 1;
1128 if (spec->dig_in_nid && !(spec->gpio_dir & 0x01)) {
1129 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1130 if (err < 0)
1131 return err;
1134 /* if we have no master control, let's create it */
1135 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
1136 unsigned int vmaster_tlv[4];
1137 snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0],
1138 HDA_OUTPUT, vmaster_tlv);
1139 /* correct volume offset */
1140 vmaster_tlv[2] += vmaster_tlv[3] * spec->volume_offset;
1141 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
1142 vmaster_tlv, slave_vols);
1143 if (err < 0)
1144 return err;
1146 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1147 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1148 NULL, slave_sws);
1149 if (err < 0)
1150 return err;
1153 if (spec->aloopback_ctl &&
1154 snd_hda_get_bool_hint(codec, "loopback") == 1) {
1155 err = snd_hda_add_new_ctls(codec, spec->aloopback_ctl);
1156 if (err < 0)
1157 return err;
1160 stac92xx_free_kctls(codec); /* no longer needed */
1162 /* create jack input elements */
1163 if (spec->hp_detect) {
1164 for (i = 0; i < cfg->hp_outs; i++) {
1165 int type = SND_JACK_HEADPHONE;
1166 nid = cfg->hp_pins[i];
1167 /* jack detection */
1168 if (cfg->hp_outs == i)
1169 type |= SND_JACK_LINEOUT;
1170 err = stac92xx_add_jack(codec, nid, type);
1171 if (err < 0)
1172 return err;
1175 for (i = 0; i < cfg->line_outs; i++) {
1176 err = stac92xx_add_jack(codec, cfg->line_out_pins[i],
1177 SND_JACK_LINEOUT);
1178 if (err < 0)
1179 return err;
1181 for (i = 0; i < AUTO_PIN_LAST; i++) {
1182 nid = cfg->input_pins[i];
1183 if (nid) {
1184 err = stac92xx_add_jack(codec, nid,
1185 SND_JACK_MICROPHONE);
1186 if (err < 0)
1187 return err;
1191 return 0;
1194 static unsigned int ref9200_pin_configs[8] = {
1195 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
1196 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
1199 static unsigned int gateway9200_m4_pin_configs[8] = {
1200 0x400000fe, 0x404500f4, 0x400100f0, 0x90110010,
1201 0x400100f1, 0x02a1902e, 0x500000f2, 0x500000f3,
1203 static unsigned int gateway9200_m4_2_pin_configs[8] = {
1204 0x400000fe, 0x404500f4, 0x400100f0, 0x90110010,
1205 0x400100f1, 0x02a1902e, 0x500000f2, 0x500000f3,
1209 STAC 9200 pin configs for
1210 102801A8
1211 102801DE
1212 102801E8
1214 static unsigned int dell9200_d21_pin_configs[8] = {
1215 0x400001f0, 0x400001f1, 0x02214030, 0x01014010,
1216 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
1220 STAC 9200 pin configs for
1221 102801C0
1222 102801C1
1224 static unsigned int dell9200_d22_pin_configs[8] = {
1225 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
1226 0x01813020, 0x02a19021, 0x90100140, 0x400001f2,
1230 STAC 9200 pin configs for
1231 102801C4 (Dell Dimension E310)
1232 102801C5
1233 102801C7
1234 102801D9
1235 102801DA
1236 102801E3
1238 static unsigned int dell9200_d23_pin_configs[8] = {
1239 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
1240 0x01813020, 0x01a19021, 0x90100140, 0x400001f2,
1245 STAC 9200-32 pin configs for
1246 102801B5 (Dell Inspiron 630m)
1247 102801D8 (Dell Inspiron 640m)
1249 static unsigned int dell9200_m21_pin_configs[8] = {
1250 0x40c003fa, 0x03441340, 0x0321121f, 0x90170310,
1251 0x408003fb, 0x03a11020, 0x401003fc, 0x403003fd,
1255 STAC 9200-32 pin configs for
1256 102801C2 (Dell Latitude D620)
1257 102801C8
1258 102801CC (Dell Latitude D820)
1259 102801D4
1260 102801D6
1262 static unsigned int dell9200_m22_pin_configs[8] = {
1263 0x40c003fa, 0x0144131f, 0x0321121f, 0x90170310,
1264 0x90a70321, 0x03a11020, 0x401003fb, 0x40f000fc,
1268 STAC 9200-32 pin configs for
1269 102801CE (Dell XPS M1710)
1270 102801CF (Dell Precision M90)
1272 static unsigned int dell9200_m23_pin_configs[8] = {
1273 0x40c003fa, 0x01441340, 0x0421421f, 0x90170310,
1274 0x408003fb, 0x04a1102e, 0x90170311, 0x403003fc,
1278 STAC 9200-32 pin configs for
1279 102801C9
1280 102801CA
1281 102801CB (Dell Latitude 120L)
1282 102801D3
1284 static unsigned int dell9200_m24_pin_configs[8] = {
1285 0x40c003fa, 0x404003fb, 0x0321121f, 0x90170310,
1286 0x408003fc, 0x03a11020, 0x401003fd, 0x403003fe,
1290 STAC 9200-32 pin configs for
1291 102801BD (Dell Inspiron E1505n)
1292 102801EE
1293 102801EF
1295 static unsigned int dell9200_m25_pin_configs[8] = {
1296 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
1297 0x408003fb, 0x04a11020, 0x401003fc, 0x403003fd,
1301 STAC 9200-32 pin configs for
1302 102801F5 (Dell Inspiron 1501)
1303 102801F6
1305 static unsigned int dell9200_m26_pin_configs[8] = {
1306 0x40c003fa, 0x404003fb, 0x0421121f, 0x90170310,
1307 0x408003fc, 0x04a11020, 0x401003fd, 0x403003fe,
1311 STAC 9200-32
1312 102801CD (Dell Inspiron E1705/9400)
1314 static unsigned int dell9200_m27_pin_configs[8] = {
1315 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
1316 0x90170310, 0x04a11020, 0x90170310, 0x40f003fc,
1319 static unsigned int oqo9200_pin_configs[8] = {
1320 0x40c000f0, 0x404000f1, 0x0221121f, 0x02211210,
1321 0x90170111, 0x90a70120, 0x400000f2, 0x400000f3,
1325 static unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
1326 [STAC_REF] = ref9200_pin_configs,
1327 [STAC_9200_OQO] = oqo9200_pin_configs,
1328 [STAC_9200_DELL_D21] = dell9200_d21_pin_configs,
1329 [STAC_9200_DELL_D22] = dell9200_d22_pin_configs,
1330 [STAC_9200_DELL_D23] = dell9200_d23_pin_configs,
1331 [STAC_9200_DELL_M21] = dell9200_m21_pin_configs,
1332 [STAC_9200_DELL_M22] = dell9200_m22_pin_configs,
1333 [STAC_9200_DELL_M23] = dell9200_m23_pin_configs,
1334 [STAC_9200_DELL_M24] = dell9200_m24_pin_configs,
1335 [STAC_9200_DELL_M25] = dell9200_m25_pin_configs,
1336 [STAC_9200_DELL_M26] = dell9200_m26_pin_configs,
1337 [STAC_9200_DELL_M27] = dell9200_m27_pin_configs,
1338 [STAC_9200_M4] = gateway9200_m4_pin_configs,
1339 [STAC_9200_M4_2] = gateway9200_m4_2_pin_configs,
1340 [STAC_9200_PANASONIC] = ref9200_pin_configs,
1343 static const char *stac9200_models[STAC_9200_MODELS] = {
1344 [STAC_AUTO] = "auto",
1345 [STAC_REF] = "ref",
1346 [STAC_9200_OQO] = "oqo",
1347 [STAC_9200_DELL_D21] = "dell-d21",
1348 [STAC_9200_DELL_D22] = "dell-d22",
1349 [STAC_9200_DELL_D23] = "dell-d23",
1350 [STAC_9200_DELL_M21] = "dell-m21",
1351 [STAC_9200_DELL_M22] = "dell-m22",
1352 [STAC_9200_DELL_M23] = "dell-m23",
1353 [STAC_9200_DELL_M24] = "dell-m24",
1354 [STAC_9200_DELL_M25] = "dell-m25",
1355 [STAC_9200_DELL_M26] = "dell-m26",
1356 [STAC_9200_DELL_M27] = "dell-m27",
1357 [STAC_9200_M4] = "gateway-m4",
1358 [STAC_9200_M4_2] = "gateway-m4-2",
1359 [STAC_9200_PANASONIC] = "panasonic",
1362 static struct snd_pci_quirk stac9200_cfg_tbl[] = {
1363 /* SigmaTel reference board */
1364 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1365 "DFI LanParty", STAC_REF),
1366 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1367 "DFI LanParty", STAC_REF),
1368 /* Dell laptops have BIOS problem */
1369 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a8,
1370 "unknown Dell", STAC_9200_DELL_D21),
1371 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01b5,
1372 "Dell Inspiron 630m", STAC_9200_DELL_M21),
1373 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bd,
1374 "Dell Inspiron E1505n", STAC_9200_DELL_M25),
1375 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c0,
1376 "unknown Dell", STAC_9200_DELL_D22),
1377 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c1,
1378 "unknown Dell", STAC_9200_DELL_D22),
1379 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c2,
1380 "Dell Latitude D620", STAC_9200_DELL_M22),
1381 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c5,
1382 "unknown Dell", STAC_9200_DELL_D23),
1383 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c7,
1384 "unknown Dell", STAC_9200_DELL_D23),
1385 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c8,
1386 "unknown Dell", STAC_9200_DELL_M22),
1387 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c9,
1388 "unknown Dell", STAC_9200_DELL_M24),
1389 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ca,
1390 "unknown Dell", STAC_9200_DELL_M24),
1391 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cb,
1392 "Dell Latitude 120L", STAC_9200_DELL_M24),
1393 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cc,
1394 "Dell Latitude D820", STAC_9200_DELL_M22),
1395 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cd,
1396 "Dell Inspiron E1705/9400", STAC_9200_DELL_M27),
1397 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ce,
1398 "Dell XPS M1710", STAC_9200_DELL_M23),
1399 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cf,
1400 "Dell Precision M90", STAC_9200_DELL_M23),
1401 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d3,
1402 "unknown Dell", STAC_9200_DELL_M22),
1403 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d4,
1404 "unknown Dell", STAC_9200_DELL_M22),
1405 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d6,
1406 "unknown Dell", STAC_9200_DELL_M22),
1407 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d8,
1408 "Dell Inspiron 640m", STAC_9200_DELL_M21),
1409 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d9,
1410 "unknown Dell", STAC_9200_DELL_D23),
1411 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01da,
1412 "unknown Dell", STAC_9200_DELL_D23),
1413 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01de,
1414 "unknown Dell", STAC_9200_DELL_D21),
1415 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e3,
1416 "unknown Dell", STAC_9200_DELL_D23),
1417 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e8,
1418 "unknown Dell", STAC_9200_DELL_D21),
1419 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ee,
1420 "unknown Dell", STAC_9200_DELL_M25),
1421 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ef,
1422 "unknown Dell", STAC_9200_DELL_M25),
1423 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f5,
1424 "Dell Inspiron 1501", STAC_9200_DELL_M26),
1425 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f6,
1426 "unknown Dell", STAC_9200_DELL_M26),
1427 /* Panasonic */
1428 SND_PCI_QUIRK(0x10f7, 0x8338, "Panasonic CF-74", STAC_9200_PANASONIC),
1429 /* Gateway machines needs EAPD to be set on resume */
1430 SND_PCI_QUIRK(0x107b, 0x0205, "Gateway S-7110M", STAC_9200_M4),
1431 SND_PCI_QUIRK(0x107b, 0x0317, "Gateway MT3423, MX341*", STAC_9200_M4_2),
1432 SND_PCI_QUIRK(0x107b, 0x0318, "Gateway ML3019, MT3707", STAC_9200_M4_2),
1433 /* OQO Mobile */
1434 SND_PCI_QUIRK(0x1106, 0x3288, "OQO Model 2", STAC_9200_OQO),
1435 {} /* terminator */
1438 static unsigned int ref925x_pin_configs[8] = {
1439 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
1440 0x90a70320, 0x02214210, 0x01019020, 0x9033032e,
1443 static unsigned int stac925xM1_pin_configs[8] = {
1444 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1445 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1448 static unsigned int stac925xM1_2_pin_configs[8] = {
1449 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1450 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1453 static unsigned int stac925xM2_pin_configs[8] = {
1454 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1455 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1458 static unsigned int stac925xM2_2_pin_configs[8] = {
1459 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1460 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1463 static unsigned int stac925xM3_pin_configs[8] = {
1464 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1465 0x40a000f0, 0x90100210, 0x400003f1, 0x503303f3,
1468 static unsigned int stac925xM5_pin_configs[8] = {
1469 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1470 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1473 static unsigned int stac925xM6_pin_configs[8] = {
1474 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1475 0x40a000f0, 0x90100210, 0x400003f1, 0x90330320,
1478 static unsigned int *stac925x_brd_tbl[STAC_925x_MODELS] = {
1479 [STAC_REF] = ref925x_pin_configs,
1480 [STAC_M1] = stac925xM1_pin_configs,
1481 [STAC_M1_2] = stac925xM1_2_pin_configs,
1482 [STAC_M2] = stac925xM2_pin_configs,
1483 [STAC_M2_2] = stac925xM2_2_pin_configs,
1484 [STAC_M3] = stac925xM3_pin_configs,
1485 [STAC_M5] = stac925xM5_pin_configs,
1486 [STAC_M6] = stac925xM6_pin_configs,
1489 static const char *stac925x_models[STAC_925x_MODELS] = {
1490 [STAC_925x_AUTO] = "auto",
1491 [STAC_REF] = "ref",
1492 [STAC_M1] = "m1",
1493 [STAC_M1_2] = "m1-2",
1494 [STAC_M2] = "m2",
1495 [STAC_M2_2] = "m2-2",
1496 [STAC_M3] = "m3",
1497 [STAC_M5] = "m5",
1498 [STAC_M6] = "m6",
1501 static struct snd_pci_quirk stac925x_codec_id_cfg_tbl[] = {
1502 SND_PCI_QUIRK(0x107b, 0x0316, "Gateway M255", STAC_M2),
1503 SND_PCI_QUIRK(0x107b, 0x0366, "Gateway MP6954", STAC_M5),
1504 SND_PCI_QUIRK(0x107b, 0x0461, "Gateway NX560XL", STAC_M1),
1505 SND_PCI_QUIRK(0x107b, 0x0681, "Gateway NX860", STAC_M2),
1506 SND_PCI_QUIRK(0x107b, 0x0367, "Gateway MX6453", STAC_M1_2),
1507 /* Not sure about the brand name for those */
1508 SND_PCI_QUIRK(0x107b, 0x0281, "Gateway mobile", STAC_M1),
1509 SND_PCI_QUIRK(0x107b, 0x0507, "Gateway mobile", STAC_M3),
1510 SND_PCI_QUIRK(0x107b, 0x0281, "Gateway mobile", STAC_M6),
1511 SND_PCI_QUIRK(0x107b, 0x0685, "Gateway mobile", STAC_M2_2),
1512 {} /* terminator */
1515 static struct snd_pci_quirk stac925x_cfg_tbl[] = {
1516 /* SigmaTel reference board */
1517 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, "DFI LanParty", STAC_REF),
1518 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101, "DFI LanParty", STAC_REF),
1519 SND_PCI_QUIRK(0x8384, 0x7632, "Stac9202 Reference Board", STAC_REF),
1521 /* Default table for unknown ID */
1522 SND_PCI_QUIRK(0x1002, 0x437b, "Gateway mobile", STAC_M2_2),
1524 {} /* terminator */
1527 static unsigned int ref92hd73xx_pin_configs[13] = {
1528 0x02214030, 0x02a19040, 0x01a19020, 0x02214030,
1529 0x0181302e, 0x01014010, 0x01014020, 0x01014030,
1530 0x02319040, 0x90a000f0, 0x90a000f0, 0x01452050,
1531 0x01452050,
1534 static unsigned int dell_m6_pin_configs[13] = {
1535 0x0321101f, 0x4f00000f, 0x4f0000f0, 0x90170110,
1536 0x03a11020, 0x0321101f, 0x4f0000f0, 0x4f0000f0,
1537 0x4f0000f0, 0x90a60160, 0x4f0000f0, 0x4f0000f0,
1538 0x4f0000f0,
1541 static unsigned int alienware_m17x_pin_configs[13] = {
1542 0x0321101f, 0x0321101f, 0x03a11020, 0x03014020,
1543 0x90170110, 0x4f0000f0, 0x4f0000f0, 0x4f0000f0,
1544 0x4f0000f0, 0x90a60160, 0x4f0000f0, 0x4f0000f0,
1545 0x904601b0,
1548 static unsigned int intel_dg45id_pin_configs[13] = {
1549 0x02214230, 0x02A19240, 0x01013214, 0x01014210,
1550 0x01A19250, 0x01011212, 0x01016211
1553 static unsigned int *stac92hd73xx_brd_tbl[STAC_92HD73XX_MODELS] = {
1554 [STAC_92HD73XX_REF] = ref92hd73xx_pin_configs,
1555 [STAC_DELL_M6_AMIC] = dell_m6_pin_configs,
1556 [STAC_DELL_M6_DMIC] = dell_m6_pin_configs,
1557 [STAC_DELL_M6_BOTH] = dell_m6_pin_configs,
1558 [STAC_DELL_EQ] = dell_m6_pin_configs,
1559 [STAC_ALIENWARE_M17X] = alienware_m17x_pin_configs,
1560 [STAC_92HD73XX_INTEL] = intel_dg45id_pin_configs,
1563 static const char *stac92hd73xx_models[STAC_92HD73XX_MODELS] = {
1564 [STAC_92HD73XX_AUTO] = "auto",
1565 [STAC_92HD73XX_NO_JD] = "no-jd",
1566 [STAC_92HD73XX_REF] = "ref",
1567 [STAC_92HD73XX_INTEL] = "intel",
1568 [STAC_DELL_M6_AMIC] = "dell-m6-amic",
1569 [STAC_DELL_M6_DMIC] = "dell-m6-dmic",
1570 [STAC_DELL_M6_BOTH] = "dell-m6",
1571 [STAC_DELL_EQ] = "dell-eq",
1572 [STAC_ALIENWARE_M17X] = "alienware",
1575 static struct snd_pci_quirk stac92hd73xx_cfg_tbl[] = {
1576 /* SigmaTel reference board */
1577 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1578 "DFI LanParty", STAC_92HD73XX_REF),
1579 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1580 "DFI LanParty", STAC_92HD73XX_REF),
1581 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5002,
1582 "Intel DG45ID", STAC_92HD73XX_INTEL),
1583 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5003,
1584 "Intel DG45FC", STAC_92HD73XX_INTEL),
1585 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0254,
1586 "Dell Studio 1535", STAC_DELL_M6_DMIC),
1587 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0255,
1588 "unknown Dell", STAC_DELL_M6_DMIC),
1589 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0256,
1590 "unknown Dell", STAC_DELL_M6_BOTH),
1591 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0257,
1592 "unknown Dell", STAC_DELL_M6_BOTH),
1593 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025e,
1594 "unknown Dell", STAC_DELL_M6_AMIC),
1595 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025f,
1596 "unknown Dell", STAC_DELL_M6_AMIC),
1597 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0271,
1598 "unknown Dell", STAC_DELL_M6_DMIC),
1599 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0272,
1600 "unknown Dell", STAC_DELL_M6_DMIC),
1601 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x029f,
1602 "Dell Studio 1537", STAC_DELL_M6_DMIC),
1603 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02a0,
1604 "Dell Studio 17", STAC_DELL_M6_DMIC),
1605 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02be,
1606 "Dell Studio 1555", STAC_DELL_M6_DMIC),
1607 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02bd,
1608 "Dell Studio 1557", STAC_DELL_M6_DMIC),
1609 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02fe,
1610 "Dell Studio XPS 1645", STAC_DELL_M6_BOTH),
1611 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0413,
1612 "Dell Studio 1558", STAC_DELL_M6_BOTH),
1613 {} /* terminator */
1616 static struct snd_pci_quirk stac92hd73xx_codec_id_cfg_tbl[] = {
1617 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02a1,
1618 "Alienware M17x", STAC_ALIENWARE_M17X),
1619 {} /* terminator */
1622 static unsigned int ref92hd83xxx_pin_configs[10] = {
1623 0x02214030, 0x02211010, 0x02a19020, 0x02170130,
1624 0x01014050, 0x01819040, 0x01014020, 0x90a3014e,
1625 0x01451160, 0x98560170,
1628 static unsigned int dell_s14_pin_configs[10] = {
1629 0x0221403f, 0x0221101f, 0x02a19020, 0x90170110,
1630 0x40f000f0, 0x40f000f0, 0x40f000f0, 0x90a60160,
1631 0x40f000f0, 0x40f000f0,
1634 static unsigned int *stac92hd83xxx_brd_tbl[STAC_92HD83XXX_MODELS] = {
1635 [STAC_92HD83XXX_REF] = ref92hd83xxx_pin_configs,
1636 [STAC_92HD83XXX_PWR_REF] = ref92hd83xxx_pin_configs,
1637 [STAC_DELL_S14] = dell_s14_pin_configs,
1640 static const char *stac92hd83xxx_models[STAC_92HD83XXX_MODELS] = {
1641 [STAC_92HD83XXX_AUTO] = "auto",
1642 [STAC_92HD83XXX_REF] = "ref",
1643 [STAC_92HD83XXX_PWR_REF] = "mic-ref",
1644 [STAC_DELL_S14] = "dell-s14",
1645 [STAC_92HD83XXX_HP] = "hp",
1648 static struct snd_pci_quirk stac92hd83xxx_cfg_tbl[] = {
1649 /* SigmaTel reference board */
1650 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1651 "DFI LanParty", STAC_92HD83XXX_REF),
1652 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1653 "DFI LanParty", STAC_92HD83XXX_REF),
1654 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ba,
1655 "unknown Dell", STAC_DELL_S14),
1656 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xff00, 0x3600,
1657 "HP", STAC_92HD83XXX_HP),
1658 {} /* terminator */
1661 static unsigned int ref92hd71bxx_pin_configs[STAC92HD71BXX_NUM_PINS] = {
1662 0x02214030, 0x02a19040, 0x01a19020, 0x01014010,
1663 0x0181302e, 0x01014010, 0x01019020, 0x90a000f0,
1664 0x90a000f0, 0x01452050, 0x01452050, 0x00000000,
1665 0x00000000
1668 static unsigned int dell_m4_1_pin_configs[STAC92HD71BXX_NUM_PINS] = {
1669 0x0421101f, 0x04a11221, 0x40f000f0, 0x90170110,
1670 0x23a1902e, 0x23014250, 0x40f000f0, 0x90a000f0,
1671 0x40f000f0, 0x4f0000f0, 0x4f0000f0, 0x00000000,
1672 0x00000000
1675 static unsigned int dell_m4_2_pin_configs[STAC92HD71BXX_NUM_PINS] = {
1676 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1677 0x23a1902e, 0x23014250, 0x40f000f0, 0x40f000f0,
1678 0x40f000f0, 0x044413b0, 0x044413b0, 0x00000000,
1679 0x00000000
1682 static unsigned int dell_m4_3_pin_configs[STAC92HD71BXX_NUM_PINS] = {
1683 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1684 0x40f000f0, 0x40f000f0, 0x40f000f0, 0x90a000f0,
1685 0x40f000f0, 0x044413b0, 0x044413b0, 0x00000000,
1686 0x00000000
1689 static unsigned int *stac92hd71bxx_brd_tbl[STAC_92HD71BXX_MODELS] = {
1690 [STAC_92HD71BXX_REF] = ref92hd71bxx_pin_configs,
1691 [STAC_DELL_M4_1] = dell_m4_1_pin_configs,
1692 [STAC_DELL_M4_2] = dell_m4_2_pin_configs,
1693 [STAC_DELL_M4_3] = dell_m4_3_pin_configs,
1694 [STAC_HP_M4] = NULL,
1695 [STAC_HP_DV4] = NULL,
1696 [STAC_HP_DV5] = NULL,
1697 [STAC_HP_HDX] = NULL,
1698 [STAC_HP_DV4_1222NR] = NULL,
1701 static const char *stac92hd71bxx_models[STAC_92HD71BXX_MODELS] = {
1702 [STAC_92HD71BXX_AUTO] = "auto",
1703 [STAC_92HD71BXX_REF] = "ref",
1704 [STAC_DELL_M4_1] = "dell-m4-1",
1705 [STAC_DELL_M4_2] = "dell-m4-2",
1706 [STAC_DELL_M4_3] = "dell-m4-3",
1707 [STAC_HP_M4] = "hp-m4",
1708 [STAC_HP_DV4] = "hp-dv4",
1709 [STAC_HP_DV5] = "hp-dv5",
1710 [STAC_HP_HDX] = "hp-hdx",
1711 [STAC_HP_DV4_1222NR] = "hp-dv4-1222nr",
1714 static struct snd_pci_quirk stac92hd71bxx_cfg_tbl[] = {
1715 /* SigmaTel reference board */
1716 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1717 "DFI LanParty", STAC_92HD71BXX_REF),
1718 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1719 "DFI LanParty", STAC_92HD71BXX_REF),
1720 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x30fb,
1721 "HP dv4-1222nr", STAC_HP_DV4_1222NR),
1722 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x1720,
1723 "HP", STAC_HP_DV5),
1724 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3080,
1725 "HP", STAC_HP_DV5),
1726 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x30f0,
1727 "HP dv4-7", STAC_HP_DV4),
1728 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3600,
1729 "HP dv4-7", STAC_HP_DV5),
1730 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3610,
1731 "HP HDX", STAC_HP_HDX), /* HDX18 */
1732 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361a,
1733 "HP mini 1000", STAC_HP_M4),
1734 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361b,
1735 "HP HDX", STAC_HP_HDX), /* HDX16 */
1736 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3620,
1737 "HP dv6", STAC_HP_DV5),
1738 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3061,
1739 "HP dv6", STAC_HP_DV5), /* HP dv6-1110ax */
1740 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x7010,
1741 "HP", STAC_HP_DV5),
1742 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0233,
1743 "unknown Dell", STAC_DELL_M4_1),
1744 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0234,
1745 "unknown Dell", STAC_DELL_M4_1),
1746 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0250,
1747 "unknown Dell", STAC_DELL_M4_1),
1748 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024f,
1749 "unknown Dell", STAC_DELL_M4_1),
1750 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024d,
1751 "unknown Dell", STAC_DELL_M4_1),
1752 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0251,
1753 "unknown Dell", STAC_DELL_M4_1),
1754 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0277,
1755 "unknown Dell", STAC_DELL_M4_1),
1756 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0263,
1757 "unknown Dell", STAC_DELL_M4_2),
1758 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0265,
1759 "unknown Dell", STAC_DELL_M4_2),
1760 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0262,
1761 "unknown Dell", STAC_DELL_M4_2),
1762 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0264,
1763 "unknown Dell", STAC_DELL_M4_2),
1764 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02aa,
1765 "unknown Dell", STAC_DELL_M4_3),
1766 {} /* terminator */
1769 static unsigned int ref922x_pin_configs[10] = {
1770 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
1771 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
1772 0x40000100, 0x40000100,
1776 STAC 922X pin configs for
1777 102801A7
1778 102801AB
1779 102801A9
1780 102801D1
1781 102801D2
1783 static unsigned int dell_922x_d81_pin_configs[10] = {
1784 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1785 0x02a19020, 0x01117011, 0x400001f0, 0x400001f1,
1786 0x01813122, 0x400001f2,
1790 STAC 922X pin configs for
1791 102801AC
1792 102801D0
1794 static unsigned int dell_922x_d82_pin_configs[10] = {
1795 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1796 0x02a19020, 0x01117011, 0x01451140, 0x400001f0,
1797 0x01813122, 0x400001f1,
1801 STAC 922X pin configs for
1802 102801BF
1804 static unsigned int dell_922x_m81_pin_configs[10] = {
1805 0x0321101f, 0x01112024, 0x01111222, 0x91174220,
1806 0x03a11050, 0x01116221, 0x90a70330, 0x01452340,
1807 0x40C003f1, 0x405003f0,
1811 STAC 9221 A1 pin configs for
1812 102801D7 (Dell XPS M1210)
1814 static unsigned int dell_922x_m82_pin_configs[10] = {
1815 0x02211211, 0x408103ff, 0x02a1123e, 0x90100310,
1816 0x408003f1, 0x0221121f, 0x03451340, 0x40c003f2,
1817 0x508003f3, 0x405003f4,
1820 static unsigned int d945gtp3_pin_configs[10] = {
1821 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
1822 0x40000100, 0x40000100, 0x40000100, 0x40000100,
1823 0x02a19120, 0x40000100,
1826 static unsigned int d945gtp5_pin_configs[10] = {
1827 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
1828 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
1829 0x02a19320, 0x40000100,
1832 static unsigned int intel_mac_v1_pin_configs[10] = {
1833 0x0121e21f, 0x400000ff, 0x9017e110, 0x400000fd,
1834 0x400000fe, 0x0181e020, 0x1145e030, 0x11c5e240,
1835 0x400000fc, 0x400000fb,
1838 static unsigned int intel_mac_v2_pin_configs[10] = {
1839 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
1840 0x400000fe, 0x0181e020, 0x1145e230, 0x500000fa,
1841 0x400000fc, 0x400000fb,
1844 static unsigned int intel_mac_v3_pin_configs[10] = {
1845 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
1846 0x400000fe, 0x0181e020, 0x1145e230, 0x11c5e240,
1847 0x400000fc, 0x400000fb,
1850 static unsigned int intel_mac_v4_pin_configs[10] = {
1851 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
1852 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
1853 0x400000fc, 0x400000fb,
1856 static unsigned int intel_mac_v5_pin_configs[10] = {
1857 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
1858 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
1859 0x400000fc, 0x400000fb,
1862 static unsigned int ecs202_pin_configs[10] = {
1863 0x0221401f, 0x02a19020, 0x01a19020, 0x01114010,
1864 0x408000f0, 0x01813022, 0x074510a0, 0x40c400f1,
1865 0x9037012e, 0x40e000f2,
1868 static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
1869 [STAC_D945_REF] = ref922x_pin_configs,
1870 [STAC_D945GTP3] = d945gtp3_pin_configs,
1871 [STAC_D945GTP5] = d945gtp5_pin_configs,
1872 [STAC_INTEL_MAC_V1] = intel_mac_v1_pin_configs,
1873 [STAC_INTEL_MAC_V2] = intel_mac_v2_pin_configs,
1874 [STAC_INTEL_MAC_V3] = intel_mac_v3_pin_configs,
1875 [STAC_INTEL_MAC_V4] = intel_mac_v4_pin_configs,
1876 [STAC_INTEL_MAC_V5] = intel_mac_v5_pin_configs,
1877 [STAC_INTEL_MAC_AUTO] = intel_mac_v3_pin_configs,
1878 /* for backward compatibility */
1879 [STAC_MACMINI] = intel_mac_v3_pin_configs,
1880 [STAC_MACBOOK] = intel_mac_v5_pin_configs,
1881 [STAC_MACBOOK_PRO_V1] = intel_mac_v3_pin_configs,
1882 [STAC_MACBOOK_PRO_V2] = intel_mac_v3_pin_configs,
1883 [STAC_IMAC_INTEL] = intel_mac_v2_pin_configs,
1884 [STAC_IMAC_INTEL_20] = intel_mac_v3_pin_configs,
1885 [STAC_ECS_202] = ecs202_pin_configs,
1886 [STAC_922X_DELL_D81] = dell_922x_d81_pin_configs,
1887 [STAC_922X_DELL_D82] = dell_922x_d82_pin_configs,
1888 [STAC_922X_DELL_M81] = dell_922x_m81_pin_configs,
1889 [STAC_922X_DELL_M82] = dell_922x_m82_pin_configs,
1892 static const char *stac922x_models[STAC_922X_MODELS] = {
1893 [STAC_922X_AUTO] = "auto",
1894 [STAC_D945_REF] = "ref",
1895 [STAC_D945GTP5] = "5stack",
1896 [STAC_D945GTP3] = "3stack",
1897 [STAC_INTEL_MAC_V1] = "intel-mac-v1",
1898 [STAC_INTEL_MAC_V2] = "intel-mac-v2",
1899 [STAC_INTEL_MAC_V3] = "intel-mac-v3",
1900 [STAC_INTEL_MAC_V4] = "intel-mac-v4",
1901 [STAC_INTEL_MAC_V5] = "intel-mac-v5",
1902 [STAC_INTEL_MAC_AUTO] = "intel-mac-auto",
1903 /* for backward compatibility */
1904 [STAC_MACMINI] = "macmini",
1905 [STAC_MACBOOK] = "macbook",
1906 [STAC_MACBOOK_PRO_V1] = "macbook-pro-v1",
1907 [STAC_MACBOOK_PRO_V2] = "macbook-pro",
1908 [STAC_IMAC_INTEL] = "imac-intel",
1909 [STAC_IMAC_INTEL_20] = "imac-intel-20",
1910 [STAC_ECS_202] = "ecs202",
1911 [STAC_922X_DELL_D81] = "dell-d81",
1912 [STAC_922X_DELL_D82] = "dell-d82",
1913 [STAC_922X_DELL_M81] = "dell-m81",
1914 [STAC_922X_DELL_M82] = "dell-m82",
1917 static struct snd_pci_quirk stac922x_cfg_tbl[] = {
1918 /* SigmaTel reference board */
1919 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1920 "DFI LanParty", STAC_D945_REF),
1921 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1922 "DFI LanParty", STAC_D945_REF),
1923 /* Intel 945G based systems */
1924 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101,
1925 "Intel D945G", STAC_D945GTP3),
1926 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0202,
1927 "Intel D945G", STAC_D945GTP3),
1928 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0606,
1929 "Intel D945G", STAC_D945GTP3),
1930 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0601,
1931 "Intel D945G", STAC_D945GTP3),
1932 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0111,
1933 "Intel D945G", STAC_D945GTP3),
1934 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1115,
1935 "Intel D945G", STAC_D945GTP3),
1936 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1116,
1937 "Intel D945G", STAC_D945GTP3),
1938 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1117,
1939 "Intel D945G", STAC_D945GTP3),
1940 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1118,
1941 "Intel D945G", STAC_D945GTP3),
1942 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1119,
1943 "Intel D945G", STAC_D945GTP3),
1944 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x8826,
1945 "Intel D945G", STAC_D945GTP3),
1946 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5049,
1947 "Intel D945G", STAC_D945GTP3),
1948 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5055,
1949 "Intel D945G", STAC_D945GTP3),
1950 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5048,
1951 "Intel D945G", STAC_D945GTP3),
1952 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0110,
1953 "Intel D945G", STAC_D945GTP3),
1954 /* Intel D945G 5-stack systems */
1955 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0404,
1956 "Intel D945G", STAC_D945GTP5),
1957 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0303,
1958 "Intel D945G", STAC_D945GTP5),
1959 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0013,
1960 "Intel D945G", STAC_D945GTP5),
1961 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0417,
1962 "Intel D945G", STAC_D945GTP5),
1963 /* Intel 945P based systems */
1964 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0b0b,
1965 "Intel D945P", STAC_D945GTP3),
1966 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0112,
1967 "Intel D945P", STAC_D945GTP3),
1968 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0d0d,
1969 "Intel D945P", STAC_D945GTP3),
1970 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0909,
1971 "Intel D945P", STAC_D945GTP3),
1972 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0505,
1973 "Intel D945P", STAC_D945GTP3),
1974 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707,
1975 "Intel D945P", STAC_D945GTP5),
1976 /* other intel */
1977 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0204,
1978 "Intel D945", STAC_D945_REF),
1979 /* other systems */
1980 /* Apple Intel Mac (Mac Mini, MacBook, MacBook Pro...) */
1981 SND_PCI_QUIRK(0x8384, 0x7680,
1982 "Mac", STAC_INTEL_MAC_AUTO),
1983 /* Dell systems */
1984 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a7,
1985 "unknown Dell", STAC_922X_DELL_D81),
1986 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a9,
1987 "unknown Dell", STAC_922X_DELL_D81),
1988 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ab,
1989 "unknown Dell", STAC_922X_DELL_D81),
1990 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ac,
1991 "unknown Dell", STAC_922X_DELL_D82),
1992 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bf,
1993 "unknown Dell", STAC_922X_DELL_M81),
1994 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d0,
1995 "unknown Dell", STAC_922X_DELL_D82),
1996 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d1,
1997 "unknown Dell", STAC_922X_DELL_D81),
1998 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d2,
1999 "unknown Dell", STAC_922X_DELL_D81),
2000 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d7,
2001 "Dell XPS M1210", STAC_922X_DELL_M82),
2002 /* ECS/PC Chips boards */
2003 SND_PCI_QUIRK_MASK(0x1019, 0xf000, 0x2000,
2004 "ECS/PC chips", STAC_ECS_202),
2005 {} /* terminator */
2008 static unsigned int ref927x_pin_configs[14] = {
2009 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2010 0x01a19040, 0x01011012, 0x01016011, 0x0101201f,
2011 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
2012 0x01c42190, 0x40000100,
2015 static unsigned int d965_3st_pin_configs[14] = {
2016 0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
2017 0x01a19021, 0x01813024, 0x40000100, 0x40000100,
2018 0x40000100, 0x40000100, 0x40000100, 0x40000100,
2019 0x40000100, 0x40000100
2022 static unsigned int d965_5st_pin_configs[14] = {
2023 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2024 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
2025 0x40000100, 0x40000100, 0x40000100, 0x01442070,
2026 0x40000100, 0x40000100
2029 static unsigned int d965_5st_no_fp_pin_configs[14] = {
2030 0x40000100, 0x40000100, 0x0181304e, 0x01014010,
2031 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
2032 0x40000100, 0x40000100, 0x40000100, 0x01442070,
2033 0x40000100, 0x40000100
2036 static unsigned int dell_3st_pin_configs[14] = {
2037 0x02211230, 0x02a11220, 0x01a19040, 0x01114210,
2038 0x01111212, 0x01116211, 0x01813050, 0x01112214,
2039 0x403003fa, 0x90a60040, 0x90a60040, 0x404003fb,
2040 0x40c003fc, 0x40000100
2043 static unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
2044 [STAC_D965_REF_NO_JD] = ref927x_pin_configs,
2045 [STAC_D965_REF] = ref927x_pin_configs,
2046 [STAC_D965_3ST] = d965_3st_pin_configs,
2047 [STAC_D965_5ST] = d965_5st_pin_configs,
2048 [STAC_D965_5ST_NO_FP] = d965_5st_no_fp_pin_configs,
2049 [STAC_DELL_3ST] = dell_3st_pin_configs,
2050 [STAC_DELL_BIOS] = NULL,
2051 [STAC_927X_VOLKNOB] = NULL,
2054 static const char *stac927x_models[STAC_927X_MODELS] = {
2055 [STAC_927X_AUTO] = "auto",
2056 [STAC_D965_REF_NO_JD] = "ref-no-jd",
2057 [STAC_D965_REF] = "ref",
2058 [STAC_D965_3ST] = "3stack",
2059 [STAC_D965_5ST] = "5stack",
2060 [STAC_D965_5ST_NO_FP] = "5stack-no-fp",
2061 [STAC_DELL_3ST] = "dell-3stack",
2062 [STAC_DELL_BIOS] = "dell-bios",
2063 [STAC_927X_VOLKNOB] = "volknob",
2066 static struct snd_pci_quirk stac927x_cfg_tbl[] = {
2067 /* SigmaTel reference board */
2068 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2069 "DFI LanParty", STAC_D965_REF),
2070 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2071 "DFI LanParty", STAC_D965_REF),
2072 /* Intel 946 based systems */
2073 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST),
2074 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST),
2075 /* 965 based 3 stack systems */
2076 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2100,
2077 "Intel D965", STAC_D965_3ST),
2078 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2000,
2079 "Intel D965", STAC_D965_3ST),
2080 /* Dell 3 stack systems */
2081 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01dd, "Dell Dimension E520", STAC_DELL_3ST),
2082 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ed, "Dell ", STAC_DELL_3ST),
2083 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f4, "Dell ", STAC_DELL_3ST),
2084 /* Dell 3 stack systems with verb table in BIOS */
2085 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f3, "Dell Inspiron 1420", STAC_DELL_BIOS),
2086 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f7, "Dell XPS M1730", STAC_DELL_BIOS),
2087 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0227, "Dell Vostro 1400 ", STAC_DELL_BIOS),
2088 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022e, "Dell ", STAC_DELL_BIOS),
2089 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022f, "Dell Inspiron 1525", STAC_DELL_BIOS),
2090 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0242, "Dell ", STAC_DELL_BIOS),
2091 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0243, "Dell ", STAC_DELL_BIOS),
2092 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ff, "Dell ", STAC_DELL_BIOS),
2093 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0209, "Dell XPS 1330", STAC_DELL_BIOS),
2094 /* 965 based 5 stack systems */
2095 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2300,
2096 "Intel D965", STAC_D965_5ST),
2097 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2500,
2098 "Intel D965", STAC_D965_5ST),
2099 /* volume-knob fixes */
2100 SND_PCI_QUIRK_VENDOR(0x10cf, "FSC", STAC_927X_VOLKNOB),
2101 {} /* terminator */
2104 static unsigned int ref9205_pin_configs[12] = {
2105 0x40000100, 0x40000100, 0x01016011, 0x01014010,
2106 0x01813122, 0x01a19021, 0x01019020, 0x40000100,
2107 0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
2111 STAC 9205 pin configs for
2112 102801F1
2113 102801F2
2114 102801FC
2115 102801FD
2116 10280204
2117 1028021F
2118 10280228 (Dell Vostro 1500)
2119 10280229 (Dell Vostro 1700)
2121 static unsigned int dell_9205_m42_pin_configs[12] = {
2122 0x0321101F, 0x03A11020, 0x400003FA, 0x90170310,
2123 0x400003FB, 0x400003FC, 0x400003FD, 0x40F000F9,
2124 0x90A60330, 0x400003FF, 0x0144131F, 0x40C003FE,
2128 STAC 9205 pin configs for
2129 102801F9
2130 102801FA
2131 102801FE
2132 102801FF (Dell Precision M4300)
2133 10280206
2134 10280200
2135 10280201
2137 static unsigned int dell_9205_m43_pin_configs[12] = {
2138 0x0321101f, 0x03a11020, 0x90a70330, 0x90170310,
2139 0x400000fe, 0x400000ff, 0x400000fd, 0x40f000f9,
2140 0x400000fa, 0x400000fc, 0x0144131f, 0x40c003f8,
2143 static unsigned int dell_9205_m44_pin_configs[12] = {
2144 0x0421101f, 0x04a11020, 0x400003fa, 0x90170310,
2145 0x400003fb, 0x400003fc, 0x400003fd, 0x400003f9,
2146 0x90a60330, 0x400003ff, 0x01441340, 0x40c003fe,
2149 static unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
2150 [STAC_9205_REF] = ref9205_pin_configs,
2151 [STAC_9205_DELL_M42] = dell_9205_m42_pin_configs,
2152 [STAC_9205_DELL_M43] = dell_9205_m43_pin_configs,
2153 [STAC_9205_DELL_M44] = dell_9205_m44_pin_configs,
2154 [STAC_9205_EAPD] = NULL,
2157 static const char *stac9205_models[STAC_9205_MODELS] = {
2158 [STAC_9205_AUTO] = "auto",
2159 [STAC_9205_REF] = "ref",
2160 [STAC_9205_DELL_M42] = "dell-m42",
2161 [STAC_9205_DELL_M43] = "dell-m43",
2162 [STAC_9205_DELL_M44] = "dell-m44",
2163 [STAC_9205_EAPD] = "eapd",
2166 static struct snd_pci_quirk stac9205_cfg_tbl[] = {
2167 /* SigmaTel reference board */
2168 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2169 "DFI LanParty", STAC_9205_REF),
2170 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xfb30,
2171 "SigmaTel", STAC_9205_REF),
2172 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2173 "DFI LanParty", STAC_9205_REF),
2174 /* Dell */
2175 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f1,
2176 "unknown Dell", STAC_9205_DELL_M42),
2177 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f2,
2178 "unknown Dell", STAC_9205_DELL_M42),
2179 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f8,
2180 "Dell Precision", STAC_9205_DELL_M43),
2181 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f9,
2182 "Dell Precision", STAC_9205_DELL_M43),
2183 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fa,
2184 "Dell Precision", STAC_9205_DELL_M43),
2185 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fc,
2186 "unknown Dell", STAC_9205_DELL_M42),
2187 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fd,
2188 "unknown Dell", STAC_9205_DELL_M42),
2189 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fe,
2190 "Dell Precision", STAC_9205_DELL_M43),
2191 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ff,
2192 "Dell Precision M4300", STAC_9205_DELL_M43),
2193 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0204,
2194 "unknown Dell", STAC_9205_DELL_M42),
2195 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0206,
2196 "Dell Precision", STAC_9205_DELL_M43),
2197 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021b,
2198 "Dell Precision", STAC_9205_DELL_M43),
2199 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021c,
2200 "Dell Precision", STAC_9205_DELL_M43),
2201 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021f,
2202 "Dell Inspiron", STAC_9205_DELL_M44),
2203 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0228,
2204 "Dell Vostro 1500", STAC_9205_DELL_M42),
2205 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0229,
2206 "Dell Vostro 1700", STAC_9205_DELL_M42),
2207 /* Gateway */
2208 SND_PCI_QUIRK(0x107b, 0x0560, "Gateway T6834c", STAC_9205_EAPD),
2209 SND_PCI_QUIRK(0x107b, 0x0565, "Gateway T1616", STAC_9205_EAPD),
2210 {} /* terminator */
2213 static void stac92xx_set_config_regs(struct hda_codec *codec,
2214 unsigned int *pincfgs)
2216 int i;
2217 struct sigmatel_spec *spec = codec->spec;
2219 if (!pincfgs)
2220 return;
2222 for (i = 0; i < spec->num_pins; i++)
2223 if (spec->pin_nids[i] && pincfgs[i])
2224 snd_hda_codec_set_pincfg(codec, spec->pin_nids[i],
2225 pincfgs[i]);
2229 * Analog playback callbacks
2231 static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
2232 struct hda_codec *codec,
2233 struct snd_pcm_substream *substream)
2235 struct sigmatel_spec *spec = codec->spec;
2236 if (spec->stream_delay)
2237 msleep(spec->stream_delay);
2238 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2239 hinfo);
2242 static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2243 struct hda_codec *codec,
2244 unsigned int stream_tag,
2245 unsigned int format,
2246 struct snd_pcm_substream *substream)
2248 struct sigmatel_spec *spec = codec->spec;
2249 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
2252 static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2253 struct hda_codec *codec,
2254 struct snd_pcm_substream *substream)
2256 struct sigmatel_spec *spec = codec->spec;
2257 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2261 * Digital playback callbacks
2263 static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2264 struct hda_codec *codec,
2265 struct snd_pcm_substream *substream)
2267 struct sigmatel_spec *spec = codec->spec;
2268 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2271 static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2272 struct hda_codec *codec,
2273 struct snd_pcm_substream *substream)
2275 struct sigmatel_spec *spec = codec->spec;
2276 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2279 static int stac92xx_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2280 struct hda_codec *codec,
2281 unsigned int stream_tag,
2282 unsigned int format,
2283 struct snd_pcm_substream *substream)
2285 struct sigmatel_spec *spec = codec->spec;
2286 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2287 stream_tag, format, substream);
2290 static int stac92xx_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2291 struct hda_codec *codec,
2292 struct snd_pcm_substream *substream)
2294 struct sigmatel_spec *spec = codec->spec;
2295 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2300 * Analog capture callbacks
2302 static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2303 struct hda_codec *codec,
2304 unsigned int stream_tag,
2305 unsigned int format,
2306 struct snd_pcm_substream *substream)
2308 struct sigmatel_spec *spec = codec->spec;
2309 hda_nid_t nid = spec->adc_nids[substream->number];
2311 if (spec->powerdown_adcs) {
2312 msleep(40);
2313 snd_hda_codec_write(codec, nid, 0,
2314 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
2316 snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format);
2317 return 0;
2320 static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2321 struct hda_codec *codec,
2322 struct snd_pcm_substream *substream)
2324 struct sigmatel_spec *spec = codec->spec;
2325 hda_nid_t nid = spec->adc_nids[substream->number];
2327 snd_hda_codec_cleanup_stream(codec, nid);
2328 if (spec->powerdown_adcs)
2329 snd_hda_codec_write(codec, nid, 0,
2330 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
2331 return 0;
2334 static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
2335 .substreams = 1,
2336 .channels_min = 2,
2337 .channels_max = 2,
2338 /* NID is set in stac92xx_build_pcms */
2339 .ops = {
2340 .open = stac92xx_dig_playback_pcm_open,
2341 .close = stac92xx_dig_playback_pcm_close,
2342 .prepare = stac92xx_dig_playback_pcm_prepare,
2343 .cleanup = stac92xx_dig_playback_pcm_cleanup
2347 static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
2348 .substreams = 1,
2349 .channels_min = 2,
2350 .channels_max = 2,
2351 /* NID is set in stac92xx_build_pcms */
2354 static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
2355 .substreams = 1,
2356 .channels_min = 2,
2357 .channels_max = 8,
2358 .nid = 0x02, /* NID to query formats and rates */
2359 .ops = {
2360 .open = stac92xx_playback_pcm_open,
2361 .prepare = stac92xx_playback_pcm_prepare,
2362 .cleanup = stac92xx_playback_pcm_cleanup
2366 static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
2367 .substreams = 1,
2368 .channels_min = 2,
2369 .channels_max = 2,
2370 .nid = 0x06, /* NID to query formats and rates */
2371 .ops = {
2372 .open = stac92xx_playback_pcm_open,
2373 .prepare = stac92xx_playback_pcm_prepare,
2374 .cleanup = stac92xx_playback_pcm_cleanup
2378 static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
2379 .channels_min = 2,
2380 .channels_max = 2,
2381 /* NID + .substreams is set in stac92xx_build_pcms */
2382 .ops = {
2383 .prepare = stac92xx_capture_pcm_prepare,
2384 .cleanup = stac92xx_capture_pcm_cleanup
2388 static int stac92xx_build_pcms(struct hda_codec *codec)
2390 struct sigmatel_spec *spec = codec->spec;
2391 struct hda_pcm *info = spec->pcm_rec;
2393 codec->num_pcms = 1;
2394 codec->pcm_info = info;
2396 info->name = "STAC92xx Analog";
2397 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
2398 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2399 spec->multiout.dac_nids[0];
2400 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
2401 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2402 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adcs;
2404 if (spec->alt_switch) {
2405 codec->num_pcms++;
2406 info++;
2407 info->name = "STAC92xx Analog Alt";
2408 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
2411 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2412 codec->num_pcms++;
2413 info++;
2414 info->name = "STAC92xx Digital";
2415 info->pcm_type = spec->autocfg.dig_out_type[0];
2416 if (spec->multiout.dig_out_nid) {
2417 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
2418 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2420 if (spec->dig_in_nid) {
2421 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
2422 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2426 return 0;
2429 static unsigned int stac92xx_get_default_vref(struct hda_codec *codec,
2430 hda_nid_t nid)
2432 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2433 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
2434 if (pincap & AC_PINCAP_VREF_100)
2435 return AC_PINCTL_VREF_100;
2436 if (pincap & AC_PINCAP_VREF_80)
2437 return AC_PINCTL_VREF_80;
2438 if (pincap & AC_PINCAP_VREF_50)
2439 return AC_PINCTL_VREF_50;
2440 if (pincap & AC_PINCAP_VREF_GRD)
2441 return AC_PINCTL_VREF_GRD;
2442 return 0;
2445 static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
2448 snd_hda_codec_write_cache(codec, nid, 0,
2449 AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
2452 #define stac92xx_hp_switch_info snd_ctl_boolean_mono_info
2454 static int stac92xx_hp_switch_get(struct snd_kcontrol *kcontrol,
2455 struct snd_ctl_elem_value *ucontrol)
2457 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2458 struct sigmatel_spec *spec = codec->spec;
2460 ucontrol->value.integer.value[0] = !!spec->hp_switch;
2461 return 0;
2464 static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid);
2466 static int stac92xx_hp_switch_put(struct snd_kcontrol *kcontrol,
2467 struct snd_ctl_elem_value *ucontrol)
2469 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2470 struct sigmatel_spec *spec = codec->spec;
2471 int nid = kcontrol->private_value;
2473 spec->hp_switch = ucontrol->value.integer.value[0] ? nid : 0;
2475 /* check to be sure that the ports are upto date with
2476 * switch changes
2478 stac_issue_unsol_event(codec, nid);
2480 return 1;
2483 static int stac92xx_dc_bias_info(struct snd_kcontrol *kcontrol,
2484 struct snd_ctl_elem_info *uinfo)
2486 int i;
2487 static char *texts[] = {
2488 "Mic In", "Line In", "Line Out"
2491 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2492 struct sigmatel_spec *spec = codec->spec;
2493 hda_nid_t nid = kcontrol->private_value;
2495 if (nid == spec->mic_switch || nid == spec->line_switch)
2496 i = 3;
2497 else
2498 i = 2;
2500 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2501 uinfo->value.enumerated.items = i;
2502 uinfo->count = 1;
2503 if (uinfo->value.enumerated.item >= i)
2504 uinfo->value.enumerated.item = i-1;
2505 strcpy(uinfo->value.enumerated.name,
2506 texts[uinfo->value.enumerated.item]);
2508 return 0;
2511 static int stac92xx_dc_bias_get(struct snd_kcontrol *kcontrol,
2512 struct snd_ctl_elem_value *ucontrol)
2514 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2515 hda_nid_t nid = kcontrol->private_value;
2516 unsigned int vref = stac92xx_vref_get(codec, nid);
2518 if (vref == stac92xx_get_default_vref(codec, nid))
2519 ucontrol->value.enumerated.item[0] = 0;
2520 else if (vref == AC_PINCTL_VREF_GRD)
2521 ucontrol->value.enumerated.item[0] = 1;
2522 else if (vref == AC_PINCTL_VREF_HIZ)
2523 ucontrol->value.enumerated.item[0] = 2;
2525 return 0;
2528 static int stac92xx_dc_bias_put(struct snd_kcontrol *kcontrol,
2529 struct snd_ctl_elem_value *ucontrol)
2531 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2532 unsigned int new_vref = 0;
2533 int error;
2534 hda_nid_t nid = kcontrol->private_value;
2536 if (ucontrol->value.enumerated.item[0] == 0)
2537 new_vref = stac92xx_get_default_vref(codec, nid);
2538 else if (ucontrol->value.enumerated.item[0] == 1)
2539 new_vref = AC_PINCTL_VREF_GRD;
2540 else if (ucontrol->value.enumerated.item[0] == 2)
2541 new_vref = AC_PINCTL_VREF_HIZ;
2542 else
2543 return 0;
2545 if (new_vref != stac92xx_vref_get(codec, nid)) {
2546 error = stac92xx_vref_set(codec, nid, new_vref);
2547 return error;
2550 return 0;
2553 static int stac92xx_io_switch_info(struct snd_kcontrol *kcontrol,
2554 struct snd_ctl_elem_info *uinfo)
2556 static char *texts[2];
2557 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2558 struct sigmatel_spec *spec = codec->spec;
2560 if (kcontrol->private_value == spec->line_switch)
2561 texts[0] = "Line In";
2562 else
2563 texts[0] = "Mic In";
2564 texts[1] = "Line Out";
2565 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2566 uinfo->value.enumerated.items = 2;
2567 uinfo->count = 1;
2569 if (uinfo->value.enumerated.item >= 2)
2570 uinfo->value.enumerated.item = 1;
2571 strcpy(uinfo->value.enumerated.name,
2572 texts[uinfo->value.enumerated.item]);
2574 return 0;
2577 static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2579 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2580 struct sigmatel_spec *spec = codec->spec;
2581 hda_nid_t nid = kcontrol->private_value;
2582 int io_idx = (nid == spec->mic_switch) ? 1 : 0;
2584 ucontrol->value.enumerated.item[0] = spec->io_switch[io_idx];
2585 return 0;
2588 static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2590 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2591 struct sigmatel_spec *spec = codec->spec;
2592 hda_nid_t nid = kcontrol->private_value;
2593 int io_idx = (nid == spec->mic_switch) ? 1 : 0;
2594 unsigned short val = !!ucontrol->value.enumerated.item[0];
2596 spec->io_switch[io_idx] = val;
2598 if (val)
2599 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
2600 else {
2601 unsigned int pinctl = AC_PINCTL_IN_EN;
2602 if (io_idx) /* set VREF for mic */
2603 pinctl |= stac92xx_get_default_vref(codec, nid);
2604 stac92xx_auto_set_pinctl(codec, nid, pinctl);
2607 /* check the auto-mute again: we need to mute/unmute the speaker
2608 * appropriately according to the pin direction
2610 if (spec->hp_detect)
2611 stac_issue_unsol_event(codec, nid);
2613 return 1;
2616 #define stac92xx_clfe_switch_info snd_ctl_boolean_mono_info
2618 static int stac92xx_clfe_switch_get(struct snd_kcontrol *kcontrol,
2619 struct snd_ctl_elem_value *ucontrol)
2621 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2622 struct sigmatel_spec *spec = codec->spec;
2624 ucontrol->value.integer.value[0] = spec->clfe_swap;
2625 return 0;
2628 static int stac92xx_clfe_switch_put(struct snd_kcontrol *kcontrol,
2629 struct snd_ctl_elem_value *ucontrol)
2631 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2632 struct sigmatel_spec *spec = codec->spec;
2633 hda_nid_t nid = kcontrol->private_value & 0xff;
2634 unsigned int val = !!ucontrol->value.integer.value[0];
2636 if (spec->clfe_swap == val)
2637 return 0;
2639 spec->clfe_swap = val;
2641 snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
2642 spec->clfe_swap ? 0x4 : 0x0);
2644 return 1;
2647 #define STAC_CODEC_HP_SWITCH(xname) \
2648 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2649 .name = xname, \
2650 .index = 0, \
2651 .info = stac92xx_hp_switch_info, \
2652 .get = stac92xx_hp_switch_get, \
2653 .put = stac92xx_hp_switch_put, \
2656 #define STAC_CODEC_IO_SWITCH(xname, xpval) \
2657 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2658 .name = xname, \
2659 .index = 0, \
2660 .info = stac92xx_io_switch_info, \
2661 .get = stac92xx_io_switch_get, \
2662 .put = stac92xx_io_switch_put, \
2663 .private_value = xpval, \
2666 #define STAC_CODEC_CLFE_SWITCH(xname, xpval) \
2667 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2668 .name = xname, \
2669 .index = 0, \
2670 .info = stac92xx_clfe_switch_info, \
2671 .get = stac92xx_clfe_switch_get, \
2672 .put = stac92xx_clfe_switch_put, \
2673 .private_value = xpval, \
2676 enum {
2677 STAC_CTL_WIDGET_VOL,
2678 STAC_CTL_WIDGET_MUTE,
2679 STAC_CTL_WIDGET_MUTE_BEEP,
2680 STAC_CTL_WIDGET_MONO_MUX,
2681 STAC_CTL_WIDGET_HP_SWITCH,
2682 STAC_CTL_WIDGET_IO_SWITCH,
2683 STAC_CTL_WIDGET_CLFE_SWITCH,
2684 STAC_CTL_WIDGET_DC_BIAS
2687 static struct snd_kcontrol_new stac92xx_control_templates[] = {
2688 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2689 HDA_CODEC_MUTE(NULL, 0, 0, 0),
2690 HDA_CODEC_MUTE_BEEP(NULL, 0, 0, 0),
2691 STAC_MONO_MUX,
2692 STAC_CODEC_HP_SWITCH(NULL),
2693 STAC_CODEC_IO_SWITCH(NULL, 0),
2694 STAC_CODEC_CLFE_SWITCH(NULL, 0),
2695 DC_BIAS(NULL, 0, 0),
2698 /* add dynamic controls */
2699 static struct snd_kcontrol_new *
2700 stac_control_new(struct sigmatel_spec *spec,
2701 struct snd_kcontrol_new *ktemp,
2702 const char *name,
2703 unsigned int subdev)
2705 struct snd_kcontrol_new *knew;
2707 snd_array_init(&spec->kctls, sizeof(*knew), 32);
2708 knew = snd_array_new(&spec->kctls);
2709 if (!knew)
2710 return NULL;
2711 *knew = *ktemp;
2712 knew->name = kstrdup(name, GFP_KERNEL);
2713 if (!knew->name) {
2714 /* roolback */
2715 memset(knew, 0, sizeof(*knew));
2716 spec->kctls.alloced--;
2717 return NULL;
2719 knew->subdevice = subdev;
2720 return knew;
2723 static int stac92xx_add_control_temp(struct sigmatel_spec *spec,
2724 struct snd_kcontrol_new *ktemp,
2725 int idx, const char *name,
2726 unsigned long val)
2728 struct snd_kcontrol_new *knew = stac_control_new(spec, ktemp, name,
2729 HDA_SUBDEV_AMP_FLAG);
2730 if (!knew)
2731 return -ENOMEM;
2732 knew->index = idx;
2733 knew->private_value = val;
2734 return 0;
2737 static inline int stac92xx_add_control_idx(struct sigmatel_spec *spec,
2738 int type, int idx, const char *name,
2739 unsigned long val)
2741 return stac92xx_add_control_temp(spec,
2742 &stac92xx_control_templates[type],
2743 idx, name, val);
2747 /* add dynamic controls */
2748 static inline int stac92xx_add_control(struct sigmatel_spec *spec, int type,
2749 const char *name, unsigned long val)
2751 return stac92xx_add_control_idx(spec, type, 0, name, val);
2754 static struct snd_kcontrol_new stac_input_src_temp = {
2755 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2756 .name = "Input Source",
2757 .info = stac92xx_mux_enum_info,
2758 .get = stac92xx_mux_enum_get,
2759 .put = stac92xx_mux_enum_put,
2762 static inline int stac92xx_add_jack_mode_control(struct hda_codec *codec,
2763 hda_nid_t nid, int idx)
2765 int def_conf = snd_hda_codec_get_pincfg(codec, nid);
2766 int control = 0;
2767 struct sigmatel_spec *spec = codec->spec;
2768 char name[22];
2770 if (!((get_defcfg_connect(def_conf)) & AC_JACK_PORT_FIXED)) {
2771 if (stac92xx_get_default_vref(codec, nid) == AC_PINCTL_VREF_GRD
2772 && nid == spec->line_switch)
2773 control = STAC_CTL_WIDGET_IO_SWITCH;
2774 else if (snd_hda_query_pin_caps(codec, nid)
2775 & (AC_PINCAP_VREF_GRD << AC_PINCAP_VREF_SHIFT))
2776 control = STAC_CTL_WIDGET_DC_BIAS;
2777 else if (nid == spec->mic_switch)
2778 control = STAC_CTL_WIDGET_IO_SWITCH;
2781 if (control) {
2782 strcpy(name, auto_pin_cfg_labels[idx]);
2783 return stac92xx_add_control(codec->spec, control,
2784 strcat(name, " Jack Mode"), nid);
2787 return 0;
2790 static int stac92xx_add_input_source(struct sigmatel_spec *spec)
2792 struct snd_kcontrol_new *knew;
2793 struct hda_input_mux *imux = &spec->private_imux;
2795 if (spec->auto_mic)
2796 return 0; /* no need for input source */
2797 if (!spec->num_adcs || imux->num_items <= 1)
2798 return 0; /* no need for input source control */
2799 knew = stac_control_new(spec, &stac_input_src_temp,
2800 stac_input_src_temp.name, 0);
2801 if (!knew)
2802 return -ENOMEM;
2803 knew->count = spec->num_adcs;
2804 return 0;
2807 /* check whether the line-input can be used as line-out */
2808 static hda_nid_t check_line_out_switch(struct hda_codec *codec)
2810 struct sigmatel_spec *spec = codec->spec;
2811 struct auto_pin_cfg *cfg = &spec->autocfg;
2812 hda_nid_t nid;
2813 unsigned int pincap;
2815 if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
2816 return 0;
2817 nid = cfg->input_pins[AUTO_PIN_LINE];
2818 pincap = snd_hda_query_pin_caps(codec, nid);
2819 if (pincap & AC_PINCAP_OUT)
2820 return nid;
2821 return 0;
2824 /* check whether the mic-input can be used as line-out */
2825 static hda_nid_t check_mic_out_switch(struct hda_codec *codec)
2827 struct sigmatel_spec *spec = codec->spec;
2828 struct auto_pin_cfg *cfg = &spec->autocfg;
2829 unsigned int def_conf, pincap;
2830 unsigned int mic_pin;
2832 if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
2833 return 0;
2834 mic_pin = AUTO_PIN_MIC;
2835 for (;;) {
2836 hda_nid_t nid = cfg->input_pins[mic_pin];
2837 def_conf = snd_hda_codec_get_pincfg(codec, nid);
2838 /* some laptops have an internal analog microphone
2839 * which can't be used as a output */
2840 if (get_defcfg_connect(def_conf) != AC_JACK_PORT_FIXED) {
2841 pincap = snd_hda_query_pin_caps(codec, nid);
2842 if (pincap & AC_PINCAP_OUT)
2843 return nid;
2845 if (mic_pin == AUTO_PIN_MIC)
2846 mic_pin = AUTO_PIN_FRONT_MIC;
2847 else
2848 break;
2850 return 0;
2853 static int is_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2855 int i;
2857 for (i = 0; i < spec->multiout.num_dacs; i++) {
2858 if (spec->multiout.dac_nids[i] == nid)
2859 return 1;
2862 return 0;
2865 static int check_all_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2867 int i;
2868 if (is_in_dac_nids(spec, nid))
2869 return 1;
2870 for (i = 0; i < spec->autocfg.hp_outs; i++)
2871 if (spec->hp_dacs[i] == nid)
2872 return 1;
2873 for (i = 0; i < spec->autocfg.speaker_outs; i++)
2874 if (spec->speaker_dacs[i] == nid)
2875 return 1;
2876 return 0;
2879 static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t nid)
2881 struct sigmatel_spec *spec = codec->spec;
2882 int j, conn_len;
2883 hda_nid_t conn[HDA_MAX_CONNECTIONS];
2884 unsigned int wcaps, wtype;
2886 conn_len = snd_hda_get_connections(codec, nid, conn,
2887 HDA_MAX_CONNECTIONS);
2888 /* 92HD88: trace back up the link of nids to find the DAC */
2889 while (conn_len == 1 && (get_wcaps_type(get_wcaps(codec, conn[0]))
2890 != AC_WID_AUD_OUT)) {
2891 nid = conn[0];
2892 conn_len = snd_hda_get_connections(codec, nid, conn,
2893 HDA_MAX_CONNECTIONS);
2895 for (j = 0; j < conn_len; j++) {
2896 wcaps = get_wcaps(codec, conn[j]);
2897 wtype = get_wcaps_type(wcaps);
2898 /* we check only analog outputs */
2899 if (wtype != AC_WID_AUD_OUT || (wcaps & AC_WCAP_DIGITAL))
2900 continue;
2901 /* if this route has a free DAC, assign it */
2902 if (!check_all_dac_nids(spec, conn[j])) {
2903 if (conn_len > 1) {
2904 /* select this DAC in the pin's input mux */
2905 snd_hda_codec_write_cache(codec, nid, 0,
2906 AC_VERB_SET_CONNECT_SEL, j);
2908 return conn[j];
2911 /* if all DACs are already assigned, connect to the primary DAC */
2912 if (conn_len > 1) {
2913 for (j = 0; j < conn_len; j++) {
2914 if (conn[j] == spec->multiout.dac_nids[0]) {
2915 snd_hda_codec_write_cache(codec, nid, 0,
2916 AC_VERB_SET_CONNECT_SEL, j);
2917 break;
2921 return 0;
2924 static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid);
2925 static int add_spec_extra_dacs(struct sigmatel_spec *spec, hda_nid_t nid);
2928 * Fill in the dac_nids table from the parsed pin configuration
2929 * This function only works when every pin in line_out_pins[]
2930 * contains atleast one DAC in its connection list. Some 92xx
2931 * codecs are not connected directly to a DAC, such as the 9200
2932 * and 9202/925x. For those, dac_nids[] must be hard-coded.
2934 static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec)
2936 struct sigmatel_spec *spec = codec->spec;
2937 struct auto_pin_cfg *cfg = &spec->autocfg;
2938 int i;
2939 hda_nid_t nid, dac;
2941 for (i = 0; i < cfg->line_outs; i++) {
2942 nid = cfg->line_out_pins[i];
2943 dac = get_unassigned_dac(codec, nid);
2944 if (!dac) {
2945 if (spec->multiout.num_dacs > 0) {
2946 /* we have already working output pins,
2947 * so let's drop the broken ones again
2949 cfg->line_outs = spec->multiout.num_dacs;
2950 break;
2952 /* error out, no available DAC found */
2953 snd_printk(KERN_ERR
2954 "%s: No available DAC for pin 0x%x\n",
2955 __func__, nid);
2956 return -ENODEV;
2958 add_spec_dacs(spec, dac);
2961 for (i = 0; i < cfg->hp_outs; i++) {
2962 nid = cfg->hp_pins[i];
2963 dac = get_unassigned_dac(codec, nid);
2964 if (dac) {
2965 if (!spec->multiout.hp_nid)
2966 spec->multiout.hp_nid = dac;
2967 else
2968 add_spec_extra_dacs(spec, dac);
2970 spec->hp_dacs[i] = dac;
2973 for (i = 0; i < cfg->speaker_outs; i++) {
2974 nid = cfg->speaker_pins[i];
2975 dac = get_unassigned_dac(codec, nid);
2976 if (dac)
2977 add_spec_extra_dacs(spec, dac);
2978 spec->speaker_dacs[i] = dac;
2981 /* add line-in as output */
2982 nid = check_line_out_switch(codec);
2983 if (nid) {
2984 dac = get_unassigned_dac(codec, nid);
2985 if (dac) {
2986 snd_printdd("STAC: Add line-in 0x%x as output %d\n",
2987 nid, cfg->line_outs);
2988 cfg->line_out_pins[cfg->line_outs] = nid;
2989 cfg->line_outs++;
2990 spec->line_switch = nid;
2991 add_spec_dacs(spec, dac);
2994 /* add mic as output */
2995 nid = check_mic_out_switch(codec);
2996 if (nid) {
2997 dac = get_unassigned_dac(codec, nid);
2998 if (dac) {
2999 snd_printdd("STAC: Add mic-in 0x%x as output %d\n",
3000 nid, cfg->line_outs);
3001 cfg->line_out_pins[cfg->line_outs] = nid;
3002 cfg->line_outs++;
3003 spec->mic_switch = nid;
3004 add_spec_dacs(spec, dac);
3008 snd_printd("stac92xx: dac_nids=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
3009 spec->multiout.num_dacs,
3010 spec->multiout.dac_nids[0],
3011 spec->multiout.dac_nids[1],
3012 spec->multiout.dac_nids[2],
3013 spec->multiout.dac_nids[3],
3014 spec->multiout.dac_nids[4]);
3016 return 0;
3019 /* create volume control/switch for the given prefx type */
3020 static int create_controls_idx(struct hda_codec *codec, const char *pfx,
3021 int idx, hda_nid_t nid, int chs)
3023 struct sigmatel_spec *spec = codec->spec;
3024 char name[32];
3025 int err;
3027 if (!spec->check_volume_offset) {
3028 unsigned int caps, step, nums, db_scale;
3029 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3030 step = (caps & AC_AMPCAP_STEP_SIZE) >>
3031 AC_AMPCAP_STEP_SIZE_SHIFT;
3032 step = (step + 1) * 25; /* in .01dB unit */
3033 nums = (caps & AC_AMPCAP_NUM_STEPS) >>
3034 AC_AMPCAP_NUM_STEPS_SHIFT;
3035 db_scale = nums * step;
3036 /* if dB scale is over -64dB, and finer enough,
3037 * let's reduce it to half
3039 if (db_scale > 6400 && nums >= 0x1f)
3040 spec->volume_offset = nums / 2;
3041 spec->check_volume_offset = 1;
3044 sprintf(name, "%s Playback Volume", pfx);
3045 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_VOL, idx, name,
3046 HDA_COMPOSE_AMP_VAL_OFS(nid, chs, 0, HDA_OUTPUT,
3047 spec->volume_offset));
3048 if (err < 0)
3049 return err;
3050 sprintf(name, "%s Playback Switch", pfx);
3051 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_MUTE, idx, name,
3052 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
3053 if (err < 0)
3054 return err;
3055 return 0;
3058 #define create_controls(codec, pfx, nid, chs) \
3059 create_controls_idx(codec, pfx, 0, nid, chs)
3061 static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
3063 if (spec->multiout.num_dacs > 4) {
3064 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
3065 return 1;
3066 } else {
3067 spec->multiout.dac_nids[spec->multiout.num_dacs] = nid;
3068 spec->multiout.num_dacs++;
3070 return 0;
3073 static int add_spec_extra_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
3075 int i;
3076 for (i = 0; i < ARRAY_SIZE(spec->multiout.extra_out_nid); i++) {
3077 if (!spec->multiout.extra_out_nid[i]) {
3078 spec->multiout.extra_out_nid[i] = nid;
3079 return 0;
3082 printk(KERN_WARNING "stac92xx: No space for extra DAC 0x%x\n", nid);
3083 return 1;
3086 /* Create output controls
3087 * The mixer elements are named depending on the given type (AUTO_PIN_XXX_OUT)
3089 static int create_multi_out_ctls(struct hda_codec *codec, int num_outs,
3090 const hda_nid_t *pins,
3091 const hda_nid_t *dac_nids,
3092 int type)
3094 struct sigmatel_spec *spec = codec->spec;
3095 static const char *chname[4] = {
3096 "Front", "Surround", NULL /*CLFE*/, "Side"
3098 hda_nid_t nid;
3099 int i, err;
3100 unsigned int wid_caps;
3102 for (i = 0; i < num_outs && i < ARRAY_SIZE(chname); i++) {
3103 if (type == AUTO_PIN_HP_OUT && !spec->hp_detect) {
3104 wid_caps = get_wcaps(codec, pins[i]);
3105 if (wid_caps & AC_WCAP_UNSOL_CAP)
3106 spec->hp_detect = 1;
3108 nid = dac_nids[i];
3109 if (!nid)
3110 continue;
3111 if (type != AUTO_PIN_HP_OUT && i == 2) {
3112 /* Center/LFE */
3113 err = create_controls(codec, "Center", nid, 1);
3114 if (err < 0)
3115 return err;
3116 err = create_controls(codec, "LFE", nid, 2);
3117 if (err < 0)
3118 return err;
3120 wid_caps = get_wcaps(codec, nid);
3122 if (wid_caps & AC_WCAP_LR_SWAP) {
3123 err = stac92xx_add_control(spec,
3124 STAC_CTL_WIDGET_CLFE_SWITCH,
3125 "Swap Center/LFE Playback Switch", nid);
3127 if (err < 0)
3128 return err;
3131 } else {
3132 const char *name;
3133 int idx;
3134 switch (type) {
3135 case AUTO_PIN_HP_OUT:
3136 name = "Headphone";
3137 idx = i;
3138 break;
3139 case AUTO_PIN_SPEAKER_OUT:
3140 name = "Speaker";
3141 idx = i;
3142 break;
3143 default:
3144 name = chname[i];
3145 idx = 0;
3146 break;
3148 err = create_controls_idx(codec, name, idx, nid, 3);
3149 if (err < 0)
3150 return err;
3153 return 0;
3156 static int stac92xx_add_capvol_ctls(struct hda_codec *codec, unsigned long vol,
3157 unsigned long sw, int idx)
3159 int err;
3160 err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_VOL, idx,
3161 "Capture Volume", vol);
3162 if (err < 0)
3163 return err;
3164 err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_MUTE, idx,
3165 "Capture Switch", sw);
3166 if (err < 0)
3167 return err;
3168 return 0;
3171 /* add playback controls from the parsed DAC table */
3172 static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
3173 const struct auto_pin_cfg *cfg)
3175 struct sigmatel_spec *spec = codec->spec;
3176 hda_nid_t nid;
3177 int err;
3178 int idx;
3180 err = create_multi_out_ctls(codec, cfg->line_outs, cfg->line_out_pins,
3181 spec->multiout.dac_nids,
3182 cfg->line_out_type);
3183 if (err < 0)
3184 return err;
3186 if (cfg->hp_outs > 1 && cfg->line_out_type == AUTO_PIN_LINE_OUT) {
3187 err = stac92xx_add_control(spec,
3188 STAC_CTL_WIDGET_HP_SWITCH,
3189 "Headphone as Line Out Switch",
3190 cfg->hp_pins[cfg->hp_outs - 1]);
3191 if (err < 0)
3192 return err;
3195 for (idx = AUTO_PIN_MIC; idx <= AUTO_PIN_FRONT_LINE; idx++) {
3196 nid = cfg->input_pins[idx];
3197 if (nid) {
3198 err = stac92xx_add_jack_mode_control(codec, nid, idx);
3199 if (err < 0)
3200 return err;
3204 return 0;
3207 /* add playback controls for Speaker and HP outputs */
3208 static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
3209 struct auto_pin_cfg *cfg)
3211 struct sigmatel_spec *spec = codec->spec;
3212 int err;
3214 err = create_multi_out_ctls(codec, cfg->hp_outs, cfg->hp_pins,
3215 spec->hp_dacs, AUTO_PIN_HP_OUT);
3216 if (err < 0)
3217 return err;
3219 err = create_multi_out_ctls(codec, cfg->speaker_outs, cfg->speaker_pins,
3220 spec->speaker_dacs, AUTO_PIN_SPEAKER_OUT);
3221 if (err < 0)
3222 return err;
3224 return 0;
3227 /* labels for mono mux outputs */
3228 static const char *stac92xx_mono_labels[4] = {
3229 "DAC0", "DAC1", "Mixer", "DAC2"
3232 /* create mono mux for mono out on capable codecs */
3233 static int stac92xx_auto_create_mono_output_ctls(struct hda_codec *codec)
3235 struct sigmatel_spec *spec = codec->spec;
3236 struct hda_input_mux *mono_mux = &spec->private_mono_mux;
3237 int i, num_cons;
3238 hda_nid_t con_lst[ARRAY_SIZE(stac92xx_mono_labels)];
3240 num_cons = snd_hda_get_connections(codec,
3241 spec->mono_nid,
3242 con_lst,
3243 HDA_MAX_NUM_INPUTS);
3244 if (num_cons <= 0 || num_cons > ARRAY_SIZE(stac92xx_mono_labels))
3245 return -EINVAL;
3247 for (i = 0; i < num_cons; i++) {
3248 mono_mux->items[mono_mux->num_items].label =
3249 stac92xx_mono_labels[i];
3250 mono_mux->items[mono_mux->num_items].index = i;
3251 mono_mux->num_items++;
3254 return stac92xx_add_control(spec, STAC_CTL_WIDGET_MONO_MUX,
3255 "Mono Mux", spec->mono_nid);
3258 /* create PC beep volume controls */
3259 static int stac92xx_auto_create_beep_ctls(struct hda_codec *codec,
3260 hda_nid_t nid)
3262 struct sigmatel_spec *spec = codec->spec;
3263 u32 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3264 int err, type = STAC_CTL_WIDGET_MUTE_BEEP;
3266 if (spec->anabeep_nid == nid)
3267 type = STAC_CTL_WIDGET_MUTE;
3269 /* check for mute support for the the amp */
3270 if ((caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT) {
3271 err = stac92xx_add_control(spec, type,
3272 "Beep Playback Switch",
3273 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3274 if (err < 0)
3275 return err;
3278 /* check to see if there is volume support for the amp */
3279 if ((caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3280 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL,
3281 "Beep Playback Volume",
3282 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3283 if (err < 0)
3284 return err;
3286 return 0;
3289 #ifdef CONFIG_SND_HDA_INPUT_BEEP
3290 #define stac92xx_dig_beep_switch_info snd_ctl_boolean_mono_info
3292 static int stac92xx_dig_beep_switch_get(struct snd_kcontrol *kcontrol,
3293 struct snd_ctl_elem_value *ucontrol)
3295 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3296 ucontrol->value.integer.value[0] = codec->beep->enabled;
3297 return 0;
3300 static int stac92xx_dig_beep_switch_put(struct snd_kcontrol *kcontrol,
3301 struct snd_ctl_elem_value *ucontrol)
3303 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3304 return snd_hda_enable_beep_device(codec, ucontrol->value.integer.value[0]);
3307 static struct snd_kcontrol_new stac92xx_dig_beep_ctrl = {
3308 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3309 .info = stac92xx_dig_beep_switch_info,
3310 .get = stac92xx_dig_beep_switch_get,
3311 .put = stac92xx_dig_beep_switch_put,
3314 static int stac92xx_beep_switch_ctl(struct hda_codec *codec)
3316 return stac92xx_add_control_temp(codec->spec, &stac92xx_dig_beep_ctrl,
3317 0, "Beep Playback Switch", 0);
3319 #endif
3321 static int stac92xx_auto_create_mux_input_ctls(struct hda_codec *codec)
3323 struct sigmatel_spec *spec = codec->spec;
3324 int i, j, err = 0;
3326 for (i = 0; i < spec->num_muxes; i++) {
3327 hda_nid_t nid;
3328 unsigned int wcaps;
3329 unsigned long val;
3331 nid = spec->mux_nids[i];
3332 wcaps = get_wcaps(codec, nid);
3333 if (!(wcaps & AC_WCAP_OUT_AMP))
3334 continue;
3336 /* check whether already the same control was created as
3337 * normal Capture Volume.
3339 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3340 for (j = 0; j < spec->num_caps; j++) {
3341 if (spec->capvols[j] == val)
3342 break;
3344 if (j < spec->num_caps)
3345 continue;
3347 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_VOL, i,
3348 "Mux Capture Volume", val);
3349 if (err < 0)
3350 return err;
3352 return 0;
3355 static const char *stac92xx_spdif_labels[3] = {
3356 "Digital Playback", "Analog Mux 1", "Analog Mux 2",
3359 static int stac92xx_auto_create_spdif_mux_ctls(struct hda_codec *codec)
3361 struct sigmatel_spec *spec = codec->spec;
3362 struct hda_input_mux *spdif_mux = &spec->private_smux;
3363 const char **labels = spec->spdif_labels;
3364 int i, num_cons;
3365 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
3367 num_cons = snd_hda_get_connections(codec,
3368 spec->smux_nids[0],
3369 con_lst,
3370 HDA_MAX_NUM_INPUTS);
3371 if (num_cons <= 0)
3372 return -EINVAL;
3374 if (!labels)
3375 labels = stac92xx_spdif_labels;
3377 for (i = 0; i < num_cons; i++) {
3378 spdif_mux->items[spdif_mux->num_items].label = labels[i];
3379 spdif_mux->items[spdif_mux->num_items].index = i;
3380 spdif_mux->num_items++;
3383 return 0;
3386 /* labels for dmic mux inputs */
3387 static const char *stac92xx_dmic_labels[5] = {
3388 "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
3389 "Digital Mic 3", "Digital Mic 4"
3392 static int get_connection_index(struct hda_codec *codec, hda_nid_t mux,
3393 hda_nid_t nid)
3395 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
3396 int i, nums;
3398 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
3399 for (i = 0; i < nums; i++)
3400 if (conn[i] == nid)
3401 return i;
3402 return -1;
3405 /* create a volume assigned to the given pin (only if supported) */
3406 /* return 1 if the volume control is created */
3407 static int create_elem_capture_vol(struct hda_codec *codec, hda_nid_t nid,
3408 const char *label, int direction)
3410 unsigned int caps, nums;
3411 char name[32];
3412 int err;
3414 if (direction == HDA_OUTPUT)
3415 caps = AC_WCAP_OUT_AMP;
3416 else
3417 caps = AC_WCAP_IN_AMP;
3418 if (!(get_wcaps(codec, nid) & caps))
3419 return 0;
3420 caps = query_amp_caps(codec, nid, direction);
3421 nums = (caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT;
3422 if (!nums)
3423 return 0;
3424 snprintf(name, sizeof(name), "%s Capture Volume", label);
3425 err = stac92xx_add_control(codec->spec, STAC_CTL_WIDGET_VOL, name,
3426 HDA_COMPOSE_AMP_VAL(nid, 3, 0, direction));
3427 if (err < 0)
3428 return err;
3429 return 1;
3432 /* create playback/capture controls for input pins on dmic capable codecs */
3433 static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
3434 const struct auto_pin_cfg *cfg)
3436 struct sigmatel_spec *spec = codec->spec;
3437 struct hda_input_mux *imux = &spec->private_imux;
3438 struct hda_input_mux *dimux = &spec->private_dimux;
3439 int err, i, active_mics;
3440 unsigned int def_conf;
3442 dimux->items[dimux->num_items].label = stac92xx_dmic_labels[0];
3443 dimux->items[dimux->num_items].index = 0;
3444 dimux->num_items++;
3446 active_mics = 0;
3447 for (i = 0; i < spec->num_dmics; i++) {
3448 /* check the validity: sometimes it's a dead vendor-spec node */
3449 if (get_wcaps_type(get_wcaps(codec, spec->dmic_nids[i]))
3450 != AC_WID_PIN)
3451 continue;
3452 def_conf = snd_hda_codec_get_pincfg(codec, spec->dmic_nids[i]);
3453 if (get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)
3454 active_mics++;
3457 for (i = 0; i < spec->num_dmics; i++) {
3458 hda_nid_t nid;
3459 int index;
3460 const char *label;
3462 nid = spec->dmic_nids[i];
3463 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
3464 continue;
3465 def_conf = snd_hda_codec_get_pincfg(codec, nid);
3466 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
3467 continue;
3469 index = get_connection_index(codec, spec->dmux_nids[0], nid);
3470 if (index < 0)
3471 continue;
3473 if (active_mics == 1)
3474 label = "Digital Mic";
3475 else
3476 label = stac92xx_dmic_labels[dimux->num_items];
3478 err = create_elem_capture_vol(codec, nid, label, HDA_INPUT);
3479 if (err < 0)
3480 return err;
3481 if (!err) {
3482 err = create_elem_capture_vol(codec, nid, label,
3483 HDA_OUTPUT);
3484 if (err < 0)
3485 return err;
3488 dimux->items[dimux->num_items].label = label;
3489 dimux->items[dimux->num_items].index = index;
3490 dimux->num_items++;
3491 if (snd_hda_get_bool_hint(codec, "separate_dmux") != 1) {
3492 imux->items[imux->num_items].label = label;
3493 imux->items[imux->num_items].index = index;
3494 imux->num_items++;
3498 return 0;
3501 static int check_mic_pin(struct hda_codec *codec, hda_nid_t nid,
3502 hda_nid_t *fixed, hda_nid_t *ext)
3504 unsigned int cfg;
3506 if (!nid)
3507 return 0;
3508 cfg = snd_hda_codec_get_pincfg(codec, nid);
3509 switch (get_defcfg_connect(cfg)) {
3510 case AC_JACK_PORT_FIXED:
3511 if (*fixed)
3512 return 1; /* already occupied */
3513 *fixed = nid;
3514 break;
3515 case AC_JACK_PORT_COMPLEX:
3516 if (*ext)
3517 return 1; /* already occupied */
3518 *ext = nid;
3519 break;
3521 return 0;
3524 static int set_mic_route(struct hda_codec *codec,
3525 struct sigmatel_mic_route *mic,
3526 hda_nid_t pin)
3528 struct sigmatel_spec *spec = codec->spec;
3529 struct auto_pin_cfg *cfg = &spec->autocfg;
3530 int i;
3532 mic->pin = pin;
3533 for (i = AUTO_PIN_MIC; i <= AUTO_PIN_FRONT_MIC; i++)
3534 if (pin == cfg->input_pins[i])
3535 break;
3536 if (i <= AUTO_PIN_FRONT_MIC) {
3537 /* analog pin */
3538 i = get_connection_index(codec, spec->mux_nids[0], pin);
3539 if (i < 0)
3540 return -1;
3541 mic->mux_idx = i;
3542 mic->dmux_idx = -1;
3543 if (spec->dmux_nids)
3544 mic->dmux_idx = get_connection_index(codec,
3545 spec->dmux_nids[0],
3546 spec->mux_nids[0]);
3547 } else if (spec->dmux_nids) {
3548 /* digital pin */
3549 i = get_connection_index(codec, spec->dmux_nids[0], pin);
3550 if (i < 0)
3551 return -1;
3552 mic->dmux_idx = i;
3553 mic->mux_idx = -1;
3554 if (spec->mux_nids)
3555 mic->mux_idx = get_connection_index(codec,
3556 spec->mux_nids[0],
3557 spec->dmux_nids[0]);
3559 return 0;
3562 /* return non-zero if the device is for automatic mic switch */
3563 static int stac_check_auto_mic(struct hda_codec *codec)
3565 struct sigmatel_spec *spec = codec->spec;
3566 struct auto_pin_cfg *cfg = &spec->autocfg;
3567 hda_nid_t fixed, ext;
3568 int i;
3570 for (i = AUTO_PIN_LINE; i < AUTO_PIN_LAST; i++) {
3571 if (cfg->input_pins[i])
3572 return 0; /* must be exclusively mics */
3574 fixed = ext = 0;
3575 for (i = AUTO_PIN_MIC; i <= AUTO_PIN_FRONT_MIC; i++)
3576 if (check_mic_pin(codec, cfg->input_pins[i], &fixed, &ext))
3577 return 0;
3578 for (i = 0; i < spec->num_dmics; i++)
3579 if (check_mic_pin(codec, spec->dmic_nids[i], &fixed, &ext))
3580 return 0;
3581 if (!fixed || !ext)
3582 return 0;
3583 if (!(get_wcaps(codec, ext) & AC_WCAP_UNSOL_CAP))
3584 return 0; /* no unsol support */
3585 if (set_mic_route(codec, &spec->ext_mic, ext) ||
3586 set_mic_route(codec, &spec->int_mic, fixed))
3587 return 0; /* something is wrong */
3588 return 1;
3591 /* create playback/capture controls for input pins */
3592 static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
3594 struct sigmatel_spec *spec = codec->spec;
3595 struct hda_input_mux *imux = &spec->private_imux;
3596 int i, j;
3598 for (i = 0; i < AUTO_PIN_LAST; i++) {
3599 hda_nid_t nid = cfg->input_pins[i];
3600 int index, err;
3602 if (!nid)
3603 continue;
3604 index = -1;
3605 for (j = 0; j < spec->num_muxes; j++) {
3606 index = get_connection_index(codec, spec->mux_nids[j],
3607 nid);
3608 if (index >= 0)
3609 break;
3611 if (index < 0)
3612 continue;
3614 err = create_elem_capture_vol(codec, nid,
3615 auto_pin_cfg_labels[i],
3616 HDA_INPUT);
3617 if (err < 0)
3618 return err;
3620 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
3621 imux->items[imux->num_items].index = index;
3622 imux->num_items++;
3624 spec->num_analog_muxes = imux->num_items;
3626 if (imux->num_items) {
3628 * Set the current input for the muxes.
3629 * The STAC9221 has two input muxes with identical source
3630 * NID lists. Hopefully this won't get confused.
3632 for (i = 0; i < spec->num_muxes; i++) {
3633 snd_hda_codec_write_cache(codec, spec->mux_nids[i], 0,
3634 AC_VERB_SET_CONNECT_SEL,
3635 imux->items[0].index);
3639 return 0;
3642 static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
3644 struct sigmatel_spec *spec = codec->spec;
3645 int i;
3647 for (i = 0; i < spec->autocfg.line_outs; i++) {
3648 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3649 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
3653 static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
3655 struct sigmatel_spec *spec = codec->spec;
3656 int i;
3658 for (i = 0; i < spec->autocfg.hp_outs; i++) {
3659 hda_nid_t pin;
3660 pin = spec->autocfg.hp_pins[i];
3661 if (pin) /* connect to front */
3662 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
3664 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
3665 hda_nid_t pin;
3666 pin = spec->autocfg.speaker_pins[i];
3667 if (pin) /* connect to front */
3668 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
3672 static int is_dual_headphones(struct hda_codec *codec)
3674 struct sigmatel_spec *spec = codec->spec;
3675 int i, valid_hps;
3677 if (spec->autocfg.line_out_type != AUTO_PIN_SPEAKER_OUT ||
3678 spec->autocfg.hp_outs <= 1)
3679 return 0;
3680 valid_hps = 0;
3681 for (i = 0; i < spec->autocfg.hp_outs; i++) {
3682 hda_nid_t nid = spec->autocfg.hp_pins[i];
3683 unsigned int cfg = snd_hda_codec_get_pincfg(codec, nid);
3684 if (get_defcfg_location(cfg) & AC_JACK_LOC_SEPARATE)
3685 continue;
3686 valid_hps++;
3688 return (valid_hps > 1);
3692 static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out, hda_nid_t dig_in)
3694 struct sigmatel_spec *spec = codec->spec;
3695 int hp_swap = 0;
3696 int i, err;
3698 if ((err = snd_hda_parse_pin_def_config(codec,
3699 &spec->autocfg,
3700 spec->dmic_nids)) < 0)
3701 return err;
3702 if (! spec->autocfg.line_outs)
3703 return 0; /* can't find valid pin config */
3705 /* If we have no real line-out pin and multiple hp-outs, HPs should
3706 * be set up as multi-channel outputs.
3708 if (is_dual_headphones(codec)) {
3709 /* Copy hp_outs to line_outs, backup line_outs in
3710 * speaker_outs so that the following routines can handle
3711 * HP pins as primary outputs.
3713 snd_printdd("stac92xx: Enabling multi-HPs workaround\n");
3714 memcpy(spec->autocfg.speaker_pins, spec->autocfg.line_out_pins,
3715 sizeof(spec->autocfg.line_out_pins));
3716 spec->autocfg.speaker_outs = spec->autocfg.line_outs;
3717 memcpy(spec->autocfg.line_out_pins, spec->autocfg.hp_pins,
3718 sizeof(spec->autocfg.hp_pins));
3719 spec->autocfg.line_outs = spec->autocfg.hp_outs;
3720 spec->autocfg.line_out_type = AUTO_PIN_HP_OUT;
3721 spec->autocfg.hp_outs = 0;
3722 hp_swap = 1;
3724 if (spec->autocfg.mono_out_pin) {
3725 int dir = get_wcaps(codec, spec->autocfg.mono_out_pin) &
3726 (AC_WCAP_OUT_AMP | AC_WCAP_IN_AMP);
3727 u32 caps = query_amp_caps(codec,
3728 spec->autocfg.mono_out_pin, dir);
3729 hda_nid_t conn_list[1];
3731 /* get the mixer node and then the mono mux if it exists */
3732 if (snd_hda_get_connections(codec,
3733 spec->autocfg.mono_out_pin, conn_list, 1) &&
3734 snd_hda_get_connections(codec, conn_list[0],
3735 conn_list, 1) > 0) {
3737 int wcaps = get_wcaps(codec, conn_list[0]);
3738 int wid_type = get_wcaps_type(wcaps);
3739 /* LR swap check, some stac925x have a mux that
3740 * changes the DACs output path instead of the
3741 * mono-mux path.
3743 if (wid_type == AC_WID_AUD_SEL &&
3744 !(wcaps & AC_WCAP_LR_SWAP))
3745 spec->mono_nid = conn_list[0];
3747 if (dir) {
3748 hda_nid_t nid = spec->autocfg.mono_out_pin;
3750 /* most mono outs have a least a mute/unmute switch */
3751 dir = (dir & AC_WCAP_OUT_AMP) ? HDA_OUTPUT : HDA_INPUT;
3752 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE,
3753 "Mono Playback Switch",
3754 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
3755 if (err < 0)
3756 return err;
3757 /* check for volume support for the amp */
3758 if ((caps & AC_AMPCAP_NUM_STEPS)
3759 >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3760 err = stac92xx_add_control(spec,
3761 STAC_CTL_WIDGET_VOL,
3762 "Mono Playback Volume",
3763 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
3764 if (err < 0)
3765 return err;
3769 stac92xx_auto_set_pinctl(codec, spec->autocfg.mono_out_pin,
3770 AC_PINCTL_OUT_EN);
3773 if (!spec->multiout.num_dacs) {
3774 err = stac92xx_auto_fill_dac_nids(codec);
3775 if (err < 0)
3776 return err;
3777 err = stac92xx_auto_create_multi_out_ctls(codec,
3778 &spec->autocfg);
3779 if (err < 0)
3780 return err;
3783 /* setup analog beep controls */
3784 if (spec->anabeep_nid > 0) {
3785 err = stac92xx_auto_create_beep_ctls(codec,
3786 spec->anabeep_nid);
3787 if (err < 0)
3788 return err;
3791 /* setup digital beep controls and input device */
3792 #ifdef CONFIG_SND_HDA_INPUT_BEEP
3793 if (spec->digbeep_nid > 0) {
3794 hda_nid_t nid = spec->digbeep_nid;
3795 unsigned int caps;
3797 err = stac92xx_auto_create_beep_ctls(codec, nid);
3798 if (err < 0)
3799 return err;
3800 err = snd_hda_attach_beep_device(codec, nid);
3801 if (err < 0)
3802 return err;
3803 if (codec->beep) {
3804 /* IDT/STAC codecs have linear beep tone parameter */
3805 codec->beep->linear_tone = 1;
3806 /* if no beep switch is available, make its own one */
3807 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3808 if (!(caps & AC_AMPCAP_MUTE)) {
3809 err = stac92xx_beep_switch_ctl(codec);
3810 if (err < 0)
3811 return err;
3815 #endif
3817 err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg);
3818 if (err < 0)
3819 return err;
3821 /* All output parsing done, now restore the swapped hp pins */
3822 if (hp_swap) {
3823 memcpy(spec->autocfg.hp_pins, spec->autocfg.line_out_pins,
3824 sizeof(spec->autocfg.hp_pins));
3825 spec->autocfg.hp_outs = spec->autocfg.line_outs;
3826 spec->autocfg.line_out_type = AUTO_PIN_HP_OUT;
3827 spec->autocfg.line_outs = 0;
3830 if (stac_check_auto_mic(codec)) {
3831 spec->auto_mic = 1;
3832 /* only one capture for auto-mic */
3833 spec->num_adcs = 1;
3834 spec->num_caps = 1;
3835 spec->num_muxes = 1;
3838 for (i = 0; i < spec->num_caps; i++) {
3839 err = stac92xx_add_capvol_ctls(codec, spec->capvols[i],
3840 spec->capsws[i], i);
3841 if (err < 0)
3842 return err;
3845 err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg);
3846 if (err < 0)
3847 return err;
3849 if (spec->mono_nid > 0) {
3850 err = stac92xx_auto_create_mono_output_ctls(codec);
3851 if (err < 0)
3852 return err;
3854 if (spec->num_dmics > 0 && !spec->dinput_mux)
3855 if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
3856 &spec->autocfg)) < 0)
3857 return err;
3858 if (spec->num_muxes > 0) {
3859 err = stac92xx_auto_create_mux_input_ctls(codec);
3860 if (err < 0)
3861 return err;
3863 if (spec->num_smuxes > 0) {
3864 err = stac92xx_auto_create_spdif_mux_ctls(codec);
3865 if (err < 0)
3866 return err;
3869 err = stac92xx_add_input_source(spec);
3870 if (err < 0)
3871 return err;
3873 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3874 if (spec->multiout.max_channels > 2)
3875 spec->surr_switch = 1;
3877 if (spec->autocfg.dig_outs)
3878 spec->multiout.dig_out_nid = dig_out;
3879 if (dig_in && spec->autocfg.dig_in_pin)
3880 spec->dig_in_nid = dig_in;
3882 if (spec->kctls.list)
3883 spec->mixers[spec->num_mixers++] = spec->kctls.list;
3885 spec->input_mux = &spec->private_imux;
3886 if (!spec->dinput_mux)
3887 spec->dinput_mux = &spec->private_dimux;
3888 spec->sinput_mux = &spec->private_smux;
3889 spec->mono_mux = &spec->private_mono_mux;
3890 return 1;
3893 /* add playback controls for HP output */
3894 static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
3895 struct auto_pin_cfg *cfg)
3897 struct sigmatel_spec *spec = codec->spec;
3898 hda_nid_t pin = cfg->hp_pins[0];
3899 unsigned int wid_caps;
3901 if (! pin)
3902 return 0;
3904 wid_caps = get_wcaps(codec, pin);
3905 if (wid_caps & AC_WCAP_UNSOL_CAP)
3906 spec->hp_detect = 1;
3908 return 0;
3911 /* add playback controls for LFE output */
3912 static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
3913 struct auto_pin_cfg *cfg)
3915 struct sigmatel_spec *spec = codec->spec;
3916 int err;
3917 hda_nid_t lfe_pin = 0x0;
3918 int i;
3921 * search speaker outs and line outs for a mono speaker pin
3922 * with an amp. If one is found, add LFE controls
3923 * for it.
3925 for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
3926 hda_nid_t pin = spec->autocfg.speaker_pins[i];
3927 unsigned int wcaps = get_wcaps(codec, pin);
3928 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
3929 if (wcaps == AC_WCAP_OUT_AMP)
3930 /* found a mono speaker with an amp, must be lfe */
3931 lfe_pin = pin;
3934 /* if speaker_outs is 0, then speakers may be in line_outs */
3935 if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
3936 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
3937 hda_nid_t pin = spec->autocfg.line_out_pins[i];
3938 unsigned int defcfg;
3939 defcfg = snd_hda_codec_get_pincfg(codec, pin);
3940 if (get_defcfg_device(defcfg) == AC_JACK_SPEAKER) {
3941 unsigned int wcaps = get_wcaps(codec, pin);
3942 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
3943 if (wcaps == AC_WCAP_OUT_AMP)
3944 /* found a mono speaker with an amp,
3945 must be lfe */
3946 lfe_pin = pin;
3951 if (lfe_pin) {
3952 err = create_controls(codec, "LFE", lfe_pin, 1);
3953 if (err < 0)
3954 return err;
3957 return 0;
3960 static int stac9200_parse_auto_config(struct hda_codec *codec)
3962 struct sigmatel_spec *spec = codec->spec;
3963 int err;
3965 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
3966 return err;
3968 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
3969 return err;
3971 if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
3972 return err;
3974 if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
3975 return err;
3977 if (spec->num_muxes > 0) {
3978 err = stac92xx_auto_create_mux_input_ctls(codec);
3979 if (err < 0)
3980 return err;
3983 err = stac92xx_add_input_source(spec);
3984 if (err < 0)
3985 return err;
3987 if (spec->autocfg.dig_outs)
3988 spec->multiout.dig_out_nid = 0x05;
3989 if (spec->autocfg.dig_in_pin)
3990 spec->dig_in_nid = 0x04;
3992 if (spec->kctls.list)
3993 spec->mixers[spec->num_mixers++] = spec->kctls.list;
3995 spec->input_mux = &spec->private_imux;
3996 spec->dinput_mux = &spec->private_dimux;
3998 return 1;
4002 * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
4003 * funky external mute control using GPIO pins.
4006 static void stac_gpio_set(struct hda_codec *codec, unsigned int mask,
4007 unsigned int dir_mask, unsigned int data)
4009 unsigned int gpiostate, gpiomask, gpiodir;
4011 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
4012 AC_VERB_GET_GPIO_DATA, 0);
4013 gpiostate = (gpiostate & ~dir_mask) | (data & dir_mask);
4015 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
4016 AC_VERB_GET_GPIO_MASK, 0);
4017 gpiomask |= mask;
4019 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
4020 AC_VERB_GET_GPIO_DIRECTION, 0);
4021 gpiodir |= dir_mask;
4023 /* Configure GPIOx as CMOS */
4024 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
4026 snd_hda_codec_write(codec, codec->afg, 0,
4027 AC_VERB_SET_GPIO_MASK, gpiomask);
4028 snd_hda_codec_read(codec, codec->afg, 0,
4029 AC_VERB_SET_GPIO_DIRECTION, gpiodir); /* sync */
4031 msleep(1);
4033 snd_hda_codec_read(codec, codec->afg, 0,
4034 AC_VERB_SET_GPIO_DATA, gpiostate); /* sync */
4037 #ifdef CONFIG_SND_HDA_INPUT_JACK
4038 static void stac92xx_free_jack_priv(struct snd_jack *jack)
4040 struct sigmatel_jack *jacks = jack->private_data;
4041 jacks->nid = 0;
4042 jacks->jack = NULL;
4044 #endif
4046 static int stac92xx_add_jack(struct hda_codec *codec,
4047 hda_nid_t nid, int type)
4049 #ifdef CONFIG_SND_HDA_INPUT_JACK
4050 struct sigmatel_spec *spec = codec->spec;
4051 struct sigmatel_jack *jack;
4052 int def_conf = snd_hda_codec_get_pincfg(codec, nid);
4053 int connectivity = get_defcfg_connect(def_conf);
4054 char name[32];
4055 int err;
4057 if (connectivity && connectivity != AC_JACK_PORT_FIXED)
4058 return 0;
4060 snd_array_init(&spec->jacks, sizeof(*jack), 32);
4061 jack = snd_array_new(&spec->jacks);
4062 if (!jack)
4063 return -ENOMEM;
4064 jack->nid = nid;
4065 jack->type = type;
4067 snprintf(name, sizeof(name), "%s at %s %s Jack",
4068 snd_hda_get_jack_type(def_conf),
4069 snd_hda_get_jack_connectivity(def_conf),
4070 snd_hda_get_jack_location(def_conf));
4072 err = snd_jack_new(codec->bus->card, name, type, &jack->jack);
4073 if (err < 0) {
4074 jack->nid = 0;
4075 return err;
4077 jack->jack->private_data = jack;
4078 jack->jack->private_free = stac92xx_free_jack_priv;
4079 #endif
4080 return 0;
4083 static int stac_add_event(struct sigmatel_spec *spec, hda_nid_t nid,
4084 unsigned char type, int data)
4086 struct sigmatel_event *event;
4088 snd_array_init(&spec->events, sizeof(*event), 32);
4089 event = snd_array_new(&spec->events);
4090 if (!event)
4091 return -ENOMEM;
4092 event->nid = nid;
4093 event->type = type;
4094 event->tag = spec->events.used;
4095 event->data = data;
4097 return event->tag;
4100 static struct sigmatel_event *stac_get_event(struct hda_codec *codec,
4101 hda_nid_t nid)
4103 struct sigmatel_spec *spec = codec->spec;
4104 struct sigmatel_event *event = spec->events.list;
4105 int i;
4107 for (i = 0; i < spec->events.used; i++, event++) {
4108 if (event->nid == nid)
4109 return event;
4111 return NULL;
4114 static struct sigmatel_event *stac_get_event_from_tag(struct hda_codec *codec,
4115 unsigned char tag)
4117 struct sigmatel_spec *spec = codec->spec;
4118 struct sigmatel_event *event = spec->events.list;
4119 int i;
4121 for (i = 0; i < spec->events.used; i++, event++) {
4122 if (event->tag == tag)
4123 return event;
4125 return NULL;
4128 /* check if given nid is a valid pin and no other events are assigned
4129 * to it. If OK, assign the event, set the unsol flag, and returns 1.
4130 * Otherwise, returns zero.
4132 static int enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
4133 unsigned int type)
4135 struct sigmatel_event *event;
4136 int tag;
4138 if (!(get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP))
4139 return 0;
4140 event = stac_get_event(codec, nid);
4141 if (event) {
4142 if (event->type != type)
4143 return 0;
4144 tag = event->tag;
4145 } else {
4146 tag = stac_add_event(codec->spec, nid, type, 0);
4147 if (tag < 0)
4148 return 0;
4150 snd_hda_codec_write_cache(codec, nid, 0,
4151 AC_VERB_SET_UNSOLICITED_ENABLE,
4152 AC_USRSP_EN | tag);
4153 return 1;
4156 static int is_nid_hp_pin(struct auto_pin_cfg *cfg, hda_nid_t nid)
4158 int i;
4159 for (i = 0; i < cfg->hp_outs; i++)
4160 if (cfg->hp_pins[i] == nid)
4161 return 1; /* nid is a HP-Out */
4163 return 0; /* nid is not a HP-Out */
4166 static void stac92xx_power_down(struct hda_codec *codec)
4168 struct sigmatel_spec *spec = codec->spec;
4170 /* power down inactive DACs */
4171 hda_nid_t *dac;
4172 for (dac = spec->dac_list; *dac; dac++)
4173 if (!check_all_dac_nids(spec, *dac))
4174 snd_hda_codec_write(codec, *dac, 0,
4175 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
4178 static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
4179 int enable);
4181 static inline int get_int_hint(struct hda_codec *codec, const char *key,
4182 int *valp)
4184 const char *p;
4185 p = snd_hda_get_hint(codec, key);
4186 if (p) {
4187 unsigned long val;
4188 if (!strict_strtoul(p, 0, &val)) {
4189 *valp = val;
4190 return 1;
4193 return 0;
4196 /* override some hints from the hwdep entry */
4197 static void stac_store_hints(struct hda_codec *codec)
4199 struct sigmatel_spec *spec = codec->spec;
4200 int val;
4202 val = snd_hda_get_bool_hint(codec, "hp_detect");
4203 if (val >= 0)
4204 spec->hp_detect = val;
4205 if (get_int_hint(codec, "gpio_mask", &spec->gpio_mask)) {
4206 spec->eapd_mask = spec->gpio_dir = spec->gpio_data =
4207 spec->gpio_mask;
4209 if (get_int_hint(codec, "gpio_dir", &spec->gpio_dir))
4210 spec->gpio_mask &= spec->gpio_mask;
4211 if (get_int_hint(codec, "gpio_data", &spec->gpio_data))
4212 spec->gpio_dir &= spec->gpio_mask;
4213 if (get_int_hint(codec, "eapd_mask", &spec->eapd_mask))
4214 spec->eapd_mask &= spec->gpio_mask;
4215 if (get_int_hint(codec, "gpio_mute", &spec->gpio_mute))
4216 spec->gpio_mute &= spec->gpio_mask;
4217 val = snd_hda_get_bool_hint(codec, "eapd_switch");
4218 if (val >= 0)
4219 spec->eapd_switch = val;
4220 get_int_hint(codec, "gpio_led_polarity", &spec->gpio_led_polarity);
4221 if (get_int_hint(codec, "gpio_led", &spec->gpio_led)) {
4222 spec->gpio_mask |= spec->gpio_led;
4223 spec->gpio_dir |= spec->gpio_led;
4224 if (spec->gpio_led_polarity)
4225 spec->gpio_data |= spec->gpio_led;
4229 static int stac92xx_init(struct hda_codec *codec)
4231 struct sigmatel_spec *spec = codec->spec;
4232 struct auto_pin_cfg *cfg = &spec->autocfg;
4233 unsigned int gpio;
4234 int i;
4236 snd_hda_sequence_write(codec, spec->init);
4238 /* power down adcs initially */
4239 if (spec->powerdown_adcs)
4240 for (i = 0; i < spec->num_adcs; i++)
4241 snd_hda_codec_write(codec,
4242 spec->adc_nids[i], 0,
4243 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
4245 /* override some hints */
4246 stac_store_hints(codec);
4248 /* set up GPIO */
4249 gpio = spec->gpio_data;
4250 /* turn on EAPD statically when spec->eapd_switch isn't set.
4251 * otherwise, unsol event will turn it on/off dynamically
4253 if (!spec->eapd_switch)
4254 gpio |= spec->eapd_mask;
4255 stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, gpio);
4257 /* set up pins */
4258 if (spec->hp_detect) {
4259 /* Enable unsolicited responses on the HP widget */
4260 for (i = 0; i < cfg->hp_outs; i++) {
4261 hda_nid_t nid = cfg->hp_pins[i];
4262 enable_pin_detect(codec, nid, STAC_HP_EVENT);
4264 if (cfg->line_out_type == AUTO_PIN_LINE_OUT &&
4265 cfg->speaker_outs > 0) {
4266 /* enable pin-detect for line-outs as well */
4267 for (i = 0; i < cfg->line_outs; i++) {
4268 hda_nid_t nid = cfg->line_out_pins[i];
4269 enable_pin_detect(codec, nid, STAC_LO_EVENT);
4273 /* force to enable the first line-out; the others are set up
4274 * in unsol_event
4276 stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
4277 AC_PINCTL_OUT_EN);
4278 /* fake event to set up pins */
4279 if (cfg->hp_pins[0])
4280 stac_issue_unsol_event(codec, cfg->hp_pins[0]);
4281 else if (cfg->line_out_pins[0])
4282 stac_issue_unsol_event(codec, cfg->line_out_pins[0]);
4283 } else {
4284 stac92xx_auto_init_multi_out(codec);
4285 stac92xx_auto_init_hp_out(codec);
4286 for (i = 0; i < cfg->hp_outs; i++)
4287 stac_toggle_power_map(codec, cfg->hp_pins[i], 1);
4289 if (spec->auto_mic) {
4290 /* initialize connection to analog input */
4291 if (spec->dmux_nids)
4292 snd_hda_codec_write_cache(codec, spec->dmux_nids[0], 0,
4293 AC_VERB_SET_CONNECT_SEL, 0);
4294 if (enable_pin_detect(codec, spec->ext_mic.pin, STAC_MIC_EVENT))
4295 stac_issue_unsol_event(codec, spec->ext_mic.pin);
4297 for (i = 0; i < AUTO_PIN_LAST; i++) {
4298 hda_nid_t nid = cfg->input_pins[i];
4299 if (nid) {
4300 unsigned int pinctl, conf;
4301 if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC) {
4302 /* for mic pins, force to initialize */
4303 pinctl = stac92xx_get_default_vref(codec, nid);
4304 pinctl |= AC_PINCTL_IN_EN;
4305 stac92xx_auto_set_pinctl(codec, nid, pinctl);
4306 } else {
4307 pinctl = snd_hda_codec_read(codec, nid, 0,
4308 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4309 /* if PINCTL already set then skip */
4310 /* Also, if both INPUT and OUTPUT are set,
4311 * it must be a BIOS bug; need to override, too
4313 if (!(pinctl & AC_PINCTL_IN_EN) ||
4314 (pinctl & AC_PINCTL_OUT_EN)) {
4315 pinctl &= ~AC_PINCTL_OUT_EN;
4316 pinctl |= AC_PINCTL_IN_EN;
4317 stac92xx_auto_set_pinctl(codec, nid,
4318 pinctl);
4321 conf = snd_hda_codec_get_pincfg(codec, nid);
4322 if (get_defcfg_connect(conf) != AC_JACK_PORT_FIXED) {
4323 if (enable_pin_detect(codec, nid,
4324 STAC_INSERT_EVENT))
4325 stac_issue_unsol_event(codec, nid);
4329 for (i = 0; i < spec->num_dmics; i++)
4330 stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
4331 AC_PINCTL_IN_EN);
4332 if (cfg->dig_out_pins[0])
4333 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pins[0],
4334 AC_PINCTL_OUT_EN);
4335 if (cfg->dig_in_pin)
4336 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
4337 AC_PINCTL_IN_EN);
4338 for (i = 0; i < spec->num_pwrs; i++) {
4339 hda_nid_t nid = spec->pwr_nids[i];
4340 int pinctl, def_conf;
4342 /* power on when no jack detection is available */
4343 if (!spec->hp_detect) {
4344 stac_toggle_power_map(codec, nid, 1);
4345 continue;
4348 if (is_nid_hp_pin(cfg, nid))
4349 continue; /* already has an unsol event */
4351 pinctl = snd_hda_codec_read(codec, nid, 0,
4352 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4353 /* outputs are only ports capable of power management
4354 * any attempts on powering down a input port cause the
4355 * referenced VREF to act quirky.
4357 if (pinctl & AC_PINCTL_IN_EN) {
4358 stac_toggle_power_map(codec, nid, 1);
4359 continue;
4361 def_conf = snd_hda_codec_get_pincfg(codec, nid);
4362 def_conf = get_defcfg_connect(def_conf);
4363 /* skip any ports that don't have jacks since presence
4364 * detection is useless */
4365 if (def_conf != AC_JACK_PORT_COMPLEX) {
4366 if (def_conf != AC_JACK_PORT_NONE)
4367 stac_toggle_power_map(codec, nid, 1);
4368 continue;
4370 if (enable_pin_detect(codec, nid, STAC_PWR_EVENT))
4371 stac_issue_unsol_event(codec, nid);
4374 #ifdef CONFIG_SND_HDA_POWER_SAVE
4375 /* sync mute LED */
4376 if (spec->gpio_led && codec->patch_ops.check_power_status)
4377 codec->patch_ops.check_power_status(codec, 0x01);
4378 #endif
4379 if (spec->dac_list)
4380 stac92xx_power_down(codec);
4381 return 0;
4384 static void stac92xx_free_jacks(struct hda_codec *codec)
4386 #ifdef CONFIG_SND_HDA_INPUT_JACK
4387 /* free jack instances manually when clearing/reconfiguring */
4388 struct sigmatel_spec *spec = codec->spec;
4389 if (!codec->bus->shutdown && spec->jacks.list) {
4390 struct sigmatel_jack *jacks = spec->jacks.list;
4391 int i;
4392 for (i = 0; i < spec->jacks.used; i++, jacks++) {
4393 if (jacks->jack)
4394 snd_device_free(codec->bus->card, jacks->jack);
4397 snd_array_free(&spec->jacks);
4398 #endif
4401 static void stac92xx_free_kctls(struct hda_codec *codec)
4403 struct sigmatel_spec *spec = codec->spec;
4405 if (spec->kctls.list) {
4406 struct snd_kcontrol_new *kctl = spec->kctls.list;
4407 int i;
4408 for (i = 0; i < spec->kctls.used; i++)
4409 kfree(kctl[i].name);
4411 snd_array_free(&spec->kctls);
4414 static void stac92xx_shutup(struct hda_codec *codec)
4416 struct sigmatel_spec *spec = codec->spec;
4418 snd_hda_shutup_pins(codec);
4420 if (spec->eapd_mask)
4421 stac_gpio_set(codec, spec->gpio_mask,
4422 spec->gpio_dir, spec->gpio_data &
4423 ~spec->eapd_mask);
4426 static void stac92xx_free(struct hda_codec *codec)
4428 struct sigmatel_spec *spec = codec->spec;
4430 if (! spec)
4431 return;
4433 stac92xx_shutup(codec);
4434 stac92xx_free_jacks(codec);
4435 snd_array_free(&spec->events);
4437 kfree(spec);
4438 snd_hda_detach_beep_device(codec);
4441 static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
4442 unsigned int flag)
4444 unsigned int old_ctl, pin_ctl;
4446 pin_ctl = snd_hda_codec_read(codec, nid,
4447 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
4449 if (pin_ctl & AC_PINCTL_IN_EN) {
4451 * we need to check the current set-up direction of
4452 * shared input pins since they can be switched via
4453 * "xxx as Output" mixer switch
4455 struct sigmatel_spec *spec = codec->spec;
4456 if (nid == spec->line_switch || nid == spec->mic_switch)
4457 return;
4460 old_ctl = pin_ctl;
4461 /* if setting pin direction bits, clear the current
4462 direction bits first */
4463 if (flag & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))
4464 pin_ctl &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
4466 pin_ctl |= flag;
4467 if (old_ctl != pin_ctl)
4468 snd_hda_codec_write_cache(codec, nid, 0,
4469 AC_VERB_SET_PIN_WIDGET_CONTROL,
4470 pin_ctl);
4473 static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
4474 unsigned int flag)
4476 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
4477 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
4478 if (pin_ctl & flag)
4479 snd_hda_codec_write_cache(codec, nid, 0,
4480 AC_VERB_SET_PIN_WIDGET_CONTROL,
4481 pin_ctl & ~flag);
4484 static inline int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
4486 if (!nid)
4487 return 0;
4488 return snd_hda_jack_detect(codec, nid);
4491 static void stac92xx_line_out_detect(struct hda_codec *codec,
4492 int presence)
4494 struct sigmatel_spec *spec = codec->spec;
4495 struct auto_pin_cfg *cfg = &spec->autocfg;
4496 int i;
4498 for (i = 0; i < cfg->line_outs; i++) {
4499 if (presence)
4500 break;
4501 presence = get_pin_presence(codec, cfg->line_out_pins[i]);
4502 if (presence) {
4503 unsigned int pinctl;
4504 pinctl = snd_hda_codec_read(codec,
4505 cfg->line_out_pins[i], 0,
4506 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4507 if (pinctl & AC_PINCTL_IN_EN)
4508 presence = 0; /* mic- or line-input */
4512 if (presence) {
4513 /* disable speakers */
4514 for (i = 0; i < cfg->speaker_outs; i++)
4515 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
4516 AC_PINCTL_OUT_EN);
4517 if (spec->eapd_mask && spec->eapd_switch)
4518 stac_gpio_set(codec, spec->gpio_mask,
4519 spec->gpio_dir, spec->gpio_data &
4520 ~spec->eapd_mask);
4521 } else {
4522 /* enable speakers */
4523 for (i = 0; i < cfg->speaker_outs; i++)
4524 stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
4525 AC_PINCTL_OUT_EN);
4526 if (spec->eapd_mask && spec->eapd_switch)
4527 stac_gpio_set(codec, spec->gpio_mask,
4528 spec->gpio_dir, spec->gpio_data |
4529 spec->eapd_mask);
4533 /* return non-zero if the hp-pin of the given array index isn't
4534 * a jack-detection target
4536 static int no_hp_sensing(struct sigmatel_spec *spec, int i)
4538 struct auto_pin_cfg *cfg = &spec->autocfg;
4540 /* ignore sensing of shared line and mic jacks */
4541 if (cfg->hp_pins[i] == spec->line_switch)
4542 return 1;
4543 if (cfg->hp_pins[i] == spec->mic_switch)
4544 return 1;
4545 /* ignore if the pin is set as line-out */
4546 if (cfg->hp_pins[i] == spec->hp_switch)
4547 return 1;
4548 return 0;
4551 static void stac92xx_hp_detect(struct hda_codec *codec)
4553 struct sigmatel_spec *spec = codec->spec;
4554 struct auto_pin_cfg *cfg = &spec->autocfg;
4555 int i, presence;
4557 presence = 0;
4558 if (spec->gpio_mute)
4559 presence = !(snd_hda_codec_read(codec, codec->afg, 0,
4560 AC_VERB_GET_GPIO_DATA, 0) & spec->gpio_mute);
4562 for (i = 0; i < cfg->hp_outs; i++) {
4563 if (presence)
4564 break;
4565 if (no_hp_sensing(spec, i))
4566 continue;
4567 presence = get_pin_presence(codec, cfg->hp_pins[i]);
4568 if (presence) {
4569 unsigned int pinctl;
4570 pinctl = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
4571 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4572 if (pinctl & AC_PINCTL_IN_EN)
4573 presence = 0; /* mic- or line-input */
4577 if (presence) {
4578 /* disable lineouts */
4579 if (spec->hp_switch)
4580 stac92xx_reset_pinctl(codec, spec->hp_switch,
4581 AC_PINCTL_OUT_EN);
4582 for (i = 0; i < cfg->line_outs; i++)
4583 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
4584 AC_PINCTL_OUT_EN);
4585 } else {
4586 /* enable lineouts */
4587 if (spec->hp_switch)
4588 stac92xx_set_pinctl(codec, spec->hp_switch,
4589 AC_PINCTL_OUT_EN);
4590 for (i = 0; i < cfg->line_outs; i++)
4591 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
4592 AC_PINCTL_OUT_EN);
4594 stac92xx_line_out_detect(codec, presence);
4595 /* toggle hp outs */
4596 for (i = 0; i < cfg->hp_outs; i++) {
4597 unsigned int val = AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN;
4598 if (no_hp_sensing(spec, i))
4599 continue;
4600 if (presence)
4601 stac92xx_set_pinctl(codec, cfg->hp_pins[i], val);
4602 #if 0 /* FIXME */
4603 /* Resetting the pinctl like below may lead to (a sort of) regressions
4604 * on some devices since they use the HP pin actually for line/speaker
4605 * outs although the default pin config shows a different pin (that is
4606 * wrong and useless).
4608 * So, it's basically a problem of default pin configs, likely a BIOS issue.
4609 * But, disabling the code below just works around it, and I'm too tired of
4610 * bug reports with such devices...
4612 else
4613 stac92xx_reset_pinctl(codec, cfg->hp_pins[i], val);
4614 #endif /* FIXME */
4618 static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
4619 int enable)
4621 struct sigmatel_spec *spec = codec->spec;
4622 unsigned int idx, val;
4624 for (idx = 0; idx < spec->num_pwrs; idx++) {
4625 if (spec->pwr_nids[idx] == nid)
4626 break;
4628 if (idx >= spec->num_pwrs)
4629 return;
4631 /* several codecs have two power down bits */
4632 if (spec->pwr_mapping)
4633 idx = spec->pwr_mapping[idx];
4634 else
4635 idx = 1 << idx;
4637 val = snd_hda_codec_read(codec, codec->afg, 0, 0x0fec, 0x0) & 0xff;
4638 if (enable)
4639 val &= ~idx;
4640 else
4641 val |= idx;
4643 /* power down unused output ports */
4644 snd_hda_codec_write(codec, codec->afg, 0, 0x7ec, val);
4647 static void stac92xx_pin_sense(struct hda_codec *codec, hda_nid_t nid)
4649 stac_toggle_power_map(codec, nid, get_pin_presence(codec, nid));
4652 static void stac92xx_report_jack(struct hda_codec *codec, hda_nid_t nid)
4654 struct sigmatel_spec *spec = codec->spec;
4655 struct sigmatel_jack *jacks = spec->jacks.list;
4657 if (jacks) {
4658 int i;
4659 for (i = 0; i < spec->jacks.used; i++) {
4660 if (jacks->nid == nid) {
4661 unsigned int pin_ctl =
4662 snd_hda_codec_read(codec, nid,
4663 0, AC_VERB_GET_PIN_WIDGET_CONTROL,
4664 0x00);
4665 int type = jacks->type;
4666 if (type == (SND_JACK_LINEOUT
4667 | SND_JACK_HEADPHONE))
4668 type = (pin_ctl & AC_PINCTL_HP_EN)
4669 ? SND_JACK_HEADPHONE : SND_JACK_LINEOUT;
4670 snd_jack_report(jacks->jack,
4671 get_pin_presence(codec, nid)
4672 ? type : 0);
4674 jacks++;
4679 static void stac92xx_mic_detect(struct hda_codec *codec)
4681 struct sigmatel_spec *spec = codec->spec;
4682 struct sigmatel_mic_route *mic;
4684 if (get_pin_presence(codec, spec->ext_mic.pin))
4685 mic = &spec->ext_mic;
4686 else
4687 mic = &spec->int_mic;
4688 if (mic->dmux_idx >= 0)
4689 snd_hda_codec_write_cache(codec, spec->dmux_nids[0], 0,
4690 AC_VERB_SET_CONNECT_SEL,
4691 mic->dmux_idx);
4692 if (mic->mux_idx >= 0)
4693 snd_hda_codec_write_cache(codec, spec->mux_nids[0], 0,
4694 AC_VERB_SET_CONNECT_SEL,
4695 mic->mux_idx);
4698 static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid)
4700 struct sigmatel_event *event = stac_get_event(codec, nid);
4701 if (!event)
4702 return;
4703 codec->patch_ops.unsol_event(codec, (unsigned)event->tag << 26);
4706 static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
4708 struct sigmatel_spec *spec = codec->spec;
4709 struct sigmatel_event *event;
4710 int tag, data;
4712 tag = (res >> 26) & 0x7f;
4713 event = stac_get_event_from_tag(codec, tag);
4714 if (!event)
4715 return;
4717 switch (event->type) {
4718 case STAC_HP_EVENT:
4719 case STAC_LO_EVENT:
4720 stac92xx_hp_detect(codec);
4721 break;
4722 case STAC_MIC_EVENT:
4723 stac92xx_mic_detect(codec);
4724 break;
4727 switch (event->type) {
4728 case STAC_HP_EVENT:
4729 case STAC_LO_EVENT:
4730 case STAC_MIC_EVENT:
4731 case STAC_INSERT_EVENT:
4732 case STAC_PWR_EVENT:
4733 if (spec->num_pwrs > 0)
4734 stac92xx_pin_sense(codec, event->nid);
4735 stac92xx_report_jack(codec, event->nid);
4737 switch (codec->subsystem_id) {
4738 case 0x103c308f:
4739 if (event->nid == 0xb) {
4740 int pin = AC_PINCTL_IN_EN;
4742 if (get_pin_presence(codec, 0xa)
4743 && get_pin_presence(codec, 0xb))
4744 pin |= AC_PINCTL_VREF_80;
4745 if (!get_pin_presence(codec, 0xb))
4746 pin |= AC_PINCTL_VREF_80;
4748 /* toggle VREF state based on mic + hp pin
4749 * status
4751 stac92xx_auto_set_pinctl(codec, 0x0a, pin);
4754 break;
4755 case STAC_VREF_EVENT:
4756 data = snd_hda_codec_read(codec, codec->afg, 0,
4757 AC_VERB_GET_GPIO_DATA, 0);
4758 /* toggle VREF state based on GPIOx status */
4759 snd_hda_codec_write(codec, codec->afg, 0, 0x7e0,
4760 !!(data & (1 << event->data)));
4761 break;
4765 static int hp_blike_system(u32 subsystem_id);
4767 static void set_hp_led_gpio(struct hda_codec *codec)
4769 struct sigmatel_spec *spec = codec->spec;
4770 unsigned int gpio;
4772 if (spec->gpio_led)
4773 return;
4775 gpio = snd_hda_param_read(codec, codec->afg, AC_PAR_GPIO_CAP);
4776 gpio &= AC_GPIO_IO_COUNT;
4777 if (gpio > 3)
4778 spec->gpio_led = 0x08; /* GPIO 3 */
4779 else
4780 spec->gpio_led = 0x01; /* GPIO 0 */
4784 * This method searches for the mute LED GPIO configuration
4785 * provided as OEM string in SMBIOS. The format of that string
4786 * is HP_Mute_LED_P_G or HP_Mute_LED_P
4787 * where P can be 0 or 1 and defines mute LED GPIO control state (low/high)
4788 * that corresponds to the NOT muted state of the master volume
4789 * and G is the index of the GPIO to use as the mute LED control (0..9)
4790 * If _G portion is missing it is assigned based on the codec ID
4792 * So, HP B-series like systems may have HP_Mute_LED_0 (current models)
4793 * or HP_Mute_LED_0_3 (future models) OEM SMBIOS strings
4796 * The dv-series laptops don't seem to have the HP_Mute_LED* strings in
4797 * SMBIOS - at least the ones I have seen do not have them - which include
4798 * my own system (HP Pavilion dv6-1110ax) and my cousin's
4799 * HP Pavilion dv9500t CTO.
4800 * Need more information on whether it is true across the entire series.
4801 * -- kunal
4803 static int find_mute_led_gpio(struct hda_codec *codec, int default_polarity)
4805 struct sigmatel_spec *spec = codec->spec;
4806 const struct dmi_device *dev = NULL;
4808 if ((codec->subsystem_id >> 16) == PCI_VENDOR_ID_HP) {
4809 while ((dev = dmi_find_device(DMI_DEV_TYPE_OEM_STRING,
4810 NULL, dev))) {
4811 if (sscanf(dev->name, "HP_Mute_LED_%d_%d",
4812 &spec->gpio_led_polarity,
4813 &spec->gpio_led) == 2) {
4814 spec->gpio_led = 1 << spec->gpio_led;
4815 return 1;
4817 if (sscanf(dev->name, "HP_Mute_LED_%d",
4818 &spec->gpio_led_polarity) == 1) {
4819 set_hp_led_gpio(codec);
4820 return 1;
4825 * Fallback case - if we don't find the DMI strings,
4826 * we statically set the GPIO - if not a B-series system.
4828 if (!hp_blike_system(codec->subsystem_id)) {
4829 set_hp_led_gpio(codec);
4830 spec->gpio_led_polarity = default_polarity;
4831 return 1;
4834 return 0;
4837 static int hp_blike_system(u32 subsystem_id)
4839 switch (subsystem_id) {
4840 case 0x103c1520:
4841 case 0x103c1521:
4842 case 0x103c1523:
4843 case 0x103c1524:
4844 case 0x103c1525:
4845 case 0x103c1722:
4846 case 0x103c1723:
4847 case 0x103c1724:
4848 case 0x103c1725:
4849 case 0x103c1726:
4850 case 0x103c1727:
4851 case 0x103c1728:
4852 case 0x103c1729:
4853 case 0x103c172a:
4854 case 0x103c172b:
4855 case 0x103c307e:
4856 case 0x103c307f:
4857 case 0x103c3080:
4858 case 0x103c3081:
4859 case 0x103c7007:
4860 case 0x103c7008:
4861 return 1;
4863 return 0;
4866 #ifdef CONFIG_PROC_FS
4867 static void stac92hd_proc_hook(struct snd_info_buffer *buffer,
4868 struct hda_codec *codec, hda_nid_t nid)
4870 if (nid == codec->afg)
4871 snd_iprintf(buffer, "Power-Map: 0x%02x\n",
4872 snd_hda_codec_read(codec, nid, 0, 0x0fec, 0x0));
4875 static void analog_loop_proc_hook(struct snd_info_buffer *buffer,
4876 struct hda_codec *codec,
4877 unsigned int verb)
4879 snd_iprintf(buffer, "Analog Loopback: 0x%02x\n",
4880 snd_hda_codec_read(codec, codec->afg, 0, verb, 0));
4883 /* stac92hd71bxx, stac92hd73xx */
4884 static void stac92hd7x_proc_hook(struct snd_info_buffer *buffer,
4885 struct hda_codec *codec, hda_nid_t nid)
4887 stac92hd_proc_hook(buffer, codec, nid);
4888 if (nid == codec->afg)
4889 analog_loop_proc_hook(buffer, codec, 0xfa0);
4892 static void stac9205_proc_hook(struct snd_info_buffer *buffer,
4893 struct hda_codec *codec, hda_nid_t nid)
4895 if (nid == codec->afg)
4896 analog_loop_proc_hook(buffer, codec, 0xfe0);
4899 static void stac927x_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, 0xfeb);
4905 #else
4906 #define stac92hd_proc_hook NULL
4907 #define stac92hd7x_proc_hook NULL
4908 #define stac9205_proc_hook NULL
4909 #define stac927x_proc_hook NULL
4910 #endif
4912 #ifdef SND_HDA_NEEDS_RESUME
4913 static int stac92xx_resume(struct hda_codec *codec)
4915 struct sigmatel_spec *spec = codec->spec;
4917 stac92xx_init(codec);
4918 snd_hda_codec_resume_amp(codec);
4919 snd_hda_codec_resume_cache(codec);
4920 /* fake event to set up pins again to override cached values */
4921 if (spec->hp_detect) {
4922 if (spec->autocfg.hp_pins[0])
4923 stac_issue_unsol_event(codec, spec->autocfg.hp_pins[0]);
4924 else if (spec->autocfg.line_out_pins[0])
4925 stac_issue_unsol_event(codec,
4926 spec->autocfg.line_out_pins[0]);
4928 #ifdef CONFIG_SND_HDA_POWER_SAVE
4929 /* sync mute LED */
4930 if (spec->gpio_led && codec->patch_ops.check_power_status)
4931 codec->patch_ops.check_power_status(codec, 0x01);
4932 #endif
4933 return 0;
4937 * using power check for controlling mute led of HP notebooks
4938 * check for mute state only on Speakers (nid = 0x10)
4940 * For this feature CONFIG_SND_HDA_POWER_SAVE is needed, otherwise
4941 * the LED is NOT working properly !
4943 * Changed name to reflect that it now works for any designated
4944 * model, not just HP HDX.
4947 #ifdef CONFIG_SND_HDA_POWER_SAVE
4948 static int stac92xx_hp_check_power_status(struct hda_codec *codec,
4949 hda_nid_t nid)
4951 struct sigmatel_spec *spec = codec->spec;
4952 int i, muted = 1;
4954 for (i = 0; i < spec->multiout.num_dacs; i++) {
4955 nid = spec->multiout.dac_nids[i];
4956 if (!(snd_hda_codec_amp_read(codec, nid, 0, HDA_OUTPUT, 0) &
4957 HDA_AMP_MUTE)) {
4958 muted = 0; /* something heard */
4959 break;
4962 if (muted)
4963 spec->gpio_data &= ~spec->gpio_led; /* orange */
4964 else
4965 spec->gpio_data |= spec->gpio_led; /* white */
4967 if (!spec->gpio_led_polarity) {
4968 /* LED state is inverted on these systems */
4969 spec->gpio_data ^= spec->gpio_led;
4972 stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, spec->gpio_data);
4973 return 0;
4975 #endif
4977 static int stac92xx_suspend(struct hda_codec *codec, pm_message_t state)
4979 stac92xx_shutup(codec);
4980 return 0;
4982 #endif
4984 static struct hda_codec_ops stac92xx_patch_ops = {
4985 .build_controls = stac92xx_build_controls,
4986 .build_pcms = stac92xx_build_pcms,
4987 .init = stac92xx_init,
4988 .free = stac92xx_free,
4989 .unsol_event = stac92xx_unsol_event,
4990 #ifdef SND_HDA_NEEDS_RESUME
4991 .suspend = stac92xx_suspend,
4992 .resume = stac92xx_resume,
4993 #endif
4994 .reboot_notify = stac92xx_shutup,
4997 static int patch_stac9200(struct hda_codec *codec)
4999 struct sigmatel_spec *spec;
5000 int err;
5002 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5003 if (spec == NULL)
5004 return -ENOMEM;
5006 codec->no_trigger_sense = 1;
5007 codec->spec = spec;
5008 spec->num_pins = ARRAY_SIZE(stac9200_pin_nids);
5009 spec->pin_nids = stac9200_pin_nids;
5010 spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS,
5011 stac9200_models,
5012 stac9200_cfg_tbl);
5013 if (spec->board_config < 0)
5014 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5015 codec->chip_name);
5016 else
5017 stac92xx_set_config_regs(codec,
5018 stac9200_brd_tbl[spec->board_config]);
5020 spec->multiout.max_channels = 2;
5021 spec->multiout.num_dacs = 1;
5022 spec->multiout.dac_nids = stac9200_dac_nids;
5023 spec->adc_nids = stac9200_adc_nids;
5024 spec->mux_nids = stac9200_mux_nids;
5025 spec->num_muxes = 1;
5026 spec->num_dmics = 0;
5027 spec->num_adcs = 1;
5028 spec->num_pwrs = 0;
5030 if (spec->board_config == STAC_9200_M4 ||
5031 spec->board_config == STAC_9200_M4_2 ||
5032 spec->board_config == STAC_9200_OQO)
5033 spec->init = stac9200_eapd_init;
5034 else
5035 spec->init = stac9200_core_init;
5036 spec->mixer = stac9200_mixer;
5038 if (spec->board_config == STAC_9200_PANASONIC) {
5039 spec->gpio_mask = spec->gpio_dir = 0x09;
5040 spec->gpio_data = 0x00;
5043 err = stac9200_parse_auto_config(codec);
5044 if (err < 0) {
5045 stac92xx_free(codec);
5046 return err;
5049 /* CF-74 has no headphone detection, and the driver should *NOT*
5050 * do detection and HP/speaker toggle because the hardware does it.
5052 if (spec->board_config == STAC_9200_PANASONIC)
5053 spec->hp_detect = 0;
5055 codec->patch_ops = stac92xx_patch_ops;
5057 return 0;
5060 static int patch_stac925x(struct hda_codec *codec)
5062 struct sigmatel_spec *spec;
5063 int err;
5065 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5066 if (spec == NULL)
5067 return -ENOMEM;
5069 codec->no_trigger_sense = 1;
5070 codec->spec = spec;
5071 spec->num_pins = ARRAY_SIZE(stac925x_pin_nids);
5072 spec->pin_nids = stac925x_pin_nids;
5074 /* Check first for codec ID */
5075 spec->board_config = snd_hda_check_board_codec_sid_config(codec,
5076 STAC_925x_MODELS,
5077 stac925x_models,
5078 stac925x_codec_id_cfg_tbl);
5080 /* Now checks for PCI ID, if codec ID is not found */
5081 if (spec->board_config < 0)
5082 spec->board_config = snd_hda_check_board_config(codec,
5083 STAC_925x_MODELS,
5084 stac925x_models,
5085 stac925x_cfg_tbl);
5086 again:
5087 if (spec->board_config < 0)
5088 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5089 codec->chip_name);
5090 else
5091 stac92xx_set_config_regs(codec,
5092 stac925x_brd_tbl[spec->board_config]);
5094 spec->multiout.max_channels = 2;
5095 spec->multiout.num_dacs = 1;
5096 spec->multiout.dac_nids = stac925x_dac_nids;
5097 spec->adc_nids = stac925x_adc_nids;
5098 spec->mux_nids = stac925x_mux_nids;
5099 spec->num_muxes = 1;
5100 spec->num_adcs = 1;
5101 spec->num_pwrs = 0;
5102 switch (codec->vendor_id) {
5103 case 0x83847632: /* STAC9202 */
5104 case 0x83847633: /* STAC9202D */
5105 case 0x83847636: /* STAC9251 */
5106 case 0x83847637: /* STAC9251D */
5107 spec->num_dmics = STAC925X_NUM_DMICS;
5108 spec->dmic_nids = stac925x_dmic_nids;
5109 spec->num_dmuxes = ARRAY_SIZE(stac925x_dmux_nids);
5110 spec->dmux_nids = stac925x_dmux_nids;
5111 break;
5112 default:
5113 spec->num_dmics = 0;
5114 break;
5117 spec->init = stac925x_core_init;
5118 spec->mixer = stac925x_mixer;
5119 spec->num_caps = 1;
5120 spec->capvols = stac925x_capvols;
5121 spec->capsws = stac925x_capsws;
5123 err = stac92xx_parse_auto_config(codec, 0x8, 0x7);
5124 if (!err) {
5125 if (spec->board_config < 0) {
5126 printk(KERN_WARNING "hda_codec: No auto-config is "
5127 "available, default to model=ref\n");
5128 spec->board_config = STAC_925x_REF;
5129 goto again;
5131 err = -EINVAL;
5133 if (err < 0) {
5134 stac92xx_free(codec);
5135 return err;
5138 codec->patch_ops = stac92xx_patch_ops;
5140 return 0;
5143 static int patch_stac92hd73xx(struct hda_codec *codec)
5145 struct sigmatel_spec *spec;
5146 hda_nid_t conn[STAC92HD73_DAC_COUNT + 2];
5147 int err = 0;
5148 int num_dacs;
5150 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5151 if (spec == NULL)
5152 return -ENOMEM;
5154 codec->no_trigger_sense = 1;
5155 codec->spec = spec;
5156 codec->slave_dig_outs = stac92hd73xx_slave_dig_outs;
5157 spec->num_pins = ARRAY_SIZE(stac92hd73xx_pin_nids);
5158 spec->pin_nids = stac92hd73xx_pin_nids;
5159 spec->board_config = snd_hda_check_board_config(codec,
5160 STAC_92HD73XX_MODELS,
5161 stac92hd73xx_models,
5162 stac92hd73xx_cfg_tbl);
5163 /* check codec subsystem id if not found */
5164 if (spec->board_config < 0)
5165 spec->board_config =
5166 snd_hda_check_board_codec_sid_config(codec,
5167 STAC_92HD73XX_MODELS, stac92hd73xx_models,
5168 stac92hd73xx_codec_id_cfg_tbl);
5169 again:
5170 if (spec->board_config < 0)
5171 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5172 codec->chip_name);
5173 else
5174 stac92xx_set_config_regs(codec,
5175 stac92hd73xx_brd_tbl[spec->board_config]);
5177 num_dacs = snd_hda_get_connections(codec, 0x0a,
5178 conn, STAC92HD73_DAC_COUNT + 2) - 1;
5180 if (num_dacs < 3 || num_dacs > 5) {
5181 printk(KERN_WARNING "hda_codec: Could not determine "
5182 "number of channels defaulting to DAC count\n");
5183 num_dacs = STAC92HD73_DAC_COUNT;
5185 spec->init = stac92hd73xx_core_init;
5186 switch (num_dacs) {
5187 case 0x3: /* 6 Channel */
5188 spec->aloopback_ctl = stac92hd73xx_6ch_loopback;
5189 break;
5190 case 0x4: /* 8 Channel */
5191 spec->aloopback_ctl = stac92hd73xx_8ch_loopback;
5192 break;
5193 case 0x5: /* 10 Channel */
5194 spec->aloopback_ctl = stac92hd73xx_10ch_loopback;
5195 break;
5197 spec->multiout.dac_nids = spec->dac_nids;
5199 spec->aloopback_mask = 0x01;
5200 spec->aloopback_shift = 8;
5202 spec->digbeep_nid = 0x1c;
5203 spec->mux_nids = stac92hd73xx_mux_nids;
5204 spec->adc_nids = stac92hd73xx_adc_nids;
5205 spec->dmic_nids = stac92hd73xx_dmic_nids;
5206 spec->dmux_nids = stac92hd73xx_dmux_nids;
5207 spec->smux_nids = stac92hd73xx_smux_nids;
5209 spec->num_muxes = ARRAY_SIZE(stac92hd73xx_mux_nids);
5210 spec->num_adcs = ARRAY_SIZE(stac92hd73xx_adc_nids);
5211 spec->num_dmuxes = ARRAY_SIZE(stac92hd73xx_dmux_nids);
5213 spec->num_caps = STAC92HD73XX_NUM_CAPS;
5214 spec->capvols = stac92hd73xx_capvols;
5215 spec->capsws = stac92hd73xx_capsws;
5217 switch (spec->board_config) {
5218 case STAC_DELL_EQ:
5219 spec->init = dell_eq_core_init;
5220 /* fallthru */
5221 case STAC_DELL_M6_AMIC:
5222 case STAC_DELL_M6_DMIC:
5223 case STAC_DELL_M6_BOTH:
5224 spec->num_smuxes = 0;
5225 spec->eapd_switch = 0;
5227 switch (spec->board_config) {
5228 case STAC_DELL_M6_AMIC: /* Analog Mics */
5229 snd_hda_codec_set_pincfg(codec, 0x0b, 0x90A70170);
5230 spec->num_dmics = 0;
5231 break;
5232 case STAC_DELL_M6_DMIC: /* Digital Mics */
5233 snd_hda_codec_set_pincfg(codec, 0x13, 0x90A60160);
5234 spec->num_dmics = 1;
5235 break;
5236 case STAC_DELL_M6_BOTH: /* Both */
5237 snd_hda_codec_set_pincfg(codec, 0x0b, 0x90A70170);
5238 snd_hda_codec_set_pincfg(codec, 0x13, 0x90A60160);
5239 spec->num_dmics = 1;
5240 break;
5242 break;
5243 case STAC_ALIENWARE_M17X:
5244 spec->num_dmics = STAC92HD73XX_NUM_DMICS;
5245 spec->num_smuxes = ARRAY_SIZE(stac92hd73xx_smux_nids);
5246 spec->eapd_switch = 0;
5247 break;
5248 default:
5249 spec->num_dmics = STAC92HD73XX_NUM_DMICS;
5250 spec->num_smuxes = ARRAY_SIZE(stac92hd73xx_smux_nids);
5251 spec->eapd_switch = 1;
5252 break;
5254 if (spec->board_config != STAC_92HD73XX_REF) {
5255 /* GPIO0 High = Enable EAPD */
5256 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
5257 spec->gpio_data = 0x01;
5260 spec->num_pwrs = ARRAY_SIZE(stac92hd73xx_pwr_nids);
5261 spec->pwr_nids = stac92hd73xx_pwr_nids;
5263 err = stac92xx_parse_auto_config(codec, 0x25, 0x27);
5265 if (!err) {
5266 if (spec->board_config < 0) {
5267 printk(KERN_WARNING "hda_codec: No auto-config is "
5268 "available, default to model=ref\n");
5269 spec->board_config = STAC_92HD73XX_REF;
5270 goto again;
5272 err = -EINVAL;
5275 if (err < 0) {
5276 stac92xx_free(codec);
5277 return err;
5280 if (spec->board_config == STAC_92HD73XX_NO_JD)
5281 spec->hp_detect = 0;
5283 codec->patch_ops = stac92xx_patch_ops;
5285 codec->proc_widget_hook = stac92hd7x_proc_hook;
5287 return 0;
5290 static int patch_stac92hd83xxx(struct hda_codec *codec)
5292 struct sigmatel_spec *spec;
5293 hda_nid_t conn[STAC92HD83_DAC_COUNT + 1];
5294 int err;
5295 int num_dacs;
5297 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5298 if (spec == NULL)
5299 return -ENOMEM;
5301 codec->no_trigger_sense = 1;
5302 codec->spec = spec;
5303 codec->slave_dig_outs = stac92hd83xxx_slave_dig_outs;
5304 spec->digbeep_nid = 0x21;
5305 spec->mux_nids = stac92hd83xxx_mux_nids;
5306 spec->num_muxes = ARRAY_SIZE(stac92hd83xxx_mux_nids);
5307 spec->adc_nids = stac92hd83xxx_adc_nids;
5308 spec->num_adcs = ARRAY_SIZE(stac92hd83xxx_adc_nids);
5309 spec->pwr_nids = stac92hd83xxx_pwr_nids;
5310 spec->pwr_mapping = stac92hd83xxx_pwr_mapping;
5311 spec->num_pwrs = ARRAY_SIZE(stac92hd83xxx_pwr_nids);
5312 spec->multiout.dac_nids = spec->dac_nids;
5314 spec->init = stac92hd83xxx_core_init;
5315 spec->num_pins = ARRAY_SIZE(stac92hd83xxx_pin_nids);
5316 spec->pin_nids = stac92hd83xxx_pin_nids;
5317 spec->num_caps = STAC92HD83XXX_NUM_CAPS;
5318 spec->capvols = stac92hd83xxx_capvols;
5319 spec->capsws = stac92hd83xxx_capsws;
5321 spec->board_config = snd_hda_check_board_config(codec,
5322 STAC_92HD83XXX_MODELS,
5323 stac92hd83xxx_models,
5324 stac92hd83xxx_cfg_tbl);
5325 again:
5326 if (spec->board_config < 0)
5327 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5328 codec->chip_name);
5329 else
5330 stac92xx_set_config_regs(codec,
5331 stac92hd83xxx_brd_tbl[spec->board_config]);
5333 switch (codec->vendor_id) {
5334 case 0x111d7666:
5335 case 0x111d7667:
5336 case 0x111d7668:
5337 case 0x111d7669:
5338 spec->num_pins = ARRAY_SIZE(stac92hd88xxx_pin_nids);
5339 spec->pin_nids = stac92hd88xxx_pin_nids;
5340 spec->mono_nid = 0;
5341 spec->digbeep_nid = 0;
5342 spec->num_pwrs = 0;
5343 break;
5344 case 0x111d7604:
5345 case 0x111d76d4:
5346 case 0x111d7605:
5347 case 0x111d76d5:
5348 if (spec->board_config == STAC_92HD83XXX_PWR_REF)
5349 break;
5350 spec->num_pwrs = 0;
5351 break;
5354 codec->patch_ops = stac92xx_patch_ops;
5356 if (find_mute_led_gpio(codec, 0))
5357 snd_printd("mute LED gpio %d polarity %d\n",
5358 spec->gpio_led,
5359 spec->gpio_led_polarity);
5361 #ifdef CONFIG_SND_HDA_POWER_SAVE
5362 if (spec->gpio_led) {
5363 spec->gpio_mask |= spec->gpio_led;
5364 spec->gpio_dir |= spec->gpio_led;
5365 spec->gpio_data |= spec->gpio_led;
5366 /* register check_power_status callback. */
5367 codec->patch_ops.check_power_status =
5368 stac92xx_hp_check_power_status;
5370 #endif
5372 err = stac92xx_parse_auto_config(codec, 0x1d, 0);
5373 if (!err) {
5374 if (spec->board_config < 0) {
5375 printk(KERN_WARNING "hda_codec: No auto-config is "
5376 "available, default to model=ref\n");
5377 spec->board_config = STAC_92HD83XXX_REF;
5378 goto again;
5380 err = -EINVAL;
5383 if (err < 0) {
5384 stac92xx_free(codec);
5385 return err;
5388 /* docking output support */
5389 num_dacs = snd_hda_get_connections(codec, 0xF,
5390 conn, STAC92HD83_DAC_COUNT + 1) - 1;
5391 /* skip non-DAC connections */
5392 while (num_dacs >= 0 &&
5393 (get_wcaps_type(get_wcaps(codec, conn[num_dacs]))
5394 != AC_WID_AUD_OUT))
5395 num_dacs--;
5396 /* set port E and F to select the last DAC */
5397 if (num_dacs >= 0) {
5398 snd_hda_codec_write_cache(codec, 0xE, 0,
5399 AC_VERB_SET_CONNECT_SEL, num_dacs);
5400 snd_hda_codec_write_cache(codec, 0xF, 0,
5401 AC_VERB_SET_CONNECT_SEL, num_dacs);
5404 codec->proc_widget_hook = stac92hd_proc_hook;
5406 return 0;
5409 /* get the pin connection (fixed, none, etc) */
5410 static unsigned int stac_get_defcfg_connect(struct hda_codec *codec, int idx)
5412 struct sigmatel_spec *spec = codec->spec;
5413 unsigned int cfg;
5415 cfg = snd_hda_codec_get_pincfg(codec, spec->pin_nids[idx]);
5416 return get_defcfg_connect(cfg);
5419 static int stac92hd71bxx_connected_ports(struct hda_codec *codec,
5420 hda_nid_t *nids, int num_nids)
5422 struct sigmatel_spec *spec = codec->spec;
5423 int idx, num;
5424 unsigned int def_conf;
5426 for (num = 0; num < num_nids; num++) {
5427 for (idx = 0; idx < spec->num_pins; idx++)
5428 if (spec->pin_nids[idx] == nids[num])
5429 break;
5430 if (idx >= spec->num_pins)
5431 break;
5432 def_conf = stac_get_defcfg_connect(codec, idx);
5433 if (def_conf == AC_JACK_PORT_NONE)
5434 break;
5436 return num;
5439 static int stac92hd71bxx_connected_smuxes(struct hda_codec *codec,
5440 hda_nid_t dig0pin)
5442 struct sigmatel_spec *spec = codec->spec;
5443 int idx;
5445 for (idx = 0; idx < spec->num_pins; idx++)
5446 if (spec->pin_nids[idx] == dig0pin)
5447 break;
5448 if ((idx + 2) >= spec->num_pins)
5449 return 0;
5451 /* dig1pin case */
5452 if (stac_get_defcfg_connect(codec, idx + 1) != AC_JACK_PORT_NONE)
5453 return 2;
5455 /* dig0pin + dig2pin case */
5456 if (stac_get_defcfg_connect(codec, idx + 2) != AC_JACK_PORT_NONE)
5457 return 2;
5458 if (stac_get_defcfg_connect(codec, idx) != AC_JACK_PORT_NONE)
5459 return 1;
5460 else
5461 return 0;
5464 /* HP dv7 bass switch - GPIO5 */
5465 #define stac_hp_bass_gpio_info snd_ctl_boolean_mono_info
5466 static int stac_hp_bass_gpio_get(struct snd_kcontrol *kcontrol,
5467 struct snd_ctl_elem_value *ucontrol)
5469 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5470 struct sigmatel_spec *spec = codec->spec;
5471 ucontrol->value.integer.value[0] = !!(spec->gpio_data & 0x20);
5472 return 0;
5475 static int stac_hp_bass_gpio_put(struct snd_kcontrol *kcontrol,
5476 struct snd_ctl_elem_value *ucontrol)
5478 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5479 struct sigmatel_spec *spec = codec->spec;
5480 unsigned int gpio_data;
5482 gpio_data = (spec->gpio_data & ~0x20) |
5483 (ucontrol->value.integer.value[0] ? 0x20 : 0);
5484 if (gpio_data == spec->gpio_data)
5485 return 0;
5486 spec->gpio_data = gpio_data;
5487 stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, spec->gpio_data);
5488 return 1;
5491 static struct snd_kcontrol_new stac_hp_bass_sw_ctrl = {
5492 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5493 .info = stac_hp_bass_gpio_info,
5494 .get = stac_hp_bass_gpio_get,
5495 .put = stac_hp_bass_gpio_put,
5498 static int stac_add_hp_bass_switch(struct hda_codec *codec)
5500 struct sigmatel_spec *spec = codec->spec;
5502 if (!stac_control_new(spec, &stac_hp_bass_sw_ctrl,
5503 "Bass Speaker Playback Switch", 0))
5504 return -ENOMEM;
5506 spec->gpio_mask |= 0x20;
5507 spec->gpio_dir |= 0x20;
5508 spec->gpio_data |= 0x20;
5509 return 0;
5512 static int patch_stac92hd71bxx(struct hda_codec *codec)
5514 struct sigmatel_spec *spec;
5515 struct hda_verb *unmute_init = stac92hd71bxx_unmute_core_init;
5516 unsigned int pin_cfg;
5517 int err = 0;
5519 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5520 if (spec == NULL)
5521 return -ENOMEM;
5523 codec->no_trigger_sense = 1;
5524 codec->spec = spec;
5525 codec->patch_ops = stac92xx_patch_ops;
5526 spec->num_pins = STAC92HD71BXX_NUM_PINS;
5527 switch (codec->vendor_id) {
5528 case 0x111d76b6:
5529 case 0x111d76b7:
5530 spec->pin_nids = stac92hd71bxx_pin_nids_4port;
5531 break;
5532 case 0x111d7603:
5533 case 0x111d7608:
5534 /* On 92HD75Bx 0x27 isn't a pin nid */
5535 spec->num_pins--;
5536 /* fallthrough */
5537 default:
5538 spec->pin_nids = stac92hd71bxx_pin_nids_6port;
5540 spec->num_pwrs = ARRAY_SIZE(stac92hd71bxx_pwr_nids);
5541 spec->board_config = snd_hda_check_board_config(codec,
5542 STAC_92HD71BXX_MODELS,
5543 stac92hd71bxx_models,
5544 stac92hd71bxx_cfg_tbl);
5545 again:
5546 if (spec->board_config < 0)
5547 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5548 codec->chip_name);
5549 else
5550 stac92xx_set_config_regs(codec,
5551 stac92hd71bxx_brd_tbl[spec->board_config]);
5553 if (spec->board_config != STAC_92HD71BXX_REF) {
5554 /* GPIO0 = EAPD */
5555 spec->gpio_mask = 0x01;
5556 spec->gpio_dir = 0x01;
5557 spec->gpio_data = 0x01;
5560 spec->dmic_nids = stac92hd71bxx_dmic_nids;
5561 spec->dmux_nids = stac92hd71bxx_dmux_nids;
5563 spec->num_caps = STAC92HD71BXX_NUM_CAPS;
5564 spec->capvols = stac92hd71bxx_capvols;
5565 spec->capsws = stac92hd71bxx_capsws;
5567 switch (codec->vendor_id) {
5568 case 0x111d76b6: /* 4 Port without Analog Mixer */
5569 case 0x111d76b7:
5570 unmute_init++;
5571 /* fallthru */
5572 case 0x111d76b4: /* 6 Port without Analog Mixer */
5573 case 0x111d76b5:
5574 spec->init = stac92hd71bxx_core_init;
5575 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
5576 spec->num_dmics = stac92hd71bxx_connected_ports(codec,
5577 stac92hd71bxx_dmic_nids,
5578 STAC92HD71BXX_NUM_DMICS);
5579 break;
5580 case 0x111d7608: /* 5 Port with Analog Mixer */
5581 switch (spec->board_config) {
5582 case STAC_HP_M4:
5583 /* Enable VREF power saving on GPIO1 detect */
5584 err = stac_add_event(spec, codec->afg,
5585 STAC_VREF_EVENT, 0x02);
5586 if (err < 0)
5587 return err;
5588 snd_hda_codec_write_cache(codec, codec->afg, 0,
5589 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x02);
5590 snd_hda_codec_write_cache(codec, codec->afg, 0,
5591 AC_VERB_SET_UNSOLICITED_ENABLE,
5592 AC_USRSP_EN | err);
5593 spec->gpio_mask |= 0x02;
5594 break;
5596 if ((codec->revision_id & 0xf) == 0 ||
5597 (codec->revision_id & 0xf) == 1)
5598 spec->stream_delay = 40; /* 40 milliseconds */
5600 /* no output amps */
5601 spec->num_pwrs = 0;
5602 /* disable VSW */
5603 spec->init = stac92hd71bxx_core_init;
5604 unmute_init++;
5605 snd_hda_codec_set_pincfg(codec, 0x0f, 0x40f000f0);
5606 snd_hda_codec_set_pincfg(codec, 0x19, 0x40f000f3);
5607 stac92hd71bxx_dmic_nids[STAC92HD71BXX_NUM_DMICS - 1] = 0;
5608 spec->num_dmics = stac92hd71bxx_connected_ports(codec,
5609 stac92hd71bxx_dmic_nids,
5610 STAC92HD71BXX_NUM_DMICS - 1);
5611 break;
5612 case 0x111d7603: /* 6 Port with Analog Mixer */
5613 if ((codec->revision_id & 0xf) == 1)
5614 spec->stream_delay = 40; /* 40 milliseconds */
5616 /* no output amps */
5617 spec->num_pwrs = 0;
5618 /* fallthru */
5619 default:
5620 spec->init = stac92hd71bxx_core_init;
5621 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
5622 spec->num_dmics = stac92hd71bxx_connected_ports(codec,
5623 stac92hd71bxx_dmic_nids,
5624 STAC92HD71BXX_NUM_DMICS);
5625 break;
5628 if (get_wcaps(codec, 0xa) & AC_WCAP_IN_AMP)
5629 snd_hda_sequence_write_cache(codec, unmute_init);
5631 /* Some HP machines seem to have unstable codec communications
5632 * especially with ATI fglrx driver. For recovering from the
5633 * CORB/RIRB stall, allow the BUS reset and keep always sync
5635 if (spec->board_config == STAC_HP_DV5) {
5636 codec->bus->sync_write = 1;
5637 codec->bus->allow_bus_reset = 1;
5640 spec->aloopback_ctl = stac92hd71bxx_loopback;
5641 spec->aloopback_mask = 0x50;
5642 spec->aloopback_shift = 0;
5644 spec->powerdown_adcs = 1;
5645 spec->digbeep_nid = 0x26;
5646 spec->mux_nids = stac92hd71bxx_mux_nids;
5647 spec->adc_nids = stac92hd71bxx_adc_nids;
5648 spec->smux_nids = stac92hd71bxx_smux_nids;
5649 spec->pwr_nids = stac92hd71bxx_pwr_nids;
5651 spec->num_muxes = ARRAY_SIZE(stac92hd71bxx_mux_nids);
5652 spec->num_adcs = ARRAY_SIZE(stac92hd71bxx_adc_nids);
5653 spec->num_dmuxes = ARRAY_SIZE(stac92hd71bxx_dmux_nids);
5654 spec->num_smuxes = stac92hd71bxx_connected_smuxes(codec, 0x1e);
5656 snd_printdd("Found board config: %d\n", spec->board_config);
5658 switch (spec->board_config) {
5659 case STAC_HP_M4:
5660 /* enable internal microphone */
5661 snd_hda_codec_set_pincfg(codec, 0x0e, 0x01813040);
5662 stac92xx_auto_set_pinctl(codec, 0x0e,
5663 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80);
5664 /* fallthru */
5665 case STAC_DELL_M4_2:
5666 spec->num_dmics = 0;
5667 spec->num_smuxes = 0;
5668 spec->num_dmuxes = 0;
5669 break;
5670 case STAC_DELL_M4_1:
5671 case STAC_DELL_M4_3:
5672 spec->num_dmics = 1;
5673 spec->num_smuxes = 0;
5674 spec->num_dmuxes = 1;
5675 break;
5676 case STAC_HP_DV4_1222NR:
5677 spec->num_dmics = 1;
5678 /* I don't know if it needs 1 or 2 smuxes - will wait for
5679 * bug reports to fix if needed
5681 spec->num_smuxes = 1;
5682 spec->num_dmuxes = 1;
5683 /* fallthrough */
5684 case STAC_HP_DV4:
5685 spec->gpio_led = 0x01;
5686 /* fallthrough */
5687 case STAC_HP_DV5:
5688 snd_hda_codec_set_pincfg(codec, 0x0d, 0x90170010);
5689 stac92xx_auto_set_pinctl(codec, 0x0d, AC_PINCTL_OUT_EN);
5690 /* HP dv6 gives the headphone pin as a line-out. Thus we
5691 * need to set hp_detect flag here to force to enable HP
5692 * detection.
5694 spec->hp_detect = 1;
5695 break;
5696 case STAC_HP_HDX:
5697 spec->num_dmics = 1;
5698 spec->num_dmuxes = 1;
5699 spec->num_smuxes = 1;
5700 spec->gpio_led = 0x08;
5701 break;
5704 if (hp_blike_system(codec->subsystem_id)) {
5705 pin_cfg = snd_hda_codec_get_pincfg(codec, 0x0f);
5706 if (get_defcfg_device(pin_cfg) == AC_JACK_LINE_OUT ||
5707 get_defcfg_device(pin_cfg) == AC_JACK_SPEAKER ||
5708 get_defcfg_device(pin_cfg) == AC_JACK_HP_OUT) {
5709 /* It was changed in the BIOS to just satisfy MS DTM.
5710 * Lets turn it back into slaved HP
5712 pin_cfg = (pin_cfg & (~AC_DEFCFG_DEVICE))
5713 | (AC_JACK_HP_OUT <<
5714 AC_DEFCFG_DEVICE_SHIFT);
5715 pin_cfg = (pin_cfg & (~(AC_DEFCFG_DEF_ASSOC
5716 | AC_DEFCFG_SEQUENCE)))
5717 | 0x1f;
5718 snd_hda_codec_set_pincfg(codec, 0x0f, pin_cfg);
5722 if (find_mute_led_gpio(codec, 1))
5723 snd_printd("mute LED gpio %d polarity %d\n",
5724 spec->gpio_led,
5725 spec->gpio_led_polarity);
5727 #ifdef CONFIG_SND_HDA_POWER_SAVE
5728 if (spec->gpio_led) {
5729 spec->gpio_mask |= spec->gpio_led;
5730 spec->gpio_dir |= spec->gpio_led;
5731 spec->gpio_data |= spec->gpio_led;
5732 /* register check_power_status callback. */
5733 codec->patch_ops.check_power_status =
5734 stac92xx_hp_check_power_status;
5736 #endif
5738 spec->multiout.dac_nids = spec->dac_nids;
5740 err = stac92xx_parse_auto_config(codec, 0x21, 0);
5741 if (!err) {
5742 if (spec->board_config < 0) {
5743 printk(KERN_WARNING "hda_codec: No auto-config is "
5744 "available, default to model=ref\n");
5745 spec->board_config = STAC_92HD71BXX_REF;
5746 goto again;
5748 err = -EINVAL;
5751 if (err < 0) {
5752 stac92xx_free(codec);
5753 return err;
5756 /* enable bass on HP dv7 */
5757 if (spec->board_config == STAC_HP_DV4 ||
5758 spec->board_config == STAC_HP_DV5) {
5759 unsigned int cap;
5760 cap = snd_hda_param_read(codec, 0x1, AC_PAR_GPIO_CAP);
5761 cap &= AC_GPIO_IO_COUNT;
5762 if (cap >= 6)
5763 stac_add_hp_bass_switch(codec);
5766 codec->proc_widget_hook = stac92hd7x_proc_hook;
5768 return 0;
5771 static int patch_stac922x(struct hda_codec *codec)
5773 struct sigmatel_spec *spec;
5774 int err;
5776 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5777 if (spec == NULL)
5778 return -ENOMEM;
5780 codec->no_trigger_sense = 1;
5781 codec->spec = spec;
5782 spec->num_pins = ARRAY_SIZE(stac922x_pin_nids);
5783 spec->pin_nids = stac922x_pin_nids;
5784 spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS,
5785 stac922x_models,
5786 stac922x_cfg_tbl);
5787 if (spec->board_config == STAC_INTEL_MAC_AUTO) {
5788 spec->gpio_mask = spec->gpio_dir = 0x03;
5789 spec->gpio_data = 0x03;
5790 /* Intel Macs have all same PCI SSID, so we need to check
5791 * codec SSID to distinguish the exact models
5793 printk(KERN_INFO "hda_codec: STAC922x, Apple subsys_id=%x\n", codec->subsystem_id);
5794 switch (codec->subsystem_id) {
5796 case 0x106b0800:
5797 spec->board_config = STAC_INTEL_MAC_V1;
5798 break;
5799 case 0x106b0600:
5800 case 0x106b0700:
5801 spec->board_config = STAC_INTEL_MAC_V2;
5802 break;
5803 case 0x106b0e00:
5804 case 0x106b0f00:
5805 case 0x106b1600:
5806 case 0x106b1700:
5807 case 0x106b0200:
5808 case 0x106b1e00:
5809 spec->board_config = STAC_INTEL_MAC_V3;
5810 break;
5811 case 0x106b1a00:
5812 case 0x00000100:
5813 spec->board_config = STAC_INTEL_MAC_V4;
5814 break;
5815 case 0x106b0a00:
5816 case 0x106b2200:
5817 spec->board_config = STAC_INTEL_MAC_V5;
5818 break;
5819 default:
5820 spec->board_config = STAC_INTEL_MAC_V3;
5821 break;
5825 again:
5826 if (spec->board_config < 0)
5827 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5828 codec->chip_name);
5829 else
5830 stac92xx_set_config_regs(codec,
5831 stac922x_brd_tbl[spec->board_config]);
5833 spec->adc_nids = stac922x_adc_nids;
5834 spec->mux_nids = stac922x_mux_nids;
5835 spec->num_muxes = ARRAY_SIZE(stac922x_mux_nids);
5836 spec->num_adcs = ARRAY_SIZE(stac922x_adc_nids);
5837 spec->num_dmics = 0;
5838 spec->num_pwrs = 0;
5840 spec->init = stac922x_core_init;
5842 spec->num_caps = STAC922X_NUM_CAPS;
5843 spec->capvols = stac922x_capvols;
5844 spec->capsws = stac922x_capsws;
5846 spec->multiout.dac_nids = spec->dac_nids;
5848 err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
5849 if (!err) {
5850 if (spec->board_config < 0) {
5851 printk(KERN_WARNING "hda_codec: No auto-config is "
5852 "available, default to model=ref\n");
5853 spec->board_config = STAC_D945_REF;
5854 goto again;
5856 err = -EINVAL;
5858 if (err < 0) {
5859 stac92xx_free(codec);
5860 return err;
5863 codec->patch_ops = stac92xx_patch_ops;
5865 /* Fix Mux capture level; max to 2 */
5866 snd_hda_override_amp_caps(codec, 0x12, HDA_OUTPUT,
5867 (0 << AC_AMPCAP_OFFSET_SHIFT) |
5868 (2 << AC_AMPCAP_NUM_STEPS_SHIFT) |
5869 (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5870 (0 << AC_AMPCAP_MUTE_SHIFT));
5872 return 0;
5875 static int patch_stac927x(struct hda_codec *codec)
5877 struct sigmatel_spec *spec;
5878 int err;
5880 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5881 if (spec == NULL)
5882 return -ENOMEM;
5884 codec->no_trigger_sense = 1;
5885 codec->spec = spec;
5886 codec->slave_dig_outs = stac927x_slave_dig_outs;
5887 spec->num_pins = ARRAY_SIZE(stac927x_pin_nids);
5888 spec->pin_nids = stac927x_pin_nids;
5889 spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS,
5890 stac927x_models,
5891 stac927x_cfg_tbl);
5892 again:
5893 if (spec->board_config < 0)
5894 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5895 codec->chip_name);
5896 else
5897 stac92xx_set_config_regs(codec,
5898 stac927x_brd_tbl[spec->board_config]);
5900 spec->digbeep_nid = 0x23;
5901 spec->adc_nids = stac927x_adc_nids;
5902 spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
5903 spec->mux_nids = stac927x_mux_nids;
5904 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
5905 spec->smux_nids = stac927x_smux_nids;
5906 spec->num_smuxes = ARRAY_SIZE(stac927x_smux_nids);
5907 spec->spdif_labels = stac927x_spdif_labels;
5908 spec->dac_list = stac927x_dac_nids;
5909 spec->multiout.dac_nids = spec->dac_nids;
5911 if (spec->board_config != STAC_D965_REF) {
5912 /* GPIO0 High = Enable EAPD */
5913 spec->eapd_mask = spec->gpio_mask = 0x01;
5914 spec->gpio_dir = spec->gpio_data = 0x01;
5917 switch (spec->board_config) {
5918 case STAC_D965_3ST:
5919 case STAC_D965_5ST:
5920 /* GPIO0 High = Enable EAPD */
5921 spec->num_dmics = 0;
5922 spec->init = d965_core_init;
5923 break;
5924 case STAC_DELL_BIOS:
5925 switch (codec->subsystem_id) {
5926 case 0x10280209:
5927 case 0x1028022e:
5928 /* correct the device field to SPDIF out */
5929 snd_hda_codec_set_pincfg(codec, 0x21, 0x01442070);
5930 break;
5932 /* configure the analog microphone on some laptops */
5933 snd_hda_codec_set_pincfg(codec, 0x0c, 0x90a79130);
5934 /* correct the front output jack as a hp out */
5935 snd_hda_codec_set_pincfg(codec, 0x0f, 0x0227011f);
5936 /* correct the front input jack as a mic */
5937 snd_hda_codec_set_pincfg(codec, 0x0e, 0x02a79130);
5938 /* fallthru */
5939 case STAC_DELL_3ST:
5940 if (codec->subsystem_id != 0x1028022f) {
5941 /* GPIO2 High = Enable EAPD */
5942 spec->eapd_mask = spec->gpio_mask = 0x04;
5943 spec->gpio_dir = spec->gpio_data = 0x04;
5945 spec->dmic_nids = stac927x_dmic_nids;
5946 spec->num_dmics = STAC927X_NUM_DMICS;
5948 spec->init = dell_3st_core_init;
5949 spec->dmux_nids = stac927x_dmux_nids;
5950 spec->num_dmuxes = ARRAY_SIZE(stac927x_dmux_nids);
5951 break;
5952 case STAC_927X_VOLKNOB:
5953 spec->num_dmics = 0;
5954 spec->init = stac927x_volknob_core_init;
5955 break;
5956 default:
5957 spec->num_dmics = 0;
5958 spec->init = stac927x_core_init;
5959 break;
5962 spec->num_caps = STAC927X_NUM_CAPS;
5963 spec->capvols = stac927x_capvols;
5964 spec->capsws = stac927x_capsws;
5966 spec->num_pwrs = 0;
5967 spec->aloopback_ctl = stac927x_loopback;
5968 spec->aloopback_mask = 0x40;
5969 spec->aloopback_shift = 0;
5970 spec->eapd_switch = 1;
5972 err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
5973 if (!err) {
5974 if (spec->board_config < 0) {
5975 printk(KERN_WARNING "hda_codec: No auto-config is "
5976 "available, default to model=ref\n");
5977 spec->board_config = STAC_D965_REF;
5978 goto again;
5980 err = -EINVAL;
5982 if (err < 0) {
5983 stac92xx_free(codec);
5984 return err;
5987 codec->patch_ops = stac92xx_patch_ops;
5989 codec->proc_widget_hook = stac927x_proc_hook;
5992 * !!FIXME!!
5993 * The STAC927x seem to require fairly long delays for certain
5994 * command sequences. With too short delays (even if the answer
5995 * is set to RIRB properly), it results in the silence output
5996 * on some hardwares like Dell.
5998 * The below flag enables the longer delay (see get_response
5999 * in hda_intel.c).
6001 codec->bus->needs_damn_long_delay = 1;
6003 /* no jack detecion for ref-no-jd model */
6004 if (spec->board_config == STAC_D965_REF_NO_JD)
6005 spec->hp_detect = 0;
6007 return 0;
6010 static int patch_stac9205(struct hda_codec *codec)
6012 struct sigmatel_spec *spec;
6013 int err;
6015 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6016 if (spec == NULL)
6017 return -ENOMEM;
6019 codec->no_trigger_sense = 1;
6020 codec->spec = spec;
6021 spec->num_pins = ARRAY_SIZE(stac9205_pin_nids);
6022 spec->pin_nids = stac9205_pin_nids;
6023 spec->board_config = snd_hda_check_board_config(codec, STAC_9205_MODELS,
6024 stac9205_models,
6025 stac9205_cfg_tbl);
6026 again:
6027 if (spec->board_config < 0)
6028 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6029 codec->chip_name);
6030 else
6031 stac92xx_set_config_regs(codec,
6032 stac9205_brd_tbl[spec->board_config]);
6034 spec->digbeep_nid = 0x23;
6035 spec->adc_nids = stac9205_adc_nids;
6036 spec->num_adcs = ARRAY_SIZE(stac9205_adc_nids);
6037 spec->mux_nids = stac9205_mux_nids;
6038 spec->num_muxes = ARRAY_SIZE(stac9205_mux_nids);
6039 spec->smux_nids = stac9205_smux_nids;
6040 spec->num_smuxes = ARRAY_SIZE(stac9205_smux_nids);
6041 spec->dmic_nids = stac9205_dmic_nids;
6042 spec->num_dmics = STAC9205_NUM_DMICS;
6043 spec->dmux_nids = stac9205_dmux_nids;
6044 spec->num_dmuxes = ARRAY_SIZE(stac9205_dmux_nids);
6045 spec->num_pwrs = 0;
6047 spec->init = stac9205_core_init;
6048 spec->aloopback_ctl = stac9205_loopback;
6050 spec->num_caps = STAC9205_NUM_CAPS;
6051 spec->capvols = stac9205_capvols;
6052 spec->capsws = stac9205_capsws;
6054 spec->aloopback_mask = 0x40;
6055 spec->aloopback_shift = 0;
6056 /* Turn on/off EAPD per HP plugging */
6057 if (spec->board_config != STAC_9205_EAPD)
6058 spec->eapd_switch = 1;
6059 spec->multiout.dac_nids = spec->dac_nids;
6061 switch (spec->board_config){
6062 case STAC_9205_DELL_M43:
6063 /* Enable SPDIF in/out */
6064 snd_hda_codec_set_pincfg(codec, 0x1f, 0x01441030);
6065 snd_hda_codec_set_pincfg(codec, 0x20, 0x1c410030);
6067 /* Enable unsol response for GPIO4/Dock HP connection */
6068 err = stac_add_event(spec, codec->afg, STAC_VREF_EVENT, 0x01);
6069 if (err < 0)
6070 return err;
6071 snd_hda_codec_write_cache(codec, codec->afg, 0,
6072 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x10);
6073 snd_hda_codec_write_cache(codec, codec->afg, 0,
6074 AC_VERB_SET_UNSOLICITED_ENABLE,
6075 AC_USRSP_EN | err);
6077 spec->gpio_dir = 0x0b;
6078 spec->eapd_mask = 0x01;
6079 spec->gpio_mask = 0x1b;
6080 spec->gpio_mute = 0x10;
6081 /* GPIO0 High = EAPD, GPIO1 Low = Headphone Mute,
6082 * GPIO3 Low = DRM
6084 spec->gpio_data = 0x01;
6085 break;
6086 case STAC_9205_REF:
6087 /* SPDIF-In enabled */
6088 break;
6089 default:
6090 /* GPIO0 High = EAPD */
6091 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
6092 spec->gpio_data = 0x01;
6093 break;
6096 err = stac92xx_parse_auto_config(codec, 0x1f, 0x20);
6097 if (!err) {
6098 if (spec->board_config < 0) {
6099 printk(KERN_WARNING "hda_codec: No auto-config is "
6100 "available, default to model=ref\n");
6101 spec->board_config = STAC_9205_REF;
6102 goto again;
6104 err = -EINVAL;
6106 if (err < 0) {
6107 stac92xx_free(codec);
6108 return err;
6111 codec->patch_ops = stac92xx_patch_ops;
6113 codec->proc_widget_hook = stac9205_proc_hook;
6115 return 0;
6119 * STAC9872 hack
6122 static struct hda_verb stac9872_core_init[] = {
6123 {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
6124 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
6128 static hda_nid_t stac9872_pin_nids[] = {
6129 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
6130 0x11, 0x13, 0x14,
6133 static hda_nid_t stac9872_adc_nids[] = {
6134 0x8 /*,0x6*/
6137 static hda_nid_t stac9872_mux_nids[] = {
6138 0x15
6141 static unsigned long stac9872_capvols[] = {
6142 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
6144 #define stac9872_capsws stac9872_capvols
6146 static unsigned int stac9872_vaio_pin_configs[9] = {
6147 0x03211020, 0x411111f0, 0x411111f0, 0x03a15030,
6148 0x411111f0, 0x90170110, 0x411111f0, 0x411111f0,
6149 0x90a7013e
6152 static const char *stac9872_models[STAC_9872_MODELS] = {
6153 [STAC_9872_AUTO] = "auto",
6154 [STAC_9872_VAIO] = "vaio",
6157 static unsigned int *stac9872_brd_tbl[STAC_9872_MODELS] = {
6158 [STAC_9872_VAIO] = stac9872_vaio_pin_configs,
6161 static struct snd_pci_quirk stac9872_cfg_tbl[] = {
6162 SND_PCI_QUIRK_MASK(0x104d, 0xfff0, 0x81e0,
6163 "Sony VAIO F/S", STAC_9872_VAIO),
6164 {} /* terminator */
6167 static int patch_stac9872(struct hda_codec *codec)
6169 struct sigmatel_spec *spec;
6170 int err;
6172 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6173 if (spec == NULL)
6174 return -ENOMEM;
6175 codec->no_trigger_sense = 1;
6176 codec->spec = spec;
6177 spec->num_pins = ARRAY_SIZE(stac9872_pin_nids);
6178 spec->pin_nids = stac9872_pin_nids;
6180 spec->board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
6181 stac9872_models,
6182 stac9872_cfg_tbl);
6183 if (spec->board_config < 0)
6184 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6185 codec->chip_name);
6186 else
6187 stac92xx_set_config_regs(codec,
6188 stac9872_brd_tbl[spec->board_config]);
6190 spec->multiout.dac_nids = spec->dac_nids;
6191 spec->num_adcs = ARRAY_SIZE(stac9872_adc_nids);
6192 spec->adc_nids = stac9872_adc_nids;
6193 spec->num_muxes = ARRAY_SIZE(stac9872_mux_nids);
6194 spec->mux_nids = stac9872_mux_nids;
6195 spec->init = stac9872_core_init;
6196 spec->num_caps = 1;
6197 spec->capvols = stac9872_capvols;
6198 spec->capsws = stac9872_capsws;
6200 err = stac92xx_parse_auto_config(codec, 0x10, 0x12);
6201 if (err < 0) {
6202 stac92xx_free(codec);
6203 return -EINVAL;
6205 spec->input_mux = &spec->private_imux;
6206 codec->patch_ops = stac92xx_patch_ops;
6207 return 0;
6212 * patch entries
6214 static struct hda_codec_preset snd_hda_preset_sigmatel[] = {
6215 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
6216 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
6217 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
6218 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
6219 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
6220 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
6221 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
6222 { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
6223 { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
6224 { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
6225 { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
6226 { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
6227 { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
6228 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
6229 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
6230 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
6231 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
6232 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
6233 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
6234 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
6235 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
6236 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
6237 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
6238 { .id = 0x83847632, .name = "STAC9202", .patch = patch_stac925x },
6239 { .id = 0x83847633, .name = "STAC9202D", .patch = patch_stac925x },
6240 { .id = 0x83847634, .name = "STAC9250", .patch = patch_stac925x },
6241 { .id = 0x83847635, .name = "STAC9250D", .patch = patch_stac925x },
6242 { .id = 0x83847636, .name = "STAC9251", .patch = patch_stac925x },
6243 { .id = 0x83847637, .name = "STAC9250D", .patch = patch_stac925x },
6244 { .id = 0x83847645, .name = "92HD206X", .patch = patch_stac927x },
6245 { .id = 0x83847646, .name = "92HD206D", .patch = patch_stac927x },
6246 /* The following does not take into account .id=0x83847661 when subsys =
6247 * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
6248 * currently not fully supported.
6250 { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
6251 { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
6252 { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
6253 { .id = 0x83847698, .name = "STAC9205", .patch = patch_stac9205 },
6254 { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
6255 { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
6256 { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
6257 { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
6258 { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
6259 { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
6260 { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
6261 { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
6262 { .id = 0x111d7603, .name = "92HD75B3X5", .patch = patch_stac92hd71bxx},
6263 { .id = 0x111d7604, .name = "92HD83C1X5", .patch = patch_stac92hd83xxx},
6264 { .id = 0x111d76d4, .name = "92HD83C1C5", .patch = patch_stac92hd83xxx},
6265 { .id = 0x111d7605, .name = "92HD81B1X5", .patch = patch_stac92hd83xxx},
6266 { .id = 0x111d76d5, .name = "92HD81B1C5", .patch = patch_stac92hd83xxx},
6267 { .id = 0x111d7666, .name = "92HD88B3", .patch = patch_stac92hd83xxx},
6268 { .id = 0x111d7667, .name = "92HD88B1", .patch = patch_stac92hd83xxx},
6269 { .id = 0x111d7668, .name = "92HD88B2", .patch = patch_stac92hd83xxx},
6270 { .id = 0x111d7669, .name = "92HD88B4", .patch = patch_stac92hd83xxx},
6271 { .id = 0x111d7608, .name = "92HD75B2X5", .patch = patch_stac92hd71bxx},
6272 { .id = 0x111d7674, .name = "92HD73D1X5", .patch = patch_stac92hd73xx },
6273 { .id = 0x111d7675, .name = "92HD73C1X5", .patch = patch_stac92hd73xx },
6274 { .id = 0x111d7676, .name = "92HD73E1X5", .patch = patch_stac92hd73xx },
6275 { .id = 0x111d76b0, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
6276 { .id = 0x111d76b1, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
6277 { .id = 0x111d76b2, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
6278 { .id = 0x111d76b3, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
6279 { .id = 0x111d76b4, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
6280 { .id = 0x111d76b5, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
6281 { .id = 0x111d76b6, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
6282 { .id = 0x111d76b7, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
6283 {} /* terminator */
6286 MODULE_ALIAS("snd-hda-codec-id:8384*");
6287 MODULE_ALIAS("snd-hda-codec-id:111d*");
6289 MODULE_LICENSE("GPL");
6290 MODULE_DESCRIPTION("IDT/Sigmatel HD-audio codec");
6292 static struct hda_codec_preset_list sigmatel_list = {
6293 .preset = snd_hda_preset_sigmatel,
6294 .owner = THIS_MODULE,
6297 static int __init patch_sigmatel_init(void)
6299 return snd_hda_add_codec_preset(&sigmatel_list);
6302 static void __exit patch_sigmatel_exit(void)
6304 snd_hda_delete_codec_preset(&sigmatel_list);
6307 module_init(patch_sigmatel_init)
6308 module_exit(patch_sigmatel_exit)