blob: 6dd4822dbec0e8b3f38cb4cb85da76429e2042ae [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,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010065 STAC_922X_MODELS
66};
67
68enum {
69 STAC_D965_REF,
70 STAC_D965_3ST,
71 STAC_D965_5ST,
72 STAC_927X_MODELS
73};
Matt Porter403d1942005-11-29 15:00:51 +010074
Matt2f2f4252005-04-13 14:45:30 +020075struct sigmatel_spec {
Takashi Iwaic8b6bf92005-11-17 14:57:47 +010076 struct snd_kcontrol_new *mixers[4];
Mattc7d4b2f2005-06-27 14:59:41 +020077 unsigned int num_mixers;
78
Matt Porter403d1942005-11-29 15:00:51 +010079 int board_config;
Mattc7d4b2f2005-06-27 14:59:41 +020080 unsigned int surr_switch: 1;
Matt Porter403d1942005-11-29 15:00:51 +010081 unsigned int line_switch: 1;
82 unsigned int mic_switch: 1;
Matt Porter3cc08dc2006-01-23 15:27:49 +010083 unsigned int alt_switch: 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +010084 unsigned int hp_detect: 1;
Sam Revitch62fe78e2006-05-10 15:09:17 +020085 unsigned int gpio_mute: 1;
Mattc7d4b2f2005-06-27 14:59:41 +020086
Matt2f2f4252005-04-13 14:45:30 +020087 /* playback */
88 struct hda_multi_out multiout;
Matt Porter3cc08dc2006-01-23 15:27:49 +010089 hda_nid_t dac_nids[5];
Matt2f2f4252005-04-13 14:45:30 +020090
91 /* capture */
92 hda_nid_t *adc_nids;
Matt2f2f4252005-04-13 14:45:30 +020093 unsigned int num_adcs;
Mattdabbed62005-06-14 10:19:34 +020094 hda_nid_t *mux_nids;
95 unsigned int num_muxes;
Matt Porter8b657272006-10-26 17:12:59 +020096 hda_nid_t *dmic_nids;
97 unsigned int num_dmics;
98 hda_nid_t dmux_nid;
Mattdabbed62005-06-14 10:19:34 +020099 hda_nid_t dig_in_nid;
Matt2f2f4252005-04-13 14:45:30 +0200100
Matt2f2f4252005-04-13 14:45:30 +0200101 /* pin widgets */
102 hda_nid_t *pin_nids;
103 unsigned int num_pins;
Matt2f2f4252005-04-13 14:45:30 +0200104 unsigned int *pin_configs;
Richard Fish11b44bb2006-08-23 18:31:34 +0200105 unsigned int *bios_pin_configs;
Matt2f2f4252005-04-13 14:45:30 +0200106
107 /* codec specific stuff */
108 struct hda_verb *init;
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100109 struct snd_kcontrol_new *mixer;
Matt2f2f4252005-04-13 14:45:30 +0200110
111 /* capture source */
Matt Porter8b657272006-10-26 17:12:59 +0200112 struct hda_input_mux *dinput_mux;
113 unsigned int cur_dmux;
Mattc7d4b2f2005-06-27 14:59:41 +0200114 struct hda_input_mux *input_mux;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100115 unsigned int cur_mux[3];
Matt2f2f4252005-04-13 14:45:30 +0200116
Matt Porter403d1942005-11-29 15:00:51 +0100117 /* i/o switches */
118 unsigned int io_switch[2];
Matt2f2f4252005-04-13 14:45:30 +0200119
Mattc7d4b2f2005-06-27 14:59:41 +0200120 struct hda_pcm pcm_rec[2]; /* PCM information */
121
122 /* dynamic controls and input_mux */
123 struct auto_pin_cfg autocfg;
124 unsigned int num_kctl_alloc, num_kctl_used;
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100125 struct snd_kcontrol_new *kctl_alloc;
Matt Porter8b657272006-10-26 17:12:59 +0200126 struct hda_input_mux private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +0200127 struct hda_input_mux private_imux;
Matt2f2f4252005-04-13 14:45:30 +0200128};
129
130static hda_nid_t stac9200_adc_nids[1] = {
131 0x03,
132};
133
134static hda_nid_t stac9200_mux_nids[1] = {
135 0x0c,
136};
137
138static hda_nid_t stac9200_dac_nids[1] = {
139 0x02,
140};
141
Tobin Davis8e21c342007-01-08 11:04:17 +0100142static hda_nid_t stac925x_adc_nids[1] = {
143 0x03,
144};
145
146static hda_nid_t stac925x_mux_nids[1] = {
147 0x0f,
148};
149
150static hda_nid_t stac925x_dac_nids[1] = {
151 0x02,
152};
153
Matt2f2f4252005-04-13 14:45:30 +0200154static hda_nid_t stac922x_adc_nids[2] = {
155 0x06, 0x07,
156};
157
158static hda_nid_t stac922x_mux_nids[2] = {
159 0x12, 0x13,
160};
161
Matt Porter3cc08dc2006-01-23 15:27:49 +0100162static hda_nid_t stac927x_adc_nids[3] = {
163 0x07, 0x08, 0x09
164};
165
166static hda_nid_t stac927x_mux_nids[3] = {
167 0x15, 0x16, 0x17
168};
169
Matt Porterf3302a52006-07-31 12:49:34 +0200170static hda_nid_t stac9205_adc_nids[2] = {
171 0x12, 0x13
172};
173
174static hda_nid_t stac9205_mux_nids[2] = {
175 0x19, 0x1a
176};
177
Takashi Iwai25494132007-03-12 12:36:16 +0100178static hda_nid_t stac9205_dmic_nids[2] = {
179 0x17, 0x18,
Matt Porter8b657272006-10-26 17:12:59 +0200180};
181
Mattc7d4b2f2005-06-27 14:59:41 +0200182static hda_nid_t stac9200_pin_nids[8] = {
Tobin Davis93ed1502006-09-01 21:03:12 +0200183 0x08, 0x09, 0x0d, 0x0e,
184 0x0f, 0x10, 0x11, 0x12,
Matt2f2f4252005-04-13 14:45:30 +0200185};
186
Tobin Davis8e21c342007-01-08 11:04:17 +0100187static hda_nid_t stac925x_pin_nids[8] = {
188 0x07, 0x08, 0x0a, 0x0b,
189 0x0c, 0x0d, 0x10, 0x11,
190};
191
Matt2f2f4252005-04-13 14:45:30 +0200192static hda_nid_t stac922x_pin_nids[10] = {
193 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
194 0x0f, 0x10, 0x11, 0x15, 0x1b,
195};
196
Matt Porter3cc08dc2006-01-23 15:27:49 +0100197static hda_nid_t stac927x_pin_nids[14] = {
198 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
199 0x0f, 0x10, 0x11, 0x12, 0x13,
200 0x14, 0x21, 0x22, 0x23,
201};
202
Matt Porterf3302a52006-07-31 12:49:34 +0200203static hda_nid_t stac9205_pin_nids[12] = {
204 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
205 0x0f, 0x14, 0x16, 0x17, 0x18,
206 0x21, 0x22,
207
208};
209
Matt Porter8b657272006-10-26 17:12:59 +0200210static int stac92xx_dmux_enum_info(struct snd_kcontrol *kcontrol,
211 struct snd_ctl_elem_info *uinfo)
212{
213 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
214 struct sigmatel_spec *spec = codec->spec;
215 return snd_hda_input_mux_info(spec->dinput_mux, uinfo);
216}
217
218static int stac92xx_dmux_enum_get(struct snd_kcontrol *kcontrol,
219 struct snd_ctl_elem_value *ucontrol)
220{
221 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
222 struct sigmatel_spec *spec = codec->spec;
223
224 ucontrol->value.enumerated.item[0] = spec->cur_dmux;
225 return 0;
226}
227
228static int stac92xx_dmux_enum_put(struct snd_kcontrol *kcontrol,
229 struct snd_ctl_elem_value *ucontrol)
230{
231 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
232 struct sigmatel_spec *spec = codec->spec;
233
234 return snd_hda_input_mux_put(codec, spec->dinput_mux, ucontrol,
235 spec->dmux_nid, &spec->cur_dmux);
236}
237
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100238static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Matt2f2f4252005-04-13 14:45:30 +0200239{
240 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
241 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +0200242 return snd_hda_input_mux_info(spec->input_mux, uinfo);
Matt2f2f4252005-04-13 14:45:30 +0200243}
244
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100245static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200246{
247 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
248 struct sigmatel_spec *spec = codec->spec;
249 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
250
251 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
252 return 0;
253}
254
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100255static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200256{
257 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
258 struct sigmatel_spec *spec = codec->spec;
259 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
260
Mattc7d4b2f2005-06-27 14:59:41 +0200261 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
Matt2f2f4252005-04-13 14:45:30 +0200262 spec->mux_nids[adc_idx], &spec->cur_mux[adc_idx]);
263}
264
Mattc7d4b2f2005-06-27 14:59:41 +0200265static struct hda_verb stac9200_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200266 /* set dac0mux for dac converter */
Mattc7d4b2f2005-06-27 14:59:41 +0200267 { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
Matt2f2f4252005-04-13 14:45:30 +0200268 {}
269};
270
Tobin Davis8e21c342007-01-08 11:04:17 +0100271static struct hda_verb stac925x_core_init[] = {
272 /* set dac0mux for dac converter */
273 { 0x06, AC_VERB_SET_CONNECT_SEL, 0x00},
274 {}
275};
276
Mattc7d4b2f2005-06-27 14:59:41 +0200277static struct hda_verb stac922x_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200278 /* set master volume and direct control */
Mattc7d4b2f2005-06-27 14:59:41 +0200279 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matt2f2f4252005-04-13 14:45:30 +0200280 {}
281};
282
Tobin Davis93ed1502006-09-01 21:03:12 +0200283static struct hda_verb d965_core_init[] = {
Takashi Iwai19039bd2006-06-28 15:52:16 +0200284 /* set master volume and direct control */
Tobin Davis93ed1502006-09-01 21:03:12 +0200285 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Takashi Iwai19039bd2006-06-28 15:52:16 +0200286 /* unmute node 0x1b */
287 { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
288 /* select node 0x03 as DAC */
289 { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
290 {}
291};
292
Matt Porter3cc08dc2006-01-23 15:27:49 +0100293static struct hda_verb stac927x_core_init[] = {
294 /* set master volume and direct control */
295 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
296 {}
297};
298
Matt Porterf3302a52006-07-31 12:49:34 +0200299static struct hda_verb stac9205_core_init[] = {
300 /* set master volume and direct control */
301 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
302 {}
303};
304
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100305static struct snd_kcontrol_new stac9200_mixer[] = {
Matt2f2f4252005-04-13 14:45:30 +0200306 HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
307 HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
308 {
309 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
310 .name = "Input Source",
311 .count = 1,
312 .info = stac92xx_mux_enum_info,
313 .get = stac92xx_mux_enum_get,
314 .put = stac92xx_mux_enum_put,
315 },
316 HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
317 HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
Mattc7d4b2f2005-06-27 14:59:41 +0200318 HDA_CODEC_VOLUME("Capture Mux Volume", 0x0c, 0, HDA_OUTPUT),
Matt2f2f4252005-04-13 14:45:30 +0200319 { } /* end */
320};
321
Tobin Davis8e21c342007-01-08 11:04:17 +0100322static struct snd_kcontrol_new stac925x_mixer[] = {
323 HDA_CODEC_VOLUME("Master Playback Volume", 0xe, 0, HDA_OUTPUT),
324 HDA_CODEC_MUTE("Master Playback Switch", 0xe, 0, HDA_OUTPUT),
325 {
326 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
327 .name = "Input Source",
328 .count = 1,
329 .info = stac92xx_mux_enum_info,
330 .get = stac92xx_mux_enum_get,
331 .put = stac92xx_mux_enum_put,
332 },
333 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_OUTPUT),
334 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_OUTPUT),
335 HDA_CODEC_VOLUME("Capture Mux Volume", 0x0f, 0, HDA_OUTPUT),
336 { } /* end */
337};
338
Mattc7d4b2f2005-06-27 14:59:41 +0200339/* This needs to be generated dynamically based on sequence */
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100340static struct snd_kcontrol_new stac922x_mixer[] = {
Matt2f2f4252005-04-13 14:45:30 +0200341 {
342 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
343 .name = "Input Source",
344 .count = 1,
345 .info = stac92xx_mux_enum_info,
346 .get = stac92xx_mux_enum_get,
347 .put = stac92xx_mux_enum_put,
348 },
349 HDA_CODEC_VOLUME("Capture Volume", 0x17, 0x0, HDA_INPUT),
Takashi Iwai0fd17082006-01-13 18:46:21 +0100350 HDA_CODEC_MUTE("Capture Switch", 0x17, 0x0, HDA_INPUT),
Matt2f2f4252005-04-13 14:45:30 +0200351 HDA_CODEC_VOLUME("Mux Capture Volume", 0x12, 0x0, HDA_OUTPUT),
352 { } /* end */
353};
354
Takashi Iwai19039bd2006-06-28 15:52:16 +0200355/* This needs to be generated dynamically based on sequence */
356static struct snd_kcontrol_new stac9227_mixer[] = {
357 {
358 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
359 .name = "Input Source",
360 .count = 1,
361 .info = stac92xx_mux_enum_info,
362 .get = stac92xx_mux_enum_get,
363 .put = stac92xx_mux_enum_put,
364 },
365 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
366 HDA_CODEC_MUTE("Capture Switch", 0x1b, 0x0, HDA_OUTPUT),
367 { } /* end */
368};
369
Takashi Iwaid1d985f2006-11-23 19:27:12 +0100370static struct snd_kcontrol_new stac927x_mixer[] = {
Matt Porter3cc08dc2006-01-23 15:27:49 +0100371 {
372 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
373 .name = "Input Source",
374 .count = 1,
375 .info = stac92xx_mux_enum_info,
376 .get = stac92xx_mux_enum_get,
377 .put = stac92xx_mux_enum_put,
378 },
379 HDA_CODEC_VOLUME("InMux Capture Volume", 0x15, 0x0, HDA_OUTPUT),
380 HDA_CODEC_VOLUME("InVol Capture Volume", 0x18, 0x0, HDA_INPUT),
381 HDA_CODEC_MUTE("ADCMux Capture Switch", 0x1b, 0x0, HDA_OUTPUT),
382 { } /* end */
383};
384
Takashi Iwaid1d985f2006-11-23 19:27:12 +0100385static struct snd_kcontrol_new stac9205_mixer[] = {
Matt Porterf3302a52006-07-31 12:49:34 +0200386 {
387 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Matt Porter8b657272006-10-26 17:12:59 +0200388 .name = "Digital Input Source",
389 .count = 1,
390 .info = stac92xx_dmux_enum_info,
391 .get = stac92xx_dmux_enum_get,
392 .put = stac92xx_dmux_enum_put,
393 },
394 {
395 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Matt Porterf3302a52006-07-31 12:49:34 +0200396 .name = "Input Source",
397 .count = 1,
398 .info = stac92xx_mux_enum_info,
399 .get = stac92xx_mux_enum_get,
400 .put = stac92xx_mux_enum_put,
401 },
402 HDA_CODEC_VOLUME("InMux Capture Volume", 0x19, 0x0, HDA_OUTPUT),
403 HDA_CODEC_VOLUME("InVol Capture Volume", 0x1b, 0x0, HDA_INPUT),
404 HDA_CODEC_MUTE("ADCMux Capture Switch", 0x1d, 0x0, HDA_OUTPUT),
405 { } /* end */
406};
407
Matt2f2f4252005-04-13 14:45:30 +0200408static int stac92xx_build_controls(struct hda_codec *codec)
409{
410 struct sigmatel_spec *spec = codec->spec;
411 int err;
Mattc7d4b2f2005-06-27 14:59:41 +0200412 int i;
Matt2f2f4252005-04-13 14:45:30 +0200413
414 err = snd_hda_add_new_ctls(codec, spec->mixer);
415 if (err < 0)
416 return err;
Mattc7d4b2f2005-06-27 14:59:41 +0200417
418 for (i = 0; i < spec->num_mixers; i++) {
419 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
420 if (err < 0)
421 return err;
422 }
423
Mattdabbed62005-06-14 10:19:34 +0200424 if (spec->multiout.dig_out_nid) {
425 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
426 if (err < 0)
427 return err;
428 }
429 if (spec->dig_in_nid) {
430 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
431 if (err < 0)
432 return err;
433 }
434 return 0;
Matt2f2f4252005-04-13 14:45:30 +0200435}
436
Matt Porter403d1942005-11-29 15:00:51 +0100437static unsigned int ref9200_pin_configs[8] = {
Mattdabbed62005-06-14 10:19:34 +0200438 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
Matt2f2f4252005-04-13 14:45:30 +0200439 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
440};
441
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100442static unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
443 [STAC_REF] = ref9200_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +0100444};
445
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100446static const char *stac9200_models[STAC_9200_MODELS] = {
447 [STAC_REF] = "ref",
448};
449
450static struct snd_pci_quirk stac9200_cfg_tbl[] = {
451 /* SigmaTel reference board */
452 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
453 "DFI LanParty", STAC_REF),
Matt Portere7377072006-11-06 11:20:38 +0100454 /* Dell laptops have BIOS problem */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100455 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01b5,
456 "Dell Inspiron 630m", STAC_REF),
457 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c2,
458 "Dell Latitude D620", STAC_REF),
459 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cb,
460 "Dell Latitude 120L", STAC_REF),
Cory T. Tusar877b8662007-01-30 17:30:55 +0100461 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cc,
462 "Dell Latitude D820", STAC_REF),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +0100463 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cd,
464 "Dell Inspiron E1705/9400", STAC_REF),
465 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ce,
466 "Dell XPS M1710", STAC_REF),
Takashi Iwaif0f96742007-02-14 00:59:17 +0100467 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cf,
468 "Dell Precision M90", STAC_REF),
Matt Porter403d1942005-11-29 15:00:51 +0100469 {} /* terminator */
470};
471
Tobin Davis8e21c342007-01-08 11:04:17 +0100472static unsigned int ref925x_pin_configs[8] = {
473 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
474 0x90a70320, 0x02214210, 0x400003f1, 0x9033032e,
475};
476
477static unsigned int stac925x_MA6_pin_configs[8] = {
478 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
479 0x90a70320, 0x90100211, 0x400003f1, 0x9033032e,
480};
481
482static unsigned int stac925xM2_2_pin_configs[8] = {
483 0x40c003f3, 0x424503f2, 0x041800f4, 0x02a19020,
484 0x50a103F0, 0x90100210, 0x400003f1, 0x9033032e,
485};
486
487static unsigned int *stac925x_brd_tbl[STAC_925x_MODELS] = {
488 [STAC_REF] = ref925x_pin_configs,
489 [STAC_M2_2] = stac925xM2_2_pin_configs,
490 [STAC_MA6] = stac925x_MA6_pin_configs,
491};
492
493static const char *stac925x_models[STAC_925x_MODELS] = {
494 [STAC_REF] = "ref",
495 [STAC_M2_2] = "m2-2",
496 [STAC_MA6] = "m6",
497};
498
499static struct snd_pci_quirk stac925x_cfg_tbl[] = {
500 /* SigmaTel reference board */
501 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, "DFI LanParty", STAC_REF),
502 SND_PCI_QUIRK(0x107b, 0x0316, "Gateway M255", STAC_REF),
503 SND_PCI_QUIRK(0x107b, 0x0366, "Gateway MP6954", STAC_REF),
504 SND_PCI_QUIRK(0x107b, 0x0461, "Gateway NX560XL", STAC_MA6),
505 SND_PCI_QUIRK(0x1002, 0x437b, "Gateway MX6453", STAC_M2_2),
506 {} /* terminator */
507};
508
Matt Porter403d1942005-11-29 15:00:51 +0100509static unsigned int ref922x_pin_configs[10] = {
510 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
511 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
Matt2f2f4252005-04-13 14:45:30 +0200512 0x40000100, 0x40000100,
513};
514
Matt Porter403d1942005-11-29 15:00:51 +0100515static unsigned int d945gtp3_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +0100516 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
Matt Porter403d1942005-11-29 15:00:51 +0100517 0x40000100, 0x40000100, 0x40000100, 0x40000100,
518 0x02a19120, 0x40000100,
519};
520
521static unsigned int d945gtp5_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +0100522 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
523 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
Matt Porter403d1942005-11-29 15:00:51 +0100524 0x02a19320, 0x40000100,
525};
526
Nicolas Boichat6f0778d2007-03-15 12:38:15 +0100527static unsigned int macbook_pro_v1_pin_configs[10] = {
528 0x0321e230, 0x03a1e020, 0x9017e110, 0x01014010,
529 0x01a19021, 0x0381e021, 0x1345e240, 0x13c5e22e,
530 0x02a19320, 0x400000fb
531};
532
533static unsigned int macbook_pro_v2_pin_configs[10] = {
Takashi Iwai3fc24d82007-02-16 13:27:18 +0100534 0x0221401f, 0x90a70120, 0x01813024, 0x01014010,
535 0x400000fd, 0x01016011, 0x1345e240, 0x13c5e22e,
536 0x400000fc, 0x400000fb,
537};
538
Takashi Iwai19039bd2006-06-28 15:52:16 +0200539static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100540 [STAC_D945_REF] = ref922x_pin_configs,
Takashi Iwai19039bd2006-06-28 15:52:16 +0200541 [STAC_D945GTP3] = d945gtp3_pin_configs,
542 [STAC_D945GTP5] = d945gtp5_pin_configs,
Takashi Iwai02a50392007-03-19 11:42:18 +0100543 [STAC_MACMINI] = macbook_pro_v1_pin_configs,
544 [STAC_MACBOOK] = macbook_pro_v1_pin_configs,
Nicolas Boichat6f0778d2007-03-15 12:38:15 +0100545 [STAC_MACBOOK_PRO_V1] = macbook_pro_v1_pin_configs,
546 [STAC_MACBOOK_PRO_V2] = macbook_pro_v2_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +0100547};
548
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100549static const char *stac922x_models[STAC_922X_MODELS] = {
550 [STAC_D945_REF] = "ref",
551 [STAC_D945GTP5] = "5stack",
552 [STAC_D945GTP3] = "3stack",
553 [STAC_MACMINI] = "macmini",
Takashi Iwai3fc24d82007-02-16 13:27:18 +0100554 [STAC_MACBOOK] = "macbook",
Nicolas Boichat6f0778d2007-03-15 12:38:15 +0100555 [STAC_MACBOOK_PRO_V1] = "macbook-pro-v1",
556 [STAC_MACBOOK_PRO_V2] = "macbook-pro",
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100557};
558
559static struct snd_pci_quirk stac922x_cfg_tbl[] = {
560 /* SigmaTel reference board */
561 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
562 "DFI LanParty", STAC_D945_REF),
563 /* Intel 945G based systems */
564 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101,
565 "Intel D945G", STAC_D945GTP3),
566 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0202,
567 "Intel D945G", STAC_D945GTP3),
568 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0606,
569 "Intel D945G", STAC_D945GTP3),
570 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0601,
571 "Intel D945G", STAC_D945GTP3),
572 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0111,
573 "Intel D945G", STAC_D945GTP3),
574 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1115,
575 "Intel D945G", STAC_D945GTP3),
576 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1116,
577 "Intel D945G", STAC_D945GTP3),
578 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1117,
579 "Intel D945G", STAC_D945GTP3),
580 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1118,
581 "Intel D945G", STAC_D945GTP3),
582 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1119,
583 "Intel D945G", STAC_D945GTP3),
584 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x8826,
585 "Intel D945G", STAC_D945GTP3),
586 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5049,
587 "Intel D945G", STAC_D945GTP3),
588 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5055,
589 "Intel D945G", STAC_D945GTP3),
590 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5048,
591 "Intel D945G", STAC_D945GTP3),
592 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0110,
593 "Intel D945G", STAC_D945GTP3),
594 /* Intel D945G 5-stack systems */
595 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0404,
596 "Intel D945G", STAC_D945GTP5),
597 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0303,
598 "Intel D945G", STAC_D945GTP5),
599 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0013,
600 "Intel D945G", STAC_D945GTP5),
601 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0417,
602 "Intel D945G", STAC_D945GTP5),
603 /* Intel 945P based systems */
604 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0b0b,
605 "Intel D945P", STAC_D945GTP3),
606 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0112,
607 "Intel D945P", STAC_D945GTP3),
608 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0d0d,
609 "Intel D945P", STAC_D945GTP3),
610 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0909,
611 "Intel D945P", STAC_D945GTP3),
612 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0505,
613 "Intel D945P", STAC_D945GTP3),
614 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707,
615 "Intel D945P", STAC_D945GTP5),
616 /* other systems */
617 /* Apple Mac Mini (early 2006) */
618 SND_PCI_QUIRK(0x8384, 0x7680,
619 "Mac Mini", STAC_MACMINI),
Matt Porter403d1942005-11-29 15:00:51 +0100620 {} /* terminator */
621};
622
Matt Porter3cc08dc2006-01-23 15:27:49 +0100623static unsigned int ref927x_pin_configs[14] = {
Tobin Davis93ed1502006-09-01 21:03:12 +0200624 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
625 0x01a19040, 0x01011012, 0x01016011, 0x0101201f,
626 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
627 0x01c42190, 0x40000100,
Matt Porter3cc08dc2006-01-23 15:27:49 +0100628};
629
Tobin Davis93ed1502006-09-01 21:03:12 +0200630static unsigned int d965_3st_pin_configs[14] = {
Tobin Davis81d3dbd2006-08-22 19:44:45 +0200631 0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
632 0x01a19021, 0x01813024, 0x40000100, 0x40000100,
633 0x40000100, 0x40000100, 0x40000100, 0x40000100,
634 0x40000100, 0x40000100
635};
636
Tobin Davis93ed1502006-09-01 21:03:12 +0200637static unsigned int d965_5st_pin_configs[14] = {
638 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
639 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
640 0x40000100, 0x40000100, 0x40000100, 0x01442070,
641 0x40000100, 0x40000100
642};
643
644static unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100645 [STAC_D965_REF] = ref927x_pin_configs,
Tobin Davis93ed1502006-09-01 21:03:12 +0200646 [STAC_D965_3ST] = d965_3st_pin_configs,
647 [STAC_D965_5ST] = d965_5st_pin_configs,
Matt Porter3cc08dc2006-01-23 15:27:49 +0100648};
649
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100650static const char *stac927x_models[STAC_927X_MODELS] = {
651 [STAC_D965_REF] = "ref",
652 [STAC_D965_3ST] = "3stack",
653 [STAC_D965_5ST] = "5stack",
654};
655
656static struct snd_pci_quirk stac927x_cfg_tbl[] = {
657 /* SigmaTel reference board */
658 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
659 "DFI LanParty", STAC_D965_REF),
Tobin Davis81d3dbd2006-08-22 19:44:45 +0200660 /* Intel 946 based systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100661 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST),
662 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST),
Tobin Davis93ed1502006-09-01 21:03:12 +0200663 /* 965 based 3 stack systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100664 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2116, "Intel D965", STAC_D965_3ST),
665 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2115, "Intel D965", STAC_D965_3ST),
666 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2114, "Intel D965", STAC_D965_3ST),
667 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2113, "Intel D965", STAC_D965_3ST),
668 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2112, "Intel D965", STAC_D965_3ST),
669 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2111, "Intel D965", STAC_D965_3ST),
670 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2110, "Intel D965", STAC_D965_3ST),
671 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2009, "Intel D965", STAC_D965_3ST),
672 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2008, "Intel D965", STAC_D965_3ST),
673 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2007, "Intel D965", STAC_D965_3ST),
674 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2006, "Intel D965", STAC_D965_3ST),
675 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2005, "Intel D965", STAC_D965_3ST),
676 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2004, "Intel D965", STAC_D965_3ST),
677 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2003, "Intel D965", STAC_D965_3ST),
678 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2002, "Intel D965", STAC_D965_3ST),
679 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2001, "Intel D965", STAC_D965_3ST),
Tobin Davis93ed1502006-09-01 21:03:12 +0200680 /* 965 based 5 stack systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100681 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2301, "Intel D965", STAC_D965_5ST),
682 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2302, "Intel D965", STAC_D965_5ST),
683 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2303, "Intel D965", STAC_D965_5ST),
684 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2304, "Intel D965", STAC_D965_5ST),
685 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2305, "Intel D965", STAC_D965_5ST),
686 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2501, "Intel D965", STAC_D965_5ST),
687 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2502, "Intel D965", STAC_D965_5ST),
688 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2503, "Intel D965", STAC_D965_5ST),
689 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2504, "Intel D965", STAC_D965_5ST),
Matt Porter3cc08dc2006-01-23 15:27:49 +0100690 {} /* terminator */
691};
692
Matt Porterf3302a52006-07-31 12:49:34 +0200693static unsigned int ref9205_pin_configs[12] = {
694 0x40000100, 0x40000100, 0x01016011, 0x01014010,
Matt Porter8b657272006-10-26 17:12:59 +0200695 0x01813122, 0x01a19021, 0x40000100, 0x40000100,
696 0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
Matt Porterf3302a52006-07-31 12:49:34 +0200697};
698
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100699static unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
Matt Porterf3302a52006-07-31 12:49:34 +0200700 ref9205_pin_configs,
701};
702
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100703static const char *stac9205_models[STAC_9205_MODELS] = {
704 [STAC_9205_REF] = "ref",
705};
706
707static struct snd_pci_quirk stac9205_cfg_tbl[] = {
708 /* SigmaTel reference board */
709 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
710 "DFI LanParty", STAC_9205_REF),
Matt Porterf3302a52006-07-31 12:49:34 +0200711 {} /* terminator */
712};
713
Richard Fish11b44bb2006-08-23 18:31:34 +0200714static int stac92xx_save_bios_config_regs(struct hda_codec *codec)
715{
716 int i;
717 struct sigmatel_spec *spec = codec->spec;
718
719 if (! spec->bios_pin_configs) {
720 spec->bios_pin_configs = kcalloc(spec->num_pins,
721 sizeof(*spec->bios_pin_configs), GFP_KERNEL);
722 if (! spec->bios_pin_configs)
723 return -ENOMEM;
724 }
725
726 for (i = 0; i < spec->num_pins; i++) {
727 hda_nid_t nid = spec->pin_nids[i];
728 unsigned int pin_cfg;
729
730 pin_cfg = snd_hda_codec_read(codec, nid, 0,
731 AC_VERB_GET_CONFIG_DEFAULT, 0x00);
732 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x bios pin config %8.8x\n",
733 nid, pin_cfg);
734 spec->bios_pin_configs[i] = pin_cfg;
735 }
736
737 return 0;
738}
739
Matt2f2f4252005-04-13 14:45:30 +0200740static void stac92xx_set_config_regs(struct hda_codec *codec)
741{
742 int i;
743 struct sigmatel_spec *spec = codec->spec;
744 unsigned int pin_cfg;
745
Richard Fish11b44bb2006-08-23 18:31:34 +0200746 if (! spec->pin_nids || ! spec->pin_configs)
747 return;
748
749 for (i = 0; i < spec->num_pins; i++) {
Matt2f2f4252005-04-13 14:45:30 +0200750 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
751 AC_VERB_SET_CONFIG_DEFAULT_BYTES_0,
752 spec->pin_configs[i] & 0x000000ff);
753 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
754 AC_VERB_SET_CONFIG_DEFAULT_BYTES_1,
755 (spec->pin_configs[i] & 0x0000ff00) >> 8);
756 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
757 AC_VERB_SET_CONFIG_DEFAULT_BYTES_2,
758 (spec->pin_configs[i] & 0x00ff0000) >> 16);
759 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
760 AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
761 spec->pin_configs[i] >> 24);
762 pin_cfg = snd_hda_codec_read(codec, spec->pin_nids[i], 0,
763 AC_VERB_GET_CONFIG_DEFAULT,
764 0x00);
Matt Porter403d1942005-11-29 15:00:51 +0100765 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 +0200766 }
767}
Matt2f2f4252005-04-13 14:45:30 +0200768
Matt2f2f4252005-04-13 14:45:30 +0200769/*
770 * Analog playback callbacks
771 */
772static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
773 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100774 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200775{
776 struct sigmatel_spec *spec = codec->spec;
777 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
778}
779
780static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
781 struct hda_codec *codec,
782 unsigned int stream_tag,
783 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100784 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200785{
786 struct sigmatel_spec *spec = codec->spec;
Matt Porter403d1942005-11-29 15:00:51 +0100787 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
Matt2f2f4252005-04-13 14:45:30 +0200788}
789
790static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
791 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100792 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200793{
794 struct sigmatel_spec *spec = codec->spec;
795 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
796}
797
798/*
Mattdabbed62005-06-14 10:19:34 +0200799 * Digital playback callbacks
800 */
801static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
802 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100803 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +0200804{
805 struct sigmatel_spec *spec = codec->spec;
806 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
807}
808
809static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
810 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100811 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +0200812{
813 struct sigmatel_spec *spec = codec->spec;
814 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
815}
816
817
818/*
Matt2f2f4252005-04-13 14:45:30 +0200819 * Analog capture callbacks
820 */
821static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
822 struct hda_codec *codec,
823 unsigned int stream_tag,
824 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100825 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200826{
827 struct sigmatel_spec *spec = codec->spec;
828
829 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
830 stream_tag, 0, format);
831 return 0;
832}
833
834static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
835 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100836 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200837{
838 struct sigmatel_spec *spec = codec->spec;
839
840 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 0, 0, 0);
841 return 0;
842}
843
Mattdabbed62005-06-14 10:19:34 +0200844static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
845 .substreams = 1,
846 .channels_min = 2,
847 .channels_max = 2,
848 /* NID is set in stac92xx_build_pcms */
849 .ops = {
850 .open = stac92xx_dig_playback_pcm_open,
851 .close = stac92xx_dig_playback_pcm_close
852 },
853};
854
855static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
856 .substreams = 1,
857 .channels_min = 2,
858 .channels_max = 2,
859 /* NID is set in stac92xx_build_pcms */
860};
861
Matt2f2f4252005-04-13 14:45:30 +0200862static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
863 .substreams = 1,
864 .channels_min = 2,
Mattc7d4b2f2005-06-27 14:59:41 +0200865 .channels_max = 8,
Matt2f2f4252005-04-13 14:45:30 +0200866 .nid = 0x02, /* NID to query formats and rates */
867 .ops = {
868 .open = stac92xx_playback_pcm_open,
869 .prepare = stac92xx_playback_pcm_prepare,
870 .cleanup = stac92xx_playback_pcm_cleanup
871 },
872};
873
Matt Porter3cc08dc2006-01-23 15:27:49 +0100874static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
875 .substreams = 1,
876 .channels_min = 2,
877 .channels_max = 2,
878 .nid = 0x06, /* NID to query formats and rates */
879 .ops = {
880 .open = stac92xx_playback_pcm_open,
881 .prepare = stac92xx_playback_pcm_prepare,
882 .cleanup = stac92xx_playback_pcm_cleanup
883 },
884};
885
Matt2f2f4252005-04-13 14:45:30 +0200886static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
887 .substreams = 2,
888 .channels_min = 2,
889 .channels_max = 2,
Matt Porter3cc08dc2006-01-23 15:27:49 +0100890 /* NID is set in stac92xx_build_pcms */
Matt2f2f4252005-04-13 14:45:30 +0200891 .ops = {
892 .prepare = stac92xx_capture_pcm_prepare,
893 .cleanup = stac92xx_capture_pcm_cleanup
894 },
895};
896
897static int stac92xx_build_pcms(struct hda_codec *codec)
898{
899 struct sigmatel_spec *spec = codec->spec;
900 struct hda_pcm *info = spec->pcm_rec;
901
902 codec->num_pcms = 1;
903 codec->pcm_info = info;
904
Mattc7d4b2f2005-06-27 14:59:41 +0200905 info->name = "STAC92xx Analog";
Matt2f2f4252005-04-13 14:45:30 +0200906 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
Matt2f2f4252005-04-13 14:45:30 +0200907 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100908 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
909
910 if (spec->alt_switch) {
911 codec->num_pcms++;
912 info++;
913 info->name = "STAC92xx Analog Alt";
914 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
915 }
Matt2f2f4252005-04-13 14:45:30 +0200916
Mattdabbed62005-06-14 10:19:34 +0200917 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
918 codec->num_pcms++;
919 info++;
920 info->name = "STAC92xx Digital";
921 if (spec->multiout.dig_out_nid) {
922 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
923 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
924 }
925 if (spec->dig_in_nid) {
926 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
927 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
928 }
929 }
930
Matt2f2f4252005-04-13 14:45:30 +0200931 return 0;
932}
933
Takashi Iwaic960a032006-03-23 17:06:28 +0100934static unsigned int stac92xx_get_vref(struct hda_codec *codec, hda_nid_t nid)
935{
936 unsigned int pincap = snd_hda_param_read(codec, nid,
937 AC_PAR_PIN_CAP);
938 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
939 if (pincap & AC_PINCAP_VREF_100)
940 return AC_PINCTL_VREF_100;
941 if (pincap & AC_PINCAP_VREF_80)
942 return AC_PINCTL_VREF_80;
943 if (pincap & AC_PINCAP_VREF_50)
944 return AC_PINCTL_VREF_50;
945 if (pincap & AC_PINCAP_VREF_GRD)
946 return AC_PINCTL_VREF_GRD;
947 return 0;
948}
949
Matt Porter403d1942005-11-29 15:00:51 +0100950static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
951
952{
953 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
954}
955
956static int stac92xx_io_switch_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
957{
958 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
959 uinfo->count = 1;
960 uinfo->value.integer.min = 0;
961 uinfo->value.integer.max = 1;
962 return 0;
963}
964
965static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
966{
967 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
968 struct sigmatel_spec *spec = codec->spec;
969 int io_idx = kcontrol-> private_value & 0xff;
970
971 ucontrol->value.integer.value[0] = spec->io_switch[io_idx];
972 return 0;
973}
974
975static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
976{
977 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
978 struct sigmatel_spec *spec = codec->spec;
979 hda_nid_t nid = kcontrol->private_value >> 8;
980 int io_idx = kcontrol-> private_value & 0xff;
981 unsigned short val = ucontrol->value.integer.value[0];
982
983 spec->io_switch[io_idx] = val;
984
985 if (val)
986 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
Takashi Iwaic960a032006-03-23 17:06:28 +0100987 else {
988 unsigned int pinctl = AC_PINCTL_IN_EN;
989 if (io_idx) /* set VREF for mic */
990 pinctl |= stac92xx_get_vref(codec, nid);
991 stac92xx_auto_set_pinctl(codec, nid, pinctl);
992 }
Matt Porter403d1942005-11-29 15:00:51 +0100993 return 1;
994}
995
996#define STAC_CODEC_IO_SWITCH(xname, xpval) \
997 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
998 .name = xname, \
999 .index = 0, \
1000 .info = stac92xx_io_switch_info, \
1001 .get = stac92xx_io_switch_get, \
1002 .put = stac92xx_io_switch_put, \
1003 .private_value = xpval, \
1004 }
1005
1006
Mattc7d4b2f2005-06-27 14:59:41 +02001007enum {
1008 STAC_CTL_WIDGET_VOL,
1009 STAC_CTL_WIDGET_MUTE,
Matt Porter403d1942005-11-29 15:00:51 +01001010 STAC_CTL_WIDGET_IO_SWITCH,
Mattc7d4b2f2005-06-27 14:59:41 +02001011};
1012
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001013static struct snd_kcontrol_new stac92xx_control_templates[] = {
Mattc7d4b2f2005-06-27 14:59:41 +02001014 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
1015 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Matt Porter403d1942005-11-29 15:00:51 +01001016 STAC_CODEC_IO_SWITCH(NULL, 0),
Mattc7d4b2f2005-06-27 14:59:41 +02001017};
1018
1019/* add dynamic controls */
1020static int stac92xx_add_control(struct sigmatel_spec *spec, int type, const char *name, unsigned long val)
1021{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001022 struct snd_kcontrol_new *knew;
Mattc7d4b2f2005-06-27 14:59:41 +02001023
1024 if (spec->num_kctl_used >= spec->num_kctl_alloc) {
1025 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
1026
1027 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */
1028 if (! knew)
1029 return -ENOMEM;
1030 if (spec->kctl_alloc) {
1031 memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
1032 kfree(spec->kctl_alloc);
1033 }
1034 spec->kctl_alloc = knew;
1035 spec->num_kctl_alloc = num;
1036 }
1037
1038 knew = &spec->kctl_alloc[spec->num_kctl_used];
1039 *knew = stac92xx_control_templates[type];
Takashi Iwai82fe0c52005-06-30 10:54:33 +02001040 knew->name = kstrdup(name, GFP_KERNEL);
Mattc7d4b2f2005-06-27 14:59:41 +02001041 if (! knew->name)
1042 return -ENOMEM;
1043 knew->private_value = val;
1044 spec->num_kctl_used++;
1045 return 0;
1046}
1047
Matt Porter403d1942005-11-29 15:00:51 +01001048/* flag inputs as additional dynamic lineouts */
1049static int stac92xx_add_dyn_out_pins(struct hda_codec *codec, struct auto_pin_cfg *cfg)
1050{
1051 struct sigmatel_spec *spec = codec->spec;
1052
1053 switch (cfg->line_outs) {
1054 case 3:
1055 /* add line-in as side */
1056 if (cfg->input_pins[AUTO_PIN_LINE]) {
1057 cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_LINE];
1058 spec->line_switch = 1;
1059 cfg->line_outs++;
1060 }
1061 break;
1062 case 2:
1063 /* add line-in as clfe and mic as side */
1064 if (cfg->input_pins[AUTO_PIN_LINE]) {
1065 cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_LINE];
1066 spec->line_switch = 1;
1067 cfg->line_outs++;
1068 }
1069 if (cfg->input_pins[AUTO_PIN_MIC]) {
1070 cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_MIC];
1071 spec->mic_switch = 1;
1072 cfg->line_outs++;
1073 }
1074 break;
1075 case 1:
1076 /* add line-in as surr and mic as clfe */
1077 if (cfg->input_pins[AUTO_PIN_LINE]) {
1078 cfg->line_out_pins[1] = cfg->input_pins[AUTO_PIN_LINE];
1079 spec->line_switch = 1;
1080 cfg->line_outs++;
1081 }
1082 if (cfg->input_pins[AUTO_PIN_MIC]) {
1083 cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_MIC];
1084 spec->mic_switch = 1;
1085 cfg->line_outs++;
1086 }
1087 break;
1088 }
1089
1090 return 0;
1091}
1092
Matt Porter3cc08dc2006-01-23 15:27:49 +01001093/*
1094 * XXX The line_out pin widget connection list may not be set to the
1095 * desired DAC nid. This is the case on 927x where ports A and B can
1096 * be routed to several DACs.
1097 *
1098 * This requires an analysis of the line-out/hp pin configuration
1099 * to provide a best fit for pin/DAC configurations that are routable.
1100 * For now, 927x DAC4 is not supported and 927x DAC1 output to ports
1101 * A and B is not supported.
1102 */
Mattc7d4b2f2005-06-27 14:59:41 +02001103/* fill in the dac_nids table from the parsed pin configuration */
Takashi Iwai19039bd2006-06-28 15:52:16 +02001104static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec,
1105 const struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02001106{
1107 struct sigmatel_spec *spec = codec->spec;
1108 hda_nid_t nid;
1109 int i;
1110
1111 /* check the pins hardwired to audio widget */
1112 for (i = 0; i < cfg->line_outs; i++) {
1113 nid = cfg->line_out_pins[i];
1114 spec->multiout.dac_nids[i] = snd_hda_codec_read(codec, nid, 0,
1115 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
1116 }
1117
Takashi Iwai82bc9552006-03-21 11:24:42 +01001118 spec->multiout.num_dacs = cfg->line_outs;
Mattc7d4b2f2005-06-27 14:59:41 +02001119
1120 return 0;
1121}
1122
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001123/* create volume control/switch for the given prefx type */
1124static int create_controls(struct sigmatel_spec *spec, const char *pfx, hda_nid_t nid, int chs)
1125{
1126 char name[32];
1127 int err;
1128
1129 sprintf(name, "%s Playback Volume", pfx);
1130 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, name,
1131 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1132 if (err < 0)
1133 return err;
1134 sprintf(name, "%s Playback Switch", pfx);
1135 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, name,
1136 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1137 if (err < 0)
1138 return err;
1139 return 0;
1140}
1141
Mattc7d4b2f2005-06-27 14:59:41 +02001142/* add playback controls from the parsed DAC table */
Takashi Iwai19039bd2006-06-28 15:52:16 +02001143static int stac92xx_auto_create_multi_out_ctls(struct sigmatel_spec *spec,
1144 const struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02001145{
Takashi Iwai19039bd2006-06-28 15:52:16 +02001146 static const char *chname[4] = {
1147 "Front", "Surround", NULL /*CLFE*/, "Side"
1148 };
Mattc7d4b2f2005-06-27 14:59:41 +02001149 hda_nid_t nid;
1150 int i, err;
1151
1152 for (i = 0; i < cfg->line_outs; i++) {
Matt Porter403d1942005-11-29 15:00:51 +01001153 if (!spec->multiout.dac_nids[i])
Mattc7d4b2f2005-06-27 14:59:41 +02001154 continue;
1155
1156 nid = spec->multiout.dac_nids[i];
1157
1158 if (i == 2) {
1159 /* Center/LFE */
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001160 err = create_controls(spec, "Center", nid, 1);
1161 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001162 return err;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001163 err = create_controls(spec, "LFE", nid, 2);
1164 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001165 return err;
1166 } else {
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001167 err = create_controls(spec, chname[i], nid, 3);
1168 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001169 return err;
1170 }
1171 }
1172
Matt Porter403d1942005-11-29 15:00:51 +01001173 if (spec->line_switch)
1174 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Line In as Output Switch", cfg->input_pins[AUTO_PIN_LINE] << 8)) < 0)
1175 return err;
1176
1177 if (spec->mic_switch)
1178 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Mic as Output Switch", (cfg->input_pins[AUTO_PIN_MIC] << 8) | 1)) < 0)
1179 return err;
1180
Mattc7d4b2f2005-06-27 14:59:41 +02001181 return 0;
1182}
1183
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001184static int check_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
1185{
1186 int i;
1187
1188 for (i = 0; i < spec->multiout.num_dacs; i++) {
1189 if (spec->multiout.dac_nids[i] == nid)
1190 return 1;
1191 }
1192 if (spec->multiout.hp_nid == nid)
1193 return 1;
1194 return 0;
1195}
1196
1197static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
1198{
1199 if (!spec->multiout.hp_nid)
1200 spec->multiout.hp_nid = nid;
1201 else if (spec->multiout.num_dacs > 4) {
1202 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
1203 return 1;
1204 } else {
1205 spec->multiout.dac_nids[spec->multiout.num_dacs] = nid;
1206 spec->multiout.num_dacs++;
1207 }
1208 return 0;
1209}
1210
1211/* add playback controls for Speaker and HP outputs */
1212static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
1213 struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02001214{
1215 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02001216 hda_nid_t nid;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001217 int i, old_num_dacs, err;
Mattc7d4b2f2005-06-27 14:59:41 +02001218
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001219 old_num_dacs = spec->multiout.num_dacs;
1220 for (i = 0; i < cfg->hp_outs; i++) {
1221 unsigned int wid_caps = get_wcaps(codec, cfg->hp_pins[i]);
1222 if (wid_caps & AC_WCAP_UNSOL_CAP)
1223 spec->hp_detect = 1;
1224 nid = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
1225 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
1226 if (check_in_dac_nids(spec, nid))
1227 nid = 0;
1228 if (! nid)
Mattc7d4b2f2005-06-27 14:59:41 +02001229 continue;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001230 add_spec_dacs(spec, nid);
1231 }
1232 for (i = 0; i < cfg->speaker_outs; i++) {
1233 nid = snd_hda_codec_read(codec, cfg->speaker_pins[0], 0,
1234 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
1235 if (check_in_dac_nids(spec, nid))
1236 nid = 0;
1237 if (check_in_dac_nids(spec, nid))
1238 nid = 0;
1239 if (! nid)
1240 continue;
1241 add_spec_dacs(spec, nid);
Mattc7d4b2f2005-06-27 14:59:41 +02001242 }
1243
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001244 for (i = old_num_dacs; i < spec->multiout.num_dacs; i++) {
1245 static const char *pfxs[] = {
1246 "Speaker", "External Speaker", "Speaker2",
1247 };
1248 err = create_controls(spec, pfxs[i - old_num_dacs],
1249 spec->multiout.dac_nids[i], 3);
1250 if (err < 0)
1251 return err;
1252 }
1253 if (spec->multiout.hp_nid) {
1254 const char *pfx;
1255 if (old_num_dacs == spec->multiout.num_dacs)
1256 pfx = "Master";
1257 else
1258 pfx = "Headphone";
1259 err = create_controls(spec, pfx, spec->multiout.hp_nid, 3);
1260 if (err < 0)
1261 return err;
1262 }
Mattc7d4b2f2005-06-27 14:59:41 +02001263
1264 return 0;
1265}
1266
Matt Porter8b657272006-10-26 17:12:59 +02001267/* labels for dmic mux inputs */
Adrian Bunkddc2cec2006-11-20 12:03:44 +01001268static const char *stac92xx_dmic_labels[5] = {
Matt Porter8b657272006-10-26 17:12:59 +02001269 "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
1270 "Digital Mic 3", "Digital Mic 4"
1271};
1272
1273/* create playback/capture controls for input pins on dmic capable codecs */
1274static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
1275 const struct auto_pin_cfg *cfg)
1276{
1277 struct sigmatel_spec *spec = codec->spec;
1278 struct hda_input_mux *dimux = &spec->private_dimux;
1279 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
1280 int i, j;
1281
1282 dimux->items[dimux->num_items].label = stac92xx_dmic_labels[0];
1283 dimux->items[dimux->num_items].index = 0;
1284 dimux->num_items++;
1285
1286 for (i = 0; i < spec->num_dmics; i++) {
1287 int index;
1288 int num_cons;
1289 unsigned int def_conf;
1290
1291 def_conf = snd_hda_codec_read(codec,
1292 spec->dmic_nids[i],
1293 0,
1294 AC_VERB_GET_CONFIG_DEFAULT,
1295 0);
1296 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
1297 continue;
1298
1299 num_cons = snd_hda_get_connections(codec,
1300 spec->dmux_nid,
1301 con_lst,
1302 HDA_MAX_NUM_INPUTS);
1303 for (j = 0; j < num_cons; j++)
1304 if (con_lst[j] == spec->dmic_nids[i]) {
1305 index = j;
1306 goto found;
1307 }
1308 continue;
1309found:
1310 dimux->items[dimux->num_items].label =
1311 stac92xx_dmic_labels[dimux->num_items];
1312 dimux->items[dimux->num_items].index = index;
1313 dimux->num_items++;
1314 }
1315
1316 return 0;
1317}
1318
Mattc7d4b2f2005-06-27 14:59:41 +02001319/* create playback/capture controls for input pins */
1320static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
1321{
1322 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02001323 struct hda_input_mux *imux = &spec->private_imux;
1324 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
1325 int i, j, k;
1326
1327 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwai314634b2006-09-21 11:56:18 +02001328 int index;
Mattc7d4b2f2005-06-27 14:59:41 +02001329
Takashi Iwai314634b2006-09-21 11:56:18 +02001330 if (!cfg->input_pins[i])
1331 continue;
1332 index = -1;
1333 for (j = 0; j < spec->num_muxes; j++) {
1334 int num_cons;
1335 num_cons = snd_hda_get_connections(codec,
1336 spec->mux_nids[j],
1337 con_lst,
1338 HDA_MAX_NUM_INPUTS);
1339 for (k = 0; k < num_cons; k++)
1340 if (con_lst[k] == cfg->input_pins[i]) {
1341 index = k;
1342 goto found;
1343 }
Mattc7d4b2f2005-06-27 14:59:41 +02001344 }
Takashi Iwai314634b2006-09-21 11:56:18 +02001345 continue;
1346 found:
1347 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
1348 imux->items[imux->num_items].index = index;
1349 imux->num_items++;
Mattc7d4b2f2005-06-27 14:59:41 +02001350 }
1351
Sam Revitch62fe78e2006-05-10 15:09:17 +02001352 if (imux->num_items == 1) {
1353 /*
1354 * Set the current input for the muxes.
1355 * The STAC9221 has two input muxes with identical source
1356 * NID lists. Hopefully this won't get confused.
1357 */
1358 for (i = 0; i < spec->num_muxes; i++) {
1359 snd_hda_codec_write(codec, spec->mux_nids[i], 0,
1360 AC_VERB_SET_CONNECT_SEL,
1361 imux->items[0].index);
1362 }
1363 }
1364
Mattc7d4b2f2005-06-27 14:59:41 +02001365 return 0;
1366}
1367
Mattc7d4b2f2005-06-27 14:59:41 +02001368static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
1369{
1370 struct sigmatel_spec *spec = codec->spec;
1371 int i;
1372
1373 for (i = 0; i < spec->autocfg.line_outs; i++) {
1374 hda_nid_t nid = spec->autocfg.line_out_pins[i];
1375 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
1376 }
1377}
1378
1379static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
1380{
1381 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001382 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02001383
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001384 for (i = 0; i < spec->autocfg.hp_outs; i++) {
1385 hda_nid_t pin;
1386 pin = spec->autocfg.hp_pins[i];
1387 if (pin) /* connect to front */
1388 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
1389 }
1390 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
1391 hda_nid_t pin;
1392 pin = spec->autocfg.speaker_pins[i];
1393 if (pin) /* connect to front */
1394 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
1395 }
Mattc7d4b2f2005-06-27 14:59:41 +02001396}
1397
Matt Porter3cc08dc2006-01-23 15:27:49 +01001398static 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 +02001399{
1400 struct sigmatel_spec *spec = codec->spec;
1401 int err;
1402
Matt Porter8b657272006-10-26 17:12:59 +02001403 if ((err = snd_hda_parse_pin_def_config(codec,
1404 &spec->autocfg,
1405 spec->dmic_nids)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001406 return err;
Takashi Iwai82bc9552006-03-21 11:24:42 +01001407 if (! spec->autocfg.line_outs)
Matt Porter869264c2006-01-25 19:20:50 +01001408 return 0; /* can't find valid pin config */
Takashi Iwai19039bd2006-06-28 15:52:16 +02001409
Matt Porter403d1942005-11-29 15:00:51 +01001410 if ((err = stac92xx_add_dyn_out_pins(codec, &spec->autocfg)) < 0)
1411 return err;
Takashi Iwai19039bd2006-06-28 15:52:16 +02001412 if (spec->multiout.num_dacs == 0)
1413 if ((err = stac92xx_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
1414 return err;
Mattc7d4b2f2005-06-27 14:59:41 +02001415
1416 if ((err = stac92xx_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
1417 (err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg)) < 0 ||
1418 (err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
1419 return err;
1420
Matt Porter8b657272006-10-26 17:12:59 +02001421 if (spec->num_dmics > 0)
1422 if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
1423 &spec->autocfg)) < 0)
1424 return err;
1425
Mattc7d4b2f2005-06-27 14:59:41 +02001426 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Matt Porter403d1942005-11-29 15:00:51 +01001427 if (spec->multiout.max_channels > 2)
Mattc7d4b2f2005-06-27 14:59:41 +02001428 spec->surr_switch = 1;
Mattc7d4b2f2005-06-27 14:59:41 +02001429
Takashi Iwai82bc9552006-03-21 11:24:42 +01001430 if (spec->autocfg.dig_out_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01001431 spec->multiout.dig_out_nid = dig_out;
Takashi Iwai82bc9552006-03-21 11:24:42 +01001432 if (spec->autocfg.dig_in_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01001433 spec->dig_in_nid = dig_in;
Mattc7d4b2f2005-06-27 14:59:41 +02001434
1435 if (spec->kctl_alloc)
1436 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
1437
1438 spec->input_mux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02001439 spec->dinput_mux = &spec->private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +02001440
1441 return 1;
1442}
1443
Takashi Iwai82bc9552006-03-21 11:24:42 +01001444/* add playback controls for HP output */
1445static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
1446 struct auto_pin_cfg *cfg)
1447{
1448 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001449 hda_nid_t pin = cfg->hp_pins[0];
Takashi Iwai82bc9552006-03-21 11:24:42 +01001450 unsigned int wid_caps;
1451
1452 if (! pin)
1453 return 0;
1454
1455 wid_caps = get_wcaps(codec, pin);
Takashi Iwai505cb342006-03-27 12:51:52 +02001456 if (wid_caps & AC_WCAP_UNSOL_CAP)
Takashi Iwai82bc9552006-03-21 11:24:42 +01001457 spec->hp_detect = 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +01001458
1459 return 0;
1460}
1461
Richard Fish160ea0d2006-09-06 13:58:25 +02001462/* add playback controls for LFE output */
1463static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
1464 struct auto_pin_cfg *cfg)
1465{
1466 struct sigmatel_spec *spec = codec->spec;
1467 int err;
1468 hda_nid_t lfe_pin = 0x0;
1469 int i;
1470
1471 /*
1472 * search speaker outs and line outs for a mono speaker pin
1473 * with an amp. If one is found, add LFE controls
1474 * for it.
1475 */
1476 for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
1477 hda_nid_t pin = spec->autocfg.speaker_pins[i];
1478 unsigned long wcaps = get_wcaps(codec, pin);
1479 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
1480 if (wcaps == AC_WCAP_OUT_AMP)
1481 /* found a mono speaker with an amp, must be lfe */
1482 lfe_pin = pin;
1483 }
1484
1485 /* if speaker_outs is 0, then speakers may be in line_outs */
1486 if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
1487 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
1488 hda_nid_t pin = spec->autocfg.line_out_pins[i];
1489 unsigned long cfg;
1490 cfg = snd_hda_codec_read(codec, pin, 0,
1491 AC_VERB_GET_CONFIG_DEFAULT,
1492 0x00);
1493 if (get_defcfg_device(cfg) == AC_JACK_SPEAKER) {
1494 unsigned long wcaps = get_wcaps(codec, pin);
1495 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
1496 if (wcaps == AC_WCAP_OUT_AMP)
1497 /* found a mono speaker with an amp,
1498 must be lfe */
1499 lfe_pin = pin;
1500 }
1501 }
1502 }
1503
1504 if (lfe_pin) {
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001505 err = create_controls(spec, "LFE", lfe_pin, 1);
Richard Fish160ea0d2006-09-06 13:58:25 +02001506 if (err < 0)
1507 return err;
1508 }
1509
1510 return 0;
1511}
1512
Mattc7d4b2f2005-06-27 14:59:41 +02001513static int stac9200_parse_auto_config(struct hda_codec *codec)
1514{
1515 struct sigmatel_spec *spec = codec->spec;
1516 int err;
1517
Kailang Yangdf694da2005-12-05 19:42:22 +01001518 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001519 return err;
1520
1521 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
1522 return err;
1523
Takashi Iwai82bc9552006-03-21 11:24:42 +01001524 if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
1525 return err;
1526
Richard Fish160ea0d2006-09-06 13:58:25 +02001527 if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
1528 return err;
1529
Takashi Iwai82bc9552006-03-21 11:24:42 +01001530 if (spec->autocfg.dig_out_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02001531 spec->multiout.dig_out_nid = 0x05;
Takashi Iwai82bc9552006-03-21 11:24:42 +01001532 if (spec->autocfg.dig_in_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02001533 spec->dig_in_nid = 0x04;
Mattc7d4b2f2005-06-27 14:59:41 +02001534
1535 if (spec->kctl_alloc)
1536 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
1537
1538 spec->input_mux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02001539 spec->dinput_mux = &spec->private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +02001540
1541 return 1;
1542}
1543
Sam Revitch62fe78e2006-05-10 15:09:17 +02001544/*
1545 * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
1546 * funky external mute control using GPIO pins.
1547 */
1548
1549static void stac922x_gpio_mute(struct hda_codec *codec, int pin, int muted)
1550{
1551 unsigned int gpiostate, gpiomask, gpiodir;
1552
1553 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
1554 AC_VERB_GET_GPIO_DATA, 0);
1555
1556 if (!muted)
1557 gpiostate |= (1 << pin);
1558 else
1559 gpiostate &= ~(1 << pin);
1560
1561 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
1562 AC_VERB_GET_GPIO_MASK, 0);
1563 gpiomask |= (1 << pin);
1564
1565 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
1566 AC_VERB_GET_GPIO_DIRECTION, 0);
1567 gpiodir |= (1 << pin);
1568
1569 /* AppleHDA seems to do this -- WTF is this verb?? */
1570 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
1571
1572 snd_hda_codec_write(codec, codec->afg, 0,
1573 AC_VERB_SET_GPIO_MASK, gpiomask);
1574 snd_hda_codec_write(codec, codec->afg, 0,
1575 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
1576
1577 msleep(1);
1578
1579 snd_hda_codec_write(codec, codec->afg, 0,
1580 AC_VERB_SET_GPIO_DATA, gpiostate);
1581}
1582
Takashi Iwai314634b2006-09-21 11:56:18 +02001583static void enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
1584 unsigned int event)
1585{
1586 if (get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP)
1587 snd_hda_codec_write(codec, nid, 0,
1588 AC_VERB_SET_UNSOLICITED_ENABLE,
1589 (AC_USRSP_EN | event));
1590}
1591
Mattc7d4b2f2005-06-27 14:59:41 +02001592static int stac92xx_init(struct hda_codec *codec)
1593{
1594 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai82bc9552006-03-21 11:24:42 +01001595 struct auto_pin_cfg *cfg = &spec->autocfg;
1596 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02001597
Mattc7d4b2f2005-06-27 14:59:41 +02001598 snd_hda_sequence_write(codec, spec->init);
1599
Takashi Iwai82bc9552006-03-21 11:24:42 +01001600 /* set up pins */
1601 if (spec->hp_detect) {
Takashi Iwai505cb342006-03-27 12:51:52 +02001602 /* Enable unsolicited responses on the HP widget */
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001603 for (i = 0; i < cfg->hp_outs; i++)
Takashi Iwai314634b2006-09-21 11:56:18 +02001604 enable_pin_detect(codec, cfg->hp_pins[i],
1605 STAC_HP_EVENT);
Takashi Iwai0a07acaf2007-03-13 10:40:23 +01001606 /* force to enable the first line-out; the others are set up
1607 * in unsol_event
1608 */
1609 stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
1610 AC_PINCTL_OUT_EN);
Takashi Iwaieb995a82006-09-21 14:28:21 +02001611 stac92xx_auto_init_hp_out(codec);
Takashi Iwai82bc9552006-03-21 11:24:42 +01001612 /* fake event to set up pins */
1613 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
1614 } else {
1615 stac92xx_auto_init_multi_out(codec);
1616 stac92xx_auto_init_hp_out(codec);
1617 }
1618 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwaic960a032006-03-23 17:06:28 +01001619 hda_nid_t nid = cfg->input_pins[i];
1620 if (nid) {
1621 unsigned int pinctl = AC_PINCTL_IN_EN;
1622 if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC)
1623 pinctl |= stac92xx_get_vref(codec, nid);
1624 stac92xx_auto_set_pinctl(codec, nid, pinctl);
1625 }
Takashi Iwai82bc9552006-03-21 11:24:42 +01001626 }
Matt Porter8b657272006-10-26 17:12:59 +02001627 if (spec->num_dmics > 0)
1628 for (i = 0; i < spec->num_dmics; i++)
1629 stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
1630 AC_PINCTL_IN_EN);
1631
Takashi Iwai82bc9552006-03-21 11:24:42 +01001632 if (cfg->dig_out_pin)
1633 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pin,
1634 AC_PINCTL_OUT_EN);
1635 if (cfg->dig_in_pin)
1636 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
1637 AC_PINCTL_IN_EN);
1638
Sam Revitch62fe78e2006-05-10 15:09:17 +02001639 if (spec->gpio_mute) {
1640 stac922x_gpio_mute(codec, 0, 0);
1641 stac922x_gpio_mute(codec, 1, 0);
1642 }
1643
Mattc7d4b2f2005-06-27 14:59:41 +02001644 return 0;
1645}
1646
Matt2f2f4252005-04-13 14:45:30 +02001647static void stac92xx_free(struct hda_codec *codec)
1648{
Mattc7d4b2f2005-06-27 14:59:41 +02001649 struct sigmatel_spec *spec = codec->spec;
1650 int i;
1651
1652 if (! spec)
1653 return;
1654
1655 if (spec->kctl_alloc) {
1656 for (i = 0; i < spec->num_kctl_used; i++)
1657 kfree(spec->kctl_alloc[i].name);
1658 kfree(spec->kctl_alloc);
1659 }
1660
Richard Fish11b44bb2006-08-23 18:31:34 +02001661 if (spec->bios_pin_configs)
1662 kfree(spec->bios_pin_configs);
1663
Mattc7d4b2f2005-06-27 14:59:41 +02001664 kfree(spec);
Matt2f2f4252005-04-13 14:45:30 +02001665}
1666
Matt4e550962005-07-04 17:51:39 +02001667static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
1668 unsigned int flag)
1669{
1670 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
1671 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Takashi Iwai314634b2006-09-21 11:56:18 +02001672 if (flag == AC_PINCTL_OUT_EN && (pin_ctl & AC_PINCTL_IN_EN))
1673 return;
Matt4e550962005-07-04 17:51:39 +02001674 snd_hda_codec_write(codec, nid, 0,
1675 AC_VERB_SET_PIN_WIDGET_CONTROL,
1676 pin_ctl | flag);
1677}
1678
1679static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
1680 unsigned int flag)
1681{
1682 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
1683 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
1684 snd_hda_codec_write(codec, nid, 0,
1685 AC_VERB_SET_PIN_WIDGET_CONTROL,
1686 pin_ctl & ~flag);
1687}
1688
Takashi Iwai314634b2006-09-21 11:56:18 +02001689static int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
1690{
1691 if (!nid)
1692 return 0;
1693 if (snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PIN_SENSE, 0x00)
1694 & (1 << 31))
1695 return 1;
1696 return 0;
1697}
1698
1699static void stac92xx_hp_detect(struct hda_codec *codec, unsigned int res)
Matt4e550962005-07-04 17:51:39 +02001700{
1701 struct sigmatel_spec *spec = codec->spec;
1702 struct auto_pin_cfg *cfg = &spec->autocfg;
1703 int i, presence;
1704
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001705 presence = 0;
1706 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai314634b2006-09-21 11:56:18 +02001707 presence = get_pin_presence(codec, cfg->hp_pins[i]);
1708 if (presence)
1709 break;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001710 }
Matt4e550962005-07-04 17:51:39 +02001711
1712 if (presence) {
1713 /* disable lineouts, enable hp */
1714 for (i = 0; i < cfg->line_outs; i++)
1715 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
1716 AC_PINCTL_OUT_EN);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001717 for (i = 0; i < cfg->speaker_outs; i++)
1718 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
1719 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02001720 } else {
1721 /* enable lineouts, disable hp */
1722 for (i = 0; i < cfg->line_outs; i++)
1723 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
1724 AC_PINCTL_OUT_EN);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001725 for (i = 0; i < cfg->speaker_outs; i++)
1726 stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
1727 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02001728 }
1729}
1730
Takashi Iwai314634b2006-09-21 11:56:18 +02001731static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
1732{
1733 switch (res >> 26) {
1734 case STAC_HP_EVENT:
1735 stac92xx_hp_detect(codec, res);
1736 break;
1737 }
1738}
1739
Mattff6fdc32005-06-27 15:06:52 +02001740#ifdef CONFIG_PM
1741static int stac92xx_resume(struct hda_codec *codec)
1742{
1743 struct sigmatel_spec *spec = codec->spec;
1744 int i;
1745
1746 stac92xx_init(codec);
Richard Fish11b44bb2006-08-23 18:31:34 +02001747 stac92xx_set_config_regs(codec);
Mattff6fdc32005-06-27 15:06:52 +02001748 for (i = 0; i < spec->num_mixers; i++)
1749 snd_hda_resume_ctls(codec, spec->mixers[i]);
1750 if (spec->multiout.dig_out_nid)
1751 snd_hda_resume_spdif_out(codec);
1752 if (spec->dig_in_nid)
1753 snd_hda_resume_spdif_in(codec);
1754
1755 return 0;
1756}
1757#endif
1758
Matt2f2f4252005-04-13 14:45:30 +02001759static struct hda_codec_ops stac92xx_patch_ops = {
1760 .build_controls = stac92xx_build_controls,
1761 .build_pcms = stac92xx_build_pcms,
1762 .init = stac92xx_init,
1763 .free = stac92xx_free,
Matt4e550962005-07-04 17:51:39 +02001764 .unsol_event = stac92xx_unsol_event,
Mattff6fdc32005-06-27 15:06:52 +02001765#ifdef CONFIG_PM
1766 .resume = stac92xx_resume,
1767#endif
Matt2f2f4252005-04-13 14:45:30 +02001768};
1769
1770static int patch_stac9200(struct hda_codec *codec)
1771{
1772 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02001773 int err;
Matt2f2f4252005-04-13 14:45:30 +02001774
Takashi Iwaie560d8d2005-09-09 14:21:46 +02001775 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02001776 if (spec == NULL)
1777 return -ENOMEM;
1778
1779 codec->spec = spec;
Richard Fish11b44bb2006-08-23 18:31:34 +02001780 spec->num_pins = 8;
1781 spec->pin_nids = stac9200_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001782 spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS,
1783 stac9200_models,
1784 stac9200_cfg_tbl);
Richard Fish11b44bb2006-08-23 18:31:34 +02001785 if (spec->board_config < 0) {
1786 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9200, using BIOS defaults\n");
1787 err = stac92xx_save_bios_config_regs(codec);
1788 if (err < 0) {
1789 stac92xx_free(codec);
1790 return err;
1791 }
1792 spec->pin_configs = spec->bios_pin_configs;
1793 } else {
Matt Porter403d1942005-11-29 15:00:51 +01001794 spec->pin_configs = stac9200_brd_tbl[spec->board_config];
1795 stac92xx_set_config_regs(codec);
1796 }
Matt2f2f4252005-04-13 14:45:30 +02001797
1798 spec->multiout.max_channels = 2;
1799 spec->multiout.num_dacs = 1;
1800 spec->multiout.dac_nids = stac9200_dac_nids;
1801 spec->adc_nids = stac9200_adc_nids;
1802 spec->mux_nids = stac9200_mux_nids;
Mattdabbed62005-06-14 10:19:34 +02001803 spec->num_muxes = 1;
Matt Porter8b657272006-10-26 17:12:59 +02001804 spec->num_dmics = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02001805
1806 spec->init = stac9200_core_init;
Matt2f2f4252005-04-13 14:45:30 +02001807 spec->mixer = stac9200_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02001808
1809 err = stac9200_parse_auto_config(codec);
1810 if (err < 0) {
1811 stac92xx_free(codec);
1812 return err;
1813 }
Matt2f2f4252005-04-13 14:45:30 +02001814
1815 codec->patch_ops = stac92xx_patch_ops;
1816
1817 return 0;
1818}
1819
Tobin Davis8e21c342007-01-08 11:04:17 +01001820static int patch_stac925x(struct hda_codec *codec)
1821{
1822 struct sigmatel_spec *spec;
1823 int err;
1824
1825 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1826 if (spec == NULL)
1827 return -ENOMEM;
1828
1829 codec->spec = spec;
1830 spec->num_pins = 8;
1831 spec->pin_nids = stac925x_pin_nids;
1832 spec->board_config = snd_hda_check_board_config(codec, STAC_925x_MODELS,
1833 stac925x_models,
1834 stac925x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01001835 again:
Tobin Davis8e21c342007-01-08 11:04:17 +01001836 if (spec->board_config < 0) {
1837 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC925x, using BIOS defaults\n");
1838 err = stac92xx_save_bios_config_regs(codec);
1839 if (err < 0) {
1840 stac92xx_free(codec);
1841 return err;
1842 }
1843 spec->pin_configs = spec->bios_pin_configs;
1844 } else if (stac925x_brd_tbl[spec->board_config] != NULL){
1845 spec->pin_configs = stac925x_brd_tbl[spec->board_config];
1846 stac92xx_set_config_regs(codec);
1847 }
1848
1849 spec->multiout.max_channels = 2;
1850 spec->multiout.num_dacs = 1;
1851 spec->multiout.dac_nids = stac925x_dac_nids;
1852 spec->adc_nids = stac925x_adc_nids;
1853 spec->mux_nids = stac925x_mux_nids;
1854 spec->num_muxes = 1;
1855 spec->num_dmics = 0;
1856
1857 spec->init = stac925x_core_init;
1858 spec->mixer = stac925x_mixer;
1859
1860 err = stac92xx_parse_auto_config(codec, 0x8, 0x7);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01001861 if (!err) {
1862 if (spec->board_config < 0) {
1863 printk(KERN_WARNING "hda_codec: No auto-config is "
1864 "available, default to model=ref\n");
1865 spec->board_config = STAC_925x_REF;
1866 goto again;
1867 }
1868 err = -EINVAL;
1869 }
Tobin Davis8e21c342007-01-08 11:04:17 +01001870 if (err < 0) {
1871 stac92xx_free(codec);
1872 return err;
1873 }
1874
1875 codec->patch_ops = stac92xx_patch_ops;
1876
1877 return 0;
1878}
1879
Matt2f2f4252005-04-13 14:45:30 +02001880static int patch_stac922x(struct hda_codec *codec)
1881{
1882 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02001883 int err;
Matt2f2f4252005-04-13 14:45:30 +02001884
Takashi Iwaie560d8d2005-09-09 14:21:46 +02001885 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02001886 if (spec == NULL)
1887 return -ENOMEM;
1888
1889 codec->spec = spec;
Richard Fish11b44bb2006-08-23 18:31:34 +02001890 spec->num_pins = 10;
1891 spec->pin_nids = stac922x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001892 spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS,
1893 stac922x_models,
1894 stac922x_cfg_tbl);
Takashi Iwai3fc24d82007-02-16 13:27:18 +01001895 if (spec->board_config == STAC_MACMINI) {
1896 spec->gpio_mute = 1;
1897 /* Intel Macs have all same PCI SSID, so we need to check
1898 * codec SSID to distinguish the exact models
1899 */
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01001900 printk(KERN_INFO "hda_codec: STAC922x, Apple subsys_id=%x\n", codec->subsystem_id);
Takashi Iwai3fc24d82007-02-16 13:27:18 +01001901 switch (codec->subsystem_id) {
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01001902 case 0x106b0200: /* MacBook Pro first generation */
1903 spec->board_config = STAC_MACBOOK_PRO_V1;
1904 break;
1905 case 0x106b1e00: /* MacBook Pro second generation */
1906 spec->board_config = STAC_MACBOOK_PRO_V2;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01001907 break;
1908 }
1909 }
1910
Takashi Iwai9e507ab2007-02-08 17:50:10 +01001911 again:
Richard Fish11b44bb2006-08-23 18:31:34 +02001912 if (spec->board_config < 0) {
1913 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC922x, "
1914 "using BIOS defaults\n");
1915 err = stac92xx_save_bios_config_regs(codec);
1916 if (err < 0) {
1917 stac92xx_free(codec);
1918 return err;
1919 }
1920 spec->pin_configs = spec->bios_pin_configs;
1921 } else if (stac922x_brd_tbl[spec->board_config] != NULL) {
Matt Porter403d1942005-11-29 15:00:51 +01001922 spec->pin_configs = stac922x_brd_tbl[spec->board_config];
1923 stac92xx_set_config_regs(codec);
1924 }
Matt2f2f4252005-04-13 14:45:30 +02001925
Matt2f2f4252005-04-13 14:45:30 +02001926 spec->adc_nids = stac922x_adc_nids;
1927 spec->mux_nids = stac922x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01001928 spec->num_muxes = ARRAY_SIZE(stac922x_mux_nids);
Matt Porter8b657272006-10-26 17:12:59 +02001929 spec->num_dmics = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02001930
1931 spec->init = stac922x_core_init;
Matt2f2f4252005-04-13 14:45:30 +02001932 spec->mixer = stac922x_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02001933
1934 spec->multiout.dac_nids = spec->dac_nids;
Takashi Iwai19039bd2006-06-28 15:52:16 +02001935
Matt Porter3cc08dc2006-01-23 15:27:49 +01001936 err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01001937 if (!err) {
1938 if (spec->board_config < 0) {
1939 printk(KERN_WARNING "hda_codec: No auto-config is "
1940 "available, default to model=ref\n");
1941 spec->board_config = STAC_D945_REF;
1942 goto again;
1943 }
1944 err = -EINVAL;
1945 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01001946 if (err < 0) {
1947 stac92xx_free(codec);
1948 return err;
1949 }
1950
1951 codec->patch_ops = stac92xx_patch_ops;
1952
1953 return 0;
1954}
1955
1956static int patch_stac927x(struct hda_codec *codec)
1957{
1958 struct sigmatel_spec *spec;
1959 int err;
1960
1961 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1962 if (spec == NULL)
1963 return -ENOMEM;
1964
1965 codec->spec = spec;
Richard Fish11b44bb2006-08-23 18:31:34 +02001966 spec->num_pins = 14;
1967 spec->pin_nids = stac927x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001968 spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS,
1969 stac927x_models,
1970 stac927x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01001971 again:
Richard Fish11b44bb2006-08-23 18:31:34 +02001972 if (spec->board_config < 0) {
Matt Porter3cc08dc2006-01-23 15:27:49 +01001973 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC927x, using BIOS defaults\n");
Richard Fish11b44bb2006-08-23 18:31:34 +02001974 err = stac92xx_save_bios_config_regs(codec);
1975 if (err < 0) {
1976 stac92xx_free(codec);
1977 return err;
1978 }
1979 spec->pin_configs = spec->bios_pin_configs;
1980 } else if (stac927x_brd_tbl[spec->board_config] != NULL) {
Matt Porter3cc08dc2006-01-23 15:27:49 +01001981 spec->pin_configs = stac927x_brd_tbl[spec->board_config];
1982 stac92xx_set_config_regs(codec);
1983 }
1984
Tobin Davis81d3dbd2006-08-22 19:44:45 +02001985 switch (spec->board_config) {
Tobin Davis93ed1502006-09-01 21:03:12 +02001986 case STAC_D965_3ST:
Tobin Davis81d3dbd2006-08-22 19:44:45 +02001987 spec->adc_nids = stac927x_adc_nids;
1988 spec->mux_nids = stac927x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01001989 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
Matt Porter8b657272006-10-26 17:12:59 +02001990 spec->num_dmics = 0;
Tobin Davis93ed1502006-09-01 21:03:12 +02001991 spec->init = d965_core_init;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02001992 spec->mixer = stac9227_mixer;
1993 break;
Tobin Davis93ed1502006-09-01 21:03:12 +02001994 case STAC_D965_5ST:
1995 spec->adc_nids = stac927x_adc_nids;
1996 spec->mux_nids = stac927x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01001997 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
Matt Porter8b657272006-10-26 17:12:59 +02001998 spec->num_dmics = 0;
Tobin Davis93ed1502006-09-01 21:03:12 +02001999 spec->init = d965_core_init;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002000 spec->mixer = stac9227_mixer;
2001 break;
2002 default:
2003 spec->adc_nids = stac927x_adc_nids;
2004 spec->mux_nids = stac927x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01002005 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
Matt Porter8b657272006-10-26 17:12:59 +02002006 spec->num_dmics = 0;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002007 spec->init = stac927x_core_init;
2008 spec->mixer = stac927x_mixer;
2009 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01002010
2011 spec->multiout.dac_nids = spec->dac_nids;
2012
2013 err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002014 if (!err) {
2015 if (spec->board_config < 0) {
2016 printk(KERN_WARNING "hda_codec: No auto-config is "
2017 "available, default to model=ref\n");
2018 spec->board_config = STAC_D965_REF;
2019 goto again;
2020 }
2021 err = -EINVAL;
2022 }
Mattc7d4b2f2005-06-27 14:59:41 +02002023 if (err < 0) {
2024 stac92xx_free(codec);
2025 return err;
2026 }
Matt2f2f4252005-04-13 14:45:30 +02002027
2028 codec->patch_ops = stac92xx_patch_ops;
2029
2030 return 0;
2031}
2032
Matt Porterf3302a52006-07-31 12:49:34 +02002033static int patch_stac9205(struct hda_codec *codec)
2034{
2035 struct sigmatel_spec *spec;
2036 int err;
2037
2038 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2039 if (spec == NULL)
2040 return -ENOMEM;
2041
2042 codec->spec = spec;
Richard Fish11b44bb2006-08-23 18:31:34 +02002043 spec->num_pins = 14;
2044 spec->pin_nids = stac9205_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002045 spec->board_config = snd_hda_check_board_config(codec, STAC_9205_MODELS,
2046 stac9205_models,
2047 stac9205_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002048 again:
Richard Fish11b44bb2006-08-23 18:31:34 +02002049 if (spec->board_config < 0) {
2050 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9205, using BIOS defaults\n");
2051 err = stac92xx_save_bios_config_regs(codec);
2052 if (err < 0) {
2053 stac92xx_free(codec);
2054 return err;
2055 }
2056 spec->pin_configs = spec->bios_pin_configs;
2057 } else {
Matt Porterf3302a52006-07-31 12:49:34 +02002058 spec->pin_configs = stac9205_brd_tbl[spec->board_config];
2059 stac92xx_set_config_regs(codec);
2060 }
2061
2062 spec->adc_nids = stac9205_adc_nids;
2063 spec->mux_nids = stac9205_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01002064 spec->num_muxes = ARRAY_SIZE(stac9205_mux_nids);
Matt Porter8b657272006-10-26 17:12:59 +02002065 spec->dmic_nids = stac9205_dmic_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01002066 spec->num_dmics = ARRAY_SIZE(stac9205_dmic_nids);
Matt Porter8b657272006-10-26 17:12:59 +02002067 spec->dmux_nid = 0x1d;
Matt Porterf3302a52006-07-31 12:49:34 +02002068
2069 spec->init = stac9205_core_init;
2070 spec->mixer = stac9205_mixer;
2071
2072 spec->multiout.dac_nids = spec->dac_nids;
2073
Matt Porter33382402006-12-18 13:17:28 +01002074 /* Configure GPIO0 as EAPD output */
2075 snd_hda_codec_write(codec, codec->afg, 0,
2076 AC_VERB_SET_GPIO_DIRECTION, 0x00000001);
2077 /* Configure GPIO0 as CMOS */
2078 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0x00000000);
2079 /* Assert GPIO0 high */
2080 snd_hda_codec_write(codec, codec->afg, 0,
2081 AC_VERB_SET_GPIO_DATA, 0x00000001);
2082 /* Enable GPIO0 */
2083 snd_hda_codec_write(codec, codec->afg, 0,
2084 AC_VERB_SET_GPIO_MASK, 0x00000001);
2085
Matt Porterf3302a52006-07-31 12:49:34 +02002086 err = stac92xx_parse_auto_config(codec, 0x1f, 0x20);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002087 if (!err) {
2088 if (spec->board_config < 0) {
2089 printk(KERN_WARNING "hda_codec: No auto-config is "
2090 "available, default to model=ref\n");
2091 spec->board_config = STAC_9205_REF;
2092 goto again;
2093 }
2094 err = -EINVAL;
2095 }
Matt Porterf3302a52006-07-31 12:49:34 +02002096 if (err < 0) {
2097 stac92xx_free(codec);
2098 return err;
2099 }
2100
2101 codec->patch_ops = stac92xx_patch_ops;
2102
2103 return 0;
2104}
2105
Matt2f2f4252005-04-13 14:45:30 +02002106/*
Guillaume Munch6d859062006-08-22 17:15:47 +02002107 * STAC9872 hack
Takashi Iwaidb064e52006-03-16 16:04:58 +01002108 */
2109
Guillaume Munch99ccc562006-08-16 19:35:12 +02002110/* static config for Sony VAIO FE550G and Sony VAIO AR */
Takashi Iwaidb064e52006-03-16 16:04:58 +01002111static hda_nid_t vaio_dacs[] = { 0x2 };
2112#define VAIO_HP_DAC 0x5
2113static hda_nid_t vaio_adcs[] = { 0x8 /*,0x6*/ };
2114static hda_nid_t vaio_mux_nids[] = { 0x15 };
2115
2116static struct hda_input_mux vaio_mux = {
2117 .num_items = 2,
2118 .items = {
Takashi Iwaid7737812006-04-25 13:05:43 +02002119 /* { "HP", 0x0 }, */
2120 { "Line", 0x1 },
Takashi Iwaidb064e52006-03-16 16:04:58 +01002121 { "Mic", 0x2 },
2122 { "PCM", 0x3 },
2123 }
2124};
2125
2126static struct hda_verb vaio_init[] = {
2127 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
2128 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
2129 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
2130 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
2131 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
2132 {0x15, AC_VERB_SET_CONNECT_SEL, 0x2}, /* mic-sel: 0a,0d,14,02 */
2133 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
2134 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
2135 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
2136 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
2137 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
2138 {}
2139};
2140
Guillaume Munch6d859062006-08-22 17:15:47 +02002141static struct hda_verb vaio_ar_init[] = {
2142 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
2143 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
2144 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
2145 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
2146/* {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },*/ /* Optical Out */
2147 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
2148 {0x15, AC_VERB_SET_CONNECT_SEL, 0x2}, /* mic-sel: 0a,0d,14,02 */
2149 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
2150 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
2151/* {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},*/ /* Optical Out */
2152 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
2153 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
2154 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
2155 {}
2156};
2157
Takashi Iwaidb064e52006-03-16 16:04:58 +01002158/* bind volumes of both NID 0x02 and 0x05 */
2159static int vaio_master_vol_put(struct snd_kcontrol *kcontrol,
2160 struct snd_ctl_elem_value *ucontrol)
2161{
2162 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2163 long *valp = ucontrol->value.integer.value;
2164 int change;
2165
2166 change = snd_hda_codec_amp_update(codec, 0x02, 0, HDA_OUTPUT, 0,
2167 0x7f, valp[0] & 0x7f);
2168 change |= snd_hda_codec_amp_update(codec, 0x02, 1, HDA_OUTPUT, 0,
2169 0x7f, valp[1] & 0x7f);
2170 snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
2171 0x7f, valp[0] & 0x7f);
2172 snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
2173 0x7f, valp[1] & 0x7f);
2174 return change;
2175}
2176
2177/* bind volumes of both NID 0x02 and 0x05 */
2178static int vaio_master_sw_put(struct snd_kcontrol *kcontrol,
2179 struct snd_ctl_elem_value *ucontrol)
2180{
2181 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2182 long *valp = ucontrol->value.integer.value;
2183 int change;
2184
2185 change = snd_hda_codec_amp_update(codec, 0x02, 0, HDA_OUTPUT, 0,
Takashi Iwaia9393d72006-05-03 11:59:03 +02002186 0x80, (valp[0] ? 0 : 0x80));
Takashi Iwaidb064e52006-03-16 16:04:58 +01002187 change |= snd_hda_codec_amp_update(codec, 0x02, 1, HDA_OUTPUT, 0,
Takashi Iwaia9393d72006-05-03 11:59:03 +02002188 0x80, (valp[1] ? 0 : 0x80));
Takashi Iwaidb064e52006-03-16 16:04:58 +01002189 snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
Takashi Iwaia9393d72006-05-03 11:59:03 +02002190 0x80, (valp[0] ? 0 : 0x80));
Takashi Iwaidb064e52006-03-16 16:04:58 +01002191 snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
Takashi Iwaia9393d72006-05-03 11:59:03 +02002192 0x80, (valp[1] ? 0 : 0x80));
Takashi Iwaidb064e52006-03-16 16:04:58 +01002193 return change;
2194}
2195
2196static struct snd_kcontrol_new vaio_mixer[] = {
2197 {
2198 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2199 .name = "Master Playback Volume",
2200 .info = snd_hda_mixer_amp_volume_info,
2201 .get = snd_hda_mixer_amp_volume_get,
2202 .put = vaio_master_vol_put,
Takashi Iwaic2566522006-08-17 18:21:36 +02002203 .tlv = { .c = snd_hda_mixer_amp_tlv },
Takashi Iwaidb064e52006-03-16 16:04:58 +01002204 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2205 },
2206 {
2207 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2208 .name = "Master Playback Switch",
2209 .info = snd_hda_mixer_amp_switch_info,
2210 .get = snd_hda_mixer_amp_switch_get,
2211 .put = vaio_master_sw_put,
2212 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2213 },
2214 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
2215 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
2216 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
2217 {
2218 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2219 .name = "Capture Source",
2220 .count = 1,
2221 .info = stac92xx_mux_enum_info,
2222 .get = stac92xx_mux_enum_get,
2223 .put = stac92xx_mux_enum_put,
2224 },
2225 {}
2226};
2227
Guillaume Munch6d859062006-08-22 17:15:47 +02002228static struct snd_kcontrol_new vaio_ar_mixer[] = {
2229 {
2230 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2231 .name = "Master Playback Volume",
2232 .info = snd_hda_mixer_amp_volume_info,
2233 .get = snd_hda_mixer_amp_volume_get,
2234 .put = vaio_master_vol_put,
2235 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2236 },
2237 {
2238 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2239 .name = "Master Playback Switch",
2240 .info = snd_hda_mixer_amp_switch_info,
2241 .get = snd_hda_mixer_amp_switch_get,
2242 .put = vaio_master_sw_put,
2243 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2244 },
2245 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
2246 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
2247 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
2248 /*HDA_CODEC_MUTE("Optical Out Switch", 0x10, 0, HDA_OUTPUT),
2249 HDA_CODEC_VOLUME("Optical Out Volume", 0x10, 0, HDA_OUTPUT),*/
2250 {
2251 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2252 .name = "Capture Source",
2253 .count = 1,
2254 .info = stac92xx_mux_enum_info,
2255 .get = stac92xx_mux_enum_get,
2256 .put = stac92xx_mux_enum_put,
2257 },
2258 {}
2259};
2260
2261static struct hda_codec_ops stac9872_patch_ops = {
Takashi Iwaidb064e52006-03-16 16:04:58 +01002262 .build_controls = stac92xx_build_controls,
2263 .build_pcms = stac92xx_build_pcms,
2264 .init = stac92xx_init,
2265 .free = stac92xx_free,
2266#ifdef CONFIG_PM
2267 .resume = stac92xx_resume,
2268#endif
2269};
2270
Guillaume Munch6d859062006-08-22 17:15:47 +02002271enum { /* FE and SZ series. id=0x83847661 and subsys=0x104D0700 or 104D1000. */
2272 CXD9872RD_VAIO,
2273 /* Unknown. id=0x83847662 and subsys=0x104D1200 or 104D1000. */
2274 STAC9872AK_VAIO,
2275 /* Unknown. id=0x83847661 and subsys=0x104D1200. */
2276 STAC9872K_VAIO,
2277 /* AR Series. id=0x83847664 and subsys=104D1300 */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002278 CXD9872AKD_VAIO,
2279 STAC_9872_MODELS,
2280};
Takashi Iwaidb064e52006-03-16 16:04:58 +01002281
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002282static const char *stac9872_models[STAC_9872_MODELS] = {
2283 [CXD9872RD_VAIO] = "vaio",
2284 [CXD9872AKD_VAIO] = "vaio-ar",
2285};
2286
2287static struct snd_pci_quirk stac9872_cfg_tbl[] = {
2288 SND_PCI_QUIRK(0x104d, 0x81e6, "Sony VAIO F/S", CXD9872RD_VAIO),
2289 SND_PCI_QUIRK(0x104d, 0x81ef, "Sony VAIO F/S", CXD9872RD_VAIO),
2290 SND_PCI_QUIRK(0x104d, 0x81fd, "Sony VAIO AR", CXD9872AKD_VAIO),
Tobin Davis68e22542007-03-12 11:36:39 +01002291 SND_PCI_QUIRK(0x104d, 0x8205, "Sony VAIO AR", CXD9872AKD_VAIO),
Takashi Iwaidb064e52006-03-16 16:04:58 +01002292 {}
2293};
2294
Guillaume Munch6d859062006-08-22 17:15:47 +02002295static int patch_stac9872(struct hda_codec *codec)
Takashi Iwaidb064e52006-03-16 16:04:58 +01002296{
2297 struct sigmatel_spec *spec;
2298 int board_config;
2299
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002300 board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
2301 stac9872_models,
2302 stac9872_cfg_tbl);
Takashi Iwaidb064e52006-03-16 16:04:58 +01002303 if (board_config < 0)
2304 /* unknown config, let generic-parser do its job... */
2305 return snd_hda_parse_generic_codec(codec);
2306
2307 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2308 if (spec == NULL)
2309 return -ENOMEM;
2310
2311 codec->spec = spec;
2312 switch (board_config) {
Guillaume Munch6d859062006-08-22 17:15:47 +02002313 case CXD9872RD_VAIO:
2314 case STAC9872AK_VAIO:
2315 case STAC9872K_VAIO:
Takashi Iwaidb064e52006-03-16 16:04:58 +01002316 spec->mixer = vaio_mixer;
2317 spec->init = vaio_init;
2318 spec->multiout.max_channels = 2;
2319 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
2320 spec->multiout.dac_nids = vaio_dacs;
2321 spec->multiout.hp_nid = VAIO_HP_DAC;
2322 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
2323 spec->adc_nids = vaio_adcs;
2324 spec->input_mux = &vaio_mux;
2325 spec->mux_nids = vaio_mux_nids;
2326 break;
Guillaume Munch6d859062006-08-22 17:15:47 +02002327
2328 case CXD9872AKD_VAIO:
2329 spec->mixer = vaio_ar_mixer;
2330 spec->init = vaio_ar_init;
2331 spec->multiout.max_channels = 2;
2332 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
2333 spec->multiout.dac_nids = vaio_dacs;
2334 spec->multiout.hp_nid = VAIO_HP_DAC;
2335 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
2336 spec->adc_nids = vaio_adcs;
2337 spec->input_mux = &vaio_mux;
2338 spec->mux_nids = vaio_mux_nids;
2339 break;
Takashi Iwaidb064e52006-03-16 16:04:58 +01002340 }
2341
Guillaume Munch6d859062006-08-22 17:15:47 +02002342 codec->patch_ops = stac9872_patch_ops;
Takashi Iwaidb064e52006-03-16 16:04:58 +01002343 return 0;
2344}
2345
2346
2347/*
Matt2f2f4252005-04-13 14:45:30 +02002348 * patch entries
2349 */
2350struct hda_codec_preset snd_hda_preset_sigmatel[] = {
2351 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
2352 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
2353 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
2354 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
2355 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
2356 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
2357 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
Matt Porter22a27c72006-07-06 18:49:10 +02002358 { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
2359 { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
2360 { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
2361 { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
2362 { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
2363 { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
Matt Porter3cc08dc2006-01-23 15:27:49 +01002364 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
2365 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
2366 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
2367 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
2368 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
2369 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
2370 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
2371 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
2372 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
2373 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
Tobin Davis8e21c342007-01-08 11:04:17 +01002374 { .id = 0x83847632, .name = "STAC9202", .patch = patch_stac925x },
2375 { .id = 0x83847633, .name = "STAC9202D", .patch = patch_stac925x },
2376 { .id = 0x83847634, .name = "STAC9250", .patch = patch_stac925x },
2377 { .id = 0x83847635, .name = "STAC9250D", .patch = patch_stac925x },
2378 { .id = 0x83847636, .name = "STAC9251", .patch = patch_stac925x },
2379 { .id = 0x83847637, .name = "STAC9250D", .patch = patch_stac925x },
Guillaume Munch6d859062006-08-22 17:15:47 +02002380 /* The following does not take into account .id=0x83847661 when subsys =
2381 * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
2382 * currently not fully supported.
2383 */
2384 { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
2385 { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
2386 { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
Matt Porterf3302a52006-07-31 12:49:34 +02002387 { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
2388 { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
2389 { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
2390 { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
2391 { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
2392 { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
2393 { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
2394 { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
Matt2f2f4252005-04-13 14:45:30 +02002395 {} /* terminator */
2396};