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 <sound/driver.h>
28 #include <linux/init.h>
29 #include <linux/delay.h>
30 #include <linux/slab.h>
31 #include <linux/pci.h>
32 #include <sound/core.h>
33 #include <sound/asoundef.h>
34 #include "hda_codec.h"
35 #include "hda_local.h"
37 #define NUM_CONTROL_ALLOC 32
38 #define STAC_HP_EVENT 0x37
41 #define STAC_D945GTP3 1
42 #define STAC_D945GTP5 2
43 #define STAC_MACMINI 3
44 #define STAC_922X_MODELS 4 /* number of 922x models */
45 #define STAC_D965_3ST 4
46 #define STAC_D965_5ST 5
47 #define STAC_927X_MODELS 6 /* number of 927x models */
49 struct sigmatel_spec {
50 struct snd_kcontrol_new *mixers[4];
51 unsigned int num_mixers;
54 unsigned int surr_switch: 1;
55 unsigned int line_switch: 1;
56 unsigned int mic_switch: 1;
57 unsigned int alt_switch: 1;
58 unsigned int hp_detect: 1;
59 unsigned int gpio_mute: 1;
62 struct hda_multi_out multiout;
63 hda_nid_t dac_nids[5];
67 unsigned int num_adcs;
69 unsigned int num_muxes;
71 unsigned int num_dmics;
77 unsigned int num_pins;
78 unsigned int *pin_configs;
79 unsigned int *bios_pin_configs;
81 /* codec specific stuff */
82 struct hda_verb *init;
83 struct snd_kcontrol_new *mixer;
86 struct hda_input_mux *dinput_mux;
87 unsigned int cur_dmux;
88 struct hda_input_mux *input_mux;
89 unsigned int cur_mux[3];
92 unsigned int io_switch[2];
94 struct hda_pcm pcm_rec[2]; /* PCM information */
96 /* dynamic controls and input_mux */
97 struct auto_pin_cfg autocfg;
98 unsigned int num_kctl_alloc, num_kctl_used;
99 struct snd_kcontrol_new *kctl_alloc;
100 struct hda_input_mux private_dimux;
101 struct hda_input_mux private_imux;
104 static hda_nid_t stac9200_adc_nids[1] = {
108 static hda_nid_t stac9200_mux_nids[1] = {
112 static hda_nid_t stac9200_dac_nids[1] = {
116 static hda_nid_t stac922x_adc_nids[2] = {
120 static hda_nid_t stac922x_mux_nids[2] = {
124 static hda_nid_t stac927x_adc_nids[3] = {
128 static hda_nid_t stac927x_mux_nids[3] = {
132 static hda_nid_t stac9205_adc_nids[2] = {
136 static hda_nid_t stac9205_mux_nids[2] = {
140 static hda_nid_t stac9205_dmic_nids[3] = {
144 static hda_nid_t stac9200_pin_nids[8] = {
145 0x08, 0x09, 0x0d, 0x0e,
146 0x0f, 0x10, 0x11, 0x12,
149 static hda_nid_t stac922x_pin_nids[10] = {
150 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
151 0x0f, 0x10, 0x11, 0x15, 0x1b,
154 static hda_nid_t stac927x_pin_nids[14] = {
155 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
156 0x0f, 0x10, 0x11, 0x12, 0x13,
157 0x14, 0x21, 0x22, 0x23,
160 static hda_nid_t stac9205_pin_nids[12] = {
161 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
162 0x0f, 0x14, 0x16, 0x17, 0x18,
167 static int stac92xx_dmux_enum_info(struct snd_kcontrol *kcontrol,
168 struct snd_ctl_elem_info *uinfo)
170 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
171 struct sigmatel_spec *spec = codec->spec;
172 return snd_hda_input_mux_info(spec->dinput_mux, uinfo);
175 static int stac92xx_dmux_enum_get(struct snd_kcontrol *kcontrol,
176 struct snd_ctl_elem_value *ucontrol)
178 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
179 struct sigmatel_spec *spec = codec->spec;
181 ucontrol->value.enumerated.item[0] = spec->cur_dmux;
185 static int stac92xx_dmux_enum_put(struct snd_kcontrol *kcontrol,
186 struct snd_ctl_elem_value *ucontrol)
188 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
189 struct sigmatel_spec *spec = codec->spec;
191 return snd_hda_input_mux_put(codec, spec->dinput_mux, ucontrol,
192 spec->dmux_nid, &spec->cur_dmux);
195 static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
197 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
198 struct sigmatel_spec *spec = codec->spec;
199 return snd_hda_input_mux_info(spec->input_mux, uinfo);
202 static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
204 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
205 struct sigmatel_spec *spec = codec->spec;
206 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
208 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
212 static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
214 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
215 struct sigmatel_spec *spec = codec->spec;
216 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
218 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
219 spec->mux_nids[adc_idx], &spec->cur_mux[adc_idx]);
222 static struct hda_verb stac9200_core_init[] = {
223 /* set dac0mux for dac converter */
224 { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
228 static struct hda_verb stac922x_core_init[] = {
229 /* set master volume and direct control */
230 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
234 static struct hda_verb d965_core_init[] = {
235 /* set master volume and direct control */
236 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
237 /* unmute node 0x1b */
238 { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
239 /* select node 0x03 as DAC */
240 { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
244 static struct hda_verb stac927x_core_init[] = {
245 /* set master volume and direct control */
246 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
250 static struct hda_verb stac9205_core_init[] = {
251 /* set master volume and direct control */
252 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
256 static struct snd_kcontrol_new stac9200_mixer[] = {
257 HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
258 HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
260 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
261 .name = "Input Source",
263 .info = stac92xx_mux_enum_info,
264 .get = stac92xx_mux_enum_get,
265 .put = stac92xx_mux_enum_put,
267 HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
268 HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
269 HDA_CODEC_VOLUME("Capture Mux Volume", 0x0c, 0, HDA_OUTPUT),
273 /* This needs to be generated dynamically based on sequence */
274 static struct snd_kcontrol_new stac922x_mixer[] = {
276 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
277 .name = "Input Source",
279 .info = stac92xx_mux_enum_info,
280 .get = stac92xx_mux_enum_get,
281 .put = stac92xx_mux_enum_put,
283 HDA_CODEC_VOLUME("Capture Volume", 0x17, 0x0, HDA_INPUT),
284 HDA_CODEC_MUTE("Capture Switch", 0x17, 0x0, HDA_INPUT),
285 HDA_CODEC_VOLUME("Mux Capture Volume", 0x12, 0x0, HDA_OUTPUT),
289 /* This needs to be generated dynamically based on sequence */
290 static struct snd_kcontrol_new stac9227_mixer[] = {
292 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
293 .name = "Input Source",
295 .info = stac92xx_mux_enum_info,
296 .get = stac92xx_mux_enum_get,
297 .put = stac92xx_mux_enum_put,
299 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
300 HDA_CODEC_MUTE("Capture Switch", 0x1b, 0x0, HDA_OUTPUT),
304 static snd_kcontrol_new_t stac927x_mixer[] = {
306 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
307 .name = "Input Source",
309 .info = stac92xx_mux_enum_info,
310 .get = stac92xx_mux_enum_get,
311 .put = stac92xx_mux_enum_put,
313 HDA_CODEC_VOLUME("InMux Capture Volume", 0x15, 0x0, HDA_OUTPUT),
314 HDA_CODEC_VOLUME("InVol Capture Volume", 0x18, 0x0, HDA_INPUT),
315 HDA_CODEC_MUTE("ADCMux Capture Switch", 0x1b, 0x0, HDA_OUTPUT),
319 static snd_kcontrol_new_t stac9205_mixer[] = {
321 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
322 .name = "Digital Input Source",
324 .info = stac92xx_dmux_enum_info,
325 .get = stac92xx_dmux_enum_get,
326 .put = stac92xx_dmux_enum_put,
329 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
330 .name = "Input Source",
332 .info = stac92xx_mux_enum_info,
333 .get = stac92xx_mux_enum_get,
334 .put = stac92xx_mux_enum_put,
336 HDA_CODEC_VOLUME("InMux Capture Volume", 0x19, 0x0, HDA_OUTPUT),
337 HDA_CODEC_VOLUME("InVol Capture Volume", 0x1b, 0x0, HDA_INPUT),
338 HDA_CODEC_MUTE("ADCMux Capture Switch", 0x1d, 0x0, HDA_OUTPUT),
342 static int stac92xx_build_controls(struct hda_codec *codec)
344 struct sigmatel_spec *spec = codec->spec;
348 err = snd_hda_add_new_ctls(codec, spec->mixer);
352 for (i = 0; i < spec->num_mixers; i++) {
353 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
358 if (spec->multiout.dig_out_nid) {
359 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
363 if (spec->dig_in_nid) {
364 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
371 static unsigned int ref9200_pin_configs[8] = {
372 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
373 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
376 static unsigned int *stac9200_brd_tbl[] = {
380 static struct hda_board_config stac9200_cfg_tbl[] = {
381 { .modelname = "ref",
382 .pci_subvendor = PCI_VENDOR_ID_INTEL,
383 .pci_subdevice = 0x2668, /* DFI LanParty */
384 .config = STAC_REF },
385 /* Dell laptops have BIOS problem */
386 { .pci_subvendor = PCI_VENDOR_ID_DELL, .pci_subdevice = 0x01b5,
387 .config = STAC_REF }, /* Dell Inspiron 630m */
388 { .pci_subvendor = PCI_VENDOR_ID_DELL, .pci_subdevice = 0x01c2,
389 .config = STAC_REF }, /* Dell Latitude D620 */
390 { .pci_subvendor = PCI_VENDOR_ID_DELL, .pci_subdevice = 0x01cb,
391 .config = STAC_REF }, /* Dell Latitude 120L */
395 static unsigned int ref922x_pin_configs[10] = {
396 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
397 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
398 0x40000100, 0x40000100,
401 static unsigned int d945gtp3_pin_configs[10] = {
402 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
403 0x40000100, 0x40000100, 0x40000100, 0x40000100,
404 0x02a19120, 0x40000100,
407 static unsigned int d945gtp5_pin_configs[10] = {
408 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
409 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
410 0x02a19320, 0x40000100,
413 static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
414 [STAC_REF] = ref922x_pin_configs,
415 [STAC_D945GTP3] = d945gtp3_pin_configs,
416 [STAC_D945GTP5] = d945gtp5_pin_configs,
417 [STAC_MACMINI] = d945gtp5_pin_configs,
420 static struct hda_board_config stac922x_cfg_tbl[] = {
421 { .modelname = "5stack", .config = STAC_D945GTP5 },
422 { .modelname = "3stack", .config = STAC_D945GTP3 },
423 { .modelname = "ref",
424 .pci_subvendor = PCI_VENDOR_ID_INTEL,
425 .pci_subdevice = 0x2668, /* DFI LanParty */
426 .config = STAC_REF }, /* SigmaTel reference board */
427 /* Intel 945G based systems */
428 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
429 .pci_subdevice = 0x0101,
430 .config = STAC_D945GTP3 }, /* Intel D945GTP - 3 Stack */
431 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
432 .pci_subdevice = 0x0202,
433 .config = STAC_D945GTP3 }, /* Intel D945GNT - 3 Stack */
434 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
435 .pci_subdevice = 0x0606,
436 .config = STAC_D945GTP3 }, /* Intel D945GTP - 3 Stack */
437 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
438 .pci_subdevice = 0x0601,
439 .config = STAC_D945GTP3 }, /* Intel D945GTP - 3 Stack */
440 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
441 .pci_subdevice = 0x0111,
442 .config = STAC_D945GTP3 }, /* Intel D945GZP - 3 Stack */
443 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
444 .pci_subdevice = 0x1115,
445 .config = STAC_D945GTP3 }, /* Intel D945GPM - 3 Stack */
446 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
447 .pci_subdevice = 0x1116,
448 .config = STAC_D945GTP3 }, /* Intel D945GBO - 3 Stack */
449 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
450 .pci_subdevice = 0x1117,
451 .config = STAC_D945GTP3 }, /* Intel D945GPM - 3 Stack */
452 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
453 .pci_subdevice = 0x1118,
454 .config = STAC_D945GTP3 }, /* Intel D945GPM - 3 Stack */
455 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
456 .pci_subdevice = 0x1119,
457 .config = STAC_D945GTP3 }, /* Intel D945GPM - 3 Stack */
458 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
459 .pci_subdevice = 0x8826,
460 .config = STAC_D945GTP3 }, /* Intel D945GPM - 3 Stack */
461 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
462 .pci_subdevice = 0x5049,
463 .config = STAC_D945GTP3 }, /* Intel D945GCZ - 3 Stack */
464 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
465 .pci_subdevice = 0x5055,
466 .config = STAC_D945GTP3 }, /* Intel D945GCZ - 3 Stack */
467 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
468 .pci_subdevice = 0x5048,
469 .config = STAC_D945GTP3 }, /* Intel D945GPB - 3 Stack */
470 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
471 .pci_subdevice = 0x0110,
472 .config = STAC_D945GTP3 }, /* Intel D945GLR - 3 Stack */
473 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
474 .pci_subdevice = 0x0404,
475 .config = STAC_D945GTP5 }, /* Intel D945GTP - 5 Stack */
476 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
477 .pci_subdevice = 0x0303,
478 .config = STAC_D945GTP5 }, /* Intel D945GNT - 5 Stack */
479 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
480 .pci_subdevice = 0x0013,
481 .config = STAC_D945GTP5 }, /* Intel D955XBK - 5 Stack */
482 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
483 .pci_subdevice = 0x0417,
484 .config = STAC_D945GTP5 }, /* Intel D975XBK - 5 Stack */
485 /* Intel 945P based systems */
486 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
487 .pci_subdevice = 0x0b0b,
488 .config = STAC_D945GTP3 }, /* Intel D945PSN - 3 Stack */
489 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
490 .pci_subdevice = 0x0112,
491 .config = STAC_D945GTP3 }, /* Intel D945PLN - 3 Stack */
492 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
493 .pci_subdevice = 0x0d0d,
494 .config = STAC_D945GTP3 }, /* Intel D945PLM - 3 Stack */
495 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
496 .pci_subdevice = 0x0909,
497 .config = STAC_D945GTP3 }, /* Intel D945PAW - 3 Stack */
498 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
499 .pci_subdevice = 0x0505,
500 .config = STAC_D945GTP3 }, /* Intel D945PLM - 3 Stack */
501 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
502 .pci_subdevice = 0x0707,
503 .config = STAC_D945GTP5 }, /* Intel D945PSV - 5 Stack */
505 { .pci_subvendor = 0x8384,
506 .pci_subdevice = 0x7680,
507 .config = STAC_MACMINI }, /* Apple Mac Mini (early 2006) */
511 static unsigned int ref927x_pin_configs[14] = {
512 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
513 0x01a19040, 0x01011012, 0x01016011, 0x0101201f,
514 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
515 0x01c42190, 0x40000100,
518 static unsigned int d965_3st_pin_configs[14] = {
519 0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
520 0x01a19021, 0x01813024, 0x40000100, 0x40000100,
521 0x40000100, 0x40000100, 0x40000100, 0x40000100,
522 0x40000100, 0x40000100
525 static unsigned int d965_5st_pin_configs[14] = {
526 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
527 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
528 0x40000100, 0x40000100, 0x40000100, 0x01442070,
529 0x40000100, 0x40000100
532 static unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
533 [STAC_REF] = ref927x_pin_configs,
534 [STAC_D965_3ST] = d965_3st_pin_configs,
535 [STAC_D965_5ST] = d965_5st_pin_configs,
538 static struct hda_board_config stac927x_cfg_tbl[] = {
539 { .modelname = "5stack", .config = STAC_D965_5ST },
540 { .modelname = "3stack", .config = STAC_D965_3ST },
541 { .modelname = "ref",
542 .pci_subvendor = PCI_VENDOR_ID_INTEL,
543 .pci_subdevice = 0x2668, /* DFI LanParty */
544 .config = STAC_REF }, /* SigmaTel reference board */
545 /* Intel 946 based systems */
546 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
547 .pci_subdevice = 0x3d01,
548 .config = STAC_D965_3ST }, /* D946 configuration */
549 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
550 .pci_subdevice = 0xa301,
551 .config = STAC_D965_3ST }, /* Intel D946GZT - 3 stack */
552 /* 965 based 3 stack systems */
553 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
554 .pci_subdevice = 0x2116,
555 .config = STAC_D965_3ST }, /* Intel D965 3Stack config */
556 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
557 .pci_subdevice = 0x2115,
558 .config = STAC_D965_3ST }, /* Intel DQ965WC - 3 Stack */
559 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
560 .pci_subdevice = 0x2114,
561 .config = STAC_D965_3ST }, /* Intel D965 3Stack config */
562 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
563 .pci_subdevice = 0x2113,
564 .config = STAC_D965_3ST }, /* Intel D965 3Stack config */
565 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
566 .pci_subdevice = 0x2112,
567 .config = STAC_D965_3ST }, /* Intel DG965MS - 3 Stack */
568 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
569 .pci_subdevice = 0x2111,
570 .config = STAC_D965_3ST }, /* Intel D965 3Stack config */
571 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
572 .pci_subdevice = 0x2110,
573 .config = STAC_D965_3ST }, /* Intel D965 3Stack config */
574 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
575 .pci_subdevice = 0x2009,
576 .config = STAC_D965_3ST }, /* Intel D965 3Stack config */
577 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
578 .pci_subdevice = 0x2008,
579 .config = STAC_D965_3ST }, /* Intel DQ965GF - 3 Stack */
580 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
581 .pci_subdevice = 0x2007,
582 .config = STAC_D965_3ST }, /* Intel D965 3Stack config */
583 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
584 .pci_subdevice = 0x2006,
585 .config = STAC_D965_3ST }, /* Intel D965 3Stack config */
586 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
587 .pci_subdevice = 0x2005,
588 .config = STAC_D965_3ST }, /* Intel D965 3Stack config */
589 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
590 .pci_subdevice = 0x2004,
591 .config = STAC_D965_3ST }, /* Intel D965 3Stack config */
592 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
593 .pci_subdevice = 0x2003,
594 .config = STAC_D965_3ST }, /* Intel D965 3Stack config */
595 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
596 .pci_subdevice = 0x2002,
597 .config = STAC_D965_3ST }, /* Intel D965 3Stack config */
598 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
599 .pci_subdevice = 0x2001,
600 .config = STAC_D965_3ST }, /* Intel DQ965GF - 3 Stack */
601 /* 965 based 5 stack systems */
602 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
603 .pci_subdevice = 0x2301,
604 .config = STAC_D965_5ST }, /* Intel DG965 - 5 Stack */
605 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
606 .pci_subdevice = 0x2302,
607 .config = STAC_D965_5ST }, /* Intel DG965 - 5 Stack */
608 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
609 .pci_subdevice = 0x2303,
610 .config = STAC_D965_5ST }, /* Intel DG965 - 5 Stack */
611 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
612 .pci_subdevice = 0x2304,
613 .config = STAC_D965_5ST }, /* Intel DG965 - 5 Stack */
614 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
615 .pci_subdevice = 0x2305,
616 .config = STAC_D965_5ST }, /* Intel DG965 - 5 Stack */
617 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
618 .pci_subdevice = 0x2501,
619 .config = STAC_D965_5ST }, /* Intel DG965MQ - 5 Stack */
620 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
621 .pci_subdevice = 0x2502,
622 .config = STAC_D965_5ST }, /* Intel DG965 - 5 Stack */
623 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
624 .pci_subdevice = 0x2503,
625 .config = STAC_D965_5ST }, /* Intel DG965 - 5 Stack */
626 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
627 .pci_subdevice = 0x2504,
628 .config = STAC_D965_5ST }, /* Intel DQ965GF - 5 Stack */
632 static unsigned int ref9205_pin_configs[12] = {
633 0x40000100, 0x40000100, 0x01016011, 0x01014010,
634 0x01813122, 0x01a19021, 0x40000100, 0x40000100,
635 0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
638 static unsigned int *stac9205_brd_tbl[] = {
642 static struct hda_board_config stac9205_cfg_tbl[] = {
643 { .modelname = "ref",
644 .pci_subvendor = PCI_VENDOR_ID_INTEL,
645 .pci_subdevice = 0x2668, /* DFI LanParty */
646 .config = STAC_REF }, /* SigmaTel reference board */
650 static int stac92xx_save_bios_config_regs(struct hda_codec *codec)
653 struct sigmatel_spec *spec = codec->spec;
655 if (! spec->bios_pin_configs) {
656 spec->bios_pin_configs = kcalloc(spec->num_pins,
657 sizeof(*spec->bios_pin_configs), GFP_KERNEL);
658 if (! spec->bios_pin_configs)
662 for (i = 0; i < spec->num_pins; i++) {
663 hda_nid_t nid = spec->pin_nids[i];
664 unsigned int pin_cfg;
666 pin_cfg = snd_hda_codec_read(codec, nid, 0,
667 AC_VERB_GET_CONFIG_DEFAULT, 0x00);
668 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x bios pin config %8.8x\n",
670 spec->bios_pin_configs[i] = pin_cfg;
676 static void stac92xx_set_config_regs(struct hda_codec *codec)
679 struct sigmatel_spec *spec = codec->spec;
680 unsigned int pin_cfg;
682 if (! spec->pin_nids || ! spec->pin_configs)
685 for (i = 0; i < spec->num_pins; i++) {
686 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
687 AC_VERB_SET_CONFIG_DEFAULT_BYTES_0,
688 spec->pin_configs[i] & 0x000000ff);
689 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
690 AC_VERB_SET_CONFIG_DEFAULT_BYTES_1,
691 (spec->pin_configs[i] & 0x0000ff00) >> 8);
692 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
693 AC_VERB_SET_CONFIG_DEFAULT_BYTES_2,
694 (spec->pin_configs[i] & 0x00ff0000) >> 16);
695 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
696 AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
697 spec->pin_configs[i] >> 24);
698 pin_cfg = snd_hda_codec_read(codec, spec->pin_nids[i], 0,
699 AC_VERB_GET_CONFIG_DEFAULT,
701 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x pin config %8.8x\n", spec->pin_nids[i], pin_cfg);
706 * Analog playback callbacks
708 static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
709 struct hda_codec *codec,
710 struct snd_pcm_substream *substream)
712 struct sigmatel_spec *spec = codec->spec;
713 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
716 static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
717 struct hda_codec *codec,
718 unsigned int stream_tag,
720 struct snd_pcm_substream *substream)
722 struct sigmatel_spec *spec = codec->spec;
723 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
726 static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
727 struct hda_codec *codec,
728 struct snd_pcm_substream *substream)
730 struct sigmatel_spec *spec = codec->spec;
731 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
735 * Digital playback callbacks
737 static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
738 struct hda_codec *codec,
739 struct snd_pcm_substream *substream)
741 struct sigmatel_spec *spec = codec->spec;
742 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
745 static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
746 struct hda_codec *codec,
747 struct snd_pcm_substream *substream)
749 struct sigmatel_spec *spec = codec->spec;
750 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
755 * Analog capture callbacks
757 static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
758 struct hda_codec *codec,
759 unsigned int stream_tag,
761 struct snd_pcm_substream *substream)
763 struct sigmatel_spec *spec = codec->spec;
765 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
766 stream_tag, 0, format);
770 static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
771 struct hda_codec *codec,
772 struct snd_pcm_substream *substream)
774 struct sigmatel_spec *spec = codec->spec;
776 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 0, 0, 0);
780 static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
784 /* NID is set in stac92xx_build_pcms */
786 .open = stac92xx_dig_playback_pcm_open,
787 .close = stac92xx_dig_playback_pcm_close
791 static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
795 /* NID is set in stac92xx_build_pcms */
798 static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
802 .nid = 0x02, /* NID to query formats and rates */
804 .open = stac92xx_playback_pcm_open,
805 .prepare = stac92xx_playback_pcm_prepare,
806 .cleanup = stac92xx_playback_pcm_cleanup
810 static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
814 .nid = 0x06, /* NID to query formats and rates */
816 .open = stac92xx_playback_pcm_open,
817 .prepare = stac92xx_playback_pcm_prepare,
818 .cleanup = stac92xx_playback_pcm_cleanup
822 static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
826 /* NID is set in stac92xx_build_pcms */
828 .prepare = stac92xx_capture_pcm_prepare,
829 .cleanup = stac92xx_capture_pcm_cleanup
833 static int stac92xx_build_pcms(struct hda_codec *codec)
835 struct sigmatel_spec *spec = codec->spec;
836 struct hda_pcm *info = spec->pcm_rec;
839 codec->pcm_info = info;
841 info->name = "STAC92xx Analog";
842 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
843 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
844 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
846 if (spec->alt_switch) {
849 info->name = "STAC92xx Analog Alt";
850 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
853 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
856 info->name = "STAC92xx Digital";
857 if (spec->multiout.dig_out_nid) {
858 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
859 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
861 if (spec->dig_in_nid) {
862 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
863 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
870 static unsigned int stac92xx_get_vref(struct hda_codec *codec, hda_nid_t nid)
872 unsigned int pincap = snd_hda_param_read(codec, nid,
874 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
875 if (pincap & AC_PINCAP_VREF_100)
876 return AC_PINCTL_VREF_100;
877 if (pincap & AC_PINCAP_VREF_80)
878 return AC_PINCTL_VREF_80;
879 if (pincap & AC_PINCAP_VREF_50)
880 return AC_PINCTL_VREF_50;
881 if (pincap & AC_PINCAP_VREF_GRD)
882 return AC_PINCTL_VREF_GRD;
886 static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
889 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
892 static int stac92xx_io_switch_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
894 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
896 uinfo->value.integer.min = 0;
897 uinfo->value.integer.max = 1;
901 static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
903 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
904 struct sigmatel_spec *spec = codec->spec;
905 int io_idx = kcontrol-> private_value & 0xff;
907 ucontrol->value.integer.value[0] = spec->io_switch[io_idx];
911 static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
913 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
914 struct sigmatel_spec *spec = codec->spec;
915 hda_nid_t nid = kcontrol->private_value >> 8;
916 int io_idx = kcontrol-> private_value & 0xff;
917 unsigned short val = ucontrol->value.integer.value[0];
919 spec->io_switch[io_idx] = val;
922 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
924 unsigned int pinctl = AC_PINCTL_IN_EN;
925 if (io_idx) /* set VREF for mic */
926 pinctl |= stac92xx_get_vref(codec, nid);
927 stac92xx_auto_set_pinctl(codec, nid, pinctl);
932 #define STAC_CODEC_IO_SWITCH(xname, xpval) \
933 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
936 .info = stac92xx_io_switch_info, \
937 .get = stac92xx_io_switch_get, \
938 .put = stac92xx_io_switch_put, \
939 .private_value = xpval, \
945 STAC_CTL_WIDGET_MUTE,
946 STAC_CTL_WIDGET_IO_SWITCH,
949 static struct snd_kcontrol_new stac92xx_control_templates[] = {
950 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
951 HDA_CODEC_MUTE(NULL, 0, 0, 0),
952 STAC_CODEC_IO_SWITCH(NULL, 0),
955 /* add dynamic controls */
956 static int stac92xx_add_control(struct sigmatel_spec *spec, int type, const char *name, unsigned long val)
958 struct snd_kcontrol_new *knew;
960 if (spec->num_kctl_used >= spec->num_kctl_alloc) {
961 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
963 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */
966 if (spec->kctl_alloc) {
967 memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
968 kfree(spec->kctl_alloc);
970 spec->kctl_alloc = knew;
971 spec->num_kctl_alloc = num;
974 knew = &spec->kctl_alloc[spec->num_kctl_used];
975 *knew = stac92xx_control_templates[type];
976 knew->name = kstrdup(name, GFP_KERNEL);
979 knew->private_value = val;
980 spec->num_kctl_used++;
984 /* flag inputs as additional dynamic lineouts */
985 static int stac92xx_add_dyn_out_pins(struct hda_codec *codec, struct auto_pin_cfg *cfg)
987 struct sigmatel_spec *spec = codec->spec;
989 switch (cfg->line_outs) {
991 /* add line-in as side */
992 if (cfg->input_pins[AUTO_PIN_LINE]) {
993 cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_LINE];
994 spec->line_switch = 1;
999 /* add line-in as clfe and mic as side */
1000 if (cfg->input_pins[AUTO_PIN_LINE]) {
1001 cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_LINE];
1002 spec->line_switch = 1;
1005 if (cfg->input_pins[AUTO_PIN_MIC]) {
1006 cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_MIC];
1007 spec->mic_switch = 1;
1012 /* add line-in as surr and mic as clfe */
1013 if (cfg->input_pins[AUTO_PIN_LINE]) {
1014 cfg->line_out_pins[1] = cfg->input_pins[AUTO_PIN_LINE];
1015 spec->line_switch = 1;
1018 if (cfg->input_pins[AUTO_PIN_MIC]) {
1019 cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_MIC];
1020 spec->mic_switch = 1;
1030 * XXX The line_out pin widget connection list may not be set to the
1031 * desired DAC nid. This is the case on 927x where ports A and B can
1032 * be routed to several DACs.
1034 * This requires an analysis of the line-out/hp pin configuration
1035 * to provide a best fit for pin/DAC configurations that are routable.
1036 * For now, 927x DAC4 is not supported and 927x DAC1 output to ports
1037 * A and B is not supported.
1039 /* fill in the dac_nids table from the parsed pin configuration */
1040 static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec,
1041 const struct auto_pin_cfg *cfg)
1043 struct sigmatel_spec *spec = codec->spec;
1047 /* check the pins hardwired to audio widget */
1048 for (i = 0; i < cfg->line_outs; i++) {
1049 nid = cfg->line_out_pins[i];
1050 spec->multiout.dac_nids[i] = snd_hda_codec_read(codec, nid, 0,
1051 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
1054 spec->multiout.num_dacs = cfg->line_outs;
1059 /* create volume control/switch for the given prefx type */
1060 static int create_controls(struct sigmatel_spec *spec, const char *pfx, hda_nid_t nid, int chs)
1065 sprintf(name, "%s Playback Volume", pfx);
1066 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, name,
1067 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1070 sprintf(name, "%s Playback Switch", pfx);
1071 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, name,
1072 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1078 /* add playback controls from the parsed DAC table */
1079 static int stac92xx_auto_create_multi_out_ctls(struct sigmatel_spec *spec,
1080 const struct auto_pin_cfg *cfg)
1082 static const char *chname[4] = {
1083 "Front", "Surround", NULL /*CLFE*/, "Side"
1088 for (i = 0; i < cfg->line_outs; i++) {
1089 if (!spec->multiout.dac_nids[i])
1092 nid = spec->multiout.dac_nids[i];
1096 err = create_controls(spec, "Center", nid, 1);
1099 err = create_controls(spec, "LFE", nid, 2);
1103 err = create_controls(spec, chname[i], nid, 3);
1109 if (spec->line_switch)
1110 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Line In as Output Switch", cfg->input_pins[AUTO_PIN_LINE] << 8)) < 0)
1113 if (spec->mic_switch)
1114 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Mic as Output Switch", (cfg->input_pins[AUTO_PIN_MIC] << 8) | 1)) < 0)
1120 static int check_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
1124 for (i = 0; i < spec->multiout.num_dacs; i++) {
1125 if (spec->multiout.dac_nids[i] == nid)
1128 if (spec->multiout.hp_nid == nid)
1133 static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
1135 if (!spec->multiout.hp_nid)
1136 spec->multiout.hp_nid = nid;
1137 else if (spec->multiout.num_dacs > 4) {
1138 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
1141 spec->multiout.dac_nids[spec->multiout.num_dacs] = nid;
1142 spec->multiout.num_dacs++;
1147 /* add playback controls for Speaker and HP outputs */
1148 static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
1149 struct auto_pin_cfg *cfg)
1151 struct sigmatel_spec *spec = codec->spec;
1153 int i, old_num_dacs, err;
1155 old_num_dacs = spec->multiout.num_dacs;
1156 for (i = 0; i < cfg->hp_outs; i++) {
1157 unsigned int wid_caps = get_wcaps(codec, cfg->hp_pins[i]);
1158 if (wid_caps & AC_WCAP_UNSOL_CAP)
1159 spec->hp_detect = 1;
1160 nid = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
1161 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
1162 if (check_in_dac_nids(spec, nid))
1166 add_spec_dacs(spec, nid);
1168 for (i = 0; i < cfg->speaker_outs; i++) {
1169 nid = snd_hda_codec_read(codec, cfg->speaker_pins[0], 0,
1170 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
1171 if (check_in_dac_nids(spec, nid))
1173 if (check_in_dac_nids(spec, nid))
1177 add_spec_dacs(spec, nid);
1180 for (i = old_num_dacs; i < spec->multiout.num_dacs; i++) {
1181 static const char *pfxs[] = {
1182 "Speaker", "External Speaker", "Speaker2",
1184 err = create_controls(spec, pfxs[i - old_num_dacs],
1185 spec->multiout.dac_nids[i], 3);
1189 if (spec->multiout.hp_nid) {
1191 if (old_num_dacs == spec->multiout.num_dacs)
1195 err = create_controls(spec, pfx, spec->multiout.hp_nid, 3);
1203 /* labels for dmic mux inputs */
1204 const char *stac92xx_dmic_labels[5] = {
1205 "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
1206 "Digital Mic 3", "Digital Mic 4"
1209 /* create playback/capture controls for input pins on dmic capable codecs */
1210 static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
1211 const struct auto_pin_cfg *cfg)
1213 struct sigmatel_spec *spec = codec->spec;
1214 struct hda_input_mux *dimux = &spec->private_dimux;
1215 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
1218 dimux->items[dimux->num_items].label = stac92xx_dmic_labels[0];
1219 dimux->items[dimux->num_items].index = 0;
1222 for (i = 0; i < spec->num_dmics; i++) {
1225 unsigned int def_conf;
1227 def_conf = snd_hda_codec_read(codec,
1230 AC_VERB_GET_CONFIG_DEFAULT,
1232 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
1235 num_cons = snd_hda_get_connections(codec,
1238 HDA_MAX_NUM_INPUTS);
1239 for (j = 0; j < num_cons; j++)
1240 if (con_lst[j] == spec->dmic_nids[i]) {
1246 dimux->items[dimux->num_items].label =
1247 stac92xx_dmic_labels[dimux->num_items];
1248 dimux->items[dimux->num_items].index = index;
1255 /* create playback/capture controls for input pins */
1256 static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
1258 struct sigmatel_spec *spec = codec->spec;
1259 struct hda_input_mux *imux = &spec->private_imux;
1260 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
1263 for (i = 0; i < AUTO_PIN_LAST; i++) {
1266 if (!cfg->input_pins[i])
1269 for (j = 0; j < spec->num_muxes; j++) {
1271 num_cons = snd_hda_get_connections(codec,
1274 HDA_MAX_NUM_INPUTS);
1275 for (k = 0; k < num_cons; k++)
1276 if (con_lst[k] == cfg->input_pins[i]) {
1283 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
1284 imux->items[imux->num_items].index = index;
1288 if (imux->num_items == 1) {
1290 * Set the current input for the muxes.
1291 * The STAC9221 has two input muxes with identical source
1292 * NID lists. Hopefully this won't get confused.
1294 for (i = 0; i < spec->num_muxes; i++) {
1295 snd_hda_codec_write(codec, spec->mux_nids[i], 0,
1296 AC_VERB_SET_CONNECT_SEL,
1297 imux->items[0].index);
1304 static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
1306 struct sigmatel_spec *spec = codec->spec;
1309 for (i = 0; i < spec->autocfg.line_outs; i++) {
1310 hda_nid_t nid = spec->autocfg.line_out_pins[i];
1311 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
1315 static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
1317 struct sigmatel_spec *spec = codec->spec;
1320 for (i = 0; i < spec->autocfg.hp_outs; i++) {
1322 pin = spec->autocfg.hp_pins[i];
1323 if (pin) /* connect to front */
1324 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
1326 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
1328 pin = spec->autocfg.speaker_pins[i];
1329 if (pin) /* connect to front */
1330 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
1334 static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out, hda_nid_t dig_in)
1336 struct sigmatel_spec *spec = codec->spec;
1339 if ((err = snd_hda_parse_pin_def_config(codec,
1341 spec->dmic_nids)) < 0)
1343 if (! spec->autocfg.line_outs)
1344 return 0; /* can't find valid pin config */
1346 if ((err = stac92xx_add_dyn_out_pins(codec, &spec->autocfg)) < 0)
1348 if (spec->multiout.num_dacs == 0)
1349 if ((err = stac92xx_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
1352 if ((err = stac92xx_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
1353 (err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg)) < 0 ||
1354 (err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
1357 if (spec->num_dmics > 0)
1358 if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
1359 &spec->autocfg)) < 0)
1362 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
1363 if (spec->multiout.max_channels > 2)
1364 spec->surr_switch = 1;
1366 if (spec->autocfg.dig_out_pin)
1367 spec->multiout.dig_out_nid = dig_out;
1368 if (spec->autocfg.dig_in_pin)
1369 spec->dig_in_nid = dig_in;
1371 if (spec->kctl_alloc)
1372 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
1374 spec->input_mux = &spec->private_imux;
1375 spec->dinput_mux = &spec->private_dimux;
1380 /* add playback controls for HP output */
1381 static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
1382 struct auto_pin_cfg *cfg)
1384 struct sigmatel_spec *spec = codec->spec;
1385 hda_nid_t pin = cfg->hp_pins[0];
1386 unsigned int wid_caps;
1391 wid_caps = get_wcaps(codec, pin);
1392 if (wid_caps & AC_WCAP_UNSOL_CAP)
1393 spec->hp_detect = 1;
1398 /* add playback controls for LFE output */
1399 static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
1400 struct auto_pin_cfg *cfg)
1402 struct sigmatel_spec *spec = codec->spec;
1404 hda_nid_t lfe_pin = 0x0;
1408 * search speaker outs and line outs for a mono speaker pin
1409 * with an amp. If one is found, add LFE controls
1412 for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
1413 hda_nid_t pin = spec->autocfg.speaker_pins[i];
1414 unsigned long wcaps = get_wcaps(codec, pin);
1415 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
1416 if (wcaps == AC_WCAP_OUT_AMP)
1417 /* found a mono speaker with an amp, must be lfe */
1421 /* if speaker_outs is 0, then speakers may be in line_outs */
1422 if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
1423 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
1424 hda_nid_t pin = spec->autocfg.line_out_pins[i];
1426 cfg = snd_hda_codec_read(codec, pin, 0,
1427 AC_VERB_GET_CONFIG_DEFAULT,
1429 if (get_defcfg_device(cfg) == AC_JACK_SPEAKER) {
1430 unsigned long wcaps = get_wcaps(codec, pin);
1431 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
1432 if (wcaps == AC_WCAP_OUT_AMP)
1433 /* found a mono speaker with an amp,
1441 err = create_controls(spec, "LFE", lfe_pin, 1);
1449 static int stac9200_parse_auto_config(struct hda_codec *codec)
1451 struct sigmatel_spec *spec = codec->spec;
1454 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
1457 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
1460 if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
1463 if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
1466 if (spec->autocfg.dig_out_pin)
1467 spec->multiout.dig_out_nid = 0x05;
1468 if (spec->autocfg.dig_in_pin)
1469 spec->dig_in_nid = 0x04;
1471 if (spec->kctl_alloc)
1472 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
1474 spec->input_mux = &spec->private_imux;
1475 spec->dinput_mux = &spec->private_dimux;
1481 * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
1482 * funky external mute control using GPIO pins.
1485 static void stac922x_gpio_mute(struct hda_codec *codec, int pin, int muted)
1487 unsigned int gpiostate, gpiomask, gpiodir;
1489 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
1490 AC_VERB_GET_GPIO_DATA, 0);
1493 gpiostate |= (1 << pin);
1495 gpiostate &= ~(1 << pin);
1497 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
1498 AC_VERB_GET_GPIO_MASK, 0);
1499 gpiomask |= (1 << pin);
1501 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
1502 AC_VERB_GET_GPIO_DIRECTION, 0);
1503 gpiodir |= (1 << pin);
1505 /* AppleHDA seems to do this -- WTF is this verb?? */
1506 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
1508 snd_hda_codec_write(codec, codec->afg, 0,
1509 AC_VERB_SET_GPIO_MASK, gpiomask);
1510 snd_hda_codec_write(codec, codec->afg, 0,
1511 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
1515 snd_hda_codec_write(codec, codec->afg, 0,
1516 AC_VERB_SET_GPIO_DATA, gpiostate);
1519 static void enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
1522 if (get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP)
1523 snd_hda_codec_write(codec, nid, 0,
1524 AC_VERB_SET_UNSOLICITED_ENABLE,
1525 (AC_USRSP_EN | event));
1528 static int stac92xx_init(struct hda_codec *codec)
1530 struct sigmatel_spec *spec = codec->spec;
1531 struct auto_pin_cfg *cfg = &spec->autocfg;
1534 snd_hda_sequence_write(codec, spec->init);
1537 if (spec->hp_detect) {
1538 /* Enable unsolicited responses on the HP widget */
1539 for (i = 0; i < cfg->hp_outs; i++)
1540 enable_pin_detect(codec, cfg->hp_pins[i],
1542 stac92xx_auto_init_hp_out(codec);
1543 /* fake event to set up pins */
1544 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
1546 stac92xx_auto_init_multi_out(codec);
1547 stac92xx_auto_init_hp_out(codec);
1549 for (i = 0; i < AUTO_PIN_LAST; i++) {
1550 hda_nid_t nid = cfg->input_pins[i];
1552 unsigned int pinctl = AC_PINCTL_IN_EN;
1553 if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC)
1554 pinctl |= stac92xx_get_vref(codec, nid);
1555 stac92xx_auto_set_pinctl(codec, nid, pinctl);
1558 if (spec->num_dmics > 0)
1559 for (i = 0; i < spec->num_dmics; i++)
1560 stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
1563 if (cfg->dig_out_pin)
1564 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pin,
1566 if (cfg->dig_in_pin)
1567 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
1570 if (spec->gpio_mute) {
1571 stac922x_gpio_mute(codec, 0, 0);
1572 stac922x_gpio_mute(codec, 1, 0);
1578 static void stac92xx_free(struct hda_codec *codec)
1580 struct sigmatel_spec *spec = codec->spec;
1586 if (spec->kctl_alloc) {
1587 for (i = 0; i < spec->num_kctl_used; i++)
1588 kfree(spec->kctl_alloc[i].name);
1589 kfree(spec->kctl_alloc);
1592 if (spec->bios_pin_configs)
1593 kfree(spec->bios_pin_configs);
1598 static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
1601 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
1602 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
1603 if (flag == AC_PINCTL_OUT_EN && (pin_ctl & AC_PINCTL_IN_EN))
1605 snd_hda_codec_write(codec, nid, 0,
1606 AC_VERB_SET_PIN_WIDGET_CONTROL,
1610 static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
1613 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
1614 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
1615 snd_hda_codec_write(codec, nid, 0,
1616 AC_VERB_SET_PIN_WIDGET_CONTROL,
1620 static int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
1624 if (snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PIN_SENSE, 0x00)
1630 static void stac92xx_hp_detect(struct hda_codec *codec, unsigned int res)
1632 struct sigmatel_spec *spec = codec->spec;
1633 struct auto_pin_cfg *cfg = &spec->autocfg;
1637 for (i = 0; i < cfg->hp_outs; i++) {
1638 presence = get_pin_presence(codec, cfg->hp_pins[i]);
1644 /* disable lineouts, enable hp */
1645 for (i = 0; i < cfg->line_outs; i++)
1646 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
1648 for (i = 0; i < cfg->speaker_outs; i++)
1649 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
1652 /* enable lineouts, disable hp */
1653 for (i = 0; i < cfg->line_outs; i++)
1654 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
1656 for (i = 0; i < cfg->speaker_outs; i++)
1657 stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
1662 static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
1664 switch (res >> 26) {
1666 stac92xx_hp_detect(codec, res);
1672 static int stac92xx_resume(struct hda_codec *codec)
1674 struct sigmatel_spec *spec = codec->spec;
1677 stac92xx_init(codec);
1678 stac92xx_set_config_regs(codec);
1679 for (i = 0; i < spec->num_mixers; i++)
1680 snd_hda_resume_ctls(codec, spec->mixers[i]);
1681 if (spec->multiout.dig_out_nid)
1682 snd_hda_resume_spdif_out(codec);
1683 if (spec->dig_in_nid)
1684 snd_hda_resume_spdif_in(codec);
1690 static struct hda_codec_ops stac92xx_patch_ops = {
1691 .build_controls = stac92xx_build_controls,
1692 .build_pcms = stac92xx_build_pcms,
1693 .init = stac92xx_init,
1694 .free = stac92xx_free,
1695 .unsol_event = stac92xx_unsol_event,
1697 .resume = stac92xx_resume,
1701 static int patch_stac9200(struct hda_codec *codec)
1703 struct sigmatel_spec *spec;
1706 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1712 spec->pin_nids = stac9200_pin_nids;
1713 spec->board_config = snd_hda_check_board_config(codec, stac9200_cfg_tbl);
1714 if (spec->board_config < 0) {
1715 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9200, using BIOS defaults\n");
1716 err = stac92xx_save_bios_config_regs(codec);
1718 stac92xx_free(codec);
1721 spec->pin_configs = spec->bios_pin_configs;
1723 spec->pin_configs = stac9200_brd_tbl[spec->board_config];
1724 stac92xx_set_config_regs(codec);
1727 spec->multiout.max_channels = 2;
1728 spec->multiout.num_dacs = 1;
1729 spec->multiout.dac_nids = stac9200_dac_nids;
1730 spec->adc_nids = stac9200_adc_nids;
1731 spec->mux_nids = stac9200_mux_nids;
1732 spec->num_muxes = 1;
1733 spec->num_dmics = 0;
1735 spec->init = stac9200_core_init;
1736 spec->mixer = stac9200_mixer;
1738 err = stac9200_parse_auto_config(codec);
1740 stac92xx_free(codec);
1744 codec->patch_ops = stac92xx_patch_ops;
1749 static int patch_stac922x(struct hda_codec *codec)
1751 struct sigmatel_spec *spec;
1754 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1759 spec->num_pins = 10;
1760 spec->pin_nids = stac922x_pin_nids;
1761 spec->board_config = snd_hda_check_board_config(codec, stac922x_cfg_tbl);
1762 if (spec->board_config < 0) {
1763 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC922x, "
1764 "using BIOS defaults\n");
1765 err = stac92xx_save_bios_config_regs(codec);
1767 stac92xx_free(codec);
1770 spec->pin_configs = spec->bios_pin_configs;
1771 } else if (stac922x_brd_tbl[spec->board_config] != NULL) {
1772 spec->pin_configs = stac922x_brd_tbl[spec->board_config];
1773 stac92xx_set_config_regs(codec);
1776 spec->adc_nids = stac922x_adc_nids;
1777 spec->mux_nids = stac922x_mux_nids;
1778 spec->num_muxes = 2;
1779 spec->num_dmics = 0;
1781 spec->init = stac922x_core_init;
1782 spec->mixer = stac922x_mixer;
1784 spec->multiout.dac_nids = spec->dac_nids;
1786 err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
1788 stac92xx_free(codec);
1792 if (spec->board_config == STAC_MACMINI)
1793 spec->gpio_mute = 1;
1795 codec->patch_ops = stac92xx_patch_ops;
1800 static int patch_stac927x(struct hda_codec *codec)
1802 struct sigmatel_spec *spec;
1805 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1810 spec->num_pins = 14;
1811 spec->pin_nids = stac927x_pin_nids;
1812 spec->board_config = snd_hda_check_board_config(codec, stac927x_cfg_tbl);
1813 if (spec->board_config < 0) {
1814 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC927x, using BIOS defaults\n");
1815 err = stac92xx_save_bios_config_regs(codec);
1817 stac92xx_free(codec);
1820 spec->pin_configs = spec->bios_pin_configs;
1821 } else if (stac927x_brd_tbl[spec->board_config] != NULL) {
1822 spec->pin_configs = stac927x_brd_tbl[spec->board_config];
1823 stac92xx_set_config_regs(codec);
1826 switch (spec->board_config) {
1828 spec->adc_nids = stac927x_adc_nids;
1829 spec->mux_nids = stac927x_mux_nids;
1830 spec->num_muxes = 3;
1831 spec->num_dmics = 0;
1832 spec->init = d965_core_init;
1833 spec->mixer = stac9227_mixer;
1836 spec->adc_nids = stac927x_adc_nids;
1837 spec->mux_nids = stac927x_mux_nids;
1838 spec->num_muxes = 3;
1839 spec->num_dmics = 0;
1840 spec->init = d965_core_init;
1841 spec->mixer = stac9227_mixer;
1844 spec->adc_nids = stac927x_adc_nids;
1845 spec->mux_nids = stac927x_mux_nids;
1846 spec->num_muxes = 3;
1847 spec->num_dmics = 0;
1848 spec->init = stac927x_core_init;
1849 spec->mixer = stac927x_mixer;
1852 spec->multiout.dac_nids = spec->dac_nids;
1854 err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
1856 stac92xx_free(codec);
1860 codec->patch_ops = stac92xx_patch_ops;
1865 static int patch_stac9205(struct hda_codec *codec)
1867 struct sigmatel_spec *spec;
1870 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1875 spec->num_pins = 14;
1876 spec->pin_nids = stac9205_pin_nids;
1877 spec->board_config = snd_hda_check_board_config(codec, stac9205_cfg_tbl);
1878 if (spec->board_config < 0) {
1879 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9205, using BIOS defaults\n");
1880 err = stac92xx_save_bios_config_regs(codec);
1882 stac92xx_free(codec);
1885 spec->pin_configs = spec->bios_pin_configs;
1887 spec->pin_configs = stac9205_brd_tbl[spec->board_config];
1888 stac92xx_set_config_regs(codec);
1891 spec->adc_nids = stac9205_adc_nids;
1892 spec->mux_nids = stac9205_mux_nids;
1893 spec->num_muxes = 2;
1894 spec->dmic_nids = stac9205_dmic_nids;
1895 spec->num_dmics = 2;
1896 spec->dmux_nid = 0x1d;
1898 spec->init = stac9205_core_init;
1899 spec->mixer = stac9205_mixer;
1901 spec->multiout.dac_nids = spec->dac_nids;
1903 err = stac92xx_parse_auto_config(codec, 0x1f, 0x20);
1905 stac92xx_free(codec);
1909 codec->patch_ops = stac92xx_patch_ops;
1918 /* static config for Sony VAIO FE550G and Sony VAIO AR */
1919 static hda_nid_t vaio_dacs[] = { 0x2 };
1920 #define VAIO_HP_DAC 0x5
1921 static hda_nid_t vaio_adcs[] = { 0x8 /*,0x6*/ };
1922 static hda_nid_t vaio_mux_nids[] = { 0x15 };
1924 static struct hda_input_mux vaio_mux = {
1927 /* { "HP", 0x0 }, */
1934 static struct hda_verb vaio_init[] = {
1935 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
1936 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
1937 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
1938 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
1939 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
1940 {0x15, AC_VERB_SET_CONNECT_SEL, 0x2}, /* mic-sel: 0a,0d,14,02 */
1941 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
1942 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
1943 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
1944 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
1945 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
1949 static struct hda_verb vaio_ar_init[] = {
1950 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
1951 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
1952 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
1953 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
1954 /* {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },*/ /* Optical Out */
1955 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
1956 {0x15, AC_VERB_SET_CONNECT_SEL, 0x2}, /* mic-sel: 0a,0d,14,02 */
1957 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
1958 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
1959 /* {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},*/ /* Optical Out */
1960 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
1961 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
1962 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
1966 /* bind volumes of both NID 0x02 and 0x05 */
1967 static int vaio_master_vol_put(struct snd_kcontrol *kcontrol,
1968 struct snd_ctl_elem_value *ucontrol)
1970 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1971 long *valp = ucontrol->value.integer.value;
1974 change = snd_hda_codec_amp_update(codec, 0x02, 0, HDA_OUTPUT, 0,
1975 0x7f, valp[0] & 0x7f);
1976 change |= snd_hda_codec_amp_update(codec, 0x02, 1, HDA_OUTPUT, 0,
1977 0x7f, valp[1] & 0x7f);
1978 snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
1979 0x7f, valp[0] & 0x7f);
1980 snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
1981 0x7f, valp[1] & 0x7f);
1985 /* bind volumes of both NID 0x02 and 0x05 */
1986 static int vaio_master_sw_put(struct snd_kcontrol *kcontrol,
1987 struct snd_ctl_elem_value *ucontrol)
1989 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1990 long *valp = ucontrol->value.integer.value;
1993 change = snd_hda_codec_amp_update(codec, 0x02, 0, HDA_OUTPUT, 0,
1994 0x80, (valp[0] ? 0 : 0x80));
1995 change |= snd_hda_codec_amp_update(codec, 0x02, 1, HDA_OUTPUT, 0,
1996 0x80, (valp[1] ? 0 : 0x80));
1997 snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
1998 0x80, (valp[0] ? 0 : 0x80));
1999 snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
2000 0x80, (valp[1] ? 0 : 0x80));
2004 static struct snd_kcontrol_new vaio_mixer[] = {
2006 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2007 .name = "Master Playback Volume",
2008 .info = snd_hda_mixer_amp_volume_info,
2009 .get = snd_hda_mixer_amp_volume_get,
2010 .put = vaio_master_vol_put,
2011 .tlv = { .c = snd_hda_mixer_amp_tlv },
2012 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2015 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2016 .name = "Master Playback Switch",
2017 .info = snd_hda_mixer_amp_switch_info,
2018 .get = snd_hda_mixer_amp_switch_get,
2019 .put = vaio_master_sw_put,
2020 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2022 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
2023 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
2024 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
2026 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2027 .name = "Capture Source",
2029 .info = stac92xx_mux_enum_info,
2030 .get = stac92xx_mux_enum_get,
2031 .put = stac92xx_mux_enum_put,
2036 static struct snd_kcontrol_new vaio_ar_mixer[] = {
2038 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2039 .name = "Master Playback Volume",
2040 .info = snd_hda_mixer_amp_volume_info,
2041 .get = snd_hda_mixer_amp_volume_get,
2042 .put = vaio_master_vol_put,
2043 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2046 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2047 .name = "Master Playback Switch",
2048 .info = snd_hda_mixer_amp_switch_info,
2049 .get = snd_hda_mixer_amp_switch_get,
2050 .put = vaio_master_sw_put,
2051 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2053 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
2054 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
2055 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
2056 /*HDA_CODEC_MUTE("Optical Out Switch", 0x10, 0, HDA_OUTPUT),
2057 HDA_CODEC_VOLUME("Optical Out Volume", 0x10, 0, HDA_OUTPUT),*/
2059 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2060 .name = "Capture Source",
2062 .info = stac92xx_mux_enum_info,
2063 .get = stac92xx_mux_enum_get,
2064 .put = stac92xx_mux_enum_put,
2069 static struct hda_codec_ops stac9872_patch_ops = {
2070 .build_controls = stac92xx_build_controls,
2071 .build_pcms = stac92xx_build_pcms,
2072 .init = stac92xx_init,
2073 .free = stac92xx_free,
2075 .resume = stac92xx_resume,
2079 enum { /* FE and SZ series. id=0x83847661 and subsys=0x104D0700 or 104D1000. */
2081 /* Unknown. id=0x83847662 and subsys=0x104D1200 or 104D1000. */
2083 /* Unknown. id=0x83847661 and subsys=0x104D1200. */
2085 /* AR Series. id=0x83847664 and subsys=104D1300 */
2089 static struct hda_board_config stac9872_cfg_tbl[] = {
2090 { .modelname = "vaio", .config = CXD9872RD_VAIO },
2091 { .modelname = "vaio-ar", .config = CXD9872AKD_VAIO },
2092 { .pci_subvendor = 0x104d, .pci_subdevice = 0x81e6,
2093 .config = CXD9872RD_VAIO },
2094 { .pci_subvendor = 0x104d, .pci_subdevice = 0x81ef,
2095 .config = CXD9872RD_VAIO },
2096 { .pci_subvendor = 0x104d, .pci_subdevice = 0x81fd,
2097 .config = CXD9872AKD_VAIO },
2101 static int patch_stac9872(struct hda_codec *codec)
2103 struct sigmatel_spec *spec;
2106 board_config = snd_hda_check_board_config(codec, stac9872_cfg_tbl);
2107 if (board_config < 0)
2108 /* unknown config, let generic-parser do its job... */
2109 return snd_hda_parse_generic_codec(codec);
2111 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2116 switch (board_config) {
2117 case CXD9872RD_VAIO:
2118 case STAC9872AK_VAIO:
2119 case STAC9872K_VAIO:
2120 spec->mixer = vaio_mixer;
2121 spec->init = vaio_init;
2122 spec->multiout.max_channels = 2;
2123 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
2124 spec->multiout.dac_nids = vaio_dacs;
2125 spec->multiout.hp_nid = VAIO_HP_DAC;
2126 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
2127 spec->adc_nids = vaio_adcs;
2128 spec->input_mux = &vaio_mux;
2129 spec->mux_nids = vaio_mux_nids;
2132 case CXD9872AKD_VAIO:
2133 spec->mixer = vaio_ar_mixer;
2134 spec->init = vaio_ar_init;
2135 spec->multiout.max_channels = 2;
2136 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
2137 spec->multiout.dac_nids = vaio_dacs;
2138 spec->multiout.hp_nid = VAIO_HP_DAC;
2139 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
2140 spec->adc_nids = vaio_adcs;
2141 spec->input_mux = &vaio_mux;
2142 spec->mux_nids = vaio_mux_nids;
2146 codec->patch_ops = stac9872_patch_ops;
2154 struct hda_codec_preset snd_hda_preset_sigmatel[] = {
2155 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
2156 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
2157 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
2158 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
2159 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
2160 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
2161 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
2162 { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
2163 { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
2164 { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
2165 { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
2166 { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
2167 { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
2168 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
2169 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
2170 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
2171 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
2172 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
2173 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
2174 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
2175 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
2176 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
2177 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
2178 /* The following does not take into account .id=0x83847661 when subsys =
2179 * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
2180 * currently not fully supported.
2182 { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
2183 { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
2184 { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
2185 { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
2186 { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
2187 { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
2188 { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
2189 { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
2190 { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
2191 { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
2192 { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },