[ALSA] hda-codec - Fix ALC662 auto mode
[GitHub/mt8127/android_kernel_alcatel_ttab.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
8e21c34c
TD
50enum {
51 STAC_925x_REF,
52 STAC_M2_2,
53 STAC_MA6,
2c11f955 54 STAC_PA6,
8e21c34c
TD
55 STAC_925x_MODELS
56};
57
f5fcc13c
TI
58enum {
59 STAC_D945_REF,
60 STAC_D945GTP3,
61 STAC_D945GTP5,
76c08828 62 STAC_922X_DELL,
5d5d3bc3
IZ
63 STAC_INTEL_MAC_V1,
64 STAC_INTEL_MAC_V2,
65 STAC_INTEL_MAC_V3,
66 STAC_INTEL_MAC_V4,
67 STAC_INTEL_MAC_V5,
68 /* for backward compitability */
f5fcc13c 69 STAC_MACMINI,
3fc24d85 70 STAC_MACBOOK,
6f0778d8
NB
71 STAC_MACBOOK_PRO_V1,
72 STAC_MACBOOK_PRO_V2,
f16928fb 73 STAC_IMAC_INTEL,
0dae0f83 74 STAC_IMAC_INTEL_20,
f5fcc13c
TI
75 STAC_922X_MODELS
76};
77
78enum {
79 STAC_D965_REF,
80 STAC_D965_3ST,
81 STAC_D965_5ST,
82 STAC_927X_MODELS
83};
403d1944 84
2f2f4251 85struct sigmatel_spec {
c8b6bf9b 86 struct snd_kcontrol_new *mixers[4];
c7d4b2fa
M
87 unsigned int num_mixers;
88
403d1944 89 int board_config;
c7d4b2fa 90 unsigned int surr_switch: 1;
403d1944
MP
91 unsigned int line_switch: 1;
92 unsigned int mic_switch: 1;
3cc08dc6 93 unsigned int alt_switch: 1;
82bc955f 94 unsigned int hp_detect: 1;
62fe78e9 95 unsigned int gpio_mute: 1;
c7d4b2fa 96
2f2f4251
M
97 /* playback */
98 struct hda_multi_out multiout;
3cc08dc6 99 hda_nid_t dac_nids[5];
2f2f4251
M
100
101 /* capture */
102 hda_nid_t *adc_nids;
2f2f4251 103 unsigned int num_adcs;
dabbed6f
M
104 hda_nid_t *mux_nids;
105 unsigned int num_muxes;
8b65727b
MP
106 hda_nid_t *dmic_nids;
107 unsigned int num_dmics;
108 hda_nid_t dmux_nid;
dabbed6f 109 hda_nid_t dig_in_nid;
2f2f4251 110
2f2f4251
M
111 /* pin widgets */
112 hda_nid_t *pin_nids;
113 unsigned int num_pins;
2f2f4251 114 unsigned int *pin_configs;
11b44bbd 115 unsigned int *bios_pin_configs;
2f2f4251
M
116
117 /* codec specific stuff */
118 struct hda_verb *init;
c8b6bf9b 119 struct snd_kcontrol_new *mixer;
2f2f4251
M
120
121 /* capture source */
8b65727b
MP
122 struct hda_input_mux *dinput_mux;
123 unsigned int cur_dmux;
c7d4b2fa 124 struct hda_input_mux *input_mux;
3cc08dc6 125 unsigned int cur_mux[3];
2f2f4251 126
403d1944
MP
127 /* i/o switches */
128 unsigned int io_switch[2];
2f2f4251 129
c7d4b2fa
M
130 struct hda_pcm pcm_rec[2]; /* PCM information */
131
132 /* dynamic controls and input_mux */
133 struct auto_pin_cfg autocfg;
134 unsigned int num_kctl_alloc, num_kctl_used;
c8b6bf9b 135 struct snd_kcontrol_new *kctl_alloc;
8b65727b 136 struct hda_input_mux private_dimux;
c7d4b2fa 137 struct hda_input_mux private_imux;
2f2f4251
M
138};
139
140static hda_nid_t stac9200_adc_nids[1] = {
141 0x03,
142};
143
144static hda_nid_t stac9200_mux_nids[1] = {
145 0x0c,
146};
147
148static hda_nid_t stac9200_dac_nids[1] = {
149 0x02,
150};
151
8e21c34c
TD
152static hda_nid_t stac925x_adc_nids[1] = {
153 0x03,
154};
155
156static hda_nid_t stac925x_mux_nids[1] = {
157 0x0f,
158};
159
160static hda_nid_t stac925x_dac_nids[1] = {
161 0x02,
162};
163
2c11f955
TD
164static hda_nid_t stac925x_dmic_nids[1] = {
165 0x15,
166};
167
2f2f4251
M
168static hda_nid_t stac922x_adc_nids[2] = {
169 0x06, 0x07,
170};
171
172static hda_nid_t stac922x_mux_nids[2] = {
173 0x12, 0x13,
174};
175
3cc08dc6
MP
176static hda_nid_t stac927x_adc_nids[3] = {
177 0x07, 0x08, 0x09
178};
179
180static hda_nid_t stac927x_mux_nids[3] = {
181 0x15, 0x16, 0x17
182};
183
f3302a59
MP
184static hda_nid_t stac9205_adc_nids[2] = {
185 0x12, 0x13
186};
187
188static hda_nid_t stac9205_mux_nids[2] = {
189 0x19, 0x1a
190};
191
2549413e
TI
192static hda_nid_t stac9205_dmic_nids[2] = {
193 0x17, 0x18,
8b65727b
MP
194};
195
c7d4b2fa 196static hda_nid_t stac9200_pin_nids[8] = {
93ed1503
TD
197 0x08, 0x09, 0x0d, 0x0e,
198 0x0f, 0x10, 0x11, 0x12,
2f2f4251
M
199};
200
8e21c34c
TD
201static hda_nid_t stac925x_pin_nids[8] = {
202 0x07, 0x08, 0x0a, 0x0b,
203 0x0c, 0x0d, 0x10, 0x11,
204};
205
2f2f4251
M
206static hda_nid_t stac922x_pin_nids[10] = {
207 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
208 0x0f, 0x10, 0x11, 0x15, 0x1b,
209};
210
3cc08dc6
MP
211static hda_nid_t stac927x_pin_nids[14] = {
212 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
213 0x0f, 0x10, 0x11, 0x12, 0x13,
214 0x14, 0x21, 0x22, 0x23,
215};
216
f3302a59
MP
217static hda_nid_t stac9205_pin_nids[12] = {
218 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
219 0x0f, 0x14, 0x16, 0x17, 0x18,
220 0x21, 0x22,
221
222};
223
8b65727b
MP
224static int stac92xx_dmux_enum_info(struct snd_kcontrol *kcontrol,
225 struct snd_ctl_elem_info *uinfo)
226{
227 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
228 struct sigmatel_spec *spec = codec->spec;
229 return snd_hda_input_mux_info(spec->dinput_mux, uinfo);
230}
231
232static int stac92xx_dmux_enum_get(struct snd_kcontrol *kcontrol,
233 struct snd_ctl_elem_value *ucontrol)
234{
235 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
236 struct sigmatel_spec *spec = codec->spec;
237
238 ucontrol->value.enumerated.item[0] = spec->cur_dmux;
239 return 0;
240}
241
242static int stac92xx_dmux_enum_put(struct snd_kcontrol *kcontrol,
243 struct snd_ctl_elem_value *ucontrol)
244{
245 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
246 struct sigmatel_spec *spec = codec->spec;
247
248 return snd_hda_input_mux_put(codec, spec->dinput_mux, ucontrol,
249 spec->dmux_nid, &spec->cur_dmux);
250}
251
c8b6bf9b 252static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
2f2f4251
M
253{
254 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
255 struct sigmatel_spec *spec = codec->spec;
c7d4b2fa 256 return snd_hda_input_mux_info(spec->input_mux, uinfo);
2f2f4251
M
257}
258
c8b6bf9b 259static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2f2f4251
M
260{
261 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
262 struct sigmatel_spec *spec = codec->spec;
263 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
264
265 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
266 return 0;
267}
268
c8b6bf9b 269static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2f2f4251
M
270{
271 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
272 struct sigmatel_spec *spec = codec->spec;
273 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
274
c7d4b2fa 275 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
2f2f4251
M
276 spec->mux_nids[adc_idx], &spec->cur_mux[adc_idx]);
277}
278
c7d4b2fa 279static struct hda_verb stac9200_core_init[] = {
2f2f4251 280 /* set dac0mux for dac converter */
c7d4b2fa 281 { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
2f2f4251
M
282 {}
283};
284
8e21c34c
TD
285static struct hda_verb stac925x_core_init[] = {
286 /* set dac0mux for dac converter */
287 { 0x06, AC_VERB_SET_CONNECT_SEL, 0x00},
288 {}
289};
290
c7d4b2fa 291static struct hda_verb stac922x_core_init[] = {
2f2f4251 292 /* set master volume and direct control */
c7d4b2fa 293 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
2f2f4251
M
294 {}
295};
296
93ed1503 297static struct hda_verb d965_core_init[] = {
19039bd0 298 /* set master volume and direct control */
93ed1503 299 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
19039bd0
TI
300 /* unmute node 0x1b */
301 { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
302 /* select node 0x03 as DAC */
303 { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
304 {}
305};
306
3cc08dc6
MP
307static struct hda_verb stac927x_core_init[] = {
308 /* set master volume and direct control */
309 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
310 {}
311};
312
f3302a59
MP
313static struct hda_verb stac9205_core_init[] = {
314 /* set master volume and direct control */
315 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
316 {}
317};
318
c8b6bf9b 319static struct snd_kcontrol_new stac9200_mixer[] = {
2f2f4251
M
320 HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
321 HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
322 {
323 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
324 .name = "Input Source",
325 .count = 1,
326 .info = stac92xx_mux_enum_info,
327 .get = stac92xx_mux_enum_get,
328 .put = stac92xx_mux_enum_put,
329 },
330 HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
331 HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
c7d4b2fa 332 HDA_CODEC_VOLUME("Capture Mux Volume", 0x0c, 0, HDA_OUTPUT),
2f2f4251
M
333 { } /* end */
334};
335
8e21c34c
TD
336static struct snd_kcontrol_new stac925x_mixer[] = {
337 HDA_CODEC_VOLUME("Master Playback Volume", 0xe, 0, HDA_OUTPUT),
338 HDA_CODEC_MUTE("Master Playback Switch", 0xe, 0, HDA_OUTPUT),
339 {
340 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
341 .name = "Input Source",
342 .count = 1,
343 .info = stac92xx_mux_enum_info,
344 .get = stac92xx_mux_enum_get,
345 .put = stac92xx_mux_enum_put,
346 },
347 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_OUTPUT),
348 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_OUTPUT),
349 HDA_CODEC_VOLUME("Capture Mux Volume", 0x0f, 0, HDA_OUTPUT),
350 { } /* end */
351};
352
c7d4b2fa 353/* This needs to be generated dynamically based on sequence */
c8b6bf9b 354static struct snd_kcontrol_new stac922x_mixer[] = {
2f2f4251
M
355 {
356 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
357 .name = "Input Source",
358 .count = 1,
359 .info = stac92xx_mux_enum_info,
360 .get = stac92xx_mux_enum_get,
361 .put = stac92xx_mux_enum_put,
362 },
363 HDA_CODEC_VOLUME("Capture Volume", 0x17, 0x0, HDA_INPUT),
0fd1708a 364 HDA_CODEC_MUTE("Capture Switch", 0x17, 0x0, HDA_INPUT),
2f2f4251
M
365 HDA_CODEC_VOLUME("Mux Capture Volume", 0x12, 0x0, HDA_OUTPUT),
366 { } /* end */
367};
368
19039bd0
TI
369/* This needs to be generated dynamically based on sequence */
370static struct snd_kcontrol_new stac9227_mixer[] = {
371 {
372 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
373 .name = "Input Source",
374 .count = 1,
375 .info = stac92xx_mux_enum_info,
376 .get = stac92xx_mux_enum_get,
377 .put = stac92xx_mux_enum_put,
378 },
379 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
380 HDA_CODEC_MUTE("Capture Switch", 0x1b, 0x0, HDA_OUTPUT),
381 { } /* end */
382};
383
d1d985f0 384static struct snd_kcontrol_new stac927x_mixer[] = {
3cc08dc6
MP
385 {
386 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
387 .name = "Input Source",
388 .count = 1,
389 .info = stac92xx_mux_enum_info,
390 .get = stac92xx_mux_enum_get,
391 .put = stac92xx_mux_enum_put,
392 },
393 HDA_CODEC_VOLUME("InMux Capture Volume", 0x15, 0x0, HDA_OUTPUT),
394 HDA_CODEC_VOLUME("InVol Capture Volume", 0x18, 0x0, HDA_INPUT),
395 HDA_CODEC_MUTE("ADCMux Capture Switch", 0x1b, 0x0, HDA_OUTPUT),
396 { } /* end */
397};
398
d1d985f0 399static struct snd_kcontrol_new stac9205_mixer[] = {
8b65727b
MP
400 {
401 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
402 .name = "Digital Input Source",
403 .count = 1,
404 .info = stac92xx_dmux_enum_info,
405 .get = stac92xx_dmux_enum_get,
406 .put = stac92xx_dmux_enum_put,
407 },
f3302a59
MP
408 {
409 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
410 .name = "Input Source",
411 .count = 1,
412 .info = stac92xx_mux_enum_info,
413 .get = stac92xx_mux_enum_get,
414 .put = stac92xx_mux_enum_put,
415 },
416 HDA_CODEC_VOLUME("InMux Capture Volume", 0x19, 0x0, HDA_OUTPUT),
417 HDA_CODEC_VOLUME("InVol Capture Volume", 0x1b, 0x0, HDA_INPUT),
418 HDA_CODEC_MUTE("ADCMux Capture Switch", 0x1d, 0x0, HDA_OUTPUT),
419 { } /* end */
420};
421
2f2f4251
M
422static int stac92xx_build_controls(struct hda_codec *codec)
423{
424 struct sigmatel_spec *spec = codec->spec;
425 int err;
c7d4b2fa 426 int i;
2f2f4251
M
427
428 err = snd_hda_add_new_ctls(codec, spec->mixer);
429 if (err < 0)
430 return err;
c7d4b2fa
M
431
432 for (i = 0; i < spec->num_mixers; i++) {
433 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
434 if (err < 0)
435 return err;
436 }
437
dabbed6f
M
438 if (spec->multiout.dig_out_nid) {
439 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
440 if (err < 0)
441 return err;
442 }
443 if (spec->dig_in_nid) {
444 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
445 if (err < 0)
446 return err;
447 }
448 return 0;
2f2f4251
M
449}
450
403d1944 451static unsigned int ref9200_pin_configs[8] = {
dabbed6f 452 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
2f2f4251
M
453 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
454};
455
f5fcc13c
TI
456static unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
457 [STAC_REF] = ref9200_pin_configs,
403d1944
MP
458};
459
f5fcc13c
TI
460static const char *stac9200_models[STAC_9200_MODELS] = {
461 [STAC_REF] = "ref",
462};
463
464static struct snd_pci_quirk stac9200_cfg_tbl[] = {
465 /* SigmaTel reference board */
466 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
467 "DFI LanParty", STAC_REF),
e7377071 468 /* Dell laptops have BIOS problem */
f5fcc13c
TI
469 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01b5,
470 "Dell Inspiron 630m", STAC_REF),
471 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c2,
472 "Dell Latitude D620", STAC_REF),
473 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cb,
474 "Dell Latitude 120L", STAC_REF),
877b866d
CT
475 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cc,
476 "Dell Latitude D820", STAC_REF),
46f02ca3
MN
477 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cd,
478 "Dell Inspiron E1705/9400", STAC_REF),
479 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ce,
480 "Dell XPS M1710", STAC_REF),
f0f96745
TI
481 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cf,
482 "Dell Precision M90", STAC_REF),
8286c53e
DC
483 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d6,
484 "unknown Dell", STAC_REF),
49c605db
TD
485 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d8,
486 "Dell Inspiron 640m", STAC_REF),
487 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f5,
488 "Dell Inspiron 1501", STAC_REF),
489
490 /* Panasonic */
491 SND_PCI_QUIRK(0x10f7, 0x8338, "Panasonic CF-74", STAC_REF),
492
403d1944
MP
493 {} /* terminator */
494};
495
8e21c34c
TD
496static unsigned int ref925x_pin_configs[8] = {
497 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
498 0x90a70320, 0x02214210, 0x400003f1, 0x9033032e,
499};
500
501static unsigned int stac925x_MA6_pin_configs[8] = {
502 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
503 0x90a70320, 0x90100211, 0x400003f1, 0x9033032e,
504};
505
2c11f955
TD
506static unsigned int stac925x_PA6_pin_configs[8] = {
507 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
508 0x50a103f0, 0x90100211, 0x400003f1, 0x9033032e,
509};
510
8e21c34c 511static unsigned int stac925xM2_2_pin_configs[8] = {
7353e14d
SL
512 0x40c003f3, 0x424503f2, 0x04180011, 0x02a19020,
513 0x50a103f0, 0x90100212, 0x400003f1, 0x9033032e,
8e21c34c
TD
514};
515
516static unsigned int *stac925x_brd_tbl[STAC_925x_MODELS] = {
517 [STAC_REF] = ref925x_pin_configs,
518 [STAC_M2_2] = stac925xM2_2_pin_configs,
519 [STAC_MA6] = stac925x_MA6_pin_configs,
2c11f955 520 [STAC_PA6] = stac925x_PA6_pin_configs,
8e21c34c
TD
521};
522
523static const char *stac925x_models[STAC_925x_MODELS] = {
524 [STAC_REF] = "ref",
525 [STAC_M2_2] = "m2-2",
526 [STAC_MA6] = "m6",
2c11f955 527 [STAC_PA6] = "pa6",
8e21c34c
TD
528};
529
530static struct snd_pci_quirk stac925x_cfg_tbl[] = {
531 /* SigmaTel reference board */
532 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, "DFI LanParty", STAC_REF),
2c11f955 533 SND_PCI_QUIRK(0x8384, 0x7632, "Stac9202 Reference Board", STAC_REF),
8e21c34c
TD
534 SND_PCI_QUIRK(0x107b, 0x0316, "Gateway M255", STAC_REF),
535 SND_PCI_QUIRK(0x107b, 0x0366, "Gateway MP6954", STAC_REF),
536 SND_PCI_QUIRK(0x107b, 0x0461, "Gateway NX560XL", STAC_MA6),
2c11f955 537 SND_PCI_QUIRK(0x107b, 0x0681, "Gateway NX860", STAC_PA6),
8e21c34c
TD
538 SND_PCI_QUIRK(0x1002, 0x437b, "Gateway MX6453", STAC_M2_2),
539 {} /* terminator */
540};
541
403d1944
MP
542static unsigned int ref922x_pin_configs[10] = {
543 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
544 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
2f2f4251
M
545 0x40000100, 0x40000100,
546};
547
403d1944 548static unsigned int d945gtp3_pin_configs[10] = {
869264c4 549 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
403d1944
MP
550 0x40000100, 0x40000100, 0x40000100, 0x40000100,
551 0x02a19120, 0x40000100,
552};
553
554static unsigned int d945gtp5_pin_configs[10] = {
869264c4
MP
555 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
556 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
403d1944
MP
557 0x02a19320, 0x40000100,
558};
559
5d5d3bc3
IZ
560static unsigned int intel_mac_v1_pin_configs[10] = {
561 0x0121e21f, 0x400000ff, 0x9017e110, 0x400000fd,
562 0x400000fe, 0x0181e020, 0x1145e030, 0x11c5e240,
563 0x400000fc, 0x400000fb,
564};
565
566static unsigned int intel_mac_v2_pin_configs[10] = {
567 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
568 0x400000fe, 0x0181e020, 0x1145e230, 0x500000fa,
569 0x400000fc, 0x400000fb,
6f0778d8
NB
570};
571
5d5d3bc3
IZ
572static unsigned int intel_mac_v3_pin_configs[10] = {
573 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
574 0x400000fe, 0x0181e020, 0x1145e230, 0x11c5e240,
3fc24d85
TI
575 0x400000fc, 0x400000fb,
576};
577
5d5d3bc3
IZ
578static unsigned int intel_mac_v4_pin_configs[10] = {
579 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
580 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
f16928fb
SF
581 0x400000fc, 0x400000fb,
582};
583
5d5d3bc3
IZ
584static unsigned int intel_mac_v5_pin_configs[10] = {
585 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
586 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
587 0x400000fc, 0x400000fb,
0dae0f83
TI
588};
589
76c08828
TI
590static unsigned int stac922x_dell_pin_configs[10] = {
591 0x0221121e, 0x408103ff, 0x02a1123e, 0x90100310,
592 0x408003f1, 0x0221122f, 0x03451340, 0x40c003f2,
593 0x50a003f3, 0x405003f4
594};
595
19039bd0 596static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
f5fcc13c 597 [STAC_D945_REF] = ref922x_pin_configs,
19039bd0
TI
598 [STAC_D945GTP3] = d945gtp3_pin_configs,
599 [STAC_D945GTP5] = d945gtp5_pin_configs,
76c08828 600 [STAC_922X_DELL] = stac922x_dell_pin_configs,
5d5d3bc3
IZ
601 [STAC_INTEL_MAC_V1] = intel_mac_v1_pin_configs,
602 [STAC_INTEL_MAC_V2] = intel_mac_v2_pin_configs,
603 [STAC_INTEL_MAC_V3] = intel_mac_v3_pin_configs,
604 [STAC_INTEL_MAC_V4] = intel_mac_v4_pin_configs,
605 [STAC_INTEL_MAC_V5] = intel_mac_v5_pin_configs,
606 /* for backward compitability */
607 [STAC_MACMINI] = intel_mac_v3_pin_configs,
608 [STAC_MACBOOK] = intel_mac_v5_pin_configs,
609 [STAC_MACBOOK_PRO_V1] = intel_mac_v3_pin_configs,
610 [STAC_MACBOOK_PRO_V2] = intel_mac_v3_pin_configs,
611 [STAC_IMAC_INTEL] = intel_mac_v2_pin_configs,
612 [STAC_IMAC_INTEL_20] = intel_mac_v3_pin_configs,
403d1944
MP
613};
614
f5fcc13c
TI
615static const char *stac922x_models[STAC_922X_MODELS] = {
616 [STAC_D945_REF] = "ref",
617 [STAC_D945GTP5] = "5stack",
618 [STAC_D945GTP3] = "3stack",
76c08828 619 [STAC_922X_DELL] = "dell",
5d5d3bc3
IZ
620 [STAC_INTEL_MAC_V1] = "intel-mac-v1",
621 [STAC_INTEL_MAC_V2] = "intel-mac-v2",
622 [STAC_INTEL_MAC_V3] = "intel-mac-v3",
623 [STAC_INTEL_MAC_V4] = "intel-mac-v4",
624 [STAC_INTEL_MAC_V5] = "intel-mac-v5",
625 /* for backward compitability */
f5fcc13c 626 [STAC_MACMINI] = "macmini",
3fc24d85 627 [STAC_MACBOOK] = "macbook",
6f0778d8
NB
628 [STAC_MACBOOK_PRO_V1] = "macbook-pro-v1",
629 [STAC_MACBOOK_PRO_V2] = "macbook-pro",
f16928fb 630 [STAC_IMAC_INTEL] = "imac-intel",
0dae0f83 631 [STAC_IMAC_INTEL_20] = "imac-intel-20",
f5fcc13c
TI
632};
633
634static struct snd_pci_quirk stac922x_cfg_tbl[] = {
635 /* SigmaTel reference board */
636 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
637 "DFI LanParty", STAC_D945_REF),
638 /* Intel 945G based systems */
639 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101,
640 "Intel D945G", STAC_D945GTP3),
641 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0202,
642 "Intel D945G", STAC_D945GTP3),
643 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0606,
644 "Intel D945G", STAC_D945GTP3),
645 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0601,
646 "Intel D945G", STAC_D945GTP3),
647 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0111,
648 "Intel D945G", STAC_D945GTP3),
649 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1115,
650 "Intel D945G", STAC_D945GTP3),
651 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1116,
652 "Intel D945G", STAC_D945GTP3),
653 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1117,
654 "Intel D945G", STAC_D945GTP3),
655 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1118,
656 "Intel D945G", STAC_D945GTP3),
657 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1119,
658 "Intel D945G", STAC_D945GTP3),
659 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x8826,
660 "Intel D945G", STAC_D945GTP3),
661 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5049,
662 "Intel D945G", STAC_D945GTP3),
663 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5055,
664 "Intel D945G", STAC_D945GTP3),
665 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5048,
666 "Intel D945G", STAC_D945GTP3),
667 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0110,
668 "Intel D945G", STAC_D945GTP3),
669 /* Intel D945G 5-stack systems */
670 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0404,
671 "Intel D945G", STAC_D945GTP5),
672 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0303,
673 "Intel D945G", STAC_D945GTP5),
674 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0013,
675 "Intel D945G", STAC_D945GTP5),
676 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0417,
677 "Intel D945G", STAC_D945GTP5),
678 /* Intel 945P based systems */
679 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0b0b,
680 "Intel D945P", STAC_D945GTP3),
681 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0112,
682 "Intel D945P", STAC_D945GTP3),
683 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0d0d,
684 "Intel D945P", STAC_D945GTP3),
685 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0909,
686 "Intel D945P", STAC_D945GTP3),
687 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0505,
688 "Intel D945P", STAC_D945GTP3),
689 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707,
690 "Intel D945P", STAC_D945GTP5),
691 /* other systems */
692 /* Apple Mac Mini (early 2006) */
693 SND_PCI_QUIRK(0x8384, 0x7680,
5d5d3bc3 694 "Mac Mini", STAC_INTEL_MAC_V3),
76c08828
TI
695 /* Dell */
696 SND_PCI_QUIRK(0x1028, 0x01d7, "Dell XPS M1210", STAC_922X_DELL),
697
403d1944
MP
698 {} /* terminator */
699};
700
3cc08dc6 701static unsigned int ref927x_pin_configs[14] = {
93ed1503
TD
702 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
703 0x01a19040, 0x01011012, 0x01016011, 0x0101201f,
704 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
705 0x01c42190, 0x40000100,
3cc08dc6
MP
706};
707
93ed1503 708static unsigned int d965_3st_pin_configs[14] = {
81d3dbde
TD
709 0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
710 0x01a19021, 0x01813024, 0x40000100, 0x40000100,
711 0x40000100, 0x40000100, 0x40000100, 0x40000100,
712 0x40000100, 0x40000100
713};
714
93ed1503
TD
715static unsigned int d965_5st_pin_configs[14] = {
716 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
717 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
718 0x40000100, 0x40000100, 0x40000100, 0x01442070,
719 0x40000100, 0x40000100
720};
721
722static unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
f5fcc13c 723 [STAC_D965_REF] = ref927x_pin_configs,
93ed1503
TD
724 [STAC_D965_3ST] = d965_3st_pin_configs,
725 [STAC_D965_5ST] = d965_5st_pin_configs,
3cc08dc6
MP
726};
727
f5fcc13c
TI
728static const char *stac927x_models[STAC_927X_MODELS] = {
729 [STAC_D965_REF] = "ref",
730 [STAC_D965_3ST] = "3stack",
731 [STAC_D965_5ST] = "5stack",
732};
733
734static struct snd_pci_quirk stac927x_cfg_tbl[] = {
735 /* SigmaTel reference board */
736 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
737 "DFI LanParty", STAC_D965_REF),
81d3dbde 738 /* Intel 946 based systems */
f5fcc13c
TI
739 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST),
740 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST),
93ed1503 741 /* 965 based 3 stack systems */
f5fcc13c
TI
742 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2116, "Intel D965", STAC_D965_3ST),
743 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2115, "Intel D965", STAC_D965_3ST),
744 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2114, "Intel D965", STAC_D965_3ST),
745 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2113, "Intel D965", STAC_D965_3ST),
746 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2112, "Intel D965", STAC_D965_3ST),
747 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2111, "Intel D965", STAC_D965_3ST),
748 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2110, "Intel D965", STAC_D965_3ST),
749 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2009, "Intel D965", STAC_D965_3ST),
750 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2008, "Intel D965", STAC_D965_3ST),
751 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2007, "Intel D965", STAC_D965_3ST),
752 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2006, "Intel D965", STAC_D965_3ST),
753 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2005, "Intel D965", STAC_D965_3ST),
754 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2004, "Intel D965", STAC_D965_3ST),
755 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2003, "Intel D965", STAC_D965_3ST),
756 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2002, "Intel D965", STAC_D965_3ST),
757 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2001, "Intel D965", STAC_D965_3ST),
93ed1503 758 /* 965 based 5 stack systems */
f5fcc13c
TI
759 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2301, "Intel D965", STAC_D965_5ST),
760 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2302, "Intel D965", STAC_D965_5ST),
761 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2303, "Intel D965", STAC_D965_5ST),
762 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2304, "Intel D965", STAC_D965_5ST),
763 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2305, "Intel D965", STAC_D965_5ST),
764 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2501, "Intel D965", STAC_D965_5ST),
765 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2502, "Intel D965", STAC_D965_5ST),
766 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2503, "Intel D965", STAC_D965_5ST),
767 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2504, "Intel D965", STAC_D965_5ST),
3cc08dc6
MP
768 {} /* terminator */
769};
770
f3302a59
MP
771static unsigned int ref9205_pin_configs[12] = {
772 0x40000100, 0x40000100, 0x01016011, 0x01014010,
8b65727b
MP
773 0x01813122, 0x01a19021, 0x40000100, 0x40000100,
774 0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
f3302a59
MP
775};
776
f5fcc13c 777static unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
f3302a59
MP
778 ref9205_pin_configs,
779};
780
f5fcc13c
TI
781static const char *stac9205_models[STAC_9205_MODELS] = {
782 [STAC_9205_REF] = "ref",
783};
784
785static struct snd_pci_quirk stac9205_cfg_tbl[] = {
786 /* SigmaTel reference board */
787 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
788 "DFI LanParty", STAC_9205_REF),
f3302a59
MP
789 {} /* terminator */
790};
791
11b44bbd
RF
792static int stac92xx_save_bios_config_regs(struct hda_codec *codec)
793{
794 int i;
795 struct sigmatel_spec *spec = codec->spec;
796
797 if (! spec->bios_pin_configs) {
798 spec->bios_pin_configs = kcalloc(spec->num_pins,
799 sizeof(*spec->bios_pin_configs), GFP_KERNEL);
800 if (! spec->bios_pin_configs)
801 return -ENOMEM;
802 }
803
804 for (i = 0; i < spec->num_pins; i++) {
805 hda_nid_t nid = spec->pin_nids[i];
806 unsigned int pin_cfg;
807
808 pin_cfg = snd_hda_codec_read(codec, nid, 0,
809 AC_VERB_GET_CONFIG_DEFAULT, 0x00);
810 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x bios pin config %8.8x\n",
811 nid, pin_cfg);
812 spec->bios_pin_configs[i] = pin_cfg;
813 }
814
815 return 0;
816}
817
2f2f4251
M
818static void stac92xx_set_config_regs(struct hda_codec *codec)
819{
820 int i;
821 struct sigmatel_spec *spec = codec->spec;
822 unsigned int pin_cfg;
823
11b44bbd
RF
824 if (! spec->pin_nids || ! spec->pin_configs)
825 return;
826
827 for (i = 0; i < spec->num_pins; i++) {
2f2f4251
M
828 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
829 AC_VERB_SET_CONFIG_DEFAULT_BYTES_0,
830 spec->pin_configs[i] & 0x000000ff);
831 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
832 AC_VERB_SET_CONFIG_DEFAULT_BYTES_1,
833 (spec->pin_configs[i] & 0x0000ff00) >> 8);
834 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
835 AC_VERB_SET_CONFIG_DEFAULT_BYTES_2,
836 (spec->pin_configs[i] & 0x00ff0000) >> 16);
837 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
838 AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
839 spec->pin_configs[i] >> 24);
840 pin_cfg = snd_hda_codec_read(codec, spec->pin_nids[i], 0,
841 AC_VERB_GET_CONFIG_DEFAULT,
842 0x00);
403d1944 843 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x pin config %8.8x\n", spec->pin_nids[i], pin_cfg);
2f2f4251
M
844 }
845}
2f2f4251 846
92a22beb
MR
847static void stac92xx_enable_eapd(struct hda_codec *codec)
848{
849 /* Configure GPIO0 as output */
850 snd_hda_codec_write(codec, codec->afg, 0,
851 AC_VERB_SET_GPIO_DIRECTION, 0x00000001);
852 /* Configure GPIO0 as CMOS */
853 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0x00000000);
854 /* Assert GPIO0 high */
855 snd_hda_codec_write(codec, codec->afg, 0,
856 AC_VERB_SET_GPIO_DATA, 0x00000001);
857 /* Enable GPIO0 */
858 snd_hda_codec_write(codec, codec->afg, 0,
859 AC_VERB_SET_GPIO_MASK, 0x00000001);
860}
861
dabbed6f 862/*
c7d4b2fa 863 * Analog playback callbacks
dabbed6f 864 */
c7d4b2fa
M
865static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
866 struct hda_codec *codec,
c8b6bf9b 867 struct snd_pcm_substream *substream)
2f2f4251 868{
dabbed6f 869 struct sigmatel_spec *spec = codec->spec;
c7d4b2fa 870 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
2f2f4251
M
871}
872
2f2f4251
M
873static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
874 struct hda_codec *codec,
875 unsigned int stream_tag,
876 unsigned int format,
c8b6bf9b 877 struct snd_pcm_substream *substream)
2f2f4251
M
878{
879 struct sigmatel_spec *spec = codec->spec;
403d1944 880 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
2f2f4251
M
881}
882
883static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
884 struct hda_codec *codec,
c8b6bf9b 885 struct snd_pcm_substream *substream)
2f2f4251
M
886{
887 struct sigmatel_spec *spec = codec->spec;
888 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
889}
890
dabbed6f
M
891/*
892 * Digital playback callbacks
893 */
894static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
895 struct hda_codec *codec,
c8b6bf9b 896 struct snd_pcm_substream *substream)
dabbed6f
M
897{
898 struct sigmatel_spec *spec = codec->spec;
899 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
900}
901
902static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
903 struct hda_codec *codec,
c8b6bf9b 904 struct snd_pcm_substream *substream)
dabbed6f
M
905{
906 struct sigmatel_spec *spec = codec->spec;
907 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
908}
909
6b97eb45
TI
910static int stac92xx_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
911 struct hda_codec *codec,
912 unsigned int stream_tag,
913 unsigned int format,
914 struct snd_pcm_substream *substream)
915{
916 struct sigmatel_spec *spec = codec->spec;
917 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
918 stream_tag, format, substream);
919}
920
dabbed6f 921
2f2f4251
M
922/*
923 * Analog capture callbacks
924 */
925static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
926 struct hda_codec *codec,
927 unsigned int stream_tag,
928 unsigned int format,
c8b6bf9b 929 struct snd_pcm_substream *substream)
2f2f4251
M
930{
931 struct sigmatel_spec *spec = codec->spec;
932
933 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
934 stream_tag, 0, format);
935 return 0;
936}
937
938static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
939 struct hda_codec *codec,
c8b6bf9b 940 struct snd_pcm_substream *substream)
2f2f4251
M
941{
942 struct sigmatel_spec *spec = codec->spec;
943
944 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 0, 0, 0);
945 return 0;
946}
947
dabbed6f
M
948static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
949 .substreams = 1,
950 .channels_min = 2,
951 .channels_max = 2,
952 /* NID is set in stac92xx_build_pcms */
953 .ops = {
954 .open = stac92xx_dig_playback_pcm_open,
6b97eb45
TI
955 .close = stac92xx_dig_playback_pcm_close,
956 .prepare = stac92xx_dig_playback_pcm_prepare
dabbed6f
M
957 },
958};
959
960static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
961 .substreams = 1,
962 .channels_min = 2,
963 .channels_max = 2,
964 /* NID is set in stac92xx_build_pcms */
965};
966
2f2f4251
M
967static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
968 .substreams = 1,
969 .channels_min = 2,
c7d4b2fa 970 .channels_max = 8,
2f2f4251
M
971 .nid = 0x02, /* NID to query formats and rates */
972 .ops = {
973 .open = stac92xx_playback_pcm_open,
974 .prepare = stac92xx_playback_pcm_prepare,
975 .cleanup = stac92xx_playback_pcm_cleanup
976 },
977};
978
3cc08dc6
MP
979static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
980 .substreams = 1,
981 .channels_min = 2,
982 .channels_max = 2,
983 .nid = 0x06, /* NID to query formats and rates */
984 .ops = {
985 .open = stac92xx_playback_pcm_open,
986 .prepare = stac92xx_playback_pcm_prepare,
987 .cleanup = stac92xx_playback_pcm_cleanup
988 },
989};
990
2f2f4251
M
991static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
992 .substreams = 2,
993 .channels_min = 2,
994 .channels_max = 2,
3cc08dc6 995 /* NID is set in stac92xx_build_pcms */
2f2f4251
M
996 .ops = {
997 .prepare = stac92xx_capture_pcm_prepare,
998 .cleanup = stac92xx_capture_pcm_cleanup
999 },
1000};
1001
1002static int stac92xx_build_pcms(struct hda_codec *codec)
1003{
1004 struct sigmatel_spec *spec = codec->spec;
1005 struct hda_pcm *info = spec->pcm_rec;
1006
1007 codec->num_pcms = 1;
1008 codec->pcm_info = info;
1009
c7d4b2fa 1010 info->name = "STAC92xx Analog";
2f2f4251 1011 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
2f2f4251 1012 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
3cc08dc6
MP
1013 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
1014
1015 if (spec->alt_switch) {
1016 codec->num_pcms++;
1017 info++;
1018 info->name = "STAC92xx Analog Alt";
1019 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
1020 }
2f2f4251 1021
dabbed6f
M
1022 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
1023 codec->num_pcms++;
1024 info++;
1025 info->name = "STAC92xx Digital";
1026 if (spec->multiout.dig_out_nid) {
1027 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
1028 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
1029 }
1030 if (spec->dig_in_nid) {
1031 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
1032 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
1033 }
1034 }
1035
2f2f4251
M
1036 return 0;
1037}
1038
c960a03b
TI
1039static unsigned int stac92xx_get_vref(struct hda_codec *codec, hda_nid_t nid)
1040{
1041 unsigned int pincap = snd_hda_param_read(codec, nid,
1042 AC_PAR_PIN_CAP);
1043 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
1044 if (pincap & AC_PINCAP_VREF_100)
1045 return AC_PINCTL_VREF_100;
1046 if (pincap & AC_PINCAP_VREF_80)
1047 return AC_PINCTL_VREF_80;
1048 if (pincap & AC_PINCAP_VREF_50)
1049 return AC_PINCTL_VREF_50;
1050 if (pincap & AC_PINCAP_VREF_GRD)
1051 return AC_PINCTL_VREF_GRD;
1052 return 0;
1053}
1054
403d1944
MP
1055static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
1056
1057{
1058 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
1059}
1060
1061static int stac92xx_io_switch_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1062{
1063 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1064 uinfo->count = 1;
1065 uinfo->value.integer.min = 0;
1066 uinfo->value.integer.max = 1;
1067 return 0;
1068}
1069
1070static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1071{
1072 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1073 struct sigmatel_spec *spec = codec->spec;
1074 int io_idx = kcontrol-> private_value & 0xff;
1075
1076 ucontrol->value.integer.value[0] = spec->io_switch[io_idx];
1077 return 0;
1078}
1079
1080static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1081{
1082 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1083 struct sigmatel_spec *spec = codec->spec;
1084 hda_nid_t nid = kcontrol->private_value >> 8;
1085 int io_idx = kcontrol-> private_value & 0xff;
1086 unsigned short val = ucontrol->value.integer.value[0];
1087
1088 spec->io_switch[io_idx] = val;
1089
1090 if (val)
1091 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
c960a03b
TI
1092 else {
1093 unsigned int pinctl = AC_PINCTL_IN_EN;
1094 if (io_idx) /* set VREF for mic */
1095 pinctl |= stac92xx_get_vref(codec, nid);
1096 stac92xx_auto_set_pinctl(codec, nid, pinctl);
1097 }
403d1944
MP
1098 return 1;
1099}
1100
1101#define STAC_CODEC_IO_SWITCH(xname, xpval) \
1102 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1103 .name = xname, \
1104 .index = 0, \
1105 .info = stac92xx_io_switch_info, \
1106 .get = stac92xx_io_switch_get, \
1107 .put = stac92xx_io_switch_put, \
1108 .private_value = xpval, \
1109 }
1110
1111
c7d4b2fa
M
1112enum {
1113 STAC_CTL_WIDGET_VOL,
1114 STAC_CTL_WIDGET_MUTE,
403d1944 1115 STAC_CTL_WIDGET_IO_SWITCH,
c7d4b2fa
M
1116};
1117
c8b6bf9b 1118static struct snd_kcontrol_new stac92xx_control_templates[] = {
c7d4b2fa
M
1119 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
1120 HDA_CODEC_MUTE(NULL, 0, 0, 0),
403d1944 1121 STAC_CODEC_IO_SWITCH(NULL, 0),
c7d4b2fa
M
1122};
1123
1124/* add dynamic controls */
1125static int stac92xx_add_control(struct sigmatel_spec *spec, int type, const char *name, unsigned long val)
1126{
c8b6bf9b 1127 struct snd_kcontrol_new *knew;
c7d4b2fa
M
1128
1129 if (spec->num_kctl_used >= spec->num_kctl_alloc) {
1130 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
1131
1132 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */
1133 if (! knew)
1134 return -ENOMEM;
1135 if (spec->kctl_alloc) {
1136 memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
1137 kfree(spec->kctl_alloc);
1138 }
1139 spec->kctl_alloc = knew;
1140 spec->num_kctl_alloc = num;
1141 }
1142
1143 knew = &spec->kctl_alloc[spec->num_kctl_used];
1144 *knew = stac92xx_control_templates[type];
82fe0c58 1145 knew->name = kstrdup(name, GFP_KERNEL);
c7d4b2fa
M
1146 if (! knew->name)
1147 return -ENOMEM;
1148 knew->private_value = val;
1149 spec->num_kctl_used++;
1150 return 0;
1151}
1152
403d1944
MP
1153/* flag inputs as additional dynamic lineouts */
1154static int stac92xx_add_dyn_out_pins(struct hda_codec *codec, struct auto_pin_cfg *cfg)
1155{
1156 struct sigmatel_spec *spec = codec->spec;
7b043899
SL
1157 unsigned int wcaps, wtype;
1158 int i, num_dacs = 0;
1159
1160 /* use the wcaps cache to count all DACs available for line-outs */
1161 for (i = 0; i < codec->num_nodes; i++) {
1162 wcaps = codec->wcaps[i];
1163 wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
1164 if (wtype == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL))
1165 num_dacs++;
1166 }
403d1944 1167
7b043899
SL
1168 snd_printdd("%s: total dac count=%d\n", __func__, num_dacs);
1169
403d1944
MP
1170 switch (cfg->line_outs) {
1171 case 3:
1172 /* add line-in as side */
7b043899 1173 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 3) {
403d1944
MP
1174 cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_LINE];
1175 spec->line_switch = 1;
1176 cfg->line_outs++;
1177 }
1178 break;
1179 case 2:
1180 /* add line-in as clfe and mic as side */
7b043899 1181 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 2) {
403d1944
MP
1182 cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_LINE];
1183 spec->line_switch = 1;
1184 cfg->line_outs++;
1185 }
7b043899 1186 if (cfg->input_pins[AUTO_PIN_MIC] && num_dacs > 3) {
403d1944
MP
1187 cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_MIC];
1188 spec->mic_switch = 1;
1189 cfg->line_outs++;
1190 }
1191 break;
1192 case 1:
1193 /* add line-in as surr and mic as clfe */
7b043899 1194 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 1) {
403d1944
MP
1195 cfg->line_out_pins[1] = cfg->input_pins[AUTO_PIN_LINE];
1196 spec->line_switch = 1;
1197 cfg->line_outs++;
1198 }
7b043899 1199 if (cfg->input_pins[AUTO_PIN_MIC] && num_dacs > 2) {
403d1944
MP
1200 cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_MIC];
1201 spec->mic_switch = 1;
1202 cfg->line_outs++;
1203 }
1204 break;
1205 }
1206
1207 return 0;
1208}
1209
7b043899
SL
1210
1211static int is_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
1212{
1213 int i;
1214
1215 for (i = 0; i < spec->multiout.num_dacs; i++) {
1216 if (spec->multiout.dac_nids[i] == nid)
1217 return 1;
1218 }
1219
1220 return 0;
1221}
1222
3cc08dc6 1223/*
7b043899
SL
1224 * Fill in the dac_nids table from the parsed pin configuration
1225 * This function only works when every pin in line_out_pins[]
1226 * contains atleast one DAC in its connection list. Some 92xx
1227 * codecs are not connected directly to a DAC, such as the 9200
1228 * and 9202/925x. For those, dac_nids[] must be hard-coded.
3cc08dc6 1229 */
19039bd0 1230static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec,
df802952 1231 struct auto_pin_cfg *cfg)
c7d4b2fa
M
1232{
1233 struct sigmatel_spec *spec = codec->spec;
7b043899
SL
1234 int i, j, conn_len = 0;
1235 hda_nid_t nid, conn[HDA_MAX_CONNECTIONS];
1236 unsigned int wcaps, wtype;
1237
c7d4b2fa
M
1238 for (i = 0; i < cfg->line_outs; i++) {
1239 nid = cfg->line_out_pins[i];
7b043899
SL
1240 conn_len = snd_hda_get_connections(codec, nid, conn,
1241 HDA_MAX_CONNECTIONS);
1242 for (j = 0; j < conn_len; j++) {
1243 wcaps = snd_hda_param_read(codec, conn[j],
1244 AC_PAR_AUDIO_WIDGET_CAP);
1245 wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
1246
1247 if (wtype != AC_WID_AUD_OUT ||
1248 (wcaps & AC_WCAP_DIGITAL))
1249 continue;
1250 /* conn[j] is a DAC routed to this line-out */
1251 if (!is_in_dac_nids(spec, conn[j]))
1252 break;
1253 }
1254
1255 if (j == conn_len) {
df802952
TI
1256 if (spec->multiout.num_dacs > 0) {
1257 /* we have already working output pins,
1258 * so let's drop the broken ones again
1259 */
1260 cfg->line_outs = spec->multiout.num_dacs;
1261 break;
1262 }
7b043899
SL
1263 /* error out, no available DAC found */
1264 snd_printk(KERN_ERR
1265 "%s: No available DAC for pin 0x%x\n",
1266 __func__, nid);
1267 return -ENODEV;
1268 }
1269
1270 spec->multiout.dac_nids[i] = conn[j];
1271 spec->multiout.num_dacs++;
1272 if (conn_len > 1) {
1273 /* select this DAC in the pin's input mux */
1274 snd_hda_codec_write(codec, nid, 0,
1275 AC_VERB_SET_CONNECT_SEL, j);
c7d4b2fa 1276
7b043899
SL
1277 }
1278 }
c7d4b2fa 1279
7b043899
SL
1280 snd_printd("dac_nids=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
1281 spec->multiout.num_dacs,
1282 spec->multiout.dac_nids[0],
1283 spec->multiout.dac_nids[1],
1284 spec->multiout.dac_nids[2],
1285 spec->multiout.dac_nids[3],
1286 spec->multiout.dac_nids[4]);
c7d4b2fa
M
1287 return 0;
1288}
1289
eb06ed8f
TI
1290/* create volume control/switch for the given prefx type */
1291static int create_controls(struct sigmatel_spec *spec, const char *pfx, hda_nid_t nid, int chs)
1292{
1293 char name[32];
1294 int err;
1295
1296 sprintf(name, "%s Playback Volume", pfx);
1297 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, name,
1298 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1299 if (err < 0)
1300 return err;
1301 sprintf(name, "%s Playback Switch", pfx);
1302 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, name,
1303 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1304 if (err < 0)
1305 return err;
1306 return 0;
1307}
1308
c7d4b2fa 1309/* add playback controls from the parsed DAC table */
19039bd0
TI
1310static int stac92xx_auto_create_multi_out_ctls(struct sigmatel_spec *spec,
1311 const struct auto_pin_cfg *cfg)
c7d4b2fa 1312{
19039bd0
TI
1313 static const char *chname[4] = {
1314 "Front", "Surround", NULL /*CLFE*/, "Side"
1315 };
c7d4b2fa
M
1316 hda_nid_t nid;
1317 int i, err;
1318
1319 for (i = 0; i < cfg->line_outs; i++) {
403d1944 1320 if (!spec->multiout.dac_nids[i])
c7d4b2fa
M
1321 continue;
1322
1323 nid = spec->multiout.dac_nids[i];
1324
1325 if (i == 2) {
1326 /* Center/LFE */
eb06ed8f
TI
1327 err = create_controls(spec, "Center", nid, 1);
1328 if (err < 0)
c7d4b2fa 1329 return err;
eb06ed8f
TI
1330 err = create_controls(spec, "LFE", nid, 2);
1331 if (err < 0)
c7d4b2fa
M
1332 return err;
1333 } else {
eb06ed8f
TI
1334 err = create_controls(spec, chname[i], nid, 3);
1335 if (err < 0)
c7d4b2fa
M
1336 return err;
1337 }
1338 }
1339
403d1944
MP
1340 if (spec->line_switch)
1341 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Line In as Output Switch", cfg->input_pins[AUTO_PIN_LINE] << 8)) < 0)
1342 return err;
1343
1344 if (spec->mic_switch)
1345 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Mic as Output Switch", (cfg->input_pins[AUTO_PIN_MIC] << 8) | 1)) < 0)
1346 return err;
1347
c7d4b2fa
M
1348 return 0;
1349}
1350
eb06ed8f 1351static int check_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
c7d4b2fa 1352{
7b043899
SL
1353 if (is_in_dac_nids(spec, nid))
1354 return 1;
eb06ed8f
TI
1355 if (spec->multiout.hp_nid == nid)
1356 return 1;
1357 return 0;
1358}
c7d4b2fa 1359
eb06ed8f
TI
1360static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
1361{
1362 if (!spec->multiout.hp_nid)
1363 spec->multiout.hp_nid = nid;
1364 else if (spec->multiout.num_dacs > 4) {
1365 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
1366 return 1;
1367 } else {
1368 spec->multiout.dac_nids[spec->multiout.num_dacs] = nid;
1369 spec->multiout.num_dacs++;
1370 }
1371 return 0;
1372}
4e55096e 1373
eb06ed8f
TI
1374/* add playback controls for Speaker and HP outputs */
1375static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
1376 struct auto_pin_cfg *cfg)
1377{
1378 struct sigmatel_spec *spec = codec->spec;
1379 hda_nid_t nid;
1380 int i, old_num_dacs, err;
1381
1382 old_num_dacs = spec->multiout.num_dacs;
1383 for (i = 0; i < cfg->hp_outs; i++) {
1384 unsigned int wid_caps = get_wcaps(codec, cfg->hp_pins[i]);
1385 if (wid_caps & AC_WCAP_UNSOL_CAP)
1386 spec->hp_detect = 1;
1387 nid = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
1388 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
1389 if (check_in_dac_nids(spec, nid))
1390 nid = 0;
1391 if (! nid)
c7d4b2fa 1392 continue;
eb06ed8f
TI
1393 add_spec_dacs(spec, nid);
1394 }
1395 for (i = 0; i < cfg->speaker_outs; i++) {
7b043899 1396 nid = snd_hda_codec_read(codec, cfg->speaker_pins[i], 0,
eb06ed8f
TI
1397 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
1398 if (check_in_dac_nids(spec, nid))
1399 nid = 0;
eb06ed8f
TI
1400 if (! nid)
1401 continue;
1402 add_spec_dacs(spec, nid);
c7d4b2fa
M
1403 }
1404
eb06ed8f
TI
1405 for (i = old_num_dacs; i < spec->multiout.num_dacs; i++) {
1406 static const char *pfxs[] = {
1407 "Speaker", "External Speaker", "Speaker2",
1408 };
1409 err = create_controls(spec, pfxs[i - old_num_dacs],
1410 spec->multiout.dac_nids[i], 3);
1411 if (err < 0)
1412 return err;
1413 }
1414 if (spec->multiout.hp_nid) {
1415 const char *pfx;
1416 if (old_num_dacs == spec->multiout.num_dacs)
1417 pfx = "Master";
1418 else
1419 pfx = "Headphone";
1420 err = create_controls(spec, pfx, spec->multiout.hp_nid, 3);
1421 if (err < 0)
1422 return err;
1423 }
c7d4b2fa
M
1424
1425 return 0;
1426}
1427
8b65727b 1428/* labels for dmic mux inputs */
ddc2cec4 1429static const char *stac92xx_dmic_labels[5] = {
8b65727b
MP
1430 "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
1431 "Digital Mic 3", "Digital Mic 4"
1432};
1433
1434/* create playback/capture controls for input pins on dmic capable codecs */
1435static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
1436 const struct auto_pin_cfg *cfg)
1437{
1438 struct sigmatel_spec *spec = codec->spec;
1439 struct hda_input_mux *dimux = &spec->private_dimux;
1440 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
1441 int i, j;
1442
1443 dimux->items[dimux->num_items].label = stac92xx_dmic_labels[0];
1444 dimux->items[dimux->num_items].index = 0;
1445 dimux->num_items++;
1446
1447 for (i = 0; i < spec->num_dmics; i++) {
1448 int index;
1449 int num_cons;
1450 unsigned int def_conf;
1451
1452 def_conf = snd_hda_codec_read(codec,
1453 spec->dmic_nids[i],
1454 0,
1455 AC_VERB_GET_CONFIG_DEFAULT,
1456 0);
1457 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
1458 continue;
1459
1460 num_cons = snd_hda_get_connections(codec,
1461 spec->dmux_nid,
1462 con_lst,
1463 HDA_MAX_NUM_INPUTS);
1464 for (j = 0; j < num_cons; j++)
1465 if (con_lst[j] == spec->dmic_nids[i]) {
1466 index = j;
1467 goto found;
1468 }
1469 continue;
1470found:
1471 dimux->items[dimux->num_items].label =
1472 stac92xx_dmic_labels[dimux->num_items];
1473 dimux->items[dimux->num_items].index = index;
1474 dimux->num_items++;
1475 }
1476
1477 return 0;
1478}
1479
c7d4b2fa
M
1480/* create playback/capture controls for input pins */
1481static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
1482{
1483 struct sigmatel_spec *spec = codec->spec;
c7d4b2fa
M
1484 struct hda_input_mux *imux = &spec->private_imux;
1485 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
1486 int i, j, k;
1487
1488 for (i = 0; i < AUTO_PIN_LAST; i++) {
314634bc
TI
1489 int index;
1490
1491 if (!cfg->input_pins[i])
1492 continue;
1493 index = -1;
1494 for (j = 0; j < spec->num_muxes; j++) {
1495 int num_cons;
1496 num_cons = snd_hda_get_connections(codec,
1497 spec->mux_nids[j],
1498 con_lst,
1499 HDA_MAX_NUM_INPUTS);
1500 for (k = 0; k < num_cons; k++)
1501 if (con_lst[k] == cfg->input_pins[i]) {
1502 index = k;
1503 goto found;
1504 }
c7d4b2fa 1505 }
314634bc
TI
1506 continue;
1507 found:
1508 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
1509 imux->items[imux->num_items].index = index;
1510 imux->num_items++;
c7d4b2fa
M
1511 }
1512
7b043899 1513 if (imux->num_items) {
62fe78e9
SR
1514 /*
1515 * Set the current input for the muxes.
1516 * The STAC9221 has two input muxes with identical source
1517 * NID lists. Hopefully this won't get confused.
1518 */
1519 for (i = 0; i < spec->num_muxes; i++) {
1520 snd_hda_codec_write(codec, spec->mux_nids[i], 0,
1521 AC_VERB_SET_CONNECT_SEL,
1522 imux->items[0].index);
1523 }
1524 }
1525
c7d4b2fa
M
1526 return 0;
1527}
1528
c7d4b2fa
M
1529static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
1530{
1531 struct sigmatel_spec *spec = codec->spec;
1532 int i;
1533
1534 for (i = 0; i < spec->autocfg.line_outs; i++) {
1535 hda_nid_t nid = spec->autocfg.line_out_pins[i];
1536 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
1537 }
1538}
1539
1540static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
1541{
1542 struct sigmatel_spec *spec = codec->spec;
eb06ed8f 1543 int i;
c7d4b2fa 1544
eb06ed8f
TI
1545 for (i = 0; i < spec->autocfg.hp_outs; i++) {
1546 hda_nid_t pin;
1547 pin = spec->autocfg.hp_pins[i];
1548 if (pin) /* connect to front */
1549 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
1550 }
1551 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
1552 hda_nid_t pin;
1553 pin = spec->autocfg.speaker_pins[i];
1554 if (pin) /* connect to front */
1555 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
1556 }
c7d4b2fa
M
1557}
1558
3cc08dc6 1559static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out, hda_nid_t dig_in)
c7d4b2fa
M
1560{
1561 struct sigmatel_spec *spec = codec->spec;
1562 int err;
1563
8b65727b
MP
1564 if ((err = snd_hda_parse_pin_def_config(codec,
1565 &spec->autocfg,
1566 spec->dmic_nids)) < 0)
c7d4b2fa 1567 return err;
82bc955f 1568 if (! spec->autocfg.line_outs)
869264c4 1569 return 0; /* can't find valid pin config */
19039bd0 1570
403d1944
MP
1571 if ((err = stac92xx_add_dyn_out_pins(codec, &spec->autocfg)) < 0)
1572 return err;
19039bd0
TI
1573 if (spec->multiout.num_dacs == 0)
1574 if ((err = stac92xx_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
1575 return err;
c7d4b2fa
M
1576
1577 if ((err = stac92xx_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
1578 (err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg)) < 0 ||
1579 (err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
1580 return err;
1581
8b65727b
MP
1582 if (spec->num_dmics > 0)
1583 if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
1584 &spec->autocfg)) < 0)
1585 return err;
1586
c7d4b2fa 1587 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
403d1944 1588 if (spec->multiout.max_channels > 2)
c7d4b2fa 1589 spec->surr_switch = 1;
c7d4b2fa 1590
82bc955f 1591 if (spec->autocfg.dig_out_pin)
3cc08dc6 1592 spec->multiout.dig_out_nid = dig_out;
82bc955f 1593 if (spec->autocfg.dig_in_pin)
3cc08dc6 1594 spec->dig_in_nid = dig_in;
c7d4b2fa
M
1595
1596 if (spec->kctl_alloc)
1597 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
1598
1599 spec->input_mux = &spec->private_imux;
8b65727b 1600 spec->dinput_mux = &spec->private_dimux;
c7d4b2fa
M
1601
1602 return 1;
1603}
1604
82bc955f
TI
1605/* add playback controls for HP output */
1606static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
1607 struct auto_pin_cfg *cfg)
1608{
1609 struct sigmatel_spec *spec = codec->spec;
eb06ed8f 1610 hda_nid_t pin = cfg->hp_pins[0];
82bc955f
TI
1611 unsigned int wid_caps;
1612
1613 if (! pin)
1614 return 0;
1615
1616 wid_caps = get_wcaps(codec, pin);
505cb341 1617 if (wid_caps & AC_WCAP_UNSOL_CAP)
82bc955f 1618 spec->hp_detect = 1;
82bc955f
TI
1619
1620 return 0;
1621}
1622
160ea0dc
RF
1623/* add playback controls for LFE output */
1624static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
1625 struct auto_pin_cfg *cfg)
1626{
1627 struct sigmatel_spec *spec = codec->spec;
1628 int err;
1629 hda_nid_t lfe_pin = 0x0;
1630 int i;
1631
1632 /*
1633 * search speaker outs and line outs for a mono speaker pin
1634 * with an amp. If one is found, add LFE controls
1635 * for it.
1636 */
1637 for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
1638 hda_nid_t pin = spec->autocfg.speaker_pins[i];
1639 unsigned long wcaps = get_wcaps(codec, pin);
1640 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
1641 if (wcaps == AC_WCAP_OUT_AMP)
1642 /* found a mono speaker with an amp, must be lfe */
1643 lfe_pin = pin;
1644 }
1645
1646 /* if speaker_outs is 0, then speakers may be in line_outs */
1647 if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
1648 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
1649 hda_nid_t pin = spec->autocfg.line_out_pins[i];
1650 unsigned long cfg;
1651 cfg = snd_hda_codec_read(codec, pin, 0,
1652 AC_VERB_GET_CONFIG_DEFAULT,
1653 0x00);
1654 if (get_defcfg_device(cfg) == AC_JACK_SPEAKER) {
1655 unsigned long wcaps = get_wcaps(codec, pin);
1656 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
1657 if (wcaps == AC_WCAP_OUT_AMP)
1658 /* found a mono speaker with an amp,
1659 must be lfe */
1660 lfe_pin = pin;
1661 }
1662 }
1663 }
1664
1665 if (lfe_pin) {
eb06ed8f 1666 err = create_controls(spec, "LFE", lfe_pin, 1);
160ea0dc
RF
1667 if (err < 0)
1668 return err;
1669 }
1670
1671 return 0;
1672}
1673
c7d4b2fa
M
1674static int stac9200_parse_auto_config(struct hda_codec *codec)
1675{
1676 struct sigmatel_spec *spec = codec->spec;
1677 int err;
1678
df694daa 1679 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
c7d4b2fa
M
1680 return err;
1681
1682 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
1683 return err;
1684
82bc955f
TI
1685 if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
1686 return err;
1687
160ea0dc
RF
1688 if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
1689 return err;
1690
82bc955f 1691 if (spec->autocfg.dig_out_pin)
c7d4b2fa 1692 spec->multiout.dig_out_nid = 0x05;
82bc955f 1693 if (spec->autocfg.dig_in_pin)
c7d4b2fa 1694 spec->dig_in_nid = 0x04;
c7d4b2fa
M
1695
1696 if (spec->kctl_alloc)
1697 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
1698
1699 spec->input_mux = &spec->private_imux;
8b65727b 1700 spec->dinput_mux = &spec->private_dimux;
c7d4b2fa
M
1701
1702 return 1;
1703}
1704
62fe78e9
SR
1705/*
1706 * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
1707 * funky external mute control using GPIO pins.
1708 */
1709
1710static void stac922x_gpio_mute(struct hda_codec *codec, int pin, int muted)
1711{
1712 unsigned int gpiostate, gpiomask, gpiodir;
1713
1714 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
1715 AC_VERB_GET_GPIO_DATA, 0);
1716
1717 if (!muted)
1718 gpiostate |= (1 << pin);
1719 else
1720 gpiostate &= ~(1 << pin);
1721
1722 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
1723 AC_VERB_GET_GPIO_MASK, 0);
1724 gpiomask |= (1 << pin);
1725
1726 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
1727 AC_VERB_GET_GPIO_DIRECTION, 0);
1728 gpiodir |= (1 << pin);
1729
1730 /* AppleHDA seems to do this -- WTF is this verb?? */
1731 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
1732
1733 snd_hda_codec_write(codec, codec->afg, 0,
1734 AC_VERB_SET_GPIO_MASK, gpiomask);
1735 snd_hda_codec_write(codec, codec->afg, 0,
1736 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
1737
1738 msleep(1);
1739
1740 snd_hda_codec_write(codec, codec->afg, 0,
1741 AC_VERB_SET_GPIO_DATA, gpiostate);
1742}
1743
314634bc
TI
1744static void enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
1745 unsigned int event)
1746{
1747 if (get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP)
1748 snd_hda_codec_write(codec, nid, 0,
1749 AC_VERB_SET_UNSOLICITED_ENABLE,
1750 (AC_USRSP_EN | event));
1751}
1752
c7d4b2fa
M
1753static int stac92xx_init(struct hda_codec *codec)
1754{
1755 struct sigmatel_spec *spec = codec->spec;
82bc955f
TI
1756 struct auto_pin_cfg *cfg = &spec->autocfg;
1757 int i;
c7d4b2fa 1758
c7d4b2fa
M
1759 snd_hda_sequence_write(codec, spec->init);
1760
82bc955f
TI
1761 /* set up pins */
1762 if (spec->hp_detect) {
505cb341 1763 /* Enable unsolicited responses on the HP widget */
eb06ed8f 1764 for (i = 0; i < cfg->hp_outs; i++)
314634bc
TI
1765 enable_pin_detect(codec, cfg->hp_pins[i],
1766 STAC_HP_EVENT);
0a07acaf
TI
1767 /* force to enable the first line-out; the others are set up
1768 * in unsol_event
1769 */
1770 stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
1771 AC_PINCTL_OUT_EN);
eb995a8c 1772 stac92xx_auto_init_hp_out(codec);
82bc955f
TI
1773 /* fake event to set up pins */
1774 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
1775 } else {
1776 stac92xx_auto_init_multi_out(codec);
1777 stac92xx_auto_init_hp_out(codec);
1778 }
1779 for (i = 0; i < AUTO_PIN_LAST; i++) {
c960a03b
TI
1780 hda_nid_t nid = cfg->input_pins[i];
1781 if (nid) {
1782 unsigned int pinctl = AC_PINCTL_IN_EN;
1783 if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC)
1784 pinctl |= stac92xx_get_vref(codec, nid);
1785 stac92xx_auto_set_pinctl(codec, nid, pinctl);
1786 }
82bc955f 1787 }
8b65727b
MP
1788 if (spec->num_dmics > 0)
1789 for (i = 0; i < spec->num_dmics; i++)
1790 stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
1791 AC_PINCTL_IN_EN);
1792
82bc955f
TI
1793 if (cfg->dig_out_pin)
1794 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pin,
1795 AC_PINCTL_OUT_EN);
1796 if (cfg->dig_in_pin)
1797 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
1798 AC_PINCTL_IN_EN);
1799
62fe78e9
SR
1800 if (spec->gpio_mute) {
1801 stac922x_gpio_mute(codec, 0, 0);
1802 stac922x_gpio_mute(codec, 1, 0);
1803 }
1804
c7d4b2fa
M
1805 return 0;
1806}
1807
2f2f4251
M
1808static void stac92xx_free(struct hda_codec *codec)
1809{
c7d4b2fa
M
1810 struct sigmatel_spec *spec = codec->spec;
1811 int i;
1812
1813 if (! spec)
1814 return;
1815
1816 if (spec->kctl_alloc) {
1817 for (i = 0; i < spec->num_kctl_used; i++)
1818 kfree(spec->kctl_alloc[i].name);
1819 kfree(spec->kctl_alloc);
1820 }
1821
11b44bbd
RF
1822 if (spec->bios_pin_configs)
1823 kfree(spec->bios_pin_configs);
1824
c7d4b2fa 1825 kfree(spec);
2f2f4251
M
1826}
1827
4e55096e
M
1828static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
1829 unsigned int flag)
1830{
1831 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
1832 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
7b043899 1833
f9acba43
TI
1834 if (pin_ctl & AC_PINCTL_IN_EN) {
1835 /*
1836 * we need to check the current set-up direction of
1837 * shared input pins since they can be switched via
1838 * "xxx as Output" mixer switch
1839 */
1840 struct sigmatel_spec *spec = codec->spec;
1841 struct auto_pin_cfg *cfg = &spec->autocfg;
1842 if ((nid == cfg->input_pins[AUTO_PIN_LINE] &&
1843 spec->line_switch) ||
1844 (nid == cfg->input_pins[AUTO_PIN_MIC] &&
1845 spec->mic_switch))
1846 return;
1847 }
1848
7b043899
SL
1849 /* if setting pin direction bits, clear the current
1850 direction bits first */
1851 if (flag & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))
1852 pin_ctl &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
1853
4e55096e
M
1854 snd_hda_codec_write(codec, nid, 0,
1855 AC_VERB_SET_PIN_WIDGET_CONTROL,
1856 pin_ctl | flag);
1857}
1858
1859static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
1860 unsigned int flag)
1861{
1862 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
1863 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
1864 snd_hda_codec_write(codec, nid, 0,
1865 AC_VERB_SET_PIN_WIDGET_CONTROL,
1866 pin_ctl & ~flag);
1867}
1868
314634bc
TI
1869static int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
1870{
1871 if (!nid)
1872 return 0;
1873 if (snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PIN_SENSE, 0x00)
1874 & (1 << 31))
1875 return 1;
1876 return 0;
1877}
1878
1879static void stac92xx_hp_detect(struct hda_codec *codec, unsigned int res)
4e55096e
M
1880{
1881 struct sigmatel_spec *spec = codec->spec;
1882 struct auto_pin_cfg *cfg = &spec->autocfg;
1883 int i, presence;
1884
eb06ed8f
TI
1885 presence = 0;
1886 for (i = 0; i < cfg->hp_outs; i++) {
314634bc
TI
1887 presence = get_pin_presence(codec, cfg->hp_pins[i]);
1888 if (presence)
1889 break;
eb06ed8f 1890 }
4e55096e
M
1891
1892 if (presence) {
1893 /* disable lineouts, enable hp */
1894 for (i = 0; i < cfg->line_outs; i++)
1895 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
1896 AC_PINCTL_OUT_EN);
eb06ed8f
TI
1897 for (i = 0; i < cfg->speaker_outs; i++)
1898 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
1899 AC_PINCTL_OUT_EN);
4e55096e
M
1900 } else {
1901 /* enable lineouts, disable hp */
1902 for (i = 0; i < cfg->line_outs; i++)
1903 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
1904 AC_PINCTL_OUT_EN);
eb06ed8f
TI
1905 for (i = 0; i < cfg->speaker_outs; i++)
1906 stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
1907 AC_PINCTL_OUT_EN);
4e55096e
M
1908 }
1909}
1910
314634bc
TI
1911static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
1912{
1913 switch (res >> 26) {
1914 case STAC_HP_EVENT:
1915 stac92xx_hp_detect(codec, res);
1916 break;
1917 }
1918}
1919
ff6fdc37
M
1920#ifdef CONFIG_PM
1921static int stac92xx_resume(struct hda_codec *codec)
1922{
1923 struct sigmatel_spec *spec = codec->spec;
1924 int i;
1925
1926 stac92xx_init(codec);
11b44bbd 1927 stac92xx_set_config_regs(codec);
5d403b19 1928 snd_hda_resume_ctls(codec, spec->mixer);
ff6fdc37
M
1929 for (i = 0; i < spec->num_mixers; i++)
1930 snd_hda_resume_ctls(codec, spec->mixers[i]);
1931 if (spec->multiout.dig_out_nid)
1932 snd_hda_resume_spdif_out(codec);
1933 if (spec->dig_in_nid)
1934 snd_hda_resume_spdif_in(codec);
1935
1936 return 0;
1937}
1938#endif
1939
2f2f4251
M
1940static struct hda_codec_ops stac92xx_patch_ops = {
1941 .build_controls = stac92xx_build_controls,
1942 .build_pcms = stac92xx_build_pcms,
1943 .init = stac92xx_init,
1944 .free = stac92xx_free,
4e55096e 1945 .unsol_event = stac92xx_unsol_event,
ff6fdc37
M
1946#ifdef CONFIG_PM
1947 .resume = stac92xx_resume,
1948#endif
2f2f4251
M
1949};
1950
1951static int patch_stac9200(struct hda_codec *codec)
1952{
1953 struct sigmatel_spec *spec;
c7d4b2fa 1954 int err;
2f2f4251 1955
e560d8d8 1956 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2f2f4251
M
1957 if (spec == NULL)
1958 return -ENOMEM;
1959
1960 codec->spec = spec;
11b44bbd
RF
1961 spec->num_pins = 8;
1962 spec->pin_nids = stac9200_pin_nids;
f5fcc13c
TI
1963 spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS,
1964 stac9200_models,
1965 stac9200_cfg_tbl);
11b44bbd
RF
1966 if (spec->board_config < 0) {
1967 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9200, using BIOS defaults\n");
1968 err = stac92xx_save_bios_config_regs(codec);
1969 if (err < 0) {
1970 stac92xx_free(codec);
1971 return err;
1972 }
1973 spec->pin_configs = spec->bios_pin_configs;
1974 } else {
403d1944
MP
1975 spec->pin_configs = stac9200_brd_tbl[spec->board_config];
1976 stac92xx_set_config_regs(codec);
1977 }
2f2f4251
M
1978
1979 spec->multiout.max_channels = 2;
1980 spec->multiout.num_dacs = 1;
1981 spec->multiout.dac_nids = stac9200_dac_nids;
1982 spec->adc_nids = stac9200_adc_nids;
1983 spec->mux_nids = stac9200_mux_nids;
dabbed6f 1984 spec->num_muxes = 1;
8b65727b 1985 spec->num_dmics = 0;
c7d4b2fa
M
1986
1987 spec->init = stac9200_core_init;
2f2f4251 1988 spec->mixer = stac9200_mixer;
c7d4b2fa
M
1989
1990 err = stac9200_parse_auto_config(codec);
1991 if (err < 0) {
1992 stac92xx_free(codec);
1993 return err;
1994 }
2f2f4251
M
1995
1996 codec->patch_ops = stac92xx_patch_ops;
1997
1998 return 0;
1999}
2000
8e21c34c
TD
2001static int patch_stac925x(struct hda_codec *codec)
2002{
2003 struct sigmatel_spec *spec;
2004 int err;
2005
2006 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2007 if (spec == NULL)
2008 return -ENOMEM;
2009
2010 codec->spec = spec;
2011 spec->num_pins = 8;
2012 spec->pin_nids = stac925x_pin_nids;
2013 spec->board_config = snd_hda_check_board_config(codec, STAC_925x_MODELS,
2014 stac925x_models,
2015 stac925x_cfg_tbl);
9e507abd 2016 again:
8e21c34c 2017 if (spec->board_config < 0) {
2c11f955
TD
2018 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC925x,"
2019 "using BIOS defaults\n");
8e21c34c
TD
2020 err = stac92xx_save_bios_config_regs(codec);
2021 if (err < 0) {
2022 stac92xx_free(codec);
2023 return err;
2024 }
2025 spec->pin_configs = spec->bios_pin_configs;
2026 } else if (stac925x_brd_tbl[spec->board_config] != NULL){
2027 spec->pin_configs = stac925x_brd_tbl[spec->board_config];
2028 stac92xx_set_config_regs(codec);
2029 }
2030
2031 spec->multiout.max_channels = 2;
2032 spec->multiout.num_dacs = 1;
2033 spec->multiout.dac_nids = stac925x_dac_nids;
2034 spec->adc_nids = stac925x_adc_nids;
2035 spec->mux_nids = stac925x_mux_nids;
2036 spec->num_muxes = 1;
2c11f955
TD
2037 switch (codec->vendor_id) {
2038 case 0x83847632: /* STAC9202 */
2039 case 0x83847633: /* STAC9202D */
2040 case 0x83847636: /* STAC9251 */
2041 case 0x83847637: /* STAC9251D */
2042 spec->num_dmics = 1;
2043 spec->dmic_nids = stac925x_dmic_nids;
2044 break;
2045 default:
2046 spec->num_dmics = 0;
2047 break;
2048 }
8e21c34c
TD
2049
2050 spec->init = stac925x_core_init;
2051 spec->mixer = stac925x_mixer;
2052
2053 err = stac92xx_parse_auto_config(codec, 0x8, 0x7);
9e507abd
TI
2054 if (!err) {
2055 if (spec->board_config < 0) {
2056 printk(KERN_WARNING "hda_codec: No auto-config is "
2057 "available, default to model=ref\n");
2058 spec->board_config = STAC_925x_REF;
2059 goto again;
2060 }
2061 err = -EINVAL;
2062 }
8e21c34c
TD
2063 if (err < 0) {
2064 stac92xx_free(codec);
2065 return err;
2066 }
2067
2068 codec->patch_ops = stac92xx_patch_ops;
2069
2070 return 0;
2071}
2072
2f2f4251
M
2073static int patch_stac922x(struct hda_codec *codec)
2074{
2075 struct sigmatel_spec *spec;
c7d4b2fa 2076 int err;
2f2f4251 2077
e560d8d8 2078 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2f2f4251
M
2079 if (spec == NULL)
2080 return -ENOMEM;
2081
2082 codec->spec = spec;
11b44bbd
RF
2083 spec->num_pins = 10;
2084 spec->pin_nids = stac922x_pin_nids;
f5fcc13c
TI
2085 spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS,
2086 stac922x_models,
2087 stac922x_cfg_tbl);
5d5d3bc3 2088 if (spec->board_config == STAC_INTEL_MAC_V3) {
3fc24d85
TI
2089 spec->gpio_mute = 1;
2090 /* Intel Macs have all same PCI SSID, so we need to check
2091 * codec SSID to distinguish the exact models
2092 */
6f0778d8 2093 printk(KERN_INFO "hda_codec: STAC922x, Apple subsys_id=%x\n", codec->subsystem_id);
3fc24d85 2094 switch (codec->subsystem_id) {
5d5d3bc3
IZ
2095
2096 case 0x106b0800:
2097 spec->board_config = STAC_INTEL_MAC_V1;
c45e20eb 2098 break;
5d5d3bc3
IZ
2099 case 0x106b0600:
2100 case 0x106b0700:
2101 spec->board_config = STAC_INTEL_MAC_V2;
6f0778d8 2102 break;
5d5d3bc3
IZ
2103 case 0x106b0e00:
2104 case 0x106b0f00:
2105 case 0x106b1600:
2106 case 0x106b1700:
2107 case 0x106b0200:
2108 case 0x106b1e00:
2109 spec->board_config = STAC_INTEL_MAC_V3;
3fc24d85 2110 break;
5d5d3bc3
IZ
2111 case 0x106b1a00:
2112 case 0x00000100:
2113 spec->board_config = STAC_INTEL_MAC_V4;
f16928fb 2114 break;
5d5d3bc3
IZ
2115 case 0x106b0a00:
2116 case 0x106b2200:
2117 spec->board_config = STAC_INTEL_MAC_V5;
0dae0f83 2118 break;
3fc24d85
TI
2119 }
2120 }
2121
9e507abd 2122 again:
11b44bbd
RF
2123 if (spec->board_config < 0) {
2124 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC922x, "
2125 "using BIOS defaults\n");
2126 err = stac92xx_save_bios_config_regs(codec);
2127 if (err < 0) {
2128 stac92xx_free(codec);
2129 return err;
2130 }
2131 spec->pin_configs = spec->bios_pin_configs;
2132 } else if (stac922x_brd_tbl[spec->board_config] != NULL) {
403d1944
MP
2133 spec->pin_configs = stac922x_brd_tbl[spec->board_config];
2134 stac92xx_set_config_regs(codec);
2135 }
2f2f4251 2136
c7d4b2fa
M
2137 spec->adc_nids = stac922x_adc_nids;
2138 spec->mux_nids = stac922x_mux_nids;
2549413e 2139 spec->num_muxes = ARRAY_SIZE(stac922x_mux_nids);
8b65727b 2140 spec->num_dmics = 0;
c7d4b2fa
M
2141
2142 spec->init = stac922x_core_init;
2f2f4251 2143 spec->mixer = stac922x_mixer;
c7d4b2fa
M
2144
2145 spec->multiout.dac_nids = spec->dac_nids;
19039bd0 2146
3cc08dc6 2147 err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
9e507abd
TI
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_D945_REF;
2153 goto again;
2154 }
2155 err = -EINVAL;
2156 }
3cc08dc6
MP
2157 if (err < 0) {
2158 stac92xx_free(codec);
2159 return err;
2160 }
2161
2162 codec->patch_ops = stac92xx_patch_ops;
2163
807a4636
TI
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));
2170
3cc08dc6
MP
2171 return 0;
2172}
2173
2174static int patch_stac927x(struct hda_codec *codec)
2175{
2176 struct sigmatel_spec *spec;
2177 int err;
2178
2179 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2180 if (spec == NULL)
2181 return -ENOMEM;
2182
2183 codec->spec = spec;
11b44bbd
RF
2184 spec->num_pins = 14;
2185 spec->pin_nids = stac927x_pin_nids;
f5fcc13c
TI
2186 spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS,
2187 stac927x_models,
2188 stac927x_cfg_tbl);
9e507abd 2189 again:
11b44bbd 2190 if (spec->board_config < 0) {
3cc08dc6 2191 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC927x, using BIOS defaults\n");
11b44bbd
RF
2192 err = stac92xx_save_bios_config_regs(codec);
2193 if (err < 0) {
2194 stac92xx_free(codec);
2195 return err;
2196 }
2197 spec->pin_configs = spec->bios_pin_configs;
2198 } else if (stac927x_brd_tbl[spec->board_config] != NULL) {
3cc08dc6
MP
2199 spec->pin_configs = stac927x_brd_tbl[spec->board_config];
2200 stac92xx_set_config_regs(codec);
2201 }
2202
81d3dbde 2203 switch (spec->board_config) {
93ed1503 2204 case STAC_D965_3ST:
81d3dbde
TD
2205 spec->adc_nids = stac927x_adc_nids;
2206 spec->mux_nids = stac927x_mux_nids;
2549413e 2207 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
8b65727b 2208 spec->num_dmics = 0;
93ed1503 2209 spec->init = d965_core_init;
81d3dbde
TD
2210 spec->mixer = stac9227_mixer;
2211 break;
93ed1503
TD
2212 case STAC_D965_5ST:
2213 spec->adc_nids = stac927x_adc_nids;
2214 spec->mux_nids = stac927x_mux_nids;
2549413e 2215 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
8b65727b 2216 spec->num_dmics = 0;
93ed1503 2217 spec->init = d965_core_init;
81d3dbde
TD
2218 spec->mixer = stac9227_mixer;
2219 break;
2220 default:
2221 spec->adc_nids = stac927x_adc_nids;
2222 spec->mux_nids = stac927x_mux_nids;
2549413e 2223 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
8b65727b 2224 spec->num_dmics = 0;
81d3dbde
TD
2225 spec->init = stac927x_core_init;
2226 spec->mixer = stac927x_mixer;
2227 }
3cc08dc6
MP
2228
2229 spec->multiout.dac_nids = spec->dac_nids;
92a22beb
MR
2230 stac92xx_enable_eapd(codec);
2231
3cc08dc6 2232 err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
9e507abd
TI
2233 if (!err) {
2234 if (spec->board_config < 0) {
2235 printk(KERN_WARNING "hda_codec: No auto-config is "
2236 "available, default to model=ref\n");
2237 spec->board_config = STAC_D965_REF;
2238 goto again;
2239 }
2240 err = -EINVAL;
2241 }
c7d4b2fa
M
2242 if (err < 0) {
2243 stac92xx_free(codec);
2244 return err;
2245 }
2f2f4251
M
2246
2247 codec->patch_ops = stac92xx_patch_ops;
2248
897cc188
TI
2249 /* Fix Mux capture level; max to 2 */
2250 snd_hda_override_amp_caps(codec, 0x12, HDA_OUTPUT,
2251 (0 << AC_AMPCAP_OFFSET_SHIFT) |
2252 (2 << AC_AMPCAP_NUM_STEPS_SHIFT) |
2253 (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
2254 (0 << AC_AMPCAP_MUTE_SHIFT));
2255
2f2f4251
M
2256 return 0;
2257}
2258
f3302a59
MP
2259static int patch_stac9205(struct hda_codec *codec)
2260{
2261 struct sigmatel_spec *spec;
2262 int err;
2263
2264 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2265 if (spec == NULL)
2266 return -ENOMEM;
2267
2268 codec->spec = spec;
11b44bbd
RF
2269 spec->num_pins = 14;
2270 spec->pin_nids = stac9205_pin_nids;
f5fcc13c
TI
2271 spec->board_config = snd_hda_check_board_config(codec, STAC_9205_MODELS,
2272 stac9205_models,
2273 stac9205_cfg_tbl);
9e507abd 2274 again:
11b44bbd
RF
2275 if (spec->board_config < 0) {
2276 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9205, using BIOS defaults\n");
2277 err = stac92xx_save_bios_config_regs(codec);
2278 if (err < 0) {
2279 stac92xx_free(codec);
2280 return err;
2281 }
2282 spec->pin_configs = spec->bios_pin_configs;
2283 } else {
f3302a59
MP
2284 spec->pin_configs = stac9205_brd_tbl[spec->board_config];
2285 stac92xx_set_config_regs(codec);
2286 }
2287
2288 spec->adc_nids = stac9205_adc_nids;
2289 spec->mux_nids = stac9205_mux_nids;
2549413e 2290 spec->num_muxes = ARRAY_SIZE(stac9205_mux_nids);
8b65727b 2291 spec->dmic_nids = stac9205_dmic_nids;
2549413e 2292 spec->num_dmics = ARRAY_SIZE(stac9205_dmic_nids);
8b65727b 2293 spec->dmux_nid = 0x1d;
f3302a59
MP
2294
2295 spec->init = stac9205_core_init;
2296 spec->mixer = stac9205_mixer;
2297
2298 spec->multiout.dac_nids = spec->dac_nids;
92a22beb 2299 stac92xx_enable_eapd(codec);
33382403 2300
f3302a59 2301 err = stac92xx_parse_auto_config(codec, 0x1f, 0x20);
9e507abd
TI
2302 if (!err) {
2303 if (spec->board_config < 0) {
2304 printk(KERN_WARNING "hda_codec: No auto-config is "
2305 "available, default to model=ref\n");
2306 spec->board_config = STAC_9205_REF;
2307 goto again;
2308 }
2309 err = -EINVAL;
2310 }
f3302a59
MP
2311 if (err < 0) {
2312 stac92xx_free(codec);
2313 return err;
2314 }
2315
2316 codec->patch_ops = stac92xx_patch_ops;
2317
2318 return 0;
2319}
2320
db064e50 2321/*
6d859065 2322 * STAC9872 hack
db064e50
TI
2323 */
2324
99ccc560 2325/* static config for Sony VAIO FE550G and Sony VAIO AR */
db064e50
TI
2326static hda_nid_t vaio_dacs[] = { 0x2 };
2327#define VAIO_HP_DAC 0x5
2328static hda_nid_t vaio_adcs[] = { 0x8 /*,0x6*/ };
2329static hda_nid_t vaio_mux_nids[] = { 0x15 };
2330
2331static struct hda_input_mux vaio_mux = {
2332 .num_items = 2,
2333 .items = {
d773781c
TI
2334 /* { "HP", 0x0 }, */
2335 { "Line", 0x1 },
db064e50
TI
2336 { "Mic", 0x2 },
2337 { "PCM", 0x3 },
2338 }
2339};
2340
2341static struct hda_verb vaio_init[] = {
2342 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
2343 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
2344 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
2345 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
2346 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
2347 {0x15, AC_VERB_SET_CONNECT_SEL, 0x2}, /* mic-sel: 0a,0d,14,02 */
2348 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
2349 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
2350 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
2351 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
2352 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
2353 {}
2354};
2355
6d859065
GM
2356static struct hda_verb vaio_ar_init[] = {
2357 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
2358 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
2359 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
2360 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
2361/* {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },*/ /* Optical Out */
2362 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
2363 {0x15, AC_VERB_SET_CONNECT_SEL, 0x2}, /* mic-sel: 0a,0d,14,02 */
2364 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
2365 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
2366/* {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},*/ /* Optical Out */
2367 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
2368 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
2369 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
2370 {}
2371};
2372
db064e50
TI
2373/* bind volumes of both NID 0x02 and 0x05 */
2374static int vaio_master_vol_put(struct snd_kcontrol *kcontrol,
2375 struct snd_ctl_elem_value *ucontrol)
2376{
2377 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2378 long *valp = ucontrol->value.integer.value;
2379 int change;
2380
2381 change = snd_hda_codec_amp_update(codec, 0x02, 0, HDA_OUTPUT, 0,
2382 0x7f, valp[0] & 0x7f);
2383 change |= snd_hda_codec_amp_update(codec, 0x02, 1, HDA_OUTPUT, 0,
2384 0x7f, valp[1] & 0x7f);
2385 snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
2386 0x7f, valp[0] & 0x7f);
2387 snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
2388 0x7f, valp[1] & 0x7f);
2389 return change;
2390}
2391
2392/* bind volumes of both NID 0x02 and 0x05 */
2393static int vaio_master_sw_put(struct snd_kcontrol *kcontrol,
2394 struct snd_ctl_elem_value *ucontrol)
2395{
2396 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2397 long *valp = ucontrol->value.integer.value;
2398 int change;
2399
2400 change = snd_hda_codec_amp_update(codec, 0x02, 0, HDA_OUTPUT, 0,
a9393d70 2401 0x80, (valp[0] ? 0 : 0x80));
db064e50 2402 change |= snd_hda_codec_amp_update(codec, 0x02, 1, HDA_OUTPUT, 0,
a9393d70 2403 0x80, (valp[1] ? 0 : 0x80));
db064e50 2404 snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
a9393d70 2405 0x80, (valp[0] ? 0 : 0x80));
db064e50 2406 snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
a9393d70 2407 0x80, (valp[1] ? 0 : 0x80));
db064e50
TI
2408 return change;
2409}
2410
2411static struct snd_kcontrol_new vaio_mixer[] = {
2412 {
2413 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2414 .name = "Master Playback Volume",
2415 .info = snd_hda_mixer_amp_volume_info,
2416 .get = snd_hda_mixer_amp_volume_get,
2417 .put = vaio_master_vol_put,
c2566524 2418 .tlv = { .c = snd_hda_mixer_amp_tlv },
db064e50
TI
2419 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2420 },
2421 {
2422 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2423 .name = "Master Playback Switch",
2424 .info = snd_hda_mixer_amp_switch_info,
2425 .get = snd_hda_mixer_amp_switch_get,
2426 .put = vaio_master_sw_put,
2427 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2428 },
2429 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
2430 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
2431 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
2432 {
2433 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2434 .name = "Capture Source",
2435 .count = 1,
2436 .info = stac92xx_mux_enum_info,
2437 .get = stac92xx_mux_enum_get,
2438 .put = stac92xx_mux_enum_put,
2439 },
2440 {}
2441};
2442
6d859065
GM
2443static struct snd_kcontrol_new vaio_ar_mixer[] = {
2444 {
2445 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2446 .name = "Master Playback Volume",
2447 .info = snd_hda_mixer_amp_volume_info,
2448 .get = snd_hda_mixer_amp_volume_get,
2449 .put = vaio_master_vol_put,
2450 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2451 },
2452 {
2453 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2454 .name = "Master Playback Switch",
2455 .info = snd_hda_mixer_amp_switch_info,
2456 .get = snd_hda_mixer_amp_switch_get,
2457 .put = vaio_master_sw_put,
2458 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2459 },
2460 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
2461 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
2462 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
2463 /*HDA_CODEC_MUTE("Optical Out Switch", 0x10, 0, HDA_OUTPUT),
2464 HDA_CODEC_VOLUME("Optical Out Volume", 0x10, 0, HDA_OUTPUT),*/
2465 {
2466 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2467 .name = "Capture Source",
2468 .count = 1,
2469 .info = stac92xx_mux_enum_info,
2470 .get = stac92xx_mux_enum_get,
2471 .put = stac92xx_mux_enum_put,
2472 },
2473 {}
2474};
2475
2476static struct hda_codec_ops stac9872_patch_ops = {
db064e50
TI
2477 .build_controls = stac92xx_build_controls,
2478 .build_pcms = stac92xx_build_pcms,
2479 .init = stac92xx_init,
2480 .free = stac92xx_free,
2481#ifdef CONFIG_PM
2482 .resume = stac92xx_resume,
2483#endif
2484};
2485
6d859065
GM
2486enum { /* FE and SZ series. id=0x83847661 and subsys=0x104D0700 or 104D1000. */
2487 CXD9872RD_VAIO,
2488 /* Unknown. id=0x83847662 and subsys=0x104D1200 or 104D1000. */
2489 STAC9872AK_VAIO,
2490 /* Unknown. id=0x83847661 and subsys=0x104D1200. */
2491 STAC9872K_VAIO,
2492 /* AR Series. id=0x83847664 and subsys=104D1300 */
f5fcc13c
TI
2493 CXD9872AKD_VAIO,
2494 STAC_9872_MODELS,
2495};
2496
2497static const char *stac9872_models[STAC_9872_MODELS] = {
2498 [CXD9872RD_VAIO] = "vaio",
2499 [CXD9872AKD_VAIO] = "vaio-ar",
2500};
2501
2502static struct snd_pci_quirk stac9872_cfg_tbl[] = {
2503 SND_PCI_QUIRK(0x104d, 0x81e6, "Sony VAIO F/S", CXD9872RD_VAIO),
2504 SND_PCI_QUIRK(0x104d, 0x81ef, "Sony VAIO F/S", CXD9872RD_VAIO),
2505 SND_PCI_QUIRK(0x104d, 0x81fd, "Sony VAIO AR", CXD9872AKD_VAIO),
68e22543 2506 SND_PCI_QUIRK(0x104d, 0x8205, "Sony VAIO AR", CXD9872AKD_VAIO),
db064e50
TI
2507 {}
2508};
2509
6d859065 2510static int patch_stac9872(struct hda_codec *codec)
db064e50
TI
2511{
2512 struct sigmatel_spec *spec;
2513 int board_config;
2514
f5fcc13c
TI
2515 board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
2516 stac9872_models,
2517 stac9872_cfg_tbl);
db064e50
TI
2518 if (board_config < 0)
2519 /* unknown config, let generic-parser do its job... */
2520 return snd_hda_parse_generic_codec(codec);
2521
2522 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2523 if (spec == NULL)
2524 return -ENOMEM;
2525
2526 codec->spec = spec;
2527 switch (board_config) {
6d859065
GM
2528 case CXD9872RD_VAIO:
2529 case STAC9872AK_VAIO:
2530 case STAC9872K_VAIO:
db064e50
TI
2531 spec->mixer = vaio_mixer;
2532 spec->init = vaio_init;
2533 spec->multiout.max_channels = 2;
2534 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
2535 spec->multiout.dac_nids = vaio_dacs;
2536 spec->multiout.hp_nid = VAIO_HP_DAC;
2537 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
2538 spec->adc_nids = vaio_adcs;
2539 spec->input_mux = &vaio_mux;
2540 spec->mux_nids = vaio_mux_nids;
2541 break;
6d859065
GM
2542
2543 case CXD9872AKD_VAIO:
2544 spec->mixer = vaio_ar_mixer;
2545 spec->init = vaio_ar_init;
2546 spec->multiout.max_channels = 2;
2547 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
2548 spec->multiout.dac_nids = vaio_dacs;
2549 spec->multiout.hp_nid = VAIO_HP_DAC;
2550 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
2551 spec->adc_nids = vaio_adcs;
2552 spec->input_mux = &vaio_mux;
2553 spec->mux_nids = vaio_mux_nids;
2554 break;
db064e50
TI
2555 }
2556
6d859065 2557 codec->patch_ops = stac9872_patch_ops;
db064e50
TI
2558 return 0;
2559}
2560
2561
2f2f4251
M
2562/*
2563 * patch entries
2564 */
2565struct hda_codec_preset snd_hda_preset_sigmatel[] = {
2566 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
2567 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
2568 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
2569 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
2570 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
2571 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
2572 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
22a27c7f
MP
2573 { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
2574 { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
2575 { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
2576 { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
2577 { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
2578 { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
3cc08dc6
MP
2579 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
2580 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
2581 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
2582 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
2583 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
2584 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
2585 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
2586 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
2587 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
2588 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
8e21c34c
TD
2589 { .id = 0x83847632, .name = "STAC9202", .patch = patch_stac925x },
2590 { .id = 0x83847633, .name = "STAC9202D", .patch = patch_stac925x },
2591 { .id = 0x83847634, .name = "STAC9250", .patch = patch_stac925x },
2592 { .id = 0x83847635, .name = "STAC9250D", .patch = patch_stac925x },
2593 { .id = 0x83847636, .name = "STAC9251", .patch = patch_stac925x },
2594 { .id = 0x83847637, .name = "STAC9250D", .patch = patch_stac925x },
6d859065
GM
2595 /* The following does not take into account .id=0x83847661 when subsys =
2596 * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
2597 * currently not fully supported.
2598 */
2599 { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
2600 { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
2601 { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
f3302a59
MP
2602 { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
2603 { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
2604 { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
2605 { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
2606 { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
2607 { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
2608 { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
2609 { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
2f2f4251
M
2610 {} /* terminator */
2611};