blob: 87169032be1f2008daaf4df30b263854aa4a1b89 [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
Tobin Davis93ed1502006-09-01 21:03:12 +020045#define STAC_922X_MODELS 4 /* number of 922x models */
46#define STAC_D965_3ST 4
47#define STAC_D965_5ST 5
48#define STAC_927X_MODELS 6 /* number of 922x models */
Matt Porter403d1942005-11-29 15:00:51 +010049
Matt2f2f4252005-04-13 14:45:30 +020050struct sigmatel_spec {
Takashi Iwaic8b6bf92005-11-17 14:57:47 +010051 struct snd_kcontrol_new *mixers[4];
Mattc7d4b2f2005-06-27 14:59:41 +020052 unsigned int num_mixers;
53
Matt Porter403d1942005-11-29 15:00:51 +010054 int board_config;
Mattc7d4b2f2005-06-27 14:59:41 +020055 unsigned int surr_switch: 1;
Matt Porter403d1942005-11-29 15:00:51 +010056 unsigned int line_switch: 1;
57 unsigned int mic_switch: 1;
Matt Porter3cc08dc2006-01-23 15:27:49 +010058 unsigned int alt_switch: 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +010059 unsigned int hp_detect: 1;
Sam Revitch62fe78e2006-05-10 15:09:17 +020060 unsigned int gpio_mute: 1;
Mattc7d4b2f2005-06-27 14:59:41 +020061
Matt2f2f4252005-04-13 14:45:30 +020062 /* playback */
63 struct hda_multi_out multiout;
Matt Porter3cc08dc2006-01-23 15:27:49 +010064 hda_nid_t dac_nids[5];
Matt2f2f4252005-04-13 14:45:30 +020065
66 /* capture */
67 hda_nid_t *adc_nids;
Matt2f2f4252005-04-13 14:45:30 +020068 unsigned int num_adcs;
Mattdabbed62005-06-14 10:19:34 +020069 hda_nid_t *mux_nids;
70 unsigned int num_muxes;
Mattdabbed62005-06-14 10:19:34 +020071 hda_nid_t dig_in_nid;
Matt2f2f4252005-04-13 14:45:30 +020072
Matt2f2f4252005-04-13 14:45:30 +020073 /* pin widgets */
74 hda_nid_t *pin_nids;
75 unsigned int num_pins;
Matt2f2f4252005-04-13 14:45:30 +020076 unsigned int *pin_configs;
Richard Fish11b44bb2006-08-23 18:31:34 +020077 unsigned int *bios_pin_configs;
Matt2f2f4252005-04-13 14:45:30 +020078
79 /* codec specific stuff */
80 struct hda_verb *init;
Takashi Iwaic8b6bf92005-11-17 14:57:47 +010081 struct snd_kcontrol_new *mixer;
Matt2f2f4252005-04-13 14:45:30 +020082
83 /* capture source */
Mattc7d4b2f2005-06-27 14:59:41 +020084 struct hda_input_mux *input_mux;
Matt Porter3cc08dc2006-01-23 15:27:49 +010085 unsigned int cur_mux[3];
Matt2f2f4252005-04-13 14:45:30 +020086
Matt Porter403d1942005-11-29 15:00:51 +010087 /* i/o switches */
88 unsigned int io_switch[2];
Matt2f2f4252005-04-13 14:45:30 +020089
Mattc7d4b2f2005-06-27 14:59:41 +020090 struct hda_pcm pcm_rec[2]; /* PCM information */
91
92 /* dynamic controls and input_mux */
93 struct auto_pin_cfg autocfg;
94 unsigned int num_kctl_alloc, num_kctl_used;
Takashi Iwaic8b6bf92005-11-17 14:57:47 +010095 struct snd_kcontrol_new *kctl_alloc;
Mattc7d4b2f2005-06-27 14:59:41 +020096 struct hda_input_mux private_imux;
Matt2f2f4252005-04-13 14:45:30 +020097};
98
99static hda_nid_t stac9200_adc_nids[1] = {
100 0x03,
101};
102
103static hda_nid_t stac9200_mux_nids[1] = {
104 0x0c,
105};
106
107static hda_nid_t stac9200_dac_nids[1] = {
108 0x02,
109};
110
Matt2f2f4252005-04-13 14:45:30 +0200111static hda_nid_t stac922x_adc_nids[2] = {
112 0x06, 0x07,
113};
114
115static hda_nid_t stac922x_mux_nids[2] = {
116 0x12, 0x13,
117};
118
Matt Porter3cc08dc2006-01-23 15:27:49 +0100119static hda_nid_t stac927x_adc_nids[3] = {
120 0x07, 0x08, 0x09
121};
122
123static hda_nid_t stac927x_mux_nids[3] = {
124 0x15, 0x16, 0x17
125};
126
Matt Porterf3302a52006-07-31 12:49:34 +0200127static hda_nid_t stac9205_adc_nids[2] = {
128 0x12, 0x13
129};
130
131static hda_nid_t stac9205_mux_nids[2] = {
132 0x19, 0x1a
133};
134
Mattc7d4b2f2005-06-27 14:59:41 +0200135static hda_nid_t stac9200_pin_nids[8] = {
Tobin Davis93ed1502006-09-01 21:03:12 +0200136 0x08, 0x09, 0x0d, 0x0e,
137 0x0f, 0x10, 0x11, 0x12,
Matt2f2f4252005-04-13 14:45:30 +0200138};
139
140static hda_nid_t stac922x_pin_nids[10] = {
141 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
142 0x0f, 0x10, 0x11, 0x15, 0x1b,
143};
144
Matt Porter3cc08dc2006-01-23 15:27:49 +0100145static hda_nid_t stac927x_pin_nids[14] = {
146 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
147 0x0f, 0x10, 0x11, 0x12, 0x13,
148 0x14, 0x21, 0x22, 0x23,
149};
150
Matt Porterf3302a52006-07-31 12:49:34 +0200151static hda_nid_t stac9205_pin_nids[12] = {
152 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
153 0x0f, 0x14, 0x16, 0x17, 0x18,
154 0x21, 0x22,
155
156};
157
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100158static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Matt2f2f4252005-04-13 14:45:30 +0200159{
160 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
161 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +0200162 return snd_hda_input_mux_info(spec->input_mux, uinfo);
Matt2f2f4252005-04-13 14:45:30 +0200163}
164
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100165static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200166{
167 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
168 struct sigmatel_spec *spec = codec->spec;
169 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
170
171 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
172 return 0;
173}
174
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100175static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200176{
177 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
178 struct sigmatel_spec *spec = codec->spec;
179 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
180
Mattc7d4b2f2005-06-27 14:59:41 +0200181 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
Matt2f2f4252005-04-13 14:45:30 +0200182 spec->mux_nids[adc_idx], &spec->cur_mux[adc_idx]);
183}
184
Mattc7d4b2f2005-06-27 14:59:41 +0200185static struct hda_verb stac9200_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200186 /* set dac0mux for dac converter */
Mattc7d4b2f2005-06-27 14:59:41 +0200187 { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
Matt2f2f4252005-04-13 14:45:30 +0200188 {}
189};
190
Mattc7d4b2f2005-06-27 14:59:41 +0200191static struct hda_verb stac922x_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200192 /* set master volume and direct control */
Mattc7d4b2f2005-06-27 14:59:41 +0200193 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matt2f2f4252005-04-13 14:45:30 +0200194 {}
195};
196
Tobin Davis93ed1502006-09-01 21:03:12 +0200197static struct hda_verb d965_core_init[] = {
Takashi Iwai19039bd2006-06-28 15:52:16 +0200198 /* set master volume and direct control */
Tobin Davis93ed1502006-09-01 21:03:12 +0200199 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Takashi Iwai19039bd2006-06-28 15:52:16 +0200200 /* unmute node 0x1b */
201 { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
202 /* select node 0x03 as DAC */
203 { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
204 {}
205};
206
Matt Porter3cc08dc2006-01-23 15:27:49 +0100207static struct hda_verb stac927x_core_init[] = {
208 /* set master volume and direct control */
209 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
210 {}
211};
212
Matt Porterf3302a52006-07-31 12:49:34 +0200213static struct hda_verb stac9205_core_init[] = {
214 /* set master volume and direct control */
215 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
216 {}
217};
218
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100219static struct snd_kcontrol_new stac9200_mixer[] = {
Matt2f2f4252005-04-13 14:45:30 +0200220 HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
221 HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
222 {
223 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
224 .name = "Input Source",
225 .count = 1,
226 .info = stac92xx_mux_enum_info,
227 .get = stac92xx_mux_enum_get,
228 .put = stac92xx_mux_enum_put,
229 },
230 HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
231 HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
Mattc7d4b2f2005-06-27 14:59:41 +0200232 HDA_CODEC_VOLUME("Capture Mux Volume", 0x0c, 0, HDA_OUTPUT),
Matt2f2f4252005-04-13 14:45:30 +0200233 { } /* end */
234};
235
Mattc7d4b2f2005-06-27 14:59:41 +0200236/* This needs to be generated dynamically based on sequence */
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100237static struct snd_kcontrol_new stac922x_mixer[] = {
Matt2f2f4252005-04-13 14:45:30 +0200238 {
239 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
240 .name = "Input Source",
241 .count = 1,
242 .info = stac92xx_mux_enum_info,
243 .get = stac92xx_mux_enum_get,
244 .put = stac92xx_mux_enum_put,
245 },
246 HDA_CODEC_VOLUME("Capture Volume", 0x17, 0x0, HDA_INPUT),
Takashi Iwai0fd17082006-01-13 18:46:21 +0100247 HDA_CODEC_MUTE("Capture Switch", 0x17, 0x0, HDA_INPUT),
Matt2f2f4252005-04-13 14:45:30 +0200248 HDA_CODEC_VOLUME("Mux Capture Volume", 0x12, 0x0, HDA_OUTPUT),
249 { } /* end */
250};
251
Takashi Iwai19039bd2006-06-28 15:52:16 +0200252/* This needs to be generated dynamically based on sequence */
253static struct snd_kcontrol_new stac9227_mixer[] = {
254 {
255 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
256 .name = "Input Source",
257 .count = 1,
258 .info = stac92xx_mux_enum_info,
259 .get = stac92xx_mux_enum_get,
260 .put = stac92xx_mux_enum_put,
261 },
262 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
263 HDA_CODEC_MUTE("Capture Switch", 0x1b, 0x0, HDA_OUTPUT),
264 { } /* end */
265};
266
Matt Porter3cc08dc2006-01-23 15:27:49 +0100267static snd_kcontrol_new_t stac927x_mixer[] = {
268 {
269 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
270 .name = "Input Source",
271 .count = 1,
272 .info = stac92xx_mux_enum_info,
273 .get = stac92xx_mux_enum_get,
274 .put = stac92xx_mux_enum_put,
275 },
276 HDA_CODEC_VOLUME("InMux Capture Volume", 0x15, 0x0, HDA_OUTPUT),
277 HDA_CODEC_VOLUME("InVol Capture Volume", 0x18, 0x0, HDA_INPUT),
278 HDA_CODEC_MUTE("ADCMux Capture Switch", 0x1b, 0x0, HDA_OUTPUT),
279 { } /* end */
280};
281
Matt Porterf3302a52006-07-31 12:49:34 +0200282static snd_kcontrol_new_t stac9205_mixer[] = {
283 {
284 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
285 .name = "Input Source",
286 .count = 1,
287 .info = stac92xx_mux_enum_info,
288 .get = stac92xx_mux_enum_get,
289 .put = stac92xx_mux_enum_put,
290 },
291 HDA_CODEC_VOLUME("InMux Capture Volume", 0x19, 0x0, HDA_OUTPUT),
292 HDA_CODEC_VOLUME("InVol Capture Volume", 0x1b, 0x0, HDA_INPUT),
293 HDA_CODEC_MUTE("ADCMux Capture Switch", 0x1d, 0x0, HDA_OUTPUT),
294 { } /* end */
295};
296
Matt2f2f4252005-04-13 14:45:30 +0200297static int stac92xx_build_controls(struct hda_codec *codec)
298{
299 struct sigmatel_spec *spec = codec->spec;
300 int err;
Mattc7d4b2f2005-06-27 14:59:41 +0200301 int i;
Matt2f2f4252005-04-13 14:45:30 +0200302
303 err = snd_hda_add_new_ctls(codec, spec->mixer);
304 if (err < 0)
305 return err;
Mattc7d4b2f2005-06-27 14:59:41 +0200306
307 for (i = 0; i < spec->num_mixers; i++) {
308 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
309 if (err < 0)
310 return err;
311 }
312
Mattdabbed62005-06-14 10:19:34 +0200313 if (spec->multiout.dig_out_nid) {
314 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
315 if (err < 0)
316 return err;
317 }
318 if (spec->dig_in_nid) {
319 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
320 if (err < 0)
321 return err;
322 }
323 return 0;
Matt2f2f4252005-04-13 14:45:30 +0200324}
325
Matt Porter403d1942005-11-29 15:00:51 +0100326static unsigned int ref9200_pin_configs[8] = {
Mattdabbed62005-06-14 10:19:34 +0200327 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
Matt2f2f4252005-04-13 14:45:30 +0200328 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
329};
330
Matt Porter403d1942005-11-29 15:00:51 +0100331static unsigned int *stac9200_brd_tbl[] = {
332 ref9200_pin_configs,
333};
334
335static struct hda_board_config stac9200_cfg_tbl[] = {
336 { .modelname = "ref",
337 .pci_subvendor = PCI_VENDOR_ID_INTEL,
338 .pci_subdevice = 0x2668, /* DFI LanParty */
339 .config = STAC_REF },
340 {} /* terminator */
341};
342
343static unsigned int ref922x_pin_configs[10] = {
344 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
345 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
Matt2f2f4252005-04-13 14:45:30 +0200346 0x40000100, 0x40000100,
347};
348
Matt Porter403d1942005-11-29 15:00:51 +0100349static unsigned int d945gtp3_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +0100350 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
Matt Porter403d1942005-11-29 15:00:51 +0100351 0x40000100, 0x40000100, 0x40000100, 0x40000100,
352 0x02a19120, 0x40000100,
353};
354
355static unsigned int d945gtp5_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +0100356 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
357 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
Matt Porter403d1942005-11-29 15:00:51 +0100358 0x02a19320, 0x40000100,
359};
360
Takashi Iwai19039bd2006-06-28 15:52:16 +0200361static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
362 [STAC_REF] = ref922x_pin_configs,
363 [STAC_D945GTP3] = d945gtp3_pin_configs,
364 [STAC_D945GTP5] = d945gtp5_pin_configs,
Linus Torvalds7c3dec02006-07-10 22:21:43 -0700365 [STAC_MACMINI] = d945gtp5_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +0100366};
367
368static struct hda_board_config stac922x_cfg_tbl[] = {
Tobin Davis93ed1502006-09-01 21:03:12 +0200369 { .modelname = "5stack", .config = STAC_D945GTP5 },
370 { .modelname = "3stack", .config = STAC_D945GTP3 },
Matt Porter403d1942005-11-29 15:00:51 +0100371 { .modelname = "ref",
372 .pci_subvendor = PCI_VENDOR_ID_INTEL,
373 .pci_subdevice = 0x2668, /* DFI LanParty */
374 .config = STAC_REF }, /* SigmaTel reference board */
Tobin Davis948a4db2006-08-22 19:43:46 +0200375 /* Intel 945G based systems */
Matt Porter403d1942005-11-29 15:00:51 +0100376 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
377 .pci_subdevice = 0x0101,
378 .config = STAC_D945GTP3 }, /* Intel D945GTP - 3 Stack */
379 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
Takashi Iwai353b9e62006-02-16 18:16:17 +0100380 .pci_subdevice = 0x0202,
Tobin Davis948a4db2006-08-22 19:43:46 +0200381 .config = STAC_D945GTP3 }, /* Intel D945GNT - 3 Stack */
Takashi Iwai353b9e62006-02-16 18:16:17 +0100382 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
Tobin Davis948a4db2006-08-22 19:43:46 +0200383 .pci_subdevice = 0x0606,
384 .config = STAC_D945GTP3 }, /* Intel D945GTP - 3 Stack */
Takashi Iwai353b9e62006-02-16 18:16:17 +0100385 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
Tobin Davis948a4db2006-08-22 19:43:46 +0200386 .pci_subdevice = 0x0601,
387 .config = STAC_D945GTP3 }, /* Intel D945GTP - 3 Stack */
388 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
389 .pci_subdevice = 0x0111,
390 .config = STAC_D945GTP3 }, /* Intel D945GZP - 3 Stack */
391 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
392 .pci_subdevice = 0x1115,
393 .config = STAC_D945GTP3 }, /* Intel D945GPM - 3 Stack */
394 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
395 .pci_subdevice = 0x1116,
396 .config = STAC_D945GTP3 }, /* Intel D945GBO - 3 Stack */
397 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
398 .pci_subdevice = 0x1117,
399 .config = STAC_D945GTP3 }, /* Intel D945GPM - 3 Stack */
400 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
401 .pci_subdevice = 0x1118,
402 .config = STAC_D945GTP3 }, /* Intel D945GPM - 3 Stack */
403 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
404 .pci_subdevice = 0x1119,
405 .config = STAC_D945GTP3 }, /* Intel D945GPM - 3 Stack */
406 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
407 .pci_subdevice = 0x8826,
408 .config = STAC_D945GTP3 }, /* Intel D945GPM - 3 Stack */
409 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
410 .pci_subdevice = 0x5049,
411 .config = STAC_D945GTP3 }, /* Intel D945GCZ - 3 Stack */
412 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
413 .pci_subdevice = 0x5055,
414 .config = STAC_D945GTP3 }, /* Intel D945GCZ - 3 Stack */
415 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
416 .pci_subdevice = 0x5048,
417 .config = STAC_D945GTP3 }, /* Intel D945GPB - 3 Stack */
418 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
419 .pci_subdevice = 0x0110,
420 .config = STAC_D945GTP3 }, /* Intel D945GLR - 3 Stack */
421 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
Matt Porter403d1942005-11-29 15:00:51 +0100422 .pci_subdevice = 0x0404,
423 .config = STAC_D945GTP5 }, /* Intel D945GTP - 5 Stack */
424 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
425 .pci_subdevice = 0x0303,
426 .config = STAC_D945GTP5 }, /* Intel D945GNT - 5 Stack */
427 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
428 .pci_subdevice = 0x0013,
429 .config = STAC_D945GTP5 }, /* Intel D955XBK - 5 Stack */
Matt Porterd62c40e2006-01-23 15:26:27 +0100430 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
431 .pci_subdevice = 0x0417,
432 .config = STAC_D945GTP5 }, /* Intel D975XBK - 5 Stack */
Tobin Davis948a4db2006-08-22 19:43:46 +0200433 /* Intel 945P based systems */
434 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
435 .pci_subdevice = 0x0b0b,
436 .config = STAC_D945GTP3 }, /* Intel D945PSN - 3 Stack */
437 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
438 .pci_subdevice = 0x0112,
439 .config = STAC_D945GTP3 }, /* Intel D945PLN - 3 Stack */
440 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
441 .pci_subdevice = 0x0d0d,
442 .config = STAC_D945GTP3 }, /* Intel D945PLM - 3 Stack */
443 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
444 .pci_subdevice = 0x0909,
445 .config = STAC_D945GTP3 }, /* Intel D945PAW - 3 Stack */
446 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
447 .pci_subdevice = 0x0505,
448 .config = STAC_D945GTP3 }, /* Intel D945PLM - 3 Stack */
449 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
450 .pci_subdevice = 0x0707,
451 .config = STAC_D945GTP5 }, /* Intel D945PSV - 5 Stack */
452 /* other systems */
Sam Revitch62fe78e2006-05-10 15:09:17 +0200453 { .pci_subvendor = 0x8384,
454 .pci_subdevice = 0x7680,
455 .config = STAC_MACMINI }, /* Apple Mac Mini (early 2006) */
Matt Porter403d1942005-11-29 15:00:51 +0100456 {} /* terminator */
457};
458
Matt Porter3cc08dc2006-01-23 15:27:49 +0100459static unsigned int ref927x_pin_configs[14] = {
Tobin Davis93ed1502006-09-01 21:03:12 +0200460 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
461 0x01a19040, 0x01011012, 0x01016011, 0x0101201f,
462 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
463 0x01c42190, 0x40000100,
Matt Porter3cc08dc2006-01-23 15:27:49 +0100464};
465
Tobin Davis93ed1502006-09-01 21:03:12 +0200466static unsigned int d965_3st_pin_configs[14] = {
Tobin Davis81d3dbd2006-08-22 19:44:45 +0200467 0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
468 0x01a19021, 0x01813024, 0x40000100, 0x40000100,
469 0x40000100, 0x40000100, 0x40000100, 0x40000100,
470 0x40000100, 0x40000100
471};
472
Tobin Davis93ed1502006-09-01 21:03:12 +0200473static unsigned int d965_5st_pin_configs[14] = {
474 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
475 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
476 0x40000100, 0x40000100, 0x40000100, 0x01442070,
477 0x40000100, 0x40000100
478};
479
480static unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
Tobin Davis81d3dbd2006-08-22 19:44:45 +0200481 [STAC_REF] = ref927x_pin_configs,
Tobin Davis93ed1502006-09-01 21:03:12 +0200482 [STAC_D965_3ST] = d965_3st_pin_configs,
483 [STAC_D965_5ST] = d965_5st_pin_configs,
Matt Porter3cc08dc2006-01-23 15:27:49 +0100484};
485
486static struct hda_board_config stac927x_cfg_tbl[] = {
Tobin Davis93ed1502006-09-01 21:03:12 +0200487 { .modelname = "5stack", .config = STAC_D965_5ST },
488 { .modelname = "3stack", .config = STAC_D965_3ST },
Matt Porter3cc08dc2006-01-23 15:27:49 +0100489 { .modelname = "ref",
490 .pci_subvendor = PCI_VENDOR_ID_INTEL,
491 .pci_subdevice = 0x2668, /* DFI LanParty */
492 .config = STAC_REF }, /* SigmaTel reference board */
Tobin Davis81d3dbd2006-08-22 19:44:45 +0200493 /* Intel 946 based systems */
494 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
495 .pci_subdevice = 0x3d01,
Tobin Davis93ed1502006-09-01 21:03:12 +0200496 .config = STAC_D965_3ST }, /* D946 configuration */
Tobin Davis81d3dbd2006-08-22 19:44:45 +0200497 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
498 .pci_subdevice = 0xa301,
Tobin Davis93ed1502006-09-01 21:03:12 +0200499 .config = STAC_D965_3ST }, /* Intel D946GZT - 3 stack */
500 /* 965 based 3 stack systems */
Tobin Davis81d3dbd2006-08-22 19:44:45 +0200501 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
502 .pci_subdevice = 0x2116,
Tobin Davis93ed1502006-09-01 21:03:12 +0200503 .config = STAC_D965_3ST }, /* Intel D965 3Stack config */
Tobin Davis81d3dbd2006-08-22 19:44:45 +0200504 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
505 .pci_subdevice = 0x2115,
Tobin Davis93ed1502006-09-01 21:03:12 +0200506 .config = STAC_D965_3ST }, /* Intel DQ965WC - 3 Stack */
Tobin Davis81d3dbd2006-08-22 19:44:45 +0200507 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
508 .pci_subdevice = 0x2114,
Tobin Davis93ed1502006-09-01 21:03:12 +0200509 .config = STAC_D965_3ST }, /* Intel D965 3Stack config */
Tobin Davis81d3dbd2006-08-22 19:44:45 +0200510 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
511 .pci_subdevice = 0x2113,
Tobin Davis93ed1502006-09-01 21:03:12 +0200512 .config = STAC_D965_3ST }, /* Intel D965 3Stack config */
Tobin Davis81d3dbd2006-08-22 19:44:45 +0200513 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
514 .pci_subdevice = 0x2112,
Tobin Davis93ed1502006-09-01 21:03:12 +0200515 .config = STAC_D965_3ST }, /* Intel DG965MS - 3 Stack */
Tobin Davis81d3dbd2006-08-22 19:44:45 +0200516 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
517 .pci_subdevice = 0x2111,
Tobin Davis93ed1502006-09-01 21:03:12 +0200518 .config = STAC_D965_3ST }, /* Intel D965 3Stack config */
Tobin Davis81d3dbd2006-08-22 19:44:45 +0200519 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
520 .pci_subdevice = 0x2110,
Tobin Davis93ed1502006-09-01 21:03:12 +0200521 .config = STAC_D965_3ST }, /* Intel D965 3Stack config */
Tobin Davis81d3dbd2006-08-22 19:44:45 +0200522 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
523 .pci_subdevice = 0x2009,
Tobin Davis93ed1502006-09-01 21:03:12 +0200524 .config = STAC_D965_3ST }, /* Intel D965 3Stack config */
Tobin Davis81d3dbd2006-08-22 19:44:45 +0200525 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
526 .pci_subdevice = 0x2008,
Tobin Davis93ed1502006-09-01 21:03:12 +0200527 .config = STAC_D965_3ST }, /* Intel DQ965GF - 3 Stack */
Tobin Davis81d3dbd2006-08-22 19:44:45 +0200528 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
529 .pci_subdevice = 0x2007,
Tobin Davis93ed1502006-09-01 21:03:12 +0200530 .config = STAC_D965_3ST }, /* Intel D965 3Stack config */
Tobin Davis81d3dbd2006-08-22 19:44:45 +0200531 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
532 .pci_subdevice = 0x2006,
Tobin Davis93ed1502006-09-01 21:03:12 +0200533 .config = STAC_D965_3ST }, /* Intel D965 3Stack config */
Tobin Davis81d3dbd2006-08-22 19:44:45 +0200534 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
535 .pci_subdevice = 0x2005,
Tobin Davis93ed1502006-09-01 21:03:12 +0200536 .config = STAC_D965_3ST }, /* Intel D965 3Stack config */
Tobin Davis81d3dbd2006-08-22 19:44:45 +0200537 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
538 .pci_subdevice = 0x2004,
Tobin Davis93ed1502006-09-01 21:03:12 +0200539 .config = STAC_D965_3ST }, /* Intel D965 3Stack config */
Tobin Davis81d3dbd2006-08-22 19:44:45 +0200540 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
541 .pci_subdevice = 0x2003,
Tobin Davis93ed1502006-09-01 21:03:12 +0200542 .config = STAC_D965_3ST }, /* Intel D965 3Stack config */
Tobin Davis81d3dbd2006-08-22 19:44:45 +0200543 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
544 .pci_subdevice = 0x2002,
Tobin Davis93ed1502006-09-01 21:03:12 +0200545 .config = STAC_D965_3ST }, /* Intel D965 3Stack config */
Tobin Davis81d3dbd2006-08-22 19:44:45 +0200546 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
547 .pci_subdevice = 0x2001,
Tobin Davis93ed1502006-09-01 21:03:12 +0200548 .config = STAC_D965_3ST }, /* Intel DQ965GF - 3 Stack */
549 /* 965 based 5 stack systems */
550 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
551 .pci_subdevice = 0x2301,
552 .config = STAC_D965_5ST }, /* Intel DG965 - 5 Stack */
553 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
554 .pci_subdevice = 0x2302,
555 .config = STAC_D965_5ST }, /* Intel DG965 - 5 Stack */
556 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
557 .pci_subdevice = 0x2303,
558 .config = STAC_D965_5ST }, /* Intel DG965 - 5 Stack */
559 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
560 .pci_subdevice = 0x2304,
561 .config = STAC_D965_5ST }, /* Intel DG965 - 5 Stack */
562 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
563 .pci_subdevice = 0x2305,
564 .config = STAC_D965_5ST }, /* Intel DG965 - 5 Stack */
565 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
566 .pci_subdevice = 0x2501,
567 .config = STAC_D965_5ST }, /* Intel DG965MQ - 5 Stack */
568 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
569 .pci_subdevice = 0x2502,
570 .config = STAC_D965_5ST }, /* Intel DG965 - 5 Stack */
571 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
572 .pci_subdevice = 0x2503,
573 .config = STAC_D965_5ST }, /* Intel DG965 - 5 Stack */
574 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
575 .pci_subdevice = 0x2504,
576 .config = STAC_D965_5ST }, /* Intel DQ965GF - 5 Stack */
Matt Porter3cc08dc2006-01-23 15:27:49 +0100577 {} /* terminator */
578};
579
Matt Porterf3302a52006-07-31 12:49:34 +0200580static unsigned int ref9205_pin_configs[12] = {
581 0x40000100, 0x40000100, 0x01016011, 0x01014010,
582 0x01813122, 0x01a19021, 0x40000100, 0x40000100,
583 0x40000100, 0x40000100, 0x01441030, 0x01c41030
584};
585
586static unsigned int *stac9205_brd_tbl[] = {
587 ref9205_pin_configs,
588};
589
590static struct hda_board_config stac9205_cfg_tbl[] = {
591 { .modelname = "ref",
592 .pci_subvendor = PCI_VENDOR_ID_INTEL,
593 .pci_subdevice = 0x2668, /* DFI LanParty */
594 .config = STAC_REF }, /* SigmaTel reference board */
Takashi Iwai2c7782b2006-08-25 13:11:26 +0200595 /* Dell laptops have BIOS problem */
596 { .pci_subvendor = PCI_VENDOR_ID_DELL, .pci_subdevice = 0x01b5,
597 .config = STAC_REF }, /* Dell Inspiron 630m */
598 { .pci_subvendor = PCI_VENDOR_ID_DELL, .pci_subdevice = 0x01c2,
599 .config = STAC_REF }, /* Dell Latitude D620 */
600 { .pci_subvendor = PCI_VENDOR_ID_DELL, .pci_subdevice = 0x01cb,
601 .config = STAC_REF }, /* Dell Latitude 120L */
Matt Porterf3302a52006-07-31 12:49:34 +0200602 {} /* terminator */
603};
604
Richard Fish11b44bb2006-08-23 18:31:34 +0200605static int stac92xx_save_bios_config_regs(struct hda_codec *codec)
606{
607 int i;
608 struct sigmatel_spec *spec = codec->spec;
609
610 if (! spec->bios_pin_configs) {
611 spec->bios_pin_configs = kcalloc(spec->num_pins,
612 sizeof(*spec->bios_pin_configs), GFP_KERNEL);
613 if (! spec->bios_pin_configs)
614 return -ENOMEM;
615 }
616
617 for (i = 0; i < spec->num_pins; i++) {
618 hda_nid_t nid = spec->pin_nids[i];
619 unsigned int pin_cfg;
620
621 pin_cfg = snd_hda_codec_read(codec, nid, 0,
622 AC_VERB_GET_CONFIG_DEFAULT, 0x00);
623 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x bios pin config %8.8x\n",
624 nid, pin_cfg);
625 spec->bios_pin_configs[i] = pin_cfg;
626 }
627
628 return 0;
629}
630
Matt2f2f4252005-04-13 14:45:30 +0200631static void stac92xx_set_config_regs(struct hda_codec *codec)
632{
633 int i;
634 struct sigmatel_spec *spec = codec->spec;
635 unsigned int pin_cfg;
636
Richard Fish11b44bb2006-08-23 18:31:34 +0200637 if (! spec->pin_nids || ! spec->pin_configs)
638 return;
639
640 for (i = 0; i < spec->num_pins; i++) {
Matt2f2f4252005-04-13 14:45:30 +0200641 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
642 AC_VERB_SET_CONFIG_DEFAULT_BYTES_0,
643 spec->pin_configs[i] & 0x000000ff);
644 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
645 AC_VERB_SET_CONFIG_DEFAULT_BYTES_1,
646 (spec->pin_configs[i] & 0x0000ff00) >> 8);
647 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
648 AC_VERB_SET_CONFIG_DEFAULT_BYTES_2,
649 (spec->pin_configs[i] & 0x00ff0000) >> 16);
650 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
651 AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
652 spec->pin_configs[i] >> 24);
653 pin_cfg = snd_hda_codec_read(codec, spec->pin_nids[i], 0,
654 AC_VERB_GET_CONFIG_DEFAULT,
655 0x00);
Matt Porter403d1942005-11-29 15:00:51 +0100656 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 +0200657 }
658}
Matt2f2f4252005-04-13 14:45:30 +0200659
Matt2f2f4252005-04-13 14:45:30 +0200660/*
661 * Analog playback callbacks
662 */
663static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
664 struct hda_codec *codec,
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;
668 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
669}
670
671static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
672 struct hda_codec *codec,
673 unsigned int stream_tag,
674 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100675 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200676{
677 struct sigmatel_spec *spec = codec->spec;
Matt Porter403d1942005-11-29 15:00:51 +0100678 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
Matt2f2f4252005-04-13 14:45:30 +0200679}
680
681static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
682 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100683 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200684{
685 struct sigmatel_spec *spec = codec->spec;
686 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
687}
688
689/*
Mattdabbed62005-06-14 10:19:34 +0200690 * Digital playback callbacks
691 */
692static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
693 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100694 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +0200695{
696 struct sigmatel_spec *spec = codec->spec;
697 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
698}
699
700static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
701 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100702 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +0200703{
704 struct sigmatel_spec *spec = codec->spec;
705 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
706}
707
708
709/*
Matt2f2f4252005-04-13 14:45:30 +0200710 * Analog capture callbacks
711 */
712static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
713 struct hda_codec *codec,
714 unsigned int stream_tag,
715 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100716 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200717{
718 struct sigmatel_spec *spec = codec->spec;
719
720 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
721 stream_tag, 0, format);
722 return 0;
723}
724
725static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
726 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100727 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200728{
729 struct sigmatel_spec *spec = codec->spec;
730
731 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 0, 0, 0);
732 return 0;
733}
734
Mattdabbed62005-06-14 10:19:34 +0200735static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
736 .substreams = 1,
737 .channels_min = 2,
738 .channels_max = 2,
739 /* NID is set in stac92xx_build_pcms */
740 .ops = {
741 .open = stac92xx_dig_playback_pcm_open,
742 .close = stac92xx_dig_playback_pcm_close
743 },
744};
745
746static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
747 .substreams = 1,
748 .channels_min = 2,
749 .channels_max = 2,
750 /* NID is set in stac92xx_build_pcms */
751};
752
Matt2f2f4252005-04-13 14:45:30 +0200753static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
754 .substreams = 1,
755 .channels_min = 2,
Mattc7d4b2f2005-06-27 14:59:41 +0200756 .channels_max = 8,
Matt2f2f4252005-04-13 14:45:30 +0200757 .nid = 0x02, /* NID to query formats and rates */
758 .ops = {
759 .open = stac92xx_playback_pcm_open,
760 .prepare = stac92xx_playback_pcm_prepare,
761 .cleanup = stac92xx_playback_pcm_cleanup
762 },
763};
764
Matt Porter3cc08dc2006-01-23 15:27:49 +0100765static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
766 .substreams = 1,
767 .channels_min = 2,
768 .channels_max = 2,
769 .nid = 0x06, /* NID to query formats and rates */
770 .ops = {
771 .open = stac92xx_playback_pcm_open,
772 .prepare = stac92xx_playback_pcm_prepare,
773 .cleanup = stac92xx_playback_pcm_cleanup
774 },
775};
776
Matt2f2f4252005-04-13 14:45:30 +0200777static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
778 .substreams = 2,
779 .channels_min = 2,
780 .channels_max = 2,
Matt Porter3cc08dc2006-01-23 15:27:49 +0100781 /* NID is set in stac92xx_build_pcms */
Matt2f2f4252005-04-13 14:45:30 +0200782 .ops = {
783 .prepare = stac92xx_capture_pcm_prepare,
784 .cleanup = stac92xx_capture_pcm_cleanup
785 },
786};
787
788static int stac92xx_build_pcms(struct hda_codec *codec)
789{
790 struct sigmatel_spec *spec = codec->spec;
791 struct hda_pcm *info = spec->pcm_rec;
792
793 codec->num_pcms = 1;
794 codec->pcm_info = info;
795
Mattc7d4b2f2005-06-27 14:59:41 +0200796 info->name = "STAC92xx Analog";
Matt2f2f4252005-04-13 14:45:30 +0200797 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
Matt2f2f4252005-04-13 14:45:30 +0200798 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100799 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
800
801 if (spec->alt_switch) {
802 codec->num_pcms++;
803 info++;
804 info->name = "STAC92xx Analog Alt";
805 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
806 }
Matt2f2f4252005-04-13 14:45:30 +0200807
Mattdabbed62005-06-14 10:19:34 +0200808 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
809 codec->num_pcms++;
810 info++;
811 info->name = "STAC92xx Digital";
812 if (spec->multiout.dig_out_nid) {
813 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
814 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
815 }
816 if (spec->dig_in_nid) {
817 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
818 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
819 }
820 }
821
Matt2f2f4252005-04-13 14:45:30 +0200822 return 0;
823}
824
Takashi Iwaic960a032006-03-23 17:06:28 +0100825static unsigned int stac92xx_get_vref(struct hda_codec *codec, hda_nid_t nid)
826{
827 unsigned int pincap = snd_hda_param_read(codec, nid,
828 AC_PAR_PIN_CAP);
829 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
830 if (pincap & AC_PINCAP_VREF_100)
831 return AC_PINCTL_VREF_100;
832 if (pincap & AC_PINCAP_VREF_80)
833 return AC_PINCTL_VREF_80;
834 if (pincap & AC_PINCAP_VREF_50)
835 return AC_PINCTL_VREF_50;
836 if (pincap & AC_PINCAP_VREF_GRD)
837 return AC_PINCTL_VREF_GRD;
838 return 0;
839}
840
Matt Porter403d1942005-11-29 15:00:51 +0100841static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
842
843{
844 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
845}
846
847static int stac92xx_io_switch_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
848{
849 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
850 uinfo->count = 1;
851 uinfo->value.integer.min = 0;
852 uinfo->value.integer.max = 1;
853 return 0;
854}
855
856static int stac92xx_io_switch_get(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 int io_idx = kcontrol-> private_value & 0xff;
861
862 ucontrol->value.integer.value[0] = spec->io_switch[io_idx];
863 return 0;
864}
865
866static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
867{
868 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
869 struct sigmatel_spec *spec = codec->spec;
870 hda_nid_t nid = kcontrol->private_value >> 8;
871 int io_idx = kcontrol-> private_value & 0xff;
872 unsigned short val = ucontrol->value.integer.value[0];
873
874 spec->io_switch[io_idx] = val;
875
876 if (val)
877 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
Takashi Iwaic960a032006-03-23 17:06:28 +0100878 else {
879 unsigned int pinctl = AC_PINCTL_IN_EN;
880 if (io_idx) /* set VREF for mic */
881 pinctl |= stac92xx_get_vref(codec, nid);
882 stac92xx_auto_set_pinctl(codec, nid, pinctl);
883 }
Matt Porter403d1942005-11-29 15:00:51 +0100884 return 1;
885}
886
887#define STAC_CODEC_IO_SWITCH(xname, xpval) \
888 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
889 .name = xname, \
890 .index = 0, \
891 .info = stac92xx_io_switch_info, \
892 .get = stac92xx_io_switch_get, \
893 .put = stac92xx_io_switch_put, \
894 .private_value = xpval, \
895 }
896
897
Mattc7d4b2f2005-06-27 14:59:41 +0200898enum {
899 STAC_CTL_WIDGET_VOL,
900 STAC_CTL_WIDGET_MUTE,
Matt Porter403d1942005-11-29 15:00:51 +0100901 STAC_CTL_WIDGET_IO_SWITCH,
Mattc7d4b2f2005-06-27 14:59:41 +0200902};
903
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100904static struct snd_kcontrol_new stac92xx_control_templates[] = {
Mattc7d4b2f2005-06-27 14:59:41 +0200905 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
906 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Matt Porter403d1942005-11-29 15:00:51 +0100907 STAC_CODEC_IO_SWITCH(NULL, 0),
Mattc7d4b2f2005-06-27 14:59:41 +0200908};
909
910/* add dynamic controls */
911static int stac92xx_add_control(struct sigmatel_spec *spec, int type, const char *name, unsigned long val)
912{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100913 struct snd_kcontrol_new *knew;
Mattc7d4b2f2005-06-27 14:59:41 +0200914
915 if (spec->num_kctl_used >= spec->num_kctl_alloc) {
916 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
917
918 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */
919 if (! knew)
920 return -ENOMEM;
921 if (spec->kctl_alloc) {
922 memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
923 kfree(spec->kctl_alloc);
924 }
925 spec->kctl_alloc = knew;
926 spec->num_kctl_alloc = num;
927 }
928
929 knew = &spec->kctl_alloc[spec->num_kctl_used];
930 *knew = stac92xx_control_templates[type];
Takashi Iwai82fe0c52005-06-30 10:54:33 +0200931 knew->name = kstrdup(name, GFP_KERNEL);
Mattc7d4b2f2005-06-27 14:59:41 +0200932 if (! knew->name)
933 return -ENOMEM;
934 knew->private_value = val;
935 spec->num_kctl_used++;
936 return 0;
937}
938
Matt Porter403d1942005-11-29 15:00:51 +0100939/* flag inputs as additional dynamic lineouts */
940static int stac92xx_add_dyn_out_pins(struct hda_codec *codec, struct auto_pin_cfg *cfg)
941{
942 struct sigmatel_spec *spec = codec->spec;
943
944 switch (cfg->line_outs) {
945 case 3:
946 /* add line-in as side */
947 if (cfg->input_pins[AUTO_PIN_LINE]) {
948 cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_LINE];
949 spec->line_switch = 1;
950 cfg->line_outs++;
951 }
952 break;
953 case 2:
954 /* add line-in as clfe and mic as side */
955 if (cfg->input_pins[AUTO_PIN_LINE]) {
956 cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_LINE];
957 spec->line_switch = 1;
958 cfg->line_outs++;
959 }
960 if (cfg->input_pins[AUTO_PIN_MIC]) {
961 cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_MIC];
962 spec->mic_switch = 1;
963 cfg->line_outs++;
964 }
965 break;
966 case 1:
967 /* add line-in as surr and mic as clfe */
968 if (cfg->input_pins[AUTO_PIN_LINE]) {
969 cfg->line_out_pins[1] = cfg->input_pins[AUTO_PIN_LINE];
970 spec->line_switch = 1;
971 cfg->line_outs++;
972 }
973 if (cfg->input_pins[AUTO_PIN_MIC]) {
974 cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_MIC];
975 spec->mic_switch = 1;
976 cfg->line_outs++;
977 }
978 break;
979 }
980
981 return 0;
982}
983
Matt Porter3cc08dc2006-01-23 15:27:49 +0100984/*
985 * XXX The line_out pin widget connection list may not be set to the
986 * desired DAC nid. This is the case on 927x where ports A and B can
987 * be routed to several DACs.
988 *
989 * This requires an analysis of the line-out/hp pin configuration
990 * to provide a best fit for pin/DAC configurations that are routable.
991 * For now, 927x DAC4 is not supported and 927x DAC1 output to ports
992 * A and B is not supported.
993 */
Mattc7d4b2f2005-06-27 14:59:41 +0200994/* fill in the dac_nids table from the parsed pin configuration */
Takashi Iwai19039bd2006-06-28 15:52:16 +0200995static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec,
996 const struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +0200997{
998 struct sigmatel_spec *spec = codec->spec;
999 hda_nid_t nid;
1000 int i;
1001
1002 /* check the pins hardwired to audio widget */
1003 for (i = 0; i < cfg->line_outs; i++) {
1004 nid = cfg->line_out_pins[i];
1005 spec->multiout.dac_nids[i] = snd_hda_codec_read(codec, nid, 0,
1006 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
1007 }
1008
Takashi Iwai82bc9552006-03-21 11:24:42 +01001009 spec->multiout.num_dacs = cfg->line_outs;
Mattc7d4b2f2005-06-27 14:59:41 +02001010
1011 return 0;
1012}
1013
1014/* add playback controls from the parsed DAC table */
Takashi Iwai19039bd2006-06-28 15:52:16 +02001015static int stac92xx_auto_create_multi_out_ctls(struct sigmatel_spec *spec,
1016 const struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02001017{
1018 char name[32];
Takashi Iwai19039bd2006-06-28 15:52:16 +02001019 static const char *chname[4] = {
1020 "Front", "Surround", NULL /*CLFE*/, "Side"
1021 };
Mattc7d4b2f2005-06-27 14:59:41 +02001022 hda_nid_t nid;
1023 int i, err;
1024
1025 for (i = 0; i < cfg->line_outs; i++) {
Matt Porter403d1942005-11-29 15:00:51 +01001026 if (!spec->multiout.dac_nids[i])
Mattc7d4b2f2005-06-27 14:59:41 +02001027 continue;
1028
1029 nid = spec->multiout.dac_nids[i];
1030
1031 if (i == 2) {
1032 /* Center/LFE */
1033 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, "Center Playback Volume",
1034 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT))) < 0)
1035 return err;
1036 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, "LFE Playback Volume",
1037 HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT))) < 0)
1038 return err;
1039 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, "Center Playback Switch",
1040 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT))) < 0)
1041 return err;
1042 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, "LFE Playback Switch",
1043 HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT))) < 0)
1044 return err;
1045 } else {
1046 sprintf(name, "%s Playback Volume", chname[i]);
1047 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, name,
1048 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
1049 return err;
1050 sprintf(name, "%s Playback Switch", chname[i]);
1051 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, name,
1052 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
1053 return err;
1054 }
1055 }
1056
Matt Porter403d1942005-11-29 15:00:51 +01001057 if (spec->line_switch)
1058 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Line In as Output Switch", cfg->input_pins[AUTO_PIN_LINE] << 8)) < 0)
1059 return err;
1060
1061 if (spec->mic_switch)
1062 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Mic as Output Switch", (cfg->input_pins[AUTO_PIN_MIC] << 8) | 1)) < 0)
1063 return err;
1064
Mattc7d4b2f2005-06-27 14:59:41 +02001065 return 0;
1066}
1067
1068/* add playback controls for HP output */
1069static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec, struct auto_pin_cfg *cfg)
1070{
1071 struct sigmatel_spec *spec = codec->spec;
1072 hda_nid_t pin = cfg->hp_pin;
1073 hda_nid_t nid;
1074 int i, err;
Matt4e550962005-07-04 17:51:39 +02001075 unsigned int wid_caps;
Mattc7d4b2f2005-06-27 14:59:41 +02001076
1077 if (! pin)
1078 return 0;
1079
Takashi Iwai54d17402005-11-21 16:33:22 +01001080 wid_caps = get_wcaps(codec, pin);
Takashi Iwai505cb342006-03-27 12:51:52 +02001081 if (wid_caps & AC_WCAP_UNSOL_CAP)
Takashi Iwai82bc9552006-03-21 11:24:42 +01001082 spec->hp_detect = 1;
Matt4e550962005-07-04 17:51:39 +02001083
Mattc7d4b2f2005-06-27 14:59:41 +02001084 nid = snd_hda_codec_read(codec, pin, 0, AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
1085 for (i = 0; i < cfg->line_outs; i++) {
1086 if (! spec->multiout.dac_nids[i])
1087 continue;
1088 if (spec->multiout.dac_nids[i] == nid)
1089 return 0;
1090 }
1091
1092 spec->multiout.hp_nid = nid;
1093
1094 /* control HP volume/switch on the output mixer amp */
1095 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, "Headphone Playback Volume",
1096 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
1097 return err;
1098 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, "Headphone Playback Switch",
1099 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
1100 return err;
1101
1102 return 0;
1103}
1104
1105/* create playback/capture controls for input pins */
1106static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
1107{
1108 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02001109 struct hda_input_mux *imux = &spec->private_imux;
1110 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
1111 int i, j, k;
1112
1113 for (i = 0; i < AUTO_PIN_LAST; i++) {
1114 int index = -1;
1115 if (cfg->input_pins[i]) {
Takashi Iwai4a471b72005-12-07 13:56:29 +01001116 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
Mattc7d4b2f2005-06-27 14:59:41 +02001117
1118 for (j=0; j<spec->num_muxes; j++) {
1119 int num_cons = snd_hda_get_connections(codec, spec->mux_nids[j], con_lst, HDA_MAX_NUM_INPUTS);
1120 for (k=0; k<num_cons; k++)
1121 if (con_lst[k] == cfg->input_pins[i]) {
1122 index = k;
1123 break;
1124 }
1125 if (index >= 0)
1126 break;
1127 }
1128 imux->items[imux->num_items].index = index;
1129 imux->num_items++;
1130 }
1131 }
1132
Sam Revitch62fe78e2006-05-10 15:09:17 +02001133 if (imux->num_items == 1) {
1134 /*
1135 * Set the current input for the muxes.
1136 * The STAC9221 has two input muxes with identical source
1137 * NID lists. Hopefully this won't get confused.
1138 */
1139 for (i = 0; i < spec->num_muxes; i++) {
1140 snd_hda_codec_write(codec, spec->mux_nids[i], 0,
1141 AC_VERB_SET_CONNECT_SEL,
1142 imux->items[0].index);
1143 }
1144 }
1145
Mattc7d4b2f2005-06-27 14:59:41 +02001146 return 0;
1147}
1148
Mattc7d4b2f2005-06-27 14:59:41 +02001149static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
1150{
1151 struct sigmatel_spec *spec = codec->spec;
1152 int i;
1153
1154 for (i = 0; i < spec->autocfg.line_outs; i++) {
1155 hda_nid_t nid = spec->autocfg.line_out_pins[i];
1156 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
1157 }
1158}
1159
1160static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
1161{
1162 struct sigmatel_spec *spec = codec->spec;
1163 hda_nid_t pin;
1164
1165 pin = spec->autocfg.hp_pin;
1166 if (pin) /* connect to front */
1167 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
1168}
1169
Matt Porter3cc08dc2006-01-23 15:27:49 +01001170static 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 +02001171{
1172 struct sigmatel_spec *spec = codec->spec;
1173 int err;
1174
Kailang Yangdf694da2005-12-05 19:42:22 +01001175 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001176 return err;
Takashi Iwai82bc9552006-03-21 11:24:42 +01001177 if (! spec->autocfg.line_outs)
Matt Porter869264c2006-01-25 19:20:50 +01001178 return 0; /* can't find valid pin config */
Takashi Iwai19039bd2006-06-28 15:52:16 +02001179
Matt Porter403d1942005-11-29 15:00:51 +01001180 if ((err = stac92xx_add_dyn_out_pins(codec, &spec->autocfg)) < 0)
1181 return err;
Takashi Iwai19039bd2006-06-28 15:52:16 +02001182 if (spec->multiout.num_dacs == 0)
1183 if ((err = stac92xx_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
1184 return err;
Mattc7d4b2f2005-06-27 14:59:41 +02001185
1186 if ((err = stac92xx_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
1187 (err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg)) < 0 ||
1188 (err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
1189 return err;
1190
1191 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Matt Porter403d1942005-11-29 15:00:51 +01001192 if (spec->multiout.max_channels > 2)
Mattc7d4b2f2005-06-27 14:59:41 +02001193 spec->surr_switch = 1;
Mattc7d4b2f2005-06-27 14:59:41 +02001194
Takashi Iwai82bc9552006-03-21 11:24:42 +01001195 if (spec->autocfg.dig_out_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01001196 spec->multiout.dig_out_nid = dig_out;
Takashi Iwai82bc9552006-03-21 11:24:42 +01001197 if (spec->autocfg.dig_in_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01001198 spec->dig_in_nid = dig_in;
Mattc7d4b2f2005-06-27 14:59:41 +02001199
1200 if (spec->kctl_alloc)
1201 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
1202
1203 spec->input_mux = &spec->private_imux;
1204
1205 return 1;
1206}
1207
Takashi Iwai82bc9552006-03-21 11:24:42 +01001208/* add playback controls for HP output */
1209static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
1210 struct auto_pin_cfg *cfg)
1211{
1212 struct sigmatel_spec *spec = codec->spec;
1213 hda_nid_t pin = cfg->hp_pin;
1214 unsigned int wid_caps;
1215
1216 if (! pin)
1217 return 0;
1218
1219 wid_caps = get_wcaps(codec, pin);
Takashi Iwai505cb342006-03-27 12:51:52 +02001220 if (wid_caps & AC_WCAP_UNSOL_CAP)
Takashi Iwai82bc9552006-03-21 11:24:42 +01001221 spec->hp_detect = 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +01001222
1223 return 0;
1224}
1225
Mattc7d4b2f2005-06-27 14:59:41 +02001226static int stac9200_parse_auto_config(struct hda_codec *codec)
1227{
1228 struct sigmatel_spec *spec = codec->spec;
1229 int err;
1230
Kailang Yangdf694da2005-12-05 19:42:22 +01001231 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001232 return err;
1233
1234 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
1235 return err;
1236
Takashi Iwai82bc9552006-03-21 11:24:42 +01001237 if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
1238 return err;
1239
1240 if (spec->autocfg.dig_out_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02001241 spec->multiout.dig_out_nid = 0x05;
Takashi Iwai82bc9552006-03-21 11:24:42 +01001242 if (spec->autocfg.dig_in_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02001243 spec->dig_in_nid = 0x04;
Mattc7d4b2f2005-06-27 14:59:41 +02001244
1245 if (spec->kctl_alloc)
1246 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
1247
1248 spec->input_mux = &spec->private_imux;
1249
1250 return 1;
1251}
1252
Sam Revitch62fe78e2006-05-10 15:09:17 +02001253/*
1254 * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
1255 * funky external mute control using GPIO pins.
1256 */
1257
1258static void stac922x_gpio_mute(struct hda_codec *codec, int pin, int muted)
1259{
1260 unsigned int gpiostate, gpiomask, gpiodir;
1261
1262 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
1263 AC_VERB_GET_GPIO_DATA, 0);
1264
1265 if (!muted)
1266 gpiostate |= (1 << pin);
1267 else
1268 gpiostate &= ~(1 << pin);
1269
1270 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
1271 AC_VERB_GET_GPIO_MASK, 0);
1272 gpiomask |= (1 << pin);
1273
1274 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
1275 AC_VERB_GET_GPIO_DIRECTION, 0);
1276 gpiodir |= (1 << pin);
1277
1278 /* AppleHDA seems to do this -- WTF is this verb?? */
1279 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
1280
1281 snd_hda_codec_write(codec, codec->afg, 0,
1282 AC_VERB_SET_GPIO_MASK, gpiomask);
1283 snd_hda_codec_write(codec, codec->afg, 0,
1284 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
1285
1286 msleep(1);
1287
1288 snd_hda_codec_write(codec, codec->afg, 0,
1289 AC_VERB_SET_GPIO_DATA, gpiostate);
1290}
1291
Mattc7d4b2f2005-06-27 14:59:41 +02001292static int stac92xx_init(struct hda_codec *codec)
1293{
1294 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai82bc9552006-03-21 11:24:42 +01001295 struct auto_pin_cfg *cfg = &spec->autocfg;
1296 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02001297
Mattc7d4b2f2005-06-27 14:59:41 +02001298 snd_hda_sequence_write(codec, spec->init);
1299
Takashi Iwai82bc9552006-03-21 11:24:42 +01001300 /* set up pins */
1301 if (spec->hp_detect) {
Takashi Iwai505cb342006-03-27 12:51:52 +02001302 /* Enable unsolicited responses on the HP widget */
1303 snd_hda_codec_write(codec, cfg->hp_pin, 0,
1304 AC_VERB_SET_UNSOLICITED_ENABLE,
1305 STAC_UNSOL_ENABLE);
Takashi Iwai82bc9552006-03-21 11:24:42 +01001306 /* fake event to set up pins */
1307 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
Tobin Davis68a6abd2006-08-21 19:02:10 +02001308 /* enable the headphones by default. If/when unsol_event detection works, this will be ignored */
1309 stac92xx_auto_init_hp_out(codec);
Takashi Iwai82bc9552006-03-21 11:24:42 +01001310 } else {
1311 stac92xx_auto_init_multi_out(codec);
1312 stac92xx_auto_init_hp_out(codec);
1313 }
1314 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwaic960a032006-03-23 17:06:28 +01001315 hda_nid_t nid = cfg->input_pins[i];
1316 if (nid) {
1317 unsigned int pinctl = AC_PINCTL_IN_EN;
1318 if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC)
1319 pinctl |= stac92xx_get_vref(codec, nid);
1320 stac92xx_auto_set_pinctl(codec, nid, pinctl);
1321 }
Takashi Iwai82bc9552006-03-21 11:24:42 +01001322 }
1323 if (cfg->dig_out_pin)
1324 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pin,
1325 AC_PINCTL_OUT_EN);
1326 if (cfg->dig_in_pin)
1327 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
1328 AC_PINCTL_IN_EN);
1329
Sam Revitch62fe78e2006-05-10 15:09:17 +02001330 if (spec->gpio_mute) {
1331 stac922x_gpio_mute(codec, 0, 0);
1332 stac922x_gpio_mute(codec, 1, 0);
1333 }
1334
Mattc7d4b2f2005-06-27 14:59:41 +02001335 return 0;
1336}
1337
Matt2f2f4252005-04-13 14:45:30 +02001338static void stac92xx_free(struct hda_codec *codec)
1339{
Mattc7d4b2f2005-06-27 14:59:41 +02001340 struct sigmatel_spec *spec = codec->spec;
1341 int i;
1342
1343 if (! spec)
1344 return;
1345
1346 if (spec->kctl_alloc) {
1347 for (i = 0; i < spec->num_kctl_used; i++)
1348 kfree(spec->kctl_alloc[i].name);
1349 kfree(spec->kctl_alloc);
1350 }
1351
Richard Fish11b44bb2006-08-23 18:31:34 +02001352 if (spec->bios_pin_configs)
1353 kfree(spec->bios_pin_configs);
1354
Mattc7d4b2f2005-06-27 14:59:41 +02001355 kfree(spec);
Matt2f2f4252005-04-13 14:45:30 +02001356}
1357
Matt4e550962005-07-04 17:51:39 +02001358static void stac92xx_set_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_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
1369 unsigned int flag)
1370{
1371 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
1372 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
1373 snd_hda_codec_write(codec, nid, 0,
1374 AC_VERB_SET_PIN_WIDGET_CONTROL,
1375 pin_ctl & ~flag);
1376}
1377
1378static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
1379{
1380 struct sigmatel_spec *spec = codec->spec;
1381 struct auto_pin_cfg *cfg = &spec->autocfg;
1382 int i, presence;
1383
1384 if ((res >> 26) != STAC_HP_EVENT)
1385 return;
1386
1387 presence = snd_hda_codec_read(codec, cfg->hp_pin, 0,
1388 AC_VERB_GET_PIN_SENSE, 0x00) >> 31;
1389
1390 if (presence) {
1391 /* disable lineouts, enable hp */
1392 for (i = 0; i < cfg->line_outs; i++)
1393 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
1394 AC_PINCTL_OUT_EN);
1395 stac92xx_set_pinctl(codec, cfg->hp_pin, AC_PINCTL_OUT_EN);
1396 } else {
1397 /* enable lineouts, disable hp */
1398 for (i = 0; i < cfg->line_outs; i++)
1399 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
1400 AC_PINCTL_OUT_EN);
1401 stac92xx_reset_pinctl(codec, cfg->hp_pin, AC_PINCTL_OUT_EN);
1402 }
1403}
1404
Mattff6fdc32005-06-27 15:06:52 +02001405#ifdef CONFIG_PM
1406static int stac92xx_resume(struct hda_codec *codec)
1407{
1408 struct sigmatel_spec *spec = codec->spec;
1409 int i;
1410
1411 stac92xx_init(codec);
Richard Fish11b44bb2006-08-23 18:31:34 +02001412 stac92xx_set_config_regs(codec);
Mattff6fdc32005-06-27 15:06:52 +02001413 for (i = 0; i < spec->num_mixers; i++)
1414 snd_hda_resume_ctls(codec, spec->mixers[i]);
1415 if (spec->multiout.dig_out_nid)
1416 snd_hda_resume_spdif_out(codec);
1417 if (spec->dig_in_nid)
1418 snd_hda_resume_spdif_in(codec);
1419
1420 return 0;
1421}
1422#endif
1423
Matt2f2f4252005-04-13 14:45:30 +02001424static struct hda_codec_ops stac92xx_patch_ops = {
1425 .build_controls = stac92xx_build_controls,
1426 .build_pcms = stac92xx_build_pcms,
1427 .init = stac92xx_init,
1428 .free = stac92xx_free,
Matt4e550962005-07-04 17:51:39 +02001429 .unsol_event = stac92xx_unsol_event,
Mattff6fdc32005-06-27 15:06:52 +02001430#ifdef CONFIG_PM
1431 .resume = stac92xx_resume,
1432#endif
Matt2f2f4252005-04-13 14:45:30 +02001433};
1434
1435static int patch_stac9200(struct hda_codec *codec)
1436{
1437 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02001438 int err;
Matt2f2f4252005-04-13 14:45:30 +02001439
Takashi Iwaie560d8d2005-09-09 14:21:46 +02001440 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02001441 if (spec == NULL)
1442 return -ENOMEM;
1443
1444 codec->spec = spec;
Richard Fish11b44bb2006-08-23 18:31:34 +02001445 spec->num_pins = 8;
1446 spec->pin_nids = stac9200_pin_nids;
Matt Porter403d1942005-11-29 15:00:51 +01001447 spec->board_config = snd_hda_check_board_config(codec, stac9200_cfg_tbl);
Richard Fish11b44bb2006-08-23 18:31:34 +02001448 if (spec->board_config < 0) {
1449 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9200, using BIOS defaults\n");
1450 err = stac92xx_save_bios_config_regs(codec);
1451 if (err < 0) {
1452 stac92xx_free(codec);
1453 return err;
1454 }
1455 spec->pin_configs = spec->bios_pin_configs;
1456 } else {
Matt Porter403d1942005-11-29 15:00:51 +01001457 spec->pin_configs = stac9200_brd_tbl[spec->board_config];
1458 stac92xx_set_config_regs(codec);
1459 }
Matt2f2f4252005-04-13 14:45:30 +02001460
1461 spec->multiout.max_channels = 2;
1462 spec->multiout.num_dacs = 1;
1463 spec->multiout.dac_nids = stac9200_dac_nids;
1464 spec->adc_nids = stac9200_adc_nids;
1465 spec->mux_nids = stac9200_mux_nids;
Mattdabbed62005-06-14 10:19:34 +02001466 spec->num_muxes = 1;
Mattc7d4b2f2005-06-27 14:59:41 +02001467
1468 spec->init = stac9200_core_init;
Matt2f2f4252005-04-13 14:45:30 +02001469 spec->mixer = stac9200_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02001470
1471 err = stac9200_parse_auto_config(codec);
1472 if (err < 0) {
1473 stac92xx_free(codec);
1474 return err;
1475 }
Matt2f2f4252005-04-13 14:45:30 +02001476
1477 codec->patch_ops = stac92xx_patch_ops;
1478
1479 return 0;
1480}
1481
1482static int patch_stac922x(struct hda_codec *codec)
1483{
1484 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02001485 int err;
Matt2f2f4252005-04-13 14:45:30 +02001486
Takashi Iwaie560d8d2005-09-09 14:21:46 +02001487 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02001488 if (spec == NULL)
1489 return -ENOMEM;
1490
1491 codec->spec = spec;
Richard Fish11b44bb2006-08-23 18:31:34 +02001492 spec->num_pins = 10;
1493 spec->pin_nids = stac922x_pin_nids;
Matt Porter403d1942005-11-29 15:00:51 +01001494 spec->board_config = snd_hda_check_board_config(codec, stac922x_cfg_tbl);
Richard Fish11b44bb2006-08-23 18:31:34 +02001495 if (spec->board_config < 0) {
1496 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC922x, "
1497 "using BIOS defaults\n");
1498 err = stac92xx_save_bios_config_regs(codec);
1499 if (err < 0) {
1500 stac92xx_free(codec);
1501 return err;
1502 }
1503 spec->pin_configs = spec->bios_pin_configs;
1504 } else if (stac922x_brd_tbl[spec->board_config] != NULL) {
Matt Porter403d1942005-11-29 15:00:51 +01001505 spec->pin_configs = stac922x_brd_tbl[spec->board_config];
1506 stac92xx_set_config_regs(codec);
1507 }
Matt2f2f4252005-04-13 14:45:30 +02001508
Matt2f2f4252005-04-13 14:45:30 +02001509 spec->adc_nids = stac922x_adc_nids;
1510 spec->mux_nids = stac922x_mux_nids;
Mattdabbed62005-06-14 10:19:34 +02001511 spec->num_muxes = 2;
Mattc7d4b2f2005-06-27 14:59:41 +02001512
1513 spec->init = stac922x_core_init;
Matt2f2f4252005-04-13 14:45:30 +02001514 spec->mixer = stac922x_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02001515
1516 spec->multiout.dac_nids = spec->dac_nids;
Takashi Iwai19039bd2006-06-28 15:52:16 +02001517
Matt Porter3cc08dc2006-01-23 15:27:49 +01001518 err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
1519 if (err < 0) {
1520 stac92xx_free(codec);
1521 return err;
1522 }
1523
Sam Revitch62fe78e2006-05-10 15:09:17 +02001524 if (spec->board_config == STAC_MACMINI)
1525 spec->gpio_mute = 1;
1526
Matt Porter3cc08dc2006-01-23 15:27:49 +01001527 codec->patch_ops = stac92xx_patch_ops;
1528
1529 return 0;
1530}
1531
1532static int patch_stac927x(struct hda_codec *codec)
1533{
1534 struct sigmatel_spec *spec;
1535 int err;
1536
1537 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1538 if (spec == NULL)
1539 return -ENOMEM;
1540
1541 codec->spec = spec;
Richard Fish11b44bb2006-08-23 18:31:34 +02001542 spec->num_pins = 14;
1543 spec->pin_nids = stac927x_pin_nids;
Matt Porter3cc08dc2006-01-23 15:27:49 +01001544 spec->board_config = snd_hda_check_board_config(codec, stac927x_cfg_tbl);
Richard Fish11b44bb2006-08-23 18:31:34 +02001545 if (spec->board_config < 0) {
Matt Porter3cc08dc2006-01-23 15:27:49 +01001546 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC927x, using BIOS defaults\n");
Richard Fish11b44bb2006-08-23 18:31:34 +02001547 err = stac92xx_save_bios_config_regs(codec);
1548 if (err < 0) {
1549 stac92xx_free(codec);
1550 return err;
1551 }
1552 spec->pin_configs = spec->bios_pin_configs;
1553 } else if (stac927x_brd_tbl[spec->board_config] != NULL) {
Matt Porter3cc08dc2006-01-23 15:27:49 +01001554 spec->pin_configs = stac927x_brd_tbl[spec->board_config];
1555 stac92xx_set_config_regs(codec);
1556 }
1557
Tobin Davis81d3dbd2006-08-22 19:44:45 +02001558 switch (spec->board_config) {
Tobin Davis93ed1502006-09-01 21:03:12 +02001559 case STAC_D965_3ST:
Tobin Davis81d3dbd2006-08-22 19:44:45 +02001560 spec->adc_nids = stac927x_adc_nids;
1561 spec->mux_nids = stac927x_mux_nids;
1562 spec->num_muxes = 3;
Tobin Davis93ed1502006-09-01 21:03:12 +02001563 spec->init = d965_core_init;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02001564 spec->mixer = stac9227_mixer;
1565 break;
Tobin Davis93ed1502006-09-01 21:03:12 +02001566 case STAC_D965_5ST:
1567 spec->adc_nids = stac927x_adc_nids;
1568 spec->mux_nids = stac927x_mux_nids;
1569 spec->num_muxes = 3;
1570 spec->init = d965_core_init;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02001571 spec->mixer = stac9227_mixer;
1572 break;
1573 default:
1574 spec->adc_nids = stac927x_adc_nids;
1575 spec->mux_nids = stac927x_mux_nids;
1576 spec->num_muxes = 3;
1577 spec->init = stac927x_core_init;
1578 spec->mixer = stac927x_mixer;
1579 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01001580
1581 spec->multiout.dac_nids = spec->dac_nids;
1582
1583 err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
Mattc7d4b2f2005-06-27 14:59:41 +02001584 if (err < 0) {
1585 stac92xx_free(codec);
1586 return err;
1587 }
Matt2f2f4252005-04-13 14:45:30 +02001588
1589 codec->patch_ops = stac92xx_patch_ops;
1590
1591 return 0;
1592}
1593
Matt Porterf3302a52006-07-31 12:49:34 +02001594static int patch_stac9205(struct hda_codec *codec)
1595{
1596 struct sigmatel_spec *spec;
1597 int err;
1598
1599 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1600 if (spec == NULL)
1601 return -ENOMEM;
1602
1603 codec->spec = spec;
Richard Fish11b44bb2006-08-23 18:31:34 +02001604 spec->num_pins = 14;
1605 spec->pin_nids = stac9205_pin_nids;
Matt Porterf3302a52006-07-31 12:49:34 +02001606 spec->board_config = snd_hda_check_board_config(codec, stac9205_cfg_tbl);
Richard Fish11b44bb2006-08-23 18:31:34 +02001607 if (spec->board_config < 0) {
1608 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9205, using BIOS defaults\n");
1609 err = stac92xx_save_bios_config_regs(codec);
1610 if (err < 0) {
1611 stac92xx_free(codec);
1612 return err;
1613 }
1614 spec->pin_configs = spec->bios_pin_configs;
1615 } else {
Matt Porterf3302a52006-07-31 12:49:34 +02001616 spec->pin_configs = stac9205_brd_tbl[spec->board_config];
1617 stac92xx_set_config_regs(codec);
1618 }
1619
1620 spec->adc_nids = stac9205_adc_nids;
1621 spec->mux_nids = stac9205_mux_nids;
1622 spec->num_muxes = 3;
1623
1624 spec->init = stac9205_core_init;
1625 spec->mixer = stac9205_mixer;
1626
1627 spec->multiout.dac_nids = spec->dac_nids;
1628
1629 err = stac92xx_parse_auto_config(codec, 0x1f, 0x20);
1630 if (err < 0) {
1631 stac92xx_free(codec);
1632 return err;
1633 }
1634
1635 codec->patch_ops = stac92xx_patch_ops;
1636
1637 return 0;
1638}
1639
Matt2f2f4252005-04-13 14:45:30 +02001640/*
Guillaume Munch6d859062006-08-22 17:15:47 +02001641 * STAC9872 hack
Takashi Iwaidb064e52006-03-16 16:04:58 +01001642 */
1643
Guillaume Munch99ccc562006-08-16 19:35:12 +02001644/* static config for Sony VAIO FE550G and Sony VAIO AR */
Takashi Iwaidb064e52006-03-16 16:04:58 +01001645static hda_nid_t vaio_dacs[] = { 0x2 };
1646#define VAIO_HP_DAC 0x5
1647static hda_nid_t vaio_adcs[] = { 0x8 /*,0x6*/ };
1648static hda_nid_t vaio_mux_nids[] = { 0x15 };
1649
1650static struct hda_input_mux vaio_mux = {
1651 .num_items = 2,
1652 .items = {
Takashi Iwaid7737812006-04-25 13:05:43 +02001653 /* { "HP", 0x0 }, */
1654 { "Line", 0x1 },
Takashi Iwaidb064e52006-03-16 16:04:58 +01001655 { "Mic", 0x2 },
1656 { "PCM", 0x3 },
1657 }
1658};
1659
1660static struct hda_verb vaio_init[] = {
1661 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
1662 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
1663 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
1664 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
1665 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
1666 {0x15, AC_VERB_SET_CONNECT_SEL, 0x2}, /* mic-sel: 0a,0d,14,02 */
1667 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
1668 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
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
Guillaume Munch6d859062006-08-22 17:15:47 +02001675static struct hda_verb vaio_ar_init[] = {
1676 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
1677 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
1678 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
1679 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
1680/* {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },*/ /* Optical Out */
1681 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
1682 {0x15, AC_VERB_SET_CONNECT_SEL, 0x2}, /* mic-sel: 0a,0d,14,02 */
1683 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
1684 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
1685/* {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},*/ /* Optical Out */
1686 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
1687 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
1688 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
1689 {}
1690};
1691
Takashi Iwaidb064e52006-03-16 16:04:58 +01001692/* bind volumes of both NID 0x02 and 0x05 */
1693static int vaio_master_vol_put(struct snd_kcontrol *kcontrol,
1694 struct snd_ctl_elem_value *ucontrol)
1695{
1696 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1697 long *valp = ucontrol->value.integer.value;
1698 int change;
1699
1700 change = snd_hda_codec_amp_update(codec, 0x02, 0, HDA_OUTPUT, 0,
1701 0x7f, valp[0] & 0x7f);
1702 change |= snd_hda_codec_amp_update(codec, 0x02, 1, HDA_OUTPUT, 0,
1703 0x7f, valp[1] & 0x7f);
1704 snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
1705 0x7f, valp[0] & 0x7f);
1706 snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
1707 0x7f, valp[1] & 0x7f);
1708 return change;
1709}
1710
1711/* bind volumes of both NID 0x02 and 0x05 */
1712static int vaio_master_sw_put(struct snd_kcontrol *kcontrol,
1713 struct snd_ctl_elem_value *ucontrol)
1714{
1715 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1716 long *valp = ucontrol->value.integer.value;
1717 int change;
1718
1719 change = snd_hda_codec_amp_update(codec, 0x02, 0, HDA_OUTPUT, 0,
Takashi Iwaia9393d72006-05-03 11:59:03 +02001720 0x80, (valp[0] ? 0 : 0x80));
Takashi Iwaidb064e52006-03-16 16:04:58 +01001721 change |= snd_hda_codec_amp_update(codec, 0x02, 1, HDA_OUTPUT, 0,
Takashi Iwaia9393d72006-05-03 11:59:03 +02001722 0x80, (valp[1] ? 0 : 0x80));
Takashi Iwaidb064e52006-03-16 16:04:58 +01001723 snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
Takashi Iwaia9393d72006-05-03 11:59:03 +02001724 0x80, (valp[0] ? 0 : 0x80));
Takashi Iwaidb064e52006-03-16 16:04:58 +01001725 snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
Takashi Iwaia9393d72006-05-03 11:59:03 +02001726 0x80, (valp[1] ? 0 : 0x80));
Takashi Iwaidb064e52006-03-16 16:04:58 +01001727 return change;
1728}
1729
1730static struct snd_kcontrol_new vaio_mixer[] = {
1731 {
1732 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1733 .name = "Master Playback Volume",
1734 .info = snd_hda_mixer_amp_volume_info,
1735 .get = snd_hda_mixer_amp_volume_get,
1736 .put = vaio_master_vol_put,
Takashi Iwaic2566522006-08-17 18:21:36 +02001737 .tlv = { .c = snd_hda_mixer_amp_tlv },
Takashi Iwaidb064e52006-03-16 16:04:58 +01001738 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
1739 },
1740 {
1741 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1742 .name = "Master Playback Switch",
1743 .info = snd_hda_mixer_amp_switch_info,
1744 .get = snd_hda_mixer_amp_switch_get,
1745 .put = vaio_master_sw_put,
1746 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
1747 },
1748 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
1749 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
1750 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
1751 {
1752 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1753 .name = "Capture Source",
1754 .count = 1,
1755 .info = stac92xx_mux_enum_info,
1756 .get = stac92xx_mux_enum_get,
1757 .put = stac92xx_mux_enum_put,
1758 },
1759 {}
1760};
1761
Guillaume Munch6d859062006-08-22 17:15:47 +02001762static struct snd_kcontrol_new vaio_ar_mixer[] = {
1763 {
1764 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1765 .name = "Master Playback Volume",
1766 .info = snd_hda_mixer_amp_volume_info,
1767 .get = snd_hda_mixer_amp_volume_get,
1768 .put = vaio_master_vol_put,
1769 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
1770 },
1771 {
1772 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1773 .name = "Master Playback Switch",
1774 .info = snd_hda_mixer_amp_switch_info,
1775 .get = snd_hda_mixer_amp_switch_get,
1776 .put = vaio_master_sw_put,
1777 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
1778 },
1779 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
1780 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
1781 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
1782 /*HDA_CODEC_MUTE("Optical Out Switch", 0x10, 0, HDA_OUTPUT),
1783 HDA_CODEC_VOLUME("Optical Out Volume", 0x10, 0, HDA_OUTPUT),*/
1784 {
1785 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1786 .name = "Capture Source",
1787 .count = 1,
1788 .info = stac92xx_mux_enum_info,
1789 .get = stac92xx_mux_enum_get,
1790 .put = stac92xx_mux_enum_put,
1791 },
1792 {}
1793};
1794
1795static struct hda_codec_ops stac9872_patch_ops = {
Takashi Iwaidb064e52006-03-16 16:04:58 +01001796 .build_controls = stac92xx_build_controls,
1797 .build_pcms = stac92xx_build_pcms,
1798 .init = stac92xx_init,
1799 .free = stac92xx_free,
1800#ifdef CONFIG_PM
1801 .resume = stac92xx_resume,
1802#endif
1803};
1804
Guillaume Munch6d859062006-08-22 17:15:47 +02001805enum { /* FE and SZ series. id=0x83847661 and subsys=0x104D0700 or 104D1000. */
1806 CXD9872RD_VAIO,
1807 /* Unknown. id=0x83847662 and subsys=0x104D1200 or 104D1000. */
1808 STAC9872AK_VAIO,
1809 /* Unknown. id=0x83847661 and subsys=0x104D1200. */
1810 STAC9872K_VAIO,
1811 /* AR Series. id=0x83847664 and subsys=104D1300 */
1812 CXD9872AKD_VAIO
1813 };
Takashi Iwaidb064e52006-03-16 16:04:58 +01001814
Guillaume Munch6d859062006-08-22 17:15:47 +02001815static struct hda_board_config stac9872_cfg_tbl[] = {
1816 { .modelname = "vaio", .config = CXD9872RD_VAIO },
1817 { .modelname = "vaio-ar", .config = CXD9872AKD_VAIO },
Takashi Iwaidb064e52006-03-16 16:04:58 +01001818 { .pci_subvendor = 0x104d, .pci_subdevice = 0x81e6,
Guillaume Munch6d859062006-08-22 17:15:47 +02001819 .config = CXD9872RD_VAIO },
Takashi Iwaidb064e52006-03-16 16:04:58 +01001820 { .pci_subvendor = 0x104d, .pci_subdevice = 0x81ef,
Guillaume Munch6d859062006-08-22 17:15:47 +02001821 .config = CXD9872RD_VAIO },
Guillaume Munch99ccc562006-08-16 19:35:12 +02001822 { .pci_subvendor = 0x104d, .pci_subdevice = 0x81fd,
Guillaume Munch6d859062006-08-22 17:15:47 +02001823 .config = CXD9872AKD_VAIO },
Takashi Iwaidb064e52006-03-16 16:04:58 +01001824 {}
1825};
1826
Guillaume Munch6d859062006-08-22 17:15:47 +02001827static int patch_stac9872(struct hda_codec *codec)
Takashi Iwaidb064e52006-03-16 16:04:58 +01001828{
1829 struct sigmatel_spec *spec;
1830 int board_config;
1831
Guillaume Munch6d859062006-08-22 17:15:47 +02001832 board_config = snd_hda_check_board_config(codec, stac9872_cfg_tbl);
Takashi Iwaidb064e52006-03-16 16:04:58 +01001833 if (board_config < 0)
1834 /* unknown config, let generic-parser do its job... */
1835 return snd_hda_parse_generic_codec(codec);
1836
1837 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1838 if (spec == NULL)
1839 return -ENOMEM;
1840
1841 codec->spec = spec;
1842 switch (board_config) {
Guillaume Munch6d859062006-08-22 17:15:47 +02001843 case CXD9872RD_VAIO:
1844 case STAC9872AK_VAIO:
1845 case STAC9872K_VAIO:
Takashi Iwaidb064e52006-03-16 16:04:58 +01001846 spec->mixer = vaio_mixer;
1847 spec->init = vaio_init;
1848 spec->multiout.max_channels = 2;
1849 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
1850 spec->multiout.dac_nids = vaio_dacs;
1851 spec->multiout.hp_nid = VAIO_HP_DAC;
1852 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
1853 spec->adc_nids = vaio_adcs;
1854 spec->input_mux = &vaio_mux;
1855 spec->mux_nids = vaio_mux_nids;
1856 break;
Guillaume Munch6d859062006-08-22 17:15:47 +02001857
1858 case CXD9872AKD_VAIO:
1859 spec->mixer = vaio_ar_mixer;
1860 spec->init = vaio_ar_init;
1861 spec->multiout.max_channels = 2;
1862 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
1863 spec->multiout.dac_nids = vaio_dacs;
1864 spec->multiout.hp_nid = VAIO_HP_DAC;
1865 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
1866 spec->adc_nids = vaio_adcs;
1867 spec->input_mux = &vaio_mux;
1868 spec->mux_nids = vaio_mux_nids;
1869 break;
Takashi Iwaidb064e52006-03-16 16:04:58 +01001870 }
1871
Guillaume Munch6d859062006-08-22 17:15:47 +02001872 codec->patch_ops = stac9872_patch_ops;
Takashi Iwaidb064e52006-03-16 16:04:58 +01001873 return 0;
1874}
1875
1876
1877/*
Matt2f2f4252005-04-13 14:45:30 +02001878 * patch entries
1879 */
1880struct hda_codec_preset snd_hda_preset_sigmatel[] = {
1881 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
1882 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
1883 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
1884 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
1885 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
1886 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
1887 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
Matt Porter22a27c72006-07-06 18:49:10 +02001888 { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
1889 { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
1890 { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
1891 { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
1892 { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
1893 { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
Matt Porter3cc08dc2006-01-23 15:27:49 +01001894 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
1895 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
1896 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
1897 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
1898 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
1899 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
1900 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
1901 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
1902 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
1903 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
Guillaume Munch6d859062006-08-22 17:15:47 +02001904 /* The following does not take into account .id=0x83847661 when subsys =
1905 * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
1906 * currently not fully supported.
1907 */
1908 { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
1909 { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
1910 { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
Matt Porterf3302a52006-07-31 12:49:34 +02001911 { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
1912 { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
1913 { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
1914 { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
1915 { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
1916 { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
1917 { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
1918 { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
Matt2f2f4252005-04-13 14:45:30 +02001919 {} /* terminator */
1920};