blob: 61903848cd43c9cf04405faef1a16b7a1099cbe1 [file] [log] [blame]
Matt2f2f4252005-04-13 14:45:30 +02001/*
2 * Universal Interface for Intel High Definition Audio Codec
3 *
4 * HD audio interface patch for SigmaTel STAC92xx
5 *
6 * Copyright (c) 2005 Embedded Alley Solutions, Inc.
Matt Porter403d1942005-11-29 15:00:51 +01007 * Matt Porter <mporter@embeddedalley.com>
Matt2f2f4252005-04-13 14:45:30 +02008 *
9 * Based on patch_cmedia.c and patch_realtek.c
10 * Copyright (c) 2004 Takashi Iwai <tiwai@suse.de>
11 *
12 * This driver is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This driver is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 */
26
27#include <sound/driver.h>
28#include <linux/init.h>
29#include <linux/delay.h>
30#include <linux/slab.h>
31#include <linux/pci.h>
32#include <sound/core.h>
Mattc7d4b2f2005-06-27 14:59:41 +020033#include <sound/asoundef.h>
Matt2f2f4252005-04-13 14:45:30 +020034#include "hda_codec.h"
35#include "hda_local.h"
36
Matt4e550962005-07-04 17:51:39 +020037#define NUM_CONTROL_ALLOC 32
38#define STAC_HP_EVENT 0x37
39#define STAC_UNSOL_ENABLE (AC_USRSP_EN | STAC_HP_EVENT)
40
Matt Porter403d1942005-11-29 15:00:51 +010041#define STAC_REF 0
42#define STAC_D945GTP3 1
43#define STAC_D945GTP5 2
44
Matt2f2f4252005-04-13 14:45:30 +020045struct sigmatel_spec {
Takashi Iwaic8b6bf92005-11-17 14:57:47 +010046 struct snd_kcontrol_new *mixers[4];
Mattc7d4b2f2005-06-27 14:59:41 +020047 unsigned int num_mixers;
48
Matt Porter403d1942005-11-29 15:00:51 +010049 int board_config;
Mattc7d4b2f2005-06-27 14:59:41 +020050 unsigned int surr_switch: 1;
Matt Porter403d1942005-11-29 15:00:51 +010051 unsigned int line_switch: 1;
52 unsigned int mic_switch: 1;
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 Iwaic8b6bf92005-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 Iwaic8b6bf92005-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 Iwaic8b6bf92005-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 Iwaic8b6bf92005-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 Iwaic8b6bf92005-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 Iwaic8b6bf92005-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 Iwaic8b6bf92005-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),
Matt2f2f4252005-04-13 14:45:30 +0200186 HDA_CODEC_VOLUME("Mux Capture Volume", 0x12, 0x0, HDA_OUTPUT),
187 { } /* end */
188};
189
Matt2f2f4252005-04-13 14:45:30 +0200190static int stac92xx_build_controls(struct hda_codec *codec)
191{
192 struct sigmatel_spec *spec = codec->spec;
193 int err;
Mattc7d4b2f2005-06-27 14:59:41 +0200194 int i;
Matt2f2f4252005-04-13 14:45:30 +0200195
196 err = snd_hda_add_new_ctls(codec, spec->mixer);
197 if (err < 0)
198 return err;
Mattc7d4b2f2005-06-27 14:59:41 +0200199
200 for (i = 0; i < spec->num_mixers; i++) {
201 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
202 if (err < 0)
203 return err;
204 }
205
Mattdabbed62005-06-14 10:19:34 +0200206 if (spec->multiout.dig_out_nid) {
207 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
208 if (err < 0)
209 return err;
210 }
211 if (spec->dig_in_nid) {
212 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
213 if (err < 0)
214 return err;
215 }
216 return 0;
Matt2f2f4252005-04-13 14:45:30 +0200217}
218
Matt Porter403d1942005-11-29 15:00:51 +0100219static unsigned int ref9200_pin_configs[8] = {
Mattdabbed62005-06-14 10:19:34 +0200220 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
Matt2f2f4252005-04-13 14:45:30 +0200221 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
222};
223
Matt Porter403d1942005-11-29 15:00:51 +0100224static unsigned int *stac9200_brd_tbl[] = {
225 ref9200_pin_configs,
226};
227
228static struct hda_board_config stac9200_cfg_tbl[] = {
229 { .modelname = "ref",
230 .pci_subvendor = PCI_VENDOR_ID_INTEL,
231 .pci_subdevice = 0x2668, /* DFI LanParty */
232 .config = STAC_REF },
233 {} /* terminator */
234};
235
236static unsigned int ref922x_pin_configs[10] = {
237 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
238 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
Matt2f2f4252005-04-13 14:45:30 +0200239 0x40000100, 0x40000100,
240};
241
Matt Porter403d1942005-11-29 15:00:51 +0100242static unsigned int d945gtp3_pin_configs[10] = {
243 0x0221401f, 0x01a19022, 0x01813021, 0x01114010,
244 0x40000100, 0x40000100, 0x40000100, 0x40000100,
245 0x02a19120, 0x40000100,
246};
247
248static unsigned int d945gtp5_pin_configs[10] = {
249 0x0221401f, 0x01111012, 0x01813024, 0x01114010,
250 0x01a19021, 0x01116011, 0x01452130, 0x40000100,
251 0x02a19320, 0x40000100,
252};
253
254static unsigned int *stac922x_brd_tbl[] = {
255 ref922x_pin_configs,
256 d945gtp3_pin_configs,
257 d945gtp5_pin_configs,
258};
259
260static struct hda_board_config stac922x_cfg_tbl[] = {
261 { .modelname = "ref",
262 .pci_subvendor = PCI_VENDOR_ID_INTEL,
263 .pci_subdevice = 0x2668, /* DFI LanParty */
264 .config = STAC_REF }, /* SigmaTel reference board */
265 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
266 .pci_subdevice = 0x0101,
267 .config = STAC_D945GTP3 }, /* Intel D945GTP - 3 Stack */
268 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
269 .pci_subdevice = 0x0404,
270 .config = STAC_D945GTP5 }, /* Intel D945GTP - 5 Stack */
271 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
272 .pci_subdevice = 0x0303,
273 .config = STAC_D945GTP5 }, /* Intel D945GNT - 5 Stack */
274 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
275 .pci_subdevice = 0x0013,
276 .config = STAC_D945GTP5 }, /* Intel D955XBK - 5 Stack */
277 {} /* terminator */
278};
279
Matt2f2f4252005-04-13 14:45:30 +0200280static void stac92xx_set_config_regs(struct hda_codec *codec)
281{
282 int i;
283 struct sigmatel_spec *spec = codec->spec;
284 unsigned int pin_cfg;
285
286 for (i=0; i < spec->num_pins; i++) {
287 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
288 AC_VERB_SET_CONFIG_DEFAULT_BYTES_0,
289 spec->pin_configs[i] & 0x000000ff);
290 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
291 AC_VERB_SET_CONFIG_DEFAULT_BYTES_1,
292 (spec->pin_configs[i] & 0x0000ff00) >> 8);
293 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
294 AC_VERB_SET_CONFIG_DEFAULT_BYTES_2,
295 (spec->pin_configs[i] & 0x00ff0000) >> 16);
296 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
297 AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
298 spec->pin_configs[i] >> 24);
299 pin_cfg = snd_hda_codec_read(codec, spec->pin_nids[i], 0,
300 AC_VERB_GET_CONFIG_DEFAULT,
301 0x00);
Matt Porter403d1942005-11-29 15:00:51 +0100302 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 +0200303 }
304}
Matt2f2f4252005-04-13 14:45:30 +0200305
Matt2f2f4252005-04-13 14:45:30 +0200306/*
307 * Analog playback callbacks
308 */
309static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
310 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100311 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200312{
313 struct sigmatel_spec *spec = codec->spec;
314 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
315}
316
317static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
318 struct hda_codec *codec,
319 unsigned int stream_tag,
320 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100321 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200322{
323 struct sigmatel_spec *spec = codec->spec;
Matt Porter403d1942005-11-29 15:00:51 +0100324 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
Matt2f2f4252005-04-13 14:45:30 +0200325}
326
327static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
328 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100329 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200330{
331 struct sigmatel_spec *spec = codec->spec;
332 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
333}
334
335/*
Mattdabbed62005-06-14 10:19:34 +0200336 * Digital playback callbacks
337 */
338static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
339 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100340 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +0200341{
342 struct sigmatel_spec *spec = codec->spec;
343 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
344}
345
346static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
347 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100348 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +0200349{
350 struct sigmatel_spec *spec = codec->spec;
351 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
352}
353
354
355/*
Matt2f2f4252005-04-13 14:45:30 +0200356 * Analog capture callbacks
357 */
358static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
359 struct hda_codec *codec,
360 unsigned int stream_tag,
361 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100362 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200363{
364 struct sigmatel_spec *spec = codec->spec;
365
366 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
367 stream_tag, 0, format);
368 return 0;
369}
370
371static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
372 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100373 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200374{
375 struct sigmatel_spec *spec = codec->spec;
376
377 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 0, 0, 0);
378 return 0;
379}
380
Mattdabbed62005-06-14 10:19:34 +0200381static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
382 .substreams = 1,
383 .channels_min = 2,
384 .channels_max = 2,
385 /* NID is set in stac92xx_build_pcms */
386 .ops = {
387 .open = stac92xx_dig_playback_pcm_open,
388 .close = stac92xx_dig_playback_pcm_close
389 },
390};
391
392static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
393 .substreams = 1,
394 .channels_min = 2,
395 .channels_max = 2,
396 /* NID is set in stac92xx_build_pcms */
397};
398
Matt2f2f4252005-04-13 14:45:30 +0200399static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
400 .substreams = 1,
401 .channels_min = 2,
Mattc7d4b2f2005-06-27 14:59:41 +0200402 .channels_max = 8,
Matt2f2f4252005-04-13 14:45:30 +0200403 .nid = 0x02, /* NID to query formats and rates */
404 .ops = {
405 .open = stac92xx_playback_pcm_open,
406 .prepare = stac92xx_playback_pcm_prepare,
407 .cleanup = stac92xx_playback_pcm_cleanup
408 },
409};
410
411static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
412 .substreams = 2,
413 .channels_min = 2,
414 .channels_max = 2,
415 .nid = 0x06, /* NID to query formats and rates */
416 .ops = {
417 .prepare = stac92xx_capture_pcm_prepare,
418 .cleanup = stac92xx_capture_pcm_cleanup
419 },
420};
421
422static int stac92xx_build_pcms(struct hda_codec *codec)
423{
424 struct sigmatel_spec *spec = codec->spec;
425 struct hda_pcm *info = spec->pcm_rec;
426
427 codec->num_pcms = 1;
428 codec->pcm_info = info;
429
Mattc7d4b2f2005-06-27 14:59:41 +0200430 info->name = "STAC92xx Analog";
Matt2f2f4252005-04-13 14:45:30 +0200431 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
Matt2f2f4252005-04-13 14:45:30 +0200432 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
Matt2f2f4252005-04-13 14:45:30 +0200433
Mattdabbed62005-06-14 10:19:34 +0200434 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
435 codec->num_pcms++;
436 info++;
437 info->name = "STAC92xx Digital";
438 if (spec->multiout.dig_out_nid) {
439 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
440 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
441 }
442 if (spec->dig_in_nid) {
443 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
444 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
445 }
446 }
447
Matt2f2f4252005-04-13 14:45:30 +0200448 return 0;
449}
450
Matt Porter403d1942005-11-29 15:00:51 +0100451static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
452
453{
454 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
455}
456
457static int stac92xx_io_switch_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
458{
459 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
460 uinfo->count = 1;
461 uinfo->value.integer.min = 0;
462 uinfo->value.integer.max = 1;
463 return 0;
464}
465
466static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
467{
468 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
469 struct sigmatel_spec *spec = codec->spec;
470 int io_idx = kcontrol-> private_value & 0xff;
471
472 ucontrol->value.integer.value[0] = spec->io_switch[io_idx];
473 return 0;
474}
475
476static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
477{
478 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
479 struct sigmatel_spec *spec = codec->spec;
480 hda_nid_t nid = kcontrol->private_value >> 8;
481 int io_idx = kcontrol-> private_value & 0xff;
482 unsigned short val = ucontrol->value.integer.value[0];
483
484 spec->io_switch[io_idx] = val;
485
486 if (val)
487 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
488 else
489 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_IN_EN);
490
491 return 1;
492}
493
494#define STAC_CODEC_IO_SWITCH(xname, xpval) \
495 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
496 .name = xname, \
497 .index = 0, \
498 .info = stac92xx_io_switch_info, \
499 .get = stac92xx_io_switch_get, \
500 .put = stac92xx_io_switch_put, \
501 .private_value = xpval, \
502 }
503
504
Mattc7d4b2f2005-06-27 14:59:41 +0200505enum {
506 STAC_CTL_WIDGET_VOL,
507 STAC_CTL_WIDGET_MUTE,
Matt Porter403d1942005-11-29 15:00:51 +0100508 STAC_CTL_WIDGET_IO_SWITCH,
Mattc7d4b2f2005-06-27 14:59:41 +0200509};
510
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100511static struct snd_kcontrol_new stac92xx_control_templates[] = {
Mattc7d4b2f2005-06-27 14:59:41 +0200512 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
513 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Matt Porter403d1942005-11-29 15:00:51 +0100514 STAC_CODEC_IO_SWITCH(NULL, 0),
Mattc7d4b2f2005-06-27 14:59:41 +0200515};
516
517/* add dynamic controls */
518static int stac92xx_add_control(struct sigmatel_spec *spec, int type, const char *name, unsigned long val)
519{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100520 struct snd_kcontrol_new *knew;
Mattc7d4b2f2005-06-27 14:59:41 +0200521
522 if (spec->num_kctl_used >= spec->num_kctl_alloc) {
523 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
524
525 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */
526 if (! knew)
527 return -ENOMEM;
528 if (spec->kctl_alloc) {
529 memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
530 kfree(spec->kctl_alloc);
531 }
532 spec->kctl_alloc = knew;
533 spec->num_kctl_alloc = num;
534 }
535
536 knew = &spec->kctl_alloc[spec->num_kctl_used];
537 *knew = stac92xx_control_templates[type];
Takashi Iwai82fe0c52005-06-30 10:54:33 +0200538 knew->name = kstrdup(name, GFP_KERNEL);
Mattc7d4b2f2005-06-27 14:59:41 +0200539 if (! knew->name)
540 return -ENOMEM;
541 knew->private_value = val;
542 spec->num_kctl_used++;
543 return 0;
544}
545
Matt Porter403d1942005-11-29 15:00:51 +0100546/* flag inputs as additional dynamic lineouts */
547static int stac92xx_add_dyn_out_pins(struct hda_codec *codec, struct auto_pin_cfg *cfg)
548{
549 struct sigmatel_spec *spec = codec->spec;
550
551 switch (cfg->line_outs) {
552 case 3:
553 /* add line-in as side */
554 if (cfg->input_pins[AUTO_PIN_LINE]) {
555 cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_LINE];
556 spec->line_switch = 1;
557 cfg->line_outs++;
558 }
559 break;
560 case 2:
561 /* add line-in as clfe and mic as side */
562 if (cfg->input_pins[AUTO_PIN_LINE]) {
563 cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_LINE];
564 spec->line_switch = 1;
565 cfg->line_outs++;
566 }
567 if (cfg->input_pins[AUTO_PIN_MIC]) {
568 cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_MIC];
569 spec->mic_switch = 1;
570 cfg->line_outs++;
571 }
572 break;
573 case 1:
574 /* add line-in as surr and mic as clfe */
575 if (cfg->input_pins[AUTO_PIN_LINE]) {
576 cfg->line_out_pins[1] = cfg->input_pins[AUTO_PIN_LINE];
577 spec->line_switch = 1;
578 cfg->line_outs++;
579 }
580 if (cfg->input_pins[AUTO_PIN_MIC]) {
581 cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_MIC];
582 spec->mic_switch = 1;
583 cfg->line_outs++;
584 }
585 break;
586 }
587
588 return 0;
589}
590
Mattc7d4b2f2005-06-27 14:59:41 +0200591/* fill in the dac_nids table from the parsed pin configuration */
592static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
593{
594 struct sigmatel_spec *spec = codec->spec;
595 hda_nid_t nid;
596 int i;
597
598 /* check the pins hardwired to audio widget */
599 for (i = 0; i < cfg->line_outs; i++) {
600 nid = cfg->line_out_pins[i];
601 spec->multiout.dac_nids[i] = snd_hda_codec_read(codec, nid, 0,
602 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
603 }
604
605 spec->multiout.num_dacs = cfg->line_outs;
606
607 return 0;
608}
609
610/* add playback controls from the parsed DAC table */
611static int stac92xx_auto_create_multi_out_ctls(struct sigmatel_spec *spec, const struct auto_pin_cfg *cfg)
612{
613 char name[32];
614 static const char *chname[4] = { "Front", "Surround", NULL /*CLFE*/, "Side" };
615 hda_nid_t nid;
616 int i, err;
617
618 for (i = 0; i < cfg->line_outs; i++) {
Matt Porter403d1942005-11-29 15:00:51 +0100619 if (!spec->multiout.dac_nids[i])
Mattc7d4b2f2005-06-27 14:59:41 +0200620 continue;
621
622 nid = spec->multiout.dac_nids[i];
623
624 if (i == 2) {
625 /* Center/LFE */
626 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, "Center Playback Volume",
627 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT))) < 0)
628 return err;
629 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, "LFE Playback Volume",
630 HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT))) < 0)
631 return err;
632 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, "Center Playback Switch",
633 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT))) < 0)
634 return err;
635 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, "LFE Playback Switch",
636 HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT))) < 0)
637 return err;
638 } else {
639 sprintf(name, "%s Playback Volume", chname[i]);
640 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, name,
641 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
642 return err;
643 sprintf(name, "%s Playback Switch", chname[i]);
644 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, name,
645 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
646 return err;
647 }
648 }
649
Matt Porter403d1942005-11-29 15:00:51 +0100650 if (spec->line_switch)
651 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Line In as Output Switch", cfg->input_pins[AUTO_PIN_LINE] << 8)) < 0)
652 return err;
653
654 if (spec->mic_switch)
655 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Mic as Output Switch", (cfg->input_pins[AUTO_PIN_MIC] << 8) | 1)) < 0)
656 return err;
657
Mattc7d4b2f2005-06-27 14:59:41 +0200658 return 0;
659}
660
661/* add playback controls for HP output */
662static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec, struct auto_pin_cfg *cfg)
663{
664 struct sigmatel_spec *spec = codec->spec;
665 hda_nid_t pin = cfg->hp_pin;
666 hda_nid_t nid;
667 int i, err;
Matt4e550962005-07-04 17:51:39 +0200668 unsigned int wid_caps;
Mattc7d4b2f2005-06-27 14:59:41 +0200669
670 if (! pin)
671 return 0;
672
Takashi Iwai54d17402005-11-21 16:33:22 +0100673 wid_caps = get_wcaps(codec, pin);
Matt4e550962005-07-04 17:51:39 +0200674 if (wid_caps & AC_WCAP_UNSOL_CAP)
675 /* Enable unsolicited responses on the HP widget */
676 snd_hda_codec_write(codec, pin, 0,
677 AC_VERB_SET_UNSOLICITED_ENABLE,
678 STAC_UNSOL_ENABLE);
679
Mattc7d4b2f2005-06-27 14:59:41 +0200680 nid = snd_hda_codec_read(codec, pin, 0, AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
681 for (i = 0; i < cfg->line_outs; i++) {
682 if (! spec->multiout.dac_nids[i])
683 continue;
684 if (spec->multiout.dac_nids[i] == nid)
685 return 0;
686 }
687
688 spec->multiout.hp_nid = nid;
689
690 /* control HP volume/switch on the output mixer amp */
691 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, "Headphone Playback Volume",
692 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
693 return err;
694 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, "Headphone Playback Switch",
695 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
696 return err;
697
698 return 0;
699}
700
701/* create playback/capture controls for input pins */
702static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
703{
704 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +0200705 struct hda_input_mux *imux = &spec->private_imux;
706 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
707 int i, j, k;
708
709 for (i = 0; i < AUTO_PIN_LAST; i++) {
710 int index = -1;
711 if (cfg->input_pins[i]) {
Matt Porter403d1942005-11-29 15:00:51 +0100712 /* Enable active pin widget as an input */
713 stac92xx_auto_set_pinctl(codec, cfg->input_pins[i], AC_PINCTL_IN_EN);
714
Takashi Iwai4a471b72005-12-07 13:56:29 +0100715 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
Mattc7d4b2f2005-06-27 14:59:41 +0200716
717 for (j=0; j<spec->num_muxes; j++) {
718 int num_cons = snd_hda_get_connections(codec, spec->mux_nids[j], con_lst, HDA_MAX_NUM_INPUTS);
719 for (k=0; k<num_cons; k++)
720 if (con_lst[k] == cfg->input_pins[i]) {
721 index = k;
722 break;
723 }
724 if (index >= 0)
725 break;
726 }
727 imux->items[imux->num_items].index = index;
728 imux->num_items++;
729 }
730 }
731
732 return 0;
733}
734
Mattc7d4b2f2005-06-27 14:59:41 +0200735static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
736{
737 struct sigmatel_spec *spec = codec->spec;
738 int i;
739
740 for (i = 0; i < spec->autocfg.line_outs; i++) {
741 hda_nid_t nid = spec->autocfg.line_out_pins[i];
742 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
743 }
744}
745
746static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
747{
748 struct sigmatel_spec *spec = codec->spec;
749 hda_nid_t pin;
750
751 pin = spec->autocfg.hp_pin;
752 if (pin) /* connect to front */
753 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
754}
755
756static int stac922x_parse_auto_config(struct hda_codec *codec)
757{
758 struct sigmatel_spec *spec = codec->spec;
759 int err;
760
Kailang Yangdf694da2005-12-05 19:42:22 +0100761 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +0200762 return err;
Matt Porter403d1942005-11-29 15:00:51 +0100763 if ((err = stac92xx_add_dyn_out_pins(codec, &spec->autocfg)) < 0)
764 return err;
Mattc7d4b2f2005-06-27 14:59:41 +0200765 if ((err = stac92xx_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
766 return err;
767 if (! spec->autocfg.line_outs && ! spec->autocfg.hp_pin)
768 return 0; /* can't find valid pin config */
769
770 if ((err = stac92xx_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
771 (err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg)) < 0 ||
772 (err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
773 return err;
774
775 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Matt Porter403d1942005-11-29 15:00:51 +0100776 if (spec->multiout.max_channels > 2)
Mattc7d4b2f2005-06-27 14:59:41 +0200777 spec->surr_switch = 1;
Mattc7d4b2f2005-06-27 14:59:41 +0200778
779 if (spec->autocfg.dig_out_pin) {
780 spec->multiout.dig_out_nid = 0x08;
781 stac92xx_auto_set_pinctl(codec, spec->autocfg.dig_out_pin, AC_PINCTL_OUT_EN);
782 }
783 if (spec->autocfg.dig_in_pin) {
784 spec->dig_in_nid = 0x09;
785 stac92xx_auto_set_pinctl(codec, spec->autocfg.dig_in_pin, AC_PINCTL_IN_EN);
786 }
787
788 if (spec->kctl_alloc)
789 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
790
791 spec->input_mux = &spec->private_imux;
792
793 return 1;
794}
795
796static int stac9200_parse_auto_config(struct hda_codec *codec)
797{
798 struct sigmatel_spec *spec = codec->spec;
799 int err;
800
Kailang Yangdf694da2005-12-05 19:42:22 +0100801 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +0200802 return err;
803
804 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
805 return err;
806
807 if (spec->autocfg.dig_out_pin) {
808 spec->multiout.dig_out_nid = 0x05;
809 stac92xx_auto_set_pinctl(codec, spec->autocfg.dig_out_pin, AC_PINCTL_OUT_EN);
810 }
811 if (spec->autocfg.dig_in_pin) {
812 spec->dig_in_nid = 0x04;
813 stac92xx_auto_set_pinctl(codec, spec->autocfg.dig_in_pin, AC_PINCTL_IN_EN);
814 }
815
816 if (spec->kctl_alloc)
817 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
818
819 spec->input_mux = &spec->private_imux;
820
821 return 1;
822}
823
Mattc7d4b2f2005-06-27 14:59:41 +0200824static int stac92xx_init(struct hda_codec *codec)
825{
826 struct sigmatel_spec *spec = codec->spec;
827
Mattc7d4b2f2005-06-27 14:59:41 +0200828 snd_hda_sequence_write(codec, spec->init);
829
830 stac92xx_auto_init_multi_out(codec);
831 stac92xx_auto_init_hp_out(codec);
832
833 return 0;
834}
835
Matt2f2f4252005-04-13 14:45:30 +0200836static void stac92xx_free(struct hda_codec *codec)
837{
Mattc7d4b2f2005-06-27 14:59:41 +0200838 struct sigmatel_spec *spec = codec->spec;
839 int i;
840
841 if (! spec)
842 return;
843
844 if (spec->kctl_alloc) {
845 for (i = 0; i < spec->num_kctl_used; i++)
846 kfree(spec->kctl_alloc[i].name);
847 kfree(spec->kctl_alloc);
848 }
849
850 kfree(spec);
Matt2f2f4252005-04-13 14:45:30 +0200851}
852
Matt4e550962005-07-04 17:51:39 +0200853static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
854 unsigned int flag)
855{
856 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
857 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
858 snd_hda_codec_write(codec, nid, 0,
859 AC_VERB_SET_PIN_WIDGET_CONTROL,
860 pin_ctl | flag);
861}
862
863static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
864 unsigned int flag)
865{
866 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
867 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
868 snd_hda_codec_write(codec, nid, 0,
869 AC_VERB_SET_PIN_WIDGET_CONTROL,
870 pin_ctl & ~flag);
871}
872
873static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
874{
875 struct sigmatel_spec *spec = codec->spec;
876 struct auto_pin_cfg *cfg = &spec->autocfg;
877 int i, presence;
878
879 if ((res >> 26) != STAC_HP_EVENT)
880 return;
881
882 presence = snd_hda_codec_read(codec, cfg->hp_pin, 0,
883 AC_VERB_GET_PIN_SENSE, 0x00) >> 31;
884
885 if (presence) {
886 /* disable lineouts, enable hp */
887 for (i = 0; i < cfg->line_outs; i++)
888 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
889 AC_PINCTL_OUT_EN);
890 stac92xx_set_pinctl(codec, cfg->hp_pin, AC_PINCTL_OUT_EN);
891 } else {
892 /* enable lineouts, disable hp */
893 for (i = 0; i < cfg->line_outs; i++)
894 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
895 AC_PINCTL_OUT_EN);
896 stac92xx_reset_pinctl(codec, cfg->hp_pin, AC_PINCTL_OUT_EN);
897 }
898}
899
Mattff6fdc32005-06-27 15:06:52 +0200900#ifdef CONFIG_PM
901static int stac92xx_resume(struct hda_codec *codec)
902{
903 struct sigmatel_spec *spec = codec->spec;
904 int i;
905
906 stac92xx_init(codec);
907 for (i = 0; i < spec->num_mixers; i++)
908 snd_hda_resume_ctls(codec, spec->mixers[i]);
909 if (spec->multiout.dig_out_nid)
910 snd_hda_resume_spdif_out(codec);
911 if (spec->dig_in_nid)
912 snd_hda_resume_spdif_in(codec);
913
914 return 0;
915}
916#endif
917
Matt2f2f4252005-04-13 14:45:30 +0200918static struct hda_codec_ops stac92xx_patch_ops = {
919 .build_controls = stac92xx_build_controls,
920 .build_pcms = stac92xx_build_pcms,
921 .init = stac92xx_init,
922 .free = stac92xx_free,
Matt4e550962005-07-04 17:51:39 +0200923 .unsol_event = stac92xx_unsol_event,
Mattff6fdc32005-06-27 15:06:52 +0200924#ifdef CONFIG_PM
925 .resume = stac92xx_resume,
926#endif
Matt2f2f4252005-04-13 14:45:30 +0200927};
928
929static int patch_stac9200(struct hda_codec *codec)
930{
931 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +0200932 int err;
Matt2f2f4252005-04-13 14:45:30 +0200933
Takashi Iwaie560d8d2005-09-09 14:21:46 +0200934 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +0200935 if (spec == NULL)
936 return -ENOMEM;
937
938 codec->spec = spec;
Matt Porter403d1942005-11-29 15:00:51 +0100939 spec->board_config = snd_hda_check_board_config(codec, stac9200_cfg_tbl);
940 if (spec->board_config < 0)
941 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9200, using BIOS defaults\n");
942 else {
943 spec->num_pins = 8;
944 spec->pin_nids = stac9200_pin_nids;
945 spec->pin_configs = stac9200_brd_tbl[spec->board_config];
946 stac92xx_set_config_regs(codec);
947 }
Matt2f2f4252005-04-13 14:45:30 +0200948
949 spec->multiout.max_channels = 2;
950 spec->multiout.num_dacs = 1;
951 spec->multiout.dac_nids = stac9200_dac_nids;
952 spec->adc_nids = stac9200_adc_nids;
953 spec->mux_nids = stac9200_mux_nids;
Mattdabbed62005-06-14 10:19:34 +0200954 spec->num_muxes = 1;
Mattc7d4b2f2005-06-27 14:59:41 +0200955
956 spec->init = stac9200_core_init;
Matt2f2f4252005-04-13 14:45:30 +0200957 spec->mixer = stac9200_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +0200958
959 err = stac9200_parse_auto_config(codec);
960 if (err < 0) {
961 stac92xx_free(codec);
962 return err;
963 }
Matt2f2f4252005-04-13 14:45:30 +0200964
965 codec->patch_ops = stac92xx_patch_ops;
966
967 return 0;
968}
969
970static int patch_stac922x(struct hda_codec *codec)
971{
972 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +0200973 int err;
Matt2f2f4252005-04-13 14:45:30 +0200974
Takashi Iwaie560d8d2005-09-09 14:21:46 +0200975 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +0200976 if (spec == NULL)
977 return -ENOMEM;
978
979 codec->spec = spec;
Matt Porter403d1942005-11-29 15:00:51 +0100980 spec->board_config = snd_hda_check_board_config(codec, stac922x_cfg_tbl);
981 if (spec->board_config < 0)
982 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC922x, using BIOS defaults\n");
983 else {
984 spec->num_pins = 10;
985 spec->pin_nids = stac922x_pin_nids;
986 spec->pin_configs = stac922x_brd_tbl[spec->board_config];
987 stac92xx_set_config_regs(codec);
988 }
Matt2f2f4252005-04-13 14:45:30 +0200989
Matt2f2f4252005-04-13 14:45:30 +0200990 spec->adc_nids = stac922x_adc_nids;
991 spec->mux_nids = stac922x_mux_nids;
Mattdabbed62005-06-14 10:19:34 +0200992 spec->num_muxes = 2;
Mattc7d4b2f2005-06-27 14:59:41 +0200993
994 spec->init = stac922x_core_init;
Matt2f2f4252005-04-13 14:45:30 +0200995 spec->mixer = stac922x_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +0200996
997 spec->multiout.dac_nids = spec->dac_nids;
998
999 err = stac922x_parse_auto_config(codec);
1000 if (err < 0) {
1001 stac92xx_free(codec);
1002 return err;
1003 }
Matt2f2f4252005-04-13 14:45:30 +02001004
1005 codec->patch_ops = stac92xx_patch_ops;
1006
1007 return 0;
1008}
1009
1010/*
1011 * patch entries
1012 */
1013struct hda_codec_preset snd_hda_preset_sigmatel[] = {
1014 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
1015 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
1016 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
1017 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
1018 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
1019 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
1020 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
1021 {} /* terminator */
1022};