]> bbs.cooldavid.org Git - net-next-2.6.git/blame_incremental - sound/pci/hda/patch_sigmatel.c
ALSA: hda - Remove unused proc entry in hda_bus struct
[net-next-2.6.git] / sound / pci / hda / patch_sigmatel.c
... / ...
CommitLineData
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.
7 * Matt Porter <mporter@embeddedalley.com>
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 <linux/init.h>
28#include <linux/delay.h>
29#include <linux/slab.h>
30#include <linux/pci.h>
31#include <sound/core.h>
32#include <sound/asoundef.h>
33#include <sound/jack.h>
34#include "hda_codec.h"
35#include "hda_local.h"
36#include "hda_patch.h"
37#include "hda_beep.h"
38
39enum {
40 STAC_VREF_EVENT = 1,
41 STAC_INSERT_EVENT,
42 STAC_PWR_EVENT,
43 STAC_HP_EVENT,
44};
45
46enum {
47 STAC_REF,
48 STAC_9200_OQO,
49 STAC_9200_DELL_D21,
50 STAC_9200_DELL_D22,
51 STAC_9200_DELL_D23,
52 STAC_9200_DELL_M21,
53 STAC_9200_DELL_M22,
54 STAC_9200_DELL_M23,
55 STAC_9200_DELL_M24,
56 STAC_9200_DELL_M25,
57 STAC_9200_DELL_M26,
58 STAC_9200_DELL_M27,
59 STAC_9200_GATEWAY,
60 STAC_9200_PANASONIC,
61 STAC_9200_MODELS
62};
63
64enum {
65 STAC_9205_REF,
66 STAC_9205_DELL_M42,
67 STAC_9205_DELL_M43,
68 STAC_9205_DELL_M44,
69 STAC_9205_MODELS
70};
71
72enum {
73 STAC_92HD73XX_REF,
74 STAC_DELL_M6_AMIC,
75 STAC_DELL_M6_DMIC,
76 STAC_DELL_M6_BOTH,
77 STAC_DELL_EQ,
78 STAC_92HD73XX_MODELS
79};
80
81enum {
82 STAC_92HD83XXX_REF,
83 STAC_92HD83XXX_MODELS
84};
85
86enum {
87 STAC_92HD71BXX_REF,
88 STAC_DELL_M4_1,
89 STAC_DELL_M4_2,
90 STAC_DELL_M4_3,
91 STAC_HP_M4,
92 STAC_92HD71BXX_MODELS
93};
94
95enum {
96 STAC_925x_REF,
97 STAC_M2_2,
98 STAC_MA6,
99 STAC_PA6,
100 STAC_925x_MODELS
101};
102
103enum {
104 STAC_D945_REF,
105 STAC_D945GTP3,
106 STAC_D945GTP5,
107 STAC_INTEL_MAC_V1,
108 STAC_INTEL_MAC_V2,
109 STAC_INTEL_MAC_V3,
110 STAC_INTEL_MAC_V4,
111 STAC_INTEL_MAC_V5,
112 STAC_INTEL_MAC_AUTO, /* This model is selected if no module parameter
113 * is given, one of the above models will be
114 * chosen according to the subsystem id. */
115 /* for backward compatibility */
116 STAC_MACMINI,
117 STAC_MACBOOK,
118 STAC_MACBOOK_PRO_V1,
119 STAC_MACBOOK_PRO_V2,
120 STAC_IMAC_INTEL,
121 STAC_IMAC_INTEL_20,
122 STAC_ECS_202,
123 STAC_922X_DELL_D81,
124 STAC_922X_DELL_D82,
125 STAC_922X_DELL_M81,
126 STAC_922X_DELL_M82,
127 STAC_922X_MODELS
128};
129
130enum {
131 STAC_D965_REF,
132 STAC_D965_3ST,
133 STAC_D965_5ST,
134 STAC_DELL_3ST,
135 STAC_DELL_BIOS,
136 STAC_927X_MODELS
137};
138
139struct sigmatel_event {
140 hda_nid_t nid;
141 unsigned char type;
142 unsigned char tag;
143 int data;
144};
145
146struct sigmatel_jack {
147 hda_nid_t nid;
148 int type;
149 struct snd_jack *jack;
150};
151
152struct sigmatel_spec {
153 struct snd_kcontrol_new *mixers[4];
154 unsigned int num_mixers;
155
156 int board_config;
157 unsigned int eapd_switch: 1;
158 unsigned int surr_switch: 1;
159 unsigned int line_switch: 1;
160 unsigned int mic_switch: 1;
161 unsigned int alt_switch: 1;
162 unsigned int hp_detect: 1;
163 unsigned int spdif_mute: 1;
164
165 /* gpio lines */
166 unsigned int eapd_mask;
167 unsigned int gpio_mask;
168 unsigned int gpio_dir;
169 unsigned int gpio_data;
170 unsigned int gpio_mute;
171
172 /* stream */
173 unsigned int stream_delay;
174
175 /* analog loopback */
176 unsigned char aloopback_mask;
177 unsigned char aloopback_shift;
178
179 /* power management */
180 unsigned int num_pwrs;
181 unsigned int *pwr_mapping;
182 hda_nid_t *pwr_nids;
183 hda_nid_t *dac_list;
184
185 /* jack detection */
186 struct snd_array jacks;
187
188 /* events */
189 struct snd_array events;
190
191 /* playback */
192 struct hda_input_mux *mono_mux;
193 struct hda_input_mux *amp_mux;
194 unsigned int cur_mmux;
195 struct hda_multi_out multiout;
196 hda_nid_t dac_nids[5];
197
198 /* capture */
199 hda_nid_t *adc_nids;
200 unsigned int num_adcs;
201 hda_nid_t *mux_nids;
202 unsigned int num_muxes;
203 hda_nid_t *dmic_nids;
204 unsigned int num_dmics;
205 hda_nid_t *dmux_nids;
206 unsigned int num_dmuxes;
207 hda_nid_t *smux_nids;
208 unsigned int num_smuxes;
209 const char **spdif_labels;
210
211 hda_nid_t dig_in_nid;
212 hda_nid_t mono_nid;
213 hda_nid_t anabeep_nid;
214 hda_nid_t digbeep_nid;
215
216 /* pin widgets */
217 hda_nid_t *pin_nids;
218 unsigned int num_pins;
219 unsigned int *pin_configs;
220
221 /* codec specific stuff */
222 struct hda_verb *init;
223 struct snd_kcontrol_new *mixer;
224
225 /* capture source */
226 struct hda_input_mux *dinput_mux;
227 unsigned int cur_dmux[2];
228 struct hda_input_mux *input_mux;
229 unsigned int cur_mux[3];
230 struct hda_input_mux *sinput_mux;
231 unsigned int cur_smux[2];
232 unsigned int cur_amux;
233 hda_nid_t *amp_nids;
234 unsigned int num_amps;
235 unsigned int powerdown_adcs;
236
237 /* i/o switches */
238 unsigned int io_switch[2];
239 unsigned int clfe_swap;
240 unsigned int hp_switch; /* NID of HP as line-out */
241 unsigned int aloopback;
242
243 struct hda_pcm pcm_rec[2]; /* PCM information */
244
245 /* dynamic controls and input_mux */
246 struct auto_pin_cfg autocfg;
247 struct snd_array kctls;
248 struct hda_input_mux private_dimux;
249 struct hda_input_mux private_imux;
250 struct hda_input_mux private_smux;
251 struct hda_input_mux private_amp_mux;
252 struct hda_input_mux private_mono_mux;
253};
254
255static hda_nid_t stac9200_adc_nids[1] = {
256 0x03,
257};
258
259static hda_nid_t stac9200_mux_nids[1] = {
260 0x0c,
261};
262
263static hda_nid_t stac9200_dac_nids[1] = {
264 0x02,
265};
266
267static hda_nid_t stac92hd73xx_pwr_nids[8] = {
268 0x0a, 0x0b, 0x0c, 0xd, 0x0e,
269 0x0f, 0x10, 0x11
270};
271
272static hda_nid_t stac92hd73xx_slave_dig_outs[2] = {
273 0x26, 0,
274};
275
276static hda_nid_t stac92hd73xx_adc_nids[2] = {
277 0x1a, 0x1b
278};
279
280#define DELL_M6_AMP 2
281static hda_nid_t stac92hd73xx_amp_nids[3] = {
282 0x0b, 0x0c, 0x0e
283};
284
285#define STAC92HD73XX_NUM_DMICS 2
286static hda_nid_t stac92hd73xx_dmic_nids[STAC92HD73XX_NUM_DMICS + 1] = {
287 0x13, 0x14, 0
288};
289
290#define STAC92HD73_DAC_COUNT 5
291static hda_nid_t stac92hd73xx_dac_nids[STAC92HD73_DAC_COUNT] = {
292 0x15, 0x16, 0x17, 0x18, 0x19,
293};
294
295static hda_nid_t stac92hd73xx_mux_nids[4] = {
296 0x28, 0x29, 0x2a, 0x2b,
297};
298
299static hda_nid_t stac92hd73xx_dmux_nids[2] = {
300 0x20, 0x21,
301};
302
303static hda_nid_t stac92hd73xx_smux_nids[2] = {
304 0x22, 0x23,
305};
306
307#define STAC92HD83XXX_NUM_DMICS 2
308static hda_nid_t stac92hd83xxx_dmic_nids[STAC92HD83XXX_NUM_DMICS + 1] = {
309 0x11, 0x12, 0
310};
311
312#define STAC92HD81_DAC_COUNT 2
313#define STAC92HD83_DAC_COUNT 3
314static hda_nid_t stac92hd83xxx_dac_nids[STAC92HD73_DAC_COUNT] = {
315 0x13, 0x14, 0x22,
316};
317
318static hda_nid_t stac92hd83xxx_dmux_nids[2] = {
319 0x17, 0x18,
320};
321
322static hda_nid_t stac92hd83xxx_adc_nids[2] = {
323 0x15, 0x16,
324};
325
326static hda_nid_t stac92hd83xxx_pwr_nids[4] = {
327 0xa, 0xb, 0xd, 0xe,
328};
329
330static hda_nid_t stac92hd83xxx_slave_dig_outs[2] = {
331 0x1e, 0,
332};
333
334static unsigned int stac92hd83xxx_pwr_mapping[4] = {
335 0x03, 0x0c, 0x10, 0x40,
336};
337
338static hda_nid_t stac92hd71bxx_pwr_nids[3] = {
339 0x0a, 0x0d, 0x0f
340};
341
342static hda_nid_t stac92hd71bxx_adc_nids[2] = {
343 0x12, 0x13,
344};
345
346static hda_nid_t stac92hd71bxx_mux_nids[2] = {
347 0x1a, 0x1b
348};
349
350static hda_nid_t stac92hd71bxx_dmux_nids[2] = {
351 0x1c, 0x1d,
352};
353
354static hda_nid_t stac92hd71bxx_smux_nids[2] = {
355 0x24, 0x25,
356};
357
358static hda_nid_t stac92hd71bxx_dac_nids[1] = {
359 0x10, /*0x11, */
360};
361
362#define STAC92HD71BXX_NUM_DMICS 2
363static hda_nid_t stac92hd71bxx_dmic_nids[STAC92HD71BXX_NUM_DMICS + 1] = {
364 0x18, 0x19, 0
365};
366
367static hda_nid_t stac92hd71bxx_slave_dig_outs[2] = {
368 0x22, 0
369};
370
371static hda_nid_t stac925x_adc_nids[1] = {
372 0x03,
373};
374
375static hda_nid_t stac925x_mux_nids[1] = {
376 0x0f,
377};
378
379static hda_nid_t stac925x_dac_nids[1] = {
380 0x02,
381};
382
383#define STAC925X_NUM_DMICS 1
384static hda_nid_t stac925x_dmic_nids[STAC925X_NUM_DMICS + 1] = {
385 0x15, 0
386};
387
388static hda_nid_t stac925x_dmux_nids[1] = {
389 0x14,
390};
391
392static hda_nid_t stac922x_adc_nids[2] = {
393 0x06, 0x07,
394};
395
396static hda_nid_t stac922x_mux_nids[2] = {
397 0x12, 0x13,
398};
399
400static hda_nid_t stac927x_adc_nids[3] = {
401 0x07, 0x08, 0x09
402};
403
404static hda_nid_t stac927x_mux_nids[3] = {
405 0x15, 0x16, 0x17
406};
407
408static hda_nid_t stac927x_smux_nids[1] = {
409 0x21,
410};
411
412static hda_nid_t stac927x_dac_nids[6] = {
413 0x02, 0x03, 0x04, 0x05, 0x06, 0
414};
415
416static hda_nid_t stac927x_dmux_nids[1] = {
417 0x1b,
418};
419
420#define STAC927X_NUM_DMICS 2
421static hda_nid_t stac927x_dmic_nids[STAC927X_NUM_DMICS + 1] = {
422 0x13, 0x14, 0
423};
424
425static const char *stac927x_spdif_labels[5] = {
426 "Digital Playback", "ADAT", "Analog Mux 1",
427 "Analog Mux 2", "Analog Mux 3"
428};
429
430static hda_nid_t stac9205_adc_nids[2] = {
431 0x12, 0x13
432};
433
434static hda_nid_t stac9205_mux_nids[2] = {
435 0x19, 0x1a
436};
437
438static hda_nid_t stac9205_dmux_nids[1] = {
439 0x1d,
440};
441
442static hda_nid_t stac9205_smux_nids[1] = {
443 0x21,
444};
445
446#define STAC9205_NUM_DMICS 2
447static hda_nid_t stac9205_dmic_nids[STAC9205_NUM_DMICS + 1] = {
448 0x17, 0x18, 0
449};
450
451static hda_nid_t stac9200_pin_nids[8] = {
452 0x08, 0x09, 0x0d, 0x0e,
453 0x0f, 0x10, 0x11, 0x12,
454};
455
456static hda_nid_t stac925x_pin_nids[8] = {
457 0x07, 0x08, 0x0a, 0x0b,
458 0x0c, 0x0d, 0x10, 0x11,
459};
460
461static hda_nid_t stac922x_pin_nids[10] = {
462 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
463 0x0f, 0x10, 0x11, 0x15, 0x1b,
464};
465
466static hda_nid_t stac92hd73xx_pin_nids[13] = {
467 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
468 0x0f, 0x10, 0x11, 0x12, 0x13,
469 0x14, 0x22, 0x23
470};
471
472static hda_nid_t stac92hd83xxx_pin_nids[14] = {
473 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
474 0x0f, 0x10, 0x11, 0x12, 0x13,
475 0x1d, 0x1e, 0x1f, 0x20
476};
477static hda_nid_t stac92hd71bxx_pin_nids[11] = {
478 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
479 0x0f, 0x14, 0x18, 0x19, 0x1e,
480 0x1f,
481};
482
483static hda_nid_t stac927x_pin_nids[14] = {
484 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
485 0x0f, 0x10, 0x11, 0x12, 0x13,
486 0x14, 0x21, 0x22, 0x23,
487};
488
489static hda_nid_t stac9205_pin_nids[12] = {
490 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
491 0x0f, 0x14, 0x16, 0x17, 0x18,
492 0x21, 0x22,
493};
494
495#define stac92xx_amp_volume_info snd_hda_mixer_amp_volume_info
496
497static int stac92xx_amp_volume_get(struct snd_kcontrol *kcontrol,
498 struct snd_ctl_elem_value *ucontrol)
499{
500 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
501 struct sigmatel_spec *spec = codec->spec;
502 hda_nid_t nid = spec->amp_nids[spec->cur_amux];
503
504 kcontrol->private_value ^= get_amp_nid(kcontrol);
505 kcontrol->private_value |= nid;
506
507 return snd_hda_mixer_amp_volume_get(kcontrol, ucontrol);
508}
509
510static int stac92xx_amp_volume_put(struct snd_kcontrol *kcontrol,
511 struct snd_ctl_elem_value *ucontrol)
512{
513 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
514 struct sigmatel_spec *spec = codec->spec;
515 hda_nid_t nid = spec->amp_nids[spec->cur_amux];
516
517 kcontrol->private_value ^= get_amp_nid(kcontrol);
518 kcontrol->private_value |= nid;
519
520 return snd_hda_mixer_amp_volume_put(kcontrol, ucontrol);
521}
522
523static int stac92xx_dmux_enum_info(struct snd_kcontrol *kcontrol,
524 struct snd_ctl_elem_info *uinfo)
525{
526 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
527 struct sigmatel_spec *spec = codec->spec;
528 return snd_hda_input_mux_info(spec->dinput_mux, uinfo);
529}
530
531static int stac92xx_dmux_enum_get(struct snd_kcontrol *kcontrol,
532 struct snd_ctl_elem_value *ucontrol)
533{
534 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
535 struct sigmatel_spec *spec = codec->spec;
536 unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
537
538 ucontrol->value.enumerated.item[0] = spec->cur_dmux[dmux_idx];
539 return 0;
540}
541
542static int stac92xx_dmux_enum_put(struct snd_kcontrol *kcontrol,
543 struct snd_ctl_elem_value *ucontrol)
544{
545 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
546 struct sigmatel_spec *spec = codec->spec;
547 unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
548
549 return snd_hda_input_mux_put(codec, spec->dinput_mux, ucontrol,
550 spec->dmux_nids[dmux_idx], &spec->cur_dmux[dmux_idx]);
551}
552
553static int stac92xx_smux_enum_info(struct snd_kcontrol *kcontrol,
554 struct snd_ctl_elem_info *uinfo)
555{
556 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
557 struct sigmatel_spec *spec = codec->spec;
558 return snd_hda_input_mux_info(spec->sinput_mux, uinfo);
559}
560
561static int stac92xx_smux_enum_get(struct snd_kcontrol *kcontrol,
562 struct snd_ctl_elem_value *ucontrol)
563{
564 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
565 struct sigmatel_spec *spec = codec->spec;
566 unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
567
568 ucontrol->value.enumerated.item[0] = spec->cur_smux[smux_idx];
569 return 0;
570}
571
572static int stac92xx_smux_enum_put(struct snd_kcontrol *kcontrol,
573 struct snd_ctl_elem_value *ucontrol)
574{
575 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
576 struct sigmatel_spec *spec = codec->spec;
577 struct hda_input_mux *smux = &spec->private_smux;
578 unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
579 int err, val;
580 hda_nid_t nid;
581
582 err = snd_hda_input_mux_put(codec, spec->sinput_mux, ucontrol,
583 spec->smux_nids[smux_idx], &spec->cur_smux[smux_idx]);
584 if (err < 0)
585 return err;
586
587 if (spec->spdif_mute) {
588 if (smux_idx == 0)
589 nid = spec->multiout.dig_out_nid;
590 else
591 nid = codec->slave_dig_outs[smux_idx - 1];
592 if (spec->cur_smux[smux_idx] == smux->num_items - 1)
593 val = AMP_OUT_MUTE;
594 else
595 val = AMP_OUT_UNMUTE;
596 /* un/mute SPDIF out */
597 snd_hda_codec_write_cache(codec, nid, 0,
598 AC_VERB_SET_AMP_GAIN_MUTE, val);
599 }
600 return 0;
601}
602
603static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
604{
605 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
606 struct sigmatel_spec *spec = codec->spec;
607 return snd_hda_input_mux_info(spec->input_mux, uinfo);
608}
609
610static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
611{
612 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
613 struct sigmatel_spec *spec = codec->spec;
614 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
615
616 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
617 return 0;
618}
619
620static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
621{
622 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
623 struct sigmatel_spec *spec = codec->spec;
624 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
625
626 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
627 spec->mux_nids[adc_idx], &spec->cur_mux[adc_idx]);
628}
629
630static int stac92xx_mono_mux_enum_info(struct snd_kcontrol *kcontrol,
631 struct snd_ctl_elem_info *uinfo)
632{
633 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
634 struct sigmatel_spec *spec = codec->spec;
635 return snd_hda_input_mux_info(spec->mono_mux, uinfo);
636}
637
638static int stac92xx_mono_mux_enum_get(struct snd_kcontrol *kcontrol,
639 struct snd_ctl_elem_value *ucontrol)
640{
641 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
642 struct sigmatel_spec *spec = codec->spec;
643
644 ucontrol->value.enumerated.item[0] = spec->cur_mmux;
645 return 0;
646}
647
648static int stac92xx_mono_mux_enum_put(struct snd_kcontrol *kcontrol,
649 struct snd_ctl_elem_value *ucontrol)
650{
651 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
652 struct sigmatel_spec *spec = codec->spec;
653
654 return snd_hda_input_mux_put(codec, spec->mono_mux, ucontrol,
655 spec->mono_nid, &spec->cur_mmux);
656}
657
658static int stac92xx_amp_mux_enum_info(struct snd_kcontrol *kcontrol,
659 struct snd_ctl_elem_info *uinfo)
660{
661 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
662 struct sigmatel_spec *spec = codec->spec;
663 return snd_hda_input_mux_info(spec->amp_mux, uinfo);
664}
665
666static int stac92xx_amp_mux_enum_get(struct snd_kcontrol *kcontrol,
667 struct snd_ctl_elem_value *ucontrol)
668{
669 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
670 struct sigmatel_spec *spec = codec->spec;
671
672 ucontrol->value.enumerated.item[0] = spec->cur_amux;
673 return 0;
674}
675
676static int stac92xx_amp_mux_enum_put(struct snd_kcontrol *kcontrol,
677 struct snd_ctl_elem_value *ucontrol)
678{
679 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
680 struct sigmatel_spec *spec = codec->spec;
681 struct snd_kcontrol *ctl =
682 snd_hda_find_mixer_ctl(codec, "Amp Capture Volume");
683 if (!ctl)
684 return -EINVAL;
685
686 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE |
687 SNDRV_CTL_EVENT_MASK_INFO, &ctl->id);
688
689 return snd_hda_input_mux_put(codec, spec->amp_mux, ucontrol,
690 0, &spec->cur_amux);
691}
692
693#define stac92xx_aloopback_info snd_ctl_boolean_mono_info
694
695static int stac92xx_aloopback_get(struct snd_kcontrol *kcontrol,
696 struct snd_ctl_elem_value *ucontrol)
697{
698 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
699 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
700 struct sigmatel_spec *spec = codec->spec;
701
702 ucontrol->value.integer.value[0] = !!(spec->aloopback &
703 (spec->aloopback_mask << idx));
704 return 0;
705}
706
707static int stac92xx_aloopback_put(struct snd_kcontrol *kcontrol,
708 struct snd_ctl_elem_value *ucontrol)
709{
710 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
711 struct sigmatel_spec *spec = codec->spec;
712 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
713 unsigned int dac_mode;
714 unsigned int val, idx_val;
715
716 idx_val = spec->aloopback_mask << idx;
717 if (ucontrol->value.integer.value[0])
718 val = spec->aloopback | idx_val;
719 else
720 val = spec->aloopback & ~idx_val;
721 if (spec->aloopback == val)
722 return 0;
723
724 spec->aloopback = val;
725
726 /* Only return the bits defined by the shift value of the
727 * first two bytes of the mask
728 */
729 dac_mode = snd_hda_codec_read(codec, codec->afg, 0,
730 kcontrol->private_value & 0xFFFF, 0x0);
731 dac_mode >>= spec->aloopback_shift;
732
733 if (spec->aloopback & idx_val) {
734 snd_hda_power_up(codec);
735 dac_mode |= idx_val;
736 } else {
737 snd_hda_power_down(codec);
738 dac_mode &= ~idx_val;
739 }
740
741 snd_hda_codec_write_cache(codec, codec->afg, 0,
742 kcontrol->private_value >> 16, dac_mode);
743
744 return 1;
745}
746
747static struct hda_verb stac9200_core_init[] = {
748 /* set dac0mux for dac converter */
749 { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
750 {}
751};
752
753static struct hda_verb stac9200_eapd_init[] = {
754 /* set dac0mux for dac converter */
755 {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
756 {0x08, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
757 {}
758};
759
760static struct hda_verb stac92hd73xx_6ch_core_init[] = {
761 /* set master volume and direct control */
762 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
763 /* setup audio connections */
764 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00},
765 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x01},
766 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x02},
767 /* setup adcs to point to mixer */
768 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
769 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
770 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
771 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
772 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
773 /* setup import muxs */
774 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
775 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
776 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
777 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x00},
778 {}
779};
780
781static struct hda_verb dell_eq_core_init[] = {
782 /* set master volume to max value without distortion
783 * and direct control */
784 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xec},
785 /* setup audio connections */
786 { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
787 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x02},
788 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x01},
789 /* setup adcs to point to mixer */
790 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
791 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
792 /* setup import muxs */
793 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
794 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
795 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
796 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x00},
797 {}
798};
799
800static struct hda_verb dell_m6_core_init[] = {
801 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
802 /* setup audio connections */
803 { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
804 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x01},
805 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x02},
806 /* setup adcs to point to mixer */
807 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
808 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
809 /* setup import muxs */
810 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
811 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
812 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
813 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x00},
814 {}
815};
816
817static struct hda_verb stac92hd73xx_8ch_core_init[] = {
818 /* set master volume and direct control */
819 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
820 /* setup audio connections */
821 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00},
822 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x01},
823 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x02},
824 /* connect hp ports to dac3 */
825 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x03},
826 { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x03},
827 /* setup adcs to point to mixer */
828 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
829 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
830 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
831 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
832 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
833 /* setup import muxs */
834 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
835 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
836 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
837 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x03},
838 {}
839};
840
841static struct hda_verb stac92hd73xx_10ch_core_init[] = {
842 /* set master volume and direct control */
843 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
844 /* setup audio connections */
845 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
846 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x01 },
847 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x02 },
848 /* dac3 is connected to import3 mux */
849 { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0xb07f},
850 /* connect hp ports to dac4 */
851 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x04},
852 { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x04},
853 /* setup adcs to point to mixer */
854 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
855 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
856 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
857 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
858 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
859 /* setup import muxs */
860 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
861 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
862 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
863 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x03},
864 {}
865};
866
867static struct hda_verb stac92hd83xxx_core_init[] = {
868 /* start of config #1 */
869 { 0xe, AC_VERB_SET_CONNECT_SEL, 0x3},
870
871 /* start of config #2 */
872 { 0xa, AC_VERB_SET_CONNECT_SEL, 0x0},
873 { 0xb, AC_VERB_SET_CONNECT_SEL, 0x0},
874 { 0xd, AC_VERB_SET_CONNECT_SEL, 0x1},
875
876 /* power state controls amps */
877 { 0x01, AC_VERB_SET_EAPD, 1 << 2},
878};
879
880static struct hda_verb stac92hd71bxx_core_init[] = {
881 /* set master volume and direct control */
882 { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
883 /* connect headphone jack to dac1 */
884 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x01},
885 /* unmute right and left channels for nodes 0x0a, 0xd, 0x0f */
886 { 0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
887 { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
888 { 0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
889};
890
891#define HD_DISABLE_PORTF 2
892static struct hda_verb stac92hd71bxx_analog_core_init[] = {
893 /* start of config #1 */
894
895 /* connect port 0f to audio mixer */
896 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x2},
897 /* unmute right and left channels for node 0x0f */
898 { 0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
899 /* start of config #2 */
900
901 /* set master volume and direct control */
902 { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
903 /* connect headphone jack to dac1 */
904 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x01},
905 /* unmute right and left channels for nodes 0x0a, 0xd */
906 { 0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
907 { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
908 {}
909};
910
911static struct hda_verb stac925x_core_init[] = {
912 /* set dac0mux for dac converter */
913 { 0x06, AC_VERB_SET_CONNECT_SEL, 0x00},
914 {}
915};
916
917static struct hda_verb stac922x_core_init[] = {
918 /* set master volume and direct control */
919 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
920 {}
921};
922
923static struct hda_verb d965_core_init[] = {
924 /* set master volume and direct control */
925 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
926 /* unmute node 0x1b */
927 { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
928 /* select node 0x03 as DAC */
929 { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
930 {}
931};
932
933static struct hda_verb stac927x_core_init[] = {
934 /* set master volume and direct control */
935 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
936 /* enable analog pc beep path */
937 { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
938 {}
939};
940
941static struct hda_verb stac9205_core_init[] = {
942 /* set master volume and direct control */
943 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
944 /* enable analog pc beep path */
945 { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
946 {}
947};
948
949#define STAC_MONO_MUX \
950 { \
951 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
952 .name = "Mono Mux", \
953 .count = 1, \
954 .info = stac92xx_mono_mux_enum_info, \
955 .get = stac92xx_mono_mux_enum_get, \
956 .put = stac92xx_mono_mux_enum_put, \
957 }
958
959#define STAC_AMP_MUX \
960 { \
961 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
962 .name = "Amp Selector Capture Switch", \
963 .count = 1, \
964 .info = stac92xx_amp_mux_enum_info, \
965 .get = stac92xx_amp_mux_enum_get, \
966 .put = stac92xx_amp_mux_enum_put, \
967 }
968
969#define STAC_AMP_VOL(xname, nid, chs, idx, dir) \
970 { \
971 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
972 .name = xname, \
973 .index = 0, \
974 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
975 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
976 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
977 .info = stac92xx_amp_volume_info, \
978 .get = stac92xx_amp_volume_get, \
979 .put = stac92xx_amp_volume_put, \
980 .tlv = { .c = snd_hda_mixer_amp_tlv }, \
981 .private_value = HDA_COMPOSE_AMP_VAL(nid, chs, idx, dir) \
982 }
983
984#define STAC_INPUT_SOURCE(cnt) \
985 { \
986 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
987 .name = "Input Source", \
988 .count = cnt, \
989 .info = stac92xx_mux_enum_info, \
990 .get = stac92xx_mux_enum_get, \
991 .put = stac92xx_mux_enum_put, \
992 }
993
994#define STAC_ANALOG_LOOPBACK(verb_read, verb_write, cnt) \
995 { \
996 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
997 .name = "Analog Loopback", \
998 .count = cnt, \
999 .info = stac92xx_aloopback_info, \
1000 .get = stac92xx_aloopback_get, \
1001 .put = stac92xx_aloopback_put, \
1002 .private_value = verb_read | (verb_write << 16), \
1003 }
1004
1005static struct snd_kcontrol_new stac9200_mixer[] = {
1006 HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
1007 HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
1008 STAC_INPUT_SOURCE(1),
1009 HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
1010 HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
1011 { } /* end */
1012};
1013
1014#define DELL_M6_MIXER 6
1015static struct snd_kcontrol_new stac92hd73xx_6ch_mixer[] = {
1016 /* start of config #1 */
1017 HDA_CODEC_VOLUME("Front Mic Mixer Capture Volume", 0x1d, 0, HDA_INPUT),
1018 HDA_CODEC_MUTE("Front Mic Mixer Capture Switch", 0x1d, 0, HDA_INPUT),
1019
1020 HDA_CODEC_VOLUME("Line In Mixer Capture Volume", 0x1d, 0x2, HDA_INPUT),
1021 HDA_CODEC_MUTE("Line In Mixer Capture Switch", 0x1d, 0x2, HDA_INPUT),
1022
1023 HDA_CODEC_VOLUME("CD Mixer Capture Volume", 0x1d, 0x4, HDA_INPUT),
1024 HDA_CODEC_MUTE("CD Mixer Capture Switch", 0x1d, 0x4, HDA_INPUT),
1025
1026 /* start of config #2 */
1027 HDA_CODEC_VOLUME("Mic Mixer Capture Volume", 0x1d, 0x1, HDA_INPUT),
1028 HDA_CODEC_MUTE("Mic Mixer Capture Switch", 0x1d, 0x1, HDA_INPUT),
1029
1030 HDA_CODEC_VOLUME("DAC Mixer Capture Volume", 0x1d, 0x3, HDA_INPUT),
1031 HDA_CODEC_MUTE("DAC Mixer Capture Switch", 0x1d, 0x3, HDA_INPUT),
1032
1033 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 3),
1034
1035 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x20, 0x0, HDA_OUTPUT),
1036 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x20, 0x0, HDA_OUTPUT),
1037
1038 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x21, 0x0, HDA_OUTPUT),
1039 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x21, 0x0, HDA_OUTPUT),
1040
1041 { } /* end */
1042};
1043
1044static struct snd_kcontrol_new stac92hd73xx_8ch_mixer[] = {
1045 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 4),
1046
1047 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x20, 0x0, HDA_OUTPUT),
1048 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x20, 0x0, HDA_OUTPUT),
1049
1050 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x21, 0x0, HDA_OUTPUT),
1051 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x21, 0x0, HDA_OUTPUT),
1052
1053 HDA_CODEC_VOLUME("Front Mic Mixer Capture Volume", 0x1d, 0, HDA_INPUT),
1054 HDA_CODEC_MUTE("Front Mic Mixer Capture Switch", 0x1d, 0, HDA_INPUT),
1055
1056 HDA_CODEC_VOLUME("Mic Mixer Capture Volume", 0x1d, 0x1, HDA_INPUT),
1057 HDA_CODEC_MUTE("Mic Mixer Capture Switch", 0x1d, 0x1, HDA_INPUT),
1058
1059 HDA_CODEC_VOLUME("Line In Mixer Capture Volume", 0x1d, 0x2, HDA_INPUT),
1060 HDA_CODEC_MUTE("Line In Mixer Capture Switch", 0x1d, 0x2, HDA_INPUT),
1061
1062 HDA_CODEC_VOLUME("DAC Mixer Capture Volume", 0x1d, 0x3, HDA_INPUT),
1063 HDA_CODEC_MUTE("DAC Mixer Capture Switch", 0x1d, 0x3, HDA_INPUT),
1064
1065 HDA_CODEC_VOLUME("CD Mixer Capture Volume", 0x1d, 0x4, HDA_INPUT),
1066 HDA_CODEC_MUTE("CD Mixer Capture Switch", 0x1d, 0x4, HDA_INPUT),
1067 { } /* end */
1068};
1069
1070static struct snd_kcontrol_new stac92hd73xx_10ch_mixer[] = {
1071 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 5),
1072
1073 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x20, 0x0, HDA_OUTPUT),
1074 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x20, 0x0, HDA_OUTPUT),
1075
1076 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x21, 0x0, HDA_OUTPUT),
1077 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x21, 0x0, HDA_OUTPUT),
1078
1079 HDA_CODEC_VOLUME("Front Mic Mixer Capture Volume", 0x1d, 0, HDA_INPUT),
1080 HDA_CODEC_MUTE("Front Mic Mixer Capture Switch", 0x1d, 0, HDA_INPUT),
1081
1082 HDA_CODEC_VOLUME("Mic Mixer Capture Volume", 0x1d, 0x1, HDA_INPUT),
1083 HDA_CODEC_MUTE("Mic Mixer Capture Switch", 0x1d, 0x1, HDA_INPUT),
1084
1085 HDA_CODEC_VOLUME("Line In Mixer Capture Volume", 0x1d, 0x2, HDA_INPUT),
1086 HDA_CODEC_MUTE("Line In Mixer Capture Switch", 0x1d, 0x2, HDA_INPUT),
1087
1088 HDA_CODEC_VOLUME("DAC Mixer Capture Volume", 0x1d, 0x3, HDA_INPUT),
1089 HDA_CODEC_MUTE("DAC Mixer Capture Switch", 0x1d, 0x3, HDA_INPUT),
1090
1091 HDA_CODEC_VOLUME("CD Mixer Capture Volume", 0x1d, 0x4, HDA_INPUT),
1092 HDA_CODEC_MUTE("CD Mixer Capture Switch", 0x1d, 0x4, HDA_INPUT),
1093 { } /* end */
1094};
1095
1096
1097static struct snd_kcontrol_new stac92hd83xxx_mixer[] = {
1098 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x17, 0x0, HDA_OUTPUT),
1099 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x17, 0x0, HDA_OUTPUT),
1100
1101 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x18, 0x0, HDA_OUTPUT),
1102 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x18, 0x0, HDA_OUTPUT),
1103
1104 HDA_CODEC_VOLUME("DAC0 Capture Volume", 0x1b, 0, HDA_INPUT),
1105 HDA_CODEC_MUTE("DAC0 Capture Switch", 0x1b, 0, HDA_INPUT),
1106
1107 HDA_CODEC_VOLUME("DAC1 Capture Volume", 0x1b, 0x1, HDA_INPUT),
1108 HDA_CODEC_MUTE("DAC1 Capture Switch", 0x1b, 0x1, HDA_INPUT),
1109
1110 HDA_CODEC_VOLUME("Front Mic Capture Volume", 0x1b, 0x2, HDA_INPUT),
1111 HDA_CODEC_MUTE("Front Mic Capture Switch", 0x1b, 0x2, HDA_INPUT),
1112
1113 HDA_CODEC_VOLUME("Line In Capture Volume", 0x1b, 0x3, HDA_INPUT),
1114 HDA_CODEC_MUTE("Line In Capture Switch", 0x1b, 0x3, HDA_INPUT),
1115
1116 /*
1117 HDA_CODEC_VOLUME("Mic Capture Volume", 0x1b, 0x4, HDA_INPUT),
1118 HDA_CODEC_MUTE("Mic Capture Switch", 0x1b 0x4, HDA_INPUT),
1119 */
1120 { } /* end */
1121};
1122
1123static struct snd_kcontrol_new stac92hd71bxx_analog_mixer[] = {
1124 STAC_INPUT_SOURCE(2),
1125 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A0, 2),
1126
1127 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1c, 0x0, HDA_OUTPUT),
1128 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1c, 0x0, HDA_OUTPUT),
1129
1130 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x1d, 0x0, HDA_OUTPUT),
1131 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1d, 0x0, HDA_OUTPUT),
1132 /* analog pc-beep replaced with digital beep support */
1133 /*
1134 HDA_CODEC_VOLUME("PC Beep Volume", 0x17, 0x2, HDA_INPUT),
1135 HDA_CODEC_MUTE("PC Beep Switch", 0x17, 0x2, HDA_INPUT),
1136 */
1137
1138 HDA_CODEC_MUTE("Import0 Mux Capture Switch", 0x17, 0x0, HDA_INPUT),
1139 HDA_CODEC_VOLUME("Import0 Mux Capture Volume", 0x17, 0x0, HDA_INPUT),
1140
1141 HDA_CODEC_MUTE("Import1 Mux Capture Switch", 0x17, 0x1, HDA_INPUT),
1142 HDA_CODEC_VOLUME("Import1 Mux Capture Volume", 0x17, 0x1, HDA_INPUT),
1143
1144 HDA_CODEC_MUTE("DAC0 Capture Switch", 0x17, 0x3, HDA_INPUT),
1145 HDA_CODEC_VOLUME("DAC0 Capture Volume", 0x17, 0x3, HDA_INPUT),
1146
1147 HDA_CODEC_MUTE("DAC1 Capture Switch", 0x17, 0x4, HDA_INPUT),
1148 HDA_CODEC_VOLUME("DAC1 Capture Volume", 0x17, 0x4, HDA_INPUT),
1149 { } /* end */
1150};
1151
1152static struct snd_kcontrol_new stac92hd71bxx_mixer[] = {
1153 STAC_INPUT_SOURCE(2),
1154 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A0, 2),
1155
1156 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1c, 0x0, HDA_OUTPUT),
1157 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1c, 0x0, HDA_OUTPUT),
1158
1159 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x1d, 0x0, HDA_OUTPUT),
1160 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1d, 0x0, HDA_OUTPUT),
1161 { } /* end */
1162};
1163
1164static struct snd_kcontrol_new stac925x_mixer[] = {
1165 STAC_INPUT_SOURCE(1),
1166 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_OUTPUT),
1167 HDA_CODEC_MUTE("Capture Switch", 0x14, 0, HDA_OUTPUT),
1168 { } /* end */
1169};
1170
1171static struct snd_kcontrol_new stac9205_mixer[] = {
1172 STAC_INPUT_SOURCE(2),
1173 STAC_ANALOG_LOOPBACK(0xFE0, 0x7E0, 1),
1174
1175 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1b, 0x0, HDA_INPUT),
1176 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1d, 0x0, HDA_OUTPUT),
1177
1178 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x1c, 0x0, HDA_INPUT),
1179 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1e, 0x0, HDA_OUTPUT),
1180 { } /* end */
1181};
1182
1183/* This needs to be generated dynamically based on sequence */
1184static struct snd_kcontrol_new stac922x_mixer[] = {
1185 STAC_INPUT_SOURCE(2),
1186 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x17, 0x0, HDA_INPUT),
1187 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x17, 0x0, HDA_INPUT),
1188
1189 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x18, 0x0, HDA_INPUT),
1190 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x18, 0x0, HDA_INPUT),
1191 { } /* end */
1192};
1193
1194
1195static struct snd_kcontrol_new stac927x_mixer[] = {
1196 STAC_INPUT_SOURCE(3),
1197 STAC_ANALOG_LOOPBACK(0xFEB, 0x7EB, 1),
1198
1199 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x18, 0x0, HDA_INPUT),
1200 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1b, 0x0, HDA_OUTPUT),
1201
1202 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x19, 0x0, HDA_INPUT),
1203 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1c, 0x0, HDA_OUTPUT),
1204
1205 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x2, 0x1A, 0x0, HDA_INPUT),
1206 HDA_CODEC_MUTE_IDX("Capture Switch", 0x2, 0x1d, 0x0, HDA_OUTPUT),
1207 { } /* end */
1208};
1209
1210static struct snd_kcontrol_new stac_dmux_mixer = {
1211 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1212 .name = "Digital Input Source",
1213 /* count set later */
1214 .info = stac92xx_dmux_enum_info,
1215 .get = stac92xx_dmux_enum_get,
1216 .put = stac92xx_dmux_enum_put,
1217};
1218
1219static struct snd_kcontrol_new stac_smux_mixer = {
1220 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1221 .name = "IEC958 Playback Source",
1222 /* count set later */
1223 .info = stac92xx_smux_enum_info,
1224 .get = stac92xx_smux_enum_get,
1225 .put = stac92xx_smux_enum_put,
1226};
1227
1228static const char *slave_vols[] = {
1229 "Front Playback Volume",
1230 "Surround Playback Volume",
1231 "Center Playback Volume",
1232 "LFE Playback Volume",
1233 "Side Playback Volume",
1234 "Headphone Playback Volume",
1235 "Headphone Playback Volume",
1236 "Speaker Playback Volume",
1237 "External Speaker Playback Volume",
1238 "Speaker2 Playback Volume",
1239 NULL
1240};
1241
1242static const char *slave_sws[] = {
1243 "Front Playback Switch",
1244 "Surround Playback Switch",
1245 "Center Playback Switch",
1246 "LFE Playback Switch",
1247 "Side Playback Switch",
1248 "Headphone Playback Switch",
1249 "Headphone Playback Switch",
1250 "Speaker Playback Switch",
1251 "External Speaker Playback Switch",
1252 "Speaker2 Playback Switch",
1253 "IEC958 Playback Switch",
1254 NULL
1255};
1256
1257static void stac92xx_free_kctls(struct hda_codec *codec);
1258static int stac92xx_add_jack(struct hda_codec *codec, hda_nid_t nid, int type);
1259
1260static int stac92xx_build_controls(struct hda_codec *codec)
1261{
1262 struct sigmatel_spec *spec = codec->spec;
1263 struct auto_pin_cfg *cfg = &spec->autocfg;
1264 hda_nid_t nid;
1265 int err;
1266 int i;
1267
1268 err = snd_hda_add_new_ctls(codec, spec->mixer);
1269 if (err < 0)
1270 return err;
1271
1272 for (i = 0; i < spec->num_mixers; i++) {
1273 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1274 if (err < 0)
1275 return err;
1276 }
1277 if (spec->num_dmuxes > 0) {
1278 stac_dmux_mixer.count = spec->num_dmuxes;
1279 err = snd_hda_ctl_add(codec,
1280 snd_ctl_new1(&stac_dmux_mixer, codec));
1281 if (err < 0)
1282 return err;
1283 }
1284 if (spec->num_smuxes > 0) {
1285 int wcaps = get_wcaps(codec, spec->multiout.dig_out_nid);
1286 struct hda_input_mux *smux = &spec->private_smux;
1287 /* check for mute support on SPDIF out */
1288 if (wcaps & AC_WCAP_OUT_AMP) {
1289 smux->items[smux->num_items].label = "Off";
1290 smux->items[smux->num_items].index = 0;
1291 smux->num_items++;
1292 spec->spdif_mute = 1;
1293 }
1294 stac_smux_mixer.count = spec->num_smuxes;
1295 err = snd_ctl_add(codec->bus->card,
1296 snd_ctl_new1(&stac_smux_mixer, codec));
1297 if (err < 0)
1298 return err;
1299 }
1300
1301 if (spec->multiout.dig_out_nid) {
1302 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
1303 if (err < 0)
1304 return err;
1305 err = snd_hda_create_spdif_share_sw(codec,
1306 &spec->multiout);
1307 if (err < 0)
1308 return err;
1309 spec->multiout.share_spdif = 1;
1310 }
1311 if (spec->dig_in_nid && !(spec->gpio_dir & 0x01)) {
1312 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1313 if (err < 0)
1314 return err;
1315 }
1316
1317 /* if we have no master control, let's create it */
1318 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
1319 unsigned int vmaster_tlv[4];
1320 snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0],
1321 HDA_OUTPUT, vmaster_tlv);
1322 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
1323 vmaster_tlv, slave_vols);
1324 if (err < 0)
1325 return err;
1326 }
1327 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1328 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1329 NULL, slave_sws);
1330 if (err < 0)
1331 return err;
1332 }
1333
1334 stac92xx_free_kctls(codec); /* no longer needed */
1335
1336 /* create jack input elements */
1337 if (spec->hp_detect) {
1338 for (i = 0; i < cfg->hp_outs; i++) {
1339 int type = SND_JACK_HEADPHONE;
1340 nid = cfg->hp_pins[i];
1341 /* jack detection */
1342 if (cfg->hp_outs == i)
1343 type |= SND_JACK_LINEOUT;
1344 err = stac92xx_add_jack(codec, nid, type);
1345 if (err < 0)
1346 return err;
1347 }
1348 }
1349 for (i = 0; i < cfg->line_outs; i++) {
1350 err = stac92xx_add_jack(codec, cfg->line_out_pins[i],
1351 SND_JACK_LINEOUT);
1352 if (err < 0)
1353 return err;
1354 }
1355 for (i = 0; i < AUTO_PIN_LAST; i++) {
1356 nid = cfg->input_pins[i];
1357 if (nid) {
1358 err = stac92xx_add_jack(codec, nid,
1359 SND_JACK_MICROPHONE);
1360 if (err < 0)
1361 return err;
1362 }
1363 }
1364
1365 return 0;
1366}
1367
1368static unsigned int ref9200_pin_configs[8] = {
1369 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
1370 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
1371};
1372
1373/*
1374 STAC 9200 pin configs for
1375 102801A8
1376 102801DE
1377 102801E8
1378*/
1379static unsigned int dell9200_d21_pin_configs[8] = {
1380 0x400001f0, 0x400001f1, 0x02214030, 0x01014010,
1381 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
1382};
1383
1384/*
1385 STAC 9200 pin configs for
1386 102801C0
1387 102801C1
1388*/
1389static unsigned int dell9200_d22_pin_configs[8] = {
1390 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
1391 0x01813020, 0x02a19021, 0x90100140, 0x400001f2,
1392};
1393
1394/*
1395 STAC 9200 pin configs for
1396 102801C4 (Dell Dimension E310)
1397 102801C5
1398 102801C7
1399 102801D9
1400 102801DA
1401 102801E3
1402*/
1403static unsigned int dell9200_d23_pin_configs[8] = {
1404 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
1405 0x01813020, 0x01a19021, 0x90100140, 0x400001f2,
1406};
1407
1408
1409/*
1410 STAC 9200-32 pin configs for
1411 102801B5 (Dell Inspiron 630m)
1412 102801D8 (Dell Inspiron 640m)
1413*/
1414static unsigned int dell9200_m21_pin_configs[8] = {
1415 0x40c003fa, 0x03441340, 0x0321121f, 0x90170310,
1416 0x408003fb, 0x03a11020, 0x401003fc, 0x403003fd,
1417};
1418
1419/*
1420 STAC 9200-32 pin configs for
1421 102801C2 (Dell Latitude D620)
1422 102801C8
1423 102801CC (Dell Latitude D820)
1424 102801D4
1425 102801D6
1426*/
1427static unsigned int dell9200_m22_pin_configs[8] = {
1428 0x40c003fa, 0x0144131f, 0x0321121f, 0x90170310,
1429 0x90a70321, 0x03a11020, 0x401003fb, 0x40f000fc,
1430};
1431
1432/*
1433 STAC 9200-32 pin configs for
1434 102801CE (Dell XPS M1710)
1435 102801CF (Dell Precision M90)
1436*/
1437static unsigned int dell9200_m23_pin_configs[8] = {
1438 0x40c003fa, 0x01441340, 0x0421421f, 0x90170310,
1439 0x408003fb, 0x04a1102e, 0x90170311, 0x403003fc,
1440};
1441
1442/*
1443 STAC 9200-32 pin configs for
1444 102801C9
1445 102801CA
1446 102801CB (Dell Latitude 120L)
1447 102801D3
1448*/
1449static unsigned int dell9200_m24_pin_configs[8] = {
1450 0x40c003fa, 0x404003fb, 0x0321121f, 0x90170310,
1451 0x408003fc, 0x03a11020, 0x401003fd, 0x403003fe,
1452};
1453
1454/*
1455 STAC 9200-32 pin configs for
1456 102801BD (Dell Inspiron E1505n)
1457 102801EE
1458 102801EF
1459*/
1460static unsigned int dell9200_m25_pin_configs[8] = {
1461 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
1462 0x408003fb, 0x04a11020, 0x401003fc, 0x403003fd,
1463};
1464
1465/*
1466 STAC 9200-32 pin configs for
1467 102801F5 (Dell Inspiron 1501)
1468 102801F6
1469*/
1470static unsigned int dell9200_m26_pin_configs[8] = {
1471 0x40c003fa, 0x404003fb, 0x0421121f, 0x90170310,
1472 0x408003fc, 0x04a11020, 0x401003fd, 0x403003fe,
1473};
1474
1475/*
1476 STAC 9200-32
1477 102801CD (Dell Inspiron E1705/9400)
1478*/
1479static unsigned int dell9200_m27_pin_configs[8] = {
1480 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
1481 0x90170310, 0x04a11020, 0x90170310, 0x40f003fc,
1482};
1483
1484static unsigned int oqo9200_pin_configs[8] = {
1485 0x40c000f0, 0x404000f1, 0x0221121f, 0x02211210,
1486 0x90170111, 0x90a70120, 0x400000f2, 0x400000f3,
1487};
1488
1489
1490static unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
1491 [STAC_REF] = ref9200_pin_configs,
1492 [STAC_9200_OQO] = oqo9200_pin_configs,
1493 [STAC_9200_DELL_D21] = dell9200_d21_pin_configs,
1494 [STAC_9200_DELL_D22] = dell9200_d22_pin_configs,
1495 [STAC_9200_DELL_D23] = dell9200_d23_pin_configs,
1496 [STAC_9200_DELL_M21] = dell9200_m21_pin_configs,
1497 [STAC_9200_DELL_M22] = dell9200_m22_pin_configs,
1498 [STAC_9200_DELL_M23] = dell9200_m23_pin_configs,
1499 [STAC_9200_DELL_M24] = dell9200_m24_pin_configs,
1500 [STAC_9200_DELL_M25] = dell9200_m25_pin_configs,
1501 [STAC_9200_DELL_M26] = dell9200_m26_pin_configs,
1502 [STAC_9200_DELL_M27] = dell9200_m27_pin_configs,
1503 [STAC_9200_PANASONIC] = ref9200_pin_configs,
1504};
1505
1506static const char *stac9200_models[STAC_9200_MODELS] = {
1507 [STAC_REF] = "ref",
1508 [STAC_9200_OQO] = "oqo",
1509 [STAC_9200_DELL_D21] = "dell-d21",
1510 [STAC_9200_DELL_D22] = "dell-d22",
1511 [STAC_9200_DELL_D23] = "dell-d23",
1512 [STAC_9200_DELL_M21] = "dell-m21",
1513 [STAC_9200_DELL_M22] = "dell-m22",
1514 [STAC_9200_DELL_M23] = "dell-m23",
1515 [STAC_9200_DELL_M24] = "dell-m24",
1516 [STAC_9200_DELL_M25] = "dell-m25",
1517 [STAC_9200_DELL_M26] = "dell-m26",
1518 [STAC_9200_DELL_M27] = "dell-m27",
1519 [STAC_9200_GATEWAY] = "gateway",
1520 [STAC_9200_PANASONIC] = "panasonic",
1521};
1522
1523static struct snd_pci_quirk stac9200_cfg_tbl[] = {
1524 /* SigmaTel reference board */
1525 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1526 "DFI LanParty", STAC_REF),
1527 /* Dell laptops have BIOS problem */
1528 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a8,
1529 "unknown Dell", STAC_9200_DELL_D21),
1530 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01b5,
1531 "Dell Inspiron 630m", STAC_9200_DELL_M21),
1532 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bd,
1533 "Dell Inspiron E1505n", STAC_9200_DELL_M25),
1534 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c0,
1535 "unknown Dell", STAC_9200_DELL_D22),
1536 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c1,
1537 "unknown Dell", STAC_9200_DELL_D22),
1538 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c2,
1539 "Dell Latitude D620", STAC_9200_DELL_M22),
1540 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c5,
1541 "unknown Dell", STAC_9200_DELL_D23),
1542 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c7,
1543 "unknown Dell", STAC_9200_DELL_D23),
1544 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c8,
1545 "unknown Dell", STAC_9200_DELL_M22),
1546 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c9,
1547 "unknown Dell", STAC_9200_DELL_M24),
1548 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ca,
1549 "unknown Dell", STAC_9200_DELL_M24),
1550 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cb,
1551 "Dell Latitude 120L", STAC_9200_DELL_M24),
1552 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cc,
1553 "Dell Latitude D820", STAC_9200_DELL_M22),
1554 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cd,
1555 "Dell Inspiron E1705/9400", STAC_9200_DELL_M27),
1556 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ce,
1557 "Dell XPS M1710", STAC_9200_DELL_M23),
1558 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cf,
1559 "Dell Precision M90", STAC_9200_DELL_M23),
1560 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d3,
1561 "unknown Dell", STAC_9200_DELL_M22),
1562 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d4,
1563 "unknown Dell", STAC_9200_DELL_M22),
1564 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d6,
1565 "unknown Dell", STAC_9200_DELL_M22),
1566 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d8,
1567 "Dell Inspiron 640m", STAC_9200_DELL_M21),
1568 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d9,
1569 "unknown Dell", STAC_9200_DELL_D23),
1570 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01da,
1571 "unknown Dell", STAC_9200_DELL_D23),
1572 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01de,
1573 "unknown Dell", STAC_9200_DELL_D21),
1574 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e3,
1575 "unknown Dell", STAC_9200_DELL_D23),
1576 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e8,
1577 "unknown Dell", STAC_9200_DELL_D21),
1578 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ee,
1579 "unknown Dell", STAC_9200_DELL_M25),
1580 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ef,
1581 "unknown Dell", STAC_9200_DELL_M25),
1582 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f5,
1583 "Dell Inspiron 1501", STAC_9200_DELL_M26),
1584 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f6,
1585 "unknown Dell", STAC_9200_DELL_M26),
1586 /* Panasonic */
1587 SND_PCI_QUIRK(0x10f7, 0x8338, "Panasonic CF-74", STAC_9200_PANASONIC),
1588 /* Gateway machines needs EAPD to be set on resume */
1589 SND_PCI_QUIRK(0x107b, 0x0205, "Gateway S-7110M", STAC_9200_GATEWAY),
1590 SND_PCI_QUIRK(0x107b, 0x0317, "Gateway MT3423, MX341*",
1591 STAC_9200_GATEWAY),
1592 SND_PCI_QUIRK(0x107b, 0x0318, "Gateway ML3019, MT3707",
1593 STAC_9200_GATEWAY),
1594 /* OQO Mobile */
1595 SND_PCI_QUIRK(0x1106, 0x3288, "OQO Model 2", STAC_9200_OQO),
1596 {} /* terminator */
1597};
1598
1599static unsigned int ref925x_pin_configs[8] = {
1600 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
1601 0x90a70320, 0x02214210, 0x01019020, 0x9033032e,
1602};
1603
1604static unsigned int stac925x_MA6_pin_configs[8] = {
1605 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
1606 0x90a70320, 0x90100211, 0x400003f1, 0x9033032e,
1607};
1608
1609static unsigned int stac925x_PA6_pin_configs[8] = {
1610 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
1611 0x50a103f0, 0x90100211, 0x400003f1, 0x9033032e,
1612};
1613
1614static unsigned int stac925xM2_2_pin_configs[8] = {
1615 0x40c003f3, 0x424503f2, 0x04180011, 0x02a19020,
1616 0x50a103f0, 0x90100212, 0x400003f1, 0x9033032e,
1617};
1618
1619static unsigned int *stac925x_brd_tbl[STAC_925x_MODELS] = {
1620 [STAC_REF] = ref925x_pin_configs,
1621 [STAC_M2_2] = stac925xM2_2_pin_configs,
1622 [STAC_MA6] = stac925x_MA6_pin_configs,
1623 [STAC_PA6] = stac925x_PA6_pin_configs,
1624};
1625
1626static const char *stac925x_models[STAC_925x_MODELS] = {
1627 [STAC_REF] = "ref",
1628 [STAC_M2_2] = "m2-2",
1629 [STAC_MA6] = "m6",
1630 [STAC_PA6] = "pa6",
1631};
1632
1633static struct snd_pci_quirk stac925x_cfg_tbl[] = {
1634 /* SigmaTel reference board */
1635 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, "DFI LanParty", STAC_REF),
1636 SND_PCI_QUIRK(0x8384, 0x7632, "Stac9202 Reference Board", STAC_REF),
1637 SND_PCI_QUIRK(0x107b, 0x0316, "Gateway M255", STAC_REF),
1638 SND_PCI_QUIRK(0x107b, 0x0366, "Gateway MP6954", STAC_REF),
1639 SND_PCI_QUIRK(0x107b, 0x0461, "Gateway NX560XL", STAC_MA6),
1640 SND_PCI_QUIRK(0x107b, 0x0681, "Gateway NX860", STAC_PA6),
1641 SND_PCI_QUIRK(0x1002, 0x437b, "Gateway MX6453", STAC_M2_2),
1642 {} /* terminator */
1643};
1644
1645static unsigned int ref92hd73xx_pin_configs[13] = {
1646 0x02214030, 0x02a19040, 0x01a19020, 0x02214030,
1647 0x0181302e, 0x01014010, 0x01014020, 0x01014030,
1648 0x02319040, 0x90a000f0, 0x90a000f0, 0x01452050,
1649 0x01452050,
1650};
1651
1652static unsigned int dell_m6_pin_configs[13] = {
1653 0x0321101f, 0x4f00000f, 0x4f0000f0, 0x90170110,
1654 0x03a11020, 0x0321101f, 0x4f0000f0, 0x4f0000f0,
1655 0x4f0000f0, 0x90a60160, 0x4f0000f0, 0x4f0000f0,
1656 0x4f0000f0,
1657};
1658
1659static unsigned int *stac92hd73xx_brd_tbl[STAC_92HD73XX_MODELS] = {
1660 [STAC_92HD73XX_REF] = ref92hd73xx_pin_configs,
1661 [STAC_DELL_M6_AMIC] = dell_m6_pin_configs,
1662 [STAC_DELL_M6_DMIC] = dell_m6_pin_configs,
1663 [STAC_DELL_M6_BOTH] = dell_m6_pin_configs,
1664 [STAC_DELL_EQ] = dell_m6_pin_configs,
1665};
1666
1667static const char *stac92hd73xx_models[STAC_92HD73XX_MODELS] = {
1668 [STAC_92HD73XX_REF] = "ref",
1669 [STAC_DELL_M6_AMIC] = "dell-m6-amic",
1670 [STAC_DELL_M6_DMIC] = "dell-m6-dmic",
1671 [STAC_DELL_M6_BOTH] = "dell-m6",
1672 [STAC_DELL_EQ] = "dell-eq",
1673};
1674
1675static struct snd_pci_quirk stac92hd73xx_cfg_tbl[] = {
1676 /* SigmaTel reference board */
1677 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1678 "DFI LanParty", STAC_92HD73XX_REF),
1679 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0254,
1680 "Dell Studio 1535", STAC_DELL_M6_DMIC),
1681 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0255,
1682 "unknown Dell", STAC_DELL_M6_DMIC),
1683 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0256,
1684 "unknown Dell", STAC_DELL_M6_BOTH),
1685 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0257,
1686 "unknown Dell", STAC_DELL_M6_BOTH),
1687 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025e,
1688 "unknown Dell", STAC_DELL_M6_AMIC),
1689 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025f,
1690 "unknown Dell", STAC_DELL_M6_AMIC),
1691 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0271,
1692 "unknown Dell", STAC_DELL_M6_DMIC),
1693 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0272,
1694 "unknown Dell", STAC_DELL_M6_DMIC),
1695 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x029f,
1696 "Dell Studio 1537", STAC_DELL_M6_DMIC),
1697 {} /* terminator */
1698};
1699
1700static unsigned int ref92hd83xxx_pin_configs[14] = {
1701 0x02214030, 0x02211010, 0x02a19020, 0x02170130,
1702 0x01014050, 0x01819040, 0x01014020, 0x90a3014e,
1703 0x40f000f0, 0x40f000f0, 0x40f000f0, 0x40f000f0,
1704 0x01451160, 0x98560170,
1705};
1706
1707static unsigned int *stac92hd83xxx_brd_tbl[STAC_92HD83XXX_MODELS] = {
1708 [STAC_92HD83XXX_REF] = ref92hd83xxx_pin_configs,
1709};
1710
1711static const char *stac92hd83xxx_models[STAC_92HD83XXX_MODELS] = {
1712 [STAC_92HD83XXX_REF] = "ref",
1713};
1714
1715static struct snd_pci_quirk stac92hd83xxx_cfg_tbl[] = {
1716 /* SigmaTel reference board */
1717 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1718 "DFI LanParty", STAC_92HD71BXX_REF),
1719};
1720
1721static unsigned int ref92hd71bxx_pin_configs[11] = {
1722 0x02214030, 0x02a19040, 0x01a19020, 0x01014010,
1723 0x0181302e, 0x01014010, 0x01019020, 0x90a000f0,
1724 0x90a000f0, 0x01452050, 0x01452050,
1725};
1726
1727static unsigned int dell_m4_1_pin_configs[11] = {
1728 0x0421101f, 0x04a11221, 0x40f000f0, 0x90170110,
1729 0x23a1902e, 0x23014250, 0x40f000f0, 0x90a000f0,
1730 0x40f000f0, 0x4f0000f0, 0x4f0000f0,
1731};
1732
1733static unsigned int dell_m4_2_pin_configs[11] = {
1734 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1735 0x23a1902e, 0x23014250, 0x40f000f0, 0x40f000f0,
1736 0x40f000f0, 0x044413b0, 0x044413b0,
1737};
1738
1739static unsigned int dell_m4_3_pin_configs[11] = {
1740 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1741 0x40f000f0, 0x40f000f0, 0x40f000f0, 0x90a000f0,
1742 0x40f000f0, 0x044413b0, 0x044413b0,
1743};
1744
1745static unsigned int *stac92hd71bxx_brd_tbl[STAC_92HD71BXX_MODELS] = {
1746 [STAC_92HD71BXX_REF] = ref92hd71bxx_pin_configs,
1747 [STAC_DELL_M4_1] = dell_m4_1_pin_configs,
1748 [STAC_DELL_M4_2] = dell_m4_2_pin_configs,
1749 [STAC_DELL_M4_3] = dell_m4_3_pin_configs,
1750 [STAC_HP_M4] = NULL,
1751};
1752
1753static const char *stac92hd71bxx_models[STAC_92HD71BXX_MODELS] = {
1754 [STAC_92HD71BXX_REF] = "ref",
1755 [STAC_DELL_M4_1] = "dell-m4-1",
1756 [STAC_DELL_M4_2] = "dell-m4-2",
1757 [STAC_DELL_M4_3] = "dell-m4-3",
1758 [STAC_HP_M4] = "hp-m4",
1759};
1760
1761static struct snd_pci_quirk stac92hd71bxx_cfg_tbl[] = {
1762 /* SigmaTel reference board */
1763 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1764 "DFI LanParty", STAC_92HD71BXX_REF),
1765 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x30f2,
1766 "HP dv5", STAC_HP_M4),
1767 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x30f4,
1768 "HP dv7", STAC_HP_M4),
1769 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361a,
1770 "unknown HP", STAC_HP_M4),
1771 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0233,
1772 "unknown Dell", STAC_DELL_M4_1),
1773 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0234,
1774 "unknown Dell", STAC_DELL_M4_1),
1775 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0250,
1776 "unknown Dell", STAC_DELL_M4_1),
1777 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024f,
1778 "unknown Dell", STAC_DELL_M4_1),
1779 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024d,
1780 "unknown Dell", STAC_DELL_M4_1),
1781 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0251,
1782 "unknown Dell", STAC_DELL_M4_1),
1783 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0277,
1784 "unknown Dell", STAC_DELL_M4_1),
1785 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0263,
1786 "unknown Dell", STAC_DELL_M4_2),
1787 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0265,
1788 "unknown Dell", STAC_DELL_M4_2),
1789 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0262,
1790 "unknown Dell", STAC_DELL_M4_2),
1791 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0264,
1792 "unknown Dell", STAC_DELL_M4_2),
1793 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02aa,
1794 "unknown Dell", STAC_DELL_M4_3),
1795 {} /* terminator */
1796};
1797
1798static unsigned int ref922x_pin_configs[10] = {
1799 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
1800 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
1801 0x40000100, 0x40000100,
1802};
1803
1804/*
1805 STAC 922X pin configs for
1806 102801A7
1807 102801AB
1808 102801A9
1809 102801D1
1810 102801D2
1811*/
1812static unsigned int dell_922x_d81_pin_configs[10] = {
1813 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1814 0x02a19020, 0x01117011, 0x400001f0, 0x400001f1,
1815 0x01813122, 0x400001f2,
1816};
1817
1818/*
1819 STAC 922X pin configs for
1820 102801AC
1821 102801D0
1822*/
1823static unsigned int dell_922x_d82_pin_configs[10] = {
1824 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1825 0x02a19020, 0x01117011, 0x01451140, 0x400001f0,
1826 0x01813122, 0x400001f1,
1827};
1828
1829/*
1830 STAC 922X pin configs for
1831 102801BF
1832*/
1833static unsigned int dell_922x_m81_pin_configs[10] = {
1834 0x0321101f, 0x01112024, 0x01111222, 0x91174220,
1835 0x03a11050, 0x01116221, 0x90a70330, 0x01452340,
1836 0x40C003f1, 0x405003f0,
1837};
1838
1839/*
1840 STAC 9221 A1 pin configs for
1841 102801D7 (Dell XPS M1210)
1842*/
1843static unsigned int dell_922x_m82_pin_configs[10] = {
1844 0x02211211, 0x408103ff, 0x02a1123e, 0x90100310,
1845 0x408003f1, 0x0221121f, 0x03451340, 0x40c003f2,
1846 0x508003f3, 0x405003f4,
1847};
1848
1849static unsigned int d945gtp3_pin_configs[10] = {
1850 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
1851 0x40000100, 0x40000100, 0x40000100, 0x40000100,
1852 0x02a19120, 0x40000100,
1853};
1854
1855static unsigned int d945gtp5_pin_configs[10] = {
1856 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
1857 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
1858 0x02a19320, 0x40000100,
1859};
1860
1861static unsigned int intel_mac_v1_pin_configs[10] = {
1862 0x0121e21f, 0x400000ff, 0x9017e110, 0x400000fd,
1863 0x400000fe, 0x0181e020, 0x1145e030, 0x11c5e240,
1864 0x400000fc, 0x400000fb,
1865};
1866
1867static unsigned int intel_mac_v2_pin_configs[10] = {
1868 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
1869 0x400000fe, 0x0181e020, 0x1145e230, 0x500000fa,
1870 0x400000fc, 0x400000fb,
1871};
1872
1873static unsigned int intel_mac_v3_pin_configs[10] = {
1874 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
1875 0x400000fe, 0x0181e020, 0x1145e230, 0x11c5e240,
1876 0x400000fc, 0x400000fb,
1877};
1878
1879static unsigned int intel_mac_v4_pin_configs[10] = {
1880 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
1881 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
1882 0x400000fc, 0x400000fb,
1883};
1884
1885static unsigned int intel_mac_v5_pin_configs[10] = {
1886 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
1887 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
1888 0x400000fc, 0x400000fb,
1889};
1890
1891static unsigned int ecs202_pin_configs[10] = {
1892 0x0221401f, 0x02a19020, 0x01a19020, 0x01114010,
1893 0x408000f0, 0x01813022, 0x074510a0, 0x40c400f1,
1894 0x9037012e, 0x40e000f2,
1895};
1896
1897static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
1898 [STAC_D945_REF] = ref922x_pin_configs,
1899 [STAC_D945GTP3] = d945gtp3_pin_configs,
1900 [STAC_D945GTP5] = d945gtp5_pin_configs,
1901 [STAC_INTEL_MAC_V1] = intel_mac_v1_pin_configs,
1902 [STAC_INTEL_MAC_V2] = intel_mac_v2_pin_configs,
1903 [STAC_INTEL_MAC_V3] = intel_mac_v3_pin_configs,
1904 [STAC_INTEL_MAC_V4] = intel_mac_v4_pin_configs,
1905 [STAC_INTEL_MAC_V5] = intel_mac_v5_pin_configs,
1906 [STAC_INTEL_MAC_AUTO] = intel_mac_v3_pin_configs,
1907 /* for backward compatibility */
1908 [STAC_MACMINI] = intel_mac_v3_pin_configs,
1909 [STAC_MACBOOK] = intel_mac_v5_pin_configs,
1910 [STAC_MACBOOK_PRO_V1] = intel_mac_v3_pin_configs,
1911 [STAC_MACBOOK_PRO_V2] = intel_mac_v3_pin_configs,
1912 [STAC_IMAC_INTEL] = intel_mac_v2_pin_configs,
1913 [STAC_IMAC_INTEL_20] = intel_mac_v3_pin_configs,
1914 [STAC_ECS_202] = ecs202_pin_configs,
1915 [STAC_922X_DELL_D81] = dell_922x_d81_pin_configs,
1916 [STAC_922X_DELL_D82] = dell_922x_d82_pin_configs,
1917 [STAC_922X_DELL_M81] = dell_922x_m81_pin_configs,
1918 [STAC_922X_DELL_M82] = dell_922x_m82_pin_configs,
1919};
1920
1921static const char *stac922x_models[STAC_922X_MODELS] = {
1922 [STAC_D945_REF] = "ref",
1923 [STAC_D945GTP5] = "5stack",
1924 [STAC_D945GTP3] = "3stack",
1925 [STAC_INTEL_MAC_V1] = "intel-mac-v1",
1926 [STAC_INTEL_MAC_V2] = "intel-mac-v2",
1927 [STAC_INTEL_MAC_V3] = "intel-mac-v3",
1928 [STAC_INTEL_MAC_V4] = "intel-mac-v4",
1929 [STAC_INTEL_MAC_V5] = "intel-mac-v5",
1930 [STAC_INTEL_MAC_AUTO] = "intel-mac-auto",
1931 /* for backward compatibility */
1932 [STAC_MACMINI] = "macmini",
1933 [STAC_MACBOOK] = "macbook",
1934 [STAC_MACBOOK_PRO_V1] = "macbook-pro-v1",
1935 [STAC_MACBOOK_PRO_V2] = "macbook-pro",
1936 [STAC_IMAC_INTEL] = "imac-intel",
1937 [STAC_IMAC_INTEL_20] = "imac-intel-20",
1938 [STAC_ECS_202] = "ecs202",
1939 [STAC_922X_DELL_D81] = "dell-d81",
1940 [STAC_922X_DELL_D82] = "dell-d82",
1941 [STAC_922X_DELL_M81] = "dell-m81",
1942 [STAC_922X_DELL_M82] = "dell-m82",
1943};
1944
1945static struct snd_pci_quirk stac922x_cfg_tbl[] = {
1946 /* SigmaTel reference board */
1947 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1948 "DFI LanParty", STAC_D945_REF),
1949 /* Intel 945G based systems */
1950 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101,
1951 "Intel D945G", STAC_D945GTP3),
1952 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0202,
1953 "Intel D945G", STAC_D945GTP3),
1954 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0606,
1955 "Intel D945G", STAC_D945GTP3),
1956 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0601,
1957 "Intel D945G", STAC_D945GTP3),
1958 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0111,
1959 "Intel D945G", STAC_D945GTP3),
1960 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1115,
1961 "Intel D945G", STAC_D945GTP3),
1962 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1116,
1963 "Intel D945G", STAC_D945GTP3),
1964 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1117,
1965 "Intel D945G", STAC_D945GTP3),
1966 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1118,
1967 "Intel D945G", STAC_D945GTP3),
1968 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1119,
1969 "Intel D945G", STAC_D945GTP3),
1970 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x8826,
1971 "Intel D945G", STAC_D945GTP3),
1972 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5049,
1973 "Intel D945G", STAC_D945GTP3),
1974 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5055,
1975 "Intel D945G", STAC_D945GTP3),
1976 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5048,
1977 "Intel D945G", STAC_D945GTP3),
1978 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0110,
1979 "Intel D945G", STAC_D945GTP3),
1980 /* Intel D945G 5-stack systems */
1981 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0404,
1982 "Intel D945G", STAC_D945GTP5),
1983 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0303,
1984 "Intel D945G", STAC_D945GTP5),
1985 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0013,
1986 "Intel D945G", STAC_D945GTP5),
1987 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0417,
1988 "Intel D945G", STAC_D945GTP5),
1989 /* Intel 945P based systems */
1990 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0b0b,
1991 "Intel D945P", STAC_D945GTP3),
1992 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0112,
1993 "Intel D945P", STAC_D945GTP3),
1994 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0d0d,
1995 "Intel D945P", STAC_D945GTP3),
1996 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0909,
1997 "Intel D945P", STAC_D945GTP3),
1998 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0505,
1999 "Intel D945P", STAC_D945GTP3),
2000 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707,
2001 "Intel D945P", STAC_D945GTP5),
2002 /* other systems */
2003 /* Apple Intel Mac (Mac Mini, MacBook, MacBook Pro...) */
2004 SND_PCI_QUIRK(0x8384, 0x7680,
2005 "Mac", STAC_INTEL_MAC_AUTO),
2006 /* Dell systems */
2007 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a7,
2008 "unknown Dell", STAC_922X_DELL_D81),
2009 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a9,
2010 "unknown Dell", STAC_922X_DELL_D81),
2011 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ab,
2012 "unknown Dell", STAC_922X_DELL_D81),
2013 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ac,
2014 "unknown Dell", STAC_922X_DELL_D82),
2015 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bf,
2016 "unknown Dell", STAC_922X_DELL_M81),
2017 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d0,
2018 "unknown Dell", STAC_922X_DELL_D82),
2019 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d1,
2020 "unknown Dell", STAC_922X_DELL_D81),
2021 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d2,
2022 "unknown Dell", STAC_922X_DELL_D81),
2023 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d7,
2024 "Dell XPS M1210", STAC_922X_DELL_M82),
2025 /* ECS/PC Chips boards */
2026 SND_PCI_QUIRK(0x1019, 0x2144,
2027 "ECS/PC chips", STAC_ECS_202),
2028 SND_PCI_QUIRK(0x1019, 0x2608,
2029 "ECS/PC chips", STAC_ECS_202),
2030 SND_PCI_QUIRK(0x1019, 0x2633,
2031 "ECS/PC chips P17G/1333", STAC_ECS_202),
2032 SND_PCI_QUIRK(0x1019, 0x2811,
2033 "ECS/PC chips", STAC_ECS_202),
2034 SND_PCI_QUIRK(0x1019, 0x2812,
2035 "ECS/PC chips", STAC_ECS_202),
2036 SND_PCI_QUIRK(0x1019, 0x2813,
2037 "ECS/PC chips", STAC_ECS_202),
2038 SND_PCI_QUIRK(0x1019, 0x2814,
2039 "ECS/PC chips", STAC_ECS_202),
2040 SND_PCI_QUIRK(0x1019, 0x2815,
2041 "ECS/PC chips", STAC_ECS_202),
2042 SND_PCI_QUIRK(0x1019, 0x2816,
2043 "ECS/PC chips", STAC_ECS_202),
2044 SND_PCI_QUIRK(0x1019, 0x2817,
2045 "ECS/PC chips", STAC_ECS_202),
2046 SND_PCI_QUIRK(0x1019, 0x2818,
2047 "ECS/PC chips", STAC_ECS_202),
2048 SND_PCI_QUIRK(0x1019, 0x2819,
2049 "ECS/PC chips", STAC_ECS_202),
2050 SND_PCI_QUIRK(0x1019, 0x2820,
2051 "ECS/PC chips", STAC_ECS_202),
2052 {} /* terminator */
2053};
2054
2055static unsigned int ref927x_pin_configs[14] = {
2056 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2057 0x01a19040, 0x01011012, 0x01016011, 0x0101201f,
2058 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
2059 0x01c42190, 0x40000100,
2060};
2061
2062static unsigned int d965_3st_pin_configs[14] = {
2063 0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
2064 0x01a19021, 0x01813024, 0x40000100, 0x40000100,
2065 0x40000100, 0x40000100, 0x40000100, 0x40000100,
2066 0x40000100, 0x40000100
2067};
2068
2069static unsigned int d965_5st_pin_configs[14] = {
2070 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2071 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
2072 0x40000100, 0x40000100, 0x40000100, 0x01442070,
2073 0x40000100, 0x40000100
2074};
2075
2076static unsigned int dell_3st_pin_configs[14] = {
2077 0x02211230, 0x02a11220, 0x01a19040, 0x01114210,
2078 0x01111212, 0x01116211, 0x01813050, 0x01112214,
2079 0x403003fa, 0x90a60040, 0x90a60040, 0x404003fb,
2080 0x40c003fc, 0x40000100
2081};
2082
2083static unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
2084 [STAC_D965_REF] = ref927x_pin_configs,
2085 [STAC_D965_3ST] = d965_3st_pin_configs,
2086 [STAC_D965_5ST] = d965_5st_pin_configs,
2087 [STAC_DELL_3ST] = dell_3st_pin_configs,
2088 [STAC_DELL_BIOS] = NULL,
2089};
2090
2091static const char *stac927x_models[STAC_927X_MODELS] = {
2092 [STAC_D965_REF] = "ref",
2093 [STAC_D965_3ST] = "3stack",
2094 [STAC_D965_5ST] = "5stack",
2095 [STAC_DELL_3ST] = "dell-3stack",
2096 [STAC_DELL_BIOS] = "dell-bios",
2097};
2098
2099static struct snd_pci_quirk stac927x_cfg_tbl[] = {
2100 /* SigmaTel reference board */
2101 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2102 "DFI LanParty", STAC_D965_REF),
2103 /* Intel 946 based systems */
2104 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST),
2105 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST),
2106 /* 965 based 3 stack systems */
2107 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2116, "Intel D965", STAC_D965_3ST),
2108 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2115, "Intel D965", STAC_D965_3ST),
2109 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2114, "Intel D965", STAC_D965_3ST),
2110 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2113, "Intel D965", STAC_D965_3ST),
2111 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2112, "Intel D965", STAC_D965_3ST),
2112 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2111, "Intel D965", STAC_D965_3ST),
2113 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2110, "Intel D965", STAC_D965_3ST),
2114 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2009, "Intel D965", STAC_D965_3ST),
2115 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2008, "Intel D965", STAC_D965_3ST),
2116 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2007, "Intel D965", STAC_D965_3ST),
2117 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2006, "Intel D965", STAC_D965_3ST),
2118 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2005, "Intel D965", STAC_D965_3ST),
2119 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2004, "Intel D965", STAC_D965_3ST),
2120 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2003, "Intel D965", STAC_D965_3ST),
2121 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2002, "Intel D965", STAC_D965_3ST),
2122 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2001, "Intel D965", STAC_D965_3ST),
2123 /* Dell 3 stack systems */
2124 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f7, "Dell XPS M1730", STAC_DELL_3ST),
2125 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01dd, "Dell Dimension E520", STAC_DELL_3ST),
2126 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ed, "Dell ", STAC_DELL_3ST),
2127 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f4, "Dell ", STAC_DELL_3ST),
2128 /* Dell 3 stack systems with verb table in BIOS */
2129 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f3, "Dell Inspiron 1420", STAC_DELL_BIOS),
2130 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0227, "Dell Vostro 1400 ", STAC_DELL_BIOS),
2131 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022e, "Dell ", STAC_DELL_BIOS),
2132 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022f, "Dell Inspiron 1525", STAC_DELL_3ST),
2133 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0242, "Dell ", STAC_DELL_BIOS),
2134 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0243, "Dell ", STAC_DELL_BIOS),
2135 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ff, "Dell ", STAC_DELL_BIOS),
2136 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0209, "Dell XPS 1330", STAC_DELL_BIOS),
2137 /* 965 based 5 stack systems */
2138 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2301, "Intel D965", STAC_D965_5ST),
2139 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2302, "Intel D965", STAC_D965_5ST),
2140 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2303, "Intel D965", STAC_D965_5ST),
2141 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2304, "Intel D965", STAC_D965_5ST),
2142 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2305, "Intel D965", STAC_D965_5ST),
2143 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2501, "Intel D965", STAC_D965_5ST),
2144 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2502, "Intel D965", STAC_D965_5ST),
2145 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2503, "Intel D965", STAC_D965_5ST),
2146 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2504, "Intel D965", STAC_D965_5ST),
2147 {} /* terminator */
2148};
2149
2150static unsigned int ref9205_pin_configs[12] = {
2151 0x40000100, 0x40000100, 0x01016011, 0x01014010,
2152 0x01813122, 0x01a19021, 0x01019020, 0x40000100,
2153 0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
2154};
2155
2156/*
2157 STAC 9205 pin configs for
2158 102801F1
2159 102801F2
2160 102801FC
2161 102801FD
2162 10280204
2163 1028021F
2164 10280228 (Dell Vostro 1500)
2165*/
2166static unsigned int dell_9205_m42_pin_configs[12] = {
2167 0x0321101F, 0x03A11020, 0x400003FA, 0x90170310,
2168 0x400003FB, 0x400003FC, 0x400003FD, 0x40F000F9,
2169 0x90A60330, 0x400003FF, 0x0144131F, 0x40C003FE,
2170};
2171
2172/*
2173 STAC 9205 pin configs for
2174 102801F9
2175 102801FA
2176 102801FE
2177 102801FF (Dell Precision M4300)
2178 10280206
2179 10280200
2180 10280201
2181*/
2182static unsigned int dell_9205_m43_pin_configs[12] = {
2183 0x0321101f, 0x03a11020, 0x90a70330, 0x90170310,
2184 0x400000fe, 0x400000ff, 0x400000fd, 0x40f000f9,
2185 0x400000fa, 0x400000fc, 0x0144131f, 0x40c003f8,
2186};
2187
2188static unsigned int dell_9205_m44_pin_configs[12] = {
2189 0x0421101f, 0x04a11020, 0x400003fa, 0x90170310,
2190 0x400003fb, 0x400003fc, 0x400003fd, 0x400003f9,
2191 0x90a60330, 0x400003ff, 0x01441340, 0x40c003fe,
2192};
2193
2194static unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
2195 [STAC_9205_REF] = ref9205_pin_configs,
2196 [STAC_9205_DELL_M42] = dell_9205_m42_pin_configs,
2197 [STAC_9205_DELL_M43] = dell_9205_m43_pin_configs,
2198 [STAC_9205_DELL_M44] = dell_9205_m44_pin_configs,
2199};
2200
2201static const char *stac9205_models[STAC_9205_MODELS] = {
2202 [STAC_9205_REF] = "ref",
2203 [STAC_9205_DELL_M42] = "dell-m42",
2204 [STAC_9205_DELL_M43] = "dell-m43",
2205 [STAC_9205_DELL_M44] = "dell-m44",
2206};
2207
2208static struct snd_pci_quirk stac9205_cfg_tbl[] = {
2209 /* SigmaTel reference board */
2210 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2211 "DFI LanParty", STAC_9205_REF),
2212 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f1,
2213 "unknown Dell", STAC_9205_DELL_M42),
2214 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f2,
2215 "unknown Dell", STAC_9205_DELL_M42),
2216 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f8,
2217 "Dell Precision", STAC_9205_DELL_M43),
2218 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f9,
2219 "Dell Precision", STAC_9205_DELL_M43),
2220 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fa,
2221 "Dell Precision", STAC_9205_DELL_M43),
2222 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fc,
2223 "unknown Dell", STAC_9205_DELL_M42),
2224 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fd,
2225 "unknown Dell", STAC_9205_DELL_M42),
2226 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fe,
2227 "Dell Precision", STAC_9205_DELL_M43),
2228 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ff,
2229 "Dell Precision M4300", STAC_9205_DELL_M43),
2230 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0204,
2231 "unknown Dell", STAC_9205_DELL_M42),
2232 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0206,
2233 "Dell Precision", STAC_9205_DELL_M43),
2234 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021b,
2235 "Dell Precision", STAC_9205_DELL_M43),
2236 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021c,
2237 "Dell Precision", STAC_9205_DELL_M43),
2238 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021f,
2239 "Dell Inspiron", STAC_9205_DELL_M44),
2240 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0228,
2241 "Dell Vostro 1500", STAC_9205_DELL_M42),
2242 {} /* terminator */
2243};
2244
2245static int stac92xx_save_bios_config_regs(struct hda_codec *codec)
2246{
2247 int i;
2248 struct sigmatel_spec *spec = codec->spec;
2249
2250 kfree(spec->pin_configs);
2251 spec->pin_configs = kcalloc(spec->num_pins, sizeof(*spec->pin_configs),
2252 GFP_KERNEL);
2253 if (!spec->pin_configs)
2254 return -ENOMEM;
2255
2256 for (i = 0; i < spec->num_pins; i++) {
2257 hda_nid_t nid = spec->pin_nids[i];
2258 unsigned int pin_cfg;
2259
2260 pin_cfg = snd_hda_codec_read(codec, nid, 0,
2261 AC_VERB_GET_CONFIG_DEFAULT, 0x00);
2262 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x bios pin config %8.8x\n",
2263 nid, pin_cfg);
2264 spec->pin_configs[i] = pin_cfg;
2265 }
2266
2267 return 0;
2268}
2269
2270static void stac92xx_set_config_reg(struct hda_codec *codec,
2271 hda_nid_t pin_nid, unsigned int pin_config)
2272{
2273 int i;
2274 snd_hda_codec_write(codec, pin_nid, 0,
2275 AC_VERB_SET_CONFIG_DEFAULT_BYTES_0,
2276 pin_config & 0x000000ff);
2277 snd_hda_codec_write(codec, pin_nid, 0,
2278 AC_VERB_SET_CONFIG_DEFAULT_BYTES_1,
2279 (pin_config & 0x0000ff00) >> 8);
2280 snd_hda_codec_write(codec, pin_nid, 0,
2281 AC_VERB_SET_CONFIG_DEFAULT_BYTES_2,
2282 (pin_config & 0x00ff0000) >> 16);
2283 snd_hda_codec_write(codec, pin_nid, 0,
2284 AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
2285 pin_config >> 24);
2286 i = snd_hda_codec_read(codec, pin_nid, 0,
2287 AC_VERB_GET_CONFIG_DEFAULT,
2288 0x00);
2289 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x pin config %8.8x\n",
2290 pin_nid, i);
2291}
2292
2293static void stac92xx_set_config_regs(struct hda_codec *codec)
2294{
2295 int i;
2296 struct sigmatel_spec *spec = codec->spec;
2297
2298 if (!spec->pin_configs)
2299 return;
2300
2301 for (i = 0; i < spec->num_pins; i++)
2302 stac92xx_set_config_reg(codec, spec->pin_nids[i],
2303 spec->pin_configs[i]);
2304}
2305
2306static int stac_save_pin_cfgs(struct hda_codec *codec, unsigned int *pins)
2307{
2308 struct sigmatel_spec *spec = codec->spec;
2309
2310 if (!pins)
2311 return stac92xx_save_bios_config_regs(codec);
2312
2313 kfree(spec->pin_configs);
2314 spec->pin_configs = kmemdup(pins,
2315 spec->num_pins * sizeof(*pins),
2316 GFP_KERNEL);
2317 if (!spec->pin_configs)
2318 return -ENOMEM;
2319
2320 stac92xx_set_config_regs(codec);
2321 return 0;
2322}
2323
2324static void stac_change_pin_config(struct hda_codec *codec, hda_nid_t nid,
2325 unsigned int cfg)
2326{
2327 struct sigmatel_spec *spec = codec->spec;
2328 int i;
2329
2330 for (i = 0; i < spec->num_pins; i++) {
2331 if (spec->pin_nids[i] == nid) {
2332 spec->pin_configs[i] = cfg;
2333 stac92xx_set_config_reg(codec, nid, cfg);
2334 break;
2335 }
2336 }
2337}
2338
2339/*
2340 * Analog playback callbacks
2341 */
2342static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
2343 struct hda_codec *codec,
2344 struct snd_pcm_substream *substream)
2345{
2346 struct sigmatel_spec *spec = codec->spec;
2347 if (spec->stream_delay)
2348 msleep(spec->stream_delay);
2349 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2350 hinfo);
2351}
2352
2353static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2354 struct hda_codec *codec,
2355 unsigned int stream_tag,
2356 unsigned int format,
2357 struct snd_pcm_substream *substream)
2358{
2359 struct sigmatel_spec *spec = codec->spec;
2360 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
2361}
2362
2363static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2364 struct hda_codec *codec,
2365 struct snd_pcm_substream *substream)
2366{
2367 struct sigmatel_spec *spec = codec->spec;
2368 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2369}
2370
2371/*
2372 * Digital playback callbacks
2373 */
2374static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2375 struct hda_codec *codec,
2376 struct snd_pcm_substream *substream)
2377{
2378 struct sigmatel_spec *spec = codec->spec;
2379 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2380}
2381
2382static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2383 struct hda_codec *codec,
2384 struct snd_pcm_substream *substream)
2385{
2386 struct sigmatel_spec *spec = codec->spec;
2387 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2388}
2389
2390static int stac92xx_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2391 struct hda_codec *codec,
2392 unsigned int stream_tag,
2393 unsigned int format,
2394 struct snd_pcm_substream *substream)
2395{
2396 struct sigmatel_spec *spec = codec->spec;
2397 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2398 stream_tag, format, substream);
2399}
2400
2401
2402/*
2403 * Analog capture callbacks
2404 */
2405static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2406 struct hda_codec *codec,
2407 unsigned int stream_tag,
2408 unsigned int format,
2409 struct snd_pcm_substream *substream)
2410{
2411 struct sigmatel_spec *spec = codec->spec;
2412 hda_nid_t nid = spec->adc_nids[substream->number];
2413
2414 if (spec->powerdown_adcs) {
2415 msleep(40);
2416 snd_hda_codec_write_cache(codec, nid, 0,
2417 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
2418 }
2419 snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format);
2420 return 0;
2421}
2422
2423static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2424 struct hda_codec *codec,
2425 struct snd_pcm_substream *substream)
2426{
2427 struct sigmatel_spec *spec = codec->spec;
2428 hda_nid_t nid = spec->adc_nids[substream->number];
2429
2430 snd_hda_codec_cleanup_stream(codec, nid);
2431 if (spec->powerdown_adcs)
2432 snd_hda_codec_write_cache(codec, nid, 0,
2433 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
2434 return 0;
2435}
2436
2437static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
2438 .substreams = 1,
2439 .channels_min = 2,
2440 .channels_max = 2,
2441 /* NID is set in stac92xx_build_pcms */
2442 .ops = {
2443 .open = stac92xx_dig_playback_pcm_open,
2444 .close = stac92xx_dig_playback_pcm_close,
2445 .prepare = stac92xx_dig_playback_pcm_prepare
2446 },
2447};
2448
2449static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
2450 .substreams = 1,
2451 .channels_min = 2,
2452 .channels_max = 2,
2453 /* NID is set in stac92xx_build_pcms */
2454};
2455
2456static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
2457 .substreams = 1,
2458 .channels_min = 2,
2459 .channels_max = 8,
2460 .nid = 0x02, /* NID to query formats and rates */
2461 .ops = {
2462 .open = stac92xx_playback_pcm_open,
2463 .prepare = stac92xx_playback_pcm_prepare,
2464 .cleanup = stac92xx_playback_pcm_cleanup
2465 },
2466};
2467
2468static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
2469 .substreams = 1,
2470 .channels_min = 2,
2471 .channels_max = 2,
2472 .nid = 0x06, /* NID to query formats and rates */
2473 .ops = {
2474 .open = stac92xx_playback_pcm_open,
2475 .prepare = stac92xx_playback_pcm_prepare,
2476 .cleanup = stac92xx_playback_pcm_cleanup
2477 },
2478};
2479
2480static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
2481 .channels_min = 2,
2482 .channels_max = 2,
2483 /* NID + .substreams is set in stac92xx_build_pcms */
2484 .ops = {
2485 .prepare = stac92xx_capture_pcm_prepare,
2486 .cleanup = stac92xx_capture_pcm_cleanup
2487 },
2488};
2489
2490static int stac92xx_build_pcms(struct hda_codec *codec)
2491{
2492 struct sigmatel_spec *spec = codec->spec;
2493 struct hda_pcm *info = spec->pcm_rec;
2494
2495 codec->num_pcms = 1;
2496 codec->pcm_info = info;
2497
2498 info->name = "STAC92xx Analog";
2499 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
2500 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
2501 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2502 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adcs;
2503
2504 if (spec->alt_switch) {
2505 codec->num_pcms++;
2506 info++;
2507 info->name = "STAC92xx Analog Alt";
2508 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
2509 }
2510
2511 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2512 codec->num_pcms++;
2513 info++;
2514 info->name = "STAC92xx Digital";
2515 info->pcm_type = HDA_PCM_TYPE_SPDIF;
2516 if (spec->multiout.dig_out_nid) {
2517 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
2518 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2519 }
2520 if (spec->dig_in_nid) {
2521 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
2522 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2523 }
2524 }
2525
2526 return 0;
2527}
2528
2529static unsigned int stac92xx_get_vref(struct hda_codec *codec, hda_nid_t nid)
2530{
2531 unsigned int pincap = snd_hda_param_read(codec, nid,
2532 AC_PAR_PIN_CAP);
2533 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
2534 if (pincap & AC_PINCAP_VREF_100)
2535 return AC_PINCTL_VREF_100;
2536 if (pincap & AC_PINCAP_VREF_80)
2537 return AC_PINCTL_VREF_80;
2538 if (pincap & AC_PINCAP_VREF_50)
2539 return AC_PINCTL_VREF_50;
2540 if (pincap & AC_PINCAP_VREF_GRD)
2541 return AC_PINCTL_VREF_GRD;
2542 return 0;
2543}
2544
2545static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
2546
2547{
2548 snd_hda_codec_write_cache(codec, nid, 0,
2549 AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
2550}
2551
2552#define stac92xx_hp_switch_info snd_ctl_boolean_mono_info
2553
2554static int stac92xx_hp_switch_get(struct snd_kcontrol *kcontrol,
2555 struct snd_ctl_elem_value *ucontrol)
2556{
2557 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2558 struct sigmatel_spec *spec = codec->spec;
2559
2560 ucontrol->value.integer.value[0] = !!spec->hp_switch;
2561 return 0;
2562}
2563
2564static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid,
2565 unsigned char type);
2566
2567static int stac92xx_hp_switch_put(struct snd_kcontrol *kcontrol,
2568 struct snd_ctl_elem_value *ucontrol)
2569{
2570 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2571 struct sigmatel_spec *spec = codec->spec;
2572 int nid = kcontrol->private_value;
2573
2574 spec->hp_switch = ucontrol->value.integer.value[0] ? nid : 0;
2575
2576 /* check to be sure that the ports are upto date with
2577 * switch changes
2578 */
2579 stac_issue_unsol_event(codec, nid, STAC_HP_EVENT);
2580
2581 return 1;
2582}
2583
2584#define stac92xx_io_switch_info snd_ctl_boolean_mono_info
2585
2586static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2587{
2588 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2589 struct sigmatel_spec *spec = codec->spec;
2590 int io_idx = kcontrol-> private_value & 0xff;
2591
2592 ucontrol->value.integer.value[0] = spec->io_switch[io_idx];
2593 return 0;
2594}
2595
2596static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2597{
2598 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2599 struct sigmatel_spec *spec = codec->spec;
2600 hda_nid_t nid = kcontrol->private_value >> 8;
2601 int io_idx = kcontrol-> private_value & 0xff;
2602 unsigned short val = !!ucontrol->value.integer.value[0];
2603
2604 spec->io_switch[io_idx] = val;
2605
2606 if (val)
2607 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
2608 else {
2609 unsigned int pinctl = AC_PINCTL_IN_EN;
2610 if (io_idx) /* set VREF for mic */
2611 pinctl |= stac92xx_get_vref(codec, nid);
2612 stac92xx_auto_set_pinctl(codec, nid, pinctl);
2613 }
2614
2615 /* check the auto-mute again: we need to mute/unmute the speaker
2616 * appropriately according to the pin direction
2617 */
2618 if (spec->hp_detect)
2619 stac_issue_unsol_event(codec, nid, STAC_HP_EVENT);
2620
2621 return 1;
2622}
2623
2624#define stac92xx_clfe_switch_info snd_ctl_boolean_mono_info
2625
2626static int stac92xx_clfe_switch_get(struct snd_kcontrol *kcontrol,
2627 struct snd_ctl_elem_value *ucontrol)
2628{
2629 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2630 struct sigmatel_spec *spec = codec->spec;
2631
2632 ucontrol->value.integer.value[0] = spec->clfe_swap;
2633 return 0;
2634}
2635
2636static int stac92xx_clfe_switch_put(struct snd_kcontrol *kcontrol,
2637 struct snd_ctl_elem_value *ucontrol)
2638{
2639 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2640 struct sigmatel_spec *spec = codec->spec;
2641 hda_nid_t nid = kcontrol->private_value & 0xff;
2642 unsigned int val = !!ucontrol->value.integer.value[0];
2643
2644 if (spec->clfe_swap == val)
2645 return 0;
2646
2647 spec->clfe_swap = val;
2648
2649 snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
2650 spec->clfe_swap ? 0x4 : 0x0);
2651
2652 return 1;
2653}
2654
2655#define STAC_CODEC_HP_SWITCH(xname) \
2656 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2657 .name = xname, \
2658 .index = 0, \
2659 .info = stac92xx_hp_switch_info, \
2660 .get = stac92xx_hp_switch_get, \
2661 .put = stac92xx_hp_switch_put, \
2662 }
2663
2664#define STAC_CODEC_IO_SWITCH(xname, xpval) \
2665 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2666 .name = xname, \
2667 .index = 0, \
2668 .info = stac92xx_io_switch_info, \
2669 .get = stac92xx_io_switch_get, \
2670 .put = stac92xx_io_switch_put, \
2671 .private_value = xpval, \
2672 }
2673
2674#define STAC_CODEC_CLFE_SWITCH(xname, xpval) \
2675 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2676 .name = xname, \
2677 .index = 0, \
2678 .info = stac92xx_clfe_switch_info, \
2679 .get = stac92xx_clfe_switch_get, \
2680 .put = stac92xx_clfe_switch_put, \
2681 .private_value = xpval, \
2682 }
2683
2684enum {
2685 STAC_CTL_WIDGET_VOL,
2686 STAC_CTL_WIDGET_MUTE,
2687 STAC_CTL_WIDGET_MONO_MUX,
2688 STAC_CTL_WIDGET_AMP_MUX,
2689 STAC_CTL_WIDGET_AMP_VOL,
2690 STAC_CTL_WIDGET_HP_SWITCH,
2691 STAC_CTL_WIDGET_IO_SWITCH,
2692 STAC_CTL_WIDGET_CLFE_SWITCH
2693};
2694
2695static struct snd_kcontrol_new stac92xx_control_templates[] = {
2696 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2697 HDA_CODEC_MUTE(NULL, 0, 0, 0),
2698 STAC_MONO_MUX,
2699 STAC_AMP_MUX,
2700 STAC_AMP_VOL(NULL, 0, 0, 0, 0),
2701 STAC_CODEC_HP_SWITCH(NULL),
2702 STAC_CODEC_IO_SWITCH(NULL, 0),
2703 STAC_CODEC_CLFE_SWITCH(NULL, 0),
2704};
2705
2706/* add dynamic controls */
2707static int stac92xx_add_control_temp(struct sigmatel_spec *spec,
2708 struct snd_kcontrol_new *ktemp,
2709 int idx, const char *name,
2710 unsigned long val)
2711{
2712 struct snd_kcontrol_new *knew;
2713
2714 snd_array_init(&spec->kctls, sizeof(*knew), 32);
2715 knew = snd_array_new(&spec->kctls);
2716 if (!knew)
2717 return -ENOMEM;
2718 *knew = *ktemp;
2719 knew->index = idx;
2720 knew->name = kstrdup(name, GFP_KERNEL);
2721 if (!knew->name)
2722 return -ENOMEM;
2723 knew->private_value = val;
2724 return 0;
2725}
2726
2727static inline int stac92xx_add_control_idx(struct sigmatel_spec *spec,
2728 int type, int idx, const char *name,
2729 unsigned long val)
2730{
2731 return stac92xx_add_control_temp(spec,
2732 &stac92xx_control_templates[type],
2733 idx, name, val);
2734}
2735
2736
2737/* add dynamic controls */
2738static inline int stac92xx_add_control(struct sigmatel_spec *spec, int type,
2739 const char *name, unsigned long val)
2740{
2741 return stac92xx_add_control_idx(spec, type, 0, name, val);
2742}
2743
2744/* flag inputs as additional dynamic lineouts */
2745static int stac92xx_add_dyn_out_pins(struct hda_codec *codec, struct auto_pin_cfg *cfg)
2746{
2747 struct sigmatel_spec *spec = codec->spec;
2748 unsigned int wcaps, wtype;
2749 int i, num_dacs = 0;
2750
2751 /* use the wcaps cache to count all DACs available for line-outs */
2752 for (i = 0; i < codec->num_nodes; i++) {
2753 wcaps = codec->wcaps[i];
2754 wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
2755
2756 if (wtype == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL))
2757 num_dacs++;
2758 }
2759
2760 snd_printdd("%s: total dac count=%d\n", __func__, num_dacs);
2761
2762 switch (cfg->line_outs) {
2763 case 3:
2764 /* add line-in as side */
2765 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 3) {
2766 cfg->line_out_pins[cfg->line_outs] =
2767 cfg->input_pins[AUTO_PIN_LINE];
2768 spec->line_switch = 1;
2769 cfg->line_outs++;
2770 }
2771 break;
2772 case 2:
2773 /* add line-in as clfe and mic as side */
2774 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 2) {
2775 cfg->line_out_pins[cfg->line_outs] =
2776 cfg->input_pins[AUTO_PIN_LINE];
2777 spec->line_switch = 1;
2778 cfg->line_outs++;
2779 }
2780 if (cfg->input_pins[AUTO_PIN_MIC] && num_dacs > 3) {
2781 cfg->line_out_pins[cfg->line_outs] =
2782 cfg->input_pins[AUTO_PIN_MIC];
2783 spec->mic_switch = 1;
2784 cfg->line_outs++;
2785 }
2786 break;
2787 case 1:
2788 /* add line-in as surr and mic as clfe */
2789 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 1) {
2790 cfg->line_out_pins[cfg->line_outs] =
2791 cfg->input_pins[AUTO_PIN_LINE];
2792 spec->line_switch = 1;
2793 cfg->line_outs++;
2794 }
2795 if (cfg->input_pins[AUTO_PIN_MIC] && num_dacs > 2) {
2796 cfg->line_out_pins[cfg->line_outs] =
2797 cfg->input_pins[AUTO_PIN_MIC];
2798 spec->mic_switch = 1;
2799 cfg->line_outs++;
2800 }
2801 break;
2802 }
2803
2804 return 0;
2805}
2806
2807
2808static int is_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2809{
2810 int i;
2811
2812 for (i = 0; i < spec->multiout.num_dacs; i++) {
2813 if (spec->multiout.dac_nids[i] == nid)
2814 return 1;
2815 }
2816
2817 return 0;
2818}
2819
2820/*
2821 * Fill in the dac_nids table from the parsed pin configuration
2822 * This function only works when every pin in line_out_pins[]
2823 * contains atleast one DAC in its connection list. Some 92xx
2824 * codecs are not connected directly to a DAC, such as the 9200
2825 * and 9202/925x. For those, dac_nids[] must be hard-coded.
2826 */
2827static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec,
2828 struct auto_pin_cfg *cfg)
2829{
2830 struct sigmatel_spec *spec = codec->spec;
2831 int i, j, conn_len = 0;
2832 hda_nid_t nid, conn[HDA_MAX_CONNECTIONS];
2833 unsigned int wcaps, wtype;
2834
2835 for (i = 0; i < cfg->line_outs; i++) {
2836 nid = cfg->line_out_pins[i];
2837 conn_len = snd_hda_get_connections(codec, nid, conn,
2838 HDA_MAX_CONNECTIONS);
2839 for (j = 0; j < conn_len; j++) {
2840 wcaps = snd_hda_param_read(codec, conn[j],
2841 AC_PAR_AUDIO_WIDGET_CAP);
2842 wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
2843 if (wtype != AC_WID_AUD_OUT ||
2844 (wcaps & AC_WCAP_DIGITAL))
2845 continue;
2846 /* conn[j] is a DAC routed to this line-out */
2847 if (!is_in_dac_nids(spec, conn[j]))
2848 break;
2849 }
2850
2851 if (j == conn_len) {
2852 if (spec->multiout.num_dacs > 0) {
2853 /* we have already working output pins,
2854 * so let's drop the broken ones again
2855 */
2856 cfg->line_outs = spec->multiout.num_dacs;
2857 break;
2858 }
2859 /* error out, no available DAC found */
2860 snd_printk(KERN_ERR
2861 "%s: No available DAC for pin 0x%x\n",
2862 __func__, nid);
2863 return -ENODEV;
2864 }
2865
2866 spec->multiout.dac_nids[i] = conn[j];
2867 spec->multiout.num_dacs++;
2868 if (conn_len > 1) {
2869 /* select this DAC in the pin's input mux */
2870 snd_hda_codec_write_cache(codec, nid, 0,
2871 AC_VERB_SET_CONNECT_SEL, j);
2872
2873 }
2874 }
2875
2876 snd_printd("dac_nids=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
2877 spec->multiout.num_dacs,
2878 spec->multiout.dac_nids[0],
2879 spec->multiout.dac_nids[1],
2880 spec->multiout.dac_nids[2],
2881 spec->multiout.dac_nids[3],
2882 spec->multiout.dac_nids[4]);
2883 return 0;
2884}
2885
2886/* create volume control/switch for the given prefx type */
2887static int create_controls(struct sigmatel_spec *spec, const char *pfx, hda_nid_t nid, int chs)
2888{
2889 char name[32];
2890 int err;
2891
2892 sprintf(name, "%s Playback Volume", pfx);
2893 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, name,
2894 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
2895 if (err < 0)
2896 return err;
2897 sprintf(name, "%s Playback Switch", pfx);
2898 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, name,
2899 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
2900 if (err < 0)
2901 return err;
2902 return 0;
2903}
2904
2905static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
2906{
2907 if (!spec->multiout.hp_nid)
2908 spec->multiout.hp_nid = nid;
2909 else if (spec->multiout.num_dacs > 4) {
2910 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
2911 return 1;
2912 } else {
2913 spec->multiout.dac_nids[spec->multiout.num_dacs] = nid;
2914 spec->multiout.num_dacs++;
2915 }
2916 return 0;
2917}
2918
2919static int check_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2920{
2921 if (is_in_dac_nids(spec, nid))
2922 return 1;
2923 if (spec->multiout.hp_nid == nid)
2924 return 1;
2925 return 0;
2926}
2927
2928/* add playback controls from the parsed DAC table */
2929static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
2930 const struct auto_pin_cfg *cfg)
2931{
2932 static const char *chname[4] = {
2933 "Front", "Surround", NULL /*CLFE*/, "Side"
2934 };
2935 hda_nid_t nid = 0;
2936 int i, err;
2937
2938 struct sigmatel_spec *spec = codec->spec;
2939 unsigned int wid_caps, pincap;
2940
2941
2942 for (i = 0; i < cfg->line_outs && i < spec->multiout.num_dacs; i++) {
2943 if (!spec->multiout.dac_nids[i])
2944 continue;
2945
2946 nid = spec->multiout.dac_nids[i];
2947
2948 if (i == 2) {
2949 /* Center/LFE */
2950 err = create_controls(spec, "Center", nid, 1);
2951 if (err < 0)
2952 return err;
2953 err = create_controls(spec, "LFE", nid, 2);
2954 if (err < 0)
2955 return err;
2956
2957 wid_caps = get_wcaps(codec, nid);
2958
2959 if (wid_caps & AC_WCAP_LR_SWAP) {
2960 err = stac92xx_add_control(spec,
2961 STAC_CTL_WIDGET_CLFE_SWITCH,
2962 "Swap Center/LFE Playback Switch", nid);
2963
2964 if (err < 0)
2965 return err;
2966 }
2967
2968 } else {
2969 err = create_controls(spec, chname[i], nid, 3);
2970 if (err < 0)
2971 return err;
2972 }
2973 }
2974
2975 if ((spec->multiout.num_dacs - cfg->line_outs) > 0 &&
2976 cfg->hp_outs && !spec->multiout.hp_nid)
2977 spec->multiout.hp_nid = nid;
2978
2979 if (cfg->hp_outs > 1 && cfg->line_out_type == AUTO_PIN_LINE_OUT) {
2980 err = stac92xx_add_control(spec,
2981 STAC_CTL_WIDGET_HP_SWITCH,
2982 "Headphone as Line Out Switch",
2983 cfg->hp_pins[cfg->hp_outs - 1]);
2984 if (err < 0)
2985 return err;
2986 }
2987
2988 if (spec->line_switch) {
2989 nid = cfg->input_pins[AUTO_PIN_LINE];
2990 pincap = snd_hda_param_read(codec, nid,
2991 AC_PAR_PIN_CAP);
2992 if (pincap & AC_PINCAP_OUT) {
2993 err = stac92xx_add_control(spec,
2994 STAC_CTL_WIDGET_IO_SWITCH,
2995 "Line In as Output Switch", nid << 8);
2996 if (err < 0)
2997 return err;
2998 }
2999 }
3000
3001 if (spec->mic_switch) {
3002 unsigned int def_conf;
3003 unsigned int mic_pin = AUTO_PIN_MIC;
3004again:
3005 nid = cfg->input_pins[mic_pin];
3006 def_conf = snd_hda_codec_read(codec, nid, 0,
3007 AC_VERB_GET_CONFIG_DEFAULT, 0);
3008 /* some laptops have an internal analog microphone
3009 * which can't be used as a output */
3010 if (get_defcfg_connect(def_conf) != AC_JACK_PORT_FIXED) {
3011 pincap = snd_hda_param_read(codec, nid,
3012 AC_PAR_PIN_CAP);
3013 if (pincap & AC_PINCAP_OUT) {
3014 err = stac92xx_add_control(spec,
3015 STAC_CTL_WIDGET_IO_SWITCH,
3016 "Mic as Output Switch", (nid << 8) | 1);
3017 nid = snd_hda_codec_read(codec, nid, 0,
3018 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
3019 if (!check_in_dac_nids(spec, nid))
3020 add_spec_dacs(spec, nid);
3021 if (err < 0)
3022 return err;
3023 }
3024 } else if (mic_pin == AUTO_PIN_MIC) {
3025 mic_pin = AUTO_PIN_FRONT_MIC;
3026 goto again;
3027 }
3028 }
3029
3030 return 0;
3031}
3032
3033/* add playback controls for Speaker and HP outputs */
3034static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
3035 struct auto_pin_cfg *cfg)
3036{
3037 struct sigmatel_spec *spec = codec->spec;
3038 hda_nid_t nid;
3039 int i, old_num_dacs, err;
3040
3041 old_num_dacs = spec->multiout.num_dacs;
3042 for (i = 0; i < cfg->hp_outs; i++) {
3043 unsigned int wid_caps = get_wcaps(codec, cfg->hp_pins[i]);
3044 if (wid_caps & AC_WCAP_UNSOL_CAP)
3045 spec->hp_detect = 1;
3046 nid = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
3047 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
3048 if (check_in_dac_nids(spec, nid))
3049 nid = 0;
3050 if (! nid)
3051 continue;
3052 add_spec_dacs(spec, nid);
3053 }
3054 for (i = 0; i < cfg->speaker_outs; i++) {
3055 nid = snd_hda_codec_read(codec, cfg->speaker_pins[i], 0,
3056 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
3057 if (check_in_dac_nids(spec, nid))
3058 nid = 0;
3059 if (! nid)
3060 continue;
3061 add_spec_dacs(spec, nid);
3062 }
3063 for (i = 0; i < cfg->line_outs; i++) {
3064 nid = snd_hda_codec_read(codec, cfg->line_out_pins[i], 0,
3065 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
3066 if (check_in_dac_nids(spec, nid))
3067 nid = 0;
3068 if (! nid)
3069 continue;
3070 add_spec_dacs(spec, nid);
3071 }
3072 for (i = old_num_dacs; i < spec->multiout.num_dacs; i++) {
3073 static const char *pfxs[] = {
3074 "Speaker", "External Speaker", "Speaker2",
3075 };
3076 err = create_controls(spec, pfxs[i - old_num_dacs],
3077 spec->multiout.dac_nids[i], 3);
3078 if (err < 0)
3079 return err;
3080 }
3081 if (spec->multiout.hp_nid) {
3082 err = create_controls(spec, "Headphone",
3083 spec->multiout.hp_nid, 3);
3084 if (err < 0)
3085 return err;
3086 }
3087
3088 return 0;
3089}
3090
3091/* labels for mono mux outputs */
3092static const char *stac92xx_mono_labels[4] = {
3093 "DAC0", "DAC1", "Mixer", "DAC2"
3094};
3095
3096/* create mono mux for mono out on capable codecs */
3097static int stac92xx_auto_create_mono_output_ctls(struct hda_codec *codec)
3098{
3099 struct sigmatel_spec *spec = codec->spec;
3100 struct hda_input_mux *mono_mux = &spec->private_mono_mux;
3101 int i, num_cons;
3102 hda_nid_t con_lst[ARRAY_SIZE(stac92xx_mono_labels)];
3103
3104 num_cons = snd_hda_get_connections(codec,
3105 spec->mono_nid,
3106 con_lst,
3107 HDA_MAX_NUM_INPUTS);
3108 if (!num_cons || num_cons > ARRAY_SIZE(stac92xx_mono_labels))
3109 return -EINVAL;
3110
3111 for (i = 0; i < num_cons; i++) {
3112 mono_mux->items[mono_mux->num_items].label =
3113 stac92xx_mono_labels[i];
3114 mono_mux->items[mono_mux->num_items].index = i;
3115 mono_mux->num_items++;
3116 }
3117
3118 return stac92xx_add_control(spec, STAC_CTL_WIDGET_MONO_MUX,
3119 "Mono Mux", spec->mono_nid);
3120}
3121
3122/* labels for amp mux outputs */
3123static const char *stac92xx_amp_labels[3] = {
3124 "Front Microphone", "Microphone", "Line In",
3125};
3126
3127/* create amp out controls mux on capable codecs */
3128static int stac92xx_auto_create_amp_output_ctls(struct hda_codec *codec)
3129{
3130 struct sigmatel_spec *spec = codec->spec;
3131 struct hda_input_mux *amp_mux = &spec->private_amp_mux;
3132 int i, err;
3133
3134 for (i = 0; i < spec->num_amps; i++) {
3135 amp_mux->items[amp_mux->num_items].label =
3136 stac92xx_amp_labels[i];
3137 amp_mux->items[amp_mux->num_items].index = i;
3138 amp_mux->num_items++;
3139 }
3140
3141 if (spec->num_amps > 1) {
3142 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_AMP_MUX,
3143 "Amp Selector Capture Switch", 0);
3144 if (err < 0)
3145 return err;
3146 }
3147 return stac92xx_add_control(spec, STAC_CTL_WIDGET_AMP_VOL,
3148 "Amp Capture Volume",
3149 HDA_COMPOSE_AMP_VAL(spec->amp_nids[0], 3, 0, HDA_INPUT));
3150}
3151
3152
3153/* create PC beep volume controls */
3154static int stac92xx_auto_create_beep_ctls(struct hda_codec *codec,
3155 hda_nid_t nid)
3156{
3157 struct sigmatel_spec *spec = codec->spec;
3158 u32 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3159 int err;
3160
3161 /* check for mute support for the the amp */
3162 if ((caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT) {
3163 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE,
3164 "PC Beep Playback Switch",
3165 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3166 if (err < 0)
3167 return err;
3168 }
3169
3170 /* check to see if there is volume support for the amp */
3171 if ((caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3172 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL,
3173 "PC Beep Playback Volume",
3174 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3175 if (err < 0)
3176 return err;
3177 }
3178 return 0;
3179}
3180
3181#ifdef CONFIG_SND_HDA_INPUT_BEEP
3182#define stac92xx_dig_beep_switch_info snd_ctl_boolean_mono_info
3183
3184static int stac92xx_dig_beep_switch_get(struct snd_kcontrol *kcontrol,
3185 struct snd_ctl_elem_value *ucontrol)
3186{
3187 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3188 ucontrol->value.integer.value[0] = codec->beep->enabled;
3189 return 0;
3190}
3191
3192static int stac92xx_dig_beep_switch_put(struct snd_kcontrol *kcontrol,
3193 struct snd_ctl_elem_value *ucontrol)
3194{
3195 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3196 int enabled = !!ucontrol->value.integer.value[0];
3197 if (codec->beep->enabled != enabled) {
3198 codec->beep->enabled = enabled;
3199 return 1;
3200 }
3201 return 0;
3202}
3203
3204static struct snd_kcontrol_new stac92xx_dig_beep_ctrl = {
3205 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3206 .info = stac92xx_dig_beep_switch_info,
3207 .get = stac92xx_dig_beep_switch_get,
3208 .put = stac92xx_dig_beep_switch_put,
3209};
3210
3211static int stac92xx_beep_switch_ctl(struct hda_codec *codec)
3212{
3213 return stac92xx_add_control_temp(codec->spec, &stac92xx_dig_beep_ctrl,
3214 0, "PC Beep Playback Switch", 0);
3215}
3216#endif
3217
3218static int stac92xx_auto_create_mux_input_ctls(struct hda_codec *codec)
3219{
3220 struct sigmatel_spec *spec = codec->spec;
3221 int wcaps, nid, i, err = 0;
3222
3223 for (i = 0; i < spec->num_muxes; i++) {
3224 nid = spec->mux_nids[i];
3225 wcaps = get_wcaps(codec, nid);
3226
3227 if (wcaps & AC_WCAP_OUT_AMP) {
3228 err = stac92xx_add_control_idx(spec,
3229 STAC_CTL_WIDGET_VOL, i, "Mux Capture Volume",
3230 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
3231 if (err < 0)
3232 return err;
3233 }
3234 }
3235 return 0;
3236};
3237
3238static const char *stac92xx_spdif_labels[3] = {
3239 "Digital Playback", "Analog Mux 1", "Analog Mux 2",
3240};
3241
3242static int stac92xx_auto_create_spdif_mux_ctls(struct hda_codec *codec)
3243{
3244 struct sigmatel_spec *spec = codec->spec;
3245 struct hda_input_mux *spdif_mux = &spec->private_smux;
3246 const char **labels = spec->spdif_labels;
3247 int i, num_cons;
3248 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
3249
3250 num_cons = snd_hda_get_connections(codec,
3251 spec->smux_nids[0],
3252 con_lst,
3253 HDA_MAX_NUM_INPUTS);
3254 if (!num_cons)
3255 return -EINVAL;
3256
3257 if (!labels)
3258 labels = stac92xx_spdif_labels;
3259
3260 for (i = 0; i < num_cons; i++) {
3261 spdif_mux->items[spdif_mux->num_items].label = labels[i];
3262 spdif_mux->items[spdif_mux->num_items].index = i;
3263 spdif_mux->num_items++;
3264 }
3265
3266 return 0;
3267}
3268
3269/* labels for dmic mux inputs */
3270static const char *stac92xx_dmic_labels[5] = {
3271 "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
3272 "Digital Mic 3", "Digital Mic 4"
3273};
3274
3275/* create playback/capture controls for input pins on dmic capable codecs */
3276static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
3277 const struct auto_pin_cfg *cfg)
3278{
3279 struct sigmatel_spec *spec = codec->spec;
3280 struct hda_input_mux *dimux = &spec->private_dimux;
3281 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
3282 int err, i, j;
3283 char name[32];
3284
3285 dimux->items[dimux->num_items].label = stac92xx_dmic_labels[0];
3286 dimux->items[dimux->num_items].index = 0;
3287 dimux->num_items++;
3288
3289 for (i = 0; i < spec->num_dmics; i++) {
3290 hda_nid_t nid;
3291 int index;
3292 int num_cons;
3293 unsigned int wcaps;
3294 unsigned int def_conf;
3295
3296 def_conf = snd_hda_codec_read(codec,
3297 spec->dmic_nids[i],
3298 0,
3299 AC_VERB_GET_CONFIG_DEFAULT,
3300 0);
3301 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
3302 continue;
3303
3304 nid = spec->dmic_nids[i];
3305 num_cons = snd_hda_get_connections(codec,
3306 spec->dmux_nids[0],
3307 con_lst,
3308 HDA_MAX_NUM_INPUTS);
3309 for (j = 0; j < num_cons; j++)
3310 if (con_lst[j] == nid) {
3311 index = j;
3312 goto found;
3313 }
3314 continue;
3315found:
3316 wcaps = get_wcaps(codec, nid) &
3317 (AC_WCAP_OUT_AMP | AC_WCAP_IN_AMP);
3318
3319 if (wcaps) {
3320 sprintf(name, "%s Capture Volume",
3321 stac92xx_dmic_labels[dimux->num_items]);
3322
3323 err = stac92xx_add_control(spec,
3324 STAC_CTL_WIDGET_VOL,
3325 name,
3326 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3327 (wcaps & AC_WCAP_OUT_AMP) ?
3328 HDA_OUTPUT : HDA_INPUT));
3329 if (err < 0)
3330 return err;
3331 }
3332
3333 dimux->items[dimux->num_items].label =
3334 stac92xx_dmic_labels[dimux->num_items];
3335 dimux->items[dimux->num_items].index = index;
3336 dimux->num_items++;
3337 }
3338
3339 return 0;
3340}
3341
3342/* create playback/capture controls for input pins */
3343static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
3344{
3345 struct sigmatel_spec *spec = codec->spec;
3346 struct hda_input_mux *imux = &spec->private_imux;
3347 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
3348 int i, j, k;
3349
3350 for (i = 0; i < AUTO_PIN_LAST; i++) {
3351 int index;
3352
3353 if (!cfg->input_pins[i])
3354 continue;
3355 index = -1;
3356 for (j = 0; j < spec->num_muxes; j++) {
3357 int num_cons;
3358 num_cons = snd_hda_get_connections(codec,
3359 spec->mux_nids[j],
3360 con_lst,
3361 HDA_MAX_NUM_INPUTS);
3362 for (k = 0; k < num_cons; k++)
3363 if (con_lst[k] == cfg->input_pins[i]) {
3364 index = k;
3365 goto found;
3366 }
3367 }
3368 continue;
3369 found:
3370 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
3371 imux->items[imux->num_items].index = index;
3372 imux->num_items++;
3373 }
3374
3375 if (imux->num_items) {
3376 /*
3377 * Set the current input for the muxes.
3378 * The STAC9221 has two input muxes with identical source
3379 * NID lists. Hopefully this won't get confused.
3380 */
3381 for (i = 0; i < spec->num_muxes; i++) {
3382 snd_hda_codec_write_cache(codec, spec->mux_nids[i], 0,
3383 AC_VERB_SET_CONNECT_SEL,
3384 imux->items[0].index);
3385 }
3386 }
3387
3388 return 0;
3389}
3390
3391static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
3392{
3393 struct sigmatel_spec *spec = codec->spec;
3394 int i;
3395
3396 for (i = 0; i < spec->autocfg.line_outs; i++) {
3397 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3398 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
3399 }
3400}
3401
3402static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
3403{
3404 struct sigmatel_spec *spec = codec->spec;
3405 int i;
3406
3407 for (i = 0; i < spec->autocfg.hp_outs; i++) {
3408 hda_nid_t pin;
3409 pin = spec->autocfg.hp_pins[i];
3410 if (pin) /* connect to front */
3411 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
3412 }
3413 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
3414 hda_nid_t pin;
3415 pin = spec->autocfg.speaker_pins[i];
3416 if (pin) /* connect to front */
3417 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
3418 }
3419}
3420
3421static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out, hda_nid_t dig_in)
3422{
3423 struct sigmatel_spec *spec = codec->spec;
3424 int err;
3425 int hp_speaker_swap = 0;
3426
3427 if ((err = snd_hda_parse_pin_def_config(codec,
3428 &spec->autocfg,
3429 spec->dmic_nids)) < 0)
3430 return err;
3431 if (! spec->autocfg.line_outs)
3432 return 0; /* can't find valid pin config */
3433
3434 /* If we have no real line-out pin and multiple hp-outs, HPs should
3435 * be set up as multi-channel outputs.
3436 */
3437 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT &&
3438 spec->autocfg.hp_outs > 1) {
3439 /* Copy hp_outs to line_outs, backup line_outs in
3440 * speaker_outs so that the following routines can handle
3441 * HP pins as primary outputs.
3442 */
3443 memcpy(spec->autocfg.speaker_pins, spec->autocfg.line_out_pins,
3444 sizeof(spec->autocfg.line_out_pins));
3445 spec->autocfg.speaker_outs = spec->autocfg.line_outs;
3446 memcpy(spec->autocfg.line_out_pins, spec->autocfg.hp_pins,
3447 sizeof(spec->autocfg.hp_pins));
3448 spec->autocfg.line_outs = spec->autocfg.hp_outs;
3449 hp_speaker_swap = 1;
3450 }
3451 if (spec->autocfg.mono_out_pin) {
3452 int dir = get_wcaps(codec, spec->autocfg.mono_out_pin) &
3453 (AC_WCAP_OUT_AMP | AC_WCAP_IN_AMP);
3454 u32 caps = query_amp_caps(codec,
3455 spec->autocfg.mono_out_pin, dir);
3456 hda_nid_t conn_list[1];
3457
3458 /* get the mixer node and then the mono mux if it exists */
3459 if (snd_hda_get_connections(codec,
3460 spec->autocfg.mono_out_pin, conn_list, 1) &&
3461 snd_hda_get_connections(codec, conn_list[0],
3462 conn_list, 1)) {
3463
3464 int wcaps = get_wcaps(codec, conn_list[0]);
3465 int wid_type = (wcaps & AC_WCAP_TYPE)
3466 >> AC_WCAP_TYPE_SHIFT;
3467 /* LR swap check, some stac925x have a mux that
3468 * changes the DACs output path instead of the
3469 * mono-mux path.
3470 */
3471 if (wid_type == AC_WID_AUD_SEL &&
3472 !(wcaps & AC_WCAP_LR_SWAP))
3473 spec->mono_nid = conn_list[0];
3474 }
3475 if (dir) {
3476 hda_nid_t nid = spec->autocfg.mono_out_pin;
3477
3478 /* most mono outs have a least a mute/unmute switch */
3479 dir = (dir & AC_WCAP_OUT_AMP) ? HDA_OUTPUT : HDA_INPUT;
3480 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE,
3481 "Mono Playback Switch",
3482 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
3483 if (err < 0)
3484 return err;
3485 /* check for volume support for the amp */
3486 if ((caps & AC_AMPCAP_NUM_STEPS)
3487 >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3488 err = stac92xx_add_control(spec,
3489 STAC_CTL_WIDGET_VOL,
3490 "Mono Playback Volume",
3491 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
3492 if (err < 0)
3493 return err;
3494 }
3495 }
3496
3497 stac92xx_auto_set_pinctl(codec, spec->autocfg.mono_out_pin,
3498 AC_PINCTL_OUT_EN);
3499 }
3500
3501 if ((err = stac92xx_add_dyn_out_pins(codec, &spec->autocfg)) < 0)
3502 return err;
3503 if (spec->multiout.num_dacs == 0)
3504 if ((err = stac92xx_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
3505 return err;
3506
3507 err = stac92xx_auto_create_multi_out_ctls(codec, &spec->autocfg);
3508
3509 if (err < 0)
3510 return err;
3511
3512 /* setup analog beep controls */
3513 if (spec->anabeep_nid > 0) {
3514 err = stac92xx_auto_create_beep_ctls(codec,
3515 spec->anabeep_nid);
3516 if (err < 0)
3517 return err;
3518 }
3519
3520 /* setup digital beep controls and input device */
3521#ifdef CONFIG_SND_HDA_INPUT_BEEP
3522 if (spec->digbeep_nid > 0) {
3523 hda_nid_t nid = spec->digbeep_nid;
3524 unsigned int caps;
3525
3526 err = stac92xx_auto_create_beep_ctls(codec, nid);
3527 if (err < 0)
3528 return err;
3529 err = snd_hda_attach_beep_device(codec, nid);
3530 if (err < 0)
3531 return err;
3532 /* if no beep switch is available, make its own one */
3533 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3534 if (codec->beep &&
3535 !((caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT)) {
3536 err = stac92xx_beep_switch_ctl(codec);
3537 if (err < 0)
3538 return err;
3539 }
3540 }
3541#endif
3542
3543 if (hp_speaker_swap == 1) {
3544 /* Restore the hp_outs and line_outs */
3545 memcpy(spec->autocfg.hp_pins, spec->autocfg.line_out_pins,
3546 sizeof(spec->autocfg.line_out_pins));
3547 spec->autocfg.hp_outs = spec->autocfg.line_outs;
3548 memcpy(spec->autocfg.line_out_pins, spec->autocfg.speaker_pins,
3549 sizeof(spec->autocfg.speaker_pins));
3550 spec->autocfg.line_outs = spec->autocfg.speaker_outs;
3551 memset(spec->autocfg.speaker_pins, 0,
3552 sizeof(spec->autocfg.speaker_pins));
3553 spec->autocfg.speaker_outs = 0;
3554 }
3555
3556 err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg);
3557
3558 if (err < 0)
3559 return err;
3560
3561 err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg);
3562
3563 if (err < 0)
3564 return err;
3565
3566 if (spec->mono_nid > 0) {
3567 err = stac92xx_auto_create_mono_output_ctls(codec);
3568 if (err < 0)
3569 return err;
3570 }
3571 if (spec->num_amps > 0) {
3572 err = stac92xx_auto_create_amp_output_ctls(codec);
3573 if (err < 0)
3574 return err;
3575 }
3576 if (spec->num_dmics > 0 && !spec->dinput_mux)
3577 if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
3578 &spec->autocfg)) < 0)
3579 return err;
3580 if (spec->num_muxes > 0) {
3581 err = stac92xx_auto_create_mux_input_ctls(codec);
3582 if (err < 0)
3583 return err;
3584 }
3585 if (spec->num_smuxes > 0) {
3586 err = stac92xx_auto_create_spdif_mux_ctls(codec);
3587 if (err < 0)
3588 return err;
3589 }
3590
3591 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3592 if (spec->multiout.max_channels > 2)
3593 spec->surr_switch = 1;
3594
3595 if (spec->autocfg.dig_out_pin)
3596 spec->multiout.dig_out_nid = dig_out;
3597 if (dig_in && spec->autocfg.dig_in_pin)
3598 spec->dig_in_nid = dig_in;
3599
3600 if (spec->kctls.list)
3601 spec->mixers[spec->num_mixers++] = spec->kctls.list;
3602
3603 spec->input_mux = &spec->private_imux;
3604 spec->dinput_mux = &spec->private_dimux;
3605 spec->sinput_mux = &spec->private_smux;
3606 spec->mono_mux = &spec->private_mono_mux;
3607 spec->amp_mux = &spec->private_amp_mux;
3608 return 1;
3609}
3610
3611/* add playback controls for HP output */
3612static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
3613 struct auto_pin_cfg *cfg)
3614{
3615 struct sigmatel_spec *spec = codec->spec;
3616 hda_nid_t pin = cfg->hp_pins[0];
3617 unsigned int wid_caps;
3618
3619 if (! pin)
3620 return 0;
3621
3622 wid_caps = get_wcaps(codec, pin);
3623 if (wid_caps & AC_WCAP_UNSOL_CAP)
3624 spec->hp_detect = 1;
3625
3626 return 0;
3627}
3628
3629/* add playback controls for LFE output */
3630static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
3631 struct auto_pin_cfg *cfg)
3632{
3633 struct sigmatel_spec *spec = codec->spec;
3634 int err;
3635 hda_nid_t lfe_pin = 0x0;
3636 int i;
3637
3638 /*
3639 * search speaker outs and line outs for a mono speaker pin
3640 * with an amp. If one is found, add LFE controls
3641 * for it.
3642 */
3643 for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
3644 hda_nid_t pin = spec->autocfg.speaker_pins[i];
3645 unsigned int wcaps = get_wcaps(codec, pin);
3646 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
3647 if (wcaps == AC_WCAP_OUT_AMP)
3648 /* found a mono speaker with an amp, must be lfe */
3649 lfe_pin = pin;
3650 }
3651
3652 /* if speaker_outs is 0, then speakers may be in line_outs */
3653 if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
3654 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
3655 hda_nid_t pin = spec->autocfg.line_out_pins[i];
3656 unsigned int defcfg;
3657 defcfg = snd_hda_codec_read(codec, pin, 0,
3658 AC_VERB_GET_CONFIG_DEFAULT,
3659 0x00);
3660 if (get_defcfg_device(defcfg) == AC_JACK_SPEAKER) {
3661 unsigned int wcaps = get_wcaps(codec, pin);
3662 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
3663 if (wcaps == AC_WCAP_OUT_AMP)
3664 /* found a mono speaker with an amp,
3665 must be lfe */
3666 lfe_pin = pin;
3667 }
3668 }
3669 }
3670
3671 if (lfe_pin) {
3672 err = create_controls(spec, "LFE", lfe_pin, 1);
3673 if (err < 0)
3674 return err;
3675 }
3676
3677 return 0;
3678}
3679
3680static int stac9200_parse_auto_config(struct hda_codec *codec)
3681{
3682 struct sigmatel_spec *spec = codec->spec;
3683 int err;
3684
3685 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
3686 return err;
3687
3688 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
3689 return err;
3690
3691 if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
3692 return err;
3693
3694 if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
3695 return err;
3696
3697 if (spec->num_muxes > 0) {
3698 err = stac92xx_auto_create_mux_input_ctls(codec);
3699 if (err < 0)
3700 return err;
3701 }
3702
3703 if (spec->autocfg.dig_out_pin)
3704 spec->multiout.dig_out_nid = 0x05;
3705 if (spec->autocfg.dig_in_pin)
3706 spec->dig_in_nid = 0x04;
3707
3708 if (spec->kctls.list)
3709 spec->mixers[spec->num_mixers++] = spec->kctls.list;
3710
3711 spec->input_mux = &spec->private_imux;
3712 spec->dinput_mux = &spec->private_dimux;
3713
3714 return 1;
3715}
3716
3717/*
3718 * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
3719 * funky external mute control using GPIO pins.
3720 */
3721
3722static void stac_gpio_set(struct hda_codec *codec, unsigned int mask,
3723 unsigned int dir_mask, unsigned int data)
3724{
3725 unsigned int gpiostate, gpiomask, gpiodir;
3726
3727 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
3728 AC_VERB_GET_GPIO_DATA, 0);
3729 gpiostate = (gpiostate & ~dir_mask) | (data & dir_mask);
3730
3731 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
3732 AC_VERB_GET_GPIO_MASK, 0);
3733 gpiomask |= mask;
3734
3735 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
3736 AC_VERB_GET_GPIO_DIRECTION, 0);
3737 gpiodir |= dir_mask;
3738
3739 /* Configure GPIOx as CMOS */
3740 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
3741
3742 snd_hda_codec_write(codec, codec->afg, 0,
3743 AC_VERB_SET_GPIO_MASK, gpiomask);
3744 snd_hda_codec_read(codec, codec->afg, 0,
3745 AC_VERB_SET_GPIO_DIRECTION, gpiodir); /* sync */
3746
3747 msleep(1);
3748
3749 snd_hda_codec_read(codec, codec->afg, 0,
3750 AC_VERB_SET_GPIO_DATA, gpiostate); /* sync */
3751}
3752
3753static int stac92xx_add_jack(struct hda_codec *codec,
3754 hda_nid_t nid, int type)
3755{
3756#ifdef CONFIG_SND_JACK
3757 struct sigmatel_spec *spec = codec->spec;
3758 struct sigmatel_jack *jack;
3759 int def_conf = snd_hda_codec_read(codec, nid,
3760 0, AC_VERB_GET_CONFIG_DEFAULT, 0);
3761 int connectivity = get_defcfg_connect(def_conf);
3762 char name[32];
3763
3764 if (connectivity && connectivity != AC_JACK_PORT_FIXED)
3765 return 0;
3766
3767 snd_array_init(&spec->jacks, sizeof(*jack), 32);
3768 jack = snd_array_new(&spec->jacks);
3769 if (!jack)
3770 return -ENOMEM;
3771 jack->nid = nid;
3772 jack->type = type;
3773
3774 sprintf(name, "%s at %s %s Jack",
3775 snd_hda_get_jack_type(def_conf),
3776 snd_hda_get_jack_connectivity(def_conf),
3777 snd_hda_get_jack_location(def_conf));
3778
3779 return snd_jack_new(codec->bus->card, name, type, &jack->jack);
3780#else
3781 return 0;
3782#endif
3783}
3784
3785static int stac_add_event(struct sigmatel_spec *spec, hda_nid_t nid,
3786 unsigned char type, int data)
3787{
3788 struct sigmatel_event *event;
3789
3790 snd_array_init(&spec->events, sizeof(*event), 32);
3791 event = snd_array_new(&spec->events);
3792 if (!event)
3793 return -ENOMEM;
3794 event->nid = nid;
3795 event->type = type;
3796 event->tag = spec->events.used;
3797 event->data = data;
3798
3799 return event->tag;
3800}
3801
3802static struct sigmatel_event *stac_get_event(struct hda_codec *codec,
3803 hda_nid_t nid, unsigned char type)
3804{
3805 struct sigmatel_spec *spec = codec->spec;
3806 struct sigmatel_event *event = spec->events.list;
3807 int i;
3808
3809 for (i = 0; i < spec->events.used; i++, event++) {
3810 if (event->nid == nid && event->type == type)
3811 return event;
3812 }
3813 return NULL;
3814}
3815
3816static struct sigmatel_event *stac_get_event_from_tag(struct hda_codec *codec,
3817 unsigned char tag)
3818{
3819 struct sigmatel_spec *spec = codec->spec;
3820 struct sigmatel_event *event = spec->events.list;
3821 int i;
3822
3823 for (i = 0; i < spec->events.used; i++, event++) {
3824 if (event->tag == tag)
3825 return event;
3826 }
3827 return NULL;
3828}
3829
3830static void enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
3831 unsigned int type)
3832{
3833 struct sigmatel_event *event;
3834 int tag;
3835
3836 if (!(get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP))
3837 return;
3838 event = stac_get_event(codec, nid, type);
3839 if (event)
3840 tag = event->tag;
3841 else
3842 tag = stac_add_event(codec->spec, nid, type, 0);
3843 if (tag < 0)
3844 return;
3845 snd_hda_codec_write_cache(codec, nid, 0,
3846 AC_VERB_SET_UNSOLICITED_ENABLE,
3847 AC_USRSP_EN | tag);
3848}
3849
3850static int is_nid_hp_pin(struct auto_pin_cfg *cfg, hda_nid_t nid)
3851{
3852 int i;
3853 for (i = 0; i < cfg->hp_outs; i++)
3854 if (cfg->hp_pins[i] == nid)
3855 return 1; /* nid is a HP-Out */
3856
3857 return 0; /* nid is not a HP-Out */
3858};
3859
3860static void stac92xx_power_down(struct hda_codec *codec)
3861{
3862 struct sigmatel_spec *spec = codec->spec;
3863
3864 /* power down inactive DACs */
3865 hda_nid_t *dac;
3866 for (dac = spec->dac_list; *dac; dac++)
3867 if (!is_in_dac_nids(spec, *dac) &&
3868 spec->multiout.hp_nid != *dac)
3869 snd_hda_codec_write_cache(codec, *dac, 0,
3870 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3871}
3872
3873static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
3874 int enable);
3875
3876static int stac92xx_init(struct hda_codec *codec)
3877{
3878 struct sigmatel_spec *spec = codec->spec;
3879 struct auto_pin_cfg *cfg = &spec->autocfg;
3880 unsigned int gpio;
3881 int i;
3882
3883 snd_hda_sequence_write(codec, spec->init);
3884
3885 /* power down adcs initially */
3886 if (spec->powerdown_adcs)
3887 for (i = 0; i < spec->num_adcs; i++)
3888 snd_hda_codec_write_cache(codec,
3889 spec->adc_nids[i], 0,
3890 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3891
3892 /* set up GPIO */
3893 gpio = spec->gpio_data;
3894 /* turn on EAPD statically when spec->eapd_switch isn't set.
3895 * otherwise, unsol event will turn it on/off dynamically
3896 */
3897 if (!spec->eapd_switch)
3898 gpio |= spec->eapd_mask;
3899 stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, gpio);
3900
3901 /* set up pins */
3902 if (spec->hp_detect) {
3903 /* Enable unsolicited responses on the HP widget */
3904 for (i = 0; i < cfg->hp_outs; i++) {
3905 hda_nid_t nid = cfg->hp_pins[i];
3906 enable_pin_detect(codec, nid, STAC_HP_EVENT);
3907 }
3908 /* force to enable the first line-out; the others are set up
3909 * in unsol_event
3910 */
3911 stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
3912 AC_PINCTL_OUT_EN);
3913 /* fake event to set up pins */
3914 stac_issue_unsol_event(codec, spec->autocfg.hp_pins[0],
3915 STAC_HP_EVENT);
3916 } else {
3917 stac92xx_auto_init_multi_out(codec);
3918 stac92xx_auto_init_hp_out(codec);
3919 }
3920 for (i = 0; i < AUTO_PIN_LAST; i++) {
3921 hda_nid_t nid = cfg->input_pins[i];
3922 if (nid) {
3923 unsigned int pinctl;
3924 if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC) {
3925 /* for mic pins, force to initialize */
3926 pinctl = stac92xx_get_vref(codec, nid);
3927 } else {
3928 pinctl = snd_hda_codec_read(codec, nid, 0,
3929 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3930 /* if PINCTL already set then skip */
3931 if (pinctl & AC_PINCTL_IN_EN)
3932 continue;
3933 }
3934 pinctl |= AC_PINCTL_IN_EN;
3935 stac92xx_auto_set_pinctl(codec, nid, pinctl);
3936 enable_pin_detect(codec, nid, STAC_INSERT_EVENT);
3937 }
3938 }
3939 for (i = 0; i < spec->num_dmics; i++)
3940 stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
3941 AC_PINCTL_IN_EN);
3942 if (cfg->dig_out_pin)
3943 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pin,
3944 AC_PINCTL_OUT_EN);
3945 if (cfg->dig_in_pin)
3946 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
3947 AC_PINCTL_IN_EN);
3948 for (i = 0; i < spec->num_pwrs; i++) {
3949 hda_nid_t nid = spec->pwr_nids[i];
3950 int pinctl, def_conf;
3951
3952 if (is_nid_hp_pin(cfg, nid) && spec->hp_detect)
3953 continue; /* already has an unsol event */
3954
3955 pinctl = snd_hda_codec_read(codec, nid, 0,
3956 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3957 /* outputs are only ports capable of power management
3958 * any attempts on powering down a input port cause the
3959 * referenced VREF to act quirky.
3960 */
3961 if (pinctl & AC_PINCTL_IN_EN)
3962 continue;
3963 def_conf = snd_hda_codec_read(codec, nid, 0,
3964 AC_VERB_GET_CONFIG_DEFAULT, 0);
3965 def_conf = get_defcfg_connect(def_conf);
3966 /* skip any ports that don't have jacks since presence
3967 * detection is useless */
3968 if (def_conf != AC_JACK_PORT_COMPLEX) {
3969 if (def_conf != AC_JACK_PORT_NONE)
3970 stac_toggle_power_map(codec, nid, 1);
3971 continue;
3972 }
3973 enable_pin_detect(codec, nid, STAC_PWR_EVENT);
3974 stac_issue_unsol_event(codec, nid, STAC_PWR_EVENT);
3975 }
3976 if (spec->dac_list)
3977 stac92xx_power_down(codec);
3978 return 0;
3979}
3980
3981static void stac92xx_free_jacks(struct hda_codec *codec)
3982{
3983#ifdef CONFIG_SND_JACK
3984 /* free jack instances manually when clearing/reconfiguring */
3985 struct sigmatel_spec *spec = codec->spec;
3986 if (!codec->bus->shutdown && spec->jacks.list) {
3987 struct sigmatel_jack *jacks = spec->jacks.list;
3988 int i;
3989 for (i = 0; i < spec->jacks.used; i++)
3990 snd_device_free(codec->bus->card, &jacks[i].jack);
3991 }
3992 snd_array_free(&spec->jacks);
3993#endif
3994}
3995
3996static void stac92xx_free_kctls(struct hda_codec *codec)
3997{
3998 struct sigmatel_spec *spec = codec->spec;
3999
4000 if (spec->kctls.list) {
4001 struct snd_kcontrol_new *kctl = spec->kctls.list;
4002 int i;
4003 for (i = 0; i < spec->kctls.used; i++)
4004 kfree(kctl[i].name);
4005 }
4006 snd_array_free(&spec->kctls);
4007}
4008
4009static void stac92xx_free(struct hda_codec *codec)
4010{
4011 struct sigmatel_spec *spec = codec->spec;
4012
4013 if (! spec)
4014 return;
4015
4016 kfree(spec->pin_configs);
4017 stac92xx_free_jacks(codec);
4018 snd_array_free(&spec->events);
4019
4020 kfree(spec);
4021 snd_hda_detach_beep_device(codec);
4022}
4023
4024static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
4025 unsigned int flag)
4026{
4027 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
4028 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
4029
4030 if (pin_ctl & AC_PINCTL_IN_EN) {
4031 /*
4032 * we need to check the current set-up direction of
4033 * shared input pins since they can be switched via
4034 * "xxx as Output" mixer switch
4035 */
4036 struct sigmatel_spec *spec = codec->spec;
4037 struct auto_pin_cfg *cfg = &spec->autocfg;
4038 if ((nid == cfg->input_pins[AUTO_PIN_LINE] &&
4039 spec->line_switch) ||
4040 (nid == cfg->input_pins[AUTO_PIN_MIC] &&
4041 spec->mic_switch))
4042 return;
4043 }
4044
4045 /* if setting pin direction bits, clear the current
4046 direction bits first */
4047 if (flag & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))
4048 pin_ctl &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
4049
4050 snd_hda_codec_write_cache(codec, nid, 0,
4051 AC_VERB_SET_PIN_WIDGET_CONTROL,
4052 pin_ctl | flag);
4053}
4054
4055static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
4056 unsigned int flag)
4057{
4058 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
4059 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
4060 snd_hda_codec_write_cache(codec, nid, 0,
4061 AC_VERB_SET_PIN_WIDGET_CONTROL,
4062 pin_ctl & ~flag);
4063}
4064
4065static int get_hp_pin_presence(struct hda_codec *codec, hda_nid_t nid)
4066{
4067 if (!nid)
4068 return 0;
4069 if (snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PIN_SENSE, 0x00)
4070 & (1 << 31)) {
4071 unsigned int pinctl;
4072 pinctl = snd_hda_codec_read(codec, nid, 0,
4073 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4074 if (pinctl & AC_PINCTL_IN_EN)
4075 return 0; /* mic- or line-input */
4076 else
4077 return 1; /* HP-output */
4078 }
4079 return 0;
4080}
4081
4082/* return non-zero if the hp-pin of the given array index isn't
4083 * a jack-detection target
4084 */
4085static int no_hp_sensing(struct sigmatel_spec *spec, int i)
4086{
4087 struct auto_pin_cfg *cfg = &spec->autocfg;
4088
4089 /* ignore sensing of shared line and mic jacks */
4090 if (spec->line_switch &&
4091 cfg->hp_pins[i] == cfg->input_pins[AUTO_PIN_LINE])
4092 return 1;
4093 if (spec->mic_switch &&
4094 cfg->hp_pins[i] == cfg->input_pins[AUTO_PIN_MIC])
4095 return 1;
4096 /* ignore if the pin is set as line-out */
4097 if (cfg->hp_pins[i] == spec->hp_switch)
4098 return 1;
4099 return 0;
4100}
4101
4102static void stac92xx_hp_detect(struct hda_codec *codec)
4103{
4104 struct sigmatel_spec *spec = codec->spec;
4105 struct auto_pin_cfg *cfg = &spec->autocfg;
4106 int i, presence;
4107
4108 presence = 0;
4109 if (spec->gpio_mute)
4110 presence = !(snd_hda_codec_read(codec, codec->afg, 0,
4111 AC_VERB_GET_GPIO_DATA, 0) & spec->gpio_mute);
4112
4113 for (i = 0; i < cfg->hp_outs; i++) {
4114 if (presence)
4115 break;
4116 if (no_hp_sensing(spec, i))
4117 continue;
4118 presence = get_hp_pin_presence(codec, cfg->hp_pins[i]);
4119 }
4120
4121 if (presence) {
4122 /* disable lineouts */
4123 if (spec->hp_switch)
4124 stac92xx_reset_pinctl(codec, spec->hp_switch,
4125 AC_PINCTL_OUT_EN);
4126 for (i = 0; i < cfg->line_outs; i++)
4127 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
4128 AC_PINCTL_OUT_EN);
4129 for (i = 0; i < cfg->speaker_outs; i++)
4130 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
4131 AC_PINCTL_OUT_EN);
4132 if (spec->eapd_mask && spec->eapd_switch)
4133 stac_gpio_set(codec, spec->gpio_mask,
4134 spec->gpio_dir, spec->gpio_data &
4135 ~spec->eapd_mask);
4136 } else {
4137 /* enable lineouts */
4138 if (spec->hp_switch)
4139 stac92xx_set_pinctl(codec, spec->hp_switch,
4140 AC_PINCTL_OUT_EN);
4141 for (i = 0; i < cfg->line_outs; i++)
4142 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
4143 AC_PINCTL_OUT_EN);
4144 for (i = 0; i < cfg->speaker_outs; i++)
4145 stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
4146 AC_PINCTL_OUT_EN);
4147 if (spec->eapd_mask && spec->eapd_switch)
4148 stac_gpio_set(codec, spec->gpio_mask,
4149 spec->gpio_dir, spec->gpio_data |
4150 spec->eapd_mask);
4151 }
4152 /* toggle hp outs */
4153 for (i = 0; i < cfg->hp_outs; i++) {
4154 unsigned int val = AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN;
4155 if (no_hp_sensing(spec, i))
4156 continue;
4157 if (presence)
4158 stac92xx_set_pinctl(codec, cfg->hp_pins[i], val);
4159 else
4160 stac92xx_reset_pinctl(codec, cfg->hp_pins[i], val);
4161 }
4162}
4163
4164static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
4165 int enable)
4166{
4167 struct sigmatel_spec *spec = codec->spec;
4168 unsigned int idx, val;
4169
4170 for (idx = 0; idx < spec->num_pwrs; idx++) {
4171 if (spec->pwr_nids[idx] == nid)
4172 break;
4173 }
4174 if (idx >= spec->num_pwrs)
4175 return;
4176
4177 /* several codecs have two power down bits */
4178 if (spec->pwr_mapping)
4179 idx = spec->pwr_mapping[idx];
4180 else
4181 idx = 1 << idx;
4182
4183 val = snd_hda_codec_read(codec, codec->afg, 0, 0x0fec, 0x0) & 0xff;
4184 if (enable)
4185 val &= ~idx;
4186 else
4187 val |= idx;
4188
4189 /* power down unused output ports */
4190 snd_hda_codec_write(codec, codec->afg, 0, 0x7ec, val);
4191}
4192
4193static void stac92xx_pin_sense(struct hda_codec *codec, hda_nid_t nid)
4194{
4195 stac_toggle_power_map(codec, nid, get_hp_pin_presence(codec, nid));
4196}
4197
4198static void stac92xx_report_jack(struct hda_codec *codec, hda_nid_t nid)
4199{
4200 struct sigmatel_spec *spec = codec->spec;
4201 struct sigmatel_jack *jacks = spec->jacks.list;
4202
4203 if (jacks) {
4204 int i;
4205 for (i = 0; i < spec->jacks.used; i++) {
4206 if (jacks->nid == nid) {
4207 unsigned int pin_ctl =
4208 snd_hda_codec_read(codec, nid,
4209 0, AC_VERB_GET_PIN_WIDGET_CONTROL,
4210 0x00);
4211 int type = jacks->type;
4212 if (type == (SND_JACK_LINEOUT
4213 | SND_JACK_HEADPHONE))
4214 type = (pin_ctl & AC_PINCTL_HP_EN)
4215 ? SND_JACK_HEADPHONE : SND_JACK_LINEOUT;
4216 snd_jack_report(jacks->jack,
4217 get_hp_pin_presence(codec, nid)
4218 ? type : 0);
4219 }
4220 jacks++;
4221 }
4222 }
4223}
4224
4225static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid,
4226 unsigned char type)
4227{
4228 struct sigmatel_event *event = stac_get_event(codec, nid, type);
4229 if (!event)
4230 return;
4231 codec->patch_ops.unsol_event(codec, (unsigned)event->tag << 26);
4232}
4233
4234static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
4235{
4236 struct sigmatel_spec *spec = codec->spec;
4237 struct sigmatel_event *event;
4238 int tag, data;
4239
4240 tag = (res >> 26) & 0x7f;
4241 event = stac_get_event_from_tag(codec, tag);
4242 if (!event)
4243 return;
4244
4245 switch (event->type) {
4246 case STAC_HP_EVENT:
4247 stac92xx_hp_detect(codec);
4248 /* fallthru */
4249 case STAC_INSERT_EVENT:
4250 case STAC_PWR_EVENT:
4251 if (spec->num_pwrs > 0)
4252 stac92xx_pin_sense(codec, event->nid);
4253 stac92xx_report_jack(codec, event->nid);
4254 break;
4255 case STAC_VREF_EVENT:
4256 data = snd_hda_codec_read(codec, codec->afg, 0,
4257 AC_VERB_GET_GPIO_DATA, 0);
4258 /* toggle VREF state based on GPIOx status */
4259 snd_hda_codec_write(codec, codec->afg, 0, 0x7e0,
4260 !!(data & (1 << event->data)));
4261 break;
4262 }
4263}
4264
4265#ifdef SND_HDA_NEEDS_RESUME
4266static int stac92xx_resume(struct hda_codec *codec)
4267{
4268 struct sigmatel_spec *spec = codec->spec;
4269
4270 stac92xx_set_config_regs(codec);
4271 stac92xx_init(codec);
4272 snd_hda_codec_resume_amp(codec);
4273 snd_hda_codec_resume_cache(codec);
4274 /* fake event to set up pins again to override cached values */
4275 if (spec->hp_detect)
4276 stac_issue_unsol_event(codec, spec->autocfg.hp_pins[0],
4277 STAC_HP_EVENT);
4278 return 0;
4279}
4280
4281static int stac92xx_suspend(struct hda_codec *codec, pm_message_t state)
4282{
4283 struct sigmatel_spec *spec = codec->spec;
4284 if (spec->eapd_mask)
4285 stac_gpio_set(codec, spec->gpio_mask,
4286 spec->gpio_dir, spec->gpio_data &
4287 ~spec->eapd_mask);
4288 return 0;
4289}
4290#endif
4291
4292static struct hda_codec_ops stac92xx_patch_ops = {
4293 .build_controls = stac92xx_build_controls,
4294 .build_pcms = stac92xx_build_pcms,
4295 .init = stac92xx_init,
4296 .free = stac92xx_free,
4297 .unsol_event = stac92xx_unsol_event,
4298#ifdef SND_HDA_NEEDS_RESUME
4299 .suspend = stac92xx_suspend,
4300 .resume = stac92xx_resume,
4301#endif
4302};
4303
4304static int patch_stac9200(struct hda_codec *codec)
4305{
4306 struct sigmatel_spec *spec;
4307 int err;
4308
4309 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4310 if (spec == NULL)
4311 return -ENOMEM;
4312
4313 codec->spec = spec;
4314 spec->num_pins = ARRAY_SIZE(stac9200_pin_nids);
4315 spec->pin_nids = stac9200_pin_nids;
4316 spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS,
4317 stac9200_models,
4318 stac9200_cfg_tbl);
4319 if (spec->board_config < 0) {
4320 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9200, using BIOS defaults\n");
4321 err = stac92xx_save_bios_config_regs(codec);
4322 } else
4323 err = stac_save_pin_cfgs(codec,
4324 stac9200_brd_tbl[spec->board_config]);
4325 if (err < 0) {
4326 stac92xx_free(codec);
4327 return err;
4328 }
4329
4330 spec->multiout.max_channels = 2;
4331 spec->multiout.num_dacs = 1;
4332 spec->multiout.dac_nids = stac9200_dac_nids;
4333 spec->adc_nids = stac9200_adc_nids;
4334 spec->mux_nids = stac9200_mux_nids;
4335 spec->num_muxes = 1;
4336 spec->num_dmics = 0;
4337 spec->num_adcs = 1;
4338 spec->num_pwrs = 0;
4339
4340 if (spec->board_config == STAC_9200_GATEWAY ||
4341 spec->board_config == STAC_9200_OQO)
4342 spec->init = stac9200_eapd_init;
4343 else
4344 spec->init = stac9200_core_init;
4345 spec->mixer = stac9200_mixer;
4346
4347 if (spec->board_config == STAC_9200_PANASONIC) {
4348 spec->gpio_mask = spec->gpio_dir = 0x09;
4349 spec->gpio_data = 0x00;
4350 }
4351
4352 err = stac9200_parse_auto_config(codec);
4353 if (err < 0) {
4354 stac92xx_free(codec);
4355 return err;
4356 }
4357
4358 codec->patch_ops = stac92xx_patch_ops;
4359
4360 return 0;
4361}
4362
4363static int patch_stac925x(struct hda_codec *codec)
4364{
4365 struct sigmatel_spec *spec;
4366 int err;
4367
4368 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4369 if (spec == NULL)
4370 return -ENOMEM;
4371
4372 codec->spec = spec;
4373 spec->num_pins = ARRAY_SIZE(stac925x_pin_nids);
4374 spec->pin_nids = stac925x_pin_nids;
4375 spec->board_config = snd_hda_check_board_config(codec, STAC_925x_MODELS,
4376 stac925x_models,
4377 stac925x_cfg_tbl);
4378 again:
4379 if (spec->board_config < 0) {
4380 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC925x,"
4381 "using BIOS defaults\n");
4382 err = stac92xx_save_bios_config_regs(codec);
4383 } else
4384 err = stac_save_pin_cfgs(codec,
4385 stac925x_brd_tbl[spec->board_config]);
4386 if (err < 0) {
4387 stac92xx_free(codec);
4388 return err;
4389 }
4390
4391 spec->multiout.max_channels = 2;
4392 spec->multiout.num_dacs = 1;
4393 spec->multiout.dac_nids = stac925x_dac_nids;
4394 spec->adc_nids = stac925x_adc_nids;
4395 spec->mux_nids = stac925x_mux_nids;
4396 spec->num_muxes = 1;
4397 spec->num_adcs = 1;
4398 spec->num_pwrs = 0;
4399 switch (codec->vendor_id) {
4400 case 0x83847632: /* STAC9202 */
4401 case 0x83847633: /* STAC9202D */
4402 case 0x83847636: /* STAC9251 */
4403 case 0x83847637: /* STAC9251D */
4404 spec->num_dmics = STAC925X_NUM_DMICS;
4405 spec->dmic_nids = stac925x_dmic_nids;
4406 spec->num_dmuxes = ARRAY_SIZE(stac925x_dmux_nids);
4407 spec->dmux_nids = stac925x_dmux_nids;
4408 break;
4409 default:
4410 spec->num_dmics = 0;
4411 break;
4412 }
4413
4414 spec->init = stac925x_core_init;
4415 spec->mixer = stac925x_mixer;
4416
4417 err = stac92xx_parse_auto_config(codec, 0x8, 0x7);
4418 if (!err) {
4419 if (spec->board_config < 0) {
4420 printk(KERN_WARNING "hda_codec: No auto-config is "
4421 "available, default to model=ref\n");
4422 spec->board_config = STAC_925x_REF;
4423 goto again;
4424 }
4425 err = -EINVAL;
4426 }
4427 if (err < 0) {
4428 stac92xx_free(codec);
4429 return err;
4430 }
4431
4432 codec->patch_ops = stac92xx_patch_ops;
4433
4434 return 0;
4435}
4436
4437static struct hda_input_mux stac92hd73xx_dmux = {
4438 .num_items = 4,
4439 .items = {
4440 { "Analog Inputs", 0x0b },
4441 { "Digital Mic 1", 0x09 },
4442 { "Digital Mic 2", 0x0a },
4443 { "CD", 0x08 },
4444 }
4445};
4446
4447static int patch_stac92hd73xx(struct hda_codec *codec)
4448{
4449 struct sigmatel_spec *spec;
4450 hda_nid_t conn[STAC92HD73_DAC_COUNT + 2];
4451 int err = 0;
4452
4453 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4454 if (spec == NULL)
4455 return -ENOMEM;
4456
4457 codec->spec = spec;
4458 codec->slave_dig_outs = stac92hd73xx_slave_dig_outs;
4459 spec->num_pins = ARRAY_SIZE(stac92hd73xx_pin_nids);
4460 spec->pin_nids = stac92hd73xx_pin_nids;
4461 spec->board_config = snd_hda_check_board_config(codec,
4462 STAC_92HD73XX_MODELS,
4463 stac92hd73xx_models,
4464 stac92hd73xx_cfg_tbl);
4465again:
4466 if (spec->board_config < 0) {
4467 snd_printdd(KERN_INFO "hda_codec: Unknown model for"
4468 " STAC92HD73XX, using BIOS defaults\n");
4469 err = stac92xx_save_bios_config_regs(codec);
4470 } else
4471 err = stac_save_pin_cfgs(codec,
4472 stac92hd73xx_brd_tbl[spec->board_config]);
4473 if (err < 0) {
4474 stac92xx_free(codec);
4475 return err;
4476 }
4477
4478 spec->multiout.num_dacs = snd_hda_get_connections(codec, 0x0a,
4479 conn, STAC92HD73_DAC_COUNT + 2) - 1;
4480
4481 if (spec->multiout.num_dacs < 0) {
4482 printk(KERN_WARNING "hda_codec: Could not determine "
4483 "number of channels defaulting to DAC count\n");
4484 spec->multiout.num_dacs = STAC92HD73_DAC_COUNT;
4485 }
4486
4487 switch (spec->multiout.num_dacs) {
4488 case 0x3: /* 6 Channel */
4489 spec->mixer = stac92hd73xx_6ch_mixer;
4490 spec->init = stac92hd73xx_6ch_core_init;
4491 break;
4492 case 0x4: /* 8 Channel */
4493 spec->mixer = stac92hd73xx_8ch_mixer;
4494 spec->init = stac92hd73xx_8ch_core_init;
4495 break;
4496 case 0x5: /* 10 Channel */
4497 spec->mixer = stac92hd73xx_10ch_mixer;
4498 spec->init = stac92hd73xx_10ch_core_init;
4499 };
4500
4501 spec->multiout.dac_nids = stac92hd73xx_dac_nids;
4502 spec->aloopback_mask = 0x01;
4503 spec->aloopback_shift = 8;
4504
4505 spec->digbeep_nid = 0x1c;
4506 spec->mux_nids = stac92hd73xx_mux_nids;
4507 spec->adc_nids = stac92hd73xx_adc_nids;
4508 spec->dmic_nids = stac92hd73xx_dmic_nids;
4509 spec->dmux_nids = stac92hd73xx_dmux_nids;
4510 spec->smux_nids = stac92hd73xx_smux_nids;
4511 spec->amp_nids = stac92hd73xx_amp_nids;
4512 spec->num_amps = ARRAY_SIZE(stac92hd73xx_amp_nids);
4513
4514 spec->num_muxes = ARRAY_SIZE(stac92hd73xx_mux_nids);
4515 spec->num_adcs = ARRAY_SIZE(stac92hd73xx_adc_nids);
4516 spec->num_dmuxes = ARRAY_SIZE(stac92hd73xx_dmux_nids);
4517 memcpy(&spec->private_dimux, &stac92hd73xx_dmux,
4518 sizeof(stac92hd73xx_dmux));
4519
4520 switch (spec->board_config) {
4521 case STAC_DELL_EQ:
4522 spec->init = dell_eq_core_init;
4523 /* fallthru */
4524 case STAC_DELL_M6_AMIC:
4525 case STAC_DELL_M6_DMIC:
4526 case STAC_DELL_M6_BOTH:
4527 spec->num_smuxes = 0;
4528 spec->mixer = &stac92hd73xx_6ch_mixer[DELL_M6_MIXER];
4529 spec->amp_nids = &stac92hd73xx_amp_nids[DELL_M6_AMP];
4530 spec->eapd_switch = 0;
4531 spec->num_amps = 1;
4532
4533 if (!spec->init)
4534 spec->init = dell_m6_core_init;
4535 switch (spec->board_config) {
4536 case STAC_DELL_M6_AMIC: /* Analog Mics */
4537 stac92xx_set_config_reg(codec, 0x0b, 0x90A70170);
4538 spec->num_dmics = 0;
4539 spec->private_dimux.num_items = 1;
4540 break;
4541 case STAC_DELL_M6_DMIC: /* Digital Mics */
4542 stac92xx_set_config_reg(codec, 0x13, 0x90A60160);
4543 spec->num_dmics = 1;
4544 spec->private_dimux.num_items = 2;
4545 break;
4546 case STAC_DELL_M6_BOTH: /* Both */
4547 stac92xx_set_config_reg(codec, 0x0b, 0x90A70170);
4548 stac92xx_set_config_reg(codec, 0x13, 0x90A60160);
4549 spec->num_dmics = 1;
4550 spec->private_dimux.num_items = 2;
4551 break;
4552 }
4553 break;
4554 default:
4555 spec->num_dmics = STAC92HD73XX_NUM_DMICS;
4556 spec->num_smuxes = ARRAY_SIZE(stac92hd73xx_smux_nids);
4557 spec->eapd_switch = 1;
4558 }
4559 if (spec->board_config > STAC_92HD73XX_REF) {
4560 /* GPIO0 High = Enable EAPD */
4561 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
4562 spec->gpio_data = 0x01;
4563 }
4564 spec->dinput_mux = &spec->private_dimux;
4565
4566 spec->num_pwrs = ARRAY_SIZE(stac92hd73xx_pwr_nids);
4567 spec->pwr_nids = stac92hd73xx_pwr_nids;
4568
4569 err = stac92xx_parse_auto_config(codec, 0x25, 0x27);
4570
4571 if (!err) {
4572 if (spec->board_config < 0) {
4573 printk(KERN_WARNING "hda_codec: No auto-config is "
4574 "available, default to model=ref\n");
4575 spec->board_config = STAC_92HD73XX_REF;
4576 goto again;
4577 }
4578 err = -EINVAL;
4579 }
4580
4581 if (err < 0) {
4582 stac92xx_free(codec);
4583 return err;
4584 }
4585
4586 codec->patch_ops = stac92xx_patch_ops;
4587
4588 return 0;
4589}
4590
4591static struct hda_input_mux stac92hd83xxx_dmux = {
4592 .num_items = 3,
4593 .items = {
4594 { "Analog Inputs", 0x03 },
4595 { "Digital Mic 1", 0x04 },
4596 { "Digital Mic 2", 0x05 },
4597 }
4598};
4599
4600static int patch_stac92hd83xxx(struct hda_codec *codec)
4601{
4602 struct sigmatel_spec *spec;
4603 int err;
4604
4605 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4606 if (spec == NULL)
4607 return -ENOMEM;
4608
4609 codec->spec = spec;
4610 codec->slave_dig_outs = stac92hd83xxx_slave_dig_outs;
4611 spec->mono_nid = 0x19;
4612 spec->digbeep_nid = 0x21;
4613 spec->dmic_nids = stac92hd83xxx_dmic_nids;
4614 spec->dmux_nids = stac92hd83xxx_dmux_nids;
4615 spec->adc_nids = stac92hd83xxx_adc_nids;
4616 spec->pwr_nids = stac92hd83xxx_pwr_nids;
4617 spec->pwr_mapping = stac92hd83xxx_pwr_mapping;
4618 spec->num_pwrs = ARRAY_SIZE(stac92hd83xxx_pwr_nids);
4619 spec->multiout.dac_nids = stac92hd83xxx_dac_nids;
4620
4621 spec->init = stac92hd83xxx_core_init;
4622 switch (codec->vendor_id) {
4623 case 0x111d7605:
4624 spec->multiout.num_dacs = STAC92HD81_DAC_COUNT;
4625 break;
4626 default:
4627 spec->num_pwrs--;
4628 spec->init++; /* switch to config #2 */
4629 spec->multiout.num_dacs = STAC92HD83_DAC_COUNT;
4630 }
4631
4632 spec->mixer = stac92hd83xxx_mixer;
4633 spec->num_pins = ARRAY_SIZE(stac92hd83xxx_pin_nids);
4634 spec->num_dmuxes = ARRAY_SIZE(stac92hd83xxx_dmux_nids);
4635 spec->num_adcs = ARRAY_SIZE(stac92hd83xxx_adc_nids);
4636 spec->num_dmics = STAC92HD83XXX_NUM_DMICS;
4637 spec->dinput_mux = &stac92hd83xxx_dmux;
4638 spec->pin_nids = stac92hd83xxx_pin_nids;
4639 spec->board_config = snd_hda_check_board_config(codec,
4640 STAC_92HD83XXX_MODELS,
4641 stac92hd83xxx_models,
4642 stac92hd83xxx_cfg_tbl);
4643again:
4644 if (spec->board_config < 0) {
4645 snd_printdd(KERN_INFO "hda_codec: Unknown model for"
4646 " STAC92HD83XXX, using BIOS defaults\n");
4647 err = stac92xx_save_bios_config_regs(codec);
4648 } else
4649 err = stac_save_pin_cfgs(codec,
4650 stac92hd83xxx_brd_tbl[spec->board_config]);
4651 if (err < 0) {
4652 stac92xx_free(codec);
4653 return err;
4654 }
4655
4656 err = stac92xx_parse_auto_config(codec, 0x1d, 0);
4657 if (!err) {
4658 if (spec->board_config < 0) {
4659 printk(KERN_WARNING "hda_codec: No auto-config is "
4660 "available, default to model=ref\n");
4661 spec->board_config = STAC_92HD83XXX_REF;
4662 goto again;
4663 }
4664 err = -EINVAL;
4665 }
4666
4667 if (err < 0) {
4668 stac92xx_free(codec);
4669 return err;
4670 }
4671
4672 codec->patch_ops = stac92xx_patch_ops;
4673
4674 return 0;
4675}
4676
4677#ifdef SND_HDA_NEEDS_RESUME
4678static void stac92hd71xx_set_power_state(struct hda_codec *codec, int pwr)
4679{
4680 struct sigmatel_spec *spec = codec->spec;
4681 int i;
4682 snd_hda_codec_write_cache(codec, codec->afg, 0,
4683 AC_VERB_SET_POWER_STATE, pwr);
4684
4685 msleep(1);
4686 for (i = 0; i < spec->num_adcs; i++) {
4687 snd_hda_codec_write_cache(codec,
4688 spec->adc_nids[i], 0,
4689 AC_VERB_SET_POWER_STATE, pwr);
4690 }
4691};
4692
4693static int stac92hd71xx_resume(struct hda_codec *codec)
4694{
4695 stac92hd71xx_set_power_state(codec, AC_PWRST_D0);
4696 return stac92xx_resume(codec);
4697}
4698
4699static int stac92hd71xx_suspend(struct hda_codec *codec, pm_message_t state)
4700{
4701 stac92hd71xx_set_power_state(codec, AC_PWRST_D3);
4702 return stac92xx_suspend(codec, state);
4703};
4704
4705#endif
4706
4707static struct hda_codec_ops stac92hd71bxx_patch_ops = {
4708 .build_controls = stac92xx_build_controls,
4709 .build_pcms = stac92xx_build_pcms,
4710 .init = stac92xx_init,
4711 .free = stac92xx_free,
4712 .unsol_event = stac92xx_unsol_event,
4713#ifdef SND_HDA_NEEDS_RESUME
4714 .suspend = stac92hd71xx_suspend,
4715 .resume = stac92hd71xx_resume,
4716#endif
4717};
4718
4719static struct hda_input_mux stac92hd71bxx_dmux = {
4720 .num_items = 4,
4721 .items = {
4722 { "Analog Inputs", 0x00 },
4723 { "Mixer", 0x01 },
4724 { "Digital Mic 1", 0x02 },
4725 { "Digital Mic 2", 0x03 },
4726 }
4727};
4728
4729static int patch_stac92hd71bxx(struct hda_codec *codec)
4730{
4731 struct sigmatel_spec *spec;
4732 int err = 0;
4733
4734 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4735 if (spec == NULL)
4736 return -ENOMEM;
4737
4738 codec->spec = spec;
4739 codec->patch_ops = stac92xx_patch_ops;
4740 spec->num_pins = ARRAY_SIZE(stac92hd71bxx_pin_nids);
4741 spec->num_pwrs = ARRAY_SIZE(stac92hd71bxx_pwr_nids);
4742 spec->pin_nids = stac92hd71bxx_pin_nids;
4743 memcpy(&spec->private_dimux, &stac92hd71bxx_dmux,
4744 sizeof(stac92hd71bxx_dmux));
4745 spec->board_config = snd_hda_check_board_config(codec,
4746 STAC_92HD71BXX_MODELS,
4747 stac92hd71bxx_models,
4748 stac92hd71bxx_cfg_tbl);
4749again:
4750 if (spec->board_config < 0) {
4751 snd_printdd(KERN_INFO "hda_codec: Unknown model for"
4752 " STAC92HD71BXX, using BIOS defaults\n");
4753 err = stac92xx_save_bios_config_regs(codec);
4754 } else
4755 err = stac_save_pin_cfgs(codec,
4756 stac92hd71bxx_brd_tbl[spec->board_config]);
4757 if (err < 0) {
4758 stac92xx_free(codec);
4759 return err;
4760 }
4761
4762 if (spec->board_config > STAC_92HD71BXX_REF) {
4763 /* GPIO0 = EAPD */
4764 spec->gpio_mask = 0x01;
4765 spec->gpio_dir = 0x01;
4766 spec->gpio_data = 0x01;
4767 }
4768
4769 switch (codec->vendor_id) {
4770 case 0x111d76b6: /* 4 Port without Analog Mixer */
4771 case 0x111d76b7:
4772 case 0x111d76b4: /* 6 Port without Analog Mixer */
4773 case 0x111d76b5:
4774 spec->mixer = stac92hd71bxx_mixer;
4775 spec->init = stac92hd71bxx_core_init;
4776 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
4777 break;
4778 case 0x111d7608: /* 5 Port with Analog Mixer */
4779 switch (spec->board_config) {
4780 case STAC_HP_M4:
4781 /* Enable VREF power saving on GPIO1 detect */
4782 err = stac_add_event(spec, codec->afg,
4783 STAC_VREF_EVENT, 0x02);
4784 if (err < 0)
4785 return err;
4786 snd_hda_codec_write_cache(codec, codec->afg, 0,
4787 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x02);
4788 snd_hda_codec_write_cache(codec, codec->afg, 0,
4789 AC_VERB_SET_UNSOLICITED_ENABLE,
4790 AC_USRSP_EN | err);
4791 spec->gpio_mask |= 0x02;
4792 break;
4793 }
4794 if ((codec->revision_id & 0xf) == 0 ||
4795 (codec->revision_id & 0xf) == 1) {
4796#ifdef SND_HDA_NEEDS_RESUME
4797 codec->patch_ops = stac92hd71bxx_patch_ops;
4798#endif
4799 spec->stream_delay = 40; /* 40 milliseconds */
4800 }
4801
4802 /* no output amps */
4803 spec->num_pwrs = 0;
4804 spec->mixer = stac92hd71bxx_analog_mixer;
4805 spec->dinput_mux = &spec->private_dimux;
4806
4807 /* disable VSW */
4808 spec->init = &stac92hd71bxx_analog_core_init[HD_DISABLE_PORTF];
4809 stac_change_pin_config(codec, 0xf, 0x40f000f0);
4810 break;
4811 case 0x111d7603: /* 6 Port with Analog Mixer */
4812 if ((codec->revision_id & 0xf) == 1) {
4813#ifdef SND_HDA_NEEDS_RESUME
4814 codec->patch_ops = stac92hd71bxx_patch_ops;
4815#endif
4816 spec->stream_delay = 40; /* 40 milliseconds */
4817 }
4818
4819 /* no output amps */
4820 spec->num_pwrs = 0;
4821 /* fallthru */
4822 default:
4823 spec->dinput_mux = &spec->private_dimux;
4824 spec->mixer = stac92hd71bxx_analog_mixer;
4825 spec->init = stac92hd71bxx_analog_core_init;
4826 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
4827 }
4828
4829 spec->aloopback_mask = 0x50;
4830 spec->aloopback_shift = 0;
4831
4832 spec->powerdown_adcs = 1;
4833 spec->digbeep_nid = 0x26;
4834 spec->mux_nids = stac92hd71bxx_mux_nids;
4835 spec->adc_nids = stac92hd71bxx_adc_nids;
4836 spec->dmic_nids = stac92hd71bxx_dmic_nids;
4837 spec->dmux_nids = stac92hd71bxx_dmux_nids;
4838 spec->smux_nids = stac92hd71bxx_smux_nids;
4839 spec->pwr_nids = stac92hd71bxx_pwr_nids;
4840
4841 spec->num_muxes = ARRAY_SIZE(stac92hd71bxx_mux_nids);
4842 spec->num_adcs = ARRAY_SIZE(stac92hd71bxx_adc_nids);
4843
4844 switch (spec->board_config) {
4845 case STAC_HP_M4:
4846 /* enable internal microphone */
4847 stac_change_pin_config(codec, 0x0e, 0x01813040);
4848 stac92xx_auto_set_pinctl(codec, 0x0e,
4849 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80);
4850 /* fallthru */
4851 case STAC_DELL_M4_2:
4852 spec->num_dmics = 0;
4853 spec->num_smuxes = 0;
4854 spec->num_dmuxes = 0;
4855 break;
4856 case STAC_DELL_M4_1:
4857 case STAC_DELL_M4_3:
4858 spec->num_dmics = 1;
4859 spec->num_smuxes = 0;
4860 spec->num_dmuxes = 0;
4861 break;
4862 default:
4863 spec->num_dmics = STAC92HD71BXX_NUM_DMICS;
4864 spec->num_smuxes = ARRAY_SIZE(stac92hd71bxx_smux_nids);
4865 spec->num_dmuxes = ARRAY_SIZE(stac92hd71bxx_dmux_nids);
4866 };
4867
4868 spec->multiout.num_dacs = 1;
4869 spec->multiout.hp_nid = 0x11;
4870 spec->multiout.dac_nids = stac92hd71bxx_dac_nids;
4871 if (spec->dinput_mux)
4872 spec->private_dimux.num_items +=
4873 spec->num_dmics -
4874 (ARRAY_SIZE(stac92hd71bxx_dmic_nids) - 1);
4875
4876 err = stac92xx_parse_auto_config(codec, 0x21, 0x23);
4877 if (!err) {
4878 if (spec->board_config < 0) {
4879 printk(KERN_WARNING "hda_codec: No auto-config is "
4880 "available, default to model=ref\n");
4881 spec->board_config = STAC_92HD71BXX_REF;
4882 goto again;
4883 }
4884 err = -EINVAL;
4885 }
4886
4887 if (err < 0) {
4888 stac92xx_free(codec);
4889 return err;
4890 }
4891
4892 return 0;
4893};
4894
4895static int patch_stac922x(struct hda_codec *codec)
4896{
4897 struct sigmatel_spec *spec;
4898 int err;
4899
4900 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4901 if (spec == NULL)
4902 return -ENOMEM;
4903
4904 codec->spec = spec;
4905 spec->num_pins = ARRAY_SIZE(stac922x_pin_nids);
4906 spec->pin_nids = stac922x_pin_nids;
4907 spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS,
4908 stac922x_models,
4909 stac922x_cfg_tbl);
4910 if (spec->board_config == STAC_INTEL_MAC_AUTO) {
4911 spec->gpio_mask = spec->gpio_dir = 0x03;
4912 spec->gpio_data = 0x03;
4913 /* Intel Macs have all same PCI SSID, so we need to check
4914 * codec SSID to distinguish the exact models
4915 */
4916 printk(KERN_INFO "hda_codec: STAC922x, Apple subsys_id=%x\n", codec->subsystem_id);
4917 switch (codec->subsystem_id) {
4918
4919 case 0x106b0800:
4920 spec->board_config = STAC_INTEL_MAC_V1;
4921 break;
4922 case 0x106b0600:
4923 case 0x106b0700:
4924 spec->board_config = STAC_INTEL_MAC_V2;
4925 break;
4926 case 0x106b0e00:
4927 case 0x106b0f00:
4928 case 0x106b1600:
4929 case 0x106b1700:
4930 case 0x106b0200:
4931 case 0x106b1e00:
4932 spec->board_config = STAC_INTEL_MAC_V3;
4933 break;
4934 case 0x106b1a00:
4935 case 0x00000100:
4936 spec->board_config = STAC_INTEL_MAC_V4;
4937 break;
4938 case 0x106b0a00:
4939 case 0x106b2200:
4940 spec->board_config = STAC_INTEL_MAC_V5;
4941 break;
4942 default:
4943 spec->board_config = STAC_INTEL_MAC_V3;
4944 break;
4945 }
4946 }
4947
4948 again:
4949 if (spec->board_config < 0) {
4950 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC922x, "
4951 "using BIOS defaults\n");
4952 err = stac92xx_save_bios_config_regs(codec);
4953 } else
4954 err = stac_save_pin_cfgs(codec,
4955 stac922x_brd_tbl[spec->board_config]);
4956 if (err < 0) {
4957 stac92xx_free(codec);
4958 return err;
4959 }
4960
4961 spec->adc_nids = stac922x_adc_nids;
4962 spec->mux_nids = stac922x_mux_nids;
4963 spec->num_muxes = ARRAY_SIZE(stac922x_mux_nids);
4964 spec->num_adcs = ARRAY_SIZE(stac922x_adc_nids);
4965 spec->num_dmics = 0;
4966 spec->num_pwrs = 0;
4967
4968 spec->init = stac922x_core_init;
4969 spec->mixer = stac922x_mixer;
4970
4971 spec->multiout.dac_nids = spec->dac_nids;
4972
4973 err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
4974 if (!err) {
4975 if (spec->board_config < 0) {
4976 printk(KERN_WARNING "hda_codec: No auto-config is "
4977 "available, default to model=ref\n");
4978 spec->board_config = STAC_D945_REF;
4979 goto again;
4980 }
4981 err = -EINVAL;
4982 }
4983 if (err < 0) {
4984 stac92xx_free(codec);
4985 return err;
4986 }
4987
4988 codec->patch_ops = stac92xx_patch_ops;
4989
4990 /* Fix Mux capture level; max to 2 */
4991 snd_hda_override_amp_caps(codec, 0x12, HDA_OUTPUT,
4992 (0 << AC_AMPCAP_OFFSET_SHIFT) |
4993 (2 << AC_AMPCAP_NUM_STEPS_SHIFT) |
4994 (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4995 (0 << AC_AMPCAP_MUTE_SHIFT));
4996
4997 return 0;
4998}
4999
5000static int patch_stac927x(struct hda_codec *codec)
5001{
5002 struct sigmatel_spec *spec;
5003 int err;
5004
5005 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5006 if (spec == NULL)
5007 return -ENOMEM;
5008
5009 codec->spec = spec;
5010 spec->num_pins = ARRAY_SIZE(stac927x_pin_nids);
5011 spec->pin_nids = stac927x_pin_nids;
5012 spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS,
5013 stac927x_models,
5014 stac927x_cfg_tbl);
5015 again:
5016 if (spec->board_config < 0 || !stac927x_brd_tbl[spec->board_config]) {
5017 if (spec->board_config < 0)
5018 snd_printdd(KERN_INFO "hda_codec: Unknown model for"
5019 "STAC927x, using BIOS defaults\n");
5020 err = stac92xx_save_bios_config_regs(codec);
5021 } else
5022 err = stac_save_pin_cfgs(codec,
5023 stac927x_brd_tbl[spec->board_config]);
5024 if (err < 0) {
5025 stac92xx_free(codec);
5026 return err;
5027 }
5028
5029 spec->digbeep_nid = 0x23;
5030 spec->adc_nids = stac927x_adc_nids;
5031 spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
5032 spec->mux_nids = stac927x_mux_nids;
5033 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
5034 spec->smux_nids = stac927x_smux_nids;
5035 spec->num_smuxes = ARRAY_SIZE(stac927x_smux_nids);
5036 spec->spdif_labels = stac927x_spdif_labels;
5037 spec->dac_list = stac927x_dac_nids;
5038 spec->multiout.dac_nids = spec->dac_nids;
5039
5040 switch (spec->board_config) {
5041 case STAC_D965_3ST:
5042 case STAC_D965_5ST:
5043 /* GPIO0 High = Enable EAPD */
5044 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x01;
5045 spec->gpio_data = 0x01;
5046 spec->num_dmics = 0;
5047
5048 spec->init = d965_core_init;
5049 spec->mixer = stac927x_mixer;
5050 break;
5051 case STAC_DELL_BIOS:
5052 switch (codec->subsystem_id) {
5053 case 0x10280209:
5054 case 0x1028022e:
5055 /* correct the device field to SPDIF out */
5056 stac_change_pin_config(codec, 0x21, 0x01442070);
5057 break;
5058 };
5059 /* configure the analog microphone on some laptops */
5060 stac_change_pin_config(codec, 0x0c, 0x90a79130);
5061 /* correct the front output jack as a hp out */
5062 stac_change_pin_config(codec, 0x0f, 0x0227011f);
5063 /* correct the front input jack as a mic */
5064 stac_change_pin_config(codec, 0x0e, 0x02a79130);
5065 /* fallthru */
5066 case STAC_DELL_3ST:
5067 /* GPIO2 High = Enable EAPD */
5068 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x04;
5069 spec->gpio_data = 0x04;
5070 spec->dmic_nids = stac927x_dmic_nids;
5071 spec->num_dmics = STAC927X_NUM_DMICS;
5072
5073 spec->init = d965_core_init;
5074 spec->mixer = stac927x_mixer;
5075 spec->dmux_nids = stac927x_dmux_nids;
5076 spec->num_dmuxes = ARRAY_SIZE(stac927x_dmux_nids);
5077 break;
5078 default:
5079 if (spec->board_config > STAC_D965_REF) {
5080 /* GPIO0 High = Enable EAPD */
5081 spec->eapd_mask = spec->gpio_mask = 0x01;
5082 spec->gpio_dir = spec->gpio_data = 0x01;
5083 }
5084 spec->num_dmics = 0;
5085
5086 spec->init = stac927x_core_init;
5087 spec->mixer = stac927x_mixer;
5088 }
5089
5090 spec->num_pwrs = 0;
5091 spec->aloopback_mask = 0x40;
5092 spec->aloopback_shift = 0;
5093 spec->eapd_switch = 1;
5094
5095 err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
5096 if (!err) {
5097 if (spec->board_config < 0) {
5098 printk(KERN_WARNING "hda_codec: No auto-config is "
5099 "available, default to model=ref\n");
5100 spec->board_config = STAC_D965_REF;
5101 goto again;
5102 }
5103 err = -EINVAL;
5104 }
5105 if (err < 0) {
5106 stac92xx_free(codec);
5107 return err;
5108 }
5109
5110 codec->patch_ops = stac92xx_patch_ops;
5111
5112 /*
5113 * !!FIXME!!
5114 * The STAC927x seem to require fairly long delays for certain
5115 * command sequences. With too short delays (even if the answer
5116 * is set to RIRB properly), it results in the silence output
5117 * on some hardwares like Dell.
5118 *
5119 * The below flag enables the longer delay (see get_response
5120 * in hda_intel.c).
5121 */
5122 codec->bus->needs_damn_long_delay = 1;
5123
5124 return 0;
5125}
5126
5127static int patch_stac9205(struct hda_codec *codec)
5128{
5129 struct sigmatel_spec *spec;
5130 int err;
5131
5132 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5133 if (spec == NULL)
5134 return -ENOMEM;
5135
5136 codec->spec = spec;
5137 spec->num_pins = ARRAY_SIZE(stac9205_pin_nids);
5138 spec->pin_nids = stac9205_pin_nids;
5139 spec->board_config = snd_hda_check_board_config(codec, STAC_9205_MODELS,
5140 stac9205_models,
5141 stac9205_cfg_tbl);
5142 again:
5143 if (spec->board_config < 0) {
5144 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9205, using BIOS defaults\n");
5145 err = stac92xx_save_bios_config_regs(codec);
5146 } else
5147 err = stac_save_pin_cfgs(codec,
5148 stac9205_brd_tbl[spec->board_config]);
5149 if (err < 0) {
5150 stac92xx_free(codec);
5151 return err;
5152 }
5153
5154 spec->digbeep_nid = 0x23;
5155 spec->adc_nids = stac9205_adc_nids;
5156 spec->num_adcs = ARRAY_SIZE(stac9205_adc_nids);
5157 spec->mux_nids = stac9205_mux_nids;
5158 spec->num_muxes = ARRAY_SIZE(stac9205_mux_nids);
5159 spec->smux_nids = stac9205_smux_nids;
5160 spec->num_smuxes = ARRAY_SIZE(stac9205_smux_nids);
5161 spec->dmic_nids = stac9205_dmic_nids;
5162 spec->num_dmics = STAC9205_NUM_DMICS;
5163 spec->dmux_nids = stac9205_dmux_nids;
5164 spec->num_dmuxes = ARRAY_SIZE(stac9205_dmux_nids);
5165 spec->num_pwrs = 0;
5166
5167 spec->init = stac9205_core_init;
5168 spec->mixer = stac9205_mixer;
5169
5170 spec->aloopback_mask = 0x40;
5171 spec->aloopback_shift = 0;
5172 spec->eapd_switch = 1;
5173 spec->multiout.dac_nids = spec->dac_nids;
5174
5175 switch (spec->board_config){
5176 case STAC_9205_DELL_M43:
5177 /* Enable SPDIF in/out */
5178 stac_change_pin_config(codec, 0x1f, 0x01441030);
5179 stac_change_pin_config(codec, 0x20, 0x1c410030);
5180
5181 /* Enable unsol response for GPIO4/Dock HP connection */
5182 err = stac_add_event(spec, codec->afg, STAC_VREF_EVENT, 0x01);
5183 if (err < 0)
5184 return err;
5185 snd_hda_codec_write_cache(codec, codec->afg, 0,
5186 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x10);
5187 snd_hda_codec_write_cache(codec, codec->afg, 0,
5188 AC_VERB_SET_UNSOLICITED_ENABLE,
5189 AC_USRSP_EN | err);
5190
5191 spec->gpio_dir = 0x0b;
5192 spec->eapd_mask = 0x01;
5193 spec->gpio_mask = 0x1b;
5194 spec->gpio_mute = 0x10;
5195 /* GPIO0 High = EAPD, GPIO1 Low = Headphone Mute,
5196 * GPIO3 Low = DRM
5197 */
5198 spec->gpio_data = 0x01;
5199 break;
5200 case STAC_9205_REF:
5201 /* SPDIF-In enabled */
5202 break;
5203 default:
5204 /* GPIO0 High = EAPD */
5205 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
5206 spec->gpio_data = 0x01;
5207 break;
5208 }
5209
5210 err = stac92xx_parse_auto_config(codec, 0x1f, 0x20);
5211 if (!err) {
5212 if (spec->board_config < 0) {
5213 printk(KERN_WARNING "hda_codec: No auto-config is "
5214 "available, default to model=ref\n");
5215 spec->board_config = STAC_9205_REF;
5216 goto again;
5217 }
5218 err = -EINVAL;
5219 }
5220 if (err < 0) {
5221 stac92xx_free(codec);
5222 return err;
5223 }
5224
5225 codec->patch_ops = stac92xx_patch_ops;
5226
5227 return 0;
5228}
5229
5230/*
5231 * STAC9872 hack
5232 */
5233
5234/* static config for Sony VAIO FE550G and Sony VAIO AR */
5235static hda_nid_t vaio_dacs[] = { 0x2 };
5236#define VAIO_HP_DAC 0x5
5237static hda_nid_t vaio_adcs[] = { 0x8 /*,0x6*/ };
5238static hda_nid_t vaio_mux_nids[] = { 0x15 };
5239
5240static struct hda_input_mux vaio_mux = {
5241 .num_items = 3,
5242 .items = {
5243 /* { "HP", 0x0 }, */
5244 { "Mic Jack", 0x1 },
5245 { "Internal Mic", 0x2 },
5246 { "PCM", 0x3 },
5247 }
5248};
5249
5250static struct hda_verb vaio_init[] = {
5251 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
5252 {0x0a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | STAC_HP_EVENT},
5253 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
5254 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
5255 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
5256 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
5257 {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
5258 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
5259 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
5260 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
5261 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
5262 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
5263 {}
5264};
5265
5266static struct hda_verb vaio_ar_init[] = {
5267 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
5268 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
5269 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
5270 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
5271/* {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },*/ /* Optical Out */
5272 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
5273 {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
5274 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
5275 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
5276/* {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},*/ /* Optical Out */
5277 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
5278 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
5279 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
5280 {}
5281};
5282
5283static struct snd_kcontrol_new vaio_mixer[] = {
5284 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x02, 0, HDA_OUTPUT),
5285 HDA_CODEC_MUTE("Headphone Playback Switch", 0x02, 0, HDA_OUTPUT),
5286 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x05, 0, HDA_OUTPUT),
5287 HDA_CODEC_MUTE("Speaker Playback Switch", 0x05, 0, HDA_OUTPUT),
5288 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
5289 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
5290 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
5291 {
5292 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5293 .name = "Capture Source",
5294 .count = 1,
5295 .info = stac92xx_mux_enum_info,
5296 .get = stac92xx_mux_enum_get,
5297 .put = stac92xx_mux_enum_put,
5298 },
5299 {}
5300};
5301
5302static struct snd_kcontrol_new vaio_ar_mixer[] = {
5303 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x02, 0, HDA_OUTPUT),
5304 HDA_CODEC_MUTE("Headphone Playback Switch", 0x02, 0, HDA_OUTPUT),
5305 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x05, 0, HDA_OUTPUT),
5306 HDA_CODEC_MUTE("Speaker Playback Switch", 0x05, 0, HDA_OUTPUT),
5307 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
5308 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
5309 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
5310 /*HDA_CODEC_MUTE("Optical Out Switch", 0x10, 0, HDA_OUTPUT),
5311 HDA_CODEC_VOLUME("Optical Out Volume", 0x10, 0, HDA_OUTPUT),*/
5312 {
5313 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5314 .name = "Capture Source",
5315 .count = 1,
5316 .info = stac92xx_mux_enum_info,
5317 .get = stac92xx_mux_enum_get,
5318 .put = stac92xx_mux_enum_put,
5319 },
5320 {}
5321};
5322
5323static struct hda_codec_ops stac9872_patch_ops = {
5324 .build_controls = stac92xx_build_controls,
5325 .build_pcms = stac92xx_build_pcms,
5326 .init = stac92xx_init,
5327 .free = stac92xx_free,
5328#ifdef SND_HDA_NEEDS_RESUME
5329 .resume = stac92xx_resume,
5330#endif
5331};
5332
5333static int stac9872_vaio_init(struct hda_codec *codec)
5334{
5335 int err;
5336
5337 err = stac92xx_init(codec);
5338 if (err < 0)
5339 return err;
5340 if (codec->patch_ops.unsol_event)
5341 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
5342 return 0;
5343}
5344
5345static void stac9872_vaio_hp_detect(struct hda_codec *codec, unsigned int res)
5346{
5347 if (get_hp_pin_presence(codec, 0x0a)) {
5348 stac92xx_reset_pinctl(codec, 0x0f, AC_PINCTL_OUT_EN);
5349 stac92xx_set_pinctl(codec, 0x0a, AC_PINCTL_OUT_EN);
5350 } else {
5351 stac92xx_reset_pinctl(codec, 0x0a, AC_PINCTL_OUT_EN);
5352 stac92xx_set_pinctl(codec, 0x0f, AC_PINCTL_OUT_EN);
5353 }
5354}
5355
5356static void stac9872_vaio_unsol_event(struct hda_codec *codec, unsigned int res)
5357{
5358 switch (res >> 26) {
5359 case STAC_HP_EVENT:
5360 stac9872_vaio_hp_detect(codec, res);
5361 break;
5362 }
5363}
5364
5365static struct hda_codec_ops stac9872_vaio_patch_ops = {
5366 .build_controls = stac92xx_build_controls,
5367 .build_pcms = stac92xx_build_pcms,
5368 .init = stac9872_vaio_init,
5369 .free = stac92xx_free,
5370 .unsol_event = stac9872_vaio_unsol_event,
5371#ifdef CONFIG_PM
5372 .resume = stac92xx_resume,
5373#endif
5374};
5375
5376enum { /* FE and SZ series. id=0x83847661 and subsys=0x104D0700 or 104D1000. */
5377 CXD9872RD_VAIO,
5378 /* Unknown. id=0x83847662 and subsys=0x104D1200 or 104D1000. */
5379 STAC9872AK_VAIO,
5380 /* Unknown. id=0x83847661 and subsys=0x104D1200. */
5381 STAC9872K_VAIO,
5382 /* AR Series. id=0x83847664 and subsys=104D1300 */
5383 CXD9872AKD_VAIO,
5384 STAC_9872_MODELS,
5385};
5386
5387static const char *stac9872_models[STAC_9872_MODELS] = {
5388 [CXD9872RD_VAIO] = "vaio",
5389 [CXD9872AKD_VAIO] = "vaio-ar",
5390};
5391
5392static struct snd_pci_quirk stac9872_cfg_tbl[] = {
5393 SND_PCI_QUIRK(0x104d, 0x81e6, "Sony VAIO F/S", CXD9872RD_VAIO),
5394 SND_PCI_QUIRK(0x104d, 0x81ef, "Sony VAIO F/S", CXD9872RD_VAIO),
5395 SND_PCI_QUIRK(0x104d, 0x81fd, "Sony VAIO AR", CXD9872AKD_VAIO),
5396 SND_PCI_QUIRK(0x104d, 0x8205, "Sony VAIO AR", CXD9872AKD_VAIO),
5397 {}
5398};
5399
5400static int patch_stac9872(struct hda_codec *codec)
5401{
5402 struct sigmatel_spec *spec;
5403 int board_config;
5404
5405 board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
5406 stac9872_models,
5407 stac9872_cfg_tbl);
5408 if (board_config < 0)
5409 /* unknown config, let generic-parser do its job... */
5410 return snd_hda_parse_generic_codec(codec);
5411
5412 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5413 if (spec == NULL)
5414 return -ENOMEM;
5415
5416 codec->spec = spec;
5417 switch (board_config) {
5418 case CXD9872RD_VAIO:
5419 case STAC9872AK_VAIO:
5420 case STAC9872K_VAIO:
5421 spec->mixer = vaio_mixer;
5422 spec->init = vaio_init;
5423 spec->multiout.max_channels = 2;
5424 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
5425 spec->multiout.dac_nids = vaio_dacs;
5426 spec->multiout.hp_nid = VAIO_HP_DAC;
5427 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
5428 spec->adc_nids = vaio_adcs;
5429 spec->num_pwrs = 0;
5430 spec->input_mux = &vaio_mux;
5431 spec->mux_nids = vaio_mux_nids;
5432 codec->patch_ops = stac9872_vaio_patch_ops;
5433 break;
5434
5435 case CXD9872AKD_VAIO:
5436 spec->mixer = vaio_ar_mixer;
5437 spec->init = vaio_ar_init;
5438 spec->multiout.max_channels = 2;
5439 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
5440 spec->multiout.dac_nids = vaio_dacs;
5441 spec->multiout.hp_nid = VAIO_HP_DAC;
5442 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
5443 spec->num_pwrs = 0;
5444 spec->adc_nids = vaio_adcs;
5445 spec->input_mux = &vaio_mux;
5446 spec->mux_nids = vaio_mux_nids;
5447 codec->patch_ops = stac9872_patch_ops;
5448 break;
5449 }
5450
5451 return 0;
5452}
5453
5454
5455/*
5456 * patch entries
5457 */
5458struct hda_codec_preset snd_hda_preset_sigmatel[] = {
5459 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
5460 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
5461 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
5462 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
5463 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
5464 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
5465 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
5466 { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
5467 { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
5468 { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
5469 { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
5470 { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
5471 { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
5472 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
5473 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
5474 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
5475 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
5476 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
5477 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
5478 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
5479 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
5480 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
5481 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
5482 { .id = 0x83847632, .name = "STAC9202", .patch = patch_stac925x },
5483 { .id = 0x83847633, .name = "STAC9202D", .patch = patch_stac925x },
5484 { .id = 0x83847634, .name = "STAC9250", .patch = patch_stac925x },
5485 { .id = 0x83847635, .name = "STAC9250D", .patch = patch_stac925x },
5486 { .id = 0x83847636, .name = "STAC9251", .patch = patch_stac925x },
5487 { .id = 0x83847637, .name = "STAC9250D", .patch = patch_stac925x },
5488 { .id = 0x83847645, .name = "92HD206X", .patch = patch_stac927x },
5489 { .id = 0x83847646, .name = "92HD206D", .patch = patch_stac927x },
5490 /* The following does not take into account .id=0x83847661 when subsys =
5491 * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
5492 * currently not fully supported.
5493 */
5494 { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
5495 { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
5496 { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
5497 { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
5498 { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
5499 { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
5500 { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
5501 { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
5502 { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
5503 { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
5504 { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
5505 { .id = 0x111d7603, .name = "92HD75B3X5", .patch = patch_stac92hd71bxx},
5506 { .id = 0x111d7604, .name = "92HD83C1X5", .patch = patch_stac92hd83xxx},
5507 { .id = 0x111d7605, .name = "92HD81B1X5", .patch = patch_stac92hd83xxx},
5508 { .id = 0x111d7608, .name = "92HD75B2X5", .patch = patch_stac92hd71bxx},
5509 { .id = 0x111d7674, .name = "92HD73D1X5", .patch = patch_stac92hd73xx },
5510 { .id = 0x111d7675, .name = "92HD73C1X5", .patch = patch_stac92hd73xx },
5511 { .id = 0x111d7676, .name = "92HD73E1X5", .patch = patch_stac92hd73xx },
5512 { .id = 0x111d76b0, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
5513 { .id = 0x111d76b1, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
5514 { .id = 0x111d76b2, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
5515 { .id = 0x111d76b3, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
5516 { .id = 0x111d76b4, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
5517 { .id = 0x111d76b5, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
5518 { .id = 0x111d76b6, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
5519 { .id = 0x111d76b7, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
5520 {} /* terminator */
5521};