]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - sound/pci/hda/patch_sigmatel.c
[ALSA] hda-codec - Add support of newer version of Intel iMac
[mirror_ubuntu-artful-kernel.git] / sound / pci / hda / patch_sigmatel.c
1 /*
2 * Universal Interface for Intel High Definition Audio Codec
3 *
4 * HD audio interface patch for SigmaTel STAC92xx
5 *
6 * Copyright (c) 2005 Embedded Alley Solutions, Inc.
7 * Matt Porter <mporter@embeddedalley.com>
8 *
9 * Based on patch_cmedia.c and patch_realtek.c
10 * Copyright (c) 2004 Takashi Iwai <tiwai@suse.de>
11 *
12 * This driver is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This driver is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 */
26
27 #include <sound/driver.h>
28 #include <linux/init.h>
29 #include <linux/delay.h>
30 #include <linux/slab.h>
31 #include <linux/pci.h>
32 #include <sound/core.h>
33 #include <sound/asoundef.h>
34 #include "hda_codec.h"
35 #include "hda_local.h"
36
37 #define NUM_CONTROL_ALLOC 32
38 #define STAC_HP_EVENT 0x37
39
40 enum {
41 STAC_REF,
42 STAC_9200_MODELS
43 };
44
45 enum {
46 STAC_9205_REF,
47 STAC_9205_MODELS
48 };
49
50 enum {
51 STAC_925x_REF,
52 STAC_M2_2,
53 STAC_MA6,
54 STAC_PA6,
55 STAC_925x_MODELS
56 };
57
58 enum {
59 STAC_D945_REF,
60 STAC_D945GTP3,
61 STAC_D945GTP5,
62 STAC_MACMINI,
63 STAC_MACBOOK,
64 STAC_MACBOOK_PRO_V1,
65 STAC_MACBOOK_PRO_V2,
66 STAC_IMAC_INTEL,
67 STAC_IMAC_INTEL_20,
68 STAC_922X_MODELS
69 };
70
71 enum {
72 STAC_D965_REF,
73 STAC_D965_3ST,
74 STAC_D965_5ST,
75 STAC_927X_MODELS
76 };
77
78 struct sigmatel_spec {
79 struct snd_kcontrol_new *mixers[4];
80 unsigned int num_mixers;
81
82 int board_config;
83 unsigned int surr_switch: 1;
84 unsigned int line_switch: 1;
85 unsigned int mic_switch: 1;
86 unsigned int alt_switch: 1;
87 unsigned int hp_detect: 1;
88 unsigned int gpio_mute: 1;
89
90 /* playback */
91 struct hda_multi_out multiout;
92 hda_nid_t dac_nids[5];
93
94 /* capture */
95 hda_nid_t *adc_nids;
96 unsigned int num_adcs;
97 hda_nid_t *mux_nids;
98 unsigned int num_muxes;
99 hda_nid_t *dmic_nids;
100 unsigned int num_dmics;
101 hda_nid_t dmux_nid;
102 hda_nid_t dig_in_nid;
103
104 /* pin widgets */
105 hda_nid_t *pin_nids;
106 unsigned int num_pins;
107 unsigned int *pin_configs;
108 unsigned int *bios_pin_configs;
109
110 /* codec specific stuff */
111 struct hda_verb *init;
112 struct snd_kcontrol_new *mixer;
113
114 /* capture source */
115 struct hda_input_mux *dinput_mux;
116 unsigned int cur_dmux;
117 struct hda_input_mux *input_mux;
118 unsigned int cur_mux[3];
119
120 /* i/o switches */
121 unsigned int io_switch[2];
122
123 struct hda_pcm pcm_rec[2]; /* PCM information */
124
125 /* dynamic controls and input_mux */
126 struct auto_pin_cfg autocfg;
127 unsigned int num_kctl_alloc, num_kctl_used;
128 struct snd_kcontrol_new *kctl_alloc;
129 struct hda_input_mux private_dimux;
130 struct hda_input_mux private_imux;
131 };
132
133 static hda_nid_t stac9200_adc_nids[1] = {
134 0x03,
135 };
136
137 static hda_nid_t stac9200_mux_nids[1] = {
138 0x0c,
139 };
140
141 static hda_nid_t stac9200_dac_nids[1] = {
142 0x02,
143 };
144
145 static hda_nid_t stac925x_adc_nids[1] = {
146 0x03,
147 };
148
149 static hda_nid_t stac925x_mux_nids[1] = {
150 0x0f,
151 };
152
153 static hda_nid_t stac925x_dac_nids[1] = {
154 0x02,
155 };
156
157 static hda_nid_t stac925x_dmic_nids[1] = {
158 0x15,
159 };
160
161 static hda_nid_t stac922x_adc_nids[2] = {
162 0x06, 0x07,
163 };
164
165 static hda_nid_t stac922x_mux_nids[2] = {
166 0x12, 0x13,
167 };
168
169 static hda_nid_t stac927x_adc_nids[3] = {
170 0x07, 0x08, 0x09
171 };
172
173 static hda_nid_t stac927x_mux_nids[3] = {
174 0x15, 0x16, 0x17
175 };
176
177 static hda_nid_t stac9205_adc_nids[2] = {
178 0x12, 0x13
179 };
180
181 static hda_nid_t stac9205_mux_nids[2] = {
182 0x19, 0x1a
183 };
184
185 static hda_nid_t stac9205_dmic_nids[2] = {
186 0x17, 0x18,
187 };
188
189 static hda_nid_t stac9200_pin_nids[8] = {
190 0x08, 0x09, 0x0d, 0x0e,
191 0x0f, 0x10, 0x11, 0x12,
192 };
193
194 static hda_nid_t stac925x_pin_nids[8] = {
195 0x07, 0x08, 0x0a, 0x0b,
196 0x0c, 0x0d, 0x10, 0x11,
197 };
198
199 static hda_nid_t stac922x_pin_nids[10] = {
200 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
201 0x0f, 0x10, 0x11, 0x15, 0x1b,
202 };
203
204 static hda_nid_t stac927x_pin_nids[14] = {
205 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
206 0x0f, 0x10, 0x11, 0x12, 0x13,
207 0x14, 0x21, 0x22, 0x23,
208 };
209
210 static hda_nid_t stac9205_pin_nids[12] = {
211 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
212 0x0f, 0x14, 0x16, 0x17, 0x18,
213 0x21, 0x22,
214
215 };
216
217 static int stac92xx_dmux_enum_info(struct snd_kcontrol *kcontrol,
218 struct snd_ctl_elem_info *uinfo)
219 {
220 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
221 struct sigmatel_spec *spec = codec->spec;
222 return snd_hda_input_mux_info(spec->dinput_mux, uinfo);
223 }
224
225 static int stac92xx_dmux_enum_get(struct snd_kcontrol *kcontrol,
226 struct snd_ctl_elem_value *ucontrol)
227 {
228 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
229 struct sigmatel_spec *spec = codec->spec;
230
231 ucontrol->value.enumerated.item[0] = spec->cur_dmux;
232 return 0;
233 }
234
235 static int stac92xx_dmux_enum_put(struct snd_kcontrol *kcontrol,
236 struct snd_ctl_elem_value *ucontrol)
237 {
238 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
239 struct sigmatel_spec *spec = codec->spec;
240
241 return snd_hda_input_mux_put(codec, spec->dinput_mux, ucontrol,
242 spec->dmux_nid, &spec->cur_dmux);
243 }
244
245 static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
246 {
247 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
248 struct sigmatel_spec *spec = codec->spec;
249 return snd_hda_input_mux_info(spec->input_mux, uinfo);
250 }
251
252 static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
253 {
254 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
255 struct sigmatel_spec *spec = codec->spec;
256 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
257
258 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
259 return 0;
260 }
261
262 static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
263 {
264 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
265 struct sigmatel_spec *spec = codec->spec;
266 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
267
268 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
269 spec->mux_nids[adc_idx], &spec->cur_mux[adc_idx]);
270 }
271
272 static struct hda_verb stac9200_core_init[] = {
273 /* set dac0mux for dac converter */
274 { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
275 {}
276 };
277
278 static struct hda_verb stac925x_core_init[] = {
279 /* set dac0mux for dac converter */
280 { 0x06, AC_VERB_SET_CONNECT_SEL, 0x00},
281 {}
282 };
283
284 static struct hda_verb stac922x_core_init[] = {
285 /* set master volume and direct control */
286 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
287 {}
288 };
289
290 static struct hda_verb d965_core_init[] = {
291 /* set master volume and direct control */
292 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
293 /* unmute node 0x1b */
294 { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
295 /* select node 0x03 as DAC */
296 { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
297 {}
298 };
299
300 static struct hda_verb stac927x_core_init[] = {
301 /* set master volume and direct control */
302 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
303 {}
304 };
305
306 static struct hda_verb stac9205_core_init[] = {
307 /* set master volume and direct control */
308 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
309 {}
310 };
311
312 static struct snd_kcontrol_new stac9200_mixer[] = {
313 HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
314 HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
315 {
316 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
317 .name = "Input Source",
318 .count = 1,
319 .info = stac92xx_mux_enum_info,
320 .get = stac92xx_mux_enum_get,
321 .put = stac92xx_mux_enum_put,
322 },
323 HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
324 HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
325 HDA_CODEC_VOLUME("Capture Mux Volume", 0x0c, 0, HDA_OUTPUT),
326 { } /* end */
327 };
328
329 static struct snd_kcontrol_new stac925x_mixer[] = {
330 HDA_CODEC_VOLUME("Master Playback Volume", 0xe, 0, HDA_OUTPUT),
331 HDA_CODEC_MUTE("Master Playback Switch", 0xe, 0, HDA_OUTPUT),
332 {
333 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
334 .name = "Input Source",
335 .count = 1,
336 .info = stac92xx_mux_enum_info,
337 .get = stac92xx_mux_enum_get,
338 .put = stac92xx_mux_enum_put,
339 },
340 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_OUTPUT),
341 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_OUTPUT),
342 HDA_CODEC_VOLUME("Capture Mux Volume", 0x0f, 0, HDA_OUTPUT),
343 { } /* end */
344 };
345
346 /* This needs to be generated dynamically based on sequence */
347 static struct snd_kcontrol_new stac922x_mixer[] = {
348 {
349 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
350 .name = "Input Source",
351 .count = 1,
352 .info = stac92xx_mux_enum_info,
353 .get = stac92xx_mux_enum_get,
354 .put = stac92xx_mux_enum_put,
355 },
356 HDA_CODEC_VOLUME("Capture Volume", 0x17, 0x0, HDA_INPUT),
357 HDA_CODEC_MUTE("Capture Switch", 0x17, 0x0, HDA_INPUT),
358 HDA_CODEC_VOLUME("Mux Capture Volume", 0x12, 0x0, HDA_OUTPUT),
359 { } /* end */
360 };
361
362 /* This needs to be generated dynamically based on sequence */
363 static struct snd_kcontrol_new stac9227_mixer[] = {
364 {
365 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
366 .name = "Input Source",
367 .count = 1,
368 .info = stac92xx_mux_enum_info,
369 .get = stac92xx_mux_enum_get,
370 .put = stac92xx_mux_enum_put,
371 },
372 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
373 HDA_CODEC_MUTE("Capture Switch", 0x1b, 0x0, HDA_OUTPUT),
374 { } /* end */
375 };
376
377 static struct snd_kcontrol_new stac927x_mixer[] = {
378 {
379 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
380 .name = "Input Source",
381 .count = 1,
382 .info = stac92xx_mux_enum_info,
383 .get = stac92xx_mux_enum_get,
384 .put = stac92xx_mux_enum_put,
385 },
386 HDA_CODEC_VOLUME("InMux Capture Volume", 0x15, 0x0, HDA_OUTPUT),
387 HDA_CODEC_VOLUME("InVol Capture Volume", 0x18, 0x0, HDA_INPUT),
388 HDA_CODEC_MUTE("ADCMux Capture Switch", 0x1b, 0x0, HDA_OUTPUT),
389 { } /* end */
390 };
391
392 static struct snd_kcontrol_new stac9205_mixer[] = {
393 {
394 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
395 .name = "Digital Input Source",
396 .count = 1,
397 .info = stac92xx_dmux_enum_info,
398 .get = stac92xx_dmux_enum_get,
399 .put = stac92xx_dmux_enum_put,
400 },
401 {
402 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
403 .name = "Input Source",
404 .count = 1,
405 .info = stac92xx_mux_enum_info,
406 .get = stac92xx_mux_enum_get,
407 .put = stac92xx_mux_enum_put,
408 },
409 HDA_CODEC_VOLUME("InMux Capture Volume", 0x19, 0x0, HDA_OUTPUT),
410 HDA_CODEC_VOLUME("InVol Capture Volume", 0x1b, 0x0, HDA_INPUT),
411 HDA_CODEC_MUTE("ADCMux Capture Switch", 0x1d, 0x0, HDA_OUTPUT),
412 { } /* end */
413 };
414
415 static int stac92xx_build_controls(struct hda_codec *codec)
416 {
417 struct sigmatel_spec *spec = codec->spec;
418 int err;
419 int i;
420
421 err = snd_hda_add_new_ctls(codec, spec->mixer);
422 if (err < 0)
423 return err;
424
425 for (i = 0; i < spec->num_mixers; i++) {
426 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
427 if (err < 0)
428 return err;
429 }
430
431 if (spec->multiout.dig_out_nid) {
432 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
433 if (err < 0)
434 return err;
435 }
436 if (spec->dig_in_nid) {
437 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
438 if (err < 0)
439 return err;
440 }
441 return 0;
442 }
443
444 static unsigned int ref9200_pin_configs[8] = {
445 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
446 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
447 };
448
449 static unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
450 [STAC_REF] = ref9200_pin_configs,
451 };
452
453 static const char *stac9200_models[STAC_9200_MODELS] = {
454 [STAC_REF] = "ref",
455 };
456
457 static struct snd_pci_quirk stac9200_cfg_tbl[] = {
458 /* SigmaTel reference board */
459 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
460 "DFI LanParty", STAC_REF),
461 /* Dell laptops have BIOS problem */
462 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01b5,
463 "Dell Inspiron 630m", STAC_REF),
464 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c2,
465 "Dell Latitude D620", STAC_REF),
466 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cb,
467 "Dell Latitude 120L", STAC_REF),
468 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cc,
469 "Dell Latitude D820", STAC_REF),
470 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cd,
471 "Dell Inspiron E1705/9400", STAC_REF),
472 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ce,
473 "Dell XPS M1710", STAC_REF),
474 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cf,
475 "Dell Precision M90", STAC_REF),
476 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d6,
477 "unknown Dell", STAC_REF),
478 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d8,
479 "Dell Inspiron 640m", STAC_REF),
480 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f5,
481 "Dell Inspiron 1501", STAC_REF),
482
483 /* Panasonic */
484 SND_PCI_QUIRK(0x10f7, 0x8338, "Panasonic CF-74", STAC_REF),
485
486 {} /* terminator */
487 };
488
489 static unsigned int ref925x_pin_configs[8] = {
490 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
491 0x90a70320, 0x02214210, 0x400003f1, 0x9033032e,
492 };
493
494 static unsigned int stac925x_MA6_pin_configs[8] = {
495 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
496 0x90a70320, 0x90100211, 0x400003f1, 0x9033032e,
497 };
498
499 static unsigned int stac925x_PA6_pin_configs[8] = {
500 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
501 0x50a103f0, 0x90100211, 0x400003f1, 0x9033032e,
502 };
503
504 static unsigned int stac925xM2_2_pin_configs[8] = {
505 0x40c003f3, 0x424503f2, 0x04180011, 0x02a19020,
506 0x50a103f0, 0x90100212, 0x400003f1, 0x9033032e,
507 };
508
509 static unsigned int *stac925x_brd_tbl[STAC_925x_MODELS] = {
510 [STAC_REF] = ref925x_pin_configs,
511 [STAC_M2_2] = stac925xM2_2_pin_configs,
512 [STAC_MA6] = stac925x_MA6_pin_configs,
513 [STAC_PA6] = stac925x_PA6_pin_configs,
514 };
515
516 static const char *stac925x_models[STAC_925x_MODELS] = {
517 [STAC_REF] = "ref",
518 [STAC_M2_2] = "m2-2",
519 [STAC_MA6] = "m6",
520 [STAC_PA6] = "pa6",
521 };
522
523 static struct snd_pci_quirk stac925x_cfg_tbl[] = {
524 /* SigmaTel reference board */
525 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, "DFI LanParty", STAC_REF),
526 SND_PCI_QUIRK(0x8384, 0x7632, "Stac9202 Reference Board", STAC_REF),
527 SND_PCI_QUIRK(0x107b, 0x0316, "Gateway M255", STAC_REF),
528 SND_PCI_QUIRK(0x107b, 0x0366, "Gateway MP6954", STAC_REF),
529 SND_PCI_QUIRK(0x107b, 0x0461, "Gateway NX560XL", STAC_MA6),
530 SND_PCI_QUIRK(0x107b, 0x0681, "Gateway NX860", STAC_PA6),
531 SND_PCI_QUIRK(0x1002, 0x437b, "Gateway MX6453", STAC_M2_2),
532 {} /* terminator */
533 };
534
535 static unsigned int ref922x_pin_configs[10] = {
536 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
537 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
538 0x40000100, 0x40000100,
539 };
540
541 static unsigned int d945gtp3_pin_configs[10] = {
542 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
543 0x40000100, 0x40000100, 0x40000100, 0x40000100,
544 0x02a19120, 0x40000100,
545 };
546
547 static unsigned int d945gtp5_pin_configs[10] = {
548 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
549 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
550 0x02a19320, 0x40000100,
551 };
552
553 static unsigned int macbook_pro_v1_pin_configs[10] = {
554 0x0321e230, 0x03a1e020, 0x9017e110, 0x01014010,
555 0x01a19021, 0x0381e021, 0x1345e240, 0x13c5e22e,
556 0x02a19320, 0x400000fb
557 };
558
559 static unsigned int macbook_pro_v2_pin_configs[10] = {
560 0x0221401f, 0x90a70120, 0x01813024, 0x01014010,
561 0x400000fd, 0x01016011, 0x1345e240, 0x13c5e22e,
562 0x400000fc, 0x400000fb,
563 };
564
565 static unsigned int imac_intel_pin_configs[10] = {
566 0x0121e230, 0x90a70120, 0x9017e110, 0x400000fe,
567 0x400000fd, 0x0181e021, 0x1145e040, 0x400000fa,
568 0x400000fc, 0x400000fb,
569 };
570
571 static unsigned int imac_intel_20_pin_configs[10] = {
572 0x0121E21F, 0x90A7012E, 0x9017E110, 0x400000FD,
573 0x400000FE, 0x0181E020, 0x1145E230, 0x11C5E240,
574 0x400000FC, 0x400000FB,
575 };
576
577 static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
578 [STAC_D945_REF] = ref922x_pin_configs,
579 [STAC_D945GTP3] = d945gtp3_pin_configs,
580 [STAC_D945GTP5] = d945gtp5_pin_configs,
581 [STAC_MACMINI] = macbook_pro_v1_pin_configs,
582 [STAC_MACBOOK] = macbook_pro_v1_pin_configs,
583 [STAC_MACBOOK_PRO_V1] = macbook_pro_v1_pin_configs,
584 [STAC_MACBOOK_PRO_V2] = macbook_pro_v2_pin_configs,
585 [STAC_IMAC_INTEL] = imac_intel_pin_configs,
586 [STAC_IMAC_INTEL_20] = imac_intel_20_pin_configs,
587 };
588
589 static const char *stac922x_models[STAC_922X_MODELS] = {
590 [STAC_D945_REF] = "ref",
591 [STAC_D945GTP5] = "5stack",
592 [STAC_D945GTP3] = "3stack",
593 [STAC_MACMINI] = "macmini",
594 [STAC_MACBOOK] = "macbook",
595 [STAC_MACBOOK_PRO_V1] = "macbook-pro-v1",
596 [STAC_MACBOOK_PRO_V2] = "macbook-pro",
597 [STAC_IMAC_INTEL] = "imac-intel",
598 [STAC_IMAC_INTEL_20] = "imac-intel-20",
599 };
600
601 static struct snd_pci_quirk stac922x_cfg_tbl[] = {
602 /* SigmaTel reference board */
603 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
604 "DFI LanParty", STAC_D945_REF),
605 /* Intel 945G based systems */
606 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101,
607 "Intel D945G", STAC_D945GTP3),
608 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0202,
609 "Intel D945G", STAC_D945GTP3),
610 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0606,
611 "Intel D945G", STAC_D945GTP3),
612 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0601,
613 "Intel D945G", STAC_D945GTP3),
614 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0111,
615 "Intel D945G", STAC_D945GTP3),
616 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1115,
617 "Intel D945G", STAC_D945GTP3),
618 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1116,
619 "Intel D945G", STAC_D945GTP3),
620 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1117,
621 "Intel D945G", STAC_D945GTP3),
622 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1118,
623 "Intel D945G", STAC_D945GTP3),
624 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1119,
625 "Intel D945G", STAC_D945GTP3),
626 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x8826,
627 "Intel D945G", STAC_D945GTP3),
628 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5049,
629 "Intel D945G", STAC_D945GTP3),
630 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5055,
631 "Intel D945G", STAC_D945GTP3),
632 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5048,
633 "Intel D945G", STAC_D945GTP3),
634 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0110,
635 "Intel D945G", STAC_D945GTP3),
636 /* Intel D945G 5-stack systems */
637 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0404,
638 "Intel D945G", STAC_D945GTP5),
639 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0303,
640 "Intel D945G", STAC_D945GTP5),
641 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0013,
642 "Intel D945G", STAC_D945GTP5),
643 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0417,
644 "Intel D945G", STAC_D945GTP5),
645 /* Intel 945P based systems */
646 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0b0b,
647 "Intel D945P", STAC_D945GTP3),
648 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0112,
649 "Intel D945P", STAC_D945GTP3),
650 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0d0d,
651 "Intel D945P", STAC_D945GTP3),
652 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0909,
653 "Intel D945P", STAC_D945GTP3),
654 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0505,
655 "Intel D945P", STAC_D945GTP3),
656 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707,
657 "Intel D945P", STAC_D945GTP5),
658 /* other systems */
659 /* Apple Mac Mini (early 2006) */
660 SND_PCI_QUIRK(0x8384, 0x7680,
661 "Mac Mini", STAC_MACMINI),
662 {} /* terminator */
663 };
664
665 static unsigned int ref927x_pin_configs[14] = {
666 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
667 0x01a19040, 0x01011012, 0x01016011, 0x0101201f,
668 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
669 0x01c42190, 0x40000100,
670 };
671
672 static unsigned int d965_3st_pin_configs[14] = {
673 0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
674 0x01a19021, 0x01813024, 0x40000100, 0x40000100,
675 0x40000100, 0x40000100, 0x40000100, 0x40000100,
676 0x40000100, 0x40000100
677 };
678
679 static unsigned int d965_5st_pin_configs[14] = {
680 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
681 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
682 0x40000100, 0x40000100, 0x40000100, 0x01442070,
683 0x40000100, 0x40000100
684 };
685
686 static unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
687 [STAC_D965_REF] = ref927x_pin_configs,
688 [STAC_D965_3ST] = d965_3st_pin_configs,
689 [STAC_D965_5ST] = d965_5st_pin_configs,
690 };
691
692 static const char *stac927x_models[STAC_927X_MODELS] = {
693 [STAC_D965_REF] = "ref",
694 [STAC_D965_3ST] = "3stack",
695 [STAC_D965_5ST] = "5stack",
696 };
697
698 static struct snd_pci_quirk stac927x_cfg_tbl[] = {
699 /* SigmaTel reference board */
700 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
701 "DFI LanParty", STAC_D965_REF),
702 /* Intel 946 based systems */
703 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST),
704 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST),
705 /* 965 based 3 stack systems */
706 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2116, "Intel D965", STAC_D965_3ST),
707 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2115, "Intel D965", STAC_D965_3ST),
708 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2114, "Intel D965", STAC_D965_3ST),
709 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2113, "Intel D965", STAC_D965_3ST),
710 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2112, "Intel D965", STAC_D965_3ST),
711 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2111, "Intel D965", STAC_D965_3ST),
712 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2110, "Intel D965", STAC_D965_3ST),
713 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2009, "Intel D965", STAC_D965_3ST),
714 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2008, "Intel D965", STAC_D965_3ST),
715 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2007, "Intel D965", STAC_D965_3ST),
716 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2006, "Intel D965", STAC_D965_3ST),
717 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2005, "Intel D965", STAC_D965_3ST),
718 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2004, "Intel D965", STAC_D965_3ST),
719 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2003, "Intel D965", STAC_D965_3ST),
720 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2002, "Intel D965", STAC_D965_3ST),
721 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2001, "Intel D965", STAC_D965_3ST),
722 /* 965 based 5 stack systems */
723 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2301, "Intel D965", STAC_D965_5ST),
724 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2302, "Intel D965", STAC_D965_5ST),
725 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2303, "Intel D965", STAC_D965_5ST),
726 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2304, "Intel D965", STAC_D965_5ST),
727 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2305, "Intel D965", STAC_D965_5ST),
728 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2501, "Intel D965", STAC_D965_5ST),
729 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2502, "Intel D965", STAC_D965_5ST),
730 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2503, "Intel D965", STAC_D965_5ST),
731 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2504, "Intel D965", STAC_D965_5ST),
732 {} /* terminator */
733 };
734
735 static unsigned int ref9205_pin_configs[12] = {
736 0x40000100, 0x40000100, 0x01016011, 0x01014010,
737 0x01813122, 0x01a19021, 0x40000100, 0x40000100,
738 0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
739 };
740
741 static unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
742 ref9205_pin_configs,
743 };
744
745 static const char *stac9205_models[STAC_9205_MODELS] = {
746 [STAC_9205_REF] = "ref",
747 };
748
749 static struct snd_pci_quirk stac9205_cfg_tbl[] = {
750 /* SigmaTel reference board */
751 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
752 "DFI LanParty", STAC_9205_REF),
753 {} /* terminator */
754 };
755
756 static int stac92xx_save_bios_config_regs(struct hda_codec *codec)
757 {
758 int i;
759 struct sigmatel_spec *spec = codec->spec;
760
761 if (! spec->bios_pin_configs) {
762 spec->bios_pin_configs = kcalloc(spec->num_pins,
763 sizeof(*spec->bios_pin_configs), GFP_KERNEL);
764 if (! spec->bios_pin_configs)
765 return -ENOMEM;
766 }
767
768 for (i = 0; i < spec->num_pins; i++) {
769 hda_nid_t nid = spec->pin_nids[i];
770 unsigned int pin_cfg;
771
772 pin_cfg = snd_hda_codec_read(codec, nid, 0,
773 AC_VERB_GET_CONFIG_DEFAULT, 0x00);
774 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x bios pin config %8.8x\n",
775 nid, pin_cfg);
776 spec->bios_pin_configs[i] = pin_cfg;
777 }
778
779 return 0;
780 }
781
782 static void stac92xx_set_config_regs(struct hda_codec *codec)
783 {
784 int i;
785 struct sigmatel_spec *spec = codec->spec;
786 unsigned int pin_cfg;
787
788 if (! spec->pin_nids || ! spec->pin_configs)
789 return;
790
791 for (i = 0; i < spec->num_pins; i++) {
792 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
793 AC_VERB_SET_CONFIG_DEFAULT_BYTES_0,
794 spec->pin_configs[i] & 0x000000ff);
795 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
796 AC_VERB_SET_CONFIG_DEFAULT_BYTES_1,
797 (spec->pin_configs[i] & 0x0000ff00) >> 8);
798 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
799 AC_VERB_SET_CONFIG_DEFAULT_BYTES_2,
800 (spec->pin_configs[i] & 0x00ff0000) >> 16);
801 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
802 AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
803 spec->pin_configs[i] >> 24);
804 pin_cfg = snd_hda_codec_read(codec, spec->pin_nids[i], 0,
805 AC_VERB_GET_CONFIG_DEFAULT,
806 0x00);
807 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x pin config %8.8x\n", spec->pin_nids[i], pin_cfg);
808 }
809 }
810
811 /*
812 * Analog playback callbacks
813 */
814 static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
815 struct hda_codec *codec,
816 struct snd_pcm_substream *substream)
817 {
818 struct sigmatel_spec *spec = codec->spec;
819 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
820 }
821
822 static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
823 struct hda_codec *codec,
824 unsigned int stream_tag,
825 unsigned int format,
826 struct snd_pcm_substream *substream)
827 {
828 struct sigmatel_spec *spec = codec->spec;
829 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
830 }
831
832 static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
833 struct hda_codec *codec,
834 struct snd_pcm_substream *substream)
835 {
836 struct sigmatel_spec *spec = codec->spec;
837 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
838 }
839
840 /*
841 * Digital playback callbacks
842 */
843 static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
844 struct hda_codec *codec,
845 struct snd_pcm_substream *substream)
846 {
847 struct sigmatel_spec *spec = codec->spec;
848 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
849 }
850
851 static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
852 struct hda_codec *codec,
853 struct snd_pcm_substream *substream)
854 {
855 struct sigmatel_spec *spec = codec->spec;
856 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
857 }
858
859 static int stac92xx_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
860 struct hda_codec *codec,
861 unsigned int stream_tag,
862 unsigned int format,
863 struct snd_pcm_substream *substream)
864 {
865 struct sigmatel_spec *spec = codec->spec;
866 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
867 stream_tag, format, substream);
868 }
869
870
871 /*
872 * Analog capture callbacks
873 */
874 static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
875 struct hda_codec *codec,
876 unsigned int stream_tag,
877 unsigned int format,
878 struct snd_pcm_substream *substream)
879 {
880 struct sigmatel_spec *spec = codec->spec;
881
882 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
883 stream_tag, 0, format);
884 return 0;
885 }
886
887 static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
888 struct hda_codec *codec,
889 struct snd_pcm_substream *substream)
890 {
891 struct sigmatel_spec *spec = codec->spec;
892
893 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 0, 0, 0);
894 return 0;
895 }
896
897 static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
898 .substreams = 1,
899 .channels_min = 2,
900 .channels_max = 2,
901 /* NID is set in stac92xx_build_pcms */
902 .ops = {
903 .open = stac92xx_dig_playback_pcm_open,
904 .close = stac92xx_dig_playback_pcm_close,
905 .prepare = stac92xx_dig_playback_pcm_prepare
906 },
907 };
908
909 static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
910 .substreams = 1,
911 .channels_min = 2,
912 .channels_max = 2,
913 /* NID is set in stac92xx_build_pcms */
914 };
915
916 static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
917 .substreams = 1,
918 .channels_min = 2,
919 .channels_max = 8,
920 .nid = 0x02, /* NID to query formats and rates */
921 .ops = {
922 .open = stac92xx_playback_pcm_open,
923 .prepare = stac92xx_playback_pcm_prepare,
924 .cleanup = stac92xx_playback_pcm_cleanup
925 },
926 };
927
928 static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
929 .substreams = 1,
930 .channels_min = 2,
931 .channels_max = 2,
932 .nid = 0x06, /* NID to query formats and rates */
933 .ops = {
934 .open = stac92xx_playback_pcm_open,
935 .prepare = stac92xx_playback_pcm_prepare,
936 .cleanup = stac92xx_playback_pcm_cleanup
937 },
938 };
939
940 static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
941 .substreams = 2,
942 .channels_min = 2,
943 .channels_max = 2,
944 /* NID is set in stac92xx_build_pcms */
945 .ops = {
946 .prepare = stac92xx_capture_pcm_prepare,
947 .cleanup = stac92xx_capture_pcm_cleanup
948 },
949 };
950
951 static int stac92xx_build_pcms(struct hda_codec *codec)
952 {
953 struct sigmatel_spec *spec = codec->spec;
954 struct hda_pcm *info = spec->pcm_rec;
955
956 codec->num_pcms = 1;
957 codec->pcm_info = info;
958
959 info->name = "STAC92xx Analog";
960 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
961 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
962 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
963
964 if (spec->alt_switch) {
965 codec->num_pcms++;
966 info++;
967 info->name = "STAC92xx Analog Alt";
968 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
969 }
970
971 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
972 codec->num_pcms++;
973 info++;
974 info->name = "STAC92xx Digital";
975 if (spec->multiout.dig_out_nid) {
976 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
977 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
978 }
979 if (spec->dig_in_nid) {
980 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
981 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
982 }
983 }
984
985 return 0;
986 }
987
988 static unsigned int stac92xx_get_vref(struct hda_codec *codec, hda_nid_t nid)
989 {
990 unsigned int pincap = snd_hda_param_read(codec, nid,
991 AC_PAR_PIN_CAP);
992 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
993 if (pincap & AC_PINCAP_VREF_100)
994 return AC_PINCTL_VREF_100;
995 if (pincap & AC_PINCAP_VREF_80)
996 return AC_PINCTL_VREF_80;
997 if (pincap & AC_PINCAP_VREF_50)
998 return AC_PINCTL_VREF_50;
999 if (pincap & AC_PINCAP_VREF_GRD)
1000 return AC_PINCTL_VREF_GRD;
1001 return 0;
1002 }
1003
1004 static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
1005
1006 {
1007 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
1008 }
1009
1010 static int stac92xx_io_switch_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1011 {
1012 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1013 uinfo->count = 1;
1014 uinfo->value.integer.min = 0;
1015 uinfo->value.integer.max = 1;
1016 return 0;
1017 }
1018
1019 static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1020 {
1021 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1022 struct sigmatel_spec *spec = codec->spec;
1023 int io_idx = kcontrol-> private_value & 0xff;
1024
1025 ucontrol->value.integer.value[0] = spec->io_switch[io_idx];
1026 return 0;
1027 }
1028
1029 static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1030 {
1031 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1032 struct sigmatel_spec *spec = codec->spec;
1033 hda_nid_t nid = kcontrol->private_value >> 8;
1034 int io_idx = kcontrol-> private_value & 0xff;
1035 unsigned short val = ucontrol->value.integer.value[0];
1036
1037 spec->io_switch[io_idx] = val;
1038
1039 if (val)
1040 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
1041 else {
1042 unsigned int pinctl = AC_PINCTL_IN_EN;
1043 if (io_idx) /* set VREF for mic */
1044 pinctl |= stac92xx_get_vref(codec, nid);
1045 stac92xx_auto_set_pinctl(codec, nid, pinctl);
1046 }
1047 return 1;
1048 }
1049
1050 #define STAC_CODEC_IO_SWITCH(xname, xpval) \
1051 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1052 .name = xname, \
1053 .index = 0, \
1054 .info = stac92xx_io_switch_info, \
1055 .get = stac92xx_io_switch_get, \
1056 .put = stac92xx_io_switch_put, \
1057 .private_value = xpval, \
1058 }
1059
1060
1061 enum {
1062 STAC_CTL_WIDGET_VOL,
1063 STAC_CTL_WIDGET_MUTE,
1064 STAC_CTL_WIDGET_IO_SWITCH,
1065 };
1066
1067 static struct snd_kcontrol_new stac92xx_control_templates[] = {
1068 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
1069 HDA_CODEC_MUTE(NULL, 0, 0, 0),
1070 STAC_CODEC_IO_SWITCH(NULL, 0),
1071 };
1072
1073 /* add dynamic controls */
1074 static int stac92xx_add_control(struct sigmatel_spec *spec, int type, const char *name, unsigned long val)
1075 {
1076 struct snd_kcontrol_new *knew;
1077
1078 if (spec->num_kctl_used >= spec->num_kctl_alloc) {
1079 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
1080
1081 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */
1082 if (! knew)
1083 return -ENOMEM;
1084 if (spec->kctl_alloc) {
1085 memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
1086 kfree(spec->kctl_alloc);
1087 }
1088 spec->kctl_alloc = knew;
1089 spec->num_kctl_alloc = num;
1090 }
1091
1092 knew = &spec->kctl_alloc[spec->num_kctl_used];
1093 *knew = stac92xx_control_templates[type];
1094 knew->name = kstrdup(name, GFP_KERNEL);
1095 if (! knew->name)
1096 return -ENOMEM;
1097 knew->private_value = val;
1098 spec->num_kctl_used++;
1099 return 0;
1100 }
1101
1102 /* flag inputs as additional dynamic lineouts */
1103 static int stac92xx_add_dyn_out_pins(struct hda_codec *codec, struct auto_pin_cfg *cfg)
1104 {
1105 struct sigmatel_spec *spec = codec->spec;
1106 unsigned int wcaps, wtype;
1107 int i, num_dacs = 0;
1108
1109 /* use the wcaps cache to count all DACs available for line-outs */
1110 for (i = 0; i < codec->num_nodes; i++) {
1111 wcaps = codec->wcaps[i];
1112 wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
1113 if (wtype == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL))
1114 num_dacs++;
1115 }
1116
1117 snd_printdd("%s: total dac count=%d\n", __func__, num_dacs);
1118
1119 switch (cfg->line_outs) {
1120 case 3:
1121 /* add line-in as side */
1122 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 3) {
1123 cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_LINE];
1124 spec->line_switch = 1;
1125 cfg->line_outs++;
1126 }
1127 break;
1128 case 2:
1129 /* add line-in as clfe and mic as side */
1130 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 2) {
1131 cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_LINE];
1132 spec->line_switch = 1;
1133 cfg->line_outs++;
1134 }
1135 if (cfg->input_pins[AUTO_PIN_MIC] && num_dacs > 3) {
1136 cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_MIC];
1137 spec->mic_switch = 1;
1138 cfg->line_outs++;
1139 }
1140 break;
1141 case 1:
1142 /* add line-in as surr and mic as clfe */
1143 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 1) {
1144 cfg->line_out_pins[1] = cfg->input_pins[AUTO_PIN_LINE];
1145 spec->line_switch = 1;
1146 cfg->line_outs++;
1147 }
1148 if (cfg->input_pins[AUTO_PIN_MIC] && num_dacs > 2) {
1149 cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_MIC];
1150 spec->mic_switch = 1;
1151 cfg->line_outs++;
1152 }
1153 break;
1154 }
1155
1156 return 0;
1157 }
1158
1159
1160 static int is_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
1161 {
1162 int i;
1163
1164 for (i = 0; i < spec->multiout.num_dacs; i++) {
1165 if (spec->multiout.dac_nids[i] == nid)
1166 return 1;
1167 }
1168
1169 return 0;
1170 }
1171
1172 /*
1173 * Fill in the dac_nids table from the parsed pin configuration
1174 * This function only works when every pin in line_out_pins[]
1175 * contains atleast one DAC in its connection list. Some 92xx
1176 * codecs are not connected directly to a DAC, such as the 9200
1177 * and 9202/925x. For those, dac_nids[] must be hard-coded.
1178 */
1179 static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec,
1180 const struct auto_pin_cfg *cfg)
1181 {
1182 struct sigmatel_spec *spec = codec->spec;
1183 int i, j, conn_len = 0;
1184 hda_nid_t nid, conn[HDA_MAX_CONNECTIONS];
1185 unsigned int wcaps, wtype;
1186
1187 for (i = 0; i < cfg->line_outs; i++) {
1188 nid = cfg->line_out_pins[i];
1189 conn_len = snd_hda_get_connections(codec, nid, conn,
1190 HDA_MAX_CONNECTIONS);
1191 for (j = 0; j < conn_len; j++) {
1192 wcaps = snd_hda_param_read(codec, conn[j],
1193 AC_PAR_AUDIO_WIDGET_CAP);
1194 wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
1195
1196 if (wtype != AC_WID_AUD_OUT ||
1197 (wcaps & AC_WCAP_DIGITAL))
1198 continue;
1199 /* conn[j] is a DAC routed to this line-out */
1200 if (!is_in_dac_nids(spec, conn[j]))
1201 break;
1202 }
1203
1204 if (j == conn_len) {
1205 /* error out, no available DAC found */
1206 snd_printk(KERN_ERR
1207 "%s: No available DAC for pin 0x%x\n",
1208 __func__, nid);
1209 return -ENODEV;
1210 }
1211
1212 spec->multiout.dac_nids[i] = conn[j];
1213 spec->multiout.num_dacs++;
1214 if (conn_len > 1) {
1215 /* select this DAC in the pin's input mux */
1216 snd_hda_codec_write(codec, nid, 0,
1217 AC_VERB_SET_CONNECT_SEL, j);
1218
1219 }
1220 }
1221
1222 snd_printd("dac_nids=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
1223 spec->multiout.num_dacs,
1224 spec->multiout.dac_nids[0],
1225 spec->multiout.dac_nids[1],
1226 spec->multiout.dac_nids[2],
1227 spec->multiout.dac_nids[3],
1228 spec->multiout.dac_nids[4]);
1229 return 0;
1230 }
1231
1232 /* create volume control/switch for the given prefx type */
1233 static int create_controls(struct sigmatel_spec *spec, const char *pfx, hda_nid_t nid, int chs)
1234 {
1235 char name[32];
1236 int err;
1237
1238 sprintf(name, "%s Playback Volume", pfx);
1239 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, name,
1240 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1241 if (err < 0)
1242 return err;
1243 sprintf(name, "%s Playback Switch", pfx);
1244 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, name,
1245 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1246 if (err < 0)
1247 return err;
1248 return 0;
1249 }
1250
1251 /* add playback controls from the parsed DAC table */
1252 static int stac92xx_auto_create_multi_out_ctls(struct sigmatel_spec *spec,
1253 const struct auto_pin_cfg *cfg)
1254 {
1255 static const char *chname[4] = {
1256 "Front", "Surround", NULL /*CLFE*/, "Side"
1257 };
1258 hda_nid_t nid;
1259 int i, err;
1260
1261 for (i = 0; i < cfg->line_outs; i++) {
1262 if (!spec->multiout.dac_nids[i])
1263 continue;
1264
1265 nid = spec->multiout.dac_nids[i];
1266
1267 if (i == 2) {
1268 /* Center/LFE */
1269 err = create_controls(spec, "Center", nid, 1);
1270 if (err < 0)
1271 return err;
1272 err = create_controls(spec, "LFE", nid, 2);
1273 if (err < 0)
1274 return err;
1275 } else {
1276 err = create_controls(spec, chname[i], nid, 3);
1277 if (err < 0)
1278 return err;
1279 }
1280 }
1281
1282 if (spec->line_switch)
1283 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Line In as Output Switch", cfg->input_pins[AUTO_PIN_LINE] << 8)) < 0)
1284 return err;
1285
1286 if (spec->mic_switch)
1287 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Mic as Output Switch", (cfg->input_pins[AUTO_PIN_MIC] << 8) | 1)) < 0)
1288 return err;
1289
1290 return 0;
1291 }
1292
1293 static int check_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
1294 {
1295 if (is_in_dac_nids(spec, nid))
1296 return 1;
1297 if (spec->multiout.hp_nid == nid)
1298 return 1;
1299 return 0;
1300 }
1301
1302 static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
1303 {
1304 if (!spec->multiout.hp_nid)
1305 spec->multiout.hp_nid = nid;
1306 else if (spec->multiout.num_dacs > 4) {
1307 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
1308 return 1;
1309 } else {
1310 spec->multiout.dac_nids[spec->multiout.num_dacs] = nid;
1311 spec->multiout.num_dacs++;
1312 }
1313 return 0;
1314 }
1315
1316 /* add playback controls for Speaker and HP outputs */
1317 static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
1318 struct auto_pin_cfg *cfg)
1319 {
1320 struct sigmatel_spec *spec = codec->spec;
1321 hda_nid_t nid;
1322 int i, old_num_dacs, err;
1323
1324 old_num_dacs = spec->multiout.num_dacs;
1325 for (i = 0; i < cfg->hp_outs; i++) {
1326 unsigned int wid_caps = get_wcaps(codec, cfg->hp_pins[i]);
1327 if (wid_caps & AC_WCAP_UNSOL_CAP)
1328 spec->hp_detect = 1;
1329 nid = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
1330 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
1331 if (check_in_dac_nids(spec, nid))
1332 nid = 0;
1333 if (! nid)
1334 continue;
1335 add_spec_dacs(spec, nid);
1336 }
1337 for (i = 0; i < cfg->speaker_outs; i++) {
1338 nid = snd_hda_codec_read(codec, cfg->speaker_pins[i], 0,
1339 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
1340 if (check_in_dac_nids(spec, nid))
1341 nid = 0;
1342 if (! nid)
1343 continue;
1344 add_spec_dacs(spec, nid);
1345 }
1346
1347 for (i = old_num_dacs; i < spec->multiout.num_dacs; i++) {
1348 static const char *pfxs[] = {
1349 "Speaker", "External Speaker", "Speaker2",
1350 };
1351 err = create_controls(spec, pfxs[i - old_num_dacs],
1352 spec->multiout.dac_nids[i], 3);
1353 if (err < 0)
1354 return err;
1355 }
1356 if (spec->multiout.hp_nid) {
1357 const char *pfx;
1358 if (old_num_dacs == spec->multiout.num_dacs)
1359 pfx = "Master";
1360 else
1361 pfx = "Headphone";
1362 err = create_controls(spec, pfx, spec->multiout.hp_nid, 3);
1363 if (err < 0)
1364 return err;
1365 }
1366
1367 return 0;
1368 }
1369
1370 /* labels for dmic mux inputs */
1371 static const char *stac92xx_dmic_labels[5] = {
1372 "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
1373 "Digital Mic 3", "Digital Mic 4"
1374 };
1375
1376 /* create playback/capture controls for input pins on dmic capable codecs */
1377 static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
1378 const struct auto_pin_cfg *cfg)
1379 {
1380 struct sigmatel_spec *spec = codec->spec;
1381 struct hda_input_mux *dimux = &spec->private_dimux;
1382 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
1383 int i, j;
1384
1385 dimux->items[dimux->num_items].label = stac92xx_dmic_labels[0];
1386 dimux->items[dimux->num_items].index = 0;
1387 dimux->num_items++;
1388
1389 for (i = 0; i < spec->num_dmics; i++) {
1390 int index;
1391 int num_cons;
1392 unsigned int def_conf;
1393
1394 def_conf = snd_hda_codec_read(codec,
1395 spec->dmic_nids[i],
1396 0,
1397 AC_VERB_GET_CONFIG_DEFAULT,
1398 0);
1399 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
1400 continue;
1401
1402 num_cons = snd_hda_get_connections(codec,
1403 spec->dmux_nid,
1404 con_lst,
1405 HDA_MAX_NUM_INPUTS);
1406 for (j = 0; j < num_cons; j++)
1407 if (con_lst[j] == spec->dmic_nids[i]) {
1408 index = j;
1409 goto found;
1410 }
1411 continue;
1412 found:
1413 dimux->items[dimux->num_items].label =
1414 stac92xx_dmic_labels[dimux->num_items];
1415 dimux->items[dimux->num_items].index = index;
1416 dimux->num_items++;
1417 }
1418
1419 return 0;
1420 }
1421
1422 /* create playback/capture controls for input pins */
1423 static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
1424 {
1425 struct sigmatel_spec *spec = codec->spec;
1426 struct hda_input_mux *imux = &spec->private_imux;
1427 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
1428 int i, j, k;
1429
1430 for (i = 0; i < AUTO_PIN_LAST; i++) {
1431 int index;
1432
1433 if (!cfg->input_pins[i])
1434 continue;
1435 index = -1;
1436 for (j = 0; j < spec->num_muxes; j++) {
1437 int num_cons;
1438 num_cons = snd_hda_get_connections(codec,
1439 spec->mux_nids[j],
1440 con_lst,
1441 HDA_MAX_NUM_INPUTS);
1442 for (k = 0; k < num_cons; k++)
1443 if (con_lst[k] == cfg->input_pins[i]) {
1444 index = k;
1445 goto found;
1446 }
1447 }
1448 continue;
1449 found:
1450 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
1451 imux->items[imux->num_items].index = index;
1452 imux->num_items++;
1453 }
1454
1455 if (imux->num_items) {
1456 /*
1457 * Set the current input for the muxes.
1458 * The STAC9221 has two input muxes with identical source
1459 * NID lists. Hopefully this won't get confused.
1460 */
1461 for (i = 0; i < spec->num_muxes; i++) {
1462 snd_hda_codec_write(codec, spec->mux_nids[i], 0,
1463 AC_VERB_SET_CONNECT_SEL,
1464 imux->items[0].index);
1465 }
1466 }
1467
1468 return 0;
1469 }
1470
1471 static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
1472 {
1473 struct sigmatel_spec *spec = codec->spec;
1474 int i;
1475
1476 for (i = 0; i < spec->autocfg.line_outs; i++) {
1477 hda_nid_t nid = spec->autocfg.line_out_pins[i];
1478 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
1479 }
1480 }
1481
1482 static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
1483 {
1484 struct sigmatel_spec *spec = codec->spec;
1485 int i;
1486
1487 for (i = 0; i < spec->autocfg.hp_outs; i++) {
1488 hda_nid_t pin;
1489 pin = spec->autocfg.hp_pins[i];
1490 if (pin) /* connect to front */
1491 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
1492 }
1493 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
1494 hda_nid_t pin;
1495 pin = spec->autocfg.speaker_pins[i];
1496 if (pin) /* connect to front */
1497 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
1498 }
1499 }
1500
1501 static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out, hda_nid_t dig_in)
1502 {
1503 struct sigmatel_spec *spec = codec->spec;
1504 int err;
1505
1506 if ((err = snd_hda_parse_pin_def_config(codec,
1507 &spec->autocfg,
1508 spec->dmic_nids)) < 0)
1509 return err;
1510 if (! spec->autocfg.line_outs)
1511 return 0; /* can't find valid pin config */
1512
1513 if ((err = stac92xx_add_dyn_out_pins(codec, &spec->autocfg)) < 0)
1514 return err;
1515 if (spec->multiout.num_dacs == 0)
1516 if ((err = stac92xx_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
1517 return err;
1518
1519 if ((err = stac92xx_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
1520 (err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg)) < 0 ||
1521 (err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
1522 return err;
1523
1524 if (spec->num_dmics > 0)
1525 if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
1526 &spec->autocfg)) < 0)
1527 return err;
1528
1529 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
1530 if (spec->multiout.max_channels > 2)
1531 spec->surr_switch = 1;
1532
1533 if (spec->autocfg.dig_out_pin)
1534 spec->multiout.dig_out_nid = dig_out;
1535 if (spec->autocfg.dig_in_pin)
1536 spec->dig_in_nid = dig_in;
1537
1538 if (spec->kctl_alloc)
1539 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
1540
1541 spec->input_mux = &spec->private_imux;
1542 spec->dinput_mux = &spec->private_dimux;
1543
1544 return 1;
1545 }
1546
1547 /* add playback controls for HP output */
1548 static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
1549 struct auto_pin_cfg *cfg)
1550 {
1551 struct sigmatel_spec *spec = codec->spec;
1552 hda_nid_t pin = cfg->hp_pins[0];
1553 unsigned int wid_caps;
1554
1555 if (! pin)
1556 return 0;
1557
1558 wid_caps = get_wcaps(codec, pin);
1559 if (wid_caps & AC_WCAP_UNSOL_CAP)
1560 spec->hp_detect = 1;
1561
1562 return 0;
1563 }
1564
1565 /* add playback controls for LFE output */
1566 static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
1567 struct auto_pin_cfg *cfg)
1568 {
1569 struct sigmatel_spec *spec = codec->spec;
1570 int err;
1571 hda_nid_t lfe_pin = 0x0;
1572 int i;
1573
1574 /*
1575 * search speaker outs and line outs for a mono speaker pin
1576 * with an amp. If one is found, add LFE controls
1577 * for it.
1578 */
1579 for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
1580 hda_nid_t pin = spec->autocfg.speaker_pins[i];
1581 unsigned long wcaps = get_wcaps(codec, pin);
1582 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
1583 if (wcaps == AC_WCAP_OUT_AMP)
1584 /* found a mono speaker with an amp, must be lfe */
1585 lfe_pin = pin;
1586 }
1587
1588 /* if speaker_outs is 0, then speakers may be in line_outs */
1589 if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
1590 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
1591 hda_nid_t pin = spec->autocfg.line_out_pins[i];
1592 unsigned long cfg;
1593 cfg = snd_hda_codec_read(codec, pin, 0,
1594 AC_VERB_GET_CONFIG_DEFAULT,
1595 0x00);
1596 if (get_defcfg_device(cfg) == AC_JACK_SPEAKER) {
1597 unsigned long wcaps = get_wcaps(codec, pin);
1598 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
1599 if (wcaps == AC_WCAP_OUT_AMP)
1600 /* found a mono speaker with an amp,
1601 must be lfe */
1602 lfe_pin = pin;
1603 }
1604 }
1605 }
1606
1607 if (lfe_pin) {
1608 err = create_controls(spec, "LFE", lfe_pin, 1);
1609 if (err < 0)
1610 return err;
1611 }
1612
1613 return 0;
1614 }
1615
1616 static int stac9200_parse_auto_config(struct hda_codec *codec)
1617 {
1618 struct sigmatel_spec *spec = codec->spec;
1619 int err;
1620
1621 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
1622 return err;
1623
1624 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
1625 return err;
1626
1627 if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
1628 return err;
1629
1630 if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
1631 return err;
1632
1633 if (spec->autocfg.dig_out_pin)
1634 spec->multiout.dig_out_nid = 0x05;
1635 if (spec->autocfg.dig_in_pin)
1636 spec->dig_in_nid = 0x04;
1637
1638 if (spec->kctl_alloc)
1639 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
1640
1641 spec->input_mux = &spec->private_imux;
1642 spec->dinput_mux = &spec->private_dimux;
1643
1644 return 1;
1645 }
1646
1647 /*
1648 * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
1649 * funky external mute control using GPIO pins.
1650 */
1651
1652 static void stac922x_gpio_mute(struct hda_codec *codec, int pin, int muted)
1653 {
1654 unsigned int gpiostate, gpiomask, gpiodir;
1655
1656 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
1657 AC_VERB_GET_GPIO_DATA, 0);
1658
1659 if (!muted)
1660 gpiostate |= (1 << pin);
1661 else
1662 gpiostate &= ~(1 << pin);
1663
1664 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
1665 AC_VERB_GET_GPIO_MASK, 0);
1666 gpiomask |= (1 << pin);
1667
1668 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
1669 AC_VERB_GET_GPIO_DIRECTION, 0);
1670 gpiodir |= (1 << pin);
1671
1672 /* AppleHDA seems to do this -- WTF is this verb?? */
1673 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
1674
1675 snd_hda_codec_write(codec, codec->afg, 0,
1676 AC_VERB_SET_GPIO_MASK, gpiomask);
1677 snd_hda_codec_write(codec, codec->afg, 0,
1678 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
1679
1680 msleep(1);
1681
1682 snd_hda_codec_write(codec, codec->afg, 0,
1683 AC_VERB_SET_GPIO_DATA, gpiostate);
1684 }
1685
1686 static void enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
1687 unsigned int event)
1688 {
1689 if (get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP)
1690 snd_hda_codec_write(codec, nid, 0,
1691 AC_VERB_SET_UNSOLICITED_ENABLE,
1692 (AC_USRSP_EN | event));
1693 }
1694
1695 static int stac92xx_init(struct hda_codec *codec)
1696 {
1697 struct sigmatel_spec *spec = codec->spec;
1698 struct auto_pin_cfg *cfg = &spec->autocfg;
1699 int i;
1700
1701 snd_hda_sequence_write(codec, spec->init);
1702
1703 /* set up pins */
1704 if (spec->hp_detect) {
1705 /* Enable unsolicited responses on the HP widget */
1706 for (i = 0; i < cfg->hp_outs; i++)
1707 enable_pin_detect(codec, cfg->hp_pins[i],
1708 STAC_HP_EVENT);
1709 /* force to enable the first line-out; the others are set up
1710 * in unsol_event
1711 */
1712 stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
1713 AC_PINCTL_OUT_EN);
1714 stac92xx_auto_init_hp_out(codec);
1715 /* fake event to set up pins */
1716 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
1717 } else {
1718 stac92xx_auto_init_multi_out(codec);
1719 stac92xx_auto_init_hp_out(codec);
1720 }
1721 for (i = 0; i < AUTO_PIN_LAST; i++) {
1722 hda_nid_t nid = cfg->input_pins[i];
1723 if (nid) {
1724 unsigned int pinctl = AC_PINCTL_IN_EN;
1725 if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC)
1726 pinctl |= stac92xx_get_vref(codec, nid);
1727 stac92xx_auto_set_pinctl(codec, nid, pinctl);
1728 }
1729 }
1730 if (spec->num_dmics > 0)
1731 for (i = 0; i < spec->num_dmics; i++)
1732 stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
1733 AC_PINCTL_IN_EN);
1734
1735 if (cfg->dig_out_pin)
1736 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pin,
1737 AC_PINCTL_OUT_EN);
1738 if (cfg->dig_in_pin)
1739 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
1740 AC_PINCTL_IN_EN);
1741
1742 if (spec->gpio_mute) {
1743 stac922x_gpio_mute(codec, 0, 0);
1744 stac922x_gpio_mute(codec, 1, 0);
1745 }
1746
1747 return 0;
1748 }
1749
1750 static void stac92xx_free(struct hda_codec *codec)
1751 {
1752 struct sigmatel_spec *spec = codec->spec;
1753 int i;
1754
1755 if (! spec)
1756 return;
1757
1758 if (spec->kctl_alloc) {
1759 for (i = 0; i < spec->num_kctl_used; i++)
1760 kfree(spec->kctl_alloc[i].name);
1761 kfree(spec->kctl_alloc);
1762 }
1763
1764 if (spec->bios_pin_configs)
1765 kfree(spec->bios_pin_configs);
1766
1767 kfree(spec);
1768 }
1769
1770 static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
1771 unsigned int flag)
1772 {
1773 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
1774 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
1775
1776 if (pin_ctl & AC_PINCTL_IN_EN) {
1777 /*
1778 * we need to check the current set-up direction of
1779 * shared input pins since they can be switched via
1780 * "xxx as Output" mixer switch
1781 */
1782 struct sigmatel_spec *spec = codec->spec;
1783 struct auto_pin_cfg *cfg = &spec->autocfg;
1784 if ((nid == cfg->input_pins[AUTO_PIN_LINE] &&
1785 spec->line_switch) ||
1786 (nid == cfg->input_pins[AUTO_PIN_MIC] &&
1787 spec->mic_switch))
1788 return;
1789 }
1790
1791 /* if setting pin direction bits, clear the current
1792 direction bits first */
1793 if (flag & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))
1794 pin_ctl &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
1795
1796 snd_hda_codec_write(codec, nid, 0,
1797 AC_VERB_SET_PIN_WIDGET_CONTROL,
1798 pin_ctl | flag);
1799 }
1800
1801 static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
1802 unsigned int flag)
1803 {
1804 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
1805 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
1806 snd_hda_codec_write(codec, nid, 0,
1807 AC_VERB_SET_PIN_WIDGET_CONTROL,
1808 pin_ctl & ~flag);
1809 }
1810
1811 static int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
1812 {
1813 if (!nid)
1814 return 0;
1815 if (snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PIN_SENSE, 0x00)
1816 & (1 << 31))
1817 return 1;
1818 return 0;
1819 }
1820
1821 static void stac92xx_hp_detect(struct hda_codec *codec, unsigned int res)
1822 {
1823 struct sigmatel_spec *spec = codec->spec;
1824 struct auto_pin_cfg *cfg = &spec->autocfg;
1825 int i, presence;
1826
1827 presence = 0;
1828 for (i = 0; i < cfg->hp_outs; i++) {
1829 presence = get_pin_presence(codec, cfg->hp_pins[i]);
1830 if (presence)
1831 break;
1832 }
1833
1834 if (presence) {
1835 /* disable lineouts, enable hp */
1836 for (i = 0; i < cfg->line_outs; i++)
1837 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
1838 AC_PINCTL_OUT_EN);
1839 for (i = 0; i < cfg->speaker_outs; i++)
1840 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
1841 AC_PINCTL_OUT_EN);
1842 } else {
1843 /* enable lineouts, disable hp */
1844 for (i = 0; i < cfg->line_outs; i++)
1845 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
1846 AC_PINCTL_OUT_EN);
1847 for (i = 0; i < cfg->speaker_outs; i++)
1848 stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
1849 AC_PINCTL_OUT_EN);
1850 }
1851 }
1852
1853 static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
1854 {
1855 switch (res >> 26) {
1856 case STAC_HP_EVENT:
1857 stac92xx_hp_detect(codec, res);
1858 break;
1859 }
1860 }
1861
1862 #ifdef CONFIG_PM
1863 static int stac92xx_resume(struct hda_codec *codec)
1864 {
1865 struct sigmatel_spec *spec = codec->spec;
1866 int i;
1867
1868 stac92xx_init(codec);
1869 stac92xx_set_config_regs(codec);
1870 snd_hda_resume_ctls(codec, spec->mixer);
1871 for (i = 0; i < spec->num_mixers; i++)
1872 snd_hda_resume_ctls(codec, spec->mixers[i]);
1873 if (spec->multiout.dig_out_nid)
1874 snd_hda_resume_spdif_out(codec);
1875 if (spec->dig_in_nid)
1876 snd_hda_resume_spdif_in(codec);
1877
1878 return 0;
1879 }
1880 #endif
1881
1882 static struct hda_codec_ops stac92xx_patch_ops = {
1883 .build_controls = stac92xx_build_controls,
1884 .build_pcms = stac92xx_build_pcms,
1885 .init = stac92xx_init,
1886 .free = stac92xx_free,
1887 .unsol_event = stac92xx_unsol_event,
1888 #ifdef CONFIG_PM
1889 .resume = stac92xx_resume,
1890 #endif
1891 };
1892
1893 static int patch_stac9200(struct hda_codec *codec)
1894 {
1895 struct sigmatel_spec *spec;
1896 int err;
1897
1898 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1899 if (spec == NULL)
1900 return -ENOMEM;
1901
1902 codec->spec = spec;
1903 spec->num_pins = 8;
1904 spec->pin_nids = stac9200_pin_nids;
1905 spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS,
1906 stac9200_models,
1907 stac9200_cfg_tbl);
1908 if (spec->board_config < 0) {
1909 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9200, using BIOS defaults\n");
1910 err = stac92xx_save_bios_config_regs(codec);
1911 if (err < 0) {
1912 stac92xx_free(codec);
1913 return err;
1914 }
1915 spec->pin_configs = spec->bios_pin_configs;
1916 } else {
1917 spec->pin_configs = stac9200_brd_tbl[spec->board_config];
1918 stac92xx_set_config_regs(codec);
1919 }
1920
1921 spec->multiout.max_channels = 2;
1922 spec->multiout.num_dacs = 1;
1923 spec->multiout.dac_nids = stac9200_dac_nids;
1924 spec->adc_nids = stac9200_adc_nids;
1925 spec->mux_nids = stac9200_mux_nids;
1926 spec->num_muxes = 1;
1927 spec->num_dmics = 0;
1928
1929 spec->init = stac9200_core_init;
1930 spec->mixer = stac9200_mixer;
1931
1932 err = stac9200_parse_auto_config(codec);
1933 if (err < 0) {
1934 stac92xx_free(codec);
1935 return err;
1936 }
1937
1938 codec->patch_ops = stac92xx_patch_ops;
1939
1940 return 0;
1941 }
1942
1943 static int patch_stac925x(struct hda_codec *codec)
1944 {
1945 struct sigmatel_spec *spec;
1946 int err;
1947
1948 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1949 if (spec == NULL)
1950 return -ENOMEM;
1951
1952 codec->spec = spec;
1953 spec->num_pins = 8;
1954 spec->pin_nids = stac925x_pin_nids;
1955 spec->board_config = snd_hda_check_board_config(codec, STAC_925x_MODELS,
1956 stac925x_models,
1957 stac925x_cfg_tbl);
1958 again:
1959 if (spec->board_config < 0) {
1960 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC925x,"
1961 "using BIOS defaults\n");
1962 err = stac92xx_save_bios_config_regs(codec);
1963 if (err < 0) {
1964 stac92xx_free(codec);
1965 return err;
1966 }
1967 spec->pin_configs = spec->bios_pin_configs;
1968 } else if (stac925x_brd_tbl[spec->board_config] != NULL){
1969 spec->pin_configs = stac925x_brd_tbl[spec->board_config];
1970 stac92xx_set_config_regs(codec);
1971 }
1972
1973 spec->multiout.max_channels = 2;
1974 spec->multiout.num_dacs = 1;
1975 spec->multiout.dac_nids = stac925x_dac_nids;
1976 spec->adc_nids = stac925x_adc_nids;
1977 spec->mux_nids = stac925x_mux_nids;
1978 spec->num_muxes = 1;
1979 switch (codec->vendor_id) {
1980 case 0x83847632: /* STAC9202 */
1981 case 0x83847633: /* STAC9202D */
1982 case 0x83847636: /* STAC9251 */
1983 case 0x83847637: /* STAC9251D */
1984 spec->num_dmics = 1;
1985 spec->dmic_nids = stac925x_dmic_nids;
1986 break;
1987 default:
1988 spec->num_dmics = 0;
1989 break;
1990 }
1991
1992 spec->init = stac925x_core_init;
1993 spec->mixer = stac925x_mixer;
1994
1995 err = stac92xx_parse_auto_config(codec, 0x8, 0x7);
1996 if (!err) {
1997 if (spec->board_config < 0) {
1998 printk(KERN_WARNING "hda_codec: No auto-config is "
1999 "available, default to model=ref\n");
2000 spec->board_config = STAC_925x_REF;
2001 goto again;
2002 }
2003 err = -EINVAL;
2004 }
2005 if (err < 0) {
2006 stac92xx_free(codec);
2007 return err;
2008 }
2009
2010 codec->patch_ops = stac92xx_patch_ops;
2011
2012 return 0;
2013 }
2014
2015 static int patch_stac922x(struct hda_codec *codec)
2016 {
2017 struct sigmatel_spec *spec;
2018 int err;
2019
2020 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2021 if (spec == NULL)
2022 return -ENOMEM;
2023
2024 codec->spec = spec;
2025 spec->num_pins = 10;
2026 spec->pin_nids = stac922x_pin_nids;
2027 spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS,
2028 stac922x_models,
2029 stac922x_cfg_tbl);
2030 if (spec->board_config == STAC_MACMINI) {
2031 spec->gpio_mute = 1;
2032 /* Intel Macs have all same PCI SSID, so we need to check
2033 * codec SSID to distinguish the exact models
2034 */
2035 printk(KERN_INFO "hda_codec: STAC922x, Apple subsys_id=%x\n", codec->subsystem_id);
2036 switch (codec->subsystem_id) {
2037 case 0x106b0a00: /* MacBook First generatoin */
2038 spec->board_config = STAC_MACBOOK;
2039 break;
2040 case 0x106b0200: /* MacBook Pro first generation */
2041 spec->board_config = STAC_MACBOOK_PRO_V1;
2042 break;
2043 case 0x106b1e00: /* MacBook Pro second generation */
2044 spec->board_config = STAC_MACBOOK_PRO_V2;
2045 break;
2046 case 0x106b0700: /* Intel-based iMac */
2047 spec->board_config = STAC_IMAC_INTEL;
2048 break;
2049 case 0x106b1700: /* Intel iMac 20 */
2050 spec->board_config = STAC_IMAC_INTEL_20;
2051 break;
2052 }
2053 }
2054
2055 again:
2056 if (spec->board_config < 0) {
2057 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC922x, "
2058 "using BIOS defaults\n");
2059 err = stac92xx_save_bios_config_regs(codec);
2060 if (err < 0) {
2061 stac92xx_free(codec);
2062 return err;
2063 }
2064 spec->pin_configs = spec->bios_pin_configs;
2065 } else if (stac922x_brd_tbl[spec->board_config] != NULL) {
2066 spec->pin_configs = stac922x_brd_tbl[spec->board_config];
2067 stac92xx_set_config_regs(codec);
2068 }
2069
2070 spec->adc_nids = stac922x_adc_nids;
2071 spec->mux_nids = stac922x_mux_nids;
2072 spec->num_muxes = ARRAY_SIZE(stac922x_mux_nids);
2073 spec->num_dmics = 0;
2074
2075 spec->init = stac922x_core_init;
2076 spec->mixer = stac922x_mixer;
2077
2078 spec->multiout.dac_nids = spec->dac_nids;
2079
2080 err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
2081 if (!err) {
2082 if (spec->board_config < 0) {
2083 printk(KERN_WARNING "hda_codec: No auto-config is "
2084 "available, default to model=ref\n");
2085 spec->board_config = STAC_D945_REF;
2086 goto again;
2087 }
2088 err = -EINVAL;
2089 }
2090 if (err < 0) {
2091 stac92xx_free(codec);
2092 return err;
2093 }
2094
2095 codec->patch_ops = stac92xx_patch_ops;
2096
2097 return 0;
2098 }
2099
2100 static int patch_stac927x(struct hda_codec *codec)
2101 {
2102 struct sigmatel_spec *spec;
2103 int err;
2104
2105 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2106 if (spec == NULL)
2107 return -ENOMEM;
2108
2109 codec->spec = spec;
2110 spec->num_pins = 14;
2111 spec->pin_nids = stac927x_pin_nids;
2112 spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS,
2113 stac927x_models,
2114 stac927x_cfg_tbl);
2115 again:
2116 if (spec->board_config < 0) {
2117 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC927x, using BIOS defaults\n");
2118 err = stac92xx_save_bios_config_regs(codec);
2119 if (err < 0) {
2120 stac92xx_free(codec);
2121 return err;
2122 }
2123 spec->pin_configs = spec->bios_pin_configs;
2124 } else if (stac927x_brd_tbl[spec->board_config] != NULL) {
2125 spec->pin_configs = stac927x_brd_tbl[spec->board_config];
2126 stac92xx_set_config_regs(codec);
2127 }
2128
2129 switch (spec->board_config) {
2130 case STAC_D965_3ST:
2131 spec->adc_nids = stac927x_adc_nids;
2132 spec->mux_nids = stac927x_mux_nids;
2133 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
2134 spec->num_dmics = 0;
2135 spec->init = d965_core_init;
2136 spec->mixer = stac9227_mixer;
2137 break;
2138 case STAC_D965_5ST:
2139 spec->adc_nids = stac927x_adc_nids;
2140 spec->mux_nids = stac927x_mux_nids;
2141 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
2142 spec->num_dmics = 0;
2143 spec->init = d965_core_init;
2144 spec->mixer = stac9227_mixer;
2145 break;
2146 default:
2147 spec->adc_nids = stac927x_adc_nids;
2148 spec->mux_nids = stac927x_mux_nids;
2149 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
2150 spec->num_dmics = 0;
2151 spec->init = stac927x_core_init;
2152 spec->mixer = stac927x_mixer;
2153 }
2154
2155 spec->multiout.dac_nids = spec->dac_nids;
2156
2157 err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
2158 if (!err) {
2159 if (spec->board_config < 0) {
2160 printk(KERN_WARNING "hda_codec: No auto-config is "
2161 "available, default to model=ref\n");
2162 spec->board_config = STAC_D965_REF;
2163 goto again;
2164 }
2165 err = -EINVAL;
2166 }
2167 if (err < 0) {
2168 stac92xx_free(codec);
2169 return err;
2170 }
2171
2172 codec->patch_ops = stac92xx_patch_ops;
2173
2174 /* Fix Mux capture level; max to 2 */
2175 snd_hda_override_amp_caps(codec, 0x12, HDA_OUTPUT,
2176 (0 << AC_AMPCAP_OFFSET_SHIFT) |
2177 (2 << AC_AMPCAP_NUM_STEPS_SHIFT) |
2178 (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
2179 (0 << AC_AMPCAP_MUTE_SHIFT));
2180
2181 return 0;
2182 }
2183
2184 static int patch_stac9205(struct hda_codec *codec)
2185 {
2186 struct sigmatel_spec *spec;
2187 int err;
2188
2189 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2190 if (spec == NULL)
2191 return -ENOMEM;
2192
2193 codec->spec = spec;
2194 spec->num_pins = 14;
2195 spec->pin_nids = stac9205_pin_nids;
2196 spec->board_config = snd_hda_check_board_config(codec, STAC_9205_MODELS,
2197 stac9205_models,
2198 stac9205_cfg_tbl);
2199 again:
2200 if (spec->board_config < 0) {
2201 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9205, using BIOS defaults\n");
2202 err = stac92xx_save_bios_config_regs(codec);
2203 if (err < 0) {
2204 stac92xx_free(codec);
2205 return err;
2206 }
2207 spec->pin_configs = spec->bios_pin_configs;
2208 } else {
2209 spec->pin_configs = stac9205_brd_tbl[spec->board_config];
2210 stac92xx_set_config_regs(codec);
2211 }
2212
2213 spec->adc_nids = stac9205_adc_nids;
2214 spec->mux_nids = stac9205_mux_nids;
2215 spec->num_muxes = ARRAY_SIZE(stac9205_mux_nids);
2216 spec->dmic_nids = stac9205_dmic_nids;
2217 spec->num_dmics = ARRAY_SIZE(stac9205_dmic_nids);
2218 spec->dmux_nid = 0x1d;
2219
2220 spec->init = stac9205_core_init;
2221 spec->mixer = stac9205_mixer;
2222
2223 spec->multiout.dac_nids = spec->dac_nids;
2224
2225 /* Configure GPIO0 as EAPD output */
2226 snd_hda_codec_write(codec, codec->afg, 0,
2227 AC_VERB_SET_GPIO_DIRECTION, 0x00000001);
2228 /* Configure GPIO0 as CMOS */
2229 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0x00000000);
2230 /* Assert GPIO0 high */
2231 snd_hda_codec_write(codec, codec->afg, 0,
2232 AC_VERB_SET_GPIO_DATA, 0x00000001);
2233 /* Enable GPIO0 */
2234 snd_hda_codec_write(codec, codec->afg, 0,
2235 AC_VERB_SET_GPIO_MASK, 0x00000001);
2236
2237 err = stac92xx_parse_auto_config(codec, 0x1f, 0x20);
2238 if (!err) {
2239 if (spec->board_config < 0) {
2240 printk(KERN_WARNING "hda_codec: No auto-config is "
2241 "available, default to model=ref\n");
2242 spec->board_config = STAC_9205_REF;
2243 goto again;
2244 }
2245 err = -EINVAL;
2246 }
2247 if (err < 0) {
2248 stac92xx_free(codec);
2249 return err;
2250 }
2251
2252 codec->patch_ops = stac92xx_patch_ops;
2253
2254 return 0;
2255 }
2256
2257 /*
2258 * STAC9872 hack
2259 */
2260
2261 /* static config for Sony VAIO FE550G and Sony VAIO AR */
2262 static hda_nid_t vaio_dacs[] = { 0x2 };
2263 #define VAIO_HP_DAC 0x5
2264 static hda_nid_t vaio_adcs[] = { 0x8 /*,0x6*/ };
2265 static hda_nid_t vaio_mux_nids[] = { 0x15 };
2266
2267 static struct hda_input_mux vaio_mux = {
2268 .num_items = 2,
2269 .items = {
2270 /* { "HP", 0x0 }, */
2271 { "Line", 0x1 },
2272 { "Mic", 0x2 },
2273 { "PCM", 0x3 },
2274 }
2275 };
2276
2277 static struct hda_verb vaio_init[] = {
2278 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
2279 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
2280 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
2281 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
2282 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
2283 {0x15, AC_VERB_SET_CONNECT_SEL, 0x2}, /* mic-sel: 0a,0d,14,02 */
2284 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
2285 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
2286 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
2287 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
2288 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
2289 {}
2290 };
2291
2292 static struct hda_verb vaio_ar_init[] = {
2293 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
2294 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
2295 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
2296 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
2297 /* {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },*/ /* Optical Out */
2298 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
2299 {0x15, AC_VERB_SET_CONNECT_SEL, 0x2}, /* mic-sel: 0a,0d,14,02 */
2300 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
2301 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
2302 /* {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},*/ /* Optical Out */
2303 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
2304 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
2305 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
2306 {}
2307 };
2308
2309 /* bind volumes of both NID 0x02 and 0x05 */
2310 static int vaio_master_vol_put(struct snd_kcontrol *kcontrol,
2311 struct snd_ctl_elem_value *ucontrol)
2312 {
2313 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2314 long *valp = ucontrol->value.integer.value;
2315 int change;
2316
2317 change = snd_hda_codec_amp_update(codec, 0x02, 0, HDA_OUTPUT, 0,
2318 0x7f, valp[0] & 0x7f);
2319 change |= snd_hda_codec_amp_update(codec, 0x02, 1, HDA_OUTPUT, 0,
2320 0x7f, valp[1] & 0x7f);
2321 snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
2322 0x7f, valp[0] & 0x7f);
2323 snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
2324 0x7f, valp[1] & 0x7f);
2325 return change;
2326 }
2327
2328 /* bind volumes of both NID 0x02 and 0x05 */
2329 static int vaio_master_sw_put(struct snd_kcontrol *kcontrol,
2330 struct snd_ctl_elem_value *ucontrol)
2331 {
2332 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2333 long *valp = ucontrol->value.integer.value;
2334 int change;
2335
2336 change = snd_hda_codec_amp_update(codec, 0x02, 0, HDA_OUTPUT, 0,
2337 0x80, (valp[0] ? 0 : 0x80));
2338 change |= snd_hda_codec_amp_update(codec, 0x02, 1, HDA_OUTPUT, 0,
2339 0x80, (valp[1] ? 0 : 0x80));
2340 snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
2341 0x80, (valp[0] ? 0 : 0x80));
2342 snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
2343 0x80, (valp[1] ? 0 : 0x80));
2344 return change;
2345 }
2346
2347 static struct snd_kcontrol_new vaio_mixer[] = {
2348 {
2349 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2350 .name = "Master Playback Volume",
2351 .info = snd_hda_mixer_amp_volume_info,
2352 .get = snd_hda_mixer_amp_volume_get,
2353 .put = vaio_master_vol_put,
2354 .tlv = { .c = snd_hda_mixer_amp_tlv },
2355 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2356 },
2357 {
2358 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2359 .name = "Master Playback Switch",
2360 .info = snd_hda_mixer_amp_switch_info,
2361 .get = snd_hda_mixer_amp_switch_get,
2362 .put = vaio_master_sw_put,
2363 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2364 },
2365 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
2366 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
2367 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
2368 {
2369 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2370 .name = "Capture Source",
2371 .count = 1,
2372 .info = stac92xx_mux_enum_info,
2373 .get = stac92xx_mux_enum_get,
2374 .put = stac92xx_mux_enum_put,
2375 },
2376 {}
2377 };
2378
2379 static struct snd_kcontrol_new vaio_ar_mixer[] = {
2380 {
2381 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2382 .name = "Master Playback Volume",
2383 .info = snd_hda_mixer_amp_volume_info,
2384 .get = snd_hda_mixer_amp_volume_get,
2385 .put = vaio_master_vol_put,
2386 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2387 },
2388 {
2389 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2390 .name = "Master Playback Switch",
2391 .info = snd_hda_mixer_amp_switch_info,
2392 .get = snd_hda_mixer_amp_switch_get,
2393 .put = vaio_master_sw_put,
2394 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2395 },
2396 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
2397 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
2398 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
2399 /*HDA_CODEC_MUTE("Optical Out Switch", 0x10, 0, HDA_OUTPUT),
2400 HDA_CODEC_VOLUME("Optical Out Volume", 0x10, 0, HDA_OUTPUT),*/
2401 {
2402 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2403 .name = "Capture Source",
2404 .count = 1,
2405 .info = stac92xx_mux_enum_info,
2406 .get = stac92xx_mux_enum_get,
2407 .put = stac92xx_mux_enum_put,
2408 },
2409 {}
2410 };
2411
2412 static struct hda_codec_ops stac9872_patch_ops = {
2413 .build_controls = stac92xx_build_controls,
2414 .build_pcms = stac92xx_build_pcms,
2415 .init = stac92xx_init,
2416 .free = stac92xx_free,
2417 #ifdef CONFIG_PM
2418 .resume = stac92xx_resume,
2419 #endif
2420 };
2421
2422 enum { /* FE and SZ series. id=0x83847661 and subsys=0x104D0700 or 104D1000. */
2423 CXD9872RD_VAIO,
2424 /* Unknown. id=0x83847662 and subsys=0x104D1200 or 104D1000. */
2425 STAC9872AK_VAIO,
2426 /* Unknown. id=0x83847661 and subsys=0x104D1200. */
2427 STAC9872K_VAIO,
2428 /* AR Series. id=0x83847664 and subsys=104D1300 */
2429 CXD9872AKD_VAIO,
2430 STAC_9872_MODELS,
2431 };
2432
2433 static const char *stac9872_models[STAC_9872_MODELS] = {
2434 [CXD9872RD_VAIO] = "vaio",
2435 [CXD9872AKD_VAIO] = "vaio-ar",
2436 };
2437
2438 static struct snd_pci_quirk stac9872_cfg_tbl[] = {
2439 SND_PCI_QUIRK(0x104d, 0x81e6, "Sony VAIO F/S", CXD9872RD_VAIO),
2440 SND_PCI_QUIRK(0x104d, 0x81ef, "Sony VAIO F/S", CXD9872RD_VAIO),
2441 SND_PCI_QUIRK(0x104d, 0x81fd, "Sony VAIO AR", CXD9872AKD_VAIO),
2442 SND_PCI_QUIRK(0x104d, 0x8205, "Sony VAIO AR", CXD9872AKD_VAIO),
2443 {}
2444 };
2445
2446 static int patch_stac9872(struct hda_codec *codec)
2447 {
2448 struct sigmatel_spec *spec;
2449 int board_config;
2450
2451 board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
2452 stac9872_models,
2453 stac9872_cfg_tbl);
2454 if (board_config < 0)
2455 /* unknown config, let generic-parser do its job... */
2456 return snd_hda_parse_generic_codec(codec);
2457
2458 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2459 if (spec == NULL)
2460 return -ENOMEM;
2461
2462 codec->spec = spec;
2463 switch (board_config) {
2464 case CXD9872RD_VAIO:
2465 case STAC9872AK_VAIO:
2466 case STAC9872K_VAIO:
2467 spec->mixer = vaio_mixer;
2468 spec->init = vaio_init;
2469 spec->multiout.max_channels = 2;
2470 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
2471 spec->multiout.dac_nids = vaio_dacs;
2472 spec->multiout.hp_nid = VAIO_HP_DAC;
2473 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
2474 spec->adc_nids = vaio_adcs;
2475 spec->input_mux = &vaio_mux;
2476 spec->mux_nids = vaio_mux_nids;
2477 break;
2478
2479 case CXD9872AKD_VAIO:
2480 spec->mixer = vaio_ar_mixer;
2481 spec->init = vaio_ar_init;
2482 spec->multiout.max_channels = 2;
2483 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
2484 spec->multiout.dac_nids = vaio_dacs;
2485 spec->multiout.hp_nid = VAIO_HP_DAC;
2486 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
2487 spec->adc_nids = vaio_adcs;
2488 spec->input_mux = &vaio_mux;
2489 spec->mux_nids = vaio_mux_nids;
2490 break;
2491 }
2492
2493 codec->patch_ops = stac9872_patch_ops;
2494 return 0;
2495 }
2496
2497
2498 /*
2499 * patch entries
2500 */
2501 struct hda_codec_preset snd_hda_preset_sigmatel[] = {
2502 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
2503 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
2504 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
2505 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
2506 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
2507 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
2508 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
2509 { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
2510 { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
2511 { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
2512 { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
2513 { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
2514 { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
2515 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
2516 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
2517 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
2518 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
2519 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
2520 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
2521 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
2522 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
2523 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
2524 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
2525 { .id = 0x83847632, .name = "STAC9202", .patch = patch_stac925x },
2526 { .id = 0x83847633, .name = "STAC9202D", .patch = patch_stac925x },
2527 { .id = 0x83847634, .name = "STAC9250", .patch = patch_stac925x },
2528 { .id = 0x83847635, .name = "STAC9250D", .patch = patch_stac925x },
2529 { .id = 0x83847636, .name = "STAC9251", .patch = patch_stac925x },
2530 { .id = 0x83847637, .name = "STAC9250D", .patch = patch_stac925x },
2531 /* The following does not take into account .id=0x83847661 when subsys =
2532 * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
2533 * currently not fully supported.
2534 */
2535 { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
2536 { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
2537 { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
2538 { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
2539 { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
2540 { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
2541 { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
2542 { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
2543 { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
2544 { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
2545 { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
2546 {} /* terminator */
2547 };