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