[ALSA] Fixes typos in Audiophile-USB.txt
[linux-2.6-block.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
39#define STAC_UNSOL_ENABLE (AC_USRSP_EN | STAC_HP_EVENT)
40
403d1944
MP
41#define STAC_REF 0
42#define STAC_D945GTP3 1
43#define STAC_D945GTP5 2
44
2f2f4251 45struct sigmatel_spec {
c8b6bf9b 46 struct snd_kcontrol_new *mixers[4];
c7d4b2fa
M
47 unsigned int num_mixers;
48
403d1944 49 int board_config;
c7d4b2fa 50 unsigned int surr_switch: 1;
403d1944
MP
51 unsigned int line_switch: 1;
52 unsigned int mic_switch: 1;
3cc08dc6 53 unsigned int alt_switch: 1;
c7d4b2fa 54
2f2f4251
M
55 /* playback */
56 struct hda_multi_out multiout;
3cc08dc6 57 hda_nid_t dac_nids[5];
2f2f4251
M
58
59 /* capture */
60 hda_nid_t *adc_nids;
2f2f4251 61 unsigned int num_adcs;
dabbed6f
M
62 hda_nid_t *mux_nids;
63 unsigned int num_muxes;
dabbed6f 64 hda_nid_t dig_in_nid;
2f2f4251 65
2f2f4251
M
66 /* pin widgets */
67 hda_nid_t *pin_nids;
68 unsigned int num_pins;
2f2f4251 69 unsigned int *pin_configs;
2f2f4251
M
70
71 /* codec specific stuff */
72 struct hda_verb *init;
c8b6bf9b 73 struct snd_kcontrol_new *mixer;
2f2f4251
M
74
75 /* capture source */
c7d4b2fa 76 struct hda_input_mux *input_mux;
3cc08dc6 77 unsigned int cur_mux[3];
2f2f4251 78
403d1944
MP
79 /* i/o switches */
80 unsigned int io_switch[2];
2f2f4251 81
c7d4b2fa
M
82 struct hda_pcm pcm_rec[2]; /* PCM information */
83
84 /* dynamic controls and input_mux */
85 struct auto_pin_cfg autocfg;
86 unsigned int num_kctl_alloc, num_kctl_used;
c8b6bf9b 87 struct snd_kcontrol_new *kctl_alloc;
c7d4b2fa 88 struct hda_input_mux private_imux;
2f2f4251
M
89};
90
91static hda_nid_t stac9200_adc_nids[1] = {
92 0x03,
93};
94
95static hda_nid_t stac9200_mux_nids[1] = {
96 0x0c,
97};
98
99static hda_nid_t stac9200_dac_nids[1] = {
100 0x02,
101};
102
2f2f4251
M
103static hda_nid_t stac922x_adc_nids[2] = {
104 0x06, 0x07,
105};
106
107static hda_nid_t stac922x_mux_nids[2] = {
108 0x12, 0x13,
109};
110
3cc08dc6
MP
111static hda_nid_t stac927x_adc_nids[3] = {
112 0x07, 0x08, 0x09
113};
114
115static hda_nid_t stac927x_mux_nids[3] = {
116 0x15, 0x16, 0x17
117};
118
c7d4b2fa
M
119static hda_nid_t stac9200_pin_nids[8] = {
120 0x08, 0x09, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12,
2f2f4251
M
121};
122
123static hda_nid_t stac922x_pin_nids[10] = {
124 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
125 0x0f, 0x10, 0x11, 0x15, 0x1b,
126};
127
3cc08dc6
MP
128static hda_nid_t stac927x_pin_nids[14] = {
129 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
130 0x0f, 0x10, 0x11, 0x12, 0x13,
131 0x14, 0x21, 0x22, 0x23,
132};
133
c8b6bf9b 134static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
2f2f4251
M
135{
136 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
137 struct sigmatel_spec *spec = codec->spec;
c7d4b2fa 138 return snd_hda_input_mux_info(spec->input_mux, uinfo);
2f2f4251
M
139}
140
c8b6bf9b 141static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2f2f4251
M
142{
143 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
144 struct sigmatel_spec *spec = codec->spec;
145 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
146
147 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
148 return 0;
149}
150
c8b6bf9b 151static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2f2f4251
M
152{
153 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
154 struct sigmatel_spec *spec = codec->spec;
155 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
156
c7d4b2fa 157 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
2f2f4251
M
158 spec->mux_nids[adc_idx], &spec->cur_mux[adc_idx]);
159}
160
c7d4b2fa 161static struct hda_verb stac9200_core_init[] = {
2f2f4251 162 /* set dac0mux for dac converter */
c7d4b2fa 163 { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
2f2f4251
M
164 {}
165};
166
c7d4b2fa 167static struct hda_verb stac922x_core_init[] = {
2f2f4251 168 /* set master volume and direct control */
c7d4b2fa 169 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
2f2f4251
M
170 {}
171};
172
3cc08dc6
MP
173static struct hda_verb stac927x_core_init[] = {
174 /* set master volume and direct control */
175 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
176 {}
177};
178
c8b6bf9b 179static struct snd_kcontrol_new stac9200_mixer[] = {
2f2f4251
M
180 HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
181 HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
182 {
183 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
184 .name = "Input Source",
185 .count = 1,
186 .info = stac92xx_mux_enum_info,
187 .get = stac92xx_mux_enum_get,
188 .put = stac92xx_mux_enum_put,
189 },
190 HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
191 HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
c7d4b2fa 192 HDA_CODEC_VOLUME("Capture Mux Volume", 0x0c, 0, HDA_OUTPUT),
2f2f4251
M
193 { } /* end */
194};
195
c7d4b2fa 196/* This needs to be generated dynamically based on sequence */
c8b6bf9b 197static struct snd_kcontrol_new stac922x_mixer[] = {
2f2f4251
M
198 {
199 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
200 .name = "Input Source",
201 .count = 1,
202 .info = stac92xx_mux_enum_info,
203 .get = stac92xx_mux_enum_get,
204 .put = stac92xx_mux_enum_put,
205 },
206 HDA_CODEC_VOLUME("Capture Volume", 0x17, 0x0, HDA_INPUT),
0fd1708a 207 HDA_CODEC_MUTE("Capture Switch", 0x17, 0x0, HDA_INPUT),
2f2f4251
M
208 HDA_CODEC_VOLUME("Mux Capture Volume", 0x12, 0x0, HDA_OUTPUT),
209 { } /* end */
210};
211
3cc08dc6
MP
212static snd_kcontrol_new_t stac927x_mixer[] = {
213 {
214 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
215 .name = "Input Source",
216 .count = 1,
217 .info = stac92xx_mux_enum_info,
218 .get = stac92xx_mux_enum_get,
219 .put = stac92xx_mux_enum_put,
220 },
221 HDA_CODEC_VOLUME("InMux Capture Volume", 0x15, 0x0, HDA_OUTPUT),
222 HDA_CODEC_VOLUME("InVol Capture Volume", 0x18, 0x0, HDA_INPUT),
223 HDA_CODEC_MUTE("ADCMux Capture Switch", 0x1b, 0x0, HDA_OUTPUT),
224 { } /* end */
225};
226
2f2f4251
M
227static int stac92xx_build_controls(struct hda_codec *codec)
228{
229 struct sigmatel_spec *spec = codec->spec;
230 int err;
c7d4b2fa 231 int i;
2f2f4251
M
232
233 err = snd_hda_add_new_ctls(codec, spec->mixer);
234 if (err < 0)
235 return err;
c7d4b2fa
M
236
237 for (i = 0; i < spec->num_mixers; i++) {
238 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
239 if (err < 0)
240 return err;
241 }
242
dabbed6f
M
243 if (spec->multiout.dig_out_nid) {
244 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
245 if (err < 0)
246 return err;
247 }
248 if (spec->dig_in_nid) {
249 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
250 if (err < 0)
251 return err;
252 }
253 return 0;
2f2f4251
M
254}
255
403d1944 256static unsigned int ref9200_pin_configs[8] = {
dabbed6f 257 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
2f2f4251
M
258 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
259};
260
403d1944
MP
261static unsigned int *stac9200_brd_tbl[] = {
262 ref9200_pin_configs,
263};
264
265static struct hda_board_config stac9200_cfg_tbl[] = {
266 { .modelname = "ref",
267 .pci_subvendor = PCI_VENDOR_ID_INTEL,
268 .pci_subdevice = 0x2668, /* DFI LanParty */
269 .config = STAC_REF },
270 {} /* terminator */
271};
272
273static unsigned int ref922x_pin_configs[10] = {
274 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
275 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
2f2f4251
M
276 0x40000100, 0x40000100,
277};
278
403d1944 279static unsigned int d945gtp3_pin_configs[10] = {
869264c4 280 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
403d1944
MP
281 0x40000100, 0x40000100, 0x40000100, 0x40000100,
282 0x02a19120, 0x40000100,
283};
284
285static unsigned int d945gtp5_pin_configs[10] = {
869264c4
MP
286 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
287 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
403d1944
MP
288 0x02a19320, 0x40000100,
289};
290
291static unsigned int *stac922x_brd_tbl[] = {
292 ref922x_pin_configs,
293 d945gtp3_pin_configs,
294 d945gtp5_pin_configs,
295};
296
297static struct hda_board_config stac922x_cfg_tbl[] = {
298 { .modelname = "ref",
299 .pci_subvendor = PCI_VENDOR_ID_INTEL,
300 .pci_subdevice = 0x2668, /* DFI LanParty */
301 .config = STAC_REF }, /* SigmaTel reference board */
302 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
303 .pci_subdevice = 0x0101,
304 .config = STAC_D945GTP3 }, /* Intel D945GTP - 3 Stack */
353b9e66
TI
305 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
306 .pci_subdevice = 0x0202,
307 .config = STAC_D945GTP3 }, /* Intel D945GNT - 3 Stack, 9221 A1 */
308 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
309 .pci_subdevice = 0x0b0b,
310 .config = STAC_D945GTP3 }, /* Intel D945PSN - 3 Stack, 9221 A1 */
403d1944
MP
311 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
312 .pci_subdevice = 0x0404,
313 .config = STAC_D945GTP5 }, /* Intel D945GTP - 5 Stack */
314 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
315 .pci_subdevice = 0x0303,
316 .config = STAC_D945GTP5 }, /* Intel D945GNT - 5 Stack */
317 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
318 .pci_subdevice = 0x0013,
319 .config = STAC_D945GTP5 }, /* Intel D955XBK - 5 Stack */
d62c40e0
MP
320 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
321 .pci_subdevice = 0x0417,
322 .config = STAC_D945GTP5 }, /* Intel D975XBK - 5 Stack */
403d1944
MP
323 {} /* terminator */
324};
325
3cc08dc6
MP
326static unsigned int ref927x_pin_configs[14] = {
327 0x01813122, 0x01a19021, 0x01014010, 0x01016011,
328 0x01012012, 0x01011014, 0x40000100, 0x40000100,
329 0x40000100, 0x40000100, 0x40000100, 0x01441030,
330 0x01c41030, 0x40000100,
331};
332
333static unsigned int *stac927x_brd_tbl[] = {
334 ref927x_pin_configs,
335};
336
337static struct hda_board_config stac927x_cfg_tbl[] = {
338 { .modelname = "ref",
339 .pci_subvendor = PCI_VENDOR_ID_INTEL,
340 .pci_subdevice = 0x2668, /* DFI LanParty */
341 .config = STAC_REF }, /* SigmaTel reference board */
342 {} /* terminator */
343};
344
2f2f4251
M
345static void stac92xx_set_config_regs(struct hda_codec *codec)
346{
347 int i;
348 struct sigmatel_spec *spec = codec->spec;
349 unsigned int pin_cfg;
350
351 for (i=0; i < spec->num_pins; i++) {
352 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
353 AC_VERB_SET_CONFIG_DEFAULT_BYTES_0,
354 spec->pin_configs[i] & 0x000000ff);
355 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
356 AC_VERB_SET_CONFIG_DEFAULT_BYTES_1,
357 (spec->pin_configs[i] & 0x0000ff00) >> 8);
358 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
359 AC_VERB_SET_CONFIG_DEFAULT_BYTES_2,
360 (spec->pin_configs[i] & 0x00ff0000) >> 16);
361 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
362 AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
363 spec->pin_configs[i] >> 24);
364 pin_cfg = snd_hda_codec_read(codec, spec->pin_nids[i], 0,
365 AC_VERB_GET_CONFIG_DEFAULT,
366 0x00);
403d1944 367 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x pin config %8.8x\n", spec->pin_nids[i], pin_cfg);
2f2f4251
M
368 }
369}
2f2f4251 370
dabbed6f 371/*
c7d4b2fa 372 * Analog playback callbacks
dabbed6f 373 */
c7d4b2fa
M
374static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
375 struct hda_codec *codec,
c8b6bf9b 376 struct snd_pcm_substream *substream)
2f2f4251 377{
dabbed6f 378 struct sigmatel_spec *spec = codec->spec;
c7d4b2fa 379 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
2f2f4251
M
380}
381
2f2f4251
M
382static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
383 struct hda_codec *codec,
384 unsigned int stream_tag,
385 unsigned int format,
c8b6bf9b 386 struct snd_pcm_substream *substream)
2f2f4251
M
387{
388 struct sigmatel_spec *spec = codec->spec;
403d1944 389 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
2f2f4251
M
390}
391
392static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
393 struct hda_codec *codec,
c8b6bf9b 394 struct snd_pcm_substream *substream)
2f2f4251
M
395{
396 struct sigmatel_spec *spec = codec->spec;
397 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
398}
399
dabbed6f
M
400/*
401 * Digital playback callbacks
402 */
403static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
404 struct hda_codec *codec,
c8b6bf9b 405 struct snd_pcm_substream *substream)
dabbed6f
M
406{
407 struct sigmatel_spec *spec = codec->spec;
408 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
409}
410
411static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
412 struct hda_codec *codec,
c8b6bf9b 413 struct snd_pcm_substream *substream)
dabbed6f
M
414{
415 struct sigmatel_spec *spec = codec->spec;
416 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
417}
418
419
2f2f4251
M
420/*
421 * Analog capture callbacks
422 */
423static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
424 struct hda_codec *codec,
425 unsigned int stream_tag,
426 unsigned int format,
c8b6bf9b 427 struct snd_pcm_substream *substream)
2f2f4251
M
428{
429 struct sigmatel_spec *spec = codec->spec;
430
431 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
432 stream_tag, 0, format);
433 return 0;
434}
435
436static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
437 struct hda_codec *codec,
c8b6bf9b 438 struct snd_pcm_substream *substream)
2f2f4251
M
439{
440 struct sigmatel_spec *spec = codec->spec;
441
442 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 0, 0, 0);
443 return 0;
444}
445
dabbed6f
M
446static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
447 .substreams = 1,
448 .channels_min = 2,
449 .channels_max = 2,
450 /* NID is set in stac92xx_build_pcms */
451 .ops = {
452 .open = stac92xx_dig_playback_pcm_open,
453 .close = stac92xx_dig_playback_pcm_close
454 },
455};
456
457static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
458 .substreams = 1,
459 .channels_min = 2,
460 .channels_max = 2,
461 /* NID is set in stac92xx_build_pcms */
462};
463
2f2f4251
M
464static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
465 .substreams = 1,
466 .channels_min = 2,
c7d4b2fa 467 .channels_max = 8,
2f2f4251
M
468 .nid = 0x02, /* NID to query formats and rates */
469 .ops = {
470 .open = stac92xx_playback_pcm_open,
471 .prepare = stac92xx_playback_pcm_prepare,
472 .cleanup = stac92xx_playback_pcm_cleanup
473 },
474};
475
3cc08dc6
MP
476static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
477 .substreams = 1,
478 .channels_min = 2,
479 .channels_max = 2,
480 .nid = 0x06, /* NID to query formats and rates */
481 .ops = {
482 .open = stac92xx_playback_pcm_open,
483 .prepare = stac92xx_playback_pcm_prepare,
484 .cleanup = stac92xx_playback_pcm_cleanup
485 },
486};
487
2f2f4251
M
488static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
489 .substreams = 2,
490 .channels_min = 2,
491 .channels_max = 2,
3cc08dc6 492 /* NID is set in stac92xx_build_pcms */
2f2f4251
M
493 .ops = {
494 .prepare = stac92xx_capture_pcm_prepare,
495 .cleanup = stac92xx_capture_pcm_cleanup
496 },
497};
498
499static int stac92xx_build_pcms(struct hda_codec *codec)
500{
501 struct sigmatel_spec *spec = codec->spec;
502 struct hda_pcm *info = spec->pcm_rec;
503
504 codec->num_pcms = 1;
505 codec->pcm_info = info;
506
c7d4b2fa 507 info->name = "STAC92xx Analog";
2f2f4251 508 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
2f2f4251 509 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
3cc08dc6
MP
510 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
511
512 if (spec->alt_switch) {
513 codec->num_pcms++;
514 info++;
515 info->name = "STAC92xx Analog Alt";
516 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
517 }
2f2f4251 518
dabbed6f
M
519 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
520 codec->num_pcms++;
521 info++;
522 info->name = "STAC92xx Digital";
523 if (spec->multiout.dig_out_nid) {
524 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
525 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
526 }
527 if (spec->dig_in_nid) {
528 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
529 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
530 }
531 }
532
2f2f4251
M
533 return 0;
534}
535
403d1944
MP
536static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
537
538{
539 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
540}
541
542static int stac92xx_io_switch_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
543{
544 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
545 uinfo->count = 1;
546 uinfo->value.integer.min = 0;
547 uinfo->value.integer.max = 1;
548 return 0;
549}
550
551static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
552{
553 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
554 struct sigmatel_spec *spec = codec->spec;
555 int io_idx = kcontrol-> private_value & 0xff;
556
557 ucontrol->value.integer.value[0] = spec->io_switch[io_idx];
558 return 0;
559}
560
561static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
562{
563 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
564 struct sigmatel_spec *spec = codec->spec;
565 hda_nid_t nid = kcontrol->private_value >> 8;
566 int io_idx = kcontrol-> private_value & 0xff;
567 unsigned short val = ucontrol->value.integer.value[0];
568
569 spec->io_switch[io_idx] = val;
570
571 if (val)
572 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
573 else
574 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_IN_EN);
575
576 return 1;
577}
578
579#define STAC_CODEC_IO_SWITCH(xname, xpval) \
580 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
581 .name = xname, \
582 .index = 0, \
583 .info = stac92xx_io_switch_info, \
584 .get = stac92xx_io_switch_get, \
585 .put = stac92xx_io_switch_put, \
586 .private_value = xpval, \
587 }
588
589
c7d4b2fa
M
590enum {
591 STAC_CTL_WIDGET_VOL,
592 STAC_CTL_WIDGET_MUTE,
403d1944 593 STAC_CTL_WIDGET_IO_SWITCH,
c7d4b2fa
M
594};
595
c8b6bf9b 596static struct snd_kcontrol_new stac92xx_control_templates[] = {
c7d4b2fa
M
597 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
598 HDA_CODEC_MUTE(NULL, 0, 0, 0),
403d1944 599 STAC_CODEC_IO_SWITCH(NULL, 0),
c7d4b2fa
M
600};
601
602/* add dynamic controls */
603static int stac92xx_add_control(struct sigmatel_spec *spec, int type, const char *name, unsigned long val)
604{
c8b6bf9b 605 struct snd_kcontrol_new *knew;
c7d4b2fa
M
606
607 if (spec->num_kctl_used >= spec->num_kctl_alloc) {
608 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
609
610 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */
611 if (! knew)
612 return -ENOMEM;
613 if (spec->kctl_alloc) {
614 memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
615 kfree(spec->kctl_alloc);
616 }
617 spec->kctl_alloc = knew;
618 spec->num_kctl_alloc = num;
619 }
620
621 knew = &spec->kctl_alloc[spec->num_kctl_used];
622 *knew = stac92xx_control_templates[type];
82fe0c58 623 knew->name = kstrdup(name, GFP_KERNEL);
c7d4b2fa
M
624 if (! knew->name)
625 return -ENOMEM;
626 knew->private_value = val;
627 spec->num_kctl_used++;
628 return 0;
629}
630
403d1944
MP
631/* flag inputs as additional dynamic lineouts */
632static int stac92xx_add_dyn_out_pins(struct hda_codec *codec, struct auto_pin_cfg *cfg)
633{
634 struct sigmatel_spec *spec = codec->spec;
635
636 switch (cfg->line_outs) {
637 case 3:
638 /* add line-in as side */
639 if (cfg->input_pins[AUTO_PIN_LINE]) {
640 cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_LINE];
641 spec->line_switch = 1;
642 cfg->line_outs++;
643 }
644 break;
645 case 2:
646 /* add line-in as clfe and mic as side */
647 if (cfg->input_pins[AUTO_PIN_LINE]) {
648 cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_LINE];
649 spec->line_switch = 1;
650 cfg->line_outs++;
651 }
652 if (cfg->input_pins[AUTO_PIN_MIC]) {
653 cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_MIC];
654 spec->mic_switch = 1;
655 cfg->line_outs++;
656 }
657 break;
658 case 1:
659 /* add line-in as surr and mic as clfe */
660 if (cfg->input_pins[AUTO_PIN_LINE]) {
661 cfg->line_out_pins[1] = cfg->input_pins[AUTO_PIN_LINE];
662 spec->line_switch = 1;
663 cfg->line_outs++;
664 }
665 if (cfg->input_pins[AUTO_PIN_MIC]) {
666 cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_MIC];
667 spec->mic_switch = 1;
668 cfg->line_outs++;
669 }
670 break;
671 }
672
673 return 0;
674}
675
3cc08dc6
MP
676/*
677 * XXX The line_out pin widget connection list may not be set to the
678 * desired DAC nid. This is the case on 927x where ports A and B can
679 * be routed to several DACs.
680 *
681 * This requires an analysis of the line-out/hp pin configuration
682 * to provide a best fit for pin/DAC configurations that are routable.
683 * For now, 927x DAC4 is not supported and 927x DAC1 output to ports
684 * A and B is not supported.
685 */
c7d4b2fa
M
686/* fill in the dac_nids table from the parsed pin configuration */
687static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
688{
689 struct sigmatel_spec *spec = codec->spec;
690 hda_nid_t nid;
691 int i;
692
693 /* check the pins hardwired to audio widget */
694 for (i = 0; i < cfg->line_outs; i++) {
695 nid = cfg->line_out_pins[i];
696 spec->multiout.dac_nids[i] = snd_hda_codec_read(codec, nid, 0,
697 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
698 }
699
ad0651f9
TI
700 if (cfg->line_outs)
701 spec->multiout.num_dacs = cfg->line_outs;
702 else if (cfg->hp_pin) {
703 spec->multiout.dac_nids[0] = snd_hda_codec_read(codec, cfg->hp_pin, 0,
704 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
705 spec->multiout.num_dacs = 1;
706 }
c7d4b2fa
M
707
708 return 0;
709}
710
711/* add playback controls from the parsed DAC table */
712static int stac92xx_auto_create_multi_out_ctls(struct sigmatel_spec *spec, const struct auto_pin_cfg *cfg)
713{
714 char name[32];
715 static const char *chname[4] = { "Front", "Surround", NULL /*CLFE*/, "Side" };
716 hda_nid_t nid;
717 int i, err;
718
719 for (i = 0; i < cfg->line_outs; i++) {
403d1944 720 if (!spec->multiout.dac_nids[i])
c7d4b2fa
M
721 continue;
722
723 nid = spec->multiout.dac_nids[i];
724
725 if (i == 2) {
726 /* Center/LFE */
727 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, "Center Playback Volume",
728 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT))) < 0)
729 return err;
730 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, "LFE Playback Volume",
731 HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT))) < 0)
732 return err;
733 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, "Center Playback Switch",
734 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT))) < 0)
735 return err;
736 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, "LFE Playback Switch",
737 HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT))) < 0)
738 return err;
739 } else {
740 sprintf(name, "%s Playback Volume", chname[i]);
741 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, name,
742 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
743 return err;
744 sprintf(name, "%s Playback Switch", chname[i]);
745 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, name,
746 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
747 return err;
748 }
749 }
750
403d1944
MP
751 if (spec->line_switch)
752 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Line In as Output Switch", cfg->input_pins[AUTO_PIN_LINE] << 8)) < 0)
753 return err;
754
755 if (spec->mic_switch)
756 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Mic as Output Switch", (cfg->input_pins[AUTO_PIN_MIC] << 8) | 1)) < 0)
757 return err;
758
c7d4b2fa
M
759 return 0;
760}
761
762/* add playback controls for HP output */
763static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec, struct auto_pin_cfg *cfg)
764{
765 struct sigmatel_spec *spec = codec->spec;
766 hda_nid_t pin = cfg->hp_pin;
767 hda_nid_t nid;
768 int i, err;
4e55096e 769 unsigned int wid_caps;
c7d4b2fa
M
770
771 if (! pin)
772 return 0;
773
54d17403 774 wid_caps = get_wcaps(codec, pin);
4e55096e
M
775 if (wid_caps & AC_WCAP_UNSOL_CAP)
776 /* Enable unsolicited responses on the HP widget */
777 snd_hda_codec_write(codec, pin, 0,
778 AC_VERB_SET_UNSOLICITED_ENABLE,
779 STAC_UNSOL_ENABLE);
780
c7d4b2fa
M
781 nid = snd_hda_codec_read(codec, pin, 0, AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
782 for (i = 0; i < cfg->line_outs; i++) {
783 if (! spec->multiout.dac_nids[i])
784 continue;
785 if (spec->multiout.dac_nids[i] == nid)
786 return 0;
787 }
788
789 spec->multiout.hp_nid = nid;
790
791 /* control HP volume/switch on the output mixer amp */
792 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, "Headphone Playback Volume",
793 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
794 return err;
795 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, "Headphone Playback Switch",
796 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
797 return err;
798
799 return 0;
800}
801
802/* create playback/capture controls for input pins */
803static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
804{
805 struct sigmatel_spec *spec = codec->spec;
c7d4b2fa
M
806 struct hda_input_mux *imux = &spec->private_imux;
807 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
808 int i, j, k;
809
810 for (i = 0; i < AUTO_PIN_LAST; i++) {
811 int index = -1;
812 if (cfg->input_pins[i]) {
403d1944
MP
813 /* Enable active pin widget as an input */
814 stac92xx_auto_set_pinctl(codec, cfg->input_pins[i], AC_PINCTL_IN_EN);
815
4a471b7d 816 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
c7d4b2fa
M
817
818 for (j=0; j<spec->num_muxes; j++) {
819 int num_cons = snd_hda_get_connections(codec, spec->mux_nids[j], con_lst, HDA_MAX_NUM_INPUTS);
820 for (k=0; k<num_cons; k++)
821 if (con_lst[k] == cfg->input_pins[i]) {
822 index = k;
823 break;
824 }
825 if (index >= 0)
826 break;
827 }
828 imux->items[imux->num_items].index = index;
829 imux->num_items++;
830 }
831 }
832
833 return 0;
834}
835
c7d4b2fa
M
836static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
837{
838 struct sigmatel_spec *spec = codec->spec;
839 int i;
840
841 for (i = 0; i < spec->autocfg.line_outs; i++) {
842 hda_nid_t nid = spec->autocfg.line_out_pins[i];
843 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
844 }
845}
846
847static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
848{
849 struct sigmatel_spec *spec = codec->spec;
850 hda_nid_t pin;
851
852 pin = spec->autocfg.hp_pin;
853 if (pin) /* connect to front */
854 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
855}
856
3cc08dc6 857static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out, hda_nid_t dig_in)
c7d4b2fa
M
858{
859 struct sigmatel_spec *spec = codec->spec;
860 int err;
861
df694daa 862 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
c7d4b2fa 863 return err;
869264c4
MP
864 if (! spec->autocfg.line_outs && ! spec->autocfg.hp_pin)
865 return 0; /* can't find valid pin config */
866 stac92xx_auto_init_multi_out(codec);
867 stac92xx_auto_init_hp_out(codec);
403d1944
MP
868 if ((err = stac92xx_add_dyn_out_pins(codec, &spec->autocfg)) < 0)
869 return err;
c7d4b2fa
M
870 if ((err = stac92xx_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
871 return err;
c7d4b2fa
M
872
873 if ((err = stac92xx_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
874 (err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg)) < 0 ||
875 (err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
876 return err;
877
878 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
403d1944 879 if (spec->multiout.max_channels > 2)
c7d4b2fa 880 spec->surr_switch = 1;
c7d4b2fa
M
881
882 if (spec->autocfg.dig_out_pin) {
3cc08dc6 883 spec->multiout.dig_out_nid = dig_out;
c7d4b2fa
M
884 stac92xx_auto_set_pinctl(codec, spec->autocfg.dig_out_pin, AC_PINCTL_OUT_EN);
885 }
886 if (spec->autocfg.dig_in_pin) {
3cc08dc6 887 spec->dig_in_nid = dig_in;
c7d4b2fa
M
888 stac92xx_auto_set_pinctl(codec, spec->autocfg.dig_in_pin, AC_PINCTL_IN_EN);
889 }
890
891 if (spec->kctl_alloc)
892 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
893
894 spec->input_mux = &spec->private_imux;
895
896 return 1;
897}
898
899static int stac9200_parse_auto_config(struct hda_codec *codec)
900{
901 struct sigmatel_spec *spec = codec->spec;
902 int err;
903
df694daa 904 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
c7d4b2fa
M
905 return err;
906
907 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
908 return err;
909
910 if (spec->autocfg.dig_out_pin) {
911 spec->multiout.dig_out_nid = 0x05;
912 stac92xx_auto_set_pinctl(codec, spec->autocfg.dig_out_pin, AC_PINCTL_OUT_EN);
913 }
914 if (spec->autocfg.dig_in_pin) {
915 spec->dig_in_nid = 0x04;
916 stac92xx_auto_set_pinctl(codec, spec->autocfg.dig_in_pin, AC_PINCTL_IN_EN);
917 }
918
919 if (spec->kctl_alloc)
920 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
921
922 spec->input_mux = &spec->private_imux;
923
924 return 1;
925}
926
c7d4b2fa
M
927static int stac92xx_init(struct hda_codec *codec)
928{
929 struct sigmatel_spec *spec = codec->spec;
930
c7d4b2fa
M
931 snd_hda_sequence_write(codec, spec->init);
932
c7d4b2fa
M
933 return 0;
934}
935
2f2f4251
M
936static void stac92xx_free(struct hda_codec *codec)
937{
c7d4b2fa
M
938 struct sigmatel_spec *spec = codec->spec;
939 int i;
940
941 if (! spec)
942 return;
943
944 if (spec->kctl_alloc) {
945 for (i = 0; i < spec->num_kctl_used; i++)
946 kfree(spec->kctl_alloc[i].name);
947 kfree(spec->kctl_alloc);
948 }
949
950 kfree(spec);
2f2f4251
M
951}
952
4e55096e
M
953static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
954 unsigned int flag)
955{
956 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
957 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
958 snd_hda_codec_write(codec, nid, 0,
959 AC_VERB_SET_PIN_WIDGET_CONTROL,
960 pin_ctl | flag);
961}
962
963static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
964 unsigned int flag)
965{
966 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
967 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
968 snd_hda_codec_write(codec, nid, 0,
969 AC_VERB_SET_PIN_WIDGET_CONTROL,
970 pin_ctl & ~flag);
971}
972
973static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
974{
975 struct sigmatel_spec *spec = codec->spec;
976 struct auto_pin_cfg *cfg = &spec->autocfg;
977 int i, presence;
978
979 if ((res >> 26) != STAC_HP_EVENT)
980 return;
981
982 presence = snd_hda_codec_read(codec, cfg->hp_pin, 0,
983 AC_VERB_GET_PIN_SENSE, 0x00) >> 31;
984
985 if (presence) {
986 /* disable lineouts, enable hp */
987 for (i = 0; i < cfg->line_outs; i++)
988 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
989 AC_PINCTL_OUT_EN);
990 stac92xx_set_pinctl(codec, cfg->hp_pin, AC_PINCTL_OUT_EN);
991 } else {
992 /* enable lineouts, disable hp */
993 for (i = 0; i < cfg->line_outs; i++)
994 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
995 AC_PINCTL_OUT_EN);
996 stac92xx_reset_pinctl(codec, cfg->hp_pin, AC_PINCTL_OUT_EN);
997 }
998}
999
ff6fdc37
M
1000#ifdef CONFIG_PM
1001static int stac92xx_resume(struct hda_codec *codec)
1002{
1003 struct sigmatel_spec *spec = codec->spec;
1004 int i;
1005
1006 stac92xx_init(codec);
1007 for (i = 0; i < spec->num_mixers; i++)
1008 snd_hda_resume_ctls(codec, spec->mixers[i]);
1009 if (spec->multiout.dig_out_nid)
1010 snd_hda_resume_spdif_out(codec);
1011 if (spec->dig_in_nid)
1012 snd_hda_resume_spdif_in(codec);
1013
1014 return 0;
1015}
1016#endif
1017
2f2f4251
M
1018static struct hda_codec_ops stac92xx_patch_ops = {
1019 .build_controls = stac92xx_build_controls,
1020 .build_pcms = stac92xx_build_pcms,
1021 .init = stac92xx_init,
1022 .free = stac92xx_free,
4e55096e 1023 .unsol_event = stac92xx_unsol_event,
ff6fdc37
M
1024#ifdef CONFIG_PM
1025 .resume = stac92xx_resume,
1026#endif
2f2f4251
M
1027};
1028
1029static int patch_stac9200(struct hda_codec *codec)
1030{
1031 struct sigmatel_spec *spec;
c7d4b2fa 1032 int err;
2f2f4251 1033
e560d8d8 1034 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2f2f4251
M
1035 if (spec == NULL)
1036 return -ENOMEM;
1037
1038 codec->spec = spec;
403d1944
MP
1039 spec->board_config = snd_hda_check_board_config(codec, stac9200_cfg_tbl);
1040 if (spec->board_config < 0)
1041 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9200, using BIOS defaults\n");
1042 else {
1043 spec->num_pins = 8;
1044 spec->pin_nids = stac9200_pin_nids;
1045 spec->pin_configs = stac9200_brd_tbl[spec->board_config];
1046 stac92xx_set_config_regs(codec);
1047 }
2f2f4251
M
1048
1049 spec->multiout.max_channels = 2;
1050 spec->multiout.num_dacs = 1;
1051 spec->multiout.dac_nids = stac9200_dac_nids;
1052 spec->adc_nids = stac9200_adc_nids;
1053 spec->mux_nids = stac9200_mux_nids;
dabbed6f 1054 spec->num_muxes = 1;
c7d4b2fa
M
1055
1056 spec->init = stac9200_core_init;
2f2f4251 1057 spec->mixer = stac9200_mixer;
c7d4b2fa
M
1058
1059 err = stac9200_parse_auto_config(codec);
1060 if (err < 0) {
1061 stac92xx_free(codec);
1062 return err;
1063 }
2f2f4251
M
1064
1065 codec->patch_ops = stac92xx_patch_ops;
1066
1067 return 0;
1068}
1069
1070static int patch_stac922x(struct hda_codec *codec)
1071{
1072 struct sigmatel_spec *spec;
c7d4b2fa 1073 int err;
2f2f4251 1074
e560d8d8 1075 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2f2f4251
M
1076 if (spec == NULL)
1077 return -ENOMEM;
1078
1079 codec->spec = spec;
403d1944
MP
1080 spec->board_config = snd_hda_check_board_config(codec, stac922x_cfg_tbl);
1081 if (spec->board_config < 0)
1082 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC922x, using BIOS defaults\n");
1083 else {
1084 spec->num_pins = 10;
1085 spec->pin_nids = stac922x_pin_nids;
1086 spec->pin_configs = stac922x_brd_tbl[spec->board_config];
1087 stac92xx_set_config_regs(codec);
1088 }
2f2f4251 1089
c7d4b2fa
M
1090 spec->adc_nids = stac922x_adc_nids;
1091 spec->mux_nids = stac922x_mux_nids;
1092 spec->num_muxes = 2;
1093
1094 spec->init = stac922x_core_init;
2f2f4251 1095 spec->mixer = stac922x_mixer;
c7d4b2fa
M
1096
1097 spec->multiout.dac_nids = spec->dac_nids;
1098
3cc08dc6
MP
1099 err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
1100 if (err < 0) {
1101 stac92xx_free(codec);
1102 return err;
1103 }
1104
1105 codec->patch_ops = stac92xx_patch_ops;
1106
1107 return 0;
1108}
1109
1110static int patch_stac927x(struct hda_codec *codec)
1111{
1112 struct sigmatel_spec *spec;
1113 int err;
1114
1115 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1116 if (spec == NULL)
1117 return -ENOMEM;
1118
1119 codec->spec = spec;
1120 spec->board_config = snd_hda_check_board_config(codec, stac927x_cfg_tbl);
1121 if (spec->board_config < 0)
1122 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC927x, using BIOS defaults\n");
1123 else {
1124 spec->num_pins = 14;
1125 spec->pin_nids = stac927x_pin_nids;
1126 spec->pin_configs = stac927x_brd_tbl[spec->board_config];
1127 stac92xx_set_config_regs(codec);
1128 }
1129
1130 spec->adc_nids = stac927x_adc_nids;
1131 spec->mux_nids = stac927x_mux_nids;
1132 spec->num_muxes = 3;
1133
1134 spec->init = stac927x_core_init;
1135 spec->mixer = stac927x_mixer;
1136
1137 spec->multiout.dac_nids = spec->dac_nids;
1138
1139 err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
c7d4b2fa
M
1140 if (err < 0) {
1141 stac92xx_free(codec);
1142 return err;
1143 }
2f2f4251
M
1144
1145 codec->patch_ops = stac92xx_patch_ops;
1146
1147 return 0;
1148}
1149
db064e50
TI
1150/*
1151 * STAC 7661(?) hack
1152 */
1153
1154/* static config for Sony VAIO FE550G */
1155static hda_nid_t vaio_dacs[] = { 0x2 };
1156#define VAIO_HP_DAC 0x5
1157static hda_nid_t vaio_adcs[] = { 0x8 /*,0x6*/ };
1158static hda_nid_t vaio_mux_nids[] = { 0x15 };
1159
1160static struct hda_input_mux vaio_mux = {
1161 .num_items = 2,
1162 .items = {
1163 /* { "HP", 0x0 },
1164 { "Unknown", 0x1 }, */
1165 { "Mic", 0x2 },
1166 { "PCM", 0x3 },
1167 }
1168};
1169
1170static struct hda_verb vaio_init[] = {
1171 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
1172 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
1173 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
1174 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
1175 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
1176 {0x15, AC_VERB_SET_CONNECT_SEL, 0x2}, /* mic-sel: 0a,0d,14,02 */
1177 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
1178 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
1179 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
1180 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
1181 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
1182 {}
1183};
1184
1185/* bind volumes of both NID 0x02 and 0x05 */
1186static int vaio_master_vol_put(struct snd_kcontrol *kcontrol,
1187 struct snd_ctl_elem_value *ucontrol)
1188{
1189 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1190 long *valp = ucontrol->value.integer.value;
1191 int change;
1192
1193 change = snd_hda_codec_amp_update(codec, 0x02, 0, HDA_OUTPUT, 0,
1194 0x7f, valp[0] & 0x7f);
1195 change |= snd_hda_codec_amp_update(codec, 0x02, 1, HDA_OUTPUT, 0,
1196 0x7f, valp[1] & 0x7f);
1197 snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
1198 0x7f, valp[0] & 0x7f);
1199 snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
1200 0x7f, valp[1] & 0x7f);
1201 return change;
1202}
1203
1204/* bind volumes of both NID 0x02 and 0x05 */
1205static int vaio_master_sw_put(struct snd_kcontrol *kcontrol,
1206 struct snd_ctl_elem_value *ucontrol)
1207{
1208 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1209 long *valp = ucontrol->value.integer.value;
1210 int change;
1211
1212 change = snd_hda_codec_amp_update(codec, 0x02, 0, HDA_OUTPUT, 0,
1213 0x80, valp[0] & 0x80);
1214 change |= snd_hda_codec_amp_update(codec, 0x02, 1, HDA_OUTPUT, 0,
1215 0x80, valp[1] & 0x80);
1216 snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
1217 0x80, valp[0] & 0x80);
1218 snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
1219 0x80, valp[1] & 0x80);
1220 return change;
1221}
1222
1223static struct snd_kcontrol_new vaio_mixer[] = {
1224 {
1225 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1226 .name = "Master Playback Volume",
1227 .info = snd_hda_mixer_amp_volume_info,
1228 .get = snd_hda_mixer_amp_volume_get,
1229 .put = vaio_master_vol_put,
1230 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
1231 },
1232 {
1233 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1234 .name = "Master Playback Switch",
1235 .info = snd_hda_mixer_amp_switch_info,
1236 .get = snd_hda_mixer_amp_switch_get,
1237 .put = vaio_master_sw_put,
1238 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
1239 },
1240 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
1241 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
1242 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
1243 {
1244 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1245 .name = "Capture Source",
1246 .count = 1,
1247 .info = stac92xx_mux_enum_info,
1248 .get = stac92xx_mux_enum_get,
1249 .put = stac92xx_mux_enum_put,
1250 },
1251 {}
1252};
1253
1254static struct hda_codec_ops stac7661_patch_ops = {
1255 .build_controls = stac92xx_build_controls,
1256 .build_pcms = stac92xx_build_pcms,
1257 .init = stac92xx_init,
1258 .free = stac92xx_free,
1259#ifdef CONFIG_PM
1260 .resume = stac92xx_resume,
1261#endif
1262};
1263
1264enum { STAC7661_VAIO };
1265
1266static struct hda_board_config stac7661_cfg_tbl[] = {
1267 { .modelname = "vaio", .config = STAC7661_VAIO },
1268 { .pci_subvendor = 0x104d, .pci_subdevice = 0x81e6,
1269 .config = STAC7661_VAIO },
1270 { .pci_subvendor = 0x104d, .pci_subdevice = 0x81ef,
1271 .config = STAC7661_VAIO },
1272 {}
1273};
1274
1275static int patch_stac7661(struct hda_codec *codec)
1276{
1277 struct sigmatel_spec *spec;
1278 int board_config;
1279
1280 board_config = snd_hda_check_board_config(codec, stac7661_cfg_tbl);
1281 if (board_config < 0)
1282 /* unknown config, let generic-parser do its job... */
1283 return snd_hda_parse_generic_codec(codec);
1284
1285 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1286 if (spec == NULL)
1287 return -ENOMEM;
1288
1289 codec->spec = spec;
1290 switch (board_config) {
1291 case STAC7661_VAIO:
1292 spec->mixer = vaio_mixer;
1293 spec->init = vaio_init;
1294 spec->multiout.max_channels = 2;
1295 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
1296 spec->multiout.dac_nids = vaio_dacs;
1297 spec->multiout.hp_nid = VAIO_HP_DAC;
1298 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
1299 spec->adc_nids = vaio_adcs;
1300 spec->input_mux = &vaio_mux;
1301 spec->mux_nids = vaio_mux_nids;
1302 break;
1303 }
1304
1305 codec->patch_ops = stac7661_patch_ops;
1306 return 0;
1307}
1308
1309
2f2f4251
M
1310/*
1311 * patch entries
1312 */
1313struct hda_codec_preset snd_hda_preset_sigmatel[] = {
1314 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
1315 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
1316 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
1317 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
1318 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
1319 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
1320 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
3cc08dc6
MP
1321 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
1322 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
1323 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
1324 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
1325 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
1326 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
1327 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
1328 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
1329 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
1330 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
db064e50 1331 { .id = 0x83847661, .name = "STAC7661", .patch = patch_stac7661 },
2f2f4251
M
1332 {} /* terminator */
1333};