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 "hda_codec.h"
36#include "hda_local.h"
37#include "hda_beep.h"
38
39enum {
40 STAC_VREF_EVENT = 1,
41 STAC_INSERT_EVENT,
42 STAC_PWR_EVENT,
43 STAC_HP_EVENT,
44 STAC_LO_EVENT,
45 STAC_MIC_EVENT,
46};
47
48enum {
49 STAC_AUTO,
50 STAC_REF,
51 STAC_9200_OQO,
52 STAC_9200_DELL_D21,
53 STAC_9200_DELL_D22,
54 STAC_9200_DELL_D23,
55 STAC_9200_DELL_M21,
56 STAC_9200_DELL_M22,
57 STAC_9200_DELL_M23,
58 STAC_9200_DELL_M24,
59 STAC_9200_DELL_M25,
60 STAC_9200_DELL_M26,
61 STAC_9200_DELL_M27,
62 STAC_9200_M4,
63 STAC_9200_M4_2,
64 STAC_9200_PANASONIC,
65 STAC_9200_MODELS
66};
67
68enum {
69 STAC_9205_AUTO,
70 STAC_9205_REF,
71 STAC_9205_DELL_M42,
72 STAC_9205_DELL_M43,
73 STAC_9205_DELL_M44,
74 STAC_9205_EAPD,
75 STAC_9205_MODELS
76};
77
78enum {
79 STAC_92HD73XX_AUTO,
80 STAC_92HD73XX_NO_JD,
81 STAC_92HD73XX_REF,
82 STAC_92HD73XX_INTEL,
83 STAC_DELL_M6_AMIC,
84 STAC_DELL_M6_DMIC,
85 STAC_DELL_M6_BOTH,
86 STAC_DELL_EQ,
87 STAC_ALIENWARE_M17X,
88 STAC_92HD73XX_MODELS
89};
90
91enum {
92 STAC_92HD83XXX_AUTO,
93 STAC_92HD83XXX_REF,
94 STAC_92HD83XXX_PWR_REF,
95 STAC_DELL_S14,
96 STAC_92HD83XXX_HP,
97 STAC_92HD83XXX_MODELS
98};
99
100enum {
101 STAC_92HD71BXX_AUTO,
102 STAC_92HD71BXX_REF,
103 STAC_DELL_M4_1,
104 STAC_DELL_M4_2,
105 STAC_DELL_M4_3,
106 STAC_HP_M4,
107 STAC_HP_DV4,
108 STAC_HP_DV5,
109 STAC_HP_HDX,
110 STAC_HP_DV4_1222NR,
111 STAC_92HD71BXX_MODELS
112};
113
114enum {
115 STAC_925x_AUTO,
116 STAC_925x_REF,
117 STAC_M1,
118 STAC_M1_2,
119 STAC_M2,
120 STAC_M2_2,
121 STAC_M3,
122 STAC_M5,
123 STAC_M6,
124 STAC_925x_MODELS
125};
126
127enum {
128 STAC_922X_AUTO,
129 STAC_D945_REF,
130 STAC_D945GTP3,
131 STAC_D945GTP5,
132 STAC_INTEL_MAC_V1,
133 STAC_INTEL_MAC_V2,
134 STAC_INTEL_MAC_V3,
135 STAC_INTEL_MAC_V4,
136 STAC_INTEL_MAC_V5,
137 STAC_INTEL_MAC_AUTO,
138
139
140
141 STAC_MACMINI,
142 STAC_MACBOOK,
143 STAC_MACBOOK_PRO_V1,
144 STAC_MACBOOK_PRO_V2,
145 STAC_IMAC_INTEL,
146 STAC_IMAC_INTEL_20,
147 STAC_ECS_202,
148 STAC_922X_DELL_D81,
149 STAC_922X_DELL_D82,
150 STAC_922X_DELL_M81,
151 STAC_922X_DELL_M82,
152 STAC_922X_MODELS
153};
154
155enum {
156 STAC_927X_AUTO,
157 STAC_D965_REF_NO_JD,
158 STAC_D965_REF,
159 STAC_D965_3ST,
160 STAC_D965_5ST,
161 STAC_D965_5ST_NO_FP,
162 STAC_DELL_3ST,
163 STAC_DELL_BIOS,
164 STAC_927X_VOLKNOB,
165 STAC_927X_MODELS
166};
167
168enum {
169 STAC_9872_AUTO,
170 STAC_9872_VAIO,
171 STAC_9872_MODELS
172};
173
174struct sigmatel_event {
175 hda_nid_t nid;
176 unsigned char type;
177 unsigned char tag;
178 int data;
179};
180
181struct sigmatel_jack {
182 hda_nid_t nid;
183 int type;
184 struct snd_jack *jack;
185};
186
187struct sigmatel_mic_route {
188 hda_nid_t pin;
189 signed char mux_idx;
190 signed char dmux_idx;
191};
192
193struct sigmatel_spec {
194 struct snd_kcontrol_new *mixers[4];
195 unsigned int num_mixers;
196
197 int board_config;
198 unsigned int eapd_switch: 1;
199 unsigned int surr_switch: 1;
200 unsigned int alt_switch: 1;
201 unsigned int hp_detect: 1;
202 unsigned int spdif_mute: 1;
203 unsigned int check_volume_offset:1;
204 unsigned int auto_mic:1;
205 unsigned int linear_tone_beep:1;
206
207
208 unsigned int eapd_mask;
209 unsigned int gpio_mask;
210 unsigned int gpio_dir;
211 unsigned int gpio_data;
212 unsigned int gpio_mute;
213 unsigned int gpio_led;
214 unsigned int gpio_led_polarity;
215
216
217 unsigned int stream_delay;
218
219
220 struct snd_kcontrol_new *aloopback_ctl;
221 unsigned char aloopback_mask;
222 unsigned char aloopback_shift;
223
224
225 unsigned int num_pwrs;
226 unsigned int *pwr_mapping;
227 hda_nid_t *pwr_nids;
228 hda_nid_t *dac_list;
229
230
231 struct snd_array jacks;
232
233
234 struct snd_array events;
235
236
237 struct hda_input_mux *mono_mux;
238 unsigned int cur_mmux;
239 struct hda_multi_out multiout;
240 hda_nid_t dac_nids[5];
241 hda_nid_t hp_dacs[5];
242 hda_nid_t speaker_dacs[5];
243
244 int volume_offset;
245
246
247 hda_nid_t *adc_nids;
248 unsigned int num_adcs;
249 hda_nid_t *mux_nids;
250 unsigned int num_muxes;
251 hda_nid_t *dmic_nids;
252 unsigned int num_dmics;
253 hda_nid_t *dmux_nids;
254 unsigned int num_dmuxes;
255 hda_nid_t *smux_nids;
256 unsigned int num_smuxes;
257 unsigned int num_analog_muxes;
258
259 unsigned long *capvols;
260 unsigned long *capsws;
261 unsigned int num_caps;
262
263 struct sigmatel_mic_route ext_mic;
264 struct sigmatel_mic_route int_mic;
265
266 const char **spdif_labels;
267
268 hda_nid_t dig_in_nid;
269 hda_nid_t mono_nid;
270 hda_nid_t anabeep_nid;
271 hda_nid_t digbeep_nid;
272
273
274 hda_nid_t *pin_nids;
275 unsigned int num_pins;
276
277
278 struct hda_verb *init;
279 struct snd_kcontrol_new *mixer;
280
281
282 struct hda_input_mux *dinput_mux;
283 unsigned int cur_dmux[2];
284 struct hda_input_mux *input_mux;
285 unsigned int cur_mux[3];
286 struct hda_input_mux *sinput_mux;
287 unsigned int cur_smux[2];
288 unsigned int cur_amux;
289 hda_nid_t *amp_nids;
290 unsigned int powerdown_adcs;
291
292
293 unsigned int io_switch[2];
294 unsigned int clfe_swap;
295 hda_nid_t line_switch;
296 hda_nid_t mic_switch;
297 hda_nid_t hp_switch;
298 unsigned int aloopback;
299
300 struct hda_pcm pcm_rec[2];
301
302
303 struct auto_pin_cfg autocfg;
304 struct snd_array kctls;
305 struct hda_input_mux private_dimux;
306 struct hda_input_mux private_imux;
307 struct hda_input_mux private_smux;
308 struct hda_input_mux private_mono_mux;
309};
310
311static hda_nid_t stac9200_adc_nids[1] = {
312 0x03,
313};
314
315static hda_nid_t stac9200_mux_nids[1] = {
316 0x0c,
317};
318
319static hda_nid_t stac9200_dac_nids[1] = {
320 0x02,
321};
322
323static hda_nid_t stac92hd73xx_pwr_nids[8] = {
324 0x0a, 0x0b, 0x0c, 0xd, 0x0e,
325 0x0f, 0x10, 0x11
326};
327
328static hda_nid_t stac92hd73xx_slave_dig_outs[2] = {
329 0x26, 0,
330};
331
332static hda_nid_t stac92hd73xx_adc_nids[2] = {
333 0x1a, 0x1b
334};
335
336#define STAC92HD73XX_NUM_DMICS 2
337static hda_nid_t stac92hd73xx_dmic_nids[STAC92HD73XX_NUM_DMICS + 1] = {
338 0x13, 0x14, 0
339};
340
341#define STAC92HD73_DAC_COUNT 5
342
343static hda_nid_t stac92hd73xx_mux_nids[2] = {
344 0x20, 0x21,
345};
346
347static hda_nid_t stac92hd73xx_dmux_nids[2] = {
348 0x20, 0x21,
349};
350
351static hda_nid_t stac92hd73xx_smux_nids[2] = {
352 0x22, 0x23,
353};
354
355#define STAC92HD73XX_NUM_CAPS 2
356static unsigned long stac92hd73xx_capvols[] = {
357 HDA_COMPOSE_AMP_VAL(0x20, 3, 0, HDA_OUTPUT),
358 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
359};
360#define stac92hd73xx_capsws stac92hd73xx_capvols
361
362#define STAC92HD83_DAC_COUNT 3
363
364static hda_nid_t stac92hd83xxx_mux_nids[2] = {
365 0x17, 0x18,
366};
367
368static hda_nid_t stac92hd83xxx_adc_nids[2] = {
369 0x15, 0x16,
370};
371
372static hda_nid_t stac92hd83xxx_pwr_nids[4] = {
373 0xa, 0xb, 0xd, 0xe,
374};
375
376static hda_nid_t stac92hd83xxx_slave_dig_outs[2] = {
377 0x1e, 0,
378};
379
380static unsigned int stac92hd83xxx_pwr_mapping[4] = {
381 0x03, 0x0c, 0x20, 0x40,
382};
383
384#define STAC92HD83XXX_NUM_CAPS 2
385static unsigned long stac92hd83xxx_capvols[] = {
386 HDA_COMPOSE_AMP_VAL(0x17, 3, 0, HDA_OUTPUT),
387 HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_OUTPUT),
388};
389#define stac92hd83xxx_capsws stac92hd83xxx_capvols
390
391static hda_nid_t stac92hd71bxx_pwr_nids[3] = {
392 0x0a, 0x0d, 0x0f
393};
394
395static hda_nid_t stac92hd71bxx_adc_nids[2] = {
396 0x12, 0x13,
397};
398
399static hda_nid_t stac92hd71bxx_mux_nids[2] = {
400 0x1a, 0x1b
401};
402
403static hda_nid_t stac92hd71bxx_dmux_nids[2] = {
404 0x1c, 0x1d,
405};
406
407static hda_nid_t stac92hd71bxx_smux_nids[2] = {
408 0x24, 0x25,
409};
410
411#define STAC92HD71BXX_NUM_DMICS 2
412static hda_nid_t stac92hd71bxx_dmic_nids[STAC92HD71BXX_NUM_DMICS + 1] = {
413 0x18, 0x19, 0
414};
415
416static hda_nid_t stac92hd71bxx_slave_dig_outs[2] = {
417 0x22, 0
418};
419
420#define STAC92HD71BXX_NUM_CAPS 2
421static unsigned long stac92hd71bxx_capvols[] = {
422 HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_OUTPUT),
423 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
424};
425#define stac92hd71bxx_capsws stac92hd71bxx_capvols
426
427static hda_nid_t stac925x_adc_nids[1] = {
428 0x03,
429};
430
431static hda_nid_t stac925x_mux_nids[1] = {
432 0x0f,
433};
434
435static hda_nid_t stac925x_dac_nids[1] = {
436 0x02,
437};
438
439#define STAC925X_NUM_DMICS 1
440static hda_nid_t stac925x_dmic_nids[STAC925X_NUM_DMICS + 1] = {
441 0x15, 0
442};
443
444static hda_nid_t stac925x_dmux_nids[1] = {
445 0x14,
446};
447
448static unsigned long stac925x_capvols[] = {
449 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_OUTPUT),
450};
451static unsigned long stac925x_capsws[] = {
452 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
453};
454
455static hda_nid_t stac922x_adc_nids[2] = {
456 0x06, 0x07,
457};
458
459static hda_nid_t stac922x_mux_nids[2] = {
460 0x12, 0x13,
461};
462
463#define STAC922X_NUM_CAPS 2
464static unsigned long stac922x_capvols[] = {
465 HDA_COMPOSE_AMP_VAL(0x17, 3, 0, HDA_INPUT),
466 HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_INPUT),
467};
468#define stac922x_capsws stac922x_capvols
469
470static hda_nid_t stac927x_slave_dig_outs[2] = {
471 0x1f, 0,
472};
473
474static hda_nid_t stac927x_adc_nids[3] = {
475 0x07, 0x08, 0x09
476};
477
478static hda_nid_t stac927x_mux_nids[3] = {
479 0x15, 0x16, 0x17
480};
481
482static hda_nid_t stac927x_smux_nids[1] = {
483 0x21,
484};
485
486static hda_nid_t stac927x_dac_nids[6] = {
487 0x02, 0x03, 0x04, 0x05, 0x06, 0
488};
489
490static hda_nid_t stac927x_dmux_nids[1] = {
491 0x1b,
492};
493
494#define STAC927X_NUM_DMICS 2
495static hda_nid_t stac927x_dmic_nids[STAC927X_NUM_DMICS + 1] = {
496 0x13, 0x14, 0
497};
498
499#define STAC927X_NUM_CAPS 3
500static unsigned long stac927x_capvols[] = {
501 HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_INPUT),
502 HDA_COMPOSE_AMP_VAL(0x19, 3, 0, HDA_INPUT),
503 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_INPUT),
504};
505static unsigned long stac927x_capsws[] = {
506 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
507 HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_OUTPUT),
508 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
509};
510
511static const char *stac927x_spdif_labels[5] = {
512 "Digital Playback", "ADAT", "Analog Mux 1",
513 "Analog Mux 2", "Analog Mux 3"
514};
515
516static hda_nid_t stac9205_adc_nids[2] = {
517 0x12, 0x13
518};
519
520static hda_nid_t stac9205_mux_nids[2] = {
521 0x19, 0x1a
522};
523
524static hda_nid_t stac9205_dmux_nids[1] = {
525 0x1d,
526};
527
528static hda_nid_t stac9205_smux_nids[1] = {
529 0x21,
530};
531
532#define STAC9205_NUM_DMICS 2
533static hda_nid_t stac9205_dmic_nids[STAC9205_NUM_DMICS + 1] = {
534 0x17, 0x18, 0
535};
536
537#define STAC9205_NUM_CAPS 2
538static unsigned long stac9205_capvols[] = {
539 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_INPUT),
540 HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_INPUT),
541};
542static unsigned long stac9205_capsws[] = {
543 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
544 HDA_COMPOSE_AMP_VAL(0x1e, 3, 0, HDA_OUTPUT),
545};
546
547static hda_nid_t stac9200_pin_nids[8] = {
548 0x08, 0x09, 0x0d, 0x0e,
549 0x0f, 0x10, 0x11, 0x12,
550};
551
552static hda_nid_t stac925x_pin_nids[8] = {
553 0x07, 0x08, 0x0a, 0x0b,
554 0x0c, 0x0d, 0x10, 0x11,
555};
556
557static hda_nid_t stac922x_pin_nids[10] = {
558 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
559 0x0f, 0x10, 0x11, 0x15, 0x1b,
560};
561
562static hda_nid_t stac92hd73xx_pin_nids[13] = {
563 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
564 0x0f, 0x10, 0x11, 0x12, 0x13,
565 0x14, 0x22, 0x23
566};
567
568static hda_nid_t stac92hd83xxx_pin_nids[10] = {
569 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
570 0x0f, 0x10, 0x11, 0x1f, 0x20,
571};
572
573static hda_nid_t stac92hd88xxx_pin_nids[10] = {
574 0x0a, 0x0b, 0x0c, 0x0d,
575 0x0f, 0x11, 0x1f, 0x20,
576};
577
578#define STAC92HD71BXX_NUM_PINS 13
579static hda_nid_t stac92hd71bxx_pin_nids_4port[STAC92HD71BXX_NUM_PINS] = {
580 0x0a, 0x0b, 0x0c, 0x0d, 0x00,
581 0x00, 0x14, 0x18, 0x19, 0x1e,
582 0x1f, 0x20, 0x27
583};
584static hda_nid_t stac92hd71bxx_pin_nids_6port[STAC92HD71BXX_NUM_PINS] = {
585 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
586 0x0f, 0x14, 0x18, 0x19, 0x1e,
587 0x1f, 0x20, 0x27
588};
589
590static hda_nid_t stac927x_pin_nids[14] = {
591 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
592 0x0f, 0x10, 0x11, 0x12, 0x13,
593 0x14, 0x21, 0x22, 0x23,
594};
595
596static hda_nid_t stac9205_pin_nids[12] = {
597 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
598 0x0f, 0x14, 0x16, 0x17, 0x18,
599 0x21, 0x22,
600};
601
602static int stac92xx_dmux_enum_info(struct snd_kcontrol *kcontrol,
603 struct snd_ctl_elem_info *uinfo)
604{
605 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
606 struct sigmatel_spec *spec = codec->spec;
607 return snd_hda_input_mux_info(spec->dinput_mux, uinfo);
608}
609
610static int stac92xx_dmux_enum_get(struct snd_kcontrol *kcontrol,
611 struct snd_ctl_elem_value *ucontrol)
612{
613 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
614 struct sigmatel_spec *spec = codec->spec;
615 unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
616
617 ucontrol->value.enumerated.item[0] = spec->cur_dmux[dmux_idx];
618 return 0;
619}
620
621static int stac92xx_dmux_enum_put(struct snd_kcontrol *kcontrol,
622 struct snd_ctl_elem_value *ucontrol)
623{
624 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
625 struct sigmatel_spec *spec = codec->spec;
626 unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
627
628 return snd_hda_input_mux_put(codec, spec->dinput_mux, ucontrol,
629 spec->dmux_nids[dmux_idx], &spec->cur_dmux[dmux_idx]);
630}
631
632static int stac92xx_smux_enum_info(struct snd_kcontrol *kcontrol,
633 struct snd_ctl_elem_info *uinfo)
634{
635 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
636 struct sigmatel_spec *spec = codec->spec;
637 return snd_hda_input_mux_info(spec->sinput_mux, uinfo);
638}
639
640static int stac92xx_smux_enum_get(struct snd_kcontrol *kcontrol,
641 struct snd_ctl_elem_value *ucontrol)
642{
643 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
644 struct sigmatel_spec *spec = codec->spec;
645 unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
646
647 ucontrol->value.enumerated.item[0] = spec->cur_smux[smux_idx];
648 return 0;
649}
650
651static int stac92xx_smux_enum_put(struct snd_kcontrol *kcontrol,
652 struct snd_ctl_elem_value *ucontrol)
653{
654 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
655 struct sigmatel_spec *spec = codec->spec;
656 struct hda_input_mux *smux = &spec->private_smux;
657 unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
658 int err, val;
659 hda_nid_t nid;
660
661 err = snd_hda_input_mux_put(codec, spec->sinput_mux, ucontrol,
662 spec->smux_nids[smux_idx], &spec->cur_smux[smux_idx]);
663 if (err < 0)
664 return err;
665
666 if (spec->spdif_mute) {
667 if (smux_idx == 0)
668 nid = spec->multiout.dig_out_nid;
669 else
670 nid = codec->slave_dig_outs[smux_idx - 1];
671 if (spec->cur_smux[smux_idx] == smux->num_items - 1)
672 val = HDA_AMP_MUTE;
673 else
674 val = 0;
675
676 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
677 HDA_AMP_MUTE, val);
678 }
679 return 0;
680}
681
682static unsigned int stac92xx_vref_set(struct hda_codec *codec,
683 hda_nid_t nid, unsigned int new_vref)
684{
685 int error;
686 unsigned int pincfg;
687 pincfg = snd_hda_codec_read(codec, nid, 0,
688 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
689
690 pincfg &= 0xff;
691 pincfg &= ~(AC_PINCTL_VREFEN | AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
692 pincfg |= new_vref;
693
694 if (new_vref == AC_PINCTL_VREF_HIZ)
695 pincfg |= AC_PINCTL_OUT_EN;
696 else
697 pincfg |= AC_PINCTL_IN_EN;
698
699 error = snd_hda_codec_write_cache(codec, nid, 0,
700 AC_VERB_SET_PIN_WIDGET_CONTROL, pincfg);
701 if (error < 0)
702 return error;
703 else
704 return 1;
705}
706
707static unsigned int stac92xx_vref_get(struct hda_codec *codec, hda_nid_t nid)
708{
709 unsigned int vref;
710 vref = snd_hda_codec_read(codec, nid, 0,
711 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
712 vref &= AC_PINCTL_VREFEN;
713 return vref;
714}
715
716static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
717{
718 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
719 struct sigmatel_spec *spec = codec->spec;
720 return snd_hda_input_mux_info(spec->input_mux, uinfo);
721}
722
723static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
724{
725 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
726 struct sigmatel_spec *spec = codec->spec;
727 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
728
729 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
730 return 0;
731}
732
733static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
734{
735 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
736 struct sigmatel_spec *spec = codec->spec;
737 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
738 const struct hda_input_mux *imux = spec->input_mux;
739 unsigned int idx, prev_idx;
740
741 idx = ucontrol->value.enumerated.item[0];
742 if (idx >= imux->num_items)
743 idx = imux->num_items - 1;
744 prev_idx = spec->cur_mux[adc_idx];
745 if (prev_idx == idx)
746 return 0;
747 if (idx < spec->num_analog_muxes) {
748 snd_hda_codec_write_cache(codec, spec->mux_nids[adc_idx], 0,
749 AC_VERB_SET_CONNECT_SEL,
750 imux->items[idx].index);
751 if (prev_idx >= spec->num_analog_muxes) {
752 imux = spec->dinput_mux;
753
754 snd_hda_codec_write_cache(codec,
755 spec->dmux_nids[adc_idx], 0,
756 AC_VERB_SET_CONNECT_SEL,
757 imux->items[0].index);
758 }
759 } else {
760 imux = spec->dinput_mux;
761 snd_hda_codec_write_cache(codec, spec->dmux_nids[adc_idx], 0,
762 AC_VERB_SET_CONNECT_SEL,
763 imux->items[idx - 1].index);
764 }
765 spec->cur_mux[adc_idx] = idx;
766 return 1;
767}
768
769static int stac92xx_mono_mux_enum_info(struct snd_kcontrol *kcontrol,
770 struct snd_ctl_elem_info *uinfo)
771{
772 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
773 struct sigmatel_spec *spec = codec->spec;
774 return snd_hda_input_mux_info(spec->mono_mux, uinfo);
775}
776
777static int stac92xx_mono_mux_enum_get(struct snd_kcontrol *kcontrol,
778 struct snd_ctl_elem_value *ucontrol)
779{
780 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
781 struct sigmatel_spec *spec = codec->spec;
782
783 ucontrol->value.enumerated.item[0] = spec->cur_mmux;
784 return 0;
785}
786
787static int stac92xx_mono_mux_enum_put(struct snd_kcontrol *kcontrol,
788 struct snd_ctl_elem_value *ucontrol)
789{
790 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
791 struct sigmatel_spec *spec = codec->spec;
792
793 return snd_hda_input_mux_put(codec, spec->mono_mux, ucontrol,
794 spec->mono_nid, &spec->cur_mmux);
795}
796
797#define stac92xx_aloopback_info snd_ctl_boolean_mono_info
798
799static int stac92xx_aloopback_get(struct snd_kcontrol *kcontrol,
800 struct snd_ctl_elem_value *ucontrol)
801{
802 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
803 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
804 struct sigmatel_spec *spec = codec->spec;
805
806 ucontrol->value.integer.value[0] = !!(spec->aloopback &
807 (spec->aloopback_mask << idx));
808 return 0;
809}
810
811static int stac92xx_aloopback_put(struct snd_kcontrol *kcontrol,
812 struct snd_ctl_elem_value *ucontrol)
813{
814 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
815 struct sigmatel_spec *spec = codec->spec;
816 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
817 unsigned int dac_mode;
818 unsigned int val, idx_val;
819
820 idx_val = spec->aloopback_mask << idx;
821 if (ucontrol->value.integer.value[0])
822 val = spec->aloopback | idx_val;
823 else
824 val = spec->aloopback & ~idx_val;
825 if (spec->aloopback == val)
826 return 0;
827
828 spec->aloopback = val;
829
830
831
832
833 dac_mode = snd_hda_codec_read(codec, codec->afg, 0,
834 kcontrol->private_value & 0xFFFF, 0x0);
835 dac_mode >>= spec->aloopback_shift;
836
837 if (spec->aloopback & idx_val) {
838 snd_hda_power_up(codec);
839 dac_mode |= idx_val;
840 } else {
841 snd_hda_power_down(codec);
842 dac_mode &= ~idx_val;
843 }
844
845 snd_hda_codec_write_cache(codec, codec->afg, 0,
846 kcontrol->private_value >> 16, dac_mode);
847
848 return 1;
849}
850
851static struct hda_verb stac9200_core_init[] = {
852
853 { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
854 {}
855};
856
857static struct hda_verb stac9200_eapd_init[] = {
858
859 {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
860 {0x08, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
861 {}
862};
863
864static struct hda_verb dell_eq_core_init[] = {
865
866
867 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xec},
868 {}
869};
870
871static struct hda_verb stac92hd73xx_core_init[] = {
872
873 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
874 {}
875};
876
877static struct hda_verb stac92hd83xxx_core_init[] = {
878
879 { 0x01, AC_VERB_SET_EAPD, 1 << 2},
880 {}
881};
882
883static struct hda_verb stac92hd71bxx_core_init[] = {
884
885 { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
886 {}
887};
888
889static struct hda_verb stac92hd71bxx_unmute_core_init[] = {
890
891 { 0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
892 { 0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
893 { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
894 {}
895};
896
897static struct hda_verb stac925x_core_init[] = {
898
899 { 0x06, AC_VERB_SET_CONNECT_SEL, 0x00},
900
901 { 0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
902 {}
903};
904
905static struct hda_verb stac922x_core_init[] = {
906
907 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
908 {}
909};
910
911static struct hda_verb d965_core_init[] = {
912
913 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
914
915 { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
916
917 { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
918 {}
919};
920
921static struct hda_verb dell_3st_core_init[] = {
922
923 {0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0x7f},
924
925 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
926
927 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
928 {}
929};
930
931static struct hda_verb stac927x_core_init[] = {
932
933 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
934
935 { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
936 {}
937};
938
939static struct hda_verb stac927x_volknob_core_init[] = {
940
941 {0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0x7f},
942
943 {0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
944 {}
945};
946
947static struct hda_verb stac9205_core_init[] = {
948
949 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
950
951 { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
952 {}
953};
954
955#define STAC_MONO_MUX \
956 { \
957 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
958 .name = "Mono Mux", \
959 .count = 1, \
960 .info = stac92xx_mono_mux_enum_info, \
961 .get = stac92xx_mono_mux_enum_get, \
962 .put = stac92xx_mono_mux_enum_put, \
963 }
964
965#define STAC_ANALOG_LOOPBACK(verb_read, verb_write, cnt) \
966 { \
967 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
968 .name = "Analog Loopback", \
969 .count = cnt, \
970 .info = stac92xx_aloopback_info, \
971 .get = stac92xx_aloopback_get, \
972 .put = stac92xx_aloopback_put, \
973 .private_value = verb_read | (verb_write << 16), \
974 }
975
976#define DC_BIAS(xname, idx, nid) \
977 { \
978 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
979 .name = xname, \
980 .index = idx, \
981 .info = stac92xx_dc_bias_info, \
982 .get = stac92xx_dc_bias_get, \
983 .put = stac92xx_dc_bias_put, \
984 .private_value = nid, \
985 }
986
987static struct snd_kcontrol_new stac9200_mixer[] = {
988 HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
989 HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
990 HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
991 HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
992 { }
993};
994
995static struct snd_kcontrol_new stac92hd73xx_6ch_loopback[] = {
996 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 3),
997 {}
998};
999
1000static struct snd_kcontrol_new stac92hd73xx_8ch_loopback[] = {
1001 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 4),
1002 {}
1003};
1004
1005static struct snd_kcontrol_new stac92hd73xx_10ch_loopback[] = {
1006 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 5),
1007 {}
1008};
1009
1010
1011static struct snd_kcontrol_new stac92hd71bxx_loopback[] = {
1012 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A0, 2)
1013};
1014
1015static struct snd_kcontrol_new stac925x_mixer[] = {
1016 HDA_CODEC_VOLUME("Master Playback Volume", 0x0e, 0, HDA_OUTPUT),
1017 HDA_CODEC_MUTE("Master Playback Switch", 0x0e, 0, HDA_OUTPUT),
1018 { }
1019};
1020
1021static struct snd_kcontrol_new stac9205_loopback[] = {
1022 STAC_ANALOG_LOOPBACK(0xFE0, 0x7E0, 1),
1023 {}
1024};
1025
1026static struct snd_kcontrol_new stac927x_loopback[] = {
1027 STAC_ANALOG_LOOPBACK(0xFEB, 0x7EB, 1),
1028 {}
1029};
1030
1031static struct snd_kcontrol_new stac_dmux_mixer = {
1032 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1033 .name = "Digital Input Source",
1034
1035 .info = stac92xx_dmux_enum_info,
1036 .get = stac92xx_dmux_enum_get,
1037 .put = stac92xx_dmux_enum_put,
1038};
1039
1040static struct snd_kcontrol_new stac_smux_mixer = {
1041 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1042 .name = "IEC958 Playback Source",
1043
1044 .info = stac92xx_smux_enum_info,
1045 .get = stac92xx_smux_enum_get,
1046 .put = stac92xx_smux_enum_put,
1047};
1048
1049static const char *slave_vols[] = {
1050 "Front Playback Volume",
1051 "Surround Playback Volume",
1052 "Center Playback Volume",
1053 "LFE Playback Volume",
1054 "Side Playback Volume",
1055 "Headphone Playback Volume",
1056 "Speaker Playback Volume",
1057 NULL
1058};
1059
1060static const char *slave_sws[] = {
1061 "Front Playback Switch",
1062 "Surround Playback Switch",
1063 "Center Playback Switch",
1064 "LFE Playback Switch",
1065 "Side Playback Switch",
1066 "Headphone Playback Switch",
1067 "Speaker Playback Switch",
1068 "IEC958 Playback Switch",
1069 NULL
1070};
1071
1072static void stac92xx_free_kctls(struct hda_codec *codec);
1073static int stac92xx_add_jack(struct hda_codec *codec, hda_nid_t nid, int type);
1074
1075static int stac92xx_build_controls(struct hda_codec *codec)
1076{
1077 struct sigmatel_spec *spec = codec->spec;
1078 struct auto_pin_cfg *cfg = &spec->autocfg;
1079 hda_nid_t nid;
1080 int err;
1081 int i;
1082
1083 if (spec->mixer) {
1084 err = snd_hda_add_new_ctls(codec, spec->mixer);
1085 if (err < 0)
1086 return err;
1087 }
1088
1089 for (i = 0; i < spec->num_mixers; i++) {
1090 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1091 if (err < 0)
1092 return err;
1093 }
1094 if (!spec->auto_mic && spec->num_dmuxes > 0 &&
1095 snd_hda_get_bool_hint(codec, "separate_dmux") == 1) {
1096 stac_dmux_mixer.count = spec->num_dmuxes;
1097 err = snd_hda_ctl_add(codec, 0,
1098 snd_ctl_new1(&stac_dmux_mixer, codec));
1099 if (err < 0)
1100 return err;
1101 }
1102 if (spec->num_smuxes > 0) {
1103 int wcaps = get_wcaps(codec, spec->multiout.dig_out_nid);
1104 struct hda_input_mux *smux = &spec->private_smux;
1105
1106 if (wcaps & AC_WCAP_OUT_AMP) {
1107 smux->items[smux->num_items].label = "Off";
1108 smux->items[smux->num_items].index = 0;
1109 smux->num_items++;
1110 spec->spdif_mute = 1;
1111 }
1112 stac_smux_mixer.count = spec->num_smuxes;
1113 err = snd_hda_ctl_add(codec, 0,
1114 snd_ctl_new1(&stac_smux_mixer, codec));
1115 if (err < 0)
1116 return err;
1117 }
1118
1119 if (spec->multiout.dig_out_nid) {
1120 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
1121 if (err < 0)
1122 return err;
1123 err = snd_hda_create_spdif_share_sw(codec,
1124 &spec->multiout);
1125 if (err < 0)
1126 return err;
1127 spec->multiout.share_spdif = 1;
1128 }
1129 if (spec->dig_in_nid && !(spec->gpio_dir & 0x01)) {
1130 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1131 if (err < 0)
1132 return err;
1133 }
1134
1135
1136 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
1137 unsigned int vmaster_tlv[4];
1138 snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0],
1139 HDA_OUTPUT, vmaster_tlv);
1140
1141 vmaster_tlv[2] += vmaster_tlv[3] * spec->volume_offset;
1142 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
1143 vmaster_tlv, slave_vols);
1144 if (err < 0)
1145 return err;
1146 }
1147 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1148 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1149 NULL, slave_sws);
1150 if (err < 0)
1151 return err;
1152 }
1153
1154 if (spec->aloopback_ctl &&
1155 snd_hda_get_bool_hint(codec, "loopback") == 1) {
1156 err = snd_hda_add_new_ctls(codec, spec->aloopback_ctl);
1157 if (err < 0)
1158 return err;
1159 }
1160
1161 stac92xx_free_kctls(codec);
1162
1163
1164 if (spec->hp_detect) {
1165 for (i = 0; i < cfg->hp_outs; i++) {
1166 int type = SND_JACK_HEADPHONE;
1167 nid = cfg->hp_pins[i];
1168
1169 if (cfg->hp_outs == i)
1170 type |= SND_JACK_LINEOUT;
1171 err = stac92xx_add_jack(codec, nid, type);
1172 if (err < 0)
1173 return err;
1174 }
1175 }
1176 for (i = 0; i < cfg->line_outs; i++) {
1177 err = stac92xx_add_jack(codec, cfg->line_out_pins[i],
1178 SND_JACK_LINEOUT);
1179 if (err < 0)
1180 return err;
1181 }
1182 for (i = 0; i < AUTO_PIN_LAST; i++) {
1183 nid = cfg->input_pins[i];
1184 if (nid) {
1185 err = stac92xx_add_jack(codec, nid,
1186 SND_JACK_MICROPHONE);
1187 if (err < 0)
1188 return err;
1189 }
1190 }
1191
1192 return 0;
1193}
1194
1195static unsigned int ref9200_pin_configs[8] = {
1196 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
1197 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
1198};
1199
1200static unsigned int gateway9200_m4_pin_configs[8] = {
1201 0x400000fe, 0x404500f4, 0x400100f0, 0x90110010,
1202 0x400100f1, 0x02a1902e, 0x500000f2, 0x500000f3,
1203};
1204static unsigned int gateway9200_m4_2_pin_configs[8] = {
1205 0x400000fe, 0x404500f4, 0x400100f0, 0x90110010,
1206 0x400100f1, 0x02a1902e, 0x500000f2, 0x500000f3,
1207};
1208
1209
1210
1211
1212
1213
1214
1215static unsigned int dell9200_d21_pin_configs[8] = {
1216 0x400001f0, 0x400001f1, 0x02214030, 0x01014010,
1217 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
1218};
1219
1220
1221
1222
1223
1224
1225static unsigned int dell9200_d22_pin_configs[8] = {
1226 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
1227 0x01813020, 0x02a19021, 0x90100140, 0x400001f2,
1228};
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239static unsigned int dell9200_d23_pin_configs[8] = {
1240 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
1241 0x01813020, 0x01a19021, 0x90100140, 0x400001f2,
1242};
1243
1244
1245
1246
1247
1248
1249
1250static unsigned int dell9200_m21_pin_configs[8] = {
1251 0x40c003fa, 0x03441340, 0x0321121f, 0x90170310,
1252 0x408003fb, 0x03a11020, 0x401003fc, 0x403003fd,
1253};
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263static unsigned int dell9200_m22_pin_configs[8] = {
1264 0x40c003fa, 0x0144131f, 0x0321121f, 0x90170310,
1265 0x90a70321, 0x03a11020, 0x401003fb, 0x40f000fc,
1266};
1267
1268
1269
1270
1271
1272
1273static unsigned int dell9200_m23_pin_configs[8] = {
1274 0x40c003fa, 0x01441340, 0x0421421f, 0x90170310,
1275 0x408003fb, 0x04a1102e, 0x90170311, 0x403003fc,
1276};
1277
1278
1279
1280
1281
1282
1283
1284
1285static unsigned int dell9200_m24_pin_configs[8] = {
1286 0x40c003fa, 0x404003fb, 0x0321121f, 0x90170310,
1287 0x408003fc, 0x03a11020, 0x401003fd, 0x403003fe,
1288};
1289
1290
1291
1292
1293
1294
1295
1296static unsigned int dell9200_m25_pin_configs[8] = {
1297 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
1298 0x408003fb, 0x04a11020, 0x401003fc, 0x403003fd,
1299};
1300
1301
1302
1303
1304
1305
1306static unsigned int dell9200_m26_pin_configs[8] = {
1307 0x40c003fa, 0x404003fb, 0x0421121f, 0x90170310,
1308 0x408003fc, 0x04a11020, 0x401003fd, 0x403003fe,
1309};
1310
1311
1312
1313
1314
1315static unsigned int dell9200_m27_pin_configs[8] = {
1316 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
1317 0x90170310, 0x04a11020, 0x90170310, 0x40f003fc,
1318};
1319
1320static unsigned int oqo9200_pin_configs[8] = {
1321 0x40c000f0, 0x404000f1, 0x0221121f, 0x02211210,
1322 0x90170111, 0x90a70120, 0x400000f2, 0x400000f3,
1323};
1324
1325
1326static unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
1327 [STAC_REF] = ref9200_pin_configs,
1328 [STAC_9200_OQO] = oqo9200_pin_configs,
1329 [STAC_9200_DELL_D21] = dell9200_d21_pin_configs,
1330 [STAC_9200_DELL_D22] = dell9200_d22_pin_configs,
1331 [STAC_9200_DELL_D23] = dell9200_d23_pin_configs,
1332 [STAC_9200_DELL_M21] = dell9200_m21_pin_configs,
1333 [STAC_9200_DELL_M22] = dell9200_m22_pin_configs,
1334 [STAC_9200_DELL_M23] = dell9200_m23_pin_configs,
1335 [STAC_9200_DELL_M24] = dell9200_m24_pin_configs,
1336 [STAC_9200_DELL_M25] = dell9200_m25_pin_configs,
1337 [STAC_9200_DELL_M26] = dell9200_m26_pin_configs,
1338 [STAC_9200_DELL_M27] = dell9200_m27_pin_configs,
1339 [STAC_9200_M4] = gateway9200_m4_pin_configs,
1340 [STAC_9200_M4_2] = gateway9200_m4_2_pin_configs,
1341 [STAC_9200_PANASONIC] = ref9200_pin_configs,
1342};
1343
1344static const char *stac9200_models[STAC_9200_MODELS] = {
1345 [STAC_AUTO] = "auto",
1346 [STAC_REF] = "ref",
1347 [STAC_9200_OQO] = "oqo",
1348 [STAC_9200_DELL_D21] = "dell-d21",
1349 [STAC_9200_DELL_D22] = "dell-d22",
1350 [STAC_9200_DELL_D23] = "dell-d23",
1351 [STAC_9200_DELL_M21] = "dell-m21",
1352 [STAC_9200_DELL_M22] = "dell-m22",
1353 [STAC_9200_DELL_M23] = "dell-m23",
1354 [STAC_9200_DELL_M24] = "dell-m24",
1355 [STAC_9200_DELL_M25] = "dell-m25",
1356 [STAC_9200_DELL_M26] = "dell-m26",
1357 [STAC_9200_DELL_M27] = "dell-m27",
1358 [STAC_9200_M4] = "gateway-m4",
1359 [STAC_9200_M4_2] = "gateway-m4-2",
1360 [STAC_9200_PANASONIC] = "panasonic",
1361};
1362
1363static struct snd_pci_quirk stac9200_cfg_tbl[] = {
1364
1365 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1366 "DFI LanParty", STAC_REF),
1367 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1368 "DFI LanParty", STAC_REF),
1369
1370 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a8,
1371 "unknown Dell", STAC_9200_DELL_D21),
1372 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01b5,
1373 "Dell Inspiron 630m", STAC_9200_DELL_M21),
1374 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bd,
1375 "Dell Inspiron E1505n", STAC_9200_DELL_M25),
1376 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c0,
1377 "unknown Dell", STAC_9200_DELL_D22),
1378 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c1,
1379 "unknown Dell", STAC_9200_DELL_D22),
1380 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c2,
1381 "Dell Latitude D620", STAC_9200_DELL_M22),
1382 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c5,
1383 "unknown Dell", STAC_9200_DELL_D23),
1384 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c7,
1385 "unknown Dell", STAC_9200_DELL_D23),
1386 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c8,
1387 "unknown Dell", STAC_9200_DELL_M22),
1388 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c9,
1389 "unknown Dell", STAC_9200_DELL_M24),
1390 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ca,
1391 "unknown Dell", STAC_9200_DELL_M24),
1392 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cb,
1393 "Dell Latitude 120L", STAC_9200_DELL_M24),
1394 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cc,
1395 "Dell Latitude D820", STAC_9200_DELL_M22),
1396 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cd,
1397 "Dell Inspiron E1705/9400", STAC_9200_DELL_M27),
1398 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ce,
1399 "Dell XPS M1710", STAC_9200_DELL_M23),
1400 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cf,
1401 "Dell Precision M90", STAC_9200_DELL_M23),
1402 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d3,
1403 "unknown Dell", STAC_9200_DELL_M22),
1404 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d4,
1405 "unknown Dell", STAC_9200_DELL_M22),
1406 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d6,
1407 "unknown Dell", STAC_9200_DELL_M22),
1408 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d8,
1409 "Dell Inspiron 640m", STAC_9200_DELL_M21),
1410 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d9,
1411 "unknown Dell", STAC_9200_DELL_D23),
1412 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01da,
1413 "unknown Dell", STAC_9200_DELL_D23),
1414 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01de,
1415 "unknown Dell", STAC_9200_DELL_D21),
1416 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e3,
1417 "unknown Dell", STAC_9200_DELL_D23),
1418 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e8,
1419 "unknown Dell", STAC_9200_DELL_D21),
1420 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ee,
1421 "unknown Dell", STAC_9200_DELL_M25),
1422 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ef,
1423 "unknown Dell", STAC_9200_DELL_M25),
1424 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f5,
1425 "Dell Inspiron 1501", STAC_9200_DELL_M26),
1426 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f6,
1427 "unknown Dell", STAC_9200_DELL_M26),
1428
1429 SND_PCI_QUIRK(0x10f7, 0x8338, "Panasonic CF-74", STAC_9200_PANASONIC),
1430
1431 SND_PCI_QUIRK(0x107b, 0x0205, "Gateway S-7110M", STAC_9200_M4),
1432 SND_PCI_QUIRK(0x107b, 0x0317, "Gateway MT3423, MX341*", STAC_9200_M4_2),
1433 SND_PCI_QUIRK(0x107b, 0x0318, "Gateway ML3019, MT3707", STAC_9200_M4_2),
1434
1435 SND_PCI_QUIRK(0x1106, 0x3288, "OQO Model 2", STAC_9200_OQO),
1436 {}
1437};
1438
1439static unsigned int ref925x_pin_configs[8] = {
1440 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
1441 0x90a70320, 0x02214210, 0x01019020, 0x9033032e,
1442};
1443
1444static unsigned int stac925xM1_pin_configs[8] = {
1445 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1446 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1447};
1448
1449static unsigned int stac925xM1_2_pin_configs[8] = {
1450 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1451 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1452};
1453
1454static unsigned int stac925xM2_pin_configs[8] = {
1455 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1456 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1457};
1458
1459static unsigned int stac925xM2_2_pin_configs[8] = {
1460 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1461 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1462};
1463
1464static unsigned int stac925xM3_pin_configs[8] = {
1465 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1466 0x40a000f0, 0x90100210, 0x400003f1, 0x503303f3,
1467};
1468
1469static unsigned int stac925xM5_pin_configs[8] = {
1470 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1471 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1472};
1473
1474static unsigned int stac925xM6_pin_configs[8] = {
1475 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1476 0x40a000f0, 0x90100210, 0x400003f1, 0x90330320,
1477};
1478
1479static unsigned int *stac925x_brd_tbl[STAC_925x_MODELS] = {
1480 [STAC_REF] = ref925x_pin_configs,
1481 [STAC_M1] = stac925xM1_pin_configs,
1482 [STAC_M1_2] = stac925xM1_2_pin_configs,
1483 [STAC_M2] = stac925xM2_pin_configs,
1484 [STAC_M2_2] = stac925xM2_2_pin_configs,
1485 [STAC_M3] = stac925xM3_pin_configs,
1486 [STAC_M5] = stac925xM5_pin_configs,
1487 [STAC_M6] = stac925xM6_pin_configs,
1488};
1489
1490static const char *stac925x_models[STAC_925x_MODELS] = {
1491 [STAC_925x_AUTO] = "auto",
1492 [STAC_REF] = "ref",
1493 [STAC_M1] = "m1",
1494 [STAC_M1_2] = "m1-2",
1495 [STAC_M2] = "m2",
1496 [STAC_M2_2] = "m2-2",
1497 [STAC_M3] = "m3",
1498 [STAC_M5] = "m5",
1499 [STAC_M6] = "m6",
1500};
1501
1502static struct snd_pci_quirk stac925x_codec_id_cfg_tbl[] = {
1503 SND_PCI_QUIRK(0x107b, 0x0316, "Gateway M255", STAC_M2),
1504 SND_PCI_QUIRK(0x107b, 0x0366, "Gateway MP6954", STAC_M5),
1505 SND_PCI_QUIRK(0x107b, 0x0461, "Gateway NX560XL", STAC_M1),
1506 SND_PCI_QUIRK(0x107b, 0x0681, "Gateway NX860", STAC_M2),
1507 SND_PCI_QUIRK(0x107b, 0x0367, "Gateway MX6453", STAC_M1_2),
1508
1509 SND_PCI_QUIRK(0x107b, 0x0281, "Gateway mobile", STAC_M1),
1510 SND_PCI_QUIRK(0x107b, 0x0507, "Gateway mobile", STAC_M3),
1511 SND_PCI_QUIRK(0x107b, 0x0281, "Gateway mobile", STAC_M6),
1512 SND_PCI_QUIRK(0x107b, 0x0685, "Gateway mobile", STAC_M2_2),
1513 {}
1514};
1515
1516static struct snd_pci_quirk stac925x_cfg_tbl[] = {
1517
1518 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, "DFI LanParty", STAC_REF),
1519 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101, "DFI LanParty", STAC_REF),
1520 SND_PCI_QUIRK(0x8384, 0x7632, "Stac9202 Reference Board", STAC_REF),
1521
1522
1523 SND_PCI_QUIRK(0x1002, 0x437b, "Gateway mobile", STAC_M2_2),
1524
1525 {}
1526};
1527
1528static unsigned int ref92hd73xx_pin_configs[13] = {
1529 0x02214030, 0x02a19040, 0x01a19020, 0x02214030,
1530 0x0181302e, 0x01014010, 0x01014020, 0x01014030,
1531 0x02319040, 0x90a000f0, 0x90a000f0, 0x01452050,
1532 0x01452050,
1533};
1534
1535static unsigned int dell_m6_pin_configs[13] = {
1536 0x0321101f, 0x4f00000f, 0x4f0000f0, 0x90170110,
1537 0x03a11020, 0x0321101f, 0x4f0000f0, 0x4f0000f0,
1538 0x4f0000f0, 0x90a60160, 0x4f0000f0, 0x4f0000f0,
1539 0x4f0000f0,
1540};
1541
1542static unsigned int alienware_m17x_pin_configs[13] = {
1543 0x0321101f, 0x0321101f, 0x03a11020, 0x03014020,
1544 0x90170110, 0x4f0000f0, 0x4f0000f0, 0x4f0000f0,
1545 0x4f0000f0, 0x90a60160, 0x4f0000f0, 0x4f0000f0,
1546 0x904601b0,
1547};
1548
1549static unsigned int intel_dg45id_pin_configs[13] = {
1550 0x02214230, 0x02A19240, 0x01013214, 0x01014210,
1551 0x01A19250, 0x01011212, 0x01016211
1552};
1553
1554static unsigned int *stac92hd73xx_brd_tbl[STAC_92HD73XX_MODELS] = {
1555 [STAC_92HD73XX_REF] = ref92hd73xx_pin_configs,
1556 [STAC_DELL_M6_AMIC] = dell_m6_pin_configs,
1557 [STAC_DELL_M6_DMIC] = dell_m6_pin_configs,
1558 [STAC_DELL_M6_BOTH] = dell_m6_pin_configs,
1559 [STAC_DELL_EQ] = dell_m6_pin_configs,
1560 [STAC_ALIENWARE_M17X] = alienware_m17x_pin_configs,
1561 [STAC_92HD73XX_INTEL] = intel_dg45id_pin_configs,
1562};
1563
1564static const char *stac92hd73xx_models[STAC_92HD73XX_MODELS] = {
1565 [STAC_92HD73XX_AUTO] = "auto",
1566 [STAC_92HD73XX_NO_JD] = "no-jd",
1567 [STAC_92HD73XX_REF] = "ref",
1568 [STAC_92HD73XX_INTEL] = "intel",
1569 [STAC_DELL_M6_AMIC] = "dell-m6-amic",
1570 [STAC_DELL_M6_DMIC] = "dell-m6-dmic",
1571 [STAC_DELL_M6_BOTH] = "dell-m6",
1572 [STAC_DELL_EQ] = "dell-eq",
1573 [STAC_ALIENWARE_M17X] = "alienware",
1574};
1575
1576static struct snd_pci_quirk stac92hd73xx_cfg_tbl[] = {
1577
1578 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1579 "DFI LanParty", STAC_92HD73XX_REF),
1580 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1581 "DFI LanParty", STAC_92HD73XX_REF),
1582 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5002,
1583 "Intel DG45ID", STAC_92HD73XX_INTEL),
1584 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5003,
1585 "Intel DG45FC", STAC_92HD73XX_INTEL),
1586 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0254,
1587 "Dell Studio 1535", STAC_DELL_M6_DMIC),
1588 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0255,
1589 "unknown Dell", STAC_DELL_M6_DMIC),
1590 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0256,
1591 "unknown Dell", STAC_DELL_M6_BOTH),
1592 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0257,
1593 "unknown Dell", STAC_DELL_M6_BOTH),
1594 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025e,
1595 "unknown Dell", STAC_DELL_M6_AMIC),
1596 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025f,
1597 "unknown Dell", STAC_DELL_M6_AMIC),
1598 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0271,
1599 "unknown Dell", STAC_DELL_M6_DMIC),
1600 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0272,
1601 "unknown Dell", STAC_DELL_M6_DMIC),
1602 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x029f,
1603 "Dell Studio 1537", STAC_DELL_M6_DMIC),
1604 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02a0,
1605 "Dell Studio 17", STAC_DELL_M6_DMIC),
1606 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02be,
1607 "Dell Studio 1555", STAC_DELL_M6_DMIC),
1608 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02bd,
1609 "Dell Studio 1557", STAC_DELL_M6_DMIC),
1610 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02fe,
1611 "Dell Studio XPS 1645", STAC_DELL_M6_BOTH),
1612 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0413,
1613 "Dell Studio 1558", STAC_DELL_M6_BOTH),
1614 {}
1615};
1616
1617static struct snd_pci_quirk stac92hd73xx_codec_id_cfg_tbl[] = {
1618 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02a1,
1619 "Alienware M17x", STAC_ALIENWARE_M17X),
1620 {}
1621};
1622
1623static unsigned int ref92hd83xxx_pin_configs[10] = {
1624 0x02214030, 0x02211010, 0x02a19020, 0x02170130,
1625 0x01014050, 0x01819040, 0x01014020, 0x90a3014e,
1626 0x01451160, 0x98560170,
1627};
1628
1629static unsigned int dell_s14_pin_configs[10] = {
1630 0x0221403f, 0x0221101f, 0x02a19020, 0x90170110,
1631 0x40f000f0, 0x40f000f0, 0x40f000f0, 0x90a60160,
1632 0x40f000f0, 0x40f000f0,
1633};
1634
1635static unsigned int *stac92hd83xxx_brd_tbl[STAC_92HD83XXX_MODELS] = {
1636 [STAC_92HD83XXX_REF] = ref92hd83xxx_pin_configs,
1637 [STAC_92HD83XXX_PWR_REF] = ref92hd83xxx_pin_configs,
1638 [STAC_DELL_S14] = dell_s14_pin_configs,
1639};
1640
1641static const char *stac92hd83xxx_models[STAC_92HD83XXX_MODELS] = {
1642 [STAC_92HD83XXX_AUTO] = "auto",
1643 [STAC_92HD83XXX_REF] = "ref",
1644 [STAC_92HD83XXX_PWR_REF] = "mic-ref",
1645 [STAC_DELL_S14] = "dell-s14",
1646 [STAC_92HD83XXX_HP] = "hp",
1647};
1648
1649static struct snd_pci_quirk stac92hd83xxx_cfg_tbl[] = {
1650
1651 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1652 "DFI LanParty", STAC_92HD83XXX_REF),
1653 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1654 "DFI LanParty", STAC_92HD83XXX_REF),
1655 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ba,
1656 "unknown Dell", STAC_DELL_S14),
1657 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xff00, 0x3600,
1658 "HP", STAC_92HD83XXX_HP),
1659 {}
1660};
1661
1662static unsigned int ref92hd71bxx_pin_configs[STAC92HD71BXX_NUM_PINS] = {
1663 0x02214030, 0x02a19040, 0x01a19020, 0x01014010,
1664 0x0181302e, 0x01014010, 0x01019020, 0x90a000f0,
1665 0x90a000f0, 0x01452050, 0x01452050, 0x00000000,
1666 0x00000000
1667};
1668
1669static unsigned int dell_m4_1_pin_configs[STAC92HD71BXX_NUM_PINS] = {
1670 0x0421101f, 0x04a11221, 0x40f000f0, 0x90170110,
1671 0x23a1902e, 0x23014250, 0x40f000f0, 0x90a000f0,
1672 0x40f000f0, 0x4f0000f0, 0x4f0000f0, 0x00000000,
1673 0x00000000
1674};
1675
1676static unsigned int dell_m4_2_pin_configs[STAC92HD71BXX_NUM_PINS] = {
1677 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1678 0x23a1902e, 0x23014250, 0x40f000f0, 0x40f000f0,
1679 0x40f000f0, 0x044413b0, 0x044413b0, 0x00000000,
1680 0x00000000
1681};
1682
1683static unsigned int dell_m4_3_pin_configs[STAC92HD71BXX_NUM_PINS] = {
1684 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1685 0x40f000f0, 0x40f000f0, 0x40f000f0, 0x90a000f0,
1686 0x40f000f0, 0x044413b0, 0x044413b0, 0x00000000,
1687 0x00000000
1688};
1689
1690static unsigned int *stac92hd71bxx_brd_tbl[STAC_92HD71BXX_MODELS] = {
1691 [STAC_92HD71BXX_REF] = ref92hd71bxx_pin_configs,
1692 [STAC_DELL_M4_1] = dell_m4_1_pin_configs,
1693 [STAC_DELL_M4_2] = dell_m4_2_pin_configs,
1694 [STAC_DELL_M4_3] = dell_m4_3_pin_configs,
1695 [STAC_HP_M4] = NULL,
1696 [STAC_HP_DV4] = NULL,
1697 [STAC_HP_DV5] = NULL,
1698 [STAC_HP_HDX] = NULL,
1699 [STAC_HP_DV4_1222NR] = NULL,
1700};
1701
1702static const char *stac92hd71bxx_models[STAC_92HD71BXX_MODELS] = {
1703 [STAC_92HD71BXX_AUTO] = "auto",
1704 [STAC_92HD71BXX_REF] = "ref",
1705 [STAC_DELL_M4_1] = "dell-m4-1",
1706 [STAC_DELL_M4_2] = "dell-m4-2",
1707 [STAC_DELL_M4_3] = "dell-m4-3",
1708 [STAC_HP_M4] = "hp-m4",
1709 [STAC_HP_DV4] = "hp-dv4",
1710 [STAC_HP_DV5] = "hp-dv5",
1711 [STAC_HP_HDX] = "hp-hdx",
1712 [STAC_HP_DV4_1222NR] = "hp-dv4-1222nr",
1713};
1714
1715static struct snd_pci_quirk stac92hd71bxx_cfg_tbl[] = {
1716
1717 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1718 "DFI LanParty", STAC_92HD71BXX_REF),
1719 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1720 "DFI LanParty", STAC_92HD71BXX_REF),
1721 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x30fb,
1722 "HP dv4-1222nr", STAC_HP_DV4_1222NR),
1723 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x1720,
1724 "HP", STAC_HP_DV5),
1725 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3080,
1726 "HP", STAC_HP_DV5),
1727 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x30f0,
1728 "HP dv4-7", STAC_HP_DV4),
1729 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3600,
1730 "HP dv4-7", STAC_HP_DV5),
1731 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3610,
1732 "HP HDX", STAC_HP_HDX),
1733 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361a,
1734 "HP mini 1000", STAC_HP_M4),
1735 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361b,
1736 "HP HDX", STAC_HP_HDX),
1737 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3620,
1738 "HP dv6", STAC_HP_DV5),
1739 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3061,
1740 "HP dv6", STAC_HP_DV5),
1741 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x7010,
1742 "HP", STAC_HP_DV5),
1743 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0233,
1744 "unknown Dell", STAC_DELL_M4_1),
1745 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0234,
1746 "unknown Dell", STAC_DELL_M4_1),
1747 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0250,
1748 "unknown Dell", STAC_DELL_M4_1),
1749 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024f,
1750 "unknown Dell", STAC_DELL_M4_1),
1751 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024d,
1752 "unknown Dell", STAC_DELL_M4_1),
1753 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0251,
1754 "unknown Dell", STAC_DELL_M4_1),
1755 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0277,
1756 "unknown Dell", STAC_DELL_M4_1),
1757 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0263,
1758 "unknown Dell", STAC_DELL_M4_2),
1759 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0265,
1760 "unknown Dell", STAC_DELL_M4_2),
1761 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0262,
1762 "unknown Dell", STAC_DELL_M4_2),
1763 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0264,
1764 "unknown Dell", STAC_DELL_M4_2),
1765 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02aa,
1766 "unknown Dell", STAC_DELL_M4_3),
1767 {}
1768};
1769
1770static unsigned int ref922x_pin_configs[10] = {
1771 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
1772 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
1773 0x40000100, 0x40000100,
1774};
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784static unsigned int dell_922x_d81_pin_configs[10] = {
1785 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1786 0x02a19020, 0x01117011, 0x400001f0, 0x400001f1,
1787 0x01813122, 0x400001f2,
1788};
1789
1790
1791
1792
1793
1794
1795static unsigned int dell_922x_d82_pin_configs[10] = {
1796 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1797 0x02a19020, 0x01117011, 0x01451140, 0x400001f0,
1798 0x01813122, 0x400001f1,
1799};
1800
1801
1802
1803
1804
1805static unsigned int dell_922x_m81_pin_configs[10] = {
1806 0x0321101f, 0x01112024, 0x01111222, 0x91174220,
1807 0x03a11050, 0x01116221, 0x90a70330, 0x01452340,
1808 0x40C003f1, 0x405003f0,
1809};
1810
1811
1812
1813
1814
1815static unsigned int dell_922x_m82_pin_configs[10] = {
1816 0x02211211, 0x408103ff, 0x02a1123e, 0x90100310,
1817 0x408003f1, 0x0221121f, 0x03451340, 0x40c003f2,
1818 0x508003f3, 0x405003f4,
1819};
1820
1821static unsigned int d945gtp3_pin_configs[10] = {
1822 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
1823 0x40000100, 0x40000100, 0x40000100, 0x40000100,
1824 0x02a19120, 0x40000100,
1825};
1826
1827static unsigned int d945gtp5_pin_configs[10] = {
1828 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
1829 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
1830 0x02a19320, 0x40000100,
1831};
1832
1833static unsigned int intel_mac_v1_pin_configs[10] = {
1834 0x0121e21f, 0x400000ff, 0x9017e110, 0x400000fd,
1835 0x400000fe, 0x0181e020, 0x1145e030, 0x11c5e240,
1836 0x400000fc, 0x400000fb,
1837};
1838
1839static unsigned int intel_mac_v2_pin_configs[10] = {
1840 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
1841 0x400000fe, 0x0181e020, 0x1145e230, 0x500000fa,
1842 0x400000fc, 0x400000fb,
1843};
1844
1845static unsigned int intel_mac_v3_pin_configs[10] = {
1846 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
1847 0x400000fe, 0x0181e020, 0x1145e230, 0x11c5e240,
1848 0x400000fc, 0x400000fb,
1849};
1850
1851static unsigned int intel_mac_v4_pin_configs[10] = {
1852 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
1853 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
1854 0x400000fc, 0x400000fb,
1855};
1856
1857static unsigned int intel_mac_v5_pin_configs[10] = {
1858 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
1859 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
1860 0x400000fc, 0x400000fb,
1861};
1862
1863static unsigned int ecs202_pin_configs[10] = {
1864 0x0221401f, 0x02a19020, 0x01a19020, 0x01114010,
1865 0x408000f0, 0x01813022, 0x074510a0, 0x40c400f1,
1866 0x9037012e, 0x40e000f2,
1867};
1868
1869static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
1870 [STAC_D945_REF] = ref922x_pin_configs,
1871 [STAC_D945GTP3] = d945gtp3_pin_configs,
1872 [STAC_D945GTP5] = d945gtp5_pin_configs,
1873 [STAC_INTEL_MAC_V1] = intel_mac_v1_pin_configs,
1874 [STAC_INTEL_MAC_V2] = intel_mac_v2_pin_configs,
1875 [STAC_INTEL_MAC_V3] = intel_mac_v3_pin_configs,
1876 [STAC_INTEL_MAC_V4] = intel_mac_v4_pin_configs,
1877 [STAC_INTEL_MAC_V5] = intel_mac_v5_pin_configs,
1878 [STAC_INTEL_MAC_AUTO] = intel_mac_v3_pin_configs,
1879
1880 [STAC_MACMINI] = intel_mac_v3_pin_configs,
1881 [STAC_MACBOOK] = intel_mac_v5_pin_configs,
1882 [STAC_MACBOOK_PRO_V1] = intel_mac_v3_pin_configs,
1883 [STAC_MACBOOK_PRO_V2] = intel_mac_v3_pin_configs,
1884 [STAC_IMAC_INTEL] = intel_mac_v2_pin_configs,
1885 [STAC_IMAC_INTEL_20] = intel_mac_v3_pin_configs,
1886 [STAC_ECS_202] = ecs202_pin_configs,
1887 [STAC_922X_DELL_D81] = dell_922x_d81_pin_configs,
1888 [STAC_922X_DELL_D82] = dell_922x_d82_pin_configs,
1889 [STAC_922X_DELL_M81] = dell_922x_m81_pin_configs,
1890 [STAC_922X_DELL_M82] = dell_922x_m82_pin_configs,
1891};
1892
1893static const char *stac922x_models[STAC_922X_MODELS] = {
1894 [STAC_922X_AUTO] = "auto",
1895 [STAC_D945_REF] = "ref",
1896 [STAC_D945GTP5] = "5stack",
1897 [STAC_D945GTP3] = "3stack",
1898 [STAC_INTEL_MAC_V1] = "intel-mac-v1",
1899 [STAC_INTEL_MAC_V2] = "intel-mac-v2",
1900 [STAC_INTEL_MAC_V3] = "intel-mac-v3",
1901 [STAC_INTEL_MAC_V4] = "intel-mac-v4",
1902 [STAC_INTEL_MAC_V5] = "intel-mac-v5",
1903 [STAC_INTEL_MAC_AUTO] = "intel-mac-auto",
1904
1905 [STAC_MACMINI] = "macmini",
1906 [STAC_MACBOOK] = "macbook",
1907 [STAC_MACBOOK_PRO_V1] = "macbook-pro-v1",
1908 [STAC_MACBOOK_PRO_V2] = "macbook-pro",
1909 [STAC_IMAC_INTEL] = "imac-intel",
1910 [STAC_IMAC_INTEL_20] = "imac-intel-20",
1911 [STAC_ECS_202] = "ecs202",
1912 [STAC_922X_DELL_D81] = "dell-d81",
1913 [STAC_922X_DELL_D82] = "dell-d82",
1914 [STAC_922X_DELL_M81] = "dell-m81",
1915 [STAC_922X_DELL_M82] = "dell-m82",
1916};
1917
1918static struct snd_pci_quirk stac922x_cfg_tbl[] = {
1919
1920 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1921 "DFI LanParty", STAC_D945_REF),
1922 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1923 "DFI LanParty", STAC_D945_REF),
1924
1925 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101,
1926 "Intel D945G", STAC_D945GTP3),
1927 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0202,
1928 "Intel D945G", STAC_D945GTP3),
1929 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0606,
1930 "Intel D945G", STAC_D945GTP3),
1931 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0601,
1932 "Intel D945G", STAC_D945GTP3),
1933 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0111,
1934 "Intel D945G", STAC_D945GTP3),
1935 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1115,
1936 "Intel D945G", STAC_D945GTP3),
1937 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1116,
1938 "Intel D945G", STAC_D945GTP3),
1939 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1117,
1940 "Intel D945G", STAC_D945GTP3),
1941 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1118,
1942 "Intel D945G", STAC_D945GTP3),
1943 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1119,
1944 "Intel D945G", STAC_D945GTP3),
1945 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x8826,
1946 "Intel D945G", STAC_D945GTP3),
1947 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5049,
1948 "Intel D945G", STAC_D945GTP3),
1949 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5055,
1950 "Intel D945G", STAC_D945GTP3),
1951 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5048,
1952 "Intel D945G", STAC_D945GTP3),
1953 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0110,
1954 "Intel D945G", STAC_D945GTP3),
1955
1956 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0404,
1957 "Intel D945G", STAC_D945GTP5),
1958 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0303,
1959 "Intel D945G", STAC_D945GTP5),
1960 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0013,
1961 "Intel D945G", STAC_D945GTP5),
1962 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0417,
1963 "Intel D945G", STAC_D945GTP5),
1964
1965 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0b0b,
1966 "Intel D945P", STAC_D945GTP3),
1967 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0112,
1968 "Intel D945P", STAC_D945GTP3),
1969 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0d0d,
1970 "Intel D945P", STAC_D945GTP3),
1971 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0909,
1972 "Intel D945P", STAC_D945GTP3),
1973 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0505,
1974 "Intel D945P", STAC_D945GTP3),
1975 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707,
1976 "Intel D945P", STAC_D945GTP5),
1977
1978 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0204,
1979 "Intel D945", STAC_D945_REF),
1980
1981
1982 SND_PCI_QUIRK(0x8384, 0x7680,
1983 "Mac", STAC_INTEL_MAC_AUTO),
1984
1985 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a7,
1986 "unknown Dell", STAC_922X_DELL_D81),
1987 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a9,
1988 "unknown Dell", STAC_922X_DELL_D81),
1989 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ab,
1990 "unknown Dell", STAC_922X_DELL_D81),
1991 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ac,
1992 "unknown Dell", STAC_922X_DELL_D82),
1993 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bf,
1994 "unknown Dell", STAC_922X_DELL_M81),
1995 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d0,
1996 "unknown Dell", STAC_922X_DELL_D82),
1997 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d1,
1998 "unknown Dell", STAC_922X_DELL_D81),
1999 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d2,
2000 "unknown Dell", STAC_922X_DELL_D81),
2001 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d7,
2002 "Dell XPS M1210", STAC_922X_DELL_M82),
2003
2004 SND_PCI_QUIRK_MASK(0x1019, 0xf000, 0x2000,
2005 "ECS/PC chips", STAC_ECS_202),
2006 {}
2007};
2008
2009static unsigned int ref927x_pin_configs[14] = {
2010 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2011 0x01a19040, 0x01011012, 0x01016011, 0x0101201f,
2012 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
2013 0x01c42190, 0x40000100,
2014};
2015
2016static unsigned int d965_3st_pin_configs[14] = {
2017 0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
2018 0x01a19021, 0x01813024, 0x40000100, 0x40000100,
2019 0x40000100, 0x40000100, 0x40000100, 0x40000100,
2020 0x40000100, 0x40000100
2021};
2022
2023static unsigned int d965_5st_pin_configs[14] = {
2024 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2025 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
2026 0x40000100, 0x40000100, 0x40000100, 0x01442070,
2027 0x40000100, 0x40000100
2028};
2029
2030static unsigned int d965_5st_no_fp_pin_configs[14] = {
2031 0x40000100, 0x40000100, 0x0181304e, 0x01014010,
2032 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
2033 0x40000100, 0x40000100, 0x40000100, 0x01442070,
2034 0x40000100, 0x40000100
2035};
2036
2037static unsigned int dell_3st_pin_configs[14] = {
2038 0x02211230, 0x02a11220, 0x01a19040, 0x01114210,
2039 0x01111212, 0x01116211, 0x01813050, 0x01112214,
2040 0x403003fa, 0x90a60040, 0x90a60040, 0x404003fb,
2041 0x40c003fc, 0x40000100
2042};
2043
2044static unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
2045 [STAC_D965_REF_NO_JD] = ref927x_pin_configs,
2046 [STAC_D965_REF] = ref927x_pin_configs,
2047 [STAC_D965_3ST] = d965_3st_pin_configs,
2048 [STAC_D965_5ST] = d965_5st_pin_configs,
2049 [STAC_D965_5ST_NO_FP] = d965_5st_no_fp_pin_configs,
2050 [STAC_DELL_3ST] = dell_3st_pin_configs,
2051 [STAC_DELL_BIOS] = NULL,
2052 [STAC_927X_VOLKNOB] = NULL,
2053};
2054
2055static const char *stac927x_models[STAC_927X_MODELS] = {
2056 [STAC_927X_AUTO] = "auto",
2057 [STAC_D965_REF_NO_JD] = "ref-no-jd",
2058 [STAC_D965_REF] = "ref",
2059 [STAC_D965_3ST] = "3stack",
2060 [STAC_D965_5ST] = "5stack",
2061 [STAC_D965_5ST_NO_FP] = "5stack-no-fp",
2062 [STAC_DELL_3ST] = "dell-3stack",
2063 [STAC_DELL_BIOS] = "dell-bios",
2064 [STAC_927X_VOLKNOB] = "volknob",
2065};
2066
2067static struct snd_pci_quirk stac927x_cfg_tbl[] = {
2068
2069 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2070 "DFI LanParty", STAC_D965_REF),
2071 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2072 "DFI LanParty", STAC_D965_REF),
2073
2074 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST),
2075 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST),
2076
2077 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2100,
2078 "Intel D965", STAC_D965_3ST),
2079 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2000,
2080 "Intel D965", STAC_D965_3ST),
2081
2082 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01dd, "Dell Dimension E520", STAC_DELL_3ST),
2083 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ed, "Dell ", STAC_DELL_3ST),
2084 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f4, "Dell ", STAC_DELL_3ST),
2085
2086 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f3, "Dell Inspiron 1420", STAC_DELL_BIOS),
2087 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f7, "Dell XPS M1730", STAC_DELL_BIOS),
2088 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0227, "Dell Vostro 1400 ", STAC_DELL_BIOS),
2089 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022e, "Dell ", STAC_DELL_BIOS),
2090 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022f, "Dell Inspiron 1525", STAC_DELL_BIOS),
2091 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0242, "Dell ", STAC_DELL_BIOS),
2092 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0243, "Dell ", STAC_DELL_BIOS),
2093 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ff, "Dell ", STAC_DELL_BIOS),
2094 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0209, "Dell XPS 1330", STAC_DELL_BIOS),
2095
2096 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2300,
2097 "Intel D965", STAC_D965_5ST),
2098 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2500,
2099 "Intel D965", STAC_D965_5ST),
2100
2101 SND_PCI_QUIRK_VENDOR(0x10cf, "FSC", STAC_927X_VOLKNOB),
2102 {}
2103};
2104
2105static unsigned int ref9205_pin_configs[12] = {
2106 0x40000100, 0x40000100, 0x01016011, 0x01014010,
2107 0x01813122, 0x01a19021, 0x01019020, 0x40000100,
2108 0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
2109};
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122static unsigned int dell_9205_m42_pin_configs[12] = {
2123 0x0321101F, 0x03A11020, 0x400003FA, 0x90170310,
2124 0x400003FB, 0x400003FC, 0x400003FD, 0x40F000F9,
2125 0x90A60330, 0x400003FF, 0x0144131F, 0x40C003FE,
2126};
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138static unsigned int dell_9205_m43_pin_configs[12] = {
2139 0x0321101f, 0x03a11020, 0x90a70330, 0x90170310,
2140 0x400000fe, 0x400000ff, 0x400000fd, 0x40f000f9,
2141 0x400000fa, 0x400000fc, 0x0144131f, 0x40c003f8,
2142};
2143
2144static unsigned int dell_9205_m44_pin_configs[12] = {
2145 0x0421101f, 0x04a11020, 0x400003fa, 0x90170310,
2146 0x400003fb, 0x400003fc, 0x400003fd, 0x400003f9,
2147 0x90a60330, 0x400003ff, 0x01441340, 0x40c003fe,
2148};
2149
2150static unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
2151 [STAC_9205_REF] = ref9205_pin_configs,
2152 [STAC_9205_DELL_M42] = dell_9205_m42_pin_configs,
2153 [STAC_9205_DELL_M43] = dell_9205_m43_pin_configs,
2154 [STAC_9205_DELL_M44] = dell_9205_m44_pin_configs,
2155 [STAC_9205_EAPD] = NULL,
2156};
2157
2158static const char *stac9205_models[STAC_9205_MODELS] = {
2159 [STAC_9205_AUTO] = "auto",
2160 [STAC_9205_REF] = "ref",
2161 [STAC_9205_DELL_M42] = "dell-m42",
2162 [STAC_9205_DELL_M43] = "dell-m43",
2163 [STAC_9205_DELL_M44] = "dell-m44",
2164 [STAC_9205_EAPD] = "eapd",
2165};
2166
2167static struct snd_pci_quirk stac9205_cfg_tbl[] = {
2168
2169 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2170 "DFI LanParty", STAC_9205_REF),
2171 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xfb30,
2172 "SigmaTel", STAC_9205_REF),
2173 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2174 "DFI LanParty", STAC_9205_REF),
2175
2176 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f1,
2177 "unknown Dell", STAC_9205_DELL_M42),
2178 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f2,
2179 "unknown Dell", STAC_9205_DELL_M42),
2180 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f8,
2181 "Dell Precision", STAC_9205_DELL_M43),
2182 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f9,
2183 "Dell Precision", STAC_9205_DELL_M43),
2184 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fa,
2185 "Dell Precision", STAC_9205_DELL_M43),
2186 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fc,
2187 "unknown Dell", STAC_9205_DELL_M42),
2188 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fd,
2189 "unknown Dell", STAC_9205_DELL_M42),
2190 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fe,
2191 "Dell Precision", STAC_9205_DELL_M43),
2192 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ff,
2193 "Dell Precision M4300", STAC_9205_DELL_M43),
2194 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0204,
2195 "unknown Dell", STAC_9205_DELL_M42),
2196 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0206,
2197 "Dell Precision", STAC_9205_DELL_M43),
2198 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021b,
2199 "Dell Precision", STAC_9205_DELL_M43),
2200 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021c,
2201 "Dell Precision", STAC_9205_DELL_M43),
2202 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021f,
2203 "Dell Inspiron", STAC_9205_DELL_M44),
2204 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0228,
2205 "Dell Vostro 1500", STAC_9205_DELL_M42),
2206 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0229,
2207 "Dell Vostro 1700", STAC_9205_DELL_M42),
2208
2209 SND_PCI_QUIRK(0x107b, 0x0560, "Gateway T6834c", STAC_9205_EAPD),
2210 SND_PCI_QUIRK(0x107b, 0x0565, "Gateway T1616", STAC_9205_EAPD),
2211 {}
2212};
2213
2214static void stac92xx_set_config_regs(struct hda_codec *codec,
2215 unsigned int *pincfgs)
2216{
2217 int i;
2218 struct sigmatel_spec *spec = codec->spec;
2219
2220 if (!pincfgs)
2221 return;
2222
2223 for (i = 0; i < spec->num_pins; i++)
2224 if (spec->pin_nids[i] && pincfgs[i])
2225 snd_hda_codec_set_pincfg(codec, spec->pin_nids[i],
2226 pincfgs[i]);
2227}
2228
2229
2230
2231
2232static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
2233 struct hda_codec *codec,
2234 struct snd_pcm_substream *substream)
2235{
2236 struct sigmatel_spec *spec = codec->spec;
2237 if (spec->stream_delay)
2238 msleep(spec->stream_delay);
2239 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2240 hinfo);
2241}
2242
2243static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2244 struct hda_codec *codec,
2245 unsigned int stream_tag,
2246 unsigned int format,
2247 struct snd_pcm_substream *substream)
2248{
2249 struct sigmatel_spec *spec = codec->spec;
2250 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
2251}
2252
2253static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2254 struct hda_codec *codec,
2255 struct snd_pcm_substream *substream)
2256{
2257 struct sigmatel_spec *spec = codec->spec;
2258 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2259}
2260
2261
2262
2263
2264static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2265 struct hda_codec *codec,
2266 struct snd_pcm_substream *substream)
2267{
2268 struct sigmatel_spec *spec = codec->spec;
2269 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2270}
2271
2272static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2273 struct hda_codec *codec,
2274 struct snd_pcm_substream *substream)
2275{
2276 struct sigmatel_spec *spec = codec->spec;
2277 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2278}
2279
2280static int stac92xx_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2281 struct hda_codec *codec,
2282 unsigned int stream_tag,
2283 unsigned int format,
2284 struct snd_pcm_substream *substream)
2285{
2286 struct sigmatel_spec *spec = codec->spec;
2287 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2288 stream_tag, format, substream);
2289}
2290
2291static int stac92xx_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2292 struct hda_codec *codec,
2293 struct snd_pcm_substream *substream)
2294{
2295 struct sigmatel_spec *spec = codec->spec;
2296 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2297}
2298
2299
2300
2301
2302
2303static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2304 struct hda_codec *codec,
2305 unsigned int stream_tag,
2306 unsigned int format,
2307 struct snd_pcm_substream *substream)
2308{
2309 struct sigmatel_spec *spec = codec->spec;
2310 hda_nid_t nid = spec->adc_nids[substream->number];
2311
2312 if (spec->powerdown_adcs) {
2313 msleep(40);
2314 snd_hda_codec_write(codec, nid, 0,
2315 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
2316 }
2317 snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format);
2318 return 0;
2319}
2320
2321static int stac92xx_capture_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 hda_nid_t nid = spec->adc_nids[substream->number];
2327
2328 snd_hda_codec_cleanup_stream(codec, nid);
2329 if (spec->powerdown_adcs)
2330 snd_hda_codec_write(codec, nid, 0,
2331 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
2332 return 0;
2333}
2334
2335static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
2336 .substreams = 1,
2337 .channels_min = 2,
2338 .channels_max = 2,
2339
2340 .ops = {
2341 .open = stac92xx_dig_playback_pcm_open,
2342 .close = stac92xx_dig_playback_pcm_close,
2343 .prepare = stac92xx_dig_playback_pcm_prepare,
2344 .cleanup = stac92xx_dig_playback_pcm_cleanup
2345 },
2346};
2347
2348static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
2349 .substreams = 1,
2350 .channels_min = 2,
2351 .channels_max = 2,
2352
2353};
2354
2355static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
2356 .substreams = 1,
2357 .channels_min = 2,
2358 .channels_max = 8,
2359 .nid = 0x02,
2360 .ops = {
2361 .open = stac92xx_playback_pcm_open,
2362 .prepare = stac92xx_playback_pcm_prepare,
2363 .cleanup = stac92xx_playback_pcm_cleanup
2364 },
2365};
2366
2367static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
2368 .substreams = 1,
2369 .channels_min = 2,
2370 .channels_max = 2,
2371 .nid = 0x06,
2372 .ops = {
2373 .open = stac92xx_playback_pcm_open,
2374 .prepare = stac92xx_playback_pcm_prepare,
2375 .cleanup = stac92xx_playback_pcm_cleanup
2376 },
2377};
2378
2379static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
2380 .channels_min = 2,
2381 .channels_max = 2,
2382
2383 .ops = {
2384 .prepare = stac92xx_capture_pcm_prepare,
2385 .cleanup = stac92xx_capture_pcm_cleanup
2386 },
2387};
2388
2389static int stac92xx_build_pcms(struct hda_codec *codec)
2390{
2391 struct sigmatel_spec *spec = codec->spec;
2392 struct hda_pcm *info = spec->pcm_rec;
2393
2394 codec->num_pcms = 1;
2395 codec->pcm_info = info;
2396
2397 info->name = "STAC92xx Analog";
2398 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
2399 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2400 spec->multiout.dac_nids[0];
2401 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
2402 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2403 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adcs;
2404
2405 if (spec->alt_switch) {
2406 codec->num_pcms++;
2407 info++;
2408 info->name = "STAC92xx Analog Alt";
2409 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
2410 }
2411
2412 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2413 codec->num_pcms++;
2414 info++;
2415 info->name = "STAC92xx Digital";
2416 info->pcm_type = spec->autocfg.dig_out_type[0];
2417 if (spec->multiout.dig_out_nid) {
2418 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
2419 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2420 }
2421 if (spec->dig_in_nid) {
2422 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
2423 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2424 }
2425 }
2426
2427 return 0;
2428}
2429
2430static unsigned int stac92xx_get_default_vref(struct hda_codec *codec,
2431 hda_nid_t nid)
2432{
2433 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2434 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
2435 if (pincap & AC_PINCAP_VREF_100)
2436 return AC_PINCTL_VREF_100;
2437 if (pincap & AC_PINCAP_VREF_80)
2438 return AC_PINCTL_VREF_80;
2439 if (pincap & AC_PINCAP_VREF_50)
2440 return AC_PINCTL_VREF_50;
2441 if (pincap & AC_PINCAP_VREF_GRD)
2442 return AC_PINCTL_VREF_GRD;
2443 return 0;
2444}
2445
2446static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
2447
2448{
2449 snd_hda_codec_write_cache(codec, nid, 0,
2450 AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
2451}
2452
2453#define stac92xx_hp_switch_info snd_ctl_boolean_mono_info
2454
2455static int stac92xx_hp_switch_get(struct snd_kcontrol *kcontrol,
2456 struct snd_ctl_elem_value *ucontrol)
2457{
2458 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2459 struct sigmatel_spec *spec = codec->spec;
2460
2461 ucontrol->value.integer.value[0] = !!spec->hp_switch;
2462 return 0;
2463}
2464
2465static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid);
2466
2467static int stac92xx_hp_switch_put(struct snd_kcontrol *kcontrol,
2468 struct snd_ctl_elem_value *ucontrol)
2469{
2470 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2471 struct sigmatel_spec *spec = codec->spec;
2472 int nid = kcontrol->private_value;
2473
2474 spec->hp_switch = ucontrol->value.integer.value[0] ? nid : 0;
2475
2476
2477
2478
2479 stac_issue_unsol_event(codec, nid);
2480
2481 return 1;
2482}
2483
2484static int stac92xx_dc_bias_info(struct snd_kcontrol *kcontrol,
2485 struct snd_ctl_elem_info *uinfo)
2486{
2487 int i;
2488 static char *texts[] = {
2489 "Mic In", "Line In", "Line Out"
2490 };
2491
2492 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2493 struct sigmatel_spec *spec = codec->spec;
2494 hda_nid_t nid = kcontrol->private_value;
2495
2496 if (nid == spec->mic_switch || nid == spec->line_switch)
2497 i = 3;
2498 else
2499 i = 2;
2500
2501 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2502 uinfo->value.enumerated.items = i;
2503 uinfo->count = 1;
2504 if (uinfo->value.enumerated.item >= i)
2505 uinfo->value.enumerated.item = i-1;
2506 strcpy(uinfo->value.enumerated.name,
2507 texts[uinfo->value.enumerated.item]);
2508
2509 return 0;
2510}
2511
2512static int stac92xx_dc_bias_get(struct snd_kcontrol *kcontrol,
2513 struct snd_ctl_elem_value *ucontrol)
2514{
2515 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2516 hda_nid_t nid = kcontrol->private_value;
2517 unsigned int vref = stac92xx_vref_get(codec, nid);
2518
2519 if (vref == stac92xx_get_default_vref(codec, nid))
2520 ucontrol->value.enumerated.item[0] = 0;
2521 else if (vref == AC_PINCTL_VREF_GRD)
2522 ucontrol->value.enumerated.item[0] = 1;
2523 else if (vref == AC_PINCTL_VREF_HIZ)
2524 ucontrol->value.enumerated.item[0] = 2;
2525
2526 return 0;
2527}
2528
2529static int stac92xx_dc_bias_put(struct snd_kcontrol *kcontrol,
2530 struct snd_ctl_elem_value *ucontrol)
2531{
2532 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2533 unsigned int new_vref = 0;
2534 int error;
2535 hda_nid_t nid = kcontrol->private_value;
2536
2537 if (ucontrol->value.enumerated.item[0] == 0)
2538 new_vref = stac92xx_get_default_vref(codec, nid);
2539 else if (ucontrol->value.enumerated.item[0] == 1)
2540 new_vref = AC_PINCTL_VREF_GRD;
2541 else if (ucontrol->value.enumerated.item[0] == 2)
2542 new_vref = AC_PINCTL_VREF_HIZ;
2543 else
2544 return 0;
2545
2546 if (new_vref != stac92xx_vref_get(codec, nid)) {
2547 error = stac92xx_vref_set(codec, nid, new_vref);
2548 return error;
2549 }
2550
2551 return 0;
2552}
2553
2554static int stac92xx_io_switch_info(struct snd_kcontrol *kcontrol,
2555 struct snd_ctl_elem_info *uinfo)
2556{
2557 static char *texts[2];
2558 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2559 struct sigmatel_spec *spec = codec->spec;
2560
2561 if (kcontrol->private_value == spec->line_switch)
2562 texts[0] = "Line In";
2563 else
2564 texts[0] = "Mic In";
2565 texts[1] = "Line Out";
2566 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2567 uinfo->value.enumerated.items = 2;
2568 uinfo->count = 1;
2569
2570 if (uinfo->value.enumerated.item >= 2)
2571 uinfo->value.enumerated.item = 1;
2572 strcpy(uinfo->value.enumerated.name,
2573 texts[uinfo->value.enumerated.item]);
2574
2575 return 0;
2576}
2577
2578static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2579{
2580 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2581 struct sigmatel_spec *spec = codec->spec;
2582 hda_nid_t nid = kcontrol->private_value;
2583 int io_idx = (nid == spec->mic_switch) ? 1 : 0;
2584
2585 ucontrol->value.enumerated.item[0] = spec->io_switch[io_idx];
2586 return 0;
2587}
2588
2589static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2590{
2591 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2592 struct sigmatel_spec *spec = codec->spec;
2593 hda_nid_t nid = kcontrol->private_value;
2594 int io_idx = (nid == spec->mic_switch) ? 1 : 0;
2595 unsigned short val = !!ucontrol->value.enumerated.item[0];
2596
2597 spec->io_switch[io_idx] = val;
2598
2599 if (val)
2600 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
2601 else {
2602 unsigned int pinctl = AC_PINCTL_IN_EN;
2603 if (io_idx)
2604 pinctl |= stac92xx_get_default_vref(codec, nid);
2605 stac92xx_auto_set_pinctl(codec, nid, pinctl);
2606 }
2607
2608
2609
2610
2611 if (spec->hp_detect)
2612 stac_issue_unsol_event(codec, nid);
2613
2614 return 1;
2615}
2616
2617#define stac92xx_clfe_switch_info snd_ctl_boolean_mono_info
2618
2619static int stac92xx_clfe_switch_get(struct snd_kcontrol *kcontrol,
2620 struct snd_ctl_elem_value *ucontrol)
2621{
2622 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2623 struct sigmatel_spec *spec = codec->spec;
2624
2625 ucontrol->value.integer.value[0] = spec->clfe_swap;
2626 return 0;
2627}
2628
2629static int stac92xx_clfe_switch_put(struct snd_kcontrol *kcontrol,
2630 struct snd_ctl_elem_value *ucontrol)
2631{
2632 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2633 struct sigmatel_spec *spec = codec->spec;
2634 hda_nid_t nid = kcontrol->private_value & 0xff;
2635 unsigned int val = !!ucontrol->value.integer.value[0];
2636
2637 if (spec->clfe_swap == val)
2638 return 0;
2639
2640 spec->clfe_swap = val;
2641
2642 snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
2643 spec->clfe_swap ? 0x4 : 0x0);
2644
2645 return 1;
2646}
2647
2648#define STAC_CODEC_HP_SWITCH(xname) \
2649 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2650 .name = xname, \
2651 .index = 0, \
2652 .info = stac92xx_hp_switch_info, \
2653 .get = stac92xx_hp_switch_get, \
2654 .put = stac92xx_hp_switch_put, \
2655 }
2656
2657#define STAC_CODEC_IO_SWITCH(xname, xpval) \
2658 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2659 .name = xname, \
2660 .index = 0, \
2661 .info = stac92xx_io_switch_info, \
2662 .get = stac92xx_io_switch_get, \
2663 .put = stac92xx_io_switch_put, \
2664 .private_value = xpval, \
2665 }
2666
2667#define STAC_CODEC_CLFE_SWITCH(xname, xpval) \
2668 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2669 .name = xname, \
2670 .index = 0, \
2671 .info = stac92xx_clfe_switch_info, \
2672 .get = stac92xx_clfe_switch_get, \
2673 .put = stac92xx_clfe_switch_put, \
2674 .private_value = xpval, \
2675 }
2676
2677enum {
2678 STAC_CTL_WIDGET_VOL,
2679 STAC_CTL_WIDGET_MUTE,
2680 STAC_CTL_WIDGET_MUTE_BEEP,
2681 STAC_CTL_WIDGET_MONO_MUX,
2682 STAC_CTL_WIDGET_HP_SWITCH,
2683 STAC_CTL_WIDGET_IO_SWITCH,
2684 STAC_CTL_WIDGET_CLFE_SWITCH,
2685 STAC_CTL_WIDGET_DC_BIAS
2686};
2687
2688static struct snd_kcontrol_new stac92xx_control_templates[] = {
2689 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2690 HDA_CODEC_MUTE(NULL, 0, 0, 0),
2691 HDA_CODEC_MUTE_BEEP(NULL, 0, 0, 0),
2692 STAC_MONO_MUX,
2693 STAC_CODEC_HP_SWITCH(NULL),
2694 STAC_CODEC_IO_SWITCH(NULL, 0),
2695 STAC_CODEC_CLFE_SWITCH(NULL, 0),
2696 DC_BIAS(NULL, 0, 0),
2697};
2698
2699
2700static struct snd_kcontrol_new *
2701stac_control_new(struct sigmatel_spec *spec,
2702 struct snd_kcontrol_new *ktemp,
2703 const char *name,
2704 unsigned int subdev)
2705{
2706 struct snd_kcontrol_new *knew;
2707
2708 snd_array_init(&spec->kctls, sizeof(*knew), 32);
2709 knew = snd_array_new(&spec->kctls);
2710 if (!knew)
2711 return NULL;
2712 *knew = *ktemp;
2713 knew->name = kstrdup(name, GFP_KERNEL);
2714 if (!knew->name) {
2715
2716 memset(knew, 0, sizeof(*knew));
2717 spec->kctls.alloced--;
2718 return NULL;
2719 }
2720 knew->subdevice = subdev;
2721 return knew;
2722}
2723
2724static int stac92xx_add_control_temp(struct sigmatel_spec *spec,
2725 struct snd_kcontrol_new *ktemp,
2726 int idx, const char *name,
2727 unsigned long val)
2728{
2729 struct snd_kcontrol_new *knew = stac_control_new(spec, ktemp, name,
2730 HDA_SUBDEV_AMP_FLAG);
2731 if (!knew)
2732 return -ENOMEM;
2733 knew->index = idx;
2734 knew->private_value = val;
2735 return 0;
2736}
2737
2738static inline int stac92xx_add_control_idx(struct sigmatel_spec *spec,
2739 int type, int idx, const char *name,
2740 unsigned long val)
2741{
2742 return stac92xx_add_control_temp(spec,
2743 &stac92xx_control_templates[type],
2744 idx, name, val);
2745}
2746
2747
2748
2749static inline int stac92xx_add_control(struct sigmatel_spec *spec, int type,
2750 const char *name, unsigned long val)
2751{
2752 return stac92xx_add_control_idx(spec, type, 0, name, val);
2753}
2754
2755static struct snd_kcontrol_new stac_input_src_temp = {
2756 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2757 .name = "Input Source",
2758 .info = stac92xx_mux_enum_info,
2759 .get = stac92xx_mux_enum_get,
2760 .put = stac92xx_mux_enum_put,
2761};
2762
2763static inline int stac92xx_add_jack_mode_control(struct hda_codec *codec,
2764 hda_nid_t nid, int idx)
2765{
2766 int def_conf = snd_hda_codec_get_pincfg(codec, nid);
2767 int control = 0;
2768 struct sigmatel_spec *spec = codec->spec;
2769 char name[22];
2770
2771 if (!((get_defcfg_connect(def_conf)) & AC_JACK_PORT_FIXED)) {
2772 if (stac92xx_get_default_vref(codec, nid) == AC_PINCTL_VREF_GRD
2773 && nid == spec->line_switch)
2774 control = STAC_CTL_WIDGET_IO_SWITCH;
2775 else if (snd_hda_query_pin_caps(codec, nid)
2776 & (AC_PINCAP_VREF_GRD << AC_PINCAP_VREF_SHIFT))
2777 control = STAC_CTL_WIDGET_DC_BIAS;
2778 else if (nid == spec->mic_switch)
2779 control = STAC_CTL_WIDGET_IO_SWITCH;
2780 }
2781
2782 if (control) {
2783 strcpy(name, auto_pin_cfg_labels[idx]);
2784 return stac92xx_add_control(codec->spec, control,
2785 strcat(name, " Jack Mode"), nid);
2786 }
2787
2788 return 0;
2789}
2790
2791static int stac92xx_add_input_source(struct sigmatel_spec *spec)
2792{
2793 struct snd_kcontrol_new *knew;
2794 struct hda_input_mux *imux = &spec->private_imux;
2795
2796 if (spec->auto_mic)
2797 return 0;
2798 if (!spec->num_adcs || imux->num_items <= 1)
2799 return 0;
2800 knew = stac_control_new(spec, &stac_input_src_temp,
2801 stac_input_src_temp.name, 0);
2802 if (!knew)
2803 return -ENOMEM;
2804 knew->count = spec->num_adcs;
2805 return 0;
2806}
2807
2808
2809static hda_nid_t check_line_out_switch(struct hda_codec *codec)
2810{
2811 struct sigmatel_spec *spec = codec->spec;
2812 struct auto_pin_cfg *cfg = &spec->autocfg;
2813 hda_nid_t nid;
2814 unsigned int pincap;
2815
2816 if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
2817 return 0;
2818 nid = cfg->input_pins[AUTO_PIN_LINE];
2819 pincap = snd_hda_query_pin_caps(codec, nid);
2820 if (pincap & AC_PINCAP_OUT)
2821 return nid;
2822 return 0;
2823}
2824
2825
2826static hda_nid_t check_mic_out_switch(struct hda_codec *codec)
2827{
2828 struct sigmatel_spec *spec = codec->spec;
2829 struct auto_pin_cfg *cfg = &spec->autocfg;
2830 unsigned int def_conf, pincap;
2831 unsigned int mic_pin;
2832
2833 if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
2834 return 0;
2835 mic_pin = AUTO_PIN_MIC;
2836 for (;;) {
2837 hda_nid_t nid = cfg->input_pins[mic_pin];
2838 def_conf = snd_hda_codec_get_pincfg(codec, nid);
2839
2840
2841 if (get_defcfg_connect(def_conf) != AC_JACK_PORT_FIXED) {
2842 pincap = snd_hda_query_pin_caps(codec, nid);
2843 if (pincap & AC_PINCAP_OUT)
2844 return nid;
2845 }
2846 if (mic_pin == AUTO_PIN_MIC)
2847 mic_pin = AUTO_PIN_FRONT_MIC;
2848 else
2849 break;
2850 }
2851 return 0;
2852}
2853
2854static int is_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2855{
2856 int i;
2857
2858 for (i = 0; i < spec->multiout.num_dacs; i++) {
2859 if (spec->multiout.dac_nids[i] == nid)
2860 return 1;
2861 }
2862
2863 return 0;
2864}
2865
2866static int check_all_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2867{
2868 int i;
2869 if (is_in_dac_nids(spec, nid))
2870 return 1;
2871 for (i = 0; i < spec->autocfg.hp_outs; i++)
2872 if (spec->hp_dacs[i] == nid)
2873 return 1;
2874 for (i = 0; i < spec->autocfg.speaker_outs; i++)
2875 if (spec->speaker_dacs[i] == nid)
2876 return 1;
2877 return 0;
2878}
2879
2880static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t nid)
2881{
2882 struct sigmatel_spec *spec = codec->spec;
2883 int j, conn_len;
2884 hda_nid_t conn[HDA_MAX_CONNECTIONS];
2885 unsigned int wcaps, wtype;
2886
2887 conn_len = snd_hda_get_connections(codec, nid, conn,
2888 HDA_MAX_CONNECTIONS);
2889
2890 while (conn_len == 1 && (get_wcaps_type(get_wcaps(codec, conn[0]))
2891 != AC_WID_AUD_OUT)) {
2892 nid = conn[0];
2893 conn_len = snd_hda_get_connections(codec, nid, conn,
2894 HDA_MAX_CONNECTIONS);
2895 }
2896 for (j = 0; j < conn_len; j++) {
2897 wcaps = get_wcaps(codec, conn[j]);
2898 wtype = get_wcaps_type(wcaps);
2899
2900 if (wtype != AC_WID_AUD_OUT || (wcaps & AC_WCAP_DIGITAL))
2901 continue;
2902
2903 if (!check_all_dac_nids(spec, conn[j])) {
2904 if (conn_len > 1) {
2905
2906 snd_hda_codec_write_cache(codec, nid, 0,
2907 AC_VERB_SET_CONNECT_SEL, j);
2908 }
2909 return conn[j];
2910 }
2911 }
2912
2913 if (conn_len > 1) {
2914 for (j = 0; j < conn_len; j++) {
2915 if (conn[j] == spec->multiout.dac_nids[0]) {
2916 snd_hda_codec_write_cache(codec, nid, 0,
2917 AC_VERB_SET_CONNECT_SEL, j);
2918 break;
2919 }
2920 }
2921 }
2922 return 0;
2923}
2924
2925static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid);
2926static int add_spec_extra_dacs(struct sigmatel_spec *spec, hda_nid_t nid);
2927
2928
2929
2930
2931
2932
2933
2934
2935static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec)
2936{
2937 struct sigmatel_spec *spec = codec->spec;
2938 struct auto_pin_cfg *cfg = &spec->autocfg;
2939 int i;
2940 hda_nid_t nid, dac;
2941
2942 for (i = 0; i < cfg->line_outs; i++) {
2943 nid = cfg->line_out_pins[i];
2944 dac = get_unassigned_dac(codec, nid);
2945 if (!dac) {
2946 if (spec->multiout.num_dacs > 0) {
2947
2948
2949
2950 cfg->line_outs = spec->multiout.num_dacs;
2951 break;
2952 }
2953
2954 snd_printk(KERN_ERR
2955 "%s: No available DAC for pin 0x%x\n",
2956 __func__, nid);
2957 return -ENODEV;
2958 }
2959 add_spec_dacs(spec, dac);
2960 }
2961
2962 for (i = 0; i < cfg->hp_outs; i++) {
2963 nid = cfg->hp_pins[i];
2964 dac = get_unassigned_dac(codec, nid);
2965 if (dac) {
2966 if (!spec->multiout.hp_nid)
2967 spec->multiout.hp_nid = dac;
2968 else
2969 add_spec_extra_dacs(spec, dac);
2970 }
2971 spec->hp_dacs[i] = dac;
2972 }
2973
2974 for (i = 0; i < cfg->speaker_outs; i++) {
2975 nid = cfg->speaker_pins[i];
2976 dac = get_unassigned_dac(codec, nid);
2977 if (dac)
2978 add_spec_extra_dacs(spec, dac);
2979 spec->speaker_dacs[i] = dac;
2980 }
2981
2982
2983 nid = check_line_out_switch(codec);
2984 if (nid) {
2985 dac = get_unassigned_dac(codec, nid);
2986 if (dac) {
2987 snd_printdd("STAC: Add line-in 0x%x as output %d\n",
2988 nid, cfg->line_outs);
2989 cfg->line_out_pins[cfg->line_outs] = nid;
2990 cfg->line_outs++;
2991 spec->line_switch = nid;
2992 add_spec_dacs(spec, dac);
2993 }
2994 }
2995
2996 nid = check_mic_out_switch(codec);
2997 if (nid) {
2998 dac = get_unassigned_dac(codec, nid);
2999 if (dac) {
3000 snd_printdd("STAC: Add mic-in 0x%x as output %d\n",
3001 nid, cfg->line_outs);
3002 cfg->line_out_pins[cfg->line_outs] = nid;
3003 cfg->line_outs++;
3004 spec->mic_switch = nid;
3005 add_spec_dacs(spec, dac);
3006 }
3007 }
3008
3009 snd_printd("stac92xx: dac_nids=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
3010 spec->multiout.num_dacs,
3011 spec->multiout.dac_nids[0],
3012 spec->multiout.dac_nids[1],
3013 spec->multiout.dac_nids[2],
3014 spec->multiout.dac_nids[3],
3015 spec->multiout.dac_nids[4]);
3016
3017 return 0;
3018}
3019
3020
3021static int create_controls_idx(struct hda_codec *codec, const char *pfx,
3022 int idx, hda_nid_t nid, int chs)
3023{
3024 struct sigmatel_spec *spec = codec->spec;
3025 char name[32];
3026 int err;
3027
3028 if (!spec->check_volume_offset) {
3029 unsigned int caps, step, nums, db_scale;
3030 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3031 step = (caps & AC_AMPCAP_STEP_SIZE) >>
3032 AC_AMPCAP_STEP_SIZE_SHIFT;
3033 step = (step + 1) * 25;
3034 nums = (caps & AC_AMPCAP_NUM_STEPS) >>
3035 AC_AMPCAP_NUM_STEPS_SHIFT;
3036 db_scale = nums * step;
3037
3038
3039
3040 if (db_scale > 6400 && nums >= 0x1f)
3041 spec->volume_offset = nums / 2;
3042 spec->check_volume_offset = 1;
3043 }
3044
3045 sprintf(name, "%s Playback Volume", pfx);
3046 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_VOL, idx, name,
3047 HDA_COMPOSE_AMP_VAL_OFS(nid, chs, 0, HDA_OUTPUT,
3048 spec->volume_offset));
3049 if (err < 0)
3050 return err;
3051 sprintf(name, "%s Playback Switch", pfx);
3052 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_MUTE, idx, name,
3053 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
3054 if (err < 0)
3055 return err;
3056 return 0;
3057}
3058
3059#define create_controls(codec, pfx, nid, chs) \
3060 create_controls_idx(codec, pfx, 0, nid, chs)
3061
3062static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
3063{
3064 if (spec->multiout.num_dacs > 4) {
3065 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
3066 return 1;
3067 } else {
3068 spec->multiout.dac_nids[spec->multiout.num_dacs] = nid;
3069 spec->multiout.num_dacs++;
3070 }
3071 return 0;
3072}
3073
3074static int add_spec_extra_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
3075{
3076 int i;
3077 for (i = 0; i < ARRAY_SIZE(spec->multiout.extra_out_nid); i++) {
3078 if (!spec->multiout.extra_out_nid[i]) {
3079 spec->multiout.extra_out_nid[i] = nid;
3080 return 0;
3081 }
3082 }
3083 printk(KERN_WARNING "stac92xx: No space for extra DAC 0x%x\n", nid);
3084 return 1;
3085}
3086
3087
3088
3089
3090static int create_multi_out_ctls(struct hda_codec *codec, int num_outs,
3091 const hda_nid_t *pins,
3092 const hda_nid_t *dac_nids,
3093 int type)
3094{
3095 struct sigmatel_spec *spec = codec->spec;
3096 static const char *chname[4] = {
3097 "Front", "Surround", NULL , "Side"
3098 };
3099 hda_nid_t nid;
3100 int i, err;
3101 unsigned int wid_caps;
3102
3103 for (i = 0; i < num_outs && i < ARRAY_SIZE(chname); i++) {
3104 if (type == AUTO_PIN_HP_OUT && !spec->hp_detect) {
3105 wid_caps = get_wcaps(codec, pins[i]);
3106 if (wid_caps & AC_WCAP_UNSOL_CAP)
3107 spec->hp_detect = 1;
3108 }
3109 nid = dac_nids[i];
3110 if (!nid)
3111 continue;
3112 if (type != AUTO_PIN_HP_OUT && i == 2) {
3113
3114 err = create_controls(codec, "Center", nid, 1);
3115 if (err < 0)
3116 return err;
3117 err = create_controls(codec, "LFE", nid, 2);
3118 if (err < 0)
3119 return err;
3120
3121 wid_caps = get_wcaps(codec, nid);
3122
3123 if (wid_caps & AC_WCAP_LR_SWAP) {
3124 err = stac92xx_add_control(spec,
3125 STAC_CTL_WIDGET_CLFE_SWITCH,
3126 "Swap Center/LFE Playback Switch", nid);
3127
3128 if (err < 0)
3129 return err;
3130 }
3131
3132 } else {
3133 const char *name;
3134 int idx;
3135 switch (type) {
3136 case AUTO_PIN_HP_OUT:
3137 name = "Headphone";
3138 idx = i;
3139 break;
3140 case AUTO_PIN_SPEAKER_OUT:
3141 name = "Speaker";
3142 idx = i;
3143 break;
3144 default:
3145 name = chname[i];
3146 idx = 0;
3147 break;
3148 }
3149 err = create_controls_idx(codec, name, idx, nid, 3);
3150 if (err < 0)
3151 return err;
3152 }
3153 }
3154 return 0;
3155}
3156
3157static int stac92xx_add_capvol_ctls(struct hda_codec *codec, unsigned long vol,
3158 unsigned long sw, int idx)
3159{
3160 int err;
3161 err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_VOL, idx,
3162 "Capture Volume", vol);
3163 if (err < 0)
3164 return err;
3165 err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_MUTE, idx,
3166 "Capture Switch", sw);
3167 if (err < 0)
3168 return err;
3169 return 0;
3170}
3171
3172
3173static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
3174 const struct auto_pin_cfg *cfg)
3175{
3176 struct sigmatel_spec *spec = codec->spec;
3177 hda_nid_t nid;
3178 int err;
3179 int idx;
3180
3181 err = create_multi_out_ctls(codec, cfg->line_outs, cfg->line_out_pins,
3182 spec->multiout.dac_nids,
3183 cfg->line_out_type);
3184 if (err < 0)
3185 return err;
3186
3187 if (cfg->hp_outs > 1 && cfg->line_out_type == AUTO_PIN_LINE_OUT) {
3188 err = stac92xx_add_control(spec,
3189 STAC_CTL_WIDGET_HP_SWITCH,
3190 "Headphone as Line Out Switch",
3191 cfg->hp_pins[cfg->hp_outs - 1]);
3192 if (err < 0)
3193 return err;
3194 }
3195
3196 for (idx = AUTO_PIN_MIC; idx <= AUTO_PIN_FRONT_LINE; idx++) {
3197 nid = cfg->input_pins[idx];
3198 if (nid) {
3199 err = stac92xx_add_jack_mode_control(codec, nid, idx);
3200 if (err < 0)
3201 return err;
3202 }
3203 }
3204
3205 return 0;
3206}
3207
3208
3209static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
3210 struct auto_pin_cfg *cfg)
3211{
3212 struct sigmatel_spec *spec = codec->spec;
3213 int err;
3214
3215 err = create_multi_out_ctls(codec, cfg->hp_outs, cfg->hp_pins,
3216 spec->hp_dacs, AUTO_PIN_HP_OUT);
3217 if (err < 0)
3218 return err;
3219
3220 err = create_multi_out_ctls(codec, cfg->speaker_outs, cfg->speaker_pins,
3221 spec->speaker_dacs, AUTO_PIN_SPEAKER_OUT);
3222 if (err < 0)
3223 return err;
3224
3225 return 0;
3226}
3227
3228
3229static const char *stac92xx_mono_labels[4] = {
3230 "DAC0", "DAC1", "Mixer", "DAC2"
3231};
3232
3233
3234static int stac92xx_auto_create_mono_output_ctls(struct hda_codec *codec)
3235{
3236 struct sigmatel_spec *spec = codec->spec;
3237 struct hda_input_mux *mono_mux = &spec->private_mono_mux;
3238 int i, num_cons;
3239 hda_nid_t con_lst[ARRAY_SIZE(stac92xx_mono_labels)];
3240
3241 num_cons = snd_hda_get_connections(codec,
3242 spec->mono_nid,
3243 con_lst,
3244 HDA_MAX_NUM_INPUTS);
3245 if (num_cons <= 0 || num_cons > ARRAY_SIZE(stac92xx_mono_labels))
3246 return -EINVAL;
3247
3248 for (i = 0; i < num_cons; i++) {
3249 mono_mux->items[mono_mux->num_items].label =
3250 stac92xx_mono_labels[i];
3251 mono_mux->items[mono_mux->num_items].index = i;
3252 mono_mux->num_items++;
3253 }
3254
3255 return stac92xx_add_control(spec, STAC_CTL_WIDGET_MONO_MUX,
3256 "Mono Mux", spec->mono_nid);
3257}
3258
3259
3260static int stac92xx_auto_create_beep_ctls(struct hda_codec *codec,
3261 hda_nid_t nid)
3262{
3263 struct sigmatel_spec *spec = codec->spec;
3264 u32 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3265 int err, type = STAC_CTL_WIDGET_MUTE_BEEP;
3266
3267 if (spec->anabeep_nid == nid)
3268 type = STAC_CTL_WIDGET_MUTE;
3269
3270
3271 if ((caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT) {
3272 err = stac92xx_add_control(spec, type,
3273 "Beep Playback Switch",
3274 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3275 if (err < 0)
3276 return err;
3277 }
3278
3279
3280 if ((caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3281 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL,
3282 "Beep Playback Volume",
3283 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3284 if (err < 0)
3285 return err;
3286 }
3287 return 0;
3288}
3289
3290#ifdef CONFIG_SND_HDA_INPUT_BEEP
3291#define stac92xx_dig_beep_switch_info snd_ctl_boolean_mono_info
3292
3293static int stac92xx_dig_beep_switch_get(struct snd_kcontrol *kcontrol,
3294 struct snd_ctl_elem_value *ucontrol)
3295{
3296 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3297 ucontrol->value.integer.value[0] = codec->beep->enabled;
3298 return 0;
3299}
3300
3301static int stac92xx_dig_beep_switch_put(struct snd_kcontrol *kcontrol,
3302 struct snd_ctl_elem_value *ucontrol)
3303{
3304 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3305 return snd_hda_enable_beep_device(codec, ucontrol->value.integer.value[0]);
3306}
3307
3308static struct snd_kcontrol_new stac92xx_dig_beep_ctrl = {
3309 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3310 .info = stac92xx_dig_beep_switch_info,
3311 .get = stac92xx_dig_beep_switch_get,
3312 .put = stac92xx_dig_beep_switch_put,
3313};
3314
3315static int stac92xx_beep_switch_ctl(struct hda_codec *codec)
3316{
3317 return stac92xx_add_control_temp(codec->spec, &stac92xx_dig_beep_ctrl,
3318 0, "Beep Playback Switch", 0);
3319}
3320#endif
3321
3322static int stac92xx_auto_create_mux_input_ctls(struct hda_codec *codec)
3323{
3324 struct sigmatel_spec *spec = codec->spec;
3325 int i, j, err = 0;
3326
3327 for (i = 0; i < spec->num_muxes; i++) {
3328 hda_nid_t nid;
3329 unsigned int wcaps;
3330 unsigned long val;
3331
3332 nid = spec->mux_nids[i];
3333 wcaps = get_wcaps(codec, nid);
3334 if (!(wcaps & AC_WCAP_OUT_AMP))
3335 continue;
3336
3337
3338
3339
3340 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3341 for (j = 0; j < spec->num_caps; j++) {
3342 if (spec->capvols[j] == val)
3343 break;
3344 }
3345 if (j < spec->num_caps)
3346 continue;
3347
3348 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_VOL, i,
3349 "Mux Capture Volume", val);
3350 if (err < 0)
3351 return err;
3352 }
3353 return 0;
3354};
3355
3356static const char *stac92xx_spdif_labels[3] = {
3357 "Digital Playback", "Analog Mux 1", "Analog Mux 2",
3358};
3359
3360static int stac92xx_auto_create_spdif_mux_ctls(struct hda_codec *codec)
3361{
3362 struct sigmatel_spec *spec = codec->spec;
3363 struct hda_input_mux *spdif_mux = &spec->private_smux;
3364 const char **labels = spec->spdif_labels;
3365 int i, num_cons;
3366 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
3367
3368 num_cons = snd_hda_get_connections(codec,
3369 spec->smux_nids[0],
3370 con_lst,
3371 HDA_MAX_NUM_INPUTS);
3372 if (num_cons <= 0)
3373 return -EINVAL;
3374
3375 if (!labels)
3376 labels = stac92xx_spdif_labels;
3377
3378 for (i = 0; i < num_cons; i++) {
3379 spdif_mux->items[spdif_mux->num_items].label = labels[i];
3380 spdif_mux->items[spdif_mux->num_items].index = i;
3381 spdif_mux->num_items++;
3382 }
3383
3384 return 0;
3385}
3386
3387
3388static const char *stac92xx_dmic_labels[5] = {
3389 "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
3390 "Digital Mic 3", "Digital Mic 4"
3391};
3392
3393static int get_connection_index(struct hda_codec *codec, hda_nid_t mux,
3394 hda_nid_t nid)
3395{
3396 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
3397 int i, nums;
3398
3399 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
3400 for (i = 0; i < nums; i++)
3401 if (conn[i] == nid)
3402 return i;
3403 return -1;
3404}
3405
3406
3407
3408static int create_elem_capture_vol(struct hda_codec *codec, hda_nid_t nid,
3409 const char *label, int direction)
3410{
3411 unsigned int caps, nums;
3412 char name[32];
3413 int err;
3414
3415 if (direction == HDA_OUTPUT)
3416 caps = AC_WCAP_OUT_AMP;
3417 else
3418 caps = AC_WCAP_IN_AMP;
3419 if (!(get_wcaps(codec, nid) & caps))
3420 return 0;
3421 caps = query_amp_caps(codec, nid, direction);
3422 nums = (caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT;
3423 if (!nums)
3424 return 0;
3425 snprintf(name, sizeof(name), "%s Capture Volume", label);
3426 err = stac92xx_add_control(codec->spec, STAC_CTL_WIDGET_VOL, name,
3427 HDA_COMPOSE_AMP_VAL(nid, 3, 0, direction));
3428 if (err < 0)
3429 return err;
3430 return 1;
3431}
3432
3433
3434static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
3435 const struct auto_pin_cfg *cfg)
3436{
3437 struct sigmatel_spec *spec = codec->spec;
3438 struct hda_input_mux *imux = &spec->private_imux;
3439 struct hda_input_mux *dimux = &spec->private_dimux;
3440 int err, i, active_mics;
3441 unsigned int def_conf;
3442
3443 dimux->items[dimux->num_items].label = stac92xx_dmic_labels[0];
3444 dimux->items[dimux->num_items].index = 0;
3445 dimux->num_items++;
3446
3447 active_mics = 0;
3448 for (i = 0; i < spec->num_dmics; i++) {
3449
3450 if (get_wcaps_type(get_wcaps(codec, spec->dmic_nids[i]))
3451 != AC_WID_PIN)
3452 continue;
3453 def_conf = snd_hda_codec_get_pincfg(codec, spec->dmic_nids[i]);
3454 if (get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)
3455 active_mics++;
3456 }
3457
3458 for (i = 0; i < spec->num_dmics; i++) {
3459 hda_nid_t nid;
3460 int index;
3461 const char *label;
3462
3463 nid = spec->dmic_nids[i];
3464 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
3465 continue;
3466 def_conf = snd_hda_codec_get_pincfg(codec, nid);
3467 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
3468 continue;
3469
3470 index = get_connection_index(codec, spec->dmux_nids[0], nid);
3471 if (index < 0)
3472 continue;
3473
3474 if (active_mics == 1)
3475 label = "Digital Mic";
3476 else
3477 label = stac92xx_dmic_labels[dimux->num_items];
3478
3479 err = create_elem_capture_vol(codec, nid, label, HDA_INPUT);
3480 if (err < 0)
3481 return err;
3482 if (!err) {
3483 err = create_elem_capture_vol(codec, nid, label,
3484 HDA_OUTPUT);
3485 if (err < 0)
3486 return err;
3487 }
3488
3489 dimux->items[dimux->num_items].label = label;
3490 dimux->items[dimux->num_items].index = index;
3491 dimux->num_items++;
3492 if (snd_hda_get_bool_hint(codec, "separate_dmux") != 1) {
3493 imux->items[imux->num_items].label = label;
3494 imux->items[imux->num_items].index = index;
3495 imux->num_items++;
3496 }
3497 }
3498
3499 return 0;
3500}
3501
3502static int check_mic_pin(struct hda_codec *codec, hda_nid_t nid,
3503 hda_nid_t *fixed, hda_nid_t *ext)
3504{
3505 unsigned int cfg;
3506
3507 if (!nid)
3508 return 0;
3509 cfg = snd_hda_codec_get_pincfg(codec, nid);
3510 switch (get_defcfg_connect(cfg)) {
3511 case AC_JACK_PORT_FIXED:
3512 if (*fixed)
3513 return 1;
3514 *fixed = nid;
3515 break;
3516 case AC_JACK_PORT_COMPLEX:
3517 if (*ext)
3518 return 1;
3519 *ext = nid;
3520 break;
3521 }
3522 return 0;
3523}
3524
3525static int set_mic_route(struct hda_codec *codec,
3526 struct sigmatel_mic_route *mic,
3527 hda_nid_t pin)
3528{
3529 struct sigmatel_spec *spec = codec->spec;
3530 struct auto_pin_cfg *cfg = &spec->autocfg;
3531 int i;
3532
3533 mic->pin = pin;
3534 for (i = AUTO_PIN_MIC; i <= AUTO_PIN_FRONT_MIC; i++)
3535 if (pin == cfg->input_pins[i])
3536 break;
3537 if (i <= AUTO_PIN_FRONT_MIC) {
3538
3539 i = get_connection_index(codec, spec->mux_nids[0], pin);
3540 if (i < 0)
3541 return -1;
3542 mic->mux_idx = i;
3543 mic->dmux_idx = -1;
3544 if (spec->dmux_nids)
3545 mic->dmux_idx = get_connection_index(codec,
3546 spec->dmux_nids[0],
3547 spec->mux_nids[0]);
3548 } else if (spec->dmux_nids) {
3549
3550 i = get_connection_index(codec, spec->dmux_nids[0], pin);
3551 if (i < 0)
3552 return -1;
3553 mic->dmux_idx = i;
3554 mic->mux_idx = -1;
3555 if (spec->mux_nids)
3556 mic->mux_idx = get_connection_index(codec,
3557 spec->mux_nids[0],
3558 spec->dmux_nids[0]);
3559 }
3560 return 0;
3561}
3562
3563
3564static int stac_check_auto_mic(struct hda_codec *codec)
3565{
3566 struct sigmatel_spec *spec = codec->spec;
3567 struct auto_pin_cfg *cfg = &spec->autocfg;
3568 hda_nid_t fixed, ext;
3569 int i;
3570
3571 for (i = AUTO_PIN_LINE; i < AUTO_PIN_LAST; i++) {
3572 if (cfg->input_pins[i])
3573 return 0;
3574 }
3575 fixed = ext = 0;
3576 for (i = AUTO_PIN_MIC; i <= AUTO_PIN_FRONT_MIC; i++)
3577 if (check_mic_pin(codec, cfg->input_pins[i], &fixed, &ext))
3578 return 0;
3579 for (i = 0; i < spec->num_dmics; i++)
3580 if (check_mic_pin(codec, spec->dmic_nids[i], &fixed, &ext))
3581 return 0;
3582 if (!fixed || !ext)
3583 return 0;
3584 if (!(get_wcaps(codec, ext) & AC_WCAP_UNSOL_CAP))
3585 return 0;
3586 if (set_mic_route(codec, &spec->ext_mic, ext) ||
3587 set_mic_route(codec, &spec->int_mic, fixed))
3588 return 0;
3589 return 1;
3590}
3591
3592
3593static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
3594{
3595 struct sigmatel_spec *spec = codec->spec;
3596 struct hda_input_mux *imux = &spec->private_imux;
3597 int i, j;
3598
3599 for (i = 0; i < AUTO_PIN_LAST; i++) {
3600 hda_nid_t nid = cfg->input_pins[i];
3601 int index, err;
3602
3603 if (!nid)
3604 continue;
3605 index = -1;
3606 for (j = 0; j < spec->num_muxes; j++) {
3607 index = get_connection_index(codec, spec->mux_nids[j],
3608 nid);
3609 if (index >= 0)
3610 break;
3611 }
3612 if (index < 0)
3613 continue;
3614
3615 err = create_elem_capture_vol(codec, nid,
3616 auto_pin_cfg_labels[i],
3617 HDA_INPUT);
3618 if (err < 0)
3619 return err;
3620
3621 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
3622 imux->items[imux->num_items].index = index;
3623 imux->num_items++;
3624 }
3625 spec->num_analog_muxes = imux->num_items;
3626
3627 if (imux->num_items) {
3628
3629
3630
3631
3632
3633 for (i = 0; i < spec->num_muxes; i++) {
3634 snd_hda_codec_write_cache(codec, spec->mux_nids[i], 0,
3635 AC_VERB_SET_CONNECT_SEL,
3636 imux->items[0].index);
3637 }
3638 }
3639
3640 return 0;
3641}
3642
3643static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
3644{
3645 struct sigmatel_spec *spec = codec->spec;
3646 int i;
3647
3648 for (i = 0; i < spec->autocfg.line_outs; i++) {
3649 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3650 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
3651 }
3652}
3653
3654static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
3655{
3656 struct sigmatel_spec *spec = codec->spec;
3657 int i;
3658
3659 for (i = 0; i < spec->autocfg.hp_outs; i++) {
3660 hda_nid_t pin;
3661 pin = spec->autocfg.hp_pins[i];
3662 if (pin)
3663 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
3664 }
3665 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
3666 hda_nid_t pin;
3667 pin = spec->autocfg.speaker_pins[i];
3668 if (pin)
3669 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
3670 }
3671}
3672
3673static int is_dual_headphones(struct hda_codec *codec)
3674{
3675 struct sigmatel_spec *spec = codec->spec;
3676 int i, valid_hps;
3677
3678 if (spec->autocfg.line_out_type != AUTO_PIN_SPEAKER_OUT ||
3679 spec->autocfg.hp_outs <= 1)
3680 return 0;
3681 valid_hps = 0;
3682 for (i = 0; i < spec->autocfg.hp_outs; i++) {
3683 hda_nid_t nid = spec->autocfg.hp_pins[i];
3684 unsigned int cfg = snd_hda_codec_get_pincfg(codec, nid);
3685 if (get_defcfg_location(cfg) & AC_JACK_LOC_SEPARATE)
3686 continue;
3687 valid_hps++;
3688 }
3689 return (valid_hps > 1);
3690}
3691
3692
3693static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out, hda_nid_t dig_in)
3694{
3695 struct sigmatel_spec *spec = codec->spec;
3696 int hp_swap = 0;
3697 int i, err;
3698
3699 if ((err = snd_hda_parse_pin_def_config(codec,
3700 &spec->autocfg,
3701 spec->dmic_nids)) < 0)
3702 return err;
3703 if (! spec->autocfg.line_outs)
3704 return 0;
3705
3706
3707
3708
3709 if (is_dual_headphones(codec)) {
3710
3711
3712
3713
3714 snd_printdd("stac92xx: Enabling multi-HPs workaround\n");
3715 memcpy(spec->autocfg.speaker_pins, spec->autocfg.line_out_pins,
3716 sizeof(spec->autocfg.line_out_pins));
3717 spec->autocfg.speaker_outs = spec->autocfg.line_outs;
3718 memcpy(spec->autocfg.line_out_pins, spec->autocfg.hp_pins,
3719 sizeof(spec->autocfg.hp_pins));
3720 spec->autocfg.line_outs = spec->autocfg.hp_outs;
3721 spec->autocfg.line_out_type = AUTO_PIN_HP_OUT;
3722 spec->autocfg.hp_outs = 0;
3723 hp_swap = 1;
3724 }
3725 if (spec->autocfg.mono_out_pin) {
3726 int dir = get_wcaps(codec, spec->autocfg.mono_out_pin) &
3727 (AC_WCAP_OUT_AMP | AC_WCAP_IN_AMP);
3728 u32 caps = query_amp_caps(codec,
3729 spec->autocfg.mono_out_pin, dir);
3730 hda_nid_t conn_list[1];
3731
3732
3733 if (snd_hda_get_connections(codec,
3734 spec->autocfg.mono_out_pin, conn_list, 1) &&
3735 snd_hda_get_connections(codec, conn_list[0],
3736 conn_list, 1) > 0) {
3737
3738 int wcaps = get_wcaps(codec, conn_list[0]);
3739 int wid_type = get_wcaps_type(wcaps);
3740
3741
3742
3743
3744 if (wid_type == AC_WID_AUD_SEL &&
3745 !(wcaps & AC_WCAP_LR_SWAP))
3746 spec->mono_nid = conn_list[0];
3747 }
3748 if (dir) {
3749 hda_nid_t nid = spec->autocfg.mono_out_pin;
3750
3751
3752 dir = (dir & AC_WCAP_OUT_AMP) ? HDA_OUTPUT : HDA_INPUT;
3753 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE,
3754 "Mono Playback Switch",
3755 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
3756 if (err < 0)
3757 return err;
3758
3759 if ((caps & AC_AMPCAP_NUM_STEPS)
3760 >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3761 err = stac92xx_add_control(spec,
3762 STAC_CTL_WIDGET_VOL,
3763 "Mono Playback Volume",
3764 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
3765 if (err < 0)
3766 return err;
3767 }
3768 }
3769
3770 stac92xx_auto_set_pinctl(codec, spec->autocfg.mono_out_pin,
3771 AC_PINCTL_OUT_EN);
3772 }
3773
3774 if (!spec->multiout.num_dacs) {
3775 err = stac92xx_auto_fill_dac_nids(codec);
3776 if (err < 0)
3777 return err;
3778 err = stac92xx_auto_create_multi_out_ctls(codec,
3779 &spec->autocfg);
3780 if (err < 0)
3781 return err;
3782 }
3783
3784
3785 if (spec->anabeep_nid > 0) {
3786 err = stac92xx_auto_create_beep_ctls(codec,
3787 spec->anabeep_nid);
3788 if (err < 0)
3789 return err;
3790 }
3791
3792
3793#ifdef CONFIG_SND_HDA_INPUT_BEEP
3794 if (spec->digbeep_nid > 0) {
3795 hda_nid_t nid = spec->digbeep_nid;
3796 unsigned int caps;
3797
3798 err = stac92xx_auto_create_beep_ctls(codec, nid);
3799 if (err < 0)
3800 return err;
3801 err = snd_hda_attach_beep_device(codec, nid);
3802 if (err < 0)
3803 return err;
3804 if (codec->beep) {
3805
3806 codec->beep->linear_tone = spec->linear_tone_beep;
3807
3808 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3809 if (!(caps & AC_AMPCAP_MUTE)) {
3810 err = stac92xx_beep_switch_ctl(codec);
3811 if (err < 0)
3812 return err;
3813 }
3814 }
3815 }
3816#endif
3817
3818 err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg);
3819 if (err < 0)
3820 return err;
3821
3822
3823 if (hp_swap) {
3824 memcpy(spec->autocfg.hp_pins, spec->autocfg.line_out_pins,
3825 sizeof(spec->autocfg.hp_pins));
3826 spec->autocfg.hp_outs = spec->autocfg.line_outs;
3827 spec->autocfg.line_out_type = AUTO_PIN_HP_OUT;
3828 spec->autocfg.line_outs = 0;
3829 }
3830
3831 if (stac_check_auto_mic(codec)) {
3832 spec->auto_mic = 1;
3833
3834 spec->num_adcs = 1;
3835 spec->num_caps = 1;
3836 spec->num_muxes = 1;
3837 }
3838
3839 for (i = 0; i < spec->num_caps; i++) {
3840 err = stac92xx_add_capvol_ctls(codec, spec->capvols[i],
3841 spec->capsws[i], i);
3842 if (err < 0)
3843 return err;
3844 }
3845
3846 err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg);
3847 if (err < 0)
3848 return err;
3849
3850 if (spec->mono_nid > 0) {
3851 err = stac92xx_auto_create_mono_output_ctls(codec);
3852 if (err < 0)
3853 return err;
3854 }
3855 if (spec->num_dmics > 0 && !spec->dinput_mux)
3856 if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
3857 &spec->autocfg)) < 0)
3858 return err;
3859 if (spec->num_muxes > 0) {
3860 err = stac92xx_auto_create_mux_input_ctls(codec);
3861 if (err < 0)
3862 return err;
3863 }
3864 if (spec->num_smuxes > 0) {
3865 err = stac92xx_auto_create_spdif_mux_ctls(codec);
3866 if (err < 0)
3867 return err;
3868 }
3869
3870 err = stac92xx_add_input_source(spec);
3871 if (err < 0)
3872 return err;
3873
3874 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3875 if (spec->multiout.max_channels > 2)
3876 spec->surr_switch = 1;
3877
3878 if (spec->autocfg.dig_outs)
3879 spec->multiout.dig_out_nid = dig_out;
3880 if (dig_in && spec->autocfg.dig_in_pin)
3881 spec->dig_in_nid = dig_in;
3882
3883 if (spec->kctls.list)
3884 spec->mixers[spec->num_mixers++] = spec->kctls.list;
3885
3886 spec->input_mux = &spec->private_imux;
3887 if (!spec->dinput_mux)
3888 spec->dinput_mux = &spec->private_dimux;
3889 spec->sinput_mux = &spec->private_smux;
3890 spec->mono_mux = &spec->private_mono_mux;
3891 return 1;
3892}
3893
3894
3895static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
3896 struct auto_pin_cfg *cfg)
3897{
3898 struct sigmatel_spec *spec = codec->spec;
3899 hda_nid_t pin = cfg->hp_pins[0];
3900 unsigned int wid_caps;
3901
3902 if (! pin)
3903 return 0;
3904
3905 wid_caps = get_wcaps(codec, pin);
3906 if (wid_caps & AC_WCAP_UNSOL_CAP)
3907 spec->hp_detect = 1;
3908
3909 return 0;
3910}
3911
3912
3913static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
3914 struct auto_pin_cfg *cfg)
3915{
3916 struct sigmatel_spec *spec = codec->spec;
3917 int err;
3918 hda_nid_t lfe_pin = 0x0;
3919 int i;
3920
3921
3922
3923
3924
3925
3926 for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
3927 hda_nid_t pin = spec->autocfg.speaker_pins[i];
3928 unsigned int wcaps = get_wcaps(codec, pin);
3929 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
3930 if (wcaps == AC_WCAP_OUT_AMP)
3931
3932 lfe_pin = pin;
3933 }
3934
3935
3936 if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
3937 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
3938 hda_nid_t pin = spec->autocfg.line_out_pins[i];
3939 unsigned int defcfg;
3940 defcfg = snd_hda_codec_get_pincfg(codec, pin);
3941 if (get_defcfg_device(defcfg) == AC_JACK_SPEAKER) {
3942 unsigned int wcaps = get_wcaps(codec, pin);
3943 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
3944 if (wcaps == AC_WCAP_OUT_AMP)
3945
3946
3947 lfe_pin = pin;
3948 }
3949 }
3950 }
3951
3952 if (lfe_pin) {
3953 err = create_controls(codec, "LFE", lfe_pin, 1);
3954 if (err < 0)
3955 return err;
3956 }
3957
3958 return 0;
3959}
3960
3961static int stac9200_parse_auto_config(struct hda_codec *codec)
3962{
3963 struct sigmatel_spec *spec = codec->spec;
3964 int err;
3965
3966 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
3967 return err;
3968
3969 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
3970 return err;
3971
3972 if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
3973 return err;
3974
3975 if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
3976 return err;
3977
3978 if (spec->num_muxes > 0) {
3979 err = stac92xx_auto_create_mux_input_ctls(codec);
3980 if (err < 0)
3981 return err;
3982 }
3983
3984 err = stac92xx_add_input_source(spec);
3985 if (err < 0)
3986 return err;
3987
3988 if (spec->autocfg.dig_outs)
3989 spec->multiout.dig_out_nid = 0x05;
3990 if (spec->autocfg.dig_in_pin)
3991 spec->dig_in_nid = 0x04;
3992
3993 if (spec->kctls.list)
3994 spec->mixers[spec->num_mixers++] = spec->kctls.list;
3995
3996 spec->input_mux = &spec->private_imux;
3997 spec->dinput_mux = &spec->private_dimux;
3998
3999 return 1;
4000}
4001
4002
4003
4004
4005
4006
4007static void stac_gpio_set(struct hda_codec *codec, unsigned int mask,
4008 unsigned int dir_mask, unsigned int data)
4009{
4010 unsigned int gpiostate, gpiomask, gpiodir;
4011
4012 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
4013 AC_VERB_GET_GPIO_DATA, 0);
4014 gpiostate = (gpiostate & ~dir_mask) | (data & dir_mask);
4015
4016 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
4017 AC_VERB_GET_GPIO_MASK, 0);
4018 gpiomask |= mask;
4019
4020 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
4021 AC_VERB_GET_GPIO_DIRECTION, 0);
4022 gpiodir |= dir_mask;
4023
4024
4025 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
4026
4027 snd_hda_codec_write(codec, codec->afg, 0,
4028 AC_VERB_SET_GPIO_MASK, gpiomask);
4029 snd_hda_codec_read(codec, codec->afg, 0,
4030 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
4031
4032 msleep(1);
4033
4034 snd_hda_codec_read(codec, codec->afg, 0,
4035 AC_VERB_SET_GPIO_DATA, gpiostate);
4036}
4037
4038#ifdef CONFIG_SND_HDA_INPUT_JACK
4039static void stac92xx_free_jack_priv(struct snd_jack *jack)
4040{
4041 struct sigmatel_jack *jacks = jack->private_data;
4042 jacks->nid = 0;
4043 jacks->jack = NULL;
4044}
4045#endif
4046
4047static int stac92xx_add_jack(struct hda_codec *codec,
4048 hda_nid_t nid, int type)
4049{
4050#ifdef CONFIG_SND_HDA_INPUT_JACK
4051 struct sigmatel_spec *spec = codec->spec;
4052 struct sigmatel_jack *jack;
4053 int def_conf = snd_hda_codec_get_pincfg(codec, nid);
4054 int connectivity = get_defcfg_connect(def_conf);
4055 char name[32];
4056 int err;
4057
4058 if (connectivity && connectivity != AC_JACK_PORT_FIXED)
4059 return 0;
4060
4061 snd_array_init(&spec->jacks, sizeof(*jack), 32);
4062 jack = snd_array_new(&spec->jacks);
4063 if (!jack)
4064 return -ENOMEM;
4065 jack->nid = nid;
4066 jack->type = type;
4067
4068 snprintf(name, sizeof(name), "%s at %s %s Jack",
4069 snd_hda_get_jack_type(def_conf),
4070 snd_hda_get_jack_connectivity(def_conf),
4071 snd_hda_get_jack_location(def_conf));
4072
4073 err = snd_jack_new(codec->bus->card, name, type, &jack->jack);
4074 if (err < 0) {
4075 jack->nid = 0;
4076 return err;
4077 }
4078 jack->jack->private_data = jack;
4079 jack->jack->private_free = stac92xx_free_jack_priv;
4080#endif
4081 return 0;
4082}
4083
4084static int stac_add_event(struct sigmatel_spec *spec, hda_nid_t nid,
4085 unsigned char type, int data)
4086{
4087 struct sigmatel_event *event;
4088
4089 snd_array_init(&spec->events, sizeof(*event), 32);
4090 event = snd_array_new(&spec->events);
4091 if (!event)
4092 return -ENOMEM;
4093 event->nid = nid;
4094 event->type = type;
4095 event->tag = spec->events.used;
4096 event->data = data;
4097
4098 return event->tag;
4099}
4100
4101static struct sigmatel_event *stac_get_event(struct hda_codec *codec,
4102 hda_nid_t nid)
4103{
4104 struct sigmatel_spec *spec = codec->spec;
4105 struct sigmatel_event *event = spec->events.list;
4106 int i;
4107
4108 for (i = 0; i < spec->events.used; i++, event++) {
4109 if (event->nid == nid)
4110 return event;
4111 }
4112 return NULL;
4113}
4114
4115static struct sigmatel_event *stac_get_event_from_tag(struct hda_codec *codec,
4116 unsigned char tag)
4117{
4118 struct sigmatel_spec *spec = codec->spec;
4119 struct sigmatel_event *event = spec->events.list;
4120 int i;
4121
4122 for (i = 0; i < spec->events.used; i++, event++) {
4123 if (event->tag == tag)
4124 return event;
4125 }
4126 return NULL;
4127}
4128
4129
4130
4131
4132
4133static int enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
4134 unsigned int type)
4135{
4136 struct sigmatel_event *event;
4137 int tag;
4138
4139 if (!(get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP))
4140 return 0;
4141 event = stac_get_event(codec, nid);
4142 if (event) {
4143 if (event->type != type)
4144 return 0;
4145 tag = event->tag;
4146 } else {
4147 tag = stac_add_event(codec->spec, nid, type, 0);
4148 if (tag < 0)
4149 return 0;
4150 }
4151 snd_hda_codec_write_cache(codec, nid, 0,
4152 AC_VERB_SET_UNSOLICITED_ENABLE,
4153 AC_USRSP_EN | tag);
4154 return 1;
4155}
4156
4157static int is_nid_hp_pin(struct auto_pin_cfg *cfg, hda_nid_t nid)
4158{
4159 int i;
4160 for (i = 0; i < cfg->hp_outs; i++)
4161 if (cfg->hp_pins[i] == nid)
4162 return 1;
4163
4164 return 0;
4165};
4166
4167static void stac92xx_power_down(struct hda_codec *codec)
4168{
4169 struct sigmatel_spec *spec = codec->spec;
4170
4171
4172 hda_nid_t *dac;
4173 for (dac = spec->dac_list; *dac; dac++)
4174 if (!check_all_dac_nids(spec, *dac))
4175 snd_hda_codec_write(codec, *dac, 0,
4176 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
4177}
4178
4179static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
4180 int enable);
4181
4182static inline int get_int_hint(struct hda_codec *codec, const char *key,
4183 int *valp)
4184{
4185 const char *p;
4186 p = snd_hda_get_hint(codec, key);
4187 if (p) {
4188 unsigned long val;
4189 if (!strict_strtoul(p, 0, &val)) {
4190 *valp = val;
4191 return 1;
4192 }
4193 }
4194 return 0;
4195}
4196
4197
4198static void stac_store_hints(struct hda_codec *codec)
4199{
4200 struct sigmatel_spec *spec = codec->spec;
4201 int val;
4202
4203 val = snd_hda_get_bool_hint(codec, "hp_detect");
4204 if (val >= 0)
4205 spec->hp_detect = val;
4206 if (get_int_hint(codec, "gpio_mask", &spec->gpio_mask)) {
4207 spec->eapd_mask = spec->gpio_dir = spec->gpio_data =
4208 spec->gpio_mask;
4209 }
4210 if (get_int_hint(codec, "gpio_dir", &spec->gpio_dir))
4211 spec->gpio_mask &= spec->gpio_mask;
4212 if (get_int_hint(codec, "gpio_data", &spec->gpio_data))
4213 spec->gpio_dir &= spec->gpio_mask;
4214 if (get_int_hint(codec, "eapd_mask", &spec->eapd_mask))
4215 spec->eapd_mask &= spec->gpio_mask;
4216 if (get_int_hint(codec, "gpio_mute", &spec->gpio_mute))
4217 spec->gpio_mute &= spec->gpio_mask;
4218 val = snd_hda_get_bool_hint(codec, "eapd_switch");
4219 if (val >= 0)
4220 spec->eapd_switch = val;
4221 get_int_hint(codec, "gpio_led_polarity", &spec->gpio_led_polarity);
4222 if (get_int_hint(codec, "gpio_led", &spec->gpio_led)) {
4223 spec->gpio_mask |= spec->gpio_led;
4224 spec->gpio_dir |= spec->gpio_led;
4225 if (spec->gpio_led_polarity)
4226 spec->gpio_data |= spec->gpio_led;
4227 }
4228}
4229
4230static int stac92xx_init(struct hda_codec *codec)
4231{
4232 struct sigmatel_spec *spec = codec->spec;
4233 struct auto_pin_cfg *cfg = &spec->autocfg;
4234 unsigned int gpio;
4235 int i;
4236
4237 snd_hda_sequence_write(codec, spec->init);
4238
4239
4240 if (spec->powerdown_adcs)
4241 for (i = 0; i < spec->num_adcs; i++)
4242 snd_hda_codec_write(codec,
4243 spec->adc_nids[i], 0,
4244 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
4245
4246
4247 stac_store_hints(codec);
4248
4249
4250 gpio = spec->gpio_data;
4251
4252
4253
4254 if (!spec->eapd_switch)
4255 gpio |= spec->eapd_mask;
4256 stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, gpio);
4257
4258
4259 if (spec->hp_detect) {
4260
4261 for (i = 0; i < cfg->hp_outs; i++) {
4262 hda_nid_t nid = cfg->hp_pins[i];
4263 enable_pin_detect(codec, nid, STAC_HP_EVENT);
4264 }
4265 if (cfg->line_out_type == AUTO_PIN_LINE_OUT &&
4266 cfg->speaker_outs > 0) {
4267
4268 for (i = 0; i < cfg->line_outs; i++) {
4269 hda_nid_t nid = cfg->line_out_pins[i];
4270 enable_pin_detect(codec, nid, STAC_LO_EVENT);
4271 }
4272 }
4273
4274
4275
4276
4277 stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
4278 AC_PINCTL_OUT_EN);
4279
4280 if (cfg->hp_pins[0])
4281 stac_issue_unsol_event(codec, cfg->hp_pins[0]);
4282 else if (cfg->line_out_pins[0])
4283 stac_issue_unsol_event(codec, cfg->line_out_pins[0]);
4284 } else {
4285 stac92xx_auto_init_multi_out(codec);
4286 stac92xx_auto_init_hp_out(codec);
4287 for (i = 0; i < cfg->hp_outs; i++)
4288 stac_toggle_power_map(codec, cfg->hp_pins[i], 1);
4289 }
4290 if (spec->auto_mic) {
4291
4292 if (spec->dmux_nids)
4293 snd_hda_codec_write_cache(codec, spec->dmux_nids[0], 0,
4294 AC_VERB_SET_CONNECT_SEL, 0);
4295 if (enable_pin_detect(codec, spec->ext_mic.pin, STAC_MIC_EVENT))
4296 stac_issue_unsol_event(codec, spec->ext_mic.pin);
4297 }
4298 for (i = 0; i < AUTO_PIN_LAST; i++) {
4299 hda_nid_t nid = cfg->input_pins[i];
4300 if (nid) {
4301 unsigned int pinctl, conf;
4302 if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC) {
4303
4304 pinctl = stac92xx_get_default_vref(codec, nid);
4305 pinctl |= AC_PINCTL_IN_EN;
4306 stac92xx_auto_set_pinctl(codec, nid, pinctl);
4307 } else {
4308 pinctl = snd_hda_codec_read(codec, nid, 0,
4309 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4310
4311
4312
4313
4314 if (!(pinctl & AC_PINCTL_IN_EN) ||
4315 (pinctl & AC_PINCTL_OUT_EN)) {
4316 pinctl &= ~AC_PINCTL_OUT_EN;
4317 pinctl |= AC_PINCTL_IN_EN;
4318 stac92xx_auto_set_pinctl(codec, nid,
4319 pinctl);
4320 }
4321 }
4322 conf = snd_hda_codec_get_pincfg(codec, nid);
4323 if (get_defcfg_connect(conf) != AC_JACK_PORT_FIXED) {
4324 if (enable_pin_detect(codec, nid,
4325 STAC_INSERT_EVENT))
4326 stac_issue_unsol_event(codec, nid);
4327 }
4328 }
4329 }
4330 for (i = 0; i < spec->num_dmics; i++)
4331 stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
4332 AC_PINCTL_IN_EN);
4333 if (cfg->dig_out_pins[0])
4334 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pins[0],
4335 AC_PINCTL_OUT_EN);
4336 if (cfg->dig_in_pin)
4337 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
4338 AC_PINCTL_IN_EN);
4339 for (i = 0; i < spec->num_pwrs; i++) {
4340 hda_nid_t nid = spec->pwr_nids[i];
4341 int pinctl, def_conf;
4342
4343
4344 if (!spec->hp_detect) {
4345 stac_toggle_power_map(codec, nid, 1);
4346 continue;
4347 }
4348
4349 if (is_nid_hp_pin(cfg, nid))
4350 continue;
4351
4352 pinctl = snd_hda_codec_read(codec, nid, 0,
4353 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4354
4355
4356
4357
4358 if (pinctl & AC_PINCTL_IN_EN) {
4359 stac_toggle_power_map(codec, nid, 1);
4360 continue;
4361 }
4362 def_conf = snd_hda_codec_get_pincfg(codec, nid);
4363 def_conf = get_defcfg_connect(def_conf);
4364
4365
4366 if (def_conf != AC_JACK_PORT_COMPLEX) {
4367 if (def_conf != AC_JACK_PORT_NONE)
4368 stac_toggle_power_map(codec, nid, 1);
4369 continue;
4370 }
4371 if (enable_pin_detect(codec, nid, STAC_PWR_EVENT))
4372 stac_issue_unsol_event(codec, nid);
4373 }
4374
4375#ifdef CONFIG_SND_HDA_POWER_SAVE
4376
4377 if (spec->gpio_led && codec->patch_ops.check_power_status)
4378 codec->patch_ops.check_power_status(codec, 0x01);
4379#endif
4380 if (spec->dac_list)
4381 stac92xx_power_down(codec);
4382 return 0;
4383}
4384
4385static void stac92xx_free_jacks(struct hda_codec *codec)
4386{
4387#ifdef CONFIG_SND_HDA_INPUT_JACK
4388
4389 struct sigmatel_spec *spec = codec->spec;
4390 if (!codec->bus->shutdown && spec->jacks.list) {
4391 struct sigmatel_jack *jacks = spec->jacks.list;
4392 int i;
4393 for (i = 0; i < spec->jacks.used; i++, jacks++) {
4394 if (jacks->jack)
4395 snd_device_free(codec->bus->card, jacks->jack);
4396 }
4397 }
4398 snd_array_free(&spec->jacks);
4399#endif
4400}
4401
4402static void stac92xx_free_kctls(struct hda_codec *codec)
4403{
4404 struct sigmatel_spec *spec = codec->spec;
4405
4406 if (spec->kctls.list) {
4407 struct snd_kcontrol_new *kctl = spec->kctls.list;
4408 int i;
4409 for (i = 0; i < spec->kctls.used; i++)
4410 kfree(kctl[i].name);
4411 }
4412 snd_array_free(&spec->kctls);
4413}
4414
4415static void stac92xx_shutup(struct hda_codec *codec)
4416{
4417 struct sigmatel_spec *spec = codec->spec;
4418
4419 snd_hda_shutup_pins(codec);
4420
4421 if (spec->eapd_mask)
4422 stac_gpio_set(codec, spec->gpio_mask,
4423 spec->gpio_dir, spec->gpio_data &
4424 ~spec->eapd_mask);
4425}
4426
4427static void stac92xx_free(struct hda_codec *codec)
4428{
4429 struct sigmatel_spec *spec = codec->spec;
4430
4431 if (! spec)
4432 return;
4433
4434 stac92xx_shutup(codec);
4435 stac92xx_free_jacks(codec);
4436 snd_array_free(&spec->events);
4437
4438 kfree(spec);
4439 snd_hda_detach_beep_device(codec);
4440}
4441
4442static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
4443 unsigned int flag)
4444{
4445 unsigned int old_ctl, pin_ctl;
4446
4447 pin_ctl = snd_hda_codec_read(codec, nid,
4448 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
4449
4450 if (pin_ctl & AC_PINCTL_IN_EN) {
4451
4452
4453
4454
4455
4456 struct sigmatel_spec *spec = codec->spec;
4457 if (nid == spec->line_switch || nid == spec->mic_switch)
4458 return;
4459 }
4460
4461 old_ctl = pin_ctl;
4462
4463
4464 if (flag & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))
4465 pin_ctl &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
4466
4467 pin_ctl |= flag;
4468 if (old_ctl != pin_ctl)
4469 snd_hda_codec_write_cache(codec, nid, 0,
4470 AC_VERB_SET_PIN_WIDGET_CONTROL,
4471 pin_ctl);
4472}
4473
4474static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
4475 unsigned int flag)
4476{
4477 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
4478 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
4479 if (pin_ctl & flag)
4480 snd_hda_codec_write_cache(codec, nid, 0,
4481 AC_VERB_SET_PIN_WIDGET_CONTROL,
4482 pin_ctl & ~flag);
4483}
4484
4485static inline int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
4486{
4487 if (!nid)
4488 return 0;
4489 return snd_hda_jack_detect(codec, nid);
4490}
4491
4492static void stac92xx_line_out_detect(struct hda_codec *codec,
4493 int presence)
4494{
4495 struct sigmatel_spec *spec = codec->spec;
4496 struct auto_pin_cfg *cfg = &spec->autocfg;
4497 int i;
4498
4499 for (i = 0; i < cfg->line_outs; i++) {
4500 if (presence)
4501 break;
4502 presence = get_pin_presence(codec, cfg->line_out_pins[i]);
4503 if (presence) {
4504 unsigned int pinctl;
4505 pinctl = snd_hda_codec_read(codec,
4506 cfg->line_out_pins[i], 0,
4507 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4508 if (pinctl & AC_PINCTL_IN_EN)
4509 presence = 0;
4510 }
4511 }
4512
4513 if (presence) {
4514
4515 for (i = 0; i < cfg->speaker_outs; i++)
4516 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
4517 AC_PINCTL_OUT_EN);
4518 if (spec->eapd_mask && spec->eapd_switch)
4519 stac_gpio_set(codec, spec->gpio_mask,
4520 spec->gpio_dir, spec->gpio_data &
4521 ~spec->eapd_mask);
4522 } else {
4523
4524 for (i = 0; i < cfg->speaker_outs; i++)
4525 stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
4526 AC_PINCTL_OUT_EN);
4527 if (spec->eapd_mask && spec->eapd_switch)
4528 stac_gpio_set(codec, spec->gpio_mask,
4529 spec->gpio_dir, spec->gpio_data |
4530 spec->eapd_mask);
4531 }
4532}
4533
4534
4535
4536
4537static int no_hp_sensing(struct sigmatel_spec *spec, int i)
4538{
4539 struct auto_pin_cfg *cfg = &spec->autocfg;
4540
4541
4542 if (cfg->hp_pins[i] == spec->line_switch)
4543 return 1;
4544 if (cfg->hp_pins[i] == spec->mic_switch)
4545 return 1;
4546
4547 if (cfg->hp_pins[i] == spec->hp_switch)
4548 return 1;
4549 return 0;
4550}
4551
4552static void stac92xx_hp_detect(struct hda_codec *codec)
4553{
4554 struct sigmatel_spec *spec = codec->spec;
4555 struct auto_pin_cfg *cfg = &spec->autocfg;
4556 int i, presence;
4557
4558 presence = 0;
4559 if (spec->gpio_mute)
4560 presence = !(snd_hda_codec_read(codec, codec->afg, 0,
4561 AC_VERB_GET_GPIO_DATA, 0) & spec->gpio_mute);
4562
4563 for (i = 0; i < cfg->hp_outs; i++) {
4564 if (presence)
4565 break;
4566 if (no_hp_sensing(spec, i))
4567 continue;
4568 presence = get_pin_presence(codec, cfg->hp_pins[i]);
4569 if (presence) {
4570 unsigned int pinctl;
4571 pinctl = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
4572 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4573 if (pinctl & AC_PINCTL_IN_EN)
4574 presence = 0;
4575 }
4576 }
4577
4578 if (presence) {
4579
4580 if (spec->hp_switch)
4581 stac92xx_reset_pinctl(codec, spec->hp_switch,
4582 AC_PINCTL_OUT_EN);
4583 for (i = 0; i < cfg->line_outs; i++)
4584 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
4585 AC_PINCTL_OUT_EN);
4586 } else {
4587
4588 if (spec->hp_switch)
4589 stac92xx_set_pinctl(codec, spec->hp_switch,
4590 AC_PINCTL_OUT_EN);
4591 for (i = 0; i < cfg->line_outs; i++)
4592 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
4593 AC_PINCTL_OUT_EN);
4594 }
4595 stac92xx_line_out_detect(codec, presence);
4596
4597 for (i = 0; i < cfg->hp_outs; i++) {
4598 unsigned int val = AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN;
4599 if (no_hp_sensing(spec, i))
4600 continue;
4601 if (presence)
4602 stac92xx_set_pinctl(codec, cfg->hp_pins[i], val);
4603#if 0
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613 else
4614 stac92xx_reset_pinctl(codec, cfg->hp_pins[i], val);
4615#endif
4616 }
4617}
4618
4619static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
4620 int enable)
4621{
4622 struct sigmatel_spec *spec = codec->spec;
4623 unsigned int idx, val;
4624
4625 for (idx = 0; idx < spec->num_pwrs; idx++) {
4626 if (spec->pwr_nids[idx] == nid)
4627 break;
4628 }
4629 if (idx >= spec->num_pwrs)
4630 return;
4631
4632
4633 if (spec->pwr_mapping)
4634 idx = spec->pwr_mapping[idx];
4635 else
4636 idx = 1 << idx;
4637
4638 val = snd_hda_codec_read(codec, codec->afg, 0, 0x0fec, 0x0) & 0xff;
4639 if (enable)
4640 val &= ~idx;
4641 else
4642 val |= idx;
4643
4644
4645 snd_hda_codec_write(codec, codec->afg, 0, 0x7ec, val);
4646}
4647
4648static void stac92xx_pin_sense(struct hda_codec *codec, hda_nid_t nid)
4649{
4650 stac_toggle_power_map(codec, nid, get_pin_presence(codec, nid));
4651}
4652
4653static void stac92xx_report_jack(struct hda_codec *codec, hda_nid_t nid)
4654{
4655 struct sigmatel_spec *spec = codec->spec;
4656 struct sigmatel_jack *jacks = spec->jacks.list;
4657
4658 if (jacks) {
4659 int i;
4660 for (i = 0; i < spec->jacks.used; i++) {
4661 if (jacks->nid == nid) {
4662 unsigned int pin_ctl =
4663 snd_hda_codec_read(codec, nid,
4664 0, AC_VERB_GET_PIN_WIDGET_CONTROL,
4665 0x00);
4666 int type = jacks->type;
4667 if (type == (SND_JACK_LINEOUT
4668 | SND_JACK_HEADPHONE))
4669 type = (pin_ctl & AC_PINCTL_HP_EN)
4670 ? SND_JACK_HEADPHONE : SND_JACK_LINEOUT;
4671 snd_jack_report(jacks->jack,
4672 get_pin_presence(codec, nid)
4673 ? type : 0);
4674 }
4675 jacks++;
4676 }
4677 }
4678}
4679
4680static void stac92xx_mic_detect(struct hda_codec *codec)
4681{
4682 struct sigmatel_spec *spec = codec->spec;
4683 struct sigmatel_mic_route *mic;
4684
4685 if (get_pin_presence(codec, spec->ext_mic.pin))
4686 mic = &spec->ext_mic;
4687 else
4688 mic = &spec->int_mic;
4689 if (mic->dmux_idx >= 0)
4690 snd_hda_codec_write_cache(codec, spec->dmux_nids[0], 0,
4691 AC_VERB_SET_CONNECT_SEL,
4692 mic->dmux_idx);
4693 if (mic->mux_idx >= 0)
4694 snd_hda_codec_write_cache(codec, spec->mux_nids[0], 0,
4695 AC_VERB_SET_CONNECT_SEL,
4696 mic->mux_idx);
4697}
4698
4699static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid)
4700{
4701 struct sigmatel_event *event = stac_get_event(codec, nid);
4702 if (!event)
4703 return;
4704 codec->patch_ops.unsol_event(codec, (unsigned)event->tag << 26);
4705}
4706
4707static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
4708{
4709 struct sigmatel_spec *spec = codec->spec;
4710 struct sigmatel_event *event;
4711 int tag, data;
4712
4713 tag = (res >> 26) & 0x7f;
4714 event = stac_get_event_from_tag(codec, tag);
4715 if (!event)
4716 return;
4717
4718 switch (event->type) {
4719 case STAC_HP_EVENT:
4720 case STAC_LO_EVENT:
4721 stac92xx_hp_detect(codec);
4722 break;
4723 case STAC_MIC_EVENT:
4724 stac92xx_mic_detect(codec);
4725 break;
4726 }
4727
4728 switch (event->type) {
4729 case STAC_HP_EVENT:
4730 case STAC_LO_EVENT:
4731 case STAC_MIC_EVENT:
4732 case STAC_INSERT_EVENT:
4733 case STAC_PWR_EVENT:
4734 if (spec->num_pwrs > 0)
4735 stac92xx_pin_sense(codec, event->nid);
4736 stac92xx_report_jack(codec, event->nid);
4737
4738 switch (codec->subsystem_id) {
4739 case 0x103c308f:
4740 if (event->nid == 0xb) {
4741 int pin = AC_PINCTL_IN_EN;
4742
4743 if (get_pin_presence(codec, 0xa)
4744 && get_pin_presence(codec, 0xb))
4745 pin |= AC_PINCTL_VREF_80;
4746 if (!get_pin_presence(codec, 0xb))
4747 pin |= AC_PINCTL_VREF_80;
4748
4749
4750
4751
4752 stac92xx_auto_set_pinctl(codec, 0x0a, pin);
4753 }
4754 }
4755 break;
4756 case STAC_VREF_EVENT:
4757 data = snd_hda_codec_read(codec, codec->afg, 0,
4758 AC_VERB_GET_GPIO_DATA, 0);
4759
4760 snd_hda_codec_write(codec, codec->afg, 0, 0x7e0,
4761 !!(data & (1 << event->data)));
4762 break;
4763 }
4764}
4765
4766static int hp_blike_system(u32 subsystem_id);
4767
4768static void set_hp_led_gpio(struct hda_codec *codec)
4769{
4770 struct sigmatel_spec *spec = codec->spec;
4771 unsigned int gpio;
4772
4773 if (spec->gpio_led)
4774 return;
4775
4776 gpio = snd_hda_param_read(codec, codec->afg, AC_PAR_GPIO_CAP);
4777 gpio &= AC_GPIO_IO_COUNT;
4778 if (gpio > 3)
4779 spec->gpio_led = 0x08;
4780 else
4781 spec->gpio_led = 0x01;
4782}
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804static int find_mute_led_gpio(struct hda_codec *codec, int default_polarity)
4805{
4806 struct sigmatel_spec *spec = codec->spec;
4807 const struct dmi_device *dev = NULL;
4808
4809 if ((codec->subsystem_id >> 16) == PCI_VENDOR_ID_HP) {
4810 while ((dev = dmi_find_device(DMI_DEV_TYPE_OEM_STRING,
4811 NULL, dev))) {
4812 if (sscanf(dev->name, "HP_Mute_LED_%d_%d",
4813 &spec->gpio_led_polarity,
4814 &spec->gpio_led) == 2) {
4815 spec->gpio_led = 1 << spec->gpio_led;
4816 return 1;
4817 }
4818 if (sscanf(dev->name, "HP_Mute_LED_%d",
4819 &spec->gpio_led_polarity) == 1) {
4820 set_hp_led_gpio(codec);
4821 return 1;
4822 }
4823 }
4824
4825
4826
4827
4828
4829 if (!hp_blike_system(codec->subsystem_id)) {
4830 set_hp_led_gpio(codec);
4831 spec->gpio_led_polarity = default_polarity;
4832 return 1;
4833 }
4834 }
4835 return 0;
4836}
4837
4838static int hp_blike_system(u32 subsystem_id)
4839{
4840 switch (subsystem_id) {
4841 case 0x103c1520:
4842 case 0x103c1521:
4843 case 0x103c1523:
4844 case 0x103c1524:
4845 case 0x103c1525:
4846 case 0x103c1722:
4847 case 0x103c1723:
4848 case 0x103c1724:
4849 case 0x103c1725:
4850 case 0x103c1726:
4851 case 0x103c1727:
4852 case 0x103c1728:
4853 case 0x103c1729:
4854 case 0x103c172a:
4855 case 0x103c172b:
4856 case 0x103c307e:
4857 case 0x103c307f:
4858 case 0x103c3080:
4859 case 0x103c3081:
4860 case 0x103c7007:
4861 case 0x103c7008:
4862 return 1;
4863 }
4864 return 0;
4865}
4866
4867#ifdef CONFIG_PROC_FS
4868static void stac92hd_proc_hook(struct snd_info_buffer *buffer,
4869 struct hda_codec *codec, hda_nid_t nid)
4870{
4871 if (nid == codec->afg)
4872 snd_iprintf(buffer, "Power-Map: 0x%02x\n",
4873 snd_hda_codec_read(codec, nid, 0, 0x0fec, 0x0));
4874}
4875
4876static void analog_loop_proc_hook(struct snd_info_buffer *buffer,
4877 struct hda_codec *codec,
4878 unsigned int verb)
4879{
4880 snd_iprintf(buffer, "Analog Loopback: 0x%02x\n",
4881 snd_hda_codec_read(codec, codec->afg, 0, verb, 0));
4882}
4883
4884
4885static void stac92hd7x_proc_hook(struct snd_info_buffer *buffer,
4886 struct hda_codec *codec, hda_nid_t nid)
4887{
4888 stac92hd_proc_hook(buffer, codec, nid);
4889 if (nid == codec->afg)
4890 analog_loop_proc_hook(buffer, codec, 0xfa0);
4891}
4892
4893static void stac9205_proc_hook(struct snd_info_buffer *buffer,
4894 struct hda_codec *codec, hda_nid_t nid)
4895{
4896 if (nid == codec->afg)
4897 analog_loop_proc_hook(buffer, codec, 0xfe0);
4898}
4899
4900static void stac927x_proc_hook(struct snd_info_buffer *buffer,
4901 struct hda_codec *codec, hda_nid_t nid)
4902{
4903 if (nid == codec->afg)
4904 analog_loop_proc_hook(buffer, codec, 0xfeb);
4905}
4906#else
4907#define stac92hd_proc_hook NULL
4908#define stac92hd7x_proc_hook NULL
4909#define stac9205_proc_hook NULL
4910#define stac927x_proc_hook NULL
4911#endif
4912
4913#ifdef SND_HDA_NEEDS_RESUME
4914static int stac92xx_resume(struct hda_codec *codec)
4915{
4916 struct sigmatel_spec *spec = codec->spec;
4917
4918 stac92xx_init(codec);
4919 snd_hda_codec_resume_amp(codec);
4920 snd_hda_codec_resume_cache(codec);
4921
4922 if (spec->hp_detect) {
4923 if (spec->autocfg.hp_pins[0])
4924 stac_issue_unsol_event(codec, spec->autocfg.hp_pins[0]);
4925 else if (spec->autocfg.line_out_pins[0])
4926 stac_issue_unsol_event(codec,
4927 spec->autocfg.line_out_pins[0]);
4928 }
4929#ifdef CONFIG_SND_HDA_POWER_SAVE
4930
4931 if (spec->gpio_led && codec->patch_ops.check_power_status)
4932 codec->patch_ops.check_power_status(codec, 0x01);
4933#endif
4934 return 0;
4935}
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948#ifdef CONFIG_SND_HDA_POWER_SAVE
4949static int stac92xx_hp_check_power_status(struct hda_codec *codec,
4950 hda_nid_t nid)
4951{
4952 struct sigmatel_spec *spec = codec->spec;
4953 int i, muted = 1;
4954
4955 for (i = 0; i < spec->multiout.num_dacs; i++) {
4956 nid = spec->multiout.dac_nids[i];
4957 if (!(snd_hda_codec_amp_read(codec, nid, 0, HDA_OUTPUT, 0) &
4958 HDA_AMP_MUTE)) {
4959 muted = 0;
4960 break;
4961 }
4962 }
4963 if (muted)
4964 spec->gpio_data &= ~spec->gpio_led;
4965 else
4966 spec->gpio_data |= spec->gpio_led;
4967
4968 if (!spec->gpio_led_polarity) {
4969
4970 spec->gpio_data ^= spec->gpio_led;
4971 }
4972
4973 stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, spec->gpio_data);
4974 return 0;
4975}
4976#endif
4977
4978static int stac92xx_suspend(struct hda_codec *codec, pm_message_t state)
4979{
4980 stac92xx_shutup(codec);
4981 return 0;
4982}
4983#endif
4984
4985static struct hda_codec_ops stac92xx_patch_ops = {
4986 .build_controls = stac92xx_build_controls,
4987 .build_pcms = stac92xx_build_pcms,
4988 .init = stac92xx_init,
4989 .free = stac92xx_free,
4990 .unsol_event = stac92xx_unsol_event,
4991#ifdef SND_HDA_NEEDS_RESUME
4992 .suspend = stac92xx_suspend,
4993 .resume = stac92xx_resume,
4994#endif
4995 .reboot_notify = stac92xx_shutup,
4996};
4997
4998static int patch_stac9200(struct hda_codec *codec)
4999{
5000 struct sigmatel_spec *spec;
5001 int err;
5002
5003 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5004 if (spec == NULL)
5005 return -ENOMEM;
5006
5007 codec->no_trigger_sense = 1;
5008 codec->spec = spec;
5009 spec->linear_tone_beep = 1;
5010 spec->num_pins = ARRAY_SIZE(stac9200_pin_nids);
5011 spec->pin_nids = stac9200_pin_nids;
5012 spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS,
5013 stac9200_models,
5014 stac9200_cfg_tbl);
5015 if (spec->board_config < 0)
5016 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5017 codec->chip_name);
5018 else
5019 stac92xx_set_config_regs(codec,
5020 stac9200_brd_tbl[spec->board_config]);
5021
5022 spec->multiout.max_channels = 2;
5023 spec->multiout.num_dacs = 1;
5024 spec->multiout.dac_nids = stac9200_dac_nids;
5025 spec->adc_nids = stac9200_adc_nids;
5026 spec->mux_nids = stac9200_mux_nids;
5027 spec->num_muxes = 1;
5028 spec->num_dmics = 0;
5029 spec->num_adcs = 1;
5030 spec->num_pwrs = 0;
5031
5032 if (spec->board_config == STAC_9200_M4 ||
5033 spec->board_config == STAC_9200_M4_2 ||
5034 spec->board_config == STAC_9200_OQO)
5035 spec->init = stac9200_eapd_init;
5036 else
5037 spec->init = stac9200_core_init;
5038 spec->mixer = stac9200_mixer;
5039
5040 if (spec->board_config == STAC_9200_PANASONIC) {
5041 spec->gpio_mask = spec->gpio_dir = 0x09;
5042 spec->gpio_data = 0x00;
5043 }
5044
5045 err = stac9200_parse_auto_config(codec);
5046 if (err < 0) {
5047 stac92xx_free(codec);
5048 return err;
5049 }
5050
5051
5052
5053
5054 if (spec->board_config == STAC_9200_PANASONIC)
5055 spec->hp_detect = 0;
5056
5057 codec->patch_ops = stac92xx_patch_ops;
5058
5059 return 0;
5060}
5061
5062static int patch_stac925x(struct hda_codec *codec)
5063{
5064 struct sigmatel_spec *spec;
5065 int err;
5066
5067 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5068 if (spec == NULL)
5069 return -ENOMEM;
5070
5071 codec->no_trigger_sense = 1;
5072 codec->spec = spec;
5073 spec->linear_tone_beep = 1;
5074 spec->num_pins = ARRAY_SIZE(stac925x_pin_nids);
5075 spec->pin_nids = stac925x_pin_nids;
5076
5077
5078 spec->board_config = snd_hda_check_board_codec_sid_config(codec,
5079 STAC_925x_MODELS,
5080 stac925x_models,
5081 stac925x_codec_id_cfg_tbl);
5082
5083
5084 if (spec->board_config < 0)
5085 spec->board_config = snd_hda_check_board_config(codec,
5086 STAC_925x_MODELS,
5087 stac925x_models,
5088 stac925x_cfg_tbl);
5089 again:
5090 if (spec->board_config < 0)
5091 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5092 codec->chip_name);
5093 else
5094 stac92xx_set_config_regs(codec,
5095 stac925x_brd_tbl[spec->board_config]);
5096
5097 spec->multiout.max_channels = 2;
5098 spec->multiout.num_dacs = 1;
5099 spec->multiout.dac_nids = stac925x_dac_nids;
5100 spec->adc_nids = stac925x_adc_nids;
5101 spec->mux_nids = stac925x_mux_nids;
5102 spec->num_muxes = 1;
5103 spec->num_adcs = 1;
5104 spec->num_pwrs = 0;
5105 switch (codec->vendor_id) {
5106 case 0x83847632:
5107 case 0x83847633:
5108 case 0x83847636:
5109 case 0x83847637:
5110 spec->num_dmics = STAC925X_NUM_DMICS;
5111 spec->dmic_nids = stac925x_dmic_nids;
5112 spec->num_dmuxes = ARRAY_SIZE(stac925x_dmux_nids);
5113 spec->dmux_nids = stac925x_dmux_nids;
5114 break;
5115 default:
5116 spec->num_dmics = 0;
5117 break;
5118 }
5119
5120 spec->init = stac925x_core_init;
5121 spec->mixer = stac925x_mixer;
5122 spec->num_caps = 1;
5123 spec->capvols = stac925x_capvols;
5124 spec->capsws = stac925x_capsws;
5125
5126 err = stac92xx_parse_auto_config(codec, 0x8, 0x7);
5127 if (!