• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /netgear-R7000-V1.0.7.12_1.2.5/components/opensource/linux/linux-2.6.36/sound/pci/hda/
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 <linux/dmi.h>
32#include <sound/core.h>
33#include <sound/asoundef.h>
34#include <sound/jack.h>
35#include "hda_codec.h"
36#include "hda_local.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	STAC_LO_EVENT,
45	STAC_MIC_EVENT,
46};
47
48enum {
49	STAC_AUTO,
50	STAC_REF,
51	STAC_9200_OQO,
52	STAC_9200_DELL_D21,
53	STAC_9200_DELL_D22,
54	STAC_9200_DELL_D23,
55	STAC_9200_DELL_M21,
56	STAC_9200_DELL_M22,
57	STAC_9200_DELL_M23,
58	STAC_9200_DELL_M24,
59	STAC_9200_DELL_M25,
60	STAC_9200_DELL_M26,
61	STAC_9200_DELL_M27,
62	STAC_9200_M4,
63	STAC_9200_M4_2,
64	STAC_9200_PANASONIC,
65	STAC_9200_MODELS
66};
67
68enum {
69	STAC_9205_AUTO,
70	STAC_9205_REF,
71	STAC_9205_DELL_M42,
72	STAC_9205_DELL_M43,
73	STAC_9205_DELL_M44,
74	STAC_9205_EAPD,
75	STAC_9205_MODELS
76};
77
78enum {
79	STAC_92HD73XX_AUTO,
80	STAC_92HD73XX_NO_JD, /* no jack-detection */
81	STAC_92HD73XX_REF,
82	STAC_92HD73XX_INTEL,
83	STAC_DELL_M6_AMIC,
84	STAC_DELL_M6_DMIC,
85	STAC_DELL_M6_BOTH,
86	STAC_DELL_EQ,
87	STAC_ALIENWARE_M17X,
88	STAC_92HD73XX_MODELS
89};
90
91enum {
92	STAC_92HD83XXX_AUTO,
93	STAC_92HD83XXX_REF,
94	STAC_92HD83XXX_PWR_REF,
95	STAC_DELL_S14,
96	STAC_DELL_E6410,
97	STAC_92HD83XXX_HP,
98	STAC_HP_DV7_4000,
99	STAC_92HD83XXX_MODELS
100};
101
102enum {
103	STAC_92HD71BXX_AUTO,
104	STAC_92HD71BXX_REF,
105	STAC_DELL_M4_1,
106	STAC_DELL_M4_2,
107	STAC_DELL_M4_3,
108	STAC_HP_M4,
109	STAC_HP_DV4,
110	STAC_HP_DV5,
111	STAC_HP_HDX,
112	STAC_HP_DV4_1222NR,
113	STAC_92HD71BXX_MODELS
114};
115
116enum {
117	STAC_925x_AUTO,
118	STAC_925x_REF,
119	STAC_M1,
120	STAC_M1_2,
121	STAC_M2,
122	STAC_M2_2,
123	STAC_M3,
124	STAC_M5,
125	STAC_M6,
126	STAC_925x_MODELS
127};
128
129enum {
130	STAC_922X_AUTO,
131	STAC_D945_REF,
132	STAC_D945GTP3,
133	STAC_D945GTP5,
134	STAC_INTEL_MAC_V1,
135	STAC_INTEL_MAC_V2,
136	STAC_INTEL_MAC_V3,
137	STAC_INTEL_MAC_V4,
138	STAC_INTEL_MAC_V5,
139	STAC_INTEL_MAC_AUTO, /* This model is selected if no module parameter
140			      * is given, one of the above models will be
141			      * chosen according to the subsystem id. */
142	/* for backward compatibility */
143	STAC_MACMINI,
144	STAC_MACBOOK,
145	STAC_MACBOOK_PRO_V1,
146	STAC_MACBOOK_PRO_V2,
147	STAC_IMAC_INTEL,
148	STAC_IMAC_INTEL_20,
149	STAC_ECS_202,
150	STAC_922X_DELL_D81,
151	STAC_922X_DELL_D82,
152	STAC_922X_DELL_M81,
153	STAC_922X_DELL_M82,
154	STAC_922X_MODELS
155};
156
157enum {
158	STAC_927X_AUTO,
159	STAC_D965_REF_NO_JD, /* no jack-detection */
160	STAC_D965_REF,
161	STAC_D965_3ST,
162	STAC_D965_5ST,
163	STAC_D965_5ST_NO_FP,
164	STAC_DELL_3ST,
165	STAC_DELL_BIOS,
166	STAC_927X_VOLKNOB,
167	STAC_927X_MODELS
168};
169
170enum {
171	STAC_9872_AUTO,
172	STAC_9872_VAIO,
173	STAC_9872_MODELS
174};
175
176struct sigmatel_event {
177	hda_nid_t nid;
178	unsigned char type;
179	unsigned char tag;
180	int data;
181};
182
183struct sigmatel_jack {
184	hda_nid_t nid;
185	int type;
186	struct snd_jack *jack;
187};
188
189struct sigmatel_mic_route {
190	hda_nid_t pin;
191	signed char mux_idx;
192	signed char dmux_idx;
193};
194
195struct sigmatel_spec {
196	struct snd_kcontrol_new *mixers[4];
197	unsigned int num_mixers;
198
199	int board_config;
200	unsigned int eapd_switch: 1;
201	unsigned int surr_switch: 1;
202	unsigned int alt_switch: 1;
203	unsigned int hp_detect: 1;
204	unsigned int spdif_mute: 1;
205	unsigned int check_volume_offset:1;
206	unsigned int auto_mic:1;
207	unsigned int linear_tone_beep:1;
208
209	/* gpio lines */
210	unsigned int eapd_mask;
211	unsigned int gpio_mask;
212	unsigned int gpio_dir;
213	unsigned int gpio_data;
214	unsigned int gpio_mute;
215	unsigned int gpio_led;
216	unsigned int gpio_led_polarity;
217
218	/* stream */
219	unsigned int stream_delay;
220
221	/* analog loopback */
222	struct snd_kcontrol_new *aloopback_ctl;
223	unsigned char aloopback_mask;
224	unsigned char aloopback_shift;
225
226	/* power management */
227	unsigned int num_pwrs;
228	unsigned int *pwr_mapping;
229	hda_nid_t *pwr_nids;
230	hda_nid_t *dac_list;
231
232	/* jack detection */
233	struct snd_array jacks;
234
235	/* events */
236	struct snd_array events;
237
238	/* playback */
239	struct hda_input_mux *mono_mux;
240	unsigned int cur_mmux;
241	struct hda_multi_out multiout;
242	hda_nid_t dac_nids[5];
243	hda_nid_t hp_dacs[5];
244	hda_nid_t speaker_dacs[5];
245
246	int volume_offset;
247
248	/* capture */
249	hda_nid_t *adc_nids;
250	unsigned int num_adcs;
251	hda_nid_t *mux_nids;
252	unsigned int num_muxes;
253	hda_nid_t *dmic_nids;
254	unsigned int num_dmics;
255	hda_nid_t *dmux_nids;
256	unsigned int num_dmuxes;
257	hda_nid_t *smux_nids;
258	unsigned int num_smuxes;
259	unsigned int num_analog_muxes;
260
261	unsigned long *capvols; /* amp-volume attr: HDA_COMPOSE_AMP_VAL() */
262	unsigned long *capsws; /* amp-mute attr: HDA_COMPOSE_AMP_VAL() */
263	unsigned int num_caps; /* number of capture volume/switch elements */
264
265	struct sigmatel_mic_route ext_mic;
266	struct sigmatel_mic_route int_mic;
267
268	const char **spdif_labels;
269
270	hda_nid_t dig_in_nid;
271	hda_nid_t mono_nid;
272	hda_nid_t anabeep_nid;
273	hda_nid_t digbeep_nid;
274
275	/* pin widgets */
276	hda_nid_t *pin_nids;
277	unsigned int num_pins;
278
279	/* codec specific stuff */
280	struct hda_verb *init;
281	struct snd_kcontrol_new *mixer;
282
283	/* capture source */
284	struct hda_input_mux *dinput_mux;
285	unsigned int cur_dmux[2];
286	struct hda_input_mux *input_mux;
287	unsigned int cur_mux[3];
288	struct hda_input_mux *sinput_mux;
289	unsigned int cur_smux[2];
290	unsigned int cur_amux;
291	hda_nid_t *amp_nids;
292	unsigned int powerdown_adcs;
293
294	/* i/o switches */
295	unsigned int io_switch[2];
296	unsigned int clfe_swap;
297	hda_nid_t line_switch;	/* shared line-in for input and output */
298	hda_nid_t mic_switch;	/* shared mic-in for input and output */
299	hda_nid_t hp_switch; /* NID of HP as line-out */
300	unsigned int aloopback;
301
302	struct hda_pcm pcm_rec[2];	/* PCM information */
303
304	/* dynamic controls and input_mux */
305	struct auto_pin_cfg autocfg;
306	struct snd_array kctls;
307	struct hda_input_mux private_dimux;
308	struct hda_input_mux private_imux;
309	struct hda_input_mux private_smux;
310	struct hda_input_mux private_mono_mux;
311};
312
313static hda_nid_t stac9200_adc_nids[1] = {
314        0x03,
315};
316
317static hda_nid_t stac9200_mux_nids[1] = {
318        0x0c,
319};
320
321static hda_nid_t stac9200_dac_nids[1] = {
322        0x02,
323};
324
325static hda_nid_t stac92hd73xx_pwr_nids[8] = {
326	0x0a, 0x0b, 0x0c, 0xd, 0x0e,
327	0x0f, 0x10, 0x11
328};
329
330static hda_nid_t stac92hd73xx_slave_dig_outs[2] = {
331	0x26, 0,
332};
333
334static hda_nid_t stac92hd73xx_adc_nids[2] = {
335	0x1a, 0x1b
336};
337
338#define STAC92HD73XX_NUM_DMICS	2
339static hda_nid_t stac92hd73xx_dmic_nids[STAC92HD73XX_NUM_DMICS + 1] = {
340	0x13, 0x14, 0
341};
342
343#define STAC92HD73_DAC_COUNT 5
344
345static hda_nid_t stac92hd73xx_mux_nids[2] = {
346	0x20, 0x21,
347};
348
349static hda_nid_t stac92hd73xx_dmux_nids[2] = {
350	0x20, 0x21,
351};
352
353static hda_nid_t stac92hd73xx_smux_nids[2] = {
354	0x22, 0x23,
355};
356
357#define STAC92HD73XX_NUM_CAPS	2
358static unsigned long stac92hd73xx_capvols[] = {
359	HDA_COMPOSE_AMP_VAL(0x20, 3, 0, HDA_OUTPUT),
360	HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
361};
362#define stac92hd73xx_capsws	stac92hd73xx_capvols
363
364#define STAC92HD83_DAC_COUNT 3
365
366static hda_nid_t stac92hd83xxx_mux_nids[2] = {
367	0x17, 0x18,
368};
369
370static hda_nid_t stac92hd83xxx_adc_nids[2] = {
371	0x15, 0x16,
372};
373
374static hda_nid_t stac92hd83xxx_pwr_nids[4] = {
375	0xa, 0xb, 0xd, 0xe,
376};
377
378static hda_nid_t stac92hd83xxx_slave_dig_outs[2] = {
379	0x1e, 0,
380};
381
382static unsigned int stac92hd83xxx_pwr_mapping[4] = {
383	0x03, 0x0c, 0x20, 0x40,
384};
385
386#define STAC92HD83XXX_NUM_CAPS	2
387static unsigned long stac92hd83xxx_capvols[] = {
388	HDA_COMPOSE_AMP_VAL(0x17, 3, 0, HDA_OUTPUT),
389	HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_OUTPUT),
390};
391#define stac92hd83xxx_capsws	stac92hd83xxx_capvols
392
393static hda_nid_t stac92hd71bxx_pwr_nids[3] = {
394	0x0a, 0x0d, 0x0f
395};
396
397static hda_nid_t stac92hd71bxx_adc_nids[2] = {
398	0x12, 0x13,
399};
400
401static hda_nid_t stac92hd71bxx_mux_nids[2] = {
402	0x1a, 0x1b
403};
404
405static hda_nid_t stac92hd71bxx_dmux_nids[2] = {
406	0x1c, 0x1d,
407};
408
409static hda_nid_t stac92hd71bxx_smux_nids[2] = {
410	0x24, 0x25,
411};
412
413#define STAC92HD71BXX_NUM_DMICS	2
414static hda_nid_t stac92hd71bxx_dmic_nids[STAC92HD71BXX_NUM_DMICS + 1] = {
415	0x18, 0x19, 0
416};
417
418static hda_nid_t stac92hd71bxx_slave_dig_outs[2] = {
419	0x22, 0
420};
421
422#define STAC92HD71BXX_NUM_CAPS		2
423static unsigned long stac92hd71bxx_capvols[] = {
424	HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_OUTPUT),
425	HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
426};
427#define stac92hd71bxx_capsws	stac92hd71bxx_capvols
428
429static hda_nid_t stac925x_adc_nids[1] = {
430        0x03,
431};
432
433static hda_nid_t stac925x_mux_nids[1] = {
434        0x0f,
435};
436
437static hda_nid_t stac925x_dac_nids[1] = {
438        0x02,
439};
440
441#define STAC925X_NUM_DMICS	1
442static hda_nid_t stac925x_dmic_nids[STAC925X_NUM_DMICS + 1] = {
443	0x15, 0
444};
445
446static hda_nid_t stac925x_dmux_nids[1] = {
447	0x14,
448};
449
450static unsigned long stac925x_capvols[] = {
451	HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_OUTPUT),
452};
453static unsigned long stac925x_capsws[] = {
454	HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
455};
456
457static hda_nid_t stac922x_adc_nids[2] = {
458        0x06, 0x07,
459};
460
461static hda_nid_t stac922x_mux_nids[2] = {
462        0x12, 0x13,
463};
464
465#define STAC922X_NUM_CAPS	2
466static unsigned long stac922x_capvols[] = {
467	HDA_COMPOSE_AMP_VAL(0x17, 3, 0, HDA_INPUT),
468	HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_INPUT),
469};
470#define stac922x_capsws		stac922x_capvols
471
472static hda_nid_t stac927x_slave_dig_outs[2] = {
473	0x1f, 0,
474};
475
476static hda_nid_t stac927x_adc_nids[3] = {
477        0x07, 0x08, 0x09
478};
479
480static hda_nid_t stac927x_mux_nids[3] = {
481        0x15, 0x16, 0x17
482};
483
484static hda_nid_t stac927x_smux_nids[1] = {
485	0x21,
486};
487
488static hda_nid_t stac927x_dac_nids[6] = {
489	0x02, 0x03, 0x04, 0x05, 0x06, 0
490};
491
492static hda_nid_t stac927x_dmux_nids[1] = {
493	0x1b,
494};
495
496#define STAC927X_NUM_DMICS 2
497static hda_nid_t stac927x_dmic_nids[STAC927X_NUM_DMICS + 1] = {
498	0x13, 0x14, 0
499};
500
501#define STAC927X_NUM_CAPS	3
502static unsigned long stac927x_capvols[] = {
503	HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_INPUT),
504	HDA_COMPOSE_AMP_VAL(0x19, 3, 0, HDA_INPUT),
505	HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_INPUT),
506};
507static unsigned long stac927x_capsws[] = {
508	HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
509	HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_OUTPUT),
510	HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
511};
512
513static const char *stac927x_spdif_labels[5] = {
514	"Digital Playback", "ADAT", "Analog Mux 1",
515	"Analog Mux 2", "Analog Mux 3"
516};
517
518static hda_nid_t stac9205_adc_nids[2] = {
519        0x12, 0x13
520};
521
522static hda_nid_t stac9205_mux_nids[2] = {
523        0x19, 0x1a
524};
525
526static hda_nid_t stac9205_dmux_nids[1] = {
527	0x1d,
528};
529
530static hda_nid_t stac9205_smux_nids[1] = {
531	0x21,
532};
533
534#define STAC9205_NUM_DMICS	2
535static hda_nid_t stac9205_dmic_nids[STAC9205_NUM_DMICS + 1] = {
536        0x17, 0x18, 0
537};
538
539#define STAC9205_NUM_CAPS	2
540static unsigned long stac9205_capvols[] = {
541	HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_INPUT),
542	HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_INPUT),
543};
544static unsigned long stac9205_capsws[] = {
545	HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
546	HDA_COMPOSE_AMP_VAL(0x1e, 3, 0, HDA_OUTPUT),
547};
548
549static hda_nid_t stac9200_pin_nids[8] = {
550	0x08, 0x09, 0x0d, 0x0e,
551	0x0f, 0x10, 0x11, 0x12,
552};
553
554static hda_nid_t stac925x_pin_nids[8] = {
555	0x07, 0x08, 0x0a, 0x0b,
556	0x0c, 0x0d, 0x10, 0x11,
557};
558
559static hda_nid_t stac922x_pin_nids[10] = {
560	0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
561	0x0f, 0x10, 0x11, 0x15, 0x1b,
562};
563
564static hda_nid_t stac92hd73xx_pin_nids[13] = {
565	0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
566	0x0f, 0x10, 0x11, 0x12, 0x13,
567	0x14, 0x22, 0x23
568};
569
570static hda_nid_t stac92hd83xxx_pin_nids[10] = {
571	0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
572	0x0f, 0x10, 0x11, 0x1f, 0x20,
573};
574
575static hda_nid_t stac92hd88xxx_pin_nids[10] = {
576	0x0a, 0x0b, 0x0c, 0x0d,
577	0x0f, 0x11, 0x1f, 0x20,
578};
579
580#define STAC92HD71BXX_NUM_PINS 13
581static hda_nid_t stac92hd71bxx_pin_nids_4port[STAC92HD71BXX_NUM_PINS] = {
582	0x0a, 0x0b, 0x0c, 0x0d, 0x00,
583	0x00, 0x14, 0x18, 0x19, 0x1e,
584	0x1f, 0x20, 0x27
585};
586static hda_nid_t stac92hd71bxx_pin_nids_6port[STAC92HD71BXX_NUM_PINS] = {
587	0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
588	0x0f, 0x14, 0x18, 0x19, 0x1e,
589	0x1f, 0x20, 0x27
590};
591
592static hda_nid_t stac927x_pin_nids[14] = {
593	0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
594	0x0f, 0x10, 0x11, 0x12, 0x13,
595	0x14, 0x21, 0x22, 0x23,
596};
597
598static hda_nid_t stac9205_pin_nids[12] = {
599	0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
600	0x0f, 0x14, 0x16, 0x17, 0x18,
601	0x21, 0x22,
602};
603
604static int stac92xx_dmux_enum_info(struct snd_kcontrol *kcontrol,
605				   struct snd_ctl_elem_info *uinfo)
606{
607	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
608	struct sigmatel_spec *spec = codec->spec;
609	return snd_hda_input_mux_info(spec->dinput_mux, uinfo);
610}
611
612static int stac92xx_dmux_enum_get(struct snd_kcontrol *kcontrol,
613				  struct snd_ctl_elem_value *ucontrol)
614{
615	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
616	struct sigmatel_spec *spec = codec->spec;
617	unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
618
619	ucontrol->value.enumerated.item[0] = spec->cur_dmux[dmux_idx];
620	return 0;
621}
622
623static int stac92xx_dmux_enum_put(struct snd_kcontrol *kcontrol,
624				  struct snd_ctl_elem_value *ucontrol)
625{
626	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
627	struct sigmatel_spec *spec = codec->spec;
628	unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
629
630	return snd_hda_input_mux_put(codec, spec->dinput_mux, ucontrol,
631			spec->dmux_nids[dmux_idx], &spec->cur_dmux[dmux_idx]);
632}
633
634static int stac92xx_smux_enum_info(struct snd_kcontrol *kcontrol,
635				   struct snd_ctl_elem_info *uinfo)
636{
637	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
638	struct sigmatel_spec *spec = codec->spec;
639	return snd_hda_input_mux_info(spec->sinput_mux, uinfo);
640}
641
642static int stac92xx_smux_enum_get(struct snd_kcontrol *kcontrol,
643				  struct snd_ctl_elem_value *ucontrol)
644{
645	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
646	struct sigmatel_spec *spec = codec->spec;
647	unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
648
649	ucontrol->value.enumerated.item[0] = spec->cur_smux[smux_idx];
650	return 0;
651}
652
653static int stac92xx_smux_enum_put(struct snd_kcontrol *kcontrol,
654				  struct snd_ctl_elem_value *ucontrol)
655{
656	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
657	struct sigmatel_spec *spec = codec->spec;
658	struct hda_input_mux *smux = &spec->private_smux;
659	unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
660	int err, val;
661	hda_nid_t nid;
662
663	err = snd_hda_input_mux_put(codec, spec->sinput_mux, ucontrol,
664			spec->smux_nids[smux_idx], &spec->cur_smux[smux_idx]);
665	if (err < 0)
666		return err;
667
668	if (spec->spdif_mute) {
669		if (smux_idx == 0)
670			nid = spec->multiout.dig_out_nid;
671		else
672			nid = codec->slave_dig_outs[smux_idx - 1];
673		if (spec->cur_smux[smux_idx] == smux->num_items - 1)
674			val = HDA_AMP_MUTE;
675		else
676			val = 0;
677		/* un/mute SPDIF out */
678		snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
679					 HDA_AMP_MUTE, val);
680	}
681	return 0;
682}
683
684static unsigned int stac92xx_vref_set(struct hda_codec *codec,
685					hda_nid_t nid, unsigned int new_vref)
686{
687	int error;
688	unsigned int pincfg;
689	pincfg = snd_hda_codec_read(codec, nid, 0,
690				AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
691
692	pincfg &= 0xff;
693	pincfg &= ~(AC_PINCTL_VREFEN | AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
694	pincfg |= new_vref;
695
696	if (new_vref == AC_PINCTL_VREF_HIZ)
697		pincfg |= AC_PINCTL_OUT_EN;
698	else
699		pincfg |= AC_PINCTL_IN_EN;
700
701	error = snd_hda_codec_write_cache(codec, nid, 0,
702					AC_VERB_SET_PIN_WIDGET_CONTROL, pincfg);
703	if (error < 0)
704		return error;
705	else
706		return 1;
707}
708
709static unsigned int stac92xx_vref_get(struct hda_codec *codec, hda_nid_t nid)
710{
711	unsigned int vref;
712	vref = snd_hda_codec_read(codec, nid, 0,
713				AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
714	vref &= AC_PINCTL_VREFEN;
715	return vref;
716}
717
718static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
719{
720	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
721	struct sigmatel_spec *spec = codec->spec;
722	return snd_hda_input_mux_info(spec->input_mux, uinfo);
723}
724
725static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
726{
727	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
728	struct sigmatel_spec *spec = codec->spec;
729	unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
730
731	ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
732	return 0;
733}
734
735static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
736{
737	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
738	struct sigmatel_spec *spec = codec->spec;
739	unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
740	const struct hda_input_mux *imux = spec->input_mux;
741	unsigned int idx, prev_idx;
742
743	idx = ucontrol->value.enumerated.item[0];
744	if (idx >= imux->num_items)
745		idx = imux->num_items - 1;
746	prev_idx = spec->cur_mux[adc_idx];
747	if (prev_idx == idx)
748		return 0;
749	if (idx < spec->num_analog_muxes) {
750		snd_hda_codec_write_cache(codec, spec->mux_nids[adc_idx], 0,
751					  AC_VERB_SET_CONNECT_SEL,
752					  imux->items[idx].index);
753		if (prev_idx >= spec->num_analog_muxes) {
754			imux = spec->dinput_mux;
755			/* 0 = analog */
756			snd_hda_codec_write_cache(codec,
757						  spec->dmux_nids[adc_idx], 0,
758						  AC_VERB_SET_CONNECT_SEL,
759						  imux->items[0].index);
760		}
761	} else {
762		imux = spec->dinput_mux;
763		snd_hda_codec_write_cache(codec, spec->dmux_nids[adc_idx], 0,
764					  AC_VERB_SET_CONNECT_SEL,
765					  imux->items[idx - 1].index);
766	}
767	spec->cur_mux[adc_idx] = idx;
768	return 1;
769}
770
771static int stac92xx_mono_mux_enum_info(struct snd_kcontrol *kcontrol,
772	struct snd_ctl_elem_info *uinfo)
773{
774	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
775	struct sigmatel_spec *spec = codec->spec;
776	return snd_hda_input_mux_info(spec->mono_mux, uinfo);
777}
778
779static int stac92xx_mono_mux_enum_get(struct snd_kcontrol *kcontrol,
780	struct snd_ctl_elem_value *ucontrol)
781{
782	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
783	struct sigmatel_spec *spec = codec->spec;
784
785	ucontrol->value.enumerated.item[0] = spec->cur_mmux;
786	return 0;
787}
788
789static int stac92xx_mono_mux_enum_put(struct snd_kcontrol *kcontrol,
790	struct snd_ctl_elem_value *ucontrol)
791{
792	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
793	struct sigmatel_spec *spec = codec->spec;
794
795	return snd_hda_input_mux_put(codec, spec->mono_mux, ucontrol,
796				     spec->mono_nid, &spec->cur_mmux);
797}
798
799#define stac92xx_aloopback_info snd_ctl_boolean_mono_info
800
801static int stac92xx_aloopback_get(struct snd_kcontrol *kcontrol,
802	struct snd_ctl_elem_value *ucontrol)
803{
804	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
805	unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
806	struct sigmatel_spec *spec = codec->spec;
807
808	ucontrol->value.integer.value[0] = !!(spec->aloopback &
809					      (spec->aloopback_mask << idx));
810	return 0;
811}
812
813static int stac92xx_aloopback_put(struct snd_kcontrol *kcontrol,
814		struct snd_ctl_elem_value *ucontrol)
815{
816	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
817	struct sigmatel_spec *spec = codec->spec;
818	unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
819	unsigned int dac_mode;
820	unsigned int val, idx_val;
821
822	idx_val = spec->aloopback_mask << idx;
823	if (ucontrol->value.integer.value[0])
824		val = spec->aloopback | idx_val;
825	else
826		val = spec->aloopback & ~idx_val;
827	if (spec->aloopback == val)
828		return 0;
829
830	spec->aloopback = val;
831
832	/* Only return the bits defined by the shift value of the
833	 * first two bytes of the mask
834	 */
835	dac_mode = snd_hda_codec_read(codec, codec->afg, 0,
836				      kcontrol->private_value & 0xFFFF, 0x0);
837	dac_mode >>= spec->aloopback_shift;
838
839	if (spec->aloopback & idx_val) {
840		snd_hda_power_up(codec);
841		dac_mode |= idx_val;
842	} else {
843		snd_hda_power_down(codec);
844		dac_mode &= ~idx_val;
845	}
846
847	snd_hda_codec_write_cache(codec, codec->afg, 0,
848		kcontrol->private_value >> 16, dac_mode);
849
850	return 1;
851}
852
853static struct hda_verb stac9200_core_init[] = {
854	/* set dac0mux for dac converter */
855	{ 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
856	{}
857};
858
859static struct hda_verb stac9200_eapd_init[] = {
860	/* set dac0mux for dac converter */
861	{0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
862	{0x08, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
863	{}
864};
865
866static struct hda_verb dell_eq_core_init[] = {
867	/* set master volume to max value without distortion
868	 * and direct control */
869	{ 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xec},
870	{}
871};
872
873static struct hda_verb stac92hd73xx_core_init[] = {
874	/* set master volume and direct control */
875	{ 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
876	{}
877};
878
879static struct hda_verb stac92hd83xxx_core_init[] = {
880	/* power state controls amps */
881	{ 0x01, AC_VERB_SET_EAPD, 1 << 2},
882	{}
883};
884
885static struct hda_verb stac92hd71bxx_core_init[] = {
886	/* set master volume and direct control */
887	{ 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
888	{}
889};
890
891static struct hda_verb stac92hd71bxx_unmute_core_init[] = {
892	/* unmute right and left channels for nodes 0x0f, 0xa, 0x0d */
893	{ 0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
894	{ 0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
895	{ 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
896	{}
897};
898
899static struct hda_verb stac925x_core_init[] = {
900	/* set dac0mux for dac converter */
901	{ 0x06, AC_VERB_SET_CONNECT_SEL, 0x00},
902	/* mute the master volume */
903	{ 0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
904	{}
905};
906
907static struct hda_verb stac922x_core_init[] = {
908	/* set master volume and direct control */
909	{ 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
910	{}
911};
912
913static struct hda_verb d965_core_init[] = {
914	/* set master volume and direct control */
915	{ 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
916	/* unmute node 0x1b */
917	{ 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
918	/* select node 0x03 as DAC */
919	{ 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
920	{}
921};
922
923static struct hda_verb dell_3st_core_init[] = {
924	/* don't set delta bit */
925	{0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0x7f},
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 stac927x_volknob_core_init[] = {
942	/* don't set delta bit */
943	{0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0x7f},
944	/* enable analog pc beep path */
945	{0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
946	{}
947};
948
949static struct hda_verb stac9205_core_init[] = {
950	/* set master volume and direct control */
951	{ 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
952	/* enable analog pc beep path */
953	{ 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
954	{}
955};
956
957#define STAC_MONO_MUX \
958	{ \
959		.iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
960		.name = "Mono Mux", \
961		.count = 1, \
962		.info = stac92xx_mono_mux_enum_info, \
963		.get = stac92xx_mono_mux_enum_get, \
964		.put = stac92xx_mono_mux_enum_put, \
965	}
966
967#define STAC_ANALOG_LOOPBACK(verb_read, verb_write, cnt) \
968	{ \
969		.iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
970		.name  = "Analog Loopback", \
971		.count = cnt, \
972		.info  = stac92xx_aloopback_info, \
973		.get   = stac92xx_aloopback_get, \
974		.put   = stac92xx_aloopback_put, \
975		.private_value = verb_read | (verb_write << 16), \
976	}
977
978#define DC_BIAS(xname, idx, nid) \
979	{ \
980		.iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
981		.name = xname, \
982		.index = idx, \
983		.info = stac92xx_dc_bias_info, \
984		.get = stac92xx_dc_bias_get, \
985		.put = stac92xx_dc_bias_put, \
986		.private_value = nid, \
987	}
988
989static struct snd_kcontrol_new stac9200_mixer[] = {
990	HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
991	HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
992	HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
993	HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
994	{ } /* end */
995};
996
997static struct snd_kcontrol_new stac92hd73xx_6ch_loopback[] = {
998	STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 3),
999	{}
1000};
1001
1002static struct snd_kcontrol_new stac92hd73xx_8ch_loopback[] = {
1003	STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 4),
1004	{}
1005};
1006
1007static struct snd_kcontrol_new stac92hd73xx_10ch_loopback[] = {
1008	STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 5),
1009	{}
1010};
1011
1012
1013static struct snd_kcontrol_new stac92hd71bxx_loopback[] = {
1014	STAC_ANALOG_LOOPBACK(0xFA0, 0x7A0, 2)
1015};
1016
1017static struct snd_kcontrol_new stac925x_mixer[] = {
1018	HDA_CODEC_VOLUME("Master Playback Volume", 0x0e, 0, HDA_OUTPUT),
1019	HDA_CODEC_MUTE("Master Playback Switch", 0x0e, 0, HDA_OUTPUT),
1020	{ } /* end */
1021};
1022
1023static struct snd_kcontrol_new stac9205_loopback[] = {
1024	STAC_ANALOG_LOOPBACK(0xFE0, 0x7E0, 1),
1025	{}
1026};
1027
1028static struct snd_kcontrol_new stac927x_loopback[] = {
1029	STAC_ANALOG_LOOPBACK(0xFEB, 0x7EB, 1),
1030	{}
1031};
1032
1033static struct snd_kcontrol_new stac_dmux_mixer = {
1034	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1035	.name = "Digital Input Source",
1036	/* count set later */
1037	.info = stac92xx_dmux_enum_info,
1038	.get = stac92xx_dmux_enum_get,
1039	.put = stac92xx_dmux_enum_put,
1040};
1041
1042static struct snd_kcontrol_new stac_smux_mixer = {
1043	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1044	.name = "IEC958 Playback Source",
1045	/* count set later */
1046	.info = stac92xx_smux_enum_info,
1047	.get = stac92xx_smux_enum_get,
1048	.put = stac92xx_smux_enum_put,
1049};
1050
1051static const char *slave_vols[] = {
1052	"Front Playback Volume",
1053	"Surround Playback Volume",
1054	"Center Playback Volume",
1055	"LFE Playback Volume",
1056	"Side Playback Volume",
1057	"Headphone Playback Volume",
1058	"Speaker Playback Volume",
1059	NULL
1060};
1061
1062static const char *slave_sws[] = {
1063	"Front Playback Switch",
1064	"Surround Playback Switch",
1065	"Center Playback Switch",
1066	"LFE Playback Switch",
1067	"Side Playback Switch",
1068	"Headphone Playback Switch",
1069	"Speaker Playback Switch",
1070	"IEC958 Playback Switch",
1071	NULL
1072};
1073
1074static void stac92xx_free_kctls(struct hda_codec *codec);
1075static int stac92xx_add_jack(struct hda_codec *codec, hda_nid_t nid, int type);
1076
1077static int stac92xx_build_controls(struct hda_codec *codec)
1078{
1079	struct sigmatel_spec *spec = codec->spec;
1080	struct auto_pin_cfg *cfg = &spec->autocfg;
1081	hda_nid_t nid;
1082	int err;
1083	int i;
1084
1085	if (spec->mixer) {
1086		err = snd_hda_add_new_ctls(codec, spec->mixer);
1087		if (err < 0)
1088			return err;
1089	}
1090
1091	for (i = 0; i < spec->num_mixers; i++) {
1092		err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1093		if (err < 0)
1094			return err;
1095	}
1096	if (!spec->auto_mic && spec->num_dmuxes > 0 &&
1097	    snd_hda_get_bool_hint(codec, "separate_dmux") == 1) {
1098		stac_dmux_mixer.count = spec->num_dmuxes;
1099		err = snd_hda_ctl_add(codec, 0,
1100				  snd_ctl_new1(&stac_dmux_mixer, codec));
1101		if (err < 0)
1102			return err;
1103	}
1104	if (spec->num_smuxes > 0) {
1105		int wcaps = get_wcaps(codec, spec->multiout.dig_out_nid);
1106		struct hda_input_mux *smux = &spec->private_smux;
1107		/* check for mute support on SPDIF out */
1108		if (wcaps & AC_WCAP_OUT_AMP) {
1109			smux->items[smux->num_items].label = "Off";
1110			smux->items[smux->num_items].index = 0;
1111			smux->num_items++;
1112			spec->spdif_mute = 1;
1113		}
1114		stac_smux_mixer.count = spec->num_smuxes;
1115		err = snd_hda_ctl_add(codec, 0,
1116				  snd_ctl_new1(&stac_smux_mixer, codec));
1117		if (err < 0)
1118			return err;
1119	}
1120
1121	if (spec->multiout.dig_out_nid) {
1122		err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
1123		if (err < 0)
1124			return err;
1125		err = snd_hda_create_spdif_share_sw(codec,
1126						    &spec->multiout);
1127		if (err < 0)
1128			return err;
1129		spec->multiout.share_spdif = 1;
1130	}
1131	if (spec->dig_in_nid && !(spec->gpio_dir & 0x01)) {
1132		err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1133		if (err < 0)
1134			return err;
1135	}
1136
1137	/* if we have no master control, let's create it */
1138	if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
1139		unsigned int vmaster_tlv[4];
1140		snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0],
1141					HDA_OUTPUT, vmaster_tlv);
1142		/* correct volume offset */
1143		vmaster_tlv[2] += vmaster_tlv[3] * spec->volume_offset;
1144		err = snd_hda_add_vmaster(codec, "Master Playback Volume",
1145					  vmaster_tlv, slave_vols);
1146		if (err < 0)
1147			return err;
1148	}
1149	if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1150		err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1151					  NULL, slave_sws);
1152		if (err < 0)
1153			return err;
1154	}
1155
1156	if (spec->aloopback_ctl &&
1157	    snd_hda_get_bool_hint(codec, "loopback") == 1) {
1158		err = snd_hda_add_new_ctls(codec, spec->aloopback_ctl);
1159		if (err < 0)
1160			return err;
1161	}
1162
1163	stac92xx_free_kctls(codec); /* no longer needed */
1164
1165	/* create jack input elements */
1166	if (spec->hp_detect) {
1167		for (i = 0; i < cfg->hp_outs; i++) {
1168			int type = SND_JACK_HEADPHONE;
1169			nid = cfg->hp_pins[i];
1170			/* jack detection */
1171			if (cfg->hp_outs == i)
1172				type |= SND_JACK_LINEOUT;
1173			err = stac92xx_add_jack(codec, nid, type);
1174			if (err < 0)
1175				return err;
1176		}
1177	}
1178	for (i = 0; i < cfg->line_outs; i++) {
1179		err = stac92xx_add_jack(codec, cfg->line_out_pins[i],
1180					SND_JACK_LINEOUT);
1181		if (err < 0)
1182			return err;
1183	}
1184	for (i = 0; i < AUTO_PIN_LAST; i++) {
1185		nid = cfg->input_pins[i];
1186		if (nid) {
1187			err = stac92xx_add_jack(codec, nid,
1188						SND_JACK_MICROPHONE);
1189			if (err < 0)
1190				return err;
1191		}
1192	}
1193
1194	return 0;
1195}
1196
1197static unsigned int ref9200_pin_configs[8] = {
1198	0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
1199	0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
1200};
1201
1202static unsigned int gateway9200_m4_pin_configs[8] = {
1203	0x400000fe, 0x404500f4, 0x400100f0, 0x90110010,
1204	0x400100f1, 0x02a1902e, 0x500000f2, 0x500000f3,
1205};
1206static unsigned int gateway9200_m4_2_pin_configs[8] = {
1207	0x400000fe, 0x404500f4, 0x400100f0, 0x90110010,
1208	0x400100f1, 0x02a1902e, 0x500000f2, 0x500000f3,
1209};
1210
1211/*
1212    STAC 9200 pin configs for
1213    102801A8
1214    102801DE
1215    102801E8
1216*/
1217static unsigned int dell9200_d21_pin_configs[8] = {
1218	0x400001f0, 0x400001f1, 0x02214030, 0x01014010,
1219	0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
1220};
1221
1222/*
1223    STAC 9200 pin configs for
1224    102801C0
1225    102801C1
1226*/
1227static unsigned int dell9200_d22_pin_configs[8] = {
1228	0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
1229	0x01813020, 0x02a19021, 0x90100140, 0x400001f2,
1230};
1231
1232/*
1233    STAC 9200 pin configs for
1234    102801C4 (Dell Dimension E310)
1235    102801C5
1236    102801C7
1237    102801D9
1238    102801DA
1239    102801E3
1240*/
1241static unsigned int dell9200_d23_pin_configs[8] = {
1242	0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
1243	0x01813020, 0x01a19021, 0x90100140, 0x400001f2,
1244};
1245
1246
1247/*
1248    STAC 9200-32 pin configs for
1249    102801B5 (Dell Inspiron 630m)
1250    102801D8 (Dell Inspiron 640m)
1251*/
1252static unsigned int dell9200_m21_pin_configs[8] = {
1253	0x40c003fa, 0x03441340, 0x0321121f, 0x90170310,
1254	0x408003fb, 0x03a11020, 0x401003fc, 0x403003fd,
1255};
1256
1257/*
1258    STAC 9200-32 pin configs for
1259    102801C2 (Dell Latitude D620)
1260    102801C8
1261    102801CC (Dell Latitude D820)
1262    102801D4
1263    102801D6
1264*/
1265static unsigned int dell9200_m22_pin_configs[8] = {
1266	0x40c003fa, 0x0144131f, 0x0321121f, 0x90170310,
1267	0x90a70321, 0x03a11020, 0x401003fb, 0x40f000fc,
1268};
1269
1270/*
1271    STAC 9200-32 pin configs for
1272    102801CE (Dell XPS M1710)
1273    102801CF (Dell Precision M90)
1274*/
1275static unsigned int dell9200_m23_pin_configs[8] = {
1276	0x40c003fa, 0x01441340, 0x0421421f, 0x90170310,
1277	0x408003fb, 0x04a1102e, 0x90170311, 0x403003fc,
1278};
1279
1280/*
1281    STAC 9200-32 pin configs for
1282    102801C9
1283    102801CA
1284    102801CB (Dell Latitude 120L)
1285    102801D3
1286*/
1287static unsigned int dell9200_m24_pin_configs[8] = {
1288	0x40c003fa, 0x404003fb, 0x0321121f, 0x90170310,
1289	0x408003fc, 0x03a11020, 0x401003fd, 0x403003fe,
1290};
1291
1292/*
1293    STAC 9200-32 pin configs for
1294    102801BD (Dell Inspiron E1505n)
1295    102801EE
1296    102801EF
1297*/
1298static unsigned int dell9200_m25_pin_configs[8] = {
1299	0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
1300	0x408003fb, 0x04a11020, 0x401003fc, 0x403003fd,
1301};
1302
1303/*
1304    STAC 9200-32 pin configs for
1305    102801F5 (Dell Inspiron 1501)
1306    102801F6
1307*/
1308static unsigned int dell9200_m26_pin_configs[8] = {
1309	0x40c003fa, 0x404003fb, 0x0421121f, 0x90170310,
1310	0x408003fc, 0x04a11020, 0x401003fd, 0x403003fe,
1311};
1312
1313/*
1314    STAC 9200-32
1315    102801CD (Dell Inspiron E1705/9400)
1316*/
1317static unsigned int dell9200_m27_pin_configs[8] = {
1318	0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
1319	0x90170310, 0x04a11020, 0x90170310, 0x40f003fc,
1320};
1321
1322static unsigned int oqo9200_pin_configs[8] = {
1323	0x40c000f0, 0x404000f1, 0x0221121f, 0x02211210,
1324	0x90170111, 0x90a70120, 0x400000f2, 0x400000f3,
1325};
1326
1327
1328static unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
1329	[STAC_REF] = ref9200_pin_configs,
1330	[STAC_9200_OQO] = oqo9200_pin_configs,
1331	[STAC_9200_DELL_D21] = dell9200_d21_pin_configs,
1332	[STAC_9200_DELL_D22] = dell9200_d22_pin_configs,
1333	[STAC_9200_DELL_D23] = dell9200_d23_pin_configs,
1334	[STAC_9200_DELL_M21] = dell9200_m21_pin_configs,
1335	[STAC_9200_DELL_M22] = dell9200_m22_pin_configs,
1336	[STAC_9200_DELL_M23] = dell9200_m23_pin_configs,
1337	[STAC_9200_DELL_M24] = dell9200_m24_pin_configs,
1338	[STAC_9200_DELL_M25] = dell9200_m25_pin_configs,
1339	[STAC_9200_DELL_M26] = dell9200_m26_pin_configs,
1340	[STAC_9200_DELL_M27] = dell9200_m27_pin_configs,
1341	[STAC_9200_M4] = gateway9200_m4_pin_configs,
1342	[STAC_9200_M4_2] = gateway9200_m4_2_pin_configs,
1343	[STAC_9200_PANASONIC] = ref9200_pin_configs,
1344};
1345
1346static const char *stac9200_models[STAC_9200_MODELS] = {
1347	[STAC_AUTO] = "auto",
1348	[STAC_REF] = "ref",
1349	[STAC_9200_OQO] = "oqo",
1350	[STAC_9200_DELL_D21] = "dell-d21",
1351	[STAC_9200_DELL_D22] = "dell-d22",
1352	[STAC_9200_DELL_D23] = "dell-d23",
1353	[STAC_9200_DELL_M21] = "dell-m21",
1354	[STAC_9200_DELL_M22] = "dell-m22",
1355	[STAC_9200_DELL_M23] = "dell-m23",
1356	[STAC_9200_DELL_M24] = "dell-m24",
1357	[STAC_9200_DELL_M25] = "dell-m25",
1358	[STAC_9200_DELL_M26] = "dell-m26",
1359	[STAC_9200_DELL_M27] = "dell-m27",
1360	[STAC_9200_M4] = "gateway-m4",
1361	[STAC_9200_M4_2] = "gateway-m4-2",
1362	[STAC_9200_PANASONIC] = "panasonic",
1363};
1364
1365static struct snd_pci_quirk stac9200_cfg_tbl[] = {
1366	/* SigmaTel reference board */
1367	SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1368		      "DFI LanParty", STAC_REF),
1369	SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1370		      "DFI LanParty", STAC_REF),
1371	/* Dell laptops have BIOS problem */
1372	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a8,
1373		      "unknown Dell", STAC_9200_DELL_D21),
1374	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01b5,
1375		      "Dell Inspiron 630m", STAC_9200_DELL_M21),
1376	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bd,
1377		      "Dell Inspiron E1505n", STAC_9200_DELL_M25),
1378	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c0,
1379		      "unknown Dell", STAC_9200_DELL_D22),
1380	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c1,
1381		      "unknown Dell", STAC_9200_DELL_D22),
1382	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c2,
1383		      "Dell Latitude D620", STAC_9200_DELL_M22),
1384	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c5,
1385		      "unknown Dell", STAC_9200_DELL_D23),
1386	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c7,
1387		      "unknown Dell", STAC_9200_DELL_D23),
1388	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c8,
1389		      "unknown Dell", STAC_9200_DELL_M22),
1390	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c9,
1391		      "unknown Dell", STAC_9200_DELL_M24),
1392	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ca,
1393		      "unknown Dell", STAC_9200_DELL_M24),
1394	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cb,
1395		      "Dell Latitude 120L", STAC_9200_DELL_M24),
1396	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cc,
1397		      "Dell Latitude D820", STAC_9200_DELL_M22),
1398	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cd,
1399		      "Dell Inspiron E1705/9400", STAC_9200_DELL_M27),
1400	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ce,
1401		      "Dell XPS M1710", STAC_9200_DELL_M23),
1402	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cf,
1403		      "Dell Precision M90", STAC_9200_DELL_M23),
1404	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d3,
1405		      "unknown Dell", STAC_9200_DELL_M22),
1406	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d4,
1407		      "unknown Dell", STAC_9200_DELL_M22),
1408	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d6,
1409		      "unknown Dell", STAC_9200_DELL_M22),
1410	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d8,
1411		      "Dell Inspiron 640m", STAC_9200_DELL_M21),
1412	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d9,
1413		      "unknown Dell", STAC_9200_DELL_D23),
1414	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01da,
1415		      "unknown Dell", STAC_9200_DELL_D23),
1416	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01de,
1417		      "unknown Dell", STAC_9200_DELL_D21),
1418	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e3,
1419		      "unknown Dell", STAC_9200_DELL_D23),
1420	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e8,
1421		      "unknown Dell", STAC_9200_DELL_D21),
1422	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ee,
1423		      "unknown Dell", STAC_9200_DELL_M25),
1424	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ef,
1425		      "unknown Dell", STAC_9200_DELL_M25),
1426	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f5,
1427		      "Dell Inspiron 1501", STAC_9200_DELL_M26),
1428	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f6,
1429		      "unknown Dell", STAC_9200_DELL_M26),
1430	/* Panasonic */
1431	SND_PCI_QUIRK(0x10f7, 0x8338, "Panasonic CF-74", STAC_9200_PANASONIC),
1432	/* Gateway machines needs EAPD to be set on resume */
1433	SND_PCI_QUIRK(0x107b, 0x0205, "Gateway S-7110M", STAC_9200_M4),
1434	SND_PCI_QUIRK(0x107b, 0x0317, "Gateway MT3423, MX341*", STAC_9200_M4_2),
1435	SND_PCI_QUIRK(0x107b, 0x0318, "Gateway ML3019, MT3707", STAC_9200_M4_2),
1436	/* OQO Mobile */
1437	SND_PCI_QUIRK(0x1106, 0x3288, "OQO Model 2", STAC_9200_OQO),
1438	{} /* terminator */
1439};
1440
1441static unsigned int ref925x_pin_configs[8] = {
1442	0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
1443	0x90a70320, 0x02214210, 0x01019020, 0x9033032e,
1444};
1445
1446static unsigned int stac925xM1_pin_configs[8] = {
1447	0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1448	0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1449};
1450
1451static unsigned int stac925xM1_2_pin_configs[8] = {
1452	0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1453	0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1454};
1455
1456static unsigned int stac925xM2_pin_configs[8] = {
1457	0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1458	0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1459};
1460
1461static unsigned int stac925xM2_2_pin_configs[8] = {
1462	0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1463	0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1464};
1465
1466static unsigned int stac925xM3_pin_configs[8] = {
1467	0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1468	0x40a000f0, 0x90100210, 0x400003f1, 0x503303f3,
1469};
1470
1471static unsigned int stac925xM5_pin_configs[8] = {
1472	0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1473	0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1474};
1475
1476static unsigned int stac925xM6_pin_configs[8] = {
1477	0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1478	0x40a000f0, 0x90100210, 0x400003f1, 0x90330320,
1479};
1480
1481static unsigned int *stac925x_brd_tbl[STAC_925x_MODELS] = {
1482	[STAC_REF] = ref925x_pin_configs,
1483	[STAC_M1] = stac925xM1_pin_configs,
1484	[STAC_M1_2] = stac925xM1_2_pin_configs,
1485	[STAC_M2] = stac925xM2_pin_configs,
1486	[STAC_M2_2] = stac925xM2_2_pin_configs,
1487	[STAC_M3] = stac925xM3_pin_configs,
1488	[STAC_M5] = stac925xM5_pin_configs,
1489	[STAC_M6] = stac925xM6_pin_configs,
1490};
1491
1492static const char *stac925x_models[STAC_925x_MODELS] = {
1493	[STAC_925x_AUTO] = "auto",
1494	[STAC_REF] = "ref",
1495	[STAC_M1] = "m1",
1496	[STAC_M1_2] = "m1-2",
1497	[STAC_M2] = "m2",
1498	[STAC_M2_2] = "m2-2",
1499	[STAC_M3] = "m3",
1500	[STAC_M5] = "m5",
1501	[STAC_M6] = "m6",
1502};
1503
1504static struct snd_pci_quirk stac925x_codec_id_cfg_tbl[] = {
1505	SND_PCI_QUIRK(0x107b, 0x0316, "Gateway M255", STAC_M2),
1506	SND_PCI_QUIRK(0x107b, 0x0366, "Gateway MP6954", STAC_M5),
1507	SND_PCI_QUIRK(0x107b, 0x0461, "Gateway NX560XL", STAC_M1),
1508	SND_PCI_QUIRK(0x107b, 0x0681, "Gateway NX860", STAC_M2),
1509	SND_PCI_QUIRK(0x107b, 0x0367, "Gateway MX6453", STAC_M1_2),
1510	/* Not sure about the brand name for those */
1511	SND_PCI_QUIRK(0x107b, 0x0281, "Gateway mobile", STAC_M1),
1512	SND_PCI_QUIRK(0x107b, 0x0507, "Gateway mobile", STAC_M3),
1513	SND_PCI_QUIRK(0x107b, 0x0281, "Gateway mobile", STAC_M6),
1514	SND_PCI_QUIRK(0x107b, 0x0685, "Gateway mobile", STAC_M2_2),
1515	{} /* terminator */
1516};
1517
1518static struct snd_pci_quirk stac925x_cfg_tbl[] = {
1519	/* SigmaTel reference board */
1520	SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, "DFI LanParty", STAC_REF),
1521	SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101, "DFI LanParty", STAC_REF),
1522	SND_PCI_QUIRK(0x8384, 0x7632, "Stac9202 Reference Board", STAC_REF),
1523
1524	/* Default table for unknown ID */
1525	SND_PCI_QUIRK(0x1002, 0x437b, "Gateway mobile", STAC_M2_2),
1526
1527	{} /* terminator */
1528};
1529
1530static unsigned int ref92hd73xx_pin_configs[13] = {
1531	0x02214030, 0x02a19040, 0x01a19020, 0x02214030,
1532	0x0181302e, 0x01014010, 0x01014020, 0x01014030,
1533	0x02319040, 0x90a000f0, 0x90a000f0, 0x01452050,
1534	0x01452050,
1535};
1536
1537static unsigned int dell_m6_pin_configs[13] = {
1538	0x0321101f, 0x4f00000f, 0x4f0000f0, 0x90170110,
1539	0x03a11020, 0x0321101f, 0x4f0000f0, 0x4f0000f0,
1540	0x4f0000f0, 0x90a60160, 0x4f0000f0, 0x4f0000f0,
1541	0x4f0000f0,
1542};
1543
1544static unsigned int alienware_m17x_pin_configs[13] = {
1545	0x0321101f, 0x0321101f, 0x03a11020, 0x03014020,
1546	0x90170110, 0x4f0000f0, 0x4f0000f0, 0x4f0000f0,
1547	0x4f0000f0, 0x90a60160, 0x4f0000f0, 0x4f0000f0,
1548	0x904601b0,
1549};
1550
1551static unsigned int intel_dg45id_pin_configs[13] = {
1552	0x02214230, 0x02A19240, 0x01013214, 0x01014210,
1553	0x01A19250, 0x01011212, 0x01016211
1554};
1555
1556static unsigned int *stac92hd73xx_brd_tbl[STAC_92HD73XX_MODELS] = {
1557	[STAC_92HD73XX_REF]	= ref92hd73xx_pin_configs,
1558	[STAC_DELL_M6_AMIC]	= dell_m6_pin_configs,
1559	[STAC_DELL_M6_DMIC]	= dell_m6_pin_configs,
1560	[STAC_DELL_M6_BOTH]	= dell_m6_pin_configs,
1561	[STAC_DELL_EQ]	= dell_m6_pin_configs,
1562	[STAC_ALIENWARE_M17X]	= alienware_m17x_pin_configs,
1563	[STAC_92HD73XX_INTEL]	= intel_dg45id_pin_configs,
1564};
1565
1566static const char *stac92hd73xx_models[STAC_92HD73XX_MODELS] = {
1567	[STAC_92HD73XX_AUTO] = "auto",
1568	[STAC_92HD73XX_NO_JD] = "no-jd",
1569	[STAC_92HD73XX_REF] = "ref",
1570	[STAC_92HD73XX_INTEL] = "intel",
1571	[STAC_DELL_M6_AMIC] = "dell-m6-amic",
1572	[STAC_DELL_M6_DMIC] = "dell-m6-dmic",
1573	[STAC_DELL_M6_BOTH] = "dell-m6",
1574	[STAC_DELL_EQ] = "dell-eq",
1575	[STAC_ALIENWARE_M17X] = "alienware",
1576};
1577
1578static struct snd_pci_quirk stac92hd73xx_cfg_tbl[] = {
1579	/* SigmaTel reference board */
1580	SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1581				"DFI LanParty", STAC_92HD73XX_REF),
1582	SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1583				"DFI LanParty", STAC_92HD73XX_REF),
1584	SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5002,
1585				"Intel DG45ID", STAC_92HD73XX_INTEL),
1586	SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5003,
1587				"Intel DG45FC", STAC_92HD73XX_INTEL),
1588	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0254,
1589				"Dell Studio 1535", STAC_DELL_M6_DMIC),
1590	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0255,
1591				"unknown Dell", STAC_DELL_M6_DMIC),
1592	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0256,
1593				"unknown Dell", STAC_DELL_M6_BOTH),
1594	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0257,
1595				"unknown Dell", STAC_DELL_M6_BOTH),
1596	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025e,
1597				"unknown Dell", STAC_DELL_M6_AMIC),
1598	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025f,
1599				"unknown Dell", STAC_DELL_M6_AMIC),
1600	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0271,
1601				"unknown Dell", STAC_DELL_M6_DMIC),
1602	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0272,
1603				"unknown Dell", STAC_DELL_M6_DMIC),
1604	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x029f,
1605				"Dell Studio 1537", STAC_DELL_M6_DMIC),
1606	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02a0,
1607				"Dell Studio 17", STAC_DELL_M6_DMIC),
1608	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02be,
1609				"Dell Studio 1555", STAC_DELL_M6_DMIC),
1610	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02bd,
1611				"Dell Studio 1557", STAC_DELL_M6_DMIC),
1612	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02fe,
1613				"Dell Studio XPS 1645", STAC_DELL_M6_BOTH),
1614	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0413,
1615				"Dell Studio 1558", STAC_DELL_M6_BOTH),
1616	{} /* terminator */
1617};
1618
1619static struct snd_pci_quirk stac92hd73xx_codec_id_cfg_tbl[] = {
1620	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02a1,
1621		      "Alienware M17x", STAC_ALIENWARE_M17X),
1622	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x043a,
1623		      "Alienware M17x", STAC_ALIENWARE_M17X),
1624	{} /* terminator */
1625};
1626
1627static unsigned int ref92hd83xxx_pin_configs[10] = {
1628	0x02214030, 0x02211010, 0x02a19020, 0x02170130,
1629	0x01014050, 0x01819040, 0x01014020, 0x90a3014e,
1630	0x01451160, 0x98560170,
1631};
1632
1633static unsigned int dell_s14_pin_configs[10] = {
1634	0x0221403f, 0x0221101f, 0x02a19020, 0x90170110,
1635	0x40f000f0, 0x40f000f0, 0x40f000f0, 0x90a60160,
1636	0x40f000f0, 0x40f000f0,
1637};
1638
1639/* Deliberately turn off 0x0f (Dock Mic) to make it choose Int Mic instead */
1640static unsigned int dell_e6410_pin_configs[10] = {
1641	0x04a11020, 0x0421101f, 0x400000f0, 0x90170110,
1642	0x23011050, 0x40f000f0, 0x400000f0, 0x90a60130,
1643	0x40f000f0, 0x40f000f0,
1644};
1645
1646static unsigned int hp_dv7_4000_pin_configs[10] = {
1647	0x03a12050, 0x0321201f, 0x40f000f0, 0x90170110,
1648	0x40f000f0, 0x40f000f0, 0x90170110, 0xd5a30140,
1649	0x40f000f0, 0x40f000f0,
1650};
1651
1652static unsigned int *stac92hd83xxx_brd_tbl[STAC_92HD83XXX_MODELS] = {
1653	[STAC_92HD83XXX_REF] = ref92hd83xxx_pin_configs,
1654	[STAC_92HD83XXX_PWR_REF] = ref92hd83xxx_pin_configs,
1655	[STAC_DELL_S14] = dell_s14_pin_configs,
1656	[STAC_DELL_E6410] = dell_e6410_pin_configs,
1657	[STAC_HP_DV7_4000] = hp_dv7_4000_pin_configs,
1658};
1659
1660static const char *stac92hd83xxx_models[STAC_92HD83XXX_MODELS] = {
1661	[STAC_92HD83XXX_AUTO] = "auto",
1662	[STAC_92HD83XXX_REF] = "ref",
1663	[STAC_92HD83XXX_PWR_REF] = "mic-ref",
1664	[STAC_DELL_S14] = "dell-s14",
1665	[STAC_DELL_E6410] = "dell-e6410",
1666	[STAC_92HD83XXX_HP] = "hp",
1667	[STAC_HP_DV7_4000] = "hp-dv7-4000",
1668};
1669
1670static struct snd_pci_quirk stac92hd83xxx_cfg_tbl[] = {
1671	/* SigmaTel reference board */
1672	SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1673		      "DFI LanParty", STAC_92HD83XXX_REF),
1674	SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1675		      "DFI LanParty", STAC_92HD83XXX_REF),
1676	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ba,
1677		      "unknown Dell", STAC_DELL_S14),
1678	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x040a,
1679		      "Dell E6410", STAC_DELL_E6410),
1680	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x040b,
1681		      "Dell E6510", STAC_DELL_E6410),
1682	SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xff00, 0x3600,
1683		      "HP", STAC_92HD83XXX_HP),
1684	{} /* terminator */
1685};
1686
1687static unsigned int ref92hd71bxx_pin_configs[STAC92HD71BXX_NUM_PINS] = {
1688	0x02214030, 0x02a19040, 0x01a19020, 0x01014010,
1689	0x0181302e, 0x01014010, 0x01019020, 0x90a000f0,
1690	0x90a000f0, 0x01452050, 0x01452050, 0x00000000,
1691	0x00000000
1692};
1693
1694static unsigned int dell_m4_1_pin_configs[STAC92HD71BXX_NUM_PINS] = {
1695	0x0421101f, 0x04a11221, 0x40f000f0, 0x90170110,
1696	0x23a1902e, 0x23014250, 0x40f000f0, 0x90a000f0,
1697	0x40f000f0, 0x4f0000f0, 0x4f0000f0, 0x00000000,
1698	0x00000000
1699};
1700
1701static unsigned int dell_m4_2_pin_configs[STAC92HD71BXX_NUM_PINS] = {
1702	0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1703	0x23a1902e, 0x23014250, 0x40f000f0, 0x40f000f0,
1704	0x40f000f0, 0x044413b0, 0x044413b0, 0x00000000,
1705	0x00000000
1706};
1707
1708static unsigned int dell_m4_3_pin_configs[STAC92HD71BXX_NUM_PINS] = {
1709	0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1710	0x40f000f0, 0x40f000f0, 0x40f000f0, 0x90a000f0,
1711	0x40f000f0, 0x044413b0, 0x044413b0, 0x00000000,
1712	0x00000000
1713};
1714
1715static unsigned int *stac92hd71bxx_brd_tbl[STAC_92HD71BXX_MODELS] = {
1716	[STAC_92HD71BXX_REF] = ref92hd71bxx_pin_configs,
1717	[STAC_DELL_M4_1]	= dell_m4_1_pin_configs,
1718	[STAC_DELL_M4_2]	= dell_m4_2_pin_configs,
1719	[STAC_DELL_M4_3]	= dell_m4_3_pin_configs,
1720	[STAC_HP_M4]		= NULL,
1721	[STAC_HP_DV4]		= NULL,
1722	[STAC_HP_DV5]		= NULL,
1723	[STAC_HP_HDX]           = NULL,
1724	[STAC_HP_DV4_1222NR]	= NULL,
1725};
1726
1727static const char *stac92hd71bxx_models[STAC_92HD71BXX_MODELS] = {
1728	[STAC_92HD71BXX_AUTO] = "auto",
1729	[STAC_92HD71BXX_REF] = "ref",
1730	[STAC_DELL_M4_1] = "dell-m4-1",
1731	[STAC_DELL_M4_2] = "dell-m4-2",
1732	[STAC_DELL_M4_3] = "dell-m4-3",
1733	[STAC_HP_M4] = "hp-m4",
1734	[STAC_HP_DV4] = "hp-dv4",
1735	[STAC_HP_DV5] = "hp-dv5",
1736	[STAC_HP_HDX] = "hp-hdx",
1737	[STAC_HP_DV4_1222NR] = "hp-dv4-1222nr",
1738};
1739
1740static struct snd_pci_quirk stac92hd71bxx_cfg_tbl[] = {
1741	/* SigmaTel reference board */
1742	SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1743		      "DFI LanParty", STAC_92HD71BXX_REF),
1744	SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1745		      "DFI LanParty", STAC_92HD71BXX_REF),
1746	SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x30fb,
1747		      "HP dv4-1222nr", STAC_HP_DV4_1222NR),
1748	SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x1720,
1749			  "HP", STAC_HP_DV5),
1750	SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3080,
1751		      "HP", STAC_HP_DV5),
1752	SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x30f0,
1753		      "HP dv4-7", STAC_HP_DV4),
1754	SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3600,
1755		      "HP dv4-7", STAC_HP_DV5),
1756	SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3610,
1757		      "HP HDX", STAC_HP_HDX),  /* HDX18 */
1758	SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361a,
1759		      "HP mini 1000", STAC_HP_M4),
1760	SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361b,
1761		      "HP HDX", STAC_HP_HDX),  /* HDX16 */
1762	SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3620,
1763		      "HP dv6", STAC_HP_DV5),
1764	SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3061,
1765		      "HP dv6", STAC_HP_DV5), /* HP dv6-1110ax */
1766	SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x363e,
1767		      "HP DV6", STAC_HP_DV5),
1768	SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x7010,
1769		      "HP", STAC_HP_DV5),
1770	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0233,
1771				"unknown Dell", STAC_DELL_M4_1),
1772	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0234,
1773				"unknown Dell", STAC_DELL_M4_1),
1774	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0250,
1775				"unknown Dell", STAC_DELL_M4_1),
1776	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024f,
1777				"unknown Dell", STAC_DELL_M4_1),
1778	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024d,
1779				"unknown Dell", STAC_DELL_M4_1),
1780	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0251,
1781				"unknown Dell", STAC_DELL_M4_1),
1782	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0277,
1783				"unknown Dell", STAC_DELL_M4_1),
1784	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0263,
1785				"unknown Dell", STAC_DELL_M4_2),
1786	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0265,
1787				"unknown Dell", STAC_DELL_M4_2),
1788	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0262,
1789				"unknown Dell", STAC_DELL_M4_2),
1790	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0264,
1791				"unknown Dell", STAC_DELL_M4_2),
1792	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02aa,
1793				"unknown Dell", STAC_DELL_M4_3),
1794	{} /* terminator */
1795};
1796
1797static unsigned int ref922x_pin_configs[10] = {
1798	0x01014010, 0x01016011, 0x01012012, 0x0221401f,
1799	0x01813122, 0x01011014, 0x01441030, 0x01c41030,
1800	0x40000100, 0x40000100,
1801};
1802
1803/*
1804    STAC 922X pin configs for
1805    102801A7
1806    102801AB
1807    102801A9
1808    102801D1
1809    102801D2
1810*/
1811static unsigned int dell_922x_d81_pin_configs[10] = {
1812	0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1813	0x02a19020, 0x01117011, 0x400001f0, 0x400001f1,
1814	0x01813122, 0x400001f2,
1815};
1816
1817/*
1818    STAC 922X pin configs for
1819    102801AC
1820    102801D0
1821*/
1822static unsigned int dell_922x_d82_pin_configs[10] = {
1823	0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1824	0x02a19020, 0x01117011, 0x01451140, 0x400001f0,
1825	0x01813122, 0x400001f1,
1826};
1827
1828/*
1829    STAC 922X pin configs for
1830    102801BF
1831*/
1832static unsigned int dell_922x_m81_pin_configs[10] = {
1833	0x0321101f, 0x01112024, 0x01111222, 0x91174220,
1834	0x03a11050, 0x01116221, 0x90a70330, 0x01452340,
1835	0x40C003f1, 0x405003f0,
1836};
1837
1838/*
1839    STAC 9221 A1 pin configs for
1840    102801D7 (Dell XPS M1210)
1841*/
1842static unsigned int dell_922x_m82_pin_configs[10] = {
1843	0x02211211, 0x408103ff, 0x02a1123e, 0x90100310,
1844	0x408003f1, 0x0221121f, 0x03451340, 0x40c003f2,
1845	0x508003f3, 0x405003f4,
1846};
1847
1848static unsigned int d945gtp3_pin_configs[10] = {
1849	0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
1850	0x40000100, 0x40000100, 0x40000100, 0x40000100,
1851	0x02a19120, 0x40000100,
1852};
1853
1854static unsigned int d945gtp5_pin_configs[10] = {
1855	0x0221401f, 0x01011012, 0x01813024, 0x01014010,
1856	0x01a19021, 0x01016011, 0x01452130, 0x40000100,
1857	0x02a19320, 0x40000100,
1858};
1859
1860static unsigned int intel_mac_v1_pin_configs[10] = {
1861	0x0121e21f, 0x400000ff, 0x9017e110, 0x400000fd,
1862	0x400000fe, 0x0181e020, 0x1145e030, 0x11c5e240,
1863	0x400000fc, 0x400000fb,
1864};
1865
1866static unsigned int intel_mac_v2_pin_configs[10] = {
1867	0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
1868	0x400000fe, 0x0181e020, 0x1145e230, 0x500000fa,
1869	0x400000fc, 0x400000fb,
1870};
1871
1872static unsigned int intel_mac_v3_pin_configs[10] = {
1873	0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
1874	0x400000fe, 0x0181e020, 0x1145e230, 0x11c5e240,
1875	0x400000fc, 0x400000fb,
1876};
1877
1878static unsigned int intel_mac_v4_pin_configs[10] = {
1879	0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
1880	0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
1881	0x400000fc, 0x400000fb,
1882};
1883
1884static unsigned int intel_mac_v5_pin_configs[10] = {
1885	0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
1886	0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
1887	0x400000fc, 0x400000fb,
1888};
1889
1890static unsigned int ecs202_pin_configs[10] = {
1891	0x0221401f, 0x02a19020, 0x01a19020, 0x01114010,
1892	0x408000f0, 0x01813022, 0x074510a0, 0x40c400f1,
1893	0x9037012e, 0x40e000f2,
1894};
1895
1896static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
1897	[STAC_D945_REF] = ref922x_pin_configs,
1898	[STAC_D945GTP3] = d945gtp3_pin_configs,
1899	[STAC_D945GTP5] = d945gtp5_pin_configs,
1900	[STAC_INTEL_MAC_V1] = intel_mac_v1_pin_configs,
1901	[STAC_INTEL_MAC_V2] = intel_mac_v2_pin_configs,
1902	[STAC_INTEL_MAC_V3] = intel_mac_v3_pin_configs,
1903	[STAC_INTEL_MAC_V4] = intel_mac_v4_pin_configs,
1904	[STAC_INTEL_MAC_V5] = intel_mac_v5_pin_configs,
1905	[STAC_INTEL_MAC_AUTO] = intel_mac_v3_pin_configs,
1906	/* for backward compatibility */
1907	[STAC_MACMINI] = intel_mac_v3_pin_configs,
1908	[STAC_MACBOOK] = intel_mac_v5_pin_configs,
1909	[STAC_MACBOOK_PRO_V1] = intel_mac_v3_pin_configs,
1910	[STAC_MACBOOK_PRO_V2] = intel_mac_v3_pin_configs,
1911	[STAC_IMAC_INTEL] = intel_mac_v2_pin_configs,
1912	[STAC_IMAC_INTEL_20] = intel_mac_v3_pin_configs,
1913	[STAC_ECS_202] = ecs202_pin_configs,
1914	[STAC_922X_DELL_D81] = dell_922x_d81_pin_configs,
1915	[STAC_922X_DELL_D82] = dell_922x_d82_pin_configs,
1916	[STAC_922X_DELL_M81] = dell_922x_m81_pin_configs,
1917	[STAC_922X_DELL_M82] = dell_922x_m82_pin_configs,
1918};
1919
1920static const char *stac922x_models[STAC_922X_MODELS] = {
1921	[STAC_922X_AUTO] = "auto",
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	SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1950		      "DFI LanParty", STAC_D945_REF),
1951	/* Intel 945G based systems */
1952	SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101,
1953		      "Intel D945G", STAC_D945GTP3),
1954	SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0202,
1955		      "Intel D945G", STAC_D945GTP3),
1956	SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0606,
1957		      "Intel D945G", STAC_D945GTP3),
1958	SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0601,
1959		      "Intel D945G", STAC_D945GTP3),
1960	SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0111,
1961		      "Intel D945G", STAC_D945GTP3),
1962	SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1115,
1963		      "Intel D945G", STAC_D945GTP3),
1964	SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1116,
1965		      "Intel D945G", STAC_D945GTP3),
1966	SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1117,
1967		      "Intel D945G", STAC_D945GTP3),
1968	SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1118,
1969		      "Intel D945G", STAC_D945GTP3),
1970	SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1119,
1971		      "Intel D945G", STAC_D945GTP3),
1972	SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x8826,
1973		      "Intel D945G", STAC_D945GTP3),
1974	SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5049,
1975		      "Intel D945G", STAC_D945GTP3),
1976	SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5055,
1977		      "Intel D945G", STAC_D945GTP3),
1978	SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5048,
1979		      "Intel D945G", STAC_D945GTP3),
1980	SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0110,
1981		      "Intel D945G", STAC_D945GTP3),
1982	/* Intel D945G 5-stack systems */
1983	SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0404,
1984		      "Intel D945G", STAC_D945GTP5),
1985	SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0303,
1986		      "Intel D945G", STAC_D945GTP5),
1987	SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0013,
1988		      "Intel D945G", STAC_D945GTP5),
1989	SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0417,
1990		      "Intel D945G", STAC_D945GTP5),
1991	/* Intel 945P based systems */
1992	SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0b0b,
1993		      "Intel D945P", STAC_D945GTP3),
1994	SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0112,
1995		      "Intel D945P", STAC_D945GTP3),
1996	SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0d0d,
1997		      "Intel D945P", STAC_D945GTP3),
1998	SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0909,
1999		      "Intel D945P", STAC_D945GTP3),
2000	SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0505,
2001		      "Intel D945P", STAC_D945GTP3),
2002	SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707,
2003		      "Intel D945P", STAC_D945GTP5),
2004	/* other intel */
2005	SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0204,
2006		      "Intel D945", STAC_D945_REF),
2007	/* other systems  */
2008	/* Apple Intel Mac (Mac Mini, MacBook, MacBook Pro...) */
2009	SND_PCI_QUIRK(0x8384, 0x7680,
2010		      "Mac", STAC_INTEL_MAC_AUTO),
2011	/* Dell systems  */
2012	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a7,
2013		      "unknown Dell", STAC_922X_DELL_D81),
2014	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a9,
2015		      "unknown Dell", STAC_922X_DELL_D81),
2016	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ab,
2017		      "unknown Dell", STAC_922X_DELL_D81),
2018	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ac,
2019		      "unknown Dell", STAC_922X_DELL_D82),
2020	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bf,
2021		      "unknown Dell", STAC_922X_DELL_M81),
2022	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d0,
2023		      "unknown Dell", STAC_922X_DELL_D82),
2024	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d1,
2025		      "unknown Dell", STAC_922X_DELL_D81),
2026	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d2,
2027		      "unknown Dell", STAC_922X_DELL_D81),
2028	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d7,
2029		      "Dell XPS M1210", STAC_922X_DELL_M82),
2030	/* ECS/PC Chips boards */
2031	SND_PCI_QUIRK_MASK(0x1019, 0xf000, 0x2000,
2032		      "ECS/PC chips", STAC_ECS_202),
2033	{} /* terminator */
2034};
2035
2036static unsigned int ref927x_pin_configs[14] = {
2037	0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2038	0x01a19040, 0x01011012, 0x01016011, 0x0101201f,
2039	0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
2040	0x01c42190, 0x40000100,
2041};
2042
2043static unsigned int d965_3st_pin_configs[14] = {
2044	0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
2045	0x01a19021, 0x01813024, 0x40000100, 0x40000100,
2046	0x40000100, 0x40000100, 0x40000100, 0x40000100,
2047	0x40000100, 0x40000100
2048};
2049
2050static unsigned int d965_5st_pin_configs[14] = {
2051	0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2052	0x01a19040, 0x01011012, 0x01016011, 0x40000100,
2053	0x40000100, 0x40000100, 0x40000100, 0x01442070,
2054	0x40000100, 0x40000100
2055};
2056
2057static unsigned int d965_5st_no_fp_pin_configs[14] = {
2058	0x40000100, 0x40000100, 0x0181304e, 0x01014010,
2059	0x01a19040, 0x01011012, 0x01016011, 0x40000100,
2060	0x40000100, 0x40000100, 0x40000100, 0x01442070,
2061	0x40000100, 0x40000100
2062};
2063
2064static unsigned int dell_3st_pin_configs[14] = {
2065	0x02211230, 0x02a11220, 0x01a19040, 0x01114210,
2066	0x01111212, 0x01116211, 0x01813050, 0x01112214,
2067	0x403003fa, 0x90a60040, 0x90a60040, 0x404003fb,
2068	0x40c003fc, 0x40000100
2069};
2070
2071static unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
2072	[STAC_D965_REF_NO_JD] = ref927x_pin_configs,
2073	[STAC_D965_REF]  = ref927x_pin_configs,
2074	[STAC_D965_3ST]  = d965_3st_pin_configs,
2075	[STAC_D965_5ST]  = d965_5st_pin_configs,
2076	[STAC_D965_5ST_NO_FP]  = d965_5st_no_fp_pin_configs,
2077	[STAC_DELL_3ST]  = dell_3st_pin_configs,
2078	[STAC_DELL_BIOS] = NULL,
2079	[STAC_927X_VOLKNOB] = NULL,
2080};
2081
2082static const char *stac927x_models[STAC_927X_MODELS] = {
2083	[STAC_927X_AUTO]	= "auto",
2084	[STAC_D965_REF_NO_JD]	= "ref-no-jd",
2085	[STAC_D965_REF]		= "ref",
2086	[STAC_D965_3ST]		= "3stack",
2087	[STAC_D965_5ST]		= "5stack",
2088	[STAC_D965_5ST_NO_FP]	= "5stack-no-fp",
2089	[STAC_DELL_3ST]		= "dell-3stack",
2090	[STAC_DELL_BIOS]	= "dell-bios",
2091	[STAC_927X_VOLKNOB]	= "volknob",
2092};
2093
2094static struct snd_pci_quirk stac927x_cfg_tbl[] = {
2095	/* SigmaTel reference board */
2096	SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2097		      "DFI LanParty", STAC_D965_REF),
2098	SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2099		      "DFI LanParty", STAC_D965_REF),
2100	 /* Intel 946 based systems */
2101	SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST),
2102	SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST),
2103	/* 965 based 3 stack systems */
2104	SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2100,
2105			   "Intel D965", STAC_D965_3ST),
2106	SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2000,
2107			   "Intel D965", STAC_D965_3ST),
2108	/* Dell 3 stack systems */
2109	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL,  0x01dd, "Dell Dimension E520", STAC_DELL_3ST),
2110	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL,  0x01ed, "Dell     ", STAC_DELL_3ST),
2111	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL,  0x01f4, "Dell     ", STAC_DELL_3ST),
2112	/* Dell 3 stack systems with verb table in BIOS */
2113	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL,  0x01f3, "Dell Inspiron 1420", STAC_DELL_BIOS),
2114	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL,  0x01f7, "Dell XPS M1730", STAC_DELL_BIOS),
2115	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL,  0x0227, "Dell Vostro 1400  ", STAC_DELL_BIOS),
2116	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL,  0x022e, "Dell     ", STAC_DELL_BIOS),
2117	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL,  0x022f, "Dell Inspiron 1525", STAC_DELL_BIOS),
2118	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL,  0x0242, "Dell     ", STAC_DELL_BIOS),
2119	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL,  0x0243, "Dell     ", STAC_DELL_BIOS),
2120	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL,  0x02ff, "Dell     ", STAC_DELL_BIOS),
2121	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL,  0x0209, "Dell XPS 1330", STAC_DELL_BIOS),
2122	/* 965 based 5 stack systems */
2123	SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2300,
2124			   "Intel D965", STAC_D965_5ST),
2125	SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2500,
2126			   "Intel D965", STAC_D965_5ST),
2127	/* volume-knob fixes */
2128	SND_PCI_QUIRK_VENDOR(0x10cf, "FSC", STAC_927X_VOLKNOB),
2129	{} /* terminator */
2130};
2131
2132static unsigned int ref9205_pin_configs[12] = {
2133	0x40000100, 0x40000100, 0x01016011, 0x01014010,
2134	0x01813122, 0x01a19021, 0x01019020, 0x40000100,
2135	0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
2136};
2137
2138/*
2139    STAC 9205 pin configs for
2140    102801F1
2141    102801F2
2142    102801FC
2143    102801FD
2144    10280204
2145    1028021F
2146    10280228 (Dell Vostro 1500)
2147    10280229 (Dell Vostro 1700)
2148*/
2149static unsigned int dell_9205_m42_pin_configs[12] = {
2150	0x0321101F, 0x03A11020, 0x400003FA, 0x90170310,
2151	0x400003FB, 0x400003FC, 0x400003FD, 0x40F000F9,
2152	0x90A60330, 0x400003FF, 0x0144131F, 0x40C003FE,
2153};
2154
2155/*
2156    STAC 9205 pin configs for
2157    102801F9
2158    102801FA
2159    102801FE
2160    102801FF (Dell Precision M4300)
2161    10280206
2162    10280200
2163    10280201
2164*/
2165static unsigned int dell_9205_m43_pin_configs[12] = {
2166	0x0321101f, 0x03a11020, 0x90a70330, 0x90170310,
2167	0x400000fe, 0x400000ff, 0x400000fd, 0x40f000f9,
2168	0x400000fa, 0x400000fc, 0x0144131f, 0x40c003f8,
2169};
2170
2171static unsigned int dell_9205_m44_pin_configs[12] = {
2172	0x0421101f, 0x04a11020, 0x400003fa, 0x90170310,
2173	0x400003fb, 0x400003fc, 0x400003fd, 0x400003f9,
2174	0x90a60330, 0x400003ff, 0x01441340, 0x40c003fe,
2175};
2176
2177static unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
2178	[STAC_9205_REF] = ref9205_pin_configs,
2179	[STAC_9205_DELL_M42] = dell_9205_m42_pin_configs,
2180	[STAC_9205_DELL_M43] = dell_9205_m43_pin_configs,
2181	[STAC_9205_DELL_M44] = dell_9205_m44_pin_configs,
2182	[STAC_9205_EAPD] = NULL,
2183};
2184
2185static const char *stac9205_models[STAC_9205_MODELS] = {
2186	[STAC_9205_AUTO] = "auto",
2187	[STAC_9205_REF] = "ref",
2188	[STAC_9205_DELL_M42] = "dell-m42",
2189	[STAC_9205_DELL_M43] = "dell-m43",
2190	[STAC_9205_DELL_M44] = "dell-m44",
2191	[STAC_9205_EAPD] = "eapd",
2192};
2193
2194static struct snd_pci_quirk stac9205_cfg_tbl[] = {
2195	/* SigmaTel reference board */
2196	SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2197		      "DFI LanParty", STAC_9205_REF),
2198	SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xfb30,
2199		      "SigmaTel", STAC_9205_REF),
2200	SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2201		      "DFI LanParty", STAC_9205_REF),
2202	/* Dell */
2203	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f1,
2204		      "unknown Dell", STAC_9205_DELL_M42),
2205	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f2,
2206		      "unknown Dell", STAC_9205_DELL_M42),
2207	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f8,
2208		      "Dell Precision", STAC_9205_DELL_M43),
2209	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f9,
2210		      "Dell Precision", STAC_9205_DELL_M43),
2211	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fa,
2212		      "Dell Precision", STAC_9205_DELL_M43),
2213	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fc,
2214		      "unknown Dell", STAC_9205_DELL_M42),
2215	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fd,
2216		      "unknown Dell", STAC_9205_DELL_M42),
2217	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fe,
2218		      "Dell Precision", STAC_9205_DELL_M43),
2219	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ff,
2220		      "Dell Precision M4300", STAC_9205_DELL_M43),
2221	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0204,
2222		      "unknown Dell", STAC_9205_DELL_M42),
2223	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0206,
2224		      "Dell Precision", STAC_9205_DELL_M43),
2225	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021b,
2226		      "Dell Precision", STAC_9205_DELL_M43),
2227	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021c,
2228		      "Dell Precision", STAC_9205_DELL_M43),
2229	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021f,
2230		      "Dell Inspiron", STAC_9205_DELL_M44),
2231	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0228,
2232		      "Dell Vostro 1500", STAC_9205_DELL_M42),
2233	SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0229,
2234		      "Dell Vostro 1700", STAC_9205_DELL_M42),
2235	/* Gateway */
2236	SND_PCI_QUIRK(0x107b, 0x0560, "Gateway T6834c", STAC_9205_EAPD),
2237	SND_PCI_QUIRK(0x107b, 0x0565, "Gateway T1616", STAC_9205_EAPD),
2238	{} /* terminator */
2239};
2240
2241static void stac92xx_set_config_regs(struct hda_codec *codec,
2242				     unsigned int *pincfgs)
2243{
2244	int i;
2245	struct sigmatel_spec *spec = codec->spec;
2246
2247	if (!pincfgs)
2248		return;
2249
2250	for (i = 0; i < spec->num_pins; i++)
2251		if (spec->pin_nids[i] && pincfgs[i])
2252			snd_hda_codec_set_pincfg(codec, spec->pin_nids[i],
2253						 pincfgs[i]);
2254}
2255
2256/*
2257 * Analog playback callbacks
2258 */
2259static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
2260				      struct hda_codec *codec,
2261				      struct snd_pcm_substream *substream)
2262{
2263	struct sigmatel_spec *spec = codec->spec;
2264	if (spec->stream_delay)
2265		msleep(spec->stream_delay);
2266	return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2267					     hinfo);
2268}
2269
2270static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2271					 struct hda_codec *codec,
2272					 unsigned int stream_tag,
2273					 unsigned int format,
2274					 struct snd_pcm_substream *substream)
2275{
2276	struct sigmatel_spec *spec = codec->spec;
2277	return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
2278}
2279
2280static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2281					struct hda_codec *codec,
2282					struct snd_pcm_substream *substream)
2283{
2284	struct sigmatel_spec *spec = codec->spec;
2285	return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2286}
2287
2288/*
2289 * Digital playback callbacks
2290 */
2291static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2292					  struct hda_codec *codec,
2293					  struct snd_pcm_substream *substream)
2294{
2295	struct sigmatel_spec *spec = codec->spec;
2296	return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2297}
2298
2299static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2300					   struct hda_codec *codec,
2301					   struct snd_pcm_substream *substream)
2302{
2303	struct sigmatel_spec *spec = codec->spec;
2304	return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2305}
2306
2307static int stac92xx_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2308					 struct hda_codec *codec,
2309					 unsigned int stream_tag,
2310					 unsigned int format,
2311					 struct snd_pcm_substream *substream)
2312{
2313	struct sigmatel_spec *spec = codec->spec;
2314	return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2315					     stream_tag, format, substream);
2316}
2317
2318static int stac92xx_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2319					struct hda_codec *codec,
2320					struct snd_pcm_substream *substream)
2321{
2322	struct sigmatel_spec *spec = codec->spec;
2323	return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2324}
2325
2326
2327/*
2328 * Analog capture callbacks
2329 */
2330static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2331					struct hda_codec *codec,
2332					unsigned int stream_tag,
2333					unsigned int format,
2334					struct snd_pcm_substream *substream)
2335{
2336	struct sigmatel_spec *spec = codec->spec;
2337	hda_nid_t nid = spec->adc_nids[substream->number];
2338
2339	if (spec->powerdown_adcs) {
2340		msleep(40);
2341		snd_hda_codec_write(codec, nid, 0,
2342			AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
2343	}
2344	snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format);
2345	return 0;
2346}
2347
2348static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2349					struct hda_codec *codec,
2350					struct snd_pcm_substream *substream)
2351{
2352	struct sigmatel_spec *spec = codec->spec;
2353	hda_nid_t nid = spec->adc_nids[substream->number];
2354
2355	snd_hda_codec_cleanup_stream(codec, nid);
2356	if (spec->powerdown_adcs)
2357		snd_hda_codec_write(codec, nid, 0,
2358			AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
2359	return 0;
2360}
2361
2362static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
2363	.substreams = 1,
2364	.channels_min = 2,
2365	.channels_max = 2,
2366	/* NID is set in stac92xx_build_pcms */
2367	.ops = {
2368		.open = stac92xx_dig_playback_pcm_open,
2369		.close = stac92xx_dig_playback_pcm_close,
2370		.prepare = stac92xx_dig_playback_pcm_prepare,
2371		.cleanup = stac92xx_dig_playback_pcm_cleanup
2372	},
2373};
2374
2375static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
2376	.substreams = 1,
2377	.channels_min = 2,
2378	.channels_max = 2,
2379	/* NID is set in stac92xx_build_pcms */
2380};
2381
2382static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
2383	.substreams = 1,
2384	.channels_min = 2,
2385	.channels_max = 8,
2386	.nid = 0x02, /* NID to query formats and rates */
2387	.ops = {
2388		.open = stac92xx_playback_pcm_open,
2389		.prepare = stac92xx_playback_pcm_prepare,
2390		.cleanup = stac92xx_playback_pcm_cleanup
2391	},
2392};
2393
2394static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
2395	.substreams = 1,
2396	.channels_min = 2,
2397	.channels_max = 2,
2398	.nid = 0x06, /* NID to query formats and rates */
2399	.ops = {
2400		.open = stac92xx_playback_pcm_open,
2401		.prepare = stac92xx_playback_pcm_prepare,
2402		.cleanup = stac92xx_playback_pcm_cleanup
2403	},
2404};
2405
2406static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
2407	.channels_min = 2,
2408	.channels_max = 2,
2409	/* NID + .substreams is set in stac92xx_build_pcms */
2410	.ops = {
2411		.prepare = stac92xx_capture_pcm_prepare,
2412		.cleanup = stac92xx_capture_pcm_cleanup
2413	},
2414};
2415
2416static int stac92xx_build_pcms(struct hda_codec *codec)
2417{
2418	struct sigmatel_spec *spec = codec->spec;
2419	struct hda_pcm *info = spec->pcm_rec;
2420
2421	codec->num_pcms = 1;
2422	codec->pcm_info = info;
2423
2424	info->name = "STAC92xx Analog";
2425	info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
2426	info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2427		spec->multiout.dac_nids[0];
2428	info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
2429	info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2430	info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adcs;
2431
2432	if (spec->alt_switch) {
2433		codec->num_pcms++;
2434		info++;
2435		info->name = "STAC92xx Analog Alt";
2436		info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
2437	}
2438
2439	if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2440		codec->num_pcms++;
2441		info++;
2442		info->name = "STAC92xx Digital";
2443		info->pcm_type = spec->autocfg.dig_out_type[0];
2444		if (spec->multiout.dig_out_nid) {
2445			info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
2446			info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2447		}
2448		if (spec->dig_in_nid) {
2449			info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
2450			info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2451		}
2452	}
2453
2454	return 0;
2455}
2456
2457static unsigned int stac92xx_get_default_vref(struct hda_codec *codec,
2458					hda_nid_t nid)
2459{
2460	unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2461	pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
2462	if (pincap & AC_PINCAP_VREF_100)
2463		return AC_PINCTL_VREF_100;
2464	if (pincap & AC_PINCAP_VREF_80)
2465		return AC_PINCTL_VREF_80;
2466	if (pincap & AC_PINCAP_VREF_50)
2467		return AC_PINCTL_VREF_50;
2468	if (pincap & AC_PINCAP_VREF_GRD)
2469		return AC_PINCTL_VREF_GRD;
2470	return 0;
2471}
2472
2473static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
2474
2475{
2476	snd_hda_codec_write_cache(codec, nid, 0,
2477				  AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
2478}
2479
2480#define stac92xx_hp_switch_info		snd_ctl_boolean_mono_info
2481
2482static int stac92xx_hp_switch_get(struct snd_kcontrol *kcontrol,
2483			struct snd_ctl_elem_value *ucontrol)
2484{
2485	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2486	struct sigmatel_spec *spec = codec->spec;
2487
2488	ucontrol->value.integer.value[0] = !!spec->hp_switch;
2489	return 0;
2490}
2491
2492static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid);
2493
2494static int stac92xx_hp_switch_put(struct snd_kcontrol *kcontrol,
2495			struct snd_ctl_elem_value *ucontrol)
2496{
2497	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2498	struct sigmatel_spec *spec = codec->spec;
2499	int nid = kcontrol->private_value;
2500
2501	spec->hp_switch = ucontrol->value.integer.value[0] ? nid : 0;
2502
2503	/* check to be sure that the ports are upto date with
2504	 * switch changes
2505	 */
2506	stac_issue_unsol_event(codec, nid);
2507
2508	return 1;
2509}
2510
2511static int stac92xx_dc_bias_info(struct snd_kcontrol *kcontrol,
2512				struct snd_ctl_elem_info *uinfo)
2513{
2514	int i;
2515	static char *texts[] = {
2516		"Mic In", "Line In", "Line Out"
2517	};
2518
2519	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2520	struct sigmatel_spec *spec = codec->spec;
2521	hda_nid_t nid = kcontrol->private_value;
2522
2523	if (nid == spec->mic_switch || nid == spec->line_switch)
2524		i = 3;
2525	else
2526		i = 2;
2527
2528	uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2529	uinfo->value.enumerated.items = i;
2530	uinfo->count = 1;
2531	if (uinfo->value.enumerated.item >= i)
2532		uinfo->value.enumerated.item = i-1;
2533	strcpy(uinfo->value.enumerated.name,
2534		texts[uinfo->value.enumerated.item]);
2535
2536	return 0;
2537}
2538
2539static int stac92xx_dc_bias_get(struct snd_kcontrol *kcontrol,
2540				struct snd_ctl_elem_value *ucontrol)
2541{
2542	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2543	hda_nid_t nid = kcontrol->private_value;
2544	unsigned int vref = stac92xx_vref_get(codec, nid);
2545
2546	if (vref == stac92xx_get_default_vref(codec, nid))
2547		ucontrol->value.enumerated.item[0] = 0;
2548	else if (vref == AC_PINCTL_VREF_GRD)
2549		ucontrol->value.enumerated.item[0] = 1;
2550	else if (vref == AC_PINCTL_VREF_HIZ)
2551		ucontrol->value.enumerated.item[0] = 2;
2552
2553	return 0;
2554}
2555
2556static int stac92xx_dc_bias_put(struct snd_kcontrol *kcontrol,
2557				struct snd_ctl_elem_value *ucontrol)
2558{
2559	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2560	unsigned int new_vref = 0;
2561	int error;
2562	hda_nid_t nid = kcontrol->private_value;
2563
2564	if (ucontrol->value.enumerated.item[0] == 0)
2565		new_vref = stac92xx_get_default_vref(codec, nid);
2566	else if (ucontrol->value.enumerated.item[0] == 1)
2567		new_vref = AC_PINCTL_VREF_GRD;
2568	else if (ucontrol->value.enumerated.item[0] == 2)
2569		new_vref = AC_PINCTL_VREF_HIZ;
2570	else
2571		return 0;
2572
2573	if (new_vref != stac92xx_vref_get(codec, nid)) {
2574		error = stac92xx_vref_set(codec, nid, new_vref);
2575		return error;
2576	}
2577
2578	return 0;
2579}
2580
2581static int stac92xx_io_switch_info(struct snd_kcontrol *kcontrol,
2582				struct snd_ctl_elem_info *uinfo)
2583{
2584	static char *texts[2];
2585	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2586	struct sigmatel_spec *spec = codec->spec;
2587
2588	if (kcontrol->private_value == spec->line_switch)
2589		texts[0] = "Line In";
2590	else
2591		texts[0] = "Mic In";
2592	texts[1] = "Line Out";
2593	uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2594	uinfo->value.enumerated.items = 2;
2595	uinfo->count = 1;
2596
2597	if (uinfo->value.enumerated.item >= 2)
2598		uinfo->value.enumerated.item = 1;
2599	strcpy(uinfo->value.enumerated.name,
2600		texts[uinfo->value.enumerated.item]);
2601
2602	return 0;
2603}
2604
2605static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2606{
2607	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2608	struct sigmatel_spec *spec = codec->spec;
2609	hda_nid_t nid = kcontrol->private_value;
2610	int io_idx = (nid == spec->mic_switch) ? 1 : 0;
2611
2612	ucontrol->value.enumerated.item[0] = spec->io_switch[io_idx];
2613	return 0;
2614}
2615
2616static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2617{
2618        struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2619	struct sigmatel_spec *spec = codec->spec;
2620	hda_nid_t nid = kcontrol->private_value;
2621	int io_idx = (nid == spec->mic_switch) ? 1 : 0;
2622	unsigned short val = !!ucontrol->value.enumerated.item[0];
2623
2624	spec->io_switch[io_idx] = val;
2625
2626	if (val)
2627		stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
2628	else {
2629		unsigned int pinctl = AC_PINCTL_IN_EN;
2630		if (io_idx) /* set VREF for mic */
2631			pinctl |= stac92xx_get_default_vref(codec, nid);
2632		stac92xx_auto_set_pinctl(codec, nid, pinctl);
2633	}
2634
2635	/* check the auto-mute again: we need to mute/unmute the speaker
2636	 * appropriately according to the pin direction
2637	 */
2638	if (spec->hp_detect)
2639		stac_issue_unsol_event(codec, nid);
2640
2641        return 1;
2642}
2643
2644#define stac92xx_clfe_switch_info snd_ctl_boolean_mono_info
2645
2646static int stac92xx_clfe_switch_get(struct snd_kcontrol *kcontrol,
2647		struct snd_ctl_elem_value *ucontrol)
2648{
2649	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2650	struct sigmatel_spec *spec = codec->spec;
2651
2652	ucontrol->value.integer.value[0] = spec->clfe_swap;
2653	return 0;
2654}
2655
2656static int stac92xx_clfe_switch_put(struct snd_kcontrol *kcontrol,
2657		struct snd_ctl_elem_value *ucontrol)
2658{
2659	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2660	struct sigmatel_spec *spec = codec->spec;
2661	hda_nid_t nid = kcontrol->private_value & 0xff;
2662	unsigned int val = !!ucontrol->value.integer.value[0];
2663
2664	if (spec->clfe_swap == val)
2665		return 0;
2666
2667	spec->clfe_swap = val;
2668
2669	snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
2670		spec->clfe_swap ? 0x4 : 0x0);
2671
2672	return 1;
2673}
2674
2675#define STAC_CODEC_HP_SWITCH(xname) \
2676	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2677	  .name = xname, \
2678	  .index = 0, \
2679	  .info = stac92xx_hp_switch_info, \
2680	  .get = stac92xx_hp_switch_get, \
2681	  .put = stac92xx_hp_switch_put, \
2682	}
2683
2684#define STAC_CODEC_IO_SWITCH(xname, xpval) \
2685	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2686	  .name = xname, \
2687	  .index = 0, \
2688          .info = stac92xx_io_switch_info, \
2689          .get = stac92xx_io_switch_get, \
2690          .put = stac92xx_io_switch_put, \
2691          .private_value = xpval, \
2692	}
2693
2694#define STAC_CODEC_CLFE_SWITCH(xname, xpval) \
2695	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2696	  .name = xname, \
2697	  .index = 0, \
2698	  .info = stac92xx_clfe_switch_info, \
2699	  .get = stac92xx_clfe_switch_get, \
2700	  .put = stac92xx_clfe_switch_put, \
2701	  .private_value = xpval, \
2702	}
2703
2704enum {
2705	STAC_CTL_WIDGET_VOL,
2706	STAC_CTL_WIDGET_MUTE,
2707	STAC_CTL_WIDGET_MUTE_BEEP,
2708	STAC_CTL_WIDGET_MONO_MUX,
2709	STAC_CTL_WIDGET_HP_SWITCH,
2710	STAC_CTL_WIDGET_IO_SWITCH,
2711	STAC_CTL_WIDGET_CLFE_SWITCH,
2712	STAC_CTL_WIDGET_DC_BIAS
2713};
2714
2715static struct snd_kcontrol_new stac92xx_control_templates[] = {
2716	HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2717	HDA_CODEC_MUTE(NULL, 0, 0, 0),
2718	HDA_CODEC_MUTE_BEEP(NULL, 0, 0, 0),
2719	STAC_MONO_MUX,
2720	STAC_CODEC_HP_SWITCH(NULL),
2721	STAC_CODEC_IO_SWITCH(NULL, 0),
2722	STAC_CODEC_CLFE_SWITCH(NULL, 0),
2723	DC_BIAS(NULL, 0, 0),
2724};
2725
2726/* add dynamic controls */
2727static struct snd_kcontrol_new *
2728stac_control_new(struct sigmatel_spec *spec,
2729		 struct snd_kcontrol_new *ktemp,
2730		 const char *name,
2731		 unsigned int subdev)
2732{
2733	struct snd_kcontrol_new *knew;
2734
2735	snd_array_init(&spec->kctls, sizeof(*knew), 32);
2736	knew = snd_array_new(&spec->kctls);
2737	if (!knew)
2738		return NULL;
2739	*knew = *ktemp;
2740	knew->name = kstrdup(name, GFP_KERNEL);
2741	if (!knew->name) {
2742		/* roolback */
2743		memset(knew, 0, sizeof(*knew));
2744		spec->kctls.alloced--;
2745		return NULL;
2746	}
2747	knew->subdevice = subdev;
2748	return knew;
2749}
2750
2751static int stac92xx_add_control_temp(struct sigmatel_spec *spec,
2752				     struct snd_kcontrol_new *ktemp,
2753				     int idx, const char *name,
2754				     unsigned long val)
2755{
2756	struct snd_kcontrol_new *knew = stac_control_new(spec, ktemp, name,
2757							 HDA_SUBDEV_AMP_FLAG);
2758	if (!knew)
2759		return -ENOMEM;
2760	knew->index = idx;
2761	knew->private_value = val;
2762	return 0;
2763}
2764
2765static inline int stac92xx_add_control_idx(struct sigmatel_spec *spec,
2766					   int type, int idx, const char *name,
2767					   unsigned long val)
2768{
2769	return stac92xx_add_control_temp(spec,
2770					 &stac92xx_control_templates[type],
2771					 idx, name, val);
2772}
2773
2774
2775/* add dynamic controls */
2776static inline int stac92xx_add_control(struct sigmatel_spec *spec, int type,
2777				       const char *name, unsigned long val)
2778{
2779	return stac92xx_add_control_idx(spec, type, 0, name, val);
2780}
2781
2782static struct snd_kcontrol_new stac_input_src_temp = {
2783	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2784	.name = "Input Source",
2785	.info = stac92xx_mux_enum_info,
2786	.get = stac92xx_mux_enum_get,
2787	.put = stac92xx_mux_enum_put,
2788};
2789
2790static inline int stac92xx_add_jack_mode_control(struct hda_codec *codec,
2791						hda_nid_t nid, int idx)
2792{
2793	int def_conf = snd_hda_codec_get_pincfg(codec, nid);
2794	int control = 0;
2795	struct sigmatel_spec *spec = codec->spec;
2796	char name[22];
2797
2798	if (!((get_defcfg_connect(def_conf)) & AC_JACK_PORT_FIXED)) {
2799		if (stac92xx_get_default_vref(codec, nid) == AC_PINCTL_VREF_GRD
2800			&& nid == spec->line_switch)
2801			control = STAC_CTL_WIDGET_IO_SWITCH;
2802		else if (snd_hda_query_pin_caps(codec, nid)
2803			& (AC_PINCAP_VREF_GRD << AC_PINCAP_VREF_SHIFT))
2804			control = STAC_CTL_WIDGET_DC_BIAS;
2805		else if (nid == spec->mic_switch)
2806			control = STAC_CTL_WIDGET_IO_SWITCH;
2807	}
2808
2809	if (control) {
2810		strcpy(name, auto_pin_cfg_labels[idx]);
2811		return stac92xx_add_control(codec->spec, control,
2812					strcat(name, " Jack Mode"), nid);
2813	}
2814
2815	return 0;
2816}
2817
2818static int stac92xx_add_input_source(struct sigmatel_spec *spec)
2819{
2820	struct snd_kcontrol_new *knew;
2821	struct hda_input_mux *imux = &spec->private_imux;
2822
2823	if (spec->auto_mic)
2824		return 0; /* no need for input source */
2825	if (!spec->num_adcs || imux->num_items <= 1)
2826		return 0; /* no need for input source control */
2827	knew = stac_control_new(spec, &stac_input_src_temp,
2828				stac_input_src_temp.name, 0);
2829	if (!knew)
2830		return -ENOMEM;
2831	knew->count = spec->num_adcs;
2832	return 0;
2833}
2834
2835/* check whether the line-input can be used as line-out */
2836static hda_nid_t check_line_out_switch(struct hda_codec *codec)
2837{
2838	struct sigmatel_spec *spec = codec->spec;
2839	struct auto_pin_cfg *cfg = &spec->autocfg;
2840	hda_nid_t nid;
2841	unsigned int pincap;
2842
2843	if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
2844		return 0;
2845	nid = cfg->input_pins[AUTO_PIN_LINE];
2846	pincap = snd_hda_query_pin_caps(codec, nid);
2847	if (pincap & AC_PINCAP_OUT)
2848		return nid;
2849	return 0;
2850}
2851
2852/* check whether the mic-input can be used as line-out */
2853static hda_nid_t check_mic_out_switch(struct hda_codec *codec)
2854{
2855	struct sigmatel_spec *spec = codec->spec;
2856	struct auto_pin_cfg *cfg = &spec->autocfg;
2857	unsigned int def_conf, pincap;
2858	unsigned int mic_pin;
2859
2860	if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
2861		return 0;
2862	mic_pin = AUTO_PIN_MIC;
2863	for (;;) {
2864		hda_nid_t nid = cfg->input_pins[mic_pin];
2865		def_conf = snd_hda_codec_get_pincfg(codec, nid);
2866		/* some laptops have an internal analog microphone
2867		 * which can't be used as a output */
2868		if (get_defcfg_connect(def_conf) != AC_JACK_PORT_FIXED) {
2869			pincap = snd_hda_query_pin_caps(codec, nid);
2870			if (pincap & AC_PINCAP_OUT)
2871				return nid;
2872		}
2873		if (mic_pin == AUTO_PIN_MIC)
2874			mic_pin = AUTO_PIN_FRONT_MIC;
2875		else
2876			break;
2877	}
2878	return 0;
2879}
2880
2881static int is_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2882{
2883	int i;
2884
2885	for (i = 0; i < spec->multiout.num_dacs; i++) {
2886		if (spec->multiout.dac_nids[i] == nid)
2887			return 1;
2888	}
2889
2890	return 0;
2891}
2892
2893static int check_all_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2894{
2895	int i;
2896	if (is_in_dac_nids(spec, nid))
2897		return 1;
2898	for (i = 0; i < spec->autocfg.hp_outs; i++)
2899		if (spec->hp_dacs[i] == nid)
2900			return 1;
2901	for (i = 0; i < spec->autocfg.speaker_outs; i++)
2902		if (spec->speaker_dacs[i] == nid)
2903			return 1;
2904	return 0;
2905}
2906
2907static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t nid)
2908{
2909	struct sigmatel_spec *spec = codec->spec;
2910	int j, conn_len;
2911	hda_nid_t conn[HDA_MAX_CONNECTIONS];
2912	unsigned int wcaps, wtype;
2913
2914	conn_len = snd_hda_get_connections(codec, nid, conn,
2915					   HDA_MAX_CONNECTIONS);
2916	/* 92HD88: trace back up the link of nids to find the DAC */
2917	while (conn_len == 1 && (get_wcaps_type(get_wcaps(codec, conn[0]))
2918					!= AC_WID_AUD_OUT)) {
2919		nid = conn[0];
2920		conn_len = snd_hda_get_connections(codec, nid, conn,
2921			HDA_MAX_CONNECTIONS);
2922	}
2923	for (j = 0; j < conn_len; j++) {
2924		wcaps = get_wcaps(codec, conn[j]);
2925		wtype = get_wcaps_type(wcaps);
2926		/* we check only analog outputs */
2927		if (wtype != AC_WID_AUD_OUT || (wcaps & AC_WCAP_DIGITAL))
2928			continue;
2929		/* if this route has a free DAC, assign it */
2930		if (!check_all_dac_nids(spec, conn[j])) {
2931			if (conn_len > 1) {
2932				/* select this DAC in the pin's input mux */
2933				snd_hda_codec_write_cache(codec, nid, 0,
2934						  AC_VERB_SET_CONNECT_SEL, j);
2935			}
2936			return conn[j];
2937		}
2938	}
2939	/* if all DACs are already assigned, connect to the primary DAC */
2940	if (conn_len > 1) {
2941		for (j = 0; j < conn_len; j++) {
2942			if (conn[j] == spec->multiout.dac_nids[0]) {
2943				snd_hda_codec_write_cache(codec, nid, 0,
2944						  AC_VERB_SET_CONNECT_SEL, j);
2945				break;
2946			}
2947		}
2948	}
2949	return 0;
2950}
2951
2952static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid);
2953static int add_spec_extra_dacs(struct sigmatel_spec *spec, hda_nid_t nid);
2954
2955/*
2956 * Fill in the dac_nids table from the parsed pin configuration
2957 * This function only works when every pin in line_out_pins[]
2958 * contains atleast one DAC in its connection list. Some 92xx
2959 * codecs are not connected directly to a DAC, such as the 9200
2960 * and 9202/925x. For those, dac_nids[] must be hard-coded.
2961 */
2962static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec)
2963{
2964	struct sigmatel_spec *spec = codec->spec;
2965	struct auto_pin_cfg *cfg = &spec->autocfg;
2966	int i;
2967	hda_nid_t nid, dac;
2968
2969	for (i = 0; i < cfg->line_outs; i++) {
2970		nid = cfg->line_out_pins[i];
2971		dac = get_unassigned_dac(codec, nid);
2972		if (!dac) {
2973			if (spec->multiout.num_dacs > 0) {
2974				/* we have already working output pins,
2975				 * so let's drop the broken ones again
2976				 */
2977				cfg->line_outs = spec->multiout.num_dacs;
2978				break;
2979			}
2980			/* error out, no available DAC found */
2981			snd_printk(KERN_ERR
2982				   "%s: No available DAC for pin 0x%x\n",
2983				   __func__, nid);
2984			return -ENODEV;
2985		}
2986		add_spec_dacs(spec, dac);
2987	}
2988
2989	for (i = 0; i < cfg->hp_outs; i++) {
2990		nid = cfg->hp_pins[i];
2991		dac = get_unassigned_dac(codec, nid);
2992		if (dac) {
2993			if (!spec->multiout.hp_nid)
2994				spec->multiout.hp_nid = dac;
2995			else
2996				add_spec_extra_dacs(spec, dac);
2997		}
2998		spec->hp_dacs[i] = dac;
2999	}
3000
3001	for (i = 0; i < cfg->speaker_outs; i++) {
3002		nid = cfg->speaker_pins[i];
3003		dac = get_unassigned_dac(codec, nid);
3004		if (dac)
3005			add_spec_extra_dacs(spec, dac);
3006		spec->speaker_dacs[i] = dac;
3007	}
3008
3009	/* add line-in as output */
3010	nid = check_line_out_switch(codec);
3011	if (nid) {
3012		dac = get_unassigned_dac(codec, nid);
3013		if (dac) {
3014			snd_printdd("STAC: Add line-in 0x%x as output %d\n",
3015				    nid, cfg->line_outs);
3016			cfg->line_out_pins[cfg->line_outs] = nid;
3017			cfg->line_outs++;
3018			spec->line_switch = nid;
3019			add_spec_dacs(spec, dac);
3020		}
3021	}
3022	/* add mic as output */
3023	nid = check_mic_out_switch(codec);
3024	if (nid) {
3025		dac = get_unassigned_dac(codec, nid);
3026		if (dac) {
3027			snd_printdd("STAC: Add mic-in 0x%x as output %d\n",
3028				    nid, cfg->line_outs);
3029			cfg->line_out_pins[cfg->line_outs] = nid;
3030			cfg->line_outs++;
3031			spec->mic_switch = nid;
3032			add_spec_dacs(spec, dac);
3033		}
3034	}
3035
3036	snd_printd("stac92xx: dac_nids=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
3037		   spec->multiout.num_dacs,
3038		   spec->multiout.dac_nids[0],
3039		   spec->multiout.dac_nids[1],
3040		   spec->multiout.dac_nids[2],
3041		   spec->multiout.dac_nids[3],
3042		   spec->multiout.dac_nids[4]);
3043
3044	return 0;
3045}
3046
3047/* create volume control/switch for the given prefx type */
3048static int create_controls_idx(struct hda_codec *codec, const char *pfx,
3049			       int idx, hda_nid_t nid, int chs)
3050{
3051	struct sigmatel_spec *spec = codec->spec;
3052	char name[32];
3053	int err;
3054
3055	if (!spec->check_volume_offset) {
3056		unsigned int caps, step, nums, db_scale;
3057		caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3058		step = (caps & AC_AMPCAP_STEP_SIZE) >>
3059			AC_AMPCAP_STEP_SIZE_SHIFT;
3060		step = (step + 1) * 25; /* in .01dB unit */
3061		nums = (caps & AC_AMPCAP_NUM_STEPS) >>
3062			AC_AMPCAP_NUM_STEPS_SHIFT;
3063		db_scale = nums * step;
3064		/* if dB scale is over -64dB, and finer enough,
3065		 * let's reduce it to half
3066		 */
3067		if (db_scale > 6400 && nums >= 0x1f)
3068			spec->volume_offset = nums / 2;
3069		spec->check_volume_offset = 1;
3070	}
3071
3072	sprintf(name, "%s Playback Volume", pfx);
3073	err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_VOL, idx, name,
3074		HDA_COMPOSE_AMP_VAL_OFS(nid, chs, 0, HDA_OUTPUT,
3075					spec->volume_offset));
3076	if (err < 0)
3077		return err;
3078	sprintf(name, "%s Playback Switch", pfx);
3079	err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_MUTE, idx, name,
3080				   HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
3081	if (err < 0)
3082		return err;
3083	return 0;
3084}
3085
3086#define create_controls(codec, pfx, nid, chs) \
3087	create_controls_idx(codec, pfx, 0, nid, chs)
3088
3089static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
3090{
3091	if (spec->multiout.num_dacs > 4) {
3092		printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
3093		return 1;
3094	} else {
3095		spec->multiout.dac_nids[spec->multiout.num_dacs] = nid;
3096		spec->multiout.num_dacs++;
3097	}
3098	return 0;
3099}
3100
3101static int add_spec_extra_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
3102{
3103	int i;
3104	for (i = 0; i < ARRAY_SIZE(spec->multiout.extra_out_nid); i++) {
3105		if (!spec->multiout.extra_out_nid[i]) {
3106			spec->multiout.extra_out_nid[i] = nid;
3107			return 0;
3108		}
3109	}
3110	printk(KERN_WARNING "stac92xx: No space for extra DAC 0x%x\n", nid);
3111	return 1;
3112}
3113
3114/* Create output controls
3115 * The mixer elements are named depending on the given type (AUTO_PIN_XXX_OUT)
3116 */
3117static int create_multi_out_ctls(struct hda_codec *codec, int num_outs,
3118				 const hda_nid_t *pins,
3119				 const hda_nid_t *dac_nids,
3120				 int type)
3121{
3122	struct sigmatel_spec *spec = codec->spec;
3123	static const char *chname[4] = {
3124		"Front", "Surround", NULL /*CLFE*/, "Side"
3125	};
3126	hda_nid_t nid;
3127	int i, err;
3128	unsigned int wid_caps;
3129
3130	for (i = 0; i < num_outs && i < ARRAY_SIZE(chname); i++) {
3131		if (type == AUTO_PIN_HP_OUT && !spec->hp_detect) {
3132			wid_caps = get_wcaps(codec, pins[i]);
3133			if (wid_caps & AC_WCAP_UNSOL_CAP)
3134				spec->hp_detect = 1;
3135		}
3136		nid = dac_nids[i];
3137		if (!nid)
3138			continue;
3139		if (type != AUTO_PIN_HP_OUT && i == 2) {
3140			/* Center/LFE */
3141			err = create_controls(codec, "Center", nid, 1);
3142			if (err < 0)
3143				return err;
3144			err = create_controls(codec, "LFE", nid, 2);
3145			if (err < 0)
3146				return err;
3147
3148			wid_caps = get_wcaps(codec, nid);
3149
3150			if (wid_caps & AC_WCAP_LR_SWAP) {
3151				err = stac92xx_add_control(spec,
3152					STAC_CTL_WIDGET_CLFE_SWITCH,
3153					"Swap Center/LFE Playback Switch", nid);
3154
3155				if (err < 0)
3156					return err;
3157			}
3158
3159		} else {
3160			const char *name;
3161			int idx;
3162			switch (type) {
3163			case AUTO_PIN_HP_OUT:
3164				name = "Headphone";
3165				idx = i;
3166				break;
3167			case AUTO_PIN_SPEAKER_OUT:
3168				name = "Speaker";
3169				idx = i;
3170				break;
3171			default:
3172				name = chname[i];
3173				idx = 0;
3174				break;
3175			}
3176			err = create_controls_idx(codec, name, idx, nid, 3);
3177			if (err < 0)
3178				return err;
3179		}
3180	}
3181	return 0;
3182}
3183
3184static int stac92xx_add_capvol_ctls(struct hda_codec *codec, unsigned long vol,
3185				    unsigned long sw, int idx)
3186{
3187	int err;
3188	err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_VOL, idx,
3189				       "Capture Volume", vol);
3190	if (err < 0)
3191		return err;
3192	err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_MUTE, idx,
3193				       "Capture Switch", sw);
3194	if (err < 0)
3195		return err;
3196	return 0;
3197}
3198
3199/* add playback controls from the parsed DAC table */
3200static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
3201					       const struct auto_pin_cfg *cfg)
3202{
3203	struct sigmatel_spec *spec = codec->spec;
3204	hda_nid_t nid;
3205	int err;
3206	int idx;
3207
3208	err = create_multi_out_ctls(codec, cfg->line_outs, cfg->line_out_pins,
3209				    spec->multiout.dac_nids,
3210				    cfg->line_out_type);
3211	if (err < 0)
3212		return err;
3213
3214	if (cfg->hp_outs > 1 && cfg->line_out_type == AUTO_PIN_LINE_OUT) {
3215		err = stac92xx_add_control(spec,
3216			STAC_CTL_WIDGET_HP_SWITCH,
3217			"Headphone as Line Out Switch",
3218			cfg->hp_pins[cfg->hp_outs - 1]);
3219		if (err < 0)
3220			return err;
3221	}
3222
3223	for (idx = AUTO_PIN_MIC; idx <= AUTO_PIN_FRONT_LINE; idx++) {
3224		nid = cfg->input_pins[idx];
3225		if (nid) {
3226			err = stac92xx_add_jack_mode_control(codec, nid, idx);
3227			if (err < 0)
3228				return err;
3229		}
3230	}
3231
3232	return 0;
3233}
3234
3235/* add playback controls for Speaker and HP outputs */
3236static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
3237					struct auto_pin_cfg *cfg)
3238{
3239	struct sigmatel_spec *spec = codec->spec;
3240	int err;
3241
3242	err = create_multi_out_ctls(codec, cfg->hp_outs, cfg->hp_pins,
3243				    spec->hp_dacs, AUTO_PIN_HP_OUT);
3244	if (err < 0)
3245		return err;
3246
3247	err = create_multi_out_ctls(codec, cfg->speaker_outs, cfg->speaker_pins,
3248				    spec->speaker_dacs, AUTO_PIN_SPEAKER_OUT);
3249	if (err < 0)
3250		return err;
3251
3252	return 0;
3253}
3254
3255/* labels for mono mux outputs */
3256static const char *stac92xx_mono_labels[4] = {
3257	"DAC0", "DAC1", "Mixer", "DAC2"
3258};
3259
3260/* create mono mux for mono out on capable codecs */
3261static int stac92xx_auto_create_mono_output_ctls(struct hda_codec *codec)
3262{
3263	struct sigmatel_spec *spec = codec->spec;
3264	struct hda_input_mux *mono_mux = &spec->private_mono_mux;
3265	int i, num_cons;
3266	hda_nid_t con_lst[ARRAY_SIZE(stac92xx_mono_labels)];
3267
3268	num_cons = snd_hda_get_connections(codec,
3269				spec->mono_nid,
3270				con_lst,
3271				HDA_MAX_NUM_INPUTS);
3272	if (num_cons <= 0 || num_cons > ARRAY_SIZE(stac92xx_mono_labels))
3273		return -EINVAL;
3274
3275	for (i = 0; i < num_cons; i++) {
3276		mono_mux->items[mono_mux->num_items].label =
3277					stac92xx_mono_labels[i];
3278		mono_mux->items[mono_mux->num_items].index = i;
3279		mono_mux->num_items++;
3280	}
3281
3282	return stac92xx_add_control(spec, STAC_CTL_WIDGET_MONO_MUX,
3283				"Mono Mux", spec->mono_nid);
3284}
3285
3286/* create PC beep volume controls */
3287static int stac92xx_auto_create_beep_ctls(struct hda_codec *codec,
3288						hda_nid_t nid)
3289{
3290	struct sigmatel_spec *spec = codec->spec;
3291	u32 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3292	int err, type = STAC_CTL_WIDGET_MUTE_BEEP;
3293
3294	if (spec->anabeep_nid == nid)
3295		type = STAC_CTL_WIDGET_MUTE;
3296
3297	/* check for mute support for the the amp */
3298	if ((caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT) {
3299		err = stac92xx_add_control(spec, type,
3300			"Beep Playback Switch",
3301			HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3302			if (err < 0)
3303				return err;
3304	}
3305
3306	/* check to see if there is volume support for the amp */
3307	if ((caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3308		err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL,
3309			"Beep Playback Volume",
3310			HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3311			if (err < 0)
3312				return err;
3313	}
3314	return 0;
3315}
3316
3317#ifdef CONFIG_SND_HDA_INPUT_BEEP
3318#define stac92xx_dig_beep_switch_info snd_ctl_boolean_mono_info
3319
3320static int stac92xx_dig_beep_switch_get(struct snd_kcontrol *kcontrol,
3321					struct snd_ctl_elem_value *ucontrol)
3322{
3323	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3324	ucontrol->value.integer.value[0] = codec->beep->enabled;
3325	return 0;
3326}
3327
3328static int stac92xx_dig_beep_switch_put(struct snd_kcontrol *kcontrol,
3329					struct snd_ctl_elem_value *ucontrol)
3330{
3331	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3332	return snd_hda_enable_beep_device(codec, ucontrol->value.integer.value[0]);
3333}
3334
3335static struct snd_kcontrol_new stac92xx_dig_beep_ctrl = {
3336	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3337	.info = stac92xx_dig_beep_switch_info,
3338	.get = stac92xx_dig_beep_switch_get,
3339	.put = stac92xx_dig_beep_switch_put,
3340};
3341
3342static int stac92xx_beep_switch_ctl(struct hda_codec *codec)
3343{
3344	return stac92xx_add_control_temp(codec->spec, &stac92xx_dig_beep_ctrl,
3345					 0, "Beep Playback Switch", 0);
3346}
3347#endif
3348
3349static int stac92xx_auto_create_mux_input_ctls(struct hda_codec *codec)
3350{
3351	struct sigmatel_spec *spec = codec->spec;
3352	int i, j, err = 0;
3353
3354	for (i = 0; i < spec->num_muxes; i++) {
3355		hda_nid_t nid;
3356		unsigned int wcaps;
3357		unsigned long val;
3358
3359		nid = spec->mux_nids[i];
3360		wcaps = get_wcaps(codec, nid);
3361		if (!(wcaps & AC_WCAP_OUT_AMP))
3362			continue;
3363
3364		/* check whether already the same control was created as
3365		 * normal Capture Volume.
3366		 */
3367		val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3368		for (j = 0; j < spec->num_caps; j++) {
3369			if (spec->capvols[j] == val)
3370				break;
3371		}
3372		if (j < spec->num_caps)
3373			continue;
3374
3375		err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_VOL, i,
3376					       "Mux Capture Volume", val);
3377		if (err < 0)
3378			return err;
3379	}
3380	return 0;
3381};
3382
3383static const char *stac92xx_spdif_labels[3] = {
3384	"Digital Playback", "Analog Mux 1", "Analog Mux 2",
3385};
3386
3387static int stac92xx_auto_create_spdif_mux_ctls(struct hda_codec *codec)
3388{
3389	struct sigmatel_spec *spec = codec->spec;
3390	struct hda_input_mux *spdif_mux = &spec->private_smux;
3391	const char **labels = spec->spdif_labels;
3392	int i, num_cons;
3393	hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
3394
3395	num_cons = snd_hda_get_connections(codec,
3396				spec->smux_nids[0],
3397				con_lst,
3398				HDA_MAX_NUM_INPUTS);
3399	if (num_cons <= 0)
3400		return -EINVAL;
3401
3402	if (!labels)
3403		labels = stac92xx_spdif_labels;
3404
3405	for (i = 0; i < num_cons; i++) {
3406		spdif_mux->items[spdif_mux->num_items].label = labels[i];
3407		spdif_mux->items[spdif_mux->num_items].index = i;
3408		spdif_mux->num_items++;
3409	}
3410
3411	return 0;
3412}
3413
3414/* labels for dmic mux inputs */
3415static const char *stac92xx_dmic_labels[5] = {
3416	"Analog Inputs", "Digital Mic 1", "Digital Mic 2",
3417	"Digital Mic 3", "Digital Mic 4"
3418};
3419
3420static int get_connection_index(struct hda_codec *codec, hda_nid_t mux,
3421				hda_nid_t nid)
3422{
3423	hda_nid_t conn[HDA_MAX_NUM_INPUTS];
3424	int i, nums;
3425
3426	nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
3427	for (i = 0; i < nums; i++)
3428		if (conn[i] == nid)
3429			return i;
3430	return -1;
3431}
3432
3433/* create a volume assigned to the given pin (only if supported) */
3434/* return 1 if the volume control is created */
3435static int create_elem_capture_vol(struct hda_codec *codec, hda_nid_t nid,
3436				   const char *label, int direction)
3437{
3438	unsigned int caps, nums;
3439	char name[32];
3440	int err;
3441
3442	if (direction == HDA_OUTPUT)
3443		caps = AC_WCAP_OUT_AMP;
3444	else
3445		caps = AC_WCAP_IN_AMP;
3446	if (!(get_wcaps(codec, nid) & caps))
3447		return 0;
3448	caps = query_amp_caps(codec, nid, direction);
3449	nums = (caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT;
3450	if (!nums)
3451		return 0;
3452	snprintf(name, sizeof(name), "%s Capture Volume", label);
3453	err = stac92xx_add_control(codec->spec, STAC_CTL_WIDGET_VOL, name,
3454				    HDA_COMPOSE_AMP_VAL(nid, 3, 0, direction));
3455	if (err < 0)
3456		return err;
3457	return 1;
3458}
3459
3460/* create playback/capture controls for input pins on dmic capable codecs */
3461static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
3462						const struct auto_pin_cfg *cfg)
3463{
3464	struct sigmatel_spec *spec = codec->spec;
3465	struct hda_input_mux *imux = &spec->private_imux;
3466	struct hda_input_mux *dimux = &spec->private_dimux;
3467	int err, i, active_mics;
3468	unsigned int def_conf;
3469
3470	dimux->items[dimux->num_items].label = stac92xx_dmic_labels[0];
3471	dimux->items[dimux->num_items].index = 0;
3472	dimux->num_items++;
3473
3474	active_mics = 0;
3475	for (i = 0; i < spec->num_dmics; i++) {
3476		/* check the validity: sometimes it's a dead vendor-spec node */
3477		if (get_wcaps_type(get_wcaps(codec, spec->dmic_nids[i]))
3478		    != AC_WID_PIN)
3479			continue;
3480		def_conf = snd_hda_codec_get_pincfg(codec, spec->dmic_nids[i]);
3481		if (get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)
3482			active_mics++;
3483	}
3484
3485	for (i = 0; i < spec->num_dmics; i++) {
3486		hda_nid_t nid;
3487		int index;
3488		const char *label;
3489
3490		nid = spec->dmic_nids[i];
3491		if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
3492			continue;
3493		def_conf = snd_hda_codec_get_pincfg(codec, nid);
3494		if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
3495			continue;
3496
3497		index = get_connection_index(codec, spec->dmux_nids[0], nid);
3498		if (index < 0)
3499			continue;
3500
3501		if (active_mics == 1)
3502			label = "Digital Mic";
3503		else
3504			label = stac92xx_dmic_labels[dimux->num_items];
3505
3506		err = create_elem_capture_vol(codec, nid, label, HDA_INPUT);
3507		if (err < 0)
3508			return err;
3509		if (!err) {
3510			err = create_elem_capture_vol(codec, nid, label,
3511						      HDA_OUTPUT);
3512			if (err < 0)
3513				return err;
3514		}
3515
3516		dimux->items[dimux->num_items].label = label;
3517		dimux->items[dimux->num_items].index = index;
3518		dimux->num_items++;
3519		if (snd_hda_get_bool_hint(codec, "separate_dmux") != 1) {
3520			imux->items[imux->num_items].label = label;
3521			imux->items[imux->num_items].index = index;
3522			imux->num_items++;
3523		}
3524	}
3525
3526	return 0;
3527}
3528
3529static int check_mic_pin(struct hda_codec *codec, hda_nid_t nid,
3530			 hda_nid_t *fixed, hda_nid_t *ext)
3531{
3532	unsigned int cfg;
3533
3534	if (!nid)
3535		return 0;
3536	cfg = snd_hda_codec_get_pincfg(codec, nid);
3537	switch (get_defcfg_connect(cfg)) {
3538	case AC_JACK_PORT_FIXED:
3539		if (*fixed)
3540			return 1; /* already occupied */
3541		*fixed = nid;
3542		break;
3543	case AC_JACK_PORT_COMPLEX:
3544		if (*ext)
3545			return 1; /* already occupied */
3546		*ext = nid;
3547		break;
3548	}
3549	return 0;
3550}
3551
3552static int set_mic_route(struct hda_codec *codec,
3553			 struct sigmatel_mic_route *mic,
3554			 hda_nid_t pin)
3555{
3556	struct sigmatel_spec *spec = codec->spec;
3557	struct auto_pin_cfg *cfg = &spec->autocfg;
3558	int i;
3559
3560	mic->pin = pin;
3561	for (i = AUTO_PIN_MIC; i <= AUTO_PIN_FRONT_MIC; i++)
3562		if (pin == cfg->input_pins[i])
3563			break;
3564	if (i <= AUTO_PIN_FRONT_MIC) {
3565		/* analog pin */
3566		i = get_connection_index(codec, spec->mux_nids[0], pin);
3567		if (i < 0)
3568			return -1;
3569		mic->mux_idx = i;
3570		mic->dmux_idx = -1;
3571		if (spec->dmux_nids)
3572			mic->dmux_idx = get_connection_index(codec,
3573							     spec->dmux_nids[0],
3574							     spec->mux_nids[0]);
3575	}  else if (spec->dmux_nids) {
3576		/* digital pin */
3577		i = get_connection_index(codec, spec->dmux_nids[0], pin);
3578		if (i < 0)
3579			return -1;
3580		mic->dmux_idx = i;
3581		mic->mux_idx = -1;
3582		if (spec->mux_nids)
3583			mic->mux_idx = get_connection_index(codec,
3584							    spec->mux_nids[0],
3585							    spec->dmux_nids[0]);
3586	}
3587	return 0;
3588}
3589
3590/* return non-zero if the device is for automatic mic switch */
3591static int stac_check_auto_mic(struct hda_codec *codec)
3592{
3593	struct sigmatel_spec *spec = codec->spec;
3594	struct auto_pin_cfg *cfg = &spec->autocfg;
3595	hda_nid_t fixed, ext;
3596	int i;
3597
3598	for (i = AUTO_PIN_LINE; i < AUTO_PIN_LAST; i++) {
3599		if (cfg->input_pins[i])
3600			return 0; /* must be exclusively mics */
3601	}
3602	fixed = ext = 0;
3603	for (i = AUTO_PIN_MIC; i <= AUTO_PIN_FRONT_MIC; i++)
3604		if (check_mic_pin(codec, cfg->input_pins[i], &fixed, &ext))
3605			return 0;
3606	for (i = 0; i < spec->num_dmics; i++)
3607		if (check_mic_pin(codec, spec->dmic_nids[i], &fixed, &ext))
3608			return 0;
3609	if (!fixed || !ext)
3610		return 0;
3611	if (!(get_wcaps(codec, ext) & AC_WCAP_UNSOL_CAP))
3612		return 0; /* no unsol support */
3613	if (set_mic_route(codec, &spec->ext_mic, ext) ||
3614	    set_mic_route(codec, &spec->int_mic, fixed))
3615		return 0; /* something is wrong */
3616	return 1;
3617}
3618
3619/* create playback/capture controls for input pins */
3620static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
3621{
3622	struct sigmatel_spec *spec = codec->spec;
3623	struct hda_input_mux *imux = &spec->private_imux;
3624	int i, j;
3625
3626	for (i = 0; i < AUTO_PIN_LAST; i++) {
3627		hda_nid_t nid = cfg->input_pins[i];
3628		int index, err;
3629
3630		if (!nid)
3631			continue;
3632		index = -1;
3633		for (j = 0; j < spec->num_muxes; j++) {
3634			index = get_connection_index(codec, spec->mux_nids[j],
3635						     nid);
3636			if (index >= 0)
3637				break;
3638		}
3639		if (index < 0)
3640			continue;
3641
3642		err = create_elem_capture_vol(codec, nid,
3643					      auto_pin_cfg_labels[i],
3644					      HDA_INPUT);
3645		if (err < 0)
3646			return err;
3647
3648		imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
3649		imux->items[imux->num_items].index = index;
3650		imux->num_items++;
3651	}
3652	spec->num_analog_muxes = imux->num_items;
3653
3654	if (imux->num_items) {
3655		/*
3656		 * Set the current input for the muxes.
3657		 * The STAC9221 has two input muxes with identical source
3658		 * NID lists.  Hopefully this won't get confused.
3659		 */
3660		for (i = 0; i < spec->num_muxes; i++) {
3661			snd_hda_codec_write_cache(codec, spec->mux_nids[i], 0,
3662						  AC_VERB_SET_CONNECT_SEL,
3663						  imux->items[0].index);
3664		}
3665	}
3666
3667	return 0;
3668}
3669
3670static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
3671{
3672	struct sigmatel_spec *spec = codec->spec;
3673	int i;
3674
3675	for (i = 0; i < spec->autocfg.line_outs; i++) {
3676		hda_nid_t nid = spec->autocfg.line_out_pins[i];
3677		stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
3678	}
3679}
3680
3681static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
3682{
3683	struct sigmatel_spec *spec = codec->spec;
3684	int i;
3685
3686	for (i = 0; i < spec->autocfg.hp_outs; i++) {
3687		hda_nid_t pin;
3688		pin = spec->autocfg.hp_pins[i];
3689		if (pin) /* connect to front */
3690			stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
3691	}
3692	for (i = 0; i < spec->autocfg.speaker_outs; i++) {
3693		hda_nid_t pin;
3694		pin = spec->autocfg.speaker_pins[i];
3695		if (pin) /* connect to front */
3696			stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
3697	}
3698}
3699
3700static int is_dual_headphones(struct hda_codec *codec)
3701{
3702	struct sigmatel_spec *spec = codec->spec;
3703	int i, valid_hps;
3704
3705	if (spec->autocfg.line_out_type != AUTO_PIN_SPEAKER_OUT ||
3706	    spec->autocfg.hp_outs <= 1)
3707		return 0;
3708	valid_hps = 0;
3709	for (i = 0; i < spec->autocfg.hp_outs; i++) {
3710		hda_nid_t nid = spec->autocfg.hp_pins[i];
3711		unsigned int cfg = snd_hda_codec_get_pincfg(codec, nid);
3712		if (get_defcfg_location(cfg) & AC_JACK_LOC_SEPARATE)
3713			continue;
3714		valid_hps++;
3715	}
3716	return (valid_hps > 1);
3717}
3718
3719
3720static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out, hda_nid_t dig_in)
3721{
3722	struct sigmatel_spec *spec = codec->spec;
3723	int hp_swap = 0;
3724	int i, err;
3725
3726	if ((err = snd_hda_parse_pin_def_config(codec,
3727						&spec->autocfg,
3728						spec->dmic_nids)) < 0)
3729		return err;
3730	if (! spec->autocfg.line_outs)
3731		return 0; /* can't find valid pin config */
3732
3733	/* If we have no real line-out pin and multiple hp-outs, HPs should
3734	 * be set up as multi-channel outputs.
3735	 */
3736	if (is_dual_headphones(codec)) {
3737		/* Copy hp_outs to line_outs, backup line_outs in
3738		 * speaker_outs so that the following routines can handle
3739		 * HP pins as primary outputs.
3740		 */
3741		snd_printdd("stac92xx: Enabling multi-HPs workaround\n");
3742		memcpy(spec->autocfg.speaker_pins, spec->autocfg.line_out_pins,
3743		       sizeof(spec->autocfg.line_out_pins));
3744		spec->autocfg.speaker_outs = spec->autocfg.line_outs;
3745		memcpy(spec->autocfg.line_out_pins, spec->autocfg.hp_pins,
3746		       sizeof(spec->autocfg.hp_pins));
3747		spec->autocfg.line_outs = spec->autocfg.hp_outs;
3748		spec->autocfg.line_out_type = AUTO_PIN_HP_OUT;
3749		spec->autocfg.hp_outs = 0;
3750		hp_swap = 1;
3751	}
3752	if (spec->autocfg.mono_out_pin) {
3753		int dir = get_wcaps(codec, spec->autocfg.mono_out_pin) &
3754			(AC_WCAP_OUT_AMP | AC_WCAP_IN_AMP);
3755		u32 caps = query_amp_caps(codec,
3756				spec->autocfg.mono_out_pin, dir);
3757		hda_nid_t conn_list[1];
3758
3759		/* get the mixer node and then the mono mux if it exists */
3760		if (snd_hda_get_connections(codec,
3761				spec->autocfg.mono_out_pin, conn_list, 1) &&
3762				snd_hda_get_connections(codec, conn_list[0],
3763				conn_list, 1) > 0) {
3764
3765				int wcaps = get_wcaps(codec, conn_list[0]);
3766				int wid_type = get_wcaps_type(wcaps);
3767				/* LR swap check, some stac925x have a mux that
3768 				 * changes the DACs output path instead of the
3769 				 * mono-mux path.
3770 				 */
3771				if (wid_type == AC_WID_AUD_SEL &&
3772						!(wcaps & AC_WCAP_LR_SWAP))
3773					spec->mono_nid = conn_list[0];
3774		}
3775		if (dir) {
3776			hda_nid_t nid = spec->autocfg.mono_out_pin;
3777
3778			/* most mono outs have a least a mute/unmute switch */
3779			dir = (dir & AC_WCAP_OUT_AMP) ? HDA_OUTPUT : HDA_INPUT;
3780			err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE,
3781				"Mono Playback Switch",
3782				HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
3783			if (err < 0)
3784				return err;
3785			/* check for volume support for the amp */
3786			if ((caps & AC_AMPCAP_NUM_STEPS)
3787					>> AC_AMPCAP_NUM_STEPS_SHIFT) {
3788				err = stac92xx_add_control(spec,
3789					STAC_CTL_WIDGET_VOL,
3790					"Mono Playback Volume",
3791				HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
3792				if (err < 0)
3793					return err;
3794			}
3795		}
3796
3797		stac92xx_auto_set_pinctl(codec, spec->autocfg.mono_out_pin,
3798					 AC_PINCTL_OUT_EN);
3799	}
3800
3801	if (!spec->multiout.num_dacs) {
3802		err = stac92xx_auto_fill_dac_nids(codec);
3803		if (err < 0)
3804			return err;
3805		err = stac92xx_auto_create_multi_out_ctls(codec,
3806							  &spec->autocfg);
3807		if (err < 0)
3808			return err;
3809	}
3810
3811	/* setup analog beep controls */
3812	if (spec->anabeep_nid > 0) {
3813		err = stac92xx_auto_create_beep_ctls(codec,
3814			spec->anabeep_nid);
3815		if (err < 0)
3816			return err;
3817	}
3818
3819	/* setup digital beep controls and input device */
3820#ifdef CONFIG_SND_HDA_INPUT_BEEP
3821	if (spec->digbeep_nid > 0) {
3822		hda_nid_t nid = spec->digbeep_nid;
3823		unsigned int caps;
3824
3825		err = stac92xx_auto_create_beep_ctls(codec, nid);
3826		if (err < 0)
3827			return err;
3828		err = snd_hda_attach_beep_device(codec, nid);
3829		if (err < 0)
3830			return err;
3831		if (codec->beep) {
3832			/* IDT/STAC codecs have linear beep tone parameter */
3833			codec->beep->linear_tone = spec->linear_tone_beep;
3834			/* if no beep switch is available, make its own one */
3835			caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3836			if (!(caps & AC_AMPCAP_MUTE)) {
3837				err = stac92xx_beep_switch_ctl(codec);
3838				if (err < 0)
3839					return err;
3840			}
3841		}
3842	}
3843#endif
3844
3845	err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg);
3846	if (err < 0)
3847		return err;
3848
3849	/* All output parsing done, now restore the swapped hp pins */
3850	if (hp_swap) {
3851		memcpy(spec->autocfg.hp_pins, spec->autocfg.line_out_pins,
3852		       sizeof(spec->autocfg.hp_pins));
3853		spec->autocfg.hp_outs = spec->autocfg.line_outs;
3854		spec->autocfg.line_out_type = AUTO_PIN_HP_OUT;
3855		spec->autocfg.line_outs = 0;
3856	}
3857
3858	if (stac_check_auto_mic(codec)) {
3859		spec->auto_mic = 1;
3860		/* only one capture for auto-mic */
3861		spec->num_adcs = 1;
3862		spec->num_caps = 1;
3863		spec->num_muxes = 1;
3864	}
3865
3866	for (i = 0; i < spec->num_caps; i++) {
3867		err = stac92xx_add_capvol_ctls(codec, spec->capvols[i],
3868					       spec->capsws[i], i);
3869		if (err < 0)
3870			return err;
3871	}
3872
3873	err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg);
3874	if (err < 0)
3875		return err;
3876
3877	if (spec->mono_nid > 0) {
3878		err = stac92xx_auto_create_mono_output_ctls(codec);
3879		if (err < 0)
3880			return err;
3881	}
3882	if (spec->num_dmics > 0 && !spec->dinput_mux)
3883		if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
3884						&spec->autocfg)) < 0)
3885			return err;
3886	if (spec->num_muxes > 0) {
3887		err = stac92xx_auto_create_mux_input_ctls(codec);
3888		if (err < 0)
3889			return err;
3890	}
3891	if (spec->num_smuxes > 0) {
3892		err = stac92xx_auto_create_spdif_mux_ctls(codec);
3893		if (err < 0)
3894			return err;
3895	}
3896
3897	err = stac92xx_add_input_source(spec);
3898	if (err < 0)
3899		return err;
3900
3901	spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3902	if (spec->multiout.max_channels > 2)
3903		spec->surr_switch = 1;
3904
3905	if (spec->autocfg.dig_outs)
3906		spec->multiout.dig_out_nid = dig_out;
3907	if (dig_in && spec->autocfg.dig_in_pin)
3908		spec->dig_in_nid = dig_in;
3909
3910	if (spec->kctls.list)
3911		spec->mixers[spec->num_mixers++] = spec->kctls.list;
3912
3913	spec->input_mux = &spec->private_imux;
3914	if (!spec->dinput_mux)
3915		spec->dinput_mux = &spec->private_dimux;
3916	spec->sinput_mux = &spec->private_smux;
3917	spec->mono_mux = &spec->private_mono_mux;
3918	return 1;
3919}
3920
3921/* add playback controls for HP output */
3922static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
3923					struct auto_pin_cfg *cfg)
3924{
3925	struct sigmatel_spec *spec = codec->spec;
3926	hda_nid_t pin = cfg->hp_pins[0];
3927	unsigned int wid_caps;
3928
3929	if (! pin)
3930		return 0;
3931
3932	wid_caps = get_wcaps(codec, pin);
3933	if (wid_caps & AC_WCAP_UNSOL_CAP)
3934		spec->hp_detect = 1;
3935
3936	return 0;
3937}
3938
3939/* add playback controls for LFE output */
3940static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
3941					struct auto_pin_cfg *cfg)
3942{
3943	struct sigmatel_spec *spec = codec->spec;
3944	int err;
3945	hda_nid_t lfe_pin = 0x0;
3946	int i;
3947
3948	/*
3949	 * search speaker outs and line outs for a mono speaker pin
3950	 * with an amp.  If one is found, add LFE controls
3951	 * for it.
3952	 */
3953	for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
3954		hda_nid_t pin = spec->autocfg.speaker_pins[i];
3955		unsigned int wcaps = get_wcaps(codec, pin);
3956		wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
3957		if (wcaps == AC_WCAP_OUT_AMP)
3958			/* found a mono speaker with an amp, must be lfe */
3959			lfe_pin = pin;
3960	}
3961
3962	/* if speaker_outs is 0, then speakers may be in line_outs */
3963	if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
3964		for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
3965			hda_nid_t pin = spec->autocfg.line_out_pins[i];
3966			unsigned int defcfg;
3967			defcfg = snd_hda_codec_get_pincfg(codec, pin);
3968			if (get_defcfg_device(defcfg) == AC_JACK_SPEAKER) {
3969				unsigned int wcaps = get_wcaps(codec, pin);
3970				wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
3971				if (wcaps == AC_WCAP_OUT_AMP)
3972					/* found a mono speaker with an amp,
3973					   must be lfe */
3974					lfe_pin = pin;
3975			}
3976		}
3977	}
3978
3979	if (lfe_pin) {
3980		err = create_controls(codec, "LFE", lfe_pin, 1);
3981		if (err < 0)
3982			return err;
3983	}
3984
3985	return 0;
3986}
3987
3988static int stac9200_parse_auto_config(struct hda_codec *codec)
3989{
3990	struct sigmatel_spec *spec = codec->spec;
3991	int err;
3992
3993	if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
3994		return err;
3995
3996	if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
3997		return err;
3998
3999	if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
4000		return err;
4001
4002	if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
4003		return err;
4004
4005	if (spec->num_muxes > 0) {
4006		err = stac92xx_auto_create_mux_input_ctls(codec);
4007		if (err < 0)
4008			return err;
4009	}
4010
4011	err = stac92xx_add_input_source(spec);
4012	if (err < 0)
4013		return err;
4014
4015	if (spec->autocfg.dig_outs)
4016		spec->multiout.dig_out_nid = 0x05;
4017	if (spec->autocfg.dig_in_pin)
4018		spec->dig_in_nid = 0x04;
4019
4020	if (spec->kctls.list)
4021		spec->mixers[spec->num_mixers++] = spec->kctls.list;
4022
4023	spec->input_mux = &spec->private_imux;
4024	spec->dinput_mux = &spec->private_dimux;
4025
4026	return 1;
4027}
4028
4029/*
4030 * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
4031 * funky external mute control using GPIO pins.
4032 */
4033
4034static void stac_gpio_set(struct hda_codec *codec, unsigned int mask,
4035			  unsigned int dir_mask, unsigned int data)
4036{
4037	unsigned int gpiostate, gpiomask, gpiodir;
4038
4039	gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
4040				       AC_VERB_GET_GPIO_DATA, 0);
4041	gpiostate = (gpiostate & ~dir_mask) | (data & dir_mask);
4042
4043	gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
4044				      AC_VERB_GET_GPIO_MASK, 0);
4045	gpiomask |= mask;
4046
4047	gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
4048				     AC_VERB_GET_GPIO_DIRECTION, 0);
4049	gpiodir |= dir_mask;
4050
4051	/* Configure GPIOx as CMOS */
4052	snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
4053
4054	snd_hda_codec_write(codec, codec->afg, 0,
4055			    AC_VERB_SET_GPIO_MASK, gpiomask);
4056	snd_hda_codec_read(codec, codec->afg, 0,
4057			   AC_VERB_SET_GPIO_DIRECTION, gpiodir); /* sync */
4058
4059	msleep(1);
4060
4061	snd_hda_codec_read(codec, codec->afg, 0,
4062			   AC_VERB_SET_GPIO_DATA, gpiostate); /* sync */
4063}
4064
4065#ifdef CONFIG_SND_HDA_INPUT_JACK
4066static void stac92xx_free_jack_priv(struct snd_jack *jack)
4067{
4068	struct sigmatel_jack *jacks = jack->private_data;
4069	jacks->nid = 0;
4070	jacks->jack = NULL;
4071}
4072#endif
4073
4074static int stac92xx_add_jack(struct hda_codec *codec,
4075		hda_nid_t nid, int type)
4076{
4077#ifdef CONFIG_SND_HDA_INPUT_JACK
4078	struct sigmatel_spec *spec = codec->spec;
4079	struct sigmatel_jack *jack;
4080	int def_conf = snd_hda_codec_get_pincfg(codec, nid);
4081	int connectivity = get_defcfg_connect(def_conf);
4082	char name[32];
4083	int err;
4084
4085	if (connectivity && connectivity != AC_JACK_PORT_FIXED)
4086		return 0;
4087
4088	snd_array_init(&spec->jacks, sizeof(*jack), 32);
4089	jack = snd_array_new(&spec->jacks);
4090	if (!jack)
4091		return -ENOMEM;
4092	jack->nid = nid;
4093	jack->type = type;
4094
4095	snprintf(name, sizeof(name), "%s at %s %s Jack",
4096		snd_hda_get_jack_type(def_conf),
4097		snd_hda_get_jack_connectivity(def_conf),
4098		snd_hda_get_jack_location(def_conf));
4099
4100	err = snd_jack_new(codec->bus->card, name, type, &jack->jack);
4101	if (err < 0) {
4102		jack->nid = 0;
4103		return err;
4104	}
4105	jack->jack->private_data = jack;
4106	jack->jack->private_free = stac92xx_free_jack_priv;
4107#endif
4108	return 0;
4109}
4110
4111static int stac_add_event(struct sigmatel_spec *spec, hda_nid_t nid,
4112			  unsigned char type, int data)
4113{
4114	struct sigmatel_event *event;
4115
4116	snd_array_init(&spec->events, sizeof(*event), 32);
4117	event = snd_array_new(&spec->events);
4118	if (!event)
4119		return -ENOMEM;
4120	event->nid = nid;
4121	event->type = type;
4122	event->tag = spec->events.used;
4123	event->data = data;
4124
4125	return event->tag;
4126}
4127
4128static struct sigmatel_event *stac_get_event(struct hda_codec *codec,
4129					     hda_nid_t nid)
4130{
4131	struct sigmatel_spec *spec = codec->spec;
4132	struct sigmatel_event *event = spec->events.list;
4133	int i;
4134
4135	for (i = 0; i < spec->events.used; i++, event++) {
4136		if (event->nid == nid)
4137			return event;
4138	}
4139	return NULL;
4140}
4141
4142static struct sigmatel_event *stac_get_event_from_tag(struct hda_codec *codec,
4143						      unsigned char tag)
4144{
4145	struct sigmatel_spec *spec = codec->spec;
4146	struct sigmatel_event *event = spec->events.list;
4147	int i;
4148
4149	for (i = 0; i < spec->events.used; i++, event++) {
4150		if (event->tag == tag)
4151			return event;
4152	}
4153	return NULL;
4154}
4155
4156/* check if given nid is a valid pin and no other events are assigned
4157 * to it.  If OK, assign the event, set the unsol flag, and returns 1.
4158 * Otherwise, returns zero.
4159 */
4160static int enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
4161			     unsigned int type)
4162{
4163	struct sigmatel_event *event;
4164	int tag;
4165
4166	if (!(get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP))
4167		return 0;
4168	event = stac_get_event(codec, nid);
4169	if (event) {
4170		if (event->type != type)
4171			return 0;
4172		tag = event->tag;
4173	} else {
4174		tag = stac_add_event(codec->spec, nid, type, 0);
4175		if (tag < 0)
4176			return 0;
4177	}
4178	snd_hda_codec_write_cache(codec, nid, 0,
4179				  AC_VERB_SET_UNSOLICITED_ENABLE,
4180				  AC_USRSP_EN | tag);
4181	return 1;
4182}
4183
4184static int is_nid_hp_pin(struct auto_pin_cfg *cfg, hda_nid_t nid)
4185{
4186	int i;
4187	for (i = 0; i < cfg->hp_outs; i++)
4188		if (cfg->hp_pins[i] == nid)
4189			return 1; /* nid is a HP-Out */
4190
4191	return 0; /* nid is not a HP-Out */
4192};
4193
4194static void stac92xx_power_down(struct hda_codec *codec)
4195{
4196	struct sigmatel_spec *spec = codec->spec;
4197
4198	/* power down inactive DACs */
4199	hda_nid_t *dac;
4200	for (dac = spec->dac_list; *dac; dac++)
4201		if (!check_all_dac_nids(spec, *dac))
4202			snd_hda_codec_write(codec, *dac, 0,
4203					AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
4204}
4205
4206static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
4207				  int enable);
4208
4209static inline int get_int_hint(struct hda_codec *codec, const char *key,
4210			       int *valp)
4211{
4212	const char *p;
4213	p = snd_hda_get_hint(codec, key);
4214	if (p) {
4215		unsigned long val;
4216		if (!strict_strtoul(p, 0, &val)) {
4217			*valp = val;
4218			return 1;
4219		}
4220	}
4221	return 0;
4222}
4223
4224/* override some hints from the hwdep entry */
4225static void stac_store_hints(struct hda_codec *codec)
4226{
4227	struct sigmatel_spec *spec = codec->spec;
4228	int val;
4229
4230	val = snd_hda_get_bool_hint(codec, "hp_detect");
4231	if (val >= 0)
4232		spec->hp_detect = val;
4233	if (get_int_hint(codec, "gpio_mask", &spec->gpio_mask)) {
4234		spec->eapd_mask = spec->gpio_dir = spec->gpio_data =
4235			spec->gpio_mask;
4236	}
4237	if (get_int_hint(codec, "gpio_dir", &spec->gpio_dir))
4238		spec->gpio_mask &= spec->gpio_mask;
4239	if (get_int_hint(codec, "gpio_data", &spec->gpio_data))
4240		spec->gpio_dir &= spec->gpio_mask;
4241	if (get_int_hint(codec, "eapd_mask", &spec->eapd_mask))
4242		spec->eapd_mask &= spec->gpio_mask;
4243	if (get_int_hint(codec, "gpio_mute", &spec->gpio_mute))
4244		spec->gpio_mute &= spec->gpio_mask;
4245	val = snd_hda_get_bool_hint(codec, "eapd_switch");
4246	if (val >= 0)
4247		spec->eapd_switch = val;
4248	get_int_hint(codec, "gpio_led_polarity", &spec->gpio_led_polarity);
4249	if (get_int_hint(codec, "gpio_led", &spec->gpio_led)) {
4250		spec->gpio_mask |= spec->gpio_led;
4251		spec->gpio_dir |= spec->gpio_led;
4252		if (spec->gpio_led_polarity)
4253			spec->gpio_data |= spec->gpio_led;
4254	}
4255}
4256
4257static int stac92xx_init(struct hda_codec *codec)
4258{
4259	struct sigmatel_spec *spec = codec->spec;
4260	struct auto_pin_cfg *cfg = &spec->autocfg;
4261	unsigned int gpio;
4262	int i;
4263
4264	snd_hda_sequence_write(codec, spec->init);
4265
4266	/* power down adcs initially */
4267	if (spec->powerdown_adcs)
4268		for (i = 0; i < spec->num_adcs; i++)
4269			snd_hda_codec_write(codec,
4270				spec->adc_nids[i], 0,
4271				AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
4272
4273	/* override some hints */
4274	stac_store_hints(codec);
4275
4276	/* set up GPIO */
4277	gpio = spec->gpio_data;
4278	/* turn on EAPD statically when spec->eapd_switch isn't set.
4279	 * otherwise, unsol event will turn it on/off dynamically
4280	 */
4281	if (!spec->eapd_switch)
4282		gpio |= spec->eapd_mask;
4283	stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, gpio);
4284
4285	/* set up pins */
4286	if (spec->hp_detect) {
4287		/* Enable unsolicited responses on the HP widget */
4288		for (i = 0; i < cfg->hp_outs; i++) {
4289			hda_nid_t nid = cfg->hp_pins[i];
4290			enable_pin_detect(codec, nid, STAC_HP_EVENT);
4291		}
4292		if (cfg->line_out_type == AUTO_PIN_LINE_OUT &&
4293		    cfg->speaker_outs > 0) {
4294			/* enable pin-detect for line-outs as well */
4295			for (i = 0; i < cfg->line_outs; i++) {
4296				hda_nid_t nid = cfg->line_out_pins[i];
4297				enable_pin_detect(codec, nid, STAC_LO_EVENT);
4298			}
4299		}
4300
4301		/* force to enable the first line-out; the others are set up
4302		 * in unsol_event
4303		 */
4304		stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
4305				AC_PINCTL_OUT_EN);
4306		/* fake event to set up pins */
4307		if (cfg->hp_pins[0])
4308			stac_issue_unsol_event(codec, cfg->hp_pins[0]);
4309		else if (cfg->line_out_pins[0])
4310			stac_issue_unsol_event(codec, cfg->line_out_pins[0]);
4311	} else {
4312		stac92xx_auto_init_multi_out(codec);
4313		stac92xx_auto_init_hp_out(codec);
4314		for (i = 0; i < cfg->hp_outs; i++)
4315			stac_toggle_power_map(codec, cfg->hp_pins[i], 1);
4316	}
4317	if (spec->auto_mic) {
4318		/* initialize connection to analog input */
4319		if (spec->dmux_nids)
4320			snd_hda_codec_write_cache(codec, spec->dmux_nids[0], 0,
4321					  AC_VERB_SET_CONNECT_SEL, 0);
4322		if (enable_pin_detect(codec, spec->ext_mic.pin, STAC_MIC_EVENT))
4323			stac_issue_unsol_event(codec, spec->ext_mic.pin);
4324	}
4325	for (i = 0; i < AUTO_PIN_LAST; i++) {
4326		hda_nid_t nid = cfg->input_pins[i];
4327		if (nid) {
4328			unsigned int pinctl, conf;
4329			if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC) {
4330				/* for mic pins, force to initialize */
4331				pinctl = stac92xx_get_default_vref(codec, nid);
4332				pinctl |= AC_PINCTL_IN_EN;
4333				stac92xx_auto_set_pinctl(codec, nid, pinctl);
4334			} else {
4335				pinctl = snd_hda_codec_read(codec, nid, 0,
4336					AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4337				/* if PINCTL already set then skip */
4338				/* Also, if both INPUT and OUTPUT are set,
4339				 * it must be a BIOS bug; need to override, too
4340				 */
4341				if (!(pinctl & AC_PINCTL_IN_EN) ||
4342				    (pinctl & AC_PINCTL_OUT_EN)) {
4343					pinctl &= ~AC_PINCTL_OUT_EN;
4344					pinctl |= AC_PINCTL_IN_EN;
4345					stac92xx_auto_set_pinctl(codec, nid,
4346								 pinctl);
4347				}
4348			}
4349			conf = snd_hda_codec_get_pincfg(codec, nid);
4350			if (get_defcfg_connect(conf) != AC_JACK_PORT_FIXED) {
4351				if (enable_pin_detect(codec, nid,
4352						      STAC_INSERT_EVENT))
4353					stac_issue_unsol_event(codec, nid);
4354			}
4355		}
4356	}
4357	for (i = 0; i < spec->num_dmics; i++)
4358		stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
4359					AC_PINCTL_IN_EN);
4360	if (cfg->dig_out_pins[0])
4361		stac92xx_auto_set_pinctl(codec, cfg->dig_out_pins[0],
4362					 AC_PINCTL_OUT_EN);
4363	if (cfg->dig_in_pin)
4364		stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
4365					 AC_PINCTL_IN_EN);
4366	for (i = 0; i < spec->num_pwrs; i++)  {
4367		hda_nid_t nid = spec->pwr_nids[i];
4368		int pinctl, def_conf;
4369
4370		/* power on when no jack detection is available */
4371		if (!spec->hp_detect) {
4372			stac_toggle_power_map(codec, nid, 1);
4373			continue;
4374		}
4375
4376		if (is_nid_hp_pin(cfg, nid))
4377			continue; /* already has an unsol event */
4378
4379		pinctl = snd_hda_codec_read(codec, nid, 0,
4380					    AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4381		/* outputs are only ports capable of power management
4382		 * any attempts on powering down a input port cause the
4383		 * referenced VREF to act quirky.
4384		 */
4385		if (pinctl & AC_PINCTL_IN_EN) {
4386			stac_toggle_power_map(codec, nid, 1);
4387			continue;
4388		}
4389		def_conf = snd_hda_codec_get_pincfg(codec, nid);
4390		def_conf = get_defcfg_connect(def_conf);
4391		/* skip any ports that don't have jacks since presence
4392 		 * detection is useless */
4393		if (def_conf != AC_JACK_PORT_COMPLEX) {
4394			if (def_conf != AC_JACK_PORT_NONE)
4395				stac_toggle_power_map(codec, nid, 1);
4396			continue;
4397		}
4398		if (enable_pin_detect(codec, nid, STAC_PWR_EVENT))
4399			stac_issue_unsol_event(codec, nid);
4400	}
4401
4402#ifdef CONFIG_SND_HDA_POWER_SAVE
4403	/* sync mute LED */
4404	if (spec->gpio_led && codec->patch_ops.check_power_status)
4405		codec->patch_ops.check_power_status(codec, 0x01);
4406#endif
4407	if (spec->dac_list)
4408		stac92xx_power_down(codec);
4409	return 0;
4410}
4411
4412static void stac92xx_free_jacks(struct hda_codec *codec)
4413{
4414#ifdef CONFIG_SND_HDA_INPUT_JACK
4415	/* free jack instances manually when clearing/reconfiguring */
4416	struct sigmatel_spec *spec = codec->spec;
4417	if (!codec->bus->shutdown && spec->jacks.list) {
4418		struct sigmatel_jack *jacks = spec->jacks.list;
4419		int i;
4420		for (i = 0; i < spec->jacks.used; i++, jacks++) {
4421			if (jacks->jack)
4422				snd_device_free(codec->bus->card, jacks->jack);
4423		}
4424	}
4425	snd_array_free(&spec->jacks);
4426#endif
4427}
4428
4429static void stac92xx_free_kctls(struct hda_codec *codec)
4430{
4431	struct sigmatel_spec *spec = codec->spec;
4432
4433	if (spec->kctls.list) {
4434		struct snd_kcontrol_new *kctl = spec->kctls.list;
4435		int i;
4436		for (i = 0; i < spec->kctls.used; i++)
4437			kfree(kctl[i].name);
4438	}
4439	snd_array_free(&spec->kctls);
4440}
4441
4442static void stac92xx_shutup(struct hda_codec *codec)
4443{
4444	struct sigmatel_spec *spec = codec->spec;
4445
4446	snd_hda_shutup_pins(codec);
4447
4448	if (spec->eapd_mask)
4449		stac_gpio_set(codec, spec->gpio_mask,
4450				spec->gpio_dir, spec->gpio_data &
4451				~spec->eapd_mask);
4452}
4453
4454static void stac92xx_free(struct hda_codec *codec)
4455{
4456	struct sigmatel_spec *spec = codec->spec;
4457
4458	if (! spec)
4459		return;
4460
4461	stac92xx_shutup(codec);
4462	stac92xx_free_jacks(codec);
4463	snd_array_free(&spec->events);
4464
4465	kfree(spec);
4466	snd_hda_detach_beep_device(codec);
4467}
4468
4469static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
4470				unsigned int flag)
4471{
4472	unsigned int old_ctl, pin_ctl;
4473
4474	pin_ctl = snd_hda_codec_read(codec, nid,
4475			0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
4476
4477	if (pin_ctl & AC_PINCTL_IN_EN) {
4478		struct sigmatel_spec *spec = codec->spec;
4479		if (nid == spec->line_switch || nid == spec->mic_switch)
4480			return;
4481	}
4482
4483	old_ctl = pin_ctl;
4484	/* if setting pin direction bits, clear the current
4485	   direction bits first */
4486	if (flag & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))
4487		pin_ctl &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
4488
4489	pin_ctl |= flag;
4490	if (old_ctl != pin_ctl)
4491		snd_hda_codec_write_cache(codec, nid, 0,
4492					  AC_VERB_SET_PIN_WIDGET_CONTROL,
4493					  pin_ctl);
4494}
4495
4496static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
4497				  unsigned int flag)
4498{
4499	unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
4500			0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
4501	if (pin_ctl & flag)
4502		snd_hda_codec_write_cache(codec, nid, 0,
4503					  AC_VERB_SET_PIN_WIDGET_CONTROL,
4504					  pin_ctl & ~flag);
4505}
4506
4507static inline int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
4508{
4509	if (!nid)
4510		return 0;
4511	return snd_hda_jack_detect(codec, nid);
4512}
4513
4514static void stac92xx_line_out_detect(struct hda_codec *codec,
4515				     int presence)
4516{
4517	struct sigmatel_spec *spec = codec->spec;
4518	struct auto_pin_cfg *cfg = &spec->autocfg;
4519	int i;
4520
4521	for (i = 0; i < cfg->line_outs; i++) {
4522		if (presence)
4523			break;
4524		presence = get_pin_presence(codec, cfg->line_out_pins[i]);
4525		if (presence) {
4526			unsigned int pinctl;
4527			pinctl = snd_hda_codec_read(codec,
4528						    cfg->line_out_pins[i], 0,
4529					    AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4530			if (pinctl & AC_PINCTL_IN_EN)
4531				presence = 0; /* mic- or line-input */
4532		}
4533	}
4534
4535	if (presence) {
4536		/* disable speakers */
4537		for (i = 0; i < cfg->speaker_outs; i++)
4538			stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
4539						AC_PINCTL_OUT_EN);
4540		if (spec->eapd_mask && spec->eapd_switch)
4541			stac_gpio_set(codec, spec->gpio_mask,
4542				spec->gpio_dir, spec->gpio_data &
4543				~spec->eapd_mask);
4544	} else {
4545		/* enable speakers */
4546		for (i = 0; i < cfg->speaker_outs; i++)
4547			stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
4548						AC_PINCTL_OUT_EN);
4549		if (spec->eapd_mask && spec->eapd_switch)
4550			stac_gpio_set(codec, spec->gpio_mask,
4551				spec->gpio_dir, spec->gpio_data |
4552				spec->eapd_mask);
4553	}
4554}
4555
4556/* return non-zero if the hp-pin of the given array index isn't
4557 * a jack-detection target
4558 */
4559static int no_hp_sensing(struct sigmatel_spec *spec, int i)
4560{
4561	struct auto_pin_cfg *cfg = &spec->autocfg;
4562
4563	/* ignore sensing of shared line and mic jacks */
4564	if (cfg->hp_pins[i] == spec->line_switch)
4565		return 1;
4566	if (cfg->hp_pins[i] == spec->mic_switch)
4567		return 1;
4568	/* ignore if the pin is set as line-out */
4569	if (cfg->hp_pins[i] == spec->hp_switch)
4570		return 1;
4571	return 0;
4572}
4573
4574static void stac92xx_hp_detect(struct hda_codec *codec)
4575{
4576	struct sigmatel_spec *spec = codec->spec;
4577	struct auto_pin_cfg *cfg = &spec->autocfg;
4578	int i, presence;
4579
4580	presence = 0;
4581	if (spec->gpio_mute)
4582		presence = !(snd_hda_codec_read(codec, codec->afg, 0,
4583			AC_VERB_GET_GPIO_DATA, 0) & spec->gpio_mute);
4584
4585	for (i = 0; i < cfg->hp_outs; i++) {
4586		if (presence)
4587			break;
4588		if (no_hp_sensing(spec, i))
4589			continue;
4590		presence = get_pin_presence(codec, cfg->hp_pins[i]);
4591		if (presence) {
4592			unsigned int pinctl;
4593			pinctl = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
4594					    AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4595			if (pinctl & AC_PINCTL_IN_EN)
4596				presence = 0; /* mic- or line-input */
4597		}
4598	}
4599
4600	if (presence) {
4601		/* disable lineouts */
4602		if (spec->hp_switch)
4603			stac92xx_reset_pinctl(codec, spec->hp_switch,
4604					      AC_PINCTL_OUT_EN);
4605		for (i = 0; i < cfg->line_outs; i++)
4606			stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
4607						AC_PINCTL_OUT_EN);
4608	} else {
4609		/* enable lineouts */
4610		if (spec->hp_switch)
4611			stac92xx_set_pinctl(codec, spec->hp_switch,
4612					    AC_PINCTL_OUT_EN);
4613		for (i = 0; i < cfg->line_outs; i++)
4614			stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
4615						AC_PINCTL_OUT_EN);
4616	}
4617	stac92xx_line_out_detect(codec, presence);
4618	/* toggle hp outs */
4619	for (i = 0; i < cfg->hp_outs; i++) {
4620		unsigned int val = AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN;
4621		if (no_hp_sensing(spec, i))
4622			continue;
4623		if (presence)
4624			stac92xx_set_pinctl(codec, cfg->hp_pins[i], val);
4625	}
4626}
4627
4628static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
4629				  int enable)
4630{
4631	struct sigmatel_spec *spec = codec->spec;
4632	unsigned int idx, val;
4633
4634	for (idx = 0; idx < spec->num_pwrs; idx++) {
4635		if (spec->pwr_nids[idx] == nid)
4636			break;
4637	}
4638	if (idx >= spec->num_pwrs)
4639		return;
4640
4641	/* several codecs have two power down bits */
4642	if (spec->pwr_mapping)
4643		idx = spec->pwr_mapping[idx];
4644	else
4645		idx = 1 << idx;
4646
4647	val = snd_hda_codec_read(codec, codec->afg, 0, 0x0fec, 0x0) & 0xff;
4648	if (enable)
4649		val &= ~idx;
4650	else
4651		val |= idx;
4652
4653	/* power down unused output ports */
4654	snd_hda_codec_write(codec, codec->afg, 0, 0x7ec, val);
4655}
4656
4657static void stac92xx_pin_sense(struct hda_codec *codec, hda_nid_t nid)
4658{
4659	stac_toggle_power_map(codec, nid, get_pin_presence(codec, nid));
4660}
4661
4662static void stac92xx_report_jack(struct hda_codec *codec, hda_nid_t nid)
4663{
4664	struct sigmatel_spec *spec = codec->spec;
4665	struct sigmatel_jack *jacks = spec->jacks.list;
4666
4667	if (jacks) {
4668		int i;
4669		for (i = 0; i < spec->jacks.used; i++) {
4670			if (jacks->nid == nid) {
4671				unsigned int pin_ctl =
4672					snd_hda_codec_read(codec, nid,
4673					0, AC_VERB_GET_PIN_WIDGET_CONTROL,
4674					 0x00);
4675				int type = jacks->type;
4676				if (type == (SND_JACK_LINEOUT
4677						| SND_JACK_HEADPHONE))
4678					type = (pin_ctl & AC_PINCTL_HP_EN)
4679					? SND_JACK_HEADPHONE : SND_JACK_LINEOUT;
4680				snd_jack_report(jacks->jack,
4681					get_pin_presence(codec, nid)
4682					? type : 0);
4683			}
4684			jacks++;
4685		}
4686	}
4687}
4688
4689static void stac92xx_mic_detect(struct hda_codec *codec)
4690{
4691	struct sigmatel_spec *spec = codec->spec;
4692	struct sigmatel_mic_route *mic;
4693
4694	if (get_pin_presence(codec, spec->ext_mic.pin))
4695		mic = &spec->ext_mic;
4696	else
4697		mic = &spec->int_mic;
4698	if (mic->dmux_idx >= 0)
4699		snd_hda_codec_write_cache(codec, spec->dmux_nids[0], 0,
4700					  AC_VERB_SET_CONNECT_SEL,
4701					  mic->dmux_idx);
4702	if (mic->mux_idx >= 0)
4703		snd_hda_codec_write_cache(codec, spec->mux_nids[0], 0,
4704					  AC_VERB_SET_CONNECT_SEL,
4705					  mic->mux_idx);
4706}
4707
4708static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid)
4709{
4710	struct sigmatel_event *event = stac_get_event(codec, nid);
4711	if (!event)
4712		return;
4713	codec->patch_ops.unsol_event(codec, (unsigned)event->tag << 26);
4714}
4715
4716static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
4717{
4718	struct sigmatel_spec *spec = codec->spec;
4719	struct sigmatel_event *event;
4720	int tag, data;
4721
4722	tag = (res >> 26) & 0x7f;
4723	event = stac_get_event_from_tag(codec, tag);
4724	if (!event)
4725		return;
4726
4727	switch (event->type) {
4728	case STAC_HP_EVENT:
4729	case STAC_LO_EVENT:
4730		stac92xx_hp_detect(codec);
4731		break;
4732	case STAC_MIC_EVENT:
4733		stac92xx_mic_detect(codec);
4734		break;
4735	}
4736
4737	switch (event->type) {
4738	case STAC_HP_EVENT:
4739	case STAC_LO_EVENT:
4740	case STAC_MIC_EVENT:
4741	case STAC_INSERT_EVENT:
4742	case STAC_PWR_EVENT:
4743		if (spec->num_pwrs > 0)
4744			stac92xx_pin_sense(codec, event->nid);
4745		stac92xx_report_jack(codec, event->nid);
4746
4747		switch (codec->subsystem_id) {
4748		case 0x103c308f:
4749			if (event->nid == 0xb) {
4750				int pin = AC_PINCTL_IN_EN;
4751
4752				if (get_pin_presence(codec, 0xa)
4753						&& get_pin_presence(codec, 0xb))
4754					pin |= AC_PINCTL_VREF_80;
4755				if (!get_pin_presence(codec, 0xb))
4756					pin |= AC_PINCTL_VREF_80;
4757
4758				/* toggle VREF state based on mic + hp pin
4759				 * status
4760				 */
4761				stac92xx_auto_set_pinctl(codec, 0x0a, pin);
4762			}
4763		}
4764		break;
4765	case STAC_VREF_EVENT:
4766		data = snd_hda_codec_read(codec, codec->afg, 0,
4767					  AC_VERB_GET_GPIO_DATA, 0);
4768		/* toggle VREF state based on GPIOx status */
4769		snd_hda_codec_write(codec, codec->afg, 0, 0x7e0,
4770				    !!(data & (1 << event->data)));
4771		break;
4772	}
4773}
4774
4775static int hp_blike_system(u32 subsystem_id);
4776
4777static void set_hp_led_gpio(struct hda_codec *codec)
4778{
4779	struct sigmatel_spec *spec = codec->spec;
4780	unsigned int gpio;
4781
4782	if (spec->gpio_led)
4783		return;
4784
4785	gpio = snd_hda_param_read(codec, codec->afg, AC_PAR_GPIO_CAP);
4786	gpio &= AC_GPIO_IO_COUNT;
4787	if (gpio > 3)
4788		spec->gpio_led = 0x08; /* GPIO 3 */
4789	else
4790		spec->gpio_led = 0x01; /* GPIO 0 */
4791}
4792
4793/*
4794 * This method searches for the mute LED GPIO configuration
4795 * provided as OEM string in SMBIOS. The format of that string
4796 * is HP_Mute_LED_P_G or HP_Mute_LED_P
4797 * where P can be 0 or 1 and defines mute LED GPIO control state (low/high)
4798 * that corresponds to the NOT muted state of the master volume
4799 * and G is the index of the GPIO to use as the mute LED control (0..9)
4800 * If _G portion is missing it is assigned based on the codec ID
4801 *
4802 * So, HP B-series like systems may have HP_Mute_LED_0 (current models)
4803 * or  HP_Mute_LED_0_3 (future models) OEM SMBIOS strings
4804 *
4805 *
4806 * The dv-series laptops don't seem to have the HP_Mute_LED* strings in
4807 * SMBIOS - at least the ones I have seen do not have them - which include
4808 * my own system (HP Pavilion dv6-1110ax) and my cousin's
4809 * HP Pavilion dv9500t CTO.
4810 * Need more information on whether it is true across the entire series.
4811 * -- kunal
4812 */
4813static int find_mute_led_gpio(struct hda_codec *codec, int default_polarity)
4814{
4815	struct sigmatel_spec *spec = codec->spec;
4816	const struct dmi_device *dev = NULL;
4817
4818	if ((codec->subsystem_id >> 16) == PCI_VENDOR_ID_HP) {
4819		while ((dev = dmi_find_device(DMI_DEV_TYPE_OEM_STRING,
4820								NULL, dev))) {
4821			if (sscanf(dev->name, "HP_Mute_LED_%d_%d",
4822				  &spec->gpio_led_polarity,
4823				  &spec->gpio_led) == 2) {
4824				spec->gpio_led = 1 << spec->gpio_led;
4825				return 1;
4826			}
4827			if (sscanf(dev->name, "HP_Mute_LED_%d",
4828				  &spec->gpio_led_polarity) == 1) {
4829				set_hp_led_gpio(codec);
4830				return 1;
4831			}
4832		}
4833
4834		/*
4835		 * Fallback case - if we don't find the DMI strings,
4836		 * we statically set the GPIO - if not a B-series system.
4837		 */
4838		if (!hp_blike_system(codec->subsystem_id)) {
4839			set_hp_led_gpio(codec);
4840			spec->gpio_led_polarity = default_polarity;
4841			return 1;
4842		}
4843	}
4844	return 0;
4845}
4846
4847static int hp_blike_system(u32 subsystem_id)
4848{
4849	switch (subsystem_id) {
4850	case 0x103c1520:
4851	case 0x103c1521:
4852	case 0x103c1523:
4853	case 0x103c1524:
4854	case 0x103c1525:
4855	case 0x103c1722:
4856	case 0x103c1723:
4857	case 0x103c1724:
4858	case 0x103c1725:
4859	case 0x103c1726:
4860	case 0x103c1727:
4861	case 0x103c1728:
4862	case 0x103c1729:
4863	case 0x103c172a:
4864	case 0x103c172b:
4865	case 0x103c307e:
4866	case 0x103c307f:
4867	case 0x103c3080:
4868	case 0x103c3081:
4869	case 0x103c7007:
4870	case 0x103c7008:
4871		return 1;
4872	}
4873	return 0;
4874}
4875
4876#ifdef CONFIG_PROC_FS
4877static void stac92hd_proc_hook(struct snd_info_buffer *buffer,
4878			       struct hda_codec *codec, hda_nid_t nid)
4879{
4880	if (nid == codec->afg)
4881		snd_iprintf(buffer, "Power-Map: 0x%02x\n",
4882			    snd_hda_codec_read(codec, nid, 0, 0x0fec, 0x0));
4883}
4884
4885static void analog_loop_proc_hook(struct snd_info_buffer *buffer,
4886				  struct hda_codec *codec,
4887				  unsigned int verb)
4888{
4889	snd_iprintf(buffer, "Analog Loopback: 0x%02x\n",
4890		    snd_hda_codec_read(codec, codec->afg, 0, verb, 0));
4891}
4892
4893/* stac92hd71bxx, stac92hd73xx */
4894static void stac92hd7x_proc_hook(struct snd_info_buffer *buffer,
4895				 struct hda_codec *codec, hda_nid_t nid)
4896{
4897	stac92hd_proc_hook(buffer, codec, nid);
4898	if (nid == codec->afg)
4899		analog_loop_proc_hook(buffer, codec, 0xfa0);
4900}
4901
4902static void stac9205_proc_hook(struct snd_info_buffer *buffer,
4903			       struct hda_codec *codec, hda_nid_t nid)
4904{
4905	if (nid == codec->afg)
4906		analog_loop_proc_hook(buffer, codec, 0xfe0);
4907}
4908
4909static void stac927x_proc_hook(struct snd_info_buffer *buffer,
4910			       struct hda_codec *codec, hda_nid_t nid)
4911{
4912	if (nid == codec->afg)
4913		analog_loop_proc_hook(buffer, codec, 0xfeb);
4914}
4915#else
4916#define stac92hd_proc_hook	NULL
4917#define stac92hd7x_proc_hook	NULL
4918#define stac9205_proc_hook	NULL
4919#define stac927x_proc_hook	NULL
4920#endif
4921
4922#ifdef SND_HDA_NEEDS_RESUME
4923static int stac92xx_resume(struct hda_codec *codec)
4924{
4925	struct sigmatel_spec *spec = codec->spec;
4926
4927	stac92xx_init(codec);
4928	snd_hda_codec_resume_amp(codec);
4929	snd_hda_codec_resume_cache(codec);
4930	/* fake event to set up pins again to override cached values */
4931	if (spec->hp_detect) {
4932		if (spec->autocfg.hp_pins[0])
4933			stac_issue_unsol_event(codec, spec->autocfg.hp_pins[0]);
4934		else if (spec->autocfg.line_out_pins[0])
4935			stac_issue_unsol_event(codec,
4936					       spec->autocfg.line_out_pins[0]);
4937	}
4938#ifdef CONFIG_SND_HDA_POWER_SAVE
4939	/* sync mute LED */
4940	if (spec->gpio_led && codec->patch_ops.check_power_status)
4941		codec->patch_ops.check_power_status(codec, 0x01);
4942#endif
4943	return 0;
4944}
4945
4946/*
4947 * using power check for controlling mute led of HP notebooks
4948 * check for mute state only on Speakers (nid = 0x10)
4949 *
4950 * For this feature CONFIG_SND_HDA_POWER_SAVE is needed, otherwise
4951 * the LED is NOT working properly !
4952 *
4953 * Changed name to reflect that it now works for any designated
4954 * model, not just HP HDX.
4955 */
4956
4957#ifdef CONFIG_SND_HDA_POWER_SAVE
4958static int stac92xx_hp_check_power_status(struct hda_codec *codec,
4959					      hda_nid_t nid)
4960{
4961	struct sigmatel_spec *spec = codec->spec;
4962	int i, muted = 1;
4963
4964	for (i = 0; i < spec->multiout.num_dacs; i++) {
4965		nid = spec->multiout.dac_nids[i];
4966		if (!(snd_hda_codec_amp_read(codec, nid, 0, HDA_OUTPUT, 0) &
4967		      HDA_AMP_MUTE)) {
4968			muted = 0; /* something heard */
4969			break;
4970		}
4971	}
4972	if (muted)
4973		spec->gpio_data &= ~spec->gpio_led; /* orange */
4974	else
4975		spec->gpio_data |= spec->gpio_led; /* white */
4976
4977	if (!spec->gpio_led_polarity) {
4978		/* LED state is inverted on these systems */
4979		spec->gpio_data ^= spec->gpio_led;
4980	}
4981
4982	stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, spec->gpio_data);
4983	return 0;
4984}
4985#endif
4986
4987static int stac92xx_suspend(struct hda_codec *codec, pm_message_t state)
4988{
4989	stac92xx_shutup(codec);
4990	return 0;
4991}
4992#endif
4993
4994static struct hda_codec_ops stac92xx_patch_ops = {
4995	.build_controls = stac92xx_build_controls,
4996	.build_pcms = stac92xx_build_pcms,
4997	.init = stac92xx_init,
4998	.free = stac92xx_free,
4999	.unsol_event = stac92xx_unsol_event,
5000#ifdef SND_HDA_NEEDS_RESUME
5001	.suspend = stac92xx_suspend,
5002	.resume = stac92xx_resume,
5003#endif
5004	.reboot_notify = stac92xx_shutup,
5005};
5006
5007static int patch_stac9200(struct hda_codec *codec)
5008{
5009	struct sigmatel_spec *spec;
5010	int err;
5011
5012	spec  = kzalloc(sizeof(*spec), GFP_KERNEL);
5013	if (spec == NULL)
5014		return -ENOMEM;
5015
5016	codec->no_trigger_sense = 1;
5017	codec->spec = spec;
5018	spec->linear_tone_beep = 1;
5019	spec->num_pins = ARRAY_SIZE(stac9200_pin_nids);
5020	spec->pin_nids = stac9200_pin_nids;
5021	spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS,
5022							stac9200_models,
5023							stac9200_cfg_tbl);
5024	if (spec->board_config < 0)
5025		snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5026			    codec->chip_name);
5027	else
5028		stac92xx_set_config_regs(codec,
5029					 stac9200_brd_tbl[spec->board_config]);
5030
5031	spec->multiout.max_channels = 2;
5032	spec->multiout.num_dacs = 1;
5033	spec->multiout.dac_nids = stac9200_dac_nids;
5034	spec->adc_nids = stac9200_adc_nids;
5035	spec->mux_nids = stac9200_mux_nids;
5036	spec->num_muxes = 1;
5037	spec->num_dmics = 0;
5038	spec->num_adcs = 1;
5039	spec->num_pwrs = 0;
5040
5041	if (spec->board_config == STAC_9200_M4 ||
5042	    spec->board_config == STAC_9200_M4_2 ||
5043	    spec->board_config == STAC_9200_OQO)
5044		spec->init = stac9200_eapd_init;
5045	else
5046		spec->init = stac9200_core_init;
5047	spec->mixer = stac9200_mixer;
5048
5049	if (spec->board_config == STAC_9200_PANASONIC) {
5050		spec->gpio_mask = spec->gpio_dir = 0x09;
5051		spec->gpio_data = 0x00;
5052	}
5053
5054	err = stac9200_parse_auto_config(codec);
5055	if (err < 0) {
5056		stac92xx_free(codec);
5057		return err;
5058	}
5059
5060	/* CF-74 has no headphone detection, and the driver should *NOT*
5061	 * do detection and HP/speaker toggle because the hardware does it.
5062	 */
5063	if (spec->board_config == STAC_9200_PANASONIC)
5064		spec->hp_detect = 0;
5065
5066	codec->patch_ops = stac92xx_patch_ops;
5067
5068	return 0;
5069}
5070
5071static int patch_stac925x(struct hda_codec *codec)
5072{
5073	struct sigmatel_spec *spec;
5074	int err;
5075
5076	spec  = kzalloc(sizeof(*spec), GFP_KERNEL);
5077	if (spec == NULL)
5078		return -ENOMEM;
5079
5080	codec->no_trigger_sense = 1;
5081	codec->spec = spec;
5082	spec->linear_tone_beep = 1;
5083	spec->num_pins = ARRAY_SIZE(stac925x_pin_nids);
5084	spec->pin_nids = stac925x_pin_nids;
5085
5086	/* Check first for codec ID */
5087	spec->board_config = snd_hda_check_board_codec_sid_config(codec,
5088							STAC_925x_MODELS,
5089							stac925x_models,
5090							stac925x_codec_id_cfg_tbl);
5091
5092	/* Now checks for PCI ID, if codec ID is not found */
5093	if (spec->board_config < 0)
5094		spec->board_config = snd_hda_check_board_config(codec,
5095							STAC_925x_MODELS,
5096							stac925x_models,
5097							stac925x_cfg_tbl);
5098 again:
5099	if (spec->board_config < 0)
5100		snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5101			    codec->chip_name);
5102	else
5103		stac92xx_set_config_regs(codec,
5104					 stac925x_brd_tbl[spec->board_config]);
5105
5106	spec->multiout.max_channels = 2;
5107	spec->multiout.num_dacs = 1;
5108	spec->multiout.dac_nids = stac925x_dac_nids;
5109	spec->adc_nids = stac925x_adc_nids;
5110	spec->mux_nids = stac925x_mux_nids;
5111	spec->num_muxes = 1;
5112	spec->num_adcs = 1;
5113	spec->num_pwrs = 0;
5114	switch (codec->vendor_id) {
5115	case 0x83847632: /* STAC9202  */
5116	case 0x83847633: /* STAC9202D */
5117	case 0x83847636: /* STAC9251  */
5118	case 0x83847637: /* STAC9251D */
5119		spec->num_dmics = STAC925X_NUM_DMICS;
5120		spec->dmic_nids = stac925x_dmic_nids;
5121		spec->num_dmuxes = ARRAY_SIZE(stac925x_dmux_nids);
5122		spec->dmux_nids = stac925x_dmux_nids;
5123		break;
5124	default:
5125		spec->num_dmics = 0;
5126		break;
5127	}
5128
5129	spec->init = stac925x_core_init;
5130	spec->mixer = stac925x_mixer;
5131	spec->num_caps = 1;
5132	spec->capvols = stac925x_capvols;
5133	spec->capsws = stac925x_capsws;
5134
5135	err = stac92xx_parse_auto_config(codec, 0x8, 0x7);
5136	if (!err) {
5137		if (spec->board_config < 0) {
5138			printk(KERN_WARNING "hda_codec: No auto-config is "
5139			       "available, default to model=ref\n");
5140			spec->board_config = STAC_925x_REF;
5141			goto again;
5142		}
5143		err = -EINVAL;
5144	}
5145	if (err < 0) {
5146		stac92xx_free(codec);
5147		return err;
5148	}
5149
5150	codec->patch_ops = stac92xx_patch_ops;
5151
5152	return 0;
5153}
5154
5155static int patch_stac92hd73xx(struct hda_codec *codec)
5156{
5157	struct sigmatel_spec *spec;
5158	hda_nid_t conn[STAC92HD73_DAC_COUNT + 2];
5159	int err = 0;
5160	int num_dacs;
5161
5162	spec  = kzalloc(sizeof(*spec), GFP_KERNEL);
5163	if (spec == NULL)
5164		return -ENOMEM;
5165
5166	codec->no_trigger_sense = 1;
5167	codec->spec = spec;
5168	spec->linear_tone_beep = 0;
5169	codec->slave_dig_outs = stac92hd73xx_slave_dig_outs;
5170	spec->num_pins = ARRAY_SIZE(stac92hd73xx_pin_nids);
5171	spec->pin_nids = stac92hd73xx_pin_nids;
5172	spec->board_config = snd_hda_check_board_config(codec,
5173							STAC_92HD73XX_MODELS,
5174							stac92hd73xx_models,
5175							stac92hd73xx_cfg_tbl);
5176	/* check codec subsystem id if not found */
5177	if (spec->board_config < 0)
5178		spec->board_config =
5179			snd_hda_check_board_codec_sid_config(codec,
5180				STAC_92HD73XX_MODELS, stac92hd73xx_models,
5181				stac92hd73xx_codec_id_cfg_tbl);
5182again:
5183	if (spec->board_config < 0)
5184		snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5185			    codec->chip_name);
5186	else
5187		stac92xx_set_config_regs(codec,
5188				stac92hd73xx_brd_tbl[spec->board_config]);
5189
5190	num_dacs = snd_hda_get_connections(codec, 0x0a,
5191			conn, STAC92HD73_DAC_COUNT + 2) - 1;
5192
5193	if (num_dacs < 3 || num_dacs > 5) {
5194		printk(KERN_WARNING "hda_codec: Could not determine "
5195		       "number of channels defaulting to DAC count\n");
5196		num_dacs = STAC92HD73_DAC_COUNT;
5197	}
5198	spec->init = stac92hd73xx_core_init;
5199	switch (num_dacs) {
5200	case 0x3: /* 6 Channel */
5201		spec->aloopback_ctl = stac92hd73xx_6ch_loopback;
5202		break;
5203	case 0x4: /* 8 Channel */
5204		spec->aloopback_ctl = stac92hd73xx_8ch_loopback;
5205		break;
5206	case 0x5: /* 10 Channel */
5207		spec->aloopback_ctl = stac92hd73xx_10ch_loopback;
5208		break;
5209	}
5210	spec->multiout.dac_nids = spec->dac_nids;
5211
5212	spec->aloopback_mask = 0x01;
5213	spec->aloopback_shift = 8;
5214
5215	spec->digbeep_nid = 0x1c;
5216	spec->mux_nids = stac92hd73xx_mux_nids;
5217	spec->adc_nids = stac92hd73xx_adc_nids;
5218	spec->dmic_nids = stac92hd73xx_dmic_nids;
5219	spec->dmux_nids = stac92hd73xx_dmux_nids;
5220	spec->smux_nids = stac92hd73xx_smux_nids;
5221
5222	spec->num_muxes = ARRAY_SIZE(stac92hd73xx_mux_nids);
5223	spec->num_adcs = ARRAY_SIZE(stac92hd73xx_adc_nids);
5224	spec->num_dmuxes = ARRAY_SIZE(stac92hd73xx_dmux_nids);
5225
5226	spec->num_caps = STAC92HD73XX_NUM_CAPS;
5227	spec->capvols = stac92hd73xx_capvols;
5228	spec->capsws = stac92hd73xx_capsws;
5229
5230	switch (spec->board_config) {
5231	case STAC_DELL_EQ:
5232		spec->init = dell_eq_core_init;
5233		/* fallthru */
5234	case STAC_DELL_M6_AMIC:
5235	case STAC_DELL_M6_DMIC:
5236	case STAC_DELL_M6_BOTH:
5237		spec->num_smuxes = 0;
5238		spec->eapd_switch = 0;
5239
5240		switch (spec->board_config) {
5241		case STAC_DELL_M6_AMIC: /* Analog Mics */
5242			snd_hda_codec_set_pincfg(codec, 0x0b, 0x90A70170);
5243			spec->num_dmics = 0;
5244			break;
5245		case STAC_DELL_M6_DMIC: /* Digital Mics */
5246			snd_hda_codec_set_pincfg(codec, 0x13, 0x90A60160);
5247			spec->num_dmics = 1;
5248			break;
5249		case STAC_DELL_M6_BOTH: /* Both */
5250			snd_hda_codec_set_pincfg(codec, 0x0b, 0x90A70170);
5251			snd_hda_codec_set_pincfg(codec, 0x13, 0x90A60160);
5252			spec->num_dmics = 1;
5253			break;
5254		}
5255		break;
5256	case STAC_ALIENWARE_M17X:
5257		spec->num_dmics = STAC92HD73XX_NUM_DMICS;
5258		spec->num_smuxes = ARRAY_SIZE(stac92hd73xx_smux_nids);
5259		spec->eapd_switch = 0;
5260		break;
5261	default:
5262		spec->num_dmics = STAC92HD73XX_NUM_DMICS;
5263		spec->num_smuxes = ARRAY_SIZE(stac92hd73xx_smux_nids);
5264		spec->eapd_switch = 1;
5265		break;
5266	}
5267	if (spec->board_config != STAC_92HD73XX_REF) {
5268		/* GPIO0 High = Enable EAPD */
5269		spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
5270		spec->gpio_data = 0x01;
5271	}
5272
5273	spec->num_pwrs = ARRAY_SIZE(stac92hd73xx_pwr_nids);
5274	spec->pwr_nids = stac92hd73xx_pwr_nids;
5275
5276	err = stac92xx_parse_auto_config(codec, 0x25, 0x27);
5277
5278	if (!err) {
5279		if (spec->board_config < 0) {
5280			printk(KERN_WARNING "hda_codec: No auto-config is "
5281			       "available, default to model=ref\n");
5282			spec->board_config = STAC_92HD73XX_REF;
5283			goto again;
5284		}
5285		err = -EINVAL;
5286	}
5287
5288	if (err < 0) {
5289		stac92xx_free(codec);
5290		return err;
5291	}
5292
5293	if (spec->board_config == STAC_92HD73XX_NO_JD)
5294		spec->hp_detect = 0;
5295
5296	codec->patch_ops = stac92xx_patch_ops;
5297
5298	codec->proc_widget_hook = stac92hd7x_proc_hook;
5299
5300	return 0;
5301}
5302
5303static int patch_stac92hd83xxx(struct hda_codec *codec)
5304{
5305	struct sigmatel_spec *spec;
5306	hda_nid_t conn[STAC92HD83_DAC_COUNT + 1];
5307	int err;
5308	int num_dacs;
5309
5310	spec  = kzalloc(sizeof(*spec), GFP_KERNEL);
5311	if (spec == NULL)
5312		return -ENOMEM;
5313
5314	codec->no_trigger_sense = 1;
5315	codec->spec = spec;
5316	spec->linear_tone_beep = 1;
5317	codec->slave_dig_outs = stac92hd83xxx_slave_dig_outs;
5318	spec->digbeep_nid = 0x21;
5319	spec->mux_nids = stac92hd83xxx_mux_nids;
5320	spec->num_muxes = ARRAY_SIZE(stac92hd83xxx_mux_nids);
5321	spec->adc_nids = stac92hd83xxx_adc_nids;
5322	spec->num_adcs = ARRAY_SIZE(stac92hd83xxx_adc_nids);
5323	spec->pwr_nids = stac92hd83xxx_pwr_nids;
5324	spec->pwr_mapping = stac92hd83xxx_pwr_mapping;
5325	spec->num_pwrs = ARRAY_SIZE(stac92hd83xxx_pwr_nids);
5326	spec->multiout.dac_nids = spec->dac_nids;
5327
5328	spec->init = stac92hd83xxx_core_init;
5329	spec->num_pins = ARRAY_SIZE(stac92hd83xxx_pin_nids);
5330	spec->pin_nids = stac92hd83xxx_pin_nids;
5331	spec->num_caps = STAC92HD83XXX_NUM_CAPS;
5332	spec->capvols = stac92hd83xxx_capvols;
5333	spec->capsws = stac92hd83xxx_capsws;
5334
5335	spec->board_config = snd_hda_check_board_config(codec,
5336							STAC_92HD83XXX_MODELS,
5337							stac92hd83xxx_models,
5338							stac92hd83xxx_cfg_tbl);
5339again:
5340	if (spec->board_config < 0)
5341		snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5342			    codec->chip_name);
5343	else
5344		stac92xx_set_config_regs(codec,
5345				stac92hd83xxx_brd_tbl[spec->board_config]);
5346
5347	switch (codec->vendor_id) {
5348	case 0x111d7666:
5349	case 0x111d7667:
5350	case 0x111d7668:
5351	case 0x111d7669:
5352	case 0x111d76d1:
5353	case 0x111d76d9:
5354		spec->num_pins = ARRAY_SIZE(stac92hd88xxx_pin_nids);
5355		spec->pin_nids = stac92hd88xxx_pin_nids;
5356		spec->mono_nid = 0;
5357		spec->digbeep_nid = 0;
5358		spec->num_pwrs = 0;
5359		break;
5360	case 0x111d7604:
5361	case 0x111d76d4:
5362	case 0x111d7605:
5363	case 0x111d76d5:
5364		if (spec->board_config == STAC_92HD83XXX_PWR_REF)
5365			break;
5366		spec->num_pwrs = 0;
5367		break;
5368	}
5369
5370	codec->patch_ops = stac92xx_patch_ops;
5371
5372	if (find_mute_led_gpio(codec, 0))
5373		snd_printd("mute LED gpio %d polarity %d\n",
5374				spec->gpio_led,
5375				spec->gpio_led_polarity);
5376
5377#ifdef CONFIG_SND_HDA_POWER_SAVE
5378	if (spec->gpio_led) {
5379		spec->gpio_mask |= spec->gpio_led;
5380		spec->gpio_dir |= spec->gpio_led;
5381		spec->gpio_data |= spec->gpio_led;
5382		/* register check_power_status callback. */
5383		codec->patch_ops.check_power_status =
5384			stac92xx_hp_check_power_status;
5385	}
5386#endif
5387
5388	err = stac92xx_parse_auto_config(codec, 0x1d, 0);
5389	if (!err) {
5390		if (spec->board_config < 0) {
5391			printk(KERN_WARNING "hda_codec: No auto-config is "
5392			       "available, default to model=ref\n");
5393			spec->board_config = STAC_92HD83XXX_REF;
5394			goto again;
5395		}
5396		err = -EINVAL;
5397	}
5398
5399	if (err < 0) {
5400		stac92xx_free(codec);
5401		return err;
5402	}
5403
5404	/* docking output support */
5405	num_dacs = snd_hda_get_connections(codec, 0xF,
5406				conn, STAC92HD83_DAC_COUNT + 1) - 1;
5407	/* skip non-DAC connections */
5408	while (num_dacs >= 0 &&
5409			(get_wcaps_type(get_wcaps(codec, conn[num_dacs]))
5410					!= AC_WID_AUD_OUT))
5411		num_dacs--;
5412	/* set port E and F to select the last DAC */
5413	if (num_dacs >= 0) {
5414		snd_hda_codec_write_cache(codec, 0xE, 0,
5415			AC_VERB_SET_CONNECT_SEL, num_dacs);
5416		snd_hda_codec_write_cache(codec, 0xF, 0,
5417			AC_VERB_SET_CONNECT_SEL, num_dacs);
5418	}
5419
5420	codec->proc_widget_hook = stac92hd_proc_hook;
5421
5422	return 0;
5423}
5424
5425/* get the pin connection (fixed, none, etc) */
5426static unsigned int stac_get_defcfg_connect(struct hda_codec *codec, int idx)
5427{
5428	struct sigmatel_spec *spec = codec->spec;
5429	unsigned int cfg;
5430
5431	cfg = snd_hda_codec_get_pincfg(codec, spec->pin_nids[idx]);
5432	return get_defcfg_connect(cfg);
5433}
5434
5435static int stac92hd71bxx_connected_ports(struct hda_codec *codec,
5436					 hda_nid_t *nids, int num_nids)
5437{
5438	struct sigmatel_spec *spec = codec->spec;
5439	int idx, num;
5440	unsigned int def_conf;
5441
5442	for (num = 0; num < num_nids; num++) {
5443		for (idx = 0; idx < spec->num_pins; idx++)
5444			if (spec->pin_nids[idx] == nids[num])
5445				break;
5446		if (idx >= spec->num_pins)
5447			break;
5448		def_conf = stac_get_defcfg_connect(codec, idx);
5449		if (def_conf == AC_JACK_PORT_NONE)
5450			break;
5451	}
5452	return num;
5453}
5454
5455static int stac92hd71bxx_connected_smuxes(struct hda_codec *codec,
5456					  hda_nid_t dig0pin)
5457{
5458	struct sigmatel_spec *spec = codec->spec;
5459	int idx;
5460
5461	for (idx = 0; idx < spec->num_pins; idx++)
5462		if (spec->pin_nids[idx] == dig0pin)
5463			break;
5464	if ((idx + 2) >= spec->num_pins)
5465		return 0;
5466
5467	/* dig1pin case */
5468	if (stac_get_defcfg_connect(codec, idx + 1) != AC_JACK_PORT_NONE)
5469		return 2;
5470
5471	/* dig0pin + dig2pin case */
5472	if (stac_get_defcfg_connect(codec, idx + 2) != AC_JACK_PORT_NONE)
5473		return 2;
5474	if (stac_get_defcfg_connect(codec, idx) != AC_JACK_PORT_NONE)
5475		return 1;
5476	else
5477		return 0;
5478}
5479
5480/* HP dv7 bass switch - GPIO5 */
5481#define stac_hp_bass_gpio_info	snd_ctl_boolean_mono_info
5482static int stac_hp_bass_gpio_get(struct snd_kcontrol *kcontrol,
5483				 struct snd_ctl_elem_value *ucontrol)
5484{
5485	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5486	struct sigmatel_spec *spec = codec->spec;
5487	ucontrol->value.integer.value[0] = !!(spec->gpio_data & 0x20);
5488	return 0;
5489}
5490
5491static int stac_hp_bass_gpio_put(struct snd_kcontrol *kcontrol,
5492				 struct snd_ctl_elem_value *ucontrol)
5493{
5494	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5495	struct sigmatel_spec *spec = codec->spec;
5496	unsigned int gpio_data;
5497
5498	gpio_data = (spec->gpio_data & ~0x20) |
5499		(ucontrol->value.integer.value[0] ? 0x20 : 0);
5500	if (gpio_data == spec->gpio_data)
5501		return 0;
5502	spec->gpio_data = gpio_data;
5503	stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, spec->gpio_data);
5504	return 1;
5505}
5506
5507static struct snd_kcontrol_new stac_hp_bass_sw_ctrl = {
5508	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5509	.info = stac_hp_bass_gpio_info,
5510	.get = stac_hp_bass_gpio_get,
5511	.put = stac_hp_bass_gpio_put,
5512};
5513
5514static int stac_add_hp_bass_switch(struct hda_codec *codec)
5515{
5516	struct sigmatel_spec *spec = codec->spec;
5517
5518	if (!stac_control_new(spec, &stac_hp_bass_sw_ctrl,
5519			      "Bass Speaker Playback Switch", 0))
5520		return -ENOMEM;
5521
5522	spec->gpio_mask |= 0x20;
5523	spec->gpio_dir |= 0x20;
5524	spec->gpio_data |= 0x20;
5525	return 0;
5526}
5527
5528static int patch_stac92hd71bxx(struct hda_codec *codec)
5529{
5530	struct sigmatel_spec *spec;
5531	struct hda_verb *unmute_init = stac92hd71bxx_unmute_core_init;
5532	unsigned int pin_cfg;
5533	int err = 0;
5534
5535	spec  = kzalloc(sizeof(*spec), GFP_KERNEL);
5536	if (spec == NULL)
5537		return -ENOMEM;
5538
5539	codec->no_trigger_sense = 1;
5540	codec->spec = spec;
5541	spec->linear_tone_beep = 0;
5542	codec->patch_ops = stac92xx_patch_ops;
5543	spec->num_pins = STAC92HD71BXX_NUM_PINS;
5544	switch (codec->vendor_id) {
5545	case 0x111d76b6:
5546	case 0x111d76b7:
5547		spec->pin_nids = stac92hd71bxx_pin_nids_4port;
5548		break;
5549	case 0x111d7603:
5550	case 0x111d7608:
5551		/* On 92HD75Bx 0x27 isn't a pin nid */
5552		spec->num_pins--;
5553		/* fallthrough */
5554	default:
5555		spec->pin_nids = stac92hd71bxx_pin_nids_6port;
5556	}
5557	spec->num_pwrs = ARRAY_SIZE(stac92hd71bxx_pwr_nids);
5558	spec->board_config = snd_hda_check_board_config(codec,
5559							STAC_92HD71BXX_MODELS,
5560							stac92hd71bxx_models,
5561							stac92hd71bxx_cfg_tbl);
5562again:
5563	if (spec->board_config < 0)
5564		snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5565			    codec->chip_name);
5566	else
5567		stac92xx_set_config_regs(codec,
5568				stac92hd71bxx_brd_tbl[spec->board_config]);
5569
5570	if (spec->board_config != STAC_92HD71BXX_REF) {
5571		/* GPIO0 = EAPD */
5572		spec->gpio_mask = 0x01;
5573		spec->gpio_dir = 0x01;
5574		spec->gpio_data = 0x01;
5575	}
5576
5577	spec->dmic_nids = stac92hd71bxx_dmic_nids;
5578	spec->dmux_nids = stac92hd71bxx_dmux_nids;
5579
5580	spec->num_caps = STAC92HD71BXX_NUM_CAPS;
5581	spec->capvols = stac92hd71bxx_capvols;
5582	spec->capsws = stac92hd71bxx_capsws;
5583
5584	switch (codec->vendor_id) {
5585	case 0x111d76b6: /* 4 Port without Analog Mixer */
5586	case 0x111d76b7:
5587		unmute_init++;
5588		/* fallthru */
5589	case 0x111d76b4: /* 6 Port without Analog Mixer */
5590	case 0x111d76b5:
5591		spec->init = stac92hd71bxx_core_init;
5592		codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
5593		spec->num_dmics = stac92hd71bxx_connected_ports(codec,
5594					stac92hd71bxx_dmic_nids,
5595					STAC92HD71BXX_NUM_DMICS);
5596		break;
5597	case 0x111d7608: /* 5 Port with Analog Mixer */
5598		switch (spec->board_config) {
5599		case STAC_HP_M4:
5600			/* Enable VREF power saving on GPIO1 detect */
5601			err = stac_add_event(spec, codec->afg,
5602					     STAC_VREF_EVENT, 0x02);
5603			if (err < 0)
5604				return err;
5605			snd_hda_codec_write_cache(codec, codec->afg, 0,
5606				AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x02);
5607			snd_hda_codec_write_cache(codec, codec->afg, 0,
5608				AC_VERB_SET_UNSOLICITED_ENABLE,
5609				AC_USRSP_EN | err);
5610			spec->gpio_mask |= 0x02;
5611			break;
5612		}
5613		if ((codec->revision_id & 0xf) == 0 ||
5614		    (codec->revision_id & 0xf) == 1)
5615			spec->stream_delay = 40; /* 40 milliseconds */
5616
5617		/* no output amps */
5618		spec->num_pwrs = 0;
5619		/* disable VSW */
5620		spec->init = stac92hd71bxx_core_init;
5621		unmute_init++;
5622		snd_hda_codec_set_pincfg(codec, 0x0f, 0x40f000f0);
5623		snd_hda_codec_set_pincfg(codec, 0x19, 0x40f000f3);
5624		stac92hd71bxx_dmic_nids[STAC92HD71BXX_NUM_DMICS - 1] = 0;
5625		spec->num_dmics = stac92hd71bxx_connected_ports(codec,
5626					stac92hd71bxx_dmic_nids,
5627					STAC92HD71BXX_NUM_DMICS - 1);
5628		break;
5629	case 0x111d7603: /* 6 Port with Analog Mixer */
5630		if ((codec->revision_id & 0xf) == 1)
5631			spec->stream_delay = 40; /* 40 milliseconds */
5632
5633		/* no output amps */
5634		spec->num_pwrs = 0;
5635		/* fallthru */
5636	default:
5637		spec->init = stac92hd71bxx_core_init;
5638		codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
5639		spec->num_dmics = stac92hd71bxx_connected_ports(codec,
5640					stac92hd71bxx_dmic_nids,
5641					STAC92HD71BXX_NUM_DMICS);
5642		break;
5643	}
5644
5645	if (get_wcaps(codec, 0xa) & AC_WCAP_IN_AMP)
5646		snd_hda_sequence_write_cache(codec, unmute_init);
5647
5648	/* Some HP machines seem to have unstable codec communications
5649	 * especially with ATI fglrx driver.  For recovering from the
5650	 * CORB/RIRB stall, allow the BUS reset and keep always sync
5651	 */
5652	if (spec->board_config == STAC_HP_DV5) {
5653		codec->bus->sync_write = 1;
5654		codec->bus->allow_bus_reset = 1;
5655	}
5656
5657	spec->aloopback_ctl = stac92hd71bxx_loopback;
5658	spec->aloopback_mask = 0x50;
5659	spec->aloopback_shift = 0;
5660
5661	spec->powerdown_adcs = 1;
5662	spec->digbeep_nid = 0x26;
5663	spec->mux_nids = stac92hd71bxx_mux_nids;
5664	spec->adc_nids = stac92hd71bxx_adc_nids;
5665	spec->smux_nids = stac92hd71bxx_smux_nids;
5666	spec->pwr_nids = stac92hd71bxx_pwr_nids;
5667
5668	spec->num_muxes = ARRAY_SIZE(stac92hd71bxx_mux_nids);
5669	spec->num_adcs = ARRAY_SIZE(stac92hd71bxx_adc_nids);
5670	spec->num_dmuxes = ARRAY_SIZE(stac92hd71bxx_dmux_nids);
5671	spec->num_smuxes = stac92hd71bxx_connected_smuxes(codec, 0x1e);
5672
5673	snd_printdd("Found board config: %d\n", spec->board_config);
5674
5675	switch (spec->board_config) {
5676	case STAC_HP_M4:
5677		/* enable internal microphone */
5678		snd_hda_codec_set_pincfg(codec, 0x0e, 0x01813040);
5679		stac92xx_auto_set_pinctl(codec, 0x0e,
5680			AC_PINCTL_IN_EN | AC_PINCTL_VREF_80);
5681		/* fallthru */
5682	case STAC_DELL_M4_2:
5683		spec->num_dmics = 0;
5684		spec->num_smuxes = 0;
5685		spec->num_dmuxes = 0;
5686		break;
5687	case STAC_DELL_M4_1:
5688	case STAC_DELL_M4_3:
5689		spec->num_dmics = 1;
5690		spec->num_smuxes = 0;
5691		spec->num_dmuxes = 1;
5692		break;
5693	case STAC_HP_DV4_1222NR:
5694		spec->num_dmics = 1;
5695		/* I don't know if it needs 1 or 2 smuxes - will wait for
5696		 * bug reports to fix if needed
5697		 */
5698		spec->num_smuxes = 1;
5699		spec->num_dmuxes = 1;
5700		/* fallthrough */
5701	case STAC_HP_DV4:
5702		spec->gpio_led = 0x01;
5703		/* fallthrough */
5704	case STAC_HP_DV5:
5705		snd_hda_codec_set_pincfg(codec, 0x0d, 0x90170010);
5706		stac92xx_auto_set_pinctl(codec, 0x0d, AC_PINCTL_OUT_EN);
5707		/* HP dv6 gives the headphone pin as a line-out.  Thus we
5708		 * need to set hp_detect flag here to force to enable HP
5709		 * detection.
5710		 */
5711		spec->hp_detect = 1;
5712		break;
5713	case STAC_HP_HDX:
5714		spec->num_dmics = 1;
5715		spec->num_dmuxes = 1;
5716		spec->num_smuxes = 1;
5717		spec->gpio_led = 0x08;
5718		break;
5719	}
5720
5721	if (hp_blike_system(codec->subsystem_id)) {
5722		pin_cfg = snd_hda_codec_get_pincfg(codec, 0x0f);
5723		if (get_defcfg_device(pin_cfg) == AC_JACK_LINE_OUT ||
5724			get_defcfg_device(pin_cfg) == AC_JACK_SPEAKER  ||
5725			get_defcfg_device(pin_cfg) == AC_JACK_HP_OUT) {
5726			/* It was changed in the BIOS to just satisfy MS DTM.
5727			 * Lets turn it back into slaved HP
5728			 */
5729			pin_cfg = (pin_cfg & (~AC_DEFCFG_DEVICE))
5730					| (AC_JACK_HP_OUT <<
5731						AC_DEFCFG_DEVICE_SHIFT);
5732			pin_cfg = (pin_cfg & (~(AC_DEFCFG_DEF_ASSOC
5733							| AC_DEFCFG_SEQUENCE)))
5734								| 0x1f;
5735			snd_hda_codec_set_pincfg(codec, 0x0f, pin_cfg);
5736		}
5737	}
5738
5739	if (find_mute_led_gpio(codec, 1))
5740		snd_printd("mute LED gpio %d polarity %d\n",
5741				spec->gpio_led,
5742				spec->gpio_led_polarity);
5743
5744#ifdef CONFIG_SND_HDA_POWER_SAVE
5745	if (spec->gpio_led) {
5746		spec->gpio_mask |= spec->gpio_led;
5747		spec->gpio_dir |= spec->gpio_led;
5748		spec->gpio_data |= spec->gpio_led;
5749		/* register check_power_status callback. */
5750		codec->patch_ops.check_power_status =
5751			stac92xx_hp_check_power_status;
5752	}
5753#endif
5754
5755	spec->multiout.dac_nids = spec->dac_nids;
5756
5757	err = stac92xx_parse_auto_config(codec, 0x21, 0);
5758	if (!err) {
5759		if (spec->board_config < 0) {
5760			printk(KERN_WARNING "hda_codec: No auto-config is "
5761			       "available, default to model=ref\n");
5762			spec->board_config = STAC_92HD71BXX_REF;
5763			goto again;
5764		}
5765		err = -EINVAL;
5766	}
5767
5768	if (err < 0) {
5769		stac92xx_free(codec);
5770		return err;
5771	}
5772
5773	/* enable bass on HP dv7 */
5774	if (spec->board_config == STAC_HP_DV4 ||
5775	    spec->board_config == STAC_HP_DV5) {
5776		unsigned int cap;
5777		cap = snd_hda_param_read(codec, 0x1, AC_PAR_GPIO_CAP);
5778		cap &= AC_GPIO_IO_COUNT;
5779		if (cap >= 6)
5780			stac_add_hp_bass_switch(codec);
5781	}
5782
5783	codec->proc_widget_hook = stac92hd7x_proc_hook;
5784
5785	return 0;
5786}
5787
5788static int patch_stac922x(struct hda_codec *codec)
5789{
5790	struct sigmatel_spec *spec;
5791	int err;
5792
5793	spec  = kzalloc(sizeof(*spec), GFP_KERNEL);
5794	if (spec == NULL)
5795		return -ENOMEM;
5796
5797	codec->no_trigger_sense = 1;
5798	codec->spec = spec;
5799	spec->linear_tone_beep = 1;
5800	spec->num_pins = ARRAY_SIZE(stac922x_pin_nids);
5801	spec->pin_nids = stac922x_pin_nids;
5802	spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS,
5803							stac922x_models,
5804							stac922x_cfg_tbl);
5805	if (spec->board_config == STAC_INTEL_MAC_AUTO) {
5806		spec->gpio_mask = spec->gpio_dir = 0x03;
5807		spec->gpio_data = 0x03;
5808		/* Intel Macs have all same PCI SSID, so we need to check
5809		 * codec SSID to distinguish the exact models
5810		 */
5811		printk(KERN_INFO "hda_codec: STAC922x, Apple subsys_id=%x\n", codec->subsystem_id);
5812		switch (codec->subsystem_id) {
5813
5814		case 0x106b0800:
5815			spec->board_config = STAC_INTEL_MAC_V1;
5816			break;
5817		case 0x106b0600:
5818		case 0x106b0700:
5819			spec->board_config = STAC_INTEL_MAC_V2;
5820			break;
5821		case 0x106b0e00:
5822		case 0x106b0f00:
5823		case 0x106b1600:
5824		case 0x106b1700:
5825		case 0x106b0200:
5826		case 0x106b1e00:
5827			spec->board_config = STAC_INTEL_MAC_V3;
5828			break;
5829		case 0x106b1a00:
5830		case 0x00000100:
5831			spec->board_config = STAC_INTEL_MAC_V4;
5832			break;
5833		case 0x106b0a00:
5834		case 0x106b2200:
5835			spec->board_config = STAC_INTEL_MAC_V5;
5836			break;
5837		default:
5838			spec->board_config = STAC_INTEL_MAC_V3;
5839			break;
5840		}
5841	}
5842
5843 again:
5844	if (spec->board_config < 0)
5845		snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5846			    codec->chip_name);
5847	else
5848		stac92xx_set_config_regs(codec,
5849				stac922x_brd_tbl[spec->board_config]);
5850
5851	spec->adc_nids = stac922x_adc_nids;
5852	spec->mux_nids = stac922x_mux_nids;
5853	spec->num_muxes = ARRAY_SIZE(stac922x_mux_nids);
5854	spec->num_adcs = ARRAY_SIZE(stac922x_adc_nids);
5855	spec->num_dmics = 0;
5856	spec->num_pwrs = 0;
5857
5858	spec->init = stac922x_core_init;
5859
5860	spec->num_caps = STAC922X_NUM_CAPS;
5861	spec->capvols = stac922x_capvols;
5862	spec->capsws = stac922x_capsws;
5863
5864	spec->multiout.dac_nids = spec->dac_nids;
5865
5866	err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
5867	if (!err) {
5868		if (spec->board_config < 0) {
5869			printk(KERN_WARNING "hda_codec: No auto-config is "
5870			       "available, default to model=ref\n");
5871			spec->board_config = STAC_D945_REF;
5872			goto again;
5873		}
5874		err = -EINVAL;
5875	}
5876	if (err < 0) {
5877		stac92xx_free(codec);
5878		return err;
5879	}
5880
5881	codec->patch_ops = stac92xx_patch_ops;
5882
5883	/* Fix Mux capture level; max to 2 */
5884	snd_hda_override_amp_caps(codec, 0x12, HDA_OUTPUT,
5885				  (0 << AC_AMPCAP_OFFSET_SHIFT) |
5886				  (2 << AC_AMPCAP_NUM_STEPS_SHIFT) |
5887				  (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5888				  (0 << AC_AMPCAP_MUTE_SHIFT));
5889
5890	return 0;
5891}
5892
5893static int patch_stac927x(struct hda_codec *codec)
5894{
5895	struct sigmatel_spec *spec;
5896	int err;
5897
5898	spec  = kzalloc(sizeof(*spec), GFP_KERNEL);
5899	if (spec == NULL)
5900		return -ENOMEM;
5901
5902	codec->no_trigger_sense = 1;
5903	codec->spec = spec;
5904	spec->linear_tone_beep = 1;
5905	codec->slave_dig_outs = stac927x_slave_dig_outs;
5906	spec->num_pins = ARRAY_SIZE(stac927x_pin_nids);
5907	spec->pin_nids = stac927x_pin_nids;
5908	spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS,
5909							stac927x_models,
5910							stac927x_cfg_tbl);
5911 again:
5912	if (spec->board_config < 0)
5913		snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5914			    codec->chip_name);
5915	else
5916		stac92xx_set_config_regs(codec,
5917				stac927x_brd_tbl[spec->board_config]);
5918
5919	spec->digbeep_nid = 0x23;
5920	spec->adc_nids = stac927x_adc_nids;
5921	spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
5922	spec->mux_nids = stac927x_mux_nids;
5923	spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
5924	spec->smux_nids = stac927x_smux_nids;
5925	spec->num_smuxes = ARRAY_SIZE(stac927x_smux_nids);
5926	spec->spdif_labels = stac927x_spdif_labels;
5927	spec->dac_list = stac927x_dac_nids;
5928	spec->multiout.dac_nids = spec->dac_nids;
5929
5930	if (spec->board_config != STAC_D965_REF) {
5931		/* GPIO0 High = Enable EAPD */
5932		spec->eapd_mask = spec->gpio_mask = 0x01;
5933		spec->gpio_dir = spec->gpio_data = 0x01;
5934	}
5935
5936	switch (spec->board_config) {
5937	case STAC_D965_3ST:
5938	case STAC_D965_5ST:
5939		/* GPIO0 High = Enable EAPD */
5940		spec->num_dmics = 0;
5941		spec->init = d965_core_init;
5942		break;
5943	case STAC_DELL_BIOS:
5944		switch (codec->subsystem_id) {
5945		case 0x10280209:
5946		case 0x1028022e:
5947			/* correct the device field to SPDIF out */
5948			snd_hda_codec_set_pincfg(codec, 0x21, 0x01442070);
5949			break;
5950		}
5951		/* configure the analog microphone on some laptops */
5952		snd_hda_codec_set_pincfg(codec, 0x0c, 0x90a79130);
5953		/* correct the front output jack as a hp out */
5954		snd_hda_codec_set_pincfg(codec, 0x0f, 0x0227011f);
5955		/* correct the front input jack as a mic */
5956		snd_hda_codec_set_pincfg(codec, 0x0e, 0x02a79130);
5957		/* fallthru */
5958	case STAC_DELL_3ST:
5959		if (codec->subsystem_id != 0x1028022f) {
5960			/* GPIO2 High = Enable EAPD */
5961			spec->eapd_mask = spec->gpio_mask = 0x04;
5962			spec->gpio_dir = spec->gpio_data = 0x04;
5963		}
5964		spec->dmic_nids = stac927x_dmic_nids;
5965		spec->num_dmics = STAC927X_NUM_DMICS;
5966
5967		spec->init = dell_3st_core_init;
5968		spec->dmux_nids = stac927x_dmux_nids;
5969		spec->num_dmuxes = ARRAY_SIZE(stac927x_dmux_nids);
5970		break;
5971	case STAC_927X_VOLKNOB:
5972		spec->num_dmics = 0;
5973		spec->init = stac927x_volknob_core_init;
5974		break;
5975	default:
5976		spec->num_dmics = 0;
5977		spec->init = stac927x_core_init;
5978		break;
5979	}
5980
5981	spec->num_caps = STAC927X_NUM_CAPS;
5982	spec->capvols = stac927x_capvols;
5983	spec->capsws = stac927x_capsws;
5984
5985	spec->num_pwrs = 0;
5986	spec->aloopback_ctl = stac927x_loopback;
5987	spec->aloopback_mask = 0x40;
5988	spec->aloopback_shift = 0;
5989	spec->eapd_switch = 1;
5990
5991	err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
5992	if (!err) {
5993		if (spec->board_config < 0) {
5994			printk(KERN_WARNING "hda_codec: No auto-config is "
5995			       "available, default to model=ref\n");
5996			spec->board_config = STAC_D965_REF;
5997			goto again;
5998		}
5999		err = -EINVAL;
6000	}
6001	if (err < 0) {
6002		stac92xx_free(codec);
6003		return err;
6004	}
6005
6006	codec->patch_ops = stac92xx_patch_ops;
6007
6008	codec->proc_widget_hook = stac927x_proc_hook;
6009
6010	codec->bus->needs_damn_long_delay = 1;
6011
6012	/* no jack detecion for ref-no-jd model */
6013	if (spec->board_config == STAC_D965_REF_NO_JD)
6014		spec->hp_detect = 0;
6015
6016	return 0;
6017}
6018
6019static int patch_stac9205(struct hda_codec *codec)
6020{
6021	struct sigmatel_spec *spec;
6022	int err;
6023
6024	spec  = kzalloc(sizeof(*spec), GFP_KERNEL);
6025	if (spec == NULL)
6026		return -ENOMEM;
6027
6028	codec->no_trigger_sense = 1;
6029	codec->spec = spec;
6030	spec->linear_tone_beep = 1;
6031	spec->num_pins = ARRAY_SIZE(stac9205_pin_nids);
6032	spec->pin_nids = stac9205_pin_nids;
6033	spec->board_config = snd_hda_check_board_config(codec, STAC_9205_MODELS,
6034							stac9205_models,
6035							stac9205_cfg_tbl);
6036 again:
6037	if (spec->board_config < 0)
6038		snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6039			    codec->chip_name);
6040	else
6041		stac92xx_set_config_regs(codec,
6042					 stac9205_brd_tbl[spec->board_config]);
6043
6044	spec->digbeep_nid = 0x23;
6045	spec->adc_nids = stac9205_adc_nids;
6046	spec->num_adcs = ARRAY_SIZE(stac9205_adc_nids);
6047	spec->mux_nids = stac9205_mux_nids;
6048	spec->num_muxes = ARRAY_SIZE(stac9205_mux_nids);
6049	spec->smux_nids = stac9205_smux_nids;
6050	spec->num_smuxes = ARRAY_SIZE(stac9205_smux_nids);
6051	spec->dmic_nids = stac9205_dmic_nids;
6052	spec->num_dmics = STAC9205_NUM_DMICS;
6053	spec->dmux_nids = stac9205_dmux_nids;
6054	spec->num_dmuxes = ARRAY_SIZE(stac9205_dmux_nids);
6055	spec->num_pwrs = 0;
6056
6057	spec->init = stac9205_core_init;
6058	spec->aloopback_ctl = stac9205_loopback;
6059
6060	spec->num_caps = STAC9205_NUM_CAPS;
6061	spec->capvols = stac9205_capvols;
6062	spec->capsws = stac9205_capsws;
6063
6064	spec->aloopback_mask = 0x40;
6065	spec->aloopback_shift = 0;
6066	/* Turn on/off EAPD per HP plugging */
6067	if (spec->board_config != STAC_9205_EAPD)
6068		spec->eapd_switch = 1;
6069	spec->multiout.dac_nids = spec->dac_nids;
6070
6071	switch (spec->board_config){
6072	case STAC_9205_DELL_M43:
6073		/* Enable SPDIF in/out */
6074		snd_hda_codec_set_pincfg(codec, 0x1f, 0x01441030);
6075		snd_hda_codec_set_pincfg(codec, 0x20, 0x1c410030);
6076
6077		/* Enable unsol response for GPIO4/Dock HP connection */
6078		err = stac_add_event(spec, codec->afg, STAC_VREF_EVENT, 0x01);
6079		if (err < 0)
6080			return err;
6081		snd_hda_codec_write_cache(codec, codec->afg, 0,
6082			AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x10);
6083		snd_hda_codec_write_cache(codec, codec->afg, 0,
6084					  AC_VERB_SET_UNSOLICITED_ENABLE,
6085					  AC_USRSP_EN | err);
6086
6087		spec->gpio_dir = 0x0b;
6088		spec->eapd_mask = 0x01;
6089		spec->gpio_mask = 0x1b;
6090		spec->gpio_mute = 0x10;
6091		/* GPIO0 High = EAPD, GPIO1 Low = Headphone Mute,
6092		 * GPIO3 Low = DRM
6093		 */
6094		spec->gpio_data = 0x01;
6095		break;
6096	case STAC_9205_REF:
6097		/* SPDIF-In enabled */
6098		break;
6099	default:
6100		/* GPIO0 High = EAPD */
6101		spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
6102		spec->gpio_data = 0x01;
6103		break;
6104	}
6105
6106	err = stac92xx_parse_auto_config(codec, 0x1f, 0x20);
6107	if (!err) {
6108		if (spec->board_config < 0) {
6109			printk(KERN_WARNING "hda_codec: No auto-config is "
6110			       "available, default to model=ref\n");
6111			spec->board_config = STAC_9205_REF;
6112			goto again;
6113		}
6114		err = -EINVAL;
6115	}
6116	if (err < 0) {
6117		stac92xx_free(codec);
6118		return err;
6119	}
6120
6121	codec->patch_ops = stac92xx_patch_ops;
6122
6123	codec->proc_widget_hook = stac9205_proc_hook;
6124
6125	return 0;
6126}
6127
6128/*
6129 * STAC9872 hack
6130 */
6131
6132static struct hda_verb stac9872_core_init[] = {
6133	{0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
6134	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
6135	{}
6136};
6137
6138static hda_nid_t stac9872_pin_nids[] = {
6139	0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
6140	0x11, 0x13, 0x14,
6141};
6142
6143static hda_nid_t stac9872_adc_nids[] = {
6144	0x8 /*,0x6*/
6145};
6146
6147static hda_nid_t stac9872_mux_nids[] = {
6148	0x15
6149};
6150
6151static unsigned long stac9872_capvols[] = {
6152	HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
6153};
6154#define stac9872_capsws		stac9872_capvols
6155
6156static unsigned int stac9872_vaio_pin_configs[9] = {
6157	0x03211020, 0x411111f0, 0x411111f0, 0x03a15030,
6158	0x411111f0, 0x90170110, 0x411111f0, 0x411111f0,
6159	0x90a7013e
6160};
6161
6162static const char *stac9872_models[STAC_9872_MODELS] = {
6163	[STAC_9872_AUTO] = "auto",
6164	[STAC_9872_VAIO] = "vaio",
6165};
6166
6167static unsigned int *stac9872_brd_tbl[STAC_9872_MODELS] = {
6168	[STAC_9872_VAIO] = stac9872_vaio_pin_configs,
6169};
6170
6171static struct snd_pci_quirk stac9872_cfg_tbl[] = {
6172	SND_PCI_QUIRK_MASK(0x104d, 0xfff0, 0x81e0,
6173			   "Sony VAIO F/S", STAC_9872_VAIO),
6174	{} /* terminator */
6175};
6176
6177static int patch_stac9872(struct hda_codec *codec)
6178{
6179	struct sigmatel_spec *spec;
6180	int err;
6181
6182	spec  = kzalloc(sizeof(*spec), GFP_KERNEL);
6183	if (spec == NULL)
6184		return -ENOMEM;
6185	codec->no_trigger_sense = 1;
6186	codec->spec = spec;
6187	spec->linear_tone_beep = 1;
6188	spec->num_pins = ARRAY_SIZE(stac9872_pin_nids);
6189	spec->pin_nids = stac9872_pin_nids;
6190
6191	spec->board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
6192							stac9872_models,
6193							stac9872_cfg_tbl);
6194	if (spec->board_config < 0)
6195		snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6196			    codec->chip_name);
6197	else
6198		stac92xx_set_config_regs(codec,
6199					 stac9872_brd_tbl[spec->board_config]);
6200
6201	spec->multiout.dac_nids = spec->dac_nids;
6202	spec->num_adcs = ARRAY_SIZE(stac9872_adc_nids);
6203	spec->adc_nids = stac9872_adc_nids;
6204	spec->num_muxes = ARRAY_SIZE(stac9872_mux_nids);
6205	spec->mux_nids = stac9872_mux_nids;
6206	spec->init = stac9872_core_init;
6207	spec->num_caps = 1;
6208	spec->capvols = stac9872_capvols;
6209	spec->capsws = stac9872_capsws;
6210
6211	err = stac92xx_parse_auto_config(codec, 0x10, 0x12);
6212	if (err < 0) {
6213		stac92xx_free(codec);
6214		return -EINVAL;
6215	}
6216	spec->input_mux = &spec->private_imux;
6217	codec->patch_ops = stac92xx_patch_ops;
6218	return 0;
6219}
6220
6221
6222/*
6223 * patch entries
6224 */
6225static struct hda_codec_preset snd_hda_preset_sigmatel[] = {
6226 	{ .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
6227 	{ .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
6228 	{ .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
6229 	{ .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
6230 	{ .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
6231 	{ .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
6232 	{ .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
6233 	{ .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
6234 	{ .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
6235 	{ .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
6236 	{ .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
6237 	{ .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
6238 	{ .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
6239 	{ .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
6240 	{ .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
6241 	{ .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
6242 	{ .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
6243 	{ .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
6244 	{ .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
6245 	{ .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
6246 	{ .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
6247 	{ .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
6248 	{ .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
6249	{ .id = 0x83847632, .name = "STAC9202",  .patch = patch_stac925x },
6250	{ .id = 0x83847633, .name = "STAC9202D", .patch = patch_stac925x },
6251	{ .id = 0x83847634, .name = "STAC9250", .patch = patch_stac925x },
6252	{ .id = 0x83847635, .name = "STAC9250D", .patch = patch_stac925x },
6253	{ .id = 0x83847636, .name = "STAC9251", .patch = patch_stac925x },
6254	{ .id = 0x83847637, .name = "STAC9250D", .patch = patch_stac925x },
6255	{ .id = 0x83847645, .name = "92HD206X", .patch = patch_stac927x },
6256	{ .id = 0x83847646, .name = "92HD206D", .patch = patch_stac927x },
6257 	/* The following does not take into account .id=0x83847661 when subsys =
6258 	 * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
6259 	 * currently not fully supported.
6260 	 */
6261 	{ .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
6262 	{ .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
6263 	{ .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
6264	{ .id = 0x83847698, .name = "STAC9205", .patch = patch_stac9205 },
6265 	{ .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
6266 	{ .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
6267 	{ .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
6268 	{ .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
6269 	{ .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
6270 	{ .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
6271 	{ .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
6272 	{ .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
6273	{ .id = 0x111d7603, .name = "92HD75B3X5", .patch = patch_stac92hd71bxx},
6274	{ .id = 0x111d7604, .name = "92HD83C1X5", .patch = patch_stac92hd83xxx},
6275	{ .id = 0x111d76d4, .name = "92HD83C1C5", .patch = patch_stac92hd83xxx},
6276	{ .id = 0x111d7605, .name = "92HD81B1X5", .patch = patch_stac92hd83xxx},
6277	{ .id = 0x111d76d5, .name = "92HD81B1C5", .patch = patch_stac92hd83xxx},
6278	{ .id = 0x111d76d1, .name = "92HD87B1/3", .patch = patch_stac92hd83xxx},
6279	{ .id = 0x111d76d9, .name = "92HD87B2/4", .patch = patch_stac92hd83xxx},
6280	{ .id = 0x111d7666, .name = "92HD88B3", .patch = patch_stac92hd83xxx},
6281	{ .id = 0x111d7667, .name = "92HD88B1", .patch = patch_stac92hd83xxx},
6282	{ .id = 0x111d7668, .name = "92HD88B2", .patch = patch_stac92hd83xxx},
6283	{ .id = 0x111d7669, .name = "92HD88B4", .patch = patch_stac92hd83xxx},
6284	{ .id = 0x111d7608, .name = "92HD75B2X5", .patch = patch_stac92hd71bxx},
6285	{ .id = 0x111d7674, .name = "92HD73D1X5", .patch = patch_stac92hd73xx },
6286	{ .id = 0x111d7675, .name = "92HD73C1X5", .patch = patch_stac92hd73xx },
6287	{ .id = 0x111d7676, .name = "92HD73E1X5", .patch = patch_stac92hd73xx },
6288	{ .id = 0x111d76b0, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
6289	{ .id = 0x111d76b1, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
6290	{ .id = 0x111d76b2, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
6291	{ .id = 0x111d76b3, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
6292	{ .id = 0x111d76b4, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
6293	{ .id = 0x111d76b5, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
6294	{ .id = 0x111d76b6, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
6295	{ .id = 0x111d76b7, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
6296	{ .id = 0x111d76c0, .name = "92HD89C3", .patch = patch_stac92hd73xx },
6297	{ .id = 0x111d76c1, .name = "92HD89C2", .patch = patch_stac92hd73xx },
6298	{ .id = 0x111d76c2, .name = "92HD89C1", .patch = patch_stac92hd73xx },
6299	{ .id = 0x111d76c3, .name = "92HD89B3", .patch = patch_stac92hd73xx },
6300	{ .id = 0x111d76c4, .name = "92HD89B2", .patch = patch_stac92hd73xx },
6301	{ .id = 0x111d76c5, .name = "92HD89B1", .patch = patch_stac92hd73xx },
6302	{ .id = 0x111d76c6, .name = "92HD89E3", .patch = patch_stac92hd73xx },
6303	{ .id = 0x111d76c7, .name = "92HD89E2", .patch = patch_stac92hd73xx },
6304	{ .id = 0x111d76c8, .name = "92HD89E1", .patch = patch_stac92hd73xx },
6305	{ .id = 0x111d76c9, .name = "92HD89D3", .patch = patch_stac92hd73xx },
6306	{ .id = 0x111d76ca, .name = "92HD89D2", .patch = patch_stac92hd73xx },
6307	{ .id = 0x111d76cb, .name = "92HD89D1", .patch = patch_stac92hd73xx },
6308	{ .id = 0x111d76cc, .name = "92HD89F3", .patch = patch_stac92hd73xx },
6309	{ .id = 0x111d76cd, .name = "92HD89F2", .patch = patch_stac92hd73xx },
6310	{ .id = 0x111d76ce, .name = "92HD89F1", .patch = patch_stac92hd73xx },
6311	{} /* terminator */
6312};
6313
6314MODULE_ALIAS("snd-hda-codec-id:8384*");
6315MODULE_ALIAS("snd-hda-codec-id:111d*");
6316
6317MODULE_LICENSE("GPL");
6318MODULE_DESCRIPTION("IDT/Sigmatel HD-audio codec");
6319
6320static struct hda_codec_preset_list sigmatel_list = {
6321	.preset = snd_hda_preset_sigmatel,
6322	.owner = THIS_MODULE,
6323};
6324
6325static int __init patch_sigmatel_init(void)
6326{
6327	return snd_hda_add_codec_preset(&sigmatel_list);
6328}
6329
6330static void __exit patch_sigmatel_exit(void)
6331{
6332	snd_hda_delete_codec_preset(&sigmatel_list);
6333}
6334
6335module_init(patch_sigmatel_init)
6336module_exit(patch_sigmatel_exit)
6337