blob: abe9493f0a2cac97246c026f48c7636043d25f12 [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
39#define STAC_UNSOL_ENABLE (AC_USRSP_EN | STAC_HP_EVENT)
40
Matt Porter403d1942005-11-29 15:00:51 +010041#define STAC_REF 0
42#define STAC_D945GTP3 1
43#define STAC_D945GTP5 2
44
Matt2f2f4252005-04-13 14:45:30 +020045struct sigmatel_spec {
Takashi Iwaic8b6bf92005-11-17 14:57:47 +010046 struct snd_kcontrol_new *mixers[4];
Mattc7d4b2f2005-06-27 14:59:41 +020047 unsigned int num_mixers;
48
Matt Porter403d1942005-11-29 15:00:51 +010049 int board_config;
Mattc7d4b2f2005-06-27 14:59:41 +020050 unsigned int surr_switch: 1;
Matt Porter403d1942005-11-29 15:00:51 +010051 unsigned int line_switch: 1;
52 unsigned int mic_switch: 1;
Matt Porter3cc08dc2006-01-23 15:27:49 +010053 unsigned int alt_switch: 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +010054 unsigned int hp_detect: 1;
Mattc7d4b2f2005-06-27 14:59:41 +020055
Matt2f2f4252005-04-13 14:45:30 +020056 /* playback */
57 struct hda_multi_out multiout;
Matt Porter3cc08dc2006-01-23 15:27:49 +010058 hda_nid_t dac_nids[5];
Matt2f2f4252005-04-13 14:45:30 +020059
60 /* capture */
61 hda_nid_t *adc_nids;
Matt2f2f4252005-04-13 14:45:30 +020062 unsigned int num_adcs;
Mattdabbed62005-06-14 10:19:34 +020063 hda_nid_t *mux_nids;
64 unsigned int num_muxes;
Mattdabbed62005-06-14 10:19:34 +020065 hda_nid_t dig_in_nid;
Matt2f2f4252005-04-13 14:45:30 +020066
Matt2f2f4252005-04-13 14:45:30 +020067 /* pin widgets */
68 hda_nid_t *pin_nids;
69 unsigned int num_pins;
Matt2f2f4252005-04-13 14:45:30 +020070 unsigned int *pin_configs;
Matt2f2f4252005-04-13 14:45:30 +020071
72 /* codec specific stuff */
73 struct hda_verb *init;
Takashi Iwaic8b6bf92005-11-17 14:57:47 +010074 struct snd_kcontrol_new *mixer;
Matt2f2f4252005-04-13 14:45:30 +020075
76 /* capture source */
Mattc7d4b2f2005-06-27 14:59:41 +020077 struct hda_input_mux *input_mux;
Matt Porter3cc08dc2006-01-23 15:27:49 +010078 unsigned int cur_mux[3];
Matt2f2f4252005-04-13 14:45:30 +020079
Matt Porter403d1942005-11-29 15:00:51 +010080 /* i/o switches */
81 unsigned int io_switch[2];
Matt2f2f4252005-04-13 14:45:30 +020082
Mattc7d4b2f2005-06-27 14:59:41 +020083 struct hda_pcm pcm_rec[2]; /* PCM information */
84
85 /* dynamic controls and input_mux */
86 struct auto_pin_cfg autocfg;
87 unsigned int num_kctl_alloc, num_kctl_used;
Takashi Iwaic8b6bf92005-11-17 14:57:47 +010088 struct snd_kcontrol_new *kctl_alloc;
Mattc7d4b2f2005-06-27 14:59:41 +020089 struct hda_input_mux private_imux;
Matt2f2f4252005-04-13 14:45:30 +020090};
91
92static hda_nid_t stac9200_adc_nids[1] = {
93 0x03,
94};
95
96static hda_nid_t stac9200_mux_nids[1] = {
97 0x0c,
98};
99
100static hda_nid_t stac9200_dac_nids[1] = {
101 0x02,
102};
103
Matt2f2f4252005-04-13 14:45:30 +0200104static hda_nid_t stac922x_adc_nids[2] = {
105 0x06, 0x07,
106};
107
108static hda_nid_t stac922x_mux_nids[2] = {
109 0x12, 0x13,
110};
111
Matt Porter3cc08dc2006-01-23 15:27:49 +0100112static hda_nid_t stac927x_adc_nids[3] = {
113 0x07, 0x08, 0x09
114};
115
116static hda_nid_t stac927x_mux_nids[3] = {
117 0x15, 0x16, 0x17
118};
119
Mattc7d4b2f2005-06-27 14:59:41 +0200120static hda_nid_t stac9200_pin_nids[8] = {
121 0x08, 0x09, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12,
Matt2f2f4252005-04-13 14:45:30 +0200122};
123
124static hda_nid_t stac922x_pin_nids[10] = {
125 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
126 0x0f, 0x10, 0x11, 0x15, 0x1b,
127};
128
Matt Porter3cc08dc2006-01-23 15:27:49 +0100129static hda_nid_t stac927x_pin_nids[14] = {
130 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
131 0x0f, 0x10, 0x11, 0x12, 0x13,
132 0x14, 0x21, 0x22, 0x23,
133};
134
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100135static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Matt2f2f4252005-04-13 14:45:30 +0200136{
137 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
138 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +0200139 return snd_hda_input_mux_info(spec->input_mux, uinfo);
Matt2f2f4252005-04-13 14:45:30 +0200140}
141
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100142static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200143{
144 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
145 struct sigmatel_spec *spec = codec->spec;
146 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
147
148 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
149 return 0;
150}
151
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100152static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200153{
154 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
155 struct sigmatel_spec *spec = codec->spec;
156 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
157
Mattc7d4b2f2005-06-27 14:59:41 +0200158 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
Matt2f2f4252005-04-13 14:45:30 +0200159 spec->mux_nids[adc_idx], &spec->cur_mux[adc_idx]);
160}
161
Mattc7d4b2f2005-06-27 14:59:41 +0200162static struct hda_verb stac9200_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200163 /* set dac0mux for dac converter */
Mattc7d4b2f2005-06-27 14:59:41 +0200164 { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
Matt2f2f4252005-04-13 14:45:30 +0200165 {}
166};
167
Mattc7d4b2f2005-06-27 14:59:41 +0200168static struct hda_verb stac922x_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200169 /* set master volume and direct control */
Mattc7d4b2f2005-06-27 14:59:41 +0200170 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matt2f2f4252005-04-13 14:45:30 +0200171 {}
172};
173
Matt Porter3cc08dc2006-01-23 15:27:49 +0100174static struct hda_verb stac927x_core_init[] = {
175 /* set master volume and direct control */
176 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
177 {}
178};
179
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100180static struct snd_kcontrol_new stac9200_mixer[] = {
Matt2f2f4252005-04-13 14:45:30 +0200181 HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
182 HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
183 {
184 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
185 .name = "Input Source",
186 .count = 1,
187 .info = stac92xx_mux_enum_info,
188 .get = stac92xx_mux_enum_get,
189 .put = stac92xx_mux_enum_put,
190 },
191 HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
192 HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
Mattc7d4b2f2005-06-27 14:59:41 +0200193 HDA_CODEC_VOLUME("Capture Mux Volume", 0x0c, 0, HDA_OUTPUT),
Matt2f2f4252005-04-13 14:45:30 +0200194 { } /* end */
195};
196
Mattc7d4b2f2005-06-27 14:59:41 +0200197/* This needs to be generated dynamically based on sequence */
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100198static struct snd_kcontrol_new stac922x_mixer[] = {
Matt2f2f4252005-04-13 14:45:30 +0200199 {
200 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
201 .name = "Input Source",
202 .count = 1,
203 .info = stac92xx_mux_enum_info,
204 .get = stac92xx_mux_enum_get,
205 .put = stac92xx_mux_enum_put,
206 },
207 HDA_CODEC_VOLUME("Capture Volume", 0x17, 0x0, HDA_INPUT),
Takashi Iwai0fd17082006-01-13 18:46:21 +0100208 HDA_CODEC_MUTE("Capture Switch", 0x17, 0x0, HDA_INPUT),
Matt2f2f4252005-04-13 14:45:30 +0200209 HDA_CODEC_VOLUME("Mux Capture Volume", 0x12, 0x0, HDA_OUTPUT),
210 { } /* end */
211};
212
Matt Porter3cc08dc2006-01-23 15:27:49 +0100213static snd_kcontrol_new_t stac927x_mixer[] = {
214 {
215 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
216 .name = "Input Source",
217 .count = 1,
218 .info = stac92xx_mux_enum_info,
219 .get = stac92xx_mux_enum_get,
220 .put = stac92xx_mux_enum_put,
221 },
222 HDA_CODEC_VOLUME("InMux Capture Volume", 0x15, 0x0, HDA_OUTPUT),
223 HDA_CODEC_VOLUME("InVol Capture Volume", 0x18, 0x0, HDA_INPUT),
224 HDA_CODEC_MUTE("ADCMux Capture Switch", 0x1b, 0x0, HDA_OUTPUT),
225 { } /* end */
226};
227
Matt2f2f4252005-04-13 14:45:30 +0200228static int stac92xx_build_controls(struct hda_codec *codec)
229{
230 struct sigmatel_spec *spec = codec->spec;
231 int err;
Mattc7d4b2f2005-06-27 14:59:41 +0200232 int i;
Matt2f2f4252005-04-13 14:45:30 +0200233
234 err = snd_hda_add_new_ctls(codec, spec->mixer);
235 if (err < 0)
236 return err;
Mattc7d4b2f2005-06-27 14:59:41 +0200237
238 for (i = 0; i < spec->num_mixers; i++) {
239 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
240 if (err < 0)
241 return err;
242 }
243
Mattdabbed62005-06-14 10:19:34 +0200244 if (spec->multiout.dig_out_nid) {
245 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
246 if (err < 0)
247 return err;
248 }
249 if (spec->dig_in_nid) {
250 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
251 if (err < 0)
252 return err;
253 }
254 return 0;
Matt2f2f4252005-04-13 14:45:30 +0200255}
256
Matt Porter403d1942005-11-29 15:00:51 +0100257static unsigned int ref9200_pin_configs[8] = {
Mattdabbed62005-06-14 10:19:34 +0200258 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
Matt2f2f4252005-04-13 14:45:30 +0200259 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
260};
261
Matt Porter403d1942005-11-29 15:00:51 +0100262static unsigned int *stac9200_brd_tbl[] = {
263 ref9200_pin_configs,
264};
265
266static struct hda_board_config stac9200_cfg_tbl[] = {
267 { .modelname = "ref",
268 .pci_subvendor = PCI_VENDOR_ID_INTEL,
269 .pci_subdevice = 0x2668, /* DFI LanParty */
270 .config = STAC_REF },
271 {} /* terminator */
272};
273
274static unsigned int ref922x_pin_configs[10] = {
275 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
276 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
Matt2f2f4252005-04-13 14:45:30 +0200277 0x40000100, 0x40000100,
278};
279
Matt Porter403d1942005-11-29 15:00:51 +0100280static unsigned int d945gtp3_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +0100281 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
Matt Porter403d1942005-11-29 15:00:51 +0100282 0x40000100, 0x40000100, 0x40000100, 0x40000100,
283 0x02a19120, 0x40000100,
284};
285
286static unsigned int d945gtp5_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +0100287 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
288 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
Matt Porter403d1942005-11-29 15:00:51 +0100289 0x02a19320, 0x40000100,
290};
291
292static unsigned int *stac922x_brd_tbl[] = {
293 ref922x_pin_configs,
294 d945gtp3_pin_configs,
295 d945gtp5_pin_configs,
296};
297
298static struct hda_board_config stac922x_cfg_tbl[] = {
299 { .modelname = "ref",
300 .pci_subvendor = PCI_VENDOR_ID_INTEL,
301 .pci_subdevice = 0x2668, /* DFI LanParty */
302 .config = STAC_REF }, /* SigmaTel reference board */
303 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
304 .pci_subdevice = 0x0101,
305 .config = STAC_D945GTP3 }, /* Intel D945GTP - 3 Stack */
306 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
Takashi Iwai353b9e62006-02-16 18:16:17 +0100307 .pci_subdevice = 0x0202,
308 .config = STAC_D945GTP3 }, /* Intel D945GNT - 3 Stack, 9221 A1 */
309 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
310 .pci_subdevice = 0x0b0b,
311 .config = STAC_D945GTP3 }, /* Intel D945PSN - 3 Stack, 9221 A1 */
312 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
Matt Porter403d1942005-11-29 15:00:51 +0100313 .pci_subdevice = 0x0404,
314 .config = STAC_D945GTP5 }, /* Intel D945GTP - 5 Stack */
315 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
316 .pci_subdevice = 0x0303,
317 .config = STAC_D945GTP5 }, /* Intel D945GNT - 5 Stack */
318 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
319 .pci_subdevice = 0x0013,
320 .config = STAC_D945GTP5 }, /* Intel D955XBK - 5 Stack */
Matt Porterd62c40e2006-01-23 15:26:27 +0100321 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
322 .pci_subdevice = 0x0417,
323 .config = STAC_D945GTP5 }, /* Intel D975XBK - 5 Stack */
Matt Porter403d1942005-11-29 15:00:51 +0100324 {} /* terminator */
325};
326
Matt Porter3cc08dc2006-01-23 15:27:49 +0100327static unsigned int ref927x_pin_configs[14] = {
328 0x01813122, 0x01a19021, 0x01014010, 0x01016011,
329 0x01012012, 0x01011014, 0x40000100, 0x40000100,
330 0x40000100, 0x40000100, 0x40000100, 0x01441030,
331 0x01c41030, 0x40000100,
332};
333
334static unsigned int *stac927x_brd_tbl[] = {
335 ref927x_pin_configs,
336};
337
338static struct hda_board_config stac927x_cfg_tbl[] = {
339 { .modelname = "ref",
340 .pci_subvendor = PCI_VENDOR_ID_INTEL,
341 .pci_subdevice = 0x2668, /* DFI LanParty */
342 .config = STAC_REF }, /* SigmaTel reference board */
343 {} /* terminator */
344};
345
Matt2f2f4252005-04-13 14:45:30 +0200346static void stac92xx_set_config_regs(struct hda_codec *codec)
347{
348 int i;
349 struct sigmatel_spec *spec = codec->spec;
350 unsigned int pin_cfg;
351
352 for (i=0; i < spec->num_pins; i++) {
353 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
354 AC_VERB_SET_CONFIG_DEFAULT_BYTES_0,
355 spec->pin_configs[i] & 0x000000ff);
356 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
357 AC_VERB_SET_CONFIG_DEFAULT_BYTES_1,
358 (spec->pin_configs[i] & 0x0000ff00) >> 8);
359 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
360 AC_VERB_SET_CONFIG_DEFAULT_BYTES_2,
361 (spec->pin_configs[i] & 0x00ff0000) >> 16);
362 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
363 AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
364 spec->pin_configs[i] >> 24);
365 pin_cfg = snd_hda_codec_read(codec, spec->pin_nids[i], 0,
366 AC_VERB_GET_CONFIG_DEFAULT,
367 0x00);
Matt Porter403d1942005-11-29 15:00:51 +0100368 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 +0200369 }
370}
Matt2f2f4252005-04-13 14:45:30 +0200371
Matt2f2f4252005-04-13 14:45:30 +0200372/*
373 * Analog playback callbacks
374 */
375static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
376 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100377 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200378{
379 struct sigmatel_spec *spec = codec->spec;
380 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
381}
382
383static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
384 struct hda_codec *codec,
385 unsigned int stream_tag,
386 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100387 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200388{
389 struct sigmatel_spec *spec = codec->spec;
Matt Porter403d1942005-11-29 15:00:51 +0100390 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
Matt2f2f4252005-04-13 14:45:30 +0200391}
392
393static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
394 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100395 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200396{
397 struct sigmatel_spec *spec = codec->spec;
398 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
399}
400
401/*
Mattdabbed62005-06-14 10:19:34 +0200402 * Digital playback callbacks
403 */
404static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
405 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100406 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +0200407{
408 struct sigmatel_spec *spec = codec->spec;
409 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
410}
411
412static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
413 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100414 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +0200415{
416 struct sigmatel_spec *spec = codec->spec;
417 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
418}
419
420
421/*
Matt2f2f4252005-04-13 14:45:30 +0200422 * Analog capture callbacks
423 */
424static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
425 struct hda_codec *codec,
426 unsigned int stream_tag,
427 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100428 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200429{
430 struct sigmatel_spec *spec = codec->spec;
431
432 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
433 stream_tag, 0, format);
434 return 0;
435}
436
437static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
438 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100439 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200440{
441 struct sigmatel_spec *spec = codec->spec;
442
443 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 0, 0, 0);
444 return 0;
445}
446
Mattdabbed62005-06-14 10:19:34 +0200447static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
448 .substreams = 1,
449 .channels_min = 2,
450 .channels_max = 2,
451 /* NID is set in stac92xx_build_pcms */
452 .ops = {
453 .open = stac92xx_dig_playback_pcm_open,
454 .close = stac92xx_dig_playback_pcm_close
455 },
456};
457
458static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
459 .substreams = 1,
460 .channels_min = 2,
461 .channels_max = 2,
462 /* NID is set in stac92xx_build_pcms */
463};
464
Matt2f2f4252005-04-13 14:45:30 +0200465static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
466 .substreams = 1,
467 .channels_min = 2,
Mattc7d4b2f2005-06-27 14:59:41 +0200468 .channels_max = 8,
Matt2f2f4252005-04-13 14:45:30 +0200469 .nid = 0x02, /* NID to query formats and rates */
470 .ops = {
471 .open = stac92xx_playback_pcm_open,
472 .prepare = stac92xx_playback_pcm_prepare,
473 .cleanup = stac92xx_playback_pcm_cleanup
474 },
475};
476
Matt Porter3cc08dc2006-01-23 15:27:49 +0100477static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
478 .substreams = 1,
479 .channels_min = 2,
480 .channels_max = 2,
481 .nid = 0x06, /* NID to query formats and rates */
482 .ops = {
483 .open = stac92xx_playback_pcm_open,
484 .prepare = stac92xx_playback_pcm_prepare,
485 .cleanup = stac92xx_playback_pcm_cleanup
486 },
487};
488
Matt2f2f4252005-04-13 14:45:30 +0200489static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
490 .substreams = 2,
491 .channels_min = 2,
492 .channels_max = 2,
Matt Porter3cc08dc2006-01-23 15:27:49 +0100493 /* NID is set in stac92xx_build_pcms */
Matt2f2f4252005-04-13 14:45:30 +0200494 .ops = {
495 .prepare = stac92xx_capture_pcm_prepare,
496 .cleanup = stac92xx_capture_pcm_cleanup
497 },
498};
499
500static int stac92xx_build_pcms(struct hda_codec *codec)
501{
502 struct sigmatel_spec *spec = codec->spec;
503 struct hda_pcm *info = spec->pcm_rec;
504
505 codec->num_pcms = 1;
506 codec->pcm_info = info;
507
Mattc7d4b2f2005-06-27 14:59:41 +0200508 info->name = "STAC92xx Analog";
Matt2f2f4252005-04-13 14:45:30 +0200509 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
Matt2f2f4252005-04-13 14:45:30 +0200510 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100511 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
512
513 if (spec->alt_switch) {
514 codec->num_pcms++;
515 info++;
516 info->name = "STAC92xx Analog Alt";
517 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
518 }
Matt2f2f4252005-04-13 14:45:30 +0200519
Mattdabbed62005-06-14 10:19:34 +0200520 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
521 codec->num_pcms++;
522 info++;
523 info->name = "STAC92xx Digital";
524 if (spec->multiout.dig_out_nid) {
525 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
526 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
527 }
528 if (spec->dig_in_nid) {
529 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
530 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
531 }
532 }
533
Matt2f2f4252005-04-13 14:45:30 +0200534 return 0;
535}
536
Takashi Iwaic960a032006-03-23 17:06:28 +0100537static unsigned int stac92xx_get_vref(struct hda_codec *codec, hda_nid_t nid)
538{
539 unsigned int pincap = snd_hda_param_read(codec, nid,
540 AC_PAR_PIN_CAP);
541 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
542 if (pincap & AC_PINCAP_VREF_100)
543 return AC_PINCTL_VREF_100;
544 if (pincap & AC_PINCAP_VREF_80)
545 return AC_PINCTL_VREF_80;
546 if (pincap & AC_PINCAP_VREF_50)
547 return AC_PINCTL_VREF_50;
548 if (pincap & AC_PINCAP_VREF_GRD)
549 return AC_PINCTL_VREF_GRD;
550 return 0;
551}
552
Matt Porter403d1942005-11-29 15:00:51 +0100553static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
554
555{
556 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
557}
558
559static int stac92xx_io_switch_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
560{
561 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
562 uinfo->count = 1;
563 uinfo->value.integer.min = 0;
564 uinfo->value.integer.max = 1;
565 return 0;
566}
567
568static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
569{
570 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
571 struct sigmatel_spec *spec = codec->spec;
572 int io_idx = kcontrol-> private_value & 0xff;
573
574 ucontrol->value.integer.value[0] = spec->io_switch[io_idx];
575 return 0;
576}
577
578static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
579{
580 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
581 struct sigmatel_spec *spec = codec->spec;
582 hda_nid_t nid = kcontrol->private_value >> 8;
583 int io_idx = kcontrol-> private_value & 0xff;
584 unsigned short val = ucontrol->value.integer.value[0];
585
586 spec->io_switch[io_idx] = val;
587
588 if (val)
589 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
Takashi Iwaic960a032006-03-23 17:06:28 +0100590 else {
591 unsigned int pinctl = AC_PINCTL_IN_EN;
592 if (io_idx) /* set VREF for mic */
593 pinctl |= stac92xx_get_vref(codec, nid);
594 stac92xx_auto_set_pinctl(codec, nid, pinctl);
595 }
Matt Porter403d1942005-11-29 15:00:51 +0100596 return 1;
597}
598
599#define STAC_CODEC_IO_SWITCH(xname, xpval) \
600 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
601 .name = xname, \
602 .index = 0, \
603 .info = stac92xx_io_switch_info, \
604 .get = stac92xx_io_switch_get, \
605 .put = stac92xx_io_switch_put, \
606 .private_value = xpval, \
607 }
608
609
Mattc7d4b2f2005-06-27 14:59:41 +0200610enum {
611 STAC_CTL_WIDGET_VOL,
612 STAC_CTL_WIDGET_MUTE,
Matt Porter403d1942005-11-29 15:00:51 +0100613 STAC_CTL_WIDGET_IO_SWITCH,
Mattc7d4b2f2005-06-27 14:59:41 +0200614};
615
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100616static struct snd_kcontrol_new stac92xx_control_templates[] = {
Mattc7d4b2f2005-06-27 14:59:41 +0200617 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
618 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Matt Porter403d1942005-11-29 15:00:51 +0100619 STAC_CODEC_IO_SWITCH(NULL, 0),
Mattc7d4b2f2005-06-27 14:59:41 +0200620};
621
622/* add dynamic controls */
623static int stac92xx_add_control(struct sigmatel_spec *spec, int type, const char *name, unsigned long val)
624{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100625 struct snd_kcontrol_new *knew;
Mattc7d4b2f2005-06-27 14:59:41 +0200626
627 if (spec->num_kctl_used >= spec->num_kctl_alloc) {
628 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
629
630 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */
631 if (! knew)
632 return -ENOMEM;
633 if (spec->kctl_alloc) {
634 memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
635 kfree(spec->kctl_alloc);
636 }
637 spec->kctl_alloc = knew;
638 spec->num_kctl_alloc = num;
639 }
640
641 knew = &spec->kctl_alloc[spec->num_kctl_used];
642 *knew = stac92xx_control_templates[type];
Takashi Iwai82fe0c52005-06-30 10:54:33 +0200643 knew->name = kstrdup(name, GFP_KERNEL);
Mattc7d4b2f2005-06-27 14:59:41 +0200644 if (! knew->name)
645 return -ENOMEM;
646 knew->private_value = val;
647 spec->num_kctl_used++;
648 return 0;
649}
650
Matt Porter403d1942005-11-29 15:00:51 +0100651/* flag inputs as additional dynamic lineouts */
652static int stac92xx_add_dyn_out_pins(struct hda_codec *codec, struct auto_pin_cfg *cfg)
653{
654 struct sigmatel_spec *spec = codec->spec;
655
656 switch (cfg->line_outs) {
657 case 3:
658 /* add line-in as side */
659 if (cfg->input_pins[AUTO_PIN_LINE]) {
660 cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_LINE];
661 spec->line_switch = 1;
662 cfg->line_outs++;
663 }
664 break;
665 case 2:
666 /* add line-in as clfe and mic as side */
667 if (cfg->input_pins[AUTO_PIN_LINE]) {
668 cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_LINE];
669 spec->line_switch = 1;
670 cfg->line_outs++;
671 }
672 if (cfg->input_pins[AUTO_PIN_MIC]) {
673 cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_MIC];
674 spec->mic_switch = 1;
675 cfg->line_outs++;
676 }
677 break;
678 case 1:
679 /* add line-in as surr and mic as clfe */
680 if (cfg->input_pins[AUTO_PIN_LINE]) {
681 cfg->line_out_pins[1] = cfg->input_pins[AUTO_PIN_LINE];
682 spec->line_switch = 1;
683 cfg->line_outs++;
684 }
685 if (cfg->input_pins[AUTO_PIN_MIC]) {
686 cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_MIC];
687 spec->mic_switch = 1;
688 cfg->line_outs++;
689 }
690 break;
691 }
692
693 return 0;
694}
695
Matt Porter3cc08dc2006-01-23 15:27:49 +0100696/*
697 * XXX The line_out pin widget connection list may not be set to the
698 * desired DAC nid. This is the case on 927x where ports A and B can
699 * be routed to several DACs.
700 *
701 * This requires an analysis of the line-out/hp pin configuration
702 * to provide a best fit for pin/DAC configurations that are routable.
703 * For now, 927x DAC4 is not supported and 927x DAC1 output to ports
704 * A and B is not supported.
705 */
Mattc7d4b2f2005-06-27 14:59:41 +0200706/* fill in the dac_nids table from the parsed pin configuration */
707static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
708{
709 struct sigmatel_spec *spec = codec->spec;
710 hda_nid_t nid;
711 int i;
712
713 /* check the pins hardwired to audio widget */
714 for (i = 0; i < cfg->line_outs; i++) {
715 nid = cfg->line_out_pins[i];
716 spec->multiout.dac_nids[i] = snd_hda_codec_read(codec, nid, 0,
717 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
718 }
719
Takashi Iwai82bc9552006-03-21 11:24:42 +0100720 spec->multiout.num_dacs = cfg->line_outs;
Mattc7d4b2f2005-06-27 14:59:41 +0200721
722 return 0;
723}
724
725/* add playback controls from the parsed DAC table */
726static int stac92xx_auto_create_multi_out_ctls(struct sigmatel_spec *spec, const struct auto_pin_cfg *cfg)
727{
728 char name[32];
729 static const char *chname[4] = { "Front", "Surround", NULL /*CLFE*/, "Side" };
730 hda_nid_t nid;
731 int i, err;
732
733 for (i = 0; i < cfg->line_outs; i++) {
Matt Porter403d1942005-11-29 15:00:51 +0100734 if (!spec->multiout.dac_nids[i])
Mattc7d4b2f2005-06-27 14:59:41 +0200735 continue;
736
737 nid = spec->multiout.dac_nids[i];
738
739 if (i == 2) {
740 /* Center/LFE */
741 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, "Center Playback Volume",
742 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT))) < 0)
743 return err;
744 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, "LFE Playback Volume",
745 HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT))) < 0)
746 return err;
747 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, "Center Playback Switch",
748 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT))) < 0)
749 return err;
750 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, "LFE Playback Switch",
751 HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT))) < 0)
752 return err;
753 } else {
754 sprintf(name, "%s Playback Volume", chname[i]);
755 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, name,
756 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
757 return err;
758 sprintf(name, "%s Playback Switch", chname[i]);
759 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, name,
760 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
761 return err;
762 }
763 }
764
Matt Porter403d1942005-11-29 15:00:51 +0100765 if (spec->line_switch)
766 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Line In as Output Switch", cfg->input_pins[AUTO_PIN_LINE] << 8)) < 0)
767 return err;
768
769 if (spec->mic_switch)
770 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Mic as Output Switch", (cfg->input_pins[AUTO_PIN_MIC] << 8) | 1)) < 0)
771 return err;
772
Mattc7d4b2f2005-06-27 14:59:41 +0200773 return 0;
774}
775
776/* add playback controls for HP output */
777static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec, struct auto_pin_cfg *cfg)
778{
779 struct sigmatel_spec *spec = codec->spec;
780 hda_nid_t pin = cfg->hp_pin;
781 hda_nid_t nid;
782 int i, err;
Matt4e550962005-07-04 17:51:39 +0200783 unsigned int wid_caps;
Mattc7d4b2f2005-06-27 14:59:41 +0200784
785 if (! pin)
786 return 0;
787
Takashi Iwai54d17402005-11-21 16:33:22 +0100788 wid_caps = get_wcaps(codec, pin);
Takashi Iwai505cb342006-03-27 12:51:52 +0200789 if (wid_caps & AC_WCAP_UNSOL_CAP)
Takashi Iwai82bc9552006-03-21 11:24:42 +0100790 spec->hp_detect = 1;
Matt4e550962005-07-04 17:51:39 +0200791
Mattc7d4b2f2005-06-27 14:59:41 +0200792 nid = snd_hda_codec_read(codec, pin, 0, AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
793 for (i = 0; i < cfg->line_outs; i++) {
794 if (! spec->multiout.dac_nids[i])
795 continue;
796 if (spec->multiout.dac_nids[i] == nid)
797 return 0;
798 }
799
800 spec->multiout.hp_nid = nid;
801
802 /* control HP volume/switch on the output mixer amp */
803 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, "Headphone Playback Volume",
804 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
805 return err;
806 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, "Headphone Playback Switch",
807 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
808 return err;
809
810 return 0;
811}
812
813/* create playback/capture controls for input pins */
814static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
815{
816 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +0200817 struct hda_input_mux *imux = &spec->private_imux;
818 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
819 int i, j, k;
820
821 for (i = 0; i < AUTO_PIN_LAST; i++) {
822 int index = -1;
823 if (cfg->input_pins[i]) {
Takashi Iwai4a471b72005-12-07 13:56:29 +0100824 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
Mattc7d4b2f2005-06-27 14:59:41 +0200825
826 for (j=0; j<spec->num_muxes; j++) {
827 int num_cons = snd_hda_get_connections(codec, spec->mux_nids[j], con_lst, HDA_MAX_NUM_INPUTS);
828 for (k=0; k<num_cons; k++)
829 if (con_lst[k] == cfg->input_pins[i]) {
830 index = k;
831 break;
832 }
833 if (index >= 0)
834 break;
835 }
836 imux->items[imux->num_items].index = index;
837 imux->num_items++;
838 }
839 }
840
841 return 0;
842}
843
Mattc7d4b2f2005-06-27 14:59:41 +0200844static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
845{
846 struct sigmatel_spec *spec = codec->spec;
847 int i;
848
849 for (i = 0; i < spec->autocfg.line_outs; i++) {
850 hda_nid_t nid = spec->autocfg.line_out_pins[i];
851 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
852 }
853}
854
855static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
856{
857 struct sigmatel_spec *spec = codec->spec;
858 hda_nid_t pin;
859
860 pin = spec->autocfg.hp_pin;
861 if (pin) /* connect to front */
862 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
863}
864
Matt Porter3cc08dc2006-01-23 15:27:49 +0100865static 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 +0200866{
867 struct sigmatel_spec *spec = codec->spec;
868 int err;
869
Kailang Yangdf694da2005-12-05 19:42:22 +0100870 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +0200871 return err;
Takashi Iwai82bc9552006-03-21 11:24:42 +0100872 if (! spec->autocfg.line_outs)
Matt Porter869264c2006-01-25 19:20:50 +0100873 return 0; /* can't find valid pin config */
Matt Porter403d1942005-11-29 15:00:51 +0100874 if ((err = stac92xx_add_dyn_out_pins(codec, &spec->autocfg)) < 0)
875 return err;
Mattc7d4b2f2005-06-27 14:59:41 +0200876 if ((err = stac92xx_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
877 return err;
Mattc7d4b2f2005-06-27 14:59:41 +0200878
879 if ((err = stac92xx_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
880 (err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg)) < 0 ||
881 (err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
882 return err;
883
884 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Matt Porter403d1942005-11-29 15:00:51 +0100885 if (spec->multiout.max_channels > 2)
Mattc7d4b2f2005-06-27 14:59:41 +0200886 spec->surr_switch = 1;
Mattc7d4b2f2005-06-27 14:59:41 +0200887
Takashi Iwai82bc9552006-03-21 11:24:42 +0100888 if (spec->autocfg.dig_out_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +0100889 spec->multiout.dig_out_nid = dig_out;
Takashi Iwai82bc9552006-03-21 11:24:42 +0100890 if (spec->autocfg.dig_in_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +0100891 spec->dig_in_nid = dig_in;
Mattc7d4b2f2005-06-27 14:59:41 +0200892
893 if (spec->kctl_alloc)
894 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
895
896 spec->input_mux = &spec->private_imux;
897
898 return 1;
899}
900
Takashi Iwai82bc9552006-03-21 11:24:42 +0100901/* add playback controls for HP output */
902static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
903 struct auto_pin_cfg *cfg)
904{
905 struct sigmatel_spec *spec = codec->spec;
906 hda_nid_t pin = cfg->hp_pin;
907 unsigned int wid_caps;
908
909 if (! pin)
910 return 0;
911
912 wid_caps = get_wcaps(codec, pin);
Takashi Iwai505cb342006-03-27 12:51:52 +0200913 if (wid_caps & AC_WCAP_UNSOL_CAP)
Takashi Iwai82bc9552006-03-21 11:24:42 +0100914 spec->hp_detect = 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +0100915
916 return 0;
917}
918
Mattc7d4b2f2005-06-27 14:59:41 +0200919static int stac9200_parse_auto_config(struct hda_codec *codec)
920{
921 struct sigmatel_spec *spec = codec->spec;
922 int err;
923
Kailang Yangdf694da2005-12-05 19:42:22 +0100924 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +0200925 return err;
926
927 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
928 return err;
929
Takashi Iwai82bc9552006-03-21 11:24:42 +0100930 if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
931 return err;
932
933 if (spec->autocfg.dig_out_pin)
Mattc7d4b2f2005-06-27 14:59:41 +0200934 spec->multiout.dig_out_nid = 0x05;
Takashi Iwai82bc9552006-03-21 11:24:42 +0100935 if (spec->autocfg.dig_in_pin)
Mattc7d4b2f2005-06-27 14:59:41 +0200936 spec->dig_in_nid = 0x04;
Mattc7d4b2f2005-06-27 14:59:41 +0200937
938 if (spec->kctl_alloc)
939 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
940
941 spec->input_mux = &spec->private_imux;
942
943 return 1;
944}
945
Mattc7d4b2f2005-06-27 14:59:41 +0200946static int stac92xx_init(struct hda_codec *codec)
947{
948 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai82bc9552006-03-21 11:24:42 +0100949 struct auto_pin_cfg *cfg = &spec->autocfg;
950 int i;
Mattc7d4b2f2005-06-27 14:59:41 +0200951
Mattc7d4b2f2005-06-27 14:59:41 +0200952 snd_hda_sequence_write(codec, spec->init);
953
Takashi Iwai82bc9552006-03-21 11:24:42 +0100954 /* set up pins */
955 if (spec->hp_detect) {
Takashi Iwai505cb342006-03-27 12:51:52 +0200956 /* Enable unsolicited responses on the HP widget */
957 snd_hda_codec_write(codec, cfg->hp_pin, 0,
958 AC_VERB_SET_UNSOLICITED_ENABLE,
959 STAC_UNSOL_ENABLE);
Takashi Iwai82bc9552006-03-21 11:24:42 +0100960 /* fake event to set up pins */
961 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
962 } else {
963 stac92xx_auto_init_multi_out(codec);
964 stac92xx_auto_init_hp_out(codec);
965 }
966 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwaic960a032006-03-23 17:06:28 +0100967 hda_nid_t nid = cfg->input_pins[i];
968 if (nid) {
969 unsigned int pinctl = AC_PINCTL_IN_EN;
970 if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC)
971 pinctl |= stac92xx_get_vref(codec, nid);
972 stac92xx_auto_set_pinctl(codec, nid, pinctl);
973 }
Takashi Iwai82bc9552006-03-21 11:24:42 +0100974 }
975 if (cfg->dig_out_pin)
976 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pin,
977 AC_PINCTL_OUT_EN);
978 if (cfg->dig_in_pin)
979 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
980 AC_PINCTL_IN_EN);
981
Mattc7d4b2f2005-06-27 14:59:41 +0200982 return 0;
983}
984
Matt2f2f4252005-04-13 14:45:30 +0200985static void stac92xx_free(struct hda_codec *codec)
986{
Mattc7d4b2f2005-06-27 14:59:41 +0200987 struct sigmatel_spec *spec = codec->spec;
988 int i;
989
990 if (! spec)
991 return;
992
993 if (spec->kctl_alloc) {
994 for (i = 0; i < spec->num_kctl_used; i++)
995 kfree(spec->kctl_alloc[i].name);
996 kfree(spec->kctl_alloc);
997 }
998
999 kfree(spec);
Matt2f2f4252005-04-13 14:45:30 +02001000}
1001
Matt4e550962005-07-04 17:51:39 +02001002static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
1003 unsigned int flag)
1004{
1005 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
1006 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
1007 snd_hda_codec_write(codec, nid, 0,
1008 AC_VERB_SET_PIN_WIDGET_CONTROL,
1009 pin_ctl | flag);
1010}
1011
1012static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
1013 unsigned int flag)
1014{
1015 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
1016 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
1017 snd_hda_codec_write(codec, nid, 0,
1018 AC_VERB_SET_PIN_WIDGET_CONTROL,
1019 pin_ctl & ~flag);
1020}
1021
1022static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
1023{
1024 struct sigmatel_spec *spec = codec->spec;
1025 struct auto_pin_cfg *cfg = &spec->autocfg;
1026 int i, presence;
1027
1028 if ((res >> 26) != STAC_HP_EVENT)
1029 return;
1030
1031 presence = snd_hda_codec_read(codec, cfg->hp_pin, 0,
1032 AC_VERB_GET_PIN_SENSE, 0x00) >> 31;
1033
1034 if (presence) {
1035 /* disable lineouts, enable hp */
1036 for (i = 0; i < cfg->line_outs; i++)
1037 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
1038 AC_PINCTL_OUT_EN);
1039 stac92xx_set_pinctl(codec, cfg->hp_pin, AC_PINCTL_OUT_EN);
1040 } else {
1041 /* enable lineouts, disable hp */
1042 for (i = 0; i < cfg->line_outs; i++)
1043 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
1044 AC_PINCTL_OUT_EN);
1045 stac92xx_reset_pinctl(codec, cfg->hp_pin, AC_PINCTL_OUT_EN);
1046 }
1047}
1048
Mattff6fdc32005-06-27 15:06:52 +02001049#ifdef CONFIG_PM
1050static int stac92xx_resume(struct hda_codec *codec)
1051{
1052 struct sigmatel_spec *spec = codec->spec;
1053 int i;
1054
1055 stac92xx_init(codec);
1056 for (i = 0; i < spec->num_mixers; i++)
1057 snd_hda_resume_ctls(codec, spec->mixers[i]);
1058 if (spec->multiout.dig_out_nid)
1059 snd_hda_resume_spdif_out(codec);
1060 if (spec->dig_in_nid)
1061 snd_hda_resume_spdif_in(codec);
1062
1063 return 0;
1064}
1065#endif
1066
Matt2f2f4252005-04-13 14:45:30 +02001067static struct hda_codec_ops stac92xx_patch_ops = {
1068 .build_controls = stac92xx_build_controls,
1069 .build_pcms = stac92xx_build_pcms,
1070 .init = stac92xx_init,
1071 .free = stac92xx_free,
Matt4e550962005-07-04 17:51:39 +02001072 .unsol_event = stac92xx_unsol_event,
Mattff6fdc32005-06-27 15:06:52 +02001073#ifdef CONFIG_PM
1074 .resume = stac92xx_resume,
1075#endif
Matt2f2f4252005-04-13 14:45:30 +02001076};
1077
1078static int patch_stac9200(struct hda_codec *codec)
1079{
1080 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02001081 int err;
Matt2f2f4252005-04-13 14:45:30 +02001082
Takashi Iwaie560d8d2005-09-09 14:21:46 +02001083 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02001084 if (spec == NULL)
1085 return -ENOMEM;
1086
1087 codec->spec = spec;
Matt Porter403d1942005-11-29 15:00:51 +01001088 spec->board_config = snd_hda_check_board_config(codec, stac9200_cfg_tbl);
1089 if (spec->board_config < 0)
1090 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9200, using BIOS defaults\n");
1091 else {
1092 spec->num_pins = 8;
1093 spec->pin_nids = stac9200_pin_nids;
1094 spec->pin_configs = stac9200_brd_tbl[spec->board_config];
1095 stac92xx_set_config_regs(codec);
1096 }
Matt2f2f4252005-04-13 14:45:30 +02001097
1098 spec->multiout.max_channels = 2;
1099 spec->multiout.num_dacs = 1;
1100 spec->multiout.dac_nids = stac9200_dac_nids;
1101 spec->adc_nids = stac9200_adc_nids;
1102 spec->mux_nids = stac9200_mux_nids;
Mattdabbed62005-06-14 10:19:34 +02001103 spec->num_muxes = 1;
Mattc7d4b2f2005-06-27 14:59:41 +02001104
1105 spec->init = stac9200_core_init;
Matt2f2f4252005-04-13 14:45:30 +02001106 spec->mixer = stac9200_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02001107
1108 err = stac9200_parse_auto_config(codec);
1109 if (err < 0) {
1110 stac92xx_free(codec);
1111 return err;
1112 }
Matt2f2f4252005-04-13 14:45:30 +02001113
1114 codec->patch_ops = stac92xx_patch_ops;
1115
1116 return 0;
1117}
1118
1119static int patch_stac922x(struct hda_codec *codec)
1120{
1121 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02001122 int err;
Matt2f2f4252005-04-13 14:45:30 +02001123
Takashi Iwaie560d8d2005-09-09 14:21:46 +02001124 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02001125 if (spec == NULL)
1126 return -ENOMEM;
1127
1128 codec->spec = spec;
Matt Porter403d1942005-11-29 15:00:51 +01001129 spec->board_config = snd_hda_check_board_config(codec, stac922x_cfg_tbl);
1130 if (spec->board_config < 0)
1131 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC922x, using BIOS defaults\n");
1132 else {
1133 spec->num_pins = 10;
1134 spec->pin_nids = stac922x_pin_nids;
1135 spec->pin_configs = stac922x_brd_tbl[spec->board_config];
1136 stac92xx_set_config_regs(codec);
1137 }
Matt2f2f4252005-04-13 14:45:30 +02001138
Matt2f2f4252005-04-13 14:45:30 +02001139 spec->adc_nids = stac922x_adc_nids;
1140 spec->mux_nids = stac922x_mux_nids;
Mattdabbed62005-06-14 10:19:34 +02001141 spec->num_muxes = 2;
Mattc7d4b2f2005-06-27 14:59:41 +02001142
1143 spec->init = stac922x_core_init;
Matt2f2f4252005-04-13 14:45:30 +02001144 spec->mixer = stac922x_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02001145
1146 spec->multiout.dac_nids = spec->dac_nids;
1147
Matt Porter3cc08dc2006-01-23 15:27:49 +01001148 err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
1149 if (err < 0) {
1150 stac92xx_free(codec);
1151 return err;
1152 }
1153
1154 codec->patch_ops = stac92xx_patch_ops;
1155
1156 return 0;
1157}
1158
1159static int patch_stac927x(struct hda_codec *codec)
1160{
1161 struct sigmatel_spec *spec;
1162 int err;
1163
1164 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1165 if (spec == NULL)
1166 return -ENOMEM;
1167
1168 codec->spec = spec;
1169 spec->board_config = snd_hda_check_board_config(codec, stac927x_cfg_tbl);
1170 if (spec->board_config < 0)
1171 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC927x, using BIOS defaults\n");
1172 else {
1173 spec->num_pins = 14;
1174 spec->pin_nids = stac927x_pin_nids;
1175 spec->pin_configs = stac927x_brd_tbl[spec->board_config];
1176 stac92xx_set_config_regs(codec);
1177 }
1178
1179 spec->adc_nids = stac927x_adc_nids;
1180 spec->mux_nids = stac927x_mux_nids;
1181 spec->num_muxes = 3;
1182
1183 spec->init = stac927x_core_init;
1184 spec->mixer = stac927x_mixer;
1185
1186 spec->multiout.dac_nids = spec->dac_nids;
1187
1188 err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
Mattc7d4b2f2005-06-27 14:59:41 +02001189 if (err < 0) {
1190 stac92xx_free(codec);
1191 return err;
1192 }
Matt2f2f4252005-04-13 14:45:30 +02001193
1194 codec->patch_ops = stac92xx_patch_ops;
1195
1196 return 0;
1197}
1198
1199/*
Takashi Iwaidb064e52006-03-16 16:04:58 +01001200 * STAC 7661(?) hack
1201 */
1202
1203/* static config for Sony VAIO FE550G */
1204static hda_nid_t vaio_dacs[] = { 0x2 };
1205#define VAIO_HP_DAC 0x5
1206static hda_nid_t vaio_adcs[] = { 0x8 /*,0x6*/ };
1207static hda_nid_t vaio_mux_nids[] = { 0x15 };
1208
1209static struct hda_input_mux vaio_mux = {
1210 .num_items = 2,
1211 .items = {
1212 /* { "HP", 0x0 },
1213 { "Unknown", 0x1 }, */
1214 { "Mic", 0x2 },
1215 { "PCM", 0x3 },
1216 }
1217};
1218
1219static struct hda_verb vaio_init[] = {
1220 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
1221 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
1222 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
1223 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
1224 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
1225 {0x15, AC_VERB_SET_CONNECT_SEL, 0x2}, /* mic-sel: 0a,0d,14,02 */
1226 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
1227 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
1228 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
1229 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
1230 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
1231 {}
1232};
1233
1234/* bind volumes of both NID 0x02 and 0x05 */
1235static int vaio_master_vol_put(struct snd_kcontrol *kcontrol,
1236 struct snd_ctl_elem_value *ucontrol)
1237{
1238 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1239 long *valp = ucontrol->value.integer.value;
1240 int change;
1241
1242 change = snd_hda_codec_amp_update(codec, 0x02, 0, HDA_OUTPUT, 0,
1243 0x7f, valp[0] & 0x7f);
1244 change |= snd_hda_codec_amp_update(codec, 0x02, 1, HDA_OUTPUT, 0,
1245 0x7f, valp[1] & 0x7f);
1246 snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
1247 0x7f, valp[0] & 0x7f);
1248 snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
1249 0x7f, valp[1] & 0x7f);
1250 return change;
1251}
1252
1253/* bind volumes of both NID 0x02 and 0x05 */
1254static int vaio_master_sw_put(struct snd_kcontrol *kcontrol,
1255 struct snd_ctl_elem_value *ucontrol)
1256{
1257 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1258 long *valp = ucontrol->value.integer.value;
1259 int change;
1260
1261 change = snd_hda_codec_amp_update(codec, 0x02, 0, HDA_OUTPUT, 0,
1262 0x80, valp[0] & 0x80);
1263 change |= snd_hda_codec_amp_update(codec, 0x02, 1, HDA_OUTPUT, 0,
1264 0x80, valp[1] & 0x80);
1265 snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
1266 0x80, valp[0] & 0x80);
1267 snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
1268 0x80, valp[1] & 0x80);
1269 return change;
1270}
1271
1272static struct snd_kcontrol_new vaio_mixer[] = {
1273 {
1274 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1275 .name = "Master Playback Volume",
1276 .info = snd_hda_mixer_amp_volume_info,
1277 .get = snd_hda_mixer_amp_volume_get,
1278 .put = vaio_master_vol_put,
1279 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
1280 },
1281 {
1282 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1283 .name = "Master Playback Switch",
1284 .info = snd_hda_mixer_amp_switch_info,
1285 .get = snd_hda_mixer_amp_switch_get,
1286 .put = vaio_master_sw_put,
1287 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
1288 },
1289 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
1290 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
1291 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
1292 {
1293 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1294 .name = "Capture Source",
1295 .count = 1,
1296 .info = stac92xx_mux_enum_info,
1297 .get = stac92xx_mux_enum_get,
1298 .put = stac92xx_mux_enum_put,
1299 },
1300 {}
1301};
1302
1303static struct hda_codec_ops stac7661_patch_ops = {
1304 .build_controls = stac92xx_build_controls,
1305 .build_pcms = stac92xx_build_pcms,
1306 .init = stac92xx_init,
1307 .free = stac92xx_free,
1308#ifdef CONFIG_PM
1309 .resume = stac92xx_resume,
1310#endif
1311};
1312
1313enum { STAC7661_VAIO };
1314
1315static struct hda_board_config stac7661_cfg_tbl[] = {
1316 { .modelname = "vaio", .config = STAC7661_VAIO },
1317 { .pci_subvendor = 0x104d, .pci_subdevice = 0x81e6,
1318 .config = STAC7661_VAIO },
1319 { .pci_subvendor = 0x104d, .pci_subdevice = 0x81ef,
1320 .config = STAC7661_VAIO },
1321 {}
1322};
1323
1324static int patch_stac7661(struct hda_codec *codec)
1325{
1326 struct sigmatel_spec *spec;
1327 int board_config;
1328
1329 board_config = snd_hda_check_board_config(codec, stac7661_cfg_tbl);
1330 if (board_config < 0)
1331 /* unknown config, let generic-parser do its job... */
1332 return snd_hda_parse_generic_codec(codec);
1333
1334 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1335 if (spec == NULL)
1336 return -ENOMEM;
1337
1338 codec->spec = spec;
1339 switch (board_config) {
1340 case STAC7661_VAIO:
1341 spec->mixer = vaio_mixer;
1342 spec->init = vaio_init;
1343 spec->multiout.max_channels = 2;
1344 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
1345 spec->multiout.dac_nids = vaio_dacs;
1346 spec->multiout.hp_nid = VAIO_HP_DAC;
1347 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
1348 spec->adc_nids = vaio_adcs;
1349 spec->input_mux = &vaio_mux;
1350 spec->mux_nids = vaio_mux_nids;
1351 break;
1352 }
1353
1354 codec->patch_ops = stac7661_patch_ops;
1355 return 0;
1356}
1357
1358
1359/*
Matt2f2f4252005-04-13 14:45:30 +02001360 * patch entries
1361 */
1362struct hda_codec_preset snd_hda_preset_sigmatel[] = {
1363 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
1364 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
1365 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
1366 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
1367 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
1368 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
1369 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
Matt Porter3cc08dc2006-01-23 15:27:49 +01001370 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
1371 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
1372 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
1373 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
1374 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
1375 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
1376 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
1377 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
1378 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
1379 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
Takashi Iwaidb064e52006-03-16 16:04:58 +01001380 { .id = 0x83847661, .name = "STAC7661", .patch = patch_stac7661 },
Matt2f2f4252005-04-13 14:45:30 +02001381 {} /* terminator */
1382};