blob: 98144f93dff9b8a5adf46d54a475abdca7fcc36c [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,
Takashi Iwaidfe495d2007-08-23 19:04:28 +020042 STAC_9200_DELL_D21,
43 STAC_9200_DELL_D22,
44 STAC_9200_DELL_D23,
45 STAC_9200_DELL_M21,
46 STAC_9200_DELL_M22,
47 STAC_9200_DELL_M23,
48 STAC_9200_DELL_M24,
49 STAC_9200_DELL_M25,
50 STAC_9200_DELL_M26,
51 STAC_9200_DELL_M27,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010052 STAC_9200_MODELS
53};
54
55enum {
56 STAC_9205_REF,
Takashi Iwaidfe495d2007-08-23 19:04:28 +020057 STAC_9205_DELL_M42,
Tobin Davisae0a8ed2007-08-13 15:50:29 +020058 STAC_9205_DELL_M43,
59 STAC_9205_DELL_M44,
60 STAC_9205_M43xx,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010061 STAC_9205_MODELS
62};
63
64enum {
Tobin Davis8e21c342007-01-08 11:04:17 +010065 STAC_925x_REF,
66 STAC_M2_2,
67 STAC_MA6,
Tobin Davis2c11f952007-05-17 09:36:34 +020068 STAC_PA6,
Tobin Davis8e21c342007-01-08 11:04:17 +010069 STAC_925x_MODELS
70};
71
72enum {
Takashi Iwaif5fcc132006-11-24 17:07:44 +010073 STAC_D945_REF,
74 STAC_D945GTP3,
75 STAC_D945GTP5,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +020076 STAC_INTEL_MAC_V1,
77 STAC_INTEL_MAC_V2,
78 STAC_INTEL_MAC_V3,
79 STAC_INTEL_MAC_V4,
80 STAC_INTEL_MAC_V5,
Takashi Iwaidfe495d2007-08-23 19:04:28 +020081 /* for backward compatibility */
Takashi Iwaif5fcc132006-11-24 17:07:44 +010082 STAC_MACMINI,
Takashi Iwai3fc24d82007-02-16 13:27:18 +010083 STAC_MACBOOK,
Nicolas Boichat6f0778d2007-03-15 12:38:15 +010084 STAC_MACBOOK_PRO_V1,
85 STAC_MACBOOK_PRO_V2,
Sylvain FORETf16928f2007-04-27 14:22:36 +020086 STAC_IMAC_INTEL,
Takashi Iwai0dae0f82007-05-21 12:41:29 +020087 STAC_IMAC_INTEL_20,
Takashi Iwaidfe495d2007-08-23 19:04:28 +020088 STAC_922X_DELL_D81,
89 STAC_922X_DELL_D82,
90 STAC_922X_DELL_M81,
91 STAC_922X_DELL_M82,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010092 STAC_922X_MODELS
93};
94
95enum {
96 STAC_D965_REF,
97 STAC_D965_3ST,
98 STAC_D965_5ST,
Tobin Davis4ff076e2007-08-07 11:48:12 +020099 STAC_DELL_3ST,
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100100 STAC_927X_MODELS
101};
Matt Porter403d1942005-11-29 15:00:51 +0100102
Matt2f2f4252005-04-13 14:45:30 +0200103struct sigmatel_spec {
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100104 struct snd_kcontrol_new *mixers[4];
Mattc7d4b2f2005-06-27 14:59:41 +0200105 unsigned int num_mixers;
106
Matt Porter403d1942005-11-29 15:00:51 +0100107 int board_config;
Mattc7d4b2f2005-06-27 14:59:41 +0200108 unsigned int surr_switch: 1;
Matt Porter403d1942005-11-29 15:00:51 +0100109 unsigned int line_switch: 1;
110 unsigned int mic_switch: 1;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100111 unsigned int alt_switch: 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +0100112 unsigned int hp_detect: 1;
Sam Revitch62fe78e2006-05-10 15:09:17 +0200113 unsigned int gpio_mute: 1;
Mattc7d4b2f2005-06-27 14:59:41 +0200114
Takashi Iwai82599802007-07-31 15:56:24 +0200115 unsigned int gpio_mask, gpio_data;
116
Matt2f2f4252005-04-13 14:45:30 +0200117 /* playback */
118 struct hda_multi_out multiout;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100119 hda_nid_t dac_nids[5];
Matt2f2f4252005-04-13 14:45:30 +0200120
121 /* capture */
122 hda_nid_t *adc_nids;
Matt2f2f4252005-04-13 14:45:30 +0200123 unsigned int num_adcs;
Mattdabbed62005-06-14 10:19:34 +0200124 hda_nid_t *mux_nids;
125 unsigned int num_muxes;
Matt Porter8b657272006-10-26 17:12:59 +0200126 hda_nid_t *dmic_nids;
127 unsigned int num_dmics;
128 hda_nid_t dmux_nid;
Mattdabbed62005-06-14 10:19:34 +0200129 hda_nid_t dig_in_nid;
Matt2f2f4252005-04-13 14:45:30 +0200130
Matt2f2f4252005-04-13 14:45:30 +0200131 /* pin widgets */
132 hda_nid_t *pin_nids;
133 unsigned int num_pins;
Matt2f2f4252005-04-13 14:45:30 +0200134 unsigned int *pin_configs;
Richard Fish11b44bb2006-08-23 18:31:34 +0200135 unsigned int *bios_pin_configs;
Matt2f2f4252005-04-13 14:45:30 +0200136
137 /* codec specific stuff */
138 struct hda_verb *init;
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100139 struct snd_kcontrol_new *mixer;
Matt2f2f4252005-04-13 14:45:30 +0200140
141 /* capture source */
Matt Porter8b657272006-10-26 17:12:59 +0200142 struct hda_input_mux *dinput_mux;
143 unsigned int cur_dmux;
Mattc7d4b2f2005-06-27 14:59:41 +0200144 struct hda_input_mux *input_mux;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100145 unsigned int cur_mux[3];
Matt2f2f4252005-04-13 14:45:30 +0200146
Matt Porter403d1942005-11-29 15:00:51 +0100147 /* i/o switches */
148 unsigned int io_switch[2];
Matt2f2f4252005-04-13 14:45:30 +0200149
Mattc7d4b2f2005-06-27 14:59:41 +0200150 struct hda_pcm pcm_rec[2]; /* PCM information */
151
152 /* dynamic controls and input_mux */
153 struct auto_pin_cfg autocfg;
154 unsigned int num_kctl_alloc, num_kctl_used;
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100155 struct snd_kcontrol_new *kctl_alloc;
Matt Porter8b657272006-10-26 17:12:59 +0200156 struct hda_input_mux private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +0200157 struct hda_input_mux private_imux;
Matt2f2f4252005-04-13 14:45:30 +0200158};
159
160static hda_nid_t stac9200_adc_nids[1] = {
161 0x03,
162};
163
164static hda_nid_t stac9200_mux_nids[1] = {
165 0x0c,
166};
167
168static hda_nid_t stac9200_dac_nids[1] = {
169 0x02,
170};
171
Tobin Davis8e21c342007-01-08 11:04:17 +0100172static hda_nid_t stac925x_adc_nids[1] = {
173 0x03,
174};
175
176static hda_nid_t stac925x_mux_nids[1] = {
177 0x0f,
178};
179
180static hda_nid_t stac925x_dac_nids[1] = {
181 0x02,
182};
183
Tobin Davis2c11f952007-05-17 09:36:34 +0200184static hda_nid_t stac925x_dmic_nids[1] = {
185 0x15,
186};
187
Matt2f2f4252005-04-13 14:45:30 +0200188static hda_nid_t stac922x_adc_nids[2] = {
189 0x06, 0x07,
190};
191
192static hda_nid_t stac922x_mux_nids[2] = {
193 0x12, 0x13,
194};
195
Matt Porter3cc08dc2006-01-23 15:27:49 +0100196static hda_nid_t stac927x_adc_nids[3] = {
197 0x07, 0x08, 0x09
198};
199
200static hda_nid_t stac927x_mux_nids[3] = {
201 0x15, 0x16, 0x17
202};
203
Matt Porterf3302a52006-07-31 12:49:34 +0200204static hda_nid_t stac9205_adc_nids[2] = {
205 0x12, 0x13
206};
207
208static hda_nid_t stac9205_mux_nids[2] = {
209 0x19, 0x1a
210};
211
Takashi Iwai25494132007-03-12 12:36:16 +0100212static hda_nid_t stac9205_dmic_nids[2] = {
213 0x17, 0x18,
Matt Porter8b657272006-10-26 17:12:59 +0200214};
215
Mattc7d4b2f2005-06-27 14:59:41 +0200216static hda_nid_t stac9200_pin_nids[8] = {
Tobin Davis93ed1502006-09-01 21:03:12 +0200217 0x08, 0x09, 0x0d, 0x0e,
218 0x0f, 0x10, 0x11, 0x12,
Matt2f2f4252005-04-13 14:45:30 +0200219};
220
Tobin Davis8e21c342007-01-08 11:04:17 +0100221static hda_nid_t stac925x_pin_nids[8] = {
222 0x07, 0x08, 0x0a, 0x0b,
223 0x0c, 0x0d, 0x10, 0x11,
224};
225
Matt2f2f4252005-04-13 14:45:30 +0200226static hda_nid_t stac922x_pin_nids[10] = {
227 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
228 0x0f, 0x10, 0x11, 0x15, 0x1b,
229};
230
Matt Porter3cc08dc2006-01-23 15:27:49 +0100231static hda_nid_t stac927x_pin_nids[14] = {
232 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
233 0x0f, 0x10, 0x11, 0x12, 0x13,
234 0x14, 0x21, 0x22, 0x23,
235};
236
Matt Porterf3302a52006-07-31 12:49:34 +0200237static hda_nid_t stac9205_pin_nids[12] = {
238 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
239 0x0f, 0x14, 0x16, 0x17, 0x18,
240 0x21, 0x22,
Matt Porterf3302a52006-07-31 12:49:34 +0200241};
242
Matt Porter8b657272006-10-26 17:12:59 +0200243static int stac92xx_dmux_enum_info(struct snd_kcontrol *kcontrol,
244 struct snd_ctl_elem_info *uinfo)
245{
246 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
247 struct sigmatel_spec *spec = codec->spec;
248 return snd_hda_input_mux_info(spec->dinput_mux, uinfo);
249}
250
251static int stac92xx_dmux_enum_get(struct snd_kcontrol *kcontrol,
252 struct snd_ctl_elem_value *ucontrol)
253{
254 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
255 struct sigmatel_spec *spec = codec->spec;
256
257 ucontrol->value.enumerated.item[0] = spec->cur_dmux;
258 return 0;
259}
260
261static int stac92xx_dmux_enum_put(struct snd_kcontrol *kcontrol,
262 struct snd_ctl_elem_value *ucontrol)
263{
264 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
265 struct sigmatel_spec *spec = codec->spec;
266
267 return snd_hda_input_mux_put(codec, spec->dinput_mux, ucontrol,
268 spec->dmux_nid, &spec->cur_dmux);
269}
270
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100271static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Matt2f2f4252005-04-13 14:45:30 +0200272{
273 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
274 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +0200275 return snd_hda_input_mux_info(spec->input_mux, uinfo);
Matt2f2f4252005-04-13 14:45:30 +0200276}
277
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100278static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200279{
280 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
281 struct sigmatel_spec *spec = codec->spec;
282 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
283
284 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
285 return 0;
286}
287
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100288static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200289{
290 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
291 struct sigmatel_spec *spec = codec->spec;
292 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
293
Mattc7d4b2f2005-06-27 14:59:41 +0200294 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
Matt2f2f4252005-04-13 14:45:30 +0200295 spec->mux_nids[adc_idx], &spec->cur_mux[adc_idx]);
296}
297
Mattc7d4b2f2005-06-27 14:59:41 +0200298static struct hda_verb stac9200_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200299 /* set dac0mux for dac converter */
Mattc7d4b2f2005-06-27 14:59:41 +0200300 { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
Matt2f2f4252005-04-13 14:45:30 +0200301 {}
302};
303
Tobin Davis8e21c342007-01-08 11:04:17 +0100304static struct hda_verb stac925x_core_init[] = {
305 /* set dac0mux for dac converter */
306 { 0x06, AC_VERB_SET_CONNECT_SEL, 0x00},
307 {}
308};
309
Mattc7d4b2f2005-06-27 14:59:41 +0200310static struct hda_verb stac922x_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200311 /* set master volume and direct control */
Mattc7d4b2f2005-06-27 14:59:41 +0200312 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matt2f2f4252005-04-13 14:45:30 +0200313 {}
314};
315
Tobin Davis93ed1502006-09-01 21:03:12 +0200316static struct hda_verb d965_core_init[] = {
Takashi Iwai19039bd2006-06-28 15:52:16 +0200317 /* set master volume and direct control */
Tobin Davis93ed1502006-09-01 21:03:12 +0200318 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Takashi Iwai19039bd2006-06-28 15:52:16 +0200319 /* unmute node 0x1b */
320 { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
321 /* select node 0x03 as DAC */
322 { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
323 {}
324};
325
Matt Porter3cc08dc2006-01-23 15:27:49 +0100326static struct hda_verb stac927x_core_init[] = {
327 /* set master volume and direct control */
328 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
329 {}
330};
331
Matt Porterf3302a52006-07-31 12:49:34 +0200332static struct hda_verb stac9205_core_init[] = {
333 /* set master volume and direct control */
334 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
335 {}
336};
337
Maxim Levitskyca7c5a82007-08-31 12:52:19 +0200338#define STAC_INPUT_SOURCE \
339 { \
340 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
341 .name = "Input Source", \
342 .count = 1, \
343 .info = stac92xx_mux_enum_info, \
344 .get = stac92xx_mux_enum_get, \
345 .put = stac92xx_mux_enum_put, \
346 }
347
348
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100349static struct snd_kcontrol_new stac9200_mixer[] = {
Matt2f2f4252005-04-13 14:45:30 +0200350 HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
351 HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
Maxim Levitskyca7c5a82007-08-31 12:52:19 +0200352 STAC_INPUT_SOURCE,
Matt2f2f4252005-04-13 14:45:30 +0200353 HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
354 HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
Mattc7d4b2f2005-06-27 14:59:41 +0200355 HDA_CODEC_VOLUME("Capture Mux Volume", 0x0c, 0, HDA_OUTPUT),
Matt2f2f4252005-04-13 14:45:30 +0200356 { } /* end */
357};
358
Tobin Davis8e21c342007-01-08 11:04:17 +0100359static struct snd_kcontrol_new stac925x_mixer[] = {
Maxim Levitskyca7c5a82007-08-31 12:52:19 +0200360 STAC_INPUT_SOURCE,
Tobin Davis8e21c342007-01-08 11:04:17 +0100361 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_OUTPUT),
362 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_OUTPUT),
363 HDA_CODEC_VOLUME("Capture Mux Volume", 0x0f, 0, HDA_OUTPUT),
364 { } /* end */
365};
366
Mattc7d4b2f2005-06-27 14:59:41 +0200367/* This needs to be generated dynamically based on sequence */
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100368static struct snd_kcontrol_new stac922x_mixer[] = {
Maxim Levitskyca7c5a82007-08-31 12:52:19 +0200369 STAC_INPUT_SOURCE,
Matt2f2f4252005-04-13 14:45:30 +0200370 HDA_CODEC_VOLUME("Capture Volume", 0x17, 0x0, HDA_INPUT),
Takashi Iwai0fd17082006-01-13 18:46:21 +0100371 HDA_CODEC_MUTE("Capture Switch", 0x17, 0x0, HDA_INPUT),
Matt2f2f4252005-04-13 14:45:30 +0200372 HDA_CODEC_VOLUME("Mux Capture Volume", 0x12, 0x0, HDA_OUTPUT),
373 { } /* end */
374};
375
Takashi Iwai19039bd2006-06-28 15:52:16 +0200376/* This needs to be generated dynamically based on sequence */
377static struct snd_kcontrol_new stac9227_mixer[] = {
Maxim Levitskyca7c5a82007-08-31 12:52:19 +0200378 STAC_INPUT_SOURCE,
Takashi Iwai19039bd2006-06-28 15:52:16 +0200379 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
380 HDA_CODEC_MUTE("Capture Switch", 0x1b, 0x0, HDA_OUTPUT),
381 { } /* end */
382};
383
Takashi Iwaid1d985f2006-11-23 19:27:12 +0100384static struct snd_kcontrol_new stac927x_mixer[] = {
Maxim Levitskyca7c5a82007-08-31 12:52:19 +0200385 STAC_INPUT_SOURCE,
Matt Porter3cc08dc2006-01-23 15:27:49 +0100386 HDA_CODEC_VOLUME("InMux Capture Volume", 0x15, 0x0, HDA_OUTPUT),
387 HDA_CODEC_VOLUME("InVol Capture Volume", 0x18, 0x0, HDA_INPUT),
388 HDA_CODEC_MUTE("ADCMux Capture Switch", 0x1b, 0x0, HDA_OUTPUT),
389 { } /* end */
390};
391
Takashi Iwaid1d985f2006-11-23 19:27:12 +0100392static struct snd_kcontrol_new stac9205_mixer[] = {
Matt Porterf3302a52006-07-31 12:49:34 +0200393 {
394 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Matt Porter8b657272006-10-26 17:12:59 +0200395 .name = "Digital Input Source",
396 .count = 1,
397 .info = stac92xx_dmux_enum_info,
398 .get = stac92xx_dmux_enum_get,
399 .put = stac92xx_dmux_enum_put,
400 },
Maxim Levitskyca7c5a82007-08-31 12:52:19 +0200401 STAC_INPUT_SOURCE,
Matt Porterf3302a52006-07-31 12:49:34 +0200402 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 Iwaidfe495d2007-08-23 19:04:28 +0200442/*
443 STAC 9200 pin configs for
444 102801A8
445 102801DE
446 102801E8
447*/
448static unsigned int dell9200_d21_pin_configs[8] = {
449 0x400001f0, 0x400001f1, 0x01a19021, 0x90100140,
450 0x01813122, 0x02214030, 0x01014010, 0x02a19020,
451};
452
453/*
454 STAC 9200 pin configs for
455 102801C0
456 102801C1
457*/
458static unsigned int dell9200_d22_pin_configs[8] = {
459 0x400001f0, 0x400001f1, 0x02a19021, 0x90100140,
460 0x400001f2, 0x0221401f, 0x01014010, 0x01813020,
461};
462
463/*
464 STAC 9200 pin configs for
465 102801C4 (Dell Dimension E310)
466 102801C5
467 102801C7
468 102801D9
469 102801DA
470 102801E3
471*/
472static unsigned int dell9200_d23_pin_configs[8] = {
473 0x400001f0, 0x400001f1, 0x01a19021, 0x90100140,
474 0x400001f2, 0x0221401f, 0x01014010, 0x01813020,
475};
476
477
478/*
479 STAC 9200-32 pin configs for
480 102801B5 (Dell Inspiron 630m)
481 102801D8 (Dell Inspiron 640m)
482*/
483static unsigned int dell9200_m21_pin_configs[8] = {
484 0x40c003fa, 0x03441340, 0x03a11020, 0x401003fc,
485 0x403003fd, 0x0321121f, 0x0321121f, 0x408003fb,
486};
487
488/*
489 STAC 9200-32 pin configs for
490 102801C2 (Dell Latitude D620)
491 102801C8
492 102801CC (Dell Latitude D820)
493 102801D4
494 102801D6
495*/
496static unsigned int dell9200_m22_pin_configs[8] = {
497 0x40c003fa, 0x0144131f, 0x03A11020, 0x401003fb,
498 0x40f000fc, 0x0321121f, 0x90170310, 0x90a70321,
499};
500
501/*
502 STAC 9200-32 pin configs for
503 102801CE (Dell XPS M1710)
504 102801CF (Dell Precision M90)
505*/
506static unsigned int dell9200_m23_pin_configs[8] = {
507 0x40c003fa, 0x01441340, 0x0421421f, 0x90170310,
508 0x408003fb, 0x04a1102e, 0x90170311, 0x403003fc,
509};
510
511/*
512 STAC 9200-32 pin configs for
513 102801C9
514 102801CA
515 102801CB (Dell Latitude 120L)
516 102801D3
517*/
518static unsigned int dell9200_m24_pin_configs[8] = {
519 0x40c003fa, 0x404003fb, 0x03a11020, 0x401003fd,
520 0x403003fe, 0x0321121f, 0x90170310, 0x408003fc,
521};
522
523/*
524 STAC 9200-32 pin configs for
525 102801BD (Dell Inspiron E1505n)
526 102801EE
527 102801EF
528*/
529static unsigned int dell9200_m25_pin_configs[8] = {
530 0x40c003fa, 0x01441340, 0x04a11020, 0x401003fc,
531 0x403003fd, 0x0421121f, 0x90170310, 0x408003fb,
532};
533
534/*
535 STAC 9200-32 pin configs for
536 102801F5 (Dell Inspiron 1501)
537 102801F6
538*/
539static unsigned int dell9200_m26_pin_configs[8] = {
540 0x40c003fa, 0x404003fb, 0x04a11020, 0x401003fd,
541 0x403003fe, 0x0421121f, 0x90170310, 0x408003fc,
542};
543
544/*
545 STAC 9200-32
546 102801CD (Dell Inspiron E1705/9400)
547*/
548static unsigned int dell9200_m27_pin_configs[8] = {
549 0x40c003fa, 0x01441340, 0x04a11020, 0x90170310,
550 0x40f003fc, 0x0421121f, 0x90170310, 0x408003fb,
551};
552
553
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100554static unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
555 [STAC_REF] = ref9200_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200556 [STAC_9200_DELL_D21] = dell9200_d21_pin_configs,
557 [STAC_9200_DELL_D22] = dell9200_d22_pin_configs,
558 [STAC_9200_DELL_D23] = dell9200_d23_pin_configs,
559 [STAC_9200_DELL_M21] = dell9200_m21_pin_configs,
560 [STAC_9200_DELL_M22] = dell9200_m22_pin_configs,
561 [STAC_9200_DELL_M23] = dell9200_m23_pin_configs,
562 [STAC_9200_DELL_M24] = dell9200_m24_pin_configs,
563 [STAC_9200_DELL_M25] = dell9200_m25_pin_configs,
564 [STAC_9200_DELL_M26] = dell9200_m26_pin_configs,
565 [STAC_9200_DELL_M27] = dell9200_m27_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +0100566};
567
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100568static const char *stac9200_models[STAC_9200_MODELS] = {
569 [STAC_REF] = "ref",
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200570 [STAC_9200_DELL_D21] = "dell-d21",
571 [STAC_9200_DELL_D22] = "dell-d22",
572 [STAC_9200_DELL_D23] = "dell-d23",
573 [STAC_9200_DELL_M21] = "dell-m21",
574 [STAC_9200_DELL_M22] = "dell-m22",
575 [STAC_9200_DELL_M23] = "dell-m23",
576 [STAC_9200_DELL_M24] = "dell-m24",
577 [STAC_9200_DELL_M25] = "dell-m25",
578 [STAC_9200_DELL_M26] = "dell-m26",
579 [STAC_9200_DELL_M27] = "dell-m27",
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100580};
581
582static struct snd_pci_quirk stac9200_cfg_tbl[] = {
583 /* SigmaTel reference board */
584 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
585 "DFI LanParty", STAC_REF),
Matt Portere7377072006-11-06 11:20:38 +0100586 /* Dell laptops have BIOS problem */
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200587 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a8,
588 "unknown Dell", STAC_9200_DELL_D21),
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100589 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01b5,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200590 "Dell Inspiron 630m", STAC_9200_DELL_M21),
591 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bd,
592 "Dell Inspiron E1505n", STAC_9200_DELL_M25),
593 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c0,
594 "unknown Dell", STAC_9200_DELL_D22),
595 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c1,
596 "unknown Dell", STAC_9200_DELL_D22),
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100597 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200598 "Dell Latitude D620", STAC_9200_DELL_M22),
599 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c5,
600 "unknown Dell", STAC_9200_DELL_D23),
601 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c7,
602 "unknown Dell", STAC_9200_DELL_D23),
603 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c8,
604 "unknown Dell", STAC_9200_DELL_M22),
605 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c9,
606 "unknown Dell", STAC_9200_DELL_M24),
607 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ca,
608 "unknown Dell", STAC_9200_DELL_M24),
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100609 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cb,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200610 "Dell Latitude 120L", STAC_9200_DELL_M24),
Cory T. Tusar877b8662007-01-30 17:30:55 +0100611 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200612 "Dell Latitude D820", STAC_9200_DELL_M22),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +0100613 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200614 "Dell Inspiron E1705/9400", STAC_9200_DELL_M27),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +0100615 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ce,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200616 "Dell XPS M1710", STAC_9200_DELL_M23),
Takashi Iwaif0f96742007-02-14 00:59:17 +0100617 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cf,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200618 "Dell Precision M90", STAC_9200_DELL_M23),
619 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d3,
620 "unknown Dell", STAC_9200_DELL_M22),
621 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d4,
622 "unknown Dell", STAC_9200_DELL_M22),
Daniel T Chen8286c532007-05-15 11:46:23 +0200623 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d6,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200624 "unknown Dell", STAC_9200_DELL_M22),
Tobin Davis49c605d2007-05-17 09:38:24 +0200625 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d8,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200626 "Dell Inspiron 640m", STAC_9200_DELL_M21),
627 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d9,
628 "unknown Dell", STAC_9200_DELL_D23),
629 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01da,
630 "unknown Dell", STAC_9200_DELL_D23),
631 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01de,
632 "unknown Dell", STAC_9200_DELL_D21),
633 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e3,
634 "unknown Dell", STAC_9200_DELL_D23),
635 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e8,
636 "unknown Dell", STAC_9200_DELL_D21),
637 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ee,
638 "unknown Dell", STAC_9200_DELL_M25),
639 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ef,
640 "unknown Dell", STAC_9200_DELL_M25),
Tobin Davis49c605d2007-05-17 09:38:24 +0200641 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f5,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200642 "Dell Inspiron 1501", STAC_9200_DELL_M26),
643 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f6,
644 "unknown Dell", STAC_9200_DELL_M26),
Tobin Davis49c605d2007-05-17 09:38:24 +0200645 /* Panasonic */
646 SND_PCI_QUIRK(0x10f7, 0x8338, "Panasonic CF-74", STAC_REF),
647
Matt Porter403d1942005-11-29 15:00:51 +0100648 {} /* terminator */
649};
650
Tobin Davis8e21c342007-01-08 11:04:17 +0100651static unsigned int ref925x_pin_configs[8] = {
652 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
653 0x90a70320, 0x02214210, 0x400003f1, 0x9033032e,
654};
655
656static unsigned int stac925x_MA6_pin_configs[8] = {
657 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
658 0x90a70320, 0x90100211, 0x400003f1, 0x9033032e,
659};
660
Tobin Davis2c11f952007-05-17 09:36:34 +0200661static unsigned int stac925x_PA6_pin_configs[8] = {
662 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
663 0x50a103f0, 0x90100211, 0x400003f1, 0x9033032e,
664};
665
Tobin Davis8e21c342007-01-08 11:04:17 +0100666static unsigned int stac925xM2_2_pin_configs[8] = {
Steve Longerbeam7353e142007-05-29 14:36:17 +0200667 0x40c003f3, 0x424503f2, 0x04180011, 0x02a19020,
668 0x50a103f0, 0x90100212, 0x400003f1, 0x9033032e,
Tobin Davis8e21c342007-01-08 11:04:17 +0100669};
670
671static unsigned int *stac925x_brd_tbl[STAC_925x_MODELS] = {
672 [STAC_REF] = ref925x_pin_configs,
673 [STAC_M2_2] = stac925xM2_2_pin_configs,
674 [STAC_MA6] = stac925x_MA6_pin_configs,
Tobin Davis2c11f952007-05-17 09:36:34 +0200675 [STAC_PA6] = stac925x_PA6_pin_configs,
Tobin Davis8e21c342007-01-08 11:04:17 +0100676};
677
678static const char *stac925x_models[STAC_925x_MODELS] = {
679 [STAC_REF] = "ref",
680 [STAC_M2_2] = "m2-2",
681 [STAC_MA6] = "m6",
Tobin Davis2c11f952007-05-17 09:36:34 +0200682 [STAC_PA6] = "pa6",
Tobin Davis8e21c342007-01-08 11:04:17 +0100683};
684
685static struct snd_pci_quirk stac925x_cfg_tbl[] = {
686 /* SigmaTel reference board */
687 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, "DFI LanParty", STAC_REF),
Tobin Davis2c11f952007-05-17 09:36:34 +0200688 SND_PCI_QUIRK(0x8384, 0x7632, "Stac9202 Reference Board", STAC_REF),
Tobin Davis8e21c342007-01-08 11:04:17 +0100689 SND_PCI_QUIRK(0x107b, 0x0316, "Gateway M255", STAC_REF),
690 SND_PCI_QUIRK(0x107b, 0x0366, "Gateway MP6954", STAC_REF),
691 SND_PCI_QUIRK(0x107b, 0x0461, "Gateway NX560XL", STAC_MA6),
Tobin Davis2c11f952007-05-17 09:36:34 +0200692 SND_PCI_QUIRK(0x107b, 0x0681, "Gateway NX860", STAC_PA6),
Tobin Davis8e21c342007-01-08 11:04:17 +0100693 SND_PCI_QUIRK(0x1002, 0x437b, "Gateway MX6453", STAC_M2_2),
694 {} /* terminator */
695};
696
Matt Porter403d1942005-11-29 15:00:51 +0100697static unsigned int ref922x_pin_configs[10] = {
698 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
699 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
Matt2f2f4252005-04-13 14:45:30 +0200700 0x40000100, 0x40000100,
701};
702
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200703/*
704 STAC 922X pin configs for
705 102801A7
706 102801AB
707 102801A9
708 102801D1
709 102801D2
710*/
711static unsigned int dell_922x_d81_pin_configs[10] = {
712 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
713 0x02a19020, 0x01117011, 0x400001f0, 0x400001f1,
714 0x01813122, 0x400001f2,
715};
716
717/*
718 STAC 922X pin configs for
719 102801AC
720 102801D0
721*/
722static unsigned int dell_922x_d82_pin_configs[10] = {
723 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
724 0x02a19020, 0x01117011, 0x01451140, 0x400001f0,
725 0x01813122, 0x400001f1,
726};
727
728/*
729 STAC 922X pin configs for
730 102801BF
731*/
732static unsigned int dell_922x_m81_pin_configs[10] = {
733 0x0321101f, 0x01112024, 0x01111222, 0x91174220,
734 0x03a11050, 0x01116221, 0x90a70330, 0x01452340,
735 0x40C003f1, 0x405003f0,
736};
737
738/*
739 STAC 9221 A1 pin configs for
740 102801D7 (Dell XPS M1210)
741*/
742static unsigned int dell_922x_m82_pin_configs[10] = {
743 0x0221121f, 0x408103ff, 0x02111212, 0x90100310,
744 0x408003f1, 0x02111211, 0x03451340, 0x40c003f2,
745 0x508003f3, 0x405003f4,
746};
747
Matt Porter403d1942005-11-29 15:00:51 +0100748static unsigned int d945gtp3_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +0100749 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
Matt Porter403d1942005-11-29 15:00:51 +0100750 0x40000100, 0x40000100, 0x40000100, 0x40000100,
751 0x02a19120, 0x40000100,
752};
753
754static unsigned int d945gtp5_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +0100755 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
756 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
Matt Porter403d1942005-11-29 15:00:51 +0100757 0x02a19320, 0x40000100,
758};
759
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +0200760static unsigned int intel_mac_v1_pin_configs[10] = {
761 0x0121e21f, 0x400000ff, 0x9017e110, 0x400000fd,
762 0x400000fe, 0x0181e020, 0x1145e030, 0x11c5e240,
Takashi Iwai3fc24d82007-02-16 13:27:18 +0100763 0x400000fc, 0x400000fb,
764};
765
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +0200766static unsigned int intel_mac_v2_pin_configs[10] = {
767 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
768 0x400000fe, 0x0181e020, 0x1145e230, 0x500000fa,
Sylvain FORETf16928f2007-04-27 14:22:36 +0200769 0x400000fc, 0x400000fb,
770};
771
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +0200772static unsigned int intel_mac_v3_pin_configs[10] = {
773 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
774 0x400000fe, 0x0181e020, 0x1145e230, 0x11c5e240,
775 0x400000fc, 0x400000fb,
776};
777
778static unsigned int intel_mac_v4_pin_configs[10] = {
779 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
780 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
781 0x400000fc, 0x400000fb,
782};
783
784static unsigned int intel_mac_v5_pin_configs[10] = {
785 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
786 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
787 0x400000fc, 0x400000fb,
Takashi Iwai0dae0f82007-05-21 12:41:29 +0200788};
789
Takashi Iwai76c08822007-06-19 12:17:42 +0200790
Takashi Iwai19039bd2006-06-28 15:52:16 +0200791static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100792 [STAC_D945_REF] = ref922x_pin_configs,
Takashi Iwai19039bd2006-06-28 15:52:16 +0200793 [STAC_D945GTP3] = d945gtp3_pin_configs,
794 [STAC_D945GTP5] = d945gtp5_pin_configs,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +0200795 [STAC_INTEL_MAC_V1] = intel_mac_v1_pin_configs,
796 [STAC_INTEL_MAC_V2] = intel_mac_v2_pin_configs,
797 [STAC_INTEL_MAC_V3] = intel_mac_v3_pin_configs,
798 [STAC_INTEL_MAC_V4] = intel_mac_v4_pin_configs,
799 [STAC_INTEL_MAC_V5] = intel_mac_v5_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200800 /* for backward compatibility */
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +0200801 [STAC_MACMINI] = intel_mac_v3_pin_configs,
802 [STAC_MACBOOK] = intel_mac_v5_pin_configs,
803 [STAC_MACBOOK_PRO_V1] = intel_mac_v3_pin_configs,
804 [STAC_MACBOOK_PRO_V2] = intel_mac_v3_pin_configs,
805 [STAC_IMAC_INTEL] = intel_mac_v2_pin_configs,
806 [STAC_IMAC_INTEL_20] = intel_mac_v3_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200807 [STAC_922X_DELL_D81] = dell_922x_d81_pin_configs,
808 [STAC_922X_DELL_D82] = dell_922x_d82_pin_configs,
809 [STAC_922X_DELL_M81] = dell_922x_m81_pin_configs,
810 [STAC_922X_DELL_M82] = dell_922x_m82_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +0100811};
812
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100813static const char *stac922x_models[STAC_922X_MODELS] = {
814 [STAC_D945_REF] = "ref",
815 [STAC_D945GTP5] = "5stack",
816 [STAC_D945GTP3] = "3stack",
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +0200817 [STAC_INTEL_MAC_V1] = "intel-mac-v1",
818 [STAC_INTEL_MAC_V2] = "intel-mac-v2",
819 [STAC_INTEL_MAC_V3] = "intel-mac-v3",
820 [STAC_INTEL_MAC_V4] = "intel-mac-v4",
821 [STAC_INTEL_MAC_V5] = "intel-mac-v5",
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200822 /* for backward compatibility */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100823 [STAC_MACMINI] = "macmini",
Takashi Iwai3fc24d82007-02-16 13:27:18 +0100824 [STAC_MACBOOK] = "macbook",
Nicolas Boichat6f0778d2007-03-15 12:38:15 +0100825 [STAC_MACBOOK_PRO_V1] = "macbook-pro-v1",
826 [STAC_MACBOOK_PRO_V2] = "macbook-pro",
Sylvain FORETf16928f2007-04-27 14:22:36 +0200827 [STAC_IMAC_INTEL] = "imac-intel",
Takashi Iwai0dae0f82007-05-21 12:41:29 +0200828 [STAC_IMAC_INTEL_20] = "imac-intel-20",
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200829 [STAC_922X_DELL_D81] = "dell-d81",
830 [STAC_922X_DELL_D82] = "dell-d82",
831 [STAC_922X_DELL_M81] = "dell-m81",
832 [STAC_922X_DELL_M82] = "dell-m82",
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100833};
834
835static struct snd_pci_quirk stac922x_cfg_tbl[] = {
836 /* SigmaTel reference board */
837 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
838 "DFI LanParty", STAC_D945_REF),
839 /* Intel 945G based systems */
840 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101,
841 "Intel D945G", STAC_D945GTP3),
842 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0202,
843 "Intel D945G", STAC_D945GTP3),
844 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0606,
845 "Intel D945G", STAC_D945GTP3),
846 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0601,
847 "Intel D945G", STAC_D945GTP3),
848 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0111,
849 "Intel D945G", STAC_D945GTP3),
850 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1115,
851 "Intel D945G", STAC_D945GTP3),
852 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1116,
853 "Intel D945G", STAC_D945GTP3),
854 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1117,
855 "Intel D945G", STAC_D945GTP3),
856 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1118,
857 "Intel D945G", STAC_D945GTP3),
858 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1119,
859 "Intel D945G", STAC_D945GTP3),
860 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x8826,
861 "Intel D945G", STAC_D945GTP3),
862 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5049,
863 "Intel D945G", STAC_D945GTP3),
864 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5055,
865 "Intel D945G", STAC_D945GTP3),
866 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5048,
867 "Intel D945G", STAC_D945GTP3),
868 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0110,
869 "Intel D945G", STAC_D945GTP3),
870 /* Intel D945G 5-stack systems */
871 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0404,
872 "Intel D945G", STAC_D945GTP5),
873 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0303,
874 "Intel D945G", STAC_D945GTP5),
875 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0013,
876 "Intel D945G", STAC_D945GTP5),
877 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0417,
878 "Intel D945G", STAC_D945GTP5),
879 /* Intel 945P based systems */
880 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0b0b,
881 "Intel D945P", STAC_D945GTP3),
882 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0112,
883 "Intel D945P", STAC_D945GTP3),
884 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0d0d,
885 "Intel D945P", STAC_D945GTP3),
886 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0909,
887 "Intel D945P", STAC_D945GTP3),
888 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0505,
889 "Intel D945P", STAC_D945GTP3),
890 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707,
891 "Intel D945P", STAC_D945GTP5),
892 /* other systems */
893 /* Apple Mac Mini (early 2006) */
894 SND_PCI_QUIRK(0x8384, 0x7680,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +0200895 "Mac Mini", STAC_INTEL_MAC_V3),
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200896 /* Dell systems */
897 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a7,
898 "unknown Dell", STAC_922X_DELL_D81),
899 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a9,
900 "unknown Dell", STAC_922X_DELL_D81),
901 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ab,
902 "unknown Dell", STAC_922X_DELL_D81),
903 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ac,
904 "unknown Dell", STAC_922X_DELL_D82),
905 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bf,
906 "unknown Dell", STAC_922X_DELL_M81),
907 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d0,
908 "unknown Dell", STAC_922X_DELL_D82),
909 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d1,
910 "unknown Dell", STAC_922X_DELL_D81),
911 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d2,
912 "unknown Dell", STAC_922X_DELL_D81),
913 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d7,
914 "Dell XPS M1210", STAC_922X_DELL_M82),
Matt Porter403d1942005-11-29 15:00:51 +0100915 {} /* terminator */
916};
917
Matt Porter3cc08dc2006-01-23 15:27:49 +0100918static unsigned int ref927x_pin_configs[14] = {
Tobin Davis93ed1502006-09-01 21:03:12 +0200919 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
920 0x01a19040, 0x01011012, 0x01016011, 0x0101201f,
921 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
922 0x01c42190, 0x40000100,
Matt Porter3cc08dc2006-01-23 15:27:49 +0100923};
924
Tobin Davis93ed1502006-09-01 21:03:12 +0200925static unsigned int d965_3st_pin_configs[14] = {
Tobin Davis81d3dbd2006-08-22 19:44:45 +0200926 0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
927 0x01a19021, 0x01813024, 0x40000100, 0x40000100,
928 0x40000100, 0x40000100, 0x40000100, 0x40000100,
929 0x40000100, 0x40000100
930};
931
Tobin Davis93ed1502006-09-01 21:03:12 +0200932static unsigned int d965_5st_pin_configs[14] = {
933 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
934 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
935 0x40000100, 0x40000100, 0x40000100, 0x01442070,
936 0x40000100, 0x40000100
937};
938
Tobin Davis4ff076e2007-08-07 11:48:12 +0200939static unsigned int dell_3st_pin_configs[14] = {
940 0x02211230, 0x02a11220, 0x01a19040, 0x01114210,
941 0x01111212, 0x01116211, 0x01813050, 0x01112214,
942 0x403003fa, 0x40000100, 0x40000100, 0x404003fb,
943 0x40c003fc, 0x40000100
944};
945
Tobin Davis93ed1502006-09-01 21:03:12 +0200946static unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100947 [STAC_D965_REF] = ref927x_pin_configs,
Tobin Davis93ed1502006-09-01 21:03:12 +0200948 [STAC_D965_3ST] = d965_3st_pin_configs,
949 [STAC_D965_5ST] = d965_5st_pin_configs,
Tobin Davis4ff076e2007-08-07 11:48:12 +0200950 [STAC_DELL_3ST] = dell_3st_pin_configs,
Matt Porter3cc08dc2006-01-23 15:27:49 +0100951};
952
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100953static const char *stac927x_models[STAC_927X_MODELS] = {
954 [STAC_D965_REF] = "ref",
955 [STAC_D965_3ST] = "3stack",
956 [STAC_D965_5ST] = "5stack",
Tobin Davis4ff076e2007-08-07 11:48:12 +0200957 [STAC_DELL_3ST] = "dell-3stack",
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100958};
959
960static struct snd_pci_quirk stac927x_cfg_tbl[] = {
961 /* SigmaTel reference board */
962 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
963 "DFI LanParty", STAC_D965_REF),
Tobin Davis81d3dbd2006-08-22 19:44:45 +0200964 /* Intel 946 based systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100965 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST),
966 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST),
Tobin Davis93ed1502006-09-01 21:03:12 +0200967 /* 965 based 3 stack systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100968 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2116, "Intel D965", STAC_D965_3ST),
969 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2115, "Intel D965", STAC_D965_3ST),
970 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2114, "Intel D965", STAC_D965_3ST),
971 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2113, "Intel D965", STAC_D965_3ST),
972 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2112, "Intel D965", STAC_D965_3ST),
973 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2111, "Intel D965", STAC_D965_3ST),
974 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2110, "Intel D965", STAC_D965_3ST),
975 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2009, "Intel D965", STAC_D965_3ST),
976 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2008, "Intel D965", STAC_D965_3ST),
977 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2007, "Intel D965", STAC_D965_3ST),
978 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2006, "Intel D965", STAC_D965_3ST),
979 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2005, "Intel D965", STAC_D965_3ST),
980 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2004, "Intel D965", STAC_D965_3ST),
981 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2003, "Intel D965", STAC_D965_3ST),
982 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2002, "Intel D965", STAC_D965_3ST),
983 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2001, "Intel D965", STAC_D965_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +0200984 /* Dell 3 stack systems */
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200985 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01dd, "Dell Dimension E520", STAC_DELL_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +0200986 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ed, "Dell ", STAC_DELL_3ST),
987 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f4, "Dell ", STAC_DELL_3ST),
Tobin Davis93ed1502006-09-01 21:03:12 +0200988 /* 965 based 5 stack systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100989 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2301, "Intel D965", STAC_D965_5ST),
990 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2302, "Intel D965", STAC_D965_5ST),
991 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2303, "Intel D965", STAC_D965_5ST),
992 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2304, "Intel D965", STAC_D965_5ST),
993 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2305, "Intel D965", STAC_D965_5ST),
994 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2501, "Intel D965", STAC_D965_5ST),
995 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2502, "Intel D965", STAC_D965_5ST),
996 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2503, "Intel D965", STAC_D965_5ST),
997 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2504, "Intel D965", STAC_D965_5ST),
Matt Porter3cc08dc2006-01-23 15:27:49 +0100998 {} /* terminator */
999};
1000
Matt Porterf3302a52006-07-31 12:49:34 +02001001static unsigned int ref9205_pin_configs[12] = {
1002 0x40000100, 0x40000100, 0x01016011, 0x01014010,
Matt Porter8b657272006-10-26 17:12:59 +02001003 0x01813122, 0x01a19021, 0x40000100, 0x40000100,
1004 0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
Matt Porterf3302a52006-07-31 12:49:34 +02001005};
1006
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001007/*
1008 STAC 9205 pin configs for
1009 102801F1
1010 102801F2
1011 102801FC
1012 102801FD
1013 10280204
1014 1028021F
1015*/
1016static unsigned int dell_9205_m42_pin_configs[12] = {
1017 0x0321101F, 0x03A11020, 0x400003FA, 0x90170310,
1018 0x400003FB, 0x400003FC, 0x400003FD, 0x40F000F9,
1019 0x90A60330, 0x400003FF, 0x0144131F, 0x40C003FE,
1020};
1021
1022/*
1023 STAC 9205 pin configs for
1024 102801F9
1025 102801FA
1026 102801FE
1027 102801FF (Dell Precision M4300)
1028 10280206
1029 10280200
1030 10280201
1031*/
1032static unsigned int dell_9205_m43_pin_configs[12] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001033 0x0321101f, 0x03a11020, 0x90a70330, 0x90170310,
1034 0x400000fe, 0x400000ff, 0x400000fd, 0x40f000f9,
1035 0x400000fa, 0x400000fc, 0x0144131f, 0x40c003f8,
1036};
1037
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001038static unsigned int dell_9205_m44_pin_configs[12] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001039 0x0421101f, 0x04a11020, 0x400003fa, 0x90170310,
1040 0x400003fb, 0x400003fc, 0x400003fd, 0x400003f9,
1041 0x90a60330, 0x400003ff, 0x01441340, 0x40c003fe,
1042};
1043
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001044static unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001045 [STAC_9205_REF] = ref9205_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001046 [STAC_9205_DELL_M42] = dell_9205_m42_pin_configs,
1047 [STAC_9205_DELL_M43] = dell_9205_m43_pin_configs,
1048 [STAC_9205_DELL_M44] = dell_9205_m44_pin_configs,
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001049 [STAC_9205_M43xx] = NULL,
Matt Porterf3302a52006-07-31 12:49:34 +02001050};
1051
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001052static const char *stac9205_models[STAC_9205_MODELS] = {
1053 [STAC_9205_REF] = "ref",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001054 [STAC_9205_DELL_M42] = "dell-m42",
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001055 [STAC_9205_DELL_M43] = "dell-m43",
1056 [STAC_9205_DELL_M44] = "dell-m44",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001057};
1058
1059static struct snd_pci_quirk stac9205_cfg_tbl[] = {
1060 /* SigmaTel reference board */
1061 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1062 "DFI LanParty", STAC_9205_REF),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001063 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f1,
1064 "unknown Dell", STAC_9205_DELL_M42),
1065 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f2,
1066 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001067 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f8,
1068 "Dell Precision", STAC_9205_M43xx),
1069 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f9,
1070 "Dell Precision", STAC_9205_DELL_M43),
1071 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fa,
1072 "Dell Precision", STAC_9205_DELL_M43),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001073 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fc,
1074 "unknown Dell", STAC_9205_DELL_M42),
1075 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fd,
1076 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001077 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fe,
1078 "Dell Precision", STAC_9205_DELL_M43),
1079 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ff,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001080 "Dell Precision M4300", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001081 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0206,
1082 "Dell Precision", STAC_9205_DELL_M43),
1083 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f1,
1084 "Dell Inspiron", STAC_9205_DELL_M44),
1085 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f2,
1086 "Dell Inspiron", STAC_9205_DELL_M44),
1087 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fc,
1088 "Dell Inspiron", STAC_9205_DELL_M44),
1089 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fd,
1090 "Dell Inspiron", STAC_9205_DELL_M44),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001091 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0204,
1092 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001093 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021f,
1094 "Dell Inspiron", STAC_9205_DELL_M44),
Matt Porterf3302a52006-07-31 12:49:34 +02001095 {} /* terminator */
1096};
1097
Richard Fish11b44bb2006-08-23 18:31:34 +02001098static int stac92xx_save_bios_config_regs(struct hda_codec *codec)
1099{
1100 int i;
1101 struct sigmatel_spec *spec = codec->spec;
1102
1103 if (! spec->bios_pin_configs) {
1104 spec->bios_pin_configs = kcalloc(spec->num_pins,
1105 sizeof(*spec->bios_pin_configs), GFP_KERNEL);
1106 if (! spec->bios_pin_configs)
1107 return -ENOMEM;
1108 }
1109
1110 for (i = 0; i < spec->num_pins; i++) {
1111 hda_nid_t nid = spec->pin_nids[i];
1112 unsigned int pin_cfg;
1113
1114 pin_cfg = snd_hda_codec_read(codec, nid, 0,
1115 AC_VERB_GET_CONFIG_DEFAULT, 0x00);
1116 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x bios pin config %8.8x\n",
1117 nid, pin_cfg);
1118 spec->bios_pin_configs[i] = pin_cfg;
1119 }
1120
1121 return 0;
1122}
1123
Matthew Ranostay87d48362007-07-17 11:52:24 +02001124static void stac92xx_set_config_reg(struct hda_codec *codec,
1125 hda_nid_t pin_nid, unsigned int pin_config)
1126{
1127 int i;
1128 snd_hda_codec_write(codec, pin_nid, 0,
1129 AC_VERB_SET_CONFIG_DEFAULT_BYTES_0,
1130 pin_config & 0x000000ff);
1131 snd_hda_codec_write(codec, pin_nid, 0,
1132 AC_VERB_SET_CONFIG_DEFAULT_BYTES_1,
1133 (pin_config & 0x0000ff00) >> 8);
1134 snd_hda_codec_write(codec, pin_nid, 0,
1135 AC_VERB_SET_CONFIG_DEFAULT_BYTES_2,
1136 (pin_config & 0x00ff0000) >> 16);
1137 snd_hda_codec_write(codec, pin_nid, 0,
1138 AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
1139 pin_config >> 24);
1140 i = snd_hda_codec_read(codec, pin_nid, 0,
1141 AC_VERB_GET_CONFIG_DEFAULT,
1142 0x00);
1143 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x pin config %8.8x\n",
1144 pin_nid, i);
1145}
1146
Matt2f2f4252005-04-13 14:45:30 +02001147static void stac92xx_set_config_regs(struct hda_codec *codec)
1148{
1149 int i;
1150 struct sigmatel_spec *spec = codec->spec;
Matt2f2f4252005-04-13 14:45:30 +02001151
Matthew Ranostay87d48362007-07-17 11:52:24 +02001152 if (!spec->pin_configs)
1153 return;
Richard Fish11b44bb2006-08-23 18:31:34 +02001154
Matthew Ranostay87d48362007-07-17 11:52:24 +02001155 for (i = 0; i < spec->num_pins; i++)
1156 stac92xx_set_config_reg(codec, spec->pin_nids[i],
1157 spec->pin_configs[i]);
Matt2f2f4252005-04-13 14:45:30 +02001158}
Matt2f2f4252005-04-13 14:45:30 +02001159
Takashi Iwai82599802007-07-31 15:56:24 +02001160static void stac92xx_enable_gpio_mask(struct hda_codec *codec)
Matthew Ranostay92a22be2007-06-19 16:48:28 +02001161{
Takashi Iwai82599802007-07-31 15:56:24 +02001162 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay87d48362007-07-17 11:52:24 +02001163 /* Configure GPIOx as output */
Takashi Iwai82beb8f2007-08-10 17:09:26 +02001164 snd_hda_codec_write_cache(codec, codec->afg, 0,
1165 AC_VERB_SET_GPIO_DIRECTION, spec->gpio_mask);
Matthew Ranostay87d48362007-07-17 11:52:24 +02001166 /* Configure GPIOx as CMOS */
Takashi Iwai82beb8f2007-08-10 17:09:26 +02001167 snd_hda_codec_write_cache(codec, codec->afg, 0, 0x7e7, 0x00000000);
Matthew Ranostay87d48362007-07-17 11:52:24 +02001168 /* Assert GPIOx */
Takashi Iwai82beb8f2007-08-10 17:09:26 +02001169 snd_hda_codec_write_cache(codec, codec->afg, 0,
1170 AC_VERB_SET_GPIO_DATA, spec->gpio_data);
Matthew Ranostay87d48362007-07-17 11:52:24 +02001171 /* Enable GPIOx */
Takashi Iwai82beb8f2007-08-10 17:09:26 +02001172 snd_hda_codec_write_cache(codec, codec->afg, 0,
1173 AC_VERB_SET_GPIO_MASK, spec->gpio_mask);
Matthew Ranostay92a22be2007-06-19 16:48:28 +02001174}
1175
Matt2f2f4252005-04-13 14:45:30 +02001176/*
1177 * Analog playback callbacks
1178 */
1179static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
1180 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001181 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02001182{
1183 struct sigmatel_spec *spec = codec->spec;
1184 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
1185}
1186
1187static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1188 struct hda_codec *codec,
1189 unsigned int stream_tag,
1190 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001191 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02001192{
1193 struct sigmatel_spec *spec = codec->spec;
Matt Porter403d1942005-11-29 15:00:51 +01001194 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
Matt2f2f4252005-04-13 14:45:30 +02001195}
1196
1197static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
1198 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001199 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02001200{
1201 struct sigmatel_spec *spec = codec->spec;
1202 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
1203}
1204
1205/*
Mattdabbed62005-06-14 10:19:34 +02001206 * Digital playback callbacks
1207 */
1208static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
1209 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001210 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +02001211{
1212 struct sigmatel_spec *spec = codec->spec;
1213 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
1214}
1215
1216static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
1217 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001218 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +02001219{
1220 struct sigmatel_spec *spec = codec->spec;
1221 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
1222}
1223
Takashi Iwai6b97eb42007-04-05 14:51:48 +02001224static int stac92xx_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1225 struct hda_codec *codec,
1226 unsigned int stream_tag,
1227 unsigned int format,
1228 struct snd_pcm_substream *substream)
1229{
1230 struct sigmatel_spec *spec = codec->spec;
1231 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1232 stream_tag, format, substream);
1233}
1234
Mattdabbed62005-06-14 10:19:34 +02001235
1236/*
Matt2f2f4252005-04-13 14:45:30 +02001237 * Analog capture callbacks
1238 */
1239static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1240 struct hda_codec *codec,
1241 unsigned int stream_tag,
1242 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001243 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02001244{
1245 struct sigmatel_spec *spec = codec->spec;
1246
1247 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
1248 stream_tag, 0, format);
1249 return 0;
1250}
1251
1252static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1253 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001254 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02001255{
1256 struct sigmatel_spec *spec = codec->spec;
1257
1258 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 0, 0, 0);
1259 return 0;
1260}
1261
Mattdabbed62005-06-14 10:19:34 +02001262static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
1263 .substreams = 1,
1264 .channels_min = 2,
1265 .channels_max = 2,
1266 /* NID is set in stac92xx_build_pcms */
1267 .ops = {
1268 .open = stac92xx_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02001269 .close = stac92xx_dig_playback_pcm_close,
1270 .prepare = stac92xx_dig_playback_pcm_prepare
Mattdabbed62005-06-14 10:19:34 +02001271 },
1272};
1273
1274static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
1275 .substreams = 1,
1276 .channels_min = 2,
1277 .channels_max = 2,
1278 /* NID is set in stac92xx_build_pcms */
1279};
1280
Matt2f2f4252005-04-13 14:45:30 +02001281static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
1282 .substreams = 1,
1283 .channels_min = 2,
Mattc7d4b2f2005-06-27 14:59:41 +02001284 .channels_max = 8,
Matt2f2f4252005-04-13 14:45:30 +02001285 .nid = 0x02, /* NID to query formats and rates */
1286 .ops = {
1287 .open = stac92xx_playback_pcm_open,
1288 .prepare = stac92xx_playback_pcm_prepare,
1289 .cleanup = stac92xx_playback_pcm_cleanup
1290 },
1291};
1292
Matt Porter3cc08dc2006-01-23 15:27:49 +01001293static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
1294 .substreams = 1,
1295 .channels_min = 2,
1296 .channels_max = 2,
1297 .nid = 0x06, /* NID to query formats and rates */
1298 .ops = {
1299 .open = stac92xx_playback_pcm_open,
1300 .prepare = stac92xx_playback_pcm_prepare,
1301 .cleanup = stac92xx_playback_pcm_cleanup
1302 },
1303};
1304
Matt2f2f4252005-04-13 14:45:30 +02001305static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
1306 .substreams = 2,
1307 .channels_min = 2,
1308 .channels_max = 2,
Matt Porter3cc08dc2006-01-23 15:27:49 +01001309 /* NID is set in stac92xx_build_pcms */
Matt2f2f4252005-04-13 14:45:30 +02001310 .ops = {
1311 .prepare = stac92xx_capture_pcm_prepare,
1312 .cleanup = stac92xx_capture_pcm_cleanup
1313 },
1314};
1315
1316static int stac92xx_build_pcms(struct hda_codec *codec)
1317{
1318 struct sigmatel_spec *spec = codec->spec;
1319 struct hda_pcm *info = spec->pcm_rec;
1320
1321 codec->num_pcms = 1;
1322 codec->pcm_info = info;
1323
Mattc7d4b2f2005-06-27 14:59:41 +02001324 info->name = "STAC92xx Analog";
Matt2f2f4252005-04-13 14:45:30 +02001325 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
Matt2f2f4252005-04-13 14:45:30 +02001326 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
Matt Porter3cc08dc2006-01-23 15:27:49 +01001327 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
1328
1329 if (spec->alt_switch) {
1330 codec->num_pcms++;
1331 info++;
1332 info->name = "STAC92xx Analog Alt";
1333 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
1334 }
Matt2f2f4252005-04-13 14:45:30 +02001335
Mattdabbed62005-06-14 10:19:34 +02001336 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
1337 codec->num_pcms++;
1338 info++;
1339 info->name = "STAC92xx Digital";
1340 if (spec->multiout.dig_out_nid) {
1341 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
1342 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
1343 }
1344 if (spec->dig_in_nid) {
1345 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
1346 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
1347 }
1348 }
1349
Matt2f2f4252005-04-13 14:45:30 +02001350 return 0;
1351}
1352
Takashi Iwaic960a032006-03-23 17:06:28 +01001353static unsigned int stac92xx_get_vref(struct hda_codec *codec, hda_nid_t nid)
1354{
1355 unsigned int pincap = snd_hda_param_read(codec, nid,
1356 AC_PAR_PIN_CAP);
1357 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
1358 if (pincap & AC_PINCAP_VREF_100)
1359 return AC_PINCTL_VREF_100;
1360 if (pincap & AC_PINCAP_VREF_80)
1361 return AC_PINCTL_VREF_80;
1362 if (pincap & AC_PINCAP_VREF_50)
1363 return AC_PINCTL_VREF_50;
1364 if (pincap & AC_PINCAP_VREF_GRD)
1365 return AC_PINCTL_VREF_GRD;
1366 return 0;
1367}
1368
Matt Porter403d1942005-11-29 15:00:51 +01001369static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
1370
1371{
Takashi Iwai82beb8f2007-08-10 17:09:26 +02001372 snd_hda_codec_write_cache(codec, nid, 0,
1373 AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
Matt Porter403d1942005-11-29 15:00:51 +01001374}
1375
Takashi Iwaia5ce8892007-07-23 15:42:26 +02001376#define stac92xx_io_switch_info snd_ctl_boolean_mono_info
Matt Porter403d1942005-11-29 15:00:51 +01001377
1378static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1379{
1380 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1381 struct sigmatel_spec *spec = codec->spec;
1382 int io_idx = kcontrol-> private_value & 0xff;
1383
1384 ucontrol->value.integer.value[0] = spec->io_switch[io_idx];
1385 return 0;
1386}
1387
1388static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1389{
1390 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1391 struct sigmatel_spec *spec = codec->spec;
1392 hda_nid_t nid = kcontrol->private_value >> 8;
1393 int io_idx = kcontrol-> private_value & 0xff;
1394 unsigned short val = ucontrol->value.integer.value[0];
1395
1396 spec->io_switch[io_idx] = val;
1397
1398 if (val)
1399 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
Takashi Iwaic960a032006-03-23 17:06:28 +01001400 else {
1401 unsigned int pinctl = AC_PINCTL_IN_EN;
1402 if (io_idx) /* set VREF for mic */
1403 pinctl |= stac92xx_get_vref(codec, nid);
1404 stac92xx_auto_set_pinctl(codec, nid, pinctl);
1405 }
Matt Porter403d1942005-11-29 15:00:51 +01001406 return 1;
1407}
1408
1409#define STAC_CODEC_IO_SWITCH(xname, xpval) \
1410 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1411 .name = xname, \
1412 .index = 0, \
1413 .info = stac92xx_io_switch_info, \
1414 .get = stac92xx_io_switch_get, \
1415 .put = stac92xx_io_switch_put, \
1416 .private_value = xpval, \
1417 }
1418
1419
Mattc7d4b2f2005-06-27 14:59:41 +02001420enum {
1421 STAC_CTL_WIDGET_VOL,
1422 STAC_CTL_WIDGET_MUTE,
Matt Porter403d1942005-11-29 15:00:51 +01001423 STAC_CTL_WIDGET_IO_SWITCH,
Mattc7d4b2f2005-06-27 14:59:41 +02001424};
1425
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001426static struct snd_kcontrol_new stac92xx_control_templates[] = {
Mattc7d4b2f2005-06-27 14:59:41 +02001427 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
1428 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Matt Porter403d1942005-11-29 15:00:51 +01001429 STAC_CODEC_IO_SWITCH(NULL, 0),
Mattc7d4b2f2005-06-27 14:59:41 +02001430};
1431
1432/* add dynamic controls */
1433static int stac92xx_add_control(struct sigmatel_spec *spec, int type, const char *name, unsigned long val)
1434{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001435 struct snd_kcontrol_new *knew;
Mattc7d4b2f2005-06-27 14:59:41 +02001436
1437 if (spec->num_kctl_used >= spec->num_kctl_alloc) {
1438 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
1439
1440 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */
1441 if (! knew)
1442 return -ENOMEM;
1443 if (spec->kctl_alloc) {
1444 memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
1445 kfree(spec->kctl_alloc);
1446 }
1447 spec->kctl_alloc = knew;
1448 spec->num_kctl_alloc = num;
1449 }
1450
1451 knew = &spec->kctl_alloc[spec->num_kctl_used];
1452 *knew = stac92xx_control_templates[type];
Takashi Iwai82fe0c52005-06-30 10:54:33 +02001453 knew->name = kstrdup(name, GFP_KERNEL);
Mattc7d4b2f2005-06-27 14:59:41 +02001454 if (! knew->name)
1455 return -ENOMEM;
1456 knew->private_value = val;
1457 spec->num_kctl_used++;
1458 return 0;
1459}
1460
Matt Porter403d1942005-11-29 15:00:51 +01001461/* flag inputs as additional dynamic lineouts */
1462static int stac92xx_add_dyn_out_pins(struct hda_codec *codec, struct auto_pin_cfg *cfg)
1463{
1464 struct sigmatel_spec *spec = codec->spec;
Steve Longerbeam7b043892007-05-03 20:50:03 +02001465 unsigned int wcaps, wtype;
1466 int i, num_dacs = 0;
1467
1468 /* use the wcaps cache to count all DACs available for line-outs */
1469 for (i = 0; i < codec->num_nodes; i++) {
1470 wcaps = codec->wcaps[i];
1471 wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
1472 if (wtype == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL))
1473 num_dacs++;
1474 }
Matt Porter403d1942005-11-29 15:00:51 +01001475
Steve Longerbeam7b043892007-05-03 20:50:03 +02001476 snd_printdd("%s: total dac count=%d\n", __func__, num_dacs);
1477
Matt Porter403d1942005-11-29 15:00:51 +01001478 switch (cfg->line_outs) {
1479 case 3:
1480 /* add line-in as side */
Steve Longerbeam7b043892007-05-03 20:50:03 +02001481 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 3) {
Matt Porter403d1942005-11-29 15:00:51 +01001482 cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_LINE];
1483 spec->line_switch = 1;
1484 cfg->line_outs++;
1485 }
1486 break;
1487 case 2:
1488 /* add line-in as clfe and mic as side */
Steve Longerbeam7b043892007-05-03 20:50:03 +02001489 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 2) {
Matt Porter403d1942005-11-29 15:00:51 +01001490 cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_LINE];
1491 spec->line_switch = 1;
1492 cfg->line_outs++;
1493 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02001494 if (cfg->input_pins[AUTO_PIN_MIC] && num_dacs > 3) {
Matt Porter403d1942005-11-29 15:00:51 +01001495 cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_MIC];
1496 spec->mic_switch = 1;
1497 cfg->line_outs++;
1498 }
1499 break;
1500 case 1:
1501 /* add line-in as surr and mic as clfe */
Steve Longerbeam7b043892007-05-03 20:50:03 +02001502 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 1) {
Matt Porter403d1942005-11-29 15:00:51 +01001503 cfg->line_out_pins[1] = cfg->input_pins[AUTO_PIN_LINE];
1504 spec->line_switch = 1;
1505 cfg->line_outs++;
1506 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02001507 if (cfg->input_pins[AUTO_PIN_MIC] && num_dacs > 2) {
Matt Porter403d1942005-11-29 15:00:51 +01001508 cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_MIC];
1509 spec->mic_switch = 1;
1510 cfg->line_outs++;
1511 }
1512 break;
1513 }
1514
1515 return 0;
1516}
1517
Steve Longerbeam7b043892007-05-03 20:50:03 +02001518
1519static int is_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
1520{
1521 int i;
1522
1523 for (i = 0; i < spec->multiout.num_dacs; i++) {
1524 if (spec->multiout.dac_nids[i] == nid)
1525 return 1;
1526 }
1527
1528 return 0;
1529}
1530
Matt Porter3cc08dc2006-01-23 15:27:49 +01001531/*
Steve Longerbeam7b043892007-05-03 20:50:03 +02001532 * Fill in the dac_nids table from the parsed pin configuration
1533 * This function only works when every pin in line_out_pins[]
1534 * contains atleast one DAC in its connection list. Some 92xx
1535 * codecs are not connected directly to a DAC, such as the 9200
1536 * and 9202/925x. For those, dac_nids[] must be hard-coded.
Matt Porter3cc08dc2006-01-23 15:27:49 +01001537 */
Takashi Iwai19039bd2006-06-28 15:52:16 +02001538static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec,
Takashi Iwaidf802952007-07-02 19:18:00 +02001539 struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02001540{
1541 struct sigmatel_spec *spec = codec->spec;
Steve Longerbeam7b043892007-05-03 20:50:03 +02001542 int i, j, conn_len = 0;
1543 hda_nid_t nid, conn[HDA_MAX_CONNECTIONS];
1544 unsigned int wcaps, wtype;
1545
Mattc7d4b2f2005-06-27 14:59:41 +02001546 for (i = 0; i < cfg->line_outs; i++) {
1547 nid = cfg->line_out_pins[i];
Steve Longerbeam7b043892007-05-03 20:50:03 +02001548 conn_len = snd_hda_get_connections(codec, nid, conn,
1549 HDA_MAX_CONNECTIONS);
1550 for (j = 0; j < conn_len; j++) {
1551 wcaps = snd_hda_param_read(codec, conn[j],
1552 AC_PAR_AUDIO_WIDGET_CAP);
1553 wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
1554
1555 if (wtype != AC_WID_AUD_OUT ||
1556 (wcaps & AC_WCAP_DIGITAL))
1557 continue;
1558 /* conn[j] is a DAC routed to this line-out */
1559 if (!is_in_dac_nids(spec, conn[j]))
1560 break;
1561 }
1562
1563 if (j == conn_len) {
Takashi Iwaidf802952007-07-02 19:18:00 +02001564 if (spec->multiout.num_dacs > 0) {
1565 /* we have already working output pins,
1566 * so let's drop the broken ones again
1567 */
1568 cfg->line_outs = spec->multiout.num_dacs;
1569 break;
1570 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02001571 /* error out, no available DAC found */
1572 snd_printk(KERN_ERR
1573 "%s: No available DAC for pin 0x%x\n",
1574 __func__, nid);
1575 return -ENODEV;
1576 }
1577
1578 spec->multiout.dac_nids[i] = conn[j];
1579 spec->multiout.num_dacs++;
1580 if (conn_len > 1) {
1581 /* select this DAC in the pin's input mux */
Takashi Iwai82beb8f2007-08-10 17:09:26 +02001582 snd_hda_codec_write_cache(codec, nid, 0,
1583 AC_VERB_SET_CONNECT_SEL, j);
Steve Longerbeam7b043892007-05-03 20:50:03 +02001584
1585 }
Mattc7d4b2f2005-06-27 14:59:41 +02001586 }
1587
Steve Longerbeam7b043892007-05-03 20:50:03 +02001588 snd_printd("dac_nids=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
1589 spec->multiout.num_dacs,
1590 spec->multiout.dac_nids[0],
1591 spec->multiout.dac_nids[1],
1592 spec->multiout.dac_nids[2],
1593 spec->multiout.dac_nids[3],
1594 spec->multiout.dac_nids[4]);
Mattc7d4b2f2005-06-27 14:59:41 +02001595 return 0;
1596}
1597
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001598/* create volume control/switch for the given prefx type */
1599static int create_controls(struct sigmatel_spec *spec, const char *pfx, hda_nid_t nid, int chs)
1600{
1601 char name[32];
1602 int err;
1603
1604 sprintf(name, "%s Playback Volume", pfx);
1605 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, name,
1606 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1607 if (err < 0)
1608 return err;
1609 sprintf(name, "%s Playback Switch", pfx);
1610 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, name,
1611 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1612 if (err < 0)
1613 return err;
1614 return 0;
1615}
1616
Mattc7d4b2f2005-06-27 14:59:41 +02001617/* add playback controls from the parsed DAC table */
Takashi Iwai19039bd2006-06-28 15:52:16 +02001618static int stac92xx_auto_create_multi_out_ctls(struct sigmatel_spec *spec,
1619 const struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02001620{
Takashi Iwai19039bd2006-06-28 15:52:16 +02001621 static const char *chname[4] = {
1622 "Front", "Surround", NULL /*CLFE*/, "Side"
1623 };
Mattc7d4b2f2005-06-27 14:59:41 +02001624 hda_nid_t nid;
1625 int i, err;
1626
1627 for (i = 0; i < cfg->line_outs; i++) {
Matt Porter403d1942005-11-29 15:00:51 +01001628 if (!spec->multiout.dac_nids[i])
Mattc7d4b2f2005-06-27 14:59:41 +02001629 continue;
1630
1631 nid = spec->multiout.dac_nids[i];
1632
1633 if (i == 2) {
1634 /* Center/LFE */
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001635 err = create_controls(spec, "Center", nid, 1);
1636 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001637 return err;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001638 err = create_controls(spec, "LFE", nid, 2);
1639 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001640 return err;
1641 } else {
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001642 err = create_controls(spec, chname[i], nid, 3);
1643 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001644 return err;
1645 }
1646 }
1647
Matt Porter403d1942005-11-29 15:00:51 +01001648 if (spec->line_switch)
1649 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Line In as Output Switch", cfg->input_pins[AUTO_PIN_LINE] << 8)) < 0)
1650 return err;
1651
1652 if (spec->mic_switch)
1653 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Mic as Output Switch", (cfg->input_pins[AUTO_PIN_MIC] << 8) | 1)) < 0)
1654 return err;
1655
Mattc7d4b2f2005-06-27 14:59:41 +02001656 return 0;
1657}
1658
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001659static int check_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
1660{
Steve Longerbeam7b043892007-05-03 20:50:03 +02001661 if (is_in_dac_nids(spec, nid))
1662 return 1;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001663 if (spec->multiout.hp_nid == nid)
1664 return 1;
1665 return 0;
1666}
1667
1668static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
1669{
1670 if (!spec->multiout.hp_nid)
1671 spec->multiout.hp_nid = nid;
1672 else if (spec->multiout.num_dacs > 4) {
1673 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
1674 return 1;
1675 } else {
1676 spec->multiout.dac_nids[spec->multiout.num_dacs] = nid;
1677 spec->multiout.num_dacs++;
1678 }
1679 return 0;
1680}
1681
1682/* add playback controls for Speaker and HP outputs */
1683static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
1684 struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02001685{
1686 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02001687 hda_nid_t nid;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001688 int i, old_num_dacs, err;
Mattc7d4b2f2005-06-27 14:59:41 +02001689
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001690 old_num_dacs = spec->multiout.num_dacs;
1691 for (i = 0; i < cfg->hp_outs; i++) {
1692 unsigned int wid_caps = get_wcaps(codec, cfg->hp_pins[i]);
1693 if (wid_caps & AC_WCAP_UNSOL_CAP)
1694 spec->hp_detect = 1;
1695 nid = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
1696 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
1697 if (check_in_dac_nids(spec, nid))
1698 nid = 0;
1699 if (! nid)
Mattc7d4b2f2005-06-27 14:59:41 +02001700 continue;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001701 add_spec_dacs(spec, nid);
1702 }
1703 for (i = 0; i < cfg->speaker_outs; i++) {
Steve Longerbeam7b043892007-05-03 20:50:03 +02001704 nid = snd_hda_codec_read(codec, cfg->speaker_pins[i], 0,
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001705 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
1706 if (check_in_dac_nids(spec, nid))
1707 nid = 0;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001708 if (! nid)
1709 continue;
1710 add_spec_dacs(spec, nid);
Mattc7d4b2f2005-06-27 14:59:41 +02001711 }
Matthew Ranostay1b290a52007-07-12 15:17:34 +02001712 for (i = 0; i < cfg->line_outs; i++) {
1713 nid = snd_hda_codec_read(codec, cfg->line_out_pins[i], 0,
1714 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
1715 if (check_in_dac_nids(spec, nid))
1716 nid = 0;
1717 if (! nid)
1718 continue;
1719 add_spec_dacs(spec, nid);
1720 }
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001721 for (i = old_num_dacs; i < spec->multiout.num_dacs; i++) {
1722 static const char *pfxs[] = {
1723 "Speaker", "External Speaker", "Speaker2",
1724 };
1725 err = create_controls(spec, pfxs[i - old_num_dacs],
1726 spec->multiout.dac_nids[i], 3);
1727 if (err < 0)
1728 return err;
1729 }
1730 if (spec->multiout.hp_nid) {
1731 const char *pfx;
1732 if (old_num_dacs == spec->multiout.num_dacs)
1733 pfx = "Master";
1734 else
1735 pfx = "Headphone";
1736 err = create_controls(spec, pfx, spec->multiout.hp_nid, 3);
1737 if (err < 0)
1738 return err;
1739 }
Mattc7d4b2f2005-06-27 14:59:41 +02001740
1741 return 0;
1742}
1743
Matt Porter8b657272006-10-26 17:12:59 +02001744/* labels for dmic mux inputs */
Adrian Bunkddc2cec2006-11-20 12:03:44 +01001745static const char *stac92xx_dmic_labels[5] = {
Matt Porter8b657272006-10-26 17:12:59 +02001746 "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
1747 "Digital Mic 3", "Digital Mic 4"
1748};
1749
1750/* create playback/capture controls for input pins on dmic capable codecs */
1751static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
1752 const struct auto_pin_cfg *cfg)
1753{
1754 struct sigmatel_spec *spec = codec->spec;
1755 struct hda_input_mux *dimux = &spec->private_dimux;
1756 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
1757 int i, j;
1758
1759 dimux->items[dimux->num_items].label = stac92xx_dmic_labels[0];
1760 dimux->items[dimux->num_items].index = 0;
1761 dimux->num_items++;
1762
1763 for (i = 0; i < spec->num_dmics; i++) {
1764 int index;
1765 int num_cons;
1766 unsigned int def_conf;
1767
1768 def_conf = snd_hda_codec_read(codec,
1769 spec->dmic_nids[i],
1770 0,
1771 AC_VERB_GET_CONFIG_DEFAULT,
1772 0);
1773 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
1774 continue;
1775
1776 num_cons = snd_hda_get_connections(codec,
1777 spec->dmux_nid,
1778 con_lst,
1779 HDA_MAX_NUM_INPUTS);
1780 for (j = 0; j < num_cons; j++)
1781 if (con_lst[j] == spec->dmic_nids[i]) {
1782 index = j;
1783 goto found;
1784 }
1785 continue;
1786found:
1787 dimux->items[dimux->num_items].label =
1788 stac92xx_dmic_labels[dimux->num_items];
1789 dimux->items[dimux->num_items].index = index;
1790 dimux->num_items++;
1791 }
1792
1793 return 0;
1794}
1795
Mattc7d4b2f2005-06-27 14:59:41 +02001796/* create playback/capture controls for input pins */
1797static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
1798{
1799 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02001800 struct hda_input_mux *imux = &spec->private_imux;
1801 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
1802 int i, j, k;
1803
1804 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwai314634b2006-09-21 11:56:18 +02001805 int index;
Mattc7d4b2f2005-06-27 14:59:41 +02001806
Takashi Iwai314634b2006-09-21 11:56:18 +02001807 if (!cfg->input_pins[i])
1808 continue;
1809 index = -1;
1810 for (j = 0; j < spec->num_muxes; j++) {
1811 int num_cons;
1812 num_cons = snd_hda_get_connections(codec,
1813 spec->mux_nids[j],
1814 con_lst,
1815 HDA_MAX_NUM_INPUTS);
1816 for (k = 0; k < num_cons; k++)
1817 if (con_lst[k] == cfg->input_pins[i]) {
1818 index = k;
1819 goto found;
1820 }
Mattc7d4b2f2005-06-27 14:59:41 +02001821 }
Takashi Iwai314634b2006-09-21 11:56:18 +02001822 continue;
1823 found:
1824 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
1825 imux->items[imux->num_items].index = index;
1826 imux->num_items++;
Mattc7d4b2f2005-06-27 14:59:41 +02001827 }
1828
Steve Longerbeam7b043892007-05-03 20:50:03 +02001829 if (imux->num_items) {
Sam Revitch62fe78e2006-05-10 15:09:17 +02001830 /*
1831 * Set the current input for the muxes.
1832 * The STAC9221 has two input muxes with identical source
1833 * NID lists. Hopefully this won't get confused.
1834 */
1835 for (i = 0; i < spec->num_muxes; i++) {
Takashi Iwai82beb8f2007-08-10 17:09:26 +02001836 snd_hda_codec_write_cache(codec, spec->mux_nids[i], 0,
1837 AC_VERB_SET_CONNECT_SEL,
1838 imux->items[0].index);
Sam Revitch62fe78e2006-05-10 15:09:17 +02001839 }
1840 }
1841
Mattc7d4b2f2005-06-27 14:59:41 +02001842 return 0;
1843}
1844
Mattc7d4b2f2005-06-27 14:59:41 +02001845static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
1846{
1847 struct sigmatel_spec *spec = codec->spec;
1848 int i;
1849
1850 for (i = 0; i < spec->autocfg.line_outs; i++) {
1851 hda_nid_t nid = spec->autocfg.line_out_pins[i];
1852 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
1853 }
1854}
1855
1856static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
1857{
1858 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001859 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02001860
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001861 for (i = 0; i < spec->autocfg.hp_outs; i++) {
1862 hda_nid_t pin;
1863 pin = spec->autocfg.hp_pins[i];
1864 if (pin) /* connect to front */
1865 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
1866 }
1867 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
1868 hda_nid_t pin;
1869 pin = spec->autocfg.speaker_pins[i];
1870 if (pin) /* connect to front */
1871 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
1872 }
Mattc7d4b2f2005-06-27 14:59:41 +02001873}
1874
Matt Porter3cc08dc2006-01-23 15:27:49 +01001875static 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 +02001876{
1877 struct sigmatel_spec *spec = codec->spec;
1878 int err;
1879
Matt Porter8b657272006-10-26 17:12:59 +02001880 if ((err = snd_hda_parse_pin_def_config(codec,
1881 &spec->autocfg,
1882 spec->dmic_nids)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001883 return err;
Takashi Iwai82bc9552006-03-21 11:24:42 +01001884 if (! spec->autocfg.line_outs)
Matt Porter869264c2006-01-25 19:20:50 +01001885 return 0; /* can't find valid pin config */
Takashi Iwai19039bd2006-06-28 15:52:16 +02001886
Matt Porter403d1942005-11-29 15:00:51 +01001887 if ((err = stac92xx_add_dyn_out_pins(codec, &spec->autocfg)) < 0)
1888 return err;
Takashi Iwai19039bd2006-06-28 15:52:16 +02001889 if (spec->multiout.num_dacs == 0)
1890 if ((err = stac92xx_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
1891 return err;
Mattc7d4b2f2005-06-27 14:59:41 +02001892
1893 if ((err = stac92xx_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
1894 (err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg)) < 0 ||
1895 (err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
1896 return err;
1897
Matt Porter8b657272006-10-26 17:12:59 +02001898 if (spec->num_dmics > 0)
1899 if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
1900 &spec->autocfg)) < 0)
1901 return err;
1902
Mattc7d4b2f2005-06-27 14:59:41 +02001903 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Matt Porter403d1942005-11-29 15:00:51 +01001904 if (spec->multiout.max_channels > 2)
Mattc7d4b2f2005-06-27 14:59:41 +02001905 spec->surr_switch = 1;
Mattc7d4b2f2005-06-27 14:59:41 +02001906
Takashi Iwai82bc9552006-03-21 11:24:42 +01001907 if (spec->autocfg.dig_out_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01001908 spec->multiout.dig_out_nid = dig_out;
Takashi Iwai82bc9552006-03-21 11:24:42 +01001909 if (spec->autocfg.dig_in_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01001910 spec->dig_in_nid = dig_in;
Mattc7d4b2f2005-06-27 14:59:41 +02001911
1912 if (spec->kctl_alloc)
1913 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
1914
1915 spec->input_mux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02001916 spec->dinput_mux = &spec->private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +02001917
1918 return 1;
1919}
1920
Takashi Iwai82bc9552006-03-21 11:24:42 +01001921/* add playback controls for HP output */
1922static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
1923 struct auto_pin_cfg *cfg)
1924{
1925 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001926 hda_nid_t pin = cfg->hp_pins[0];
Takashi Iwai82bc9552006-03-21 11:24:42 +01001927 unsigned int wid_caps;
1928
1929 if (! pin)
1930 return 0;
1931
1932 wid_caps = get_wcaps(codec, pin);
Takashi Iwai505cb342006-03-27 12:51:52 +02001933 if (wid_caps & AC_WCAP_UNSOL_CAP)
Takashi Iwai82bc9552006-03-21 11:24:42 +01001934 spec->hp_detect = 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +01001935
1936 return 0;
1937}
1938
Richard Fish160ea0d2006-09-06 13:58:25 +02001939/* add playback controls for LFE output */
1940static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
1941 struct auto_pin_cfg *cfg)
1942{
1943 struct sigmatel_spec *spec = codec->spec;
1944 int err;
1945 hda_nid_t lfe_pin = 0x0;
1946 int i;
1947
1948 /*
1949 * search speaker outs and line outs for a mono speaker pin
1950 * with an amp. If one is found, add LFE controls
1951 * for it.
1952 */
1953 for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
1954 hda_nid_t pin = spec->autocfg.speaker_pins[i];
1955 unsigned long wcaps = get_wcaps(codec, pin);
1956 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
1957 if (wcaps == AC_WCAP_OUT_AMP)
1958 /* found a mono speaker with an amp, must be lfe */
1959 lfe_pin = pin;
1960 }
1961
1962 /* if speaker_outs is 0, then speakers may be in line_outs */
1963 if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
1964 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
1965 hda_nid_t pin = spec->autocfg.line_out_pins[i];
1966 unsigned long cfg;
1967 cfg = snd_hda_codec_read(codec, pin, 0,
1968 AC_VERB_GET_CONFIG_DEFAULT,
1969 0x00);
1970 if (get_defcfg_device(cfg) == AC_JACK_SPEAKER) {
1971 unsigned long wcaps = get_wcaps(codec, pin);
1972 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
1973 if (wcaps == AC_WCAP_OUT_AMP)
1974 /* found a mono speaker with an amp,
1975 must be lfe */
1976 lfe_pin = pin;
1977 }
1978 }
1979 }
1980
1981 if (lfe_pin) {
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001982 err = create_controls(spec, "LFE", lfe_pin, 1);
Richard Fish160ea0d2006-09-06 13:58:25 +02001983 if (err < 0)
1984 return err;
1985 }
1986
1987 return 0;
1988}
1989
Mattc7d4b2f2005-06-27 14:59:41 +02001990static int stac9200_parse_auto_config(struct hda_codec *codec)
1991{
1992 struct sigmatel_spec *spec = codec->spec;
1993 int err;
1994
Kailang Yangdf694da2005-12-05 19:42:22 +01001995 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001996 return err;
1997
1998 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
1999 return err;
2000
Takashi Iwai82bc9552006-03-21 11:24:42 +01002001 if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
2002 return err;
2003
Richard Fish160ea0d2006-09-06 13:58:25 +02002004 if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
2005 return err;
2006
Takashi Iwai82bc9552006-03-21 11:24:42 +01002007 if (spec->autocfg.dig_out_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02002008 spec->multiout.dig_out_nid = 0x05;
Takashi Iwai82bc9552006-03-21 11:24:42 +01002009 if (spec->autocfg.dig_in_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02002010 spec->dig_in_nid = 0x04;
Mattc7d4b2f2005-06-27 14:59:41 +02002011
2012 if (spec->kctl_alloc)
2013 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
2014
2015 spec->input_mux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02002016 spec->dinput_mux = &spec->private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +02002017
2018 return 1;
2019}
2020
Sam Revitch62fe78e2006-05-10 15:09:17 +02002021/*
2022 * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
2023 * funky external mute control using GPIO pins.
2024 */
2025
2026static void stac922x_gpio_mute(struct hda_codec *codec, int pin, int muted)
2027{
2028 unsigned int gpiostate, gpiomask, gpiodir;
2029
2030 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
2031 AC_VERB_GET_GPIO_DATA, 0);
2032
2033 if (!muted)
2034 gpiostate |= (1 << pin);
2035 else
2036 gpiostate &= ~(1 << pin);
2037
2038 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
2039 AC_VERB_GET_GPIO_MASK, 0);
2040 gpiomask |= (1 << pin);
2041
2042 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
2043 AC_VERB_GET_GPIO_DIRECTION, 0);
2044 gpiodir |= (1 << pin);
2045
2046 /* AppleHDA seems to do this -- WTF is this verb?? */
2047 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
2048
2049 snd_hda_codec_write(codec, codec->afg, 0,
2050 AC_VERB_SET_GPIO_MASK, gpiomask);
2051 snd_hda_codec_write(codec, codec->afg, 0,
2052 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
2053
2054 msleep(1);
2055
2056 snd_hda_codec_write(codec, codec->afg, 0,
2057 AC_VERB_SET_GPIO_DATA, gpiostate);
2058}
2059
Takashi Iwai314634b2006-09-21 11:56:18 +02002060static void enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
2061 unsigned int event)
2062{
2063 if (get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP)
2064 snd_hda_codec_write(codec, nid, 0,
2065 AC_VERB_SET_UNSOLICITED_ENABLE,
2066 (AC_USRSP_EN | event));
2067}
2068
Mattc7d4b2f2005-06-27 14:59:41 +02002069static int stac92xx_init(struct hda_codec *codec)
2070{
2071 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai82bc9552006-03-21 11:24:42 +01002072 struct auto_pin_cfg *cfg = &spec->autocfg;
2073 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02002074
Mattc7d4b2f2005-06-27 14:59:41 +02002075 snd_hda_sequence_write(codec, spec->init);
2076
Takashi Iwai82bc9552006-03-21 11:24:42 +01002077 /* set up pins */
2078 if (spec->hp_detect) {
Takashi Iwai505cb342006-03-27 12:51:52 +02002079 /* Enable unsolicited responses on the HP widget */
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002080 for (i = 0; i < cfg->hp_outs; i++)
Takashi Iwai314634b2006-09-21 11:56:18 +02002081 enable_pin_detect(codec, cfg->hp_pins[i],
2082 STAC_HP_EVENT);
Takashi Iwai0a07acaf2007-03-13 10:40:23 +01002083 /* force to enable the first line-out; the others are set up
2084 * in unsol_event
2085 */
2086 stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
2087 AC_PINCTL_OUT_EN);
Takashi Iwaieb995a82006-09-21 14:28:21 +02002088 stac92xx_auto_init_hp_out(codec);
Takashi Iwai82bc9552006-03-21 11:24:42 +01002089 /* fake event to set up pins */
2090 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
2091 } else {
2092 stac92xx_auto_init_multi_out(codec);
2093 stac92xx_auto_init_hp_out(codec);
2094 }
2095 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwaic960a032006-03-23 17:06:28 +01002096 hda_nid_t nid = cfg->input_pins[i];
2097 if (nid) {
2098 unsigned int pinctl = AC_PINCTL_IN_EN;
2099 if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC)
2100 pinctl |= stac92xx_get_vref(codec, nid);
2101 stac92xx_auto_set_pinctl(codec, nid, pinctl);
2102 }
Takashi Iwai82bc9552006-03-21 11:24:42 +01002103 }
Matt Porter8b657272006-10-26 17:12:59 +02002104 if (spec->num_dmics > 0)
2105 for (i = 0; i < spec->num_dmics; i++)
2106 stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
2107 AC_PINCTL_IN_EN);
2108
Takashi Iwai82bc9552006-03-21 11:24:42 +01002109 if (cfg->dig_out_pin)
2110 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pin,
2111 AC_PINCTL_OUT_EN);
2112 if (cfg->dig_in_pin)
2113 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
2114 AC_PINCTL_IN_EN);
2115
Sam Revitch62fe78e2006-05-10 15:09:17 +02002116 if (spec->gpio_mute) {
2117 stac922x_gpio_mute(codec, 0, 0);
2118 stac922x_gpio_mute(codec, 1, 0);
2119 }
2120
Mattc7d4b2f2005-06-27 14:59:41 +02002121 return 0;
2122}
2123
Matt2f2f4252005-04-13 14:45:30 +02002124static void stac92xx_free(struct hda_codec *codec)
2125{
Mattc7d4b2f2005-06-27 14:59:41 +02002126 struct sigmatel_spec *spec = codec->spec;
2127 int i;
2128
2129 if (! spec)
2130 return;
2131
2132 if (spec->kctl_alloc) {
2133 for (i = 0; i < spec->num_kctl_used; i++)
2134 kfree(spec->kctl_alloc[i].name);
2135 kfree(spec->kctl_alloc);
2136 }
2137
Richard Fish11b44bb2006-08-23 18:31:34 +02002138 if (spec->bios_pin_configs)
2139 kfree(spec->bios_pin_configs);
2140
Mattc7d4b2f2005-06-27 14:59:41 +02002141 kfree(spec);
Matt2f2f4252005-04-13 14:45:30 +02002142}
2143
Matt4e550962005-07-04 17:51:39 +02002144static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
2145 unsigned int flag)
2146{
2147 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
2148 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Steve Longerbeam7b043892007-05-03 20:50:03 +02002149
Takashi Iwaif9acba42007-05-29 18:01:06 +02002150 if (pin_ctl & AC_PINCTL_IN_EN) {
2151 /*
2152 * we need to check the current set-up direction of
2153 * shared input pins since they can be switched via
2154 * "xxx as Output" mixer switch
2155 */
2156 struct sigmatel_spec *spec = codec->spec;
2157 struct auto_pin_cfg *cfg = &spec->autocfg;
2158 if ((nid == cfg->input_pins[AUTO_PIN_LINE] &&
2159 spec->line_switch) ||
2160 (nid == cfg->input_pins[AUTO_PIN_MIC] &&
2161 spec->mic_switch))
2162 return;
2163 }
2164
Steve Longerbeam7b043892007-05-03 20:50:03 +02002165 /* if setting pin direction bits, clear the current
2166 direction bits first */
2167 if (flag & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))
2168 pin_ctl &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
2169
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002170 snd_hda_codec_write_cache(codec, nid, 0,
Matt4e550962005-07-04 17:51:39 +02002171 AC_VERB_SET_PIN_WIDGET_CONTROL,
2172 pin_ctl | flag);
2173}
2174
2175static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
2176 unsigned int flag)
2177{
2178 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
2179 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002180 snd_hda_codec_write_cache(codec, nid, 0,
Matt4e550962005-07-04 17:51:39 +02002181 AC_VERB_SET_PIN_WIDGET_CONTROL,
2182 pin_ctl & ~flag);
2183}
2184
Takashi Iwai314634b2006-09-21 11:56:18 +02002185static int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
2186{
2187 if (!nid)
2188 return 0;
2189 if (snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PIN_SENSE, 0x00)
2190 & (1 << 31))
2191 return 1;
2192 return 0;
2193}
2194
2195static void stac92xx_hp_detect(struct hda_codec *codec, unsigned int res)
Matt4e550962005-07-04 17:51:39 +02002196{
2197 struct sigmatel_spec *spec = codec->spec;
2198 struct auto_pin_cfg *cfg = &spec->autocfg;
2199 int i, presence;
2200
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002201 presence = 0;
2202 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai314634b2006-09-21 11:56:18 +02002203 presence = get_pin_presence(codec, cfg->hp_pins[i]);
2204 if (presence)
2205 break;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002206 }
Matt4e550962005-07-04 17:51:39 +02002207
2208 if (presence) {
2209 /* disable lineouts, enable hp */
2210 for (i = 0; i < cfg->line_outs; i++)
2211 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
2212 AC_PINCTL_OUT_EN);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002213 for (i = 0; i < cfg->speaker_outs; i++)
2214 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
2215 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02002216 } else {
2217 /* enable lineouts, disable hp */
2218 for (i = 0; i < cfg->line_outs; i++)
2219 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
2220 AC_PINCTL_OUT_EN);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002221 for (i = 0; i < cfg->speaker_outs; i++)
2222 stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
2223 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02002224 }
2225}
2226
Takashi Iwai314634b2006-09-21 11:56:18 +02002227static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
2228{
2229 switch (res >> 26) {
2230 case STAC_HP_EVENT:
2231 stac92xx_hp_detect(codec, res);
2232 break;
2233 }
2234}
2235
Takashi Iwaicb53c622007-08-10 17:21:45 +02002236#ifdef SND_HDA_NEEDS_RESUME
Mattff6fdc32005-06-27 15:06:52 +02002237static int stac92xx_resume(struct hda_codec *codec)
2238{
Richard Fish11b44bb2006-08-23 18:31:34 +02002239 stac92xx_set_config_regs(codec);
Takashi Iwai82599802007-07-31 15:56:24 +02002240 stac92xx_init(codec);
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002241 snd_hda_codec_resume_amp(codec);
2242 snd_hda_codec_resume_cache(codec);
Mattff6fdc32005-06-27 15:06:52 +02002243 return 0;
2244}
2245#endif
2246
Matt2f2f4252005-04-13 14:45:30 +02002247static struct hda_codec_ops stac92xx_patch_ops = {
2248 .build_controls = stac92xx_build_controls,
2249 .build_pcms = stac92xx_build_pcms,
2250 .init = stac92xx_init,
2251 .free = stac92xx_free,
Matt4e550962005-07-04 17:51:39 +02002252 .unsol_event = stac92xx_unsol_event,
Takashi Iwaicb53c622007-08-10 17:21:45 +02002253#ifdef SND_HDA_NEEDS_RESUME
Mattff6fdc32005-06-27 15:06:52 +02002254 .resume = stac92xx_resume,
2255#endif
Matt2f2f4252005-04-13 14:45:30 +02002256};
2257
2258static int patch_stac9200(struct hda_codec *codec)
2259{
2260 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02002261 int err;
Matt2f2f4252005-04-13 14:45:30 +02002262
Takashi Iwaie560d8d2005-09-09 14:21:46 +02002263 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02002264 if (spec == NULL)
2265 return -ENOMEM;
2266
2267 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02002268 spec->num_pins = ARRAY_SIZE(stac9200_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02002269 spec->pin_nids = stac9200_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002270 spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS,
2271 stac9200_models,
2272 stac9200_cfg_tbl);
Richard Fish11b44bb2006-08-23 18:31:34 +02002273 if (spec->board_config < 0) {
2274 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9200, using BIOS defaults\n");
2275 err = stac92xx_save_bios_config_regs(codec);
2276 if (err < 0) {
2277 stac92xx_free(codec);
2278 return err;
2279 }
2280 spec->pin_configs = spec->bios_pin_configs;
2281 } else {
Matt Porter403d1942005-11-29 15:00:51 +01002282 spec->pin_configs = stac9200_brd_tbl[spec->board_config];
2283 stac92xx_set_config_regs(codec);
2284 }
Matt2f2f4252005-04-13 14:45:30 +02002285
2286 spec->multiout.max_channels = 2;
2287 spec->multiout.num_dacs = 1;
2288 spec->multiout.dac_nids = stac9200_dac_nids;
2289 spec->adc_nids = stac9200_adc_nids;
2290 spec->mux_nids = stac9200_mux_nids;
Mattdabbed62005-06-14 10:19:34 +02002291 spec->num_muxes = 1;
Matt Porter8b657272006-10-26 17:12:59 +02002292 spec->num_dmics = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02002293
2294 spec->init = stac9200_core_init;
Matt2f2f4252005-04-13 14:45:30 +02002295 spec->mixer = stac9200_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02002296
2297 err = stac9200_parse_auto_config(codec);
2298 if (err < 0) {
2299 stac92xx_free(codec);
2300 return err;
2301 }
Matt2f2f4252005-04-13 14:45:30 +02002302
2303 codec->patch_ops = stac92xx_patch_ops;
2304
2305 return 0;
2306}
2307
Tobin Davis8e21c342007-01-08 11:04:17 +01002308static int patch_stac925x(struct hda_codec *codec)
2309{
2310 struct sigmatel_spec *spec;
2311 int err;
2312
2313 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2314 if (spec == NULL)
2315 return -ENOMEM;
2316
2317 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02002318 spec->num_pins = ARRAY_SIZE(stac925x_pin_nids);
Tobin Davis8e21c342007-01-08 11:04:17 +01002319 spec->pin_nids = stac925x_pin_nids;
2320 spec->board_config = snd_hda_check_board_config(codec, STAC_925x_MODELS,
2321 stac925x_models,
2322 stac925x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002323 again:
Tobin Davis8e21c342007-01-08 11:04:17 +01002324 if (spec->board_config < 0) {
Tobin Davis2c11f952007-05-17 09:36:34 +02002325 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC925x,"
2326 "using BIOS defaults\n");
Tobin Davis8e21c342007-01-08 11:04:17 +01002327 err = stac92xx_save_bios_config_regs(codec);
2328 if (err < 0) {
2329 stac92xx_free(codec);
2330 return err;
2331 }
2332 spec->pin_configs = spec->bios_pin_configs;
2333 } else if (stac925x_brd_tbl[spec->board_config] != NULL){
2334 spec->pin_configs = stac925x_brd_tbl[spec->board_config];
2335 stac92xx_set_config_regs(codec);
2336 }
2337
2338 spec->multiout.max_channels = 2;
2339 spec->multiout.num_dacs = 1;
2340 spec->multiout.dac_nids = stac925x_dac_nids;
2341 spec->adc_nids = stac925x_adc_nids;
2342 spec->mux_nids = stac925x_mux_nids;
2343 spec->num_muxes = 1;
Tobin Davis2c11f952007-05-17 09:36:34 +02002344 switch (codec->vendor_id) {
2345 case 0x83847632: /* STAC9202 */
2346 case 0x83847633: /* STAC9202D */
2347 case 0x83847636: /* STAC9251 */
2348 case 0x83847637: /* STAC9251D */
2349 spec->num_dmics = 1;
2350 spec->dmic_nids = stac925x_dmic_nids;
2351 break;
2352 default:
2353 spec->num_dmics = 0;
2354 break;
2355 }
Tobin Davis8e21c342007-01-08 11:04:17 +01002356
2357 spec->init = stac925x_core_init;
2358 spec->mixer = stac925x_mixer;
2359
2360 err = stac92xx_parse_auto_config(codec, 0x8, 0x7);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002361 if (!err) {
2362 if (spec->board_config < 0) {
2363 printk(KERN_WARNING "hda_codec: No auto-config is "
2364 "available, default to model=ref\n");
2365 spec->board_config = STAC_925x_REF;
2366 goto again;
2367 }
2368 err = -EINVAL;
2369 }
Tobin Davis8e21c342007-01-08 11:04:17 +01002370 if (err < 0) {
2371 stac92xx_free(codec);
2372 return err;
2373 }
2374
2375 codec->patch_ops = stac92xx_patch_ops;
2376
2377 return 0;
2378}
2379
Matt2f2f4252005-04-13 14:45:30 +02002380static int patch_stac922x(struct hda_codec *codec)
2381{
2382 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02002383 int err;
Matt2f2f4252005-04-13 14:45:30 +02002384
Takashi Iwaie560d8d2005-09-09 14:21:46 +02002385 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02002386 if (spec == NULL)
2387 return -ENOMEM;
2388
2389 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02002390 spec->num_pins = ARRAY_SIZE(stac922x_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02002391 spec->pin_nids = stac922x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002392 spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS,
2393 stac922x_models,
2394 stac922x_cfg_tbl);
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002395 if (spec->board_config == STAC_INTEL_MAC_V3) {
Takashi Iwai3fc24d82007-02-16 13:27:18 +01002396 spec->gpio_mute = 1;
2397 /* Intel Macs have all same PCI SSID, so we need to check
2398 * codec SSID to distinguish the exact models
2399 */
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01002400 printk(KERN_INFO "hda_codec: STAC922x, Apple subsys_id=%x\n", codec->subsystem_id);
Takashi Iwai3fc24d82007-02-16 13:27:18 +01002401 switch (codec->subsystem_id) {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002402
2403 case 0x106b0800:
2404 spec->board_config = STAC_INTEL_MAC_V1;
Abhijit Bhopatkarc45e20e2007-04-17 11:57:16 +02002405 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002406 case 0x106b0600:
2407 case 0x106b0700:
2408 spec->board_config = STAC_INTEL_MAC_V2;
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01002409 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002410 case 0x106b0e00:
2411 case 0x106b0f00:
2412 case 0x106b1600:
2413 case 0x106b1700:
2414 case 0x106b0200:
2415 case 0x106b1e00:
2416 spec->board_config = STAC_INTEL_MAC_V3;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01002417 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002418 case 0x106b1a00:
2419 case 0x00000100:
2420 spec->board_config = STAC_INTEL_MAC_V4;
Sylvain FORETf16928f2007-04-27 14:22:36 +02002421 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002422 case 0x106b0a00:
2423 case 0x106b2200:
2424 spec->board_config = STAC_INTEL_MAC_V5;
Takashi Iwai0dae0f82007-05-21 12:41:29 +02002425 break;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01002426 }
2427 }
2428
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002429 again:
Richard Fish11b44bb2006-08-23 18:31:34 +02002430 if (spec->board_config < 0) {
2431 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC922x, "
2432 "using BIOS defaults\n");
2433 err = stac92xx_save_bios_config_regs(codec);
2434 if (err < 0) {
2435 stac92xx_free(codec);
2436 return err;
2437 }
2438 spec->pin_configs = spec->bios_pin_configs;
2439 } else if (stac922x_brd_tbl[spec->board_config] != NULL) {
Matt Porter403d1942005-11-29 15:00:51 +01002440 spec->pin_configs = stac922x_brd_tbl[spec->board_config];
2441 stac92xx_set_config_regs(codec);
2442 }
Matt2f2f4252005-04-13 14:45:30 +02002443
Matt2f2f4252005-04-13 14:45:30 +02002444 spec->adc_nids = stac922x_adc_nids;
2445 spec->mux_nids = stac922x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01002446 spec->num_muxes = ARRAY_SIZE(stac922x_mux_nids);
Matt Porter8b657272006-10-26 17:12:59 +02002447 spec->num_dmics = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02002448
2449 spec->init = stac922x_core_init;
Matt2f2f4252005-04-13 14:45:30 +02002450 spec->mixer = stac922x_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02002451
2452 spec->multiout.dac_nids = spec->dac_nids;
Takashi Iwai19039bd2006-06-28 15:52:16 +02002453
Matt Porter3cc08dc2006-01-23 15:27:49 +01002454 err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002455 if (!err) {
2456 if (spec->board_config < 0) {
2457 printk(KERN_WARNING "hda_codec: No auto-config is "
2458 "available, default to model=ref\n");
2459 spec->board_config = STAC_D945_REF;
2460 goto again;
2461 }
2462 err = -EINVAL;
2463 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01002464 if (err < 0) {
2465 stac92xx_free(codec);
2466 return err;
2467 }
2468
2469 codec->patch_ops = stac92xx_patch_ops;
2470
Takashi Iwai807a46362007-05-29 19:01:37 +02002471 /* Fix Mux capture level; max to 2 */
2472 snd_hda_override_amp_caps(codec, 0x12, HDA_OUTPUT,
2473 (0 << AC_AMPCAP_OFFSET_SHIFT) |
2474 (2 << AC_AMPCAP_NUM_STEPS_SHIFT) |
2475 (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
2476 (0 << AC_AMPCAP_MUTE_SHIFT));
2477
Matt Porter3cc08dc2006-01-23 15:27:49 +01002478 return 0;
2479}
2480
2481static int patch_stac927x(struct hda_codec *codec)
2482{
2483 struct sigmatel_spec *spec;
2484 int err;
2485
2486 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2487 if (spec == NULL)
2488 return -ENOMEM;
2489
2490 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02002491 spec->num_pins = ARRAY_SIZE(stac927x_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02002492 spec->pin_nids = stac927x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002493 spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS,
2494 stac927x_models,
2495 stac927x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002496 again:
Richard Fish11b44bb2006-08-23 18:31:34 +02002497 if (spec->board_config < 0) {
Matt Porter3cc08dc2006-01-23 15:27:49 +01002498 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC927x, using BIOS defaults\n");
Richard Fish11b44bb2006-08-23 18:31:34 +02002499 err = stac92xx_save_bios_config_regs(codec);
2500 if (err < 0) {
2501 stac92xx_free(codec);
2502 return err;
2503 }
2504 spec->pin_configs = spec->bios_pin_configs;
2505 } else if (stac927x_brd_tbl[spec->board_config] != NULL) {
Matt Porter3cc08dc2006-01-23 15:27:49 +01002506 spec->pin_configs = stac927x_brd_tbl[spec->board_config];
2507 stac92xx_set_config_regs(codec);
2508 }
2509
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002510 switch (spec->board_config) {
Tobin Davis93ed1502006-09-01 21:03:12 +02002511 case STAC_D965_3ST:
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002512 spec->adc_nids = stac927x_adc_nids;
2513 spec->mux_nids = stac927x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01002514 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
Matt Porter8b657272006-10-26 17:12:59 +02002515 spec->num_dmics = 0;
Tobin Davis93ed1502006-09-01 21:03:12 +02002516 spec->init = d965_core_init;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002517 spec->mixer = stac9227_mixer;
2518 break;
Tobin Davis93ed1502006-09-01 21:03:12 +02002519 case STAC_D965_5ST:
2520 spec->adc_nids = stac927x_adc_nids;
2521 spec->mux_nids = stac927x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01002522 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
Matt Porter8b657272006-10-26 17:12:59 +02002523 spec->num_dmics = 0;
Tobin Davis93ed1502006-09-01 21:03:12 +02002524 spec->init = d965_core_init;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002525 spec->mixer = stac9227_mixer;
2526 break;
2527 default:
2528 spec->adc_nids = stac927x_adc_nids;
2529 spec->mux_nids = stac927x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01002530 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
Matt Porter8b657272006-10-26 17:12:59 +02002531 spec->num_dmics = 0;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002532 spec->init = stac927x_core_init;
2533 spec->mixer = stac927x_mixer;
2534 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01002535
2536 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostay87d48362007-07-17 11:52:24 +02002537 /* GPIO0 High = Enable EAPD */
Takashi Iwai82599802007-07-31 15:56:24 +02002538 spec->gpio_mask = spec->gpio_data = 0x00000001;
2539 stac92xx_enable_gpio_mask(codec);
Matthew Ranostay92a22be2007-06-19 16:48:28 +02002540
Matt Porter3cc08dc2006-01-23 15:27:49 +01002541 err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002542 if (!err) {
2543 if (spec->board_config < 0) {
2544 printk(KERN_WARNING "hda_codec: No auto-config is "
2545 "available, default to model=ref\n");
2546 spec->board_config = STAC_D965_REF;
2547 goto again;
2548 }
2549 err = -EINVAL;
2550 }
Mattc7d4b2f2005-06-27 14:59:41 +02002551 if (err < 0) {
2552 stac92xx_free(codec);
2553 return err;
2554 }
Matt2f2f4252005-04-13 14:45:30 +02002555
2556 codec->patch_ops = stac92xx_patch_ops;
2557
2558 return 0;
2559}
2560
Matt Porterf3302a52006-07-31 12:49:34 +02002561static int patch_stac9205(struct hda_codec *codec)
2562{
2563 struct sigmatel_spec *spec;
Takashi Iwai82599802007-07-31 15:56:24 +02002564 int err;
Matt Porterf3302a52006-07-31 12:49:34 +02002565
2566 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2567 if (spec == NULL)
2568 return -ENOMEM;
2569
2570 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02002571 spec->num_pins = ARRAY_SIZE(stac9205_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02002572 spec->pin_nids = stac9205_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002573 spec->board_config = snd_hda_check_board_config(codec, STAC_9205_MODELS,
2574 stac9205_models,
2575 stac9205_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002576 again:
Richard Fish11b44bb2006-08-23 18:31:34 +02002577 if (spec->board_config < 0) {
2578 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9205, using BIOS defaults\n");
2579 err = stac92xx_save_bios_config_regs(codec);
2580 if (err < 0) {
2581 stac92xx_free(codec);
2582 return err;
2583 }
2584 spec->pin_configs = spec->bios_pin_configs;
2585 } else {
Matt Porterf3302a52006-07-31 12:49:34 +02002586 spec->pin_configs = stac9205_brd_tbl[spec->board_config];
2587 stac92xx_set_config_regs(codec);
2588 }
2589
2590 spec->adc_nids = stac9205_adc_nids;
2591 spec->mux_nids = stac9205_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01002592 spec->num_muxes = ARRAY_SIZE(stac9205_mux_nids);
Matt Porter8b657272006-10-26 17:12:59 +02002593 spec->dmic_nids = stac9205_dmic_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01002594 spec->num_dmics = ARRAY_SIZE(stac9205_dmic_nids);
Matt Porter8b657272006-10-26 17:12:59 +02002595 spec->dmux_nid = 0x1d;
Matt Porterf3302a52006-07-31 12:49:34 +02002596
2597 spec->init = stac9205_core_init;
2598 spec->mixer = stac9205_mixer;
2599
2600 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostay87d48362007-07-17 11:52:24 +02002601
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002602 switch (spec->board_config){
2603 case STAC_9205_M43xx:
2604 case STAC_9205_DELL_M43:
Matthew Ranostay87d48362007-07-17 11:52:24 +02002605 /* Enable SPDIF in/out */
2606 stac92xx_set_config_reg(codec, 0x1f, 0x01441030);
2607 stac92xx_set_config_reg(codec, 0x20, 0x1c410030);
Matt Porter33382402006-12-18 13:17:28 +01002608
Takashi Iwai82599802007-07-31 15:56:24 +02002609 spec->gpio_mask = 0x00000007; /* GPIO0-2 */
Matthew Ranostay87d48362007-07-17 11:52:24 +02002610 /* GPIO0 High = EAPD, GPIO1 Low = DRM,
2611 * GPIO2 High = Headphone Mute
2612 */
Takashi Iwai82599802007-07-31 15:56:24 +02002613 spec->gpio_data = 0x00000005;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002614 break;
2615 default:
2616 /* GPIO0 High = EAPD */
2617 spec->gpio_mask = spec->gpio_data = 0x00000001;
2618 break;
2619 }
Matthew Ranostay87d48362007-07-17 11:52:24 +02002620
Takashi Iwai82599802007-07-31 15:56:24 +02002621 stac92xx_enable_gpio_mask(codec);
Matt Porterf3302a52006-07-31 12:49:34 +02002622 err = stac92xx_parse_auto_config(codec, 0x1f, 0x20);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002623 if (!err) {
2624 if (spec->board_config < 0) {
2625 printk(KERN_WARNING "hda_codec: No auto-config is "
2626 "available, default to model=ref\n");
2627 spec->board_config = STAC_9205_REF;
2628 goto again;
2629 }
2630 err = -EINVAL;
2631 }
Matt Porterf3302a52006-07-31 12:49:34 +02002632 if (err < 0) {
2633 stac92xx_free(codec);
2634 return err;
2635 }
2636
2637 codec->patch_ops = stac92xx_patch_ops;
2638
2639 return 0;
2640}
2641
Matt2f2f4252005-04-13 14:45:30 +02002642/*
Guillaume Munch6d859062006-08-22 17:15:47 +02002643 * STAC9872 hack
Takashi Iwaidb064e52006-03-16 16:04:58 +01002644 */
2645
Guillaume Munch99ccc562006-08-16 19:35:12 +02002646/* static config for Sony VAIO FE550G and Sony VAIO AR */
Takashi Iwaidb064e52006-03-16 16:04:58 +01002647static hda_nid_t vaio_dacs[] = { 0x2 };
2648#define VAIO_HP_DAC 0x5
2649static hda_nid_t vaio_adcs[] = { 0x8 /*,0x6*/ };
2650static hda_nid_t vaio_mux_nids[] = { 0x15 };
2651
2652static struct hda_input_mux vaio_mux = {
2653 .num_items = 2,
2654 .items = {
Takashi Iwaid7737812006-04-25 13:05:43 +02002655 /* { "HP", 0x0 }, */
Takashi Iwai1624cb92007-07-05 13:10:51 +02002656 { "Mic Jack", 0x1 },
2657 { "Internal Mic", 0x2 },
Takashi Iwaidb064e52006-03-16 16:04:58 +01002658 { "PCM", 0x3 },
2659 }
2660};
2661
2662static struct hda_verb vaio_init[] = {
2663 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
Takashi Iwai72e7b0d2007-08-16 17:33:55 +02002664 {0x0a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | STAC_HP_EVENT},
Takashi Iwaidb064e52006-03-16 16:04:58 +01002665 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
2666 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
2667 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
2668 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
Takashi Iwai1624cb92007-07-05 13:10:51 +02002669 {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
Takashi Iwaidb064e52006-03-16 16:04:58 +01002670 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
2671 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
2672 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
2673 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
2674 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
2675 {}
2676};
2677
Guillaume Munch6d859062006-08-22 17:15:47 +02002678static struct hda_verb vaio_ar_init[] = {
2679 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
2680 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
2681 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
2682 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
2683/* {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },*/ /* Optical Out */
2684 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
Takashi Iwai1624cb92007-07-05 13:10:51 +02002685 {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
Guillaume Munch6d859062006-08-22 17:15:47 +02002686 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
2687 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
2688/* {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},*/ /* Optical Out */
2689 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
2690 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
2691 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
2692 {}
2693};
2694
Takashi Iwaidb064e52006-03-16 16:04:58 +01002695/* bind volumes of both NID 0x02 and 0x05 */
Takashi Iwaicca3b372007-08-10 17:12:15 +02002696static struct hda_bind_ctls vaio_bind_master_vol = {
2697 .ops = &snd_hda_bind_vol,
2698 .values = {
2699 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2700 HDA_COMPOSE_AMP_VAL(0x05, 3, 0, HDA_OUTPUT),
2701 0
2702 },
2703};
Takashi Iwaidb064e52006-03-16 16:04:58 +01002704
2705/* bind volumes of both NID 0x02 and 0x05 */
Takashi Iwaicca3b372007-08-10 17:12:15 +02002706static struct hda_bind_ctls vaio_bind_master_sw = {
2707 .ops = &snd_hda_bind_sw,
2708 .values = {
2709 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2710 HDA_COMPOSE_AMP_VAL(0x05, 3, 0, HDA_OUTPUT),
2711 0,
2712 },
2713};
Takashi Iwaidb064e52006-03-16 16:04:58 +01002714
2715static struct snd_kcontrol_new vaio_mixer[] = {
Takashi Iwaicca3b372007-08-10 17:12:15 +02002716 HDA_BIND_VOL("Master Playback Volume", &vaio_bind_master_vol),
2717 HDA_BIND_SW("Master Playback Switch", &vaio_bind_master_sw),
Takashi Iwaidb064e52006-03-16 16:04:58 +01002718 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
2719 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
2720 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
2721 {
2722 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2723 .name = "Capture Source",
2724 .count = 1,
2725 .info = stac92xx_mux_enum_info,
2726 .get = stac92xx_mux_enum_get,
2727 .put = stac92xx_mux_enum_put,
2728 },
2729 {}
2730};
2731
Guillaume Munch6d859062006-08-22 17:15:47 +02002732static struct snd_kcontrol_new vaio_ar_mixer[] = {
Takashi Iwaicca3b372007-08-10 17:12:15 +02002733 HDA_BIND_VOL("Master Playback Volume", &vaio_bind_master_vol),
2734 HDA_BIND_SW("Master Playback Switch", &vaio_bind_master_sw),
Guillaume Munch6d859062006-08-22 17:15:47 +02002735 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
2736 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
2737 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
2738 /*HDA_CODEC_MUTE("Optical Out Switch", 0x10, 0, HDA_OUTPUT),
2739 HDA_CODEC_VOLUME("Optical Out Volume", 0x10, 0, HDA_OUTPUT),*/
2740 {
2741 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2742 .name = "Capture Source",
2743 .count = 1,
2744 .info = stac92xx_mux_enum_info,
2745 .get = stac92xx_mux_enum_get,
2746 .put = stac92xx_mux_enum_put,
2747 },
2748 {}
2749};
2750
2751static struct hda_codec_ops stac9872_patch_ops = {
Takashi Iwaidb064e52006-03-16 16:04:58 +01002752 .build_controls = stac92xx_build_controls,
2753 .build_pcms = stac92xx_build_pcms,
2754 .init = stac92xx_init,
2755 .free = stac92xx_free,
Takashi Iwaicb53c622007-08-10 17:21:45 +02002756#ifdef SND_HDA_NEEDS_RESUME
Takashi Iwaidb064e52006-03-16 16:04:58 +01002757 .resume = stac92xx_resume,
2758#endif
2759};
2760
Takashi Iwai72e7b0d2007-08-16 17:33:55 +02002761static int stac9872_vaio_init(struct hda_codec *codec)
2762{
2763 int err;
2764
2765 err = stac92xx_init(codec);
2766 if (err < 0)
2767 return err;
2768 if (codec->patch_ops.unsol_event)
2769 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
2770 return 0;
2771}
2772
2773static void stac9872_vaio_hp_detect(struct hda_codec *codec, unsigned int res)
2774{
2775 if (get_pin_presence(codec, 0x0a)) {
2776 stac92xx_reset_pinctl(codec, 0x0f, AC_PINCTL_OUT_EN);
2777 stac92xx_set_pinctl(codec, 0x0a, AC_PINCTL_OUT_EN);
2778 } else {
2779 stac92xx_reset_pinctl(codec, 0x0a, AC_PINCTL_OUT_EN);
2780 stac92xx_set_pinctl(codec, 0x0f, AC_PINCTL_OUT_EN);
2781 }
2782}
2783
2784static void stac9872_vaio_unsol_event(struct hda_codec *codec, unsigned int res)
2785{
2786 switch (res >> 26) {
2787 case STAC_HP_EVENT:
2788 stac9872_vaio_hp_detect(codec, res);
2789 break;
2790 }
2791}
2792
2793static struct hda_codec_ops stac9872_vaio_patch_ops = {
2794 .build_controls = stac92xx_build_controls,
2795 .build_pcms = stac92xx_build_pcms,
2796 .init = stac9872_vaio_init,
2797 .free = stac92xx_free,
2798 .unsol_event = stac9872_vaio_unsol_event,
2799#ifdef CONFIG_PM
2800 .resume = stac92xx_resume,
2801#endif
2802};
2803
Guillaume Munch6d859062006-08-22 17:15:47 +02002804enum { /* FE and SZ series. id=0x83847661 and subsys=0x104D0700 or 104D1000. */
2805 CXD9872RD_VAIO,
2806 /* Unknown. id=0x83847662 and subsys=0x104D1200 or 104D1000. */
2807 STAC9872AK_VAIO,
2808 /* Unknown. id=0x83847661 and subsys=0x104D1200. */
2809 STAC9872K_VAIO,
2810 /* AR Series. id=0x83847664 and subsys=104D1300 */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002811 CXD9872AKD_VAIO,
2812 STAC_9872_MODELS,
2813};
Takashi Iwaidb064e52006-03-16 16:04:58 +01002814
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002815static const char *stac9872_models[STAC_9872_MODELS] = {
2816 [CXD9872RD_VAIO] = "vaio",
2817 [CXD9872AKD_VAIO] = "vaio-ar",
2818};
2819
2820static struct snd_pci_quirk stac9872_cfg_tbl[] = {
2821 SND_PCI_QUIRK(0x104d, 0x81e6, "Sony VAIO F/S", CXD9872RD_VAIO),
2822 SND_PCI_QUIRK(0x104d, 0x81ef, "Sony VAIO F/S", CXD9872RD_VAIO),
2823 SND_PCI_QUIRK(0x104d, 0x81fd, "Sony VAIO AR", CXD9872AKD_VAIO),
Tobin Davis68e22542007-03-12 11:36:39 +01002824 SND_PCI_QUIRK(0x104d, 0x8205, "Sony VAIO AR", CXD9872AKD_VAIO),
Takashi Iwaidb064e52006-03-16 16:04:58 +01002825 {}
2826};
2827
Guillaume Munch6d859062006-08-22 17:15:47 +02002828static int patch_stac9872(struct hda_codec *codec)
Takashi Iwaidb064e52006-03-16 16:04:58 +01002829{
2830 struct sigmatel_spec *spec;
2831 int board_config;
2832
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002833 board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
2834 stac9872_models,
2835 stac9872_cfg_tbl);
Takashi Iwaidb064e52006-03-16 16:04:58 +01002836 if (board_config < 0)
2837 /* unknown config, let generic-parser do its job... */
2838 return snd_hda_parse_generic_codec(codec);
2839
2840 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2841 if (spec == NULL)
2842 return -ENOMEM;
2843
2844 codec->spec = spec;
2845 switch (board_config) {
Guillaume Munch6d859062006-08-22 17:15:47 +02002846 case CXD9872RD_VAIO:
2847 case STAC9872AK_VAIO:
2848 case STAC9872K_VAIO:
Takashi Iwaidb064e52006-03-16 16:04:58 +01002849 spec->mixer = vaio_mixer;
2850 spec->init = vaio_init;
2851 spec->multiout.max_channels = 2;
2852 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
2853 spec->multiout.dac_nids = vaio_dacs;
2854 spec->multiout.hp_nid = VAIO_HP_DAC;
2855 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
2856 spec->adc_nids = vaio_adcs;
2857 spec->input_mux = &vaio_mux;
2858 spec->mux_nids = vaio_mux_nids;
Takashi Iwai72e7b0d2007-08-16 17:33:55 +02002859 codec->patch_ops = stac9872_vaio_patch_ops;
Takashi Iwaidb064e52006-03-16 16:04:58 +01002860 break;
Guillaume Munch6d859062006-08-22 17:15:47 +02002861
2862 case CXD9872AKD_VAIO:
2863 spec->mixer = vaio_ar_mixer;
2864 spec->init = vaio_ar_init;
2865 spec->multiout.max_channels = 2;
2866 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
2867 spec->multiout.dac_nids = vaio_dacs;
2868 spec->multiout.hp_nid = VAIO_HP_DAC;
2869 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
2870 spec->adc_nids = vaio_adcs;
2871 spec->input_mux = &vaio_mux;
2872 spec->mux_nids = vaio_mux_nids;
Takashi Iwai72e7b0d2007-08-16 17:33:55 +02002873 codec->patch_ops = stac9872_patch_ops;
Guillaume Munch6d859062006-08-22 17:15:47 +02002874 break;
Takashi Iwaidb064e52006-03-16 16:04:58 +01002875 }
2876
Takashi Iwaidb064e52006-03-16 16:04:58 +01002877 return 0;
2878}
2879
2880
2881/*
Matt2f2f4252005-04-13 14:45:30 +02002882 * patch entries
2883 */
2884struct hda_codec_preset snd_hda_preset_sigmatel[] = {
2885 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
2886 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
2887 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
2888 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
2889 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
2890 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
2891 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
Matt Porter22a27c72006-07-06 18:49:10 +02002892 { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
2893 { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
2894 { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
2895 { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
2896 { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
2897 { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
Matt Porter3cc08dc2006-01-23 15:27:49 +01002898 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
2899 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
2900 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
2901 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
2902 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
2903 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
2904 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
2905 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
2906 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
2907 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
Tobin Davis8e21c342007-01-08 11:04:17 +01002908 { .id = 0x83847632, .name = "STAC9202", .patch = patch_stac925x },
2909 { .id = 0x83847633, .name = "STAC9202D", .patch = patch_stac925x },
2910 { .id = 0x83847634, .name = "STAC9250", .patch = patch_stac925x },
2911 { .id = 0x83847635, .name = "STAC9250D", .patch = patch_stac925x },
2912 { .id = 0x83847636, .name = "STAC9251", .patch = patch_stac925x },
2913 { .id = 0x83847637, .name = "STAC9250D", .patch = patch_stac925x },
Guillaume Munch6d859062006-08-22 17:15:47 +02002914 /* The following does not take into account .id=0x83847661 when subsys =
2915 * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
2916 * currently not fully supported.
2917 */
2918 { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
2919 { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
2920 { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
Matt Porterf3302a52006-07-31 12:49:34 +02002921 { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
2922 { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
2923 { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
2924 { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
2925 { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
2926 { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
2927 { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
2928 { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
Matt2f2f4252005-04-13 14:45:30 +02002929 {} /* terminator */
2930};