blob: 87a36e9d6546c01656dbcab6e6946db4da405cab [file] [log] [blame]
Matt2f2f4252005-04-13 14:45:30 +02001/*
2 * Universal Interface for Intel High Definition Audio Codec
3 *
4 * HD audio interface patch for SigmaTel STAC92xx
5 *
6 * Copyright (c) 2005 Embedded Alley Solutions, Inc.
Matt Porter403d1942005-11-29 15:00:51 +01007 * Matt Porter <mporter@embeddedalley.com>
Matt2f2f4252005-04-13 14:45:30 +02008 *
9 * Based on patch_cmedia.c and patch_realtek.c
10 * Copyright (c) 2004 Takashi Iwai <tiwai@suse.de>
11 *
12 * This driver is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This driver is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 */
26
27#include <sound/driver.h>
28#include <linux/init.h>
29#include <linux/delay.h>
30#include <linux/slab.h>
31#include <linux/pci.h>
32#include <sound/core.h>
Mattc7d4b2f2005-06-27 14:59:41 +020033#include <sound/asoundef.h>
Matt2f2f4252005-04-13 14:45:30 +020034#include "hda_codec.h"
35#include "hda_local.h"
36
Matt4e550962005-07-04 17:51:39 +020037#define NUM_CONTROL_ALLOC 32
38#define STAC_HP_EVENT 0x37
Matt4e550962005-07-04 17:51:39 +020039
Takashi Iwaif5fcc132006-11-24 17:07:44 +010040enum {
41 STAC_REF,
42 STAC_9200_MODELS
43};
44
45enum {
46 STAC_9205_REF,
Matthew Ranostay87d48362007-07-17 11:52:24 +020047 STAC_M43xx,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010048 STAC_9205_MODELS
49};
50
51enum {
Tobin Davis8e21c342007-01-08 11:04:17 +010052 STAC_925x_REF,
53 STAC_M2_2,
54 STAC_MA6,
Tobin Davis2c11f952007-05-17 09:36:34 +020055 STAC_PA6,
Tobin Davis8e21c342007-01-08 11:04:17 +010056 STAC_925x_MODELS
57};
58
59enum {
Takashi Iwaif5fcc132006-11-24 17:07:44 +010060 STAC_D945_REF,
61 STAC_D945GTP3,
62 STAC_D945GTP5,
Takashi Iwai76c08822007-06-19 12:17:42 +020063 STAC_922X_DELL,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +020064 STAC_INTEL_MAC_V1,
65 STAC_INTEL_MAC_V2,
66 STAC_INTEL_MAC_V3,
67 STAC_INTEL_MAC_V4,
68 STAC_INTEL_MAC_V5,
69 /* for backward compitability */
Takashi Iwaif5fcc132006-11-24 17:07:44 +010070 STAC_MACMINI,
Takashi Iwai3fc24d82007-02-16 13:27:18 +010071 STAC_MACBOOK,
Nicolas Boichat6f0778d2007-03-15 12:38:15 +010072 STAC_MACBOOK_PRO_V1,
73 STAC_MACBOOK_PRO_V2,
Sylvain FORETf16928f2007-04-27 14:22:36 +020074 STAC_IMAC_INTEL,
Takashi Iwai0dae0f82007-05-21 12:41:29 +020075 STAC_IMAC_INTEL_20,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010076 STAC_922X_MODELS
77};
78
79enum {
80 STAC_D965_REF,
81 STAC_D965_3ST,
82 STAC_D965_5ST,
Tobin Davis4ff076e2007-08-07 11:48:12 +020083 STAC_DELL_3ST,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010084 STAC_927X_MODELS
85};
Matt Porter403d1942005-11-29 15:00:51 +010086
Matt2f2f4252005-04-13 14:45:30 +020087struct sigmatel_spec {
Takashi Iwaic8b6bf92005-11-17 14:57:47 +010088 struct snd_kcontrol_new *mixers[4];
Mattc7d4b2f2005-06-27 14:59:41 +020089 unsigned int num_mixers;
90
Matt Porter403d1942005-11-29 15:00:51 +010091 int board_config;
Mattc7d4b2f2005-06-27 14:59:41 +020092 unsigned int surr_switch: 1;
Matt Porter403d1942005-11-29 15:00:51 +010093 unsigned int line_switch: 1;
94 unsigned int mic_switch: 1;
Matt Porter3cc08dc2006-01-23 15:27:49 +010095 unsigned int alt_switch: 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +010096 unsigned int hp_detect: 1;
Sam Revitch62fe78e2006-05-10 15:09:17 +020097 unsigned int gpio_mute: 1;
Mattc7d4b2f2005-06-27 14:59:41 +020098
Takashi Iwai82599802007-07-31 15:56:24 +020099 unsigned int gpio_mask, gpio_data;
100
Matt2f2f4252005-04-13 14:45:30 +0200101 /* playback */
102 struct hda_multi_out multiout;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100103 hda_nid_t dac_nids[5];
Matt2f2f4252005-04-13 14:45:30 +0200104
105 /* capture */
106 hda_nid_t *adc_nids;
Matt2f2f4252005-04-13 14:45:30 +0200107 unsigned int num_adcs;
Mattdabbed62005-06-14 10:19:34 +0200108 hda_nid_t *mux_nids;
109 unsigned int num_muxes;
Matt Porter8b657272006-10-26 17:12:59 +0200110 hda_nid_t *dmic_nids;
111 unsigned int num_dmics;
112 hda_nid_t dmux_nid;
Mattdabbed62005-06-14 10:19:34 +0200113 hda_nid_t dig_in_nid;
Matt2f2f4252005-04-13 14:45:30 +0200114
Matt2f2f4252005-04-13 14:45:30 +0200115 /* pin widgets */
116 hda_nid_t *pin_nids;
117 unsigned int num_pins;
Matt2f2f4252005-04-13 14:45:30 +0200118 unsigned int *pin_configs;
Richard Fish11b44bb2006-08-23 18:31:34 +0200119 unsigned int *bios_pin_configs;
Matt2f2f4252005-04-13 14:45:30 +0200120
121 /* codec specific stuff */
122 struct hda_verb *init;
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100123 struct snd_kcontrol_new *mixer;
Matt2f2f4252005-04-13 14:45:30 +0200124
125 /* capture source */
Matt Porter8b657272006-10-26 17:12:59 +0200126 struct hda_input_mux *dinput_mux;
127 unsigned int cur_dmux;
Mattc7d4b2f2005-06-27 14:59:41 +0200128 struct hda_input_mux *input_mux;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100129 unsigned int cur_mux[3];
Matt2f2f4252005-04-13 14:45:30 +0200130
Matt Porter403d1942005-11-29 15:00:51 +0100131 /* i/o switches */
132 unsigned int io_switch[2];
Matt2f2f4252005-04-13 14:45:30 +0200133
Mattc7d4b2f2005-06-27 14:59:41 +0200134 struct hda_pcm pcm_rec[2]; /* PCM information */
135
136 /* dynamic controls and input_mux */
137 struct auto_pin_cfg autocfg;
138 unsigned int num_kctl_alloc, num_kctl_used;
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100139 struct snd_kcontrol_new *kctl_alloc;
Matt Porter8b657272006-10-26 17:12:59 +0200140 struct hda_input_mux private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +0200141 struct hda_input_mux private_imux;
Matt2f2f4252005-04-13 14:45:30 +0200142};
143
144static hda_nid_t stac9200_adc_nids[1] = {
145 0x03,
146};
147
148static hda_nid_t stac9200_mux_nids[1] = {
149 0x0c,
150};
151
152static hda_nid_t stac9200_dac_nids[1] = {
153 0x02,
154};
155
Tobin Davis8e21c342007-01-08 11:04:17 +0100156static hda_nid_t stac925x_adc_nids[1] = {
157 0x03,
158};
159
160static hda_nid_t stac925x_mux_nids[1] = {
161 0x0f,
162};
163
164static hda_nid_t stac925x_dac_nids[1] = {
165 0x02,
166};
167
Tobin Davis2c11f952007-05-17 09:36:34 +0200168static hda_nid_t stac925x_dmic_nids[1] = {
169 0x15,
170};
171
Matt2f2f4252005-04-13 14:45:30 +0200172static hda_nid_t stac922x_adc_nids[2] = {
173 0x06, 0x07,
174};
175
176static hda_nid_t stac922x_mux_nids[2] = {
177 0x12, 0x13,
178};
179
Matt Porter3cc08dc2006-01-23 15:27:49 +0100180static hda_nid_t stac927x_adc_nids[3] = {
181 0x07, 0x08, 0x09
182};
183
184static hda_nid_t stac927x_mux_nids[3] = {
185 0x15, 0x16, 0x17
186};
187
Matt Porterf3302a52006-07-31 12:49:34 +0200188static hda_nid_t stac9205_adc_nids[2] = {
189 0x12, 0x13
190};
191
192static hda_nid_t stac9205_mux_nids[2] = {
193 0x19, 0x1a
194};
195
Takashi Iwai25494132007-03-12 12:36:16 +0100196static hda_nid_t stac9205_dmic_nids[2] = {
197 0x17, 0x18,
Matt Porter8b657272006-10-26 17:12:59 +0200198};
199
Mattc7d4b2f2005-06-27 14:59:41 +0200200static hda_nid_t stac9200_pin_nids[8] = {
Tobin Davis93ed1502006-09-01 21:03:12 +0200201 0x08, 0x09, 0x0d, 0x0e,
202 0x0f, 0x10, 0x11, 0x12,
Matt2f2f4252005-04-13 14:45:30 +0200203};
204
Tobin Davis8e21c342007-01-08 11:04:17 +0100205static hda_nid_t stac925x_pin_nids[8] = {
206 0x07, 0x08, 0x0a, 0x0b,
207 0x0c, 0x0d, 0x10, 0x11,
208};
209
Matt2f2f4252005-04-13 14:45:30 +0200210static hda_nid_t stac922x_pin_nids[10] = {
211 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
212 0x0f, 0x10, 0x11, 0x15, 0x1b,
213};
214
Matt Porter3cc08dc2006-01-23 15:27:49 +0100215static hda_nid_t stac927x_pin_nids[14] = {
216 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
217 0x0f, 0x10, 0x11, 0x12, 0x13,
218 0x14, 0x21, 0x22, 0x23,
219};
220
Matt Porterf3302a52006-07-31 12:49:34 +0200221static hda_nid_t stac9205_pin_nids[12] = {
222 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
223 0x0f, 0x14, 0x16, 0x17, 0x18,
224 0x21, 0x22,
Matt Porterf3302a52006-07-31 12:49:34 +0200225};
226
Matt Porter8b657272006-10-26 17:12:59 +0200227static int stac92xx_dmux_enum_info(struct snd_kcontrol *kcontrol,
228 struct snd_ctl_elem_info *uinfo)
229{
230 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
231 struct sigmatel_spec *spec = codec->spec;
232 return snd_hda_input_mux_info(spec->dinput_mux, uinfo);
233}
234
235static int stac92xx_dmux_enum_get(struct snd_kcontrol *kcontrol,
236 struct snd_ctl_elem_value *ucontrol)
237{
238 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
239 struct sigmatel_spec *spec = codec->spec;
240
241 ucontrol->value.enumerated.item[0] = spec->cur_dmux;
242 return 0;
243}
244
245static int stac92xx_dmux_enum_put(struct snd_kcontrol *kcontrol,
246 struct snd_ctl_elem_value *ucontrol)
247{
248 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
249 struct sigmatel_spec *spec = codec->spec;
250
251 return snd_hda_input_mux_put(codec, spec->dinput_mux, ucontrol,
252 spec->dmux_nid, &spec->cur_dmux);
253}
254
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100255static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Matt2f2f4252005-04-13 14:45:30 +0200256{
257 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
258 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +0200259 return snd_hda_input_mux_info(spec->input_mux, uinfo);
Matt2f2f4252005-04-13 14:45:30 +0200260}
261
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100262static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200263{
264 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
265 struct sigmatel_spec *spec = codec->spec;
266 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
267
268 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
269 return 0;
270}
271
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100272static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200273{
274 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
275 struct sigmatel_spec *spec = codec->spec;
276 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
277
Mattc7d4b2f2005-06-27 14:59:41 +0200278 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
Matt2f2f4252005-04-13 14:45:30 +0200279 spec->mux_nids[adc_idx], &spec->cur_mux[adc_idx]);
280}
281
Mattc7d4b2f2005-06-27 14:59:41 +0200282static struct hda_verb stac9200_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200283 /* set dac0mux for dac converter */
Mattc7d4b2f2005-06-27 14:59:41 +0200284 { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
Matt2f2f4252005-04-13 14:45:30 +0200285 {}
286};
287
Tobin Davis8e21c342007-01-08 11:04:17 +0100288static struct hda_verb stac925x_core_init[] = {
289 /* set dac0mux for dac converter */
290 { 0x06, AC_VERB_SET_CONNECT_SEL, 0x00},
291 {}
292};
293
Mattc7d4b2f2005-06-27 14:59:41 +0200294static struct hda_verb stac922x_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200295 /* set master volume and direct control */
Mattc7d4b2f2005-06-27 14:59:41 +0200296 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matt2f2f4252005-04-13 14:45:30 +0200297 {}
298};
299
Tobin Davis93ed1502006-09-01 21:03:12 +0200300static struct hda_verb d965_core_init[] = {
Takashi Iwai19039bd2006-06-28 15:52:16 +0200301 /* set master volume and direct control */
Tobin Davis93ed1502006-09-01 21:03:12 +0200302 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Takashi Iwai19039bd2006-06-28 15:52:16 +0200303 /* unmute node 0x1b */
304 { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
305 /* select node 0x03 as DAC */
306 { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
307 {}
308};
309
Matt Porter3cc08dc2006-01-23 15:27:49 +0100310static struct hda_verb stac927x_core_init[] = {
311 /* set master volume and direct control */
312 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
313 {}
314};
315
Matt Porterf3302a52006-07-31 12:49:34 +0200316static struct hda_verb stac9205_core_init[] = {
317 /* set master volume and direct control */
318 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
319 {}
320};
321
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100322static struct snd_kcontrol_new stac9200_mixer[] = {
Matt2f2f4252005-04-13 14:45:30 +0200323 HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
324 HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
325 {
326 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
327 .name = "Input Source",
328 .count = 1,
329 .info = stac92xx_mux_enum_info,
330 .get = stac92xx_mux_enum_get,
331 .put = stac92xx_mux_enum_put,
332 },
333 HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
334 HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
Mattc7d4b2f2005-06-27 14:59:41 +0200335 HDA_CODEC_VOLUME("Capture Mux Volume", 0x0c, 0, HDA_OUTPUT),
Matt2f2f4252005-04-13 14:45:30 +0200336 { } /* end */
337};
338
Tobin Davis8e21c342007-01-08 11:04:17 +0100339static struct snd_kcontrol_new stac925x_mixer[] = {
Tobin Davis8e21c342007-01-08 11:04:17 +0100340 {
341 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
342 .name = "Input Source",
343 .count = 1,
344 .info = stac92xx_mux_enum_info,
345 .get = stac92xx_mux_enum_get,
346 .put = stac92xx_mux_enum_put,
347 },
348 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_OUTPUT),
349 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_OUTPUT),
350 HDA_CODEC_VOLUME("Capture Mux Volume", 0x0f, 0, HDA_OUTPUT),
351 { } /* end */
352};
353
Mattc7d4b2f2005-06-27 14:59:41 +0200354/* This needs to be generated dynamically based on sequence */
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100355static struct snd_kcontrol_new stac922x_mixer[] = {
Matt2f2f4252005-04-13 14:45:30 +0200356 {
357 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
358 .name = "Input Source",
359 .count = 1,
360 .info = stac92xx_mux_enum_info,
361 .get = stac92xx_mux_enum_get,
362 .put = stac92xx_mux_enum_put,
363 },
364 HDA_CODEC_VOLUME("Capture Volume", 0x17, 0x0, HDA_INPUT),
Takashi Iwai0fd17082006-01-13 18:46:21 +0100365 HDA_CODEC_MUTE("Capture Switch", 0x17, 0x0, HDA_INPUT),
Matt2f2f4252005-04-13 14:45:30 +0200366 HDA_CODEC_VOLUME("Mux Capture Volume", 0x12, 0x0, HDA_OUTPUT),
367 { } /* end */
368};
369
Takashi Iwai19039bd2006-06-28 15:52:16 +0200370/* This needs to be generated dynamically based on sequence */
371static struct snd_kcontrol_new stac9227_mixer[] = {
372 {
373 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
374 .name = "Input Source",
375 .count = 1,
376 .info = stac92xx_mux_enum_info,
377 .get = stac92xx_mux_enum_get,
378 .put = stac92xx_mux_enum_put,
379 },
380 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
381 HDA_CODEC_MUTE("Capture Switch", 0x1b, 0x0, HDA_OUTPUT),
382 { } /* end */
383};
384
Takashi Iwaid1d985f2006-11-23 19:27:12 +0100385static struct snd_kcontrol_new stac927x_mixer[] = {
Matt Porter3cc08dc2006-01-23 15:27:49 +0100386 {
387 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
388 .name = "Input Source",
389 .count = 1,
390 .info = stac92xx_mux_enum_info,
391 .get = stac92xx_mux_enum_get,
392 .put = stac92xx_mux_enum_put,
393 },
394 HDA_CODEC_VOLUME("InMux Capture Volume", 0x15, 0x0, HDA_OUTPUT),
395 HDA_CODEC_VOLUME("InVol Capture Volume", 0x18, 0x0, HDA_INPUT),
396 HDA_CODEC_MUTE("ADCMux Capture Switch", 0x1b, 0x0, HDA_OUTPUT),
397 { } /* end */
398};
399
Takashi Iwaid1d985f2006-11-23 19:27:12 +0100400static struct snd_kcontrol_new stac9205_mixer[] = {
Matt Porterf3302a52006-07-31 12:49:34 +0200401 {
402 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Matt Porter8b657272006-10-26 17:12:59 +0200403 .name = "Digital Input Source",
404 .count = 1,
405 .info = stac92xx_dmux_enum_info,
406 .get = stac92xx_dmux_enum_get,
407 .put = stac92xx_dmux_enum_put,
408 },
409 {
410 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Matt Porterf3302a52006-07-31 12:49:34 +0200411 .name = "Input Source",
412 .count = 1,
413 .info = stac92xx_mux_enum_info,
414 .get = stac92xx_mux_enum_get,
415 .put = stac92xx_mux_enum_put,
416 },
417 HDA_CODEC_VOLUME("InMux Capture Volume", 0x19, 0x0, HDA_OUTPUT),
418 HDA_CODEC_VOLUME("InVol Capture Volume", 0x1b, 0x0, HDA_INPUT),
419 HDA_CODEC_MUTE("ADCMux Capture Switch", 0x1d, 0x0, HDA_OUTPUT),
420 { } /* end */
421};
422
Matt2f2f4252005-04-13 14:45:30 +0200423static int stac92xx_build_controls(struct hda_codec *codec)
424{
425 struct sigmatel_spec *spec = codec->spec;
426 int err;
Mattc7d4b2f2005-06-27 14:59:41 +0200427 int i;
Matt2f2f4252005-04-13 14:45:30 +0200428
429 err = snd_hda_add_new_ctls(codec, spec->mixer);
430 if (err < 0)
431 return err;
Mattc7d4b2f2005-06-27 14:59:41 +0200432
433 for (i = 0; i < spec->num_mixers; i++) {
434 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
435 if (err < 0)
436 return err;
437 }
438
Mattdabbed62005-06-14 10:19:34 +0200439 if (spec->multiout.dig_out_nid) {
440 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
441 if (err < 0)
442 return err;
443 }
444 if (spec->dig_in_nid) {
445 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
446 if (err < 0)
447 return err;
448 }
449 return 0;
Matt2f2f4252005-04-13 14:45:30 +0200450}
451
Matt Porter403d1942005-11-29 15:00:51 +0100452static unsigned int ref9200_pin_configs[8] = {
Mattdabbed62005-06-14 10:19:34 +0200453 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
Matt2f2f4252005-04-13 14:45:30 +0200454 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
455};
456
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100457static unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
458 [STAC_REF] = ref9200_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +0100459};
460
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100461static const char *stac9200_models[STAC_9200_MODELS] = {
462 [STAC_REF] = "ref",
463};
464
465static struct snd_pci_quirk stac9200_cfg_tbl[] = {
466 /* SigmaTel reference board */
467 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
468 "DFI LanParty", STAC_REF),
Matt Portere7377072006-11-06 11:20:38 +0100469 /* Dell laptops have BIOS problem */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100470 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01b5,
471 "Dell Inspiron 630m", STAC_REF),
472 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c2,
473 "Dell Latitude D620", STAC_REF),
474 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cb,
475 "Dell Latitude 120L", STAC_REF),
Cory T. Tusar877b8662007-01-30 17:30:55 +0100476 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cc,
477 "Dell Latitude D820", STAC_REF),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +0100478 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cd,
479 "Dell Inspiron E1705/9400", STAC_REF),
480 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ce,
481 "Dell XPS M1710", STAC_REF),
Takashi Iwaif0f96742007-02-14 00:59:17 +0100482 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cf,
483 "Dell Precision M90", STAC_REF),
Daniel T Chen8286c532007-05-15 11:46:23 +0200484 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d6,
485 "unknown Dell", STAC_REF),
Tobin Davis49c605d2007-05-17 09:38:24 +0200486 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d8,
487 "Dell Inspiron 640m", STAC_REF),
488 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f5,
489 "Dell Inspiron 1501", STAC_REF),
490
491 /* Panasonic */
492 SND_PCI_QUIRK(0x10f7, 0x8338, "Panasonic CF-74", STAC_REF),
493
Matt Porter403d1942005-11-29 15:00:51 +0100494 {} /* terminator */
495};
496
Tobin Davis8e21c342007-01-08 11:04:17 +0100497static unsigned int ref925x_pin_configs[8] = {
498 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
499 0x90a70320, 0x02214210, 0x400003f1, 0x9033032e,
500};
501
502static unsigned int stac925x_MA6_pin_configs[8] = {
503 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
504 0x90a70320, 0x90100211, 0x400003f1, 0x9033032e,
505};
506
Tobin Davis2c11f952007-05-17 09:36:34 +0200507static unsigned int stac925x_PA6_pin_configs[8] = {
508 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
509 0x50a103f0, 0x90100211, 0x400003f1, 0x9033032e,
510};
511
Tobin Davis8e21c342007-01-08 11:04:17 +0100512static unsigned int stac925xM2_2_pin_configs[8] = {
Steve Longerbeam7353e142007-05-29 14:36:17 +0200513 0x40c003f3, 0x424503f2, 0x04180011, 0x02a19020,
514 0x50a103f0, 0x90100212, 0x400003f1, 0x9033032e,
Tobin Davis8e21c342007-01-08 11:04:17 +0100515};
516
517static unsigned int *stac925x_brd_tbl[STAC_925x_MODELS] = {
518 [STAC_REF] = ref925x_pin_configs,
519 [STAC_M2_2] = stac925xM2_2_pin_configs,
520 [STAC_MA6] = stac925x_MA6_pin_configs,
Tobin Davis2c11f952007-05-17 09:36:34 +0200521 [STAC_PA6] = stac925x_PA6_pin_configs,
Tobin Davis8e21c342007-01-08 11:04:17 +0100522};
523
524static const char *stac925x_models[STAC_925x_MODELS] = {
525 [STAC_REF] = "ref",
526 [STAC_M2_2] = "m2-2",
527 [STAC_MA6] = "m6",
Tobin Davis2c11f952007-05-17 09:36:34 +0200528 [STAC_PA6] = "pa6",
Tobin Davis8e21c342007-01-08 11:04:17 +0100529};
530
531static struct snd_pci_quirk stac925x_cfg_tbl[] = {
532 /* SigmaTel reference board */
533 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, "DFI LanParty", STAC_REF),
Tobin Davis2c11f952007-05-17 09:36:34 +0200534 SND_PCI_QUIRK(0x8384, 0x7632, "Stac9202 Reference Board", STAC_REF),
Tobin Davis8e21c342007-01-08 11:04:17 +0100535 SND_PCI_QUIRK(0x107b, 0x0316, "Gateway M255", STAC_REF),
536 SND_PCI_QUIRK(0x107b, 0x0366, "Gateway MP6954", STAC_REF),
537 SND_PCI_QUIRK(0x107b, 0x0461, "Gateway NX560XL", STAC_MA6),
Tobin Davis2c11f952007-05-17 09:36:34 +0200538 SND_PCI_QUIRK(0x107b, 0x0681, "Gateway NX860", STAC_PA6),
Tobin Davis8e21c342007-01-08 11:04:17 +0100539 SND_PCI_QUIRK(0x1002, 0x437b, "Gateway MX6453", STAC_M2_2),
540 {} /* terminator */
541};
542
Matt Porter403d1942005-11-29 15:00:51 +0100543static unsigned int ref922x_pin_configs[10] = {
544 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
545 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
Matt2f2f4252005-04-13 14:45:30 +0200546 0x40000100, 0x40000100,
547};
548
Matt Porter403d1942005-11-29 15:00:51 +0100549static unsigned int d945gtp3_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +0100550 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
Matt Porter403d1942005-11-29 15:00:51 +0100551 0x40000100, 0x40000100, 0x40000100, 0x40000100,
552 0x02a19120, 0x40000100,
553};
554
555static unsigned int d945gtp5_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +0100556 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
557 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
Matt Porter403d1942005-11-29 15:00:51 +0100558 0x02a19320, 0x40000100,
559};
560
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +0200561static unsigned int intel_mac_v1_pin_configs[10] = {
562 0x0121e21f, 0x400000ff, 0x9017e110, 0x400000fd,
563 0x400000fe, 0x0181e020, 0x1145e030, 0x11c5e240,
Takashi Iwai3fc24d82007-02-16 13:27:18 +0100564 0x400000fc, 0x400000fb,
565};
566
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +0200567static unsigned int intel_mac_v2_pin_configs[10] = {
568 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
569 0x400000fe, 0x0181e020, 0x1145e230, 0x500000fa,
Sylvain FORETf16928f2007-04-27 14:22:36 +0200570 0x400000fc, 0x400000fb,
571};
572
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +0200573static unsigned int intel_mac_v3_pin_configs[10] = {
574 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
575 0x400000fe, 0x0181e020, 0x1145e230, 0x11c5e240,
576 0x400000fc, 0x400000fb,
577};
578
579static unsigned int intel_mac_v4_pin_configs[10] = {
580 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
581 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
582 0x400000fc, 0x400000fb,
583};
584
585static unsigned int intel_mac_v5_pin_configs[10] = {
586 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
587 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
588 0x400000fc, 0x400000fb,
Takashi Iwai0dae0f82007-05-21 12:41:29 +0200589};
590
Takashi Iwai76c08822007-06-19 12:17:42 +0200591static unsigned int stac922x_dell_pin_configs[10] = {
592 0x0221121e, 0x408103ff, 0x02a1123e, 0x90100310,
593 0x408003f1, 0x0221122f, 0x03451340, 0x40c003f2,
594 0x50a003f3, 0x405003f4
595};
596
Takashi Iwai19039bd2006-06-28 15:52:16 +0200597static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100598 [STAC_D945_REF] = ref922x_pin_configs,
Takashi Iwai19039bd2006-06-28 15:52:16 +0200599 [STAC_D945GTP3] = d945gtp3_pin_configs,
600 [STAC_D945GTP5] = d945gtp5_pin_configs,
Takashi Iwai76c08822007-06-19 12:17:42 +0200601 [STAC_922X_DELL] = stac922x_dell_pin_configs,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +0200602 [STAC_INTEL_MAC_V1] = intel_mac_v1_pin_configs,
603 [STAC_INTEL_MAC_V2] = intel_mac_v2_pin_configs,
604 [STAC_INTEL_MAC_V3] = intel_mac_v3_pin_configs,
605 [STAC_INTEL_MAC_V4] = intel_mac_v4_pin_configs,
606 [STAC_INTEL_MAC_V5] = intel_mac_v5_pin_configs,
607 /* for backward compitability */
608 [STAC_MACMINI] = intel_mac_v3_pin_configs,
609 [STAC_MACBOOK] = intel_mac_v5_pin_configs,
610 [STAC_MACBOOK_PRO_V1] = intel_mac_v3_pin_configs,
611 [STAC_MACBOOK_PRO_V2] = intel_mac_v3_pin_configs,
612 [STAC_IMAC_INTEL] = intel_mac_v2_pin_configs,
613 [STAC_IMAC_INTEL_20] = intel_mac_v3_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +0100614};
615
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100616static const char *stac922x_models[STAC_922X_MODELS] = {
617 [STAC_D945_REF] = "ref",
618 [STAC_D945GTP5] = "5stack",
619 [STAC_D945GTP3] = "3stack",
Takashi Iwai76c08822007-06-19 12:17:42 +0200620 [STAC_922X_DELL] = "dell",
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +0200621 [STAC_INTEL_MAC_V1] = "intel-mac-v1",
622 [STAC_INTEL_MAC_V2] = "intel-mac-v2",
623 [STAC_INTEL_MAC_V3] = "intel-mac-v3",
624 [STAC_INTEL_MAC_V4] = "intel-mac-v4",
625 [STAC_INTEL_MAC_V5] = "intel-mac-v5",
626 /* for backward compitability */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100627 [STAC_MACMINI] = "macmini",
Takashi Iwai3fc24d82007-02-16 13:27:18 +0100628 [STAC_MACBOOK] = "macbook",
Nicolas Boichat6f0778d2007-03-15 12:38:15 +0100629 [STAC_MACBOOK_PRO_V1] = "macbook-pro-v1",
630 [STAC_MACBOOK_PRO_V2] = "macbook-pro",
Sylvain FORETf16928f2007-04-27 14:22:36 +0200631 [STAC_IMAC_INTEL] = "imac-intel",
Takashi Iwai0dae0f82007-05-21 12:41:29 +0200632 [STAC_IMAC_INTEL_20] = "imac-intel-20",
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100633};
634
635static struct snd_pci_quirk stac922x_cfg_tbl[] = {
636 /* SigmaTel reference board */
637 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
638 "DFI LanParty", STAC_D945_REF),
639 /* Intel 945G based systems */
640 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101,
641 "Intel D945G", STAC_D945GTP3),
642 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0202,
643 "Intel D945G", STAC_D945GTP3),
644 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0606,
645 "Intel D945G", STAC_D945GTP3),
646 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0601,
647 "Intel D945G", STAC_D945GTP3),
648 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0111,
649 "Intel D945G", STAC_D945GTP3),
650 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1115,
651 "Intel D945G", STAC_D945GTP3),
652 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1116,
653 "Intel D945G", STAC_D945GTP3),
654 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1117,
655 "Intel D945G", STAC_D945GTP3),
656 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1118,
657 "Intel D945G", STAC_D945GTP3),
658 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1119,
659 "Intel D945G", STAC_D945GTP3),
660 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x8826,
661 "Intel D945G", STAC_D945GTP3),
662 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5049,
663 "Intel D945G", STAC_D945GTP3),
664 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5055,
665 "Intel D945G", STAC_D945GTP3),
666 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5048,
667 "Intel D945G", STAC_D945GTP3),
668 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0110,
669 "Intel D945G", STAC_D945GTP3),
670 /* Intel D945G 5-stack systems */
671 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0404,
672 "Intel D945G", STAC_D945GTP5),
673 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0303,
674 "Intel D945G", STAC_D945GTP5),
675 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0013,
676 "Intel D945G", STAC_D945GTP5),
677 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0417,
678 "Intel D945G", STAC_D945GTP5),
679 /* Intel 945P based systems */
680 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0b0b,
681 "Intel D945P", STAC_D945GTP3),
682 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0112,
683 "Intel D945P", STAC_D945GTP3),
684 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0d0d,
685 "Intel D945P", STAC_D945GTP3),
686 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0909,
687 "Intel D945P", STAC_D945GTP3),
688 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0505,
689 "Intel D945P", STAC_D945GTP3),
690 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707,
691 "Intel D945P", STAC_D945GTP5),
692 /* other systems */
693 /* Apple Mac Mini (early 2006) */
694 SND_PCI_QUIRK(0x8384, 0x7680,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +0200695 "Mac Mini", STAC_INTEL_MAC_V3),
Takashi Iwai76c08822007-06-19 12:17:42 +0200696 /* Dell */
697 SND_PCI_QUIRK(0x1028, 0x01d7, "Dell XPS M1210", STAC_922X_DELL),
698
Matt Porter403d1942005-11-29 15:00:51 +0100699 {} /* terminator */
700};
701
Matt Porter3cc08dc2006-01-23 15:27:49 +0100702static unsigned int ref927x_pin_configs[14] = {
Tobin Davis93ed1502006-09-01 21:03:12 +0200703 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
704 0x01a19040, 0x01011012, 0x01016011, 0x0101201f,
705 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
706 0x01c42190, 0x40000100,
Matt Porter3cc08dc2006-01-23 15:27:49 +0100707};
708
Tobin Davis93ed1502006-09-01 21:03:12 +0200709static unsigned int d965_3st_pin_configs[14] = {
Tobin Davis81d3dbd2006-08-22 19:44:45 +0200710 0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
711 0x01a19021, 0x01813024, 0x40000100, 0x40000100,
712 0x40000100, 0x40000100, 0x40000100, 0x40000100,
713 0x40000100, 0x40000100
714};
715
Tobin Davis93ed1502006-09-01 21:03:12 +0200716static unsigned int d965_5st_pin_configs[14] = {
717 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
718 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
719 0x40000100, 0x40000100, 0x40000100, 0x01442070,
720 0x40000100, 0x40000100
721};
722
Tobin Davis4ff076e2007-08-07 11:48:12 +0200723static unsigned int dell_3st_pin_configs[14] = {
724 0x02211230, 0x02a11220, 0x01a19040, 0x01114210,
725 0x01111212, 0x01116211, 0x01813050, 0x01112214,
726 0x403003fa, 0x40000100, 0x40000100, 0x404003fb,
727 0x40c003fc, 0x40000100
728};
729
Tobin Davis93ed1502006-09-01 21:03:12 +0200730static unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100731 [STAC_D965_REF] = ref927x_pin_configs,
Tobin Davis93ed1502006-09-01 21:03:12 +0200732 [STAC_D965_3ST] = d965_3st_pin_configs,
733 [STAC_D965_5ST] = d965_5st_pin_configs,
Tobin Davis4ff076e2007-08-07 11:48:12 +0200734 [STAC_DELL_3ST] = dell_3st_pin_configs,
Matt Porter3cc08dc2006-01-23 15:27:49 +0100735};
736
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100737static const char *stac927x_models[STAC_927X_MODELS] = {
738 [STAC_D965_REF] = "ref",
739 [STAC_D965_3ST] = "3stack",
740 [STAC_D965_5ST] = "5stack",
Tobin Davis4ff076e2007-08-07 11:48:12 +0200741 [STAC_DELL_3ST] = "dell-3stack",
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100742};
743
744static struct snd_pci_quirk stac927x_cfg_tbl[] = {
745 /* SigmaTel reference board */
746 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
747 "DFI LanParty", STAC_D965_REF),
Tobin Davis81d3dbd2006-08-22 19:44:45 +0200748 /* Intel 946 based systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100749 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST),
750 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST),
Tobin Davis93ed1502006-09-01 21:03:12 +0200751 /* 965 based 3 stack systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100752 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2116, "Intel D965", STAC_D965_3ST),
753 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2115, "Intel D965", STAC_D965_3ST),
754 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2114, "Intel D965", STAC_D965_3ST),
755 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2113, "Intel D965", STAC_D965_3ST),
756 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2112, "Intel D965", STAC_D965_3ST),
757 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2111, "Intel D965", STAC_D965_3ST),
758 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2110, "Intel D965", STAC_D965_3ST),
759 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2009, "Intel D965", STAC_D965_3ST),
760 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2008, "Intel D965", STAC_D965_3ST),
761 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2007, "Intel D965", STAC_D965_3ST),
762 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2006, "Intel D965", STAC_D965_3ST),
763 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2005, "Intel D965", STAC_D965_3ST),
764 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2004, "Intel D965", STAC_D965_3ST),
765 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2003, "Intel D965", STAC_D965_3ST),
766 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2002, "Intel D965", STAC_D965_3ST),
767 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2001, "Intel D965", STAC_D965_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +0200768 /* Dell 3 stack systems */
769 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01dd, "Dell E520", STAC_DELL_3ST),
770 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ed, "Dell ", STAC_DELL_3ST),
771 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f4, "Dell ", STAC_DELL_3ST),
Tobin Davis93ed1502006-09-01 21:03:12 +0200772 /* 965 based 5 stack systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100773 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2301, "Intel D965", STAC_D965_5ST),
774 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2302, "Intel D965", STAC_D965_5ST),
775 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2303, "Intel D965", STAC_D965_5ST),
776 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2304, "Intel D965", STAC_D965_5ST),
777 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2305, "Intel D965", STAC_D965_5ST),
778 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2501, "Intel D965", STAC_D965_5ST),
779 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2502, "Intel D965", STAC_D965_5ST),
780 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2503, "Intel D965", STAC_D965_5ST),
781 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2504, "Intel D965", STAC_D965_5ST),
Matt Porter3cc08dc2006-01-23 15:27:49 +0100782 {} /* terminator */
783};
784
Matt Porterf3302a52006-07-31 12:49:34 +0200785static unsigned int ref9205_pin_configs[12] = {
786 0x40000100, 0x40000100, 0x01016011, 0x01014010,
Matt Porter8b657272006-10-26 17:12:59 +0200787 0x01813122, 0x01a19021, 0x40000100, 0x40000100,
788 0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
Matt Porterf3302a52006-07-31 12:49:34 +0200789};
790
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100791static unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
Matthew Ranostay87d48362007-07-17 11:52:24 +0200792 [STAC_REF] = ref9205_pin_configs,
793 [STAC_M43xx] = NULL,
Matt Porterf3302a52006-07-31 12:49:34 +0200794};
795
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100796static const char *stac9205_models[STAC_9205_MODELS] = {
797 [STAC_9205_REF] = "ref",
798};
799
800static struct snd_pci_quirk stac9205_cfg_tbl[] = {
801 /* SigmaTel reference board */
802 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
803 "DFI LanParty", STAC_9205_REF),
Matthew Ranostay87d48362007-07-17 11:52:24 +0200804 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x01f8,
805 "Dell Precision", STAC_M43xx),
806 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x01ff,
807 "Dell Precision", STAC_M43xx),
Matt Porterf3302a52006-07-31 12:49:34 +0200808 {} /* terminator */
809};
810
Richard Fish11b44bb2006-08-23 18:31:34 +0200811static int stac92xx_save_bios_config_regs(struct hda_codec *codec)
812{
813 int i;
814 struct sigmatel_spec *spec = codec->spec;
815
816 if (! spec->bios_pin_configs) {
817 spec->bios_pin_configs = kcalloc(spec->num_pins,
818 sizeof(*spec->bios_pin_configs), GFP_KERNEL);
819 if (! spec->bios_pin_configs)
820 return -ENOMEM;
821 }
822
823 for (i = 0; i < spec->num_pins; i++) {
824 hda_nid_t nid = spec->pin_nids[i];
825 unsigned int pin_cfg;
826
827 pin_cfg = snd_hda_codec_read(codec, nid, 0,
828 AC_VERB_GET_CONFIG_DEFAULT, 0x00);
829 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x bios pin config %8.8x\n",
830 nid, pin_cfg);
831 spec->bios_pin_configs[i] = pin_cfg;
832 }
833
834 return 0;
835}
836
Matthew Ranostay87d48362007-07-17 11:52:24 +0200837static void stac92xx_set_config_reg(struct hda_codec *codec,
838 hda_nid_t pin_nid, unsigned int pin_config)
839{
840 int i;
841 snd_hda_codec_write(codec, pin_nid, 0,
842 AC_VERB_SET_CONFIG_DEFAULT_BYTES_0,
843 pin_config & 0x000000ff);
844 snd_hda_codec_write(codec, pin_nid, 0,
845 AC_VERB_SET_CONFIG_DEFAULT_BYTES_1,
846 (pin_config & 0x0000ff00) >> 8);
847 snd_hda_codec_write(codec, pin_nid, 0,
848 AC_VERB_SET_CONFIG_DEFAULT_BYTES_2,
849 (pin_config & 0x00ff0000) >> 16);
850 snd_hda_codec_write(codec, pin_nid, 0,
851 AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
852 pin_config >> 24);
853 i = snd_hda_codec_read(codec, pin_nid, 0,
854 AC_VERB_GET_CONFIG_DEFAULT,
855 0x00);
856 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x pin config %8.8x\n",
857 pin_nid, i);
858}
859
Matt2f2f4252005-04-13 14:45:30 +0200860static void stac92xx_set_config_regs(struct hda_codec *codec)
861{
862 int i;
863 struct sigmatel_spec *spec = codec->spec;
Matt2f2f4252005-04-13 14:45:30 +0200864
Matthew Ranostay87d48362007-07-17 11:52:24 +0200865 if (!spec->pin_configs)
866 return;
Richard Fish11b44bb2006-08-23 18:31:34 +0200867
Matthew Ranostay87d48362007-07-17 11:52:24 +0200868 for (i = 0; i < spec->num_pins; i++)
869 stac92xx_set_config_reg(codec, spec->pin_nids[i],
870 spec->pin_configs[i]);
Matt2f2f4252005-04-13 14:45:30 +0200871}
Matt2f2f4252005-04-13 14:45:30 +0200872
Takashi Iwai82599802007-07-31 15:56:24 +0200873static void stac92xx_enable_gpio_mask(struct hda_codec *codec)
Matthew Ranostay92a22be2007-06-19 16:48:28 +0200874{
Takashi Iwai82599802007-07-31 15:56:24 +0200875 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay87d48362007-07-17 11:52:24 +0200876 /* Configure GPIOx as output */
Matthew Ranostay92a22be2007-06-19 16:48:28 +0200877 snd_hda_codec_write(codec, codec->afg, 0,
Takashi Iwai82599802007-07-31 15:56:24 +0200878 AC_VERB_SET_GPIO_DIRECTION, spec->gpio_mask);
Matthew Ranostay87d48362007-07-17 11:52:24 +0200879 /* Configure GPIOx as CMOS */
Matthew Ranostay92a22be2007-06-19 16:48:28 +0200880 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0x00000000);
Matthew Ranostay87d48362007-07-17 11:52:24 +0200881 /* Assert GPIOx */
Matthew Ranostay92a22be2007-06-19 16:48:28 +0200882 snd_hda_codec_write(codec, codec->afg, 0,
Takashi Iwai82599802007-07-31 15:56:24 +0200883 AC_VERB_SET_GPIO_DATA, spec->gpio_data);
Matthew Ranostay87d48362007-07-17 11:52:24 +0200884 /* Enable GPIOx */
Matthew Ranostay92a22be2007-06-19 16:48:28 +0200885 snd_hda_codec_write(codec, codec->afg, 0,
Takashi Iwai82599802007-07-31 15:56:24 +0200886 AC_VERB_SET_GPIO_MASK, spec->gpio_mask);
Matthew Ranostay92a22be2007-06-19 16:48:28 +0200887}
888
Matt2f2f4252005-04-13 14:45:30 +0200889/*
890 * Analog playback callbacks
891 */
892static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
893 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100894 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200895{
896 struct sigmatel_spec *spec = codec->spec;
897 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
898}
899
900static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
901 struct hda_codec *codec,
902 unsigned int stream_tag,
903 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100904 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200905{
906 struct sigmatel_spec *spec = codec->spec;
Matt Porter403d1942005-11-29 15:00:51 +0100907 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
Matt2f2f4252005-04-13 14:45:30 +0200908}
909
910static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
911 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100912 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200913{
914 struct sigmatel_spec *spec = codec->spec;
915 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
916}
917
918/*
Mattdabbed62005-06-14 10:19:34 +0200919 * Digital playback callbacks
920 */
921static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
922 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100923 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +0200924{
925 struct sigmatel_spec *spec = codec->spec;
926 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
927}
928
929static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
930 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100931 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +0200932{
933 struct sigmatel_spec *spec = codec->spec;
934 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
935}
936
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200937static int stac92xx_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
938 struct hda_codec *codec,
939 unsigned int stream_tag,
940 unsigned int format,
941 struct snd_pcm_substream *substream)
942{
943 struct sigmatel_spec *spec = codec->spec;
944 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
945 stream_tag, format, substream);
946}
947
Mattdabbed62005-06-14 10:19:34 +0200948
949/*
Matt2f2f4252005-04-13 14:45:30 +0200950 * Analog capture callbacks
951 */
952static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
953 struct hda_codec *codec,
954 unsigned int stream_tag,
955 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100956 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200957{
958 struct sigmatel_spec *spec = codec->spec;
959
960 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
961 stream_tag, 0, format);
962 return 0;
963}
964
965static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
966 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100967 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200968{
969 struct sigmatel_spec *spec = codec->spec;
970
971 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 0, 0, 0);
972 return 0;
973}
974
Mattdabbed62005-06-14 10:19:34 +0200975static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
976 .substreams = 1,
977 .channels_min = 2,
978 .channels_max = 2,
979 /* NID is set in stac92xx_build_pcms */
980 .ops = {
981 .open = stac92xx_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200982 .close = stac92xx_dig_playback_pcm_close,
983 .prepare = stac92xx_dig_playback_pcm_prepare
Mattdabbed62005-06-14 10:19:34 +0200984 },
985};
986
987static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
988 .substreams = 1,
989 .channels_min = 2,
990 .channels_max = 2,
991 /* NID is set in stac92xx_build_pcms */
992};
993
Matt2f2f4252005-04-13 14:45:30 +0200994static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
995 .substreams = 1,
996 .channels_min = 2,
Mattc7d4b2f2005-06-27 14:59:41 +0200997 .channels_max = 8,
Matt2f2f4252005-04-13 14:45:30 +0200998 .nid = 0x02, /* NID to query formats and rates */
999 .ops = {
1000 .open = stac92xx_playback_pcm_open,
1001 .prepare = stac92xx_playback_pcm_prepare,
1002 .cleanup = stac92xx_playback_pcm_cleanup
1003 },
1004};
1005
Matt Porter3cc08dc2006-01-23 15:27:49 +01001006static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
1007 .substreams = 1,
1008 .channels_min = 2,
1009 .channels_max = 2,
1010 .nid = 0x06, /* NID to query formats and rates */
1011 .ops = {
1012 .open = stac92xx_playback_pcm_open,
1013 .prepare = stac92xx_playback_pcm_prepare,
1014 .cleanup = stac92xx_playback_pcm_cleanup
1015 },
1016};
1017
Matt2f2f4252005-04-13 14:45:30 +02001018static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
1019 .substreams = 2,
1020 .channels_min = 2,
1021 .channels_max = 2,
Matt Porter3cc08dc2006-01-23 15:27:49 +01001022 /* NID is set in stac92xx_build_pcms */
Matt2f2f4252005-04-13 14:45:30 +02001023 .ops = {
1024 .prepare = stac92xx_capture_pcm_prepare,
1025 .cleanup = stac92xx_capture_pcm_cleanup
1026 },
1027};
1028
1029static int stac92xx_build_pcms(struct hda_codec *codec)
1030{
1031 struct sigmatel_spec *spec = codec->spec;
1032 struct hda_pcm *info = spec->pcm_rec;
1033
1034 codec->num_pcms = 1;
1035 codec->pcm_info = info;
1036
Mattc7d4b2f2005-06-27 14:59:41 +02001037 info->name = "STAC92xx Analog";
Matt2f2f4252005-04-13 14:45:30 +02001038 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
Matt2f2f4252005-04-13 14:45:30 +02001039 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
Matt Porter3cc08dc2006-01-23 15:27:49 +01001040 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
1041
1042 if (spec->alt_switch) {
1043 codec->num_pcms++;
1044 info++;
1045 info->name = "STAC92xx Analog Alt";
1046 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
1047 }
Matt2f2f4252005-04-13 14:45:30 +02001048
Mattdabbed62005-06-14 10:19:34 +02001049 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
1050 codec->num_pcms++;
1051 info++;
1052 info->name = "STAC92xx Digital";
1053 if (spec->multiout.dig_out_nid) {
1054 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
1055 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
1056 }
1057 if (spec->dig_in_nid) {
1058 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
1059 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
1060 }
1061 }
1062
Matt2f2f4252005-04-13 14:45:30 +02001063 return 0;
1064}
1065
Takashi Iwaic960a032006-03-23 17:06:28 +01001066static unsigned int stac92xx_get_vref(struct hda_codec *codec, hda_nid_t nid)
1067{
1068 unsigned int pincap = snd_hda_param_read(codec, nid,
1069 AC_PAR_PIN_CAP);
1070 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
1071 if (pincap & AC_PINCAP_VREF_100)
1072 return AC_PINCTL_VREF_100;
1073 if (pincap & AC_PINCAP_VREF_80)
1074 return AC_PINCTL_VREF_80;
1075 if (pincap & AC_PINCAP_VREF_50)
1076 return AC_PINCTL_VREF_50;
1077 if (pincap & AC_PINCAP_VREF_GRD)
1078 return AC_PINCTL_VREF_GRD;
1079 return 0;
1080}
1081
Matt Porter403d1942005-11-29 15:00:51 +01001082static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
1083
1084{
1085 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
1086}
1087
Takashi Iwaia5ce8892007-07-23 15:42:26 +02001088#define stac92xx_io_switch_info snd_ctl_boolean_mono_info
Matt Porter403d1942005-11-29 15:00:51 +01001089
1090static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1091{
1092 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1093 struct sigmatel_spec *spec = codec->spec;
1094 int io_idx = kcontrol-> private_value & 0xff;
1095
1096 ucontrol->value.integer.value[0] = spec->io_switch[io_idx];
1097 return 0;
1098}
1099
1100static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1101{
1102 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1103 struct sigmatel_spec *spec = codec->spec;
1104 hda_nid_t nid = kcontrol->private_value >> 8;
1105 int io_idx = kcontrol-> private_value & 0xff;
1106 unsigned short val = ucontrol->value.integer.value[0];
1107
1108 spec->io_switch[io_idx] = val;
1109
1110 if (val)
1111 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
Takashi Iwaic960a032006-03-23 17:06:28 +01001112 else {
1113 unsigned int pinctl = AC_PINCTL_IN_EN;
1114 if (io_idx) /* set VREF for mic */
1115 pinctl |= stac92xx_get_vref(codec, nid);
1116 stac92xx_auto_set_pinctl(codec, nid, pinctl);
1117 }
Matt Porter403d1942005-11-29 15:00:51 +01001118 return 1;
1119}
1120
1121#define STAC_CODEC_IO_SWITCH(xname, xpval) \
1122 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1123 .name = xname, \
1124 .index = 0, \
1125 .info = stac92xx_io_switch_info, \
1126 .get = stac92xx_io_switch_get, \
1127 .put = stac92xx_io_switch_put, \
1128 .private_value = xpval, \
1129 }
1130
1131
Mattc7d4b2f2005-06-27 14:59:41 +02001132enum {
1133 STAC_CTL_WIDGET_VOL,
1134 STAC_CTL_WIDGET_MUTE,
Matt Porter403d1942005-11-29 15:00:51 +01001135 STAC_CTL_WIDGET_IO_SWITCH,
Mattc7d4b2f2005-06-27 14:59:41 +02001136};
1137
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001138static struct snd_kcontrol_new stac92xx_control_templates[] = {
Mattc7d4b2f2005-06-27 14:59:41 +02001139 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
1140 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Matt Porter403d1942005-11-29 15:00:51 +01001141 STAC_CODEC_IO_SWITCH(NULL, 0),
Mattc7d4b2f2005-06-27 14:59:41 +02001142};
1143
1144/* add dynamic controls */
1145static int stac92xx_add_control(struct sigmatel_spec *spec, int type, const char *name, unsigned long val)
1146{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001147 struct snd_kcontrol_new *knew;
Mattc7d4b2f2005-06-27 14:59:41 +02001148
1149 if (spec->num_kctl_used >= spec->num_kctl_alloc) {
1150 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
1151
1152 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */
1153 if (! knew)
1154 return -ENOMEM;
1155 if (spec->kctl_alloc) {
1156 memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
1157 kfree(spec->kctl_alloc);
1158 }
1159 spec->kctl_alloc = knew;
1160 spec->num_kctl_alloc = num;
1161 }
1162
1163 knew = &spec->kctl_alloc[spec->num_kctl_used];
1164 *knew = stac92xx_control_templates[type];
Takashi Iwai82fe0c52005-06-30 10:54:33 +02001165 knew->name = kstrdup(name, GFP_KERNEL);
Mattc7d4b2f2005-06-27 14:59:41 +02001166 if (! knew->name)
1167 return -ENOMEM;
1168 knew->private_value = val;
1169 spec->num_kctl_used++;
1170 return 0;
1171}
1172
Matt Porter403d1942005-11-29 15:00:51 +01001173/* flag inputs as additional dynamic lineouts */
1174static int stac92xx_add_dyn_out_pins(struct hda_codec *codec, struct auto_pin_cfg *cfg)
1175{
1176 struct sigmatel_spec *spec = codec->spec;
Steve Longerbeam7b043892007-05-03 20:50:03 +02001177 unsigned int wcaps, wtype;
1178 int i, num_dacs = 0;
1179
1180 /* use the wcaps cache to count all DACs available for line-outs */
1181 for (i = 0; i < codec->num_nodes; i++) {
1182 wcaps = codec->wcaps[i];
1183 wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
1184 if (wtype == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL))
1185 num_dacs++;
1186 }
Matt Porter403d1942005-11-29 15:00:51 +01001187
Steve Longerbeam7b043892007-05-03 20:50:03 +02001188 snd_printdd("%s: total dac count=%d\n", __func__, num_dacs);
1189
Matt Porter403d1942005-11-29 15:00:51 +01001190 switch (cfg->line_outs) {
1191 case 3:
1192 /* add line-in as side */
Steve Longerbeam7b043892007-05-03 20:50:03 +02001193 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 3) {
Matt Porter403d1942005-11-29 15:00:51 +01001194 cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_LINE];
1195 spec->line_switch = 1;
1196 cfg->line_outs++;
1197 }
1198 break;
1199 case 2:
1200 /* add line-in as clfe and mic as side */
Steve Longerbeam7b043892007-05-03 20:50:03 +02001201 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 2) {
Matt Porter403d1942005-11-29 15:00:51 +01001202 cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_LINE];
1203 spec->line_switch = 1;
1204 cfg->line_outs++;
1205 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02001206 if (cfg->input_pins[AUTO_PIN_MIC] && num_dacs > 3) {
Matt Porter403d1942005-11-29 15:00:51 +01001207 cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_MIC];
1208 spec->mic_switch = 1;
1209 cfg->line_outs++;
1210 }
1211 break;
1212 case 1:
1213 /* add line-in as surr and mic as clfe */
Steve Longerbeam7b043892007-05-03 20:50:03 +02001214 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 1) {
Matt Porter403d1942005-11-29 15:00:51 +01001215 cfg->line_out_pins[1] = cfg->input_pins[AUTO_PIN_LINE];
1216 spec->line_switch = 1;
1217 cfg->line_outs++;
1218 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02001219 if (cfg->input_pins[AUTO_PIN_MIC] && num_dacs > 2) {
Matt Porter403d1942005-11-29 15:00:51 +01001220 cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_MIC];
1221 spec->mic_switch = 1;
1222 cfg->line_outs++;
1223 }
1224 break;
1225 }
1226
1227 return 0;
1228}
1229
Steve Longerbeam7b043892007-05-03 20:50:03 +02001230
1231static int is_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
1232{
1233 int i;
1234
1235 for (i = 0; i < spec->multiout.num_dacs; i++) {
1236 if (spec->multiout.dac_nids[i] == nid)
1237 return 1;
1238 }
1239
1240 return 0;
1241}
1242
Matt Porter3cc08dc2006-01-23 15:27:49 +01001243/*
Steve Longerbeam7b043892007-05-03 20:50:03 +02001244 * Fill in the dac_nids table from the parsed pin configuration
1245 * This function only works when every pin in line_out_pins[]
1246 * contains atleast one DAC in its connection list. Some 92xx
1247 * codecs are not connected directly to a DAC, such as the 9200
1248 * and 9202/925x. For those, dac_nids[] must be hard-coded.
Matt Porter3cc08dc2006-01-23 15:27:49 +01001249 */
Takashi Iwai19039bd2006-06-28 15:52:16 +02001250static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec,
Takashi Iwaidf802952007-07-02 19:18:00 +02001251 struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02001252{
1253 struct sigmatel_spec *spec = codec->spec;
Steve Longerbeam7b043892007-05-03 20:50:03 +02001254 int i, j, conn_len = 0;
1255 hda_nid_t nid, conn[HDA_MAX_CONNECTIONS];
1256 unsigned int wcaps, wtype;
1257
Mattc7d4b2f2005-06-27 14:59:41 +02001258 for (i = 0; i < cfg->line_outs; i++) {
1259 nid = cfg->line_out_pins[i];
Steve Longerbeam7b043892007-05-03 20:50:03 +02001260 conn_len = snd_hda_get_connections(codec, nid, conn,
1261 HDA_MAX_CONNECTIONS);
1262 for (j = 0; j < conn_len; j++) {
1263 wcaps = snd_hda_param_read(codec, conn[j],
1264 AC_PAR_AUDIO_WIDGET_CAP);
1265 wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
1266
1267 if (wtype != AC_WID_AUD_OUT ||
1268 (wcaps & AC_WCAP_DIGITAL))
1269 continue;
1270 /* conn[j] is a DAC routed to this line-out */
1271 if (!is_in_dac_nids(spec, conn[j]))
1272 break;
1273 }
1274
1275 if (j == conn_len) {
Takashi Iwaidf802952007-07-02 19:18:00 +02001276 if (spec->multiout.num_dacs > 0) {
1277 /* we have already working output pins,
1278 * so let's drop the broken ones again
1279 */
1280 cfg->line_outs = spec->multiout.num_dacs;
1281 break;
1282 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02001283 /* error out, no available DAC found */
1284 snd_printk(KERN_ERR
1285 "%s: No available DAC for pin 0x%x\n",
1286 __func__, nid);
1287 return -ENODEV;
1288 }
1289
1290 spec->multiout.dac_nids[i] = conn[j];
1291 spec->multiout.num_dacs++;
1292 if (conn_len > 1) {
1293 /* select this DAC in the pin's input mux */
1294 snd_hda_codec_write(codec, nid, 0,
1295 AC_VERB_SET_CONNECT_SEL, j);
1296
1297 }
Mattc7d4b2f2005-06-27 14:59:41 +02001298 }
1299
Steve Longerbeam7b043892007-05-03 20:50:03 +02001300 snd_printd("dac_nids=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
1301 spec->multiout.num_dacs,
1302 spec->multiout.dac_nids[0],
1303 spec->multiout.dac_nids[1],
1304 spec->multiout.dac_nids[2],
1305 spec->multiout.dac_nids[3],
1306 spec->multiout.dac_nids[4]);
Mattc7d4b2f2005-06-27 14:59:41 +02001307 return 0;
1308}
1309
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001310/* create volume control/switch for the given prefx type */
1311static int create_controls(struct sigmatel_spec *spec, const char *pfx, hda_nid_t nid, int chs)
1312{
1313 char name[32];
1314 int err;
1315
1316 sprintf(name, "%s Playback Volume", pfx);
1317 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, name,
1318 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1319 if (err < 0)
1320 return err;
1321 sprintf(name, "%s Playback Switch", pfx);
1322 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, name,
1323 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1324 if (err < 0)
1325 return err;
1326 return 0;
1327}
1328
Mattc7d4b2f2005-06-27 14:59:41 +02001329/* add playback controls from the parsed DAC table */
Takashi Iwai19039bd2006-06-28 15:52:16 +02001330static int stac92xx_auto_create_multi_out_ctls(struct sigmatel_spec *spec,
1331 const struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02001332{
Takashi Iwai19039bd2006-06-28 15:52:16 +02001333 static const char *chname[4] = {
1334 "Front", "Surround", NULL /*CLFE*/, "Side"
1335 };
Mattc7d4b2f2005-06-27 14:59:41 +02001336 hda_nid_t nid;
1337 int i, err;
1338
1339 for (i = 0; i < cfg->line_outs; i++) {
Matt Porter403d1942005-11-29 15:00:51 +01001340 if (!spec->multiout.dac_nids[i])
Mattc7d4b2f2005-06-27 14:59:41 +02001341 continue;
1342
1343 nid = spec->multiout.dac_nids[i];
1344
1345 if (i == 2) {
1346 /* Center/LFE */
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001347 err = create_controls(spec, "Center", nid, 1);
1348 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001349 return err;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001350 err = create_controls(spec, "LFE", nid, 2);
1351 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001352 return err;
1353 } else {
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001354 err = create_controls(spec, chname[i], nid, 3);
1355 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001356 return err;
1357 }
1358 }
1359
Matt Porter403d1942005-11-29 15:00:51 +01001360 if (spec->line_switch)
1361 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Line In as Output Switch", cfg->input_pins[AUTO_PIN_LINE] << 8)) < 0)
1362 return err;
1363
1364 if (spec->mic_switch)
1365 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Mic as Output Switch", (cfg->input_pins[AUTO_PIN_MIC] << 8) | 1)) < 0)
1366 return err;
1367
Mattc7d4b2f2005-06-27 14:59:41 +02001368 return 0;
1369}
1370
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001371static int check_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
1372{
Steve Longerbeam7b043892007-05-03 20:50:03 +02001373 if (is_in_dac_nids(spec, nid))
1374 return 1;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001375 if (spec->multiout.hp_nid == nid)
1376 return 1;
1377 return 0;
1378}
1379
1380static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
1381{
1382 if (!spec->multiout.hp_nid)
1383 spec->multiout.hp_nid = nid;
1384 else if (spec->multiout.num_dacs > 4) {
1385 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
1386 return 1;
1387 } else {
1388 spec->multiout.dac_nids[spec->multiout.num_dacs] = nid;
1389 spec->multiout.num_dacs++;
1390 }
1391 return 0;
1392}
1393
1394/* add playback controls for Speaker and HP outputs */
1395static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
1396 struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02001397{
1398 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02001399 hda_nid_t nid;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001400 int i, old_num_dacs, err;
Mattc7d4b2f2005-06-27 14:59:41 +02001401
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001402 old_num_dacs = spec->multiout.num_dacs;
1403 for (i = 0; i < cfg->hp_outs; i++) {
1404 unsigned int wid_caps = get_wcaps(codec, cfg->hp_pins[i]);
1405 if (wid_caps & AC_WCAP_UNSOL_CAP)
1406 spec->hp_detect = 1;
1407 nid = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
1408 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
1409 if (check_in_dac_nids(spec, nid))
1410 nid = 0;
1411 if (! nid)
Mattc7d4b2f2005-06-27 14:59:41 +02001412 continue;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001413 add_spec_dacs(spec, nid);
1414 }
1415 for (i = 0; i < cfg->speaker_outs; i++) {
Steve Longerbeam7b043892007-05-03 20:50:03 +02001416 nid = snd_hda_codec_read(codec, cfg->speaker_pins[i], 0,
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001417 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
1418 if (check_in_dac_nids(spec, nid))
1419 nid = 0;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001420 if (! nid)
1421 continue;
1422 add_spec_dacs(spec, nid);
Mattc7d4b2f2005-06-27 14:59:41 +02001423 }
Matthew Ranostay1b290a52007-07-12 15:17:34 +02001424 for (i = 0; i < cfg->line_outs; i++) {
1425 nid = snd_hda_codec_read(codec, cfg->line_out_pins[i], 0,
1426 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
1427 if (check_in_dac_nids(spec, nid))
1428 nid = 0;
1429 if (! nid)
1430 continue;
1431 add_spec_dacs(spec, nid);
1432 }
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001433 for (i = old_num_dacs; i < spec->multiout.num_dacs; i++) {
1434 static const char *pfxs[] = {
1435 "Speaker", "External Speaker", "Speaker2",
1436 };
1437 err = create_controls(spec, pfxs[i - old_num_dacs],
1438 spec->multiout.dac_nids[i], 3);
1439 if (err < 0)
1440 return err;
1441 }
1442 if (spec->multiout.hp_nid) {
1443 const char *pfx;
1444 if (old_num_dacs == spec->multiout.num_dacs)
1445 pfx = "Master";
1446 else
1447 pfx = "Headphone";
1448 err = create_controls(spec, pfx, spec->multiout.hp_nid, 3);
1449 if (err < 0)
1450 return err;
1451 }
Mattc7d4b2f2005-06-27 14:59:41 +02001452
1453 return 0;
1454}
1455
Matt Porter8b657272006-10-26 17:12:59 +02001456/* labels for dmic mux inputs */
Adrian Bunkddc2cec2006-11-20 12:03:44 +01001457static const char *stac92xx_dmic_labels[5] = {
Matt Porter8b657272006-10-26 17:12:59 +02001458 "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
1459 "Digital Mic 3", "Digital Mic 4"
1460};
1461
1462/* create playback/capture controls for input pins on dmic capable codecs */
1463static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
1464 const struct auto_pin_cfg *cfg)
1465{
1466 struct sigmatel_spec *spec = codec->spec;
1467 struct hda_input_mux *dimux = &spec->private_dimux;
1468 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
1469 int i, j;
1470
1471 dimux->items[dimux->num_items].label = stac92xx_dmic_labels[0];
1472 dimux->items[dimux->num_items].index = 0;
1473 dimux->num_items++;
1474
1475 for (i = 0; i < spec->num_dmics; i++) {
1476 int index;
1477 int num_cons;
1478 unsigned int def_conf;
1479
1480 def_conf = snd_hda_codec_read(codec,
1481 spec->dmic_nids[i],
1482 0,
1483 AC_VERB_GET_CONFIG_DEFAULT,
1484 0);
1485 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
1486 continue;
1487
1488 num_cons = snd_hda_get_connections(codec,
1489 spec->dmux_nid,
1490 con_lst,
1491 HDA_MAX_NUM_INPUTS);
1492 for (j = 0; j < num_cons; j++)
1493 if (con_lst[j] == spec->dmic_nids[i]) {
1494 index = j;
1495 goto found;
1496 }
1497 continue;
1498found:
1499 dimux->items[dimux->num_items].label =
1500 stac92xx_dmic_labels[dimux->num_items];
1501 dimux->items[dimux->num_items].index = index;
1502 dimux->num_items++;
1503 }
1504
1505 return 0;
1506}
1507
Mattc7d4b2f2005-06-27 14:59:41 +02001508/* create playback/capture controls for input pins */
1509static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
1510{
1511 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02001512 struct hda_input_mux *imux = &spec->private_imux;
1513 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
1514 int i, j, k;
1515
1516 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwai314634b2006-09-21 11:56:18 +02001517 int index;
Mattc7d4b2f2005-06-27 14:59:41 +02001518
Takashi Iwai314634b2006-09-21 11:56:18 +02001519 if (!cfg->input_pins[i])
1520 continue;
1521 index = -1;
1522 for (j = 0; j < spec->num_muxes; j++) {
1523 int num_cons;
1524 num_cons = snd_hda_get_connections(codec,
1525 spec->mux_nids[j],
1526 con_lst,
1527 HDA_MAX_NUM_INPUTS);
1528 for (k = 0; k < num_cons; k++)
1529 if (con_lst[k] == cfg->input_pins[i]) {
1530 index = k;
1531 goto found;
1532 }
Mattc7d4b2f2005-06-27 14:59:41 +02001533 }
Takashi Iwai314634b2006-09-21 11:56:18 +02001534 continue;
1535 found:
1536 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
1537 imux->items[imux->num_items].index = index;
1538 imux->num_items++;
Mattc7d4b2f2005-06-27 14:59:41 +02001539 }
1540
Steve Longerbeam7b043892007-05-03 20:50:03 +02001541 if (imux->num_items) {
Sam Revitch62fe78e2006-05-10 15:09:17 +02001542 /*
1543 * Set the current input for the muxes.
1544 * The STAC9221 has two input muxes with identical source
1545 * NID lists. Hopefully this won't get confused.
1546 */
1547 for (i = 0; i < spec->num_muxes; i++) {
1548 snd_hda_codec_write(codec, spec->mux_nids[i], 0,
1549 AC_VERB_SET_CONNECT_SEL,
1550 imux->items[0].index);
1551 }
1552 }
1553
Mattc7d4b2f2005-06-27 14:59:41 +02001554 return 0;
1555}
1556
Mattc7d4b2f2005-06-27 14:59:41 +02001557static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
1558{
1559 struct sigmatel_spec *spec = codec->spec;
1560 int i;
1561
1562 for (i = 0; i < spec->autocfg.line_outs; i++) {
1563 hda_nid_t nid = spec->autocfg.line_out_pins[i];
1564 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
1565 }
1566}
1567
1568static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
1569{
1570 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001571 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02001572
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001573 for (i = 0; i < spec->autocfg.hp_outs; i++) {
1574 hda_nid_t pin;
1575 pin = spec->autocfg.hp_pins[i];
1576 if (pin) /* connect to front */
1577 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
1578 }
1579 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
1580 hda_nid_t pin;
1581 pin = spec->autocfg.speaker_pins[i];
1582 if (pin) /* connect to front */
1583 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
1584 }
Mattc7d4b2f2005-06-27 14:59:41 +02001585}
1586
Matt Porter3cc08dc2006-01-23 15:27:49 +01001587static 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 +02001588{
1589 struct sigmatel_spec *spec = codec->spec;
1590 int err;
1591
Matt Porter8b657272006-10-26 17:12:59 +02001592 if ((err = snd_hda_parse_pin_def_config(codec,
1593 &spec->autocfg,
1594 spec->dmic_nids)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001595 return err;
Takashi Iwai82bc9552006-03-21 11:24:42 +01001596 if (! spec->autocfg.line_outs)
Matt Porter869264c2006-01-25 19:20:50 +01001597 return 0; /* can't find valid pin config */
Takashi Iwai19039bd2006-06-28 15:52:16 +02001598
Matt Porter403d1942005-11-29 15:00:51 +01001599 if ((err = stac92xx_add_dyn_out_pins(codec, &spec->autocfg)) < 0)
1600 return err;
Takashi Iwai19039bd2006-06-28 15:52:16 +02001601 if (spec->multiout.num_dacs == 0)
1602 if ((err = stac92xx_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
1603 return err;
Mattc7d4b2f2005-06-27 14:59:41 +02001604
1605 if ((err = stac92xx_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
1606 (err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg)) < 0 ||
1607 (err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
1608 return err;
1609
Matt Porter8b657272006-10-26 17:12:59 +02001610 if (spec->num_dmics > 0)
1611 if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
1612 &spec->autocfg)) < 0)
1613 return err;
1614
Mattc7d4b2f2005-06-27 14:59:41 +02001615 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Matt Porter403d1942005-11-29 15:00:51 +01001616 if (spec->multiout.max_channels > 2)
Mattc7d4b2f2005-06-27 14:59:41 +02001617 spec->surr_switch = 1;
Mattc7d4b2f2005-06-27 14:59:41 +02001618
Takashi Iwai82bc9552006-03-21 11:24:42 +01001619 if (spec->autocfg.dig_out_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01001620 spec->multiout.dig_out_nid = dig_out;
Takashi Iwai82bc9552006-03-21 11:24:42 +01001621 if (spec->autocfg.dig_in_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01001622 spec->dig_in_nid = dig_in;
Mattc7d4b2f2005-06-27 14:59:41 +02001623
1624 if (spec->kctl_alloc)
1625 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
1626
1627 spec->input_mux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02001628 spec->dinput_mux = &spec->private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +02001629
1630 return 1;
1631}
1632
Takashi Iwai82bc9552006-03-21 11:24:42 +01001633/* add playback controls for HP output */
1634static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
1635 struct auto_pin_cfg *cfg)
1636{
1637 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001638 hda_nid_t pin = cfg->hp_pins[0];
Takashi Iwai82bc9552006-03-21 11:24:42 +01001639 unsigned int wid_caps;
1640
1641 if (! pin)
1642 return 0;
1643
1644 wid_caps = get_wcaps(codec, pin);
Takashi Iwai505cb342006-03-27 12:51:52 +02001645 if (wid_caps & AC_WCAP_UNSOL_CAP)
Takashi Iwai82bc9552006-03-21 11:24:42 +01001646 spec->hp_detect = 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +01001647
1648 return 0;
1649}
1650
Richard Fish160ea0d2006-09-06 13:58:25 +02001651/* add playback controls for LFE output */
1652static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
1653 struct auto_pin_cfg *cfg)
1654{
1655 struct sigmatel_spec *spec = codec->spec;
1656 int err;
1657 hda_nid_t lfe_pin = 0x0;
1658 int i;
1659
1660 /*
1661 * search speaker outs and line outs for a mono speaker pin
1662 * with an amp. If one is found, add LFE controls
1663 * for it.
1664 */
1665 for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
1666 hda_nid_t pin = spec->autocfg.speaker_pins[i];
1667 unsigned long wcaps = get_wcaps(codec, pin);
1668 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
1669 if (wcaps == AC_WCAP_OUT_AMP)
1670 /* found a mono speaker with an amp, must be lfe */
1671 lfe_pin = pin;
1672 }
1673
1674 /* if speaker_outs is 0, then speakers may be in line_outs */
1675 if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
1676 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
1677 hda_nid_t pin = spec->autocfg.line_out_pins[i];
1678 unsigned long cfg;
1679 cfg = snd_hda_codec_read(codec, pin, 0,
1680 AC_VERB_GET_CONFIG_DEFAULT,
1681 0x00);
1682 if (get_defcfg_device(cfg) == AC_JACK_SPEAKER) {
1683 unsigned long wcaps = get_wcaps(codec, pin);
1684 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
1685 if (wcaps == AC_WCAP_OUT_AMP)
1686 /* found a mono speaker with an amp,
1687 must be lfe */
1688 lfe_pin = pin;
1689 }
1690 }
1691 }
1692
1693 if (lfe_pin) {
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001694 err = create_controls(spec, "LFE", lfe_pin, 1);
Richard Fish160ea0d2006-09-06 13:58:25 +02001695 if (err < 0)
1696 return err;
1697 }
1698
1699 return 0;
1700}
1701
Mattc7d4b2f2005-06-27 14:59:41 +02001702static int stac9200_parse_auto_config(struct hda_codec *codec)
1703{
1704 struct sigmatel_spec *spec = codec->spec;
1705 int err;
1706
Kailang Yangdf694da2005-12-05 19:42:22 +01001707 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001708 return err;
1709
1710 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
1711 return err;
1712
Takashi Iwai82bc9552006-03-21 11:24:42 +01001713 if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
1714 return err;
1715
Richard Fish160ea0d2006-09-06 13:58:25 +02001716 if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
1717 return err;
1718
Takashi Iwai82bc9552006-03-21 11:24:42 +01001719 if (spec->autocfg.dig_out_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02001720 spec->multiout.dig_out_nid = 0x05;
Takashi Iwai82bc9552006-03-21 11:24:42 +01001721 if (spec->autocfg.dig_in_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02001722 spec->dig_in_nid = 0x04;
Mattc7d4b2f2005-06-27 14:59:41 +02001723
1724 if (spec->kctl_alloc)
1725 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
1726
1727 spec->input_mux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02001728 spec->dinput_mux = &spec->private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +02001729
1730 return 1;
1731}
1732
Sam Revitch62fe78e2006-05-10 15:09:17 +02001733/*
1734 * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
1735 * funky external mute control using GPIO pins.
1736 */
1737
1738static void stac922x_gpio_mute(struct hda_codec *codec, int pin, int muted)
1739{
1740 unsigned int gpiostate, gpiomask, gpiodir;
1741
1742 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
1743 AC_VERB_GET_GPIO_DATA, 0);
1744
1745 if (!muted)
1746 gpiostate |= (1 << pin);
1747 else
1748 gpiostate &= ~(1 << pin);
1749
1750 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
1751 AC_VERB_GET_GPIO_MASK, 0);
1752 gpiomask |= (1 << pin);
1753
1754 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
1755 AC_VERB_GET_GPIO_DIRECTION, 0);
1756 gpiodir |= (1 << pin);
1757
1758 /* AppleHDA seems to do this -- WTF is this verb?? */
1759 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
1760
1761 snd_hda_codec_write(codec, codec->afg, 0,
1762 AC_VERB_SET_GPIO_MASK, gpiomask);
1763 snd_hda_codec_write(codec, codec->afg, 0,
1764 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
1765
1766 msleep(1);
1767
1768 snd_hda_codec_write(codec, codec->afg, 0,
1769 AC_VERB_SET_GPIO_DATA, gpiostate);
1770}
1771
Takashi Iwai314634b2006-09-21 11:56:18 +02001772static void enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
1773 unsigned int event)
1774{
1775 if (get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP)
1776 snd_hda_codec_write(codec, nid, 0,
1777 AC_VERB_SET_UNSOLICITED_ENABLE,
1778 (AC_USRSP_EN | event));
1779}
1780
Mattc7d4b2f2005-06-27 14:59:41 +02001781static int stac92xx_init(struct hda_codec *codec)
1782{
1783 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai82bc9552006-03-21 11:24:42 +01001784 struct auto_pin_cfg *cfg = &spec->autocfg;
1785 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02001786
Mattc7d4b2f2005-06-27 14:59:41 +02001787 snd_hda_sequence_write(codec, spec->init);
1788
Takashi Iwai82bc9552006-03-21 11:24:42 +01001789 /* set up pins */
1790 if (spec->hp_detect) {
Takashi Iwai505cb342006-03-27 12:51:52 +02001791 /* Enable unsolicited responses on the HP widget */
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001792 for (i = 0; i < cfg->hp_outs; i++)
Takashi Iwai314634b2006-09-21 11:56:18 +02001793 enable_pin_detect(codec, cfg->hp_pins[i],
1794 STAC_HP_EVENT);
Takashi Iwai0a07acaf2007-03-13 10:40:23 +01001795 /* force to enable the first line-out; the others are set up
1796 * in unsol_event
1797 */
1798 stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
1799 AC_PINCTL_OUT_EN);
Takashi Iwaieb995a82006-09-21 14:28:21 +02001800 stac92xx_auto_init_hp_out(codec);
Takashi Iwai82bc9552006-03-21 11:24:42 +01001801 /* fake event to set up pins */
1802 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
1803 } else {
1804 stac92xx_auto_init_multi_out(codec);
1805 stac92xx_auto_init_hp_out(codec);
1806 }
1807 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwaic960a032006-03-23 17:06:28 +01001808 hda_nid_t nid = cfg->input_pins[i];
1809 if (nid) {
1810 unsigned int pinctl = AC_PINCTL_IN_EN;
1811 if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC)
1812 pinctl |= stac92xx_get_vref(codec, nid);
1813 stac92xx_auto_set_pinctl(codec, nid, pinctl);
1814 }
Takashi Iwai82bc9552006-03-21 11:24:42 +01001815 }
Matt Porter8b657272006-10-26 17:12:59 +02001816 if (spec->num_dmics > 0)
1817 for (i = 0; i < spec->num_dmics; i++)
1818 stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
1819 AC_PINCTL_IN_EN);
1820
Takashi Iwai82bc9552006-03-21 11:24:42 +01001821 if (cfg->dig_out_pin)
1822 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pin,
1823 AC_PINCTL_OUT_EN);
1824 if (cfg->dig_in_pin)
1825 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
1826 AC_PINCTL_IN_EN);
1827
Sam Revitch62fe78e2006-05-10 15:09:17 +02001828 if (spec->gpio_mute) {
1829 stac922x_gpio_mute(codec, 0, 0);
1830 stac922x_gpio_mute(codec, 1, 0);
1831 }
1832
Mattc7d4b2f2005-06-27 14:59:41 +02001833 return 0;
1834}
1835
Matt2f2f4252005-04-13 14:45:30 +02001836static void stac92xx_free(struct hda_codec *codec)
1837{
Mattc7d4b2f2005-06-27 14:59:41 +02001838 struct sigmatel_spec *spec = codec->spec;
1839 int i;
1840
1841 if (! spec)
1842 return;
1843
1844 if (spec->kctl_alloc) {
1845 for (i = 0; i < spec->num_kctl_used; i++)
1846 kfree(spec->kctl_alloc[i].name);
1847 kfree(spec->kctl_alloc);
1848 }
1849
Richard Fish11b44bb2006-08-23 18:31:34 +02001850 if (spec->bios_pin_configs)
1851 kfree(spec->bios_pin_configs);
1852
Mattc7d4b2f2005-06-27 14:59:41 +02001853 kfree(spec);
Matt2f2f4252005-04-13 14:45:30 +02001854}
1855
Matt4e550962005-07-04 17:51:39 +02001856static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
1857 unsigned int flag)
1858{
1859 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
1860 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Steve Longerbeam7b043892007-05-03 20:50:03 +02001861
Takashi Iwaif9acba42007-05-29 18:01:06 +02001862 if (pin_ctl & AC_PINCTL_IN_EN) {
1863 /*
1864 * we need to check the current set-up direction of
1865 * shared input pins since they can be switched via
1866 * "xxx as Output" mixer switch
1867 */
1868 struct sigmatel_spec *spec = codec->spec;
1869 struct auto_pin_cfg *cfg = &spec->autocfg;
1870 if ((nid == cfg->input_pins[AUTO_PIN_LINE] &&
1871 spec->line_switch) ||
1872 (nid == cfg->input_pins[AUTO_PIN_MIC] &&
1873 spec->mic_switch))
1874 return;
1875 }
1876
Steve Longerbeam7b043892007-05-03 20:50:03 +02001877 /* if setting pin direction bits, clear the current
1878 direction bits first */
1879 if (flag & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))
1880 pin_ctl &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
1881
Matt4e550962005-07-04 17:51:39 +02001882 snd_hda_codec_write(codec, nid, 0,
1883 AC_VERB_SET_PIN_WIDGET_CONTROL,
1884 pin_ctl | flag);
1885}
1886
1887static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
1888 unsigned int flag)
1889{
1890 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
1891 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
1892 snd_hda_codec_write(codec, nid, 0,
1893 AC_VERB_SET_PIN_WIDGET_CONTROL,
1894 pin_ctl & ~flag);
1895}
1896
Takashi Iwai314634b2006-09-21 11:56:18 +02001897static int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
1898{
1899 if (!nid)
1900 return 0;
1901 if (snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PIN_SENSE, 0x00)
1902 & (1 << 31))
1903 return 1;
1904 return 0;
1905}
1906
1907static void stac92xx_hp_detect(struct hda_codec *codec, unsigned int res)
Matt4e550962005-07-04 17:51:39 +02001908{
1909 struct sigmatel_spec *spec = codec->spec;
1910 struct auto_pin_cfg *cfg = &spec->autocfg;
1911 int i, presence;
1912
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001913 presence = 0;
1914 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai314634b2006-09-21 11:56:18 +02001915 presence = get_pin_presence(codec, cfg->hp_pins[i]);
1916 if (presence)
1917 break;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001918 }
Matt4e550962005-07-04 17:51:39 +02001919
1920 if (presence) {
1921 /* disable lineouts, enable hp */
1922 for (i = 0; i < cfg->line_outs; i++)
1923 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
1924 AC_PINCTL_OUT_EN);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001925 for (i = 0; i < cfg->speaker_outs; i++)
1926 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
1927 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02001928 } else {
1929 /* enable lineouts, disable hp */
1930 for (i = 0; i < cfg->line_outs; i++)
1931 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
1932 AC_PINCTL_OUT_EN);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001933 for (i = 0; i < cfg->speaker_outs; i++)
1934 stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
1935 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02001936 }
1937}
1938
Takashi Iwai314634b2006-09-21 11:56:18 +02001939static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
1940{
1941 switch (res >> 26) {
1942 case STAC_HP_EVENT:
1943 stac92xx_hp_detect(codec, res);
1944 break;
1945 }
1946}
1947
Mattff6fdc32005-06-27 15:06:52 +02001948#ifdef CONFIG_PM
1949static int stac92xx_resume(struct hda_codec *codec)
1950{
1951 struct sigmatel_spec *spec = codec->spec;
1952 int i;
1953
Richard Fish11b44bb2006-08-23 18:31:34 +02001954 stac92xx_set_config_regs(codec);
Takashi Iwai82599802007-07-31 15:56:24 +02001955 if (spec->gpio_mask && spec->gpio_data)
1956 stac92xx_enable_gpio_mask(codec);
1957 stac92xx_init(codec);
Takashi Iwai5d403b12007-05-03 12:32:29 +02001958 snd_hda_resume_ctls(codec, spec->mixer);
Mattff6fdc32005-06-27 15:06:52 +02001959 for (i = 0; i < spec->num_mixers; i++)
1960 snd_hda_resume_ctls(codec, spec->mixers[i]);
1961 if (spec->multiout.dig_out_nid)
1962 snd_hda_resume_spdif_out(codec);
1963 if (spec->dig_in_nid)
1964 snd_hda_resume_spdif_in(codec);
1965
1966 return 0;
1967}
1968#endif
1969
Matt2f2f4252005-04-13 14:45:30 +02001970static struct hda_codec_ops stac92xx_patch_ops = {
1971 .build_controls = stac92xx_build_controls,
1972 .build_pcms = stac92xx_build_pcms,
1973 .init = stac92xx_init,
1974 .free = stac92xx_free,
Matt4e550962005-07-04 17:51:39 +02001975 .unsol_event = stac92xx_unsol_event,
Mattff6fdc32005-06-27 15:06:52 +02001976#ifdef CONFIG_PM
1977 .resume = stac92xx_resume,
1978#endif
Matt2f2f4252005-04-13 14:45:30 +02001979};
1980
1981static int patch_stac9200(struct hda_codec *codec)
1982{
1983 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02001984 int err;
Matt2f2f4252005-04-13 14:45:30 +02001985
Takashi Iwaie560d8d2005-09-09 14:21:46 +02001986 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02001987 if (spec == NULL)
1988 return -ENOMEM;
1989
1990 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02001991 spec->num_pins = ARRAY_SIZE(stac9200_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02001992 spec->pin_nids = stac9200_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001993 spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS,
1994 stac9200_models,
1995 stac9200_cfg_tbl);
Richard Fish11b44bb2006-08-23 18:31:34 +02001996 if (spec->board_config < 0) {
1997 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9200, using BIOS defaults\n");
1998 err = stac92xx_save_bios_config_regs(codec);
1999 if (err < 0) {
2000 stac92xx_free(codec);
2001 return err;
2002 }
2003 spec->pin_configs = spec->bios_pin_configs;
2004 } else {
Matt Porter403d1942005-11-29 15:00:51 +01002005 spec->pin_configs = stac9200_brd_tbl[spec->board_config];
2006 stac92xx_set_config_regs(codec);
2007 }
Matt2f2f4252005-04-13 14:45:30 +02002008
2009 spec->multiout.max_channels = 2;
2010 spec->multiout.num_dacs = 1;
2011 spec->multiout.dac_nids = stac9200_dac_nids;
2012 spec->adc_nids = stac9200_adc_nids;
2013 spec->mux_nids = stac9200_mux_nids;
Mattdabbed62005-06-14 10:19:34 +02002014 spec->num_muxes = 1;
Matt Porter8b657272006-10-26 17:12:59 +02002015 spec->num_dmics = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02002016
2017 spec->init = stac9200_core_init;
Matt2f2f4252005-04-13 14:45:30 +02002018 spec->mixer = stac9200_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02002019
2020 err = stac9200_parse_auto_config(codec);
2021 if (err < 0) {
2022 stac92xx_free(codec);
2023 return err;
2024 }
Matt2f2f4252005-04-13 14:45:30 +02002025
2026 codec->patch_ops = stac92xx_patch_ops;
2027
2028 return 0;
2029}
2030
Tobin Davis8e21c342007-01-08 11:04:17 +01002031static int patch_stac925x(struct hda_codec *codec)
2032{
2033 struct sigmatel_spec *spec;
2034 int err;
2035
2036 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2037 if (spec == NULL)
2038 return -ENOMEM;
2039
2040 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02002041 spec->num_pins = ARRAY_SIZE(stac925x_pin_nids);
Tobin Davis8e21c342007-01-08 11:04:17 +01002042 spec->pin_nids = stac925x_pin_nids;
2043 spec->board_config = snd_hda_check_board_config(codec, STAC_925x_MODELS,
2044 stac925x_models,
2045 stac925x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002046 again:
Tobin Davis8e21c342007-01-08 11:04:17 +01002047 if (spec->board_config < 0) {
Tobin Davis2c11f952007-05-17 09:36:34 +02002048 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC925x,"
2049 "using BIOS defaults\n");
Tobin Davis8e21c342007-01-08 11:04:17 +01002050 err = stac92xx_save_bios_config_regs(codec);
2051 if (err < 0) {
2052 stac92xx_free(codec);
2053 return err;
2054 }
2055 spec->pin_configs = spec->bios_pin_configs;
2056 } else if (stac925x_brd_tbl[spec->board_config] != NULL){
2057 spec->pin_configs = stac925x_brd_tbl[spec->board_config];
2058 stac92xx_set_config_regs(codec);
2059 }
2060
2061 spec->multiout.max_channels = 2;
2062 spec->multiout.num_dacs = 1;
2063 spec->multiout.dac_nids = stac925x_dac_nids;
2064 spec->adc_nids = stac925x_adc_nids;
2065 spec->mux_nids = stac925x_mux_nids;
2066 spec->num_muxes = 1;
Tobin Davis2c11f952007-05-17 09:36:34 +02002067 switch (codec->vendor_id) {
2068 case 0x83847632: /* STAC9202 */
2069 case 0x83847633: /* STAC9202D */
2070 case 0x83847636: /* STAC9251 */
2071 case 0x83847637: /* STAC9251D */
2072 spec->num_dmics = 1;
2073 spec->dmic_nids = stac925x_dmic_nids;
2074 break;
2075 default:
2076 spec->num_dmics = 0;
2077 break;
2078 }
Tobin Davis8e21c342007-01-08 11:04:17 +01002079
2080 spec->init = stac925x_core_init;
2081 spec->mixer = stac925x_mixer;
2082
2083 err = stac92xx_parse_auto_config(codec, 0x8, 0x7);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002084 if (!err) {
2085 if (spec->board_config < 0) {
2086 printk(KERN_WARNING "hda_codec: No auto-config is "
2087 "available, default to model=ref\n");
2088 spec->board_config = STAC_925x_REF;
2089 goto again;
2090 }
2091 err = -EINVAL;
2092 }
Tobin Davis8e21c342007-01-08 11:04:17 +01002093 if (err < 0) {
2094 stac92xx_free(codec);
2095 return err;
2096 }
2097
2098 codec->patch_ops = stac92xx_patch_ops;
2099
2100 return 0;
2101}
2102
Matt2f2f4252005-04-13 14:45:30 +02002103static int patch_stac922x(struct hda_codec *codec)
2104{
2105 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02002106 int err;
Matt2f2f4252005-04-13 14:45:30 +02002107
Takashi Iwaie560d8d2005-09-09 14:21:46 +02002108 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02002109 if (spec == NULL)
2110 return -ENOMEM;
2111
2112 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02002113 spec->num_pins = ARRAY_SIZE(stac922x_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02002114 spec->pin_nids = stac922x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002115 spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS,
2116 stac922x_models,
2117 stac922x_cfg_tbl);
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002118 if (spec->board_config == STAC_INTEL_MAC_V3) {
Takashi Iwai3fc24d82007-02-16 13:27:18 +01002119 spec->gpio_mute = 1;
2120 /* Intel Macs have all same PCI SSID, so we need to check
2121 * codec SSID to distinguish the exact models
2122 */
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01002123 printk(KERN_INFO "hda_codec: STAC922x, Apple subsys_id=%x\n", codec->subsystem_id);
Takashi Iwai3fc24d82007-02-16 13:27:18 +01002124 switch (codec->subsystem_id) {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002125
2126 case 0x106b0800:
2127 spec->board_config = STAC_INTEL_MAC_V1;
Abhijit Bhopatkarc45e20e2007-04-17 11:57:16 +02002128 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002129 case 0x106b0600:
2130 case 0x106b0700:
2131 spec->board_config = STAC_INTEL_MAC_V2;
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01002132 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002133 case 0x106b0e00:
2134 case 0x106b0f00:
2135 case 0x106b1600:
2136 case 0x106b1700:
2137 case 0x106b0200:
2138 case 0x106b1e00:
2139 spec->board_config = STAC_INTEL_MAC_V3;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01002140 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002141 case 0x106b1a00:
2142 case 0x00000100:
2143 spec->board_config = STAC_INTEL_MAC_V4;
Sylvain FORETf16928f2007-04-27 14:22:36 +02002144 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002145 case 0x106b0a00:
2146 case 0x106b2200:
2147 spec->board_config = STAC_INTEL_MAC_V5;
Takashi Iwai0dae0f82007-05-21 12:41:29 +02002148 break;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01002149 }
2150 }
2151
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002152 again:
Richard Fish11b44bb2006-08-23 18:31:34 +02002153 if (spec->board_config < 0) {
2154 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC922x, "
2155 "using BIOS defaults\n");
2156 err = stac92xx_save_bios_config_regs(codec);
2157 if (err < 0) {
2158 stac92xx_free(codec);
2159 return err;
2160 }
2161 spec->pin_configs = spec->bios_pin_configs;
2162 } else if (stac922x_brd_tbl[spec->board_config] != NULL) {
Matt Porter403d1942005-11-29 15:00:51 +01002163 spec->pin_configs = stac922x_brd_tbl[spec->board_config];
2164 stac92xx_set_config_regs(codec);
2165 }
Matt2f2f4252005-04-13 14:45:30 +02002166
Matt2f2f4252005-04-13 14:45:30 +02002167 spec->adc_nids = stac922x_adc_nids;
2168 spec->mux_nids = stac922x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01002169 spec->num_muxes = ARRAY_SIZE(stac922x_mux_nids);
Matt Porter8b657272006-10-26 17:12:59 +02002170 spec->num_dmics = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02002171
2172 spec->init = stac922x_core_init;
Matt2f2f4252005-04-13 14:45:30 +02002173 spec->mixer = stac922x_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02002174
2175 spec->multiout.dac_nids = spec->dac_nids;
Takashi Iwai19039bd2006-06-28 15:52:16 +02002176
Matt Porter3cc08dc2006-01-23 15:27:49 +01002177 err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002178 if (!err) {
2179 if (spec->board_config < 0) {
2180 printk(KERN_WARNING "hda_codec: No auto-config is "
2181 "available, default to model=ref\n");
2182 spec->board_config = STAC_D945_REF;
2183 goto again;
2184 }
2185 err = -EINVAL;
2186 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01002187 if (err < 0) {
2188 stac92xx_free(codec);
2189 return err;
2190 }
2191
2192 codec->patch_ops = stac92xx_patch_ops;
2193
Takashi Iwai807a46362007-05-29 19:01:37 +02002194 /* Fix Mux capture level; max to 2 */
2195 snd_hda_override_amp_caps(codec, 0x12, HDA_OUTPUT,
2196 (0 << AC_AMPCAP_OFFSET_SHIFT) |
2197 (2 << AC_AMPCAP_NUM_STEPS_SHIFT) |
2198 (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
2199 (0 << AC_AMPCAP_MUTE_SHIFT));
2200
Matt Porter3cc08dc2006-01-23 15:27:49 +01002201 return 0;
2202}
2203
2204static int patch_stac927x(struct hda_codec *codec)
2205{
2206 struct sigmatel_spec *spec;
2207 int err;
2208
2209 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2210 if (spec == NULL)
2211 return -ENOMEM;
2212
2213 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02002214 spec->num_pins = ARRAY_SIZE(stac927x_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02002215 spec->pin_nids = stac927x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002216 spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS,
2217 stac927x_models,
2218 stac927x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002219 again:
Richard Fish11b44bb2006-08-23 18:31:34 +02002220 if (spec->board_config < 0) {
Matt Porter3cc08dc2006-01-23 15:27:49 +01002221 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC927x, using BIOS defaults\n");
Richard Fish11b44bb2006-08-23 18:31:34 +02002222 err = stac92xx_save_bios_config_regs(codec);
2223 if (err < 0) {
2224 stac92xx_free(codec);
2225 return err;
2226 }
2227 spec->pin_configs = spec->bios_pin_configs;
2228 } else if (stac927x_brd_tbl[spec->board_config] != NULL) {
Matt Porter3cc08dc2006-01-23 15:27:49 +01002229 spec->pin_configs = stac927x_brd_tbl[spec->board_config];
2230 stac92xx_set_config_regs(codec);
2231 }
2232
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002233 switch (spec->board_config) {
Tobin Davis93ed1502006-09-01 21:03:12 +02002234 case STAC_D965_3ST:
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002235 spec->adc_nids = stac927x_adc_nids;
2236 spec->mux_nids = stac927x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01002237 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
Matt Porter8b657272006-10-26 17:12:59 +02002238 spec->num_dmics = 0;
Tobin Davis93ed1502006-09-01 21:03:12 +02002239 spec->init = d965_core_init;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002240 spec->mixer = stac9227_mixer;
2241 break;
Tobin Davis93ed1502006-09-01 21:03:12 +02002242 case STAC_D965_5ST:
2243 spec->adc_nids = stac927x_adc_nids;
2244 spec->mux_nids = stac927x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01002245 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
Matt Porter8b657272006-10-26 17:12:59 +02002246 spec->num_dmics = 0;
Tobin Davis93ed1502006-09-01 21:03:12 +02002247 spec->init = d965_core_init;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002248 spec->mixer = stac9227_mixer;
2249 break;
2250 default:
2251 spec->adc_nids = stac927x_adc_nids;
2252 spec->mux_nids = stac927x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01002253 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
Matt Porter8b657272006-10-26 17:12:59 +02002254 spec->num_dmics = 0;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002255 spec->init = stac927x_core_init;
2256 spec->mixer = stac927x_mixer;
2257 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01002258
2259 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostay87d48362007-07-17 11:52:24 +02002260 /* GPIO0 High = Enable EAPD */
Takashi Iwai82599802007-07-31 15:56:24 +02002261 spec->gpio_mask = spec->gpio_data = 0x00000001;
2262 stac92xx_enable_gpio_mask(codec);
Matthew Ranostay92a22be2007-06-19 16:48:28 +02002263
Matt Porter3cc08dc2006-01-23 15:27:49 +01002264 err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002265 if (!err) {
2266 if (spec->board_config < 0) {
2267 printk(KERN_WARNING "hda_codec: No auto-config is "
2268 "available, default to model=ref\n");
2269 spec->board_config = STAC_D965_REF;
2270 goto again;
2271 }
2272 err = -EINVAL;
2273 }
Mattc7d4b2f2005-06-27 14:59:41 +02002274 if (err < 0) {
2275 stac92xx_free(codec);
2276 return err;
2277 }
Matt2f2f4252005-04-13 14:45:30 +02002278
2279 codec->patch_ops = stac92xx_patch_ops;
2280
2281 return 0;
2282}
2283
Matt Porterf3302a52006-07-31 12:49:34 +02002284static int patch_stac9205(struct hda_codec *codec)
2285{
2286 struct sigmatel_spec *spec;
Takashi Iwai82599802007-07-31 15:56:24 +02002287 int err;
Matt Porterf3302a52006-07-31 12:49:34 +02002288
2289 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2290 if (spec == NULL)
2291 return -ENOMEM;
2292
2293 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02002294 spec->num_pins = ARRAY_SIZE(stac9205_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02002295 spec->pin_nids = stac9205_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002296 spec->board_config = snd_hda_check_board_config(codec, STAC_9205_MODELS,
2297 stac9205_models,
2298 stac9205_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002299 again:
Richard Fish11b44bb2006-08-23 18:31:34 +02002300 if (spec->board_config < 0) {
2301 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9205, using BIOS defaults\n");
2302 err = stac92xx_save_bios_config_regs(codec);
2303 if (err < 0) {
2304 stac92xx_free(codec);
2305 return err;
2306 }
2307 spec->pin_configs = spec->bios_pin_configs;
2308 } else {
Matt Porterf3302a52006-07-31 12:49:34 +02002309 spec->pin_configs = stac9205_brd_tbl[spec->board_config];
2310 stac92xx_set_config_regs(codec);
2311 }
2312
2313 spec->adc_nids = stac9205_adc_nids;
2314 spec->mux_nids = stac9205_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01002315 spec->num_muxes = ARRAY_SIZE(stac9205_mux_nids);
Matt Porter8b657272006-10-26 17:12:59 +02002316 spec->dmic_nids = stac9205_dmic_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01002317 spec->num_dmics = ARRAY_SIZE(stac9205_dmic_nids);
Matt Porter8b657272006-10-26 17:12:59 +02002318 spec->dmux_nid = 0x1d;
Matt Porterf3302a52006-07-31 12:49:34 +02002319
2320 spec->init = stac9205_core_init;
2321 spec->mixer = stac9205_mixer;
2322
2323 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostay87d48362007-07-17 11:52:24 +02002324
2325 if (spec->board_config == STAC_M43xx) {
2326 /* Enable SPDIF in/out */
2327 stac92xx_set_config_reg(codec, 0x1f, 0x01441030);
2328 stac92xx_set_config_reg(codec, 0x20, 0x1c410030);
Matt Porter33382402006-12-18 13:17:28 +01002329
Takashi Iwai82599802007-07-31 15:56:24 +02002330 spec->gpio_mask = 0x00000007; /* GPIO0-2 */
Matthew Ranostay87d48362007-07-17 11:52:24 +02002331 /* GPIO0 High = EAPD, GPIO1 Low = DRM,
2332 * GPIO2 High = Headphone Mute
2333 */
Takashi Iwai82599802007-07-31 15:56:24 +02002334 spec->gpio_data = 0x00000005;
Matthew Ranostay87d48362007-07-17 11:52:24 +02002335 } else
Takashi Iwai82599802007-07-31 15:56:24 +02002336 spec->gpio_mask = spec->gpio_data =
2337 0x00000001; /* GPIO0 High = EAPD */
Matthew Ranostay87d48362007-07-17 11:52:24 +02002338
Takashi Iwai82599802007-07-31 15:56:24 +02002339 stac92xx_enable_gpio_mask(codec);
Matt Porterf3302a52006-07-31 12:49:34 +02002340 err = stac92xx_parse_auto_config(codec, 0x1f, 0x20);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002341 if (!err) {
2342 if (spec->board_config < 0) {
2343 printk(KERN_WARNING "hda_codec: No auto-config is "
2344 "available, default to model=ref\n");
2345 spec->board_config = STAC_9205_REF;
2346 goto again;
2347 }
2348 err = -EINVAL;
2349 }
Matt Porterf3302a52006-07-31 12:49:34 +02002350 if (err < 0) {
2351 stac92xx_free(codec);
2352 return err;
2353 }
2354
2355 codec->patch_ops = stac92xx_patch_ops;
2356
2357 return 0;
2358}
2359
Matt2f2f4252005-04-13 14:45:30 +02002360/*
Guillaume Munch6d859062006-08-22 17:15:47 +02002361 * STAC9872 hack
Takashi Iwaidb064e52006-03-16 16:04:58 +01002362 */
2363
Guillaume Munch99ccc562006-08-16 19:35:12 +02002364/* static config for Sony VAIO FE550G and Sony VAIO AR */
Takashi Iwaidb064e52006-03-16 16:04:58 +01002365static hda_nid_t vaio_dacs[] = { 0x2 };
2366#define VAIO_HP_DAC 0x5
2367static hda_nid_t vaio_adcs[] = { 0x8 /*,0x6*/ };
2368static hda_nid_t vaio_mux_nids[] = { 0x15 };
2369
2370static struct hda_input_mux vaio_mux = {
2371 .num_items = 2,
2372 .items = {
Takashi Iwaid7737812006-04-25 13:05:43 +02002373 /* { "HP", 0x0 }, */
Takashi Iwai1624cb92007-07-05 13:10:51 +02002374 { "Mic Jack", 0x1 },
2375 { "Internal Mic", 0x2 },
Takashi Iwaidb064e52006-03-16 16:04:58 +01002376 { "PCM", 0x3 },
2377 }
2378};
2379
2380static struct hda_verb vaio_init[] = {
2381 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
2382 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
2383 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
2384 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
2385 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
Takashi Iwai1624cb92007-07-05 13:10:51 +02002386 {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
Takashi Iwaidb064e52006-03-16 16:04:58 +01002387 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
2388 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
2389 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
2390 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
2391 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
2392 {}
2393};
2394
Guillaume Munch6d859062006-08-22 17:15:47 +02002395static struct hda_verb vaio_ar_init[] = {
2396 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
2397 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
2398 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
2399 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
2400/* {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },*/ /* Optical Out */
2401 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
Takashi Iwai1624cb92007-07-05 13:10:51 +02002402 {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
Guillaume Munch6d859062006-08-22 17:15:47 +02002403 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
2404 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
2405/* {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},*/ /* Optical Out */
2406 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
2407 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
2408 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
2409 {}
2410};
2411
Takashi Iwaidb064e52006-03-16 16:04:58 +01002412/* bind volumes of both NID 0x02 and 0x05 */
2413static int vaio_master_vol_put(struct snd_kcontrol *kcontrol,
2414 struct snd_ctl_elem_value *ucontrol)
2415{
2416 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2417 long *valp = ucontrol->value.integer.value;
2418 int change;
2419
2420 change = snd_hda_codec_amp_update(codec, 0x02, 0, HDA_OUTPUT, 0,
2421 0x7f, valp[0] & 0x7f);
2422 change |= snd_hda_codec_amp_update(codec, 0x02, 1, HDA_OUTPUT, 0,
2423 0x7f, valp[1] & 0x7f);
2424 snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
2425 0x7f, valp[0] & 0x7f);
2426 snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
2427 0x7f, valp[1] & 0x7f);
2428 return change;
2429}
2430
2431/* bind volumes of both NID 0x02 and 0x05 */
2432static int vaio_master_sw_put(struct snd_kcontrol *kcontrol,
2433 struct snd_ctl_elem_value *ucontrol)
2434{
2435 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2436 long *valp = ucontrol->value.integer.value;
2437 int change;
2438
2439 change = snd_hda_codec_amp_update(codec, 0x02, 0, HDA_OUTPUT, 0,
Takashi Iwaia9393d72006-05-03 11:59:03 +02002440 0x80, (valp[0] ? 0 : 0x80));
Takashi Iwaidb064e52006-03-16 16:04:58 +01002441 change |= snd_hda_codec_amp_update(codec, 0x02, 1, HDA_OUTPUT, 0,
Takashi Iwaia9393d72006-05-03 11:59:03 +02002442 0x80, (valp[1] ? 0 : 0x80));
Takashi Iwaidb064e52006-03-16 16:04:58 +01002443 snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
Takashi Iwaia9393d72006-05-03 11:59:03 +02002444 0x80, (valp[0] ? 0 : 0x80));
Takashi Iwaidb064e52006-03-16 16:04:58 +01002445 snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
Takashi Iwaia9393d72006-05-03 11:59:03 +02002446 0x80, (valp[1] ? 0 : 0x80));
Takashi Iwaidb064e52006-03-16 16:04:58 +01002447 return change;
2448}
2449
2450static struct snd_kcontrol_new vaio_mixer[] = {
2451 {
2452 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2453 .name = "Master Playback Volume",
2454 .info = snd_hda_mixer_amp_volume_info,
2455 .get = snd_hda_mixer_amp_volume_get,
2456 .put = vaio_master_vol_put,
Takashi Iwaic2566522006-08-17 18:21:36 +02002457 .tlv = { .c = snd_hda_mixer_amp_tlv },
Takashi Iwaidb064e52006-03-16 16:04:58 +01002458 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2459 },
2460 {
2461 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2462 .name = "Master Playback Switch",
2463 .info = snd_hda_mixer_amp_switch_info,
2464 .get = snd_hda_mixer_amp_switch_get,
2465 .put = vaio_master_sw_put,
2466 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2467 },
2468 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
2469 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
2470 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
2471 {
2472 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2473 .name = "Capture Source",
2474 .count = 1,
2475 .info = stac92xx_mux_enum_info,
2476 .get = stac92xx_mux_enum_get,
2477 .put = stac92xx_mux_enum_put,
2478 },
2479 {}
2480};
2481
Guillaume Munch6d859062006-08-22 17:15:47 +02002482static struct snd_kcontrol_new vaio_ar_mixer[] = {
2483 {
2484 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2485 .name = "Master Playback Volume",
2486 .info = snd_hda_mixer_amp_volume_info,
2487 .get = snd_hda_mixer_amp_volume_get,
2488 .put = vaio_master_vol_put,
2489 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2490 },
2491 {
2492 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2493 .name = "Master Playback Switch",
2494 .info = snd_hda_mixer_amp_switch_info,
2495 .get = snd_hda_mixer_amp_switch_get,
2496 .put = vaio_master_sw_put,
2497 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2498 },
2499 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
2500 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
2501 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
2502 /*HDA_CODEC_MUTE("Optical Out Switch", 0x10, 0, HDA_OUTPUT),
2503 HDA_CODEC_VOLUME("Optical Out Volume", 0x10, 0, HDA_OUTPUT),*/
2504 {
2505 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2506 .name = "Capture Source",
2507 .count = 1,
2508 .info = stac92xx_mux_enum_info,
2509 .get = stac92xx_mux_enum_get,
2510 .put = stac92xx_mux_enum_put,
2511 },
2512 {}
2513};
2514
2515static struct hda_codec_ops stac9872_patch_ops = {
Takashi Iwaidb064e52006-03-16 16:04:58 +01002516 .build_controls = stac92xx_build_controls,
2517 .build_pcms = stac92xx_build_pcms,
2518 .init = stac92xx_init,
2519 .free = stac92xx_free,
2520#ifdef CONFIG_PM
2521 .resume = stac92xx_resume,
2522#endif
2523};
2524
Guillaume Munch6d859062006-08-22 17:15:47 +02002525enum { /* FE and SZ series. id=0x83847661 and subsys=0x104D0700 or 104D1000. */
2526 CXD9872RD_VAIO,
2527 /* Unknown. id=0x83847662 and subsys=0x104D1200 or 104D1000. */
2528 STAC9872AK_VAIO,
2529 /* Unknown. id=0x83847661 and subsys=0x104D1200. */
2530 STAC9872K_VAIO,
2531 /* AR Series. id=0x83847664 and subsys=104D1300 */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002532 CXD9872AKD_VAIO,
2533 STAC_9872_MODELS,
2534};
Takashi Iwaidb064e52006-03-16 16:04:58 +01002535
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002536static const char *stac9872_models[STAC_9872_MODELS] = {
2537 [CXD9872RD_VAIO] = "vaio",
2538 [CXD9872AKD_VAIO] = "vaio-ar",
2539};
2540
2541static struct snd_pci_quirk stac9872_cfg_tbl[] = {
2542 SND_PCI_QUIRK(0x104d, 0x81e6, "Sony VAIO F/S", CXD9872RD_VAIO),
2543 SND_PCI_QUIRK(0x104d, 0x81ef, "Sony VAIO F/S", CXD9872RD_VAIO),
2544 SND_PCI_QUIRK(0x104d, 0x81fd, "Sony VAIO AR", CXD9872AKD_VAIO),
Tobin Davis68e22542007-03-12 11:36:39 +01002545 SND_PCI_QUIRK(0x104d, 0x8205, "Sony VAIO AR", CXD9872AKD_VAIO),
Takashi Iwaidb064e52006-03-16 16:04:58 +01002546 {}
2547};
2548
Guillaume Munch6d859062006-08-22 17:15:47 +02002549static int patch_stac9872(struct hda_codec *codec)
Takashi Iwaidb064e52006-03-16 16:04:58 +01002550{
2551 struct sigmatel_spec *spec;
2552 int board_config;
2553
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002554 board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
2555 stac9872_models,
2556 stac9872_cfg_tbl);
Takashi Iwaidb064e52006-03-16 16:04:58 +01002557 if (board_config < 0)
2558 /* unknown config, let generic-parser do its job... */
2559 return snd_hda_parse_generic_codec(codec);
2560
2561 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2562 if (spec == NULL)
2563 return -ENOMEM;
2564
2565 codec->spec = spec;
2566 switch (board_config) {
Guillaume Munch6d859062006-08-22 17:15:47 +02002567 case CXD9872RD_VAIO:
2568 case STAC9872AK_VAIO:
2569 case STAC9872K_VAIO:
Takashi Iwaidb064e52006-03-16 16:04:58 +01002570 spec->mixer = vaio_mixer;
2571 spec->init = vaio_init;
2572 spec->multiout.max_channels = 2;
2573 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
2574 spec->multiout.dac_nids = vaio_dacs;
2575 spec->multiout.hp_nid = VAIO_HP_DAC;
2576 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
2577 spec->adc_nids = vaio_adcs;
2578 spec->input_mux = &vaio_mux;
2579 spec->mux_nids = vaio_mux_nids;
2580 break;
Guillaume Munch6d859062006-08-22 17:15:47 +02002581
2582 case CXD9872AKD_VAIO:
2583 spec->mixer = vaio_ar_mixer;
2584 spec->init = vaio_ar_init;
2585 spec->multiout.max_channels = 2;
2586 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
2587 spec->multiout.dac_nids = vaio_dacs;
2588 spec->multiout.hp_nid = VAIO_HP_DAC;
2589 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
2590 spec->adc_nids = vaio_adcs;
2591 spec->input_mux = &vaio_mux;
2592 spec->mux_nids = vaio_mux_nids;
2593 break;
Takashi Iwaidb064e52006-03-16 16:04:58 +01002594 }
2595
Guillaume Munch6d859062006-08-22 17:15:47 +02002596 codec->patch_ops = stac9872_patch_ops;
Takashi Iwaidb064e52006-03-16 16:04:58 +01002597 return 0;
2598}
2599
2600
2601/*
Matt2f2f4252005-04-13 14:45:30 +02002602 * patch entries
2603 */
2604struct hda_codec_preset snd_hda_preset_sigmatel[] = {
2605 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
2606 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
2607 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
2608 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
2609 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
2610 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
2611 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
Matt Porter22a27c72006-07-06 18:49:10 +02002612 { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
2613 { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
2614 { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
2615 { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
2616 { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
2617 { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
Matt Porter3cc08dc2006-01-23 15:27:49 +01002618 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
2619 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
2620 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
2621 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
2622 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
2623 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
2624 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
2625 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
2626 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
2627 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
Tobin Davis8e21c342007-01-08 11:04:17 +01002628 { .id = 0x83847632, .name = "STAC9202", .patch = patch_stac925x },
2629 { .id = 0x83847633, .name = "STAC9202D", .patch = patch_stac925x },
2630 { .id = 0x83847634, .name = "STAC9250", .patch = patch_stac925x },
2631 { .id = 0x83847635, .name = "STAC9250D", .patch = patch_stac925x },
2632 { .id = 0x83847636, .name = "STAC9251", .patch = patch_stac925x },
2633 { .id = 0x83847637, .name = "STAC9250D", .patch = patch_stac925x },
Guillaume Munch6d859062006-08-22 17:15:47 +02002634 /* The following does not take into account .id=0x83847661 when subsys =
2635 * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
2636 * currently not fully supported.
2637 */
2638 { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
2639 { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
2640 { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
Matt Porterf3302a52006-07-31 12:49:34 +02002641 { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
2642 { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
2643 { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
2644 { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
2645 { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
2646 { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
2647 { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
2648 { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
Matt2f2f4252005-04-13 14:45:30 +02002649 {} /* terminator */
2650};