blob: 8d5ad7c0db072c3c7fa730d4792df4a8df32e207 [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 */
Takashi Iwai2c7782b2006-08-25 13:11:26 +0200585 /* Dell laptops have BIOS problem */
586 { .pci_subvendor = PCI_VENDOR_ID_DELL, .pci_subdevice = 0x01b5,
587 .config = STAC_REF }, /* Dell Inspiron 630m */
588 { .pci_subvendor = PCI_VENDOR_ID_DELL, .pci_subdevice = 0x01c2,
589 .config = STAC_REF }, /* Dell Latitude D620 */
590 { .pci_subvendor = PCI_VENDOR_ID_DELL, .pci_subdevice = 0x01cb,
591 .config = STAC_REF }, /* Dell Latitude 120L */
Matt Porterf3302a52006-07-31 12:49:34 +0200592 {} /* terminator */
593};
594
Richard Fish11b44bb2006-08-23 18:31:34 +0200595static int stac92xx_save_bios_config_regs(struct hda_codec *codec)
596{
597 int i;
598 struct sigmatel_spec *spec = codec->spec;
599
600 if (! spec->bios_pin_configs) {
601 spec->bios_pin_configs = kcalloc(spec->num_pins,
602 sizeof(*spec->bios_pin_configs), GFP_KERNEL);
603 if (! spec->bios_pin_configs)
604 return -ENOMEM;
605 }
606
607 for (i = 0; i < spec->num_pins; i++) {
608 hda_nid_t nid = spec->pin_nids[i];
609 unsigned int pin_cfg;
610
611 pin_cfg = snd_hda_codec_read(codec, nid, 0,
612 AC_VERB_GET_CONFIG_DEFAULT, 0x00);
613 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x bios pin config %8.8x\n",
614 nid, pin_cfg);
615 spec->bios_pin_configs[i] = pin_cfg;
616 }
617
618 return 0;
619}
620
Matt2f2f4252005-04-13 14:45:30 +0200621static void stac92xx_set_config_regs(struct hda_codec *codec)
622{
623 int i;
624 struct sigmatel_spec *spec = codec->spec;
625 unsigned int pin_cfg;
626
Richard Fish11b44bb2006-08-23 18:31:34 +0200627 if (! spec->pin_nids || ! spec->pin_configs)
628 return;
629
630 for (i = 0; i < spec->num_pins; i++) {
Matt2f2f4252005-04-13 14:45:30 +0200631 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
632 AC_VERB_SET_CONFIG_DEFAULT_BYTES_0,
633 spec->pin_configs[i] & 0x000000ff);
634 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
635 AC_VERB_SET_CONFIG_DEFAULT_BYTES_1,
636 (spec->pin_configs[i] & 0x0000ff00) >> 8);
637 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
638 AC_VERB_SET_CONFIG_DEFAULT_BYTES_2,
639 (spec->pin_configs[i] & 0x00ff0000) >> 16);
640 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
641 AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
642 spec->pin_configs[i] >> 24);
643 pin_cfg = snd_hda_codec_read(codec, spec->pin_nids[i], 0,
644 AC_VERB_GET_CONFIG_DEFAULT,
645 0x00);
Matt Porter403d1942005-11-29 15:00:51 +0100646 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 +0200647 }
648}
Matt2f2f4252005-04-13 14:45:30 +0200649
Matt2f2f4252005-04-13 14:45:30 +0200650/*
651 * Analog playback callbacks
652 */
653static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
654 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100655 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200656{
657 struct sigmatel_spec *spec = codec->spec;
658 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
659}
660
661static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
662 struct hda_codec *codec,
663 unsigned int stream_tag,
664 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100665 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200666{
667 struct sigmatel_spec *spec = codec->spec;
Matt Porter403d1942005-11-29 15:00:51 +0100668 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
Matt2f2f4252005-04-13 14:45:30 +0200669}
670
671static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
672 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100673 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200674{
675 struct sigmatel_spec *spec = codec->spec;
676 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
677}
678
679/*
Mattdabbed62005-06-14 10:19:34 +0200680 * Digital playback callbacks
681 */
682static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
683 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100684 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +0200685{
686 struct sigmatel_spec *spec = codec->spec;
687 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
688}
689
690static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
691 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100692 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +0200693{
694 struct sigmatel_spec *spec = codec->spec;
695 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
696}
697
698
699/*
Matt2f2f4252005-04-13 14:45:30 +0200700 * Analog capture callbacks
701 */
702static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
703 struct hda_codec *codec,
704 unsigned int stream_tag,
705 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100706 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200707{
708 struct sigmatel_spec *spec = codec->spec;
709
710 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
711 stream_tag, 0, format);
712 return 0;
713}
714
715static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
716 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100717 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200718{
719 struct sigmatel_spec *spec = codec->spec;
720
721 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 0, 0, 0);
722 return 0;
723}
724
Mattdabbed62005-06-14 10:19:34 +0200725static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
726 .substreams = 1,
727 .channels_min = 2,
728 .channels_max = 2,
729 /* NID is set in stac92xx_build_pcms */
730 .ops = {
731 .open = stac92xx_dig_playback_pcm_open,
732 .close = stac92xx_dig_playback_pcm_close
733 },
734};
735
736static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
737 .substreams = 1,
738 .channels_min = 2,
739 .channels_max = 2,
740 /* NID is set in stac92xx_build_pcms */
741};
742
Matt2f2f4252005-04-13 14:45:30 +0200743static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
744 .substreams = 1,
745 .channels_min = 2,
Mattc7d4b2f2005-06-27 14:59:41 +0200746 .channels_max = 8,
Matt2f2f4252005-04-13 14:45:30 +0200747 .nid = 0x02, /* NID to query formats and rates */
748 .ops = {
749 .open = stac92xx_playback_pcm_open,
750 .prepare = stac92xx_playback_pcm_prepare,
751 .cleanup = stac92xx_playback_pcm_cleanup
752 },
753};
754
Matt Porter3cc08dc2006-01-23 15:27:49 +0100755static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
756 .substreams = 1,
757 .channels_min = 2,
758 .channels_max = 2,
759 .nid = 0x06, /* NID to query formats and rates */
760 .ops = {
761 .open = stac92xx_playback_pcm_open,
762 .prepare = stac92xx_playback_pcm_prepare,
763 .cleanup = stac92xx_playback_pcm_cleanup
764 },
765};
766
Matt2f2f4252005-04-13 14:45:30 +0200767static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
768 .substreams = 2,
769 .channels_min = 2,
770 .channels_max = 2,
Matt Porter3cc08dc2006-01-23 15:27:49 +0100771 /* NID is set in stac92xx_build_pcms */
Matt2f2f4252005-04-13 14:45:30 +0200772 .ops = {
773 .prepare = stac92xx_capture_pcm_prepare,
774 .cleanup = stac92xx_capture_pcm_cleanup
775 },
776};
777
778static int stac92xx_build_pcms(struct hda_codec *codec)
779{
780 struct sigmatel_spec *spec = codec->spec;
781 struct hda_pcm *info = spec->pcm_rec;
782
783 codec->num_pcms = 1;
784 codec->pcm_info = info;
785
Mattc7d4b2f2005-06-27 14:59:41 +0200786 info->name = "STAC92xx Analog";
Matt2f2f4252005-04-13 14:45:30 +0200787 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
Matt2f2f4252005-04-13 14:45:30 +0200788 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100789 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
790
791 if (spec->alt_switch) {
792 codec->num_pcms++;
793 info++;
794 info->name = "STAC92xx Analog Alt";
795 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
796 }
Matt2f2f4252005-04-13 14:45:30 +0200797
Mattdabbed62005-06-14 10:19:34 +0200798 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
799 codec->num_pcms++;
800 info++;
801 info->name = "STAC92xx Digital";
802 if (spec->multiout.dig_out_nid) {
803 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
804 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
805 }
806 if (spec->dig_in_nid) {
807 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
808 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
809 }
810 }
811
Matt2f2f4252005-04-13 14:45:30 +0200812 return 0;
813}
814
Takashi Iwaic960a032006-03-23 17:06:28 +0100815static unsigned int stac92xx_get_vref(struct hda_codec *codec, hda_nid_t nid)
816{
817 unsigned int pincap = snd_hda_param_read(codec, nid,
818 AC_PAR_PIN_CAP);
819 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
820 if (pincap & AC_PINCAP_VREF_100)
821 return AC_PINCTL_VREF_100;
822 if (pincap & AC_PINCAP_VREF_80)
823 return AC_PINCTL_VREF_80;
824 if (pincap & AC_PINCAP_VREF_50)
825 return AC_PINCTL_VREF_50;
826 if (pincap & AC_PINCAP_VREF_GRD)
827 return AC_PINCTL_VREF_GRD;
828 return 0;
829}
830
Matt Porter403d1942005-11-29 15:00:51 +0100831static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
832
833{
834 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
835}
836
837static int stac92xx_io_switch_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
838{
839 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
840 uinfo->count = 1;
841 uinfo->value.integer.min = 0;
842 uinfo->value.integer.max = 1;
843 return 0;
844}
845
846static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
847{
848 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
849 struct sigmatel_spec *spec = codec->spec;
850 int io_idx = kcontrol-> private_value & 0xff;
851
852 ucontrol->value.integer.value[0] = spec->io_switch[io_idx];
853 return 0;
854}
855
856static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
857{
858 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
859 struct sigmatel_spec *spec = codec->spec;
860 hda_nid_t nid = kcontrol->private_value >> 8;
861 int io_idx = kcontrol-> private_value & 0xff;
862 unsigned short val = ucontrol->value.integer.value[0];
863
864 spec->io_switch[io_idx] = val;
865
866 if (val)
867 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
Takashi Iwaic960a032006-03-23 17:06:28 +0100868 else {
869 unsigned int pinctl = AC_PINCTL_IN_EN;
870 if (io_idx) /* set VREF for mic */
871 pinctl |= stac92xx_get_vref(codec, nid);
872 stac92xx_auto_set_pinctl(codec, nid, pinctl);
873 }
Matt Porter403d1942005-11-29 15:00:51 +0100874 return 1;
875}
876
877#define STAC_CODEC_IO_SWITCH(xname, xpval) \
878 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
879 .name = xname, \
880 .index = 0, \
881 .info = stac92xx_io_switch_info, \
882 .get = stac92xx_io_switch_get, \
883 .put = stac92xx_io_switch_put, \
884 .private_value = xpval, \
885 }
886
887
Mattc7d4b2f2005-06-27 14:59:41 +0200888enum {
889 STAC_CTL_WIDGET_VOL,
890 STAC_CTL_WIDGET_MUTE,
Matt Porter403d1942005-11-29 15:00:51 +0100891 STAC_CTL_WIDGET_IO_SWITCH,
Mattc7d4b2f2005-06-27 14:59:41 +0200892};
893
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100894static struct snd_kcontrol_new stac92xx_control_templates[] = {
Mattc7d4b2f2005-06-27 14:59:41 +0200895 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
896 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Matt Porter403d1942005-11-29 15:00:51 +0100897 STAC_CODEC_IO_SWITCH(NULL, 0),
Mattc7d4b2f2005-06-27 14:59:41 +0200898};
899
900/* add dynamic controls */
901static int stac92xx_add_control(struct sigmatel_spec *spec, int type, const char *name, unsigned long val)
902{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100903 struct snd_kcontrol_new *knew;
Mattc7d4b2f2005-06-27 14:59:41 +0200904
905 if (spec->num_kctl_used >= spec->num_kctl_alloc) {
906 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
907
908 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */
909 if (! knew)
910 return -ENOMEM;
911 if (spec->kctl_alloc) {
912 memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
913 kfree(spec->kctl_alloc);
914 }
915 spec->kctl_alloc = knew;
916 spec->num_kctl_alloc = num;
917 }
918
919 knew = &spec->kctl_alloc[spec->num_kctl_used];
920 *knew = stac92xx_control_templates[type];
Takashi Iwai82fe0c52005-06-30 10:54:33 +0200921 knew->name = kstrdup(name, GFP_KERNEL);
Mattc7d4b2f2005-06-27 14:59:41 +0200922 if (! knew->name)
923 return -ENOMEM;
924 knew->private_value = val;
925 spec->num_kctl_used++;
926 return 0;
927}
928
Matt Porter403d1942005-11-29 15:00:51 +0100929/* flag inputs as additional dynamic lineouts */
930static int stac92xx_add_dyn_out_pins(struct hda_codec *codec, struct auto_pin_cfg *cfg)
931{
932 struct sigmatel_spec *spec = codec->spec;
933
934 switch (cfg->line_outs) {
935 case 3:
936 /* add line-in as side */
937 if (cfg->input_pins[AUTO_PIN_LINE]) {
938 cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_LINE];
939 spec->line_switch = 1;
940 cfg->line_outs++;
941 }
942 break;
943 case 2:
944 /* add line-in as clfe and mic as side */
945 if (cfg->input_pins[AUTO_PIN_LINE]) {
946 cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_LINE];
947 spec->line_switch = 1;
948 cfg->line_outs++;
949 }
950 if (cfg->input_pins[AUTO_PIN_MIC]) {
951 cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_MIC];
952 spec->mic_switch = 1;
953 cfg->line_outs++;
954 }
955 break;
956 case 1:
957 /* add line-in as surr and mic as clfe */
958 if (cfg->input_pins[AUTO_PIN_LINE]) {
959 cfg->line_out_pins[1] = cfg->input_pins[AUTO_PIN_LINE];
960 spec->line_switch = 1;
961 cfg->line_outs++;
962 }
963 if (cfg->input_pins[AUTO_PIN_MIC]) {
964 cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_MIC];
965 spec->mic_switch = 1;
966 cfg->line_outs++;
967 }
968 break;
969 }
970
971 return 0;
972}
973
Matt Porter3cc08dc2006-01-23 15:27:49 +0100974/*
975 * XXX The line_out pin widget connection list may not be set to the
976 * desired DAC nid. This is the case on 927x where ports A and B can
977 * be routed to several DACs.
978 *
979 * This requires an analysis of the line-out/hp pin configuration
980 * to provide a best fit for pin/DAC configurations that are routable.
981 * For now, 927x DAC4 is not supported and 927x DAC1 output to ports
982 * A and B is not supported.
983 */
Mattc7d4b2f2005-06-27 14:59:41 +0200984/* fill in the dac_nids table from the parsed pin configuration */
Takashi Iwai19039bd2006-06-28 15:52:16 +0200985static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec,
986 const struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +0200987{
988 struct sigmatel_spec *spec = codec->spec;
989 hda_nid_t nid;
990 int i;
991
992 /* check the pins hardwired to audio widget */
993 for (i = 0; i < cfg->line_outs; i++) {
994 nid = cfg->line_out_pins[i];
995 spec->multiout.dac_nids[i] = snd_hda_codec_read(codec, nid, 0,
996 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
997 }
998
Takashi Iwai82bc9552006-03-21 11:24:42 +0100999 spec->multiout.num_dacs = cfg->line_outs;
Mattc7d4b2f2005-06-27 14:59:41 +02001000
1001 return 0;
1002}
1003
1004/* add playback controls from the parsed DAC table */
Takashi Iwai19039bd2006-06-28 15:52:16 +02001005static int stac92xx_auto_create_multi_out_ctls(struct sigmatel_spec *spec,
1006 const struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02001007{
1008 char name[32];
Takashi Iwai19039bd2006-06-28 15:52:16 +02001009 static const char *chname[4] = {
1010 "Front", "Surround", NULL /*CLFE*/, "Side"
1011 };
Mattc7d4b2f2005-06-27 14:59:41 +02001012 hda_nid_t nid;
1013 int i, err;
1014
1015 for (i = 0; i < cfg->line_outs; i++) {
Matt Porter403d1942005-11-29 15:00:51 +01001016 if (!spec->multiout.dac_nids[i])
Mattc7d4b2f2005-06-27 14:59:41 +02001017 continue;
1018
1019 nid = spec->multiout.dac_nids[i];
1020
1021 if (i == 2) {
1022 /* Center/LFE */
1023 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, "Center Playback Volume",
1024 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT))) < 0)
1025 return err;
1026 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, "LFE Playback Volume",
1027 HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT))) < 0)
1028 return err;
1029 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, "Center Playback Switch",
1030 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT))) < 0)
1031 return err;
1032 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, "LFE Playback Switch",
1033 HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT))) < 0)
1034 return err;
1035 } else {
1036 sprintf(name, "%s Playback Volume", chname[i]);
1037 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, name,
1038 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
1039 return err;
1040 sprintf(name, "%s Playback Switch", chname[i]);
1041 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, name,
1042 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
1043 return err;
1044 }
1045 }
1046
Matt Porter403d1942005-11-29 15:00:51 +01001047 if (spec->line_switch)
1048 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Line In as Output Switch", cfg->input_pins[AUTO_PIN_LINE] << 8)) < 0)
1049 return err;
1050
1051 if (spec->mic_switch)
1052 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Mic as Output Switch", (cfg->input_pins[AUTO_PIN_MIC] << 8) | 1)) < 0)
1053 return err;
1054
Mattc7d4b2f2005-06-27 14:59:41 +02001055 return 0;
1056}
1057
1058/* add playback controls for HP output */
1059static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec, struct auto_pin_cfg *cfg)
1060{
1061 struct sigmatel_spec *spec = codec->spec;
1062 hda_nid_t pin = cfg->hp_pin;
1063 hda_nid_t nid;
1064 int i, err;
Matt4e550962005-07-04 17:51:39 +02001065 unsigned int wid_caps;
Mattc7d4b2f2005-06-27 14:59:41 +02001066
1067 if (! pin)
1068 return 0;
1069
Takashi Iwai54d17402005-11-21 16:33:22 +01001070 wid_caps = get_wcaps(codec, pin);
Takashi Iwai505cb342006-03-27 12:51:52 +02001071 if (wid_caps & AC_WCAP_UNSOL_CAP)
Takashi Iwai82bc9552006-03-21 11:24:42 +01001072 spec->hp_detect = 1;
Matt4e550962005-07-04 17:51:39 +02001073
Mattc7d4b2f2005-06-27 14:59:41 +02001074 nid = snd_hda_codec_read(codec, pin, 0, AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
1075 for (i = 0; i < cfg->line_outs; i++) {
1076 if (! spec->multiout.dac_nids[i])
1077 continue;
1078 if (spec->multiout.dac_nids[i] == nid)
1079 return 0;
1080 }
1081
1082 spec->multiout.hp_nid = nid;
1083
1084 /* control HP volume/switch on the output mixer amp */
1085 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, "Headphone Playback Volume",
1086 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
1087 return err;
1088 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, "Headphone Playback Switch",
1089 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
1090 return err;
1091
1092 return 0;
1093}
1094
1095/* create playback/capture controls for input pins */
1096static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
1097{
1098 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02001099 struct hda_input_mux *imux = &spec->private_imux;
1100 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
1101 int i, j, k;
1102
1103 for (i = 0; i < AUTO_PIN_LAST; i++) {
1104 int index = -1;
1105 if (cfg->input_pins[i]) {
Takashi Iwai4a471b72005-12-07 13:56:29 +01001106 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
Mattc7d4b2f2005-06-27 14:59:41 +02001107
1108 for (j=0; j<spec->num_muxes; j++) {
1109 int num_cons = snd_hda_get_connections(codec, spec->mux_nids[j], con_lst, HDA_MAX_NUM_INPUTS);
1110 for (k=0; k<num_cons; k++)
1111 if (con_lst[k] == cfg->input_pins[i]) {
1112 index = k;
1113 break;
1114 }
1115 if (index >= 0)
1116 break;
1117 }
1118 imux->items[imux->num_items].index = index;
1119 imux->num_items++;
1120 }
1121 }
1122
Sam Revitch62fe78e2006-05-10 15:09:17 +02001123 if (imux->num_items == 1) {
1124 /*
1125 * Set the current input for the muxes.
1126 * The STAC9221 has two input muxes with identical source
1127 * NID lists. Hopefully this won't get confused.
1128 */
1129 for (i = 0; i < spec->num_muxes; i++) {
1130 snd_hda_codec_write(codec, spec->mux_nids[i], 0,
1131 AC_VERB_SET_CONNECT_SEL,
1132 imux->items[0].index);
1133 }
1134 }
1135
Mattc7d4b2f2005-06-27 14:59:41 +02001136 return 0;
1137}
1138
Mattc7d4b2f2005-06-27 14:59:41 +02001139static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
1140{
1141 struct sigmatel_spec *spec = codec->spec;
1142 int i;
1143
1144 for (i = 0; i < spec->autocfg.line_outs; i++) {
1145 hda_nid_t nid = spec->autocfg.line_out_pins[i];
1146 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
1147 }
1148}
1149
1150static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
1151{
1152 struct sigmatel_spec *spec = codec->spec;
1153 hda_nid_t pin;
1154
1155 pin = spec->autocfg.hp_pin;
1156 if (pin) /* connect to front */
1157 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
1158}
1159
Matt Porter3cc08dc2006-01-23 15:27:49 +01001160static 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 +02001161{
1162 struct sigmatel_spec *spec = codec->spec;
1163 int err;
1164
Kailang Yangdf694da2005-12-05 19:42:22 +01001165 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001166 return err;
Takashi Iwai82bc9552006-03-21 11:24:42 +01001167 if (! spec->autocfg.line_outs)
Matt Porter869264c2006-01-25 19:20:50 +01001168 return 0; /* can't find valid pin config */
Takashi Iwai19039bd2006-06-28 15:52:16 +02001169
Matt Porter403d1942005-11-29 15:00:51 +01001170 if ((err = stac92xx_add_dyn_out_pins(codec, &spec->autocfg)) < 0)
1171 return err;
Takashi Iwai19039bd2006-06-28 15:52:16 +02001172 if (spec->multiout.num_dacs == 0)
1173 if ((err = stac92xx_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
1174 return err;
Mattc7d4b2f2005-06-27 14:59:41 +02001175
1176 if ((err = stac92xx_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
1177 (err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg)) < 0 ||
1178 (err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
1179 return err;
1180
1181 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Matt Porter403d1942005-11-29 15:00:51 +01001182 if (spec->multiout.max_channels > 2)
Mattc7d4b2f2005-06-27 14:59:41 +02001183 spec->surr_switch = 1;
Mattc7d4b2f2005-06-27 14:59:41 +02001184
Takashi Iwai82bc9552006-03-21 11:24:42 +01001185 if (spec->autocfg.dig_out_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01001186 spec->multiout.dig_out_nid = dig_out;
Takashi Iwai82bc9552006-03-21 11:24:42 +01001187 if (spec->autocfg.dig_in_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01001188 spec->dig_in_nid = dig_in;
Mattc7d4b2f2005-06-27 14:59:41 +02001189
1190 if (spec->kctl_alloc)
1191 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
1192
1193 spec->input_mux = &spec->private_imux;
1194
1195 return 1;
1196}
1197
Takashi Iwai82bc9552006-03-21 11:24:42 +01001198/* add playback controls for HP output */
1199static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
1200 struct auto_pin_cfg *cfg)
1201{
1202 struct sigmatel_spec *spec = codec->spec;
1203 hda_nid_t pin = cfg->hp_pin;
1204 unsigned int wid_caps;
1205
1206 if (! pin)
1207 return 0;
1208
1209 wid_caps = get_wcaps(codec, pin);
Takashi Iwai505cb342006-03-27 12:51:52 +02001210 if (wid_caps & AC_WCAP_UNSOL_CAP)
Takashi Iwai82bc9552006-03-21 11:24:42 +01001211 spec->hp_detect = 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +01001212
1213 return 0;
1214}
1215
Mattc7d4b2f2005-06-27 14:59:41 +02001216static int stac9200_parse_auto_config(struct hda_codec *codec)
1217{
1218 struct sigmatel_spec *spec = codec->spec;
1219 int err;
1220
Kailang Yangdf694da2005-12-05 19:42:22 +01001221 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001222 return err;
1223
1224 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
1225 return err;
1226
Takashi Iwai82bc9552006-03-21 11:24:42 +01001227 if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
1228 return err;
1229
1230 if (spec->autocfg.dig_out_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02001231 spec->multiout.dig_out_nid = 0x05;
Takashi Iwai82bc9552006-03-21 11:24:42 +01001232 if (spec->autocfg.dig_in_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02001233 spec->dig_in_nid = 0x04;
Mattc7d4b2f2005-06-27 14:59:41 +02001234
1235 if (spec->kctl_alloc)
1236 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
1237
1238 spec->input_mux = &spec->private_imux;
1239
1240 return 1;
1241}
1242
Sam Revitch62fe78e2006-05-10 15:09:17 +02001243/*
1244 * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
1245 * funky external mute control using GPIO pins.
1246 */
1247
1248static void stac922x_gpio_mute(struct hda_codec *codec, int pin, int muted)
1249{
1250 unsigned int gpiostate, gpiomask, gpiodir;
1251
1252 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
1253 AC_VERB_GET_GPIO_DATA, 0);
1254
1255 if (!muted)
1256 gpiostate |= (1 << pin);
1257 else
1258 gpiostate &= ~(1 << pin);
1259
1260 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
1261 AC_VERB_GET_GPIO_MASK, 0);
1262 gpiomask |= (1 << pin);
1263
1264 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
1265 AC_VERB_GET_GPIO_DIRECTION, 0);
1266 gpiodir |= (1 << pin);
1267
1268 /* AppleHDA seems to do this -- WTF is this verb?? */
1269 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
1270
1271 snd_hda_codec_write(codec, codec->afg, 0,
1272 AC_VERB_SET_GPIO_MASK, gpiomask);
1273 snd_hda_codec_write(codec, codec->afg, 0,
1274 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
1275
1276 msleep(1);
1277
1278 snd_hda_codec_write(codec, codec->afg, 0,
1279 AC_VERB_SET_GPIO_DATA, gpiostate);
1280}
1281
Mattc7d4b2f2005-06-27 14:59:41 +02001282static int stac92xx_init(struct hda_codec *codec)
1283{
1284 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai82bc9552006-03-21 11:24:42 +01001285 struct auto_pin_cfg *cfg = &spec->autocfg;
1286 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02001287
Mattc7d4b2f2005-06-27 14:59:41 +02001288 snd_hda_sequence_write(codec, spec->init);
1289
Takashi Iwai82bc9552006-03-21 11:24:42 +01001290 /* set up pins */
1291 if (spec->hp_detect) {
Takashi Iwai505cb342006-03-27 12:51:52 +02001292 /* Enable unsolicited responses on the HP widget */
1293 snd_hda_codec_write(codec, cfg->hp_pin, 0,
1294 AC_VERB_SET_UNSOLICITED_ENABLE,
1295 STAC_UNSOL_ENABLE);
Takashi Iwai82bc9552006-03-21 11:24:42 +01001296 /* fake event to set up pins */
1297 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
Tobin Davis68a6abd2006-08-21 19:02:10 +02001298 /* enable the headphones by default. If/when unsol_event detection works, this will be ignored */
1299 stac92xx_auto_init_hp_out(codec);
Takashi Iwai82bc9552006-03-21 11:24:42 +01001300 } else {
1301 stac92xx_auto_init_multi_out(codec);
1302 stac92xx_auto_init_hp_out(codec);
1303 }
1304 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwaic960a032006-03-23 17:06:28 +01001305 hda_nid_t nid = cfg->input_pins[i];
1306 if (nid) {
1307 unsigned int pinctl = AC_PINCTL_IN_EN;
1308 if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC)
1309 pinctl |= stac92xx_get_vref(codec, nid);
1310 stac92xx_auto_set_pinctl(codec, nid, pinctl);
1311 }
Takashi Iwai82bc9552006-03-21 11:24:42 +01001312 }
1313 if (cfg->dig_out_pin)
1314 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pin,
1315 AC_PINCTL_OUT_EN);
1316 if (cfg->dig_in_pin)
1317 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
1318 AC_PINCTL_IN_EN);
1319
Sam Revitch62fe78e2006-05-10 15:09:17 +02001320 if (spec->gpio_mute) {
1321 stac922x_gpio_mute(codec, 0, 0);
1322 stac922x_gpio_mute(codec, 1, 0);
1323 }
1324
Mattc7d4b2f2005-06-27 14:59:41 +02001325 return 0;
1326}
1327
Matt2f2f4252005-04-13 14:45:30 +02001328static void stac92xx_free(struct hda_codec *codec)
1329{
Mattc7d4b2f2005-06-27 14:59:41 +02001330 struct sigmatel_spec *spec = codec->spec;
1331 int i;
1332
1333 if (! spec)
1334 return;
1335
1336 if (spec->kctl_alloc) {
1337 for (i = 0; i < spec->num_kctl_used; i++)
1338 kfree(spec->kctl_alloc[i].name);
1339 kfree(spec->kctl_alloc);
1340 }
1341
Richard Fish11b44bb2006-08-23 18:31:34 +02001342 if (spec->bios_pin_configs)
1343 kfree(spec->bios_pin_configs);
1344
Mattc7d4b2f2005-06-27 14:59:41 +02001345 kfree(spec);
Matt2f2f4252005-04-13 14:45:30 +02001346}
1347
Matt4e550962005-07-04 17:51:39 +02001348static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
1349 unsigned int flag)
1350{
1351 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
1352 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
1353 snd_hda_codec_write(codec, nid, 0,
1354 AC_VERB_SET_PIN_WIDGET_CONTROL,
1355 pin_ctl | flag);
1356}
1357
1358static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
1359 unsigned int flag)
1360{
1361 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
1362 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
1363 snd_hda_codec_write(codec, nid, 0,
1364 AC_VERB_SET_PIN_WIDGET_CONTROL,
1365 pin_ctl & ~flag);
1366}
1367
1368static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
1369{
1370 struct sigmatel_spec *spec = codec->spec;
1371 struct auto_pin_cfg *cfg = &spec->autocfg;
1372 int i, presence;
1373
1374 if ((res >> 26) != STAC_HP_EVENT)
1375 return;
1376
1377 presence = snd_hda_codec_read(codec, cfg->hp_pin, 0,
1378 AC_VERB_GET_PIN_SENSE, 0x00) >> 31;
1379
1380 if (presence) {
1381 /* disable lineouts, enable hp */
1382 for (i = 0; i < cfg->line_outs; i++)
1383 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
1384 AC_PINCTL_OUT_EN);
1385 stac92xx_set_pinctl(codec, cfg->hp_pin, AC_PINCTL_OUT_EN);
1386 } else {
1387 /* enable lineouts, disable hp */
1388 for (i = 0; i < cfg->line_outs; i++)
1389 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
1390 AC_PINCTL_OUT_EN);
1391 stac92xx_reset_pinctl(codec, cfg->hp_pin, AC_PINCTL_OUT_EN);
1392 }
1393}
1394
Mattff6fdc32005-06-27 15:06:52 +02001395#ifdef CONFIG_PM
1396static int stac92xx_resume(struct hda_codec *codec)
1397{
1398 struct sigmatel_spec *spec = codec->spec;
1399 int i;
1400
1401 stac92xx_init(codec);
Richard Fish11b44bb2006-08-23 18:31:34 +02001402 stac92xx_set_config_regs(codec);
Mattff6fdc32005-06-27 15:06:52 +02001403 for (i = 0; i < spec->num_mixers; i++)
1404 snd_hda_resume_ctls(codec, spec->mixers[i]);
1405 if (spec->multiout.dig_out_nid)
1406 snd_hda_resume_spdif_out(codec);
1407 if (spec->dig_in_nid)
1408 snd_hda_resume_spdif_in(codec);
1409
1410 return 0;
1411}
1412#endif
1413
Matt2f2f4252005-04-13 14:45:30 +02001414static struct hda_codec_ops stac92xx_patch_ops = {
1415 .build_controls = stac92xx_build_controls,
1416 .build_pcms = stac92xx_build_pcms,
1417 .init = stac92xx_init,
1418 .free = stac92xx_free,
Matt4e550962005-07-04 17:51:39 +02001419 .unsol_event = stac92xx_unsol_event,
Mattff6fdc32005-06-27 15:06:52 +02001420#ifdef CONFIG_PM
1421 .resume = stac92xx_resume,
1422#endif
Matt2f2f4252005-04-13 14:45:30 +02001423};
1424
1425static int patch_stac9200(struct hda_codec *codec)
1426{
1427 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02001428 int err;
Matt2f2f4252005-04-13 14:45:30 +02001429
Takashi Iwaie560d8d2005-09-09 14:21:46 +02001430 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02001431 if (spec == NULL)
1432 return -ENOMEM;
1433
1434 codec->spec = spec;
Richard Fish11b44bb2006-08-23 18:31:34 +02001435 spec->num_pins = 8;
1436 spec->pin_nids = stac9200_pin_nids;
Matt Porter403d1942005-11-29 15:00:51 +01001437 spec->board_config = snd_hda_check_board_config(codec, stac9200_cfg_tbl);
Richard Fish11b44bb2006-08-23 18:31:34 +02001438 if (spec->board_config < 0) {
1439 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9200, using BIOS defaults\n");
1440 err = stac92xx_save_bios_config_regs(codec);
1441 if (err < 0) {
1442 stac92xx_free(codec);
1443 return err;
1444 }
1445 spec->pin_configs = spec->bios_pin_configs;
1446 } else {
Matt Porter403d1942005-11-29 15:00:51 +01001447 spec->pin_configs = stac9200_brd_tbl[spec->board_config];
1448 stac92xx_set_config_regs(codec);
1449 }
Matt2f2f4252005-04-13 14:45:30 +02001450
1451 spec->multiout.max_channels = 2;
1452 spec->multiout.num_dacs = 1;
1453 spec->multiout.dac_nids = stac9200_dac_nids;
1454 spec->adc_nids = stac9200_adc_nids;
1455 spec->mux_nids = stac9200_mux_nids;
Mattdabbed62005-06-14 10:19:34 +02001456 spec->num_muxes = 1;
Mattc7d4b2f2005-06-27 14:59:41 +02001457
1458 spec->init = stac9200_core_init;
Matt2f2f4252005-04-13 14:45:30 +02001459 spec->mixer = stac9200_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02001460
1461 err = stac9200_parse_auto_config(codec);
1462 if (err < 0) {
1463 stac92xx_free(codec);
1464 return err;
1465 }
Matt2f2f4252005-04-13 14:45:30 +02001466
1467 codec->patch_ops = stac92xx_patch_ops;
1468
1469 return 0;
1470}
1471
1472static int patch_stac922x(struct hda_codec *codec)
1473{
1474 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02001475 int err;
Matt2f2f4252005-04-13 14:45:30 +02001476
Takashi Iwaie560d8d2005-09-09 14:21:46 +02001477 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02001478 if (spec == NULL)
1479 return -ENOMEM;
1480
1481 codec->spec = spec;
Richard Fish11b44bb2006-08-23 18:31:34 +02001482 spec->num_pins = 10;
1483 spec->pin_nids = stac922x_pin_nids;
Matt Porter403d1942005-11-29 15:00:51 +01001484 spec->board_config = snd_hda_check_board_config(codec, stac922x_cfg_tbl);
Richard Fish11b44bb2006-08-23 18:31:34 +02001485 if (spec->board_config < 0) {
1486 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC922x, "
1487 "using BIOS defaults\n");
1488 err = stac92xx_save_bios_config_regs(codec);
1489 if (err < 0) {
1490 stac92xx_free(codec);
1491 return err;
1492 }
1493 spec->pin_configs = spec->bios_pin_configs;
1494 } else if (stac922x_brd_tbl[spec->board_config] != NULL) {
Matt Porter403d1942005-11-29 15:00:51 +01001495 spec->pin_configs = stac922x_brd_tbl[spec->board_config];
1496 stac92xx_set_config_regs(codec);
1497 }
Matt2f2f4252005-04-13 14:45:30 +02001498
Matt2f2f4252005-04-13 14:45:30 +02001499 spec->adc_nids = stac922x_adc_nids;
1500 spec->mux_nids = stac922x_mux_nids;
Mattdabbed62005-06-14 10:19:34 +02001501 spec->num_muxes = 2;
Mattc7d4b2f2005-06-27 14:59:41 +02001502
1503 spec->init = stac922x_core_init;
Matt2f2f4252005-04-13 14:45:30 +02001504 spec->mixer = stac922x_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02001505
1506 spec->multiout.dac_nids = spec->dac_nids;
Takashi Iwai19039bd2006-06-28 15:52:16 +02001507
Matt Porter3cc08dc2006-01-23 15:27:49 +01001508 err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
1509 if (err < 0) {
1510 stac92xx_free(codec);
1511 return err;
1512 }
1513
Sam Revitch62fe78e2006-05-10 15:09:17 +02001514 if (spec->board_config == STAC_MACMINI)
1515 spec->gpio_mute = 1;
1516
Matt Porter3cc08dc2006-01-23 15:27:49 +01001517 codec->patch_ops = stac92xx_patch_ops;
1518
1519 return 0;
1520}
1521
1522static int patch_stac927x(struct hda_codec *codec)
1523{
1524 struct sigmatel_spec *spec;
1525 int err;
1526
1527 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1528 if (spec == NULL)
1529 return -ENOMEM;
1530
1531 codec->spec = spec;
Richard Fish11b44bb2006-08-23 18:31:34 +02001532 spec->num_pins = 14;
1533 spec->pin_nids = stac927x_pin_nids;
Matt Porter3cc08dc2006-01-23 15:27:49 +01001534 spec->board_config = snd_hda_check_board_config(codec, stac927x_cfg_tbl);
Richard Fish11b44bb2006-08-23 18:31:34 +02001535 if (spec->board_config < 0) {
Matt Porter3cc08dc2006-01-23 15:27:49 +01001536 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC927x, using BIOS defaults\n");
Richard Fish11b44bb2006-08-23 18:31:34 +02001537 err = stac92xx_save_bios_config_regs(codec);
1538 if (err < 0) {
1539 stac92xx_free(codec);
1540 return err;
1541 }
1542 spec->pin_configs = spec->bios_pin_configs;
1543 } else if (stac927x_brd_tbl[spec->board_config] != NULL) {
Matt Porter3cc08dc2006-01-23 15:27:49 +01001544 spec->pin_configs = stac927x_brd_tbl[spec->board_config];
1545 stac92xx_set_config_regs(codec);
1546 }
1547
Tobin Davis81d3dbd2006-08-22 19:44:45 +02001548 switch (spec->board_config) {
1549 case STAC_D965_2112:
1550 spec->adc_nids = stac927x_adc_nids;
1551 spec->mux_nids = stac927x_mux_nids;
1552 spec->num_muxes = 3;
1553 spec->init = d965_2112_core_init;
1554 spec->mixer = stac9227_mixer;
1555 break;
1556 case STAC_D965_284B:
1557 spec->adc_nids = stac9227_adc_nids;
1558 spec->mux_nids = stac9227_mux_nids;
1559 spec->num_muxes = 2;
1560 spec->init = stac9227_core_init;
1561 spec->mixer = stac9227_mixer;
1562 break;
1563 default:
1564 spec->adc_nids = stac927x_adc_nids;
1565 spec->mux_nids = stac927x_mux_nids;
1566 spec->num_muxes = 3;
1567 spec->init = stac927x_core_init;
1568 spec->mixer = stac927x_mixer;
1569 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01001570
1571 spec->multiout.dac_nids = spec->dac_nids;
1572
1573 err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
Mattc7d4b2f2005-06-27 14:59:41 +02001574 if (err < 0) {
1575 stac92xx_free(codec);
1576 return err;
1577 }
Matt2f2f4252005-04-13 14:45:30 +02001578
1579 codec->patch_ops = stac92xx_patch_ops;
1580
1581 return 0;
1582}
1583
Matt Porterf3302a52006-07-31 12:49:34 +02001584static int patch_stac9205(struct hda_codec *codec)
1585{
1586 struct sigmatel_spec *spec;
1587 int err;
1588
1589 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1590 if (spec == NULL)
1591 return -ENOMEM;
1592
1593 codec->spec = spec;
Richard Fish11b44bb2006-08-23 18:31:34 +02001594 spec->num_pins = 14;
1595 spec->pin_nids = stac9205_pin_nids;
Matt Porterf3302a52006-07-31 12:49:34 +02001596 spec->board_config = snd_hda_check_board_config(codec, stac9205_cfg_tbl);
Richard Fish11b44bb2006-08-23 18:31:34 +02001597 if (spec->board_config < 0) {
1598 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9205, using BIOS defaults\n");
1599 err = stac92xx_save_bios_config_regs(codec);
1600 if (err < 0) {
1601 stac92xx_free(codec);
1602 return err;
1603 }
1604 spec->pin_configs = spec->bios_pin_configs;
1605 } else {
Matt Porterf3302a52006-07-31 12:49:34 +02001606 spec->pin_configs = stac9205_brd_tbl[spec->board_config];
1607 stac92xx_set_config_regs(codec);
1608 }
1609
1610 spec->adc_nids = stac9205_adc_nids;
1611 spec->mux_nids = stac9205_mux_nids;
1612 spec->num_muxes = 3;
1613
1614 spec->init = stac9205_core_init;
1615 spec->mixer = stac9205_mixer;
1616
1617 spec->multiout.dac_nids = spec->dac_nids;
1618
1619 err = stac92xx_parse_auto_config(codec, 0x1f, 0x20);
1620 if (err < 0) {
1621 stac92xx_free(codec);
1622 return err;
1623 }
1624
1625 codec->patch_ops = stac92xx_patch_ops;
1626
1627 return 0;
1628}
1629
Matt2f2f4252005-04-13 14:45:30 +02001630/*
Guillaume Munch6d859062006-08-22 17:15:47 +02001631 * STAC9872 hack
Takashi Iwaidb064e52006-03-16 16:04:58 +01001632 */
1633
Guillaume Munch99ccc562006-08-16 19:35:12 +02001634/* static config for Sony VAIO FE550G and Sony VAIO AR */
Takashi Iwaidb064e52006-03-16 16:04:58 +01001635static hda_nid_t vaio_dacs[] = { 0x2 };
1636#define VAIO_HP_DAC 0x5
1637static hda_nid_t vaio_adcs[] = { 0x8 /*,0x6*/ };
1638static hda_nid_t vaio_mux_nids[] = { 0x15 };
1639
1640static struct hda_input_mux vaio_mux = {
1641 .num_items = 2,
1642 .items = {
Takashi Iwaid7737812006-04-25 13:05:43 +02001643 /* { "HP", 0x0 }, */
1644 { "Line", 0x1 },
Takashi Iwaidb064e52006-03-16 16:04:58 +01001645 { "Mic", 0x2 },
1646 { "PCM", 0x3 },
1647 }
1648};
1649
1650static struct hda_verb vaio_init[] = {
1651 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
1652 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
1653 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
1654 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
1655 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
1656 {0x15, AC_VERB_SET_CONNECT_SEL, 0x2}, /* mic-sel: 0a,0d,14,02 */
1657 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
1658 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
1659 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
1660 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
1661 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
1662 {}
1663};
1664
Guillaume Munch6d859062006-08-22 17:15:47 +02001665static struct hda_verb vaio_ar_init[] = {
1666 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
1667 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
1668 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
1669 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
1670/* {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },*/ /* Optical Out */
1671 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
1672 {0x15, AC_VERB_SET_CONNECT_SEL, 0x2}, /* mic-sel: 0a,0d,14,02 */
1673 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
1674 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
1675/* {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},*/ /* Optical Out */
1676 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
1677 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
1678 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
1679 {}
1680};
1681
Takashi Iwaidb064e52006-03-16 16:04:58 +01001682/* bind volumes of both NID 0x02 and 0x05 */
1683static int vaio_master_vol_put(struct snd_kcontrol *kcontrol,
1684 struct snd_ctl_elem_value *ucontrol)
1685{
1686 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1687 long *valp = ucontrol->value.integer.value;
1688 int change;
1689
1690 change = snd_hda_codec_amp_update(codec, 0x02, 0, HDA_OUTPUT, 0,
1691 0x7f, valp[0] & 0x7f);
1692 change |= snd_hda_codec_amp_update(codec, 0x02, 1, HDA_OUTPUT, 0,
1693 0x7f, valp[1] & 0x7f);
1694 snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
1695 0x7f, valp[0] & 0x7f);
1696 snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
1697 0x7f, valp[1] & 0x7f);
1698 return change;
1699}
1700
1701/* bind volumes of both NID 0x02 and 0x05 */
1702static int vaio_master_sw_put(struct snd_kcontrol *kcontrol,
1703 struct snd_ctl_elem_value *ucontrol)
1704{
1705 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1706 long *valp = ucontrol->value.integer.value;
1707 int change;
1708
1709 change = snd_hda_codec_amp_update(codec, 0x02, 0, HDA_OUTPUT, 0,
Takashi Iwaia9393d72006-05-03 11:59:03 +02001710 0x80, (valp[0] ? 0 : 0x80));
Takashi Iwaidb064e52006-03-16 16:04:58 +01001711 change |= snd_hda_codec_amp_update(codec, 0x02, 1, HDA_OUTPUT, 0,
Takashi Iwaia9393d72006-05-03 11:59:03 +02001712 0x80, (valp[1] ? 0 : 0x80));
Takashi Iwaidb064e52006-03-16 16:04:58 +01001713 snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
Takashi Iwaia9393d72006-05-03 11:59:03 +02001714 0x80, (valp[0] ? 0 : 0x80));
Takashi Iwaidb064e52006-03-16 16:04:58 +01001715 snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
Takashi Iwaia9393d72006-05-03 11:59:03 +02001716 0x80, (valp[1] ? 0 : 0x80));
Takashi Iwaidb064e52006-03-16 16:04:58 +01001717 return change;
1718}
1719
1720static struct snd_kcontrol_new vaio_mixer[] = {
1721 {
1722 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1723 .name = "Master Playback Volume",
1724 .info = snd_hda_mixer_amp_volume_info,
1725 .get = snd_hda_mixer_amp_volume_get,
1726 .put = vaio_master_vol_put,
Takashi Iwaic2566522006-08-17 18:21:36 +02001727 .tlv = { .c = snd_hda_mixer_amp_tlv },
Takashi Iwaidb064e52006-03-16 16:04:58 +01001728 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
1729 },
1730 {
1731 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1732 .name = "Master Playback Switch",
1733 .info = snd_hda_mixer_amp_switch_info,
1734 .get = snd_hda_mixer_amp_switch_get,
1735 .put = vaio_master_sw_put,
1736 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
1737 },
1738 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
1739 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
1740 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
1741 {
1742 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1743 .name = "Capture Source",
1744 .count = 1,
1745 .info = stac92xx_mux_enum_info,
1746 .get = stac92xx_mux_enum_get,
1747 .put = stac92xx_mux_enum_put,
1748 },
1749 {}
1750};
1751
Guillaume Munch6d859062006-08-22 17:15:47 +02001752static struct snd_kcontrol_new vaio_ar_mixer[] = {
1753 {
1754 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1755 .name = "Master Playback Volume",
1756 .info = snd_hda_mixer_amp_volume_info,
1757 .get = snd_hda_mixer_amp_volume_get,
1758 .put = vaio_master_vol_put,
1759 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
1760 },
1761 {
1762 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1763 .name = "Master Playback Switch",
1764 .info = snd_hda_mixer_amp_switch_info,
1765 .get = snd_hda_mixer_amp_switch_get,
1766 .put = vaio_master_sw_put,
1767 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
1768 },
1769 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
1770 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
1771 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
1772 /*HDA_CODEC_MUTE("Optical Out Switch", 0x10, 0, HDA_OUTPUT),
1773 HDA_CODEC_VOLUME("Optical Out Volume", 0x10, 0, HDA_OUTPUT),*/
1774 {
1775 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1776 .name = "Capture Source",
1777 .count = 1,
1778 .info = stac92xx_mux_enum_info,
1779 .get = stac92xx_mux_enum_get,
1780 .put = stac92xx_mux_enum_put,
1781 },
1782 {}
1783};
1784
1785static struct hda_codec_ops stac9872_patch_ops = {
Takashi Iwaidb064e52006-03-16 16:04:58 +01001786 .build_controls = stac92xx_build_controls,
1787 .build_pcms = stac92xx_build_pcms,
1788 .init = stac92xx_init,
1789 .free = stac92xx_free,
1790#ifdef CONFIG_PM
1791 .resume = stac92xx_resume,
1792#endif
1793};
1794
Guillaume Munch6d859062006-08-22 17:15:47 +02001795enum { /* FE and SZ series. id=0x83847661 and subsys=0x104D0700 or 104D1000. */
1796 CXD9872RD_VAIO,
1797 /* Unknown. id=0x83847662 and subsys=0x104D1200 or 104D1000. */
1798 STAC9872AK_VAIO,
1799 /* Unknown. id=0x83847661 and subsys=0x104D1200. */
1800 STAC9872K_VAIO,
1801 /* AR Series. id=0x83847664 and subsys=104D1300 */
1802 CXD9872AKD_VAIO
1803 };
Takashi Iwaidb064e52006-03-16 16:04:58 +01001804
Guillaume Munch6d859062006-08-22 17:15:47 +02001805static struct hda_board_config stac9872_cfg_tbl[] = {
1806 { .modelname = "vaio", .config = CXD9872RD_VAIO },
1807 { .modelname = "vaio-ar", .config = CXD9872AKD_VAIO },
Takashi Iwaidb064e52006-03-16 16:04:58 +01001808 { .pci_subvendor = 0x104d, .pci_subdevice = 0x81e6,
Guillaume Munch6d859062006-08-22 17:15:47 +02001809 .config = CXD9872RD_VAIO },
Takashi Iwaidb064e52006-03-16 16:04:58 +01001810 { .pci_subvendor = 0x104d, .pci_subdevice = 0x81ef,
Guillaume Munch6d859062006-08-22 17:15:47 +02001811 .config = CXD9872RD_VAIO },
Guillaume Munch99ccc562006-08-16 19:35:12 +02001812 { .pci_subvendor = 0x104d, .pci_subdevice = 0x81fd,
Guillaume Munch6d859062006-08-22 17:15:47 +02001813 .config = CXD9872AKD_VAIO },
Takashi Iwaidb064e52006-03-16 16:04:58 +01001814 {}
1815};
1816
Guillaume Munch6d859062006-08-22 17:15:47 +02001817static int patch_stac9872(struct hda_codec *codec)
Takashi Iwaidb064e52006-03-16 16:04:58 +01001818{
1819 struct sigmatel_spec *spec;
1820 int board_config;
1821
Guillaume Munch6d859062006-08-22 17:15:47 +02001822 board_config = snd_hda_check_board_config(codec, stac9872_cfg_tbl);
Takashi Iwaidb064e52006-03-16 16:04:58 +01001823 if (board_config < 0)
1824 /* unknown config, let generic-parser do its job... */
1825 return snd_hda_parse_generic_codec(codec);
1826
1827 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1828 if (spec == NULL)
1829 return -ENOMEM;
1830
1831 codec->spec = spec;
1832 switch (board_config) {
Guillaume Munch6d859062006-08-22 17:15:47 +02001833 case CXD9872RD_VAIO:
1834 case STAC9872AK_VAIO:
1835 case STAC9872K_VAIO:
Takashi Iwaidb064e52006-03-16 16:04:58 +01001836 spec->mixer = vaio_mixer;
1837 spec->init = vaio_init;
1838 spec->multiout.max_channels = 2;
1839 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
1840 spec->multiout.dac_nids = vaio_dacs;
1841 spec->multiout.hp_nid = VAIO_HP_DAC;
1842 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
1843 spec->adc_nids = vaio_adcs;
1844 spec->input_mux = &vaio_mux;
1845 spec->mux_nids = vaio_mux_nids;
1846 break;
Guillaume Munch6d859062006-08-22 17:15:47 +02001847
1848 case CXD9872AKD_VAIO:
1849 spec->mixer = vaio_ar_mixer;
1850 spec->init = vaio_ar_init;
1851 spec->multiout.max_channels = 2;
1852 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
1853 spec->multiout.dac_nids = vaio_dacs;
1854 spec->multiout.hp_nid = VAIO_HP_DAC;
1855 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
1856 spec->adc_nids = vaio_adcs;
1857 spec->input_mux = &vaio_mux;
1858 spec->mux_nids = vaio_mux_nids;
1859 break;
Takashi Iwaidb064e52006-03-16 16:04:58 +01001860 }
1861
Guillaume Munch6d859062006-08-22 17:15:47 +02001862 codec->patch_ops = stac9872_patch_ops;
Takashi Iwaidb064e52006-03-16 16:04:58 +01001863 return 0;
1864}
1865
1866
1867/*
Matt2f2f4252005-04-13 14:45:30 +02001868 * patch entries
1869 */
1870struct hda_codec_preset snd_hda_preset_sigmatel[] = {
1871 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
1872 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
1873 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
1874 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
1875 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
1876 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
1877 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
Matt Porter22a27c72006-07-06 18:49:10 +02001878 { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
1879 { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
1880 { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
1881 { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
1882 { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
1883 { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
Matt Porter3cc08dc2006-01-23 15:27:49 +01001884 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
1885 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
1886 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
1887 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
1888 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
1889 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
1890 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
1891 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
1892 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
1893 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
Guillaume Munch6d859062006-08-22 17:15:47 +02001894 /* The following does not take into account .id=0x83847661 when subsys =
1895 * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
1896 * currently not fully supported.
1897 */
1898 { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
1899 { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
1900 { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
Matt Porterf3302a52006-07-31 12:49:34 +02001901 { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
1902 { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
1903 { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
1904 { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
1905 { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
1906 { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
1907 { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
1908 { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
Matt2f2f4252005-04-13 14:45:30 +02001909 {} /* terminator */
1910};