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