blob: 1527cb61e5d656390a30b5736cb935d90c049869 [file] [log] [blame]
Matt2f2f4252005-04-13 14:45:30 +02001/*
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.
Matt Porter403d1942005-11-29 15:00:51 +01007 * Matt Porter <mporter@embeddedalley.com>
Matt2f2f4252005-04-13 14:45:30 +02008 *
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>
Mattc7d4b2f2005-06-27 14:59:41 +020033#include <sound/asoundef.h>
Matt2f2f4252005-04-13 14:45:30 +020034#include "hda_codec.h"
35#include "hda_local.h"
36
Matt4e550962005-07-04 17:51:39 +020037#define NUM_CONTROL_ALLOC 32
38#define STAC_HP_EVENT 0x37
Matt4e550962005-07-04 17:51:39 +020039
Takashi Iwaif5fcc132006-11-24 17:07:44 +010040enum {
41 STAC_REF,
42 STAC_9200_MODELS
43};
44
45enum {
46 STAC_9205_REF,
47 STAC_9205_MODELS
48};
49
50enum {
Tobin Davis8e21c342007-01-08 11:04:17 +010051 STAC_925x_REF,
52 STAC_M2_2,
53 STAC_MA6,
Tobin Davis2c11f952007-05-17 09:36:34 +020054 STAC_PA6,
Tobin Davis8e21c342007-01-08 11:04:17 +010055 STAC_925x_MODELS
56};
57
58enum {
Takashi Iwaif5fcc132006-11-24 17:07:44 +010059 STAC_D945_REF,
60 STAC_D945GTP3,
61 STAC_D945GTP5,
62 STAC_MACMINI,
Takashi Iwai3fc24d82007-02-16 13:27:18 +010063 STAC_MACBOOK,
Nicolas Boichat6f0778d2007-03-15 12:38:15 +010064 STAC_MACBOOK_PRO_V1,
65 STAC_MACBOOK_PRO_V2,
Sylvain FORETf16928f2007-04-27 14:22:36 +020066 STAC_IMAC_INTEL,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010067 STAC_922X_MODELS
68};
69
70enum {
71 STAC_D965_REF,
72 STAC_D965_3ST,
73 STAC_D965_5ST,
74 STAC_927X_MODELS
75};
Matt Porter403d1942005-11-29 15:00:51 +010076
Matt2f2f4252005-04-13 14:45:30 +020077struct sigmatel_spec {
Takashi Iwaic8b6bf92005-11-17 14:57:47 +010078 struct snd_kcontrol_new *mixers[4];
Mattc7d4b2f2005-06-27 14:59:41 +020079 unsigned int num_mixers;
80
Matt Porter403d1942005-11-29 15:00:51 +010081 int board_config;
Mattc7d4b2f2005-06-27 14:59:41 +020082 unsigned int surr_switch: 1;
Matt Porter403d1942005-11-29 15:00:51 +010083 unsigned int line_switch: 1;
84 unsigned int mic_switch: 1;
Matt Porter3cc08dc2006-01-23 15:27:49 +010085 unsigned int alt_switch: 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +010086 unsigned int hp_detect: 1;
Sam Revitch62fe78e2006-05-10 15:09:17 +020087 unsigned int gpio_mute: 1;
Mattc7d4b2f2005-06-27 14:59:41 +020088
Matt2f2f4252005-04-13 14:45:30 +020089 /* playback */
90 struct hda_multi_out multiout;
Matt Porter3cc08dc2006-01-23 15:27:49 +010091 hda_nid_t dac_nids[5];
Matt2f2f4252005-04-13 14:45:30 +020092
93 /* capture */
94 hda_nid_t *adc_nids;
Matt2f2f4252005-04-13 14:45:30 +020095 unsigned int num_adcs;
Mattdabbed62005-06-14 10:19:34 +020096 hda_nid_t *mux_nids;
97 unsigned int num_muxes;
Matt Porter8b657272006-10-26 17:12:59 +020098 hda_nid_t *dmic_nids;
99 unsigned int num_dmics;
100 hda_nid_t dmux_nid;
Mattdabbed62005-06-14 10:19:34 +0200101 hda_nid_t dig_in_nid;
Matt2f2f4252005-04-13 14:45:30 +0200102
Matt2f2f4252005-04-13 14:45:30 +0200103 /* pin widgets */
104 hda_nid_t *pin_nids;
105 unsigned int num_pins;
Matt2f2f4252005-04-13 14:45:30 +0200106 unsigned int *pin_configs;
Richard Fish11b44bb2006-08-23 18:31:34 +0200107 unsigned int *bios_pin_configs;
Matt2f2f4252005-04-13 14:45:30 +0200108
109 /* codec specific stuff */
110 struct hda_verb *init;
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100111 struct snd_kcontrol_new *mixer;
Matt2f2f4252005-04-13 14:45:30 +0200112
113 /* capture source */
Matt Porter8b657272006-10-26 17:12:59 +0200114 struct hda_input_mux *dinput_mux;
115 unsigned int cur_dmux;
Mattc7d4b2f2005-06-27 14:59:41 +0200116 struct hda_input_mux *input_mux;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100117 unsigned int cur_mux[3];
Matt2f2f4252005-04-13 14:45:30 +0200118
Matt Porter403d1942005-11-29 15:00:51 +0100119 /* i/o switches */
120 unsigned int io_switch[2];
Matt2f2f4252005-04-13 14:45:30 +0200121
Mattc7d4b2f2005-06-27 14:59:41 +0200122 struct hda_pcm pcm_rec[2]; /* PCM information */
123
124 /* dynamic controls and input_mux */
125 struct auto_pin_cfg autocfg;
126 unsigned int num_kctl_alloc, num_kctl_used;
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100127 struct snd_kcontrol_new *kctl_alloc;
Matt Porter8b657272006-10-26 17:12:59 +0200128 struct hda_input_mux private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +0200129 struct hda_input_mux private_imux;
Matt2f2f4252005-04-13 14:45:30 +0200130};
131
132static hda_nid_t stac9200_adc_nids[1] = {
133 0x03,
134};
135
136static hda_nid_t stac9200_mux_nids[1] = {
137 0x0c,
138};
139
140static hda_nid_t stac9200_dac_nids[1] = {
141 0x02,
142};
143
Tobin Davis8e21c342007-01-08 11:04:17 +0100144static hda_nid_t stac925x_adc_nids[1] = {
145 0x03,
146};
147
148static hda_nid_t stac925x_mux_nids[1] = {
149 0x0f,
150};
151
152static hda_nid_t stac925x_dac_nids[1] = {
153 0x02,
154};
155
Tobin Davis2c11f952007-05-17 09:36:34 +0200156static hda_nid_t stac925x_dmic_nids[1] = {
157 0x15,
158};
159
Matt2f2f4252005-04-13 14:45:30 +0200160static hda_nid_t stac922x_adc_nids[2] = {
161 0x06, 0x07,
162};
163
164static hda_nid_t stac922x_mux_nids[2] = {
165 0x12, 0x13,
166};
167
Matt Porter3cc08dc2006-01-23 15:27:49 +0100168static hda_nid_t stac927x_adc_nids[3] = {
169 0x07, 0x08, 0x09
170};
171
172static hda_nid_t stac927x_mux_nids[3] = {
173 0x15, 0x16, 0x17
174};
175
Matt Porterf3302a52006-07-31 12:49:34 +0200176static hda_nid_t stac9205_adc_nids[2] = {
177 0x12, 0x13
178};
179
180static hda_nid_t stac9205_mux_nids[2] = {
181 0x19, 0x1a
182};
183
Takashi Iwai25494132007-03-12 12:36:16 +0100184static hda_nid_t stac9205_dmic_nids[2] = {
185 0x17, 0x18,
Matt Porter8b657272006-10-26 17:12:59 +0200186};
187
Mattc7d4b2f2005-06-27 14:59:41 +0200188static hda_nid_t stac9200_pin_nids[8] = {
Tobin Davis93ed1502006-09-01 21:03:12 +0200189 0x08, 0x09, 0x0d, 0x0e,
190 0x0f, 0x10, 0x11, 0x12,
Matt2f2f4252005-04-13 14:45:30 +0200191};
192
Tobin Davis8e21c342007-01-08 11:04:17 +0100193static hda_nid_t stac925x_pin_nids[8] = {
194 0x07, 0x08, 0x0a, 0x0b,
195 0x0c, 0x0d, 0x10, 0x11,
196};
197
Matt2f2f4252005-04-13 14:45:30 +0200198static hda_nid_t stac922x_pin_nids[10] = {
199 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
200 0x0f, 0x10, 0x11, 0x15, 0x1b,
201};
202
Matt Porter3cc08dc2006-01-23 15:27:49 +0100203static hda_nid_t stac927x_pin_nids[14] = {
204 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
205 0x0f, 0x10, 0x11, 0x12, 0x13,
206 0x14, 0x21, 0x22, 0x23,
207};
208
Matt Porterf3302a52006-07-31 12:49:34 +0200209static hda_nid_t stac9205_pin_nids[12] = {
210 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
211 0x0f, 0x14, 0x16, 0x17, 0x18,
212 0x21, 0x22,
213
214};
215
Matt Porter8b657272006-10-26 17:12:59 +0200216static int stac92xx_dmux_enum_info(struct snd_kcontrol *kcontrol,
217 struct snd_ctl_elem_info *uinfo)
218{
219 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
220 struct sigmatel_spec *spec = codec->spec;
221 return snd_hda_input_mux_info(spec->dinput_mux, uinfo);
222}
223
224static int stac92xx_dmux_enum_get(struct snd_kcontrol *kcontrol,
225 struct snd_ctl_elem_value *ucontrol)
226{
227 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
228 struct sigmatel_spec *spec = codec->spec;
229
230 ucontrol->value.enumerated.item[0] = spec->cur_dmux;
231 return 0;
232}
233
234static int stac92xx_dmux_enum_put(struct snd_kcontrol *kcontrol,
235 struct snd_ctl_elem_value *ucontrol)
236{
237 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
238 struct sigmatel_spec *spec = codec->spec;
239
240 return snd_hda_input_mux_put(codec, spec->dinput_mux, ucontrol,
241 spec->dmux_nid, &spec->cur_dmux);
242}
243
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100244static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Matt2f2f4252005-04-13 14:45:30 +0200245{
246 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
247 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +0200248 return snd_hda_input_mux_info(spec->input_mux, uinfo);
Matt2f2f4252005-04-13 14:45:30 +0200249}
250
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100251static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200252{
253 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
254 struct sigmatel_spec *spec = codec->spec;
255 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
256
257 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
258 return 0;
259}
260
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100261static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200262{
263 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
264 struct sigmatel_spec *spec = codec->spec;
265 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
266
Mattc7d4b2f2005-06-27 14:59:41 +0200267 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
Matt2f2f4252005-04-13 14:45:30 +0200268 spec->mux_nids[adc_idx], &spec->cur_mux[adc_idx]);
269}
270
Mattc7d4b2f2005-06-27 14:59:41 +0200271static struct hda_verb stac9200_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200272 /* set dac0mux for dac converter */
Mattc7d4b2f2005-06-27 14:59:41 +0200273 { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
Matt2f2f4252005-04-13 14:45:30 +0200274 {}
275};
276
Tobin Davis8e21c342007-01-08 11:04:17 +0100277static struct hda_verb stac925x_core_init[] = {
278 /* set dac0mux for dac converter */
279 { 0x06, AC_VERB_SET_CONNECT_SEL, 0x00},
280 {}
281};
282
Mattc7d4b2f2005-06-27 14:59:41 +0200283static struct hda_verb stac922x_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200284 /* set master volume and direct control */
Mattc7d4b2f2005-06-27 14:59:41 +0200285 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matt2f2f4252005-04-13 14:45:30 +0200286 {}
287};
288
Tobin Davis93ed1502006-09-01 21:03:12 +0200289static struct hda_verb d965_core_init[] = {
Takashi Iwai19039bd2006-06-28 15:52:16 +0200290 /* set master volume and direct control */
Tobin Davis93ed1502006-09-01 21:03:12 +0200291 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Takashi Iwai19039bd2006-06-28 15:52:16 +0200292 /* unmute node 0x1b */
293 { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
294 /* select node 0x03 as DAC */
295 { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
296 {}
297};
298
Matt Porter3cc08dc2006-01-23 15:27:49 +0100299static struct hda_verb stac927x_core_init[] = {
300 /* set master volume and direct control */
301 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
302 {}
303};
304
Matt Porterf3302a52006-07-31 12:49:34 +0200305static struct hda_verb stac9205_core_init[] = {
306 /* set master volume and direct control */
307 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
308 {}
309};
310
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100311static struct snd_kcontrol_new stac9200_mixer[] = {
Matt2f2f4252005-04-13 14:45:30 +0200312 HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
313 HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
314 {
315 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
316 .name = "Input Source",
317 .count = 1,
318 .info = stac92xx_mux_enum_info,
319 .get = stac92xx_mux_enum_get,
320 .put = stac92xx_mux_enum_put,
321 },
322 HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
323 HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
Mattc7d4b2f2005-06-27 14:59:41 +0200324 HDA_CODEC_VOLUME("Capture Mux Volume", 0x0c, 0, HDA_OUTPUT),
Matt2f2f4252005-04-13 14:45:30 +0200325 { } /* end */
326};
327
Tobin Davis8e21c342007-01-08 11:04:17 +0100328static struct snd_kcontrol_new stac925x_mixer[] = {
329 HDA_CODEC_VOLUME("Master Playback Volume", 0xe, 0, HDA_OUTPUT),
330 HDA_CODEC_MUTE("Master Playback Switch", 0xe, 0, HDA_OUTPUT),
331 {
332 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
333 .name = "Input Source",
334 .count = 1,
335 .info = stac92xx_mux_enum_info,
336 .get = stac92xx_mux_enum_get,
337 .put = stac92xx_mux_enum_put,
338 },
339 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_OUTPUT),
340 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_OUTPUT),
341 HDA_CODEC_VOLUME("Capture Mux Volume", 0x0f, 0, HDA_OUTPUT),
342 { } /* end */
343};
344
Mattc7d4b2f2005-06-27 14:59:41 +0200345/* This needs to be generated dynamically based on sequence */
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100346static struct snd_kcontrol_new stac922x_mixer[] = {
Matt2f2f4252005-04-13 14:45:30 +0200347 {
348 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
349 .name = "Input Source",
350 .count = 1,
351 .info = stac92xx_mux_enum_info,
352 .get = stac92xx_mux_enum_get,
353 .put = stac92xx_mux_enum_put,
354 },
355 HDA_CODEC_VOLUME("Capture Volume", 0x17, 0x0, HDA_INPUT),
Takashi Iwai0fd17082006-01-13 18:46:21 +0100356 HDA_CODEC_MUTE("Capture Switch", 0x17, 0x0, HDA_INPUT),
Matt2f2f4252005-04-13 14:45:30 +0200357 HDA_CODEC_VOLUME("Mux Capture Volume", 0x12, 0x0, HDA_OUTPUT),
358 { } /* end */
359};
360
Takashi Iwai19039bd2006-06-28 15:52:16 +0200361/* This needs to be generated dynamically based on sequence */
362static struct snd_kcontrol_new stac9227_mixer[] = {
363 {
364 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
365 .name = "Input Source",
366 .count = 1,
367 .info = stac92xx_mux_enum_info,
368 .get = stac92xx_mux_enum_get,
369 .put = stac92xx_mux_enum_put,
370 },
371 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
372 HDA_CODEC_MUTE("Capture Switch", 0x1b, 0x0, HDA_OUTPUT),
373 { } /* end */
374};
375
Takashi Iwaid1d985f2006-11-23 19:27:12 +0100376static struct snd_kcontrol_new stac927x_mixer[] = {
Matt Porter3cc08dc2006-01-23 15:27:49 +0100377 {
378 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
379 .name = "Input Source",
380 .count = 1,
381 .info = stac92xx_mux_enum_info,
382 .get = stac92xx_mux_enum_get,
383 .put = stac92xx_mux_enum_put,
384 },
385 HDA_CODEC_VOLUME("InMux Capture Volume", 0x15, 0x0, HDA_OUTPUT),
386 HDA_CODEC_VOLUME("InVol Capture Volume", 0x18, 0x0, HDA_INPUT),
387 HDA_CODEC_MUTE("ADCMux Capture Switch", 0x1b, 0x0, HDA_OUTPUT),
388 { } /* end */
389};
390
Takashi Iwaid1d985f2006-11-23 19:27:12 +0100391static struct snd_kcontrol_new stac9205_mixer[] = {
Matt Porterf3302a52006-07-31 12:49:34 +0200392 {
393 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Matt Porter8b657272006-10-26 17:12:59 +0200394 .name = "Digital Input Source",
395 .count = 1,
396 .info = stac92xx_dmux_enum_info,
397 .get = stac92xx_dmux_enum_get,
398 .put = stac92xx_dmux_enum_put,
399 },
400 {
401 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Matt Porterf3302a52006-07-31 12:49:34 +0200402 .name = "Input Source",
403 .count = 1,
404 .info = stac92xx_mux_enum_info,
405 .get = stac92xx_mux_enum_get,
406 .put = stac92xx_mux_enum_put,
407 },
408 HDA_CODEC_VOLUME("InMux Capture Volume", 0x19, 0x0, HDA_OUTPUT),
409 HDA_CODEC_VOLUME("InVol Capture Volume", 0x1b, 0x0, HDA_INPUT),
410 HDA_CODEC_MUTE("ADCMux Capture Switch", 0x1d, 0x0, HDA_OUTPUT),
411 { } /* end */
412};
413
Matt2f2f4252005-04-13 14:45:30 +0200414static int stac92xx_build_controls(struct hda_codec *codec)
415{
416 struct sigmatel_spec *spec = codec->spec;
417 int err;
Mattc7d4b2f2005-06-27 14:59:41 +0200418 int i;
Matt2f2f4252005-04-13 14:45:30 +0200419
420 err = snd_hda_add_new_ctls(codec, spec->mixer);
421 if (err < 0)
422 return err;
Mattc7d4b2f2005-06-27 14:59:41 +0200423
424 for (i = 0; i < spec->num_mixers; i++) {
425 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
426 if (err < 0)
427 return err;
428 }
429
Mattdabbed62005-06-14 10:19:34 +0200430 if (spec->multiout.dig_out_nid) {
431 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
432 if (err < 0)
433 return err;
434 }
435 if (spec->dig_in_nid) {
436 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
437 if (err < 0)
438 return err;
439 }
440 return 0;
Matt2f2f4252005-04-13 14:45:30 +0200441}
442
Matt Porter403d1942005-11-29 15:00:51 +0100443static unsigned int ref9200_pin_configs[8] = {
Mattdabbed62005-06-14 10:19:34 +0200444 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
Matt2f2f4252005-04-13 14:45:30 +0200445 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
446};
447
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100448static unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
449 [STAC_REF] = ref9200_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +0100450};
451
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100452static const char *stac9200_models[STAC_9200_MODELS] = {
453 [STAC_REF] = "ref",
454};
455
456static struct snd_pci_quirk stac9200_cfg_tbl[] = {
457 /* SigmaTel reference board */
458 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
459 "DFI LanParty", STAC_REF),
Matt Portere7377072006-11-06 11:20:38 +0100460 /* Dell laptops have BIOS problem */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100461 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01b5,
462 "Dell Inspiron 630m", STAC_REF),
463 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c2,
464 "Dell Latitude D620", STAC_REF),
465 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cb,
466 "Dell Latitude 120L", STAC_REF),
Cory T. Tusar877b8662007-01-30 17:30:55 +0100467 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cc,
468 "Dell Latitude D820", STAC_REF),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +0100469 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cd,
470 "Dell Inspiron E1705/9400", STAC_REF),
471 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ce,
472 "Dell XPS M1710", STAC_REF),
Takashi Iwaif0f96742007-02-14 00:59:17 +0100473 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cf,
474 "Dell Precision M90", STAC_REF),
Daniel T Chen8286c532007-05-15 11:46:23 +0200475 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d6,
476 "unknown Dell", STAC_REF),
Tobin Davis49c605d2007-05-17 09:38:24 +0200477 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d8,
478 "Dell Inspiron 640m", STAC_REF),
479 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f5,
480 "Dell Inspiron 1501", STAC_REF),
481
482 /* Panasonic */
483 SND_PCI_QUIRK(0x10f7, 0x8338, "Panasonic CF-74", STAC_REF),
484
Matt Porter403d1942005-11-29 15:00:51 +0100485 {} /* terminator */
486};
487
Tobin Davis8e21c342007-01-08 11:04:17 +0100488static unsigned int ref925x_pin_configs[8] = {
489 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
490 0x90a70320, 0x02214210, 0x400003f1, 0x9033032e,
491};
492
493static unsigned int stac925x_MA6_pin_configs[8] = {
494 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
495 0x90a70320, 0x90100211, 0x400003f1, 0x9033032e,
496};
497
Tobin Davis2c11f952007-05-17 09:36:34 +0200498static unsigned int stac925x_PA6_pin_configs[8] = {
499 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
500 0x50a103f0, 0x90100211, 0x400003f1, 0x9033032e,
501};
502
Tobin Davis8e21c342007-01-08 11:04:17 +0100503static unsigned int stac925xM2_2_pin_configs[8] = {
Steve Longerbeam7353e142007-05-29 14:36:17 +0200504 0x40c003f3, 0x424503f2, 0x04180011, 0x02a19020,
505 0x50a103f0, 0x90100212, 0x400003f1, 0x9033032e,
Tobin Davis8e21c342007-01-08 11:04:17 +0100506};
507
508static unsigned int *stac925x_brd_tbl[STAC_925x_MODELS] = {
509 [STAC_REF] = ref925x_pin_configs,
510 [STAC_M2_2] = stac925xM2_2_pin_configs,
511 [STAC_MA6] = stac925x_MA6_pin_configs,
Tobin Davis2c11f952007-05-17 09:36:34 +0200512 [STAC_PA6] = stac925x_PA6_pin_configs,
Tobin Davis8e21c342007-01-08 11:04:17 +0100513};
514
515static const char *stac925x_models[STAC_925x_MODELS] = {
516 [STAC_REF] = "ref",
517 [STAC_M2_2] = "m2-2",
518 [STAC_MA6] = "m6",
Tobin Davis2c11f952007-05-17 09:36:34 +0200519 [STAC_PA6] = "pa6",
Tobin Davis8e21c342007-01-08 11:04:17 +0100520};
521
522static struct snd_pci_quirk stac925x_cfg_tbl[] = {
523 /* SigmaTel reference board */
524 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, "DFI LanParty", STAC_REF),
Tobin Davis2c11f952007-05-17 09:36:34 +0200525 SND_PCI_QUIRK(0x8384, 0x7632, "Stac9202 Reference Board", STAC_REF),
Tobin Davis8e21c342007-01-08 11:04:17 +0100526 SND_PCI_QUIRK(0x107b, 0x0316, "Gateway M255", STAC_REF),
527 SND_PCI_QUIRK(0x107b, 0x0366, "Gateway MP6954", STAC_REF),
528 SND_PCI_QUIRK(0x107b, 0x0461, "Gateway NX560XL", STAC_MA6),
Tobin Davis2c11f952007-05-17 09:36:34 +0200529 SND_PCI_QUIRK(0x107b, 0x0681, "Gateway NX860", STAC_PA6),
Tobin Davis8e21c342007-01-08 11:04:17 +0100530 SND_PCI_QUIRK(0x1002, 0x437b, "Gateway MX6453", STAC_M2_2),
531 {} /* terminator */
532};
533
Matt Porter403d1942005-11-29 15:00:51 +0100534static unsigned int ref922x_pin_configs[10] = {
535 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
536 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
Matt2f2f4252005-04-13 14:45:30 +0200537 0x40000100, 0x40000100,
538};
539
Matt Porter403d1942005-11-29 15:00:51 +0100540static unsigned int d945gtp3_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +0100541 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
Matt Porter403d1942005-11-29 15:00:51 +0100542 0x40000100, 0x40000100, 0x40000100, 0x40000100,
543 0x02a19120, 0x40000100,
544};
545
546static unsigned int d945gtp5_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +0100547 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
548 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
Matt Porter403d1942005-11-29 15:00:51 +0100549 0x02a19320, 0x40000100,
550};
551
Nicolas Boichat6f0778d2007-03-15 12:38:15 +0100552static unsigned int macbook_pro_v1_pin_configs[10] = {
553 0x0321e230, 0x03a1e020, 0x9017e110, 0x01014010,
554 0x01a19021, 0x0381e021, 0x1345e240, 0x13c5e22e,
555 0x02a19320, 0x400000fb
556};
557
558static unsigned int macbook_pro_v2_pin_configs[10] = {
Takashi Iwai3fc24d82007-02-16 13:27:18 +0100559 0x0221401f, 0x90a70120, 0x01813024, 0x01014010,
560 0x400000fd, 0x01016011, 0x1345e240, 0x13c5e22e,
561 0x400000fc, 0x400000fb,
562};
563
Sylvain FORETf16928f2007-04-27 14:22:36 +0200564static unsigned int imac_intel_pin_configs[10] = {
565 0x0121e230, 0x90a70120, 0x9017e110, 0x400000fe,
566 0x400000fd, 0x0181e021, 0x1145e040, 0x400000fa,
567 0x400000fc, 0x400000fb,
568};
569
Takashi Iwai19039bd2006-06-28 15:52:16 +0200570static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100571 [STAC_D945_REF] = ref922x_pin_configs,
Takashi Iwai19039bd2006-06-28 15:52:16 +0200572 [STAC_D945GTP3] = d945gtp3_pin_configs,
573 [STAC_D945GTP5] = d945gtp5_pin_configs,
Takashi Iwai02a50392007-03-19 11:42:18 +0100574 [STAC_MACMINI] = macbook_pro_v1_pin_configs,
575 [STAC_MACBOOK] = macbook_pro_v1_pin_configs,
Nicolas Boichat6f0778d2007-03-15 12:38:15 +0100576 [STAC_MACBOOK_PRO_V1] = macbook_pro_v1_pin_configs,
577 [STAC_MACBOOK_PRO_V2] = macbook_pro_v2_pin_configs,
Sylvain FORETf16928f2007-04-27 14:22:36 +0200578 [STAC_IMAC_INTEL] = imac_intel_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +0100579};
580
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100581static const char *stac922x_models[STAC_922X_MODELS] = {
582 [STAC_D945_REF] = "ref",
583 [STAC_D945GTP5] = "5stack",
584 [STAC_D945GTP3] = "3stack",
585 [STAC_MACMINI] = "macmini",
Takashi Iwai3fc24d82007-02-16 13:27:18 +0100586 [STAC_MACBOOK] = "macbook",
Nicolas Boichat6f0778d2007-03-15 12:38:15 +0100587 [STAC_MACBOOK_PRO_V1] = "macbook-pro-v1",
588 [STAC_MACBOOK_PRO_V2] = "macbook-pro",
Sylvain FORETf16928f2007-04-27 14:22:36 +0200589 [STAC_IMAC_INTEL] = "imac-intel",
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100590};
591
592static struct snd_pci_quirk stac922x_cfg_tbl[] = {
593 /* SigmaTel reference board */
594 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
595 "DFI LanParty", STAC_D945_REF),
596 /* Intel 945G based systems */
597 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101,
598 "Intel D945G", STAC_D945GTP3),
599 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0202,
600 "Intel D945G", STAC_D945GTP3),
601 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0606,
602 "Intel D945G", STAC_D945GTP3),
603 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0601,
604 "Intel D945G", STAC_D945GTP3),
605 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0111,
606 "Intel D945G", STAC_D945GTP3),
607 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1115,
608 "Intel D945G", STAC_D945GTP3),
609 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1116,
610 "Intel D945G", STAC_D945GTP3),
611 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1117,
612 "Intel D945G", STAC_D945GTP3),
613 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1118,
614 "Intel D945G", STAC_D945GTP3),
615 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1119,
616 "Intel D945G", STAC_D945GTP3),
617 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x8826,
618 "Intel D945G", STAC_D945GTP3),
619 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5049,
620 "Intel D945G", STAC_D945GTP3),
621 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5055,
622 "Intel D945G", STAC_D945GTP3),
623 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5048,
624 "Intel D945G", STAC_D945GTP3),
625 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0110,
626 "Intel D945G", STAC_D945GTP3),
627 /* Intel D945G 5-stack systems */
628 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0404,
629 "Intel D945G", STAC_D945GTP5),
630 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0303,
631 "Intel D945G", STAC_D945GTP5),
632 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0013,
633 "Intel D945G", STAC_D945GTP5),
634 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0417,
635 "Intel D945G", STAC_D945GTP5),
636 /* Intel 945P based systems */
637 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0b0b,
638 "Intel D945P", STAC_D945GTP3),
639 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0112,
640 "Intel D945P", STAC_D945GTP3),
641 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0d0d,
642 "Intel D945P", STAC_D945GTP3),
643 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0909,
644 "Intel D945P", STAC_D945GTP3),
645 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0505,
646 "Intel D945P", STAC_D945GTP3),
647 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707,
648 "Intel D945P", STAC_D945GTP5),
649 /* other systems */
650 /* Apple Mac Mini (early 2006) */
651 SND_PCI_QUIRK(0x8384, 0x7680,
652 "Mac Mini", STAC_MACMINI),
Matt Porter403d1942005-11-29 15:00:51 +0100653 {} /* terminator */
654};
655
Matt Porter3cc08dc2006-01-23 15:27:49 +0100656static unsigned int ref927x_pin_configs[14] = {
Tobin Davis93ed1502006-09-01 21:03:12 +0200657 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
658 0x01a19040, 0x01011012, 0x01016011, 0x0101201f,
659 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
660 0x01c42190, 0x40000100,
Matt Porter3cc08dc2006-01-23 15:27:49 +0100661};
662
Tobin Davis93ed1502006-09-01 21:03:12 +0200663static unsigned int d965_3st_pin_configs[14] = {
Tobin Davis81d3dbd2006-08-22 19:44:45 +0200664 0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
665 0x01a19021, 0x01813024, 0x40000100, 0x40000100,
666 0x40000100, 0x40000100, 0x40000100, 0x40000100,
667 0x40000100, 0x40000100
668};
669
Tobin Davis93ed1502006-09-01 21:03:12 +0200670static unsigned int d965_5st_pin_configs[14] = {
671 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
672 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
673 0x40000100, 0x40000100, 0x40000100, 0x01442070,
674 0x40000100, 0x40000100
675};
676
677static unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100678 [STAC_D965_REF] = ref927x_pin_configs,
Tobin Davis93ed1502006-09-01 21:03:12 +0200679 [STAC_D965_3ST] = d965_3st_pin_configs,
680 [STAC_D965_5ST] = d965_5st_pin_configs,
Matt Porter3cc08dc2006-01-23 15:27:49 +0100681};
682
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100683static const char *stac927x_models[STAC_927X_MODELS] = {
684 [STAC_D965_REF] = "ref",
685 [STAC_D965_3ST] = "3stack",
686 [STAC_D965_5ST] = "5stack",
687};
688
689static struct snd_pci_quirk stac927x_cfg_tbl[] = {
690 /* SigmaTel reference board */
691 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
692 "DFI LanParty", STAC_D965_REF),
Tobin Davis81d3dbd2006-08-22 19:44:45 +0200693 /* Intel 946 based systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100694 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST),
695 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST),
Tobin Davis93ed1502006-09-01 21:03:12 +0200696 /* 965 based 3 stack systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100697 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2116, "Intel D965", STAC_D965_3ST),
698 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2115, "Intel D965", STAC_D965_3ST),
699 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2114, "Intel D965", STAC_D965_3ST),
700 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2113, "Intel D965", STAC_D965_3ST),
701 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2112, "Intel D965", STAC_D965_3ST),
702 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2111, "Intel D965", STAC_D965_3ST),
703 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2110, "Intel D965", STAC_D965_3ST),
704 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2009, "Intel D965", STAC_D965_3ST),
705 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2008, "Intel D965", STAC_D965_3ST),
706 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2007, "Intel D965", STAC_D965_3ST),
707 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2006, "Intel D965", STAC_D965_3ST),
708 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2005, "Intel D965", STAC_D965_3ST),
709 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2004, "Intel D965", STAC_D965_3ST),
710 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2003, "Intel D965", STAC_D965_3ST),
711 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2002, "Intel D965", STAC_D965_3ST),
712 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2001, "Intel D965", STAC_D965_3ST),
Tobin Davis93ed1502006-09-01 21:03:12 +0200713 /* 965 based 5 stack systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100714 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2301, "Intel D965", STAC_D965_5ST),
715 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2302, "Intel D965", STAC_D965_5ST),
716 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2303, "Intel D965", STAC_D965_5ST),
717 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2304, "Intel D965", STAC_D965_5ST),
718 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2305, "Intel D965", STAC_D965_5ST),
719 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2501, "Intel D965", STAC_D965_5ST),
720 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2502, "Intel D965", STAC_D965_5ST),
721 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2503, "Intel D965", STAC_D965_5ST),
722 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2504, "Intel D965", STAC_D965_5ST),
Matt Porter3cc08dc2006-01-23 15:27:49 +0100723 {} /* terminator */
724};
725
Matt Porterf3302a52006-07-31 12:49:34 +0200726static unsigned int ref9205_pin_configs[12] = {
727 0x40000100, 0x40000100, 0x01016011, 0x01014010,
Matt Porter8b657272006-10-26 17:12:59 +0200728 0x01813122, 0x01a19021, 0x40000100, 0x40000100,
729 0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
Matt Porterf3302a52006-07-31 12:49:34 +0200730};
731
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100732static unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
Matt Porterf3302a52006-07-31 12:49:34 +0200733 ref9205_pin_configs,
734};
735
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100736static const char *stac9205_models[STAC_9205_MODELS] = {
737 [STAC_9205_REF] = "ref",
738};
739
740static struct snd_pci_quirk stac9205_cfg_tbl[] = {
741 /* SigmaTel reference board */
742 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
743 "DFI LanParty", STAC_9205_REF),
Matt Porterf3302a52006-07-31 12:49:34 +0200744 {} /* terminator */
745};
746
Richard Fish11b44bb2006-08-23 18:31:34 +0200747static int stac92xx_save_bios_config_regs(struct hda_codec *codec)
748{
749 int i;
750 struct sigmatel_spec *spec = codec->spec;
751
752 if (! spec->bios_pin_configs) {
753 spec->bios_pin_configs = kcalloc(spec->num_pins,
754 sizeof(*spec->bios_pin_configs), GFP_KERNEL);
755 if (! spec->bios_pin_configs)
756 return -ENOMEM;
757 }
758
759 for (i = 0; i < spec->num_pins; i++) {
760 hda_nid_t nid = spec->pin_nids[i];
761 unsigned int pin_cfg;
762
763 pin_cfg = snd_hda_codec_read(codec, nid, 0,
764 AC_VERB_GET_CONFIG_DEFAULT, 0x00);
765 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x bios pin config %8.8x\n",
766 nid, pin_cfg);
767 spec->bios_pin_configs[i] = pin_cfg;
768 }
769
770 return 0;
771}
772
Matt2f2f4252005-04-13 14:45:30 +0200773static void stac92xx_set_config_regs(struct hda_codec *codec)
774{
775 int i;
776 struct sigmatel_spec *spec = codec->spec;
777 unsigned int pin_cfg;
778
Richard Fish11b44bb2006-08-23 18:31:34 +0200779 if (! spec->pin_nids || ! spec->pin_configs)
780 return;
781
782 for (i = 0; i < spec->num_pins; i++) {
Matt2f2f4252005-04-13 14:45:30 +0200783 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
784 AC_VERB_SET_CONFIG_DEFAULT_BYTES_0,
785 spec->pin_configs[i] & 0x000000ff);
786 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
787 AC_VERB_SET_CONFIG_DEFAULT_BYTES_1,
788 (spec->pin_configs[i] & 0x0000ff00) >> 8);
789 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
790 AC_VERB_SET_CONFIG_DEFAULT_BYTES_2,
791 (spec->pin_configs[i] & 0x00ff0000) >> 16);
792 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
793 AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
794 spec->pin_configs[i] >> 24);
795 pin_cfg = snd_hda_codec_read(codec, spec->pin_nids[i], 0,
796 AC_VERB_GET_CONFIG_DEFAULT,
797 0x00);
Matt Porter403d1942005-11-29 15:00:51 +0100798 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x pin config %8.8x\n", spec->pin_nids[i], pin_cfg);
Matt2f2f4252005-04-13 14:45:30 +0200799 }
800}
Matt2f2f4252005-04-13 14:45:30 +0200801
Matt2f2f4252005-04-13 14:45:30 +0200802/*
803 * Analog playback callbacks
804 */
805static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
806 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100807 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200808{
809 struct sigmatel_spec *spec = codec->spec;
810 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
811}
812
813static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
814 struct hda_codec *codec,
815 unsigned int stream_tag,
816 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100817 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200818{
819 struct sigmatel_spec *spec = codec->spec;
Matt Porter403d1942005-11-29 15:00:51 +0100820 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
Matt2f2f4252005-04-13 14:45:30 +0200821}
822
823static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
824 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100825 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200826{
827 struct sigmatel_spec *spec = codec->spec;
828 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
829}
830
831/*
Mattdabbed62005-06-14 10:19:34 +0200832 * Digital playback callbacks
833 */
834static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
835 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100836 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +0200837{
838 struct sigmatel_spec *spec = codec->spec;
839 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
840}
841
842static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
843 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100844 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +0200845{
846 struct sigmatel_spec *spec = codec->spec;
847 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
848}
849
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200850static int stac92xx_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
851 struct hda_codec *codec,
852 unsigned int stream_tag,
853 unsigned int format,
854 struct snd_pcm_substream *substream)
855{
856 struct sigmatel_spec *spec = codec->spec;
857 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
858 stream_tag, format, substream);
859}
860
Mattdabbed62005-06-14 10:19:34 +0200861
862/*
Matt2f2f4252005-04-13 14:45:30 +0200863 * Analog capture callbacks
864 */
865static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
866 struct hda_codec *codec,
867 unsigned int stream_tag,
868 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100869 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200870{
871 struct sigmatel_spec *spec = codec->spec;
872
873 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
874 stream_tag, 0, format);
875 return 0;
876}
877
878static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
879 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100880 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200881{
882 struct sigmatel_spec *spec = codec->spec;
883
884 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 0, 0, 0);
885 return 0;
886}
887
Mattdabbed62005-06-14 10:19:34 +0200888static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
889 .substreams = 1,
890 .channels_min = 2,
891 .channels_max = 2,
892 /* NID is set in stac92xx_build_pcms */
893 .ops = {
894 .open = stac92xx_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200895 .close = stac92xx_dig_playback_pcm_close,
896 .prepare = stac92xx_dig_playback_pcm_prepare
Mattdabbed62005-06-14 10:19:34 +0200897 },
898};
899
900static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
901 .substreams = 1,
902 .channels_min = 2,
903 .channels_max = 2,
904 /* NID is set in stac92xx_build_pcms */
905};
906
Matt2f2f4252005-04-13 14:45:30 +0200907static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
908 .substreams = 1,
909 .channels_min = 2,
Mattc7d4b2f2005-06-27 14:59:41 +0200910 .channels_max = 8,
Matt2f2f4252005-04-13 14:45:30 +0200911 .nid = 0x02, /* NID to query formats and rates */
912 .ops = {
913 .open = stac92xx_playback_pcm_open,
914 .prepare = stac92xx_playback_pcm_prepare,
915 .cleanup = stac92xx_playback_pcm_cleanup
916 },
917};
918
Matt Porter3cc08dc2006-01-23 15:27:49 +0100919static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
920 .substreams = 1,
921 .channels_min = 2,
922 .channels_max = 2,
923 .nid = 0x06, /* NID to query formats and rates */
924 .ops = {
925 .open = stac92xx_playback_pcm_open,
926 .prepare = stac92xx_playback_pcm_prepare,
927 .cleanup = stac92xx_playback_pcm_cleanup
928 },
929};
930
Matt2f2f4252005-04-13 14:45:30 +0200931static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
932 .substreams = 2,
933 .channels_min = 2,
934 .channels_max = 2,
Matt Porter3cc08dc2006-01-23 15:27:49 +0100935 /* NID is set in stac92xx_build_pcms */
Matt2f2f4252005-04-13 14:45:30 +0200936 .ops = {
937 .prepare = stac92xx_capture_pcm_prepare,
938 .cleanup = stac92xx_capture_pcm_cleanup
939 },
940};
941
942static int stac92xx_build_pcms(struct hda_codec *codec)
943{
944 struct sigmatel_spec *spec = codec->spec;
945 struct hda_pcm *info = spec->pcm_rec;
946
947 codec->num_pcms = 1;
948 codec->pcm_info = info;
949
Mattc7d4b2f2005-06-27 14:59:41 +0200950 info->name = "STAC92xx Analog";
Matt2f2f4252005-04-13 14:45:30 +0200951 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
Matt2f2f4252005-04-13 14:45:30 +0200952 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100953 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
954
955 if (spec->alt_switch) {
956 codec->num_pcms++;
957 info++;
958 info->name = "STAC92xx Analog Alt";
959 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
960 }
Matt2f2f4252005-04-13 14:45:30 +0200961
Mattdabbed62005-06-14 10:19:34 +0200962 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
963 codec->num_pcms++;
964 info++;
965 info->name = "STAC92xx Digital";
966 if (spec->multiout.dig_out_nid) {
967 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
968 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
969 }
970 if (spec->dig_in_nid) {
971 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
972 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
973 }
974 }
975
Matt2f2f4252005-04-13 14:45:30 +0200976 return 0;
977}
978
Takashi Iwaic960a032006-03-23 17:06:28 +0100979static unsigned int stac92xx_get_vref(struct hda_codec *codec, hda_nid_t nid)
980{
981 unsigned int pincap = snd_hda_param_read(codec, nid,
982 AC_PAR_PIN_CAP);
983 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
984 if (pincap & AC_PINCAP_VREF_100)
985 return AC_PINCTL_VREF_100;
986 if (pincap & AC_PINCAP_VREF_80)
987 return AC_PINCTL_VREF_80;
988 if (pincap & AC_PINCAP_VREF_50)
989 return AC_PINCTL_VREF_50;
990 if (pincap & AC_PINCAP_VREF_GRD)
991 return AC_PINCTL_VREF_GRD;
992 return 0;
993}
994
Matt Porter403d1942005-11-29 15:00:51 +0100995static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
996
997{
998 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
999}
1000
1001static int stac92xx_io_switch_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1002{
1003 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1004 uinfo->count = 1;
1005 uinfo->value.integer.min = 0;
1006 uinfo->value.integer.max = 1;
1007 return 0;
1008}
1009
1010static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1011{
1012 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1013 struct sigmatel_spec *spec = codec->spec;
1014 int io_idx = kcontrol-> private_value & 0xff;
1015
1016 ucontrol->value.integer.value[0] = spec->io_switch[io_idx];
1017 return 0;
1018}
1019
1020static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1021{
1022 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1023 struct sigmatel_spec *spec = codec->spec;
1024 hda_nid_t nid = kcontrol->private_value >> 8;
1025 int io_idx = kcontrol-> private_value & 0xff;
1026 unsigned short val = ucontrol->value.integer.value[0];
1027
1028 spec->io_switch[io_idx] = val;
1029
1030 if (val)
1031 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
Takashi Iwaic960a032006-03-23 17:06:28 +01001032 else {
1033 unsigned int pinctl = AC_PINCTL_IN_EN;
1034 if (io_idx) /* set VREF for mic */
1035 pinctl |= stac92xx_get_vref(codec, nid);
1036 stac92xx_auto_set_pinctl(codec, nid, pinctl);
1037 }
Matt Porter403d1942005-11-29 15:00:51 +01001038 return 1;
1039}
1040
1041#define STAC_CODEC_IO_SWITCH(xname, xpval) \
1042 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1043 .name = xname, \
1044 .index = 0, \
1045 .info = stac92xx_io_switch_info, \
1046 .get = stac92xx_io_switch_get, \
1047 .put = stac92xx_io_switch_put, \
1048 .private_value = xpval, \
1049 }
1050
1051
Mattc7d4b2f2005-06-27 14:59:41 +02001052enum {
1053 STAC_CTL_WIDGET_VOL,
1054 STAC_CTL_WIDGET_MUTE,
Matt Porter403d1942005-11-29 15:00:51 +01001055 STAC_CTL_WIDGET_IO_SWITCH,
Mattc7d4b2f2005-06-27 14:59:41 +02001056};
1057
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001058static struct snd_kcontrol_new stac92xx_control_templates[] = {
Mattc7d4b2f2005-06-27 14:59:41 +02001059 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
1060 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Matt Porter403d1942005-11-29 15:00:51 +01001061 STAC_CODEC_IO_SWITCH(NULL, 0),
Mattc7d4b2f2005-06-27 14:59:41 +02001062};
1063
1064/* add dynamic controls */
1065static int stac92xx_add_control(struct sigmatel_spec *spec, int type, const char *name, unsigned long val)
1066{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001067 struct snd_kcontrol_new *knew;
Mattc7d4b2f2005-06-27 14:59:41 +02001068
1069 if (spec->num_kctl_used >= spec->num_kctl_alloc) {
1070 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
1071
1072 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */
1073 if (! knew)
1074 return -ENOMEM;
1075 if (spec->kctl_alloc) {
1076 memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
1077 kfree(spec->kctl_alloc);
1078 }
1079 spec->kctl_alloc = knew;
1080 spec->num_kctl_alloc = num;
1081 }
1082
1083 knew = &spec->kctl_alloc[spec->num_kctl_used];
1084 *knew = stac92xx_control_templates[type];
Takashi Iwai82fe0c52005-06-30 10:54:33 +02001085 knew->name = kstrdup(name, GFP_KERNEL);
Mattc7d4b2f2005-06-27 14:59:41 +02001086 if (! knew->name)
1087 return -ENOMEM;
1088 knew->private_value = val;
1089 spec->num_kctl_used++;
1090 return 0;
1091}
1092
Matt Porter403d1942005-11-29 15:00:51 +01001093/* flag inputs as additional dynamic lineouts */
1094static int stac92xx_add_dyn_out_pins(struct hda_codec *codec, struct auto_pin_cfg *cfg)
1095{
1096 struct sigmatel_spec *spec = codec->spec;
Steve Longerbeam7b043892007-05-03 20:50:03 +02001097 unsigned int wcaps, wtype;
1098 int i, num_dacs = 0;
1099
1100 /* use the wcaps cache to count all DACs available for line-outs */
1101 for (i = 0; i < codec->num_nodes; i++) {
1102 wcaps = codec->wcaps[i];
1103 wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
1104 if (wtype == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL))
1105 num_dacs++;
1106 }
Matt Porter403d1942005-11-29 15:00:51 +01001107
Steve Longerbeam7b043892007-05-03 20:50:03 +02001108 snd_printdd("%s: total dac count=%d\n", __func__, num_dacs);
1109
Matt Porter403d1942005-11-29 15:00:51 +01001110 switch (cfg->line_outs) {
1111 case 3:
1112 /* add line-in as side */
Steve Longerbeam7b043892007-05-03 20:50:03 +02001113 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 3) {
Matt Porter403d1942005-11-29 15:00:51 +01001114 cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_LINE];
1115 spec->line_switch = 1;
1116 cfg->line_outs++;
1117 }
1118 break;
1119 case 2:
1120 /* add line-in as clfe and mic as side */
Steve Longerbeam7b043892007-05-03 20:50:03 +02001121 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 2) {
Matt Porter403d1942005-11-29 15:00:51 +01001122 cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_LINE];
1123 spec->line_switch = 1;
1124 cfg->line_outs++;
1125 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02001126 if (cfg->input_pins[AUTO_PIN_MIC] && num_dacs > 3) {
Matt Porter403d1942005-11-29 15:00:51 +01001127 cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_MIC];
1128 spec->mic_switch = 1;
1129 cfg->line_outs++;
1130 }
1131 break;
1132 case 1:
1133 /* add line-in as surr and mic as clfe */
Steve Longerbeam7b043892007-05-03 20:50:03 +02001134 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 1) {
Matt Porter403d1942005-11-29 15:00:51 +01001135 cfg->line_out_pins[1] = cfg->input_pins[AUTO_PIN_LINE];
1136 spec->line_switch = 1;
1137 cfg->line_outs++;
1138 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02001139 if (cfg->input_pins[AUTO_PIN_MIC] && num_dacs > 2) {
Matt Porter403d1942005-11-29 15:00:51 +01001140 cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_MIC];
1141 spec->mic_switch = 1;
1142 cfg->line_outs++;
1143 }
1144 break;
1145 }
1146
1147 return 0;
1148}
1149
Steve Longerbeam7b043892007-05-03 20:50:03 +02001150
1151static int is_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
1152{
1153 int i;
1154
1155 for (i = 0; i < spec->multiout.num_dacs; i++) {
1156 if (spec->multiout.dac_nids[i] == nid)
1157 return 1;
1158 }
1159
1160 return 0;
1161}
1162
Matt Porter3cc08dc2006-01-23 15:27:49 +01001163/*
Steve Longerbeam7b043892007-05-03 20:50:03 +02001164 * Fill in the dac_nids table from the parsed pin configuration
1165 * This function only works when every pin in line_out_pins[]
1166 * contains atleast one DAC in its connection list. Some 92xx
1167 * codecs are not connected directly to a DAC, such as the 9200
1168 * and 9202/925x. For those, dac_nids[] must be hard-coded.
Matt Porter3cc08dc2006-01-23 15:27:49 +01001169 */
Takashi Iwai19039bd2006-06-28 15:52:16 +02001170static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec,
1171 const struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02001172{
1173 struct sigmatel_spec *spec = codec->spec;
Steve Longerbeam7b043892007-05-03 20:50:03 +02001174 int i, j, conn_len = 0;
1175 hda_nid_t nid, conn[HDA_MAX_CONNECTIONS];
1176 unsigned int wcaps, wtype;
1177
Mattc7d4b2f2005-06-27 14:59:41 +02001178 for (i = 0; i < cfg->line_outs; i++) {
1179 nid = cfg->line_out_pins[i];
Steve Longerbeam7b043892007-05-03 20:50:03 +02001180 conn_len = snd_hda_get_connections(codec, nid, conn,
1181 HDA_MAX_CONNECTIONS);
1182 for (j = 0; j < conn_len; j++) {
1183 wcaps = snd_hda_param_read(codec, conn[j],
1184 AC_PAR_AUDIO_WIDGET_CAP);
1185 wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
1186
1187 if (wtype != AC_WID_AUD_OUT ||
1188 (wcaps & AC_WCAP_DIGITAL))
1189 continue;
1190 /* conn[j] is a DAC routed to this line-out */
1191 if (!is_in_dac_nids(spec, conn[j]))
1192 break;
1193 }
1194
1195 if (j == conn_len) {
1196 /* error out, no available DAC found */
1197 snd_printk(KERN_ERR
1198 "%s: No available DAC for pin 0x%x\n",
1199 __func__, nid);
1200 return -ENODEV;
1201 }
1202
1203 spec->multiout.dac_nids[i] = conn[j];
1204 spec->multiout.num_dacs++;
1205 if (conn_len > 1) {
1206 /* select this DAC in the pin's input mux */
1207 snd_hda_codec_write(codec, nid, 0,
1208 AC_VERB_SET_CONNECT_SEL, j);
1209
1210 }
Mattc7d4b2f2005-06-27 14:59:41 +02001211 }
1212
Steve Longerbeam7b043892007-05-03 20:50:03 +02001213 snd_printd("dac_nids=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
1214 spec->multiout.num_dacs,
1215 spec->multiout.dac_nids[0],
1216 spec->multiout.dac_nids[1],
1217 spec->multiout.dac_nids[2],
1218 spec->multiout.dac_nids[3],
1219 spec->multiout.dac_nids[4]);
Mattc7d4b2f2005-06-27 14:59:41 +02001220 return 0;
1221}
1222
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001223/* create volume control/switch for the given prefx type */
1224static int create_controls(struct sigmatel_spec *spec, const char *pfx, hda_nid_t nid, int chs)
1225{
1226 char name[32];
1227 int err;
1228
1229 sprintf(name, "%s Playback Volume", pfx);
1230 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, name,
1231 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1232 if (err < 0)
1233 return err;
1234 sprintf(name, "%s Playback Switch", pfx);
1235 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, name,
1236 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1237 if (err < 0)
1238 return err;
1239 return 0;
1240}
1241
Mattc7d4b2f2005-06-27 14:59:41 +02001242/* add playback controls from the parsed DAC table */
Takashi Iwai19039bd2006-06-28 15:52:16 +02001243static int stac92xx_auto_create_multi_out_ctls(struct sigmatel_spec *spec,
1244 const struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02001245{
Takashi Iwai19039bd2006-06-28 15:52:16 +02001246 static const char *chname[4] = {
1247 "Front", "Surround", NULL /*CLFE*/, "Side"
1248 };
Mattc7d4b2f2005-06-27 14:59:41 +02001249 hda_nid_t nid;
1250 int i, err;
1251
1252 for (i = 0; i < cfg->line_outs; i++) {
Matt Porter403d1942005-11-29 15:00:51 +01001253 if (!spec->multiout.dac_nids[i])
Mattc7d4b2f2005-06-27 14:59:41 +02001254 continue;
1255
1256 nid = spec->multiout.dac_nids[i];
1257
1258 if (i == 2) {
1259 /* Center/LFE */
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001260 err = create_controls(spec, "Center", nid, 1);
1261 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001262 return err;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001263 err = create_controls(spec, "LFE", nid, 2);
1264 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001265 return err;
1266 } else {
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001267 err = create_controls(spec, chname[i], nid, 3);
1268 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001269 return err;
1270 }
1271 }
1272
Matt Porter403d1942005-11-29 15:00:51 +01001273 if (spec->line_switch)
1274 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Line In as Output Switch", cfg->input_pins[AUTO_PIN_LINE] << 8)) < 0)
1275 return err;
1276
1277 if (spec->mic_switch)
1278 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Mic as Output Switch", (cfg->input_pins[AUTO_PIN_MIC] << 8) | 1)) < 0)
1279 return err;
1280
Mattc7d4b2f2005-06-27 14:59:41 +02001281 return 0;
1282}
1283
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001284static int check_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
1285{
Steve Longerbeam7b043892007-05-03 20:50:03 +02001286 if (is_in_dac_nids(spec, nid))
1287 return 1;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001288 if (spec->multiout.hp_nid == nid)
1289 return 1;
1290 return 0;
1291}
1292
1293static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
1294{
1295 if (!spec->multiout.hp_nid)
1296 spec->multiout.hp_nid = nid;
1297 else if (spec->multiout.num_dacs > 4) {
1298 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
1299 return 1;
1300 } else {
1301 spec->multiout.dac_nids[spec->multiout.num_dacs] = nid;
1302 spec->multiout.num_dacs++;
1303 }
1304 return 0;
1305}
1306
1307/* add playback controls for Speaker and HP outputs */
1308static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
1309 struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02001310{
1311 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02001312 hda_nid_t nid;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001313 int i, old_num_dacs, err;
Mattc7d4b2f2005-06-27 14:59:41 +02001314
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001315 old_num_dacs = spec->multiout.num_dacs;
1316 for (i = 0; i < cfg->hp_outs; i++) {
1317 unsigned int wid_caps = get_wcaps(codec, cfg->hp_pins[i]);
1318 if (wid_caps & AC_WCAP_UNSOL_CAP)
1319 spec->hp_detect = 1;
1320 nid = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
1321 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
1322 if (check_in_dac_nids(spec, nid))
1323 nid = 0;
1324 if (! nid)
Mattc7d4b2f2005-06-27 14:59:41 +02001325 continue;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001326 add_spec_dacs(spec, nid);
1327 }
1328 for (i = 0; i < cfg->speaker_outs; i++) {
Steve Longerbeam7b043892007-05-03 20:50:03 +02001329 nid = snd_hda_codec_read(codec, cfg->speaker_pins[i], 0,
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001330 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
1331 if (check_in_dac_nids(spec, nid))
1332 nid = 0;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001333 if (! nid)
1334 continue;
1335 add_spec_dacs(spec, nid);
Mattc7d4b2f2005-06-27 14:59:41 +02001336 }
1337
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001338 for (i = old_num_dacs; i < spec->multiout.num_dacs; i++) {
1339 static const char *pfxs[] = {
1340 "Speaker", "External Speaker", "Speaker2",
1341 };
1342 err = create_controls(spec, pfxs[i - old_num_dacs],
1343 spec->multiout.dac_nids[i], 3);
1344 if (err < 0)
1345 return err;
1346 }
1347 if (spec->multiout.hp_nid) {
1348 const char *pfx;
1349 if (old_num_dacs == spec->multiout.num_dacs)
1350 pfx = "Master";
1351 else
1352 pfx = "Headphone";
1353 err = create_controls(spec, pfx, spec->multiout.hp_nid, 3);
1354 if (err < 0)
1355 return err;
1356 }
Mattc7d4b2f2005-06-27 14:59:41 +02001357
1358 return 0;
1359}
1360
Matt Porter8b657272006-10-26 17:12:59 +02001361/* labels for dmic mux inputs */
Adrian Bunkddc2cec2006-11-20 12:03:44 +01001362static const char *stac92xx_dmic_labels[5] = {
Matt Porter8b657272006-10-26 17:12:59 +02001363 "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
1364 "Digital Mic 3", "Digital Mic 4"
1365};
1366
1367/* create playback/capture controls for input pins on dmic capable codecs */
1368static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
1369 const struct auto_pin_cfg *cfg)
1370{
1371 struct sigmatel_spec *spec = codec->spec;
1372 struct hda_input_mux *dimux = &spec->private_dimux;
1373 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
1374 int i, j;
1375
1376 dimux->items[dimux->num_items].label = stac92xx_dmic_labels[0];
1377 dimux->items[dimux->num_items].index = 0;
1378 dimux->num_items++;
1379
1380 for (i = 0; i < spec->num_dmics; i++) {
1381 int index;
1382 int num_cons;
1383 unsigned int def_conf;
1384
1385 def_conf = snd_hda_codec_read(codec,
1386 spec->dmic_nids[i],
1387 0,
1388 AC_VERB_GET_CONFIG_DEFAULT,
1389 0);
1390 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
1391 continue;
1392
1393 num_cons = snd_hda_get_connections(codec,
1394 spec->dmux_nid,
1395 con_lst,
1396 HDA_MAX_NUM_INPUTS);
1397 for (j = 0; j < num_cons; j++)
1398 if (con_lst[j] == spec->dmic_nids[i]) {
1399 index = j;
1400 goto found;
1401 }
1402 continue;
1403found:
1404 dimux->items[dimux->num_items].label =
1405 stac92xx_dmic_labels[dimux->num_items];
1406 dimux->items[dimux->num_items].index = index;
1407 dimux->num_items++;
1408 }
1409
1410 return 0;
1411}
1412
Mattc7d4b2f2005-06-27 14:59:41 +02001413/* create playback/capture controls for input pins */
1414static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
1415{
1416 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02001417 struct hda_input_mux *imux = &spec->private_imux;
1418 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
1419 int i, j, k;
1420
1421 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwai314634b2006-09-21 11:56:18 +02001422 int index;
Mattc7d4b2f2005-06-27 14:59:41 +02001423
Takashi Iwai314634b2006-09-21 11:56:18 +02001424 if (!cfg->input_pins[i])
1425 continue;
1426 index = -1;
1427 for (j = 0; j < spec->num_muxes; j++) {
1428 int num_cons;
1429 num_cons = snd_hda_get_connections(codec,
1430 spec->mux_nids[j],
1431 con_lst,
1432 HDA_MAX_NUM_INPUTS);
1433 for (k = 0; k < num_cons; k++)
1434 if (con_lst[k] == cfg->input_pins[i]) {
1435 index = k;
1436 goto found;
1437 }
Mattc7d4b2f2005-06-27 14:59:41 +02001438 }
Takashi Iwai314634b2006-09-21 11:56:18 +02001439 continue;
1440 found:
1441 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
1442 imux->items[imux->num_items].index = index;
1443 imux->num_items++;
Mattc7d4b2f2005-06-27 14:59:41 +02001444 }
1445
Steve Longerbeam7b043892007-05-03 20:50:03 +02001446 if (imux->num_items) {
Sam Revitch62fe78e2006-05-10 15:09:17 +02001447 /*
1448 * Set the current input for the muxes.
1449 * The STAC9221 has two input muxes with identical source
1450 * NID lists. Hopefully this won't get confused.
1451 */
1452 for (i = 0; i < spec->num_muxes; i++) {
1453 snd_hda_codec_write(codec, spec->mux_nids[i], 0,
1454 AC_VERB_SET_CONNECT_SEL,
1455 imux->items[0].index);
1456 }
1457 }
1458
Mattc7d4b2f2005-06-27 14:59:41 +02001459 return 0;
1460}
1461
Mattc7d4b2f2005-06-27 14:59:41 +02001462static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
1463{
1464 struct sigmatel_spec *spec = codec->spec;
1465 int i;
1466
1467 for (i = 0; i < spec->autocfg.line_outs; i++) {
1468 hda_nid_t nid = spec->autocfg.line_out_pins[i];
1469 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
1470 }
1471}
1472
1473static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
1474{
1475 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001476 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02001477
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001478 for (i = 0; i < spec->autocfg.hp_outs; i++) {
1479 hda_nid_t pin;
1480 pin = spec->autocfg.hp_pins[i];
1481 if (pin) /* connect to front */
1482 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
1483 }
1484 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
1485 hda_nid_t pin;
1486 pin = spec->autocfg.speaker_pins[i];
1487 if (pin) /* connect to front */
1488 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
1489 }
Mattc7d4b2f2005-06-27 14:59:41 +02001490}
1491
Matt Porter3cc08dc2006-01-23 15:27:49 +01001492static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out, hda_nid_t dig_in)
Mattc7d4b2f2005-06-27 14:59:41 +02001493{
1494 struct sigmatel_spec *spec = codec->spec;
1495 int err;
1496
Matt Porter8b657272006-10-26 17:12:59 +02001497 if ((err = snd_hda_parse_pin_def_config(codec,
1498 &spec->autocfg,
1499 spec->dmic_nids)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001500 return err;
Takashi Iwai82bc9552006-03-21 11:24:42 +01001501 if (! spec->autocfg.line_outs)
Matt Porter869264c2006-01-25 19:20:50 +01001502 return 0; /* can't find valid pin config */
Takashi Iwai19039bd2006-06-28 15:52:16 +02001503
Matt Porter403d1942005-11-29 15:00:51 +01001504 if ((err = stac92xx_add_dyn_out_pins(codec, &spec->autocfg)) < 0)
1505 return err;
Takashi Iwai19039bd2006-06-28 15:52:16 +02001506 if (spec->multiout.num_dacs == 0)
1507 if ((err = stac92xx_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
1508 return err;
Mattc7d4b2f2005-06-27 14:59:41 +02001509
1510 if ((err = stac92xx_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
1511 (err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg)) < 0 ||
1512 (err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
1513 return err;
1514
Matt Porter8b657272006-10-26 17:12:59 +02001515 if (spec->num_dmics > 0)
1516 if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
1517 &spec->autocfg)) < 0)
1518 return err;
1519
Mattc7d4b2f2005-06-27 14:59:41 +02001520 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Matt Porter403d1942005-11-29 15:00:51 +01001521 if (spec->multiout.max_channels > 2)
Mattc7d4b2f2005-06-27 14:59:41 +02001522 spec->surr_switch = 1;
Mattc7d4b2f2005-06-27 14:59:41 +02001523
Takashi Iwai82bc9552006-03-21 11:24:42 +01001524 if (spec->autocfg.dig_out_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01001525 spec->multiout.dig_out_nid = dig_out;
Takashi Iwai82bc9552006-03-21 11:24:42 +01001526 if (spec->autocfg.dig_in_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01001527 spec->dig_in_nid = dig_in;
Mattc7d4b2f2005-06-27 14:59:41 +02001528
1529 if (spec->kctl_alloc)
1530 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
1531
1532 spec->input_mux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02001533 spec->dinput_mux = &spec->private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +02001534
1535 return 1;
1536}
1537
Takashi Iwai82bc9552006-03-21 11:24:42 +01001538/* add playback controls for HP output */
1539static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
1540 struct auto_pin_cfg *cfg)
1541{
1542 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001543 hda_nid_t pin = cfg->hp_pins[0];
Takashi Iwai82bc9552006-03-21 11:24:42 +01001544 unsigned int wid_caps;
1545
1546 if (! pin)
1547 return 0;
1548
1549 wid_caps = get_wcaps(codec, pin);
Takashi Iwai505cb342006-03-27 12:51:52 +02001550 if (wid_caps & AC_WCAP_UNSOL_CAP)
Takashi Iwai82bc9552006-03-21 11:24:42 +01001551 spec->hp_detect = 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +01001552
1553 return 0;
1554}
1555
Richard Fish160ea0d2006-09-06 13:58:25 +02001556/* add playback controls for LFE output */
1557static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
1558 struct auto_pin_cfg *cfg)
1559{
1560 struct sigmatel_spec *spec = codec->spec;
1561 int err;
1562 hda_nid_t lfe_pin = 0x0;
1563 int i;
1564
1565 /*
1566 * search speaker outs and line outs for a mono speaker pin
1567 * with an amp. If one is found, add LFE controls
1568 * for it.
1569 */
1570 for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
1571 hda_nid_t pin = spec->autocfg.speaker_pins[i];
1572 unsigned long wcaps = get_wcaps(codec, pin);
1573 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
1574 if (wcaps == AC_WCAP_OUT_AMP)
1575 /* found a mono speaker with an amp, must be lfe */
1576 lfe_pin = pin;
1577 }
1578
1579 /* if speaker_outs is 0, then speakers may be in line_outs */
1580 if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
1581 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
1582 hda_nid_t pin = spec->autocfg.line_out_pins[i];
1583 unsigned long cfg;
1584 cfg = snd_hda_codec_read(codec, pin, 0,
1585 AC_VERB_GET_CONFIG_DEFAULT,
1586 0x00);
1587 if (get_defcfg_device(cfg) == AC_JACK_SPEAKER) {
1588 unsigned long wcaps = get_wcaps(codec, pin);
1589 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
1590 if (wcaps == AC_WCAP_OUT_AMP)
1591 /* found a mono speaker with an amp,
1592 must be lfe */
1593 lfe_pin = pin;
1594 }
1595 }
1596 }
1597
1598 if (lfe_pin) {
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001599 err = create_controls(spec, "LFE", lfe_pin, 1);
Richard Fish160ea0d2006-09-06 13:58:25 +02001600 if (err < 0)
1601 return err;
1602 }
1603
1604 return 0;
1605}
1606
Mattc7d4b2f2005-06-27 14:59:41 +02001607static int stac9200_parse_auto_config(struct hda_codec *codec)
1608{
1609 struct sigmatel_spec *spec = codec->spec;
1610 int err;
1611
Kailang Yangdf694da2005-12-05 19:42:22 +01001612 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001613 return err;
1614
1615 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
1616 return err;
1617
Takashi Iwai82bc9552006-03-21 11:24:42 +01001618 if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
1619 return err;
1620
Richard Fish160ea0d2006-09-06 13:58:25 +02001621 if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
1622 return err;
1623
Takashi Iwai82bc9552006-03-21 11:24:42 +01001624 if (spec->autocfg.dig_out_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02001625 spec->multiout.dig_out_nid = 0x05;
Takashi Iwai82bc9552006-03-21 11:24:42 +01001626 if (spec->autocfg.dig_in_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02001627 spec->dig_in_nid = 0x04;
Mattc7d4b2f2005-06-27 14:59:41 +02001628
1629 if (spec->kctl_alloc)
1630 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
1631
1632 spec->input_mux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02001633 spec->dinput_mux = &spec->private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +02001634
1635 return 1;
1636}
1637
Sam Revitch62fe78e2006-05-10 15:09:17 +02001638/*
1639 * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
1640 * funky external mute control using GPIO pins.
1641 */
1642
1643static void stac922x_gpio_mute(struct hda_codec *codec, int pin, int muted)
1644{
1645 unsigned int gpiostate, gpiomask, gpiodir;
1646
1647 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
1648 AC_VERB_GET_GPIO_DATA, 0);
1649
1650 if (!muted)
1651 gpiostate |= (1 << pin);
1652 else
1653 gpiostate &= ~(1 << pin);
1654
1655 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
1656 AC_VERB_GET_GPIO_MASK, 0);
1657 gpiomask |= (1 << pin);
1658
1659 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
1660 AC_VERB_GET_GPIO_DIRECTION, 0);
1661 gpiodir |= (1 << pin);
1662
1663 /* AppleHDA seems to do this -- WTF is this verb?? */
1664 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
1665
1666 snd_hda_codec_write(codec, codec->afg, 0,
1667 AC_VERB_SET_GPIO_MASK, gpiomask);
1668 snd_hda_codec_write(codec, codec->afg, 0,
1669 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
1670
1671 msleep(1);
1672
1673 snd_hda_codec_write(codec, codec->afg, 0,
1674 AC_VERB_SET_GPIO_DATA, gpiostate);
1675}
1676
Takashi Iwai314634b2006-09-21 11:56:18 +02001677static void enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
1678 unsigned int event)
1679{
1680 if (get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP)
1681 snd_hda_codec_write(codec, nid, 0,
1682 AC_VERB_SET_UNSOLICITED_ENABLE,
1683 (AC_USRSP_EN | event));
1684}
1685
Mattc7d4b2f2005-06-27 14:59:41 +02001686static int stac92xx_init(struct hda_codec *codec)
1687{
1688 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai82bc9552006-03-21 11:24:42 +01001689 struct auto_pin_cfg *cfg = &spec->autocfg;
1690 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02001691
Mattc7d4b2f2005-06-27 14:59:41 +02001692 snd_hda_sequence_write(codec, spec->init);
1693
Takashi Iwai82bc9552006-03-21 11:24:42 +01001694 /* set up pins */
1695 if (spec->hp_detect) {
Takashi Iwai505cb342006-03-27 12:51:52 +02001696 /* Enable unsolicited responses on the HP widget */
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001697 for (i = 0; i < cfg->hp_outs; i++)
Takashi Iwai314634b2006-09-21 11:56:18 +02001698 enable_pin_detect(codec, cfg->hp_pins[i],
1699 STAC_HP_EVENT);
Takashi Iwai0a07acaf2007-03-13 10:40:23 +01001700 /* force to enable the first line-out; the others are set up
1701 * in unsol_event
1702 */
1703 stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
1704 AC_PINCTL_OUT_EN);
Takashi Iwaieb995a82006-09-21 14:28:21 +02001705 stac92xx_auto_init_hp_out(codec);
Takashi Iwai82bc9552006-03-21 11:24:42 +01001706 /* fake event to set up pins */
1707 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
1708 } else {
1709 stac92xx_auto_init_multi_out(codec);
1710 stac92xx_auto_init_hp_out(codec);
1711 }
1712 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwaic960a032006-03-23 17:06:28 +01001713 hda_nid_t nid = cfg->input_pins[i];
1714 if (nid) {
1715 unsigned int pinctl = AC_PINCTL_IN_EN;
1716 if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC)
1717 pinctl |= stac92xx_get_vref(codec, nid);
1718 stac92xx_auto_set_pinctl(codec, nid, pinctl);
1719 }
Takashi Iwai82bc9552006-03-21 11:24:42 +01001720 }
Matt Porter8b657272006-10-26 17:12:59 +02001721 if (spec->num_dmics > 0)
1722 for (i = 0; i < spec->num_dmics; i++)
1723 stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
1724 AC_PINCTL_IN_EN);
1725
Takashi Iwai82bc9552006-03-21 11:24:42 +01001726 if (cfg->dig_out_pin)
1727 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pin,
1728 AC_PINCTL_OUT_EN);
1729 if (cfg->dig_in_pin)
1730 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
1731 AC_PINCTL_IN_EN);
1732
Sam Revitch62fe78e2006-05-10 15:09:17 +02001733 if (spec->gpio_mute) {
1734 stac922x_gpio_mute(codec, 0, 0);
1735 stac922x_gpio_mute(codec, 1, 0);
1736 }
1737
Mattc7d4b2f2005-06-27 14:59:41 +02001738 return 0;
1739}
1740
Matt2f2f4252005-04-13 14:45:30 +02001741static void stac92xx_free(struct hda_codec *codec)
1742{
Mattc7d4b2f2005-06-27 14:59:41 +02001743 struct sigmatel_spec *spec = codec->spec;
1744 int i;
1745
1746 if (! spec)
1747 return;
1748
1749 if (spec->kctl_alloc) {
1750 for (i = 0; i < spec->num_kctl_used; i++)
1751 kfree(spec->kctl_alloc[i].name);
1752 kfree(spec->kctl_alloc);
1753 }
1754
Richard Fish11b44bb2006-08-23 18:31:34 +02001755 if (spec->bios_pin_configs)
1756 kfree(spec->bios_pin_configs);
1757
Mattc7d4b2f2005-06-27 14:59:41 +02001758 kfree(spec);
Matt2f2f4252005-04-13 14:45:30 +02001759}
1760
Matt4e550962005-07-04 17:51:39 +02001761static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
1762 unsigned int flag)
1763{
1764 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
1765 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Steve Longerbeam7b043892007-05-03 20:50:03 +02001766
1767 /* if setting pin direction bits, clear the current
1768 direction bits first */
1769 if (flag & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))
1770 pin_ctl &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
1771
Matt4e550962005-07-04 17:51:39 +02001772 snd_hda_codec_write(codec, nid, 0,
1773 AC_VERB_SET_PIN_WIDGET_CONTROL,
1774 pin_ctl | flag);
1775}
1776
1777static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
1778 unsigned int flag)
1779{
1780 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
1781 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
1782 snd_hda_codec_write(codec, nid, 0,
1783 AC_VERB_SET_PIN_WIDGET_CONTROL,
1784 pin_ctl & ~flag);
1785}
1786
Takashi Iwai314634b2006-09-21 11:56:18 +02001787static int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
1788{
1789 if (!nid)
1790 return 0;
1791 if (snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PIN_SENSE, 0x00)
1792 & (1 << 31))
1793 return 1;
1794 return 0;
1795}
1796
1797static void stac92xx_hp_detect(struct hda_codec *codec, unsigned int res)
Matt4e550962005-07-04 17:51:39 +02001798{
1799 struct sigmatel_spec *spec = codec->spec;
1800 struct auto_pin_cfg *cfg = &spec->autocfg;
1801 int i, presence;
1802
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001803 presence = 0;
1804 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai314634b2006-09-21 11:56:18 +02001805 presence = get_pin_presence(codec, cfg->hp_pins[i]);
1806 if (presence)
1807 break;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001808 }
Matt4e550962005-07-04 17:51:39 +02001809
1810 if (presence) {
1811 /* disable lineouts, enable hp */
1812 for (i = 0; i < cfg->line_outs; i++)
1813 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
1814 AC_PINCTL_OUT_EN);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001815 for (i = 0; i < cfg->speaker_outs; i++)
1816 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
1817 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02001818 } else {
1819 /* enable lineouts, disable hp */
1820 for (i = 0; i < cfg->line_outs; i++)
1821 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
1822 AC_PINCTL_OUT_EN);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001823 for (i = 0; i < cfg->speaker_outs; i++)
1824 stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
1825 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02001826 }
1827}
1828
Takashi Iwai314634b2006-09-21 11:56:18 +02001829static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
1830{
1831 switch (res >> 26) {
1832 case STAC_HP_EVENT:
1833 stac92xx_hp_detect(codec, res);
1834 break;
1835 }
1836}
1837
Mattff6fdc32005-06-27 15:06:52 +02001838#ifdef CONFIG_PM
1839static int stac92xx_resume(struct hda_codec *codec)
1840{
1841 struct sigmatel_spec *spec = codec->spec;
1842 int i;
1843
1844 stac92xx_init(codec);
Richard Fish11b44bb2006-08-23 18:31:34 +02001845 stac92xx_set_config_regs(codec);
Takashi Iwai5d403b12007-05-03 12:32:29 +02001846 snd_hda_resume_ctls(codec, spec->mixer);
Mattff6fdc32005-06-27 15:06:52 +02001847 for (i = 0; i < spec->num_mixers; i++)
1848 snd_hda_resume_ctls(codec, spec->mixers[i]);
1849 if (spec->multiout.dig_out_nid)
1850 snd_hda_resume_spdif_out(codec);
1851 if (spec->dig_in_nid)
1852 snd_hda_resume_spdif_in(codec);
1853
1854 return 0;
1855}
1856#endif
1857
Matt2f2f4252005-04-13 14:45:30 +02001858static struct hda_codec_ops stac92xx_patch_ops = {
1859 .build_controls = stac92xx_build_controls,
1860 .build_pcms = stac92xx_build_pcms,
1861 .init = stac92xx_init,
1862 .free = stac92xx_free,
Matt4e550962005-07-04 17:51:39 +02001863 .unsol_event = stac92xx_unsol_event,
Mattff6fdc32005-06-27 15:06:52 +02001864#ifdef CONFIG_PM
1865 .resume = stac92xx_resume,
1866#endif
Matt2f2f4252005-04-13 14:45:30 +02001867};
1868
1869static int patch_stac9200(struct hda_codec *codec)
1870{
1871 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02001872 int err;
Matt2f2f4252005-04-13 14:45:30 +02001873
Takashi Iwaie560d8d2005-09-09 14:21:46 +02001874 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02001875 if (spec == NULL)
1876 return -ENOMEM;
1877
1878 codec->spec = spec;
Richard Fish11b44bb2006-08-23 18:31:34 +02001879 spec->num_pins = 8;
1880 spec->pin_nids = stac9200_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001881 spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS,
1882 stac9200_models,
1883 stac9200_cfg_tbl);
Richard Fish11b44bb2006-08-23 18:31:34 +02001884 if (spec->board_config < 0) {
1885 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9200, using BIOS defaults\n");
1886 err = stac92xx_save_bios_config_regs(codec);
1887 if (err < 0) {
1888 stac92xx_free(codec);
1889 return err;
1890 }
1891 spec->pin_configs = spec->bios_pin_configs;
1892 } else {
Matt Porter403d1942005-11-29 15:00:51 +01001893 spec->pin_configs = stac9200_brd_tbl[spec->board_config];
1894 stac92xx_set_config_regs(codec);
1895 }
Matt2f2f4252005-04-13 14:45:30 +02001896
1897 spec->multiout.max_channels = 2;
1898 spec->multiout.num_dacs = 1;
1899 spec->multiout.dac_nids = stac9200_dac_nids;
1900 spec->adc_nids = stac9200_adc_nids;
1901 spec->mux_nids = stac9200_mux_nids;
Mattdabbed62005-06-14 10:19:34 +02001902 spec->num_muxes = 1;
Matt Porter8b657272006-10-26 17:12:59 +02001903 spec->num_dmics = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02001904
1905 spec->init = stac9200_core_init;
Matt2f2f4252005-04-13 14:45:30 +02001906 spec->mixer = stac9200_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02001907
1908 err = stac9200_parse_auto_config(codec);
1909 if (err < 0) {
1910 stac92xx_free(codec);
1911 return err;
1912 }
Matt2f2f4252005-04-13 14:45:30 +02001913
1914 codec->patch_ops = stac92xx_patch_ops;
1915
1916 return 0;
1917}
1918
Tobin Davis8e21c342007-01-08 11:04:17 +01001919static int patch_stac925x(struct hda_codec *codec)
1920{
1921 struct sigmatel_spec *spec;
1922 int err;
1923
1924 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1925 if (spec == NULL)
1926 return -ENOMEM;
1927
1928 codec->spec = spec;
1929 spec->num_pins = 8;
1930 spec->pin_nids = stac925x_pin_nids;
1931 spec->board_config = snd_hda_check_board_config(codec, STAC_925x_MODELS,
1932 stac925x_models,
1933 stac925x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01001934 again:
Tobin Davis8e21c342007-01-08 11:04:17 +01001935 if (spec->board_config < 0) {
Tobin Davis2c11f952007-05-17 09:36:34 +02001936 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC925x,"
1937 "using BIOS defaults\n");
Tobin Davis8e21c342007-01-08 11:04:17 +01001938 err = stac92xx_save_bios_config_regs(codec);
1939 if (err < 0) {
1940 stac92xx_free(codec);
1941 return err;
1942 }
1943 spec->pin_configs = spec->bios_pin_configs;
1944 } else if (stac925x_brd_tbl[spec->board_config] != NULL){
1945 spec->pin_configs = stac925x_brd_tbl[spec->board_config];
1946 stac92xx_set_config_regs(codec);
1947 }
1948
1949 spec->multiout.max_channels = 2;
1950 spec->multiout.num_dacs = 1;
1951 spec->multiout.dac_nids = stac925x_dac_nids;
1952 spec->adc_nids = stac925x_adc_nids;
1953 spec->mux_nids = stac925x_mux_nids;
1954 spec->num_muxes = 1;
Tobin Davis2c11f952007-05-17 09:36:34 +02001955 switch (codec->vendor_id) {
1956 case 0x83847632: /* STAC9202 */
1957 case 0x83847633: /* STAC9202D */
1958 case 0x83847636: /* STAC9251 */
1959 case 0x83847637: /* STAC9251D */
1960 spec->num_dmics = 1;
1961 spec->dmic_nids = stac925x_dmic_nids;
1962 break;
1963 default:
1964 spec->num_dmics = 0;
1965 break;
1966 }
Tobin Davis8e21c342007-01-08 11:04:17 +01001967
1968 spec->init = stac925x_core_init;
1969 spec->mixer = stac925x_mixer;
1970
1971 err = stac92xx_parse_auto_config(codec, 0x8, 0x7);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01001972 if (!err) {
1973 if (spec->board_config < 0) {
1974 printk(KERN_WARNING "hda_codec: No auto-config is "
1975 "available, default to model=ref\n");
1976 spec->board_config = STAC_925x_REF;
1977 goto again;
1978 }
1979 err = -EINVAL;
1980 }
Tobin Davis8e21c342007-01-08 11:04:17 +01001981 if (err < 0) {
1982 stac92xx_free(codec);
1983 return err;
1984 }
1985
1986 codec->patch_ops = stac92xx_patch_ops;
1987
1988 return 0;
1989}
1990
Matt2f2f4252005-04-13 14:45:30 +02001991static int patch_stac922x(struct hda_codec *codec)
1992{
1993 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02001994 int err;
Matt2f2f4252005-04-13 14:45:30 +02001995
Takashi Iwaie560d8d2005-09-09 14:21:46 +02001996 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02001997 if (spec == NULL)
1998 return -ENOMEM;
1999
2000 codec->spec = spec;
Richard Fish11b44bb2006-08-23 18:31:34 +02002001 spec->num_pins = 10;
2002 spec->pin_nids = stac922x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002003 spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS,
2004 stac922x_models,
2005 stac922x_cfg_tbl);
Takashi Iwai3fc24d82007-02-16 13:27:18 +01002006 if (spec->board_config == STAC_MACMINI) {
2007 spec->gpio_mute = 1;
2008 /* Intel Macs have all same PCI SSID, so we need to check
2009 * codec SSID to distinguish the exact models
2010 */
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01002011 printk(KERN_INFO "hda_codec: STAC922x, Apple subsys_id=%x\n", codec->subsystem_id);
Takashi Iwai3fc24d82007-02-16 13:27:18 +01002012 switch (codec->subsystem_id) {
Abhijit Bhopatkarc45e20e2007-04-17 11:57:16 +02002013 case 0x106b0a00: /* MacBook First generatoin */
2014 spec->board_config = STAC_MACBOOK;
2015 break;
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01002016 case 0x106b0200: /* MacBook Pro first generation */
2017 spec->board_config = STAC_MACBOOK_PRO_V1;
2018 break;
2019 case 0x106b1e00: /* MacBook Pro second generation */
2020 spec->board_config = STAC_MACBOOK_PRO_V2;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01002021 break;
Sylvain FORETf16928f2007-04-27 14:22:36 +02002022 case 0x106b0700: /* Intel-based iMac */
2023 spec->board_config = STAC_IMAC_INTEL;
2024 break;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01002025 }
2026 }
2027
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002028 again:
Richard Fish11b44bb2006-08-23 18:31:34 +02002029 if (spec->board_config < 0) {
2030 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC922x, "
2031 "using BIOS defaults\n");
2032 err = stac92xx_save_bios_config_regs(codec);
2033 if (err < 0) {
2034 stac92xx_free(codec);
2035 return err;
2036 }
2037 spec->pin_configs = spec->bios_pin_configs;
2038 } else if (stac922x_brd_tbl[spec->board_config] != NULL) {
Matt Porter403d1942005-11-29 15:00:51 +01002039 spec->pin_configs = stac922x_brd_tbl[spec->board_config];
2040 stac92xx_set_config_regs(codec);
2041 }
Matt2f2f4252005-04-13 14:45:30 +02002042
Matt2f2f4252005-04-13 14:45:30 +02002043 spec->adc_nids = stac922x_adc_nids;
2044 spec->mux_nids = stac922x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01002045 spec->num_muxes = ARRAY_SIZE(stac922x_mux_nids);
Matt Porter8b657272006-10-26 17:12:59 +02002046 spec->num_dmics = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02002047
2048 spec->init = stac922x_core_init;
Matt2f2f4252005-04-13 14:45:30 +02002049 spec->mixer = stac922x_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02002050
2051 spec->multiout.dac_nids = spec->dac_nids;
Takashi Iwai19039bd2006-06-28 15:52:16 +02002052
Matt Porter3cc08dc2006-01-23 15:27:49 +01002053 err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002054 if (!err) {
2055 if (spec->board_config < 0) {
2056 printk(KERN_WARNING "hda_codec: No auto-config is "
2057 "available, default to model=ref\n");
2058 spec->board_config = STAC_D945_REF;
2059 goto again;
2060 }
2061 err = -EINVAL;
2062 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01002063 if (err < 0) {
2064 stac92xx_free(codec);
2065 return err;
2066 }
2067
2068 codec->patch_ops = stac92xx_patch_ops;
2069
2070 return 0;
2071}
2072
2073static int patch_stac927x(struct hda_codec *codec)
2074{
2075 struct sigmatel_spec *spec;
2076 int err;
2077
2078 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2079 if (spec == NULL)
2080 return -ENOMEM;
2081
2082 codec->spec = spec;
Richard Fish11b44bb2006-08-23 18:31:34 +02002083 spec->num_pins = 14;
2084 spec->pin_nids = stac927x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002085 spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS,
2086 stac927x_models,
2087 stac927x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002088 again:
Richard Fish11b44bb2006-08-23 18:31:34 +02002089 if (spec->board_config < 0) {
Matt Porter3cc08dc2006-01-23 15:27:49 +01002090 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC927x, using BIOS defaults\n");
Richard Fish11b44bb2006-08-23 18:31:34 +02002091 err = stac92xx_save_bios_config_regs(codec);
2092 if (err < 0) {
2093 stac92xx_free(codec);
2094 return err;
2095 }
2096 spec->pin_configs = spec->bios_pin_configs;
2097 } else if (stac927x_brd_tbl[spec->board_config] != NULL) {
Matt Porter3cc08dc2006-01-23 15:27:49 +01002098 spec->pin_configs = stac927x_brd_tbl[spec->board_config];
2099 stac92xx_set_config_regs(codec);
2100 }
2101
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002102 switch (spec->board_config) {
Tobin Davis93ed1502006-09-01 21:03:12 +02002103 case STAC_D965_3ST:
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002104 spec->adc_nids = stac927x_adc_nids;
2105 spec->mux_nids = stac927x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01002106 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
Matt Porter8b657272006-10-26 17:12:59 +02002107 spec->num_dmics = 0;
Tobin Davis93ed1502006-09-01 21:03:12 +02002108 spec->init = d965_core_init;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002109 spec->mixer = stac9227_mixer;
2110 break;
Tobin Davis93ed1502006-09-01 21:03:12 +02002111 case STAC_D965_5ST:
2112 spec->adc_nids = stac927x_adc_nids;
2113 spec->mux_nids = stac927x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01002114 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
Matt Porter8b657272006-10-26 17:12:59 +02002115 spec->num_dmics = 0;
Tobin Davis93ed1502006-09-01 21:03:12 +02002116 spec->init = d965_core_init;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002117 spec->mixer = stac9227_mixer;
2118 break;
2119 default:
2120 spec->adc_nids = stac927x_adc_nids;
2121 spec->mux_nids = stac927x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01002122 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
Matt Porter8b657272006-10-26 17:12:59 +02002123 spec->num_dmics = 0;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002124 spec->init = stac927x_core_init;
2125 spec->mixer = stac927x_mixer;
2126 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01002127
2128 spec->multiout.dac_nids = spec->dac_nids;
2129
2130 err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002131 if (!err) {
2132 if (spec->board_config < 0) {
2133 printk(KERN_WARNING "hda_codec: No auto-config is "
2134 "available, default to model=ref\n");
2135 spec->board_config = STAC_D965_REF;
2136 goto again;
2137 }
2138 err = -EINVAL;
2139 }
Mattc7d4b2f2005-06-27 14:59:41 +02002140 if (err < 0) {
2141 stac92xx_free(codec);
2142 return err;
2143 }
Matt2f2f4252005-04-13 14:45:30 +02002144
2145 codec->patch_ops = stac92xx_patch_ops;
2146
2147 return 0;
2148}
2149
Matt Porterf3302a52006-07-31 12:49:34 +02002150static int patch_stac9205(struct hda_codec *codec)
2151{
2152 struct sigmatel_spec *spec;
2153 int err;
2154
2155 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2156 if (spec == NULL)
2157 return -ENOMEM;
2158
2159 codec->spec = spec;
Richard Fish11b44bb2006-08-23 18:31:34 +02002160 spec->num_pins = 14;
2161 spec->pin_nids = stac9205_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002162 spec->board_config = snd_hda_check_board_config(codec, STAC_9205_MODELS,
2163 stac9205_models,
2164 stac9205_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002165 again:
Richard Fish11b44bb2006-08-23 18:31:34 +02002166 if (spec->board_config < 0) {
2167 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9205, using BIOS defaults\n");
2168 err = stac92xx_save_bios_config_regs(codec);
2169 if (err < 0) {
2170 stac92xx_free(codec);
2171 return err;
2172 }
2173 spec->pin_configs = spec->bios_pin_configs;
2174 } else {
Matt Porterf3302a52006-07-31 12:49:34 +02002175 spec->pin_configs = stac9205_brd_tbl[spec->board_config];
2176 stac92xx_set_config_regs(codec);
2177 }
2178
2179 spec->adc_nids = stac9205_adc_nids;
2180 spec->mux_nids = stac9205_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01002181 spec->num_muxes = ARRAY_SIZE(stac9205_mux_nids);
Matt Porter8b657272006-10-26 17:12:59 +02002182 spec->dmic_nids = stac9205_dmic_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01002183 spec->num_dmics = ARRAY_SIZE(stac9205_dmic_nids);
Matt Porter8b657272006-10-26 17:12:59 +02002184 spec->dmux_nid = 0x1d;
Matt Porterf3302a52006-07-31 12:49:34 +02002185
2186 spec->init = stac9205_core_init;
2187 spec->mixer = stac9205_mixer;
2188
2189 spec->multiout.dac_nids = spec->dac_nids;
2190
Matt Porter33382402006-12-18 13:17:28 +01002191 /* Configure GPIO0 as EAPD output */
2192 snd_hda_codec_write(codec, codec->afg, 0,
2193 AC_VERB_SET_GPIO_DIRECTION, 0x00000001);
2194 /* Configure GPIO0 as CMOS */
2195 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0x00000000);
2196 /* Assert GPIO0 high */
2197 snd_hda_codec_write(codec, codec->afg, 0,
2198 AC_VERB_SET_GPIO_DATA, 0x00000001);
2199 /* Enable GPIO0 */
2200 snd_hda_codec_write(codec, codec->afg, 0,
2201 AC_VERB_SET_GPIO_MASK, 0x00000001);
2202
Matt Porterf3302a52006-07-31 12:49:34 +02002203 err = stac92xx_parse_auto_config(codec, 0x1f, 0x20);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002204 if (!err) {
2205 if (spec->board_config < 0) {
2206 printk(KERN_WARNING "hda_codec: No auto-config is "
2207 "available, default to model=ref\n");
2208 spec->board_config = STAC_9205_REF;
2209 goto again;
2210 }
2211 err = -EINVAL;
2212 }
Matt Porterf3302a52006-07-31 12:49:34 +02002213 if (err < 0) {
2214 stac92xx_free(codec);
2215 return err;
2216 }
2217
2218 codec->patch_ops = stac92xx_patch_ops;
2219
2220 return 0;
2221}
2222
Matt2f2f4252005-04-13 14:45:30 +02002223/*
Guillaume Munch6d859062006-08-22 17:15:47 +02002224 * STAC9872 hack
Takashi Iwaidb064e52006-03-16 16:04:58 +01002225 */
2226
Guillaume Munch99ccc562006-08-16 19:35:12 +02002227/* static config for Sony VAIO FE550G and Sony VAIO AR */
Takashi Iwaidb064e52006-03-16 16:04:58 +01002228static hda_nid_t vaio_dacs[] = { 0x2 };
2229#define VAIO_HP_DAC 0x5
2230static hda_nid_t vaio_adcs[] = { 0x8 /*,0x6*/ };
2231static hda_nid_t vaio_mux_nids[] = { 0x15 };
2232
2233static struct hda_input_mux vaio_mux = {
2234 .num_items = 2,
2235 .items = {
Takashi Iwaid7737812006-04-25 13:05:43 +02002236 /* { "HP", 0x0 }, */
2237 { "Line", 0x1 },
Takashi Iwaidb064e52006-03-16 16:04:58 +01002238 { "Mic", 0x2 },
2239 { "PCM", 0x3 },
2240 }
2241};
2242
2243static struct hda_verb vaio_init[] = {
2244 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
2245 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
2246 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
2247 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
2248 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
2249 {0x15, AC_VERB_SET_CONNECT_SEL, 0x2}, /* mic-sel: 0a,0d,14,02 */
2250 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
2251 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
2252 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
2253 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
2254 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
2255 {}
2256};
2257
Guillaume Munch6d859062006-08-22 17:15:47 +02002258static struct hda_verb vaio_ar_init[] = {
2259 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
2260 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
2261 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
2262 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
2263/* {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },*/ /* Optical Out */
2264 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
2265 {0x15, AC_VERB_SET_CONNECT_SEL, 0x2}, /* mic-sel: 0a,0d,14,02 */
2266 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
2267 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
2268/* {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},*/ /* Optical Out */
2269 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
2270 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
2271 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
2272 {}
2273};
2274
Takashi Iwaidb064e52006-03-16 16:04:58 +01002275/* bind volumes of both NID 0x02 and 0x05 */
2276static int vaio_master_vol_put(struct snd_kcontrol *kcontrol,
2277 struct snd_ctl_elem_value *ucontrol)
2278{
2279 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2280 long *valp = ucontrol->value.integer.value;
2281 int change;
2282
2283 change = snd_hda_codec_amp_update(codec, 0x02, 0, HDA_OUTPUT, 0,
2284 0x7f, valp[0] & 0x7f);
2285 change |= snd_hda_codec_amp_update(codec, 0x02, 1, HDA_OUTPUT, 0,
2286 0x7f, valp[1] & 0x7f);
2287 snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
2288 0x7f, valp[0] & 0x7f);
2289 snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
2290 0x7f, valp[1] & 0x7f);
2291 return change;
2292}
2293
2294/* bind volumes of both NID 0x02 and 0x05 */
2295static int vaio_master_sw_put(struct snd_kcontrol *kcontrol,
2296 struct snd_ctl_elem_value *ucontrol)
2297{
2298 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2299 long *valp = ucontrol->value.integer.value;
2300 int change;
2301
2302 change = snd_hda_codec_amp_update(codec, 0x02, 0, HDA_OUTPUT, 0,
Takashi Iwaia9393d72006-05-03 11:59:03 +02002303 0x80, (valp[0] ? 0 : 0x80));
Takashi Iwaidb064e52006-03-16 16:04:58 +01002304 change |= snd_hda_codec_amp_update(codec, 0x02, 1, HDA_OUTPUT, 0,
Takashi Iwaia9393d72006-05-03 11:59:03 +02002305 0x80, (valp[1] ? 0 : 0x80));
Takashi Iwaidb064e52006-03-16 16:04:58 +01002306 snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
Takashi Iwaia9393d72006-05-03 11:59:03 +02002307 0x80, (valp[0] ? 0 : 0x80));
Takashi Iwaidb064e52006-03-16 16:04:58 +01002308 snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
Takashi Iwaia9393d72006-05-03 11:59:03 +02002309 0x80, (valp[1] ? 0 : 0x80));
Takashi Iwaidb064e52006-03-16 16:04:58 +01002310 return change;
2311}
2312
2313static struct snd_kcontrol_new vaio_mixer[] = {
2314 {
2315 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2316 .name = "Master Playback Volume",
2317 .info = snd_hda_mixer_amp_volume_info,
2318 .get = snd_hda_mixer_amp_volume_get,
2319 .put = vaio_master_vol_put,
Takashi Iwaic2566522006-08-17 18:21:36 +02002320 .tlv = { .c = snd_hda_mixer_amp_tlv },
Takashi Iwaidb064e52006-03-16 16:04:58 +01002321 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2322 },
2323 {
2324 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2325 .name = "Master Playback Switch",
2326 .info = snd_hda_mixer_amp_switch_info,
2327 .get = snd_hda_mixer_amp_switch_get,
2328 .put = vaio_master_sw_put,
2329 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2330 },
2331 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
2332 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
2333 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
2334 {
2335 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2336 .name = "Capture Source",
2337 .count = 1,
2338 .info = stac92xx_mux_enum_info,
2339 .get = stac92xx_mux_enum_get,
2340 .put = stac92xx_mux_enum_put,
2341 },
2342 {}
2343};
2344
Guillaume Munch6d859062006-08-22 17:15:47 +02002345static struct snd_kcontrol_new vaio_ar_mixer[] = {
2346 {
2347 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2348 .name = "Master Playback Volume",
2349 .info = snd_hda_mixer_amp_volume_info,
2350 .get = snd_hda_mixer_amp_volume_get,
2351 .put = vaio_master_vol_put,
2352 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2353 },
2354 {
2355 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2356 .name = "Master Playback Switch",
2357 .info = snd_hda_mixer_amp_switch_info,
2358 .get = snd_hda_mixer_amp_switch_get,
2359 .put = vaio_master_sw_put,
2360 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2361 },
2362 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
2363 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
2364 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
2365 /*HDA_CODEC_MUTE("Optical Out Switch", 0x10, 0, HDA_OUTPUT),
2366 HDA_CODEC_VOLUME("Optical Out Volume", 0x10, 0, HDA_OUTPUT),*/
2367 {
2368 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2369 .name = "Capture Source",
2370 .count = 1,
2371 .info = stac92xx_mux_enum_info,
2372 .get = stac92xx_mux_enum_get,
2373 .put = stac92xx_mux_enum_put,
2374 },
2375 {}
2376};
2377
2378static struct hda_codec_ops stac9872_patch_ops = {
Takashi Iwaidb064e52006-03-16 16:04:58 +01002379 .build_controls = stac92xx_build_controls,
2380 .build_pcms = stac92xx_build_pcms,
2381 .init = stac92xx_init,
2382 .free = stac92xx_free,
2383#ifdef CONFIG_PM
2384 .resume = stac92xx_resume,
2385#endif
2386};
2387
Guillaume Munch6d859062006-08-22 17:15:47 +02002388enum { /* FE and SZ series. id=0x83847661 and subsys=0x104D0700 or 104D1000. */
2389 CXD9872RD_VAIO,
2390 /* Unknown. id=0x83847662 and subsys=0x104D1200 or 104D1000. */
2391 STAC9872AK_VAIO,
2392 /* Unknown. id=0x83847661 and subsys=0x104D1200. */
2393 STAC9872K_VAIO,
2394 /* AR Series. id=0x83847664 and subsys=104D1300 */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002395 CXD9872AKD_VAIO,
2396 STAC_9872_MODELS,
2397};
Takashi Iwaidb064e52006-03-16 16:04:58 +01002398
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002399static const char *stac9872_models[STAC_9872_MODELS] = {
2400 [CXD9872RD_VAIO] = "vaio",
2401 [CXD9872AKD_VAIO] = "vaio-ar",
2402};
2403
2404static struct snd_pci_quirk stac9872_cfg_tbl[] = {
2405 SND_PCI_QUIRK(0x104d, 0x81e6, "Sony VAIO F/S", CXD9872RD_VAIO),
2406 SND_PCI_QUIRK(0x104d, 0x81ef, "Sony VAIO F/S", CXD9872RD_VAIO),
2407 SND_PCI_QUIRK(0x104d, 0x81fd, "Sony VAIO AR", CXD9872AKD_VAIO),
Tobin Davis68e22542007-03-12 11:36:39 +01002408 SND_PCI_QUIRK(0x104d, 0x8205, "Sony VAIO AR", CXD9872AKD_VAIO),
Takashi Iwaidb064e52006-03-16 16:04:58 +01002409 {}
2410};
2411
Guillaume Munch6d859062006-08-22 17:15:47 +02002412static int patch_stac9872(struct hda_codec *codec)
Takashi Iwaidb064e52006-03-16 16:04:58 +01002413{
2414 struct sigmatel_spec *spec;
2415 int board_config;
2416
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002417 board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
2418 stac9872_models,
2419 stac9872_cfg_tbl);
Takashi Iwaidb064e52006-03-16 16:04:58 +01002420 if (board_config < 0)
2421 /* unknown config, let generic-parser do its job... */
2422 return snd_hda_parse_generic_codec(codec);
2423
2424 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2425 if (spec == NULL)
2426 return -ENOMEM;
2427
2428 codec->spec = spec;
2429 switch (board_config) {
Guillaume Munch6d859062006-08-22 17:15:47 +02002430 case CXD9872RD_VAIO:
2431 case STAC9872AK_VAIO:
2432 case STAC9872K_VAIO:
Takashi Iwaidb064e52006-03-16 16:04:58 +01002433 spec->mixer = vaio_mixer;
2434 spec->init = vaio_init;
2435 spec->multiout.max_channels = 2;
2436 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
2437 spec->multiout.dac_nids = vaio_dacs;
2438 spec->multiout.hp_nid = VAIO_HP_DAC;
2439 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
2440 spec->adc_nids = vaio_adcs;
2441 spec->input_mux = &vaio_mux;
2442 spec->mux_nids = vaio_mux_nids;
2443 break;
Guillaume Munch6d859062006-08-22 17:15:47 +02002444
2445 case CXD9872AKD_VAIO:
2446 spec->mixer = vaio_ar_mixer;
2447 spec->init = vaio_ar_init;
2448 spec->multiout.max_channels = 2;
2449 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
2450 spec->multiout.dac_nids = vaio_dacs;
2451 spec->multiout.hp_nid = VAIO_HP_DAC;
2452 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
2453 spec->adc_nids = vaio_adcs;
2454 spec->input_mux = &vaio_mux;
2455 spec->mux_nids = vaio_mux_nids;
2456 break;
Takashi Iwaidb064e52006-03-16 16:04:58 +01002457 }
2458
Guillaume Munch6d859062006-08-22 17:15:47 +02002459 codec->patch_ops = stac9872_patch_ops;
Takashi Iwaidb064e52006-03-16 16:04:58 +01002460 return 0;
2461}
2462
2463
2464/*
Matt2f2f4252005-04-13 14:45:30 +02002465 * patch entries
2466 */
2467struct hda_codec_preset snd_hda_preset_sigmatel[] = {
2468 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
2469 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
2470 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
2471 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
2472 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
2473 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
2474 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
Matt Porter22a27c72006-07-06 18:49:10 +02002475 { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
2476 { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
2477 { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
2478 { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
2479 { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
2480 { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
Matt Porter3cc08dc2006-01-23 15:27:49 +01002481 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
2482 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
2483 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
2484 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
2485 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
2486 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
2487 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
2488 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
2489 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
2490 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
Tobin Davis8e21c342007-01-08 11:04:17 +01002491 { .id = 0x83847632, .name = "STAC9202", .patch = patch_stac925x },
2492 { .id = 0x83847633, .name = "STAC9202D", .patch = patch_stac925x },
2493 { .id = 0x83847634, .name = "STAC9250", .patch = patch_stac925x },
2494 { .id = 0x83847635, .name = "STAC9250D", .patch = patch_stac925x },
2495 { .id = 0x83847636, .name = "STAC9251", .patch = patch_stac925x },
2496 { .id = 0x83847637, .name = "STAC9250D", .patch = patch_stac925x },
Guillaume Munch6d859062006-08-22 17:15:47 +02002497 /* The following does not take into account .id=0x83847661 when subsys =
2498 * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
2499 * currently not fully supported.
2500 */
2501 { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
2502 { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
2503 { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
Matt Porterf3302a52006-07-31 12:49:34 +02002504 { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
2505 { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
2506 { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
2507 { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
2508 { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
2509 { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
2510 { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
2511 { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
Matt2f2f4252005-04-13 14:45:30 +02002512 {} /* terminator */
2513};