blob: d2c340e45f9e1728eab57ef06c310d17bbc4f6ed [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
Matt2f2f4252005-04-13 14:45:30 +020098 /* playback */
99 struct hda_multi_out multiout;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100100 hda_nid_t dac_nids[5];
Matt2f2f4252005-04-13 14:45:30 +0200101
102 /* capture */
103 hda_nid_t *adc_nids;
Matt2f2f4252005-04-13 14:45:30 +0200104 unsigned int num_adcs;
Mattdabbed62005-06-14 10:19:34 +0200105 hda_nid_t *mux_nids;
106 unsigned int num_muxes;
Matt Porter8b657272006-10-26 17:12:59 +0200107 hda_nid_t *dmic_nids;
108 unsigned int num_dmics;
109 hda_nid_t dmux_nid;
Mattdabbed62005-06-14 10:19:34 +0200110 hda_nid_t dig_in_nid;
Matt2f2f4252005-04-13 14:45:30 +0200111
Matt2f2f4252005-04-13 14:45:30 +0200112 /* pin widgets */
113 hda_nid_t *pin_nids;
114 unsigned int num_pins;
Matt2f2f4252005-04-13 14:45:30 +0200115 unsigned int *pin_configs;
Richard Fish11b44bb2006-08-23 18:31:34 +0200116 unsigned int *bios_pin_configs;
Matt2f2f4252005-04-13 14:45:30 +0200117
118 /* codec specific stuff */
119 struct hda_verb *init;
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100120 struct snd_kcontrol_new *mixer;
Matt2f2f4252005-04-13 14:45:30 +0200121
122 /* capture source */
Matt Porter8b657272006-10-26 17:12:59 +0200123 struct hda_input_mux *dinput_mux;
124 unsigned int cur_dmux;
Mattc7d4b2f2005-06-27 14:59:41 +0200125 struct hda_input_mux *input_mux;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100126 unsigned int cur_mux[3];
Matt2f2f4252005-04-13 14:45:30 +0200127
Matt Porter403d1942005-11-29 15:00:51 +0100128 /* i/o switches */
129 unsigned int io_switch[2];
Matt2f2f4252005-04-13 14:45:30 +0200130
Mattc7d4b2f2005-06-27 14:59:41 +0200131 struct hda_pcm pcm_rec[2]; /* PCM information */
132
133 /* dynamic controls and input_mux */
134 struct auto_pin_cfg autocfg;
135 unsigned int num_kctl_alloc, num_kctl_used;
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100136 struct snd_kcontrol_new *kctl_alloc;
Matt Porter8b657272006-10-26 17:12:59 +0200137 struct hda_input_mux private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +0200138 struct hda_input_mux private_imux;
Matt2f2f4252005-04-13 14:45:30 +0200139};
140
141static hda_nid_t stac9200_adc_nids[1] = {
142 0x03,
143};
144
145static hda_nid_t stac9200_mux_nids[1] = {
146 0x0c,
147};
148
149static hda_nid_t stac9200_dac_nids[1] = {
150 0x02,
151};
152
Tobin Davis8e21c342007-01-08 11:04:17 +0100153static hda_nid_t stac925x_adc_nids[1] = {
154 0x03,
155};
156
157static hda_nid_t stac925x_mux_nids[1] = {
158 0x0f,
159};
160
161static hda_nid_t stac925x_dac_nids[1] = {
162 0x02,
163};
164
Tobin Davis2c11f952007-05-17 09:36:34 +0200165static hda_nid_t stac925x_dmic_nids[1] = {
166 0x15,
167};
168
Matt2f2f4252005-04-13 14:45:30 +0200169static hda_nid_t stac922x_adc_nids[2] = {
170 0x06, 0x07,
171};
172
173static hda_nid_t stac922x_mux_nids[2] = {
174 0x12, 0x13,
175};
176
Matt Porter3cc08dc2006-01-23 15:27:49 +0100177static hda_nid_t stac927x_adc_nids[3] = {
178 0x07, 0x08, 0x09
179};
180
181static hda_nid_t stac927x_mux_nids[3] = {
182 0x15, 0x16, 0x17
183};
184
Matt Porterf3302a52006-07-31 12:49:34 +0200185static hda_nid_t stac9205_adc_nids[2] = {
186 0x12, 0x13
187};
188
189static hda_nid_t stac9205_mux_nids[2] = {
190 0x19, 0x1a
191};
192
Takashi Iwai25494132007-03-12 12:36:16 +0100193static hda_nid_t stac9205_dmic_nids[2] = {
194 0x17, 0x18,
Matt Porter8b657272006-10-26 17:12:59 +0200195};
196
Mattc7d4b2f2005-06-27 14:59:41 +0200197static hda_nid_t stac9200_pin_nids[8] = {
Tobin Davis93ed1502006-09-01 21:03:12 +0200198 0x08, 0x09, 0x0d, 0x0e,
199 0x0f, 0x10, 0x11, 0x12,
Matt2f2f4252005-04-13 14:45:30 +0200200};
201
Tobin Davis8e21c342007-01-08 11:04:17 +0100202static hda_nid_t stac925x_pin_nids[8] = {
203 0x07, 0x08, 0x0a, 0x0b,
204 0x0c, 0x0d, 0x10, 0x11,
205};
206
Matt2f2f4252005-04-13 14:45:30 +0200207static hda_nid_t stac922x_pin_nids[10] = {
208 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
209 0x0f, 0x10, 0x11, 0x15, 0x1b,
210};
211
Matt Porter3cc08dc2006-01-23 15:27:49 +0100212static hda_nid_t stac927x_pin_nids[14] = {
213 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
214 0x0f, 0x10, 0x11, 0x12, 0x13,
215 0x14, 0x21, 0x22, 0x23,
216};
217
Matt Porterf3302a52006-07-31 12:49:34 +0200218static hda_nid_t stac9205_pin_nids[12] = {
219 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
220 0x0f, 0x14, 0x16, 0x17, 0x18,
221 0x21, 0x22,
Matt Porterf3302a52006-07-31 12:49:34 +0200222};
223
Matt Porter8b657272006-10-26 17:12:59 +0200224static int stac92xx_dmux_enum_info(struct snd_kcontrol *kcontrol,
225 struct snd_ctl_elem_info *uinfo)
226{
227 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
228 struct sigmatel_spec *spec = codec->spec;
229 return snd_hda_input_mux_info(spec->dinput_mux, uinfo);
230}
231
232static int stac92xx_dmux_enum_get(struct snd_kcontrol *kcontrol,
233 struct snd_ctl_elem_value *ucontrol)
234{
235 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
236 struct sigmatel_spec *spec = codec->spec;
237
238 ucontrol->value.enumerated.item[0] = spec->cur_dmux;
239 return 0;
240}
241
242static int stac92xx_dmux_enum_put(struct snd_kcontrol *kcontrol,
243 struct snd_ctl_elem_value *ucontrol)
244{
245 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
246 struct sigmatel_spec *spec = codec->spec;
247
248 return snd_hda_input_mux_put(codec, spec->dinput_mux, ucontrol,
249 spec->dmux_nid, &spec->cur_dmux);
250}
251
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100252static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Matt2f2f4252005-04-13 14:45:30 +0200253{
254 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
255 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +0200256 return snd_hda_input_mux_info(spec->input_mux, uinfo);
Matt2f2f4252005-04-13 14:45:30 +0200257}
258
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100259static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200260{
261 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
262 struct sigmatel_spec *spec = codec->spec;
263 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
264
265 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
266 return 0;
267}
268
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100269static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200270{
271 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
272 struct sigmatel_spec *spec = codec->spec;
273 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
274
Mattc7d4b2f2005-06-27 14:59:41 +0200275 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
Matt2f2f4252005-04-13 14:45:30 +0200276 spec->mux_nids[adc_idx], &spec->cur_mux[adc_idx]);
277}
278
Mattc7d4b2f2005-06-27 14:59:41 +0200279static struct hda_verb stac9200_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200280 /* set dac0mux for dac converter */
Mattc7d4b2f2005-06-27 14:59:41 +0200281 { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
Matt2f2f4252005-04-13 14:45:30 +0200282 {}
283};
284
Tobin Davis8e21c342007-01-08 11:04:17 +0100285static struct hda_verb stac925x_core_init[] = {
286 /* set dac0mux for dac converter */
287 { 0x06, AC_VERB_SET_CONNECT_SEL, 0x00},
288 {}
289};
290
Mattc7d4b2f2005-06-27 14:59:41 +0200291static struct hda_verb stac922x_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200292 /* set master volume and direct control */
Mattc7d4b2f2005-06-27 14:59:41 +0200293 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matt2f2f4252005-04-13 14:45:30 +0200294 {}
295};
296
Tobin Davis93ed1502006-09-01 21:03:12 +0200297static struct hda_verb d965_core_init[] = {
Takashi Iwai19039bd2006-06-28 15:52:16 +0200298 /* set master volume and direct control */
Tobin Davis93ed1502006-09-01 21:03:12 +0200299 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Takashi Iwai19039bd2006-06-28 15:52:16 +0200300 /* unmute node 0x1b */
301 { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
302 /* select node 0x03 as DAC */
303 { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
304 {}
305};
306
Matt Porter3cc08dc2006-01-23 15:27:49 +0100307static struct hda_verb stac927x_core_init[] = {
308 /* set master volume and direct control */
309 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
310 {}
311};
312
Matt Porterf3302a52006-07-31 12:49:34 +0200313static struct hda_verb stac9205_core_init[] = {
314 /* set master volume and direct control */
315 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
316 {}
317};
318
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100319static struct snd_kcontrol_new stac9200_mixer[] = {
Matt2f2f4252005-04-13 14:45:30 +0200320 HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
321 HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
322 {
323 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
324 .name = "Input Source",
325 .count = 1,
326 .info = stac92xx_mux_enum_info,
327 .get = stac92xx_mux_enum_get,
328 .put = stac92xx_mux_enum_put,
329 },
330 HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
331 HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
Mattc7d4b2f2005-06-27 14:59:41 +0200332 HDA_CODEC_VOLUME("Capture Mux Volume", 0x0c, 0, HDA_OUTPUT),
Matt2f2f4252005-04-13 14:45:30 +0200333 { } /* end */
334};
335
Tobin Davis8e21c342007-01-08 11:04:17 +0100336static struct snd_kcontrol_new stac925x_mixer[] = {
Tobin Davis8e21c342007-01-08 11:04:17 +0100337 {
338 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
339 .name = "Input Source",
340 .count = 1,
341 .info = stac92xx_mux_enum_info,
342 .get = stac92xx_mux_enum_get,
343 .put = stac92xx_mux_enum_put,
344 },
345 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_OUTPUT),
346 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_OUTPUT),
347 HDA_CODEC_VOLUME("Capture Mux Volume", 0x0f, 0, HDA_OUTPUT),
348 { } /* end */
349};
350
Mattc7d4b2f2005-06-27 14:59:41 +0200351/* This needs to be generated dynamically based on sequence */
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100352static struct snd_kcontrol_new stac922x_mixer[] = {
Matt2f2f4252005-04-13 14:45:30 +0200353 {
354 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
355 .name = "Input Source",
356 .count = 1,
357 .info = stac92xx_mux_enum_info,
358 .get = stac92xx_mux_enum_get,
359 .put = stac92xx_mux_enum_put,
360 },
361 HDA_CODEC_VOLUME("Capture Volume", 0x17, 0x0, HDA_INPUT),
Takashi Iwai0fd17082006-01-13 18:46:21 +0100362 HDA_CODEC_MUTE("Capture Switch", 0x17, 0x0, HDA_INPUT),
Matt2f2f4252005-04-13 14:45:30 +0200363 HDA_CODEC_VOLUME("Mux Capture Volume", 0x12, 0x0, HDA_OUTPUT),
364 { } /* end */
365};
366
Takashi Iwai19039bd2006-06-28 15:52:16 +0200367/* This needs to be generated dynamically based on sequence */
368static struct snd_kcontrol_new stac9227_mixer[] = {
369 {
370 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
371 .name = "Input Source",
372 .count = 1,
373 .info = stac92xx_mux_enum_info,
374 .get = stac92xx_mux_enum_get,
375 .put = stac92xx_mux_enum_put,
376 },
377 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
378 HDA_CODEC_MUTE("Capture Switch", 0x1b, 0x0, HDA_OUTPUT),
379 { } /* end */
380};
381
Takashi Iwaid1d985f2006-11-23 19:27:12 +0100382static struct snd_kcontrol_new stac927x_mixer[] = {
Matt Porter3cc08dc2006-01-23 15:27:49 +0100383 {
384 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
385 .name = "Input Source",
386 .count = 1,
387 .info = stac92xx_mux_enum_info,
388 .get = stac92xx_mux_enum_get,
389 .put = stac92xx_mux_enum_put,
390 },
391 HDA_CODEC_VOLUME("InMux Capture Volume", 0x15, 0x0, HDA_OUTPUT),
392 HDA_CODEC_VOLUME("InVol Capture Volume", 0x18, 0x0, HDA_INPUT),
393 HDA_CODEC_MUTE("ADCMux Capture Switch", 0x1b, 0x0, HDA_OUTPUT),
394 { } /* end */
395};
396
Takashi Iwaid1d985f2006-11-23 19:27:12 +0100397static struct snd_kcontrol_new stac9205_mixer[] = {
Matt Porterf3302a52006-07-31 12:49:34 +0200398 {
399 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Matt Porter8b657272006-10-26 17:12:59 +0200400 .name = "Digital Input Source",
401 .count = 1,
402 .info = stac92xx_dmux_enum_info,
403 .get = stac92xx_dmux_enum_get,
404 .put = stac92xx_dmux_enum_put,
405 },
406 {
407 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Matt Porterf3302a52006-07-31 12:49:34 +0200408 .name = "Input Source",
409 .count = 1,
410 .info = stac92xx_mux_enum_info,
411 .get = stac92xx_mux_enum_get,
412 .put = stac92xx_mux_enum_put,
413 },
414 HDA_CODEC_VOLUME("InMux Capture Volume", 0x19, 0x0, HDA_OUTPUT),
415 HDA_CODEC_VOLUME("InVol Capture Volume", 0x1b, 0x0, HDA_INPUT),
416 HDA_CODEC_MUTE("ADCMux Capture Switch", 0x1d, 0x0, HDA_OUTPUT),
417 { } /* end */
418};
419
Matt2f2f4252005-04-13 14:45:30 +0200420static int stac92xx_build_controls(struct hda_codec *codec)
421{
422 struct sigmatel_spec *spec = codec->spec;
423 int err;
Mattc7d4b2f2005-06-27 14:59:41 +0200424 int i;
Matt2f2f4252005-04-13 14:45:30 +0200425
426 err = snd_hda_add_new_ctls(codec, spec->mixer);
427 if (err < 0)
428 return err;
Mattc7d4b2f2005-06-27 14:59:41 +0200429
430 for (i = 0; i < spec->num_mixers; i++) {
431 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
432 if (err < 0)
433 return err;
434 }
435
Mattdabbed62005-06-14 10:19:34 +0200436 if (spec->multiout.dig_out_nid) {
437 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
438 if (err < 0)
439 return err;
440 }
441 if (spec->dig_in_nid) {
442 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
443 if (err < 0)
444 return err;
445 }
446 return 0;
Matt2f2f4252005-04-13 14:45:30 +0200447}
448
Matt Porter403d1942005-11-29 15:00:51 +0100449static unsigned int ref9200_pin_configs[8] = {
Mattdabbed62005-06-14 10:19:34 +0200450 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
Matt2f2f4252005-04-13 14:45:30 +0200451 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
452};
453
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100454static unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
455 [STAC_REF] = ref9200_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +0100456};
457
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100458static const char *stac9200_models[STAC_9200_MODELS] = {
459 [STAC_REF] = "ref",
460};
461
462static struct snd_pci_quirk stac9200_cfg_tbl[] = {
463 /* SigmaTel reference board */
464 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
465 "DFI LanParty", STAC_REF),
Matt Portere7377072006-11-06 11:20:38 +0100466 /* Dell laptops have BIOS problem */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100467 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01b5,
468 "Dell Inspiron 630m", STAC_REF),
469 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c2,
470 "Dell Latitude D620", STAC_REF),
471 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cb,
472 "Dell Latitude 120L", STAC_REF),
Cory T. Tusar877b8662007-01-30 17:30:55 +0100473 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cc,
474 "Dell Latitude D820", STAC_REF),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +0100475 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cd,
476 "Dell Inspiron E1705/9400", STAC_REF),
477 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ce,
478 "Dell XPS M1710", STAC_REF),
Takashi Iwaif0f96742007-02-14 00:59:17 +0100479 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cf,
480 "Dell Precision M90", STAC_REF),
Daniel T Chen8286c532007-05-15 11:46:23 +0200481 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d6,
482 "unknown Dell", STAC_REF),
Tobin Davis49c605d2007-05-17 09:38:24 +0200483 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d8,
484 "Dell Inspiron 640m", STAC_REF),
485 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f5,
486 "Dell Inspiron 1501", STAC_REF),
487
488 /* Panasonic */
489 SND_PCI_QUIRK(0x10f7, 0x8338, "Panasonic CF-74", STAC_REF),
490
Matt Porter403d1942005-11-29 15:00:51 +0100491 {} /* terminator */
492};
493
Tobin Davis8e21c342007-01-08 11:04:17 +0100494static unsigned int ref925x_pin_configs[8] = {
495 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
496 0x90a70320, 0x02214210, 0x400003f1, 0x9033032e,
497};
498
499static unsigned int stac925x_MA6_pin_configs[8] = {
500 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
501 0x90a70320, 0x90100211, 0x400003f1, 0x9033032e,
502};
503
Tobin Davis2c11f952007-05-17 09:36:34 +0200504static unsigned int stac925x_PA6_pin_configs[8] = {
505 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
506 0x50a103f0, 0x90100211, 0x400003f1, 0x9033032e,
507};
508
Tobin Davis8e21c342007-01-08 11:04:17 +0100509static unsigned int stac925xM2_2_pin_configs[8] = {
Steve Longerbeam7353e142007-05-29 14:36:17 +0200510 0x40c003f3, 0x424503f2, 0x04180011, 0x02a19020,
511 0x50a103f0, 0x90100212, 0x400003f1, 0x9033032e,
Tobin Davis8e21c342007-01-08 11:04:17 +0100512};
513
514static unsigned int *stac925x_brd_tbl[STAC_925x_MODELS] = {
515 [STAC_REF] = ref925x_pin_configs,
516 [STAC_M2_2] = stac925xM2_2_pin_configs,
517 [STAC_MA6] = stac925x_MA6_pin_configs,
Tobin Davis2c11f952007-05-17 09:36:34 +0200518 [STAC_PA6] = stac925x_PA6_pin_configs,
Tobin Davis8e21c342007-01-08 11:04:17 +0100519};
520
521static const char *stac925x_models[STAC_925x_MODELS] = {
522 [STAC_REF] = "ref",
523 [STAC_M2_2] = "m2-2",
524 [STAC_MA6] = "m6",
Tobin Davis2c11f952007-05-17 09:36:34 +0200525 [STAC_PA6] = "pa6",
Tobin Davis8e21c342007-01-08 11:04:17 +0100526};
527
528static struct snd_pci_quirk stac925x_cfg_tbl[] = {
529 /* SigmaTel reference board */
530 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, "DFI LanParty", STAC_REF),
Tobin Davis2c11f952007-05-17 09:36:34 +0200531 SND_PCI_QUIRK(0x8384, 0x7632, "Stac9202 Reference Board", STAC_REF),
Tobin Davis8e21c342007-01-08 11:04:17 +0100532 SND_PCI_QUIRK(0x107b, 0x0316, "Gateway M255", STAC_REF),
533 SND_PCI_QUIRK(0x107b, 0x0366, "Gateway MP6954", STAC_REF),
534 SND_PCI_QUIRK(0x107b, 0x0461, "Gateway NX560XL", STAC_MA6),
Tobin Davis2c11f952007-05-17 09:36:34 +0200535 SND_PCI_QUIRK(0x107b, 0x0681, "Gateway NX860", STAC_PA6),
Tobin Davis8e21c342007-01-08 11:04:17 +0100536 SND_PCI_QUIRK(0x1002, 0x437b, "Gateway MX6453", STAC_M2_2),
537 {} /* terminator */
538};
539
Matt Porter403d1942005-11-29 15:00:51 +0100540static unsigned int ref922x_pin_configs[10] = {
541 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
542 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
Matt2f2f4252005-04-13 14:45:30 +0200543 0x40000100, 0x40000100,
544};
545
Matt Porter403d1942005-11-29 15:00:51 +0100546static unsigned int d945gtp3_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +0100547 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
Matt Porter403d1942005-11-29 15:00:51 +0100548 0x40000100, 0x40000100, 0x40000100, 0x40000100,
549 0x02a19120, 0x40000100,
550};
551
552static unsigned int d945gtp5_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +0100553 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
554 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
Matt Porter403d1942005-11-29 15:00:51 +0100555 0x02a19320, 0x40000100,
556};
557
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +0200558static unsigned int intel_mac_v1_pin_configs[10] = {
559 0x0121e21f, 0x400000ff, 0x9017e110, 0x400000fd,
560 0x400000fe, 0x0181e020, 0x1145e030, 0x11c5e240,
Takashi Iwai3fc24d82007-02-16 13:27:18 +0100561 0x400000fc, 0x400000fb,
562};
563
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +0200564static unsigned int intel_mac_v2_pin_configs[10] = {
565 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
566 0x400000fe, 0x0181e020, 0x1145e230, 0x500000fa,
Sylvain FORETf16928f2007-04-27 14:22:36 +0200567 0x400000fc, 0x400000fb,
568};
569
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +0200570static unsigned int intel_mac_v3_pin_configs[10] = {
571 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
572 0x400000fe, 0x0181e020, 0x1145e230, 0x11c5e240,
573 0x400000fc, 0x400000fb,
574};
575
576static unsigned int intel_mac_v4_pin_configs[10] = {
577 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
578 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
579 0x400000fc, 0x400000fb,
580};
581
582static unsigned int intel_mac_v5_pin_configs[10] = {
583 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
584 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
585 0x400000fc, 0x400000fb,
Takashi Iwai0dae0f82007-05-21 12:41:29 +0200586};
587
Takashi Iwai76c08822007-06-19 12:17:42 +0200588static unsigned int stac922x_dell_pin_configs[10] = {
589 0x0221121e, 0x408103ff, 0x02a1123e, 0x90100310,
590 0x408003f1, 0x0221122f, 0x03451340, 0x40c003f2,
591 0x50a003f3, 0x405003f4
592};
593
Takashi Iwai19039bd2006-06-28 15:52:16 +0200594static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100595 [STAC_D945_REF] = ref922x_pin_configs,
Takashi Iwai19039bd2006-06-28 15:52:16 +0200596 [STAC_D945GTP3] = d945gtp3_pin_configs,
597 [STAC_D945GTP5] = d945gtp5_pin_configs,
Takashi Iwai76c08822007-06-19 12:17:42 +0200598 [STAC_922X_DELL] = stac922x_dell_pin_configs,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +0200599 [STAC_INTEL_MAC_V1] = intel_mac_v1_pin_configs,
600 [STAC_INTEL_MAC_V2] = intel_mac_v2_pin_configs,
601 [STAC_INTEL_MAC_V3] = intel_mac_v3_pin_configs,
602 [STAC_INTEL_MAC_V4] = intel_mac_v4_pin_configs,
603 [STAC_INTEL_MAC_V5] = intel_mac_v5_pin_configs,
604 /* for backward compitability */
605 [STAC_MACMINI] = intel_mac_v3_pin_configs,
606 [STAC_MACBOOK] = intel_mac_v5_pin_configs,
607 [STAC_MACBOOK_PRO_V1] = intel_mac_v3_pin_configs,
608 [STAC_MACBOOK_PRO_V2] = intel_mac_v3_pin_configs,
609 [STAC_IMAC_INTEL] = intel_mac_v2_pin_configs,
610 [STAC_IMAC_INTEL_20] = intel_mac_v3_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +0100611};
612
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100613static const char *stac922x_models[STAC_922X_MODELS] = {
614 [STAC_D945_REF] = "ref",
615 [STAC_D945GTP5] = "5stack",
616 [STAC_D945GTP3] = "3stack",
Takashi Iwai76c08822007-06-19 12:17:42 +0200617 [STAC_922X_DELL] = "dell",
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +0200618 [STAC_INTEL_MAC_V1] = "intel-mac-v1",
619 [STAC_INTEL_MAC_V2] = "intel-mac-v2",
620 [STAC_INTEL_MAC_V3] = "intel-mac-v3",
621 [STAC_INTEL_MAC_V4] = "intel-mac-v4",
622 [STAC_INTEL_MAC_V5] = "intel-mac-v5",
623 /* for backward compitability */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100624 [STAC_MACMINI] = "macmini",
Takashi Iwai3fc24d82007-02-16 13:27:18 +0100625 [STAC_MACBOOK] = "macbook",
Nicolas Boichat6f0778d2007-03-15 12:38:15 +0100626 [STAC_MACBOOK_PRO_V1] = "macbook-pro-v1",
627 [STAC_MACBOOK_PRO_V2] = "macbook-pro",
Sylvain FORETf16928f2007-04-27 14:22:36 +0200628 [STAC_IMAC_INTEL] = "imac-intel",
Takashi Iwai0dae0f82007-05-21 12:41:29 +0200629 [STAC_IMAC_INTEL_20] = "imac-intel-20",
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100630};
631
632static struct snd_pci_quirk stac922x_cfg_tbl[] = {
633 /* SigmaTel reference board */
634 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
635 "DFI LanParty", STAC_D945_REF),
636 /* Intel 945G based systems */
637 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101,
638 "Intel D945G", STAC_D945GTP3),
639 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0202,
640 "Intel D945G", STAC_D945GTP3),
641 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0606,
642 "Intel D945G", STAC_D945GTP3),
643 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0601,
644 "Intel D945G", STAC_D945GTP3),
645 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0111,
646 "Intel D945G", STAC_D945GTP3),
647 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1115,
648 "Intel D945G", STAC_D945GTP3),
649 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1116,
650 "Intel D945G", STAC_D945GTP3),
651 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1117,
652 "Intel D945G", STAC_D945GTP3),
653 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1118,
654 "Intel D945G", STAC_D945GTP3),
655 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1119,
656 "Intel D945G", STAC_D945GTP3),
657 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x8826,
658 "Intel D945G", STAC_D945GTP3),
659 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5049,
660 "Intel D945G", STAC_D945GTP3),
661 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5055,
662 "Intel D945G", STAC_D945GTP3),
663 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5048,
664 "Intel D945G", STAC_D945GTP3),
665 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0110,
666 "Intel D945G", STAC_D945GTP3),
667 /* Intel D945G 5-stack systems */
668 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0404,
669 "Intel D945G", STAC_D945GTP5),
670 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0303,
671 "Intel D945G", STAC_D945GTP5),
672 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0013,
673 "Intel D945G", STAC_D945GTP5),
674 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0417,
675 "Intel D945G", STAC_D945GTP5),
676 /* Intel 945P based systems */
677 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0b0b,
678 "Intel D945P", STAC_D945GTP3),
679 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0112,
680 "Intel D945P", STAC_D945GTP3),
681 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0d0d,
682 "Intel D945P", STAC_D945GTP3),
683 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0909,
684 "Intel D945P", STAC_D945GTP3),
685 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0505,
686 "Intel D945P", STAC_D945GTP3),
687 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707,
688 "Intel D945P", STAC_D945GTP5),
689 /* other systems */
690 /* Apple Mac Mini (early 2006) */
691 SND_PCI_QUIRK(0x8384, 0x7680,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +0200692 "Mac Mini", STAC_INTEL_MAC_V3),
Takashi Iwai76c08822007-06-19 12:17:42 +0200693 /* Dell */
694 SND_PCI_QUIRK(0x1028, 0x01d7, "Dell XPS M1210", STAC_922X_DELL),
695
Matt Porter403d1942005-11-29 15:00:51 +0100696 {} /* terminator */
697};
698
Matt Porter3cc08dc2006-01-23 15:27:49 +0100699static unsigned int ref927x_pin_configs[14] = {
Tobin Davis93ed1502006-09-01 21:03:12 +0200700 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
701 0x01a19040, 0x01011012, 0x01016011, 0x0101201f,
702 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
703 0x01c42190, 0x40000100,
Matt Porter3cc08dc2006-01-23 15:27:49 +0100704};
705
Tobin Davis93ed1502006-09-01 21:03:12 +0200706static unsigned int d965_3st_pin_configs[14] = {
Tobin Davis81d3dbd2006-08-22 19:44:45 +0200707 0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
708 0x01a19021, 0x01813024, 0x40000100, 0x40000100,
709 0x40000100, 0x40000100, 0x40000100, 0x40000100,
710 0x40000100, 0x40000100
711};
712
Tobin Davis93ed1502006-09-01 21:03:12 +0200713static unsigned int d965_5st_pin_configs[14] = {
714 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
715 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
716 0x40000100, 0x40000100, 0x40000100, 0x01442070,
717 0x40000100, 0x40000100
718};
719
720static unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100721 [STAC_D965_REF] = ref927x_pin_configs,
Tobin Davis93ed1502006-09-01 21:03:12 +0200722 [STAC_D965_3ST] = d965_3st_pin_configs,
723 [STAC_D965_5ST] = d965_5st_pin_configs,
Matt Porter3cc08dc2006-01-23 15:27:49 +0100724};
725
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100726static const char *stac927x_models[STAC_927X_MODELS] = {
727 [STAC_D965_REF] = "ref",
728 [STAC_D965_3ST] = "3stack",
729 [STAC_D965_5ST] = "5stack",
730};
731
732static struct snd_pci_quirk stac927x_cfg_tbl[] = {
733 /* SigmaTel reference board */
734 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
735 "DFI LanParty", STAC_D965_REF),
Tobin Davis81d3dbd2006-08-22 19:44:45 +0200736 /* Intel 946 based systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100737 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST),
738 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST),
Tobin Davis93ed1502006-09-01 21:03:12 +0200739 /* 965 based 3 stack systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100740 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2116, "Intel D965", STAC_D965_3ST),
741 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2115, "Intel D965", STAC_D965_3ST),
742 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2114, "Intel D965", STAC_D965_3ST),
743 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2113, "Intel D965", STAC_D965_3ST),
744 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2112, "Intel D965", STAC_D965_3ST),
745 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2111, "Intel D965", STAC_D965_3ST),
746 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2110, "Intel D965", STAC_D965_3ST),
747 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2009, "Intel D965", STAC_D965_3ST),
748 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2008, "Intel D965", STAC_D965_3ST),
749 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2007, "Intel D965", STAC_D965_3ST),
750 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2006, "Intel D965", STAC_D965_3ST),
751 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2005, "Intel D965", STAC_D965_3ST),
752 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2004, "Intel D965", STAC_D965_3ST),
753 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2003, "Intel D965", STAC_D965_3ST),
754 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2002, "Intel D965", STAC_D965_3ST),
755 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2001, "Intel D965", STAC_D965_3ST),
Tobin Davis93ed1502006-09-01 21:03:12 +0200756 /* 965 based 5 stack systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100757 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2301, "Intel D965", STAC_D965_5ST),
758 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2302, "Intel D965", STAC_D965_5ST),
759 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2303, "Intel D965", STAC_D965_5ST),
760 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2304, "Intel D965", STAC_D965_5ST),
761 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2305, "Intel D965", STAC_D965_5ST),
762 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2501, "Intel D965", STAC_D965_5ST),
763 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2502, "Intel D965", STAC_D965_5ST),
764 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2503, "Intel D965", STAC_D965_5ST),
765 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2504, "Intel D965", STAC_D965_5ST),
Matt Porter3cc08dc2006-01-23 15:27:49 +0100766 {} /* terminator */
767};
768
Matt Porterf3302a52006-07-31 12:49:34 +0200769static unsigned int ref9205_pin_configs[12] = {
770 0x40000100, 0x40000100, 0x01016011, 0x01014010,
Matt Porter8b657272006-10-26 17:12:59 +0200771 0x01813122, 0x01a19021, 0x40000100, 0x40000100,
772 0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
Matt Porterf3302a52006-07-31 12:49:34 +0200773};
774
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100775static unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
Matthew Ranostay87d48362007-07-17 11:52:24 +0200776 [STAC_REF] = ref9205_pin_configs,
777 [STAC_M43xx] = NULL,
Matt Porterf3302a52006-07-31 12:49:34 +0200778};
779
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100780static const char *stac9205_models[STAC_9205_MODELS] = {
781 [STAC_9205_REF] = "ref",
782};
783
784static struct snd_pci_quirk stac9205_cfg_tbl[] = {
785 /* SigmaTel reference board */
786 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
787 "DFI LanParty", STAC_9205_REF),
Matthew Ranostay87d48362007-07-17 11:52:24 +0200788 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x01f8,
789 "Dell Precision", STAC_M43xx),
790 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x01ff,
791 "Dell Precision", STAC_M43xx),
Matt Porterf3302a52006-07-31 12:49:34 +0200792 {} /* terminator */
793};
794
Richard Fish11b44bb2006-08-23 18:31:34 +0200795static int stac92xx_save_bios_config_regs(struct hda_codec *codec)
796{
797 int i;
798 struct sigmatel_spec *spec = codec->spec;
799
800 if (! spec->bios_pin_configs) {
801 spec->bios_pin_configs = kcalloc(spec->num_pins,
802 sizeof(*spec->bios_pin_configs), GFP_KERNEL);
803 if (! spec->bios_pin_configs)
804 return -ENOMEM;
805 }
806
807 for (i = 0; i < spec->num_pins; i++) {
808 hda_nid_t nid = spec->pin_nids[i];
809 unsigned int pin_cfg;
810
811 pin_cfg = snd_hda_codec_read(codec, nid, 0,
812 AC_VERB_GET_CONFIG_DEFAULT, 0x00);
813 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x bios pin config %8.8x\n",
814 nid, pin_cfg);
815 spec->bios_pin_configs[i] = pin_cfg;
816 }
817
818 return 0;
819}
820
Matthew Ranostay87d48362007-07-17 11:52:24 +0200821static void stac92xx_set_config_reg(struct hda_codec *codec,
822 hda_nid_t pin_nid, unsigned int pin_config)
823{
824 int i;
825 snd_hda_codec_write(codec, pin_nid, 0,
826 AC_VERB_SET_CONFIG_DEFAULT_BYTES_0,
827 pin_config & 0x000000ff);
828 snd_hda_codec_write(codec, pin_nid, 0,
829 AC_VERB_SET_CONFIG_DEFAULT_BYTES_1,
830 (pin_config & 0x0000ff00) >> 8);
831 snd_hda_codec_write(codec, pin_nid, 0,
832 AC_VERB_SET_CONFIG_DEFAULT_BYTES_2,
833 (pin_config & 0x00ff0000) >> 16);
834 snd_hda_codec_write(codec, pin_nid, 0,
835 AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
836 pin_config >> 24);
837 i = snd_hda_codec_read(codec, pin_nid, 0,
838 AC_VERB_GET_CONFIG_DEFAULT,
839 0x00);
840 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x pin config %8.8x\n",
841 pin_nid, i);
842}
843
Matt2f2f4252005-04-13 14:45:30 +0200844static void stac92xx_set_config_regs(struct hda_codec *codec)
845{
846 int i;
847 struct sigmatel_spec *spec = codec->spec;
Matt2f2f4252005-04-13 14:45:30 +0200848
Matthew Ranostay87d48362007-07-17 11:52:24 +0200849 if (!spec->pin_configs)
850 return;
Richard Fish11b44bb2006-08-23 18:31:34 +0200851
Matthew Ranostay87d48362007-07-17 11:52:24 +0200852 for (i = 0; i < spec->num_pins; i++)
853 stac92xx_set_config_reg(codec, spec->pin_nids[i],
854 spec->pin_configs[i]);
Matt2f2f4252005-04-13 14:45:30 +0200855}
Matt2f2f4252005-04-13 14:45:30 +0200856
Matthew Ranostay87d48362007-07-17 11:52:24 +0200857static void stac92xx_enable_gpio_mask(struct hda_codec *codec,
858 int gpio_mask, int gpio_data)
Matthew Ranostay92a22be2007-06-19 16:48:28 +0200859{
Matthew Ranostay87d48362007-07-17 11:52:24 +0200860 /* Configure GPIOx as output */
Matthew Ranostay92a22be2007-06-19 16:48:28 +0200861 snd_hda_codec_write(codec, codec->afg, 0,
Matthew Ranostay87d48362007-07-17 11:52:24 +0200862 AC_VERB_SET_GPIO_DIRECTION, gpio_mask);
863 /* Configure GPIOx as CMOS */
Matthew Ranostay92a22be2007-06-19 16:48:28 +0200864 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0x00000000);
Matthew Ranostay87d48362007-07-17 11:52:24 +0200865 /* Assert GPIOx */
Matthew Ranostay92a22be2007-06-19 16:48:28 +0200866 snd_hda_codec_write(codec, codec->afg, 0,
Matthew Ranostay87d48362007-07-17 11:52:24 +0200867 AC_VERB_SET_GPIO_DATA, gpio_data);
868 /* Enable GPIOx */
Matthew Ranostay92a22be2007-06-19 16:48:28 +0200869 snd_hda_codec_write(codec, codec->afg, 0,
Matthew Ranostay87d48362007-07-17 11:52:24 +0200870 AC_VERB_SET_GPIO_MASK, gpio_mask);
Matthew Ranostay92a22be2007-06-19 16:48:28 +0200871}
872
Matt2f2f4252005-04-13 14:45:30 +0200873/*
874 * Analog playback callbacks
875 */
876static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
877 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100878 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200879{
880 struct sigmatel_spec *spec = codec->spec;
881 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
882}
883
884static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
885 struct hda_codec *codec,
886 unsigned int stream_tag,
887 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100888 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200889{
890 struct sigmatel_spec *spec = codec->spec;
Matt Porter403d1942005-11-29 15:00:51 +0100891 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
Matt2f2f4252005-04-13 14:45:30 +0200892}
893
894static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
895 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100896 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200897{
898 struct sigmatel_spec *spec = codec->spec;
899 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
900}
901
902/*
Mattdabbed62005-06-14 10:19:34 +0200903 * Digital playback callbacks
904 */
905static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
906 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100907 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +0200908{
909 struct sigmatel_spec *spec = codec->spec;
910 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
911}
912
913static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
914 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100915 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +0200916{
917 struct sigmatel_spec *spec = codec->spec;
918 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
919}
920
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200921static int stac92xx_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
922 struct hda_codec *codec,
923 unsigned int stream_tag,
924 unsigned int format,
925 struct snd_pcm_substream *substream)
926{
927 struct sigmatel_spec *spec = codec->spec;
928 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
929 stream_tag, format, substream);
930}
931
Mattdabbed62005-06-14 10:19:34 +0200932
933/*
Matt2f2f4252005-04-13 14:45:30 +0200934 * Analog capture callbacks
935 */
936static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
937 struct hda_codec *codec,
938 unsigned int stream_tag,
939 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100940 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200941{
942 struct sigmatel_spec *spec = codec->spec;
943
944 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
945 stream_tag, 0, format);
946 return 0;
947}
948
949static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
950 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100951 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200952{
953 struct sigmatel_spec *spec = codec->spec;
954
955 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 0, 0, 0);
956 return 0;
957}
958
Mattdabbed62005-06-14 10:19:34 +0200959static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
960 .substreams = 1,
961 .channels_min = 2,
962 .channels_max = 2,
963 /* NID is set in stac92xx_build_pcms */
964 .ops = {
965 .open = stac92xx_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200966 .close = stac92xx_dig_playback_pcm_close,
967 .prepare = stac92xx_dig_playback_pcm_prepare
Mattdabbed62005-06-14 10:19:34 +0200968 },
969};
970
971static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
972 .substreams = 1,
973 .channels_min = 2,
974 .channels_max = 2,
975 /* NID is set in stac92xx_build_pcms */
976};
977
Matt2f2f4252005-04-13 14:45:30 +0200978static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
979 .substreams = 1,
980 .channels_min = 2,
Mattc7d4b2f2005-06-27 14:59:41 +0200981 .channels_max = 8,
Matt2f2f4252005-04-13 14:45:30 +0200982 .nid = 0x02, /* NID to query formats and rates */
983 .ops = {
984 .open = stac92xx_playback_pcm_open,
985 .prepare = stac92xx_playback_pcm_prepare,
986 .cleanup = stac92xx_playback_pcm_cleanup
987 },
988};
989
Matt Porter3cc08dc2006-01-23 15:27:49 +0100990static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
991 .substreams = 1,
992 .channels_min = 2,
993 .channels_max = 2,
994 .nid = 0x06, /* NID to query formats and rates */
995 .ops = {
996 .open = stac92xx_playback_pcm_open,
997 .prepare = stac92xx_playback_pcm_prepare,
998 .cleanup = stac92xx_playback_pcm_cleanup
999 },
1000};
1001
Matt2f2f4252005-04-13 14:45:30 +02001002static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
1003 .substreams = 2,
1004 .channels_min = 2,
1005 .channels_max = 2,
Matt Porter3cc08dc2006-01-23 15:27:49 +01001006 /* NID is set in stac92xx_build_pcms */
Matt2f2f4252005-04-13 14:45:30 +02001007 .ops = {
1008 .prepare = stac92xx_capture_pcm_prepare,
1009 .cleanup = stac92xx_capture_pcm_cleanup
1010 },
1011};
1012
1013static int stac92xx_build_pcms(struct hda_codec *codec)
1014{
1015 struct sigmatel_spec *spec = codec->spec;
1016 struct hda_pcm *info = spec->pcm_rec;
1017
1018 codec->num_pcms = 1;
1019 codec->pcm_info = info;
1020
Mattc7d4b2f2005-06-27 14:59:41 +02001021 info->name = "STAC92xx Analog";
Matt2f2f4252005-04-13 14:45:30 +02001022 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
Matt2f2f4252005-04-13 14:45:30 +02001023 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
Matt Porter3cc08dc2006-01-23 15:27:49 +01001024 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
1025
1026 if (spec->alt_switch) {
1027 codec->num_pcms++;
1028 info++;
1029 info->name = "STAC92xx Analog Alt";
1030 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
1031 }
Matt2f2f4252005-04-13 14:45:30 +02001032
Mattdabbed62005-06-14 10:19:34 +02001033 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
1034 codec->num_pcms++;
1035 info++;
1036 info->name = "STAC92xx Digital";
1037 if (spec->multiout.dig_out_nid) {
1038 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
1039 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
1040 }
1041 if (spec->dig_in_nid) {
1042 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
1043 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
1044 }
1045 }
1046
Matt2f2f4252005-04-13 14:45:30 +02001047 return 0;
1048}
1049
Takashi Iwaic960a032006-03-23 17:06:28 +01001050static unsigned int stac92xx_get_vref(struct hda_codec *codec, hda_nid_t nid)
1051{
1052 unsigned int pincap = snd_hda_param_read(codec, nid,
1053 AC_PAR_PIN_CAP);
1054 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
1055 if (pincap & AC_PINCAP_VREF_100)
1056 return AC_PINCTL_VREF_100;
1057 if (pincap & AC_PINCAP_VREF_80)
1058 return AC_PINCTL_VREF_80;
1059 if (pincap & AC_PINCAP_VREF_50)
1060 return AC_PINCTL_VREF_50;
1061 if (pincap & AC_PINCAP_VREF_GRD)
1062 return AC_PINCTL_VREF_GRD;
1063 return 0;
1064}
1065
Matt Porter403d1942005-11-29 15:00:51 +01001066static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
1067
1068{
1069 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
1070}
1071
Takashi Iwaia5ce8892007-07-23 15:42:26 +02001072#define stac92xx_io_switch_info snd_ctl_boolean_mono_info
Matt Porter403d1942005-11-29 15:00:51 +01001073
1074static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1075{
1076 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1077 struct sigmatel_spec *spec = codec->spec;
1078 int io_idx = kcontrol-> private_value & 0xff;
1079
1080 ucontrol->value.integer.value[0] = spec->io_switch[io_idx];
1081 return 0;
1082}
1083
1084static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1085{
1086 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1087 struct sigmatel_spec *spec = codec->spec;
1088 hda_nid_t nid = kcontrol->private_value >> 8;
1089 int io_idx = kcontrol-> private_value & 0xff;
1090 unsigned short val = ucontrol->value.integer.value[0];
1091
1092 spec->io_switch[io_idx] = val;
1093
1094 if (val)
1095 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
Takashi Iwaic960a032006-03-23 17:06:28 +01001096 else {
1097 unsigned int pinctl = AC_PINCTL_IN_EN;
1098 if (io_idx) /* set VREF for mic */
1099 pinctl |= stac92xx_get_vref(codec, nid);
1100 stac92xx_auto_set_pinctl(codec, nid, pinctl);
1101 }
Matt Porter403d1942005-11-29 15:00:51 +01001102 return 1;
1103}
1104
1105#define STAC_CODEC_IO_SWITCH(xname, xpval) \
1106 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1107 .name = xname, \
1108 .index = 0, \
1109 .info = stac92xx_io_switch_info, \
1110 .get = stac92xx_io_switch_get, \
1111 .put = stac92xx_io_switch_put, \
1112 .private_value = xpval, \
1113 }
1114
1115
Mattc7d4b2f2005-06-27 14:59:41 +02001116enum {
1117 STAC_CTL_WIDGET_VOL,
1118 STAC_CTL_WIDGET_MUTE,
Matt Porter403d1942005-11-29 15:00:51 +01001119 STAC_CTL_WIDGET_IO_SWITCH,
Mattc7d4b2f2005-06-27 14:59:41 +02001120};
1121
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001122static struct snd_kcontrol_new stac92xx_control_templates[] = {
Mattc7d4b2f2005-06-27 14:59:41 +02001123 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
1124 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Matt Porter403d1942005-11-29 15:00:51 +01001125 STAC_CODEC_IO_SWITCH(NULL, 0),
Mattc7d4b2f2005-06-27 14:59:41 +02001126};
1127
1128/* add dynamic controls */
1129static int stac92xx_add_control(struct sigmatel_spec *spec, int type, const char *name, unsigned long val)
1130{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001131 struct snd_kcontrol_new *knew;
Mattc7d4b2f2005-06-27 14:59:41 +02001132
1133 if (spec->num_kctl_used >= spec->num_kctl_alloc) {
1134 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
1135
1136 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */
1137 if (! knew)
1138 return -ENOMEM;
1139 if (spec->kctl_alloc) {
1140 memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
1141 kfree(spec->kctl_alloc);
1142 }
1143 spec->kctl_alloc = knew;
1144 spec->num_kctl_alloc = num;
1145 }
1146
1147 knew = &spec->kctl_alloc[spec->num_kctl_used];
1148 *knew = stac92xx_control_templates[type];
Takashi Iwai82fe0c52005-06-30 10:54:33 +02001149 knew->name = kstrdup(name, GFP_KERNEL);
Mattc7d4b2f2005-06-27 14:59:41 +02001150 if (! knew->name)
1151 return -ENOMEM;
1152 knew->private_value = val;
1153 spec->num_kctl_used++;
1154 return 0;
1155}
1156
Matt Porter403d1942005-11-29 15:00:51 +01001157/* flag inputs as additional dynamic lineouts */
1158static int stac92xx_add_dyn_out_pins(struct hda_codec *codec, struct auto_pin_cfg *cfg)
1159{
1160 struct sigmatel_spec *spec = codec->spec;
Steve Longerbeam7b043892007-05-03 20:50:03 +02001161 unsigned int wcaps, wtype;
1162 int i, num_dacs = 0;
1163
1164 /* use the wcaps cache to count all DACs available for line-outs */
1165 for (i = 0; i < codec->num_nodes; i++) {
1166 wcaps = codec->wcaps[i];
1167 wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
1168 if (wtype == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL))
1169 num_dacs++;
1170 }
Matt Porter403d1942005-11-29 15:00:51 +01001171
Steve Longerbeam7b043892007-05-03 20:50:03 +02001172 snd_printdd("%s: total dac count=%d\n", __func__, num_dacs);
1173
Matt Porter403d1942005-11-29 15:00:51 +01001174 switch (cfg->line_outs) {
1175 case 3:
1176 /* add line-in as side */
Steve Longerbeam7b043892007-05-03 20:50:03 +02001177 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 3) {
Matt Porter403d1942005-11-29 15:00:51 +01001178 cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_LINE];
1179 spec->line_switch = 1;
1180 cfg->line_outs++;
1181 }
1182 break;
1183 case 2:
1184 /* add line-in as clfe and mic as side */
Steve Longerbeam7b043892007-05-03 20:50:03 +02001185 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 2) {
Matt Porter403d1942005-11-29 15:00:51 +01001186 cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_LINE];
1187 spec->line_switch = 1;
1188 cfg->line_outs++;
1189 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02001190 if (cfg->input_pins[AUTO_PIN_MIC] && num_dacs > 3) {
Matt Porter403d1942005-11-29 15:00:51 +01001191 cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_MIC];
1192 spec->mic_switch = 1;
1193 cfg->line_outs++;
1194 }
1195 break;
1196 case 1:
1197 /* add line-in as surr and mic as clfe */
Steve Longerbeam7b043892007-05-03 20:50:03 +02001198 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 1) {
Matt Porter403d1942005-11-29 15:00:51 +01001199 cfg->line_out_pins[1] = cfg->input_pins[AUTO_PIN_LINE];
1200 spec->line_switch = 1;
1201 cfg->line_outs++;
1202 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02001203 if (cfg->input_pins[AUTO_PIN_MIC] && num_dacs > 2) {
Matt Porter403d1942005-11-29 15:00:51 +01001204 cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_MIC];
1205 spec->mic_switch = 1;
1206 cfg->line_outs++;
1207 }
1208 break;
1209 }
1210
1211 return 0;
1212}
1213
Steve Longerbeam7b043892007-05-03 20:50:03 +02001214
1215static int is_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
1216{
1217 int i;
1218
1219 for (i = 0; i < spec->multiout.num_dacs; i++) {
1220 if (spec->multiout.dac_nids[i] == nid)
1221 return 1;
1222 }
1223
1224 return 0;
1225}
1226
Matt Porter3cc08dc2006-01-23 15:27:49 +01001227/*
Steve Longerbeam7b043892007-05-03 20:50:03 +02001228 * Fill in the dac_nids table from the parsed pin configuration
1229 * This function only works when every pin in line_out_pins[]
1230 * contains atleast one DAC in its connection list. Some 92xx
1231 * codecs are not connected directly to a DAC, such as the 9200
1232 * and 9202/925x. For those, dac_nids[] must be hard-coded.
Matt Porter3cc08dc2006-01-23 15:27:49 +01001233 */
Takashi Iwai19039bd2006-06-28 15:52:16 +02001234static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec,
Takashi Iwaidf802952007-07-02 19:18:00 +02001235 struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02001236{
1237 struct sigmatel_spec *spec = codec->spec;
Steve Longerbeam7b043892007-05-03 20:50:03 +02001238 int i, j, conn_len = 0;
1239 hda_nid_t nid, conn[HDA_MAX_CONNECTIONS];
1240 unsigned int wcaps, wtype;
1241
Mattc7d4b2f2005-06-27 14:59:41 +02001242 for (i = 0; i < cfg->line_outs; i++) {
1243 nid = cfg->line_out_pins[i];
Steve Longerbeam7b043892007-05-03 20:50:03 +02001244 conn_len = snd_hda_get_connections(codec, nid, conn,
1245 HDA_MAX_CONNECTIONS);
1246 for (j = 0; j < conn_len; j++) {
1247 wcaps = snd_hda_param_read(codec, conn[j],
1248 AC_PAR_AUDIO_WIDGET_CAP);
1249 wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
1250
1251 if (wtype != AC_WID_AUD_OUT ||
1252 (wcaps & AC_WCAP_DIGITAL))
1253 continue;
1254 /* conn[j] is a DAC routed to this line-out */
1255 if (!is_in_dac_nids(spec, conn[j]))
1256 break;
1257 }
1258
1259 if (j == conn_len) {
Takashi Iwaidf802952007-07-02 19:18:00 +02001260 if (spec->multiout.num_dacs > 0) {
1261 /* we have already working output pins,
1262 * so let's drop the broken ones again
1263 */
1264 cfg->line_outs = spec->multiout.num_dacs;
1265 break;
1266 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02001267 /* error out, no available DAC found */
1268 snd_printk(KERN_ERR
1269 "%s: No available DAC for pin 0x%x\n",
1270 __func__, nid);
1271 return -ENODEV;
1272 }
1273
1274 spec->multiout.dac_nids[i] = conn[j];
1275 spec->multiout.num_dacs++;
1276 if (conn_len > 1) {
1277 /* select this DAC in the pin's input mux */
1278 snd_hda_codec_write(codec, nid, 0,
1279 AC_VERB_SET_CONNECT_SEL, j);
1280
1281 }
Mattc7d4b2f2005-06-27 14:59:41 +02001282 }
1283
Steve Longerbeam7b043892007-05-03 20:50:03 +02001284 snd_printd("dac_nids=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
1285 spec->multiout.num_dacs,
1286 spec->multiout.dac_nids[0],
1287 spec->multiout.dac_nids[1],
1288 spec->multiout.dac_nids[2],
1289 spec->multiout.dac_nids[3],
1290 spec->multiout.dac_nids[4]);
Mattc7d4b2f2005-06-27 14:59:41 +02001291 return 0;
1292}
1293
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001294/* create volume control/switch for the given prefx type */
1295static int create_controls(struct sigmatel_spec *spec, const char *pfx, hda_nid_t nid, int chs)
1296{
1297 char name[32];
1298 int err;
1299
1300 sprintf(name, "%s Playback Volume", pfx);
1301 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, name,
1302 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1303 if (err < 0)
1304 return err;
1305 sprintf(name, "%s Playback Switch", pfx);
1306 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, name,
1307 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1308 if (err < 0)
1309 return err;
1310 return 0;
1311}
1312
Mattc7d4b2f2005-06-27 14:59:41 +02001313/* add playback controls from the parsed DAC table */
Takashi Iwai19039bd2006-06-28 15:52:16 +02001314static int stac92xx_auto_create_multi_out_ctls(struct sigmatel_spec *spec,
1315 const struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02001316{
Takashi Iwai19039bd2006-06-28 15:52:16 +02001317 static const char *chname[4] = {
1318 "Front", "Surround", NULL /*CLFE*/, "Side"
1319 };
Mattc7d4b2f2005-06-27 14:59:41 +02001320 hda_nid_t nid;
1321 int i, err;
1322
1323 for (i = 0; i < cfg->line_outs; i++) {
Matt Porter403d1942005-11-29 15:00:51 +01001324 if (!spec->multiout.dac_nids[i])
Mattc7d4b2f2005-06-27 14:59:41 +02001325 continue;
1326
1327 nid = spec->multiout.dac_nids[i];
1328
1329 if (i == 2) {
1330 /* Center/LFE */
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001331 err = create_controls(spec, "Center", nid, 1);
1332 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001333 return err;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001334 err = create_controls(spec, "LFE", nid, 2);
1335 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001336 return err;
1337 } else {
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001338 err = create_controls(spec, chname[i], nid, 3);
1339 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001340 return err;
1341 }
1342 }
1343
Matt Porter403d1942005-11-29 15:00:51 +01001344 if (spec->line_switch)
1345 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Line In as Output Switch", cfg->input_pins[AUTO_PIN_LINE] << 8)) < 0)
1346 return err;
1347
1348 if (spec->mic_switch)
1349 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Mic as Output Switch", (cfg->input_pins[AUTO_PIN_MIC] << 8) | 1)) < 0)
1350 return err;
1351
Mattc7d4b2f2005-06-27 14:59:41 +02001352 return 0;
1353}
1354
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001355static int check_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
1356{
Steve Longerbeam7b043892007-05-03 20:50:03 +02001357 if (is_in_dac_nids(spec, nid))
1358 return 1;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001359 if (spec->multiout.hp_nid == nid)
1360 return 1;
1361 return 0;
1362}
1363
1364static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
1365{
1366 if (!spec->multiout.hp_nid)
1367 spec->multiout.hp_nid = nid;
1368 else if (spec->multiout.num_dacs > 4) {
1369 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
1370 return 1;
1371 } else {
1372 spec->multiout.dac_nids[spec->multiout.num_dacs] = nid;
1373 spec->multiout.num_dacs++;
1374 }
1375 return 0;
1376}
1377
1378/* add playback controls for Speaker and HP outputs */
1379static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
1380 struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02001381{
1382 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02001383 hda_nid_t nid;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001384 int i, old_num_dacs, err;
Mattc7d4b2f2005-06-27 14:59:41 +02001385
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001386 old_num_dacs = spec->multiout.num_dacs;
1387 for (i = 0; i < cfg->hp_outs; i++) {
1388 unsigned int wid_caps = get_wcaps(codec, cfg->hp_pins[i]);
1389 if (wid_caps & AC_WCAP_UNSOL_CAP)
1390 spec->hp_detect = 1;
1391 nid = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
1392 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
1393 if (check_in_dac_nids(spec, nid))
1394 nid = 0;
1395 if (! nid)
Mattc7d4b2f2005-06-27 14:59:41 +02001396 continue;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001397 add_spec_dacs(spec, nid);
1398 }
1399 for (i = 0; i < cfg->speaker_outs; i++) {
Steve Longerbeam7b043892007-05-03 20:50:03 +02001400 nid = snd_hda_codec_read(codec, cfg->speaker_pins[i], 0,
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001401 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
1402 if (check_in_dac_nids(spec, nid))
1403 nid = 0;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001404 if (! nid)
1405 continue;
1406 add_spec_dacs(spec, nid);
Mattc7d4b2f2005-06-27 14:59:41 +02001407 }
Matthew Ranostay1b290a52007-07-12 15:17:34 +02001408 for (i = 0; i < cfg->line_outs; i++) {
1409 nid = snd_hda_codec_read(codec, cfg->line_out_pins[i], 0,
1410 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
1411 if (check_in_dac_nids(spec, nid))
1412 nid = 0;
1413 if (! nid)
1414 continue;
1415 add_spec_dacs(spec, nid);
1416 }
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001417 for (i = old_num_dacs; i < spec->multiout.num_dacs; i++) {
1418 static const char *pfxs[] = {
1419 "Speaker", "External Speaker", "Speaker2",
1420 };
1421 err = create_controls(spec, pfxs[i - old_num_dacs],
1422 spec->multiout.dac_nids[i], 3);
1423 if (err < 0)
1424 return err;
1425 }
1426 if (spec->multiout.hp_nid) {
1427 const char *pfx;
1428 if (old_num_dacs == spec->multiout.num_dacs)
1429 pfx = "Master";
1430 else
1431 pfx = "Headphone";
1432 err = create_controls(spec, pfx, spec->multiout.hp_nid, 3);
1433 if (err < 0)
1434 return err;
1435 }
Mattc7d4b2f2005-06-27 14:59:41 +02001436
1437 return 0;
1438}
1439
Matt Porter8b657272006-10-26 17:12:59 +02001440/* labels for dmic mux inputs */
Adrian Bunkddc2cec2006-11-20 12:03:44 +01001441static const char *stac92xx_dmic_labels[5] = {
Matt Porter8b657272006-10-26 17:12:59 +02001442 "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
1443 "Digital Mic 3", "Digital Mic 4"
1444};
1445
1446/* create playback/capture controls for input pins on dmic capable codecs */
1447static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
1448 const struct auto_pin_cfg *cfg)
1449{
1450 struct sigmatel_spec *spec = codec->spec;
1451 struct hda_input_mux *dimux = &spec->private_dimux;
1452 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
1453 int i, j;
1454
1455 dimux->items[dimux->num_items].label = stac92xx_dmic_labels[0];
1456 dimux->items[dimux->num_items].index = 0;
1457 dimux->num_items++;
1458
1459 for (i = 0; i < spec->num_dmics; i++) {
1460 int index;
1461 int num_cons;
1462 unsigned int def_conf;
1463
1464 def_conf = snd_hda_codec_read(codec,
1465 spec->dmic_nids[i],
1466 0,
1467 AC_VERB_GET_CONFIG_DEFAULT,
1468 0);
1469 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
1470 continue;
1471
1472 num_cons = snd_hda_get_connections(codec,
1473 spec->dmux_nid,
1474 con_lst,
1475 HDA_MAX_NUM_INPUTS);
1476 for (j = 0; j < num_cons; j++)
1477 if (con_lst[j] == spec->dmic_nids[i]) {
1478 index = j;
1479 goto found;
1480 }
1481 continue;
1482found:
1483 dimux->items[dimux->num_items].label =
1484 stac92xx_dmic_labels[dimux->num_items];
1485 dimux->items[dimux->num_items].index = index;
1486 dimux->num_items++;
1487 }
1488
1489 return 0;
1490}
1491
Mattc7d4b2f2005-06-27 14:59:41 +02001492/* create playback/capture controls for input pins */
1493static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
1494{
1495 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02001496 struct hda_input_mux *imux = &spec->private_imux;
1497 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
1498 int i, j, k;
1499
1500 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwai314634b2006-09-21 11:56:18 +02001501 int index;
Mattc7d4b2f2005-06-27 14:59:41 +02001502
Takashi Iwai314634b2006-09-21 11:56:18 +02001503 if (!cfg->input_pins[i])
1504 continue;
1505 index = -1;
1506 for (j = 0; j < spec->num_muxes; j++) {
1507 int num_cons;
1508 num_cons = snd_hda_get_connections(codec,
1509 spec->mux_nids[j],
1510 con_lst,
1511 HDA_MAX_NUM_INPUTS);
1512 for (k = 0; k < num_cons; k++)
1513 if (con_lst[k] == cfg->input_pins[i]) {
1514 index = k;
1515 goto found;
1516 }
Mattc7d4b2f2005-06-27 14:59:41 +02001517 }
Takashi Iwai314634b2006-09-21 11:56:18 +02001518 continue;
1519 found:
1520 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
1521 imux->items[imux->num_items].index = index;
1522 imux->num_items++;
Mattc7d4b2f2005-06-27 14:59:41 +02001523 }
1524
Steve Longerbeam7b043892007-05-03 20:50:03 +02001525 if (imux->num_items) {
Sam Revitch62fe78e2006-05-10 15:09:17 +02001526 /*
1527 * Set the current input for the muxes.
1528 * The STAC9221 has two input muxes with identical source
1529 * NID lists. Hopefully this won't get confused.
1530 */
1531 for (i = 0; i < spec->num_muxes; i++) {
1532 snd_hda_codec_write(codec, spec->mux_nids[i], 0,
1533 AC_VERB_SET_CONNECT_SEL,
1534 imux->items[0].index);
1535 }
1536 }
1537
Mattc7d4b2f2005-06-27 14:59:41 +02001538 return 0;
1539}
1540
Mattc7d4b2f2005-06-27 14:59:41 +02001541static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
1542{
1543 struct sigmatel_spec *spec = codec->spec;
1544 int i;
1545
1546 for (i = 0; i < spec->autocfg.line_outs; i++) {
1547 hda_nid_t nid = spec->autocfg.line_out_pins[i];
1548 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
1549 }
1550}
1551
1552static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
1553{
1554 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001555 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02001556
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001557 for (i = 0; i < spec->autocfg.hp_outs; i++) {
1558 hda_nid_t pin;
1559 pin = spec->autocfg.hp_pins[i];
1560 if (pin) /* connect to front */
1561 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
1562 }
1563 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
1564 hda_nid_t pin;
1565 pin = spec->autocfg.speaker_pins[i];
1566 if (pin) /* connect to front */
1567 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
1568 }
Mattc7d4b2f2005-06-27 14:59:41 +02001569}
1570
Matt Porter3cc08dc2006-01-23 15:27:49 +01001571static 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 +02001572{
1573 struct sigmatel_spec *spec = codec->spec;
1574 int err;
1575
Matt Porter8b657272006-10-26 17:12:59 +02001576 if ((err = snd_hda_parse_pin_def_config(codec,
1577 &spec->autocfg,
1578 spec->dmic_nids)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001579 return err;
Takashi Iwai82bc9552006-03-21 11:24:42 +01001580 if (! spec->autocfg.line_outs)
Matt Porter869264c2006-01-25 19:20:50 +01001581 return 0; /* can't find valid pin config */
Takashi Iwai19039bd2006-06-28 15:52:16 +02001582
Matt Porter403d1942005-11-29 15:00:51 +01001583 if ((err = stac92xx_add_dyn_out_pins(codec, &spec->autocfg)) < 0)
1584 return err;
Takashi Iwai19039bd2006-06-28 15:52:16 +02001585 if (spec->multiout.num_dacs == 0)
1586 if ((err = stac92xx_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
1587 return err;
Mattc7d4b2f2005-06-27 14:59:41 +02001588
1589 if ((err = stac92xx_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
1590 (err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg)) < 0 ||
1591 (err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
1592 return err;
1593
Matt Porter8b657272006-10-26 17:12:59 +02001594 if (spec->num_dmics > 0)
1595 if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
1596 &spec->autocfg)) < 0)
1597 return err;
1598
Mattc7d4b2f2005-06-27 14:59:41 +02001599 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Matt Porter403d1942005-11-29 15:00:51 +01001600 if (spec->multiout.max_channels > 2)
Mattc7d4b2f2005-06-27 14:59:41 +02001601 spec->surr_switch = 1;
Mattc7d4b2f2005-06-27 14:59:41 +02001602
Takashi Iwai82bc9552006-03-21 11:24:42 +01001603 if (spec->autocfg.dig_out_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01001604 spec->multiout.dig_out_nid = dig_out;
Takashi Iwai82bc9552006-03-21 11:24:42 +01001605 if (spec->autocfg.dig_in_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01001606 spec->dig_in_nid = dig_in;
Mattc7d4b2f2005-06-27 14:59:41 +02001607
1608 if (spec->kctl_alloc)
1609 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
1610
1611 spec->input_mux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02001612 spec->dinput_mux = &spec->private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +02001613
1614 return 1;
1615}
1616
Takashi Iwai82bc9552006-03-21 11:24:42 +01001617/* add playback controls for HP output */
1618static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
1619 struct auto_pin_cfg *cfg)
1620{
1621 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001622 hda_nid_t pin = cfg->hp_pins[0];
Takashi Iwai82bc9552006-03-21 11:24:42 +01001623 unsigned int wid_caps;
1624
1625 if (! pin)
1626 return 0;
1627
1628 wid_caps = get_wcaps(codec, pin);
Takashi Iwai505cb342006-03-27 12:51:52 +02001629 if (wid_caps & AC_WCAP_UNSOL_CAP)
Takashi Iwai82bc9552006-03-21 11:24:42 +01001630 spec->hp_detect = 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +01001631
1632 return 0;
1633}
1634
Richard Fish160ea0d2006-09-06 13:58:25 +02001635/* add playback controls for LFE output */
1636static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
1637 struct auto_pin_cfg *cfg)
1638{
1639 struct sigmatel_spec *spec = codec->spec;
1640 int err;
1641 hda_nid_t lfe_pin = 0x0;
1642 int i;
1643
1644 /*
1645 * search speaker outs and line outs for a mono speaker pin
1646 * with an amp. If one is found, add LFE controls
1647 * for it.
1648 */
1649 for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
1650 hda_nid_t pin = spec->autocfg.speaker_pins[i];
1651 unsigned long wcaps = get_wcaps(codec, pin);
1652 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
1653 if (wcaps == AC_WCAP_OUT_AMP)
1654 /* found a mono speaker with an amp, must be lfe */
1655 lfe_pin = pin;
1656 }
1657
1658 /* if speaker_outs is 0, then speakers may be in line_outs */
1659 if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
1660 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
1661 hda_nid_t pin = spec->autocfg.line_out_pins[i];
1662 unsigned long cfg;
1663 cfg = snd_hda_codec_read(codec, pin, 0,
1664 AC_VERB_GET_CONFIG_DEFAULT,
1665 0x00);
1666 if (get_defcfg_device(cfg) == AC_JACK_SPEAKER) {
1667 unsigned long wcaps = get_wcaps(codec, pin);
1668 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
1669 if (wcaps == AC_WCAP_OUT_AMP)
1670 /* found a mono speaker with an amp,
1671 must be lfe */
1672 lfe_pin = pin;
1673 }
1674 }
1675 }
1676
1677 if (lfe_pin) {
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001678 err = create_controls(spec, "LFE", lfe_pin, 1);
Richard Fish160ea0d2006-09-06 13:58:25 +02001679 if (err < 0)
1680 return err;
1681 }
1682
1683 return 0;
1684}
1685
Mattc7d4b2f2005-06-27 14:59:41 +02001686static int stac9200_parse_auto_config(struct hda_codec *codec)
1687{
1688 struct sigmatel_spec *spec = codec->spec;
1689 int err;
1690
Kailang Yangdf694da2005-12-05 19:42:22 +01001691 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001692 return err;
1693
1694 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
1695 return err;
1696
Takashi Iwai82bc9552006-03-21 11:24:42 +01001697 if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
1698 return err;
1699
Richard Fish160ea0d2006-09-06 13:58:25 +02001700 if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
1701 return err;
1702
Takashi Iwai82bc9552006-03-21 11:24:42 +01001703 if (spec->autocfg.dig_out_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02001704 spec->multiout.dig_out_nid = 0x05;
Takashi Iwai82bc9552006-03-21 11:24:42 +01001705 if (spec->autocfg.dig_in_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02001706 spec->dig_in_nid = 0x04;
Mattc7d4b2f2005-06-27 14:59:41 +02001707
1708 if (spec->kctl_alloc)
1709 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
1710
1711 spec->input_mux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02001712 spec->dinput_mux = &spec->private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +02001713
1714 return 1;
1715}
1716
Sam Revitch62fe78e2006-05-10 15:09:17 +02001717/*
1718 * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
1719 * funky external mute control using GPIO pins.
1720 */
1721
1722static void stac922x_gpio_mute(struct hda_codec *codec, int pin, int muted)
1723{
1724 unsigned int gpiostate, gpiomask, gpiodir;
1725
1726 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
1727 AC_VERB_GET_GPIO_DATA, 0);
1728
1729 if (!muted)
1730 gpiostate |= (1 << pin);
1731 else
1732 gpiostate &= ~(1 << pin);
1733
1734 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
1735 AC_VERB_GET_GPIO_MASK, 0);
1736 gpiomask |= (1 << pin);
1737
1738 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
1739 AC_VERB_GET_GPIO_DIRECTION, 0);
1740 gpiodir |= (1 << pin);
1741
1742 /* AppleHDA seems to do this -- WTF is this verb?? */
1743 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
1744
1745 snd_hda_codec_write(codec, codec->afg, 0,
1746 AC_VERB_SET_GPIO_MASK, gpiomask);
1747 snd_hda_codec_write(codec, codec->afg, 0,
1748 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
1749
1750 msleep(1);
1751
1752 snd_hda_codec_write(codec, codec->afg, 0,
1753 AC_VERB_SET_GPIO_DATA, gpiostate);
1754}
1755
Takashi Iwai314634b2006-09-21 11:56:18 +02001756static void enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
1757 unsigned int event)
1758{
1759 if (get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP)
1760 snd_hda_codec_write(codec, nid, 0,
1761 AC_VERB_SET_UNSOLICITED_ENABLE,
1762 (AC_USRSP_EN | event));
1763}
1764
Mattc7d4b2f2005-06-27 14:59:41 +02001765static int stac92xx_init(struct hda_codec *codec)
1766{
1767 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai82bc9552006-03-21 11:24:42 +01001768 struct auto_pin_cfg *cfg = &spec->autocfg;
1769 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02001770
Mattc7d4b2f2005-06-27 14:59:41 +02001771 snd_hda_sequence_write(codec, spec->init);
1772
Takashi Iwai82bc9552006-03-21 11:24:42 +01001773 /* set up pins */
1774 if (spec->hp_detect) {
Takashi Iwai505cb342006-03-27 12:51:52 +02001775 /* Enable unsolicited responses on the HP widget */
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001776 for (i = 0; i < cfg->hp_outs; i++)
Takashi Iwai314634b2006-09-21 11:56:18 +02001777 enable_pin_detect(codec, cfg->hp_pins[i],
1778 STAC_HP_EVENT);
Takashi Iwai0a07acaf2007-03-13 10:40:23 +01001779 /* force to enable the first line-out; the others are set up
1780 * in unsol_event
1781 */
1782 stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
1783 AC_PINCTL_OUT_EN);
Takashi Iwaieb995a82006-09-21 14:28:21 +02001784 stac92xx_auto_init_hp_out(codec);
Takashi Iwai82bc9552006-03-21 11:24:42 +01001785 /* fake event to set up pins */
1786 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
1787 } else {
1788 stac92xx_auto_init_multi_out(codec);
1789 stac92xx_auto_init_hp_out(codec);
1790 }
1791 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwaic960a032006-03-23 17:06:28 +01001792 hda_nid_t nid = cfg->input_pins[i];
1793 if (nid) {
1794 unsigned int pinctl = AC_PINCTL_IN_EN;
1795 if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC)
1796 pinctl |= stac92xx_get_vref(codec, nid);
1797 stac92xx_auto_set_pinctl(codec, nid, pinctl);
1798 }
Takashi Iwai82bc9552006-03-21 11:24:42 +01001799 }
Matt Porter8b657272006-10-26 17:12:59 +02001800 if (spec->num_dmics > 0)
1801 for (i = 0; i < spec->num_dmics; i++)
1802 stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
1803 AC_PINCTL_IN_EN);
1804
Takashi Iwai82bc9552006-03-21 11:24:42 +01001805 if (cfg->dig_out_pin)
1806 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pin,
1807 AC_PINCTL_OUT_EN);
1808 if (cfg->dig_in_pin)
1809 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
1810 AC_PINCTL_IN_EN);
1811
Sam Revitch62fe78e2006-05-10 15:09:17 +02001812 if (spec->gpio_mute) {
1813 stac922x_gpio_mute(codec, 0, 0);
1814 stac922x_gpio_mute(codec, 1, 0);
1815 }
1816
Mattc7d4b2f2005-06-27 14:59:41 +02001817 return 0;
1818}
1819
Matt2f2f4252005-04-13 14:45:30 +02001820static void stac92xx_free(struct hda_codec *codec)
1821{
Mattc7d4b2f2005-06-27 14:59:41 +02001822 struct sigmatel_spec *spec = codec->spec;
1823 int i;
1824
1825 if (! spec)
1826 return;
1827
1828 if (spec->kctl_alloc) {
1829 for (i = 0; i < spec->num_kctl_used; i++)
1830 kfree(spec->kctl_alloc[i].name);
1831 kfree(spec->kctl_alloc);
1832 }
1833
Richard Fish11b44bb2006-08-23 18:31:34 +02001834 if (spec->bios_pin_configs)
1835 kfree(spec->bios_pin_configs);
1836
Mattc7d4b2f2005-06-27 14:59:41 +02001837 kfree(spec);
Matt2f2f4252005-04-13 14:45:30 +02001838}
1839
Matt4e550962005-07-04 17:51:39 +02001840static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
1841 unsigned int flag)
1842{
1843 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
1844 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Steve Longerbeam7b043892007-05-03 20:50:03 +02001845
Takashi Iwaif9acba42007-05-29 18:01:06 +02001846 if (pin_ctl & AC_PINCTL_IN_EN) {
1847 /*
1848 * we need to check the current set-up direction of
1849 * shared input pins since they can be switched via
1850 * "xxx as Output" mixer switch
1851 */
1852 struct sigmatel_spec *spec = codec->spec;
1853 struct auto_pin_cfg *cfg = &spec->autocfg;
1854 if ((nid == cfg->input_pins[AUTO_PIN_LINE] &&
1855 spec->line_switch) ||
1856 (nid == cfg->input_pins[AUTO_PIN_MIC] &&
1857 spec->mic_switch))
1858 return;
1859 }
1860
Steve Longerbeam7b043892007-05-03 20:50:03 +02001861 /* if setting pin direction bits, clear the current
1862 direction bits first */
1863 if (flag & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))
1864 pin_ctl &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
1865
Matt4e550962005-07-04 17:51:39 +02001866 snd_hda_codec_write(codec, nid, 0,
1867 AC_VERB_SET_PIN_WIDGET_CONTROL,
1868 pin_ctl | flag);
1869}
1870
1871static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
1872 unsigned int flag)
1873{
1874 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
1875 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
1876 snd_hda_codec_write(codec, nid, 0,
1877 AC_VERB_SET_PIN_WIDGET_CONTROL,
1878 pin_ctl & ~flag);
1879}
1880
Takashi Iwai314634b2006-09-21 11:56:18 +02001881static int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
1882{
1883 if (!nid)
1884 return 0;
1885 if (snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PIN_SENSE, 0x00)
1886 & (1 << 31))
1887 return 1;
1888 return 0;
1889}
1890
1891static void stac92xx_hp_detect(struct hda_codec *codec, unsigned int res)
Matt4e550962005-07-04 17:51:39 +02001892{
1893 struct sigmatel_spec *spec = codec->spec;
1894 struct auto_pin_cfg *cfg = &spec->autocfg;
1895 int i, presence;
1896
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001897 presence = 0;
1898 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai314634b2006-09-21 11:56:18 +02001899 presence = get_pin_presence(codec, cfg->hp_pins[i]);
1900 if (presence)
1901 break;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001902 }
Matt4e550962005-07-04 17:51:39 +02001903
1904 if (presence) {
1905 /* disable lineouts, enable hp */
1906 for (i = 0; i < cfg->line_outs; i++)
1907 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
1908 AC_PINCTL_OUT_EN);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001909 for (i = 0; i < cfg->speaker_outs; i++)
1910 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
1911 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02001912 } else {
1913 /* enable lineouts, disable hp */
1914 for (i = 0; i < cfg->line_outs; i++)
1915 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
1916 AC_PINCTL_OUT_EN);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001917 for (i = 0; i < cfg->speaker_outs; i++)
1918 stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
1919 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02001920 }
1921}
1922
Takashi Iwai314634b2006-09-21 11:56:18 +02001923static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
1924{
1925 switch (res >> 26) {
1926 case STAC_HP_EVENT:
1927 stac92xx_hp_detect(codec, res);
1928 break;
1929 }
1930}
1931
Mattff6fdc32005-06-27 15:06:52 +02001932#ifdef CONFIG_PM
1933static int stac92xx_resume(struct hda_codec *codec)
1934{
1935 struct sigmatel_spec *spec = codec->spec;
1936 int i;
1937
1938 stac92xx_init(codec);
Richard Fish11b44bb2006-08-23 18:31:34 +02001939 stac92xx_set_config_regs(codec);
Takashi Iwai5d403b12007-05-03 12:32:29 +02001940 snd_hda_resume_ctls(codec, spec->mixer);
Mattff6fdc32005-06-27 15:06:52 +02001941 for (i = 0; i < spec->num_mixers; i++)
1942 snd_hda_resume_ctls(codec, spec->mixers[i]);
1943 if (spec->multiout.dig_out_nid)
1944 snd_hda_resume_spdif_out(codec);
1945 if (spec->dig_in_nid)
1946 snd_hda_resume_spdif_in(codec);
1947
1948 return 0;
1949}
1950#endif
1951
Matt2f2f4252005-04-13 14:45:30 +02001952static struct hda_codec_ops stac92xx_patch_ops = {
1953 .build_controls = stac92xx_build_controls,
1954 .build_pcms = stac92xx_build_pcms,
1955 .init = stac92xx_init,
1956 .free = stac92xx_free,
Matt4e550962005-07-04 17:51:39 +02001957 .unsol_event = stac92xx_unsol_event,
Mattff6fdc32005-06-27 15:06:52 +02001958#ifdef CONFIG_PM
1959 .resume = stac92xx_resume,
1960#endif
Matt2f2f4252005-04-13 14:45:30 +02001961};
1962
1963static int patch_stac9200(struct hda_codec *codec)
1964{
1965 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02001966 int err;
Matt2f2f4252005-04-13 14:45:30 +02001967
Takashi Iwaie560d8d2005-09-09 14:21:46 +02001968 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02001969 if (spec == NULL)
1970 return -ENOMEM;
1971
1972 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02001973 spec->num_pins = ARRAY_SIZE(stac9200_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02001974 spec->pin_nids = stac9200_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001975 spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS,
1976 stac9200_models,
1977 stac9200_cfg_tbl);
Richard Fish11b44bb2006-08-23 18:31:34 +02001978 if (spec->board_config < 0) {
1979 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9200, using BIOS defaults\n");
1980 err = stac92xx_save_bios_config_regs(codec);
1981 if (err < 0) {
1982 stac92xx_free(codec);
1983 return err;
1984 }
1985 spec->pin_configs = spec->bios_pin_configs;
1986 } else {
Matt Porter403d1942005-11-29 15:00:51 +01001987 spec->pin_configs = stac9200_brd_tbl[spec->board_config];
1988 stac92xx_set_config_regs(codec);
1989 }
Matt2f2f4252005-04-13 14:45:30 +02001990
1991 spec->multiout.max_channels = 2;
1992 spec->multiout.num_dacs = 1;
1993 spec->multiout.dac_nids = stac9200_dac_nids;
1994 spec->adc_nids = stac9200_adc_nids;
1995 spec->mux_nids = stac9200_mux_nids;
Mattdabbed62005-06-14 10:19:34 +02001996 spec->num_muxes = 1;
Matt Porter8b657272006-10-26 17:12:59 +02001997 spec->num_dmics = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02001998
1999 spec->init = stac9200_core_init;
Matt2f2f4252005-04-13 14:45:30 +02002000 spec->mixer = stac9200_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02002001
2002 err = stac9200_parse_auto_config(codec);
2003 if (err < 0) {
2004 stac92xx_free(codec);
2005 return err;
2006 }
Matt2f2f4252005-04-13 14:45:30 +02002007
2008 codec->patch_ops = stac92xx_patch_ops;
2009
2010 return 0;
2011}
2012
Tobin Davis8e21c342007-01-08 11:04:17 +01002013static int patch_stac925x(struct hda_codec *codec)
2014{
2015 struct sigmatel_spec *spec;
2016 int err;
2017
2018 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2019 if (spec == NULL)
2020 return -ENOMEM;
2021
2022 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02002023 spec->num_pins = ARRAY_SIZE(stac925x_pin_nids);
Tobin Davis8e21c342007-01-08 11:04:17 +01002024 spec->pin_nids = stac925x_pin_nids;
2025 spec->board_config = snd_hda_check_board_config(codec, STAC_925x_MODELS,
2026 stac925x_models,
2027 stac925x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002028 again:
Tobin Davis8e21c342007-01-08 11:04:17 +01002029 if (spec->board_config < 0) {
Tobin Davis2c11f952007-05-17 09:36:34 +02002030 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC925x,"
2031 "using BIOS defaults\n");
Tobin Davis8e21c342007-01-08 11:04:17 +01002032 err = stac92xx_save_bios_config_regs(codec);
2033 if (err < 0) {
2034 stac92xx_free(codec);
2035 return err;
2036 }
2037 spec->pin_configs = spec->bios_pin_configs;
2038 } else if (stac925x_brd_tbl[spec->board_config] != NULL){
2039 spec->pin_configs = stac925x_brd_tbl[spec->board_config];
2040 stac92xx_set_config_regs(codec);
2041 }
2042
2043 spec->multiout.max_channels = 2;
2044 spec->multiout.num_dacs = 1;
2045 spec->multiout.dac_nids = stac925x_dac_nids;
2046 spec->adc_nids = stac925x_adc_nids;
2047 spec->mux_nids = stac925x_mux_nids;
2048 spec->num_muxes = 1;
Tobin Davis2c11f952007-05-17 09:36:34 +02002049 switch (codec->vendor_id) {
2050 case 0x83847632: /* STAC9202 */
2051 case 0x83847633: /* STAC9202D */
2052 case 0x83847636: /* STAC9251 */
2053 case 0x83847637: /* STAC9251D */
2054 spec->num_dmics = 1;
2055 spec->dmic_nids = stac925x_dmic_nids;
2056 break;
2057 default:
2058 spec->num_dmics = 0;
2059 break;
2060 }
Tobin Davis8e21c342007-01-08 11:04:17 +01002061
2062 spec->init = stac925x_core_init;
2063 spec->mixer = stac925x_mixer;
2064
2065 err = stac92xx_parse_auto_config(codec, 0x8, 0x7);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002066 if (!err) {
2067 if (spec->board_config < 0) {
2068 printk(KERN_WARNING "hda_codec: No auto-config is "
2069 "available, default to model=ref\n");
2070 spec->board_config = STAC_925x_REF;
2071 goto again;
2072 }
2073 err = -EINVAL;
2074 }
Tobin Davis8e21c342007-01-08 11:04:17 +01002075 if (err < 0) {
2076 stac92xx_free(codec);
2077 return err;
2078 }
2079
2080 codec->patch_ops = stac92xx_patch_ops;
2081
2082 return 0;
2083}
2084
Matt2f2f4252005-04-13 14:45:30 +02002085static int patch_stac922x(struct hda_codec *codec)
2086{
2087 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02002088 int err;
Matt2f2f4252005-04-13 14:45:30 +02002089
Takashi Iwaie560d8d2005-09-09 14:21:46 +02002090 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02002091 if (spec == NULL)
2092 return -ENOMEM;
2093
2094 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02002095 spec->num_pins = ARRAY_SIZE(stac922x_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02002096 spec->pin_nids = stac922x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002097 spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS,
2098 stac922x_models,
2099 stac922x_cfg_tbl);
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002100 if (spec->board_config == STAC_INTEL_MAC_V3) {
Takashi Iwai3fc24d82007-02-16 13:27:18 +01002101 spec->gpio_mute = 1;
2102 /* Intel Macs have all same PCI SSID, so we need to check
2103 * codec SSID to distinguish the exact models
2104 */
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01002105 printk(KERN_INFO "hda_codec: STAC922x, Apple subsys_id=%x\n", codec->subsystem_id);
Takashi Iwai3fc24d82007-02-16 13:27:18 +01002106 switch (codec->subsystem_id) {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002107
2108 case 0x106b0800:
2109 spec->board_config = STAC_INTEL_MAC_V1;
Abhijit Bhopatkarc45e20e2007-04-17 11:57:16 +02002110 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002111 case 0x106b0600:
2112 case 0x106b0700:
2113 spec->board_config = STAC_INTEL_MAC_V2;
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01002114 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002115 case 0x106b0e00:
2116 case 0x106b0f00:
2117 case 0x106b1600:
2118 case 0x106b1700:
2119 case 0x106b0200:
2120 case 0x106b1e00:
2121 spec->board_config = STAC_INTEL_MAC_V3;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01002122 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002123 case 0x106b1a00:
2124 case 0x00000100:
2125 spec->board_config = STAC_INTEL_MAC_V4;
Sylvain FORETf16928f2007-04-27 14:22:36 +02002126 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002127 case 0x106b0a00:
2128 case 0x106b2200:
2129 spec->board_config = STAC_INTEL_MAC_V5;
Takashi Iwai0dae0f82007-05-21 12:41:29 +02002130 break;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01002131 }
2132 }
2133
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002134 again:
Richard Fish11b44bb2006-08-23 18:31:34 +02002135 if (spec->board_config < 0) {
2136 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC922x, "
2137 "using BIOS defaults\n");
2138 err = stac92xx_save_bios_config_regs(codec);
2139 if (err < 0) {
2140 stac92xx_free(codec);
2141 return err;
2142 }
2143 spec->pin_configs = spec->bios_pin_configs;
2144 } else if (stac922x_brd_tbl[spec->board_config] != NULL) {
Matt Porter403d1942005-11-29 15:00:51 +01002145 spec->pin_configs = stac922x_brd_tbl[spec->board_config];
2146 stac92xx_set_config_regs(codec);
2147 }
Matt2f2f4252005-04-13 14:45:30 +02002148
Matt2f2f4252005-04-13 14:45:30 +02002149 spec->adc_nids = stac922x_adc_nids;
2150 spec->mux_nids = stac922x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01002151 spec->num_muxes = ARRAY_SIZE(stac922x_mux_nids);
Matt Porter8b657272006-10-26 17:12:59 +02002152 spec->num_dmics = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02002153
2154 spec->init = stac922x_core_init;
Matt2f2f4252005-04-13 14:45:30 +02002155 spec->mixer = stac922x_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02002156
2157 spec->multiout.dac_nids = spec->dac_nids;
Takashi Iwai19039bd2006-06-28 15:52:16 +02002158
Matt Porter3cc08dc2006-01-23 15:27:49 +01002159 err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002160 if (!err) {
2161 if (spec->board_config < 0) {
2162 printk(KERN_WARNING "hda_codec: No auto-config is "
2163 "available, default to model=ref\n");
2164 spec->board_config = STAC_D945_REF;
2165 goto again;
2166 }
2167 err = -EINVAL;
2168 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01002169 if (err < 0) {
2170 stac92xx_free(codec);
2171 return err;
2172 }
2173
2174 codec->patch_ops = stac92xx_patch_ops;
2175
Takashi Iwai807a46362007-05-29 19:01:37 +02002176 /* Fix Mux capture level; max to 2 */
2177 snd_hda_override_amp_caps(codec, 0x12, HDA_OUTPUT,
2178 (0 << AC_AMPCAP_OFFSET_SHIFT) |
2179 (2 << AC_AMPCAP_NUM_STEPS_SHIFT) |
2180 (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
2181 (0 << AC_AMPCAP_MUTE_SHIFT));
2182
Matt Porter3cc08dc2006-01-23 15:27:49 +01002183 return 0;
2184}
2185
2186static int patch_stac927x(struct hda_codec *codec)
2187{
2188 struct sigmatel_spec *spec;
2189 int err;
2190
2191 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2192 if (spec == NULL)
2193 return -ENOMEM;
2194
2195 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02002196 spec->num_pins = ARRAY_SIZE(stac927x_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02002197 spec->pin_nids = stac927x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002198 spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS,
2199 stac927x_models,
2200 stac927x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002201 again:
Richard Fish11b44bb2006-08-23 18:31:34 +02002202 if (spec->board_config < 0) {
Matt Porter3cc08dc2006-01-23 15:27:49 +01002203 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC927x, using BIOS defaults\n");
Richard Fish11b44bb2006-08-23 18:31:34 +02002204 err = stac92xx_save_bios_config_regs(codec);
2205 if (err < 0) {
2206 stac92xx_free(codec);
2207 return err;
2208 }
2209 spec->pin_configs = spec->bios_pin_configs;
2210 } else if (stac927x_brd_tbl[spec->board_config] != NULL) {
Matt Porter3cc08dc2006-01-23 15:27:49 +01002211 spec->pin_configs = stac927x_brd_tbl[spec->board_config];
2212 stac92xx_set_config_regs(codec);
2213 }
2214
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002215 switch (spec->board_config) {
Tobin Davis93ed1502006-09-01 21:03:12 +02002216 case STAC_D965_3ST:
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002217 spec->adc_nids = stac927x_adc_nids;
2218 spec->mux_nids = stac927x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01002219 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
Matt Porter8b657272006-10-26 17:12:59 +02002220 spec->num_dmics = 0;
Tobin Davis93ed1502006-09-01 21:03:12 +02002221 spec->init = d965_core_init;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002222 spec->mixer = stac9227_mixer;
2223 break;
Tobin Davis93ed1502006-09-01 21:03:12 +02002224 case STAC_D965_5ST:
2225 spec->adc_nids = stac927x_adc_nids;
2226 spec->mux_nids = stac927x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01002227 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
Matt Porter8b657272006-10-26 17:12:59 +02002228 spec->num_dmics = 0;
Tobin Davis93ed1502006-09-01 21:03:12 +02002229 spec->init = d965_core_init;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002230 spec->mixer = stac9227_mixer;
2231 break;
2232 default:
2233 spec->adc_nids = stac927x_adc_nids;
2234 spec->mux_nids = stac927x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01002235 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
Matt Porter8b657272006-10-26 17:12:59 +02002236 spec->num_dmics = 0;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002237 spec->init = stac927x_core_init;
2238 spec->mixer = stac927x_mixer;
2239 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01002240
2241 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostay87d48362007-07-17 11:52:24 +02002242 /* GPIO0 High = Enable EAPD */
2243 stac92xx_enable_gpio_mask(codec, 0x00000001, 0x00000001);
Matthew Ranostay92a22be2007-06-19 16:48:28 +02002244
Matt Porter3cc08dc2006-01-23 15:27:49 +01002245 err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002246 if (!err) {
2247 if (spec->board_config < 0) {
2248 printk(KERN_WARNING "hda_codec: No auto-config is "
2249 "available, default to model=ref\n");
2250 spec->board_config = STAC_D965_REF;
2251 goto again;
2252 }
2253 err = -EINVAL;
2254 }
Mattc7d4b2f2005-06-27 14:59:41 +02002255 if (err < 0) {
2256 stac92xx_free(codec);
2257 return err;
2258 }
Matt2f2f4252005-04-13 14:45:30 +02002259
2260 codec->patch_ops = stac92xx_patch_ops;
2261
2262 return 0;
2263}
2264
Matt Porterf3302a52006-07-31 12:49:34 +02002265static int patch_stac9205(struct hda_codec *codec)
2266{
2267 struct sigmatel_spec *spec;
Matthew Ranostay87d48362007-07-17 11:52:24 +02002268 int err, gpio_mask, gpio_data;
Matt Porterf3302a52006-07-31 12:49:34 +02002269
2270 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2271 if (spec == NULL)
2272 return -ENOMEM;
2273
2274 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02002275 spec->num_pins = ARRAY_SIZE(stac9205_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02002276 spec->pin_nids = stac9205_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002277 spec->board_config = snd_hda_check_board_config(codec, STAC_9205_MODELS,
2278 stac9205_models,
2279 stac9205_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002280 again:
Richard Fish11b44bb2006-08-23 18:31:34 +02002281 if (spec->board_config < 0) {
2282 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9205, using BIOS defaults\n");
2283 err = stac92xx_save_bios_config_regs(codec);
2284 if (err < 0) {
2285 stac92xx_free(codec);
2286 return err;
2287 }
2288 spec->pin_configs = spec->bios_pin_configs;
2289 } else {
Matt Porterf3302a52006-07-31 12:49:34 +02002290 spec->pin_configs = stac9205_brd_tbl[spec->board_config];
2291 stac92xx_set_config_regs(codec);
2292 }
2293
2294 spec->adc_nids = stac9205_adc_nids;
2295 spec->mux_nids = stac9205_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01002296 spec->num_muxes = ARRAY_SIZE(stac9205_mux_nids);
Matt Porter8b657272006-10-26 17:12:59 +02002297 spec->dmic_nids = stac9205_dmic_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01002298 spec->num_dmics = ARRAY_SIZE(stac9205_dmic_nids);
Matt Porter8b657272006-10-26 17:12:59 +02002299 spec->dmux_nid = 0x1d;
Matt Porterf3302a52006-07-31 12:49:34 +02002300
2301 spec->init = stac9205_core_init;
2302 spec->mixer = stac9205_mixer;
2303
2304 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostay87d48362007-07-17 11:52:24 +02002305
2306 if (spec->board_config == STAC_M43xx) {
2307 /* Enable SPDIF in/out */
2308 stac92xx_set_config_reg(codec, 0x1f, 0x01441030);
2309 stac92xx_set_config_reg(codec, 0x20, 0x1c410030);
Matt Porter33382402006-12-18 13:17:28 +01002310
Matthew Ranostay87d48362007-07-17 11:52:24 +02002311 gpio_mask = 0x00000007; /* GPIO0-2 */
2312 /* GPIO0 High = EAPD, GPIO1 Low = DRM,
2313 * GPIO2 High = Headphone Mute
2314 */
2315 gpio_data = 0x00000005;
2316 } else
2317 gpio_mask = gpio_data = 0x00000001; /* GPIO0 High = EAPD */
2318
2319 stac92xx_enable_gpio_mask(codec, gpio_mask, gpio_data);
Matt Porterf3302a52006-07-31 12:49:34 +02002320 err = stac92xx_parse_auto_config(codec, 0x1f, 0x20);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002321 if (!err) {
2322 if (spec->board_config < 0) {
2323 printk(KERN_WARNING "hda_codec: No auto-config is "
2324 "available, default to model=ref\n");
2325 spec->board_config = STAC_9205_REF;
2326 goto again;
2327 }
2328 err = -EINVAL;
2329 }
Matt Porterf3302a52006-07-31 12:49:34 +02002330 if (err < 0) {
2331 stac92xx_free(codec);
2332 return err;
2333 }
2334
2335 codec->patch_ops = stac92xx_patch_ops;
2336
2337 return 0;
2338}
2339
Matt2f2f4252005-04-13 14:45:30 +02002340/*
Guillaume Munch6d859062006-08-22 17:15:47 +02002341 * STAC9872 hack
Takashi Iwaidb064e52006-03-16 16:04:58 +01002342 */
2343
Guillaume Munch99ccc562006-08-16 19:35:12 +02002344/* static config for Sony VAIO FE550G and Sony VAIO AR */
Takashi Iwaidb064e52006-03-16 16:04:58 +01002345static hda_nid_t vaio_dacs[] = { 0x2 };
2346#define VAIO_HP_DAC 0x5
2347static hda_nid_t vaio_adcs[] = { 0x8 /*,0x6*/ };
2348static hda_nid_t vaio_mux_nids[] = { 0x15 };
2349
2350static struct hda_input_mux vaio_mux = {
2351 .num_items = 2,
2352 .items = {
Takashi Iwaid7737812006-04-25 13:05:43 +02002353 /* { "HP", 0x0 }, */
Takashi Iwai1624cb92007-07-05 13:10:51 +02002354 { "Mic Jack", 0x1 },
2355 { "Internal Mic", 0x2 },
Takashi Iwaidb064e52006-03-16 16:04:58 +01002356 { "PCM", 0x3 },
2357 }
2358};
2359
2360static struct hda_verb vaio_init[] = {
2361 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
2362 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
2363 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
2364 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
2365 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
Takashi Iwai1624cb92007-07-05 13:10:51 +02002366 {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
Takashi Iwaidb064e52006-03-16 16:04:58 +01002367 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
2368 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
2369 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
2370 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
2371 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
2372 {}
2373};
2374
Guillaume Munch6d859062006-08-22 17:15:47 +02002375static struct hda_verb vaio_ar_init[] = {
2376 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
2377 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
2378 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
2379 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
2380/* {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },*/ /* Optical Out */
2381 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
Takashi Iwai1624cb92007-07-05 13:10:51 +02002382 {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
Guillaume Munch6d859062006-08-22 17:15:47 +02002383 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
2384 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
2385/* {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},*/ /* Optical Out */
2386 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
2387 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
2388 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
2389 {}
2390};
2391
Takashi Iwaidb064e52006-03-16 16:04:58 +01002392/* bind volumes of both NID 0x02 and 0x05 */
2393static int vaio_master_vol_put(struct snd_kcontrol *kcontrol,
2394 struct snd_ctl_elem_value *ucontrol)
2395{
2396 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2397 long *valp = ucontrol->value.integer.value;
2398 int change;
2399
2400 change = snd_hda_codec_amp_update(codec, 0x02, 0, HDA_OUTPUT, 0,
2401 0x7f, valp[0] & 0x7f);
2402 change |= snd_hda_codec_amp_update(codec, 0x02, 1, HDA_OUTPUT, 0,
2403 0x7f, valp[1] & 0x7f);
2404 snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
2405 0x7f, valp[0] & 0x7f);
2406 snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
2407 0x7f, valp[1] & 0x7f);
2408 return change;
2409}
2410
2411/* bind volumes of both NID 0x02 and 0x05 */
2412static int vaio_master_sw_put(struct snd_kcontrol *kcontrol,
2413 struct snd_ctl_elem_value *ucontrol)
2414{
2415 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2416 long *valp = ucontrol->value.integer.value;
2417 int change;
2418
2419 change = snd_hda_codec_amp_update(codec, 0x02, 0, HDA_OUTPUT, 0,
Takashi Iwaia9393d72006-05-03 11:59:03 +02002420 0x80, (valp[0] ? 0 : 0x80));
Takashi Iwaidb064e52006-03-16 16:04:58 +01002421 change |= snd_hda_codec_amp_update(codec, 0x02, 1, HDA_OUTPUT, 0,
Takashi Iwaia9393d72006-05-03 11:59:03 +02002422 0x80, (valp[1] ? 0 : 0x80));
Takashi Iwaidb064e52006-03-16 16:04:58 +01002423 snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
Takashi Iwaia9393d72006-05-03 11:59:03 +02002424 0x80, (valp[0] ? 0 : 0x80));
Takashi Iwaidb064e52006-03-16 16:04:58 +01002425 snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
Takashi Iwaia9393d72006-05-03 11:59:03 +02002426 0x80, (valp[1] ? 0 : 0x80));
Takashi Iwaidb064e52006-03-16 16:04:58 +01002427 return change;
2428}
2429
2430static struct snd_kcontrol_new vaio_mixer[] = {
2431 {
2432 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2433 .name = "Master Playback Volume",
2434 .info = snd_hda_mixer_amp_volume_info,
2435 .get = snd_hda_mixer_amp_volume_get,
2436 .put = vaio_master_vol_put,
Takashi Iwaic2566522006-08-17 18:21:36 +02002437 .tlv = { .c = snd_hda_mixer_amp_tlv },
Takashi Iwaidb064e52006-03-16 16:04:58 +01002438 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2439 },
2440 {
2441 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2442 .name = "Master Playback Switch",
2443 .info = snd_hda_mixer_amp_switch_info,
2444 .get = snd_hda_mixer_amp_switch_get,
2445 .put = vaio_master_sw_put,
2446 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2447 },
2448 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
2449 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
2450 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
2451 {
2452 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2453 .name = "Capture Source",
2454 .count = 1,
2455 .info = stac92xx_mux_enum_info,
2456 .get = stac92xx_mux_enum_get,
2457 .put = stac92xx_mux_enum_put,
2458 },
2459 {}
2460};
2461
Guillaume Munch6d859062006-08-22 17:15:47 +02002462static struct snd_kcontrol_new vaio_ar_mixer[] = {
2463 {
2464 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2465 .name = "Master Playback Volume",
2466 .info = snd_hda_mixer_amp_volume_info,
2467 .get = snd_hda_mixer_amp_volume_get,
2468 .put = vaio_master_vol_put,
2469 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2470 },
2471 {
2472 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2473 .name = "Master Playback Switch",
2474 .info = snd_hda_mixer_amp_switch_info,
2475 .get = snd_hda_mixer_amp_switch_get,
2476 .put = vaio_master_sw_put,
2477 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2478 },
2479 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
2480 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
2481 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
2482 /*HDA_CODEC_MUTE("Optical Out Switch", 0x10, 0, HDA_OUTPUT),
2483 HDA_CODEC_VOLUME("Optical Out Volume", 0x10, 0, HDA_OUTPUT),*/
2484 {
2485 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2486 .name = "Capture Source",
2487 .count = 1,
2488 .info = stac92xx_mux_enum_info,
2489 .get = stac92xx_mux_enum_get,
2490 .put = stac92xx_mux_enum_put,
2491 },
2492 {}
2493};
2494
2495static struct hda_codec_ops stac9872_patch_ops = {
Takashi Iwaidb064e52006-03-16 16:04:58 +01002496 .build_controls = stac92xx_build_controls,
2497 .build_pcms = stac92xx_build_pcms,
2498 .init = stac92xx_init,
2499 .free = stac92xx_free,
2500#ifdef CONFIG_PM
2501 .resume = stac92xx_resume,
2502#endif
2503};
2504
Guillaume Munch6d859062006-08-22 17:15:47 +02002505enum { /* FE and SZ series. id=0x83847661 and subsys=0x104D0700 or 104D1000. */
2506 CXD9872RD_VAIO,
2507 /* Unknown. id=0x83847662 and subsys=0x104D1200 or 104D1000. */
2508 STAC9872AK_VAIO,
2509 /* Unknown. id=0x83847661 and subsys=0x104D1200. */
2510 STAC9872K_VAIO,
2511 /* AR Series. id=0x83847664 and subsys=104D1300 */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002512 CXD9872AKD_VAIO,
2513 STAC_9872_MODELS,
2514};
Takashi Iwaidb064e52006-03-16 16:04:58 +01002515
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002516static const char *stac9872_models[STAC_9872_MODELS] = {
2517 [CXD9872RD_VAIO] = "vaio",
2518 [CXD9872AKD_VAIO] = "vaio-ar",
2519};
2520
2521static struct snd_pci_quirk stac9872_cfg_tbl[] = {
2522 SND_PCI_QUIRK(0x104d, 0x81e6, "Sony VAIO F/S", CXD9872RD_VAIO),
2523 SND_PCI_QUIRK(0x104d, 0x81ef, "Sony VAIO F/S", CXD9872RD_VAIO),
2524 SND_PCI_QUIRK(0x104d, 0x81fd, "Sony VAIO AR", CXD9872AKD_VAIO),
Tobin Davis68e22542007-03-12 11:36:39 +01002525 SND_PCI_QUIRK(0x104d, 0x8205, "Sony VAIO AR", CXD9872AKD_VAIO),
Takashi Iwaidb064e52006-03-16 16:04:58 +01002526 {}
2527};
2528
Guillaume Munch6d859062006-08-22 17:15:47 +02002529static int patch_stac9872(struct hda_codec *codec)
Takashi Iwaidb064e52006-03-16 16:04:58 +01002530{
2531 struct sigmatel_spec *spec;
2532 int board_config;
2533
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002534 board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
2535 stac9872_models,
2536 stac9872_cfg_tbl);
Takashi Iwaidb064e52006-03-16 16:04:58 +01002537 if (board_config < 0)
2538 /* unknown config, let generic-parser do its job... */
2539 return snd_hda_parse_generic_codec(codec);
2540
2541 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2542 if (spec == NULL)
2543 return -ENOMEM;
2544
2545 codec->spec = spec;
2546 switch (board_config) {
Guillaume Munch6d859062006-08-22 17:15:47 +02002547 case CXD9872RD_VAIO:
2548 case STAC9872AK_VAIO:
2549 case STAC9872K_VAIO:
Takashi Iwaidb064e52006-03-16 16:04:58 +01002550 spec->mixer = vaio_mixer;
2551 spec->init = vaio_init;
2552 spec->multiout.max_channels = 2;
2553 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
2554 spec->multiout.dac_nids = vaio_dacs;
2555 spec->multiout.hp_nid = VAIO_HP_DAC;
2556 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
2557 spec->adc_nids = vaio_adcs;
2558 spec->input_mux = &vaio_mux;
2559 spec->mux_nids = vaio_mux_nids;
2560 break;
Guillaume Munch6d859062006-08-22 17:15:47 +02002561
2562 case CXD9872AKD_VAIO:
2563 spec->mixer = vaio_ar_mixer;
2564 spec->init = vaio_ar_init;
2565 spec->multiout.max_channels = 2;
2566 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
2567 spec->multiout.dac_nids = vaio_dacs;
2568 spec->multiout.hp_nid = VAIO_HP_DAC;
2569 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
2570 spec->adc_nids = vaio_adcs;
2571 spec->input_mux = &vaio_mux;
2572 spec->mux_nids = vaio_mux_nids;
2573 break;
Takashi Iwaidb064e52006-03-16 16:04:58 +01002574 }
2575
Guillaume Munch6d859062006-08-22 17:15:47 +02002576 codec->patch_ops = stac9872_patch_ops;
Takashi Iwaidb064e52006-03-16 16:04:58 +01002577 return 0;
2578}
2579
2580
2581/*
Matt2f2f4252005-04-13 14:45:30 +02002582 * patch entries
2583 */
2584struct hda_codec_preset snd_hda_preset_sigmatel[] = {
2585 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
2586 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
2587 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
2588 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
2589 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
2590 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
2591 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
Matt Porter22a27c72006-07-06 18:49:10 +02002592 { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
2593 { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
2594 { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
2595 { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
2596 { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
2597 { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
Matt Porter3cc08dc2006-01-23 15:27:49 +01002598 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
2599 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
2600 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
2601 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
2602 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
2603 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
2604 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
2605 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
2606 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
2607 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
Tobin Davis8e21c342007-01-08 11:04:17 +01002608 { .id = 0x83847632, .name = "STAC9202", .patch = patch_stac925x },
2609 { .id = 0x83847633, .name = "STAC9202D", .patch = patch_stac925x },
2610 { .id = 0x83847634, .name = "STAC9250", .patch = patch_stac925x },
2611 { .id = 0x83847635, .name = "STAC9250D", .patch = patch_stac925x },
2612 { .id = 0x83847636, .name = "STAC9251", .patch = patch_stac925x },
2613 { .id = 0x83847637, .name = "STAC9250D", .patch = patch_stac925x },
Guillaume Munch6d859062006-08-22 17:15:47 +02002614 /* The following does not take into account .id=0x83847661 when subsys =
2615 * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
2616 * currently not fully supported.
2617 */
2618 { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
2619 { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
2620 { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
Matt Porterf3302a52006-07-31 12:49:34 +02002621 { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
2622 { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
2623 { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
2624 { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
2625 { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
2626 { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
2627 { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
2628 { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
Matt2f2f4252005-04-13 14:45:30 +02002629 {} /* terminator */
2630};