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