blob: 86cd3f67b9fb1eae9271fcefc97303a822c708f6 [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
Matthew Ranostay7f168592007-10-18 17:38:17 +0200207#define STAC927X_NUM_DMICS 2
208static hda_nid_t stac927x_dmic_nids[STAC927X_NUM_DMICS + 1] = {
209 0x13, 0x14, 0
210};
211
Matt Porterf3302a52006-07-31 12:49:34 +0200212static hda_nid_t stac9205_adc_nids[2] = {
213 0x12, 0x13
214};
215
216static hda_nid_t stac9205_mux_nids[2] = {
217 0x19, 0x1a
218};
219
Takashi Iwaif6e98522007-10-16 14:27:04 +0200220#define STAC9205_NUM_DMICS 2
221static hda_nid_t stac9205_dmic_nids[STAC9205_NUM_DMICS + 1] = {
222 0x17, 0x18, 0
Matt Porter8b657272006-10-26 17:12:59 +0200223};
224
Mattc7d4b2f2005-06-27 14:59:41 +0200225static hda_nid_t stac9200_pin_nids[8] = {
Tobin Davis93ed1502006-09-01 21:03:12 +0200226 0x08, 0x09, 0x0d, 0x0e,
227 0x0f, 0x10, 0x11, 0x12,
Matt2f2f4252005-04-13 14:45:30 +0200228};
229
Tobin Davis8e21c342007-01-08 11:04:17 +0100230static hda_nid_t stac925x_pin_nids[8] = {
231 0x07, 0x08, 0x0a, 0x0b,
232 0x0c, 0x0d, 0x10, 0x11,
233};
234
Matt2f2f4252005-04-13 14:45:30 +0200235static hda_nid_t stac922x_pin_nids[10] = {
236 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
237 0x0f, 0x10, 0x11, 0x15, 0x1b,
238};
239
Matt Porter3cc08dc2006-01-23 15:27:49 +0100240static hda_nid_t stac927x_pin_nids[14] = {
241 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
242 0x0f, 0x10, 0x11, 0x12, 0x13,
243 0x14, 0x21, 0x22, 0x23,
244};
245
Matt Porterf3302a52006-07-31 12:49:34 +0200246static hda_nid_t stac9205_pin_nids[12] = {
247 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
248 0x0f, 0x14, 0x16, 0x17, 0x18,
249 0x21, 0x22,
Matt Porterf3302a52006-07-31 12:49:34 +0200250};
251
Matt Porter8b657272006-10-26 17:12:59 +0200252static int stac92xx_dmux_enum_info(struct snd_kcontrol *kcontrol,
253 struct snd_ctl_elem_info *uinfo)
254{
255 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
256 struct sigmatel_spec *spec = codec->spec;
257 return snd_hda_input_mux_info(spec->dinput_mux, uinfo);
258}
259
260static int stac92xx_dmux_enum_get(struct snd_kcontrol *kcontrol,
261 struct snd_ctl_elem_value *ucontrol)
262{
263 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
264 struct sigmatel_spec *spec = codec->spec;
265
266 ucontrol->value.enumerated.item[0] = spec->cur_dmux;
267 return 0;
268}
269
270static int stac92xx_dmux_enum_put(struct snd_kcontrol *kcontrol,
271 struct snd_ctl_elem_value *ucontrol)
272{
273 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
274 struct sigmatel_spec *spec = codec->spec;
275
276 return snd_hda_input_mux_put(codec, spec->dinput_mux, ucontrol,
277 spec->dmux_nid, &spec->cur_dmux);
278}
279
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100280static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Matt2f2f4252005-04-13 14:45:30 +0200281{
282 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
283 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +0200284 return snd_hda_input_mux_info(spec->input_mux, uinfo);
Matt2f2f4252005-04-13 14:45:30 +0200285}
286
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100287static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200288{
289 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
290 struct sigmatel_spec *spec = codec->spec;
291 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
292
293 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
294 return 0;
295}
296
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100297static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200298{
299 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
300 struct sigmatel_spec *spec = codec->spec;
301 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
302
Mattc7d4b2f2005-06-27 14:59:41 +0200303 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
Matt2f2f4252005-04-13 14:45:30 +0200304 spec->mux_nids[adc_idx], &spec->cur_mux[adc_idx]);
305}
306
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200307#define stac92xx_aloopback_info snd_ctl_boolean_mono_info
308
309static int stac92xx_aloopback_get(struct snd_kcontrol *kcontrol,
310 struct snd_ctl_elem_value *ucontrol)
311{
312 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
313 struct sigmatel_spec *spec = codec->spec;
314
315 ucontrol->value.integer.value[0] = spec->aloopback;
316 return 0;
317}
318
319static int stac92xx_aloopback_put(struct snd_kcontrol *kcontrol,
320 struct snd_ctl_elem_value *ucontrol)
321{
322 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
323 struct sigmatel_spec *spec = codec->spec;
324 unsigned int dac_mode;
325
326 if (spec->aloopback == ucontrol->value.integer.value[0])
327 return 0;
328
329 spec->aloopback = ucontrol->value.integer.value[0];
330
331
332 dac_mode = snd_hda_codec_read(codec, codec->afg, 0,
333 kcontrol->private_value & 0xFFFF, 0x0);
334
335 if (spec->aloopback) {
336 snd_hda_power_up(codec);
337 dac_mode |= 0x40;
338 } else {
339 snd_hda_power_down(codec);
340 dac_mode &= ~0x40;
341 }
342
343 snd_hda_codec_write_cache(codec, codec->afg, 0,
344 kcontrol->private_value >> 16, dac_mode);
345
346 return 1;
347}
348
Mattc7d4b2f2005-06-27 14:59:41 +0200349static struct hda_verb stac9200_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200350 /* set dac0mux for dac converter */
Mattc7d4b2f2005-06-27 14:59:41 +0200351 { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
Matt2f2f4252005-04-13 14:45:30 +0200352 {}
353};
354
Takashi Iwai1194b5b2007-10-10 10:04:26 +0200355static struct hda_verb stac9200_eapd_init[] = {
356 /* set dac0mux for dac converter */
357 {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
358 {0x08, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
359 {}
360};
361
Tobin Davis8e21c342007-01-08 11:04:17 +0100362static struct hda_verb stac925x_core_init[] = {
363 /* set dac0mux for dac converter */
364 { 0x06, AC_VERB_SET_CONNECT_SEL, 0x00},
365 {}
366};
367
Mattc7d4b2f2005-06-27 14:59:41 +0200368static struct hda_verb stac922x_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200369 /* set master volume and direct control */
Mattc7d4b2f2005-06-27 14:59:41 +0200370 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matt2f2f4252005-04-13 14:45:30 +0200371 {}
372};
373
Tobin Davis93ed1502006-09-01 21:03:12 +0200374static struct hda_verb d965_core_init[] = {
Takashi Iwai19039bd2006-06-28 15:52:16 +0200375 /* set master volume and direct control */
Tobin Davis93ed1502006-09-01 21:03:12 +0200376 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Takashi Iwai19039bd2006-06-28 15:52:16 +0200377 /* unmute node 0x1b */
378 { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
379 /* select node 0x03 as DAC */
380 { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
381 {}
382};
383
Matt Porter3cc08dc2006-01-23 15:27:49 +0100384static struct hda_verb stac927x_core_init[] = {
385 /* set master volume and direct control */
386 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
387 {}
388};
389
Matt Porterf3302a52006-07-31 12:49:34 +0200390static struct hda_verb stac9205_core_init[] = {
391 /* set master volume and direct control */
392 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
393 {}
394};
395
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200396#define STAC_INPUT_SOURCE(cnt) \
Maxim Levitskyca7c5a82007-08-31 12:52:19 +0200397 { \
398 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
399 .name = "Input Source", \
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200400 .count = cnt, \
Maxim Levitskyca7c5a82007-08-31 12:52:19 +0200401 .info = stac92xx_mux_enum_info, \
402 .get = stac92xx_mux_enum_get, \
403 .put = stac92xx_mux_enum_put, \
404 }
405
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200406#define STAC_ANALOG_LOOPBACK(verb_read,verb_write) \
407 { \
408 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
409 .name = "Analog Loopback", \
410 .count = 1, \
411 .info = stac92xx_aloopback_info, \
412 .get = stac92xx_aloopback_get, \
413 .put = stac92xx_aloopback_put, \
414 .private_value = verb_read | (verb_write << 16), \
415 }
416
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100417static struct snd_kcontrol_new stac9200_mixer[] = {
Matt2f2f4252005-04-13 14:45:30 +0200418 HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
419 HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200420 STAC_INPUT_SOURCE(1),
Matt2f2f4252005-04-13 14:45:30 +0200421 HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
422 HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
Mattc7d4b2f2005-06-27 14:59:41 +0200423 HDA_CODEC_VOLUME("Capture Mux Volume", 0x0c, 0, HDA_OUTPUT),
Matt2f2f4252005-04-13 14:45:30 +0200424 { } /* end */
425};
426
Tobin Davis8e21c342007-01-08 11:04:17 +0100427static struct snd_kcontrol_new stac925x_mixer[] = {
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200428 STAC_INPUT_SOURCE(1),
Tobin Davis8e21c342007-01-08 11:04:17 +0100429 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_OUTPUT),
430 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_OUTPUT),
431 HDA_CODEC_VOLUME("Capture Mux Volume", 0x0f, 0, HDA_OUTPUT),
432 { } /* end */
433};
434
Takashi Iwaid1d985f2006-11-23 19:27:12 +0100435static struct snd_kcontrol_new stac9205_mixer[] = {
Matt Porterf3302a52006-07-31 12:49:34 +0200436 {
437 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Matt Porter8b657272006-10-26 17:12:59 +0200438 .name = "Digital Input Source",
439 .count = 1,
440 .info = stac92xx_dmux_enum_info,
441 .get = stac92xx_dmux_enum_get,
442 .put = stac92xx_dmux_enum_put,
443 },
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200444 STAC_INPUT_SOURCE(2),
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200445 STAC_ANALOG_LOOPBACK(0xFE0, 0x7E0),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200446
447 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1b, 0x0, HDA_INPUT),
448 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1d, 0x0, HDA_OUTPUT),
449 HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x0, 0x19, 0x0, HDA_OUTPUT),
450
451 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x1c, 0x0, HDA_INPUT),
452 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1e, 0x0, HDA_OUTPUT),
453 HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x1, 0x1A, 0x0, HDA_OUTPUT),
454
455 { } /* end */
456};
457
458/* This needs to be generated dynamically based on sequence */
459static struct snd_kcontrol_new stac922x_mixer[] = {
460 STAC_INPUT_SOURCE(2),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200461 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x17, 0x0, HDA_INPUT),
462 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x17, 0x0, HDA_INPUT),
463 HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x0, 0x12, 0x0, HDA_OUTPUT),
464
465 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x18, 0x0, HDA_INPUT),
466 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x18, 0x0, HDA_INPUT),
467 HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x1, 0x13, 0x0, HDA_OUTPUT),
468 { } /* end */
469};
470
471
472static struct snd_kcontrol_new stac927x_mixer[] = {
473 STAC_INPUT_SOURCE(3),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200474 STAC_ANALOG_LOOPBACK(0xFEB, 0x7EB),
475
476 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x18, 0x0, HDA_INPUT),
477 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1b, 0x0, HDA_OUTPUT),
478 HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x0, 0x15, 0x0, HDA_OUTPUT),
479
480 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x19, 0x0, HDA_INPUT),
481 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1c, 0x0, HDA_OUTPUT),
482 HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x1, 0x16, 0x0, HDA_OUTPUT),
483
484 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x2, 0x1A, 0x0, HDA_INPUT),
485 HDA_CODEC_MUTE_IDX("Capture Switch", 0x2, 0x1d, 0x0, HDA_OUTPUT),
486 HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x2, 0x17, 0x0, HDA_OUTPUT),
Matt Porterf3302a52006-07-31 12:49:34 +0200487 { } /* end */
488};
489
Matt2f2f4252005-04-13 14:45:30 +0200490static int stac92xx_build_controls(struct hda_codec *codec)
491{
492 struct sigmatel_spec *spec = codec->spec;
493 int err;
Mattc7d4b2f2005-06-27 14:59:41 +0200494 int i;
Matt2f2f4252005-04-13 14:45:30 +0200495
496 err = snd_hda_add_new_ctls(codec, spec->mixer);
497 if (err < 0)
498 return err;
Mattc7d4b2f2005-06-27 14:59:41 +0200499
500 for (i = 0; i < spec->num_mixers; i++) {
501 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
502 if (err < 0)
503 return err;
504 }
505
Mattdabbed62005-06-14 10:19:34 +0200506 if (spec->multiout.dig_out_nid) {
507 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
508 if (err < 0)
509 return err;
510 }
511 if (spec->dig_in_nid) {
512 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
513 if (err < 0)
514 return err;
515 }
516 return 0;
Matt2f2f4252005-04-13 14:45:30 +0200517}
518
Matt Porter403d1942005-11-29 15:00:51 +0100519static unsigned int ref9200_pin_configs[8] = {
Mattdabbed62005-06-14 10:19:34 +0200520 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
Matt2f2f4252005-04-13 14:45:30 +0200521 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
522};
523
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200524/*
525 STAC 9200 pin configs for
526 102801A8
527 102801DE
528 102801E8
529*/
530static unsigned int dell9200_d21_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +0200531 0x400001f0, 0x400001f1, 0x02214030, 0x01014010,
532 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200533};
534
535/*
536 STAC 9200 pin configs for
537 102801C0
538 102801C1
539*/
540static unsigned int dell9200_d22_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +0200541 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
542 0x01813020, 0x02a19021, 0x90100140, 0x400001f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200543};
544
545/*
546 STAC 9200 pin configs for
547 102801C4 (Dell Dimension E310)
548 102801C5
549 102801C7
550 102801D9
551 102801DA
552 102801E3
553*/
554static unsigned int dell9200_d23_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +0200555 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
556 0x01813020, 0x01a19021, 0x90100140, 0x400001f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200557};
558
559
560/*
561 STAC 9200-32 pin configs for
562 102801B5 (Dell Inspiron 630m)
563 102801D8 (Dell Inspiron 640m)
564*/
565static unsigned int dell9200_m21_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +0200566 0x40c003fa, 0x03441340, 0x0321121f, 0x90170310,
567 0x408003fb, 0x03a11020, 0x401003fc, 0x403003fd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200568};
569
570/*
571 STAC 9200-32 pin configs for
572 102801C2 (Dell Latitude D620)
573 102801C8
574 102801CC (Dell Latitude D820)
575 102801D4
576 102801D6
577*/
578static unsigned int dell9200_m22_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +0200579 0x40c003fa, 0x0144131f, 0x0321121f, 0x90170310,
580 0x90a70321, 0x03a11020, 0x401003fb, 0x40f000fc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200581};
582
583/*
584 STAC 9200-32 pin configs for
585 102801CE (Dell XPS M1710)
586 102801CF (Dell Precision M90)
587*/
588static unsigned int dell9200_m23_pin_configs[8] = {
589 0x40c003fa, 0x01441340, 0x0421421f, 0x90170310,
590 0x408003fb, 0x04a1102e, 0x90170311, 0x403003fc,
591};
592
593/*
594 STAC 9200-32 pin configs for
595 102801C9
596 102801CA
597 102801CB (Dell Latitude 120L)
598 102801D3
599*/
600static unsigned int dell9200_m24_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +0200601 0x40c003fa, 0x404003fb, 0x0321121f, 0x90170310,
602 0x408003fc, 0x03a11020, 0x401003fd, 0x403003fe,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200603};
604
605/*
606 STAC 9200-32 pin configs for
607 102801BD (Dell Inspiron E1505n)
608 102801EE
609 102801EF
610*/
611static unsigned int dell9200_m25_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +0200612 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
613 0x408003fb, 0x04a11020, 0x401003fc, 0x403003fd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200614};
615
616/*
617 STAC 9200-32 pin configs for
618 102801F5 (Dell Inspiron 1501)
619 102801F6
620*/
621static unsigned int dell9200_m26_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +0200622 0x40c003fa, 0x404003fb, 0x0421121f, 0x90170310,
623 0x408003fc, 0x04a11020, 0x401003fd, 0x403003fe,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200624};
625
626/*
627 STAC 9200-32
628 102801CD (Dell Inspiron E1705/9400)
629*/
630static unsigned int dell9200_m27_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +0200631 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
632 0x90170310, 0x04a11020, 0x90170310, 0x40f003fc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200633};
634
635
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100636static unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
637 [STAC_REF] = ref9200_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200638 [STAC_9200_DELL_D21] = dell9200_d21_pin_configs,
639 [STAC_9200_DELL_D22] = dell9200_d22_pin_configs,
640 [STAC_9200_DELL_D23] = dell9200_d23_pin_configs,
641 [STAC_9200_DELL_M21] = dell9200_m21_pin_configs,
642 [STAC_9200_DELL_M22] = dell9200_m22_pin_configs,
643 [STAC_9200_DELL_M23] = dell9200_m23_pin_configs,
644 [STAC_9200_DELL_M24] = dell9200_m24_pin_configs,
645 [STAC_9200_DELL_M25] = dell9200_m25_pin_configs,
646 [STAC_9200_DELL_M26] = dell9200_m26_pin_configs,
647 [STAC_9200_DELL_M27] = dell9200_m27_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +0100648};
649
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100650static const char *stac9200_models[STAC_9200_MODELS] = {
651 [STAC_REF] = "ref",
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200652 [STAC_9200_DELL_D21] = "dell-d21",
653 [STAC_9200_DELL_D22] = "dell-d22",
654 [STAC_9200_DELL_D23] = "dell-d23",
655 [STAC_9200_DELL_M21] = "dell-m21",
656 [STAC_9200_DELL_M22] = "dell-m22",
657 [STAC_9200_DELL_M23] = "dell-m23",
658 [STAC_9200_DELL_M24] = "dell-m24",
659 [STAC_9200_DELL_M25] = "dell-m25",
660 [STAC_9200_DELL_M26] = "dell-m26",
661 [STAC_9200_DELL_M27] = "dell-m27",
Takashi Iwai1194b5b2007-10-10 10:04:26 +0200662 [STAC_9200_GATEWAY] = "gateway",
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100663};
664
665static struct snd_pci_quirk stac9200_cfg_tbl[] = {
666 /* SigmaTel reference board */
667 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
668 "DFI LanParty", STAC_REF),
Matt Portere7377072006-11-06 11:20:38 +0100669 /* Dell laptops have BIOS problem */
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200670 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a8,
671 "unknown Dell", STAC_9200_DELL_D21),
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100672 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01b5,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200673 "Dell Inspiron 630m", STAC_9200_DELL_M21),
674 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bd,
675 "Dell Inspiron E1505n", STAC_9200_DELL_M25),
676 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c0,
677 "unknown Dell", STAC_9200_DELL_D22),
678 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c1,
679 "unknown Dell", STAC_9200_DELL_D22),
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100680 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200681 "Dell Latitude D620", STAC_9200_DELL_M22),
682 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c5,
683 "unknown Dell", STAC_9200_DELL_D23),
684 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c7,
685 "unknown Dell", STAC_9200_DELL_D23),
686 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c8,
687 "unknown Dell", STAC_9200_DELL_M22),
688 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c9,
689 "unknown Dell", STAC_9200_DELL_M24),
690 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ca,
691 "unknown Dell", STAC_9200_DELL_M24),
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100692 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cb,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200693 "Dell Latitude 120L", STAC_9200_DELL_M24),
Cory T. Tusar877b8662007-01-30 17:30:55 +0100694 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200695 "Dell Latitude D820", STAC_9200_DELL_M22),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +0100696 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200697 "Dell Inspiron E1705/9400", STAC_9200_DELL_M27),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +0100698 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ce,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200699 "Dell XPS M1710", STAC_9200_DELL_M23),
Takashi Iwaif0f96742007-02-14 00:59:17 +0100700 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cf,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200701 "Dell Precision M90", STAC_9200_DELL_M23),
702 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d3,
703 "unknown Dell", STAC_9200_DELL_M22),
704 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d4,
705 "unknown Dell", STAC_9200_DELL_M22),
Daniel T Chen8286c532007-05-15 11:46:23 +0200706 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d6,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200707 "unknown Dell", STAC_9200_DELL_M22),
Tobin Davis49c605d2007-05-17 09:38:24 +0200708 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d8,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200709 "Dell Inspiron 640m", STAC_9200_DELL_M21),
710 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d9,
711 "unknown Dell", STAC_9200_DELL_D23),
712 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01da,
713 "unknown Dell", STAC_9200_DELL_D23),
714 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01de,
715 "unknown Dell", STAC_9200_DELL_D21),
716 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e3,
717 "unknown Dell", STAC_9200_DELL_D23),
718 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e8,
719 "unknown Dell", STAC_9200_DELL_D21),
720 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ee,
721 "unknown Dell", STAC_9200_DELL_M25),
722 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ef,
723 "unknown Dell", STAC_9200_DELL_M25),
Tobin Davis49c605d2007-05-17 09:38:24 +0200724 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f5,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200725 "Dell Inspiron 1501", STAC_9200_DELL_M26),
726 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f6,
727 "unknown Dell", STAC_9200_DELL_M26),
Tobin Davis49c605d2007-05-17 09:38:24 +0200728 /* Panasonic */
729 SND_PCI_QUIRK(0x10f7, 0x8338, "Panasonic CF-74", STAC_REF),
Takashi Iwai1194b5b2007-10-10 10:04:26 +0200730 /* Gateway machines needs EAPD to be set on resume */
731 SND_PCI_QUIRK(0x107b, 0x0205, "Gateway S-7110M", STAC_9200_GATEWAY),
732 SND_PCI_QUIRK(0x107b, 0x0317, "Gateway MT3423, MX341*",
733 STAC_9200_GATEWAY),
734 SND_PCI_QUIRK(0x107b, 0x0318, "Gateway ML3019, MT3707",
735 STAC_9200_GATEWAY),
Matt Porter403d1942005-11-29 15:00:51 +0100736 {} /* terminator */
737};
738
Tobin Davis8e21c342007-01-08 11:04:17 +0100739static unsigned int ref925x_pin_configs[8] = {
740 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
741 0x90a70320, 0x02214210, 0x400003f1, 0x9033032e,
742};
743
744static unsigned int stac925x_MA6_pin_configs[8] = {
745 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
746 0x90a70320, 0x90100211, 0x400003f1, 0x9033032e,
747};
748
Tobin Davis2c11f952007-05-17 09:36:34 +0200749static unsigned int stac925x_PA6_pin_configs[8] = {
750 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
751 0x50a103f0, 0x90100211, 0x400003f1, 0x9033032e,
752};
753
Tobin Davis8e21c342007-01-08 11:04:17 +0100754static unsigned int stac925xM2_2_pin_configs[8] = {
Steve Longerbeam7353e142007-05-29 14:36:17 +0200755 0x40c003f3, 0x424503f2, 0x04180011, 0x02a19020,
756 0x50a103f0, 0x90100212, 0x400003f1, 0x9033032e,
Tobin Davis8e21c342007-01-08 11:04:17 +0100757};
758
759static unsigned int *stac925x_brd_tbl[STAC_925x_MODELS] = {
760 [STAC_REF] = ref925x_pin_configs,
761 [STAC_M2_2] = stac925xM2_2_pin_configs,
762 [STAC_MA6] = stac925x_MA6_pin_configs,
Tobin Davis2c11f952007-05-17 09:36:34 +0200763 [STAC_PA6] = stac925x_PA6_pin_configs,
Tobin Davis8e21c342007-01-08 11:04:17 +0100764};
765
766static const char *stac925x_models[STAC_925x_MODELS] = {
767 [STAC_REF] = "ref",
768 [STAC_M2_2] = "m2-2",
769 [STAC_MA6] = "m6",
Tobin Davis2c11f952007-05-17 09:36:34 +0200770 [STAC_PA6] = "pa6",
Tobin Davis8e21c342007-01-08 11:04:17 +0100771};
772
773static struct snd_pci_quirk stac925x_cfg_tbl[] = {
774 /* SigmaTel reference board */
775 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, "DFI LanParty", STAC_REF),
Tobin Davis2c11f952007-05-17 09:36:34 +0200776 SND_PCI_QUIRK(0x8384, 0x7632, "Stac9202 Reference Board", STAC_REF),
Tobin Davis8e21c342007-01-08 11:04:17 +0100777 SND_PCI_QUIRK(0x107b, 0x0316, "Gateway M255", STAC_REF),
778 SND_PCI_QUIRK(0x107b, 0x0366, "Gateway MP6954", STAC_REF),
779 SND_PCI_QUIRK(0x107b, 0x0461, "Gateway NX560XL", STAC_MA6),
Tobin Davis2c11f952007-05-17 09:36:34 +0200780 SND_PCI_QUIRK(0x107b, 0x0681, "Gateway NX860", STAC_PA6),
Tobin Davis8e21c342007-01-08 11:04:17 +0100781 SND_PCI_QUIRK(0x1002, 0x437b, "Gateway MX6453", STAC_M2_2),
782 {} /* terminator */
783};
784
Matt Porter403d1942005-11-29 15:00:51 +0100785static unsigned int ref922x_pin_configs[10] = {
786 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
787 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
Matt2f2f4252005-04-13 14:45:30 +0200788 0x40000100, 0x40000100,
789};
790
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200791/*
792 STAC 922X pin configs for
793 102801A7
794 102801AB
795 102801A9
796 102801D1
797 102801D2
798*/
799static unsigned int dell_922x_d81_pin_configs[10] = {
800 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
801 0x02a19020, 0x01117011, 0x400001f0, 0x400001f1,
802 0x01813122, 0x400001f2,
803};
804
805/*
806 STAC 922X pin configs for
807 102801AC
808 102801D0
809*/
810static unsigned int dell_922x_d82_pin_configs[10] = {
811 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
812 0x02a19020, 0x01117011, 0x01451140, 0x400001f0,
813 0x01813122, 0x400001f1,
814};
815
816/*
817 STAC 922X pin configs for
818 102801BF
819*/
820static unsigned int dell_922x_m81_pin_configs[10] = {
821 0x0321101f, 0x01112024, 0x01111222, 0x91174220,
822 0x03a11050, 0x01116221, 0x90a70330, 0x01452340,
823 0x40C003f1, 0x405003f0,
824};
825
826/*
827 STAC 9221 A1 pin configs for
828 102801D7 (Dell XPS M1210)
829*/
830static unsigned int dell_922x_m82_pin_configs[10] = {
831 0x0221121f, 0x408103ff, 0x02111212, 0x90100310,
832 0x408003f1, 0x02111211, 0x03451340, 0x40c003f2,
833 0x508003f3, 0x405003f4,
834};
835
Matt Porter403d1942005-11-29 15:00:51 +0100836static unsigned int d945gtp3_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +0100837 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
Matt Porter403d1942005-11-29 15:00:51 +0100838 0x40000100, 0x40000100, 0x40000100, 0x40000100,
839 0x02a19120, 0x40000100,
840};
841
842static unsigned int d945gtp5_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +0100843 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
844 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
Matt Porter403d1942005-11-29 15:00:51 +0100845 0x02a19320, 0x40000100,
846};
847
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +0200848static unsigned int intel_mac_v1_pin_configs[10] = {
849 0x0121e21f, 0x400000ff, 0x9017e110, 0x400000fd,
850 0x400000fe, 0x0181e020, 0x1145e030, 0x11c5e240,
Takashi Iwai3fc24d82007-02-16 13:27:18 +0100851 0x400000fc, 0x400000fb,
852};
853
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +0200854static unsigned int intel_mac_v2_pin_configs[10] = {
855 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
856 0x400000fe, 0x0181e020, 0x1145e230, 0x500000fa,
Sylvain FORETf16928f2007-04-27 14:22:36 +0200857 0x400000fc, 0x400000fb,
858};
859
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +0200860static unsigned int intel_mac_v3_pin_configs[10] = {
861 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
862 0x400000fe, 0x0181e020, 0x1145e230, 0x11c5e240,
863 0x400000fc, 0x400000fb,
864};
865
866static unsigned int intel_mac_v4_pin_configs[10] = {
867 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
868 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
869 0x400000fc, 0x400000fb,
870};
871
872static unsigned int intel_mac_v5_pin_configs[10] = {
873 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
874 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
875 0x400000fc, 0x400000fb,
Takashi Iwai0dae0f82007-05-21 12:41:29 +0200876};
877
Takashi Iwai76c08822007-06-19 12:17:42 +0200878
Takashi Iwai19039bd2006-06-28 15:52:16 +0200879static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100880 [STAC_D945_REF] = ref922x_pin_configs,
Takashi Iwai19039bd2006-06-28 15:52:16 +0200881 [STAC_D945GTP3] = d945gtp3_pin_configs,
882 [STAC_D945GTP5] = d945gtp5_pin_configs,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +0200883 [STAC_INTEL_MAC_V1] = intel_mac_v1_pin_configs,
884 [STAC_INTEL_MAC_V2] = intel_mac_v2_pin_configs,
885 [STAC_INTEL_MAC_V3] = intel_mac_v3_pin_configs,
886 [STAC_INTEL_MAC_V4] = intel_mac_v4_pin_configs,
887 [STAC_INTEL_MAC_V5] = intel_mac_v5_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200888 /* for backward compatibility */
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +0200889 [STAC_MACMINI] = intel_mac_v3_pin_configs,
890 [STAC_MACBOOK] = intel_mac_v5_pin_configs,
891 [STAC_MACBOOK_PRO_V1] = intel_mac_v3_pin_configs,
892 [STAC_MACBOOK_PRO_V2] = intel_mac_v3_pin_configs,
893 [STAC_IMAC_INTEL] = intel_mac_v2_pin_configs,
894 [STAC_IMAC_INTEL_20] = intel_mac_v3_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200895 [STAC_922X_DELL_D81] = dell_922x_d81_pin_configs,
896 [STAC_922X_DELL_D82] = dell_922x_d82_pin_configs,
897 [STAC_922X_DELL_M81] = dell_922x_m81_pin_configs,
898 [STAC_922X_DELL_M82] = dell_922x_m82_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +0100899};
900
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100901static const char *stac922x_models[STAC_922X_MODELS] = {
902 [STAC_D945_REF] = "ref",
903 [STAC_D945GTP5] = "5stack",
904 [STAC_D945GTP3] = "3stack",
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +0200905 [STAC_INTEL_MAC_V1] = "intel-mac-v1",
906 [STAC_INTEL_MAC_V2] = "intel-mac-v2",
907 [STAC_INTEL_MAC_V3] = "intel-mac-v3",
908 [STAC_INTEL_MAC_V4] = "intel-mac-v4",
909 [STAC_INTEL_MAC_V5] = "intel-mac-v5",
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200910 /* for backward compatibility */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100911 [STAC_MACMINI] = "macmini",
Takashi Iwai3fc24d82007-02-16 13:27:18 +0100912 [STAC_MACBOOK] = "macbook",
Nicolas Boichat6f0778d2007-03-15 12:38:15 +0100913 [STAC_MACBOOK_PRO_V1] = "macbook-pro-v1",
914 [STAC_MACBOOK_PRO_V2] = "macbook-pro",
Sylvain FORETf16928f2007-04-27 14:22:36 +0200915 [STAC_IMAC_INTEL] = "imac-intel",
Takashi Iwai0dae0f82007-05-21 12:41:29 +0200916 [STAC_IMAC_INTEL_20] = "imac-intel-20",
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200917 [STAC_922X_DELL_D81] = "dell-d81",
918 [STAC_922X_DELL_D82] = "dell-d82",
919 [STAC_922X_DELL_M81] = "dell-m81",
920 [STAC_922X_DELL_M82] = "dell-m82",
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100921};
922
923static struct snd_pci_quirk stac922x_cfg_tbl[] = {
924 /* SigmaTel reference board */
925 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
926 "DFI LanParty", STAC_D945_REF),
927 /* Intel 945G based systems */
928 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101,
929 "Intel D945G", STAC_D945GTP3),
930 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0202,
931 "Intel D945G", STAC_D945GTP3),
932 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0606,
933 "Intel D945G", STAC_D945GTP3),
934 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0601,
935 "Intel D945G", STAC_D945GTP3),
936 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0111,
937 "Intel D945G", STAC_D945GTP3),
938 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1115,
939 "Intel D945G", STAC_D945GTP3),
940 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1116,
941 "Intel D945G", STAC_D945GTP3),
942 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1117,
943 "Intel D945G", STAC_D945GTP3),
944 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1118,
945 "Intel D945G", STAC_D945GTP3),
946 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1119,
947 "Intel D945G", STAC_D945GTP3),
948 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x8826,
949 "Intel D945G", STAC_D945GTP3),
950 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5049,
951 "Intel D945G", STAC_D945GTP3),
952 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5055,
953 "Intel D945G", STAC_D945GTP3),
954 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5048,
955 "Intel D945G", STAC_D945GTP3),
956 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0110,
957 "Intel D945G", STAC_D945GTP3),
958 /* Intel D945G 5-stack systems */
959 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0404,
960 "Intel D945G", STAC_D945GTP5),
961 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0303,
962 "Intel D945G", STAC_D945GTP5),
963 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0013,
964 "Intel D945G", STAC_D945GTP5),
965 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0417,
966 "Intel D945G", STAC_D945GTP5),
967 /* Intel 945P based systems */
968 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0b0b,
969 "Intel D945P", STAC_D945GTP3),
970 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0112,
971 "Intel D945P", STAC_D945GTP3),
972 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0d0d,
973 "Intel D945P", STAC_D945GTP3),
974 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0909,
975 "Intel D945P", STAC_D945GTP3),
976 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0505,
977 "Intel D945P", STAC_D945GTP3),
978 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707,
979 "Intel D945P", STAC_D945GTP5),
980 /* other systems */
981 /* Apple Mac Mini (early 2006) */
982 SND_PCI_QUIRK(0x8384, 0x7680,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +0200983 "Mac Mini", STAC_INTEL_MAC_V3),
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200984 /* Dell systems */
985 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a7,
986 "unknown Dell", STAC_922X_DELL_D81),
987 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a9,
988 "unknown Dell", STAC_922X_DELL_D81),
989 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ab,
990 "unknown Dell", STAC_922X_DELL_D81),
991 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ac,
992 "unknown Dell", STAC_922X_DELL_D82),
993 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bf,
994 "unknown Dell", STAC_922X_DELL_M81),
995 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d0,
996 "unknown Dell", STAC_922X_DELL_D82),
997 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d1,
998 "unknown Dell", STAC_922X_DELL_D81),
999 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d2,
1000 "unknown Dell", STAC_922X_DELL_D81),
1001 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d7,
1002 "Dell XPS M1210", STAC_922X_DELL_M82),
Matt Porter403d1942005-11-29 15:00:51 +01001003 {} /* terminator */
1004};
1005
Matt Porter3cc08dc2006-01-23 15:27:49 +01001006static unsigned int ref927x_pin_configs[14] = {
Tobin Davis93ed1502006-09-01 21:03:12 +02001007 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
1008 0x01a19040, 0x01011012, 0x01016011, 0x0101201f,
1009 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
1010 0x01c42190, 0x40000100,
Matt Porter3cc08dc2006-01-23 15:27:49 +01001011};
1012
Tobin Davis93ed1502006-09-01 21:03:12 +02001013static unsigned int d965_3st_pin_configs[14] = {
Tobin Davis81d3dbd2006-08-22 19:44:45 +02001014 0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
1015 0x01a19021, 0x01813024, 0x40000100, 0x40000100,
1016 0x40000100, 0x40000100, 0x40000100, 0x40000100,
1017 0x40000100, 0x40000100
1018};
1019
Tobin Davis93ed1502006-09-01 21:03:12 +02001020static unsigned int d965_5st_pin_configs[14] = {
1021 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
1022 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
1023 0x40000100, 0x40000100, 0x40000100, 0x01442070,
1024 0x40000100, 0x40000100
1025};
1026
Tobin Davis4ff076e2007-08-07 11:48:12 +02001027static unsigned int dell_3st_pin_configs[14] = {
1028 0x02211230, 0x02a11220, 0x01a19040, 0x01114210,
1029 0x01111212, 0x01116211, 0x01813050, 0x01112214,
1030 0x403003fa, 0x40000100, 0x40000100, 0x404003fb,
1031 0x40c003fc, 0x40000100
1032};
1033
Tobin Davis93ed1502006-09-01 21:03:12 +02001034static unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001035 [STAC_D965_REF] = ref927x_pin_configs,
Tobin Davis93ed1502006-09-01 21:03:12 +02001036 [STAC_D965_3ST] = d965_3st_pin_configs,
1037 [STAC_D965_5ST] = d965_5st_pin_configs,
Tobin Davis4ff076e2007-08-07 11:48:12 +02001038 [STAC_DELL_3ST] = dell_3st_pin_configs,
Matt Porter3cc08dc2006-01-23 15:27:49 +01001039};
1040
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001041static const char *stac927x_models[STAC_927X_MODELS] = {
1042 [STAC_D965_REF] = "ref",
1043 [STAC_D965_3ST] = "3stack",
1044 [STAC_D965_5ST] = "5stack",
Tobin Davis4ff076e2007-08-07 11:48:12 +02001045 [STAC_DELL_3ST] = "dell-3stack",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001046};
1047
1048static struct snd_pci_quirk stac927x_cfg_tbl[] = {
1049 /* SigmaTel reference board */
1050 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1051 "DFI LanParty", STAC_D965_REF),
Tobin Davis81d3dbd2006-08-22 19:44:45 +02001052 /* Intel 946 based systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001053 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST),
1054 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST),
Tobin Davis93ed1502006-09-01 21:03:12 +02001055 /* 965 based 3 stack systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001056 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2116, "Intel D965", STAC_D965_3ST),
1057 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2115, "Intel D965", STAC_D965_3ST),
1058 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2114, "Intel D965", STAC_D965_3ST),
1059 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2113, "Intel D965", STAC_D965_3ST),
1060 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2112, "Intel D965", STAC_D965_3ST),
1061 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2111, "Intel D965", STAC_D965_3ST),
1062 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2110, "Intel D965", STAC_D965_3ST),
1063 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2009, "Intel D965", STAC_D965_3ST),
1064 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2008, "Intel D965", STAC_D965_3ST),
1065 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2007, "Intel D965", STAC_D965_3ST),
1066 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2006, "Intel D965", STAC_D965_3ST),
1067 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2005, "Intel D965", STAC_D965_3ST),
1068 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2004, "Intel D965", STAC_D965_3ST),
1069 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2003, "Intel D965", STAC_D965_3ST),
1070 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2002, "Intel D965", STAC_D965_3ST),
1071 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2001, "Intel D965", STAC_D965_3ST),
Tim Gardner5e915bb2007-10-10 10:42:00 +02001072 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f3, "Dell Inspiron 1420", STAC_D965_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +02001073 /* Dell 3 stack systems */
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001074 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01dd, "Dell Dimension E520", STAC_DELL_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +02001075 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ed, "Dell ", STAC_DELL_3ST),
1076 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f4, "Dell ", STAC_DELL_3ST),
Tobin Davis93ed1502006-09-01 21:03:12 +02001077 /* 965 based 5 stack systems */
Tim Gardner5e915bb2007-10-10 10:42:00 +02001078 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0209, "Dell XPS 1330", STAC_D965_5ST),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001079 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2301, "Intel D965", STAC_D965_5ST),
1080 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2302, "Intel D965", STAC_D965_5ST),
1081 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2303, "Intel D965", STAC_D965_5ST),
1082 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2304, "Intel D965", STAC_D965_5ST),
1083 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2305, "Intel D965", STAC_D965_5ST),
1084 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2501, "Intel D965", STAC_D965_5ST),
1085 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2502, "Intel D965", STAC_D965_5ST),
1086 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2503, "Intel D965", STAC_D965_5ST),
1087 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2504, "Intel D965", STAC_D965_5ST),
Matt Porter3cc08dc2006-01-23 15:27:49 +01001088 {} /* terminator */
1089};
1090
Matt Porterf3302a52006-07-31 12:49:34 +02001091static unsigned int ref9205_pin_configs[12] = {
1092 0x40000100, 0x40000100, 0x01016011, 0x01014010,
Matt Porter8b657272006-10-26 17:12:59 +02001093 0x01813122, 0x01a19021, 0x40000100, 0x40000100,
1094 0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
Matt Porterf3302a52006-07-31 12:49:34 +02001095};
1096
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001097/*
1098 STAC 9205 pin configs for
1099 102801F1
1100 102801F2
1101 102801FC
1102 102801FD
1103 10280204
1104 1028021F
1105*/
1106static unsigned int dell_9205_m42_pin_configs[12] = {
1107 0x0321101F, 0x03A11020, 0x400003FA, 0x90170310,
1108 0x400003FB, 0x400003FC, 0x400003FD, 0x40F000F9,
1109 0x90A60330, 0x400003FF, 0x0144131F, 0x40C003FE,
1110};
1111
1112/*
1113 STAC 9205 pin configs for
1114 102801F9
1115 102801FA
1116 102801FE
1117 102801FF (Dell Precision M4300)
1118 10280206
1119 10280200
1120 10280201
1121*/
1122static unsigned int dell_9205_m43_pin_configs[12] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001123 0x0321101f, 0x03a11020, 0x90a70330, 0x90170310,
1124 0x400000fe, 0x400000ff, 0x400000fd, 0x40f000f9,
1125 0x400000fa, 0x400000fc, 0x0144131f, 0x40c003f8,
1126};
1127
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001128static unsigned int dell_9205_m44_pin_configs[12] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001129 0x0421101f, 0x04a11020, 0x400003fa, 0x90170310,
1130 0x400003fb, 0x400003fc, 0x400003fd, 0x400003f9,
1131 0x90a60330, 0x400003ff, 0x01441340, 0x40c003fe,
1132};
1133
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001134static unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001135 [STAC_9205_REF] = ref9205_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001136 [STAC_9205_DELL_M42] = dell_9205_m42_pin_configs,
1137 [STAC_9205_DELL_M43] = dell_9205_m43_pin_configs,
1138 [STAC_9205_DELL_M44] = dell_9205_m44_pin_configs,
Matt Porterf3302a52006-07-31 12:49:34 +02001139};
1140
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001141static const char *stac9205_models[STAC_9205_MODELS] = {
1142 [STAC_9205_REF] = "ref",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001143 [STAC_9205_DELL_M42] = "dell-m42",
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001144 [STAC_9205_DELL_M43] = "dell-m43",
1145 [STAC_9205_DELL_M44] = "dell-m44",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001146};
1147
1148static struct snd_pci_quirk stac9205_cfg_tbl[] = {
1149 /* SigmaTel reference board */
1150 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1151 "DFI LanParty", STAC_9205_REF),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001152 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f1,
1153 "unknown Dell", STAC_9205_DELL_M42),
1154 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f2,
1155 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001156 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f8,
Matthew Ranostayb44ef2f2007-09-18 00:52:38 +02001157 "Dell Precision", STAC_9205_DELL_M43),
1158 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021c,
1159 "Dell Precision", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001160 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f9,
1161 "Dell Precision", STAC_9205_DELL_M43),
Matthew Ranostaye45e4592007-09-10 23:09:42 +02001162 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021b,
1163 "Dell Precision", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001164 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fa,
1165 "Dell Precision", STAC_9205_DELL_M43),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001166 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fc,
1167 "unknown Dell", STAC_9205_DELL_M42),
1168 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fd,
1169 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001170 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fe,
1171 "Dell Precision", STAC_9205_DELL_M43),
1172 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ff,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001173 "Dell Precision M4300", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001174 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0206,
1175 "Dell Precision", STAC_9205_DELL_M43),
1176 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f1,
1177 "Dell Inspiron", STAC_9205_DELL_M44),
1178 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f2,
1179 "Dell Inspiron", STAC_9205_DELL_M44),
1180 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fc,
1181 "Dell Inspiron", STAC_9205_DELL_M44),
1182 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fd,
1183 "Dell Inspiron", STAC_9205_DELL_M44),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001184 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0204,
1185 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001186 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021f,
1187 "Dell Inspiron", STAC_9205_DELL_M44),
Matt Porterf3302a52006-07-31 12:49:34 +02001188 {} /* terminator */
1189};
1190
Richard Fish11b44bb2006-08-23 18:31:34 +02001191static int stac92xx_save_bios_config_regs(struct hda_codec *codec)
1192{
1193 int i;
1194 struct sigmatel_spec *spec = codec->spec;
1195
1196 if (! spec->bios_pin_configs) {
1197 spec->bios_pin_configs = kcalloc(spec->num_pins,
1198 sizeof(*spec->bios_pin_configs), GFP_KERNEL);
1199 if (! spec->bios_pin_configs)
1200 return -ENOMEM;
1201 }
1202
1203 for (i = 0; i < spec->num_pins; i++) {
1204 hda_nid_t nid = spec->pin_nids[i];
1205 unsigned int pin_cfg;
1206
1207 pin_cfg = snd_hda_codec_read(codec, nid, 0,
1208 AC_VERB_GET_CONFIG_DEFAULT, 0x00);
1209 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x bios pin config %8.8x\n",
1210 nid, pin_cfg);
1211 spec->bios_pin_configs[i] = pin_cfg;
1212 }
1213
1214 return 0;
1215}
1216
Matthew Ranostay87d48362007-07-17 11:52:24 +02001217static void stac92xx_set_config_reg(struct hda_codec *codec,
1218 hda_nid_t pin_nid, unsigned int pin_config)
1219{
1220 int i;
1221 snd_hda_codec_write(codec, pin_nid, 0,
1222 AC_VERB_SET_CONFIG_DEFAULT_BYTES_0,
1223 pin_config & 0x000000ff);
1224 snd_hda_codec_write(codec, pin_nid, 0,
1225 AC_VERB_SET_CONFIG_DEFAULT_BYTES_1,
1226 (pin_config & 0x0000ff00) >> 8);
1227 snd_hda_codec_write(codec, pin_nid, 0,
1228 AC_VERB_SET_CONFIG_DEFAULT_BYTES_2,
1229 (pin_config & 0x00ff0000) >> 16);
1230 snd_hda_codec_write(codec, pin_nid, 0,
1231 AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
1232 pin_config >> 24);
1233 i = snd_hda_codec_read(codec, pin_nid, 0,
1234 AC_VERB_GET_CONFIG_DEFAULT,
1235 0x00);
1236 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x pin config %8.8x\n",
1237 pin_nid, i);
1238}
1239
Matt2f2f4252005-04-13 14:45:30 +02001240static void stac92xx_set_config_regs(struct hda_codec *codec)
1241{
1242 int i;
1243 struct sigmatel_spec *spec = codec->spec;
Matt2f2f4252005-04-13 14:45:30 +02001244
Matthew Ranostay87d48362007-07-17 11:52:24 +02001245 if (!spec->pin_configs)
1246 return;
Richard Fish11b44bb2006-08-23 18:31:34 +02001247
Matthew Ranostay87d48362007-07-17 11:52:24 +02001248 for (i = 0; i < spec->num_pins; i++)
1249 stac92xx_set_config_reg(codec, spec->pin_nids[i],
1250 spec->pin_configs[i]);
Matt2f2f4252005-04-13 14:45:30 +02001251}
Matt2f2f4252005-04-13 14:45:30 +02001252
Takashi Iwai82599802007-07-31 15:56:24 +02001253static void stac92xx_enable_gpio_mask(struct hda_codec *codec)
Matthew Ranostay92a22be2007-06-19 16:48:28 +02001254{
Takashi Iwai82599802007-07-31 15:56:24 +02001255 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay87d48362007-07-17 11:52:24 +02001256 /* Configure GPIOx as output */
Takashi Iwai82beb8f2007-08-10 17:09:26 +02001257 snd_hda_codec_write_cache(codec, codec->afg, 0,
1258 AC_VERB_SET_GPIO_DIRECTION, spec->gpio_mask);
Matthew Ranostay87d48362007-07-17 11:52:24 +02001259 /* Configure GPIOx as CMOS */
Takashi Iwai82beb8f2007-08-10 17:09:26 +02001260 snd_hda_codec_write_cache(codec, codec->afg, 0, 0x7e7, 0x00000000);
Matthew Ranostay87d48362007-07-17 11:52:24 +02001261 /* Assert GPIOx */
Takashi Iwai82beb8f2007-08-10 17:09:26 +02001262 snd_hda_codec_write_cache(codec, codec->afg, 0,
1263 AC_VERB_SET_GPIO_DATA, spec->gpio_data);
Matthew Ranostay87d48362007-07-17 11:52:24 +02001264 /* Enable GPIOx */
Takashi Iwai82beb8f2007-08-10 17:09:26 +02001265 snd_hda_codec_write_cache(codec, codec->afg, 0,
1266 AC_VERB_SET_GPIO_MASK, spec->gpio_mask);
Matthew Ranostay92a22be2007-06-19 16:48:28 +02001267}
1268
Matt2f2f4252005-04-13 14:45:30 +02001269/*
1270 * Analog playback callbacks
1271 */
1272static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
1273 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001274 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02001275{
1276 struct sigmatel_spec *spec = codec->spec;
1277 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
1278}
1279
1280static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1281 struct hda_codec *codec,
1282 unsigned int stream_tag,
1283 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001284 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02001285{
1286 struct sigmatel_spec *spec = codec->spec;
Matt Porter403d1942005-11-29 15:00:51 +01001287 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
Matt2f2f4252005-04-13 14:45:30 +02001288}
1289
1290static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
1291 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001292 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02001293{
1294 struct sigmatel_spec *spec = codec->spec;
1295 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
1296}
1297
1298/*
Mattdabbed62005-06-14 10:19:34 +02001299 * Digital playback callbacks
1300 */
1301static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
1302 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001303 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +02001304{
1305 struct sigmatel_spec *spec = codec->spec;
1306 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
1307}
1308
1309static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
1310 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001311 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +02001312{
1313 struct sigmatel_spec *spec = codec->spec;
1314 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
1315}
1316
Takashi Iwai6b97eb42007-04-05 14:51:48 +02001317static int stac92xx_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1318 struct hda_codec *codec,
1319 unsigned int stream_tag,
1320 unsigned int format,
1321 struct snd_pcm_substream *substream)
1322{
1323 struct sigmatel_spec *spec = codec->spec;
1324 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1325 stream_tag, format, substream);
1326}
1327
Mattdabbed62005-06-14 10:19:34 +02001328
1329/*
Matt2f2f4252005-04-13 14:45:30 +02001330 * Analog capture callbacks
1331 */
1332static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1333 struct hda_codec *codec,
1334 unsigned int stream_tag,
1335 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001336 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02001337{
1338 struct sigmatel_spec *spec = codec->spec;
1339
1340 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
1341 stream_tag, 0, format);
1342 return 0;
1343}
1344
1345static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1346 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001347 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02001348{
1349 struct sigmatel_spec *spec = codec->spec;
1350
1351 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 0, 0, 0);
1352 return 0;
1353}
1354
Mattdabbed62005-06-14 10:19:34 +02001355static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
1356 .substreams = 1,
1357 .channels_min = 2,
1358 .channels_max = 2,
1359 /* NID is set in stac92xx_build_pcms */
1360 .ops = {
1361 .open = stac92xx_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02001362 .close = stac92xx_dig_playback_pcm_close,
1363 .prepare = stac92xx_dig_playback_pcm_prepare
Mattdabbed62005-06-14 10:19:34 +02001364 },
1365};
1366
1367static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
1368 .substreams = 1,
1369 .channels_min = 2,
1370 .channels_max = 2,
1371 /* NID is set in stac92xx_build_pcms */
1372};
1373
Matt2f2f4252005-04-13 14:45:30 +02001374static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
1375 .substreams = 1,
1376 .channels_min = 2,
Mattc7d4b2f2005-06-27 14:59:41 +02001377 .channels_max = 8,
Matt2f2f4252005-04-13 14:45:30 +02001378 .nid = 0x02, /* NID to query formats and rates */
1379 .ops = {
1380 .open = stac92xx_playback_pcm_open,
1381 .prepare = stac92xx_playback_pcm_prepare,
1382 .cleanup = stac92xx_playback_pcm_cleanup
1383 },
1384};
1385
Matt Porter3cc08dc2006-01-23 15:27:49 +01001386static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
1387 .substreams = 1,
1388 .channels_min = 2,
1389 .channels_max = 2,
1390 .nid = 0x06, /* NID to query formats and rates */
1391 .ops = {
1392 .open = stac92xx_playback_pcm_open,
1393 .prepare = stac92xx_playback_pcm_prepare,
1394 .cleanup = stac92xx_playback_pcm_cleanup
1395 },
1396};
1397
Matt2f2f4252005-04-13 14:45:30 +02001398static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
Matt2f2f4252005-04-13 14:45:30 +02001399 .channels_min = 2,
1400 .channels_max = 2,
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001401 /* NID + .substreams is set in stac92xx_build_pcms */
Matt2f2f4252005-04-13 14:45:30 +02001402 .ops = {
1403 .prepare = stac92xx_capture_pcm_prepare,
1404 .cleanup = stac92xx_capture_pcm_cleanup
1405 },
1406};
1407
1408static int stac92xx_build_pcms(struct hda_codec *codec)
1409{
1410 struct sigmatel_spec *spec = codec->spec;
1411 struct hda_pcm *info = spec->pcm_rec;
1412
1413 codec->num_pcms = 1;
1414 codec->pcm_info = info;
1415
Mattc7d4b2f2005-06-27 14:59:41 +02001416 info->name = "STAC92xx Analog";
Matt2f2f4252005-04-13 14:45:30 +02001417 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
Matt2f2f4252005-04-13 14:45:30 +02001418 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
Matt Porter3cc08dc2006-01-23 15:27:49 +01001419 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001420 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adcs;
Matt Porter3cc08dc2006-01-23 15:27:49 +01001421
1422 if (spec->alt_switch) {
1423 codec->num_pcms++;
1424 info++;
1425 info->name = "STAC92xx Analog Alt";
1426 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
1427 }
Matt2f2f4252005-04-13 14:45:30 +02001428
Mattdabbed62005-06-14 10:19:34 +02001429 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
1430 codec->num_pcms++;
1431 info++;
1432 info->name = "STAC92xx Digital";
1433 if (spec->multiout.dig_out_nid) {
1434 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
1435 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
1436 }
1437 if (spec->dig_in_nid) {
1438 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
1439 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
1440 }
1441 }
1442
Matt2f2f4252005-04-13 14:45:30 +02001443 return 0;
1444}
1445
Takashi Iwaic960a032006-03-23 17:06:28 +01001446static unsigned int stac92xx_get_vref(struct hda_codec *codec, hda_nid_t nid)
1447{
1448 unsigned int pincap = snd_hda_param_read(codec, nid,
1449 AC_PAR_PIN_CAP);
1450 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
1451 if (pincap & AC_PINCAP_VREF_100)
1452 return AC_PINCTL_VREF_100;
1453 if (pincap & AC_PINCAP_VREF_80)
1454 return AC_PINCTL_VREF_80;
1455 if (pincap & AC_PINCAP_VREF_50)
1456 return AC_PINCTL_VREF_50;
1457 if (pincap & AC_PINCAP_VREF_GRD)
1458 return AC_PINCTL_VREF_GRD;
1459 return 0;
1460}
1461
Matt Porter403d1942005-11-29 15:00:51 +01001462static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
1463
1464{
Takashi Iwai82beb8f2007-08-10 17:09:26 +02001465 snd_hda_codec_write_cache(codec, nid, 0,
1466 AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
Matt Porter403d1942005-11-29 15:00:51 +01001467}
1468
Takashi Iwaia5ce8892007-07-23 15:42:26 +02001469#define stac92xx_io_switch_info snd_ctl_boolean_mono_info
Matt Porter403d1942005-11-29 15:00:51 +01001470
1471static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1472{
1473 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1474 struct sigmatel_spec *spec = codec->spec;
1475 int io_idx = kcontrol-> private_value & 0xff;
1476
1477 ucontrol->value.integer.value[0] = spec->io_switch[io_idx];
1478 return 0;
1479}
1480
1481static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1482{
1483 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1484 struct sigmatel_spec *spec = codec->spec;
1485 hda_nid_t nid = kcontrol->private_value >> 8;
1486 int io_idx = kcontrol-> private_value & 0xff;
1487 unsigned short val = ucontrol->value.integer.value[0];
1488
1489 spec->io_switch[io_idx] = val;
1490
1491 if (val)
1492 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
Takashi Iwaic960a032006-03-23 17:06:28 +01001493 else {
1494 unsigned int pinctl = AC_PINCTL_IN_EN;
1495 if (io_idx) /* set VREF for mic */
1496 pinctl |= stac92xx_get_vref(codec, nid);
1497 stac92xx_auto_set_pinctl(codec, nid, pinctl);
1498 }
Matt Porter403d1942005-11-29 15:00:51 +01001499 return 1;
1500}
1501
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02001502#define stac92xx_clfe_switch_info snd_ctl_boolean_mono_info
1503
1504static int stac92xx_clfe_switch_get(struct snd_kcontrol *kcontrol,
1505 struct snd_ctl_elem_value *ucontrol)
1506{
1507 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1508 struct sigmatel_spec *spec = codec->spec;
1509
1510 ucontrol->value.integer.value[0] = spec->clfe_swap;
1511 return 0;
1512}
1513
1514static int stac92xx_clfe_switch_put(struct snd_kcontrol *kcontrol,
1515 struct snd_ctl_elem_value *ucontrol)
1516{
1517 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1518 struct sigmatel_spec *spec = codec->spec;
1519 hda_nid_t nid = kcontrol->private_value & 0xff;
1520
1521 if (spec->clfe_swap == ucontrol->value.integer.value[0])
1522 return 0;
1523
1524 spec->clfe_swap = ucontrol->value.integer.value[0];
1525
1526 snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
1527 spec->clfe_swap ? 0x4 : 0x0);
1528
1529 return 1;
1530}
1531
Matt Porter403d1942005-11-29 15:00:51 +01001532#define STAC_CODEC_IO_SWITCH(xname, xpval) \
1533 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1534 .name = xname, \
1535 .index = 0, \
1536 .info = stac92xx_io_switch_info, \
1537 .get = stac92xx_io_switch_get, \
1538 .put = stac92xx_io_switch_put, \
1539 .private_value = xpval, \
1540 }
1541
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02001542#define STAC_CODEC_CLFE_SWITCH(xname, xpval) \
1543 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1544 .name = xname, \
1545 .index = 0, \
1546 .info = stac92xx_clfe_switch_info, \
1547 .get = stac92xx_clfe_switch_get, \
1548 .put = stac92xx_clfe_switch_put, \
1549 .private_value = xpval, \
1550 }
Matt Porter403d1942005-11-29 15:00:51 +01001551
Mattc7d4b2f2005-06-27 14:59:41 +02001552enum {
1553 STAC_CTL_WIDGET_VOL,
1554 STAC_CTL_WIDGET_MUTE,
Matt Porter403d1942005-11-29 15:00:51 +01001555 STAC_CTL_WIDGET_IO_SWITCH,
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02001556 STAC_CTL_WIDGET_CLFE_SWITCH
Mattc7d4b2f2005-06-27 14:59:41 +02001557};
1558
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001559static struct snd_kcontrol_new stac92xx_control_templates[] = {
Mattc7d4b2f2005-06-27 14:59:41 +02001560 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
1561 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Matt Porter403d1942005-11-29 15:00:51 +01001562 STAC_CODEC_IO_SWITCH(NULL, 0),
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02001563 STAC_CODEC_CLFE_SWITCH(NULL, 0),
Mattc7d4b2f2005-06-27 14:59:41 +02001564};
1565
1566/* add dynamic controls */
1567static int stac92xx_add_control(struct sigmatel_spec *spec, int type, const char *name, unsigned long val)
1568{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001569 struct snd_kcontrol_new *knew;
Mattc7d4b2f2005-06-27 14:59:41 +02001570
1571 if (spec->num_kctl_used >= spec->num_kctl_alloc) {
1572 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
1573
1574 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */
1575 if (! knew)
1576 return -ENOMEM;
1577 if (spec->kctl_alloc) {
1578 memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
1579 kfree(spec->kctl_alloc);
1580 }
1581 spec->kctl_alloc = knew;
1582 spec->num_kctl_alloc = num;
1583 }
1584
1585 knew = &spec->kctl_alloc[spec->num_kctl_used];
1586 *knew = stac92xx_control_templates[type];
Takashi Iwai82fe0c52005-06-30 10:54:33 +02001587 knew->name = kstrdup(name, GFP_KERNEL);
Mattc7d4b2f2005-06-27 14:59:41 +02001588 if (! knew->name)
1589 return -ENOMEM;
1590 knew->private_value = val;
1591 spec->num_kctl_used++;
1592 return 0;
1593}
1594
Matt Porter403d1942005-11-29 15:00:51 +01001595/* flag inputs as additional dynamic lineouts */
1596static int stac92xx_add_dyn_out_pins(struct hda_codec *codec, struct auto_pin_cfg *cfg)
1597{
1598 struct sigmatel_spec *spec = codec->spec;
Steve Longerbeam7b043892007-05-03 20:50:03 +02001599 unsigned int wcaps, wtype;
1600 int i, num_dacs = 0;
1601
1602 /* use the wcaps cache to count all DACs available for line-outs */
1603 for (i = 0; i < codec->num_nodes; i++) {
1604 wcaps = codec->wcaps[i];
1605 wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
1606 if (wtype == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL))
1607 num_dacs++;
1608 }
Matt Porter403d1942005-11-29 15:00:51 +01001609
Steve Longerbeam7b043892007-05-03 20:50:03 +02001610 snd_printdd("%s: total dac count=%d\n", __func__, num_dacs);
1611
Matt Porter403d1942005-11-29 15:00:51 +01001612 switch (cfg->line_outs) {
1613 case 3:
1614 /* add line-in as side */
Steve Longerbeam7b043892007-05-03 20:50:03 +02001615 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 3) {
Takashi Iwaic480f792007-09-03 09:43:38 +02001616 cfg->line_out_pins[cfg->line_outs] =
1617 cfg->input_pins[AUTO_PIN_LINE];
Matt Porter403d1942005-11-29 15:00:51 +01001618 spec->line_switch = 1;
1619 cfg->line_outs++;
1620 }
1621 break;
1622 case 2:
1623 /* add line-in as clfe and mic as side */
Steve Longerbeam7b043892007-05-03 20:50:03 +02001624 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 2) {
Takashi Iwaic480f792007-09-03 09:43:38 +02001625 cfg->line_out_pins[cfg->line_outs] =
1626 cfg->input_pins[AUTO_PIN_LINE];
Matt Porter403d1942005-11-29 15:00:51 +01001627 spec->line_switch = 1;
1628 cfg->line_outs++;
1629 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02001630 if (cfg->input_pins[AUTO_PIN_MIC] && num_dacs > 3) {
Takashi Iwaic480f792007-09-03 09:43:38 +02001631 cfg->line_out_pins[cfg->line_outs] =
1632 cfg->input_pins[AUTO_PIN_MIC];
Matt Porter403d1942005-11-29 15:00:51 +01001633 spec->mic_switch = 1;
1634 cfg->line_outs++;
1635 }
1636 break;
1637 case 1:
1638 /* add line-in as surr and mic as clfe */
Steve Longerbeam7b043892007-05-03 20:50:03 +02001639 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 1) {
Takashi Iwaic480f792007-09-03 09:43:38 +02001640 cfg->line_out_pins[cfg->line_outs] =
1641 cfg->input_pins[AUTO_PIN_LINE];
Matt Porter403d1942005-11-29 15:00:51 +01001642 spec->line_switch = 1;
1643 cfg->line_outs++;
1644 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02001645 if (cfg->input_pins[AUTO_PIN_MIC] && num_dacs > 2) {
Takashi Iwaic480f792007-09-03 09:43:38 +02001646 cfg->line_out_pins[cfg->line_outs] =
1647 cfg->input_pins[AUTO_PIN_MIC];
Matt Porter403d1942005-11-29 15:00:51 +01001648 spec->mic_switch = 1;
1649 cfg->line_outs++;
1650 }
1651 break;
1652 }
1653
1654 return 0;
1655}
1656
Steve Longerbeam7b043892007-05-03 20:50:03 +02001657
1658static int is_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
1659{
1660 int i;
1661
1662 for (i = 0; i < spec->multiout.num_dacs; i++) {
1663 if (spec->multiout.dac_nids[i] == nid)
1664 return 1;
1665 }
1666
1667 return 0;
1668}
1669
Matt Porter3cc08dc2006-01-23 15:27:49 +01001670/*
Steve Longerbeam7b043892007-05-03 20:50:03 +02001671 * Fill in the dac_nids table from the parsed pin configuration
1672 * This function only works when every pin in line_out_pins[]
1673 * contains atleast one DAC in its connection list. Some 92xx
1674 * codecs are not connected directly to a DAC, such as the 9200
1675 * and 9202/925x. For those, dac_nids[] must be hard-coded.
Matt Porter3cc08dc2006-01-23 15:27:49 +01001676 */
Takashi Iwai19039bd2006-06-28 15:52:16 +02001677static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec,
Takashi Iwaidf802952007-07-02 19:18:00 +02001678 struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02001679{
1680 struct sigmatel_spec *spec = codec->spec;
Steve Longerbeam7b043892007-05-03 20:50:03 +02001681 int i, j, conn_len = 0;
1682 hda_nid_t nid, conn[HDA_MAX_CONNECTIONS];
1683 unsigned int wcaps, wtype;
1684
Mattc7d4b2f2005-06-27 14:59:41 +02001685 for (i = 0; i < cfg->line_outs; i++) {
1686 nid = cfg->line_out_pins[i];
Steve Longerbeam7b043892007-05-03 20:50:03 +02001687 conn_len = snd_hda_get_connections(codec, nid, conn,
1688 HDA_MAX_CONNECTIONS);
1689 for (j = 0; j < conn_len; j++) {
1690 wcaps = snd_hda_param_read(codec, conn[j],
1691 AC_PAR_AUDIO_WIDGET_CAP);
1692 wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
1693
1694 if (wtype != AC_WID_AUD_OUT ||
1695 (wcaps & AC_WCAP_DIGITAL))
1696 continue;
1697 /* conn[j] is a DAC routed to this line-out */
1698 if (!is_in_dac_nids(spec, conn[j]))
1699 break;
1700 }
1701
1702 if (j == conn_len) {
Takashi Iwaidf802952007-07-02 19:18:00 +02001703 if (spec->multiout.num_dacs > 0) {
1704 /* we have already working output pins,
1705 * so let's drop the broken ones again
1706 */
1707 cfg->line_outs = spec->multiout.num_dacs;
1708 break;
1709 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02001710 /* error out, no available DAC found */
1711 snd_printk(KERN_ERR
1712 "%s: No available DAC for pin 0x%x\n",
1713 __func__, nid);
1714 return -ENODEV;
1715 }
1716
1717 spec->multiout.dac_nids[i] = conn[j];
1718 spec->multiout.num_dacs++;
1719 if (conn_len > 1) {
1720 /* select this DAC in the pin's input mux */
Takashi Iwai82beb8f2007-08-10 17:09:26 +02001721 snd_hda_codec_write_cache(codec, nid, 0,
1722 AC_VERB_SET_CONNECT_SEL, j);
Steve Longerbeam7b043892007-05-03 20:50:03 +02001723
1724 }
Mattc7d4b2f2005-06-27 14:59:41 +02001725 }
1726
Steve Longerbeam7b043892007-05-03 20:50:03 +02001727 snd_printd("dac_nids=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
1728 spec->multiout.num_dacs,
1729 spec->multiout.dac_nids[0],
1730 spec->multiout.dac_nids[1],
1731 spec->multiout.dac_nids[2],
1732 spec->multiout.dac_nids[3],
1733 spec->multiout.dac_nids[4]);
Mattc7d4b2f2005-06-27 14:59:41 +02001734 return 0;
1735}
1736
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001737/* create volume control/switch for the given prefx type */
1738static int create_controls(struct sigmatel_spec *spec, const char *pfx, hda_nid_t nid, int chs)
1739{
1740 char name[32];
1741 int err;
1742
1743 sprintf(name, "%s Playback Volume", pfx);
1744 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, name,
1745 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1746 if (err < 0)
1747 return err;
1748 sprintf(name, "%s Playback Switch", pfx);
1749 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, name,
1750 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1751 if (err < 0)
1752 return err;
1753 return 0;
1754}
1755
Mattc7d4b2f2005-06-27 14:59:41 +02001756/* add playback controls from the parsed DAC table */
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02001757static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
Takashi Iwai19039bd2006-06-28 15:52:16 +02001758 const struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02001759{
Takashi Iwai19039bd2006-06-28 15:52:16 +02001760 static const char *chname[4] = {
1761 "Front", "Surround", NULL /*CLFE*/, "Side"
1762 };
Mattc7d4b2f2005-06-27 14:59:41 +02001763 hda_nid_t nid;
1764 int i, err;
1765
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02001766 struct sigmatel_spec *spec = codec->spec;
1767 unsigned int wid_caps;
1768
1769
Mattc7d4b2f2005-06-27 14:59:41 +02001770 for (i = 0; i < cfg->line_outs; i++) {
Matt Porter403d1942005-11-29 15:00:51 +01001771 if (!spec->multiout.dac_nids[i])
Mattc7d4b2f2005-06-27 14:59:41 +02001772 continue;
1773
1774 nid = spec->multiout.dac_nids[i];
1775
1776 if (i == 2) {
1777 /* Center/LFE */
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001778 err = create_controls(spec, "Center", nid, 1);
1779 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001780 return err;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001781 err = create_controls(spec, "LFE", nid, 2);
1782 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001783 return err;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02001784
1785 wid_caps = get_wcaps(codec, nid);
1786
1787 if (wid_caps & AC_WCAP_LR_SWAP) {
1788 err = stac92xx_add_control(spec,
1789 STAC_CTL_WIDGET_CLFE_SWITCH,
1790 "Swap Center/LFE Playback Switch", nid);
1791
1792 if (err < 0)
1793 return err;
1794 }
1795
Mattc7d4b2f2005-06-27 14:59:41 +02001796 } else {
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001797 err = create_controls(spec, chname[i], nid, 3);
1798 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001799 return err;
1800 }
1801 }
1802
Matt Porter403d1942005-11-29 15:00:51 +01001803 if (spec->line_switch)
1804 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Line In as Output Switch", cfg->input_pins[AUTO_PIN_LINE] << 8)) < 0)
1805 return err;
1806
1807 if (spec->mic_switch)
1808 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Mic as Output Switch", (cfg->input_pins[AUTO_PIN_MIC] << 8) | 1)) < 0)
1809 return err;
1810
Mattc7d4b2f2005-06-27 14:59:41 +02001811 return 0;
1812}
1813
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001814static int check_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
1815{
Steve Longerbeam7b043892007-05-03 20:50:03 +02001816 if (is_in_dac_nids(spec, nid))
1817 return 1;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001818 if (spec->multiout.hp_nid == nid)
1819 return 1;
1820 return 0;
1821}
1822
1823static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
1824{
1825 if (!spec->multiout.hp_nid)
1826 spec->multiout.hp_nid = nid;
1827 else if (spec->multiout.num_dacs > 4) {
1828 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
1829 return 1;
1830 } else {
1831 spec->multiout.dac_nids[spec->multiout.num_dacs] = nid;
1832 spec->multiout.num_dacs++;
1833 }
1834 return 0;
1835}
1836
1837/* add playback controls for Speaker and HP outputs */
1838static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
1839 struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02001840{
1841 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02001842 hda_nid_t nid;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001843 int i, old_num_dacs, err;
Mattc7d4b2f2005-06-27 14:59:41 +02001844
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001845 old_num_dacs = spec->multiout.num_dacs;
1846 for (i = 0; i < cfg->hp_outs; i++) {
1847 unsigned int wid_caps = get_wcaps(codec, cfg->hp_pins[i]);
1848 if (wid_caps & AC_WCAP_UNSOL_CAP)
1849 spec->hp_detect = 1;
1850 nid = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
1851 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
1852 if (check_in_dac_nids(spec, nid))
1853 nid = 0;
1854 if (! nid)
Mattc7d4b2f2005-06-27 14:59:41 +02001855 continue;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001856 add_spec_dacs(spec, nid);
1857 }
1858 for (i = 0; i < cfg->speaker_outs; i++) {
Steve Longerbeam7b043892007-05-03 20:50:03 +02001859 nid = snd_hda_codec_read(codec, cfg->speaker_pins[i], 0,
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001860 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
1861 if (check_in_dac_nids(spec, nid))
1862 nid = 0;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001863 if (! nid)
1864 continue;
1865 add_spec_dacs(spec, nid);
Mattc7d4b2f2005-06-27 14:59:41 +02001866 }
Matthew Ranostay1b290a52007-07-12 15:17:34 +02001867 for (i = 0; i < cfg->line_outs; i++) {
1868 nid = snd_hda_codec_read(codec, cfg->line_out_pins[i], 0,
1869 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
1870 if (check_in_dac_nids(spec, nid))
1871 nid = 0;
1872 if (! nid)
1873 continue;
1874 add_spec_dacs(spec, nid);
1875 }
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001876 for (i = old_num_dacs; i < spec->multiout.num_dacs; i++) {
1877 static const char *pfxs[] = {
1878 "Speaker", "External Speaker", "Speaker2",
1879 };
1880 err = create_controls(spec, pfxs[i - old_num_dacs],
1881 spec->multiout.dac_nids[i], 3);
1882 if (err < 0)
1883 return err;
1884 }
1885 if (spec->multiout.hp_nid) {
1886 const char *pfx;
Takashi Iwai6020c002007-11-19 11:56:26 +01001887 if (old_num_dacs == spec->multiout.num_dacs)
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001888 pfx = "Master";
1889 else
1890 pfx = "Headphone";
1891 err = create_controls(spec, pfx, spec->multiout.hp_nid, 3);
1892 if (err < 0)
1893 return err;
1894 }
Mattc7d4b2f2005-06-27 14:59:41 +02001895
1896 return 0;
1897}
1898
Matt Porter8b657272006-10-26 17:12:59 +02001899/* labels for dmic mux inputs */
Adrian Bunkddc2cec2006-11-20 12:03:44 +01001900static const char *stac92xx_dmic_labels[5] = {
Matt Porter8b657272006-10-26 17:12:59 +02001901 "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
1902 "Digital Mic 3", "Digital Mic 4"
1903};
1904
1905/* create playback/capture controls for input pins on dmic capable codecs */
1906static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
1907 const struct auto_pin_cfg *cfg)
1908{
1909 struct sigmatel_spec *spec = codec->spec;
1910 struct hda_input_mux *dimux = &spec->private_dimux;
1911 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
1912 int i, j;
1913
1914 dimux->items[dimux->num_items].label = stac92xx_dmic_labels[0];
1915 dimux->items[dimux->num_items].index = 0;
1916 dimux->num_items++;
1917
1918 for (i = 0; i < spec->num_dmics; i++) {
1919 int index;
1920 int num_cons;
1921 unsigned int def_conf;
1922
1923 def_conf = snd_hda_codec_read(codec,
1924 spec->dmic_nids[i],
1925 0,
1926 AC_VERB_GET_CONFIG_DEFAULT,
1927 0);
1928 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
1929 continue;
1930
1931 num_cons = snd_hda_get_connections(codec,
1932 spec->dmux_nid,
1933 con_lst,
1934 HDA_MAX_NUM_INPUTS);
1935 for (j = 0; j < num_cons; j++)
1936 if (con_lst[j] == spec->dmic_nids[i]) {
1937 index = j;
1938 goto found;
1939 }
1940 continue;
1941found:
1942 dimux->items[dimux->num_items].label =
1943 stac92xx_dmic_labels[dimux->num_items];
1944 dimux->items[dimux->num_items].index = index;
1945 dimux->num_items++;
1946 }
1947
1948 return 0;
1949}
1950
Mattc7d4b2f2005-06-27 14:59:41 +02001951/* create playback/capture controls for input pins */
1952static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
1953{
1954 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02001955 struct hda_input_mux *imux = &spec->private_imux;
1956 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
1957 int i, j, k;
1958
1959 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwai314634b2006-09-21 11:56:18 +02001960 int index;
Mattc7d4b2f2005-06-27 14:59:41 +02001961
Takashi Iwai314634b2006-09-21 11:56:18 +02001962 if (!cfg->input_pins[i])
1963 continue;
1964 index = -1;
1965 for (j = 0; j < spec->num_muxes; j++) {
1966 int num_cons;
1967 num_cons = snd_hda_get_connections(codec,
1968 spec->mux_nids[j],
1969 con_lst,
1970 HDA_MAX_NUM_INPUTS);
1971 for (k = 0; k < num_cons; k++)
1972 if (con_lst[k] == cfg->input_pins[i]) {
1973 index = k;
1974 goto found;
1975 }
Mattc7d4b2f2005-06-27 14:59:41 +02001976 }
Takashi Iwai314634b2006-09-21 11:56:18 +02001977 continue;
1978 found:
1979 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
1980 imux->items[imux->num_items].index = index;
1981 imux->num_items++;
Mattc7d4b2f2005-06-27 14:59:41 +02001982 }
1983
Steve Longerbeam7b043892007-05-03 20:50:03 +02001984 if (imux->num_items) {
Sam Revitch62fe78e2006-05-10 15:09:17 +02001985 /*
1986 * Set the current input for the muxes.
1987 * The STAC9221 has two input muxes with identical source
1988 * NID lists. Hopefully this won't get confused.
1989 */
1990 for (i = 0; i < spec->num_muxes; i++) {
Takashi Iwai82beb8f2007-08-10 17:09:26 +02001991 snd_hda_codec_write_cache(codec, spec->mux_nids[i], 0,
1992 AC_VERB_SET_CONNECT_SEL,
1993 imux->items[0].index);
Sam Revitch62fe78e2006-05-10 15:09:17 +02001994 }
1995 }
1996
Mattc7d4b2f2005-06-27 14:59:41 +02001997 return 0;
1998}
1999
Mattc7d4b2f2005-06-27 14:59:41 +02002000static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
2001{
2002 struct sigmatel_spec *spec = codec->spec;
2003 int i;
2004
2005 for (i = 0; i < spec->autocfg.line_outs; i++) {
2006 hda_nid_t nid = spec->autocfg.line_out_pins[i];
2007 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
2008 }
2009}
2010
2011static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
2012{
2013 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002014 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02002015
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002016 for (i = 0; i < spec->autocfg.hp_outs; i++) {
2017 hda_nid_t pin;
2018 pin = spec->autocfg.hp_pins[i];
2019 if (pin) /* connect to front */
2020 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
2021 }
2022 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
2023 hda_nid_t pin;
2024 pin = spec->autocfg.speaker_pins[i];
2025 if (pin) /* connect to front */
2026 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
2027 }
Mattc7d4b2f2005-06-27 14:59:41 +02002028}
2029
Matt Porter3cc08dc2006-01-23 15:27:49 +01002030static 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 +02002031{
2032 struct sigmatel_spec *spec = codec->spec;
2033 int err;
2034
Matt Porter8b657272006-10-26 17:12:59 +02002035 if ((err = snd_hda_parse_pin_def_config(codec,
2036 &spec->autocfg,
2037 spec->dmic_nids)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02002038 return err;
Takashi Iwai82bc9552006-03-21 11:24:42 +01002039 if (! spec->autocfg.line_outs)
Matt Porter869264c2006-01-25 19:20:50 +01002040 return 0; /* can't find valid pin config */
Takashi Iwai19039bd2006-06-28 15:52:16 +02002041
Matt Porter403d1942005-11-29 15:00:51 +01002042 if ((err = stac92xx_add_dyn_out_pins(codec, &spec->autocfg)) < 0)
2043 return err;
Takashi Iwai19039bd2006-06-28 15:52:16 +02002044 if (spec->multiout.num_dacs == 0)
2045 if ((err = stac92xx_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
2046 return err;
Mattc7d4b2f2005-06-27 14:59:41 +02002047
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002048 err = stac92xx_auto_create_multi_out_ctls(codec, &spec->autocfg);
2049
2050 if (err < 0)
2051 return err;
2052
2053 err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg);
2054
2055 if (err < 0)
2056 return err;
2057
2058 err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg);
2059
2060 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02002061 return err;
2062
Matt Porter8b657272006-10-26 17:12:59 +02002063 if (spec->num_dmics > 0)
2064 if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
2065 &spec->autocfg)) < 0)
2066 return err;
2067
Mattc7d4b2f2005-06-27 14:59:41 +02002068 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Matt Porter403d1942005-11-29 15:00:51 +01002069 if (spec->multiout.max_channels > 2)
Mattc7d4b2f2005-06-27 14:59:41 +02002070 spec->surr_switch = 1;
Mattc7d4b2f2005-06-27 14:59:41 +02002071
Takashi Iwai82bc9552006-03-21 11:24:42 +01002072 if (spec->autocfg.dig_out_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01002073 spec->multiout.dig_out_nid = dig_out;
Takashi Iwai82bc9552006-03-21 11:24:42 +01002074 if (spec->autocfg.dig_in_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01002075 spec->dig_in_nid = dig_in;
Mattc7d4b2f2005-06-27 14:59:41 +02002076
2077 if (spec->kctl_alloc)
2078 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
2079
2080 spec->input_mux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02002081 spec->dinput_mux = &spec->private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +02002082
2083 return 1;
2084}
2085
Takashi Iwai82bc9552006-03-21 11:24:42 +01002086/* add playback controls for HP output */
2087static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
2088 struct auto_pin_cfg *cfg)
2089{
2090 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002091 hda_nid_t pin = cfg->hp_pins[0];
Takashi Iwai82bc9552006-03-21 11:24:42 +01002092 unsigned int wid_caps;
2093
2094 if (! pin)
2095 return 0;
2096
2097 wid_caps = get_wcaps(codec, pin);
Takashi Iwai505cb342006-03-27 12:51:52 +02002098 if (wid_caps & AC_WCAP_UNSOL_CAP)
Takashi Iwai82bc9552006-03-21 11:24:42 +01002099 spec->hp_detect = 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +01002100
2101 return 0;
2102}
2103
Richard Fish160ea0d2006-09-06 13:58:25 +02002104/* add playback controls for LFE output */
2105static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
2106 struct auto_pin_cfg *cfg)
2107{
2108 struct sigmatel_spec *spec = codec->spec;
2109 int err;
2110 hda_nid_t lfe_pin = 0x0;
2111 int i;
2112
2113 /*
2114 * search speaker outs and line outs for a mono speaker pin
2115 * with an amp. If one is found, add LFE controls
2116 * for it.
2117 */
2118 for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
2119 hda_nid_t pin = spec->autocfg.speaker_pins[i];
2120 unsigned long wcaps = get_wcaps(codec, pin);
2121 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
2122 if (wcaps == AC_WCAP_OUT_AMP)
2123 /* found a mono speaker with an amp, must be lfe */
2124 lfe_pin = pin;
2125 }
2126
2127 /* if speaker_outs is 0, then speakers may be in line_outs */
2128 if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
2129 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
2130 hda_nid_t pin = spec->autocfg.line_out_pins[i];
2131 unsigned long cfg;
2132 cfg = snd_hda_codec_read(codec, pin, 0,
2133 AC_VERB_GET_CONFIG_DEFAULT,
2134 0x00);
2135 if (get_defcfg_device(cfg) == AC_JACK_SPEAKER) {
2136 unsigned long wcaps = get_wcaps(codec, pin);
2137 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
2138 if (wcaps == AC_WCAP_OUT_AMP)
2139 /* found a mono speaker with an amp,
2140 must be lfe */
2141 lfe_pin = pin;
2142 }
2143 }
2144 }
2145
2146 if (lfe_pin) {
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002147 err = create_controls(spec, "LFE", lfe_pin, 1);
Richard Fish160ea0d2006-09-06 13:58:25 +02002148 if (err < 0)
2149 return err;
2150 }
2151
2152 return 0;
2153}
2154
Mattc7d4b2f2005-06-27 14:59:41 +02002155static int stac9200_parse_auto_config(struct hda_codec *codec)
2156{
2157 struct sigmatel_spec *spec = codec->spec;
2158 int err;
2159
Kailang Yangdf694da2005-12-05 19:42:22 +01002160 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02002161 return err;
2162
2163 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
2164 return err;
2165
Takashi Iwai82bc9552006-03-21 11:24:42 +01002166 if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
2167 return err;
2168
Richard Fish160ea0d2006-09-06 13:58:25 +02002169 if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
2170 return err;
2171
Takashi Iwai82bc9552006-03-21 11:24:42 +01002172 if (spec->autocfg.dig_out_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02002173 spec->multiout.dig_out_nid = 0x05;
Takashi Iwai82bc9552006-03-21 11:24:42 +01002174 if (spec->autocfg.dig_in_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02002175 spec->dig_in_nid = 0x04;
Mattc7d4b2f2005-06-27 14:59:41 +02002176
2177 if (spec->kctl_alloc)
2178 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
2179
2180 spec->input_mux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02002181 spec->dinput_mux = &spec->private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +02002182
2183 return 1;
2184}
2185
Sam Revitch62fe78e2006-05-10 15:09:17 +02002186/*
2187 * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
2188 * funky external mute control using GPIO pins.
2189 */
2190
2191static void stac922x_gpio_mute(struct hda_codec *codec, int pin, int muted)
2192{
2193 unsigned int gpiostate, gpiomask, gpiodir;
2194
2195 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
2196 AC_VERB_GET_GPIO_DATA, 0);
2197
2198 if (!muted)
2199 gpiostate |= (1 << pin);
2200 else
2201 gpiostate &= ~(1 << pin);
2202
2203 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
2204 AC_VERB_GET_GPIO_MASK, 0);
2205 gpiomask |= (1 << pin);
2206
2207 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
2208 AC_VERB_GET_GPIO_DIRECTION, 0);
2209 gpiodir |= (1 << pin);
2210
2211 /* AppleHDA seems to do this -- WTF is this verb?? */
2212 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
2213
2214 snd_hda_codec_write(codec, codec->afg, 0,
2215 AC_VERB_SET_GPIO_MASK, gpiomask);
2216 snd_hda_codec_write(codec, codec->afg, 0,
2217 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
2218
2219 msleep(1);
2220
2221 snd_hda_codec_write(codec, codec->afg, 0,
2222 AC_VERB_SET_GPIO_DATA, gpiostate);
2223}
2224
Takashi Iwai314634b2006-09-21 11:56:18 +02002225static void enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
2226 unsigned int event)
2227{
2228 if (get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP)
Takashi Iwaidc81bed2007-09-03 09:36:36 +02002229 snd_hda_codec_write_cache(codec, nid, 0,
2230 AC_VERB_SET_UNSOLICITED_ENABLE,
2231 (AC_USRSP_EN | event));
Takashi Iwai314634b2006-09-21 11:56:18 +02002232}
2233
Mattc7d4b2f2005-06-27 14:59:41 +02002234static int stac92xx_init(struct hda_codec *codec)
2235{
2236 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai82bc9552006-03-21 11:24:42 +01002237 struct auto_pin_cfg *cfg = &spec->autocfg;
2238 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02002239
Mattc7d4b2f2005-06-27 14:59:41 +02002240 snd_hda_sequence_write(codec, spec->init);
2241
Takashi Iwai82bc9552006-03-21 11:24:42 +01002242 /* set up pins */
2243 if (spec->hp_detect) {
Takashi Iwai505cb342006-03-27 12:51:52 +02002244 /* Enable unsolicited responses on the HP widget */
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002245 for (i = 0; i < cfg->hp_outs; i++)
Takashi Iwai314634b2006-09-21 11:56:18 +02002246 enable_pin_detect(codec, cfg->hp_pins[i],
2247 STAC_HP_EVENT);
Takashi Iwai0a07aca2007-03-13 10:40:23 +01002248 /* force to enable the first line-out; the others are set up
2249 * in unsol_event
2250 */
2251 stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
2252 AC_PINCTL_OUT_EN);
Takashi Iwaieb995a82006-09-21 14:28:21 +02002253 stac92xx_auto_init_hp_out(codec);
Takashi Iwai82bc9552006-03-21 11:24:42 +01002254 /* fake event to set up pins */
2255 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
2256 } else {
2257 stac92xx_auto_init_multi_out(codec);
2258 stac92xx_auto_init_hp_out(codec);
2259 }
2260 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwaic960a032006-03-23 17:06:28 +01002261 hda_nid_t nid = cfg->input_pins[i];
2262 if (nid) {
2263 unsigned int pinctl = AC_PINCTL_IN_EN;
2264 if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC)
2265 pinctl |= stac92xx_get_vref(codec, nid);
2266 stac92xx_auto_set_pinctl(codec, nid, pinctl);
2267 }
Takashi Iwai82bc9552006-03-21 11:24:42 +01002268 }
Matt Porter8b657272006-10-26 17:12:59 +02002269 if (spec->num_dmics > 0)
2270 for (i = 0; i < spec->num_dmics; i++)
2271 stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
2272 AC_PINCTL_IN_EN);
2273
Takashi Iwai82bc9552006-03-21 11:24:42 +01002274 if (cfg->dig_out_pin)
2275 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pin,
2276 AC_PINCTL_OUT_EN);
2277 if (cfg->dig_in_pin)
2278 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
2279 AC_PINCTL_IN_EN);
2280
Sam Revitch62fe78e2006-05-10 15:09:17 +02002281 if (spec->gpio_mute) {
2282 stac922x_gpio_mute(codec, 0, 0);
2283 stac922x_gpio_mute(codec, 1, 0);
2284 }
2285
Mattc7d4b2f2005-06-27 14:59:41 +02002286 return 0;
2287}
2288
Matt2f2f4252005-04-13 14:45:30 +02002289static void stac92xx_free(struct hda_codec *codec)
2290{
Mattc7d4b2f2005-06-27 14:59:41 +02002291 struct sigmatel_spec *spec = codec->spec;
2292 int i;
2293
2294 if (! spec)
2295 return;
2296
2297 if (spec->kctl_alloc) {
2298 for (i = 0; i < spec->num_kctl_used; i++)
2299 kfree(spec->kctl_alloc[i].name);
2300 kfree(spec->kctl_alloc);
2301 }
2302
Richard Fish11b44bb2006-08-23 18:31:34 +02002303 if (spec->bios_pin_configs)
2304 kfree(spec->bios_pin_configs);
2305
Mattc7d4b2f2005-06-27 14:59:41 +02002306 kfree(spec);
Matt2f2f4252005-04-13 14:45:30 +02002307}
2308
Matt4e550962005-07-04 17:51:39 +02002309static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
2310 unsigned int flag)
2311{
2312 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
2313 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Steve Longerbeam7b043892007-05-03 20:50:03 +02002314
Takashi Iwaif9acba42007-05-29 18:01:06 +02002315 if (pin_ctl & AC_PINCTL_IN_EN) {
2316 /*
2317 * we need to check the current set-up direction of
2318 * shared input pins since they can be switched via
2319 * "xxx as Output" mixer switch
2320 */
2321 struct sigmatel_spec *spec = codec->spec;
2322 struct auto_pin_cfg *cfg = &spec->autocfg;
2323 if ((nid == cfg->input_pins[AUTO_PIN_LINE] &&
2324 spec->line_switch) ||
2325 (nid == cfg->input_pins[AUTO_PIN_MIC] &&
2326 spec->mic_switch))
2327 return;
2328 }
2329
Steve Longerbeam7b043892007-05-03 20:50:03 +02002330 /* if setting pin direction bits, clear the current
2331 direction bits first */
2332 if (flag & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))
2333 pin_ctl &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
2334
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002335 snd_hda_codec_write_cache(codec, nid, 0,
Matt4e550962005-07-04 17:51:39 +02002336 AC_VERB_SET_PIN_WIDGET_CONTROL,
2337 pin_ctl | flag);
2338}
2339
2340static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
2341 unsigned int flag)
2342{
2343 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
2344 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002345 snd_hda_codec_write_cache(codec, nid, 0,
Matt4e550962005-07-04 17:51:39 +02002346 AC_VERB_SET_PIN_WIDGET_CONTROL,
2347 pin_ctl & ~flag);
2348}
2349
Takashi Iwai314634b2006-09-21 11:56:18 +02002350static int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
2351{
2352 if (!nid)
2353 return 0;
2354 if (snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PIN_SENSE, 0x00)
2355 & (1 << 31))
2356 return 1;
2357 return 0;
2358}
2359
2360static void stac92xx_hp_detect(struct hda_codec *codec, unsigned int res)
Matt4e550962005-07-04 17:51:39 +02002361{
2362 struct sigmatel_spec *spec = codec->spec;
2363 struct auto_pin_cfg *cfg = &spec->autocfg;
2364 int i, presence;
2365
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002366 presence = 0;
2367 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai314634b2006-09-21 11:56:18 +02002368 presence = get_pin_presence(codec, cfg->hp_pins[i]);
2369 if (presence)
2370 break;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002371 }
Matt4e550962005-07-04 17:51:39 +02002372
2373 if (presence) {
2374 /* disable lineouts, enable hp */
2375 for (i = 0; i < cfg->line_outs; i++)
2376 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
2377 AC_PINCTL_OUT_EN);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002378 for (i = 0; i < cfg->speaker_outs; i++)
2379 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
2380 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02002381 } else {
2382 /* enable lineouts, disable hp */
2383 for (i = 0; i < cfg->line_outs; i++)
2384 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
2385 AC_PINCTL_OUT_EN);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002386 for (i = 0; i < cfg->speaker_outs; i++)
2387 stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
2388 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02002389 }
2390}
2391
Takashi Iwai314634b2006-09-21 11:56:18 +02002392static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
2393{
2394 switch (res >> 26) {
2395 case STAC_HP_EVENT:
2396 stac92xx_hp_detect(codec, res);
2397 break;
2398 }
2399}
2400
Takashi Iwaicb53c622007-08-10 17:21:45 +02002401#ifdef SND_HDA_NEEDS_RESUME
Mattff6fdc32005-06-27 15:06:52 +02002402static int stac92xx_resume(struct hda_codec *codec)
2403{
Takashi Iwaidc81bed2007-09-03 09:36:36 +02002404 struct sigmatel_spec *spec = codec->spec;
2405
Richard Fish11b44bb2006-08-23 18:31:34 +02002406 stac92xx_set_config_regs(codec);
Takashi Iwaidc81bed2007-09-03 09:36:36 +02002407 snd_hda_sequence_write(codec, spec->init);
2408 if (spec->gpio_mute) {
2409 stac922x_gpio_mute(codec, 0, 0);
2410 stac922x_gpio_mute(codec, 1, 0);
2411 }
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002412 snd_hda_codec_resume_amp(codec);
2413 snd_hda_codec_resume_cache(codec);
Takashi Iwaidc81bed2007-09-03 09:36:36 +02002414 /* invoke unsolicited event to reset the HP state */
2415 if (spec->hp_detect)
2416 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
Mattff6fdc32005-06-27 15:06:52 +02002417 return 0;
2418}
2419#endif
2420
Matt2f2f4252005-04-13 14:45:30 +02002421static struct hda_codec_ops stac92xx_patch_ops = {
2422 .build_controls = stac92xx_build_controls,
2423 .build_pcms = stac92xx_build_pcms,
2424 .init = stac92xx_init,
2425 .free = stac92xx_free,
Matt4e550962005-07-04 17:51:39 +02002426 .unsol_event = stac92xx_unsol_event,
Takashi Iwaicb53c622007-08-10 17:21:45 +02002427#ifdef SND_HDA_NEEDS_RESUME
Mattff6fdc32005-06-27 15:06:52 +02002428 .resume = stac92xx_resume,
2429#endif
Matt2f2f4252005-04-13 14:45:30 +02002430};
2431
2432static int patch_stac9200(struct hda_codec *codec)
2433{
2434 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02002435 int err;
Matt2f2f4252005-04-13 14:45:30 +02002436
Takashi Iwaie560d8d2005-09-09 14:21:46 +02002437 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02002438 if (spec == NULL)
2439 return -ENOMEM;
2440
2441 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02002442 spec->num_pins = ARRAY_SIZE(stac9200_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02002443 spec->pin_nids = stac9200_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002444 spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS,
2445 stac9200_models,
2446 stac9200_cfg_tbl);
Richard Fish11b44bb2006-08-23 18:31:34 +02002447 if (spec->board_config < 0) {
2448 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9200, using BIOS defaults\n");
2449 err = stac92xx_save_bios_config_regs(codec);
2450 if (err < 0) {
2451 stac92xx_free(codec);
2452 return err;
2453 }
2454 spec->pin_configs = spec->bios_pin_configs;
2455 } else {
Matt Porter403d1942005-11-29 15:00:51 +01002456 spec->pin_configs = stac9200_brd_tbl[spec->board_config];
2457 stac92xx_set_config_regs(codec);
2458 }
Matt2f2f4252005-04-13 14:45:30 +02002459
2460 spec->multiout.max_channels = 2;
2461 spec->multiout.num_dacs = 1;
2462 spec->multiout.dac_nids = stac9200_dac_nids;
2463 spec->adc_nids = stac9200_adc_nids;
2464 spec->mux_nids = stac9200_mux_nids;
Mattdabbed62005-06-14 10:19:34 +02002465 spec->num_muxes = 1;
Matt Porter8b657272006-10-26 17:12:59 +02002466 spec->num_dmics = 0;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002467 spec->num_adcs = 1;
Mattc7d4b2f2005-06-27 14:59:41 +02002468
Takashi Iwai1194b5b2007-10-10 10:04:26 +02002469 if (spec->board_config == STAC_9200_GATEWAY)
2470 spec->init = stac9200_eapd_init;
2471 else
2472 spec->init = stac9200_core_init;
Matt2f2f4252005-04-13 14:45:30 +02002473 spec->mixer = stac9200_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02002474
2475 err = stac9200_parse_auto_config(codec);
2476 if (err < 0) {
2477 stac92xx_free(codec);
2478 return err;
2479 }
Matt2f2f4252005-04-13 14:45:30 +02002480
2481 codec->patch_ops = stac92xx_patch_ops;
2482
2483 return 0;
2484}
2485
Tobin Davis8e21c342007-01-08 11:04:17 +01002486static int patch_stac925x(struct hda_codec *codec)
2487{
2488 struct sigmatel_spec *spec;
2489 int err;
2490
2491 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2492 if (spec == NULL)
2493 return -ENOMEM;
2494
2495 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02002496 spec->num_pins = ARRAY_SIZE(stac925x_pin_nids);
Tobin Davis8e21c342007-01-08 11:04:17 +01002497 spec->pin_nids = stac925x_pin_nids;
2498 spec->board_config = snd_hda_check_board_config(codec, STAC_925x_MODELS,
2499 stac925x_models,
2500 stac925x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002501 again:
Tobin Davis8e21c342007-01-08 11:04:17 +01002502 if (spec->board_config < 0) {
Tobin Davis2c11f952007-05-17 09:36:34 +02002503 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC925x,"
2504 "using BIOS defaults\n");
Tobin Davis8e21c342007-01-08 11:04:17 +01002505 err = stac92xx_save_bios_config_regs(codec);
2506 if (err < 0) {
2507 stac92xx_free(codec);
2508 return err;
2509 }
2510 spec->pin_configs = spec->bios_pin_configs;
2511 } else if (stac925x_brd_tbl[spec->board_config] != NULL){
2512 spec->pin_configs = stac925x_brd_tbl[spec->board_config];
2513 stac92xx_set_config_regs(codec);
2514 }
2515
2516 spec->multiout.max_channels = 2;
2517 spec->multiout.num_dacs = 1;
2518 spec->multiout.dac_nids = stac925x_dac_nids;
2519 spec->adc_nids = stac925x_adc_nids;
2520 spec->mux_nids = stac925x_mux_nids;
2521 spec->num_muxes = 1;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002522 spec->num_adcs = 1;
Tobin Davis2c11f952007-05-17 09:36:34 +02002523 switch (codec->vendor_id) {
2524 case 0x83847632: /* STAC9202 */
2525 case 0x83847633: /* STAC9202D */
2526 case 0x83847636: /* STAC9251 */
2527 case 0x83847637: /* STAC9251D */
Takashi Iwaif6e98522007-10-16 14:27:04 +02002528 spec->num_dmics = STAC925X_NUM_DMICS;
Tobin Davis2c11f952007-05-17 09:36:34 +02002529 spec->dmic_nids = stac925x_dmic_nids;
2530 break;
2531 default:
2532 spec->num_dmics = 0;
2533 break;
2534 }
Tobin Davis8e21c342007-01-08 11:04:17 +01002535
2536 spec->init = stac925x_core_init;
2537 spec->mixer = stac925x_mixer;
2538
2539 err = stac92xx_parse_auto_config(codec, 0x8, 0x7);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002540 if (!err) {
2541 if (spec->board_config < 0) {
2542 printk(KERN_WARNING "hda_codec: No auto-config is "
2543 "available, default to model=ref\n");
2544 spec->board_config = STAC_925x_REF;
2545 goto again;
2546 }
2547 err = -EINVAL;
2548 }
Tobin Davis8e21c342007-01-08 11:04:17 +01002549 if (err < 0) {
2550 stac92xx_free(codec);
2551 return err;
2552 }
2553
2554 codec->patch_ops = stac92xx_patch_ops;
2555
2556 return 0;
2557}
2558
Matt2f2f4252005-04-13 14:45:30 +02002559static int patch_stac922x(struct hda_codec *codec)
2560{
2561 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02002562 int err;
Matt2f2f4252005-04-13 14:45:30 +02002563
Takashi Iwaie560d8d2005-09-09 14:21:46 +02002564 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02002565 if (spec == NULL)
2566 return -ENOMEM;
2567
2568 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02002569 spec->num_pins = ARRAY_SIZE(stac922x_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02002570 spec->pin_nids = stac922x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002571 spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS,
2572 stac922x_models,
2573 stac922x_cfg_tbl);
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002574 if (spec->board_config == STAC_INTEL_MAC_V3) {
Takashi Iwai3fc24d82007-02-16 13:27:18 +01002575 spec->gpio_mute = 1;
2576 /* Intel Macs have all same PCI SSID, so we need to check
2577 * codec SSID to distinguish the exact models
2578 */
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01002579 printk(KERN_INFO "hda_codec: STAC922x, Apple subsys_id=%x\n", codec->subsystem_id);
Takashi Iwai3fc24d82007-02-16 13:27:18 +01002580 switch (codec->subsystem_id) {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002581
2582 case 0x106b0800:
2583 spec->board_config = STAC_INTEL_MAC_V1;
Abhijit Bhopatkarc45e20e2007-04-17 11:57:16 +02002584 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002585 case 0x106b0600:
2586 case 0x106b0700:
2587 spec->board_config = STAC_INTEL_MAC_V2;
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01002588 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002589 case 0x106b0e00:
2590 case 0x106b0f00:
2591 case 0x106b1600:
2592 case 0x106b1700:
2593 case 0x106b0200:
2594 case 0x106b1e00:
2595 spec->board_config = STAC_INTEL_MAC_V3;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01002596 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002597 case 0x106b1a00:
2598 case 0x00000100:
2599 spec->board_config = STAC_INTEL_MAC_V4;
Sylvain FORETf16928f2007-04-27 14:22:36 +02002600 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002601 case 0x106b0a00:
2602 case 0x106b2200:
2603 spec->board_config = STAC_INTEL_MAC_V5;
Takashi Iwai0dae0f82007-05-21 12:41:29 +02002604 break;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01002605 }
2606 }
2607
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002608 again:
Richard Fish11b44bb2006-08-23 18:31:34 +02002609 if (spec->board_config < 0) {
2610 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC922x, "
2611 "using BIOS defaults\n");
2612 err = stac92xx_save_bios_config_regs(codec);
2613 if (err < 0) {
2614 stac92xx_free(codec);
2615 return err;
2616 }
2617 spec->pin_configs = spec->bios_pin_configs;
2618 } else if (stac922x_brd_tbl[spec->board_config] != NULL) {
Matt Porter403d1942005-11-29 15:00:51 +01002619 spec->pin_configs = stac922x_brd_tbl[spec->board_config];
2620 stac92xx_set_config_regs(codec);
2621 }
Matt2f2f4252005-04-13 14:45:30 +02002622
Matt2f2f4252005-04-13 14:45:30 +02002623 spec->adc_nids = stac922x_adc_nids;
2624 spec->mux_nids = stac922x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01002625 spec->num_muxes = ARRAY_SIZE(stac922x_mux_nids);
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002626 spec->num_adcs = ARRAY_SIZE(stac922x_adc_nids);
Matt Porter8b657272006-10-26 17:12:59 +02002627 spec->num_dmics = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02002628
2629 spec->init = stac922x_core_init;
Matt2f2f4252005-04-13 14:45:30 +02002630 spec->mixer = stac922x_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02002631
2632 spec->multiout.dac_nids = spec->dac_nids;
Takashi Iwai19039bd2006-06-28 15:52:16 +02002633
Matt Porter3cc08dc2006-01-23 15:27:49 +01002634 err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002635 if (!err) {
2636 if (spec->board_config < 0) {
2637 printk(KERN_WARNING "hda_codec: No auto-config is "
2638 "available, default to model=ref\n");
2639 spec->board_config = STAC_D945_REF;
2640 goto again;
2641 }
2642 err = -EINVAL;
2643 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01002644 if (err < 0) {
2645 stac92xx_free(codec);
2646 return err;
2647 }
2648
2649 codec->patch_ops = stac92xx_patch_ops;
2650
Takashi Iwai807a46362007-05-29 19:01:37 +02002651 /* Fix Mux capture level; max to 2 */
2652 snd_hda_override_amp_caps(codec, 0x12, HDA_OUTPUT,
2653 (0 << AC_AMPCAP_OFFSET_SHIFT) |
2654 (2 << AC_AMPCAP_NUM_STEPS_SHIFT) |
2655 (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
2656 (0 << AC_AMPCAP_MUTE_SHIFT));
2657
Matt Porter3cc08dc2006-01-23 15:27:49 +01002658 return 0;
2659}
2660
2661static int patch_stac927x(struct hda_codec *codec)
2662{
2663 struct sigmatel_spec *spec;
2664 int err;
2665
2666 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2667 if (spec == NULL)
2668 return -ENOMEM;
2669
2670 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02002671 spec->num_pins = ARRAY_SIZE(stac927x_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02002672 spec->pin_nids = stac927x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002673 spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS,
2674 stac927x_models,
2675 stac927x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002676 again:
Richard Fish11b44bb2006-08-23 18:31:34 +02002677 if (spec->board_config < 0) {
Matt Porter3cc08dc2006-01-23 15:27:49 +01002678 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC927x, using BIOS defaults\n");
Richard Fish11b44bb2006-08-23 18:31:34 +02002679 err = stac92xx_save_bios_config_regs(codec);
2680 if (err < 0) {
2681 stac92xx_free(codec);
2682 return err;
2683 }
2684 spec->pin_configs = spec->bios_pin_configs;
2685 } else if (stac927x_brd_tbl[spec->board_config] != NULL) {
Matt Porter3cc08dc2006-01-23 15:27:49 +01002686 spec->pin_configs = stac927x_brd_tbl[spec->board_config];
2687 stac92xx_set_config_regs(codec);
2688 }
2689
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002690 switch (spec->board_config) {
Tobin Davis93ed1502006-09-01 21:03:12 +02002691 case STAC_D965_3ST:
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002692 spec->adc_nids = stac927x_adc_nids;
2693 spec->mux_nids = stac927x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01002694 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002695 spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
Tobin Davis93ed1502006-09-01 21:03:12 +02002696 spec->init = d965_core_init;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002697 spec->mixer = stac927x_mixer;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002698 break;
Tobin Davis93ed1502006-09-01 21:03:12 +02002699 case STAC_D965_5ST:
2700 spec->adc_nids = stac927x_adc_nids;
2701 spec->mux_nids = stac927x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01002702 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002703 spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
Tobin Davis93ed1502006-09-01 21:03:12 +02002704 spec->init = d965_core_init;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002705 spec->mixer = stac927x_mixer;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002706 break;
2707 default:
2708 spec->adc_nids = stac927x_adc_nids;
2709 spec->mux_nids = stac927x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01002710 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002711 spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002712 spec->init = stac927x_core_init;
2713 spec->mixer = stac927x_mixer;
2714 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01002715
Matthew Ranostay7f168592007-10-18 17:38:17 +02002716 switch (codec->subsystem_id) {
2717 case 0x1028020A: /* STAC 9228 */
2718 case 0x10280209: /* STAC 9228 */
2719 spec->dmic_nids = stac927x_dmic_nids;
2720 spec->num_dmics = STAC927X_NUM_DMICS;
2721 break;
2722 default:
2723 spec->num_dmics = 0;
2724 }
2725
Matt Porter3cc08dc2006-01-23 15:27:49 +01002726 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostay87d48362007-07-17 11:52:24 +02002727 /* GPIO0 High = Enable EAPD */
Takashi Iwai82599802007-07-31 15:56:24 +02002728 spec->gpio_mask = spec->gpio_data = 0x00000001;
2729 stac92xx_enable_gpio_mask(codec);
Matthew Ranostay92a22be2007-06-19 16:48:28 +02002730
Matt Porter3cc08dc2006-01-23 15:27:49 +01002731 err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002732 if (!err) {
2733 if (spec->board_config < 0) {
2734 printk(KERN_WARNING "hda_codec: No auto-config is "
2735 "available, default to model=ref\n");
2736 spec->board_config = STAC_D965_REF;
2737 goto again;
2738 }
2739 err = -EINVAL;
2740 }
Mattc7d4b2f2005-06-27 14:59:41 +02002741 if (err < 0) {
2742 stac92xx_free(codec);
2743 return err;
2744 }
Matt2f2f4252005-04-13 14:45:30 +02002745
2746 codec->patch_ops = stac92xx_patch_ops;
2747
2748 return 0;
2749}
2750
Matt Porterf3302a52006-07-31 12:49:34 +02002751static int patch_stac9205(struct hda_codec *codec)
2752{
2753 struct sigmatel_spec *spec;
Takashi Iwai82599802007-07-31 15:56:24 +02002754 int err;
Matt Porterf3302a52006-07-31 12:49:34 +02002755
2756 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2757 if (spec == NULL)
2758 return -ENOMEM;
2759
2760 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02002761 spec->num_pins = ARRAY_SIZE(stac9205_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02002762 spec->pin_nids = stac9205_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002763 spec->board_config = snd_hda_check_board_config(codec, STAC_9205_MODELS,
2764 stac9205_models,
2765 stac9205_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002766 again:
Richard Fish11b44bb2006-08-23 18:31:34 +02002767 if (spec->board_config < 0) {
2768 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9205, using BIOS defaults\n");
2769 err = stac92xx_save_bios_config_regs(codec);
2770 if (err < 0) {
2771 stac92xx_free(codec);
2772 return err;
2773 }
2774 spec->pin_configs = spec->bios_pin_configs;
2775 } else {
Matt Porterf3302a52006-07-31 12:49:34 +02002776 spec->pin_configs = stac9205_brd_tbl[spec->board_config];
2777 stac92xx_set_config_regs(codec);
2778 }
2779
2780 spec->adc_nids = stac9205_adc_nids;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002781 spec->num_adcs = ARRAY_SIZE(stac9205_adc_nids);
Matt Porterf3302a52006-07-31 12:49:34 +02002782 spec->mux_nids = stac9205_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01002783 spec->num_muxes = ARRAY_SIZE(stac9205_mux_nids);
Matt Porter8b657272006-10-26 17:12:59 +02002784 spec->dmic_nids = stac9205_dmic_nids;
Takashi Iwaif6e98522007-10-16 14:27:04 +02002785 spec->num_dmics = STAC9205_NUM_DMICS;
Matt Porter8b657272006-10-26 17:12:59 +02002786 spec->dmux_nid = 0x1d;
Matt Porterf3302a52006-07-31 12:49:34 +02002787
2788 spec->init = stac9205_core_init;
2789 spec->mixer = stac9205_mixer;
2790
2791 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostay87d48362007-07-17 11:52:24 +02002792
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002793 switch (spec->board_config){
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002794 case STAC_9205_DELL_M43:
Matthew Ranostay87d48362007-07-17 11:52:24 +02002795 /* Enable SPDIF in/out */
2796 stac92xx_set_config_reg(codec, 0x1f, 0x01441030);
2797 stac92xx_set_config_reg(codec, 0x20, 0x1c410030);
Matt Porter33382402006-12-18 13:17:28 +01002798
Takashi Iwai82599802007-07-31 15:56:24 +02002799 spec->gpio_mask = 0x00000007; /* GPIO0-2 */
Matthew Ranostay87d48362007-07-17 11:52:24 +02002800 /* GPIO0 High = EAPD, GPIO1 Low = DRM,
2801 * GPIO2 High = Headphone Mute
2802 */
Takashi Iwai82599802007-07-31 15:56:24 +02002803 spec->gpio_data = 0x00000005;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002804 break;
2805 default:
2806 /* GPIO0 High = EAPD */
2807 spec->gpio_mask = spec->gpio_data = 0x00000001;
2808 break;
2809 }
Matthew Ranostay87d48362007-07-17 11:52:24 +02002810
Takashi Iwai82599802007-07-31 15:56:24 +02002811 stac92xx_enable_gpio_mask(codec);
Matt Porterf3302a52006-07-31 12:49:34 +02002812 err = stac92xx_parse_auto_config(codec, 0x1f, 0x20);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002813 if (!err) {
2814 if (spec->board_config < 0) {
2815 printk(KERN_WARNING "hda_codec: No auto-config is "
2816 "available, default to model=ref\n");
2817 spec->board_config = STAC_9205_REF;
2818 goto again;
2819 }
2820 err = -EINVAL;
2821 }
Matt Porterf3302a52006-07-31 12:49:34 +02002822 if (err < 0) {
2823 stac92xx_free(codec);
2824 return err;
2825 }
2826
2827 codec->patch_ops = stac92xx_patch_ops;
2828
2829 return 0;
2830}
2831
Matt2f2f4252005-04-13 14:45:30 +02002832/*
Guillaume Munch6d859062006-08-22 17:15:47 +02002833 * STAC9872 hack
Takashi Iwaidb064e52006-03-16 16:04:58 +01002834 */
2835
Guillaume Munch99ccc562006-08-16 19:35:12 +02002836/* static config for Sony VAIO FE550G and Sony VAIO AR */
Takashi Iwaidb064e52006-03-16 16:04:58 +01002837static hda_nid_t vaio_dacs[] = { 0x2 };
2838#define VAIO_HP_DAC 0x5
2839static hda_nid_t vaio_adcs[] = { 0x8 /*,0x6*/ };
2840static hda_nid_t vaio_mux_nids[] = { 0x15 };
2841
2842static struct hda_input_mux vaio_mux = {
Takashi Iwaia3a2f422007-10-11 11:21:21 +02002843 .num_items = 3,
Takashi Iwaidb064e52006-03-16 16:04:58 +01002844 .items = {
Takashi Iwaid7737812006-04-25 13:05:43 +02002845 /* { "HP", 0x0 }, */
Takashi Iwai1624cb92007-07-05 13:10:51 +02002846 { "Mic Jack", 0x1 },
2847 { "Internal Mic", 0x2 },
Takashi Iwaidb064e52006-03-16 16:04:58 +01002848 { "PCM", 0x3 },
2849 }
2850};
2851
2852static struct hda_verb vaio_init[] = {
2853 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
Takashi Iwai72e7b0d2007-08-16 17:33:55 +02002854 {0x0a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | STAC_HP_EVENT},
Takashi Iwaidb064e52006-03-16 16:04:58 +01002855 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
2856 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
2857 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
2858 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
Takashi Iwai1624cb92007-07-05 13:10:51 +02002859 {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
Takashi Iwaidb064e52006-03-16 16:04:58 +01002860 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
2861 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
2862 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
2863 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
2864 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
2865 {}
2866};
2867
Guillaume Munch6d859062006-08-22 17:15:47 +02002868static struct hda_verb vaio_ar_init[] = {
2869 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
2870 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
2871 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
2872 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
2873/* {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },*/ /* Optical Out */
2874 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
Takashi Iwai1624cb92007-07-05 13:10:51 +02002875 {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
Guillaume Munch6d859062006-08-22 17:15:47 +02002876 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
2877 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
2878/* {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},*/ /* Optical Out */
2879 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
2880 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
2881 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
2882 {}
2883};
2884
Takashi Iwaidb064e52006-03-16 16:04:58 +01002885/* bind volumes of both NID 0x02 and 0x05 */
Takashi Iwaicca3b372007-08-10 17:12:15 +02002886static struct hda_bind_ctls vaio_bind_master_vol = {
2887 .ops = &snd_hda_bind_vol,
2888 .values = {
2889 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2890 HDA_COMPOSE_AMP_VAL(0x05, 3, 0, HDA_OUTPUT),
2891 0
2892 },
2893};
Takashi Iwaidb064e52006-03-16 16:04:58 +01002894
2895/* bind volumes of both NID 0x02 and 0x05 */
Takashi Iwaicca3b372007-08-10 17:12:15 +02002896static struct hda_bind_ctls vaio_bind_master_sw = {
2897 .ops = &snd_hda_bind_sw,
2898 .values = {
2899 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2900 HDA_COMPOSE_AMP_VAL(0x05, 3, 0, HDA_OUTPUT),
2901 0,
2902 },
2903};
Takashi Iwaidb064e52006-03-16 16:04:58 +01002904
2905static struct snd_kcontrol_new vaio_mixer[] = {
Takashi Iwaicca3b372007-08-10 17:12:15 +02002906 HDA_BIND_VOL("Master Playback Volume", &vaio_bind_master_vol),
2907 HDA_BIND_SW("Master Playback Switch", &vaio_bind_master_sw),
Takashi Iwaidb064e52006-03-16 16:04:58 +01002908 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
2909 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
2910 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
2911 {
2912 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2913 .name = "Capture Source",
2914 .count = 1,
2915 .info = stac92xx_mux_enum_info,
2916 .get = stac92xx_mux_enum_get,
2917 .put = stac92xx_mux_enum_put,
2918 },
2919 {}
2920};
2921
Guillaume Munch6d859062006-08-22 17:15:47 +02002922static struct snd_kcontrol_new vaio_ar_mixer[] = {
Takashi Iwaicca3b372007-08-10 17:12:15 +02002923 HDA_BIND_VOL("Master Playback Volume", &vaio_bind_master_vol),
2924 HDA_BIND_SW("Master Playback Switch", &vaio_bind_master_sw),
Guillaume Munch6d859062006-08-22 17:15:47 +02002925 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
2926 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
2927 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
2928 /*HDA_CODEC_MUTE("Optical Out Switch", 0x10, 0, HDA_OUTPUT),
2929 HDA_CODEC_VOLUME("Optical Out Volume", 0x10, 0, HDA_OUTPUT),*/
2930 {
2931 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2932 .name = "Capture Source",
2933 .count = 1,
2934 .info = stac92xx_mux_enum_info,
2935 .get = stac92xx_mux_enum_get,
2936 .put = stac92xx_mux_enum_put,
2937 },
2938 {}
2939};
2940
2941static struct hda_codec_ops stac9872_patch_ops = {
Takashi Iwaidb064e52006-03-16 16:04:58 +01002942 .build_controls = stac92xx_build_controls,
2943 .build_pcms = stac92xx_build_pcms,
2944 .init = stac92xx_init,
2945 .free = stac92xx_free,
Takashi Iwaicb53c622007-08-10 17:21:45 +02002946#ifdef SND_HDA_NEEDS_RESUME
Takashi Iwaidb064e52006-03-16 16:04:58 +01002947 .resume = stac92xx_resume,
2948#endif
2949};
2950
Takashi Iwai72e7b0d2007-08-16 17:33:55 +02002951static int stac9872_vaio_init(struct hda_codec *codec)
2952{
2953 int err;
2954
2955 err = stac92xx_init(codec);
2956 if (err < 0)
2957 return err;
2958 if (codec->patch_ops.unsol_event)
2959 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
2960 return 0;
2961}
2962
2963static void stac9872_vaio_hp_detect(struct hda_codec *codec, unsigned int res)
2964{
2965 if (get_pin_presence(codec, 0x0a)) {
2966 stac92xx_reset_pinctl(codec, 0x0f, AC_PINCTL_OUT_EN);
2967 stac92xx_set_pinctl(codec, 0x0a, AC_PINCTL_OUT_EN);
2968 } else {
2969 stac92xx_reset_pinctl(codec, 0x0a, AC_PINCTL_OUT_EN);
2970 stac92xx_set_pinctl(codec, 0x0f, AC_PINCTL_OUT_EN);
2971 }
2972}
2973
2974static void stac9872_vaio_unsol_event(struct hda_codec *codec, unsigned int res)
2975{
2976 switch (res >> 26) {
2977 case STAC_HP_EVENT:
2978 stac9872_vaio_hp_detect(codec, res);
2979 break;
2980 }
2981}
2982
2983static struct hda_codec_ops stac9872_vaio_patch_ops = {
2984 .build_controls = stac92xx_build_controls,
2985 .build_pcms = stac92xx_build_pcms,
2986 .init = stac9872_vaio_init,
2987 .free = stac92xx_free,
2988 .unsol_event = stac9872_vaio_unsol_event,
2989#ifdef CONFIG_PM
2990 .resume = stac92xx_resume,
2991#endif
2992};
2993
Guillaume Munch6d859062006-08-22 17:15:47 +02002994enum { /* FE and SZ series. id=0x83847661 and subsys=0x104D0700 or 104D1000. */
2995 CXD9872RD_VAIO,
2996 /* Unknown. id=0x83847662 and subsys=0x104D1200 or 104D1000. */
2997 STAC9872AK_VAIO,
2998 /* Unknown. id=0x83847661 and subsys=0x104D1200. */
2999 STAC9872K_VAIO,
3000 /* AR Series. id=0x83847664 and subsys=104D1300 */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01003001 CXD9872AKD_VAIO,
3002 STAC_9872_MODELS,
3003};
Takashi Iwaidb064e52006-03-16 16:04:58 +01003004
Takashi Iwaif5fcc132006-11-24 17:07:44 +01003005static const char *stac9872_models[STAC_9872_MODELS] = {
3006 [CXD9872RD_VAIO] = "vaio",
3007 [CXD9872AKD_VAIO] = "vaio-ar",
3008};
3009
3010static struct snd_pci_quirk stac9872_cfg_tbl[] = {
3011 SND_PCI_QUIRK(0x104d, 0x81e6, "Sony VAIO F/S", CXD9872RD_VAIO),
3012 SND_PCI_QUIRK(0x104d, 0x81ef, "Sony VAIO F/S", CXD9872RD_VAIO),
3013 SND_PCI_QUIRK(0x104d, 0x81fd, "Sony VAIO AR", CXD9872AKD_VAIO),
Tobin Davis68e22542007-03-12 11:36:39 +01003014 SND_PCI_QUIRK(0x104d, 0x8205, "Sony VAIO AR", CXD9872AKD_VAIO),
Takashi Iwaidb064e52006-03-16 16:04:58 +01003015 {}
3016};
3017
Guillaume Munch6d859062006-08-22 17:15:47 +02003018static int patch_stac9872(struct hda_codec *codec)
Takashi Iwaidb064e52006-03-16 16:04:58 +01003019{
3020 struct sigmatel_spec *spec;
3021 int board_config;
3022
Takashi Iwaif5fcc132006-11-24 17:07:44 +01003023 board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
3024 stac9872_models,
3025 stac9872_cfg_tbl);
Takashi Iwaidb064e52006-03-16 16:04:58 +01003026 if (board_config < 0)
3027 /* unknown config, let generic-parser do its job... */
3028 return snd_hda_parse_generic_codec(codec);
3029
3030 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3031 if (spec == NULL)
3032 return -ENOMEM;
3033
3034 codec->spec = spec;
3035 switch (board_config) {
Guillaume Munch6d859062006-08-22 17:15:47 +02003036 case CXD9872RD_VAIO:
3037 case STAC9872AK_VAIO:
3038 case STAC9872K_VAIO:
Takashi Iwaidb064e52006-03-16 16:04:58 +01003039 spec->mixer = vaio_mixer;
3040 spec->init = vaio_init;
3041 spec->multiout.max_channels = 2;
3042 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
3043 spec->multiout.dac_nids = vaio_dacs;
3044 spec->multiout.hp_nid = VAIO_HP_DAC;
3045 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
3046 spec->adc_nids = vaio_adcs;
3047 spec->input_mux = &vaio_mux;
3048 spec->mux_nids = vaio_mux_nids;
Takashi Iwai72e7b0d2007-08-16 17:33:55 +02003049 codec->patch_ops = stac9872_vaio_patch_ops;
Takashi Iwaidb064e52006-03-16 16:04:58 +01003050 break;
Guillaume Munch6d859062006-08-22 17:15:47 +02003051
3052 case CXD9872AKD_VAIO:
3053 spec->mixer = vaio_ar_mixer;
3054 spec->init = vaio_ar_init;
3055 spec->multiout.max_channels = 2;
3056 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
3057 spec->multiout.dac_nids = vaio_dacs;
3058 spec->multiout.hp_nid = VAIO_HP_DAC;
3059 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
3060 spec->adc_nids = vaio_adcs;
3061 spec->input_mux = &vaio_mux;
3062 spec->mux_nids = vaio_mux_nids;
Takashi Iwai72e7b0d2007-08-16 17:33:55 +02003063 codec->patch_ops = stac9872_patch_ops;
Guillaume Munch6d859062006-08-22 17:15:47 +02003064 break;
Takashi Iwaidb064e52006-03-16 16:04:58 +01003065 }
3066
Takashi Iwaidb064e52006-03-16 16:04:58 +01003067 return 0;
3068}
3069
3070
3071/*
Matt2f2f4252005-04-13 14:45:30 +02003072 * patch entries
3073 */
3074struct hda_codec_preset snd_hda_preset_sigmatel[] = {
3075 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
3076 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
3077 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
3078 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
3079 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
3080 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
3081 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
Matt Porter22a27c72006-07-06 18:49:10 +02003082 { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
3083 { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
3084 { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
3085 { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
3086 { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
3087 { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
Matt Porter3cc08dc2006-01-23 15:27:49 +01003088 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
3089 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
3090 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
3091 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
3092 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
3093 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
3094 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
3095 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
3096 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
3097 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
Tobin Davis8e21c342007-01-08 11:04:17 +01003098 { .id = 0x83847632, .name = "STAC9202", .patch = patch_stac925x },
3099 { .id = 0x83847633, .name = "STAC9202D", .patch = patch_stac925x },
3100 { .id = 0x83847634, .name = "STAC9250", .patch = patch_stac925x },
3101 { .id = 0x83847635, .name = "STAC9250D", .patch = patch_stac925x },
3102 { .id = 0x83847636, .name = "STAC9251", .patch = patch_stac925x },
3103 { .id = 0x83847637, .name = "STAC9250D", .patch = patch_stac925x },
Guillaume Munch6d859062006-08-22 17:15:47 +02003104 /* The following does not take into account .id=0x83847661 when subsys =
3105 * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
3106 * currently not fully supported.
3107 */
3108 { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
3109 { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
3110 { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
Matt Porterf3302a52006-07-31 12:49:34 +02003111 { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
3112 { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
3113 { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
3114 { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
3115 { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
3116 { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
3117 { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
3118 { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
Matt2f2f4252005-04-13 14:45:30 +02003119 {} /* terminator */
3120};