blob: cbaa00aa5b92a9add9898afc8d434986f4e40bbd [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,
47 STAC_9205_MODELS
48};
49
50enum {
51 STAC_D945_REF,
52 STAC_D945GTP3,
53 STAC_D945GTP5,
54 STAC_MACMINI,
55 STAC_922X_MODELS
56};
57
58enum {
59 STAC_D965_REF,
60 STAC_D965_3ST,
61 STAC_D965_5ST,
62 STAC_927X_MODELS
63};
Matt Porter403d1942005-11-29 15:00:51 +010064
Matt2f2f4252005-04-13 14:45:30 +020065struct sigmatel_spec {
Takashi Iwaic8b6bf92005-11-17 14:57:47 +010066 struct snd_kcontrol_new *mixers[4];
Mattc7d4b2f2005-06-27 14:59:41 +020067 unsigned int num_mixers;
68
Matt Porter403d1942005-11-29 15:00:51 +010069 int board_config;
Mattc7d4b2f2005-06-27 14:59:41 +020070 unsigned int surr_switch: 1;
Matt Porter403d1942005-11-29 15:00:51 +010071 unsigned int line_switch: 1;
72 unsigned int mic_switch: 1;
Matt Porter3cc08dc2006-01-23 15:27:49 +010073 unsigned int alt_switch: 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +010074 unsigned int hp_detect: 1;
Sam Revitch62fe78e2006-05-10 15:09:17 +020075 unsigned int gpio_mute: 1;
Mattc7d4b2f2005-06-27 14:59:41 +020076
Matt2f2f4252005-04-13 14:45:30 +020077 /* playback */
78 struct hda_multi_out multiout;
Matt Porter3cc08dc2006-01-23 15:27:49 +010079 hda_nid_t dac_nids[5];
Matt2f2f4252005-04-13 14:45:30 +020080
81 /* capture */
82 hda_nid_t *adc_nids;
Matt2f2f4252005-04-13 14:45:30 +020083 unsigned int num_adcs;
Mattdabbed62005-06-14 10:19:34 +020084 hda_nid_t *mux_nids;
85 unsigned int num_muxes;
Matt Porter8b657272006-10-26 17:12:59 +020086 hda_nid_t *dmic_nids;
87 unsigned int num_dmics;
88 hda_nid_t dmux_nid;
Mattdabbed62005-06-14 10:19:34 +020089 hda_nid_t dig_in_nid;
Matt2f2f4252005-04-13 14:45:30 +020090
Matt2f2f4252005-04-13 14:45:30 +020091 /* pin widgets */
92 hda_nid_t *pin_nids;
93 unsigned int num_pins;
Matt2f2f4252005-04-13 14:45:30 +020094 unsigned int *pin_configs;
Richard Fish11b44bb2006-08-23 18:31:34 +020095 unsigned int *bios_pin_configs;
Matt2f2f4252005-04-13 14:45:30 +020096
97 /* codec specific stuff */
98 struct hda_verb *init;
Takashi Iwaic8b6bf92005-11-17 14:57:47 +010099 struct snd_kcontrol_new *mixer;
Matt2f2f4252005-04-13 14:45:30 +0200100
101 /* capture source */
Matt Porter8b657272006-10-26 17:12:59 +0200102 struct hda_input_mux *dinput_mux;
103 unsigned int cur_dmux;
Mattc7d4b2f2005-06-27 14:59:41 +0200104 struct hda_input_mux *input_mux;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100105 unsigned int cur_mux[3];
Matt2f2f4252005-04-13 14:45:30 +0200106
Matt Porter403d1942005-11-29 15:00:51 +0100107 /* i/o switches */
108 unsigned int io_switch[2];
Matt2f2f4252005-04-13 14:45:30 +0200109
Mattc7d4b2f2005-06-27 14:59:41 +0200110 struct hda_pcm pcm_rec[2]; /* PCM information */
111
112 /* dynamic controls and input_mux */
113 struct auto_pin_cfg autocfg;
114 unsigned int num_kctl_alloc, num_kctl_used;
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100115 struct snd_kcontrol_new *kctl_alloc;
Matt Porter8b657272006-10-26 17:12:59 +0200116 struct hda_input_mux private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +0200117 struct hda_input_mux private_imux;
Matt2f2f4252005-04-13 14:45:30 +0200118};
119
120static hda_nid_t stac9200_adc_nids[1] = {
121 0x03,
122};
123
124static hda_nid_t stac9200_mux_nids[1] = {
125 0x0c,
126};
127
128static hda_nid_t stac9200_dac_nids[1] = {
129 0x02,
130};
131
Matt2f2f4252005-04-13 14:45:30 +0200132static hda_nid_t stac922x_adc_nids[2] = {
133 0x06, 0x07,
134};
135
136static hda_nid_t stac922x_mux_nids[2] = {
137 0x12, 0x13,
138};
139
Matt Porter3cc08dc2006-01-23 15:27:49 +0100140static hda_nid_t stac927x_adc_nids[3] = {
141 0x07, 0x08, 0x09
142};
143
144static hda_nid_t stac927x_mux_nids[3] = {
145 0x15, 0x16, 0x17
146};
147
Matt Porterf3302a52006-07-31 12:49:34 +0200148static hda_nid_t stac9205_adc_nids[2] = {
149 0x12, 0x13
150};
151
152static hda_nid_t stac9205_mux_nids[2] = {
153 0x19, 0x1a
154};
155
Matt Porter8b657272006-10-26 17:12:59 +0200156static hda_nid_t stac9205_dmic_nids[3] = {
157 0x17, 0x18, 0
158};
159
Mattc7d4b2f2005-06-27 14:59:41 +0200160static hda_nid_t stac9200_pin_nids[8] = {
Tobin Davis93ed1502006-09-01 21:03:12 +0200161 0x08, 0x09, 0x0d, 0x0e,
162 0x0f, 0x10, 0x11, 0x12,
Matt2f2f4252005-04-13 14:45:30 +0200163};
164
165static hda_nid_t stac922x_pin_nids[10] = {
166 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
167 0x0f, 0x10, 0x11, 0x15, 0x1b,
168};
169
Matt Porter3cc08dc2006-01-23 15:27:49 +0100170static hda_nid_t stac927x_pin_nids[14] = {
171 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
172 0x0f, 0x10, 0x11, 0x12, 0x13,
173 0x14, 0x21, 0x22, 0x23,
174};
175
Matt Porterf3302a52006-07-31 12:49:34 +0200176static hda_nid_t stac9205_pin_nids[12] = {
177 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
178 0x0f, 0x14, 0x16, 0x17, 0x18,
179 0x21, 0x22,
180
181};
182
Matt Porter8b657272006-10-26 17:12:59 +0200183static int stac92xx_dmux_enum_info(struct snd_kcontrol *kcontrol,
184 struct snd_ctl_elem_info *uinfo)
185{
186 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
187 struct sigmatel_spec *spec = codec->spec;
188 return snd_hda_input_mux_info(spec->dinput_mux, uinfo);
189}
190
191static int stac92xx_dmux_enum_get(struct snd_kcontrol *kcontrol,
192 struct snd_ctl_elem_value *ucontrol)
193{
194 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
195 struct sigmatel_spec *spec = codec->spec;
196
197 ucontrol->value.enumerated.item[0] = spec->cur_dmux;
198 return 0;
199}
200
201static int stac92xx_dmux_enum_put(struct snd_kcontrol *kcontrol,
202 struct snd_ctl_elem_value *ucontrol)
203{
204 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
205 struct sigmatel_spec *spec = codec->spec;
206
207 return snd_hda_input_mux_put(codec, spec->dinput_mux, ucontrol,
208 spec->dmux_nid, &spec->cur_dmux);
209}
210
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100211static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Matt2f2f4252005-04-13 14:45:30 +0200212{
213 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
214 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +0200215 return snd_hda_input_mux_info(spec->input_mux, uinfo);
Matt2f2f4252005-04-13 14:45:30 +0200216}
217
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100218static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200219{
220 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
221 struct sigmatel_spec *spec = codec->spec;
222 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
223
224 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
225 return 0;
226}
227
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100228static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200229{
230 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
231 struct sigmatel_spec *spec = codec->spec;
232 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
233
Mattc7d4b2f2005-06-27 14:59:41 +0200234 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
Matt2f2f4252005-04-13 14:45:30 +0200235 spec->mux_nids[adc_idx], &spec->cur_mux[adc_idx]);
236}
237
Mattc7d4b2f2005-06-27 14:59:41 +0200238static struct hda_verb stac9200_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200239 /* set dac0mux for dac converter */
Mattc7d4b2f2005-06-27 14:59:41 +0200240 { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
Matt2f2f4252005-04-13 14:45:30 +0200241 {}
242};
243
Mattc7d4b2f2005-06-27 14:59:41 +0200244static struct hda_verb stac922x_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200245 /* set master volume and direct control */
Mattc7d4b2f2005-06-27 14:59:41 +0200246 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matt2f2f4252005-04-13 14:45:30 +0200247 {}
248};
249
Tobin Davis93ed1502006-09-01 21:03:12 +0200250static struct hda_verb d965_core_init[] = {
Takashi Iwai19039bd2006-06-28 15:52:16 +0200251 /* set master volume and direct control */
Tobin Davis93ed1502006-09-01 21:03:12 +0200252 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Takashi Iwai19039bd2006-06-28 15:52:16 +0200253 /* unmute node 0x1b */
254 { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
255 /* select node 0x03 as DAC */
256 { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
257 {}
258};
259
Matt Porter3cc08dc2006-01-23 15:27:49 +0100260static struct hda_verb stac927x_core_init[] = {
261 /* set master volume and direct control */
262 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
263 {}
264};
265
Matt Porterf3302a52006-07-31 12:49:34 +0200266static struct hda_verb stac9205_core_init[] = {
267 /* set master volume and direct control */
268 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
269 {}
270};
271
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100272static struct snd_kcontrol_new stac9200_mixer[] = {
Matt2f2f4252005-04-13 14:45:30 +0200273 HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
274 HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
275 {
276 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
277 .name = "Input Source",
278 .count = 1,
279 .info = stac92xx_mux_enum_info,
280 .get = stac92xx_mux_enum_get,
281 .put = stac92xx_mux_enum_put,
282 },
283 HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
284 HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
Mattc7d4b2f2005-06-27 14:59:41 +0200285 HDA_CODEC_VOLUME("Capture Mux Volume", 0x0c, 0, HDA_OUTPUT),
Matt2f2f4252005-04-13 14:45:30 +0200286 { } /* end */
287};
288
Mattc7d4b2f2005-06-27 14:59:41 +0200289/* This needs to be generated dynamically based on sequence */
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100290static struct snd_kcontrol_new stac922x_mixer[] = {
Matt2f2f4252005-04-13 14:45:30 +0200291 {
292 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
293 .name = "Input Source",
294 .count = 1,
295 .info = stac92xx_mux_enum_info,
296 .get = stac92xx_mux_enum_get,
297 .put = stac92xx_mux_enum_put,
298 },
299 HDA_CODEC_VOLUME("Capture Volume", 0x17, 0x0, HDA_INPUT),
Takashi Iwai0fd17082006-01-13 18:46:21 +0100300 HDA_CODEC_MUTE("Capture Switch", 0x17, 0x0, HDA_INPUT),
Matt2f2f4252005-04-13 14:45:30 +0200301 HDA_CODEC_VOLUME("Mux Capture Volume", 0x12, 0x0, HDA_OUTPUT),
302 { } /* end */
303};
304
Takashi Iwai19039bd2006-06-28 15:52:16 +0200305/* This needs to be generated dynamically based on sequence */
306static struct snd_kcontrol_new stac9227_mixer[] = {
307 {
308 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
309 .name = "Input Source",
310 .count = 1,
311 .info = stac92xx_mux_enum_info,
312 .get = stac92xx_mux_enum_get,
313 .put = stac92xx_mux_enum_put,
314 },
315 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
316 HDA_CODEC_MUTE("Capture Switch", 0x1b, 0x0, HDA_OUTPUT),
317 { } /* end */
318};
319
Takashi Iwaid1d985f2006-11-23 19:27:12 +0100320static struct snd_kcontrol_new stac927x_mixer[] = {
Matt Porter3cc08dc2006-01-23 15:27:49 +0100321 {
322 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
323 .name = "Input Source",
324 .count = 1,
325 .info = stac92xx_mux_enum_info,
326 .get = stac92xx_mux_enum_get,
327 .put = stac92xx_mux_enum_put,
328 },
329 HDA_CODEC_VOLUME("InMux Capture Volume", 0x15, 0x0, HDA_OUTPUT),
330 HDA_CODEC_VOLUME("InVol Capture Volume", 0x18, 0x0, HDA_INPUT),
331 HDA_CODEC_MUTE("ADCMux Capture Switch", 0x1b, 0x0, HDA_OUTPUT),
332 { } /* end */
333};
334
Takashi Iwaid1d985f2006-11-23 19:27:12 +0100335static struct snd_kcontrol_new stac9205_mixer[] = {
Matt Porterf3302a52006-07-31 12:49:34 +0200336 {
337 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Matt Porter8b657272006-10-26 17:12:59 +0200338 .name = "Digital Input Source",
339 .count = 1,
340 .info = stac92xx_dmux_enum_info,
341 .get = stac92xx_dmux_enum_get,
342 .put = stac92xx_dmux_enum_put,
343 },
344 {
345 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Matt Porterf3302a52006-07-31 12:49:34 +0200346 .name = "Input Source",
347 .count = 1,
348 .info = stac92xx_mux_enum_info,
349 .get = stac92xx_mux_enum_get,
350 .put = stac92xx_mux_enum_put,
351 },
352 HDA_CODEC_VOLUME("InMux Capture Volume", 0x19, 0x0, HDA_OUTPUT),
353 HDA_CODEC_VOLUME("InVol Capture Volume", 0x1b, 0x0, HDA_INPUT),
354 HDA_CODEC_MUTE("ADCMux Capture Switch", 0x1d, 0x0, HDA_OUTPUT),
355 { } /* end */
356};
357
Matt2f2f4252005-04-13 14:45:30 +0200358static int stac92xx_build_controls(struct hda_codec *codec)
359{
360 struct sigmatel_spec *spec = codec->spec;
361 int err;
Mattc7d4b2f2005-06-27 14:59:41 +0200362 int i;
Matt2f2f4252005-04-13 14:45:30 +0200363
364 err = snd_hda_add_new_ctls(codec, spec->mixer);
365 if (err < 0)
366 return err;
Mattc7d4b2f2005-06-27 14:59:41 +0200367
368 for (i = 0; i < spec->num_mixers; i++) {
369 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
370 if (err < 0)
371 return err;
372 }
373
Mattdabbed62005-06-14 10:19:34 +0200374 if (spec->multiout.dig_out_nid) {
375 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
376 if (err < 0)
377 return err;
378 }
379 if (spec->dig_in_nid) {
380 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
381 if (err < 0)
382 return err;
383 }
384 return 0;
Matt2f2f4252005-04-13 14:45:30 +0200385}
386
Matt Porter403d1942005-11-29 15:00:51 +0100387static unsigned int ref9200_pin_configs[8] = {
Mattdabbed62005-06-14 10:19:34 +0200388 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
Matt2f2f4252005-04-13 14:45:30 +0200389 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
390};
391
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100392static unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
393 [STAC_REF] = ref9200_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +0100394};
395
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100396static const char *stac9200_models[STAC_9200_MODELS] = {
397 [STAC_REF] = "ref",
398};
399
400static struct snd_pci_quirk stac9200_cfg_tbl[] = {
401 /* SigmaTel reference board */
402 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
403 "DFI LanParty", STAC_REF),
Matt Portere7377072006-11-06 11:20:38 +0100404 /* Dell laptops have BIOS problem */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100405 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01b5,
406 "Dell Inspiron 630m", STAC_REF),
407 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c2,
408 "Dell Latitude D620", STAC_REF),
409 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cb,
410 "Dell Latitude 120L", STAC_REF),
Matt Porter403d1942005-11-29 15:00:51 +0100411 {} /* terminator */
412};
413
414static unsigned int ref922x_pin_configs[10] = {
415 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
416 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
Matt2f2f4252005-04-13 14:45:30 +0200417 0x40000100, 0x40000100,
418};
419
Matt Porter403d1942005-11-29 15:00:51 +0100420static unsigned int d945gtp3_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +0100421 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
Matt Porter403d1942005-11-29 15:00:51 +0100422 0x40000100, 0x40000100, 0x40000100, 0x40000100,
423 0x02a19120, 0x40000100,
424};
425
426static unsigned int d945gtp5_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +0100427 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
428 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
Matt Porter403d1942005-11-29 15:00:51 +0100429 0x02a19320, 0x40000100,
430};
431
Takashi Iwai19039bd2006-06-28 15:52:16 +0200432static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100433 [STAC_D945_REF] = ref922x_pin_configs,
Takashi Iwai19039bd2006-06-28 15:52:16 +0200434 [STAC_D945GTP3] = d945gtp3_pin_configs,
435 [STAC_D945GTP5] = d945gtp5_pin_configs,
Linus Torvalds7c3dec02006-07-10 22:21:43 -0700436 [STAC_MACMINI] = d945gtp5_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +0100437};
438
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100439static const char *stac922x_models[STAC_922X_MODELS] = {
440 [STAC_D945_REF] = "ref",
441 [STAC_D945GTP5] = "5stack",
442 [STAC_D945GTP3] = "3stack",
443 [STAC_MACMINI] = "macmini",
444};
445
446static struct snd_pci_quirk stac922x_cfg_tbl[] = {
447 /* SigmaTel reference board */
448 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
449 "DFI LanParty", STAC_D945_REF),
450 /* Intel 945G based systems */
451 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101,
452 "Intel D945G", STAC_D945GTP3),
453 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0202,
454 "Intel D945G", STAC_D945GTP3),
455 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0606,
456 "Intel D945G", STAC_D945GTP3),
457 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0601,
458 "Intel D945G", STAC_D945GTP3),
459 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0111,
460 "Intel D945G", STAC_D945GTP3),
461 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1115,
462 "Intel D945G", STAC_D945GTP3),
463 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1116,
464 "Intel D945G", STAC_D945GTP3),
465 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1117,
466 "Intel D945G", STAC_D945GTP3),
467 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1118,
468 "Intel D945G", STAC_D945GTP3),
469 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1119,
470 "Intel D945G", STAC_D945GTP3),
471 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x8826,
472 "Intel D945G", STAC_D945GTP3),
473 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5049,
474 "Intel D945G", STAC_D945GTP3),
475 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5055,
476 "Intel D945G", STAC_D945GTP3),
477 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5048,
478 "Intel D945G", STAC_D945GTP3),
479 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0110,
480 "Intel D945G", STAC_D945GTP3),
481 /* Intel D945G 5-stack systems */
482 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0404,
483 "Intel D945G", STAC_D945GTP5),
484 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0303,
485 "Intel D945G", STAC_D945GTP5),
486 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0013,
487 "Intel D945G", STAC_D945GTP5),
488 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0417,
489 "Intel D945G", STAC_D945GTP5),
490 /* Intel 945P based systems */
491 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0b0b,
492 "Intel D945P", STAC_D945GTP3),
493 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0112,
494 "Intel D945P", STAC_D945GTP3),
495 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0d0d,
496 "Intel D945P", STAC_D945GTP3),
497 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0909,
498 "Intel D945P", STAC_D945GTP3),
499 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0505,
500 "Intel D945P", STAC_D945GTP3),
501 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707,
502 "Intel D945P", STAC_D945GTP5),
503 /* other systems */
504 /* Apple Mac Mini (early 2006) */
505 SND_PCI_QUIRK(0x8384, 0x7680,
506 "Mac Mini", STAC_MACMINI),
Matt Porter403d1942005-11-29 15:00:51 +0100507 {} /* terminator */
508};
509
Matt Porter3cc08dc2006-01-23 15:27:49 +0100510static unsigned int ref927x_pin_configs[14] = {
Tobin Davis93ed1502006-09-01 21:03:12 +0200511 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
512 0x01a19040, 0x01011012, 0x01016011, 0x0101201f,
513 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
514 0x01c42190, 0x40000100,
Matt Porter3cc08dc2006-01-23 15:27:49 +0100515};
516
Tobin Davis93ed1502006-09-01 21:03:12 +0200517static unsigned int d965_3st_pin_configs[14] = {
Tobin Davis81d3dbd2006-08-22 19:44:45 +0200518 0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
519 0x01a19021, 0x01813024, 0x40000100, 0x40000100,
520 0x40000100, 0x40000100, 0x40000100, 0x40000100,
521 0x40000100, 0x40000100
522};
523
Tobin Davis93ed1502006-09-01 21:03:12 +0200524static unsigned int d965_5st_pin_configs[14] = {
525 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
526 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
527 0x40000100, 0x40000100, 0x40000100, 0x01442070,
528 0x40000100, 0x40000100
529};
530
531static unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100532 [STAC_D965_REF] = ref927x_pin_configs,
Tobin Davis93ed1502006-09-01 21:03:12 +0200533 [STAC_D965_3ST] = d965_3st_pin_configs,
534 [STAC_D965_5ST] = d965_5st_pin_configs,
Matt Porter3cc08dc2006-01-23 15:27:49 +0100535};
536
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100537static const char *stac927x_models[STAC_927X_MODELS] = {
538 [STAC_D965_REF] = "ref",
539 [STAC_D965_3ST] = "3stack",
540 [STAC_D965_5ST] = "5stack",
541};
542
543static struct snd_pci_quirk stac927x_cfg_tbl[] = {
544 /* SigmaTel reference board */
545 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
546 "DFI LanParty", STAC_D965_REF),
Tobin Davis81d3dbd2006-08-22 19:44:45 +0200547 /* Intel 946 based systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100548 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST),
549 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST),
Tobin Davis93ed1502006-09-01 21:03:12 +0200550 /* 965 based 3 stack systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100551 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2116, "Intel D965", STAC_D965_3ST),
552 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2115, "Intel D965", STAC_D965_3ST),
553 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2114, "Intel D965", STAC_D965_3ST),
554 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2113, "Intel D965", STAC_D965_3ST),
555 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2112, "Intel D965", STAC_D965_3ST),
556 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2111, "Intel D965", STAC_D965_3ST),
557 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2110, "Intel D965", STAC_D965_3ST),
558 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2009, "Intel D965", STAC_D965_3ST),
559 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2008, "Intel D965", STAC_D965_3ST),
560 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2007, "Intel D965", STAC_D965_3ST),
561 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2006, "Intel D965", STAC_D965_3ST),
562 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2005, "Intel D965", STAC_D965_3ST),
563 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2004, "Intel D965", STAC_D965_3ST),
564 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2003, "Intel D965", STAC_D965_3ST),
565 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2002, "Intel D965", STAC_D965_3ST),
566 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2001, "Intel D965", STAC_D965_3ST),
Tobin Davis93ed1502006-09-01 21:03:12 +0200567 /* 965 based 5 stack systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100568 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2301, "Intel D965", STAC_D965_5ST),
569 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2302, "Intel D965", STAC_D965_5ST),
570 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2303, "Intel D965", STAC_D965_5ST),
571 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2304, "Intel D965", STAC_D965_5ST),
572 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2305, "Intel D965", STAC_D965_5ST),
573 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2501, "Intel D965", STAC_D965_5ST),
574 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2502, "Intel D965", STAC_D965_5ST),
575 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2503, "Intel D965", STAC_D965_5ST),
576 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2504, "Intel D965", STAC_D965_5ST),
Matt Porter3cc08dc2006-01-23 15:27:49 +0100577 {} /* terminator */
578};
579
Matt Porterf3302a52006-07-31 12:49:34 +0200580static unsigned int ref9205_pin_configs[12] = {
581 0x40000100, 0x40000100, 0x01016011, 0x01014010,
Matt Porter8b657272006-10-26 17:12:59 +0200582 0x01813122, 0x01a19021, 0x40000100, 0x40000100,
583 0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
Matt Porterf3302a52006-07-31 12:49:34 +0200584};
585
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100586static unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
Matt Porterf3302a52006-07-31 12:49:34 +0200587 ref9205_pin_configs,
588};
589
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100590static const char *stac9205_models[STAC_9205_MODELS] = {
591 [STAC_9205_REF] = "ref",
592};
593
594static struct snd_pci_quirk stac9205_cfg_tbl[] = {
595 /* SigmaTel reference board */
596 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
597 "DFI LanParty", STAC_9205_REF),
Matt Porterf3302a52006-07-31 12:49:34 +0200598 {} /* terminator */
599};
600
Richard Fish11b44bb2006-08-23 18:31:34 +0200601static int stac92xx_save_bios_config_regs(struct hda_codec *codec)
602{
603 int i;
604 struct sigmatel_spec *spec = codec->spec;
605
606 if (! spec->bios_pin_configs) {
607 spec->bios_pin_configs = kcalloc(spec->num_pins,
608 sizeof(*spec->bios_pin_configs), GFP_KERNEL);
609 if (! spec->bios_pin_configs)
610 return -ENOMEM;
611 }
612
613 for (i = 0; i < spec->num_pins; i++) {
614 hda_nid_t nid = spec->pin_nids[i];
615 unsigned int pin_cfg;
616
617 pin_cfg = snd_hda_codec_read(codec, nid, 0,
618 AC_VERB_GET_CONFIG_DEFAULT, 0x00);
619 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x bios pin config %8.8x\n",
620 nid, pin_cfg);
621 spec->bios_pin_configs[i] = pin_cfg;
622 }
623
624 return 0;
625}
626
Matt2f2f4252005-04-13 14:45:30 +0200627static void stac92xx_set_config_regs(struct hda_codec *codec)
628{
629 int i;
630 struct sigmatel_spec *spec = codec->spec;
631 unsigned int pin_cfg;
632
Richard Fish11b44bb2006-08-23 18:31:34 +0200633 if (! spec->pin_nids || ! spec->pin_configs)
634 return;
635
636 for (i = 0; i < spec->num_pins; i++) {
Matt2f2f4252005-04-13 14:45:30 +0200637 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
638 AC_VERB_SET_CONFIG_DEFAULT_BYTES_0,
639 spec->pin_configs[i] & 0x000000ff);
640 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
641 AC_VERB_SET_CONFIG_DEFAULT_BYTES_1,
642 (spec->pin_configs[i] & 0x0000ff00) >> 8);
643 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
644 AC_VERB_SET_CONFIG_DEFAULT_BYTES_2,
645 (spec->pin_configs[i] & 0x00ff0000) >> 16);
646 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
647 AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
648 spec->pin_configs[i] >> 24);
649 pin_cfg = snd_hda_codec_read(codec, spec->pin_nids[i], 0,
650 AC_VERB_GET_CONFIG_DEFAULT,
651 0x00);
Matt Porter403d1942005-11-29 15:00:51 +0100652 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x pin config %8.8x\n", spec->pin_nids[i], pin_cfg);
Matt2f2f4252005-04-13 14:45:30 +0200653 }
654}
Matt2f2f4252005-04-13 14:45:30 +0200655
Matt2f2f4252005-04-13 14:45:30 +0200656/*
657 * Analog playback callbacks
658 */
659static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
660 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100661 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200662{
663 struct sigmatel_spec *spec = codec->spec;
664 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
665}
666
667static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
668 struct hda_codec *codec,
669 unsigned int stream_tag,
670 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100671 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200672{
673 struct sigmatel_spec *spec = codec->spec;
Matt Porter403d1942005-11-29 15:00:51 +0100674 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
Matt2f2f4252005-04-13 14:45:30 +0200675}
676
677static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
678 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100679 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200680{
681 struct sigmatel_spec *spec = codec->spec;
682 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
683}
684
685/*
Mattdabbed62005-06-14 10:19:34 +0200686 * Digital playback callbacks
687 */
688static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
689 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100690 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +0200691{
692 struct sigmatel_spec *spec = codec->spec;
693 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
694}
695
696static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
697 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100698 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +0200699{
700 struct sigmatel_spec *spec = codec->spec;
701 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
702}
703
704
705/*
Matt2f2f4252005-04-13 14:45:30 +0200706 * Analog capture callbacks
707 */
708static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
709 struct hda_codec *codec,
710 unsigned int stream_tag,
711 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100712 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200713{
714 struct sigmatel_spec *spec = codec->spec;
715
716 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
717 stream_tag, 0, format);
718 return 0;
719}
720
721static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
722 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100723 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200724{
725 struct sigmatel_spec *spec = codec->spec;
726
727 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 0, 0, 0);
728 return 0;
729}
730
Mattdabbed62005-06-14 10:19:34 +0200731static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
732 .substreams = 1,
733 .channels_min = 2,
734 .channels_max = 2,
735 /* NID is set in stac92xx_build_pcms */
736 .ops = {
737 .open = stac92xx_dig_playback_pcm_open,
738 .close = stac92xx_dig_playback_pcm_close
739 },
740};
741
742static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
743 .substreams = 1,
744 .channels_min = 2,
745 .channels_max = 2,
746 /* NID is set in stac92xx_build_pcms */
747};
748
Matt2f2f4252005-04-13 14:45:30 +0200749static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
750 .substreams = 1,
751 .channels_min = 2,
Mattc7d4b2f2005-06-27 14:59:41 +0200752 .channels_max = 8,
Matt2f2f4252005-04-13 14:45:30 +0200753 .nid = 0x02, /* NID to query formats and rates */
754 .ops = {
755 .open = stac92xx_playback_pcm_open,
756 .prepare = stac92xx_playback_pcm_prepare,
757 .cleanup = stac92xx_playback_pcm_cleanup
758 },
759};
760
Matt Porter3cc08dc2006-01-23 15:27:49 +0100761static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
762 .substreams = 1,
763 .channels_min = 2,
764 .channels_max = 2,
765 .nid = 0x06, /* NID to query formats and rates */
766 .ops = {
767 .open = stac92xx_playback_pcm_open,
768 .prepare = stac92xx_playback_pcm_prepare,
769 .cleanup = stac92xx_playback_pcm_cleanup
770 },
771};
772
Matt2f2f4252005-04-13 14:45:30 +0200773static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
774 .substreams = 2,
775 .channels_min = 2,
776 .channels_max = 2,
Matt Porter3cc08dc2006-01-23 15:27:49 +0100777 /* NID is set in stac92xx_build_pcms */
Matt2f2f4252005-04-13 14:45:30 +0200778 .ops = {
779 .prepare = stac92xx_capture_pcm_prepare,
780 .cleanup = stac92xx_capture_pcm_cleanup
781 },
782};
783
784static int stac92xx_build_pcms(struct hda_codec *codec)
785{
786 struct sigmatel_spec *spec = codec->spec;
787 struct hda_pcm *info = spec->pcm_rec;
788
789 codec->num_pcms = 1;
790 codec->pcm_info = info;
791
Mattc7d4b2f2005-06-27 14:59:41 +0200792 info->name = "STAC92xx Analog";
Matt2f2f4252005-04-13 14:45:30 +0200793 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
Matt2f2f4252005-04-13 14:45:30 +0200794 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100795 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
796
797 if (spec->alt_switch) {
798 codec->num_pcms++;
799 info++;
800 info->name = "STAC92xx Analog Alt";
801 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
802 }
Matt2f2f4252005-04-13 14:45:30 +0200803
Mattdabbed62005-06-14 10:19:34 +0200804 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
805 codec->num_pcms++;
806 info++;
807 info->name = "STAC92xx Digital";
808 if (spec->multiout.dig_out_nid) {
809 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
810 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
811 }
812 if (spec->dig_in_nid) {
813 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
814 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
815 }
816 }
817
Matt2f2f4252005-04-13 14:45:30 +0200818 return 0;
819}
820
Takashi Iwaic960a032006-03-23 17:06:28 +0100821static unsigned int stac92xx_get_vref(struct hda_codec *codec, hda_nid_t nid)
822{
823 unsigned int pincap = snd_hda_param_read(codec, nid,
824 AC_PAR_PIN_CAP);
825 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
826 if (pincap & AC_PINCAP_VREF_100)
827 return AC_PINCTL_VREF_100;
828 if (pincap & AC_PINCAP_VREF_80)
829 return AC_PINCTL_VREF_80;
830 if (pincap & AC_PINCAP_VREF_50)
831 return AC_PINCTL_VREF_50;
832 if (pincap & AC_PINCAP_VREF_GRD)
833 return AC_PINCTL_VREF_GRD;
834 return 0;
835}
836
Matt Porter403d1942005-11-29 15:00:51 +0100837static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
838
839{
840 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
841}
842
843static int stac92xx_io_switch_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
844{
845 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
846 uinfo->count = 1;
847 uinfo->value.integer.min = 0;
848 uinfo->value.integer.max = 1;
849 return 0;
850}
851
852static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
853{
854 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
855 struct sigmatel_spec *spec = codec->spec;
856 int io_idx = kcontrol-> private_value & 0xff;
857
858 ucontrol->value.integer.value[0] = spec->io_switch[io_idx];
859 return 0;
860}
861
862static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
863{
864 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
865 struct sigmatel_spec *spec = codec->spec;
866 hda_nid_t nid = kcontrol->private_value >> 8;
867 int io_idx = kcontrol-> private_value & 0xff;
868 unsigned short val = ucontrol->value.integer.value[0];
869
870 spec->io_switch[io_idx] = val;
871
872 if (val)
873 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
Takashi Iwaic960a032006-03-23 17:06:28 +0100874 else {
875 unsigned int pinctl = AC_PINCTL_IN_EN;
876 if (io_idx) /* set VREF for mic */
877 pinctl |= stac92xx_get_vref(codec, nid);
878 stac92xx_auto_set_pinctl(codec, nid, pinctl);
879 }
Matt Porter403d1942005-11-29 15:00:51 +0100880 return 1;
881}
882
883#define STAC_CODEC_IO_SWITCH(xname, xpval) \
884 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
885 .name = xname, \
886 .index = 0, \
887 .info = stac92xx_io_switch_info, \
888 .get = stac92xx_io_switch_get, \
889 .put = stac92xx_io_switch_put, \
890 .private_value = xpval, \
891 }
892
893
Mattc7d4b2f2005-06-27 14:59:41 +0200894enum {
895 STAC_CTL_WIDGET_VOL,
896 STAC_CTL_WIDGET_MUTE,
Matt Porter403d1942005-11-29 15:00:51 +0100897 STAC_CTL_WIDGET_IO_SWITCH,
Mattc7d4b2f2005-06-27 14:59:41 +0200898};
899
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100900static struct snd_kcontrol_new stac92xx_control_templates[] = {
Mattc7d4b2f2005-06-27 14:59:41 +0200901 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
902 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Matt Porter403d1942005-11-29 15:00:51 +0100903 STAC_CODEC_IO_SWITCH(NULL, 0),
Mattc7d4b2f2005-06-27 14:59:41 +0200904};
905
906/* add dynamic controls */
907static int stac92xx_add_control(struct sigmatel_spec *spec, int type, const char *name, unsigned long val)
908{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100909 struct snd_kcontrol_new *knew;
Mattc7d4b2f2005-06-27 14:59:41 +0200910
911 if (spec->num_kctl_used >= spec->num_kctl_alloc) {
912 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
913
914 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */
915 if (! knew)
916 return -ENOMEM;
917 if (spec->kctl_alloc) {
918 memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
919 kfree(spec->kctl_alloc);
920 }
921 spec->kctl_alloc = knew;
922 spec->num_kctl_alloc = num;
923 }
924
925 knew = &spec->kctl_alloc[spec->num_kctl_used];
926 *knew = stac92xx_control_templates[type];
Takashi Iwai82fe0c52005-06-30 10:54:33 +0200927 knew->name = kstrdup(name, GFP_KERNEL);
Mattc7d4b2f2005-06-27 14:59:41 +0200928 if (! knew->name)
929 return -ENOMEM;
930 knew->private_value = val;
931 spec->num_kctl_used++;
932 return 0;
933}
934
Matt Porter403d1942005-11-29 15:00:51 +0100935/* flag inputs as additional dynamic lineouts */
936static int stac92xx_add_dyn_out_pins(struct hda_codec *codec, struct auto_pin_cfg *cfg)
937{
938 struct sigmatel_spec *spec = codec->spec;
939
940 switch (cfg->line_outs) {
941 case 3:
942 /* add line-in as side */
943 if (cfg->input_pins[AUTO_PIN_LINE]) {
944 cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_LINE];
945 spec->line_switch = 1;
946 cfg->line_outs++;
947 }
948 break;
949 case 2:
950 /* add line-in as clfe and mic as side */
951 if (cfg->input_pins[AUTO_PIN_LINE]) {
952 cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_LINE];
953 spec->line_switch = 1;
954 cfg->line_outs++;
955 }
956 if (cfg->input_pins[AUTO_PIN_MIC]) {
957 cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_MIC];
958 spec->mic_switch = 1;
959 cfg->line_outs++;
960 }
961 break;
962 case 1:
963 /* add line-in as surr and mic as clfe */
964 if (cfg->input_pins[AUTO_PIN_LINE]) {
965 cfg->line_out_pins[1] = cfg->input_pins[AUTO_PIN_LINE];
966 spec->line_switch = 1;
967 cfg->line_outs++;
968 }
969 if (cfg->input_pins[AUTO_PIN_MIC]) {
970 cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_MIC];
971 spec->mic_switch = 1;
972 cfg->line_outs++;
973 }
974 break;
975 }
976
977 return 0;
978}
979
Matt Porter3cc08dc2006-01-23 15:27:49 +0100980/*
981 * XXX The line_out pin widget connection list may not be set to the
982 * desired DAC nid. This is the case on 927x where ports A and B can
983 * be routed to several DACs.
984 *
985 * This requires an analysis of the line-out/hp pin configuration
986 * to provide a best fit for pin/DAC configurations that are routable.
987 * For now, 927x DAC4 is not supported and 927x DAC1 output to ports
988 * A and B is not supported.
989 */
Mattc7d4b2f2005-06-27 14:59:41 +0200990/* fill in the dac_nids table from the parsed pin configuration */
Takashi Iwai19039bd2006-06-28 15:52:16 +0200991static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec,
992 const struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +0200993{
994 struct sigmatel_spec *spec = codec->spec;
995 hda_nid_t nid;
996 int i;
997
998 /* check the pins hardwired to audio widget */
999 for (i = 0; i < cfg->line_outs; i++) {
1000 nid = cfg->line_out_pins[i];
1001 spec->multiout.dac_nids[i] = snd_hda_codec_read(codec, nid, 0,
1002 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
1003 }
1004
Takashi Iwai82bc9552006-03-21 11:24:42 +01001005 spec->multiout.num_dacs = cfg->line_outs;
Mattc7d4b2f2005-06-27 14:59:41 +02001006
1007 return 0;
1008}
1009
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001010/* create volume control/switch for the given prefx type */
1011static int create_controls(struct sigmatel_spec *spec, const char *pfx, hda_nid_t nid, int chs)
1012{
1013 char name[32];
1014 int err;
1015
1016 sprintf(name, "%s Playback Volume", pfx);
1017 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, name,
1018 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1019 if (err < 0)
1020 return err;
1021 sprintf(name, "%s Playback Switch", pfx);
1022 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, name,
1023 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1024 if (err < 0)
1025 return err;
1026 return 0;
1027}
1028
Mattc7d4b2f2005-06-27 14:59:41 +02001029/* add playback controls from the parsed DAC table */
Takashi Iwai19039bd2006-06-28 15:52:16 +02001030static int stac92xx_auto_create_multi_out_ctls(struct sigmatel_spec *spec,
1031 const struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02001032{
Takashi Iwai19039bd2006-06-28 15:52:16 +02001033 static const char *chname[4] = {
1034 "Front", "Surround", NULL /*CLFE*/, "Side"
1035 };
Mattc7d4b2f2005-06-27 14:59:41 +02001036 hda_nid_t nid;
1037 int i, err;
1038
1039 for (i = 0; i < cfg->line_outs; i++) {
Matt Porter403d1942005-11-29 15:00:51 +01001040 if (!spec->multiout.dac_nids[i])
Mattc7d4b2f2005-06-27 14:59:41 +02001041 continue;
1042
1043 nid = spec->multiout.dac_nids[i];
1044
1045 if (i == 2) {
1046 /* Center/LFE */
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001047 err = create_controls(spec, "Center", nid, 1);
1048 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001049 return err;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001050 err = create_controls(spec, "LFE", nid, 2);
1051 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001052 return err;
1053 } else {
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001054 err = create_controls(spec, chname[i], nid, 3);
1055 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001056 return err;
1057 }
1058 }
1059
Matt Porter403d1942005-11-29 15:00:51 +01001060 if (spec->line_switch)
1061 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Line In as Output Switch", cfg->input_pins[AUTO_PIN_LINE] << 8)) < 0)
1062 return err;
1063
1064 if (spec->mic_switch)
1065 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Mic as Output Switch", (cfg->input_pins[AUTO_PIN_MIC] << 8) | 1)) < 0)
1066 return err;
1067
Mattc7d4b2f2005-06-27 14:59:41 +02001068 return 0;
1069}
1070
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001071static int check_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
1072{
1073 int i;
1074
1075 for (i = 0; i < spec->multiout.num_dacs; i++) {
1076 if (spec->multiout.dac_nids[i] == nid)
1077 return 1;
1078 }
1079 if (spec->multiout.hp_nid == nid)
1080 return 1;
1081 return 0;
1082}
1083
1084static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
1085{
1086 if (!spec->multiout.hp_nid)
1087 spec->multiout.hp_nid = nid;
1088 else if (spec->multiout.num_dacs > 4) {
1089 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
1090 return 1;
1091 } else {
1092 spec->multiout.dac_nids[spec->multiout.num_dacs] = nid;
1093 spec->multiout.num_dacs++;
1094 }
1095 return 0;
1096}
1097
1098/* add playback controls for Speaker and HP outputs */
1099static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
1100 struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02001101{
1102 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02001103 hda_nid_t nid;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001104 int i, old_num_dacs, err;
Mattc7d4b2f2005-06-27 14:59:41 +02001105
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001106 old_num_dacs = spec->multiout.num_dacs;
1107 for (i = 0; i < cfg->hp_outs; i++) {
1108 unsigned int wid_caps = get_wcaps(codec, cfg->hp_pins[i]);
1109 if (wid_caps & AC_WCAP_UNSOL_CAP)
1110 spec->hp_detect = 1;
1111 nid = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
1112 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
1113 if (check_in_dac_nids(spec, nid))
1114 nid = 0;
1115 if (! nid)
Mattc7d4b2f2005-06-27 14:59:41 +02001116 continue;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001117 add_spec_dacs(spec, nid);
1118 }
1119 for (i = 0; i < cfg->speaker_outs; i++) {
1120 nid = snd_hda_codec_read(codec, cfg->speaker_pins[0], 0,
1121 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
1122 if (check_in_dac_nids(spec, nid))
1123 nid = 0;
1124 if (check_in_dac_nids(spec, nid))
1125 nid = 0;
1126 if (! nid)
1127 continue;
1128 add_spec_dacs(spec, nid);
Mattc7d4b2f2005-06-27 14:59:41 +02001129 }
1130
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001131 for (i = old_num_dacs; i < spec->multiout.num_dacs; i++) {
1132 static const char *pfxs[] = {
1133 "Speaker", "External Speaker", "Speaker2",
1134 };
1135 err = create_controls(spec, pfxs[i - old_num_dacs],
1136 spec->multiout.dac_nids[i], 3);
1137 if (err < 0)
1138 return err;
1139 }
1140 if (spec->multiout.hp_nid) {
1141 const char *pfx;
1142 if (old_num_dacs == spec->multiout.num_dacs)
1143 pfx = "Master";
1144 else
1145 pfx = "Headphone";
1146 err = create_controls(spec, pfx, spec->multiout.hp_nid, 3);
1147 if (err < 0)
1148 return err;
1149 }
Mattc7d4b2f2005-06-27 14:59:41 +02001150
1151 return 0;
1152}
1153
Matt Porter8b657272006-10-26 17:12:59 +02001154/* labels for dmic mux inputs */
Adrian Bunkddc2cec2006-11-20 12:03:44 +01001155static const char *stac92xx_dmic_labels[5] = {
Matt Porter8b657272006-10-26 17:12:59 +02001156 "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
1157 "Digital Mic 3", "Digital Mic 4"
1158};
1159
1160/* create playback/capture controls for input pins on dmic capable codecs */
1161static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
1162 const struct auto_pin_cfg *cfg)
1163{
1164 struct sigmatel_spec *spec = codec->spec;
1165 struct hda_input_mux *dimux = &spec->private_dimux;
1166 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
1167 int i, j;
1168
1169 dimux->items[dimux->num_items].label = stac92xx_dmic_labels[0];
1170 dimux->items[dimux->num_items].index = 0;
1171 dimux->num_items++;
1172
1173 for (i = 0; i < spec->num_dmics; i++) {
1174 int index;
1175 int num_cons;
1176 unsigned int def_conf;
1177
1178 def_conf = snd_hda_codec_read(codec,
1179 spec->dmic_nids[i],
1180 0,
1181 AC_VERB_GET_CONFIG_DEFAULT,
1182 0);
1183 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
1184 continue;
1185
1186 num_cons = snd_hda_get_connections(codec,
1187 spec->dmux_nid,
1188 con_lst,
1189 HDA_MAX_NUM_INPUTS);
1190 for (j = 0; j < num_cons; j++)
1191 if (con_lst[j] == spec->dmic_nids[i]) {
1192 index = j;
1193 goto found;
1194 }
1195 continue;
1196found:
1197 dimux->items[dimux->num_items].label =
1198 stac92xx_dmic_labels[dimux->num_items];
1199 dimux->items[dimux->num_items].index = index;
1200 dimux->num_items++;
1201 }
1202
1203 return 0;
1204}
1205
Mattc7d4b2f2005-06-27 14:59:41 +02001206/* create playback/capture controls for input pins */
1207static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
1208{
1209 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02001210 struct hda_input_mux *imux = &spec->private_imux;
1211 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
1212 int i, j, k;
1213
1214 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwai314634b2006-09-21 11:56:18 +02001215 int index;
Mattc7d4b2f2005-06-27 14:59:41 +02001216
Takashi Iwai314634b2006-09-21 11:56:18 +02001217 if (!cfg->input_pins[i])
1218 continue;
1219 index = -1;
1220 for (j = 0; j < spec->num_muxes; j++) {
1221 int num_cons;
1222 num_cons = snd_hda_get_connections(codec,
1223 spec->mux_nids[j],
1224 con_lst,
1225 HDA_MAX_NUM_INPUTS);
1226 for (k = 0; k < num_cons; k++)
1227 if (con_lst[k] == cfg->input_pins[i]) {
1228 index = k;
1229 goto found;
1230 }
Mattc7d4b2f2005-06-27 14:59:41 +02001231 }
Takashi Iwai314634b2006-09-21 11:56:18 +02001232 continue;
1233 found:
1234 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
1235 imux->items[imux->num_items].index = index;
1236 imux->num_items++;
Mattc7d4b2f2005-06-27 14:59:41 +02001237 }
1238
Sam Revitch62fe78e2006-05-10 15:09:17 +02001239 if (imux->num_items == 1) {
1240 /*
1241 * Set the current input for the muxes.
1242 * The STAC9221 has two input muxes with identical source
1243 * NID lists. Hopefully this won't get confused.
1244 */
1245 for (i = 0; i < spec->num_muxes; i++) {
1246 snd_hda_codec_write(codec, spec->mux_nids[i], 0,
1247 AC_VERB_SET_CONNECT_SEL,
1248 imux->items[0].index);
1249 }
1250 }
1251
Mattc7d4b2f2005-06-27 14:59:41 +02001252 return 0;
1253}
1254
Mattc7d4b2f2005-06-27 14:59:41 +02001255static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
1256{
1257 struct sigmatel_spec *spec = codec->spec;
1258 int i;
1259
1260 for (i = 0; i < spec->autocfg.line_outs; i++) {
1261 hda_nid_t nid = spec->autocfg.line_out_pins[i];
1262 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
1263 }
1264}
1265
1266static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
1267{
1268 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001269 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02001270
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001271 for (i = 0; i < spec->autocfg.hp_outs; i++) {
1272 hda_nid_t pin;
1273 pin = spec->autocfg.hp_pins[i];
1274 if (pin) /* connect to front */
1275 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
1276 }
1277 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
1278 hda_nid_t pin;
1279 pin = spec->autocfg.speaker_pins[i];
1280 if (pin) /* connect to front */
1281 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
1282 }
Mattc7d4b2f2005-06-27 14:59:41 +02001283}
1284
Matt Porter3cc08dc2006-01-23 15:27:49 +01001285static 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 +02001286{
1287 struct sigmatel_spec *spec = codec->spec;
1288 int err;
1289
Matt Porter8b657272006-10-26 17:12:59 +02001290 if ((err = snd_hda_parse_pin_def_config(codec,
1291 &spec->autocfg,
1292 spec->dmic_nids)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001293 return err;
Takashi Iwai82bc9552006-03-21 11:24:42 +01001294 if (! spec->autocfg.line_outs)
Matt Porter869264c2006-01-25 19:20:50 +01001295 return 0; /* can't find valid pin config */
Takashi Iwai19039bd2006-06-28 15:52:16 +02001296
Matt Porter403d1942005-11-29 15:00:51 +01001297 if ((err = stac92xx_add_dyn_out_pins(codec, &spec->autocfg)) < 0)
1298 return err;
Takashi Iwai19039bd2006-06-28 15:52:16 +02001299 if (spec->multiout.num_dacs == 0)
1300 if ((err = stac92xx_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
1301 return err;
Mattc7d4b2f2005-06-27 14:59:41 +02001302
1303 if ((err = stac92xx_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
1304 (err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg)) < 0 ||
1305 (err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
1306 return err;
1307
Matt Porter8b657272006-10-26 17:12:59 +02001308 if (spec->num_dmics > 0)
1309 if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
1310 &spec->autocfg)) < 0)
1311 return err;
1312
Mattc7d4b2f2005-06-27 14:59:41 +02001313 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Matt Porter403d1942005-11-29 15:00:51 +01001314 if (spec->multiout.max_channels > 2)
Mattc7d4b2f2005-06-27 14:59:41 +02001315 spec->surr_switch = 1;
Mattc7d4b2f2005-06-27 14:59:41 +02001316
Takashi Iwai82bc9552006-03-21 11:24:42 +01001317 if (spec->autocfg.dig_out_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01001318 spec->multiout.dig_out_nid = dig_out;
Takashi Iwai82bc9552006-03-21 11:24:42 +01001319 if (spec->autocfg.dig_in_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01001320 spec->dig_in_nid = dig_in;
Mattc7d4b2f2005-06-27 14:59:41 +02001321
1322 if (spec->kctl_alloc)
1323 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
1324
1325 spec->input_mux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02001326 spec->dinput_mux = &spec->private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +02001327
1328 return 1;
1329}
1330
Takashi Iwai82bc9552006-03-21 11:24:42 +01001331/* add playback controls for HP output */
1332static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
1333 struct auto_pin_cfg *cfg)
1334{
1335 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001336 hda_nid_t pin = cfg->hp_pins[0];
Takashi Iwai82bc9552006-03-21 11:24:42 +01001337 unsigned int wid_caps;
1338
1339 if (! pin)
1340 return 0;
1341
1342 wid_caps = get_wcaps(codec, pin);
Takashi Iwai505cb342006-03-27 12:51:52 +02001343 if (wid_caps & AC_WCAP_UNSOL_CAP)
Takashi Iwai82bc9552006-03-21 11:24:42 +01001344 spec->hp_detect = 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +01001345
1346 return 0;
1347}
1348
Richard Fish160ea0d2006-09-06 13:58:25 +02001349/* add playback controls for LFE output */
1350static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
1351 struct auto_pin_cfg *cfg)
1352{
1353 struct sigmatel_spec *spec = codec->spec;
1354 int err;
1355 hda_nid_t lfe_pin = 0x0;
1356 int i;
1357
1358 /*
1359 * search speaker outs and line outs for a mono speaker pin
1360 * with an amp. If one is found, add LFE controls
1361 * for it.
1362 */
1363 for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
1364 hda_nid_t pin = spec->autocfg.speaker_pins[i];
1365 unsigned long wcaps = get_wcaps(codec, pin);
1366 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
1367 if (wcaps == AC_WCAP_OUT_AMP)
1368 /* found a mono speaker with an amp, must be lfe */
1369 lfe_pin = pin;
1370 }
1371
1372 /* if speaker_outs is 0, then speakers may be in line_outs */
1373 if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
1374 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
1375 hda_nid_t pin = spec->autocfg.line_out_pins[i];
1376 unsigned long cfg;
1377 cfg = snd_hda_codec_read(codec, pin, 0,
1378 AC_VERB_GET_CONFIG_DEFAULT,
1379 0x00);
1380 if (get_defcfg_device(cfg) == AC_JACK_SPEAKER) {
1381 unsigned long wcaps = get_wcaps(codec, pin);
1382 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
1383 if (wcaps == AC_WCAP_OUT_AMP)
1384 /* found a mono speaker with an amp,
1385 must be lfe */
1386 lfe_pin = pin;
1387 }
1388 }
1389 }
1390
1391 if (lfe_pin) {
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001392 err = create_controls(spec, "LFE", lfe_pin, 1);
Richard Fish160ea0d2006-09-06 13:58:25 +02001393 if (err < 0)
1394 return err;
1395 }
1396
1397 return 0;
1398}
1399
Mattc7d4b2f2005-06-27 14:59:41 +02001400static int stac9200_parse_auto_config(struct hda_codec *codec)
1401{
1402 struct sigmatel_spec *spec = codec->spec;
1403 int err;
1404
Kailang Yangdf694da2005-12-05 19:42:22 +01001405 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001406 return err;
1407
1408 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
1409 return err;
1410
Takashi Iwai82bc9552006-03-21 11:24:42 +01001411 if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
1412 return err;
1413
Richard Fish160ea0d2006-09-06 13:58:25 +02001414 if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
1415 return err;
1416
Takashi Iwai82bc9552006-03-21 11:24:42 +01001417 if (spec->autocfg.dig_out_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02001418 spec->multiout.dig_out_nid = 0x05;
Takashi Iwai82bc9552006-03-21 11:24:42 +01001419 if (spec->autocfg.dig_in_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02001420 spec->dig_in_nid = 0x04;
Mattc7d4b2f2005-06-27 14:59:41 +02001421
1422 if (spec->kctl_alloc)
1423 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
1424
1425 spec->input_mux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02001426 spec->dinput_mux = &spec->private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +02001427
1428 return 1;
1429}
1430
Sam Revitch62fe78e2006-05-10 15:09:17 +02001431/*
1432 * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
1433 * funky external mute control using GPIO pins.
1434 */
1435
1436static void stac922x_gpio_mute(struct hda_codec *codec, int pin, int muted)
1437{
1438 unsigned int gpiostate, gpiomask, gpiodir;
1439
1440 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
1441 AC_VERB_GET_GPIO_DATA, 0);
1442
1443 if (!muted)
1444 gpiostate |= (1 << pin);
1445 else
1446 gpiostate &= ~(1 << pin);
1447
1448 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
1449 AC_VERB_GET_GPIO_MASK, 0);
1450 gpiomask |= (1 << pin);
1451
1452 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
1453 AC_VERB_GET_GPIO_DIRECTION, 0);
1454 gpiodir |= (1 << pin);
1455
1456 /* AppleHDA seems to do this -- WTF is this verb?? */
1457 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
1458
1459 snd_hda_codec_write(codec, codec->afg, 0,
1460 AC_VERB_SET_GPIO_MASK, gpiomask);
1461 snd_hda_codec_write(codec, codec->afg, 0,
1462 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
1463
1464 msleep(1);
1465
1466 snd_hda_codec_write(codec, codec->afg, 0,
1467 AC_VERB_SET_GPIO_DATA, gpiostate);
1468}
1469
Takashi Iwai314634b2006-09-21 11:56:18 +02001470static void enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
1471 unsigned int event)
1472{
1473 if (get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP)
1474 snd_hda_codec_write(codec, nid, 0,
1475 AC_VERB_SET_UNSOLICITED_ENABLE,
1476 (AC_USRSP_EN | event));
1477}
1478
Mattc7d4b2f2005-06-27 14:59:41 +02001479static int stac92xx_init(struct hda_codec *codec)
1480{
1481 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai82bc9552006-03-21 11:24:42 +01001482 struct auto_pin_cfg *cfg = &spec->autocfg;
1483 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02001484
Mattc7d4b2f2005-06-27 14:59:41 +02001485 snd_hda_sequence_write(codec, spec->init);
1486
Takashi Iwai82bc9552006-03-21 11:24:42 +01001487 /* set up pins */
1488 if (spec->hp_detect) {
Takashi Iwai505cb342006-03-27 12:51:52 +02001489 /* Enable unsolicited responses on the HP widget */
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001490 for (i = 0; i < cfg->hp_outs; i++)
Takashi Iwai314634b2006-09-21 11:56:18 +02001491 enable_pin_detect(codec, cfg->hp_pins[i],
1492 STAC_HP_EVENT);
Takashi Iwaieb995a82006-09-21 14:28:21 +02001493 stac92xx_auto_init_hp_out(codec);
Takashi Iwai82bc9552006-03-21 11:24:42 +01001494 /* fake event to set up pins */
1495 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
1496 } else {
1497 stac92xx_auto_init_multi_out(codec);
1498 stac92xx_auto_init_hp_out(codec);
1499 }
1500 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwaic960a032006-03-23 17:06:28 +01001501 hda_nid_t nid = cfg->input_pins[i];
1502 if (nid) {
1503 unsigned int pinctl = AC_PINCTL_IN_EN;
1504 if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC)
1505 pinctl |= stac92xx_get_vref(codec, nid);
1506 stac92xx_auto_set_pinctl(codec, nid, pinctl);
1507 }
Takashi Iwai82bc9552006-03-21 11:24:42 +01001508 }
Matt Porter8b657272006-10-26 17:12:59 +02001509 if (spec->num_dmics > 0)
1510 for (i = 0; i < spec->num_dmics; i++)
1511 stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
1512 AC_PINCTL_IN_EN);
1513
Takashi Iwai82bc9552006-03-21 11:24:42 +01001514 if (cfg->dig_out_pin)
1515 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pin,
1516 AC_PINCTL_OUT_EN);
1517 if (cfg->dig_in_pin)
1518 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
1519 AC_PINCTL_IN_EN);
1520
Sam Revitch62fe78e2006-05-10 15:09:17 +02001521 if (spec->gpio_mute) {
1522 stac922x_gpio_mute(codec, 0, 0);
1523 stac922x_gpio_mute(codec, 1, 0);
1524 }
1525
Mattc7d4b2f2005-06-27 14:59:41 +02001526 return 0;
1527}
1528
Matt2f2f4252005-04-13 14:45:30 +02001529static void stac92xx_free(struct hda_codec *codec)
1530{
Mattc7d4b2f2005-06-27 14:59:41 +02001531 struct sigmatel_spec *spec = codec->spec;
1532 int i;
1533
1534 if (! spec)
1535 return;
1536
1537 if (spec->kctl_alloc) {
1538 for (i = 0; i < spec->num_kctl_used; i++)
1539 kfree(spec->kctl_alloc[i].name);
1540 kfree(spec->kctl_alloc);
1541 }
1542
Richard Fish11b44bb2006-08-23 18:31:34 +02001543 if (spec->bios_pin_configs)
1544 kfree(spec->bios_pin_configs);
1545
Mattc7d4b2f2005-06-27 14:59:41 +02001546 kfree(spec);
Matt2f2f4252005-04-13 14:45:30 +02001547}
1548
Matt4e550962005-07-04 17:51:39 +02001549static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
1550 unsigned int flag)
1551{
1552 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
1553 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Takashi Iwai314634b2006-09-21 11:56:18 +02001554 if (flag == AC_PINCTL_OUT_EN && (pin_ctl & AC_PINCTL_IN_EN))
1555 return;
Matt4e550962005-07-04 17:51:39 +02001556 snd_hda_codec_write(codec, nid, 0,
1557 AC_VERB_SET_PIN_WIDGET_CONTROL,
1558 pin_ctl | flag);
1559}
1560
1561static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
1562 unsigned int flag)
1563{
1564 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
1565 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
1566 snd_hda_codec_write(codec, nid, 0,
1567 AC_VERB_SET_PIN_WIDGET_CONTROL,
1568 pin_ctl & ~flag);
1569}
1570
Takashi Iwai314634b2006-09-21 11:56:18 +02001571static int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
1572{
1573 if (!nid)
1574 return 0;
1575 if (snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PIN_SENSE, 0x00)
1576 & (1 << 31))
1577 return 1;
1578 return 0;
1579}
1580
1581static void stac92xx_hp_detect(struct hda_codec *codec, unsigned int res)
Matt4e550962005-07-04 17:51:39 +02001582{
1583 struct sigmatel_spec *spec = codec->spec;
1584 struct auto_pin_cfg *cfg = &spec->autocfg;
1585 int i, presence;
1586
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001587 presence = 0;
1588 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai314634b2006-09-21 11:56:18 +02001589 presence = get_pin_presence(codec, cfg->hp_pins[i]);
1590 if (presence)
1591 break;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001592 }
Matt4e550962005-07-04 17:51:39 +02001593
1594 if (presence) {
1595 /* disable lineouts, enable hp */
1596 for (i = 0; i < cfg->line_outs; i++)
1597 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
1598 AC_PINCTL_OUT_EN);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001599 for (i = 0; i < cfg->speaker_outs; i++)
1600 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
1601 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02001602 } else {
1603 /* enable lineouts, disable hp */
1604 for (i = 0; i < cfg->line_outs; i++)
1605 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
1606 AC_PINCTL_OUT_EN);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001607 for (i = 0; i < cfg->speaker_outs; i++)
1608 stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
1609 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02001610 }
1611}
1612
Takashi Iwai314634b2006-09-21 11:56:18 +02001613static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
1614{
1615 switch (res >> 26) {
1616 case STAC_HP_EVENT:
1617 stac92xx_hp_detect(codec, res);
1618 break;
1619 }
1620}
1621
Mattff6fdc32005-06-27 15:06:52 +02001622#ifdef CONFIG_PM
1623static int stac92xx_resume(struct hda_codec *codec)
1624{
1625 struct sigmatel_spec *spec = codec->spec;
1626 int i;
1627
1628 stac92xx_init(codec);
Richard Fish11b44bb2006-08-23 18:31:34 +02001629 stac92xx_set_config_regs(codec);
Mattff6fdc32005-06-27 15:06:52 +02001630 for (i = 0; i < spec->num_mixers; i++)
1631 snd_hda_resume_ctls(codec, spec->mixers[i]);
1632 if (spec->multiout.dig_out_nid)
1633 snd_hda_resume_spdif_out(codec);
1634 if (spec->dig_in_nid)
1635 snd_hda_resume_spdif_in(codec);
1636
1637 return 0;
1638}
1639#endif
1640
Matt2f2f4252005-04-13 14:45:30 +02001641static struct hda_codec_ops stac92xx_patch_ops = {
1642 .build_controls = stac92xx_build_controls,
1643 .build_pcms = stac92xx_build_pcms,
1644 .init = stac92xx_init,
1645 .free = stac92xx_free,
Matt4e550962005-07-04 17:51:39 +02001646 .unsol_event = stac92xx_unsol_event,
Mattff6fdc32005-06-27 15:06:52 +02001647#ifdef CONFIG_PM
1648 .resume = stac92xx_resume,
1649#endif
Matt2f2f4252005-04-13 14:45:30 +02001650};
1651
1652static int patch_stac9200(struct hda_codec *codec)
1653{
1654 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02001655 int err;
Matt2f2f4252005-04-13 14:45:30 +02001656
Takashi Iwaie560d8d2005-09-09 14:21:46 +02001657 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02001658 if (spec == NULL)
1659 return -ENOMEM;
1660
1661 codec->spec = spec;
Richard Fish11b44bb2006-08-23 18:31:34 +02001662 spec->num_pins = 8;
1663 spec->pin_nids = stac9200_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001664 spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS,
1665 stac9200_models,
1666 stac9200_cfg_tbl);
Richard Fish11b44bb2006-08-23 18:31:34 +02001667 if (spec->board_config < 0) {
1668 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9200, using BIOS defaults\n");
1669 err = stac92xx_save_bios_config_regs(codec);
1670 if (err < 0) {
1671 stac92xx_free(codec);
1672 return err;
1673 }
1674 spec->pin_configs = spec->bios_pin_configs;
1675 } else {
Matt Porter403d1942005-11-29 15:00:51 +01001676 spec->pin_configs = stac9200_brd_tbl[spec->board_config];
1677 stac92xx_set_config_regs(codec);
1678 }
Matt2f2f4252005-04-13 14:45:30 +02001679
1680 spec->multiout.max_channels = 2;
1681 spec->multiout.num_dacs = 1;
1682 spec->multiout.dac_nids = stac9200_dac_nids;
1683 spec->adc_nids = stac9200_adc_nids;
1684 spec->mux_nids = stac9200_mux_nids;
Mattdabbed62005-06-14 10:19:34 +02001685 spec->num_muxes = 1;
Matt Porter8b657272006-10-26 17:12:59 +02001686 spec->num_dmics = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02001687
1688 spec->init = stac9200_core_init;
Matt2f2f4252005-04-13 14:45:30 +02001689 spec->mixer = stac9200_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02001690
1691 err = stac9200_parse_auto_config(codec);
1692 if (err < 0) {
1693 stac92xx_free(codec);
1694 return err;
1695 }
Matt2f2f4252005-04-13 14:45:30 +02001696
1697 codec->patch_ops = stac92xx_patch_ops;
1698
1699 return 0;
1700}
1701
1702static int patch_stac922x(struct hda_codec *codec)
1703{
1704 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02001705 int err;
Matt2f2f4252005-04-13 14:45:30 +02001706
Takashi Iwaie560d8d2005-09-09 14:21:46 +02001707 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02001708 if (spec == NULL)
1709 return -ENOMEM;
1710
1711 codec->spec = spec;
Richard Fish11b44bb2006-08-23 18:31:34 +02001712 spec->num_pins = 10;
1713 spec->pin_nids = stac922x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001714 spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS,
1715 stac922x_models,
1716 stac922x_cfg_tbl);
Richard Fish11b44bb2006-08-23 18:31:34 +02001717 if (spec->board_config < 0) {
1718 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC922x, "
1719 "using BIOS defaults\n");
1720 err = stac92xx_save_bios_config_regs(codec);
1721 if (err < 0) {
1722 stac92xx_free(codec);
1723 return err;
1724 }
1725 spec->pin_configs = spec->bios_pin_configs;
1726 } else if (stac922x_brd_tbl[spec->board_config] != NULL) {
Matt Porter403d1942005-11-29 15:00:51 +01001727 spec->pin_configs = stac922x_brd_tbl[spec->board_config];
1728 stac92xx_set_config_regs(codec);
1729 }
Matt2f2f4252005-04-13 14:45:30 +02001730
Matt2f2f4252005-04-13 14:45:30 +02001731 spec->adc_nids = stac922x_adc_nids;
1732 spec->mux_nids = stac922x_mux_nids;
Mattdabbed62005-06-14 10:19:34 +02001733 spec->num_muxes = 2;
Matt Porter8b657272006-10-26 17:12:59 +02001734 spec->num_dmics = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02001735
1736 spec->init = stac922x_core_init;
Matt2f2f4252005-04-13 14:45:30 +02001737 spec->mixer = stac922x_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02001738
1739 spec->multiout.dac_nids = spec->dac_nids;
Takashi Iwai19039bd2006-06-28 15:52:16 +02001740
Matt Porter3cc08dc2006-01-23 15:27:49 +01001741 err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
1742 if (err < 0) {
1743 stac92xx_free(codec);
1744 return err;
1745 }
1746
Sam Revitch62fe78e2006-05-10 15:09:17 +02001747 if (spec->board_config == STAC_MACMINI)
1748 spec->gpio_mute = 1;
1749
Matt Porter3cc08dc2006-01-23 15:27:49 +01001750 codec->patch_ops = stac92xx_patch_ops;
1751
1752 return 0;
1753}
1754
1755static int patch_stac927x(struct hda_codec *codec)
1756{
1757 struct sigmatel_spec *spec;
1758 int err;
1759
1760 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1761 if (spec == NULL)
1762 return -ENOMEM;
1763
1764 codec->spec = spec;
Richard Fish11b44bb2006-08-23 18:31:34 +02001765 spec->num_pins = 14;
1766 spec->pin_nids = stac927x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001767 spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS,
1768 stac927x_models,
1769 stac927x_cfg_tbl);
Richard Fish11b44bb2006-08-23 18:31:34 +02001770 if (spec->board_config < 0) {
Matt Porter3cc08dc2006-01-23 15:27:49 +01001771 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC927x, using BIOS defaults\n");
Richard Fish11b44bb2006-08-23 18:31:34 +02001772 err = stac92xx_save_bios_config_regs(codec);
1773 if (err < 0) {
1774 stac92xx_free(codec);
1775 return err;
1776 }
1777 spec->pin_configs = spec->bios_pin_configs;
1778 } else if (stac927x_brd_tbl[spec->board_config] != NULL) {
Matt Porter3cc08dc2006-01-23 15:27:49 +01001779 spec->pin_configs = stac927x_brd_tbl[spec->board_config];
1780 stac92xx_set_config_regs(codec);
1781 }
1782
Tobin Davis81d3dbd2006-08-22 19:44:45 +02001783 switch (spec->board_config) {
Tobin Davis93ed1502006-09-01 21:03:12 +02001784 case STAC_D965_3ST:
Tobin Davis81d3dbd2006-08-22 19:44:45 +02001785 spec->adc_nids = stac927x_adc_nids;
1786 spec->mux_nids = stac927x_mux_nids;
1787 spec->num_muxes = 3;
Matt Porter8b657272006-10-26 17:12:59 +02001788 spec->num_dmics = 0;
Tobin Davis93ed1502006-09-01 21:03:12 +02001789 spec->init = d965_core_init;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02001790 spec->mixer = stac9227_mixer;
1791 break;
Tobin Davis93ed1502006-09-01 21:03:12 +02001792 case STAC_D965_5ST:
1793 spec->adc_nids = stac927x_adc_nids;
1794 spec->mux_nids = stac927x_mux_nids;
1795 spec->num_muxes = 3;
Matt Porter8b657272006-10-26 17:12:59 +02001796 spec->num_dmics = 0;
Tobin Davis93ed1502006-09-01 21:03:12 +02001797 spec->init = d965_core_init;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02001798 spec->mixer = stac9227_mixer;
1799 break;
1800 default:
1801 spec->adc_nids = stac927x_adc_nids;
1802 spec->mux_nids = stac927x_mux_nids;
1803 spec->num_muxes = 3;
Matt Porter8b657272006-10-26 17:12:59 +02001804 spec->num_dmics = 0;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02001805 spec->init = stac927x_core_init;
1806 spec->mixer = stac927x_mixer;
1807 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01001808
1809 spec->multiout.dac_nids = spec->dac_nids;
1810
1811 err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
Mattc7d4b2f2005-06-27 14:59:41 +02001812 if (err < 0) {
1813 stac92xx_free(codec);
1814 return err;
1815 }
Matt2f2f4252005-04-13 14:45:30 +02001816
1817 codec->patch_ops = stac92xx_patch_ops;
1818
1819 return 0;
1820}
1821
Matt Porterf3302a52006-07-31 12:49:34 +02001822static int patch_stac9205(struct hda_codec *codec)
1823{
1824 struct sigmatel_spec *spec;
1825 int err;
1826
1827 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1828 if (spec == NULL)
1829 return -ENOMEM;
1830
1831 codec->spec = spec;
Richard Fish11b44bb2006-08-23 18:31:34 +02001832 spec->num_pins = 14;
1833 spec->pin_nids = stac9205_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001834 spec->board_config = snd_hda_check_board_config(codec, STAC_9205_MODELS,
1835 stac9205_models,
1836 stac9205_cfg_tbl);
Richard Fish11b44bb2006-08-23 18:31:34 +02001837 if (spec->board_config < 0) {
1838 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9205, using BIOS defaults\n");
1839 err = stac92xx_save_bios_config_regs(codec);
1840 if (err < 0) {
1841 stac92xx_free(codec);
1842 return err;
1843 }
1844 spec->pin_configs = spec->bios_pin_configs;
1845 } else {
Matt Porterf3302a52006-07-31 12:49:34 +02001846 spec->pin_configs = stac9205_brd_tbl[spec->board_config];
1847 stac92xx_set_config_regs(codec);
1848 }
1849
1850 spec->adc_nids = stac9205_adc_nids;
1851 spec->mux_nids = stac9205_mux_nids;
Matt Porter8b657272006-10-26 17:12:59 +02001852 spec->num_muxes = 2;
1853 spec->dmic_nids = stac9205_dmic_nids;
1854 spec->num_dmics = 2;
1855 spec->dmux_nid = 0x1d;
Matt Porterf3302a52006-07-31 12:49:34 +02001856
1857 spec->init = stac9205_core_init;
1858 spec->mixer = stac9205_mixer;
1859
1860 spec->multiout.dac_nids = spec->dac_nids;
1861
1862 err = stac92xx_parse_auto_config(codec, 0x1f, 0x20);
1863 if (err < 0) {
1864 stac92xx_free(codec);
1865 return err;
1866 }
1867
1868 codec->patch_ops = stac92xx_patch_ops;
1869
1870 return 0;
1871}
1872
Matt2f2f4252005-04-13 14:45:30 +02001873/*
Guillaume Munch6d859062006-08-22 17:15:47 +02001874 * STAC9872 hack
Takashi Iwaidb064e52006-03-16 16:04:58 +01001875 */
1876
Guillaume Munch99ccc562006-08-16 19:35:12 +02001877/* static config for Sony VAIO FE550G and Sony VAIO AR */
Takashi Iwaidb064e52006-03-16 16:04:58 +01001878static hda_nid_t vaio_dacs[] = { 0x2 };
1879#define VAIO_HP_DAC 0x5
1880static hda_nid_t vaio_adcs[] = { 0x8 /*,0x6*/ };
1881static hda_nid_t vaio_mux_nids[] = { 0x15 };
1882
1883static struct hda_input_mux vaio_mux = {
1884 .num_items = 2,
1885 .items = {
Takashi Iwaid7737812006-04-25 13:05:43 +02001886 /* { "HP", 0x0 }, */
1887 { "Line", 0x1 },
Takashi Iwaidb064e52006-03-16 16:04:58 +01001888 { "Mic", 0x2 },
1889 { "PCM", 0x3 },
1890 }
1891};
1892
1893static struct hda_verb vaio_init[] = {
1894 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
1895 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
1896 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
1897 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
1898 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
1899 {0x15, AC_VERB_SET_CONNECT_SEL, 0x2}, /* mic-sel: 0a,0d,14,02 */
1900 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
1901 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
1902 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
1903 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
1904 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
1905 {}
1906};
1907
Guillaume Munch6d859062006-08-22 17:15:47 +02001908static struct hda_verb vaio_ar_init[] = {
1909 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
1910 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
1911 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
1912 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
1913/* {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },*/ /* Optical Out */
1914 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
1915 {0x15, AC_VERB_SET_CONNECT_SEL, 0x2}, /* mic-sel: 0a,0d,14,02 */
1916 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
1917 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
1918/* {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},*/ /* Optical Out */
1919 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
1920 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
1921 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
1922 {}
1923};
1924
Takashi Iwaidb064e52006-03-16 16:04:58 +01001925/* bind volumes of both NID 0x02 and 0x05 */
1926static int vaio_master_vol_put(struct snd_kcontrol *kcontrol,
1927 struct snd_ctl_elem_value *ucontrol)
1928{
1929 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1930 long *valp = ucontrol->value.integer.value;
1931 int change;
1932
1933 change = snd_hda_codec_amp_update(codec, 0x02, 0, HDA_OUTPUT, 0,
1934 0x7f, valp[0] & 0x7f);
1935 change |= snd_hda_codec_amp_update(codec, 0x02, 1, HDA_OUTPUT, 0,
1936 0x7f, valp[1] & 0x7f);
1937 snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
1938 0x7f, valp[0] & 0x7f);
1939 snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
1940 0x7f, valp[1] & 0x7f);
1941 return change;
1942}
1943
1944/* bind volumes of both NID 0x02 and 0x05 */
1945static int vaio_master_sw_put(struct snd_kcontrol *kcontrol,
1946 struct snd_ctl_elem_value *ucontrol)
1947{
1948 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1949 long *valp = ucontrol->value.integer.value;
1950 int change;
1951
1952 change = snd_hda_codec_amp_update(codec, 0x02, 0, HDA_OUTPUT, 0,
Takashi Iwaia9393d72006-05-03 11:59:03 +02001953 0x80, (valp[0] ? 0 : 0x80));
Takashi Iwaidb064e52006-03-16 16:04:58 +01001954 change |= snd_hda_codec_amp_update(codec, 0x02, 1, HDA_OUTPUT, 0,
Takashi Iwaia9393d72006-05-03 11:59:03 +02001955 0x80, (valp[1] ? 0 : 0x80));
Takashi Iwaidb064e52006-03-16 16:04:58 +01001956 snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
Takashi Iwaia9393d72006-05-03 11:59:03 +02001957 0x80, (valp[0] ? 0 : 0x80));
Takashi Iwaidb064e52006-03-16 16:04:58 +01001958 snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
Takashi Iwaia9393d72006-05-03 11:59:03 +02001959 0x80, (valp[1] ? 0 : 0x80));
Takashi Iwaidb064e52006-03-16 16:04:58 +01001960 return change;
1961}
1962
1963static struct snd_kcontrol_new vaio_mixer[] = {
1964 {
1965 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1966 .name = "Master Playback Volume",
1967 .info = snd_hda_mixer_amp_volume_info,
1968 .get = snd_hda_mixer_amp_volume_get,
1969 .put = vaio_master_vol_put,
Takashi Iwaic2566522006-08-17 18:21:36 +02001970 .tlv = { .c = snd_hda_mixer_amp_tlv },
Takashi Iwaidb064e52006-03-16 16:04:58 +01001971 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
1972 },
1973 {
1974 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1975 .name = "Master Playback Switch",
1976 .info = snd_hda_mixer_amp_switch_info,
1977 .get = snd_hda_mixer_amp_switch_get,
1978 .put = vaio_master_sw_put,
1979 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
1980 },
1981 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
1982 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
1983 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
1984 {
1985 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1986 .name = "Capture Source",
1987 .count = 1,
1988 .info = stac92xx_mux_enum_info,
1989 .get = stac92xx_mux_enum_get,
1990 .put = stac92xx_mux_enum_put,
1991 },
1992 {}
1993};
1994
Guillaume Munch6d859062006-08-22 17:15:47 +02001995static struct snd_kcontrol_new vaio_ar_mixer[] = {
1996 {
1997 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1998 .name = "Master Playback Volume",
1999 .info = snd_hda_mixer_amp_volume_info,
2000 .get = snd_hda_mixer_amp_volume_get,
2001 .put = vaio_master_vol_put,
2002 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2003 },
2004 {
2005 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2006 .name = "Master Playback Switch",
2007 .info = snd_hda_mixer_amp_switch_info,
2008 .get = snd_hda_mixer_amp_switch_get,
2009 .put = vaio_master_sw_put,
2010 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2011 },
2012 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
2013 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
2014 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
2015 /*HDA_CODEC_MUTE("Optical Out Switch", 0x10, 0, HDA_OUTPUT),
2016 HDA_CODEC_VOLUME("Optical Out Volume", 0x10, 0, HDA_OUTPUT),*/
2017 {
2018 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2019 .name = "Capture Source",
2020 .count = 1,
2021 .info = stac92xx_mux_enum_info,
2022 .get = stac92xx_mux_enum_get,
2023 .put = stac92xx_mux_enum_put,
2024 },
2025 {}
2026};
2027
2028static struct hda_codec_ops stac9872_patch_ops = {
Takashi Iwaidb064e52006-03-16 16:04:58 +01002029 .build_controls = stac92xx_build_controls,
2030 .build_pcms = stac92xx_build_pcms,
2031 .init = stac92xx_init,
2032 .free = stac92xx_free,
2033#ifdef CONFIG_PM
2034 .resume = stac92xx_resume,
2035#endif
2036};
2037
Guillaume Munch6d859062006-08-22 17:15:47 +02002038enum { /* FE and SZ series. id=0x83847661 and subsys=0x104D0700 or 104D1000. */
2039 CXD9872RD_VAIO,
2040 /* Unknown. id=0x83847662 and subsys=0x104D1200 or 104D1000. */
2041 STAC9872AK_VAIO,
2042 /* Unknown. id=0x83847661 and subsys=0x104D1200. */
2043 STAC9872K_VAIO,
2044 /* AR Series. id=0x83847664 and subsys=104D1300 */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002045 CXD9872AKD_VAIO,
2046 STAC_9872_MODELS,
2047};
Takashi Iwaidb064e52006-03-16 16:04:58 +01002048
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002049static const char *stac9872_models[STAC_9872_MODELS] = {
2050 [CXD9872RD_VAIO] = "vaio",
2051 [CXD9872AKD_VAIO] = "vaio-ar",
2052};
2053
2054static struct snd_pci_quirk stac9872_cfg_tbl[] = {
2055 SND_PCI_QUIRK(0x104d, 0x81e6, "Sony VAIO F/S", CXD9872RD_VAIO),
2056 SND_PCI_QUIRK(0x104d, 0x81ef, "Sony VAIO F/S", CXD9872RD_VAIO),
2057 SND_PCI_QUIRK(0x104d, 0x81fd, "Sony VAIO AR", CXD9872AKD_VAIO),
Takashi Iwaidb064e52006-03-16 16:04:58 +01002058 {}
2059};
2060
Guillaume Munch6d859062006-08-22 17:15:47 +02002061static int patch_stac9872(struct hda_codec *codec)
Takashi Iwaidb064e52006-03-16 16:04:58 +01002062{
2063 struct sigmatel_spec *spec;
2064 int board_config;
2065
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002066 board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
2067 stac9872_models,
2068 stac9872_cfg_tbl);
Takashi Iwaidb064e52006-03-16 16:04:58 +01002069 if (board_config < 0)
2070 /* unknown config, let generic-parser do its job... */
2071 return snd_hda_parse_generic_codec(codec);
2072
2073 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2074 if (spec == NULL)
2075 return -ENOMEM;
2076
2077 codec->spec = spec;
2078 switch (board_config) {
Guillaume Munch6d859062006-08-22 17:15:47 +02002079 case CXD9872RD_VAIO:
2080 case STAC9872AK_VAIO:
2081 case STAC9872K_VAIO:
Takashi Iwaidb064e52006-03-16 16:04:58 +01002082 spec->mixer = vaio_mixer;
2083 spec->init = vaio_init;
2084 spec->multiout.max_channels = 2;
2085 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
2086 spec->multiout.dac_nids = vaio_dacs;
2087 spec->multiout.hp_nid = VAIO_HP_DAC;
2088 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
2089 spec->adc_nids = vaio_adcs;
2090 spec->input_mux = &vaio_mux;
2091 spec->mux_nids = vaio_mux_nids;
2092 break;
Guillaume Munch6d859062006-08-22 17:15:47 +02002093
2094 case CXD9872AKD_VAIO:
2095 spec->mixer = vaio_ar_mixer;
2096 spec->init = vaio_ar_init;
2097 spec->multiout.max_channels = 2;
2098 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
2099 spec->multiout.dac_nids = vaio_dacs;
2100 spec->multiout.hp_nid = VAIO_HP_DAC;
2101 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
2102 spec->adc_nids = vaio_adcs;
2103 spec->input_mux = &vaio_mux;
2104 spec->mux_nids = vaio_mux_nids;
2105 break;
Takashi Iwaidb064e52006-03-16 16:04:58 +01002106 }
2107
Guillaume Munch6d859062006-08-22 17:15:47 +02002108 codec->patch_ops = stac9872_patch_ops;
Takashi Iwaidb064e52006-03-16 16:04:58 +01002109 return 0;
2110}
2111
2112
2113/*
Matt2f2f4252005-04-13 14:45:30 +02002114 * patch entries
2115 */
2116struct hda_codec_preset snd_hda_preset_sigmatel[] = {
2117 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
2118 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
2119 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
2120 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
2121 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
2122 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
2123 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
Matt Porter22a27c72006-07-06 18:49:10 +02002124 { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
2125 { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
2126 { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
2127 { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
2128 { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
2129 { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
Matt Porter3cc08dc2006-01-23 15:27:49 +01002130 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
2131 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
2132 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
2133 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
2134 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
2135 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
2136 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
2137 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
2138 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
2139 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
Guillaume Munch6d859062006-08-22 17:15:47 +02002140 /* The following does not take into account .id=0x83847661 when subsys =
2141 * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
2142 * currently not fully supported.
2143 */
2144 { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
2145 { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
2146 { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
Matt Porterf3302a52006-07-31 12:49:34 +02002147 { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
2148 { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
2149 { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
2150 { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
2151 { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
2152 { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
2153 { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
2154 { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
Matt2f2f4252005-04-13 14:45:30 +02002155 {} /* terminator */
2156};