blob: 876e1d493239968dbae1b7e76e735d75ecd1e392 [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
Matthew Ranostay47744f62007-10-19 08:19:56 +0200396#define STAC_DIGITAL_INPUT_SOURCE(cnt) \
397 { \
398 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
399 .name = "Digital Input Source", \
400 .count = cnt, \
401 .info = stac92xx_dmux_enum_info, \
402 .get = stac92xx_dmux_enum_get, \
403 .put = stac92xx_dmux_enum_put,\
404 }
405
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200406#define STAC_INPUT_SOURCE(cnt) \
Maxim Levitskyca7c5a82007-08-31 12:52:19 +0200407 { \
408 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
409 .name = "Input Source", \
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200410 .count = cnt, \
Maxim Levitskyca7c5a82007-08-31 12:52:19 +0200411 .info = stac92xx_mux_enum_info, \
412 .get = stac92xx_mux_enum_get, \
413 .put = stac92xx_mux_enum_put, \
414 }
415
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200416#define STAC_ANALOG_LOOPBACK(verb_read,verb_write) \
417 { \
418 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
419 .name = "Analog Loopback", \
420 .count = 1, \
421 .info = stac92xx_aloopback_info, \
422 .get = stac92xx_aloopback_get, \
423 .put = stac92xx_aloopback_put, \
424 .private_value = verb_read | (verb_write << 16), \
425 }
426
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100427static struct snd_kcontrol_new stac9200_mixer[] = {
Matt2f2f4252005-04-13 14:45:30 +0200428 HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
429 HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200430 STAC_INPUT_SOURCE(1),
Matt2f2f4252005-04-13 14:45:30 +0200431 HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
432 HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
Mattc7d4b2f2005-06-27 14:59:41 +0200433 HDA_CODEC_VOLUME("Capture Mux Volume", 0x0c, 0, HDA_OUTPUT),
Matt2f2f4252005-04-13 14:45:30 +0200434 { } /* end */
435};
436
Tobin Davis8e21c342007-01-08 11:04:17 +0100437static struct snd_kcontrol_new stac925x_mixer[] = {
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200438 STAC_INPUT_SOURCE(1),
Tobin Davis8e21c342007-01-08 11:04:17 +0100439 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_OUTPUT),
440 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_OUTPUT),
441 HDA_CODEC_VOLUME("Capture Mux Volume", 0x0f, 0, HDA_OUTPUT),
442 { } /* end */
443};
444
Takashi Iwaid1d985f2006-11-23 19:27:12 +0100445static struct snd_kcontrol_new stac9205_mixer[] = {
Matthew Ranostay47744f62007-10-19 08:19:56 +0200446 STAC_DIGITAL_INPUT_SOURCE(1),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200447 STAC_INPUT_SOURCE(2),
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200448 STAC_ANALOG_LOOPBACK(0xFE0, 0x7E0),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200449
450 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1b, 0x0, HDA_INPUT),
451 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1d, 0x0, HDA_OUTPUT),
452 HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x0, 0x19, 0x0, HDA_OUTPUT),
453
454 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x1c, 0x0, HDA_INPUT),
455 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1e, 0x0, HDA_OUTPUT),
456 HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x1, 0x1A, 0x0, HDA_OUTPUT),
457
458 { } /* end */
459};
460
461/* This needs to be generated dynamically based on sequence */
462static struct snd_kcontrol_new stac922x_mixer[] = {
463 STAC_INPUT_SOURCE(2),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200464 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x17, 0x0, HDA_INPUT),
465 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x17, 0x0, HDA_INPUT),
466 HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x0, 0x12, 0x0, HDA_OUTPUT),
467
468 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x18, 0x0, HDA_INPUT),
469 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x18, 0x0, HDA_INPUT),
470 HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x1, 0x13, 0x0, HDA_OUTPUT),
471 { } /* end */
472};
473
474
475static struct snd_kcontrol_new stac927x_mixer[] = {
Matthew Ranostay47744f62007-10-19 08:19:56 +0200476 STAC_DIGITAL_INPUT_SOURCE(1),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200477 STAC_INPUT_SOURCE(3),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200478 STAC_ANALOG_LOOPBACK(0xFEB, 0x7EB),
479
480 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x18, 0x0, HDA_INPUT),
481 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1b, 0x0, HDA_OUTPUT),
482 HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x0, 0x15, 0x0, HDA_OUTPUT),
483
484 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x19, 0x0, HDA_INPUT),
485 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1c, 0x0, HDA_OUTPUT),
486 HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x1, 0x16, 0x0, HDA_OUTPUT),
487
488 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x2, 0x1A, 0x0, HDA_INPUT),
489 HDA_CODEC_MUTE_IDX("Capture Switch", 0x2, 0x1d, 0x0, HDA_OUTPUT),
490 HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x2, 0x17, 0x0, HDA_OUTPUT),
Matt Porterf3302a52006-07-31 12:49:34 +0200491 { } /* end */
492};
493
Matt2f2f4252005-04-13 14:45:30 +0200494static int stac92xx_build_controls(struct hda_codec *codec)
495{
496 struct sigmatel_spec *spec = codec->spec;
497 int err;
Mattc7d4b2f2005-06-27 14:59:41 +0200498 int i;
Matt2f2f4252005-04-13 14:45:30 +0200499
500 err = snd_hda_add_new_ctls(codec, spec->mixer);
501 if (err < 0)
502 return err;
Mattc7d4b2f2005-06-27 14:59:41 +0200503
504 for (i = 0; i < spec->num_mixers; i++) {
505 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
506 if (err < 0)
507 return err;
508 }
509
Mattdabbed62005-06-14 10:19:34 +0200510 if (spec->multiout.dig_out_nid) {
511 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
512 if (err < 0)
513 return err;
514 }
515 if (spec->dig_in_nid) {
516 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
517 if (err < 0)
518 return err;
519 }
520 return 0;
Matt2f2f4252005-04-13 14:45:30 +0200521}
522
Matt Porter403d1942005-11-29 15:00:51 +0100523static unsigned int ref9200_pin_configs[8] = {
Mattdabbed62005-06-14 10:19:34 +0200524 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
Matt2f2f4252005-04-13 14:45:30 +0200525 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
526};
527
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200528/*
529 STAC 9200 pin configs for
530 102801A8
531 102801DE
532 102801E8
533*/
534static unsigned int dell9200_d21_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +0200535 0x400001f0, 0x400001f1, 0x02214030, 0x01014010,
536 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200537};
538
539/*
540 STAC 9200 pin configs for
541 102801C0
542 102801C1
543*/
544static unsigned int dell9200_d22_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +0200545 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
546 0x01813020, 0x02a19021, 0x90100140, 0x400001f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200547};
548
549/*
550 STAC 9200 pin configs for
551 102801C4 (Dell Dimension E310)
552 102801C5
553 102801C7
554 102801D9
555 102801DA
556 102801E3
557*/
558static unsigned int dell9200_d23_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +0200559 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
560 0x01813020, 0x01a19021, 0x90100140, 0x400001f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200561};
562
563
564/*
565 STAC 9200-32 pin configs for
566 102801B5 (Dell Inspiron 630m)
567 102801D8 (Dell Inspiron 640m)
568*/
569static unsigned int dell9200_m21_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +0200570 0x40c003fa, 0x03441340, 0x0321121f, 0x90170310,
571 0x408003fb, 0x03a11020, 0x401003fc, 0x403003fd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200572};
573
574/*
575 STAC 9200-32 pin configs for
576 102801C2 (Dell Latitude D620)
577 102801C8
578 102801CC (Dell Latitude D820)
579 102801D4
580 102801D6
581*/
582static unsigned int dell9200_m22_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +0200583 0x40c003fa, 0x0144131f, 0x0321121f, 0x90170310,
584 0x90a70321, 0x03a11020, 0x401003fb, 0x40f000fc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200585};
586
587/*
588 STAC 9200-32 pin configs for
589 102801CE (Dell XPS M1710)
590 102801CF (Dell Precision M90)
591*/
592static unsigned int dell9200_m23_pin_configs[8] = {
593 0x40c003fa, 0x01441340, 0x0421421f, 0x90170310,
594 0x408003fb, 0x04a1102e, 0x90170311, 0x403003fc,
595};
596
597/*
598 STAC 9200-32 pin configs for
599 102801C9
600 102801CA
601 102801CB (Dell Latitude 120L)
602 102801D3
603*/
604static unsigned int dell9200_m24_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +0200605 0x40c003fa, 0x404003fb, 0x0321121f, 0x90170310,
606 0x408003fc, 0x03a11020, 0x401003fd, 0x403003fe,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200607};
608
609/*
610 STAC 9200-32 pin configs for
611 102801BD (Dell Inspiron E1505n)
612 102801EE
613 102801EF
614*/
615static unsigned int dell9200_m25_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +0200616 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
617 0x408003fb, 0x04a11020, 0x401003fc, 0x403003fd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200618};
619
620/*
621 STAC 9200-32 pin configs for
622 102801F5 (Dell Inspiron 1501)
623 102801F6
624*/
625static unsigned int dell9200_m26_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +0200626 0x40c003fa, 0x404003fb, 0x0421121f, 0x90170310,
627 0x408003fc, 0x04a11020, 0x401003fd, 0x403003fe,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200628};
629
630/*
631 STAC 9200-32
632 102801CD (Dell Inspiron E1705/9400)
633*/
634static unsigned int dell9200_m27_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +0200635 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
636 0x90170310, 0x04a11020, 0x90170310, 0x40f003fc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200637};
638
639
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100640static unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
641 [STAC_REF] = ref9200_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200642 [STAC_9200_DELL_D21] = dell9200_d21_pin_configs,
643 [STAC_9200_DELL_D22] = dell9200_d22_pin_configs,
644 [STAC_9200_DELL_D23] = dell9200_d23_pin_configs,
645 [STAC_9200_DELL_M21] = dell9200_m21_pin_configs,
646 [STAC_9200_DELL_M22] = dell9200_m22_pin_configs,
647 [STAC_9200_DELL_M23] = dell9200_m23_pin_configs,
648 [STAC_9200_DELL_M24] = dell9200_m24_pin_configs,
649 [STAC_9200_DELL_M25] = dell9200_m25_pin_configs,
650 [STAC_9200_DELL_M26] = dell9200_m26_pin_configs,
651 [STAC_9200_DELL_M27] = dell9200_m27_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +0100652};
653
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100654static const char *stac9200_models[STAC_9200_MODELS] = {
655 [STAC_REF] = "ref",
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200656 [STAC_9200_DELL_D21] = "dell-d21",
657 [STAC_9200_DELL_D22] = "dell-d22",
658 [STAC_9200_DELL_D23] = "dell-d23",
659 [STAC_9200_DELL_M21] = "dell-m21",
660 [STAC_9200_DELL_M22] = "dell-m22",
661 [STAC_9200_DELL_M23] = "dell-m23",
662 [STAC_9200_DELL_M24] = "dell-m24",
663 [STAC_9200_DELL_M25] = "dell-m25",
664 [STAC_9200_DELL_M26] = "dell-m26",
665 [STAC_9200_DELL_M27] = "dell-m27",
Takashi Iwai1194b5b2007-10-10 10:04:26 +0200666 [STAC_9200_GATEWAY] = "gateway",
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100667};
668
669static struct snd_pci_quirk stac9200_cfg_tbl[] = {
670 /* SigmaTel reference board */
671 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
672 "DFI LanParty", STAC_REF),
Matt Portere7377072006-11-06 11:20:38 +0100673 /* Dell laptops have BIOS problem */
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200674 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a8,
675 "unknown Dell", STAC_9200_DELL_D21),
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100676 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01b5,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200677 "Dell Inspiron 630m", STAC_9200_DELL_M21),
678 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bd,
679 "Dell Inspiron E1505n", STAC_9200_DELL_M25),
680 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c0,
681 "unknown Dell", STAC_9200_DELL_D22),
682 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c1,
683 "unknown Dell", STAC_9200_DELL_D22),
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100684 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200685 "Dell Latitude D620", STAC_9200_DELL_M22),
686 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c5,
687 "unknown Dell", STAC_9200_DELL_D23),
688 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c7,
689 "unknown Dell", STAC_9200_DELL_D23),
690 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c8,
691 "unknown Dell", STAC_9200_DELL_M22),
692 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c9,
693 "unknown Dell", STAC_9200_DELL_M24),
694 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ca,
695 "unknown Dell", STAC_9200_DELL_M24),
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100696 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cb,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200697 "Dell Latitude 120L", STAC_9200_DELL_M24),
Cory T. Tusar877b8662007-01-30 17:30:55 +0100698 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200699 "Dell Latitude D820", STAC_9200_DELL_M22),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +0100700 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200701 "Dell Inspiron E1705/9400", STAC_9200_DELL_M27),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +0100702 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ce,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200703 "Dell XPS M1710", STAC_9200_DELL_M23),
Takashi Iwaif0f96742007-02-14 00:59:17 +0100704 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cf,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200705 "Dell Precision M90", STAC_9200_DELL_M23),
706 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d3,
707 "unknown Dell", STAC_9200_DELL_M22),
708 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d4,
709 "unknown Dell", STAC_9200_DELL_M22),
Daniel T Chen8286c532007-05-15 11:46:23 +0200710 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d6,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200711 "unknown Dell", STAC_9200_DELL_M22),
Tobin Davis49c605d2007-05-17 09:38:24 +0200712 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d8,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200713 "Dell Inspiron 640m", STAC_9200_DELL_M21),
714 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d9,
715 "unknown Dell", STAC_9200_DELL_D23),
716 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01da,
717 "unknown Dell", STAC_9200_DELL_D23),
718 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01de,
719 "unknown Dell", STAC_9200_DELL_D21),
720 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e3,
721 "unknown Dell", STAC_9200_DELL_D23),
722 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e8,
723 "unknown Dell", STAC_9200_DELL_D21),
724 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ee,
725 "unknown Dell", STAC_9200_DELL_M25),
726 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ef,
727 "unknown Dell", STAC_9200_DELL_M25),
Tobin Davis49c605d2007-05-17 09:38:24 +0200728 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f5,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200729 "Dell Inspiron 1501", STAC_9200_DELL_M26),
730 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f6,
731 "unknown Dell", STAC_9200_DELL_M26),
Tobin Davis49c605d2007-05-17 09:38:24 +0200732 /* Panasonic */
733 SND_PCI_QUIRK(0x10f7, 0x8338, "Panasonic CF-74", STAC_REF),
Takashi Iwai1194b5b2007-10-10 10:04:26 +0200734 /* Gateway machines needs EAPD to be set on resume */
735 SND_PCI_QUIRK(0x107b, 0x0205, "Gateway S-7110M", STAC_9200_GATEWAY),
736 SND_PCI_QUIRK(0x107b, 0x0317, "Gateway MT3423, MX341*",
737 STAC_9200_GATEWAY),
738 SND_PCI_QUIRK(0x107b, 0x0318, "Gateway ML3019, MT3707",
739 STAC_9200_GATEWAY),
Matt Porter403d1942005-11-29 15:00:51 +0100740 {} /* terminator */
741};
742
Tobin Davis8e21c342007-01-08 11:04:17 +0100743static unsigned int ref925x_pin_configs[8] = {
744 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
745 0x90a70320, 0x02214210, 0x400003f1, 0x9033032e,
746};
747
748static unsigned int stac925x_MA6_pin_configs[8] = {
749 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
750 0x90a70320, 0x90100211, 0x400003f1, 0x9033032e,
751};
752
Tobin Davis2c11f952007-05-17 09:36:34 +0200753static unsigned int stac925x_PA6_pin_configs[8] = {
754 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
755 0x50a103f0, 0x90100211, 0x400003f1, 0x9033032e,
756};
757
Tobin Davis8e21c342007-01-08 11:04:17 +0100758static unsigned int stac925xM2_2_pin_configs[8] = {
Steve Longerbeam7353e142007-05-29 14:36:17 +0200759 0x40c003f3, 0x424503f2, 0x04180011, 0x02a19020,
760 0x50a103f0, 0x90100212, 0x400003f1, 0x9033032e,
Tobin Davis8e21c342007-01-08 11:04:17 +0100761};
762
763static unsigned int *stac925x_brd_tbl[STAC_925x_MODELS] = {
764 [STAC_REF] = ref925x_pin_configs,
765 [STAC_M2_2] = stac925xM2_2_pin_configs,
766 [STAC_MA6] = stac925x_MA6_pin_configs,
Tobin Davis2c11f952007-05-17 09:36:34 +0200767 [STAC_PA6] = stac925x_PA6_pin_configs,
Tobin Davis8e21c342007-01-08 11:04:17 +0100768};
769
770static const char *stac925x_models[STAC_925x_MODELS] = {
771 [STAC_REF] = "ref",
772 [STAC_M2_2] = "m2-2",
773 [STAC_MA6] = "m6",
Tobin Davis2c11f952007-05-17 09:36:34 +0200774 [STAC_PA6] = "pa6",
Tobin Davis8e21c342007-01-08 11:04:17 +0100775};
776
777static struct snd_pci_quirk stac925x_cfg_tbl[] = {
778 /* SigmaTel reference board */
779 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, "DFI LanParty", STAC_REF),
Tobin Davis2c11f952007-05-17 09:36:34 +0200780 SND_PCI_QUIRK(0x8384, 0x7632, "Stac9202 Reference Board", STAC_REF),
Tobin Davis8e21c342007-01-08 11:04:17 +0100781 SND_PCI_QUIRK(0x107b, 0x0316, "Gateway M255", STAC_REF),
782 SND_PCI_QUIRK(0x107b, 0x0366, "Gateway MP6954", STAC_REF),
783 SND_PCI_QUIRK(0x107b, 0x0461, "Gateway NX560XL", STAC_MA6),
Tobin Davis2c11f952007-05-17 09:36:34 +0200784 SND_PCI_QUIRK(0x107b, 0x0681, "Gateway NX860", STAC_PA6),
Tobin Davis8e21c342007-01-08 11:04:17 +0100785 SND_PCI_QUIRK(0x1002, 0x437b, "Gateway MX6453", STAC_M2_2),
786 {} /* terminator */
787};
788
Matt Porter403d1942005-11-29 15:00:51 +0100789static unsigned int ref922x_pin_configs[10] = {
790 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
791 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
Matt2f2f4252005-04-13 14:45:30 +0200792 0x40000100, 0x40000100,
793};
794
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200795/*
796 STAC 922X pin configs for
797 102801A7
798 102801AB
799 102801A9
800 102801D1
801 102801D2
802*/
803static unsigned int dell_922x_d81_pin_configs[10] = {
804 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
805 0x02a19020, 0x01117011, 0x400001f0, 0x400001f1,
806 0x01813122, 0x400001f2,
807};
808
809/*
810 STAC 922X pin configs for
811 102801AC
812 102801D0
813*/
814static unsigned int dell_922x_d82_pin_configs[10] = {
815 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
816 0x02a19020, 0x01117011, 0x01451140, 0x400001f0,
817 0x01813122, 0x400001f1,
818};
819
820/*
821 STAC 922X pin configs for
822 102801BF
823*/
824static unsigned int dell_922x_m81_pin_configs[10] = {
825 0x0321101f, 0x01112024, 0x01111222, 0x91174220,
826 0x03a11050, 0x01116221, 0x90a70330, 0x01452340,
827 0x40C003f1, 0x405003f0,
828};
829
830/*
831 STAC 9221 A1 pin configs for
832 102801D7 (Dell XPS M1210)
833*/
834static unsigned int dell_922x_m82_pin_configs[10] = {
835 0x0221121f, 0x408103ff, 0x02111212, 0x90100310,
836 0x408003f1, 0x02111211, 0x03451340, 0x40c003f2,
837 0x508003f3, 0x405003f4,
838};
839
Matt Porter403d1942005-11-29 15:00:51 +0100840static unsigned int d945gtp3_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +0100841 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
Matt Porter403d1942005-11-29 15:00:51 +0100842 0x40000100, 0x40000100, 0x40000100, 0x40000100,
843 0x02a19120, 0x40000100,
844};
845
846static unsigned int d945gtp5_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +0100847 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
848 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
Matt Porter403d1942005-11-29 15:00:51 +0100849 0x02a19320, 0x40000100,
850};
851
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +0200852static unsigned int intel_mac_v1_pin_configs[10] = {
853 0x0121e21f, 0x400000ff, 0x9017e110, 0x400000fd,
854 0x400000fe, 0x0181e020, 0x1145e030, 0x11c5e240,
Takashi Iwai3fc24d82007-02-16 13:27:18 +0100855 0x400000fc, 0x400000fb,
856};
857
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +0200858static unsigned int intel_mac_v2_pin_configs[10] = {
859 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
860 0x400000fe, 0x0181e020, 0x1145e230, 0x500000fa,
Sylvain FORETf16928f2007-04-27 14:22:36 +0200861 0x400000fc, 0x400000fb,
862};
863
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +0200864static unsigned int intel_mac_v3_pin_configs[10] = {
865 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
866 0x400000fe, 0x0181e020, 0x1145e230, 0x11c5e240,
867 0x400000fc, 0x400000fb,
868};
869
870static unsigned int intel_mac_v4_pin_configs[10] = {
871 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
872 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
873 0x400000fc, 0x400000fb,
874};
875
876static unsigned int intel_mac_v5_pin_configs[10] = {
877 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
878 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
879 0x400000fc, 0x400000fb,
Takashi Iwai0dae0f82007-05-21 12:41:29 +0200880};
881
Takashi Iwai76c08822007-06-19 12:17:42 +0200882
Takashi Iwai19039bd2006-06-28 15:52:16 +0200883static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100884 [STAC_D945_REF] = ref922x_pin_configs,
Takashi Iwai19039bd2006-06-28 15:52:16 +0200885 [STAC_D945GTP3] = d945gtp3_pin_configs,
886 [STAC_D945GTP5] = d945gtp5_pin_configs,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +0200887 [STAC_INTEL_MAC_V1] = intel_mac_v1_pin_configs,
888 [STAC_INTEL_MAC_V2] = intel_mac_v2_pin_configs,
889 [STAC_INTEL_MAC_V3] = intel_mac_v3_pin_configs,
890 [STAC_INTEL_MAC_V4] = intel_mac_v4_pin_configs,
891 [STAC_INTEL_MAC_V5] = intel_mac_v5_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200892 /* for backward compatibility */
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +0200893 [STAC_MACMINI] = intel_mac_v3_pin_configs,
894 [STAC_MACBOOK] = intel_mac_v5_pin_configs,
895 [STAC_MACBOOK_PRO_V1] = intel_mac_v3_pin_configs,
896 [STAC_MACBOOK_PRO_V2] = intel_mac_v3_pin_configs,
897 [STAC_IMAC_INTEL] = intel_mac_v2_pin_configs,
898 [STAC_IMAC_INTEL_20] = intel_mac_v3_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200899 [STAC_922X_DELL_D81] = dell_922x_d81_pin_configs,
900 [STAC_922X_DELL_D82] = dell_922x_d82_pin_configs,
901 [STAC_922X_DELL_M81] = dell_922x_m81_pin_configs,
902 [STAC_922X_DELL_M82] = dell_922x_m82_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +0100903};
904
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100905static const char *stac922x_models[STAC_922X_MODELS] = {
906 [STAC_D945_REF] = "ref",
907 [STAC_D945GTP5] = "5stack",
908 [STAC_D945GTP3] = "3stack",
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +0200909 [STAC_INTEL_MAC_V1] = "intel-mac-v1",
910 [STAC_INTEL_MAC_V2] = "intel-mac-v2",
911 [STAC_INTEL_MAC_V3] = "intel-mac-v3",
912 [STAC_INTEL_MAC_V4] = "intel-mac-v4",
913 [STAC_INTEL_MAC_V5] = "intel-mac-v5",
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200914 /* for backward compatibility */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100915 [STAC_MACMINI] = "macmini",
Takashi Iwai3fc24d82007-02-16 13:27:18 +0100916 [STAC_MACBOOK] = "macbook",
Nicolas Boichat6f0778d2007-03-15 12:38:15 +0100917 [STAC_MACBOOK_PRO_V1] = "macbook-pro-v1",
918 [STAC_MACBOOK_PRO_V2] = "macbook-pro",
Sylvain FORETf16928f2007-04-27 14:22:36 +0200919 [STAC_IMAC_INTEL] = "imac-intel",
Takashi Iwai0dae0f82007-05-21 12:41:29 +0200920 [STAC_IMAC_INTEL_20] = "imac-intel-20",
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200921 [STAC_922X_DELL_D81] = "dell-d81",
922 [STAC_922X_DELL_D82] = "dell-d82",
923 [STAC_922X_DELL_M81] = "dell-m81",
924 [STAC_922X_DELL_M82] = "dell-m82",
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100925};
926
927static struct snd_pci_quirk stac922x_cfg_tbl[] = {
928 /* SigmaTel reference board */
929 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
930 "DFI LanParty", STAC_D945_REF),
931 /* Intel 945G based systems */
932 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101,
933 "Intel D945G", STAC_D945GTP3),
934 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0202,
935 "Intel D945G", STAC_D945GTP3),
936 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0606,
937 "Intel D945G", STAC_D945GTP3),
938 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0601,
939 "Intel D945G", STAC_D945GTP3),
940 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0111,
941 "Intel D945G", STAC_D945GTP3),
942 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1115,
943 "Intel D945G", STAC_D945GTP3),
944 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1116,
945 "Intel D945G", STAC_D945GTP3),
946 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1117,
947 "Intel D945G", STAC_D945GTP3),
948 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1118,
949 "Intel D945G", STAC_D945GTP3),
950 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1119,
951 "Intel D945G", STAC_D945GTP3),
952 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x8826,
953 "Intel D945G", STAC_D945GTP3),
954 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5049,
955 "Intel D945G", STAC_D945GTP3),
956 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5055,
957 "Intel D945G", STAC_D945GTP3),
958 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5048,
959 "Intel D945G", STAC_D945GTP3),
960 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0110,
961 "Intel D945G", STAC_D945GTP3),
962 /* Intel D945G 5-stack systems */
963 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0404,
964 "Intel D945G", STAC_D945GTP5),
965 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0303,
966 "Intel D945G", STAC_D945GTP5),
967 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0013,
968 "Intel D945G", STAC_D945GTP5),
969 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0417,
970 "Intel D945G", STAC_D945GTP5),
971 /* Intel 945P based systems */
972 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0b0b,
973 "Intel D945P", STAC_D945GTP3),
974 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0112,
975 "Intel D945P", STAC_D945GTP3),
976 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0d0d,
977 "Intel D945P", STAC_D945GTP3),
978 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0909,
979 "Intel D945P", STAC_D945GTP3),
980 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0505,
981 "Intel D945P", STAC_D945GTP3),
982 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707,
983 "Intel D945P", STAC_D945GTP5),
984 /* other systems */
985 /* Apple Mac Mini (early 2006) */
986 SND_PCI_QUIRK(0x8384, 0x7680,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +0200987 "Mac Mini", STAC_INTEL_MAC_V3),
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200988 /* Dell systems */
989 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a7,
990 "unknown Dell", STAC_922X_DELL_D81),
991 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a9,
992 "unknown Dell", STAC_922X_DELL_D81),
993 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ab,
994 "unknown Dell", STAC_922X_DELL_D81),
995 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ac,
996 "unknown Dell", STAC_922X_DELL_D82),
997 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bf,
998 "unknown Dell", STAC_922X_DELL_M81),
999 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d0,
1000 "unknown Dell", STAC_922X_DELL_D82),
1001 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d1,
1002 "unknown Dell", STAC_922X_DELL_D81),
1003 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d2,
1004 "unknown Dell", STAC_922X_DELL_D81),
1005 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d7,
1006 "Dell XPS M1210", STAC_922X_DELL_M82),
Matt Porter403d1942005-11-29 15:00:51 +01001007 {} /* terminator */
1008};
1009
Matt Porter3cc08dc2006-01-23 15:27:49 +01001010static unsigned int ref927x_pin_configs[14] = {
Tobin Davis93ed1502006-09-01 21:03:12 +02001011 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
1012 0x01a19040, 0x01011012, 0x01016011, 0x0101201f,
1013 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
1014 0x01c42190, 0x40000100,
Matt Porter3cc08dc2006-01-23 15:27:49 +01001015};
1016
Tobin Davis93ed1502006-09-01 21:03:12 +02001017static unsigned int d965_3st_pin_configs[14] = {
Tobin Davis81d3dbd2006-08-22 19:44:45 +02001018 0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
1019 0x01a19021, 0x01813024, 0x40000100, 0x40000100,
1020 0x40000100, 0x40000100, 0x40000100, 0x40000100,
1021 0x40000100, 0x40000100
1022};
1023
Tobin Davis93ed1502006-09-01 21:03:12 +02001024static unsigned int d965_5st_pin_configs[14] = {
1025 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
1026 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
1027 0x40000100, 0x40000100, 0x40000100, 0x01442070,
1028 0x40000100, 0x40000100
1029};
1030
Tobin Davis4ff076e2007-08-07 11:48:12 +02001031static unsigned int dell_3st_pin_configs[14] = {
1032 0x02211230, 0x02a11220, 0x01a19040, 0x01114210,
1033 0x01111212, 0x01116211, 0x01813050, 0x01112214,
1034 0x403003fa, 0x40000100, 0x40000100, 0x404003fb,
1035 0x40c003fc, 0x40000100
1036};
1037
Tobin Davis93ed1502006-09-01 21:03:12 +02001038static unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001039 [STAC_D965_REF] = ref927x_pin_configs,
Tobin Davis93ed1502006-09-01 21:03:12 +02001040 [STAC_D965_3ST] = d965_3st_pin_configs,
1041 [STAC_D965_5ST] = d965_5st_pin_configs,
Tobin Davis4ff076e2007-08-07 11:48:12 +02001042 [STAC_DELL_3ST] = dell_3st_pin_configs,
Matt Porter3cc08dc2006-01-23 15:27:49 +01001043};
1044
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001045static const char *stac927x_models[STAC_927X_MODELS] = {
1046 [STAC_D965_REF] = "ref",
1047 [STAC_D965_3ST] = "3stack",
1048 [STAC_D965_5ST] = "5stack",
Tobin Davis4ff076e2007-08-07 11:48:12 +02001049 [STAC_DELL_3ST] = "dell-3stack",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001050};
1051
1052static struct snd_pci_quirk stac927x_cfg_tbl[] = {
1053 /* SigmaTel reference board */
1054 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1055 "DFI LanParty", STAC_D965_REF),
Tobin Davis81d3dbd2006-08-22 19:44:45 +02001056 /* Intel 946 based systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001057 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST),
1058 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST),
Tobin Davis93ed1502006-09-01 21:03:12 +02001059 /* 965 based 3 stack systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001060 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2116, "Intel D965", STAC_D965_3ST),
1061 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2115, "Intel D965", STAC_D965_3ST),
1062 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2114, "Intel D965", STAC_D965_3ST),
1063 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2113, "Intel D965", STAC_D965_3ST),
1064 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2112, "Intel D965", STAC_D965_3ST),
1065 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2111, "Intel D965", STAC_D965_3ST),
1066 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2110, "Intel D965", STAC_D965_3ST),
1067 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2009, "Intel D965", STAC_D965_3ST),
1068 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2008, "Intel D965", STAC_D965_3ST),
1069 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2007, "Intel D965", STAC_D965_3ST),
1070 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2006, "Intel D965", STAC_D965_3ST),
1071 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2005, "Intel D965", STAC_D965_3ST),
1072 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2004, "Intel D965", STAC_D965_3ST),
1073 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2003, "Intel D965", STAC_D965_3ST),
1074 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2002, "Intel D965", STAC_D965_3ST),
1075 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2001, "Intel D965", STAC_D965_3ST),
Tim Gardner5e915bb2007-10-10 10:42:00 +02001076 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f3, "Dell Inspiron 1420", STAC_D965_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +02001077 /* Dell 3 stack systems */
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001078 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01dd, "Dell Dimension E520", STAC_DELL_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +02001079 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ed, "Dell ", STAC_DELL_3ST),
1080 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f4, "Dell ", STAC_DELL_3ST),
Tobin Davis93ed1502006-09-01 21:03:12 +02001081 /* 965 based 5 stack systems */
Tim Gardner5e915bb2007-10-10 10:42:00 +02001082 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0209, "Dell XPS 1330", STAC_D965_5ST),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001083 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2301, "Intel D965", STAC_D965_5ST),
1084 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2302, "Intel D965", STAC_D965_5ST),
1085 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2303, "Intel D965", STAC_D965_5ST),
1086 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2304, "Intel D965", STAC_D965_5ST),
1087 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2305, "Intel D965", STAC_D965_5ST),
1088 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2501, "Intel D965", STAC_D965_5ST),
1089 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2502, "Intel D965", STAC_D965_5ST),
1090 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2503, "Intel D965", STAC_D965_5ST),
1091 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2504, "Intel D965", STAC_D965_5ST),
Matt Porter3cc08dc2006-01-23 15:27:49 +01001092 {} /* terminator */
1093};
1094
Matt Porterf3302a52006-07-31 12:49:34 +02001095static unsigned int ref9205_pin_configs[12] = {
1096 0x40000100, 0x40000100, 0x01016011, 0x01014010,
Matt Porter8b657272006-10-26 17:12:59 +02001097 0x01813122, 0x01a19021, 0x40000100, 0x40000100,
1098 0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
Matt Porterf3302a52006-07-31 12:49:34 +02001099};
1100
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001101/*
1102 STAC 9205 pin configs for
1103 102801F1
1104 102801F2
1105 102801FC
1106 102801FD
1107 10280204
1108 1028021F
1109*/
1110static unsigned int dell_9205_m42_pin_configs[12] = {
1111 0x0321101F, 0x03A11020, 0x400003FA, 0x90170310,
1112 0x400003FB, 0x400003FC, 0x400003FD, 0x40F000F9,
1113 0x90A60330, 0x400003FF, 0x0144131F, 0x40C003FE,
1114};
1115
1116/*
1117 STAC 9205 pin configs for
1118 102801F9
1119 102801FA
1120 102801FE
1121 102801FF (Dell Precision M4300)
1122 10280206
1123 10280200
1124 10280201
1125*/
1126static unsigned int dell_9205_m43_pin_configs[12] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001127 0x0321101f, 0x03a11020, 0x90a70330, 0x90170310,
1128 0x400000fe, 0x400000ff, 0x400000fd, 0x40f000f9,
1129 0x400000fa, 0x400000fc, 0x0144131f, 0x40c003f8,
1130};
1131
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001132static unsigned int dell_9205_m44_pin_configs[12] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001133 0x0421101f, 0x04a11020, 0x400003fa, 0x90170310,
1134 0x400003fb, 0x400003fc, 0x400003fd, 0x400003f9,
1135 0x90a60330, 0x400003ff, 0x01441340, 0x40c003fe,
1136};
1137
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001138static unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001139 [STAC_9205_REF] = ref9205_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001140 [STAC_9205_DELL_M42] = dell_9205_m42_pin_configs,
1141 [STAC_9205_DELL_M43] = dell_9205_m43_pin_configs,
1142 [STAC_9205_DELL_M44] = dell_9205_m44_pin_configs,
Matt Porterf3302a52006-07-31 12:49:34 +02001143};
1144
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001145static const char *stac9205_models[STAC_9205_MODELS] = {
1146 [STAC_9205_REF] = "ref",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001147 [STAC_9205_DELL_M42] = "dell-m42",
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001148 [STAC_9205_DELL_M43] = "dell-m43",
1149 [STAC_9205_DELL_M44] = "dell-m44",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001150};
1151
1152static struct snd_pci_quirk stac9205_cfg_tbl[] = {
1153 /* SigmaTel reference board */
1154 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1155 "DFI LanParty", STAC_9205_REF),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001156 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f1,
1157 "unknown Dell", STAC_9205_DELL_M42),
1158 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f2,
1159 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001160 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f8,
Matthew Ranostayb44ef2f2007-09-18 00:52:38 +02001161 "Dell Precision", STAC_9205_DELL_M43),
1162 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021c,
1163 "Dell Precision", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001164 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f9,
1165 "Dell Precision", STAC_9205_DELL_M43),
Matthew Ranostaye45e4592007-09-10 23:09:42 +02001166 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021b,
1167 "Dell Precision", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001168 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fa,
1169 "Dell Precision", STAC_9205_DELL_M43),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001170 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fc,
1171 "unknown Dell", STAC_9205_DELL_M42),
1172 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fd,
1173 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001174 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fe,
1175 "Dell Precision", STAC_9205_DELL_M43),
1176 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ff,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001177 "Dell Precision M4300", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001178 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0206,
1179 "Dell Precision", STAC_9205_DELL_M43),
1180 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f1,
1181 "Dell Inspiron", STAC_9205_DELL_M44),
1182 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f2,
1183 "Dell Inspiron", STAC_9205_DELL_M44),
1184 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fc,
1185 "Dell Inspiron", STAC_9205_DELL_M44),
1186 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fd,
1187 "Dell Inspiron", STAC_9205_DELL_M44),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001188 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0204,
1189 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001190 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021f,
1191 "Dell Inspiron", STAC_9205_DELL_M44),
Matt Porterf3302a52006-07-31 12:49:34 +02001192 {} /* terminator */
1193};
1194
Richard Fish11b44bb2006-08-23 18:31:34 +02001195static int stac92xx_save_bios_config_regs(struct hda_codec *codec)
1196{
1197 int i;
1198 struct sigmatel_spec *spec = codec->spec;
1199
1200 if (! spec->bios_pin_configs) {
1201 spec->bios_pin_configs = kcalloc(spec->num_pins,
1202 sizeof(*spec->bios_pin_configs), GFP_KERNEL);
1203 if (! spec->bios_pin_configs)
1204 return -ENOMEM;
1205 }
1206
1207 for (i = 0; i < spec->num_pins; i++) {
1208 hda_nid_t nid = spec->pin_nids[i];
1209 unsigned int pin_cfg;
1210
1211 pin_cfg = snd_hda_codec_read(codec, nid, 0,
1212 AC_VERB_GET_CONFIG_DEFAULT, 0x00);
1213 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x bios pin config %8.8x\n",
1214 nid, pin_cfg);
1215 spec->bios_pin_configs[i] = pin_cfg;
1216 }
1217
1218 return 0;
1219}
1220
Matthew Ranostay87d48362007-07-17 11:52:24 +02001221static void stac92xx_set_config_reg(struct hda_codec *codec,
1222 hda_nid_t pin_nid, unsigned int pin_config)
1223{
1224 int i;
1225 snd_hda_codec_write(codec, pin_nid, 0,
1226 AC_VERB_SET_CONFIG_DEFAULT_BYTES_0,
1227 pin_config & 0x000000ff);
1228 snd_hda_codec_write(codec, pin_nid, 0,
1229 AC_VERB_SET_CONFIG_DEFAULT_BYTES_1,
1230 (pin_config & 0x0000ff00) >> 8);
1231 snd_hda_codec_write(codec, pin_nid, 0,
1232 AC_VERB_SET_CONFIG_DEFAULT_BYTES_2,
1233 (pin_config & 0x00ff0000) >> 16);
1234 snd_hda_codec_write(codec, pin_nid, 0,
1235 AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
1236 pin_config >> 24);
1237 i = snd_hda_codec_read(codec, pin_nid, 0,
1238 AC_VERB_GET_CONFIG_DEFAULT,
1239 0x00);
1240 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x pin config %8.8x\n",
1241 pin_nid, i);
1242}
1243
Matt2f2f4252005-04-13 14:45:30 +02001244static void stac92xx_set_config_regs(struct hda_codec *codec)
1245{
1246 int i;
1247 struct sigmatel_spec *spec = codec->spec;
Matt2f2f4252005-04-13 14:45:30 +02001248
Matthew Ranostay87d48362007-07-17 11:52:24 +02001249 if (!spec->pin_configs)
1250 return;
Richard Fish11b44bb2006-08-23 18:31:34 +02001251
Matthew Ranostay87d48362007-07-17 11:52:24 +02001252 for (i = 0; i < spec->num_pins; i++)
1253 stac92xx_set_config_reg(codec, spec->pin_nids[i],
1254 spec->pin_configs[i]);
Matt2f2f4252005-04-13 14:45:30 +02001255}
Matt2f2f4252005-04-13 14:45:30 +02001256
Takashi Iwai82599802007-07-31 15:56:24 +02001257static void stac92xx_enable_gpio_mask(struct hda_codec *codec)
Matthew Ranostay92a22be2007-06-19 16:48:28 +02001258{
Takashi Iwai82599802007-07-31 15:56:24 +02001259 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay87d48362007-07-17 11:52:24 +02001260 /* Configure GPIOx as output */
Takashi Iwai82beb8f2007-08-10 17:09:26 +02001261 snd_hda_codec_write_cache(codec, codec->afg, 0,
1262 AC_VERB_SET_GPIO_DIRECTION, spec->gpio_mask);
Matthew Ranostay87d48362007-07-17 11:52:24 +02001263 /* Configure GPIOx as CMOS */
Takashi Iwai82beb8f2007-08-10 17:09:26 +02001264 snd_hda_codec_write_cache(codec, codec->afg, 0, 0x7e7, 0x00000000);
Matthew Ranostay87d48362007-07-17 11:52:24 +02001265 /* Assert GPIOx */
Takashi Iwai82beb8f2007-08-10 17:09:26 +02001266 snd_hda_codec_write_cache(codec, codec->afg, 0,
1267 AC_VERB_SET_GPIO_DATA, spec->gpio_data);
Matthew Ranostay87d48362007-07-17 11:52:24 +02001268 /* Enable GPIOx */
Takashi Iwai82beb8f2007-08-10 17:09:26 +02001269 snd_hda_codec_write_cache(codec, codec->afg, 0,
1270 AC_VERB_SET_GPIO_MASK, spec->gpio_mask);
Matthew Ranostay92a22be2007-06-19 16:48:28 +02001271}
1272
Matt2f2f4252005-04-13 14:45:30 +02001273/*
1274 * Analog playback callbacks
1275 */
1276static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
1277 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001278 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02001279{
1280 struct sigmatel_spec *spec = codec->spec;
1281 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
1282}
1283
1284static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1285 struct hda_codec *codec,
1286 unsigned int stream_tag,
1287 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001288 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02001289{
1290 struct sigmatel_spec *spec = codec->spec;
Matt Porter403d1942005-11-29 15:00:51 +01001291 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
Matt2f2f4252005-04-13 14:45:30 +02001292}
1293
1294static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
1295 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001296 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02001297{
1298 struct sigmatel_spec *spec = codec->spec;
1299 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
1300}
1301
1302/*
Mattdabbed62005-06-14 10:19:34 +02001303 * Digital playback callbacks
1304 */
1305static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
1306 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001307 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +02001308{
1309 struct sigmatel_spec *spec = codec->spec;
1310 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
1311}
1312
1313static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
1314 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001315 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +02001316{
1317 struct sigmatel_spec *spec = codec->spec;
1318 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
1319}
1320
Takashi Iwai6b97eb42007-04-05 14:51:48 +02001321static int stac92xx_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1322 struct hda_codec *codec,
1323 unsigned int stream_tag,
1324 unsigned int format,
1325 struct snd_pcm_substream *substream)
1326{
1327 struct sigmatel_spec *spec = codec->spec;
1328 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1329 stream_tag, format, substream);
1330}
1331
Mattdabbed62005-06-14 10:19:34 +02001332
1333/*
Matt2f2f4252005-04-13 14:45:30 +02001334 * Analog capture callbacks
1335 */
1336static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1337 struct hda_codec *codec,
1338 unsigned int stream_tag,
1339 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001340 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02001341{
1342 struct sigmatel_spec *spec = codec->spec;
1343
1344 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
1345 stream_tag, 0, format);
1346 return 0;
1347}
1348
1349static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1350 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001351 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02001352{
1353 struct sigmatel_spec *spec = codec->spec;
1354
1355 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 0, 0, 0);
1356 return 0;
1357}
1358
Mattdabbed62005-06-14 10:19:34 +02001359static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
1360 .substreams = 1,
1361 .channels_min = 2,
1362 .channels_max = 2,
1363 /* NID is set in stac92xx_build_pcms */
1364 .ops = {
1365 .open = stac92xx_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02001366 .close = stac92xx_dig_playback_pcm_close,
1367 .prepare = stac92xx_dig_playback_pcm_prepare
Mattdabbed62005-06-14 10:19:34 +02001368 },
1369};
1370
1371static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
1372 .substreams = 1,
1373 .channels_min = 2,
1374 .channels_max = 2,
1375 /* NID is set in stac92xx_build_pcms */
1376};
1377
Matt2f2f4252005-04-13 14:45:30 +02001378static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
1379 .substreams = 1,
1380 .channels_min = 2,
Mattc7d4b2f2005-06-27 14:59:41 +02001381 .channels_max = 8,
Matt2f2f4252005-04-13 14:45:30 +02001382 .nid = 0x02, /* NID to query formats and rates */
1383 .ops = {
1384 .open = stac92xx_playback_pcm_open,
1385 .prepare = stac92xx_playback_pcm_prepare,
1386 .cleanup = stac92xx_playback_pcm_cleanup
1387 },
1388};
1389
Matt Porter3cc08dc2006-01-23 15:27:49 +01001390static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
1391 .substreams = 1,
1392 .channels_min = 2,
1393 .channels_max = 2,
1394 .nid = 0x06, /* NID to query formats and rates */
1395 .ops = {
1396 .open = stac92xx_playback_pcm_open,
1397 .prepare = stac92xx_playback_pcm_prepare,
1398 .cleanup = stac92xx_playback_pcm_cleanup
1399 },
1400};
1401
Matt2f2f4252005-04-13 14:45:30 +02001402static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
Matt2f2f4252005-04-13 14:45:30 +02001403 .channels_min = 2,
1404 .channels_max = 2,
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001405 /* NID + .substreams is set in stac92xx_build_pcms */
Matt2f2f4252005-04-13 14:45:30 +02001406 .ops = {
1407 .prepare = stac92xx_capture_pcm_prepare,
1408 .cleanup = stac92xx_capture_pcm_cleanup
1409 },
1410};
1411
1412static int stac92xx_build_pcms(struct hda_codec *codec)
1413{
1414 struct sigmatel_spec *spec = codec->spec;
1415 struct hda_pcm *info = spec->pcm_rec;
1416
1417 codec->num_pcms = 1;
1418 codec->pcm_info = info;
1419
Mattc7d4b2f2005-06-27 14:59:41 +02001420 info->name = "STAC92xx Analog";
Matt2f2f4252005-04-13 14:45:30 +02001421 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
Matt2f2f4252005-04-13 14:45:30 +02001422 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
Matt Porter3cc08dc2006-01-23 15:27:49 +01001423 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001424 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adcs;
Matt Porter3cc08dc2006-01-23 15:27:49 +01001425
1426 if (spec->alt_switch) {
1427 codec->num_pcms++;
1428 info++;
1429 info->name = "STAC92xx Analog Alt";
1430 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
1431 }
Matt2f2f4252005-04-13 14:45:30 +02001432
Mattdabbed62005-06-14 10:19:34 +02001433 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
1434 codec->num_pcms++;
1435 info++;
1436 info->name = "STAC92xx Digital";
1437 if (spec->multiout.dig_out_nid) {
1438 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
1439 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
1440 }
1441 if (spec->dig_in_nid) {
1442 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
1443 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
1444 }
1445 }
1446
Matt2f2f4252005-04-13 14:45:30 +02001447 return 0;
1448}
1449
Takashi Iwaic960a032006-03-23 17:06:28 +01001450static unsigned int stac92xx_get_vref(struct hda_codec *codec, hda_nid_t nid)
1451{
1452 unsigned int pincap = snd_hda_param_read(codec, nid,
1453 AC_PAR_PIN_CAP);
1454 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
1455 if (pincap & AC_PINCAP_VREF_100)
1456 return AC_PINCTL_VREF_100;
1457 if (pincap & AC_PINCAP_VREF_80)
1458 return AC_PINCTL_VREF_80;
1459 if (pincap & AC_PINCAP_VREF_50)
1460 return AC_PINCTL_VREF_50;
1461 if (pincap & AC_PINCAP_VREF_GRD)
1462 return AC_PINCTL_VREF_GRD;
1463 return 0;
1464}
1465
Matt Porter403d1942005-11-29 15:00:51 +01001466static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
1467
1468{
Takashi Iwai82beb8f2007-08-10 17:09:26 +02001469 snd_hda_codec_write_cache(codec, nid, 0,
1470 AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
Matt Porter403d1942005-11-29 15:00:51 +01001471}
1472
Takashi Iwaia5ce8892007-07-23 15:42:26 +02001473#define stac92xx_io_switch_info snd_ctl_boolean_mono_info
Matt Porter403d1942005-11-29 15:00:51 +01001474
1475static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1476{
1477 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1478 struct sigmatel_spec *spec = codec->spec;
1479 int io_idx = kcontrol-> private_value & 0xff;
1480
1481 ucontrol->value.integer.value[0] = spec->io_switch[io_idx];
1482 return 0;
1483}
1484
1485static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1486{
1487 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1488 struct sigmatel_spec *spec = codec->spec;
1489 hda_nid_t nid = kcontrol->private_value >> 8;
1490 int io_idx = kcontrol-> private_value & 0xff;
1491 unsigned short val = ucontrol->value.integer.value[0];
1492
1493 spec->io_switch[io_idx] = val;
1494
1495 if (val)
1496 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
Takashi Iwaic960a032006-03-23 17:06:28 +01001497 else {
1498 unsigned int pinctl = AC_PINCTL_IN_EN;
1499 if (io_idx) /* set VREF for mic */
1500 pinctl |= stac92xx_get_vref(codec, nid);
1501 stac92xx_auto_set_pinctl(codec, nid, pinctl);
1502 }
Matt Porter403d1942005-11-29 15:00:51 +01001503 return 1;
1504}
1505
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02001506#define stac92xx_clfe_switch_info snd_ctl_boolean_mono_info
1507
1508static int stac92xx_clfe_switch_get(struct snd_kcontrol *kcontrol,
1509 struct snd_ctl_elem_value *ucontrol)
1510{
1511 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1512 struct sigmatel_spec *spec = codec->spec;
1513
1514 ucontrol->value.integer.value[0] = spec->clfe_swap;
1515 return 0;
1516}
1517
1518static int stac92xx_clfe_switch_put(struct snd_kcontrol *kcontrol,
1519 struct snd_ctl_elem_value *ucontrol)
1520{
1521 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1522 struct sigmatel_spec *spec = codec->spec;
1523 hda_nid_t nid = kcontrol->private_value & 0xff;
1524
1525 if (spec->clfe_swap == ucontrol->value.integer.value[0])
1526 return 0;
1527
1528 spec->clfe_swap = ucontrol->value.integer.value[0];
1529
1530 snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
1531 spec->clfe_swap ? 0x4 : 0x0);
1532
1533 return 1;
1534}
1535
Matt Porter403d1942005-11-29 15:00:51 +01001536#define STAC_CODEC_IO_SWITCH(xname, xpval) \
1537 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1538 .name = xname, \
1539 .index = 0, \
1540 .info = stac92xx_io_switch_info, \
1541 .get = stac92xx_io_switch_get, \
1542 .put = stac92xx_io_switch_put, \
1543 .private_value = xpval, \
1544 }
1545
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02001546#define STAC_CODEC_CLFE_SWITCH(xname, xpval) \
1547 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1548 .name = xname, \
1549 .index = 0, \
1550 .info = stac92xx_clfe_switch_info, \
1551 .get = stac92xx_clfe_switch_get, \
1552 .put = stac92xx_clfe_switch_put, \
1553 .private_value = xpval, \
1554 }
Matt Porter403d1942005-11-29 15:00:51 +01001555
Mattc7d4b2f2005-06-27 14:59:41 +02001556enum {
1557 STAC_CTL_WIDGET_VOL,
1558 STAC_CTL_WIDGET_MUTE,
Matt Porter403d1942005-11-29 15:00:51 +01001559 STAC_CTL_WIDGET_IO_SWITCH,
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02001560 STAC_CTL_WIDGET_CLFE_SWITCH
Mattc7d4b2f2005-06-27 14:59:41 +02001561};
1562
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001563static struct snd_kcontrol_new stac92xx_control_templates[] = {
Mattc7d4b2f2005-06-27 14:59:41 +02001564 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
1565 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Matt Porter403d1942005-11-29 15:00:51 +01001566 STAC_CODEC_IO_SWITCH(NULL, 0),
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02001567 STAC_CODEC_CLFE_SWITCH(NULL, 0),
Mattc7d4b2f2005-06-27 14:59:41 +02001568};
1569
1570/* add dynamic controls */
1571static int stac92xx_add_control(struct sigmatel_spec *spec, int type, const char *name, unsigned long val)
1572{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001573 struct snd_kcontrol_new *knew;
Mattc7d4b2f2005-06-27 14:59:41 +02001574
1575 if (spec->num_kctl_used >= spec->num_kctl_alloc) {
1576 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
1577
1578 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */
1579 if (! knew)
1580 return -ENOMEM;
1581 if (spec->kctl_alloc) {
1582 memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
1583 kfree(spec->kctl_alloc);
1584 }
1585 spec->kctl_alloc = knew;
1586 spec->num_kctl_alloc = num;
1587 }
1588
1589 knew = &spec->kctl_alloc[spec->num_kctl_used];
1590 *knew = stac92xx_control_templates[type];
Takashi Iwai82fe0c52005-06-30 10:54:33 +02001591 knew->name = kstrdup(name, GFP_KERNEL);
Mattc7d4b2f2005-06-27 14:59:41 +02001592 if (! knew->name)
1593 return -ENOMEM;
1594 knew->private_value = val;
1595 spec->num_kctl_used++;
1596 return 0;
1597}
1598
Matt Porter403d1942005-11-29 15:00:51 +01001599/* flag inputs as additional dynamic lineouts */
1600static int stac92xx_add_dyn_out_pins(struct hda_codec *codec, struct auto_pin_cfg *cfg)
1601{
1602 struct sigmatel_spec *spec = codec->spec;
Steve Longerbeam7b043892007-05-03 20:50:03 +02001603 unsigned int wcaps, wtype;
1604 int i, num_dacs = 0;
1605
1606 /* use the wcaps cache to count all DACs available for line-outs */
1607 for (i = 0; i < codec->num_nodes; i++) {
1608 wcaps = codec->wcaps[i];
1609 wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
1610 if (wtype == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL))
1611 num_dacs++;
1612 }
Matt Porter403d1942005-11-29 15:00:51 +01001613
Steve Longerbeam7b043892007-05-03 20:50:03 +02001614 snd_printdd("%s: total dac count=%d\n", __func__, num_dacs);
1615
Matt Porter403d1942005-11-29 15:00:51 +01001616 switch (cfg->line_outs) {
1617 case 3:
1618 /* add line-in as side */
Steve Longerbeam7b043892007-05-03 20:50:03 +02001619 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 3) {
Takashi Iwaic480f792007-09-03 09:43:38 +02001620 cfg->line_out_pins[cfg->line_outs] =
1621 cfg->input_pins[AUTO_PIN_LINE];
Matt Porter403d1942005-11-29 15:00:51 +01001622 spec->line_switch = 1;
1623 cfg->line_outs++;
1624 }
1625 break;
1626 case 2:
1627 /* add line-in as clfe and mic as side */
Steve Longerbeam7b043892007-05-03 20:50:03 +02001628 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 2) {
Takashi Iwaic480f792007-09-03 09:43:38 +02001629 cfg->line_out_pins[cfg->line_outs] =
1630 cfg->input_pins[AUTO_PIN_LINE];
Matt Porter403d1942005-11-29 15:00:51 +01001631 spec->line_switch = 1;
1632 cfg->line_outs++;
1633 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02001634 if (cfg->input_pins[AUTO_PIN_MIC] && num_dacs > 3) {
Takashi Iwaic480f792007-09-03 09:43:38 +02001635 cfg->line_out_pins[cfg->line_outs] =
1636 cfg->input_pins[AUTO_PIN_MIC];
Matt Porter403d1942005-11-29 15:00:51 +01001637 spec->mic_switch = 1;
1638 cfg->line_outs++;
1639 }
1640 break;
1641 case 1:
1642 /* add line-in as surr and mic as clfe */
Steve Longerbeam7b043892007-05-03 20:50:03 +02001643 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 1) {
Takashi Iwaic480f792007-09-03 09:43:38 +02001644 cfg->line_out_pins[cfg->line_outs] =
1645 cfg->input_pins[AUTO_PIN_LINE];
Matt Porter403d1942005-11-29 15:00:51 +01001646 spec->line_switch = 1;
1647 cfg->line_outs++;
1648 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02001649 if (cfg->input_pins[AUTO_PIN_MIC] && num_dacs > 2) {
Takashi Iwaic480f792007-09-03 09:43:38 +02001650 cfg->line_out_pins[cfg->line_outs] =
1651 cfg->input_pins[AUTO_PIN_MIC];
Matt Porter403d1942005-11-29 15:00:51 +01001652 spec->mic_switch = 1;
1653 cfg->line_outs++;
1654 }
1655 break;
1656 }
1657
1658 return 0;
1659}
1660
Steve Longerbeam7b043892007-05-03 20:50:03 +02001661
1662static int is_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
1663{
1664 int i;
1665
1666 for (i = 0; i < spec->multiout.num_dacs; i++) {
1667 if (spec->multiout.dac_nids[i] == nid)
1668 return 1;
1669 }
1670
1671 return 0;
1672}
1673
Matt Porter3cc08dc2006-01-23 15:27:49 +01001674/*
Steve Longerbeam7b043892007-05-03 20:50:03 +02001675 * Fill in the dac_nids table from the parsed pin configuration
1676 * This function only works when every pin in line_out_pins[]
1677 * contains atleast one DAC in its connection list. Some 92xx
1678 * codecs are not connected directly to a DAC, such as the 9200
1679 * and 9202/925x. For those, dac_nids[] must be hard-coded.
Matt Porter3cc08dc2006-01-23 15:27:49 +01001680 */
Takashi Iwai19039bd2006-06-28 15:52:16 +02001681static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec,
Takashi Iwaidf802952007-07-02 19:18:00 +02001682 struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02001683{
1684 struct sigmatel_spec *spec = codec->spec;
Steve Longerbeam7b043892007-05-03 20:50:03 +02001685 int i, j, conn_len = 0;
1686 hda_nid_t nid, conn[HDA_MAX_CONNECTIONS];
1687 unsigned int wcaps, wtype;
1688
Mattc7d4b2f2005-06-27 14:59:41 +02001689 for (i = 0; i < cfg->line_outs; i++) {
1690 nid = cfg->line_out_pins[i];
Steve Longerbeam7b043892007-05-03 20:50:03 +02001691 conn_len = snd_hda_get_connections(codec, nid, conn,
1692 HDA_MAX_CONNECTIONS);
1693 for (j = 0; j < conn_len; j++) {
1694 wcaps = snd_hda_param_read(codec, conn[j],
1695 AC_PAR_AUDIO_WIDGET_CAP);
1696 wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
1697
1698 if (wtype != AC_WID_AUD_OUT ||
1699 (wcaps & AC_WCAP_DIGITAL))
1700 continue;
1701 /* conn[j] is a DAC routed to this line-out */
1702 if (!is_in_dac_nids(spec, conn[j]))
1703 break;
1704 }
1705
1706 if (j == conn_len) {
Takashi Iwaidf802952007-07-02 19:18:00 +02001707 if (spec->multiout.num_dacs > 0) {
1708 /* we have already working output pins,
1709 * so let's drop the broken ones again
1710 */
1711 cfg->line_outs = spec->multiout.num_dacs;
1712 break;
1713 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02001714 /* error out, no available DAC found */
1715 snd_printk(KERN_ERR
1716 "%s: No available DAC for pin 0x%x\n",
1717 __func__, nid);
1718 return -ENODEV;
1719 }
1720
1721 spec->multiout.dac_nids[i] = conn[j];
1722 spec->multiout.num_dacs++;
1723 if (conn_len > 1) {
1724 /* select this DAC in the pin's input mux */
Takashi Iwai82beb8f2007-08-10 17:09:26 +02001725 snd_hda_codec_write_cache(codec, nid, 0,
1726 AC_VERB_SET_CONNECT_SEL, j);
Steve Longerbeam7b043892007-05-03 20:50:03 +02001727
1728 }
Mattc7d4b2f2005-06-27 14:59:41 +02001729 }
1730
Steve Longerbeam7b043892007-05-03 20:50:03 +02001731 snd_printd("dac_nids=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
1732 spec->multiout.num_dacs,
1733 spec->multiout.dac_nids[0],
1734 spec->multiout.dac_nids[1],
1735 spec->multiout.dac_nids[2],
1736 spec->multiout.dac_nids[3],
1737 spec->multiout.dac_nids[4]);
Mattc7d4b2f2005-06-27 14:59:41 +02001738 return 0;
1739}
1740
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001741/* create volume control/switch for the given prefx type */
1742static int create_controls(struct sigmatel_spec *spec, const char *pfx, hda_nid_t nid, int chs)
1743{
1744 char name[32];
1745 int err;
1746
1747 sprintf(name, "%s Playback Volume", pfx);
1748 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, name,
1749 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1750 if (err < 0)
1751 return err;
1752 sprintf(name, "%s Playback Switch", pfx);
1753 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, name,
1754 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1755 if (err < 0)
1756 return err;
1757 return 0;
1758}
1759
Mattc7d4b2f2005-06-27 14:59:41 +02001760/* add playback controls from the parsed DAC table */
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02001761static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
Takashi Iwai19039bd2006-06-28 15:52:16 +02001762 const struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02001763{
Takashi Iwai19039bd2006-06-28 15:52:16 +02001764 static const char *chname[4] = {
1765 "Front", "Surround", NULL /*CLFE*/, "Side"
1766 };
Mattc7d4b2f2005-06-27 14:59:41 +02001767 hda_nid_t nid;
1768 int i, err;
1769
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02001770 struct sigmatel_spec *spec = codec->spec;
1771 unsigned int wid_caps;
1772
1773
Mattc7d4b2f2005-06-27 14:59:41 +02001774 for (i = 0; i < cfg->line_outs; i++) {
Matt Porter403d1942005-11-29 15:00:51 +01001775 if (!spec->multiout.dac_nids[i])
Mattc7d4b2f2005-06-27 14:59:41 +02001776 continue;
1777
1778 nid = spec->multiout.dac_nids[i];
1779
1780 if (i == 2) {
1781 /* Center/LFE */
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001782 err = create_controls(spec, "Center", nid, 1);
1783 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001784 return err;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001785 err = create_controls(spec, "LFE", nid, 2);
1786 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001787 return err;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02001788
1789 wid_caps = get_wcaps(codec, nid);
1790
1791 if (wid_caps & AC_WCAP_LR_SWAP) {
1792 err = stac92xx_add_control(spec,
1793 STAC_CTL_WIDGET_CLFE_SWITCH,
1794 "Swap Center/LFE Playback Switch", nid);
1795
1796 if (err < 0)
1797 return err;
1798 }
1799
Mattc7d4b2f2005-06-27 14:59:41 +02001800 } else {
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001801 err = create_controls(spec, chname[i], nid, 3);
1802 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001803 return err;
1804 }
1805 }
1806
Matt Porter403d1942005-11-29 15:00:51 +01001807 if (spec->line_switch)
1808 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Line In as Output Switch", cfg->input_pins[AUTO_PIN_LINE] << 8)) < 0)
1809 return err;
1810
1811 if (spec->mic_switch)
1812 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Mic as Output Switch", (cfg->input_pins[AUTO_PIN_MIC] << 8) | 1)) < 0)
1813 return err;
1814
Mattc7d4b2f2005-06-27 14:59:41 +02001815 return 0;
1816}
1817
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001818static int check_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
1819{
Steve Longerbeam7b043892007-05-03 20:50:03 +02001820 if (is_in_dac_nids(spec, nid))
1821 return 1;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001822 if (spec->multiout.hp_nid == nid)
1823 return 1;
1824 return 0;
1825}
1826
1827static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
1828{
1829 if (!spec->multiout.hp_nid)
1830 spec->multiout.hp_nid = nid;
1831 else if (spec->multiout.num_dacs > 4) {
1832 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
1833 return 1;
1834 } else {
1835 spec->multiout.dac_nids[spec->multiout.num_dacs] = nid;
1836 spec->multiout.num_dacs++;
1837 }
1838 return 0;
1839}
1840
1841/* add playback controls for Speaker and HP outputs */
1842static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
1843 struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02001844{
1845 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02001846 hda_nid_t nid;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001847 int i, old_num_dacs, err;
Mattc7d4b2f2005-06-27 14:59:41 +02001848
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001849 old_num_dacs = spec->multiout.num_dacs;
1850 for (i = 0; i < cfg->hp_outs; i++) {
1851 unsigned int wid_caps = get_wcaps(codec, cfg->hp_pins[i]);
1852 if (wid_caps & AC_WCAP_UNSOL_CAP)
1853 spec->hp_detect = 1;
1854 nid = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
1855 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
1856 if (check_in_dac_nids(spec, nid))
1857 nid = 0;
1858 if (! nid)
Mattc7d4b2f2005-06-27 14:59:41 +02001859 continue;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001860 add_spec_dacs(spec, nid);
1861 }
1862 for (i = 0; i < cfg->speaker_outs; i++) {
Steve Longerbeam7b043892007-05-03 20:50:03 +02001863 nid = snd_hda_codec_read(codec, cfg->speaker_pins[i], 0,
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001864 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
1865 if (check_in_dac_nids(spec, nid))
1866 nid = 0;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001867 if (! nid)
1868 continue;
1869 add_spec_dacs(spec, nid);
Mattc7d4b2f2005-06-27 14:59:41 +02001870 }
Matthew Ranostay1b290a52007-07-12 15:17:34 +02001871 for (i = 0; i < cfg->line_outs; i++) {
1872 nid = snd_hda_codec_read(codec, cfg->line_out_pins[i], 0,
1873 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
1874 if (check_in_dac_nids(spec, nid))
1875 nid = 0;
1876 if (! nid)
1877 continue;
1878 add_spec_dacs(spec, nid);
1879 }
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001880 for (i = old_num_dacs; i < spec->multiout.num_dacs; i++) {
1881 static const char *pfxs[] = {
1882 "Speaker", "External Speaker", "Speaker2",
1883 };
1884 err = create_controls(spec, pfxs[i - old_num_dacs],
1885 spec->multiout.dac_nids[i], 3);
1886 if (err < 0)
1887 return err;
1888 }
1889 if (spec->multiout.hp_nid) {
1890 const char *pfx;
Takashi Iwai6020c002007-11-19 11:56:26 +01001891 if (old_num_dacs == spec->multiout.num_dacs)
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001892 pfx = "Master";
1893 else
1894 pfx = "Headphone";
1895 err = create_controls(spec, pfx, spec->multiout.hp_nid, 3);
1896 if (err < 0)
1897 return err;
1898 }
Mattc7d4b2f2005-06-27 14:59:41 +02001899
1900 return 0;
1901}
1902
Matt Porter8b657272006-10-26 17:12:59 +02001903/* labels for dmic mux inputs */
Adrian Bunkddc2cec2006-11-20 12:03:44 +01001904static const char *stac92xx_dmic_labels[5] = {
Matt Porter8b657272006-10-26 17:12:59 +02001905 "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
1906 "Digital Mic 3", "Digital Mic 4"
1907};
1908
1909/* create playback/capture controls for input pins on dmic capable codecs */
1910static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
1911 const struct auto_pin_cfg *cfg)
1912{
1913 struct sigmatel_spec *spec = codec->spec;
1914 struct hda_input_mux *dimux = &spec->private_dimux;
1915 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
1916 int i, j;
1917
1918 dimux->items[dimux->num_items].label = stac92xx_dmic_labels[0];
1919 dimux->items[dimux->num_items].index = 0;
1920 dimux->num_items++;
1921
1922 for (i = 0; i < spec->num_dmics; i++) {
1923 int index;
1924 int num_cons;
1925 unsigned int def_conf;
1926
1927 def_conf = snd_hda_codec_read(codec,
1928 spec->dmic_nids[i],
1929 0,
1930 AC_VERB_GET_CONFIG_DEFAULT,
1931 0);
1932 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
1933 continue;
1934
1935 num_cons = snd_hda_get_connections(codec,
1936 spec->dmux_nid,
1937 con_lst,
1938 HDA_MAX_NUM_INPUTS);
1939 for (j = 0; j < num_cons; j++)
1940 if (con_lst[j] == spec->dmic_nids[i]) {
1941 index = j;
1942 goto found;
1943 }
1944 continue;
1945found:
1946 dimux->items[dimux->num_items].label =
1947 stac92xx_dmic_labels[dimux->num_items];
1948 dimux->items[dimux->num_items].index = index;
1949 dimux->num_items++;
1950 }
1951
1952 return 0;
1953}
1954
Mattc7d4b2f2005-06-27 14:59:41 +02001955/* create playback/capture controls for input pins */
1956static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
1957{
1958 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02001959 struct hda_input_mux *imux = &spec->private_imux;
1960 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
1961 int i, j, k;
1962
1963 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwai314634b2006-09-21 11:56:18 +02001964 int index;
Mattc7d4b2f2005-06-27 14:59:41 +02001965
Takashi Iwai314634b2006-09-21 11:56:18 +02001966 if (!cfg->input_pins[i])
1967 continue;
1968 index = -1;
1969 for (j = 0; j < spec->num_muxes; j++) {
1970 int num_cons;
1971 num_cons = snd_hda_get_connections(codec,
1972 spec->mux_nids[j],
1973 con_lst,
1974 HDA_MAX_NUM_INPUTS);
1975 for (k = 0; k < num_cons; k++)
1976 if (con_lst[k] == cfg->input_pins[i]) {
1977 index = k;
1978 goto found;
1979 }
Mattc7d4b2f2005-06-27 14:59:41 +02001980 }
Takashi Iwai314634b2006-09-21 11:56:18 +02001981 continue;
1982 found:
1983 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
1984 imux->items[imux->num_items].index = index;
1985 imux->num_items++;
Mattc7d4b2f2005-06-27 14:59:41 +02001986 }
1987
Steve Longerbeam7b043892007-05-03 20:50:03 +02001988 if (imux->num_items) {
Sam Revitch62fe78e2006-05-10 15:09:17 +02001989 /*
1990 * Set the current input for the muxes.
1991 * The STAC9221 has two input muxes with identical source
1992 * NID lists. Hopefully this won't get confused.
1993 */
1994 for (i = 0; i < spec->num_muxes; i++) {
Takashi Iwai82beb8f2007-08-10 17:09:26 +02001995 snd_hda_codec_write_cache(codec, spec->mux_nids[i], 0,
1996 AC_VERB_SET_CONNECT_SEL,
1997 imux->items[0].index);
Sam Revitch62fe78e2006-05-10 15:09:17 +02001998 }
1999 }
2000
Mattc7d4b2f2005-06-27 14:59:41 +02002001 return 0;
2002}
2003
Mattc7d4b2f2005-06-27 14:59:41 +02002004static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
2005{
2006 struct sigmatel_spec *spec = codec->spec;
2007 int i;
2008
2009 for (i = 0; i < spec->autocfg.line_outs; i++) {
2010 hda_nid_t nid = spec->autocfg.line_out_pins[i];
2011 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
2012 }
2013}
2014
2015static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
2016{
2017 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002018 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02002019
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002020 for (i = 0; i < spec->autocfg.hp_outs; i++) {
2021 hda_nid_t pin;
2022 pin = spec->autocfg.hp_pins[i];
2023 if (pin) /* connect to front */
2024 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
2025 }
2026 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
2027 hda_nid_t pin;
2028 pin = spec->autocfg.speaker_pins[i];
2029 if (pin) /* connect to front */
2030 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
2031 }
Mattc7d4b2f2005-06-27 14:59:41 +02002032}
2033
Matt Porter3cc08dc2006-01-23 15:27:49 +01002034static 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 +02002035{
2036 struct sigmatel_spec *spec = codec->spec;
2037 int err;
2038
Matt Porter8b657272006-10-26 17:12:59 +02002039 if ((err = snd_hda_parse_pin_def_config(codec,
2040 &spec->autocfg,
2041 spec->dmic_nids)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02002042 return err;
Takashi Iwai82bc9552006-03-21 11:24:42 +01002043 if (! spec->autocfg.line_outs)
Matt Porter869264c2006-01-25 19:20:50 +01002044 return 0; /* can't find valid pin config */
Takashi Iwai19039bd2006-06-28 15:52:16 +02002045
Matt Porter403d1942005-11-29 15:00:51 +01002046 if ((err = stac92xx_add_dyn_out_pins(codec, &spec->autocfg)) < 0)
2047 return err;
Takashi Iwai19039bd2006-06-28 15:52:16 +02002048 if (spec->multiout.num_dacs == 0)
2049 if ((err = stac92xx_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
2050 return err;
Mattc7d4b2f2005-06-27 14:59:41 +02002051
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002052 err = stac92xx_auto_create_multi_out_ctls(codec, &spec->autocfg);
2053
2054 if (err < 0)
2055 return err;
2056
2057 err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg);
2058
2059 if (err < 0)
2060 return err;
2061
2062 err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg);
2063
2064 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02002065 return err;
2066
Matt Porter8b657272006-10-26 17:12:59 +02002067 if (spec->num_dmics > 0)
2068 if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
2069 &spec->autocfg)) < 0)
2070 return err;
2071
Mattc7d4b2f2005-06-27 14:59:41 +02002072 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Matt Porter403d1942005-11-29 15:00:51 +01002073 if (spec->multiout.max_channels > 2)
Mattc7d4b2f2005-06-27 14:59:41 +02002074 spec->surr_switch = 1;
Mattc7d4b2f2005-06-27 14:59:41 +02002075
Takashi Iwai82bc9552006-03-21 11:24:42 +01002076 if (spec->autocfg.dig_out_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01002077 spec->multiout.dig_out_nid = dig_out;
Takashi Iwai82bc9552006-03-21 11:24:42 +01002078 if (spec->autocfg.dig_in_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01002079 spec->dig_in_nid = dig_in;
Mattc7d4b2f2005-06-27 14:59:41 +02002080
2081 if (spec->kctl_alloc)
2082 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
2083
2084 spec->input_mux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02002085 spec->dinput_mux = &spec->private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +02002086
2087 return 1;
2088}
2089
Takashi Iwai82bc9552006-03-21 11:24:42 +01002090/* add playback controls for HP output */
2091static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
2092 struct auto_pin_cfg *cfg)
2093{
2094 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002095 hda_nid_t pin = cfg->hp_pins[0];
Takashi Iwai82bc9552006-03-21 11:24:42 +01002096 unsigned int wid_caps;
2097
2098 if (! pin)
2099 return 0;
2100
2101 wid_caps = get_wcaps(codec, pin);
Takashi Iwai505cb342006-03-27 12:51:52 +02002102 if (wid_caps & AC_WCAP_UNSOL_CAP)
Takashi Iwai82bc9552006-03-21 11:24:42 +01002103 spec->hp_detect = 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +01002104
2105 return 0;
2106}
2107
Richard Fish160ea0d2006-09-06 13:58:25 +02002108/* add playback controls for LFE output */
2109static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
2110 struct auto_pin_cfg *cfg)
2111{
2112 struct sigmatel_spec *spec = codec->spec;
2113 int err;
2114 hda_nid_t lfe_pin = 0x0;
2115 int i;
2116
2117 /*
2118 * search speaker outs and line outs for a mono speaker pin
2119 * with an amp. If one is found, add LFE controls
2120 * for it.
2121 */
2122 for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
2123 hda_nid_t pin = spec->autocfg.speaker_pins[i];
2124 unsigned long wcaps = get_wcaps(codec, pin);
2125 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
2126 if (wcaps == AC_WCAP_OUT_AMP)
2127 /* found a mono speaker with an amp, must be lfe */
2128 lfe_pin = pin;
2129 }
2130
2131 /* if speaker_outs is 0, then speakers may be in line_outs */
2132 if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
2133 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
2134 hda_nid_t pin = spec->autocfg.line_out_pins[i];
2135 unsigned long cfg;
2136 cfg = snd_hda_codec_read(codec, pin, 0,
2137 AC_VERB_GET_CONFIG_DEFAULT,
2138 0x00);
2139 if (get_defcfg_device(cfg) == AC_JACK_SPEAKER) {
2140 unsigned long wcaps = get_wcaps(codec, pin);
2141 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
2142 if (wcaps == AC_WCAP_OUT_AMP)
2143 /* found a mono speaker with an amp,
2144 must be lfe */
2145 lfe_pin = pin;
2146 }
2147 }
2148 }
2149
2150 if (lfe_pin) {
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002151 err = create_controls(spec, "LFE", lfe_pin, 1);
Richard Fish160ea0d2006-09-06 13:58:25 +02002152 if (err < 0)
2153 return err;
2154 }
2155
2156 return 0;
2157}
2158
Mattc7d4b2f2005-06-27 14:59:41 +02002159static int stac9200_parse_auto_config(struct hda_codec *codec)
2160{
2161 struct sigmatel_spec *spec = codec->spec;
2162 int err;
2163
Kailang Yangdf694da2005-12-05 19:42:22 +01002164 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02002165 return err;
2166
2167 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
2168 return err;
2169
Takashi Iwai82bc9552006-03-21 11:24:42 +01002170 if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
2171 return err;
2172
Richard Fish160ea0d2006-09-06 13:58:25 +02002173 if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
2174 return err;
2175
Takashi Iwai82bc9552006-03-21 11:24:42 +01002176 if (spec->autocfg.dig_out_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02002177 spec->multiout.dig_out_nid = 0x05;
Takashi Iwai82bc9552006-03-21 11:24:42 +01002178 if (spec->autocfg.dig_in_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02002179 spec->dig_in_nid = 0x04;
Mattc7d4b2f2005-06-27 14:59:41 +02002180
2181 if (spec->kctl_alloc)
2182 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
2183
2184 spec->input_mux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02002185 spec->dinput_mux = &spec->private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +02002186
2187 return 1;
2188}
2189
Sam Revitch62fe78e2006-05-10 15:09:17 +02002190/*
2191 * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
2192 * funky external mute control using GPIO pins.
2193 */
2194
2195static void stac922x_gpio_mute(struct hda_codec *codec, int pin, int muted)
2196{
2197 unsigned int gpiostate, gpiomask, gpiodir;
2198
2199 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
2200 AC_VERB_GET_GPIO_DATA, 0);
2201
2202 if (!muted)
2203 gpiostate |= (1 << pin);
2204 else
2205 gpiostate &= ~(1 << pin);
2206
2207 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
2208 AC_VERB_GET_GPIO_MASK, 0);
2209 gpiomask |= (1 << pin);
2210
2211 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
2212 AC_VERB_GET_GPIO_DIRECTION, 0);
2213 gpiodir |= (1 << pin);
2214
2215 /* AppleHDA seems to do this -- WTF is this verb?? */
2216 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
2217
2218 snd_hda_codec_write(codec, codec->afg, 0,
2219 AC_VERB_SET_GPIO_MASK, gpiomask);
2220 snd_hda_codec_write(codec, codec->afg, 0,
2221 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
2222
2223 msleep(1);
2224
2225 snd_hda_codec_write(codec, codec->afg, 0,
2226 AC_VERB_SET_GPIO_DATA, gpiostate);
2227}
2228
Takashi Iwai314634b2006-09-21 11:56:18 +02002229static void enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
2230 unsigned int event)
2231{
2232 if (get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP)
Takashi Iwaidc81bed2007-09-03 09:36:36 +02002233 snd_hda_codec_write_cache(codec, nid, 0,
2234 AC_VERB_SET_UNSOLICITED_ENABLE,
2235 (AC_USRSP_EN | event));
Takashi Iwai314634b2006-09-21 11:56:18 +02002236}
2237
Mattc7d4b2f2005-06-27 14:59:41 +02002238static int stac92xx_init(struct hda_codec *codec)
2239{
2240 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai82bc9552006-03-21 11:24:42 +01002241 struct auto_pin_cfg *cfg = &spec->autocfg;
2242 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02002243
Mattc7d4b2f2005-06-27 14:59:41 +02002244 snd_hda_sequence_write(codec, spec->init);
2245
Takashi Iwai82bc9552006-03-21 11:24:42 +01002246 /* set up pins */
2247 if (spec->hp_detect) {
Takashi Iwai505cb342006-03-27 12:51:52 +02002248 /* Enable unsolicited responses on the HP widget */
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002249 for (i = 0; i < cfg->hp_outs; i++)
Takashi Iwai314634b2006-09-21 11:56:18 +02002250 enable_pin_detect(codec, cfg->hp_pins[i],
2251 STAC_HP_EVENT);
Takashi Iwai0a07aca2007-03-13 10:40:23 +01002252 /* force to enable the first line-out; the others are set up
2253 * in unsol_event
2254 */
2255 stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
2256 AC_PINCTL_OUT_EN);
Takashi Iwaieb995a82006-09-21 14:28:21 +02002257 stac92xx_auto_init_hp_out(codec);
Takashi Iwai82bc9552006-03-21 11:24:42 +01002258 /* fake event to set up pins */
2259 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
2260 } else {
2261 stac92xx_auto_init_multi_out(codec);
2262 stac92xx_auto_init_hp_out(codec);
2263 }
2264 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwaic960a032006-03-23 17:06:28 +01002265 hda_nid_t nid = cfg->input_pins[i];
2266 if (nid) {
2267 unsigned int pinctl = AC_PINCTL_IN_EN;
2268 if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC)
2269 pinctl |= stac92xx_get_vref(codec, nid);
2270 stac92xx_auto_set_pinctl(codec, nid, pinctl);
2271 }
Takashi Iwai82bc9552006-03-21 11:24:42 +01002272 }
Matt Porter8b657272006-10-26 17:12:59 +02002273 if (spec->num_dmics > 0)
2274 for (i = 0; i < spec->num_dmics; i++)
2275 stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
2276 AC_PINCTL_IN_EN);
2277
Takashi Iwai82bc9552006-03-21 11:24:42 +01002278 if (cfg->dig_out_pin)
2279 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pin,
2280 AC_PINCTL_OUT_EN);
2281 if (cfg->dig_in_pin)
2282 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
2283 AC_PINCTL_IN_EN);
2284
Sam Revitch62fe78e2006-05-10 15:09:17 +02002285 if (spec->gpio_mute) {
2286 stac922x_gpio_mute(codec, 0, 0);
2287 stac922x_gpio_mute(codec, 1, 0);
2288 }
2289
Mattc7d4b2f2005-06-27 14:59:41 +02002290 return 0;
2291}
2292
Matt2f2f4252005-04-13 14:45:30 +02002293static void stac92xx_free(struct hda_codec *codec)
2294{
Mattc7d4b2f2005-06-27 14:59:41 +02002295 struct sigmatel_spec *spec = codec->spec;
2296 int i;
2297
2298 if (! spec)
2299 return;
2300
2301 if (spec->kctl_alloc) {
2302 for (i = 0; i < spec->num_kctl_used; i++)
2303 kfree(spec->kctl_alloc[i].name);
2304 kfree(spec->kctl_alloc);
2305 }
2306
Richard Fish11b44bb2006-08-23 18:31:34 +02002307 if (spec->bios_pin_configs)
2308 kfree(spec->bios_pin_configs);
2309
Mattc7d4b2f2005-06-27 14:59:41 +02002310 kfree(spec);
Matt2f2f4252005-04-13 14:45:30 +02002311}
2312
Matt4e550962005-07-04 17:51:39 +02002313static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
2314 unsigned int flag)
2315{
2316 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
2317 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Steve Longerbeam7b043892007-05-03 20:50:03 +02002318
Takashi Iwaif9acba42007-05-29 18:01:06 +02002319 if (pin_ctl & AC_PINCTL_IN_EN) {
2320 /*
2321 * we need to check the current set-up direction of
2322 * shared input pins since they can be switched via
2323 * "xxx as Output" mixer switch
2324 */
2325 struct sigmatel_spec *spec = codec->spec;
2326 struct auto_pin_cfg *cfg = &spec->autocfg;
2327 if ((nid == cfg->input_pins[AUTO_PIN_LINE] &&
2328 spec->line_switch) ||
2329 (nid == cfg->input_pins[AUTO_PIN_MIC] &&
2330 spec->mic_switch))
2331 return;
2332 }
2333
Steve Longerbeam7b043892007-05-03 20:50:03 +02002334 /* if setting pin direction bits, clear the current
2335 direction bits first */
2336 if (flag & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))
2337 pin_ctl &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
2338
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002339 snd_hda_codec_write_cache(codec, nid, 0,
Matt4e550962005-07-04 17:51:39 +02002340 AC_VERB_SET_PIN_WIDGET_CONTROL,
2341 pin_ctl | flag);
2342}
2343
2344static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
2345 unsigned int flag)
2346{
2347 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
2348 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002349 snd_hda_codec_write_cache(codec, nid, 0,
Matt4e550962005-07-04 17:51:39 +02002350 AC_VERB_SET_PIN_WIDGET_CONTROL,
2351 pin_ctl & ~flag);
2352}
2353
Takashi Iwai314634b2006-09-21 11:56:18 +02002354static int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
2355{
2356 if (!nid)
2357 return 0;
2358 if (snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PIN_SENSE, 0x00)
2359 & (1 << 31))
2360 return 1;
2361 return 0;
2362}
2363
2364static void stac92xx_hp_detect(struct hda_codec *codec, unsigned int res)
Matt4e550962005-07-04 17:51:39 +02002365{
2366 struct sigmatel_spec *spec = codec->spec;
2367 struct auto_pin_cfg *cfg = &spec->autocfg;
2368 int i, presence;
2369
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002370 presence = 0;
2371 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai314634b2006-09-21 11:56:18 +02002372 presence = get_pin_presence(codec, cfg->hp_pins[i]);
2373 if (presence)
2374 break;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002375 }
Matt4e550962005-07-04 17:51:39 +02002376
2377 if (presence) {
2378 /* disable lineouts, enable hp */
2379 for (i = 0; i < cfg->line_outs; i++)
2380 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
2381 AC_PINCTL_OUT_EN);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002382 for (i = 0; i < cfg->speaker_outs; i++)
2383 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
2384 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02002385 } else {
2386 /* enable lineouts, disable hp */
2387 for (i = 0; i < cfg->line_outs; i++)
2388 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
2389 AC_PINCTL_OUT_EN);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002390 for (i = 0; i < cfg->speaker_outs; i++)
2391 stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
2392 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02002393 }
2394}
2395
Takashi Iwai314634b2006-09-21 11:56:18 +02002396static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
2397{
2398 switch (res >> 26) {
2399 case STAC_HP_EVENT:
2400 stac92xx_hp_detect(codec, res);
2401 break;
2402 }
2403}
2404
Takashi Iwaicb53c622007-08-10 17:21:45 +02002405#ifdef SND_HDA_NEEDS_RESUME
Mattff6fdc32005-06-27 15:06:52 +02002406static int stac92xx_resume(struct hda_codec *codec)
2407{
Takashi Iwaidc81bed2007-09-03 09:36:36 +02002408 struct sigmatel_spec *spec = codec->spec;
2409
Richard Fish11b44bb2006-08-23 18:31:34 +02002410 stac92xx_set_config_regs(codec);
Takashi Iwaidc81bed2007-09-03 09:36:36 +02002411 snd_hda_sequence_write(codec, spec->init);
2412 if (spec->gpio_mute) {
2413 stac922x_gpio_mute(codec, 0, 0);
2414 stac922x_gpio_mute(codec, 1, 0);
2415 }
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002416 snd_hda_codec_resume_amp(codec);
2417 snd_hda_codec_resume_cache(codec);
Takashi Iwaidc81bed2007-09-03 09:36:36 +02002418 /* invoke unsolicited event to reset the HP state */
2419 if (spec->hp_detect)
2420 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
Mattff6fdc32005-06-27 15:06:52 +02002421 return 0;
2422}
2423#endif
2424
Matt2f2f4252005-04-13 14:45:30 +02002425static struct hda_codec_ops stac92xx_patch_ops = {
2426 .build_controls = stac92xx_build_controls,
2427 .build_pcms = stac92xx_build_pcms,
2428 .init = stac92xx_init,
2429 .free = stac92xx_free,
Matt4e550962005-07-04 17:51:39 +02002430 .unsol_event = stac92xx_unsol_event,
Takashi Iwaicb53c622007-08-10 17:21:45 +02002431#ifdef SND_HDA_NEEDS_RESUME
Mattff6fdc32005-06-27 15:06:52 +02002432 .resume = stac92xx_resume,
2433#endif
Matt2f2f4252005-04-13 14:45:30 +02002434};
2435
2436static int patch_stac9200(struct hda_codec *codec)
2437{
2438 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02002439 int err;
Matt2f2f4252005-04-13 14:45:30 +02002440
Takashi Iwaie560d8d2005-09-09 14:21:46 +02002441 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02002442 if (spec == NULL)
2443 return -ENOMEM;
2444
2445 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02002446 spec->num_pins = ARRAY_SIZE(stac9200_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02002447 spec->pin_nids = stac9200_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002448 spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS,
2449 stac9200_models,
2450 stac9200_cfg_tbl);
Richard Fish11b44bb2006-08-23 18:31:34 +02002451 if (spec->board_config < 0) {
2452 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9200, using BIOS defaults\n");
2453 err = stac92xx_save_bios_config_regs(codec);
2454 if (err < 0) {
2455 stac92xx_free(codec);
2456 return err;
2457 }
2458 spec->pin_configs = spec->bios_pin_configs;
2459 } else {
Matt Porter403d1942005-11-29 15:00:51 +01002460 spec->pin_configs = stac9200_brd_tbl[spec->board_config];
2461 stac92xx_set_config_regs(codec);
2462 }
Matt2f2f4252005-04-13 14:45:30 +02002463
2464 spec->multiout.max_channels = 2;
2465 spec->multiout.num_dacs = 1;
2466 spec->multiout.dac_nids = stac9200_dac_nids;
2467 spec->adc_nids = stac9200_adc_nids;
2468 spec->mux_nids = stac9200_mux_nids;
Mattdabbed62005-06-14 10:19:34 +02002469 spec->num_muxes = 1;
Matt Porter8b657272006-10-26 17:12:59 +02002470 spec->num_dmics = 0;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002471 spec->num_adcs = 1;
Mattc7d4b2f2005-06-27 14:59:41 +02002472
Takashi Iwai1194b5b2007-10-10 10:04:26 +02002473 if (spec->board_config == STAC_9200_GATEWAY)
2474 spec->init = stac9200_eapd_init;
2475 else
2476 spec->init = stac9200_core_init;
Matt2f2f4252005-04-13 14:45:30 +02002477 spec->mixer = stac9200_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02002478
2479 err = stac9200_parse_auto_config(codec);
2480 if (err < 0) {
2481 stac92xx_free(codec);
2482 return err;
2483 }
Matt2f2f4252005-04-13 14:45:30 +02002484
2485 codec->patch_ops = stac92xx_patch_ops;
2486
2487 return 0;
2488}
2489
Tobin Davis8e21c342007-01-08 11:04:17 +01002490static int patch_stac925x(struct hda_codec *codec)
2491{
2492 struct sigmatel_spec *spec;
2493 int err;
2494
2495 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2496 if (spec == NULL)
2497 return -ENOMEM;
2498
2499 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02002500 spec->num_pins = ARRAY_SIZE(stac925x_pin_nids);
Tobin Davis8e21c342007-01-08 11:04:17 +01002501 spec->pin_nids = stac925x_pin_nids;
2502 spec->board_config = snd_hda_check_board_config(codec, STAC_925x_MODELS,
2503 stac925x_models,
2504 stac925x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002505 again:
Tobin Davis8e21c342007-01-08 11:04:17 +01002506 if (spec->board_config < 0) {
Tobin Davis2c11f952007-05-17 09:36:34 +02002507 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC925x,"
2508 "using BIOS defaults\n");
Tobin Davis8e21c342007-01-08 11:04:17 +01002509 err = stac92xx_save_bios_config_regs(codec);
2510 if (err < 0) {
2511 stac92xx_free(codec);
2512 return err;
2513 }
2514 spec->pin_configs = spec->bios_pin_configs;
2515 } else if (stac925x_brd_tbl[spec->board_config] != NULL){
2516 spec->pin_configs = stac925x_brd_tbl[spec->board_config];
2517 stac92xx_set_config_regs(codec);
2518 }
2519
2520 spec->multiout.max_channels = 2;
2521 spec->multiout.num_dacs = 1;
2522 spec->multiout.dac_nids = stac925x_dac_nids;
2523 spec->adc_nids = stac925x_adc_nids;
2524 spec->mux_nids = stac925x_mux_nids;
2525 spec->num_muxes = 1;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002526 spec->num_adcs = 1;
Tobin Davis2c11f952007-05-17 09:36:34 +02002527 switch (codec->vendor_id) {
2528 case 0x83847632: /* STAC9202 */
2529 case 0x83847633: /* STAC9202D */
2530 case 0x83847636: /* STAC9251 */
2531 case 0x83847637: /* STAC9251D */
Takashi Iwaif6e98522007-10-16 14:27:04 +02002532 spec->num_dmics = STAC925X_NUM_DMICS;
Tobin Davis2c11f952007-05-17 09:36:34 +02002533 spec->dmic_nids = stac925x_dmic_nids;
2534 break;
2535 default:
2536 spec->num_dmics = 0;
2537 break;
2538 }
Tobin Davis8e21c342007-01-08 11:04:17 +01002539
2540 spec->init = stac925x_core_init;
2541 spec->mixer = stac925x_mixer;
2542
2543 err = stac92xx_parse_auto_config(codec, 0x8, 0x7);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002544 if (!err) {
2545 if (spec->board_config < 0) {
2546 printk(KERN_WARNING "hda_codec: No auto-config is "
2547 "available, default to model=ref\n");
2548 spec->board_config = STAC_925x_REF;
2549 goto again;
2550 }
2551 err = -EINVAL;
2552 }
Tobin Davis8e21c342007-01-08 11:04:17 +01002553 if (err < 0) {
2554 stac92xx_free(codec);
2555 return err;
2556 }
2557
2558 codec->patch_ops = stac92xx_patch_ops;
2559
2560 return 0;
2561}
2562
Matt2f2f4252005-04-13 14:45:30 +02002563static int patch_stac922x(struct hda_codec *codec)
2564{
2565 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02002566 int err;
Matt2f2f4252005-04-13 14:45:30 +02002567
Takashi Iwaie560d8d2005-09-09 14:21:46 +02002568 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02002569 if (spec == NULL)
2570 return -ENOMEM;
2571
2572 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02002573 spec->num_pins = ARRAY_SIZE(stac922x_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02002574 spec->pin_nids = stac922x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002575 spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS,
2576 stac922x_models,
2577 stac922x_cfg_tbl);
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002578 if (spec->board_config == STAC_INTEL_MAC_V3) {
Takashi Iwai3fc24d82007-02-16 13:27:18 +01002579 spec->gpio_mute = 1;
2580 /* Intel Macs have all same PCI SSID, so we need to check
2581 * codec SSID to distinguish the exact models
2582 */
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01002583 printk(KERN_INFO "hda_codec: STAC922x, Apple subsys_id=%x\n", codec->subsystem_id);
Takashi Iwai3fc24d82007-02-16 13:27:18 +01002584 switch (codec->subsystem_id) {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002585
2586 case 0x106b0800:
2587 spec->board_config = STAC_INTEL_MAC_V1;
Abhijit Bhopatkarc45e20e2007-04-17 11:57:16 +02002588 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002589 case 0x106b0600:
2590 case 0x106b0700:
2591 spec->board_config = STAC_INTEL_MAC_V2;
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01002592 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002593 case 0x106b0e00:
2594 case 0x106b0f00:
2595 case 0x106b1600:
2596 case 0x106b1700:
2597 case 0x106b0200:
2598 case 0x106b1e00:
2599 spec->board_config = STAC_INTEL_MAC_V3;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01002600 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002601 case 0x106b1a00:
2602 case 0x00000100:
2603 spec->board_config = STAC_INTEL_MAC_V4;
Sylvain FORETf16928f2007-04-27 14:22:36 +02002604 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002605 case 0x106b0a00:
2606 case 0x106b2200:
2607 spec->board_config = STAC_INTEL_MAC_V5;
Takashi Iwai0dae0f82007-05-21 12:41:29 +02002608 break;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01002609 }
2610 }
2611
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002612 again:
Richard Fish11b44bb2006-08-23 18:31:34 +02002613 if (spec->board_config < 0) {
2614 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC922x, "
2615 "using BIOS defaults\n");
2616 err = stac92xx_save_bios_config_regs(codec);
2617 if (err < 0) {
2618 stac92xx_free(codec);
2619 return err;
2620 }
2621 spec->pin_configs = spec->bios_pin_configs;
2622 } else if (stac922x_brd_tbl[spec->board_config] != NULL) {
Matt Porter403d1942005-11-29 15:00:51 +01002623 spec->pin_configs = stac922x_brd_tbl[spec->board_config];
2624 stac92xx_set_config_regs(codec);
2625 }
Matt2f2f4252005-04-13 14:45:30 +02002626
Matt2f2f4252005-04-13 14:45:30 +02002627 spec->adc_nids = stac922x_adc_nids;
2628 spec->mux_nids = stac922x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01002629 spec->num_muxes = ARRAY_SIZE(stac922x_mux_nids);
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002630 spec->num_adcs = ARRAY_SIZE(stac922x_adc_nids);
Matt Porter8b657272006-10-26 17:12:59 +02002631 spec->num_dmics = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02002632
2633 spec->init = stac922x_core_init;
Matt2f2f4252005-04-13 14:45:30 +02002634 spec->mixer = stac922x_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02002635
2636 spec->multiout.dac_nids = spec->dac_nids;
Takashi Iwai19039bd2006-06-28 15:52:16 +02002637
Matt Porter3cc08dc2006-01-23 15:27:49 +01002638 err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002639 if (!err) {
2640 if (spec->board_config < 0) {
2641 printk(KERN_WARNING "hda_codec: No auto-config is "
2642 "available, default to model=ref\n");
2643 spec->board_config = STAC_D945_REF;
2644 goto again;
2645 }
2646 err = -EINVAL;
2647 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01002648 if (err < 0) {
2649 stac92xx_free(codec);
2650 return err;
2651 }
2652
2653 codec->patch_ops = stac92xx_patch_ops;
2654
Takashi Iwai807a46362007-05-29 19:01:37 +02002655 /* Fix Mux capture level; max to 2 */
2656 snd_hda_override_amp_caps(codec, 0x12, HDA_OUTPUT,
2657 (0 << AC_AMPCAP_OFFSET_SHIFT) |
2658 (2 << AC_AMPCAP_NUM_STEPS_SHIFT) |
2659 (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
2660 (0 << AC_AMPCAP_MUTE_SHIFT));
2661
Matt Porter3cc08dc2006-01-23 15:27:49 +01002662 return 0;
2663}
2664
2665static int patch_stac927x(struct hda_codec *codec)
2666{
2667 struct sigmatel_spec *spec;
2668 int err;
2669
2670 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2671 if (spec == NULL)
2672 return -ENOMEM;
2673
2674 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02002675 spec->num_pins = ARRAY_SIZE(stac927x_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02002676 spec->pin_nids = stac927x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002677 spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS,
2678 stac927x_models,
2679 stac927x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002680 again:
Richard Fish11b44bb2006-08-23 18:31:34 +02002681 if (spec->board_config < 0) {
Matt Porter3cc08dc2006-01-23 15:27:49 +01002682 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC927x, using BIOS defaults\n");
Richard Fish11b44bb2006-08-23 18:31:34 +02002683 err = stac92xx_save_bios_config_regs(codec);
2684 if (err < 0) {
2685 stac92xx_free(codec);
2686 return err;
2687 }
2688 spec->pin_configs = spec->bios_pin_configs;
2689 } else if (stac927x_brd_tbl[spec->board_config] != NULL) {
Matt Porter3cc08dc2006-01-23 15:27:49 +01002690 spec->pin_configs = stac927x_brd_tbl[spec->board_config];
2691 stac92xx_set_config_regs(codec);
2692 }
2693
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002694 switch (spec->board_config) {
Tobin Davis93ed1502006-09-01 21:03:12 +02002695 case STAC_D965_3ST:
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002696 spec->adc_nids = stac927x_adc_nids;
2697 spec->mux_nids = stac927x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01002698 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002699 spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
Tobin Davis93ed1502006-09-01 21:03:12 +02002700 spec->init = d965_core_init;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002701 spec->mixer = stac927x_mixer;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002702 break;
Tobin Davis93ed1502006-09-01 21:03:12 +02002703 case STAC_D965_5ST:
2704 spec->adc_nids = stac927x_adc_nids;
2705 spec->mux_nids = stac927x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01002706 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002707 spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
Tobin Davis93ed1502006-09-01 21:03:12 +02002708 spec->init = d965_core_init;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002709 spec->mixer = stac927x_mixer;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002710 break;
2711 default:
2712 spec->adc_nids = stac927x_adc_nids;
2713 spec->mux_nids = stac927x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01002714 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002715 spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002716 spec->init = stac927x_core_init;
2717 spec->mixer = stac927x_mixer;
2718 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01002719
Matthew Ranostay7f168592007-10-18 17:38:17 +02002720 switch (codec->subsystem_id) {
2721 case 0x1028020A: /* STAC 9228 */
2722 case 0x10280209: /* STAC 9228 */
2723 spec->dmic_nids = stac927x_dmic_nids;
2724 spec->num_dmics = STAC927X_NUM_DMICS;
Matthew Ranostay83eef752007-10-22 12:27:10 +02002725 spec->dmux_nid = 0x1b;
Matthew Ranostay7f168592007-10-18 17:38:17 +02002726 break;
2727 default:
2728 spec->num_dmics = 0;
2729 }
2730
Matt Porter3cc08dc2006-01-23 15:27:49 +01002731 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostay87d48362007-07-17 11:52:24 +02002732 /* GPIO0 High = Enable EAPD */
Takashi Iwai82599802007-07-31 15:56:24 +02002733 spec->gpio_mask = spec->gpio_data = 0x00000001;
2734 stac92xx_enable_gpio_mask(codec);
Matthew Ranostay92a22be2007-06-19 16:48:28 +02002735
Matt Porter3cc08dc2006-01-23 15:27:49 +01002736 err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002737 if (!err) {
2738 if (spec->board_config < 0) {
2739 printk(KERN_WARNING "hda_codec: No auto-config is "
2740 "available, default to model=ref\n");
2741 spec->board_config = STAC_D965_REF;
2742 goto again;
2743 }
2744 err = -EINVAL;
2745 }
Mattc7d4b2f2005-06-27 14:59:41 +02002746 if (err < 0) {
2747 stac92xx_free(codec);
2748 return err;
2749 }
Matt2f2f4252005-04-13 14:45:30 +02002750
2751 codec->patch_ops = stac92xx_patch_ops;
2752
2753 return 0;
2754}
2755
Matt Porterf3302a52006-07-31 12:49:34 +02002756static int patch_stac9205(struct hda_codec *codec)
2757{
2758 struct sigmatel_spec *spec;
Takashi Iwai82599802007-07-31 15:56:24 +02002759 int err;
Matt Porterf3302a52006-07-31 12:49:34 +02002760
2761 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2762 if (spec == NULL)
2763 return -ENOMEM;
2764
2765 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02002766 spec->num_pins = ARRAY_SIZE(stac9205_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02002767 spec->pin_nids = stac9205_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002768 spec->board_config = snd_hda_check_board_config(codec, STAC_9205_MODELS,
2769 stac9205_models,
2770 stac9205_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002771 again:
Richard Fish11b44bb2006-08-23 18:31:34 +02002772 if (spec->board_config < 0) {
2773 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9205, using BIOS defaults\n");
2774 err = stac92xx_save_bios_config_regs(codec);
2775 if (err < 0) {
2776 stac92xx_free(codec);
2777 return err;
2778 }
2779 spec->pin_configs = spec->bios_pin_configs;
2780 } else {
Matt Porterf3302a52006-07-31 12:49:34 +02002781 spec->pin_configs = stac9205_brd_tbl[spec->board_config];
2782 stac92xx_set_config_regs(codec);
2783 }
2784
2785 spec->adc_nids = stac9205_adc_nids;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002786 spec->num_adcs = ARRAY_SIZE(stac9205_adc_nids);
Matt Porterf3302a52006-07-31 12:49:34 +02002787 spec->mux_nids = stac9205_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01002788 spec->num_muxes = ARRAY_SIZE(stac9205_mux_nids);
Matt Porter8b657272006-10-26 17:12:59 +02002789 spec->dmic_nids = stac9205_dmic_nids;
Takashi Iwaif6e98522007-10-16 14:27:04 +02002790 spec->num_dmics = STAC9205_NUM_DMICS;
Matt Porter8b657272006-10-26 17:12:59 +02002791 spec->dmux_nid = 0x1d;
Matt Porterf3302a52006-07-31 12:49:34 +02002792
2793 spec->init = stac9205_core_init;
2794 spec->mixer = stac9205_mixer;
2795
2796 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostay87d48362007-07-17 11:52:24 +02002797
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002798 switch (spec->board_config){
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002799 case STAC_9205_DELL_M43:
Matthew Ranostay87d48362007-07-17 11:52:24 +02002800 /* Enable SPDIF in/out */
2801 stac92xx_set_config_reg(codec, 0x1f, 0x01441030);
2802 stac92xx_set_config_reg(codec, 0x20, 0x1c410030);
Matt Porter33382402006-12-18 13:17:28 +01002803
Takashi Iwai82599802007-07-31 15:56:24 +02002804 spec->gpio_mask = 0x00000007; /* GPIO0-2 */
Matthew Ranostay87d48362007-07-17 11:52:24 +02002805 /* GPIO0 High = EAPD, GPIO1 Low = DRM,
2806 * GPIO2 High = Headphone Mute
2807 */
Takashi Iwai82599802007-07-31 15:56:24 +02002808 spec->gpio_data = 0x00000005;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002809 break;
2810 default:
2811 /* GPIO0 High = EAPD */
2812 spec->gpio_mask = spec->gpio_data = 0x00000001;
2813 break;
2814 }
Matthew Ranostay87d48362007-07-17 11:52:24 +02002815
Takashi Iwai82599802007-07-31 15:56:24 +02002816 stac92xx_enable_gpio_mask(codec);
Matt Porterf3302a52006-07-31 12:49:34 +02002817 err = stac92xx_parse_auto_config(codec, 0x1f, 0x20);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002818 if (!err) {
2819 if (spec->board_config < 0) {
2820 printk(KERN_WARNING "hda_codec: No auto-config is "
2821 "available, default to model=ref\n");
2822 spec->board_config = STAC_9205_REF;
2823 goto again;
2824 }
2825 err = -EINVAL;
2826 }
Matt Porterf3302a52006-07-31 12:49:34 +02002827 if (err < 0) {
2828 stac92xx_free(codec);
2829 return err;
2830 }
2831
2832 codec->patch_ops = stac92xx_patch_ops;
2833
2834 return 0;
2835}
2836
Matt2f2f4252005-04-13 14:45:30 +02002837/*
Guillaume Munch6d859062006-08-22 17:15:47 +02002838 * STAC9872 hack
Takashi Iwaidb064e52006-03-16 16:04:58 +01002839 */
2840
Guillaume Munch99ccc562006-08-16 19:35:12 +02002841/* static config for Sony VAIO FE550G and Sony VAIO AR */
Takashi Iwaidb064e52006-03-16 16:04:58 +01002842static hda_nid_t vaio_dacs[] = { 0x2 };
2843#define VAIO_HP_DAC 0x5
2844static hda_nid_t vaio_adcs[] = { 0x8 /*,0x6*/ };
2845static hda_nid_t vaio_mux_nids[] = { 0x15 };
2846
2847static struct hda_input_mux vaio_mux = {
Takashi Iwaia3a2f422007-10-11 11:21:21 +02002848 .num_items = 3,
Takashi Iwaidb064e52006-03-16 16:04:58 +01002849 .items = {
Takashi Iwaid7737812006-04-25 13:05:43 +02002850 /* { "HP", 0x0 }, */
Takashi Iwai1624cb92007-07-05 13:10:51 +02002851 { "Mic Jack", 0x1 },
2852 { "Internal Mic", 0x2 },
Takashi Iwaidb064e52006-03-16 16:04:58 +01002853 { "PCM", 0x3 },
2854 }
2855};
2856
2857static struct hda_verb vaio_init[] = {
2858 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
Takashi Iwai72e7b0d2007-08-16 17:33:55 +02002859 {0x0a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | STAC_HP_EVENT},
Takashi Iwaidb064e52006-03-16 16:04:58 +01002860 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
2861 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
2862 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
2863 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
Takashi Iwai1624cb92007-07-05 13:10:51 +02002864 {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
Takashi Iwaidb064e52006-03-16 16:04:58 +01002865 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
2866 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
2867 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
2868 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
2869 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
2870 {}
2871};
2872
Guillaume Munch6d859062006-08-22 17:15:47 +02002873static struct hda_verb vaio_ar_init[] = {
2874 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
2875 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
2876 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
2877 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
2878/* {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },*/ /* Optical Out */
2879 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
Takashi Iwai1624cb92007-07-05 13:10:51 +02002880 {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
Guillaume Munch6d859062006-08-22 17:15:47 +02002881 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
2882 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
2883/* {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},*/ /* Optical Out */
2884 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
2885 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
2886 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
2887 {}
2888};
2889
Takashi Iwaidb064e52006-03-16 16:04:58 +01002890/* bind volumes of both NID 0x02 and 0x05 */
Takashi Iwaicca3b372007-08-10 17:12:15 +02002891static struct hda_bind_ctls vaio_bind_master_vol = {
2892 .ops = &snd_hda_bind_vol,
2893 .values = {
2894 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2895 HDA_COMPOSE_AMP_VAL(0x05, 3, 0, HDA_OUTPUT),
2896 0
2897 },
2898};
Takashi Iwaidb064e52006-03-16 16:04:58 +01002899
2900/* bind volumes of both NID 0x02 and 0x05 */
Takashi Iwaicca3b372007-08-10 17:12:15 +02002901static struct hda_bind_ctls vaio_bind_master_sw = {
2902 .ops = &snd_hda_bind_sw,
2903 .values = {
2904 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2905 HDA_COMPOSE_AMP_VAL(0x05, 3, 0, HDA_OUTPUT),
2906 0,
2907 },
2908};
Takashi Iwaidb064e52006-03-16 16:04:58 +01002909
2910static struct snd_kcontrol_new vaio_mixer[] = {
Takashi Iwaicca3b372007-08-10 17:12:15 +02002911 HDA_BIND_VOL("Master Playback Volume", &vaio_bind_master_vol),
2912 HDA_BIND_SW("Master Playback Switch", &vaio_bind_master_sw),
Takashi Iwaidb064e52006-03-16 16:04:58 +01002913 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
2914 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
2915 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
2916 {
2917 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2918 .name = "Capture Source",
2919 .count = 1,
2920 .info = stac92xx_mux_enum_info,
2921 .get = stac92xx_mux_enum_get,
2922 .put = stac92xx_mux_enum_put,
2923 },
2924 {}
2925};
2926
Guillaume Munch6d859062006-08-22 17:15:47 +02002927static struct snd_kcontrol_new vaio_ar_mixer[] = {
Takashi Iwaicca3b372007-08-10 17:12:15 +02002928 HDA_BIND_VOL("Master Playback Volume", &vaio_bind_master_vol),
2929 HDA_BIND_SW("Master Playback Switch", &vaio_bind_master_sw),
Guillaume Munch6d859062006-08-22 17:15:47 +02002930 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
2931 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
2932 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
2933 /*HDA_CODEC_MUTE("Optical Out Switch", 0x10, 0, HDA_OUTPUT),
2934 HDA_CODEC_VOLUME("Optical Out Volume", 0x10, 0, HDA_OUTPUT),*/
2935 {
2936 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2937 .name = "Capture Source",
2938 .count = 1,
2939 .info = stac92xx_mux_enum_info,
2940 .get = stac92xx_mux_enum_get,
2941 .put = stac92xx_mux_enum_put,
2942 },
2943 {}
2944};
2945
2946static struct hda_codec_ops stac9872_patch_ops = {
Takashi Iwaidb064e52006-03-16 16:04:58 +01002947 .build_controls = stac92xx_build_controls,
2948 .build_pcms = stac92xx_build_pcms,
2949 .init = stac92xx_init,
2950 .free = stac92xx_free,
Takashi Iwaicb53c622007-08-10 17:21:45 +02002951#ifdef SND_HDA_NEEDS_RESUME
Takashi Iwaidb064e52006-03-16 16:04:58 +01002952 .resume = stac92xx_resume,
2953#endif
2954};
2955
Takashi Iwai72e7b0d2007-08-16 17:33:55 +02002956static int stac9872_vaio_init(struct hda_codec *codec)
2957{
2958 int err;
2959
2960 err = stac92xx_init(codec);
2961 if (err < 0)
2962 return err;
2963 if (codec->patch_ops.unsol_event)
2964 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
2965 return 0;
2966}
2967
2968static void stac9872_vaio_hp_detect(struct hda_codec *codec, unsigned int res)
2969{
2970 if (get_pin_presence(codec, 0x0a)) {
2971 stac92xx_reset_pinctl(codec, 0x0f, AC_PINCTL_OUT_EN);
2972 stac92xx_set_pinctl(codec, 0x0a, AC_PINCTL_OUT_EN);
2973 } else {
2974 stac92xx_reset_pinctl(codec, 0x0a, AC_PINCTL_OUT_EN);
2975 stac92xx_set_pinctl(codec, 0x0f, AC_PINCTL_OUT_EN);
2976 }
2977}
2978
2979static void stac9872_vaio_unsol_event(struct hda_codec *codec, unsigned int res)
2980{
2981 switch (res >> 26) {
2982 case STAC_HP_EVENT:
2983 stac9872_vaio_hp_detect(codec, res);
2984 break;
2985 }
2986}
2987
2988static struct hda_codec_ops stac9872_vaio_patch_ops = {
2989 .build_controls = stac92xx_build_controls,
2990 .build_pcms = stac92xx_build_pcms,
2991 .init = stac9872_vaio_init,
2992 .free = stac92xx_free,
2993 .unsol_event = stac9872_vaio_unsol_event,
2994#ifdef CONFIG_PM
2995 .resume = stac92xx_resume,
2996#endif
2997};
2998
Guillaume Munch6d859062006-08-22 17:15:47 +02002999enum { /* FE and SZ series. id=0x83847661 and subsys=0x104D0700 or 104D1000. */
3000 CXD9872RD_VAIO,
3001 /* Unknown. id=0x83847662 and subsys=0x104D1200 or 104D1000. */
3002 STAC9872AK_VAIO,
3003 /* Unknown. id=0x83847661 and subsys=0x104D1200. */
3004 STAC9872K_VAIO,
3005 /* AR Series. id=0x83847664 and subsys=104D1300 */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01003006 CXD9872AKD_VAIO,
3007 STAC_9872_MODELS,
3008};
Takashi Iwaidb064e52006-03-16 16:04:58 +01003009
Takashi Iwaif5fcc132006-11-24 17:07:44 +01003010static const char *stac9872_models[STAC_9872_MODELS] = {
3011 [CXD9872RD_VAIO] = "vaio",
3012 [CXD9872AKD_VAIO] = "vaio-ar",
3013};
3014
3015static struct snd_pci_quirk stac9872_cfg_tbl[] = {
3016 SND_PCI_QUIRK(0x104d, 0x81e6, "Sony VAIO F/S", CXD9872RD_VAIO),
3017 SND_PCI_QUIRK(0x104d, 0x81ef, "Sony VAIO F/S", CXD9872RD_VAIO),
3018 SND_PCI_QUIRK(0x104d, 0x81fd, "Sony VAIO AR", CXD9872AKD_VAIO),
Tobin Davis68e22542007-03-12 11:36:39 +01003019 SND_PCI_QUIRK(0x104d, 0x8205, "Sony VAIO AR", CXD9872AKD_VAIO),
Takashi Iwaidb064e52006-03-16 16:04:58 +01003020 {}
3021};
3022
Guillaume Munch6d859062006-08-22 17:15:47 +02003023static int patch_stac9872(struct hda_codec *codec)
Takashi Iwaidb064e52006-03-16 16:04:58 +01003024{
3025 struct sigmatel_spec *spec;
3026 int board_config;
3027
Takashi Iwaif5fcc132006-11-24 17:07:44 +01003028 board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
3029 stac9872_models,
3030 stac9872_cfg_tbl);
Takashi Iwaidb064e52006-03-16 16:04:58 +01003031 if (board_config < 0)
3032 /* unknown config, let generic-parser do its job... */
3033 return snd_hda_parse_generic_codec(codec);
3034
3035 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3036 if (spec == NULL)
3037 return -ENOMEM;
3038
3039 codec->spec = spec;
3040 switch (board_config) {
Guillaume Munch6d859062006-08-22 17:15:47 +02003041 case CXD9872RD_VAIO:
3042 case STAC9872AK_VAIO:
3043 case STAC9872K_VAIO:
Takashi Iwaidb064e52006-03-16 16:04:58 +01003044 spec->mixer = vaio_mixer;
3045 spec->init = vaio_init;
3046 spec->multiout.max_channels = 2;
3047 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
3048 spec->multiout.dac_nids = vaio_dacs;
3049 spec->multiout.hp_nid = VAIO_HP_DAC;
3050 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
3051 spec->adc_nids = vaio_adcs;
3052 spec->input_mux = &vaio_mux;
3053 spec->mux_nids = vaio_mux_nids;
Takashi Iwai72e7b0d2007-08-16 17:33:55 +02003054 codec->patch_ops = stac9872_vaio_patch_ops;
Takashi Iwaidb064e52006-03-16 16:04:58 +01003055 break;
Guillaume Munch6d859062006-08-22 17:15:47 +02003056
3057 case CXD9872AKD_VAIO:
3058 spec->mixer = vaio_ar_mixer;
3059 spec->init = vaio_ar_init;
3060 spec->multiout.max_channels = 2;
3061 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
3062 spec->multiout.dac_nids = vaio_dacs;
3063 spec->multiout.hp_nid = VAIO_HP_DAC;
3064 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
3065 spec->adc_nids = vaio_adcs;
3066 spec->input_mux = &vaio_mux;
3067 spec->mux_nids = vaio_mux_nids;
Takashi Iwai72e7b0d2007-08-16 17:33:55 +02003068 codec->patch_ops = stac9872_patch_ops;
Guillaume Munch6d859062006-08-22 17:15:47 +02003069 break;
Takashi Iwaidb064e52006-03-16 16:04:58 +01003070 }
3071
Takashi Iwaidb064e52006-03-16 16:04:58 +01003072 return 0;
3073}
3074
3075
3076/*
Matt2f2f4252005-04-13 14:45:30 +02003077 * patch entries
3078 */
3079struct hda_codec_preset snd_hda_preset_sigmatel[] = {
3080 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
3081 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
3082 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
3083 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
3084 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
3085 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
3086 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
Matt Porter22a27c72006-07-06 18:49:10 +02003087 { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
3088 { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
3089 { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
3090 { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
3091 { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
3092 { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
Matt Porter3cc08dc2006-01-23 15:27:49 +01003093 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
3094 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
3095 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
3096 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
3097 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
3098 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
3099 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
3100 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
3101 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
3102 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
Tobin Davis8e21c342007-01-08 11:04:17 +01003103 { .id = 0x83847632, .name = "STAC9202", .patch = patch_stac925x },
3104 { .id = 0x83847633, .name = "STAC9202D", .patch = patch_stac925x },
3105 { .id = 0x83847634, .name = "STAC9250", .patch = patch_stac925x },
3106 { .id = 0x83847635, .name = "STAC9250D", .patch = patch_stac925x },
3107 { .id = 0x83847636, .name = "STAC9251", .patch = patch_stac925x },
3108 { .id = 0x83847637, .name = "STAC9250D", .patch = patch_stac925x },
Guillaume Munch6d859062006-08-22 17:15:47 +02003109 /* The following does not take into account .id=0x83847661 when subsys =
3110 * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
3111 * currently not fully supported.
3112 */
3113 { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
3114 { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
3115 { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
Matt Porterf3302a52006-07-31 12:49:34 +02003116 { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
3117 { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
3118 { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
3119 { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
3120 { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
3121 { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
3122 { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
3123 { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
Matt2f2f4252005-04-13 14:45:30 +02003124 {} /* terminator */
3125};