blob: 45ddf548d6fb40cedb97df64c1ed14ddf49c3a23 [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 Iwaic8b6bf9b2005-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;
Mattc7d4b2f2005-06-27 14:59:41 +020054
Matt2f2f4252005-04-13 14:45:30 +020055 /* playback */
56 struct hda_multi_out multiout;
Matt Porter3cc08dc2006-01-23 15:27:49 +010057 hda_nid_t dac_nids[5];
Matt2f2f4252005-04-13 14:45:30 +020058
59 /* capture */
60 hda_nid_t *adc_nids;
Matt2f2f4252005-04-13 14:45:30 +020061 unsigned int num_adcs;
Mattdabbed62005-06-14 10:19:34 +020062 hda_nid_t *mux_nids;
63 unsigned int num_muxes;
Mattdabbed62005-06-14 10:19:34 +020064 hda_nid_t dig_in_nid;
Matt2f2f4252005-04-13 14:45:30 +020065
Matt2f2f4252005-04-13 14:45:30 +020066 /* pin widgets */
67 hda_nid_t *pin_nids;
68 unsigned int num_pins;
Matt2f2f4252005-04-13 14:45:30 +020069 unsigned int *pin_configs;
Matt2f2f4252005-04-13 14:45:30 +020070
71 /* codec specific stuff */
72 struct hda_verb *init;
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +010073 struct snd_kcontrol_new *mixer;
Matt2f2f4252005-04-13 14:45:30 +020074
75 /* capture source */
Mattc7d4b2f2005-06-27 14:59:41 +020076 struct hda_input_mux *input_mux;
Matt Porter3cc08dc2006-01-23 15:27:49 +010077 unsigned int cur_mux[3];
Matt2f2f4252005-04-13 14:45:30 +020078
Matt Porter403d1942005-11-29 15:00:51 +010079 /* i/o switches */
80 unsigned int io_switch[2];
Matt2f2f4252005-04-13 14:45:30 +020081
Mattc7d4b2f2005-06-27 14:59:41 +020082 struct hda_pcm pcm_rec[2]; /* PCM information */
83
84 /* dynamic controls and input_mux */
85 struct auto_pin_cfg autocfg;
86 unsigned int num_kctl_alloc, num_kctl_used;
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +010087 struct snd_kcontrol_new *kctl_alloc;
Mattc7d4b2f2005-06-27 14:59:41 +020088 struct hda_input_mux private_imux;
Matt2f2f4252005-04-13 14:45:30 +020089};
90
91static hda_nid_t stac9200_adc_nids[1] = {
92 0x03,
93};
94
95static hda_nid_t stac9200_mux_nids[1] = {
96 0x0c,
97};
98
99static hda_nid_t stac9200_dac_nids[1] = {
100 0x02,
101};
102
Matt2f2f4252005-04-13 14:45:30 +0200103static hda_nid_t stac922x_adc_nids[2] = {
104 0x06, 0x07,
105};
106
107static hda_nid_t stac922x_mux_nids[2] = {
108 0x12, 0x13,
109};
110
Matt Porter3cc08dc2006-01-23 15:27:49 +0100111static hda_nid_t stac927x_adc_nids[3] = {
112 0x07, 0x08, 0x09
113};
114
115static hda_nid_t stac927x_mux_nids[3] = {
116 0x15, 0x16, 0x17
117};
118
Mattc7d4b2f2005-06-27 14:59:41 +0200119static hda_nid_t stac9200_pin_nids[8] = {
120 0x08, 0x09, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12,
Matt2f2f4252005-04-13 14:45:30 +0200121};
122
123static hda_nid_t stac922x_pin_nids[10] = {
124 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
125 0x0f, 0x10, 0x11, 0x15, 0x1b,
126};
127
Matt Porter3cc08dc2006-01-23 15:27:49 +0100128static hda_nid_t stac927x_pin_nids[14] = {
129 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
130 0x0f, 0x10, 0x11, 0x12, 0x13,
131 0x14, 0x21, 0x22, 0x23,
132};
133
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100134static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Matt2f2f4252005-04-13 14:45:30 +0200135{
136 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
137 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +0200138 return snd_hda_input_mux_info(spec->input_mux, uinfo);
Matt2f2f4252005-04-13 14:45:30 +0200139}
140
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100141static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200142{
143 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
144 struct sigmatel_spec *spec = codec->spec;
145 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
146
147 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
148 return 0;
149}
150
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100151static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200152{
153 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
154 struct sigmatel_spec *spec = codec->spec;
155 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
156
Mattc7d4b2f2005-06-27 14:59:41 +0200157 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
Matt2f2f4252005-04-13 14:45:30 +0200158 spec->mux_nids[adc_idx], &spec->cur_mux[adc_idx]);
159}
160
Mattc7d4b2f2005-06-27 14:59:41 +0200161static struct hda_verb stac9200_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200162 /* set dac0mux for dac converter */
Mattc7d4b2f2005-06-27 14:59:41 +0200163 { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
Matt2f2f4252005-04-13 14:45:30 +0200164 {}
165};
166
Mattc7d4b2f2005-06-27 14:59:41 +0200167static struct hda_verb stac922x_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200168 /* set master volume and direct control */
Mattc7d4b2f2005-06-27 14:59:41 +0200169 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matt2f2f4252005-04-13 14:45:30 +0200170 {}
171};
172
Matt Porter3cc08dc2006-01-23 15:27:49 +0100173static struct hda_verb stac927x_core_init[] = {
174 /* set master volume and direct control */
175 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
176 {}
177};
178
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100179static struct snd_kcontrol_new stac9200_mixer[] = {
Matt2f2f4252005-04-13 14:45:30 +0200180 HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
181 HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
182 {
183 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
184 .name = "Input Source",
185 .count = 1,
186 .info = stac92xx_mux_enum_info,
187 .get = stac92xx_mux_enum_get,
188 .put = stac92xx_mux_enum_put,
189 },
190 HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
191 HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
Mattc7d4b2f2005-06-27 14:59:41 +0200192 HDA_CODEC_VOLUME("Capture Mux Volume", 0x0c, 0, HDA_OUTPUT),
Matt2f2f4252005-04-13 14:45:30 +0200193 { } /* end */
194};
195
Mattc7d4b2f2005-06-27 14:59:41 +0200196/* This needs to be generated dynamically based on sequence */
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100197static struct snd_kcontrol_new stac922x_mixer[] = {
Matt2f2f4252005-04-13 14:45:30 +0200198 {
199 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
200 .name = "Input Source",
201 .count = 1,
202 .info = stac92xx_mux_enum_info,
203 .get = stac92xx_mux_enum_get,
204 .put = stac92xx_mux_enum_put,
205 },
206 HDA_CODEC_VOLUME("Capture Volume", 0x17, 0x0, HDA_INPUT),
Takashi Iwai0fd17082006-01-13 18:46:21 +0100207 HDA_CODEC_MUTE("Capture Switch", 0x17, 0x0, HDA_INPUT),
Matt2f2f4252005-04-13 14:45:30 +0200208 HDA_CODEC_VOLUME("Mux Capture Volume", 0x12, 0x0, HDA_OUTPUT),
209 { } /* end */
210};
211
Matt Porter3cc08dc2006-01-23 15:27:49 +0100212static snd_kcontrol_new_t stac927x_mixer[] = {
213 {
214 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
215 .name = "Input Source",
216 .count = 1,
217 .info = stac92xx_mux_enum_info,
218 .get = stac92xx_mux_enum_get,
219 .put = stac92xx_mux_enum_put,
220 },
221 HDA_CODEC_VOLUME("InMux Capture Volume", 0x15, 0x0, HDA_OUTPUT),
222 HDA_CODEC_VOLUME("InVol Capture Volume", 0x18, 0x0, HDA_INPUT),
223 HDA_CODEC_MUTE("ADCMux Capture Switch", 0x1b, 0x0, HDA_OUTPUT),
224 { } /* end */
225};
226
Matt2f2f4252005-04-13 14:45:30 +0200227static int stac92xx_build_controls(struct hda_codec *codec)
228{
229 struct sigmatel_spec *spec = codec->spec;
230 int err;
Mattc7d4b2f2005-06-27 14:59:41 +0200231 int i;
Matt2f2f4252005-04-13 14:45:30 +0200232
233 err = snd_hda_add_new_ctls(codec, spec->mixer);
234 if (err < 0)
235 return err;
Mattc7d4b2f2005-06-27 14:59:41 +0200236
237 for (i = 0; i < spec->num_mixers; i++) {
238 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
239 if (err < 0)
240 return err;
241 }
242
Mattdabbed62005-06-14 10:19:34 +0200243 if (spec->multiout.dig_out_nid) {
244 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
245 if (err < 0)
246 return err;
247 }
248 if (spec->dig_in_nid) {
249 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
250 if (err < 0)
251 return err;
252 }
253 return 0;
Matt2f2f4252005-04-13 14:45:30 +0200254}
255
Matt Porter403d1942005-11-29 15:00:51 +0100256static unsigned int ref9200_pin_configs[8] = {
Mattdabbed62005-06-14 10:19:34 +0200257 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
Matt2f2f4252005-04-13 14:45:30 +0200258 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
259};
260
Matt Porter403d1942005-11-29 15:00:51 +0100261static unsigned int *stac9200_brd_tbl[] = {
262 ref9200_pin_configs,
263};
264
265static struct hda_board_config stac9200_cfg_tbl[] = {
266 { .modelname = "ref",
267 .pci_subvendor = PCI_VENDOR_ID_INTEL,
268 .pci_subdevice = 0x2668, /* DFI LanParty */
269 .config = STAC_REF },
270 {} /* terminator */
271};
272
273static unsigned int ref922x_pin_configs[10] = {
274 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
275 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
Matt2f2f4252005-04-13 14:45:30 +0200276 0x40000100, 0x40000100,
277};
278
Matt Porter403d1942005-11-29 15:00:51 +0100279static unsigned int d945gtp3_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +0100280 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
Matt Porter403d1942005-11-29 15:00:51 +0100281 0x40000100, 0x40000100, 0x40000100, 0x40000100,
282 0x02a19120, 0x40000100,
283};
284
285static unsigned int d945gtp5_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +0100286 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
287 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
Matt Porter403d1942005-11-29 15:00:51 +0100288 0x02a19320, 0x40000100,
289};
290
291static unsigned int *stac922x_brd_tbl[] = {
292 ref922x_pin_configs,
293 d945gtp3_pin_configs,
294 d945gtp5_pin_configs,
295};
296
297static struct hda_board_config stac922x_cfg_tbl[] = {
298 { .modelname = "ref",
299 .pci_subvendor = PCI_VENDOR_ID_INTEL,
300 .pci_subdevice = 0x2668, /* DFI LanParty */
301 .config = STAC_REF }, /* SigmaTel reference board */
302 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
303 .pci_subdevice = 0x0101,
304 .config = STAC_D945GTP3 }, /* Intel D945GTP - 3 Stack */
305 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
Takashi Iwai353b9e62006-02-16 18:16:17 +0100306 .pci_subdevice = 0x0202,
307 .config = STAC_D945GTP3 }, /* Intel D945GNT - 3 Stack, 9221 A1 */
308 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
309 .pci_subdevice = 0x0b0b,
310 .config = STAC_D945GTP3 }, /* Intel D945PSN - 3 Stack, 9221 A1 */
311 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
Matt Porter403d1942005-11-29 15:00:51 +0100312 .pci_subdevice = 0x0404,
313 .config = STAC_D945GTP5 }, /* Intel D945GTP - 5 Stack */
314 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
315 .pci_subdevice = 0x0303,
316 .config = STAC_D945GTP5 }, /* Intel D945GNT - 5 Stack */
317 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
318 .pci_subdevice = 0x0013,
319 .config = STAC_D945GTP5 }, /* Intel D955XBK - 5 Stack */
Matt Porterd62c40e2006-01-23 15:26:27 +0100320 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
321 .pci_subdevice = 0x0417,
322 .config = STAC_D945GTP5 }, /* Intel D975XBK - 5 Stack */
Matt Porter403d1942005-11-29 15:00:51 +0100323 {} /* terminator */
324};
325
Matt Porter3cc08dc2006-01-23 15:27:49 +0100326static unsigned int ref927x_pin_configs[14] = {
327 0x01813122, 0x01a19021, 0x01014010, 0x01016011,
328 0x01012012, 0x01011014, 0x40000100, 0x40000100,
329 0x40000100, 0x40000100, 0x40000100, 0x01441030,
330 0x01c41030, 0x40000100,
331};
332
333static unsigned int *stac927x_brd_tbl[] = {
334 ref927x_pin_configs,
335};
336
337static struct hda_board_config stac927x_cfg_tbl[] = {
338 { .modelname = "ref",
339 .pci_subvendor = PCI_VENDOR_ID_INTEL,
340 .pci_subdevice = 0x2668, /* DFI LanParty */
341 .config = STAC_REF }, /* SigmaTel reference board */
342 {} /* terminator */
343};
344
Matt2f2f4252005-04-13 14:45:30 +0200345static void stac92xx_set_config_regs(struct hda_codec *codec)
346{
347 int i;
348 struct sigmatel_spec *spec = codec->spec;
349 unsigned int pin_cfg;
350
351 for (i=0; i < spec->num_pins; i++) {
352 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
353 AC_VERB_SET_CONFIG_DEFAULT_BYTES_0,
354 spec->pin_configs[i] & 0x000000ff);
355 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
356 AC_VERB_SET_CONFIG_DEFAULT_BYTES_1,
357 (spec->pin_configs[i] & 0x0000ff00) >> 8);
358 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
359 AC_VERB_SET_CONFIG_DEFAULT_BYTES_2,
360 (spec->pin_configs[i] & 0x00ff0000) >> 16);
361 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
362 AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
363 spec->pin_configs[i] >> 24);
364 pin_cfg = snd_hda_codec_read(codec, spec->pin_nids[i], 0,
365 AC_VERB_GET_CONFIG_DEFAULT,
366 0x00);
Matt Porter403d1942005-11-29 15:00:51 +0100367 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 +0200368 }
369}
Matt2f2f4252005-04-13 14:45:30 +0200370
Matt2f2f4252005-04-13 14:45:30 +0200371/*
372 * Analog playback callbacks
373 */
374static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
375 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100376 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200377{
378 struct sigmatel_spec *spec = codec->spec;
379 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
380}
381
382static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
383 struct hda_codec *codec,
384 unsigned int stream_tag,
385 unsigned int format,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100386 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200387{
388 struct sigmatel_spec *spec = codec->spec;
Matt Porter403d1942005-11-29 15:00:51 +0100389 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
Matt2f2f4252005-04-13 14:45:30 +0200390}
391
392static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
393 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100394 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200395{
396 struct sigmatel_spec *spec = codec->spec;
397 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
398}
399
400/*
Mattdabbed62005-06-14 10:19:34 +0200401 * Digital playback callbacks
402 */
403static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
404 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100405 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +0200406{
407 struct sigmatel_spec *spec = codec->spec;
408 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
409}
410
411static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
412 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100413 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +0200414{
415 struct sigmatel_spec *spec = codec->spec;
416 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
417}
418
419
420/*
Matt2f2f4252005-04-13 14:45:30 +0200421 * Analog capture callbacks
422 */
423static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
424 struct hda_codec *codec,
425 unsigned int stream_tag,
426 unsigned int format,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100427 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200428{
429 struct sigmatel_spec *spec = codec->spec;
430
431 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
432 stream_tag, 0, format);
433 return 0;
434}
435
436static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
437 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100438 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200439{
440 struct sigmatel_spec *spec = codec->spec;
441
442 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 0, 0, 0);
443 return 0;
444}
445
Mattdabbed62005-06-14 10:19:34 +0200446static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
447 .substreams = 1,
448 .channels_min = 2,
449 .channels_max = 2,
450 /* NID is set in stac92xx_build_pcms */
451 .ops = {
452 .open = stac92xx_dig_playback_pcm_open,
453 .close = stac92xx_dig_playback_pcm_close
454 },
455};
456
457static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
458 .substreams = 1,
459 .channels_min = 2,
460 .channels_max = 2,
461 /* NID is set in stac92xx_build_pcms */
462};
463
Matt2f2f4252005-04-13 14:45:30 +0200464static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
465 .substreams = 1,
466 .channels_min = 2,
Mattc7d4b2f2005-06-27 14:59:41 +0200467 .channels_max = 8,
Matt2f2f4252005-04-13 14:45:30 +0200468 .nid = 0x02, /* NID to query formats and rates */
469 .ops = {
470 .open = stac92xx_playback_pcm_open,
471 .prepare = stac92xx_playback_pcm_prepare,
472 .cleanup = stac92xx_playback_pcm_cleanup
473 },
474};
475
Matt Porter3cc08dc2006-01-23 15:27:49 +0100476static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
477 .substreams = 1,
478 .channels_min = 2,
479 .channels_max = 2,
480 .nid = 0x06, /* NID to query formats and rates */
481 .ops = {
482 .open = stac92xx_playback_pcm_open,
483 .prepare = stac92xx_playback_pcm_prepare,
484 .cleanup = stac92xx_playback_pcm_cleanup
485 },
486};
487
Matt2f2f4252005-04-13 14:45:30 +0200488static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
489 .substreams = 2,
490 .channels_min = 2,
491 .channels_max = 2,
Matt Porter3cc08dc2006-01-23 15:27:49 +0100492 /* NID is set in stac92xx_build_pcms */
Matt2f2f4252005-04-13 14:45:30 +0200493 .ops = {
494 .prepare = stac92xx_capture_pcm_prepare,
495 .cleanup = stac92xx_capture_pcm_cleanup
496 },
497};
498
499static int stac92xx_build_pcms(struct hda_codec *codec)
500{
501 struct sigmatel_spec *spec = codec->spec;
502 struct hda_pcm *info = spec->pcm_rec;
503
504 codec->num_pcms = 1;
505 codec->pcm_info = info;
506
Mattc7d4b2f2005-06-27 14:59:41 +0200507 info->name = "STAC92xx Analog";
Matt2f2f4252005-04-13 14:45:30 +0200508 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
Matt2f2f4252005-04-13 14:45:30 +0200509 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100510 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
511
512 if (spec->alt_switch) {
513 codec->num_pcms++;
514 info++;
515 info->name = "STAC92xx Analog Alt";
516 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
517 }
Matt2f2f4252005-04-13 14:45:30 +0200518
Mattdabbed62005-06-14 10:19:34 +0200519 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
520 codec->num_pcms++;
521 info++;
522 info->name = "STAC92xx Digital";
523 if (spec->multiout.dig_out_nid) {
524 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
525 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
526 }
527 if (spec->dig_in_nid) {
528 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
529 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
530 }
531 }
532
Matt2f2f4252005-04-13 14:45:30 +0200533 return 0;
534}
535
Matt Porter403d1942005-11-29 15:00:51 +0100536static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
537
538{
539 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
540}
541
542static int stac92xx_io_switch_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
543{
544 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
545 uinfo->count = 1;
546 uinfo->value.integer.min = 0;
547 uinfo->value.integer.max = 1;
548 return 0;
549}
550
551static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
552{
553 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
554 struct sigmatel_spec *spec = codec->spec;
555 int io_idx = kcontrol-> private_value & 0xff;
556
557 ucontrol->value.integer.value[0] = spec->io_switch[io_idx];
558 return 0;
559}
560
561static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
562{
563 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
564 struct sigmatel_spec *spec = codec->spec;
565 hda_nid_t nid = kcontrol->private_value >> 8;
566 int io_idx = kcontrol-> private_value & 0xff;
567 unsigned short val = ucontrol->value.integer.value[0];
568
569 spec->io_switch[io_idx] = val;
570
571 if (val)
572 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
573 else
574 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_IN_EN);
575
576 return 1;
577}
578
579#define STAC_CODEC_IO_SWITCH(xname, xpval) \
580 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
581 .name = xname, \
582 .index = 0, \
583 .info = stac92xx_io_switch_info, \
584 .get = stac92xx_io_switch_get, \
585 .put = stac92xx_io_switch_put, \
586 .private_value = xpval, \
587 }
588
589
Mattc7d4b2f2005-06-27 14:59:41 +0200590enum {
591 STAC_CTL_WIDGET_VOL,
592 STAC_CTL_WIDGET_MUTE,
Matt Porter403d1942005-11-29 15:00:51 +0100593 STAC_CTL_WIDGET_IO_SWITCH,
Mattc7d4b2f2005-06-27 14:59:41 +0200594};
595
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100596static struct snd_kcontrol_new stac92xx_control_templates[] = {
Mattc7d4b2f2005-06-27 14:59:41 +0200597 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
598 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Matt Porter403d1942005-11-29 15:00:51 +0100599 STAC_CODEC_IO_SWITCH(NULL, 0),
Mattc7d4b2f2005-06-27 14:59:41 +0200600};
601
602/* add dynamic controls */
603static int stac92xx_add_control(struct sigmatel_spec *spec, int type, const char *name, unsigned long val)
604{
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100605 struct snd_kcontrol_new *knew;
Mattc7d4b2f2005-06-27 14:59:41 +0200606
607 if (spec->num_kctl_used >= spec->num_kctl_alloc) {
608 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
609
610 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */
611 if (! knew)
612 return -ENOMEM;
613 if (spec->kctl_alloc) {
614 memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
615 kfree(spec->kctl_alloc);
616 }
617 spec->kctl_alloc = knew;
618 spec->num_kctl_alloc = num;
619 }
620
621 knew = &spec->kctl_alloc[spec->num_kctl_used];
622 *knew = stac92xx_control_templates[type];
Takashi Iwai82fe0c52005-06-30 10:54:33 +0200623 knew->name = kstrdup(name, GFP_KERNEL);
Mattc7d4b2f2005-06-27 14:59:41 +0200624 if (! knew->name)
625 return -ENOMEM;
626 knew->private_value = val;
627 spec->num_kctl_used++;
628 return 0;
629}
630
Matt Porter403d1942005-11-29 15:00:51 +0100631/* flag inputs as additional dynamic lineouts */
632static int stac92xx_add_dyn_out_pins(struct hda_codec *codec, struct auto_pin_cfg *cfg)
633{
634 struct sigmatel_spec *spec = codec->spec;
635
636 switch (cfg->line_outs) {
637 case 3:
638 /* add line-in as side */
639 if (cfg->input_pins[AUTO_PIN_LINE]) {
640 cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_LINE];
641 spec->line_switch = 1;
642 cfg->line_outs++;
643 }
644 break;
645 case 2:
646 /* add line-in as clfe and mic as side */
647 if (cfg->input_pins[AUTO_PIN_LINE]) {
648 cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_LINE];
649 spec->line_switch = 1;
650 cfg->line_outs++;
651 }
652 if (cfg->input_pins[AUTO_PIN_MIC]) {
653 cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_MIC];
654 spec->mic_switch = 1;
655 cfg->line_outs++;
656 }
657 break;
658 case 1:
659 /* add line-in as surr and mic as clfe */
660 if (cfg->input_pins[AUTO_PIN_LINE]) {
661 cfg->line_out_pins[1] = cfg->input_pins[AUTO_PIN_LINE];
662 spec->line_switch = 1;
663 cfg->line_outs++;
664 }
665 if (cfg->input_pins[AUTO_PIN_MIC]) {
666 cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_MIC];
667 spec->mic_switch = 1;
668 cfg->line_outs++;
669 }
670 break;
671 }
672
673 return 0;
674}
675
Matt Porter3cc08dc2006-01-23 15:27:49 +0100676/*
677 * XXX The line_out pin widget connection list may not be set to the
678 * desired DAC nid. This is the case on 927x where ports A and B can
679 * be routed to several DACs.
680 *
681 * This requires an analysis of the line-out/hp pin configuration
682 * to provide a best fit for pin/DAC configurations that are routable.
683 * For now, 927x DAC4 is not supported and 927x DAC1 output to ports
684 * A and B is not supported.
685 */
Mattc7d4b2f2005-06-27 14:59:41 +0200686/* fill in the dac_nids table from the parsed pin configuration */
687static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
688{
689 struct sigmatel_spec *spec = codec->spec;
690 hda_nid_t nid;
691 int i;
692
693 /* check the pins hardwired to audio widget */
694 for (i = 0; i < cfg->line_outs; i++) {
695 nid = cfg->line_out_pins[i];
696 spec->multiout.dac_nids[i] = snd_hda_codec_read(codec, nid, 0,
697 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
698 }
699
Takashi Iwaiad0651f2006-01-24 10:34:34 +0100700 if (cfg->line_outs)
701 spec->multiout.num_dacs = cfg->line_outs;
702 else if (cfg->hp_pin) {
703 spec->multiout.dac_nids[0] = snd_hda_codec_read(codec, cfg->hp_pin, 0,
704 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
705 spec->multiout.num_dacs = 1;
706 }
Mattc7d4b2f2005-06-27 14:59:41 +0200707
708 return 0;
709}
710
711/* add playback controls from the parsed DAC table */
712static int stac92xx_auto_create_multi_out_ctls(struct sigmatel_spec *spec, const struct auto_pin_cfg *cfg)
713{
714 char name[32];
715 static const char *chname[4] = { "Front", "Surround", NULL /*CLFE*/, "Side" };
716 hda_nid_t nid;
717 int i, err;
718
719 for (i = 0; i < cfg->line_outs; i++) {
Matt Porter403d1942005-11-29 15:00:51 +0100720 if (!spec->multiout.dac_nids[i])
Mattc7d4b2f2005-06-27 14:59:41 +0200721 continue;
722
723 nid = spec->multiout.dac_nids[i];
724
725 if (i == 2) {
726 /* Center/LFE */
727 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, "Center Playback Volume",
728 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT))) < 0)
729 return err;
730 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, "LFE Playback Volume",
731 HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT))) < 0)
732 return err;
733 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, "Center Playback Switch",
734 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT))) < 0)
735 return err;
736 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, "LFE Playback Switch",
737 HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT))) < 0)
738 return err;
739 } else {
740 sprintf(name, "%s Playback Volume", chname[i]);
741 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, name,
742 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
743 return err;
744 sprintf(name, "%s Playback Switch", chname[i]);
745 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, name,
746 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
747 return err;
748 }
749 }
750
Matt Porter403d1942005-11-29 15:00:51 +0100751 if (spec->line_switch)
752 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Line In as Output Switch", cfg->input_pins[AUTO_PIN_LINE] << 8)) < 0)
753 return err;
754
755 if (spec->mic_switch)
756 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Mic as Output Switch", (cfg->input_pins[AUTO_PIN_MIC] << 8) | 1)) < 0)
757 return err;
758
Mattc7d4b2f2005-06-27 14:59:41 +0200759 return 0;
760}
761
762/* add playback controls for HP output */
763static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec, struct auto_pin_cfg *cfg)
764{
765 struct sigmatel_spec *spec = codec->spec;
766 hda_nid_t pin = cfg->hp_pin;
767 hda_nid_t nid;
768 int i, err;
Matt4e550962005-07-04 17:51:39 +0200769 unsigned int wid_caps;
Mattc7d4b2f2005-06-27 14:59:41 +0200770
771 if (! pin)
772 return 0;
773
Takashi Iwai54d17402005-11-21 16:33:22 +0100774 wid_caps = get_wcaps(codec, pin);
Matt4e550962005-07-04 17:51:39 +0200775 if (wid_caps & AC_WCAP_UNSOL_CAP)
776 /* Enable unsolicited responses on the HP widget */
777 snd_hda_codec_write(codec, pin, 0,
778 AC_VERB_SET_UNSOLICITED_ENABLE,
779 STAC_UNSOL_ENABLE);
780
Mattc7d4b2f2005-06-27 14:59:41 +0200781 nid = snd_hda_codec_read(codec, pin, 0, AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
782 for (i = 0; i < cfg->line_outs; i++) {
783 if (! spec->multiout.dac_nids[i])
784 continue;
785 if (spec->multiout.dac_nids[i] == nid)
786 return 0;
787 }
788
789 spec->multiout.hp_nid = nid;
790
791 /* control HP volume/switch on the output mixer amp */
792 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, "Headphone Playback Volume",
793 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
794 return err;
795 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, "Headphone Playback Switch",
796 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
797 return err;
798
799 return 0;
800}
801
802/* create playback/capture controls for input pins */
803static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
804{
805 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +0200806 struct hda_input_mux *imux = &spec->private_imux;
807 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
808 int i, j, k;
809
810 for (i = 0; i < AUTO_PIN_LAST; i++) {
811 int index = -1;
812 if (cfg->input_pins[i]) {
Matt Porter403d1942005-11-29 15:00:51 +0100813 /* Enable active pin widget as an input */
814 stac92xx_auto_set_pinctl(codec, cfg->input_pins[i], AC_PINCTL_IN_EN);
815
Takashi Iwai4a471b72005-12-07 13:56:29 +0100816 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
Mattc7d4b2f2005-06-27 14:59:41 +0200817
818 for (j=0; j<spec->num_muxes; j++) {
819 int num_cons = snd_hda_get_connections(codec, spec->mux_nids[j], con_lst, HDA_MAX_NUM_INPUTS);
820 for (k=0; k<num_cons; k++)
821 if (con_lst[k] == cfg->input_pins[i]) {
822 index = k;
823 break;
824 }
825 if (index >= 0)
826 break;
827 }
828 imux->items[imux->num_items].index = index;
829 imux->num_items++;
830 }
831 }
832
833 return 0;
834}
835
Mattc7d4b2f2005-06-27 14:59:41 +0200836static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
837{
838 struct sigmatel_spec *spec = codec->spec;
839 int i;
840
841 for (i = 0; i < spec->autocfg.line_outs; i++) {
842 hda_nid_t nid = spec->autocfg.line_out_pins[i];
843 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
844 }
845}
846
847static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
848{
849 struct sigmatel_spec *spec = codec->spec;
850 hda_nid_t pin;
851
852 pin = spec->autocfg.hp_pin;
853 if (pin) /* connect to front */
854 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
855}
856
Matt Porter3cc08dc2006-01-23 15:27:49 +0100857static 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 +0200858{
859 struct sigmatel_spec *spec = codec->spec;
860 int err;
861
Kailang Yangdf694da2005-12-05 19:42:22 +0100862 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +0200863 return err;
Matt Porter869264c2006-01-25 19:20:50 +0100864 if (! spec->autocfg.line_outs && ! spec->autocfg.hp_pin)
865 return 0; /* can't find valid pin config */
866 stac92xx_auto_init_multi_out(codec);
867 stac92xx_auto_init_hp_out(codec);
Matt Porter403d1942005-11-29 15:00:51 +0100868 if ((err = stac92xx_add_dyn_out_pins(codec, &spec->autocfg)) < 0)
869 return err;
Mattc7d4b2f2005-06-27 14:59:41 +0200870 if ((err = stac92xx_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
871 return err;
Mattc7d4b2f2005-06-27 14:59:41 +0200872
873 if ((err = stac92xx_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
874 (err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg)) < 0 ||
875 (err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
876 return err;
877
878 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Matt Porter403d1942005-11-29 15:00:51 +0100879 if (spec->multiout.max_channels > 2)
Mattc7d4b2f2005-06-27 14:59:41 +0200880 spec->surr_switch = 1;
Mattc7d4b2f2005-06-27 14:59:41 +0200881
882 if (spec->autocfg.dig_out_pin) {
Matt Porter3cc08dc2006-01-23 15:27:49 +0100883 spec->multiout.dig_out_nid = dig_out;
Mattc7d4b2f2005-06-27 14:59:41 +0200884 stac92xx_auto_set_pinctl(codec, spec->autocfg.dig_out_pin, AC_PINCTL_OUT_EN);
885 }
886 if (spec->autocfg.dig_in_pin) {
Matt Porter3cc08dc2006-01-23 15:27:49 +0100887 spec->dig_in_nid = dig_in;
Mattc7d4b2f2005-06-27 14:59:41 +0200888 stac92xx_auto_set_pinctl(codec, spec->autocfg.dig_in_pin, AC_PINCTL_IN_EN);
889 }
890
891 if (spec->kctl_alloc)
892 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
893
894 spec->input_mux = &spec->private_imux;
895
896 return 1;
897}
898
899static int stac9200_parse_auto_config(struct hda_codec *codec)
900{
901 struct sigmatel_spec *spec = codec->spec;
902 int err;
903
Kailang Yangdf694da2005-12-05 19:42:22 +0100904 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +0200905 return err;
906
907 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
908 return err;
909
910 if (spec->autocfg.dig_out_pin) {
911 spec->multiout.dig_out_nid = 0x05;
912 stac92xx_auto_set_pinctl(codec, spec->autocfg.dig_out_pin, AC_PINCTL_OUT_EN);
913 }
914 if (spec->autocfg.dig_in_pin) {
915 spec->dig_in_nid = 0x04;
916 stac92xx_auto_set_pinctl(codec, spec->autocfg.dig_in_pin, AC_PINCTL_IN_EN);
917 }
918
919 if (spec->kctl_alloc)
920 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
921
922 spec->input_mux = &spec->private_imux;
923
924 return 1;
925}
926
Mattc7d4b2f2005-06-27 14:59:41 +0200927static int stac92xx_init(struct hda_codec *codec)
928{
929 struct sigmatel_spec *spec = codec->spec;
930
Mattc7d4b2f2005-06-27 14:59:41 +0200931 snd_hda_sequence_write(codec, spec->init);
932
Mattc7d4b2f2005-06-27 14:59:41 +0200933 return 0;
934}
935
Matt2f2f4252005-04-13 14:45:30 +0200936static void stac92xx_free(struct hda_codec *codec)
937{
Mattc7d4b2f2005-06-27 14:59:41 +0200938 struct sigmatel_spec *spec = codec->spec;
939 int i;
940
941 if (! spec)
942 return;
943
944 if (spec->kctl_alloc) {
945 for (i = 0; i < spec->num_kctl_used; i++)
946 kfree(spec->kctl_alloc[i].name);
947 kfree(spec->kctl_alloc);
948 }
949
950 kfree(spec);
Matt2f2f4252005-04-13 14:45:30 +0200951}
952
Matt4e550962005-07-04 17:51:39 +0200953static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
954 unsigned int flag)
955{
956 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
957 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
958 snd_hda_codec_write(codec, nid, 0,
959 AC_VERB_SET_PIN_WIDGET_CONTROL,
960 pin_ctl | flag);
961}
962
963static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
964 unsigned int flag)
965{
966 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
967 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
968 snd_hda_codec_write(codec, nid, 0,
969 AC_VERB_SET_PIN_WIDGET_CONTROL,
970 pin_ctl & ~flag);
971}
972
973static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
974{
975 struct sigmatel_spec *spec = codec->spec;
976 struct auto_pin_cfg *cfg = &spec->autocfg;
977 int i, presence;
978
979 if ((res >> 26) != STAC_HP_EVENT)
980 return;
981
982 presence = snd_hda_codec_read(codec, cfg->hp_pin, 0,
983 AC_VERB_GET_PIN_SENSE, 0x00) >> 31;
984
985 if (presence) {
986 /* disable lineouts, enable hp */
987 for (i = 0; i < cfg->line_outs; i++)
988 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
989 AC_PINCTL_OUT_EN);
990 stac92xx_set_pinctl(codec, cfg->hp_pin, AC_PINCTL_OUT_EN);
991 } else {
992 /* enable lineouts, disable hp */
993 for (i = 0; i < cfg->line_outs; i++)
994 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
995 AC_PINCTL_OUT_EN);
996 stac92xx_reset_pinctl(codec, cfg->hp_pin, AC_PINCTL_OUT_EN);
997 }
998}
999
Mattff6fdc32005-06-27 15:06:52 +02001000#ifdef CONFIG_PM
1001static int stac92xx_resume(struct hda_codec *codec)
1002{
1003 struct sigmatel_spec *spec = codec->spec;
1004 int i;
1005
1006 stac92xx_init(codec);
1007 for (i = 0; i < spec->num_mixers; i++)
1008 snd_hda_resume_ctls(codec, spec->mixers[i]);
1009 if (spec->multiout.dig_out_nid)
1010 snd_hda_resume_spdif_out(codec);
1011 if (spec->dig_in_nid)
1012 snd_hda_resume_spdif_in(codec);
1013
1014 return 0;
1015}
1016#endif
1017
Matt2f2f4252005-04-13 14:45:30 +02001018static struct hda_codec_ops stac92xx_patch_ops = {
1019 .build_controls = stac92xx_build_controls,
1020 .build_pcms = stac92xx_build_pcms,
1021 .init = stac92xx_init,
1022 .free = stac92xx_free,
Matt4e550962005-07-04 17:51:39 +02001023 .unsol_event = stac92xx_unsol_event,
Mattff6fdc32005-06-27 15:06:52 +02001024#ifdef CONFIG_PM
1025 .resume = stac92xx_resume,
1026#endif
Matt2f2f4252005-04-13 14:45:30 +02001027};
1028
1029static int patch_stac9200(struct hda_codec *codec)
1030{
1031 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02001032 int err;
Matt2f2f4252005-04-13 14:45:30 +02001033
Takashi Iwaie560d8d2005-09-09 14:21:46 +02001034 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02001035 if (spec == NULL)
1036 return -ENOMEM;
1037
1038 codec->spec = spec;
Matt Porter403d1942005-11-29 15:00:51 +01001039 spec->board_config = snd_hda_check_board_config(codec, stac9200_cfg_tbl);
1040 if (spec->board_config < 0)
1041 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9200, using BIOS defaults\n");
1042 else {
1043 spec->num_pins = 8;
1044 spec->pin_nids = stac9200_pin_nids;
1045 spec->pin_configs = stac9200_brd_tbl[spec->board_config];
1046 stac92xx_set_config_regs(codec);
1047 }
Matt2f2f4252005-04-13 14:45:30 +02001048
1049 spec->multiout.max_channels = 2;
1050 spec->multiout.num_dacs = 1;
1051 spec->multiout.dac_nids = stac9200_dac_nids;
1052 spec->adc_nids = stac9200_adc_nids;
1053 spec->mux_nids = stac9200_mux_nids;
Mattdabbed62005-06-14 10:19:34 +02001054 spec->num_muxes = 1;
Mattc7d4b2f2005-06-27 14:59:41 +02001055
1056 spec->init = stac9200_core_init;
Matt2f2f4252005-04-13 14:45:30 +02001057 spec->mixer = stac9200_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02001058
1059 err = stac9200_parse_auto_config(codec);
1060 if (err < 0) {
1061 stac92xx_free(codec);
1062 return err;
1063 }
Matt2f2f4252005-04-13 14:45:30 +02001064
1065 codec->patch_ops = stac92xx_patch_ops;
1066
1067 return 0;
1068}
1069
1070static int patch_stac922x(struct hda_codec *codec)
1071{
1072 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02001073 int err;
Matt2f2f4252005-04-13 14:45:30 +02001074
Takashi Iwaie560d8d2005-09-09 14:21:46 +02001075 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02001076 if (spec == NULL)
1077 return -ENOMEM;
1078
1079 codec->spec = spec;
Matt Porter403d1942005-11-29 15:00:51 +01001080 spec->board_config = snd_hda_check_board_config(codec, stac922x_cfg_tbl);
1081 if (spec->board_config < 0)
1082 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC922x, using BIOS defaults\n");
1083 else {
1084 spec->num_pins = 10;
1085 spec->pin_nids = stac922x_pin_nids;
1086 spec->pin_configs = stac922x_brd_tbl[spec->board_config];
1087 stac92xx_set_config_regs(codec);
1088 }
Matt2f2f4252005-04-13 14:45:30 +02001089
Matt2f2f4252005-04-13 14:45:30 +02001090 spec->adc_nids = stac922x_adc_nids;
1091 spec->mux_nids = stac922x_mux_nids;
Mattdabbed62005-06-14 10:19:34 +02001092 spec->num_muxes = 2;
Mattc7d4b2f2005-06-27 14:59:41 +02001093
1094 spec->init = stac922x_core_init;
Matt2f2f4252005-04-13 14:45:30 +02001095 spec->mixer = stac922x_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02001096
1097 spec->multiout.dac_nids = spec->dac_nids;
1098
Matt Porter3cc08dc2006-01-23 15:27:49 +01001099 err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
1100 if (err < 0) {
1101 stac92xx_free(codec);
1102 return err;
1103 }
1104
1105 codec->patch_ops = stac92xx_patch_ops;
1106
1107 return 0;
1108}
1109
1110static int patch_stac927x(struct hda_codec *codec)
1111{
1112 struct sigmatel_spec *spec;
1113 int err;
1114
1115 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1116 if (spec == NULL)
1117 return -ENOMEM;
1118
1119 codec->spec = spec;
1120 spec->board_config = snd_hda_check_board_config(codec, stac927x_cfg_tbl);
1121 if (spec->board_config < 0)
1122 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC927x, using BIOS defaults\n");
1123 else {
1124 spec->num_pins = 14;
1125 spec->pin_nids = stac927x_pin_nids;
1126 spec->pin_configs = stac927x_brd_tbl[spec->board_config];
1127 stac92xx_set_config_regs(codec);
1128 }
1129
1130 spec->adc_nids = stac927x_adc_nids;
1131 spec->mux_nids = stac927x_mux_nids;
1132 spec->num_muxes = 3;
1133
1134 spec->init = stac927x_core_init;
1135 spec->mixer = stac927x_mixer;
1136
1137 spec->multiout.dac_nids = spec->dac_nids;
1138
1139 err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
Mattc7d4b2f2005-06-27 14:59:41 +02001140 if (err < 0) {
1141 stac92xx_free(codec);
1142 return err;
1143 }
Matt2f2f4252005-04-13 14:45:30 +02001144
1145 codec->patch_ops = stac92xx_patch_ops;
1146
1147 return 0;
1148}
1149
1150/*
1151 * patch entries
1152 */
1153struct hda_codec_preset snd_hda_preset_sigmatel[] = {
1154 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
1155 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
1156 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
1157 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
1158 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
1159 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
1160 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
Matt Porter3cc08dc2006-01-23 15:27:49 +01001161 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
1162 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
1163 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
1164 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
1165 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
1166 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
1167 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
1168 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
1169 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
1170 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
Matt2f2f4252005-04-13 14:45:30 +02001171 {} /* terminator */
1172};