blob: 5ca430cc399a63900427dc96bbec1478cbe876e9 [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,
Matthew Ranostay87d48362007-07-17 11:52:24 +020047 STAC_M43xx,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010048 STAC_9205_MODELS
49};
50
51enum {
Tobin Davis8e21c342007-01-08 11:04:17 +010052 STAC_925x_REF,
53 STAC_M2_2,
54 STAC_MA6,
Tobin Davis2c11f952007-05-17 09:36:34 +020055 STAC_PA6,
Tobin Davis8e21c342007-01-08 11:04:17 +010056 STAC_925x_MODELS
57};
58
59enum {
Takashi Iwaif5fcc132006-11-24 17:07:44 +010060 STAC_D945_REF,
61 STAC_D945GTP3,
62 STAC_D945GTP5,
Takashi Iwai76c08822007-06-19 12:17:42 +020063 STAC_922X_DELL,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +020064 STAC_INTEL_MAC_V1,
65 STAC_INTEL_MAC_V2,
66 STAC_INTEL_MAC_V3,
67 STAC_INTEL_MAC_V4,
68 STAC_INTEL_MAC_V5,
69 /* for backward compitability */
Takashi Iwaif5fcc132006-11-24 17:07:44 +010070 STAC_MACMINI,
Takashi Iwai3fc24d82007-02-16 13:27:18 +010071 STAC_MACBOOK,
Nicolas Boichat6f0778d2007-03-15 12:38:15 +010072 STAC_MACBOOK_PRO_V1,
73 STAC_MACBOOK_PRO_V2,
Sylvain FORETf16928f2007-04-27 14:22:36 +020074 STAC_IMAC_INTEL,
Takashi Iwai0dae0f82007-05-21 12:41:29 +020075 STAC_IMAC_INTEL_20,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010076 STAC_922X_MODELS
77};
78
79enum {
80 STAC_D965_REF,
81 STAC_D965_3ST,
82 STAC_D965_5ST,
83 STAC_927X_MODELS
84};
Matt Porter403d1942005-11-29 15:00:51 +010085
Matt2f2f4252005-04-13 14:45:30 +020086struct sigmatel_spec {
Takashi Iwaic8b6bf92005-11-17 14:57:47 +010087 struct snd_kcontrol_new *mixers[4];
Mattc7d4b2f2005-06-27 14:59:41 +020088 unsigned int num_mixers;
89
Matt Porter403d1942005-11-29 15:00:51 +010090 int board_config;
Mattc7d4b2f2005-06-27 14:59:41 +020091 unsigned int surr_switch: 1;
Matt Porter403d1942005-11-29 15:00:51 +010092 unsigned int line_switch: 1;
93 unsigned int mic_switch: 1;
Matt Porter3cc08dc2006-01-23 15:27:49 +010094 unsigned int alt_switch: 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +010095 unsigned int hp_detect: 1;
Sam Revitch62fe78e2006-05-10 15:09:17 +020096 unsigned int gpio_mute: 1;
Mattc7d4b2f2005-06-27 14:59:41 +020097
Takashi Iwai82599802007-07-31 15:56:24 +020098 unsigned int gpio_mask, gpio_data;
99
Matt2f2f4252005-04-13 14:45:30 +0200100 /* playback */
101 struct hda_multi_out multiout;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100102 hda_nid_t dac_nids[5];
Matt2f2f4252005-04-13 14:45:30 +0200103
104 /* capture */
105 hda_nid_t *adc_nids;
Matt2f2f4252005-04-13 14:45:30 +0200106 unsigned int num_adcs;
Mattdabbed62005-06-14 10:19:34 +0200107 hda_nid_t *mux_nids;
108 unsigned int num_muxes;
Matt Porter8b657272006-10-26 17:12:59 +0200109 hda_nid_t *dmic_nids;
110 unsigned int num_dmics;
111 hda_nid_t dmux_nid;
Mattdabbed62005-06-14 10:19:34 +0200112 hda_nid_t dig_in_nid;
Matt2f2f4252005-04-13 14:45:30 +0200113
Matt2f2f4252005-04-13 14:45:30 +0200114 /* pin widgets */
115 hda_nid_t *pin_nids;
116 unsigned int num_pins;
Matt2f2f4252005-04-13 14:45:30 +0200117 unsigned int *pin_configs;
Richard Fish11b44bb2006-08-23 18:31:34 +0200118 unsigned int *bios_pin_configs;
Matt2f2f4252005-04-13 14:45:30 +0200119
120 /* codec specific stuff */
121 struct hda_verb *init;
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100122 struct snd_kcontrol_new *mixer;
Matt2f2f4252005-04-13 14:45:30 +0200123
124 /* capture source */
Matt Porter8b657272006-10-26 17:12:59 +0200125 struct hda_input_mux *dinput_mux;
126 unsigned int cur_dmux;
Mattc7d4b2f2005-06-27 14:59:41 +0200127 struct hda_input_mux *input_mux;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100128 unsigned int cur_mux[3];
Matt2f2f4252005-04-13 14:45:30 +0200129
Matt Porter403d1942005-11-29 15:00:51 +0100130 /* i/o switches */
131 unsigned int io_switch[2];
Matt2f2f4252005-04-13 14:45:30 +0200132
Mattc7d4b2f2005-06-27 14:59:41 +0200133 struct hda_pcm pcm_rec[2]; /* PCM information */
134
135 /* dynamic controls and input_mux */
136 struct auto_pin_cfg autocfg;
137 unsigned int num_kctl_alloc, num_kctl_used;
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100138 struct snd_kcontrol_new *kctl_alloc;
Matt Porter8b657272006-10-26 17:12:59 +0200139 struct hda_input_mux private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +0200140 struct hda_input_mux private_imux;
Matt2f2f4252005-04-13 14:45:30 +0200141};
142
143static hda_nid_t stac9200_adc_nids[1] = {
144 0x03,
145};
146
147static hda_nid_t stac9200_mux_nids[1] = {
148 0x0c,
149};
150
151static hda_nid_t stac9200_dac_nids[1] = {
152 0x02,
153};
154
Tobin Davis8e21c342007-01-08 11:04:17 +0100155static hda_nid_t stac925x_adc_nids[1] = {
156 0x03,
157};
158
159static hda_nid_t stac925x_mux_nids[1] = {
160 0x0f,
161};
162
163static hda_nid_t stac925x_dac_nids[1] = {
164 0x02,
165};
166
Tobin Davis2c11f952007-05-17 09:36:34 +0200167static hda_nid_t stac925x_dmic_nids[1] = {
168 0x15,
169};
170
Matt2f2f4252005-04-13 14:45:30 +0200171static hda_nid_t stac922x_adc_nids[2] = {
172 0x06, 0x07,
173};
174
175static hda_nid_t stac922x_mux_nids[2] = {
176 0x12, 0x13,
177};
178
Matt Porter3cc08dc2006-01-23 15:27:49 +0100179static hda_nid_t stac927x_adc_nids[3] = {
180 0x07, 0x08, 0x09
181};
182
183static hda_nid_t stac927x_mux_nids[3] = {
184 0x15, 0x16, 0x17
185};
186
Matt Porterf3302a52006-07-31 12:49:34 +0200187static hda_nid_t stac9205_adc_nids[2] = {
188 0x12, 0x13
189};
190
191static hda_nid_t stac9205_mux_nids[2] = {
192 0x19, 0x1a
193};
194
Takashi Iwai25494132007-03-12 12:36:16 +0100195static hda_nid_t stac9205_dmic_nids[2] = {
196 0x17, 0x18,
Matt Porter8b657272006-10-26 17:12:59 +0200197};
198
Mattc7d4b2f2005-06-27 14:59:41 +0200199static hda_nid_t stac9200_pin_nids[8] = {
Tobin Davis93ed1502006-09-01 21:03:12 +0200200 0x08, 0x09, 0x0d, 0x0e,
201 0x0f, 0x10, 0x11, 0x12,
Matt2f2f4252005-04-13 14:45:30 +0200202};
203
Tobin Davis8e21c342007-01-08 11:04:17 +0100204static hda_nid_t stac925x_pin_nids[8] = {
205 0x07, 0x08, 0x0a, 0x0b,
206 0x0c, 0x0d, 0x10, 0x11,
207};
208
Matt2f2f4252005-04-13 14:45:30 +0200209static hda_nid_t stac922x_pin_nids[10] = {
210 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
211 0x0f, 0x10, 0x11, 0x15, 0x1b,
212};
213
Matt Porter3cc08dc2006-01-23 15:27:49 +0100214static hda_nid_t stac927x_pin_nids[14] = {
215 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
216 0x0f, 0x10, 0x11, 0x12, 0x13,
217 0x14, 0x21, 0x22, 0x23,
218};
219
Matt Porterf3302a52006-07-31 12:49:34 +0200220static hda_nid_t stac9205_pin_nids[12] = {
221 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
222 0x0f, 0x14, 0x16, 0x17, 0x18,
223 0x21, 0x22,
Matt Porterf3302a52006-07-31 12:49:34 +0200224};
225
Matt Porter8b657272006-10-26 17:12:59 +0200226static int stac92xx_dmux_enum_info(struct snd_kcontrol *kcontrol,
227 struct snd_ctl_elem_info *uinfo)
228{
229 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
230 struct sigmatel_spec *spec = codec->spec;
231 return snd_hda_input_mux_info(spec->dinput_mux, uinfo);
232}
233
234static int stac92xx_dmux_enum_get(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 ucontrol->value.enumerated.item[0] = spec->cur_dmux;
241 return 0;
242}
243
244static int stac92xx_dmux_enum_put(struct snd_kcontrol *kcontrol,
245 struct snd_ctl_elem_value *ucontrol)
246{
247 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
248 struct sigmatel_spec *spec = codec->spec;
249
250 return snd_hda_input_mux_put(codec, spec->dinput_mux, ucontrol,
251 spec->dmux_nid, &spec->cur_dmux);
252}
253
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100254static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Matt2f2f4252005-04-13 14:45:30 +0200255{
256 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
257 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +0200258 return snd_hda_input_mux_info(spec->input_mux, uinfo);
Matt2f2f4252005-04-13 14:45:30 +0200259}
260
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100261static int stac92xx_mux_enum_get(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
267 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
268 return 0;
269}
270
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100271static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200272{
273 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
274 struct sigmatel_spec *spec = codec->spec;
275 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
276
Mattc7d4b2f2005-06-27 14:59:41 +0200277 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
Matt2f2f4252005-04-13 14:45:30 +0200278 spec->mux_nids[adc_idx], &spec->cur_mux[adc_idx]);
279}
280
Mattc7d4b2f2005-06-27 14:59:41 +0200281static struct hda_verb stac9200_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200282 /* set dac0mux for dac converter */
Mattc7d4b2f2005-06-27 14:59:41 +0200283 { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
Matt2f2f4252005-04-13 14:45:30 +0200284 {}
285};
286
Tobin Davis8e21c342007-01-08 11:04:17 +0100287static struct hda_verb stac925x_core_init[] = {
288 /* set dac0mux for dac converter */
289 { 0x06, AC_VERB_SET_CONNECT_SEL, 0x00},
290 {}
291};
292
Mattc7d4b2f2005-06-27 14:59:41 +0200293static struct hda_verb stac922x_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200294 /* set master volume and direct control */
Mattc7d4b2f2005-06-27 14:59:41 +0200295 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matt2f2f4252005-04-13 14:45:30 +0200296 {}
297};
298
Tobin Davis93ed1502006-09-01 21:03:12 +0200299static struct hda_verb d965_core_init[] = {
Takashi Iwai19039bd2006-06-28 15:52:16 +0200300 /* set master volume and direct control */
Tobin Davis93ed1502006-09-01 21:03:12 +0200301 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Takashi Iwai19039bd2006-06-28 15:52:16 +0200302 /* unmute node 0x1b */
303 { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
304 /* select node 0x03 as DAC */
305 { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
306 {}
307};
308
Matt Porter3cc08dc2006-01-23 15:27:49 +0100309static struct hda_verb stac927x_core_init[] = {
310 /* set master volume and direct control */
311 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
312 {}
313};
314
Matt Porterf3302a52006-07-31 12:49:34 +0200315static struct hda_verb stac9205_core_init[] = {
316 /* set master volume and direct control */
317 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
318 {}
319};
320
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100321static struct snd_kcontrol_new stac9200_mixer[] = {
Matt2f2f4252005-04-13 14:45:30 +0200322 HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
323 HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
324 {
325 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
326 .name = "Input Source",
327 .count = 1,
328 .info = stac92xx_mux_enum_info,
329 .get = stac92xx_mux_enum_get,
330 .put = stac92xx_mux_enum_put,
331 },
332 HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
333 HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
Mattc7d4b2f2005-06-27 14:59:41 +0200334 HDA_CODEC_VOLUME("Capture Mux Volume", 0x0c, 0, HDA_OUTPUT),
Matt2f2f4252005-04-13 14:45:30 +0200335 { } /* end */
336};
337
Tobin Davis8e21c342007-01-08 11:04:17 +0100338static struct snd_kcontrol_new stac925x_mixer[] = {
Tobin Davis8e21c342007-01-08 11:04:17 +0100339 {
340 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
341 .name = "Input Source",
342 .count = 1,
343 .info = stac92xx_mux_enum_info,
344 .get = stac92xx_mux_enum_get,
345 .put = stac92xx_mux_enum_put,
346 },
347 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_OUTPUT),
348 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_OUTPUT),
349 HDA_CODEC_VOLUME("Capture Mux Volume", 0x0f, 0, HDA_OUTPUT),
350 { } /* end */
351};
352
Mattc7d4b2f2005-06-27 14:59:41 +0200353/* This needs to be generated dynamically based on sequence */
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100354static struct snd_kcontrol_new stac922x_mixer[] = {
Matt2f2f4252005-04-13 14:45:30 +0200355 {
356 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
357 .name = "Input Source",
358 .count = 1,
359 .info = stac92xx_mux_enum_info,
360 .get = stac92xx_mux_enum_get,
361 .put = stac92xx_mux_enum_put,
362 },
363 HDA_CODEC_VOLUME("Capture Volume", 0x17, 0x0, HDA_INPUT),
Takashi Iwai0fd17082006-01-13 18:46:21 +0100364 HDA_CODEC_MUTE("Capture Switch", 0x17, 0x0, HDA_INPUT),
Matt2f2f4252005-04-13 14:45:30 +0200365 HDA_CODEC_VOLUME("Mux Capture Volume", 0x12, 0x0, HDA_OUTPUT),
366 { } /* end */
367};
368
Takashi Iwai19039bd2006-06-28 15:52:16 +0200369/* This needs to be generated dynamically based on sequence */
370static struct snd_kcontrol_new stac9227_mixer[] = {
371 {
372 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
373 .name = "Input Source",
374 .count = 1,
375 .info = stac92xx_mux_enum_info,
376 .get = stac92xx_mux_enum_get,
377 .put = stac92xx_mux_enum_put,
378 },
379 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
380 HDA_CODEC_MUTE("Capture Switch", 0x1b, 0x0, HDA_OUTPUT),
381 { } /* end */
382};
383
Takashi Iwaid1d985f2006-11-23 19:27:12 +0100384static struct snd_kcontrol_new stac927x_mixer[] = {
Matt Porter3cc08dc2006-01-23 15:27:49 +0100385 {
386 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
387 .name = "Input Source",
388 .count = 1,
389 .info = stac92xx_mux_enum_info,
390 .get = stac92xx_mux_enum_get,
391 .put = stac92xx_mux_enum_put,
392 },
393 HDA_CODEC_VOLUME("InMux Capture Volume", 0x15, 0x0, HDA_OUTPUT),
394 HDA_CODEC_VOLUME("InVol Capture Volume", 0x18, 0x0, HDA_INPUT),
395 HDA_CODEC_MUTE("ADCMux Capture Switch", 0x1b, 0x0, HDA_OUTPUT),
396 { } /* end */
397};
398
Takashi Iwaid1d985f2006-11-23 19:27:12 +0100399static struct snd_kcontrol_new stac9205_mixer[] = {
Matt Porterf3302a52006-07-31 12:49:34 +0200400 {
401 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Matt Porter8b657272006-10-26 17:12:59 +0200402 .name = "Digital Input Source",
403 .count = 1,
404 .info = stac92xx_dmux_enum_info,
405 .get = stac92xx_dmux_enum_get,
406 .put = stac92xx_dmux_enum_put,
407 },
408 {
409 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Matt Porterf3302a52006-07-31 12:49:34 +0200410 .name = "Input Source",
411 .count = 1,
412 .info = stac92xx_mux_enum_info,
413 .get = stac92xx_mux_enum_get,
414 .put = stac92xx_mux_enum_put,
415 },
416 HDA_CODEC_VOLUME("InMux Capture Volume", 0x19, 0x0, HDA_OUTPUT),
417 HDA_CODEC_VOLUME("InVol Capture Volume", 0x1b, 0x0, HDA_INPUT),
418 HDA_CODEC_MUTE("ADCMux Capture Switch", 0x1d, 0x0, HDA_OUTPUT),
419 { } /* end */
420};
421
Matt2f2f4252005-04-13 14:45:30 +0200422static int stac92xx_build_controls(struct hda_codec *codec)
423{
424 struct sigmatel_spec *spec = codec->spec;
425 int err;
Mattc7d4b2f2005-06-27 14:59:41 +0200426 int i;
Matt2f2f4252005-04-13 14:45:30 +0200427
428 err = snd_hda_add_new_ctls(codec, spec->mixer);
429 if (err < 0)
430 return err;
Mattc7d4b2f2005-06-27 14:59:41 +0200431
432 for (i = 0; i < spec->num_mixers; i++) {
433 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
434 if (err < 0)
435 return err;
436 }
437
Mattdabbed62005-06-14 10:19:34 +0200438 if (spec->multiout.dig_out_nid) {
439 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
440 if (err < 0)
441 return err;
442 }
443 if (spec->dig_in_nid) {
444 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
445 if (err < 0)
446 return err;
447 }
448 return 0;
Matt2f2f4252005-04-13 14:45:30 +0200449}
450
Matt Porter403d1942005-11-29 15:00:51 +0100451static unsigned int ref9200_pin_configs[8] = {
Mattdabbed62005-06-14 10:19:34 +0200452 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
Matt2f2f4252005-04-13 14:45:30 +0200453 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
454};
455
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100456static unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
457 [STAC_REF] = ref9200_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +0100458};
459
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100460static const char *stac9200_models[STAC_9200_MODELS] = {
461 [STAC_REF] = "ref",
462};
463
464static struct snd_pci_quirk stac9200_cfg_tbl[] = {
465 /* SigmaTel reference board */
466 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
467 "DFI LanParty", STAC_REF),
Matt Portere7377072006-11-06 11:20:38 +0100468 /* Dell laptops have BIOS problem */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100469 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01b5,
470 "Dell Inspiron 630m", STAC_REF),
471 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c2,
472 "Dell Latitude D620", STAC_REF),
473 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cb,
474 "Dell Latitude 120L", STAC_REF),
Cory T. Tusar877b8662007-01-30 17:30:55 +0100475 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cc,
476 "Dell Latitude D820", STAC_REF),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +0100477 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cd,
478 "Dell Inspiron E1705/9400", STAC_REF),
479 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ce,
480 "Dell XPS M1710", STAC_REF),
Takashi Iwaif0f96742007-02-14 00:59:17 +0100481 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cf,
482 "Dell Precision M90", STAC_REF),
Daniel T Chen8286c532007-05-15 11:46:23 +0200483 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d6,
484 "unknown Dell", STAC_REF),
Tobin Davis49c605d2007-05-17 09:38:24 +0200485 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d8,
486 "Dell Inspiron 640m", STAC_REF),
487 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f5,
488 "Dell Inspiron 1501", STAC_REF),
489
490 /* Panasonic */
491 SND_PCI_QUIRK(0x10f7, 0x8338, "Panasonic CF-74", STAC_REF),
492
Matt Porter403d1942005-11-29 15:00:51 +0100493 {} /* terminator */
494};
495
Tobin Davis8e21c342007-01-08 11:04:17 +0100496static unsigned int ref925x_pin_configs[8] = {
497 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
498 0x90a70320, 0x02214210, 0x400003f1, 0x9033032e,
499};
500
501static unsigned int stac925x_MA6_pin_configs[8] = {
502 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
503 0x90a70320, 0x90100211, 0x400003f1, 0x9033032e,
504};
505
Tobin Davis2c11f952007-05-17 09:36:34 +0200506static unsigned int stac925x_PA6_pin_configs[8] = {
507 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
508 0x50a103f0, 0x90100211, 0x400003f1, 0x9033032e,
509};
510
Tobin Davis8e21c342007-01-08 11:04:17 +0100511static unsigned int stac925xM2_2_pin_configs[8] = {
Steve Longerbeam7353e142007-05-29 14:36:17 +0200512 0x40c003f3, 0x424503f2, 0x04180011, 0x02a19020,
513 0x50a103f0, 0x90100212, 0x400003f1, 0x9033032e,
Tobin Davis8e21c342007-01-08 11:04:17 +0100514};
515
516static unsigned int *stac925x_brd_tbl[STAC_925x_MODELS] = {
517 [STAC_REF] = ref925x_pin_configs,
518 [STAC_M2_2] = stac925xM2_2_pin_configs,
519 [STAC_MA6] = stac925x_MA6_pin_configs,
Tobin Davis2c11f952007-05-17 09:36:34 +0200520 [STAC_PA6] = stac925x_PA6_pin_configs,
Tobin Davis8e21c342007-01-08 11:04:17 +0100521};
522
523static const char *stac925x_models[STAC_925x_MODELS] = {
524 [STAC_REF] = "ref",
525 [STAC_M2_2] = "m2-2",
526 [STAC_MA6] = "m6",
Tobin Davis2c11f952007-05-17 09:36:34 +0200527 [STAC_PA6] = "pa6",
Tobin Davis8e21c342007-01-08 11:04:17 +0100528};
529
530static struct snd_pci_quirk stac925x_cfg_tbl[] = {
531 /* SigmaTel reference board */
532 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, "DFI LanParty", STAC_REF),
Tobin Davis2c11f952007-05-17 09:36:34 +0200533 SND_PCI_QUIRK(0x8384, 0x7632, "Stac9202 Reference Board", STAC_REF),
Tobin Davis8e21c342007-01-08 11:04:17 +0100534 SND_PCI_QUIRK(0x107b, 0x0316, "Gateway M255", STAC_REF),
535 SND_PCI_QUIRK(0x107b, 0x0366, "Gateway MP6954", STAC_REF),
536 SND_PCI_QUIRK(0x107b, 0x0461, "Gateway NX560XL", STAC_MA6),
Tobin Davis2c11f952007-05-17 09:36:34 +0200537 SND_PCI_QUIRK(0x107b, 0x0681, "Gateway NX860", STAC_PA6),
Tobin Davis8e21c342007-01-08 11:04:17 +0100538 SND_PCI_QUIRK(0x1002, 0x437b, "Gateway MX6453", STAC_M2_2),
539 {} /* terminator */
540};
541
Matt Porter403d1942005-11-29 15:00:51 +0100542static unsigned int ref922x_pin_configs[10] = {
543 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
544 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
Matt2f2f4252005-04-13 14:45:30 +0200545 0x40000100, 0x40000100,
546};
547
Matt Porter403d1942005-11-29 15:00:51 +0100548static unsigned int d945gtp3_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +0100549 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
Matt Porter403d1942005-11-29 15:00:51 +0100550 0x40000100, 0x40000100, 0x40000100, 0x40000100,
551 0x02a19120, 0x40000100,
552};
553
554static unsigned int d945gtp5_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +0100555 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
556 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
Matt Porter403d1942005-11-29 15:00:51 +0100557 0x02a19320, 0x40000100,
558};
559
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +0200560static unsigned int intel_mac_v1_pin_configs[10] = {
561 0x0121e21f, 0x400000ff, 0x9017e110, 0x400000fd,
562 0x400000fe, 0x0181e020, 0x1145e030, 0x11c5e240,
Takashi Iwai3fc24d82007-02-16 13:27:18 +0100563 0x400000fc, 0x400000fb,
564};
565
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +0200566static unsigned int intel_mac_v2_pin_configs[10] = {
567 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
568 0x400000fe, 0x0181e020, 0x1145e230, 0x500000fa,
Sylvain FORETf16928f2007-04-27 14:22:36 +0200569 0x400000fc, 0x400000fb,
570};
571
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +0200572static unsigned int intel_mac_v3_pin_configs[10] = {
573 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
574 0x400000fe, 0x0181e020, 0x1145e230, 0x11c5e240,
575 0x400000fc, 0x400000fb,
576};
577
578static unsigned int intel_mac_v4_pin_configs[10] = {
579 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
580 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
581 0x400000fc, 0x400000fb,
582};
583
584static unsigned int intel_mac_v5_pin_configs[10] = {
585 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
586 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
587 0x400000fc, 0x400000fb,
Takashi Iwai0dae0f82007-05-21 12:41:29 +0200588};
589
Takashi Iwai76c08822007-06-19 12:17:42 +0200590static unsigned int stac922x_dell_pin_configs[10] = {
591 0x0221121e, 0x408103ff, 0x02a1123e, 0x90100310,
592 0x408003f1, 0x0221122f, 0x03451340, 0x40c003f2,
593 0x50a003f3, 0x405003f4
594};
595
Takashi Iwai19039bd2006-06-28 15:52:16 +0200596static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100597 [STAC_D945_REF] = ref922x_pin_configs,
Takashi Iwai19039bd2006-06-28 15:52:16 +0200598 [STAC_D945GTP3] = d945gtp3_pin_configs,
599 [STAC_D945GTP5] = d945gtp5_pin_configs,
Takashi Iwai76c08822007-06-19 12:17:42 +0200600 [STAC_922X_DELL] = stac922x_dell_pin_configs,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +0200601 [STAC_INTEL_MAC_V1] = intel_mac_v1_pin_configs,
602 [STAC_INTEL_MAC_V2] = intel_mac_v2_pin_configs,
603 [STAC_INTEL_MAC_V3] = intel_mac_v3_pin_configs,
604 [STAC_INTEL_MAC_V4] = intel_mac_v4_pin_configs,
605 [STAC_INTEL_MAC_V5] = intel_mac_v5_pin_configs,
606 /* for backward compitability */
607 [STAC_MACMINI] = intel_mac_v3_pin_configs,
608 [STAC_MACBOOK] = intel_mac_v5_pin_configs,
609 [STAC_MACBOOK_PRO_V1] = intel_mac_v3_pin_configs,
610 [STAC_MACBOOK_PRO_V2] = intel_mac_v3_pin_configs,
611 [STAC_IMAC_INTEL] = intel_mac_v2_pin_configs,
612 [STAC_IMAC_INTEL_20] = intel_mac_v3_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +0100613};
614
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100615static const char *stac922x_models[STAC_922X_MODELS] = {
616 [STAC_D945_REF] = "ref",
617 [STAC_D945GTP5] = "5stack",
618 [STAC_D945GTP3] = "3stack",
Takashi Iwai76c08822007-06-19 12:17:42 +0200619 [STAC_922X_DELL] = "dell",
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +0200620 [STAC_INTEL_MAC_V1] = "intel-mac-v1",
621 [STAC_INTEL_MAC_V2] = "intel-mac-v2",
622 [STAC_INTEL_MAC_V3] = "intel-mac-v3",
623 [STAC_INTEL_MAC_V4] = "intel-mac-v4",
624 [STAC_INTEL_MAC_V5] = "intel-mac-v5",
625 /* for backward compitability */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100626 [STAC_MACMINI] = "macmini",
Takashi Iwai3fc24d82007-02-16 13:27:18 +0100627 [STAC_MACBOOK] = "macbook",
Nicolas Boichat6f0778d2007-03-15 12:38:15 +0100628 [STAC_MACBOOK_PRO_V1] = "macbook-pro-v1",
629 [STAC_MACBOOK_PRO_V2] = "macbook-pro",
Sylvain FORETf16928f2007-04-27 14:22:36 +0200630 [STAC_IMAC_INTEL] = "imac-intel",
Takashi Iwai0dae0f82007-05-21 12:41:29 +0200631 [STAC_IMAC_INTEL_20] = "imac-intel-20",
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100632};
633
634static struct snd_pci_quirk stac922x_cfg_tbl[] = {
635 /* SigmaTel reference board */
636 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
637 "DFI LanParty", STAC_D945_REF),
638 /* Intel 945G based systems */
639 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101,
640 "Intel D945G", STAC_D945GTP3),
641 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0202,
642 "Intel D945G", STAC_D945GTP3),
643 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0606,
644 "Intel D945G", STAC_D945GTP3),
645 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0601,
646 "Intel D945G", STAC_D945GTP3),
647 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0111,
648 "Intel D945G", STAC_D945GTP3),
649 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1115,
650 "Intel D945G", STAC_D945GTP3),
651 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1116,
652 "Intel D945G", STAC_D945GTP3),
653 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1117,
654 "Intel D945G", STAC_D945GTP3),
655 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1118,
656 "Intel D945G", STAC_D945GTP3),
657 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1119,
658 "Intel D945G", STAC_D945GTP3),
659 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x8826,
660 "Intel D945G", STAC_D945GTP3),
661 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5049,
662 "Intel D945G", STAC_D945GTP3),
663 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5055,
664 "Intel D945G", STAC_D945GTP3),
665 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5048,
666 "Intel D945G", STAC_D945GTP3),
667 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0110,
668 "Intel D945G", STAC_D945GTP3),
669 /* Intel D945G 5-stack systems */
670 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0404,
671 "Intel D945G", STAC_D945GTP5),
672 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0303,
673 "Intel D945G", STAC_D945GTP5),
674 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0013,
675 "Intel D945G", STAC_D945GTP5),
676 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0417,
677 "Intel D945G", STAC_D945GTP5),
678 /* Intel 945P based systems */
679 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0b0b,
680 "Intel D945P", STAC_D945GTP3),
681 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0112,
682 "Intel D945P", STAC_D945GTP3),
683 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0d0d,
684 "Intel D945P", STAC_D945GTP3),
685 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0909,
686 "Intel D945P", STAC_D945GTP3),
687 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0505,
688 "Intel D945P", STAC_D945GTP3),
689 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707,
690 "Intel D945P", STAC_D945GTP5),
691 /* other systems */
692 /* Apple Mac Mini (early 2006) */
693 SND_PCI_QUIRK(0x8384, 0x7680,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +0200694 "Mac Mini", STAC_INTEL_MAC_V3),
Takashi Iwai76c08822007-06-19 12:17:42 +0200695 /* Dell */
696 SND_PCI_QUIRK(0x1028, 0x01d7, "Dell XPS M1210", STAC_922X_DELL),
697
Matt Porter403d1942005-11-29 15:00:51 +0100698 {} /* terminator */
699};
700
Matt Porter3cc08dc2006-01-23 15:27:49 +0100701static unsigned int ref927x_pin_configs[14] = {
Tobin Davis93ed1502006-09-01 21:03:12 +0200702 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
703 0x01a19040, 0x01011012, 0x01016011, 0x0101201f,
704 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
705 0x01c42190, 0x40000100,
Matt Porter3cc08dc2006-01-23 15:27:49 +0100706};
707
Tobin Davis93ed1502006-09-01 21:03:12 +0200708static unsigned int d965_3st_pin_configs[14] = {
Tobin Davis81d3dbd2006-08-22 19:44:45 +0200709 0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
710 0x01a19021, 0x01813024, 0x40000100, 0x40000100,
711 0x40000100, 0x40000100, 0x40000100, 0x40000100,
712 0x40000100, 0x40000100
713};
714
Tobin Davis93ed1502006-09-01 21:03:12 +0200715static unsigned int d965_5st_pin_configs[14] = {
716 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
717 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
718 0x40000100, 0x40000100, 0x40000100, 0x01442070,
719 0x40000100, 0x40000100
720};
721
722static unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100723 [STAC_D965_REF] = ref927x_pin_configs,
Tobin Davis93ed1502006-09-01 21:03:12 +0200724 [STAC_D965_3ST] = d965_3st_pin_configs,
725 [STAC_D965_5ST] = d965_5st_pin_configs,
Matt Porter3cc08dc2006-01-23 15:27:49 +0100726};
727
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100728static const char *stac927x_models[STAC_927X_MODELS] = {
729 [STAC_D965_REF] = "ref",
730 [STAC_D965_3ST] = "3stack",
731 [STAC_D965_5ST] = "5stack",
732};
733
734static struct snd_pci_quirk stac927x_cfg_tbl[] = {
735 /* SigmaTel reference board */
736 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
737 "DFI LanParty", STAC_D965_REF),
Tobin Davis81d3dbd2006-08-22 19:44:45 +0200738 /* Intel 946 based systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100739 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST),
740 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST),
Tobin Davis93ed1502006-09-01 21:03:12 +0200741 /* 965 based 3 stack systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100742 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2116, "Intel D965", STAC_D965_3ST),
743 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2115, "Intel D965", STAC_D965_3ST),
744 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2114, "Intel D965", STAC_D965_3ST),
745 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2113, "Intel D965", STAC_D965_3ST),
746 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2112, "Intel D965", STAC_D965_3ST),
747 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2111, "Intel D965", STAC_D965_3ST),
748 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2110, "Intel D965", STAC_D965_3ST),
749 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2009, "Intel D965", STAC_D965_3ST),
750 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2008, "Intel D965", STAC_D965_3ST),
751 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2007, "Intel D965", STAC_D965_3ST),
752 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2006, "Intel D965", STAC_D965_3ST),
753 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2005, "Intel D965", STAC_D965_3ST),
754 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2004, "Intel D965", STAC_D965_3ST),
755 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2003, "Intel D965", STAC_D965_3ST),
756 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2002, "Intel D965", STAC_D965_3ST),
757 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2001, "Intel D965", STAC_D965_3ST),
Tobin Davis93ed1502006-09-01 21:03:12 +0200758 /* 965 based 5 stack systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100759 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2301, "Intel D965", STAC_D965_5ST),
760 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2302, "Intel D965", STAC_D965_5ST),
761 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2303, "Intel D965", STAC_D965_5ST),
762 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2304, "Intel D965", STAC_D965_5ST),
763 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2305, "Intel D965", STAC_D965_5ST),
764 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2501, "Intel D965", STAC_D965_5ST),
765 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2502, "Intel D965", STAC_D965_5ST),
766 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2503, "Intel D965", STAC_D965_5ST),
767 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2504, "Intel D965", STAC_D965_5ST),
Matt Porter3cc08dc2006-01-23 15:27:49 +0100768 {} /* terminator */
769};
770
Matt Porterf3302a52006-07-31 12:49:34 +0200771static unsigned int ref9205_pin_configs[12] = {
772 0x40000100, 0x40000100, 0x01016011, 0x01014010,
Matt Porter8b657272006-10-26 17:12:59 +0200773 0x01813122, 0x01a19021, 0x40000100, 0x40000100,
774 0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
Matt Porterf3302a52006-07-31 12:49:34 +0200775};
776
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100777static unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
Matthew Ranostay87d48362007-07-17 11:52:24 +0200778 [STAC_REF] = ref9205_pin_configs,
779 [STAC_M43xx] = NULL,
Matt Porterf3302a52006-07-31 12:49:34 +0200780};
781
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100782static const char *stac9205_models[STAC_9205_MODELS] = {
783 [STAC_9205_REF] = "ref",
784};
785
786static struct snd_pci_quirk stac9205_cfg_tbl[] = {
787 /* SigmaTel reference board */
788 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
789 "DFI LanParty", STAC_9205_REF),
Matthew Ranostay87d48362007-07-17 11:52:24 +0200790 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x01f8,
791 "Dell Precision", STAC_M43xx),
792 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x01ff,
793 "Dell Precision", STAC_M43xx),
Matt Porterf3302a52006-07-31 12:49:34 +0200794 {} /* terminator */
795};
796
Richard Fish11b44bb2006-08-23 18:31:34 +0200797static int stac92xx_save_bios_config_regs(struct hda_codec *codec)
798{
799 int i;
800 struct sigmatel_spec *spec = codec->spec;
801
802 if (! spec->bios_pin_configs) {
803 spec->bios_pin_configs = kcalloc(spec->num_pins,
804 sizeof(*spec->bios_pin_configs), GFP_KERNEL);
805 if (! spec->bios_pin_configs)
806 return -ENOMEM;
807 }
808
809 for (i = 0; i < spec->num_pins; i++) {
810 hda_nid_t nid = spec->pin_nids[i];
811 unsigned int pin_cfg;
812
813 pin_cfg = snd_hda_codec_read(codec, nid, 0,
814 AC_VERB_GET_CONFIG_DEFAULT, 0x00);
815 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x bios pin config %8.8x\n",
816 nid, pin_cfg);
817 spec->bios_pin_configs[i] = pin_cfg;
818 }
819
820 return 0;
821}
822
Matthew Ranostay87d48362007-07-17 11:52:24 +0200823static void stac92xx_set_config_reg(struct hda_codec *codec,
824 hda_nid_t pin_nid, unsigned int pin_config)
825{
826 int i;
827 snd_hda_codec_write(codec, pin_nid, 0,
828 AC_VERB_SET_CONFIG_DEFAULT_BYTES_0,
829 pin_config & 0x000000ff);
830 snd_hda_codec_write(codec, pin_nid, 0,
831 AC_VERB_SET_CONFIG_DEFAULT_BYTES_1,
832 (pin_config & 0x0000ff00) >> 8);
833 snd_hda_codec_write(codec, pin_nid, 0,
834 AC_VERB_SET_CONFIG_DEFAULT_BYTES_2,
835 (pin_config & 0x00ff0000) >> 16);
836 snd_hda_codec_write(codec, pin_nid, 0,
837 AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
838 pin_config >> 24);
839 i = snd_hda_codec_read(codec, pin_nid, 0,
840 AC_VERB_GET_CONFIG_DEFAULT,
841 0x00);
842 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x pin config %8.8x\n",
843 pin_nid, i);
844}
845
Matt2f2f4252005-04-13 14:45:30 +0200846static void stac92xx_set_config_regs(struct hda_codec *codec)
847{
848 int i;
849 struct sigmatel_spec *spec = codec->spec;
Matt2f2f4252005-04-13 14:45:30 +0200850
Matthew Ranostay87d48362007-07-17 11:52:24 +0200851 if (!spec->pin_configs)
852 return;
Richard Fish11b44bb2006-08-23 18:31:34 +0200853
Matthew Ranostay87d48362007-07-17 11:52:24 +0200854 for (i = 0; i < spec->num_pins; i++)
855 stac92xx_set_config_reg(codec, spec->pin_nids[i],
856 spec->pin_configs[i]);
Matt2f2f4252005-04-13 14:45:30 +0200857}
Matt2f2f4252005-04-13 14:45:30 +0200858
Takashi Iwai82599802007-07-31 15:56:24 +0200859static void stac92xx_enable_gpio_mask(struct hda_codec *codec)
Matthew Ranostay92a22be2007-06-19 16:48:28 +0200860{
Takashi Iwai82599802007-07-31 15:56:24 +0200861 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay87d48362007-07-17 11:52:24 +0200862 /* Configure GPIOx as output */
Matthew Ranostay92a22be2007-06-19 16:48:28 +0200863 snd_hda_codec_write(codec, codec->afg, 0,
Takashi Iwai82599802007-07-31 15:56:24 +0200864 AC_VERB_SET_GPIO_DIRECTION, spec->gpio_mask);
Matthew Ranostay87d48362007-07-17 11:52:24 +0200865 /* Configure GPIOx as CMOS */
Matthew Ranostay92a22be2007-06-19 16:48:28 +0200866 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0x00000000);
Matthew Ranostay87d48362007-07-17 11:52:24 +0200867 /* Assert GPIOx */
Matthew Ranostay92a22be2007-06-19 16:48:28 +0200868 snd_hda_codec_write(codec, codec->afg, 0,
Takashi Iwai82599802007-07-31 15:56:24 +0200869 AC_VERB_SET_GPIO_DATA, spec->gpio_data);
Matthew Ranostay87d48362007-07-17 11:52:24 +0200870 /* Enable GPIOx */
Matthew Ranostay92a22be2007-06-19 16:48:28 +0200871 snd_hda_codec_write(codec, codec->afg, 0,
Takashi Iwai82599802007-07-31 15:56:24 +0200872 AC_VERB_SET_GPIO_MASK, spec->gpio_mask);
Matthew Ranostay92a22be2007-06-19 16:48:28 +0200873}
874
Matt2f2f4252005-04-13 14:45:30 +0200875/*
876 * Analog playback callbacks
877 */
878static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
879 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100880 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200881{
882 struct sigmatel_spec *spec = codec->spec;
883 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
884}
885
886static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
887 struct hda_codec *codec,
888 unsigned int stream_tag,
889 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100890 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200891{
892 struct sigmatel_spec *spec = codec->spec;
Matt Porter403d1942005-11-29 15:00:51 +0100893 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
Matt2f2f4252005-04-13 14:45:30 +0200894}
895
896static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
897 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100898 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200899{
900 struct sigmatel_spec *spec = codec->spec;
901 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
902}
903
904/*
Mattdabbed62005-06-14 10:19:34 +0200905 * Digital playback callbacks
906 */
907static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
908 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100909 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +0200910{
911 struct sigmatel_spec *spec = codec->spec;
912 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
913}
914
915static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
916 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100917 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +0200918{
919 struct sigmatel_spec *spec = codec->spec;
920 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
921}
922
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200923static int stac92xx_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
924 struct hda_codec *codec,
925 unsigned int stream_tag,
926 unsigned int format,
927 struct snd_pcm_substream *substream)
928{
929 struct sigmatel_spec *spec = codec->spec;
930 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
931 stream_tag, format, substream);
932}
933
Mattdabbed62005-06-14 10:19:34 +0200934
935/*
Matt2f2f4252005-04-13 14:45:30 +0200936 * Analog capture callbacks
937 */
938static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
939 struct hda_codec *codec,
940 unsigned int stream_tag,
941 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100942 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200943{
944 struct sigmatel_spec *spec = codec->spec;
945
946 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
947 stream_tag, 0, format);
948 return 0;
949}
950
951static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
952 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100953 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200954{
955 struct sigmatel_spec *spec = codec->spec;
956
957 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 0, 0, 0);
958 return 0;
959}
960
Mattdabbed62005-06-14 10:19:34 +0200961static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
962 .substreams = 1,
963 .channels_min = 2,
964 .channels_max = 2,
965 /* NID is set in stac92xx_build_pcms */
966 .ops = {
967 .open = stac92xx_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200968 .close = stac92xx_dig_playback_pcm_close,
969 .prepare = stac92xx_dig_playback_pcm_prepare
Mattdabbed62005-06-14 10:19:34 +0200970 },
971};
972
973static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
974 .substreams = 1,
975 .channels_min = 2,
976 .channels_max = 2,
977 /* NID is set in stac92xx_build_pcms */
978};
979
Matt2f2f4252005-04-13 14:45:30 +0200980static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
981 .substreams = 1,
982 .channels_min = 2,
Mattc7d4b2f2005-06-27 14:59:41 +0200983 .channels_max = 8,
Matt2f2f4252005-04-13 14:45:30 +0200984 .nid = 0x02, /* NID to query formats and rates */
985 .ops = {
986 .open = stac92xx_playback_pcm_open,
987 .prepare = stac92xx_playback_pcm_prepare,
988 .cleanup = stac92xx_playback_pcm_cleanup
989 },
990};
991
Matt Porter3cc08dc2006-01-23 15:27:49 +0100992static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
993 .substreams = 1,
994 .channels_min = 2,
995 .channels_max = 2,
996 .nid = 0x06, /* NID to query formats and rates */
997 .ops = {
998 .open = stac92xx_playback_pcm_open,
999 .prepare = stac92xx_playback_pcm_prepare,
1000 .cleanup = stac92xx_playback_pcm_cleanup
1001 },
1002};
1003
Matt2f2f4252005-04-13 14:45:30 +02001004static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
1005 .substreams = 2,
1006 .channels_min = 2,
1007 .channels_max = 2,
Matt Porter3cc08dc2006-01-23 15:27:49 +01001008 /* NID is set in stac92xx_build_pcms */
Matt2f2f4252005-04-13 14:45:30 +02001009 .ops = {
1010 .prepare = stac92xx_capture_pcm_prepare,
1011 .cleanup = stac92xx_capture_pcm_cleanup
1012 },
1013};
1014
1015static int stac92xx_build_pcms(struct hda_codec *codec)
1016{
1017 struct sigmatel_spec *spec = codec->spec;
1018 struct hda_pcm *info = spec->pcm_rec;
1019
1020 codec->num_pcms = 1;
1021 codec->pcm_info = info;
1022
Mattc7d4b2f2005-06-27 14:59:41 +02001023 info->name = "STAC92xx Analog";
Matt2f2f4252005-04-13 14:45:30 +02001024 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
Matt2f2f4252005-04-13 14:45:30 +02001025 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
Matt Porter3cc08dc2006-01-23 15:27:49 +01001026 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
1027
1028 if (spec->alt_switch) {
1029 codec->num_pcms++;
1030 info++;
1031 info->name = "STAC92xx Analog Alt";
1032 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
1033 }
Matt2f2f4252005-04-13 14:45:30 +02001034
Mattdabbed62005-06-14 10:19:34 +02001035 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
1036 codec->num_pcms++;
1037 info++;
1038 info->name = "STAC92xx Digital";
1039 if (spec->multiout.dig_out_nid) {
1040 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
1041 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
1042 }
1043 if (spec->dig_in_nid) {
1044 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
1045 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
1046 }
1047 }
1048
Matt2f2f4252005-04-13 14:45:30 +02001049 return 0;
1050}
1051
Takashi Iwaic960a032006-03-23 17:06:28 +01001052static unsigned int stac92xx_get_vref(struct hda_codec *codec, hda_nid_t nid)
1053{
1054 unsigned int pincap = snd_hda_param_read(codec, nid,
1055 AC_PAR_PIN_CAP);
1056 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
1057 if (pincap & AC_PINCAP_VREF_100)
1058 return AC_PINCTL_VREF_100;
1059 if (pincap & AC_PINCAP_VREF_80)
1060 return AC_PINCTL_VREF_80;
1061 if (pincap & AC_PINCAP_VREF_50)
1062 return AC_PINCTL_VREF_50;
1063 if (pincap & AC_PINCAP_VREF_GRD)
1064 return AC_PINCTL_VREF_GRD;
1065 return 0;
1066}
1067
Matt Porter403d1942005-11-29 15:00:51 +01001068static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
1069
1070{
1071 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
1072}
1073
Takashi Iwaia5ce8892007-07-23 15:42:26 +02001074#define stac92xx_io_switch_info snd_ctl_boolean_mono_info
Matt Porter403d1942005-11-29 15:00:51 +01001075
1076static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1077{
1078 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1079 struct sigmatel_spec *spec = codec->spec;
1080 int io_idx = kcontrol-> private_value & 0xff;
1081
1082 ucontrol->value.integer.value[0] = spec->io_switch[io_idx];
1083 return 0;
1084}
1085
1086static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1087{
1088 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1089 struct sigmatel_spec *spec = codec->spec;
1090 hda_nid_t nid = kcontrol->private_value >> 8;
1091 int io_idx = kcontrol-> private_value & 0xff;
1092 unsigned short val = ucontrol->value.integer.value[0];
1093
1094 spec->io_switch[io_idx] = val;
1095
1096 if (val)
1097 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
Takashi Iwaic960a032006-03-23 17:06:28 +01001098 else {
1099 unsigned int pinctl = AC_PINCTL_IN_EN;
1100 if (io_idx) /* set VREF for mic */
1101 pinctl |= stac92xx_get_vref(codec, nid);
1102 stac92xx_auto_set_pinctl(codec, nid, pinctl);
1103 }
Matt Porter403d1942005-11-29 15:00:51 +01001104 return 1;
1105}
1106
1107#define STAC_CODEC_IO_SWITCH(xname, xpval) \
1108 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1109 .name = xname, \
1110 .index = 0, \
1111 .info = stac92xx_io_switch_info, \
1112 .get = stac92xx_io_switch_get, \
1113 .put = stac92xx_io_switch_put, \
1114 .private_value = xpval, \
1115 }
1116
1117
Mattc7d4b2f2005-06-27 14:59:41 +02001118enum {
1119 STAC_CTL_WIDGET_VOL,
1120 STAC_CTL_WIDGET_MUTE,
Matt Porter403d1942005-11-29 15:00:51 +01001121 STAC_CTL_WIDGET_IO_SWITCH,
Mattc7d4b2f2005-06-27 14:59:41 +02001122};
1123
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001124static struct snd_kcontrol_new stac92xx_control_templates[] = {
Mattc7d4b2f2005-06-27 14:59:41 +02001125 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
1126 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Matt Porter403d1942005-11-29 15:00:51 +01001127 STAC_CODEC_IO_SWITCH(NULL, 0),
Mattc7d4b2f2005-06-27 14:59:41 +02001128};
1129
1130/* add dynamic controls */
1131static int stac92xx_add_control(struct sigmatel_spec *spec, int type, const char *name, unsigned long val)
1132{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001133 struct snd_kcontrol_new *knew;
Mattc7d4b2f2005-06-27 14:59:41 +02001134
1135 if (spec->num_kctl_used >= spec->num_kctl_alloc) {
1136 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
1137
1138 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */
1139 if (! knew)
1140 return -ENOMEM;
1141 if (spec->kctl_alloc) {
1142 memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
1143 kfree(spec->kctl_alloc);
1144 }
1145 spec->kctl_alloc = knew;
1146 spec->num_kctl_alloc = num;
1147 }
1148
1149 knew = &spec->kctl_alloc[spec->num_kctl_used];
1150 *knew = stac92xx_control_templates[type];
Takashi Iwai82fe0c52005-06-30 10:54:33 +02001151 knew->name = kstrdup(name, GFP_KERNEL);
Mattc7d4b2f2005-06-27 14:59:41 +02001152 if (! knew->name)
1153 return -ENOMEM;
1154 knew->private_value = val;
1155 spec->num_kctl_used++;
1156 return 0;
1157}
1158
Matt Porter403d1942005-11-29 15:00:51 +01001159/* flag inputs as additional dynamic lineouts */
1160static int stac92xx_add_dyn_out_pins(struct hda_codec *codec, struct auto_pin_cfg *cfg)
1161{
1162 struct sigmatel_spec *spec = codec->spec;
Steve Longerbeam7b043892007-05-03 20:50:03 +02001163 unsigned int wcaps, wtype;
1164 int i, num_dacs = 0;
1165
1166 /* use the wcaps cache to count all DACs available for line-outs */
1167 for (i = 0; i < codec->num_nodes; i++) {
1168 wcaps = codec->wcaps[i];
1169 wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
1170 if (wtype == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL))
1171 num_dacs++;
1172 }
Matt Porter403d1942005-11-29 15:00:51 +01001173
Steve Longerbeam7b043892007-05-03 20:50:03 +02001174 snd_printdd("%s: total dac count=%d\n", __func__, num_dacs);
1175
Matt Porter403d1942005-11-29 15:00:51 +01001176 switch (cfg->line_outs) {
1177 case 3:
1178 /* add line-in as side */
Steve Longerbeam7b043892007-05-03 20:50:03 +02001179 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 3) {
Matt Porter403d1942005-11-29 15:00:51 +01001180 cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_LINE];
1181 spec->line_switch = 1;
1182 cfg->line_outs++;
1183 }
1184 break;
1185 case 2:
1186 /* add line-in as clfe and mic as side */
Steve Longerbeam7b043892007-05-03 20:50:03 +02001187 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 2) {
Matt Porter403d1942005-11-29 15:00:51 +01001188 cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_LINE];
1189 spec->line_switch = 1;
1190 cfg->line_outs++;
1191 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02001192 if (cfg->input_pins[AUTO_PIN_MIC] && num_dacs > 3) {
Matt Porter403d1942005-11-29 15:00:51 +01001193 cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_MIC];
1194 spec->mic_switch = 1;
1195 cfg->line_outs++;
1196 }
1197 break;
1198 case 1:
1199 /* add line-in as surr and mic as clfe */
Steve Longerbeam7b043892007-05-03 20:50:03 +02001200 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 1) {
Matt Porter403d1942005-11-29 15:00:51 +01001201 cfg->line_out_pins[1] = cfg->input_pins[AUTO_PIN_LINE];
1202 spec->line_switch = 1;
1203 cfg->line_outs++;
1204 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02001205 if (cfg->input_pins[AUTO_PIN_MIC] && num_dacs > 2) {
Matt Porter403d1942005-11-29 15:00:51 +01001206 cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_MIC];
1207 spec->mic_switch = 1;
1208 cfg->line_outs++;
1209 }
1210 break;
1211 }
1212
1213 return 0;
1214}
1215
Steve Longerbeam7b043892007-05-03 20:50:03 +02001216
1217static int is_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
1218{
1219 int i;
1220
1221 for (i = 0; i < spec->multiout.num_dacs; i++) {
1222 if (spec->multiout.dac_nids[i] == nid)
1223 return 1;
1224 }
1225
1226 return 0;
1227}
1228
Matt Porter3cc08dc2006-01-23 15:27:49 +01001229/*
Steve Longerbeam7b043892007-05-03 20:50:03 +02001230 * Fill in the dac_nids table from the parsed pin configuration
1231 * This function only works when every pin in line_out_pins[]
1232 * contains atleast one DAC in its connection list. Some 92xx
1233 * codecs are not connected directly to a DAC, such as the 9200
1234 * and 9202/925x. For those, dac_nids[] must be hard-coded.
Matt Porter3cc08dc2006-01-23 15:27:49 +01001235 */
Takashi Iwai19039bd2006-06-28 15:52:16 +02001236static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec,
Takashi Iwaidf802952007-07-02 19:18:00 +02001237 struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02001238{
1239 struct sigmatel_spec *spec = codec->spec;
Steve Longerbeam7b043892007-05-03 20:50:03 +02001240 int i, j, conn_len = 0;
1241 hda_nid_t nid, conn[HDA_MAX_CONNECTIONS];
1242 unsigned int wcaps, wtype;
1243
Mattc7d4b2f2005-06-27 14:59:41 +02001244 for (i = 0; i < cfg->line_outs; i++) {
1245 nid = cfg->line_out_pins[i];
Steve Longerbeam7b043892007-05-03 20:50:03 +02001246 conn_len = snd_hda_get_connections(codec, nid, conn,
1247 HDA_MAX_CONNECTIONS);
1248 for (j = 0; j < conn_len; j++) {
1249 wcaps = snd_hda_param_read(codec, conn[j],
1250 AC_PAR_AUDIO_WIDGET_CAP);
1251 wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
1252
1253 if (wtype != AC_WID_AUD_OUT ||
1254 (wcaps & AC_WCAP_DIGITAL))
1255 continue;
1256 /* conn[j] is a DAC routed to this line-out */
1257 if (!is_in_dac_nids(spec, conn[j]))
1258 break;
1259 }
1260
1261 if (j == conn_len) {
Takashi Iwaidf802952007-07-02 19:18:00 +02001262 if (spec->multiout.num_dacs > 0) {
1263 /* we have already working output pins,
1264 * so let's drop the broken ones again
1265 */
1266 cfg->line_outs = spec->multiout.num_dacs;
1267 break;
1268 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02001269 /* error out, no available DAC found */
1270 snd_printk(KERN_ERR
1271 "%s: No available DAC for pin 0x%x\n",
1272 __func__, nid);
1273 return -ENODEV;
1274 }
1275
1276 spec->multiout.dac_nids[i] = conn[j];
1277 spec->multiout.num_dacs++;
1278 if (conn_len > 1) {
1279 /* select this DAC in the pin's input mux */
1280 snd_hda_codec_write(codec, nid, 0,
1281 AC_VERB_SET_CONNECT_SEL, j);
1282
1283 }
Mattc7d4b2f2005-06-27 14:59:41 +02001284 }
1285
Steve Longerbeam7b043892007-05-03 20:50:03 +02001286 snd_printd("dac_nids=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
1287 spec->multiout.num_dacs,
1288 spec->multiout.dac_nids[0],
1289 spec->multiout.dac_nids[1],
1290 spec->multiout.dac_nids[2],
1291 spec->multiout.dac_nids[3],
1292 spec->multiout.dac_nids[4]);
Mattc7d4b2f2005-06-27 14:59:41 +02001293 return 0;
1294}
1295
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001296/* create volume control/switch for the given prefx type */
1297static int create_controls(struct sigmatel_spec *spec, const char *pfx, hda_nid_t nid, int chs)
1298{
1299 char name[32];
1300 int err;
1301
1302 sprintf(name, "%s Playback Volume", pfx);
1303 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, name,
1304 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1305 if (err < 0)
1306 return err;
1307 sprintf(name, "%s Playback Switch", pfx);
1308 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, name,
1309 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1310 if (err < 0)
1311 return err;
1312 return 0;
1313}
1314
Mattc7d4b2f2005-06-27 14:59:41 +02001315/* add playback controls from the parsed DAC table */
Takashi Iwai19039bd2006-06-28 15:52:16 +02001316static int stac92xx_auto_create_multi_out_ctls(struct sigmatel_spec *spec,
1317 const struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02001318{
Takashi Iwai19039bd2006-06-28 15:52:16 +02001319 static const char *chname[4] = {
1320 "Front", "Surround", NULL /*CLFE*/, "Side"
1321 };
Mattc7d4b2f2005-06-27 14:59:41 +02001322 hda_nid_t nid;
1323 int i, err;
1324
1325 for (i = 0; i < cfg->line_outs; i++) {
Matt Porter403d1942005-11-29 15:00:51 +01001326 if (!spec->multiout.dac_nids[i])
Mattc7d4b2f2005-06-27 14:59:41 +02001327 continue;
1328
1329 nid = spec->multiout.dac_nids[i];
1330
1331 if (i == 2) {
1332 /* Center/LFE */
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001333 err = create_controls(spec, "Center", nid, 1);
1334 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001335 return err;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001336 err = create_controls(spec, "LFE", nid, 2);
1337 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001338 return err;
1339 } else {
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001340 err = create_controls(spec, chname[i], nid, 3);
1341 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001342 return err;
1343 }
1344 }
1345
Matt Porter403d1942005-11-29 15:00:51 +01001346 if (spec->line_switch)
1347 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Line In as Output Switch", cfg->input_pins[AUTO_PIN_LINE] << 8)) < 0)
1348 return err;
1349
1350 if (spec->mic_switch)
1351 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Mic as Output Switch", (cfg->input_pins[AUTO_PIN_MIC] << 8) | 1)) < 0)
1352 return err;
1353
Mattc7d4b2f2005-06-27 14:59:41 +02001354 return 0;
1355}
1356
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001357static int check_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
1358{
Steve Longerbeam7b043892007-05-03 20:50:03 +02001359 if (is_in_dac_nids(spec, nid))
1360 return 1;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001361 if (spec->multiout.hp_nid == nid)
1362 return 1;
1363 return 0;
1364}
1365
1366static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
1367{
1368 if (!spec->multiout.hp_nid)
1369 spec->multiout.hp_nid = nid;
1370 else if (spec->multiout.num_dacs > 4) {
1371 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
1372 return 1;
1373 } else {
1374 spec->multiout.dac_nids[spec->multiout.num_dacs] = nid;
1375 spec->multiout.num_dacs++;
1376 }
1377 return 0;
1378}
1379
1380/* add playback controls for Speaker and HP outputs */
1381static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
1382 struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02001383{
1384 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02001385 hda_nid_t nid;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001386 int i, old_num_dacs, err;
Mattc7d4b2f2005-06-27 14:59:41 +02001387
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001388 old_num_dacs = spec->multiout.num_dacs;
1389 for (i = 0; i < cfg->hp_outs; i++) {
1390 unsigned int wid_caps = get_wcaps(codec, cfg->hp_pins[i]);
1391 if (wid_caps & AC_WCAP_UNSOL_CAP)
1392 spec->hp_detect = 1;
1393 nid = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
1394 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
1395 if (check_in_dac_nids(spec, nid))
1396 nid = 0;
1397 if (! nid)
Mattc7d4b2f2005-06-27 14:59:41 +02001398 continue;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001399 add_spec_dacs(spec, nid);
1400 }
1401 for (i = 0; i < cfg->speaker_outs; i++) {
Steve Longerbeam7b043892007-05-03 20:50:03 +02001402 nid = snd_hda_codec_read(codec, cfg->speaker_pins[i], 0,
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001403 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
1404 if (check_in_dac_nids(spec, nid))
1405 nid = 0;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001406 if (! nid)
1407 continue;
1408 add_spec_dacs(spec, nid);
Mattc7d4b2f2005-06-27 14:59:41 +02001409 }
Matthew Ranostay1b290a52007-07-12 15:17:34 +02001410 for (i = 0; i < cfg->line_outs; i++) {
1411 nid = snd_hda_codec_read(codec, cfg->line_out_pins[i], 0,
1412 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
1413 if (check_in_dac_nids(spec, nid))
1414 nid = 0;
1415 if (! nid)
1416 continue;
1417 add_spec_dacs(spec, nid);
1418 }
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001419 for (i = old_num_dacs; i < spec->multiout.num_dacs; i++) {
1420 static const char *pfxs[] = {
1421 "Speaker", "External Speaker", "Speaker2",
1422 };
1423 err = create_controls(spec, pfxs[i - old_num_dacs],
1424 spec->multiout.dac_nids[i], 3);
1425 if (err < 0)
1426 return err;
1427 }
1428 if (spec->multiout.hp_nid) {
1429 const char *pfx;
1430 if (old_num_dacs == spec->multiout.num_dacs)
1431 pfx = "Master";
1432 else
1433 pfx = "Headphone";
1434 err = create_controls(spec, pfx, spec->multiout.hp_nid, 3);
1435 if (err < 0)
1436 return err;
1437 }
Mattc7d4b2f2005-06-27 14:59:41 +02001438
1439 return 0;
1440}
1441
Matt Porter8b657272006-10-26 17:12:59 +02001442/* labels for dmic mux inputs */
Adrian Bunkddc2cec2006-11-20 12:03:44 +01001443static const char *stac92xx_dmic_labels[5] = {
Matt Porter8b657272006-10-26 17:12:59 +02001444 "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
1445 "Digital Mic 3", "Digital Mic 4"
1446};
1447
1448/* create playback/capture controls for input pins on dmic capable codecs */
1449static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
1450 const struct auto_pin_cfg *cfg)
1451{
1452 struct sigmatel_spec *spec = codec->spec;
1453 struct hda_input_mux *dimux = &spec->private_dimux;
1454 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
1455 int i, j;
1456
1457 dimux->items[dimux->num_items].label = stac92xx_dmic_labels[0];
1458 dimux->items[dimux->num_items].index = 0;
1459 dimux->num_items++;
1460
1461 for (i = 0; i < spec->num_dmics; i++) {
1462 int index;
1463 int num_cons;
1464 unsigned int def_conf;
1465
1466 def_conf = snd_hda_codec_read(codec,
1467 spec->dmic_nids[i],
1468 0,
1469 AC_VERB_GET_CONFIG_DEFAULT,
1470 0);
1471 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
1472 continue;
1473
1474 num_cons = snd_hda_get_connections(codec,
1475 spec->dmux_nid,
1476 con_lst,
1477 HDA_MAX_NUM_INPUTS);
1478 for (j = 0; j < num_cons; j++)
1479 if (con_lst[j] == spec->dmic_nids[i]) {
1480 index = j;
1481 goto found;
1482 }
1483 continue;
1484found:
1485 dimux->items[dimux->num_items].label =
1486 stac92xx_dmic_labels[dimux->num_items];
1487 dimux->items[dimux->num_items].index = index;
1488 dimux->num_items++;
1489 }
1490
1491 return 0;
1492}
1493
Mattc7d4b2f2005-06-27 14:59:41 +02001494/* create playback/capture controls for input pins */
1495static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
1496{
1497 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02001498 struct hda_input_mux *imux = &spec->private_imux;
1499 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
1500 int i, j, k;
1501
1502 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwai314634b2006-09-21 11:56:18 +02001503 int index;
Mattc7d4b2f2005-06-27 14:59:41 +02001504
Takashi Iwai314634b2006-09-21 11:56:18 +02001505 if (!cfg->input_pins[i])
1506 continue;
1507 index = -1;
1508 for (j = 0; j < spec->num_muxes; j++) {
1509 int num_cons;
1510 num_cons = snd_hda_get_connections(codec,
1511 spec->mux_nids[j],
1512 con_lst,
1513 HDA_MAX_NUM_INPUTS);
1514 for (k = 0; k < num_cons; k++)
1515 if (con_lst[k] == cfg->input_pins[i]) {
1516 index = k;
1517 goto found;
1518 }
Mattc7d4b2f2005-06-27 14:59:41 +02001519 }
Takashi Iwai314634b2006-09-21 11:56:18 +02001520 continue;
1521 found:
1522 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
1523 imux->items[imux->num_items].index = index;
1524 imux->num_items++;
Mattc7d4b2f2005-06-27 14:59:41 +02001525 }
1526
Steve Longerbeam7b043892007-05-03 20:50:03 +02001527 if (imux->num_items) {
Sam Revitch62fe78e2006-05-10 15:09:17 +02001528 /*
1529 * Set the current input for the muxes.
1530 * The STAC9221 has two input muxes with identical source
1531 * NID lists. Hopefully this won't get confused.
1532 */
1533 for (i = 0; i < spec->num_muxes; i++) {
1534 snd_hda_codec_write(codec, spec->mux_nids[i], 0,
1535 AC_VERB_SET_CONNECT_SEL,
1536 imux->items[0].index);
1537 }
1538 }
1539
Mattc7d4b2f2005-06-27 14:59:41 +02001540 return 0;
1541}
1542
Mattc7d4b2f2005-06-27 14:59:41 +02001543static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
1544{
1545 struct sigmatel_spec *spec = codec->spec;
1546 int i;
1547
1548 for (i = 0; i < spec->autocfg.line_outs; i++) {
1549 hda_nid_t nid = spec->autocfg.line_out_pins[i];
1550 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
1551 }
1552}
1553
1554static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
1555{
1556 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001557 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02001558
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001559 for (i = 0; i < spec->autocfg.hp_outs; i++) {
1560 hda_nid_t pin;
1561 pin = spec->autocfg.hp_pins[i];
1562 if (pin) /* connect to front */
1563 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
1564 }
1565 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
1566 hda_nid_t pin;
1567 pin = spec->autocfg.speaker_pins[i];
1568 if (pin) /* connect to front */
1569 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
1570 }
Mattc7d4b2f2005-06-27 14:59:41 +02001571}
1572
Matt Porter3cc08dc2006-01-23 15:27:49 +01001573static 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 +02001574{
1575 struct sigmatel_spec *spec = codec->spec;
1576 int err;
1577
Matt Porter8b657272006-10-26 17:12:59 +02001578 if ((err = snd_hda_parse_pin_def_config(codec,
1579 &spec->autocfg,
1580 spec->dmic_nids)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001581 return err;
Takashi Iwai82bc9552006-03-21 11:24:42 +01001582 if (! spec->autocfg.line_outs)
Matt Porter869264c2006-01-25 19:20:50 +01001583 return 0; /* can't find valid pin config */
Takashi Iwai19039bd2006-06-28 15:52:16 +02001584
Matt Porter403d1942005-11-29 15:00:51 +01001585 if ((err = stac92xx_add_dyn_out_pins(codec, &spec->autocfg)) < 0)
1586 return err;
Takashi Iwai19039bd2006-06-28 15:52:16 +02001587 if (spec->multiout.num_dacs == 0)
1588 if ((err = stac92xx_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
1589 return err;
Mattc7d4b2f2005-06-27 14:59:41 +02001590
1591 if ((err = stac92xx_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
1592 (err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg)) < 0 ||
1593 (err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
1594 return err;
1595
Matt Porter8b657272006-10-26 17:12:59 +02001596 if (spec->num_dmics > 0)
1597 if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
1598 &spec->autocfg)) < 0)
1599 return err;
1600
Mattc7d4b2f2005-06-27 14:59:41 +02001601 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Matt Porter403d1942005-11-29 15:00:51 +01001602 if (spec->multiout.max_channels > 2)
Mattc7d4b2f2005-06-27 14:59:41 +02001603 spec->surr_switch = 1;
Mattc7d4b2f2005-06-27 14:59:41 +02001604
Takashi Iwai82bc9552006-03-21 11:24:42 +01001605 if (spec->autocfg.dig_out_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01001606 spec->multiout.dig_out_nid = dig_out;
Takashi Iwai82bc9552006-03-21 11:24:42 +01001607 if (spec->autocfg.dig_in_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01001608 spec->dig_in_nid = dig_in;
Mattc7d4b2f2005-06-27 14:59:41 +02001609
1610 if (spec->kctl_alloc)
1611 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
1612
1613 spec->input_mux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02001614 spec->dinput_mux = &spec->private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +02001615
1616 return 1;
1617}
1618
Takashi Iwai82bc9552006-03-21 11:24:42 +01001619/* add playback controls for HP output */
1620static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
1621 struct auto_pin_cfg *cfg)
1622{
1623 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001624 hda_nid_t pin = cfg->hp_pins[0];
Takashi Iwai82bc9552006-03-21 11:24:42 +01001625 unsigned int wid_caps;
1626
1627 if (! pin)
1628 return 0;
1629
1630 wid_caps = get_wcaps(codec, pin);
Takashi Iwai505cb342006-03-27 12:51:52 +02001631 if (wid_caps & AC_WCAP_UNSOL_CAP)
Takashi Iwai82bc9552006-03-21 11:24:42 +01001632 spec->hp_detect = 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +01001633
1634 return 0;
1635}
1636
Richard Fish160ea0d2006-09-06 13:58:25 +02001637/* add playback controls for LFE output */
1638static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
1639 struct auto_pin_cfg *cfg)
1640{
1641 struct sigmatel_spec *spec = codec->spec;
1642 int err;
1643 hda_nid_t lfe_pin = 0x0;
1644 int i;
1645
1646 /*
1647 * search speaker outs and line outs for a mono speaker pin
1648 * with an amp. If one is found, add LFE controls
1649 * for it.
1650 */
1651 for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
1652 hda_nid_t pin = spec->autocfg.speaker_pins[i];
1653 unsigned long wcaps = get_wcaps(codec, pin);
1654 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
1655 if (wcaps == AC_WCAP_OUT_AMP)
1656 /* found a mono speaker with an amp, must be lfe */
1657 lfe_pin = pin;
1658 }
1659
1660 /* if speaker_outs is 0, then speakers may be in line_outs */
1661 if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
1662 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
1663 hda_nid_t pin = spec->autocfg.line_out_pins[i];
1664 unsigned long cfg;
1665 cfg = snd_hda_codec_read(codec, pin, 0,
1666 AC_VERB_GET_CONFIG_DEFAULT,
1667 0x00);
1668 if (get_defcfg_device(cfg) == AC_JACK_SPEAKER) {
1669 unsigned long wcaps = get_wcaps(codec, pin);
1670 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
1671 if (wcaps == AC_WCAP_OUT_AMP)
1672 /* found a mono speaker with an amp,
1673 must be lfe */
1674 lfe_pin = pin;
1675 }
1676 }
1677 }
1678
1679 if (lfe_pin) {
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001680 err = create_controls(spec, "LFE", lfe_pin, 1);
Richard Fish160ea0d2006-09-06 13:58:25 +02001681 if (err < 0)
1682 return err;
1683 }
1684
1685 return 0;
1686}
1687
Mattc7d4b2f2005-06-27 14:59:41 +02001688static int stac9200_parse_auto_config(struct hda_codec *codec)
1689{
1690 struct sigmatel_spec *spec = codec->spec;
1691 int err;
1692
Kailang Yangdf694da2005-12-05 19:42:22 +01001693 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001694 return err;
1695
1696 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
1697 return err;
1698
Takashi Iwai82bc9552006-03-21 11:24:42 +01001699 if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
1700 return err;
1701
Richard Fish160ea0d2006-09-06 13:58:25 +02001702 if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
1703 return err;
1704
Takashi Iwai82bc9552006-03-21 11:24:42 +01001705 if (spec->autocfg.dig_out_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02001706 spec->multiout.dig_out_nid = 0x05;
Takashi Iwai82bc9552006-03-21 11:24:42 +01001707 if (spec->autocfg.dig_in_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02001708 spec->dig_in_nid = 0x04;
Mattc7d4b2f2005-06-27 14:59:41 +02001709
1710 if (spec->kctl_alloc)
1711 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
1712
1713 spec->input_mux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02001714 spec->dinput_mux = &spec->private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +02001715
1716 return 1;
1717}
1718
Sam Revitch62fe78e2006-05-10 15:09:17 +02001719/*
1720 * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
1721 * funky external mute control using GPIO pins.
1722 */
1723
1724static void stac922x_gpio_mute(struct hda_codec *codec, int pin, int muted)
1725{
1726 unsigned int gpiostate, gpiomask, gpiodir;
1727
1728 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
1729 AC_VERB_GET_GPIO_DATA, 0);
1730
1731 if (!muted)
1732 gpiostate |= (1 << pin);
1733 else
1734 gpiostate &= ~(1 << pin);
1735
1736 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
1737 AC_VERB_GET_GPIO_MASK, 0);
1738 gpiomask |= (1 << pin);
1739
1740 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
1741 AC_VERB_GET_GPIO_DIRECTION, 0);
1742 gpiodir |= (1 << pin);
1743
1744 /* AppleHDA seems to do this -- WTF is this verb?? */
1745 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
1746
1747 snd_hda_codec_write(codec, codec->afg, 0,
1748 AC_VERB_SET_GPIO_MASK, gpiomask);
1749 snd_hda_codec_write(codec, codec->afg, 0,
1750 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
1751
1752 msleep(1);
1753
1754 snd_hda_codec_write(codec, codec->afg, 0,
1755 AC_VERB_SET_GPIO_DATA, gpiostate);
1756}
1757
Takashi Iwai314634b2006-09-21 11:56:18 +02001758static void enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
1759 unsigned int event)
1760{
1761 if (get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP)
1762 snd_hda_codec_write(codec, nid, 0,
1763 AC_VERB_SET_UNSOLICITED_ENABLE,
1764 (AC_USRSP_EN | event));
1765}
1766
Mattc7d4b2f2005-06-27 14:59:41 +02001767static int stac92xx_init(struct hda_codec *codec)
1768{
1769 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai82bc9552006-03-21 11:24:42 +01001770 struct auto_pin_cfg *cfg = &spec->autocfg;
1771 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02001772
Mattc7d4b2f2005-06-27 14:59:41 +02001773 snd_hda_sequence_write(codec, spec->init);
1774
Takashi Iwai82bc9552006-03-21 11:24:42 +01001775 /* set up pins */
1776 if (spec->hp_detect) {
Takashi Iwai505cb342006-03-27 12:51:52 +02001777 /* Enable unsolicited responses on the HP widget */
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001778 for (i = 0; i < cfg->hp_outs; i++)
Takashi Iwai314634b2006-09-21 11:56:18 +02001779 enable_pin_detect(codec, cfg->hp_pins[i],
1780 STAC_HP_EVENT);
Takashi Iwai0a07aca2007-03-13 10:40:23 +01001781 /* force to enable the first line-out; the others are set up
1782 * in unsol_event
1783 */
1784 stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
1785 AC_PINCTL_OUT_EN);
Takashi Iwaieb995a82006-09-21 14:28:21 +02001786 stac92xx_auto_init_hp_out(codec);
Takashi Iwai82bc9552006-03-21 11:24:42 +01001787 /* fake event to set up pins */
1788 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
1789 } else {
1790 stac92xx_auto_init_multi_out(codec);
1791 stac92xx_auto_init_hp_out(codec);
1792 }
1793 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwaic960a032006-03-23 17:06:28 +01001794 hda_nid_t nid = cfg->input_pins[i];
1795 if (nid) {
1796 unsigned int pinctl = AC_PINCTL_IN_EN;
1797 if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC)
1798 pinctl |= stac92xx_get_vref(codec, nid);
1799 stac92xx_auto_set_pinctl(codec, nid, pinctl);
1800 }
Takashi Iwai82bc9552006-03-21 11:24:42 +01001801 }
Matt Porter8b657272006-10-26 17:12:59 +02001802 if (spec->num_dmics > 0)
1803 for (i = 0; i < spec->num_dmics; i++)
1804 stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
1805 AC_PINCTL_IN_EN);
1806
Takashi Iwai82bc9552006-03-21 11:24:42 +01001807 if (cfg->dig_out_pin)
1808 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pin,
1809 AC_PINCTL_OUT_EN);
1810 if (cfg->dig_in_pin)
1811 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
1812 AC_PINCTL_IN_EN);
1813
Sam Revitch62fe78e2006-05-10 15:09:17 +02001814 if (spec->gpio_mute) {
1815 stac922x_gpio_mute(codec, 0, 0);
1816 stac922x_gpio_mute(codec, 1, 0);
1817 }
1818
Mattc7d4b2f2005-06-27 14:59:41 +02001819 return 0;
1820}
1821
Matt2f2f4252005-04-13 14:45:30 +02001822static void stac92xx_free(struct hda_codec *codec)
1823{
Mattc7d4b2f2005-06-27 14:59:41 +02001824 struct sigmatel_spec *spec = codec->spec;
1825 int i;
1826
1827 if (! spec)
1828 return;
1829
1830 if (spec->kctl_alloc) {
1831 for (i = 0; i < spec->num_kctl_used; i++)
1832 kfree(spec->kctl_alloc[i].name);
1833 kfree(spec->kctl_alloc);
1834 }
1835
Richard Fish11b44bb2006-08-23 18:31:34 +02001836 if (spec->bios_pin_configs)
1837 kfree(spec->bios_pin_configs);
1838
Mattc7d4b2f2005-06-27 14:59:41 +02001839 kfree(spec);
Matt2f2f4252005-04-13 14:45:30 +02001840}
1841
Matt4e550962005-07-04 17:51:39 +02001842static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
1843 unsigned int flag)
1844{
1845 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
1846 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Steve Longerbeam7b043892007-05-03 20:50:03 +02001847
Takashi Iwaif9acba42007-05-29 18:01:06 +02001848 if (pin_ctl & AC_PINCTL_IN_EN) {
1849 /*
1850 * we need to check the current set-up direction of
1851 * shared input pins since they can be switched via
1852 * "xxx as Output" mixer switch
1853 */
1854 struct sigmatel_spec *spec = codec->spec;
1855 struct auto_pin_cfg *cfg = &spec->autocfg;
1856 if ((nid == cfg->input_pins[AUTO_PIN_LINE] &&
1857 spec->line_switch) ||
1858 (nid == cfg->input_pins[AUTO_PIN_MIC] &&
1859 spec->mic_switch))
1860 return;
1861 }
1862
Steve Longerbeam7b043892007-05-03 20:50:03 +02001863 /* if setting pin direction bits, clear the current
1864 direction bits first */
1865 if (flag & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))
1866 pin_ctl &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
1867
Matt4e550962005-07-04 17:51:39 +02001868 snd_hda_codec_write(codec, nid, 0,
1869 AC_VERB_SET_PIN_WIDGET_CONTROL,
1870 pin_ctl | flag);
1871}
1872
1873static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
1874 unsigned int flag)
1875{
1876 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
1877 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
1878 snd_hda_codec_write(codec, nid, 0,
1879 AC_VERB_SET_PIN_WIDGET_CONTROL,
1880 pin_ctl & ~flag);
1881}
1882
Takashi Iwai314634b2006-09-21 11:56:18 +02001883static int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
1884{
1885 if (!nid)
1886 return 0;
1887 if (snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PIN_SENSE, 0x00)
1888 & (1 << 31))
1889 return 1;
1890 return 0;
1891}
1892
1893static void stac92xx_hp_detect(struct hda_codec *codec, unsigned int res)
Matt4e550962005-07-04 17:51:39 +02001894{
1895 struct sigmatel_spec *spec = codec->spec;
1896 struct auto_pin_cfg *cfg = &spec->autocfg;
1897 int i, presence;
1898
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001899 presence = 0;
1900 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai314634b2006-09-21 11:56:18 +02001901 presence = get_pin_presence(codec, cfg->hp_pins[i]);
1902 if (presence)
1903 break;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001904 }
Matt4e550962005-07-04 17:51:39 +02001905
1906 if (presence) {
1907 /* disable lineouts, enable hp */
1908 for (i = 0; i < cfg->line_outs; i++)
1909 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
1910 AC_PINCTL_OUT_EN);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001911 for (i = 0; i < cfg->speaker_outs; i++)
1912 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
1913 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02001914 } else {
1915 /* enable lineouts, disable hp */
1916 for (i = 0; i < cfg->line_outs; i++)
1917 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
1918 AC_PINCTL_OUT_EN);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001919 for (i = 0; i < cfg->speaker_outs; i++)
1920 stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
1921 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02001922 }
1923}
1924
Takashi Iwai314634b2006-09-21 11:56:18 +02001925static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
1926{
1927 switch (res >> 26) {
1928 case STAC_HP_EVENT:
1929 stac92xx_hp_detect(codec, res);
1930 break;
1931 }
1932}
1933
Mattff6fdc32005-06-27 15:06:52 +02001934#ifdef CONFIG_PM
1935static int stac92xx_resume(struct hda_codec *codec)
1936{
1937 struct sigmatel_spec *spec = codec->spec;
1938 int i;
1939
Richard Fish11b44bb2006-08-23 18:31:34 +02001940 stac92xx_set_config_regs(codec);
Takashi Iwai82599802007-07-31 15:56:24 +02001941 if (spec->gpio_mask && spec->gpio_data)
1942 stac92xx_enable_gpio_mask(codec);
1943 stac92xx_init(codec);
Takashi Iwai5d403b12007-05-03 12:32:29 +02001944 snd_hda_resume_ctls(codec, spec->mixer);
Mattff6fdc32005-06-27 15:06:52 +02001945 for (i = 0; i < spec->num_mixers; i++)
1946 snd_hda_resume_ctls(codec, spec->mixers[i]);
1947 if (spec->multiout.dig_out_nid)
1948 snd_hda_resume_spdif_out(codec);
1949 if (spec->dig_in_nid)
1950 snd_hda_resume_spdif_in(codec);
1951
1952 return 0;
1953}
1954#endif
1955
Matt2f2f4252005-04-13 14:45:30 +02001956static struct hda_codec_ops stac92xx_patch_ops = {
1957 .build_controls = stac92xx_build_controls,
1958 .build_pcms = stac92xx_build_pcms,
1959 .init = stac92xx_init,
1960 .free = stac92xx_free,
Matt4e550962005-07-04 17:51:39 +02001961 .unsol_event = stac92xx_unsol_event,
Mattff6fdc32005-06-27 15:06:52 +02001962#ifdef CONFIG_PM
1963 .resume = stac92xx_resume,
1964#endif
Matt2f2f4252005-04-13 14:45:30 +02001965};
1966
1967static int patch_stac9200(struct hda_codec *codec)
1968{
1969 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02001970 int err;
Matt2f2f4252005-04-13 14:45:30 +02001971
Takashi Iwaie560d8d2005-09-09 14:21:46 +02001972 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02001973 if (spec == NULL)
1974 return -ENOMEM;
1975
1976 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02001977 spec->num_pins = ARRAY_SIZE(stac9200_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02001978 spec->pin_nids = stac9200_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001979 spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS,
1980 stac9200_models,
1981 stac9200_cfg_tbl);
Richard Fish11b44bb2006-08-23 18:31:34 +02001982 if (spec->board_config < 0) {
1983 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9200, using BIOS defaults\n");
1984 err = stac92xx_save_bios_config_regs(codec);
1985 if (err < 0) {
1986 stac92xx_free(codec);
1987 return err;
1988 }
1989 spec->pin_configs = spec->bios_pin_configs;
1990 } else {
Matt Porter403d1942005-11-29 15:00:51 +01001991 spec->pin_configs = stac9200_brd_tbl[spec->board_config];
1992 stac92xx_set_config_regs(codec);
1993 }
Matt2f2f4252005-04-13 14:45:30 +02001994
1995 spec->multiout.max_channels = 2;
1996 spec->multiout.num_dacs = 1;
1997 spec->multiout.dac_nids = stac9200_dac_nids;
1998 spec->adc_nids = stac9200_adc_nids;
1999 spec->mux_nids = stac9200_mux_nids;
Mattdabbed62005-06-14 10:19:34 +02002000 spec->num_muxes = 1;
Matt Porter8b657272006-10-26 17:12:59 +02002001 spec->num_dmics = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02002002
2003 spec->init = stac9200_core_init;
Matt2f2f4252005-04-13 14:45:30 +02002004 spec->mixer = stac9200_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02002005
2006 err = stac9200_parse_auto_config(codec);
2007 if (err < 0) {
2008 stac92xx_free(codec);
2009 return err;
2010 }
Matt2f2f4252005-04-13 14:45:30 +02002011
2012 codec->patch_ops = stac92xx_patch_ops;
2013
2014 return 0;
2015}
2016
Tobin Davis8e21c342007-01-08 11:04:17 +01002017static int patch_stac925x(struct hda_codec *codec)
2018{
2019 struct sigmatel_spec *spec;
2020 int err;
2021
2022 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2023 if (spec == NULL)
2024 return -ENOMEM;
2025
2026 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02002027 spec->num_pins = ARRAY_SIZE(stac925x_pin_nids);
Tobin Davis8e21c342007-01-08 11:04:17 +01002028 spec->pin_nids = stac925x_pin_nids;
2029 spec->board_config = snd_hda_check_board_config(codec, STAC_925x_MODELS,
2030 stac925x_models,
2031 stac925x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002032 again:
Tobin Davis8e21c342007-01-08 11:04:17 +01002033 if (spec->board_config < 0) {
Tobin Davis2c11f952007-05-17 09:36:34 +02002034 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC925x,"
2035 "using BIOS defaults\n");
Tobin Davis8e21c342007-01-08 11:04:17 +01002036 err = stac92xx_save_bios_config_regs(codec);
2037 if (err < 0) {
2038 stac92xx_free(codec);
2039 return err;
2040 }
2041 spec->pin_configs = spec->bios_pin_configs;
2042 } else if (stac925x_brd_tbl[spec->board_config] != NULL){
2043 spec->pin_configs = stac925x_brd_tbl[spec->board_config];
2044 stac92xx_set_config_regs(codec);
2045 }
2046
2047 spec->multiout.max_channels = 2;
2048 spec->multiout.num_dacs = 1;
2049 spec->multiout.dac_nids = stac925x_dac_nids;
2050 spec->adc_nids = stac925x_adc_nids;
2051 spec->mux_nids = stac925x_mux_nids;
2052 spec->num_muxes = 1;
Tobin Davis2c11f952007-05-17 09:36:34 +02002053 switch (codec->vendor_id) {
2054 case 0x83847632: /* STAC9202 */
2055 case 0x83847633: /* STAC9202D */
2056 case 0x83847636: /* STAC9251 */
2057 case 0x83847637: /* STAC9251D */
2058 spec->num_dmics = 1;
2059 spec->dmic_nids = stac925x_dmic_nids;
2060 break;
2061 default:
2062 spec->num_dmics = 0;
2063 break;
2064 }
Tobin Davis8e21c342007-01-08 11:04:17 +01002065
2066 spec->init = stac925x_core_init;
2067 spec->mixer = stac925x_mixer;
2068
2069 err = stac92xx_parse_auto_config(codec, 0x8, 0x7);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002070 if (!err) {
2071 if (spec->board_config < 0) {
2072 printk(KERN_WARNING "hda_codec: No auto-config is "
2073 "available, default to model=ref\n");
2074 spec->board_config = STAC_925x_REF;
2075 goto again;
2076 }
2077 err = -EINVAL;
2078 }
Tobin Davis8e21c342007-01-08 11:04:17 +01002079 if (err < 0) {
2080 stac92xx_free(codec);
2081 return err;
2082 }
2083
2084 codec->patch_ops = stac92xx_patch_ops;
2085
2086 return 0;
2087}
2088
Matt2f2f4252005-04-13 14:45:30 +02002089static int patch_stac922x(struct hda_codec *codec)
2090{
2091 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02002092 int err;
Matt2f2f4252005-04-13 14:45:30 +02002093
Takashi Iwaie560d8d2005-09-09 14:21:46 +02002094 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02002095 if (spec == NULL)
2096 return -ENOMEM;
2097
2098 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02002099 spec->num_pins = ARRAY_SIZE(stac922x_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02002100 spec->pin_nids = stac922x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002101 spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS,
2102 stac922x_models,
2103 stac922x_cfg_tbl);
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002104 if (spec->board_config == STAC_INTEL_MAC_V3) {
Takashi Iwai3fc24d82007-02-16 13:27:18 +01002105 spec->gpio_mute = 1;
2106 /* Intel Macs have all same PCI SSID, so we need to check
2107 * codec SSID to distinguish the exact models
2108 */
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01002109 printk(KERN_INFO "hda_codec: STAC922x, Apple subsys_id=%x\n", codec->subsystem_id);
Takashi Iwai3fc24d82007-02-16 13:27:18 +01002110 switch (codec->subsystem_id) {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002111
2112 case 0x106b0800:
2113 spec->board_config = STAC_INTEL_MAC_V1;
Abhijit Bhopatkarc45e20e2007-04-17 11:57:16 +02002114 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002115 case 0x106b0600:
2116 case 0x106b0700:
2117 spec->board_config = STAC_INTEL_MAC_V2;
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01002118 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002119 case 0x106b0e00:
2120 case 0x106b0f00:
2121 case 0x106b1600:
2122 case 0x106b1700:
2123 case 0x106b0200:
2124 case 0x106b1e00:
2125 spec->board_config = STAC_INTEL_MAC_V3;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01002126 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002127 case 0x106b1a00:
2128 case 0x00000100:
2129 spec->board_config = STAC_INTEL_MAC_V4;
Sylvain FORETf16928f2007-04-27 14:22:36 +02002130 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002131 case 0x106b0a00:
2132 case 0x106b2200:
2133 spec->board_config = STAC_INTEL_MAC_V5;
Takashi Iwai0dae0f82007-05-21 12:41:29 +02002134 break;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01002135 }
2136 }
2137
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002138 again:
Richard Fish11b44bb2006-08-23 18:31:34 +02002139 if (spec->board_config < 0) {
2140 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC922x, "
2141 "using BIOS defaults\n");
2142 err = stac92xx_save_bios_config_regs(codec);
2143 if (err < 0) {
2144 stac92xx_free(codec);
2145 return err;
2146 }
2147 spec->pin_configs = spec->bios_pin_configs;
2148 } else if (stac922x_brd_tbl[spec->board_config] != NULL) {
Matt Porter403d1942005-11-29 15:00:51 +01002149 spec->pin_configs = stac922x_brd_tbl[spec->board_config];
2150 stac92xx_set_config_regs(codec);
2151 }
Matt2f2f4252005-04-13 14:45:30 +02002152
Matt2f2f4252005-04-13 14:45:30 +02002153 spec->adc_nids = stac922x_adc_nids;
2154 spec->mux_nids = stac922x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01002155 spec->num_muxes = ARRAY_SIZE(stac922x_mux_nids);
Matt Porter8b657272006-10-26 17:12:59 +02002156 spec->num_dmics = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02002157
2158 spec->init = stac922x_core_init;
Matt2f2f4252005-04-13 14:45:30 +02002159 spec->mixer = stac922x_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02002160
2161 spec->multiout.dac_nids = spec->dac_nids;
Takashi Iwai19039bd2006-06-28 15:52:16 +02002162
Matt Porter3cc08dc2006-01-23 15:27:49 +01002163 err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002164 if (!err) {
2165 if (spec->board_config < 0) {
2166 printk(KERN_WARNING "hda_codec: No auto-config is "
2167 "available, default to model=ref\n");
2168 spec->board_config = STAC_D945_REF;
2169 goto again;
2170 }
2171 err = -EINVAL;
2172 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01002173 if (err < 0) {
2174 stac92xx_free(codec);
2175 return err;
2176 }
2177
2178 codec->patch_ops = stac92xx_patch_ops;
2179
Takashi Iwai807a46362007-05-29 19:01:37 +02002180 /* Fix Mux capture level; max to 2 */
2181 snd_hda_override_amp_caps(codec, 0x12, HDA_OUTPUT,
2182 (0 << AC_AMPCAP_OFFSET_SHIFT) |
2183 (2 << AC_AMPCAP_NUM_STEPS_SHIFT) |
2184 (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
2185 (0 << AC_AMPCAP_MUTE_SHIFT));
2186
Matt Porter3cc08dc2006-01-23 15:27:49 +01002187 return 0;
2188}
2189
2190static int patch_stac927x(struct hda_codec *codec)
2191{
2192 struct sigmatel_spec *spec;
2193 int err;
2194
2195 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2196 if (spec == NULL)
2197 return -ENOMEM;
2198
2199 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02002200 spec->num_pins = ARRAY_SIZE(stac927x_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02002201 spec->pin_nids = stac927x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002202 spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS,
2203 stac927x_models,
2204 stac927x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002205 again:
Richard Fish11b44bb2006-08-23 18:31:34 +02002206 if (spec->board_config < 0) {
Matt Porter3cc08dc2006-01-23 15:27:49 +01002207 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC927x, using BIOS defaults\n");
Richard Fish11b44bb2006-08-23 18:31:34 +02002208 err = stac92xx_save_bios_config_regs(codec);
2209 if (err < 0) {
2210 stac92xx_free(codec);
2211 return err;
2212 }
2213 spec->pin_configs = spec->bios_pin_configs;
2214 } else if (stac927x_brd_tbl[spec->board_config] != NULL) {
Matt Porter3cc08dc2006-01-23 15:27:49 +01002215 spec->pin_configs = stac927x_brd_tbl[spec->board_config];
2216 stac92xx_set_config_regs(codec);
2217 }
2218
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002219 switch (spec->board_config) {
Tobin Davis93ed1502006-09-01 21:03:12 +02002220 case STAC_D965_3ST:
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002221 spec->adc_nids = stac927x_adc_nids;
2222 spec->mux_nids = stac927x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01002223 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
Matt Porter8b657272006-10-26 17:12:59 +02002224 spec->num_dmics = 0;
Tobin Davis93ed1502006-09-01 21:03:12 +02002225 spec->init = d965_core_init;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002226 spec->mixer = stac9227_mixer;
2227 break;
Tobin Davis93ed1502006-09-01 21:03:12 +02002228 case STAC_D965_5ST:
2229 spec->adc_nids = stac927x_adc_nids;
2230 spec->mux_nids = stac927x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01002231 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
Matt Porter8b657272006-10-26 17:12:59 +02002232 spec->num_dmics = 0;
Tobin Davis93ed1502006-09-01 21:03:12 +02002233 spec->init = d965_core_init;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002234 spec->mixer = stac9227_mixer;
2235 break;
2236 default:
2237 spec->adc_nids = stac927x_adc_nids;
2238 spec->mux_nids = stac927x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01002239 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
Matt Porter8b657272006-10-26 17:12:59 +02002240 spec->num_dmics = 0;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002241 spec->init = stac927x_core_init;
2242 spec->mixer = stac927x_mixer;
2243 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01002244
2245 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostay87d48362007-07-17 11:52:24 +02002246 /* GPIO0 High = Enable EAPD */
Takashi Iwai82599802007-07-31 15:56:24 +02002247 spec->gpio_mask = spec->gpio_data = 0x00000001;
2248 stac92xx_enable_gpio_mask(codec);
Matthew Ranostay92a22be2007-06-19 16:48:28 +02002249
Matt Porter3cc08dc2006-01-23 15:27:49 +01002250 err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002251 if (!err) {
2252 if (spec->board_config < 0) {
2253 printk(KERN_WARNING "hda_codec: No auto-config is "
2254 "available, default to model=ref\n");
2255 spec->board_config = STAC_D965_REF;
2256 goto again;
2257 }
2258 err = -EINVAL;
2259 }
Mattc7d4b2f2005-06-27 14:59:41 +02002260 if (err < 0) {
2261 stac92xx_free(codec);
2262 return err;
2263 }
Matt2f2f4252005-04-13 14:45:30 +02002264
2265 codec->patch_ops = stac92xx_patch_ops;
2266
2267 return 0;
2268}
2269
Matt Porterf3302a52006-07-31 12:49:34 +02002270static int patch_stac9205(struct hda_codec *codec)
2271{
2272 struct sigmatel_spec *spec;
Takashi Iwai82599802007-07-31 15:56:24 +02002273 int err;
Matt Porterf3302a52006-07-31 12:49:34 +02002274
2275 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2276 if (spec == NULL)
2277 return -ENOMEM;
2278
2279 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02002280 spec->num_pins = ARRAY_SIZE(stac9205_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02002281 spec->pin_nids = stac9205_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002282 spec->board_config = snd_hda_check_board_config(codec, STAC_9205_MODELS,
2283 stac9205_models,
2284 stac9205_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002285 again:
Richard Fish11b44bb2006-08-23 18:31:34 +02002286 if (spec->board_config < 0) {
2287 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9205, using BIOS defaults\n");
2288 err = stac92xx_save_bios_config_regs(codec);
2289 if (err < 0) {
2290 stac92xx_free(codec);
2291 return err;
2292 }
2293 spec->pin_configs = spec->bios_pin_configs;
2294 } else {
Matt Porterf3302a52006-07-31 12:49:34 +02002295 spec->pin_configs = stac9205_brd_tbl[spec->board_config];
2296 stac92xx_set_config_regs(codec);
2297 }
2298
2299 spec->adc_nids = stac9205_adc_nids;
2300 spec->mux_nids = stac9205_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01002301 spec->num_muxes = ARRAY_SIZE(stac9205_mux_nids);
Matt Porter8b657272006-10-26 17:12:59 +02002302 spec->dmic_nids = stac9205_dmic_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01002303 spec->num_dmics = ARRAY_SIZE(stac9205_dmic_nids);
Matt Porter8b657272006-10-26 17:12:59 +02002304 spec->dmux_nid = 0x1d;
Matt Porterf3302a52006-07-31 12:49:34 +02002305
2306 spec->init = stac9205_core_init;
2307 spec->mixer = stac9205_mixer;
2308
2309 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostay87d48362007-07-17 11:52:24 +02002310
2311 if (spec->board_config == STAC_M43xx) {
2312 /* Enable SPDIF in/out */
2313 stac92xx_set_config_reg(codec, 0x1f, 0x01441030);
2314 stac92xx_set_config_reg(codec, 0x20, 0x1c410030);
Matt Porter33382402006-12-18 13:17:28 +01002315
Takashi Iwai82599802007-07-31 15:56:24 +02002316 spec->gpio_mask = 0x00000007; /* GPIO0-2 */
Matthew Ranostay87d48362007-07-17 11:52:24 +02002317 /* GPIO0 High = EAPD, GPIO1 Low = DRM,
2318 * GPIO2 High = Headphone Mute
2319 */
Takashi Iwai82599802007-07-31 15:56:24 +02002320 spec->gpio_data = 0x00000005;
Matthew Ranostay87d48362007-07-17 11:52:24 +02002321 } else
Takashi Iwai82599802007-07-31 15:56:24 +02002322 spec->gpio_mask = spec->gpio_data =
2323 0x00000001; /* GPIO0 High = EAPD */
Matthew Ranostay87d48362007-07-17 11:52:24 +02002324
Takashi Iwai82599802007-07-31 15:56:24 +02002325 stac92xx_enable_gpio_mask(codec);
Matt Porterf3302a52006-07-31 12:49:34 +02002326 err = stac92xx_parse_auto_config(codec, 0x1f, 0x20);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002327 if (!err) {
2328 if (spec->board_config < 0) {
2329 printk(KERN_WARNING "hda_codec: No auto-config is "
2330 "available, default to model=ref\n");
2331 spec->board_config = STAC_9205_REF;
2332 goto again;
2333 }
2334 err = -EINVAL;
2335 }
Matt Porterf3302a52006-07-31 12:49:34 +02002336 if (err < 0) {
2337 stac92xx_free(codec);
2338 return err;
2339 }
2340
2341 codec->patch_ops = stac92xx_patch_ops;
2342
2343 return 0;
2344}
2345
Matt2f2f4252005-04-13 14:45:30 +02002346/*
Guillaume Munch6d859062006-08-22 17:15:47 +02002347 * STAC9872 hack
Takashi Iwaidb064e52006-03-16 16:04:58 +01002348 */
2349
Guillaume Munch99ccc562006-08-16 19:35:12 +02002350/* static config for Sony VAIO FE550G and Sony VAIO AR */
Takashi Iwaidb064e52006-03-16 16:04:58 +01002351static hda_nid_t vaio_dacs[] = { 0x2 };
2352#define VAIO_HP_DAC 0x5
2353static hda_nid_t vaio_adcs[] = { 0x8 /*,0x6*/ };
2354static hda_nid_t vaio_mux_nids[] = { 0x15 };
2355
2356static struct hda_input_mux vaio_mux = {
2357 .num_items = 2,
2358 .items = {
Takashi Iwaid7737812006-04-25 13:05:43 +02002359 /* { "HP", 0x0 }, */
Takashi Iwai1624cb92007-07-05 13:10:51 +02002360 { "Mic Jack", 0x1 },
2361 { "Internal Mic", 0x2 },
Takashi Iwaidb064e52006-03-16 16:04:58 +01002362 { "PCM", 0x3 },
2363 }
2364};
2365
2366static struct hda_verb vaio_init[] = {
2367 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
2368 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
2369 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
2370 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
2371 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
Takashi Iwai1624cb92007-07-05 13:10:51 +02002372 {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
Takashi Iwaidb064e52006-03-16 16:04:58 +01002373 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
2374 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
2375 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
2376 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
2377 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
2378 {}
2379};
2380
Guillaume Munch6d859062006-08-22 17:15:47 +02002381static struct hda_verb vaio_ar_init[] = {
2382 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
2383 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
2384 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
2385 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
2386/* {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },*/ /* Optical Out */
2387 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
Takashi Iwai1624cb92007-07-05 13:10:51 +02002388 {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
Guillaume Munch6d859062006-08-22 17:15:47 +02002389 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
2390 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
2391/* {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},*/ /* Optical Out */
2392 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
2393 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
2394 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
2395 {}
2396};
2397
Takashi Iwaidb064e52006-03-16 16:04:58 +01002398/* bind volumes of both NID 0x02 and 0x05 */
2399static int vaio_master_vol_put(struct snd_kcontrol *kcontrol,
2400 struct snd_ctl_elem_value *ucontrol)
2401{
2402 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2403 long *valp = ucontrol->value.integer.value;
2404 int change;
2405
2406 change = snd_hda_codec_amp_update(codec, 0x02, 0, HDA_OUTPUT, 0,
2407 0x7f, valp[0] & 0x7f);
2408 change |= snd_hda_codec_amp_update(codec, 0x02, 1, HDA_OUTPUT, 0,
2409 0x7f, valp[1] & 0x7f);
2410 snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
2411 0x7f, valp[0] & 0x7f);
2412 snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
2413 0x7f, valp[1] & 0x7f);
2414 return change;
2415}
2416
2417/* bind volumes of both NID 0x02 and 0x05 */
2418static int vaio_master_sw_put(struct snd_kcontrol *kcontrol,
2419 struct snd_ctl_elem_value *ucontrol)
2420{
2421 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2422 long *valp = ucontrol->value.integer.value;
2423 int change;
2424
2425 change = snd_hda_codec_amp_update(codec, 0x02, 0, HDA_OUTPUT, 0,
Takashi Iwaia9393d72006-05-03 11:59:03 +02002426 0x80, (valp[0] ? 0 : 0x80));
Takashi Iwaidb064e52006-03-16 16:04:58 +01002427 change |= snd_hda_codec_amp_update(codec, 0x02, 1, HDA_OUTPUT, 0,
Takashi Iwaia9393d72006-05-03 11:59:03 +02002428 0x80, (valp[1] ? 0 : 0x80));
Takashi Iwaidb064e52006-03-16 16:04:58 +01002429 snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
Takashi Iwaia9393d72006-05-03 11:59:03 +02002430 0x80, (valp[0] ? 0 : 0x80));
Takashi Iwaidb064e52006-03-16 16:04:58 +01002431 snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
Takashi Iwaia9393d72006-05-03 11:59:03 +02002432 0x80, (valp[1] ? 0 : 0x80));
Takashi Iwaidb064e52006-03-16 16:04:58 +01002433 return change;
2434}
2435
2436static struct snd_kcontrol_new vaio_mixer[] = {
2437 {
2438 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2439 .name = "Master Playback Volume",
2440 .info = snd_hda_mixer_amp_volume_info,
2441 .get = snd_hda_mixer_amp_volume_get,
2442 .put = vaio_master_vol_put,
Takashi Iwaic2566522006-08-17 18:21:36 +02002443 .tlv = { .c = snd_hda_mixer_amp_tlv },
Takashi Iwaidb064e52006-03-16 16:04:58 +01002444 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2445 },
2446 {
2447 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2448 .name = "Master Playback Switch",
2449 .info = snd_hda_mixer_amp_switch_info,
2450 .get = snd_hda_mixer_amp_switch_get,
2451 .put = vaio_master_sw_put,
2452 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2453 },
2454 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
2455 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
2456 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
2457 {
2458 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2459 .name = "Capture Source",
2460 .count = 1,
2461 .info = stac92xx_mux_enum_info,
2462 .get = stac92xx_mux_enum_get,
2463 .put = stac92xx_mux_enum_put,
2464 },
2465 {}
2466};
2467
Guillaume Munch6d859062006-08-22 17:15:47 +02002468static struct snd_kcontrol_new vaio_ar_mixer[] = {
2469 {
2470 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2471 .name = "Master Playback Volume",
2472 .info = snd_hda_mixer_amp_volume_info,
2473 .get = snd_hda_mixer_amp_volume_get,
2474 .put = vaio_master_vol_put,
2475 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2476 },
2477 {
2478 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2479 .name = "Master Playback Switch",
2480 .info = snd_hda_mixer_amp_switch_info,
2481 .get = snd_hda_mixer_amp_switch_get,
2482 .put = vaio_master_sw_put,
2483 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2484 },
2485 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
2486 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
2487 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
2488 /*HDA_CODEC_MUTE("Optical Out Switch", 0x10, 0, HDA_OUTPUT),
2489 HDA_CODEC_VOLUME("Optical Out Volume", 0x10, 0, HDA_OUTPUT),*/
2490 {
2491 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2492 .name = "Capture Source",
2493 .count = 1,
2494 .info = stac92xx_mux_enum_info,
2495 .get = stac92xx_mux_enum_get,
2496 .put = stac92xx_mux_enum_put,
2497 },
2498 {}
2499};
2500
2501static struct hda_codec_ops stac9872_patch_ops = {
Takashi Iwaidb064e52006-03-16 16:04:58 +01002502 .build_controls = stac92xx_build_controls,
2503 .build_pcms = stac92xx_build_pcms,
2504 .init = stac92xx_init,
2505 .free = stac92xx_free,
2506#ifdef CONFIG_PM
2507 .resume = stac92xx_resume,
2508#endif
2509};
2510
Guillaume Munch6d859062006-08-22 17:15:47 +02002511enum { /* FE and SZ series. id=0x83847661 and subsys=0x104D0700 or 104D1000. */
2512 CXD9872RD_VAIO,
2513 /* Unknown. id=0x83847662 and subsys=0x104D1200 or 104D1000. */
2514 STAC9872AK_VAIO,
2515 /* Unknown. id=0x83847661 and subsys=0x104D1200. */
2516 STAC9872K_VAIO,
2517 /* AR Series. id=0x83847664 and subsys=104D1300 */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002518 CXD9872AKD_VAIO,
2519 STAC_9872_MODELS,
2520};
Takashi Iwaidb064e52006-03-16 16:04:58 +01002521
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002522static const char *stac9872_models[STAC_9872_MODELS] = {
2523 [CXD9872RD_VAIO] = "vaio",
2524 [CXD9872AKD_VAIO] = "vaio-ar",
2525};
2526
2527static struct snd_pci_quirk stac9872_cfg_tbl[] = {
2528 SND_PCI_QUIRK(0x104d, 0x81e6, "Sony VAIO F/S", CXD9872RD_VAIO),
2529 SND_PCI_QUIRK(0x104d, 0x81ef, "Sony VAIO F/S", CXD9872RD_VAIO),
2530 SND_PCI_QUIRK(0x104d, 0x81fd, "Sony VAIO AR", CXD9872AKD_VAIO),
Tobin Davis68e22542007-03-12 11:36:39 +01002531 SND_PCI_QUIRK(0x104d, 0x8205, "Sony VAIO AR", CXD9872AKD_VAIO),
Takashi Iwaidb064e52006-03-16 16:04:58 +01002532 {}
2533};
2534
Guillaume Munch6d859062006-08-22 17:15:47 +02002535static int patch_stac9872(struct hda_codec *codec)
Takashi Iwaidb064e52006-03-16 16:04:58 +01002536{
2537 struct sigmatel_spec *spec;
2538 int board_config;
2539
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002540 board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
2541 stac9872_models,
2542 stac9872_cfg_tbl);
Takashi Iwaidb064e52006-03-16 16:04:58 +01002543 if (board_config < 0)
2544 /* unknown config, let generic-parser do its job... */
2545 return snd_hda_parse_generic_codec(codec);
2546
2547 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2548 if (spec == NULL)
2549 return -ENOMEM;
2550
2551 codec->spec = spec;
2552 switch (board_config) {
Guillaume Munch6d859062006-08-22 17:15:47 +02002553 case CXD9872RD_VAIO:
2554 case STAC9872AK_VAIO:
2555 case STAC9872K_VAIO:
Takashi Iwaidb064e52006-03-16 16:04:58 +01002556 spec->mixer = vaio_mixer;
2557 spec->init = vaio_init;
2558 spec->multiout.max_channels = 2;
2559 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
2560 spec->multiout.dac_nids = vaio_dacs;
2561 spec->multiout.hp_nid = VAIO_HP_DAC;
2562 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
2563 spec->adc_nids = vaio_adcs;
2564 spec->input_mux = &vaio_mux;
2565 spec->mux_nids = vaio_mux_nids;
2566 break;
Guillaume Munch6d859062006-08-22 17:15:47 +02002567
2568 case CXD9872AKD_VAIO:
2569 spec->mixer = vaio_ar_mixer;
2570 spec->init = vaio_ar_init;
2571 spec->multiout.max_channels = 2;
2572 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
2573 spec->multiout.dac_nids = vaio_dacs;
2574 spec->multiout.hp_nid = VAIO_HP_DAC;
2575 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
2576 spec->adc_nids = vaio_adcs;
2577 spec->input_mux = &vaio_mux;
2578 spec->mux_nids = vaio_mux_nids;
2579 break;
Takashi Iwaidb064e52006-03-16 16:04:58 +01002580 }
2581
Guillaume Munch6d859062006-08-22 17:15:47 +02002582 codec->patch_ops = stac9872_patch_ops;
Takashi Iwaidb064e52006-03-16 16:04:58 +01002583 return 0;
2584}
2585
2586
2587/*
Matt2f2f4252005-04-13 14:45:30 +02002588 * patch entries
2589 */
2590struct hda_codec_preset snd_hda_preset_sigmatel[] = {
2591 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
2592 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
2593 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
2594 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
2595 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
2596 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
2597 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
Matt Porter22a27c72006-07-06 18:49:10 +02002598 { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
2599 { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
2600 { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
2601 { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
2602 { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
2603 { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
Matt Porter3cc08dc2006-01-23 15:27:49 +01002604 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
2605 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
2606 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
2607 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
2608 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
2609 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
2610 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
2611 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
2612 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
2613 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
Tobin Davis8e21c342007-01-08 11:04:17 +01002614 { .id = 0x83847632, .name = "STAC9202", .patch = patch_stac925x },
2615 { .id = 0x83847633, .name = "STAC9202D", .patch = patch_stac925x },
2616 { .id = 0x83847634, .name = "STAC9250", .patch = patch_stac925x },
2617 { .id = 0x83847635, .name = "STAC9250D", .patch = patch_stac925x },
2618 { .id = 0x83847636, .name = "STAC9251", .patch = patch_stac925x },
2619 { .id = 0x83847637, .name = "STAC9250D", .patch = patch_stac925x },
Guillaume Munch6d859062006-08-22 17:15:47 +02002620 /* The following does not take into account .id=0x83847661 when subsys =
2621 * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
2622 * currently not fully supported.
2623 */
2624 { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
2625 { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
2626 { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
Matt Porterf3302a52006-07-31 12:49:34 +02002627 { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
2628 { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
2629 { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
2630 { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
2631 { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
2632 { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
2633 { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
2634 { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
Matt2f2f4252005-04-13 14:45:30 +02002635 {} /* terminator */
2636};