blob: 239ae3fad05408a7fc0fb3cf5920bcd3e474c89e [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
Sam Revitch62fe78e2006-05-10 15:09:17 +020044#define STAC_MACMINI 3
Takashi Iwai19039bd2006-06-28 15:52:16 +020045#define STAC_D965_2112 4
46#define STAC_D965_284B 5
47#define STAC_922X_MODELS 6 /* number of 922x models */
Matt Porter403d1942005-11-29 15:00:51 +010048
Matt2f2f4252005-04-13 14:45:30 +020049struct sigmatel_spec {
Takashi Iwaic8b6bf92005-11-17 14:57:47 +010050 struct snd_kcontrol_new *mixers[4];
Mattc7d4b2f2005-06-27 14:59:41 +020051 unsigned int num_mixers;
52
Matt Porter403d1942005-11-29 15:00:51 +010053 int board_config;
Mattc7d4b2f2005-06-27 14:59:41 +020054 unsigned int surr_switch: 1;
Matt Porter403d1942005-11-29 15:00:51 +010055 unsigned int line_switch: 1;
56 unsigned int mic_switch: 1;
Matt Porter3cc08dc2006-01-23 15:27:49 +010057 unsigned int alt_switch: 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +010058 unsigned int hp_detect: 1;
Sam Revitch62fe78e2006-05-10 15:09:17 +020059 unsigned int gpio_mute: 1;
Mattc7d4b2f2005-06-27 14:59:41 +020060
Matt2f2f4252005-04-13 14:45:30 +020061 /* playback */
62 struct hda_multi_out multiout;
Matt Porter3cc08dc2006-01-23 15:27:49 +010063 hda_nid_t dac_nids[5];
Matt2f2f4252005-04-13 14:45:30 +020064
65 /* capture */
66 hda_nid_t *adc_nids;
Matt2f2f4252005-04-13 14:45:30 +020067 unsigned int num_adcs;
Mattdabbed62005-06-14 10:19:34 +020068 hda_nid_t *mux_nids;
69 unsigned int num_muxes;
Mattdabbed62005-06-14 10:19:34 +020070 hda_nid_t dig_in_nid;
Matt2f2f4252005-04-13 14:45:30 +020071
Matt2f2f4252005-04-13 14:45:30 +020072 /* pin widgets */
73 hda_nid_t *pin_nids;
74 unsigned int num_pins;
Matt2f2f4252005-04-13 14:45:30 +020075 unsigned int *pin_configs;
Richard Fish11b44bb2006-08-23 18:31:34 +020076 unsigned int *bios_pin_configs;
Matt2f2f4252005-04-13 14:45:30 +020077
78 /* codec specific stuff */
79 struct hda_verb *init;
Takashi Iwaic8b6bf92005-11-17 14:57:47 +010080 struct snd_kcontrol_new *mixer;
Matt2f2f4252005-04-13 14:45:30 +020081
82 /* capture source */
Mattc7d4b2f2005-06-27 14:59:41 +020083 struct hda_input_mux *input_mux;
Matt Porter3cc08dc2006-01-23 15:27:49 +010084 unsigned int cur_mux[3];
Matt2f2f4252005-04-13 14:45:30 +020085
Matt Porter403d1942005-11-29 15:00:51 +010086 /* i/o switches */
87 unsigned int io_switch[2];
Matt2f2f4252005-04-13 14:45:30 +020088
Mattc7d4b2f2005-06-27 14:59:41 +020089 struct hda_pcm pcm_rec[2]; /* PCM information */
90
91 /* dynamic controls and input_mux */
92 struct auto_pin_cfg autocfg;
93 unsigned int num_kctl_alloc, num_kctl_used;
Takashi Iwaic8b6bf92005-11-17 14:57:47 +010094 struct snd_kcontrol_new *kctl_alloc;
Mattc7d4b2f2005-06-27 14:59:41 +020095 struct hda_input_mux private_imux;
Matt2f2f4252005-04-13 14:45:30 +020096};
97
98static hda_nid_t stac9200_adc_nids[1] = {
99 0x03,
100};
101
102static hda_nid_t stac9200_mux_nids[1] = {
103 0x0c,
104};
105
106static hda_nid_t stac9200_dac_nids[1] = {
107 0x02,
108};
109
Matt2f2f4252005-04-13 14:45:30 +0200110static hda_nid_t stac922x_adc_nids[2] = {
111 0x06, 0x07,
112};
113
Takashi Iwai19039bd2006-06-28 15:52:16 +0200114static hda_nid_t stac9227_adc_nids[2] = {
115 0x07, 0x08,
116};
117
118#if 0
119static hda_nid_t d965_2112_dac_nids[3] = {
120 0x02, 0x03, 0x05,
121};
122#endif
123
Matt2f2f4252005-04-13 14:45:30 +0200124static hda_nid_t stac922x_mux_nids[2] = {
125 0x12, 0x13,
126};
127
Takashi Iwai19039bd2006-06-28 15:52:16 +0200128static hda_nid_t stac9227_mux_nids[2] = {
129 0x15, 0x16,
130};
131
Matt Porter3cc08dc2006-01-23 15:27:49 +0100132static hda_nid_t stac927x_adc_nids[3] = {
133 0x07, 0x08, 0x09
134};
135
136static hda_nid_t stac927x_mux_nids[3] = {
137 0x15, 0x16, 0x17
138};
139
Matt Porterf3302a52006-07-31 12:49:34 +0200140static hda_nid_t stac9205_adc_nids[2] = {
141 0x12, 0x13
142};
143
144static hda_nid_t stac9205_mux_nids[2] = {
145 0x19, 0x1a
146};
147
Mattc7d4b2f2005-06-27 14:59:41 +0200148static hda_nid_t stac9200_pin_nids[8] = {
149 0x08, 0x09, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12,
Matt2f2f4252005-04-13 14:45:30 +0200150};
151
152static hda_nid_t stac922x_pin_nids[10] = {
153 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
154 0x0f, 0x10, 0x11, 0x15, 0x1b,
155};
156
Matt Porter3cc08dc2006-01-23 15:27:49 +0100157static hda_nid_t stac927x_pin_nids[14] = {
158 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
159 0x0f, 0x10, 0x11, 0x12, 0x13,
160 0x14, 0x21, 0x22, 0x23,
161};
162
Matt Porterf3302a52006-07-31 12:49:34 +0200163static hda_nid_t stac9205_pin_nids[12] = {
164 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
165 0x0f, 0x14, 0x16, 0x17, 0x18,
166 0x21, 0x22,
167
168};
169
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100170static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Matt2f2f4252005-04-13 14:45:30 +0200171{
172 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
173 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +0200174 return snd_hda_input_mux_info(spec->input_mux, uinfo);
Matt2f2f4252005-04-13 14:45:30 +0200175}
176
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100177static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200178{
179 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
180 struct sigmatel_spec *spec = codec->spec;
181 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
182
183 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
184 return 0;
185}
186
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100187static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200188{
189 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
190 struct sigmatel_spec *spec = codec->spec;
191 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
192
Mattc7d4b2f2005-06-27 14:59:41 +0200193 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
Matt2f2f4252005-04-13 14:45:30 +0200194 spec->mux_nids[adc_idx], &spec->cur_mux[adc_idx]);
195}
196
Mattc7d4b2f2005-06-27 14:59:41 +0200197static struct hda_verb stac9200_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200198 /* set dac0mux for dac converter */
Mattc7d4b2f2005-06-27 14:59:41 +0200199 { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
Matt2f2f4252005-04-13 14:45:30 +0200200 {}
201};
202
Mattc7d4b2f2005-06-27 14:59:41 +0200203static struct hda_verb stac922x_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200204 /* set master volume and direct control */
Mattc7d4b2f2005-06-27 14:59:41 +0200205 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matt2f2f4252005-04-13 14:45:30 +0200206 {}
207};
208
Takashi Iwai19039bd2006-06-28 15:52:16 +0200209static struct hda_verb stac9227_core_init[] = {
210 /* set master volume and direct control */
211 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
212 /* unmute node 0x1b */
213 { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
214 {}
215};
216
217static struct hda_verb d965_2112_core_init[] = {
218 /* set master volume and direct control */
219 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
220 /* unmute node 0x1b */
221 { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
222 /* select node 0x03 as DAC */
223 { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
224 {}
225};
226
Matt Porter3cc08dc2006-01-23 15:27:49 +0100227static struct hda_verb stac927x_core_init[] = {
228 /* set master volume and direct control */
229 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
230 {}
231};
232
Matt Porterf3302a52006-07-31 12:49:34 +0200233static struct hda_verb stac9205_core_init[] = {
234 /* set master volume and direct control */
235 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
236 {}
237};
238
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100239static struct snd_kcontrol_new stac9200_mixer[] = {
Matt2f2f4252005-04-13 14:45:30 +0200240 HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
241 HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
242 {
243 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
244 .name = "Input Source",
245 .count = 1,
246 .info = stac92xx_mux_enum_info,
247 .get = stac92xx_mux_enum_get,
248 .put = stac92xx_mux_enum_put,
249 },
250 HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
251 HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
Mattc7d4b2f2005-06-27 14:59:41 +0200252 HDA_CODEC_VOLUME("Capture Mux Volume", 0x0c, 0, HDA_OUTPUT),
Matt2f2f4252005-04-13 14:45:30 +0200253 { } /* end */
254};
255
Mattc7d4b2f2005-06-27 14:59:41 +0200256/* This needs to be generated dynamically based on sequence */
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100257static struct snd_kcontrol_new stac922x_mixer[] = {
Matt2f2f4252005-04-13 14:45:30 +0200258 {
259 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
260 .name = "Input Source",
261 .count = 1,
262 .info = stac92xx_mux_enum_info,
263 .get = stac92xx_mux_enum_get,
264 .put = stac92xx_mux_enum_put,
265 },
266 HDA_CODEC_VOLUME("Capture Volume", 0x17, 0x0, HDA_INPUT),
Takashi Iwai0fd17082006-01-13 18:46:21 +0100267 HDA_CODEC_MUTE("Capture Switch", 0x17, 0x0, HDA_INPUT),
Matt2f2f4252005-04-13 14:45:30 +0200268 HDA_CODEC_VOLUME("Mux Capture Volume", 0x12, 0x0, HDA_OUTPUT),
269 { } /* end */
270};
271
Takashi Iwai19039bd2006-06-28 15:52:16 +0200272/* This needs to be generated dynamically based on sequence */
273static struct snd_kcontrol_new stac9227_mixer[] = {
274 {
275 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
276 .name = "Input Source",
277 .count = 1,
278 .info = stac92xx_mux_enum_info,
279 .get = stac92xx_mux_enum_get,
280 .put = stac92xx_mux_enum_put,
281 },
282 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
283 HDA_CODEC_MUTE("Capture Switch", 0x1b, 0x0, HDA_OUTPUT),
284 { } /* end */
285};
286
Matt Porter3cc08dc2006-01-23 15:27:49 +0100287static snd_kcontrol_new_t stac927x_mixer[] = {
288 {
289 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
290 .name = "Input Source",
291 .count = 1,
292 .info = stac92xx_mux_enum_info,
293 .get = stac92xx_mux_enum_get,
294 .put = stac92xx_mux_enum_put,
295 },
296 HDA_CODEC_VOLUME("InMux Capture Volume", 0x15, 0x0, HDA_OUTPUT),
297 HDA_CODEC_VOLUME("InVol Capture Volume", 0x18, 0x0, HDA_INPUT),
298 HDA_CODEC_MUTE("ADCMux Capture Switch", 0x1b, 0x0, HDA_OUTPUT),
299 { } /* end */
300};
301
Matt Porterf3302a52006-07-31 12:49:34 +0200302static snd_kcontrol_new_t stac9205_mixer[] = {
303 {
304 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
305 .name = "Input Source",
306 .count = 1,
307 .info = stac92xx_mux_enum_info,
308 .get = stac92xx_mux_enum_get,
309 .put = stac92xx_mux_enum_put,
310 },
311 HDA_CODEC_VOLUME("InMux Capture Volume", 0x19, 0x0, HDA_OUTPUT),
312 HDA_CODEC_VOLUME("InVol Capture Volume", 0x1b, 0x0, HDA_INPUT),
313 HDA_CODEC_MUTE("ADCMux Capture Switch", 0x1d, 0x0, HDA_OUTPUT),
314 { } /* end */
315};
316
Matt2f2f4252005-04-13 14:45:30 +0200317static int stac92xx_build_controls(struct hda_codec *codec)
318{
319 struct sigmatel_spec *spec = codec->spec;
320 int err;
Mattc7d4b2f2005-06-27 14:59:41 +0200321 int i;
Matt2f2f4252005-04-13 14:45:30 +0200322
323 err = snd_hda_add_new_ctls(codec, spec->mixer);
324 if (err < 0)
325 return err;
Mattc7d4b2f2005-06-27 14:59:41 +0200326
327 for (i = 0; i < spec->num_mixers; i++) {
328 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
329 if (err < 0)
330 return err;
331 }
332
Mattdabbed62005-06-14 10:19:34 +0200333 if (spec->multiout.dig_out_nid) {
334 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
335 if (err < 0)
336 return err;
337 }
338 if (spec->dig_in_nid) {
339 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
340 if (err < 0)
341 return err;
342 }
343 return 0;
Matt2f2f4252005-04-13 14:45:30 +0200344}
345
Matt Porter403d1942005-11-29 15:00:51 +0100346static unsigned int ref9200_pin_configs[8] = {
Mattdabbed62005-06-14 10:19:34 +0200347 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
Matt2f2f4252005-04-13 14:45:30 +0200348 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
349};
350
Matt Porter403d1942005-11-29 15:00:51 +0100351static unsigned int *stac9200_brd_tbl[] = {
352 ref9200_pin_configs,
353};
354
355static struct hda_board_config stac9200_cfg_tbl[] = {
356 { .modelname = "ref",
357 .pci_subvendor = PCI_VENDOR_ID_INTEL,
358 .pci_subdevice = 0x2668, /* DFI LanParty */
359 .config = STAC_REF },
360 {} /* terminator */
361};
362
363static unsigned int ref922x_pin_configs[10] = {
364 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
365 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
Matt2f2f4252005-04-13 14:45:30 +0200366 0x40000100, 0x40000100,
367};
368
Matt Porter403d1942005-11-29 15:00:51 +0100369static unsigned int d945gtp3_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +0100370 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
Matt Porter403d1942005-11-29 15:00:51 +0100371 0x40000100, 0x40000100, 0x40000100, 0x40000100,
372 0x02a19120, 0x40000100,
373};
374
375static unsigned int d945gtp5_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +0100376 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
377 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
Matt Porter403d1942005-11-29 15:00:51 +0100378 0x02a19320, 0x40000100,
379};
380
Takashi Iwai19039bd2006-06-28 15:52:16 +0200381static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
382 [STAC_REF] = ref922x_pin_configs,
383 [STAC_D945GTP3] = d945gtp3_pin_configs,
384 [STAC_D945GTP5] = d945gtp5_pin_configs,
Linus Torvalds7c3dec02006-07-10 22:21:43 -0700385 [STAC_MACMINI] = d945gtp5_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +0100386};
387
388static struct hda_board_config stac922x_cfg_tbl[] = {
389 { .modelname = "ref",
390 .pci_subvendor = PCI_VENDOR_ID_INTEL,
391 .pci_subdevice = 0x2668, /* DFI LanParty */
392 .config = STAC_REF }, /* SigmaTel reference board */
Tobin Davis948a4db2006-08-22 19:43:46 +0200393 /* Intel 945G based systems */
Matt Porter403d1942005-11-29 15:00:51 +0100394 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
395 .pci_subdevice = 0x0101,
396 .config = STAC_D945GTP3 }, /* Intel D945GTP - 3 Stack */
397 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
Takashi Iwai353b9e62006-02-16 18:16:17 +0100398 .pci_subdevice = 0x0202,
Tobin Davis948a4db2006-08-22 19:43:46 +0200399 .config = STAC_D945GTP3 }, /* Intel D945GNT - 3 Stack */
Takashi Iwai353b9e62006-02-16 18:16:17 +0100400 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
Tobin Davis948a4db2006-08-22 19:43:46 +0200401 .pci_subdevice = 0x0606,
402 .config = STAC_D945GTP3 }, /* Intel D945GTP - 3 Stack */
Takashi Iwai353b9e62006-02-16 18:16:17 +0100403 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
Tobin Davis948a4db2006-08-22 19:43:46 +0200404 .pci_subdevice = 0x0601,
405 .config = STAC_D945GTP3 }, /* Intel D945GTP - 3 Stack */
406 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
407 .pci_subdevice = 0x0111,
408 .config = STAC_D945GTP3 }, /* Intel D945GZP - 3 Stack */
409 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
410 .pci_subdevice = 0x1115,
411 .config = STAC_D945GTP3 }, /* Intel D945GPM - 3 Stack */
412 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
413 .pci_subdevice = 0x1116,
414 .config = STAC_D945GTP3 }, /* Intel D945GBO - 3 Stack */
415 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
416 .pci_subdevice = 0x1117,
417 .config = STAC_D945GTP3 }, /* Intel D945GPM - 3 Stack */
418 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
419 .pci_subdevice = 0x1118,
420 .config = STAC_D945GTP3 }, /* Intel D945GPM - 3 Stack */
421 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
422 .pci_subdevice = 0x1119,
423 .config = STAC_D945GTP3 }, /* Intel D945GPM - 3 Stack */
424 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
425 .pci_subdevice = 0x8826,
426 .config = STAC_D945GTP3 }, /* Intel D945GPM - 3 Stack */
427 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
428 .pci_subdevice = 0x5049,
429 .config = STAC_D945GTP3 }, /* Intel D945GCZ - 3 Stack */
430 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
431 .pci_subdevice = 0x5055,
432 .config = STAC_D945GTP3 }, /* Intel D945GCZ - 3 Stack */
433 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
434 .pci_subdevice = 0x5048,
435 .config = STAC_D945GTP3 }, /* Intel D945GPB - 3 Stack */
436 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
437 .pci_subdevice = 0x0110,
438 .config = STAC_D945GTP3 }, /* Intel D945GLR - 3 Stack */
439 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
Matt Porter403d1942005-11-29 15:00:51 +0100440 .pci_subdevice = 0x0404,
441 .config = STAC_D945GTP5 }, /* Intel D945GTP - 5 Stack */
442 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
443 .pci_subdevice = 0x0303,
444 .config = STAC_D945GTP5 }, /* Intel D945GNT - 5 Stack */
445 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
446 .pci_subdevice = 0x0013,
447 .config = STAC_D945GTP5 }, /* Intel D955XBK - 5 Stack */
Matt Porterd62c40e2006-01-23 15:26:27 +0100448 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
449 .pci_subdevice = 0x0417,
450 .config = STAC_D945GTP5 }, /* Intel D975XBK - 5 Stack */
Tobin Davis948a4db2006-08-22 19:43:46 +0200451 /* Intel 945P based systems */
452 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
453 .pci_subdevice = 0x0b0b,
454 .config = STAC_D945GTP3 }, /* Intel D945PSN - 3 Stack */
455 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
456 .pci_subdevice = 0x0112,
457 .config = STAC_D945GTP3 }, /* Intel D945PLN - 3 Stack */
458 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
459 .pci_subdevice = 0x0d0d,
460 .config = STAC_D945GTP3 }, /* Intel D945PLM - 3 Stack */
461 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
462 .pci_subdevice = 0x0909,
463 .config = STAC_D945GTP3 }, /* Intel D945PAW - 3 Stack */
464 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
465 .pci_subdevice = 0x0505,
466 .config = STAC_D945GTP3 }, /* Intel D945PLM - 3 Stack */
467 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
468 .pci_subdevice = 0x0707,
469 .config = STAC_D945GTP5 }, /* Intel D945PSV - 5 Stack */
470 /* other systems */
Sam Revitch62fe78e2006-05-10 15:09:17 +0200471 { .pci_subvendor = 0x8384,
472 .pci_subdevice = 0x7680,
473 .config = STAC_MACMINI }, /* Apple Mac Mini (early 2006) */
Takashi Iwai19039bd2006-06-28 15:52:16 +0200474 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
475 .pci_subdevice = 0x2112,
476 .config = STAC_D965_2112 },
477 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
478 .pci_subdevice = 0x284b,
479 .config = STAC_D965_284B },
Matt Porter403d1942005-11-29 15:00:51 +0100480 {} /* terminator */
481};
482
Matt Porter3cc08dc2006-01-23 15:27:49 +0100483static unsigned int ref927x_pin_configs[14] = {
484 0x01813122, 0x01a19021, 0x01014010, 0x01016011,
485 0x01012012, 0x01011014, 0x40000100, 0x40000100,
486 0x40000100, 0x40000100, 0x40000100, 0x01441030,
487 0x01c41030, 0x40000100,
488};
489
Tobin Davis81d3dbd2006-08-22 19:44:45 +0200490static unsigned int d965_2112_pin_configs[14] = {
491 0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
492 0x01a19021, 0x01813024, 0x40000100, 0x40000100,
493 0x40000100, 0x40000100, 0x40000100, 0x40000100,
494 0x40000100, 0x40000100
495};
496
Matt Porter3cc08dc2006-01-23 15:27:49 +0100497static unsigned int *stac927x_brd_tbl[] = {
Tobin Davis81d3dbd2006-08-22 19:44:45 +0200498 [STAC_REF] = ref927x_pin_configs,
499 [STAC_D965_2112] = d965_2112_pin_configs,
Matt Porter3cc08dc2006-01-23 15:27:49 +0100500};
501
502static struct hda_board_config stac927x_cfg_tbl[] = {
503 { .modelname = "ref",
504 .pci_subvendor = PCI_VENDOR_ID_INTEL,
505 .pci_subdevice = 0x2668, /* DFI LanParty */
506 .config = STAC_REF }, /* SigmaTel reference board */
Tobin Davis81d3dbd2006-08-22 19:44:45 +0200507 /* SigmaTel 9227 reference board */
508 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
509 .pci_subdevice = 0x284b,
510 .config = STAC_D965_284B },
511 /* Intel 946 based systems */
512 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
513 .pci_subdevice = 0x3d01,
514 .config = STAC_D965_2112 }, /* D946 configuration */
515 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
516 .pci_subdevice = 0xa301,
517 .config = STAC_D965_2112 }, /* Intel D946GZT - 3 stack */
518 /* 965 based systems */
519 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
520 .pci_subdevice = 0x2116,
521 .config = STAC_D965_2112 }, /* Intel D965 3Stack config */
522 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
523 .pci_subdevice = 0x2115,
524 .config = STAC_D965_2112 }, /* Intel DQ965WC - 3 Stack */
525 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
526 .pci_subdevice = 0x2114,
527 .config = STAC_D965_2112 }, /* Intel D965 3Stack config */
528 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
529 .pci_subdevice = 0x2113,
530 .config = STAC_D965_2112 }, /* Intel D965 3Stack config */
531 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
532 .pci_subdevice = 0x2112,
533 .config = STAC_D965_2112 }, /* Intel DG965MS - 3 Stack */
534 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
535 .pci_subdevice = 0x2111,
536 .config = STAC_D965_2112 }, /* Intel D965 3Stack config */
537 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
538 .pci_subdevice = 0x2110,
539 .config = STAC_D965_2112 }, /* Intel D965 3Stack config */
540 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
541 .pci_subdevice = 0x2009,
542 .config = STAC_D965_2112 }, /* Intel D965 3Stack config */
543 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
544 .pci_subdevice = 0x2008,
545 .config = STAC_D965_2112 }, /* Intel DQ965GF - 3 Stack */
546 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
547 .pci_subdevice = 0x2007,
548 .config = STAC_D965_2112 }, /* Intel D965 3Stack config */
549 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
550 .pci_subdevice = 0x2006,
551 .config = STAC_D965_2112 }, /* Intel D965 3Stack config */
552 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
553 .pci_subdevice = 0x2005,
554 .config = STAC_D965_2112 }, /* Intel D965 3Stack config */
555 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
556 .pci_subdevice = 0x2004,
557 .config = STAC_D965_2112 }, /* Intel D965 3Stack config */
558 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
559 .pci_subdevice = 0x2003,
560 .config = STAC_D965_2112 }, /* Intel D965 3Stack config */
561 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
562 .pci_subdevice = 0x2002,
563 .config = STAC_D965_2112 }, /* Intel D965 3Stack config */
564 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
565 .pci_subdevice = 0x2001,
566 .config = STAC_D965_2112 }, /* Intel DQ965GF - 3 Stackg */
Matt Porter3cc08dc2006-01-23 15:27:49 +0100567 {} /* terminator */
568};
569
Matt Porterf3302a52006-07-31 12:49:34 +0200570static unsigned int ref9205_pin_configs[12] = {
571 0x40000100, 0x40000100, 0x01016011, 0x01014010,
572 0x01813122, 0x01a19021, 0x40000100, 0x40000100,
573 0x40000100, 0x40000100, 0x01441030, 0x01c41030
574};
575
576static unsigned int *stac9205_brd_tbl[] = {
577 ref9205_pin_configs,
578};
579
580static struct hda_board_config stac9205_cfg_tbl[] = {
581 { .modelname = "ref",
582 .pci_subvendor = PCI_VENDOR_ID_INTEL,
583 .pci_subdevice = 0x2668, /* DFI LanParty */
584 .config = STAC_REF }, /* SigmaTel reference board */
585 {} /* terminator */
586};
587
Richard Fish11b44bb2006-08-23 18:31:34 +0200588static int stac92xx_save_bios_config_regs(struct hda_codec *codec)
589{
590 int i;
591 struct sigmatel_spec *spec = codec->spec;
592
593 if (! spec->bios_pin_configs) {
594 spec->bios_pin_configs = kcalloc(spec->num_pins,
595 sizeof(*spec->bios_pin_configs), GFP_KERNEL);
596 if (! spec->bios_pin_configs)
597 return -ENOMEM;
598 }
599
600 for (i = 0; i < spec->num_pins; i++) {
601 hda_nid_t nid = spec->pin_nids[i];
602 unsigned int pin_cfg;
603
604 pin_cfg = snd_hda_codec_read(codec, nid, 0,
605 AC_VERB_GET_CONFIG_DEFAULT, 0x00);
606 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x bios pin config %8.8x\n",
607 nid, pin_cfg);
608 spec->bios_pin_configs[i] = pin_cfg;
609 }
610
611 return 0;
612}
613
Matt2f2f4252005-04-13 14:45:30 +0200614static void stac92xx_set_config_regs(struct hda_codec *codec)
615{
616 int i;
617 struct sigmatel_spec *spec = codec->spec;
618 unsigned int pin_cfg;
619
Richard Fish11b44bb2006-08-23 18:31:34 +0200620 if (! spec->pin_nids || ! spec->pin_configs)
621 return;
622
623 for (i = 0; i < spec->num_pins; i++) {
Matt2f2f4252005-04-13 14:45:30 +0200624 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
625 AC_VERB_SET_CONFIG_DEFAULT_BYTES_0,
626 spec->pin_configs[i] & 0x000000ff);
627 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
628 AC_VERB_SET_CONFIG_DEFAULT_BYTES_1,
629 (spec->pin_configs[i] & 0x0000ff00) >> 8);
630 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
631 AC_VERB_SET_CONFIG_DEFAULT_BYTES_2,
632 (spec->pin_configs[i] & 0x00ff0000) >> 16);
633 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
634 AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
635 spec->pin_configs[i] >> 24);
636 pin_cfg = snd_hda_codec_read(codec, spec->pin_nids[i], 0,
637 AC_VERB_GET_CONFIG_DEFAULT,
638 0x00);
Matt Porter403d1942005-11-29 15:00:51 +0100639 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 +0200640 }
641}
Matt2f2f4252005-04-13 14:45:30 +0200642
Matt2f2f4252005-04-13 14:45:30 +0200643/*
644 * Analog playback callbacks
645 */
646static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
647 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100648 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200649{
650 struct sigmatel_spec *spec = codec->spec;
651 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
652}
653
654static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
655 struct hda_codec *codec,
656 unsigned int stream_tag,
657 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100658 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200659{
660 struct sigmatel_spec *spec = codec->spec;
Matt Porter403d1942005-11-29 15:00:51 +0100661 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
Matt2f2f4252005-04-13 14:45:30 +0200662}
663
664static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
665 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100666 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200667{
668 struct sigmatel_spec *spec = codec->spec;
669 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
670}
671
672/*
Mattdabbed62005-06-14 10:19:34 +0200673 * Digital playback callbacks
674 */
675static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
676 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100677 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +0200678{
679 struct sigmatel_spec *spec = codec->spec;
680 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
681}
682
683static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
684 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100685 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +0200686{
687 struct sigmatel_spec *spec = codec->spec;
688 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
689}
690
691
692/*
Matt2f2f4252005-04-13 14:45:30 +0200693 * Analog capture callbacks
694 */
695static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
696 struct hda_codec *codec,
697 unsigned int stream_tag,
698 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100699 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200700{
701 struct sigmatel_spec *spec = codec->spec;
702
703 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
704 stream_tag, 0, format);
705 return 0;
706}
707
708static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
709 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100710 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200711{
712 struct sigmatel_spec *spec = codec->spec;
713
714 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 0, 0, 0);
715 return 0;
716}
717
Mattdabbed62005-06-14 10:19:34 +0200718static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
719 .substreams = 1,
720 .channels_min = 2,
721 .channels_max = 2,
722 /* NID is set in stac92xx_build_pcms */
723 .ops = {
724 .open = stac92xx_dig_playback_pcm_open,
725 .close = stac92xx_dig_playback_pcm_close
726 },
727};
728
729static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
730 .substreams = 1,
731 .channels_min = 2,
732 .channels_max = 2,
733 /* NID is set in stac92xx_build_pcms */
734};
735
Matt2f2f4252005-04-13 14:45:30 +0200736static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
737 .substreams = 1,
738 .channels_min = 2,
Mattc7d4b2f2005-06-27 14:59:41 +0200739 .channels_max = 8,
Matt2f2f4252005-04-13 14:45:30 +0200740 .nid = 0x02, /* NID to query formats and rates */
741 .ops = {
742 .open = stac92xx_playback_pcm_open,
743 .prepare = stac92xx_playback_pcm_prepare,
744 .cleanup = stac92xx_playback_pcm_cleanup
745 },
746};
747
Matt Porter3cc08dc2006-01-23 15:27:49 +0100748static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
749 .substreams = 1,
750 .channels_min = 2,
751 .channels_max = 2,
752 .nid = 0x06, /* NID to query formats and rates */
753 .ops = {
754 .open = stac92xx_playback_pcm_open,
755 .prepare = stac92xx_playback_pcm_prepare,
756 .cleanup = stac92xx_playback_pcm_cleanup
757 },
758};
759
Matt2f2f4252005-04-13 14:45:30 +0200760static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
761 .substreams = 2,
762 .channels_min = 2,
763 .channels_max = 2,
Matt Porter3cc08dc2006-01-23 15:27:49 +0100764 /* NID is set in stac92xx_build_pcms */
Matt2f2f4252005-04-13 14:45:30 +0200765 .ops = {
766 .prepare = stac92xx_capture_pcm_prepare,
767 .cleanup = stac92xx_capture_pcm_cleanup
768 },
769};
770
771static int stac92xx_build_pcms(struct hda_codec *codec)
772{
773 struct sigmatel_spec *spec = codec->spec;
774 struct hda_pcm *info = spec->pcm_rec;
775
776 codec->num_pcms = 1;
777 codec->pcm_info = info;
778
Mattc7d4b2f2005-06-27 14:59:41 +0200779 info->name = "STAC92xx Analog";
Matt2f2f4252005-04-13 14:45:30 +0200780 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
Matt2f2f4252005-04-13 14:45:30 +0200781 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100782 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
783
784 if (spec->alt_switch) {
785 codec->num_pcms++;
786 info++;
787 info->name = "STAC92xx Analog Alt";
788 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
789 }
Matt2f2f4252005-04-13 14:45:30 +0200790
Mattdabbed62005-06-14 10:19:34 +0200791 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
792 codec->num_pcms++;
793 info++;
794 info->name = "STAC92xx Digital";
795 if (spec->multiout.dig_out_nid) {
796 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
797 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
798 }
799 if (spec->dig_in_nid) {
800 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
801 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
802 }
803 }
804
Matt2f2f4252005-04-13 14:45:30 +0200805 return 0;
806}
807
Takashi Iwaic960a032006-03-23 17:06:28 +0100808static unsigned int stac92xx_get_vref(struct hda_codec *codec, hda_nid_t nid)
809{
810 unsigned int pincap = snd_hda_param_read(codec, nid,
811 AC_PAR_PIN_CAP);
812 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
813 if (pincap & AC_PINCAP_VREF_100)
814 return AC_PINCTL_VREF_100;
815 if (pincap & AC_PINCAP_VREF_80)
816 return AC_PINCTL_VREF_80;
817 if (pincap & AC_PINCAP_VREF_50)
818 return AC_PINCTL_VREF_50;
819 if (pincap & AC_PINCAP_VREF_GRD)
820 return AC_PINCTL_VREF_GRD;
821 return 0;
822}
823
Matt Porter403d1942005-11-29 15:00:51 +0100824static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
825
826{
827 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
828}
829
830static int stac92xx_io_switch_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
831{
832 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
833 uinfo->count = 1;
834 uinfo->value.integer.min = 0;
835 uinfo->value.integer.max = 1;
836 return 0;
837}
838
839static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
840{
841 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
842 struct sigmatel_spec *spec = codec->spec;
843 int io_idx = kcontrol-> private_value & 0xff;
844
845 ucontrol->value.integer.value[0] = spec->io_switch[io_idx];
846 return 0;
847}
848
849static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
850{
851 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
852 struct sigmatel_spec *spec = codec->spec;
853 hda_nid_t nid = kcontrol->private_value >> 8;
854 int io_idx = kcontrol-> private_value & 0xff;
855 unsigned short val = ucontrol->value.integer.value[0];
856
857 spec->io_switch[io_idx] = val;
858
859 if (val)
860 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
Takashi Iwaic960a032006-03-23 17:06:28 +0100861 else {
862 unsigned int pinctl = AC_PINCTL_IN_EN;
863 if (io_idx) /* set VREF for mic */
864 pinctl |= stac92xx_get_vref(codec, nid);
865 stac92xx_auto_set_pinctl(codec, nid, pinctl);
866 }
Matt Porter403d1942005-11-29 15:00:51 +0100867 return 1;
868}
869
870#define STAC_CODEC_IO_SWITCH(xname, xpval) \
871 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
872 .name = xname, \
873 .index = 0, \
874 .info = stac92xx_io_switch_info, \
875 .get = stac92xx_io_switch_get, \
876 .put = stac92xx_io_switch_put, \
877 .private_value = xpval, \
878 }
879
880
Mattc7d4b2f2005-06-27 14:59:41 +0200881enum {
882 STAC_CTL_WIDGET_VOL,
883 STAC_CTL_WIDGET_MUTE,
Matt Porter403d1942005-11-29 15:00:51 +0100884 STAC_CTL_WIDGET_IO_SWITCH,
Mattc7d4b2f2005-06-27 14:59:41 +0200885};
886
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100887static struct snd_kcontrol_new stac92xx_control_templates[] = {
Mattc7d4b2f2005-06-27 14:59:41 +0200888 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
889 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Matt Porter403d1942005-11-29 15:00:51 +0100890 STAC_CODEC_IO_SWITCH(NULL, 0),
Mattc7d4b2f2005-06-27 14:59:41 +0200891};
892
893/* add dynamic controls */
894static int stac92xx_add_control(struct sigmatel_spec *spec, int type, const char *name, unsigned long val)
895{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100896 struct snd_kcontrol_new *knew;
Mattc7d4b2f2005-06-27 14:59:41 +0200897
898 if (spec->num_kctl_used >= spec->num_kctl_alloc) {
899 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
900
901 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */
902 if (! knew)
903 return -ENOMEM;
904 if (spec->kctl_alloc) {
905 memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
906 kfree(spec->kctl_alloc);
907 }
908 spec->kctl_alloc = knew;
909 spec->num_kctl_alloc = num;
910 }
911
912 knew = &spec->kctl_alloc[spec->num_kctl_used];
913 *knew = stac92xx_control_templates[type];
Takashi Iwai82fe0c52005-06-30 10:54:33 +0200914 knew->name = kstrdup(name, GFP_KERNEL);
Mattc7d4b2f2005-06-27 14:59:41 +0200915 if (! knew->name)
916 return -ENOMEM;
917 knew->private_value = val;
918 spec->num_kctl_used++;
919 return 0;
920}
921
Matt Porter403d1942005-11-29 15:00:51 +0100922/* flag inputs as additional dynamic lineouts */
923static int stac92xx_add_dyn_out_pins(struct hda_codec *codec, struct auto_pin_cfg *cfg)
924{
925 struct sigmatel_spec *spec = codec->spec;
926
927 switch (cfg->line_outs) {
928 case 3:
929 /* add line-in as side */
930 if (cfg->input_pins[AUTO_PIN_LINE]) {
931 cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_LINE];
932 spec->line_switch = 1;
933 cfg->line_outs++;
934 }
935 break;
936 case 2:
937 /* add line-in as clfe and mic as side */
938 if (cfg->input_pins[AUTO_PIN_LINE]) {
939 cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_LINE];
940 spec->line_switch = 1;
941 cfg->line_outs++;
942 }
943 if (cfg->input_pins[AUTO_PIN_MIC]) {
944 cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_MIC];
945 spec->mic_switch = 1;
946 cfg->line_outs++;
947 }
948 break;
949 case 1:
950 /* add line-in as surr and mic as clfe */
951 if (cfg->input_pins[AUTO_PIN_LINE]) {
952 cfg->line_out_pins[1] = cfg->input_pins[AUTO_PIN_LINE];
953 spec->line_switch = 1;
954 cfg->line_outs++;
955 }
956 if (cfg->input_pins[AUTO_PIN_MIC]) {
957 cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_MIC];
958 spec->mic_switch = 1;
959 cfg->line_outs++;
960 }
961 break;
962 }
963
964 return 0;
965}
966
Matt Porter3cc08dc2006-01-23 15:27:49 +0100967/*
968 * XXX The line_out pin widget connection list may not be set to the
969 * desired DAC nid. This is the case on 927x where ports A and B can
970 * be routed to several DACs.
971 *
972 * This requires an analysis of the line-out/hp pin configuration
973 * to provide a best fit for pin/DAC configurations that are routable.
974 * For now, 927x DAC4 is not supported and 927x DAC1 output to ports
975 * A and B is not supported.
976 */
Mattc7d4b2f2005-06-27 14:59:41 +0200977/* fill in the dac_nids table from the parsed pin configuration */
Takashi Iwai19039bd2006-06-28 15:52:16 +0200978static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec,
979 const struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +0200980{
981 struct sigmatel_spec *spec = codec->spec;
982 hda_nid_t nid;
983 int i;
984
985 /* check the pins hardwired to audio widget */
986 for (i = 0; i < cfg->line_outs; i++) {
987 nid = cfg->line_out_pins[i];
988 spec->multiout.dac_nids[i] = snd_hda_codec_read(codec, nid, 0,
989 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
990 }
991
Takashi Iwai82bc9552006-03-21 11:24:42 +0100992 spec->multiout.num_dacs = cfg->line_outs;
Mattc7d4b2f2005-06-27 14:59:41 +0200993
994 return 0;
995}
996
997/* add playback controls from the parsed DAC table */
Takashi Iwai19039bd2006-06-28 15:52:16 +0200998static int stac92xx_auto_create_multi_out_ctls(struct sigmatel_spec *spec,
999 const struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02001000{
1001 char name[32];
Takashi Iwai19039bd2006-06-28 15:52:16 +02001002 static const char *chname[4] = {
1003 "Front", "Surround", NULL /*CLFE*/, "Side"
1004 };
Mattc7d4b2f2005-06-27 14:59:41 +02001005 hda_nid_t nid;
1006 int i, err;
1007
1008 for (i = 0; i < cfg->line_outs; i++) {
Matt Porter403d1942005-11-29 15:00:51 +01001009 if (!spec->multiout.dac_nids[i])
Mattc7d4b2f2005-06-27 14:59:41 +02001010 continue;
1011
1012 nid = spec->multiout.dac_nids[i];
1013
1014 if (i == 2) {
1015 /* Center/LFE */
1016 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, "Center Playback Volume",
1017 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT))) < 0)
1018 return err;
1019 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, "LFE Playback Volume",
1020 HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT))) < 0)
1021 return err;
1022 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, "Center Playback Switch",
1023 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT))) < 0)
1024 return err;
1025 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, "LFE Playback Switch",
1026 HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT))) < 0)
1027 return err;
1028 } else {
1029 sprintf(name, "%s Playback Volume", chname[i]);
1030 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, name,
1031 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
1032 return err;
1033 sprintf(name, "%s Playback Switch", chname[i]);
1034 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, name,
1035 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
1036 return err;
1037 }
1038 }
1039
Matt Porter403d1942005-11-29 15:00:51 +01001040 if (spec->line_switch)
1041 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Line In as Output Switch", cfg->input_pins[AUTO_PIN_LINE] << 8)) < 0)
1042 return err;
1043
1044 if (spec->mic_switch)
1045 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Mic as Output Switch", (cfg->input_pins[AUTO_PIN_MIC] << 8) | 1)) < 0)
1046 return err;
1047
Mattc7d4b2f2005-06-27 14:59:41 +02001048 return 0;
1049}
1050
1051/* add playback controls for HP output */
1052static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec, struct auto_pin_cfg *cfg)
1053{
1054 struct sigmatel_spec *spec = codec->spec;
1055 hda_nid_t pin = cfg->hp_pin;
1056 hda_nid_t nid;
1057 int i, err;
Matt4e550962005-07-04 17:51:39 +02001058 unsigned int wid_caps;
Mattc7d4b2f2005-06-27 14:59:41 +02001059
1060 if (! pin)
1061 return 0;
1062
Takashi Iwai54d17402005-11-21 16:33:22 +01001063 wid_caps = get_wcaps(codec, pin);
Takashi Iwai505cb342006-03-27 12:51:52 +02001064 if (wid_caps & AC_WCAP_UNSOL_CAP)
Takashi Iwai82bc9552006-03-21 11:24:42 +01001065 spec->hp_detect = 1;
Matt4e550962005-07-04 17:51:39 +02001066
Mattc7d4b2f2005-06-27 14:59:41 +02001067 nid = snd_hda_codec_read(codec, pin, 0, AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
1068 for (i = 0; i < cfg->line_outs; i++) {
1069 if (! spec->multiout.dac_nids[i])
1070 continue;
1071 if (spec->multiout.dac_nids[i] == nid)
1072 return 0;
1073 }
1074
1075 spec->multiout.hp_nid = nid;
1076
1077 /* control HP volume/switch on the output mixer amp */
1078 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, "Headphone Playback Volume",
1079 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
1080 return err;
1081 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, "Headphone Playback Switch",
1082 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
1083 return err;
1084
1085 return 0;
1086}
1087
1088/* create playback/capture controls for input pins */
1089static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
1090{
1091 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02001092 struct hda_input_mux *imux = &spec->private_imux;
1093 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
1094 int i, j, k;
1095
1096 for (i = 0; i < AUTO_PIN_LAST; i++) {
1097 int index = -1;
1098 if (cfg->input_pins[i]) {
Takashi Iwai4a471b72005-12-07 13:56:29 +01001099 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
Mattc7d4b2f2005-06-27 14:59:41 +02001100
1101 for (j=0; j<spec->num_muxes; j++) {
1102 int num_cons = snd_hda_get_connections(codec, spec->mux_nids[j], con_lst, HDA_MAX_NUM_INPUTS);
1103 for (k=0; k<num_cons; k++)
1104 if (con_lst[k] == cfg->input_pins[i]) {
1105 index = k;
1106 break;
1107 }
1108 if (index >= 0)
1109 break;
1110 }
1111 imux->items[imux->num_items].index = index;
1112 imux->num_items++;
1113 }
1114 }
1115
Sam Revitch62fe78e2006-05-10 15:09:17 +02001116 if (imux->num_items == 1) {
1117 /*
1118 * Set the current input for the muxes.
1119 * The STAC9221 has two input muxes with identical source
1120 * NID lists. Hopefully this won't get confused.
1121 */
1122 for (i = 0; i < spec->num_muxes; i++) {
1123 snd_hda_codec_write(codec, spec->mux_nids[i], 0,
1124 AC_VERB_SET_CONNECT_SEL,
1125 imux->items[0].index);
1126 }
1127 }
1128
Mattc7d4b2f2005-06-27 14:59:41 +02001129 return 0;
1130}
1131
Mattc7d4b2f2005-06-27 14:59:41 +02001132static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
1133{
1134 struct sigmatel_spec *spec = codec->spec;
1135 int i;
1136
1137 for (i = 0; i < spec->autocfg.line_outs; i++) {
1138 hda_nid_t nid = spec->autocfg.line_out_pins[i];
1139 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
1140 }
1141}
1142
1143static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
1144{
1145 struct sigmatel_spec *spec = codec->spec;
1146 hda_nid_t pin;
1147
1148 pin = spec->autocfg.hp_pin;
1149 if (pin) /* connect to front */
1150 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
1151}
1152
Matt Porter3cc08dc2006-01-23 15:27:49 +01001153static 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 +02001154{
1155 struct sigmatel_spec *spec = codec->spec;
1156 int err;
1157
Kailang Yangdf694da2005-12-05 19:42:22 +01001158 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001159 return err;
Takashi Iwai82bc9552006-03-21 11:24:42 +01001160 if (! spec->autocfg.line_outs)
Matt Porter869264c2006-01-25 19:20:50 +01001161 return 0; /* can't find valid pin config */
Takashi Iwai19039bd2006-06-28 15:52:16 +02001162
Matt Porter403d1942005-11-29 15:00:51 +01001163 if ((err = stac92xx_add_dyn_out_pins(codec, &spec->autocfg)) < 0)
1164 return err;
Takashi Iwai19039bd2006-06-28 15:52:16 +02001165 if (spec->multiout.num_dacs == 0)
1166 if ((err = stac92xx_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
1167 return err;
Mattc7d4b2f2005-06-27 14:59:41 +02001168
1169 if ((err = stac92xx_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
1170 (err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg)) < 0 ||
1171 (err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
1172 return err;
1173
1174 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Matt Porter403d1942005-11-29 15:00:51 +01001175 if (spec->multiout.max_channels > 2)
Mattc7d4b2f2005-06-27 14:59:41 +02001176 spec->surr_switch = 1;
Mattc7d4b2f2005-06-27 14:59:41 +02001177
Takashi Iwai82bc9552006-03-21 11:24:42 +01001178 if (spec->autocfg.dig_out_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01001179 spec->multiout.dig_out_nid = dig_out;
Takashi Iwai82bc9552006-03-21 11:24:42 +01001180 if (spec->autocfg.dig_in_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01001181 spec->dig_in_nid = dig_in;
Mattc7d4b2f2005-06-27 14:59:41 +02001182
1183 if (spec->kctl_alloc)
1184 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
1185
1186 spec->input_mux = &spec->private_imux;
1187
1188 return 1;
1189}
1190
Takashi Iwai82bc9552006-03-21 11:24:42 +01001191/* add playback controls for HP output */
1192static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
1193 struct auto_pin_cfg *cfg)
1194{
1195 struct sigmatel_spec *spec = codec->spec;
1196 hda_nid_t pin = cfg->hp_pin;
1197 unsigned int wid_caps;
1198
1199 if (! pin)
1200 return 0;
1201
1202 wid_caps = get_wcaps(codec, pin);
Takashi Iwai505cb342006-03-27 12:51:52 +02001203 if (wid_caps & AC_WCAP_UNSOL_CAP)
Takashi Iwai82bc9552006-03-21 11:24:42 +01001204 spec->hp_detect = 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +01001205
1206 return 0;
1207}
1208
Mattc7d4b2f2005-06-27 14:59:41 +02001209static int stac9200_parse_auto_config(struct hda_codec *codec)
1210{
1211 struct sigmatel_spec *spec = codec->spec;
1212 int err;
1213
Kailang Yangdf694da2005-12-05 19:42:22 +01001214 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001215 return err;
1216
1217 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
1218 return err;
1219
Takashi Iwai82bc9552006-03-21 11:24:42 +01001220 if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
1221 return err;
1222
1223 if (spec->autocfg.dig_out_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02001224 spec->multiout.dig_out_nid = 0x05;
Takashi Iwai82bc9552006-03-21 11:24:42 +01001225 if (spec->autocfg.dig_in_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02001226 spec->dig_in_nid = 0x04;
Mattc7d4b2f2005-06-27 14:59:41 +02001227
1228 if (spec->kctl_alloc)
1229 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
1230
1231 spec->input_mux = &spec->private_imux;
1232
1233 return 1;
1234}
1235
Sam Revitch62fe78e2006-05-10 15:09:17 +02001236/*
1237 * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
1238 * funky external mute control using GPIO pins.
1239 */
1240
1241static void stac922x_gpio_mute(struct hda_codec *codec, int pin, int muted)
1242{
1243 unsigned int gpiostate, gpiomask, gpiodir;
1244
1245 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
1246 AC_VERB_GET_GPIO_DATA, 0);
1247
1248 if (!muted)
1249 gpiostate |= (1 << pin);
1250 else
1251 gpiostate &= ~(1 << pin);
1252
1253 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
1254 AC_VERB_GET_GPIO_MASK, 0);
1255 gpiomask |= (1 << pin);
1256
1257 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
1258 AC_VERB_GET_GPIO_DIRECTION, 0);
1259 gpiodir |= (1 << pin);
1260
1261 /* AppleHDA seems to do this -- WTF is this verb?? */
1262 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
1263
1264 snd_hda_codec_write(codec, codec->afg, 0,
1265 AC_VERB_SET_GPIO_MASK, gpiomask);
1266 snd_hda_codec_write(codec, codec->afg, 0,
1267 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
1268
1269 msleep(1);
1270
1271 snd_hda_codec_write(codec, codec->afg, 0,
1272 AC_VERB_SET_GPIO_DATA, gpiostate);
1273}
1274
Mattc7d4b2f2005-06-27 14:59:41 +02001275static int stac92xx_init(struct hda_codec *codec)
1276{
1277 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai82bc9552006-03-21 11:24:42 +01001278 struct auto_pin_cfg *cfg = &spec->autocfg;
1279 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02001280
Mattc7d4b2f2005-06-27 14:59:41 +02001281 snd_hda_sequence_write(codec, spec->init);
1282
Takashi Iwai82bc9552006-03-21 11:24:42 +01001283 /* set up pins */
1284 if (spec->hp_detect) {
Takashi Iwai505cb342006-03-27 12:51:52 +02001285 /* Enable unsolicited responses on the HP widget */
1286 snd_hda_codec_write(codec, cfg->hp_pin, 0,
1287 AC_VERB_SET_UNSOLICITED_ENABLE,
1288 STAC_UNSOL_ENABLE);
Takashi Iwai82bc9552006-03-21 11:24:42 +01001289 /* fake event to set up pins */
1290 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
Tobin Davis68a6abd2006-08-21 19:02:10 +02001291 /* enable the headphones by default. If/when unsol_event detection works, this will be ignored */
1292 stac92xx_auto_init_hp_out(codec);
Takashi Iwai82bc9552006-03-21 11:24:42 +01001293 } else {
1294 stac92xx_auto_init_multi_out(codec);
1295 stac92xx_auto_init_hp_out(codec);
1296 }
1297 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwaic960a032006-03-23 17:06:28 +01001298 hda_nid_t nid = cfg->input_pins[i];
1299 if (nid) {
1300 unsigned int pinctl = AC_PINCTL_IN_EN;
1301 if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC)
1302 pinctl |= stac92xx_get_vref(codec, nid);
1303 stac92xx_auto_set_pinctl(codec, nid, pinctl);
1304 }
Takashi Iwai82bc9552006-03-21 11:24:42 +01001305 }
1306 if (cfg->dig_out_pin)
1307 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pin,
1308 AC_PINCTL_OUT_EN);
1309 if (cfg->dig_in_pin)
1310 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
1311 AC_PINCTL_IN_EN);
1312
Sam Revitch62fe78e2006-05-10 15:09:17 +02001313 if (spec->gpio_mute) {
1314 stac922x_gpio_mute(codec, 0, 0);
1315 stac922x_gpio_mute(codec, 1, 0);
1316 }
1317
Mattc7d4b2f2005-06-27 14:59:41 +02001318 return 0;
1319}
1320
Matt2f2f4252005-04-13 14:45:30 +02001321static void stac92xx_free(struct hda_codec *codec)
1322{
Mattc7d4b2f2005-06-27 14:59:41 +02001323 struct sigmatel_spec *spec = codec->spec;
1324 int i;
1325
1326 if (! spec)
1327 return;
1328
1329 if (spec->kctl_alloc) {
1330 for (i = 0; i < spec->num_kctl_used; i++)
1331 kfree(spec->kctl_alloc[i].name);
1332 kfree(spec->kctl_alloc);
1333 }
1334
Richard Fish11b44bb2006-08-23 18:31:34 +02001335 if (spec->bios_pin_configs)
1336 kfree(spec->bios_pin_configs);
1337
Mattc7d4b2f2005-06-27 14:59:41 +02001338 kfree(spec);
Matt2f2f4252005-04-13 14:45:30 +02001339}
1340
Matt4e550962005-07-04 17:51:39 +02001341static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
1342 unsigned int flag)
1343{
1344 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
1345 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
1346 snd_hda_codec_write(codec, nid, 0,
1347 AC_VERB_SET_PIN_WIDGET_CONTROL,
1348 pin_ctl | flag);
1349}
1350
1351static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
1352 unsigned int flag)
1353{
1354 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
1355 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
1356 snd_hda_codec_write(codec, nid, 0,
1357 AC_VERB_SET_PIN_WIDGET_CONTROL,
1358 pin_ctl & ~flag);
1359}
1360
1361static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
1362{
1363 struct sigmatel_spec *spec = codec->spec;
1364 struct auto_pin_cfg *cfg = &spec->autocfg;
1365 int i, presence;
1366
1367 if ((res >> 26) != STAC_HP_EVENT)
1368 return;
1369
1370 presence = snd_hda_codec_read(codec, cfg->hp_pin, 0,
1371 AC_VERB_GET_PIN_SENSE, 0x00) >> 31;
1372
1373 if (presence) {
1374 /* disable lineouts, enable hp */
1375 for (i = 0; i < cfg->line_outs; i++)
1376 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
1377 AC_PINCTL_OUT_EN);
1378 stac92xx_set_pinctl(codec, cfg->hp_pin, AC_PINCTL_OUT_EN);
1379 } else {
1380 /* enable lineouts, disable hp */
1381 for (i = 0; i < cfg->line_outs; i++)
1382 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
1383 AC_PINCTL_OUT_EN);
1384 stac92xx_reset_pinctl(codec, cfg->hp_pin, AC_PINCTL_OUT_EN);
1385 }
1386}
1387
Mattff6fdc32005-06-27 15:06:52 +02001388#ifdef CONFIG_PM
1389static int stac92xx_resume(struct hda_codec *codec)
1390{
1391 struct sigmatel_spec *spec = codec->spec;
1392 int i;
1393
1394 stac92xx_init(codec);
Richard Fish11b44bb2006-08-23 18:31:34 +02001395 stac92xx_set_config_regs(codec);
Mattff6fdc32005-06-27 15:06:52 +02001396 for (i = 0; i < spec->num_mixers; i++)
1397 snd_hda_resume_ctls(codec, spec->mixers[i]);
1398 if (spec->multiout.dig_out_nid)
1399 snd_hda_resume_spdif_out(codec);
1400 if (spec->dig_in_nid)
1401 snd_hda_resume_spdif_in(codec);
1402
1403 return 0;
1404}
1405#endif
1406
Matt2f2f4252005-04-13 14:45:30 +02001407static struct hda_codec_ops stac92xx_patch_ops = {
1408 .build_controls = stac92xx_build_controls,
1409 .build_pcms = stac92xx_build_pcms,
1410 .init = stac92xx_init,
1411 .free = stac92xx_free,
Matt4e550962005-07-04 17:51:39 +02001412 .unsol_event = stac92xx_unsol_event,
Mattff6fdc32005-06-27 15:06:52 +02001413#ifdef CONFIG_PM
1414 .resume = stac92xx_resume,
1415#endif
Matt2f2f4252005-04-13 14:45:30 +02001416};
1417
1418static int patch_stac9200(struct hda_codec *codec)
1419{
1420 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02001421 int err;
Matt2f2f4252005-04-13 14:45:30 +02001422
Takashi Iwaie560d8d2005-09-09 14:21:46 +02001423 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02001424 if (spec == NULL)
1425 return -ENOMEM;
1426
1427 codec->spec = spec;
Richard Fish11b44bb2006-08-23 18:31:34 +02001428 spec->num_pins = 8;
1429 spec->pin_nids = stac9200_pin_nids;
Matt Porter403d1942005-11-29 15:00:51 +01001430 spec->board_config = snd_hda_check_board_config(codec, stac9200_cfg_tbl);
Richard Fish11b44bb2006-08-23 18:31:34 +02001431 if (spec->board_config < 0) {
1432 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9200, using BIOS defaults\n");
1433 err = stac92xx_save_bios_config_regs(codec);
1434 if (err < 0) {
1435 stac92xx_free(codec);
1436 return err;
1437 }
1438 spec->pin_configs = spec->bios_pin_configs;
1439 } else {
Matt Porter403d1942005-11-29 15:00:51 +01001440 spec->pin_configs = stac9200_brd_tbl[spec->board_config];
1441 stac92xx_set_config_regs(codec);
1442 }
Matt2f2f4252005-04-13 14:45:30 +02001443
1444 spec->multiout.max_channels = 2;
1445 spec->multiout.num_dacs = 1;
1446 spec->multiout.dac_nids = stac9200_dac_nids;
1447 spec->adc_nids = stac9200_adc_nids;
1448 spec->mux_nids = stac9200_mux_nids;
Mattdabbed62005-06-14 10:19:34 +02001449 spec->num_muxes = 1;
Mattc7d4b2f2005-06-27 14:59:41 +02001450
1451 spec->init = stac9200_core_init;
Matt2f2f4252005-04-13 14:45:30 +02001452 spec->mixer = stac9200_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02001453
1454 err = stac9200_parse_auto_config(codec);
1455 if (err < 0) {
1456 stac92xx_free(codec);
1457 return err;
1458 }
Matt2f2f4252005-04-13 14:45:30 +02001459
1460 codec->patch_ops = stac92xx_patch_ops;
1461
1462 return 0;
1463}
1464
1465static int patch_stac922x(struct hda_codec *codec)
1466{
1467 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02001468 int err;
Matt2f2f4252005-04-13 14:45:30 +02001469
Takashi Iwaie560d8d2005-09-09 14:21:46 +02001470 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02001471 if (spec == NULL)
1472 return -ENOMEM;
1473
1474 codec->spec = spec;
Richard Fish11b44bb2006-08-23 18:31:34 +02001475 spec->num_pins = 10;
1476 spec->pin_nids = stac922x_pin_nids;
Matt Porter403d1942005-11-29 15:00:51 +01001477 spec->board_config = snd_hda_check_board_config(codec, stac922x_cfg_tbl);
Richard Fish11b44bb2006-08-23 18:31:34 +02001478 if (spec->board_config < 0) {
1479 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC922x, "
1480 "using BIOS defaults\n");
1481 err = stac92xx_save_bios_config_regs(codec);
1482 if (err < 0) {
1483 stac92xx_free(codec);
1484 return err;
1485 }
1486 spec->pin_configs = spec->bios_pin_configs;
1487 } else if (stac922x_brd_tbl[spec->board_config] != NULL) {
Matt Porter403d1942005-11-29 15:00:51 +01001488 spec->pin_configs = stac922x_brd_tbl[spec->board_config];
1489 stac92xx_set_config_regs(codec);
1490 }
Matt2f2f4252005-04-13 14:45:30 +02001491
Matt2f2f4252005-04-13 14:45:30 +02001492 spec->adc_nids = stac922x_adc_nids;
1493 spec->mux_nids = stac922x_mux_nids;
Mattdabbed62005-06-14 10:19:34 +02001494 spec->num_muxes = 2;
Mattc7d4b2f2005-06-27 14:59:41 +02001495
1496 spec->init = stac922x_core_init;
Matt2f2f4252005-04-13 14:45:30 +02001497 spec->mixer = stac922x_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02001498
1499 spec->multiout.dac_nids = spec->dac_nids;
Takashi Iwai19039bd2006-06-28 15:52:16 +02001500
Matt Porter3cc08dc2006-01-23 15:27:49 +01001501 err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
1502 if (err < 0) {
1503 stac92xx_free(codec);
1504 return err;
1505 }
1506
Sam Revitch62fe78e2006-05-10 15:09:17 +02001507 if (spec->board_config == STAC_MACMINI)
1508 spec->gpio_mute = 1;
1509
Matt Porter3cc08dc2006-01-23 15:27:49 +01001510 codec->patch_ops = stac92xx_patch_ops;
1511
1512 return 0;
1513}
1514
1515static int patch_stac927x(struct hda_codec *codec)
1516{
1517 struct sigmatel_spec *spec;
1518 int err;
1519
1520 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1521 if (spec == NULL)
1522 return -ENOMEM;
1523
1524 codec->spec = spec;
Richard Fish11b44bb2006-08-23 18:31:34 +02001525 spec->num_pins = 14;
1526 spec->pin_nids = stac927x_pin_nids;
Matt Porter3cc08dc2006-01-23 15:27:49 +01001527 spec->board_config = snd_hda_check_board_config(codec, stac927x_cfg_tbl);
Richard Fish11b44bb2006-08-23 18:31:34 +02001528 if (spec->board_config < 0) {
Matt Porter3cc08dc2006-01-23 15:27:49 +01001529 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC927x, using BIOS defaults\n");
Richard Fish11b44bb2006-08-23 18:31:34 +02001530 err = stac92xx_save_bios_config_regs(codec);
1531 if (err < 0) {
1532 stac92xx_free(codec);
1533 return err;
1534 }
1535 spec->pin_configs = spec->bios_pin_configs;
1536 } else if (stac927x_brd_tbl[spec->board_config] != NULL) {
Matt Porter3cc08dc2006-01-23 15:27:49 +01001537 spec->pin_configs = stac927x_brd_tbl[spec->board_config];
1538 stac92xx_set_config_regs(codec);
1539 }
1540
Tobin Davis81d3dbd2006-08-22 19:44:45 +02001541 switch (spec->board_config) {
1542 case STAC_D965_2112:
1543 spec->adc_nids = stac927x_adc_nids;
1544 spec->mux_nids = stac927x_mux_nids;
1545 spec->num_muxes = 3;
1546 spec->init = d965_2112_core_init;
1547 spec->mixer = stac9227_mixer;
1548 break;
1549 case STAC_D965_284B:
1550 spec->adc_nids = stac9227_adc_nids;
1551 spec->mux_nids = stac9227_mux_nids;
1552 spec->num_muxes = 2;
1553 spec->init = stac9227_core_init;
1554 spec->mixer = stac9227_mixer;
1555 break;
1556 default:
1557 spec->adc_nids = stac927x_adc_nids;
1558 spec->mux_nids = stac927x_mux_nids;
1559 spec->num_muxes = 3;
1560 spec->init = stac927x_core_init;
1561 spec->mixer = stac927x_mixer;
1562 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01001563
1564 spec->multiout.dac_nids = spec->dac_nids;
1565
1566 err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
Mattc7d4b2f2005-06-27 14:59:41 +02001567 if (err < 0) {
1568 stac92xx_free(codec);
1569 return err;
1570 }
Matt2f2f4252005-04-13 14:45:30 +02001571
1572 codec->patch_ops = stac92xx_patch_ops;
1573
1574 return 0;
1575}
1576
Matt Porterf3302a52006-07-31 12:49:34 +02001577static int patch_stac9205(struct hda_codec *codec)
1578{
1579 struct sigmatel_spec *spec;
1580 int err;
1581
1582 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1583 if (spec == NULL)
1584 return -ENOMEM;
1585
1586 codec->spec = spec;
Richard Fish11b44bb2006-08-23 18:31:34 +02001587 spec->num_pins = 14;
1588 spec->pin_nids = stac9205_pin_nids;
Matt Porterf3302a52006-07-31 12:49:34 +02001589 spec->board_config = snd_hda_check_board_config(codec, stac9205_cfg_tbl);
Richard Fish11b44bb2006-08-23 18:31:34 +02001590 if (spec->board_config < 0) {
1591 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9205, using BIOS defaults\n");
1592 err = stac92xx_save_bios_config_regs(codec);
1593 if (err < 0) {
1594 stac92xx_free(codec);
1595 return err;
1596 }
1597 spec->pin_configs = spec->bios_pin_configs;
1598 } else {
Matt Porterf3302a52006-07-31 12:49:34 +02001599 spec->pin_configs = stac9205_brd_tbl[spec->board_config];
1600 stac92xx_set_config_regs(codec);
1601 }
1602
1603 spec->adc_nids = stac9205_adc_nids;
1604 spec->mux_nids = stac9205_mux_nids;
1605 spec->num_muxes = 3;
1606
1607 spec->init = stac9205_core_init;
1608 spec->mixer = stac9205_mixer;
1609
1610 spec->multiout.dac_nids = spec->dac_nids;
1611
1612 err = stac92xx_parse_auto_config(codec, 0x1f, 0x20);
1613 if (err < 0) {
1614 stac92xx_free(codec);
1615 return err;
1616 }
1617
1618 codec->patch_ops = stac92xx_patch_ops;
1619
1620 return 0;
1621}
1622
Matt2f2f4252005-04-13 14:45:30 +02001623/*
Guillaume Munch6d859062006-08-22 17:15:47 +02001624 * STAC9872 hack
Takashi Iwaidb064e52006-03-16 16:04:58 +01001625 */
1626
Guillaume Munch99ccc562006-08-16 19:35:12 +02001627/* static config for Sony VAIO FE550G and Sony VAIO AR */
Takashi Iwaidb064e52006-03-16 16:04:58 +01001628static hda_nid_t vaio_dacs[] = { 0x2 };
1629#define VAIO_HP_DAC 0x5
1630static hda_nid_t vaio_adcs[] = { 0x8 /*,0x6*/ };
1631static hda_nid_t vaio_mux_nids[] = { 0x15 };
1632
1633static struct hda_input_mux vaio_mux = {
1634 .num_items = 2,
1635 .items = {
Takashi Iwaid7737812006-04-25 13:05:43 +02001636 /* { "HP", 0x0 }, */
1637 { "Line", 0x1 },
Takashi Iwaidb064e52006-03-16 16:04:58 +01001638 { "Mic", 0x2 },
1639 { "PCM", 0x3 },
1640 }
1641};
1642
1643static struct hda_verb vaio_init[] = {
1644 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
1645 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
1646 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
1647 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
1648 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
1649 {0x15, AC_VERB_SET_CONNECT_SEL, 0x2}, /* mic-sel: 0a,0d,14,02 */
1650 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
1651 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
1652 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
1653 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
1654 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
1655 {}
1656};
1657
Guillaume Munch6d859062006-08-22 17:15:47 +02001658static struct hda_verb vaio_ar_init[] = {
1659 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
1660 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
1661 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
1662 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
1663/* {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },*/ /* Optical Out */
1664 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
1665 {0x15, AC_VERB_SET_CONNECT_SEL, 0x2}, /* mic-sel: 0a,0d,14,02 */
1666 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
1667 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
1668/* {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},*/ /* Optical Out */
1669 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
1670 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
1671 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
1672 {}
1673};
1674
Takashi Iwaidb064e52006-03-16 16:04:58 +01001675/* bind volumes of both NID 0x02 and 0x05 */
1676static int vaio_master_vol_put(struct snd_kcontrol *kcontrol,
1677 struct snd_ctl_elem_value *ucontrol)
1678{
1679 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1680 long *valp = ucontrol->value.integer.value;
1681 int change;
1682
1683 change = snd_hda_codec_amp_update(codec, 0x02, 0, HDA_OUTPUT, 0,
1684 0x7f, valp[0] & 0x7f);
1685 change |= snd_hda_codec_amp_update(codec, 0x02, 1, HDA_OUTPUT, 0,
1686 0x7f, valp[1] & 0x7f);
1687 snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
1688 0x7f, valp[0] & 0x7f);
1689 snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
1690 0x7f, valp[1] & 0x7f);
1691 return change;
1692}
1693
1694/* bind volumes of both NID 0x02 and 0x05 */
1695static int vaio_master_sw_put(struct snd_kcontrol *kcontrol,
1696 struct snd_ctl_elem_value *ucontrol)
1697{
1698 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1699 long *valp = ucontrol->value.integer.value;
1700 int change;
1701
1702 change = snd_hda_codec_amp_update(codec, 0x02, 0, HDA_OUTPUT, 0,
Takashi Iwaia9393d72006-05-03 11:59:03 +02001703 0x80, (valp[0] ? 0 : 0x80));
Takashi Iwaidb064e52006-03-16 16:04:58 +01001704 change |= snd_hda_codec_amp_update(codec, 0x02, 1, HDA_OUTPUT, 0,
Takashi Iwaia9393d72006-05-03 11:59:03 +02001705 0x80, (valp[1] ? 0 : 0x80));
Takashi Iwaidb064e52006-03-16 16:04:58 +01001706 snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
Takashi Iwaia9393d72006-05-03 11:59:03 +02001707 0x80, (valp[0] ? 0 : 0x80));
Takashi Iwaidb064e52006-03-16 16:04:58 +01001708 snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
Takashi Iwaia9393d72006-05-03 11:59:03 +02001709 0x80, (valp[1] ? 0 : 0x80));
Takashi Iwaidb064e52006-03-16 16:04:58 +01001710 return change;
1711}
1712
1713static struct snd_kcontrol_new vaio_mixer[] = {
1714 {
1715 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1716 .name = "Master Playback Volume",
1717 .info = snd_hda_mixer_amp_volume_info,
1718 .get = snd_hda_mixer_amp_volume_get,
1719 .put = vaio_master_vol_put,
Takashi Iwaic2566522006-08-17 18:21:36 +02001720 .tlv = { .c = snd_hda_mixer_amp_tlv },
Takashi Iwaidb064e52006-03-16 16:04:58 +01001721 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
1722 },
1723 {
1724 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1725 .name = "Master Playback Switch",
1726 .info = snd_hda_mixer_amp_switch_info,
1727 .get = snd_hda_mixer_amp_switch_get,
1728 .put = vaio_master_sw_put,
1729 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
1730 },
1731 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
1732 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
1733 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
1734 {
1735 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1736 .name = "Capture Source",
1737 .count = 1,
1738 .info = stac92xx_mux_enum_info,
1739 .get = stac92xx_mux_enum_get,
1740 .put = stac92xx_mux_enum_put,
1741 },
1742 {}
1743};
1744
Guillaume Munch6d859062006-08-22 17:15:47 +02001745static struct snd_kcontrol_new vaio_ar_mixer[] = {
1746 {
1747 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1748 .name = "Master Playback Volume",
1749 .info = snd_hda_mixer_amp_volume_info,
1750 .get = snd_hda_mixer_amp_volume_get,
1751 .put = vaio_master_vol_put,
1752 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
1753 },
1754 {
1755 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1756 .name = "Master Playback Switch",
1757 .info = snd_hda_mixer_amp_switch_info,
1758 .get = snd_hda_mixer_amp_switch_get,
1759 .put = vaio_master_sw_put,
1760 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
1761 },
1762 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
1763 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
1764 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
1765 /*HDA_CODEC_MUTE("Optical Out Switch", 0x10, 0, HDA_OUTPUT),
1766 HDA_CODEC_VOLUME("Optical Out Volume", 0x10, 0, HDA_OUTPUT),*/
1767 {
1768 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1769 .name = "Capture Source",
1770 .count = 1,
1771 .info = stac92xx_mux_enum_info,
1772 .get = stac92xx_mux_enum_get,
1773 .put = stac92xx_mux_enum_put,
1774 },
1775 {}
1776};
1777
1778static struct hda_codec_ops stac9872_patch_ops = {
Takashi Iwaidb064e52006-03-16 16:04:58 +01001779 .build_controls = stac92xx_build_controls,
1780 .build_pcms = stac92xx_build_pcms,
1781 .init = stac92xx_init,
1782 .free = stac92xx_free,
1783#ifdef CONFIG_PM
1784 .resume = stac92xx_resume,
1785#endif
1786};
1787
Guillaume Munch6d859062006-08-22 17:15:47 +02001788enum { /* FE and SZ series. id=0x83847661 and subsys=0x104D0700 or 104D1000. */
1789 CXD9872RD_VAIO,
1790 /* Unknown. id=0x83847662 and subsys=0x104D1200 or 104D1000. */
1791 STAC9872AK_VAIO,
1792 /* Unknown. id=0x83847661 and subsys=0x104D1200. */
1793 STAC9872K_VAIO,
1794 /* AR Series. id=0x83847664 and subsys=104D1300 */
1795 CXD9872AKD_VAIO
1796 };
Takashi Iwaidb064e52006-03-16 16:04:58 +01001797
Guillaume Munch6d859062006-08-22 17:15:47 +02001798static struct hda_board_config stac9872_cfg_tbl[] = {
1799 { .modelname = "vaio", .config = CXD9872RD_VAIO },
1800 { .modelname = "vaio-ar", .config = CXD9872AKD_VAIO },
Takashi Iwaidb064e52006-03-16 16:04:58 +01001801 { .pci_subvendor = 0x104d, .pci_subdevice = 0x81e6,
Guillaume Munch6d859062006-08-22 17:15:47 +02001802 .config = CXD9872RD_VAIO },
Takashi Iwaidb064e52006-03-16 16:04:58 +01001803 { .pci_subvendor = 0x104d, .pci_subdevice = 0x81ef,
Guillaume Munch6d859062006-08-22 17:15:47 +02001804 .config = CXD9872RD_VAIO },
Guillaume Munch99ccc562006-08-16 19:35:12 +02001805 { .pci_subvendor = 0x104d, .pci_subdevice = 0x81fd,
Guillaume Munch6d859062006-08-22 17:15:47 +02001806 .config = CXD9872AKD_VAIO },
Takashi Iwaidb064e52006-03-16 16:04:58 +01001807 {}
1808};
1809
Guillaume Munch6d859062006-08-22 17:15:47 +02001810static int patch_stac9872(struct hda_codec *codec)
Takashi Iwaidb064e52006-03-16 16:04:58 +01001811{
1812 struct sigmatel_spec *spec;
1813 int board_config;
1814
Guillaume Munch6d859062006-08-22 17:15:47 +02001815 board_config = snd_hda_check_board_config(codec, stac9872_cfg_tbl);
Takashi Iwaidb064e52006-03-16 16:04:58 +01001816 if (board_config < 0)
1817 /* unknown config, let generic-parser do its job... */
1818 return snd_hda_parse_generic_codec(codec);
1819
1820 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1821 if (spec == NULL)
1822 return -ENOMEM;
1823
1824 codec->spec = spec;
1825 switch (board_config) {
Guillaume Munch6d859062006-08-22 17:15:47 +02001826 case CXD9872RD_VAIO:
1827 case STAC9872AK_VAIO:
1828 case STAC9872K_VAIO:
Takashi Iwaidb064e52006-03-16 16:04:58 +01001829 spec->mixer = vaio_mixer;
1830 spec->init = vaio_init;
1831 spec->multiout.max_channels = 2;
1832 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
1833 spec->multiout.dac_nids = vaio_dacs;
1834 spec->multiout.hp_nid = VAIO_HP_DAC;
1835 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
1836 spec->adc_nids = vaio_adcs;
1837 spec->input_mux = &vaio_mux;
1838 spec->mux_nids = vaio_mux_nids;
1839 break;
Guillaume Munch6d859062006-08-22 17:15:47 +02001840
1841 case CXD9872AKD_VAIO:
1842 spec->mixer = vaio_ar_mixer;
1843 spec->init = vaio_ar_init;
1844 spec->multiout.max_channels = 2;
1845 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
1846 spec->multiout.dac_nids = vaio_dacs;
1847 spec->multiout.hp_nid = VAIO_HP_DAC;
1848 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
1849 spec->adc_nids = vaio_adcs;
1850 spec->input_mux = &vaio_mux;
1851 spec->mux_nids = vaio_mux_nids;
1852 break;
Takashi Iwaidb064e52006-03-16 16:04:58 +01001853 }
1854
Guillaume Munch6d859062006-08-22 17:15:47 +02001855 codec->patch_ops = stac9872_patch_ops;
Takashi Iwaidb064e52006-03-16 16:04:58 +01001856 return 0;
1857}
1858
1859
1860/*
Matt2f2f4252005-04-13 14:45:30 +02001861 * patch entries
1862 */
1863struct hda_codec_preset snd_hda_preset_sigmatel[] = {
1864 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
1865 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
1866 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
1867 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
1868 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
1869 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
1870 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
Matt Porter22a27c72006-07-06 18:49:10 +02001871 { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
1872 { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
1873 { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
1874 { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
1875 { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
1876 { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
Matt Porter3cc08dc2006-01-23 15:27:49 +01001877 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
1878 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
1879 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
1880 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
1881 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
1882 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
1883 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
1884 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
1885 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
1886 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
Guillaume Munch6d859062006-08-22 17:15:47 +02001887 /* The following does not take into account .id=0x83847661 when subsys =
1888 * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
1889 * currently not fully supported.
1890 */
1891 { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
1892 { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
1893 { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
Matt Porterf3302a52006-07-31 12:49:34 +02001894 { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
1895 { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
1896 { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
1897 { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
1898 { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
1899 { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
1900 { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
1901 { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
Matt2f2f4252005-04-13 14:45:30 +02001902 {} /* terminator */
1903};