allow coexistance of N build and AC build.
[tomato.git] / release / src-rt-6.x / linux / linux-2.6 / sound / pci / hda / patch_sigmatel.c
blobd5b2f53644d87c59322d33dc13a7efcc6170a237
1 /*
2 * Universal Interface for Intel High Definition Audio Codec
4 * HD audio interface patch for SigmaTel STAC92xx
6 * Copyright (c) 2005 Embedded Alley Solutions, Inc.
7 * Matt Porter <mporter@embeddedalley.com>
9 * Based on patch_cmedia.c and patch_realtek.c
10 * Copyright (c) 2004 Takashi Iwai <tiwai@suse.de>
12 * This driver is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This driver is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #include <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
40 enum {
41 STAC_REF,
42 STAC_9200_MODELS
45 enum {
46 STAC_9205_REF,
47 STAC_9205_MODELS
50 enum {
51 STAC_925x_REF,
52 STAC_M2_2,
53 STAC_MA6,
54 STAC_PA6,
55 STAC_925x_MODELS
58 enum {
59 STAC_D945_REF,
60 STAC_D945GTP3,
61 STAC_D945GTP5,
62 STAC_MACMINI,
63 STAC_MACBOOK,
64 STAC_MACBOOK_PRO_V1,
65 STAC_MACBOOK_PRO_V2,
66 STAC_IMAC_INTEL,
67 STAC_922X_MODELS
70 enum {
71 STAC_D965_REF,
72 STAC_D965_3ST,
73 STAC_D965_5ST,
74 STAC_927X_MODELS
77 struct sigmatel_spec {
78 struct snd_kcontrol_new *mixers[4];
79 unsigned int num_mixers;
81 int board_config;
82 unsigned int surr_switch: 1;
83 unsigned int line_switch: 1;
84 unsigned int mic_switch: 1;
85 unsigned int alt_switch: 1;
86 unsigned int hp_detect: 1;
87 unsigned int gpio_mute: 1;
89 /* playback */
90 struct hda_multi_out multiout;
91 hda_nid_t dac_nids[5];
93 /* capture */
94 hda_nid_t *adc_nids;
95 unsigned int num_adcs;
96 hda_nid_t *mux_nids;
97 unsigned int num_muxes;
98 hda_nid_t *dmic_nids;
99 unsigned int num_dmics;
100 hda_nid_t dmux_nid;
101 hda_nid_t dig_in_nid;
103 /* pin widgets */
104 hda_nid_t *pin_nids;
105 unsigned int num_pins;
106 unsigned int *pin_configs;
107 unsigned int *bios_pin_configs;
109 /* codec specific stuff */
110 struct hda_verb *init;
111 struct snd_kcontrol_new *mixer;
113 /* capture source */
114 struct hda_input_mux *dinput_mux;
115 unsigned int cur_dmux;
116 struct hda_input_mux *input_mux;
117 unsigned int cur_mux[3];
119 /* i/o switches */
120 unsigned int io_switch[2];
122 struct hda_pcm pcm_rec[2]; /* PCM information */
124 /* dynamic controls and input_mux */
125 struct auto_pin_cfg autocfg;
126 unsigned int num_kctl_alloc, num_kctl_used;
127 struct snd_kcontrol_new *kctl_alloc;
128 struct hda_input_mux private_dimux;
129 struct hda_input_mux private_imux;
132 static hda_nid_t stac9200_adc_nids[1] = {
133 0x03,
136 static hda_nid_t stac9200_mux_nids[1] = {
137 0x0c,
140 static hda_nid_t stac9200_dac_nids[1] = {
141 0x02,
144 static hda_nid_t stac925x_adc_nids[1] = {
145 0x03,
148 static hda_nid_t stac925x_mux_nids[1] = {
149 0x0f,
152 static hda_nid_t stac925x_dac_nids[1] = {
153 0x02,
156 #define STAC925X_NUM_DMICS 1
157 static hda_nid_t stac925x_dmic_nids[STAC925X_NUM_DMICS + 1] = {
158 0x15, 0
161 static hda_nid_t stac922x_adc_nids[2] = {
162 0x06, 0x07,
165 static hda_nid_t stac922x_mux_nids[2] = {
166 0x12, 0x13,
169 static hda_nid_t stac927x_adc_nids[3] = {
170 0x07, 0x08, 0x09
173 static hda_nid_t stac927x_mux_nids[3] = {
174 0x15, 0x16, 0x17
177 static hda_nid_t stac9205_adc_nids[2] = {
178 0x12, 0x13
181 static hda_nid_t stac9205_mux_nids[2] = {
182 0x19, 0x1a
185 #define STAC9205_NUM_DMICS 2
186 static hda_nid_t stac9205_dmic_nids[STAC9205_NUM_DMICS + 1] = {
187 0x17, 0x18, 0
190 static hda_nid_t stac9200_pin_nids[8] = {
191 0x08, 0x09, 0x0d, 0x0e,
192 0x0f, 0x10, 0x11, 0x12,
195 static hda_nid_t stac925x_pin_nids[8] = {
196 0x07, 0x08, 0x0a, 0x0b,
197 0x0c, 0x0d, 0x10, 0x11,
200 static hda_nid_t stac922x_pin_nids[10] = {
201 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
202 0x0f, 0x10, 0x11, 0x15, 0x1b,
205 static hda_nid_t stac927x_pin_nids[14] = {
206 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
207 0x0f, 0x10, 0x11, 0x12, 0x13,
208 0x14, 0x21, 0x22, 0x23,
211 static hda_nid_t stac9205_pin_nids[12] = {
212 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
213 0x0f, 0x14, 0x16, 0x17, 0x18,
214 0x21, 0x22,
218 static int stac92xx_dmux_enum_info(struct snd_kcontrol *kcontrol,
219 struct snd_ctl_elem_info *uinfo)
221 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
222 struct sigmatel_spec *spec = codec->spec;
223 return snd_hda_input_mux_info(spec->dinput_mux, uinfo);
226 static int stac92xx_dmux_enum_get(struct snd_kcontrol *kcontrol,
227 struct snd_ctl_elem_value *ucontrol)
229 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
230 struct sigmatel_spec *spec = codec->spec;
232 ucontrol->value.enumerated.item[0] = spec->cur_dmux;
233 return 0;
236 static int stac92xx_dmux_enum_put(struct snd_kcontrol *kcontrol,
237 struct snd_ctl_elem_value *ucontrol)
239 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
240 struct sigmatel_spec *spec = codec->spec;
242 return snd_hda_input_mux_put(codec, spec->dinput_mux, ucontrol,
243 spec->dmux_nid, &spec->cur_dmux);
246 static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
248 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
249 struct sigmatel_spec *spec = codec->spec;
250 return snd_hda_input_mux_info(spec->input_mux, uinfo);
253 static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
255 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
256 struct sigmatel_spec *spec = codec->spec;
257 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
259 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
260 return 0;
263 static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
265 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
266 struct sigmatel_spec *spec = codec->spec;
267 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
269 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
270 spec->mux_nids[adc_idx], &spec->cur_mux[adc_idx]);
273 static struct hda_verb stac9200_core_init[] = {
274 /* set dac0mux for dac converter */
275 { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
279 static struct hda_verb stac925x_core_init[] = {
280 /* set dac0mux for dac converter */
281 { 0x06, AC_VERB_SET_CONNECT_SEL, 0x00},
285 static struct hda_verb stac922x_core_init[] = {
286 /* set master volume and direct control */
287 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
291 static struct hda_verb d965_core_init[] = {
292 /* set master volume and direct control */
293 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
294 /* unmute node 0x1b */
295 { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
296 /* select node 0x03 as DAC */
297 { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
301 static struct hda_verb stac927x_core_init[] = {
302 /* set master volume and direct control */
303 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
307 static struct hda_verb stac9205_core_init[] = {
308 /* set master volume and direct control */
309 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
313 static struct snd_kcontrol_new stac9200_mixer[] = {
314 HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
315 HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
317 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
318 .name = "Input Source",
319 .count = 1,
320 .info = stac92xx_mux_enum_info,
321 .get = stac92xx_mux_enum_get,
322 .put = stac92xx_mux_enum_put,
324 HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
325 HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
326 HDA_CODEC_VOLUME("Capture Mux Volume", 0x0c, 0, HDA_OUTPUT),
327 { } /* end */
330 static struct snd_kcontrol_new stac925x_mixer[] = {
331 HDA_CODEC_VOLUME("Master Playback Volume", 0xe, 0, HDA_OUTPUT),
332 HDA_CODEC_MUTE("Master Playback Switch", 0xe, 0, HDA_OUTPUT),
334 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
335 .name = "Input Source",
336 .count = 1,
337 .info = stac92xx_mux_enum_info,
338 .get = stac92xx_mux_enum_get,
339 .put = stac92xx_mux_enum_put,
341 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_OUTPUT),
342 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_OUTPUT),
343 HDA_CODEC_VOLUME("Capture Mux Volume", 0x0f, 0, HDA_OUTPUT),
344 { } /* end */
347 /* This needs to be generated dynamically based on sequence */
348 static struct snd_kcontrol_new stac922x_mixer[] = {
350 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
351 .name = "Input Source",
352 .count = 1,
353 .info = stac92xx_mux_enum_info,
354 .get = stac92xx_mux_enum_get,
355 .put = stac92xx_mux_enum_put,
357 HDA_CODEC_VOLUME("Capture Volume", 0x17, 0x0, HDA_INPUT),
358 HDA_CODEC_MUTE("Capture Switch", 0x17, 0x0, HDA_INPUT),
359 HDA_CODEC_VOLUME("Mux Capture Volume", 0x12, 0x0, HDA_OUTPUT),
360 { } /* end */
363 /* This needs to be generated dynamically based on sequence */
364 static struct snd_kcontrol_new stac9227_mixer[] = {
366 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
367 .name = "Input Source",
368 .count = 1,
369 .info = stac92xx_mux_enum_info,
370 .get = stac92xx_mux_enum_get,
371 .put = stac92xx_mux_enum_put,
373 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
374 HDA_CODEC_MUTE("Capture Switch", 0x1b, 0x0, HDA_OUTPUT),
375 { } /* end */
378 static struct snd_kcontrol_new stac927x_mixer[] = {
380 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
381 .name = "Input Source",
382 .count = 1,
383 .info = stac92xx_mux_enum_info,
384 .get = stac92xx_mux_enum_get,
385 .put = stac92xx_mux_enum_put,
387 HDA_CODEC_VOLUME("InMux Capture Volume", 0x15, 0x0, HDA_OUTPUT),
388 HDA_CODEC_VOLUME("InVol Capture Volume", 0x18, 0x0, HDA_INPUT),
389 HDA_CODEC_MUTE("ADCMux Capture Switch", 0x1b, 0x0, HDA_OUTPUT),
390 { } /* end */
393 static struct snd_kcontrol_new stac9205_mixer[] = {
395 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
396 .name = "Digital Input Source",
397 .count = 1,
398 .info = stac92xx_dmux_enum_info,
399 .get = stac92xx_dmux_enum_get,
400 .put = stac92xx_dmux_enum_put,
403 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
404 .name = "Input Source",
405 .count = 1,
406 .info = stac92xx_mux_enum_info,
407 .get = stac92xx_mux_enum_get,
408 .put = stac92xx_mux_enum_put,
410 HDA_CODEC_VOLUME("InMux Capture Volume", 0x19, 0x0, HDA_OUTPUT),
411 HDA_CODEC_VOLUME("InVol Capture Volume", 0x1b, 0x0, HDA_INPUT),
412 HDA_CODEC_MUTE("ADCMux Capture Switch", 0x1d, 0x0, HDA_OUTPUT),
413 { } /* end */
416 static int stac92xx_build_controls(struct hda_codec *codec)
418 struct sigmatel_spec *spec = codec->spec;
419 int err;
420 int i;
422 err = snd_hda_add_new_ctls(codec, spec->mixer);
423 if (err < 0)
424 return err;
426 for (i = 0; i < spec->num_mixers; i++) {
427 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
428 if (err < 0)
429 return err;
432 if (spec->multiout.dig_out_nid) {
433 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
434 if (err < 0)
435 return err;
437 if (spec->dig_in_nid) {
438 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
439 if (err < 0)
440 return err;
442 return 0;
445 static unsigned int ref9200_pin_configs[8] = {
446 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
447 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
450 static unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
451 [STAC_REF] = ref9200_pin_configs,
454 static const char *stac9200_models[STAC_9200_MODELS] = {
455 [STAC_REF] = "ref",
458 static struct snd_pci_quirk stac9200_cfg_tbl[] = {
459 /* SigmaTel reference board */
460 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
461 "DFI LanParty", STAC_REF),
462 /* Dell laptops have BIOS problem */
463 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01b5,
464 "Dell Inspiron 630m", STAC_REF),
465 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c2,
466 "Dell Latitude D620", STAC_REF),
467 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cb,
468 "Dell Latitude 120L", STAC_REF),
469 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cc,
470 "Dell Latitude D820", STAC_REF),
471 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cd,
472 "Dell Inspiron E1705/9400", STAC_REF),
473 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ce,
474 "Dell XPS M1710", STAC_REF),
475 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cf,
476 "Dell Precision M90", STAC_REF),
477 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d6,
478 "unknown Dell", STAC_REF),
479 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d8,
480 "Dell Inspiron 640m", STAC_REF),
481 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f5,
482 "Dell Inspiron 1501", STAC_REF),
484 /* Panasonic */
485 SND_PCI_QUIRK(0x10f7, 0x8338, "Panasonic CF-74", STAC_REF),
487 {} /* terminator */
490 static unsigned int ref925x_pin_configs[8] = {
491 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
492 0x90a70320, 0x02214210, 0x400003f1, 0x9033032e,
495 static unsigned int stac925x_MA6_pin_configs[8] = {
496 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
497 0x90a70320, 0x90100211, 0x400003f1, 0x9033032e,
500 static unsigned int stac925x_PA6_pin_configs[8] = {
501 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
502 0x50a103f0, 0x90100211, 0x400003f1, 0x9033032e,
505 static unsigned int stac925xM2_2_pin_configs[8] = {
506 0x40c003f3, 0x424503f2, 0x04180011, 0x02a19020,
507 0x50a103f0, 0x90100212, 0x400003f1, 0x9033032e,
510 static unsigned int *stac925x_brd_tbl[STAC_925x_MODELS] = {
511 [STAC_REF] = ref925x_pin_configs,
512 [STAC_M2_2] = stac925xM2_2_pin_configs,
513 [STAC_MA6] = stac925x_MA6_pin_configs,
514 [STAC_PA6] = stac925x_PA6_pin_configs,
517 static const char *stac925x_models[STAC_925x_MODELS] = {
518 [STAC_REF] = "ref",
519 [STAC_M2_2] = "m2-2",
520 [STAC_MA6] = "m6",
521 [STAC_PA6] = "pa6",
524 static struct snd_pci_quirk stac925x_cfg_tbl[] = {
525 /* SigmaTel reference board */
526 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, "DFI LanParty", STAC_REF),
527 SND_PCI_QUIRK(0x8384, 0x7632, "Stac9202 Reference Board", STAC_REF),
528 SND_PCI_QUIRK(0x107b, 0x0316, "Gateway M255", STAC_REF),
529 SND_PCI_QUIRK(0x107b, 0x0366, "Gateway MP6954", STAC_REF),
530 SND_PCI_QUIRK(0x107b, 0x0461, "Gateway NX560XL", STAC_MA6),
531 SND_PCI_QUIRK(0x107b, 0x0681, "Gateway NX860", STAC_PA6),
532 SND_PCI_QUIRK(0x1002, 0x437b, "Gateway MX6453", STAC_M2_2),
533 {} /* terminator */
536 static unsigned int ref922x_pin_configs[10] = {
537 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
538 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
539 0x40000100, 0x40000100,
542 static unsigned int d945gtp3_pin_configs[10] = {
543 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
544 0x40000100, 0x40000100, 0x40000100, 0x40000100,
545 0x02a19120, 0x40000100,
548 static unsigned int d945gtp5_pin_configs[10] = {
549 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
550 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
551 0x02a19320, 0x40000100,
554 static unsigned int macbook_pro_v1_pin_configs[10] = {
555 0x0321e230, 0x03a1e020, 0x9017e110, 0x01014010,
556 0x01a19021, 0x0381e021, 0x1345e240, 0x13c5e22e,
557 0x02a19320, 0x400000fb
560 static unsigned int macbook_pro_v2_pin_configs[10] = {
561 0x0221401f, 0x90a70120, 0x01813024, 0x01014010,
562 0x400000fd, 0x01016011, 0x1345e240, 0x13c5e22e,
563 0x400000fc, 0x400000fb,
566 static unsigned int imac_intel_pin_configs[10] = {
567 0x0121e230, 0x90a70120, 0x9017e110, 0x400000fe,
568 0x400000fd, 0x0181e021, 0x1145e040, 0x400000fa,
569 0x400000fc, 0x400000fb,
572 static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
573 [STAC_D945_REF] = ref922x_pin_configs,
574 [STAC_D945GTP3] = d945gtp3_pin_configs,
575 [STAC_D945GTP5] = d945gtp5_pin_configs,
576 [STAC_MACMINI] = macbook_pro_v1_pin_configs,
577 [STAC_MACBOOK] = macbook_pro_v1_pin_configs,
578 [STAC_MACBOOK_PRO_V1] = macbook_pro_v1_pin_configs,
579 [STAC_MACBOOK_PRO_V2] = macbook_pro_v2_pin_configs,
580 [STAC_IMAC_INTEL] = imac_intel_pin_configs,
583 static const char *stac922x_models[STAC_922X_MODELS] = {
584 [STAC_D945_REF] = "ref",
585 [STAC_D945GTP5] = "5stack",
586 [STAC_D945GTP3] = "3stack",
587 [STAC_MACMINI] = "macmini",
588 [STAC_MACBOOK] = "macbook",
589 [STAC_MACBOOK_PRO_V1] = "macbook-pro-v1",
590 [STAC_MACBOOK_PRO_V2] = "macbook-pro",
591 [STAC_IMAC_INTEL] = "imac-intel",
594 static struct snd_pci_quirk stac922x_cfg_tbl[] = {
595 /* SigmaTel reference board */
596 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
597 "DFI LanParty", STAC_D945_REF),
598 /* Intel 945G based systems */
599 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101,
600 "Intel D945G", STAC_D945GTP3),
601 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0202,
602 "Intel D945G", STAC_D945GTP3),
603 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0606,
604 "Intel D945G", STAC_D945GTP3),
605 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0601,
606 "Intel D945G", STAC_D945GTP3),
607 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0111,
608 "Intel D945G", STAC_D945GTP3),
609 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1115,
610 "Intel D945G", STAC_D945GTP3),
611 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1116,
612 "Intel D945G", STAC_D945GTP3),
613 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1117,
614 "Intel D945G", STAC_D945GTP3),
615 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1118,
616 "Intel D945G", STAC_D945GTP3),
617 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1119,
618 "Intel D945G", STAC_D945GTP3),
619 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x8826,
620 "Intel D945G", STAC_D945GTP3),
621 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5049,
622 "Intel D945G", STAC_D945GTP3),
623 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5055,
624 "Intel D945G", STAC_D945GTP3),
625 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5048,
626 "Intel D945G", STAC_D945GTP3),
627 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0110,
628 "Intel D945G", STAC_D945GTP3),
629 /* Intel D945G 5-stack systems */
630 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0404,
631 "Intel D945G", STAC_D945GTP5),
632 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0303,
633 "Intel D945G", STAC_D945GTP5),
634 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0013,
635 "Intel D945G", STAC_D945GTP5),
636 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0417,
637 "Intel D945G", STAC_D945GTP5),
638 /* Intel 945P based systems */
639 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0b0b,
640 "Intel D945P", STAC_D945GTP3),
641 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0112,
642 "Intel D945P", STAC_D945GTP3),
643 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0d0d,
644 "Intel D945P", STAC_D945GTP3),
645 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0909,
646 "Intel D945P", STAC_D945GTP3),
647 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0505,
648 "Intel D945P", STAC_D945GTP3),
649 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707,
650 "Intel D945P", STAC_D945GTP5),
651 /* other systems */
652 /* Apple Mac Mini (early 2006) */
653 SND_PCI_QUIRK(0x8384, 0x7680,
654 "Mac Mini", STAC_MACMINI),
655 {} /* terminator */
658 static unsigned int ref927x_pin_configs[14] = {
659 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
660 0x01a19040, 0x01011012, 0x01016011, 0x0101201f,
661 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
662 0x01c42190, 0x40000100,
665 static unsigned int d965_3st_pin_configs[14] = {
666 0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
667 0x01a19021, 0x01813024, 0x40000100, 0x40000100,
668 0x40000100, 0x40000100, 0x40000100, 0x40000100,
669 0x40000100, 0x40000100
672 static unsigned int d965_5st_pin_configs[14] = {
673 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
674 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
675 0x40000100, 0x40000100, 0x40000100, 0x01442070,
676 0x40000100, 0x40000100
679 static unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
680 [STAC_D965_REF] = ref927x_pin_configs,
681 [STAC_D965_3ST] = d965_3st_pin_configs,
682 [STAC_D965_5ST] = d965_5st_pin_configs,
685 static const char *stac927x_models[STAC_927X_MODELS] = {
686 [STAC_D965_REF] = "ref",
687 [STAC_D965_3ST] = "3stack",
688 [STAC_D965_5ST] = "5stack",
691 static struct snd_pci_quirk stac927x_cfg_tbl[] = {
692 /* SigmaTel reference board */
693 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
694 "DFI LanParty", STAC_D965_REF),
695 /* Intel 946 based systems */
696 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST),
697 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST),
698 /* 965 based 3 stack systems */
699 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2116, "Intel D965", STAC_D965_3ST),
700 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2115, "Intel D965", STAC_D965_3ST),
701 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2114, "Intel D965", STAC_D965_3ST),
702 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2113, "Intel D965", STAC_D965_3ST),
703 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2112, "Intel D965", STAC_D965_3ST),
704 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2111, "Intel D965", STAC_D965_3ST),
705 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2110, "Intel D965", STAC_D965_3ST),
706 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2009, "Intel D965", STAC_D965_3ST),
707 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2008, "Intel D965", STAC_D965_3ST),
708 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2007, "Intel D965", STAC_D965_3ST),
709 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2006, "Intel D965", STAC_D965_3ST),
710 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2005, "Intel D965", STAC_D965_3ST),
711 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2004, "Intel D965", STAC_D965_3ST),
712 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2003, "Intel D965", STAC_D965_3ST),
713 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2002, "Intel D965", STAC_D965_3ST),
714 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2001, "Intel D965", STAC_D965_3ST),
715 /* 965 based 5 stack systems */
716 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2301, "Intel D965", STAC_D965_5ST),
717 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2302, "Intel D965", STAC_D965_5ST),
718 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2303, "Intel D965", STAC_D965_5ST),
719 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2304, "Intel D965", STAC_D965_5ST),
720 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2305, "Intel D965", STAC_D965_5ST),
721 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2501, "Intel D965", STAC_D965_5ST),
722 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2502, "Intel D965", STAC_D965_5ST),
723 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2503, "Intel D965", STAC_D965_5ST),
724 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2504, "Intel D965", STAC_D965_5ST),
725 {} /* terminator */
728 static unsigned int ref9205_pin_configs[12] = {
729 0x40000100, 0x40000100, 0x01016011, 0x01014010,
730 0x01813122, 0x01a19021, 0x40000100, 0x40000100,
731 0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
734 static unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
735 ref9205_pin_configs,
738 static const char *stac9205_models[STAC_9205_MODELS] = {
739 [STAC_9205_REF] = "ref",
742 static struct snd_pci_quirk stac9205_cfg_tbl[] = {
743 /* SigmaTel reference board */
744 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
745 "DFI LanParty", STAC_9205_REF),
746 {} /* terminator */
749 static int stac92xx_save_bios_config_regs(struct hda_codec *codec)
751 int i;
752 struct sigmatel_spec *spec = codec->spec;
754 if (! spec->bios_pin_configs) {
755 spec->bios_pin_configs = kcalloc(spec->num_pins,
756 sizeof(*spec->bios_pin_configs), GFP_KERNEL);
757 if (! spec->bios_pin_configs)
758 return -ENOMEM;
761 for (i = 0; i < spec->num_pins; i++) {
762 hda_nid_t nid = spec->pin_nids[i];
763 unsigned int pin_cfg;
765 pin_cfg = snd_hda_codec_read(codec, nid, 0,
766 AC_VERB_GET_CONFIG_DEFAULT, 0x00);
767 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x bios pin config %8.8x\n",
768 nid, pin_cfg);
769 spec->bios_pin_configs[i] = pin_cfg;
772 return 0;
775 static void stac92xx_set_config_regs(struct hda_codec *codec)
777 int i;
778 struct sigmatel_spec *spec = codec->spec;
779 unsigned int pin_cfg;
781 if (! spec->pin_nids || ! spec->pin_configs)
782 return;
784 for (i = 0; i < spec->num_pins; i++) {
785 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
786 AC_VERB_SET_CONFIG_DEFAULT_BYTES_0,
787 spec->pin_configs[i] & 0x000000ff);
788 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
789 AC_VERB_SET_CONFIG_DEFAULT_BYTES_1,
790 (spec->pin_configs[i] & 0x0000ff00) >> 8);
791 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
792 AC_VERB_SET_CONFIG_DEFAULT_BYTES_2,
793 (spec->pin_configs[i] & 0x00ff0000) >> 16);
794 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
795 AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
796 spec->pin_configs[i] >> 24);
797 pin_cfg = snd_hda_codec_read(codec, spec->pin_nids[i], 0,
798 AC_VERB_GET_CONFIG_DEFAULT,
799 0x00);
800 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x pin config %8.8x\n", spec->pin_nids[i], pin_cfg);
805 * Analog playback callbacks
807 static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
808 struct hda_codec *codec,
809 struct snd_pcm_substream *substream)
811 struct sigmatel_spec *spec = codec->spec;
812 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
815 static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
816 struct hda_codec *codec,
817 unsigned int stream_tag,
818 unsigned int format,
819 struct snd_pcm_substream *substream)
821 struct sigmatel_spec *spec = codec->spec;
822 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
825 static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
826 struct hda_codec *codec,
827 struct snd_pcm_substream *substream)
829 struct sigmatel_spec *spec = codec->spec;
830 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
834 * Digital playback callbacks
836 static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
837 struct hda_codec *codec,
838 struct snd_pcm_substream *substream)
840 struct sigmatel_spec *spec = codec->spec;
841 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
844 static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
845 struct hda_codec *codec,
846 struct snd_pcm_substream *substream)
848 struct sigmatel_spec *spec = codec->spec;
849 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
852 static int stac92xx_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
853 struct hda_codec *codec,
854 unsigned int stream_tag,
855 unsigned int format,
856 struct snd_pcm_substream *substream)
858 struct sigmatel_spec *spec = codec->spec;
859 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
860 stream_tag, format, substream);
865 * Analog capture callbacks
867 static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
868 struct hda_codec *codec,
869 unsigned int stream_tag,
870 unsigned int format,
871 struct snd_pcm_substream *substream)
873 struct sigmatel_spec *spec = codec->spec;
875 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
876 stream_tag, 0, format);
877 return 0;
880 static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
881 struct hda_codec *codec,
882 struct snd_pcm_substream *substream)
884 struct sigmatel_spec *spec = codec->spec;
886 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 0, 0, 0);
887 return 0;
890 static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
891 .substreams = 1,
892 .channels_min = 2,
893 .channels_max = 2,
894 /* NID is set in stac92xx_build_pcms */
895 .ops = {
896 .open = stac92xx_dig_playback_pcm_open,
897 .close = stac92xx_dig_playback_pcm_close,
898 .prepare = stac92xx_dig_playback_pcm_prepare
902 static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
903 .substreams = 1,
904 .channels_min = 2,
905 .channels_max = 2,
906 /* NID is set in stac92xx_build_pcms */
909 static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
910 .substreams = 1,
911 .channels_min = 2,
912 .channels_max = 8,
913 .nid = 0x02, /* NID to query formats and rates */
914 .ops = {
915 .open = stac92xx_playback_pcm_open,
916 .prepare = stac92xx_playback_pcm_prepare,
917 .cleanup = stac92xx_playback_pcm_cleanup
921 static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
922 .substreams = 1,
923 .channels_min = 2,
924 .channels_max = 2,
925 .nid = 0x06, /* NID to query formats and rates */
926 .ops = {
927 .open = stac92xx_playback_pcm_open,
928 .prepare = stac92xx_playback_pcm_prepare,
929 .cleanup = stac92xx_playback_pcm_cleanup
933 static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
934 .substreams = 2,
935 .channels_min = 2,
936 .channels_max = 2,
937 /* NID is set in stac92xx_build_pcms */
938 .ops = {
939 .prepare = stac92xx_capture_pcm_prepare,
940 .cleanup = stac92xx_capture_pcm_cleanup
944 static int stac92xx_build_pcms(struct hda_codec *codec)
946 struct sigmatel_spec *spec = codec->spec;
947 struct hda_pcm *info = spec->pcm_rec;
949 codec->num_pcms = 1;
950 codec->pcm_info = info;
952 info->name = "STAC92xx Analog";
953 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
954 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
955 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
957 if (spec->alt_switch) {
958 codec->num_pcms++;
959 info++;
960 info->name = "STAC92xx Analog Alt";
961 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
964 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
965 codec->num_pcms++;
966 info++;
967 info->name = "STAC92xx Digital";
968 if (spec->multiout.dig_out_nid) {
969 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
970 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
972 if (spec->dig_in_nid) {
973 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
974 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
978 return 0;
981 static unsigned int stac92xx_get_vref(struct hda_codec *codec, hda_nid_t nid)
983 unsigned int pincap = snd_hda_param_read(codec, nid,
984 AC_PAR_PIN_CAP);
985 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
986 if (pincap & AC_PINCAP_VREF_100)
987 return AC_PINCTL_VREF_100;
988 if (pincap & AC_PINCAP_VREF_80)
989 return AC_PINCTL_VREF_80;
990 if (pincap & AC_PINCAP_VREF_50)
991 return AC_PINCTL_VREF_50;
992 if (pincap & AC_PINCAP_VREF_GRD)
993 return AC_PINCTL_VREF_GRD;
994 return 0;
997 static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
1000 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
1003 static int stac92xx_io_switch_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1005 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1006 uinfo->count = 1;
1007 uinfo->value.integer.min = 0;
1008 uinfo->value.integer.max = 1;
1009 return 0;
1012 static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1014 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1015 struct sigmatel_spec *spec = codec->spec;
1016 int io_idx = kcontrol-> private_value & 0xff;
1018 ucontrol->value.integer.value[0] = spec->io_switch[io_idx];
1019 return 0;
1022 static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1024 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1025 struct sigmatel_spec *spec = codec->spec;
1026 hda_nid_t nid = kcontrol->private_value >> 8;
1027 int io_idx = kcontrol-> private_value & 0xff;
1028 unsigned short val = ucontrol->value.integer.value[0];
1030 spec->io_switch[io_idx] = val;
1032 if (val)
1033 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
1034 else {
1035 unsigned int pinctl = AC_PINCTL_IN_EN;
1036 if (io_idx) /* set VREF for mic */
1037 pinctl |= stac92xx_get_vref(codec, nid);
1038 stac92xx_auto_set_pinctl(codec, nid, pinctl);
1040 return 1;
1043 #define STAC_CODEC_IO_SWITCH(xname, xpval) \
1044 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1045 .name = xname, \
1046 .index = 0, \
1047 .info = stac92xx_io_switch_info, \
1048 .get = stac92xx_io_switch_get, \
1049 .put = stac92xx_io_switch_put, \
1050 .private_value = xpval, \
1054 enum {
1055 STAC_CTL_WIDGET_VOL,
1056 STAC_CTL_WIDGET_MUTE,
1057 STAC_CTL_WIDGET_IO_SWITCH,
1060 static struct snd_kcontrol_new stac92xx_control_templates[] = {
1061 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
1062 HDA_CODEC_MUTE(NULL, 0, 0, 0),
1063 STAC_CODEC_IO_SWITCH(NULL, 0),
1066 /* add dynamic controls */
1067 static int stac92xx_add_control(struct sigmatel_spec *spec, int type, const char *name, unsigned long val)
1069 struct snd_kcontrol_new *knew;
1071 if (spec->num_kctl_used >= spec->num_kctl_alloc) {
1072 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
1074 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */
1075 if (! knew)
1076 return -ENOMEM;
1077 if (spec->kctl_alloc) {
1078 memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
1079 kfree(spec->kctl_alloc);
1081 spec->kctl_alloc = knew;
1082 spec->num_kctl_alloc = num;
1085 knew = &spec->kctl_alloc[spec->num_kctl_used];
1086 *knew = stac92xx_control_templates[type];
1087 knew->name = kstrdup(name, GFP_KERNEL);
1088 if (! knew->name)
1089 return -ENOMEM;
1090 knew->private_value = val;
1091 spec->num_kctl_used++;
1092 return 0;
1095 /* flag inputs as additional dynamic lineouts */
1096 static int stac92xx_add_dyn_out_pins(struct hda_codec *codec, struct auto_pin_cfg *cfg)
1098 struct sigmatel_spec *spec = codec->spec;
1099 unsigned int wcaps, wtype;
1100 int i, num_dacs = 0;
1102 /* use the wcaps cache to count all DACs available for line-outs */
1103 for (i = 0; i < codec->num_nodes; i++) {
1104 wcaps = codec->wcaps[i];
1105 wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
1106 if (wtype == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL))
1107 num_dacs++;
1110 snd_printdd("%s: total dac count=%d\n", __func__, num_dacs);
1112 switch (cfg->line_outs) {
1113 case 3:
1114 /* add line-in as side */
1115 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 3) {
1116 cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_LINE];
1117 spec->line_switch = 1;
1118 cfg->line_outs++;
1120 break;
1121 case 2:
1122 /* add line-in as clfe and mic as side */
1123 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 2) {
1124 cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_LINE];
1125 spec->line_switch = 1;
1126 cfg->line_outs++;
1128 if (cfg->input_pins[AUTO_PIN_MIC] && num_dacs > 3) {
1129 cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_MIC];
1130 spec->mic_switch = 1;
1131 cfg->line_outs++;
1133 break;
1134 case 1:
1135 /* add line-in as surr and mic as clfe */
1136 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 1) {
1137 cfg->line_out_pins[1] = cfg->input_pins[AUTO_PIN_LINE];
1138 spec->line_switch = 1;
1139 cfg->line_outs++;
1141 if (cfg->input_pins[AUTO_PIN_MIC] && num_dacs > 2) {
1142 cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_MIC];
1143 spec->mic_switch = 1;
1144 cfg->line_outs++;
1146 break;
1149 return 0;
1153 static int is_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
1155 int i;
1157 for (i = 0; i < spec->multiout.num_dacs; i++) {
1158 if (spec->multiout.dac_nids[i] == nid)
1159 return 1;
1162 return 0;
1166 * Fill in the dac_nids table from the parsed pin configuration
1167 * This function only works when every pin in line_out_pins[]
1168 * contains atleast one DAC in its connection list. Some 92xx
1169 * codecs are not connected directly to a DAC, such as the 9200
1170 * and 9202/925x. For those, dac_nids[] must be hard-coded.
1172 static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec,
1173 const struct auto_pin_cfg *cfg)
1175 struct sigmatel_spec *spec = codec->spec;
1176 int i, j, conn_len = 0;
1177 hda_nid_t nid, conn[HDA_MAX_CONNECTIONS];
1178 unsigned int wcaps, wtype;
1180 for (i = 0; i < cfg->line_outs; i++) {
1181 nid = cfg->line_out_pins[i];
1182 conn_len = snd_hda_get_connections(codec, nid, conn,
1183 HDA_MAX_CONNECTIONS);
1184 for (j = 0; j < conn_len; j++) {
1185 wcaps = snd_hda_param_read(codec, conn[j],
1186 AC_PAR_AUDIO_WIDGET_CAP);
1187 wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
1189 if (wtype != AC_WID_AUD_OUT ||
1190 (wcaps & AC_WCAP_DIGITAL))
1191 continue;
1192 /* conn[j] is a DAC routed to this line-out */
1193 if (!is_in_dac_nids(spec, conn[j]))
1194 break;
1197 if (j == conn_len) {
1198 /* error out, no available DAC found */
1199 snd_printk(KERN_ERR
1200 "%s: No available DAC for pin 0x%x\n",
1201 __func__, nid);
1202 return -ENODEV;
1205 spec->multiout.dac_nids[i] = conn[j];
1206 spec->multiout.num_dacs++;
1207 if (conn_len > 1) {
1208 /* select this DAC in the pin's input mux */
1209 snd_hda_codec_write(codec, nid, 0,
1210 AC_VERB_SET_CONNECT_SEL, j);
1215 snd_printd("dac_nids=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
1216 spec->multiout.num_dacs,
1217 spec->multiout.dac_nids[0],
1218 spec->multiout.dac_nids[1],
1219 spec->multiout.dac_nids[2],
1220 spec->multiout.dac_nids[3],
1221 spec->multiout.dac_nids[4]);
1222 return 0;
1225 /* create volume control/switch for the given prefx type */
1226 static int create_controls(struct sigmatel_spec *spec, const char *pfx, hda_nid_t nid, int chs)
1228 char name[32];
1229 int err;
1231 sprintf(name, "%s Playback Volume", pfx);
1232 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, name,
1233 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1234 if (err < 0)
1235 return err;
1236 sprintf(name, "%s Playback Switch", pfx);
1237 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, name,
1238 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1239 if (err < 0)
1240 return err;
1241 return 0;
1244 /* add playback controls from the parsed DAC table */
1245 static int stac92xx_auto_create_multi_out_ctls(struct sigmatel_spec *spec,
1246 const struct auto_pin_cfg *cfg)
1248 static const char *chname[4] = {
1249 "Front", "Surround", NULL /*CLFE*/, "Side"
1251 hda_nid_t nid;
1252 int i, err;
1254 for (i = 0; i < cfg->line_outs; i++) {
1255 if (!spec->multiout.dac_nids[i])
1256 continue;
1258 nid = spec->multiout.dac_nids[i];
1260 if (i == 2) {
1261 /* Center/LFE */
1262 err = create_controls(spec, "Center", nid, 1);
1263 if (err < 0)
1264 return err;
1265 err = create_controls(spec, "LFE", nid, 2);
1266 if (err < 0)
1267 return err;
1268 } else {
1269 err = create_controls(spec, chname[i], nid, 3);
1270 if (err < 0)
1271 return err;
1275 if (spec->line_switch)
1276 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Line In as Output Switch", cfg->input_pins[AUTO_PIN_LINE] << 8)) < 0)
1277 return err;
1279 if (spec->mic_switch)
1280 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Mic as Output Switch", (cfg->input_pins[AUTO_PIN_MIC] << 8) | 1)) < 0)
1281 return err;
1283 return 0;
1286 static int check_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
1288 if (is_in_dac_nids(spec, nid))
1289 return 1;
1290 if (spec->multiout.hp_nid == nid)
1291 return 1;
1292 return 0;
1295 static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
1297 if (!spec->multiout.hp_nid)
1298 spec->multiout.hp_nid = nid;
1299 else if (spec->multiout.num_dacs > 4) {
1300 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
1301 return 1;
1302 } else {
1303 spec->multiout.dac_nids[spec->multiout.num_dacs] = nid;
1304 spec->multiout.num_dacs++;
1306 return 0;
1309 /* add playback controls for Speaker and HP outputs */
1310 static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
1311 struct auto_pin_cfg *cfg)
1313 struct sigmatel_spec *spec = codec->spec;
1314 hda_nid_t nid;
1315 int i, old_num_dacs, err;
1317 old_num_dacs = spec->multiout.num_dacs;
1318 for (i = 0; i < cfg->hp_outs; i++) {
1319 unsigned int wid_caps = get_wcaps(codec, cfg->hp_pins[i]);
1320 if (wid_caps & AC_WCAP_UNSOL_CAP)
1321 spec->hp_detect = 1;
1322 nid = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
1323 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
1324 if (check_in_dac_nids(spec, nid))
1325 nid = 0;
1326 if (! nid)
1327 continue;
1328 add_spec_dacs(spec, nid);
1330 for (i = 0; i < cfg->speaker_outs; i++) {
1331 nid = snd_hda_codec_read(codec, cfg->speaker_pins[i], 0,
1332 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
1333 if (check_in_dac_nids(spec, nid))
1334 nid = 0;
1335 if (! nid)
1336 continue;
1337 add_spec_dacs(spec, nid);
1340 for (i = old_num_dacs; i < spec->multiout.num_dacs; i++) {
1341 static const char *pfxs[] = {
1342 "Speaker", "External Speaker", "Speaker2",
1344 err = create_controls(spec, pfxs[i - old_num_dacs],
1345 spec->multiout.dac_nids[i], 3);
1346 if (err < 0)
1347 return err;
1349 if (spec->multiout.hp_nid) {
1350 const char *pfx;
1351 if (old_num_dacs == spec->multiout.num_dacs)
1352 pfx = "Master";
1353 else
1354 pfx = "Headphone";
1355 err = create_controls(spec, pfx, spec->multiout.hp_nid, 3);
1356 if (err < 0)
1357 return err;
1360 return 0;
1363 /* labels for dmic mux inputs */
1364 static const char *stac92xx_dmic_labels[5] = {
1365 "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
1366 "Digital Mic 3", "Digital Mic 4"
1369 /* create playback/capture controls for input pins on dmic capable codecs */
1370 static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
1371 const struct auto_pin_cfg *cfg)
1373 struct sigmatel_spec *spec = codec->spec;
1374 struct hda_input_mux *dimux = &spec->private_dimux;
1375 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
1376 int i, j;
1378 dimux->items[dimux->num_items].label = stac92xx_dmic_labels[0];
1379 dimux->items[dimux->num_items].index = 0;
1380 dimux->num_items++;
1382 for (i = 0; i < spec->num_dmics; i++) {
1383 int index;
1384 int num_cons;
1385 unsigned int def_conf;
1387 def_conf = snd_hda_codec_read(codec,
1388 spec->dmic_nids[i],
1390 AC_VERB_GET_CONFIG_DEFAULT,
1392 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
1393 continue;
1395 num_cons = snd_hda_get_connections(codec,
1396 spec->dmux_nid,
1397 con_lst,
1398 HDA_MAX_NUM_INPUTS);
1399 for (j = 0; j < num_cons; j++)
1400 if (con_lst[j] == spec->dmic_nids[i]) {
1401 index = j;
1402 goto found;
1404 continue;
1405 found:
1406 dimux->items[dimux->num_items].label =
1407 stac92xx_dmic_labels[dimux->num_items];
1408 dimux->items[dimux->num_items].index = index;
1409 dimux->num_items++;
1412 return 0;
1415 /* create playback/capture controls for input pins */
1416 static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
1418 struct sigmatel_spec *spec = codec->spec;
1419 struct hda_input_mux *imux = &spec->private_imux;
1420 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
1421 int i, j, k;
1423 for (i = 0; i < AUTO_PIN_LAST; i++) {
1424 int index;
1426 if (!cfg->input_pins[i])
1427 continue;
1428 index = -1;
1429 for (j = 0; j < spec->num_muxes; j++) {
1430 int num_cons;
1431 num_cons = snd_hda_get_connections(codec,
1432 spec->mux_nids[j],
1433 con_lst,
1434 HDA_MAX_NUM_INPUTS);
1435 for (k = 0; k < num_cons; k++)
1436 if (con_lst[k] == cfg->input_pins[i]) {
1437 index = k;
1438 goto found;
1441 continue;
1442 found:
1443 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
1444 imux->items[imux->num_items].index = index;
1445 imux->num_items++;
1448 if (imux->num_items) {
1450 * Set the current input for the muxes.
1451 * The STAC9221 has two input muxes with identical source
1452 * NID lists. Hopefully this won't get confused.
1454 for (i = 0; i < spec->num_muxes; i++) {
1455 snd_hda_codec_write(codec, spec->mux_nids[i], 0,
1456 AC_VERB_SET_CONNECT_SEL,
1457 imux->items[0].index);
1461 return 0;
1464 static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
1466 struct sigmatel_spec *spec = codec->spec;
1467 int i;
1469 for (i = 0; i < spec->autocfg.line_outs; i++) {
1470 hda_nid_t nid = spec->autocfg.line_out_pins[i];
1471 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
1475 static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
1477 struct sigmatel_spec *spec = codec->spec;
1478 int i;
1480 for (i = 0; i < spec->autocfg.hp_outs; i++) {
1481 hda_nid_t pin;
1482 pin = spec->autocfg.hp_pins[i];
1483 if (pin) /* connect to front */
1484 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
1486 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
1487 hda_nid_t pin;
1488 pin = spec->autocfg.speaker_pins[i];
1489 if (pin) /* connect to front */
1490 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
1494 static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out, hda_nid_t dig_in)
1496 struct sigmatel_spec *spec = codec->spec;
1497 int err;
1499 if ((err = snd_hda_parse_pin_def_config(codec,
1500 &spec->autocfg,
1501 spec->dmic_nids)) < 0)
1502 return err;
1503 if (! spec->autocfg.line_outs)
1504 return 0; /* can't find valid pin config */
1506 if ((err = stac92xx_add_dyn_out_pins(codec, &spec->autocfg)) < 0)
1507 return err;
1508 if (spec->multiout.num_dacs == 0)
1509 if ((err = stac92xx_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
1510 return err;
1512 if ((err = stac92xx_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
1513 (err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg)) < 0 ||
1514 (err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
1515 return err;
1517 if (spec->num_dmics > 0)
1518 if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
1519 &spec->autocfg)) < 0)
1520 return err;
1522 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
1523 if (spec->multiout.max_channels > 2)
1524 spec->surr_switch = 1;
1526 if (spec->autocfg.dig_out_pin)
1527 spec->multiout.dig_out_nid = dig_out;
1528 if (spec->autocfg.dig_in_pin)
1529 spec->dig_in_nid = dig_in;
1531 if (spec->kctl_alloc)
1532 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
1534 spec->input_mux = &spec->private_imux;
1535 spec->dinput_mux = &spec->private_dimux;
1537 return 1;
1540 /* add playback controls for HP output */
1541 static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
1542 struct auto_pin_cfg *cfg)
1544 struct sigmatel_spec *spec = codec->spec;
1545 hda_nid_t pin = cfg->hp_pins[0];
1546 unsigned int wid_caps;
1548 if (! pin)
1549 return 0;
1551 wid_caps = get_wcaps(codec, pin);
1552 if (wid_caps & AC_WCAP_UNSOL_CAP)
1553 spec->hp_detect = 1;
1555 return 0;
1558 /* add playback controls for LFE output */
1559 static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
1560 struct auto_pin_cfg *cfg)
1562 struct sigmatel_spec *spec = codec->spec;
1563 int err;
1564 hda_nid_t lfe_pin = 0x0;
1565 int i;
1568 * search speaker outs and line outs for a mono speaker pin
1569 * with an amp. If one is found, add LFE controls
1570 * for it.
1572 for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
1573 hda_nid_t pin = spec->autocfg.speaker_pins[i];
1574 unsigned long wcaps = get_wcaps(codec, pin);
1575 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
1576 if (wcaps == AC_WCAP_OUT_AMP)
1577 /* found a mono speaker with an amp, must be lfe */
1578 lfe_pin = pin;
1581 /* if speaker_outs is 0, then speakers may be in line_outs */
1582 if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
1583 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
1584 hda_nid_t pin = spec->autocfg.line_out_pins[i];
1585 unsigned long cfg;
1586 cfg = snd_hda_codec_read(codec, pin, 0,
1587 AC_VERB_GET_CONFIG_DEFAULT,
1588 0x00);
1589 if (get_defcfg_device(cfg) == AC_JACK_SPEAKER) {
1590 unsigned long wcaps = get_wcaps(codec, pin);
1591 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
1592 if (wcaps == AC_WCAP_OUT_AMP)
1593 /* found a mono speaker with an amp,
1594 must be lfe */
1595 lfe_pin = pin;
1600 if (lfe_pin) {
1601 err = create_controls(spec, "LFE", lfe_pin, 1);
1602 if (err < 0)
1603 return err;
1606 return 0;
1609 static int stac9200_parse_auto_config(struct hda_codec *codec)
1611 struct sigmatel_spec *spec = codec->spec;
1612 int err;
1614 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
1615 return err;
1617 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
1618 return err;
1620 if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
1621 return err;
1623 if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
1624 return err;
1626 if (spec->autocfg.dig_out_pin)
1627 spec->multiout.dig_out_nid = 0x05;
1628 if (spec->autocfg.dig_in_pin)
1629 spec->dig_in_nid = 0x04;
1631 if (spec->kctl_alloc)
1632 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
1634 spec->input_mux = &spec->private_imux;
1635 spec->dinput_mux = &spec->private_dimux;
1637 return 1;
1641 * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
1642 * funky external mute control using GPIO pins.
1645 static void stac922x_gpio_mute(struct hda_codec *codec, int pin, int muted)
1647 unsigned int gpiostate, gpiomask, gpiodir;
1649 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
1650 AC_VERB_GET_GPIO_DATA, 0);
1652 if (!muted)
1653 gpiostate |= (1 << pin);
1654 else
1655 gpiostate &= ~(1 << pin);
1657 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
1658 AC_VERB_GET_GPIO_MASK, 0);
1659 gpiomask |= (1 << pin);
1661 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
1662 AC_VERB_GET_GPIO_DIRECTION, 0);
1663 gpiodir |= (1 << pin);
1665 /* AppleHDA seems to do this -- WTF is this verb?? */
1666 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
1668 snd_hda_codec_write(codec, codec->afg, 0,
1669 AC_VERB_SET_GPIO_MASK, gpiomask);
1670 snd_hda_codec_write(codec, codec->afg, 0,
1671 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
1673 msleep(1);
1675 snd_hda_codec_write(codec, codec->afg, 0,
1676 AC_VERB_SET_GPIO_DATA, gpiostate);
1679 static void enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
1680 unsigned int event)
1682 if (get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP)
1683 snd_hda_codec_write(codec, nid, 0,
1684 AC_VERB_SET_UNSOLICITED_ENABLE,
1685 (AC_USRSP_EN | event));
1688 static int stac92xx_init(struct hda_codec *codec)
1690 struct sigmatel_spec *spec = codec->spec;
1691 struct auto_pin_cfg *cfg = &spec->autocfg;
1692 int i;
1694 snd_hda_sequence_write(codec, spec->init);
1696 /* set up pins */
1697 if (spec->hp_detect) {
1698 /* Enable unsolicited responses on the HP widget */
1699 for (i = 0; i < cfg->hp_outs; i++)
1700 enable_pin_detect(codec, cfg->hp_pins[i],
1701 STAC_HP_EVENT);
1702 /* force to enable the first line-out; the others are set up
1703 * in unsol_event
1705 stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
1706 AC_PINCTL_OUT_EN);
1707 stac92xx_auto_init_hp_out(codec);
1708 /* fake event to set up pins */
1709 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
1710 } else {
1711 stac92xx_auto_init_multi_out(codec);
1712 stac92xx_auto_init_hp_out(codec);
1714 for (i = 0; i < AUTO_PIN_LAST; i++) {
1715 hda_nid_t nid = cfg->input_pins[i];
1716 if (nid) {
1717 unsigned int pinctl = AC_PINCTL_IN_EN;
1718 if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC)
1719 pinctl |= stac92xx_get_vref(codec, nid);
1720 stac92xx_auto_set_pinctl(codec, nid, pinctl);
1723 if (spec->num_dmics > 0)
1724 for (i = 0; i < spec->num_dmics; i++)
1725 stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
1726 AC_PINCTL_IN_EN);
1728 if (cfg->dig_out_pin)
1729 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pin,
1730 AC_PINCTL_OUT_EN);
1731 if (cfg->dig_in_pin)
1732 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
1733 AC_PINCTL_IN_EN);
1735 if (spec->gpio_mute) {
1736 stac922x_gpio_mute(codec, 0, 0);
1737 stac922x_gpio_mute(codec, 1, 0);
1740 return 0;
1743 static void stac92xx_free(struct hda_codec *codec)
1745 struct sigmatel_spec *spec = codec->spec;
1746 int i;
1748 if (! spec)
1749 return;
1751 if (spec->kctl_alloc) {
1752 for (i = 0; i < spec->num_kctl_used; i++)
1753 kfree(spec->kctl_alloc[i].name);
1754 kfree(spec->kctl_alloc);
1757 if (spec->bios_pin_configs)
1758 kfree(spec->bios_pin_configs);
1760 kfree(spec);
1763 static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
1764 unsigned int flag)
1766 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
1767 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
1769 if (pin_ctl & AC_PINCTL_IN_EN) {
1771 * we need to check the current set-up direction of
1772 * shared input pins since they can be switched via
1773 * "xxx as Output" mixer switch
1775 struct sigmatel_spec *spec = codec->spec;
1776 struct auto_pin_cfg *cfg = &spec->autocfg;
1777 if ((nid == cfg->input_pins[AUTO_PIN_LINE] &&
1778 spec->line_switch) ||
1779 (nid == cfg->input_pins[AUTO_PIN_MIC] &&
1780 spec->mic_switch))
1781 return;
1784 /* if setting pin direction bits, clear the current
1785 direction bits first */
1786 if (flag & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))
1787 pin_ctl &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
1789 snd_hda_codec_write(codec, nid, 0,
1790 AC_VERB_SET_PIN_WIDGET_CONTROL,
1791 pin_ctl | flag);
1794 static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
1795 unsigned int flag)
1797 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
1798 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
1799 snd_hda_codec_write(codec, nid, 0,
1800 AC_VERB_SET_PIN_WIDGET_CONTROL,
1801 pin_ctl & ~flag);
1804 static int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
1806 if (!nid)
1807 return 0;
1808 if (snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PIN_SENSE, 0x00)
1809 & (1 << 31))
1810 return 1;
1811 return 0;
1814 static void stac92xx_hp_detect(struct hda_codec *codec, unsigned int res)
1816 struct sigmatel_spec *spec = codec->spec;
1817 struct auto_pin_cfg *cfg = &spec->autocfg;
1818 int i, presence;
1820 presence = 0;
1821 for (i = 0; i < cfg->hp_outs; i++) {
1822 presence = get_pin_presence(codec, cfg->hp_pins[i]);
1823 if (presence)
1824 break;
1827 if (presence) {
1828 /* disable lineouts, enable hp */
1829 for (i = 0; i < cfg->line_outs; i++)
1830 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
1831 AC_PINCTL_OUT_EN);
1832 for (i = 0; i < cfg->speaker_outs; i++)
1833 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
1834 AC_PINCTL_OUT_EN);
1835 } else {
1836 /* enable lineouts, disable hp */
1837 for (i = 0; i < cfg->line_outs; i++)
1838 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
1839 AC_PINCTL_OUT_EN);
1840 for (i = 0; i < cfg->speaker_outs; i++)
1841 stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
1842 AC_PINCTL_OUT_EN);
1846 static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
1848 switch (res >> 26) {
1849 case STAC_HP_EVENT:
1850 stac92xx_hp_detect(codec, res);
1851 break;
1855 #ifdef CONFIG_PM
1856 static int stac92xx_resume(struct hda_codec *codec)
1858 struct sigmatel_spec *spec = codec->spec;
1859 int i;
1861 stac92xx_init(codec);
1862 stac92xx_set_config_regs(codec);
1863 snd_hda_resume_ctls(codec, spec->mixer);
1864 for (i = 0; i < spec->num_mixers; i++)
1865 snd_hda_resume_ctls(codec, spec->mixers[i]);
1866 if (spec->multiout.dig_out_nid)
1867 snd_hda_resume_spdif_out(codec);
1868 if (spec->dig_in_nid)
1869 snd_hda_resume_spdif_in(codec);
1871 return 0;
1873 #endif
1875 static struct hda_codec_ops stac92xx_patch_ops = {
1876 .build_controls = stac92xx_build_controls,
1877 .build_pcms = stac92xx_build_pcms,
1878 .init = stac92xx_init,
1879 .free = stac92xx_free,
1880 .unsol_event = stac92xx_unsol_event,
1881 #ifdef CONFIG_PM
1882 .resume = stac92xx_resume,
1883 #endif
1886 static int patch_stac9200(struct hda_codec *codec)
1888 struct sigmatel_spec *spec;
1889 int err;
1891 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1892 if (spec == NULL)
1893 return -ENOMEM;
1895 codec->spec = spec;
1896 spec->num_pins = 8;
1897 spec->pin_nids = stac9200_pin_nids;
1898 spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS,
1899 stac9200_models,
1900 stac9200_cfg_tbl);
1901 if (spec->board_config < 0) {
1902 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9200, using BIOS defaults\n");
1903 err = stac92xx_save_bios_config_regs(codec);
1904 if (err < 0) {
1905 stac92xx_free(codec);
1906 return err;
1908 spec->pin_configs = spec->bios_pin_configs;
1909 } else {
1910 spec->pin_configs = stac9200_brd_tbl[spec->board_config];
1911 stac92xx_set_config_regs(codec);
1914 spec->multiout.max_channels = 2;
1915 spec->multiout.num_dacs = 1;
1916 spec->multiout.dac_nids = stac9200_dac_nids;
1917 spec->adc_nids = stac9200_adc_nids;
1918 spec->mux_nids = stac9200_mux_nids;
1919 spec->num_muxes = 1;
1920 spec->num_dmics = 0;
1922 spec->init = stac9200_core_init;
1923 spec->mixer = stac9200_mixer;
1925 err = stac9200_parse_auto_config(codec);
1926 if (err < 0) {
1927 stac92xx_free(codec);
1928 return err;
1931 codec->patch_ops = stac92xx_patch_ops;
1933 return 0;
1936 static int patch_stac925x(struct hda_codec *codec)
1938 struct sigmatel_spec *spec;
1939 int err;
1941 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1942 if (spec == NULL)
1943 return -ENOMEM;
1945 codec->spec = spec;
1946 spec->num_pins = 8;
1947 spec->pin_nids = stac925x_pin_nids;
1948 spec->board_config = snd_hda_check_board_config(codec, STAC_925x_MODELS,
1949 stac925x_models,
1950 stac925x_cfg_tbl);
1951 again:
1952 if (spec->board_config < 0) {
1953 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC925x,"
1954 "using BIOS defaults\n");
1955 err = stac92xx_save_bios_config_regs(codec);
1956 if (err < 0) {
1957 stac92xx_free(codec);
1958 return err;
1960 spec->pin_configs = spec->bios_pin_configs;
1961 } else if (stac925x_brd_tbl[spec->board_config] != NULL){
1962 spec->pin_configs = stac925x_brd_tbl[spec->board_config];
1963 stac92xx_set_config_regs(codec);
1966 spec->multiout.max_channels = 2;
1967 spec->multiout.num_dacs = 1;
1968 spec->multiout.dac_nids = stac925x_dac_nids;
1969 spec->adc_nids = stac925x_adc_nids;
1970 spec->mux_nids = stac925x_mux_nids;
1971 spec->num_muxes = 1;
1972 switch (codec->vendor_id) {
1973 case 0x83847632: /* STAC9202 */
1974 case 0x83847633: /* STAC9202D */
1975 case 0x83847636: /* STAC9251 */
1976 case 0x83847637: /* STAC9251D */
1977 spec->num_dmics = STAC925X_NUM_DMICS;
1978 spec->dmic_nids = stac925x_dmic_nids;
1979 break;
1980 default:
1981 spec->num_dmics = 0;
1982 break;
1985 spec->init = stac925x_core_init;
1986 spec->mixer = stac925x_mixer;
1988 err = stac92xx_parse_auto_config(codec, 0x8, 0x7);
1989 if (!err) {
1990 if (spec->board_config < 0) {
1991 printk(KERN_WARNING "hda_codec: No auto-config is "
1992 "available, default to model=ref\n");
1993 spec->board_config = STAC_925x_REF;
1994 goto again;
1996 err = -EINVAL;
1998 if (err < 0) {
1999 stac92xx_free(codec);
2000 return err;
2003 codec->patch_ops = stac92xx_patch_ops;
2005 return 0;
2008 static int patch_stac922x(struct hda_codec *codec)
2010 struct sigmatel_spec *spec;
2011 int err;
2013 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2014 if (spec == NULL)
2015 return -ENOMEM;
2017 codec->spec = spec;
2018 spec->num_pins = 10;
2019 spec->pin_nids = stac922x_pin_nids;
2020 spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS,
2021 stac922x_models,
2022 stac922x_cfg_tbl);
2023 if (spec->board_config == STAC_MACMINI) {
2024 spec->gpio_mute = 1;
2025 /* Intel Macs have all same PCI SSID, so we need to check
2026 * codec SSID to distinguish the exact models
2028 printk(KERN_INFO "hda_codec: STAC922x, Apple subsys_id=%x\n", codec->subsystem_id);
2029 switch (codec->subsystem_id) {
2030 case 0x106b0a00: /* MacBook First generatoin */
2031 spec->board_config = STAC_MACBOOK;
2032 break;
2033 case 0x106b0200: /* MacBook Pro first generation */
2034 spec->board_config = STAC_MACBOOK_PRO_V1;
2035 break;
2036 case 0x106b1e00: /* MacBook Pro second generation */
2037 spec->board_config = STAC_MACBOOK_PRO_V2;
2038 break;
2039 case 0x106b0700: /* Intel-based iMac */
2040 spec->board_config = STAC_IMAC_INTEL;
2041 break;
2045 again:
2046 if (spec->board_config < 0) {
2047 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC922x, "
2048 "using BIOS defaults\n");
2049 err = stac92xx_save_bios_config_regs(codec);
2050 if (err < 0) {
2051 stac92xx_free(codec);
2052 return err;
2054 spec->pin_configs = spec->bios_pin_configs;
2055 } else if (stac922x_brd_tbl[spec->board_config] != NULL) {
2056 spec->pin_configs = stac922x_brd_tbl[spec->board_config];
2057 stac92xx_set_config_regs(codec);
2060 spec->adc_nids = stac922x_adc_nids;
2061 spec->mux_nids = stac922x_mux_nids;
2062 spec->num_muxes = ARRAY_SIZE(stac922x_mux_nids);
2063 spec->num_dmics = 0;
2065 spec->init = stac922x_core_init;
2066 spec->mixer = stac922x_mixer;
2068 spec->multiout.dac_nids = spec->dac_nids;
2070 err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
2071 if (!err) {
2072 if (spec->board_config < 0) {
2073 printk(KERN_WARNING "hda_codec: No auto-config is "
2074 "available, default to model=ref\n");
2075 spec->board_config = STAC_D945_REF;
2076 goto again;
2078 err = -EINVAL;
2080 if (err < 0) {
2081 stac92xx_free(codec);
2082 return err;
2085 codec->patch_ops = stac92xx_patch_ops;
2087 return 0;
2090 static int patch_stac927x(struct hda_codec *codec)
2092 struct sigmatel_spec *spec;
2093 int err;
2095 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2096 if (spec == NULL)
2097 return -ENOMEM;
2099 codec->spec = spec;
2100 spec->num_pins = 14;
2101 spec->pin_nids = stac927x_pin_nids;
2102 spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS,
2103 stac927x_models,
2104 stac927x_cfg_tbl);
2105 again:
2106 if (spec->board_config < 0) {
2107 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC927x, using BIOS defaults\n");
2108 err = stac92xx_save_bios_config_regs(codec);
2109 if (err < 0) {
2110 stac92xx_free(codec);
2111 return err;
2113 spec->pin_configs = spec->bios_pin_configs;
2114 } else if (stac927x_brd_tbl[spec->board_config] != NULL) {
2115 spec->pin_configs = stac927x_brd_tbl[spec->board_config];
2116 stac92xx_set_config_regs(codec);
2119 switch (spec->board_config) {
2120 case STAC_D965_3ST:
2121 spec->adc_nids = stac927x_adc_nids;
2122 spec->mux_nids = stac927x_mux_nids;
2123 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
2124 spec->num_dmics = 0;
2125 spec->init = d965_core_init;
2126 spec->mixer = stac9227_mixer;
2127 break;
2128 case STAC_D965_5ST:
2129 spec->adc_nids = stac927x_adc_nids;
2130 spec->mux_nids = stac927x_mux_nids;
2131 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
2132 spec->num_dmics = 0;
2133 spec->init = d965_core_init;
2134 spec->mixer = stac9227_mixer;
2135 break;
2136 default:
2137 spec->adc_nids = stac927x_adc_nids;
2138 spec->mux_nids = stac927x_mux_nids;
2139 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
2140 spec->num_dmics = 0;
2141 spec->init = stac927x_core_init;
2142 spec->mixer = stac927x_mixer;
2145 spec->multiout.dac_nids = spec->dac_nids;
2147 err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
2148 if (!err) {
2149 if (spec->board_config < 0) {
2150 printk(KERN_WARNING "hda_codec: No auto-config is "
2151 "available, default to model=ref\n");
2152 spec->board_config = STAC_D965_REF;
2153 goto again;
2155 err = -EINVAL;
2157 if (err < 0) {
2158 stac92xx_free(codec);
2159 return err;
2162 codec->patch_ops = stac92xx_patch_ops;
2164 /* Fix Mux capture level; max to 2 */
2165 snd_hda_override_amp_caps(codec, 0x12, HDA_OUTPUT,
2166 (0 << AC_AMPCAP_OFFSET_SHIFT) |
2167 (2 << AC_AMPCAP_NUM_STEPS_SHIFT) |
2168 (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
2169 (0 << AC_AMPCAP_MUTE_SHIFT));
2171 return 0;
2174 static int patch_stac9205(struct hda_codec *codec)
2176 struct sigmatel_spec *spec;
2177 int err;
2179 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2180 if (spec == NULL)
2181 return -ENOMEM;
2183 codec->spec = spec;
2184 spec->num_pins = 14;
2185 spec->pin_nids = stac9205_pin_nids;
2186 spec->board_config = snd_hda_check_board_config(codec, STAC_9205_MODELS,
2187 stac9205_models,
2188 stac9205_cfg_tbl);
2189 again:
2190 if (spec->board_config < 0) {
2191 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9205, using BIOS defaults\n");
2192 err = stac92xx_save_bios_config_regs(codec);
2193 if (err < 0) {
2194 stac92xx_free(codec);
2195 return err;
2197 spec->pin_configs = spec->bios_pin_configs;
2198 } else {
2199 spec->pin_configs = stac9205_brd_tbl[spec->board_config];
2200 stac92xx_set_config_regs(codec);
2203 spec->adc_nids = stac9205_adc_nids;
2204 spec->mux_nids = stac9205_mux_nids;
2205 spec->num_muxes = ARRAY_SIZE(stac9205_mux_nids);
2206 spec->dmic_nids = stac9205_dmic_nids;
2207 spec->num_dmics = STAC9205_NUM_DMICS;
2208 spec->dmux_nid = 0x1d;
2210 spec->init = stac9205_core_init;
2211 spec->mixer = stac9205_mixer;
2213 spec->multiout.dac_nids = spec->dac_nids;
2215 /* Configure GPIO0 as EAPD output */
2216 snd_hda_codec_write(codec, codec->afg, 0,
2217 AC_VERB_SET_GPIO_DIRECTION, 0x00000001);
2218 /* Configure GPIO0 as CMOS */
2219 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0x00000000);
2220 /* Assert GPIO0 high */
2221 snd_hda_codec_write(codec, codec->afg, 0,
2222 AC_VERB_SET_GPIO_DATA, 0x00000001);
2223 /* Enable GPIO0 */
2224 snd_hda_codec_write(codec, codec->afg, 0,
2225 AC_VERB_SET_GPIO_MASK, 0x00000001);
2227 err = stac92xx_parse_auto_config(codec, 0x1f, 0x20);
2228 if (!err) {
2229 if (spec->board_config < 0) {
2230 printk(KERN_WARNING "hda_codec: No auto-config is "
2231 "available, default to model=ref\n");
2232 spec->board_config = STAC_9205_REF;
2233 goto again;
2235 err = -EINVAL;
2237 if (err < 0) {
2238 stac92xx_free(codec);
2239 return err;
2242 codec->patch_ops = stac92xx_patch_ops;
2244 return 0;
2248 * STAC9872 hack
2251 /* static config for Sony VAIO FE550G and Sony VAIO AR */
2252 static hda_nid_t vaio_dacs[] = { 0x2 };
2253 #define VAIO_HP_DAC 0x5
2254 static hda_nid_t vaio_adcs[] = { 0x8 /*,0x6*/ };
2255 static hda_nid_t vaio_mux_nids[] = { 0x15 };
2257 static struct hda_input_mux vaio_mux = {
2258 .num_items = 2,
2259 .items = {
2260 /* { "HP", 0x0 }, */
2261 { "Line", 0x1 },
2262 { "Mic", 0x2 },
2263 { "PCM", 0x3 },
2267 static struct hda_verb vaio_init[] = {
2268 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
2269 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
2270 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
2271 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
2272 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
2273 {0x15, AC_VERB_SET_CONNECT_SEL, 0x2}, /* mic-sel: 0a,0d,14,02 */
2274 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
2275 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
2276 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
2277 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
2278 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
2282 static struct hda_verb vaio_ar_init[] = {
2283 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
2284 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
2285 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
2286 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
2287 /* {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },*/ /* Optical Out */
2288 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
2289 {0x15, AC_VERB_SET_CONNECT_SEL, 0x2}, /* mic-sel: 0a,0d,14,02 */
2290 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
2291 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
2292 /* {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},*/ /* Optical Out */
2293 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
2294 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
2295 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
2299 /* bind volumes of both NID 0x02 and 0x05 */
2300 static int vaio_master_vol_put(struct snd_kcontrol *kcontrol,
2301 struct snd_ctl_elem_value *ucontrol)
2303 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2304 long *valp = ucontrol->value.integer.value;
2305 int change;
2307 change = snd_hda_codec_amp_update(codec, 0x02, 0, HDA_OUTPUT, 0,
2308 0x7f, valp[0] & 0x7f);
2309 change |= snd_hda_codec_amp_update(codec, 0x02, 1, HDA_OUTPUT, 0,
2310 0x7f, valp[1] & 0x7f);
2311 snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
2312 0x7f, valp[0] & 0x7f);
2313 snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
2314 0x7f, valp[1] & 0x7f);
2315 return change;
2318 /* bind volumes of both NID 0x02 and 0x05 */
2319 static int vaio_master_sw_put(struct snd_kcontrol *kcontrol,
2320 struct snd_ctl_elem_value *ucontrol)
2322 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2323 long *valp = ucontrol->value.integer.value;
2324 int change;
2326 change = snd_hda_codec_amp_update(codec, 0x02, 0, HDA_OUTPUT, 0,
2327 0x80, (valp[0] ? 0 : 0x80));
2328 change |= snd_hda_codec_amp_update(codec, 0x02, 1, HDA_OUTPUT, 0,
2329 0x80, (valp[1] ? 0 : 0x80));
2330 snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
2331 0x80, (valp[0] ? 0 : 0x80));
2332 snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
2333 0x80, (valp[1] ? 0 : 0x80));
2334 return change;
2337 static struct snd_kcontrol_new vaio_mixer[] = {
2339 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2340 .name = "Master Playback Volume",
2341 .info = snd_hda_mixer_amp_volume_info,
2342 .get = snd_hda_mixer_amp_volume_get,
2343 .put = vaio_master_vol_put,
2344 .tlv = { .c = snd_hda_mixer_amp_tlv },
2345 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2348 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2349 .name = "Master Playback Switch",
2350 .info = snd_hda_mixer_amp_switch_info,
2351 .get = snd_hda_mixer_amp_switch_get,
2352 .put = vaio_master_sw_put,
2353 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2355 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
2356 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
2357 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
2359 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2360 .name = "Capture Source",
2361 .count = 1,
2362 .info = stac92xx_mux_enum_info,
2363 .get = stac92xx_mux_enum_get,
2364 .put = stac92xx_mux_enum_put,
2369 static struct snd_kcontrol_new vaio_ar_mixer[] = {
2371 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2372 .name = "Master Playback Volume",
2373 .info = snd_hda_mixer_amp_volume_info,
2374 .get = snd_hda_mixer_amp_volume_get,
2375 .put = vaio_master_vol_put,
2376 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2379 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2380 .name = "Master Playback Switch",
2381 .info = snd_hda_mixer_amp_switch_info,
2382 .get = snd_hda_mixer_amp_switch_get,
2383 .put = vaio_master_sw_put,
2384 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2386 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
2387 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
2388 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
2389 /*HDA_CODEC_MUTE("Optical Out Switch", 0x10, 0, HDA_OUTPUT),
2390 HDA_CODEC_VOLUME("Optical Out Volume", 0x10, 0, HDA_OUTPUT),*/
2392 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2393 .name = "Capture Source",
2394 .count = 1,
2395 .info = stac92xx_mux_enum_info,
2396 .get = stac92xx_mux_enum_get,
2397 .put = stac92xx_mux_enum_put,
2402 static struct hda_codec_ops stac9872_patch_ops = {
2403 .build_controls = stac92xx_build_controls,
2404 .build_pcms = stac92xx_build_pcms,
2405 .init = stac92xx_init,
2406 .free = stac92xx_free,
2407 #ifdef CONFIG_PM
2408 .resume = stac92xx_resume,
2409 #endif
2412 enum { /* FE and SZ series. id=0x83847661 and subsys=0x104D0700 or 104D1000. */
2413 CXD9872RD_VAIO,
2414 /* Unknown. id=0x83847662 and subsys=0x104D1200 or 104D1000. */
2415 STAC9872AK_VAIO,
2416 /* Unknown. id=0x83847661 and subsys=0x104D1200. */
2417 STAC9872K_VAIO,
2418 /* AR Series. id=0x83847664 and subsys=104D1300 */
2419 CXD9872AKD_VAIO,
2420 STAC_9872_MODELS,
2423 static const char *stac9872_models[STAC_9872_MODELS] = {
2424 [CXD9872RD_VAIO] = "vaio",
2425 [CXD9872AKD_VAIO] = "vaio-ar",
2428 static struct snd_pci_quirk stac9872_cfg_tbl[] = {
2429 SND_PCI_QUIRK(0x104d, 0x81e6, "Sony VAIO F/S", CXD9872RD_VAIO),
2430 SND_PCI_QUIRK(0x104d, 0x81ef, "Sony VAIO F/S", CXD9872RD_VAIO),
2431 SND_PCI_QUIRK(0x104d, 0x81fd, "Sony VAIO AR", CXD9872AKD_VAIO),
2432 SND_PCI_QUIRK(0x104d, 0x8205, "Sony VAIO AR", CXD9872AKD_VAIO),
2436 static int patch_stac9872(struct hda_codec *codec)
2438 struct sigmatel_spec *spec;
2439 int board_config;
2441 board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
2442 stac9872_models,
2443 stac9872_cfg_tbl);
2444 if (board_config < 0)
2445 /* unknown config, let generic-parser do its job... */
2446 return snd_hda_parse_generic_codec(codec);
2448 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2449 if (spec == NULL)
2450 return -ENOMEM;
2452 codec->spec = spec;
2453 switch (board_config) {
2454 case CXD9872RD_VAIO:
2455 case STAC9872AK_VAIO:
2456 case STAC9872K_VAIO:
2457 spec->mixer = vaio_mixer;
2458 spec->init = vaio_init;
2459 spec->multiout.max_channels = 2;
2460 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
2461 spec->multiout.dac_nids = vaio_dacs;
2462 spec->multiout.hp_nid = VAIO_HP_DAC;
2463 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
2464 spec->adc_nids = vaio_adcs;
2465 spec->input_mux = &vaio_mux;
2466 spec->mux_nids = vaio_mux_nids;
2467 break;
2469 case CXD9872AKD_VAIO:
2470 spec->mixer = vaio_ar_mixer;
2471 spec->init = vaio_ar_init;
2472 spec->multiout.max_channels = 2;
2473 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
2474 spec->multiout.dac_nids = vaio_dacs;
2475 spec->multiout.hp_nid = VAIO_HP_DAC;
2476 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
2477 spec->adc_nids = vaio_adcs;
2478 spec->input_mux = &vaio_mux;
2479 spec->mux_nids = vaio_mux_nids;
2480 break;
2483 codec->patch_ops = stac9872_patch_ops;
2484 return 0;
2489 * patch entries
2491 struct hda_codec_preset snd_hda_preset_sigmatel[] = {
2492 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
2493 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
2494 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
2495 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
2496 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
2497 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
2498 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
2499 { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
2500 { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
2501 { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
2502 { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
2503 { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
2504 { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
2505 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
2506 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
2507 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
2508 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
2509 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
2510 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
2511 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
2512 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
2513 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
2514 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
2515 { .id = 0x83847632, .name = "STAC9202", .patch = patch_stac925x },
2516 { .id = 0x83847633, .name = "STAC9202D", .patch = patch_stac925x },
2517 { .id = 0x83847634, .name = "STAC9250", .patch = patch_stac925x },
2518 { .id = 0x83847635, .name = "STAC9250D", .patch = patch_stac925x },
2519 { .id = 0x83847636, .name = "STAC9251", .patch = patch_stac925x },
2520 { .id = 0x83847637, .name = "STAC9250D", .patch = patch_stac925x },
2521 /* The following does not take into account .id=0x83847661 when subsys =
2522 * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
2523 * currently not fully supported.
2525 { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
2526 { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
2527 { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
2528 { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
2529 { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
2530 { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
2531 { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
2532 { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
2533 { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
2534 { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
2535 { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
2536 {} /* terminator */