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