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