ALSA: hda - Fix beep frequency on IDT 92HD73xx and 92HD71Bxx codecs
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / sound / pci / hda / patch_sigmatel.c
blobb8d730c47df1099ded7f9087616a0244d64f522e
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;
205 unsigned int linear_tone_beep:1;
207 /* gpio lines */
208 unsigned int eapd_mask;
209 unsigned int gpio_mask;
210 unsigned int gpio_dir;
211 unsigned int gpio_data;
212 unsigned int gpio_mute;
213 unsigned int gpio_led;
214 unsigned int gpio_led_polarity;
216 /* stream */
217 unsigned int stream_delay;
219 /* analog loopback */
220 struct snd_kcontrol_new *aloopback_ctl;
221 unsigned char aloopback_mask;
222 unsigned char aloopback_shift;
224 /* power management */
225 unsigned int num_pwrs;
226 unsigned int *pwr_mapping;
227 hda_nid_t *pwr_nids;
228 hda_nid_t *dac_list;
230 /* jack detection */
231 struct snd_array jacks;
233 /* events */
234 struct snd_array events;
236 /* playback */
237 struct hda_input_mux *mono_mux;
238 unsigned int cur_mmux;
239 struct hda_multi_out multiout;
240 hda_nid_t dac_nids[5];
241 hda_nid_t hp_dacs[5];
242 hda_nid_t speaker_dacs[5];
244 int volume_offset;
246 /* capture */
247 hda_nid_t *adc_nids;
248 unsigned int num_adcs;
249 hda_nid_t *mux_nids;
250 unsigned int num_muxes;
251 hda_nid_t *dmic_nids;
252 unsigned int num_dmics;
253 hda_nid_t *dmux_nids;
254 unsigned int num_dmuxes;
255 hda_nid_t *smux_nids;
256 unsigned int num_smuxes;
257 unsigned int num_analog_muxes;
259 unsigned long *capvols; /* amp-volume attr: HDA_COMPOSE_AMP_VAL() */
260 unsigned long *capsws; /* amp-mute attr: HDA_COMPOSE_AMP_VAL() */
261 unsigned int num_caps; /* number of capture volume/switch elements */
263 struct sigmatel_mic_route ext_mic;
264 struct sigmatel_mic_route int_mic;
266 const char **spdif_labels;
268 hda_nid_t dig_in_nid;
269 hda_nid_t mono_nid;
270 hda_nid_t anabeep_nid;
271 hda_nid_t digbeep_nid;
273 /* pin widgets */
274 hda_nid_t *pin_nids;
275 unsigned int num_pins;
277 /* codec specific stuff */
278 struct hda_verb *init;
279 struct snd_kcontrol_new *mixer;
281 /* capture source */
282 struct hda_input_mux *dinput_mux;
283 unsigned int cur_dmux[2];
284 struct hda_input_mux *input_mux;
285 unsigned int cur_mux[3];
286 struct hda_input_mux *sinput_mux;
287 unsigned int cur_smux[2];
288 unsigned int cur_amux;
289 hda_nid_t *amp_nids;
290 unsigned int powerdown_adcs;
292 /* i/o switches */
293 unsigned int io_switch[2];
294 unsigned int clfe_swap;
295 hda_nid_t line_switch; /* shared line-in for input and output */
296 hda_nid_t mic_switch; /* shared mic-in for input and output */
297 hda_nid_t hp_switch; /* NID of HP as line-out */
298 unsigned int aloopback;
300 struct hda_pcm pcm_rec[2]; /* PCM information */
302 /* dynamic controls and input_mux */
303 struct auto_pin_cfg autocfg;
304 struct snd_array kctls;
305 struct hda_input_mux private_dimux;
306 struct hda_input_mux private_imux;
307 struct hda_input_mux private_smux;
308 struct hda_input_mux private_mono_mux;
311 static hda_nid_t stac9200_adc_nids[1] = {
312 0x03,
315 static hda_nid_t stac9200_mux_nids[1] = {
316 0x0c,
319 static hda_nid_t stac9200_dac_nids[1] = {
320 0x02,
323 static hda_nid_t stac92hd73xx_pwr_nids[8] = {
324 0x0a, 0x0b, 0x0c, 0xd, 0x0e,
325 0x0f, 0x10, 0x11
328 static hda_nid_t stac92hd73xx_slave_dig_outs[2] = {
329 0x26, 0,
332 static hda_nid_t stac92hd73xx_adc_nids[2] = {
333 0x1a, 0x1b
336 #define STAC92HD73XX_NUM_DMICS 2
337 static hda_nid_t stac92hd73xx_dmic_nids[STAC92HD73XX_NUM_DMICS + 1] = {
338 0x13, 0x14, 0
341 #define STAC92HD73_DAC_COUNT 5
343 static hda_nid_t stac92hd73xx_mux_nids[2] = {
344 0x20, 0x21,
347 static hda_nid_t stac92hd73xx_dmux_nids[2] = {
348 0x20, 0x21,
351 static hda_nid_t stac92hd73xx_smux_nids[2] = {
352 0x22, 0x23,
355 #define STAC92HD73XX_NUM_CAPS 2
356 static unsigned long stac92hd73xx_capvols[] = {
357 HDA_COMPOSE_AMP_VAL(0x20, 3, 0, HDA_OUTPUT),
358 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
360 #define stac92hd73xx_capsws stac92hd73xx_capvols
362 #define STAC92HD83_DAC_COUNT 3
364 static hda_nid_t stac92hd83xxx_mux_nids[2] = {
365 0x17, 0x18,
368 static hda_nid_t stac92hd83xxx_adc_nids[2] = {
369 0x15, 0x16,
372 static hda_nid_t stac92hd83xxx_pwr_nids[4] = {
373 0xa, 0xb, 0xd, 0xe,
376 static hda_nid_t stac92hd83xxx_slave_dig_outs[2] = {
377 0x1e, 0,
380 static unsigned int stac92hd83xxx_pwr_mapping[4] = {
381 0x03, 0x0c, 0x20, 0x40,
384 #define STAC92HD83XXX_NUM_CAPS 2
385 static unsigned long stac92hd83xxx_capvols[] = {
386 HDA_COMPOSE_AMP_VAL(0x17, 3, 0, HDA_OUTPUT),
387 HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_OUTPUT),
389 #define stac92hd83xxx_capsws stac92hd83xxx_capvols
391 static hda_nid_t stac92hd71bxx_pwr_nids[3] = {
392 0x0a, 0x0d, 0x0f
395 static hda_nid_t stac92hd71bxx_adc_nids[2] = {
396 0x12, 0x13,
399 static hda_nid_t stac92hd71bxx_mux_nids[2] = {
400 0x1a, 0x1b
403 static hda_nid_t stac92hd71bxx_dmux_nids[2] = {
404 0x1c, 0x1d,
407 static hda_nid_t stac92hd71bxx_smux_nids[2] = {
408 0x24, 0x25,
411 #define STAC92HD71BXX_NUM_DMICS 2
412 static hda_nid_t stac92hd71bxx_dmic_nids[STAC92HD71BXX_NUM_DMICS + 1] = {
413 0x18, 0x19, 0
416 static hda_nid_t stac92hd71bxx_slave_dig_outs[2] = {
417 0x22, 0
420 #define STAC92HD71BXX_NUM_CAPS 2
421 static unsigned long stac92hd71bxx_capvols[] = {
422 HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_OUTPUT),
423 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
425 #define stac92hd71bxx_capsws stac92hd71bxx_capvols
427 static hda_nid_t stac925x_adc_nids[1] = {
428 0x03,
431 static hda_nid_t stac925x_mux_nids[1] = {
432 0x0f,
435 static hda_nid_t stac925x_dac_nids[1] = {
436 0x02,
439 #define STAC925X_NUM_DMICS 1
440 static hda_nid_t stac925x_dmic_nids[STAC925X_NUM_DMICS + 1] = {
441 0x15, 0
444 static hda_nid_t stac925x_dmux_nids[1] = {
445 0x14,
448 static unsigned long stac925x_capvols[] = {
449 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_OUTPUT),
451 static unsigned long stac925x_capsws[] = {
452 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
455 static hda_nid_t stac922x_adc_nids[2] = {
456 0x06, 0x07,
459 static hda_nid_t stac922x_mux_nids[2] = {
460 0x12, 0x13,
463 #define STAC922X_NUM_CAPS 2
464 static unsigned long stac922x_capvols[] = {
465 HDA_COMPOSE_AMP_VAL(0x17, 3, 0, HDA_INPUT),
466 HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_INPUT),
468 #define stac922x_capsws stac922x_capvols
470 static hda_nid_t stac927x_slave_dig_outs[2] = {
471 0x1f, 0,
474 static hda_nid_t stac927x_adc_nids[3] = {
475 0x07, 0x08, 0x09
478 static hda_nid_t stac927x_mux_nids[3] = {
479 0x15, 0x16, 0x17
482 static hda_nid_t stac927x_smux_nids[1] = {
483 0x21,
486 static hda_nid_t stac927x_dac_nids[6] = {
487 0x02, 0x03, 0x04, 0x05, 0x06, 0
490 static hda_nid_t stac927x_dmux_nids[1] = {
491 0x1b,
494 #define STAC927X_NUM_DMICS 2
495 static hda_nid_t stac927x_dmic_nids[STAC927X_NUM_DMICS + 1] = {
496 0x13, 0x14, 0
499 #define STAC927X_NUM_CAPS 3
500 static unsigned long stac927x_capvols[] = {
501 HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_INPUT),
502 HDA_COMPOSE_AMP_VAL(0x19, 3, 0, HDA_INPUT),
503 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_INPUT),
505 static unsigned long stac927x_capsws[] = {
506 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
507 HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_OUTPUT),
508 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
511 static const char *stac927x_spdif_labels[5] = {
512 "Digital Playback", "ADAT", "Analog Mux 1",
513 "Analog Mux 2", "Analog Mux 3"
516 static hda_nid_t stac9205_adc_nids[2] = {
517 0x12, 0x13
520 static hda_nid_t stac9205_mux_nids[2] = {
521 0x19, 0x1a
524 static hda_nid_t stac9205_dmux_nids[1] = {
525 0x1d,
528 static hda_nid_t stac9205_smux_nids[1] = {
529 0x21,
532 #define STAC9205_NUM_DMICS 2
533 static hda_nid_t stac9205_dmic_nids[STAC9205_NUM_DMICS + 1] = {
534 0x17, 0x18, 0
537 #define STAC9205_NUM_CAPS 2
538 static unsigned long stac9205_capvols[] = {
539 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_INPUT),
540 HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_INPUT),
542 static unsigned long stac9205_capsws[] = {
543 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
544 HDA_COMPOSE_AMP_VAL(0x1e, 3, 0, HDA_OUTPUT),
547 static hda_nid_t stac9200_pin_nids[8] = {
548 0x08, 0x09, 0x0d, 0x0e,
549 0x0f, 0x10, 0x11, 0x12,
552 static hda_nid_t stac925x_pin_nids[8] = {
553 0x07, 0x08, 0x0a, 0x0b,
554 0x0c, 0x0d, 0x10, 0x11,
557 static hda_nid_t stac922x_pin_nids[10] = {
558 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
559 0x0f, 0x10, 0x11, 0x15, 0x1b,
562 static hda_nid_t stac92hd73xx_pin_nids[13] = {
563 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
564 0x0f, 0x10, 0x11, 0x12, 0x13,
565 0x14, 0x22, 0x23
568 static hda_nid_t stac92hd83xxx_pin_nids[10] = {
569 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
570 0x0f, 0x10, 0x11, 0x1f, 0x20,
573 static hda_nid_t stac92hd88xxx_pin_nids[10] = {
574 0x0a, 0x0b, 0x0c, 0x0d,
575 0x0f, 0x11, 0x1f, 0x20,
578 #define STAC92HD71BXX_NUM_PINS 13
579 static hda_nid_t stac92hd71bxx_pin_nids_4port[STAC92HD71BXX_NUM_PINS] = {
580 0x0a, 0x0b, 0x0c, 0x0d, 0x00,
581 0x00, 0x14, 0x18, 0x19, 0x1e,
582 0x1f, 0x20, 0x27
584 static hda_nid_t stac92hd71bxx_pin_nids_6port[STAC92HD71BXX_NUM_PINS] = {
585 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
586 0x0f, 0x14, 0x18, 0x19, 0x1e,
587 0x1f, 0x20, 0x27
590 static hda_nid_t stac927x_pin_nids[14] = {
591 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
592 0x0f, 0x10, 0x11, 0x12, 0x13,
593 0x14, 0x21, 0x22, 0x23,
596 static hda_nid_t stac9205_pin_nids[12] = {
597 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
598 0x0f, 0x14, 0x16, 0x17, 0x18,
599 0x21, 0x22,
602 static int stac92xx_dmux_enum_info(struct snd_kcontrol *kcontrol,
603 struct snd_ctl_elem_info *uinfo)
605 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
606 struct sigmatel_spec *spec = codec->spec;
607 return snd_hda_input_mux_info(spec->dinput_mux, uinfo);
610 static int stac92xx_dmux_enum_get(struct snd_kcontrol *kcontrol,
611 struct snd_ctl_elem_value *ucontrol)
613 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
614 struct sigmatel_spec *spec = codec->spec;
615 unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
617 ucontrol->value.enumerated.item[0] = spec->cur_dmux[dmux_idx];
618 return 0;
621 static int stac92xx_dmux_enum_put(struct snd_kcontrol *kcontrol,
622 struct snd_ctl_elem_value *ucontrol)
624 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
625 struct sigmatel_spec *spec = codec->spec;
626 unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
628 return snd_hda_input_mux_put(codec, spec->dinput_mux, ucontrol,
629 spec->dmux_nids[dmux_idx], &spec->cur_dmux[dmux_idx]);
632 static int stac92xx_smux_enum_info(struct snd_kcontrol *kcontrol,
633 struct snd_ctl_elem_info *uinfo)
635 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
636 struct sigmatel_spec *spec = codec->spec;
637 return snd_hda_input_mux_info(spec->sinput_mux, uinfo);
640 static int stac92xx_smux_enum_get(struct snd_kcontrol *kcontrol,
641 struct snd_ctl_elem_value *ucontrol)
643 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
644 struct sigmatel_spec *spec = codec->spec;
645 unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
647 ucontrol->value.enumerated.item[0] = spec->cur_smux[smux_idx];
648 return 0;
651 static int stac92xx_smux_enum_put(struct snd_kcontrol *kcontrol,
652 struct snd_ctl_elem_value *ucontrol)
654 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
655 struct sigmatel_spec *spec = codec->spec;
656 struct hda_input_mux *smux = &spec->private_smux;
657 unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
658 int err, val;
659 hda_nid_t nid;
661 err = snd_hda_input_mux_put(codec, spec->sinput_mux, ucontrol,
662 spec->smux_nids[smux_idx], &spec->cur_smux[smux_idx]);
663 if (err < 0)
664 return err;
666 if (spec->spdif_mute) {
667 if (smux_idx == 0)
668 nid = spec->multiout.dig_out_nid;
669 else
670 nid = codec->slave_dig_outs[smux_idx - 1];
671 if (spec->cur_smux[smux_idx] == smux->num_items - 1)
672 val = HDA_AMP_MUTE;
673 else
674 val = 0;
675 /* un/mute SPDIF out */
676 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
677 HDA_AMP_MUTE, val);
679 return 0;
682 static unsigned int stac92xx_vref_set(struct hda_codec *codec,
683 hda_nid_t nid, unsigned int new_vref)
685 int error;
686 unsigned int pincfg;
687 pincfg = snd_hda_codec_read(codec, nid, 0,
688 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
690 pincfg &= 0xff;
691 pincfg &= ~(AC_PINCTL_VREFEN | AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
692 pincfg |= new_vref;
694 if (new_vref == AC_PINCTL_VREF_HIZ)
695 pincfg |= AC_PINCTL_OUT_EN;
696 else
697 pincfg |= AC_PINCTL_IN_EN;
699 error = snd_hda_codec_write_cache(codec, nid, 0,
700 AC_VERB_SET_PIN_WIDGET_CONTROL, pincfg);
701 if (error < 0)
702 return error;
703 else
704 return 1;
707 static unsigned int stac92xx_vref_get(struct hda_codec *codec, hda_nid_t nid)
709 unsigned int vref;
710 vref = snd_hda_codec_read(codec, nid, 0,
711 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
712 vref &= AC_PINCTL_VREFEN;
713 return vref;
716 static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
718 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
719 struct sigmatel_spec *spec = codec->spec;
720 return snd_hda_input_mux_info(spec->input_mux, uinfo);
723 static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
725 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
726 struct sigmatel_spec *spec = codec->spec;
727 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
729 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
730 return 0;
733 static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
735 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
736 struct sigmatel_spec *spec = codec->spec;
737 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
738 const struct hda_input_mux *imux = spec->input_mux;
739 unsigned int idx, prev_idx;
741 idx = ucontrol->value.enumerated.item[0];
742 if (idx >= imux->num_items)
743 idx = imux->num_items - 1;
744 prev_idx = spec->cur_mux[adc_idx];
745 if (prev_idx == idx)
746 return 0;
747 if (idx < spec->num_analog_muxes) {
748 snd_hda_codec_write_cache(codec, spec->mux_nids[adc_idx], 0,
749 AC_VERB_SET_CONNECT_SEL,
750 imux->items[idx].index);
751 if (prev_idx >= spec->num_analog_muxes) {
752 imux = spec->dinput_mux;
753 /* 0 = analog */
754 snd_hda_codec_write_cache(codec,
755 spec->dmux_nids[adc_idx], 0,
756 AC_VERB_SET_CONNECT_SEL,
757 imux->items[0].index);
759 } else {
760 imux = spec->dinput_mux;
761 snd_hda_codec_write_cache(codec, spec->dmux_nids[adc_idx], 0,
762 AC_VERB_SET_CONNECT_SEL,
763 imux->items[idx - 1].index);
765 spec->cur_mux[adc_idx] = idx;
766 return 1;
769 static int stac92xx_mono_mux_enum_info(struct snd_kcontrol *kcontrol,
770 struct snd_ctl_elem_info *uinfo)
772 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
773 struct sigmatel_spec *spec = codec->spec;
774 return snd_hda_input_mux_info(spec->mono_mux, uinfo);
777 static int stac92xx_mono_mux_enum_get(struct snd_kcontrol *kcontrol,
778 struct snd_ctl_elem_value *ucontrol)
780 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
781 struct sigmatel_spec *spec = codec->spec;
783 ucontrol->value.enumerated.item[0] = spec->cur_mmux;
784 return 0;
787 static int stac92xx_mono_mux_enum_put(struct snd_kcontrol *kcontrol,
788 struct snd_ctl_elem_value *ucontrol)
790 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
791 struct sigmatel_spec *spec = codec->spec;
793 return snd_hda_input_mux_put(codec, spec->mono_mux, ucontrol,
794 spec->mono_nid, &spec->cur_mmux);
797 #define stac92xx_aloopback_info snd_ctl_boolean_mono_info
799 static int stac92xx_aloopback_get(struct snd_kcontrol *kcontrol,
800 struct snd_ctl_elem_value *ucontrol)
802 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
803 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
804 struct sigmatel_spec *spec = codec->spec;
806 ucontrol->value.integer.value[0] = !!(spec->aloopback &
807 (spec->aloopback_mask << idx));
808 return 0;
811 static int stac92xx_aloopback_put(struct snd_kcontrol *kcontrol,
812 struct snd_ctl_elem_value *ucontrol)
814 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
815 struct sigmatel_spec *spec = codec->spec;
816 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
817 unsigned int dac_mode;
818 unsigned int val, idx_val;
820 idx_val = spec->aloopback_mask << idx;
821 if (ucontrol->value.integer.value[0])
822 val = spec->aloopback | idx_val;
823 else
824 val = spec->aloopback & ~idx_val;
825 if (spec->aloopback == val)
826 return 0;
828 spec->aloopback = val;
830 /* Only return the bits defined by the shift value of the
831 * first two bytes of the mask
833 dac_mode = snd_hda_codec_read(codec, codec->afg, 0,
834 kcontrol->private_value & 0xFFFF, 0x0);
835 dac_mode >>= spec->aloopback_shift;
837 if (spec->aloopback & idx_val) {
838 snd_hda_power_up(codec);
839 dac_mode |= idx_val;
840 } else {
841 snd_hda_power_down(codec);
842 dac_mode &= ~idx_val;
845 snd_hda_codec_write_cache(codec, codec->afg, 0,
846 kcontrol->private_value >> 16, dac_mode);
848 return 1;
851 static struct hda_verb stac9200_core_init[] = {
852 /* set dac0mux for dac converter */
853 { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
857 static struct hda_verb stac9200_eapd_init[] = {
858 /* set dac0mux for dac converter */
859 {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
860 {0x08, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
864 static struct hda_verb dell_eq_core_init[] = {
865 /* set master volume to max value without distortion
866 * and direct control */
867 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xec},
871 static struct hda_verb stac92hd73xx_core_init[] = {
872 /* set master volume and direct control */
873 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
877 static struct hda_verb stac92hd83xxx_core_init[] = {
878 /* power state controls amps */
879 { 0x01, AC_VERB_SET_EAPD, 1 << 2},
883 static struct hda_verb stac92hd71bxx_core_init[] = {
884 /* set master volume and direct control */
885 { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
889 static struct hda_verb stac92hd71bxx_unmute_core_init[] = {
890 /* unmute right and left channels for nodes 0x0f, 0xa, 0x0d */
891 { 0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
892 { 0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
893 { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
897 static struct hda_verb stac925x_core_init[] = {
898 /* set dac0mux for dac converter */
899 { 0x06, AC_VERB_SET_CONNECT_SEL, 0x00},
900 /* mute the master volume */
901 { 0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
905 static struct hda_verb stac922x_core_init[] = {
906 /* set master volume and direct control */
907 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
911 static struct hda_verb d965_core_init[] = {
912 /* set master volume and direct control */
913 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
914 /* unmute node 0x1b */
915 { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
916 /* select node 0x03 as DAC */
917 { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
921 static struct hda_verb dell_3st_core_init[] = {
922 /* don't set delta bit */
923 {0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0x7f},
924 /* unmute node 0x1b */
925 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
926 /* select node 0x03 as DAC */
927 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
931 static struct hda_verb stac927x_core_init[] = {
932 /* set master volume and direct control */
933 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
934 /* enable analog pc beep path */
935 { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
939 static struct hda_verb stac927x_volknob_core_init[] = {
940 /* don't set delta bit */
941 {0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0x7f},
942 /* enable analog pc beep path */
943 {0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
947 static struct hda_verb stac9205_core_init[] = {
948 /* set master volume and direct control */
949 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
950 /* enable analog pc beep path */
951 { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
955 #define STAC_MONO_MUX \
957 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
958 .name = "Mono Mux", \
959 .count = 1, \
960 .info = stac92xx_mono_mux_enum_info, \
961 .get = stac92xx_mono_mux_enum_get, \
962 .put = stac92xx_mono_mux_enum_put, \
965 #define STAC_ANALOG_LOOPBACK(verb_read, verb_write, cnt) \
967 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
968 .name = "Analog Loopback", \
969 .count = cnt, \
970 .info = stac92xx_aloopback_info, \
971 .get = stac92xx_aloopback_get, \
972 .put = stac92xx_aloopback_put, \
973 .private_value = verb_read | (verb_write << 16), \
976 #define DC_BIAS(xname, idx, nid) \
978 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
979 .name = xname, \
980 .index = idx, \
981 .info = stac92xx_dc_bias_info, \
982 .get = stac92xx_dc_bias_get, \
983 .put = stac92xx_dc_bias_put, \
984 .private_value = nid, \
987 static struct snd_kcontrol_new stac9200_mixer[] = {
988 HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
989 HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
990 HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
991 HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
992 { } /* end */
995 static struct snd_kcontrol_new stac92hd73xx_6ch_loopback[] = {
996 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 3),
1000 static struct snd_kcontrol_new stac92hd73xx_8ch_loopback[] = {
1001 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 4),
1005 static struct snd_kcontrol_new stac92hd73xx_10ch_loopback[] = {
1006 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 5),
1011 static struct snd_kcontrol_new stac92hd71bxx_loopback[] = {
1012 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A0, 2)
1015 static struct snd_kcontrol_new stac925x_mixer[] = {
1016 HDA_CODEC_VOLUME("Master Playback Volume", 0x0e, 0, HDA_OUTPUT),
1017 HDA_CODEC_MUTE("Master Playback Switch", 0x0e, 0, HDA_OUTPUT),
1018 { } /* end */
1021 static struct snd_kcontrol_new stac9205_loopback[] = {
1022 STAC_ANALOG_LOOPBACK(0xFE0, 0x7E0, 1),
1026 static struct snd_kcontrol_new stac927x_loopback[] = {
1027 STAC_ANALOG_LOOPBACK(0xFEB, 0x7EB, 1),
1031 static struct snd_kcontrol_new stac_dmux_mixer = {
1032 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1033 .name = "Digital Input Source",
1034 /* count set later */
1035 .info = stac92xx_dmux_enum_info,
1036 .get = stac92xx_dmux_enum_get,
1037 .put = stac92xx_dmux_enum_put,
1040 static struct snd_kcontrol_new stac_smux_mixer = {
1041 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1042 .name = "IEC958 Playback Source",
1043 /* count set later */
1044 .info = stac92xx_smux_enum_info,
1045 .get = stac92xx_smux_enum_get,
1046 .put = stac92xx_smux_enum_put,
1049 static const char *slave_vols[] = {
1050 "Front Playback Volume",
1051 "Surround Playback Volume",
1052 "Center Playback Volume",
1053 "LFE Playback Volume",
1054 "Side Playback Volume",
1055 "Headphone Playback Volume",
1056 "Speaker Playback Volume",
1057 NULL
1060 static const char *slave_sws[] = {
1061 "Front Playback Switch",
1062 "Surround Playback Switch",
1063 "Center Playback Switch",
1064 "LFE Playback Switch",
1065 "Side Playback Switch",
1066 "Headphone Playback Switch",
1067 "Speaker Playback Switch",
1068 "IEC958 Playback Switch",
1069 NULL
1072 static void stac92xx_free_kctls(struct hda_codec *codec);
1073 static int stac92xx_add_jack(struct hda_codec *codec, hda_nid_t nid, int type);
1075 static int stac92xx_build_controls(struct hda_codec *codec)
1077 struct sigmatel_spec *spec = codec->spec;
1078 struct auto_pin_cfg *cfg = &spec->autocfg;
1079 hda_nid_t nid;
1080 int err;
1081 int i;
1083 if (spec->mixer) {
1084 err = snd_hda_add_new_ctls(codec, spec->mixer);
1085 if (err < 0)
1086 return err;
1089 for (i = 0; i < spec->num_mixers; i++) {
1090 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1091 if (err < 0)
1092 return err;
1094 if (!spec->auto_mic && spec->num_dmuxes > 0 &&
1095 snd_hda_get_bool_hint(codec, "separate_dmux") == 1) {
1096 stac_dmux_mixer.count = spec->num_dmuxes;
1097 err = snd_hda_ctl_add(codec, 0,
1098 snd_ctl_new1(&stac_dmux_mixer, codec));
1099 if (err < 0)
1100 return err;
1102 if (spec->num_smuxes > 0) {
1103 int wcaps = get_wcaps(codec, spec->multiout.dig_out_nid);
1104 struct hda_input_mux *smux = &spec->private_smux;
1105 /* check for mute support on SPDIF out */
1106 if (wcaps & AC_WCAP_OUT_AMP) {
1107 smux->items[smux->num_items].label = "Off";
1108 smux->items[smux->num_items].index = 0;
1109 smux->num_items++;
1110 spec->spdif_mute = 1;
1112 stac_smux_mixer.count = spec->num_smuxes;
1113 err = snd_hda_ctl_add(codec, 0,
1114 snd_ctl_new1(&stac_smux_mixer, codec));
1115 if (err < 0)
1116 return err;
1119 if (spec->multiout.dig_out_nid) {
1120 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
1121 if (err < 0)
1122 return err;
1123 err = snd_hda_create_spdif_share_sw(codec,
1124 &spec->multiout);
1125 if (err < 0)
1126 return err;
1127 spec->multiout.share_spdif = 1;
1129 if (spec->dig_in_nid && !(spec->gpio_dir & 0x01)) {
1130 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1131 if (err < 0)
1132 return err;
1135 /* if we have no master control, let's create it */
1136 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
1137 unsigned int vmaster_tlv[4];
1138 snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0],
1139 HDA_OUTPUT, vmaster_tlv);
1140 /* correct volume offset */
1141 vmaster_tlv[2] += vmaster_tlv[3] * spec->volume_offset;
1142 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
1143 vmaster_tlv, slave_vols);
1144 if (err < 0)
1145 return err;
1147 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1148 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1149 NULL, slave_sws);
1150 if (err < 0)
1151 return err;
1154 if (spec->aloopback_ctl &&
1155 snd_hda_get_bool_hint(codec, "loopback") == 1) {
1156 err = snd_hda_add_new_ctls(codec, spec->aloopback_ctl);
1157 if (err < 0)
1158 return err;
1161 stac92xx_free_kctls(codec); /* no longer needed */
1163 /* create jack input elements */
1164 if (spec->hp_detect) {
1165 for (i = 0; i < cfg->hp_outs; i++) {
1166 int type = SND_JACK_HEADPHONE;
1167 nid = cfg->hp_pins[i];
1168 /* jack detection */
1169 if (cfg->hp_outs == i)
1170 type |= SND_JACK_LINEOUT;
1171 err = stac92xx_add_jack(codec, nid, type);
1172 if (err < 0)
1173 return err;
1176 for (i = 0; i < cfg->line_outs; i++) {
1177 err = stac92xx_add_jack(codec, cfg->line_out_pins[i],
1178 SND_JACK_LINEOUT);
1179 if (err < 0)
1180 return err;
1182 for (i = 0; i < AUTO_PIN_LAST; i++) {
1183 nid = cfg->input_pins[i];
1184 if (nid) {
1185 err = stac92xx_add_jack(codec, nid,
1186 SND_JACK_MICROPHONE);
1187 if (err < 0)
1188 return err;
1192 return 0;
1195 static unsigned int ref9200_pin_configs[8] = {
1196 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
1197 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
1200 static unsigned int gateway9200_m4_pin_configs[8] = {
1201 0x400000fe, 0x404500f4, 0x400100f0, 0x90110010,
1202 0x400100f1, 0x02a1902e, 0x500000f2, 0x500000f3,
1204 static unsigned int gateway9200_m4_2_pin_configs[8] = {
1205 0x400000fe, 0x404500f4, 0x400100f0, 0x90110010,
1206 0x400100f1, 0x02a1902e, 0x500000f2, 0x500000f3,
1210 STAC 9200 pin configs for
1211 102801A8
1212 102801DE
1213 102801E8
1215 static unsigned int dell9200_d21_pin_configs[8] = {
1216 0x400001f0, 0x400001f1, 0x02214030, 0x01014010,
1217 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
1221 STAC 9200 pin configs for
1222 102801C0
1223 102801C1
1225 static unsigned int dell9200_d22_pin_configs[8] = {
1226 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
1227 0x01813020, 0x02a19021, 0x90100140, 0x400001f2,
1231 STAC 9200 pin configs for
1232 102801C4 (Dell Dimension E310)
1233 102801C5
1234 102801C7
1235 102801D9
1236 102801DA
1237 102801E3
1239 static unsigned int dell9200_d23_pin_configs[8] = {
1240 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
1241 0x01813020, 0x01a19021, 0x90100140, 0x400001f2,
1246 STAC 9200-32 pin configs for
1247 102801B5 (Dell Inspiron 630m)
1248 102801D8 (Dell Inspiron 640m)
1250 static unsigned int dell9200_m21_pin_configs[8] = {
1251 0x40c003fa, 0x03441340, 0x0321121f, 0x90170310,
1252 0x408003fb, 0x03a11020, 0x401003fc, 0x403003fd,
1256 STAC 9200-32 pin configs for
1257 102801C2 (Dell Latitude D620)
1258 102801C8
1259 102801CC (Dell Latitude D820)
1260 102801D4
1261 102801D6
1263 static unsigned int dell9200_m22_pin_configs[8] = {
1264 0x40c003fa, 0x0144131f, 0x0321121f, 0x90170310,
1265 0x90a70321, 0x03a11020, 0x401003fb, 0x40f000fc,
1269 STAC 9200-32 pin configs for
1270 102801CE (Dell XPS M1710)
1271 102801CF (Dell Precision M90)
1273 static unsigned int dell9200_m23_pin_configs[8] = {
1274 0x40c003fa, 0x01441340, 0x0421421f, 0x90170310,
1275 0x408003fb, 0x04a1102e, 0x90170311, 0x403003fc,
1279 STAC 9200-32 pin configs for
1280 102801C9
1281 102801CA
1282 102801CB (Dell Latitude 120L)
1283 102801D3
1285 static unsigned int dell9200_m24_pin_configs[8] = {
1286 0x40c003fa, 0x404003fb, 0x0321121f, 0x90170310,
1287 0x408003fc, 0x03a11020, 0x401003fd, 0x403003fe,
1291 STAC 9200-32 pin configs for
1292 102801BD (Dell Inspiron E1505n)
1293 102801EE
1294 102801EF
1296 static unsigned int dell9200_m25_pin_configs[8] = {
1297 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
1298 0x408003fb, 0x04a11020, 0x401003fc, 0x403003fd,
1302 STAC 9200-32 pin configs for
1303 102801F5 (Dell Inspiron 1501)
1304 102801F6
1306 static unsigned int dell9200_m26_pin_configs[8] = {
1307 0x40c003fa, 0x404003fb, 0x0421121f, 0x90170310,
1308 0x408003fc, 0x04a11020, 0x401003fd, 0x403003fe,
1312 STAC 9200-32
1313 102801CD (Dell Inspiron E1705/9400)
1315 static unsigned int dell9200_m27_pin_configs[8] = {
1316 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
1317 0x90170310, 0x04a11020, 0x90170310, 0x40f003fc,
1320 static unsigned int oqo9200_pin_configs[8] = {
1321 0x40c000f0, 0x404000f1, 0x0221121f, 0x02211210,
1322 0x90170111, 0x90a70120, 0x400000f2, 0x400000f3,
1326 static unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
1327 [STAC_REF] = ref9200_pin_configs,
1328 [STAC_9200_OQO] = oqo9200_pin_configs,
1329 [STAC_9200_DELL_D21] = dell9200_d21_pin_configs,
1330 [STAC_9200_DELL_D22] = dell9200_d22_pin_configs,
1331 [STAC_9200_DELL_D23] = dell9200_d23_pin_configs,
1332 [STAC_9200_DELL_M21] = dell9200_m21_pin_configs,
1333 [STAC_9200_DELL_M22] = dell9200_m22_pin_configs,
1334 [STAC_9200_DELL_M23] = dell9200_m23_pin_configs,
1335 [STAC_9200_DELL_M24] = dell9200_m24_pin_configs,
1336 [STAC_9200_DELL_M25] = dell9200_m25_pin_configs,
1337 [STAC_9200_DELL_M26] = dell9200_m26_pin_configs,
1338 [STAC_9200_DELL_M27] = dell9200_m27_pin_configs,
1339 [STAC_9200_M4] = gateway9200_m4_pin_configs,
1340 [STAC_9200_M4_2] = gateway9200_m4_2_pin_configs,
1341 [STAC_9200_PANASONIC] = ref9200_pin_configs,
1344 static const char *stac9200_models[STAC_9200_MODELS] = {
1345 [STAC_AUTO] = "auto",
1346 [STAC_REF] = "ref",
1347 [STAC_9200_OQO] = "oqo",
1348 [STAC_9200_DELL_D21] = "dell-d21",
1349 [STAC_9200_DELL_D22] = "dell-d22",
1350 [STAC_9200_DELL_D23] = "dell-d23",
1351 [STAC_9200_DELL_M21] = "dell-m21",
1352 [STAC_9200_DELL_M22] = "dell-m22",
1353 [STAC_9200_DELL_M23] = "dell-m23",
1354 [STAC_9200_DELL_M24] = "dell-m24",
1355 [STAC_9200_DELL_M25] = "dell-m25",
1356 [STAC_9200_DELL_M26] = "dell-m26",
1357 [STAC_9200_DELL_M27] = "dell-m27",
1358 [STAC_9200_M4] = "gateway-m4",
1359 [STAC_9200_M4_2] = "gateway-m4-2",
1360 [STAC_9200_PANASONIC] = "panasonic",
1363 static struct snd_pci_quirk stac9200_cfg_tbl[] = {
1364 /* SigmaTel reference board */
1365 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1366 "DFI LanParty", STAC_REF),
1367 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1368 "DFI LanParty", STAC_REF),
1369 /* Dell laptops have BIOS problem */
1370 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a8,
1371 "unknown Dell", STAC_9200_DELL_D21),
1372 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01b5,
1373 "Dell Inspiron 630m", STAC_9200_DELL_M21),
1374 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bd,
1375 "Dell Inspiron E1505n", STAC_9200_DELL_M25),
1376 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c0,
1377 "unknown Dell", STAC_9200_DELL_D22),
1378 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c1,
1379 "unknown Dell", STAC_9200_DELL_D22),
1380 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c2,
1381 "Dell Latitude D620", STAC_9200_DELL_M22),
1382 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c5,
1383 "unknown Dell", STAC_9200_DELL_D23),
1384 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c7,
1385 "unknown Dell", STAC_9200_DELL_D23),
1386 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c8,
1387 "unknown Dell", STAC_9200_DELL_M22),
1388 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c9,
1389 "unknown Dell", STAC_9200_DELL_M24),
1390 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ca,
1391 "unknown Dell", STAC_9200_DELL_M24),
1392 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cb,
1393 "Dell Latitude 120L", STAC_9200_DELL_M24),
1394 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cc,
1395 "Dell Latitude D820", STAC_9200_DELL_M22),
1396 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cd,
1397 "Dell Inspiron E1705/9400", STAC_9200_DELL_M27),
1398 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ce,
1399 "Dell XPS M1710", STAC_9200_DELL_M23),
1400 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cf,
1401 "Dell Precision M90", STAC_9200_DELL_M23),
1402 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d3,
1403 "unknown Dell", STAC_9200_DELL_M22),
1404 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d4,
1405 "unknown Dell", STAC_9200_DELL_M22),
1406 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d6,
1407 "unknown Dell", STAC_9200_DELL_M22),
1408 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d8,
1409 "Dell Inspiron 640m", STAC_9200_DELL_M21),
1410 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d9,
1411 "unknown Dell", STAC_9200_DELL_D23),
1412 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01da,
1413 "unknown Dell", STAC_9200_DELL_D23),
1414 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01de,
1415 "unknown Dell", STAC_9200_DELL_D21),
1416 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e3,
1417 "unknown Dell", STAC_9200_DELL_D23),
1418 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e8,
1419 "unknown Dell", STAC_9200_DELL_D21),
1420 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ee,
1421 "unknown Dell", STAC_9200_DELL_M25),
1422 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ef,
1423 "unknown Dell", STAC_9200_DELL_M25),
1424 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f5,
1425 "Dell Inspiron 1501", STAC_9200_DELL_M26),
1426 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f6,
1427 "unknown Dell", STAC_9200_DELL_M26),
1428 /* Panasonic */
1429 SND_PCI_QUIRK(0x10f7, 0x8338, "Panasonic CF-74", STAC_9200_PANASONIC),
1430 /* Gateway machines needs EAPD to be set on resume */
1431 SND_PCI_QUIRK(0x107b, 0x0205, "Gateway S-7110M", STAC_9200_M4),
1432 SND_PCI_QUIRK(0x107b, 0x0317, "Gateway MT3423, MX341*", STAC_9200_M4_2),
1433 SND_PCI_QUIRK(0x107b, 0x0318, "Gateway ML3019, MT3707", STAC_9200_M4_2),
1434 /* OQO Mobile */
1435 SND_PCI_QUIRK(0x1106, 0x3288, "OQO Model 2", STAC_9200_OQO),
1436 {} /* terminator */
1439 static unsigned int ref925x_pin_configs[8] = {
1440 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
1441 0x90a70320, 0x02214210, 0x01019020, 0x9033032e,
1444 static unsigned int stac925xM1_pin_configs[8] = {
1445 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1446 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1449 static unsigned int stac925xM1_2_pin_configs[8] = {
1450 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1451 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1454 static unsigned int stac925xM2_pin_configs[8] = {
1455 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1456 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1459 static unsigned int stac925xM2_2_pin_configs[8] = {
1460 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1461 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1464 static unsigned int stac925xM3_pin_configs[8] = {
1465 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1466 0x40a000f0, 0x90100210, 0x400003f1, 0x503303f3,
1469 static unsigned int stac925xM5_pin_configs[8] = {
1470 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1471 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1474 static unsigned int stac925xM6_pin_configs[8] = {
1475 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1476 0x40a000f0, 0x90100210, 0x400003f1, 0x90330320,
1479 static unsigned int *stac925x_brd_tbl[STAC_925x_MODELS] = {
1480 [STAC_REF] = ref925x_pin_configs,
1481 [STAC_M1] = stac925xM1_pin_configs,
1482 [STAC_M1_2] = stac925xM1_2_pin_configs,
1483 [STAC_M2] = stac925xM2_pin_configs,
1484 [STAC_M2_2] = stac925xM2_2_pin_configs,
1485 [STAC_M3] = stac925xM3_pin_configs,
1486 [STAC_M5] = stac925xM5_pin_configs,
1487 [STAC_M6] = stac925xM6_pin_configs,
1490 static const char *stac925x_models[STAC_925x_MODELS] = {
1491 [STAC_925x_AUTO] = "auto",
1492 [STAC_REF] = "ref",
1493 [STAC_M1] = "m1",
1494 [STAC_M1_2] = "m1-2",
1495 [STAC_M2] = "m2",
1496 [STAC_M2_2] = "m2-2",
1497 [STAC_M3] = "m3",
1498 [STAC_M5] = "m5",
1499 [STAC_M6] = "m6",
1502 static struct snd_pci_quirk stac925x_codec_id_cfg_tbl[] = {
1503 SND_PCI_QUIRK(0x107b, 0x0316, "Gateway M255", STAC_M2),
1504 SND_PCI_QUIRK(0x107b, 0x0366, "Gateway MP6954", STAC_M5),
1505 SND_PCI_QUIRK(0x107b, 0x0461, "Gateway NX560XL", STAC_M1),
1506 SND_PCI_QUIRK(0x107b, 0x0681, "Gateway NX860", STAC_M2),
1507 SND_PCI_QUIRK(0x107b, 0x0367, "Gateway MX6453", STAC_M1_2),
1508 /* Not sure about the brand name for those */
1509 SND_PCI_QUIRK(0x107b, 0x0281, "Gateway mobile", STAC_M1),
1510 SND_PCI_QUIRK(0x107b, 0x0507, "Gateway mobile", STAC_M3),
1511 SND_PCI_QUIRK(0x107b, 0x0281, "Gateway mobile", STAC_M6),
1512 SND_PCI_QUIRK(0x107b, 0x0685, "Gateway mobile", STAC_M2_2),
1513 {} /* terminator */
1516 static struct snd_pci_quirk stac925x_cfg_tbl[] = {
1517 /* SigmaTel reference board */
1518 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, "DFI LanParty", STAC_REF),
1519 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101, "DFI LanParty", STAC_REF),
1520 SND_PCI_QUIRK(0x8384, 0x7632, "Stac9202 Reference Board", STAC_REF),
1522 /* Default table for unknown ID */
1523 SND_PCI_QUIRK(0x1002, 0x437b, "Gateway mobile", STAC_M2_2),
1525 {} /* terminator */
1528 static unsigned int ref92hd73xx_pin_configs[13] = {
1529 0x02214030, 0x02a19040, 0x01a19020, 0x02214030,
1530 0x0181302e, 0x01014010, 0x01014020, 0x01014030,
1531 0x02319040, 0x90a000f0, 0x90a000f0, 0x01452050,
1532 0x01452050,
1535 static unsigned int dell_m6_pin_configs[13] = {
1536 0x0321101f, 0x4f00000f, 0x4f0000f0, 0x90170110,
1537 0x03a11020, 0x0321101f, 0x4f0000f0, 0x4f0000f0,
1538 0x4f0000f0, 0x90a60160, 0x4f0000f0, 0x4f0000f0,
1539 0x4f0000f0,
1542 static unsigned int alienware_m17x_pin_configs[13] = {
1543 0x0321101f, 0x0321101f, 0x03a11020, 0x03014020,
1544 0x90170110, 0x4f0000f0, 0x4f0000f0, 0x4f0000f0,
1545 0x4f0000f0, 0x90a60160, 0x4f0000f0, 0x4f0000f0,
1546 0x904601b0,
1549 static unsigned int intel_dg45id_pin_configs[13] = {
1550 0x02214230, 0x02A19240, 0x01013214, 0x01014210,
1551 0x01A19250, 0x01011212, 0x01016211
1554 static unsigned int *stac92hd73xx_brd_tbl[STAC_92HD73XX_MODELS] = {
1555 [STAC_92HD73XX_REF] = ref92hd73xx_pin_configs,
1556 [STAC_DELL_M6_AMIC] = dell_m6_pin_configs,
1557 [STAC_DELL_M6_DMIC] = dell_m6_pin_configs,
1558 [STAC_DELL_M6_BOTH] = dell_m6_pin_configs,
1559 [STAC_DELL_EQ] = dell_m6_pin_configs,
1560 [STAC_ALIENWARE_M17X] = alienware_m17x_pin_configs,
1561 [STAC_92HD73XX_INTEL] = intel_dg45id_pin_configs,
1564 static const char *stac92hd73xx_models[STAC_92HD73XX_MODELS] = {
1565 [STAC_92HD73XX_AUTO] = "auto",
1566 [STAC_92HD73XX_NO_JD] = "no-jd",
1567 [STAC_92HD73XX_REF] = "ref",
1568 [STAC_92HD73XX_INTEL] = "intel",
1569 [STAC_DELL_M6_AMIC] = "dell-m6-amic",
1570 [STAC_DELL_M6_DMIC] = "dell-m6-dmic",
1571 [STAC_DELL_M6_BOTH] = "dell-m6",
1572 [STAC_DELL_EQ] = "dell-eq",
1573 [STAC_ALIENWARE_M17X] = "alienware",
1576 static struct snd_pci_quirk stac92hd73xx_cfg_tbl[] = {
1577 /* SigmaTel reference board */
1578 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1579 "DFI LanParty", STAC_92HD73XX_REF),
1580 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1581 "DFI LanParty", STAC_92HD73XX_REF),
1582 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5002,
1583 "Intel DG45ID", STAC_92HD73XX_INTEL),
1584 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5003,
1585 "Intel DG45FC", STAC_92HD73XX_INTEL),
1586 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0254,
1587 "Dell Studio 1535", STAC_DELL_M6_DMIC),
1588 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0255,
1589 "unknown Dell", STAC_DELL_M6_DMIC),
1590 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0256,
1591 "unknown Dell", STAC_DELL_M6_BOTH),
1592 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0257,
1593 "unknown Dell", STAC_DELL_M6_BOTH),
1594 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025e,
1595 "unknown Dell", STAC_DELL_M6_AMIC),
1596 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025f,
1597 "unknown Dell", STAC_DELL_M6_AMIC),
1598 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0271,
1599 "unknown Dell", STAC_DELL_M6_DMIC),
1600 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0272,
1601 "unknown Dell", STAC_DELL_M6_DMIC),
1602 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x029f,
1603 "Dell Studio 1537", STAC_DELL_M6_DMIC),
1604 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02a0,
1605 "Dell Studio 17", STAC_DELL_M6_DMIC),
1606 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02be,
1607 "Dell Studio 1555", STAC_DELL_M6_DMIC),
1608 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02bd,
1609 "Dell Studio 1557", STAC_DELL_M6_DMIC),
1610 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02fe,
1611 "Dell Studio XPS 1645", STAC_DELL_M6_BOTH),
1612 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0413,
1613 "Dell Studio 1558", STAC_DELL_M6_BOTH),
1614 {} /* terminator */
1617 static struct snd_pci_quirk stac92hd73xx_codec_id_cfg_tbl[] = {
1618 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02a1,
1619 "Alienware M17x", STAC_ALIENWARE_M17X),
1620 {} /* terminator */
1623 static unsigned int ref92hd83xxx_pin_configs[10] = {
1624 0x02214030, 0x02211010, 0x02a19020, 0x02170130,
1625 0x01014050, 0x01819040, 0x01014020, 0x90a3014e,
1626 0x01451160, 0x98560170,
1629 static unsigned int dell_s14_pin_configs[10] = {
1630 0x0221403f, 0x0221101f, 0x02a19020, 0x90170110,
1631 0x40f000f0, 0x40f000f0, 0x40f000f0, 0x90a60160,
1632 0x40f000f0, 0x40f000f0,
1635 static unsigned int *stac92hd83xxx_brd_tbl[STAC_92HD83XXX_MODELS] = {
1636 [STAC_92HD83XXX_REF] = ref92hd83xxx_pin_configs,
1637 [STAC_92HD83XXX_PWR_REF] = ref92hd83xxx_pin_configs,
1638 [STAC_DELL_S14] = dell_s14_pin_configs,
1641 static const char *stac92hd83xxx_models[STAC_92HD83XXX_MODELS] = {
1642 [STAC_92HD83XXX_AUTO] = "auto",
1643 [STAC_92HD83XXX_REF] = "ref",
1644 [STAC_92HD83XXX_PWR_REF] = "mic-ref",
1645 [STAC_DELL_S14] = "dell-s14",
1646 [STAC_92HD83XXX_HP] = "hp",
1649 static struct snd_pci_quirk stac92hd83xxx_cfg_tbl[] = {
1650 /* SigmaTel reference board */
1651 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1652 "DFI LanParty", STAC_92HD83XXX_REF),
1653 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1654 "DFI LanParty", STAC_92HD83XXX_REF),
1655 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ba,
1656 "unknown Dell", STAC_DELL_S14),
1657 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xff00, 0x3600,
1658 "HP", STAC_92HD83XXX_HP),
1659 {} /* terminator */
1662 static unsigned int ref92hd71bxx_pin_configs[STAC92HD71BXX_NUM_PINS] = {
1663 0x02214030, 0x02a19040, 0x01a19020, 0x01014010,
1664 0x0181302e, 0x01014010, 0x01019020, 0x90a000f0,
1665 0x90a000f0, 0x01452050, 0x01452050, 0x00000000,
1666 0x00000000
1669 static unsigned int dell_m4_1_pin_configs[STAC92HD71BXX_NUM_PINS] = {
1670 0x0421101f, 0x04a11221, 0x40f000f0, 0x90170110,
1671 0x23a1902e, 0x23014250, 0x40f000f0, 0x90a000f0,
1672 0x40f000f0, 0x4f0000f0, 0x4f0000f0, 0x00000000,
1673 0x00000000
1676 static unsigned int dell_m4_2_pin_configs[STAC92HD71BXX_NUM_PINS] = {
1677 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1678 0x23a1902e, 0x23014250, 0x40f000f0, 0x40f000f0,
1679 0x40f000f0, 0x044413b0, 0x044413b0, 0x00000000,
1680 0x00000000
1683 static unsigned int dell_m4_3_pin_configs[STAC92HD71BXX_NUM_PINS] = {
1684 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1685 0x40f000f0, 0x40f000f0, 0x40f000f0, 0x90a000f0,
1686 0x40f000f0, 0x044413b0, 0x044413b0, 0x00000000,
1687 0x00000000
1690 static unsigned int *stac92hd71bxx_brd_tbl[STAC_92HD71BXX_MODELS] = {
1691 [STAC_92HD71BXX_REF] = ref92hd71bxx_pin_configs,
1692 [STAC_DELL_M4_1] = dell_m4_1_pin_configs,
1693 [STAC_DELL_M4_2] = dell_m4_2_pin_configs,
1694 [STAC_DELL_M4_3] = dell_m4_3_pin_configs,
1695 [STAC_HP_M4] = NULL,
1696 [STAC_HP_DV4] = NULL,
1697 [STAC_HP_DV5] = NULL,
1698 [STAC_HP_HDX] = NULL,
1699 [STAC_HP_DV4_1222NR] = NULL,
1702 static const char *stac92hd71bxx_models[STAC_92HD71BXX_MODELS] = {
1703 [STAC_92HD71BXX_AUTO] = "auto",
1704 [STAC_92HD71BXX_REF] = "ref",
1705 [STAC_DELL_M4_1] = "dell-m4-1",
1706 [STAC_DELL_M4_2] = "dell-m4-2",
1707 [STAC_DELL_M4_3] = "dell-m4-3",
1708 [STAC_HP_M4] = "hp-m4",
1709 [STAC_HP_DV4] = "hp-dv4",
1710 [STAC_HP_DV5] = "hp-dv5",
1711 [STAC_HP_HDX] = "hp-hdx",
1712 [STAC_HP_DV4_1222NR] = "hp-dv4-1222nr",
1715 static struct snd_pci_quirk stac92hd71bxx_cfg_tbl[] = {
1716 /* SigmaTel reference board */
1717 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1718 "DFI LanParty", STAC_92HD71BXX_REF),
1719 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1720 "DFI LanParty", STAC_92HD71BXX_REF),
1721 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x30fb,
1722 "HP dv4-1222nr", STAC_HP_DV4_1222NR),
1723 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x1720,
1724 "HP", STAC_HP_DV5),
1725 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3080,
1726 "HP", STAC_HP_DV5),
1727 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x30f0,
1728 "HP dv4-7", STAC_HP_DV4),
1729 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3600,
1730 "HP dv4-7", STAC_HP_DV5),
1731 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3610,
1732 "HP HDX", STAC_HP_HDX), /* HDX18 */
1733 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361a,
1734 "HP mini 1000", STAC_HP_M4),
1735 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361b,
1736 "HP HDX", STAC_HP_HDX), /* HDX16 */
1737 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3620,
1738 "HP dv6", STAC_HP_DV5),
1739 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3061,
1740 "HP dv6", STAC_HP_DV5), /* HP dv6-1110ax */
1741 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x7010,
1742 "HP", STAC_HP_DV5),
1743 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0233,
1744 "unknown Dell", STAC_DELL_M4_1),
1745 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0234,
1746 "unknown Dell", STAC_DELL_M4_1),
1747 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0250,
1748 "unknown Dell", STAC_DELL_M4_1),
1749 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024f,
1750 "unknown Dell", STAC_DELL_M4_1),
1751 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024d,
1752 "unknown Dell", STAC_DELL_M4_1),
1753 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0251,
1754 "unknown Dell", STAC_DELL_M4_1),
1755 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0277,
1756 "unknown Dell", STAC_DELL_M4_1),
1757 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0263,
1758 "unknown Dell", STAC_DELL_M4_2),
1759 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0265,
1760 "unknown Dell", STAC_DELL_M4_2),
1761 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0262,
1762 "unknown Dell", STAC_DELL_M4_2),
1763 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0264,
1764 "unknown Dell", STAC_DELL_M4_2),
1765 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02aa,
1766 "unknown Dell", STAC_DELL_M4_3),
1767 {} /* terminator */
1770 static unsigned int ref922x_pin_configs[10] = {
1771 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
1772 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
1773 0x40000100, 0x40000100,
1777 STAC 922X pin configs for
1778 102801A7
1779 102801AB
1780 102801A9
1781 102801D1
1782 102801D2
1784 static unsigned int dell_922x_d81_pin_configs[10] = {
1785 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1786 0x02a19020, 0x01117011, 0x400001f0, 0x400001f1,
1787 0x01813122, 0x400001f2,
1791 STAC 922X pin configs for
1792 102801AC
1793 102801D0
1795 static unsigned int dell_922x_d82_pin_configs[10] = {
1796 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1797 0x02a19020, 0x01117011, 0x01451140, 0x400001f0,
1798 0x01813122, 0x400001f1,
1802 STAC 922X pin configs for
1803 102801BF
1805 static unsigned int dell_922x_m81_pin_configs[10] = {
1806 0x0321101f, 0x01112024, 0x01111222, 0x91174220,
1807 0x03a11050, 0x01116221, 0x90a70330, 0x01452340,
1808 0x40C003f1, 0x405003f0,
1812 STAC 9221 A1 pin configs for
1813 102801D7 (Dell XPS M1210)
1815 static unsigned int dell_922x_m82_pin_configs[10] = {
1816 0x02211211, 0x408103ff, 0x02a1123e, 0x90100310,
1817 0x408003f1, 0x0221121f, 0x03451340, 0x40c003f2,
1818 0x508003f3, 0x405003f4,
1821 static unsigned int d945gtp3_pin_configs[10] = {
1822 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
1823 0x40000100, 0x40000100, 0x40000100, 0x40000100,
1824 0x02a19120, 0x40000100,
1827 static unsigned int d945gtp5_pin_configs[10] = {
1828 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
1829 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
1830 0x02a19320, 0x40000100,
1833 static unsigned int intel_mac_v1_pin_configs[10] = {
1834 0x0121e21f, 0x400000ff, 0x9017e110, 0x400000fd,
1835 0x400000fe, 0x0181e020, 0x1145e030, 0x11c5e240,
1836 0x400000fc, 0x400000fb,
1839 static unsigned int intel_mac_v2_pin_configs[10] = {
1840 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
1841 0x400000fe, 0x0181e020, 0x1145e230, 0x500000fa,
1842 0x400000fc, 0x400000fb,
1845 static unsigned int intel_mac_v3_pin_configs[10] = {
1846 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
1847 0x400000fe, 0x0181e020, 0x1145e230, 0x11c5e240,
1848 0x400000fc, 0x400000fb,
1851 static unsigned int intel_mac_v4_pin_configs[10] = {
1852 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
1853 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
1854 0x400000fc, 0x400000fb,
1857 static unsigned int intel_mac_v5_pin_configs[10] = {
1858 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
1859 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
1860 0x400000fc, 0x400000fb,
1863 static unsigned int ecs202_pin_configs[10] = {
1864 0x0221401f, 0x02a19020, 0x01a19020, 0x01114010,
1865 0x408000f0, 0x01813022, 0x074510a0, 0x40c400f1,
1866 0x9037012e, 0x40e000f2,
1869 static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
1870 [STAC_D945_REF] = ref922x_pin_configs,
1871 [STAC_D945GTP3] = d945gtp3_pin_configs,
1872 [STAC_D945GTP5] = d945gtp5_pin_configs,
1873 [STAC_INTEL_MAC_V1] = intel_mac_v1_pin_configs,
1874 [STAC_INTEL_MAC_V2] = intel_mac_v2_pin_configs,
1875 [STAC_INTEL_MAC_V3] = intel_mac_v3_pin_configs,
1876 [STAC_INTEL_MAC_V4] = intel_mac_v4_pin_configs,
1877 [STAC_INTEL_MAC_V5] = intel_mac_v5_pin_configs,
1878 [STAC_INTEL_MAC_AUTO] = intel_mac_v3_pin_configs,
1879 /* for backward compatibility */
1880 [STAC_MACMINI] = intel_mac_v3_pin_configs,
1881 [STAC_MACBOOK] = intel_mac_v5_pin_configs,
1882 [STAC_MACBOOK_PRO_V1] = intel_mac_v3_pin_configs,
1883 [STAC_MACBOOK_PRO_V2] = intel_mac_v3_pin_configs,
1884 [STAC_IMAC_INTEL] = intel_mac_v2_pin_configs,
1885 [STAC_IMAC_INTEL_20] = intel_mac_v3_pin_configs,
1886 [STAC_ECS_202] = ecs202_pin_configs,
1887 [STAC_922X_DELL_D81] = dell_922x_d81_pin_configs,
1888 [STAC_922X_DELL_D82] = dell_922x_d82_pin_configs,
1889 [STAC_922X_DELL_M81] = dell_922x_m81_pin_configs,
1890 [STAC_922X_DELL_M82] = dell_922x_m82_pin_configs,
1893 static const char *stac922x_models[STAC_922X_MODELS] = {
1894 [STAC_922X_AUTO] = "auto",
1895 [STAC_D945_REF] = "ref",
1896 [STAC_D945GTP5] = "5stack",
1897 [STAC_D945GTP3] = "3stack",
1898 [STAC_INTEL_MAC_V1] = "intel-mac-v1",
1899 [STAC_INTEL_MAC_V2] = "intel-mac-v2",
1900 [STAC_INTEL_MAC_V3] = "intel-mac-v3",
1901 [STAC_INTEL_MAC_V4] = "intel-mac-v4",
1902 [STAC_INTEL_MAC_V5] = "intel-mac-v5",
1903 [STAC_INTEL_MAC_AUTO] = "intel-mac-auto",
1904 /* for backward compatibility */
1905 [STAC_MACMINI] = "macmini",
1906 [STAC_MACBOOK] = "macbook",
1907 [STAC_MACBOOK_PRO_V1] = "macbook-pro-v1",
1908 [STAC_MACBOOK_PRO_V2] = "macbook-pro",
1909 [STAC_IMAC_INTEL] = "imac-intel",
1910 [STAC_IMAC_INTEL_20] = "imac-intel-20",
1911 [STAC_ECS_202] = "ecs202",
1912 [STAC_922X_DELL_D81] = "dell-d81",
1913 [STAC_922X_DELL_D82] = "dell-d82",
1914 [STAC_922X_DELL_M81] = "dell-m81",
1915 [STAC_922X_DELL_M82] = "dell-m82",
1918 static struct snd_pci_quirk stac922x_cfg_tbl[] = {
1919 /* SigmaTel reference board */
1920 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1921 "DFI LanParty", STAC_D945_REF),
1922 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1923 "DFI LanParty", STAC_D945_REF),
1924 /* Intel 945G based systems */
1925 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101,
1926 "Intel D945G", STAC_D945GTP3),
1927 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0202,
1928 "Intel D945G", STAC_D945GTP3),
1929 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0606,
1930 "Intel D945G", STAC_D945GTP3),
1931 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0601,
1932 "Intel D945G", STAC_D945GTP3),
1933 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0111,
1934 "Intel D945G", STAC_D945GTP3),
1935 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1115,
1936 "Intel D945G", STAC_D945GTP3),
1937 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1116,
1938 "Intel D945G", STAC_D945GTP3),
1939 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1117,
1940 "Intel D945G", STAC_D945GTP3),
1941 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1118,
1942 "Intel D945G", STAC_D945GTP3),
1943 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1119,
1944 "Intel D945G", STAC_D945GTP3),
1945 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x8826,
1946 "Intel D945G", STAC_D945GTP3),
1947 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5049,
1948 "Intel D945G", STAC_D945GTP3),
1949 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5055,
1950 "Intel D945G", STAC_D945GTP3),
1951 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5048,
1952 "Intel D945G", STAC_D945GTP3),
1953 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0110,
1954 "Intel D945G", STAC_D945GTP3),
1955 /* Intel D945G 5-stack systems */
1956 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0404,
1957 "Intel D945G", STAC_D945GTP5),
1958 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0303,
1959 "Intel D945G", STAC_D945GTP5),
1960 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0013,
1961 "Intel D945G", STAC_D945GTP5),
1962 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0417,
1963 "Intel D945G", STAC_D945GTP5),
1964 /* Intel 945P based systems */
1965 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0b0b,
1966 "Intel D945P", STAC_D945GTP3),
1967 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0112,
1968 "Intel D945P", STAC_D945GTP3),
1969 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0d0d,
1970 "Intel D945P", STAC_D945GTP3),
1971 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0909,
1972 "Intel D945P", STAC_D945GTP3),
1973 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0505,
1974 "Intel D945P", STAC_D945GTP3),
1975 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707,
1976 "Intel D945P", STAC_D945GTP5),
1977 /* other intel */
1978 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0204,
1979 "Intel D945", STAC_D945_REF),
1980 /* other systems */
1981 /* Apple Intel Mac (Mac Mini, MacBook, MacBook Pro...) */
1982 SND_PCI_QUIRK(0x8384, 0x7680,
1983 "Mac", STAC_INTEL_MAC_AUTO),
1984 /* Dell systems */
1985 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a7,
1986 "unknown Dell", STAC_922X_DELL_D81),
1987 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a9,
1988 "unknown Dell", STAC_922X_DELL_D81),
1989 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ab,
1990 "unknown Dell", STAC_922X_DELL_D81),
1991 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ac,
1992 "unknown Dell", STAC_922X_DELL_D82),
1993 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bf,
1994 "unknown Dell", STAC_922X_DELL_M81),
1995 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d0,
1996 "unknown Dell", STAC_922X_DELL_D82),
1997 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d1,
1998 "unknown Dell", STAC_922X_DELL_D81),
1999 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d2,
2000 "unknown Dell", STAC_922X_DELL_D81),
2001 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d7,
2002 "Dell XPS M1210", STAC_922X_DELL_M82),
2003 /* ECS/PC Chips boards */
2004 SND_PCI_QUIRK_MASK(0x1019, 0xf000, 0x2000,
2005 "ECS/PC chips", STAC_ECS_202),
2006 {} /* terminator */
2009 static unsigned int ref927x_pin_configs[14] = {
2010 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2011 0x01a19040, 0x01011012, 0x01016011, 0x0101201f,
2012 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
2013 0x01c42190, 0x40000100,
2016 static unsigned int d965_3st_pin_configs[14] = {
2017 0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
2018 0x01a19021, 0x01813024, 0x40000100, 0x40000100,
2019 0x40000100, 0x40000100, 0x40000100, 0x40000100,
2020 0x40000100, 0x40000100
2023 static unsigned int d965_5st_pin_configs[14] = {
2024 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2025 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
2026 0x40000100, 0x40000100, 0x40000100, 0x01442070,
2027 0x40000100, 0x40000100
2030 static unsigned int d965_5st_no_fp_pin_configs[14] = {
2031 0x40000100, 0x40000100, 0x0181304e, 0x01014010,
2032 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
2033 0x40000100, 0x40000100, 0x40000100, 0x01442070,
2034 0x40000100, 0x40000100
2037 static unsigned int dell_3st_pin_configs[14] = {
2038 0x02211230, 0x02a11220, 0x01a19040, 0x01114210,
2039 0x01111212, 0x01116211, 0x01813050, 0x01112214,
2040 0x403003fa, 0x90a60040, 0x90a60040, 0x404003fb,
2041 0x40c003fc, 0x40000100
2044 static unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
2045 [STAC_D965_REF_NO_JD] = ref927x_pin_configs,
2046 [STAC_D965_REF] = ref927x_pin_configs,
2047 [STAC_D965_3ST] = d965_3st_pin_configs,
2048 [STAC_D965_5ST] = d965_5st_pin_configs,
2049 [STAC_D965_5ST_NO_FP] = d965_5st_no_fp_pin_configs,
2050 [STAC_DELL_3ST] = dell_3st_pin_configs,
2051 [STAC_DELL_BIOS] = NULL,
2052 [STAC_927X_VOLKNOB] = NULL,
2055 static const char *stac927x_models[STAC_927X_MODELS] = {
2056 [STAC_927X_AUTO] = "auto",
2057 [STAC_D965_REF_NO_JD] = "ref-no-jd",
2058 [STAC_D965_REF] = "ref",
2059 [STAC_D965_3ST] = "3stack",
2060 [STAC_D965_5ST] = "5stack",
2061 [STAC_D965_5ST_NO_FP] = "5stack-no-fp",
2062 [STAC_DELL_3ST] = "dell-3stack",
2063 [STAC_DELL_BIOS] = "dell-bios",
2064 [STAC_927X_VOLKNOB] = "volknob",
2067 static struct snd_pci_quirk stac927x_cfg_tbl[] = {
2068 /* SigmaTel reference board */
2069 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2070 "DFI LanParty", STAC_D965_REF),
2071 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2072 "DFI LanParty", STAC_D965_REF),
2073 /* Intel 946 based systems */
2074 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST),
2075 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST),
2076 /* 965 based 3 stack systems */
2077 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2100,
2078 "Intel D965", STAC_D965_3ST),
2079 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2000,
2080 "Intel D965", STAC_D965_3ST),
2081 /* Dell 3 stack systems */
2082 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01dd, "Dell Dimension E520", STAC_DELL_3ST),
2083 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ed, "Dell ", STAC_DELL_3ST),
2084 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f4, "Dell ", STAC_DELL_3ST),
2085 /* Dell 3 stack systems with verb table in BIOS */
2086 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f3, "Dell Inspiron 1420", STAC_DELL_BIOS),
2087 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f7, "Dell XPS M1730", STAC_DELL_BIOS),
2088 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0227, "Dell Vostro 1400 ", STAC_DELL_BIOS),
2089 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022e, "Dell ", STAC_DELL_BIOS),
2090 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022f, "Dell Inspiron 1525", STAC_DELL_BIOS),
2091 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0242, "Dell ", STAC_DELL_BIOS),
2092 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0243, "Dell ", STAC_DELL_BIOS),
2093 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ff, "Dell ", STAC_DELL_BIOS),
2094 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0209, "Dell XPS 1330", STAC_DELL_BIOS),
2095 /* 965 based 5 stack systems */
2096 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2300,
2097 "Intel D965", STAC_D965_5ST),
2098 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2500,
2099 "Intel D965", STAC_D965_5ST),
2100 /* volume-knob fixes */
2101 SND_PCI_QUIRK_VENDOR(0x10cf, "FSC", STAC_927X_VOLKNOB),
2102 {} /* terminator */
2105 static unsigned int ref9205_pin_configs[12] = {
2106 0x40000100, 0x40000100, 0x01016011, 0x01014010,
2107 0x01813122, 0x01a19021, 0x01019020, 0x40000100,
2108 0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
2112 STAC 9205 pin configs for
2113 102801F1
2114 102801F2
2115 102801FC
2116 102801FD
2117 10280204
2118 1028021F
2119 10280228 (Dell Vostro 1500)
2120 10280229 (Dell Vostro 1700)
2122 static unsigned int dell_9205_m42_pin_configs[12] = {
2123 0x0321101F, 0x03A11020, 0x400003FA, 0x90170310,
2124 0x400003FB, 0x400003FC, 0x400003FD, 0x40F000F9,
2125 0x90A60330, 0x400003FF, 0x0144131F, 0x40C003FE,
2129 STAC 9205 pin configs for
2130 102801F9
2131 102801FA
2132 102801FE
2133 102801FF (Dell Precision M4300)
2134 10280206
2135 10280200
2136 10280201
2138 static unsigned int dell_9205_m43_pin_configs[12] = {
2139 0x0321101f, 0x03a11020, 0x90a70330, 0x90170310,
2140 0x400000fe, 0x400000ff, 0x400000fd, 0x40f000f9,
2141 0x400000fa, 0x400000fc, 0x0144131f, 0x40c003f8,
2144 static unsigned int dell_9205_m44_pin_configs[12] = {
2145 0x0421101f, 0x04a11020, 0x400003fa, 0x90170310,
2146 0x400003fb, 0x400003fc, 0x400003fd, 0x400003f9,
2147 0x90a60330, 0x400003ff, 0x01441340, 0x40c003fe,
2150 static unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
2151 [STAC_9205_REF] = ref9205_pin_configs,
2152 [STAC_9205_DELL_M42] = dell_9205_m42_pin_configs,
2153 [STAC_9205_DELL_M43] = dell_9205_m43_pin_configs,
2154 [STAC_9205_DELL_M44] = dell_9205_m44_pin_configs,
2155 [STAC_9205_EAPD] = NULL,
2158 static const char *stac9205_models[STAC_9205_MODELS] = {
2159 [STAC_9205_AUTO] = "auto",
2160 [STAC_9205_REF] = "ref",
2161 [STAC_9205_DELL_M42] = "dell-m42",
2162 [STAC_9205_DELL_M43] = "dell-m43",
2163 [STAC_9205_DELL_M44] = "dell-m44",
2164 [STAC_9205_EAPD] = "eapd",
2167 static struct snd_pci_quirk stac9205_cfg_tbl[] = {
2168 /* SigmaTel reference board */
2169 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2170 "DFI LanParty", STAC_9205_REF),
2171 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xfb30,
2172 "SigmaTel", STAC_9205_REF),
2173 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2174 "DFI LanParty", STAC_9205_REF),
2175 /* Dell */
2176 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f1,
2177 "unknown Dell", STAC_9205_DELL_M42),
2178 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f2,
2179 "unknown Dell", STAC_9205_DELL_M42),
2180 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f8,
2181 "Dell Precision", STAC_9205_DELL_M43),
2182 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f9,
2183 "Dell Precision", STAC_9205_DELL_M43),
2184 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fa,
2185 "Dell Precision", STAC_9205_DELL_M43),
2186 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fc,
2187 "unknown Dell", STAC_9205_DELL_M42),
2188 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fd,
2189 "unknown Dell", STAC_9205_DELL_M42),
2190 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fe,
2191 "Dell Precision", STAC_9205_DELL_M43),
2192 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ff,
2193 "Dell Precision M4300", STAC_9205_DELL_M43),
2194 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0204,
2195 "unknown Dell", STAC_9205_DELL_M42),
2196 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0206,
2197 "Dell Precision", STAC_9205_DELL_M43),
2198 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021b,
2199 "Dell Precision", STAC_9205_DELL_M43),
2200 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021c,
2201 "Dell Precision", STAC_9205_DELL_M43),
2202 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021f,
2203 "Dell Inspiron", STAC_9205_DELL_M44),
2204 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0228,
2205 "Dell Vostro 1500", STAC_9205_DELL_M42),
2206 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0229,
2207 "Dell Vostro 1700", STAC_9205_DELL_M42),
2208 /* Gateway */
2209 SND_PCI_QUIRK(0x107b, 0x0560, "Gateway T6834c", STAC_9205_EAPD),
2210 SND_PCI_QUIRK(0x107b, 0x0565, "Gateway T1616", STAC_9205_EAPD),
2211 {} /* terminator */
2214 static void stac92xx_set_config_regs(struct hda_codec *codec,
2215 unsigned int *pincfgs)
2217 int i;
2218 struct sigmatel_spec *spec = codec->spec;
2220 if (!pincfgs)
2221 return;
2223 for (i = 0; i < spec->num_pins; i++)
2224 if (spec->pin_nids[i] && pincfgs[i])
2225 snd_hda_codec_set_pincfg(codec, spec->pin_nids[i],
2226 pincfgs[i]);
2230 * Analog playback callbacks
2232 static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
2233 struct hda_codec *codec,
2234 struct snd_pcm_substream *substream)
2236 struct sigmatel_spec *spec = codec->spec;
2237 if (spec->stream_delay)
2238 msleep(spec->stream_delay);
2239 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2240 hinfo);
2243 static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2244 struct hda_codec *codec,
2245 unsigned int stream_tag,
2246 unsigned int format,
2247 struct snd_pcm_substream *substream)
2249 struct sigmatel_spec *spec = codec->spec;
2250 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
2253 static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2254 struct hda_codec *codec,
2255 struct snd_pcm_substream *substream)
2257 struct sigmatel_spec *spec = codec->spec;
2258 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2262 * Digital playback callbacks
2264 static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2265 struct hda_codec *codec,
2266 struct snd_pcm_substream *substream)
2268 struct sigmatel_spec *spec = codec->spec;
2269 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2272 static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2273 struct hda_codec *codec,
2274 struct snd_pcm_substream *substream)
2276 struct sigmatel_spec *spec = codec->spec;
2277 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2280 static int stac92xx_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2281 struct hda_codec *codec,
2282 unsigned int stream_tag,
2283 unsigned int format,
2284 struct snd_pcm_substream *substream)
2286 struct sigmatel_spec *spec = codec->spec;
2287 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2288 stream_tag, format, substream);
2291 static int stac92xx_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2292 struct hda_codec *codec,
2293 struct snd_pcm_substream *substream)
2295 struct sigmatel_spec *spec = codec->spec;
2296 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2301 * Analog capture callbacks
2303 static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2304 struct hda_codec *codec,
2305 unsigned int stream_tag,
2306 unsigned int format,
2307 struct snd_pcm_substream *substream)
2309 struct sigmatel_spec *spec = codec->spec;
2310 hda_nid_t nid = spec->adc_nids[substream->number];
2312 if (spec->powerdown_adcs) {
2313 msleep(40);
2314 snd_hda_codec_write(codec, nid, 0,
2315 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
2317 snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format);
2318 return 0;
2321 static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2322 struct hda_codec *codec,
2323 struct snd_pcm_substream *substream)
2325 struct sigmatel_spec *spec = codec->spec;
2326 hda_nid_t nid = spec->adc_nids[substream->number];
2328 snd_hda_codec_cleanup_stream(codec, nid);
2329 if (spec->powerdown_adcs)
2330 snd_hda_codec_write(codec, nid, 0,
2331 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
2332 return 0;
2335 static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
2336 .substreams = 1,
2337 .channels_min = 2,
2338 .channels_max = 2,
2339 /* NID is set in stac92xx_build_pcms */
2340 .ops = {
2341 .open = stac92xx_dig_playback_pcm_open,
2342 .close = stac92xx_dig_playback_pcm_close,
2343 .prepare = stac92xx_dig_playback_pcm_prepare,
2344 .cleanup = stac92xx_dig_playback_pcm_cleanup
2348 static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
2349 .substreams = 1,
2350 .channels_min = 2,
2351 .channels_max = 2,
2352 /* NID is set in stac92xx_build_pcms */
2355 static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
2356 .substreams = 1,
2357 .channels_min = 2,
2358 .channels_max = 8,
2359 .nid = 0x02, /* NID to query formats and rates */
2360 .ops = {
2361 .open = stac92xx_playback_pcm_open,
2362 .prepare = stac92xx_playback_pcm_prepare,
2363 .cleanup = stac92xx_playback_pcm_cleanup
2367 static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
2368 .substreams = 1,
2369 .channels_min = 2,
2370 .channels_max = 2,
2371 .nid = 0x06, /* NID to query formats and rates */
2372 .ops = {
2373 .open = stac92xx_playback_pcm_open,
2374 .prepare = stac92xx_playback_pcm_prepare,
2375 .cleanup = stac92xx_playback_pcm_cleanup
2379 static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
2380 .channels_min = 2,
2381 .channels_max = 2,
2382 /* NID + .substreams is set in stac92xx_build_pcms */
2383 .ops = {
2384 .prepare = stac92xx_capture_pcm_prepare,
2385 .cleanup = stac92xx_capture_pcm_cleanup
2389 static int stac92xx_build_pcms(struct hda_codec *codec)
2391 struct sigmatel_spec *spec = codec->spec;
2392 struct hda_pcm *info = spec->pcm_rec;
2394 codec->num_pcms = 1;
2395 codec->pcm_info = info;
2397 info->name = "STAC92xx Analog";
2398 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
2399 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2400 spec->multiout.dac_nids[0];
2401 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
2402 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2403 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adcs;
2405 if (spec->alt_switch) {
2406 codec->num_pcms++;
2407 info++;
2408 info->name = "STAC92xx Analog Alt";
2409 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
2412 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2413 codec->num_pcms++;
2414 info++;
2415 info->name = "STAC92xx Digital";
2416 info->pcm_type = spec->autocfg.dig_out_type[0];
2417 if (spec->multiout.dig_out_nid) {
2418 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
2419 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2421 if (spec->dig_in_nid) {
2422 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
2423 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2427 return 0;
2430 static unsigned int stac92xx_get_default_vref(struct hda_codec *codec,
2431 hda_nid_t nid)
2433 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2434 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
2435 if (pincap & AC_PINCAP_VREF_100)
2436 return AC_PINCTL_VREF_100;
2437 if (pincap & AC_PINCAP_VREF_80)
2438 return AC_PINCTL_VREF_80;
2439 if (pincap & AC_PINCAP_VREF_50)
2440 return AC_PINCTL_VREF_50;
2441 if (pincap & AC_PINCAP_VREF_GRD)
2442 return AC_PINCTL_VREF_GRD;
2443 return 0;
2446 static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
2449 snd_hda_codec_write_cache(codec, nid, 0,
2450 AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
2453 #define stac92xx_hp_switch_info snd_ctl_boolean_mono_info
2455 static int stac92xx_hp_switch_get(struct snd_kcontrol *kcontrol,
2456 struct snd_ctl_elem_value *ucontrol)
2458 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2459 struct sigmatel_spec *spec = codec->spec;
2461 ucontrol->value.integer.value[0] = !!spec->hp_switch;
2462 return 0;
2465 static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid);
2467 static int stac92xx_hp_switch_put(struct snd_kcontrol *kcontrol,
2468 struct snd_ctl_elem_value *ucontrol)
2470 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2471 struct sigmatel_spec *spec = codec->spec;
2472 int nid = kcontrol->private_value;
2474 spec->hp_switch = ucontrol->value.integer.value[0] ? nid : 0;
2476 /* check to be sure that the ports are upto date with
2477 * switch changes
2479 stac_issue_unsol_event(codec, nid);
2481 return 1;
2484 static int stac92xx_dc_bias_info(struct snd_kcontrol *kcontrol,
2485 struct snd_ctl_elem_info *uinfo)
2487 int i;
2488 static char *texts[] = {
2489 "Mic In", "Line In", "Line Out"
2492 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2493 struct sigmatel_spec *spec = codec->spec;
2494 hda_nid_t nid = kcontrol->private_value;
2496 if (nid == spec->mic_switch || nid == spec->line_switch)
2497 i = 3;
2498 else
2499 i = 2;
2501 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2502 uinfo->value.enumerated.items = i;
2503 uinfo->count = 1;
2504 if (uinfo->value.enumerated.item >= i)
2505 uinfo->value.enumerated.item = i-1;
2506 strcpy(uinfo->value.enumerated.name,
2507 texts[uinfo->value.enumerated.item]);
2509 return 0;
2512 static int stac92xx_dc_bias_get(struct snd_kcontrol *kcontrol,
2513 struct snd_ctl_elem_value *ucontrol)
2515 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2516 hda_nid_t nid = kcontrol->private_value;
2517 unsigned int vref = stac92xx_vref_get(codec, nid);
2519 if (vref == stac92xx_get_default_vref(codec, nid))
2520 ucontrol->value.enumerated.item[0] = 0;
2521 else if (vref == AC_PINCTL_VREF_GRD)
2522 ucontrol->value.enumerated.item[0] = 1;
2523 else if (vref == AC_PINCTL_VREF_HIZ)
2524 ucontrol->value.enumerated.item[0] = 2;
2526 return 0;
2529 static int stac92xx_dc_bias_put(struct snd_kcontrol *kcontrol,
2530 struct snd_ctl_elem_value *ucontrol)
2532 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2533 unsigned int new_vref = 0;
2534 int error;
2535 hda_nid_t nid = kcontrol->private_value;
2537 if (ucontrol->value.enumerated.item[0] == 0)
2538 new_vref = stac92xx_get_default_vref(codec, nid);
2539 else if (ucontrol->value.enumerated.item[0] == 1)
2540 new_vref = AC_PINCTL_VREF_GRD;
2541 else if (ucontrol->value.enumerated.item[0] == 2)
2542 new_vref = AC_PINCTL_VREF_HIZ;
2543 else
2544 return 0;
2546 if (new_vref != stac92xx_vref_get(codec, nid)) {
2547 error = stac92xx_vref_set(codec, nid, new_vref);
2548 return error;
2551 return 0;
2554 static int stac92xx_io_switch_info(struct snd_kcontrol *kcontrol,
2555 struct snd_ctl_elem_info *uinfo)
2557 static char *texts[2];
2558 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2559 struct sigmatel_spec *spec = codec->spec;
2561 if (kcontrol->private_value == spec->line_switch)
2562 texts[0] = "Line In";
2563 else
2564 texts[0] = "Mic In";
2565 texts[1] = "Line Out";
2566 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2567 uinfo->value.enumerated.items = 2;
2568 uinfo->count = 1;
2570 if (uinfo->value.enumerated.item >= 2)
2571 uinfo->value.enumerated.item = 1;
2572 strcpy(uinfo->value.enumerated.name,
2573 texts[uinfo->value.enumerated.item]);
2575 return 0;
2578 static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2580 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2581 struct sigmatel_spec *spec = codec->spec;
2582 hda_nid_t nid = kcontrol->private_value;
2583 int io_idx = (nid == spec->mic_switch) ? 1 : 0;
2585 ucontrol->value.enumerated.item[0] = spec->io_switch[io_idx];
2586 return 0;
2589 static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2591 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2592 struct sigmatel_spec *spec = codec->spec;
2593 hda_nid_t nid = kcontrol->private_value;
2594 int io_idx = (nid == spec->mic_switch) ? 1 : 0;
2595 unsigned short val = !!ucontrol->value.enumerated.item[0];
2597 spec->io_switch[io_idx] = val;
2599 if (val)
2600 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
2601 else {
2602 unsigned int pinctl = AC_PINCTL_IN_EN;
2603 if (io_idx) /* set VREF for mic */
2604 pinctl |= stac92xx_get_default_vref(codec, nid);
2605 stac92xx_auto_set_pinctl(codec, nid, pinctl);
2608 /* check the auto-mute again: we need to mute/unmute the speaker
2609 * appropriately according to the pin direction
2611 if (spec->hp_detect)
2612 stac_issue_unsol_event(codec, nid);
2614 return 1;
2617 #define stac92xx_clfe_switch_info snd_ctl_boolean_mono_info
2619 static int stac92xx_clfe_switch_get(struct snd_kcontrol *kcontrol,
2620 struct snd_ctl_elem_value *ucontrol)
2622 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2623 struct sigmatel_spec *spec = codec->spec;
2625 ucontrol->value.integer.value[0] = spec->clfe_swap;
2626 return 0;
2629 static int stac92xx_clfe_switch_put(struct snd_kcontrol *kcontrol,
2630 struct snd_ctl_elem_value *ucontrol)
2632 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2633 struct sigmatel_spec *spec = codec->spec;
2634 hda_nid_t nid = kcontrol->private_value & 0xff;
2635 unsigned int val = !!ucontrol->value.integer.value[0];
2637 if (spec->clfe_swap == val)
2638 return 0;
2640 spec->clfe_swap = val;
2642 snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
2643 spec->clfe_swap ? 0x4 : 0x0);
2645 return 1;
2648 #define STAC_CODEC_HP_SWITCH(xname) \
2649 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2650 .name = xname, \
2651 .index = 0, \
2652 .info = stac92xx_hp_switch_info, \
2653 .get = stac92xx_hp_switch_get, \
2654 .put = stac92xx_hp_switch_put, \
2657 #define STAC_CODEC_IO_SWITCH(xname, xpval) \
2658 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2659 .name = xname, \
2660 .index = 0, \
2661 .info = stac92xx_io_switch_info, \
2662 .get = stac92xx_io_switch_get, \
2663 .put = stac92xx_io_switch_put, \
2664 .private_value = xpval, \
2667 #define STAC_CODEC_CLFE_SWITCH(xname, xpval) \
2668 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2669 .name = xname, \
2670 .index = 0, \
2671 .info = stac92xx_clfe_switch_info, \
2672 .get = stac92xx_clfe_switch_get, \
2673 .put = stac92xx_clfe_switch_put, \
2674 .private_value = xpval, \
2677 enum {
2678 STAC_CTL_WIDGET_VOL,
2679 STAC_CTL_WIDGET_MUTE,
2680 STAC_CTL_WIDGET_MUTE_BEEP,
2681 STAC_CTL_WIDGET_MONO_MUX,
2682 STAC_CTL_WIDGET_HP_SWITCH,
2683 STAC_CTL_WIDGET_IO_SWITCH,
2684 STAC_CTL_WIDGET_CLFE_SWITCH,
2685 STAC_CTL_WIDGET_DC_BIAS
2688 static struct snd_kcontrol_new stac92xx_control_templates[] = {
2689 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2690 HDA_CODEC_MUTE(NULL, 0, 0, 0),
2691 HDA_CODEC_MUTE_BEEP(NULL, 0, 0, 0),
2692 STAC_MONO_MUX,
2693 STAC_CODEC_HP_SWITCH(NULL),
2694 STAC_CODEC_IO_SWITCH(NULL, 0),
2695 STAC_CODEC_CLFE_SWITCH(NULL, 0),
2696 DC_BIAS(NULL, 0, 0),
2699 /* add dynamic controls */
2700 static struct snd_kcontrol_new *
2701 stac_control_new(struct sigmatel_spec *spec,
2702 struct snd_kcontrol_new *ktemp,
2703 const char *name,
2704 unsigned int subdev)
2706 struct snd_kcontrol_new *knew;
2708 snd_array_init(&spec->kctls, sizeof(*knew), 32);
2709 knew = snd_array_new(&spec->kctls);
2710 if (!knew)
2711 return NULL;
2712 *knew = *ktemp;
2713 knew->name = kstrdup(name, GFP_KERNEL);
2714 if (!knew->name) {
2715 /* roolback */
2716 memset(knew, 0, sizeof(*knew));
2717 spec->kctls.alloced--;
2718 return NULL;
2720 knew->subdevice = subdev;
2721 return knew;
2724 static int stac92xx_add_control_temp(struct sigmatel_spec *spec,
2725 struct snd_kcontrol_new *ktemp,
2726 int idx, const char *name,
2727 unsigned long val)
2729 struct snd_kcontrol_new *knew = stac_control_new(spec, ktemp, name,
2730 HDA_SUBDEV_AMP_FLAG);
2731 if (!knew)
2732 return -ENOMEM;
2733 knew->index = idx;
2734 knew->private_value = val;
2735 return 0;
2738 static inline int stac92xx_add_control_idx(struct sigmatel_spec *spec,
2739 int type, int idx, const char *name,
2740 unsigned long val)
2742 return stac92xx_add_control_temp(spec,
2743 &stac92xx_control_templates[type],
2744 idx, name, val);
2748 /* add dynamic controls */
2749 static inline int stac92xx_add_control(struct sigmatel_spec *spec, int type,
2750 const char *name, unsigned long val)
2752 return stac92xx_add_control_idx(spec, type, 0, name, val);
2755 static struct snd_kcontrol_new stac_input_src_temp = {
2756 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2757 .name = "Input Source",
2758 .info = stac92xx_mux_enum_info,
2759 .get = stac92xx_mux_enum_get,
2760 .put = stac92xx_mux_enum_put,
2763 static inline int stac92xx_add_jack_mode_control(struct hda_codec *codec,
2764 hda_nid_t nid, int idx)
2766 int def_conf = snd_hda_codec_get_pincfg(codec, nid);
2767 int control = 0;
2768 struct sigmatel_spec *spec = codec->spec;
2769 char name[22];
2771 if (!((get_defcfg_connect(def_conf)) & AC_JACK_PORT_FIXED)) {
2772 if (stac92xx_get_default_vref(codec, nid) == AC_PINCTL_VREF_GRD
2773 && nid == spec->line_switch)
2774 control = STAC_CTL_WIDGET_IO_SWITCH;
2775 else if (snd_hda_query_pin_caps(codec, nid)
2776 & (AC_PINCAP_VREF_GRD << AC_PINCAP_VREF_SHIFT))
2777 control = STAC_CTL_WIDGET_DC_BIAS;
2778 else if (nid == spec->mic_switch)
2779 control = STAC_CTL_WIDGET_IO_SWITCH;
2782 if (control) {
2783 strcpy(name, auto_pin_cfg_labels[idx]);
2784 return stac92xx_add_control(codec->spec, control,
2785 strcat(name, " Jack Mode"), nid);
2788 return 0;
2791 static int stac92xx_add_input_source(struct sigmatel_spec *spec)
2793 struct snd_kcontrol_new *knew;
2794 struct hda_input_mux *imux = &spec->private_imux;
2796 if (spec->auto_mic)
2797 return 0; /* no need for input source */
2798 if (!spec->num_adcs || imux->num_items <= 1)
2799 return 0; /* no need for input source control */
2800 knew = stac_control_new(spec, &stac_input_src_temp,
2801 stac_input_src_temp.name, 0);
2802 if (!knew)
2803 return -ENOMEM;
2804 knew->count = spec->num_adcs;
2805 return 0;
2808 /* check whether the line-input can be used as line-out */
2809 static hda_nid_t check_line_out_switch(struct hda_codec *codec)
2811 struct sigmatel_spec *spec = codec->spec;
2812 struct auto_pin_cfg *cfg = &spec->autocfg;
2813 hda_nid_t nid;
2814 unsigned int pincap;
2816 if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
2817 return 0;
2818 nid = cfg->input_pins[AUTO_PIN_LINE];
2819 pincap = snd_hda_query_pin_caps(codec, nid);
2820 if (pincap & AC_PINCAP_OUT)
2821 return nid;
2822 return 0;
2825 /* check whether the mic-input can be used as line-out */
2826 static hda_nid_t check_mic_out_switch(struct hda_codec *codec)
2828 struct sigmatel_spec *spec = codec->spec;
2829 struct auto_pin_cfg *cfg = &spec->autocfg;
2830 unsigned int def_conf, pincap;
2831 unsigned int mic_pin;
2833 if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
2834 return 0;
2835 mic_pin = AUTO_PIN_MIC;
2836 for (;;) {
2837 hda_nid_t nid = cfg->input_pins[mic_pin];
2838 def_conf = snd_hda_codec_get_pincfg(codec, nid);
2839 /* some laptops have an internal analog microphone
2840 * which can't be used as a output */
2841 if (get_defcfg_connect(def_conf) != AC_JACK_PORT_FIXED) {
2842 pincap = snd_hda_query_pin_caps(codec, nid);
2843 if (pincap & AC_PINCAP_OUT)
2844 return nid;
2846 if (mic_pin == AUTO_PIN_MIC)
2847 mic_pin = AUTO_PIN_FRONT_MIC;
2848 else
2849 break;
2851 return 0;
2854 static int is_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2856 int i;
2858 for (i = 0; i < spec->multiout.num_dacs; i++) {
2859 if (spec->multiout.dac_nids[i] == nid)
2860 return 1;
2863 return 0;
2866 static int check_all_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2868 int i;
2869 if (is_in_dac_nids(spec, nid))
2870 return 1;
2871 for (i = 0; i < spec->autocfg.hp_outs; i++)
2872 if (spec->hp_dacs[i] == nid)
2873 return 1;
2874 for (i = 0; i < spec->autocfg.speaker_outs; i++)
2875 if (spec->speaker_dacs[i] == nid)
2876 return 1;
2877 return 0;
2880 static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t nid)
2882 struct sigmatel_spec *spec = codec->spec;
2883 int j, conn_len;
2884 hda_nid_t conn[HDA_MAX_CONNECTIONS];
2885 unsigned int wcaps, wtype;
2887 conn_len = snd_hda_get_connections(codec, nid, conn,
2888 HDA_MAX_CONNECTIONS);
2889 /* 92HD88: trace back up the link of nids to find the DAC */
2890 while (conn_len == 1 && (get_wcaps_type(get_wcaps(codec, conn[0]))
2891 != AC_WID_AUD_OUT)) {
2892 nid = conn[0];
2893 conn_len = snd_hda_get_connections(codec, nid, conn,
2894 HDA_MAX_CONNECTIONS);
2896 for (j = 0; j < conn_len; j++) {
2897 wcaps = get_wcaps(codec, conn[j]);
2898 wtype = get_wcaps_type(wcaps);
2899 /* we check only analog outputs */
2900 if (wtype != AC_WID_AUD_OUT || (wcaps & AC_WCAP_DIGITAL))
2901 continue;
2902 /* if this route has a free DAC, assign it */
2903 if (!check_all_dac_nids(spec, conn[j])) {
2904 if (conn_len > 1) {
2905 /* select this DAC in the pin's input mux */
2906 snd_hda_codec_write_cache(codec, nid, 0,
2907 AC_VERB_SET_CONNECT_SEL, j);
2909 return conn[j];
2912 /* if all DACs are already assigned, connect to the primary DAC */
2913 if (conn_len > 1) {
2914 for (j = 0; j < conn_len; j++) {
2915 if (conn[j] == spec->multiout.dac_nids[0]) {
2916 snd_hda_codec_write_cache(codec, nid, 0,
2917 AC_VERB_SET_CONNECT_SEL, j);
2918 break;
2922 return 0;
2925 static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid);
2926 static int add_spec_extra_dacs(struct sigmatel_spec *spec, hda_nid_t nid);
2929 * Fill in the dac_nids table from the parsed pin configuration
2930 * This function only works when every pin in line_out_pins[]
2931 * contains atleast one DAC in its connection list. Some 92xx
2932 * codecs are not connected directly to a DAC, such as the 9200
2933 * and 9202/925x. For those, dac_nids[] must be hard-coded.
2935 static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec)
2937 struct sigmatel_spec *spec = codec->spec;
2938 struct auto_pin_cfg *cfg = &spec->autocfg;
2939 int i;
2940 hda_nid_t nid, dac;
2942 for (i = 0; i < cfg->line_outs; i++) {
2943 nid = cfg->line_out_pins[i];
2944 dac = get_unassigned_dac(codec, nid);
2945 if (!dac) {
2946 if (spec->multiout.num_dacs > 0) {
2947 /* we have already working output pins,
2948 * so let's drop the broken ones again
2950 cfg->line_outs = spec->multiout.num_dacs;
2951 break;
2953 /* error out, no available DAC found */
2954 snd_printk(KERN_ERR
2955 "%s: No available DAC for pin 0x%x\n",
2956 __func__, nid);
2957 return -ENODEV;
2959 add_spec_dacs(spec, dac);
2962 for (i = 0; i < cfg->hp_outs; i++) {
2963 nid = cfg->hp_pins[i];
2964 dac = get_unassigned_dac(codec, nid);
2965 if (dac) {
2966 if (!spec->multiout.hp_nid)
2967 spec->multiout.hp_nid = dac;
2968 else
2969 add_spec_extra_dacs(spec, dac);
2971 spec->hp_dacs[i] = dac;
2974 for (i = 0; i < cfg->speaker_outs; i++) {
2975 nid = cfg->speaker_pins[i];
2976 dac = get_unassigned_dac(codec, nid);
2977 if (dac)
2978 add_spec_extra_dacs(spec, dac);
2979 spec->speaker_dacs[i] = dac;
2982 /* add line-in as output */
2983 nid = check_line_out_switch(codec);
2984 if (nid) {
2985 dac = get_unassigned_dac(codec, nid);
2986 if (dac) {
2987 snd_printdd("STAC: Add line-in 0x%x as output %d\n",
2988 nid, cfg->line_outs);
2989 cfg->line_out_pins[cfg->line_outs] = nid;
2990 cfg->line_outs++;
2991 spec->line_switch = nid;
2992 add_spec_dacs(spec, dac);
2995 /* add mic as output */
2996 nid = check_mic_out_switch(codec);
2997 if (nid) {
2998 dac = get_unassigned_dac(codec, nid);
2999 if (dac) {
3000 snd_printdd("STAC: Add mic-in 0x%x as output %d\n",
3001 nid, cfg->line_outs);
3002 cfg->line_out_pins[cfg->line_outs] = nid;
3003 cfg->line_outs++;
3004 spec->mic_switch = nid;
3005 add_spec_dacs(spec, dac);
3009 snd_printd("stac92xx: dac_nids=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
3010 spec->multiout.num_dacs,
3011 spec->multiout.dac_nids[0],
3012 spec->multiout.dac_nids[1],
3013 spec->multiout.dac_nids[2],
3014 spec->multiout.dac_nids[3],
3015 spec->multiout.dac_nids[4]);
3017 return 0;
3020 /* create volume control/switch for the given prefx type */
3021 static int create_controls_idx(struct hda_codec *codec, const char *pfx,
3022 int idx, hda_nid_t nid, int chs)
3024 struct sigmatel_spec *spec = codec->spec;
3025 char name[32];
3026 int err;
3028 if (!spec->check_volume_offset) {
3029 unsigned int caps, step, nums, db_scale;
3030 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3031 step = (caps & AC_AMPCAP_STEP_SIZE) >>
3032 AC_AMPCAP_STEP_SIZE_SHIFT;
3033 step = (step + 1) * 25; /* in .01dB unit */
3034 nums = (caps & AC_AMPCAP_NUM_STEPS) >>
3035 AC_AMPCAP_NUM_STEPS_SHIFT;
3036 db_scale = nums * step;
3037 /* if dB scale is over -64dB, and finer enough,
3038 * let's reduce it to half
3040 if (db_scale > 6400 && nums >= 0x1f)
3041 spec->volume_offset = nums / 2;
3042 spec->check_volume_offset = 1;
3045 sprintf(name, "%s Playback Volume", pfx);
3046 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_VOL, idx, name,
3047 HDA_COMPOSE_AMP_VAL_OFS(nid, chs, 0, HDA_OUTPUT,
3048 spec->volume_offset));
3049 if (err < 0)
3050 return err;
3051 sprintf(name, "%s Playback Switch", pfx);
3052 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_MUTE, idx, name,
3053 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
3054 if (err < 0)
3055 return err;
3056 return 0;
3059 #define create_controls(codec, pfx, nid, chs) \
3060 create_controls_idx(codec, pfx, 0, nid, chs)
3062 static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
3064 if (spec->multiout.num_dacs > 4) {
3065 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
3066 return 1;
3067 } else {
3068 spec->multiout.dac_nids[spec->multiout.num_dacs] = nid;
3069 spec->multiout.num_dacs++;
3071 return 0;
3074 static int add_spec_extra_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
3076 int i;
3077 for (i = 0; i < ARRAY_SIZE(spec->multiout.extra_out_nid); i++) {
3078 if (!spec->multiout.extra_out_nid[i]) {
3079 spec->multiout.extra_out_nid[i] = nid;
3080 return 0;
3083 printk(KERN_WARNING "stac92xx: No space for extra DAC 0x%x\n", nid);
3084 return 1;
3087 /* Create output controls
3088 * The mixer elements are named depending on the given type (AUTO_PIN_XXX_OUT)
3090 static int create_multi_out_ctls(struct hda_codec *codec, int num_outs,
3091 const hda_nid_t *pins,
3092 const hda_nid_t *dac_nids,
3093 int type)
3095 struct sigmatel_spec *spec = codec->spec;
3096 static const char *chname[4] = {
3097 "Front", "Surround", NULL /*CLFE*/, "Side"
3099 hda_nid_t nid;
3100 int i, err;
3101 unsigned int wid_caps;
3103 for (i = 0; i < num_outs && i < ARRAY_SIZE(chname); i++) {
3104 if (type == AUTO_PIN_HP_OUT && !spec->hp_detect) {
3105 wid_caps = get_wcaps(codec, pins[i]);
3106 if (wid_caps & AC_WCAP_UNSOL_CAP)
3107 spec->hp_detect = 1;
3109 nid = dac_nids[i];
3110 if (!nid)
3111 continue;
3112 if (type != AUTO_PIN_HP_OUT && i == 2) {
3113 /* Center/LFE */
3114 err = create_controls(codec, "Center", nid, 1);
3115 if (err < 0)
3116 return err;
3117 err = create_controls(codec, "LFE", nid, 2);
3118 if (err < 0)
3119 return err;
3121 wid_caps = get_wcaps(codec, nid);
3123 if (wid_caps & AC_WCAP_LR_SWAP) {
3124 err = stac92xx_add_control(spec,
3125 STAC_CTL_WIDGET_CLFE_SWITCH,
3126 "Swap Center/LFE Playback Switch", nid);
3128 if (err < 0)
3129 return err;
3132 } else {
3133 const char *name;
3134 int idx;
3135 switch (type) {
3136 case AUTO_PIN_HP_OUT:
3137 name = "Headphone";
3138 idx = i;
3139 break;
3140 case AUTO_PIN_SPEAKER_OUT:
3141 name = "Speaker";
3142 idx = i;
3143 break;
3144 default:
3145 name = chname[i];
3146 idx = 0;
3147 break;
3149 err = create_controls_idx(codec, name, idx, nid, 3);
3150 if (err < 0)
3151 return err;
3154 return 0;
3157 static int stac92xx_add_capvol_ctls(struct hda_codec *codec, unsigned long vol,
3158 unsigned long sw, int idx)
3160 int err;
3161 err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_VOL, idx,
3162 "Capture Volume", vol);
3163 if (err < 0)
3164 return err;
3165 err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_MUTE, idx,
3166 "Capture Switch", sw);
3167 if (err < 0)
3168 return err;
3169 return 0;
3172 /* add playback controls from the parsed DAC table */
3173 static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
3174 const struct auto_pin_cfg *cfg)
3176 struct sigmatel_spec *spec = codec->spec;
3177 hda_nid_t nid;
3178 int err;
3179 int idx;
3181 err = create_multi_out_ctls(codec, cfg->line_outs, cfg->line_out_pins,
3182 spec->multiout.dac_nids,
3183 cfg->line_out_type);
3184 if (err < 0)
3185 return err;
3187 if (cfg->hp_outs > 1 && cfg->line_out_type == AUTO_PIN_LINE_OUT) {
3188 err = stac92xx_add_control(spec,
3189 STAC_CTL_WIDGET_HP_SWITCH,
3190 "Headphone as Line Out Switch",
3191 cfg->hp_pins[cfg->hp_outs - 1]);
3192 if (err < 0)
3193 return err;
3196 for (idx = AUTO_PIN_MIC; idx <= AUTO_PIN_FRONT_LINE; idx++) {
3197 nid = cfg->input_pins[idx];
3198 if (nid) {
3199 err = stac92xx_add_jack_mode_control(codec, nid, idx);
3200 if (err < 0)
3201 return err;
3205 return 0;
3208 /* add playback controls for Speaker and HP outputs */
3209 static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
3210 struct auto_pin_cfg *cfg)
3212 struct sigmatel_spec *spec = codec->spec;
3213 int err;
3215 err = create_multi_out_ctls(codec, cfg->hp_outs, cfg->hp_pins,
3216 spec->hp_dacs, AUTO_PIN_HP_OUT);
3217 if (err < 0)
3218 return err;
3220 err = create_multi_out_ctls(codec, cfg->speaker_outs, cfg->speaker_pins,
3221 spec->speaker_dacs, AUTO_PIN_SPEAKER_OUT);
3222 if (err < 0)
3223 return err;
3225 return 0;
3228 /* labels for mono mux outputs */
3229 static const char *stac92xx_mono_labels[4] = {
3230 "DAC0", "DAC1", "Mixer", "DAC2"
3233 /* create mono mux for mono out on capable codecs */
3234 static int stac92xx_auto_create_mono_output_ctls(struct hda_codec *codec)
3236 struct sigmatel_spec *spec = codec->spec;
3237 struct hda_input_mux *mono_mux = &spec->private_mono_mux;
3238 int i, num_cons;
3239 hda_nid_t con_lst[ARRAY_SIZE(stac92xx_mono_labels)];
3241 num_cons = snd_hda_get_connections(codec,
3242 spec->mono_nid,
3243 con_lst,
3244 HDA_MAX_NUM_INPUTS);
3245 if (num_cons <= 0 || num_cons > ARRAY_SIZE(stac92xx_mono_labels))
3246 return -EINVAL;
3248 for (i = 0; i < num_cons; i++) {
3249 mono_mux->items[mono_mux->num_items].label =
3250 stac92xx_mono_labels[i];
3251 mono_mux->items[mono_mux->num_items].index = i;
3252 mono_mux->num_items++;
3255 return stac92xx_add_control(spec, STAC_CTL_WIDGET_MONO_MUX,
3256 "Mono Mux", spec->mono_nid);
3259 /* create PC beep volume controls */
3260 static int stac92xx_auto_create_beep_ctls(struct hda_codec *codec,
3261 hda_nid_t nid)
3263 struct sigmatel_spec *spec = codec->spec;
3264 u32 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3265 int err, type = STAC_CTL_WIDGET_MUTE_BEEP;
3267 if (spec->anabeep_nid == nid)
3268 type = STAC_CTL_WIDGET_MUTE;
3270 /* check for mute support for the the amp */
3271 if ((caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT) {
3272 err = stac92xx_add_control(spec, type,
3273 "Beep Playback Switch",
3274 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3275 if (err < 0)
3276 return err;
3279 /* check to see if there is volume support for the amp */
3280 if ((caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3281 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL,
3282 "Beep Playback Volume",
3283 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3284 if (err < 0)
3285 return err;
3287 return 0;
3290 #ifdef CONFIG_SND_HDA_INPUT_BEEP
3291 #define stac92xx_dig_beep_switch_info snd_ctl_boolean_mono_info
3293 static int stac92xx_dig_beep_switch_get(struct snd_kcontrol *kcontrol,
3294 struct snd_ctl_elem_value *ucontrol)
3296 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3297 ucontrol->value.integer.value[0] = codec->beep->enabled;
3298 return 0;
3301 static int stac92xx_dig_beep_switch_put(struct snd_kcontrol *kcontrol,
3302 struct snd_ctl_elem_value *ucontrol)
3304 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3305 return snd_hda_enable_beep_device(codec, ucontrol->value.integer.value[0]);
3308 static struct snd_kcontrol_new stac92xx_dig_beep_ctrl = {
3309 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3310 .info = stac92xx_dig_beep_switch_info,
3311 .get = stac92xx_dig_beep_switch_get,
3312 .put = stac92xx_dig_beep_switch_put,
3315 static int stac92xx_beep_switch_ctl(struct hda_codec *codec)
3317 return stac92xx_add_control_temp(codec->spec, &stac92xx_dig_beep_ctrl,
3318 0, "Beep Playback Switch", 0);
3320 #endif
3322 static int stac92xx_auto_create_mux_input_ctls(struct hda_codec *codec)
3324 struct sigmatel_spec *spec = codec->spec;
3325 int i, j, err = 0;
3327 for (i = 0; i < spec->num_muxes; i++) {
3328 hda_nid_t nid;
3329 unsigned int wcaps;
3330 unsigned long val;
3332 nid = spec->mux_nids[i];
3333 wcaps = get_wcaps(codec, nid);
3334 if (!(wcaps & AC_WCAP_OUT_AMP))
3335 continue;
3337 /* check whether already the same control was created as
3338 * normal Capture Volume.
3340 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3341 for (j = 0; j < spec->num_caps; j++) {
3342 if (spec->capvols[j] == val)
3343 break;
3345 if (j < spec->num_caps)
3346 continue;
3348 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_VOL, i,
3349 "Mux Capture Volume", val);
3350 if (err < 0)
3351 return err;
3353 return 0;
3356 static const char *stac92xx_spdif_labels[3] = {
3357 "Digital Playback", "Analog Mux 1", "Analog Mux 2",
3360 static int stac92xx_auto_create_spdif_mux_ctls(struct hda_codec *codec)
3362 struct sigmatel_spec *spec = codec->spec;
3363 struct hda_input_mux *spdif_mux = &spec->private_smux;
3364 const char **labels = spec->spdif_labels;
3365 int i, num_cons;
3366 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
3368 num_cons = snd_hda_get_connections(codec,
3369 spec->smux_nids[0],
3370 con_lst,
3371 HDA_MAX_NUM_INPUTS);
3372 if (num_cons <= 0)
3373 return -EINVAL;
3375 if (!labels)
3376 labels = stac92xx_spdif_labels;
3378 for (i = 0; i < num_cons; i++) {
3379 spdif_mux->items[spdif_mux->num_items].label = labels[i];
3380 spdif_mux->items[spdif_mux->num_items].index = i;
3381 spdif_mux->num_items++;
3384 return 0;
3387 /* labels for dmic mux inputs */
3388 static const char *stac92xx_dmic_labels[5] = {
3389 "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
3390 "Digital Mic 3", "Digital Mic 4"
3393 static int get_connection_index(struct hda_codec *codec, hda_nid_t mux,
3394 hda_nid_t nid)
3396 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
3397 int i, nums;
3399 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
3400 for (i = 0; i < nums; i++)
3401 if (conn[i] == nid)
3402 return i;
3403 return -1;
3406 /* create a volume assigned to the given pin (only if supported) */
3407 /* return 1 if the volume control is created */
3408 static int create_elem_capture_vol(struct hda_codec *codec, hda_nid_t nid,
3409 const char *label, int direction)
3411 unsigned int caps, nums;
3412 char name[32];
3413 int err;
3415 if (direction == HDA_OUTPUT)
3416 caps = AC_WCAP_OUT_AMP;
3417 else
3418 caps = AC_WCAP_IN_AMP;
3419 if (!(get_wcaps(codec, nid) & caps))
3420 return 0;
3421 caps = query_amp_caps(codec, nid, direction);
3422 nums = (caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT;
3423 if (!nums)
3424 return 0;
3425 snprintf(name, sizeof(name), "%s Capture Volume", label);
3426 err = stac92xx_add_control(codec->spec, STAC_CTL_WIDGET_VOL, name,
3427 HDA_COMPOSE_AMP_VAL(nid, 3, 0, direction));
3428 if (err < 0)
3429 return err;
3430 return 1;
3433 /* create playback/capture controls for input pins on dmic capable codecs */
3434 static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
3435 const struct auto_pin_cfg *cfg)
3437 struct sigmatel_spec *spec = codec->spec;
3438 struct hda_input_mux *imux = &spec->private_imux;
3439 struct hda_input_mux *dimux = &spec->private_dimux;
3440 int err, i, active_mics;
3441 unsigned int def_conf;
3443 dimux->items[dimux->num_items].label = stac92xx_dmic_labels[0];
3444 dimux->items[dimux->num_items].index = 0;
3445 dimux->num_items++;
3447 active_mics = 0;
3448 for (i = 0; i < spec->num_dmics; i++) {
3449 /* check the validity: sometimes it's a dead vendor-spec node */
3450 if (get_wcaps_type(get_wcaps(codec, spec->dmic_nids[i]))
3451 != AC_WID_PIN)
3452 continue;
3453 def_conf = snd_hda_codec_get_pincfg(codec, spec->dmic_nids[i]);
3454 if (get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)
3455 active_mics++;
3458 for (i = 0; i < spec->num_dmics; i++) {
3459 hda_nid_t nid;
3460 int index;
3461 const char *label;
3463 nid = spec->dmic_nids[i];
3464 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
3465 continue;
3466 def_conf = snd_hda_codec_get_pincfg(codec, nid);
3467 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
3468 continue;
3470 index = get_connection_index(codec, spec->dmux_nids[0], nid);
3471 if (index < 0)
3472 continue;
3474 if (active_mics == 1)
3475 label = "Digital Mic";
3476 else
3477 label = stac92xx_dmic_labels[dimux->num_items];
3479 err = create_elem_capture_vol(codec, nid, label, HDA_INPUT);
3480 if (err < 0)
3481 return err;
3482 if (!err) {
3483 err = create_elem_capture_vol(codec, nid, label,
3484 HDA_OUTPUT);
3485 if (err < 0)
3486 return err;
3489 dimux->items[dimux->num_items].label = label;
3490 dimux->items[dimux->num_items].index = index;
3491 dimux->num_items++;
3492 if (snd_hda_get_bool_hint(codec, "separate_dmux") != 1) {
3493 imux->items[imux->num_items].label = label;
3494 imux->items[imux->num_items].index = index;
3495 imux->num_items++;
3499 return 0;
3502 static int check_mic_pin(struct hda_codec *codec, hda_nid_t nid,
3503 hda_nid_t *fixed, hda_nid_t *ext)
3505 unsigned int cfg;
3507 if (!nid)
3508 return 0;
3509 cfg = snd_hda_codec_get_pincfg(codec, nid);
3510 switch (get_defcfg_connect(cfg)) {
3511 case AC_JACK_PORT_FIXED:
3512 if (*fixed)
3513 return 1; /* already occupied */
3514 *fixed = nid;
3515 break;
3516 case AC_JACK_PORT_COMPLEX:
3517 if (*ext)
3518 return 1; /* already occupied */
3519 *ext = nid;
3520 break;
3522 return 0;
3525 static int set_mic_route(struct hda_codec *codec,
3526 struct sigmatel_mic_route *mic,
3527 hda_nid_t pin)
3529 struct sigmatel_spec *spec = codec->spec;
3530 struct auto_pin_cfg *cfg = &spec->autocfg;
3531 int i;
3533 mic->pin = pin;
3534 for (i = AUTO_PIN_MIC; i <= AUTO_PIN_FRONT_MIC; i++)
3535 if (pin == cfg->input_pins[i])
3536 break;
3537 if (i <= AUTO_PIN_FRONT_MIC) {
3538 /* analog pin */
3539 i = get_connection_index(codec, spec->mux_nids[0], pin);
3540 if (i < 0)
3541 return -1;
3542 mic->mux_idx = i;
3543 mic->dmux_idx = -1;
3544 if (spec->dmux_nids)
3545 mic->dmux_idx = get_connection_index(codec,
3546 spec->dmux_nids[0],
3547 spec->mux_nids[0]);
3548 } else if (spec->dmux_nids) {
3549 /* digital pin */
3550 i = get_connection_index(codec, spec->dmux_nids[0], pin);
3551 if (i < 0)
3552 return -1;
3553 mic->dmux_idx = i;
3554 mic->mux_idx = -1;
3555 if (spec->mux_nids)
3556 mic->mux_idx = get_connection_index(codec,
3557 spec->mux_nids[0],
3558 spec->dmux_nids[0]);
3560 return 0;
3563 /* return non-zero if the device is for automatic mic switch */
3564 static int stac_check_auto_mic(struct hda_codec *codec)
3566 struct sigmatel_spec *spec = codec->spec;
3567 struct auto_pin_cfg *cfg = &spec->autocfg;
3568 hda_nid_t fixed, ext;
3569 int i;
3571 for (i = AUTO_PIN_LINE; i < AUTO_PIN_LAST; i++) {
3572 if (cfg->input_pins[i])
3573 return 0; /* must be exclusively mics */
3575 fixed = ext = 0;
3576 for (i = AUTO_PIN_MIC; i <= AUTO_PIN_FRONT_MIC; i++)
3577 if (check_mic_pin(codec, cfg->input_pins[i], &fixed, &ext))
3578 return 0;
3579 for (i = 0; i < spec->num_dmics; i++)
3580 if (check_mic_pin(codec, spec->dmic_nids[i], &fixed, &ext))
3581 return 0;
3582 if (!fixed || !ext)
3583 return 0;
3584 if (!(get_wcaps(codec, ext) & AC_WCAP_UNSOL_CAP))
3585 return 0; /* no unsol support */
3586 if (set_mic_route(codec, &spec->ext_mic, ext) ||
3587 set_mic_route(codec, &spec->int_mic, fixed))
3588 return 0; /* something is wrong */
3589 return 1;
3592 /* create playback/capture controls for input pins */
3593 static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
3595 struct sigmatel_spec *spec = codec->spec;
3596 struct hda_input_mux *imux = &spec->private_imux;
3597 int i, j;
3599 for (i = 0; i < AUTO_PIN_LAST; i++) {
3600 hda_nid_t nid = cfg->input_pins[i];
3601 int index, err;
3603 if (!nid)
3604 continue;
3605 index = -1;
3606 for (j = 0; j < spec->num_muxes; j++) {
3607 index = get_connection_index(codec, spec->mux_nids[j],
3608 nid);
3609 if (index >= 0)
3610 break;
3612 if (index < 0)
3613 continue;
3615 err = create_elem_capture_vol(codec, nid,
3616 auto_pin_cfg_labels[i],
3617 HDA_INPUT);
3618 if (err < 0)
3619 return err;
3621 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
3622 imux->items[imux->num_items].index = index;
3623 imux->num_items++;
3625 spec->num_analog_muxes = imux->num_items;
3627 if (imux->num_items) {
3629 * Set the current input for the muxes.
3630 * The STAC9221 has two input muxes with identical source
3631 * NID lists. Hopefully this won't get confused.
3633 for (i = 0; i < spec->num_muxes; i++) {
3634 snd_hda_codec_write_cache(codec, spec->mux_nids[i], 0,
3635 AC_VERB_SET_CONNECT_SEL,
3636 imux->items[0].index);
3640 return 0;
3643 static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
3645 struct sigmatel_spec *spec = codec->spec;
3646 int i;
3648 for (i = 0; i < spec->autocfg.line_outs; i++) {
3649 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3650 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
3654 static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
3656 struct sigmatel_spec *spec = codec->spec;
3657 int i;
3659 for (i = 0; i < spec->autocfg.hp_outs; i++) {
3660 hda_nid_t pin;
3661 pin = spec->autocfg.hp_pins[i];
3662 if (pin) /* connect to front */
3663 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
3665 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
3666 hda_nid_t pin;
3667 pin = spec->autocfg.speaker_pins[i];
3668 if (pin) /* connect to front */
3669 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
3673 static int is_dual_headphones(struct hda_codec *codec)
3675 struct sigmatel_spec *spec = codec->spec;
3676 int i, valid_hps;
3678 if (spec->autocfg.line_out_type != AUTO_PIN_SPEAKER_OUT ||
3679 spec->autocfg.hp_outs <= 1)
3680 return 0;
3681 valid_hps = 0;
3682 for (i = 0; i < spec->autocfg.hp_outs; i++) {
3683 hda_nid_t nid = spec->autocfg.hp_pins[i];
3684 unsigned int cfg = snd_hda_codec_get_pincfg(codec, nid);
3685 if (get_defcfg_location(cfg) & AC_JACK_LOC_SEPARATE)
3686 continue;
3687 valid_hps++;
3689 return (valid_hps > 1);
3693 static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out, hda_nid_t dig_in)
3695 struct sigmatel_spec *spec = codec->spec;
3696 int hp_swap = 0;
3697 int i, err;
3699 if ((err = snd_hda_parse_pin_def_config(codec,
3700 &spec->autocfg,
3701 spec->dmic_nids)) < 0)
3702 return err;
3703 if (! spec->autocfg.line_outs)
3704 return 0; /* can't find valid pin config */
3706 /* If we have no real line-out pin and multiple hp-outs, HPs should
3707 * be set up as multi-channel outputs.
3709 if (is_dual_headphones(codec)) {
3710 /* Copy hp_outs to line_outs, backup line_outs in
3711 * speaker_outs so that the following routines can handle
3712 * HP pins as primary outputs.
3714 snd_printdd("stac92xx: Enabling multi-HPs workaround\n");
3715 memcpy(spec->autocfg.speaker_pins, spec->autocfg.line_out_pins,
3716 sizeof(spec->autocfg.line_out_pins));
3717 spec->autocfg.speaker_outs = spec->autocfg.line_outs;
3718 memcpy(spec->autocfg.line_out_pins, spec->autocfg.hp_pins,
3719 sizeof(spec->autocfg.hp_pins));
3720 spec->autocfg.line_outs = spec->autocfg.hp_outs;
3721 spec->autocfg.line_out_type = AUTO_PIN_HP_OUT;
3722 spec->autocfg.hp_outs = 0;
3723 hp_swap = 1;
3725 if (spec->autocfg.mono_out_pin) {
3726 int dir = get_wcaps(codec, spec->autocfg.mono_out_pin) &
3727 (AC_WCAP_OUT_AMP | AC_WCAP_IN_AMP);
3728 u32 caps = query_amp_caps(codec,
3729 spec->autocfg.mono_out_pin, dir);
3730 hda_nid_t conn_list[1];
3732 /* get the mixer node and then the mono mux if it exists */
3733 if (snd_hda_get_connections(codec,
3734 spec->autocfg.mono_out_pin, conn_list, 1) &&
3735 snd_hda_get_connections(codec, conn_list[0],
3736 conn_list, 1) > 0) {
3738 int wcaps = get_wcaps(codec, conn_list[0]);
3739 int wid_type = get_wcaps_type(wcaps);
3740 /* LR swap check, some stac925x have a mux that
3741 * changes the DACs output path instead of the
3742 * mono-mux path.
3744 if (wid_type == AC_WID_AUD_SEL &&
3745 !(wcaps & AC_WCAP_LR_SWAP))
3746 spec->mono_nid = conn_list[0];
3748 if (dir) {
3749 hda_nid_t nid = spec->autocfg.mono_out_pin;
3751 /* most mono outs have a least a mute/unmute switch */
3752 dir = (dir & AC_WCAP_OUT_AMP) ? HDA_OUTPUT : HDA_INPUT;
3753 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE,
3754 "Mono Playback Switch",
3755 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
3756 if (err < 0)
3757 return err;
3758 /* check for volume support for the amp */
3759 if ((caps & AC_AMPCAP_NUM_STEPS)
3760 >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3761 err = stac92xx_add_control(spec,
3762 STAC_CTL_WIDGET_VOL,
3763 "Mono Playback Volume",
3764 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
3765 if (err < 0)
3766 return err;
3770 stac92xx_auto_set_pinctl(codec, spec->autocfg.mono_out_pin,
3771 AC_PINCTL_OUT_EN);
3774 if (!spec->multiout.num_dacs) {
3775 err = stac92xx_auto_fill_dac_nids(codec);
3776 if (err < 0)
3777 return err;
3778 err = stac92xx_auto_create_multi_out_ctls(codec,
3779 &spec->autocfg);
3780 if (err < 0)
3781 return err;
3784 /* setup analog beep controls */
3785 if (spec->anabeep_nid > 0) {
3786 err = stac92xx_auto_create_beep_ctls(codec,
3787 spec->anabeep_nid);
3788 if (err < 0)
3789 return err;
3792 /* setup digital beep controls and input device */
3793 #ifdef CONFIG_SND_HDA_INPUT_BEEP
3794 if (spec->digbeep_nid > 0) {
3795 hda_nid_t nid = spec->digbeep_nid;
3796 unsigned int caps;
3798 err = stac92xx_auto_create_beep_ctls(codec, nid);
3799 if (err < 0)
3800 return err;
3801 err = snd_hda_attach_beep_device(codec, nid);
3802 if (err < 0)
3803 return err;
3804 if (codec->beep) {
3805 /* IDT/STAC codecs have linear beep tone parameter */
3806 codec->beep->linear_tone = spec->linear_tone_beep;
3807 /* if no beep switch is available, make its own one */
3808 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3809 if (!(caps & AC_AMPCAP_MUTE)) {
3810 err = stac92xx_beep_switch_ctl(codec);
3811 if (err < 0)
3812 return err;
3816 #endif
3818 err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg);
3819 if (err < 0)
3820 return err;
3822 /* All output parsing done, now restore the swapped hp pins */
3823 if (hp_swap) {
3824 memcpy(spec->autocfg.hp_pins, spec->autocfg.line_out_pins,
3825 sizeof(spec->autocfg.hp_pins));
3826 spec->autocfg.hp_outs = spec->autocfg.line_outs;
3827 spec->autocfg.line_out_type = AUTO_PIN_HP_OUT;
3828 spec->autocfg.line_outs = 0;
3831 if (stac_check_auto_mic(codec)) {
3832 spec->auto_mic = 1;
3833 /* only one capture for auto-mic */
3834 spec->num_adcs = 1;
3835 spec->num_caps = 1;
3836 spec->num_muxes = 1;
3839 for (i = 0; i < spec->num_caps; i++) {
3840 err = stac92xx_add_capvol_ctls(codec, spec->capvols[i],
3841 spec->capsws[i], i);
3842 if (err < 0)
3843 return err;
3846 err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg);
3847 if (err < 0)
3848 return err;
3850 if (spec->mono_nid > 0) {
3851 err = stac92xx_auto_create_mono_output_ctls(codec);
3852 if (err < 0)
3853 return err;
3855 if (spec->num_dmics > 0 && !spec->dinput_mux)
3856 if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
3857 &spec->autocfg)) < 0)
3858 return err;
3859 if (spec->num_muxes > 0) {
3860 err = stac92xx_auto_create_mux_input_ctls(codec);
3861 if (err < 0)
3862 return err;
3864 if (spec->num_smuxes > 0) {
3865 err = stac92xx_auto_create_spdif_mux_ctls(codec);
3866 if (err < 0)
3867 return err;
3870 err = stac92xx_add_input_source(spec);
3871 if (err < 0)
3872 return err;
3874 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3875 if (spec->multiout.max_channels > 2)
3876 spec->surr_switch = 1;
3878 if (spec->autocfg.dig_outs)
3879 spec->multiout.dig_out_nid = dig_out;
3880 if (dig_in && spec->autocfg.dig_in_pin)
3881 spec->dig_in_nid = dig_in;
3883 if (spec->kctls.list)
3884 spec->mixers[spec->num_mixers++] = spec->kctls.list;
3886 spec->input_mux = &spec->private_imux;
3887 if (!spec->dinput_mux)
3888 spec->dinput_mux = &spec->private_dimux;
3889 spec->sinput_mux = &spec->private_smux;
3890 spec->mono_mux = &spec->private_mono_mux;
3891 return 1;
3894 /* add playback controls for HP output */
3895 static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
3896 struct auto_pin_cfg *cfg)
3898 struct sigmatel_spec *spec = codec->spec;
3899 hda_nid_t pin = cfg->hp_pins[0];
3900 unsigned int wid_caps;
3902 if (! pin)
3903 return 0;
3905 wid_caps = get_wcaps(codec, pin);
3906 if (wid_caps & AC_WCAP_UNSOL_CAP)
3907 spec->hp_detect = 1;
3909 return 0;
3912 /* add playback controls for LFE output */
3913 static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
3914 struct auto_pin_cfg *cfg)
3916 struct sigmatel_spec *spec = codec->spec;
3917 int err;
3918 hda_nid_t lfe_pin = 0x0;
3919 int i;
3922 * search speaker outs and line outs for a mono speaker pin
3923 * with an amp. If one is found, add LFE controls
3924 * for it.
3926 for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
3927 hda_nid_t pin = spec->autocfg.speaker_pins[i];
3928 unsigned int wcaps = get_wcaps(codec, pin);
3929 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
3930 if (wcaps == AC_WCAP_OUT_AMP)
3931 /* found a mono speaker with an amp, must be lfe */
3932 lfe_pin = pin;
3935 /* if speaker_outs is 0, then speakers may be in line_outs */
3936 if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
3937 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
3938 hda_nid_t pin = spec->autocfg.line_out_pins[i];
3939 unsigned int defcfg;
3940 defcfg = snd_hda_codec_get_pincfg(codec, pin);
3941 if (get_defcfg_device(defcfg) == AC_JACK_SPEAKER) {
3942 unsigned int wcaps = get_wcaps(codec, pin);
3943 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
3944 if (wcaps == AC_WCAP_OUT_AMP)
3945 /* found a mono speaker with an amp,
3946 must be lfe */
3947 lfe_pin = pin;
3952 if (lfe_pin) {
3953 err = create_controls(codec, "LFE", lfe_pin, 1);
3954 if (err < 0)
3955 return err;
3958 return 0;
3961 static int stac9200_parse_auto_config(struct hda_codec *codec)
3963 struct sigmatel_spec *spec = codec->spec;
3964 int err;
3966 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
3967 return err;
3969 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
3970 return err;
3972 if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
3973 return err;
3975 if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
3976 return err;
3978 if (spec->num_muxes > 0) {
3979 err = stac92xx_auto_create_mux_input_ctls(codec);
3980 if (err < 0)
3981 return err;
3984 err = stac92xx_add_input_source(spec);
3985 if (err < 0)
3986 return err;
3988 if (spec->autocfg.dig_outs)
3989 spec->multiout.dig_out_nid = 0x05;
3990 if (spec->autocfg.dig_in_pin)
3991 spec->dig_in_nid = 0x04;
3993 if (spec->kctls.list)
3994 spec->mixers[spec->num_mixers++] = spec->kctls.list;
3996 spec->input_mux = &spec->private_imux;
3997 spec->dinput_mux = &spec->private_dimux;
3999 return 1;
4003 * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
4004 * funky external mute control using GPIO pins.
4007 static void stac_gpio_set(struct hda_codec *codec, unsigned int mask,
4008 unsigned int dir_mask, unsigned int data)
4010 unsigned int gpiostate, gpiomask, gpiodir;
4012 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
4013 AC_VERB_GET_GPIO_DATA, 0);
4014 gpiostate = (gpiostate & ~dir_mask) | (data & dir_mask);
4016 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
4017 AC_VERB_GET_GPIO_MASK, 0);
4018 gpiomask |= mask;
4020 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
4021 AC_VERB_GET_GPIO_DIRECTION, 0);
4022 gpiodir |= dir_mask;
4024 /* Configure GPIOx as CMOS */
4025 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
4027 snd_hda_codec_write(codec, codec->afg, 0,
4028 AC_VERB_SET_GPIO_MASK, gpiomask);
4029 snd_hda_codec_read(codec, codec->afg, 0,
4030 AC_VERB_SET_GPIO_DIRECTION, gpiodir); /* sync */
4032 msleep(1);
4034 snd_hda_codec_read(codec, codec->afg, 0,
4035 AC_VERB_SET_GPIO_DATA, gpiostate); /* sync */
4038 #ifdef CONFIG_SND_HDA_INPUT_JACK
4039 static void stac92xx_free_jack_priv(struct snd_jack *jack)
4041 struct sigmatel_jack *jacks = jack->private_data;
4042 jacks->nid = 0;
4043 jacks->jack = NULL;
4045 #endif
4047 static int stac92xx_add_jack(struct hda_codec *codec,
4048 hda_nid_t nid, int type)
4050 #ifdef CONFIG_SND_HDA_INPUT_JACK
4051 struct sigmatel_spec *spec = codec->spec;
4052 struct sigmatel_jack *jack;
4053 int def_conf = snd_hda_codec_get_pincfg(codec, nid);
4054 int connectivity = get_defcfg_connect(def_conf);
4055 char name[32];
4056 int err;
4058 if (connectivity && connectivity != AC_JACK_PORT_FIXED)
4059 return 0;
4061 snd_array_init(&spec->jacks, sizeof(*jack), 32);
4062 jack = snd_array_new(&spec->jacks);
4063 if (!jack)
4064 return -ENOMEM;
4065 jack->nid = nid;
4066 jack->type = type;
4068 snprintf(name, sizeof(name), "%s at %s %s Jack",
4069 snd_hda_get_jack_type(def_conf),
4070 snd_hda_get_jack_connectivity(def_conf),
4071 snd_hda_get_jack_location(def_conf));
4073 err = snd_jack_new(codec->bus->card, name, type, &jack->jack);
4074 if (err < 0) {
4075 jack->nid = 0;
4076 return err;
4078 jack->jack->private_data = jack;
4079 jack->jack->private_free = stac92xx_free_jack_priv;
4080 #endif
4081 return 0;
4084 static int stac_add_event(struct sigmatel_spec *spec, hda_nid_t nid,
4085 unsigned char type, int data)
4087 struct sigmatel_event *event;
4089 snd_array_init(&spec->events, sizeof(*event), 32);
4090 event = snd_array_new(&spec->events);
4091 if (!event)
4092 return -ENOMEM;
4093 event->nid = nid;
4094 event->type = type;
4095 event->tag = spec->events.used;
4096 event->data = data;
4098 return event->tag;
4101 static struct sigmatel_event *stac_get_event(struct hda_codec *codec,
4102 hda_nid_t nid)
4104 struct sigmatel_spec *spec = codec->spec;
4105 struct sigmatel_event *event = spec->events.list;
4106 int i;
4108 for (i = 0; i < spec->events.used; i++, event++) {
4109 if (event->nid == nid)
4110 return event;
4112 return NULL;
4115 static struct sigmatel_event *stac_get_event_from_tag(struct hda_codec *codec,
4116 unsigned char tag)
4118 struct sigmatel_spec *spec = codec->spec;
4119 struct sigmatel_event *event = spec->events.list;
4120 int i;
4122 for (i = 0; i < spec->events.used; i++, event++) {
4123 if (event->tag == tag)
4124 return event;
4126 return NULL;
4129 /* check if given nid is a valid pin and no other events are assigned
4130 * to it. If OK, assign the event, set the unsol flag, and returns 1.
4131 * Otherwise, returns zero.
4133 static int enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
4134 unsigned int type)
4136 struct sigmatel_event *event;
4137 int tag;
4139 if (!(get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP))
4140 return 0;
4141 event = stac_get_event(codec, nid);
4142 if (event) {
4143 if (event->type != type)
4144 return 0;
4145 tag = event->tag;
4146 } else {
4147 tag = stac_add_event(codec->spec, nid, type, 0);
4148 if (tag < 0)
4149 return 0;
4151 snd_hda_codec_write_cache(codec, nid, 0,
4152 AC_VERB_SET_UNSOLICITED_ENABLE,
4153 AC_USRSP_EN | tag);
4154 return 1;
4157 static int is_nid_hp_pin(struct auto_pin_cfg *cfg, hda_nid_t nid)
4159 int i;
4160 for (i = 0; i < cfg->hp_outs; i++)
4161 if (cfg->hp_pins[i] == nid)
4162 return 1; /* nid is a HP-Out */
4164 return 0; /* nid is not a HP-Out */
4167 static void stac92xx_power_down(struct hda_codec *codec)
4169 struct sigmatel_spec *spec = codec->spec;
4171 /* power down inactive DACs */
4172 hda_nid_t *dac;
4173 for (dac = spec->dac_list; *dac; dac++)
4174 if (!check_all_dac_nids(spec, *dac))
4175 snd_hda_codec_write(codec, *dac, 0,
4176 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
4179 static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
4180 int enable);
4182 static inline int get_int_hint(struct hda_codec *codec, const char *key,
4183 int *valp)
4185 const char *p;
4186 p = snd_hda_get_hint(codec, key);
4187 if (p) {
4188 unsigned long val;
4189 if (!strict_strtoul(p, 0, &val)) {
4190 *valp = val;
4191 return 1;
4194 return 0;
4197 /* override some hints from the hwdep entry */
4198 static void stac_store_hints(struct hda_codec *codec)
4200 struct sigmatel_spec *spec = codec->spec;
4201 int val;
4203 val = snd_hda_get_bool_hint(codec, "hp_detect");
4204 if (val >= 0)
4205 spec->hp_detect = val;
4206 if (get_int_hint(codec, "gpio_mask", &spec->gpio_mask)) {
4207 spec->eapd_mask = spec->gpio_dir = spec->gpio_data =
4208 spec->gpio_mask;
4210 if (get_int_hint(codec, "gpio_dir", &spec->gpio_dir))
4211 spec->gpio_mask &= spec->gpio_mask;
4212 if (get_int_hint(codec, "gpio_data", &spec->gpio_data))
4213 spec->gpio_dir &= spec->gpio_mask;
4214 if (get_int_hint(codec, "eapd_mask", &spec->eapd_mask))
4215 spec->eapd_mask &= spec->gpio_mask;
4216 if (get_int_hint(codec, "gpio_mute", &spec->gpio_mute))
4217 spec->gpio_mute &= spec->gpio_mask;
4218 val = snd_hda_get_bool_hint(codec, "eapd_switch");
4219 if (val >= 0)
4220 spec->eapd_switch = val;
4221 get_int_hint(codec, "gpio_led_polarity", &spec->gpio_led_polarity);
4222 if (get_int_hint(codec, "gpio_led", &spec->gpio_led)) {
4223 spec->gpio_mask |= spec->gpio_led;
4224 spec->gpio_dir |= spec->gpio_led;
4225 if (spec->gpio_led_polarity)
4226 spec->gpio_data |= spec->gpio_led;
4230 static int stac92xx_init(struct hda_codec *codec)
4232 struct sigmatel_spec *spec = codec->spec;
4233 struct auto_pin_cfg *cfg = &spec->autocfg;
4234 unsigned int gpio;
4235 int i;
4237 snd_hda_sequence_write(codec, spec->init);
4239 /* power down adcs initially */
4240 if (spec->powerdown_adcs)
4241 for (i = 0; i < spec->num_adcs; i++)
4242 snd_hda_codec_write(codec,
4243 spec->adc_nids[i], 0,
4244 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
4246 /* override some hints */
4247 stac_store_hints(codec);
4249 /* set up GPIO */
4250 gpio = spec->gpio_data;
4251 /* turn on EAPD statically when spec->eapd_switch isn't set.
4252 * otherwise, unsol event will turn it on/off dynamically
4254 if (!spec->eapd_switch)
4255 gpio |= spec->eapd_mask;
4256 stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, gpio);
4258 /* set up pins */
4259 if (spec->hp_detect) {
4260 /* Enable unsolicited responses on the HP widget */
4261 for (i = 0; i < cfg->hp_outs; i++) {
4262 hda_nid_t nid = cfg->hp_pins[i];
4263 enable_pin_detect(codec, nid, STAC_HP_EVENT);
4265 if (cfg->line_out_type == AUTO_PIN_LINE_OUT &&
4266 cfg->speaker_outs > 0) {
4267 /* enable pin-detect for line-outs as well */
4268 for (i = 0; i < cfg->line_outs; i++) {
4269 hda_nid_t nid = cfg->line_out_pins[i];
4270 enable_pin_detect(codec, nid, STAC_LO_EVENT);
4274 /* force to enable the first line-out; the others are set up
4275 * in unsol_event
4277 stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
4278 AC_PINCTL_OUT_EN);
4279 /* fake event to set up pins */
4280 if (cfg->hp_pins[0])
4281 stac_issue_unsol_event(codec, cfg->hp_pins[0]);
4282 else if (cfg->line_out_pins[0])
4283 stac_issue_unsol_event(codec, cfg->line_out_pins[0]);
4284 } else {
4285 stac92xx_auto_init_multi_out(codec);
4286 stac92xx_auto_init_hp_out(codec);
4287 for (i = 0; i < cfg->hp_outs; i++)
4288 stac_toggle_power_map(codec, cfg->hp_pins[i], 1);
4290 if (spec->auto_mic) {
4291 /* initialize connection to analog input */
4292 if (spec->dmux_nids)
4293 snd_hda_codec_write_cache(codec, spec->dmux_nids[0], 0,
4294 AC_VERB_SET_CONNECT_SEL, 0);
4295 if (enable_pin_detect(codec, spec->ext_mic.pin, STAC_MIC_EVENT))
4296 stac_issue_unsol_event(codec, spec->ext_mic.pin);
4298 for (i = 0; i < AUTO_PIN_LAST; i++) {
4299 hda_nid_t nid = cfg->input_pins[i];
4300 if (nid) {
4301 unsigned int pinctl, conf;
4302 if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC) {
4303 /* for mic pins, force to initialize */
4304 pinctl = stac92xx_get_default_vref(codec, nid);
4305 pinctl |= AC_PINCTL_IN_EN;
4306 stac92xx_auto_set_pinctl(codec, nid, pinctl);
4307 } else {
4308 pinctl = snd_hda_codec_read(codec, nid, 0,
4309 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4310 /* if PINCTL already set then skip */
4311 /* Also, if both INPUT and OUTPUT are set,
4312 * it must be a BIOS bug; need to override, too
4314 if (!(pinctl & AC_PINCTL_IN_EN) ||
4315 (pinctl & AC_PINCTL_OUT_EN)) {
4316 pinctl &= ~AC_PINCTL_OUT_EN;
4317 pinctl |= AC_PINCTL_IN_EN;
4318 stac92xx_auto_set_pinctl(codec, nid,
4319 pinctl);
4322 conf = snd_hda_codec_get_pincfg(codec, nid);
4323 if (get_defcfg_connect(conf) != AC_JACK_PORT_FIXED) {
4324 if (enable_pin_detect(codec, nid,
4325 STAC_INSERT_EVENT))
4326 stac_issue_unsol_event(codec, nid);
4330 for (i = 0; i < spec->num_dmics; i++)
4331 stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
4332 AC_PINCTL_IN_EN);
4333 if (cfg->dig_out_pins[0])
4334 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pins[0],
4335 AC_PINCTL_OUT_EN);
4336 if (cfg->dig_in_pin)
4337 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
4338 AC_PINCTL_IN_EN);
4339 for (i = 0; i < spec->num_pwrs; i++) {
4340 hda_nid_t nid = spec->pwr_nids[i];
4341 int pinctl, def_conf;
4343 /* power on when no jack detection is available */
4344 if (!spec->hp_detect) {
4345 stac_toggle_power_map(codec, nid, 1);
4346 continue;
4349 if (is_nid_hp_pin(cfg, nid))
4350 continue; /* already has an unsol event */
4352 pinctl = snd_hda_codec_read(codec, nid, 0,
4353 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4354 /* outputs are only ports capable of power management
4355 * any attempts on powering down a input port cause the
4356 * referenced VREF to act quirky.
4358 if (pinctl & AC_PINCTL_IN_EN) {
4359 stac_toggle_power_map(codec, nid, 1);
4360 continue;
4362 def_conf = snd_hda_codec_get_pincfg(codec, nid);
4363 def_conf = get_defcfg_connect(def_conf);
4364 /* skip any ports that don't have jacks since presence
4365 * detection is useless */
4366 if (def_conf != AC_JACK_PORT_COMPLEX) {
4367 if (def_conf != AC_JACK_PORT_NONE)
4368 stac_toggle_power_map(codec, nid, 1);
4369 continue;
4371 if (enable_pin_detect(codec, nid, STAC_PWR_EVENT))
4372 stac_issue_unsol_event(codec, nid);
4375 #ifdef CONFIG_SND_HDA_POWER_SAVE
4376 /* sync mute LED */
4377 if (spec->gpio_led && codec->patch_ops.check_power_status)
4378 codec->patch_ops.check_power_status(codec, 0x01);
4379 #endif
4380 if (spec->dac_list)
4381 stac92xx_power_down(codec);
4382 return 0;
4385 static void stac92xx_free_jacks(struct hda_codec *codec)
4387 #ifdef CONFIG_SND_HDA_INPUT_JACK
4388 /* free jack instances manually when clearing/reconfiguring */
4389 struct sigmatel_spec *spec = codec->spec;
4390 if (!codec->bus->shutdown && spec->jacks.list) {
4391 struct sigmatel_jack *jacks = spec->jacks.list;
4392 int i;
4393 for (i = 0; i < spec->jacks.used; i++, jacks++) {
4394 if (jacks->jack)
4395 snd_device_free(codec->bus->card, jacks->jack);
4398 snd_array_free(&spec->jacks);
4399 #endif
4402 static void stac92xx_free_kctls(struct hda_codec *codec)
4404 struct sigmatel_spec *spec = codec->spec;
4406 if (spec->kctls.list) {
4407 struct snd_kcontrol_new *kctl = spec->kctls.list;
4408 int i;
4409 for (i = 0; i < spec->kctls.used; i++)
4410 kfree(kctl[i].name);
4412 snd_array_free(&spec->kctls);
4415 static void stac92xx_shutup(struct hda_codec *codec)
4417 struct sigmatel_spec *spec = codec->spec;
4419 snd_hda_shutup_pins(codec);
4421 if (spec->eapd_mask)
4422 stac_gpio_set(codec, spec->gpio_mask,
4423 spec->gpio_dir, spec->gpio_data &
4424 ~spec->eapd_mask);
4427 static void stac92xx_free(struct hda_codec *codec)
4429 struct sigmatel_spec *spec = codec->spec;
4431 if (! spec)
4432 return;
4434 stac92xx_shutup(codec);
4435 stac92xx_free_jacks(codec);
4436 snd_array_free(&spec->events);
4438 kfree(spec);
4439 snd_hda_detach_beep_device(codec);
4442 static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
4443 unsigned int flag)
4445 unsigned int old_ctl, pin_ctl;
4447 pin_ctl = snd_hda_codec_read(codec, nid,
4448 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
4450 if (pin_ctl & AC_PINCTL_IN_EN) {
4452 * we need to check the current set-up direction of
4453 * shared input pins since they can be switched via
4454 * "xxx as Output" mixer switch
4456 struct sigmatel_spec *spec = codec->spec;
4457 if (nid == spec->line_switch || nid == spec->mic_switch)
4458 return;
4461 old_ctl = pin_ctl;
4462 /* if setting pin direction bits, clear the current
4463 direction bits first */
4464 if (flag & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))
4465 pin_ctl &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
4467 pin_ctl |= flag;
4468 if (old_ctl != pin_ctl)
4469 snd_hda_codec_write_cache(codec, nid, 0,
4470 AC_VERB_SET_PIN_WIDGET_CONTROL,
4471 pin_ctl);
4474 static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
4475 unsigned int flag)
4477 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
4478 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
4479 if (pin_ctl & flag)
4480 snd_hda_codec_write_cache(codec, nid, 0,
4481 AC_VERB_SET_PIN_WIDGET_CONTROL,
4482 pin_ctl & ~flag);
4485 static inline int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
4487 if (!nid)
4488 return 0;
4489 return snd_hda_jack_detect(codec, nid);
4492 static void stac92xx_line_out_detect(struct hda_codec *codec,
4493 int presence)
4495 struct sigmatel_spec *spec = codec->spec;
4496 struct auto_pin_cfg *cfg = &spec->autocfg;
4497 int i;
4499 for (i = 0; i < cfg->line_outs; i++) {
4500 if (presence)
4501 break;
4502 presence = get_pin_presence(codec, cfg->line_out_pins[i]);
4503 if (presence) {
4504 unsigned int pinctl;
4505 pinctl = snd_hda_codec_read(codec,
4506 cfg->line_out_pins[i], 0,
4507 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4508 if (pinctl & AC_PINCTL_IN_EN)
4509 presence = 0; /* mic- or line-input */
4513 if (presence) {
4514 /* disable speakers */
4515 for (i = 0; i < cfg->speaker_outs; i++)
4516 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
4517 AC_PINCTL_OUT_EN);
4518 if (spec->eapd_mask && spec->eapd_switch)
4519 stac_gpio_set(codec, spec->gpio_mask,
4520 spec->gpio_dir, spec->gpio_data &
4521 ~spec->eapd_mask);
4522 } else {
4523 /* enable speakers */
4524 for (i = 0; i < cfg->speaker_outs; i++)
4525 stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
4526 AC_PINCTL_OUT_EN);
4527 if (spec->eapd_mask && spec->eapd_switch)
4528 stac_gpio_set(codec, spec->gpio_mask,
4529 spec->gpio_dir, spec->gpio_data |
4530 spec->eapd_mask);
4534 /* return non-zero if the hp-pin of the given array index isn't
4535 * a jack-detection target
4537 static int no_hp_sensing(struct sigmatel_spec *spec, int i)
4539 struct auto_pin_cfg *cfg = &spec->autocfg;
4541 /* ignore sensing of shared line and mic jacks */
4542 if (cfg->hp_pins[i] == spec->line_switch)
4543 return 1;
4544 if (cfg->hp_pins[i] == spec->mic_switch)
4545 return 1;
4546 /* ignore if the pin is set as line-out */
4547 if (cfg->hp_pins[i] == spec->hp_switch)
4548 return 1;
4549 return 0;
4552 static void stac92xx_hp_detect(struct hda_codec *codec)
4554 struct sigmatel_spec *spec = codec->spec;
4555 struct auto_pin_cfg *cfg = &spec->autocfg;
4556 int i, presence;
4558 presence = 0;
4559 if (spec->gpio_mute)
4560 presence = !(snd_hda_codec_read(codec, codec->afg, 0,
4561 AC_VERB_GET_GPIO_DATA, 0) & spec->gpio_mute);
4563 for (i = 0; i < cfg->hp_outs; i++) {
4564 if (presence)
4565 break;
4566 if (no_hp_sensing(spec, i))
4567 continue;
4568 presence = get_pin_presence(codec, cfg->hp_pins[i]);
4569 if (presence) {
4570 unsigned int pinctl;
4571 pinctl = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
4572 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4573 if (pinctl & AC_PINCTL_IN_EN)
4574 presence = 0; /* mic- or line-input */
4578 if (presence) {
4579 /* disable lineouts */
4580 if (spec->hp_switch)
4581 stac92xx_reset_pinctl(codec, spec->hp_switch,
4582 AC_PINCTL_OUT_EN);
4583 for (i = 0; i < cfg->line_outs; i++)
4584 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
4585 AC_PINCTL_OUT_EN);
4586 } else {
4587 /* enable lineouts */
4588 if (spec->hp_switch)
4589 stac92xx_set_pinctl(codec, spec->hp_switch,
4590 AC_PINCTL_OUT_EN);
4591 for (i = 0; i < cfg->line_outs; i++)
4592 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
4593 AC_PINCTL_OUT_EN);
4595 stac92xx_line_out_detect(codec, presence);
4596 /* toggle hp outs */
4597 for (i = 0; i < cfg->hp_outs; i++) {
4598 unsigned int val = AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN;
4599 if (no_hp_sensing(spec, i))
4600 continue;
4601 if (presence)
4602 stac92xx_set_pinctl(codec, cfg->hp_pins[i], val);
4603 #if 0 /* FIXME */
4604 /* Resetting the pinctl like below may lead to (a sort of) regressions
4605 * on some devices since they use the HP pin actually for line/speaker
4606 * outs although the default pin config shows a different pin (that is
4607 * wrong and useless).
4609 * So, it's basically a problem of default pin configs, likely a BIOS issue.
4610 * But, disabling the code below just works around it, and I'm too tired of
4611 * bug reports with such devices...
4613 else
4614 stac92xx_reset_pinctl(codec, cfg->hp_pins[i], val);
4615 #endif /* FIXME */
4619 static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
4620 int enable)
4622 struct sigmatel_spec *spec = codec->spec;
4623 unsigned int idx, val;
4625 for (idx = 0; idx < spec->num_pwrs; idx++) {
4626 if (spec->pwr_nids[idx] == nid)
4627 break;
4629 if (idx >= spec->num_pwrs)
4630 return;
4632 /* several codecs have two power down bits */
4633 if (spec->pwr_mapping)
4634 idx = spec->pwr_mapping[idx];
4635 else
4636 idx = 1 << idx;
4638 val = snd_hda_codec_read(codec, codec->afg, 0, 0x0fec, 0x0) & 0xff;
4639 if (enable)
4640 val &= ~idx;
4641 else
4642 val |= idx;
4644 /* power down unused output ports */
4645 snd_hda_codec_write(codec, codec->afg, 0, 0x7ec, val);
4648 static void stac92xx_pin_sense(struct hda_codec *codec, hda_nid_t nid)
4650 stac_toggle_power_map(codec, nid, get_pin_presence(codec, nid));
4653 static void stac92xx_report_jack(struct hda_codec *codec, hda_nid_t nid)
4655 struct sigmatel_spec *spec = codec->spec;
4656 struct sigmatel_jack *jacks = spec->jacks.list;
4658 if (jacks) {
4659 int i;
4660 for (i = 0; i < spec->jacks.used; i++) {
4661 if (jacks->nid == nid) {
4662 unsigned int pin_ctl =
4663 snd_hda_codec_read(codec, nid,
4664 0, AC_VERB_GET_PIN_WIDGET_CONTROL,
4665 0x00);
4666 int type = jacks->type;
4667 if (type == (SND_JACK_LINEOUT
4668 | SND_JACK_HEADPHONE))
4669 type = (pin_ctl & AC_PINCTL_HP_EN)
4670 ? SND_JACK_HEADPHONE : SND_JACK_LINEOUT;
4671 snd_jack_report(jacks->jack,
4672 get_pin_presence(codec, nid)
4673 ? type : 0);
4675 jacks++;
4680 static void stac92xx_mic_detect(struct hda_codec *codec)
4682 struct sigmatel_spec *spec = codec->spec;
4683 struct sigmatel_mic_route *mic;
4685 if (get_pin_presence(codec, spec->ext_mic.pin))
4686 mic = &spec->ext_mic;
4687 else
4688 mic = &spec->int_mic;
4689 if (mic->dmux_idx >= 0)
4690 snd_hda_codec_write_cache(codec, spec->dmux_nids[0], 0,
4691 AC_VERB_SET_CONNECT_SEL,
4692 mic->dmux_idx);
4693 if (mic->mux_idx >= 0)
4694 snd_hda_codec_write_cache(codec, spec->mux_nids[0], 0,
4695 AC_VERB_SET_CONNECT_SEL,
4696 mic->mux_idx);
4699 static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid)
4701 struct sigmatel_event *event = stac_get_event(codec, nid);
4702 if (!event)
4703 return;
4704 codec->patch_ops.unsol_event(codec, (unsigned)event->tag << 26);
4707 static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
4709 struct sigmatel_spec *spec = codec->spec;
4710 struct sigmatel_event *event;
4711 int tag, data;
4713 tag = (res >> 26) & 0x7f;
4714 event = stac_get_event_from_tag(codec, tag);
4715 if (!event)
4716 return;
4718 switch (event->type) {
4719 case STAC_HP_EVENT:
4720 case STAC_LO_EVENT:
4721 stac92xx_hp_detect(codec);
4722 break;
4723 case STAC_MIC_EVENT:
4724 stac92xx_mic_detect(codec);
4725 break;
4728 switch (event->type) {
4729 case STAC_HP_EVENT:
4730 case STAC_LO_EVENT:
4731 case STAC_MIC_EVENT:
4732 case STAC_INSERT_EVENT:
4733 case STAC_PWR_EVENT:
4734 if (spec->num_pwrs > 0)
4735 stac92xx_pin_sense(codec, event->nid);
4736 stac92xx_report_jack(codec, event->nid);
4738 switch (codec->subsystem_id) {
4739 case 0x103c308f:
4740 if (event->nid == 0xb) {
4741 int pin = AC_PINCTL_IN_EN;
4743 if (get_pin_presence(codec, 0xa)
4744 && get_pin_presence(codec, 0xb))
4745 pin |= AC_PINCTL_VREF_80;
4746 if (!get_pin_presence(codec, 0xb))
4747 pin |= AC_PINCTL_VREF_80;
4749 /* toggle VREF state based on mic + hp pin
4750 * status
4752 stac92xx_auto_set_pinctl(codec, 0x0a, pin);
4755 break;
4756 case STAC_VREF_EVENT:
4757 data = snd_hda_codec_read(codec, codec->afg, 0,
4758 AC_VERB_GET_GPIO_DATA, 0);
4759 /* toggle VREF state based on GPIOx status */
4760 snd_hda_codec_write(codec, codec->afg, 0, 0x7e0,
4761 !!(data & (1 << event->data)));
4762 break;
4766 static int hp_blike_system(u32 subsystem_id);
4768 static void set_hp_led_gpio(struct hda_codec *codec)
4770 struct sigmatel_spec *spec = codec->spec;
4771 unsigned int gpio;
4773 if (spec->gpio_led)
4774 return;
4776 gpio = snd_hda_param_read(codec, codec->afg, AC_PAR_GPIO_CAP);
4777 gpio &= AC_GPIO_IO_COUNT;
4778 if (gpio > 3)
4779 spec->gpio_led = 0x08; /* GPIO 3 */
4780 else
4781 spec->gpio_led = 0x01; /* GPIO 0 */
4785 * This method searches for the mute LED GPIO configuration
4786 * provided as OEM string in SMBIOS. The format of that string
4787 * is HP_Mute_LED_P_G or HP_Mute_LED_P
4788 * where P can be 0 or 1 and defines mute LED GPIO control state (low/high)
4789 * that corresponds to the NOT muted state of the master volume
4790 * and G is the index of the GPIO to use as the mute LED control (0..9)
4791 * If _G portion is missing it is assigned based on the codec ID
4793 * So, HP B-series like systems may have HP_Mute_LED_0 (current models)
4794 * or HP_Mute_LED_0_3 (future models) OEM SMBIOS strings
4797 * The dv-series laptops don't seem to have the HP_Mute_LED* strings in
4798 * SMBIOS - at least the ones I have seen do not have them - which include
4799 * my own system (HP Pavilion dv6-1110ax) and my cousin's
4800 * HP Pavilion dv9500t CTO.
4801 * Need more information on whether it is true across the entire series.
4802 * -- kunal
4804 static int find_mute_led_gpio(struct hda_codec *codec, int default_polarity)
4806 struct sigmatel_spec *spec = codec->spec;
4807 const struct dmi_device *dev = NULL;
4809 if ((codec->subsystem_id >> 16) == PCI_VENDOR_ID_HP) {
4810 while ((dev = dmi_find_device(DMI_DEV_TYPE_OEM_STRING,
4811 NULL, dev))) {
4812 if (sscanf(dev->name, "HP_Mute_LED_%d_%d",
4813 &spec->gpio_led_polarity,
4814 &spec->gpio_led) == 2) {
4815 spec->gpio_led = 1 << spec->gpio_led;
4816 return 1;
4818 if (sscanf(dev->name, "HP_Mute_LED_%d",
4819 &spec->gpio_led_polarity) == 1) {
4820 set_hp_led_gpio(codec);
4821 return 1;
4826 * Fallback case - if we don't find the DMI strings,
4827 * we statically set the GPIO - if not a B-series system.
4829 if (!hp_blike_system(codec->subsystem_id)) {
4830 set_hp_led_gpio(codec);
4831 spec->gpio_led_polarity = default_polarity;
4832 return 1;
4835 return 0;
4838 static int hp_blike_system(u32 subsystem_id)
4840 switch (subsystem_id) {
4841 case 0x103c1520:
4842 case 0x103c1521:
4843 case 0x103c1523:
4844 case 0x103c1524:
4845 case 0x103c1525:
4846 case 0x103c1722:
4847 case 0x103c1723:
4848 case 0x103c1724:
4849 case 0x103c1725:
4850 case 0x103c1726:
4851 case 0x103c1727:
4852 case 0x103c1728:
4853 case 0x103c1729:
4854 case 0x103c172a:
4855 case 0x103c172b:
4856 case 0x103c307e:
4857 case 0x103c307f:
4858 case 0x103c3080:
4859 case 0x103c3081:
4860 case 0x103c7007:
4861 case 0x103c7008:
4862 return 1;
4864 return 0;
4867 #ifdef CONFIG_PROC_FS
4868 static void stac92hd_proc_hook(struct snd_info_buffer *buffer,
4869 struct hda_codec *codec, hda_nid_t nid)
4871 if (nid == codec->afg)
4872 snd_iprintf(buffer, "Power-Map: 0x%02x\n",
4873 snd_hda_codec_read(codec, nid, 0, 0x0fec, 0x0));
4876 static void analog_loop_proc_hook(struct snd_info_buffer *buffer,
4877 struct hda_codec *codec,
4878 unsigned int verb)
4880 snd_iprintf(buffer, "Analog Loopback: 0x%02x\n",
4881 snd_hda_codec_read(codec, codec->afg, 0, verb, 0));
4884 /* stac92hd71bxx, stac92hd73xx */
4885 static void stac92hd7x_proc_hook(struct snd_info_buffer *buffer,
4886 struct hda_codec *codec, hda_nid_t nid)
4888 stac92hd_proc_hook(buffer, codec, nid);
4889 if (nid == codec->afg)
4890 analog_loop_proc_hook(buffer, codec, 0xfa0);
4893 static void stac9205_proc_hook(struct snd_info_buffer *buffer,
4894 struct hda_codec *codec, hda_nid_t nid)
4896 if (nid == codec->afg)
4897 analog_loop_proc_hook(buffer, codec, 0xfe0);
4900 static void stac927x_proc_hook(struct snd_info_buffer *buffer,
4901 struct hda_codec *codec, hda_nid_t nid)
4903 if (nid == codec->afg)
4904 analog_loop_proc_hook(buffer, codec, 0xfeb);
4906 #else
4907 #define stac92hd_proc_hook NULL
4908 #define stac92hd7x_proc_hook NULL
4909 #define stac9205_proc_hook NULL
4910 #define stac927x_proc_hook NULL
4911 #endif
4913 #ifdef SND_HDA_NEEDS_RESUME
4914 static int stac92xx_resume(struct hda_codec *codec)
4916 struct sigmatel_spec *spec = codec->spec;
4918 stac92xx_init(codec);
4919 snd_hda_codec_resume_amp(codec);
4920 snd_hda_codec_resume_cache(codec);
4921 /* fake event to set up pins again to override cached values */
4922 if (spec->hp_detect) {
4923 if (spec->autocfg.hp_pins[0])
4924 stac_issue_unsol_event(codec, spec->autocfg.hp_pins[0]);
4925 else if (spec->autocfg.line_out_pins[0])
4926 stac_issue_unsol_event(codec,
4927 spec->autocfg.line_out_pins[0]);
4929 #ifdef CONFIG_SND_HDA_POWER_SAVE
4930 /* sync mute LED */
4931 if (spec->gpio_led && codec->patch_ops.check_power_status)
4932 codec->patch_ops.check_power_status(codec, 0x01);
4933 #endif
4934 return 0;
4938 * using power check for controlling mute led of HP notebooks
4939 * check for mute state only on Speakers (nid = 0x10)
4941 * For this feature CONFIG_SND_HDA_POWER_SAVE is needed, otherwise
4942 * the LED is NOT working properly !
4944 * Changed name to reflect that it now works for any designated
4945 * model, not just HP HDX.
4948 #ifdef CONFIG_SND_HDA_POWER_SAVE
4949 static int stac92xx_hp_check_power_status(struct hda_codec *codec,
4950 hda_nid_t nid)
4952 struct sigmatel_spec *spec = codec->spec;
4953 int i, muted = 1;
4955 for (i = 0; i < spec->multiout.num_dacs; i++) {
4956 nid = spec->multiout.dac_nids[i];
4957 if (!(snd_hda_codec_amp_read(codec, nid, 0, HDA_OUTPUT, 0) &
4958 HDA_AMP_MUTE)) {
4959 muted = 0; /* something heard */
4960 break;
4963 if (muted)
4964 spec->gpio_data &= ~spec->gpio_led; /* orange */
4965 else
4966 spec->gpio_data |= spec->gpio_led; /* white */
4968 if (!spec->gpio_led_polarity) {
4969 /* LED state is inverted on these systems */
4970 spec->gpio_data ^= spec->gpio_led;
4973 stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, spec->gpio_data);
4974 return 0;
4976 #endif
4978 static int stac92xx_suspend(struct hda_codec *codec, pm_message_t state)
4980 stac92xx_shutup(codec);
4981 return 0;
4983 #endif
4985 static struct hda_codec_ops stac92xx_patch_ops = {
4986 .build_controls = stac92xx_build_controls,
4987 .build_pcms = stac92xx_build_pcms,
4988 .init = stac92xx_init,
4989 .free = stac92xx_free,
4990 .unsol_event = stac92xx_unsol_event,
4991 #ifdef SND_HDA_NEEDS_RESUME
4992 .suspend = stac92xx_suspend,
4993 .resume = stac92xx_resume,
4994 #endif
4995 .reboot_notify = stac92xx_shutup,
4998 static int patch_stac9200(struct hda_codec *codec)
5000 struct sigmatel_spec *spec;
5001 int err;
5003 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5004 if (spec == NULL)
5005 return -ENOMEM;
5007 codec->no_trigger_sense = 1;
5008 codec->spec = spec;
5009 spec->linear_tone_beep = 1;
5010 spec->num_pins = ARRAY_SIZE(stac9200_pin_nids);
5011 spec->pin_nids = stac9200_pin_nids;
5012 spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS,
5013 stac9200_models,
5014 stac9200_cfg_tbl);
5015 if (spec->board_config < 0)
5016 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5017 codec->chip_name);
5018 else
5019 stac92xx_set_config_regs(codec,
5020 stac9200_brd_tbl[spec->board_config]);
5022 spec->multiout.max_channels = 2;
5023 spec->multiout.num_dacs = 1;
5024 spec->multiout.dac_nids = stac9200_dac_nids;
5025 spec->adc_nids = stac9200_adc_nids;
5026 spec->mux_nids = stac9200_mux_nids;
5027 spec->num_muxes = 1;
5028 spec->num_dmics = 0;
5029 spec->num_adcs = 1;
5030 spec->num_pwrs = 0;
5032 if (spec->board_config == STAC_9200_M4 ||
5033 spec->board_config == STAC_9200_M4_2 ||
5034 spec->board_config == STAC_9200_OQO)
5035 spec->init = stac9200_eapd_init;
5036 else
5037 spec->init = stac9200_core_init;
5038 spec->mixer = stac9200_mixer;
5040 if (spec->board_config == STAC_9200_PANASONIC) {
5041 spec->gpio_mask = spec->gpio_dir = 0x09;
5042 spec->gpio_data = 0x00;
5045 err = stac9200_parse_auto_config(codec);
5046 if (err < 0) {
5047 stac92xx_free(codec);
5048 return err;
5051 /* CF-74 has no headphone detection, and the driver should *NOT*
5052 * do detection and HP/speaker toggle because the hardware does it.
5054 if (spec->board_config == STAC_9200_PANASONIC)
5055 spec->hp_detect = 0;
5057 codec->patch_ops = stac92xx_patch_ops;
5059 return 0;
5062 static int patch_stac925x(struct hda_codec *codec)
5064 struct sigmatel_spec *spec;
5065 int err;
5067 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5068 if (spec == NULL)
5069 return -ENOMEM;
5071 codec->no_trigger_sense = 1;
5072 codec->spec = spec;
5073 spec->linear_tone_beep = 1;
5074 spec->num_pins = ARRAY_SIZE(stac925x_pin_nids);
5075 spec->pin_nids = stac925x_pin_nids;
5077 /* Check first for codec ID */
5078 spec->board_config = snd_hda_check_board_codec_sid_config(codec,
5079 STAC_925x_MODELS,
5080 stac925x_models,
5081 stac925x_codec_id_cfg_tbl);
5083 /* Now checks for PCI ID, if codec ID is not found */
5084 if (spec->board_config < 0)
5085 spec->board_config = snd_hda_check_board_config(codec,
5086 STAC_925x_MODELS,
5087 stac925x_models,
5088 stac925x_cfg_tbl);
5089 again:
5090 if (spec->board_config < 0)
5091 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5092 codec->chip_name);
5093 else
5094 stac92xx_set_config_regs(codec,
5095 stac925x_brd_tbl[spec->board_config]);
5097 spec->multiout.max_channels = 2;
5098 spec->multiout.num_dacs = 1;
5099 spec->multiout.dac_nids = stac925x_dac_nids;
5100 spec->adc_nids = stac925x_adc_nids;
5101 spec->mux_nids = stac925x_mux_nids;
5102 spec->num_muxes = 1;
5103 spec->num_adcs = 1;
5104 spec->num_pwrs = 0;
5105 switch (codec->vendor_id) {
5106 case 0x83847632: /* STAC9202 */
5107 case 0x83847633: /* STAC9202D */
5108 case 0x83847636: /* STAC9251 */
5109 case 0x83847637: /* STAC9251D */
5110 spec->num_dmics = STAC925X_NUM_DMICS;
5111 spec->dmic_nids = stac925x_dmic_nids;
5112 spec->num_dmuxes = ARRAY_SIZE(stac925x_dmux_nids);
5113 spec->dmux_nids = stac925x_dmux_nids;
5114 break;
5115 default:
5116 spec->num_dmics = 0;
5117 break;
5120 spec->init = stac925x_core_init;
5121 spec->mixer = stac925x_mixer;
5122 spec->num_caps = 1;
5123 spec->capvols = stac925x_capvols;
5124 spec->capsws = stac925x_capsws;
5126 err = stac92xx_parse_auto_config(codec, 0x8, 0x7);
5127 if (!err) {
5128 if (spec->board_config < 0) {
5129 printk(KERN_WARNING "hda_codec: No auto-config is "
5130 "available, default to model=ref\n");
5131 spec->board_config = STAC_925x_REF;
5132 goto again;
5134 err = -EINVAL;
5136 if (err < 0) {
5137 stac92xx_free(codec);
5138 return err;
5141 codec->patch_ops = stac92xx_patch_ops;
5143 return 0;
5146 static int patch_stac92hd73xx(struct hda_codec *codec)
5148 struct sigmatel_spec *spec;
5149 hda_nid_t conn[STAC92HD73_DAC_COUNT + 2];
5150 int err = 0;
5151 int num_dacs;
5153 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5154 if (spec == NULL)
5155 return -ENOMEM;
5157 codec->no_trigger_sense = 1;
5158 codec->spec = spec;
5159 spec->linear_tone_beep = 0;
5160 codec->slave_dig_outs = stac92hd73xx_slave_dig_outs;
5161 spec->num_pins = ARRAY_SIZE(stac92hd73xx_pin_nids);
5162 spec->pin_nids = stac92hd73xx_pin_nids;
5163 spec->board_config = snd_hda_check_board_config(codec,
5164 STAC_92HD73XX_MODELS,
5165 stac92hd73xx_models,
5166 stac92hd73xx_cfg_tbl);
5167 /* check codec subsystem id if not found */
5168 if (spec->board_config < 0)
5169 spec->board_config =
5170 snd_hda_check_board_codec_sid_config(codec,
5171 STAC_92HD73XX_MODELS, stac92hd73xx_models,
5172 stac92hd73xx_codec_id_cfg_tbl);
5173 again:
5174 if (spec->board_config < 0)
5175 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5176 codec->chip_name);
5177 else
5178 stac92xx_set_config_regs(codec,
5179 stac92hd73xx_brd_tbl[spec->board_config]);
5181 num_dacs = snd_hda_get_connections(codec, 0x0a,
5182 conn, STAC92HD73_DAC_COUNT + 2) - 1;
5184 if (num_dacs < 3 || num_dacs > 5) {
5185 printk(KERN_WARNING "hda_codec: Could not determine "
5186 "number of channels defaulting to DAC count\n");
5187 num_dacs = STAC92HD73_DAC_COUNT;
5189 spec->init = stac92hd73xx_core_init;
5190 switch (num_dacs) {
5191 case 0x3: /* 6 Channel */
5192 spec->aloopback_ctl = stac92hd73xx_6ch_loopback;
5193 break;
5194 case 0x4: /* 8 Channel */
5195 spec->aloopback_ctl = stac92hd73xx_8ch_loopback;
5196 break;
5197 case 0x5: /* 10 Channel */
5198 spec->aloopback_ctl = stac92hd73xx_10ch_loopback;
5199 break;
5201 spec->multiout.dac_nids = spec->dac_nids;
5203 spec->aloopback_mask = 0x01;
5204 spec->aloopback_shift = 8;
5206 spec->digbeep_nid = 0x1c;
5207 spec->mux_nids = stac92hd73xx_mux_nids;
5208 spec->adc_nids = stac92hd73xx_adc_nids;
5209 spec->dmic_nids = stac92hd73xx_dmic_nids;
5210 spec->dmux_nids = stac92hd73xx_dmux_nids;
5211 spec->smux_nids = stac92hd73xx_smux_nids;
5213 spec->num_muxes = ARRAY_SIZE(stac92hd73xx_mux_nids);
5214 spec->num_adcs = ARRAY_SIZE(stac92hd73xx_adc_nids);
5215 spec->num_dmuxes = ARRAY_SIZE(stac92hd73xx_dmux_nids);
5217 spec->num_caps = STAC92HD73XX_NUM_CAPS;
5218 spec->capvols = stac92hd73xx_capvols;
5219 spec->capsws = stac92hd73xx_capsws;
5221 switch (spec->board_config) {
5222 case STAC_DELL_EQ:
5223 spec->init = dell_eq_core_init;
5224 /* fallthru */
5225 case STAC_DELL_M6_AMIC:
5226 case STAC_DELL_M6_DMIC:
5227 case STAC_DELL_M6_BOTH:
5228 spec->num_smuxes = 0;
5229 spec->eapd_switch = 0;
5231 switch (spec->board_config) {
5232 case STAC_DELL_M6_AMIC: /* Analog Mics */
5233 snd_hda_codec_set_pincfg(codec, 0x0b, 0x90A70170);
5234 spec->num_dmics = 0;
5235 break;
5236 case STAC_DELL_M6_DMIC: /* Digital Mics */
5237 snd_hda_codec_set_pincfg(codec, 0x13, 0x90A60160);
5238 spec->num_dmics = 1;
5239 break;
5240 case STAC_DELL_M6_BOTH: /* Both */
5241 snd_hda_codec_set_pincfg(codec, 0x0b, 0x90A70170);
5242 snd_hda_codec_set_pincfg(codec, 0x13, 0x90A60160);
5243 spec->num_dmics = 1;
5244 break;
5246 break;
5247 case STAC_ALIENWARE_M17X:
5248 spec->num_dmics = STAC92HD73XX_NUM_DMICS;
5249 spec->num_smuxes = ARRAY_SIZE(stac92hd73xx_smux_nids);
5250 spec->eapd_switch = 0;
5251 break;
5252 default:
5253 spec->num_dmics = STAC92HD73XX_NUM_DMICS;
5254 spec->num_smuxes = ARRAY_SIZE(stac92hd73xx_smux_nids);
5255 spec->eapd_switch = 1;
5256 break;
5258 if (spec->board_config != STAC_92HD73XX_REF) {
5259 /* GPIO0 High = Enable EAPD */
5260 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
5261 spec->gpio_data = 0x01;
5264 spec->num_pwrs = ARRAY_SIZE(stac92hd73xx_pwr_nids);
5265 spec->pwr_nids = stac92hd73xx_pwr_nids;
5267 err = stac92xx_parse_auto_config(codec, 0x25, 0x27);
5269 if (!err) {
5270 if (spec->board_config < 0) {
5271 printk(KERN_WARNING "hda_codec: No auto-config is "
5272 "available, default to model=ref\n");
5273 spec->board_config = STAC_92HD73XX_REF;
5274 goto again;
5276 err = -EINVAL;
5279 if (err < 0) {
5280 stac92xx_free(codec);
5281 return err;
5284 if (spec->board_config == STAC_92HD73XX_NO_JD)
5285 spec->hp_detect = 0;
5287 codec->patch_ops = stac92xx_patch_ops;
5289 codec->proc_widget_hook = stac92hd7x_proc_hook;
5291 return 0;
5294 static int patch_stac92hd83xxx(struct hda_codec *codec)
5296 struct sigmatel_spec *spec;
5297 hda_nid_t conn[STAC92HD83_DAC_COUNT + 1];
5298 int err;
5299 int num_dacs;
5301 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5302 if (spec == NULL)
5303 return -ENOMEM;
5305 codec->no_trigger_sense = 1;
5306 codec->spec = spec;
5307 spec->linear_tone_beep = 1;
5308 codec->slave_dig_outs = stac92hd83xxx_slave_dig_outs;
5309 spec->digbeep_nid = 0x21;
5310 spec->mux_nids = stac92hd83xxx_mux_nids;
5311 spec->num_muxes = ARRAY_SIZE(stac92hd83xxx_mux_nids);
5312 spec->adc_nids = stac92hd83xxx_adc_nids;
5313 spec->num_adcs = ARRAY_SIZE(stac92hd83xxx_adc_nids);
5314 spec->pwr_nids = stac92hd83xxx_pwr_nids;
5315 spec->pwr_mapping = stac92hd83xxx_pwr_mapping;
5316 spec->num_pwrs = ARRAY_SIZE(stac92hd83xxx_pwr_nids);
5317 spec->multiout.dac_nids = spec->dac_nids;
5319 spec->init = stac92hd83xxx_core_init;
5320 spec->num_pins = ARRAY_SIZE(stac92hd83xxx_pin_nids);
5321 spec->pin_nids = stac92hd83xxx_pin_nids;
5322 spec->num_caps = STAC92HD83XXX_NUM_CAPS;
5323 spec->capvols = stac92hd83xxx_capvols;
5324 spec->capsws = stac92hd83xxx_capsws;
5326 spec->board_config = snd_hda_check_board_config(codec,
5327 STAC_92HD83XXX_MODELS,
5328 stac92hd83xxx_models,
5329 stac92hd83xxx_cfg_tbl);
5330 again:
5331 if (spec->board_config < 0)
5332 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5333 codec->chip_name);
5334 else
5335 stac92xx_set_config_regs(codec,
5336 stac92hd83xxx_brd_tbl[spec->board_config]);
5338 switch (codec->vendor_id) {
5339 case 0x111d7666:
5340 case 0x111d7667:
5341 case 0x111d7668:
5342 case 0x111d7669:
5343 spec->num_pins = ARRAY_SIZE(stac92hd88xxx_pin_nids);
5344 spec->pin_nids = stac92hd88xxx_pin_nids;
5345 spec->mono_nid = 0;
5346 spec->digbeep_nid = 0;
5347 spec->num_pwrs = 0;
5348 break;
5349 case 0x111d7604:
5350 case 0x111d76d4:
5351 case 0x111d7605:
5352 case 0x111d76d5:
5353 if (spec->board_config == STAC_92HD83XXX_PWR_REF)
5354 break;
5355 spec->num_pwrs = 0;
5356 break;
5359 codec->patch_ops = stac92xx_patch_ops;
5361 if (find_mute_led_gpio(codec, 0))
5362 snd_printd("mute LED gpio %d polarity %d\n",
5363 spec->gpio_led,
5364 spec->gpio_led_polarity);
5366 #ifdef CONFIG_SND_HDA_POWER_SAVE
5367 if (spec->gpio_led) {
5368 spec->gpio_mask |= spec->gpio_led;
5369 spec->gpio_dir |= spec->gpio_led;
5370 spec->gpio_data |= spec->gpio_led;
5371 /* register check_power_status callback. */
5372 codec->patch_ops.check_power_status =
5373 stac92xx_hp_check_power_status;
5375 #endif
5377 err = stac92xx_parse_auto_config(codec, 0x1d, 0);
5378 if (!err) {
5379 if (spec->board_config < 0) {
5380 printk(KERN_WARNING "hda_codec: No auto-config is "
5381 "available, default to model=ref\n");
5382 spec->board_config = STAC_92HD83XXX_REF;
5383 goto again;
5385 err = -EINVAL;
5388 if (err < 0) {
5389 stac92xx_free(codec);
5390 return err;
5393 /* docking output support */
5394 num_dacs = snd_hda_get_connections(codec, 0xF,
5395 conn, STAC92HD83_DAC_COUNT + 1) - 1;
5396 /* skip non-DAC connections */
5397 while (num_dacs >= 0 &&
5398 (get_wcaps_type(get_wcaps(codec, conn[num_dacs]))
5399 != AC_WID_AUD_OUT))
5400 num_dacs--;
5401 /* set port E and F to select the last DAC */
5402 if (num_dacs >= 0) {
5403 snd_hda_codec_write_cache(codec, 0xE, 0,
5404 AC_VERB_SET_CONNECT_SEL, num_dacs);
5405 snd_hda_codec_write_cache(codec, 0xF, 0,
5406 AC_VERB_SET_CONNECT_SEL, num_dacs);
5409 codec->proc_widget_hook = stac92hd_proc_hook;
5411 return 0;
5414 /* get the pin connection (fixed, none, etc) */
5415 static unsigned int stac_get_defcfg_connect(struct hda_codec *codec, int idx)
5417 struct sigmatel_spec *spec = codec->spec;
5418 unsigned int cfg;
5420 cfg = snd_hda_codec_get_pincfg(codec, spec->pin_nids[idx]);
5421 return get_defcfg_connect(cfg);
5424 static int stac92hd71bxx_connected_ports(struct hda_codec *codec,
5425 hda_nid_t *nids, int num_nids)
5427 struct sigmatel_spec *spec = codec->spec;
5428 int idx, num;
5429 unsigned int def_conf;
5431 for (num = 0; num < num_nids; num++) {
5432 for (idx = 0; idx < spec->num_pins; idx++)
5433 if (spec->pin_nids[idx] == nids[num])
5434 break;
5435 if (idx >= spec->num_pins)
5436 break;
5437 def_conf = stac_get_defcfg_connect(codec, idx);
5438 if (def_conf == AC_JACK_PORT_NONE)
5439 break;
5441 return num;
5444 static int stac92hd71bxx_connected_smuxes(struct hda_codec *codec,
5445 hda_nid_t dig0pin)
5447 struct sigmatel_spec *spec = codec->spec;
5448 int idx;
5450 for (idx = 0; idx < spec->num_pins; idx++)
5451 if (spec->pin_nids[idx] == dig0pin)
5452 break;
5453 if ((idx + 2) >= spec->num_pins)
5454 return 0;
5456 /* dig1pin case */
5457 if (stac_get_defcfg_connect(codec, idx + 1) != AC_JACK_PORT_NONE)
5458 return 2;
5460 /* dig0pin + dig2pin case */
5461 if (stac_get_defcfg_connect(codec, idx + 2) != AC_JACK_PORT_NONE)
5462 return 2;
5463 if (stac_get_defcfg_connect(codec, idx) != AC_JACK_PORT_NONE)
5464 return 1;
5465 else
5466 return 0;
5469 /* HP dv7 bass switch - GPIO5 */
5470 #define stac_hp_bass_gpio_info snd_ctl_boolean_mono_info
5471 static int stac_hp_bass_gpio_get(struct snd_kcontrol *kcontrol,
5472 struct snd_ctl_elem_value *ucontrol)
5474 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5475 struct sigmatel_spec *spec = codec->spec;
5476 ucontrol->value.integer.value[0] = !!(spec->gpio_data & 0x20);
5477 return 0;
5480 static int stac_hp_bass_gpio_put(struct snd_kcontrol *kcontrol,
5481 struct snd_ctl_elem_value *ucontrol)
5483 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5484 struct sigmatel_spec *spec = codec->spec;
5485 unsigned int gpio_data;
5487 gpio_data = (spec->gpio_data & ~0x20) |
5488 (ucontrol->value.integer.value[0] ? 0x20 : 0);
5489 if (gpio_data == spec->gpio_data)
5490 return 0;
5491 spec->gpio_data = gpio_data;
5492 stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, spec->gpio_data);
5493 return 1;
5496 static struct snd_kcontrol_new stac_hp_bass_sw_ctrl = {
5497 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5498 .info = stac_hp_bass_gpio_info,
5499 .get = stac_hp_bass_gpio_get,
5500 .put = stac_hp_bass_gpio_put,
5503 static int stac_add_hp_bass_switch(struct hda_codec *codec)
5505 struct sigmatel_spec *spec = codec->spec;
5507 if (!stac_control_new(spec, &stac_hp_bass_sw_ctrl,
5508 "Bass Speaker Playback Switch", 0))
5509 return -ENOMEM;
5511 spec->gpio_mask |= 0x20;
5512 spec->gpio_dir |= 0x20;
5513 spec->gpio_data |= 0x20;
5514 return 0;
5517 static int patch_stac92hd71bxx(struct hda_codec *codec)
5519 struct sigmatel_spec *spec;
5520 struct hda_verb *unmute_init = stac92hd71bxx_unmute_core_init;
5521 unsigned int pin_cfg;
5522 int err = 0;
5524 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5525 if (spec == NULL)
5526 return -ENOMEM;
5528 codec->no_trigger_sense = 1;
5529 codec->spec = spec;
5530 spec->linear_tone_beep = 0;
5531 codec->patch_ops = stac92xx_patch_ops;
5532 spec->num_pins = STAC92HD71BXX_NUM_PINS;
5533 switch (codec->vendor_id) {
5534 case 0x111d76b6:
5535 case 0x111d76b7:
5536 spec->pin_nids = stac92hd71bxx_pin_nids_4port;
5537 break;
5538 case 0x111d7603:
5539 case 0x111d7608:
5540 /* On 92HD75Bx 0x27 isn't a pin nid */
5541 spec->num_pins--;
5542 /* fallthrough */
5543 default:
5544 spec->pin_nids = stac92hd71bxx_pin_nids_6port;
5546 spec->num_pwrs = ARRAY_SIZE(stac92hd71bxx_pwr_nids);
5547 spec->board_config = snd_hda_check_board_config(codec,
5548 STAC_92HD71BXX_MODELS,
5549 stac92hd71bxx_models,
5550 stac92hd71bxx_cfg_tbl);
5551 again:
5552 if (spec->board_config < 0)
5553 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5554 codec->chip_name);
5555 else
5556 stac92xx_set_config_regs(codec,
5557 stac92hd71bxx_brd_tbl[spec->board_config]);
5559 if (spec->board_config != STAC_92HD71BXX_REF) {
5560 /* GPIO0 = EAPD */
5561 spec->gpio_mask = 0x01;
5562 spec->gpio_dir = 0x01;
5563 spec->gpio_data = 0x01;
5566 spec->dmic_nids = stac92hd71bxx_dmic_nids;
5567 spec->dmux_nids = stac92hd71bxx_dmux_nids;
5569 spec->num_caps = STAC92HD71BXX_NUM_CAPS;
5570 spec->capvols = stac92hd71bxx_capvols;
5571 spec->capsws = stac92hd71bxx_capsws;
5573 switch (codec->vendor_id) {
5574 case 0x111d76b6: /* 4 Port without Analog Mixer */
5575 case 0x111d76b7:
5576 unmute_init++;
5577 /* fallthru */
5578 case 0x111d76b4: /* 6 Port without Analog Mixer */
5579 case 0x111d76b5:
5580 spec->init = stac92hd71bxx_core_init;
5581 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
5582 spec->num_dmics = stac92hd71bxx_connected_ports(codec,
5583 stac92hd71bxx_dmic_nids,
5584 STAC92HD71BXX_NUM_DMICS);
5585 break;
5586 case 0x111d7608: /* 5 Port with Analog Mixer */
5587 switch (spec->board_config) {
5588 case STAC_HP_M4:
5589 /* Enable VREF power saving on GPIO1 detect */
5590 err = stac_add_event(spec, codec->afg,
5591 STAC_VREF_EVENT, 0x02);
5592 if (err < 0)
5593 return err;
5594 snd_hda_codec_write_cache(codec, codec->afg, 0,
5595 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x02);
5596 snd_hda_codec_write_cache(codec, codec->afg, 0,
5597 AC_VERB_SET_UNSOLICITED_ENABLE,
5598 AC_USRSP_EN | err);
5599 spec->gpio_mask |= 0x02;
5600 break;
5602 if ((codec->revision_id & 0xf) == 0 ||
5603 (codec->revision_id & 0xf) == 1)
5604 spec->stream_delay = 40; /* 40 milliseconds */
5606 /* no output amps */
5607 spec->num_pwrs = 0;
5608 /* disable VSW */
5609 spec->init = stac92hd71bxx_core_init;
5610 unmute_init++;
5611 snd_hda_codec_set_pincfg(codec, 0x0f, 0x40f000f0);
5612 snd_hda_codec_set_pincfg(codec, 0x19, 0x40f000f3);
5613 stac92hd71bxx_dmic_nids[STAC92HD71BXX_NUM_DMICS - 1] = 0;
5614 spec->num_dmics = stac92hd71bxx_connected_ports(codec,
5615 stac92hd71bxx_dmic_nids,
5616 STAC92HD71BXX_NUM_DMICS - 1);
5617 break;
5618 case 0x111d7603: /* 6 Port with Analog Mixer */
5619 if ((codec->revision_id & 0xf) == 1)
5620 spec->stream_delay = 40; /* 40 milliseconds */
5622 /* no output amps */
5623 spec->num_pwrs = 0;
5624 /* fallthru */
5625 default:
5626 spec->init = stac92hd71bxx_core_init;
5627 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
5628 spec->num_dmics = stac92hd71bxx_connected_ports(codec,
5629 stac92hd71bxx_dmic_nids,
5630 STAC92HD71BXX_NUM_DMICS);
5631 break;
5634 if (get_wcaps(codec, 0xa) & AC_WCAP_IN_AMP)
5635 snd_hda_sequence_write_cache(codec, unmute_init);
5637 /* Some HP machines seem to have unstable codec communications
5638 * especially with ATI fglrx driver. For recovering from the
5639 * CORB/RIRB stall, allow the BUS reset and keep always sync
5641 if (spec->board_config == STAC_HP_DV5) {
5642 codec->bus->sync_write = 1;
5643 codec->bus->allow_bus_reset = 1;
5646 spec->aloopback_ctl = stac92hd71bxx_loopback;
5647 spec->aloopback_mask = 0x50;
5648 spec->aloopback_shift = 0;
5650 spec->powerdown_adcs = 1;
5651 spec->digbeep_nid = 0x26;
5652 spec->mux_nids = stac92hd71bxx_mux_nids;
5653 spec->adc_nids = stac92hd71bxx_adc_nids;
5654 spec->smux_nids = stac92hd71bxx_smux_nids;
5655 spec->pwr_nids = stac92hd71bxx_pwr_nids;
5657 spec->num_muxes = ARRAY_SIZE(stac92hd71bxx_mux_nids);
5658 spec->num_adcs = ARRAY_SIZE(stac92hd71bxx_adc_nids);
5659 spec->num_dmuxes = ARRAY_SIZE(stac92hd71bxx_dmux_nids);
5660 spec->num_smuxes = stac92hd71bxx_connected_smuxes(codec, 0x1e);
5662 snd_printdd("Found board config: %d\n", spec->board_config);
5664 switch (spec->board_config) {
5665 case STAC_HP_M4:
5666 /* enable internal microphone */
5667 snd_hda_codec_set_pincfg(codec, 0x0e, 0x01813040);
5668 stac92xx_auto_set_pinctl(codec, 0x0e,
5669 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80);
5670 /* fallthru */
5671 case STAC_DELL_M4_2:
5672 spec->num_dmics = 0;
5673 spec->num_smuxes = 0;
5674 spec->num_dmuxes = 0;
5675 break;
5676 case STAC_DELL_M4_1:
5677 case STAC_DELL_M4_3:
5678 spec->num_dmics = 1;
5679 spec->num_smuxes = 0;
5680 spec->num_dmuxes = 1;
5681 break;
5682 case STAC_HP_DV4_1222NR:
5683 spec->num_dmics = 1;
5684 /* I don't know if it needs 1 or 2 smuxes - will wait for
5685 * bug reports to fix if needed
5687 spec->num_smuxes = 1;
5688 spec->num_dmuxes = 1;
5689 /* fallthrough */
5690 case STAC_HP_DV4:
5691 spec->gpio_led = 0x01;
5692 /* fallthrough */
5693 case STAC_HP_DV5:
5694 snd_hda_codec_set_pincfg(codec, 0x0d, 0x90170010);
5695 stac92xx_auto_set_pinctl(codec, 0x0d, AC_PINCTL_OUT_EN);
5696 /* HP dv6 gives the headphone pin as a line-out. Thus we
5697 * need to set hp_detect flag here to force to enable HP
5698 * detection.
5700 spec->hp_detect = 1;
5701 break;
5702 case STAC_HP_HDX:
5703 spec->num_dmics = 1;
5704 spec->num_dmuxes = 1;
5705 spec->num_smuxes = 1;
5706 spec->gpio_led = 0x08;
5707 break;
5710 if (hp_blike_system(codec->subsystem_id)) {
5711 pin_cfg = snd_hda_codec_get_pincfg(codec, 0x0f);
5712 if (get_defcfg_device(pin_cfg) == AC_JACK_LINE_OUT ||
5713 get_defcfg_device(pin_cfg) == AC_JACK_SPEAKER ||
5714 get_defcfg_device(pin_cfg) == AC_JACK_HP_OUT) {
5715 /* It was changed in the BIOS to just satisfy MS DTM.
5716 * Lets turn it back into slaved HP
5718 pin_cfg = (pin_cfg & (~AC_DEFCFG_DEVICE))
5719 | (AC_JACK_HP_OUT <<
5720 AC_DEFCFG_DEVICE_SHIFT);
5721 pin_cfg = (pin_cfg & (~(AC_DEFCFG_DEF_ASSOC
5722 | AC_DEFCFG_SEQUENCE)))
5723 | 0x1f;
5724 snd_hda_codec_set_pincfg(codec, 0x0f, pin_cfg);
5728 if (find_mute_led_gpio(codec, 1))
5729 snd_printd("mute LED gpio %d polarity %d\n",
5730 spec->gpio_led,
5731 spec->gpio_led_polarity);
5733 #ifdef CONFIG_SND_HDA_POWER_SAVE
5734 if (spec->gpio_led) {
5735 spec->gpio_mask |= spec->gpio_led;
5736 spec->gpio_dir |= spec->gpio_led;
5737 spec->gpio_data |= spec->gpio_led;
5738 /* register check_power_status callback. */
5739 codec->patch_ops.check_power_status =
5740 stac92xx_hp_check_power_status;
5742 #endif
5744 spec->multiout.dac_nids = spec->dac_nids;
5746 err = stac92xx_parse_auto_config(codec, 0x21, 0);
5747 if (!err) {
5748 if (spec->board_config < 0) {
5749 printk(KERN_WARNING "hda_codec: No auto-config is "
5750 "available, default to model=ref\n");
5751 spec->board_config = STAC_92HD71BXX_REF;
5752 goto again;
5754 err = -EINVAL;
5757 if (err < 0) {
5758 stac92xx_free(codec);
5759 return err;
5762 /* enable bass on HP dv7 */
5763 if (spec->board_config == STAC_HP_DV4 ||
5764 spec->board_config == STAC_HP_DV5) {
5765 unsigned int cap;
5766 cap = snd_hda_param_read(codec, 0x1, AC_PAR_GPIO_CAP);
5767 cap &= AC_GPIO_IO_COUNT;
5768 if (cap >= 6)
5769 stac_add_hp_bass_switch(codec);
5772 codec->proc_widget_hook = stac92hd7x_proc_hook;
5774 return 0;
5777 static int patch_stac922x(struct hda_codec *codec)
5779 struct sigmatel_spec *spec;
5780 int err;
5782 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5783 if (spec == NULL)
5784 return -ENOMEM;
5786 codec->no_trigger_sense = 1;
5787 codec->spec = spec;
5788 spec->linear_tone_beep = 1;
5789 spec->num_pins = ARRAY_SIZE(stac922x_pin_nids);
5790 spec->pin_nids = stac922x_pin_nids;
5791 spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS,
5792 stac922x_models,
5793 stac922x_cfg_tbl);
5794 if (spec->board_config == STAC_INTEL_MAC_AUTO) {
5795 spec->gpio_mask = spec->gpio_dir = 0x03;
5796 spec->gpio_data = 0x03;
5797 /* Intel Macs have all same PCI SSID, so we need to check
5798 * codec SSID to distinguish the exact models
5800 printk(KERN_INFO "hda_codec: STAC922x, Apple subsys_id=%x\n", codec->subsystem_id);
5801 switch (codec->subsystem_id) {
5803 case 0x106b0800:
5804 spec->board_config = STAC_INTEL_MAC_V1;
5805 break;
5806 case 0x106b0600:
5807 case 0x106b0700:
5808 spec->board_config = STAC_INTEL_MAC_V2;
5809 break;
5810 case 0x106b0e00:
5811 case 0x106b0f00:
5812 case 0x106b1600:
5813 case 0x106b1700:
5814 case 0x106b0200:
5815 case 0x106b1e00:
5816 spec->board_config = STAC_INTEL_MAC_V3;
5817 break;
5818 case 0x106b1a00:
5819 case 0x00000100:
5820 spec->board_config = STAC_INTEL_MAC_V4;
5821 break;
5822 case 0x106b0a00:
5823 case 0x106b2200:
5824 spec->board_config = STAC_INTEL_MAC_V5;
5825 break;
5826 default:
5827 spec->board_config = STAC_INTEL_MAC_V3;
5828 break;
5832 again:
5833 if (spec->board_config < 0)
5834 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5835 codec->chip_name);
5836 else
5837 stac92xx_set_config_regs(codec,
5838 stac922x_brd_tbl[spec->board_config]);
5840 spec->adc_nids = stac922x_adc_nids;
5841 spec->mux_nids = stac922x_mux_nids;
5842 spec->num_muxes = ARRAY_SIZE(stac922x_mux_nids);
5843 spec->num_adcs = ARRAY_SIZE(stac922x_adc_nids);
5844 spec->num_dmics = 0;
5845 spec->num_pwrs = 0;
5847 spec->init = stac922x_core_init;
5849 spec->num_caps = STAC922X_NUM_CAPS;
5850 spec->capvols = stac922x_capvols;
5851 spec->capsws = stac922x_capsws;
5853 spec->multiout.dac_nids = spec->dac_nids;
5855 err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
5856 if (!err) {
5857 if (spec->board_config < 0) {
5858 printk(KERN_WARNING "hda_codec: No auto-config is "
5859 "available, default to model=ref\n");
5860 spec->board_config = STAC_D945_REF;
5861 goto again;
5863 err = -EINVAL;
5865 if (err < 0) {
5866 stac92xx_free(codec);
5867 return err;
5870 codec->patch_ops = stac92xx_patch_ops;
5872 /* Fix Mux capture level; max to 2 */
5873 snd_hda_override_amp_caps(codec, 0x12, HDA_OUTPUT,
5874 (0 << AC_AMPCAP_OFFSET_SHIFT) |
5875 (2 << AC_AMPCAP_NUM_STEPS_SHIFT) |
5876 (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5877 (0 << AC_AMPCAP_MUTE_SHIFT));
5879 return 0;
5882 static int patch_stac927x(struct hda_codec *codec)
5884 struct sigmatel_spec *spec;
5885 int err;
5887 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5888 if (spec == NULL)
5889 return -ENOMEM;
5891 codec->no_trigger_sense = 1;
5892 codec->spec = spec;
5893 spec->linear_tone_beep = 1;
5894 codec->slave_dig_outs = stac927x_slave_dig_outs;
5895 spec->num_pins = ARRAY_SIZE(stac927x_pin_nids);
5896 spec->pin_nids = stac927x_pin_nids;
5897 spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS,
5898 stac927x_models,
5899 stac927x_cfg_tbl);
5900 again:
5901 if (spec->board_config < 0)
5902 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5903 codec->chip_name);
5904 else
5905 stac92xx_set_config_regs(codec,
5906 stac927x_brd_tbl[spec->board_config]);
5908 spec->digbeep_nid = 0x23;
5909 spec->adc_nids = stac927x_adc_nids;
5910 spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
5911 spec->mux_nids = stac927x_mux_nids;
5912 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
5913 spec->smux_nids = stac927x_smux_nids;
5914 spec->num_smuxes = ARRAY_SIZE(stac927x_smux_nids);
5915 spec->spdif_labels = stac927x_spdif_labels;
5916 spec->dac_list = stac927x_dac_nids;
5917 spec->multiout.dac_nids = spec->dac_nids;
5919 if (spec->board_config != STAC_D965_REF) {
5920 /* GPIO0 High = Enable EAPD */
5921 spec->eapd_mask = spec->gpio_mask = 0x01;
5922 spec->gpio_dir = spec->gpio_data = 0x01;
5925 switch (spec->board_config) {
5926 case STAC_D965_3ST:
5927 case STAC_D965_5ST:
5928 /* GPIO0 High = Enable EAPD */
5929 spec->num_dmics = 0;
5930 spec->init = d965_core_init;
5931 break;
5932 case STAC_DELL_BIOS:
5933 switch (codec->subsystem_id) {
5934 case 0x10280209:
5935 case 0x1028022e:
5936 /* correct the device field to SPDIF out */
5937 snd_hda_codec_set_pincfg(codec, 0x21, 0x01442070);
5938 break;
5940 /* configure the analog microphone on some laptops */
5941 snd_hda_codec_set_pincfg(codec, 0x0c, 0x90a79130);
5942 /* correct the front output jack as a hp out */
5943 snd_hda_codec_set_pincfg(codec, 0x0f, 0x0227011f);
5944 /* correct the front input jack as a mic */
5945 snd_hda_codec_set_pincfg(codec, 0x0e, 0x02a79130);
5946 /* fallthru */
5947 case STAC_DELL_3ST:
5948 if (codec->subsystem_id != 0x1028022f) {
5949 /* GPIO2 High = Enable EAPD */
5950 spec->eapd_mask = spec->gpio_mask = 0x04;
5951 spec->gpio_dir = spec->gpio_data = 0x04;
5953 spec->dmic_nids = stac927x_dmic_nids;
5954 spec->num_dmics = STAC927X_NUM_DMICS;
5956 spec->init = dell_3st_core_init;
5957 spec->dmux_nids = stac927x_dmux_nids;
5958 spec->num_dmuxes = ARRAY_SIZE(stac927x_dmux_nids);
5959 break;
5960 case STAC_927X_VOLKNOB:
5961 spec->num_dmics = 0;
5962 spec->init = stac927x_volknob_core_init;
5963 break;
5964 default:
5965 spec->num_dmics = 0;
5966 spec->init = stac927x_core_init;
5967 break;
5970 spec->num_caps = STAC927X_NUM_CAPS;
5971 spec->capvols = stac927x_capvols;
5972 spec->capsws = stac927x_capsws;
5974 spec->num_pwrs = 0;
5975 spec->aloopback_ctl = stac927x_loopback;
5976 spec->aloopback_mask = 0x40;
5977 spec->aloopback_shift = 0;
5978 spec->eapd_switch = 1;
5980 err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
5981 if (!err) {
5982 if (spec->board_config < 0) {
5983 printk(KERN_WARNING "hda_codec: No auto-config is "
5984 "available, default to model=ref\n");
5985 spec->board_config = STAC_D965_REF;
5986 goto again;
5988 err = -EINVAL;
5990 if (err < 0) {
5991 stac92xx_free(codec);
5992 return err;
5995 codec->patch_ops = stac92xx_patch_ops;
5997 codec->proc_widget_hook = stac927x_proc_hook;
6000 * !!FIXME!!
6001 * The STAC927x seem to require fairly long delays for certain
6002 * command sequences. With too short delays (even if the answer
6003 * is set to RIRB properly), it results in the silence output
6004 * on some hardwares like Dell.
6006 * The below flag enables the longer delay (see get_response
6007 * in hda_intel.c).
6009 codec->bus->needs_damn_long_delay = 1;
6011 /* no jack detecion for ref-no-jd model */
6012 if (spec->board_config == STAC_D965_REF_NO_JD)
6013 spec->hp_detect = 0;
6015 return 0;
6018 static int patch_stac9205(struct hda_codec *codec)
6020 struct sigmatel_spec *spec;
6021 int err;
6023 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6024 if (spec == NULL)
6025 return -ENOMEM;
6027 codec->no_trigger_sense = 1;
6028 codec->spec = spec;
6029 spec->linear_tone_beep = 1;
6030 spec->num_pins = ARRAY_SIZE(stac9205_pin_nids);
6031 spec->pin_nids = stac9205_pin_nids;
6032 spec->board_config = snd_hda_check_board_config(codec, STAC_9205_MODELS,
6033 stac9205_models,
6034 stac9205_cfg_tbl);
6035 again:
6036 if (spec->board_config < 0)
6037 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6038 codec->chip_name);
6039 else
6040 stac92xx_set_config_regs(codec,
6041 stac9205_brd_tbl[spec->board_config]);
6043 spec->digbeep_nid = 0x23;
6044 spec->adc_nids = stac9205_adc_nids;
6045 spec->num_adcs = ARRAY_SIZE(stac9205_adc_nids);
6046 spec->mux_nids = stac9205_mux_nids;
6047 spec->num_muxes = ARRAY_SIZE(stac9205_mux_nids);
6048 spec->smux_nids = stac9205_smux_nids;
6049 spec->num_smuxes = ARRAY_SIZE(stac9205_smux_nids);
6050 spec->dmic_nids = stac9205_dmic_nids;
6051 spec->num_dmics = STAC9205_NUM_DMICS;
6052 spec->dmux_nids = stac9205_dmux_nids;
6053 spec->num_dmuxes = ARRAY_SIZE(stac9205_dmux_nids);
6054 spec->num_pwrs = 0;
6056 spec->init = stac9205_core_init;
6057 spec->aloopback_ctl = stac9205_loopback;
6059 spec->num_caps = STAC9205_NUM_CAPS;
6060 spec->capvols = stac9205_capvols;
6061 spec->capsws = stac9205_capsws;
6063 spec->aloopback_mask = 0x40;
6064 spec->aloopback_shift = 0;
6065 /* Turn on/off EAPD per HP plugging */
6066 if (spec->board_config != STAC_9205_EAPD)
6067 spec->eapd_switch = 1;
6068 spec->multiout.dac_nids = spec->dac_nids;
6070 switch (spec->board_config){
6071 case STAC_9205_DELL_M43:
6072 /* Enable SPDIF in/out */
6073 snd_hda_codec_set_pincfg(codec, 0x1f, 0x01441030);
6074 snd_hda_codec_set_pincfg(codec, 0x20, 0x1c410030);
6076 /* Enable unsol response for GPIO4/Dock HP connection */
6077 err = stac_add_event(spec, codec->afg, STAC_VREF_EVENT, 0x01);
6078 if (err < 0)
6079 return err;
6080 snd_hda_codec_write_cache(codec, codec->afg, 0,
6081 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x10);
6082 snd_hda_codec_write_cache(codec, codec->afg, 0,
6083 AC_VERB_SET_UNSOLICITED_ENABLE,
6084 AC_USRSP_EN | err);
6086 spec->gpio_dir = 0x0b;
6087 spec->eapd_mask = 0x01;
6088 spec->gpio_mask = 0x1b;
6089 spec->gpio_mute = 0x10;
6090 /* GPIO0 High = EAPD, GPIO1 Low = Headphone Mute,
6091 * GPIO3 Low = DRM
6093 spec->gpio_data = 0x01;
6094 break;
6095 case STAC_9205_REF:
6096 /* SPDIF-In enabled */
6097 break;
6098 default:
6099 /* GPIO0 High = EAPD */
6100 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
6101 spec->gpio_data = 0x01;
6102 break;
6105 err = stac92xx_parse_auto_config(codec, 0x1f, 0x20);
6106 if (!err) {
6107 if (spec->board_config < 0) {
6108 printk(KERN_WARNING "hda_codec: No auto-config is "
6109 "available, default to model=ref\n");
6110 spec->board_config = STAC_9205_REF;
6111 goto again;
6113 err = -EINVAL;
6115 if (err < 0) {
6116 stac92xx_free(codec);
6117 return err;
6120 codec->patch_ops = stac92xx_patch_ops;
6122 codec->proc_widget_hook = stac9205_proc_hook;
6124 return 0;
6128 * STAC9872 hack
6131 static struct hda_verb stac9872_core_init[] = {
6132 {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
6133 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
6137 static hda_nid_t stac9872_pin_nids[] = {
6138 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
6139 0x11, 0x13, 0x14,
6142 static hda_nid_t stac9872_adc_nids[] = {
6143 0x8 /*,0x6*/
6146 static hda_nid_t stac9872_mux_nids[] = {
6147 0x15
6150 static unsigned long stac9872_capvols[] = {
6151 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
6153 #define stac9872_capsws stac9872_capvols
6155 static unsigned int stac9872_vaio_pin_configs[9] = {
6156 0x03211020, 0x411111f0, 0x411111f0, 0x03a15030,
6157 0x411111f0, 0x90170110, 0x411111f0, 0x411111f0,
6158 0x90a7013e
6161 static const char *stac9872_models[STAC_9872_MODELS] = {
6162 [STAC_9872_AUTO] = "auto",
6163 [STAC_9872_VAIO] = "vaio",
6166 static unsigned int *stac9872_brd_tbl[STAC_9872_MODELS] = {
6167 [STAC_9872_VAIO] = stac9872_vaio_pin_configs,
6170 static struct snd_pci_quirk stac9872_cfg_tbl[] = {
6171 SND_PCI_QUIRK_MASK(0x104d, 0xfff0, 0x81e0,
6172 "Sony VAIO F/S", STAC_9872_VAIO),
6173 {} /* terminator */
6176 static int patch_stac9872(struct hda_codec *codec)
6178 struct sigmatel_spec *spec;
6179 int err;
6181 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6182 if (spec == NULL)
6183 return -ENOMEM;
6184 codec->no_trigger_sense = 1;
6185 codec->spec = spec;
6186 spec->linear_tone_beep = 1;
6187 spec->num_pins = ARRAY_SIZE(stac9872_pin_nids);
6188 spec->pin_nids = stac9872_pin_nids;
6190 spec->board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
6191 stac9872_models,
6192 stac9872_cfg_tbl);
6193 if (spec->board_config < 0)
6194 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6195 codec->chip_name);
6196 else
6197 stac92xx_set_config_regs(codec,
6198 stac9872_brd_tbl[spec->board_config]);
6200 spec->multiout.dac_nids = spec->dac_nids;
6201 spec->num_adcs = ARRAY_SIZE(stac9872_adc_nids);
6202 spec->adc_nids = stac9872_adc_nids;
6203 spec->num_muxes = ARRAY_SIZE(stac9872_mux_nids);
6204 spec->mux_nids = stac9872_mux_nids;
6205 spec->init = stac9872_core_init;
6206 spec->num_caps = 1;
6207 spec->capvols = stac9872_capvols;
6208 spec->capsws = stac9872_capsws;
6210 err = stac92xx_parse_auto_config(codec, 0x10, 0x12);
6211 if (err < 0) {
6212 stac92xx_free(codec);
6213 return -EINVAL;
6215 spec->input_mux = &spec->private_imux;
6216 codec->patch_ops = stac92xx_patch_ops;
6217 return 0;
6222 * patch entries
6224 static struct hda_codec_preset snd_hda_preset_sigmatel[] = {
6225 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
6226 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
6227 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
6228 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
6229 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
6230 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
6231 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
6232 { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
6233 { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
6234 { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
6235 { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
6236 { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
6237 { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
6238 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
6239 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
6240 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
6241 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
6242 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
6243 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
6244 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
6245 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
6246 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
6247 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
6248 { .id = 0x83847632, .name = "STAC9202", .patch = patch_stac925x },
6249 { .id = 0x83847633, .name = "STAC9202D", .patch = patch_stac925x },
6250 { .id = 0x83847634, .name = "STAC9250", .patch = patch_stac925x },
6251 { .id = 0x83847635, .name = "STAC9250D", .patch = patch_stac925x },
6252 { .id = 0x83847636, .name = "STAC9251", .patch = patch_stac925x },
6253 { .id = 0x83847637, .name = "STAC9250D", .patch = patch_stac925x },
6254 { .id = 0x83847645, .name = "92HD206X", .patch = patch_stac927x },
6255 { .id = 0x83847646, .name = "92HD206D", .patch = patch_stac927x },
6256 /* The following does not take into account .id=0x83847661 when subsys =
6257 * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
6258 * currently not fully supported.
6260 { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
6261 { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
6262 { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
6263 { .id = 0x83847698, .name = "STAC9205", .patch = patch_stac9205 },
6264 { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
6265 { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
6266 { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
6267 { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
6268 { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
6269 { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
6270 { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
6271 { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
6272 { .id = 0x111d7603, .name = "92HD75B3X5", .patch = patch_stac92hd71bxx},
6273 { .id = 0x111d7604, .name = "92HD83C1X5", .patch = patch_stac92hd83xxx},
6274 { .id = 0x111d76d4, .name = "92HD83C1C5", .patch = patch_stac92hd83xxx},
6275 { .id = 0x111d7605, .name = "92HD81B1X5", .patch = patch_stac92hd83xxx},
6276 { .id = 0x111d76d5, .name = "92HD81B1C5", .patch = patch_stac92hd83xxx},
6277 { .id = 0x111d7666, .name = "92HD88B3", .patch = patch_stac92hd83xxx},
6278 { .id = 0x111d7667, .name = "92HD88B1", .patch = patch_stac92hd83xxx},
6279 { .id = 0x111d7668, .name = "92HD88B2", .patch = patch_stac92hd83xxx},
6280 { .id = 0x111d7669, .name = "92HD88B4", .patch = patch_stac92hd83xxx},
6281 { .id = 0x111d7608, .name = "92HD75B2X5", .patch = patch_stac92hd71bxx},
6282 { .id = 0x111d7674, .name = "92HD73D1X5", .patch = patch_stac92hd73xx },
6283 { .id = 0x111d7675, .name = "92HD73C1X5", .patch = patch_stac92hd73xx },
6284 { .id = 0x111d7676, .name = "92HD73E1X5", .patch = patch_stac92hd73xx },
6285 { .id = 0x111d76b0, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
6286 { .id = 0x111d76b1, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
6287 { .id = 0x111d76b2, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
6288 { .id = 0x111d76b3, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
6289 { .id = 0x111d76b4, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
6290 { .id = 0x111d76b5, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
6291 { .id = 0x111d76b6, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
6292 { .id = 0x111d76b7, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
6293 {} /* terminator */
6296 MODULE_ALIAS("snd-hda-codec-id:8384*");
6297 MODULE_ALIAS("snd-hda-codec-id:111d*");
6299 MODULE_LICENSE("GPL");
6300 MODULE_DESCRIPTION("IDT/Sigmatel HD-audio codec");
6302 static struct hda_codec_preset_list sigmatel_list = {
6303 .preset = snd_hda_preset_sigmatel,
6304 .owner = THIS_MODULE,
6307 static int __init patch_sigmatel_init(void)
6309 return snd_hda_add_codec_preset(&sigmatel_list);
6312 static void __exit patch_sigmatel_exit(void)
6314 snd_hda_delete_codec_preset(&sigmatel_list);
6317 module_init(patch_sigmatel_init)
6318 module_exit(patch_sigmatel_exit)