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