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