blob: fe91b9b46b615bdae4b036401601bce02f844abe [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,
Takashi Iwaidfe495d2007-08-23 19:04:28 +020042 STAC_9200_DELL_D21,
43 STAC_9200_DELL_D22,
44 STAC_9200_DELL_D23,
45 STAC_9200_DELL_M21,
46 STAC_9200_DELL_M22,
47 STAC_9200_DELL_M23,
48 STAC_9200_DELL_M24,
49 STAC_9200_DELL_M25,
50 STAC_9200_DELL_M26,
51 STAC_9200_DELL_M27,
Takashi Iwai1194b5b2007-10-10 10:04:26 +020052 STAC_9200_GATEWAY,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010053 STAC_9200_MODELS
54};
55
56enum {
57 STAC_9205_REF,
Takashi Iwaidfe495d2007-08-23 19:04:28 +020058 STAC_9205_DELL_M42,
Tobin Davisae0a8ed2007-08-13 15:50:29 +020059 STAC_9205_DELL_M43,
60 STAC_9205_DELL_M44,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010061 STAC_9205_MODELS
62};
63
64enum {
Tobin Davis8e21c342007-01-08 11:04:17 +010065 STAC_925x_REF,
66 STAC_M2_2,
67 STAC_MA6,
Tobin Davis2c11f952007-05-17 09:36:34 +020068 STAC_PA6,
Tobin Davis8e21c342007-01-08 11:04:17 +010069 STAC_925x_MODELS
70};
71
72enum {
Takashi Iwaif5fcc132006-11-24 17:07:44 +010073 STAC_D945_REF,
74 STAC_D945GTP3,
75 STAC_D945GTP5,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +020076 STAC_INTEL_MAC_V1,
77 STAC_INTEL_MAC_V2,
78 STAC_INTEL_MAC_V3,
79 STAC_INTEL_MAC_V4,
80 STAC_INTEL_MAC_V5,
Takashi Iwaidfe495d2007-08-23 19:04:28 +020081 /* for backward compatibility */
Takashi Iwaif5fcc132006-11-24 17:07:44 +010082 STAC_MACMINI,
Takashi Iwai3fc24d82007-02-16 13:27:18 +010083 STAC_MACBOOK,
Nicolas Boichat6f0778d2007-03-15 12:38:15 +010084 STAC_MACBOOK_PRO_V1,
85 STAC_MACBOOK_PRO_V2,
Sylvain FORETf16928f2007-04-27 14:22:36 +020086 STAC_IMAC_INTEL,
Takashi Iwai0dae0f82007-05-21 12:41:29 +020087 STAC_IMAC_INTEL_20,
Takashi Iwaidfe495d2007-08-23 19:04:28 +020088 STAC_922X_DELL_D81,
89 STAC_922X_DELL_D82,
90 STAC_922X_DELL_M81,
91 STAC_922X_DELL_M82,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010092 STAC_922X_MODELS
93};
94
95enum {
96 STAC_D965_REF,
97 STAC_D965_3ST,
98 STAC_D965_5ST,
Tobin Davis4ff076e2007-08-07 11:48:12 +020099 STAC_DELL_3ST,
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100100 STAC_927X_MODELS
101};
Matt Porter403d1942005-11-29 15:00:51 +0100102
Matt2f2f4252005-04-13 14:45:30 +0200103struct sigmatel_spec {
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100104 struct snd_kcontrol_new *mixers[4];
Mattc7d4b2f2005-06-27 14:59:41 +0200105 unsigned int num_mixers;
106
Matt Porter403d1942005-11-29 15:00:51 +0100107 int board_config;
Mattc7d4b2f2005-06-27 14:59:41 +0200108 unsigned int surr_switch: 1;
Matt Porter403d1942005-11-29 15:00:51 +0100109 unsigned int line_switch: 1;
110 unsigned int mic_switch: 1;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100111 unsigned int alt_switch: 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +0100112 unsigned int hp_detect: 1;
Sam Revitch62fe78e2006-05-10 15:09:17 +0200113 unsigned int gpio_mute: 1;
Mattc7d4b2f2005-06-27 14:59:41 +0200114
Takashi Iwai82599802007-07-31 15:56:24 +0200115 unsigned int gpio_mask, gpio_data;
116
Matt2f2f4252005-04-13 14:45:30 +0200117 /* playback */
118 struct hda_multi_out multiout;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100119 hda_nid_t dac_nids[5];
Matt2f2f4252005-04-13 14:45:30 +0200120
121 /* capture */
122 hda_nid_t *adc_nids;
Matt2f2f4252005-04-13 14:45:30 +0200123 unsigned int num_adcs;
Mattdabbed62005-06-14 10:19:34 +0200124 hda_nid_t *mux_nids;
125 unsigned int num_muxes;
Matt Porter8b657272006-10-26 17:12:59 +0200126 hda_nid_t *dmic_nids;
127 unsigned int num_dmics;
128 hda_nid_t dmux_nid;
Mattdabbed62005-06-14 10:19:34 +0200129 hda_nid_t dig_in_nid;
Matt2f2f4252005-04-13 14:45:30 +0200130
Matt2f2f4252005-04-13 14:45:30 +0200131 /* pin widgets */
132 hda_nid_t *pin_nids;
133 unsigned int num_pins;
Matt2f2f4252005-04-13 14:45:30 +0200134 unsigned int *pin_configs;
Richard Fish11b44bb2006-08-23 18:31:34 +0200135 unsigned int *bios_pin_configs;
Matt2f2f4252005-04-13 14:45:30 +0200136
137 /* codec specific stuff */
138 struct hda_verb *init;
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100139 struct snd_kcontrol_new *mixer;
Matt2f2f4252005-04-13 14:45:30 +0200140
141 /* capture source */
Matt Porter8b657272006-10-26 17:12:59 +0200142 struct hda_input_mux *dinput_mux;
143 unsigned int cur_dmux;
Mattc7d4b2f2005-06-27 14:59:41 +0200144 struct hda_input_mux *input_mux;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100145 unsigned int cur_mux[3];
Matt2f2f4252005-04-13 14:45:30 +0200146
Matt Porter403d1942005-11-29 15:00:51 +0100147 /* i/o switches */
148 unsigned int io_switch[2];
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +0200149 unsigned int clfe_swap;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200150 unsigned int aloopback;
Matt2f2f4252005-04-13 14:45:30 +0200151
Mattc7d4b2f2005-06-27 14:59:41 +0200152 struct hda_pcm pcm_rec[2]; /* PCM information */
153
154 /* dynamic controls and input_mux */
155 struct auto_pin_cfg autocfg;
156 unsigned int num_kctl_alloc, num_kctl_used;
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100157 struct snd_kcontrol_new *kctl_alloc;
Matt Porter8b657272006-10-26 17:12:59 +0200158 struct hda_input_mux private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +0200159 struct hda_input_mux private_imux;
Matt2f2f4252005-04-13 14:45:30 +0200160};
161
162static hda_nid_t stac9200_adc_nids[1] = {
163 0x03,
164};
165
166static hda_nid_t stac9200_mux_nids[1] = {
167 0x0c,
168};
169
170static hda_nid_t stac9200_dac_nids[1] = {
171 0x02,
172};
173
Tobin Davis8e21c342007-01-08 11:04:17 +0100174static hda_nid_t stac925x_adc_nids[1] = {
175 0x03,
176};
177
178static hda_nid_t stac925x_mux_nids[1] = {
179 0x0f,
180};
181
182static hda_nid_t stac925x_dac_nids[1] = {
183 0x02,
184};
185
Tobin Davis2c11f952007-05-17 09:36:34 +0200186static hda_nid_t stac925x_dmic_nids[1] = {
187 0x15,
188};
189
Matt2f2f4252005-04-13 14:45:30 +0200190static hda_nid_t stac922x_adc_nids[2] = {
191 0x06, 0x07,
192};
193
194static hda_nid_t stac922x_mux_nids[2] = {
195 0x12, 0x13,
196};
197
Matt Porter3cc08dc2006-01-23 15:27:49 +0100198static hda_nid_t stac927x_adc_nids[3] = {
199 0x07, 0x08, 0x09
200};
201
202static hda_nid_t stac927x_mux_nids[3] = {
203 0x15, 0x16, 0x17
204};
205
Matt Porterf3302a52006-07-31 12:49:34 +0200206static hda_nid_t stac9205_adc_nids[2] = {
207 0x12, 0x13
208};
209
210static hda_nid_t stac9205_mux_nids[2] = {
211 0x19, 0x1a
212};
213
Takashi Iwai25494132007-03-12 12:36:16 +0100214static hda_nid_t stac9205_dmic_nids[2] = {
215 0x17, 0x18,
Matt Porter8b657272006-10-26 17:12:59 +0200216};
217
Mattc7d4b2f2005-06-27 14:59:41 +0200218static hda_nid_t stac9200_pin_nids[8] = {
Tobin Davis93ed1502006-09-01 21:03:12 +0200219 0x08, 0x09, 0x0d, 0x0e,
220 0x0f, 0x10, 0x11, 0x12,
Matt2f2f4252005-04-13 14:45:30 +0200221};
222
Tobin Davis8e21c342007-01-08 11:04:17 +0100223static hda_nid_t stac925x_pin_nids[8] = {
224 0x07, 0x08, 0x0a, 0x0b,
225 0x0c, 0x0d, 0x10, 0x11,
226};
227
Matt2f2f4252005-04-13 14:45:30 +0200228static hda_nid_t stac922x_pin_nids[10] = {
229 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
230 0x0f, 0x10, 0x11, 0x15, 0x1b,
231};
232
Matt Porter3cc08dc2006-01-23 15:27:49 +0100233static hda_nid_t stac927x_pin_nids[14] = {
234 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
235 0x0f, 0x10, 0x11, 0x12, 0x13,
236 0x14, 0x21, 0x22, 0x23,
237};
238
Matt Porterf3302a52006-07-31 12:49:34 +0200239static hda_nid_t stac9205_pin_nids[12] = {
240 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
241 0x0f, 0x14, 0x16, 0x17, 0x18,
242 0x21, 0x22,
Matt Porterf3302a52006-07-31 12:49:34 +0200243};
244
Matt Porter8b657272006-10-26 17:12:59 +0200245static int stac92xx_dmux_enum_info(struct snd_kcontrol *kcontrol,
246 struct snd_ctl_elem_info *uinfo)
247{
248 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
249 struct sigmatel_spec *spec = codec->spec;
250 return snd_hda_input_mux_info(spec->dinput_mux, uinfo);
251}
252
253static int stac92xx_dmux_enum_get(struct snd_kcontrol *kcontrol,
254 struct snd_ctl_elem_value *ucontrol)
255{
256 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
257 struct sigmatel_spec *spec = codec->spec;
258
259 ucontrol->value.enumerated.item[0] = spec->cur_dmux;
260 return 0;
261}
262
263static int stac92xx_dmux_enum_put(struct snd_kcontrol *kcontrol,
264 struct snd_ctl_elem_value *ucontrol)
265{
266 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
267 struct sigmatel_spec *spec = codec->spec;
268
269 return snd_hda_input_mux_put(codec, spec->dinput_mux, ucontrol,
270 spec->dmux_nid, &spec->cur_dmux);
271}
272
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100273static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Matt2f2f4252005-04-13 14:45:30 +0200274{
275 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
276 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +0200277 return snd_hda_input_mux_info(spec->input_mux, uinfo);
Matt2f2f4252005-04-13 14:45:30 +0200278}
279
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100280static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200281{
282 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
283 struct sigmatel_spec *spec = codec->spec;
284 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
285
286 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
287 return 0;
288}
289
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100290static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200291{
292 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
293 struct sigmatel_spec *spec = codec->spec;
294 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
295
Mattc7d4b2f2005-06-27 14:59:41 +0200296 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
Matt2f2f4252005-04-13 14:45:30 +0200297 spec->mux_nids[adc_idx], &spec->cur_mux[adc_idx]);
298}
299
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200300#define stac92xx_aloopback_info snd_ctl_boolean_mono_info
301
302static int stac92xx_aloopback_get(struct snd_kcontrol *kcontrol,
303 struct snd_ctl_elem_value *ucontrol)
304{
305 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
306 struct sigmatel_spec *spec = codec->spec;
307
308 ucontrol->value.integer.value[0] = spec->aloopback;
309 return 0;
310}
311
312static int stac92xx_aloopback_put(struct snd_kcontrol *kcontrol,
313 struct snd_ctl_elem_value *ucontrol)
314{
315 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
316 struct sigmatel_spec *spec = codec->spec;
317 unsigned int dac_mode;
318
319 if (spec->aloopback == ucontrol->value.integer.value[0])
320 return 0;
321
322 spec->aloopback = ucontrol->value.integer.value[0];
323
324
325 dac_mode = snd_hda_codec_read(codec, codec->afg, 0,
326 kcontrol->private_value & 0xFFFF, 0x0);
327
328 if (spec->aloopback) {
329 snd_hda_power_up(codec);
330 dac_mode |= 0x40;
331 } else {
332 snd_hda_power_down(codec);
333 dac_mode &= ~0x40;
334 }
335
336 snd_hda_codec_write_cache(codec, codec->afg, 0,
337 kcontrol->private_value >> 16, dac_mode);
338
339 return 1;
340}
341
Maxim Levitsky6e6b88f2007-09-03 15:30:26 +0200342static int stac92xx_volknob_info(struct snd_kcontrol *kcontrol,
343 struct snd_ctl_elem_info *uinfo)
344{
345 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
346 uinfo->count = 1;
347 uinfo->value.integer.min = 0;
348 uinfo->value.integer.max = 127;
349 return 0;
350}
351
352static int stac92xx_volknob_get(struct snd_kcontrol *kcontrol,
353 struct snd_ctl_elem_value *ucontrol)
354{
355 ucontrol->value.integer.value[0] = kcontrol->private_value;
356 return 0;
357}
358
359static int stac92xx_volknob_put(struct snd_kcontrol *kcontrol,
360 struct snd_ctl_elem_value *ucontrol)
361{
362 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
363
364 if (kcontrol->private_value == ucontrol->value.integer.value[0])
365 return 0;
366
367 kcontrol->private_value = ucontrol->value.integer.value[0];
368
369 snd_hda_codec_write_cache(codec, 0x24, 0,
370 AC_VERB_SET_VOLUME_KNOB_CONTROL,
371 kcontrol->private_value | 0x80);
372 return 1;
373}
374
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200375
Mattc7d4b2f2005-06-27 14:59:41 +0200376static struct hda_verb stac9200_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200377 /* set dac0mux for dac converter */
Mattc7d4b2f2005-06-27 14:59:41 +0200378 { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
Matt2f2f4252005-04-13 14:45:30 +0200379 {}
380};
381
Takashi Iwai1194b5b2007-10-10 10:04:26 +0200382static struct hda_verb stac9200_eapd_init[] = {
383 /* set dac0mux for dac converter */
384 {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
385 {0x08, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
386 {}
387};
388
Tobin Davis8e21c342007-01-08 11:04:17 +0100389static struct hda_verb stac925x_core_init[] = {
390 /* set dac0mux for dac converter */
391 { 0x06, AC_VERB_SET_CONNECT_SEL, 0x00},
392 {}
393};
394
Mattc7d4b2f2005-06-27 14:59:41 +0200395static struct hda_verb stac922x_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200396 /* set master volume and direct control */
Mattc7d4b2f2005-06-27 14:59:41 +0200397 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matt2f2f4252005-04-13 14:45:30 +0200398 {}
399};
400
Tobin Davis93ed1502006-09-01 21:03:12 +0200401static struct hda_verb d965_core_init[] = {
Takashi Iwai19039bd2006-06-28 15:52:16 +0200402 /* set master volume and direct control */
Tobin Davis93ed1502006-09-01 21:03:12 +0200403 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Takashi Iwai19039bd2006-06-28 15:52:16 +0200404 /* unmute node 0x1b */
405 { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
406 /* select node 0x03 as DAC */
407 { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
408 {}
409};
410
Matt Porter3cc08dc2006-01-23 15:27:49 +0100411static struct hda_verb stac927x_core_init[] = {
412 /* set master volume and direct control */
413 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
414 {}
415};
416
Matt Porterf3302a52006-07-31 12:49:34 +0200417static struct hda_verb stac9205_core_init[] = {
418 /* set master volume and direct control */
419 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
420 {}
421};
422
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200423#define STAC_INPUT_SOURCE(cnt) \
Maxim Levitskyca7c5a82007-08-31 12:52:19 +0200424 { \
425 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
426 .name = "Input Source", \
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200427 .count = cnt, \
Maxim Levitskyca7c5a82007-08-31 12:52:19 +0200428 .info = stac92xx_mux_enum_info, \
429 .get = stac92xx_mux_enum_get, \
430 .put = stac92xx_mux_enum_put, \
431 }
432
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200433#define STAC_ANALOG_LOOPBACK(verb_read,verb_write) \
434 { \
435 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
436 .name = "Analog Loopback", \
437 .count = 1, \
438 .info = stac92xx_aloopback_info, \
439 .get = stac92xx_aloopback_get, \
440 .put = stac92xx_aloopback_put, \
441 .private_value = verb_read | (verb_write << 16), \
442 }
443
Maxim Levitsky6e6b88f2007-09-03 15:30:26 +0200444#define STAC_VOLKNOB \
445 { \
446 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
447 .name = "Master Playback Volume", \
448 .count = 1, \
449 .info = stac92xx_volknob_info, \
450 .get = stac92xx_volknob_get, \
451 .put = stac92xx_volknob_put, \
452 .private_value = 127, \
453 }
454
Maxim Levitskyca7c5a82007-08-31 12:52:19 +0200455
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100456static struct snd_kcontrol_new stac9200_mixer[] = {
Matt2f2f4252005-04-13 14:45:30 +0200457 HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
458 HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200459 STAC_INPUT_SOURCE(1),
Matt2f2f4252005-04-13 14:45:30 +0200460 HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
461 HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
Mattc7d4b2f2005-06-27 14:59:41 +0200462 HDA_CODEC_VOLUME("Capture Mux Volume", 0x0c, 0, HDA_OUTPUT),
Matt2f2f4252005-04-13 14:45:30 +0200463 { } /* end */
464};
465
Tobin Davis8e21c342007-01-08 11:04:17 +0100466static struct snd_kcontrol_new stac925x_mixer[] = {
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200467 STAC_INPUT_SOURCE(1),
Tobin Davis8e21c342007-01-08 11:04:17 +0100468 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_OUTPUT),
469 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_OUTPUT),
470 HDA_CODEC_VOLUME("Capture Mux Volume", 0x0f, 0, HDA_OUTPUT),
471 { } /* end */
472};
473
Takashi Iwaid1d985f2006-11-23 19:27:12 +0100474static struct snd_kcontrol_new stac9205_mixer[] = {
Matt Porterf3302a52006-07-31 12:49:34 +0200475 {
476 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Matt Porter8b657272006-10-26 17:12:59 +0200477 .name = "Digital Input Source",
478 .count = 1,
479 .info = stac92xx_dmux_enum_info,
480 .get = stac92xx_dmux_enum_get,
481 .put = stac92xx_dmux_enum_put,
482 },
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200483 STAC_INPUT_SOURCE(2),
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200484 STAC_ANALOG_LOOPBACK(0xFE0, 0x7E0),
Maxim Levitsky6e6b88f2007-09-03 15:30:26 +0200485 STAC_VOLKNOB,
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200486
487 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1b, 0x0, HDA_INPUT),
488 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1d, 0x0, HDA_OUTPUT),
489 HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x0, 0x19, 0x0, HDA_OUTPUT),
490
491 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x1c, 0x0, HDA_INPUT),
492 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1e, 0x0, HDA_OUTPUT),
493 HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x1, 0x1A, 0x0, HDA_OUTPUT),
494
495 { } /* end */
496};
497
498/* This needs to be generated dynamically based on sequence */
499static struct snd_kcontrol_new stac922x_mixer[] = {
500 STAC_INPUT_SOURCE(2),
501 STAC_VOLKNOB,
502 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x17, 0x0, HDA_INPUT),
503 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x17, 0x0, HDA_INPUT),
504 HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x0, 0x12, 0x0, HDA_OUTPUT),
505
506 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x18, 0x0, HDA_INPUT),
507 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x18, 0x0, HDA_INPUT),
508 HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x1, 0x13, 0x0, HDA_OUTPUT),
509 { } /* end */
510};
511
512
513static struct snd_kcontrol_new stac927x_mixer[] = {
514 STAC_INPUT_SOURCE(3),
515 STAC_VOLKNOB,
516 STAC_ANALOG_LOOPBACK(0xFEB, 0x7EB),
517
518 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x18, 0x0, HDA_INPUT),
519 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1b, 0x0, HDA_OUTPUT),
520 HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x0, 0x15, 0x0, HDA_OUTPUT),
521
522 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x19, 0x0, HDA_INPUT),
523 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1c, 0x0, HDA_OUTPUT),
524 HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x1, 0x16, 0x0, HDA_OUTPUT),
525
526 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x2, 0x1A, 0x0, HDA_INPUT),
527 HDA_CODEC_MUTE_IDX("Capture Switch", 0x2, 0x1d, 0x0, HDA_OUTPUT),
528 HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x2, 0x17, 0x0, HDA_OUTPUT),
Matt Porterf3302a52006-07-31 12:49:34 +0200529 { } /* end */
530};
531
Matt2f2f4252005-04-13 14:45:30 +0200532static int stac92xx_build_controls(struct hda_codec *codec)
533{
534 struct sigmatel_spec *spec = codec->spec;
535 int err;
Mattc7d4b2f2005-06-27 14:59:41 +0200536 int i;
Matt2f2f4252005-04-13 14:45:30 +0200537
538 err = snd_hda_add_new_ctls(codec, spec->mixer);
539 if (err < 0)
540 return err;
Mattc7d4b2f2005-06-27 14:59:41 +0200541
542 for (i = 0; i < spec->num_mixers; i++) {
543 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
544 if (err < 0)
545 return err;
546 }
547
Mattdabbed62005-06-14 10:19:34 +0200548 if (spec->multiout.dig_out_nid) {
549 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
550 if (err < 0)
551 return err;
552 }
553 if (spec->dig_in_nid) {
554 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
555 if (err < 0)
556 return err;
557 }
558 return 0;
Matt2f2f4252005-04-13 14:45:30 +0200559}
560
Matt Porter403d1942005-11-29 15:00:51 +0100561static unsigned int ref9200_pin_configs[8] = {
Mattdabbed62005-06-14 10:19:34 +0200562 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
Matt2f2f4252005-04-13 14:45:30 +0200563 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
564};
565
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200566/*
567 STAC 9200 pin configs for
568 102801A8
569 102801DE
570 102801E8
571*/
572static unsigned int dell9200_d21_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +0200573 0x400001f0, 0x400001f1, 0x02214030, 0x01014010,
574 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200575};
576
577/*
578 STAC 9200 pin configs for
579 102801C0
580 102801C1
581*/
582static unsigned int dell9200_d22_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +0200583 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
584 0x01813020, 0x02a19021, 0x90100140, 0x400001f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200585};
586
587/*
588 STAC 9200 pin configs for
589 102801C4 (Dell Dimension E310)
590 102801C5
591 102801C7
592 102801D9
593 102801DA
594 102801E3
595*/
596static unsigned int dell9200_d23_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +0200597 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
598 0x01813020, 0x01a19021, 0x90100140, 0x400001f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200599};
600
601
602/*
603 STAC 9200-32 pin configs for
604 102801B5 (Dell Inspiron 630m)
605 102801D8 (Dell Inspiron 640m)
606*/
607static unsigned int dell9200_m21_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +0200608 0x40c003fa, 0x03441340, 0x0321121f, 0x90170310,
609 0x408003fb, 0x03a11020, 0x401003fc, 0x403003fd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200610};
611
612/*
613 STAC 9200-32 pin configs for
614 102801C2 (Dell Latitude D620)
615 102801C8
616 102801CC (Dell Latitude D820)
617 102801D4
618 102801D6
619*/
620static unsigned int dell9200_m22_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +0200621 0x40c003fa, 0x0144131f, 0x0321121f, 0x90170310,
622 0x90a70321, 0x03a11020, 0x401003fb, 0x40f000fc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200623};
624
625/*
626 STAC 9200-32 pin configs for
627 102801CE (Dell XPS M1710)
628 102801CF (Dell Precision M90)
629*/
630static unsigned int dell9200_m23_pin_configs[8] = {
631 0x40c003fa, 0x01441340, 0x0421421f, 0x90170310,
632 0x408003fb, 0x04a1102e, 0x90170311, 0x403003fc,
633};
634
635/*
636 STAC 9200-32 pin configs for
637 102801C9
638 102801CA
639 102801CB (Dell Latitude 120L)
640 102801D3
641*/
642static unsigned int dell9200_m24_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +0200643 0x40c003fa, 0x404003fb, 0x0321121f, 0x90170310,
644 0x408003fc, 0x03a11020, 0x401003fd, 0x403003fe,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200645};
646
647/*
648 STAC 9200-32 pin configs for
649 102801BD (Dell Inspiron E1505n)
650 102801EE
651 102801EF
652*/
653static unsigned int dell9200_m25_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +0200654 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
655 0x408003fb, 0x04a11020, 0x401003fc, 0x403003fd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200656};
657
658/*
659 STAC 9200-32 pin configs for
660 102801F5 (Dell Inspiron 1501)
661 102801F6
662*/
663static unsigned int dell9200_m26_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +0200664 0x40c003fa, 0x404003fb, 0x0421121f, 0x90170310,
665 0x408003fc, 0x04a11020, 0x401003fd, 0x403003fe,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200666};
667
668/*
669 STAC 9200-32
670 102801CD (Dell Inspiron E1705/9400)
671*/
672static unsigned int dell9200_m27_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +0200673 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
674 0x90170310, 0x04a11020, 0x90170310, 0x40f003fc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200675};
676
677
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100678static unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
679 [STAC_REF] = ref9200_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200680 [STAC_9200_DELL_D21] = dell9200_d21_pin_configs,
681 [STAC_9200_DELL_D22] = dell9200_d22_pin_configs,
682 [STAC_9200_DELL_D23] = dell9200_d23_pin_configs,
683 [STAC_9200_DELL_M21] = dell9200_m21_pin_configs,
684 [STAC_9200_DELL_M22] = dell9200_m22_pin_configs,
685 [STAC_9200_DELL_M23] = dell9200_m23_pin_configs,
686 [STAC_9200_DELL_M24] = dell9200_m24_pin_configs,
687 [STAC_9200_DELL_M25] = dell9200_m25_pin_configs,
688 [STAC_9200_DELL_M26] = dell9200_m26_pin_configs,
689 [STAC_9200_DELL_M27] = dell9200_m27_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +0100690};
691
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100692static const char *stac9200_models[STAC_9200_MODELS] = {
693 [STAC_REF] = "ref",
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200694 [STAC_9200_DELL_D21] = "dell-d21",
695 [STAC_9200_DELL_D22] = "dell-d22",
696 [STAC_9200_DELL_D23] = "dell-d23",
697 [STAC_9200_DELL_M21] = "dell-m21",
698 [STAC_9200_DELL_M22] = "dell-m22",
699 [STAC_9200_DELL_M23] = "dell-m23",
700 [STAC_9200_DELL_M24] = "dell-m24",
701 [STAC_9200_DELL_M25] = "dell-m25",
702 [STAC_9200_DELL_M26] = "dell-m26",
703 [STAC_9200_DELL_M27] = "dell-m27",
Takashi Iwai1194b5b2007-10-10 10:04:26 +0200704 [STAC_9200_GATEWAY] = "gateway",
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100705};
706
707static struct snd_pci_quirk stac9200_cfg_tbl[] = {
708 /* SigmaTel reference board */
709 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
710 "DFI LanParty", STAC_REF),
Matt Portere7377072006-11-06 11:20:38 +0100711 /* Dell laptops have BIOS problem */
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200712 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a8,
713 "unknown Dell", STAC_9200_DELL_D21),
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100714 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01b5,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200715 "Dell Inspiron 630m", STAC_9200_DELL_M21),
716 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bd,
717 "Dell Inspiron E1505n", STAC_9200_DELL_M25),
718 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c0,
719 "unknown Dell", STAC_9200_DELL_D22),
720 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c1,
721 "unknown Dell", STAC_9200_DELL_D22),
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100722 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200723 "Dell Latitude D620", STAC_9200_DELL_M22),
724 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c5,
725 "unknown Dell", STAC_9200_DELL_D23),
726 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c7,
727 "unknown Dell", STAC_9200_DELL_D23),
728 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c8,
729 "unknown Dell", STAC_9200_DELL_M22),
730 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c9,
731 "unknown Dell", STAC_9200_DELL_M24),
732 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ca,
733 "unknown Dell", STAC_9200_DELL_M24),
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100734 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cb,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200735 "Dell Latitude 120L", STAC_9200_DELL_M24),
Cory T. Tusar877b8662007-01-30 17:30:55 +0100736 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200737 "Dell Latitude D820", STAC_9200_DELL_M22),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +0100738 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200739 "Dell Inspiron E1705/9400", STAC_9200_DELL_M27),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +0100740 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ce,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200741 "Dell XPS M1710", STAC_9200_DELL_M23),
Takashi Iwaif0f96742007-02-14 00:59:17 +0100742 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cf,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200743 "Dell Precision M90", STAC_9200_DELL_M23),
744 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d3,
745 "unknown Dell", STAC_9200_DELL_M22),
746 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d4,
747 "unknown Dell", STAC_9200_DELL_M22),
Daniel T Chen8286c532007-05-15 11:46:23 +0200748 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d6,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200749 "unknown Dell", STAC_9200_DELL_M22),
Tobin Davis49c605d2007-05-17 09:38:24 +0200750 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d8,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200751 "Dell Inspiron 640m", STAC_9200_DELL_M21),
752 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d9,
753 "unknown Dell", STAC_9200_DELL_D23),
754 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01da,
755 "unknown Dell", STAC_9200_DELL_D23),
756 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01de,
757 "unknown Dell", STAC_9200_DELL_D21),
758 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e3,
759 "unknown Dell", STAC_9200_DELL_D23),
760 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e8,
761 "unknown Dell", STAC_9200_DELL_D21),
762 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ee,
763 "unknown Dell", STAC_9200_DELL_M25),
764 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ef,
765 "unknown Dell", STAC_9200_DELL_M25),
Tobin Davis49c605d2007-05-17 09:38:24 +0200766 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f5,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200767 "Dell Inspiron 1501", STAC_9200_DELL_M26),
768 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f6,
769 "unknown Dell", STAC_9200_DELL_M26),
Tobin Davis49c605d2007-05-17 09:38:24 +0200770 /* Panasonic */
771 SND_PCI_QUIRK(0x10f7, 0x8338, "Panasonic CF-74", STAC_REF),
Takashi Iwai1194b5b2007-10-10 10:04:26 +0200772 /* Gateway machines needs EAPD to be set on resume */
773 SND_PCI_QUIRK(0x107b, 0x0205, "Gateway S-7110M", STAC_9200_GATEWAY),
774 SND_PCI_QUIRK(0x107b, 0x0317, "Gateway MT3423, MX341*",
775 STAC_9200_GATEWAY),
776 SND_PCI_QUIRK(0x107b, 0x0318, "Gateway ML3019, MT3707",
777 STAC_9200_GATEWAY),
Matt Porter403d1942005-11-29 15:00:51 +0100778 {} /* terminator */
779};
780
Tobin Davis8e21c342007-01-08 11:04:17 +0100781static unsigned int ref925x_pin_configs[8] = {
782 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
783 0x90a70320, 0x02214210, 0x400003f1, 0x9033032e,
784};
785
786static unsigned int stac925x_MA6_pin_configs[8] = {
787 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
788 0x90a70320, 0x90100211, 0x400003f1, 0x9033032e,
789};
790
Tobin Davis2c11f952007-05-17 09:36:34 +0200791static unsigned int stac925x_PA6_pin_configs[8] = {
792 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
793 0x50a103f0, 0x90100211, 0x400003f1, 0x9033032e,
794};
795
Tobin Davis8e21c342007-01-08 11:04:17 +0100796static unsigned int stac925xM2_2_pin_configs[8] = {
Steve Longerbeam7353e142007-05-29 14:36:17 +0200797 0x40c003f3, 0x424503f2, 0x04180011, 0x02a19020,
798 0x50a103f0, 0x90100212, 0x400003f1, 0x9033032e,
Tobin Davis8e21c342007-01-08 11:04:17 +0100799};
800
801static unsigned int *stac925x_brd_tbl[STAC_925x_MODELS] = {
802 [STAC_REF] = ref925x_pin_configs,
803 [STAC_M2_2] = stac925xM2_2_pin_configs,
804 [STAC_MA6] = stac925x_MA6_pin_configs,
Tobin Davis2c11f952007-05-17 09:36:34 +0200805 [STAC_PA6] = stac925x_PA6_pin_configs,
Tobin Davis8e21c342007-01-08 11:04:17 +0100806};
807
808static const char *stac925x_models[STAC_925x_MODELS] = {
809 [STAC_REF] = "ref",
810 [STAC_M2_2] = "m2-2",
811 [STAC_MA6] = "m6",
Tobin Davis2c11f952007-05-17 09:36:34 +0200812 [STAC_PA6] = "pa6",
Tobin Davis8e21c342007-01-08 11:04:17 +0100813};
814
815static struct snd_pci_quirk stac925x_cfg_tbl[] = {
816 /* SigmaTel reference board */
817 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, "DFI LanParty", STAC_REF),
Tobin Davis2c11f952007-05-17 09:36:34 +0200818 SND_PCI_QUIRK(0x8384, 0x7632, "Stac9202 Reference Board", STAC_REF),
Tobin Davis8e21c342007-01-08 11:04:17 +0100819 SND_PCI_QUIRK(0x107b, 0x0316, "Gateway M255", STAC_REF),
820 SND_PCI_QUIRK(0x107b, 0x0366, "Gateway MP6954", STAC_REF),
821 SND_PCI_QUIRK(0x107b, 0x0461, "Gateway NX560XL", STAC_MA6),
Tobin Davis2c11f952007-05-17 09:36:34 +0200822 SND_PCI_QUIRK(0x107b, 0x0681, "Gateway NX860", STAC_PA6),
Tobin Davis8e21c342007-01-08 11:04:17 +0100823 SND_PCI_QUIRK(0x1002, 0x437b, "Gateway MX6453", STAC_M2_2),
824 {} /* terminator */
825};
826
Matt Porter403d1942005-11-29 15:00:51 +0100827static unsigned int ref922x_pin_configs[10] = {
828 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
829 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
Matt2f2f4252005-04-13 14:45:30 +0200830 0x40000100, 0x40000100,
831};
832
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200833/*
834 STAC 922X pin configs for
835 102801A7
836 102801AB
837 102801A9
838 102801D1
839 102801D2
840*/
841static unsigned int dell_922x_d81_pin_configs[10] = {
842 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
843 0x02a19020, 0x01117011, 0x400001f0, 0x400001f1,
844 0x01813122, 0x400001f2,
845};
846
847/*
848 STAC 922X pin configs for
849 102801AC
850 102801D0
851*/
852static unsigned int dell_922x_d82_pin_configs[10] = {
853 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
854 0x02a19020, 0x01117011, 0x01451140, 0x400001f0,
855 0x01813122, 0x400001f1,
856};
857
858/*
859 STAC 922X pin configs for
860 102801BF
861*/
862static unsigned int dell_922x_m81_pin_configs[10] = {
863 0x0321101f, 0x01112024, 0x01111222, 0x91174220,
864 0x03a11050, 0x01116221, 0x90a70330, 0x01452340,
865 0x40C003f1, 0x405003f0,
866};
867
868/*
869 STAC 9221 A1 pin configs for
870 102801D7 (Dell XPS M1210)
871*/
872static unsigned int dell_922x_m82_pin_configs[10] = {
873 0x0221121f, 0x408103ff, 0x02111212, 0x90100310,
874 0x408003f1, 0x02111211, 0x03451340, 0x40c003f2,
875 0x508003f3, 0x405003f4,
876};
877
Matt Porter403d1942005-11-29 15:00:51 +0100878static unsigned int d945gtp3_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +0100879 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
Matt Porter403d1942005-11-29 15:00:51 +0100880 0x40000100, 0x40000100, 0x40000100, 0x40000100,
881 0x02a19120, 0x40000100,
882};
883
884static unsigned int d945gtp5_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +0100885 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
886 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
Matt Porter403d1942005-11-29 15:00:51 +0100887 0x02a19320, 0x40000100,
888};
889
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +0200890static unsigned int intel_mac_v1_pin_configs[10] = {
891 0x0121e21f, 0x400000ff, 0x9017e110, 0x400000fd,
892 0x400000fe, 0x0181e020, 0x1145e030, 0x11c5e240,
Takashi Iwai3fc24d82007-02-16 13:27:18 +0100893 0x400000fc, 0x400000fb,
894};
895
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +0200896static unsigned int intel_mac_v2_pin_configs[10] = {
897 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
898 0x400000fe, 0x0181e020, 0x1145e230, 0x500000fa,
Sylvain FORETf16928f2007-04-27 14:22:36 +0200899 0x400000fc, 0x400000fb,
900};
901
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +0200902static unsigned int intel_mac_v3_pin_configs[10] = {
903 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
904 0x400000fe, 0x0181e020, 0x1145e230, 0x11c5e240,
905 0x400000fc, 0x400000fb,
906};
907
908static unsigned int intel_mac_v4_pin_configs[10] = {
909 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
910 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
911 0x400000fc, 0x400000fb,
912};
913
914static unsigned int intel_mac_v5_pin_configs[10] = {
915 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
916 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
917 0x400000fc, 0x400000fb,
Takashi Iwai0dae0f82007-05-21 12:41:29 +0200918};
919
Takashi Iwai76c08822007-06-19 12:17:42 +0200920
Takashi Iwai19039bd2006-06-28 15:52:16 +0200921static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100922 [STAC_D945_REF] = ref922x_pin_configs,
Takashi Iwai19039bd2006-06-28 15:52:16 +0200923 [STAC_D945GTP3] = d945gtp3_pin_configs,
924 [STAC_D945GTP5] = d945gtp5_pin_configs,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +0200925 [STAC_INTEL_MAC_V1] = intel_mac_v1_pin_configs,
926 [STAC_INTEL_MAC_V2] = intel_mac_v2_pin_configs,
927 [STAC_INTEL_MAC_V3] = intel_mac_v3_pin_configs,
928 [STAC_INTEL_MAC_V4] = intel_mac_v4_pin_configs,
929 [STAC_INTEL_MAC_V5] = intel_mac_v5_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200930 /* for backward compatibility */
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +0200931 [STAC_MACMINI] = intel_mac_v3_pin_configs,
932 [STAC_MACBOOK] = intel_mac_v5_pin_configs,
933 [STAC_MACBOOK_PRO_V1] = intel_mac_v3_pin_configs,
934 [STAC_MACBOOK_PRO_V2] = intel_mac_v3_pin_configs,
935 [STAC_IMAC_INTEL] = intel_mac_v2_pin_configs,
936 [STAC_IMAC_INTEL_20] = intel_mac_v3_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200937 [STAC_922X_DELL_D81] = dell_922x_d81_pin_configs,
938 [STAC_922X_DELL_D82] = dell_922x_d82_pin_configs,
939 [STAC_922X_DELL_M81] = dell_922x_m81_pin_configs,
940 [STAC_922X_DELL_M82] = dell_922x_m82_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +0100941};
942
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100943static const char *stac922x_models[STAC_922X_MODELS] = {
944 [STAC_D945_REF] = "ref",
945 [STAC_D945GTP5] = "5stack",
946 [STAC_D945GTP3] = "3stack",
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +0200947 [STAC_INTEL_MAC_V1] = "intel-mac-v1",
948 [STAC_INTEL_MAC_V2] = "intel-mac-v2",
949 [STAC_INTEL_MAC_V3] = "intel-mac-v3",
950 [STAC_INTEL_MAC_V4] = "intel-mac-v4",
951 [STAC_INTEL_MAC_V5] = "intel-mac-v5",
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200952 /* for backward compatibility */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100953 [STAC_MACMINI] = "macmini",
Takashi Iwai3fc24d82007-02-16 13:27:18 +0100954 [STAC_MACBOOK] = "macbook",
Nicolas Boichat6f0778d2007-03-15 12:38:15 +0100955 [STAC_MACBOOK_PRO_V1] = "macbook-pro-v1",
956 [STAC_MACBOOK_PRO_V2] = "macbook-pro",
Sylvain FORETf16928f2007-04-27 14:22:36 +0200957 [STAC_IMAC_INTEL] = "imac-intel",
Takashi Iwai0dae0f82007-05-21 12:41:29 +0200958 [STAC_IMAC_INTEL_20] = "imac-intel-20",
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200959 [STAC_922X_DELL_D81] = "dell-d81",
960 [STAC_922X_DELL_D82] = "dell-d82",
961 [STAC_922X_DELL_M81] = "dell-m81",
962 [STAC_922X_DELL_M82] = "dell-m82",
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100963};
964
965static struct snd_pci_quirk stac922x_cfg_tbl[] = {
966 /* SigmaTel reference board */
967 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
968 "DFI LanParty", STAC_D945_REF),
969 /* Intel 945G based systems */
970 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101,
971 "Intel D945G", STAC_D945GTP3),
972 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0202,
973 "Intel D945G", STAC_D945GTP3),
974 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0606,
975 "Intel D945G", STAC_D945GTP3),
976 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0601,
977 "Intel D945G", STAC_D945GTP3),
978 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0111,
979 "Intel D945G", STAC_D945GTP3),
980 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1115,
981 "Intel D945G", STAC_D945GTP3),
982 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1116,
983 "Intel D945G", STAC_D945GTP3),
984 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1117,
985 "Intel D945G", STAC_D945GTP3),
986 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1118,
987 "Intel D945G", STAC_D945GTP3),
988 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1119,
989 "Intel D945G", STAC_D945GTP3),
990 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x8826,
991 "Intel D945G", STAC_D945GTP3),
992 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5049,
993 "Intel D945G", STAC_D945GTP3),
994 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5055,
995 "Intel D945G", STAC_D945GTP3),
996 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5048,
997 "Intel D945G", STAC_D945GTP3),
998 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0110,
999 "Intel D945G", STAC_D945GTP3),
1000 /* Intel D945G 5-stack systems */
1001 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0404,
1002 "Intel D945G", STAC_D945GTP5),
1003 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0303,
1004 "Intel D945G", STAC_D945GTP5),
1005 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0013,
1006 "Intel D945G", STAC_D945GTP5),
1007 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0417,
1008 "Intel D945G", STAC_D945GTP5),
1009 /* Intel 945P based systems */
1010 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0b0b,
1011 "Intel D945P", STAC_D945GTP3),
1012 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0112,
1013 "Intel D945P", STAC_D945GTP3),
1014 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0d0d,
1015 "Intel D945P", STAC_D945GTP3),
1016 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0909,
1017 "Intel D945P", STAC_D945GTP3),
1018 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0505,
1019 "Intel D945P", STAC_D945GTP3),
1020 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707,
1021 "Intel D945P", STAC_D945GTP5),
1022 /* other systems */
1023 /* Apple Mac Mini (early 2006) */
1024 SND_PCI_QUIRK(0x8384, 0x7680,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001025 "Mac Mini", STAC_INTEL_MAC_V3),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001026 /* Dell systems */
1027 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a7,
1028 "unknown Dell", STAC_922X_DELL_D81),
1029 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a9,
1030 "unknown Dell", STAC_922X_DELL_D81),
1031 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ab,
1032 "unknown Dell", STAC_922X_DELL_D81),
1033 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ac,
1034 "unknown Dell", STAC_922X_DELL_D82),
1035 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bf,
1036 "unknown Dell", STAC_922X_DELL_M81),
1037 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d0,
1038 "unknown Dell", STAC_922X_DELL_D82),
1039 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d1,
1040 "unknown Dell", STAC_922X_DELL_D81),
1041 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d2,
1042 "unknown Dell", STAC_922X_DELL_D81),
1043 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d7,
1044 "Dell XPS M1210", STAC_922X_DELL_M82),
Matt Porter403d1942005-11-29 15:00:51 +01001045 {} /* terminator */
1046};
1047
Matt Porter3cc08dc2006-01-23 15:27:49 +01001048static unsigned int ref927x_pin_configs[14] = {
Tobin Davis93ed1502006-09-01 21:03:12 +02001049 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
1050 0x01a19040, 0x01011012, 0x01016011, 0x0101201f,
1051 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
1052 0x01c42190, 0x40000100,
Matt Porter3cc08dc2006-01-23 15:27:49 +01001053};
1054
Tobin Davis93ed1502006-09-01 21:03:12 +02001055static unsigned int d965_3st_pin_configs[14] = {
Tobin Davis81d3dbd2006-08-22 19:44:45 +02001056 0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
1057 0x01a19021, 0x01813024, 0x40000100, 0x40000100,
1058 0x40000100, 0x40000100, 0x40000100, 0x40000100,
1059 0x40000100, 0x40000100
1060};
1061
Tobin Davis93ed1502006-09-01 21:03:12 +02001062static unsigned int d965_5st_pin_configs[14] = {
1063 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
1064 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
1065 0x40000100, 0x40000100, 0x40000100, 0x01442070,
1066 0x40000100, 0x40000100
1067};
1068
Tobin Davis4ff076e2007-08-07 11:48:12 +02001069static unsigned int dell_3st_pin_configs[14] = {
1070 0x02211230, 0x02a11220, 0x01a19040, 0x01114210,
1071 0x01111212, 0x01116211, 0x01813050, 0x01112214,
1072 0x403003fa, 0x40000100, 0x40000100, 0x404003fb,
1073 0x40c003fc, 0x40000100
1074};
1075
Tobin Davis93ed1502006-09-01 21:03:12 +02001076static unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001077 [STAC_D965_REF] = ref927x_pin_configs,
Tobin Davis93ed1502006-09-01 21:03:12 +02001078 [STAC_D965_3ST] = d965_3st_pin_configs,
1079 [STAC_D965_5ST] = d965_5st_pin_configs,
Tobin Davis4ff076e2007-08-07 11:48:12 +02001080 [STAC_DELL_3ST] = dell_3st_pin_configs,
Matt Porter3cc08dc2006-01-23 15:27:49 +01001081};
1082
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001083static const char *stac927x_models[STAC_927X_MODELS] = {
1084 [STAC_D965_REF] = "ref",
1085 [STAC_D965_3ST] = "3stack",
1086 [STAC_D965_5ST] = "5stack",
Tobin Davis4ff076e2007-08-07 11:48:12 +02001087 [STAC_DELL_3ST] = "dell-3stack",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001088};
1089
1090static struct snd_pci_quirk stac927x_cfg_tbl[] = {
1091 /* SigmaTel reference board */
1092 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1093 "DFI LanParty", STAC_D965_REF),
Tobin Davis81d3dbd2006-08-22 19:44:45 +02001094 /* Intel 946 based systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001095 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST),
1096 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST),
Tobin Davis93ed1502006-09-01 21:03:12 +02001097 /* 965 based 3 stack systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001098 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2116, "Intel D965", STAC_D965_3ST),
1099 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2115, "Intel D965", STAC_D965_3ST),
1100 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2114, "Intel D965", STAC_D965_3ST),
1101 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2113, "Intel D965", STAC_D965_3ST),
1102 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2112, "Intel D965", STAC_D965_3ST),
1103 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2111, "Intel D965", STAC_D965_3ST),
1104 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2110, "Intel D965", STAC_D965_3ST),
1105 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2009, "Intel D965", STAC_D965_3ST),
1106 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2008, "Intel D965", STAC_D965_3ST),
1107 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2007, "Intel D965", STAC_D965_3ST),
1108 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2006, "Intel D965", STAC_D965_3ST),
1109 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2005, "Intel D965", STAC_D965_3ST),
1110 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2004, "Intel D965", STAC_D965_3ST),
1111 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2003, "Intel D965", STAC_D965_3ST),
1112 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2002, "Intel D965", STAC_D965_3ST),
1113 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2001, "Intel D965", STAC_D965_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +02001114 /* Dell 3 stack systems */
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001115 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01dd, "Dell Dimension E520", STAC_DELL_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +02001116 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ed, "Dell ", STAC_DELL_3ST),
1117 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f4, "Dell ", STAC_DELL_3ST),
Tobin Davis93ed1502006-09-01 21:03:12 +02001118 /* 965 based 5 stack systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001119 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2301, "Intel D965", STAC_D965_5ST),
1120 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2302, "Intel D965", STAC_D965_5ST),
1121 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2303, "Intel D965", STAC_D965_5ST),
1122 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2304, "Intel D965", STAC_D965_5ST),
1123 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2305, "Intel D965", STAC_D965_5ST),
1124 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2501, "Intel D965", STAC_D965_5ST),
1125 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2502, "Intel D965", STAC_D965_5ST),
1126 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2503, "Intel D965", STAC_D965_5ST),
1127 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2504, "Intel D965", STAC_D965_5ST),
Matt Porter3cc08dc2006-01-23 15:27:49 +01001128 {} /* terminator */
1129};
1130
Matt Porterf3302a52006-07-31 12:49:34 +02001131static unsigned int ref9205_pin_configs[12] = {
1132 0x40000100, 0x40000100, 0x01016011, 0x01014010,
Matt Porter8b657272006-10-26 17:12:59 +02001133 0x01813122, 0x01a19021, 0x40000100, 0x40000100,
1134 0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
Matt Porterf3302a52006-07-31 12:49:34 +02001135};
1136
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001137/*
1138 STAC 9205 pin configs for
1139 102801F1
1140 102801F2
1141 102801FC
1142 102801FD
1143 10280204
1144 1028021F
1145*/
1146static unsigned int dell_9205_m42_pin_configs[12] = {
1147 0x0321101F, 0x03A11020, 0x400003FA, 0x90170310,
1148 0x400003FB, 0x400003FC, 0x400003FD, 0x40F000F9,
1149 0x90A60330, 0x400003FF, 0x0144131F, 0x40C003FE,
1150};
1151
1152/*
1153 STAC 9205 pin configs for
1154 102801F9
1155 102801FA
1156 102801FE
1157 102801FF (Dell Precision M4300)
1158 10280206
1159 10280200
1160 10280201
1161*/
1162static unsigned int dell_9205_m43_pin_configs[12] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001163 0x0321101f, 0x03a11020, 0x90a70330, 0x90170310,
1164 0x400000fe, 0x400000ff, 0x400000fd, 0x40f000f9,
1165 0x400000fa, 0x400000fc, 0x0144131f, 0x40c003f8,
1166};
1167
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001168static unsigned int dell_9205_m44_pin_configs[12] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001169 0x0421101f, 0x04a11020, 0x400003fa, 0x90170310,
1170 0x400003fb, 0x400003fc, 0x400003fd, 0x400003f9,
1171 0x90a60330, 0x400003ff, 0x01441340, 0x40c003fe,
1172};
1173
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001174static unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001175 [STAC_9205_REF] = ref9205_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001176 [STAC_9205_DELL_M42] = dell_9205_m42_pin_configs,
1177 [STAC_9205_DELL_M43] = dell_9205_m43_pin_configs,
1178 [STAC_9205_DELL_M44] = dell_9205_m44_pin_configs,
Matt Porterf3302a52006-07-31 12:49:34 +02001179};
1180
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001181static const char *stac9205_models[STAC_9205_MODELS] = {
1182 [STAC_9205_REF] = "ref",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001183 [STAC_9205_DELL_M42] = "dell-m42",
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001184 [STAC_9205_DELL_M43] = "dell-m43",
1185 [STAC_9205_DELL_M44] = "dell-m44",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001186};
1187
1188static struct snd_pci_quirk stac9205_cfg_tbl[] = {
1189 /* SigmaTel reference board */
1190 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1191 "DFI LanParty", STAC_9205_REF),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001192 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f1,
1193 "unknown Dell", STAC_9205_DELL_M42),
1194 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f2,
1195 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001196 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f8,
Matthew Ranostayb44ef2f2007-09-18 00:52:38 +02001197 "Dell Precision", STAC_9205_DELL_M43),
1198 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021c,
1199 "Dell Precision", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001200 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f9,
1201 "Dell Precision", STAC_9205_DELL_M43),
Matthew Ranostaye45e4592007-09-10 23:09:42 +02001202 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021b,
1203 "Dell Precision", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001204 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fa,
1205 "Dell Precision", STAC_9205_DELL_M43),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001206 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fc,
1207 "unknown Dell", STAC_9205_DELL_M42),
1208 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fd,
1209 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001210 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fe,
1211 "Dell Precision", STAC_9205_DELL_M43),
1212 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ff,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001213 "Dell Precision M4300", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001214 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0206,
1215 "Dell Precision", STAC_9205_DELL_M43),
1216 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f1,
1217 "Dell Inspiron", STAC_9205_DELL_M44),
1218 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f2,
1219 "Dell Inspiron", STAC_9205_DELL_M44),
1220 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fc,
1221 "Dell Inspiron", STAC_9205_DELL_M44),
1222 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fd,
1223 "Dell Inspiron", STAC_9205_DELL_M44),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001224 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0204,
1225 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001226 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021f,
1227 "Dell Inspiron", STAC_9205_DELL_M44),
Matt Porterf3302a52006-07-31 12:49:34 +02001228 {} /* terminator */
1229};
1230
Richard Fish11b44bb2006-08-23 18:31:34 +02001231static int stac92xx_save_bios_config_regs(struct hda_codec *codec)
1232{
1233 int i;
1234 struct sigmatel_spec *spec = codec->spec;
1235
1236 if (! spec->bios_pin_configs) {
1237 spec->bios_pin_configs = kcalloc(spec->num_pins,
1238 sizeof(*spec->bios_pin_configs), GFP_KERNEL);
1239 if (! spec->bios_pin_configs)
1240 return -ENOMEM;
1241 }
1242
1243 for (i = 0; i < spec->num_pins; i++) {
1244 hda_nid_t nid = spec->pin_nids[i];
1245 unsigned int pin_cfg;
1246
1247 pin_cfg = snd_hda_codec_read(codec, nid, 0,
1248 AC_VERB_GET_CONFIG_DEFAULT, 0x00);
1249 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x bios pin config %8.8x\n",
1250 nid, pin_cfg);
1251 spec->bios_pin_configs[i] = pin_cfg;
1252 }
1253
1254 return 0;
1255}
1256
Matthew Ranostay87d48362007-07-17 11:52:24 +02001257static void stac92xx_set_config_reg(struct hda_codec *codec,
1258 hda_nid_t pin_nid, unsigned int pin_config)
1259{
1260 int i;
1261 snd_hda_codec_write(codec, pin_nid, 0,
1262 AC_VERB_SET_CONFIG_DEFAULT_BYTES_0,
1263 pin_config & 0x000000ff);
1264 snd_hda_codec_write(codec, pin_nid, 0,
1265 AC_VERB_SET_CONFIG_DEFAULT_BYTES_1,
1266 (pin_config & 0x0000ff00) >> 8);
1267 snd_hda_codec_write(codec, pin_nid, 0,
1268 AC_VERB_SET_CONFIG_DEFAULT_BYTES_2,
1269 (pin_config & 0x00ff0000) >> 16);
1270 snd_hda_codec_write(codec, pin_nid, 0,
1271 AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
1272 pin_config >> 24);
1273 i = snd_hda_codec_read(codec, pin_nid, 0,
1274 AC_VERB_GET_CONFIG_DEFAULT,
1275 0x00);
1276 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x pin config %8.8x\n",
1277 pin_nid, i);
1278}
1279
Matt2f2f4252005-04-13 14:45:30 +02001280static void stac92xx_set_config_regs(struct hda_codec *codec)
1281{
1282 int i;
1283 struct sigmatel_spec *spec = codec->spec;
Matt2f2f4252005-04-13 14:45:30 +02001284
Matthew Ranostay87d48362007-07-17 11:52:24 +02001285 if (!spec->pin_configs)
1286 return;
Richard Fish11b44bb2006-08-23 18:31:34 +02001287
Matthew Ranostay87d48362007-07-17 11:52:24 +02001288 for (i = 0; i < spec->num_pins; i++)
1289 stac92xx_set_config_reg(codec, spec->pin_nids[i],
1290 spec->pin_configs[i]);
Matt2f2f4252005-04-13 14:45:30 +02001291}
Matt2f2f4252005-04-13 14:45:30 +02001292
Takashi Iwai82599802007-07-31 15:56:24 +02001293static void stac92xx_enable_gpio_mask(struct hda_codec *codec)
Matthew Ranostay92a22be2007-06-19 16:48:28 +02001294{
Takashi Iwai82599802007-07-31 15:56:24 +02001295 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay87d48362007-07-17 11:52:24 +02001296 /* Configure GPIOx as output */
Takashi Iwai82beb8f2007-08-10 17:09:26 +02001297 snd_hda_codec_write_cache(codec, codec->afg, 0,
1298 AC_VERB_SET_GPIO_DIRECTION, spec->gpio_mask);
Matthew Ranostay87d48362007-07-17 11:52:24 +02001299 /* Configure GPIOx as CMOS */
Takashi Iwai82beb8f2007-08-10 17:09:26 +02001300 snd_hda_codec_write_cache(codec, codec->afg, 0, 0x7e7, 0x00000000);
Matthew Ranostay87d48362007-07-17 11:52:24 +02001301 /* Assert GPIOx */
Takashi Iwai82beb8f2007-08-10 17:09:26 +02001302 snd_hda_codec_write_cache(codec, codec->afg, 0,
1303 AC_VERB_SET_GPIO_DATA, spec->gpio_data);
Matthew Ranostay87d48362007-07-17 11:52:24 +02001304 /* Enable GPIOx */
Takashi Iwai82beb8f2007-08-10 17:09:26 +02001305 snd_hda_codec_write_cache(codec, codec->afg, 0,
1306 AC_VERB_SET_GPIO_MASK, spec->gpio_mask);
Matthew Ranostay92a22be2007-06-19 16:48:28 +02001307}
1308
Matt2f2f4252005-04-13 14:45:30 +02001309/*
1310 * Analog playback callbacks
1311 */
1312static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
1313 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001314 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02001315{
1316 struct sigmatel_spec *spec = codec->spec;
1317 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
1318}
1319
1320static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1321 struct hda_codec *codec,
1322 unsigned int stream_tag,
1323 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001324 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02001325{
1326 struct sigmatel_spec *spec = codec->spec;
Matt Porter403d1942005-11-29 15:00:51 +01001327 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
Matt2f2f4252005-04-13 14:45:30 +02001328}
1329
1330static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
1331 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001332 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02001333{
1334 struct sigmatel_spec *spec = codec->spec;
1335 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
1336}
1337
1338/*
Mattdabbed62005-06-14 10:19:34 +02001339 * Digital playback callbacks
1340 */
1341static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
1342 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001343 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +02001344{
1345 struct sigmatel_spec *spec = codec->spec;
1346 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
1347}
1348
1349static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
1350 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001351 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +02001352{
1353 struct sigmatel_spec *spec = codec->spec;
1354 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
1355}
1356
Takashi Iwai6b97eb42007-04-05 14:51:48 +02001357static int stac92xx_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1358 struct hda_codec *codec,
1359 unsigned int stream_tag,
1360 unsigned int format,
1361 struct snd_pcm_substream *substream)
1362{
1363 struct sigmatel_spec *spec = codec->spec;
1364 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1365 stream_tag, format, substream);
1366}
1367
Mattdabbed62005-06-14 10:19:34 +02001368
1369/*
Matt2f2f4252005-04-13 14:45:30 +02001370 * Analog capture callbacks
1371 */
1372static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1373 struct hda_codec *codec,
1374 unsigned int stream_tag,
1375 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001376 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02001377{
1378 struct sigmatel_spec *spec = codec->spec;
1379
1380 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
1381 stream_tag, 0, format);
1382 return 0;
1383}
1384
1385static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1386 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001387 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02001388{
1389 struct sigmatel_spec *spec = codec->spec;
1390
1391 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 0, 0, 0);
1392 return 0;
1393}
1394
Mattdabbed62005-06-14 10:19:34 +02001395static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
1396 .substreams = 1,
1397 .channels_min = 2,
1398 .channels_max = 2,
1399 /* NID is set in stac92xx_build_pcms */
1400 .ops = {
1401 .open = stac92xx_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02001402 .close = stac92xx_dig_playback_pcm_close,
1403 .prepare = stac92xx_dig_playback_pcm_prepare
Mattdabbed62005-06-14 10:19:34 +02001404 },
1405};
1406
1407static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
1408 .substreams = 1,
1409 .channels_min = 2,
1410 .channels_max = 2,
1411 /* NID is set in stac92xx_build_pcms */
1412};
1413
Matt2f2f4252005-04-13 14:45:30 +02001414static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
1415 .substreams = 1,
1416 .channels_min = 2,
Mattc7d4b2f2005-06-27 14:59:41 +02001417 .channels_max = 8,
Matt2f2f4252005-04-13 14:45:30 +02001418 .nid = 0x02, /* NID to query formats and rates */
1419 .ops = {
1420 .open = stac92xx_playback_pcm_open,
1421 .prepare = stac92xx_playback_pcm_prepare,
1422 .cleanup = stac92xx_playback_pcm_cleanup
1423 },
1424};
1425
Matt Porter3cc08dc2006-01-23 15:27:49 +01001426static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
1427 .substreams = 1,
1428 .channels_min = 2,
1429 .channels_max = 2,
1430 .nid = 0x06, /* NID to query formats and rates */
1431 .ops = {
1432 .open = stac92xx_playback_pcm_open,
1433 .prepare = stac92xx_playback_pcm_prepare,
1434 .cleanup = stac92xx_playback_pcm_cleanup
1435 },
1436};
1437
Matt2f2f4252005-04-13 14:45:30 +02001438static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
Matt2f2f4252005-04-13 14:45:30 +02001439 .channels_min = 2,
1440 .channels_max = 2,
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001441 /* NID + .substreams is set in stac92xx_build_pcms */
Matt2f2f4252005-04-13 14:45:30 +02001442 .ops = {
1443 .prepare = stac92xx_capture_pcm_prepare,
1444 .cleanup = stac92xx_capture_pcm_cleanup
1445 },
1446};
1447
1448static int stac92xx_build_pcms(struct hda_codec *codec)
1449{
1450 struct sigmatel_spec *spec = codec->spec;
1451 struct hda_pcm *info = spec->pcm_rec;
1452
1453 codec->num_pcms = 1;
1454 codec->pcm_info = info;
1455
Mattc7d4b2f2005-06-27 14:59:41 +02001456 info->name = "STAC92xx Analog";
Matt2f2f4252005-04-13 14:45:30 +02001457 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
Matt2f2f4252005-04-13 14:45:30 +02001458 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
Matt Porter3cc08dc2006-01-23 15:27:49 +01001459 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001460 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adcs;
Matt Porter3cc08dc2006-01-23 15:27:49 +01001461
1462 if (spec->alt_switch) {
1463 codec->num_pcms++;
1464 info++;
1465 info->name = "STAC92xx Analog Alt";
1466 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
1467 }
Matt2f2f4252005-04-13 14:45:30 +02001468
Mattdabbed62005-06-14 10:19:34 +02001469 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
1470 codec->num_pcms++;
1471 info++;
1472 info->name = "STAC92xx Digital";
1473 if (spec->multiout.dig_out_nid) {
1474 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
1475 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
1476 }
1477 if (spec->dig_in_nid) {
1478 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
1479 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
1480 }
1481 }
1482
Matt2f2f4252005-04-13 14:45:30 +02001483 return 0;
1484}
1485
Takashi Iwaic960a032006-03-23 17:06:28 +01001486static unsigned int stac92xx_get_vref(struct hda_codec *codec, hda_nid_t nid)
1487{
1488 unsigned int pincap = snd_hda_param_read(codec, nid,
1489 AC_PAR_PIN_CAP);
1490 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
1491 if (pincap & AC_PINCAP_VREF_100)
1492 return AC_PINCTL_VREF_100;
1493 if (pincap & AC_PINCAP_VREF_80)
1494 return AC_PINCTL_VREF_80;
1495 if (pincap & AC_PINCAP_VREF_50)
1496 return AC_PINCTL_VREF_50;
1497 if (pincap & AC_PINCAP_VREF_GRD)
1498 return AC_PINCTL_VREF_GRD;
1499 return 0;
1500}
1501
Matt Porter403d1942005-11-29 15:00:51 +01001502static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
1503
1504{
Takashi Iwai82beb8f2007-08-10 17:09:26 +02001505 snd_hda_codec_write_cache(codec, nid, 0,
1506 AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
Matt Porter403d1942005-11-29 15:00:51 +01001507}
1508
Takashi Iwaia5ce8892007-07-23 15:42:26 +02001509#define stac92xx_io_switch_info snd_ctl_boolean_mono_info
Matt Porter403d1942005-11-29 15:00:51 +01001510
1511static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1512{
1513 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1514 struct sigmatel_spec *spec = codec->spec;
1515 int io_idx = kcontrol-> private_value & 0xff;
1516
1517 ucontrol->value.integer.value[0] = spec->io_switch[io_idx];
1518 return 0;
1519}
1520
1521static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1522{
1523 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1524 struct sigmatel_spec *spec = codec->spec;
1525 hda_nid_t nid = kcontrol->private_value >> 8;
1526 int io_idx = kcontrol-> private_value & 0xff;
1527 unsigned short val = ucontrol->value.integer.value[0];
1528
1529 spec->io_switch[io_idx] = val;
1530
1531 if (val)
1532 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
Takashi Iwaic960a032006-03-23 17:06:28 +01001533 else {
1534 unsigned int pinctl = AC_PINCTL_IN_EN;
1535 if (io_idx) /* set VREF for mic */
1536 pinctl |= stac92xx_get_vref(codec, nid);
1537 stac92xx_auto_set_pinctl(codec, nid, pinctl);
1538 }
Matt Porter403d1942005-11-29 15:00:51 +01001539 return 1;
1540}
1541
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02001542#define stac92xx_clfe_switch_info snd_ctl_boolean_mono_info
1543
1544static int stac92xx_clfe_switch_get(struct snd_kcontrol *kcontrol,
1545 struct snd_ctl_elem_value *ucontrol)
1546{
1547 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1548 struct sigmatel_spec *spec = codec->spec;
1549
1550 ucontrol->value.integer.value[0] = spec->clfe_swap;
1551 return 0;
1552}
1553
1554static int stac92xx_clfe_switch_put(struct snd_kcontrol *kcontrol,
1555 struct snd_ctl_elem_value *ucontrol)
1556{
1557 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1558 struct sigmatel_spec *spec = codec->spec;
1559 hda_nid_t nid = kcontrol->private_value & 0xff;
1560
1561 if (spec->clfe_swap == ucontrol->value.integer.value[0])
1562 return 0;
1563
1564 spec->clfe_swap = ucontrol->value.integer.value[0];
1565
1566 snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
1567 spec->clfe_swap ? 0x4 : 0x0);
1568
1569 return 1;
1570}
1571
Matt Porter403d1942005-11-29 15:00:51 +01001572#define STAC_CODEC_IO_SWITCH(xname, xpval) \
1573 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1574 .name = xname, \
1575 .index = 0, \
1576 .info = stac92xx_io_switch_info, \
1577 .get = stac92xx_io_switch_get, \
1578 .put = stac92xx_io_switch_put, \
1579 .private_value = xpval, \
1580 }
1581
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02001582#define STAC_CODEC_CLFE_SWITCH(xname, xpval) \
1583 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1584 .name = xname, \
1585 .index = 0, \
1586 .info = stac92xx_clfe_switch_info, \
1587 .get = stac92xx_clfe_switch_get, \
1588 .put = stac92xx_clfe_switch_put, \
1589 .private_value = xpval, \
1590 }
Matt Porter403d1942005-11-29 15:00:51 +01001591
Mattc7d4b2f2005-06-27 14:59:41 +02001592enum {
1593 STAC_CTL_WIDGET_VOL,
1594 STAC_CTL_WIDGET_MUTE,
Matt Porter403d1942005-11-29 15:00:51 +01001595 STAC_CTL_WIDGET_IO_SWITCH,
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02001596 STAC_CTL_WIDGET_CLFE_SWITCH
Mattc7d4b2f2005-06-27 14:59:41 +02001597};
1598
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001599static struct snd_kcontrol_new stac92xx_control_templates[] = {
Mattc7d4b2f2005-06-27 14:59:41 +02001600 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
1601 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Matt Porter403d1942005-11-29 15:00:51 +01001602 STAC_CODEC_IO_SWITCH(NULL, 0),
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02001603 STAC_CODEC_CLFE_SWITCH(NULL, 0),
Mattc7d4b2f2005-06-27 14:59:41 +02001604};
1605
1606/* add dynamic controls */
1607static int stac92xx_add_control(struct sigmatel_spec *spec, int type, const char *name, unsigned long val)
1608{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001609 struct snd_kcontrol_new *knew;
Mattc7d4b2f2005-06-27 14:59:41 +02001610
1611 if (spec->num_kctl_used >= spec->num_kctl_alloc) {
1612 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
1613
1614 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */
1615 if (! knew)
1616 return -ENOMEM;
1617 if (spec->kctl_alloc) {
1618 memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
1619 kfree(spec->kctl_alloc);
1620 }
1621 spec->kctl_alloc = knew;
1622 spec->num_kctl_alloc = num;
1623 }
1624
1625 knew = &spec->kctl_alloc[spec->num_kctl_used];
1626 *knew = stac92xx_control_templates[type];
Takashi Iwai82fe0c52005-06-30 10:54:33 +02001627 knew->name = kstrdup(name, GFP_KERNEL);
Mattc7d4b2f2005-06-27 14:59:41 +02001628 if (! knew->name)
1629 return -ENOMEM;
1630 knew->private_value = val;
1631 spec->num_kctl_used++;
1632 return 0;
1633}
1634
Matt Porter403d1942005-11-29 15:00:51 +01001635/* flag inputs as additional dynamic lineouts */
1636static int stac92xx_add_dyn_out_pins(struct hda_codec *codec, struct auto_pin_cfg *cfg)
1637{
1638 struct sigmatel_spec *spec = codec->spec;
Steve Longerbeam7b043892007-05-03 20:50:03 +02001639 unsigned int wcaps, wtype;
1640 int i, num_dacs = 0;
1641
1642 /* use the wcaps cache to count all DACs available for line-outs */
1643 for (i = 0; i < codec->num_nodes; i++) {
1644 wcaps = codec->wcaps[i];
1645 wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
1646 if (wtype == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL))
1647 num_dacs++;
1648 }
Matt Porter403d1942005-11-29 15:00:51 +01001649
Steve Longerbeam7b043892007-05-03 20:50:03 +02001650 snd_printdd("%s: total dac count=%d\n", __func__, num_dacs);
1651
Matt Porter403d1942005-11-29 15:00:51 +01001652 switch (cfg->line_outs) {
1653 case 3:
1654 /* add line-in as side */
Steve Longerbeam7b043892007-05-03 20:50:03 +02001655 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 3) {
Takashi Iwaic480f792007-09-03 09:43:38 +02001656 cfg->line_out_pins[cfg->line_outs] =
1657 cfg->input_pins[AUTO_PIN_LINE];
Matt Porter403d1942005-11-29 15:00:51 +01001658 spec->line_switch = 1;
1659 cfg->line_outs++;
1660 }
1661 break;
1662 case 2:
1663 /* add line-in as clfe and mic as side */
Steve Longerbeam7b043892007-05-03 20:50:03 +02001664 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 2) {
Takashi Iwaic480f792007-09-03 09:43:38 +02001665 cfg->line_out_pins[cfg->line_outs] =
1666 cfg->input_pins[AUTO_PIN_LINE];
Matt Porter403d1942005-11-29 15:00:51 +01001667 spec->line_switch = 1;
1668 cfg->line_outs++;
1669 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02001670 if (cfg->input_pins[AUTO_PIN_MIC] && num_dacs > 3) {
Takashi Iwaic480f792007-09-03 09:43:38 +02001671 cfg->line_out_pins[cfg->line_outs] =
1672 cfg->input_pins[AUTO_PIN_MIC];
Matt Porter403d1942005-11-29 15:00:51 +01001673 spec->mic_switch = 1;
1674 cfg->line_outs++;
1675 }
1676 break;
1677 case 1:
1678 /* add line-in as surr and mic as clfe */
Steve Longerbeam7b043892007-05-03 20:50:03 +02001679 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 1) {
Takashi Iwaic480f792007-09-03 09:43:38 +02001680 cfg->line_out_pins[cfg->line_outs] =
1681 cfg->input_pins[AUTO_PIN_LINE];
Matt Porter403d1942005-11-29 15:00:51 +01001682 spec->line_switch = 1;
1683 cfg->line_outs++;
1684 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02001685 if (cfg->input_pins[AUTO_PIN_MIC] && num_dacs > 2) {
Takashi Iwaic480f792007-09-03 09:43:38 +02001686 cfg->line_out_pins[cfg->line_outs] =
1687 cfg->input_pins[AUTO_PIN_MIC];
Matt Porter403d1942005-11-29 15:00:51 +01001688 spec->mic_switch = 1;
1689 cfg->line_outs++;
1690 }
1691 break;
1692 }
1693
1694 return 0;
1695}
1696
Steve Longerbeam7b043892007-05-03 20:50:03 +02001697
1698static int is_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
1699{
1700 int i;
1701
1702 for (i = 0; i < spec->multiout.num_dacs; i++) {
1703 if (spec->multiout.dac_nids[i] == nid)
1704 return 1;
1705 }
1706
1707 return 0;
1708}
1709
Matt Porter3cc08dc2006-01-23 15:27:49 +01001710/*
Steve Longerbeam7b043892007-05-03 20:50:03 +02001711 * Fill in the dac_nids table from the parsed pin configuration
1712 * This function only works when every pin in line_out_pins[]
1713 * contains atleast one DAC in its connection list. Some 92xx
1714 * codecs are not connected directly to a DAC, such as the 9200
1715 * and 9202/925x. For those, dac_nids[] must be hard-coded.
Matt Porter3cc08dc2006-01-23 15:27:49 +01001716 */
Takashi Iwai19039bd2006-06-28 15:52:16 +02001717static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec,
Takashi Iwaidf802952007-07-02 19:18:00 +02001718 struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02001719{
1720 struct sigmatel_spec *spec = codec->spec;
Steve Longerbeam7b043892007-05-03 20:50:03 +02001721 int i, j, conn_len = 0;
1722 hda_nid_t nid, conn[HDA_MAX_CONNECTIONS];
1723 unsigned int wcaps, wtype;
1724
Mattc7d4b2f2005-06-27 14:59:41 +02001725 for (i = 0; i < cfg->line_outs; i++) {
1726 nid = cfg->line_out_pins[i];
Steve Longerbeam7b043892007-05-03 20:50:03 +02001727 conn_len = snd_hda_get_connections(codec, nid, conn,
1728 HDA_MAX_CONNECTIONS);
1729 for (j = 0; j < conn_len; j++) {
1730 wcaps = snd_hda_param_read(codec, conn[j],
1731 AC_PAR_AUDIO_WIDGET_CAP);
1732 wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
1733
1734 if (wtype != AC_WID_AUD_OUT ||
1735 (wcaps & AC_WCAP_DIGITAL))
1736 continue;
1737 /* conn[j] is a DAC routed to this line-out */
1738 if (!is_in_dac_nids(spec, conn[j]))
1739 break;
1740 }
1741
1742 if (j == conn_len) {
Takashi Iwaidf802952007-07-02 19:18:00 +02001743 if (spec->multiout.num_dacs > 0) {
1744 /* we have already working output pins,
1745 * so let's drop the broken ones again
1746 */
1747 cfg->line_outs = spec->multiout.num_dacs;
1748 break;
1749 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02001750 /* error out, no available DAC found */
1751 snd_printk(KERN_ERR
1752 "%s: No available DAC for pin 0x%x\n",
1753 __func__, nid);
1754 return -ENODEV;
1755 }
1756
1757 spec->multiout.dac_nids[i] = conn[j];
1758 spec->multiout.num_dacs++;
1759 if (conn_len > 1) {
1760 /* select this DAC in the pin's input mux */
Takashi Iwai82beb8f2007-08-10 17:09:26 +02001761 snd_hda_codec_write_cache(codec, nid, 0,
1762 AC_VERB_SET_CONNECT_SEL, j);
Steve Longerbeam7b043892007-05-03 20:50:03 +02001763
1764 }
Mattc7d4b2f2005-06-27 14:59:41 +02001765 }
1766
Steve Longerbeam7b043892007-05-03 20:50:03 +02001767 snd_printd("dac_nids=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
1768 spec->multiout.num_dacs,
1769 spec->multiout.dac_nids[0],
1770 spec->multiout.dac_nids[1],
1771 spec->multiout.dac_nids[2],
1772 spec->multiout.dac_nids[3],
1773 spec->multiout.dac_nids[4]);
Mattc7d4b2f2005-06-27 14:59:41 +02001774 return 0;
1775}
1776
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001777/* create volume control/switch for the given prefx type */
1778static int create_controls(struct sigmatel_spec *spec, const char *pfx, hda_nid_t nid, int chs)
1779{
1780 char name[32];
1781 int err;
1782
1783 sprintf(name, "%s Playback Volume", pfx);
1784 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, name,
1785 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1786 if (err < 0)
1787 return err;
1788 sprintf(name, "%s Playback Switch", pfx);
1789 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, name,
1790 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1791 if (err < 0)
1792 return err;
1793 return 0;
1794}
1795
Mattc7d4b2f2005-06-27 14:59:41 +02001796/* add playback controls from the parsed DAC table */
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02001797static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
Takashi Iwai19039bd2006-06-28 15:52:16 +02001798 const struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02001799{
Takashi Iwai19039bd2006-06-28 15:52:16 +02001800 static const char *chname[4] = {
1801 "Front", "Surround", NULL /*CLFE*/, "Side"
1802 };
Mattc7d4b2f2005-06-27 14:59:41 +02001803 hda_nid_t nid;
1804 int i, err;
1805
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02001806 struct sigmatel_spec *spec = codec->spec;
1807 unsigned int wid_caps;
1808
1809
Mattc7d4b2f2005-06-27 14:59:41 +02001810 for (i = 0; i < cfg->line_outs; i++) {
Matt Porter403d1942005-11-29 15:00:51 +01001811 if (!spec->multiout.dac_nids[i])
Mattc7d4b2f2005-06-27 14:59:41 +02001812 continue;
1813
1814 nid = spec->multiout.dac_nids[i];
1815
1816 if (i == 2) {
1817 /* Center/LFE */
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001818 err = create_controls(spec, "Center", nid, 1);
1819 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001820 return err;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001821 err = create_controls(spec, "LFE", nid, 2);
1822 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001823 return err;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02001824
1825 wid_caps = get_wcaps(codec, nid);
1826
1827 if (wid_caps & AC_WCAP_LR_SWAP) {
1828 err = stac92xx_add_control(spec,
1829 STAC_CTL_WIDGET_CLFE_SWITCH,
1830 "Swap Center/LFE Playback Switch", nid);
1831
1832 if (err < 0)
1833 return err;
1834 }
1835
Mattc7d4b2f2005-06-27 14:59:41 +02001836 } else {
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001837 err = create_controls(spec, chname[i], nid, 3);
1838 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001839 return err;
1840 }
1841 }
1842
Matt Porter403d1942005-11-29 15:00:51 +01001843 if (spec->line_switch)
1844 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Line In as Output Switch", cfg->input_pins[AUTO_PIN_LINE] << 8)) < 0)
1845 return err;
1846
1847 if (spec->mic_switch)
1848 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Mic as Output Switch", (cfg->input_pins[AUTO_PIN_MIC] << 8) | 1)) < 0)
1849 return err;
1850
Mattc7d4b2f2005-06-27 14:59:41 +02001851 return 0;
1852}
1853
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001854static int check_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
1855{
Steve Longerbeam7b043892007-05-03 20:50:03 +02001856 if (is_in_dac_nids(spec, nid))
1857 return 1;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001858 if (spec->multiout.hp_nid == nid)
1859 return 1;
1860 return 0;
1861}
1862
1863static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
1864{
1865 if (!spec->multiout.hp_nid)
1866 spec->multiout.hp_nid = nid;
1867 else if (spec->multiout.num_dacs > 4) {
1868 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
1869 return 1;
1870 } else {
1871 spec->multiout.dac_nids[spec->multiout.num_dacs] = nid;
1872 spec->multiout.num_dacs++;
1873 }
1874 return 0;
1875}
1876
1877/* add playback controls for Speaker and HP outputs */
1878static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
1879 struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02001880{
1881 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02001882 hda_nid_t nid;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001883 int i, old_num_dacs, err;
Mattc7d4b2f2005-06-27 14:59:41 +02001884
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001885 old_num_dacs = spec->multiout.num_dacs;
1886 for (i = 0; i < cfg->hp_outs; i++) {
1887 unsigned int wid_caps = get_wcaps(codec, cfg->hp_pins[i]);
1888 if (wid_caps & AC_WCAP_UNSOL_CAP)
1889 spec->hp_detect = 1;
1890 nid = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
1891 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
1892 if (check_in_dac_nids(spec, nid))
1893 nid = 0;
1894 if (! nid)
Mattc7d4b2f2005-06-27 14:59:41 +02001895 continue;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001896 add_spec_dacs(spec, nid);
1897 }
1898 for (i = 0; i < cfg->speaker_outs; i++) {
Steve Longerbeam7b043892007-05-03 20:50:03 +02001899 nid = snd_hda_codec_read(codec, cfg->speaker_pins[i], 0,
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001900 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
1901 if (check_in_dac_nids(spec, nid))
1902 nid = 0;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001903 if (! nid)
1904 continue;
1905 add_spec_dacs(spec, nid);
Mattc7d4b2f2005-06-27 14:59:41 +02001906 }
Matthew Ranostay1b290a52007-07-12 15:17:34 +02001907 for (i = 0; i < cfg->line_outs; i++) {
1908 nid = snd_hda_codec_read(codec, cfg->line_out_pins[i], 0,
1909 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
1910 if (check_in_dac_nids(spec, nid))
1911 nid = 0;
1912 if (! nid)
1913 continue;
1914 add_spec_dacs(spec, nid);
1915 }
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001916 for (i = old_num_dacs; i < spec->multiout.num_dacs; i++) {
1917 static const char *pfxs[] = {
1918 "Speaker", "External Speaker", "Speaker2",
1919 };
1920 err = create_controls(spec, pfxs[i - old_num_dacs],
1921 spec->multiout.dac_nids[i], 3);
1922 if (err < 0)
1923 return err;
1924 }
1925 if (spec->multiout.hp_nid) {
1926 const char *pfx;
1927 if (old_num_dacs == spec->multiout.num_dacs)
1928 pfx = "Master";
1929 else
1930 pfx = "Headphone";
1931 err = create_controls(spec, pfx, spec->multiout.hp_nid, 3);
1932 if (err < 0)
1933 return err;
1934 }
Mattc7d4b2f2005-06-27 14:59:41 +02001935
1936 return 0;
1937}
1938
Matt Porter8b657272006-10-26 17:12:59 +02001939/* labels for dmic mux inputs */
Adrian Bunkddc2cec2006-11-20 12:03:44 +01001940static const char *stac92xx_dmic_labels[5] = {
Matt Porter8b657272006-10-26 17:12:59 +02001941 "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
1942 "Digital Mic 3", "Digital Mic 4"
1943};
1944
1945/* create playback/capture controls for input pins on dmic capable codecs */
1946static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
1947 const struct auto_pin_cfg *cfg)
1948{
1949 struct sigmatel_spec *spec = codec->spec;
1950 struct hda_input_mux *dimux = &spec->private_dimux;
1951 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
1952 int i, j;
1953
1954 dimux->items[dimux->num_items].label = stac92xx_dmic_labels[0];
1955 dimux->items[dimux->num_items].index = 0;
1956 dimux->num_items++;
1957
1958 for (i = 0; i < spec->num_dmics; i++) {
1959 int index;
1960 int num_cons;
1961 unsigned int def_conf;
1962
1963 def_conf = snd_hda_codec_read(codec,
1964 spec->dmic_nids[i],
1965 0,
1966 AC_VERB_GET_CONFIG_DEFAULT,
1967 0);
1968 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
1969 continue;
1970
1971 num_cons = snd_hda_get_connections(codec,
1972 spec->dmux_nid,
1973 con_lst,
1974 HDA_MAX_NUM_INPUTS);
1975 for (j = 0; j < num_cons; j++)
1976 if (con_lst[j] == spec->dmic_nids[i]) {
1977 index = j;
1978 goto found;
1979 }
1980 continue;
1981found:
1982 dimux->items[dimux->num_items].label =
1983 stac92xx_dmic_labels[dimux->num_items];
1984 dimux->items[dimux->num_items].index = index;
1985 dimux->num_items++;
1986 }
1987
1988 return 0;
1989}
1990
Mattc7d4b2f2005-06-27 14:59:41 +02001991/* create playback/capture controls for input pins */
1992static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
1993{
1994 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02001995 struct hda_input_mux *imux = &spec->private_imux;
1996 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
1997 int i, j, k;
1998
1999 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwai314634b2006-09-21 11:56:18 +02002000 int index;
Mattc7d4b2f2005-06-27 14:59:41 +02002001
Takashi Iwai314634b2006-09-21 11:56:18 +02002002 if (!cfg->input_pins[i])
2003 continue;
2004 index = -1;
2005 for (j = 0; j < spec->num_muxes; j++) {
2006 int num_cons;
2007 num_cons = snd_hda_get_connections(codec,
2008 spec->mux_nids[j],
2009 con_lst,
2010 HDA_MAX_NUM_INPUTS);
2011 for (k = 0; k < num_cons; k++)
2012 if (con_lst[k] == cfg->input_pins[i]) {
2013 index = k;
2014 goto found;
2015 }
Mattc7d4b2f2005-06-27 14:59:41 +02002016 }
Takashi Iwai314634b2006-09-21 11:56:18 +02002017 continue;
2018 found:
2019 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
2020 imux->items[imux->num_items].index = index;
2021 imux->num_items++;
Mattc7d4b2f2005-06-27 14:59:41 +02002022 }
2023
Steve Longerbeam7b043892007-05-03 20:50:03 +02002024 if (imux->num_items) {
Sam Revitch62fe78e2006-05-10 15:09:17 +02002025 /*
2026 * Set the current input for the muxes.
2027 * The STAC9221 has two input muxes with identical source
2028 * NID lists. Hopefully this won't get confused.
2029 */
2030 for (i = 0; i < spec->num_muxes; i++) {
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002031 snd_hda_codec_write_cache(codec, spec->mux_nids[i], 0,
2032 AC_VERB_SET_CONNECT_SEL,
2033 imux->items[0].index);
Sam Revitch62fe78e2006-05-10 15:09:17 +02002034 }
2035 }
2036
Mattc7d4b2f2005-06-27 14:59:41 +02002037 return 0;
2038}
2039
Mattc7d4b2f2005-06-27 14:59:41 +02002040static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
2041{
2042 struct sigmatel_spec *spec = codec->spec;
2043 int i;
2044
2045 for (i = 0; i < spec->autocfg.line_outs; i++) {
2046 hda_nid_t nid = spec->autocfg.line_out_pins[i];
2047 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
2048 }
2049}
2050
2051static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
2052{
2053 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002054 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02002055
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002056 for (i = 0; i < spec->autocfg.hp_outs; i++) {
2057 hda_nid_t pin;
2058 pin = spec->autocfg.hp_pins[i];
2059 if (pin) /* connect to front */
2060 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
2061 }
2062 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
2063 hda_nid_t pin;
2064 pin = spec->autocfg.speaker_pins[i];
2065 if (pin) /* connect to front */
2066 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
2067 }
Mattc7d4b2f2005-06-27 14:59:41 +02002068}
2069
Matt Porter3cc08dc2006-01-23 15:27:49 +01002070static 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 +02002071{
2072 struct sigmatel_spec *spec = codec->spec;
2073 int err;
2074
Matt Porter8b657272006-10-26 17:12:59 +02002075 if ((err = snd_hda_parse_pin_def_config(codec,
2076 &spec->autocfg,
2077 spec->dmic_nids)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02002078 return err;
Takashi Iwai82bc9552006-03-21 11:24:42 +01002079 if (! spec->autocfg.line_outs)
Matt Porter869264c2006-01-25 19:20:50 +01002080 return 0; /* can't find valid pin config */
Takashi Iwai19039bd2006-06-28 15:52:16 +02002081
Matt Porter403d1942005-11-29 15:00:51 +01002082 if ((err = stac92xx_add_dyn_out_pins(codec, &spec->autocfg)) < 0)
2083 return err;
Takashi Iwai19039bd2006-06-28 15:52:16 +02002084 if (spec->multiout.num_dacs == 0)
2085 if ((err = stac92xx_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
2086 return err;
Mattc7d4b2f2005-06-27 14:59:41 +02002087
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002088 err = stac92xx_auto_create_multi_out_ctls(codec, &spec->autocfg);
2089
2090 if (err < 0)
2091 return err;
2092
2093 err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg);
2094
2095 if (err < 0)
2096 return err;
2097
2098 err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg);
2099
2100 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02002101 return err;
2102
Matt Porter8b657272006-10-26 17:12:59 +02002103 if (spec->num_dmics > 0)
2104 if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
2105 &spec->autocfg)) < 0)
2106 return err;
2107
Mattc7d4b2f2005-06-27 14:59:41 +02002108 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Matt Porter403d1942005-11-29 15:00:51 +01002109 if (spec->multiout.max_channels > 2)
Mattc7d4b2f2005-06-27 14:59:41 +02002110 spec->surr_switch = 1;
Mattc7d4b2f2005-06-27 14:59:41 +02002111
Takashi Iwai82bc9552006-03-21 11:24:42 +01002112 if (spec->autocfg.dig_out_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01002113 spec->multiout.dig_out_nid = dig_out;
Takashi Iwai82bc9552006-03-21 11:24:42 +01002114 if (spec->autocfg.dig_in_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01002115 spec->dig_in_nid = dig_in;
Mattc7d4b2f2005-06-27 14:59:41 +02002116
2117 if (spec->kctl_alloc)
2118 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
2119
2120 spec->input_mux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02002121 spec->dinput_mux = &spec->private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +02002122
2123 return 1;
2124}
2125
Takashi Iwai82bc9552006-03-21 11:24:42 +01002126/* add playback controls for HP output */
2127static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
2128 struct auto_pin_cfg *cfg)
2129{
2130 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002131 hda_nid_t pin = cfg->hp_pins[0];
Takashi Iwai82bc9552006-03-21 11:24:42 +01002132 unsigned int wid_caps;
2133
2134 if (! pin)
2135 return 0;
2136
2137 wid_caps = get_wcaps(codec, pin);
Takashi Iwai505cb342006-03-27 12:51:52 +02002138 if (wid_caps & AC_WCAP_UNSOL_CAP)
Takashi Iwai82bc9552006-03-21 11:24:42 +01002139 spec->hp_detect = 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +01002140
2141 return 0;
2142}
2143
Richard Fish160ea0d2006-09-06 13:58:25 +02002144/* add playback controls for LFE output */
2145static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
2146 struct auto_pin_cfg *cfg)
2147{
2148 struct sigmatel_spec *spec = codec->spec;
2149 int err;
2150 hda_nid_t lfe_pin = 0x0;
2151 int i;
2152
2153 /*
2154 * search speaker outs and line outs for a mono speaker pin
2155 * with an amp. If one is found, add LFE controls
2156 * for it.
2157 */
2158 for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
2159 hda_nid_t pin = spec->autocfg.speaker_pins[i];
2160 unsigned long wcaps = get_wcaps(codec, pin);
2161 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
2162 if (wcaps == AC_WCAP_OUT_AMP)
2163 /* found a mono speaker with an amp, must be lfe */
2164 lfe_pin = pin;
2165 }
2166
2167 /* if speaker_outs is 0, then speakers may be in line_outs */
2168 if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
2169 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
2170 hda_nid_t pin = spec->autocfg.line_out_pins[i];
2171 unsigned long cfg;
2172 cfg = snd_hda_codec_read(codec, pin, 0,
2173 AC_VERB_GET_CONFIG_DEFAULT,
2174 0x00);
2175 if (get_defcfg_device(cfg) == AC_JACK_SPEAKER) {
2176 unsigned long wcaps = get_wcaps(codec, pin);
2177 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
2178 if (wcaps == AC_WCAP_OUT_AMP)
2179 /* found a mono speaker with an amp,
2180 must be lfe */
2181 lfe_pin = pin;
2182 }
2183 }
2184 }
2185
2186 if (lfe_pin) {
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002187 err = create_controls(spec, "LFE", lfe_pin, 1);
Richard Fish160ea0d2006-09-06 13:58:25 +02002188 if (err < 0)
2189 return err;
2190 }
2191
2192 return 0;
2193}
2194
Mattc7d4b2f2005-06-27 14:59:41 +02002195static int stac9200_parse_auto_config(struct hda_codec *codec)
2196{
2197 struct sigmatel_spec *spec = codec->spec;
2198 int err;
2199
Kailang Yangdf694da2005-12-05 19:42:22 +01002200 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02002201 return err;
2202
2203 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
2204 return err;
2205
Takashi Iwai82bc9552006-03-21 11:24:42 +01002206 if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
2207 return err;
2208
Richard Fish160ea0d2006-09-06 13:58:25 +02002209 if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
2210 return err;
2211
Takashi Iwai82bc9552006-03-21 11:24:42 +01002212 if (spec->autocfg.dig_out_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02002213 spec->multiout.dig_out_nid = 0x05;
Takashi Iwai82bc9552006-03-21 11:24:42 +01002214 if (spec->autocfg.dig_in_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02002215 spec->dig_in_nid = 0x04;
Mattc7d4b2f2005-06-27 14:59:41 +02002216
2217 if (spec->kctl_alloc)
2218 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
2219
2220 spec->input_mux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02002221 spec->dinput_mux = &spec->private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +02002222
2223 return 1;
2224}
2225
Sam Revitch62fe78e2006-05-10 15:09:17 +02002226/*
2227 * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
2228 * funky external mute control using GPIO pins.
2229 */
2230
2231static void stac922x_gpio_mute(struct hda_codec *codec, int pin, int muted)
2232{
2233 unsigned int gpiostate, gpiomask, gpiodir;
2234
2235 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
2236 AC_VERB_GET_GPIO_DATA, 0);
2237
2238 if (!muted)
2239 gpiostate |= (1 << pin);
2240 else
2241 gpiostate &= ~(1 << pin);
2242
2243 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
2244 AC_VERB_GET_GPIO_MASK, 0);
2245 gpiomask |= (1 << pin);
2246
2247 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
2248 AC_VERB_GET_GPIO_DIRECTION, 0);
2249 gpiodir |= (1 << pin);
2250
2251 /* AppleHDA seems to do this -- WTF is this verb?? */
2252 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
2253
2254 snd_hda_codec_write(codec, codec->afg, 0,
2255 AC_VERB_SET_GPIO_MASK, gpiomask);
2256 snd_hda_codec_write(codec, codec->afg, 0,
2257 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
2258
2259 msleep(1);
2260
2261 snd_hda_codec_write(codec, codec->afg, 0,
2262 AC_VERB_SET_GPIO_DATA, gpiostate);
2263}
2264
Takashi Iwai314634b2006-09-21 11:56:18 +02002265static void enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
2266 unsigned int event)
2267{
2268 if (get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP)
Takashi Iwaidc81bed2007-09-03 09:36:36 +02002269 snd_hda_codec_write_cache(codec, nid, 0,
2270 AC_VERB_SET_UNSOLICITED_ENABLE,
2271 (AC_USRSP_EN | event));
Takashi Iwai314634b2006-09-21 11:56:18 +02002272}
2273
Mattc7d4b2f2005-06-27 14:59:41 +02002274static int stac92xx_init(struct hda_codec *codec)
2275{
2276 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai82bc9552006-03-21 11:24:42 +01002277 struct auto_pin_cfg *cfg = &spec->autocfg;
2278 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02002279
Mattc7d4b2f2005-06-27 14:59:41 +02002280 snd_hda_sequence_write(codec, spec->init);
2281
Takashi Iwai82bc9552006-03-21 11:24:42 +01002282 /* set up pins */
2283 if (spec->hp_detect) {
Takashi Iwai505cb342006-03-27 12:51:52 +02002284 /* Enable unsolicited responses on the HP widget */
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002285 for (i = 0; i < cfg->hp_outs; i++)
Takashi Iwai314634b2006-09-21 11:56:18 +02002286 enable_pin_detect(codec, cfg->hp_pins[i],
2287 STAC_HP_EVENT);
Takashi Iwai0a07aca2007-03-13 10:40:23 +01002288 /* force to enable the first line-out; the others are set up
2289 * in unsol_event
2290 */
2291 stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
2292 AC_PINCTL_OUT_EN);
Takashi Iwaieb995a82006-09-21 14:28:21 +02002293 stac92xx_auto_init_hp_out(codec);
Takashi Iwai82bc9552006-03-21 11:24:42 +01002294 /* fake event to set up pins */
2295 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
2296 } else {
2297 stac92xx_auto_init_multi_out(codec);
2298 stac92xx_auto_init_hp_out(codec);
2299 }
2300 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwaic960a032006-03-23 17:06:28 +01002301 hda_nid_t nid = cfg->input_pins[i];
2302 if (nid) {
2303 unsigned int pinctl = AC_PINCTL_IN_EN;
2304 if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC)
2305 pinctl |= stac92xx_get_vref(codec, nid);
2306 stac92xx_auto_set_pinctl(codec, nid, pinctl);
2307 }
Takashi Iwai82bc9552006-03-21 11:24:42 +01002308 }
Matt Porter8b657272006-10-26 17:12:59 +02002309 if (spec->num_dmics > 0)
2310 for (i = 0; i < spec->num_dmics; i++)
2311 stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
2312 AC_PINCTL_IN_EN);
2313
Takashi Iwai82bc9552006-03-21 11:24:42 +01002314 if (cfg->dig_out_pin)
2315 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pin,
2316 AC_PINCTL_OUT_EN);
2317 if (cfg->dig_in_pin)
2318 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
2319 AC_PINCTL_IN_EN);
2320
Sam Revitch62fe78e2006-05-10 15:09:17 +02002321 if (spec->gpio_mute) {
2322 stac922x_gpio_mute(codec, 0, 0);
2323 stac922x_gpio_mute(codec, 1, 0);
2324 }
2325
Mattc7d4b2f2005-06-27 14:59:41 +02002326 return 0;
2327}
2328
Matt2f2f4252005-04-13 14:45:30 +02002329static void stac92xx_free(struct hda_codec *codec)
2330{
Mattc7d4b2f2005-06-27 14:59:41 +02002331 struct sigmatel_spec *spec = codec->spec;
2332 int i;
2333
2334 if (! spec)
2335 return;
2336
2337 if (spec->kctl_alloc) {
2338 for (i = 0; i < spec->num_kctl_used; i++)
2339 kfree(spec->kctl_alloc[i].name);
2340 kfree(spec->kctl_alloc);
2341 }
2342
Richard Fish11b44bb2006-08-23 18:31:34 +02002343 if (spec->bios_pin_configs)
2344 kfree(spec->bios_pin_configs);
2345
Mattc7d4b2f2005-06-27 14:59:41 +02002346 kfree(spec);
Matt2f2f4252005-04-13 14:45:30 +02002347}
2348
Matt4e550962005-07-04 17:51:39 +02002349static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
2350 unsigned int flag)
2351{
2352 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
2353 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Steve Longerbeam7b043892007-05-03 20:50:03 +02002354
Takashi Iwaif9acba42007-05-29 18:01:06 +02002355 if (pin_ctl & AC_PINCTL_IN_EN) {
2356 /*
2357 * we need to check the current set-up direction of
2358 * shared input pins since they can be switched via
2359 * "xxx as Output" mixer switch
2360 */
2361 struct sigmatel_spec *spec = codec->spec;
2362 struct auto_pin_cfg *cfg = &spec->autocfg;
2363 if ((nid == cfg->input_pins[AUTO_PIN_LINE] &&
2364 spec->line_switch) ||
2365 (nid == cfg->input_pins[AUTO_PIN_MIC] &&
2366 spec->mic_switch))
2367 return;
2368 }
2369
Steve Longerbeam7b043892007-05-03 20:50:03 +02002370 /* if setting pin direction bits, clear the current
2371 direction bits first */
2372 if (flag & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))
2373 pin_ctl &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
2374
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002375 snd_hda_codec_write_cache(codec, nid, 0,
Matt4e550962005-07-04 17:51:39 +02002376 AC_VERB_SET_PIN_WIDGET_CONTROL,
2377 pin_ctl | flag);
2378}
2379
2380static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
2381 unsigned int flag)
2382{
2383 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
2384 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002385 snd_hda_codec_write_cache(codec, nid, 0,
Matt4e550962005-07-04 17:51:39 +02002386 AC_VERB_SET_PIN_WIDGET_CONTROL,
2387 pin_ctl & ~flag);
2388}
2389
Takashi Iwai314634b2006-09-21 11:56:18 +02002390static int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
2391{
2392 if (!nid)
2393 return 0;
2394 if (snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PIN_SENSE, 0x00)
2395 & (1 << 31))
2396 return 1;
2397 return 0;
2398}
2399
2400static void stac92xx_hp_detect(struct hda_codec *codec, unsigned int res)
Matt4e550962005-07-04 17:51:39 +02002401{
2402 struct sigmatel_spec *spec = codec->spec;
2403 struct auto_pin_cfg *cfg = &spec->autocfg;
2404 int i, presence;
2405
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002406 presence = 0;
2407 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai314634b2006-09-21 11:56:18 +02002408 presence = get_pin_presence(codec, cfg->hp_pins[i]);
2409 if (presence)
2410 break;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002411 }
Matt4e550962005-07-04 17:51:39 +02002412
2413 if (presence) {
2414 /* disable lineouts, enable hp */
2415 for (i = 0; i < cfg->line_outs; i++)
2416 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
2417 AC_PINCTL_OUT_EN);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002418 for (i = 0; i < cfg->speaker_outs; i++)
2419 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
2420 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02002421 } else {
2422 /* enable lineouts, disable hp */
2423 for (i = 0; i < cfg->line_outs; i++)
2424 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
2425 AC_PINCTL_OUT_EN);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002426 for (i = 0; i < cfg->speaker_outs; i++)
2427 stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
2428 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02002429 }
2430}
2431
Takashi Iwai314634b2006-09-21 11:56:18 +02002432static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
2433{
2434 switch (res >> 26) {
2435 case STAC_HP_EVENT:
2436 stac92xx_hp_detect(codec, res);
2437 break;
2438 }
2439}
2440
Takashi Iwaicb53c622007-08-10 17:21:45 +02002441#ifdef SND_HDA_NEEDS_RESUME
Mattff6fdc32005-06-27 15:06:52 +02002442static int stac92xx_resume(struct hda_codec *codec)
2443{
Takashi Iwaidc81bed2007-09-03 09:36:36 +02002444 struct sigmatel_spec *spec = codec->spec;
2445
Richard Fish11b44bb2006-08-23 18:31:34 +02002446 stac92xx_set_config_regs(codec);
Takashi Iwaidc81bed2007-09-03 09:36:36 +02002447 snd_hda_sequence_write(codec, spec->init);
2448 if (spec->gpio_mute) {
2449 stac922x_gpio_mute(codec, 0, 0);
2450 stac922x_gpio_mute(codec, 1, 0);
2451 }
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002452 snd_hda_codec_resume_amp(codec);
2453 snd_hda_codec_resume_cache(codec);
Takashi Iwaidc81bed2007-09-03 09:36:36 +02002454 /* invoke unsolicited event to reset the HP state */
2455 if (spec->hp_detect)
2456 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
Mattff6fdc32005-06-27 15:06:52 +02002457 return 0;
2458}
2459#endif
2460
Matt2f2f4252005-04-13 14:45:30 +02002461static struct hda_codec_ops stac92xx_patch_ops = {
2462 .build_controls = stac92xx_build_controls,
2463 .build_pcms = stac92xx_build_pcms,
2464 .init = stac92xx_init,
2465 .free = stac92xx_free,
Matt4e550962005-07-04 17:51:39 +02002466 .unsol_event = stac92xx_unsol_event,
Takashi Iwaicb53c622007-08-10 17:21:45 +02002467#ifdef SND_HDA_NEEDS_RESUME
Mattff6fdc32005-06-27 15:06:52 +02002468 .resume = stac92xx_resume,
2469#endif
Matt2f2f4252005-04-13 14:45:30 +02002470};
2471
2472static int patch_stac9200(struct hda_codec *codec)
2473{
2474 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02002475 int err;
Matt2f2f4252005-04-13 14:45:30 +02002476
Takashi Iwaie560d8d2005-09-09 14:21:46 +02002477 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02002478 if (spec == NULL)
2479 return -ENOMEM;
2480
2481 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02002482 spec->num_pins = ARRAY_SIZE(stac9200_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02002483 spec->pin_nids = stac9200_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002484 spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS,
2485 stac9200_models,
2486 stac9200_cfg_tbl);
Richard Fish11b44bb2006-08-23 18:31:34 +02002487 if (spec->board_config < 0) {
2488 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9200, using BIOS defaults\n");
2489 err = stac92xx_save_bios_config_regs(codec);
2490 if (err < 0) {
2491 stac92xx_free(codec);
2492 return err;
2493 }
2494 spec->pin_configs = spec->bios_pin_configs;
2495 } else {
Matt Porter403d1942005-11-29 15:00:51 +01002496 spec->pin_configs = stac9200_brd_tbl[spec->board_config];
2497 stac92xx_set_config_regs(codec);
2498 }
Matt2f2f4252005-04-13 14:45:30 +02002499
2500 spec->multiout.max_channels = 2;
2501 spec->multiout.num_dacs = 1;
2502 spec->multiout.dac_nids = stac9200_dac_nids;
2503 spec->adc_nids = stac9200_adc_nids;
2504 spec->mux_nids = stac9200_mux_nids;
Mattdabbed62005-06-14 10:19:34 +02002505 spec->num_muxes = 1;
Matt Porter8b657272006-10-26 17:12:59 +02002506 spec->num_dmics = 0;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002507 spec->num_adcs = 1;
Mattc7d4b2f2005-06-27 14:59:41 +02002508
Takashi Iwai1194b5b2007-10-10 10:04:26 +02002509 if (spec->board_config == STAC_9200_GATEWAY)
2510 spec->init = stac9200_eapd_init;
2511 else
2512 spec->init = stac9200_core_init;
Matt2f2f4252005-04-13 14:45:30 +02002513 spec->mixer = stac9200_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02002514
2515 err = stac9200_parse_auto_config(codec);
2516 if (err < 0) {
2517 stac92xx_free(codec);
2518 return err;
2519 }
Matt2f2f4252005-04-13 14:45:30 +02002520
2521 codec->patch_ops = stac92xx_patch_ops;
2522
2523 return 0;
2524}
2525
Tobin Davis8e21c342007-01-08 11:04:17 +01002526static int patch_stac925x(struct hda_codec *codec)
2527{
2528 struct sigmatel_spec *spec;
2529 int err;
2530
2531 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2532 if (spec == NULL)
2533 return -ENOMEM;
2534
2535 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02002536 spec->num_pins = ARRAY_SIZE(stac925x_pin_nids);
Tobin Davis8e21c342007-01-08 11:04:17 +01002537 spec->pin_nids = stac925x_pin_nids;
2538 spec->board_config = snd_hda_check_board_config(codec, STAC_925x_MODELS,
2539 stac925x_models,
2540 stac925x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002541 again:
Tobin Davis8e21c342007-01-08 11:04:17 +01002542 if (spec->board_config < 0) {
Tobin Davis2c11f952007-05-17 09:36:34 +02002543 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC925x,"
2544 "using BIOS defaults\n");
Tobin Davis8e21c342007-01-08 11:04:17 +01002545 err = stac92xx_save_bios_config_regs(codec);
2546 if (err < 0) {
2547 stac92xx_free(codec);
2548 return err;
2549 }
2550 spec->pin_configs = spec->bios_pin_configs;
2551 } else if (stac925x_brd_tbl[spec->board_config] != NULL){
2552 spec->pin_configs = stac925x_brd_tbl[spec->board_config];
2553 stac92xx_set_config_regs(codec);
2554 }
2555
2556 spec->multiout.max_channels = 2;
2557 spec->multiout.num_dacs = 1;
2558 spec->multiout.dac_nids = stac925x_dac_nids;
2559 spec->adc_nids = stac925x_adc_nids;
2560 spec->mux_nids = stac925x_mux_nids;
2561 spec->num_muxes = 1;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002562 spec->num_adcs = 1;
Tobin Davis2c11f952007-05-17 09:36:34 +02002563 switch (codec->vendor_id) {
2564 case 0x83847632: /* STAC9202 */
2565 case 0x83847633: /* STAC9202D */
2566 case 0x83847636: /* STAC9251 */
2567 case 0x83847637: /* STAC9251D */
2568 spec->num_dmics = 1;
2569 spec->dmic_nids = stac925x_dmic_nids;
2570 break;
2571 default:
2572 spec->num_dmics = 0;
2573 break;
2574 }
Tobin Davis8e21c342007-01-08 11:04:17 +01002575
2576 spec->init = stac925x_core_init;
2577 spec->mixer = stac925x_mixer;
2578
2579 err = stac92xx_parse_auto_config(codec, 0x8, 0x7);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002580 if (!err) {
2581 if (spec->board_config < 0) {
2582 printk(KERN_WARNING "hda_codec: No auto-config is "
2583 "available, default to model=ref\n");
2584 spec->board_config = STAC_925x_REF;
2585 goto again;
2586 }
2587 err = -EINVAL;
2588 }
Tobin Davis8e21c342007-01-08 11:04:17 +01002589 if (err < 0) {
2590 stac92xx_free(codec);
2591 return err;
2592 }
2593
2594 codec->patch_ops = stac92xx_patch_ops;
2595
2596 return 0;
2597}
2598
Matt2f2f4252005-04-13 14:45:30 +02002599static int patch_stac922x(struct hda_codec *codec)
2600{
2601 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02002602 int err;
Matt2f2f4252005-04-13 14:45:30 +02002603
Takashi Iwaie560d8d2005-09-09 14:21:46 +02002604 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02002605 if (spec == NULL)
2606 return -ENOMEM;
2607
2608 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02002609 spec->num_pins = ARRAY_SIZE(stac922x_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02002610 spec->pin_nids = stac922x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002611 spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS,
2612 stac922x_models,
2613 stac922x_cfg_tbl);
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002614 if (spec->board_config == STAC_INTEL_MAC_V3) {
Takashi Iwai3fc24d82007-02-16 13:27:18 +01002615 spec->gpio_mute = 1;
2616 /* Intel Macs have all same PCI SSID, so we need to check
2617 * codec SSID to distinguish the exact models
2618 */
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01002619 printk(KERN_INFO "hda_codec: STAC922x, Apple subsys_id=%x\n", codec->subsystem_id);
Takashi Iwai3fc24d82007-02-16 13:27:18 +01002620 switch (codec->subsystem_id) {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002621
2622 case 0x106b0800:
2623 spec->board_config = STAC_INTEL_MAC_V1;
Abhijit Bhopatkarc45e20e2007-04-17 11:57:16 +02002624 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002625 case 0x106b0600:
2626 case 0x106b0700:
2627 spec->board_config = STAC_INTEL_MAC_V2;
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01002628 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002629 case 0x106b0e00:
2630 case 0x106b0f00:
2631 case 0x106b1600:
2632 case 0x106b1700:
2633 case 0x106b0200:
2634 case 0x106b1e00:
2635 spec->board_config = STAC_INTEL_MAC_V3;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01002636 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002637 case 0x106b1a00:
2638 case 0x00000100:
2639 spec->board_config = STAC_INTEL_MAC_V4;
Sylvain FORETf16928f2007-04-27 14:22:36 +02002640 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002641 case 0x106b0a00:
2642 case 0x106b2200:
2643 spec->board_config = STAC_INTEL_MAC_V5;
Takashi Iwai0dae0f82007-05-21 12:41:29 +02002644 break;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01002645 }
2646 }
2647
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002648 again:
Richard Fish11b44bb2006-08-23 18:31:34 +02002649 if (spec->board_config < 0) {
2650 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC922x, "
2651 "using BIOS defaults\n");
2652 err = stac92xx_save_bios_config_regs(codec);
2653 if (err < 0) {
2654 stac92xx_free(codec);
2655 return err;
2656 }
2657 spec->pin_configs = spec->bios_pin_configs;
2658 } else if (stac922x_brd_tbl[spec->board_config] != NULL) {
Matt Porter403d1942005-11-29 15:00:51 +01002659 spec->pin_configs = stac922x_brd_tbl[spec->board_config];
2660 stac92xx_set_config_regs(codec);
2661 }
Matt2f2f4252005-04-13 14:45:30 +02002662
Matt2f2f4252005-04-13 14:45:30 +02002663 spec->adc_nids = stac922x_adc_nids;
2664 spec->mux_nids = stac922x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01002665 spec->num_muxes = ARRAY_SIZE(stac922x_mux_nids);
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002666 spec->num_adcs = ARRAY_SIZE(stac922x_adc_nids);
Matt Porter8b657272006-10-26 17:12:59 +02002667 spec->num_dmics = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02002668
2669 spec->init = stac922x_core_init;
Matt2f2f4252005-04-13 14:45:30 +02002670 spec->mixer = stac922x_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02002671
2672 spec->multiout.dac_nids = spec->dac_nids;
Takashi Iwai19039bd2006-06-28 15:52:16 +02002673
Matt Porter3cc08dc2006-01-23 15:27:49 +01002674 err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002675 if (!err) {
2676 if (spec->board_config < 0) {
2677 printk(KERN_WARNING "hda_codec: No auto-config is "
2678 "available, default to model=ref\n");
2679 spec->board_config = STAC_D945_REF;
2680 goto again;
2681 }
2682 err = -EINVAL;
2683 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01002684 if (err < 0) {
2685 stac92xx_free(codec);
2686 return err;
2687 }
2688
2689 codec->patch_ops = stac92xx_patch_ops;
2690
Takashi Iwai807a46362007-05-29 19:01:37 +02002691 /* Fix Mux capture level; max to 2 */
2692 snd_hda_override_amp_caps(codec, 0x12, HDA_OUTPUT,
2693 (0 << AC_AMPCAP_OFFSET_SHIFT) |
2694 (2 << AC_AMPCAP_NUM_STEPS_SHIFT) |
2695 (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
2696 (0 << AC_AMPCAP_MUTE_SHIFT));
2697
Matt Porter3cc08dc2006-01-23 15:27:49 +01002698 return 0;
2699}
2700
2701static int patch_stac927x(struct hda_codec *codec)
2702{
2703 struct sigmatel_spec *spec;
2704 int err;
2705
2706 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2707 if (spec == NULL)
2708 return -ENOMEM;
2709
2710 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02002711 spec->num_pins = ARRAY_SIZE(stac927x_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02002712 spec->pin_nids = stac927x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002713 spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS,
2714 stac927x_models,
2715 stac927x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002716 again:
Richard Fish11b44bb2006-08-23 18:31:34 +02002717 if (spec->board_config < 0) {
Matt Porter3cc08dc2006-01-23 15:27:49 +01002718 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC927x, using BIOS defaults\n");
Richard Fish11b44bb2006-08-23 18:31:34 +02002719 err = stac92xx_save_bios_config_regs(codec);
2720 if (err < 0) {
2721 stac92xx_free(codec);
2722 return err;
2723 }
2724 spec->pin_configs = spec->bios_pin_configs;
2725 } else if (stac927x_brd_tbl[spec->board_config] != NULL) {
Matt Porter3cc08dc2006-01-23 15:27:49 +01002726 spec->pin_configs = stac927x_brd_tbl[spec->board_config];
2727 stac92xx_set_config_regs(codec);
2728 }
2729
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002730 switch (spec->board_config) {
Tobin Davis93ed1502006-09-01 21:03:12 +02002731 case STAC_D965_3ST:
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002732 spec->adc_nids = stac927x_adc_nids;
2733 spec->mux_nids = stac927x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01002734 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002735 spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
Matt Porter8b657272006-10-26 17:12:59 +02002736 spec->num_dmics = 0;
Tobin Davis93ed1502006-09-01 21:03:12 +02002737 spec->init = d965_core_init;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002738 spec->mixer = stac927x_mixer;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002739 break;
Tobin Davis93ed1502006-09-01 21:03:12 +02002740 case STAC_D965_5ST:
2741 spec->adc_nids = stac927x_adc_nids;
2742 spec->mux_nids = stac927x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01002743 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002744 spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
Matt Porter8b657272006-10-26 17:12:59 +02002745 spec->num_dmics = 0;
Tobin Davis93ed1502006-09-01 21:03:12 +02002746 spec->init = d965_core_init;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002747 spec->mixer = stac927x_mixer;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002748 break;
2749 default:
2750 spec->adc_nids = stac927x_adc_nids;
2751 spec->mux_nids = stac927x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01002752 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002753 spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
Matt Porter8b657272006-10-26 17:12:59 +02002754 spec->num_dmics = 0;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002755 spec->init = stac927x_core_init;
2756 spec->mixer = stac927x_mixer;
2757 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01002758
2759 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostay87d48362007-07-17 11:52:24 +02002760 /* GPIO0 High = Enable EAPD */
Takashi Iwai82599802007-07-31 15:56:24 +02002761 spec->gpio_mask = spec->gpio_data = 0x00000001;
2762 stac92xx_enable_gpio_mask(codec);
Matthew Ranostay92a22be2007-06-19 16:48:28 +02002763
Matt Porter3cc08dc2006-01-23 15:27:49 +01002764 err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002765 if (!err) {
2766 if (spec->board_config < 0) {
2767 printk(KERN_WARNING "hda_codec: No auto-config is "
2768 "available, default to model=ref\n");
2769 spec->board_config = STAC_D965_REF;
2770 goto again;
2771 }
2772 err = -EINVAL;
2773 }
Mattc7d4b2f2005-06-27 14:59:41 +02002774 if (err < 0) {
2775 stac92xx_free(codec);
2776 return err;
2777 }
Matt2f2f4252005-04-13 14:45:30 +02002778
2779 codec->patch_ops = stac92xx_patch_ops;
2780
2781 return 0;
2782}
2783
Matt Porterf3302a52006-07-31 12:49:34 +02002784static int patch_stac9205(struct hda_codec *codec)
2785{
2786 struct sigmatel_spec *spec;
Takashi Iwai82599802007-07-31 15:56:24 +02002787 int err;
Matt Porterf3302a52006-07-31 12:49:34 +02002788
2789 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2790 if (spec == NULL)
2791 return -ENOMEM;
2792
2793 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02002794 spec->num_pins = ARRAY_SIZE(stac9205_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02002795 spec->pin_nids = stac9205_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002796 spec->board_config = snd_hda_check_board_config(codec, STAC_9205_MODELS,
2797 stac9205_models,
2798 stac9205_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002799 again:
Richard Fish11b44bb2006-08-23 18:31:34 +02002800 if (spec->board_config < 0) {
2801 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9205, using BIOS defaults\n");
2802 err = stac92xx_save_bios_config_regs(codec);
2803 if (err < 0) {
2804 stac92xx_free(codec);
2805 return err;
2806 }
2807 spec->pin_configs = spec->bios_pin_configs;
2808 } else {
Matt Porterf3302a52006-07-31 12:49:34 +02002809 spec->pin_configs = stac9205_brd_tbl[spec->board_config];
2810 stac92xx_set_config_regs(codec);
2811 }
2812
2813 spec->adc_nids = stac9205_adc_nids;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002814 spec->num_adcs = ARRAY_SIZE(stac9205_adc_nids);
Matt Porterf3302a52006-07-31 12:49:34 +02002815 spec->mux_nids = stac9205_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01002816 spec->num_muxes = ARRAY_SIZE(stac9205_mux_nids);
Matt Porter8b657272006-10-26 17:12:59 +02002817 spec->dmic_nids = stac9205_dmic_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01002818 spec->num_dmics = ARRAY_SIZE(stac9205_dmic_nids);
Matt Porter8b657272006-10-26 17:12:59 +02002819 spec->dmux_nid = 0x1d;
Matt Porterf3302a52006-07-31 12:49:34 +02002820
2821 spec->init = stac9205_core_init;
2822 spec->mixer = stac9205_mixer;
2823
2824 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostay87d48362007-07-17 11:52:24 +02002825
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002826 switch (spec->board_config){
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002827 case STAC_9205_DELL_M43:
Matthew Ranostay87d48362007-07-17 11:52:24 +02002828 /* Enable SPDIF in/out */
2829 stac92xx_set_config_reg(codec, 0x1f, 0x01441030);
2830 stac92xx_set_config_reg(codec, 0x20, 0x1c410030);
Matt Porter33382402006-12-18 13:17:28 +01002831
Takashi Iwai82599802007-07-31 15:56:24 +02002832 spec->gpio_mask = 0x00000007; /* GPIO0-2 */
Matthew Ranostay87d48362007-07-17 11:52:24 +02002833 /* GPIO0 High = EAPD, GPIO1 Low = DRM,
2834 * GPIO2 High = Headphone Mute
2835 */
Takashi Iwai82599802007-07-31 15:56:24 +02002836 spec->gpio_data = 0x00000005;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002837 break;
2838 default:
2839 /* GPIO0 High = EAPD */
2840 spec->gpio_mask = spec->gpio_data = 0x00000001;
2841 break;
2842 }
Matthew Ranostay87d48362007-07-17 11:52:24 +02002843
Takashi Iwai82599802007-07-31 15:56:24 +02002844 stac92xx_enable_gpio_mask(codec);
Matt Porterf3302a52006-07-31 12:49:34 +02002845 err = stac92xx_parse_auto_config(codec, 0x1f, 0x20);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002846 if (!err) {
2847 if (spec->board_config < 0) {
2848 printk(KERN_WARNING "hda_codec: No auto-config is "
2849 "available, default to model=ref\n");
2850 spec->board_config = STAC_9205_REF;
2851 goto again;
2852 }
2853 err = -EINVAL;
2854 }
Matt Porterf3302a52006-07-31 12:49:34 +02002855 if (err < 0) {
2856 stac92xx_free(codec);
2857 return err;
2858 }
2859
2860 codec->patch_ops = stac92xx_patch_ops;
2861
2862 return 0;
2863}
2864
Matt2f2f4252005-04-13 14:45:30 +02002865/*
Guillaume Munch6d859062006-08-22 17:15:47 +02002866 * STAC9872 hack
Takashi Iwaidb064e52006-03-16 16:04:58 +01002867 */
2868
Guillaume Munch99ccc562006-08-16 19:35:12 +02002869/* static config for Sony VAIO FE550G and Sony VAIO AR */
Takashi Iwaidb064e52006-03-16 16:04:58 +01002870static hda_nid_t vaio_dacs[] = { 0x2 };
2871#define VAIO_HP_DAC 0x5
2872static hda_nid_t vaio_adcs[] = { 0x8 /*,0x6*/ };
2873static hda_nid_t vaio_mux_nids[] = { 0x15 };
2874
2875static struct hda_input_mux vaio_mux = {
2876 .num_items = 2,
2877 .items = {
Takashi Iwaid7737812006-04-25 13:05:43 +02002878 /* { "HP", 0x0 }, */
Takashi Iwai1624cb92007-07-05 13:10:51 +02002879 { "Mic Jack", 0x1 },
2880 { "Internal Mic", 0x2 },
Takashi Iwaidb064e52006-03-16 16:04:58 +01002881 { "PCM", 0x3 },
2882 }
2883};
2884
2885static struct hda_verb vaio_init[] = {
2886 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
Takashi Iwai72e7b0d2007-08-16 17:33:55 +02002887 {0x0a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | STAC_HP_EVENT},
Takashi Iwaidb064e52006-03-16 16:04:58 +01002888 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
2889 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
2890 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
2891 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
Takashi Iwai1624cb92007-07-05 13:10:51 +02002892 {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
Takashi Iwaidb064e52006-03-16 16:04:58 +01002893 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
2894 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
2895 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
2896 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
2897 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
2898 {}
2899};
2900
Guillaume Munch6d859062006-08-22 17:15:47 +02002901static struct hda_verb vaio_ar_init[] = {
2902 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
2903 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
2904 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
2905 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
2906/* {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },*/ /* Optical Out */
2907 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
Takashi Iwai1624cb92007-07-05 13:10:51 +02002908 {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
Guillaume Munch6d859062006-08-22 17:15:47 +02002909 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
2910 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
2911/* {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},*/ /* Optical Out */
2912 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
2913 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
2914 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
2915 {}
2916};
2917
Takashi Iwaidb064e52006-03-16 16:04:58 +01002918/* bind volumes of both NID 0x02 and 0x05 */
Takashi Iwaicca3b372007-08-10 17:12:15 +02002919static struct hda_bind_ctls vaio_bind_master_vol = {
2920 .ops = &snd_hda_bind_vol,
2921 .values = {
2922 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2923 HDA_COMPOSE_AMP_VAL(0x05, 3, 0, HDA_OUTPUT),
2924 0
2925 },
2926};
Takashi Iwaidb064e52006-03-16 16:04:58 +01002927
2928/* bind volumes of both NID 0x02 and 0x05 */
Takashi Iwaicca3b372007-08-10 17:12:15 +02002929static struct hda_bind_ctls vaio_bind_master_sw = {
2930 .ops = &snd_hda_bind_sw,
2931 .values = {
2932 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2933 HDA_COMPOSE_AMP_VAL(0x05, 3, 0, HDA_OUTPUT),
2934 0,
2935 },
2936};
Takashi Iwaidb064e52006-03-16 16:04:58 +01002937
2938static struct snd_kcontrol_new vaio_mixer[] = {
Takashi Iwaicca3b372007-08-10 17:12:15 +02002939 HDA_BIND_VOL("Master Playback Volume", &vaio_bind_master_vol),
2940 HDA_BIND_SW("Master Playback Switch", &vaio_bind_master_sw),
Takashi Iwaidb064e52006-03-16 16:04:58 +01002941 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
2942 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
2943 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
2944 {
2945 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2946 .name = "Capture Source",
2947 .count = 1,
2948 .info = stac92xx_mux_enum_info,
2949 .get = stac92xx_mux_enum_get,
2950 .put = stac92xx_mux_enum_put,
2951 },
2952 {}
2953};
2954
Guillaume Munch6d859062006-08-22 17:15:47 +02002955static struct snd_kcontrol_new vaio_ar_mixer[] = {
Takashi Iwaicca3b372007-08-10 17:12:15 +02002956 HDA_BIND_VOL("Master Playback Volume", &vaio_bind_master_vol),
2957 HDA_BIND_SW("Master Playback Switch", &vaio_bind_master_sw),
Guillaume Munch6d859062006-08-22 17:15:47 +02002958 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
2959 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
2960 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
2961 /*HDA_CODEC_MUTE("Optical Out Switch", 0x10, 0, HDA_OUTPUT),
2962 HDA_CODEC_VOLUME("Optical Out Volume", 0x10, 0, HDA_OUTPUT),*/
2963 {
2964 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2965 .name = "Capture Source",
2966 .count = 1,
2967 .info = stac92xx_mux_enum_info,
2968 .get = stac92xx_mux_enum_get,
2969 .put = stac92xx_mux_enum_put,
2970 },
2971 {}
2972};
2973
2974static struct hda_codec_ops stac9872_patch_ops = {
Takashi Iwaidb064e52006-03-16 16:04:58 +01002975 .build_controls = stac92xx_build_controls,
2976 .build_pcms = stac92xx_build_pcms,
2977 .init = stac92xx_init,
2978 .free = stac92xx_free,
Takashi Iwaicb53c622007-08-10 17:21:45 +02002979#ifdef SND_HDA_NEEDS_RESUME
Takashi Iwaidb064e52006-03-16 16:04:58 +01002980 .resume = stac92xx_resume,
2981#endif
2982};
2983
Takashi Iwai72e7b0d2007-08-16 17:33:55 +02002984static int stac9872_vaio_init(struct hda_codec *codec)
2985{
2986 int err;
2987
2988 err = stac92xx_init(codec);
2989 if (err < 0)
2990 return err;
2991 if (codec->patch_ops.unsol_event)
2992 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
2993 return 0;
2994}
2995
2996static void stac9872_vaio_hp_detect(struct hda_codec *codec, unsigned int res)
2997{
2998 if (get_pin_presence(codec, 0x0a)) {
2999 stac92xx_reset_pinctl(codec, 0x0f, AC_PINCTL_OUT_EN);
3000 stac92xx_set_pinctl(codec, 0x0a, AC_PINCTL_OUT_EN);
3001 } else {
3002 stac92xx_reset_pinctl(codec, 0x0a, AC_PINCTL_OUT_EN);
3003 stac92xx_set_pinctl(codec, 0x0f, AC_PINCTL_OUT_EN);
3004 }
3005}
3006
3007static void stac9872_vaio_unsol_event(struct hda_codec *codec, unsigned int res)
3008{
3009 switch (res >> 26) {
3010 case STAC_HP_EVENT:
3011 stac9872_vaio_hp_detect(codec, res);
3012 break;
3013 }
3014}
3015
3016static struct hda_codec_ops stac9872_vaio_patch_ops = {
3017 .build_controls = stac92xx_build_controls,
3018 .build_pcms = stac92xx_build_pcms,
3019 .init = stac9872_vaio_init,
3020 .free = stac92xx_free,
3021 .unsol_event = stac9872_vaio_unsol_event,
3022#ifdef CONFIG_PM
3023 .resume = stac92xx_resume,
3024#endif
3025};
3026
Guillaume Munch6d859062006-08-22 17:15:47 +02003027enum { /* FE and SZ series. id=0x83847661 and subsys=0x104D0700 or 104D1000. */
3028 CXD9872RD_VAIO,
3029 /* Unknown. id=0x83847662 and subsys=0x104D1200 or 104D1000. */
3030 STAC9872AK_VAIO,
3031 /* Unknown. id=0x83847661 and subsys=0x104D1200. */
3032 STAC9872K_VAIO,
3033 /* AR Series. id=0x83847664 and subsys=104D1300 */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01003034 CXD9872AKD_VAIO,
3035 STAC_9872_MODELS,
3036};
Takashi Iwaidb064e52006-03-16 16:04:58 +01003037
Takashi Iwaif5fcc132006-11-24 17:07:44 +01003038static const char *stac9872_models[STAC_9872_MODELS] = {
3039 [CXD9872RD_VAIO] = "vaio",
3040 [CXD9872AKD_VAIO] = "vaio-ar",
3041};
3042
3043static struct snd_pci_quirk stac9872_cfg_tbl[] = {
3044 SND_PCI_QUIRK(0x104d, 0x81e6, "Sony VAIO F/S", CXD9872RD_VAIO),
3045 SND_PCI_QUIRK(0x104d, 0x81ef, "Sony VAIO F/S", CXD9872RD_VAIO),
3046 SND_PCI_QUIRK(0x104d, 0x81fd, "Sony VAIO AR", CXD9872AKD_VAIO),
Tobin Davis68e22542007-03-12 11:36:39 +01003047 SND_PCI_QUIRK(0x104d, 0x8205, "Sony VAIO AR", CXD9872AKD_VAIO),
Takashi Iwaidb064e52006-03-16 16:04:58 +01003048 {}
3049};
3050
Guillaume Munch6d859062006-08-22 17:15:47 +02003051static int patch_stac9872(struct hda_codec *codec)
Takashi Iwaidb064e52006-03-16 16:04:58 +01003052{
3053 struct sigmatel_spec *spec;
3054 int board_config;
3055
Takashi Iwaif5fcc132006-11-24 17:07:44 +01003056 board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
3057 stac9872_models,
3058 stac9872_cfg_tbl);
Takashi Iwaidb064e52006-03-16 16:04:58 +01003059 if (board_config < 0)
3060 /* unknown config, let generic-parser do its job... */
3061 return snd_hda_parse_generic_codec(codec);
3062
3063 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3064 if (spec == NULL)
3065 return -ENOMEM;
3066
3067 codec->spec = spec;
3068 switch (board_config) {
Guillaume Munch6d859062006-08-22 17:15:47 +02003069 case CXD9872RD_VAIO:
3070 case STAC9872AK_VAIO:
3071 case STAC9872K_VAIO:
Takashi Iwaidb064e52006-03-16 16:04:58 +01003072 spec->mixer = vaio_mixer;
3073 spec->init = vaio_init;
3074 spec->multiout.max_channels = 2;
3075 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
3076 spec->multiout.dac_nids = vaio_dacs;
3077 spec->multiout.hp_nid = VAIO_HP_DAC;
3078 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
3079 spec->adc_nids = vaio_adcs;
3080 spec->input_mux = &vaio_mux;
3081 spec->mux_nids = vaio_mux_nids;
Takashi Iwai72e7b0d2007-08-16 17:33:55 +02003082 codec->patch_ops = stac9872_vaio_patch_ops;
Takashi Iwaidb064e52006-03-16 16:04:58 +01003083 break;
Guillaume Munch6d859062006-08-22 17:15:47 +02003084
3085 case CXD9872AKD_VAIO:
3086 spec->mixer = vaio_ar_mixer;
3087 spec->init = vaio_ar_init;
3088 spec->multiout.max_channels = 2;
3089 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
3090 spec->multiout.dac_nids = vaio_dacs;
3091 spec->multiout.hp_nid = VAIO_HP_DAC;
3092 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
3093 spec->adc_nids = vaio_adcs;
3094 spec->input_mux = &vaio_mux;
3095 spec->mux_nids = vaio_mux_nids;
Takashi Iwai72e7b0d2007-08-16 17:33:55 +02003096 codec->patch_ops = stac9872_patch_ops;
Guillaume Munch6d859062006-08-22 17:15:47 +02003097 break;
Takashi Iwaidb064e52006-03-16 16:04:58 +01003098 }
3099
Takashi Iwaidb064e52006-03-16 16:04:58 +01003100 return 0;
3101}
3102
3103
3104/*
Matt2f2f4252005-04-13 14:45:30 +02003105 * patch entries
3106 */
3107struct hda_codec_preset snd_hda_preset_sigmatel[] = {
3108 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
3109 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
3110 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
3111 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
3112 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
3113 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
3114 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
Matt Porter22a27c72006-07-06 18:49:10 +02003115 { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
3116 { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
3117 { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
3118 { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
3119 { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
3120 { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
Matt Porter3cc08dc2006-01-23 15:27:49 +01003121 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
3122 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
3123 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
3124 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
3125 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
3126 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
3127 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
3128 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
3129 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
3130 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
Tobin Davis8e21c342007-01-08 11:04:17 +01003131 { .id = 0x83847632, .name = "STAC9202", .patch = patch_stac925x },
3132 { .id = 0x83847633, .name = "STAC9202D", .patch = patch_stac925x },
3133 { .id = 0x83847634, .name = "STAC9250", .patch = patch_stac925x },
3134 { .id = 0x83847635, .name = "STAC9250D", .patch = patch_stac925x },
3135 { .id = 0x83847636, .name = "STAC9251", .patch = patch_stac925x },
3136 { .id = 0x83847637, .name = "STAC9250D", .patch = patch_stac925x },
Guillaume Munch6d859062006-08-22 17:15:47 +02003137 /* The following does not take into account .id=0x83847661 when subsys =
3138 * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
3139 * currently not fully supported.
3140 */
3141 { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
3142 { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
3143 { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
Matt Porterf3302a52006-07-31 12:49:34 +02003144 { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
3145 { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
3146 { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
3147 { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
3148 { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
3149 { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
3150 { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
3151 { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
Matt2f2f4252005-04-13 14:45:30 +02003152 {} /* terminator */
3153};