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