blob: ab6d42207814b2f05dbb449986d8e17b91888782 [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,
Nicolas Boichat6f0778d2007-03-15 12:38:15 +010063 STAC_MACBOOK_PRO_V1,
64 STAC_MACBOOK_PRO_V2,
Sylvain FORETf16928f2007-04-27 14:22:36 +020065 STAC_IMAC_INTEL,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010066 STAC_922X_MODELS
67};
68
69enum {
70 STAC_D965_REF,
71 STAC_D965_3ST,
72 STAC_D965_5ST,
73 STAC_927X_MODELS
74};
Matt Porter403d1942005-11-29 15:00:51 +010075
Matt2f2f4252005-04-13 14:45:30 +020076struct sigmatel_spec {
Takashi Iwaic8b6bf92005-11-17 14:57:47 +010077 struct snd_kcontrol_new *mixers[4];
Mattc7d4b2f2005-06-27 14:59:41 +020078 unsigned int num_mixers;
79
Matt Porter403d1942005-11-29 15:00:51 +010080 int board_config;
Mattc7d4b2f2005-06-27 14:59:41 +020081 unsigned int surr_switch: 1;
Matt Porter403d1942005-11-29 15:00:51 +010082 unsigned int line_switch: 1;
83 unsigned int mic_switch: 1;
Matt Porter3cc08dc2006-01-23 15:27:49 +010084 unsigned int alt_switch: 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +010085 unsigned int hp_detect: 1;
Sam Revitch62fe78e2006-05-10 15:09:17 +020086 unsigned int gpio_mute: 1;
Mattc7d4b2f2005-06-27 14:59:41 +020087
Matt2f2f4252005-04-13 14:45:30 +020088 /* playback */
89 struct hda_multi_out multiout;
Matt Porter3cc08dc2006-01-23 15:27:49 +010090 hda_nid_t dac_nids[5];
Matt2f2f4252005-04-13 14:45:30 +020091
92 /* capture */
93 hda_nid_t *adc_nids;
Matt2f2f4252005-04-13 14:45:30 +020094 unsigned int num_adcs;
Mattdabbed62005-06-14 10:19:34 +020095 hda_nid_t *mux_nids;
96 unsigned int num_muxes;
Matt Porter8b657272006-10-26 17:12:59 +020097 hda_nid_t *dmic_nids;
98 unsigned int num_dmics;
99 hda_nid_t dmux_nid;
Mattdabbed62005-06-14 10:19:34 +0200100 hda_nid_t dig_in_nid;
Matt2f2f4252005-04-13 14:45:30 +0200101
Matt2f2f4252005-04-13 14:45:30 +0200102 /* pin widgets */
103 hda_nid_t *pin_nids;
104 unsigned int num_pins;
Matt2f2f4252005-04-13 14:45:30 +0200105 unsigned int *pin_configs;
Richard Fish11b44bb2006-08-23 18:31:34 +0200106 unsigned int *bios_pin_configs;
Matt2f2f4252005-04-13 14:45:30 +0200107
108 /* codec specific stuff */
109 struct hda_verb *init;
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100110 struct snd_kcontrol_new *mixer;
Matt2f2f4252005-04-13 14:45:30 +0200111
112 /* capture source */
Matt Porter8b657272006-10-26 17:12:59 +0200113 struct hda_input_mux *dinput_mux;
114 unsigned int cur_dmux;
Mattc7d4b2f2005-06-27 14:59:41 +0200115 struct hda_input_mux *input_mux;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100116 unsigned int cur_mux[3];
Matt2f2f4252005-04-13 14:45:30 +0200117
Matt Porter403d1942005-11-29 15:00:51 +0100118 /* i/o switches */
119 unsigned int io_switch[2];
Matt2f2f4252005-04-13 14:45:30 +0200120
Mattc7d4b2f2005-06-27 14:59:41 +0200121 struct hda_pcm pcm_rec[2]; /* PCM information */
122
123 /* dynamic controls and input_mux */
124 struct auto_pin_cfg autocfg;
125 unsigned int num_kctl_alloc, num_kctl_used;
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100126 struct snd_kcontrol_new *kctl_alloc;
Matt Porter8b657272006-10-26 17:12:59 +0200127 struct hda_input_mux private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +0200128 struct hda_input_mux private_imux;
Matt2f2f4252005-04-13 14:45:30 +0200129};
130
131static hda_nid_t stac9200_adc_nids[1] = {
132 0x03,
133};
134
135static hda_nid_t stac9200_mux_nids[1] = {
136 0x0c,
137};
138
139static hda_nid_t stac9200_dac_nids[1] = {
140 0x02,
141};
142
Tobin Davis8e21c342007-01-08 11:04:17 +0100143static hda_nid_t stac925x_adc_nids[1] = {
144 0x03,
145};
146
147static hda_nid_t stac925x_mux_nids[1] = {
148 0x0f,
149};
150
151static hda_nid_t stac925x_dac_nids[1] = {
152 0x02,
153};
154
Matt2f2f4252005-04-13 14:45:30 +0200155static hda_nid_t stac922x_adc_nids[2] = {
156 0x06, 0x07,
157};
158
159static hda_nid_t stac922x_mux_nids[2] = {
160 0x12, 0x13,
161};
162
Matt Porter3cc08dc2006-01-23 15:27:49 +0100163static hda_nid_t stac927x_adc_nids[3] = {
164 0x07, 0x08, 0x09
165};
166
167static hda_nid_t stac927x_mux_nids[3] = {
168 0x15, 0x16, 0x17
169};
170
Matt Porterf3302a52006-07-31 12:49:34 +0200171static hda_nid_t stac9205_adc_nids[2] = {
172 0x12, 0x13
173};
174
175static hda_nid_t stac9205_mux_nids[2] = {
176 0x19, 0x1a
177};
178
Takashi Iwai25494132007-03-12 12:36:16 +0100179static hda_nid_t stac9205_dmic_nids[2] = {
180 0x17, 0x18,
Matt Porter8b657272006-10-26 17:12:59 +0200181};
182
Mattc7d4b2f2005-06-27 14:59:41 +0200183static hda_nid_t stac9200_pin_nids[8] = {
Tobin Davis93ed1502006-09-01 21:03:12 +0200184 0x08, 0x09, 0x0d, 0x0e,
185 0x0f, 0x10, 0x11, 0x12,
Matt2f2f4252005-04-13 14:45:30 +0200186};
187
Tobin Davis8e21c342007-01-08 11:04:17 +0100188static hda_nid_t stac925x_pin_nids[8] = {
189 0x07, 0x08, 0x0a, 0x0b,
190 0x0c, 0x0d, 0x10, 0x11,
191};
192
Matt2f2f4252005-04-13 14:45:30 +0200193static hda_nid_t stac922x_pin_nids[10] = {
194 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
195 0x0f, 0x10, 0x11, 0x15, 0x1b,
196};
197
Matt Porter3cc08dc2006-01-23 15:27:49 +0100198static hda_nid_t stac927x_pin_nids[14] = {
199 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
200 0x0f, 0x10, 0x11, 0x12, 0x13,
201 0x14, 0x21, 0x22, 0x23,
202};
203
Matt Porterf3302a52006-07-31 12:49:34 +0200204static hda_nid_t stac9205_pin_nids[12] = {
205 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
206 0x0f, 0x14, 0x16, 0x17, 0x18,
207 0x21, 0x22,
208
209};
210
Matt Porter8b657272006-10-26 17:12:59 +0200211static int stac92xx_dmux_enum_info(struct snd_kcontrol *kcontrol,
212 struct snd_ctl_elem_info *uinfo)
213{
214 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
215 struct sigmatel_spec *spec = codec->spec;
216 return snd_hda_input_mux_info(spec->dinput_mux, uinfo);
217}
218
219static int stac92xx_dmux_enum_get(struct snd_kcontrol *kcontrol,
220 struct snd_ctl_elem_value *ucontrol)
221{
222 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
223 struct sigmatel_spec *spec = codec->spec;
224
225 ucontrol->value.enumerated.item[0] = spec->cur_dmux;
226 return 0;
227}
228
229static int stac92xx_dmux_enum_put(struct snd_kcontrol *kcontrol,
230 struct snd_ctl_elem_value *ucontrol)
231{
232 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
233 struct sigmatel_spec *spec = codec->spec;
234
235 return snd_hda_input_mux_put(codec, spec->dinput_mux, ucontrol,
236 spec->dmux_nid, &spec->cur_dmux);
237}
238
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100239static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Matt2f2f4252005-04-13 14:45:30 +0200240{
241 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
242 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +0200243 return snd_hda_input_mux_info(spec->input_mux, uinfo);
Matt2f2f4252005-04-13 14:45:30 +0200244}
245
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100246static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200247{
248 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
249 struct sigmatel_spec *spec = codec->spec;
250 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
251
252 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
253 return 0;
254}
255
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100256static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200257{
258 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
259 struct sigmatel_spec *spec = codec->spec;
260 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
261
Mattc7d4b2f2005-06-27 14:59:41 +0200262 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
Matt2f2f4252005-04-13 14:45:30 +0200263 spec->mux_nids[adc_idx], &spec->cur_mux[adc_idx]);
264}
265
Mattc7d4b2f2005-06-27 14:59:41 +0200266static struct hda_verb stac9200_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200267 /* set dac0mux for dac converter */
Mattc7d4b2f2005-06-27 14:59:41 +0200268 { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
Matt2f2f4252005-04-13 14:45:30 +0200269 {}
270};
271
Tobin Davis8e21c342007-01-08 11:04:17 +0100272static struct hda_verb stac925x_core_init[] = {
273 /* set dac0mux for dac converter */
274 { 0x06, AC_VERB_SET_CONNECT_SEL, 0x00},
275 {}
276};
277
Mattc7d4b2f2005-06-27 14:59:41 +0200278static struct hda_verb stac922x_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200279 /* set master volume and direct control */
Mattc7d4b2f2005-06-27 14:59:41 +0200280 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matt2f2f4252005-04-13 14:45:30 +0200281 {}
282};
283
Tobin Davis93ed1502006-09-01 21:03:12 +0200284static struct hda_verb d965_core_init[] = {
Takashi Iwai19039bd2006-06-28 15:52:16 +0200285 /* set master volume and direct control */
Tobin Davis93ed1502006-09-01 21:03:12 +0200286 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Takashi Iwai19039bd2006-06-28 15:52:16 +0200287 /* unmute node 0x1b */
288 { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
289 /* select node 0x03 as DAC */
290 { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
291 {}
292};
293
Matt Porter3cc08dc2006-01-23 15:27:49 +0100294static struct hda_verb stac927x_core_init[] = {
295 /* set master volume and direct control */
296 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
297 {}
298};
299
Matt Porterf3302a52006-07-31 12:49:34 +0200300static struct hda_verb stac9205_core_init[] = {
301 /* set master volume and direct control */
302 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
303 {}
304};
305
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100306static struct snd_kcontrol_new stac9200_mixer[] = {
Matt2f2f4252005-04-13 14:45:30 +0200307 HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
308 HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
309 {
310 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
311 .name = "Input Source",
312 .count = 1,
313 .info = stac92xx_mux_enum_info,
314 .get = stac92xx_mux_enum_get,
315 .put = stac92xx_mux_enum_put,
316 },
317 HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
318 HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
Mattc7d4b2f2005-06-27 14:59:41 +0200319 HDA_CODEC_VOLUME("Capture Mux Volume", 0x0c, 0, HDA_OUTPUT),
Matt2f2f4252005-04-13 14:45:30 +0200320 { } /* end */
321};
322
Tobin Davis8e21c342007-01-08 11:04:17 +0100323static struct snd_kcontrol_new stac925x_mixer[] = {
324 HDA_CODEC_VOLUME("Master Playback Volume", 0xe, 0, HDA_OUTPUT),
325 HDA_CODEC_MUTE("Master Playback Switch", 0xe, 0, HDA_OUTPUT),
326 {
327 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
328 .name = "Input Source",
329 .count = 1,
330 .info = stac92xx_mux_enum_info,
331 .get = stac92xx_mux_enum_get,
332 .put = stac92xx_mux_enum_put,
333 },
334 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_OUTPUT),
335 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_OUTPUT),
336 HDA_CODEC_VOLUME("Capture Mux Volume", 0x0f, 0, HDA_OUTPUT),
337 { } /* end */
338};
339
Mattc7d4b2f2005-06-27 14:59:41 +0200340/* This needs to be generated dynamically based on sequence */
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100341static struct snd_kcontrol_new stac922x_mixer[] = {
Matt2f2f4252005-04-13 14:45:30 +0200342 {
343 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
344 .name = "Input Source",
345 .count = 1,
346 .info = stac92xx_mux_enum_info,
347 .get = stac92xx_mux_enum_get,
348 .put = stac92xx_mux_enum_put,
349 },
350 HDA_CODEC_VOLUME("Capture Volume", 0x17, 0x0, HDA_INPUT),
Takashi Iwai0fd17082006-01-13 18:46:21 +0100351 HDA_CODEC_MUTE("Capture Switch", 0x17, 0x0, HDA_INPUT),
Matt2f2f4252005-04-13 14:45:30 +0200352 HDA_CODEC_VOLUME("Mux Capture Volume", 0x12, 0x0, HDA_OUTPUT),
353 { } /* end */
354};
355
Takashi Iwai19039bd2006-06-28 15:52:16 +0200356/* This needs to be generated dynamically based on sequence */
357static struct snd_kcontrol_new stac9227_mixer[] = {
358 {
359 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
360 .name = "Input Source",
361 .count = 1,
362 .info = stac92xx_mux_enum_info,
363 .get = stac92xx_mux_enum_get,
364 .put = stac92xx_mux_enum_put,
365 },
366 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
367 HDA_CODEC_MUTE("Capture Switch", 0x1b, 0x0, HDA_OUTPUT),
368 { } /* end */
369};
370
Takashi Iwaid1d985f2006-11-23 19:27:12 +0100371static struct snd_kcontrol_new stac927x_mixer[] = {
Matt Porter3cc08dc2006-01-23 15:27:49 +0100372 {
373 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
374 .name = "Input Source",
375 .count = 1,
376 .info = stac92xx_mux_enum_info,
377 .get = stac92xx_mux_enum_get,
378 .put = stac92xx_mux_enum_put,
379 },
380 HDA_CODEC_VOLUME("InMux Capture Volume", 0x15, 0x0, HDA_OUTPUT),
381 HDA_CODEC_VOLUME("InVol Capture Volume", 0x18, 0x0, HDA_INPUT),
382 HDA_CODEC_MUTE("ADCMux Capture Switch", 0x1b, 0x0, HDA_OUTPUT),
383 { } /* end */
384};
385
Takashi Iwaid1d985f2006-11-23 19:27:12 +0100386static struct snd_kcontrol_new stac9205_mixer[] = {
Matt Porterf3302a52006-07-31 12:49:34 +0200387 {
388 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Matt Porter8b657272006-10-26 17:12:59 +0200389 .name = "Digital Input Source",
390 .count = 1,
391 .info = stac92xx_dmux_enum_info,
392 .get = stac92xx_dmux_enum_get,
393 .put = stac92xx_dmux_enum_put,
394 },
395 {
396 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Matt Porterf3302a52006-07-31 12:49:34 +0200397 .name = "Input Source",
398 .count = 1,
399 .info = stac92xx_mux_enum_info,
400 .get = stac92xx_mux_enum_get,
401 .put = stac92xx_mux_enum_put,
402 },
403 HDA_CODEC_VOLUME("InMux Capture Volume", 0x19, 0x0, HDA_OUTPUT),
404 HDA_CODEC_VOLUME("InVol Capture Volume", 0x1b, 0x0, HDA_INPUT),
405 HDA_CODEC_MUTE("ADCMux Capture Switch", 0x1d, 0x0, HDA_OUTPUT),
406 { } /* end */
407};
408
Matt2f2f4252005-04-13 14:45:30 +0200409static int stac92xx_build_controls(struct hda_codec *codec)
410{
411 struct sigmatel_spec *spec = codec->spec;
412 int err;
Mattc7d4b2f2005-06-27 14:59:41 +0200413 int i;
Matt2f2f4252005-04-13 14:45:30 +0200414
415 err = snd_hda_add_new_ctls(codec, spec->mixer);
416 if (err < 0)
417 return err;
Mattc7d4b2f2005-06-27 14:59:41 +0200418
419 for (i = 0; i < spec->num_mixers; i++) {
420 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
421 if (err < 0)
422 return err;
423 }
424
Mattdabbed62005-06-14 10:19:34 +0200425 if (spec->multiout.dig_out_nid) {
426 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
427 if (err < 0)
428 return err;
429 }
430 if (spec->dig_in_nid) {
431 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
432 if (err < 0)
433 return err;
434 }
435 return 0;
Matt2f2f4252005-04-13 14:45:30 +0200436}
437
Matt Porter403d1942005-11-29 15:00:51 +0100438static unsigned int ref9200_pin_configs[8] = {
Mattdabbed62005-06-14 10:19:34 +0200439 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
Matt2f2f4252005-04-13 14:45:30 +0200440 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
441};
442
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100443static unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
444 [STAC_REF] = ref9200_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +0100445};
446
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100447static const char *stac9200_models[STAC_9200_MODELS] = {
448 [STAC_REF] = "ref",
449};
450
451static struct snd_pci_quirk stac9200_cfg_tbl[] = {
452 /* SigmaTel reference board */
453 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
454 "DFI LanParty", STAC_REF),
Matt Portere7377072006-11-06 11:20:38 +0100455 /* Dell laptops have BIOS problem */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100456 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01b5,
457 "Dell Inspiron 630m", STAC_REF),
458 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c2,
459 "Dell Latitude D620", STAC_REF),
460 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cb,
461 "Dell Latitude 120L", STAC_REF),
Cory T. Tusar877b8662007-01-30 17:30:55 +0100462 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cc,
463 "Dell Latitude D820", STAC_REF),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +0100464 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cd,
465 "Dell Inspiron E1705/9400", STAC_REF),
466 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ce,
467 "Dell XPS M1710", STAC_REF),
Takashi Iwaif0f96742007-02-14 00:59:17 +0100468 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cf,
469 "Dell Precision M90", STAC_REF),
Matt Porter403d1942005-11-29 15:00:51 +0100470 {} /* terminator */
471};
472
Tobin Davis8e21c342007-01-08 11:04:17 +0100473static unsigned int ref925x_pin_configs[8] = {
474 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
475 0x90a70320, 0x02214210, 0x400003f1, 0x9033032e,
476};
477
478static unsigned int stac925x_MA6_pin_configs[8] = {
479 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
480 0x90a70320, 0x90100211, 0x400003f1, 0x9033032e,
481};
482
483static unsigned int stac925xM2_2_pin_configs[8] = {
484 0x40c003f3, 0x424503f2, 0x041800f4, 0x02a19020,
485 0x50a103F0, 0x90100210, 0x400003f1, 0x9033032e,
486};
487
488static unsigned int *stac925x_brd_tbl[STAC_925x_MODELS] = {
489 [STAC_REF] = ref925x_pin_configs,
490 [STAC_M2_2] = stac925xM2_2_pin_configs,
491 [STAC_MA6] = stac925x_MA6_pin_configs,
492};
493
494static const char *stac925x_models[STAC_925x_MODELS] = {
495 [STAC_REF] = "ref",
496 [STAC_M2_2] = "m2-2",
497 [STAC_MA6] = "m6",
498};
499
500static struct snd_pci_quirk stac925x_cfg_tbl[] = {
501 /* SigmaTel reference board */
502 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, "DFI LanParty", STAC_REF),
503 SND_PCI_QUIRK(0x107b, 0x0316, "Gateway M255", STAC_REF),
504 SND_PCI_QUIRK(0x107b, 0x0366, "Gateway MP6954", STAC_REF),
505 SND_PCI_QUIRK(0x107b, 0x0461, "Gateway NX560XL", STAC_MA6),
506 SND_PCI_QUIRK(0x1002, 0x437b, "Gateway MX6453", STAC_M2_2),
507 {} /* terminator */
508};
509
Matt Porter403d1942005-11-29 15:00:51 +0100510static unsigned int ref922x_pin_configs[10] = {
511 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
512 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
Matt2f2f4252005-04-13 14:45:30 +0200513 0x40000100, 0x40000100,
514};
515
Matt Porter403d1942005-11-29 15:00:51 +0100516static unsigned int d945gtp3_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +0100517 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
Matt Porter403d1942005-11-29 15:00:51 +0100518 0x40000100, 0x40000100, 0x40000100, 0x40000100,
519 0x02a19120, 0x40000100,
520};
521
522static unsigned int d945gtp5_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +0100523 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
524 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
Matt Porter403d1942005-11-29 15:00:51 +0100525 0x02a19320, 0x40000100,
526};
527
Nicolas Boichat6f0778d2007-03-15 12:38:15 +0100528static unsigned int macbook_pro_v1_pin_configs[10] = {
529 0x0321e230, 0x03a1e020, 0x9017e110, 0x01014010,
530 0x01a19021, 0x0381e021, 0x1345e240, 0x13c5e22e,
531 0x02a19320, 0x400000fb
532};
533
534static unsigned int macbook_pro_v2_pin_configs[10] = {
Takashi Iwai3fc24d82007-02-16 13:27:18 +0100535 0x0221401f, 0x90a70120, 0x01813024, 0x01014010,
536 0x400000fd, 0x01016011, 0x1345e240, 0x13c5e22e,
537 0x400000fc, 0x400000fb,
538};
539
Sylvain FORETf16928f2007-04-27 14:22:36 +0200540static unsigned int imac_intel_pin_configs[10] = {
541 0x0121e230, 0x90a70120, 0x9017e110, 0x400000fe,
542 0x400000fd, 0x0181e021, 0x1145e040, 0x400000fa,
543 0x400000fc, 0x400000fb,
544};
545
Takashi Iwai19039bd2006-06-28 15:52:16 +0200546static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100547 [STAC_D945_REF] = ref922x_pin_configs,
Takashi Iwai19039bd2006-06-28 15:52:16 +0200548 [STAC_D945GTP3] = d945gtp3_pin_configs,
549 [STAC_D945GTP5] = d945gtp5_pin_configs,
Takashi Iwai02a50392007-03-19 11:42:18 +0100550 [STAC_MACMINI] = macbook_pro_v1_pin_configs,
551 [STAC_MACBOOK] = macbook_pro_v1_pin_configs,
Nicolas Boichat6f0778d2007-03-15 12:38:15 +0100552 [STAC_MACBOOK_PRO_V1] = macbook_pro_v1_pin_configs,
553 [STAC_MACBOOK_PRO_V2] = macbook_pro_v2_pin_configs,
Sylvain FORETf16928f2007-04-27 14:22:36 +0200554 [STAC_IMAC_INTEL] = imac_intel_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +0100555};
556
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100557static const char *stac922x_models[STAC_922X_MODELS] = {
558 [STAC_D945_REF] = "ref",
559 [STAC_D945GTP5] = "5stack",
560 [STAC_D945GTP3] = "3stack",
561 [STAC_MACMINI] = "macmini",
Takashi Iwai3fc24d82007-02-16 13:27:18 +0100562 [STAC_MACBOOK] = "macbook",
Nicolas Boichat6f0778d2007-03-15 12:38:15 +0100563 [STAC_MACBOOK_PRO_V1] = "macbook-pro-v1",
564 [STAC_MACBOOK_PRO_V2] = "macbook-pro",
Sylvain FORETf16928f2007-04-27 14:22:36 +0200565 [STAC_IMAC_INTEL] = "imac-intel",
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100566};
567
568static struct snd_pci_quirk stac922x_cfg_tbl[] = {
569 /* SigmaTel reference board */
570 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
571 "DFI LanParty", STAC_D945_REF),
572 /* Intel 945G based systems */
573 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101,
574 "Intel D945G", STAC_D945GTP3),
575 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0202,
576 "Intel D945G", STAC_D945GTP3),
577 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0606,
578 "Intel D945G", STAC_D945GTP3),
579 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0601,
580 "Intel D945G", STAC_D945GTP3),
581 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0111,
582 "Intel D945G", STAC_D945GTP3),
583 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1115,
584 "Intel D945G", STAC_D945GTP3),
585 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1116,
586 "Intel D945G", STAC_D945GTP3),
587 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1117,
588 "Intel D945G", STAC_D945GTP3),
589 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1118,
590 "Intel D945G", STAC_D945GTP3),
591 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1119,
592 "Intel D945G", STAC_D945GTP3),
593 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x8826,
594 "Intel D945G", STAC_D945GTP3),
595 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5049,
596 "Intel D945G", STAC_D945GTP3),
597 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5055,
598 "Intel D945G", STAC_D945GTP3),
599 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5048,
600 "Intel D945G", STAC_D945GTP3),
601 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0110,
602 "Intel D945G", STAC_D945GTP3),
603 /* Intel D945G 5-stack systems */
604 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0404,
605 "Intel D945G", STAC_D945GTP5),
606 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0303,
607 "Intel D945G", STAC_D945GTP5),
608 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0013,
609 "Intel D945G", STAC_D945GTP5),
610 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0417,
611 "Intel D945G", STAC_D945GTP5),
612 /* Intel 945P based systems */
613 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0b0b,
614 "Intel D945P", STAC_D945GTP3),
615 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0112,
616 "Intel D945P", STAC_D945GTP3),
617 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0d0d,
618 "Intel D945P", STAC_D945GTP3),
619 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0909,
620 "Intel D945P", STAC_D945GTP3),
621 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0505,
622 "Intel D945P", STAC_D945GTP3),
623 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707,
624 "Intel D945P", STAC_D945GTP5),
625 /* other systems */
626 /* Apple Mac Mini (early 2006) */
627 SND_PCI_QUIRK(0x8384, 0x7680,
628 "Mac Mini", STAC_MACMINI),
Matt Porter403d1942005-11-29 15:00:51 +0100629 {} /* terminator */
630};
631
Matt Porter3cc08dc2006-01-23 15:27:49 +0100632static unsigned int ref927x_pin_configs[14] = {
Tobin Davis93ed1502006-09-01 21:03:12 +0200633 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
634 0x01a19040, 0x01011012, 0x01016011, 0x0101201f,
635 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
636 0x01c42190, 0x40000100,
Matt Porter3cc08dc2006-01-23 15:27:49 +0100637};
638
Tobin Davis93ed1502006-09-01 21:03:12 +0200639static unsigned int d965_3st_pin_configs[14] = {
Tobin Davis81d3dbd2006-08-22 19:44:45 +0200640 0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
641 0x01a19021, 0x01813024, 0x40000100, 0x40000100,
642 0x40000100, 0x40000100, 0x40000100, 0x40000100,
643 0x40000100, 0x40000100
644};
645
Tobin Davis93ed1502006-09-01 21:03:12 +0200646static unsigned int d965_5st_pin_configs[14] = {
647 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
648 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
649 0x40000100, 0x40000100, 0x40000100, 0x01442070,
650 0x40000100, 0x40000100
651};
652
653static unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100654 [STAC_D965_REF] = ref927x_pin_configs,
Tobin Davis93ed1502006-09-01 21:03:12 +0200655 [STAC_D965_3ST] = d965_3st_pin_configs,
656 [STAC_D965_5ST] = d965_5st_pin_configs,
Matt Porter3cc08dc2006-01-23 15:27:49 +0100657};
658
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100659static const char *stac927x_models[STAC_927X_MODELS] = {
660 [STAC_D965_REF] = "ref",
661 [STAC_D965_3ST] = "3stack",
662 [STAC_D965_5ST] = "5stack",
663};
664
665static struct snd_pci_quirk stac927x_cfg_tbl[] = {
666 /* SigmaTel reference board */
667 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
668 "DFI LanParty", STAC_D965_REF),
Tobin Davis81d3dbd2006-08-22 19:44:45 +0200669 /* Intel 946 based systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100670 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST),
671 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST),
Tobin Davis93ed1502006-09-01 21:03:12 +0200672 /* 965 based 3 stack systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100673 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2116, "Intel D965", STAC_D965_3ST),
674 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2115, "Intel D965", STAC_D965_3ST),
675 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2114, "Intel D965", STAC_D965_3ST),
676 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2113, "Intel D965", STAC_D965_3ST),
677 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2112, "Intel D965", STAC_D965_3ST),
678 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2111, "Intel D965", STAC_D965_3ST),
679 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2110, "Intel D965", STAC_D965_3ST),
680 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2009, "Intel D965", STAC_D965_3ST),
681 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2008, "Intel D965", STAC_D965_3ST),
682 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2007, "Intel D965", STAC_D965_3ST),
683 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2006, "Intel D965", STAC_D965_3ST),
684 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2005, "Intel D965", STAC_D965_3ST),
685 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2004, "Intel D965", STAC_D965_3ST),
686 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2003, "Intel D965", STAC_D965_3ST),
687 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2002, "Intel D965", STAC_D965_3ST),
688 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2001, "Intel D965", STAC_D965_3ST),
Tobin Davis93ed1502006-09-01 21:03:12 +0200689 /* 965 based 5 stack systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100690 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2301, "Intel D965", STAC_D965_5ST),
691 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2302, "Intel D965", STAC_D965_5ST),
692 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2303, "Intel D965", STAC_D965_5ST),
693 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2304, "Intel D965", STAC_D965_5ST),
694 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2305, "Intel D965", STAC_D965_5ST),
695 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2501, "Intel D965", STAC_D965_5ST),
696 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2502, "Intel D965", STAC_D965_5ST),
697 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2503, "Intel D965", STAC_D965_5ST),
698 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2504, "Intel D965", STAC_D965_5ST),
Matt Porter3cc08dc2006-01-23 15:27:49 +0100699 {} /* terminator */
700};
701
Matt Porterf3302a52006-07-31 12:49:34 +0200702static unsigned int ref9205_pin_configs[12] = {
703 0x40000100, 0x40000100, 0x01016011, 0x01014010,
Matt Porter8b657272006-10-26 17:12:59 +0200704 0x01813122, 0x01a19021, 0x40000100, 0x40000100,
705 0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
Matt Porterf3302a52006-07-31 12:49:34 +0200706};
707
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100708static unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
Matt Porterf3302a52006-07-31 12:49:34 +0200709 ref9205_pin_configs,
710};
711
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100712static const char *stac9205_models[STAC_9205_MODELS] = {
713 [STAC_9205_REF] = "ref",
714};
715
716static struct snd_pci_quirk stac9205_cfg_tbl[] = {
717 /* SigmaTel reference board */
718 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
719 "DFI LanParty", STAC_9205_REF),
Matt Porterf3302a52006-07-31 12:49:34 +0200720 {} /* terminator */
721};
722
Richard Fish11b44bb2006-08-23 18:31:34 +0200723static int stac92xx_save_bios_config_regs(struct hda_codec *codec)
724{
725 int i;
726 struct sigmatel_spec *spec = codec->spec;
727
728 if (! spec->bios_pin_configs) {
729 spec->bios_pin_configs = kcalloc(spec->num_pins,
730 sizeof(*spec->bios_pin_configs), GFP_KERNEL);
731 if (! spec->bios_pin_configs)
732 return -ENOMEM;
733 }
734
735 for (i = 0; i < spec->num_pins; i++) {
736 hda_nid_t nid = spec->pin_nids[i];
737 unsigned int pin_cfg;
738
739 pin_cfg = snd_hda_codec_read(codec, nid, 0,
740 AC_VERB_GET_CONFIG_DEFAULT, 0x00);
741 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x bios pin config %8.8x\n",
742 nid, pin_cfg);
743 spec->bios_pin_configs[i] = pin_cfg;
744 }
745
746 return 0;
747}
748
Matt2f2f4252005-04-13 14:45:30 +0200749static void stac92xx_set_config_regs(struct hda_codec *codec)
750{
751 int i;
752 struct sigmatel_spec *spec = codec->spec;
753 unsigned int pin_cfg;
754
Richard Fish11b44bb2006-08-23 18:31:34 +0200755 if (! spec->pin_nids || ! spec->pin_configs)
756 return;
757
758 for (i = 0; i < spec->num_pins; i++) {
Matt2f2f4252005-04-13 14:45:30 +0200759 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
760 AC_VERB_SET_CONFIG_DEFAULT_BYTES_0,
761 spec->pin_configs[i] & 0x000000ff);
762 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
763 AC_VERB_SET_CONFIG_DEFAULT_BYTES_1,
764 (spec->pin_configs[i] & 0x0000ff00) >> 8);
765 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
766 AC_VERB_SET_CONFIG_DEFAULT_BYTES_2,
767 (spec->pin_configs[i] & 0x00ff0000) >> 16);
768 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
769 AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
770 spec->pin_configs[i] >> 24);
771 pin_cfg = snd_hda_codec_read(codec, spec->pin_nids[i], 0,
772 AC_VERB_GET_CONFIG_DEFAULT,
773 0x00);
Matt Porter403d1942005-11-29 15:00:51 +0100774 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 +0200775 }
776}
Matt2f2f4252005-04-13 14:45:30 +0200777
Matt2f2f4252005-04-13 14:45:30 +0200778/*
779 * Analog playback callbacks
780 */
781static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
782 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100783 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200784{
785 struct sigmatel_spec *spec = codec->spec;
786 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
787}
788
789static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
790 struct hda_codec *codec,
791 unsigned int stream_tag,
792 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100793 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200794{
795 struct sigmatel_spec *spec = codec->spec;
Matt Porter403d1942005-11-29 15:00:51 +0100796 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
Matt2f2f4252005-04-13 14:45:30 +0200797}
798
799static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
800 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100801 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200802{
803 struct sigmatel_spec *spec = codec->spec;
804 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
805}
806
807/*
Mattdabbed62005-06-14 10:19:34 +0200808 * Digital playback callbacks
809 */
810static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
811 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100812 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +0200813{
814 struct sigmatel_spec *spec = codec->spec;
815 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
816}
817
818static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
819 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100820 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +0200821{
822 struct sigmatel_spec *spec = codec->spec;
823 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
824}
825
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200826static int stac92xx_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
827 struct hda_codec *codec,
828 unsigned int stream_tag,
829 unsigned int format,
830 struct snd_pcm_substream *substream)
831{
832 struct sigmatel_spec *spec = codec->spec;
833 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
834 stream_tag, format, substream);
835}
836
Mattdabbed62005-06-14 10:19:34 +0200837
838/*
Matt2f2f4252005-04-13 14:45:30 +0200839 * Analog capture callbacks
840 */
841static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
842 struct hda_codec *codec,
843 unsigned int stream_tag,
844 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100845 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200846{
847 struct sigmatel_spec *spec = codec->spec;
848
849 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
850 stream_tag, 0, format);
851 return 0;
852}
853
854static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
855 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100856 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200857{
858 struct sigmatel_spec *spec = codec->spec;
859
860 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 0, 0, 0);
861 return 0;
862}
863
Mattdabbed62005-06-14 10:19:34 +0200864static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
865 .substreams = 1,
866 .channels_min = 2,
867 .channels_max = 2,
868 /* NID is set in stac92xx_build_pcms */
869 .ops = {
870 .open = stac92xx_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200871 .close = stac92xx_dig_playback_pcm_close,
872 .prepare = stac92xx_dig_playback_pcm_prepare
Mattdabbed62005-06-14 10:19:34 +0200873 },
874};
875
876static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
877 .substreams = 1,
878 .channels_min = 2,
879 .channels_max = 2,
880 /* NID is set in stac92xx_build_pcms */
881};
882
Matt2f2f4252005-04-13 14:45:30 +0200883static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
884 .substreams = 1,
885 .channels_min = 2,
Mattc7d4b2f2005-06-27 14:59:41 +0200886 .channels_max = 8,
Matt2f2f4252005-04-13 14:45:30 +0200887 .nid = 0x02, /* NID to query formats and rates */
888 .ops = {
889 .open = stac92xx_playback_pcm_open,
890 .prepare = stac92xx_playback_pcm_prepare,
891 .cleanup = stac92xx_playback_pcm_cleanup
892 },
893};
894
Matt Porter3cc08dc2006-01-23 15:27:49 +0100895static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
896 .substreams = 1,
897 .channels_min = 2,
898 .channels_max = 2,
899 .nid = 0x06, /* NID to query formats and rates */
900 .ops = {
901 .open = stac92xx_playback_pcm_open,
902 .prepare = stac92xx_playback_pcm_prepare,
903 .cleanup = stac92xx_playback_pcm_cleanup
904 },
905};
906
Matt2f2f4252005-04-13 14:45:30 +0200907static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
908 .substreams = 2,
909 .channels_min = 2,
910 .channels_max = 2,
Matt Porter3cc08dc2006-01-23 15:27:49 +0100911 /* NID is set in stac92xx_build_pcms */
Matt2f2f4252005-04-13 14:45:30 +0200912 .ops = {
913 .prepare = stac92xx_capture_pcm_prepare,
914 .cleanup = stac92xx_capture_pcm_cleanup
915 },
916};
917
918static int stac92xx_build_pcms(struct hda_codec *codec)
919{
920 struct sigmatel_spec *spec = codec->spec;
921 struct hda_pcm *info = spec->pcm_rec;
922
923 codec->num_pcms = 1;
924 codec->pcm_info = info;
925
Mattc7d4b2f2005-06-27 14:59:41 +0200926 info->name = "STAC92xx Analog";
Matt2f2f4252005-04-13 14:45:30 +0200927 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
Matt2f2f4252005-04-13 14:45:30 +0200928 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100929 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
930
931 if (spec->alt_switch) {
932 codec->num_pcms++;
933 info++;
934 info->name = "STAC92xx Analog Alt";
935 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
936 }
Matt2f2f4252005-04-13 14:45:30 +0200937
Mattdabbed62005-06-14 10:19:34 +0200938 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
939 codec->num_pcms++;
940 info++;
941 info->name = "STAC92xx Digital";
942 if (spec->multiout.dig_out_nid) {
943 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
944 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
945 }
946 if (spec->dig_in_nid) {
947 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
948 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
949 }
950 }
951
Matt2f2f4252005-04-13 14:45:30 +0200952 return 0;
953}
954
Takashi Iwaic960a032006-03-23 17:06:28 +0100955static unsigned int stac92xx_get_vref(struct hda_codec *codec, hda_nid_t nid)
956{
957 unsigned int pincap = snd_hda_param_read(codec, nid,
958 AC_PAR_PIN_CAP);
959 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
960 if (pincap & AC_PINCAP_VREF_100)
961 return AC_PINCTL_VREF_100;
962 if (pincap & AC_PINCAP_VREF_80)
963 return AC_PINCTL_VREF_80;
964 if (pincap & AC_PINCAP_VREF_50)
965 return AC_PINCTL_VREF_50;
966 if (pincap & AC_PINCAP_VREF_GRD)
967 return AC_PINCTL_VREF_GRD;
968 return 0;
969}
970
Matt Porter403d1942005-11-29 15:00:51 +0100971static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
972
973{
974 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
975}
976
977static int stac92xx_io_switch_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
978{
979 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
980 uinfo->count = 1;
981 uinfo->value.integer.min = 0;
982 uinfo->value.integer.max = 1;
983 return 0;
984}
985
986static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
987{
988 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
989 struct sigmatel_spec *spec = codec->spec;
990 int io_idx = kcontrol-> private_value & 0xff;
991
992 ucontrol->value.integer.value[0] = spec->io_switch[io_idx];
993 return 0;
994}
995
996static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
997{
998 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
999 struct sigmatel_spec *spec = codec->spec;
1000 hda_nid_t nid = kcontrol->private_value >> 8;
1001 int io_idx = kcontrol-> private_value & 0xff;
1002 unsigned short val = ucontrol->value.integer.value[0];
1003
1004 spec->io_switch[io_idx] = val;
1005
1006 if (val)
1007 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
Takashi Iwaic960a032006-03-23 17:06:28 +01001008 else {
1009 unsigned int pinctl = AC_PINCTL_IN_EN;
1010 if (io_idx) /* set VREF for mic */
1011 pinctl |= stac92xx_get_vref(codec, nid);
1012 stac92xx_auto_set_pinctl(codec, nid, pinctl);
1013 }
Matt Porter403d1942005-11-29 15:00:51 +01001014 return 1;
1015}
1016
1017#define STAC_CODEC_IO_SWITCH(xname, xpval) \
1018 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1019 .name = xname, \
1020 .index = 0, \
1021 .info = stac92xx_io_switch_info, \
1022 .get = stac92xx_io_switch_get, \
1023 .put = stac92xx_io_switch_put, \
1024 .private_value = xpval, \
1025 }
1026
1027
Mattc7d4b2f2005-06-27 14:59:41 +02001028enum {
1029 STAC_CTL_WIDGET_VOL,
1030 STAC_CTL_WIDGET_MUTE,
Matt Porter403d1942005-11-29 15:00:51 +01001031 STAC_CTL_WIDGET_IO_SWITCH,
Mattc7d4b2f2005-06-27 14:59:41 +02001032};
1033
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001034static struct snd_kcontrol_new stac92xx_control_templates[] = {
Mattc7d4b2f2005-06-27 14:59:41 +02001035 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
1036 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Matt Porter403d1942005-11-29 15:00:51 +01001037 STAC_CODEC_IO_SWITCH(NULL, 0),
Mattc7d4b2f2005-06-27 14:59:41 +02001038};
1039
1040/* add dynamic controls */
1041static int stac92xx_add_control(struct sigmatel_spec *spec, int type, const char *name, unsigned long val)
1042{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001043 struct snd_kcontrol_new *knew;
Mattc7d4b2f2005-06-27 14:59:41 +02001044
1045 if (spec->num_kctl_used >= spec->num_kctl_alloc) {
1046 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
1047
1048 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */
1049 if (! knew)
1050 return -ENOMEM;
1051 if (spec->kctl_alloc) {
1052 memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
1053 kfree(spec->kctl_alloc);
1054 }
1055 spec->kctl_alloc = knew;
1056 spec->num_kctl_alloc = num;
1057 }
1058
1059 knew = &spec->kctl_alloc[spec->num_kctl_used];
1060 *knew = stac92xx_control_templates[type];
Takashi Iwai82fe0c52005-06-30 10:54:33 +02001061 knew->name = kstrdup(name, GFP_KERNEL);
Mattc7d4b2f2005-06-27 14:59:41 +02001062 if (! knew->name)
1063 return -ENOMEM;
1064 knew->private_value = val;
1065 spec->num_kctl_used++;
1066 return 0;
1067}
1068
Matt Porter403d1942005-11-29 15:00:51 +01001069/* flag inputs as additional dynamic lineouts */
1070static int stac92xx_add_dyn_out_pins(struct hda_codec *codec, struct auto_pin_cfg *cfg)
1071{
1072 struct sigmatel_spec *spec = codec->spec;
1073
1074 switch (cfg->line_outs) {
1075 case 3:
1076 /* add line-in as side */
1077 if (cfg->input_pins[AUTO_PIN_LINE]) {
1078 cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_LINE];
1079 spec->line_switch = 1;
1080 cfg->line_outs++;
1081 }
1082 break;
1083 case 2:
1084 /* add line-in as clfe and mic as side */
1085 if (cfg->input_pins[AUTO_PIN_LINE]) {
1086 cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_LINE];
1087 spec->line_switch = 1;
1088 cfg->line_outs++;
1089 }
1090 if (cfg->input_pins[AUTO_PIN_MIC]) {
1091 cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_MIC];
1092 spec->mic_switch = 1;
1093 cfg->line_outs++;
1094 }
1095 break;
1096 case 1:
1097 /* add line-in as surr and mic as clfe */
1098 if (cfg->input_pins[AUTO_PIN_LINE]) {
1099 cfg->line_out_pins[1] = cfg->input_pins[AUTO_PIN_LINE];
1100 spec->line_switch = 1;
1101 cfg->line_outs++;
1102 }
1103 if (cfg->input_pins[AUTO_PIN_MIC]) {
1104 cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_MIC];
1105 spec->mic_switch = 1;
1106 cfg->line_outs++;
1107 }
1108 break;
1109 }
1110
1111 return 0;
1112}
1113
Matt Porter3cc08dc2006-01-23 15:27:49 +01001114/*
1115 * XXX The line_out pin widget connection list may not be set to the
1116 * desired DAC nid. This is the case on 927x where ports A and B can
1117 * be routed to several DACs.
1118 *
1119 * This requires an analysis of the line-out/hp pin configuration
1120 * to provide a best fit for pin/DAC configurations that are routable.
1121 * For now, 927x DAC4 is not supported and 927x DAC1 output to ports
1122 * A and B is not supported.
1123 */
Mattc7d4b2f2005-06-27 14:59:41 +02001124/* fill in the dac_nids table from the parsed pin configuration */
Takashi Iwai19039bd2006-06-28 15:52:16 +02001125static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec,
1126 const struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02001127{
1128 struct sigmatel_spec *spec = codec->spec;
1129 hda_nid_t nid;
1130 int i;
1131
1132 /* check the pins hardwired to audio widget */
1133 for (i = 0; i < cfg->line_outs; i++) {
1134 nid = cfg->line_out_pins[i];
1135 spec->multiout.dac_nids[i] = snd_hda_codec_read(codec, nid, 0,
1136 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
1137 }
1138
Takashi Iwai82bc9552006-03-21 11:24:42 +01001139 spec->multiout.num_dacs = cfg->line_outs;
Mattc7d4b2f2005-06-27 14:59:41 +02001140
1141 return 0;
1142}
1143
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001144/* create volume control/switch for the given prefx type */
1145static int create_controls(struct sigmatel_spec *spec, const char *pfx, hda_nid_t nid, int chs)
1146{
1147 char name[32];
1148 int err;
1149
1150 sprintf(name, "%s Playback Volume", pfx);
1151 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, name,
1152 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1153 if (err < 0)
1154 return err;
1155 sprintf(name, "%s Playback Switch", pfx);
1156 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, name,
1157 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1158 if (err < 0)
1159 return err;
1160 return 0;
1161}
1162
Mattc7d4b2f2005-06-27 14:59:41 +02001163/* add playback controls from the parsed DAC table */
Takashi Iwai19039bd2006-06-28 15:52:16 +02001164static int stac92xx_auto_create_multi_out_ctls(struct sigmatel_spec *spec,
1165 const struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02001166{
Takashi Iwai19039bd2006-06-28 15:52:16 +02001167 static const char *chname[4] = {
1168 "Front", "Surround", NULL /*CLFE*/, "Side"
1169 };
Mattc7d4b2f2005-06-27 14:59:41 +02001170 hda_nid_t nid;
1171 int i, err;
1172
1173 for (i = 0; i < cfg->line_outs; i++) {
Matt Porter403d1942005-11-29 15:00:51 +01001174 if (!spec->multiout.dac_nids[i])
Mattc7d4b2f2005-06-27 14:59:41 +02001175 continue;
1176
1177 nid = spec->multiout.dac_nids[i];
1178
1179 if (i == 2) {
1180 /* Center/LFE */
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001181 err = create_controls(spec, "Center", nid, 1);
1182 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001183 return err;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001184 err = create_controls(spec, "LFE", nid, 2);
1185 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001186 return err;
1187 } else {
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001188 err = create_controls(spec, chname[i], nid, 3);
1189 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001190 return err;
1191 }
1192 }
1193
Matt Porter403d1942005-11-29 15:00:51 +01001194 if (spec->line_switch)
1195 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Line In as Output Switch", cfg->input_pins[AUTO_PIN_LINE] << 8)) < 0)
1196 return err;
1197
1198 if (spec->mic_switch)
1199 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Mic as Output Switch", (cfg->input_pins[AUTO_PIN_MIC] << 8) | 1)) < 0)
1200 return err;
1201
Mattc7d4b2f2005-06-27 14:59:41 +02001202 return 0;
1203}
1204
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001205static int check_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
1206{
1207 int i;
1208
1209 for (i = 0; i < spec->multiout.num_dacs; i++) {
1210 if (spec->multiout.dac_nids[i] == nid)
1211 return 1;
1212 }
1213 if (spec->multiout.hp_nid == nid)
1214 return 1;
1215 return 0;
1216}
1217
1218static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
1219{
1220 if (!spec->multiout.hp_nid)
1221 spec->multiout.hp_nid = nid;
1222 else if (spec->multiout.num_dacs > 4) {
1223 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
1224 return 1;
1225 } else {
1226 spec->multiout.dac_nids[spec->multiout.num_dacs] = nid;
1227 spec->multiout.num_dacs++;
1228 }
1229 return 0;
1230}
1231
1232/* add playback controls for Speaker and HP outputs */
1233static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
1234 struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02001235{
1236 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02001237 hda_nid_t nid;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001238 int i, old_num_dacs, err;
Mattc7d4b2f2005-06-27 14:59:41 +02001239
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001240 old_num_dacs = spec->multiout.num_dacs;
1241 for (i = 0; i < cfg->hp_outs; i++) {
1242 unsigned int wid_caps = get_wcaps(codec, cfg->hp_pins[i]);
1243 if (wid_caps & AC_WCAP_UNSOL_CAP)
1244 spec->hp_detect = 1;
1245 nid = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
1246 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
1247 if (check_in_dac_nids(spec, nid))
1248 nid = 0;
1249 if (! nid)
Mattc7d4b2f2005-06-27 14:59:41 +02001250 continue;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001251 add_spec_dacs(spec, nid);
1252 }
1253 for (i = 0; i < cfg->speaker_outs; i++) {
1254 nid = snd_hda_codec_read(codec, cfg->speaker_pins[0], 0,
1255 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
1256 if (check_in_dac_nids(spec, nid))
1257 nid = 0;
1258 if (check_in_dac_nids(spec, nid))
1259 nid = 0;
1260 if (! nid)
1261 continue;
1262 add_spec_dacs(spec, nid);
Mattc7d4b2f2005-06-27 14:59:41 +02001263 }
1264
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001265 for (i = old_num_dacs; i < spec->multiout.num_dacs; i++) {
1266 static const char *pfxs[] = {
1267 "Speaker", "External Speaker", "Speaker2",
1268 };
1269 err = create_controls(spec, pfxs[i - old_num_dacs],
1270 spec->multiout.dac_nids[i], 3);
1271 if (err < 0)
1272 return err;
1273 }
1274 if (spec->multiout.hp_nid) {
1275 const char *pfx;
1276 if (old_num_dacs == spec->multiout.num_dacs)
1277 pfx = "Master";
1278 else
1279 pfx = "Headphone";
1280 err = create_controls(spec, pfx, spec->multiout.hp_nid, 3);
1281 if (err < 0)
1282 return err;
1283 }
Mattc7d4b2f2005-06-27 14:59:41 +02001284
1285 return 0;
1286}
1287
Matt Porter8b657272006-10-26 17:12:59 +02001288/* labels for dmic mux inputs */
Adrian Bunkddc2cec2006-11-20 12:03:44 +01001289static const char *stac92xx_dmic_labels[5] = {
Matt Porter8b657272006-10-26 17:12:59 +02001290 "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
1291 "Digital Mic 3", "Digital Mic 4"
1292};
1293
1294/* create playback/capture controls for input pins on dmic capable codecs */
1295static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
1296 const struct auto_pin_cfg *cfg)
1297{
1298 struct sigmatel_spec *spec = codec->spec;
1299 struct hda_input_mux *dimux = &spec->private_dimux;
1300 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
1301 int i, j;
1302
1303 dimux->items[dimux->num_items].label = stac92xx_dmic_labels[0];
1304 dimux->items[dimux->num_items].index = 0;
1305 dimux->num_items++;
1306
1307 for (i = 0; i < spec->num_dmics; i++) {
1308 int index;
1309 int num_cons;
1310 unsigned int def_conf;
1311
1312 def_conf = snd_hda_codec_read(codec,
1313 spec->dmic_nids[i],
1314 0,
1315 AC_VERB_GET_CONFIG_DEFAULT,
1316 0);
1317 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
1318 continue;
1319
1320 num_cons = snd_hda_get_connections(codec,
1321 spec->dmux_nid,
1322 con_lst,
1323 HDA_MAX_NUM_INPUTS);
1324 for (j = 0; j < num_cons; j++)
1325 if (con_lst[j] == spec->dmic_nids[i]) {
1326 index = j;
1327 goto found;
1328 }
1329 continue;
1330found:
1331 dimux->items[dimux->num_items].label =
1332 stac92xx_dmic_labels[dimux->num_items];
1333 dimux->items[dimux->num_items].index = index;
1334 dimux->num_items++;
1335 }
1336
1337 return 0;
1338}
1339
Mattc7d4b2f2005-06-27 14:59:41 +02001340/* create playback/capture controls for input pins */
1341static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
1342{
1343 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02001344 struct hda_input_mux *imux = &spec->private_imux;
1345 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
1346 int i, j, k;
1347
1348 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwai314634b2006-09-21 11:56:18 +02001349 int index;
Mattc7d4b2f2005-06-27 14:59:41 +02001350
Takashi Iwai314634b2006-09-21 11:56:18 +02001351 if (!cfg->input_pins[i])
1352 continue;
1353 index = -1;
1354 for (j = 0; j < spec->num_muxes; j++) {
1355 int num_cons;
1356 num_cons = snd_hda_get_connections(codec,
1357 spec->mux_nids[j],
1358 con_lst,
1359 HDA_MAX_NUM_INPUTS);
1360 for (k = 0; k < num_cons; k++)
1361 if (con_lst[k] == cfg->input_pins[i]) {
1362 index = k;
1363 goto found;
1364 }
Mattc7d4b2f2005-06-27 14:59:41 +02001365 }
Takashi Iwai314634b2006-09-21 11:56:18 +02001366 continue;
1367 found:
1368 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
1369 imux->items[imux->num_items].index = index;
1370 imux->num_items++;
Mattc7d4b2f2005-06-27 14:59:41 +02001371 }
1372
Sam Revitch62fe78e2006-05-10 15:09:17 +02001373 if (imux->num_items == 1) {
1374 /*
1375 * Set the current input for the muxes.
1376 * The STAC9221 has two input muxes with identical source
1377 * NID lists. Hopefully this won't get confused.
1378 */
1379 for (i = 0; i < spec->num_muxes; i++) {
1380 snd_hda_codec_write(codec, spec->mux_nids[i], 0,
1381 AC_VERB_SET_CONNECT_SEL,
1382 imux->items[0].index);
1383 }
1384 }
1385
Mattc7d4b2f2005-06-27 14:59:41 +02001386 return 0;
1387}
1388
Mattc7d4b2f2005-06-27 14:59:41 +02001389static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
1390{
1391 struct sigmatel_spec *spec = codec->spec;
1392 int i;
1393
1394 for (i = 0; i < spec->autocfg.line_outs; i++) {
1395 hda_nid_t nid = spec->autocfg.line_out_pins[i];
1396 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
1397 }
1398}
1399
1400static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
1401{
1402 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001403 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02001404
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001405 for (i = 0; i < spec->autocfg.hp_outs; i++) {
1406 hda_nid_t pin;
1407 pin = spec->autocfg.hp_pins[i];
1408 if (pin) /* connect to front */
1409 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
1410 }
1411 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
1412 hda_nid_t pin;
1413 pin = spec->autocfg.speaker_pins[i];
1414 if (pin) /* connect to front */
1415 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
1416 }
Mattc7d4b2f2005-06-27 14:59:41 +02001417}
1418
Matt Porter3cc08dc2006-01-23 15:27:49 +01001419static 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 +02001420{
1421 struct sigmatel_spec *spec = codec->spec;
1422 int err;
1423
Matt Porter8b657272006-10-26 17:12:59 +02001424 if ((err = snd_hda_parse_pin_def_config(codec,
1425 &spec->autocfg,
1426 spec->dmic_nids)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001427 return err;
Takashi Iwai82bc9552006-03-21 11:24:42 +01001428 if (! spec->autocfg.line_outs)
Matt Porter869264c2006-01-25 19:20:50 +01001429 return 0; /* can't find valid pin config */
Takashi Iwai19039bd2006-06-28 15:52:16 +02001430
Matt Porter403d1942005-11-29 15:00:51 +01001431 if ((err = stac92xx_add_dyn_out_pins(codec, &spec->autocfg)) < 0)
1432 return err;
Takashi Iwai19039bd2006-06-28 15:52:16 +02001433 if (spec->multiout.num_dacs == 0)
1434 if ((err = stac92xx_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
1435 return err;
Mattc7d4b2f2005-06-27 14:59:41 +02001436
1437 if ((err = stac92xx_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
1438 (err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg)) < 0 ||
1439 (err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
1440 return err;
1441
Matt Porter8b657272006-10-26 17:12:59 +02001442 if (spec->num_dmics > 0)
1443 if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
1444 &spec->autocfg)) < 0)
1445 return err;
1446
Mattc7d4b2f2005-06-27 14:59:41 +02001447 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Matt Porter403d1942005-11-29 15:00:51 +01001448 if (spec->multiout.max_channels > 2)
Mattc7d4b2f2005-06-27 14:59:41 +02001449 spec->surr_switch = 1;
Mattc7d4b2f2005-06-27 14:59:41 +02001450
Takashi Iwai82bc9552006-03-21 11:24:42 +01001451 if (spec->autocfg.dig_out_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01001452 spec->multiout.dig_out_nid = dig_out;
Takashi Iwai82bc9552006-03-21 11:24:42 +01001453 if (spec->autocfg.dig_in_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01001454 spec->dig_in_nid = dig_in;
Mattc7d4b2f2005-06-27 14:59:41 +02001455
1456 if (spec->kctl_alloc)
1457 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
1458
1459 spec->input_mux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02001460 spec->dinput_mux = &spec->private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +02001461
1462 return 1;
1463}
1464
Takashi Iwai82bc9552006-03-21 11:24:42 +01001465/* add playback controls for HP output */
1466static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
1467 struct auto_pin_cfg *cfg)
1468{
1469 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001470 hda_nid_t pin = cfg->hp_pins[0];
Takashi Iwai82bc9552006-03-21 11:24:42 +01001471 unsigned int wid_caps;
1472
1473 if (! pin)
1474 return 0;
1475
1476 wid_caps = get_wcaps(codec, pin);
Takashi Iwai505cb342006-03-27 12:51:52 +02001477 if (wid_caps & AC_WCAP_UNSOL_CAP)
Takashi Iwai82bc9552006-03-21 11:24:42 +01001478 spec->hp_detect = 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +01001479
1480 return 0;
1481}
1482
Richard Fish160ea0d2006-09-06 13:58:25 +02001483/* add playback controls for LFE output */
1484static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
1485 struct auto_pin_cfg *cfg)
1486{
1487 struct sigmatel_spec *spec = codec->spec;
1488 int err;
1489 hda_nid_t lfe_pin = 0x0;
1490 int i;
1491
1492 /*
1493 * search speaker outs and line outs for a mono speaker pin
1494 * with an amp. If one is found, add LFE controls
1495 * for it.
1496 */
1497 for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
1498 hda_nid_t pin = spec->autocfg.speaker_pins[i];
1499 unsigned long wcaps = get_wcaps(codec, pin);
1500 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
1501 if (wcaps == AC_WCAP_OUT_AMP)
1502 /* found a mono speaker with an amp, must be lfe */
1503 lfe_pin = pin;
1504 }
1505
1506 /* if speaker_outs is 0, then speakers may be in line_outs */
1507 if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
1508 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
1509 hda_nid_t pin = spec->autocfg.line_out_pins[i];
1510 unsigned long cfg;
1511 cfg = snd_hda_codec_read(codec, pin, 0,
1512 AC_VERB_GET_CONFIG_DEFAULT,
1513 0x00);
1514 if (get_defcfg_device(cfg) == AC_JACK_SPEAKER) {
1515 unsigned long wcaps = get_wcaps(codec, pin);
1516 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
1517 if (wcaps == AC_WCAP_OUT_AMP)
1518 /* found a mono speaker with an amp,
1519 must be lfe */
1520 lfe_pin = pin;
1521 }
1522 }
1523 }
1524
1525 if (lfe_pin) {
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001526 err = create_controls(spec, "LFE", lfe_pin, 1);
Richard Fish160ea0d2006-09-06 13:58:25 +02001527 if (err < 0)
1528 return err;
1529 }
1530
1531 return 0;
1532}
1533
Mattc7d4b2f2005-06-27 14:59:41 +02001534static int stac9200_parse_auto_config(struct hda_codec *codec)
1535{
1536 struct sigmatel_spec *spec = codec->spec;
1537 int err;
1538
Kailang Yangdf694da2005-12-05 19:42:22 +01001539 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001540 return err;
1541
1542 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
1543 return err;
1544
Takashi Iwai82bc9552006-03-21 11:24:42 +01001545 if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
1546 return err;
1547
Richard Fish160ea0d2006-09-06 13:58:25 +02001548 if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
1549 return err;
1550
Takashi Iwai82bc9552006-03-21 11:24:42 +01001551 if (spec->autocfg.dig_out_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02001552 spec->multiout.dig_out_nid = 0x05;
Takashi Iwai82bc9552006-03-21 11:24:42 +01001553 if (spec->autocfg.dig_in_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02001554 spec->dig_in_nid = 0x04;
Mattc7d4b2f2005-06-27 14:59:41 +02001555
1556 if (spec->kctl_alloc)
1557 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
1558
1559 spec->input_mux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02001560 spec->dinput_mux = &spec->private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +02001561
1562 return 1;
1563}
1564
Sam Revitch62fe78e2006-05-10 15:09:17 +02001565/*
1566 * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
1567 * funky external mute control using GPIO pins.
1568 */
1569
1570static void stac922x_gpio_mute(struct hda_codec *codec, int pin, int muted)
1571{
1572 unsigned int gpiostate, gpiomask, gpiodir;
1573
1574 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
1575 AC_VERB_GET_GPIO_DATA, 0);
1576
1577 if (!muted)
1578 gpiostate |= (1 << pin);
1579 else
1580 gpiostate &= ~(1 << pin);
1581
1582 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
1583 AC_VERB_GET_GPIO_MASK, 0);
1584 gpiomask |= (1 << pin);
1585
1586 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
1587 AC_VERB_GET_GPIO_DIRECTION, 0);
1588 gpiodir |= (1 << pin);
1589
1590 /* AppleHDA seems to do this -- WTF is this verb?? */
1591 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
1592
1593 snd_hda_codec_write(codec, codec->afg, 0,
1594 AC_VERB_SET_GPIO_MASK, gpiomask);
1595 snd_hda_codec_write(codec, codec->afg, 0,
1596 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
1597
1598 msleep(1);
1599
1600 snd_hda_codec_write(codec, codec->afg, 0,
1601 AC_VERB_SET_GPIO_DATA, gpiostate);
1602}
1603
Takashi Iwai314634b2006-09-21 11:56:18 +02001604static void enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
1605 unsigned int event)
1606{
1607 if (get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP)
1608 snd_hda_codec_write(codec, nid, 0,
1609 AC_VERB_SET_UNSOLICITED_ENABLE,
1610 (AC_USRSP_EN | event));
1611}
1612
Mattc7d4b2f2005-06-27 14:59:41 +02001613static int stac92xx_init(struct hda_codec *codec)
1614{
1615 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai82bc9552006-03-21 11:24:42 +01001616 struct auto_pin_cfg *cfg = &spec->autocfg;
1617 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02001618
Mattc7d4b2f2005-06-27 14:59:41 +02001619 snd_hda_sequence_write(codec, spec->init);
1620
Takashi Iwai82bc9552006-03-21 11:24:42 +01001621 /* set up pins */
1622 if (spec->hp_detect) {
Takashi Iwai505cb342006-03-27 12:51:52 +02001623 /* Enable unsolicited responses on the HP widget */
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001624 for (i = 0; i < cfg->hp_outs; i++)
Takashi Iwai314634b2006-09-21 11:56:18 +02001625 enable_pin_detect(codec, cfg->hp_pins[i],
1626 STAC_HP_EVENT);
Takashi Iwai0a07aca2007-03-13 10:40:23 +01001627 /* force to enable the first line-out; the others are set up
1628 * in unsol_event
1629 */
1630 stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
1631 AC_PINCTL_OUT_EN);
Takashi Iwaieb995a82006-09-21 14:28:21 +02001632 stac92xx_auto_init_hp_out(codec);
Takashi Iwai82bc9552006-03-21 11:24:42 +01001633 /* fake event to set up pins */
1634 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
1635 } else {
1636 stac92xx_auto_init_multi_out(codec);
1637 stac92xx_auto_init_hp_out(codec);
1638 }
1639 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwaic960a032006-03-23 17:06:28 +01001640 hda_nid_t nid = cfg->input_pins[i];
1641 if (nid) {
1642 unsigned int pinctl = AC_PINCTL_IN_EN;
1643 if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC)
1644 pinctl |= stac92xx_get_vref(codec, nid);
1645 stac92xx_auto_set_pinctl(codec, nid, pinctl);
1646 }
Takashi Iwai82bc9552006-03-21 11:24:42 +01001647 }
Matt Porter8b657272006-10-26 17:12:59 +02001648 if (spec->num_dmics > 0)
1649 for (i = 0; i < spec->num_dmics; i++)
1650 stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
1651 AC_PINCTL_IN_EN);
1652
Takashi Iwai82bc9552006-03-21 11:24:42 +01001653 if (cfg->dig_out_pin)
1654 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pin,
1655 AC_PINCTL_OUT_EN);
1656 if (cfg->dig_in_pin)
1657 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
1658 AC_PINCTL_IN_EN);
1659
Sam Revitch62fe78e2006-05-10 15:09:17 +02001660 if (spec->gpio_mute) {
1661 stac922x_gpio_mute(codec, 0, 0);
1662 stac922x_gpio_mute(codec, 1, 0);
1663 }
1664
Mattc7d4b2f2005-06-27 14:59:41 +02001665 return 0;
1666}
1667
Matt2f2f4252005-04-13 14:45:30 +02001668static void stac92xx_free(struct hda_codec *codec)
1669{
Mattc7d4b2f2005-06-27 14:59:41 +02001670 struct sigmatel_spec *spec = codec->spec;
1671 int i;
1672
1673 if (! spec)
1674 return;
1675
1676 if (spec->kctl_alloc) {
1677 for (i = 0; i < spec->num_kctl_used; i++)
1678 kfree(spec->kctl_alloc[i].name);
1679 kfree(spec->kctl_alloc);
1680 }
1681
Richard Fish11b44bb2006-08-23 18:31:34 +02001682 if (spec->bios_pin_configs)
1683 kfree(spec->bios_pin_configs);
1684
Mattc7d4b2f2005-06-27 14:59:41 +02001685 kfree(spec);
Matt2f2f4252005-04-13 14:45:30 +02001686}
1687
Matt4e550962005-07-04 17:51:39 +02001688static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
1689 unsigned int flag)
1690{
1691 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
1692 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Takashi Iwai314634b2006-09-21 11:56:18 +02001693 if (flag == AC_PINCTL_OUT_EN && (pin_ctl & AC_PINCTL_IN_EN))
1694 return;
Matt4e550962005-07-04 17:51:39 +02001695 snd_hda_codec_write(codec, nid, 0,
1696 AC_VERB_SET_PIN_WIDGET_CONTROL,
1697 pin_ctl | flag);
1698}
1699
1700static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
1701 unsigned int flag)
1702{
1703 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
1704 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
1705 snd_hda_codec_write(codec, nid, 0,
1706 AC_VERB_SET_PIN_WIDGET_CONTROL,
1707 pin_ctl & ~flag);
1708}
1709
Takashi Iwai314634b2006-09-21 11:56:18 +02001710static int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
1711{
1712 if (!nid)
1713 return 0;
1714 if (snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PIN_SENSE, 0x00)
1715 & (1 << 31))
1716 return 1;
1717 return 0;
1718}
1719
1720static void stac92xx_hp_detect(struct hda_codec *codec, unsigned int res)
Matt4e550962005-07-04 17:51:39 +02001721{
1722 struct sigmatel_spec *spec = codec->spec;
1723 struct auto_pin_cfg *cfg = &spec->autocfg;
1724 int i, presence;
1725
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001726 presence = 0;
1727 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai314634b2006-09-21 11:56:18 +02001728 presence = get_pin_presence(codec, cfg->hp_pins[i]);
1729 if (presence)
1730 break;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001731 }
Matt4e550962005-07-04 17:51:39 +02001732
1733 if (presence) {
1734 /* disable lineouts, enable hp */
1735 for (i = 0; i < cfg->line_outs; i++)
1736 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
1737 AC_PINCTL_OUT_EN);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001738 for (i = 0; i < cfg->speaker_outs; i++)
1739 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
1740 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02001741 } else {
1742 /* enable lineouts, disable hp */
1743 for (i = 0; i < cfg->line_outs; i++)
1744 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
1745 AC_PINCTL_OUT_EN);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001746 for (i = 0; i < cfg->speaker_outs; i++)
1747 stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
1748 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02001749 }
1750}
1751
Takashi Iwai314634b2006-09-21 11:56:18 +02001752static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
1753{
1754 switch (res >> 26) {
1755 case STAC_HP_EVENT:
1756 stac92xx_hp_detect(codec, res);
1757 break;
1758 }
1759}
1760
Mattff6fdc32005-06-27 15:06:52 +02001761#ifdef CONFIG_PM
1762static int stac92xx_resume(struct hda_codec *codec)
1763{
1764 struct sigmatel_spec *spec = codec->spec;
1765 int i;
1766
1767 stac92xx_init(codec);
Richard Fish11b44bb2006-08-23 18:31:34 +02001768 stac92xx_set_config_regs(codec);
Mattff6fdc32005-06-27 15:06:52 +02001769 for (i = 0; i < spec->num_mixers; i++)
1770 snd_hda_resume_ctls(codec, spec->mixers[i]);
1771 if (spec->multiout.dig_out_nid)
1772 snd_hda_resume_spdif_out(codec);
1773 if (spec->dig_in_nid)
1774 snd_hda_resume_spdif_in(codec);
1775
1776 return 0;
1777}
1778#endif
1779
Matt2f2f4252005-04-13 14:45:30 +02001780static struct hda_codec_ops stac92xx_patch_ops = {
1781 .build_controls = stac92xx_build_controls,
1782 .build_pcms = stac92xx_build_pcms,
1783 .init = stac92xx_init,
1784 .free = stac92xx_free,
Matt4e550962005-07-04 17:51:39 +02001785 .unsol_event = stac92xx_unsol_event,
Mattff6fdc32005-06-27 15:06:52 +02001786#ifdef CONFIG_PM
1787 .resume = stac92xx_resume,
1788#endif
Matt2f2f4252005-04-13 14:45:30 +02001789};
1790
1791static int patch_stac9200(struct hda_codec *codec)
1792{
1793 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02001794 int err;
Matt2f2f4252005-04-13 14:45:30 +02001795
Takashi Iwaie560d8d2005-09-09 14:21:46 +02001796 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02001797 if (spec == NULL)
1798 return -ENOMEM;
1799
1800 codec->spec = spec;
Richard Fish11b44bb2006-08-23 18:31:34 +02001801 spec->num_pins = 8;
1802 spec->pin_nids = stac9200_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001803 spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS,
1804 stac9200_models,
1805 stac9200_cfg_tbl);
Richard Fish11b44bb2006-08-23 18:31:34 +02001806 if (spec->board_config < 0) {
1807 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9200, using BIOS defaults\n");
1808 err = stac92xx_save_bios_config_regs(codec);
1809 if (err < 0) {
1810 stac92xx_free(codec);
1811 return err;
1812 }
1813 spec->pin_configs = spec->bios_pin_configs;
1814 } else {
Matt Porter403d1942005-11-29 15:00:51 +01001815 spec->pin_configs = stac9200_brd_tbl[spec->board_config];
1816 stac92xx_set_config_regs(codec);
1817 }
Matt2f2f4252005-04-13 14:45:30 +02001818
1819 spec->multiout.max_channels = 2;
1820 spec->multiout.num_dacs = 1;
1821 spec->multiout.dac_nids = stac9200_dac_nids;
1822 spec->adc_nids = stac9200_adc_nids;
1823 spec->mux_nids = stac9200_mux_nids;
Mattdabbed62005-06-14 10:19:34 +02001824 spec->num_muxes = 1;
Matt Porter8b657272006-10-26 17:12:59 +02001825 spec->num_dmics = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02001826
1827 spec->init = stac9200_core_init;
Matt2f2f4252005-04-13 14:45:30 +02001828 spec->mixer = stac9200_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02001829
1830 err = stac9200_parse_auto_config(codec);
1831 if (err < 0) {
1832 stac92xx_free(codec);
1833 return err;
1834 }
Matt2f2f4252005-04-13 14:45:30 +02001835
1836 codec->patch_ops = stac92xx_patch_ops;
1837
1838 return 0;
1839}
1840
Tobin Davis8e21c342007-01-08 11:04:17 +01001841static int patch_stac925x(struct hda_codec *codec)
1842{
1843 struct sigmatel_spec *spec;
1844 int err;
1845
1846 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1847 if (spec == NULL)
1848 return -ENOMEM;
1849
1850 codec->spec = spec;
1851 spec->num_pins = 8;
1852 spec->pin_nids = stac925x_pin_nids;
1853 spec->board_config = snd_hda_check_board_config(codec, STAC_925x_MODELS,
1854 stac925x_models,
1855 stac925x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01001856 again:
Tobin Davis8e21c342007-01-08 11:04:17 +01001857 if (spec->board_config < 0) {
1858 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC925x, using BIOS defaults\n");
1859 err = stac92xx_save_bios_config_regs(codec);
1860 if (err < 0) {
1861 stac92xx_free(codec);
1862 return err;
1863 }
1864 spec->pin_configs = spec->bios_pin_configs;
1865 } else if (stac925x_brd_tbl[spec->board_config] != NULL){
1866 spec->pin_configs = stac925x_brd_tbl[spec->board_config];
1867 stac92xx_set_config_regs(codec);
1868 }
1869
1870 spec->multiout.max_channels = 2;
1871 spec->multiout.num_dacs = 1;
1872 spec->multiout.dac_nids = stac925x_dac_nids;
1873 spec->adc_nids = stac925x_adc_nids;
1874 spec->mux_nids = stac925x_mux_nids;
1875 spec->num_muxes = 1;
1876 spec->num_dmics = 0;
1877
1878 spec->init = stac925x_core_init;
1879 spec->mixer = stac925x_mixer;
1880
1881 err = stac92xx_parse_auto_config(codec, 0x8, 0x7);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01001882 if (!err) {
1883 if (spec->board_config < 0) {
1884 printk(KERN_WARNING "hda_codec: No auto-config is "
1885 "available, default to model=ref\n");
1886 spec->board_config = STAC_925x_REF;
1887 goto again;
1888 }
1889 err = -EINVAL;
1890 }
Tobin Davis8e21c342007-01-08 11:04:17 +01001891 if (err < 0) {
1892 stac92xx_free(codec);
1893 return err;
1894 }
1895
1896 codec->patch_ops = stac92xx_patch_ops;
1897
1898 return 0;
1899}
1900
Matt2f2f4252005-04-13 14:45:30 +02001901static int patch_stac922x(struct hda_codec *codec)
1902{
1903 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02001904 int err;
Matt2f2f4252005-04-13 14:45:30 +02001905
Takashi Iwaie560d8d2005-09-09 14:21:46 +02001906 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02001907 if (spec == NULL)
1908 return -ENOMEM;
1909
1910 codec->spec = spec;
Richard Fish11b44bb2006-08-23 18:31:34 +02001911 spec->num_pins = 10;
1912 spec->pin_nids = stac922x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001913 spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS,
1914 stac922x_models,
1915 stac922x_cfg_tbl);
Takashi Iwai3fc24d82007-02-16 13:27:18 +01001916 if (spec->board_config == STAC_MACMINI) {
1917 spec->gpio_mute = 1;
1918 /* Intel Macs have all same PCI SSID, so we need to check
1919 * codec SSID to distinguish the exact models
1920 */
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01001921 printk(KERN_INFO "hda_codec: STAC922x, Apple subsys_id=%x\n", codec->subsystem_id);
Takashi Iwai3fc24d82007-02-16 13:27:18 +01001922 switch (codec->subsystem_id) {
Abhijit Bhopatkarc45e20e2007-04-17 11:57:16 +02001923 case 0x106b0a00: /* MacBook First generatoin */
1924 spec->board_config = STAC_MACBOOK;
1925 break;
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01001926 case 0x106b0200: /* MacBook Pro first generation */
1927 spec->board_config = STAC_MACBOOK_PRO_V1;
1928 break;
1929 case 0x106b1e00: /* MacBook Pro second generation */
1930 spec->board_config = STAC_MACBOOK_PRO_V2;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01001931 break;
Sylvain FORETf16928f2007-04-27 14:22:36 +02001932 case 0x106b0700: /* Intel-based iMac */
1933 spec->board_config = STAC_IMAC_INTEL;
1934 break;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01001935 }
1936 }
1937
Takashi Iwai9e507ab2007-02-08 17:50:10 +01001938 again:
Richard Fish11b44bb2006-08-23 18:31:34 +02001939 if (spec->board_config < 0) {
1940 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC922x, "
1941 "using BIOS defaults\n");
1942 err = stac92xx_save_bios_config_regs(codec);
1943 if (err < 0) {
1944 stac92xx_free(codec);
1945 return err;
1946 }
1947 spec->pin_configs = spec->bios_pin_configs;
1948 } else if (stac922x_brd_tbl[spec->board_config] != NULL) {
Matt Porter403d1942005-11-29 15:00:51 +01001949 spec->pin_configs = stac922x_brd_tbl[spec->board_config];
1950 stac92xx_set_config_regs(codec);
1951 }
Matt2f2f4252005-04-13 14:45:30 +02001952
Matt2f2f4252005-04-13 14:45:30 +02001953 spec->adc_nids = stac922x_adc_nids;
1954 spec->mux_nids = stac922x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01001955 spec->num_muxes = ARRAY_SIZE(stac922x_mux_nids);
Matt Porter8b657272006-10-26 17:12:59 +02001956 spec->num_dmics = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02001957
1958 spec->init = stac922x_core_init;
Matt2f2f4252005-04-13 14:45:30 +02001959 spec->mixer = stac922x_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02001960
1961 spec->multiout.dac_nids = spec->dac_nids;
Takashi Iwai19039bd2006-06-28 15:52:16 +02001962
Matt Porter3cc08dc2006-01-23 15:27:49 +01001963 err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01001964 if (!err) {
1965 if (spec->board_config < 0) {
1966 printk(KERN_WARNING "hda_codec: No auto-config is "
1967 "available, default to model=ref\n");
1968 spec->board_config = STAC_D945_REF;
1969 goto again;
1970 }
1971 err = -EINVAL;
1972 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01001973 if (err < 0) {
1974 stac92xx_free(codec);
1975 return err;
1976 }
1977
1978 codec->patch_ops = stac92xx_patch_ops;
1979
1980 return 0;
1981}
1982
1983static int patch_stac927x(struct hda_codec *codec)
1984{
1985 struct sigmatel_spec *spec;
1986 int err;
1987
1988 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1989 if (spec == NULL)
1990 return -ENOMEM;
1991
1992 codec->spec = spec;
Richard Fish11b44bb2006-08-23 18:31:34 +02001993 spec->num_pins = 14;
1994 spec->pin_nids = stac927x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001995 spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS,
1996 stac927x_models,
1997 stac927x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01001998 again:
Richard Fish11b44bb2006-08-23 18:31:34 +02001999 if (spec->board_config < 0) {
Matt Porter3cc08dc2006-01-23 15:27:49 +01002000 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC927x, using BIOS defaults\n");
Richard Fish11b44bb2006-08-23 18:31:34 +02002001 err = stac92xx_save_bios_config_regs(codec);
2002 if (err < 0) {
2003 stac92xx_free(codec);
2004 return err;
2005 }
2006 spec->pin_configs = spec->bios_pin_configs;
2007 } else if (stac927x_brd_tbl[spec->board_config] != NULL) {
Matt Porter3cc08dc2006-01-23 15:27:49 +01002008 spec->pin_configs = stac927x_brd_tbl[spec->board_config];
2009 stac92xx_set_config_regs(codec);
2010 }
2011
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002012 switch (spec->board_config) {
Tobin Davis93ed1502006-09-01 21:03:12 +02002013 case STAC_D965_3ST:
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002014 spec->adc_nids = stac927x_adc_nids;
2015 spec->mux_nids = stac927x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01002016 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
Matt Porter8b657272006-10-26 17:12:59 +02002017 spec->num_dmics = 0;
Tobin Davis93ed1502006-09-01 21:03:12 +02002018 spec->init = d965_core_init;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002019 spec->mixer = stac9227_mixer;
2020 break;
Tobin Davis93ed1502006-09-01 21:03:12 +02002021 case STAC_D965_5ST:
2022 spec->adc_nids = stac927x_adc_nids;
2023 spec->mux_nids = stac927x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01002024 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
Matt Porter8b657272006-10-26 17:12:59 +02002025 spec->num_dmics = 0;
Tobin Davis93ed1502006-09-01 21:03:12 +02002026 spec->init = d965_core_init;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002027 spec->mixer = stac9227_mixer;
2028 break;
2029 default:
2030 spec->adc_nids = stac927x_adc_nids;
2031 spec->mux_nids = stac927x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01002032 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
Matt Porter8b657272006-10-26 17:12:59 +02002033 spec->num_dmics = 0;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002034 spec->init = stac927x_core_init;
2035 spec->mixer = stac927x_mixer;
2036 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01002037
2038 spec->multiout.dac_nids = spec->dac_nids;
2039
2040 err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002041 if (!err) {
2042 if (spec->board_config < 0) {
2043 printk(KERN_WARNING "hda_codec: No auto-config is "
2044 "available, default to model=ref\n");
2045 spec->board_config = STAC_D965_REF;
2046 goto again;
2047 }
2048 err = -EINVAL;
2049 }
Mattc7d4b2f2005-06-27 14:59:41 +02002050 if (err < 0) {
2051 stac92xx_free(codec);
2052 return err;
2053 }
Matt2f2f4252005-04-13 14:45:30 +02002054
2055 codec->patch_ops = stac92xx_patch_ops;
2056
2057 return 0;
2058}
2059
Matt Porterf3302a52006-07-31 12:49:34 +02002060static int patch_stac9205(struct hda_codec *codec)
2061{
2062 struct sigmatel_spec *spec;
2063 int err;
2064
2065 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2066 if (spec == NULL)
2067 return -ENOMEM;
2068
2069 codec->spec = spec;
Richard Fish11b44bb2006-08-23 18:31:34 +02002070 spec->num_pins = 14;
2071 spec->pin_nids = stac9205_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002072 spec->board_config = snd_hda_check_board_config(codec, STAC_9205_MODELS,
2073 stac9205_models,
2074 stac9205_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002075 again:
Richard Fish11b44bb2006-08-23 18:31:34 +02002076 if (spec->board_config < 0) {
2077 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9205, using BIOS defaults\n");
2078 err = stac92xx_save_bios_config_regs(codec);
2079 if (err < 0) {
2080 stac92xx_free(codec);
2081 return err;
2082 }
2083 spec->pin_configs = spec->bios_pin_configs;
2084 } else {
Matt Porterf3302a52006-07-31 12:49:34 +02002085 spec->pin_configs = stac9205_brd_tbl[spec->board_config];
2086 stac92xx_set_config_regs(codec);
2087 }
2088
2089 spec->adc_nids = stac9205_adc_nids;
2090 spec->mux_nids = stac9205_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01002091 spec->num_muxes = ARRAY_SIZE(stac9205_mux_nids);
Matt Porter8b657272006-10-26 17:12:59 +02002092 spec->dmic_nids = stac9205_dmic_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01002093 spec->num_dmics = ARRAY_SIZE(stac9205_dmic_nids);
Matt Porter8b657272006-10-26 17:12:59 +02002094 spec->dmux_nid = 0x1d;
Matt Porterf3302a52006-07-31 12:49:34 +02002095
2096 spec->init = stac9205_core_init;
2097 spec->mixer = stac9205_mixer;
2098
2099 spec->multiout.dac_nids = spec->dac_nids;
2100
Matt Porter33382402006-12-18 13:17:28 +01002101 /* Configure GPIO0 as EAPD output */
2102 snd_hda_codec_write(codec, codec->afg, 0,
2103 AC_VERB_SET_GPIO_DIRECTION, 0x00000001);
2104 /* Configure GPIO0 as CMOS */
2105 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0x00000000);
2106 /* Assert GPIO0 high */
2107 snd_hda_codec_write(codec, codec->afg, 0,
2108 AC_VERB_SET_GPIO_DATA, 0x00000001);
2109 /* Enable GPIO0 */
2110 snd_hda_codec_write(codec, codec->afg, 0,
2111 AC_VERB_SET_GPIO_MASK, 0x00000001);
2112
Matt Porterf3302a52006-07-31 12:49:34 +02002113 err = stac92xx_parse_auto_config(codec, 0x1f, 0x20);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002114 if (!err) {
2115 if (spec->board_config < 0) {
2116 printk(KERN_WARNING "hda_codec: No auto-config is "
2117 "available, default to model=ref\n");
2118 spec->board_config = STAC_9205_REF;
2119 goto again;
2120 }
2121 err = -EINVAL;
2122 }
Matt Porterf3302a52006-07-31 12:49:34 +02002123 if (err < 0) {
2124 stac92xx_free(codec);
2125 return err;
2126 }
2127
2128 codec->patch_ops = stac92xx_patch_ops;
2129
2130 return 0;
2131}
2132
Matt2f2f4252005-04-13 14:45:30 +02002133/*
Guillaume Munch6d859062006-08-22 17:15:47 +02002134 * STAC9872 hack
Takashi Iwaidb064e52006-03-16 16:04:58 +01002135 */
2136
Guillaume Munch99ccc562006-08-16 19:35:12 +02002137/* static config for Sony VAIO FE550G and Sony VAIO AR */
Takashi Iwaidb064e52006-03-16 16:04:58 +01002138static hda_nid_t vaio_dacs[] = { 0x2 };
2139#define VAIO_HP_DAC 0x5
2140static hda_nid_t vaio_adcs[] = { 0x8 /*,0x6*/ };
2141static hda_nid_t vaio_mux_nids[] = { 0x15 };
2142
2143static struct hda_input_mux vaio_mux = {
2144 .num_items = 2,
2145 .items = {
Takashi Iwaid7737812006-04-25 13:05:43 +02002146 /* { "HP", 0x0 }, */
2147 { "Line", 0x1 },
Takashi Iwaidb064e52006-03-16 16:04:58 +01002148 { "Mic", 0x2 },
2149 { "PCM", 0x3 },
2150 }
2151};
2152
2153static struct hda_verb vaio_init[] = {
2154 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
2155 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
2156 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
2157 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
2158 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
2159 {0x15, AC_VERB_SET_CONNECT_SEL, 0x2}, /* mic-sel: 0a,0d,14,02 */
2160 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
2161 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
2162 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
2163 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
2164 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
2165 {}
2166};
2167
Guillaume Munch6d859062006-08-22 17:15:47 +02002168static struct hda_verb vaio_ar_init[] = {
2169 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
2170 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
2171 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
2172 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
2173/* {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },*/ /* Optical Out */
2174 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
2175 {0x15, AC_VERB_SET_CONNECT_SEL, 0x2}, /* mic-sel: 0a,0d,14,02 */
2176 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
2177 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
2178/* {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},*/ /* Optical Out */
2179 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
2180 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
2181 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
2182 {}
2183};
2184
Takashi Iwaidb064e52006-03-16 16:04:58 +01002185/* bind volumes of both NID 0x02 and 0x05 */
2186static int vaio_master_vol_put(struct snd_kcontrol *kcontrol,
2187 struct snd_ctl_elem_value *ucontrol)
2188{
2189 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2190 long *valp = ucontrol->value.integer.value;
2191 int change;
2192
2193 change = snd_hda_codec_amp_update(codec, 0x02, 0, HDA_OUTPUT, 0,
2194 0x7f, valp[0] & 0x7f);
2195 change |= snd_hda_codec_amp_update(codec, 0x02, 1, HDA_OUTPUT, 0,
2196 0x7f, valp[1] & 0x7f);
2197 snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
2198 0x7f, valp[0] & 0x7f);
2199 snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
2200 0x7f, valp[1] & 0x7f);
2201 return change;
2202}
2203
2204/* bind volumes of both NID 0x02 and 0x05 */
2205static int vaio_master_sw_put(struct snd_kcontrol *kcontrol,
2206 struct snd_ctl_elem_value *ucontrol)
2207{
2208 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2209 long *valp = ucontrol->value.integer.value;
2210 int change;
2211
2212 change = snd_hda_codec_amp_update(codec, 0x02, 0, HDA_OUTPUT, 0,
Takashi Iwaia9393d72006-05-03 11:59:03 +02002213 0x80, (valp[0] ? 0 : 0x80));
Takashi Iwaidb064e52006-03-16 16:04:58 +01002214 change |= snd_hda_codec_amp_update(codec, 0x02, 1, HDA_OUTPUT, 0,
Takashi Iwaia9393d72006-05-03 11:59:03 +02002215 0x80, (valp[1] ? 0 : 0x80));
Takashi Iwaidb064e52006-03-16 16:04:58 +01002216 snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
Takashi Iwaia9393d72006-05-03 11:59:03 +02002217 0x80, (valp[0] ? 0 : 0x80));
Takashi Iwaidb064e52006-03-16 16:04:58 +01002218 snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
Takashi Iwaia9393d72006-05-03 11:59:03 +02002219 0x80, (valp[1] ? 0 : 0x80));
Takashi Iwaidb064e52006-03-16 16:04:58 +01002220 return change;
2221}
2222
2223static struct snd_kcontrol_new vaio_mixer[] = {
2224 {
2225 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2226 .name = "Master Playback Volume",
2227 .info = snd_hda_mixer_amp_volume_info,
2228 .get = snd_hda_mixer_amp_volume_get,
2229 .put = vaio_master_vol_put,
Takashi Iwaic2566522006-08-17 18:21:36 +02002230 .tlv = { .c = snd_hda_mixer_amp_tlv },
Takashi Iwaidb064e52006-03-16 16:04:58 +01002231 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2232 },
2233 {
2234 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2235 .name = "Master Playback Switch",
2236 .info = snd_hda_mixer_amp_switch_info,
2237 .get = snd_hda_mixer_amp_switch_get,
2238 .put = vaio_master_sw_put,
2239 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2240 },
2241 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
2242 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
2243 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
2244 {
2245 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2246 .name = "Capture Source",
2247 .count = 1,
2248 .info = stac92xx_mux_enum_info,
2249 .get = stac92xx_mux_enum_get,
2250 .put = stac92xx_mux_enum_put,
2251 },
2252 {}
2253};
2254
Guillaume Munch6d859062006-08-22 17:15:47 +02002255static struct snd_kcontrol_new vaio_ar_mixer[] = {
2256 {
2257 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2258 .name = "Master Playback Volume",
2259 .info = snd_hda_mixer_amp_volume_info,
2260 .get = snd_hda_mixer_amp_volume_get,
2261 .put = vaio_master_vol_put,
2262 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2263 },
2264 {
2265 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2266 .name = "Master Playback Switch",
2267 .info = snd_hda_mixer_amp_switch_info,
2268 .get = snd_hda_mixer_amp_switch_get,
2269 .put = vaio_master_sw_put,
2270 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2271 },
2272 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
2273 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
2274 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
2275 /*HDA_CODEC_MUTE("Optical Out Switch", 0x10, 0, HDA_OUTPUT),
2276 HDA_CODEC_VOLUME("Optical Out Volume", 0x10, 0, HDA_OUTPUT),*/
2277 {
2278 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2279 .name = "Capture Source",
2280 .count = 1,
2281 .info = stac92xx_mux_enum_info,
2282 .get = stac92xx_mux_enum_get,
2283 .put = stac92xx_mux_enum_put,
2284 },
2285 {}
2286};
2287
2288static struct hda_codec_ops stac9872_patch_ops = {
Takashi Iwaidb064e52006-03-16 16:04:58 +01002289 .build_controls = stac92xx_build_controls,
2290 .build_pcms = stac92xx_build_pcms,
2291 .init = stac92xx_init,
2292 .free = stac92xx_free,
2293#ifdef CONFIG_PM
2294 .resume = stac92xx_resume,
2295#endif
2296};
2297
Guillaume Munch6d859062006-08-22 17:15:47 +02002298enum { /* FE and SZ series. id=0x83847661 and subsys=0x104D0700 or 104D1000. */
2299 CXD9872RD_VAIO,
2300 /* Unknown. id=0x83847662 and subsys=0x104D1200 or 104D1000. */
2301 STAC9872AK_VAIO,
2302 /* Unknown. id=0x83847661 and subsys=0x104D1200. */
2303 STAC9872K_VAIO,
2304 /* AR Series. id=0x83847664 and subsys=104D1300 */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002305 CXD9872AKD_VAIO,
2306 STAC_9872_MODELS,
2307};
Takashi Iwaidb064e52006-03-16 16:04:58 +01002308
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002309static const char *stac9872_models[STAC_9872_MODELS] = {
2310 [CXD9872RD_VAIO] = "vaio",
2311 [CXD9872AKD_VAIO] = "vaio-ar",
2312};
2313
2314static struct snd_pci_quirk stac9872_cfg_tbl[] = {
2315 SND_PCI_QUIRK(0x104d, 0x81e6, "Sony VAIO F/S", CXD9872RD_VAIO),
2316 SND_PCI_QUIRK(0x104d, 0x81ef, "Sony VAIO F/S", CXD9872RD_VAIO),
2317 SND_PCI_QUIRK(0x104d, 0x81fd, "Sony VAIO AR", CXD9872AKD_VAIO),
Tobin Davis68e22542007-03-12 11:36:39 +01002318 SND_PCI_QUIRK(0x104d, 0x8205, "Sony VAIO AR", CXD9872AKD_VAIO),
Takashi Iwaidb064e52006-03-16 16:04:58 +01002319 {}
2320};
2321
Guillaume Munch6d859062006-08-22 17:15:47 +02002322static int patch_stac9872(struct hda_codec *codec)
Takashi Iwaidb064e52006-03-16 16:04:58 +01002323{
2324 struct sigmatel_spec *spec;
2325 int board_config;
2326
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002327 board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
2328 stac9872_models,
2329 stac9872_cfg_tbl);
Takashi Iwaidb064e52006-03-16 16:04:58 +01002330 if (board_config < 0)
2331 /* unknown config, let generic-parser do its job... */
2332 return snd_hda_parse_generic_codec(codec);
2333
2334 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2335 if (spec == NULL)
2336 return -ENOMEM;
2337
2338 codec->spec = spec;
2339 switch (board_config) {
Guillaume Munch6d859062006-08-22 17:15:47 +02002340 case CXD9872RD_VAIO:
2341 case STAC9872AK_VAIO:
2342 case STAC9872K_VAIO:
Takashi Iwaidb064e52006-03-16 16:04:58 +01002343 spec->mixer = vaio_mixer;
2344 spec->init = vaio_init;
2345 spec->multiout.max_channels = 2;
2346 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
2347 spec->multiout.dac_nids = vaio_dacs;
2348 spec->multiout.hp_nid = VAIO_HP_DAC;
2349 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
2350 spec->adc_nids = vaio_adcs;
2351 spec->input_mux = &vaio_mux;
2352 spec->mux_nids = vaio_mux_nids;
2353 break;
Guillaume Munch6d859062006-08-22 17:15:47 +02002354
2355 case CXD9872AKD_VAIO:
2356 spec->mixer = vaio_ar_mixer;
2357 spec->init = vaio_ar_init;
2358 spec->multiout.max_channels = 2;
2359 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
2360 spec->multiout.dac_nids = vaio_dacs;
2361 spec->multiout.hp_nid = VAIO_HP_DAC;
2362 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
2363 spec->adc_nids = vaio_adcs;
2364 spec->input_mux = &vaio_mux;
2365 spec->mux_nids = vaio_mux_nids;
2366 break;
Takashi Iwaidb064e52006-03-16 16:04:58 +01002367 }
2368
Guillaume Munch6d859062006-08-22 17:15:47 +02002369 codec->patch_ops = stac9872_patch_ops;
Takashi Iwaidb064e52006-03-16 16:04:58 +01002370 return 0;
2371}
2372
2373
2374/*
Matt2f2f4252005-04-13 14:45:30 +02002375 * patch entries
2376 */
2377struct hda_codec_preset snd_hda_preset_sigmatel[] = {
2378 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
2379 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
2380 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
2381 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
2382 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
2383 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
2384 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
Matt Porter22a27c72006-07-06 18:49:10 +02002385 { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
2386 { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
2387 { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
2388 { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
2389 { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
2390 { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
Matt Porter3cc08dc2006-01-23 15:27:49 +01002391 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
2392 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
2393 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
2394 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
2395 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
2396 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
2397 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
2398 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
2399 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
2400 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
Tobin Davis8e21c342007-01-08 11:04:17 +01002401 { .id = 0x83847632, .name = "STAC9202", .patch = patch_stac925x },
2402 { .id = 0x83847633, .name = "STAC9202D", .patch = patch_stac925x },
2403 { .id = 0x83847634, .name = "STAC9250", .patch = patch_stac925x },
2404 { .id = 0x83847635, .name = "STAC9250D", .patch = patch_stac925x },
2405 { .id = 0x83847636, .name = "STAC9251", .patch = patch_stac925x },
2406 { .id = 0x83847637, .name = "STAC9250D", .patch = patch_stac925x },
Guillaume Munch6d859062006-08-22 17:15:47 +02002407 /* The following does not take into account .id=0x83847661 when subsys =
2408 * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
2409 * currently not fully supported.
2410 */
2411 { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
2412 { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
2413 { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
Matt Porterf3302a52006-07-31 12:49:34 +02002414 { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
2415 { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
2416 { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
2417 { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
2418 { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
2419 { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
2420 { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
2421 { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
Matt2f2f4252005-04-13 14:45:30 +02002422 {} /* terminator */
2423};