blob: fb4bed0759d182bc78277fb63de4f60b5ee38a18 [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
Mattc7d4b2f2005-06-27 14:59:41 +0200139static hda_nid_t stac9200_pin_nids[8] = {
140 0x08, 0x09, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12,
Matt2f2f4252005-04-13 14:45:30 +0200141};
142
143static hda_nid_t stac922x_pin_nids[10] = {
144 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
145 0x0f, 0x10, 0x11, 0x15, 0x1b,
146};
147
Matt Porter3cc08dc2006-01-23 15:27:49 +0100148static hda_nid_t stac927x_pin_nids[14] = {
149 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
150 0x0f, 0x10, 0x11, 0x12, 0x13,
151 0x14, 0x21, 0x22, 0x23,
152};
153
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100154static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Matt2f2f4252005-04-13 14:45:30 +0200155{
156 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
157 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +0200158 return snd_hda_input_mux_info(spec->input_mux, uinfo);
Matt2f2f4252005-04-13 14:45:30 +0200159}
160
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100161static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200162{
163 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
164 struct sigmatel_spec *spec = codec->spec;
165 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
166
167 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
168 return 0;
169}
170
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100171static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200172{
173 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
174 struct sigmatel_spec *spec = codec->spec;
175 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
176
Mattc7d4b2f2005-06-27 14:59:41 +0200177 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
Matt2f2f4252005-04-13 14:45:30 +0200178 spec->mux_nids[adc_idx], &spec->cur_mux[adc_idx]);
179}
180
Mattc7d4b2f2005-06-27 14:59:41 +0200181static struct hda_verb stac9200_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200182 /* set dac0mux for dac converter */
Mattc7d4b2f2005-06-27 14:59:41 +0200183 { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
Matt2f2f4252005-04-13 14:45:30 +0200184 {}
185};
186
Mattc7d4b2f2005-06-27 14:59:41 +0200187static struct hda_verb stac922x_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200188 /* set master volume and direct control */
Mattc7d4b2f2005-06-27 14:59:41 +0200189 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matt2f2f4252005-04-13 14:45:30 +0200190 {}
191};
192
Takashi Iwai19039bd2006-06-28 15:52:16 +0200193static struct hda_verb stac9227_core_init[] = {
194 /* set master volume and direct control */
195 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
196 /* unmute node 0x1b */
197 { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
198 {}
199};
200
201static struct hda_verb d965_2112_core_init[] = {
202 /* set master volume and direct control */
203 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
204 /* unmute node 0x1b */
205 { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
206 /* select node 0x03 as DAC */
207 { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
208 {}
209};
210
Matt Porter3cc08dc2006-01-23 15:27:49 +0100211static struct hda_verb stac927x_core_init[] = {
212 /* set master volume and direct control */
213 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
214 {}
215};
216
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100217static struct snd_kcontrol_new stac9200_mixer[] = {
Matt2f2f4252005-04-13 14:45:30 +0200218 HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
219 HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
220 {
221 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
222 .name = "Input Source",
223 .count = 1,
224 .info = stac92xx_mux_enum_info,
225 .get = stac92xx_mux_enum_get,
226 .put = stac92xx_mux_enum_put,
227 },
228 HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
229 HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
Mattc7d4b2f2005-06-27 14:59:41 +0200230 HDA_CODEC_VOLUME("Capture Mux Volume", 0x0c, 0, HDA_OUTPUT),
Matt2f2f4252005-04-13 14:45:30 +0200231 { } /* end */
232};
233
Mattc7d4b2f2005-06-27 14:59:41 +0200234/* This needs to be generated dynamically based on sequence */
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100235static struct snd_kcontrol_new stac922x_mixer[] = {
Matt2f2f4252005-04-13 14:45:30 +0200236 {
237 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
238 .name = "Input Source",
239 .count = 1,
240 .info = stac92xx_mux_enum_info,
241 .get = stac92xx_mux_enum_get,
242 .put = stac92xx_mux_enum_put,
243 },
244 HDA_CODEC_VOLUME("Capture Volume", 0x17, 0x0, HDA_INPUT),
Takashi Iwai0fd17082006-01-13 18:46:21 +0100245 HDA_CODEC_MUTE("Capture Switch", 0x17, 0x0, HDA_INPUT),
Matt2f2f4252005-04-13 14:45:30 +0200246 HDA_CODEC_VOLUME("Mux Capture Volume", 0x12, 0x0, HDA_OUTPUT),
247 { } /* end */
248};
249
Takashi Iwai19039bd2006-06-28 15:52:16 +0200250/* This needs to be generated dynamically based on sequence */
251static struct snd_kcontrol_new stac9227_mixer[] = {
252 {
253 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
254 .name = "Input Source",
255 .count = 1,
256 .info = stac92xx_mux_enum_info,
257 .get = stac92xx_mux_enum_get,
258 .put = stac92xx_mux_enum_put,
259 },
260 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
261 HDA_CODEC_MUTE("Capture Switch", 0x1b, 0x0, HDA_OUTPUT),
262 { } /* end */
263};
264
Matt Porter3cc08dc2006-01-23 15:27:49 +0100265static snd_kcontrol_new_t stac927x_mixer[] = {
266 {
267 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
268 .name = "Input Source",
269 .count = 1,
270 .info = stac92xx_mux_enum_info,
271 .get = stac92xx_mux_enum_get,
272 .put = stac92xx_mux_enum_put,
273 },
274 HDA_CODEC_VOLUME("InMux Capture Volume", 0x15, 0x0, HDA_OUTPUT),
275 HDA_CODEC_VOLUME("InVol Capture Volume", 0x18, 0x0, HDA_INPUT),
276 HDA_CODEC_MUTE("ADCMux Capture Switch", 0x1b, 0x0, HDA_OUTPUT),
277 { } /* end */
278};
279
Matt2f2f4252005-04-13 14:45:30 +0200280static int stac92xx_build_controls(struct hda_codec *codec)
281{
282 struct sigmatel_spec *spec = codec->spec;
283 int err;
Mattc7d4b2f2005-06-27 14:59:41 +0200284 int i;
Matt2f2f4252005-04-13 14:45:30 +0200285
286 err = snd_hda_add_new_ctls(codec, spec->mixer);
287 if (err < 0)
288 return err;
Mattc7d4b2f2005-06-27 14:59:41 +0200289
290 for (i = 0; i < spec->num_mixers; i++) {
291 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
292 if (err < 0)
293 return err;
294 }
295
Mattdabbed62005-06-14 10:19:34 +0200296 if (spec->multiout.dig_out_nid) {
297 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
298 if (err < 0)
299 return err;
300 }
301 if (spec->dig_in_nid) {
302 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
303 if (err < 0)
304 return err;
305 }
306 return 0;
Matt2f2f4252005-04-13 14:45:30 +0200307}
308
Matt Porter403d1942005-11-29 15:00:51 +0100309static unsigned int ref9200_pin_configs[8] = {
Mattdabbed62005-06-14 10:19:34 +0200310 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
Matt2f2f4252005-04-13 14:45:30 +0200311 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
312};
313
Matt Porter403d1942005-11-29 15:00:51 +0100314static unsigned int *stac9200_brd_tbl[] = {
315 ref9200_pin_configs,
316};
317
318static struct hda_board_config stac9200_cfg_tbl[] = {
319 { .modelname = "ref",
320 .pci_subvendor = PCI_VENDOR_ID_INTEL,
321 .pci_subdevice = 0x2668, /* DFI LanParty */
322 .config = STAC_REF },
323 {} /* terminator */
324};
325
326static unsigned int ref922x_pin_configs[10] = {
327 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
328 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
Matt2f2f4252005-04-13 14:45:30 +0200329 0x40000100, 0x40000100,
330};
331
Matt Porter403d1942005-11-29 15:00:51 +0100332static unsigned int d945gtp3_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +0100333 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
Matt Porter403d1942005-11-29 15:00:51 +0100334 0x40000100, 0x40000100, 0x40000100, 0x40000100,
335 0x02a19120, 0x40000100,
336};
337
338static unsigned int d945gtp5_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +0100339 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
340 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
Matt Porter403d1942005-11-29 15:00:51 +0100341 0x02a19320, 0x40000100,
342};
343
Takashi Iwai19039bd2006-06-28 15:52:16 +0200344static unsigned int d965_2112_pin_configs[10] = {
345 0x0221401f, 0x40000100, 0x40000100, 0x01014011,
346 0x01a19021, 0x01813024, 0x01452130, 0x40000100,
347 0x02a19320, 0x40000100,
348};
349
350static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
351 [STAC_REF] = ref922x_pin_configs,
352 [STAC_D945GTP3] = d945gtp3_pin_configs,
353 [STAC_D945GTP5] = d945gtp5_pin_configs,
354 [STAC_D965_2112] = d965_2112_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +0100355};
356
357static struct hda_board_config stac922x_cfg_tbl[] = {
358 { .modelname = "ref",
359 .pci_subvendor = PCI_VENDOR_ID_INTEL,
360 .pci_subdevice = 0x2668, /* DFI LanParty */
361 .config = STAC_REF }, /* SigmaTel reference board */
362 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
363 .pci_subdevice = 0x0101,
364 .config = STAC_D945GTP3 }, /* Intel D945GTP - 3 Stack */
365 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
Takashi Iwai353b9e62006-02-16 18:16:17 +0100366 .pci_subdevice = 0x0202,
367 .config = STAC_D945GTP3 }, /* Intel D945GNT - 3 Stack, 9221 A1 */
368 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
369 .pci_subdevice = 0x0b0b,
370 .config = STAC_D945GTP3 }, /* Intel D945PSN - 3 Stack, 9221 A1 */
371 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
Ashley Clarka29b6c82006-04-10 11:31:03 +0200372 .pci_subdevice = 0x0707,
373 .config = STAC_D945GTP5 }, /* Intel D945PSV - 5 Stack */
374 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
Matt Porter403d1942005-11-29 15:00:51 +0100375 .pci_subdevice = 0x0404,
376 .config = STAC_D945GTP5 }, /* Intel D945GTP - 5 Stack */
377 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
378 .pci_subdevice = 0x0303,
379 .config = STAC_D945GTP5 }, /* Intel D945GNT - 5 Stack */
380 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
381 .pci_subdevice = 0x0013,
382 .config = STAC_D945GTP5 }, /* Intel D955XBK - 5 Stack */
Matt Porterd62c40e2006-01-23 15:26:27 +0100383 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
384 .pci_subdevice = 0x0417,
385 .config = STAC_D945GTP5 }, /* Intel D975XBK - 5 Stack */
Sam Revitch62fe78e2006-05-10 15:09:17 +0200386 { .pci_subvendor = 0x8384,
387 .pci_subdevice = 0x7680,
388 .config = STAC_MACMINI }, /* Apple Mac Mini (early 2006) */
Takashi Iwai19039bd2006-06-28 15:52:16 +0200389 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
390 .pci_subdevice = 0x2112,
391 .config = STAC_D965_2112 },
392 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
393 .pci_subdevice = 0x284b,
394 .config = STAC_D965_284B },
Matt Porter403d1942005-11-29 15:00:51 +0100395 {} /* terminator */
396};
397
Matt Porter3cc08dc2006-01-23 15:27:49 +0100398static unsigned int ref927x_pin_configs[14] = {
399 0x01813122, 0x01a19021, 0x01014010, 0x01016011,
400 0x01012012, 0x01011014, 0x40000100, 0x40000100,
401 0x40000100, 0x40000100, 0x40000100, 0x01441030,
402 0x01c41030, 0x40000100,
403};
404
405static unsigned int *stac927x_brd_tbl[] = {
406 ref927x_pin_configs,
407};
408
409static struct hda_board_config stac927x_cfg_tbl[] = {
410 { .modelname = "ref",
411 .pci_subvendor = PCI_VENDOR_ID_INTEL,
412 .pci_subdevice = 0x2668, /* DFI LanParty */
413 .config = STAC_REF }, /* SigmaTel reference board */
414 {} /* terminator */
415};
416
Matt2f2f4252005-04-13 14:45:30 +0200417static void stac92xx_set_config_regs(struct hda_codec *codec)
418{
419 int i;
420 struct sigmatel_spec *spec = codec->spec;
421 unsigned int pin_cfg;
422
423 for (i=0; i < spec->num_pins; i++) {
424 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
425 AC_VERB_SET_CONFIG_DEFAULT_BYTES_0,
426 spec->pin_configs[i] & 0x000000ff);
427 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
428 AC_VERB_SET_CONFIG_DEFAULT_BYTES_1,
429 (spec->pin_configs[i] & 0x0000ff00) >> 8);
430 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
431 AC_VERB_SET_CONFIG_DEFAULT_BYTES_2,
432 (spec->pin_configs[i] & 0x00ff0000) >> 16);
433 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
434 AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
435 spec->pin_configs[i] >> 24);
436 pin_cfg = snd_hda_codec_read(codec, spec->pin_nids[i], 0,
437 AC_VERB_GET_CONFIG_DEFAULT,
438 0x00);
Matt Porter403d1942005-11-29 15:00:51 +0100439 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 +0200440 }
441}
Matt2f2f4252005-04-13 14:45:30 +0200442
Matt2f2f4252005-04-13 14:45:30 +0200443/*
444 * Analog playback callbacks
445 */
446static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
447 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100448 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200449{
450 struct sigmatel_spec *spec = codec->spec;
451 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
452}
453
454static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
455 struct hda_codec *codec,
456 unsigned int stream_tag,
457 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100458 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200459{
460 struct sigmatel_spec *spec = codec->spec;
Matt Porter403d1942005-11-29 15:00:51 +0100461 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
Matt2f2f4252005-04-13 14:45:30 +0200462}
463
464static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
465 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100466 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200467{
468 struct sigmatel_spec *spec = codec->spec;
469 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
470}
471
472/*
Mattdabbed62005-06-14 10:19:34 +0200473 * Digital playback callbacks
474 */
475static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
476 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100477 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +0200478{
479 struct sigmatel_spec *spec = codec->spec;
480 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
481}
482
483static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
484 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100485 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +0200486{
487 struct sigmatel_spec *spec = codec->spec;
488 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
489}
490
491
492/*
Matt2f2f4252005-04-13 14:45:30 +0200493 * Analog capture callbacks
494 */
495static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
496 struct hda_codec *codec,
497 unsigned int stream_tag,
498 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100499 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200500{
501 struct sigmatel_spec *spec = codec->spec;
502
503 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
504 stream_tag, 0, format);
505 return 0;
506}
507
508static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
509 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100510 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200511{
512 struct sigmatel_spec *spec = codec->spec;
513
514 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 0, 0, 0);
515 return 0;
516}
517
Mattdabbed62005-06-14 10:19:34 +0200518static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
519 .substreams = 1,
520 .channels_min = 2,
521 .channels_max = 2,
522 /* NID is set in stac92xx_build_pcms */
523 .ops = {
524 .open = stac92xx_dig_playback_pcm_open,
525 .close = stac92xx_dig_playback_pcm_close
526 },
527};
528
529static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
530 .substreams = 1,
531 .channels_min = 2,
532 .channels_max = 2,
533 /* NID is set in stac92xx_build_pcms */
534};
535
Matt2f2f4252005-04-13 14:45:30 +0200536static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
537 .substreams = 1,
538 .channels_min = 2,
Mattc7d4b2f2005-06-27 14:59:41 +0200539 .channels_max = 8,
Matt2f2f4252005-04-13 14:45:30 +0200540 .nid = 0x02, /* NID to query formats and rates */
541 .ops = {
542 .open = stac92xx_playback_pcm_open,
543 .prepare = stac92xx_playback_pcm_prepare,
544 .cleanup = stac92xx_playback_pcm_cleanup
545 },
546};
547
Matt Porter3cc08dc2006-01-23 15:27:49 +0100548static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
549 .substreams = 1,
550 .channels_min = 2,
551 .channels_max = 2,
552 .nid = 0x06, /* NID to query formats and rates */
553 .ops = {
554 .open = stac92xx_playback_pcm_open,
555 .prepare = stac92xx_playback_pcm_prepare,
556 .cleanup = stac92xx_playback_pcm_cleanup
557 },
558};
559
Matt2f2f4252005-04-13 14:45:30 +0200560static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
561 .substreams = 2,
562 .channels_min = 2,
563 .channels_max = 2,
Matt Porter3cc08dc2006-01-23 15:27:49 +0100564 /* NID is set in stac92xx_build_pcms */
Matt2f2f4252005-04-13 14:45:30 +0200565 .ops = {
566 .prepare = stac92xx_capture_pcm_prepare,
567 .cleanup = stac92xx_capture_pcm_cleanup
568 },
569};
570
571static int stac92xx_build_pcms(struct hda_codec *codec)
572{
573 struct sigmatel_spec *spec = codec->spec;
574 struct hda_pcm *info = spec->pcm_rec;
575
576 codec->num_pcms = 1;
577 codec->pcm_info = info;
578
Mattc7d4b2f2005-06-27 14:59:41 +0200579 info->name = "STAC92xx Analog";
Matt2f2f4252005-04-13 14:45:30 +0200580 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
Matt2f2f4252005-04-13 14:45:30 +0200581 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100582 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
583
584 if (spec->alt_switch) {
585 codec->num_pcms++;
586 info++;
587 info->name = "STAC92xx Analog Alt";
588 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
589 }
Matt2f2f4252005-04-13 14:45:30 +0200590
Mattdabbed62005-06-14 10:19:34 +0200591 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
592 codec->num_pcms++;
593 info++;
594 info->name = "STAC92xx Digital";
595 if (spec->multiout.dig_out_nid) {
596 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
597 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
598 }
599 if (spec->dig_in_nid) {
600 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
601 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
602 }
603 }
604
Matt2f2f4252005-04-13 14:45:30 +0200605 return 0;
606}
607
Takashi Iwaic960a032006-03-23 17:06:28 +0100608static unsigned int stac92xx_get_vref(struct hda_codec *codec, hda_nid_t nid)
609{
610 unsigned int pincap = snd_hda_param_read(codec, nid,
611 AC_PAR_PIN_CAP);
612 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
613 if (pincap & AC_PINCAP_VREF_100)
614 return AC_PINCTL_VREF_100;
615 if (pincap & AC_PINCAP_VREF_80)
616 return AC_PINCTL_VREF_80;
617 if (pincap & AC_PINCAP_VREF_50)
618 return AC_PINCTL_VREF_50;
619 if (pincap & AC_PINCAP_VREF_GRD)
620 return AC_PINCTL_VREF_GRD;
621 return 0;
622}
623
Matt Porter403d1942005-11-29 15:00:51 +0100624static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
625
626{
627 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
628}
629
630static int stac92xx_io_switch_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
631{
632 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
633 uinfo->count = 1;
634 uinfo->value.integer.min = 0;
635 uinfo->value.integer.max = 1;
636 return 0;
637}
638
639static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
640{
641 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
642 struct sigmatel_spec *spec = codec->spec;
643 int io_idx = kcontrol-> private_value & 0xff;
644
645 ucontrol->value.integer.value[0] = spec->io_switch[io_idx];
646 return 0;
647}
648
649static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
650{
651 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
652 struct sigmatel_spec *spec = codec->spec;
653 hda_nid_t nid = kcontrol->private_value >> 8;
654 int io_idx = kcontrol-> private_value & 0xff;
655 unsigned short val = ucontrol->value.integer.value[0];
656
657 spec->io_switch[io_idx] = val;
658
659 if (val)
660 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
Takashi Iwaic960a032006-03-23 17:06:28 +0100661 else {
662 unsigned int pinctl = AC_PINCTL_IN_EN;
663 if (io_idx) /* set VREF for mic */
664 pinctl |= stac92xx_get_vref(codec, nid);
665 stac92xx_auto_set_pinctl(codec, nid, pinctl);
666 }
Matt Porter403d1942005-11-29 15:00:51 +0100667 return 1;
668}
669
670#define STAC_CODEC_IO_SWITCH(xname, xpval) \
671 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
672 .name = xname, \
673 .index = 0, \
674 .info = stac92xx_io_switch_info, \
675 .get = stac92xx_io_switch_get, \
676 .put = stac92xx_io_switch_put, \
677 .private_value = xpval, \
678 }
679
680
Mattc7d4b2f2005-06-27 14:59:41 +0200681enum {
682 STAC_CTL_WIDGET_VOL,
683 STAC_CTL_WIDGET_MUTE,
Matt Porter403d1942005-11-29 15:00:51 +0100684 STAC_CTL_WIDGET_IO_SWITCH,
Mattc7d4b2f2005-06-27 14:59:41 +0200685};
686
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100687static struct snd_kcontrol_new stac92xx_control_templates[] = {
Mattc7d4b2f2005-06-27 14:59:41 +0200688 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
689 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Matt Porter403d1942005-11-29 15:00:51 +0100690 STAC_CODEC_IO_SWITCH(NULL, 0),
Mattc7d4b2f2005-06-27 14:59:41 +0200691};
692
693/* add dynamic controls */
694static int stac92xx_add_control(struct sigmatel_spec *spec, int type, const char *name, unsigned long val)
695{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100696 struct snd_kcontrol_new *knew;
Mattc7d4b2f2005-06-27 14:59:41 +0200697
698 if (spec->num_kctl_used >= spec->num_kctl_alloc) {
699 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
700
701 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */
702 if (! knew)
703 return -ENOMEM;
704 if (spec->kctl_alloc) {
705 memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
706 kfree(spec->kctl_alloc);
707 }
708 spec->kctl_alloc = knew;
709 spec->num_kctl_alloc = num;
710 }
711
712 knew = &spec->kctl_alloc[spec->num_kctl_used];
713 *knew = stac92xx_control_templates[type];
Takashi Iwai82fe0c52005-06-30 10:54:33 +0200714 knew->name = kstrdup(name, GFP_KERNEL);
Mattc7d4b2f2005-06-27 14:59:41 +0200715 if (! knew->name)
716 return -ENOMEM;
717 knew->private_value = val;
718 spec->num_kctl_used++;
719 return 0;
720}
721
Matt Porter403d1942005-11-29 15:00:51 +0100722/* flag inputs as additional dynamic lineouts */
723static int stac92xx_add_dyn_out_pins(struct hda_codec *codec, struct auto_pin_cfg *cfg)
724{
725 struct sigmatel_spec *spec = codec->spec;
726
727 switch (cfg->line_outs) {
728 case 3:
729 /* add line-in as side */
730 if (cfg->input_pins[AUTO_PIN_LINE]) {
731 cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_LINE];
732 spec->line_switch = 1;
733 cfg->line_outs++;
734 }
735 break;
736 case 2:
737 /* add line-in as clfe and mic as side */
738 if (cfg->input_pins[AUTO_PIN_LINE]) {
739 cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_LINE];
740 spec->line_switch = 1;
741 cfg->line_outs++;
742 }
743 if (cfg->input_pins[AUTO_PIN_MIC]) {
744 cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_MIC];
745 spec->mic_switch = 1;
746 cfg->line_outs++;
747 }
748 break;
749 case 1:
750 /* add line-in as surr and mic as clfe */
751 if (cfg->input_pins[AUTO_PIN_LINE]) {
752 cfg->line_out_pins[1] = cfg->input_pins[AUTO_PIN_LINE];
753 spec->line_switch = 1;
754 cfg->line_outs++;
755 }
756 if (cfg->input_pins[AUTO_PIN_MIC]) {
757 cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_MIC];
758 spec->mic_switch = 1;
759 cfg->line_outs++;
760 }
761 break;
762 }
763
764 return 0;
765}
766
Matt Porter3cc08dc2006-01-23 15:27:49 +0100767/*
768 * XXX The line_out pin widget connection list may not be set to the
769 * desired DAC nid. This is the case on 927x where ports A and B can
770 * be routed to several DACs.
771 *
772 * This requires an analysis of the line-out/hp pin configuration
773 * to provide a best fit for pin/DAC configurations that are routable.
774 * For now, 927x DAC4 is not supported and 927x DAC1 output to ports
775 * A and B is not supported.
776 */
Mattc7d4b2f2005-06-27 14:59:41 +0200777/* fill in the dac_nids table from the parsed pin configuration */
Takashi Iwai19039bd2006-06-28 15:52:16 +0200778static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec,
779 const struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +0200780{
781 struct sigmatel_spec *spec = codec->spec;
782 hda_nid_t nid;
783 int i;
784
785 /* check the pins hardwired to audio widget */
786 for (i = 0; i < cfg->line_outs; i++) {
787 nid = cfg->line_out_pins[i];
788 spec->multiout.dac_nids[i] = snd_hda_codec_read(codec, nid, 0,
789 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
790 }
791
Takashi Iwai82bc9552006-03-21 11:24:42 +0100792 spec->multiout.num_dacs = cfg->line_outs;
Mattc7d4b2f2005-06-27 14:59:41 +0200793
794 return 0;
795}
796
797/* add playback controls from the parsed DAC table */
Takashi Iwai19039bd2006-06-28 15:52:16 +0200798static int stac92xx_auto_create_multi_out_ctls(struct sigmatel_spec *spec,
799 const struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +0200800{
801 char name[32];
Takashi Iwai19039bd2006-06-28 15:52:16 +0200802 static const char *chname[4] = {
803 "Front", "Surround", NULL /*CLFE*/, "Side"
804 };
Mattc7d4b2f2005-06-27 14:59:41 +0200805 hda_nid_t nid;
806 int i, err;
807
808 for (i = 0; i < cfg->line_outs; i++) {
Matt Porter403d1942005-11-29 15:00:51 +0100809 if (!spec->multiout.dac_nids[i])
Mattc7d4b2f2005-06-27 14:59:41 +0200810 continue;
811
812 nid = spec->multiout.dac_nids[i];
813
814 if (i == 2) {
815 /* Center/LFE */
816 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, "Center Playback Volume",
817 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT))) < 0)
818 return err;
819 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, "LFE Playback Volume",
820 HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT))) < 0)
821 return err;
822 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, "Center Playback Switch",
823 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT))) < 0)
824 return err;
825 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, "LFE Playback Switch",
826 HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT))) < 0)
827 return err;
828 } else {
829 sprintf(name, "%s Playback Volume", chname[i]);
830 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, name,
831 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
832 return err;
833 sprintf(name, "%s Playback Switch", chname[i]);
834 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, name,
835 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
836 return err;
837 }
838 }
839
Matt Porter403d1942005-11-29 15:00:51 +0100840 if (spec->line_switch)
841 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Line In as Output Switch", cfg->input_pins[AUTO_PIN_LINE] << 8)) < 0)
842 return err;
843
844 if (spec->mic_switch)
845 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Mic as Output Switch", (cfg->input_pins[AUTO_PIN_MIC] << 8) | 1)) < 0)
846 return err;
847
Mattc7d4b2f2005-06-27 14:59:41 +0200848 return 0;
849}
850
851/* add playback controls for HP output */
852static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec, struct auto_pin_cfg *cfg)
853{
854 struct sigmatel_spec *spec = codec->spec;
855 hda_nid_t pin = cfg->hp_pin;
856 hda_nid_t nid;
857 int i, err;
Matt4e550962005-07-04 17:51:39 +0200858 unsigned int wid_caps;
Mattc7d4b2f2005-06-27 14:59:41 +0200859
860 if (! pin)
861 return 0;
862
Takashi Iwai54d17402005-11-21 16:33:22 +0100863 wid_caps = get_wcaps(codec, pin);
Takashi Iwai505cb342006-03-27 12:51:52 +0200864 if (wid_caps & AC_WCAP_UNSOL_CAP)
Takashi Iwai82bc9552006-03-21 11:24:42 +0100865 spec->hp_detect = 1;
Matt4e550962005-07-04 17:51:39 +0200866
Mattc7d4b2f2005-06-27 14:59:41 +0200867 nid = snd_hda_codec_read(codec, pin, 0, AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
868 for (i = 0; i < cfg->line_outs; i++) {
869 if (! spec->multiout.dac_nids[i])
870 continue;
871 if (spec->multiout.dac_nids[i] == nid)
872 return 0;
873 }
874
875 spec->multiout.hp_nid = nid;
876
877 /* control HP volume/switch on the output mixer amp */
878 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, "Headphone Playback Volume",
879 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
880 return err;
881 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, "Headphone Playback Switch",
882 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
883 return err;
884
885 return 0;
886}
887
888/* create playback/capture controls for input pins */
889static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
890{
891 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +0200892 struct hda_input_mux *imux = &spec->private_imux;
893 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
894 int i, j, k;
895
896 for (i = 0; i < AUTO_PIN_LAST; i++) {
897 int index = -1;
898 if (cfg->input_pins[i]) {
Takashi Iwai4a471b72005-12-07 13:56:29 +0100899 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
Mattc7d4b2f2005-06-27 14:59:41 +0200900
901 for (j=0; j<spec->num_muxes; j++) {
902 int num_cons = snd_hda_get_connections(codec, spec->mux_nids[j], con_lst, HDA_MAX_NUM_INPUTS);
903 for (k=0; k<num_cons; k++)
904 if (con_lst[k] == cfg->input_pins[i]) {
905 index = k;
906 break;
907 }
908 if (index >= 0)
909 break;
910 }
911 imux->items[imux->num_items].index = index;
912 imux->num_items++;
913 }
914 }
915
Sam Revitch62fe78e2006-05-10 15:09:17 +0200916 if (imux->num_items == 1) {
917 /*
918 * Set the current input for the muxes.
919 * The STAC9221 has two input muxes with identical source
920 * NID lists. Hopefully this won't get confused.
921 */
922 for (i = 0; i < spec->num_muxes; i++) {
923 snd_hda_codec_write(codec, spec->mux_nids[i], 0,
924 AC_VERB_SET_CONNECT_SEL,
925 imux->items[0].index);
926 }
927 }
928
Mattc7d4b2f2005-06-27 14:59:41 +0200929 return 0;
930}
931
Mattc7d4b2f2005-06-27 14:59:41 +0200932static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
933{
934 struct sigmatel_spec *spec = codec->spec;
935 int i;
936
937 for (i = 0; i < spec->autocfg.line_outs; i++) {
938 hda_nid_t nid = spec->autocfg.line_out_pins[i];
939 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
940 }
941}
942
943static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
944{
945 struct sigmatel_spec *spec = codec->spec;
946 hda_nid_t pin;
947
948 pin = spec->autocfg.hp_pin;
949 if (pin) /* connect to front */
950 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
951}
952
Matt Porter3cc08dc2006-01-23 15:27:49 +0100953static 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 +0200954{
955 struct sigmatel_spec *spec = codec->spec;
956 int err;
957
Kailang Yangdf694da2005-12-05 19:42:22 +0100958 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +0200959 return err;
Takashi Iwai82bc9552006-03-21 11:24:42 +0100960 if (! spec->autocfg.line_outs)
Matt Porter869264c2006-01-25 19:20:50 +0100961 return 0; /* can't find valid pin config */
Takashi Iwai19039bd2006-06-28 15:52:16 +0200962
Matt Porter403d1942005-11-29 15:00:51 +0100963 if ((err = stac92xx_add_dyn_out_pins(codec, &spec->autocfg)) < 0)
964 return err;
Takashi Iwai19039bd2006-06-28 15:52:16 +0200965 if (spec->multiout.num_dacs == 0)
966 if ((err = stac92xx_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
967 return err;
Mattc7d4b2f2005-06-27 14:59:41 +0200968
969 if ((err = stac92xx_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
970 (err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg)) < 0 ||
971 (err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
972 return err;
973
974 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Matt Porter403d1942005-11-29 15:00:51 +0100975 if (spec->multiout.max_channels > 2)
Mattc7d4b2f2005-06-27 14:59:41 +0200976 spec->surr_switch = 1;
Mattc7d4b2f2005-06-27 14:59:41 +0200977
Takashi Iwai82bc9552006-03-21 11:24:42 +0100978 if (spec->autocfg.dig_out_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +0100979 spec->multiout.dig_out_nid = dig_out;
Takashi Iwai82bc9552006-03-21 11:24:42 +0100980 if (spec->autocfg.dig_in_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +0100981 spec->dig_in_nid = dig_in;
Mattc7d4b2f2005-06-27 14:59:41 +0200982
983 if (spec->kctl_alloc)
984 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
985
986 spec->input_mux = &spec->private_imux;
987
988 return 1;
989}
990
Takashi Iwai82bc9552006-03-21 11:24:42 +0100991/* add playback controls for HP output */
992static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
993 struct auto_pin_cfg *cfg)
994{
995 struct sigmatel_spec *spec = codec->spec;
996 hda_nid_t pin = cfg->hp_pin;
997 unsigned int wid_caps;
998
999 if (! pin)
1000 return 0;
1001
1002 wid_caps = get_wcaps(codec, pin);
Takashi Iwai505cb342006-03-27 12:51:52 +02001003 if (wid_caps & AC_WCAP_UNSOL_CAP)
Takashi Iwai82bc9552006-03-21 11:24:42 +01001004 spec->hp_detect = 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +01001005
1006 return 0;
1007}
1008
Mattc7d4b2f2005-06-27 14:59:41 +02001009static int stac9200_parse_auto_config(struct hda_codec *codec)
1010{
1011 struct sigmatel_spec *spec = codec->spec;
1012 int err;
1013
Kailang Yangdf694da2005-12-05 19:42:22 +01001014 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001015 return err;
1016
1017 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
1018 return err;
1019
Takashi Iwai82bc9552006-03-21 11:24:42 +01001020 if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
1021 return err;
1022
1023 if (spec->autocfg.dig_out_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02001024 spec->multiout.dig_out_nid = 0x05;
Takashi Iwai82bc9552006-03-21 11:24:42 +01001025 if (spec->autocfg.dig_in_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02001026 spec->dig_in_nid = 0x04;
Mattc7d4b2f2005-06-27 14:59:41 +02001027
1028 if (spec->kctl_alloc)
1029 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
1030
1031 spec->input_mux = &spec->private_imux;
1032
1033 return 1;
1034}
1035
Sam Revitch62fe78e2006-05-10 15:09:17 +02001036/*
1037 * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
1038 * funky external mute control using GPIO pins.
1039 */
1040
1041static void stac922x_gpio_mute(struct hda_codec *codec, int pin, int muted)
1042{
1043 unsigned int gpiostate, gpiomask, gpiodir;
1044
1045 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
1046 AC_VERB_GET_GPIO_DATA, 0);
1047
1048 if (!muted)
1049 gpiostate |= (1 << pin);
1050 else
1051 gpiostate &= ~(1 << pin);
1052
1053 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
1054 AC_VERB_GET_GPIO_MASK, 0);
1055 gpiomask |= (1 << pin);
1056
1057 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
1058 AC_VERB_GET_GPIO_DIRECTION, 0);
1059 gpiodir |= (1 << pin);
1060
1061 /* AppleHDA seems to do this -- WTF is this verb?? */
1062 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
1063
1064 snd_hda_codec_write(codec, codec->afg, 0,
1065 AC_VERB_SET_GPIO_MASK, gpiomask);
1066 snd_hda_codec_write(codec, codec->afg, 0,
1067 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
1068
1069 msleep(1);
1070
1071 snd_hda_codec_write(codec, codec->afg, 0,
1072 AC_VERB_SET_GPIO_DATA, gpiostate);
1073}
1074
Mattc7d4b2f2005-06-27 14:59:41 +02001075static int stac92xx_init(struct hda_codec *codec)
1076{
1077 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai82bc9552006-03-21 11:24:42 +01001078 struct auto_pin_cfg *cfg = &spec->autocfg;
1079 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02001080
Mattc7d4b2f2005-06-27 14:59:41 +02001081 snd_hda_sequence_write(codec, spec->init);
1082
Takashi Iwai82bc9552006-03-21 11:24:42 +01001083 /* set up pins */
1084 if (spec->hp_detect) {
Takashi Iwai505cb342006-03-27 12:51:52 +02001085 /* Enable unsolicited responses on the HP widget */
1086 snd_hda_codec_write(codec, cfg->hp_pin, 0,
1087 AC_VERB_SET_UNSOLICITED_ENABLE,
1088 STAC_UNSOL_ENABLE);
Takashi Iwai82bc9552006-03-21 11:24:42 +01001089 /* fake event to set up pins */
1090 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
1091 } else {
1092 stac92xx_auto_init_multi_out(codec);
1093 stac92xx_auto_init_hp_out(codec);
1094 }
1095 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwaic960a032006-03-23 17:06:28 +01001096 hda_nid_t nid = cfg->input_pins[i];
1097 if (nid) {
1098 unsigned int pinctl = AC_PINCTL_IN_EN;
1099 if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC)
1100 pinctl |= stac92xx_get_vref(codec, nid);
1101 stac92xx_auto_set_pinctl(codec, nid, pinctl);
1102 }
Takashi Iwai82bc9552006-03-21 11:24:42 +01001103 }
1104 if (cfg->dig_out_pin)
1105 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pin,
1106 AC_PINCTL_OUT_EN);
1107 if (cfg->dig_in_pin)
1108 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
1109 AC_PINCTL_IN_EN);
1110
Sam Revitch62fe78e2006-05-10 15:09:17 +02001111 if (spec->gpio_mute) {
1112 stac922x_gpio_mute(codec, 0, 0);
1113 stac922x_gpio_mute(codec, 1, 0);
1114 }
1115
Mattc7d4b2f2005-06-27 14:59:41 +02001116 return 0;
1117}
1118
Matt2f2f4252005-04-13 14:45:30 +02001119static void stac92xx_free(struct hda_codec *codec)
1120{
Mattc7d4b2f2005-06-27 14:59:41 +02001121 struct sigmatel_spec *spec = codec->spec;
1122 int i;
1123
1124 if (! spec)
1125 return;
1126
1127 if (spec->kctl_alloc) {
1128 for (i = 0; i < spec->num_kctl_used; i++)
1129 kfree(spec->kctl_alloc[i].name);
1130 kfree(spec->kctl_alloc);
1131 }
1132
1133 kfree(spec);
Matt2f2f4252005-04-13 14:45:30 +02001134}
1135
Matt4e550962005-07-04 17:51:39 +02001136static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
1137 unsigned int flag)
1138{
1139 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
1140 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
1141 snd_hda_codec_write(codec, nid, 0,
1142 AC_VERB_SET_PIN_WIDGET_CONTROL,
1143 pin_ctl | flag);
1144}
1145
1146static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
1147 unsigned int flag)
1148{
1149 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
1150 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
1151 snd_hda_codec_write(codec, nid, 0,
1152 AC_VERB_SET_PIN_WIDGET_CONTROL,
1153 pin_ctl & ~flag);
1154}
1155
1156static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
1157{
1158 struct sigmatel_spec *spec = codec->spec;
1159 struct auto_pin_cfg *cfg = &spec->autocfg;
1160 int i, presence;
1161
1162 if ((res >> 26) != STAC_HP_EVENT)
1163 return;
1164
1165 presence = snd_hda_codec_read(codec, cfg->hp_pin, 0,
1166 AC_VERB_GET_PIN_SENSE, 0x00) >> 31;
1167
1168 if (presence) {
1169 /* disable lineouts, enable hp */
1170 for (i = 0; i < cfg->line_outs; i++)
1171 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
1172 AC_PINCTL_OUT_EN);
1173 stac92xx_set_pinctl(codec, cfg->hp_pin, AC_PINCTL_OUT_EN);
1174 } else {
1175 /* enable lineouts, disable hp */
1176 for (i = 0; i < cfg->line_outs; i++)
1177 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
1178 AC_PINCTL_OUT_EN);
1179 stac92xx_reset_pinctl(codec, cfg->hp_pin, AC_PINCTL_OUT_EN);
1180 }
1181}
1182
Mattff6fdc32005-06-27 15:06:52 +02001183#ifdef CONFIG_PM
1184static int stac92xx_resume(struct hda_codec *codec)
1185{
1186 struct sigmatel_spec *spec = codec->spec;
1187 int i;
1188
1189 stac92xx_init(codec);
1190 for (i = 0; i < spec->num_mixers; i++)
1191 snd_hda_resume_ctls(codec, spec->mixers[i]);
1192 if (spec->multiout.dig_out_nid)
1193 snd_hda_resume_spdif_out(codec);
1194 if (spec->dig_in_nid)
1195 snd_hda_resume_spdif_in(codec);
1196
1197 return 0;
1198}
1199#endif
1200
Matt2f2f4252005-04-13 14:45:30 +02001201static struct hda_codec_ops stac92xx_patch_ops = {
1202 .build_controls = stac92xx_build_controls,
1203 .build_pcms = stac92xx_build_pcms,
1204 .init = stac92xx_init,
1205 .free = stac92xx_free,
Matt4e550962005-07-04 17:51:39 +02001206 .unsol_event = stac92xx_unsol_event,
Mattff6fdc32005-06-27 15:06:52 +02001207#ifdef CONFIG_PM
1208 .resume = stac92xx_resume,
1209#endif
Matt2f2f4252005-04-13 14:45:30 +02001210};
1211
1212static int patch_stac9200(struct hda_codec *codec)
1213{
1214 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02001215 int err;
Matt2f2f4252005-04-13 14:45:30 +02001216
Takashi Iwaie560d8d2005-09-09 14:21:46 +02001217 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02001218 if (spec == NULL)
1219 return -ENOMEM;
1220
1221 codec->spec = spec;
Matt Porter403d1942005-11-29 15:00:51 +01001222 spec->board_config = snd_hda_check_board_config(codec, stac9200_cfg_tbl);
1223 if (spec->board_config < 0)
1224 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9200, using BIOS defaults\n");
1225 else {
1226 spec->num_pins = 8;
1227 spec->pin_nids = stac9200_pin_nids;
1228 spec->pin_configs = stac9200_brd_tbl[spec->board_config];
1229 stac92xx_set_config_regs(codec);
1230 }
Matt2f2f4252005-04-13 14:45:30 +02001231
1232 spec->multiout.max_channels = 2;
1233 spec->multiout.num_dacs = 1;
1234 spec->multiout.dac_nids = stac9200_dac_nids;
1235 spec->adc_nids = stac9200_adc_nids;
1236 spec->mux_nids = stac9200_mux_nids;
Mattdabbed62005-06-14 10:19:34 +02001237 spec->num_muxes = 1;
Mattc7d4b2f2005-06-27 14:59:41 +02001238
1239 spec->init = stac9200_core_init;
Matt2f2f4252005-04-13 14:45:30 +02001240 spec->mixer = stac9200_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02001241
1242 err = stac9200_parse_auto_config(codec);
1243 if (err < 0) {
1244 stac92xx_free(codec);
1245 return err;
1246 }
Matt2f2f4252005-04-13 14:45:30 +02001247
1248 codec->patch_ops = stac92xx_patch_ops;
1249
1250 return 0;
1251}
1252
1253static int patch_stac922x(struct hda_codec *codec)
1254{
1255 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02001256 int err;
Matt2f2f4252005-04-13 14:45:30 +02001257
Takashi Iwaie560d8d2005-09-09 14:21:46 +02001258 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02001259 if (spec == NULL)
1260 return -ENOMEM;
1261
1262 codec->spec = spec;
Matt Porter403d1942005-11-29 15:00:51 +01001263 spec->board_config = snd_hda_check_board_config(codec, stac922x_cfg_tbl);
1264 if (spec->board_config < 0)
Takashi Iwai19039bd2006-06-28 15:52:16 +02001265 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC922x, "
1266 "using BIOS defaults\n");
Sam Revitch62fe78e2006-05-10 15:09:17 +02001267 else if (stac922x_brd_tbl[spec->board_config] != NULL) {
Matt Porter403d1942005-11-29 15:00:51 +01001268 spec->num_pins = 10;
1269 spec->pin_nids = stac922x_pin_nids;
1270 spec->pin_configs = stac922x_brd_tbl[spec->board_config];
1271 stac92xx_set_config_regs(codec);
1272 }
Matt2f2f4252005-04-13 14:45:30 +02001273
Matt2f2f4252005-04-13 14:45:30 +02001274 spec->adc_nids = stac922x_adc_nids;
1275 spec->mux_nids = stac922x_mux_nids;
Mattdabbed62005-06-14 10:19:34 +02001276 spec->num_muxes = 2;
Mattc7d4b2f2005-06-27 14:59:41 +02001277
1278 spec->init = stac922x_core_init;
Matt2f2f4252005-04-13 14:45:30 +02001279 spec->mixer = stac922x_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02001280
1281 spec->multiout.dac_nids = spec->dac_nids;
Takashi Iwai19039bd2006-06-28 15:52:16 +02001282
1283 switch (spec->board_config) {
1284 case STAC_D965_2112:
1285 spec->adc_nids = stac9227_adc_nids;
1286 spec->mux_nids = stac9227_mux_nids;
1287#if 0
1288 spec->multiout.dac_nids = d965_2112_dac_nids;
1289 spec->multiout.num_dacs = ARRAY_SIZE(d965_2112_dac_nids);
1290#endif
1291 spec->init = d965_2112_core_init;
1292 spec->mixer = stac9227_mixer;
1293 break;
1294 case STAC_D965_284B:
1295 spec->adc_nids = stac9227_adc_nids;
1296 spec->mux_nids = stac9227_mux_nids;
1297 spec->init = stac9227_core_init;
1298 spec->mixer = stac9227_mixer;
1299 break;
1300 }
Mattc7d4b2f2005-06-27 14:59:41 +02001301
Matt Porter3cc08dc2006-01-23 15:27:49 +01001302 err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
1303 if (err < 0) {
1304 stac92xx_free(codec);
1305 return err;
1306 }
1307
Sam Revitch62fe78e2006-05-10 15:09:17 +02001308 if (spec->board_config == STAC_MACMINI)
1309 spec->gpio_mute = 1;
1310
Matt Porter3cc08dc2006-01-23 15:27:49 +01001311 codec->patch_ops = stac92xx_patch_ops;
1312
1313 return 0;
1314}
1315
1316static int patch_stac927x(struct hda_codec *codec)
1317{
1318 struct sigmatel_spec *spec;
1319 int err;
1320
1321 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1322 if (spec == NULL)
1323 return -ENOMEM;
1324
1325 codec->spec = spec;
1326 spec->board_config = snd_hda_check_board_config(codec, stac927x_cfg_tbl);
1327 if (spec->board_config < 0)
1328 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC927x, using BIOS defaults\n");
1329 else {
1330 spec->num_pins = 14;
1331 spec->pin_nids = stac927x_pin_nids;
1332 spec->pin_configs = stac927x_brd_tbl[spec->board_config];
1333 stac92xx_set_config_regs(codec);
1334 }
1335
1336 spec->adc_nids = stac927x_adc_nids;
1337 spec->mux_nids = stac927x_mux_nids;
1338 spec->num_muxes = 3;
1339
1340 spec->init = stac927x_core_init;
1341 spec->mixer = stac927x_mixer;
1342
1343 spec->multiout.dac_nids = spec->dac_nids;
1344
1345 err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
Mattc7d4b2f2005-06-27 14:59:41 +02001346 if (err < 0) {
1347 stac92xx_free(codec);
1348 return err;
1349 }
Matt2f2f4252005-04-13 14:45:30 +02001350
1351 codec->patch_ops = stac92xx_patch_ops;
1352
1353 return 0;
1354}
1355
1356/*
Takashi Iwaidb064e52006-03-16 16:04:58 +01001357 * STAC 7661(?) hack
1358 */
1359
1360/* static config for Sony VAIO FE550G */
1361static hda_nid_t vaio_dacs[] = { 0x2 };
1362#define VAIO_HP_DAC 0x5
1363static hda_nid_t vaio_adcs[] = { 0x8 /*,0x6*/ };
1364static hda_nid_t vaio_mux_nids[] = { 0x15 };
1365
1366static struct hda_input_mux vaio_mux = {
1367 .num_items = 2,
1368 .items = {
Takashi Iwaid7737812006-04-25 13:05:43 +02001369 /* { "HP", 0x0 }, */
1370 { "Line", 0x1 },
Takashi Iwaidb064e52006-03-16 16:04:58 +01001371 { "Mic", 0x2 },
1372 { "PCM", 0x3 },
1373 }
1374};
1375
1376static struct hda_verb vaio_init[] = {
1377 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
1378 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
1379 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
1380 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
1381 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
1382 {0x15, AC_VERB_SET_CONNECT_SEL, 0x2}, /* mic-sel: 0a,0d,14,02 */
1383 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
1384 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
1385 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
1386 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
1387 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
1388 {}
1389};
1390
1391/* bind volumes of both NID 0x02 and 0x05 */
1392static int vaio_master_vol_put(struct snd_kcontrol *kcontrol,
1393 struct snd_ctl_elem_value *ucontrol)
1394{
1395 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1396 long *valp = ucontrol->value.integer.value;
1397 int change;
1398
1399 change = snd_hda_codec_amp_update(codec, 0x02, 0, HDA_OUTPUT, 0,
1400 0x7f, valp[0] & 0x7f);
1401 change |= snd_hda_codec_amp_update(codec, 0x02, 1, HDA_OUTPUT, 0,
1402 0x7f, valp[1] & 0x7f);
1403 snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
1404 0x7f, valp[0] & 0x7f);
1405 snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
1406 0x7f, valp[1] & 0x7f);
1407 return change;
1408}
1409
1410/* bind volumes of both NID 0x02 and 0x05 */
1411static int vaio_master_sw_put(struct snd_kcontrol *kcontrol,
1412 struct snd_ctl_elem_value *ucontrol)
1413{
1414 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1415 long *valp = ucontrol->value.integer.value;
1416 int change;
1417
1418 change = snd_hda_codec_amp_update(codec, 0x02, 0, HDA_OUTPUT, 0,
Takashi Iwaia9393d72006-05-03 11:59:03 +02001419 0x80, (valp[0] ? 0 : 0x80));
Takashi Iwaidb064e52006-03-16 16:04:58 +01001420 change |= snd_hda_codec_amp_update(codec, 0x02, 1, HDA_OUTPUT, 0,
Takashi Iwaia9393d72006-05-03 11:59:03 +02001421 0x80, (valp[1] ? 0 : 0x80));
Takashi Iwaidb064e52006-03-16 16:04:58 +01001422 snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
Takashi Iwaia9393d72006-05-03 11:59:03 +02001423 0x80, (valp[0] ? 0 : 0x80));
Takashi Iwaidb064e52006-03-16 16:04:58 +01001424 snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
Takashi Iwaia9393d72006-05-03 11:59:03 +02001425 0x80, (valp[1] ? 0 : 0x80));
Takashi Iwaidb064e52006-03-16 16:04:58 +01001426 return change;
1427}
1428
1429static struct snd_kcontrol_new vaio_mixer[] = {
1430 {
1431 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1432 .name = "Master Playback Volume",
1433 .info = snd_hda_mixer_amp_volume_info,
1434 .get = snd_hda_mixer_amp_volume_get,
1435 .put = vaio_master_vol_put,
1436 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
1437 },
1438 {
1439 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1440 .name = "Master Playback Switch",
1441 .info = snd_hda_mixer_amp_switch_info,
1442 .get = snd_hda_mixer_amp_switch_get,
1443 .put = vaio_master_sw_put,
1444 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
1445 },
1446 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
1447 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
1448 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
1449 {
1450 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1451 .name = "Capture Source",
1452 .count = 1,
1453 .info = stac92xx_mux_enum_info,
1454 .get = stac92xx_mux_enum_get,
1455 .put = stac92xx_mux_enum_put,
1456 },
1457 {}
1458};
1459
1460static struct hda_codec_ops stac7661_patch_ops = {
1461 .build_controls = stac92xx_build_controls,
1462 .build_pcms = stac92xx_build_pcms,
1463 .init = stac92xx_init,
1464 .free = stac92xx_free,
1465#ifdef CONFIG_PM
1466 .resume = stac92xx_resume,
1467#endif
1468};
1469
1470enum { STAC7661_VAIO };
1471
1472static struct hda_board_config stac7661_cfg_tbl[] = {
1473 { .modelname = "vaio", .config = STAC7661_VAIO },
1474 { .pci_subvendor = 0x104d, .pci_subdevice = 0x81e6,
1475 .config = STAC7661_VAIO },
1476 { .pci_subvendor = 0x104d, .pci_subdevice = 0x81ef,
1477 .config = STAC7661_VAIO },
1478 {}
1479};
1480
1481static int patch_stac7661(struct hda_codec *codec)
1482{
1483 struct sigmatel_spec *spec;
1484 int board_config;
1485
1486 board_config = snd_hda_check_board_config(codec, stac7661_cfg_tbl);
1487 if (board_config < 0)
1488 /* unknown config, let generic-parser do its job... */
1489 return snd_hda_parse_generic_codec(codec);
1490
1491 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1492 if (spec == NULL)
1493 return -ENOMEM;
1494
1495 codec->spec = spec;
1496 switch (board_config) {
1497 case STAC7661_VAIO:
1498 spec->mixer = vaio_mixer;
1499 spec->init = vaio_init;
1500 spec->multiout.max_channels = 2;
1501 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
1502 spec->multiout.dac_nids = vaio_dacs;
1503 spec->multiout.hp_nid = VAIO_HP_DAC;
1504 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
1505 spec->adc_nids = vaio_adcs;
1506 spec->input_mux = &vaio_mux;
1507 spec->mux_nids = vaio_mux_nids;
1508 break;
1509 }
1510
1511 codec->patch_ops = stac7661_patch_ops;
1512 return 0;
1513}
1514
1515
1516/*
Matt2f2f4252005-04-13 14:45:30 +02001517 * patch entries
1518 */
1519struct hda_codec_preset snd_hda_preset_sigmatel[] = {
1520 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
1521 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
1522 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
1523 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
1524 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
1525 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
1526 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
Matt Portera59524f2006-05-03 14:08:33 +02001527 { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac922x },
1528 { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac922x },
1529 { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac922x },
1530 { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac922x },
1531 { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac922x },
1532 { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac922x },
Matt Porter3cc08dc2006-01-23 15:27:49 +01001533 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
1534 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
1535 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
1536 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
1537 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
1538 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
1539 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
1540 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
1541 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
1542 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
Takashi Iwaidb064e52006-03-16 16:04:58 +01001543 { .id = 0x83847661, .name = "STAC7661", .patch = patch_stac7661 },
Matt2f2f4252005-04-13 14:45:30 +02001544 {} /* terminator */
1545};