blob: bf950195107c0a3ec4648197b7fb4f15a605dcf0 [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
Takashi Iwaif6e98522007-10-16 14:27:04 +0200186#define STAC925X_NUM_DMICS 1
187static hda_nid_t stac925x_dmic_nids[STAC925X_NUM_DMICS + 1] = {
188 0x15, 0
Tobin Davis2c11f952007-05-17 09:36:34 +0200189};
190
Matt2f2f4252005-04-13 14:45:30 +0200191static hda_nid_t stac922x_adc_nids[2] = {
192 0x06, 0x07,
193};
194
195static hda_nid_t stac922x_mux_nids[2] = {
196 0x12, 0x13,
197};
198
Matt Porter3cc08dc2006-01-23 15:27:49 +0100199static hda_nid_t stac927x_adc_nids[3] = {
200 0x07, 0x08, 0x09
201};
202
203static hda_nid_t stac927x_mux_nids[3] = {
204 0x15, 0x16, 0x17
205};
206
Matt Porterf3302a52006-07-31 12:49:34 +0200207static hda_nid_t stac9205_adc_nids[2] = {
208 0x12, 0x13
209};
210
211static hda_nid_t stac9205_mux_nids[2] = {
212 0x19, 0x1a
213};
214
Takashi Iwaif6e98522007-10-16 14:27:04 +0200215#define STAC9205_NUM_DMICS 2
216static hda_nid_t stac9205_dmic_nids[STAC9205_NUM_DMICS + 1] = {
217 0x17, 0x18, 0
Matt Porter8b657272006-10-26 17:12:59 +0200218};
219
Mattc7d4b2f2005-06-27 14:59:41 +0200220static hda_nid_t stac9200_pin_nids[8] = {
Tobin Davis93ed1502006-09-01 21:03:12 +0200221 0x08, 0x09, 0x0d, 0x0e,
222 0x0f, 0x10, 0x11, 0x12,
Matt2f2f4252005-04-13 14:45:30 +0200223};
224
Tobin Davis8e21c342007-01-08 11:04:17 +0100225static hda_nid_t stac925x_pin_nids[8] = {
226 0x07, 0x08, 0x0a, 0x0b,
227 0x0c, 0x0d, 0x10, 0x11,
228};
229
Matt2f2f4252005-04-13 14:45:30 +0200230static hda_nid_t stac922x_pin_nids[10] = {
231 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
232 0x0f, 0x10, 0x11, 0x15, 0x1b,
233};
234
Matt Porter3cc08dc2006-01-23 15:27:49 +0100235static hda_nid_t stac927x_pin_nids[14] = {
236 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
237 0x0f, 0x10, 0x11, 0x12, 0x13,
238 0x14, 0x21, 0x22, 0x23,
239};
240
Matt Porterf3302a52006-07-31 12:49:34 +0200241static hda_nid_t stac9205_pin_nids[12] = {
242 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
243 0x0f, 0x14, 0x16, 0x17, 0x18,
244 0x21, 0x22,
Matt Porterf3302a52006-07-31 12:49:34 +0200245};
246
Matt Porter8b657272006-10-26 17:12:59 +0200247static int stac92xx_dmux_enum_info(struct snd_kcontrol *kcontrol,
248 struct snd_ctl_elem_info *uinfo)
249{
250 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
251 struct sigmatel_spec *spec = codec->spec;
252 return snd_hda_input_mux_info(spec->dinput_mux, uinfo);
253}
254
255static int stac92xx_dmux_enum_get(struct snd_kcontrol *kcontrol,
256 struct snd_ctl_elem_value *ucontrol)
257{
258 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
259 struct sigmatel_spec *spec = codec->spec;
260
261 ucontrol->value.enumerated.item[0] = spec->cur_dmux;
262 return 0;
263}
264
265static int stac92xx_dmux_enum_put(struct snd_kcontrol *kcontrol,
266 struct snd_ctl_elem_value *ucontrol)
267{
268 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
269 struct sigmatel_spec *spec = codec->spec;
270
271 return snd_hda_input_mux_put(codec, spec->dinput_mux, ucontrol,
272 spec->dmux_nid, &spec->cur_dmux);
273}
274
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100275static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Matt2f2f4252005-04-13 14:45:30 +0200276{
277 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
278 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +0200279 return snd_hda_input_mux_info(spec->input_mux, uinfo);
Matt2f2f4252005-04-13 14:45:30 +0200280}
281
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100282static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200283{
284 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
285 struct sigmatel_spec *spec = codec->spec;
286 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
287
288 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
289 return 0;
290}
291
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100292static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200293{
294 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
295 struct sigmatel_spec *spec = codec->spec;
296 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
297
Mattc7d4b2f2005-06-27 14:59:41 +0200298 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
Matt2f2f4252005-04-13 14:45:30 +0200299 spec->mux_nids[adc_idx], &spec->cur_mux[adc_idx]);
300}
301
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200302#define stac92xx_aloopback_info snd_ctl_boolean_mono_info
303
304static int stac92xx_aloopback_get(struct snd_kcontrol *kcontrol,
305 struct snd_ctl_elem_value *ucontrol)
306{
307 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
308 struct sigmatel_spec *spec = codec->spec;
309
310 ucontrol->value.integer.value[0] = spec->aloopback;
311 return 0;
312}
313
314static int stac92xx_aloopback_put(struct snd_kcontrol *kcontrol,
315 struct snd_ctl_elem_value *ucontrol)
316{
317 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
318 struct sigmatel_spec *spec = codec->spec;
319 unsigned int dac_mode;
320
321 if (spec->aloopback == ucontrol->value.integer.value[0])
322 return 0;
323
324 spec->aloopback = ucontrol->value.integer.value[0];
325
326
327 dac_mode = snd_hda_codec_read(codec, codec->afg, 0,
328 kcontrol->private_value & 0xFFFF, 0x0);
329
330 if (spec->aloopback) {
331 snd_hda_power_up(codec);
332 dac_mode |= 0x40;
333 } else {
334 snd_hda_power_down(codec);
335 dac_mode &= ~0x40;
336 }
337
338 snd_hda_codec_write_cache(codec, codec->afg, 0,
339 kcontrol->private_value >> 16, dac_mode);
340
341 return 1;
342}
343
Maxim Levitsky6e6b88f2007-09-03 15:30:26 +0200344static int stac92xx_volknob_info(struct snd_kcontrol *kcontrol,
345 struct snd_ctl_elem_info *uinfo)
346{
347 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
348 uinfo->count = 1;
349 uinfo->value.integer.min = 0;
350 uinfo->value.integer.max = 127;
351 return 0;
352}
353
354static int stac92xx_volknob_get(struct snd_kcontrol *kcontrol,
355 struct snd_ctl_elem_value *ucontrol)
356{
Takashi Iwai9066f242007-10-16 14:25:16 +0200357 ucontrol->value.integer.value[0] = kcontrol->private_value & 0xff;
Maxim Levitsky6e6b88f2007-09-03 15:30:26 +0200358 return 0;
359}
360
361static int stac92xx_volknob_put(struct snd_kcontrol *kcontrol,
362 struct snd_ctl_elem_value *ucontrol)
363{
364 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Takashi Iwai9066f242007-10-16 14:25:16 +0200365 unsigned int val = kcontrol->private_value & 0xff;
Maxim Levitsky6e6b88f2007-09-03 15:30:26 +0200366
Takashi Iwai9066f242007-10-16 14:25:16 +0200367 if (val == ucontrol->value.integer.value[0])
Maxim Levitsky6e6b88f2007-09-03 15:30:26 +0200368 return 0;
369
Takashi Iwai9066f242007-10-16 14:25:16 +0200370 val = ucontrol->value.integer.value[0];
371 kcontrol->private_value &= ~0xff;
372 kcontrol->private_value |= val;
Maxim Levitsky6e6b88f2007-09-03 15:30:26 +0200373
Takashi Iwai9066f242007-10-16 14:25:16 +0200374 snd_hda_codec_write_cache(codec, kcontrol->private_value >> 16, 0,
375 AC_VERB_SET_VOLUME_KNOB_CONTROL, val | 0x80);
Maxim Levitsky6e6b88f2007-09-03 15:30:26 +0200376 return 1;
377}
378
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200379
Mattc7d4b2f2005-06-27 14:59:41 +0200380static struct hda_verb stac9200_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200381 /* set dac0mux for dac converter */
Mattc7d4b2f2005-06-27 14:59:41 +0200382 { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
Matt2f2f4252005-04-13 14:45:30 +0200383 {}
384};
385
Takashi Iwai1194b5b2007-10-10 10:04:26 +0200386static struct hda_verb stac9200_eapd_init[] = {
387 /* set dac0mux for dac converter */
388 {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
389 {0x08, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
390 {}
391};
392
Tobin Davis8e21c342007-01-08 11:04:17 +0100393static struct hda_verb stac925x_core_init[] = {
394 /* set dac0mux for dac converter */
395 { 0x06, AC_VERB_SET_CONNECT_SEL, 0x00},
396 {}
397};
398
Mattc7d4b2f2005-06-27 14:59:41 +0200399static struct hda_verb stac922x_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200400 /* set master volume and direct control */
Mattc7d4b2f2005-06-27 14:59:41 +0200401 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matt2f2f4252005-04-13 14:45:30 +0200402 {}
403};
404
Tobin Davis93ed1502006-09-01 21:03:12 +0200405static struct hda_verb d965_core_init[] = {
Takashi Iwai19039bd2006-06-28 15:52:16 +0200406 /* set master volume and direct control */
Tobin Davis93ed1502006-09-01 21:03:12 +0200407 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Takashi Iwai19039bd2006-06-28 15:52:16 +0200408 /* unmute node 0x1b */
409 { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
410 /* select node 0x03 as DAC */
411 { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
412 {}
413};
414
Matt Porter3cc08dc2006-01-23 15:27:49 +0100415static struct hda_verb stac927x_core_init[] = {
416 /* set master volume and direct control */
417 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
418 {}
419};
420
Matt Porterf3302a52006-07-31 12:49:34 +0200421static struct hda_verb stac9205_core_init[] = {
422 /* set master volume and direct control */
423 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
424 {}
425};
426
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200427#define STAC_INPUT_SOURCE(cnt) \
Maxim Levitskyca7c5a82007-08-31 12:52:19 +0200428 { \
429 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
430 .name = "Input Source", \
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200431 .count = cnt, \
Maxim Levitskyca7c5a82007-08-31 12:52:19 +0200432 .info = stac92xx_mux_enum_info, \
433 .get = stac92xx_mux_enum_get, \
434 .put = stac92xx_mux_enum_put, \
435 }
436
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200437#define STAC_ANALOG_LOOPBACK(verb_read,verb_write) \
438 { \
439 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
440 .name = "Analog Loopback", \
441 .count = 1, \
442 .info = stac92xx_aloopback_info, \
443 .get = stac92xx_aloopback_get, \
444 .put = stac92xx_aloopback_put, \
445 .private_value = verb_read | (verb_write << 16), \
446 }
447
Takashi Iwai9066f242007-10-16 14:25:16 +0200448#define STAC_VOLKNOB(knob_nid) \
Maxim Levitsky6e6b88f2007-09-03 15:30:26 +0200449 { \
450 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
451 .name = "Master Playback Volume", \
452 .count = 1, \
453 .info = stac92xx_volknob_info, \
454 .get = stac92xx_volknob_get, \
455 .put = stac92xx_volknob_put, \
Takashi Iwai9066f242007-10-16 14:25:16 +0200456 .private_value = 127 | (knob_nid << 16), \
Maxim Levitsky6e6b88f2007-09-03 15:30:26 +0200457 }
458
Maxim Levitskyca7c5a82007-08-31 12:52:19 +0200459
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100460static struct snd_kcontrol_new stac9200_mixer[] = {
Matt2f2f4252005-04-13 14:45:30 +0200461 HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
462 HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200463 STAC_INPUT_SOURCE(1),
Matt2f2f4252005-04-13 14:45:30 +0200464 HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
465 HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
Mattc7d4b2f2005-06-27 14:59:41 +0200466 HDA_CODEC_VOLUME("Capture Mux Volume", 0x0c, 0, HDA_OUTPUT),
Matt2f2f4252005-04-13 14:45:30 +0200467 { } /* end */
468};
469
Tobin Davis8e21c342007-01-08 11:04:17 +0100470static struct snd_kcontrol_new stac925x_mixer[] = {
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200471 STAC_INPUT_SOURCE(1),
Tobin Davis8e21c342007-01-08 11:04:17 +0100472 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_OUTPUT),
473 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_OUTPUT),
474 HDA_CODEC_VOLUME("Capture Mux Volume", 0x0f, 0, HDA_OUTPUT),
475 { } /* end */
476};
477
Takashi Iwaid1d985f2006-11-23 19:27:12 +0100478static struct snd_kcontrol_new stac9205_mixer[] = {
Matt Porterf3302a52006-07-31 12:49:34 +0200479 {
480 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Matt Porter8b657272006-10-26 17:12:59 +0200481 .name = "Digital Input Source",
482 .count = 1,
483 .info = stac92xx_dmux_enum_info,
484 .get = stac92xx_dmux_enum_get,
485 .put = stac92xx_dmux_enum_put,
486 },
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200487 STAC_INPUT_SOURCE(2),
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200488 STAC_ANALOG_LOOPBACK(0xFE0, 0x7E0),
Takashi Iwai9066f242007-10-16 14:25:16 +0200489 STAC_VOLKNOB(0x24),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200490
491 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1b, 0x0, HDA_INPUT),
492 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1d, 0x0, HDA_OUTPUT),
493 HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x0, 0x19, 0x0, HDA_OUTPUT),
494
495 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x1c, 0x0, HDA_INPUT),
496 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1e, 0x0, HDA_OUTPUT),
497 HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x1, 0x1A, 0x0, HDA_OUTPUT),
498
499 { } /* end */
500};
501
502/* This needs to be generated dynamically based on sequence */
503static struct snd_kcontrol_new stac922x_mixer[] = {
504 STAC_INPUT_SOURCE(2),
Takashi Iwai9066f242007-10-16 14:25:16 +0200505 STAC_VOLKNOB(0x16),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200506 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x17, 0x0, HDA_INPUT),
507 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x17, 0x0, HDA_INPUT),
508 HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x0, 0x12, 0x0, HDA_OUTPUT),
509
510 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x18, 0x0, HDA_INPUT),
511 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x18, 0x0, HDA_INPUT),
512 HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x1, 0x13, 0x0, HDA_OUTPUT),
513 { } /* end */
514};
515
516
517static struct snd_kcontrol_new stac927x_mixer[] = {
518 STAC_INPUT_SOURCE(3),
Takashi Iwai9066f242007-10-16 14:25:16 +0200519 STAC_VOLKNOB(0x24),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200520 STAC_ANALOG_LOOPBACK(0xFEB, 0x7EB),
521
522 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x18, 0x0, HDA_INPUT),
523 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1b, 0x0, HDA_OUTPUT),
524 HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x0, 0x15, 0x0, HDA_OUTPUT),
525
526 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x19, 0x0, HDA_INPUT),
527 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1c, 0x0, HDA_OUTPUT),
528 HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x1, 0x16, 0x0, HDA_OUTPUT),
529
530 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x2, 0x1A, 0x0, HDA_INPUT),
531 HDA_CODEC_MUTE_IDX("Capture Switch", 0x2, 0x1d, 0x0, HDA_OUTPUT),
532 HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x2, 0x17, 0x0, HDA_OUTPUT),
Matt Porterf3302a52006-07-31 12:49:34 +0200533 { } /* end */
534};
535
Matt2f2f4252005-04-13 14:45:30 +0200536static int stac92xx_build_controls(struct hda_codec *codec)
537{
538 struct sigmatel_spec *spec = codec->spec;
539 int err;
Mattc7d4b2f2005-06-27 14:59:41 +0200540 int i;
Matt2f2f4252005-04-13 14:45:30 +0200541
542 err = snd_hda_add_new_ctls(codec, spec->mixer);
543 if (err < 0)
544 return err;
Mattc7d4b2f2005-06-27 14:59:41 +0200545
546 for (i = 0; i < spec->num_mixers; i++) {
547 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
548 if (err < 0)
549 return err;
550 }
551
Mattdabbed62005-06-14 10:19:34 +0200552 if (spec->multiout.dig_out_nid) {
553 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
554 if (err < 0)
555 return err;
556 }
557 if (spec->dig_in_nid) {
558 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
559 if (err < 0)
560 return err;
561 }
562 return 0;
Matt2f2f4252005-04-13 14:45:30 +0200563}
564
Matt Porter403d1942005-11-29 15:00:51 +0100565static unsigned int ref9200_pin_configs[8] = {
Mattdabbed62005-06-14 10:19:34 +0200566 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
Matt2f2f4252005-04-13 14:45:30 +0200567 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
568};
569
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200570/*
571 STAC 9200 pin configs for
572 102801A8
573 102801DE
574 102801E8
575*/
576static unsigned int dell9200_d21_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +0200577 0x400001f0, 0x400001f1, 0x02214030, 0x01014010,
578 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200579};
580
581/*
582 STAC 9200 pin configs for
583 102801C0
584 102801C1
585*/
586static unsigned int dell9200_d22_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +0200587 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
588 0x01813020, 0x02a19021, 0x90100140, 0x400001f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200589};
590
591/*
592 STAC 9200 pin configs for
593 102801C4 (Dell Dimension E310)
594 102801C5
595 102801C7
596 102801D9
597 102801DA
598 102801E3
599*/
600static unsigned int dell9200_d23_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +0200601 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
602 0x01813020, 0x01a19021, 0x90100140, 0x400001f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200603};
604
605
606/*
607 STAC 9200-32 pin configs for
608 102801B5 (Dell Inspiron 630m)
609 102801D8 (Dell Inspiron 640m)
610*/
611static unsigned int dell9200_m21_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +0200612 0x40c003fa, 0x03441340, 0x0321121f, 0x90170310,
613 0x408003fb, 0x03a11020, 0x401003fc, 0x403003fd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200614};
615
616/*
617 STAC 9200-32 pin configs for
618 102801C2 (Dell Latitude D620)
619 102801C8
620 102801CC (Dell Latitude D820)
621 102801D4
622 102801D6
623*/
624static unsigned int dell9200_m22_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +0200625 0x40c003fa, 0x0144131f, 0x0321121f, 0x90170310,
626 0x90a70321, 0x03a11020, 0x401003fb, 0x40f000fc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200627};
628
629/*
630 STAC 9200-32 pin configs for
631 102801CE (Dell XPS M1710)
632 102801CF (Dell Precision M90)
633*/
634static unsigned int dell9200_m23_pin_configs[8] = {
635 0x40c003fa, 0x01441340, 0x0421421f, 0x90170310,
636 0x408003fb, 0x04a1102e, 0x90170311, 0x403003fc,
637};
638
639/*
640 STAC 9200-32 pin configs for
641 102801C9
642 102801CA
643 102801CB (Dell Latitude 120L)
644 102801D3
645*/
646static unsigned int dell9200_m24_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +0200647 0x40c003fa, 0x404003fb, 0x0321121f, 0x90170310,
648 0x408003fc, 0x03a11020, 0x401003fd, 0x403003fe,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200649};
650
651/*
652 STAC 9200-32 pin configs for
653 102801BD (Dell Inspiron E1505n)
654 102801EE
655 102801EF
656*/
657static unsigned int dell9200_m25_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +0200658 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
659 0x408003fb, 0x04a11020, 0x401003fc, 0x403003fd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200660};
661
662/*
663 STAC 9200-32 pin configs for
664 102801F5 (Dell Inspiron 1501)
665 102801F6
666*/
667static unsigned int dell9200_m26_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +0200668 0x40c003fa, 0x404003fb, 0x0421121f, 0x90170310,
669 0x408003fc, 0x04a11020, 0x401003fd, 0x403003fe,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200670};
671
672/*
673 STAC 9200-32
674 102801CD (Dell Inspiron E1705/9400)
675*/
676static unsigned int dell9200_m27_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +0200677 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
678 0x90170310, 0x04a11020, 0x90170310, 0x40f003fc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200679};
680
681
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100682static unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
683 [STAC_REF] = ref9200_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200684 [STAC_9200_DELL_D21] = dell9200_d21_pin_configs,
685 [STAC_9200_DELL_D22] = dell9200_d22_pin_configs,
686 [STAC_9200_DELL_D23] = dell9200_d23_pin_configs,
687 [STAC_9200_DELL_M21] = dell9200_m21_pin_configs,
688 [STAC_9200_DELL_M22] = dell9200_m22_pin_configs,
689 [STAC_9200_DELL_M23] = dell9200_m23_pin_configs,
690 [STAC_9200_DELL_M24] = dell9200_m24_pin_configs,
691 [STAC_9200_DELL_M25] = dell9200_m25_pin_configs,
692 [STAC_9200_DELL_M26] = dell9200_m26_pin_configs,
693 [STAC_9200_DELL_M27] = dell9200_m27_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +0100694};
695
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100696static const char *stac9200_models[STAC_9200_MODELS] = {
697 [STAC_REF] = "ref",
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200698 [STAC_9200_DELL_D21] = "dell-d21",
699 [STAC_9200_DELL_D22] = "dell-d22",
700 [STAC_9200_DELL_D23] = "dell-d23",
701 [STAC_9200_DELL_M21] = "dell-m21",
702 [STAC_9200_DELL_M22] = "dell-m22",
703 [STAC_9200_DELL_M23] = "dell-m23",
704 [STAC_9200_DELL_M24] = "dell-m24",
705 [STAC_9200_DELL_M25] = "dell-m25",
706 [STAC_9200_DELL_M26] = "dell-m26",
707 [STAC_9200_DELL_M27] = "dell-m27",
Takashi Iwai1194b5b2007-10-10 10:04:26 +0200708 [STAC_9200_GATEWAY] = "gateway",
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100709};
710
711static struct snd_pci_quirk stac9200_cfg_tbl[] = {
712 /* SigmaTel reference board */
713 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
714 "DFI LanParty", STAC_REF),
Matt Portere7377072006-11-06 11:20:38 +0100715 /* Dell laptops have BIOS problem */
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200716 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a8,
717 "unknown Dell", STAC_9200_DELL_D21),
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100718 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01b5,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200719 "Dell Inspiron 630m", STAC_9200_DELL_M21),
720 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bd,
721 "Dell Inspiron E1505n", STAC_9200_DELL_M25),
722 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c0,
723 "unknown Dell", STAC_9200_DELL_D22),
724 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c1,
725 "unknown Dell", STAC_9200_DELL_D22),
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100726 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200727 "Dell Latitude D620", STAC_9200_DELL_M22),
728 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c5,
729 "unknown Dell", STAC_9200_DELL_D23),
730 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c7,
731 "unknown Dell", STAC_9200_DELL_D23),
732 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c8,
733 "unknown Dell", STAC_9200_DELL_M22),
734 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c9,
735 "unknown Dell", STAC_9200_DELL_M24),
736 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ca,
737 "unknown Dell", STAC_9200_DELL_M24),
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100738 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cb,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200739 "Dell Latitude 120L", STAC_9200_DELL_M24),
Cory T. Tusar877b8662007-01-30 17:30:55 +0100740 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200741 "Dell Latitude D820", STAC_9200_DELL_M22),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +0100742 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200743 "Dell Inspiron E1705/9400", STAC_9200_DELL_M27),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +0100744 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ce,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200745 "Dell XPS M1710", STAC_9200_DELL_M23),
Takashi Iwaif0f96742007-02-14 00:59:17 +0100746 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cf,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200747 "Dell Precision M90", STAC_9200_DELL_M23),
748 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d3,
749 "unknown Dell", STAC_9200_DELL_M22),
750 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d4,
751 "unknown Dell", STAC_9200_DELL_M22),
Daniel T Chen8286c532007-05-15 11:46:23 +0200752 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d6,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200753 "unknown Dell", STAC_9200_DELL_M22),
Tobin Davis49c605d2007-05-17 09:38:24 +0200754 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d8,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200755 "Dell Inspiron 640m", STAC_9200_DELL_M21),
756 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d9,
757 "unknown Dell", STAC_9200_DELL_D23),
758 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01da,
759 "unknown Dell", STAC_9200_DELL_D23),
760 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01de,
761 "unknown Dell", STAC_9200_DELL_D21),
762 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e3,
763 "unknown Dell", STAC_9200_DELL_D23),
764 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e8,
765 "unknown Dell", STAC_9200_DELL_D21),
766 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ee,
767 "unknown Dell", STAC_9200_DELL_M25),
768 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ef,
769 "unknown Dell", STAC_9200_DELL_M25),
Tobin Davis49c605d2007-05-17 09:38:24 +0200770 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f5,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200771 "Dell Inspiron 1501", STAC_9200_DELL_M26),
772 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f6,
773 "unknown Dell", STAC_9200_DELL_M26),
Tobin Davis49c605d2007-05-17 09:38:24 +0200774 /* Panasonic */
775 SND_PCI_QUIRK(0x10f7, 0x8338, "Panasonic CF-74", STAC_REF),
Takashi Iwai1194b5b2007-10-10 10:04:26 +0200776 /* Gateway machines needs EAPD to be set on resume */
777 SND_PCI_QUIRK(0x107b, 0x0205, "Gateway S-7110M", STAC_9200_GATEWAY),
778 SND_PCI_QUIRK(0x107b, 0x0317, "Gateway MT3423, MX341*",
779 STAC_9200_GATEWAY),
780 SND_PCI_QUIRK(0x107b, 0x0318, "Gateway ML3019, MT3707",
781 STAC_9200_GATEWAY),
Matt Porter403d1942005-11-29 15:00:51 +0100782 {} /* terminator */
783};
784
Tobin Davis8e21c342007-01-08 11:04:17 +0100785static unsigned int ref925x_pin_configs[8] = {
786 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
787 0x90a70320, 0x02214210, 0x400003f1, 0x9033032e,
788};
789
790static unsigned int stac925x_MA6_pin_configs[8] = {
791 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
792 0x90a70320, 0x90100211, 0x400003f1, 0x9033032e,
793};
794
Tobin Davis2c11f952007-05-17 09:36:34 +0200795static unsigned int stac925x_PA6_pin_configs[8] = {
796 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
797 0x50a103f0, 0x90100211, 0x400003f1, 0x9033032e,
798};
799
Tobin Davis8e21c342007-01-08 11:04:17 +0100800static unsigned int stac925xM2_2_pin_configs[8] = {
Steve Longerbeam7353e142007-05-29 14:36:17 +0200801 0x40c003f3, 0x424503f2, 0x04180011, 0x02a19020,
802 0x50a103f0, 0x90100212, 0x400003f1, 0x9033032e,
Tobin Davis8e21c342007-01-08 11:04:17 +0100803};
804
805static unsigned int *stac925x_brd_tbl[STAC_925x_MODELS] = {
806 [STAC_REF] = ref925x_pin_configs,
807 [STAC_M2_2] = stac925xM2_2_pin_configs,
808 [STAC_MA6] = stac925x_MA6_pin_configs,
Tobin Davis2c11f952007-05-17 09:36:34 +0200809 [STAC_PA6] = stac925x_PA6_pin_configs,
Tobin Davis8e21c342007-01-08 11:04:17 +0100810};
811
812static const char *stac925x_models[STAC_925x_MODELS] = {
813 [STAC_REF] = "ref",
814 [STAC_M2_2] = "m2-2",
815 [STAC_MA6] = "m6",
Tobin Davis2c11f952007-05-17 09:36:34 +0200816 [STAC_PA6] = "pa6",
Tobin Davis8e21c342007-01-08 11:04:17 +0100817};
818
819static struct snd_pci_quirk stac925x_cfg_tbl[] = {
820 /* SigmaTel reference board */
821 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, "DFI LanParty", STAC_REF),
Tobin Davis2c11f952007-05-17 09:36:34 +0200822 SND_PCI_QUIRK(0x8384, 0x7632, "Stac9202 Reference Board", STAC_REF),
Tobin Davis8e21c342007-01-08 11:04:17 +0100823 SND_PCI_QUIRK(0x107b, 0x0316, "Gateway M255", STAC_REF),
824 SND_PCI_QUIRK(0x107b, 0x0366, "Gateway MP6954", STAC_REF),
825 SND_PCI_QUIRK(0x107b, 0x0461, "Gateway NX560XL", STAC_MA6),
Tobin Davis2c11f952007-05-17 09:36:34 +0200826 SND_PCI_QUIRK(0x107b, 0x0681, "Gateway NX860", STAC_PA6),
Tobin Davis8e21c342007-01-08 11:04:17 +0100827 SND_PCI_QUIRK(0x1002, 0x437b, "Gateway MX6453", STAC_M2_2),
828 {} /* terminator */
829};
830
Matt Porter403d1942005-11-29 15:00:51 +0100831static unsigned int ref922x_pin_configs[10] = {
832 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
833 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
Matt2f2f4252005-04-13 14:45:30 +0200834 0x40000100, 0x40000100,
835};
836
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200837/*
838 STAC 922X pin configs for
839 102801A7
840 102801AB
841 102801A9
842 102801D1
843 102801D2
844*/
845static unsigned int dell_922x_d81_pin_configs[10] = {
846 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
847 0x02a19020, 0x01117011, 0x400001f0, 0x400001f1,
848 0x01813122, 0x400001f2,
849};
850
851/*
852 STAC 922X pin configs for
853 102801AC
854 102801D0
855*/
856static unsigned int dell_922x_d82_pin_configs[10] = {
857 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
858 0x02a19020, 0x01117011, 0x01451140, 0x400001f0,
859 0x01813122, 0x400001f1,
860};
861
862/*
863 STAC 922X pin configs for
864 102801BF
865*/
866static unsigned int dell_922x_m81_pin_configs[10] = {
867 0x0321101f, 0x01112024, 0x01111222, 0x91174220,
868 0x03a11050, 0x01116221, 0x90a70330, 0x01452340,
869 0x40C003f1, 0x405003f0,
870};
871
872/*
873 STAC 9221 A1 pin configs for
874 102801D7 (Dell XPS M1210)
875*/
876static unsigned int dell_922x_m82_pin_configs[10] = {
877 0x0221121f, 0x408103ff, 0x02111212, 0x90100310,
878 0x408003f1, 0x02111211, 0x03451340, 0x40c003f2,
879 0x508003f3, 0x405003f4,
880};
881
Matt Porter403d1942005-11-29 15:00:51 +0100882static unsigned int d945gtp3_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +0100883 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
Matt Porter403d1942005-11-29 15:00:51 +0100884 0x40000100, 0x40000100, 0x40000100, 0x40000100,
885 0x02a19120, 0x40000100,
886};
887
888static unsigned int d945gtp5_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +0100889 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
890 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
Matt Porter403d1942005-11-29 15:00:51 +0100891 0x02a19320, 0x40000100,
892};
893
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +0200894static unsigned int intel_mac_v1_pin_configs[10] = {
895 0x0121e21f, 0x400000ff, 0x9017e110, 0x400000fd,
896 0x400000fe, 0x0181e020, 0x1145e030, 0x11c5e240,
Takashi Iwai3fc24d82007-02-16 13:27:18 +0100897 0x400000fc, 0x400000fb,
898};
899
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +0200900static unsigned int intel_mac_v2_pin_configs[10] = {
901 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
902 0x400000fe, 0x0181e020, 0x1145e230, 0x500000fa,
Sylvain FORETf16928f2007-04-27 14:22:36 +0200903 0x400000fc, 0x400000fb,
904};
905
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +0200906static unsigned int intel_mac_v3_pin_configs[10] = {
907 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
908 0x400000fe, 0x0181e020, 0x1145e230, 0x11c5e240,
909 0x400000fc, 0x400000fb,
910};
911
912static unsigned int intel_mac_v4_pin_configs[10] = {
913 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
914 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
915 0x400000fc, 0x400000fb,
916};
917
918static unsigned int intel_mac_v5_pin_configs[10] = {
919 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
920 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
921 0x400000fc, 0x400000fb,
Takashi Iwai0dae0f82007-05-21 12:41:29 +0200922};
923
Takashi Iwai76c08822007-06-19 12:17:42 +0200924
Takashi Iwai19039bd2006-06-28 15:52:16 +0200925static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100926 [STAC_D945_REF] = ref922x_pin_configs,
Takashi Iwai19039bd2006-06-28 15:52:16 +0200927 [STAC_D945GTP3] = d945gtp3_pin_configs,
928 [STAC_D945GTP5] = d945gtp5_pin_configs,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +0200929 [STAC_INTEL_MAC_V1] = intel_mac_v1_pin_configs,
930 [STAC_INTEL_MAC_V2] = intel_mac_v2_pin_configs,
931 [STAC_INTEL_MAC_V3] = intel_mac_v3_pin_configs,
932 [STAC_INTEL_MAC_V4] = intel_mac_v4_pin_configs,
933 [STAC_INTEL_MAC_V5] = intel_mac_v5_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200934 /* for backward compatibility */
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +0200935 [STAC_MACMINI] = intel_mac_v3_pin_configs,
936 [STAC_MACBOOK] = intel_mac_v5_pin_configs,
937 [STAC_MACBOOK_PRO_V1] = intel_mac_v3_pin_configs,
938 [STAC_MACBOOK_PRO_V2] = intel_mac_v3_pin_configs,
939 [STAC_IMAC_INTEL] = intel_mac_v2_pin_configs,
940 [STAC_IMAC_INTEL_20] = intel_mac_v3_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200941 [STAC_922X_DELL_D81] = dell_922x_d81_pin_configs,
942 [STAC_922X_DELL_D82] = dell_922x_d82_pin_configs,
943 [STAC_922X_DELL_M81] = dell_922x_m81_pin_configs,
944 [STAC_922X_DELL_M82] = dell_922x_m82_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +0100945};
946
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100947static const char *stac922x_models[STAC_922X_MODELS] = {
948 [STAC_D945_REF] = "ref",
949 [STAC_D945GTP5] = "5stack",
950 [STAC_D945GTP3] = "3stack",
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +0200951 [STAC_INTEL_MAC_V1] = "intel-mac-v1",
952 [STAC_INTEL_MAC_V2] = "intel-mac-v2",
953 [STAC_INTEL_MAC_V3] = "intel-mac-v3",
954 [STAC_INTEL_MAC_V4] = "intel-mac-v4",
955 [STAC_INTEL_MAC_V5] = "intel-mac-v5",
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200956 /* for backward compatibility */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100957 [STAC_MACMINI] = "macmini",
Takashi Iwai3fc24d82007-02-16 13:27:18 +0100958 [STAC_MACBOOK] = "macbook",
Nicolas Boichat6f0778d2007-03-15 12:38:15 +0100959 [STAC_MACBOOK_PRO_V1] = "macbook-pro-v1",
960 [STAC_MACBOOK_PRO_V2] = "macbook-pro",
Sylvain FORETf16928f2007-04-27 14:22:36 +0200961 [STAC_IMAC_INTEL] = "imac-intel",
Takashi Iwai0dae0f82007-05-21 12:41:29 +0200962 [STAC_IMAC_INTEL_20] = "imac-intel-20",
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200963 [STAC_922X_DELL_D81] = "dell-d81",
964 [STAC_922X_DELL_D82] = "dell-d82",
965 [STAC_922X_DELL_M81] = "dell-m81",
966 [STAC_922X_DELL_M82] = "dell-m82",
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100967};
968
969static struct snd_pci_quirk stac922x_cfg_tbl[] = {
970 /* SigmaTel reference board */
971 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
972 "DFI LanParty", STAC_D945_REF),
973 /* Intel 945G based systems */
974 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101,
975 "Intel D945G", STAC_D945GTP3),
976 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0202,
977 "Intel D945G", STAC_D945GTP3),
978 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0606,
979 "Intel D945G", STAC_D945GTP3),
980 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0601,
981 "Intel D945G", STAC_D945GTP3),
982 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0111,
983 "Intel D945G", STAC_D945GTP3),
984 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1115,
985 "Intel D945G", STAC_D945GTP3),
986 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1116,
987 "Intel D945G", STAC_D945GTP3),
988 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1117,
989 "Intel D945G", STAC_D945GTP3),
990 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1118,
991 "Intel D945G", STAC_D945GTP3),
992 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1119,
993 "Intel D945G", STAC_D945GTP3),
994 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x8826,
995 "Intel D945G", STAC_D945GTP3),
996 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5049,
997 "Intel D945G", STAC_D945GTP3),
998 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5055,
999 "Intel D945G", STAC_D945GTP3),
1000 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5048,
1001 "Intel D945G", STAC_D945GTP3),
1002 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0110,
1003 "Intel D945G", STAC_D945GTP3),
1004 /* Intel D945G 5-stack systems */
1005 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0404,
1006 "Intel D945G", STAC_D945GTP5),
1007 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0303,
1008 "Intel D945G", STAC_D945GTP5),
1009 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0013,
1010 "Intel D945G", STAC_D945GTP5),
1011 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0417,
1012 "Intel D945G", STAC_D945GTP5),
1013 /* Intel 945P based systems */
1014 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0b0b,
1015 "Intel D945P", STAC_D945GTP3),
1016 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0112,
1017 "Intel D945P", STAC_D945GTP3),
1018 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0d0d,
1019 "Intel D945P", STAC_D945GTP3),
1020 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0909,
1021 "Intel D945P", STAC_D945GTP3),
1022 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0505,
1023 "Intel D945P", STAC_D945GTP3),
1024 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707,
1025 "Intel D945P", STAC_D945GTP5),
1026 /* other systems */
1027 /* Apple Mac Mini (early 2006) */
1028 SND_PCI_QUIRK(0x8384, 0x7680,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001029 "Mac Mini", STAC_INTEL_MAC_V3),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001030 /* Dell systems */
1031 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a7,
1032 "unknown Dell", STAC_922X_DELL_D81),
1033 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a9,
1034 "unknown Dell", STAC_922X_DELL_D81),
1035 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ab,
1036 "unknown Dell", STAC_922X_DELL_D81),
1037 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ac,
1038 "unknown Dell", STAC_922X_DELL_D82),
1039 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bf,
1040 "unknown Dell", STAC_922X_DELL_M81),
1041 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d0,
1042 "unknown Dell", STAC_922X_DELL_D82),
1043 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d1,
1044 "unknown Dell", STAC_922X_DELL_D81),
1045 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d2,
1046 "unknown Dell", STAC_922X_DELL_D81),
1047 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d7,
1048 "Dell XPS M1210", STAC_922X_DELL_M82),
Matt Porter403d1942005-11-29 15:00:51 +01001049 {} /* terminator */
1050};
1051
Matt Porter3cc08dc2006-01-23 15:27:49 +01001052static unsigned int ref927x_pin_configs[14] = {
Tobin Davis93ed1502006-09-01 21:03:12 +02001053 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
1054 0x01a19040, 0x01011012, 0x01016011, 0x0101201f,
1055 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
1056 0x01c42190, 0x40000100,
Matt Porter3cc08dc2006-01-23 15:27:49 +01001057};
1058
Tobin Davis93ed1502006-09-01 21:03:12 +02001059static unsigned int d965_3st_pin_configs[14] = {
Tobin Davis81d3dbd2006-08-22 19:44:45 +02001060 0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
1061 0x01a19021, 0x01813024, 0x40000100, 0x40000100,
1062 0x40000100, 0x40000100, 0x40000100, 0x40000100,
1063 0x40000100, 0x40000100
1064};
1065
Tobin Davis93ed1502006-09-01 21:03:12 +02001066static unsigned int d965_5st_pin_configs[14] = {
1067 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
1068 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
1069 0x40000100, 0x40000100, 0x40000100, 0x01442070,
1070 0x40000100, 0x40000100
1071};
1072
Tobin Davis4ff076e2007-08-07 11:48:12 +02001073static unsigned int dell_3st_pin_configs[14] = {
1074 0x02211230, 0x02a11220, 0x01a19040, 0x01114210,
1075 0x01111212, 0x01116211, 0x01813050, 0x01112214,
1076 0x403003fa, 0x40000100, 0x40000100, 0x404003fb,
1077 0x40c003fc, 0x40000100
1078};
1079
Tobin Davis93ed1502006-09-01 21:03:12 +02001080static unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001081 [STAC_D965_REF] = ref927x_pin_configs,
Tobin Davis93ed1502006-09-01 21:03:12 +02001082 [STAC_D965_3ST] = d965_3st_pin_configs,
1083 [STAC_D965_5ST] = d965_5st_pin_configs,
Tobin Davis4ff076e2007-08-07 11:48:12 +02001084 [STAC_DELL_3ST] = dell_3st_pin_configs,
Matt Porter3cc08dc2006-01-23 15:27:49 +01001085};
1086
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001087static const char *stac927x_models[STAC_927X_MODELS] = {
1088 [STAC_D965_REF] = "ref",
1089 [STAC_D965_3ST] = "3stack",
1090 [STAC_D965_5ST] = "5stack",
Tobin Davis4ff076e2007-08-07 11:48:12 +02001091 [STAC_DELL_3ST] = "dell-3stack",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001092};
1093
1094static struct snd_pci_quirk stac927x_cfg_tbl[] = {
1095 /* SigmaTel reference board */
1096 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1097 "DFI LanParty", STAC_D965_REF),
Tobin Davis81d3dbd2006-08-22 19:44:45 +02001098 /* Intel 946 based systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001099 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST),
1100 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST),
Tobin Davis93ed1502006-09-01 21:03:12 +02001101 /* 965 based 3 stack systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001102 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2116, "Intel D965", STAC_D965_3ST),
1103 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2115, "Intel D965", STAC_D965_3ST),
1104 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2114, "Intel D965", STAC_D965_3ST),
1105 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2113, "Intel D965", STAC_D965_3ST),
1106 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2112, "Intel D965", STAC_D965_3ST),
1107 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2111, "Intel D965", STAC_D965_3ST),
1108 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2110, "Intel D965", STAC_D965_3ST),
1109 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2009, "Intel D965", STAC_D965_3ST),
1110 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2008, "Intel D965", STAC_D965_3ST),
1111 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2007, "Intel D965", STAC_D965_3ST),
1112 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2006, "Intel D965", STAC_D965_3ST),
1113 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2005, "Intel D965", STAC_D965_3ST),
1114 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2004, "Intel D965", STAC_D965_3ST),
1115 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2003, "Intel D965", STAC_D965_3ST),
1116 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2002, "Intel D965", STAC_D965_3ST),
1117 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2001, "Intel D965", STAC_D965_3ST),
Tim Gardner5e915bb2007-10-10 10:42:00 +02001118 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f3, "Dell Inspiron 1420", STAC_D965_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +02001119 /* Dell 3 stack systems */
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001120 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01dd, "Dell Dimension E520", STAC_DELL_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +02001121 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ed, "Dell ", STAC_DELL_3ST),
1122 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f4, "Dell ", STAC_DELL_3ST),
Tobin Davis93ed1502006-09-01 21:03:12 +02001123 /* 965 based 5 stack systems */
Tim Gardner5e915bb2007-10-10 10:42:00 +02001124 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0209, "Dell XPS 1330", STAC_D965_5ST),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001125 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2301, "Intel D965", STAC_D965_5ST),
1126 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2302, "Intel D965", STAC_D965_5ST),
1127 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2303, "Intel D965", STAC_D965_5ST),
1128 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2304, "Intel D965", STAC_D965_5ST),
1129 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2305, "Intel D965", STAC_D965_5ST),
1130 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2501, "Intel D965", STAC_D965_5ST),
1131 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2502, "Intel D965", STAC_D965_5ST),
1132 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2503, "Intel D965", STAC_D965_5ST),
1133 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2504, "Intel D965", STAC_D965_5ST),
Matt Porter3cc08dc2006-01-23 15:27:49 +01001134 {} /* terminator */
1135};
1136
Matt Porterf3302a52006-07-31 12:49:34 +02001137static unsigned int ref9205_pin_configs[12] = {
1138 0x40000100, 0x40000100, 0x01016011, 0x01014010,
Matt Porter8b657272006-10-26 17:12:59 +02001139 0x01813122, 0x01a19021, 0x40000100, 0x40000100,
1140 0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
Matt Porterf3302a52006-07-31 12:49:34 +02001141};
1142
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001143/*
1144 STAC 9205 pin configs for
1145 102801F1
1146 102801F2
1147 102801FC
1148 102801FD
1149 10280204
1150 1028021F
1151*/
1152static unsigned int dell_9205_m42_pin_configs[12] = {
1153 0x0321101F, 0x03A11020, 0x400003FA, 0x90170310,
1154 0x400003FB, 0x400003FC, 0x400003FD, 0x40F000F9,
1155 0x90A60330, 0x400003FF, 0x0144131F, 0x40C003FE,
1156};
1157
1158/*
1159 STAC 9205 pin configs for
1160 102801F9
1161 102801FA
1162 102801FE
1163 102801FF (Dell Precision M4300)
1164 10280206
1165 10280200
1166 10280201
1167*/
1168static unsigned int dell_9205_m43_pin_configs[12] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001169 0x0321101f, 0x03a11020, 0x90a70330, 0x90170310,
1170 0x400000fe, 0x400000ff, 0x400000fd, 0x40f000f9,
1171 0x400000fa, 0x400000fc, 0x0144131f, 0x40c003f8,
1172};
1173
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001174static unsigned int dell_9205_m44_pin_configs[12] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001175 0x0421101f, 0x04a11020, 0x400003fa, 0x90170310,
1176 0x400003fb, 0x400003fc, 0x400003fd, 0x400003f9,
1177 0x90a60330, 0x400003ff, 0x01441340, 0x40c003fe,
1178};
1179
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001180static unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001181 [STAC_9205_REF] = ref9205_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001182 [STAC_9205_DELL_M42] = dell_9205_m42_pin_configs,
1183 [STAC_9205_DELL_M43] = dell_9205_m43_pin_configs,
1184 [STAC_9205_DELL_M44] = dell_9205_m44_pin_configs,
Matt Porterf3302a52006-07-31 12:49:34 +02001185};
1186
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001187static const char *stac9205_models[STAC_9205_MODELS] = {
1188 [STAC_9205_REF] = "ref",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001189 [STAC_9205_DELL_M42] = "dell-m42",
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001190 [STAC_9205_DELL_M43] = "dell-m43",
1191 [STAC_9205_DELL_M44] = "dell-m44",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001192};
1193
1194static struct snd_pci_quirk stac9205_cfg_tbl[] = {
1195 /* SigmaTel reference board */
1196 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1197 "DFI LanParty", STAC_9205_REF),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001198 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f1,
1199 "unknown Dell", STAC_9205_DELL_M42),
1200 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f2,
1201 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001202 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f8,
Matthew Ranostayb44ef2f2007-09-18 00:52:38 +02001203 "Dell Precision", STAC_9205_DELL_M43),
1204 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021c,
1205 "Dell Precision", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001206 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f9,
1207 "Dell Precision", STAC_9205_DELL_M43),
Matthew Ranostaye45e4592007-09-10 23:09:42 +02001208 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021b,
1209 "Dell Precision", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001210 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fa,
1211 "Dell Precision", STAC_9205_DELL_M43),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001212 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fc,
1213 "unknown Dell", STAC_9205_DELL_M42),
1214 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fd,
1215 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001216 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fe,
1217 "Dell Precision", STAC_9205_DELL_M43),
1218 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ff,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001219 "Dell Precision M4300", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001220 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0206,
1221 "Dell Precision", STAC_9205_DELL_M43),
1222 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f1,
1223 "Dell Inspiron", STAC_9205_DELL_M44),
1224 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f2,
1225 "Dell Inspiron", STAC_9205_DELL_M44),
1226 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fc,
1227 "Dell Inspiron", STAC_9205_DELL_M44),
1228 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fd,
1229 "Dell Inspiron", STAC_9205_DELL_M44),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001230 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0204,
1231 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001232 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021f,
1233 "Dell Inspiron", STAC_9205_DELL_M44),
Matt Porterf3302a52006-07-31 12:49:34 +02001234 {} /* terminator */
1235};
1236
Richard Fish11b44bb2006-08-23 18:31:34 +02001237static int stac92xx_save_bios_config_regs(struct hda_codec *codec)
1238{
1239 int i;
1240 struct sigmatel_spec *spec = codec->spec;
1241
1242 if (! spec->bios_pin_configs) {
1243 spec->bios_pin_configs = kcalloc(spec->num_pins,
1244 sizeof(*spec->bios_pin_configs), GFP_KERNEL);
1245 if (! spec->bios_pin_configs)
1246 return -ENOMEM;
1247 }
1248
1249 for (i = 0; i < spec->num_pins; i++) {
1250 hda_nid_t nid = spec->pin_nids[i];
1251 unsigned int pin_cfg;
1252
1253 pin_cfg = snd_hda_codec_read(codec, nid, 0,
1254 AC_VERB_GET_CONFIG_DEFAULT, 0x00);
1255 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x bios pin config %8.8x\n",
1256 nid, pin_cfg);
1257 spec->bios_pin_configs[i] = pin_cfg;
1258 }
1259
1260 return 0;
1261}
1262
Matthew Ranostay87d48362007-07-17 11:52:24 +02001263static void stac92xx_set_config_reg(struct hda_codec *codec,
1264 hda_nid_t pin_nid, unsigned int pin_config)
1265{
1266 int i;
1267 snd_hda_codec_write(codec, pin_nid, 0,
1268 AC_VERB_SET_CONFIG_DEFAULT_BYTES_0,
1269 pin_config & 0x000000ff);
1270 snd_hda_codec_write(codec, pin_nid, 0,
1271 AC_VERB_SET_CONFIG_DEFAULT_BYTES_1,
1272 (pin_config & 0x0000ff00) >> 8);
1273 snd_hda_codec_write(codec, pin_nid, 0,
1274 AC_VERB_SET_CONFIG_DEFAULT_BYTES_2,
1275 (pin_config & 0x00ff0000) >> 16);
1276 snd_hda_codec_write(codec, pin_nid, 0,
1277 AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
1278 pin_config >> 24);
1279 i = snd_hda_codec_read(codec, pin_nid, 0,
1280 AC_VERB_GET_CONFIG_DEFAULT,
1281 0x00);
1282 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x pin config %8.8x\n",
1283 pin_nid, i);
1284}
1285
Matt2f2f4252005-04-13 14:45:30 +02001286static void stac92xx_set_config_regs(struct hda_codec *codec)
1287{
1288 int i;
1289 struct sigmatel_spec *spec = codec->spec;
Matt2f2f4252005-04-13 14:45:30 +02001290
Matthew Ranostay87d48362007-07-17 11:52:24 +02001291 if (!spec->pin_configs)
1292 return;
Richard Fish11b44bb2006-08-23 18:31:34 +02001293
Matthew Ranostay87d48362007-07-17 11:52:24 +02001294 for (i = 0; i < spec->num_pins; i++)
1295 stac92xx_set_config_reg(codec, spec->pin_nids[i],
1296 spec->pin_configs[i]);
Matt2f2f4252005-04-13 14:45:30 +02001297}
Matt2f2f4252005-04-13 14:45:30 +02001298
Takashi Iwai82599802007-07-31 15:56:24 +02001299static void stac92xx_enable_gpio_mask(struct hda_codec *codec)
Matthew Ranostay92a22be2007-06-19 16:48:28 +02001300{
Takashi Iwai82599802007-07-31 15:56:24 +02001301 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay87d48362007-07-17 11:52:24 +02001302 /* Configure GPIOx as output */
Takashi Iwai82beb8f2007-08-10 17:09:26 +02001303 snd_hda_codec_write_cache(codec, codec->afg, 0,
1304 AC_VERB_SET_GPIO_DIRECTION, spec->gpio_mask);
Matthew Ranostay87d48362007-07-17 11:52:24 +02001305 /* Configure GPIOx as CMOS */
Takashi Iwai82beb8f2007-08-10 17:09:26 +02001306 snd_hda_codec_write_cache(codec, codec->afg, 0, 0x7e7, 0x00000000);
Matthew Ranostay87d48362007-07-17 11:52:24 +02001307 /* Assert GPIOx */
Takashi Iwai82beb8f2007-08-10 17:09:26 +02001308 snd_hda_codec_write_cache(codec, codec->afg, 0,
1309 AC_VERB_SET_GPIO_DATA, spec->gpio_data);
Matthew Ranostay87d48362007-07-17 11:52:24 +02001310 /* Enable GPIOx */
Takashi Iwai82beb8f2007-08-10 17:09:26 +02001311 snd_hda_codec_write_cache(codec, codec->afg, 0,
1312 AC_VERB_SET_GPIO_MASK, spec->gpio_mask);
Matthew Ranostay92a22be2007-06-19 16:48:28 +02001313}
1314
Matt2f2f4252005-04-13 14:45:30 +02001315/*
1316 * Analog playback callbacks
1317 */
1318static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
1319 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001320 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02001321{
1322 struct sigmatel_spec *spec = codec->spec;
1323 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
1324}
1325
1326static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1327 struct hda_codec *codec,
1328 unsigned int stream_tag,
1329 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001330 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02001331{
1332 struct sigmatel_spec *spec = codec->spec;
Matt Porter403d1942005-11-29 15:00:51 +01001333 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
Matt2f2f4252005-04-13 14:45:30 +02001334}
1335
1336static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
1337 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001338 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02001339{
1340 struct sigmatel_spec *spec = codec->spec;
1341 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
1342}
1343
1344/*
Mattdabbed62005-06-14 10:19:34 +02001345 * Digital playback callbacks
1346 */
1347static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
1348 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001349 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +02001350{
1351 struct sigmatel_spec *spec = codec->spec;
1352 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
1353}
1354
1355static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
1356 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001357 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +02001358{
1359 struct sigmatel_spec *spec = codec->spec;
1360 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
1361}
1362
Takashi Iwai6b97eb42007-04-05 14:51:48 +02001363static int stac92xx_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1364 struct hda_codec *codec,
1365 unsigned int stream_tag,
1366 unsigned int format,
1367 struct snd_pcm_substream *substream)
1368{
1369 struct sigmatel_spec *spec = codec->spec;
1370 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1371 stream_tag, format, substream);
1372}
1373
Mattdabbed62005-06-14 10:19:34 +02001374
1375/*
Matt2f2f4252005-04-13 14:45:30 +02001376 * Analog capture callbacks
1377 */
1378static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1379 struct hda_codec *codec,
1380 unsigned int stream_tag,
1381 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001382 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02001383{
1384 struct sigmatel_spec *spec = codec->spec;
1385
1386 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
1387 stream_tag, 0, format);
1388 return 0;
1389}
1390
1391static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1392 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001393 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02001394{
1395 struct sigmatel_spec *spec = codec->spec;
1396
1397 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 0, 0, 0);
1398 return 0;
1399}
1400
Mattdabbed62005-06-14 10:19:34 +02001401static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
1402 .substreams = 1,
1403 .channels_min = 2,
1404 .channels_max = 2,
1405 /* NID is set in stac92xx_build_pcms */
1406 .ops = {
1407 .open = stac92xx_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02001408 .close = stac92xx_dig_playback_pcm_close,
1409 .prepare = stac92xx_dig_playback_pcm_prepare
Mattdabbed62005-06-14 10:19:34 +02001410 },
1411};
1412
1413static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
1414 .substreams = 1,
1415 .channels_min = 2,
1416 .channels_max = 2,
1417 /* NID is set in stac92xx_build_pcms */
1418};
1419
Matt2f2f4252005-04-13 14:45:30 +02001420static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
1421 .substreams = 1,
1422 .channels_min = 2,
Mattc7d4b2f2005-06-27 14:59:41 +02001423 .channels_max = 8,
Matt2f2f4252005-04-13 14:45:30 +02001424 .nid = 0x02, /* NID to query formats and rates */
1425 .ops = {
1426 .open = stac92xx_playback_pcm_open,
1427 .prepare = stac92xx_playback_pcm_prepare,
1428 .cleanup = stac92xx_playback_pcm_cleanup
1429 },
1430};
1431
Matt Porter3cc08dc2006-01-23 15:27:49 +01001432static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
1433 .substreams = 1,
1434 .channels_min = 2,
1435 .channels_max = 2,
1436 .nid = 0x06, /* NID to query formats and rates */
1437 .ops = {
1438 .open = stac92xx_playback_pcm_open,
1439 .prepare = stac92xx_playback_pcm_prepare,
1440 .cleanup = stac92xx_playback_pcm_cleanup
1441 },
1442};
1443
Matt2f2f4252005-04-13 14:45:30 +02001444static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
Matt2f2f4252005-04-13 14:45:30 +02001445 .channels_min = 2,
1446 .channels_max = 2,
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001447 /* NID + .substreams is set in stac92xx_build_pcms */
Matt2f2f4252005-04-13 14:45:30 +02001448 .ops = {
1449 .prepare = stac92xx_capture_pcm_prepare,
1450 .cleanup = stac92xx_capture_pcm_cleanup
1451 },
1452};
1453
1454static int stac92xx_build_pcms(struct hda_codec *codec)
1455{
1456 struct sigmatel_spec *spec = codec->spec;
1457 struct hda_pcm *info = spec->pcm_rec;
1458
1459 codec->num_pcms = 1;
1460 codec->pcm_info = info;
1461
Mattc7d4b2f2005-06-27 14:59:41 +02001462 info->name = "STAC92xx Analog";
Matt2f2f4252005-04-13 14:45:30 +02001463 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
Matt2f2f4252005-04-13 14:45:30 +02001464 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
Matt Porter3cc08dc2006-01-23 15:27:49 +01001465 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001466 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adcs;
Matt Porter3cc08dc2006-01-23 15:27:49 +01001467
1468 if (spec->alt_switch) {
1469 codec->num_pcms++;
1470 info++;
1471 info->name = "STAC92xx Analog Alt";
1472 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
1473 }
Matt2f2f4252005-04-13 14:45:30 +02001474
Mattdabbed62005-06-14 10:19:34 +02001475 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
1476 codec->num_pcms++;
1477 info++;
1478 info->name = "STAC92xx Digital";
1479 if (spec->multiout.dig_out_nid) {
1480 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
1481 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
1482 }
1483 if (spec->dig_in_nid) {
1484 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
1485 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
1486 }
1487 }
1488
Matt2f2f4252005-04-13 14:45:30 +02001489 return 0;
1490}
1491
Takashi Iwaic960a032006-03-23 17:06:28 +01001492static unsigned int stac92xx_get_vref(struct hda_codec *codec, hda_nid_t nid)
1493{
1494 unsigned int pincap = snd_hda_param_read(codec, nid,
1495 AC_PAR_PIN_CAP);
1496 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
1497 if (pincap & AC_PINCAP_VREF_100)
1498 return AC_PINCTL_VREF_100;
1499 if (pincap & AC_PINCAP_VREF_80)
1500 return AC_PINCTL_VREF_80;
1501 if (pincap & AC_PINCAP_VREF_50)
1502 return AC_PINCTL_VREF_50;
1503 if (pincap & AC_PINCAP_VREF_GRD)
1504 return AC_PINCTL_VREF_GRD;
1505 return 0;
1506}
1507
Matt Porter403d1942005-11-29 15:00:51 +01001508static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
1509
1510{
Takashi Iwai82beb8f2007-08-10 17:09:26 +02001511 snd_hda_codec_write_cache(codec, nid, 0,
1512 AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
Matt Porter403d1942005-11-29 15:00:51 +01001513}
1514
Takashi Iwaia5ce8892007-07-23 15:42:26 +02001515#define stac92xx_io_switch_info snd_ctl_boolean_mono_info
Matt Porter403d1942005-11-29 15:00:51 +01001516
1517static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1518{
1519 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1520 struct sigmatel_spec *spec = codec->spec;
1521 int io_idx = kcontrol-> private_value & 0xff;
1522
1523 ucontrol->value.integer.value[0] = spec->io_switch[io_idx];
1524 return 0;
1525}
1526
1527static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1528{
1529 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1530 struct sigmatel_spec *spec = codec->spec;
1531 hda_nid_t nid = kcontrol->private_value >> 8;
1532 int io_idx = kcontrol-> private_value & 0xff;
1533 unsigned short val = ucontrol->value.integer.value[0];
1534
1535 spec->io_switch[io_idx] = val;
1536
1537 if (val)
1538 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
Takashi Iwaic960a032006-03-23 17:06:28 +01001539 else {
1540 unsigned int pinctl = AC_PINCTL_IN_EN;
1541 if (io_idx) /* set VREF for mic */
1542 pinctl |= stac92xx_get_vref(codec, nid);
1543 stac92xx_auto_set_pinctl(codec, nid, pinctl);
1544 }
Matt Porter403d1942005-11-29 15:00:51 +01001545 return 1;
1546}
1547
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02001548#define stac92xx_clfe_switch_info snd_ctl_boolean_mono_info
1549
1550static int stac92xx_clfe_switch_get(struct snd_kcontrol *kcontrol,
1551 struct snd_ctl_elem_value *ucontrol)
1552{
1553 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1554 struct sigmatel_spec *spec = codec->spec;
1555
1556 ucontrol->value.integer.value[0] = spec->clfe_swap;
1557 return 0;
1558}
1559
1560static int stac92xx_clfe_switch_put(struct snd_kcontrol *kcontrol,
1561 struct snd_ctl_elem_value *ucontrol)
1562{
1563 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1564 struct sigmatel_spec *spec = codec->spec;
1565 hda_nid_t nid = kcontrol->private_value & 0xff;
1566
1567 if (spec->clfe_swap == ucontrol->value.integer.value[0])
1568 return 0;
1569
1570 spec->clfe_swap = ucontrol->value.integer.value[0];
1571
1572 snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
1573 spec->clfe_swap ? 0x4 : 0x0);
1574
1575 return 1;
1576}
1577
Matt Porter403d1942005-11-29 15:00:51 +01001578#define STAC_CODEC_IO_SWITCH(xname, xpval) \
1579 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1580 .name = xname, \
1581 .index = 0, \
1582 .info = stac92xx_io_switch_info, \
1583 .get = stac92xx_io_switch_get, \
1584 .put = stac92xx_io_switch_put, \
1585 .private_value = xpval, \
1586 }
1587
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02001588#define STAC_CODEC_CLFE_SWITCH(xname, xpval) \
1589 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1590 .name = xname, \
1591 .index = 0, \
1592 .info = stac92xx_clfe_switch_info, \
1593 .get = stac92xx_clfe_switch_get, \
1594 .put = stac92xx_clfe_switch_put, \
1595 .private_value = xpval, \
1596 }
Matt Porter403d1942005-11-29 15:00:51 +01001597
Mattc7d4b2f2005-06-27 14:59:41 +02001598enum {
1599 STAC_CTL_WIDGET_VOL,
1600 STAC_CTL_WIDGET_MUTE,
Matt Porter403d1942005-11-29 15:00:51 +01001601 STAC_CTL_WIDGET_IO_SWITCH,
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02001602 STAC_CTL_WIDGET_CLFE_SWITCH
Mattc7d4b2f2005-06-27 14:59:41 +02001603};
1604
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001605static struct snd_kcontrol_new stac92xx_control_templates[] = {
Mattc7d4b2f2005-06-27 14:59:41 +02001606 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
1607 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Matt Porter403d1942005-11-29 15:00:51 +01001608 STAC_CODEC_IO_SWITCH(NULL, 0),
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02001609 STAC_CODEC_CLFE_SWITCH(NULL, 0),
Mattc7d4b2f2005-06-27 14:59:41 +02001610};
1611
1612/* add dynamic controls */
1613static int stac92xx_add_control(struct sigmatel_spec *spec, int type, const char *name, unsigned long val)
1614{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001615 struct snd_kcontrol_new *knew;
Mattc7d4b2f2005-06-27 14:59:41 +02001616
1617 if (spec->num_kctl_used >= spec->num_kctl_alloc) {
1618 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
1619
1620 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */
1621 if (! knew)
1622 return -ENOMEM;
1623 if (spec->kctl_alloc) {
1624 memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
1625 kfree(spec->kctl_alloc);
1626 }
1627 spec->kctl_alloc = knew;
1628 spec->num_kctl_alloc = num;
1629 }
1630
1631 knew = &spec->kctl_alloc[spec->num_kctl_used];
1632 *knew = stac92xx_control_templates[type];
Takashi Iwai82fe0c52005-06-30 10:54:33 +02001633 knew->name = kstrdup(name, GFP_KERNEL);
Mattc7d4b2f2005-06-27 14:59:41 +02001634 if (! knew->name)
1635 return -ENOMEM;
1636 knew->private_value = val;
1637 spec->num_kctl_used++;
1638 return 0;
1639}
1640
Matt Porter403d1942005-11-29 15:00:51 +01001641/* flag inputs as additional dynamic lineouts */
1642static int stac92xx_add_dyn_out_pins(struct hda_codec *codec, struct auto_pin_cfg *cfg)
1643{
1644 struct sigmatel_spec *spec = codec->spec;
Steve Longerbeam7b0438992007-05-03 20:50:03 +02001645 unsigned int wcaps, wtype;
1646 int i, num_dacs = 0;
1647
1648 /* use the wcaps cache to count all DACs available for line-outs */
1649 for (i = 0; i < codec->num_nodes; i++) {
1650 wcaps = codec->wcaps[i];
1651 wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
1652 if (wtype == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL))
1653 num_dacs++;
1654 }
Matt Porter403d1942005-11-29 15:00:51 +01001655
Steve Longerbeam7b0438992007-05-03 20:50:03 +02001656 snd_printdd("%s: total dac count=%d\n", __func__, num_dacs);
1657
Matt Porter403d1942005-11-29 15:00:51 +01001658 switch (cfg->line_outs) {
1659 case 3:
1660 /* add line-in as side */
Steve Longerbeam7b0438992007-05-03 20:50:03 +02001661 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 3) {
Takashi Iwaic480f792007-09-03 09:43:38 +02001662 cfg->line_out_pins[cfg->line_outs] =
1663 cfg->input_pins[AUTO_PIN_LINE];
Matt Porter403d1942005-11-29 15:00:51 +01001664 spec->line_switch = 1;
1665 cfg->line_outs++;
1666 }
1667 break;
1668 case 2:
1669 /* add line-in as clfe and mic as side */
Steve Longerbeam7b0438992007-05-03 20:50:03 +02001670 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 2) {
Takashi Iwaic480f792007-09-03 09:43:38 +02001671 cfg->line_out_pins[cfg->line_outs] =
1672 cfg->input_pins[AUTO_PIN_LINE];
Matt Porter403d1942005-11-29 15:00:51 +01001673 spec->line_switch = 1;
1674 cfg->line_outs++;
1675 }
Steve Longerbeam7b0438992007-05-03 20:50:03 +02001676 if (cfg->input_pins[AUTO_PIN_MIC] && num_dacs > 3) {
Takashi Iwaic480f792007-09-03 09:43:38 +02001677 cfg->line_out_pins[cfg->line_outs] =
1678 cfg->input_pins[AUTO_PIN_MIC];
Matt Porter403d1942005-11-29 15:00:51 +01001679 spec->mic_switch = 1;
1680 cfg->line_outs++;
1681 }
1682 break;
1683 case 1:
1684 /* add line-in as surr and mic as clfe */
Steve Longerbeam7b0438992007-05-03 20:50:03 +02001685 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 1) {
Takashi Iwaic480f792007-09-03 09:43:38 +02001686 cfg->line_out_pins[cfg->line_outs] =
1687 cfg->input_pins[AUTO_PIN_LINE];
Matt Porter403d1942005-11-29 15:00:51 +01001688 spec->line_switch = 1;
1689 cfg->line_outs++;
1690 }
Steve Longerbeam7b0438992007-05-03 20:50:03 +02001691 if (cfg->input_pins[AUTO_PIN_MIC] && num_dacs > 2) {
Takashi Iwaic480f792007-09-03 09:43:38 +02001692 cfg->line_out_pins[cfg->line_outs] =
1693 cfg->input_pins[AUTO_PIN_MIC];
Matt Porter403d1942005-11-29 15:00:51 +01001694 spec->mic_switch = 1;
1695 cfg->line_outs++;
1696 }
1697 break;
1698 }
1699
1700 return 0;
1701}
1702
Steve Longerbeam7b0438992007-05-03 20:50:03 +02001703
1704static int is_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
1705{
1706 int i;
1707
1708 for (i = 0; i < spec->multiout.num_dacs; i++) {
1709 if (spec->multiout.dac_nids[i] == nid)
1710 return 1;
1711 }
1712
1713 return 0;
1714}
1715
Matt Porter3cc08dc2006-01-23 15:27:49 +01001716/*
Steve Longerbeam7b0438992007-05-03 20:50:03 +02001717 * Fill in the dac_nids table from the parsed pin configuration
1718 * This function only works when every pin in line_out_pins[]
1719 * contains atleast one DAC in its connection list. Some 92xx
1720 * codecs are not connected directly to a DAC, such as the 9200
1721 * and 9202/925x. For those, dac_nids[] must be hard-coded.
Matt Porter3cc08dc2006-01-23 15:27:49 +01001722 */
Takashi Iwai19039bd2006-06-28 15:52:16 +02001723static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec,
Takashi Iwaidf802952007-07-02 19:18:00 +02001724 struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02001725{
1726 struct sigmatel_spec *spec = codec->spec;
Steve Longerbeam7b0438992007-05-03 20:50:03 +02001727 int i, j, conn_len = 0;
1728 hda_nid_t nid, conn[HDA_MAX_CONNECTIONS];
1729 unsigned int wcaps, wtype;
1730
Mattc7d4b2f2005-06-27 14:59:41 +02001731 for (i = 0; i < cfg->line_outs; i++) {
1732 nid = cfg->line_out_pins[i];
Steve Longerbeam7b0438992007-05-03 20:50:03 +02001733 conn_len = snd_hda_get_connections(codec, nid, conn,
1734 HDA_MAX_CONNECTIONS);
1735 for (j = 0; j < conn_len; j++) {
1736 wcaps = snd_hda_param_read(codec, conn[j],
1737 AC_PAR_AUDIO_WIDGET_CAP);
1738 wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
1739
1740 if (wtype != AC_WID_AUD_OUT ||
1741 (wcaps & AC_WCAP_DIGITAL))
1742 continue;
1743 /* conn[j] is a DAC routed to this line-out */
1744 if (!is_in_dac_nids(spec, conn[j]))
1745 break;
1746 }
1747
1748 if (j == conn_len) {
Takashi Iwaidf802952007-07-02 19:18:00 +02001749 if (spec->multiout.num_dacs > 0) {
1750 /* we have already working output pins,
1751 * so let's drop the broken ones again
1752 */
1753 cfg->line_outs = spec->multiout.num_dacs;
1754 break;
1755 }
Steve Longerbeam7b0438992007-05-03 20:50:03 +02001756 /* error out, no available DAC found */
1757 snd_printk(KERN_ERR
1758 "%s: No available DAC for pin 0x%x\n",
1759 __func__, nid);
1760 return -ENODEV;
1761 }
1762
1763 spec->multiout.dac_nids[i] = conn[j];
1764 spec->multiout.num_dacs++;
1765 if (conn_len > 1) {
1766 /* select this DAC in the pin's input mux */
Takashi Iwai82beb8f2007-08-10 17:09:26 +02001767 snd_hda_codec_write_cache(codec, nid, 0,
1768 AC_VERB_SET_CONNECT_SEL, j);
Steve Longerbeam7b0438992007-05-03 20:50:03 +02001769
1770 }
Mattc7d4b2f2005-06-27 14:59:41 +02001771 }
1772
Steve Longerbeam7b0438992007-05-03 20:50:03 +02001773 snd_printd("dac_nids=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
1774 spec->multiout.num_dacs,
1775 spec->multiout.dac_nids[0],
1776 spec->multiout.dac_nids[1],
1777 spec->multiout.dac_nids[2],
1778 spec->multiout.dac_nids[3],
1779 spec->multiout.dac_nids[4]);
Mattc7d4b2f2005-06-27 14:59:41 +02001780 return 0;
1781}
1782
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001783/* create volume control/switch for the given prefx type */
1784static int create_controls(struct sigmatel_spec *spec, const char *pfx, hda_nid_t nid, int chs)
1785{
1786 char name[32];
1787 int err;
1788
1789 sprintf(name, "%s Playback Volume", pfx);
1790 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, name,
1791 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1792 if (err < 0)
1793 return err;
1794 sprintf(name, "%s Playback Switch", pfx);
1795 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, name,
1796 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1797 if (err < 0)
1798 return err;
1799 return 0;
1800}
1801
Mattc7d4b2f2005-06-27 14:59:41 +02001802/* add playback controls from the parsed DAC table */
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02001803static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
Takashi Iwai19039bd2006-06-28 15:52:16 +02001804 const struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02001805{
Takashi Iwai19039bd2006-06-28 15:52:16 +02001806 static const char *chname[4] = {
1807 "Front", "Surround", NULL /*CLFE*/, "Side"
1808 };
Mattc7d4b2f2005-06-27 14:59:41 +02001809 hda_nid_t nid;
1810 int i, err;
1811
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02001812 struct sigmatel_spec *spec = codec->spec;
1813 unsigned int wid_caps;
1814
1815
Mattc7d4b2f2005-06-27 14:59:41 +02001816 for (i = 0; i < cfg->line_outs; i++) {
Matt Porter403d1942005-11-29 15:00:51 +01001817 if (!spec->multiout.dac_nids[i])
Mattc7d4b2f2005-06-27 14:59:41 +02001818 continue;
1819
1820 nid = spec->multiout.dac_nids[i];
1821
1822 if (i == 2) {
1823 /* Center/LFE */
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001824 err = create_controls(spec, "Center", nid, 1);
1825 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001826 return err;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001827 err = create_controls(spec, "LFE", nid, 2);
1828 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001829 return err;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02001830
1831 wid_caps = get_wcaps(codec, nid);
1832
1833 if (wid_caps & AC_WCAP_LR_SWAP) {
1834 err = stac92xx_add_control(spec,
1835 STAC_CTL_WIDGET_CLFE_SWITCH,
1836 "Swap Center/LFE Playback Switch", nid);
1837
1838 if (err < 0)
1839 return err;
1840 }
1841
Mattc7d4b2f2005-06-27 14:59:41 +02001842 } else {
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001843 err = create_controls(spec, chname[i], nid, 3);
1844 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001845 return err;
1846 }
1847 }
1848
Matt Porter403d1942005-11-29 15:00:51 +01001849 if (spec->line_switch)
1850 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Line In as Output Switch", cfg->input_pins[AUTO_PIN_LINE] << 8)) < 0)
1851 return err;
1852
1853 if (spec->mic_switch)
1854 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Mic as Output Switch", (cfg->input_pins[AUTO_PIN_MIC] << 8) | 1)) < 0)
1855 return err;
1856
Mattc7d4b2f2005-06-27 14:59:41 +02001857 return 0;
1858}
1859
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001860static int check_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
1861{
Steve Longerbeam7b0438992007-05-03 20:50:03 +02001862 if (is_in_dac_nids(spec, nid))
1863 return 1;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001864 if (spec->multiout.hp_nid == nid)
1865 return 1;
1866 return 0;
1867}
1868
1869static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
1870{
1871 if (!spec->multiout.hp_nid)
1872 spec->multiout.hp_nid = nid;
1873 else if (spec->multiout.num_dacs > 4) {
1874 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
1875 return 1;
1876 } else {
1877 spec->multiout.dac_nids[spec->multiout.num_dacs] = nid;
1878 spec->multiout.num_dacs++;
1879 }
1880 return 0;
1881}
1882
1883/* add playback controls for Speaker and HP outputs */
1884static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
1885 struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02001886{
1887 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02001888 hda_nid_t nid;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001889 int i, old_num_dacs, err;
Mattc7d4b2f2005-06-27 14:59:41 +02001890
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001891 old_num_dacs = spec->multiout.num_dacs;
1892 for (i = 0; i < cfg->hp_outs; i++) {
1893 unsigned int wid_caps = get_wcaps(codec, cfg->hp_pins[i]);
1894 if (wid_caps & AC_WCAP_UNSOL_CAP)
1895 spec->hp_detect = 1;
1896 nid = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
1897 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
1898 if (check_in_dac_nids(spec, nid))
1899 nid = 0;
1900 if (! nid)
Mattc7d4b2f2005-06-27 14:59:41 +02001901 continue;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001902 add_spec_dacs(spec, nid);
1903 }
1904 for (i = 0; i < cfg->speaker_outs; i++) {
Steve Longerbeam7b0438992007-05-03 20:50:03 +02001905 nid = snd_hda_codec_read(codec, cfg->speaker_pins[i], 0,
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001906 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
1907 if (check_in_dac_nids(spec, nid))
1908 nid = 0;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001909 if (! nid)
1910 continue;
1911 add_spec_dacs(spec, nid);
Mattc7d4b2f2005-06-27 14:59:41 +02001912 }
Matthew Ranostay1b290a52007-07-12 15:17:34 +02001913 for (i = 0; i < cfg->line_outs; i++) {
1914 nid = snd_hda_codec_read(codec, cfg->line_out_pins[i], 0,
1915 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
1916 if (check_in_dac_nids(spec, nid))
1917 nid = 0;
1918 if (! nid)
1919 continue;
1920 add_spec_dacs(spec, nid);
1921 }
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001922 for (i = old_num_dacs; i < spec->multiout.num_dacs; i++) {
1923 static const char *pfxs[] = {
1924 "Speaker", "External Speaker", "Speaker2",
1925 };
1926 err = create_controls(spec, pfxs[i - old_num_dacs],
1927 spec->multiout.dac_nids[i], 3);
1928 if (err < 0)
1929 return err;
1930 }
1931 if (spec->multiout.hp_nid) {
1932 const char *pfx;
1933 if (old_num_dacs == spec->multiout.num_dacs)
1934 pfx = "Master";
1935 else
1936 pfx = "Headphone";
1937 err = create_controls(spec, pfx, spec->multiout.hp_nid, 3);
1938 if (err < 0)
1939 return err;
1940 }
Mattc7d4b2f2005-06-27 14:59:41 +02001941
1942 return 0;
1943}
1944
Matt Porter8b657272006-10-26 17:12:59 +02001945/* labels for dmic mux inputs */
Adrian Bunkddc2cec2006-11-20 12:03:44 +01001946static const char *stac92xx_dmic_labels[5] = {
Matt Porter8b657272006-10-26 17:12:59 +02001947 "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
1948 "Digital Mic 3", "Digital Mic 4"
1949};
1950
1951/* create playback/capture controls for input pins on dmic capable codecs */
1952static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
1953 const struct auto_pin_cfg *cfg)
1954{
1955 struct sigmatel_spec *spec = codec->spec;
1956 struct hda_input_mux *dimux = &spec->private_dimux;
1957 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
1958 int i, j;
1959
1960 dimux->items[dimux->num_items].label = stac92xx_dmic_labels[0];
1961 dimux->items[dimux->num_items].index = 0;
1962 dimux->num_items++;
1963
1964 for (i = 0; i < spec->num_dmics; i++) {
1965 int index;
1966 int num_cons;
1967 unsigned int def_conf;
1968
1969 def_conf = snd_hda_codec_read(codec,
1970 spec->dmic_nids[i],
1971 0,
1972 AC_VERB_GET_CONFIG_DEFAULT,
1973 0);
1974 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
1975 continue;
1976
1977 num_cons = snd_hda_get_connections(codec,
1978 spec->dmux_nid,
1979 con_lst,
1980 HDA_MAX_NUM_INPUTS);
1981 for (j = 0; j < num_cons; j++)
1982 if (con_lst[j] == spec->dmic_nids[i]) {
1983 index = j;
1984 goto found;
1985 }
1986 continue;
1987found:
1988 dimux->items[dimux->num_items].label =
1989 stac92xx_dmic_labels[dimux->num_items];
1990 dimux->items[dimux->num_items].index = index;
1991 dimux->num_items++;
1992 }
1993
1994 return 0;
1995}
1996
Mattc7d4b2f2005-06-27 14:59:41 +02001997/* create playback/capture controls for input pins */
1998static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
1999{
2000 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02002001 struct hda_input_mux *imux = &spec->private_imux;
2002 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
2003 int i, j, k;
2004
2005 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwai314634b2006-09-21 11:56:18 +02002006 int index;
Mattc7d4b2f2005-06-27 14:59:41 +02002007
Takashi Iwai314634b2006-09-21 11:56:18 +02002008 if (!cfg->input_pins[i])
2009 continue;
2010 index = -1;
2011 for (j = 0; j < spec->num_muxes; j++) {
2012 int num_cons;
2013 num_cons = snd_hda_get_connections(codec,
2014 spec->mux_nids[j],
2015 con_lst,
2016 HDA_MAX_NUM_INPUTS);
2017 for (k = 0; k < num_cons; k++)
2018 if (con_lst[k] == cfg->input_pins[i]) {
2019 index = k;
2020 goto found;
2021 }
Mattc7d4b2f2005-06-27 14:59:41 +02002022 }
Takashi Iwai314634b2006-09-21 11:56:18 +02002023 continue;
2024 found:
2025 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
2026 imux->items[imux->num_items].index = index;
2027 imux->num_items++;
Mattc7d4b2f2005-06-27 14:59:41 +02002028 }
2029
Steve Longerbeam7b0438992007-05-03 20:50:03 +02002030 if (imux->num_items) {
Sam Revitch62fe78e2006-05-10 15:09:17 +02002031 /*
2032 * Set the current input for the muxes.
2033 * The STAC9221 has two input muxes with identical source
2034 * NID lists. Hopefully this won't get confused.
2035 */
2036 for (i = 0; i < spec->num_muxes; i++) {
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002037 snd_hda_codec_write_cache(codec, spec->mux_nids[i], 0,
2038 AC_VERB_SET_CONNECT_SEL,
2039 imux->items[0].index);
Sam Revitch62fe78e2006-05-10 15:09:17 +02002040 }
2041 }
2042
Mattc7d4b2f2005-06-27 14:59:41 +02002043 return 0;
2044}
2045
Mattc7d4b2f2005-06-27 14:59:41 +02002046static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
2047{
2048 struct sigmatel_spec *spec = codec->spec;
2049 int i;
2050
2051 for (i = 0; i < spec->autocfg.line_outs; i++) {
2052 hda_nid_t nid = spec->autocfg.line_out_pins[i];
2053 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
2054 }
2055}
2056
2057static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
2058{
2059 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002060 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02002061
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002062 for (i = 0; i < spec->autocfg.hp_outs; i++) {
2063 hda_nid_t pin;
2064 pin = spec->autocfg.hp_pins[i];
2065 if (pin) /* connect to front */
2066 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
2067 }
2068 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
2069 hda_nid_t pin;
2070 pin = spec->autocfg.speaker_pins[i];
2071 if (pin) /* connect to front */
2072 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
2073 }
Mattc7d4b2f2005-06-27 14:59:41 +02002074}
2075
Matt Porter3cc08dc2006-01-23 15:27:49 +01002076static 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 +02002077{
2078 struct sigmatel_spec *spec = codec->spec;
2079 int err;
2080
Matt Porter8b657272006-10-26 17:12:59 +02002081 if ((err = snd_hda_parse_pin_def_config(codec,
2082 &spec->autocfg,
2083 spec->dmic_nids)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02002084 return err;
Takashi Iwai82bc9552006-03-21 11:24:42 +01002085 if (! spec->autocfg.line_outs)
Matt Porter869264c2006-01-25 19:20:50 +01002086 return 0; /* can't find valid pin config */
Takashi Iwai19039bd2006-06-28 15:52:16 +02002087
Matt Porter403d1942005-11-29 15:00:51 +01002088 if ((err = stac92xx_add_dyn_out_pins(codec, &spec->autocfg)) < 0)
2089 return err;
Takashi Iwai19039bd2006-06-28 15:52:16 +02002090 if (spec->multiout.num_dacs == 0)
2091 if ((err = stac92xx_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
2092 return err;
Mattc7d4b2f2005-06-27 14:59:41 +02002093
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002094 err = stac92xx_auto_create_multi_out_ctls(codec, &spec->autocfg);
2095
2096 if (err < 0)
2097 return err;
2098
2099 err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg);
2100
2101 if (err < 0)
2102 return err;
2103
2104 err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg);
2105
2106 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02002107 return err;
2108
Matt Porter8b657272006-10-26 17:12:59 +02002109 if (spec->num_dmics > 0)
2110 if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
2111 &spec->autocfg)) < 0)
2112 return err;
2113
Mattc7d4b2f2005-06-27 14:59:41 +02002114 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Matt Porter403d1942005-11-29 15:00:51 +01002115 if (spec->multiout.max_channels > 2)
Mattc7d4b2f2005-06-27 14:59:41 +02002116 spec->surr_switch = 1;
Mattc7d4b2f2005-06-27 14:59:41 +02002117
Takashi Iwai82bc9552006-03-21 11:24:42 +01002118 if (spec->autocfg.dig_out_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01002119 spec->multiout.dig_out_nid = dig_out;
Takashi Iwai82bc9552006-03-21 11:24:42 +01002120 if (spec->autocfg.dig_in_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01002121 spec->dig_in_nid = dig_in;
Mattc7d4b2f2005-06-27 14:59:41 +02002122
2123 if (spec->kctl_alloc)
2124 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
2125
2126 spec->input_mux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02002127 spec->dinput_mux = &spec->private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +02002128
2129 return 1;
2130}
2131
Takashi Iwai82bc9552006-03-21 11:24:42 +01002132/* add playback controls for HP output */
2133static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
2134 struct auto_pin_cfg *cfg)
2135{
2136 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002137 hda_nid_t pin = cfg->hp_pins[0];
Takashi Iwai82bc9552006-03-21 11:24:42 +01002138 unsigned int wid_caps;
2139
2140 if (! pin)
2141 return 0;
2142
2143 wid_caps = get_wcaps(codec, pin);
Takashi Iwai505cb342006-03-27 12:51:52 +02002144 if (wid_caps & AC_WCAP_UNSOL_CAP)
Takashi Iwai82bc9552006-03-21 11:24:42 +01002145 spec->hp_detect = 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +01002146
2147 return 0;
2148}
2149
Richard Fish160ea0d2006-09-06 13:58:25 +02002150/* add playback controls for LFE output */
2151static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
2152 struct auto_pin_cfg *cfg)
2153{
2154 struct sigmatel_spec *spec = codec->spec;
2155 int err;
2156 hda_nid_t lfe_pin = 0x0;
2157 int i;
2158
2159 /*
2160 * search speaker outs and line outs for a mono speaker pin
2161 * with an amp. If one is found, add LFE controls
2162 * for it.
2163 */
2164 for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
2165 hda_nid_t pin = spec->autocfg.speaker_pins[i];
2166 unsigned long wcaps = get_wcaps(codec, pin);
2167 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
2168 if (wcaps == AC_WCAP_OUT_AMP)
2169 /* found a mono speaker with an amp, must be lfe */
2170 lfe_pin = pin;
2171 }
2172
2173 /* if speaker_outs is 0, then speakers may be in line_outs */
2174 if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
2175 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
2176 hda_nid_t pin = spec->autocfg.line_out_pins[i];
2177 unsigned long cfg;
2178 cfg = snd_hda_codec_read(codec, pin, 0,
2179 AC_VERB_GET_CONFIG_DEFAULT,
2180 0x00);
2181 if (get_defcfg_device(cfg) == AC_JACK_SPEAKER) {
2182 unsigned long wcaps = get_wcaps(codec, pin);
2183 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
2184 if (wcaps == AC_WCAP_OUT_AMP)
2185 /* found a mono speaker with an amp,
2186 must be lfe */
2187 lfe_pin = pin;
2188 }
2189 }
2190 }
2191
2192 if (lfe_pin) {
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002193 err = create_controls(spec, "LFE", lfe_pin, 1);
Richard Fish160ea0d2006-09-06 13:58:25 +02002194 if (err < 0)
2195 return err;
2196 }
2197
2198 return 0;
2199}
2200
Mattc7d4b2f2005-06-27 14:59:41 +02002201static int stac9200_parse_auto_config(struct hda_codec *codec)
2202{
2203 struct sigmatel_spec *spec = codec->spec;
2204 int err;
2205
Kailang Yangdf694da2005-12-05 19:42:22 +01002206 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02002207 return err;
2208
2209 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
2210 return err;
2211
Takashi Iwai82bc9552006-03-21 11:24:42 +01002212 if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
2213 return err;
2214
Richard Fish160ea0d2006-09-06 13:58:25 +02002215 if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
2216 return err;
2217
Takashi Iwai82bc9552006-03-21 11:24:42 +01002218 if (spec->autocfg.dig_out_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02002219 spec->multiout.dig_out_nid = 0x05;
Takashi Iwai82bc9552006-03-21 11:24:42 +01002220 if (spec->autocfg.dig_in_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02002221 spec->dig_in_nid = 0x04;
Mattc7d4b2f2005-06-27 14:59:41 +02002222
2223 if (spec->kctl_alloc)
2224 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
2225
2226 spec->input_mux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02002227 spec->dinput_mux = &spec->private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +02002228
2229 return 1;
2230}
2231
Sam Revitch62fe78e2006-05-10 15:09:17 +02002232/*
2233 * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
2234 * funky external mute control using GPIO pins.
2235 */
2236
2237static void stac922x_gpio_mute(struct hda_codec *codec, int pin, int muted)
2238{
2239 unsigned int gpiostate, gpiomask, gpiodir;
2240
2241 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
2242 AC_VERB_GET_GPIO_DATA, 0);
2243
2244 if (!muted)
2245 gpiostate |= (1 << pin);
2246 else
2247 gpiostate &= ~(1 << pin);
2248
2249 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
2250 AC_VERB_GET_GPIO_MASK, 0);
2251 gpiomask |= (1 << pin);
2252
2253 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
2254 AC_VERB_GET_GPIO_DIRECTION, 0);
2255 gpiodir |= (1 << pin);
2256
2257 /* AppleHDA seems to do this -- WTF is this verb?? */
2258 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
2259
2260 snd_hda_codec_write(codec, codec->afg, 0,
2261 AC_VERB_SET_GPIO_MASK, gpiomask);
2262 snd_hda_codec_write(codec, codec->afg, 0,
2263 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
2264
2265 msleep(1);
2266
2267 snd_hda_codec_write(codec, codec->afg, 0,
2268 AC_VERB_SET_GPIO_DATA, gpiostate);
2269}
2270
Takashi Iwai314634b2006-09-21 11:56:18 +02002271static void enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
2272 unsigned int event)
2273{
2274 if (get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP)
Takashi Iwaidc81bed2007-09-03 09:36:36 +02002275 snd_hda_codec_write_cache(codec, nid, 0,
2276 AC_VERB_SET_UNSOLICITED_ENABLE,
2277 (AC_USRSP_EN | event));
Takashi Iwai314634b2006-09-21 11:56:18 +02002278}
2279
Mattc7d4b2f2005-06-27 14:59:41 +02002280static int stac92xx_init(struct hda_codec *codec)
2281{
2282 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai82bc9552006-03-21 11:24:42 +01002283 struct auto_pin_cfg *cfg = &spec->autocfg;
2284 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02002285
Mattc7d4b2f2005-06-27 14:59:41 +02002286 snd_hda_sequence_write(codec, spec->init);
2287
Takashi Iwai82bc9552006-03-21 11:24:42 +01002288 /* set up pins */
2289 if (spec->hp_detect) {
Takashi Iwai505cb342006-03-27 12:51:52 +02002290 /* Enable unsolicited responses on the HP widget */
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002291 for (i = 0; i < cfg->hp_outs; i++)
Takashi Iwai314634b2006-09-21 11:56:18 +02002292 enable_pin_detect(codec, cfg->hp_pins[i],
2293 STAC_HP_EVENT);
Takashi Iwai0a07acaf2007-03-13 10:40:23 +01002294 /* force to enable the first line-out; the others are set up
2295 * in unsol_event
2296 */
2297 stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
2298 AC_PINCTL_OUT_EN);
Takashi Iwaieb995a82006-09-21 14:28:21 +02002299 stac92xx_auto_init_hp_out(codec);
Takashi Iwai82bc9552006-03-21 11:24:42 +01002300 /* fake event to set up pins */
2301 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
2302 } else {
2303 stac92xx_auto_init_multi_out(codec);
2304 stac92xx_auto_init_hp_out(codec);
2305 }
2306 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwaic960a032006-03-23 17:06:28 +01002307 hda_nid_t nid = cfg->input_pins[i];
2308 if (nid) {
2309 unsigned int pinctl = AC_PINCTL_IN_EN;
2310 if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC)
2311 pinctl |= stac92xx_get_vref(codec, nid);
2312 stac92xx_auto_set_pinctl(codec, nid, pinctl);
2313 }
Takashi Iwai82bc9552006-03-21 11:24:42 +01002314 }
Matt Porter8b657272006-10-26 17:12:59 +02002315 if (spec->num_dmics > 0)
2316 for (i = 0; i < spec->num_dmics; i++)
2317 stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
2318 AC_PINCTL_IN_EN);
2319
Takashi Iwai82bc9552006-03-21 11:24:42 +01002320 if (cfg->dig_out_pin)
2321 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pin,
2322 AC_PINCTL_OUT_EN);
2323 if (cfg->dig_in_pin)
2324 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
2325 AC_PINCTL_IN_EN);
2326
Sam Revitch62fe78e2006-05-10 15:09:17 +02002327 if (spec->gpio_mute) {
2328 stac922x_gpio_mute(codec, 0, 0);
2329 stac922x_gpio_mute(codec, 1, 0);
2330 }
2331
Mattc7d4b2f2005-06-27 14:59:41 +02002332 return 0;
2333}
2334
Matt2f2f4252005-04-13 14:45:30 +02002335static void stac92xx_free(struct hda_codec *codec)
2336{
Mattc7d4b2f2005-06-27 14:59:41 +02002337 struct sigmatel_spec *spec = codec->spec;
2338 int i;
2339
2340 if (! spec)
2341 return;
2342
2343 if (spec->kctl_alloc) {
2344 for (i = 0; i < spec->num_kctl_used; i++)
2345 kfree(spec->kctl_alloc[i].name);
2346 kfree(spec->kctl_alloc);
2347 }
2348
Richard Fish11b44bb2006-08-23 18:31:34 +02002349 if (spec->bios_pin_configs)
2350 kfree(spec->bios_pin_configs);
2351
Mattc7d4b2f2005-06-27 14:59:41 +02002352 kfree(spec);
Matt2f2f4252005-04-13 14:45:30 +02002353}
2354
Matt4e550962005-07-04 17:51:39 +02002355static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
2356 unsigned int flag)
2357{
2358 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
2359 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Steve Longerbeam7b0438992007-05-03 20:50:03 +02002360
Takashi Iwaif9acba42007-05-29 18:01:06 +02002361 if (pin_ctl & AC_PINCTL_IN_EN) {
2362 /*
2363 * we need to check the current set-up direction of
2364 * shared input pins since they can be switched via
2365 * "xxx as Output" mixer switch
2366 */
2367 struct sigmatel_spec *spec = codec->spec;
2368 struct auto_pin_cfg *cfg = &spec->autocfg;
2369 if ((nid == cfg->input_pins[AUTO_PIN_LINE] &&
2370 spec->line_switch) ||
2371 (nid == cfg->input_pins[AUTO_PIN_MIC] &&
2372 spec->mic_switch))
2373 return;
2374 }
2375
Steve Longerbeam7b0438992007-05-03 20:50:03 +02002376 /* if setting pin direction bits, clear the current
2377 direction bits first */
2378 if (flag & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))
2379 pin_ctl &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
2380
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002381 snd_hda_codec_write_cache(codec, nid, 0,
Matt4e550962005-07-04 17:51:39 +02002382 AC_VERB_SET_PIN_WIDGET_CONTROL,
2383 pin_ctl | flag);
2384}
2385
2386static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
2387 unsigned int flag)
2388{
2389 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
2390 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002391 snd_hda_codec_write_cache(codec, nid, 0,
Matt4e550962005-07-04 17:51:39 +02002392 AC_VERB_SET_PIN_WIDGET_CONTROL,
2393 pin_ctl & ~flag);
2394}
2395
Takashi Iwai314634b2006-09-21 11:56:18 +02002396static int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
2397{
2398 if (!nid)
2399 return 0;
2400 if (snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PIN_SENSE, 0x00)
2401 & (1 << 31))
2402 return 1;
2403 return 0;
2404}
2405
2406static void stac92xx_hp_detect(struct hda_codec *codec, unsigned int res)
Matt4e550962005-07-04 17:51:39 +02002407{
2408 struct sigmatel_spec *spec = codec->spec;
2409 struct auto_pin_cfg *cfg = &spec->autocfg;
2410 int i, presence;
2411
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002412 presence = 0;
2413 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai314634b2006-09-21 11:56:18 +02002414 presence = get_pin_presence(codec, cfg->hp_pins[i]);
2415 if (presence)
2416 break;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002417 }
Matt4e550962005-07-04 17:51:39 +02002418
2419 if (presence) {
2420 /* disable lineouts, enable hp */
2421 for (i = 0; i < cfg->line_outs; i++)
2422 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
2423 AC_PINCTL_OUT_EN);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002424 for (i = 0; i < cfg->speaker_outs; i++)
2425 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
2426 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02002427 } else {
2428 /* enable lineouts, disable hp */
2429 for (i = 0; i < cfg->line_outs; i++)
2430 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
2431 AC_PINCTL_OUT_EN);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002432 for (i = 0; i < cfg->speaker_outs; i++)
2433 stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
2434 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02002435 }
2436}
2437
Takashi Iwai314634b2006-09-21 11:56:18 +02002438static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
2439{
2440 switch (res >> 26) {
2441 case STAC_HP_EVENT:
2442 stac92xx_hp_detect(codec, res);
2443 break;
2444 }
2445}
2446
Takashi Iwaicb53c622007-08-10 17:21:45 +02002447#ifdef SND_HDA_NEEDS_RESUME
Mattff6fdc32005-06-27 15:06:52 +02002448static int stac92xx_resume(struct hda_codec *codec)
2449{
Takashi Iwaidc81bed2007-09-03 09:36:36 +02002450 struct sigmatel_spec *spec = codec->spec;
2451
Richard Fish11b44bb2006-08-23 18:31:34 +02002452 stac92xx_set_config_regs(codec);
Takashi Iwaidc81bed2007-09-03 09:36:36 +02002453 snd_hda_sequence_write(codec, spec->init);
2454 if (spec->gpio_mute) {
2455 stac922x_gpio_mute(codec, 0, 0);
2456 stac922x_gpio_mute(codec, 1, 0);
2457 }
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002458 snd_hda_codec_resume_amp(codec);
2459 snd_hda_codec_resume_cache(codec);
Takashi Iwaidc81bed2007-09-03 09:36:36 +02002460 /* invoke unsolicited event to reset the HP state */
2461 if (spec->hp_detect)
2462 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
Mattff6fdc32005-06-27 15:06:52 +02002463 return 0;
2464}
2465#endif
2466
Matt2f2f4252005-04-13 14:45:30 +02002467static struct hda_codec_ops stac92xx_patch_ops = {
2468 .build_controls = stac92xx_build_controls,
2469 .build_pcms = stac92xx_build_pcms,
2470 .init = stac92xx_init,
2471 .free = stac92xx_free,
Matt4e550962005-07-04 17:51:39 +02002472 .unsol_event = stac92xx_unsol_event,
Takashi Iwaicb53c622007-08-10 17:21:45 +02002473#ifdef SND_HDA_NEEDS_RESUME
Mattff6fdc32005-06-27 15:06:52 +02002474 .resume = stac92xx_resume,
2475#endif
Matt2f2f4252005-04-13 14:45:30 +02002476};
2477
2478static int patch_stac9200(struct hda_codec *codec)
2479{
2480 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02002481 int err;
Matt2f2f4252005-04-13 14:45:30 +02002482
Takashi Iwaie560d8d2005-09-09 14:21:46 +02002483 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02002484 if (spec == NULL)
2485 return -ENOMEM;
2486
2487 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02002488 spec->num_pins = ARRAY_SIZE(stac9200_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02002489 spec->pin_nids = stac9200_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002490 spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS,
2491 stac9200_models,
2492 stac9200_cfg_tbl);
Richard Fish11b44bb2006-08-23 18:31:34 +02002493 if (spec->board_config < 0) {
2494 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9200, using BIOS defaults\n");
2495 err = stac92xx_save_bios_config_regs(codec);
2496 if (err < 0) {
2497 stac92xx_free(codec);
2498 return err;
2499 }
2500 spec->pin_configs = spec->bios_pin_configs;
2501 } else {
Matt Porter403d1942005-11-29 15:00:51 +01002502 spec->pin_configs = stac9200_brd_tbl[spec->board_config];
2503 stac92xx_set_config_regs(codec);
2504 }
Matt2f2f4252005-04-13 14:45:30 +02002505
2506 spec->multiout.max_channels = 2;
2507 spec->multiout.num_dacs = 1;
2508 spec->multiout.dac_nids = stac9200_dac_nids;
2509 spec->adc_nids = stac9200_adc_nids;
2510 spec->mux_nids = stac9200_mux_nids;
Mattdabbed62005-06-14 10:19:34 +02002511 spec->num_muxes = 1;
Matt Porter8b657272006-10-26 17:12:59 +02002512 spec->num_dmics = 0;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002513 spec->num_adcs = 1;
Mattc7d4b2f2005-06-27 14:59:41 +02002514
Takashi Iwai1194b5b2007-10-10 10:04:26 +02002515 if (spec->board_config == STAC_9200_GATEWAY)
2516 spec->init = stac9200_eapd_init;
2517 else
2518 spec->init = stac9200_core_init;
Matt2f2f4252005-04-13 14:45:30 +02002519 spec->mixer = stac9200_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02002520
2521 err = stac9200_parse_auto_config(codec);
2522 if (err < 0) {
2523 stac92xx_free(codec);
2524 return err;
2525 }
Matt2f2f4252005-04-13 14:45:30 +02002526
2527 codec->patch_ops = stac92xx_patch_ops;
2528
2529 return 0;
2530}
2531
Tobin Davis8e21c342007-01-08 11:04:17 +01002532static int patch_stac925x(struct hda_codec *codec)
2533{
2534 struct sigmatel_spec *spec;
2535 int err;
2536
2537 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2538 if (spec == NULL)
2539 return -ENOMEM;
2540
2541 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02002542 spec->num_pins = ARRAY_SIZE(stac925x_pin_nids);
Tobin Davis8e21c342007-01-08 11:04:17 +01002543 spec->pin_nids = stac925x_pin_nids;
2544 spec->board_config = snd_hda_check_board_config(codec, STAC_925x_MODELS,
2545 stac925x_models,
2546 stac925x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002547 again:
Tobin Davis8e21c342007-01-08 11:04:17 +01002548 if (spec->board_config < 0) {
Tobin Davis2c11f952007-05-17 09:36:34 +02002549 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC925x,"
2550 "using BIOS defaults\n");
Tobin Davis8e21c342007-01-08 11:04:17 +01002551 err = stac92xx_save_bios_config_regs(codec);
2552 if (err < 0) {
2553 stac92xx_free(codec);
2554 return err;
2555 }
2556 spec->pin_configs = spec->bios_pin_configs;
2557 } else if (stac925x_brd_tbl[spec->board_config] != NULL){
2558 spec->pin_configs = stac925x_brd_tbl[spec->board_config];
2559 stac92xx_set_config_regs(codec);
2560 }
2561
2562 spec->multiout.max_channels = 2;
2563 spec->multiout.num_dacs = 1;
2564 spec->multiout.dac_nids = stac925x_dac_nids;
2565 spec->adc_nids = stac925x_adc_nids;
2566 spec->mux_nids = stac925x_mux_nids;
2567 spec->num_muxes = 1;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002568 spec->num_adcs = 1;
Tobin Davis2c11f952007-05-17 09:36:34 +02002569 switch (codec->vendor_id) {
2570 case 0x83847632: /* STAC9202 */
2571 case 0x83847633: /* STAC9202D */
2572 case 0x83847636: /* STAC9251 */
2573 case 0x83847637: /* STAC9251D */
Takashi Iwaif6e98522007-10-16 14:27:04 +02002574 spec->num_dmics = STAC925X_NUM_DMICS;
Tobin Davis2c11f952007-05-17 09:36:34 +02002575 spec->dmic_nids = stac925x_dmic_nids;
2576 break;
2577 default:
2578 spec->num_dmics = 0;
2579 break;
2580 }
Tobin Davis8e21c342007-01-08 11:04:17 +01002581
2582 spec->init = stac925x_core_init;
2583 spec->mixer = stac925x_mixer;
2584
2585 err = stac92xx_parse_auto_config(codec, 0x8, 0x7);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002586 if (!err) {
2587 if (spec->board_config < 0) {
2588 printk(KERN_WARNING "hda_codec: No auto-config is "
2589 "available, default to model=ref\n");
2590 spec->board_config = STAC_925x_REF;
2591 goto again;
2592 }
2593 err = -EINVAL;
2594 }
Tobin Davis8e21c342007-01-08 11:04:17 +01002595 if (err < 0) {
2596 stac92xx_free(codec);
2597 return err;
2598 }
2599
2600 codec->patch_ops = stac92xx_patch_ops;
2601
2602 return 0;
2603}
2604
Matt2f2f4252005-04-13 14:45:30 +02002605static int patch_stac922x(struct hda_codec *codec)
2606{
2607 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02002608 int err;
Matt2f2f4252005-04-13 14:45:30 +02002609
Takashi Iwaie560d8d2005-09-09 14:21:46 +02002610 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02002611 if (spec == NULL)
2612 return -ENOMEM;
2613
2614 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02002615 spec->num_pins = ARRAY_SIZE(stac922x_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02002616 spec->pin_nids = stac922x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002617 spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS,
2618 stac922x_models,
2619 stac922x_cfg_tbl);
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002620 if (spec->board_config == STAC_INTEL_MAC_V3) {
Takashi Iwai3fc24d82007-02-16 13:27:18 +01002621 spec->gpio_mute = 1;
2622 /* Intel Macs have all same PCI SSID, so we need to check
2623 * codec SSID to distinguish the exact models
2624 */
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01002625 printk(KERN_INFO "hda_codec: STAC922x, Apple subsys_id=%x\n", codec->subsystem_id);
Takashi Iwai3fc24d82007-02-16 13:27:18 +01002626 switch (codec->subsystem_id) {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002627
2628 case 0x106b0800:
2629 spec->board_config = STAC_INTEL_MAC_V1;
Abhijit Bhopatkarc45e20e2007-04-17 11:57:16 +02002630 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002631 case 0x106b0600:
2632 case 0x106b0700:
2633 spec->board_config = STAC_INTEL_MAC_V2;
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01002634 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002635 case 0x106b0e00:
2636 case 0x106b0f00:
2637 case 0x106b1600:
2638 case 0x106b1700:
2639 case 0x106b0200:
2640 case 0x106b1e00:
2641 spec->board_config = STAC_INTEL_MAC_V3;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01002642 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002643 case 0x106b1a00:
2644 case 0x00000100:
2645 spec->board_config = STAC_INTEL_MAC_V4;
Sylvain FORETf16928f2007-04-27 14:22:36 +02002646 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002647 case 0x106b0a00:
2648 case 0x106b2200:
2649 spec->board_config = STAC_INTEL_MAC_V5;
Takashi Iwai0dae0f82007-05-21 12:41:29 +02002650 break;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01002651 }
2652 }
2653
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002654 again:
Richard Fish11b44bb2006-08-23 18:31:34 +02002655 if (spec->board_config < 0) {
2656 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC922x, "
2657 "using BIOS defaults\n");
2658 err = stac92xx_save_bios_config_regs(codec);
2659 if (err < 0) {
2660 stac92xx_free(codec);
2661 return err;
2662 }
2663 spec->pin_configs = spec->bios_pin_configs;
2664 } else if (stac922x_brd_tbl[spec->board_config] != NULL) {
Matt Porter403d1942005-11-29 15:00:51 +01002665 spec->pin_configs = stac922x_brd_tbl[spec->board_config];
2666 stac92xx_set_config_regs(codec);
2667 }
Matt2f2f4252005-04-13 14:45:30 +02002668
Matt2f2f4252005-04-13 14:45:30 +02002669 spec->adc_nids = stac922x_adc_nids;
2670 spec->mux_nids = stac922x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01002671 spec->num_muxes = ARRAY_SIZE(stac922x_mux_nids);
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002672 spec->num_adcs = ARRAY_SIZE(stac922x_adc_nids);
Matt Porter8b657272006-10-26 17:12:59 +02002673 spec->num_dmics = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02002674
2675 spec->init = stac922x_core_init;
Matt2f2f4252005-04-13 14:45:30 +02002676 spec->mixer = stac922x_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02002677
2678 spec->multiout.dac_nids = spec->dac_nids;
Takashi Iwai19039bd2006-06-28 15:52:16 +02002679
Matt Porter3cc08dc2006-01-23 15:27:49 +01002680 err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002681 if (!err) {
2682 if (spec->board_config < 0) {
2683 printk(KERN_WARNING "hda_codec: No auto-config is "
2684 "available, default to model=ref\n");
2685 spec->board_config = STAC_D945_REF;
2686 goto again;
2687 }
2688 err = -EINVAL;
2689 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01002690 if (err < 0) {
2691 stac92xx_free(codec);
2692 return err;
2693 }
2694
2695 codec->patch_ops = stac92xx_patch_ops;
2696
Takashi Iwai807a46362007-05-29 19:01:37 +02002697 /* Fix Mux capture level; max to 2 */
2698 snd_hda_override_amp_caps(codec, 0x12, HDA_OUTPUT,
2699 (0 << AC_AMPCAP_OFFSET_SHIFT) |
2700 (2 << AC_AMPCAP_NUM_STEPS_SHIFT) |
2701 (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
2702 (0 << AC_AMPCAP_MUTE_SHIFT));
2703
Matt Porter3cc08dc2006-01-23 15:27:49 +01002704 return 0;
2705}
2706
2707static int patch_stac927x(struct hda_codec *codec)
2708{
2709 struct sigmatel_spec *spec;
2710 int err;
2711
2712 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2713 if (spec == NULL)
2714 return -ENOMEM;
2715
2716 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02002717 spec->num_pins = ARRAY_SIZE(stac927x_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02002718 spec->pin_nids = stac927x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002719 spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS,
2720 stac927x_models,
2721 stac927x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002722 again:
Richard Fish11b44bb2006-08-23 18:31:34 +02002723 if (spec->board_config < 0) {
Matt Porter3cc08dc2006-01-23 15:27:49 +01002724 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC927x, using BIOS defaults\n");
Richard Fish11b44bb2006-08-23 18:31:34 +02002725 err = stac92xx_save_bios_config_regs(codec);
2726 if (err < 0) {
2727 stac92xx_free(codec);
2728 return err;
2729 }
2730 spec->pin_configs = spec->bios_pin_configs;
2731 } else if (stac927x_brd_tbl[spec->board_config] != NULL) {
Matt Porter3cc08dc2006-01-23 15:27:49 +01002732 spec->pin_configs = stac927x_brd_tbl[spec->board_config];
2733 stac92xx_set_config_regs(codec);
2734 }
2735
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002736 switch (spec->board_config) {
Tobin Davis93ed1502006-09-01 21:03:12 +02002737 case STAC_D965_3ST:
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002738 spec->adc_nids = stac927x_adc_nids;
2739 spec->mux_nids = stac927x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01002740 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002741 spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
Matt Porter8b657272006-10-26 17:12:59 +02002742 spec->num_dmics = 0;
Tobin Davis93ed1502006-09-01 21:03:12 +02002743 spec->init = d965_core_init;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002744 spec->mixer = stac927x_mixer;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002745 break;
Tobin Davis93ed1502006-09-01 21:03:12 +02002746 case STAC_D965_5ST:
2747 spec->adc_nids = stac927x_adc_nids;
2748 spec->mux_nids = stac927x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01002749 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002750 spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
Matt Porter8b657272006-10-26 17:12:59 +02002751 spec->num_dmics = 0;
Tobin Davis93ed1502006-09-01 21:03:12 +02002752 spec->init = d965_core_init;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002753 spec->mixer = stac927x_mixer;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002754 break;
2755 default:
2756 spec->adc_nids = stac927x_adc_nids;
2757 spec->mux_nids = stac927x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01002758 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002759 spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
Matt Porter8b657272006-10-26 17:12:59 +02002760 spec->num_dmics = 0;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002761 spec->init = stac927x_core_init;
2762 spec->mixer = stac927x_mixer;
2763 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01002764
2765 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostay87d48362007-07-17 11:52:24 +02002766 /* GPIO0 High = Enable EAPD */
Takashi Iwai82599802007-07-31 15:56:24 +02002767 spec->gpio_mask = spec->gpio_data = 0x00000001;
2768 stac92xx_enable_gpio_mask(codec);
Matthew Ranostay92a22be2007-06-19 16:48:28 +02002769
Matt Porter3cc08dc2006-01-23 15:27:49 +01002770 err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002771 if (!err) {
2772 if (spec->board_config < 0) {
2773 printk(KERN_WARNING "hda_codec: No auto-config is "
2774 "available, default to model=ref\n");
2775 spec->board_config = STAC_D965_REF;
2776 goto again;
2777 }
2778 err = -EINVAL;
2779 }
Mattc7d4b2f2005-06-27 14:59:41 +02002780 if (err < 0) {
2781 stac92xx_free(codec);
2782 return err;
2783 }
Matt2f2f4252005-04-13 14:45:30 +02002784
2785 codec->patch_ops = stac92xx_patch_ops;
2786
2787 return 0;
2788}
2789
Matt Porterf3302a52006-07-31 12:49:34 +02002790static int patch_stac9205(struct hda_codec *codec)
2791{
2792 struct sigmatel_spec *spec;
Takashi Iwai82599802007-07-31 15:56:24 +02002793 int err;
Matt Porterf3302a52006-07-31 12:49:34 +02002794
2795 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2796 if (spec == NULL)
2797 return -ENOMEM;
2798
2799 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02002800 spec->num_pins = ARRAY_SIZE(stac9205_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02002801 spec->pin_nids = stac9205_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002802 spec->board_config = snd_hda_check_board_config(codec, STAC_9205_MODELS,
2803 stac9205_models,
2804 stac9205_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002805 again:
Richard Fish11b44bb2006-08-23 18:31:34 +02002806 if (spec->board_config < 0) {
2807 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9205, using BIOS defaults\n");
2808 err = stac92xx_save_bios_config_regs(codec);
2809 if (err < 0) {
2810 stac92xx_free(codec);
2811 return err;
2812 }
2813 spec->pin_configs = spec->bios_pin_configs;
2814 } else {
Matt Porterf3302a52006-07-31 12:49:34 +02002815 spec->pin_configs = stac9205_brd_tbl[spec->board_config];
2816 stac92xx_set_config_regs(codec);
2817 }
2818
2819 spec->adc_nids = stac9205_adc_nids;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002820 spec->num_adcs = ARRAY_SIZE(stac9205_adc_nids);
Matt Porterf3302a52006-07-31 12:49:34 +02002821 spec->mux_nids = stac9205_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01002822 spec->num_muxes = ARRAY_SIZE(stac9205_mux_nids);
Matt Porter8b657272006-10-26 17:12:59 +02002823 spec->dmic_nids = stac9205_dmic_nids;
Takashi Iwaif6e98522007-10-16 14:27:04 +02002824 spec->num_dmics = STAC9205_NUM_DMICS;
Matt Porter8b657272006-10-26 17:12:59 +02002825 spec->dmux_nid = 0x1d;
Matt Porterf3302a52006-07-31 12:49:34 +02002826
2827 spec->init = stac9205_core_init;
2828 spec->mixer = stac9205_mixer;
2829
2830 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostay87d48362007-07-17 11:52:24 +02002831
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002832 switch (spec->board_config){
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002833 case STAC_9205_DELL_M43:
Matthew Ranostay87d48362007-07-17 11:52:24 +02002834 /* Enable SPDIF in/out */
2835 stac92xx_set_config_reg(codec, 0x1f, 0x01441030);
2836 stac92xx_set_config_reg(codec, 0x20, 0x1c410030);
Matt Porter33382402006-12-18 13:17:28 +01002837
Takashi Iwai82599802007-07-31 15:56:24 +02002838 spec->gpio_mask = 0x00000007; /* GPIO0-2 */
Matthew Ranostay87d48362007-07-17 11:52:24 +02002839 /* GPIO0 High = EAPD, GPIO1 Low = DRM,
2840 * GPIO2 High = Headphone Mute
2841 */
Takashi Iwai82599802007-07-31 15:56:24 +02002842 spec->gpio_data = 0x00000005;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002843 break;
2844 default:
2845 /* GPIO0 High = EAPD */
2846 spec->gpio_mask = spec->gpio_data = 0x00000001;
2847 break;
2848 }
Matthew Ranostay87d48362007-07-17 11:52:24 +02002849
Takashi Iwai82599802007-07-31 15:56:24 +02002850 stac92xx_enable_gpio_mask(codec);
Matt Porterf3302a52006-07-31 12:49:34 +02002851 err = stac92xx_parse_auto_config(codec, 0x1f, 0x20);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002852 if (!err) {
2853 if (spec->board_config < 0) {
2854 printk(KERN_WARNING "hda_codec: No auto-config is "
2855 "available, default to model=ref\n");
2856 spec->board_config = STAC_9205_REF;
2857 goto again;
2858 }
2859 err = -EINVAL;
2860 }
Matt Porterf3302a52006-07-31 12:49:34 +02002861 if (err < 0) {
2862 stac92xx_free(codec);
2863 return err;
2864 }
2865
2866 codec->patch_ops = stac92xx_patch_ops;
2867
2868 return 0;
2869}
2870
Matt2f2f4252005-04-13 14:45:30 +02002871/*
Guillaume Munch6d859062006-08-22 17:15:47 +02002872 * STAC9872 hack
Takashi Iwaidb064e52006-03-16 16:04:58 +01002873 */
2874
Guillaume Munch99ccc562006-08-16 19:35:12 +02002875/* static config for Sony VAIO FE550G and Sony VAIO AR */
Takashi Iwaidb064e52006-03-16 16:04:58 +01002876static hda_nid_t vaio_dacs[] = { 0x2 };
2877#define VAIO_HP_DAC 0x5
2878static hda_nid_t vaio_adcs[] = { 0x8 /*,0x6*/ };
2879static hda_nid_t vaio_mux_nids[] = { 0x15 };
2880
2881static struct hda_input_mux vaio_mux = {
Takashi Iwaia3a2f422007-10-11 11:21:21 +02002882 .num_items = 3,
Takashi Iwaidb064e52006-03-16 16:04:58 +01002883 .items = {
Takashi Iwaid7737812006-04-25 13:05:43 +02002884 /* { "HP", 0x0 }, */
Takashi Iwai1624cb92007-07-05 13:10:51 +02002885 { "Mic Jack", 0x1 },
2886 { "Internal Mic", 0x2 },
Takashi Iwaidb064e52006-03-16 16:04:58 +01002887 { "PCM", 0x3 },
2888 }
2889};
2890
2891static struct hda_verb vaio_init[] = {
2892 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
Takashi Iwai72e7b0d2007-08-16 17:33:55 +02002893 {0x0a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | STAC_HP_EVENT},
Takashi Iwaidb064e52006-03-16 16:04:58 +01002894 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
2895 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
2896 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
2897 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
Takashi Iwai1624cb92007-07-05 13:10:51 +02002898 {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
Takashi Iwaidb064e52006-03-16 16:04:58 +01002899 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
2900 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
2901 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
2902 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
2903 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
2904 {}
2905};
2906
Guillaume Munch6d859062006-08-22 17:15:47 +02002907static struct hda_verb vaio_ar_init[] = {
2908 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
2909 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
2910 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
2911 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
2912/* {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },*/ /* Optical Out */
2913 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
Takashi Iwai1624cb92007-07-05 13:10:51 +02002914 {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
Guillaume Munch6d859062006-08-22 17:15:47 +02002915 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
2916 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
2917/* {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},*/ /* Optical Out */
2918 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
2919 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
2920 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
2921 {}
2922};
2923
Takashi Iwaidb064e52006-03-16 16:04:58 +01002924/* bind volumes of both NID 0x02 and 0x05 */
Takashi Iwaicca3b372007-08-10 17:12:15 +02002925static struct hda_bind_ctls vaio_bind_master_vol = {
2926 .ops = &snd_hda_bind_vol,
2927 .values = {
2928 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2929 HDA_COMPOSE_AMP_VAL(0x05, 3, 0, HDA_OUTPUT),
2930 0
2931 },
2932};
Takashi Iwaidb064e52006-03-16 16:04:58 +01002933
2934/* bind volumes of both NID 0x02 and 0x05 */
Takashi Iwaicca3b372007-08-10 17:12:15 +02002935static struct hda_bind_ctls vaio_bind_master_sw = {
2936 .ops = &snd_hda_bind_sw,
2937 .values = {
2938 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2939 HDA_COMPOSE_AMP_VAL(0x05, 3, 0, HDA_OUTPUT),
2940 0,
2941 },
2942};
Takashi Iwaidb064e52006-03-16 16:04:58 +01002943
2944static struct snd_kcontrol_new vaio_mixer[] = {
Takashi Iwaicca3b372007-08-10 17:12:15 +02002945 HDA_BIND_VOL("Master Playback Volume", &vaio_bind_master_vol),
2946 HDA_BIND_SW("Master Playback Switch", &vaio_bind_master_sw),
Takashi Iwaidb064e52006-03-16 16:04:58 +01002947 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
2948 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
2949 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
2950 {
2951 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2952 .name = "Capture Source",
2953 .count = 1,
2954 .info = stac92xx_mux_enum_info,
2955 .get = stac92xx_mux_enum_get,
2956 .put = stac92xx_mux_enum_put,
2957 },
2958 {}
2959};
2960
Guillaume Munch6d859062006-08-22 17:15:47 +02002961static struct snd_kcontrol_new vaio_ar_mixer[] = {
Takashi Iwaicca3b372007-08-10 17:12:15 +02002962 HDA_BIND_VOL("Master Playback Volume", &vaio_bind_master_vol),
2963 HDA_BIND_SW("Master Playback Switch", &vaio_bind_master_sw),
Guillaume Munch6d859062006-08-22 17:15:47 +02002964 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
2965 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
2966 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
2967 /*HDA_CODEC_MUTE("Optical Out Switch", 0x10, 0, HDA_OUTPUT),
2968 HDA_CODEC_VOLUME("Optical Out Volume", 0x10, 0, HDA_OUTPUT),*/
2969 {
2970 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2971 .name = "Capture Source",
2972 .count = 1,
2973 .info = stac92xx_mux_enum_info,
2974 .get = stac92xx_mux_enum_get,
2975 .put = stac92xx_mux_enum_put,
2976 },
2977 {}
2978};
2979
2980static struct hda_codec_ops stac9872_patch_ops = {
Takashi Iwaidb064e52006-03-16 16:04:58 +01002981 .build_controls = stac92xx_build_controls,
2982 .build_pcms = stac92xx_build_pcms,
2983 .init = stac92xx_init,
2984 .free = stac92xx_free,
Takashi Iwaicb53c622007-08-10 17:21:45 +02002985#ifdef SND_HDA_NEEDS_RESUME
Takashi Iwaidb064e52006-03-16 16:04:58 +01002986 .resume = stac92xx_resume,
2987#endif
2988};
2989
Takashi Iwai72e7b0d2007-08-16 17:33:55 +02002990static int stac9872_vaio_init(struct hda_codec *codec)
2991{
2992 int err;
2993
2994 err = stac92xx_init(codec);
2995 if (err < 0)
2996 return err;
2997 if (codec->patch_ops.unsol_event)
2998 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
2999 return 0;
3000}
3001
3002static void stac9872_vaio_hp_detect(struct hda_codec *codec, unsigned int res)
3003{
3004 if (get_pin_presence(codec, 0x0a)) {
3005 stac92xx_reset_pinctl(codec, 0x0f, AC_PINCTL_OUT_EN);
3006 stac92xx_set_pinctl(codec, 0x0a, AC_PINCTL_OUT_EN);
3007 } else {
3008 stac92xx_reset_pinctl(codec, 0x0a, AC_PINCTL_OUT_EN);
3009 stac92xx_set_pinctl(codec, 0x0f, AC_PINCTL_OUT_EN);
3010 }
3011}
3012
3013static void stac9872_vaio_unsol_event(struct hda_codec *codec, unsigned int res)
3014{
3015 switch (res >> 26) {
3016 case STAC_HP_EVENT:
3017 stac9872_vaio_hp_detect(codec, res);
3018 break;
3019 }
3020}
3021
3022static struct hda_codec_ops stac9872_vaio_patch_ops = {
3023 .build_controls = stac92xx_build_controls,
3024 .build_pcms = stac92xx_build_pcms,
3025 .init = stac9872_vaio_init,
3026 .free = stac92xx_free,
3027 .unsol_event = stac9872_vaio_unsol_event,
3028#ifdef CONFIG_PM
3029 .resume = stac92xx_resume,
3030#endif
3031};
3032
Guillaume Munch6d859062006-08-22 17:15:47 +02003033enum { /* FE and SZ series. id=0x83847661 and subsys=0x104D0700 or 104D1000. */
3034 CXD9872RD_VAIO,
3035 /* Unknown. id=0x83847662 and subsys=0x104D1200 or 104D1000. */
3036 STAC9872AK_VAIO,
3037 /* Unknown. id=0x83847661 and subsys=0x104D1200. */
3038 STAC9872K_VAIO,
3039 /* AR Series. id=0x83847664 and subsys=104D1300 */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01003040 CXD9872AKD_VAIO,
3041 STAC_9872_MODELS,
3042};
Takashi Iwaidb064e52006-03-16 16:04:58 +01003043
Takashi Iwaif5fcc132006-11-24 17:07:44 +01003044static const char *stac9872_models[STAC_9872_MODELS] = {
3045 [CXD9872RD_VAIO] = "vaio",
3046 [CXD9872AKD_VAIO] = "vaio-ar",
3047};
3048
3049static struct snd_pci_quirk stac9872_cfg_tbl[] = {
3050 SND_PCI_QUIRK(0x104d, 0x81e6, "Sony VAIO F/S", CXD9872RD_VAIO),
3051 SND_PCI_QUIRK(0x104d, 0x81ef, "Sony VAIO F/S", CXD9872RD_VAIO),
3052 SND_PCI_QUIRK(0x104d, 0x81fd, "Sony VAIO AR", CXD9872AKD_VAIO),
Tobin Davis68e22542007-03-12 11:36:39 +01003053 SND_PCI_QUIRK(0x104d, 0x8205, "Sony VAIO AR", CXD9872AKD_VAIO),
Takashi Iwaidb064e52006-03-16 16:04:58 +01003054 {}
3055};
3056
Guillaume Munch6d859062006-08-22 17:15:47 +02003057static int patch_stac9872(struct hda_codec *codec)
Takashi Iwaidb064e52006-03-16 16:04:58 +01003058{
3059 struct sigmatel_spec *spec;
3060 int board_config;
3061
Takashi Iwaif5fcc132006-11-24 17:07:44 +01003062 board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
3063 stac9872_models,
3064 stac9872_cfg_tbl);
Takashi Iwaidb064e52006-03-16 16:04:58 +01003065 if (board_config < 0)
3066 /* unknown config, let generic-parser do its job... */
3067 return snd_hda_parse_generic_codec(codec);
3068
3069 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3070 if (spec == NULL)
3071 return -ENOMEM;
3072
3073 codec->spec = spec;
3074 switch (board_config) {
Guillaume Munch6d859062006-08-22 17:15:47 +02003075 case CXD9872RD_VAIO:
3076 case STAC9872AK_VAIO:
3077 case STAC9872K_VAIO:
Takashi Iwaidb064e52006-03-16 16:04:58 +01003078 spec->mixer = vaio_mixer;
3079 spec->init = vaio_init;
3080 spec->multiout.max_channels = 2;
3081 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
3082 spec->multiout.dac_nids = vaio_dacs;
3083 spec->multiout.hp_nid = VAIO_HP_DAC;
3084 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
3085 spec->adc_nids = vaio_adcs;
3086 spec->input_mux = &vaio_mux;
3087 spec->mux_nids = vaio_mux_nids;
Takashi Iwai72e7b0d2007-08-16 17:33:55 +02003088 codec->patch_ops = stac9872_vaio_patch_ops;
Takashi Iwaidb064e52006-03-16 16:04:58 +01003089 break;
Guillaume Munch6d859062006-08-22 17:15:47 +02003090
3091 case CXD9872AKD_VAIO:
3092 spec->mixer = vaio_ar_mixer;
3093 spec->init = vaio_ar_init;
3094 spec->multiout.max_channels = 2;
3095 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
3096 spec->multiout.dac_nids = vaio_dacs;
3097 spec->multiout.hp_nid = VAIO_HP_DAC;
3098 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
3099 spec->adc_nids = vaio_adcs;
3100 spec->input_mux = &vaio_mux;
3101 spec->mux_nids = vaio_mux_nids;
Takashi Iwai72e7b0d2007-08-16 17:33:55 +02003102 codec->patch_ops = stac9872_patch_ops;
Guillaume Munch6d859062006-08-22 17:15:47 +02003103 break;
Takashi Iwaidb064e52006-03-16 16:04:58 +01003104 }
3105
Takashi Iwaidb064e52006-03-16 16:04:58 +01003106 return 0;
3107}
3108
3109
3110/*
Matt2f2f4252005-04-13 14:45:30 +02003111 * patch entries
3112 */
3113struct hda_codec_preset snd_hda_preset_sigmatel[] = {
3114 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
3115 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
3116 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
3117 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
3118 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
3119 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
3120 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
Matt Porter22a27c72006-07-06 18:49:10 +02003121 { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
3122 { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
3123 { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
3124 { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
3125 { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
3126 { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
Matt Porter3cc08dc2006-01-23 15:27:49 +01003127 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
3128 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
3129 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
3130 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
3131 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
3132 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
3133 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
3134 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
3135 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
3136 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
Tobin Davis8e21c342007-01-08 11:04:17 +01003137 { .id = 0x83847632, .name = "STAC9202", .patch = patch_stac925x },
3138 { .id = 0x83847633, .name = "STAC9202D", .patch = patch_stac925x },
3139 { .id = 0x83847634, .name = "STAC9250", .patch = patch_stac925x },
3140 { .id = 0x83847635, .name = "STAC9250D", .patch = patch_stac925x },
3141 { .id = 0x83847636, .name = "STAC9251", .patch = patch_stac925x },
3142 { .id = 0x83847637, .name = "STAC9250D", .patch = patch_stac925x },
Guillaume Munch6d859062006-08-22 17:15:47 +02003143 /* The following does not take into account .id=0x83847661 when subsys =
3144 * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
3145 * currently not fully supported.
3146 */
3147 { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
3148 { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
3149 { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
Matt Porterf3302a52006-07-31 12:49:34 +02003150 { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
3151 { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
3152 { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
3153 { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
3154 { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
3155 { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
3156 { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
3157 { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
Matt2f2f4252005-04-13 14:45:30 +02003158 {} /* terminator */
3159};