blob: 7cc064265204c630e842d9158db45504c92684b5 [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
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001014/* create volume control/switch for the given prefx type */
1015static int create_controls(struct sigmatel_spec *spec, const char *pfx, hda_nid_t nid, int chs)
1016{
1017 char name[32];
1018 int err;
1019
1020 sprintf(name, "%s Playback Volume", pfx);
1021 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, name,
1022 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1023 if (err < 0)
1024 return err;
1025 sprintf(name, "%s Playback Switch", pfx);
1026 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, name,
1027 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1028 if (err < 0)
1029 return err;
1030 return 0;
1031}
1032
Mattc7d4b2f2005-06-27 14:59:41 +02001033/* add playback controls from the parsed DAC table */
Takashi Iwai19039bd2006-06-28 15:52:16 +02001034static int stac92xx_auto_create_multi_out_ctls(struct sigmatel_spec *spec,
1035 const struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02001036{
Takashi Iwai19039bd2006-06-28 15:52:16 +02001037 static const char *chname[4] = {
1038 "Front", "Surround", NULL /*CLFE*/, "Side"
1039 };
Mattc7d4b2f2005-06-27 14:59:41 +02001040 hda_nid_t nid;
1041 int i, err;
1042
1043 for (i = 0; i < cfg->line_outs; i++) {
Matt Porter403d1942005-11-29 15:00:51 +01001044 if (!spec->multiout.dac_nids[i])
Mattc7d4b2f2005-06-27 14:59:41 +02001045 continue;
1046
1047 nid = spec->multiout.dac_nids[i];
1048
1049 if (i == 2) {
1050 /* Center/LFE */
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001051 err = create_controls(spec, "Center", nid, 1);
1052 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001053 return err;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001054 err = create_controls(spec, "LFE", nid, 2);
1055 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001056 return err;
1057 } else {
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001058 err = create_controls(spec, chname[i], nid, 3);
1059 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001060 return err;
1061 }
1062 }
1063
Matt Porter403d1942005-11-29 15:00:51 +01001064 if (spec->line_switch)
1065 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Line In as Output Switch", cfg->input_pins[AUTO_PIN_LINE] << 8)) < 0)
1066 return err;
1067
1068 if (spec->mic_switch)
1069 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Mic as Output Switch", (cfg->input_pins[AUTO_PIN_MIC] << 8) | 1)) < 0)
1070 return err;
1071
Mattc7d4b2f2005-06-27 14:59:41 +02001072 return 0;
1073}
1074
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001075static int check_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
1076{
1077 int i;
1078
1079 for (i = 0; i < spec->multiout.num_dacs; i++) {
1080 if (spec->multiout.dac_nids[i] == nid)
1081 return 1;
1082 }
1083 if (spec->multiout.hp_nid == nid)
1084 return 1;
1085 return 0;
1086}
1087
1088static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
1089{
1090 if (!spec->multiout.hp_nid)
1091 spec->multiout.hp_nid = nid;
1092 else if (spec->multiout.num_dacs > 4) {
1093 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
1094 return 1;
1095 } else {
1096 spec->multiout.dac_nids[spec->multiout.num_dacs] = nid;
1097 spec->multiout.num_dacs++;
1098 }
1099 return 0;
1100}
1101
1102/* add playback controls for Speaker and HP outputs */
1103static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
1104 struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02001105{
1106 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02001107 hda_nid_t nid;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001108 int i, old_num_dacs, err;
Mattc7d4b2f2005-06-27 14:59:41 +02001109
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001110 old_num_dacs = spec->multiout.num_dacs;
1111 for (i = 0; i < cfg->hp_outs; i++) {
1112 unsigned int wid_caps = get_wcaps(codec, cfg->hp_pins[i]);
1113 if (wid_caps & AC_WCAP_UNSOL_CAP)
1114 spec->hp_detect = 1;
1115 nid = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
1116 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
1117 if (check_in_dac_nids(spec, nid))
1118 nid = 0;
1119 if (! nid)
Mattc7d4b2f2005-06-27 14:59:41 +02001120 continue;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001121 add_spec_dacs(spec, nid);
1122 }
1123 for (i = 0; i < cfg->speaker_outs; i++) {
1124 nid = snd_hda_codec_read(codec, cfg->speaker_pins[0], 0,
1125 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
1126 if (check_in_dac_nids(spec, nid))
1127 nid = 0;
1128 if (check_in_dac_nids(spec, nid))
1129 nid = 0;
1130 if (! nid)
1131 continue;
1132 add_spec_dacs(spec, nid);
Mattc7d4b2f2005-06-27 14:59:41 +02001133 }
1134
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001135 for (i = old_num_dacs; i < spec->multiout.num_dacs; i++) {
1136 static const char *pfxs[] = {
1137 "Speaker", "External Speaker", "Speaker2",
1138 };
1139 err = create_controls(spec, pfxs[i - old_num_dacs],
1140 spec->multiout.dac_nids[i], 3);
1141 if (err < 0)
1142 return err;
1143 }
1144 if (spec->multiout.hp_nid) {
1145 const char *pfx;
1146 if (old_num_dacs == spec->multiout.num_dacs)
1147 pfx = "Master";
1148 else
1149 pfx = "Headphone";
1150 err = create_controls(spec, pfx, spec->multiout.hp_nid, 3);
1151 if (err < 0)
1152 return err;
1153 }
Mattc7d4b2f2005-06-27 14:59:41 +02001154
1155 return 0;
1156}
1157
1158/* create playback/capture controls for input pins */
1159static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
1160{
1161 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02001162 struct hda_input_mux *imux = &spec->private_imux;
1163 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
1164 int i, j, k;
1165
1166 for (i = 0; i < AUTO_PIN_LAST; i++) {
1167 int index = -1;
1168 if (cfg->input_pins[i]) {
Takashi Iwai4a471b72005-12-07 13:56:29 +01001169 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
Mattc7d4b2f2005-06-27 14:59:41 +02001170
1171 for (j=0; j<spec->num_muxes; j++) {
1172 int num_cons = snd_hda_get_connections(codec, spec->mux_nids[j], con_lst, HDA_MAX_NUM_INPUTS);
1173 for (k=0; k<num_cons; k++)
1174 if (con_lst[k] == cfg->input_pins[i]) {
1175 index = k;
1176 break;
1177 }
1178 if (index >= 0)
1179 break;
1180 }
1181 imux->items[imux->num_items].index = index;
1182 imux->num_items++;
1183 }
1184 }
1185
Sam Revitch62fe78e2006-05-10 15:09:17 +02001186 if (imux->num_items == 1) {
1187 /*
1188 * Set the current input for the muxes.
1189 * The STAC9221 has two input muxes with identical source
1190 * NID lists. Hopefully this won't get confused.
1191 */
1192 for (i = 0; i < spec->num_muxes; i++) {
1193 snd_hda_codec_write(codec, spec->mux_nids[i], 0,
1194 AC_VERB_SET_CONNECT_SEL,
1195 imux->items[0].index);
1196 }
1197 }
1198
Mattc7d4b2f2005-06-27 14:59:41 +02001199 return 0;
1200}
1201
Mattc7d4b2f2005-06-27 14:59:41 +02001202static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
1203{
1204 struct sigmatel_spec *spec = codec->spec;
1205 int i;
1206
1207 for (i = 0; i < spec->autocfg.line_outs; i++) {
1208 hda_nid_t nid = spec->autocfg.line_out_pins[i];
1209 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
1210 }
1211}
1212
1213static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
1214{
1215 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001216 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02001217
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001218 for (i = 0; i < spec->autocfg.hp_outs; i++) {
1219 hda_nid_t pin;
1220 pin = spec->autocfg.hp_pins[i];
1221 if (pin) /* connect to front */
1222 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
1223 }
1224 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
1225 hda_nid_t pin;
1226 pin = spec->autocfg.speaker_pins[i];
1227 if (pin) /* connect to front */
1228 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
1229 }
Mattc7d4b2f2005-06-27 14:59:41 +02001230}
1231
Matt Porter3cc08dc2006-01-23 15:27:49 +01001232static 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 +02001233{
1234 struct sigmatel_spec *spec = codec->spec;
1235 int err;
1236
Kailang Yangdf694da2005-12-05 19:42:22 +01001237 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001238 return err;
Takashi Iwai82bc9552006-03-21 11:24:42 +01001239 if (! spec->autocfg.line_outs)
Matt Porter869264c2006-01-25 19:20:50 +01001240 return 0; /* can't find valid pin config */
Takashi Iwai19039bd2006-06-28 15:52:16 +02001241
Matt Porter403d1942005-11-29 15:00:51 +01001242 if ((err = stac92xx_add_dyn_out_pins(codec, &spec->autocfg)) < 0)
1243 return err;
Takashi Iwai19039bd2006-06-28 15:52:16 +02001244 if (spec->multiout.num_dacs == 0)
1245 if ((err = stac92xx_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
1246 return err;
Mattc7d4b2f2005-06-27 14:59:41 +02001247
1248 if ((err = stac92xx_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
1249 (err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg)) < 0 ||
1250 (err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
1251 return err;
1252
1253 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Matt Porter403d1942005-11-29 15:00:51 +01001254 if (spec->multiout.max_channels > 2)
Mattc7d4b2f2005-06-27 14:59:41 +02001255 spec->surr_switch = 1;
Mattc7d4b2f2005-06-27 14:59:41 +02001256
Takashi Iwai82bc9552006-03-21 11:24:42 +01001257 if (spec->autocfg.dig_out_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01001258 spec->multiout.dig_out_nid = dig_out;
Takashi Iwai82bc9552006-03-21 11:24:42 +01001259 if (spec->autocfg.dig_in_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01001260 spec->dig_in_nid = dig_in;
Mattc7d4b2f2005-06-27 14:59:41 +02001261
1262 if (spec->kctl_alloc)
1263 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
1264
1265 spec->input_mux = &spec->private_imux;
1266
1267 return 1;
1268}
1269
Takashi Iwai82bc9552006-03-21 11:24:42 +01001270/* add playback controls for HP output */
1271static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
1272 struct auto_pin_cfg *cfg)
1273{
1274 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001275 hda_nid_t pin = cfg->hp_pins[0];
Takashi Iwai82bc9552006-03-21 11:24:42 +01001276 unsigned int wid_caps;
1277
1278 if (! pin)
1279 return 0;
1280
1281 wid_caps = get_wcaps(codec, pin);
Takashi Iwai505cb342006-03-27 12:51:52 +02001282 if (wid_caps & AC_WCAP_UNSOL_CAP)
Takashi Iwai82bc9552006-03-21 11:24:42 +01001283 spec->hp_detect = 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +01001284
1285 return 0;
1286}
1287
Richard Fish160ea0d2006-09-06 13:58:25 +02001288/* add playback controls for LFE output */
1289static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
1290 struct auto_pin_cfg *cfg)
1291{
1292 struct sigmatel_spec *spec = codec->spec;
1293 int err;
1294 hda_nid_t lfe_pin = 0x0;
1295 int i;
1296
1297 /*
1298 * search speaker outs and line outs for a mono speaker pin
1299 * with an amp. If one is found, add LFE controls
1300 * for it.
1301 */
1302 for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
1303 hda_nid_t pin = spec->autocfg.speaker_pins[i];
1304 unsigned long wcaps = get_wcaps(codec, pin);
1305 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
1306 if (wcaps == AC_WCAP_OUT_AMP)
1307 /* found a mono speaker with an amp, must be lfe */
1308 lfe_pin = pin;
1309 }
1310
1311 /* if speaker_outs is 0, then speakers may be in line_outs */
1312 if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
1313 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
1314 hda_nid_t pin = spec->autocfg.line_out_pins[i];
1315 unsigned long cfg;
1316 cfg = snd_hda_codec_read(codec, pin, 0,
1317 AC_VERB_GET_CONFIG_DEFAULT,
1318 0x00);
1319 if (get_defcfg_device(cfg) == AC_JACK_SPEAKER) {
1320 unsigned long wcaps = get_wcaps(codec, pin);
1321 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
1322 if (wcaps == AC_WCAP_OUT_AMP)
1323 /* found a mono speaker with an amp,
1324 must be lfe */
1325 lfe_pin = pin;
1326 }
1327 }
1328 }
1329
1330 if (lfe_pin) {
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001331 err = create_controls(spec, "LFE", lfe_pin, 1);
Richard Fish160ea0d2006-09-06 13:58:25 +02001332 if (err < 0)
1333 return err;
1334 }
1335
1336 return 0;
1337}
1338
Mattc7d4b2f2005-06-27 14:59:41 +02001339static int stac9200_parse_auto_config(struct hda_codec *codec)
1340{
1341 struct sigmatel_spec *spec = codec->spec;
1342 int err;
1343
Kailang Yangdf694da2005-12-05 19:42:22 +01001344 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001345 return err;
1346
1347 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
1348 return err;
1349
Takashi Iwai82bc9552006-03-21 11:24:42 +01001350 if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
1351 return err;
1352
Richard Fish160ea0d2006-09-06 13:58:25 +02001353 if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
1354 return err;
1355
Takashi Iwai82bc9552006-03-21 11:24:42 +01001356 if (spec->autocfg.dig_out_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02001357 spec->multiout.dig_out_nid = 0x05;
Takashi Iwai82bc9552006-03-21 11:24:42 +01001358 if (spec->autocfg.dig_in_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02001359 spec->dig_in_nid = 0x04;
Mattc7d4b2f2005-06-27 14:59:41 +02001360
1361 if (spec->kctl_alloc)
1362 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
1363
1364 spec->input_mux = &spec->private_imux;
1365
1366 return 1;
1367}
1368
Sam Revitch62fe78e2006-05-10 15:09:17 +02001369/*
1370 * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
1371 * funky external mute control using GPIO pins.
1372 */
1373
1374static void stac922x_gpio_mute(struct hda_codec *codec, int pin, int muted)
1375{
1376 unsigned int gpiostate, gpiomask, gpiodir;
1377
1378 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
1379 AC_VERB_GET_GPIO_DATA, 0);
1380
1381 if (!muted)
1382 gpiostate |= (1 << pin);
1383 else
1384 gpiostate &= ~(1 << pin);
1385
1386 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
1387 AC_VERB_GET_GPIO_MASK, 0);
1388 gpiomask |= (1 << pin);
1389
1390 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
1391 AC_VERB_GET_GPIO_DIRECTION, 0);
1392 gpiodir |= (1 << pin);
1393
1394 /* AppleHDA seems to do this -- WTF is this verb?? */
1395 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
1396
1397 snd_hda_codec_write(codec, codec->afg, 0,
1398 AC_VERB_SET_GPIO_MASK, gpiomask);
1399 snd_hda_codec_write(codec, codec->afg, 0,
1400 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
1401
1402 msleep(1);
1403
1404 snd_hda_codec_write(codec, codec->afg, 0,
1405 AC_VERB_SET_GPIO_DATA, gpiostate);
1406}
1407
Mattc7d4b2f2005-06-27 14:59:41 +02001408static int stac92xx_init(struct hda_codec *codec)
1409{
1410 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai82bc9552006-03-21 11:24:42 +01001411 struct auto_pin_cfg *cfg = &spec->autocfg;
1412 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02001413
Mattc7d4b2f2005-06-27 14:59:41 +02001414 snd_hda_sequence_write(codec, spec->init);
1415
Takashi Iwai82bc9552006-03-21 11:24:42 +01001416 /* set up pins */
1417 if (spec->hp_detect) {
Takashi Iwai505cb342006-03-27 12:51:52 +02001418 /* Enable unsolicited responses on the HP widget */
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001419 for (i = 0; i < cfg->hp_outs; i++)
1420 if (get_wcaps(codec, cfg->hp_pins[i]) & AC_WCAP_UNSOL_CAP)
1421 snd_hda_codec_write(codec, cfg->hp_pins[i], 0,
1422 AC_VERB_SET_UNSOLICITED_ENABLE,
1423 STAC_UNSOL_ENABLE);
Takashi Iwai82bc9552006-03-21 11:24:42 +01001424 /* fake event to set up pins */
1425 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
Tobin Davis68a6abd2006-08-21 19:02:10 +02001426 /* enable the headphones by default. If/when unsol_event detection works, this will be ignored */
1427 stac92xx_auto_init_hp_out(codec);
Takashi Iwai82bc9552006-03-21 11:24:42 +01001428 } else {
1429 stac92xx_auto_init_multi_out(codec);
1430 stac92xx_auto_init_hp_out(codec);
1431 }
1432 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwaic960a032006-03-23 17:06:28 +01001433 hda_nid_t nid = cfg->input_pins[i];
1434 if (nid) {
1435 unsigned int pinctl = AC_PINCTL_IN_EN;
1436 if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC)
1437 pinctl |= stac92xx_get_vref(codec, nid);
1438 stac92xx_auto_set_pinctl(codec, nid, pinctl);
1439 }
Takashi Iwai82bc9552006-03-21 11:24:42 +01001440 }
1441 if (cfg->dig_out_pin)
1442 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pin,
1443 AC_PINCTL_OUT_EN);
1444 if (cfg->dig_in_pin)
1445 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
1446 AC_PINCTL_IN_EN);
1447
Sam Revitch62fe78e2006-05-10 15:09:17 +02001448 if (spec->gpio_mute) {
1449 stac922x_gpio_mute(codec, 0, 0);
1450 stac922x_gpio_mute(codec, 1, 0);
1451 }
1452
Mattc7d4b2f2005-06-27 14:59:41 +02001453 return 0;
1454}
1455
Matt2f2f4252005-04-13 14:45:30 +02001456static void stac92xx_free(struct hda_codec *codec)
1457{
Mattc7d4b2f2005-06-27 14:59:41 +02001458 struct sigmatel_spec *spec = codec->spec;
1459 int i;
1460
1461 if (! spec)
1462 return;
1463
1464 if (spec->kctl_alloc) {
1465 for (i = 0; i < spec->num_kctl_used; i++)
1466 kfree(spec->kctl_alloc[i].name);
1467 kfree(spec->kctl_alloc);
1468 }
1469
Richard Fish11b44bb2006-08-23 18:31:34 +02001470 if (spec->bios_pin_configs)
1471 kfree(spec->bios_pin_configs);
1472
Mattc7d4b2f2005-06-27 14:59:41 +02001473 kfree(spec);
Matt2f2f4252005-04-13 14:45:30 +02001474}
1475
Matt4e550962005-07-04 17:51:39 +02001476static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
1477 unsigned int flag)
1478{
1479 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
1480 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
1481 snd_hda_codec_write(codec, nid, 0,
1482 AC_VERB_SET_PIN_WIDGET_CONTROL,
1483 pin_ctl | flag);
1484}
1485
1486static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
1487 unsigned int flag)
1488{
1489 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
1490 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
1491 snd_hda_codec_write(codec, nid, 0,
1492 AC_VERB_SET_PIN_WIDGET_CONTROL,
1493 pin_ctl & ~flag);
1494}
1495
1496static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
1497{
1498 struct sigmatel_spec *spec = codec->spec;
1499 struct auto_pin_cfg *cfg = &spec->autocfg;
1500 int i, presence;
1501
1502 if ((res >> 26) != STAC_HP_EVENT)
1503 return;
1504
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001505 presence = 0;
1506 for (i = 0; i < cfg->hp_outs; i++) {
1507 int p = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
1508 AC_VERB_GET_PIN_SENSE, 0x00);
1509 if (p & (1 << 31))
1510 presence++;
1511 }
Matt4e550962005-07-04 17:51:39 +02001512
1513 if (presence) {
1514 /* disable lineouts, enable hp */
1515 for (i = 0; i < cfg->line_outs; i++)
1516 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
1517 AC_PINCTL_OUT_EN);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001518 for (i = 0; i < cfg->speaker_outs; i++)
1519 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
1520 AC_PINCTL_OUT_EN);
1521 for (i = 0; i < cfg->hp_outs; i++)
1522 stac92xx_set_pinctl(codec, cfg->hp_pins[i],
1523 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02001524 } else {
1525 /* enable lineouts, disable hp */
1526 for (i = 0; i < cfg->line_outs; i++)
1527 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
1528 AC_PINCTL_OUT_EN);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001529 for (i = 0; i < cfg->speaker_outs; i++)
1530 stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
1531 AC_PINCTL_OUT_EN);
1532 for (i = 0; i < cfg->hp_outs; i++)
1533 stac92xx_reset_pinctl(codec, cfg->hp_pins[i],
1534 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02001535 }
1536}
1537
Mattff6fdc32005-06-27 15:06:52 +02001538#ifdef CONFIG_PM
1539static int stac92xx_resume(struct hda_codec *codec)
1540{
1541 struct sigmatel_spec *spec = codec->spec;
1542 int i;
1543
1544 stac92xx_init(codec);
Richard Fish11b44bb2006-08-23 18:31:34 +02001545 stac92xx_set_config_regs(codec);
Mattff6fdc32005-06-27 15:06:52 +02001546 for (i = 0; i < spec->num_mixers; i++)
1547 snd_hda_resume_ctls(codec, spec->mixers[i]);
1548 if (spec->multiout.dig_out_nid)
1549 snd_hda_resume_spdif_out(codec);
1550 if (spec->dig_in_nid)
1551 snd_hda_resume_spdif_in(codec);
1552
1553 return 0;
1554}
1555#endif
1556
Matt2f2f4252005-04-13 14:45:30 +02001557static struct hda_codec_ops stac92xx_patch_ops = {
1558 .build_controls = stac92xx_build_controls,
1559 .build_pcms = stac92xx_build_pcms,
1560 .init = stac92xx_init,
1561 .free = stac92xx_free,
Matt4e550962005-07-04 17:51:39 +02001562 .unsol_event = stac92xx_unsol_event,
Mattff6fdc32005-06-27 15:06:52 +02001563#ifdef CONFIG_PM
1564 .resume = stac92xx_resume,
1565#endif
Matt2f2f4252005-04-13 14:45:30 +02001566};
1567
1568static int patch_stac9200(struct hda_codec *codec)
1569{
1570 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02001571 int err;
Matt2f2f4252005-04-13 14:45:30 +02001572
Takashi Iwaie560d8d2005-09-09 14:21:46 +02001573 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02001574 if (spec == NULL)
1575 return -ENOMEM;
1576
1577 codec->spec = spec;
Richard Fish11b44bb2006-08-23 18:31:34 +02001578 spec->num_pins = 8;
1579 spec->pin_nids = stac9200_pin_nids;
Matt Porter403d1942005-11-29 15:00:51 +01001580 spec->board_config = snd_hda_check_board_config(codec, stac9200_cfg_tbl);
Richard Fish11b44bb2006-08-23 18:31:34 +02001581 if (spec->board_config < 0) {
1582 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9200, using BIOS defaults\n");
1583 err = stac92xx_save_bios_config_regs(codec);
1584 if (err < 0) {
1585 stac92xx_free(codec);
1586 return err;
1587 }
1588 spec->pin_configs = spec->bios_pin_configs;
1589 } else {
Matt Porter403d1942005-11-29 15:00:51 +01001590 spec->pin_configs = stac9200_brd_tbl[spec->board_config];
1591 stac92xx_set_config_regs(codec);
1592 }
Matt2f2f4252005-04-13 14:45:30 +02001593
1594 spec->multiout.max_channels = 2;
1595 spec->multiout.num_dacs = 1;
1596 spec->multiout.dac_nids = stac9200_dac_nids;
1597 spec->adc_nids = stac9200_adc_nids;
1598 spec->mux_nids = stac9200_mux_nids;
Mattdabbed62005-06-14 10:19:34 +02001599 spec->num_muxes = 1;
Mattc7d4b2f2005-06-27 14:59:41 +02001600
1601 spec->init = stac9200_core_init;
Matt2f2f4252005-04-13 14:45:30 +02001602 spec->mixer = stac9200_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02001603
1604 err = stac9200_parse_auto_config(codec);
1605 if (err < 0) {
1606 stac92xx_free(codec);
1607 return err;
1608 }
Matt2f2f4252005-04-13 14:45:30 +02001609
1610 codec->patch_ops = stac92xx_patch_ops;
1611
1612 return 0;
1613}
1614
1615static int patch_stac922x(struct hda_codec *codec)
1616{
1617 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02001618 int err;
Matt2f2f4252005-04-13 14:45:30 +02001619
Takashi Iwaie560d8d2005-09-09 14:21:46 +02001620 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02001621 if (spec == NULL)
1622 return -ENOMEM;
1623
1624 codec->spec = spec;
Richard Fish11b44bb2006-08-23 18:31:34 +02001625 spec->num_pins = 10;
1626 spec->pin_nids = stac922x_pin_nids;
Matt Porter403d1942005-11-29 15:00:51 +01001627 spec->board_config = snd_hda_check_board_config(codec, stac922x_cfg_tbl);
Richard Fish11b44bb2006-08-23 18:31:34 +02001628 if (spec->board_config < 0) {
1629 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC922x, "
1630 "using BIOS defaults\n");
1631 err = stac92xx_save_bios_config_regs(codec);
1632 if (err < 0) {
1633 stac92xx_free(codec);
1634 return err;
1635 }
1636 spec->pin_configs = spec->bios_pin_configs;
1637 } else if (stac922x_brd_tbl[spec->board_config] != NULL) {
Matt Porter403d1942005-11-29 15:00:51 +01001638 spec->pin_configs = stac922x_brd_tbl[spec->board_config];
1639 stac92xx_set_config_regs(codec);
1640 }
Matt2f2f4252005-04-13 14:45:30 +02001641
Matt2f2f4252005-04-13 14:45:30 +02001642 spec->adc_nids = stac922x_adc_nids;
1643 spec->mux_nids = stac922x_mux_nids;
Mattdabbed62005-06-14 10:19:34 +02001644 spec->num_muxes = 2;
Mattc7d4b2f2005-06-27 14:59:41 +02001645
1646 spec->init = stac922x_core_init;
Matt2f2f4252005-04-13 14:45:30 +02001647 spec->mixer = stac922x_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02001648
1649 spec->multiout.dac_nids = spec->dac_nids;
Takashi Iwai19039bd2006-06-28 15:52:16 +02001650
Matt Porter3cc08dc2006-01-23 15:27:49 +01001651 err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
1652 if (err < 0) {
1653 stac92xx_free(codec);
1654 return err;
1655 }
1656
Sam Revitch62fe78e2006-05-10 15:09:17 +02001657 if (spec->board_config == STAC_MACMINI)
1658 spec->gpio_mute = 1;
1659
Matt Porter3cc08dc2006-01-23 15:27:49 +01001660 codec->patch_ops = stac92xx_patch_ops;
1661
1662 return 0;
1663}
1664
1665static int patch_stac927x(struct hda_codec *codec)
1666{
1667 struct sigmatel_spec *spec;
1668 int err;
1669
1670 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1671 if (spec == NULL)
1672 return -ENOMEM;
1673
1674 codec->spec = spec;
Richard Fish11b44bb2006-08-23 18:31:34 +02001675 spec->num_pins = 14;
1676 spec->pin_nids = stac927x_pin_nids;
Matt Porter3cc08dc2006-01-23 15:27:49 +01001677 spec->board_config = snd_hda_check_board_config(codec, stac927x_cfg_tbl);
Richard Fish11b44bb2006-08-23 18:31:34 +02001678 if (spec->board_config < 0) {
Matt Porter3cc08dc2006-01-23 15:27:49 +01001679 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC927x, using BIOS defaults\n");
Richard Fish11b44bb2006-08-23 18:31:34 +02001680 err = stac92xx_save_bios_config_regs(codec);
1681 if (err < 0) {
1682 stac92xx_free(codec);
1683 return err;
1684 }
1685 spec->pin_configs = spec->bios_pin_configs;
1686 } else if (stac927x_brd_tbl[spec->board_config] != NULL) {
Matt Porter3cc08dc2006-01-23 15:27:49 +01001687 spec->pin_configs = stac927x_brd_tbl[spec->board_config];
1688 stac92xx_set_config_regs(codec);
1689 }
1690
Tobin Davis81d3dbd2006-08-22 19:44:45 +02001691 switch (spec->board_config) {
Tobin Davis93ed1502006-09-01 21:03:12 +02001692 case STAC_D965_3ST:
Tobin Davis81d3dbd2006-08-22 19:44:45 +02001693 spec->adc_nids = stac927x_adc_nids;
1694 spec->mux_nids = stac927x_mux_nids;
1695 spec->num_muxes = 3;
Tobin Davis93ed1502006-09-01 21:03:12 +02001696 spec->init = d965_core_init;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02001697 spec->mixer = stac9227_mixer;
1698 break;
Tobin Davis93ed1502006-09-01 21:03:12 +02001699 case STAC_D965_5ST:
1700 spec->adc_nids = stac927x_adc_nids;
1701 spec->mux_nids = stac927x_mux_nids;
1702 spec->num_muxes = 3;
1703 spec->init = d965_core_init;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02001704 spec->mixer = stac9227_mixer;
1705 break;
1706 default:
1707 spec->adc_nids = stac927x_adc_nids;
1708 spec->mux_nids = stac927x_mux_nids;
1709 spec->num_muxes = 3;
1710 spec->init = stac927x_core_init;
1711 spec->mixer = stac927x_mixer;
1712 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01001713
1714 spec->multiout.dac_nids = spec->dac_nids;
1715
1716 err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
Mattc7d4b2f2005-06-27 14:59:41 +02001717 if (err < 0) {
1718 stac92xx_free(codec);
1719 return err;
1720 }
Matt2f2f4252005-04-13 14:45:30 +02001721
1722 codec->patch_ops = stac92xx_patch_ops;
1723
1724 return 0;
1725}
1726
Matt Porterf3302a52006-07-31 12:49:34 +02001727static int patch_stac9205(struct hda_codec *codec)
1728{
1729 struct sigmatel_spec *spec;
1730 int err;
1731
1732 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1733 if (spec == NULL)
1734 return -ENOMEM;
1735
1736 codec->spec = spec;
Richard Fish11b44bb2006-08-23 18:31:34 +02001737 spec->num_pins = 14;
1738 spec->pin_nids = stac9205_pin_nids;
Matt Porterf3302a52006-07-31 12:49:34 +02001739 spec->board_config = snd_hda_check_board_config(codec, stac9205_cfg_tbl);
Richard Fish11b44bb2006-08-23 18:31:34 +02001740 if (spec->board_config < 0) {
1741 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9205, using BIOS defaults\n");
1742 err = stac92xx_save_bios_config_regs(codec);
1743 if (err < 0) {
1744 stac92xx_free(codec);
1745 return err;
1746 }
1747 spec->pin_configs = spec->bios_pin_configs;
1748 } else {
Matt Porterf3302a52006-07-31 12:49:34 +02001749 spec->pin_configs = stac9205_brd_tbl[spec->board_config];
1750 stac92xx_set_config_regs(codec);
1751 }
1752
1753 spec->adc_nids = stac9205_adc_nids;
1754 spec->mux_nids = stac9205_mux_nids;
1755 spec->num_muxes = 3;
1756
1757 spec->init = stac9205_core_init;
1758 spec->mixer = stac9205_mixer;
1759
1760 spec->multiout.dac_nids = spec->dac_nids;
1761
1762 err = stac92xx_parse_auto_config(codec, 0x1f, 0x20);
1763 if (err < 0) {
1764 stac92xx_free(codec);
1765 return err;
1766 }
1767
1768 codec->patch_ops = stac92xx_patch_ops;
1769
1770 return 0;
1771}
1772
Matt2f2f4252005-04-13 14:45:30 +02001773/*
Guillaume Munch6d859062006-08-22 17:15:47 +02001774 * STAC9872 hack
Takashi Iwaidb064e52006-03-16 16:04:58 +01001775 */
1776
Guillaume Munch99ccc562006-08-16 19:35:12 +02001777/* static config for Sony VAIO FE550G and Sony VAIO AR */
Takashi Iwaidb064e52006-03-16 16:04:58 +01001778static hda_nid_t vaio_dacs[] = { 0x2 };
1779#define VAIO_HP_DAC 0x5
1780static hda_nid_t vaio_adcs[] = { 0x8 /*,0x6*/ };
1781static hda_nid_t vaio_mux_nids[] = { 0x15 };
1782
1783static struct hda_input_mux vaio_mux = {
1784 .num_items = 2,
1785 .items = {
Takashi Iwaid7737812006-04-25 13:05:43 +02001786 /* { "HP", 0x0 }, */
1787 { "Line", 0x1 },
Takashi Iwaidb064e52006-03-16 16:04:58 +01001788 { "Mic", 0x2 },
1789 { "PCM", 0x3 },
1790 }
1791};
1792
1793static struct hda_verb vaio_init[] = {
1794 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
1795 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
1796 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
1797 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
1798 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
1799 {0x15, AC_VERB_SET_CONNECT_SEL, 0x2}, /* mic-sel: 0a,0d,14,02 */
1800 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
1801 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
1802 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
1803 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
1804 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
1805 {}
1806};
1807
Guillaume Munch6d859062006-08-22 17:15:47 +02001808static struct hda_verb vaio_ar_init[] = {
1809 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
1810 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
1811 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
1812 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
1813/* {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },*/ /* Optical Out */
1814 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
1815 {0x15, AC_VERB_SET_CONNECT_SEL, 0x2}, /* mic-sel: 0a,0d,14,02 */
1816 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
1817 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
1818/* {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},*/ /* Optical Out */
1819 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
1820 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
1821 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
1822 {}
1823};
1824
Takashi Iwaidb064e52006-03-16 16:04:58 +01001825/* bind volumes of both NID 0x02 and 0x05 */
1826static int vaio_master_vol_put(struct snd_kcontrol *kcontrol,
1827 struct snd_ctl_elem_value *ucontrol)
1828{
1829 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1830 long *valp = ucontrol->value.integer.value;
1831 int change;
1832
1833 change = snd_hda_codec_amp_update(codec, 0x02, 0, HDA_OUTPUT, 0,
1834 0x7f, valp[0] & 0x7f);
1835 change |= snd_hda_codec_amp_update(codec, 0x02, 1, HDA_OUTPUT, 0,
1836 0x7f, valp[1] & 0x7f);
1837 snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
1838 0x7f, valp[0] & 0x7f);
1839 snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
1840 0x7f, valp[1] & 0x7f);
1841 return change;
1842}
1843
1844/* bind volumes of both NID 0x02 and 0x05 */
1845static int vaio_master_sw_put(struct snd_kcontrol *kcontrol,
1846 struct snd_ctl_elem_value *ucontrol)
1847{
1848 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1849 long *valp = ucontrol->value.integer.value;
1850 int change;
1851
1852 change = snd_hda_codec_amp_update(codec, 0x02, 0, HDA_OUTPUT, 0,
Takashi Iwaia9393d72006-05-03 11:59:03 +02001853 0x80, (valp[0] ? 0 : 0x80));
Takashi Iwaidb064e52006-03-16 16:04:58 +01001854 change |= snd_hda_codec_amp_update(codec, 0x02, 1, HDA_OUTPUT, 0,
Takashi Iwaia9393d72006-05-03 11:59:03 +02001855 0x80, (valp[1] ? 0 : 0x80));
Takashi Iwaidb064e52006-03-16 16:04:58 +01001856 snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
Takashi Iwaia9393d72006-05-03 11:59:03 +02001857 0x80, (valp[0] ? 0 : 0x80));
Takashi Iwaidb064e52006-03-16 16:04:58 +01001858 snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
Takashi Iwaia9393d72006-05-03 11:59:03 +02001859 0x80, (valp[1] ? 0 : 0x80));
Takashi Iwaidb064e52006-03-16 16:04:58 +01001860 return change;
1861}
1862
1863static struct snd_kcontrol_new vaio_mixer[] = {
1864 {
1865 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1866 .name = "Master Playback Volume",
1867 .info = snd_hda_mixer_amp_volume_info,
1868 .get = snd_hda_mixer_amp_volume_get,
1869 .put = vaio_master_vol_put,
Takashi Iwaic2566522006-08-17 18:21:36 +02001870 .tlv = { .c = snd_hda_mixer_amp_tlv },
Takashi Iwaidb064e52006-03-16 16:04:58 +01001871 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
1872 },
1873 {
1874 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1875 .name = "Master Playback Switch",
1876 .info = snd_hda_mixer_amp_switch_info,
1877 .get = snd_hda_mixer_amp_switch_get,
1878 .put = vaio_master_sw_put,
1879 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
1880 },
1881 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
1882 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
1883 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
1884 {
1885 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1886 .name = "Capture Source",
1887 .count = 1,
1888 .info = stac92xx_mux_enum_info,
1889 .get = stac92xx_mux_enum_get,
1890 .put = stac92xx_mux_enum_put,
1891 },
1892 {}
1893};
1894
Guillaume Munch6d859062006-08-22 17:15:47 +02001895static struct snd_kcontrol_new vaio_ar_mixer[] = {
1896 {
1897 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1898 .name = "Master Playback Volume",
1899 .info = snd_hda_mixer_amp_volume_info,
1900 .get = snd_hda_mixer_amp_volume_get,
1901 .put = vaio_master_vol_put,
1902 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
1903 },
1904 {
1905 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1906 .name = "Master Playback Switch",
1907 .info = snd_hda_mixer_amp_switch_info,
1908 .get = snd_hda_mixer_amp_switch_get,
1909 .put = vaio_master_sw_put,
1910 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
1911 },
1912 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
1913 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
1914 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
1915 /*HDA_CODEC_MUTE("Optical Out Switch", 0x10, 0, HDA_OUTPUT),
1916 HDA_CODEC_VOLUME("Optical Out Volume", 0x10, 0, HDA_OUTPUT),*/
1917 {
1918 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1919 .name = "Capture Source",
1920 .count = 1,
1921 .info = stac92xx_mux_enum_info,
1922 .get = stac92xx_mux_enum_get,
1923 .put = stac92xx_mux_enum_put,
1924 },
1925 {}
1926};
1927
1928static struct hda_codec_ops stac9872_patch_ops = {
Takashi Iwaidb064e52006-03-16 16:04:58 +01001929 .build_controls = stac92xx_build_controls,
1930 .build_pcms = stac92xx_build_pcms,
1931 .init = stac92xx_init,
1932 .free = stac92xx_free,
1933#ifdef CONFIG_PM
1934 .resume = stac92xx_resume,
1935#endif
1936};
1937
Guillaume Munch6d859062006-08-22 17:15:47 +02001938enum { /* FE and SZ series. id=0x83847661 and subsys=0x104D0700 or 104D1000. */
1939 CXD9872RD_VAIO,
1940 /* Unknown. id=0x83847662 and subsys=0x104D1200 or 104D1000. */
1941 STAC9872AK_VAIO,
1942 /* Unknown. id=0x83847661 and subsys=0x104D1200. */
1943 STAC9872K_VAIO,
1944 /* AR Series. id=0x83847664 and subsys=104D1300 */
1945 CXD9872AKD_VAIO
1946 };
Takashi Iwaidb064e52006-03-16 16:04:58 +01001947
Guillaume Munch6d859062006-08-22 17:15:47 +02001948static struct hda_board_config stac9872_cfg_tbl[] = {
1949 { .modelname = "vaio", .config = CXD9872RD_VAIO },
1950 { .modelname = "vaio-ar", .config = CXD9872AKD_VAIO },
Takashi Iwaidb064e52006-03-16 16:04:58 +01001951 { .pci_subvendor = 0x104d, .pci_subdevice = 0x81e6,
Guillaume Munch6d859062006-08-22 17:15:47 +02001952 .config = CXD9872RD_VAIO },
Takashi Iwaidb064e52006-03-16 16:04:58 +01001953 { .pci_subvendor = 0x104d, .pci_subdevice = 0x81ef,
Guillaume Munch6d859062006-08-22 17:15:47 +02001954 .config = CXD9872RD_VAIO },
Guillaume Munch99ccc562006-08-16 19:35:12 +02001955 { .pci_subvendor = 0x104d, .pci_subdevice = 0x81fd,
Guillaume Munch6d859062006-08-22 17:15:47 +02001956 .config = CXD9872AKD_VAIO },
Takashi Iwaidb064e52006-03-16 16:04:58 +01001957 {}
1958};
1959
Guillaume Munch6d859062006-08-22 17:15:47 +02001960static int patch_stac9872(struct hda_codec *codec)
Takashi Iwaidb064e52006-03-16 16:04:58 +01001961{
1962 struct sigmatel_spec *spec;
1963 int board_config;
1964
Guillaume Munch6d859062006-08-22 17:15:47 +02001965 board_config = snd_hda_check_board_config(codec, stac9872_cfg_tbl);
Takashi Iwaidb064e52006-03-16 16:04:58 +01001966 if (board_config < 0)
1967 /* unknown config, let generic-parser do its job... */
1968 return snd_hda_parse_generic_codec(codec);
1969
1970 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1971 if (spec == NULL)
1972 return -ENOMEM;
1973
1974 codec->spec = spec;
1975 switch (board_config) {
Guillaume Munch6d859062006-08-22 17:15:47 +02001976 case CXD9872RD_VAIO:
1977 case STAC9872AK_VAIO:
1978 case STAC9872K_VAIO:
Takashi Iwaidb064e52006-03-16 16:04:58 +01001979 spec->mixer = vaio_mixer;
1980 spec->init = vaio_init;
1981 spec->multiout.max_channels = 2;
1982 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
1983 spec->multiout.dac_nids = vaio_dacs;
1984 spec->multiout.hp_nid = VAIO_HP_DAC;
1985 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
1986 spec->adc_nids = vaio_adcs;
1987 spec->input_mux = &vaio_mux;
1988 spec->mux_nids = vaio_mux_nids;
1989 break;
Guillaume Munch6d859062006-08-22 17:15:47 +02001990
1991 case CXD9872AKD_VAIO:
1992 spec->mixer = vaio_ar_mixer;
1993 spec->init = vaio_ar_init;
1994 spec->multiout.max_channels = 2;
1995 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
1996 spec->multiout.dac_nids = vaio_dacs;
1997 spec->multiout.hp_nid = VAIO_HP_DAC;
1998 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
1999 spec->adc_nids = vaio_adcs;
2000 spec->input_mux = &vaio_mux;
2001 spec->mux_nids = vaio_mux_nids;
2002 break;
Takashi Iwaidb064e52006-03-16 16:04:58 +01002003 }
2004
Guillaume Munch6d859062006-08-22 17:15:47 +02002005 codec->patch_ops = stac9872_patch_ops;
Takashi Iwaidb064e52006-03-16 16:04:58 +01002006 return 0;
2007}
2008
2009
2010/*
Matt2f2f4252005-04-13 14:45:30 +02002011 * patch entries
2012 */
2013struct hda_codec_preset snd_hda_preset_sigmatel[] = {
2014 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
2015 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
2016 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
2017 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
2018 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
2019 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
2020 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
Matt Porter22a27c72006-07-06 18:49:10 +02002021 { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
2022 { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
2023 { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
2024 { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
2025 { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
2026 { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
Matt Porter3cc08dc2006-01-23 15:27:49 +01002027 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
2028 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
2029 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
2030 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
2031 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
2032 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
2033 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
2034 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
2035 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
2036 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
Guillaume Munch6d859062006-08-22 17:15:47 +02002037 /* The following does not take into account .id=0x83847661 when subsys =
2038 * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
2039 * currently not fully supported.
2040 */
2041 { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
2042 { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
2043 { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
Matt Porterf3302a52006-07-31 12:49:34 +02002044 { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
2045 { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
2046 { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
2047 { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
2048 { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
2049 { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
2050 { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
2051 { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
Matt2f2f4252005-04-13 14:45:30 +02002052 {} /* terminator */
2053};