blob: 7b29288690cb3f8b1685ea04a65c97b4c0773fc1 [file] [log] [blame]
Matt2f2f4252005-04-13 14:45:30 +02001/*
2 * Universal Interface for Intel High Definition Audio Codec
3 *
4 * HD audio interface patch for SigmaTel STAC92xx
5 *
6 * Copyright (c) 2005 Embedded Alley Solutions, Inc.
Matt Porter403d1942005-11-29 15:00:51 +01007 * Matt Porter <mporter@embeddedalley.com>
Matt2f2f4252005-04-13 14:45:30 +02008 *
9 * Based on patch_cmedia.c and patch_realtek.c
10 * Copyright (c) 2004 Takashi Iwai <tiwai@suse.de>
11 *
12 * This driver is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This driver is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 */
26
27#include <sound/driver.h>
28#include <linux/init.h>
29#include <linux/delay.h>
30#include <linux/slab.h>
31#include <linux/pci.h>
32#include <sound/core.h>
Mattc7d4b2f2005-06-27 14:59:41 +020033#include <sound/asoundef.h>
Matt2f2f4252005-04-13 14:45:30 +020034#include "hda_codec.h"
35#include "hda_local.h"
36
Matt4e550962005-07-04 17:51:39 +020037#define NUM_CONTROL_ALLOC 32
38#define STAC_HP_EVENT 0x37
39#define STAC_UNSOL_ENABLE (AC_USRSP_EN | STAC_HP_EVENT)
40
Matt Porter403d1942005-11-29 15:00:51 +010041#define STAC_REF 0
42#define STAC_D945GTP3 1
43#define STAC_D945GTP5 2
Sam Revitch62fe78e2006-05-10 15:09:17 +020044#define STAC_MACMINI 3
Takashi Iwai19039bd2006-06-28 15:52:16 +020045#define STAC_D965_2112 4
46#define STAC_D965_284B 5
47#define STAC_922X_MODELS 6 /* number of 922x models */
Matt Porter403d1942005-11-29 15:00:51 +010048
Matt2f2f4252005-04-13 14:45:30 +020049struct sigmatel_spec {
Takashi Iwaic8b6bf92005-11-17 14:57:47 +010050 struct snd_kcontrol_new *mixers[4];
Mattc7d4b2f2005-06-27 14:59:41 +020051 unsigned int num_mixers;
52
Matt Porter403d1942005-11-29 15:00:51 +010053 int board_config;
Mattc7d4b2f2005-06-27 14:59:41 +020054 unsigned int surr_switch: 1;
Matt Porter403d1942005-11-29 15:00:51 +010055 unsigned int line_switch: 1;
56 unsigned int mic_switch: 1;
Matt Porter3cc08dc2006-01-23 15:27:49 +010057 unsigned int alt_switch: 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +010058 unsigned int hp_detect: 1;
Sam Revitch62fe78e2006-05-10 15:09:17 +020059 unsigned int gpio_mute: 1;
Mattc7d4b2f2005-06-27 14:59:41 +020060
Matt2f2f4252005-04-13 14:45:30 +020061 /* playback */
62 struct hda_multi_out multiout;
Matt Porter3cc08dc2006-01-23 15:27:49 +010063 hda_nid_t dac_nids[5];
Matt2f2f4252005-04-13 14:45:30 +020064
65 /* capture */
66 hda_nid_t *adc_nids;
Matt2f2f4252005-04-13 14:45:30 +020067 unsigned int num_adcs;
Mattdabbed62005-06-14 10:19:34 +020068 hda_nid_t *mux_nids;
69 unsigned int num_muxes;
Mattdabbed62005-06-14 10:19:34 +020070 hda_nid_t dig_in_nid;
Matt2f2f4252005-04-13 14:45:30 +020071
Matt2f2f4252005-04-13 14:45:30 +020072 /* pin widgets */
73 hda_nid_t *pin_nids;
74 unsigned int num_pins;
Matt2f2f4252005-04-13 14:45:30 +020075 unsigned int *pin_configs;
Matt2f2f4252005-04-13 14:45:30 +020076
77 /* codec specific stuff */
78 struct hda_verb *init;
Takashi Iwaic8b6bf92005-11-17 14:57:47 +010079 struct snd_kcontrol_new *mixer;
Matt2f2f4252005-04-13 14:45:30 +020080
81 /* capture source */
Mattc7d4b2f2005-06-27 14:59:41 +020082 struct hda_input_mux *input_mux;
Matt Porter3cc08dc2006-01-23 15:27:49 +010083 unsigned int cur_mux[3];
Matt2f2f4252005-04-13 14:45:30 +020084
Matt Porter403d1942005-11-29 15:00:51 +010085 /* i/o switches */
86 unsigned int io_switch[2];
Matt2f2f4252005-04-13 14:45:30 +020087
Mattc7d4b2f2005-06-27 14:59:41 +020088 struct hda_pcm pcm_rec[2]; /* PCM information */
89
90 /* dynamic controls and input_mux */
91 struct auto_pin_cfg autocfg;
92 unsigned int num_kctl_alloc, num_kctl_used;
Takashi Iwaic8b6bf92005-11-17 14:57:47 +010093 struct snd_kcontrol_new *kctl_alloc;
Mattc7d4b2f2005-06-27 14:59:41 +020094 struct hda_input_mux private_imux;
Matt2f2f4252005-04-13 14:45:30 +020095};
96
97static hda_nid_t stac9200_adc_nids[1] = {
98 0x03,
99};
100
101static hda_nid_t stac9200_mux_nids[1] = {
102 0x0c,
103};
104
105static hda_nid_t stac9200_dac_nids[1] = {
106 0x02,
107};
108
Matt2f2f4252005-04-13 14:45:30 +0200109static hda_nid_t stac922x_adc_nids[2] = {
110 0x06, 0x07,
111};
112
Takashi Iwai19039bd2006-06-28 15:52:16 +0200113static hda_nid_t stac9227_adc_nids[2] = {
114 0x07, 0x08,
115};
116
117#if 0
118static hda_nid_t d965_2112_dac_nids[3] = {
119 0x02, 0x03, 0x05,
120};
121#endif
122
Matt2f2f4252005-04-13 14:45:30 +0200123static hda_nid_t stac922x_mux_nids[2] = {
124 0x12, 0x13,
125};
126
Takashi Iwai19039bd2006-06-28 15:52:16 +0200127static hda_nid_t stac9227_mux_nids[2] = {
128 0x15, 0x16,
129};
130
Matt Porter3cc08dc2006-01-23 15:27:49 +0100131static hda_nid_t stac927x_adc_nids[3] = {
132 0x07, 0x08, 0x09
133};
134
135static hda_nid_t stac927x_mux_nids[3] = {
136 0x15, 0x16, 0x17
137};
138
Matt Porterf3302a52006-07-31 12:49:34 +0200139static hda_nid_t stac9205_adc_nids[2] = {
140 0x12, 0x13
141};
142
143static hda_nid_t stac9205_mux_nids[2] = {
144 0x19, 0x1a
145};
146
Mattc7d4b2f2005-06-27 14:59:41 +0200147static hda_nid_t stac9200_pin_nids[8] = {
148 0x08, 0x09, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12,
Matt2f2f4252005-04-13 14:45:30 +0200149};
150
151static hda_nid_t stac922x_pin_nids[10] = {
152 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
153 0x0f, 0x10, 0x11, 0x15, 0x1b,
154};
155
Matt Porter3cc08dc2006-01-23 15:27:49 +0100156static hda_nid_t stac927x_pin_nids[14] = {
157 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
158 0x0f, 0x10, 0x11, 0x12, 0x13,
159 0x14, 0x21, 0x22, 0x23,
160};
161
Matt Porterf3302a52006-07-31 12:49:34 +0200162static hda_nid_t stac9205_pin_nids[12] = {
163 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
164 0x0f, 0x14, 0x16, 0x17, 0x18,
165 0x21, 0x22,
166
167};
168
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100169static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Matt2f2f4252005-04-13 14:45:30 +0200170{
171 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
172 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +0200173 return snd_hda_input_mux_info(spec->input_mux, uinfo);
Matt2f2f4252005-04-13 14:45:30 +0200174}
175
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100176static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200177{
178 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
179 struct sigmatel_spec *spec = codec->spec;
180 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
181
182 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
183 return 0;
184}
185
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100186static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200187{
188 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
189 struct sigmatel_spec *spec = codec->spec;
190 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
191
Mattc7d4b2f2005-06-27 14:59:41 +0200192 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
Matt2f2f4252005-04-13 14:45:30 +0200193 spec->mux_nids[adc_idx], &spec->cur_mux[adc_idx]);
194}
195
Mattc7d4b2f2005-06-27 14:59:41 +0200196static struct hda_verb stac9200_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200197 /* set dac0mux for dac converter */
Mattc7d4b2f2005-06-27 14:59:41 +0200198 { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
Matt2f2f4252005-04-13 14:45:30 +0200199 {}
200};
201
Mattc7d4b2f2005-06-27 14:59:41 +0200202static struct hda_verb stac922x_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200203 /* set master volume and direct control */
Mattc7d4b2f2005-06-27 14:59:41 +0200204 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matt2f2f4252005-04-13 14:45:30 +0200205 {}
206};
207
Takashi Iwai19039bd2006-06-28 15:52:16 +0200208static struct hda_verb stac9227_core_init[] = {
209 /* set master volume and direct control */
210 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
211 /* unmute node 0x1b */
212 { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
213 {}
214};
215
216static struct hda_verb d965_2112_core_init[] = {
217 /* set master volume and direct control */
218 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
219 /* unmute node 0x1b */
220 { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
221 /* select node 0x03 as DAC */
222 { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
223 {}
224};
225
Matt Porter3cc08dc2006-01-23 15:27:49 +0100226static struct hda_verb stac927x_core_init[] = {
227 /* set master volume and direct control */
228 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
229 {}
230};
231
Matt Porterf3302a52006-07-31 12:49:34 +0200232static struct hda_verb stac9205_core_init[] = {
233 /* set master volume and direct control */
234 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
235 {}
236};
237
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100238static struct snd_kcontrol_new stac9200_mixer[] = {
Matt2f2f4252005-04-13 14:45:30 +0200239 HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
240 HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
241 {
242 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
243 .name = "Input Source",
244 .count = 1,
245 .info = stac92xx_mux_enum_info,
246 .get = stac92xx_mux_enum_get,
247 .put = stac92xx_mux_enum_put,
248 },
249 HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
250 HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
Mattc7d4b2f2005-06-27 14:59:41 +0200251 HDA_CODEC_VOLUME("Capture Mux Volume", 0x0c, 0, HDA_OUTPUT),
Matt2f2f4252005-04-13 14:45:30 +0200252 { } /* end */
253};
254
Mattc7d4b2f2005-06-27 14:59:41 +0200255/* This needs to be generated dynamically based on sequence */
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100256static struct snd_kcontrol_new stac922x_mixer[] = {
Matt2f2f4252005-04-13 14:45:30 +0200257 {
258 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
259 .name = "Input Source",
260 .count = 1,
261 .info = stac92xx_mux_enum_info,
262 .get = stac92xx_mux_enum_get,
263 .put = stac92xx_mux_enum_put,
264 },
265 HDA_CODEC_VOLUME("Capture Volume", 0x17, 0x0, HDA_INPUT),
Takashi Iwai0fd17082006-01-13 18:46:21 +0100266 HDA_CODEC_MUTE("Capture Switch", 0x17, 0x0, HDA_INPUT),
Matt2f2f4252005-04-13 14:45:30 +0200267 HDA_CODEC_VOLUME("Mux Capture Volume", 0x12, 0x0, HDA_OUTPUT),
268 { } /* end */
269};
270
Takashi Iwai19039bd2006-06-28 15:52:16 +0200271/* This needs to be generated dynamically based on sequence */
272static struct snd_kcontrol_new stac9227_mixer[] = {
273 {
274 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
275 .name = "Input Source",
276 .count = 1,
277 .info = stac92xx_mux_enum_info,
278 .get = stac92xx_mux_enum_get,
279 .put = stac92xx_mux_enum_put,
280 },
281 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
282 HDA_CODEC_MUTE("Capture Switch", 0x1b, 0x0, HDA_OUTPUT),
283 { } /* end */
284};
285
Matt Porter3cc08dc2006-01-23 15:27:49 +0100286static snd_kcontrol_new_t stac927x_mixer[] = {
287 {
288 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
289 .name = "Input Source",
290 .count = 1,
291 .info = stac92xx_mux_enum_info,
292 .get = stac92xx_mux_enum_get,
293 .put = stac92xx_mux_enum_put,
294 },
295 HDA_CODEC_VOLUME("InMux Capture Volume", 0x15, 0x0, HDA_OUTPUT),
296 HDA_CODEC_VOLUME("InVol Capture Volume", 0x18, 0x0, HDA_INPUT),
297 HDA_CODEC_MUTE("ADCMux Capture Switch", 0x1b, 0x0, HDA_OUTPUT),
298 { } /* end */
299};
300
Matt Porterf3302a52006-07-31 12:49:34 +0200301static snd_kcontrol_new_t stac9205_mixer[] = {
302 {
303 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
304 .name = "Input Source",
305 .count = 1,
306 .info = stac92xx_mux_enum_info,
307 .get = stac92xx_mux_enum_get,
308 .put = stac92xx_mux_enum_put,
309 },
310 HDA_CODEC_VOLUME("InMux Capture Volume", 0x19, 0x0, HDA_OUTPUT),
311 HDA_CODEC_VOLUME("InVol Capture Volume", 0x1b, 0x0, HDA_INPUT),
312 HDA_CODEC_MUTE("ADCMux Capture Switch", 0x1d, 0x0, HDA_OUTPUT),
313 { } /* end */
314};
315
Matt2f2f4252005-04-13 14:45:30 +0200316static int stac92xx_build_controls(struct hda_codec *codec)
317{
318 struct sigmatel_spec *spec = codec->spec;
319 int err;
Mattc7d4b2f2005-06-27 14:59:41 +0200320 int i;
Matt2f2f4252005-04-13 14:45:30 +0200321
322 err = snd_hda_add_new_ctls(codec, spec->mixer);
323 if (err < 0)
324 return err;
Mattc7d4b2f2005-06-27 14:59:41 +0200325
326 for (i = 0; i < spec->num_mixers; i++) {
327 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
328 if (err < 0)
329 return err;
330 }
331
Mattdabbed62005-06-14 10:19:34 +0200332 if (spec->multiout.dig_out_nid) {
333 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
334 if (err < 0)
335 return err;
336 }
337 if (spec->dig_in_nid) {
338 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
339 if (err < 0)
340 return err;
341 }
342 return 0;
Matt2f2f4252005-04-13 14:45:30 +0200343}
344
Matt Porter403d1942005-11-29 15:00:51 +0100345static unsigned int ref9200_pin_configs[8] = {
Mattdabbed62005-06-14 10:19:34 +0200346 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
Matt2f2f4252005-04-13 14:45:30 +0200347 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
348};
349
Matt Porter403d1942005-11-29 15:00:51 +0100350static unsigned int *stac9200_brd_tbl[] = {
351 ref9200_pin_configs,
352};
353
354static struct hda_board_config stac9200_cfg_tbl[] = {
355 { .modelname = "ref",
356 .pci_subvendor = PCI_VENDOR_ID_INTEL,
357 .pci_subdevice = 0x2668, /* DFI LanParty */
358 .config = STAC_REF },
359 {} /* terminator */
360};
361
362static unsigned int ref922x_pin_configs[10] = {
363 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
364 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
Matt2f2f4252005-04-13 14:45:30 +0200365 0x40000100, 0x40000100,
366};
367
Matt Porter403d1942005-11-29 15:00:51 +0100368static unsigned int d945gtp3_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +0100369 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
Matt Porter403d1942005-11-29 15:00:51 +0100370 0x40000100, 0x40000100, 0x40000100, 0x40000100,
371 0x02a19120, 0x40000100,
372};
373
374static unsigned int d945gtp5_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +0100375 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
376 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
Matt Porter403d1942005-11-29 15:00:51 +0100377 0x02a19320, 0x40000100,
378};
379
Takashi Iwai19039bd2006-06-28 15:52:16 +0200380static unsigned int d965_2112_pin_configs[10] = {
381 0x0221401f, 0x40000100, 0x40000100, 0x01014011,
382 0x01a19021, 0x01813024, 0x01452130, 0x40000100,
383 0x02a19320, 0x40000100,
384};
385
386static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
387 [STAC_REF] = ref922x_pin_configs,
388 [STAC_D945GTP3] = d945gtp3_pin_configs,
389 [STAC_D945GTP5] = d945gtp5_pin_configs,
Linus Torvalds7c3dec02006-07-10 22:21:43 -0700390 [STAC_MACMINI] = d945gtp5_pin_configs,
Takashi Iwai19039bd2006-06-28 15:52:16 +0200391 [STAC_D965_2112] = d965_2112_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +0100392};
393
394static struct hda_board_config stac922x_cfg_tbl[] = {
395 { .modelname = "ref",
396 .pci_subvendor = PCI_VENDOR_ID_INTEL,
397 .pci_subdevice = 0x2668, /* DFI LanParty */
398 .config = STAC_REF }, /* SigmaTel reference board */
Tobin Davis948a4db2006-08-22 19:43:46 +0200399 /* Intel 945G based systems */
Matt Porter403d1942005-11-29 15:00:51 +0100400 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
401 .pci_subdevice = 0x0101,
402 .config = STAC_D945GTP3 }, /* Intel D945GTP - 3 Stack */
403 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
Takashi Iwai353b9e62006-02-16 18:16:17 +0100404 .pci_subdevice = 0x0202,
Tobin Davis948a4db2006-08-22 19:43:46 +0200405 .config = STAC_D945GTP3 }, /* Intel D945GNT - 3 Stack */
Takashi Iwai353b9e62006-02-16 18:16:17 +0100406 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
Tobin Davis948a4db2006-08-22 19:43:46 +0200407 .pci_subdevice = 0x0606,
408 .config = STAC_D945GTP3 }, /* Intel D945GTP - 3 Stack */
Takashi Iwai353b9e62006-02-16 18:16:17 +0100409 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
Tobin Davis948a4db2006-08-22 19:43:46 +0200410 .pci_subdevice = 0x0601,
411 .config = STAC_D945GTP3 }, /* Intel D945GTP - 3 Stack */
412 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
413 .pci_subdevice = 0x0111,
414 .config = STAC_D945GTP3 }, /* Intel D945GZP - 3 Stack */
415 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
416 .pci_subdevice = 0x1115,
417 .config = STAC_D945GTP3 }, /* Intel D945GPM - 3 Stack */
418 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
419 .pci_subdevice = 0x1116,
420 .config = STAC_D945GTP3 }, /* Intel D945GBO - 3 Stack */
421 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
422 .pci_subdevice = 0x1117,
423 .config = STAC_D945GTP3 }, /* Intel D945GPM - 3 Stack */
424 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
425 .pci_subdevice = 0x1118,
426 .config = STAC_D945GTP3 }, /* Intel D945GPM - 3 Stack */
427 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
428 .pci_subdevice = 0x1119,
429 .config = STAC_D945GTP3 }, /* Intel D945GPM - 3 Stack */
430 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
431 .pci_subdevice = 0x8826,
432 .config = STAC_D945GTP3 }, /* Intel D945GPM - 3 Stack */
433 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
434 .pci_subdevice = 0x5049,
435 .config = STAC_D945GTP3 }, /* Intel D945GCZ - 3 Stack */
436 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
437 .pci_subdevice = 0x5055,
438 .config = STAC_D945GTP3 }, /* Intel D945GCZ - 3 Stack */
439 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
440 .pci_subdevice = 0x5048,
441 .config = STAC_D945GTP3 }, /* Intel D945GPB - 3 Stack */
442 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
443 .pci_subdevice = 0x0110,
444 .config = STAC_D945GTP3 }, /* Intel D945GLR - 3 Stack */
445 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
Matt Porter403d1942005-11-29 15:00:51 +0100446 .pci_subdevice = 0x0404,
447 .config = STAC_D945GTP5 }, /* Intel D945GTP - 5 Stack */
448 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
449 .pci_subdevice = 0x0303,
450 .config = STAC_D945GTP5 }, /* Intel D945GNT - 5 Stack */
451 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
452 .pci_subdevice = 0x0013,
453 .config = STAC_D945GTP5 }, /* Intel D955XBK - 5 Stack */
Matt Porterd62c40e2006-01-23 15:26:27 +0100454 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
455 .pci_subdevice = 0x0417,
456 .config = STAC_D945GTP5 }, /* Intel D975XBK - 5 Stack */
Tobin Davis948a4db2006-08-22 19:43:46 +0200457 /* Intel 945P based systems */
458 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
459 .pci_subdevice = 0x0b0b,
460 .config = STAC_D945GTP3 }, /* Intel D945PSN - 3 Stack */
461 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
462 .pci_subdevice = 0x0112,
463 .config = STAC_D945GTP3 }, /* Intel D945PLN - 3 Stack */
464 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
465 .pci_subdevice = 0x0d0d,
466 .config = STAC_D945GTP3 }, /* Intel D945PLM - 3 Stack */
467 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
468 .pci_subdevice = 0x0909,
469 .config = STAC_D945GTP3 }, /* Intel D945PAW - 3 Stack */
470 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
471 .pci_subdevice = 0x0505,
472 .config = STAC_D945GTP3 }, /* Intel D945PLM - 3 Stack */
473 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
474 .pci_subdevice = 0x0707,
475 .config = STAC_D945GTP5 }, /* Intel D945PSV - 5 Stack */
476 /* other systems */
Sam Revitch62fe78e2006-05-10 15:09:17 +0200477 { .pci_subvendor = 0x8384,
478 .pci_subdevice = 0x7680,
479 .config = STAC_MACMINI }, /* Apple Mac Mini (early 2006) */
Takashi Iwai19039bd2006-06-28 15:52:16 +0200480 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
481 .pci_subdevice = 0x2112,
482 .config = STAC_D965_2112 },
483 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
484 .pci_subdevice = 0x284b,
485 .config = STAC_D965_284B },
Matt Porter403d1942005-11-29 15:00:51 +0100486 {} /* terminator */
487};
488
Matt Porter3cc08dc2006-01-23 15:27:49 +0100489static unsigned int ref927x_pin_configs[14] = {
490 0x01813122, 0x01a19021, 0x01014010, 0x01016011,
491 0x01012012, 0x01011014, 0x40000100, 0x40000100,
492 0x40000100, 0x40000100, 0x40000100, 0x01441030,
493 0x01c41030, 0x40000100,
494};
495
496static unsigned int *stac927x_brd_tbl[] = {
497 ref927x_pin_configs,
498};
499
500static struct hda_board_config stac927x_cfg_tbl[] = {
501 { .modelname = "ref",
502 .pci_subvendor = PCI_VENDOR_ID_INTEL,
503 .pci_subdevice = 0x2668, /* DFI LanParty */
504 .config = STAC_REF }, /* SigmaTel reference board */
505 {} /* terminator */
506};
507
Matt Porterf3302a52006-07-31 12:49:34 +0200508static unsigned int ref9205_pin_configs[12] = {
509 0x40000100, 0x40000100, 0x01016011, 0x01014010,
510 0x01813122, 0x01a19021, 0x40000100, 0x40000100,
511 0x40000100, 0x40000100, 0x01441030, 0x01c41030
512};
513
514static unsigned int *stac9205_brd_tbl[] = {
515 ref9205_pin_configs,
516};
517
518static struct hda_board_config stac9205_cfg_tbl[] = {
519 { .modelname = "ref",
520 .pci_subvendor = PCI_VENDOR_ID_INTEL,
521 .pci_subdevice = 0x2668, /* DFI LanParty */
522 .config = STAC_REF }, /* SigmaTel reference board */
523 {} /* terminator */
524};
525
Matt2f2f4252005-04-13 14:45:30 +0200526static void stac92xx_set_config_regs(struct hda_codec *codec)
527{
528 int i;
529 struct sigmatel_spec *spec = codec->spec;
530 unsigned int pin_cfg;
531
532 for (i=0; i < spec->num_pins; i++) {
533 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
534 AC_VERB_SET_CONFIG_DEFAULT_BYTES_0,
535 spec->pin_configs[i] & 0x000000ff);
536 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
537 AC_VERB_SET_CONFIG_DEFAULT_BYTES_1,
538 (spec->pin_configs[i] & 0x0000ff00) >> 8);
539 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
540 AC_VERB_SET_CONFIG_DEFAULT_BYTES_2,
541 (spec->pin_configs[i] & 0x00ff0000) >> 16);
542 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
543 AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
544 spec->pin_configs[i] >> 24);
545 pin_cfg = snd_hda_codec_read(codec, spec->pin_nids[i], 0,
546 AC_VERB_GET_CONFIG_DEFAULT,
547 0x00);
Matt Porter403d1942005-11-29 15:00:51 +0100548 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 +0200549 }
550}
Matt2f2f4252005-04-13 14:45:30 +0200551
Matt2f2f4252005-04-13 14:45:30 +0200552/*
553 * Analog playback callbacks
554 */
555static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
556 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100557 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200558{
559 struct sigmatel_spec *spec = codec->spec;
560 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
561}
562
563static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
564 struct hda_codec *codec,
565 unsigned int stream_tag,
566 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100567 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200568{
569 struct sigmatel_spec *spec = codec->spec;
Matt Porter403d1942005-11-29 15:00:51 +0100570 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
Matt2f2f4252005-04-13 14:45:30 +0200571}
572
573static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
574 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100575 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200576{
577 struct sigmatel_spec *spec = codec->spec;
578 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
579}
580
581/*
Mattdabbed62005-06-14 10:19:34 +0200582 * Digital playback callbacks
583 */
584static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
585 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100586 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +0200587{
588 struct sigmatel_spec *spec = codec->spec;
589 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
590}
591
592static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
593 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100594 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +0200595{
596 struct sigmatel_spec *spec = codec->spec;
597 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
598}
599
600
601/*
Matt2f2f4252005-04-13 14:45:30 +0200602 * Analog capture callbacks
603 */
604static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
605 struct hda_codec *codec,
606 unsigned int stream_tag,
607 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100608 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200609{
610 struct sigmatel_spec *spec = codec->spec;
611
612 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
613 stream_tag, 0, format);
614 return 0;
615}
616
617static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
618 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100619 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200620{
621 struct sigmatel_spec *spec = codec->spec;
622
623 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 0, 0, 0);
624 return 0;
625}
626
Mattdabbed62005-06-14 10:19:34 +0200627static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
628 .substreams = 1,
629 .channels_min = 2,
630 .channels_max = 2,
631 /* NID is set in stac92xx_build_pcms */
632 .ops = {
633 .open = stac92xx_dig_playback_pcm_open,
634 .close = stac92xx_dig_playback_pcm_close
635 },
636};
637
638static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
639 .substreams = 1,
640 .channels_min = 2,
641 .channels_max = 2,
642 /* NID is set in stac92xx_build_pcms */
643};
644
Matt2f2f4252005-04-13 14:45:30 +0200645static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
646 .substreams = 1,
647 .channels_min = 2,
Mattc7d4b2f2005-06-27 14:59:41 +0200648 .channels_max = 8,
Matt2f2f4252005-04-13 14:45:30 +0200649 .nid = 0x02, /* NID to query formats and rates */
650 .ops = {
651 .open = stac92xx_playback_pcm_open,
652 .prepare = stac92xx_playback_pcm_prepare,
653 .cleanup = stac92xx_playback_pcm_cleanup
654 },
655};
656
Matt Porter3cc08dc2006-01-23 15:27:49 +0100657static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
658 .substreams = 1,
659 .channels_min = 2,
660 .channels_max = 2,
661 .nid = 0x06, /* NID to query formats and rates */
662 .ops = {
663 .open = stac92xx_playback_pcm_open,
664 .prepare = stac92xx_playback_pcm_prepare,
665 .cleanup = stac92xx_playback_pcm_cleanup
666 },
667};
668
Matt2f2f4252005-04-13 14:45:30 +0200669static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
670 .substreams = 2,
671 .channels_min = 2,
672 .channels_max = 2,
Matt Porter3cc08dc2006-01-23 15:27:49 +0100673 /* NID is set in stac92xx_build_pcms */
Matt2f2f4252005-04-13 14:45:30 +0200674 .ops = {
675 .prepare = stac92xx_capture_pcm_prepare,
676 .cleanup = stac92xx_capture_pcm_cleanup
677 },
678};
679
680static int stac92xx_build_pcms(struct hda_codec *codec)
681{
682 struct sigmatel_spec *spec = codec->spec;
683 struct hda_pcm *info = spec->pcm_rec;
684
685 codec->num_pcms = 1;
686 codec->pcm_info = info;
687
Mattc7d4b2f2005-06-27 14:59:41 +0200688 info->name = "STAC92xx Analog";
Matt2f2f4252005-04-13 14:45:30 +0200689 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
Matt2f2f4252005-04-13 14:45:30 +0200690 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100691 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
692
693 if (spec->alt_switch) {
694 codec->num_pcms++;
695 info++;
696 info->name = "STAC92xx Analog Alt";
697 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
698 }
Matt2f2f4252005-04-13 14:45:30 +0200699
Mattdabbed62005-06-14 10:19:34 +0200700 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
701 codec->num_pcms++;
702 info++;
703 info->name = "STAC92xx Digital";
704 if (spec->multiout.dig_out_nid) {
705 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
706 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
707 }
708 if (spec->dig_in_nid) {
709 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
710 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
711 }
712 }
713
Matt2f2f4252005-04-13 14:45:30 +0200714 return 0;
715}
716
Takashi Iwaic960a032006-03-23 17:06:28 +0100717static unsigned int stac92xx_get_vref(struct hda_codec *codec, hda_nid_t nid)
718{
719 unsigned int pincap = snd_hda_param_read(codec, nid,
720 AC_PAR_PIN_CAP);
721 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
722 if (pincap & AC_PINCAP_VREF_100)
723 return AC_PINCTL_VREF_100;
724 if (pincap & AC_PINCAP_VREF_80)
725 return AC_PINCTL_VREF_80;
726 if (pincap & AC_PINCAP_VREF_50)
727 return AC_PINCTL_VREF_50;
728 if (pincap & AC_PINCAP_VREF_GRD)
729 return AC_PINCTL_VREF_GRD;
730 return 0;
731}
732
Matt Porter403d1942005-11-29 15:00:51 +0100733static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
734
735{
736 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
737}
738
739static int stac92xx_io_switch_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
740{
741 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
742 uinfo->count = 1;
743 uinfo->value.integer.min = 0;
744 uinfo->value.integer.max = 1;
745 return 0;
746}
747
748static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
749{
750 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
751 struct sigmatel_spec *spec = codec->spec;
752 int io_idx = kcontrol-> private_value & 0xff;
753
754 ucontrol->value.integer.value[0] = spec->io_switch[io_idx];
755 return 0;
756}
757
758static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
759{
760 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
761 struct sigmatel_spec *spec = codec->spec;
762 hda_nid_t nid = kcontrol->private_value >> 8;
763 int io_idx = kcontrol-> private_value & 0xff;
764 unsigned short val = ucontrol->value.integer.value[0];
765
766 spec->io_switch[io_idx] = val;
767
768 if (val)
769 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
Takashi Iwaic960a032006-03-23 17:06:28 +0100770 else {
771 unsigned int pinctl = AC_PINCTL_IN_EN;
772 if (io_idx) /* set VREF for mic */
773 pinctl |= stac92xx_get_vref(codec, nid);
774 stac92xx_auto_set_pinctl(codec, nid, pinctl);
775 }
Matt Porter403d1942005-11-29 15:00:51 +0100776 return 1;
777}
778
779#define STAC_CODEC_IO_SWITCH(xname, xpval) \
780 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
781 .name = xname, \
782 .index = 0, \
783 .info = stac92xx_io_switch_info, \
784 .get = stac92xx_io_switch_get, \
785 .put = stac92xx_io_switch_put, \
786 .private_value = xpval, \
787 }
788
789
Mattc7d4b2f2005-06-27 14:59:41 +0200790enum {
791 STAC_CTL_WIDGET_VOL,
792 STAC_CTL_WIDGET_MUTE,
Matt Porter403d1942005-11-29 15:00:51 +0100793 STAC_CTL_WIDGET_IO_SWITCH,
Mattc7d4b2f2005-06-27 14:59:41 +0200794};
795
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100796static struct snd_kcontrol_new stac92xx_control_templates[] = {
Mattc7d4b2f2005-06-27 14:59:41 +0200797 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
798 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Matt Porter403d1942005-11-29 15:00:51 +0100799 STAC_CODEC_IO_SWITCH(NULL, 0),
Mattc7d4b2f2005-06-27 14:59:41 +0200800};
801
802/* add dynamic controls */
803static int stac92xx_add_control(struct sigmatel_spec *spec, int type, const char *name, unsigned long val)
804{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100805 struct snd_kcontrol_new *knew;
Mattc7d4b2f2005-06-27 14:59:41 +0200806
807 if (spec->num_kctl_used >= spec->num_kctl_alloc) {
808 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
809
810 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */
811 if (! knew)
812 return -ENOMEM;
813 if (spec->kctl_alloc) {
814 memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
815 kfree(spec->kctl_alloc);
816 }
817 spec->kctl_alloc = knew;
818 spec->num_kctl_alloc = num;
819 }
820
821 knew = &spec->kctl_alloc[spec->num_kctl_used];
822 *knew = stac92xx_control_templates[type];
Takashi Iwai82fe0c52005-06-30 10:54:33 +0200823 knew->name = kstrdup(name, GFP_KERNEL);
Mattc7d4b2f2005-06-27 14:59:41 +0200824 if (! knew->name)
825 return -ENOMEM;
826 knew->private_value = val;
827 spec->num_kctl_used++;
828 return 0;
829}
830
Matt Porter403d1942005-11-29 15:00:51 +0100831/* flag inputs as additional dynamic lineouts */
832static int stac92xx_add_dyn_out_pins(struct hda_codec *codec, struct auto_pin_cfg *cfg)
833{
834 struct sigmatel_spec *spec = codec->spec;
835
836 switch (cfg->line_outs) {
837 case 3:
838 /* add line-in as side */
839 if (cfg->input_pins[AUTO_PIN_LINE]) {
840 cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_LINE];
841 spec->line_switch = 1;
842 cfg->line_outs++;
843 }
844 break;
845 case 2:
846 /* add line-in as clfe and mic as side */
847 if (cfg->input_pins[AUTO_PIN_LINE]) {
848 cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_LINE];
849 spec->line_switch = 1;
850 cfg->line_outs++;
851 }
852 if (cfg->input_pins[AUTO_PIN_MIC]) {
853 cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_MIC];
854 spec->mic_switch = 1;
855 cfg->line_outs++;
856 }
857 break;
858 case 1:
859 /* add line-in as surr and mic as clfe */
860 if (cfg->input_pins[AUTO_PIN_LINE]) {
861 cfg->line_out_pins[1] = cfg->input_pins[AUTO_PIN_LINE];
862 spec->line_switch = 1;
863 cfg->line_outs++;
864 }
865 if (cfg->input_pins[AUTO_PIN_MIC]) {
866 cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_MIC];
867 spec->mic_switch = 1;
868 cfg->line_outs++;
869 }
870 break;
871 }
872
873 return 0;
874}
875
Matt Porter3cc08dc2006-01-23 15:27:49 +0100876/*
877 * XXX The line_out pin widget connection list may not be set to the
878 * desired DAC nid. This is the case on 927x where ports A and B can
879 * be routed to several DACs.
880 *
881 * This requires an analysis of the line-out/hp pin configuration
882 * to provide a best fit for pin/DAC configurations that are routable.
883 * For now, 927x DAC4 is not supported and 927x DAC1 output to ports
884 * A and B is not supported.
885 */
Mattc7d4b2f2005-06-27 14:59:41 +0200886/* fill in the dac_nids table from the parsed pin configuration */
Takashi Iwai19039bd2006-06-28 15:52:16 +0200887static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec,
888 const struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +0200889{
890 struct sigmatel_spec *spec = codec->spec;
891 hda_nid_t nid;
892 int i;
893
894 /* check the pins hardwired to audio widget */
895 for (i = 0; i < cfg->line_outs; i++) {
896 nid = cfg->line_out_pins[i];
897 spec->multiout.dac_nids[i] = snd_hda_codec_read(codec, nid, 0,
898 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
899 }
900
Takashi Iwai82bc9552006-03-21 11:24:42 +0100901 spec->multiout.num_dacs = cfg->line_outs;
Mattc7d4b2f2005-06-27 14:59:41 +0200902
903 return 0;
904}
905
906/* add playback controls from the parsed DAC table */
Takashi Iwai19039bd2006-06-28 15:52:16 +0200907static int stac92xx_auto_create_multi_out_ctls(struct sigmatel_spec *spec,
908 const struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +0200909{
910 char name[32];
Takashi Iwai19039bd2006-06-28 15:52:16 +0200911 static const char *chname[4] = {
912 "Front", "Surround", NULL /*CLFE*/, "Side"
913 };
Mattc7d4b2f2005-06-27 14:59:41 +0200914 hda_nid_t nid;
915 int i, err;
916
917 for (i = 0; i < cfg->line_outs; i++) {
Matt Porter403d1942005-11-29 15:00:51 +0100918 if (!spec->multiout.dac_nids[i])
Mattc7d4b2f2005-06-27 14:59:41 +0200919 continue;
920
921 nid = spec->multiout.dac_nids[i];
922
923 if (i == 2) {
924 /* Center/LFE */
925 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, "Center Playback Volume",
926 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT))) < 0)
927 return err;
928 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, "LFE Playback Volume",
929 HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT))) < 0)
930 return err;
931 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, "Center Playback Switch",
932 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT))) < 0)
933 return err;
934 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, "LFE Playback Switch",
935 HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT))) < 0)
936 return err;
937 } else {
938 sprintf(name, "%s Playback Volume", chname[i]);
939 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, name,
940 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
941 return err;
942 sprintf(name, "%s Playback Switch", chname[i]);
943 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, name,
944 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
945 return err;
946 }
947 }
948
Matt Porter403d1942005-11-29 15:00:51 +0100949 if (spec->line_switch)
950 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Line In as Output Switch", cfg->input_pins[AUTO_PIN_LINE] << 8)) < 0)
951 return err;
952
953 if (spec->mic_switch)
954 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Mic as Output Switch", (cfg->input_pins[AUTO_PIN_MIC] << 8) | 1)) < 0)
955 return err;
956
Mattc7d4b2f2005-06-27 14:59:41 +0200957 return 0;
958}
959
960/* add playback controls for HP output */
961static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec, struct auto_pin_cfg *cfg)
962{
963 struct sigmatel_spec *spec = codec->spec;
964 hda_nid_t pin = cfg->hp_pin;
965 hda_nid_t nid;
966 int i, err;
Matt4e550962005-07-04 17:51:39 +0200967 unsigned int wid_caps;
Mattc7d4b2f2005-06-27 14:59:41 +0200968
969 if (! pin)
970 return 0;
971
Takashi Iwai54d17402005-11-21 16:33:22 +0100972 wid_caps = get_wcaps(codec, pin);
Takashi Iwai505cb342006-03-27 12:51:52 +0200973 if (wid_caps & AC_WCAP_UNSOL_CAP)
Takashi Iwai82bc9552006-03-21 11:24:42 +0100974 spec->hp_detect = 1;
Matt4e550962005-07-04 17:51:39 +0200975
Mattc7d4b2f2005-06-27 14:59:41 +0200976 nid = snd_hda_codec_read(codec, pin, 0, AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
977 for (i = 0; i < cfg->line_outs; i++) {
978 if (! spec->multiout.dac_nids[i])
979 continue;
980 if (spec->multiout.dac_nids[i] == nid)
981 return 0;
982 }
983
984 spec->multiout.hp_nid = nid;
985
986 /* control HP volume/switch on the output mixer amp */
987 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, "Headphone Playback Volume",
988 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
989 return err;
990 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, "Headphone Playback Switch",
991 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
992 return err;
993
994 return 0;
995}
996
997/* create playback/capture controls for input pins */
998static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
999{
1000 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02001001 struct hda_input_mux *imux = &spec->private_imux;
1002 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
1003 int i, j, k;
1004
1005 for (i = 0; i < AUTO_PIN_LAST; i++) {
1006 int index = -1;
1007 if (cfg->input_pins[i]) {
Takashi Iwai4a471b72005-12-07 13:56:29 +01001008 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
Mattc7d4b2f2005-06-27 14:59:41 +02001009
1010 for (j=0; j<spec->num_muxes; j++) {
1011 int num_cons = snd_hda_get_connections(codec, spec->mux_nids[j], con_lst, HDA_MAX_NUM_INPUTS);
1012 for (k=0; k<num_cons; k++)
1013 if (con_lst[k] == cfg->input_pins[i]) {
1014 index = k;
1015 break;
1016 }
1017 if (index >= 0)
1018 break;
1019 }
1020 imux->items[imux->num_items].index = index;
1021 imux->num_items++;
1022 }
1023 }
1024
Sam Revitch62fe78e2006-05-10 15:09:17 +02001025 if (imux->num_items == 1) {
1026 /*
1027 * Set the current input for the muxes.
1028 * The STAC9221 has two input muxes with identical source
1029 * NID lists. Hopefully this won't get confused.
1030 */
1031 for (i = 0; i < spec->num_muxes; i++) {
1032 snd_hda_codec_write(codec, spec->mux_nids[i], 0,
1033 AC_VERB_SET_CONNECT_SEL,
1034 imux->items[0].index);
1035 }
1036 }
1037
Mattc7d4b2f2005-06-27 14:59:41 +02001038 return 0;
1039}
1040
Mattc7d4b2f2005-06-27 14:59:41 +02001041static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
1042{
1043 struct sigmatel_spec *spec = codec->spec;
1044 int i;
1045
1046 for (i = 0; i < spec->autocfg.line_outs; i++) {
1047 hda_nid_t nid = spec->autocfg.line_out_pins[i];
1048 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
1049 }
1050}
1051
1052static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
1053{
1054 struct sigmatel_spec *spec = codec->spec;
1055 hda_nid_t pin;
1056
1057 pin = spec->autocfg.hp_pin;
1058 if (pin) /* connect to front */
1059 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
1060}
1061
Matt Porter3cc08dc2006-01-23 15:27:49 +01001062static 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 +02001063{
1064 struct sigmatel_spec *spec = codec->spec;
1065 int err;
1066
Kailang Yangdf694da2005-12-05 19:42:22 +01001067 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001068 return err;
Takashi Iwai82bc9552006-03-21 11:24:42 +01001069 if (! spec->autocfg.line_outs)
Matt Porter869264c2006-01-25 19:20:50 +01001070 return 0; /* can't find valid pin config */
Takashi Iwai19039bd2006-06-28 15:52:16 +02001071
Matt Porter403d1942005-11-29 15:00:51 +01001072 if ((err = stac92xx_add_dyn_out_pins(codec, &spec->autocfg)) < 0)
1073 return err;
Takashi Iwai19039bd2006-06-28 15:52:16 +02001074 if (spec->multiout.num_dacs == 0)
1075 if ((err = stac92xx_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
1076 return err;
Mattc7d4b2f2005-06-27 14:59:41 +02001077
1078 if ((err = stac92xx_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
1079 (err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg)) < 0 ||
1080 (err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
1081 return err;
1082
1083 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Matt Porter403d1942005-11-29 15:00:51 +01001084 if (spec->multiout.max_channels > 2)
Mattc7d4b2f2005-06-27 14:59:41 +02001085 spec->surr_switch = 1;
Mattc7d4b2f2005-06-27 14:59:41 +02001086
Takashi Iwai82bc9552006-03-21 11:24:42 +01001087 if (spec->autocfg.dig_out_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01001088 spec->multiout.dig_out_nid = dig_out;
Takashi Iwai82bc9552006-03-21 11:24:42 +01001089 if (spec->autocfg.dig_in_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01001090 spec->dig_in_nid = dig_in;
Mattc7d4b2f2005-06-27 14:59:41 +02001091
1092 if (spec->kctl_alloc)
1093 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
1094
1095 spec->input_mux = &spec->private_imux;
1096
1097 return 1;
1098}
1099
Takashi Iwai82bc9552006-03-21 11:24:42 +01001100/* add playback controls for HP output */
1101static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
1102 struct auto_pin_cfg *cfg)
1103{
1104 struct sigmatel_spec *spec = codec->spec;
1105 hda_nid_t pin = cfg->hp_pin;
1106 unsigned int wid_caps;
1107
1108 if (! pin)
1109 return 0;
1110
1111 wid_caps = get_wcaps(codec, pin);
Takashi Iwai505cb342006-03-27 12:51:52 +02001112 if (wid_caps & AC_WCAP_UNSOL_CAP)
Takashi Iwai82bc9552006-03-21 11:24:42 +01001113 spec->hp_detect = 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +01001114
1115 return 0;
1116}
1117
Mattc7d4b2f2005-06-27 14:59:41 +02001118static int stac9200_parse_auto_config(struct hda_codec *codec)
1119{
1120 struct sigmatel_spec *spec = codec->spec;
1121 int err;
1122
Kailang Yangdf694da2005-12-05 19:42:22 +01001123 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001124 return err;
1125
1126 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
1127 return err;
1128
Takashi Iwai82bc9552006-03-21 11:24:42 +01001129 if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
1130 return err;
1131
1132 if (spec->autocfg.dig_out_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02001133 spec->multiout.dig_out_nid = 0x05;
Takashi Iwai82bc9552006-03-21 11:24:42 +01001134 if (spec->autocfg.dig_in_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02001135 spec->dig_in_nid = 0x04;
Mattc7d4b2f2005-06-27 14:59:41 +02001136
1137 if (spec->kctl_alloc)
1138 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
1139
1140 spec->input_mux = &spec->private_imux;
1141
1142 return 1;
1143}
1144
Sam Revitch62fe78e2006-05-10 15:09:17 +02001145/*
1146 * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
1147 * funky external mute control using GPIO pins.
1148 */
1149
1150static void stac922x_gpio_mute(struct hda_codec *codec, int pin, int muted)
1151{
1152 unsigned int gpiostate, gpiomask, gpiodir;
1153
1154 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
1155 AC_VERB_GET_GPIO_DATA, 0);
1156
1157 if (!muted)
1158 gpiostate |= (1 << pin);
1159 else
1160 gpiostate &= ~(1 << pin);
1161
1162 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
1163 AC_VERB_GET_GPIO_MASK, 0);
1164 gpiomask |= (1 << pin);
1165
1166 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
1167 AC_VERB_GET_GPIO_DIRECTION, 0);
1168 gpiodir |= (1 << pin);
1169
1170 /* AppleHDA seems to do this -- WTF is this verb?? */
1171 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
1172
1173 snd_hda_codec_write(codec, codec->afg, 0,
1174 AC_VERB_SET_GPIO_MASK, gpiomask);
1175 snd_hda_codec_write(codec, codec->afg, 0,
1176 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
1177
1178 msleep(1);
1179
1180 snd_hda_codec_write(codec, codec->afg, 0,
1181 AC_VERB_SET_GPIO_DATA, gpiostate);
1182}
1183
Mattc7d4b2f2005-06-27 14:59:41 +02001184static int stac92xx_init(struct hda_codec *codec)
1185{
1186 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai82bc9552006-03-21 11:24:42 +01001187 struct auto_pin_cfg *cfg = &spec->autocfg;
1188 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02001189
Mattc7d4b2f2005-06-27 14:59:41 +02001190 snd_hda_sequence_write(codec, spec->init);
1191
Takashi Iwai82bc9552006-03-21 11:24:42 +01001192 /* set up pins */
1193 if (spec->hp_detect) {
Takashi Iwai505cb342006-03-27 12:51:52 +02001194 /* Enable unsolicited responses on the HP widget */
1195 snd_hda_codec_write(codec, cfg->hp_pin, 0,
1196 AC_VERB_SET_UNSOLICITED_ENABLE,
1197 STAC_UNSOL_ENABLE);
Takashi Iwai82bc9552006-03-21 11:24:42 +01001198 /* fake event to set up pins */
1199 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
Tobin Davis68a6abd2006-08-21 19:02:10 +02001200 /* enable the headphones by default. If/when unsol_event detection works, this will be ignored */
1201 stac92xx_auto_init_hp_out(codec);
Takashi Iwai82bc9552006-03-21 11:24:42 +01001202 } else {
1203 stac92xx_auto_init_multi_out(codec);
1204 stac92xx_auto_init_hp_out(codec);
1205 }
1206 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwaic960a032006-03-23 17:06:28 +01001207 hda_nid_t nid = cfg->input_pins[i];
1208 if (nid) {
1209 unsigned int pinctl = AC_PINCTL_IN_EN;
1210 if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC)
1211 pinctl |= stac92xx_get_vref(codec, nid);
1212 stac92xx_auto_set_pinctl(codec, nid, pinctl);
1213 }
Takashi Iwai82bc9552006-03-21 11:24:42 +01001214 }
1215 if (cfg->dig_out_pin)
1216 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pin,
1217 AC_PINCTL_OUT_EN);
1218 if (cfg->dig_in_pin)
1219 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
1220 AC_PINCTL_IN_EN);
1221
Sam Revitch62fe78e2006-05-10 15:09:17 +02001222 if (spec->gpio_mute) {
1223 stac922x_gpio_mute(codec, 0, 0);
1224 stac922x_gpio_mute(codec, 1, 0);
1225 }
1226
Mattc7d4b2f2005-06-27 14:59:41 +02001227 return 0;
1228}
1229
Matt2f2f4252005-04-13 14:45:30 +02001230static void stac92xx_free(struct hda_codec *codec)
1231{
Mattc7d4b2f2005-06-27 14:59:41 +02001232 struct sigmatel_spec *spec = codec->spec;
1233 int i;
1234
1235 if (! spec)
1236 return;
1237
1238 if (spec->kctl_alloc) {
1239 for (i = 0; i < spec->num_kctl_used; i++)
1240 kfree(spec->kctl_alloc[i].name);
1241 kfree(spec->kctl_alloc);
1242 }
1243
1244 kfree(spec);
Matt2f2f4252005-04-13 14:45:30 +02001245}
1246
Matt4e550962005-07-04 17:51:39 +02001247static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
1248 unsigned int flag)
1249{
1250 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
1251 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
1252 snd_hda_codec_write(codec, nid, 0,
1253 AC_VERB_SET_PIN_WIDGET_CONTROL,
1254 pin_ctl | flag);
1255}
1256
1257static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
1258 unsigned int flag)
1259{
1260 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
1261 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
1262 snd_hda_codec_write(codec, nid, 0,
1263 AC_VERB_SET_PIN_WIDGET_CONTROL,
1264 pin_ctl & ~flag);
1265}
1266
1267static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
1268{
1269 struct sigmatel_spec *spec = codec->spec;
1270 struct auto_pin_cfg *cfg = &spec->autocfg;
1271 int i, presence;
1272
1273 if ((res >> 26) != STAC_HP_EVENT)
1274 return;
1275
1276 presence = snd_hda_codec_read(codec, cfg->hp_pin, 0,
1277 AC_VERB_GET_PIN_SENSE, 0x00) >> 31;
1278
1279 if (presence) {
1280 /* disable lineouts, enable hp */
1281 for (i = 0; i < cfg->line_outs; i++)
1282 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
1283 AC_PINCTL_OUT_EN);
1284 stac92xx_set_pinctl(codec, cfg->hp_pin, AC_PINCTL_OUT_EN);
1285 } else {
1286 /* enable lineouts, disable hp */
1287 for (i = 0; i < cfg->line_outs; i++)
1288 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
1289 AC_PINCTL_OUT_EN);
1290 stac92xx_reset_pinctl(codec, cfg->hp_pin, AC_PINCTL_OUT_EN);
1291 }
1292}
1293
Mattff6fdc32005-06-27 15:06:52 +02001294#ifdef CONFIG_PM
1295static int stac92xx_resume(struct hda_codec *codec)
1296{
1297 struct sigmatel_spec *spec = codec->spec;
1298 int i;
1299
1300 stac92xx_init(codec);
1301 for (i = 0; i < spec->num_mixers; i++)
1302 snd_hda_resume_ctls(codec, spec->mixers[i]);
1303 if (spec->multiout.dig_out_nid)
1304 snd_hda_resume_spdif_out(codec);
1305 if (spec->dig_in_nid)
1306 snd_hda_resume_spdif_in(codec);
1307
1308 return 0;
1309}
1310#endif
1311
Matt2f2f4252005-04-13 14:45:30 +02001312static struct hda_codec_ops stac92xx_patch_ops = {
1313 .build_controls = stac92xx_build_controls,
1314 .build_pcms = stac92xx_build_pcms,
1315 .init = stac92xx_init,
1316 .free = stac92xx_free,
Matt4e550962005-07-04 17:51:39 +02001317 .unsol_event = stac92xx_unsol_event,
Mattff6fdc32005-06-27 15:06:52 +02001318#ifdef CONFIG_PM
1319 .resume = stac92xx_resume,
1320#endif
Matt2f2f4252005-04-13 14:45:30 +02001321};
1322
1323static int patch_stac9200(struct hda_codec *codec)
1324{
1325 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02001326 int err;
Matt2f2f4252005-04-13 14:45:30 +02001327
Takashi Iwaie560d8d2005-09-09 14:21:46 +02001328 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02001329 if (spec == NULL)
1330 return -ENOMEM;
1331
1332 codec->spec = spec;
Matt Porter403d1942005-11-29 15:00:51 +01001333 spec->board_config = snd_hda_check_board_config(codec, stac9200_cfg_tbl);
1334 if (spec->board_config < 0)
1335 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9200, using BIOS defaults\n");
1336 else {
1337 spec->num_pins = 8;
1338 spec->pin_nids = stac9200_pin_nids;
1339 spec->pin_configs = stac9200_brd_tbl[spec->board_config];
1340 stac92xx_set_config_regs(codec);
1341 }
Matt2f2f4252005-04-13 14:45:30 +02001342
1343 spec->multiout.max_channels = 2;
1344 spec->multiout.num_dacs = 1;
1345 spec->multiout.dac_nids = stac9200_dac_nids;
1346 spec->adc_nids = stac9200_adc_nids;
1347 spec->mux_nids = stac9200_mux_nids;
Mattdabbed62005-06-14 10:19:34 +02001348 spec->num_muxes = 1;
Mattc7d4b2f2005-06-27 14:59:41 +02001349
1350 spec->init = stac9200_core_init;
Matt2f2f4252005-04-13 14:45:30 +02001351 spec->mixer = stac9200_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02001352
1353 err = stac9200_parse_auto_config(codec);
1354 if (err < 0) {
1355 stac92xx_free(codec);
1356 return err;
1357 }
Matt2f2f4252005-04-13 14:45:30 +02001358
1359 codec->patch_ops = stac92xx_patch_ops;
1360
1361 return 0;
1362}
1363
1364static int patch_stac922x(struct hda_codec *codec)
1365{
1366 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02001367 int err;
Matt2f2f4252005-04-13 14:45:30 +02001368
Takashi Iwaie560d8d2005-09-09 14:21:46 +02001369 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02001370 if (spec == NULL)
1371 return -ENOMEM;
1372
1373 codec->spec = spec;
Matt Porter403d1942005-11-29 15:00:51 +01001374 spec->board_config = snd_hda_check_board_config(codec, stac922x_cfg_tbl);
1375 if (spec->board_config < 0)
Takashi Iwai19039bd2006-06-28 15:52:16 +02001376 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC922x, "
1377 "using BIOS defaults\n");
Sam Revitch62fe78e2006-05-10 15:09:17 +02001378 else if (stac922x_brd_tbl[spec->board_config] != NULL) {
Matt Porter403d1942005-11-29 15:00:51 +01001379 spec->num_pins = 10;
1380 spec->pin_nids = stac922x_pin_nids;
1381 spec->pin_configs = stac922x_brd_tbl[spec->board_config];
1382 stac92xx_set_config_regs(codec);
1383 }
Matt2f2f4252005-04-13 14:45:30 +02001384
Matt2f2f4252005-04-13 14:45:30 +02001385 spec->adc_nids = stac922x_adc_nids;
1386 spec->mux_nids = stac922x_mux_nids;
Mattdabbed62005-06-14 10:19:34 +02001387 spec->num_muxes = 2;
Mattc7d4b2f2005-06-27 14:59:41 +02001388
1389 spec->init = stac922x_core_init;
Matt2f2f4252005-04-13 14:45:30 +02001390 spec->mixer = stac922x_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02001391
1392 spec->multiout.dac_nids = spec->dac_nids;
Takashi Iwai19039bd2006-06-28 15:52:16 +02001393
1394 switch (spec->board_config) {
1395 case STAC_D965_2112:
1396 spec->adc_nids = stac9227_adc_nids;
1397 spec->mux_nids = stac9227_mux_nids;
1398#if 0
1399 spec->multiout.dac_nids = d965_2112_dac_nids;
1400 spec->multiout.num_dacs = ARRAY_SIZE(d965_2112_dac_nids);
1401#endif
1402 spec->init = d965_2112_core_init;
1403 spec->mixer = stac9227_mixer;
1404 break;
1405 case STAC_D965_284B:
1406 spec->adc_nids = stac9227_adc_nids;
1407 spec->mux_nids = stac9227_mux_nids;
1408 spec->init = stac9227_core_init;
1409 spec->mixer = stac9227_mixer;
1410 break;
1411 }
Mattc7d4b2f2005-06-27 14:59:41 +02001412
Matt Porter3cc08dc2006-01-23 15:27:49 +01001413 err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
1414 if (err < 0) {
1415 stac92xx_free(codec);
1416 return err;
1417 }
1418
Sam Revitch62fe78e2006-05-10 15:09:17 +02001419 if (spec->board_config == STAC_MACMINI)
1420 spec->gpio_mute = 1;
1421
Matt Porter3cc08dc2006-01-23 15:27:49 +01001422 codec->patch_ops = stac92xx_patch_ops;
1423
1424 return 0;
1425}
1426
1427static int patch_stac927x(struct hda_codec *codec)
1428{
1429 struct sigmatel_spec *spec;
1430 int err;
1431
1432 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1433 if (spec == NULL)
1434 return -ENOMEM;
1435
1436 codec->spec = spec;
1437 spec->board_config = snd_hda_check_board_config(codec, stac927x_cfg_tbl);
1438 if (spec->board_config < 0)
1439 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC927x, using BIOS defaults\n");
1440 else {
1441 spec->num_pins = 14;
1442 spec->pin_nids = stac927x_pin_nids;
1443 spec->pin_configs = stac927x_brd_tbl[spec->board_config];
1444 stac92xx_set_config_regs(codec);
1445 }
1446
1447 spec->adc_nids = stac927x_adc_nids;
1448 spec->mux_nids = stac927x_mux_nids;
1449 spec->num_muxes = 3;
1450
1451 spec->init = stac927x_core_init;
1452 spec->mixer = stac927x_mixer;
1453
1454 spec->multiout.dac_nids = spec->dac_nids;
1455
1456 err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
Mattc7d4b2f2005-06-27 14:59:41 +02001457 if (err < 0) {
1458 stac92xx_free(codec);
1459 return err;
1460 }
Matt2f2f4252005-04-13 14:45:30 +02001461
1462 codec->patch_ops = stac92xx_patch_ops;
1463
1464 return 0;
1465}
1466
Matt Porterf3302a52006-07-31 12:49:34 +02001467static int patch_stac9205(struct hda_codec *codec)
1468{
1469 struct sigmatel_spec *spec;
1470 int err;
1471
1472 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1473 if (spec == NULL)
1474 return -ENOMEM;
1475
1476 codec->spec = spec;
1477 spec->board_config = snd_hda_check_board_config(codec, stac9205_cfg_tbl);
1478 if (spec->board_config < 0)
1479 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9205, using BIOS defaults\n");
1480 else {
1481 spec->num_pins = 14;
1482 spec->pin_nids = stac9205_pin_nids;
1483 spec->pin_configs = stac9205_brd_tbl[spec->board_config];
1484 stac92xx_set_config_regs(codec);
1485 }
1486
1487 spec->adc_nids = stac9205_adc_nids;
1488 spec->mux_nids = stac9205_mux_nids;
1489 spec->num_muxes = 3;
1490
1491 spec->init = stac9205_core_init;
1492 spec->mixer = stac9205_mixer;
1493
1494 spec->multiout.dac_nids = spec->dac_nids;
1495
1496 err = stac92xx_parse_auto_config(codec, 0x1f, 0x20);
1497 if (err < 0) {
1498 stac92xx_free(codec);
1499 return err;
1500 }
1501
1502 codec->patch_ops = stac92xx_patch_ops;
1503
1504 return 0;
1505}
1506
Matt2f2f4252005-04-13 14:45:30 +02001507/*
Guillaume Munch99ccc562006-08-16 19:35:12 +02001508 * STAC 7661(?) and 7664 hack
Takashi Iwaidb064e52006-03-16 16:04:58 +01001509 */
1510
Guillaume Munch99ccc562006-08-16 19:35:12 +02001511/* static config for Sony VAIO FE550G and Sony VAIO AR */
Takashi Iwaidb064e52006-03-16 16:04:58 +01001512static hda_nid_t vaio_dacs[] = { 0x2 };
1513#define VAIO_HP_DAC 0x5
1514static hda_nid_t vaio_adcs[] = { 0x8 /*,0x6*/ };
1515static hda_nid_t vaio_mux_nids[] = { 0x15 };
1516
1517static struct hda_input_mux vaio_mux = {
1518 .num_items = 2,
1519 .items = {
Takashi Iwaid7737812006-04-25 13:05:43 +02001520 /* { "HP", 0x0 }, */
1521 { "Line", 0x1 },
Takashi Iwaidb064e52006-03-16 16:04:58 +01001522 { "Mic", 0x2 },
1523 { "PCM", 0x3 },
1524 }
1525};
1526
1527static struct hda_verb vaio_init[] = {
1528 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
1529 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
1530 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
1531 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
1532 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
1533 {0x15, AC_VERB_SET_CONNECT_SEL, 0x2}, /* mic-sel: 0a,0d,14,02 */
1534 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
1535 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
1536 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
1537 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
1538 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
1539 {}
1540};
1541
1542/* bind volumes of both NID 0x02 and 0x05 */
1543static int vaio_master_vol_put(struct snd_kcontrol *kcontrol,
1544 struct snd_ctl_elem_value *ucontrol)
1545{
1546 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1547 long *valp = ucontrol->value.integer.value;
1548 int change;
1549
1550 change = snd_hda_codec_amp_update(codec, 0x02, 0, HDA_OUTPUT, 0,
1551 0x7f, valp[0] & 0x7f);
1552 change |= snd_hda_codec_amp_update(codec, 0x02, 1, HDA_OUTPUT, 0,
1553 0x7f, valp[1] & 0x7f);
1554 snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
1555 0x7f, valp[0] & 0x7f);
1556 snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
1557 0x7f, valp[1] & 0x7f);
1558 return change;
1559}
1560
1561/* bind volumes of both NID 0x02 and 0x05 */
1562static int vaio_master_sw_put(struct snd_kcontrol *kcontrol,
1563 struct snd_ctl_elem_value *ucontrol)
1564{
1565 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1566 long *valp = ucontrol->value.integer.value;
1567 int change;
1568
1569 change = snd_hda_codec_amp_update(codec, 0x02, 0, HDA_OUTPUT, 0,
Takashi Iwaia9393d72006-05-03 11:59:03 +02001570 0x80, (valp[0] ? 0 : 0x80));
Takashi Iwaidb064e52006-03-16 16:04:58 +01001571 change |= snd_hda_codec_amp_update(codec, 0x02, 1, HDA_OUTPUT, 0,
Takashi Iwaia9393d72006-05-03 11:59:03 +02001572 0x80, (valp[1] ? 0 : 0x80));
Takashi Iwaidb064e52006-03-16 16:04:58 +01001573 snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
Takashi Iwaia9393d72006-05-03 11:59:03 +02001574 0x80, (valp[0] ? 0 : 0x80));
Takashi Iwaidb064e52006-03-16 16:04:58 +01001575 snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
Takashi Iwaia9393d72006-05-03 11:59:03 +02001576 0x80, (valp[1] ? 0 : 0x80));
Takashi Iwaidb064e52006-03-16 16:04:58 +01001577 return change;
1578}
1579
1580static struct snd_kcontrol_new vaio_mixer[] = {
1581 {
1582 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1583 .name = "Master Playback Volume",
1584 .info = snd_hda_mixer_amp_volume_info,
1585 .get = snd_hda_mixer_amp_volume_get,
1586 .put = vaio_master_vol_put,
Takashi Iwaic2566522006-08-17 18:21:36 +02001587 .tlv = { .c = snd_hda_mixer_amp_tlv },
Takashi Iwaidb064e52006-03-16 16:04:58 +01001588 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
1589 },
1590 {
1591 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1592 .name = "Master Playback Switch",
1593 .info = snd_hda_mixer_amp_switch_info,
1594 .get = snd_hda_mixer_amp_switch_get,
1595 .put = vaio_master_sw_put,
1596 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
1597 },
1598 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
1599 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
1600 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
1601 {
1602 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1603 .name = "Capture Source",
1604 .count = 1,
1605 .info = stac92xx_mux_enum_info,
1606 .get = stac92xx_mux_enum_get,
1607 .put = stac92xx_mux_enum_put,
1608 },
1609 {}
1610};
1611
Guillaume Munch99ccc562006-08-16 19:35:12 +02001612static struct hda_codec_ops stac766x_patch_ops = {
Takashi Iwaidb064e52006-03-16 16:04:58 +01001613 .build_controls = stac92xx_build_controls,
1614 .build_pcms = stac92xx_build_pcms,
1615 .init = stac92xx_init,
1616 .free = stac92xx_free,
1617#ifdef CONFIG_PM
1618 .resume = stac92xx_resume,
1619#endif
1620};
1621
Guillaume Munch99ccc562006-08-16 19:35:12 +02001622enum { STAC766x_VAIO };
Takashi Iwaidb064e52006-03-16 16:04:58 +01001623
Guillaume Munch99ccc562006-08-16 19:35:12 +02001624static struct hda_board_config stac766x_cfg_tbl[] = {
1625 { .modelname = "vaio", .config = STAC766x_VAIO },
Takashi Iwaidb064e52006-03-16 16:04:58 +01001626 { .pci_subvendor = 0x104d, .pci_subdevice = 0x81e6,
Guillaume Munch99ccc562006-08-16 19:35:12 +02001627 .config = STAC766x_VAIO },
Takashi Iwaidb064e52006-03-16 16:04:58 +01001628 { .pci_subvendor = 0x104d, .pci_subdevice = 0x81ef,
Guillaume Munch99ccc562006-08-16 19:35:12 +02001629 .config = STAC766x_VAIO },
1630 { .pci_subvendor = 0x104d, .pci_subdevice = 0x81fd,
1631 .config = STAC766x_VAIO },
Takashi Iwaidb064e52006-03-16 16:04:58 +01001632 {}
1633};
1634
Guillaume Munch99ccc562006-08-16 19:35:12 +02001635static int patch_stac766x(struct hda_codec *codec)
Takashi Iwaidb064e52006-03-16 16:04:58 +01001636{
1637 struct sigmatel_spec *spec;
1638 int board_config;
1639
Guillaume Munch99ccc562006-08-16 19:35:12 +02001640 board_config = snd_hda_check_board_config(codec, stac766x_cfg_tbl);
Takashi Iwaidb064e52006-03-16 16:04:58 +01001641 if (board_config < 0)
1642 /* unknown config, let generic-parser do its job... */
1643 return snd_hda_parse_generic_codec(codec);
1644
1645 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1646 if (spec == NULL)
1647 return -ENOMEM;
1648
1649 codec->spec = spec;
1650 switch (board_config) {
Guillaume Munch99ccc562006-08-16 19:35:12 +02001651 case STAC766x_VAIO:
Takashi Iwaidb064e52006-03-16 16:04:58 +01001652 spec->mixer = vaio_mixer;
1653 spec->init = vaio_init;
1654 spec->multiout.max_channels = 2;
1655 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
1656 spec->multiout.dac_nids = vaio_dacs;
1657 spec->multiout.hp_nid = VAIO_HP_DAC;
1658 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
1659 spec->adc_nids = vaio_adcs;
1660 spec->input_mux = &vaio_mux;
1661 spec->mux_nids = vaio_mux_nids;
1662 break;
1663 }
1664
Guillaume Munch99ccc562006-08-16 19:35:12 +02001665 codec->patch_ops = stac766x_patch_ops;
Takashi Iwaidb064e52006-03-16 16:04:58 +01001666 return 0;
1667}
1668
1669
1670/*
Matt2f2f4252005-04-13 14:45:30 +02001671 * patch entries
1672 */
1673struct hda_codec_preset snd_hda_preset_sigmatel[] = {
1674 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
1675 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
1676 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
1677 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
1678 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
1679 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
1680 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
Matt Porter22a27c72006-07-06 18:49:10 +02001681 { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
1682 { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
1683 { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
1684 { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
1685 { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
1686 { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
Matt Porter3cc08dc2006-01-23 15:27:49 +01001687 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
1688 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
1689 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
1690 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
1691 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
1692 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
1693 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
1694 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
1695 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
1696 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
Guillaume Munch99ccc562006-08-16 19:35:12 +02001697 { .id = 0x83847661, .name = "STAC7661", .patch = patch_stac766x },
Matt Porterf3302a52006-07-31 12:49:34 +02001698 { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
1699 { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
1700 { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
1701 { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
1702 { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
1703 { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
1704 { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
1705 { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
Guillaume Munch99ccc562006-08-16 19:35:12 +02001706 { .id = 0x83847664, .name = "STAC7664", .patch = patch_stac766x },
Matt2f2f4252005-04-13 14:45:30 +02001707 {} /* terminator */
1708};