blob: 6e6818c8db185d068fcd93385c30d0598a8d7c7e [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),
Matt Porter403d1942005-11-29 15:00:51 +0100477 {} /* terminator */
478};
479
Tobin Davis8e21c342007-01-08 11:04:17 +0100480static unsigned int ref925x_pin_configs[8] = {
481 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
482 0x90a70320, 0x02214210, 0x400003f1, 0x9033032e,
483};
484
485static unsigned int stac925x_MA6_pin_configs[8] = {
486 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
487 0x90a70320, 0x90100211, 0x400003f1, 0x9033032e,
488};
489
Tobin Davis2c11f952007-05-17 09:36:34 +0200490static unsigned int stac925x_PA6_pin_configs[8] = {
491 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
492 0x50a103f0, 0x90100211, 0x400003f1, 0x9033032e,
493};
494
Tobin Davis8e21c342007-01-08 11:04:17 +0100495static unsigned int stac925xM2_2_pin_configs[8] = {
496 0x40c003f3, 0x424503f2, 0x041800f4, 0x02a19020,
497 0x50a103F0, 0x90100210, 0x400003f1, 0x9033032e,
498};
499
500static unsigned int *stac925x_brd_tbl[STAC_925x_MODELS] = {
501 [STAC_REF] = ref925x_pin_configs,
502 [STAC_M2_2] = stac925xM2_2_pin_configs,
503 [STAC_MA6] = stac925x_MA6_pin_configs,
Tobin Davis2c11f952007-05-17 09:36:34 +0200504 [STAC_PA6] = stac925x_PA6_pin_configs,
Tobin Davis8e21c342007-01-08 11:04:17 +0100505};
506
507static const char *stac925x_models[STAC_925x_MODELS] = {
508 [STAC_REF] = "ref",
509 [STAC_M2_2] = "m2-2",
510 [STAC_MA6] = "m6",
Tobin Davis2c11f952007-05-17 09:36:34 +0200511 [STAC_PA6] = "pa6",
Tobin Davis8e21c342007-01-08 11:04:17 +0100512};
513
514static struct snd_pci_quirk stac925x_cfg_tbl[] = {
515 /* SigmaTel reference board */
516 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, "DFI LanParty", STAC_REF),
Tobin Davis2c11f952007-05-17 09:36:34 +0200517 SND_PCI_QUIRK(0x8384, 0x7632, "Stac9202 Reference Board", STAC_REF),
Tobin Davis8e21c342007-01-08 11:04:17 +0100518 SND_PCI_QUIRK(0x107b, 0x0316, "Gateway M255", STAC_REF),
519 SND_PCI_QUIRK(0x107b, 0x0366, "Gateway MP6954", STAC_REF),
520 SND_PCI_QUIRK(0x107b, 0x0461, "Gateway NX560XL", STAC_MA6),
Tobin Davis2c11f952007-05-17 09:36:34 +0200521 SND_PCI_QUIRK(0x107b, 0x0681, "Gateway NX860", STAC_PA6),
Tobin Davis8e21c342007-01-08 11:04:17 +0100522 SND_PCI_QUIRK(0x1002, 0x437b, "Gateway MX6453", STAC_M2_2),
523 {} /* terminator */
524};
525
Matt Porter403d1942005-11-29 15:00:51 +0100526static unsigned int ref922x_pin_configs[10] = {
527 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
528 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
Matt2f2f4252005-04-13 14:45:30 +0200529 0x40000100, 0x40000100,
530};
531
Matt Porter403d1942005-11-29 15:00:51 +0100532static unsigned int d945gtp3_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +0100533 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
Matt Porter403d1942005-11-29 15:00:51 +0100534 0x40000100, 0x40000100, 0x40000100, 0x40000100,
535 0x02a19120, 0x40000100,
536};
537
538static unsigned int d945gtp5_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +0100539 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
540 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
Matt Porter403d1942005-11-29 15:00:51 +0100541 0x02a19320, 0x40000100,
542};
543
Nicolas Boichat6f0778d2007-03-15 12:38:15 +0100544static unsigned int macbook_pro_v1_pin_configs[10] = {
545 0x0321e230, 0x03a1e020, 0x9017e110, 0x01014010,
546 0x01a19021, 0x0381e021, 0x1345e240, 0x13c5e22e,
547 0x02a19320, 0x400000fb
548};
549
550static unsigned int macbook_pro_v2_pin_configs[10] = {
Takashi Iwai3fc24d82007-02-16 13:27:18 +0100551 0x0221401f, 0x90a70120, 0x01813024, 0x01014010,
552 0x400000fd, 0x01016011, 0x1345e240, 0x13c5e22e,
553 0x400000fc, 0x400000fb,
554};
555
Sylvain FORETf16928f2007-04-27 14:22:36 +0200556static unsigned int imac_intel_pin_configs[10] = {
557 0x0121e230, 0x90a70120, 0x9017e110, 0x400000fe,
558 0x400000fd, 0x0181e021, 0x1145e040, 0x400000fa,
559 0x400000fc, 0x400000fb,
560};
561
Takashi Iwai19039bd2006-06-28 15:52:16 +0200562static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100563 [STAC_D945_REF] = ref922x_pin_configs,
Takashi Iwai19039bd2006-06-28 15:52:16 +0200564 [STAC_D945GTP3] = d945gtp3_pin_configs,
565 [STAC_D945GTP5] = d945gtp5_pin_configs,
Takashi Iwai02a50392007-03-19 11:42:18 +0100566 [STAC_MACMINI] = macbook_pro_v1_pin_configs,
567 [STAC_MACBOOK] = macbook_pro_v1_pin_configs,
Nicolas Boichat6f0778d2007-03-15 12:38:15 +0100568 [STAC_MACBOOK_PRO_V1] = macbook_pro_v1_pin_configs,
569 [STAC_MACBOOK_PRO_V2] = macbook_pro_v2_pin_configs,
Sylvain FORETf16928f2007-04-27 14:22:36 +0200570 [STAC_IMAC_INTEL] = imac_intel_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +0100571};
572
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100573static const char *stac922x_models[STAC_922X_MODELS] = {
574 [STAC_D945_REF] = "ref",
575 [STAC_D945GTP5] = "5stack",
576 [STAC_D945GTP3] = "3stack",
577 [STAC_MACMINI] = "macmini",
Takashi Iwai3fc24d82007-02-16 13:27:18 +0100578 [STAC_MACBOOK] = "macbook",
Nicolas Boichat6f0778d2007-03-15 12:38:15 +0100579 [STAC_MACBOOK_PRO_V1] = "macbook-pro-v1",
580 [STAC_MACBOOK_PRO_V2] = "macbook-pro",
Sylvain FORETf16928f2007-04-27 14:22:36 +0200581 [STAC_IMAC_INTEL] = "imac-intel",
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100582};
583
584static struct snd_pci_quirk stac922x_cfg_tbl[] = {
585 /* SigmaTel reference board */
586 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
587 "DFI LanParty", STAC_D945_REF),
588 /* Intel 945G based systems */
589 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101,
590 "Intel D945G", STAC_D945GTP3),
591 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0202,
592 "Intel D945G", STAC_D945GTP3),
593 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0606,
594 "Intel D945G", STAC_D945GTP3),
595 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0601,
596 "Intel D945G", STAC_D945GTP3),
597 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0111,
598 "Intel D945G", STAC_D945GTP3),
599 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1115,
600 "Intel D945G", STAC_D945GTP3),
601 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1116,
602 "Intel D945G", STAC_D945GTP3),
603 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1117,
604 "Intel D945G", STAC_D945GTP3),
605 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1118,
606 "Intel D945G", STAC_D945GTP3),
607 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1119,
608 "Intel D945G", STAC_D945GTP3),
609 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x8826,
610 "Intel D945G", STAC_D945GTP3),
611 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5049,
612 "Intel D945G", STAC_D945GTP3),
613 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5055,
614 "Intel D945G", STAC_D945GTP3),
615 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5048,
616 "Intel D945G", STAC_D945GTP3),
617 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0110,
618 "Intel D945G", STAC_D945GTP3),
619 /* Intel D945G 5-stack systems */
620 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0404,
621 "Intel D945G", STAC_D945GTP5),
622 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0303,
623 "Intel D945G", STAC_D945GTP5),
624 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0013,
625 "Intel D945G", STAC_D945GTP5),
626 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0417,
627 "Intel D945G", STAC_D945GTP5),
628 /* Intel 945P based systems */
629 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0b0b,
630 "Intel D945P", STAC_D945GTP3),
631 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0112,
632 "Intel D945P", STAC_D945GTP3),
633 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0d0d,
634 "Intel D945P", STAC_D945GTP3),
635 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0909,
636 "Intel D945P", STAC_D945GTP3),
637 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0505,
638 "Intel D945P", STAC_D945GTP3),
639 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707,
640 "Intel D945P", STAC_D945GTP5),
641 /* other systems */
642 /* Apple Mac Mini (early 2006) */
643 SND_PCI_QUIRK(0x8384, 0x7680,
644 "Mac Mini", STAC_MACMINI),
Matt Porter403d1942005-11-29 15:00:51 +0100645 {} /* terminator */
646};
647
Matt Porter3cc08dc2006-01-23 15:27:49 +0100648static unsigned int ref927x_pin_configs[14] = {
Tobin Davis93ed1502006-09-01 21:03:12 +0200649 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
650 0x01a19040, 0x01011012, 0x01016011, 0x0101201f,
651 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
652 0x01c42190, 0x40000100,
Matt Porter3cc08dc2006-01-23 15:27:49 +0100653};
654
Tobin Davis93ed1502006-09-01 21:03:12 +0200655static unsigned int d965_3st_pin_configs[14] = {
Tobin Davis81d3dbd2006-08-22 19:44:45 +0200656 0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
657 0x01a19021, 0x01813024, 0x40000100, 0x40000100,
658 0x40000100, 0x40000100, 0x40000100, 0x40000100,
659 0x40000100, 0x40000100
660};
661
Tobin Davis93ed1502006-09-01 21:03:12 +0200662static unsigned int d965_5st_pin_configs[14] = {
663 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
664 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
665 0x40000100, 0x40000100, 0x40000100, 0x01442070,
666 0x40000100, 0x40000100
667};
668
669static unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100670 [STAC_D965_REF] = ref927x_pin_configs,
Tobin Davis93ed1502006-09-01 21:03:12 +0200671 [STAC_D965_3ST] = d965_3st_pin_configs,
672 [STAC_D965_5ST] = d965_5st_pin_configs,
Matt Porter3cc08dc2006-01-23 15:27:49 +0100673};
674
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100675static const char *stac927x_models[STAC_927X_MODELS] = {
676 [STAC_D965_REF] = "ref",
677 [STAC_D965_3ST] = "3stack",
678 [STAC_D965_5ST] = "5stack",
679};
680
681static struct snd_pci_quirk stac927x_cfg_tbl[] = {
682 /* SigmaTel reference board */
683 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
684 "DFI LanParty", STAC_D965_REF),
Tobin Davis81d3dbd2006-08-22 19:44:45 +0200685 /* Intel 946 based systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100686 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST),
687 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST),
Tobin Davis93ed1502006-09-01 21:03:12 +0200688 /* 965 based 3 stack systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100689 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2116, "Intel D965", STAC_D965_3ST),
690 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2115, "Intel D965", STAC_D965_3ST),
691 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2114, "Intel D965", STAC_D965_3ST),
692 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2113, "Intel D965", STAC_D965_3ST),
693 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2112, "Intel D965", STAC_D965_3ST),
694 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2111, "Intel D965", STAC_D965_3ST),
695 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2110, "Intel D965", STAC_D965_3ST),
696 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2009, "Intel D965", STAC_D965_3ST),
697 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2008, "Intel D965", STAC_D965_3ST),
698 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2007, "Intel D965", STAC_D965_3ST),
699 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2006, "Intel D965", STAC_D965_3ST),
700 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2005, "Intel D965", STAC_D965_3ST),
701 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2004, "Intel D965", STAC_D965_3ST),
702 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2003, "Intel D965", STAC_D965_3ST),
703 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2002, "Intel D965", STAC_D965_3ST),
704 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2001, "Intel D965", STAC_D965_3ST),
Tobin Davis93ed1502006-09-01 21:03:12 +0200705 /* 965 based 5 stack systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100706 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2301, "Intel D965", STAC_D965_5ST),
707 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2302, "Intel D965", STAC_D965_5ST),
708 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2303, "Intel D965", STAC_D965_5ST),
709 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2304, "Intel D965", STAC_D965_5ST),
710 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2305, "Intel D965", STAC_D965_5ST),
711 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2501, "Intel D965", STAC_D965_5ST),
712 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2502, "Intel D965", STAC_D965_5ST),
713 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2503, "Intel D965", STAC_D965_5ST),
714 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2504, "Intel D965", STAC_D965_5ST),
Matt Porter3cc08dc2006-01-23 15:27:49 +0100715 {} /* terminator */
716};
717
Matt Porterf3302a52006-07-31 12:49:34 +0200718static unsigned int ref9205_pin_configs[12] = {
719 0x40000100, 0x40000100, 0x01016011, 0x01014010,
Matt Porter8b657272006-10-26 17:12:59 +0200720 0x01813122, 0x01a19021, 0x40000100, 0x40000100,
721 0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
Matt Porterf3302a52006-07-31 12:49:34 +0200722};
723
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100724static unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
Matt Porterf3302a52006-07-31 12:49:34 +0200725 ref9205_pin_configs,
726};
727
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100728static const char *stac9205_models[STAC_9205_MODELS] = {
729 [STAC_9205_REF] = "ref",
730};
731
732static struct snd_pci_quirk stac9205_cfg_tbl[] = {
733 /* SigmaTel reference board */
734 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
735 "DFI LanParty", STAC_9205_REF),
Matt Porterf3302a52006-07-31 12:49:34 +0200736 {} /* terminator */
737};
738
Richard Fish11b44bb2006-08-23 18:31:34 +0200739static int stac92xx_save_bios_config_regs(struct hda_codec *codec)
740{
741 int i;
742 struct sigmatel_spec *spec = codec->spec;
743
744 if (! spec->bios_pin_configs) {
745 spec->bios_pin_configs = kcalloc(spec->num_pins,
746 sizeof(*spec->bios_pin_configs), GFP_KERNEL);
747 if (! spec->bios_pin_configs)
748 return -ENOMEM;
749 }
750
751 for (i = 0; i < spec->num_pins; i++) {
752 hda_nid_t nid = spec->pin_nids[i];
753 unsigned int pin_cfg;
754
755 pin_cfg = snd_hda_codec_read(codec, nid, 0,
756 AC_VERB_GET_CONFIG_DEFAULT, 0x00);
757 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x bios pin config %8.8x\n",
758 nid, pin_cfg);
759 spec->bios_pin_configs[i] = pin_cfg;
760 }
761
762 return 0;
763}
764
Matt2f2f4252005-04-13 14:45:30 +0200765static void stac92xx_set_config_regs(struct hda_codec *codec)
766{
767 int i;
768 struct sigmatel_spec *spec = codec->spec;
769 unsigned int pin_cfg;
770
Richard Fish11b44bb2006-08-23 18:31:34 +0200771 if (! spec->pin_nids || ! spec->pin_configs)
772 return;
773
774 for (i = 0; i < spec->num_pins; i++) {
Matt2f2f4252005-04-13 14:45:30 +0200775 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
776 AC_VERB_SET_CONFIG_DEFAULT_BYTES_0,
777 spec->pin_configs[i] & 0x000000ff);
778 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
779 AC_VERB_SET_CONFIG_DEFAULT_BYTES_1,
780 (spec->pin_configs[i] & 0x0000ff00) >> 8);
781 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
782 AC_VERB_SET_CONFIG_DEFAULT_BYTES_2,
783 (spec->pin_configs[i] & 0x00ff0000) >> 16);
784 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
785 AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
786 spec->pin_configs[i] >> 24);
787 pin_cfg = snd_hda_codec_read(codec, spec->pin_nids[i], 0,
788 AC_VERB_GET_CONFIG_DEFAULT,
789 0x00);
Matt Porter403d1942005-11-29 15:00:51 +0100790 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 +0200791 }
792}
Matt2f2f4252005-04-13 14:45:30 +0200793
Matt2f2f4252005-04-13 14:45:30 +0200794/*
795 * Analog playback callbacks
796 */
797static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
798 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100799 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200800{
801 struct sigmatel_spec *spec = codec->spec;
802 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
803}
804
805static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
806 struct hda_codec *codec,
807 unsigned int stream_tag,
808 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100809 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200810{
811 struct sigmatel_spec *spec = codec->spec;
Matt Porter403d1942005-11-29 15:00:51 +0100812 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
Matt2f2f4252005-04-13 14:45:30 +0200813}
814
815static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
816 struct hda_codec *codec,
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;
820 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
821}
822
823/*
Mattdabbed62005-06-14 10:19:34 +0200824 * Digital playback callbacks
825 */
826static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
827 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100828 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +0200829{
830 struct sigmatel_spec *spec = codec->spec;
831 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
832}
833
834static int stac92xx_dig_playback_pcm_close(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_close(codec, &spec->multiout);
840}
841
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200842static int stac92xx_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
843 struct hda_codec *codec,
844 unsigned int stream_tag,
845 unsigned int format,
846 struct snd_pcm_substream *substream)
847{
848 struct sigmatel_spec *spec = codec->spec;
849 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
850 stream_tag, format, substream);
851}
852
Mattdabbed62005-06-14 10:19:34 +0200853
854/*
Matt2f2f4252005-04-13 14:45:30 +0200855 * Analog capture callbacks
856 */
857static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
858 struct hda_codec *codec,
859 unsigned int stream_tag,
860 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100861 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200862{
863 struct sigmatel_spec *spec = codec->spec;
864
865 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
866 stream_tag, 0, format);
867 return 0;
868}
869
870static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
871 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100872 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200873{
874 struct sigmatel_spec *spec = codec->spec;
875
876 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 0, 0, 0);
877 return 0;
878}
879
Mattdabbed62005-06-14 10:19:34 +0200880static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
881 .substreams = 1,
882 .channels_min = 2,
883 .channels_max = 2,
884 /* NID is set in stac92xx_build_pcms */
885 .ops = {
886 .open = stac92xx_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200887 .close = stac92xx_dig_playback_pcm_close,
888 .prepare = stac92xx_dig_playback_pcm_prepare
Mattdabbed62005-06-14 10:19:34 +0200889 },
890};
891
892static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
893 .substreams = 1,
894 .channels_min = 2,
895 .channels_max = 2,
896 /* NID is set in stac92xx_build_pcms */
897};
898
Matt2f2f4252005-04-13 14:45:30 +0200899static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
900 .substreams = 1,
901 .channels_min = 2,
Mattc7d4b2f2005-06-27 14:59:41 +0200902 .channels_max = 8,
Matt2f2f4252005-04-13 14:45:30 +0200903 .nid = 0x02, /* NID to query formats and rates */
904 .ops = {
905 .open = stac92xx_playback_pcm_open,
906 .prepare = stac92xx_playback_pcm_prepare,
907 .cleanup = stac92xx_playback_pcm_cleanup
908 },
909};
910
Matt Porter3cc08dc2006-01-23 15:27:49 +0100911static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
912 .substreams = 1,
913 .channels_min = 2,
914 .channels_max = 2,
915 .nid = 0x06, /* NID to query formats and rates */
916 .ops = {
917 .open = stac92xx_playback_pcm_open,
918 .prepare = stac92xx_playback_pcm_prepare,
919 .cleanup = stac92xx_playback_pcm_cleanup
920 },
921};
922
Matt2f2f4252005-04-13 14:45:30 +0200923static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
924 .substreams = 2,
925 .channels_min = 2,
926 .channels_max = 2,
Matt Porter3cc08dc2006-01-23 15:27:49 +0100927 /* NID is set in stac92xx_build_pcms */
Matt2f2f4252005-04-13 14:45:30 +0200928 .ops = {
929 .prepare = stac92xx_capture_pcm_prepare,
930 .cleanup = stac92xx_capture_pcm_cleanup
931 },
932};
933
934static int stac92xx_build_pcms(struct hda_codec *codec)
935{
936 struct sigmatel_spec *spec = codec->spec;
937 struct hda_pcm *info = spec->pcm_rec;
938
939 codec->num_pcms = 1;
940 codec->pcm_info = info;
941
Mattc7d4b2f2005-06-27 14:59:41 +0200942 info->name = "STAC92xx Analog";
Matt2f2f4252005-04-13 14:45:30 +0200943 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
Matt2f2f4252005-04-13 14:45:30 +0200944 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100945 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
946
947 if (spec->alt_switch) {
948 codec->num_pcms++;
949 info++;
950 info->name = "STAC92xx Analog Alt";
951 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
952 }
Matt2f2f4252005-04-13 14:45:30 +0200953
Mattdabbed62005-06-14 10:19:34 +0200954 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
955 codec->num_pcms++;
956 info++;
957 info->name = "STAC92xx Digital";
958 if (spec->multiout.dig_out_nid) {
959 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
960 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
961 }
962 if (spec->dig_in_nid) {
963 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
964 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
965 }
966 }
967
Matt2f2f4252005-04-13 14:45:30 +0200968 return 0;
969}
970
Takashi Iwaic960a032006-03-23 17:06:28 +0100971static unsigned int stac92xx_get_vref(struct hda_codec *codec, hda_nid_t nid)
972{
973 unsigned int pincap = snd_hda_param_read(codec, nid,
974 AC_PAR_PIN_CAP);
975 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
976 if (pincap & AC_PINCAP_VREF_100)
977 return AC_PINCTL_VREF_100;
978 if (pincap & AC_PINCAP_VREF_80)
979 return AC_PINCTL_VREF_80;
980 if (pincap & AC_PINCAP_VREF_50)
981 return AC_PINCTL_VREF_50;
982 if (pincap & AC_PINCAP_VREF_GRD)
983 return AC_PINCTL_VREF_GRD;
984 return 0;
985}
986
Matt Porter403d1942005-11-29 15:00:51 +0100987static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
988
989{
990 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
991}
992
993static int stac92xx_io_switch_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
994{
995 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
996 uinfo->count = 1;
997 uinfo->value.integer.min = 0;
998 uinfo->value.integer.max = 1;
999 return 0;
1000}
1001
1002static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1003{
1004 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1005 struct sigmatel_spec *spec = codec->spec;
1006 int io_idx = kcontrol-> private_value & 0xff;
1007
1008 ucontrol->value.integer.value[0] = spec->io_switch[io_idx];
1009 return 0;
1010}
1011
1012static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1013{
1014 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1015 struct sigmatel_spec *spec = codec->spec;
1016 hda_nid_t nid = kcontrol->private_value >> 8;
1017 int io_idx = kcontrol-> private_value & 0xff;
1018 unsigned short val = ucontrol->value.integer.value[0];
1019
1020 spec->io_switch[io_idx] = val;
1021
1022 if (val)
1023 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
Takashi Iwaic960a032006-03-23 17:06:28 +01001024 else {
1025 unsigned int pinctl = AC_PINCTL_IN_EN;
1026 if (io_idx) /* set VREF for mic */
1027 pinctl |= stac92xx_get_vref(codec, nid);
1028 stac92xx_auto_set_pinctl(codec, nid, pinctl);
1029 }
Matt Porter403d1942005-11-29 15:00:51 +01001030 return 1;
1031}
1032
1033#define STAC_CODEC_IO_SWITCH(xname, xpval) \
1034 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1035 .name = xname, \
1036 .index = 0, \
1037 .info = stac92xx_io_switch_info, \
1038 .get = stac92xx_io_switch_get, \
1039 .put = stac92xx_io_switch_put, \
1040 .private_value = xpval, \
1041 }
1042
1043
Mattc7d4b2f2005-06-27 14:59:41 +02001044enum {
1045 STAC_CTL_WIDGET_VOL,
1046 STAC_CTL_WIDGET_MUTE,
Matt Porter403d1942005-11-29 15:00:51 +01001047 STAC_CTL_WIDGET_IO_SWITCH,
Mattc7d4b2f2005-06-27 14:59:41 +02001048};
1049
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001050static struct snd_kcontrol_new stac92xx_control_templates[] = {
Mattc7d4b2f2005-06-27 14:59:41 +02001051 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
1052 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Matt Porter403d1942005-11-29 15:00:51 +01001053 STAC_CODEC_IO_SWITCH(NULL, 0),
Mattc7d4b2f2005-06-27 14:59:41 +02001054};
1055
1056/* add dynamic controls */
1057static int stac92xx_add_control(struct sigmatel_spec *spec, int type, const char *name, unsigned long val)
1058{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001059 struct snd_kcontrol_new *knew;
Mattc7d4b2f2005-06-27 14:59:41 +02001060
1061 if (spec->num_kctl_used >= spec->num_kctl_alloc) {
1062 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
1063
1064 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */
1065 if (! knew)
1066 return -ENOMEM;
1067 if (spec->kctl_alloc) {
1068 memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
1069 kfree(spec->kctl_alloc);
1070 }
1071 spec->kctl_alloc = knew;
1072 spec->num_kctl_alloc = num;
1073 }
1074
1075 knew = &spec->kctl_alloc[spec->num_kctl_used];
1076 *knew = stac92xx_control_templates[type];
Takashi Iwai82fe0c52005-06-30 10:54:33 +02001077 knew->name = kstrdup(name, GFP_KERNEL);
Mattc7d4b2f2005-06-27 14:59:41 +02001078 if (! knew->name)
1079 return -ENOMEM;
1080 knew->private_value = val;
1081 spec->num_kctl_used++;
1082 return 0;
1083}
1084
Matt Porter403d1942005-11-29 15:00:51 +01001085/* flag inputs as additional dynamic lineouts */
1086static int stac92xx_add_dyn_out_pins(struct hda_codec *codec, struct auto_pin_cfg *cfg)
1087{
1088 struct sigmatel_spec *spec = codec->spec;
Steve Longerbeam7b043892007-05-03 20:50:03 +02001089 unsigned int wcaps, wtype;
1090 int i, num_dacs = 0;
1091
1092 /* use the wcaps cache to count all DACs available for line-outs */
1093 for (i = 0; i < codec->num_nodes; i++) {
1094 wcaps = codec->wcaps[i];
1095 wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
1096 if (wtype == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL))
1097 num_dacs++;
1098 }
Matt Porter403d1942005-11-29 15:00:51 +01001099
Steve Longerbeam7b043892007-05-03 20:50:03 +02001100 snd_printdd("%s: total dac count=%d\n", __func__, num_dacs);
1101
Matt Porter403d1942005-11-29 15:00:51 +01001102 switch (cfg->line_outs) {
1103 case 3:
1104 /* add line-in as side */
Steve Longerbeam7b043892007-05-03 20:50:03 +02001105 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 3) {
Matt Porter403d1942005-11-29 15:00:51 +01001106 cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_LINE];
1107 spec->line_switch = 1;
1108 cfg->line_outs++;
1109 }
1110 break;
1111 case 2:
1112 /* add line-in as clfe and mic as side */
Steve Longerbeam7b043892007-05-03 20:50:03 +02001113 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 2) {
Matt Porter403d1942005-11-29 15:00:51 +01001114 cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_LINE];
1115 spec->line_switch = 1;
1116 cfg->line_outs++;
1117 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02001118 if (cfg->input_pins[AUTO_PIN_MIC] && num_dacs > 3) {
Matt Porter403d1942005-11-29 15:00:51 +01001119 cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_MIC];
1120 spec->mic_switch = 1;
1121 cfg->line_outs++;
1122 }
1123 break;
1124 case 1:
1125 /* add line-in as surr and mic as clfe */
Steve Longerbeam7b043892007-05-03 20:50:03 +02001126 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 1) {
Matt Porter403d1942005-11-29 15:00:51 +01001127 cfg->line_out_pins[1] = cfg->input_pins[AUTO_PIN_LINE];
1128 spec->line_switch = 1;
1129 cfg->line_outs++;
1130 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02001131 if (cfg->input_pins[AUTO_PIN_MIC] && num_dacs > 2) {
Matt Porter403d1942005-11-29 15:00:51 +01001132 cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_MIC];
1133 spec->mic_switch = 1;
1134 cfg->line_outs++;
1135 }
1136 break;
1137 }
1138
1139 return 0;
1140}
1141
Steve Longerbeam7b043892007-05-03 20:50:03 +02001142
1143static int is_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
1144{
1145 int i;
1146
1147 for (i = 0; i < spec->multiout.num_dacs; i++) {
1148 if (spec->multiout.dac_nids[i] == nid)
1149 return 1;
1150 }
1151
1152 return 0;
1153}
1154
Matt Porter3cc08dc2006-01-23 15:27:49 +01001155/*
Steve Longerbeam7b043892007-05-03 20:50:03 +02001156 * Fill in the dac_nids table from the parsed pin configuration
1157 * This function only works when every pin in line_out_pins[]
1158 * contains atleast one DAC in its connection list. Some 92xx
1159 * codecs are not connected directly to a DAC, such as the 9200
1160 * and 9202/925x. For those, dac_nids[] must be hard-coded.
Matt Porter3cc08dc2006-01-23 15:27:49 +01001161 */
Takashi Iwai19039bd2006-06-28 15:52:16 +02001162static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec,
1163 const struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02001164{
1165 struct sigmatel_spec *spec = codec->spec;
Steve Longerbeam7b043892007-05-03 20:50:03 +02001166 int i, j, conn_len = 0;
1167 hda_nid_t nid, conn[HDA_MAX_CONNECTIONS];
1168 unsigned int wcaps, wtype;
1169
Mattc7d4b2f2005-06-27 14:59:41 +02001170 for (i = 0; i < cfg->line_outs; i++) {
1171 nid = cfg->line_out_pins[i];
Steve Longerbeam7b043892007-05-03 20:50:03 +02001172 conn_len = snd_hda_get_connections(codec, nid, conn,
1173 HDA_MAX_CONNECTIONS);
1174 for (j = 0; j < conn_len; j++) {
1175 wcaps = snd_hda_param_read(codec, conn[j],
1176 AC_PAR_AUDIO_WIDGET_CAP);
1177 wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
1178
1179 if (wtype != AC_WID_AUD_OUT ||
1180 (wcaps & AC_WCAP_DIGITAL))
1181 continue;
1182 /* conn[j] is a DAC routed to this line-out */
1183 if (!is_in_dac_nids(spec, conn[j]))
1184 break;
1185 }
1186
1187 if (j == conn_len) {
1188 /* error out, no available DAC found */
1189 snd_printk(KERN_ERR
1190 "%s: No available DAC for pin 0x%x\n",
1191 __func__, nid);
1192 return -ENODEV;
1193 }
1194
1195 spec->multiout.dac_nids[i] = conn[j];
1196 spec->multiout.num_dacs++;
1197 if (conn_len > 1) {
1198 /* select this DAC in the pin's input mux */
1199 snd_hda_codec_write(codec, nid, 0,
1200 AC_VERB_SET_CONNECT_SEL, j);
1201
1202 }
Mattc7d4b2f2005-06-27 14:59:41 +02001203 }
1204
Steve Longerbeam7b043892007-05-03 20:50:03 +02001205 snd_printd("dac_nids=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
1206 spec->multiout.num_dacs,
1207 spec->multiout.dac_nids[0],
1208 spec->multiout.dac_nids[1],
1209 spec->multiout.dac_nids[2],
1210 spec->multiout.dac_nids[3],
1211 spec->multiout.dac_nids[4]);
Mattc7d4b2f2005-06-27 14:59:41 +02001212 return 0;
1213}
1214
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001215/* create volume control/switch for the given prefx type */
1216static int create_controls(struct sigmatel_spec *spec, const char *pfx, hda_nid_t nid, int chs)
1217{
1218 char name[32];
1219 int err;
1220
1221 sprintf(name, "%s Playback Volume", pfx);
1222 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, name,
1223 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1224 if (err < 0)
1225 return err;
1226 sprintf(name, "%s Playback Switch", pfx);
1227 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, name,
1228 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1229 if (err < 0)
1230 return err;
1231 return 0;
1232}
1233
Mattc7d4b2f2005-06-27 14:59:41 +02001234/* add playback controls from the parsed DAC table */
Takashi Iwai19039bd2006-06-28 15:52:16 +02001235static int stac92xx_auto_create_multi_out_ctls(struct sigmatel_spec *spec,
1236 const struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02001237{
Takashi Iwai19039bd2006-06-28 15:52:16 +02001238 static const char *chname[4] = {
1239 "Front", "Surround", NULL /*CLFE*/, "Side"
1240 };
Mattc7d4b2f2005-06-27 14:59:41 +02001241 hda_nid_t nid;
1242 int i, err;
1243
1244 for (i = 0; i < cfg->line_outs; i++) {
Matt Porter403d1942005-11-29 15:00:51 +01001245 if (!spec->multiout.dac_nids[i])
Mattc7d4b2f2005-06-27 14:59:41 +02001246 continue;
1247
1248 nid = spec->multiout.dac_nids[i];
1249
1250 if (i == 2) {
1251 /* Center/LFE */
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001252 err = create_controls(spec, "Center", nid, 1);
1253 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001254 return err;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001255 err = create_controls(spec, "LFE", nid, 2);
1256 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001257 return err;
1258 } else {
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001259 err = create_controls(spec, chname[i], nid, 3);
1260 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001261 return err;
1262 }
1263 }
1264
Matt Porter403d1942005-11-29 15:00:51 +01001265 if (spec->line_switch)
1266 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Line In as Output Switch", cfg->input_pins[AUTO_PIN_LINE] << 8)) < 0)
1267 return err;
1268
1269 if (spec->mic_switch)
1270 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Mic as Output Switch", (cfg->input_pins[AUTO_PIN_MIC] << 8) | 1)) < 0)
1271 return err;
1272
Mattc7d4b2f2005-06-27 14:59:41 +02001273 return 0;
1274}
1275
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001276static int check_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
1277{
Steve Longerbeam7b043892007-05-03 20:50:03 +02001278 if (is_in_dac_nids(spec, nid))
1279 return 1;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001280 if (spec->multiout.hp_nid == nid)
1281 return 1;
1282 return 0;
1283}
1284
1285static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
1286{
1287 if (!spec->multiout.hp_nid)
1288 spec->multiout.hp_nid = nid;
1289 else if (spec->multiout.num_dacs > 4) {
1290 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
1291 return 1;
1292 } else {
1293 spec->multiout.dac_nids[spec->multiout.num_dacs] = nid;
1294 spec->multiout.num_dacs++;
1295 }
1296 return 0;
1297}
1298
1299/* add playback controls for Speaker and HP outputs */
1300static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
1301 struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02001302{
1303 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02001304 hda_nid_t nid;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001305 int i, old_num_dacs, err;
Mattc7d4b2f2005-06-27 14:59:41 +02001306
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001307 old_num_dacs = spec->multiout.num_dacs;
1308 for (i = 0; i < cfg->hp_outs; i++) {
1309 unsigned int wid_caps = get_wcaps(codec, cfg->hp_pins[i]);
1310 if (wid_caps & AC_WCAP_UNSOL_CAP)
1311 spec->hp_detect = 1;
1312 nid = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
1313 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
1314 if (check_in_dac_nids(spec, nid))
1315 nid = 0;
1316 if (! nid)
Mattc7d4b2f2005-06-27 14:59:41 +02001317 continue;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001318 add_spec_dacs(spec, nid);
1319 }
1320 for (i = 0; i < cfg->speaker_outs; i++) {
Steve Longerbeam7b043892007-05-03 20:50:03 +02001321 nid = snd_hda_codec_read(codec, cfg->speaker_pins[i], 0,
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001322 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
1323 if (check_in_dac_nids(spec, nid))
1324 nid = 0;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001325 if (! nid)
1326 continue;
1327 add_spec_dacs(spec, nid);
Mattc7d4b2f2005-06-27 14:59:41 +02001328 }
1329
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001330 for (i = old_num_dacs; i < spec->multiout.num_dacs; i++) {
1331 static const char *pfxs[] = {
1332 "Speaker", "External Speaker", "Speaker2",
1333 };
1334 err = create_controls(spec, pfxs[i - old_num_dacs],
1335 spec->multiout.dac_nids[i], 3);
1336 if (err < 0)
1337 return err;
1338 }
1339 if (spec->multiout.hp_nid) {
1340 const char *pfx;
1341 if (old_num_dacs == spec->multiout.num_dacs)
1342 pfx = "Master";
1343 else
1344 pfx = "Headphone";
1345 err = create_controls(spec, pfx, spec->multiout.hp_nid, 3);
1346 if (err < 0)
1347 return err;
1348 }
Mattc7d4b2f2005-06-27 14:59:41 +02001349
1350 return 0;
1351}
1352
Matt Porter8b657272006-10-26 17:12:59 +02001353/* labels for dmic mux inputs */
Adrian Bunkddc2cec2006-11-20 12:03:44 +01001354static const char *stac92xx_dmic_labels[5] = {
Matt Porter8b657272006-10-26 17:12:59 +02001355 "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
1356 "Digital Mic 3", "Digital Mic 4"
1357};
1358
1359/* create playback/capture controls for input pins on dmic capable codecs */
1360static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
1361 const struct auto_pin_cfg *cfg)
1362{
1363 struct sigmatel_spec *spec = codec->spec;
1364 struct hda_input_mux *dimux = &spec->private_dimux;
1365 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
1366 int i, j;
1367
1368 dimux->items[dimux->num_items].label = stac92xx_dmic_labels[0];
1369 dimux->items[dimux->num_items].index = 0;
1370 dimux->num_items++;
1371
1372 for (i = 0; i < spec->num_dmics; i++) {
1373 int index;
1374 int num_cons;
1375 unsigned int def_conf;
1376
1377 def_conf = snd_hda_codec_read(codec,
1378 spec->dmic_nids[i],
1379 0,
1380 AC_VERB_GET_CONFIG_DEFAULT,
1381 0);
1382 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
1383 continue;
1384
1385 num_cons = snd_hda_get_connections(codec,
1386 spec->dmux_nid,
1387 con_lst,
1388 HDA_MAX_NUM_INPUTS);
1389 for (j = 0; j < num_cons; j++)
1390 if (con_lst[j] == spec->dmic_nids[i]) {
1391 index = j;
1392 goto found;
1393 }
1394 continue;
1395found:
1396 dimux->items[dimux->num_items].label =
1397 stac92xx_dmic_labels[dimux->num_items];
1398 dimux->items[dimux->num_items].index = index;
1399 dimux->num_items++;
1400 }
1401
1402 return 0;
1403}
1404
Mattc7d4b2f2005-06-27 14:59:41 +02001405/* create playback/capture controls for input pins */
1406static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
1407{
1408 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02001409 struct hda_input_mux *imux = &spec->private_imux;
1410 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
1411 int i, j, k;
1412
1413 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwai314634b2006-09-21 11:56:18 +02001414 int index;
Mattc7d4b2f2005-06-27 14:59:41 +02001415
Takashi Iwai314634b2006-09-21 11:56:18 +02001416 if (!cfg->input_pins[i])
1417 continue;
1418 index = -1;
1419 for (j = 0; j < spec->num_muxes; j++) {
1420 int num_cons;
1421 num_cons = snd_hda_get_connections(codec,
1422 spec->mux_nids[j],
1423 con_lst,
1424 HDA_MAX_NUM_INPUTS);
1425 for (k = 0; k < num_cons; k++)
1426 if (con_lst[k] == cfg->input_pins[i]) {
1427 index = k;
1428 goto found;
1429 }
Mattc7d4b2f2005-06-27 14:59:41 +02001430 }
Takashi Iwai314634b2006-09-21 11:56:18 +02001431 continue;
1432 found:
1433 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
1434 imux->items[imux->num_items].index = index;
1435 imux->num_items++;
Mattc7d4b2f2005-06-27 14:59:41 +02001436 }
1437
Steve Longerbeam7b043892007-05-03 20:50:03 +02001438 if (imux->num_items) {
Sam Revitch62fe78e2006-05-10 15:09:17 +02001439 /*
1440 * Set the current input for the muxes.
1441 * The STAC9221 has two input muxes with identical source
1442 * NID lists. Hopefully this won't get confused.
1443 */
1444 for (i = 0; i < spec->num_muxes; i++) {
1445 snd_hda_codec_write(codec, spec->mux_nids[i], 0,
1446 AC_VERB_SET_CONNECT_SEL,
1447 imux->items[0].index);
1448 }
1449 }
1450
Mattc7d4b2f2005-06-27 14:59:41 +02001451 return 0;
1452}
1453
Mattc7d4b2f2005-06-27 14:59:41 +02001454static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
1455{
1456 struct sigmatel_spec *spec = codec->spec;
1457 int i;
1458
1459 for (i = 0; i < spec->autocfg.line_outs; i++) {
1460 hda_nid_t nid = spec->autocfg.line_out_pins[i];
1461 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
1462 }
1463}
1464
1465static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
1466{
1467 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001468 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02001469
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001470 for (i = 0; i < spec->autocfg.hp_outs; i++) {
1471 hda_nid_t pin;
1472 pin = spec->autocfg.hp_pins[i];
1473 if (pin) /* connect to front */
1474 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
1475 }
1476 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
1477 hda_nid_t pin;
1478 pin = spec->autocfg.speaker_pins[i];
1479 if (pin) /* connect to front */
1480 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
1481 }
Mattc7d4b2f2005-06-27 14:59:41 +02001482}
1483
Matt Porter3cc08dc2006-01-23 15:27:49 +01001484static 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 +02001485{
1486 struct sigmatel_spec *spec = codec->spec;
1487 int err;
1488
Matt Porter8b657272006-10-26 17:12:59 +02001489 if ((err = snd_hda_parse_pin_def_config(codec,
1490 &spec->autocfg,
1491 spec->dmic_nids)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001492 return err;
Takashi Iwai82bc9552006-03-21 11:24:42 +01001493 if (! spec->autocfg.line_outs)
Matt Porter869264c2006-01-25 19:20:50 +01001494 return 0; /* can't find valid pin config */
Takashi Iwai19039bd2006-06-28 15:52:16 +02001495
Matt Porter403d1942005-11-29 15:00:51 +01001496 if ((err = stac92xx_add_dyn_out_pins(codec, &spec->autocfg)) < 0)
1497 return err;
Takashi Iwai19039bd2006-06-28 15:52:16 +02001498 if (spec->multiout.num_dacs == 0)
1499 if ((err = stac92xx_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
1500 return err;
Mattc7d4b2f2005-06-27 14:59:41 +02001501
1502 if ((err = stac92xx_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
1503 (err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg)) < 0 ||
1504 (err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
1505 return err;
1506
Matt Porter8b657272006-10-26 17:12:59 +02001507 if (spec->num_dmics > 0)
1508 if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
1509 &spec->autocfg)) < 0)
1510 return err;
1511
Mattc7d4b2f2005-06-27 14:59:41 +02001512 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Matt Porter403d1942005-11-29 15:00:51 +01001513 if (spec->multiout.max_channels > 2)
Mattc7d4b2f2005-06-27 14:59:41 +02001514 spec->surr_switch = 1;
Mattc7d4b2f2005-06-27 14:59:41 +02001515
Takashi Iwai82bc9552006-03-21 11:24:42 +01001516 if (spec->autocfg.dig_out_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01001517 spec->multiout.dig_out_nid = dig_out;
Takashi Iwai82bc9552006-03-21 11:24:42 +01001518 if (spec->autocfg.dig_in_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01001519 spec->dig_in_nid = dig_in;
Mattc7d4b2f2005-06-27 14:59:41 +02001520
1521 if (spec->kctl_alloc)
1522 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
1523
1524 spec->input_mux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02001525 spec->dinput_mux = &spec->private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +02001526
1527 return 1;
1528}
1529
Takashi Iwai82bc9552006-03-21 11:24:42 +01001530/* add playback controls for HP output */
1531static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
1532 struct auto_pin_cfg *cfg)
1533{
1534 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001535 hda_nid_t pin = cfg->hp_pins[0];
Takashi Iwai82bc9552006-03-21 11:24:42 +01001536 unsigned int wid_caps;
1537
1538 if (! pin)
1539 return 0;
1540
1541 wid_caps = get_wcaps(codec, pin);
Takashi Iwai505cb342006-03-27 12:51:52 +02001542 if (wid_caps & AC_WCAP_UNSOL_CAP)
Takashi Iwai82bc9552006-03-21 11:24:42 +01001543 spec->hp_detect = 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +01001544
1545 return 0;
1546}
1547
Richard Fish160ea0d2006-09-06 13:58:25 +02001548/* add playback controls for LFE output */
1549static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
1550 struct auto_pin_cfg *cfg)
1551{
1552 struct sigmatel_spec *spec = codec->spec;
1553 int err;
1554 hda_nid_t lfe_pin = 0x0;
1555 int i;
1556
1557 /*
1558 * search speaker outs and line outs for a mono speaker pin
1559 * with an amp. If one is found, add LFE controls
1560 * for it.
1561 */
1562 for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
1563 hda_nid_t pin = spec->autocfg.speaker_pins[i];
1564 unsigned long wcaps = get_wcaps(codec, pin);
1565 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
1566 if (wcaps == AC_WCAP_OUT_AMP)
1567 /* found a mono speaker with an amp, must be lfe */
1568 lfe_pin = pin;
1569 }
1570
1571 /* if speaker_outs is 0, then speakers may be in line_outs */
1572 if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
1573 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
1574 hda_nid_t pin = spec->autocfg.line_out_pins[i];
1575 unsigned long cfg;
1576 cfg = snd_hda_codec_read(codec, pin, 0,
1577 AC_VERB_GET_CONFIG_DEFAULT,
1578 0x00);
1579 if (get_defcfg_device(cfg) == AC_JACK_SPEAKER) {
1580 unsigned long wcaps = get_wcaps(codec, pin);
1581 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
1582 if (wcaps == AC_WCAP_OUT_AMP)
1583 /* found a mono speaker with an amp,
1584 must be lfe */
1585 lfe_pin = pin;
1586 }
1587 }
1588 }
1589
1590 if (lfe_pin) {
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001591 err = create_controls(spec, "LFE", lfe_pin, 1);
Richard Fish160ea0d2006-09-06 13:58:25 +02001592 if (err < 0)
1593 return err;
1594 }
1595
1596 return 0;
1597}
1598
Mattc7d4b2f2005-06-27 14:59:41 +02001599static int stac9200_parse_auto_config(struct hda_codec *codec)
1600{
1601 struct sigmatel_spec *spec = codec->spec;
1602 int err;
1603
Kailang Yangdf694da2005-12-05 19:42:22 +01001604 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001605 return err;
1606
1607 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
1608 return err;
1609
Takashi Iwai82bc9552006-03-21 11:24:42 +01001610 if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
1611 return err;
1612
Richard Fish160ea0d2006-09-06 13:58:25 +02001613 if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
1614 return err;
1615
Takashi Iwai82bc9552006-03-21 11:24:42 +01001616 if (spec->autocfg.dig_out_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02001617 spec->multiout.dig_out_nid = 0x05;
Takashi Iwai82bc9552006-03-21 11:24:42 +01001618 if (spec->autocfg.dig_in_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02001619 spec->dig_in_nid = 0x04;
Mattc7d4b2f2005-06-27 14:59:41 +02001620
1621 if (spec->kctl_alloc)
1622 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
1623
1624 spec->input_mux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02001625 spec->dinput_mux = &spec->private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +02001626
1627 return 1;
1628}
1629
Sam Revitch62fe78e2006-05-10 15:09:17 +02001630/*
1631 * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
1632 * funky external mute control using GPIO pins.
1633 */
1634
1635static void stac922x_gpio_mute(struct hda_codec *codec, int pin, int muted)
1636{
1637 unsigned int gpiostate, gpiomask, gpiodir;
1638
1639 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
1640 AC_VERB_GET_GPIO_DATA, 0);
1641
1642 if (!muted)
1643 gpiostate |= (1 << pin);
1644 else
1645 gpiostate &= ~(1 << pin);
1646
1647 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
1648 AC_VERB_GET_GPIO_MASK, 0);
1649 gpiomask |= (1 << pin);
1650
1651 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
1652 AC_VERB_GET_GPIO_DIRECTION, 0);
1653 gpiodir |= (1 << pin);
1654
1655 /* AppleHDA seems to do this -- WTF is this verb?? */
1656 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
1657
1658 snd_hda_codec_write(codec, codec->afg, 0,
1659 AC_VERB_SET_GPIO_MASK, gpiomask);
1660 snd_hda_codec_write(codec, codec->afg, 0,
1661 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
1662
1663 msleep(1);
1664
1665 snd_hda_codec_write(codec, codec->afg, 0,
1666 AC_VERB_SET_GPIO_DATA, gpiostate);
1667}
1668
Takashi Iwai314634b2006-09-21 11:56:18 +02001669static void enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
1670 unsigned int event)
1671{
1672 if (get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP)
1673 snd_hda_codec_write(codec, nid, 0,
1674 AC_VERB_SET_UNSOLICITED_ENABLE,
1675 (AC_USRSP_EN | event));
1676}
1677
Mattc7d4b2f2005-06-27 14:59:41 +02001678static int stac92xx_init(struct hda_codec *codec)
1679{
1680 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai82bc9552006-03-21 11:24:42 +01001681 struct auto_pin_cfg *cfg = &spec->autocfg;
1682 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02001683
Mattc7d4b2f2005-06-27 14:59:41 +02001684 snd_hda_sequence_write(codec, spec->init);
1685
Takashi Iwai82bc9552006-03-21 11:24:42 +01001686 /* set up pins */
1687 if (spec->hp_detect) {
Takashi Iwai505cb342006-03-27 12:51:52 +02001688 /* Enable unsolicited responses on the HP widget */
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001689 for (i = 0; i < cfg->hp_outs; i++)
Takashi Iwai314634b2006-09-21 11:56:18 +02001690 enable_pin_detect(codec, cfg->hp_pins[i],
1691 STAC_HP_EVENT);
Takashi Iwai0a07aca2007-03-13 10:40:23 +01001692 /* force to enable the first line-out; the others are set up
1693 * in unsol_event
1694 */
1695 stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
1696 AC_PINCTL_OUT_EN);
Takashi Iwaieb995a82006-09-21 14:28:21 +02001697 stac92xx_auto_init_hp_out(codec);
Takashi Iwai82bc9552006-03-21 11:24:42 +01001698 /* fake event to set up pins */
1699 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
1700 } else {
1701 stac92xx_auto_init_multi_out(codec);
1702 stac92xx_auto_init_hp_out(codec);
1703 }
1704 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwaic960a032006-03-23 17:06:28 +01001705 hda_nid_t nid = cfg->input_pins[i];
1706 if (nid) {
1707 unsigned int pinctl = AC_PINCTL_IN_EN;
1708 if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC)
1709 pinctl |= stac92xx_get_vref(codec, nid);
1710 stac92xx_auto_set_pinctl(codec, nid, pinctl);
1711 }
Takashi Iwai82bc9552006-03-21 11:24:42 +01001712 }
Matt Porter8b657272006-10-26 17:12:59 +02001713 if (spec->num_dmics > 0)
1714 for (i = 0; i < spec->num_dmics; i++)
1715 stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
1716 AC_PINCTL_IN_EN);
1717
Takashi Iwai82bc9552006-03-21 11:24:42 +01001718 if (cfg->dig_out_pin)
1719 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pin,
1720 AC_PINCTL_OUT_EN);
1721 if (cfg->dig_in_pin)
1722 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
1723 AC_PINCTL_IN_EN);
1724
Sam Revitch62fe78e2006-05-10 15:09:17 +02001725 if (spec->gpio_mute) {
1726 stac922x_gpio_mute(codec, 0, 0);
1727 stac922x_gpio_mute(codec, 1, 0);
1728 }
1729
Mattc7d4b2f2005-06-27 14:59:41 +02001730 return 0;
1731}
1732
Matt2f2f4252005-04-13 14:45:30 +02001733static void stac92xx_free(struct hda_codec *codec)
1734{
Mattc7d4b2f2005-06-27 14:59:41 +02001735 struct sigmatel_spec *spec = codec->spec;
1736 int i;
1737
1738 if (! spec)
1739 return;
1740
1741 if (spec->kctl_alloc) {
1742 for (i = 0; i < spec->num_kctl_used; i++)
1743 kfree(spec->kctl_alloc[i].name);
1744 kfree(spec->kctl_alloc);
1745 }
1746
Richard Fish11b44bb2006-08-23 18:31:34 +02001747 if (spec->bios_pin_configs)
1748 kfree(spec->bios_pin_configs);
1749
Mattc7d4b2f2005-06-27 14:59:41 +02001750 kfree(spec);
Matt2f2f4252005-04-13 14:45:30 +02001751}
1752
Matt4e550962005-07-04 17:51:39 +02001753static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
1754 unsigned int flag)
1755{
1756 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
1757 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Steve Longerbeam7b043892007-05-03 20:50:03 +02001758
1759 /* if setting pin direction bits, clear the current
1760 direction bits first */
1761 if (flag & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))
1762 pin_ctl &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
1763
Matt4e550962005-07-04 17:51:39 +02001764 snd_hda_codec_write(codec, nid, 0,
1765 AC_VERB_SET_PIN_WIDGET_CONTROL,
1766 pin_ctl | flag);
1767}
1768
1769static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
1770 unsigned int flag)
1771{
1772 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
1773 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
1774 snd_hda_codec_write(codec, nid, 0,
1775 AC_VERB_SET_PIN_WIDGET_CONTROL,
1776 pin_ctl & ~flag);
1777}
1778
Takashi Iwai314634b2006-09-21 11:56:18 +02001779static int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
1780{
1781 if (!nid)
1782 return 0;
1783 if (snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PIN_SENSE, 0x00)
1784 & (1 << 31))
1785 return 1;
1786 return 0;
1787}
1788
1789static void stac92xx_hp_detect(struct hda_codec *codec, unsigned int res)
Matt4e550962005-07-04 17:51:39 +02001790{
1791 struct sigmatel_spec *spec = codec->spec;
1792 struct auto_pin_cfg *cfg = &spec->autocfg;
1793 int i, presence;
1794
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001795 presence = 0;
1796 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai314634b2006-09-21 11:56:18 +02001797 presence = get_pin_presence(codec, cfg->hp_pins[i]);
1798 if (presence)
1799 break;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001800 }
Matt4e550962005-07-04 17:51:39 +02001801
1802 if (presence) {
1803 /* disable lineouts, enable hp */
1804 for (i = 0; i < cfg->line_outs; i++)
1805 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
1806 AC_PINCTL_OUT_EN);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001807 for (i = 0; i < cfg->speaker_outs; i++)
1808 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
1809 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02001810 } else {
1811 /* enable lineouts, disable hp */
1812 for (i = 0; i < cfg->line_outs; i++)
1813 stac92xx_set_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_set_pinctl(codec, cfg->speaker_pins[i],
1817 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02001818 }
1819}
1820
Takashi Iwai314634b2006-09-21 11:56:18 +02001821static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
1822{
1823 switch (res >> 26) {
1824 case STAC_HP_EVENT:
1825 stac92xx_hp_detect(codec, res);
1826 break;
1827 }
1828}
1829
Mattff6fdc32005-06-27 15:06:52 +02001830#ifdef CONFIG_PM
1831static int stac92xx_resume(struct hda_codec *codec)
1832{
1833 struct sigmatel_spec *spec = codec->spec;
1834 int i;
1835
1836 stac92xx_init(codec);
Richard Fish11b44bb2006-08-23 18:31:34 +02001837 stac92xx_set_config_regs(codec);
Takashi Iwai5d403b12007-05-03 12:32:29 +02001838 snd_hda_resume_ctls(codec, spec->mixer);
Mattff6fdc32005-06-27 15:06:52 +02001839 for (i = 0; i < spec->num_mixers; i++)
1840 snd_hda_resume_ctls(codec, spec->mixers[i]);
1841 if (spec->multiout.dig_out_nid)
1842 snd_hda_resume_spdif_out(codec);
1843 if (spec->dig_in_nid)
1844 snd_hda_resume_spdif_in(codec);
1845
1846 return 0;
1847}
1848#endif
1849
Matt2f2f4252005-04-13 14:45:30 +02001850static struct hda_codec_ops stac92xx_patch_ops = {
1851 .build_controls = stac92xx_build_controls,
1852 .build_pcms = stac92xx_build_pcms,
1853 .init = stac92xx_init,
1854 .free = stac92xx_free,
Matt4e550962005-07-04 17:51:39 +02001855 .unsol_event = stac92xx_unsol_event,
Mattff6fdc32005-06-27 15:06:52 +02001856#ifdef CONFIG_PM
1857 .resume = stac92xx_resume,
1858#endif
Matt2f2f4252005-04-13 14:45:30 +02001859};
1860
1861static int patch_stac9200(struct hda_codec *codec)
1862{
1863 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02001864 int err;
Matt2f2f4252005-04-13 14:45:30 +02001865
Takashi Iwaie560d8d2005-09-09 14:21:46 +02001866 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02001867 if (spec == NULL)
1868 return -ENOMEM;
1869
1870 codec->spec = spec;
Richard Fish11b44bb2006-08-23 18:31:34 +02001871 spec->num_pins = 8;
1872 spec->pin_nids = stac9200_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001873 spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS,
1874 stac9200_models,
1875 stac9200_cfg_tbl);
Richard Fish11b44bb2006-08-23 18:31:34 +02001876 if (spec->board_config < 0) {
1877 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9200, using BIOS defaults\n");
1878 err = stac92xx_save_bios_config_regs(codec);
1879 if (err < 0) {
1880 stac92xx_free(codec);
1881 return err;
1882 }
1883 spec->pin_configs = spec->bios_pin_configs;
1884 } else {
Matt Porter403d1942005-11-29 15:00:51 +01001885 spec->pin_configs = stac9200_brd_tbl[spec->board_config];
1886 stac92xx_set_config_regs(codec);
1887 }
Matt2f2f4252005-04-13 14:45:30 +02001888
1889 spec->multiout.max_channels = 2;
1890 spec->multiout.num_dacs = 1;
1891 spec->multiout.dac_nids = stac9200_dac_nids;
1892 spec->adc_nids = stac9200_adc_nids;
1893 spec->mux_nids = stac9200_mux_nids;
Mattdabbed62005-06-14 10:19:34 +02001894 spec->num_muxes = 1;
Matt Porter8b657272006-10-26 17:12:59 +02001895 spec->num_dmics = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02001896
1897 spec->init = stac9200_core_init;
Matt2f2f4252005-04-13 14:45:30 +02001898 spec->mixer = stac9200_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02001899
1900 err = stac9200_parse_auto_config(codec);
1901 if (err < 0) {
1902 stac92xx_free(codec);
1903 return err;
1904 }
Matt2f2f4252005-04-13 14:45:30 +02001905
1906 codec->patch_ops = stac92xx_patch_ops;
1907
1908 return 0;
1909}
1910
Tobin Davis8e21c342007-01-08 11:04:17 +01001911static int patch_stac925x(struct hda_codec *codec)
1912{
1913 struct sigmatel_spec *spec;
1914 int err;
1915
1916 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1917 if (spec == NULL)
1918 return -ENOMEM;
1919
1920 codec->spec = spec;
1921 spec->num_pins = 8;
1922 spec->pin_nids = stac925x_pin_nids;
1923 spec->board_config = snd_hda_check_board_config(codec, STAC_925x_MODELS,
1924 stac925x_models,
1925 stac925x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01001926 again:
Tobin Davis8e21c342007-01-08 11:04:17 +01001927 if (spec->board_config < 0) {
Tobin Davis2c11f952007-05-17 09:36:34 +02001928 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC925x,"
1929 "using BIOS defaults\n");
Tobin Davis8e21c342007-01-08 11:04:17 +01001930 err = stac92xx_save_bios_config_regs(codec);
1931 if (err < 0) {
1932 stac92xx_free(codec);
1933 return err;
1934 }
1935 spec->pin_configs = spec->bios_pin_configs;
1936 } else if (stac925x_brd_tbl[spec->board_config] != NULL){
1937 spec->pin_configs = stac925x_brd_tbl[spec->board_config];
1938 stac92xx_set_config_regs(codec);
1939 }
1940
1941 spec->multiout.max_channels = 2;
1942 spec->multiout.num_dacs = 1;
1943 spec->multiout.dac_nids = stac925x_dac_nids;
1944 spec->adc_nids = stac925x_adc_nids;
1945 spec->mux_nids = stac925x_mux_nids;
1946 spec->num_muxes = 1;
Tobin Davis2c11f952007-05-17 09:36:34 +02001947 switch (codec->vendor_id) {
1948 case 0x83847632: /* STAC9202 */
1949 case 0x83847633: /* STAC9202D */
1950 case 0x83847636: /* STAC9251 */
1951 case 0x83847637: /* STAC9251D */
1952 spec->num_dmics = 1;
1953 spec->dmic_nids = stac925x_dmic_nids;
1954 break;
1955 default:
1956 spec->num_dmics = 0;
1957 break;
1958 }
Tobin Davis8e21c342007-01-08 11:04:17 +01001959
1960 spec->init = stac925x_core_init;
1961 spec->mixer = stac925x_mixer;
1962
1963 err = stac92xx_parse_auto_config(codec, 0x8, 0x7);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01001964 if (!err) {
1965 if (spec->board_config < 0) {
1966 printk(KERN_WARNING "hda_codec: No auto-config is "
1967 "available, default to model=ref\n");
1968 spec->board_config = STAC_925x_REF;
1969 goto again;
1970 }
1971 err = -EINVAL;
1972 }
Tobin Davis8e21c342007-01-08 11:04:17 +01001973 if (err < 0) {
1974 stac92xx_free(codec);
1975 return err;
1976 }
1977
1978 codec->patch_ops = stac92xx_patch_ops;
1979
1980 return 0;
1981}
1982
Matt2f2f4252005-04-13 14:45:30 +02001983static int patch_stac922x(struct hda_codec *codec)
1984{
1985 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02001986 int err;
Matt2f2f4252005-04-13 14:45:30 +02001987
Takashi Iwaie560d8d2005-09-09 14:21:46 +02001988 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02001989 if (spec == NULL)
1990 return -ENOMEM;
1991
1992 codec->spec = spec;
Richard Fish11b44bb2006-08-23 18:31:34 +02001993 spec->num_pins = 10;
1994 spec->pin_nids = stac922x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001995 spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS,
1996 stac922x_models,
1997 stac922x_cfg_tbl);
Takashi Iwai3fc24d82007-02-16 13:27:18 +01001998 if (spec->board_config == STAC_MACMINI) {
1999 spec->gpio_mute = 1;
2000 /* Intel Macs have all same PCI SSID, so we need to check
2001 * codec SSID to distinguish the exact models
2002 */
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01002003 printk(KERN_INFO "hda_codec: STAC922x, Apple subsys_id=%x\n", codec->subsystem_id);
Takashi Iwai3fc24d82007-02-16 13:27:18 +01002004 switch (codec->subsystem_id) {
Abhijit Bhopatkarc45e20e2007-04-17 11:57:16 +02002005 case 0x106b0a00: /* MacBook First generatoin */
2006 spec->board_config = STAC_MACBOOK;
2007 break;
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01002008 case 0x106b0200: /* MacBook Pro first generation */
2009 spec->board_config = STAC_MACBOOK_PRO_V1;
2010 break;
2011 case 0x106b1e00: /* MacBook Pro second generation */
2012 spec->board_config = STAC_MACBOOK_PRO_V2;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01002013 break;
Sylvain FORETf16928f2007-04-27 14:22:36 +02002014 case 0x106b0700: /* Intel-based iMac */
2015 spec->board_config = STAC_IMAC_INTEL;
2016 break;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01002017 }
2018 }
2019
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002020 again:
Richard Fish11b44bb2006-08-23 18:31:34 +02002021 if (spec->board_config < 0) {
2022 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC922x, "
2023 "using BIOS defaults\n");
2024 err = stac92xx_save_bios_config_regs(codec);
2025 if (err < 0) {
2026 stac92xx_free(codec);
2027 return err;
2028 }
2029 spec->pin_configs = spec->bios_pin_configs;
2030 } else if (stac922x_brd_tbl[spec->board_config] != NULL) {
Matt Porter403d1942005-11-29 15:00:51 +01002031 spec->pin_configs = stac922x_brd_tbl[spec->board_config];
2032 stac92xx_set_config_regs(codec);
2033 }
Matt2f2f4252005-04-13 14:45:30 +02002034
Matt2f2f4252005-04-13 14:45:30 +02002035 spec->adc_nids = stac922x_adc_nids;
2036 spec->mux_nids = stac922x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01002037 spec->num_muxes = ARRAY_SIZE(stac922x_mux_nids);
Matt Porter8b657272006-10-26 17:12:59 +02002038 spec->num_dmics = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02002039
2040 spec->init = stac922x_core_init;
Matt2f2f4252005-04-13 14:45:30 +02002041 spec->mixer = stac922x_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02002042
2043 spec->multiout.dac_nids = spec->dac_nids;
Takashi Iwai19039bd2006-06-28 15:52:16 +02002044
Matt Porter3cc08dc2006-01-23 15:27:49 +01002045 err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002046 if (!err) {
2047 if (spec->board_config < 0) {
2048 printk(KERN_WARNING "hda_codec: No auto-config is "
2049 "available, default to model=ref\n");
2050 spec->board_config = STAC_D945_REF;
2051 goto again;
2052 }
2053 err = -EINVAL;
2054 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01002055 if (err < 0) {
2056 stac92xx_free(codec);
2057 return err;
2058 }
2059
2060 codec->patch_ops = stac92xx_patch_ops;
2061
2062 return 0;
2063}
2064
2065static int patch_stac927x(struct hda_codec *codec)
2066{
2067 struct sigmatel_spec *spec;
2068 int err;
2069
2070 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2071 if (spec == NULL)
2072 return -ENOMEM;
2073
2074 codec->spec = spec;
Richard Fish11b44bb2006-08-23 18:31:34 +02002075 spec->num_pins = 14;
2076 spec->pin_nids = stac927x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002077 spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS,
2078 stac927x_models,
2079 stac927x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002080 again:
Richard Fish11b44bb2006-08-23 18:31:34 +02002081 if (spec->board_config < 0) {
Matt Porter3cc08dc2006-01-23 15:27:49 +01002082 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC927x, using BIOS defaults\n");
Richard Fish11b44bb2006-08-23 18:31:34 +02002083 err = stac92xx_save_bios_config_regs(codec);
2084 if (err < 0) {
2085 stac92xx_free(codec);
2086 return err;
2087 }
2088 spec->pin_configs = spec->bios_pin_configs;
2089 } else if (stac927x_brd_tbl[spec->board_config] != NULL) {
Matt Porter3cc08dc2006-01-23 15:27:49 +01002090 spec->pin_configs = stac927x_brd_tbl[spec->board_config];
2091 stac92xx_set_config_regs(codec);
2092 }
2093
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002094 switch (spec->board_config) {
Tobin Davis93ed1502006-09-01 21:03:12 +02002095 case STAC_D965_3ST:
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002096 spec->adc_nids = stac927x_adc_nids;
2097 spec->mux_nids = stac927x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01002098 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
Matt Porter8b657272006-10-26 17:12:59 +02002099 spec->num_dmics = 0;
Tobin Davis93ed1502006-09-01 21:03:12 +02002100 spec->init = d965_core_init;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002101 spec->mixer = stac9227_mixer;
2102 break;
Tobin Davis93ed1502006-09-01 21:03:12 +02002103 case STAC_D965_5ST:
2104 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;
2111 default:
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 Davis81d3dbd2006-08-22 19:44:45 +02002116 spec->init = stac927x_core_init;
2117 spec->mixer = stac927x_mixer;
2118 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01002119
2120 spec->multiout.dac_nids = spec->dac_nids;
2121
2122 err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002123 if (!err) {
2124 if (spec->board_config < 0) {
2125 printk(KERN_WARNING "hda_codec: No auto-config is "
2126 "available, default to model=ref\n");
2127 spec->board_config = STAC_D965_REF;
2128 goto again;
2129 }
2130 err = -EINVAL;
2131 }
Mattc7d4b2f2005-06-27 14:59:41 +02002132 if (err < 0) {
2133 stac92xx_free(codec);
2134 return err;
2135 }
Matt2f2f4252005-04-13 14:45:30 +02002136
2137 codec->patch_ops = stac92xx_patch_ops;
2138
2139 return 0;
2140}
2141
Matt Porterf3302a52006-07-31 12:49:34 +02002142static int patch_stac9205(struct hda_codec *codec)
2143{
2144 struct sigmatel_spec *spec;
2145 int err;
2146
2147 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2148 if (spec == NULL)
2149 return -ENOMEM;
2150
2151 codec->spec = spec;
Richard Fish11b44bb2006-08-23 18:31:34 +02002152 spec->num_pins = 14;
2153 spec->pin_nids = stac9205_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002154 spec->board_config = snd_hda_check_board_config(codec, STAC_9205_MODELS,
2155 stac9205_models,
2156 stac9205_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002157 again:
Richard Fish11b44bb2006-08-23 18:31:34 +02002158 if (spec->board_config < 0) {
2159 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9205, using BIOS defaults\n");
2160 err = stac92xx_save_bios_config_regs(codec);
2161 if (err < 0) {
2162 stac92xx_free(codec);
2163 return err;
2164 }
2165 spec->pin_configs = spec->bios_pin_configs;
2166 } else {
Matt Porterf3302a52006-07-31 12:49:34 +02002167 spec->pin_configs = stac9205_brd_tbl[spec->board_config];
2168 stac92xx_set_config_regs(codec);
2169 }
2170
2171 spec->adc_nids = stac9205_adc_nids;
2172 spec->mux_nids = stac9205_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01002173 spec->num_muxes = ARRAY_SIZE(stac9205_mux_nids);
Matt Porter8b657272006-10-26 17:12:59 +02002174 spec->dmic_nids = stac9205_dmic_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01002175 spec->num_dmics = ARRAY_SIZE(stac9205_dmic_nids);
Matt Porter8b657272006-10-26 17:12:59 +02002176 spec->dmux_nid = 0x1d;
Matt Porterf3302a52006-07-31 12:49:34 +02002177
2178 spec->init = stac9205_core_init;
2179 spec->mixer = stac9205_mixer;
2180
2181 spec->multiout.dac_nids = spec->dac_nids;
2182
Matt Porter33382402006-12-18 13:17:28 +01002183 /* Configure GPIO0 as EAPD output */
2184 snd_hda_codec_write(codec, codec->afg, 0,
2185 AC_VERB_SET_GPIO_DIRECTION, 0x00000001);
2186 /* Configure GPIO0 as CMOS */
2187 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0x00000000);
2188 /* Assert GPIO0 high */
2189 snd_hda_codec_write(codec, codec->afg, 0,
2190 AC_VERB_SET_GPIO_DATA, 0x00000001);
2191 /* Enable GPIO0 */
2192 snd_hda_codec_write(codec, codec->afg, 0,
2193 AC_VERB_SET_GPIO_MASK, 0x00000001);
2194
Matt Porterf3302a52006-07-31 12:49:34 +02002195 err = stac92xx_parse_auto_config(codec, 0x1f, 0x20);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002196 if (!err) {
2197 if (spec->board_config < 0) {
2198 printk(KERN_WARNING "hda_codec: No auto-config is "
2199 "available, default to model=ref\n");
2200 spec->board_config = STAC_9205_REF;
2201 goto again;
2202 }
2203 err = -EINVAL;
2204 }
Matt Porterf3302a52006-07-31 12:49:34 +02002205 if (err < 0) {
2206 stac92xx_free(codec);
2207 return err;
2208 }
2209
2210 codec->patch_ops = stac92xx_patch_ops;
2211
2212 return 0;
2213}
2214
Matt2f2f4252005-04-13 14:45:30 +02002215/*
Guillaume Munch6d859062006-08-22 17:15:47 +02002216 * STAC9872 hack
Takashi Iwaidb064e52006-03-16 16:04:58 +01002217 */
2218
Guillaume Munch99ccc562006-08-16 19:35:12 +02002219/* static config for Sony VAIO FE550G and Sony VAIO AR */
Takashi Iwaidb064e52006-03-16 16:04:58 +01002220static hda_nid_t vaio_dacs[] = { 0x2 };
2221#define VAIO_HP_DAC 0x5
2222static hda_nid_t vaio_adcs[] = { 0x8 /*,0x6*/ };
2223static hda_nid_t vaio_mux_nids[] = { 0x15 };
2224
2225static struct hda_input_mux vaio_mux = {
2226 .num_items = 2,
2227 .items = {
Takashi Iwaid7737812006-04-25 13:05:43 +02002228 /* { "HP", 0x0 }, */
2229 { "Line", 0x1 },
Takashi Iwaidb064e52006-03-16 16:04:58 +01002230 { "Mic", 0x2 },
2231 { "PCM", 0x3 },
2232 }
2233};
2234
2235static struct hda_verb vaio_init[] = {
2236 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
2237 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
2238 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
2239 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
2240 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
2241 {0x15, AC_VERB_SET_CONNECT_SEL, 0x2}, /* mic-sel: 0a,0d,14,02 */
2242 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
2243 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
2244 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
2245 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
2246 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
2247 {}
2248};
2249
Guillaume Munch6d859062006-08-22 17:15:47 +02002250static struct hda_verb vaio_ar_init[] = {
2251 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
2252 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
2253 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
2254 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
2255/* {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },*/ /* Optical Out */
2256 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
2257 {0x15, AC_VERB_SET_CONNECT_SEL, 0x2}, /* mic-sel: 0a,0d,14,02 */
2258 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
2259 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
2260/* {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},*/ /* Optical Out */
2261 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
2262 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
2263 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
2264 {}
2265};
2266
Takashi Iwaidb064e52006-03-16 16:04:58 +01002267/* bind volumes of both NID 0x02 and 0x05 */
2268static int vaio_master_vol_put(struct snd_kcontrol *kcontrol,
2269 struct snd_ctl_elem_value *ucontrol)
2270{
2271 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2272 long *valp = ucontrol->value.integer.value;
2273 int change;
2274
2275 change = snd_hda_codec_amp_update(codec, 0x02, 0, HDA_OUTPUT, 0,
2276 0x7f, valp[0] & 0x7f);
2277 change |= snd_hda_codec_amp_update(codec, 0x02, 1, HDA_OUTPUT, 0,
2278 0x7f, valp[1] & 0x7f);
2279 snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
2280 0x7f, valp[0] & 0x7f);
2281 snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
2282 0x7f, valp[1] & 0x7f);
2283 return change;
2284}
2285
2286/* bind volumes of both NID 0x02 and 0x05 */
2287static int vaio_master_sw_put(struct snd_kcontrol *kcontrol,
2288 struct snd_ctl_elem_value *ucontrol)
2289{
2290 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2291 long *valp = ucontrol->value.integer.value;
2292 int change;
2293
2294 change = snd_hda_codec_amp_update(codec, 0x02, 0, HDA_OUTPUT, 0,
Takashi Iwaia9393d72006-05-03 11:59:03 +02002295 0x80, (valp[0] ? 0 : 0x80));
Takashi Iwaidb064e52006-03-16 16:04:58 +01002296 change |= snd_hda_codec_amp_update(codec, 0x02, 1, HDA_OUTPUT, 0,
Takashi Iwaia9393d72006-05-03 11:59:03 +02002297 0x80, (valp[1] ? 0 : 0x80));
Takashi Iwaidb064e52006-03-16 16:04:58 +01002298 snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
Takashi Iwaia9393d72006-05-03 11:59:03 +02002299 0x80, (valp[0] ? 0 : 0x80));
Takashi Iwaidb064e52006-03-16 16:04:58 +01002300 snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
Takashi Iwaia9393d72006-05-03 11:59:03 +02002301 0x80, (valp[1] ? 0 : 0x80));
Takashi Iwaidb064e52006-03-16 16:04:58 +01002302 return change;
2303}
2304
2305static struct snd_kcontrol_new vaio_mixer[] = {
2306 {
2307 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2308 .name = "Master Playback Volume",
2309 .info = snd_hda_mixer_amp_volume_info,
2310 .get = snd_hda_mixer_amp_volume_get,
2311 .put = vaio_master_vol_put,
Takashi Iwaic2566522006-08-17 18:21:36 +02002312 .tlv = { .c = snd_hda_mixer_amp_tlv },
Takashi Iwaidb064e52006-03-16 16:04:58 +01002313 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2314 },
2315 {
2316 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2317 .name = "Master Playback Switch",
2318 .info = snd_hda_mixer_amp_switch_info,
2319 .get = snd_hda_mixer_amp_switch_get,
2320 .put = vaio_master_sw_put,
2321 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2322 },
2323 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
2324 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
2325 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
2326 {
2327 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2328 .name = "Capture Source",
2329 .count = 1,
2330 .info = stac92xx_mux_enum_info,
2331 .get = stac92xx_mux_enum_get,
2332 .put = stac92xx_mux_enum_put,
2333 },
2334 {}
2335};
2336
Guillaume Munch6d859062006-08-22 17:15:47 +02002337static struct snd_kcontrol_new vaio_ar_mixer[] = {
2338 {
2339 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2340 .name = "Master Playback Volume",
2341 .info = snd_hda_mixer_amp_volume_info,
2342 .get = snd_hda_mixer_amp_volume_get,
2343 .put = vaio_master_vol_put,
2344 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2345 },
2346 {
2347 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2348 .name = "Master Playback Switch",
2349 .info = snd_hda_mixer_amp_switch_info,
2350 .get = snd_hda_mixer_amp_switch_get,
2351 .put = vaio_master_sw_put,
2352 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2353 },
2354 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
2355 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
2356 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
2357 /*HDA_CODEC_MUTE("Optical Out Switch", 0x10, 0, HDA_OUTPUT),
2358 HDA_CODEC_VOLUME("Optical Out Volume", 0x10, 0, HDA_OUTPUT),*/
2359 {
2360 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2361 .name = "Capture Source",
2362 .count = 1,
2363 .info = stac92xx_mux_enum_info,
2364 .get = stac92xx_mux_enum_get,
2365 .put = stac92xx_mux_enum_put,
2366 },
2367 {}
2368};
2369
2370static struct hda_codec_ops stac9872_patch_ops = {
Takashi Iwaidb064e52006-03-16 16:04:58 +01002371 .build_controls = stac92xx_build_controls,
2372 .build_pcms = stac92xx_build_pcms,
2373 .init = stac92xx_init,
2374 .free = stac92xx_free,
2375#ifdef CONFIG_PM
2376 .resume = stac92xx_resume,
2377#endif
2378};
2379
Guillaume Munch6d859062006-08-22 17:15:47 +02002380enum { /* FE and SZ series. id=0x83847661 and subsys=0x104D0700 or 104D1000. */
2381 CXD9872RD_VAIO,
2382 /* Unknown. id=0x83847662 and subsys=0x104D1200 or 104D1000. */
2383 STAC9872AK_VAIO,
2384 /* Unknown. id=0x83847661 and subsys=0x104D1200. */
2385 STAC9872K_VAIO,
2386 /* AR Series. id=0x83847664 and subsys=104D1300 */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002387 CXD9872AKD_VAIO,
2388 STAC_9872_MODELS,
2389};
Takashi Iwaidb064e52006-03-16 16:04:58 +01002390
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002391static const char *stac9872_models[STAC_9872_MODELS] = {
2392 [CXD9872RD_VAIO] = "vaio",
2393 [CXD9872AKD_VAIO] = "vaio-ar",
2394};
2395
2396static struct snd_pci_quirk stac9872_cfg_tbl[] = {
2397 SND_PCI_QUIRK(0x104d, 0x81e6, "Sony VAIO F/S", CXD9872RD_VAIO),
2398 SND_PCI_QUIRK(0x104d, 0x81ef, "Sony VAIO F/S", CXD9872RD_VAIO),
2399 SND_PCI_QUIRK(0x104d, 0x81fd, "Sony VAIO AR", CXD9872AKD_VAIO),
Tobin Davis68e22542007-03-12 11:36:39 +01002400 SND_PCI_QUIRK(0x104d, 0x8205, "Sony VAIO AR", CXD9872AKD_VAIO),
Takashi Iwaidb064e52006-03-16 16:04:58 +01002401 {}
2402};
2403
Guillaume Munch6d859062006-08-22 17:15:47 +02002404static int patch_stac9872(struct hda_codec *codec)
Takashi Iwaidb064e52006-03-16 16:04:58 +01002405{
2406 struct sigmatel_spec *spec;
2407 int board_config;
2408
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002409 board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
2410 stac9872_models,
2411 stac9872_cfg_tbl);
Takashi Iwaidb064e52006-03-16 16:04:58 +01002412 if (board_config < 0)
2413 /* unknown config, let generic-parser do its job... */
2414 return snd_hda_parse_generic_codec(codec);
2415
2416 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2417 if (spec == NULL)
2418 return -ENOMEM;
2419
2420 codec->spec = spec;
2421 switch (board_config) {
Guillaume Munch6d859062006-08-22 17:15:47 +02002422 case CXD9872RD_VAIO:
2423 case STAC9872AK_VAIO:
2424 case STAC9872K_VAIO:
Takashi Iwaidb064e52006-03-16 16:04:58 +01002425 spec->mixer = vaio_mixer;
2426 spec->init = vaio_init;
2427 spec->multiout.max_channels = 2;
2428 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
2429 spec->multiout.dac_nids = vaio_dacs;
2430 spec->multiout.hp_nid = VAIO_HP_DAC;
2431 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
2432 spec->adc_nids = vaio_adcs;
2433 spec->input_mux = &vaio_mux;
2434 spec->mux_nids = vaio_mux_nids;
2435 break;
Guillaume Munch6d859062006-08-22 17:15:47 +02002436
2437 case CXD9872AKD_VAIO:
2438 spec->mixer = vaio_ar_mixer;
2439 spec->init = vaio_ar_init;
2440 spec->multiout.max_channels = 2;
2441 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
2442 spec->multiout.dac_nids = vaio_dacs;
2443 spec->multiout.hp_nid = VAIO_HP_DAC;
2444 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
2445 spec->adc_nids = vaio_adcs;
2446 spec->input_mux = &vaio_mux;
2447 spec->mux_nids = vaio_mux_nids;
2448 break;
Takashi Iwaidb064e52006-03-16 16:04:58 +01002449 }
2450
Guillaume Munch6d859062006-08-22 17:15:47 +02002451 codec->patch_ops = stac9872_patch_ops;
Takashi Iwaidb064e52006-03-16 16:04:58 +01002452 return 0;
2453}
2454
2455
2456/*
Matt2f2f4252005-04-13 14:45:30 +02002457 * patch entries
2458 */
2459struct hda_codec_preset snd_hda_preset_sigmatel[] = {
2460 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
2461 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
2462 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
2463 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
2464 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
2465 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
2466 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
Matt Porter22a27c72006-07-06 18:49:10 +02002467 { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
2468 { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
2469 { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
2470 { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
2471 { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
2472 { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
Matt Porter3cc08dc2006-01-23 15:27:49 +01002473 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
2474 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
2475 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
2476 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
2477 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
2478 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
2479 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
2480 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
2481 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
2482 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
Tobin Davis8e21c342007-01-08 11:04:17 +01002483 { .id = 0x83847632, .name = "STAC9202", .patch = patch_stac925x },
2484 { .id = 0x83847633, .name = "STAC9202D", .patch = patch_stac925x },
2485 { .id = 0x83847634, .name = "STAC9250", .patch = patch_stac925x },
2486 { .id = 0x83847635, .name = "STAC9250D", .patch = patch_stac925x },
2487 { .id = 0x83847636, .name = "STAC9251", .patch = patch_stac925x },
2488 { .id = 0x83847637, .name = "STAC9250D", .patch = patch_stac925x },
Guillaume Munch6d859062006-08-22 17:15:47 +02002489 /* The following does not take into account .id=0x83847661 when subsys =
2490 * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
2491 * currently not fully supported.
2492 */
2493 { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
2494 { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
2495 { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
Matt Porterf3302a52006-07-31 12:49:34 +02002496 { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
2497 { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
2498 { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
2499 { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
2500 { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
2501 { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
2502 { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
2503 { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
Matt2f2f4252005-04-13 14:45:30 +02002504 {} /* terminator */
2505};