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
65 struct sigmatel_spec {
66 struct snd_kcontrol_new *mixers[4];
67 unsigned int num_mixers;
70 unsigned int surr_switch: 1;
71 unsigned int line_switch: 1;
72 unsigned int mic_switch: 1;
73 unsigned int alt_switch: 1;
74 unsigned int hp_detect: 1;
75 unsigned int gpio_mute: 1;
78 struct hda_multi_out multiout;
79 hda_nid_t dac_nids[5];
83 unsigned int num_adcs;
85 unsigned int num_muxes;
87 unsigned int num_dmics;
93 unsigned int num_pins;
94 unsigned int *pin_configs;
95 unsigned int *bios_pin_configs;
97 /* codec specific stuff */
98 struct hda_verb *init;
99 struct snd_kcontrol_new *mixer;
102 struct hda_input_mux *dinput_mux;
103 unsigned int cur_dmux;
104 struct hda_input_mux *input_mux;
105 unsigned int cur_mux[3];
108 unsigned int io_switch[2];
110 struct hda_pcm pcm_rec[2]; /* PCM information */
112 /* dynamic controls and input_mux */
113 struct auto_pin_cfg autocfg;
114 unsigned int num_kctl_alloc, num_kctl_used;
115 struct snd_kcontrol_new *kctl_alloc;
116 struct hda_input_mux private_dimux;
117 struct hda_input_mux private_imux;
120 static hda_nid_t stac9200_adc_nids[1] = {
124 static hda_nid_t stac9200_mux_nids[1] = {
128 static hda_nid_t stac9200_dac_nids[1] = {
132 static hda_nid_t stac922x_adc_nids[2] = {
136 static hda_nid_t stac922x_mux_nids[2] = {
140 static hda_nid_t stac927x_adc_nids[3] = {
144 static hda_nid_t stac927x_mux_nids[3] = {
148 static hda_nid_t stac9205_adc_nids[2] = {
152 static hda_nid_t stac9205_mux_nids[2] = {
156 static hda_nid_t stac9205_dmic_nids[3] = {
160 static hda_nid_t stac9200_pin_nids[8] = {
161 0x08, 0x09, 0x0d, 0x0e,
162 0x0f, 0x10, 0x11, 0x12,
165 static hda_nid_t stac922x_pin_nids[10] = {
166 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
167 0x0f, 0x10, 0x11, 0x15, 0x1b,
170 static hda_nid_t stac927x_pin_nids[14] = {
171 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
172 0x0f, 0x10, 0x11, 0x12, 0x13,
173 0x14, 0x21, 0x22, 0x23,
176 static hda_nid_t stac9205_pin_nids[12] = {
177 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
178 0x0f, 0x14, 0x16, 0x17, 0x18,
183 static int stac92xx_dmux_enum_info(struct snd_kcontrol *kcontrol,
184 struct snd_ctl_elem_info *uinfo)
186 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
187 struct sigmatel_spec *spec = codec->spec;
188 return snd_hda_input_mux_info(spec->dinput_mux, uinfo);
191 static int stac92xx_dmux_enum_get(struct snd_kcontrol *kcontrol,
192 struct snd_ctl_elem_value *ucontrol)
194 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
195 struct sigmatel_spec *spec = codec->spec;
197 ucontrol->value.enumerated.item[0] = spec->cur_dmux;
201 static int stac92xx_dmux_enum_put(struct snd_kcontrol *kcontrol,
202 struct snd_ctl_elem_value *ucontrol)
204 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
205 struct sigmatel_spec *spec = codec->spec;
207 return snd_hda_input_mux_put(codec, spec->dinput_mux, ucontrol,
208 spec->dmux_nid, &spec->cur_dmux);
211 static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
213 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
214 struct sigmatel_spec *spec = codec->spec;
215 return snd_hda_input_mux_info(spec->input_mux, uinfo);
218 static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
220 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
221 struct sigmatel_spec *spec = codec->spec;
222 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
224 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
228 static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
230 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
231 struct sigmatel_spec *spec = codec->spec;
232 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
234 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
235 spec->mux_nids[adc_idx], &spec->cur_mux[adc_idx]);
238 static struct hda_verb stac9200_core_init[] = {
239 /* set dac0mux for dac converter */
240 { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
244 static struct hda_verb stac922x_core_init[] = {
245 /* set master volume and direct control */
246 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
250 static struct hda_verb d965_core_init[] = {
251 /* set master volume and direct control */
252 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
253 /* unmute node 0x1b */
254 { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
255 /* select node 0x03 as DAC */
256 { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
260 static struct hda_verb stac927x_core_init[] = {
261 /* set master volume and direct control */
262 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
266 static struct hda_verb stac9205_core_init[] = {
267 /* set master volume and direct control */
268 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
272 static struct snd_kcontrol_new stac9200_mixer[] = {
273 HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
274 HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
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", 0x0a, 0, HDA_OUTPUT),
284 HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
285 HDA_CODEC_VOLUME("Capture Mux Volume", 0x0c, 0, HDA_OUTPUT),
289 /* This needs to be generated dynamically based on sequence */
290 static struct snd_kcontrol_new stac922x_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", 0x17, 0x0, HDA_INPUT),
300 HDA_CODEC_MUTE("Capture Switch", 0x17, 0x0, HDA_INPUT),
301 HDA_CODEC_VOLUME("Mux Capture Volume", 0x12, 0x0, HDA_OUTPUT),
305 /* This needs to be generated dynamically based on sequence */
306 static struct snd_kcontrol_new stac9227_mixer[] = {
308 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
309 .name = "Input Source",
311 .info = stac92xx_mux_enum_info,
312 .get = stac92xx_mux_enum_get,
313 .put = stac92xx_mux_enum_put,
315 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
316 HDA_CODEC_MUTE("Capture Switch", 0x1b, 0x0, HDA_OUTPUT),
320 static struct snd_kcontrol_new stac927x_mixer[] = {
322 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
323 .name = "Input Source",
325 .info = stac92xx_mux_enum_info,
326 .get = stac92xx_mux_enum_get,
327 .put = stac92xx_mux_enum_put,
329 HDA_CODEC_VOLUME("InMux Capture Volume", 0x15, 0x0, HDA_OUTPUT),
330 HDA_CODEC_VOLUME("InVol Capture Volume", 0x18, 0x0, HDA_INPUT),
331 HDA_CODEC_MUTE("ADCMux Capture Switch", 0x1b, 0x0, HDA_OUTPUT),
335 static struct snd_kcontrol_new stac9205_mixer[] = {
337 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
338 .name = "Digital Input Source",
340 .info = stac92xx_dmux_enum_info,
341 .get = stac92xx_dmux_enum_get,
342 .put = stac92xx_dmux_enum_put,
345 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
346 .name = "Input Source",
348 .info = stac92xx_mux_enum_info,
349 .get = stac92xx_mux_enum_get,
350 .put = stac92xx_mux_enum_put,
352 HDA_CODEC_VOLUME("InMux Capture Volume", 0x19, 0x0, HDA_OUTPUT),
353 HDA_CODEC_VOLUME("InVol Capture Volume", 0x1b, 0x0, HDA_INPUT),
354 HDA_CODEC_MUTE("ADCMux Capture Switch", 0x1d, 0x0, HDA_OUTPUT),
358 static int stac92xx_build_controls(struct hda_codec *codec)
360 struct sigmatel_spec *spec = codec->spec;
364 err = snd_hda_add_new_ctls(codec, spec->mixer);
368 for (i = 0; i < spec->num_mixers; i++) {
369 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
374 if (spec->multiout.dig_out_nid) {
375 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
379 if (spec->dig_in_nid) {
380 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
387 static unsigned int ref9200_pin_configs[8] = {
388 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
389 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
392 static unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
393 [STAC_REF] = ref9200_pin_configs,
396 static const char *stac9200_models[STAC_9200_MODELS] = {
400 static struct snd_pci_quirk stac9200_cfg_tbl[] = {
401 /* SigmaTel reference board */
402 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
403 "DFI LanParty", STAC_REF),
404 /* Dell laptops have BIOS problem */
405 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01b5,
406 "Dell Inspiron 630m", STAC_REF),
407 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c2,
408 "Dell Latitude D620", STAC_REF),
409 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cb,
410 "Dell Latitude 120L", STAC_REF),
414 static unsigned int ref922x_pin_configs[10] = {
415 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
416 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
417 0x40000100, 0x40000100,
420 static unsigned int d945gtp3_pin_configs[10] = {
421 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
422 0x40000100, 0x40000100, 0x40000100, 0x40000100,
423 0x02a19120, 0x40000100,
426 static unsigned int d945gtp5_pin_configs[10] = {
427 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
428 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
429 0x02a19320, 0x40000100,
432 static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
433 [STAC_D945_REF] = ref922x_pin_configs,
434 [STAC_D945GTP3] = d945gtp3_pin_configs,
435 [STAC_D945GTP5] = d945gtp5_pin_configs,
436 [STAC_MACMINI] = d945gtp5_pin_configs,
439 static const char *stac922x_models[STAC_922X_MODELS] = {
440 [STAC_D945_REF] = "ref",
441 [STAC_D945GTP5] = "5stack",
442 [STAC_D945GTP3] = "3stack",
443 [STAC_MACMINI] = "macmini",
446 static struct snd_pci_quirk stac922x_cfg_tbl[] = {
447 /* SigmaTel reference board */
448 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
449 "DFI LanParty", STAC_D945_REF),
450 /* Intel 945G based systems */
451 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101,
452 "Intel D945G", STAC_D945GTP3),
453 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0202,
454 "Intel D945G", STAC_D945GTP3),
455 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0606,
456 "Intel D945G", STAC_D945GTP3),
457 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0601,
458 "Intel D945G", STAC_D945GTP3),
459 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0111,
460 "Intel D945G", STAC_D945GTP3),
461 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1115,
462 "Intel D945G", STAC_D945GTP3),
463 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1116,
464 "Intel D945G", STAC_D945GTP3),
465 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1117,
466 "Intel D945G", STAC_D945GTP3),
467 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1118,
468 "Intel D945G", STAC_D945GTP3),
469 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1119,
470 "Intel D945G", STAC_D945GTP3),
471 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x8826,
472 "Intel D945G", STAC_D945GTP3),
473 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5049,
474 "Intel D945G", STAC_D945GTP3),
475 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5055,
476 "Intel D945G", STAC_D945GTP3),
477 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5048,
478 "Intel D945G", STAC_D945GTP3),
479 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0110,
480 "Intel D945G", STAC_D945GTP3),
481 /* Intel D945G 5-stack systems */
482 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0404,
483 "Intel D945G", STAC_D945GTP5),
484 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0303,
485 "Intel D945G", STAC_D945GTP5),
486 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0013,
487 "Intel D945G", STAC_D945GTP5),
488 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0417,
489 "Intel D945G", STAC_D945GTP5),
490 /* Intel 945P based systems */
491 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0b0b,
492 "Intel D945P", STAC_D945GTP3),
493 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0112,
494 "Intel D945P", STAC_D945GTP3),
495 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0d0d,
496 "Intel D945P", STAC_D945GTP3),
497 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0909,
498 "Intel D945P", STAC_D945GTP3),
499 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0505,
500 "Intel D945P", STAC_D945GTP3),
501 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707,
502 "Intel D945P", STAC_D945GTP5),
504 /* Apple Mac Mini (early 2006) */
505 SND_PCI_QUIRK(0x8384, 0x7680,
506 "Mac Mini", STAC_MACMINI),
510 static unsigned int ref927x_pin_configs[14] = {
511 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
512 0x01a19040, 0x01011012, 0x01016011, 0x0101201f,
513 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
514 0x01c42190, 0x40000100,
517 static unsigned int d965_3st_pin_configs[14] = {
518 0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
519 0x01a19021, 0x01813024, 0x40000100, 0x40000100,
520 0x40000100, 0x40000100, 0x40000100, 0x40000100,
521 0x40000100, 0x40000100
524 static unsigned int d965_5st_pin_configs[14] = {
525 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
526 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
527 0x40000100, 0x40000100, 0x40000100, 0x01442070,
528 0x40000100, 0x40000100
531 static unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
532 [STAC_D965_REF] = ref927x_pin_configs,
533 [STAC_D965_3ST] = d965_3st_pin_configs,
534 [STAC_D965_5ST] = d965_5st_pin_configs,
537 static const char *stac927x_models[STAC_927X_MODELS] = {
538 [STAC_D965_REF] = "ref",
539 [STAC_D965_3ST] = "3stack",
540 [STAC_D965_5ST] = "5stack",
543 static struct snd_pci_quirk stac927x_cfg_tbl[] = {
544 /* SigmaTel reference board */
545 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
546 "DFI LanParty", STAC_D965_REF),
547 /* Intel 946 based systems */
548 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST),
549 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST),
550 /* 965 based 3 stack systems */
551 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2116, "Intel D965", STAC_D965_3ST),
552 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2115, "Intel D965", STAC_D965_3ST),
553 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2114, "Intel D965", STAC_D965_3ST),
554 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2113, "Intel D965", STAC_D965_3ST),
555 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2112, "Intel D965", STAC_D965_3ST),
556 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2111, "Intel D965", STAC_D965_3ST),
557 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2110, "Intel D965", STAC_D965_3ST),
558 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2009, "Intel D965", STAC_D965_3ST),
559 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2008, "Intel D965", STAC_D965_3ST),
560 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2007, "Intel D965", STAC_D965_3ST),
561 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2006, "Intel D965", STAC_D965_3ST),
562 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2005, "Intel D965", STAC_D965_3ST),
563 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2004, "Intel D965", STAC_D965_3ST),
564 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2003, "Intel D965", STAC_D965_3ST),
565 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2002, "Intel D965", STAC_D965_3ST),
566 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2001, "Intel D965", STAC_D965_3ST),
567 /* 965 based 5 stack systems */
568 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2301, "Intel D965", STAC_D965_5ST),
569 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2302, "Intel D965", STAC_D965_5ST),
570 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2303, "Intel D965", STAC_D965_5ST),
571 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2304, "Intel D965", STAC_D965_5ST),
572 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2305, "Intel D965", STAC_D965_5ST),
573 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2501, "Intel D965", STAC_D965_5ST),
574 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2502, "Intel D965", STAC_D965_5ST),
575 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2503, "Intel D965", STAC_D965_5ST),
576 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2504, "Intel D965", STAC_D965_5ST),
580 static unsigned int ref9205_pin_configs[12] = {
581 0x40000100, 0x40000100, 0x01016011, 0x01014010,
582 0x01813122, 0x01a19021, 0x40000100, 0x40000100,
583 0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
586 static unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
590 static const char *stac9205_models[STAC_9205_MODELS] = {
591 [STAC_9205_REF] = "ref",
594 static struct snd_pci_quirk stac9205_cfg_tbl[] = {
595 /* SigmaTel reference board */
596 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
597 "DFI LanParty", STAC_9205_REF),
601 static int stac92xx_save_bios_config_regs(struct hda_codec *codec)
604 struct sigmatel_spec *spec = codec->spec;
606 if (! spec->bios_pin_configs) {
607 spec->bios_pin_configs = kcalloc(spec->num_pins,
608 sizeof(*spec->bios_pin_configs), GFP_KERNEL);
609 if (! spec->bios_pin_configs)
613 for (i = 0; i < spec->num_pins; i++) {
614 hda_nid_t nid = spec->pin_nids[i];
615 unsigned int pin_cfg;
617 pin_cfg = snd_hda_codec_read(codec, nid, 0,
618 AC_VERB_GET_CONFIG_DEFAULT, 0x00);
619 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x bios pin config %8.8x\n",
621 spec->bios_pin_configs[i] = pin_cfg;
627 static void stac92xx_set_config_regs(struct hda_codec *codec)
630 struct sigmatel_spec *spec = codec->spec;
631 unsigned int pin_cfg;
633 if (! spec->pin_nids || ! spec->pin_configs)
636 for (i = 0; i < spec->num_pins; i++) {
637 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
638 AC_VERB_SET_CONFIG_DEFAULT_BYTES_0,
639 spec->pin_configs[i] & 0x000000ff);
640 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
641 AC_VERB_SET_CONFIG_DEFAULT_BYTES_1,
642 (spec->pin_configs[i] & 0x0000ff00) >> 8);
643 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
644 AC_VERB_SET_CONFIG_DEFAULT_BYTES_2,
645 (spec->pin_configs[i] & 0x00ff0000) >> 16);
646 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
647 AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
648 spec->pin_configs[i] >> 24);
649 pin_cfg = snd_hda_codec_read(codec, spec->pin_nids[i], 0,
650 AC_VERB_GET_CONFIG_DEFAULT,
652 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x pin config %8.8x\n", spec->pin_nids[i], pin_cfg);
657 * Analog playback callbacks
659 static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
660 struct hda_codec *codec,
661 struct snd_pcm_substream *substream)
663 struct sigmatel_spec *spec = codec->spec;
664 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
667 static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
668 struct hda_codec *codec,
669 unsigned int stream_tag,
671 struct snd_pcm_substream *substream)
673 struct sigmatel_spec *spec = codec->spec;
674 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
677 static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
678 struct hda_codec *codec,
679 struct snd_pcm_substream *substream)
681 struct sigmatel_spec *spec = codec->spec;
682 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
686 * Digital playback callbacks
688 static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
689 struct hda_codec *codec,
690 struct snd_pcm_substream *substream)
692 struct sigmatel_spec *spec = codec->spec;
693 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
696 static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
697 struct hda_codec *codec,
698 struct snd_pcm_substream *substream)
700 struct sigmatel_spec *spec = codec->spec;
701 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
706 * Analog capture callbacks
708 static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
709 struct hda_codec *codec,
710 unsigned int stream_tag,
712 struct snd_pcm_substream *substream)
714 struct sigmatel_spec *spec = codec->spec;
716 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
717 stream_tag, 0, format);
721 static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
722 struct hda_codec *codec,
723 struct snd_pcm_substream *substream)
725 struct sigmatel_spec *spec = codec->spec;
727 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 0, 0, 0);
731 static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
735 /* NID is set in stac92xx_build_pcms */
737 .open = stac92xx_dig_playback_pcm_open,
738 .close = stac92xx_dig_playback_pcm_close
742 static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
746 /* NID is set in stac92xx_build_pcms */
749 static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
753 .nid = 0x02, /* NID to query formats and rates */
755 .open = stac92xx_playback_pcm_open,
756 .prepare = stac92xx_playback_pcm_prepare,
757 .cleanup = stac92xx_playback_pcm_cleanup
761 static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
765 .nid = 0x06, /* NID to query formats and rates */
767 .open = stac92xx_playback_pcm_open,
768 .prepare = stac92xx_playback_pcm_prepare,
769 .cleanup = stac92xx_playback_pcm_cleanup
773 static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
777 /* NID is set in stac92xx_build_pcms */
779 .prepare = stac92xx_capture_pcm_prepare,
780 .cleanup = stac92xx_capture_pcm_cleanup
784 static int stac92xx_build_pcms(struct hda_codec *codec)
786 struct sigmatel_spec *spec = codec->spec;
787 struct hda_pcm *info = spec->pcm_rec;
790 codec->pcm_info = info;
792 info->name = "STAC92xx Analog";
793 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
794 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
795 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
797 if (spec->alt_switch) {
800 info->name = "STAC92xx Analog Alt";
801 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
804 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
807 info->name = "STAC92xx Digital";
808 if (spec->multiout.dig_out_nid) {
809 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
810 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
812 if (spec->dig_in_nid) {
813 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
814 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
821 static unsigned int stac92xx_get_vref(struct hda_codec *codec, hda_nid_t nid)
823 unsigned int pincap = snd_hda_param_read(codec, nid,
825 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
826 if (pincap & AC_PINCAP_VREF_100)
827 return AC_PINCTL_VREF_100;
828 if (pincap & AC_PINCAP_VREF_80)
829 return AC_PINCTL_VREF_80;
830 if (pincap & AC_PINCAP_VREF_50)
831 return AC_PINCTL_VREF_50;
832 if (pincap & AC_PINCAP_VREF_GRD)
833 return AC_PINCTL_VREF_GRD;
837 static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
840 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
843 static int stac92xx_io_switch_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
845 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
847 uinfo->value.integer.min = 0;
848 uinfo->value.integer.max = 1;
852 static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
854 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
855 struct sigmatel_spec *spec = codec->spec;
856 int io_idx = kcontrol-> private_value & 0xff;
858 ucontrol->value.integer.value[0] = spec->io_switch[io_idx];
862 static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
864 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
865 struct sigmatel_spec *spec = codec->spec;
866 hda_nid_t nid = kcontrol->private_value >> 8;
867 int io_idx = kcontrol-> private_value & 0xff;
868 unsigned short val = ucontrol->value.integer.value[0];
870 spec->io_switch[io_idx] = val;
873 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
875 unsigned int pinctl = AC_PINCTL_IN_EN;
876 if (io_idx) /* set VREF for mic */
877 pinctl |= stac92xx_get_vref(codec, nid);
878 stac92xx_auto_set_pinctl(codec, nid, pinctl);
883 #define STAC_CODEC_IO_SWITCH(xname, xpval) \
884 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
887 .info = stac92xx_io_switch_info, \
888 .get = stac92xx_io_switch_get, \
889 .put = stac92xx_io_switch_put, \
890 .private_value = xpval, \
896 STAC_CTL_WIDGET_MUTE,
897 STAC_CTL_WIDGET_IO_SWITCH,
900 static struct snd_kcontrol_new stac92xx_control_templates[] = {
901 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
902 HDA_CODEC_MUTE(NULL, 0, 0, 0),
903 STAC_CODEC_IO_SWITCH(NULL, 0),
906 /* add dynamic controls */
907 static int stac92xx_add_control(struct sigmatel_spec *spec, int type, const char *name, unsigned long val)
909 struct snd_kcontrol_new *knew;
911 if (spec->num_kctl_used >= spec->num_kctl_alloc) {
912 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
914 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */
917 if (spec->kctl_alloc) {
918 memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
919 kfree(spec->kctl_alloc);
921 spec->kctl_alloc = knew;
922 spec->num_kctl_alloc = num;
925 knew = &spec->kctl_alloc[spec->num_kctl_used];
926 *knew = stac92xx_control_templates[type];
927 knew->name = kstrdup(name, GFP_KERNEL);
930 knew->private_value = val;
931 spec->num_kctl_used++;
935 /* flag inputs as additional dynamic lineouts */
936 static int stac92xx_add_dyn_out_pins(struct hda_codec *codec, struct auto_pin_cfg *cfg)
938 struct sigmatel_spec *spec = codec->spec;
940 switch (cfg->line_outs) {
942 /* add line-in as side */
943 if (cfg->input_pins[AUTO_PIN_LINE]) {
944 cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_LINE];
945 spec->line_switch = 1;
950 /* add line-in as clfe and mic as side */
951 if (cfg->input_pins[AUTO_PIN_LINE]) {
952 cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_LINE];
953 spec->line_switch = 1;
956 if (cfg->input_pins[AUTO_PIN_MIC]) {
957 cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_MIC];
958 spec->mic_switch = 1;
963 /* add line-in as surr and mic as clfe */
964 if (cfg->input_pins[AUTO_PIN_LINE]) {
965 cfg->line_out_pins[1] = cfg->input_pins[AUTO_PIN_LINE];
966 spec->line_switch = 1;
969 if (cfg->input_pins[AUTO_PIN_MIC]) {
970 cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_MIC];
971 spec->mic_switch = 1;
981 * XXX The line_out pin widget connection list may not be set to the
982 * desired DAC nid. This is the case on 927x where ports A and B can
983 * be routed to several DACs.
985 * This requires an analysis of the line-out/hp pin configuration
986 * to provide a best fit for pin/DAC configurations that are routable.
987 * For now, 927x DAC4 is not supported and 927x DAC1 output to ports
988 * A and B is not supported.
990 /* fill in the dac_nids table from the parsed pin configuration */
991 static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec,
992 const struct auto_pin_cfg *cfg)
994 struct sigmatel_spec *spec = codec->spec;
998 /* check the pins hardwired to audio widget */
999 for (i = 0; i < cfg->line_outs; i++) {
1000 nid = cfg->line_out_pins[i];
1001 spec->multiout.dac_nids[i] = snd_hda_codec_read(codec, nid, 0,
1002 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
1005 spec->multiout.num_dacs = cfg->line_outs;
1010 /* create volume control/switch for the given prefx type */
1011 static int create_controls(struct sigmatel_spec *spec, const char *pfx, hda_nid_t nid, int chs)
1016 sprintf(name, "%s Playback Volume", pfx);
1017 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, name,
1018 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1021 sprintf(name, "%s Playback Switch", pfx);
1022 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, name,
1023 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1029 /* add playback controls from the parsed DAC table */
1030 static int stac92xx_auto_create_multi_out_ctls(struct sigmatel_spec *spec,
1031 const struct auto_pin_cfg *cfg)
1033 static const char *chname[4] = {
1034 "Front", "Surround", NULL /*CLFE*/, "Side"
1039 for (i = 0; i < cfg->line_outs; i++) {
1040 if (!spec->multiout.dac_nids[i])
1043 nid = spec->multiout.dac_nids[i];
1047 err = create_controls(spec, "Center", nid, 1);
1050 err = create_controls(spec, "LFE", nid, 2);
1054 err = create_controls(spec, chname[i], nid, 3);
1060 if (spec->line_switch)
1061 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Line In as Output Switch", cfg->input_pins[AUTO_PIN_LINE] << 8)) < 0)
1064 if (spec->mic_switch)
1065 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Mic as Output Switch", (cfg->input_pins[AUTO_PIN_MIC] << 8) | 1)) < 0)
1071 static int check_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
1075 for (i = 0; i < spec->multiout.num_dacs; i++) {
1076 if (spec->multiout.dac_nids[i] == nid)
1079 if (spec->multiout.hp_nid == nid)
1084 static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
1086 if (!spec->multiout.hp_nid)
1087 spec->multiout.hp_nid = nid;
1088 else if (spec->multiout.num_dacs > 4) {
1089 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
1092 spec->multiout.dac_nids[spec->multiout.num_dacs] = nid;
1093 spec->multiout.num_dacs++;
1098 /* add playback controls for Speaker and HP outputs */
1099 static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
1100 struct auto_pin_cfg *cfg)
1102 struct sigmatel_spec *spec = codec->spec;
1104 int i, old_num_dacs, err;
1106 old_num_dacs = spec->multiout.num_dacs;
1107 for (i = 0; i < cfg->hp_outs; i++) {
1108 unsigned int wid_caps = get_wcaps(codec, cfg->hp_pins[i]);
1109 if (wid_caps & AC_WCAP_UNSOL_CAP)
1110 spec->hp_detect = 1;
1111 nid = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
1112 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
1113 if (check_in_dac_nids(spec, nid))
1117 add_spec_dacs(spec, nid);
1119 for (i = 0; i < cfg->speaker_outs; i++) {
1120 nid = snd_hda_codec_read(codec, cfg->speaker_pins[0], 0,
1121 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
1122 if (check_in_dac_nids(spec, nid))
1124 if (check_in_dac_nids(spec, nid))
1128 add_spec_dacs(spec, nid);
1131 for (i = old_num_dacs; i < spec->multiout.num_dacs; i++) {
1132 static const char *pfxs[] = {
1133 "Speaker", "External Speaker", "Speaker2",
1135 err = create_controls(spec, pfxs[i - old_num_dacs],
1136 spec->multiout.dac_nids[i], 3);
1140 if (spec->multiout.hp_nid) {
1142 if (old_num_dacs == spec->multiout.num_dacs)
1146 err = create_controls(spec, pfx, spec->multiout.hp_nid, 3);
1154 /* labels for dmic mux inputs */
1155 static const char *stac92xx_dmic_labels[5] = {
1156 "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
1157 "Digital Mic 3", "Digital Mic 4"
1160 /* create playback/capture controls for input pins on dmic capable codecs */
1161 static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
1162 const struct auto_pin_cfg *cfg)
1164 struct sigmatel_spec *spec = codec->spec;
1165 struct hda_input_mux *dimux = &spec->private_dimux;
1166 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
1169 dimux->items[dimux->num_items].label = stac92xx_dmic_labels[0];
1170 dimux->items[dimux->num_items].index = 0;
1173 for (i = 0; i < spec->num_dmics; i++) {
1176 unsigned int def_conf;
1178 def_conf = snd_hda_codec_read(codec,
1181 AC_VERB_GET_CONFIG_DEFAULT,
1183 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
1186 num_cons = snd_hda_get_connections(codec,
1189 HDA_MAX_NUM_INPUTS);
1190 for (j = 0; j < num_cons; j++)
1191 if (con_lst[j] == spec->dmic_nids[i]) {
1197 dimux->items[dimux->num_items].label =
1198 stac92xx_dmic_labels[dimux->num_items];
1199 dimux->items[dimux->num_items].index = index;
1206 /* create playback/capture controls for input pins */
1207 static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
1209 struct sigmatel_spec *spec = codec->spec;
1210 struct hda_input_mux *imux = &spec->private_imux;
1211 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
1214 for (i = 0; i < AUTO_PIN_LAST; i++) {
1217 if (!cfg->input_pins[i])
1220 for (j = 0; j < spec->num_muxes; j++) {
1222 num_cons = snd_hda_get_connections(codec,
1225 HDA_MAX_NUM_INPUTS);
1226 for (k = 0; k < num_cons; k++)
1227 if (con_lst[k] == cfg->input_pins[i]) {
1234 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
1235 imux->items[imux->num_items].index = index;
1239 if (imux->num_items == 1) {
1241 * Set the current input for the muxes.
1242 * The STAC9221 has two input muxes with identical source
1243 * NID lists. Hopefully this won't get confused.
1245 for (i = 0; i < spec->num_muxes; i++) {
1246 snd_hda_codec_write(codec, spec->mux_nids[i], 0,
1247 AC_VERB_SET_CONNECT_SEL,
1248 imux->items[0].index);
1255 static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
1257 struct sigmatel_spec *spec = codec->spec;
1260 for (i = 0; i < spec->autocfg.line_outs; i++) {
1261 hda_nid_t nid = spec->autocfg.line_out_pins[i];
1262 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
1266 static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
1268 struct sigmatel_spec *spec = codec->spec;
1271 for (i = 0; i < spec->autocfg.hp_outs; i++) {
1273 pin = spec->autocfg.hp_pins[i];
1274 if (pin) /* connect to front */
1275 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
1277 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
1279 pin = spec->autocfg.speaker_pins[i];
1280 if (pin) /* connect to front */
1281 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
1285 static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out, hda_nid_t dig_in)
1287 struct sigmatel_spec *spec = codec->spec;
1290 if ((err = snd_hda_parse_pin_def_config(codec,
1292 spec->dmic_nids)) < 0)
1294 if (! spec->autocfg.line_outs)
1295 return 0; /* can't find valid pin config */
1297 if ((err = stac92xx_add_dyn_out_pins(codec, &spec->autocfg)) < 0)
1299 if (spec->multiout.num_dacs == 0)
1300 if ((err = stac92xx_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
1303 if ((err = stac92xx_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
1304 (err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg)) < 0 ||
1305 (err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
1308 if (spec->num_dmics > 0)
1309 if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
1310 &spec->autocfg)) < 0)
1313 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
1314 if (spec->multiout.max_channels > 2)
1315 spec->surr_switch = 1;
1317 if (spec->autocfg.dig_out_pin)
1318 spec->multiout.dig_out_nid = dig_out;
1319 if (spec->autocfg.dig_in_pin)
1320 spec->dig_in_nid = dig_in;
1322 if (spec->kctl_alloc)
1323 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
1325 spec->input_mux = &spec->private_imux;
1326 spec->dinput_mux = &spec->private_dimux;
1331 /* add playback controls for HP output */
1332 static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
1333 struct auto_pin_cfg *cfg)
1335 struct sigmatel_spec *spec = codec->spec;
1336 hda_nid_t pin = cfg->hp_pins[0];
1337 unsigned int wid_caps;
1342 wid_caps = get_wcaps(codec, pin);
1343 if (wid_caps & AC_WCAP_UNSOL_CAP)
1344 spec->hp_detect = 1;
1349 /* add playback controls for LFE output */
1350 static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
1351 struct auto_pin_cfg *cfg)
1353 struct sigmatel_spec *spec = codec->spec;
1355 hda_nid_t lfe_pin = 0x0;
1359 * search speaker outs and line outs for a mono speaker pin
1360 * with an amp. If one is found, add LFE controls
1363 for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
1364 hda_nid_t pin = spec->autocfg.speaker_pins[i];
1365 unsigned long wcaps = get_wcaps(codec, pin);
1366 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
1367 if (wcaps == AC_WCAP_OUT_AMP)
1368 /* found a mono speaker with an amp, must be lfe */
1372 /* if speaker_outs is 0, then speakers may be in line_outs */
1373 if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
1374 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
1375 hda_nid_t pin = spec->autocfg.line_out_pins[i];
1377 cfg = snd_hda_codec_read(codec, pin, 0,
1378 AC_VERB_GET_CONFIG_DEFAULT,
1380 if (get_defcfg_device(cfg) == AC_JACK_SPEAKER) {
1381 unsigned long wcaps = get_wcaps(codec, pin);
1382 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
1383 if (wcaps == AC_WCAP_OUT_AMP)
1384 /* found a mono speaker with an amp,
1392 err = create_controls(spec, "LFE", lfe_pin, 1);
1400 static int stac9200_parse_auto_config(struct hda_codec *codec)
1402 struct sigmatel_spec *spec = codec->spec;
1405 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
1408 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
1411 if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
1414 if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
1417 if (spec->autocfg.dig_out_pin)
1418 spec->multiout.dig_out_nid = 0x05;
1419 if (spec->autocfg.dig_in_pin)
1420 spec->dig_in_nid = 0x04;
1422 if (spec->kctl_alloc)
1423 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
1425 spec->input_mux = &spec->private_imux;
1426 spec->dinput_mux = &spec->private_dimux;
1432 * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
1433 * funky external mute control using GPIO pins.
1436 static void stac922x_gpio_mute(struct hda_codec *codec, int pin, int muted)
1438 unsigned int gpiostate, gpiomask, gpiodir;
1440 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
1441 AC_VERB_GET_GPIO_DATA, 0);
1444 gpiostate |= (1 << pin);
1446 gpiostate &= ~(1 << pin);
1448 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
1449 AC_VERB_GET_GPIO_MASK, 0);
1450 gpiomask |= (1 << pin);
1452 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
1453 AC_VERB_GET_GPIO_DIRECTION, 0);
1454 gpiodir |= (1 << pin);
1456 /* AppleHDA seems to do this -- WTF is this verb?? */
1457 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
1459 snd_hda_codec_write(codec, codec->afg, 0,
1460 AC_VERB_SET_GPIO_MASK, gpiomask);
1461 snd_hda_codec_write(codec, codec->afg, 0,
1462 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
1466 snd_hda_codec_write(codec, codec->afg, 0,
1467 AC_VERB_SET_GPIO_DATA, gpiostate);
1470 static void enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
1473 if (get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP)
1474 snd_hda_codec_write(codec, nid, 0,
1475 AC_VERB_SET_UNSOLICITED_ENABLE,
1476 (AC_USRSP_EN | event));
1479 static int stac92xx_init(struct hda_codec *codec)
1481 struct sigmatel_spec *spec = codec->spec;
1482 struct auto_pin_cfg *cfg = &spec->autocfg;
1485 snd_hda_sequence_write(codec, spec->init);
1488 if (spec->hp_detect) {
1489 /* Enable unsolicited responses on the HP widget */
1490 for (i = 0; i < cfg->hp_outs; i++)
1491 enable_pin_detect(codec, cfg->hp_pins[i],
1493 stac92xx_auto_init_hp_out(codec);
1494 /* fake event to set up pins */
1495 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
1497 stac92xx_auto_init_multi_out(codec);
1498 stac92xx_auto_init_hp_out(codec);
1500 for (i = 0; i < AUTO_PIN_LAST; i++) {
1501 hda_nid_t nid = cfg->input_pins[i];
1503 unsigned int pinctl = AC_PINCTL_IN_EN;
1504 if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC)
1505 pinctl |= stac92xx_get_vref(codec, nid);
1506 stac92xx_auto_set_pinctl(codec, nid, pinctl);
1509 if (spec->num_dmics > 0)
1510 for (i = 0; i < spec->num_dmics; i++)
1511 stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
1514 if (cfg->dig_out_pin)
1515 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pin,
1517 if (cfg->dig_in_pin)
1518 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
1521 if (spec->gpio_mute) {
1522 stac922x_gpio_mute(codec, 0, 0);
1523 stac922x_gpio_mute(codec, 1, 0);
1529 static void stac92xx_free(struct hda_codec *codec)
1531 struct sigmatel_spec *spec = codec->spec;
1537 if (spec->kctl_alloc) {
1538 for (i = 0; i < spec->num_kctl_used; i++)
1539 kfree(spec->kctl_alloc[i].name);
1540 kfree(spec->kctl_alloc);
1543 if (spec->bios_pin_configs)
1544 kfree(spec->bios_pin_configs);
1549 static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
1552 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
1553 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
1554 if (flag == AC_PINCTL_OUT_EN && (pin_ctl & AC_PINCTL_IN_EN))
1556 snd_hda_codec_write(codec, nid, 0,
1557 AC_VERB_SET_PIN_WIDGET_CONTROL,
1561 static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
1564 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
1565 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
1566 snd_hda_codec_write(codec, nid, 0,
1567 AC_VERB_SET_PIN_WIDGET_CONTROL,
1571 static int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
1575 if (snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PIN_SENSE, 0x00)
1581 static void stac92xx_hp_detect(struct hda_codec *codec, unsigned int res)
1583 struct sigmatel_spec *spec = codec->spec;
1584 struct auto_pin_cfg *cfg = &spec->autocfg;
1588 for (i = 0; i < cfg->hp_outs; i++) {
1589 presence = get_pin_presence(codec, cfg->hp_pins[i]);
1595 /* disable lineouts, enable hp */
1596 for (i = 0; i < cfg->line_outs; i++)
1597 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
1599 for (i = 0; i < cfg->speaker_outs; i++)
1600 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
1603 /* enable lineouts, disable hp */
1604 for (i = 0; i < cfg->line_outs; i++)
1605 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
1607 for (i = 0; i < cfg->speaker_outs; i++)
1608 stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
1613 static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
1615 switch (res >> 26) {
1617 stac92xx_hp_detect(codec, res);
1623 static int stac92xx_resume(struct hda_codec *codec)
1625 struct sigmatel_spec *spec = codec->spec;
1628 stac92xx_init(codec);
1629 stac92xx_set_config_regs(codec);
1630 for (i = 0; i < spec->num_mixers; i++)
1631 snd_hda_resume_ctls(codec, spec->mixers[i]);
1632 if (spec->multiout.dig_out_nid)
1633 snd_hda_resume_spdif_out(codec);
1634 if (spec->dig_in_nid)
1635 snd_hda_resume_spdif_in(codec);
1641 static struct hda_codec_ops stac92xx_patch_ops = {
1642 .build_controls = stac92xx_build_controls,
1643 .build_pcms = stac92xx_build_pcms,
1644 .init = stac92xx_init,
1645 .free = stac92xx_free,
1646 .unsol_event = stac92xx_unsol_event,
1648 .resume = stac92xx_resume,
1652 static int patch_stac9200(struct hda_codec *codec)
1654 struct sigmatel_spec *spec;
1657 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1663 spec->pin_nids = stac9200_pin_nids;
1664 spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS,
1667 if (spec->board_config < 0) {
1668 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9200, using BIOS defaults\n");
1669 err = stac92xx_save_bios_config_regs(codec);
1671 stac92xx_free(codec);
1674 spec->pin_configs = spec->bios_pin_configs;
1676 spec->pin_configs = stac9200_brd_tbl[spec->board_config];
1677 stac92xx_set_config_regs(codec);
1680 spec->multiout.max_channels = 2;
1681 spec->multiout.num_dacs = 1;
1682 spec->multiout.dac_nids = stac9200_dac_nids;
1683 spec->adc_nids = stac9200_adc_nids;
1684 spec->mux_nids = stac9200_mux_nids;
1685 spec->num_muxes = 1;
1686 spec->num_dmics = 0;
1688 spec->init = stac9200_core_init;
1689 spec->mixer = stac9200_mixer;
1691 err = stac9200_parse_auto_config(codec);
1693 stac92xx_free(codec);
1697 codec->patch_ops = stac92xx_patch_ops;
1702 static int patch_stac922x(struct hda_codec *codec)
1704 struct sigmatel_spec *spec;
1707 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1712 spec->num_pins = 10;
1713 spec->pin_nids = stac922x_pin_nids;
1714 spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS,
1717 if (spec->board_config < 0) {
1718 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC922x, "
1719 "using BIOS defaults\n");
1720 err = stac92xx_save_bios_config_regs(codec);
1722 stac92xx_free(codec);
1725 spec->pin_configs = spec->bios_pin_configs;
1726 } else if (stac922x_brd_tbl[spec->board_config] != NULL) {
1727 spec->pin_configs = stac922x_brd_tbl[spec->board_config];
1728 stac92xx_set_config_regs(codec);
1731 spec->adc_nids = stac922x_adc_nids;
1732 spec->mux_nids = stac922x_mux_nids;
1733 spec->num_muxes = 2;
1734 spec->num_dmics = 0;
1736 spec->init = stac922x_core_init;
1737 spec->mixer = stac922x_mixer;
1739 spec->multiout.dac_nids = spec->dac_nids;
1741 err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
1743 stac92xx_free(codec);
1747 if (spec->board_config == STAC_MACMINI)
1748 spec->gpio_mute = 1;
1750 codec->patch_ops = stac92xx_patch_ops;
1755 static int patch_stac927x(struct hda_codec *codec)
1757 struct sigmatel_spec *spec;
1760 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1765 spec->num_pins = 14;
1766 spec->pin_nids = stac927x_pin_nids;
1767 spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS,
1770 if (spec->board_config < 0) {
1771 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC927x, using BIOS defaults\n");
1772 err = stac92xx_save_bios_config_regs(codec);
1774 stac92xx_free(codec);
1777 spec->pin_configs = spec->bios_pin_configs;
1778 } else if (stac927x_brd_tbl[spec->board_config] != NULL) {
1779 spec->pin_configs = stac927x_brd_tbl[spec->board_config];
1780 stac92xx_set_config_regs(codec);
1783 switch (spec->board_config) {
1785 spec->adc_nids = stac927x_adc_nids;
1786 spec->mux_nids = stac927x_mux_nids;
1787 spec->num_muxes = 3;
1788 spec->num_dmics = 0;
1789 spec->init = d965_core_init;
1790 spec->mixer = stac9227_mixer;
1793 spec->adc_nids = stac927x_adc_nids;
1794 spec->mux_nids = stac927x_mux_nids;
1795 spec->num_muxes = 3;
1796 spec->num_dmics = 0;
1797 spec->init = d965_core_init;
1798 spec->mixer = stac9227_mixer;
1801 spec->adc_nids = stac927x_adc_nids;
1802 spec->mux_nids = stac927x_mux_nids;
1803 spec->num_muxes = 3;
1804 spec->num_dmics = 0;
1805 spec->init = stac927x_core_init;
1806 spec->mixer = stac927x_mixer;
1809 spec->multiout.dac_nids = spec->dac_nids;
1811 err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
1813 stac92xx_free(codec);
1817 codec->patch_ops = stac92xx_patch_ops;
1822 static int patch_stac9205(struct hda_codec *codec)
1824 struct sigmatel_spec *spec;
1827 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1832 spec->num_pins = 14;
1833 spec->pin_nids = stac9205_pin_nids;
1834 spec->board_config = snd_hda_check_board_config(codec, STAC_9205_MODELS,
1837 if (spec->board_config < 0) {
1838 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9205, using BIOS defaults\n");
1839 err = stac92xx_save_bios_config_regs(codec);
1841 stac92xx_free(codec);
1844 spec->pin_configs = spec->bios_pin_configs;
1846 spec->pin_configs = stac9205_brd_tbl[spec->board_config];
1847 stac92xx_set_config_regs(codec);
1850 spec->adc_nids = stac9205_adc_nids;
1851 spec->mux_nids = stac9205_mux_nids;
1852 spec->num_muxes = 2;
1853 spec->dmic_nids = stac9205_dmic_nids;
1854 spec->num_dmics = 2;
1855 spec->dmux_nid = 0x1d;
1857 spec->init = stac9205_core_init;
1858 spec->mixer = stac9205_mixer;
1860 spec->multiout.dac_nids = spec->dac_nids;
1862 err = stac92xx_parse_auto_config(codec, 0x1f, 0x20);
1864 stac92xx_free(codec);
1868 codec->patch_ops = stac92xx_patch_ops;
1877 /* static config for Sony VAIO FE550G and Sony VAIO AR */
1878 static hda_nid_t vaio_dacs[] = { 0x2 };
1879 #define VAIO_HP_DAC 0x5
1880 static hda_nid_t vaio_adcs[] = { 0x8 /*,0x6*/ };
1881 static hda_nid_t vaio_mux_nids[] = { 0x15 };
1883 static struct hda_input_mux vaio_mux = {
1886 /* { "HP", 0x0 }, */
1893 static struct hda_verb vaio_init[] = {
1894 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
1895 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
1896 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
1897 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
1898 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
1899 {0x15, AC_VERB_SET_CONNECT_SEL, 0x2}, /* mic-sel: 0a,0d,14,02 */
1900 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
1901 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
1902 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
1903 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
1904 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
1908 static struct hda_verb vaio_ar_init[] = {
1909 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
1910 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
1911 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
1912 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
1913 /* {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },*/ /* Optical Out */
1914 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
1915 {0x15, AC_VERB_SET_CONNECT_SEL, 0x2}, /* mic-sel: 0a,0d,14,02 */
1916 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
1917 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
1918 /* {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},*/ /* Optical Out */
1919 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
1920 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
1921 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
1925 /* bind volumes of both NID 0x02 and 0x05 */
1926 static int vaio_master_vol_put(struct snd_kcontrol *kcontrol,
1927 struct snd_ctl_elem_value *ucontrol)
1929 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1930 long *valp = ucontrol->value.integer.value;
1933 change = snd_hda_codec_amp_update(codec, 0x02, 0, HDA_OUTPUT, 0,
1934 0x7f, valp[0] & 0x7f);
1935 change |= snd_hda_codec_amp_update(codec, 0x02, 1, HDA_OUTPUT, 0,
1936 0x7f, valp[1] & 0x7f);
1937 snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
1938 0x7f, valp[0] & 0x7f);
1939 snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
1940 0x7f, valp[1] & 0x7f);
1944 /* bind volumes of both NID 0x02 and 0x05 */
1945 static int vaio_master_sw_put(struct snd_kcontrol *kcontrol,
1946 struct snd_ctl_elem_value *ucontrol)
1948 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1949 long *valp = ucontrol->value.integer.value;
1952 change = snd_hda_codec_amp_update(codec, 0x02, 0, HDA_OUTPUT, 0,
1953 0x80, (valp[0] ? 0 : 0x80));
1954 change |= snd_hda_codec_amp_update(codec, 0x02, 1, HDA_OUTPUT, 0,
1955 0x80, (valp[1] ? 0 : 0x80));
1956 snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
1957 0x80, (valp[0] ? 0 : 0x80));
1958 snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
1959 0x80, (valp[1] ? 0 : 0x80));
1963 static struct snd_kcontrol_new vaio_mixer[] = {
1965 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1966 .name = "Master Playback Volume",
1967 .info = snd_hda_mixer_amp_volume_info,
1968 .get = snd_hda_mixer_amp_volume_get,
1969 .put = vaio_master_vol_put,
1970 .tlv = { .c = snd_hda_mixer_amp_tlv },
1971 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
1974 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1975 .name = "Master Playback Switch",
1976 .info = snd_hda_mixer_amp_switch_info,
1977 .get = snd_hda_mixer_amp_switch_get,
1978 .put = vaio_master_sw_put,
1979 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
1981 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
1982 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
1983 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
1985 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1986 .name = "Capture Source",
1988 .info = stac92xx_mux_enum_info,
1989 .get = stac92xx_mux_enum_get,
1990 .put = stac92xx_mux_enum_put,
1995 static struct snd_kcontrol_new vaio_ar_mixer[] = {
1997 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1998 .name = "Master Playback Volume",
1999 .info = snd_hda_mixer_amp_volume_info,
2000 .get = snd_hda_mixer_amp_volume_get,
2001 .put = vaio_master_vol_put,
2002 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2005 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2006 .name = "Master Playback Switch",
2007 .info = snd_hda_mixer_amp_switch_info,
2008 .get = snd_hda_mixer_amp_switch_get,
2009 .put = vaio_master_sw_put,
2010 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2012 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
2013 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
2014 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
2015 /*HDA_CODEC_MUTE("Optical Out Switch", 0x10, 0, HDA_OUTPUT),
2016 HDA_CODEC_VOLUME("Optical Out Volume", 0x10, 0, HDA_OUTPUT),*/
2018 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2019 .name = "Capture Source",
2021 .info = stac92xx_mux_enum_info,
2022 .get = stac92xx_mux_enum_get,
2023 .put = stac92xx_mux_enum_put,
2028 static struct hda_codec_ops stac9872_patch_ops = {
2029 .build_controls = stac92xx_build_controls,
2030 .build_pcms = stac92xx_build_pcms,
2031 .init = stac92xx_init,
2032 .free = stac92xx_free,
2034 .resume = stac92xx_resume,
2038 enum { /* FE and SZ series. id=0x83847661 and subsys=0x104D0700 or 104D1000. */
2040 /* Unknown. id=0x83847662 and subsys=0x104D1200 or 104D1000. */
2042 /* Unknown. id=0x83847661 and subsys=0x104D1200. */
2044 /* AR Series. id=0x83847664 and subsys=104D1300 */
2049 static const char *stac9872_models[STAC_9872_MODELS] = {
2050 [CXD9872RD_VAIO] = "vaio",
2051 [CXD9872AKD_VAIO] = "vaio-ar",
2054 static struct snd_pci_quirk stac9872_cfg_tbl[] = {
2055 SND_PCI_QUIRK(0x104d, 0x81e6, "Sony VAIO F/S", CXD9872RD_VAIO),
2056 SND_PCI_QUIRK(0x104d, 0x81ef, "Sony VAIO F/S", CXD9872RD_VAIO),
2057 SND_PCI_QUIRK(0x104d, 0x81fd, "Sony VAIO AR", CXD9872AKD_VAIO),
2061 static int patch_stac9872(struct hda_codec *codec)
2063 struct sigmatel_spec *spec;
2066 board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
2069 if (board_config < 0)
2070 /* unknown config, let generic-parser do its job... */
2071 return snd_hda_parse_generic_codec(codec);
2073 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2078 switch (board_config) {
2079 case CXD9872RD_VAIO:
2080 case STAC9872AK_VAIO:
2081 case STAC9872K_VAIO:
2082 spec->mixer = vaio_mixer;
2083 spec->init = vaio_init;
2084 spec->multiout.max_channels = 2;
2085 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
2086 spec->multiout.dac_nids = vaio_dacs;
2087 spec->multiout.hp_nid = VAIO_HP_DAC;
2088 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
2089 spec->adc_nids = vaio_adcs;
2090 spec->input_mux = &vaio_mux;
2091 spec->mux_nids = vaio_mux_nids;
2094 case CXD9872AKD_VAIO:
2095 spec->mixer = vaio_ar_mixer;
2096 spec->init = vaio_ar_init;
2097 spec->multiout.max_channels = 2;
2098 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
2099 spec->multiout.dac_nids = vaio_dacs;
2100 spec->multiout.hp_nid = VAIO_HP_DAC;
2101 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
2102 spec->adc_nids = vaio_adcs;
2103 spec->input_mux = &vaio_mux;
2104 spec->mux_nids = vaio_mux_nids;
2108 codec->patch_ops = stac9872_patch_ops;
2116 struct hda_codec_preset snd_hda_preset_sigmatel[] = {
2117 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
2118 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
2119 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
2120 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
2121 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
2122 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
2123 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
2124 { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
2125 { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
2126 { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
2127 { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
2128 { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
2129 { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
2130 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
2131 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
2132 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
2133 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
2134 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
2135 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
2136 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
2137 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
2138 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
2139 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
2140 /* The following does not take into account .id=0x83847661 when subsys =
2141 * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
2142 * currently not fully supported.
2144 { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
2145 { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
2146 { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
2147 { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
2148 { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
2149 { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
2150 { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
2151 { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
2152 { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
2153 { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
2154 { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },