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