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