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