blob: 4c7b03996be99b773f5ff84ca9c9ae2b1a3bbf8c [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
Matt4e550962005-07-04 17:51:39 +020039
Takashi Iwaif5fcc132006-11-24 17:07:44 +010040enum {
41 STAC_REF,
42 STAC_9200_MODELS
43};
44
45enum {
46 STAC_9205_REF,
47 STAC_9205_MODELS
48};
49
50enum {
Tobin Davis8e21c342007-01-08 11:04:17 +010051 STAC_925x_REF,
52 STAC_M2_2,
53 STAC_MA6,
54 STAC_925x_MODELS
55};
56
57enum {
Takashi Iwaif5fcc132006-11-24 17:07:44 +010058 STAC_D945_REF,
59 STAC_D945GTP3,
60 STAC_D945GTP5,
61 STAC_MACMINI,
Takashi Iwai3fc24d82007-02-16 13:27:18 +010062 STAC_MACBOOK,
63 STAC_MACBOOK_PRO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010064 STAC_922X_MODELS
65};
66
67enum {
68 STAC_D965_REF,
69 STAC_D965_3ST,
70 STAC_D965_5ST,
71 STAC_927X_MODELS
72};
Matt Porter403d1942005-11-29 15:00:51 +010073
Matt2f2f4252005-04-13 14:45:30 +020074struct sigmatel_spec {
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +010075 struct snd_kcontrol_new *mixers[4];
Mattc7d4b2f2005-06-27 14:59:41 +020076 unsigned int num_mixers;
77
Matt Porter403d1942005-11-29 15:00:51 +010078 int board_config;
Mattc7d4b2f2005-06-27 14:59:41 +020079 unsigned int surr_switch: 1;
Matt Porter403d1942005-11-29 15:00:51 +010080 unsigned int line_switch: 1;
81 unsigned int mic_switch: 1;
Matt Porter3cc08dc2006-01-23 15:27:49 +010082 unsigned int alt_switch: 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +010083 unsigned int hp_detect: 1;
Sam Revitch62fe78e2006-05-10 15:09:17 +020084 unsigned int gpio_mute: 1;
Mattc7d4b2f2005-06-27 14:59:41 +020085
Matt2f2f4252005-04-13 14:45:30 +020086 /* playback */
87 struct hda_multi_out multiout;
Matt Porter3cc08dc2006-01-23 15:27:49 +010088 hda_nid_t dac_nids[5];
Matt2f2f4252005-04-13 14:45:30 +020089
90 /* capture */
91 hda_nid_t *adc_nids;
Matt2f2f4252005-04-13 14:45:30 +020092 unsigned int num_adcs;
Mattdabbed62005-06-14 10:19:34 +020093 hda_nid_t *mux_nids;
94 unsigned int num_muxes;
Matt Porter8b657272006-10-26 17:12:59 +020095 hda_nid_t *dmic_nids;
96 unsigned int num_dmics;
97 hda_nid_t dmux_nid;
Mattdabbed62005-06-14 10:19:34 +020098 hda_nid_t dig_in_nid;
Matt2f2f4252005-04-13 14:45:30 +020099
Matt2f2f4252005-04-13 14:45:30 +0200100 /* pin widgets */
101 hda_nid_t *pin_nids;
102 unsigned int num_pins;
Matt2f2f4252005-04-13 14:45:30 +0200103 unsigned int *pin_configs;
Richard Fish11b44bb2006-08-23 18:31:34 +0200104 unsigned int *bios_pin_configs;
Matt2f2f4252005-04-13 14:45:30 +0200105
106 /* codec specific stuff */
107 struct hda_verb *init;
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100108 struct snd_kcontrol_new *mixer;
Matt2f2f4252005-04-13 14:45:30 +0200109
110 /* capture source */
Matt Porter8b657272006-10-26 17:12:59 +0200111 struct hda_input_mux *dinput_mux;
112 unsigned int cur_dmux;
Mattc7d4b2f2005-06-27 14:59:41 +0200113 struct hda_input_mux *input_mux;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100114 unsigned int cur_mux[3];
Matt2f2f4252005-04-13 14:45:30 +0200115
Matt Porter403d1942005-11-29 15:00:51 +0100116 /* i/o switches */
117 unsigned int io_switch[2];
Matt2f2f4252005-04-13 14:45:30 +0200118
Mattc7d4b2f2005-06-27 14:59:41 +0200119 struct hda_pcm pcm_rec[2]; /* PCM information */
120
121 /* dynamic controls and input_mux */
122 struct auto_pin_cfg autocfg;
123 unsigned int num_kctl_alloc, num_kctl_used;
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100124 struct snd_kcontrol_new *kctl_alloc;
Matt Porter8b657272006-10-26 17:12:59 +0200125 struct hda_input_mux private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +0200126 struct hda_input_mux private_imux;
Matt2f2f4252005-04-13 14:45:30 +0200127};
128
129static hda_nid_t stac9200_adc_nids[1] = {
130 0x03,
131};
132
133static hda_nid_t stac9200_mux_nids[1] = {
134 0x0c,
135};
136
137static hda_nid_t stac9200_dac_nids[1] = {
138 0x02,
139};
140
Tobin Davis8e21c342007-01-08 11:04:17 +0100141static hda_nid_t stac925x_adc_nids[1] = {
142 0x03,
143};
144
145static hda_nid_t stac925x_mux_nids[1] = {
146 0x0f,
147};
148
149static hda_nid_t stac925x_dac_nids[1] = {
150 0x02,
151};
152
Matt2f2f4252005-04-13 14:45:30 +0200153static hda_nid_t stac922x_adc_nids[2] = {
154 0x06, 0x07,
155};
156
157static hda_nid_t stac922x_mux_nids[2] = {
158 0x12, 0x13,
159};
160
Matt Porter3cc08dc2006-01-23 15:27:49 +0100161static hda_nid_t stac927x_adc_nids[3] = {
162 0x07, 0x08, 0x09
163};
164
165static hda_nid_t stac927x_mux_nids[3] = {
166 0x15, 0x16, 0x17
167};
168
Matt Porterf3302a52006-07-31 12:49:34 +0200169static hda_nid_t stac9205_adc_nids[2] = {
170 0x12, 0x13
171};
172
173static hda_nid_t stac9205_mux_nids[2] = {
174 0x19, 0x1a
175};
176
Matt Porter8b657272006-10-26 17:12:59 +0200177static hda_nid_t stac9205_dmic_nids[3] = {
178 0x17, 0x18, 0
179};
180
Mattc7d4b2f2005-06-27 14:59:41 +0200181static hda_nid_t stac9200_pin_nids[8] = {
Tobin Davis93ed1502006-09-01 21:03:12 +0200182 0x08, 0x09, 0x0d, 0x0e,
183 0x0f, 0x10, 0x11, 0x12,
Matt2f2f4252005-04-13 14:45:30 +0200184};
185
Tobin Davis8e21c342007-01-08 11:04:17 +0100186static hda_nid_t stac925x_pin_nids[8] = {
187 0x07, 0x08, 0x0a, 0x0b,
188 0x0c, 0x0d, 0x10, 0x11,
189};
190
Matt2f2f4252005-04-13 14:45:30 +0200191static hda_nid_t stac922x_pin_nids[10] = {
192 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
193 0x0f, 0x10, 0x11, 0x15, 0x1b,
194};
195
Matt Porter3cc08dc2006-01-23 15:27:49 +0100196static hda_nid_t stac927x_pin_nids[14] = {
197 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
198 0x0f, 0x10, 0x11, 0x12, 0x13,
199 0x14, 0x21, 0x22, 0x23,
200};
201
Matt Porterf3302a52006-07-31 12:49:34 +0200202static hda_nid_t stac9205_pin_nids[12] = {
203 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
204 0x0f, 0x14, 0x16, 0x17, 0x18,
205 0x21, 0x22,
206
207};
208
Matt Porter8b657272006-10-26 17:12:59 +0200209static int stac92xx_dmux_enum_info(struct snd_kcontrol *kcontrol,
210 struct snd_ctl_elem_info *uinfo)
211{
212 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
213 struct sigmatel_spec *spec = codec->spec;
214 return snd_hda_input_mux_info(spec->dinput_mux, uinfo);
215}
216
217static int stac92xx_dmux_enum_get(struct snd_kcontrol *kcontrol,
218 struct snd_ctl_elem_value *ucontrol)
219{
220 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
221 struct sigmatel_spec *spec = codec->spec;
222
223 ucontrol->value.enumerated.item[0] = spec->cur_dmux;
224 return 0;
225}
226
227static int stac92xx_dmux_enum_put(struct snd_kcontrol *kcontrol,
228 struct snd_ctl_elem_value *ucontrol)
229{
230 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
231 struct sigmatel_spec *spec = codec->spec;
232
233 return snd_hda_input_mux_put(codec, spec->dinput_mux, ucontrol,
234 spec->dmux_nid, &spec->cur_dmux);
235}
236
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100237static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Matt2f2f4252005-04-13 14:45:30 +0200238{
239 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
240 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +0200241 return snd_hda_input_mux_info(spec->input_mux, uinfo);
Matt2f2f4252005-04-13 14:45:30 +0200242}
243
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100244static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200245{
246 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
247 struct sigmatel_spec *spec = codec->spec;
248 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
249
250 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
251 return 0;
252}
253
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100254static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200255{
256 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
257 struct sigmatel_spec *spec = codec->spec;
258 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
259
Mattc7d4b2f2005-06-27 14:59:41 +0200260 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
Matt2f2f4252005-04-13 14:45:30 +0200261 spec->mux_nids[adc_idx], &spec->cur_mux[adc_idx]);
262}
263
Mattc7d4b2f2005-06-27 14:59:41 +0200264static struct hda_verb stac9200_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200265 /* set dac0mux for dac converter */
Mattc7d4b2f2005-06-27 14:59:41 +0200266 { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
Matt2f2f4252005-04-13 14:45:30 +0200267 {}
268};
269
Tobin Davis8e21c342007-01-08 11:04:17 +0100270static struct hda_verb stac925x_core_init[] = {
271 /* set dac0mux for dac converter */
272 { 0x06, AC_VERB_SET_CONNECT_SEL, 0x00},
273 {}
274};
275
Mattc7d4b2f2005-06-27 14:59:41 +0200276static struct hda_verb stac922x_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200277 /* set master volume and direct control */
Mattc7d4b2f2005-06-27 14:59:41 +0200278 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matt2f2f4252005-04-13 14:45:30 +0200279 {}
280};
281
Tobin Davis93ed1502006-09-01 21:03:12 +0200282static struct hda_verb d965_core_init[] = {
Takashi Iwai19039bd2006-06-28 15:52:16 +0200283 /* set master volume and direct control */
Tobin Davis93ed1502006-09-01 21:03:12 +0200284 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Takashi Iwai19039bd2006-06-28 15:52:16 +0200285 /* unmute node 0x1b */
286 { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
287 /* select node 0x03 as DAC */
288 { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
289 {}
290};
291
Matt Porter3cc08dc2006-01-23 15:27:49 +0100292static struct hda_verb stac927x_core_init[] = {
293 /* set master volume and direct control */
294 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
295 {}
296};
297
Matt Porterf3302a52006-07-31 12:49:34 +0200298static struct hda_verb stac9205_core_init[] = {
299 /* set master volume and direct control */
300 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
301 {}
302};
303
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100304static struct snd_kcontrol_new stac9200_mixer[] = {
Matt2f2f4252005-04-13 14:45:30 +0200305 HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
306 HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
307 {
308 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
309 .name = "Input Source",
310 .count = 1,
311 .info = stac92xx_mux_enum_info,
312 .get = stac92xx_mux_enum_get,
313 .put = stac92xx_mux_enum_put,
314 },
315 HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
316 HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
Mattc7d4b2f2005-06-27 14:59:41 +0200317 HDA_CODEC_VOLUME("Capture Mux Volume", 0x0c, 0, HDA_OUTPUT),
Matt2f2f4252005-04-13 14:45:30 +0200318 { } /* end */
319};
320
Tobin Davis8e21c342007-01-08 11:04:17 +0100321static struct snd_kcontrol_new stac925x_mixer[] = {
322 HDA_CODEC_VOLUME("Master Playback Volume", 0xe, 0, HDA_OUTPUT),
323 HDA_CODEC_MUTE("Master Playback Switch", 0xe, 0, HDA_OUTPUT),
324 {
325 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
326 .name = "Input Source",
327 .count = 1,
328 .info = stac92xx_mux_enum_info,
329 .get = stac92xx_mux_enum_get,
330 .put = stac92xx_mux_enum_put,
331 },
332 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_OUTPUT),
333 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_OUTPUT),
334 HDA_CODEC_VOLUME("Capture Mux Volume", 0x0f, 0, HDA_OUTPUT),
335 { } /* end */
336};
337
Mattc7d4b2f2005-06-27 14:59:41 +0200338/* This needs to be generated dynamically based on sequence */
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100339static struct snd_kcontrol_new stac922x_mixer[] = {
Matt2f2f4252005-04-13 14:45:30 +0200340 {
341 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
342 .name = "Input Source",
343 .count = 1,
344 .info = stac92xx_mux_enum_info,
345 .get = stac92xx_mux_enum_get,
346 .put = stac92xx_mux_enum_put,
347 },
348 HDA_CODEC_VOLUME("Capture Volume", 0x17, 0x0, HDA_INPUT),
Takashi Iwai0fd17082006-01-13 18:46:21 +0100349 HDA_CODEC_MUTE("Capture Switch", 0x17, 0x0, HDA_INPUT),
Matt2f2f4252005-04-13 14:45:30 +0200350 HDA_CODEC_VOLUME("Mux Capture Volume", 0x12, 0x0, HDA_OUTPUT),
351 { } /* end */
352};
353
Takashi Iwai19039bd2006-06-28 15:52:16 +0200354/* This needs to be generated dynamically based on sequence */
355static struct snd_kcontrol_new stac9227_mixer[] = {
356 {
357 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
358 .name = "Input Source",
359 .count = 1,
360 .info = stac92xx_mux_enum_info,
361 .get = stac92xx_mux_enum_get,
362 .put = stac92xx_mux_enum_put,
363 },
364 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
365 HDA_CODEC_MUTE("Capture Switch", 0x1b, 0x0, HDA_OUTPUT),
366 { } /* end */
367};
368
Takashi Iwaid1d985f2006-11-23 19:27:12 +0100369static struct snd_kcontrol_new stac927x_mixer[] = {
Matt Porter3cc08dc2006-01-23 15:27:49 +0100370 {
371 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
372 .name = "Input Source",
373 .count = 1,
374 .info = stac92xx_mux_enum_info,
375 .get = stac92xx_mux_enum_get,
376 .put = stac92xx_mux_enum_put,
377 },
378 HDA_CODEC_VOLUME("InMux Capture Volume", 0x15, 0x0, HDA_OUTPUT),
379 HDA_CODEC_VOLUME("InVol Capture Volume", 0x18, 0x0, HDA_INPUT),
380 HDA_CODEC_MUTE("ADCMux Capture Switch", 0x1b, 0x0, HDA_OUTPUT),
381 { } /* end */
382};
383
Takashi Iwaid1d985f2006-11-23 19:27:12 +0100384static struct snd_kcontrol_new stac9205_mixer[] = {
Matt Porterf3302a52006-07-31 12:49:34 +0200385 {
386 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Matt Porter8b657272006-10-26 17:12:59 +0200387 .name = "Digital Input Source",
388 .count = 1,
389 .info = stac92xx_dmux_enum_info,
390 .get = stac92xx_dmux_enum_get,
391 .put = stac92xx_dmux_enum_put,
392 },
393 {
394 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Matt Porterf3302a52006-07-31 12:49:34 +0200395 .name = "Input Source",
396 .count = 1,
397 .info = stac92xx_mux_enum_info,
398 .get = stac92xx_mux_enum_get,
399 .put = stac92xx_mux_enum_put,
400 },
401 HDA_CODEC_VOLUME("InMux Capture Volume", 0x19, 0x0, HDA_OUTPUT),
402 HDA_CODEC_VOLUME("InVol Capture Volume", 0x1b, 0x0, HDA_INPUT),
403 HDA_CODEC_MUTE("ADCMux Capture Switch", 0x1d, 0x0, HDA_OUTPUT),
404 { } /* end */
405};
406
Matt2f2f4252005-04-13 14:45:30 +0200407static int stac92xx_build_controls(struct hda_codec *codec)
408{
409 struct sigmatel_spec *spec = codec->spec;
410 int err;
Mattc7d4b2f2005-06-27 14:59:41 +0200411 int i;
Matt2f2f4252005-04-13 14:45:30 +0200412
413 err = snd_hda_add_new_ctls(codec, spec->mixer);
414 if (err < 0)
415 return err;
Mattc7d4b2f2005-06-27 14:59:41 +0200416
417 for (i = 0; i < spec->num_mixers; i++) {
418 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
419 if (err < 0)
420 return err;
421 }
422
Mattdabbed62005-06-14 10:19:34 +0200423 if (spec->multiout.dig_out_nid) {
424 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
425 if (err < 0)
426 return err;
427 }
428 if (spec->dig_in_nid) {
429 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
430 if (err < 0)
431 return err;
432 }
433 return 0;
Matt2f2f4252005-04-13 14:45:30 +0200434}
435
Matt Porter403d1942005-11-29 15:00:51 +0100436static unsigned int ref9200_pin_configs[8] = {
Mattdabbed62005-06-14 10:19:34 +0200437 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
Matt2f2f4252005-04-13 14:45:30 +0200438 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
439};
440
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100441static unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
442 [STAC_REF] = ref9200_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +0100443};
444
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100445static const char *stac9200_models[STAC_9200_MODELS] = {
446 [STAC_REF] = "ref",
447};
448
449static struct snd_pci_quirk stac9200_cfg_tbl[] = {
450 /* SigmaTel reference board */
451 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
452 "DFI LanParty", STAC_REF),
Matt Portere7377072006-11-06 11:20:38 +0100453 /* Dell laptops have BIOS problem */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100454 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01b5,
455 "Dell Inspiron 630m", STAC_REF),
456 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c2,
457 "Dell Latitude D620", STAC_REF),
458 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cb,
459 "Dell Latitude 120L", STAC_REF),
Cory T. Tusar877b8662007-01-30 17:30:55 +0100460 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cc,
461 "Dell Latitude D820", STAC_REF),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +0100462 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cd,
463 "Dell Inspiron E1705/9400", STAC_REF),
464 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ce,
465 "Dell XPS M1710", STAC_REF),
Takashi Iwaif0f96742007-02-14 00:59:17 +0100466 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cf,
467 "Dell Precision M90", STAC_REF),
Matt Porter403d1942005-11-29 15:00:51 +0100468 {} /* terminator */
469};
470
Tobin Davis8e21c342007-01-08 11:04:17 +0100471static unsigned int ref925x_pin_configs[8] = {
472 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
473 0x90a70320, 0x02214210, 0x400003f1, 0x9033032e,
474};
475
476static unsigned int stac925x_MA6_pin_configs[8] = {
477 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
478 0x90a70320, 0x90100211, 0x400003f1, 0x9033032e,
479};
480
481static unsigned int stac925xM2_2_pin_configs[8] = {
482 0x40c003f3, 0x424503f2, 0x041800f4, 0x02a19020,
483 0x50a103F0, 0x90100210, 0x400003f1, 0x9033032e,
484};
485
486static unsigned int *stac925x_brd_tbl[STAC_925x_MODELS] = {
487 [STAC_REF] = ref925x_pin_configs,
488 [STAC_M2_2] = stac925xM2_2_pin_configs,
489 [STAC_MA6] = stac925x_MA6_pin_configs,
490};
491
492static const char *stac925x_models[STAC_925x_MODELS] = {
493 [STAC_REF] = "ref",
494 [STAC_M2_2] = "m2-2",
495 [STAC_MA6] = "m6",
496};
497
498static struct snd_pci_quirk stac925x_cfg_tbl[] = {
499 /* SigmaTel reference board */
500 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, "DFI LanParty", STAC_REF),
501 SND_PCI_QUIRK(0x107b, 0x0316, "Gateway M255", STAC_REF),
502 SND_PCI_QUIRK(0x107b, 0x0366, "Gateway MP6954", STAC_REF),
503 SND_PCI_QUIRK(0x107b, 0x0461, "Gateway NX560XL", STAC_MA6),
504 SND_PCI_QUIRK(0x1002, 0x437b, "Gateway MX6453", STAC_M2_2),
505 {} /* terminator */
506};
507
Matt Porter403d1942005-11-29 15:00:51 +0100508static unsigned int ref922x_pin_configs[10] = {
509 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
510 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
Matt2f2f4252005-04-13 14:45:30 +0200511 0x40000100, 0x40000100,
512};
513
Matt Porter403d1942005-11-29 15:00:51 +0100514static unsigned int d945gtp3_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +0100515 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
Matt Porter403d1942005-11-29 15:00:51 +0100516 0x40000100, 0x40000100, 0x40000100, 0x40000100,
517 0x02a19120, 0x40000100,
518};
519
520static unsigned int d945gtp5_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +0100521 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
522 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
Matt Porter403d1942005-11-29 15:00:51 +0100523 0x02a19320, 0x40000100,
524};
525
Takashi Iwai3fc24d82007-02-16 13:27:18 +0100526static unsigned int macbook_pin_configs[10] = {
527 0x0321e230, 0x03a1e020, 0x400000fd, 0x9017e110,
528 0x400000fe, 0x0381e021, 0x1345e240, 0x13c5e22e,
529 0x400000fc, 0x400000fb,
530};
531
532static unsigned int macbook_pro_pin_configs[10] = {
533 0x0221401f, 0x90a70120, 0x01813024, 0x01014010,
534 0x400000fd, 0x01016011, 0x1345e240, 0x13c5e22e,
535 0x400000fc, 0x400000fb,
536};
537
Takashi Iwai19039bd2006-06-28 15:52:16 +0200538static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100539 [STAC_D945_REF] = ref922x_pin_configs,
Takashi Iwai19039bd2006-06-28 15:52:16 +0200540 [STAC_D945GTP3] = d945gtp3_pin_configs,
541 [STAC_D945GTP5] = d945gtp5_pin_configs,
Linus Torvalds7c3dec02006-07-10 22:21:43 -0700542 [STAC_MACMINI] = d945gtp5_pin_configs,
Takashi Iwai3fc24d82007-02-16 13:27:18 +0100543 [STAC_MACBOOK] = macbook_pin_configs,
544 [STAC_MACBOOK_PRO] = macbook_pro_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +0100545};
546
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100547static const char *stac922x_models[STAC_922X_MODELS] = {
548 [STAC_D945_REF] = "ref",
549 [STAC_D945GTP5] = "5stack",
550 [STAC_D945GTP3] = "3stack",
551 [STAC_MACMINI] = "macmini",
Takashi Iwai3fc24d82007-02-16 13:27:18 +0100552 [STAC_MACBOOK] = "macbook",
553 [STAC_MACBOOK_PRO] = "macbook-pro",
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100554};
555
556static struct snd_pci_quirk stac922x_cfg_tbl[] = {
557 /* SigmaTel reference board */
558 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
559 "DFI LanParty", STAC_D945_REF),
560 /* Intel 945G based systems */
561 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101,
562 "Intel D945G", STAC_D945GTP3),
563 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0202,
564 "Intel D945G", STAC_D945GTP3),
565 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0606,
566 "Intel D945G", STAC_D945GTP3),
567 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0601,
568 "Intel D945G", STAC_D945GTP3),
569 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0111,
570 "Intel D945G", STAC_D945GTP3),
571 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1115,
572 "Intel D945G", STAC_D945GTP3),
573 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1116,
574 "Intel D945G", STAC_D945GTP3),
575 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1117,
576 "Intel D945G", STAC_D945GTP3),
577 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1118,
578 "Intel D945G", STAC_D945GTP3),
579 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1119,
580 "Intel D945G", STAC_D945GTP3),
581 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x8826,
582 "Intel D945G", STAC_D945GTP3),
583 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5049,
584 "Intel D945G", STAC_D945GTP3),
585 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5055,
586 "Intel D945G", STAC_D945GTP3),
587 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5048,
588 "Intel D945G", STAC_D945GTP3),
589 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0110,
590 "Intel D945G", STAC_D945GTP3),
591 /* Intel D945G 5-stack systems */
592 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0404,
593 "Intel D945G", STAC_D945GTP5),
594 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0303,
595 "Intel D945G", STAC_D945GTP5),
596 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0013,
597 "Intel D945G", STAC_D945GTP5),
598 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0417,
599 "Intel D945G", STAC_D945GTP5),
600 /* Intel 945P based systems */
601 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0b0b,
602 "Intel D945P", STAC_D945GTP3),
603 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0112,
604 "Intel D945P", STAC_D945GTP3),
605 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0d0d,
606 "Intel D945P", STAC_D945GTP3),
607 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0909,
608 "Intel D945P", STAC_D945GTP3),
609 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0505,
610 "Intel D945P", STAC_D945GTP3),
611 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707,
612 "Intel D945P", STAC_D945GTP5),
613 /* other systems */
614 /* Apple Mac Mini (early 2006) */
615 SND_PCI_QUIRK(0x8384, 0x7680,
616 "Mac Mini", STAC_MACMINI),
Matt Porter403d1942005-11-29 15:00:51 +0100617 {} /* terminator */
618};
619
Matt Porter3cc08dc2006-01-23 15:27:49 +0100620static unsigned int ref927x_pin_configs[14] = {
Tobin Davis93ed1502006-09-01 21:03:12 +0200621 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
622 0x01a19040, 0x01011012, 0x01016011, 0x0101201f,
623 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
624 0x01c42190, 0x40000100,
Matt Porter3cc08dc2006-01-23 15:27:49 +0100625};
626
Tobin Davis93ed1502006-09-01 21:03:12 +0200627static unsigned int d965_3st_pin_configs[14] = {
Tobin Davis81d3dbd2006-08-22 19:44:45 +0200628 0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
629 0x01a19021, 0x01813024, 0x40000100, 0x40000100,
630 0x40000100, 0x40000100, 0x40000100, 0x40000100,
631 0x40000100, 0x40000100
632};
633
Tobin Davis93ed1502006-09-01 21:03:12 +0200634static unsigned int d965_5st_pin_configs[14] = {
635 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
636 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
637 0x40000100, 0x40000100, 0x40000100, 0x01442070,
638 0x40000100, 0x40000100
639};
640
641static unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100642 [STAC_D965_REF] = ref927x_pin_configs,
Tobin Davis93ed1502006-09-01 21:03:12 +0200643 [STAC_D965_3ST] = d965_3st_pin_configs,
644 [STAC_D965_5ST] = d965_5st_pin_configs,
Matt Porter3cc08dc2006-01-23 15:27:49 +0100645};
646
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100647static const char *stac927x_models[STAC_927X_MODELS] = {
648 [STAC_D965_REF] = "ref",
649 [STAC_D965_3ST] = "3stack",
650 [STAC_D965_5ST] = "5stack",
651};
652
653static struct snd_pci_quirk stac927x_cfg_tbl[] = {
654 /* SigmaTel reference board */
655 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
656 "DFI LanParty", STAC_D965_REF),
Tobin Davis81d3dbd2006-08-22 19:44:45 +0200657 /* Intel 946 based systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100658 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST),
659 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST),
Tobin Davis93ed1502006-09-01 21:03:12 +0200660 /* 965 based 3 stack systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100661 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2116, "Intel D965", STAC_D965_3ST),
662 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2115, "Intel D965", STAC_D965_3ST),
663 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2114, "Intel D965", STAC_D965_3ST),
664 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2113, "Intel D965", STAC_D965_3ST),
665 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2112, "Intel D965", STAC_D965_3ST),
666 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2111, "Intel D965", STAC_D965_3ST),
667 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2110, "Intel D965", STAC_D965_3ST),
668 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2009, "Intel D965", STAC_D965_3ST),
669 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2008, "Intel D965", STAC_D965_3ST),
670 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2007, "Intel D965", STAC_D965_3ST),
671 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2006, "Intel D965", STAC_D965_3ST),
672 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2005, "Intel D965", STAC_D965_3ST),
673 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2004, "Intel D965", STAC_D965_3ST),
674 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2003, "Intel D965", STAC_D965_3ST),
675 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2002, "Intel D965", STAC_D965_3ST),
676 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2001, "Intel D965", STAC_D965_3ST),
Tobin Davis93ed1502006-09-01 21:03:12 +0200677 /* 965 based 5 stack systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100678 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2301, "Intel D965", STAC_D965_5ST),
679 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2302, "Intel D965", STAC_D965_5ST),
680 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2303, "Intel D965", STAC_D965_5ST),
681 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2304, "Intel D965", STAC_D965_5ST),
682 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2305, "Intel D965", STAC_D965_5ST),
683 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2501, "Intel D965", STAC_D965_5ST),
684 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2502, "Intel D965", STAC_D965_5ST),
685 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2503, "Intel D965", STAC_D965_5ST),
686 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2504, "Intel D965", STAC_D965_5ST),
Matt Porter3cc08dc2006-01-23 15:27:49 +0100687 {} /* terminator */
688};
689
Matt Porterf3302a52006-07-31 12:49:34 +0200690static unsigned int ref9205_pin_configs[12] = {
691 0x40000100, 0x40000100, 0x01016011, 0x01014010,
Matt Porter8b657272006-10-26 17:12:59 +0200692 0x01813122, 0x01a19021, 0x40000100, 0x40000100,
693 0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
Matt Porterf3302a52006-07-31 12:49:34 +0200694};
695
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100696static unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
Matt Porterf3302a52006-07-31 12:49:34 +0200697 ref9205_pin_configs,
698};
699
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100700static const char *stac9205_models[STAC_9205_MODELS] = {
701 [STAC_9205_REF] = "ref",
702};
703
704static struct snd_pci_quirk stac9205_cfg_tbl[] = {
705 /* SigmaTel reference board */
706 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
707 "DFI LanParty", STAC_9205_REF),
Matt Porterf3302a52006-07-31 12:49:34 +0200708 {} /* terminator */
709};
710
Richard Fish11b44bb2006-08-23 18:31:34 +0200711static int stac92xx_save_bios_config_regs(struct hda_codec *codec)
712{
713 int i;
714 struct sigmatel_spec *spec = codec->spec;
715
716 if (! spec->bios_pin_configs) {
717 spec->bios_pin_configs = kcalloc(spec->num_pins,
718 sizeof(*spec->bios_pin_configs), GFP_KERNEL);
719 if (! spec->bios_pin_configs)
720 return -ENOMEM;
721 }
722
723 for (i = 0; i < spec->num_pins; i++) {
724 hda_nid_t nid = spec->pin_nids[i];
725 unsigned int pin_cfg;
726
727 pin_cfg = snd_hda_codec_read(codec, nid, 0,
728 AC_VERB_GET_CONFIG_DEFAULT, 0x00);
729 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x bios pin config %8.8x\n",
730 nid, pin_cfg);
731 spec->bios_pin_configs[i] = pin_cfg;
732 }
733
734 return 0;
735}
736
Matt2f2f4252005-04-13 14:45:30 +0200737static void stac92xx_set_config_regs(struct hda_codec *codec)
738{
739 int i;
740 struct sigmatel_spec *spec = codec->spec;
741 unsigned int pin_cfg;
742
Richard Fish11b44bb2006-08-23 18:31:34 +0200743 if (! spec->pin_nids || ! spec->pin_configs)
744 return;
745
746 for (i = 0; i < spec->num_pins; i++) {
Matt2f2f4252005-04-13 14:45:30 +0200747 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
748 AC_VERB_SET_CONFIG_DEFAULT_BYTES_0,
749 spec->pin_configs[i] & 0x000000ff);
750 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
751 AC_VERB_SET_CONFIG_DEFAULT_BYTES_1,
752 (spec->pin_configs[i] & 0x0000ff00) >> 8);
753 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
754 AC_VERB_SET_CONFIG_DEFAULT_BYTES_2,
755 (spec->pin_configs[i] & 0x00ff0000) >> 16);
756 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
757 AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
758 spec->pin_configs[i] >> 24);
759 pin_cfg = snd_hda_codec_read(codec, spec->pin_nids[i], 0,
760 AC_VERB_GET_CONFIG_DEFAULT,
761 0x00);
Matt Porter403d1942005-11-29 15:00:51 +0100762 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 +0200763 }
764}
Matt2f2f4252005-04-13 14:45:30 +0200765
Matt2f2f4252005-04-13 14:45:30 +0200766/*
767 * Analog playback callbacks
768 */
769static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
770 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100771 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200772{
773 struct sigmatel_spec *spec = codec->spec;
774 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
775}
776
777static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
778 struct hda_codec *codec,
779 unsigned int stream_tag,
780 unsigned int format,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100781 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200782{
783 struct sigmatel_spec *spec = codec->spec;
Matt Porter403d1942005-11-29 15:00:51 +0100784 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
Matt2f2f4252005-04-13 14:45:30 +0200785}
786
787static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
788 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100789 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200790{
791 struct sigmatel_spec *spec = codec->spec;
792 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
793}
794
795/*
Mattdabbed62005-06-14 10:19:34 +0200796 * Digital playback callbacks
797 */
798static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
799 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100800 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +0200801{
802 struct sigmatel_spec *spec = codec->spec;
803 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
804}
805
806static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
807 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100808 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +0200809{
810 struct sigmatel_spec *spec = codec->spec;
811 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
812}
813
814
815/*
Matt2f2f4252005-04-13 14:45:30 +0200816 * Analog capture callbacks
817 */
818static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
819 struct hda_codec *codec,
820 unsigned int stream_tag,
821 unsigned int format,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100822 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200823{
824 struct sigmatel_spec *spec = codec->spec;
825
826 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
827 stream_tag, 0, format);
828 return 0;
829}
830
831static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
832 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100833 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200834{
835 struct sigmatel_spec *spec = codec->spec;
836
837 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 0, 0, 0);
838 return 0;
839}
840
Mattdabbed62005-06-14 10:19:34 +0200841static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
842 .substreams = 1,
843 .channels_min = 2,
844 .channels_max = 2,
845 /* NID is set in stac92xx_build_pcms */
846 .ops = {
847 .open = stac92xx_dig_playback_pcm_open,
848 .close = stac92xx_dig_playback_pcm_close
849 },
850};
851
852static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
853 .substreams = 1,
854 .channels_min = 2,
855 .channels_max = 2,
856 /* NID is set in stac92xx_build_pcms */
857};
858
Matt2f2f4252005-04-13 14:45:30 +0200859static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
860 .substreams = 1,
861 .channels_min = 2,
Mattc7d4b2f2005-06-27 14:59:41 +0200862 .channels_max = 8,
Matt2f2f4252005-04-13 14:45:30 +0200863 .nid = 0x02, /* NID to query formats and rates */
864 .ops = {
865 .open = stac92xx_playback_pcm_open,
866 .prepare = stac92xx_playback_pcm_prepare,
867 .cleanup = stac92xx_playback_pcm_cleanup
868 },
869};
870
Matt Porter3cc08dc2006-01-23 15:27:49 +0100871static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
872 .substreams = 1,
873 .channels_min = 2,
874 .channels_max = 2,
875 .nid = 0x06, /* NID to query formats and rates */
876 .ops = {
877 .open = stac92xx_playback_pcm_open,
878 .prepare = stac92xx_playback_pcm_prepare,
879 .cleanup = stac92xx_playback_pcm_cleanup
880 },
881};
882
Matt2f2f4252005-04-13 14:45:30 +0200883static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
884 .substreams = 2,
885 .channels_min = 2,
886 .channels_max = 2,
Matt Porter3cc08dc2006-01-23 15:27:49 +0100887 /* NID is set in stac92xx_build_pcms */
Matt2f2f4252005-04-13 14:45:30 +0200888 .ops = {
889 .prepare = stac92xx_capture_pcm_prepare,
890 .cleanup = stac92xx_capture_pcm_cleanup
891 },
892};
893
894static int stac92xx_build_pcms(struct hda_codec *codec)
895{
896 struct sigmatel_spec *spec = codec->spec;
897 struct hda_pcm *info = spec->pcm_rec;
898
899 codec->num_pcms = 1;
900 codec->pcm_info = info;
901
Mattc7d4b2f2005-06-27 14:59:41 +0200902 info->name = "STAC92xx Analog";
Matt2f2f4252005-04-13 14:45:30 +0200903 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
Matt2f2f4252005-04-13 14:45:30 +0200904 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100905 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
906
907 if (spec->alt_switch) {
908 codec->num_pcms++;
909 info++;
910 info->name = "STAC92xx Analog Alt";
911 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
912 }
Matt2f2f4252005-04-13 14:45:30 +0200913
Mattdabbed62005-06-14 10:19:34 +0200914 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
915 codec->num_pcms++;
916 info++;
917 info->name = "STAC92xx Digital";
918 if (spec->multiout.dig_out_nid) {
919 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
920 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
921 }
922 if (spec->dig_in_nid) {
923 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
924 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
925 }
926 }
927
Matt2f2f4252005-04-13 14:45:30 +0200928 return 0;
929}
930
Takashi Iwaic960a032006-03-23 17:06:28 +0100931static unsigned int stac92xx_get_vref(struct hda_codec *codec, hda_nid_t nid)
932{
933 unsigned int pincap = snd_hda_param_read(codec, nid,
934 AC_PAR_PIN_CAP);
935 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
936 if (pincap & AC_PINCAP_VREF_100)
937 return AC_PINCTL_VREF_100;
938 if (pincap & AC_PINCAP_VREF_80)
939 return AC_PINCTL_VREF_80;
940 if (pincap & AC_PINCAP_VREF_50)
941 return AC_PINCTL_VREF_50;
942 if (pincap & AC_PINCAP_VREF_GRD)
943 return AC_PINCTL_VREF_GRD;
944 return 0;
945}
946
Matt Porter403d1942005-11-29 15:00:51 +0100947static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
948
949{
950 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
951}
952
953static int stac92xx_io_switch_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
954{
955 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
956 uinfo->count = 1;
957 uinfo->value.integer.min = 0;
958 uinfo->value.integer.max = 1;
959 return 0;
960}
961
962static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
963{
964 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
965 struct sigmatel_spec *spec = codec->spec;
966 int io_idx = kcontrol-> private_value & 0xff;
967
968 ucontrol->value.integer.value[0] = spec->io_switch[io_idx];
969 return 0;
970}
971
972static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
973{
974 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
975 struct sigmatel_spec *spec = codec->spec;
976 hda_nid_t nid = kcontrol->private_value >> 8;
977 int io_idx = kcontrol-> private_value & 0xff;
978 unsigned short val = ucontrol->value.integer.value[0];
979
980 spec->io_switch[io_idx] = val;
981
982 if (val)
983 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
Takashi Iwaic960a032006-03-23 17:06:28 +0100984 else {
985 unsigned int pinctl = AC_PINCTL_IN_EN;
986 if (io_idx) /* set VREF for mic */
987 pinctl |= stac92xx_get_vref(codec, nid);
988 stac92xx_auto_set_pinctl(codec, nid, pinctl);
989 }
Matt Porter403d1942005-11-29 15:00:51 +0100990 return 1;
991}
992
993#define STAC_CODEC_IO_SWITCH(xname, xpval) \
994 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
995 .name = xname, \
996 .index = 0, \
997 .info = stac92xx_io_switch_info, \
998 .get = stac92xx_io_switch_get, \
999 .put = stac92xx_io_switch_put, \
1000 .private_value = xpval, \
1001 }
1002
1003
Mattc7d4b2f2005-06-27 14:59:41 +02001004enum {
1005 STAC_CTL_WIDGET_VOL,
1006 STAC_CTL_WIDGET_MUTE,
Matt Porter403d1942005-11-29 15:00:51 +01001007 STAC_CTL_WIDGET_IO_SWITCH,
Mattc7d4b2f2005-06-27 14:59:41 +02001008};
1009
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01001010static struct snd_kcontrol_new stac92xx_control_templates[] = {
Mattc7d4b2f2005-06-27 14:59:41 +02001011 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
1012 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Matt Porter403d1942005-11-29 15:00:51 +01001013 STAC_CODEC_IO_SWITCH(NULL, 0),
Mattc7d4b2f2005-06-27 14:59:41 +02001014};
1015
1016/* add dynamic controls */
1017static int stac92xx_add_control(struct sigmatel_spec *spec, int type, const char *name, unsigned long val)
1018{
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01001019 struct snd_kcontrol_new *knew;
Mattc7d4b2f2005-06-27 14:59:41 +02001020
1021 if (spec->num_kctl_used >= spec->num_kctl_alloc) {
1022 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
1023
1024 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */
1025 if (! knew)
1026 return -ENOMEM;
1027 if (spec->kctl_alloc) {
1028 memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
1029 kfree(spec->kctl_alloc);
1030 }
1031 spec->kctl_alloc = knew;
1032 spec->num_kctl_alloc = num;
1033 }
1034
1035 knew = &spec->kctl_alloc[spec->num_kctl_used];
1036 *knew = stac92xx_control_templates[type];
Takashi Iwai82fe0c52005-06-30 10:54:33 +02001037 knew->name = kstrdup(name, GFP_KERNEL);
Mattc7d4b2f2005-06-27 14:59:41 +02001038 if (! knew->name)
1039 return -ENOMEM;
1040 knew->private_value = val;
1041 spec->num_kctl_used++;
1042 return 0;
1043}
1044
Matt Porter403d1942005-11-29 15:00:51 +01001045/* flag inputs as additional dynamic lineouts */
1046static int stac92xx_add_dyn_out_pins(struct hda_codec *codec, struct auto_pin_cfg *cfg)
1047{
1048 struct sigmatel_spec *spec = codec->spec;
1049
1050 switch (cfg->line_outs) {
1051 case 3:
1052 /* add line-in as side */
1053 if (cfg->input_pins[AUTO_PIN_LINE]) {
1054 cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_LINE];
1055 spec->line_switch = 1;
1056 cfg->line_outs++;
1057 }
1058 break;
1059 case 2:
1060 /* add line-in as clfe and mic as side */
1061 if (cfg->input_pins[AUTO_PIN_LINE]) {
1062 cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_LINE];
1063 spec->line_switch = 1;
1064 cfg->line_outs++;
1065 }
1066 if (cfg->input_pins[AUTO_PIN_MIC]) {
1067 cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_MIC];
1068 spec->mic_switch = 1;
1069 cfg->line_outs++;
1070 }
1071 break;
1072 case 1:
1073 /* add line-in as surr and mic as clfe */
1074 if (cfg->input_pins[AUTO_PIN_LINE]) {
1075 cfg->line_out_pins[1] = cfg->input_pins[AUTO_PIN_LINE];
1076 spec->line_switch = 1;
1077 cfg->line_outs++;
1078 }
1079 if (cfg->input_pins[AUTO_PIN_MIC]) {
1080 cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_MIC];
1081 spec->mic_switch = 1;
1082 cfg->line_outs++;
1083 }
1084 break;
1085 }
1086
1087 return 0;
1088}
1089
Matt Porter3cc08dc2006-01-23 15:27:49 +01001090/*
1091 * XXX The line_out pin widget connection list may not be set to the
1092 * desired DAC nid. This is the case on 927x where ports A and B can
1093 * be routed to several DACs.
1094 *
1095 * This requires an analysis of the line-out/hp pin configuration
1096 * to provide a best fit for pin/DAC configurations that are routable.
1097 * For now, 927x DAC4 is not supported and 927x DAC1 output to ports
1098 * A and B is not supported.
1099 */
Mattc7d4b2f2005-06-27 14:59:41 +02001100/* fill in the dac_nids table from the parsed pin configuration */
Takashi Iwai19039bd2006-06-28 15:52:16 +02001101static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec,
1102 const struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02001103{
1104 struct sigmatel_spec *spec = codec->spec;
1105 hda_nid_t nid;
1106 int i;
1107
1108 /* check the pins hardwired to audio widget */
1109 for (i = 0; i < cfg->line_outs; i++) {
1110 nid = cfg->line_out_pins[i];
1111 spec->multiout.dac_nids[i] = snd_hda_codec_read(codec, nid, 0,
1112 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
1113 }
1114
Takashi Iwai82bc9552006-03-21 11:24:42 +01001115 spec->multiout.num_dacs = cfg->line_outs;
Mattc7d4b2f2005-06-27 14:59:41 +02001116
1117 return 0;
1118}
1119
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001120/* create volume control/switch for the given prefx type */
1121static int create_controls(struct sigmatel_spec *spec, const char *pfx, hda_nid_t nid, int chs)
1122{
1123 char name[32];
1124 int err;
1125
1126 sprintf(name, "%s Playback Volume", pfx);
1127 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, name,
1128 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1129 if (err < 0)
1130 return err;
1131 sprintf(name, "%s Playback Switch", pfx);
1132 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, name,
1133 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1134 if (err < 0)
1135 return err;
1136 return 0;
1137}
1138
Mattc7d4b2f2005-06-27 14:59:41 +02001139/* add playback controls from the parsed DAC table */
Takashi Iwai19039bd2006-06-28 15:52:16 +02001140static int stac92xx_auto_create_multi_out_ctls(struct sigmatel_spec *spec,
1141 const struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02001142{
Takashi Iwai19039bd2006-06-28 15:52:16 +02001143 static const char *chname[4] = {
1144 "Front", "Surround", NULL /*CLFE*/, "Side"
1145 };
Mattc7d4b2f2005-06-27 14:59:41 +02001146 hda_nid_t nid;
1147 int i, err;
1148
1149 for (i = 0; i < cfg->line_outs; i++) {
Matt Porter403d1942005-11-29 15:00:51 +01001150 if (!spec->multiout.dac_nids[i])
Mattc7d4b2f2005-06-27 14:59:41 +02001151 continue;
1152
1153 nid = spec->multiout.dac_nids[i];
1154
1155 if (i == 2) {
1156 /* Center/LFE */
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001157 err = create_controls(spec, "Center", nid, 1);
1158 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001159 return err;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001160 err = create_controls(spec, "LFE", nid, 2);
1161 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001162 return err;
1163 } else {
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001164 err = create_controls(spec, chname[i], nid, 3);
1165 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001166 return err;
1167 }
1168 }
1169
Matt Porter403d1942005-11-29 15:00:51 +01001170 if (spec->line_switch)
1171 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Line In as Output Switch", cfg->input_pins[AUTO_PIN_LINE] << 8)) < 0)
1172 return err;
1173
1174 if (spec->mic_switch)
1175 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Mic as Output Switch", (cfg->input_pins[AUTO_PIN_MIC] << 8) | 1)) < 0)
1176 return err;
1177
Mattc7d4b2f2005-06-27 14:59:41 +02001178 return 0;
1179}
1180
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001181static int check_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
1182{
1183 int i;
1184
1185 for (i = 0; i < spec->multiout.num_dacs; i++) {
1186 if (spec->multiout.dac_nids[i] == nid)
1187 return 1;
1188 }
1189 if (spec->multiout.hp_nid == nid)
1190 return 1;
1191 return 0;
1192}
1193
1194static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
1195{
1196 if (!spec->multiout.hp_nid)
1197 spec->multiout.hp_nid = nid;
1198 else if (spec->multiout.num_dacs > 4) {
1199 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
1200 return 1;
1201 } else {
1202 spec->multiout.dac_nids[spec->multiout.num_dacs] = nid;
1203 spec->multiout.num_dacs++;
1204 }
1205 return 0;
1206}
1207
1208/* add playback controls for Speaker and HP outputs */
1209static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
1210 struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02001211{
1212 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02001213 hda_nid_t nid;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001214 int i, old_num_dacs, err;
Mattc7d4b2f2005-06-27 14:59:41 +02001215
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001216 old_num_dacs = spec->multiout.num_dacs;
1217 for (i = 0; i < cfg->hp_outs; i++) {
1218 unsigned int wid_caps = get_wcaps(codec, cfg->hp_pins[i]);
1219 if (wid_caps & AC_WCAP_UNSOL_CAP)
1220 spec->hp_detect = 1;
1221 nid = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
1222 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
1223 if (check_in_dac_nids(spec, nid))
1224 nid = 0;
1225 if (! nid)
Mattc7d4b2f2005-06-27 14:59:41 +02001226 continue;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001227 add_spec_dacs(spec, nid);
1228 }
1229 for (i = 0; i < cfg->speaker_outs; i++) {
1230 nid = snd_hda_codec_read(codec, cfg->speaker_pins[0], 0,
1231 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
1232 if (check_in_dac_nids(spec, nid))
1233 nid = 0;
1234 if (check_in_dac_nids(spec, nid))
1235 nid = 0;
1236 if (! nid)
1237 continue;
1238 add_spec_dacs(spec, nid);
Mattc7d4b2f2005-06-27 14:59:41 +02001239 }
1240
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001241 for (i = old_num_dacs; i < spec->multiout.num_dacs; i++) {
1242 static const char *pfxs[] = {
1243 "Speaker", "External Speaker", "Speaker2",
1244 };
1245 err = create_controls(spec, pfxs[i - old_num_dacs],
1246 spec->multiout.dac_nids[i], 3);
1247 if (err < 0)
1248 return err;
1249 }
1250 if (spec->multiout.hp_nid) {
1251 const char *pfx;
1252 if (old_num_dacs == spec->multiout.num_dacs)
1253 pfx = "Master";
1254 else
1255 pfx = "Headphone";
1256 err = create_controls(spec, pfx, spec->multiout.hp_nid, 3);
1257 if (err < 0)
1258 return err;
1259 }
Mattc7d4b2f2005-06-27 14:59:41 +02001260
1261 return 0;
1262}
1263
Matt Porter8b657272006-10-26 17:12:59 +02001264/* labels for dmic mux inputs */
Adrian Bunkddc2cec2006-11-20 12:03:44 +01001265static const char *stac92xx_dmic_labels[5] = {
Matt Porter8b657272006-10-26 17:12:59 +02001266 "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
1267 "Digital Mic 3", "Digital Mic 4"
1268};
1269
1270/* create playback/capture controls for input pins on dmic capable codecs */
1271static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
1272 const struct auto_pin_cfg *cfg)
1273{
1274 struct sigmatel_spec *spec = codec->spec;
1275 struct hda_input_mux *dimux = &spec->private_dimux;
1276 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
1277 int i, j;
1278
1279 dimux->items[dimux->num_items].label = stac92xx_dmic_labels[0];
1280 dimux->items[dimux->num_items].index = 0;
1281 dimux->num_items++;
1282
1283 for (i = 0; i < spec->num_dmics; i++) {
1284 int index;
1285 int num_cons;
1286 unsigned int def_conf;
1287
1288 def_conf = snd_hda_codec_read(codec,
1289 spec->dmic_nids[i],
1290 0,
1291 AC_VERB_GET_CONFIG_DEFAULT,
1292 0);
1293 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
1294 continue;
1295
1296 num_cons = snd_hda_get_connections(codec,
1297 spec->dmux_nid,
1298 con_lst,
1299 HDA_MAX_NUM_INPUTS);
1300 for (j = 0; j < num_cons; j++)
1301 if (con_lst[j] == spec->dmic_nids[i]) {
1302 index = j;
1303 goto found;
1304 }
1305 continue;
1306found:
1307 dimux->items[dimux->num_items].label =
1308 stac92xx_dmic_labels[dimux->num_items];
1309 dimux->items[dimux->num_items].index = index;
1310 dimux->num_items++;
1311 }
1312
1313 return 0;
1314}
1315
Mattc7d4b2f2005-06-27 14:59:41 +02001316/* create playback/capture controls for input pins */
1317static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
1318{
1319 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02001320 struct hda_input_mux *imux = &spec->private_imux;
1321 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
1322 int i, j, k;
1323
1324 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwai314634b2006-09-21 11:56:18 +02001325 int index;
Mattc7d4b2f2005-06-27 14:59:41 +02001326
Takashi Iwai314634b2006-09-21 11:56:18 +02001327 if (!cfg->input_pins[i])
1328 continue;
1329 index = -1;
1330 for (j = 0; j < spec->num_muxes; j++) {
1331 int num_cons;
1332 num_cons = snd_hda_get_connections(codec,
1333 spec->mux_nids[j],
1334 con_lst,
1335 HDA_MAX_NUM_INPUTS);
1336 for (k = 0; k < num_cons; k++)
1337 if (con_lst[k] == cfg->input_pins[i]) {
1338 index = k;
1339 goto found;
1340 }
Mattc7d4b2f2005-06-27 14:59:41 +02001341 }
Takashi Iwai314634b2006-09-21 11:56:18 +02001342 continue;
1343 found:
1344 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
1345 imux->items[imux->num_items].index = index;
1346 imux->num_items++;
Mattc7d4b2f2005-06-27 14:59:41 +02001347 }
1348
Sam Revitch62fe78e2006-05-10 15:09:17 +02001349 if (imux->num_items == 1) {
1350 /*
1351 * Set the current input for the muxes.
1352 * The STAC9221 has two input muxes with identical source
1353 * NID lists. Hopefully this won't get confused.
1354 */
1355 for (i = 0; i < spec->num_muxes; i++) {
1356 snd_hda_codec_write(codec, spec->mux_nids[i], 0,
1357 AC_VERB_SET_CONNECT_SEL,
1358 imux->items[0].index);
1359 }
1360 }
1361
Mattc7d4b2f2005-06-27 14:59:41 +02001362 return 0;
1363}
1364
Mattc7d4b2f2005-06-27 14:59:41 +02001365static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
1366{
1367 struct sigmatel_spec *spec = codec->spec;
1368 int i;
1369
1370 for (i = 0; i < spec->autocfg.line_outs; i++) {
1371 hda_nid_t nid = spec->autocfg.line_out_pins[i];
1372 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
1373 }
1374}
1375
1376static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
1377{
1378 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001379 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02001380
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001381 for (i = 0; i < spec->autocfg.hp_outs; i++) {
1382 hda_nid_t pin;
1383 pin = spec->autocfg.hp_pins[i];
1384 if (pin) /* connect to front */
1385 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
1386 }
1387 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
1388 hda_nid_t pin;
1389 pin = spec->autocfg.speaker_pins[i];
1390 if (pin) /* connect to front */
1391 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
1392 }
Mattc7d4b2f2005-06-27 14:59:41 +02001393}
1394
Matt Porter3cc08dc2006-01-23 15:27:49 +01001395static 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 +02001396{
1397 struct sigmatel_spec *spec = codec->spec;
1398 int err;
1399
Matt Porter8b657272006-10-26 17:12:59 +02001400 if ((err = snd_hda_parse_pin_def_config(codec,
1401 &spec->autocfg,
1402 spec->dmic_nids)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001403 return err;
Takashi Iwai82bc9552006-03-21 11:24:42 +01001404 if (! spec->autocfg.line_outs)
Matt Porter869264c2006-01-25 19:20:50 +01001405 return 0; /* can't find valid pin config */
Takashi Iwai19039bd2006-06-28 15:52:16 +02001406
Matt Porter403d1942005-11-29 15:00:51 +01001407 if ((err = stac92xx_add_dyn_out_pins(codec, &spec->autocfg)) < 0)
1408 return err;
Takashi Iwai19039bd2006-06-28 15:52:16 +02001409 if (spec->multiout.num_dacs == 0)
1410 if ((err = stac92xx_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
1411 return err;
Mattc7d4b2f2005-06-27 14:59:41 +02001412
1413 if ((err = stac92xx_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
1414 (err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg)) < 0 ||
1415 (err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
1416 return err;
1417
Matt Porter8b657272006-10-26 17:12:59 +02001418 if (spec->num_dmics > 0)
1419 if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
1420 &spec->autocfg)) < 0)
1421 return err;
1422
Mattc7d4b2f2005-06-27 14:59:41 +02001423 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Matt Porter403d1942005-11-29 15:00:51 +01001424 if (spec->multiout.max_channels > 2)
Mattc7d4b2f2005-06-27 14:59:41 +02001425 spec->surr_switch = 1;
Mattc7d4b2f2005-06-27 14:59:41 +02001426
Takashi Iwai82bc9552006-03-21 11:24:42 +01001427 if (spec->autocfg.dig_out_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01001428 spec->multiout.dig_out_nid = dig_out;
Takashi Iwai82bc9552006-03-21 11:24:42 +01001429 if (spec->autocfg.dig_in_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01001430 spec->dig_in_nid = dig_in;
Mattc7d4b2f2005-06-27 14:59:41 +02001431
1432 if (spec->kctl_alloc)
1433 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
1434
1435 spec->input_mux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02001436 spec->dinput_mux = &spec->private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +02001437
1438 return 1;
1439}
1440
Takashi Iwai82bc9552006-03-21 11:24:42 +01001441/* add playback controls for HP output */
1442static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
1443 struct auto_pin_cfg *cfg)
1444{
1445 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001446 hda_nid_t pin = cfg->hp_pins[0];
Takashi Iwai82bc9552006-03-21 11:24:42 +01001447 unsigned int wid_caps;
1448
1449 if (! pin)
1450 return 0;
1451
1452 wid_caps = get_wcaps(codec, pin);
Takashi Iwai505cb342006-03-27 12:51:52 +02001453 if (wid_caps & AC_WCAP_UNSOL_CAP)
Takashi Iwai82bc9552006-03-21 11:24:42 +01001454 spec->hp_detect = 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +01001455
1456 return 0;
1457}
1458
Richard Fish160ea0d2006-09-06 13:58:25 +02001459/* add playback controls for LFE output */
1460static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
1461 struct auto_pin_cfg *cfg)
1462{
1463 struct sigmatel_spec *spec = codec->spec;
1464 int err;
1465 hda_nid_t lfe_pin = 0x0;
1466 int i;
1467
1468 /*
1469 * search speaker outs and line outs for a mono speaker pin
1470 * with an amp. If one is found, add LFE controls
1471 * for it.
1472 */
1473 for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
1474 hda_nid_t pin = spec->autocfg.speaker_pins[i];
1475 unsigned long wcaps = get_wcaps(codec, pin);
1476 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
1477 if (wcaps == AC_WCAP_OUT_AMP)
1478 /* found a mono speaker with an amp, must be lfe */
1479 lfe_pin = pin;
1480 }
1481
1482 /* if speaker_outs is 0, then speakers may be in line_outs */
1483 if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
1484 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
1485 hda_nid_t pin = spec->autocfg.line_out_pins[i];
1486 unsigned long cfg;
1487 cfg = snd_hda_codec_read(codec, pin, 0,
1488 AC_VERB_GET_CONFIG_DEFAULT,
1489 0x00);
1490 if (get_defcfg_device(cfg) == AC_JACK_SPEAKER) {
1491 unsigned long wcaps = get_wcaps(codec, pin);
1492 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
1493 if (wcaps == AC_WCAP_OUT_AMP)
1494 /* found a mono speaker with an amp,
1495 must be lfe */
1496 lfe_pin = pin;
1497 }
1498 }
1499 }
1500
1501 if (lfe_pin) {
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001502 err = create_controls(spec, "LFE", lfe_pin, 1);
Richard Fish160ea0d2006-09-06 13:58:25 +02001503 if (err < 0)
1504 return err;
1505 }
1506
1507 return 0;
1508}
1509
Mattc7d4b2f2005-06-27 14:59:41 +02001510static int stac9200_parse_auto_config(struct hda_codec *codec)
1511{
1512 struct sigmatel_spec *spec = codec->spec;
1513 int err;
1514
Kailang Yangdf694da2005-12-05 19:42:22 +01001515 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001516 return err;
1517
1518 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
1519 return err;
1520
Takashi Iwai82bc9552006-03-21 11:24:42 +01001521 if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
1522 return err;
1523
Richard Fish160ea0d2006-09-06 13:58:25 +02001524 if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
1525 return err;
1526
Takashi Iwai82bc9552006-03-21 11:24:42 +01001527 if (spec->autocfg.dig_out_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02001528 spec->multiout.dig_out_nid = 0x05;
Takashi Iwai82bc9552006-03-21 11:24:42 +01001529 if (spec->autocfg.dig_in_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02001530 spec->dig_in_nid = 0x04;
Mattc7d4b2f2005-06-27 14:59:41 +02001531
1532 if (spec->kctl_alloc)
1533 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
1534
1535 spec->input_mux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02001536 spec->dinput_mux = &spec->private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +02001537
1538 return 1;
1539}
1540
Sam Revitch62fe78e2006-05-10 15:09:17 +02001541/*
1542 * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
1543 * funky external mute control using GPIO pins.
1544 */
1545
1546static void stac922x_gpio_mute(struct hda_codec *codec, int pin, int muted)
1547{
1548 unsigned int gpiostate, gpiomask, gpiodir;
1549
1550 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
1551 AC_VERB_GET_GPIO_DATA, 0);
1552
1553 if (!muted)
1554 gpiostate |= (1 << pin);
1555 else
1556 gpiostate &= ~(1 << pin);
1557
1558 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
1559 AC_VERB_GET_GPIO_MASK, 0);
1560 gpiomask |= (1 << pin);
1561
1562 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
1563 AC_VERB_GET_GPIO_DIRECTION, 0);
1564 gpiodir |= (1 << pin);
1565
1566 /* AppleHDA seems to do this -- WTF is this verb?? */
1567 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
1568
1569 snd_hda_codec_write(codec, codec->afg, 0,
1570 AC_VERB_SET_GPIO_MASK, gpiomask);
1571 snd_hda_codec_write(codec, codec->afg, 0,
1572 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
1573
1574 msleep(1);
1575
1576 snd_hda_codec_write(codec, codec->afg, 0,
1577 AC_VERB_SET_GPIO_DATA, gpiostate);
1578}
1579
Takashi Iwai314634b2006-09-21 11:56:18 +02001580static void enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
1581 unsigned int event)
1582{
1583 if (get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP)
1584 snd_hda_codec_write(codec, nid, 0,
1585 AC_VERB_SET_UNSOLICITED_ENABLE,
1586 (AC_USRSP_EN | event));
1587}
1588
Mattc7d4b2f2005-06-27 14:59:41 +02001589static int stac92xx_init(struct hda_codec *codec)
1590{
1591 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai82bc9552006-03-21 11:24:42 +01001592 struct auto_pin_cfg *cfg = &spec->autocfg;
1593 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02001594
Mattc7d4b2f2005-06-27 14:59:41 +02001595 snd_hda_sequence_write(codec, spec->init);
1596
Takashi Iwai82bc9552006-03-21 11:24:42 +01001597 /* set up pins */
1598 if (spec->hp_detect) {
Takashi Iwai505cb342006-03-27 12:51:52 +02001599 /* Enable unsolicited responses on the HP widget */
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001600 for (i = 0; i < cfg->hp_outs; i++)
Takashi Iwai314634b2006-09-21 11:56:18 +02001601 enable_pin_detect(codec, cfg->hp_pins[i],
1602 STAC_HP_EVENT);
Takashi Iwaieb995a82006-09-21 14:28:21 +02001603 stac92xx_auto_init_hp_out(codec);
Takashi Iwai82bc9552006-03-21 11:24:42 +01001604 /* fake event to set up pins */
1605 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
1606 } else {
1607 stac92xx_auto_init_multi_out(codec);
1608 stac92xx_auto_init_hp_out(codec);
1609 }
1610 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwaic960a032006-03-23 17:06:28 +01001611 hda_nid_t nid = cfg->input_pins[i];
1612 if (nid) {
1613 unsigned int pinctl = AC_PINCTL_IN_EN;
1614 if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC)
1615 pinctl |= stac92xx_get_vref(codec, nid);
1616 stac92xx_auto_set_pinctl(codec, nid, pinctl);
1617 }
Takashi Iwai82bc9552006-03-21 11:24:42 +01001618 }
Matt Porter8b657272006-10-26 17:12:59 +02001619 if (spec->num_dmics > 0)
1620 for (i = 0; i < spec->num_dmics; i++)
1621 stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
1622 AC_PINCTL_IN_EN);
1623
Takashi Iwai82bc9552006-03-21 11:24:42 +01001624 if (cfg->dig_out_pin)
1625 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pin,
1626 AC_PINCTL_OUT_EN);
1627 if (cfg->dig_in_pin)
1628 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
1629 AC_PINCTL_IN_EN);
1630
Sam Revitch62fe78e2006-05-10 15:09:17 +02001631 if (spec->gpio_mute) {
1632 stac922x_gpio_mute(codec, 0, 0);
1633 stac922x_gpio_mute(codec, 1, 0);
1634 }
1635
Mattc7d4b2f2005-06-27 14:59:41 +02001636 return 0;
1637}
1638
Matt2f2f4252005-04-13 14:45:30 +02001639static void stac92xx_free(struct hda_codec *codec)
1640{
Mattc7d4b2f2005-06-27 14:59:41 +02001641 struct sigmatel_spec *spec = codec->spec;
1642 int i;
1643
1644 if (! spec)
1645 return;
1646
1647 if (spec->kctl_alloc) {
1648 for (i = 0; i < spec->num_kctl_used; i++)
1649 kfree(spec->kctl_alloc[i].name);
1650 kfree(spec->kctl_alloc);
1651 }
1652
Richard Fish11b44bb2006-08-23 18:31:34 +02001653 if (spec->bios_pin_configs)
1654 kfree(spec->bios_pin_configs);
1655
Mattc7d4b2f2005-06-27 14:59:41 +02001656 kfree(spec);
Matt2f2f4252005-04-13 14:45:30 +02001657}
1658
Matt4e550962005-07-04 17:51:39 +02001659static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
1660 unsigned int flag)
1661{
1662 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
1663 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Takashi Iwai314634b2006-09-21 11:56:18 +02001664 if (flag == AC_PINCTL_OUT_EN && (pin_ctl & AC_PINCTL_IN_EN))
1665 return;
Matt4e550962005-07-04 17:51:39 +02001666 snd_hda_codec_write(codec, nid, 0,
1667 AC_VERB_SET_PIN_WIDGET_CONTROL,
1668 pin_ctl | flag);
1669}
1670
1671static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
1672 unsigned int flag)
1673{
1674 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
1675 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
1676 snd_hda_codec_write(codec, nid, 0,
1677 AC_VERB_SET_PIN_WIDGET_CONTROL,
1678 pin_ctl & ~flag);
1679}
1680
Takashi Iwai314634b2006-09-21 11:56:18 +02001681static int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
1682{
1683 if (!nid)
1684 return 0;
1685 if (snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PIN_SENSE, 0x00)
1686 & (1 << 31))
1687 return 1;
1688 return 0;
1689}
1690
1691static void stac92xx_hp_detect(struct hda_codec *codec, unsigned int res)
Matt4e550962005-07-04 17:51:39 +02001692{
1693 struct sigmatel_spec *spec = codec->spec;
1694 struct auto_pin_cfg *cfg = &spec->autocfg;
1695 int i, presence;
1696
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001697 presence = 0;
1698 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai314634b2006-09-21 11:56:18 +02001699 presence = get_pin_presence(codec, cfg->hp_pins[i]);
1700 if (presence)
1701 break;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001702 }
Matt4e550962005-07-04 17:51:39 +02001703
1704 if (presence) {
1705 /* disable lineouts, enable hp */
1706 for (i = 0; i < cfg->line_outs; i++)
1707 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
1708 AC_PINCTL_OUT_EN);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001709 for (i = 0; i < cfg->speaker_outs; i++)
1710 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
1711 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02001712 } else {
1713 /* enable lineouts, disable hp */
1714 for (i = 0; i < cfg->line_outs; i++)
1715 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
1716 AC_PINCTL_OUT_EN);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001717 for (i = 0; i < cfg->speaker_outs; i++)
1718 stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
1719 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02001720 }
1721}
1722
Takashi Iwai314634b2006-09-21 11:56:18 +02001723static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
1724{
1725 switch (res >> 26) {
1726 case STAC_HP_EVENT:
1727 stac92xx_hp_detect(codec, res);
1728 break;
1729 }
1730}
1731
Mattff6fdc32005-06-27 15:06:52 +02001732#ifdef CONFIG_PM
1733static int stac92xx_resume(struct hda_codec *codec)
1734{
1735 struct sigmatel_spec *spec = codec->spec;
1736 int i;
1737
1738 stac92xx_init(codec);
Richard Fish11b44bb2006-08-23 18:31:34 +02001739 stac92xx_set_config_regs(codec);
Mattff6fdc32005-06-27 15:06:52 +02001740 for (i = 0; i < spec->num_mixers; i++)
1741 snd_hda_resume_ctls(codec, spec->mixers[i]);
1742 if (spec->multiout.dig_out_nid)
1743 snd_hda_resume_spdif_out(codec);
1744 if (spec->dig_in_nid)
1745 snd_hda_resume_spdif_in(codec);
1746
1747 return 0;
1748}
1749#endif
1750
Matt2f2f4252005-04-13 14:45:30 +02001751static struct hda_codec_ops stac92xx_patch_ops = {
1752 .build_controls = stac92xx_build_controls,
1753 .build_pcms = stac92xx_build_pcms,
1754 .init = stac92xx_init,
1755 .free = stac92xx_free,
Matt4e550962005-07-04 17:51:39 +02001756 .unsol_event = stac92xx_unsol_event,
Mattff6fdc32005-06-27 15:06:52 +02001757#ifdef CONFIG_PM
1758 .resume = stac92xx_resume,
1759#endif
Matt2f2f4252005-04-13 14:45:30 +02001760};
1761
1762static int patch_stac9200(struct hda_codec *codec)
1763{
1764 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02001765 int err;
Matt2f2f4252005-04-13 14:45:30 +02001766
Takashi Iwaie560d8d2005-09-09 14:21:46 +02001767 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02001768 if (spec == NULL)
1769 return -ENOMEM;
1770
1771 codec->spec = spec;
Richard Fish11b44bb2006-08-23 18:31:34 +02001772 spec->num_pins = 8;
1773 spec->pin_nids = stac9200_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001774 spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS,
1775 stac9200_models,
1776 stac9200_cfg_tbl);
Richard Fish11b44bb2006-08-23 18:31:34 +02001777 if (spec->board_config < 0) {
1778 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9200, using BIOS defaults\n");
1779 err = stac92xx_save_bios_config_regs(codec);
1780 if (err < 0) {
1781 stac92xx_free(codec);
1782 return err;
1783 }
1784 spec->pin_configs = spec->bios_pin_configs;
1785 } else {
Matt Porter403d1942005-11-29 15:00:51 +01001786 spec->pin_configs = stac9200_brd_tbl[spec->board_config];
1787 stac92xx_set_config_regs(codec);
1788 }
Matt2f2f4252005-04-13 14:45:30 +02001789
1790 spec->multiout.max_channels = 2;
1791 spec->multiout.num_dacs = 1;
1792 spec->multiout.dac_nids = stac9200_dac_nids;
1793 spec->adc_nids = stac9200_adc_nids;
1794 spec->mux_nids = stac9200_mux_nids;
Mattdabbed62005-06-14 10:19:34 +02001795 spec->num_muxes = 1;
Matt Porter8b657272006-10-26 17:12:59 +02001796 spec->num_dmics = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02001797
1798 spec->init = stac9200_core_init;
Matt2f2f4252005-04-13 14:45:30 +02001799 spec->mixer = stac9200_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02001800
1801 err = stac9200_parse_auto_config(codec);
1802 if (err < 0) {
1803 stac92xx_free(codec);
1804 return err;
1805 }
Matt2f2f4252005-04-13 14:45:30 +02001806
1807 codec->patch_ops = stac92xx_patch_ops;
1808
1809 return 0;
1810}
1811
Tobin Davis8e21c342007-01-08 11:04:17 +01001812static int patch_stac925x(struct hda_codec *codec)
1813{
1814 struct sigmatel_spec *spec;
1815 int err;
1816
1817 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1818 if (spec == NULL)
1819 return -ENOMEM;
1820
1821 codec->spec = spec;
1822 spec->num_pins = 8;
1823 spec->pin_nids = stac925x_pin_nids;
1824 spec->board_config = snd_hda_check_board_config(codec, STAC_925x_MODELS,
1825 stac925x_models,
1826 stac925x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01001827 again:
Tobin Davis8e21c342007-01-08 11:04:17 +01001828 if (spec->board_config < 0) {
1829 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC925x, using BIOS defaults\n");
1830 err = stac92xx_save_bios_config_regs(codec);
1831 if (err < 0) {
1832 stac92xx_free(codec);
1833 return err;
1834 }
1835 spec->pin_configs = spec->bios_pin_configs;
1836 } else if (stac925x_brd_tbl[spec->board_config] != NULL){
1837 spec->pin_configs = stac925x_brd_tbl[spec->board_config];
1838 stac92xx_set_config_regs(codec);
1839 }
1840
1841 spec->multiout.max_channels = 2;
1842 spec->multiout.num_dacs = 1;
1843 spec->multiout.dac_nids = stac925x_dac_nids;
1844 spec->adc_nids = stac925x_adc_nids;
1845 spec->mux_nids = stac925x_mux_nids;
1846 spec->num_muxes = 1;
1847 spec->num_dmics = 0;
1848
1849 spec->init = stac925x_core_init;
1850 spec->mixer = stac925x_mixer;
1851
1852 err = stac92xx_parse_auto_config(codec, 0x8, 0x7);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01001853 if (!err) {
1854 if (spec->board_config < 0) {
1855 printk(KERN_WARNING "hda_codec: No auto-config is "
1856 "available, default to model=ref\n");
1857 spec->board_config = STAC_925x_REF;
1858 goto again;
1859 }
1860 err = -EINVAL;
1861 }
Tobin Davis8e21c342007-01-08 11:04:17 +01001862 if (err < 0) {
1863 stac92xx_free(codec);
1864 return err;
1865 }
1866
1867 codec->patch_ops = stac92xx_patch_ops;
1868
1869 return 0;
1870}
1871
Matt2f2f4252005-04-13 14:45:30 +02001872static int patch_stac922x(struct hda_codec *codec)
1873{
1874 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02001875 int err;
Matt2f2f4252005-04-13 14:45:30 +02001876
Takashi Iwaie560d8d2005-09-09 14:21:46 +02001877 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02001878 if (spec == NULL)
1879 return -ENOMEM;
1880
1881 codec->spec = spec;
Richard Fish11b44bb2006-08-23 18:31:34 +02001882 spec->num_pins = 10;
1883 spec->pin_nids = stac922x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001884 spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS,
1885 stac922x_models,
1886 stac922x_cfg_tbl);
Takashi Iwai3fc24d82007-02-16 13:27:18 +01001887 if (spec->board_config == STAC_MACMINI) {
1888 spec->gpio_mute = 1;
1889 /* Intel Macs have all same PCI SSID, so we need to check
1890 * codec SSID to distinguish the exact models
1891 */
1892 switch (codec->subsystem_id) {
1893 case 0x106b1e00:
1894 spec->board_config = STAC_MACBOOK_PRO;
1895 break;
1896 }
1897 }
1898
Takashi Iwai9e507ab2007-02-08 17:50:10 +01001899 again:
Richard Fish11b44bb2006-08-23 18:31:34 +02001900 if (spec->board_config < 0) {
1901 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC922x, "
1902 "using BIOS defaults\n");
1903 err = stac92xx_save_bios_config_regs(codec);
1904 if (err < 0) {
1905 stac92xx_free(codec);
1906 return err;
1907 }
1908 spec->pin_configs = spec->bios_pin_configs;
1909 } else if (stac922x_brd_tbl[spec->board_config] != NULL) {
Matt Porter403d1942005-11-29 15:00:51 +01001910 spec->pin_configs = stac922x_brd_tbl[spec->board_config];
1911 stac92xx_set_config_regs(codec);
1912 }
Matt2f2f4252005-04-13 14:45:30 +02001913
Matt2f2f4252005-04-13 14:45:30 +02001914 spec->adc_nids = stac922x_adc_nids;
1915 spec->mux_nids = stac922x_mux_nids;
Mattdabbed62005-06-14 10:19:34 +02001916 spec->num_muxes = 2;
Matt Porter8b657272006-10-26 17:12:59 +02001917 spec->num_dmics = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02001918
1919 spec->init = stac922x_core_init;
Matt2f2f4252005-04-13 14:45:30 +02001920 spec->mixer = stac922x_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02001921
1922 spec->multiout.dac_nids = spec->dac_nids;
Takashi Iwai19039bd2006-06-28 15:52:16 +02001923
Matt Porter3cc08dc2006-01-23 15:27:49 +01001924 err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01001925 if (!err) {
1926 if (spec->board_config < 0) {
1927 printk(KERN_WARNING "hda_codec: No auto-config is "
1928 "available, default to model=ref\n");
1929 spec->board_config = STAC_D945_REF;
1930 goto again;
1931 }
1932 err = -EINVAL;
1933 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01001934 if (err < 0) {
1935 stac92xx_free(codec);
1936 return err;
1937 }
1938
1939 codec->patch_ops = stac92xx_patch_ops;
1940
1941 return 0;
1942}
1943
1944static int patch_stac927x(struct hda_codec *codec)
1945{
1946 struct sigmatel_spec *spec;
1947 int err;
1948
1949 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1950 if (spec == NULL)
1951 return -ENOMEM;
1952
1953 codec->spec = spec;
Richard Fish11b44bb2006-08-23 18:31:34 +02001954 spec->num_pins = 14;
1955 spec->pin_nids = stac927x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001956 spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS,
1957 stac927x_models,
1958 stac927x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01001959 again:
Richard Fish11b44bb2006-08-23 18:31:34 +02001960 if (spec->board_config < 0) {
Matt Porter3cc08dc2006-01-23 15:27:49 +01001961 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC927x, using BIOS defaults\n");
Richard Fish11b44bb2006-08-23 18:31:34 +02001962 err = stac92xx_save_bios_config_regs(codec);
1963 if (err < 0) {
1964 stac92xx_free(codec);
1965 return err;
1966 }
1967 spec->pin_configs = spec->bios_pin_configs;
1968 } else if (stac927x_brd_tbl[spec->board_config] != NULL) {
Matt Porter3cc08dc2006-01-23 15:27:49 +01001969 spec->pin_configs = stac927x_brd_tbl[spec->board_config];
1970 stac92xx_set_config_regs(codec);
1971 }
1972
Tobin Davis81d3dbd2006-08-22 19:44:45 +02001973 switch (spec->board_config) {
Tobin Davis93ed1502006-09-01 21:03:12 +02001974 case STAC_D965_3ST:
Tobin Davis81d3dbd2006-08-22 19:44:45 +02001975 spec->adc_nids = stac927x_adc_nids;
1976 spec->mux_nids = stac927x_mux_nids;
1977 spec->num_muxes = 3;
Matt Porter8b657272006-10-26 17:12:59 +02001978 spec->num_dmics = 0;
Tobin Davis93ed1502006-09-01 21:03:12 +02001979 spec->init = d965_core_init;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02001980 spec->mixer = stac9227_mixer;
1981 break;
Tobin Davis93ed1502006-09-01 21:03:12 +02001982 case STAC_D965_5ST:
1983 spec->adc_nids = stac927x_adc_nids;
1984 spec->mux_nids = stac927x_mux_nids;
1985 spec->num_muxes = 3;
Matt Porter8b657272006-10-26 17:12:59 +02001986 spec->num_dmics = 0;
Tobin Davis93ed1502006-09-01 21:03:12 +02001987 spec->init = d965_core_init;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02001988 spec->mixer = stac9227_mixer;
1989 break;
1990 default:
1991 spec->adc_nids = stac927x_adc_nids;
1992 spec->mux_nids = stac927x_mux_nids;
1993 spec->num_muxes = 3;
Matt Porter8b657272006-10-26 17:12:59 +02001994 spec->num_dmics = 0;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02001995 spec->init = stac927x_core_init;
1996 spec->mixer = stac927x_mixer;
1997 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01001998
1999 spec->multiout.dac_nids = spec->dac_nids;
2000
2001 err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002002 if (!err) {
2003 if (spec->board_config < 0) {
2004 printk(KERN_WARNING "hda_codec: No auto-config is "
2005 "available, default to model=ref\n");
2006 spec->board_config = STAC_D965_REF;
2007 goto again;
2008 }
2009 err = -EINVAL;
2010 }
Mattc7d4b2f2005-06-27 14:59:41 +02002011 if (err < 0) {
2012 stac92xx_free(codec);
2013 return err;
2014 }
Matt2f2f4252005-04-13 14:45:30 +02002015
2016 codec->patch_ops = stac92xx_patch_ops;
2017
2018 return 0;
2019}
2020
Matt Porterf3302a52006-07-31 12:49:34 +02002021static int patch_stac9205(struct hda_codec *codec)
2022{
2023 struct sigmatel_spec *spec;
2024 int err;
2025
2026 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2027 if (spec == NULL)
2028 return -ENOMEM;
2029
2030 codec->spec = spec;
Richard Fish11b44bb2006-08-23 18:31:34 +02002031 spec->num_pins = 14;
2032 spec->pin_nids = stac9205_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002033 spec->board_config = snd_hda_check_board_config(codec, STAC_9205_MODELS,
2034 stac9205_models,
2035 stac9205_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002036 again:
Richard Fish11b44bb2006-08-23 18:31:34 +02002037 if (spec->board_config < 0) {
2038 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9205, using BIOS defaults\n");
2039 err = stac92xx_save_bios_config_regs(codec);
2040 if (err < 0) {
2041 stac92xx_free(codec);
2042 return err;
2043 }
2044 spec->pin_configs = spec->bios_pin_configs;
2045 } else {
Matt Porterf3302a52006-07-31 12:49:34 +02002046 spec->pin_configs = stac9205_brd_tbl[spec->board_config];
2047 stac92xx_set_config_regs(codec);
2048 }
2049
2050 spec->adc_nids = stac9205_adc_nids;
2051 spec->mux_nids = stac9205_mux_nids;
Matt Porter8b657272006-10-26 17:12:59 +02002052 spec->num_muxes = 2;
2053 spec->dmic_nids = stac9205_dmic_nids;
2054 spec->num_dmics = 2;
2055 spec->dmux_nid = 0x1d;
Matt Porterf3302a52006-07-31 12:49:34 +02002056
2057 spec->init = stac9205_core_init;
2058 spec->mixer = stac9205_mixer;
2059
2060 spec->multiout.dac_nids = spec->dac_nids;
2061
Matt Porter33382402006-12-18 13:17:28 +01002062 /* Configure GPIO0 as EAPD output */
2063 snd_hda_codec_write(codec, codec->afg, 0,
2064 AC_VERB_SET_GPIO_DIRECTION, 0x00000001);
2065 /* Configure GPIO0 as CMOS */
2066 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0x00000000);
2067 /* Assert GPIO0 high */
2068 snd_hda_codec_write(codec, codec->afg, 0,
2069 AC_VERB_SET_GPIO_DATA, 0x00000001);
2070 /* Enable GPIO0 */
2071 snd_hda_codec_write(codec, codec->afg, 0,
2072 AC_VERB_SET_GPIO_MASK, 0x00000001);
2073
Matt Porterf3302a52006-07-31 12:49:34 +02002074 err = stac92xx_parse_auto_config(codec, 0x1f, 0x20);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002075 if (!err) {
2076 if (spec->board_config < 0) {
2077 printk(KERN_WARNING "hda_codec: No auto-config is "
2078 "available, default to model=ref\n");
2079 spec->board_config = STAC_9205_REF;
2080 goto again;
2081 }
2082 err = -EINVAL;
2083 }
Matt Porterf3302a52006-07-31 12:49:34 +02002084 if (err < 0) {
2085 stac92xx_free(codec);
2086 return err;
2087 }
2088
2089 codec->patch_ops = stac92xx_patch_ops;
2090
2091 return 0;
2092}
2093
Matt2f2f4252005-04-13 14:45:30 +02002094/*
Guillaume Munch6d859062006-08-22 17:15:47 +02002095 * STAC9872 hack
Takashi Iwaidb064e52006-03-16 16:04:58 +01002096 */
2097
Guillaume Munch99ccc562006-08-16 19:35:12 +02002098/* static config for Sony VAIO FE550G and Sony VAIO AR */
Takashi Iwaidb064e52006-03-16 16:04:58 +01002099static hda_nid_t vaio_dacs[] = { 0x2 };
2100#define VAIO_HP_DAC 0x5
2101static hda_nid_t vaio_adcs[] = { 0x8 /*,0x6*/ };
2102static hda_nid_t vaio_mux_nids[] = { 0x15 };
2103
2104static struct hda_input_mux vaio_mux = {
2105 .num_items = 2,
2106 .items = {
Takashi Iwaid7737812006-04-25 13:05:43 +02002107 /* { "HP", 0x0 }, */
2108 { "Line", 0x1 },
Takashi Iwaidb064e52006-03-16 16:04:58 +01002109 { "Mic", 0x2 },
2110 { "PCM", 0x3 },
2111 }
2112};
2113
2114static struct hda_verb vaio_init[] = {
2115 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
2116 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
2117 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
2118 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
2119 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
2120 {0x15, AC_VERB_SET_CONNECT_SEL, 0x2}, /* mic-sel: 0a,0d,14,02 */
2121 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
2122 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
2123 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
2124 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
2125 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
2126 {}
2127};
2128
Guillaume Munch6d859062006-08-22 17:15:47 +02002129static struct hda_verb vaio_ar_init[] = {
2130 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
2131 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
2132 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
2133 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
2134/* {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },*/ /* Optical Out */
2135 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
2136 {0x15, AC_VERB_SET_CONNECT_SEL, 0x2}, /* mic-sel: 0a,0d,14,02 */
2137 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
2138 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
2139/* {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},*/ /* Optical Out */
2140 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
2141 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
2142 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
2143 {}
2144};
2145
Takashi Iwaidb064e52006-03-16 16:04:58 +01002146/* bind volumes of both NID 0x02 and 0x05 */
2147static int vaio_master_vol_put(struct snd_kcontrol *kcontrol,
2148 struct snd_ctl_elem_value *ucontrol)
2149{
2150 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2151 long *valp = ucontrol->value.integer.value;
2152 int change;
2153
2154 change = snd_hda_codec_amp_update(codec, 0x02, 0, HDA_OUTPUT, 0,
2155 0x7f, valp[0] & 0x7f);
2156 change |= snd_hda_codec_amp_update(codec, 0x02, 1, HDA_OUTPUT, 0,
2157 0x7f, valp[1] & 0x7f);
2158 snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
2159 0x7f, valp[0] & 0x7f);
2160 snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
2161 0x7f, valp[1] & 0x7f);
2162 return change;
2163}
2164
2165/* bind volumes of both NID 0x02 and 0x05 */
2166static int vaio_master_sw_put(struct snd_kcontrol *kcontrol,
2167 struct snd_ctl_elem_value *ucontrol)
2168{
2169 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2170 long *valp = ucontrol->value.integer.value;
2171 int change;
2172
2173 change = snd_hda_codec_amp_update(codec, 0x02, 0, HDA_OUTPUT, 0,
Takashi Iwaia9393d72006-05-03 11:59:03 +02002174 0x80, (valp[0] ? 0 : 0x80));
Takashi Iwaidb064e52006-03-16 16:04:58 +01002175 change |= snd_hda_codec_amp_update(codec, 0x02, 1, HDA_OUTPUT, 0,
Takashi Iwaia9393d72006-05-03 11:59:03 +02002176 0x80, (valp[1] ? 0 : 0x80));
Takashi Iwaidb064e52006-03-16 16:04:58 +01002177 snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
Takashi Iwaia9393d72006-05-03 11:59:03 +02002178 0x80, (valp[0] ? 0 : 0x80));
Takashi Iwaidb064e52006-03-16 16:04:58 +01002179 snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
Takashi Iwaia9393d72006-05-03 11:59:03 +02002180 0x80, (valp[1] ? 0 : 0x80));
Takashi Iwaidb064e52006-03-16 16:04:58 +01002181 return change;
2182}
2183
2184static struct snd_kcontrol_new vaio_mixer[] = {
2185 {
2186 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2187 .name = "Master Playback Volume",
2188 .info = snd_hda_mixer_amp_volume_info,
2189 .get = snd_hda_mixer_amp_volume_get,
2190 .put = vaio_master_vol_put,
Takashi Iwaic2566522006-08-17 18:21:36 +02002191 .tlv = { .c = snd_hda_mixer_amp_tlv },
Takashi Iwaidb064e52006-03-16 16:04:58 +01002192 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2193 },
2194 {
2195 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2196 .name = "Master Playback Switch",
2197 .info = snd_hda_mixer_amp_switch_info,
2198 .get = snd_hda_mixer_amp_switch_get,
2199 .put = vaio_master_sw_put,
2200 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2201 },
2202 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
2203 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
2204 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
2205 {
2206 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2207 .name = "Capture Source",
2208 .count = 1,
2209 .info = stac92xx_mux_enum_info,
2210 .get = stac92xx_mux_enum_get,
2211 .put = stac92xx_mux_enum_put,
2212 },
2213 {}
2214};
2215
Guillaume Munch6d859062006-08-22 17:15:47 +02002216static struct snd_kcontrol_new vaio_ar_mixer[] = {
2217 {
2218 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2219 .name = "Master Playback Volume",
2220 .info = snd_hda_mixer_amp_volume_info,
2221 .get = snd_hda_mixer_amp_volume_get,
2222 .put = vaio_master_vol_put,
2223 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2224 },
2225 {
2226 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2227 .name = "Master Playback Switch",
2228 .info = snd_hda_mixer_amp_switch_info,
2229 .get = snd_hda_mixer_amp_switch_get,
2230 .put = vaio_master_sw_put,
2231 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2232 },
2233 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
2234 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
2235 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
2236 /*HDA_CODEC_MUTE("Optical Out Switch", 0x10, 0, HDA_OUTPUT),
2237 HDA_CODEC_VOLUME("Optical Out Volume", 0x10, 0, HDA_OUTPUT),*/
2238 {
2239 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2240 .name = "Capture Source",
2241 .count = 1,
2242 .info = stac92xx_mux_enum_info,
2243 .get = stac92xx_mux_enum_get,
2244 .put = stac92xx_mux_enum_put,
2245 },
2246 {}
2247};
2248
2249static struct hda_codec_ops stac9872_patch_ops = {
Takashi Iwaidb064e52006-03-16 16:04:58 +01002250 .build_controls = stac92xx_build_controls,
2251 .build_pcms = stac92xx_build_pcms,
2252 .init = stac92xx_init,
2253 .free = stac92xx_free,
2254#ifdef CONFIG_PM
2255 .resume = stac92xx_resume,
2256#endif
2257};
2258
Guillaume Munch6d859062006-08-22 17:15:47 +02002259enum { /* FE and SZ series. id=0x83847661 and subsys=0x104D0700 or 104D1000. */
2260 CXD9872RD_VAIO,
2261 /* Unknown. id=0x83847662 and subsys=0x104D1200 or 104D1000. */
2262 STAC9872AK_VAIO,
2263 /* Unknown. id=0x83847661 and subsys=0x104D1200. */
2264 STAC9872K_VAIO,
2265 /* AR Series. id=0x83847664 and subsys=104D1300 */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002266 CXD9872AKD_VAIO,
2267 STAC_9872_MODELS,
2268};
Takashi Iwaidb064e52006-03-16 16:04:58 +01002269
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002270static const char *stac9872_models[STAC_9872_MODELS] = {
2271 [CXD9872RD_VAIO] = "vaio",
2272 [CXD9872AKD_VAIO] = "vaio-ar",
2273};
2274
2275static struct snd_pci_quirk stac9872_cfg_tbl[] = {
2276 SND_PCI_QUIRK(0x104d, 0x81e6, "Sony VAIO F/S", CXD9872RD_VAIO),
2277 SND_PCI_QUIRK(0x104d, 0x81ef, "Sony VAIO F/S", CXD9872RD_VAIO),
2278 SND_PCI_QUIRK(0x104d, 0x81fd, "Sony VAIO AR", CXD9872AKD_VAIO),
Takashi Iwaidb064e52006-03-16 16:04:58 +01002279 {}
2280};
2281
Guillaume Munch6d859062006-08-22 17:15:47 +02002282static int patch_stac9872(struct hda_codec *codec)
Takashi Iwaidb064e52006-03-16 16:04:58 +01002283{
2284 struct sigmatel_spec *spec;
2285 int board_config;
2286
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002287 board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
2288 stac9872_models,
2289 stac9872_cfg_tbl);
Takashi Iwaidb064e52006-03-16 16:04:58 +01002290 if (board_config < 0)
2291 /* unknown config, let generic-parser do its job... */
2292 return snd_hda_parse_generic_codec(codec);
2293
2294 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2295 if (spec == NULL)
2296 return -ENOMEM;
2297
2298 codec->spec = spec;
2299 switch (board_config) {
Guillaume Munch6d859062006-08-22 17:15:47 +02002300 case CXD9872RD_VAIO:
2301 case STAC9872AK_VAIO:
2302 case STAC9872K_VAIO:
Takashi Iwaidb064e52006-03-16 16:04:58 +01002303 spec->mixer = vaio_mixer;
2304 spec->init = vaio_init;
2305 spec->multiout.max_channels = 2;
2306 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
2307 spec->multiout.dac_nids = vaio_dacs;
2308 spec->multiout.hp_nid = VAIO_HP_DAC;
2309 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
2310 spec->adc_nids = vaio_adcs;
2311 spec->input_mux = &vaio_mux;
2312 spec->mux_nids = vaio_mux_nids;
2313 break;
Guillaume Munch6d859062006-08-22 17:15:47 +02002314
2315 case CXD9872AKD_VAIO:
2316 spec->mixer = vaio_ar_mixer;
2317 spec->init = vaio_ar_init;
2318 spec->multiout.max_channels = 2;
2319 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
2320 spec->multiout.dac_nids = vaio_dacs;
2321 spec->multiout.hp_nid = VAIO_HP_DAC;
2322 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
2323 spec->adc_nids = vaio_adcs;
2324 spec->input_mux = &vaio_mux;
2325 spec->mux_nids = vaio_mux_nids;
2326 break;
Takashi Iwaidb064e52006-03-16 16:04:58 +01002327 }
2328
Guillaume Munch6d859062006-08-22 17:15:47 +02002329 codec->patch_ops = stac9872_patch_ops;
Takashi Iwaidb064e52006-03-16 16:04:58 +01002330 return 0;
2331}
2332
2333
2334/*
Matt2f2f4252005-04-13 14:45:30 +02002335 * patch entries
2336 */
2337struct hda_codec_preset snd_hda_preset_sigmatel[] = {
2338 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
2339 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
2340 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
2341 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
2342 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
2343 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
2344 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
Matt Porter22a27c72006-07-06 18:49:10 +02002345 { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
2346 { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
2347 { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
2348 { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
2349 { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
2350 { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
Matt Porter3cc08dc2006-01-23 15:27:49 +01002351 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
2352 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
2353 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
2354 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
2355 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
2356 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
2357 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
2358 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
2359 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
2360 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
Tobin Davis8e21c342007-01-08 11:04:17 +01002361 { .id = 0x83847632, .name = "STAC9202", .patch = patch_stac925x },
2362 { .id = 0x83847633, .name = "STAC9202D", .patch = patch_stac925x },
2363 { .id = 0x83847634, .name = "STAC9250", .patch = patch_stac925x },
2364 { .id = 0x83847635, .name = "STAC9250D", .patch = patch_stac925x },
2365 { .id = 0x83847636, .name = "STAC9251", .patch = patch_stac925x },
2366 { .id = 0x83847637, .name = "STAC9250D", .patch = patch_stac925x },
Guillaume Munch6d859062006-08-22 17:15:47 +02002367 /* The following does not take into account .id=0x83847661 when subsys =
2368 * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
2369 * currently not fully supported.
2370 */
2371 { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
2372 { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
2373 { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
Matt Porterf3302a52006-07-31 12:49:34 +02002374 { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
2375 { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
2376 { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
2377 { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
2378 { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
2379 { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
2380 { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
2381 { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
Matt2f2f4252005-04-13 14:45:30 +02002382 {} /* terminator */
2383};