blob: 35c2823a0a2b40e22c0aa1343a46620f8c157142 [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,
306 .pci_subdevice = 0x0404,
307 .config = STAC_D945GTP5 }, /* Intel D945GTP - 5 Stack */
308 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
309 .pci_subdevice = 0x0303,
310 .config = STAC_D945GTP5 }, /* Intel D945GNT - 5 Stack */
311 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
312 .pci_subdevice = 0x0013,
313 .config = STAC_D945GTP5 }, /* Intel D955XBK - 5 Stack */
Matt Porterd62c40e2006-01-23 15:26:27 +0100314 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
315 .pci_subdevice = 0x0417,
316 .config = STAC_D945GTP5 }, /* Intel D975XBK - 5 Stack */
Matt Porter403d1942005-11-29 15:00:51 +0100317 {} /* terminator */
318};
319
Matt Porter3cc08dc2006-01-23 15:27:49 +0100320static unsigned int ref927x_pin_configs[14] = {
321 0x01813122, 0x01a19021, 0x01014010, 0x01016011,
322 0x01012012, 0x01011014, 0x40000100, 0x40000100,
323 0x40000100, 0x40000100, 0x40000100, 0x01441030,
324 0x01c41030, 0x40000100,
325};
326
327static unsigned int *stac927x_brd_tbl[] = {
328 ref927x_pin_configs,
329};
330
331static struct hda_board_config stac927x_cfg_tbl[] = {
332 { .modelname = "ref",
333 .pci_subvendor = PCI_VENDOR_ID_INTEL,
334 .pci_subdevice = 0x2668, /* DFI LanParty */
335 .config = STAC_REF }, /* SigmaTel reference board */
336 {} /* terminator */
337};
338
Matt2f2f4252005-04-13 14:45:30 +0200339static void stac92xx_set_config_regs(struct hda_codec *codec)
340{
341 int i;
342 struct sigmatel_spec *spec = codec->spec;
343 unsigned int pin_cfg;
344
345 for (i=0; i < spec->num_pins; i++) {
346 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
347 AC_VERB_SET_CONFIG_DEFAULT_BYTES_0,
348 spec->pin_configs[i] & 0x000000ff);
349 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
350 AC_VERB_SET_CONFIG_DEFAULT_BYTES_1,
351 (spec->pin_configs[i] & 0x0000ff00) >> 8);
352 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
353 AC_VERB_SET_CONFIG_DEFAULT_BYTES_2,
354 (spec->pin_configs[i] & 0x00ff0000) >> 16);
355 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
356 AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
357 spec->pin_configs[i] >> 24);
358 pin_cfg = snd_hda_codec_read(codec, spec->pin_nids[i], 0,
359 AC_VERB_GET_CONFIG_DEFAULT,
360 0x00);
Matt Porter403d1942005-11-29 15:00:51 +0100361 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 +0200362 }
363}
Matt2f2f4252005-04-13 14:45:30 +0200364
Matt2f2f4252005-04-13 14:45:30 +0200365/*
366 * Analog playback callbacks
367 */
368static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
369 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100370 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200371{
372 struct sigmatel_spec *spec = codec->spec;
373 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
374}
375
376static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
377 struct hda_codec *codec,
378 unsigned int stream_tag,
379 unsigned int format,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100380 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200381{
382 struct sigmatel_spec *spec = codec->spec;
Matt Porter403d1942005-11-29 15:00:51 +0100383 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
Matt2f2f4252005-04-13 14:45:30 +0200384}
385
386static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
387 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100388 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200389{
390 struct sigmatel_spec *spec = codec->spec;
391 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
392}
393
394/*
Mattdabbed62005-06-14 10:19:34 +0200395 * Digital playback callbacks
396 */
397static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
398 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100399 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +0200400{
401 struct sigmatel_spec *spec = codec->spec;
402 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
403}
404
405static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
406 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100407 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +0200408{
409 struct sigmatel_spec *spec = codec->spec;
410 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
411}
412
413
414/*
Matt2f2f4252005-04-13 14:45:30 +0200415 * Analog capture callbacks
416 */
417static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
418 struct hda_codec *codec,
419 unsigned int stream_tag,
420 unsigned int format,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100421 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200422{
423 struct sigmatel_spec *spec = codec->spec;
424
425 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
426 stream_tag, 0, format);
427 return 0;
428}
429
430static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
431 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100432 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200433{
434 struct sigmatel_spec *spec = codec->spec;
435
436 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 0, 0, 0);
437 return 0;
438}
439
Mattdabbed62005-06-14 10:19:34 +0200440static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
441 .substreams = 1,
442 .channels_min = 2,
443 .channels_max = 2,
444 /* NID is set in stac92xx_build_pcms */
445 .ops = {
446 .open = stac92xx_dig_playback_pcm_open,
447 .close = stac92xx_dig_playback_pcm_close
448 },
449};
450
451static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
452 .substreams = 1,
453 .channels_min = 2,
454 .channels_max = 2,
455 /* NID is set in stac92xx_build_pcms */
456};
457
Matt2f2f4252005-04-13 14:45:30 +0200458static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
459 .substreams = 1,
460 .channels_min = 2,
Mattc7d4b2f2005-06-27 14:59:41 +0200461 .channels_max = 8,
Matt2f2f4252005-04-13 14:45:30 +0200462 .nid = 0x02, /* NID to query formats and rates */
463 .ops = {
464 .open = stac92xx_playback_pcm_open,
465 .prepare = stac92xx_playback_pcm_prepare,
466 .cleanup = stac92xx_playback_pcm_cleanup
467 },
468};
469
Matt Porter3cc08dc2006-01-23 15:27:49 +0100470static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
471 .substreams = 1,
472 .channels_min = 2,
473 .channels_max = 2,
474 .nid = 0x06, /* NID to query formats and rates */
475 .ops = {
476 .open = stac92xx_playback_pcm_open,
477 .prepare = stac92xx_playback_pcm_prepare,
478 .cleanup = stac92xx_playback_pcm_cleanup
479 },
480};
481
Matt2f2f4252005-04-13 14:45:30 +0200482static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
483 .substreams = 2,
484 .channels_min = 2,
485 .channels_max = 2,
Matt Porter3cc08dc2006-01-23 15:27:49 +0100486 /* NID is set in stac92xx_build_pcms */
Matt2f2f4252005-04-13 14:45:30 +0200487 .ops = {
488 .prepare = stac92xx_capture_pcm_prepare,
489 .cleanup = stac92xx_capture_pcm_cleanup
490 },
491};
492
493static int stac92xx_build_pcms(struct hda_codec *codec)
494{
495 struct sigmatel_spec *spec = codec->spec;
496 struct hda_pcm *info = spec->pcm_rec;
497
498 codec->num_pcms = 1;
499 codec->pcm_info = info;
500
Mattc7d4b2f2005-06-27 14:59:41 +0200501 info->name = "STAC92xx Analog";
Matt2f2f4252005-04-13 14:45:30 +0200502 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
Matt2f2f4252005-04-13 14:45:30 +0200503 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100504 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
505
506 if (spec->alt_switch) {
507 codec->num_pcms++;
508 info++;
509 info->name = "STAC92xx Analog Alt";
510 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
511 }
Matt2f2f4252005-04-13 14:45:30 +0200512
Mattdabbed62005-06-14 10:19:34 +0200513 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
514 codec->num_pcms++;
515 info++;
516 info->name = "STAC92xx Digital";
517 if (spec->multiout.dig_out_nid) {
518 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
519 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
520 }
521 if (spec->dig_in_nid) {
522 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
523 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
524 }
525 }
526
Matt2f2f4252005-04-13 14:45:30 +0200527 return 0;
528}
529
Matt Porter403d1942005-11-29 15:00:51 +0100530static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
531
532{
533 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
534}
535
536static int stac92xx_io_switch_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
537{
538 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
539 uinfo->count = 1;
540 uinfo->value.integer.min = 0;
541 uinfo->value.integer.max = 1;
542 return 0;
543}
544
545static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
546{
547 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
548 struct sigmatel_spec *spec = codec->spec;
549 int io_idx = kcontrol-> private_value & 0xff;
550
551 ucontrol->value.integer.value[0] = spec->io_switch[io_idx];
552 return 0;
553}
554
555static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
556{
557 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
558 struct sigmatel_spec *spec = codec->spec;
559 hda_nid_t nid = kcontrol->private_value >> 8;
560 int io_idx = kcontrol-> private_value & 0xff;
561 unsigned short val = ucontrol->value.integer.value[0];
562
563 spec->io_switch[io_idx] = val;
564
565 if (val)
566 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
567 else
568 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_IN_EN);
569
570 return 1;
571}
572
573#define STAC_CODEC_IO_SWITCH(xname, xpval) \
574 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
575 .name = xname, \
576 .index = 0, \
577 .info = stac92xx_io_switch_info, \
578 .get = stac92xx_io_switch_get, \
579 .put = stac92xx_io_switch_put, \
580 .private_value = xpval, \
581 }
582
583
Mattc7d4b2f2005-06-27 14:59:41 +0200584enum {
585 STAC_CTL_WIDGET_VOL,
586 STAC_CTL_WIDGET_MUTE,
Matt Porter403d1942005-11-29 15:00:51 +0100587 STAC_CTL_WIDGET_IO_SWITCH,
Mattc7d4b2f2005-06-27 14:59:41 +0200588};
589
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100590static struct snd_kcontrol_new stac92xx_control_templates[] = {
Mattc7d4b2f2005-06-27 14:59:41 +0200591 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
592 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Matt Porter403d1942005-11-29 15:00:51 +0100593 STAC_CODEC_IO_SWITCH(NULL, 0),
Mattc7d4b2f2005-06-27 14:59:41 +0200594};
595
596/* add dynamic controls */
597static int stac92xx_add_control(struct sigmatel_spec *spec, int type, const char *name, unsigned long val)
598{
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100599 struct snd_kcontrol_new *knew;
Mattc7d4b2f2005-06-27 14:59:41 +0200600
601 if (spec->num_kctl_used >= spec->num_kctl_alloc) {
602 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
603
604 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */
605 if (! knew)
606 return -ENOMEM;
607 if (spec->kctl_alloc) {
608 memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
609 kfree(spec->kctl_alloc);
610 }
611 spec->kctl_alloc = knew;
612 spec->num_kctl_alloc = num;
613 }
614
615 knew = &spec->kctl_alloc[spec->num_kctl_used];
616 *knew = stac92xx_control_templates[type];
Takashi Iwai82fe0c52005-06-30 10:54:33 +0200617 knew->name = kstrdup(name, GFP_KERNEL);
Mattc7d4b2f2005-06-27 14:59:41 +0200618 if (! knew->name)
619 return -ENOMEM;
620 knew->private_value = val;
621 spec->num_kctl_used++;
622 return 0;
623}
624
Matt Porter403d1942005-11-29 15:00:51 +0100625/* flag inputs as additional dynamic lineouts */
626static int stac92xx_add_dyn_out_pins(struct hda_codec *codec, struct auto_pin_cfg *cfg)
627{
628 struct sigmatel_spec *spec = codec->spec;
629
630 switch (cfg->line_outs) {
631 case 3:
632 /* add line-in as side */
633 if (cfg->input_pins[AUTO_PIN_LINE]) {
634 cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_LINE];
635 spec->line_switch = 1;
636 cfg->line_outs++;
637 }
638 break;
639 case 2:
640 /* add line-in as clfe and mic as side */
641 if (cfg->input_pins[AUTO_PIN_LINE]) {
642 cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_LINE];
643 spec->line_switch = 1;
644 cfg->line_outs++;
645 }
646 if (cfg->input_pins[AUTO_PIN_MIC]) {
647 cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_MIC];
648 spec->mic_switch = 1;
649 cfg->line_outs++;
650 }
651 break;
652 case 1:
653 /* add line-in as surr and mic as clfe */
654 if (cfg->input_pins[AUTO_PIN_LINE]) {
655 cfg->line_out_pins[1] = cfg->input_pins[AUTO_PIN_LINE];
656 spec->line_switch = 1;
657 cfg->line_outs++;
658 }
659 if (cfg->input_pins[AUTO_PIN_MIC]) {
660 cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_MIC];
661 spec->mic_switch = 1;
662 cfg->line_outs++;
663 }
664 break;
665 }
666
667 return 0;
668}
669
Matt Porter3cc08dc2006-01-23 15:27:49 +0100670/*
671 * XXX The line_out pin widget connection list may not be set to the
672 * desired DAC nid. This is the case on 927x where ports A and B can
673 * be routed to several DACs.
674 *
675 * This requires an analysis of the line-out/hp pin configuration
676 * to provide a best fit for pin/DAC configurations that are routable.
677 * For now, 927x DAC4 is not supported and 927x DAC1 output to ports
678 * A and B is not supported.
679 */
Mattc7d4b2f2005-06-27 14:59:41 +0200680/* fill in the dac_nids table from the parsed pin configuration */
681static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
682{
683 struct sigmatel_spec *spec = codec->spec;
684 hda_nid_t nid;
685 int i;
686
687 /* check the pins hardwired to audio widget */
688 for (i = 0; i < cfg->line_outs; i++) {
689 nid = cfg->line_out_pins[i];
690 spec->multiout.dac_nids[i] = snd_hda_codec_read(codec, nid, 0,
691 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
692 }
693
Takashi Iwaiad0651f2006-01-24 10:34:34 +0100694 if (cfg->line_outs)
695 spec->multiout.num_dacs = cfg->line_outs;
696 else if (cfg->hp_pin) {
697 spec->multiout.dac_nids[0] = snd_hda_codec_read(codec, cfg->hp_pin, 0,
698 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
699 spec->multiout.num_dacs = 1;
700 }
Mattc7d4b2f2005-06-27 14:59:41 +0200701
702 return 0;
703}
704
705/* add playback controls from the parsed DAC table */
706static int stac92xx_auto_create_multi_out_ctls(struct sigmatel_spec *spec, const struct auto_pin_cfg *cfg)
707{
708 char name[32];
709 static const char *chname[4] = { "Front", "Surround", NULL /*CLFE*/, "Side" };
710 hda_nid_t nid;
711 int i, err;
712
713 for (i = 0; i < cfg->line_outs; i++) {
Matt Porter403d1942005-11-29 15:00:51 +0100714 if (!spec->multiout.dac_nids[i])
Mattc7d4b2f2005-06-27 14:59:41 +0200715 continue;
716
717 nid = spec->multiout.dac_nids[i];
718
719 if (i == 2) {
720 /* Center/LFE */
721 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, "Center Playback Volume",
722 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT))) < 0)
723 return err;
724 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, "LFE Playback Volume",
725 HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT))) < 0)
726 return err;
727 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, "Center Playback Switch",
728 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT))) < 0)
729 return err;
730 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, "LFE Playback Switch",
731 HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT))) < 0)
732 return err;
733 } else {
734 sprintf(name, "%s Playback Volume", chname[i]);
735 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, name,
736 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
737 return err;
738 sprintf(name, "%s Playback Switch", chname[i]);
739 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, name,
740 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
741 return err;
742 }
743 }
744
Matt Porter403d1942005-11-29 15:00:51 +0100745 if (spec->line_switch)
746 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Line In as Output Switch", cfg->input_pins[AUTO_PIN_LINE] << 8)) < 0)
747 return err;
748
749 if (spec->mic_switch)
750 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Mic as Output Switch", (cfg->input_pins[AUTO_PIN_MIC] << 8) | 1)) < 0)
751 return err;
752
Mattc7d4b2f2005-06-27 14:59:41 +0200753 return 0;
754}
755
756/* add playback controls for HP output */
757static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec, struct auto_pin_cfg *cfg)
758{
759 struct sigmatel_spec *spec = codec->spec;
760 hda_nid_t pin = cfg->hp_pin;
761 hda_nid_t nid;
762 int i, err;
Matt4e550962005-07-04 17:51:39 +0200763 unsigned int wid_caps;
Mattc7d4b2f2005-06-27 14:59:41 +0200764
765 if (! pin)
766 return 0;
767
Takashi Iwai54d17402005-11-21 16:33:22 +0100768 wid_caps = get_wcaps(codec, pin);
Matt4e550962005-07-04 17:51:39 +0200769 if (wid_caps & AC_WCAP_UNSOL_CAP)
770 /* Enable unsolicited responses on the HP widget */
771 snd_hda_codec_write(codec, pin, 0,
772 AC_VERB_SET_UNSOLICITED_ENABLE,
773 STAC_UNSOL_ENABLE);
774
Mattc7d4b2f2005-06-27 14:59:41 +0200775 nid = snd_hda_codec_read(codec, pin, 0, AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
776 for (i = 0; i < cfg->line_outs; i++) {
777 if (! spec->multiout.dac_nids[i])
778 continue;
779 if (spec->multiout.dac_nids[i] == nid)
780 return 0;
781 }
782
783 spec->multiout.hp_nid = nid;
784
785 /* control HP volume/switch on the output mixer amp */
786 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, "Headphone Playback Volume",
787 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
788 return err;
789 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, "Headphone Playback Switch",
790 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
791 return err;
792
793 return 0;
794}
795
796/* create playback/capture controls for input pins */
797static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
798{
799 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +0200800 struct hda_input_mux *imux = &spec->private_imux;
801 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
802 int i, j, k;
803
804 for (i = 0; i < AUTO_PIN_LAST; i++) {
805 int index = -1;
806 if (cfg->input_pins[i]) {
Matt Porter403d1942005-11-29 15:00:51 +0100807 /* Enable active pin widget as an input */
808 stac92xx_auto_set_pinctl(codec, cfg->input_pins[i], AC_PINCTL_IN_EN);
809
Takashi Iwai4a471b72005-12-07 13:56:29 +0100810 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
Mattc7d4b2f2005-06-27 14:59:41 +0200811
812 for (j=0; j<spec->num_muxes; j++) {
813 int num_cons = snd_hda_get_connections(codec, spec->mux_nids[j], con_lst, HDA_MAX_NUM_INPUTS);
814 for (k=0; k<num_cons; k++)
815 if (con_lst[k] == cfg->input_pins[i]) {
816 index = k;
817 break;
818 }
819 if (index >= 0)
820 break;
821 }
822 imux->items[imux->num_items].index = index;
823 imux->num_items++;
824 }
825 }
826
827 return 0;
828}
829
Mattc7d4b2f2005-06-27 14:59:41 +0200830static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
831{
832 struct sigmatel_spec *spec = codec->spec;
833 int i;
834
835 for (i = 0; i < spec->autocfg.line_outs; i++) {
836 hda_nid_t nid = spec->autocfg.line_out_pins[i];
837 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
838 }
839}
840
841static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
842{
843 struct sigmatel_spec *spec = codec->spec;
844 hda_nid_t pin;
845
846 pin = spec->autocfg.hp_pin;
847 if (pin) /* connect to front */
848 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
849}
850
Matt Porter3cc08dc2006-01-23 15:27:49 +0100851static 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 +0200852{
853 struct sigmatel_spec *spec = codec->spec;
854 int err;
855
Kailang Yangdf694da2005-12-05 19:42:22 +0100856 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +0200857 return err;
Matt Porter869264c2006-01-25 19:20:50 +0100858 if (! spec->autocfg.line_outs && ! spec->autocfg.hp_pin)
859 return 0; /* can't find valid pin config */
860 stac92xx_auto_init_multi_out(codec);
861 stac92xx_auto_init_hp_out(codec);
Matt Porter403d1942005-11-29 15:00:51 +0100862 if ((err = stac92xx_add_dyn_out_pins(codec, &spec->autocfg)) < 0)
863 return err;
Mattc7d4b2f2005-06-27 14:59:41 +0200864 if ((err = stac92xx_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
865 return err;
Mattc7d4b2f2005-06-27 14:59:41 +0200866
867 if ((err = stac92xx_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
868 (err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg)) < 0 ||
869 (err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
870 return err;
871
872 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Matt Porter403d1942005-11-29 15:00:51 +0100873 if (spec->multiout.max_channels > 2)
Mattc7d4b2f2005-06-27 14:59:41 +0200874 spec->surr_switch = 1;
Mattc7d4b2f2005-06-27 14:59:41 +0200875
876 if (spec->autocfg.dig_out_pin) {
Matt Porter3cc08dc2006-01-23 15:27:49 +0100877 spec->multiout.dig_out_nid = dig_out;
Mattc7d4b2f2005-06-27 14:59:41 +0200878 stac92xx_auto_set_pinctl(codec, spec->autocfg.dig_out_pin, AC_PINCTL_OUT_EN);
879 }
880 if (spec->autocfg.dig_in_pin) {
Matt Porter3cc08dc2006-01-23 15:27:49 +0100881 spec->dig_in_nid = dig_in;
Mattc7d4b2f2005-06-27 14:59:41 +0200882 stac92xx_auto_set_pinctl(codec, spec->autocfg.dig_in_pin, AC_PINCTL_IN_EN);
883 }
884
885 if (spec->kctl_alloc)
886 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
887
888 spec->input_mux = &spec->private_imux;
889
890 return 1;
891}
892
893static int stac9200_parse_auto_config(struct hda_codec *codec)
894{
895 struct sigmatel_spec *spec = codec->spec;
896 int err;
897
Kailang Yangdf694da2005-12-05 19:42:22 +0100898 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +0200899 return err;
900
901 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
902 return err;
903
904 if (spec->autocfg.dig_out_pin) {
905 spec->multiout.dig_out_nid = 0x05;
906 stac92xx_auto_set_pinctl(codec, spec->autocfg.dig_out_pin, AC_PINCTL_OUT_EN);
907 }
908 if (spec->autocfg.dig_in_pin) {
909 spec->dig_in_nid = 0x04;
910 stac92xx_auto_set_pinctl(codec, spec->autocfg.dig_in_pin, AC_PINCTL_IN_EN);
911 }
912
913 if (spec->kctl_alloc)
914 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
915
916 spec->input_mux = &spec->private_imux;
917
918 return 1;
919}
920
Mattc7d4b2f2005-06-27 14:59:41 +0200921static int stac92xx_init(struct hda_codec *codec)
922{
923 struct sigmatel_spec *spec = codec->spec;
924
Mattc7d4b2f2005-06-27 14:59:41 +0200925 snd_hda_sequence_write(codec, spec->init);
926
Mattc7d4b2f2005-06-27 14:59:41 +0200927 return 0;
928}
929
Matt2f2f4252005-04-13 14:45:30 +0200930static void stac92xx_free(struct hda_codec *codec)
931{
Mattc7d4b2f2005-06-27 14:59:41 +0200932 struct sigmatel_spec *spec = codec->spec;
933 int i;
934
935 if (! spec)
936 return;
937
938 if (spec->kctl_alloc) {
939 for (i = 0; i < spec->num_kctl_used; i++)
940 kfree(spec->kctl_alloc[i].name);
941 kfree(spec->kctl_alloc);
942 }
943
944 kfree(spec);
Matt2f2f4252005-04-13 14:45:30 +0200945}
946
Matt4e550962005-07-04 17:51:39 +0200947static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
948 unsigned int flag)
949{
950 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
951 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
952 snd_hda_codec_write(codec, nid, 0,
953 AC_VERB_SET_PIN_WIDGET_CONTROL,
954 pin_ctl | flag);
955}
956
957static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
958 unsigned int flag)
959{
960 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
961 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
962 snd_hda_codec_write(codec, nid, 0,
963 AC_VERB_SET_PIN_WIDGET_CONTROL,
964 pin_ctl & ~flag);
965}
966
967static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
968{
969 struct sigmatel_spec *spec = codec->spec;
970 struct auto_pin_cfg *cfg = &spec->autocfg;
971 int i, presence;
972
973 if ((res >> 26) != STAC_HP_EVENT)
974 return;
975
976 presence = snd_hda_codec_read(codec, cfg->hp_pin, 0,
977 AC_VERB_GET_PIN_SENSE, 0x00) >> 31;
978
979 if (presence) {
980 /* disable lineouts, enable hp */
981 for (i = 0; i < cfg->line_outs; i++)
982 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
983 AC_PINCTL_OUT_EN);
984 stac92xx_set_pinctl(codec, cfg->hp_pin, AC_PINCTL_OUT_EN);
985 } else {
986 /* enable lineouts, disable hp */
987 for (i = 0; i < cfg->line_outs; i++)
988 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
989 AC_PINCTL_OUT_EN);
990 stac92xx_reset_pinctl(codec, cfg->hp_pin, AC_PINCTL_OUT_EN);
991 }
992}
993
Mattff6fdc32005-06-27 15:06:52 +0200994#ifdef CONFIG_PM
995static int stac92xx_resume(struct hda_codec *codec)
996{
997 struct sigmatel_spec *spec = codec->spec;
998 int i;
999
1000 stac92xx_init(codec);
1001 for (i = 0; i < spec->num_mixers; i++)
1002 snd_hda_resume_ctls(codec, spec->mixers[i]);
1003 if (spec->multiout.dig_out_nid)
1004 snd_hda_resume_spdif_out(codec);
1005 if (spec->dig_in_nid)
1006 snd_hda_resume_spdif_in(codec);
1007
1008 return 0;
1009}
1010#endif
1011
Matt2f2f4252005-04-13 14:45:30 +02001012static struct hda_codec_ops stac92xx_patch_ops = {
1013 .build_controls = stac92xx_build_controls,
1014 .build_pcms = stac92xx_build_pcms,
1015 .init = stac92xx_init,
1016 .free = stac92xx_free,
Matt4e550962005-07-04 17:51:39 +02001017 .unsol_event = stac92xx_unsol_event,
Mattff6fdc32005-06-27 15:06:52 +02001018#ifdef CONFIG_PM
1019 .resume = stac92xx_resume,
1020#endif
Matt2f2f4252005-04-13 14:45:30 +02001021};
1022
1023static int patch_stac9200(struct hda_codec *codec)
1024{
1025 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02001026 int err;
Matt2f2f4252005-04-13 14:45:30 +02001027
Takashi Iwaie560d8d2005-09-09 14:21:46 +02001028 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02001029 if (spec == NULL)
1030 return -ENOMEM;
1031
1032 codec->spec = spec;
Matt Porter403d1942005-11-29 15:00:51 +01001033 spec->board_config = snd_hda_check_board_config(codec, stac9200_cfg_tbl);
1034 if (spec->board_config < 0)
1035 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9200, using BIOS defaults\n");
1036 else {
1037 spec->num_pins = 8;
1038 spec->pin_nids = stac9200_pin_nids;
1039 spec->pin_configs = stac9200_brd_tbl[spec->board_config];
1040 stac92xx_set_config_regs(codec);
1041 }
Matt2f2f4252005-04-13 14:45:30 +02001042
1043 spec->multiout.max_channels = 2;
1044 spec->multiout.num_dacs = 1;
1045 spec->multiout.dac_nids = stac9200_dac_nids;
1046 spec->adc_nids = stac9200_adc_nids;
1047 spec->mux_nids = stac9200_mux_nids;
Mattdabbed62005-06-14 10:19:34 +02001048 spec->num_muxes = 1;
Mattc7d4b2f2005-06-27 14:59:41 +02001049
1050 spec->init = stac9200_core_init;
Matt2f2f4252005-04-13 14:45:30 +02001051 spec->mixer = stac9200_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02001052
1053 err = stac9200_parse_auto_config(codec);
1054 if (err < 0) {
1055 stac92xx_free(codec);
1056 return err;
1057 }
Matt2f2f4252005-04-13 14:45:30 +02001058
1059 codec->patch_ops = stac92xx_patch_ops;
1060
1061 return 0;
1062}
1063
1064static int patch_stac922x(struct hda_codec *codec)
1065{
1066 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02001067 int err;
Matt2f2f4252005-04-13 14:45:30 +02001068
Takashi Iwaie560d8d2005-09-09 14:21:46 +02001069 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02001070 if (spec == NULL)
1071 return -ENOMEM;
1072
1073 codec->spec = spec;
Matt Porter403d1942005-11-29 15:00:51 +01001074 spec->board_config = snd_hda_check_board_config(codec, stac922x_cfg_tbl);
1075 if (spec->board_config < 0)
1076 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC922x, using BIOS defaults\n");
1077 else {
1078 spec->num_pins = 10;
1079 spec->pin_nids = stac922x_pin_nids;
1080 spec->pin_configs = stac922x_brd_tbl[spec->board_config];
1081 stac92xx_set_config_regs(codec);
1082 }
Matt2f2f4252005-04-13 14:45:30 +02001083
Matt2f2f4252005-04-13 14:45:30 +02001084 spec->adc_nids = stac922x_adc_nids;
1085 spec->mux_nids = stac922x_mux_nids;
Mattdabbed62005-06-14 10:19:34 +02001086 spec->num_muxes = 2;
Mattc7d4b2f2005-06-27 14:59:41 +02001087
1088 spec->init = stac922x_core_init;
Matt2f2f4252005-04-13 14:45:30 +02001089 spec->mixer = stac922x_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02001090
1091 spec->multiout.dac_nids = spec->dac_nids;
1092
Matt Porter3cc08dc2006-01-23 15:27:49 +01001093 err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
1094 if (err < 0) {
1095 stac92xx_free(codec);
1096 return err;
1097 }
1098
1099 codec->patch_ops = stac92xx_patch_ops;
1100
1101 return 0;
1102}
1103
1104static int patch_stac927x(struct hda_codec *codec)
1105{
1106 struct sigmatel_spec *spec;
1107 int err;
1108
1109 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1110 if (spec == NULL)
1111 return -ENOMEM;
1112
1113 codec->spec = spec;
1114 spec->board_config = snd_hda_check_board_config(codec, stac927x_cfg_tbl);
1115 if (spec->board_config < 0)
1116 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC927x, using BIOS defaults\n");
1117 else {
1118 spec->num_pins = 14;
1119 spec->pin_nids = stac927x_pin_nids;
1120 spec->pin_configs = stac927x_brd_tbl[spec->board_config];
1121 stac92xx_set_config_regs(codec);
1122 }
1123
1124 spec->adc_nids = stac927x_adc_nids;
1125 spec->mux_nids = stac927x_mux_nids;
1126 spec->num_muxes = 3;
1127
1128 spec->init = stac927x_core_init;
1129 spec->mixer = stac927x_mixer;
1130
1131 spec->multiout.dac_nids = spec->dac_nids;
1132
1133 err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
Mattc7d4b2f2005-06-27 14:59:41 +02001134 if (err < 0) {
1135 stac92xx_free(codec);
1136 return err;
1137 }
Matt2f2f4252005-04-13 14:45:30 +02001138
1139 codec->patch_ops = stac92xx_patch_ops;
1140
1141 return 0;
1142}
1143
1144/*
1145 * patch entries
1146 */
1147struct hda_codec_preset snd_hda_preset_sigmatel[] = {
1148 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
1149 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
1150 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
1151 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
1152 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
1153 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
1154 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
Matt Porter3cc08dc2006-01-23 15:27:49 +01001155 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
1156 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
1157 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
1158 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
1159 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
1160 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
1161 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
1162 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
1163 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
1164 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
Matt2f2f4252005-04-13 14:45:30 +02001165 {} /* terminator */
1166};