[ALSA] hda-codec - Use snd_pci_quirk_lookup() for board config lookup
[deliverable/linux.git] / sound / pci / hda / patch_sigmatel.c
CommitLineData
2f2f4251
M
1/*
2 * Universal Interface for Intel High Definition Audio Codec
3 *
4 * HD audio interface patch for SigmaTel STAC92xx
5 *
6 * Copyright (c) 2005 Embedded Alley Solutions, Inc.
403d1944 7 * Matt Porter <mporter@embeddedalley.com>
2f2f4251
M
8 *
9 * Based on patch_cmedia.c and patch_realtek.c
10 * Copyright (c) 2004 Takashi Iwai <tiwai@suse.de>
11 *
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.
16 *
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.
21 *
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
25 */
26
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>
c7d4b2fa 33#include <sound/asoundef.h>
2f2f4251
M
34#include "hda_codec.h"
35#include "hda_local.h"
36
4e55096e
M
37#define NUM_CONTROL_ALLOC 32
38#define STAC_HP_EVENT 0x37
4e55096e 39
f5fcc13c
TI
40enum {
41 STAC_REF,
42 STAC_9200_MODELS
43};
44
45enum {
46 STAC_9205_REF,
47 STAC_9205_MODELS
48};
49
50enum {
51 STAC_D945_REF,
52 STAC_D945GTP3,
53 STAC_D945GTP5,
54 STAC_MACMINI,
55 STAC_922X_MODELS
56};
57
58enum {
59 STAC_D965_REF,
60 STAC_D965_3ST,
61 STAC_D965_5ST,
62 STAC_927X_MODELS
63};
403d1944 64
2f2f4251 65struct sigmatel_spec {
c8b6bf9b 66 struct snd_kcontrol_new *mixers[4];
c7d4b2fa
M
67 unsigned int num_mixers;
68
403d1944 69 int board_config;
c7d4b2fa 70 unsigned int surr_switch: 1;
403d1944
MP
71 unsigned int line_switch: 1;
72 unsigned int mic_switch: 1;
3cc08dc6 73 unsigned int alt_switch: 1;
82bc955f 74 unsigned int hp_detect: 1;
62fe78e9 75 unsigned int gpio_mute: 1;
c7d4b2fa 76
2f2f4251
M
77 /* playback */
78 struct hda_multi_out multiout;
3cc08dc6 79 hda_nid_t dac_nids[5];
2f2f4251
M
80
81 /* capture */
82 hda_nid_t *adc_nids;
2f2f4251 83 unsigned int num_adcs;
dabbed6f
M
84 hda_nid_t *mux_nids;
85 unsigned int num_muxes;
8b65727b
MP
86 hda_nid_t *dmic_nids;
87 unsigned int num_dmics;
88 hda_nid_t dmux_nid;
dabbed6f 89 hda_nid_t dig_in_nid;
2f2f4251 90
2f2f4251
M
91 /* pin widgets */
92 hda_nid_t *pin_nids;
93 unsigned int num_pins;
2f2f4251 94 unsigned int *pin_configs;
11b44bbd 95 unsigned int *bios_pin_configs;
2f2f4251
M
96
97 /* codec specific stuff */
98 struct hda_verb *init;
c8b6bf9b 99 struct snd_kcontrol_new *mixer;
2f2f4251
M
100
101 /* capture source */
8b65727b
MP
102 struct hda_input_mux *dinput_mux;
103 unsigned int cur_dmux;
c7d4b2fa 104 struct hda_input_mux *input_mux;
3cc08dc6 105 unsigned int cur_mux[3];
2f2f4251 106
403d1944
MP
107 /* i/o switches */
108 unsigned int io_switch[2];
2f2f4251 109
c7d4b2fa
M
110 struct hda_pcm pcm_rec[2]; /* PCM information */
111
112 /* dynamic controls and input_mux */
113 struct auto_pin_cfg autocfg;
114 unsigned int num_kctl_alloc, num_kctl_used;
c8b6bf9b 115 struct snd_kcontrol_new *kctl_alloc;
8b65727b 116 struct hda_input_mux private_dimux;
c7d4b2fa 117 struct hda_input_mux private_imux;
2f2f4251
M
118};
119
120static hda_nid_t stac9200_adc_nids[1] = {
121 0x03,
122};
123
124static hda_nid_t stac9200_mux_nids[1] = {
125 0x0c,
126};
127
128static hda_nid_t stac9200_dac_nids[1] = {
129 0x02,
130};
131
2f2f4251
M
132static hda_nid_t stac922x_adc_nids[2] = {
133 0x06, 0x07,
134};
135
136static hda_nid_t stac922x_mux_nids[2] = {
137 0x12, 0x13,
138};
139
3cc08dc6
MP
140static hda_nid_t stac927x_adc_nids[3] = {
141 0x07, 0x08, 0x09
142};
143
144static hda_nid_t stac927x_mux_nids[3] = {
145 0x15, 0x16, 0x17
146};
147
f3302a59
MP
148static hda_nid_t stac9205_adc_nids[2] = {
149 0x12, 0x13
150};
151
152static hda_nid_t stac9205_mux_nids[2] = {
153 0x19, 0x1a
154};
155
8b65727b
MP
156static hda_nid_t stac9205_dmic_nids[3] = {
157 0x17, 0x18, 0
158};
159
c7d4b2fa 160static hda_nid_t stac9200_pin_nids[8] = {
93ed1503
TD
161 0x08, 0x09, 0x0d, 0x0e,
162 0x0f, 0x10, 0x11, 0x12,
2f2f4251
M
163};
164
165static hda_nid_t stac922x_pin_nids[10] = {
166 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
167 0x0f, 0x10, 0x11, 0x15, 0x1b,
168};
169
3cc08dc6
MP
170static hda_nid_t stac927x_pin_nids[14] = {
171 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
172 0x0f, 0x10, 0x11, 0x12, 0x13,
173 0x14, 0x21, 0x22, 0x23,
174};
175
f3302a59
MP
176static hda_nid_t stac9205_pin_nids[12] = {
177 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
178 0x0f, 0x14, 0x16, 0x17, 0x18,
179 0x21, 0x22,
180
181};
182
8b65727b
MP
183static int stac92xx_dmux_enum_info(struct snd_kcontrol *kcontrol,
184 struct snd_ctl_elem_info *uinfo)
185{
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);
189}
190
191static int stac92xx_dmux_enum_get(struct snd_kcontrol *kcontrol,
192 struct snd_ctl_elem_value *ucontrol)
193{
194 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
195 struct sigmatel_spec *spec = codec->spec;
196
197 ucontrol->value.enumerated.item[0] = spec->cur_dmux;
198 return 0;
199}
200
201static int stac92xx_dmux_enum_put(struct snd_kcontrol *kcontrol,
202 struct snd_ctl_elem_value *ucontrol)
203{
204 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
205 struct sigmatel_spec *spec = codec->spec;
206
207 return snd_hda_input_mux_put(codec, spec->dinput_mux, ucontrol,
208 spec->dmux_nid, &spec->cur_dmux);
209}
210
c8b6bf9b 211static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
2f2f4251
M
212{
213 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
214 struct sigmatel_spec *spec = codec->spec;
c7d4b2fa 215 return snd_hda_input_mux_info(spec->input_mux, uinfo);
2f2f4251
M
216}
217
c8b6bf9b 218static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2f2f4251
M
219{
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);
223
224 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
225 return 0;
226}
227
c8b6bf9b 228static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2f2f4251
M
229{
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);
233
c7d4b2fa 234 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
2f2f4251
M
235 spec->mux_nids[adc_idx], &spec->cur_mux[adc_idx]);
236}
237
c7d4b2fa 238static struct hda_verb stac9200_core_init[] = {
2f2f4251 239 /* set dac0mux for dac converter */
c7d4b2fa 240 { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
2f2f4251
M
241 {}
242};
243
c7d4b2fa 244static struct hda_verb stac922x_core_init[] = {
2f2f4251 245 /* set master volume and direct control */
c7d4b2fa 246 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
2f2f4251
M
247 {}
248};
249
93ed1503 250static struct hda_verb d965_core_init[] = {
19039bd0 251 /* set master volume and direct control */
93ed1503 252 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
19039bd0
TI
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},
257 {}
258};
259
3cc08dc6
MP
260static struct hda_verb stac927x_core_init[] = {
261 /* set master volume and direct control */
262 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
263 {}
264};
265
f3302a59
MP
266static struct hda_verb stac9205_core_init[] = {
267 /* set master volume and direct control */
268 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
269 {}
270};
271
c8b6bf9b 272static struct snd_kcontrol_new stac9200_mixer[] = {
2f2f4251
M
273 HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
274 HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
275 {
276 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
277 .name = "Input Source",
278 .count = 1,
279 .info = stac92xx_mux_enum_info,
280 .get = stac92xx_mux_enum_get,
281 .put = stac92xx_mux_enum_put,
282 },
283 HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
284 HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
c7d4b2fa 285 HDA_CODEC_VOLUME("Capture Mux Volume", 0x0c, 0, HDA_OUTPUT),
2f2f4251
M
286 { } /* end */
287};
288
c7d4b2fa 289/* This needs to be generated dynamically based on sequence */
c8b6bf9b 290static struct snd_kcontrol_new stac922x_mixer[] = {
2f2f4251
M
291 {
292 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
293 .name = "Input Source",
294 .count = 1,
295 .info = stac92xx_mux_enum_info,
296 .get = stac92xx_mux_enum_get,
297 .put = stac92xx_mux_enum_put,
298 },
299 HDA_CODEC_VOLUME("Capture Volume", 0x17, 0x0, HDA_INPUT),
0fd1708a 300 HDA_CODEC_MUTE("Capture Switch", 0x17, 0x0, HDA_INPUT),
2f2f4251
M
301 HDA_CODEC_VOLUME("Mux Capture Volume", 0x12, 0x0, HDA_OUTPUT),
302 { } /* end */
303};
304
19039bd0
TI
305/* This needs to be generated dynamically based on sequence */
306static struct snd_kcontrol_new stac9227_mixer[] = {
307 {
308 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
309 .name = "Input Source",
310 .count = 1,
311 .info = stac92xx_mux_enum_info,
312 .get = stac92xx_mux_enum_get,
313 .put = stac92xx_mux_enum_put,
314 },
315 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
316 HDA_CODEC_MUTE("Capture Switch", 0x1b, 0x0, HDA_OUTPUT),
317 { } /* end */
318};
319
d1d985f0 320static struct snd_kcontrol_new stac927x_mixer[] = {
3cc08dc6
MP
321 {
322 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
323 .name = "Input Source",
324 .count = 1,
325 .info = stac92xx_mux_enum_info,
326 .get = stac92xx_mux_enum_get,
327 .put = stac92xx_mux_enum_put,
328 },
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),
332 { } /* end */
333};
334
d1d985f0 335static struct snd_kcontrol_new stac9205_mixer[] = {
8b65727b
MP
336 {
337 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
338 .name = "Digital Input Source",
339 .count = 1,
340 .info = stac92xx_dmux_enum_info,
341 .get = stac92xx_dmux_enum_get,
342 .put = stac92xx_dmux_enum_put,
343 },
f3302a59
MP
344 {
345 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
346 .name = "Input Source",
347 .count = 1,
348 .info = stac92xx_mux_enum_info,
349 .get = stac92xx_mux_enum_get,
350 .put = stac92xx_mux_enum_put,
351 },
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),
355 { } /* end */
356};
357
2f2f4251
M
358static int stac92xx_build_controls(struct hda_codec *codec)
359{
360 struct sigmatel_spec *spec = codec->spec;
361 int err;
c7d4b2fa 362 int i;
2f2f4251
M
363
364 err = snd_hda_add_new_ctls(codec, spec->mixer);
365 if (err < 0)
366 return err;
c7d4b2fa
M
367
368 for (i = 0; i < spec->num_mixers; i++) {
369 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
370 if (err < 0)
371 return err;
372 }
373
dabbed6f
M
374 if (spec->multiout.dig_out_nid) {
375 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
376 if (err < 0)
377 return err;
378 }
379 if (spec->dig_in_nid) {
380 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
381 if (err < 0)
382 return err;
383 }
384 return 0;
2f2f4251
M
385}
386
403d1944 387static unsigned int ref9200_pin_configs[8] = {
dabbed6f 388 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
2f2f4251
M
389 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
390};
391
f5fcc13c
TI
392static unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
393 [STAC_REF] = ref9200_pin_configs,
403d1944
MP
394};
395
f5fcc13c
TI
396static const char *stac9200_models[STAC_9200_MODELS] = {
397 [STAC_REF] = "ref",
398};
399
400static 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),
e7377071 404 /* Dell laptops have BIOS problem */
f5fcc13c
TI
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),
403d1944
MP
411 {} /* terminator */
412};
413
414static unsigned int ref922x_pin_configs[10] = {
415 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
416 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
2f2f4251
M
417 0x40000100, 0x40000100,
418};
419
403d1944 420static unsigned int d945gtp3_pin_configs[10] = {
869264c4 421 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
403d1944
MP
422 0x40000100, 0x40000100, 0x40000100, 0x40000100,
423 0x02a19120, 0x40000100,
424};
425
426static unsigned int d945gtp5_pin_configs[10] = {
869264c4
MP
427 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
428 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
403d1944
MP
429 0x02a19320, 0x40000100,
430};
431
19039bd0 432static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
f5fcc13c 433 [STAC_D945_REF] = ref922x_pin_configs,
19039bd0
TI
434 [STAC_D945GTP3] = d945gtp3_pin_configs,
435 [STAC_D945GTP5] = d945gtp5_pin_configs,
7c3dec06 436 [STAC_MACMINI] = d945gtp5_pin_configs,
403d1944
MP
437};
438
f5fcc13c
TI
439static const char *stac922x_models[STAC_922X_MODELS] = {
440 [STAC_D945_REF] = "ref",
441 [STAC_D945GTP5] = "5stack",
442 [STAC_D945GTP3] = "3stack",
443 [STAC_MACMINI] = "macmini",
444};
445
446static 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),
503 /* other systems */
504 /* Apple Mac Mini (early 2006) */
505 SND_PCI_QUIRK(0x8384, 0x7680,
506 "Mac Mini", STAC_MACMINI),
403d1944
MP
507 {} /* terminator */
508};
509
3cc08dc6 510static unsigned int ref927x_pin_configs[14] = {
93ed1503
TD
511 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
512 0x01a19040, 0x01011012, 0x01016011, 0x0101201f,
513 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
514 0x01c42190, 0x40000100,
3cc08dc6
MP
515};
516
93ed1503 517static unsigned int d965_3st_pin_configs[14] = {
81d3dbde
TD
518 0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
519 0x01a19021, 0x01813024, 0x40000100, 0x40000100,
520 0x40000100, 0x40000100, 0x40000100, 0x40000100,
521 0x40000100, 0x40000100
522};
523
93ed1503
TD
524static 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
529};
530
531static unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
f5fcc13c 532 [STAC_D965_REF] = ref927x_pin_configs,
93ed1503
TD
533 [STAC_D965_3ST] = d965_3st_pin_configs,
534 [STAC_D965_5ST] = d965_5st_pin_configs,
3cc08dc6
MP
535};
536
f5fcc13c
TI
537static const char *stac927x_models[STAC_927X_MODELS] = {
538 [STAC_D965_REF] = "ref",
539 [STAC_D965_3ST] = "3stack",
540 [STAC_D965_5ST] = "5stack",
541};
542
543static 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),
81d3dbde 547 /* Intel 946 based systems */
f5fcc13c
TI
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),
93ed1503 550 /* 965 based 3 stack systems */
f5fcc13c
TI
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),
93ed1503 567 /* 965 based 5 stack systems */
f5fcc13c
TI
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),
3cc08dc6
MP
577 {} /* terminator */
578};
579
f3302a59
MP
580static unsigned int ref9205_pin_configs[12] = {
581 0x40000100, 0x40000100, 0x01016011, 0x01014010,
8b65727b
MP
582 0x01813122, 0x01a19021, 0x40000100, 0x40000100,
583 0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
f3302a59
MP
584};
585
f5fcc13c 586static unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
f3302a59
MP
587 ref9205_pin_configs,
588};
589
f5fcc13c
TI
590static const char *stac9205_models[STAC_9205_MODELS] = {
591 [STAC_9205_REF] = "ref",
592};
593
594static 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),
f3302a59
MP
598 {} /* terminator */
599};
600
11b44bbd
RF
601static int stac92xx_save_bios_config_regs(struct hda_codec *codec)
602{
603 int i;
604 struct sigmatel_spec *spec = codec->spec;
605
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)
610 return -ENOMEM;
611 }
612
613 for (i = 0; i < spec->num_pins; i++) {
614 hda_nid_t nid = spec->pin_nids[i];
615 unsigned int pin_cfg;
616
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",
620 nid, pin_cfg);
621 spec->bios_pin_configs[i] = pin_cfg;
622 }
623
624 return 0;
625}
626
2f2f4251
M
627static void stac92xx_set_config_regs(struct hda_codec *codec)
628{
629 int i;
630 struct sigmatel_spec *spec = codec->spec;
631 unsigned int pin_cfg;
632
11b44bbd
RF
633 if (! spec->pin_nids || ! spec->pin_configs)
634 return;
635
636 for (i = 0; i < spec->num_pins; i++) {
2f2f4251
M
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,
651 0x00);
403d1944 652 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x pin config %8.8x\n", spec->pin_nids[i], pin_cfg);
2f2f4251
M
653 }
654}
2f2f4251 655
dabbed6f 656/*
c7d4b2fa 657 * Analog playback callbacks
dabbed6f 658 */
c7d4b2fa
M
659static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
660 struct hda_codec *codec,
c8b6bf9b 661 struct snd_pcm_substream *substream)
2f2f4251 662{
dabbed6f 663 struct sigmatel_spec *spec = codec->spec;
c7d4b2fa 664 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
2f2f4251
M
665}
666
2f2f4251
M
667static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
668 struct hda_codec *codec,
669 unsigned int stream_tag,
670 unsigned int format,
c8b6bf9b 671 struct snd_pcm_substream *substream)
2f2f4251
M
672{
673 struct sigmatel_spec *spec = codec->spec;
403d1944 674 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
2f2f4251
M
675}
676
677static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
678 struct hda_codec *codec,
c8b6bf9b 679 struct snd_pcm_substream *substream)
2f2f4251
M
680{
681 struct sigmatel_spec *spec = codec->spec;
682 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
683}
684
dabbed6f
M
685/*
686 * Digital playback callbacks
687 */
688static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
689 struct hda_codec *codec,
c8b6bf9b 690 struct snd_pcm_substream *substream)
dabbed6f
M
691{
692 struct sigmatel_spec *spec = codec->spec;
693 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
694}
695
696static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
697 struct hda_codec *codec,
c8b6bf9b 698 struct snd_pcm_substream *substream)
dabbed6f
M
699{
700 struct sigmatel_spec *spec = codec->spec;
701 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
702}
703
704
2f2f4251
M
705/*
706 * Analog capture callbacks
707 */
708static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
709 struct hda_codec *codec,
710 unsigned int stream_tag,
711 unsigned int format,
c8b6bf9b 712 struct snd_pcm_substream *substream)
2f2f4251
M
713{
714 struct sigmatel_spec *spec = codec->spec;
715
716 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
717 stream_tag, 0, format);
718 return 0;
719}
720
721static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
722 struct hda_codec *codec,
c8b6bf9b 723 struct snd_pcm_substream *substream)
2f2f4251
M
724{
725 struct sigmatel_spec *spec = codec->spec;
726
727 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 0, 0, 0);
728 return 0;
729}
730
dabbed6f
M
731static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
732 .substreams = 1,
733 .channels_min = 2,
734 .channels_max = 2,
735 /* NID is set in stac92xx_build_pcms */
736 .ops = {
737 .open = stac92xx_dig_playback_pcm_open,
738 .close = stac92xx_dig_playback_pcm_close
739 },
740};
741
742static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
743 .substreams = 1,
744 .channels_min = 2,
745 .channels_max = 2,
746 /* NID is set in stac92xx_build_pcms */
747};
748
2f2f4251
M
749static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
750 .substreams = 1,
751 .channels_min = 2,
c7d4b2fa 752 .channels_max = 8,
2f2f4251
M
753 .nid = 0x02, /* NID to query formats and rates */
754 .ops = {
755 .open = stac92xx_playback_pcm_open,
756 .prepare = stac92xx_playback_pcm_prepare,
757 .cleanup = stac92xx_playback_pcm_cleanup
758 },
759};
760
3cc08dc6
MP
761static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
762 .substreams = 1,
763 .channels_min = 2,
764 .channels_max = 2,
765 .nid = 0x06, /* NID to query formats and rates */
766 .ops = {
767 .open = stac92xx_playback_pcm_open,
768 .prepare = stac92xx_playback_pcm_prepare,
769 .cleanup = stac92xx_playback_pcm_cleanup
770 },
771};
772
2f2f4251
M
773static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
774 .substreams = 2,
775 .channels_min = 2,
776 .channels_max = 2,
3cc08dc6 777 /* NID is set in stac92xx_build_pcms */
2f2f4251
M
778 .ops = {
779 .prepare = stac92xx_capture_pcm_prepare,
780 .cleanup = stac92xx_capture_pcm_cleanup
781 },
782};
783
784static int stac92xx_build_pcms(struct hda_codec *codec)
785{
786 struct sigmatel_spec *spec = codec->spec;
787 struct hda_pcm *info = spec->pcm_rec;
788
789 codec->num_pcms = 1;
790 codec->pcm_info = info;
791
c7d4b2fa 792 info->name = "STAC92xx Analog";
2f2f4251 793 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
2f2f4251 794 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
3cc08dc6
MP
795 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
796
797 if (spec->alt_switch) {
798 codec->num_pcms++;
799 info++;
800 info->name = "STAC92xx Analog Alt";
801 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
802 }
2f2f4251 803
dabbed6f
M
804 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
805 codec->num_pcms++;
806 info++;
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;
811 }
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;
815 }
816 }
817
2f2f4251
M
818 return 0;
819}
820
c960a03b
TI
821static unsigned int stac92xx_get_vref(struct hda_codec *codec, hda_nid_t nid)
822{
823 unsigned int pincap = snd_hda_param_read(codec, nid,
824 AC_PAR_PIN_CAP);
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;
834 return 0;
835}
836
403d1944
MP
837static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
838
839{
840 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
841}
842
843static int stac92xx_io_switch_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
844{
845 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
846 uinfo->count = 1;
847 uinfo->value.integer.min = 0;
848 uinfo->value.integer.max = 1;
849 return 0;
850}
851
852static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
853{
854 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
855 struct sigmatel_spec *spec = codec->spec;
856 int io_idx = kcontrol-> private_value & 0xff;
857
858 ucontrol->value.integer.value[0] = spec->io_switch[io_idx];
859 return 0;
860}
861
862static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
863{
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];
869
870 spec->io_switch[io_idx] = val;
871
872 if (val)
873 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
c960a03b
TI
874 else {
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);
879 }
403d1944
MP
880 return 1;
881}
882
883#define STAC_CODEC_IO_SWITCH(xname, xpval) \
884 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
885 .name = xname, \
886 .index = 0, \
887 .info = stac92xx_io_switch_info, \
888 .get = stac92xx_io_switch_get, \
889 .put = stac92xx_io_switch_put, \
890 .private_value = xpval, \
891 }
892
893
c7d4b2fa
M
894enum {
895 STAC_CTL_WIDGET_VOL,
896 STAC_CTL_WIDGET_MUTE,
403d1944 897 STAC_CTL_WIDGET_IO_SWITCH,
c7d4b2fa
M
898};
899
c8b6bf9b 900static struct snd_kcontrol_new stac92xx_control_templates[] = {
c7d4b2fa
M
901 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
902 HDA_CODEC_MUTE(NULL, 0, 0, 0),
403d1944 903 STAC_CODEC_IO_SWITCH(NULL, 0),
c7d4b2fa
M
904};
905
906/* add dynamic controls */
907static int stac92xx_add_control(struct sigmatel_spec *spec, int type, const char *name, unsigned long val)
908{
c8b6bf9b 909 struct snd_kcontrol_new *knew;
c7d4b2fa
M
910
911 if (spec->num_kctl_used >= spec->num_kctl_alloc) {
912 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
913
914 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */
915 if (! knew)
916 return -ENOMEM;
917 if (spec->kctl_alloc) {
918 memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
919 kfree(spec->kctl_alloc);
920 }
921 spec->kctl_alloc = knew;
922 spec->num_kctl_alloc = num;
923 }
924
925 knew = &spec->kctl_alloc[spec->num_kctl_used];
926 *knew = stac92xx_control_templates[type];
82fe0c58 927 knew->name = kstrdup(name, GFP_KERNEL);
c7d4b2fa
M
928 if (! knew->name)
929 return -ENOMEM;
930 knew->private_value = val;
931 spec->num_kctl_used++;
932 return 0;
933}
934
403d1944
MP
935/* flag inputs as additional dynamic lineouts */
936static int stac92xx_add_dyn_out_pins(struct hda_codec *codec, struct auto_pin_cfg *cfg)
937{
938 struct sigmatel_spec *spec = codec->spec;
939
940 switch (cfg->line_outs) {
941 case 3:
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;
946 cfg->line_outs++;
947 }
948 break;
949 case 2:
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;
954 cfg->line_outs++;
955 }
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;
959 cfg->line_outs++;
960 }
961 break;
962 case 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;
967 cfg->line_outs++;
968 }
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;
972 cfg->line_outs++;
973 }
974 break;
975 }
976
977 return 0;
978}
979
3cc08dc6
MP
980/*
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.
984 *
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.
989 */
c7d4b2fa 990/* fill in the dac_nids table from the parsed pin configuration */
19039bd0
TI
991static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec,
992 const struct auto_pin_cfg *cfg)
c7d4b2fa
M
993{
994 struct sigmatel_spec *spec = codec->spec;
995 hda_nid_t nid;
996 int i;
997
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;
1003 }
1004
82bc955f 1005 spec->multiout.num_dacs = cfg->line_outs;
c7d4b2fa
M
1006
1007 return 0;
1008}
1009
eb06ed8f
TI
1010/* create volume control/switch for the given prefx type */
1011static int create_controls(struct sigmatel_spec *spec, const char *pfx, hda_nid_t nid, int chs)
1012{
1013 char name[32];
1014 int err;
1015
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));
1019 if (err < 0)
1020 return err;
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));
1024 if (err < 0)
1025 return err;
1026 return 0;
1027}
1028
c7d4b2fa 1029/* add playback controls from the parsed DAC table */
19039bd0
TI
1030static int stac92xx_auto_create_multi_out_ctls(struct sigmatel_spec *spec,
1031 const struct auto_pin_cfg *cfg)
c7d4b2fa 1032{
19039bd0
TI
1033 static const char *chname[4] = {
1034 "Front", "Surround", NULL /*CLFE*/, "Side"
1035 };
c7d4b2fa
M
1036 hda_nid_t nid;
1037 int i, err;
1038
1039 for (i = 0; i < cfg->line_outs; i++) {
403d1944 1040 if (!spec->multiout.dac_nids[i])
c7d4b2fa
M
1041 continue;
1042
1043 nid = spec->multiout.dac_nids[i];
1044
1045 if (i == 2) {
1046 /* Center/LFE */
eb06ed8f
TI
1047 err = create_controls(spec, "Center", nid, 1);
1048 if (err < 0)
c7d4b2fa 1049 return err;
eb06ed8f
TI
1050 err = create_controls(spec, "LFE", nid, 2);
1051 if (err < 0)
c7d4b2fa
M
1052 return err;
1053 } else {
eb06ed8f
TI
1054 err = create_controls(spec, chname[i], nid, 3);
1055 if (err < 0)
c7d4b2fa
M
1056 return err;
1057 }
1058 }
1059
403d1944
MP
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)
1062 return err;
1063
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)
1066 return err;
1067
c7d4b2fa
M
1068 return 0;
1069}
1070
eb06ed8f 1071static int check_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
c7d4b2fa 1072{
eb06ed8f 1073 int i;
c7d4b2fa 1074
eb06ed8f
TI
1075 for (i = 0; i < spec->multiout.num_dacs; i++) {
1076 if (spec->multiout.dac_nids[i] == nid)
1077 return 1;
1078 }
1079 if (spec->multiout.hp_nid == nid)
1080 return 1;
1081 return 0;
1082}
c7d4b2fa 1083
eb06ed8f
TI
1084static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
1085{
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);
1090 return 1;
1091 } else {
1092 spec->multiout.dac_nids[spec->multiout.num_dacs] = nid;
1093 spec->multiout.num_dacs++;
1094 }
1095 return 0;
1096}
4e55096e 1097
eb06ed8f
TI
1098/* add playback controls for Speaker and HP outputs */
1099static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
1100 struct auto_pin_cfg *cfg)
1101{
1102 struct sigmatel_spec *spec = codec->spec;
1103 hda_nid_t nid;
1104 int i, old_num_dacs, err;
1105
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))
1114 nid = 0;
1115 if (! nid)
c7d4b2fa 1116 continue;
eb06ed8f
TI
1117 add_spec_dacs(spec, nid);
1118 }
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))
1123 nid = 0;
1124 if (check_in_dac_nids(spec, nid))
1125 nid = 0;
1126 if (! nid)
1127 continue;
1128 add_spec_dacs(spec, nid);
c7d4b2fa
M
1129 }
1130
eb06ed8f
TI
1131 for (i = old_num_dacs; i < spec->multiout.num_dacs; i++) {
1132 static const char *pfxs[] = {
1133 "Speaker", "External Speaker", "Speaker2",
1134 };
1135 err = create_controls(spec, pfxs[i - old_num_dacs],
1136 spec->multiout.dac_nids[i], 3);
1137 if (err < 0)
1138 return err;
1139 }
1140 if (spec->multiout.hp_nid) {
1141 const char *pfx;
1142 if (old_num_dacs == spec->multiout.num_dacs)
1143 pfx = "Master";
1144 else
1145 pfx = "Headphone";
1146 err = create_controls(spec, pfx, spec->multiout.hp_nid, 3);
1147 if (err < 0)
1148 return err;
1149 }
c7d4b2fa
M
1150
1151 return 0;
1152}
1153
8b65727b 1154/* labels for dmic mux inputs */
ddc2cec4 1155static const char *stac92xx_dmic_labels[5] = {
8b65727b
MP
1156 "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
1157 "Digital Mic 3", "Digital Mic 4"
1158};
1159
1160/* create playback/capture controls for input pins on dmic capable codecs */
1161static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
1162 const struct auto_pin_cfg *cfg)
1163{
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];
1167 int i, j;
1168
1169 dimux->items[dimux->num_items].label = stac92xx_dmic_labels[0];
1170 dimux->items[dimux->num_items].index = 0;
1171 dimux->num_items++;
1172
1173 for (i = 0; i < spec->num_dmics; i++) {
1174 int index;
1175 int num_cons;
1176 unsigned int def_conf;
1177
1178 def_conf = snd_hda_codec_read(codec,
1179 spec->dmic_nids[i],
1180 0,
1181 AC_VERB_GET_CONFIG_DEFAULT,
1182 0);
1183 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
1184 continue;
1185
1186 num_cons = snd_hda_get_connections(codec,
1187 spec->dmux_nid,
1188 con_lst,
1189 HDA_MAX_NUM_INPUTS);
1190 for (j = 0; j < num_cons; j++)
1191 if (con_lst[j] == spec->dmic_nids[i]) {
1192 index = j;
1193 goto found;
1194 }
1195 continue;
1196found:
1197 dimux->items[dimux->num_items].label =
1198 stac92xx_dmic_labels[dimux->num_items];
1199 dimux->items[dimux->num_items].index = index;
1200 dimux->num_items++;
1201 }
1202
1203 return 0;
1204}
1205
c7d4b2fa
M
1206/* create playback/capture controls for input pins */
1207static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
1208{
1209 struct sigmatel_spec *spec = codec->spec;
c7d4b2fa
M
1210 struct hda_input_mux *imux = &spec->private_imux;
1211 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
1212 int i, j, k;
1213
1214 for (i = 0; i < AUTO_PIN_LAST; i++) {
314634bc
TI
1215 int index;
1216
1217 if (!cfg->input_pins[i])
1218 continue;
1219 index = -1;
1220 for (j = 0; j < spec->num_muxes; j++) {
1221 int num_cons;
1222 num_cons = snd_hda_get_connections(codec,
1223 spec->mux_nids[j],
1224 con_lst,
1225 HDA_MAX_NUM_INPUTS);
1226 for (k = 0; k < num_cons; k++)
1227 if (con_lst[k] == cfg->input_pins[i]) {
1228 index = k;
1229 goto found;
1230 }
c7d4b2fa 1231 }
314634bc
TI
1232 continue;
1233 found:
1234 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
1235 imux->items[imux->num_items].index = index;
1236 imux->num_items++;
c7d4b2fa
M
1237 }
1238
62fe78e9
SR
1239 if (imux->num_items == 1) {
1240 /*
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.
1244 */
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);
1249 }
1250 }
1251
c7d4b2fa
M
1252 return 0;
1253}
1254
c7d4b2fa
M
1255static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
1256{
1257 struct sigmatel_spec *spec = codec->spec;
1258 int i;
1259
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);
1263 }
1264}
1265
1266static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
1267{
1268 struct sigmatel_spec *spec = codec->spec;
eb06ed8f 1269 int i;
c7d4b2fa 1270
eb06ed8f
TI
1271 for (i = 0; i < spec->autocfg.hp_outs; i++) {
1272 hda_nid_t pin;
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);
1276 }
1277 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
1278 hda_nid_t pin;
1279 pin = spec->autocfg.speaker_pins[i];
1280 if (pin) /* connect to front */
1281 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
1282 }
c7d4b2fa
M
1283}
1284
3cc08dc6 1285static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out, hda_nid_t dig_in)
c7d4b2fa
M
1286{
1287 struct sigmatel_spec *spec = codec->spec;
1288 int err;
1289
8b65727b
MP
1290 if ((err = snd_hda_parse_pin_def_config(codec,
1291 &spec->autocfg,
1292 spec->dmic_nids)) < 0)
c7d4b2fa 1293 return err;
82bc955f 1294 if (! spec->autocfg.line_outs)
869264c4 1295 return 0; /* can't find valid pin config */
19039bd0 1296
403d1944
MP
1297 if ((err = stac92xx_add_dyn_out_pins(codec, &spec->autocfg)) < 0)
1298 return err;
19039bd0
TI
1299 if (spec->multiout.num_dacs == 0)
1300 if ((err = stac92xx_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
1301 return err;
c7d4b2fa
M
1302
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)
1306 return err;
1307
8b65727b
MP
1308 if (spec->num_dmics > 0)
1309 if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
1310 &spec->autocfg)) < 0)
1311 return err;
1312
c7d4b2fa 1313 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
403d1944 1314 if (spec->multiout.max_channels > 2)
c7d4b2fa 1315 spec->surr_switch = 1;
c7d4b2fa 1316
82bc955f 1317 if (spec->autocfg.dig_out_pin)
3cc08dc6 1318 spec->multiout.dig_out_nid = dig_out;
82bc955f 1319 if (spec->autocfg.dig_in_pin)
3cc08dc6 1320 spec->dig_in_nid = dig_in;
c7d4b2fa
M
1321
1322 if (spec->kctl_alloc)
1323 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
1324
1325 spec->input_mux = &spec->private_imux;
8b65727b 1326 spec->dinput_mux = &spec->private_dimux;
c7d4b2fa
M
1327
1328 return 1;
1329}
1330
82bc955f
TI
1331/* add playback controls for HP output */
1332static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
1333 struct auto_pin_cfg *cfg)
1334{
1335 struct sigmatel_spec *spec = codec->spec;
eb06ed8f 1336 hda_nid_t pin = cfg->hp_pins[0];
82bc955f
TI
1337 unsigned int wid_caps;
1338
1339 if (! pin)
1340 return 0;
1341
1342 wid_caps = get_wcaps(codec, pin);
505cb341 1343 if (wid_caps & AC_WCAP_UNSOL_CAP)
82bc955f 1344 spec->hp_detect = 1;
82bc955f
TI
1345
1346 return 0;
1347}
1348
160ea0dc
RF
1349/* add playback controls for LFE output */
1350static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
1351 struct auto_pin_cfg *cfg)
1352{
1353 struct sigmatel_spec *spec = codec->spec;
1354 int err;
1355 hda_nid_t lfe_pin = 0x0;
1356 int i;
1357
1358 /*
1359 * search speaker outs and line outs for a mono speaker pin
1360 * with an amp. If one is found, add LFE controls
1361 * for it.
1362 */
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 */
1369 lfe_pin = pin;
1370 }
1371
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];
1376 unsigned long cfg;
1377 cfg = snd_hda_codec_read(codec, pin, 0,
1378 AC_VERB_GET_CONFIG_DEFAULT,
1379 0x00);
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,
1385 must be lfe */
1386 lfe_pin = pin;
1387 }
1388 }
1389 }
1390
1391 if (lfe_pin) {
eb06ed8f 1392 err = create_controls(spec, "LFE", lfe_pin, 1);
160ea0dc
RF
1393 if (err < 0)
1394 return err;
1395 }
1396
1397 return 0;
1398}
1399
c7d4b2fa
M
1400static int stac9200_parse_auto_config(struct hda_codec *codec)
1401{
1402 struct sigmatel_spec *spec = codec->spec;
1403 int err;
1404
df694daa 1405 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
c7d4b2fa
M
1406 return err;
1407
1408 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
1409 return err;
1410
82bc955f
TI
1411 if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
1412 return err;
1413
160ea0dc
RF
1414 if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
1415 return err;
1416
82bc955f 1417 if (spec->autocfg.dig_out_pin)
c7d4b2fa 1418 spec->multiout.dig_out_nid = 0x05;
82bc955f 1419 if (spec->autocfg.dig_in_pin)
c7d4b2fa 1420 spec->dig_in_nid = 0x04;
c7d4b2fa
M
1421
1422 if (spec->kctl_alloc)
1423 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
1424
1425 spec->input_mux = &spec->private_imux;
8b65727b 1426 spec->dinput_mux = &spec->private_dimux;
c7d4b2fa
M
1427
1428 return 1;
1429}
1430
62fe78e9
SR
1431/*
1432 * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
1433 * funky external mute control using GPIO pins.
1434 */
1435
1436static void stac922x_gpio_mute(struct hda_codec *codec, int pin, int muted)
1437{
1438 unsigned int gpiostate, gpiomask, gpiodir;
1439
1440 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
1441 AC_VERB_GET_GPIO_DATA, 0);
1442
1443 if (!muted)
1444 gpiostate |= (1 << pin);
1445 else
1446 gpiostate &= ~(1 << pin);
1447
1448 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
1449 AC_VERB_GET_GPIO_MASK, 0);
1450 gpiomask |= (1 << pin);
1451
1452 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
1453 AC_VERB_GET_GPIO_DIRECTION, 0);
1454 gpiodir |= (1 << pin);
1455
1456 /* AppleHDA seems to do this -- WTF is this verb?? */
1457 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
1458
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);
1463
1464 msleep(1);
1465
1466 snd_hda_codec_write(codec, codec->afg, 0,
1467 AC_VERB_SET_GPIO_DATA, gpiostate);
1468}
1469
314634bc
TI
1470static void enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
1471 unsigned int event)
1472{
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));
1477}
1478
c7d4b2fa
M
1479static int stac92xx_init(struct hda_codec *codec)
1480{
1481 struct sigmatel_spec *spec = codec->spec;
82bc955f
TI
1482 struct auto_pin_cfg *cfg = &spec->autocfg;
1483 int i;
c7d4b2fa 1484
c7d4b2fa
M
1485 snd_hda_sequence_write(codec, spec->init);
1486
82bc955f
TI
1487 /* set up pins */
1488 if (spec->hp_detect) {
505cb341 1489 /* Enable unsolicited responses on the HP widget */
eb06ed8f 1490 for (i = 0; i < cfg->hp_outs; i++)
314634bc
TI
1491 enable_pin_detect(codec, cfg->hp_pins[i],
1492 STAC_HP_EVENT);
eb995a8c 1493 stac92xx_auto_init_hp_out(codec);
82bc955f
TI
1494 /* fake event to set up pins */
1495 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
1496 } else {
1497 stac92xx_auto_init_multi_out(codec);
1498 stac92xx_auto_init_hp_out(codec);
1499 }
1500 for (i = 0; i < AUTO_PIN_LAST; i++) {
c960a03b
TI
1501 hda_nid_t nid = cfg->input_pins[i];
1502 if (nid) {
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);
1507 }
82bc955f 1508 }
8b65727b
MP
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],
1512 AC_PINCTL_IN_EN);
1513
82bc955f
TI
1514 if (cfg->dig_out_pin)
1515 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pin,
1516 AC_PINCTL_OUT_EN);
1517 if (cfg->dig_in_pin)
1518 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
1519 AC_PINCTL_IN_EN);
1520
62fe78e9
SR
1521 if (spec->gpio_mute) {
1522 stac922x_gpio_mute(codec, 0, 0);
1523 stac922x_gpio_mute(codec, 1, 0);
1524 }
1525
c7d4b2fa
M
1526 return 0;
1527}
1528
2f2f4251
M
1529static void stac92xx_free(struct hda_codec *codec)
1530{
c7d4b2fa
M
1531 struct sigmatel_spec *spec = codec->spec;
1532 int i;
1533
1534 if (! spec)
1535 return;
1536
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);
1541 }
1542
11b44bbd
RF
1543 if (spec->bios_pin_configs)
1544 kfree(spec->bios_pin_configs);
1545
c7d4b2fa 1546 kfree(spec);
2f2f4251
M
1547}
1548
4e55096e
M
1549static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
1550 unsigned int flag)
1551{
1552 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
1553 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
314634bc
TI
1554 if (flag == AC_PINCTL_OUT_EN && (pin_ctl & AC_PINCTL_IN_EN))
1555 return;
4e55096e
M
1556 snd_hda_codec_write(codec, nid, 0,
1557 AC_VERB_SET_PIN_WIDGET_CONTROL,
1558 pin_ctl | flag);
1559}
1560
1561static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
1562 unsigned int flag)
1563{
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,
1568 pin_ctl & ~flag);
1569}
1570
314634bc
TI
1571static int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
1572{
1573 if (!nid)
1574 return 0;
1575 if (snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PIN_SENSE, 0x00)
1576 & (1 << 31))
1577 return 1;
1578 return 0;
1579}
1580
1581static void stac92xx_hp_detect(struct hda_codec *codec, unsigned int res)
4e55096e
M
1582{
1583 struct sigmatel_spec *spec = codec->spec;
1584 struct auto_pin_cfg *cfg = &spec->autocfg;
1585 int i, presence;
1586
eb06ed8f
TI
1587 presence = 0;
1588 for (i = 0; i < cfg->hp_outs; i++) {
314634bc
TI
1589 presence = get_pin_presence(codec, cfg->hp_pins[i]);
1590 if (presence)
1591 break;
eb06ed8f 1592 }
4e55096e
M
1593
1594 if (presence) {
1595 /* disable lineouts, enable hp */
1596 for (i = 0; i < cfg->line_outs; i++)
1597 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
1598 AC_PINCTL_OUT_EN);
eb06ed8f
TI
1599 for (i = 0; i < cfg->speaker_outs; i++)
1600 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
1601 AC_PINCTL_OUT_EN);
4e55096e
M
1602 } else {
1603 /* enable lineouts, disable hp */
1604 for (i = 0; i < cfg->line_outs; i++)
1605 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
1606 AC_PINCTL_OUT_EN);
eb06ed8f
TI
1607 for (i = 0; i < cfg->speaker_outs; i++)
1608 stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
1609 AC_PINCTL_OUT_EN);
4e55096e
M
1610 }
1611}
1612
314634bc
TI
1613static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
1614{
1615 switch (res >> 26) {
1616 case STAC_HP_EVENT:
1617 stac92xx_hp_detect(codec, res);
1618 break;
1619 }
1620}
1621
ff6fdc37
M
1622#ifdef CONFIG_PM
1623static int stac92xx_resume(struct hda_codec *codec)
1624{
1625 struct sigmatel_spec *spec = codec->spec;
1626 int i;
1627
1628 stac92xx_init(codec);
11b44bbd 1629 stac92xx_set_config_regs(codec);
ff6fdc37
M
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);
1636
1637 return 0;
1638}
1639#endif
1640
2f2f4251
M
1641static 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,
4e55096e 1646 .unsol_event = stac92xx_unsol_event,
ff6fdc37
M
1647#ifdef CONFIG_PM
1648 .resume = stac92xx_resume,
1649#endif
2f2f4251
M
1650};
1651
1652static int patch_stac9200(struct hda_codec *codec)
1653{
1654 struct sigmatel_spec *spec;
c7d4b2fa 1655 int err;
2f2f4251 1656
e560d8d8 1657 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2f2f4251
M
1658 if (spec == NULL)
1659 return -ENOMEM;
1660
1661 codec->spec = spec;
11b44bbd
RF
1662 spec->num_pins = 8;
1663 spec->pin_nids = stac9200_pin_nids;
f5fcc13c
TI
1664 spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS,
1665 stac9200_models,
1666 stac9200_cfg_tbl);
11b44bbd
RF
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);
1670 if (err < 0) {
1671 stac92xx_free(codec);
1672 return err;
1673 }
1674 spec->pin_configs = spec->bios_pin_configs;
1675 } else {
403d1944
MP
1676 spec->pin_configs = stac9200_brd_tbl[spec->board_config];
1677 stac92xx_set_config_regs(codec);
1678 }
2f2f4251
M
1679
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;
dabbed6f 1685 spec->num_muxes = 1;
8b65727b 1686 spec->num_dmics = 0;
c7d4b2fa
M
1687
1688 spec->init = stac9200_core_init;
2f2f4251 1689 spec->mixer = stac9200_mixer;
c7d4b2fa
M
1690
1691 err = stac9200_parse_auto_config(codec);
1692 if (err < 0) {
1693 stac92xx_free(codec);
1694 return err;
1695 }
2f2f4251
M
1696
1697 codec->patch_ops = stac92xx_patch_ops;
1698
1699 return 0;
1700}
1701
1702static int patch_stac922x(struct hda_codec *codec)
1703{
1704 struct sigmatel_spec *spec;
c7d4b2fa 1705 int err;
2f2f4251 1706
e560d8d8 1707 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2f2f4251
M
1708 if (spec == NULL)
1709 return -ENOMEM;
1710
1711 codec->spec = spec;
11b44bbd
RF
1712 spec->num_pins = 10;
1713 spec->pin_nids = stac922x_pin_nids;
f5fcc13c
TI
1714 spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS,
1715 stac922x_models,
1716 stac922x_cfg_tbl);
11b44bbd
RF
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);
1721 if (err < 0) {
1722 stac92xx_free(codec);
1723 return err;
1724 }
1725 spec->pin_configs = spec->bios_pin_configs;
1726 } else if (stac922x_brd_tbl[spec->board_config] != NULL) {
403d1944
MP
1727 spec->pin_configs = stac922x_brd_tbl[spec->board_config];
1728 stac92xx_set_config_regs(codec);
1729 }
2f2f4251 1730
c7d4b2fa
M
1731 spec->adc_nids = stac922x_adc_nids;
1732 spec->mux_nids = stac922x_mux_nids;
1733 spec->num_muxes = 2;
8b65727b 1734 spec->num_dmics = 0;
c7d4b2fa
M
1735
1736 spec->init = stac922x_core_init;
2f2f4251 1737 spec->mixer = stac922x_mixer;
c7d4b2fa
M
1738
1739 spec->multiout.dac_nids = spec->dac_nids;
19039bd0 1740
3cc08dc6
MP
1741 err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
1742 if (err < 0) {
1743 stac92xx_free(codec);
1744 return err;
1745 }
1746
62fe78e9
SR
1747 if (spec->board_config == STAC_MACMINI)
1748 spec->gpio_mute = 1;
1749
3cc08dc6
MP
1750 codec->patch_ops = stac92xx_patch_ops;
1751
1752 return 0;
1753}
1754
1755static int patch_stac927x(struct hda_codec *codec)
1756{
1757 struct sigmatel_spec *spec;
1758 int err;
1759
1760 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1761 if (spec == NULL)
1762 return -ENOMEM;
1763
1764 codec->spec = spec;
11b44bbd
RF
1765 spec->num_pins = 14;
1766 spec->pin_nids = stac927x_pin_nids;
f5fcc13c
TI
1767 spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS,
1768 stac927x_models,
1769 stac927x_cfg_tbl);
11b44bbd 1770 if (spec->board_config < 0) {
3cc08dc6 1771 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC927x, using BIOS defaults\n");
11b44bbd
RF
1772 err = stac92xx_save_bios_config_regs(codec);
1773 if (err < 0) {
1774 stac92xx_free(codec);
1775 return err;
1776 }
1777 spec->pin_configs = spec->bios_pin_configs;
1778 } else if (stac927x_brd_tbl[spec->board_config] != NULL) {
3cc08dc6
MP
1779 spec->pin_configs = stac927x_brd_tbl[spec->board_config];
1780 stac92xx_set_config_regs(codec);
1781 }
1782
81d3dbde 1783 switch (spec->board_config) {
93ed1503 1784 case STAC_D965_3ST:
81d3dbde
TD
1785 spec->adc_nids = stac927x_adc_nids;
1786 spec->mux_nids = stac927x_mux_nids;
1787 spec->num_muxes = 3;
8b65727b 1788 spec->num_dmics = 0;
93ed1503 1789 spec->init = d965_core_init;
81d3dbde
TD
1790 spec->mixer = stac9227_mixer;
1791 break;
93ed1503
TD
1792 case STAC_D965_5ST:
1793 spec->adc_nids = stac927x_adc_nids;
1794 spec->mux_nids = stac927x_mux_nids;
1795 spec->num_muxes = 3;
8b65727b 1796 spec->num_dmics = 0;
93ed1503 1797 spec->init = d965_core_init;
81d3dbde
TD
1798 spec->mixer = stac9227_mixer;
1799 break;
1800 default:
1801 spec->adc_nids = stac927x_adc_nids;
1802 spec->mux_nids = stac927x_mux_nids;
1803 spec->num_muxes = 3;
8b65727b 1804 spec->num_dmics = 0;
81d3dbde
TD
1805 spec->init = stac927x_core_init;
1806 spec->mixer = stac927x_mixer;
1807 }
3cc08dc6
MP
1808
1809 spec->multiout.dac_nids = spec->dac_nids;
1810
1811 err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
c7d4b2fa
M
1812 if (err < 0) {
1813 stac92xx_free(codec);
1814 return err;
1815 }
2f2f4251
M
1816
1817 codec->patch_ops = stac92xx_patch_ops;
1818
1819 return 0;
1820}
1821
f3302a59
MP
1822static int patch_stac9205(struct hda_codec *codec)
1823{
1824 struct sigmatel_spec *spec;
1825 int err;
1826
1827 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1828 if (spec == NULL)
1829 return -ENOMEM;
1830
1831 codec->spec = spec;
11b44bbd
RF
1832 spec->num_pins = 14;
1833 spec->pin_nids = stac9205_pin_nids;
f5fcc13c
TI
1834 spec->board_config = snd_hda_check_board_config(codec, STAC_9205_MODELS,
1835 stac9205_models,
1836 stac9205_cfg_tbl);
11b44bbd
RF
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);
1840 if (err < 0) {
1841 stac92xx_free(codec);
1842 return err;
1843 }
1844 spec->pin_configs = spec->bios_pin_configs;
1845 } else {
f3302a59
MP
1846 spec->pin_configs = stac9205_brd_tbl[spec->board_config];
1847 stac92xx_set_config_regs(codec);
1848 }
1849
1850 spec->adc_nids = stac9205_adc_nids;
1851 spec->mux_nids = stac9205_mux_nids;
8b65727b
MP
1852 spec->num_muxes = 2;
1853 spec->dmic_nids = stac9205_dmic_nids;
1854 spec->num_dmics = 2;
1855 spec->dmux_nid = 0x1d;
f3302a59
MP
1856
1857 spec->init = stac9205_core_init;
1858 spec->mixer = stac9205_mixer;
1859
1860 spec->multiout.dac_nids = spec->dac_nids;
1861
1862 err = stac92xx_parse_auto_config(codec, 0x1f, 0x20);
1863 if (err < 0) {
1864 stac92xx_free(codec);
1865 return err;
1866 }
1867
1868 codec->patch_ops = stac92xx_patch_ops;
1869
1870 return 0;
1871}
1872
db064e50 1873/*
6d859065 1874 * STAC9872 hack
db064e50
TI
1875 */
1876
99ccc560 1877/* static config for Sony VAIO FE550G and Sony VAIO AR */
db064e50
TI
1878static hda_nid_t vaio_dacs[] = { 0x2 };
1879#define VAIO_HP_DAC 0x5
1880static hda_nid_t vaio_adcs[] = { 0x8 /*,0x6*/ };
1881static hda_nid_t vaio_mux_nids[] = { 0x15 };
1882
1883static struct hda_input_mux vaio_mux = {
1884 .num_items = 2,
1885 .items = {
d773781c
TI
1886 /* { "HP", 0x0 }, */
1887 { "Line", 0x1 },
db064e50
TI
1888 { "Mic", 0x2 },
1889 { "PCM", 0x3 },
1890 }
1891};
1892
1893static 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 */
1905 {}
1906};
1907
6d859065
GM
1908static 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 */
1922 {}
1923};
1924
db064e50
TI
1925/* bind volumes of both NID 0x02 and 0x05 */
1926static int vaio_master_vol_put(struct snd_kcontrol *kcontrol,
1927 struct snd_ctl_elem_value *ucontrol)
1928{
1929 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1930 long *valp = ucontrol->value.integer.value;
1931 int change;
1932
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);
1941 return change;
1942}
1943
1944/* bind volumes of both NID 0x02 and 0x05 */
1945static int vaio_master_sw_put(struct snd_kcontrol *kcontrol,
1946 struct snd_ctl_elem_value *ucontrol)
1947{
1948 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1949 long *valp = ucontrol->value.integer.value;
1950 int change;
1951
1952 change = snd_hda_codec_amp_update(codec, 0x02, 0, HDA_OUTPUT, 0,
a9393d70 1953 0x80, (valp[0] ? 0 : 0x80));
db064e50 1954 change |= snd_hda_codec_amp_update(codec, 0x02, 1, HDA_OUTPUT, 0,
a9393d70 1955 0x80, (valp[1] ? 0 : 0x80));
db064e50 1956 snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
a9393d70 1957 0x80, (valp[0] ? 0 : 0x80));
db064e50 1958 snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
a9393d70 1959 0x80, (valp[1] ? 0 : 0x80));
db064e50
TI
1960 return change;
1961}
1962
1963static struct snd_kcontrol_new vaio_mixer[] = {
1964 {
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,
c2566524 1970 .tlv = { .c = snd_hda_mixer_amp_tlv },
db064e50
TI
1971 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
1972 },
1973 {
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),
1980 },
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),
1984 {
1985 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1986 .name = "Capture Source",
1987 .count = 1,
1988 .info = stac92xx_mux_enum_info,
1989 .get = stac92xx_mux_enum_get,
1990 .put = stac92xx_mux_enum_put,
1991 },
1992 {}
1993};
1994
6d859065
GM
1995static struct snd_kcontrol_new vaio_ar_mixer[] = {
1996 {
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),
2003 },
2004 {
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),
2011 },
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),*/
2017 {
2018 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2019 .name = "Capture Source",
2020 .count = 1,
2021 .info = stac92xx_mux_enum_info,
2022 .get = stac92xx_mux_enum_get,
2023 .put = stac92xx_mux_enum_put,
2024 },
2025 {}
2026};
2027
2028static struct hda_codec_ops stac9872_patch_ops = {
db064e50
TI
2029 .build_controls = stac92xx_build_controls,
2030 .build_pcms = stac92xx_build_pcms,
2031 .init = stac92xx_init,
2032 .free = stac92xx_free,
2033#ifdef CONFIG_PM
2034 .resume = stac92xx_resume,
2035#endif
2036};
2037
6d859065
GM
2038enum { /* FE and SZ series. id=0x83847661 and subsys=0x104D0700 or 104D1000. */
2039 CXD9872RD_VAIO,
2040 /* Unknown. id=0x83847662 and subsys=0x104D1200 or 104D1000. */
2041 STAC9872AK_VAIO,
2042 /* Unknown. id=0x83847661 and subsys=0x104D1200. */
2043 STAC9872K_VAIO,
2044 /* AR Series. id=0x83847664 and subsys=104D1300 */
f5fcc13c
TI
2045 CXD9872AKD_VAIO,
2046 STAC_9872_MODELS,
2047};
2048
2049static const char *stac9872_models[STAC_9872_MODELS] = {
2050 [CXD9872RD_VAIO] = "vaio",
2051 [CXD9872AKD_VAIO] = "vaio-ar",
2052};
2053
2054static 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),
db064e50
TI
2058 {}
2059};
2060
6d859065 2061static int patch_stac9872(struct hda_codec *codec)
db064e50
TI
2062{
2063 struct sigmatel_spec *spec;
2064 int board_config;
2065
f5fcc13c
TI
2066 board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
2067 stac9872_models,
2068 stac9872_cfg_tbl);
db064e50
TI
2069 if (board_config < 0)
2070 /* unknown config, let generic-parser do its job... */
2071 return snd_hda_parse_generic_codec(codec);
2072
2073 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2074 if (spec == NULL)
2075 return -ENOMEM;
2076
2077 codec->spec = spec;
2078 switch (board_config) {
6d859065
GM
2079 case CXD9872RD_VAIO:
2080 case STAC9872AK_VAIO:
2081 case STAC9872K_VAIO:
db064e50
TI
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;
2092 break;
6d859065
GM
2093
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;
2105 break;
db064e50
TI
2106 }
2107
6d859065 2108 codec->patch_ops = stac9872_patch_ops;
db064e50
TI
2109 return 0;
2110}
2111
2112
2f2f4251
M
2113/*
2114 * patch entries
2115 */
2116struct 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 },
22a27c7f
MP
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 },
3cc08dc6
MP
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 },
6d859065
GM
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.
2143 */
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 },
f3302a59
MP
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 },
2f2f4251
M
2155 {} /* terminator */
2156};
This page took 0.500033 seconds and 5 git commands to generate.