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