blob: f2f9465d4df298f7ca0b3af62c2aaff42bd9b27f [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;
Mattc7d4b2f2005-06-27 14:59:41 +020053
Matt2f2f4252005-04-13 14:45:30 +020054 /* playback */
55 struct hda_multi_out multiout;
Mattc7d4b2f2005-06-27 14:59:41 +020056 hda_nid_t dac_nids[4];
Matt2f2f4252005-04-13 14:45:30 +020057
58 /* capture */
59 hda_nid_t *adc_nids;
Matt2f2f4252005-04-13 14:45:30 +020060 unsigned int num_adcs;
Mattdabbed62005-06-14 10:19:34 +020061 hda_nid_t *mux_nids;
62 unsigned int num_muxes;
Mattdabbed62005-06-14 10:19:34 +020063 hda_nid_t dig_in_nid;
Matt2f2f4252005-04-13 14:45:30 +020064
Matt2f2f4252005-04-13 14:45:30 +020065 /* pin widgets */
66 hda_nid_t *pin_nids;
67 unsigned int num_pins;
Matt2f2f4252005-04-13 14:45:30 +020068 unsigned int *pin_configs;
Matt2f2f4252005-04-13 14:45:30 +020069
70 /* codec specific stuff */
71 struct hda_verb *init;
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +010072 struct snd_kcontrol_new *mixer;
Matt2f2f4252005-04-13 14:45:30 +020073
74 /* capture source */
Mattc7d4b2f2005-06-27 14:59:41 +020075 struct hda_input_mux *input_mux;
Matt2f2f4252005-04-13 14:45:30 +020076 unsigned int cur_mux[2];
77
Matt Porter403d1942005-11-29 15:00:51 +010078 /* i/o switches */
79 unsigned int io_switch[2];
Matt2f2f4252005-04-13 14:45:30 +020080
Mattc7d4b2f2005-06-27 14:59:41 +020081 struct hda_pcm pcm_rec[2]; /* PCM information */
82
83 /* dynamic controls and input_mux */
84 struct auto_pin_cfg autocfg;
85 unsigned int num_kctl_alloc, num_kctl_used;
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +010086 struct snd_kcontrol_new *kctl_alloc;
Mattc7d4b2f2005-06-27 14:59:41 +020087 struct hda_input_mux private_imux;
Matt2f2f4252005-04-13 14:45:30 +020088};
89
90static hda_nid_t stac9200_adc_nids[1] = {
91 0x03,
92};
93
94static hda_nid_t stac9200_mux_nids[1] = {
95 0x0c,
96};
97
98static hda_nid_t stac9200_dac_nids[1] = {
99 0x02,
100};
101
Matt2f2f4252005-04-13 14:45:30 +0200102static hda_nid_t stac922x_adc_nids[2] = {
103 0x06, 0x07,
104};
105
106static hda_nid_t stac922x_mux_nids[2] = {
107 0x12, 0x13,
108};
109
Mattc7d4b2f2005-06-27 14:59:41 +0200110static hda_nid_t stac9200_pin_nids[8] = {
111 0x08, 0x09, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12,
Matt2f2f4252005-04-13 14:45:30 +0200112};
113
114static hda_nid_t stac922x_pin_nids[10] = {
115 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
116 0x0f, 0x10, 0x11, 0x15, 0x1b,
117};
118
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100119static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Matt2f2f4252005-04-13 14:45:30 +0200120{
121 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
122 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +0200123 return snd_hda_input_mux_info(spec->input_mux, uinfo);
Matt2f2f4252005-04-13 14:45:30 +0200124}
125
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100126static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200127{
128 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
129 struct sigmatel_spec *spec = codec->spec;
130 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
131
132 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
133 return 0;
134}
135
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100136static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200137{
138 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
139 struct sigmatel_spec *spec = codec->spec;
140 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
141
Mattc7d4b2f2005-06-27 14:59:41 +0200142 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
Matt2f2f4252005-04-13 14:45:30 +0200143 spec->mux_nids[adc_idx], &spec->cur_mux[adc_idx]);
144}
145
Mattc7d4b2f2005-06-27 14:59:41 +0200146static struct hda_verb stac9200_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200147 /* set dac0mux for dac converter */
Mattc7d4b2f2005-06-27 14:59:41 +0200148 { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
Matt2f2f4252005-04-13 14:45:30 +0200149 {}
150};
151
Mattc7d4b2f2005-06-27 14:59:41 +0200152static struct hda_verb stac922x_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200153 /* set master volume and direct control */
Mattc7d4b2f2005-06-27 14:59:41 +0200154 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matt2f2f4252005-04-13 14:45:30 +0200155 {}
156};
157
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100158static struct snd_kcontrol_new stac9200_mixer[] = {
Matt2f2f4252005-04-13 14:45:30 +0200159 HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
160 HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
161 {
162 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
163 .name = "Input Source",
164 .count = 1,
165 .info = stac92xx_mux_enum_info,
166 .get = stac92xx_mux_enum_get,
167 .put = stac92xx_mux_enum_put,
168 },
169 HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
170 HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
Mattc7d4b2f2005-06-27 14:59:41 +0200171 HDA_CODEC_VOLUME("Capture Mux Volume", 0x0c, 0, HDA_OUTPUT),
Matt2f2f4252005-04-13 14:45:30 +0200172 { } /* end */
173};
174
Mattc7d4b2f2005-06-27 14:59:41 +0200175/* This needs to be generated dynamically based on sequence */
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100176static struct snd_kcontrol_new stac922x_mixer[] = {
Matt2f2f4252005-04-13 14:45:30 +0200177 {
178 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
179 .name = "Input Source",
180 .count = 1,
181 .info = stac92xx_mux_enum_info,
182 .get = stac92xx_mux_enum_get,
183 .put = stac92xx_mux_enum_put,
184 },
185 HDA_CODEC_VOLUME("Capture Volume", 0x17, 0x0, HDA_INPUT),
Takashi Iwai0fd17082006-01-13 18:46:21 +0100186 HDA_CODEC_MUTE("Capture Switch", 0x17, 0x0, HDA_INPUT),
Matt2f2f4252005-04-13 14:45:30 +0200187 HDA_CODEC_VOLUME("Mux Capture Volume", 0x12, 0x0, HDA_OUTPUT),
188 { } /* end */
189};
190
Matt2f2f4252005-04-13 14:45:30 +0200191static int stac92xx_build_controls(struct hda_codec *codec)
192{
193 struct sigmatel_spec *spec = codec->spec;
194 int err;
Mattc7d4b2f2005-06-27 14:59:41 +0200195 int i;
Matt2f2f4252005-04-13 14:45:30 +0200196
197 err = snd_hda_add_new_ctls(codec, spec->mixer);
198 if (err < 0)
199 return err;
Mattc7d4b2f2005-06-27 14:59:41 +0200200
201 for (i = 0; i < spec->num_mixers; i++) {
202 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
203 if (err < 0)
204 return err;
205 }
206
Mattdabbed62005-06-14 10:19:34 +0200207 if (spec->multiout.dig_out_nid) {
208 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
209 if (err < 0)
210 return err;
211 }
212 if (spec->dig_in_nid) {
213 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
214 if (err < 0)
215 return err;
216 }
217 return 0;
Matt2f2f4252005-04-13 14:45:30 +0200218}
219
Matt Porter403d1942005-11-29 15:00:51 +0100220static unsigned int ref9200_pin_configs[8] = {
Mattdabbed62005-06-14 10:19:34 +0200221 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
Matt2f2f4252005-04-13 14:45:30 +0200222 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
223};
224
Matt Porter403d1942005-11-29 15:00:51 +0100225static unsigned int *stac9200_brd_tbl[] = {
226 ref9200_pin_configs,
227};
228
229static struct hda_board_config stac9200_cfg_tbl[] = {
230 { .modelname = "ref",
231 .pci_subvendor = PCI_VENDOR_ID_INTEL,
232 .pci_subdevice = 0x2668, /* DFI LanParty */
233 .config = STAC_REF },
234 {} /* terminator */
235};
236
237static unsigned int ref922x_pin_configs[10] = {
238 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
239 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
Matt2f2f4252005-04-13 14:45:30 +0200240 0x40000100, 0x40000100,
241};
242
Matt Porter403d1942005-11-29 15:00:51 +0100243static unsigned int d945gtp3_pin_configs[10] = {
244 0x0221401f, 0x01a19022, 0x01813021, 0x01114010,
245 0x40000100, 0x40000100, 0x40000100, 0x40000100,
246 0x02a19120, 0x40000100,
247};
248
249static unsigned int d945gtp5_pin_configs[10] = {
250 0x0221401f, 0x01111012, 0x01813024, 0x01114010,
251 0x01a19021, 0x01116011, 0x01452130, 0x40000100,
252 0x02a19320, 0x40000100,
253};
254
255static unsigned int *stac922x_brd_tbl[] = {
256 ref922x_pin_configs,
257 d945gtp3_pin_configs,
258 d945gtp5_pin_configs,
259};
260
261static struct hda_board_config stac922x_cfg_tbl[] = {
262 { .modelname = "ref",
263 .pci_subvendor = PCI_VENDOR_ID_INTEL,
264 .pci_subdevice = 0x2668, /* DFI LanParty */
265 .config = STAC_REF }, /* SigmaTel reference board */
266 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
267 .pci_subdevice = 0x0101,
268 .config = STAC_D945GTP3 }, /* Intel D945GTP - 3 Stack */
269 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
270 .pci_subdevice = 0x0404,
271 .config = STAC_D945GTP5 }, /* Intel D945GTP - 5 Stack */
272 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
273 .pci_subdevice = 0x0303,
274 .config = STAC_D945GTP5 }, /* Intel D945GNT - 5 Stack */
275 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
276 .pci_subdevice = 0x0013,
277 .config = STAC_D945GTP5 }, /* Intel D955XBK - 5 Stack */
Matt Porterd62c40e2006-01-23 15:26:27 +0100278 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
279 .pci_subdevice = 0x0417,
280 .config = STAC_D945GTP5 }, /* Intel D975XBK - 5 Stack */
Matt Porter403d1942005-11-29 15:00:51 +0100281 {} /* terminator */
282};
283
Matt2f2f4252005-04-13 14:45:30 +0200284static void stac92xx_set_config_regs(struct hda_codec *codec)
285{
286 int i;
287 struct sigmatel_spec *spec = codec->spec;
288 unsigned int pin_cfg;
289
290 for (i=0; i < spec->num_pins; i++) {
291 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
292 AC_VERB_SET_CONFIG_DEFAULT_BYTES_0,
293 spec->pin_configs[i] & 0x000000ff);
294 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
295 AC_VERB_SET_CONFIG_DEFAULT_BYTES_1,
296 (spec->pin_configs[i] & 0x0000ff00) >> 8);
297 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
298 AC_VERB_SET_CONFIG_DEFAULT_BYTES_2,
299 (spec->pin_configs[i] & 0x00ff0000) >> 16);
300 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
301 AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
302 spec->pin_configs[i] >> 24);
303 pin_cfg = snd_hda_codec_read(codec, spec->pin_nids[i], 0,
304 AC_VERB_GET_CONFIG_DEFAULT,
305 0x00);
Matt Porter403d1942005-11-29 15:00:51 +0100306 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 +0200307 }
308}
Matt2f2f4252005-04-13 14:45:30 +0200309
Matt2f2f4252005-04-13 14:45:30 +0200310/*
311 * Analog playback callbacks
312 */
313static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
314 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100315 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200316{
317 struct sigmatel_spec *spec = codec->spec;
318 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
319}
320
321static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
322 struct hda_codec *codec,
323 unsigned int stream_tag,
324 unsigned int format,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100325 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200326{
327 struct sigmatel_spec *spec = codec->spec;
Matt Porter403d1942005-11-29 15:00:51 +0100328 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
Matt2f2f4252005-04-13 14:45:30 +0200329}
330
331static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
332 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100333 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200334{
335 struct sigmatel_spec *spec = codec->spec;
336 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
337}
338
339/*
Mattdabbed62005-06-14 10:19:34 +0200340 * Digital playback callbacks
341 */
342static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
343 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100344 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +0200345{
346 struct sigmatel_spec *spec = codec->spec;
347 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
348}
349
350static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
351 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100352 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +0200353{
354 struct sigmatel_spec *spec = codec->spec;
355 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
356}
357
358
359/*
Matt2f2f4252005-04-13 14:45:30 +0200360 * Analog capture callbacks
361 */
362static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
363 struct hda_codec *codec,
364 unsigned int stream_tag,
365 unsigned int format,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100366 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200367{
368 struct sigmatel_spec *spec = codec->spec;
369
370 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
371 stream_tag, 0, format);
372 return 0;
373}
374
375static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
376 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-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
381 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 0, 0, 0);
382 return 0;
383}
384
Mattdabbed62005-06-14 10:19:34 +0200385static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
386 .substreams = 1,
387 .channels_min = 2,
388 .channels_max = 2,
389 /* NID is set in stac92xx_build_pcms */
390 .ops = {
391 .open = stac92xx_dig_playback_pcm_open,
392 .close = stac92xx_dig_playback_pcm_close
393 },
394};
395
396static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
397 .substreams = 1,
398 .channels_min = 2,
399 .channels_max = 2,
400 /* NID is set in stac92xx_build_pcms */
401};
402
Matt2f2f4252005-04-13 14:45:30 +0200403static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
404 .substreams = 1,
405 .channels_min = 2,
Mattc7d4b2f2005-06-27 14:59:41 +0200406 .channels_max = 8,
Matt2f2f4252005-04-13 14:45:30 +0200407 .nid = 0x02, /* NID to query formats and rates */
408 .ops = {
409 .open = stac92xx_playback_pcm_open,
410 .prepare = stac92xx_playback_pcm_prepare,
411 .cleanup = stac92xx_playback_pcm_cleanup
412 },
413};
414
415static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
416 .substreams = 2,
417 .channels_min = 2,
418 .channels_max = 2,
419 .nid = 0x06, /* NID to query formats and rates */
420 .ops = {
421 .prepare = stac92xx_capture_pcm_prepare,
422 .cleanup = stac92xx_capture_pcm_cleanup
423 },
424};
425
426static int stac92xx_build_pcms(struct hda_codec *codec)
427{
428 struct sigmatel_spec *spec = codec->spec;
429 struct hda_pcm *info = spec->pcm_rec;
430
431 codec->num_pcms = 1;
432 codec->pcm_info = info;
433
Mattc7d4b2f2005-06-27 14:59:41 +0200434 info->name = "STAC92xx Analog";
Matt2f2f4252005-04-13 14:45:30 +0200435 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
Matt2f2f4252005-04-13 14:45:30 +0200436 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
Matt2f2f4252005-04-13 14:45:30 +0200437
Mattdabbed62005-06-14 10:19:34 +0200438 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
439 codec->num_pcms++;
440 info++;
441 info->name = "STAC92xx Digital";
442 if (spec->multiout.dig_out_nid) {
443 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
444 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
445 }
446 if (spec->dig_in_nid) {
447 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
448 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
449 }
450 }
451
Matt2f2f4252005-04-13 14:45:30 +0200452 return 0;
453}
454
Matt Porter403d1942005-11-29 15:00:51 +0100455static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
456
457{
458 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
459}
460
461static int stac92xx_io_switch_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
462{
463 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
464 uinfo->count = 1;
465 uinfo->value.integer.min = 0;
466 uinfo->value.integer.max = 1;
467 return 0;
468}
469
470static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
471{
472 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
473 struct sigmatel_spec *spec = codec->spec;
474 int io_idx = kcontrol-> private_value & 0xff;
475
476 ucontrol->value.integer.value[0] = spec->io_switch[io_idx];
477 return 0;
478}
479
480static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
481{
482 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
483 struct sigmatel_spec *spec = codec->spec;
484 hda_nid_t nid = kcontrol->private_value >> 8;
485 int io_idx = kcontrol-> private_value & 0xff;
486 unsigned short val = ucontrol->value.integer.value[0];
487
488 spec->io_switch[io_idx] = val;
489
490 if (val)
491 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
492 else
493 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_IN_EN);
494
495 return 1;
496}
497
498#define STAC_CODEC_IO_SWITCH(xname, xpval) \
499 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
500 .name = xname, \
501 .index = 0, \
502 .info = stac92xx_io_switch_info, \
503 .get = stac92xx_io_switch_get, \
504 .put = stac92xx_io_switch_put, \
505 .private_value = xpval, \
506 }
507
508
Mattc7d4b2f2005-06-27 14:59:41 +0200509enum {
510 STAC_CTL_WIDGET_VOL,
511 STAC_CTL_WIDGET_MUTE,
Matt Porter403d1942005-11-29 15:00:51 +0100512 STAC_CTL_WIDGET_IO_SWITCH,
Mattc7d4b2f2005-06-27 14:59:41 +0200513};
514
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100515static struct snd_kcontrol_new stac92xx_control_templates[] = {
Mattc7d4b2f2005-06-27 14:59:41 +0200516 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
517 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Matt Porter403d1942005-11-29 15:00:51 +0100518 STAC_CODEC_IO_SWITCH(NULL, 0),
Mattc7d4b2f2005-06-27 14:59:41 +0200519};
520
521/* add dynamic controls */
522static int stac92xx_add_control(struct sigmatel_spec *spec, int type, const char *name, unsigned long val)
523{
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100524 struct snd_kcontrol_new *knew;
Mattc7d4b2f2005-06-27 14:59:41 +0200525
526 if (spec->num_kctl_used >= spec->num_kctl_alloc) {
527 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
528
529 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */
530 if (! knew)
531 return -ENOMEM;
532 if (spec->kctl_alloc) {
533 memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
534 kfree(spec->kctl_alloc);
535 }
536 spec->kctl_alloc = knew;
537 spec->num_kctl_alloc = num;
538 }
539
540 knew = &spec->kctl_alloc[spec->num_kctl_used];
541 *knew = stac92xx_control_templates[type];
Takashi Iwai82fe0c52005-06-30 10:54:33 +0200542 knew->name = kstrdup(name, GFP_KERNEL);
Mattc7d4b2f2005-06-27 14:59:41 +0200543 if (! knew->name)
544 return -ENOMEM;
545 knew->private_value = val;
546 spec->num_kctl_used++;
547 return 0;
548}
549
Matt Porter403d1942005-11-29 15:00:51 +0100550/* flag inputs as additional dynamic lineouts */
551static int stac92xx_add_dyn_out_pins(struct hda_codec *codec, struct auto_pin_cfg *cfg)
552{
553 struct sigmatel_spec *spec = codec->spec;
554
555 switch (cfg->line_outs) {
556 case 3:
557 /* add line-in as side */
558 if (cfg->input_pins[AUTO_PIN_LINE]) {
559 cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_LINE];
560 spec->line_switch = 1;
561 cfg->line_outs++;
562 }
563 break;
564 case 2:
565 /* add line-in as clfe and mic as side */
566 if (cfg->input_pins[AUTO_PIN_LINE]) {
567 cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_LINE];
568 spec->line_switch = 1;
569 cfg->line_outs++;
570 }
571 if (cfg->input_pins[AUTO_PIN_MIC]) {
572 cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_MIC];
573 spec->mic_switch = 1;
574 cfg->line_outs++;
575 }
576 break;
577 case 1:
578 /* add line-in as surr and mic as clfe */
579 if (cfg->input_pins[AUTO_PIN_LINE]) {
580 cfg->line_out_pins[1] = cfg->input_pins[AUTO_PIN_LINE];
581 spec->line_switch = 1;
582 cfg->line_outs++;
583 }
584 if (cfg->input_pins[AUTO_PIN_MIC]) {
585 cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_MIC];
586 spec->mic_switch = 1;
587 cfg->line_outs++;
588 }
589 break;
590 }
591
592 return 0;
593}
594
Mattc7d4b2f2005-06-27 14:59:41 +0200595/* fill in the dac_nids table from the parsed pin configuration */
596static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
597{
598 struct sigmatel_spec *spec = codec->spec;
599 hda_nid_t nid;
600 int i;
601
602 /* check the pins hardwired to audio widget */
603 for (i = 0; i < cfg->line_outs; i++) {
604 nid = cfg->line_out_pins[i];
605 spec->multiout.dac_nids[i] = snd_hda_codec_read(codec, nid, 0,
606 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
607 }
608
609 spec->multiout.num_dacs = cfg->line_outs;
610
611 return 0;
612}
613
614/* add playback controls from the parsed DAC table */
615static int stac92xx_auto_create_multi_out_ctls(struct sigmatel_spec *spec, const struct auto_pin_cfg *cfg)
616{
617 char name[32];
618 static const char *chname[4] = { "Front", "Surround", NULL /*CLFE*/, "Side" };
619 hda_nid_t nid;
620 int i, err;
621
622 for (i = 0; i < cfg->line_outs; i++) {
Matt Porter403d1942005-11-29 15:00:51 +0100623 if (!spec->multiout.dac_nids[i])
Mattc7d4b2f2005-06-27 14:59:41 +0200624 continue;
625
626 nid = spec->multiout.dac_nids[i];
627
628 if (i == 2) {
629 /* Center/LFE */
630 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, "Center Playback Volume",
631 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT))) < 0)
632 return err;
633 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, "LFE Playback Volume",
634 HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT))) < 0)
635 return err;
636 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, "Center Playback Switch",
637 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT))) < 0)
638 return err;
639 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, "LFE Playback Switch",
640 HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT))) < 0)
641 return err;
642 } else {
643 sprintf(name, "%s Playback Volume", chname[i]);
644 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, name,
645 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
646 return err;
647 sprintf(name, "%s Playback Switch", chname[i]);
648 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, name,
649 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
650 return err;
651 }
652 }
653
Matt Porter403d1942005-11-29 15:00:51 +0100654 if (spec->line_switch)
655 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Line In as Output Switch", cfg->input_pins[AUTO_PIN_LINE] << 8)) < 0)
656 return err;
657
658 if (spec->mic_switch)
659 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Mic as Output Switch", (cfg->input_pins[AUTO_PIN_MIC] << 8) | 1)) < 0)
660 return err;
661
Mattc7d4b2f2005-06-27 14:59:41 +0200662 return 0;
663}
664
665/* add playback controls for HP output */
666static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec, struct auto_pin_cfg *cfg)
667{
668 struct sigmatel_spec *spec = codec->spec;
669 hda_nid_t pin = cfg->hp_pin;
670 hda_nid_t nid;
671 int i, err;
Matt4e550962005-07-04 17:51:39 +0200672 unsigned int wid_caps;
Mattc7d4b2f2005-06-27 14:59:41 +0200673
674 if (! pin)
675 return 0;
676
Takashi Iwai54d17402005-11-21 16:33:22 +0100677 wid_caps = get_wcaps(codec, pin);
Matt4e550962005-07-04 17:51:39 +0200678 if (wid_caps & AC_WCAP_UNSOL_CAP)
679 /* Enable unsolicited responses on the HP widget */
680 snd_hda_codec_write(codec, pin, 0,
681 AC_VERB_SET_UNSOLICITED_ENABLE,
682 STAC_UNSOL_ENABLE);
683
Mattc7d4b2f2005-06-27 14:59:41 +0200684 nid = snd_hda_codec_read(codec, pin, 0, AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
685 for (i = 0; i < cfg->line_outs; i++) {
686 if (! spec->multiout.dac_nids[i])
687 continue;
688 if (spec->multiout.dac_nids[i] == nid)
689 return 0;
690 }
691
692 spec->multiout.hp_nid = nid;
693
694 /* control HP volume/switch on the output mixer amp */
695 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, "Headphone Playback Volume",
696 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
697 return err;
698 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, "Headphone Playback Switch",
699 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
700 return err;
701
702 return 0;
703}
704
705/* create playback/capture controls for input pins */
706static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
707{
708 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +0200709 struct hda_input_mux *imux = &spec->private_imux;
710 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
711 int i, j, k;
712
713 for (i = 0; i < AUTO_PIN_LAST; i++) {
714 int index = -1;
715 if (cfg->input_pins[i]) {
Matt Porter403d1942005-11-29 15:00:51 +0100716 /* Enable active pin widget as an input */
717 stac92xx_auto_set_pinctl(codec, cfg->input_pins[i], AC_PINCTL_IN_EN);
718
Takashi Iwai4a471b72005-12-07 13:56:29 +0100719 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
Mattc7d4b2f2005-06-27 14:59:41 +0200720
721 for (j=0; j<spec->num_muxes; j++) {
722 int num_cons = snd_hda_get_connections(codec, spec->mux_nids[j], con_lst, HDA_MAX_NUM_INPUTS);
723 for (k=0; k<num_cons; k++)
724 if (con_lst[k] == cfg->input_pins[i]) {
725 index = k;
726 break;
727 }
728 if (index >= 0)
729 break;
730 }
731 imux->items[imux->num_items].index = index;
732 imux->num_items++;
733 }
734 }
735
736 return 0;
737}
738
Mattc7d4b2f2005-06-27 14:59:41 +0200739static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
740{
741 struct sigmatel_spec *spec = codec->spec;
742 int i;
743
744 for (i = 0; i < spec->autocfg.line_outs; i++) {
745 hda_nid_t nid = spec->autocfg.line_out_pins[i];
746 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
747 }
748}
749
750static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
751{
752 struct sigmatel_spec *spec = codec->spec;
753 hda_nid_t pin;
754
755 pin = spec->autocfg.hp_pin;
756 if (pin) /* connect to front */
757 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
758}
759
760static int stac922x_parse_auto_config(struct hda_codec *codec)
761{
762 struct sigmatel_spec *spec = codec->spec;
763 int err;
764
Kailang Yangdf694da2005-12-05 19:42:22 +0100765 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +0200766 return err;
Matt Porter403d1942005-11-29 15:00:51 +0100767 if ((err = stac92xx_add_dyn_out_pins(codec, &spec->autocfg)) < 0)
768 return err;
Mattc7d4b2f2005-06-27 14:59:41 +0200769 if ((err = stac92xx_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
770 return err;
771 if (! spec->autocfg.line_outs && ! spec->autocfg.hp_pin)
772 return 0; /* can't find valid pin config */
773
774 if ((err = stac92xx_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
775 (err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg)) < 0 ||
776 (err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
777 return err;
778
779 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Matt Porter403d1942005-11-29 15:00:51 +0100780 if (spec->multiout.max_channels > 2)
Mattc7d4b2f2005-06-27 14:59:41 +0200781 spec->surr_switch = 1;
Mattc7d4b2f2005-06-27 14:59:41 +0200782
783 if (spec->autocfg.dig_out_pin) {
784 spec->multiout.dig_out_nid = 0x08;
785 stac92xx_auto_set_pinctl(codec, spec->autocfg.dig_out_pin, AC_PINCTL_OUT_EN);
786 }
787 if (spec->autocfg.dig_in_pin) {
788 spec->dig_in_nid = 0x09;
789 stac92xx_auto_set_pinctl(codec, spec->autocfg.dig_in_pin, AC_PINCTL_IN_EN);
790 }
791
792 if (spec->kctl_alloc)
793 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
794
795 spec->input_mux = &spec->private_imux;
796
797 return 1;
798}
799
800static int stac9200_parse_auto_config(struct hda_codec *codec)
801{
802 struct sigmatel_spec *spec = codec->spec;
803 int err;
804
Kailang Yangdf694da2005-12-05 19:42:22 +0100805 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +0200806 return err;
807
808 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
809 return err;
810
811 if (spec->autocfg.dig_out_pin) {
812 spec->multiout.dig_out_nid = 0x05;
813 stac92xx_auto_set_pinctl(codec, spec->autocfg.dig_out_pin, AC_PINCTL_OUT_EN);
814 }
815 if (spec->autocfg.dig_in_pin) {
816 spec->dig_in_nid = 0x04;
817 stac92xx_auto_set_pinctl(codec, spec->autocfg.dig_in_pin, AC_PINCTL_IN_EN);
818 }
819
820 if (spec->kctl_alloc)
821 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
822
823 spec->input_mux = &spec->private_imux;
824
825 return 1;
826}
827
Mattc7d4b2f2005-06-27 14:59:41 +0200828static int stac92xx_init(struct hda_codec *codec)
829{
830 struct sigmatel_spec *spec = codec->spec;
831
Mattc7d4b2f2005-06-27 14:59:41 +0200832 snd_hda_sequence_write(codec, spec->init);
833
834 stac92xx_auto_init_multi_out(codec);
835 stac92xx_auto_init_hp_out(codec);
836
837 return 0;
838}
839
Matt2f2f4252005-04-13 14:45:30 +0200840static void stac92xx_free(struct hda_codec *codec)
841{
Mattc7d4b2f2005-06-27 14:59:41 +0200842 struct sigmatel_spec *spec = codec->spec;
843 int i;
844
845 if (! spec)
846 return;
847
848 if (spec->kctl_alloc) {
849 for (i = 0; i < spec->num_kctl_used; i++)
850 kfree(spec->kctl_alloc[i].name);
851 kfree(spec->kctl_alloc);
852 }
853
854 kfree(spec);
Matt2f2f4252005-04-13 14:45:30 +0200855}
856
Matt4e550962005-07-04 17:51:39 +0200857static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
858 unsigned int flag)
859{
860 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
861 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
862 snd_hda_codec_write(codec, nid, 0,
863 AC_VERB_SET_PIN_WIDGET_CONTROL,
864 pin_ctl | flag);
865}
866
867static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
868 unsigned int flag)
869{
870 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
871 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
872 snd_hda_codec_write(codec, nid, 0,
873 AC_VERB_SET_PIN_WIDGET_CONTROL,
874 pin_ctl & ~flag);
875}
876
877static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
878{
879 struct sigmatel_spec *spec = codec->spec;
880 struct auto_pin_cfg *cfg = &spec->autocfg;
881 int i, presence;
882
883 if ((res >> 26) != STAC_HP_EVENT)
884 return;
885
886 presence = snd_hda_codec_read(codec, cfg->hp_pin, 0,
887 AC_VERB_GET_PIN_SENSE, 0x00) >> 31;
888
889 if (presence) {
890 /* disable lineouts, enable hp */
891 for (i = 0; i < cfg->line_outs; i++)
892 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
893 AC_PINCTL_OUT_EN);
894 stac92xx_set_pinctl(codec, cfg->hp_pin, AC_PINCTL_OUT_EN);
895 } else {
896 /* enable lineouts, disable hp */
897 for (i = 0; i < cfg->line_outs; i++)
898 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
899 AC_PINCTL_OUT_EN);
900 stac92xx_reset_pinctl(codec, cfg->hp_pin, AC_PINCTL_OUT_EN);
901 }
902}
903
Mattff6fdc32005-06-27 15:06:52 +0200904#ifdef CONFIG_PM
905static int stac92xx_resume(struct hda_codec *codec)
906{
907 struct sigmatel_spec *spec = codec->spec;
908 int i;
909
910 stac92xx_init(codec);
911 for (i = 0; i < spec->num_mixers; i++)
912 snd_hda_resume_ctls(codec, spec->mixers[i]);
913 if (spec->multiout.dig_out_nid)
914 snd_hda_resume_spdif_out(codec);
915 if (spec->dig_in_nid)
916 snd_hda_resume_spdif_in(codec);
917
918 return 0;
919}
920#endif
921
Matt2f2f4252005-04-13 14:45:30 +0200922static struct hda_codec_ops stac92xx_patch_ops = {
923 .build_controls = stac92xx_build_controls,
924 .build_pcms = stac92xx_build_pcms,
925 .init = stac92xx_init,
926 .free = stac92xx_free,
Matt4e550962005-07-04 17:51:39 +0200927 .unsol_event = stac92xx_unsol_event,
Mattff6fdc32005-06-27 15:06:52 +0200928#ifdef CONFIG_PM
929 .resume = stac92xx_resume,
930#endif
Matt2f2f4252005-04-13 14:45:30 +0200931};
932
933static int patch_stac9200(struct hda_codec *codec)
934{
935 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +0200936 int err;
Matt2f2f4252005-04-13 14:45:30 +0200937
Takashi Iwaie560d8d2005-09-09 14:21:46 +0200938 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +0200939 if (spec == NULL)
940 return -ENOMEM;
941
942 codec->spec = spec;
Matt Porter403d1942005-11-29 15:00:51 +0100943 spec->board_config = snd_hda_check_board_config(codec, stac9200_cfg_tbl);
944 if (spec->board_config < 0)
945 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9200, using BIOS defaults\n");
946 else {
947 spec->num_pins = 8;
948 spec->pin_nids = stac9200_pin_nids;
949 spec->pin_configs = stac9200_brd_tbl[spec->board_config];
950 stac92xx_set_config_regs(codec);
951 }
Matt2f2f4252005-04-13 14:45:30 +0200952
953 spec->multiout.max_channels = 2;
954 spec->multiout.num_dacs = 1;
955 spec->multiout.dac_nids = stac9200_dac_nids;
956 spec->adc_nids = stac9200_adc_nids;
957 spec->mux_nids = stac9200_mux_nids;
Mattdabbed62005-06-14 10:19:34 +0200958 spec->num_muxes = 1;
Mattc7d4b2f2005-06-27 14:59:41 +0200959
960 spec->init = stac9200_core_init;
Matt2f2f4252005-04-13 14:45:30 +0200961 spec->mixer = stac9200_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +0200962
963 err = stac9200_parse_auto_config(codec);
964 if (err < 0) {
965 stac92xx_free(codec);
966 return err;
967 }
Matt2f2f4252005-04-13 14:45:30 +0200968
969 codec->patch_ops = stac92xx_patch_ops;
970
971 return 0;
972}
973
974static int patch_stac922x(struct hda_codec *codec)
975{
976 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +0200977 int err;
Matt2f2f4252005-04-13 14:45:30 +0200978
Takashi Iwaie560d8d2005-09-09 14:21:46 +0200979 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +0200980 if (spec == NULL)
981 return -ENOMEM;
982
983 codec->spec = spec;
Matt Porter403d1942005-11-29 15:00:51 +0100984 spec->board_config = snd_hda_check_board_config(codec, stac922x_cfg_tbl);
985 if (spec->board_config < 0)
986 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC922x, using BIOS defaults\n");
987 else {
988 spec->num_pins = 10;
989 spec->pin_nids = stac922x_pin_nids;
990 spec->pin_configs = stac922x_brd_tbl[spec->board_config];
991 stac92xx_set_config_regs(codec);
992 }
Matt2f2f4252005-04-13 14:45:30 +0200993
Matt2f2f4252005-04-13 14:45:30 +0200994 spec->adc_nids = stac922x_adc_nids;
995 spec->mux_nids = stac922x_mux_nids;
Mattdabbed62005-06-14 10:19:34 +0200996 spec->num_muxes = 2;
Mattc7d4b2f2005-06-27 14:59:41 +0200997
998 spec->init = stac922x_core_init;
Matt2f2f4252005-04-13 14:45:30 +0200999 spec->mixer = stac922x_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02001000
1001 spec->multiout.dac_nids = spec->dac_nids;
1002
1003 err = stac922x_parse_auto_config(codec);
1004 if (err < 0) {
1005 stac92xx_free(codec);
1006 return err;
1007 }
Matt2f2f4252005-04-13 14:45:30 +02001008
1009 codec->patch_ops = stac92xx_patch_ops;
1010
1011 return 0;
1012}
1013
1014/*
1015 * patch entries
1016 */
1017struct hda_codec_preset snd_hda_preset_sigmatel[] = {
1018 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
1019 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
1020 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
1021 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
1022 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
1023 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
1024 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
1025 {} /* terminator */
1026};